First public contribution.
1 // Copyright (c) 1996-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // used for timing graphics
20 #define TEST_BITMAP_NAME _L("Z:\\WSTEST\\TEST.MBM")
22 GLREF_C void Panic(TInt aPanic);
32 EFullScreenBitBltTest,
35 EBackupWindowDrawingTest,
38 class TGraphicsTest : public CBase
41 void DoTestL(TInt aOwningGroup, TFuncType aFunc, TInt aParam1, TAny *aParam2);
42 void DrawBitmapTestL(TInt aParam1, TAny *aParam2);
43 void XorTest(TInt aParam1, TAny *aParam2);
44 void SmallClearTest(TInt , TAny *);
45 void RectCompareTest(TInt , TAny *);
46 void UseFontTestL(TInt , TAny *);
47 void BitBltTestL(TInt , TAny *);
48 void FullScreenBitBltTestL(TInt , TAny *);
49 void MaskedBitBltTestL(TInt , TAny *);
50 void FillPatternTestL(TInt , TAny *);
51 void BackedUpWindowDrawingL(TInt aMode, TAny *);
54 CWsScreenDevice *iDevice;
57 RBackedUpWindow iBackedUpWindow;
58 RDrawableWindow *iWindowPtr;
62 TInt CreateGraphicsTest(TInt aOwningGroup, TFuncType aFunc, TInt aParam1, TAny *aParam2)
64 TGraphicsTest *iTest=NULL;
65 TRAPD(err,iTest=new(ELeave) TGraphicsTest());
68 TRAP(err,iTest->DoTestL(aOwningGroup, aFunc, aParam1, aParam2));
74 void TGraphicsTest::DoTestL(TInt aOwningGroup, TFuncType aFunc, TInt aParam1, TAny *aParam2)
77 iDevice=new(ELeave) CWsScreenDevice(iWs);
79 iGroup=RWindowGroup(iWs);
80 iGroup.Construct(ENullWsHandle);
81 iGroup.SetOwningWindowGroup(aOwningGroup);
83 if (aFunc==EBackupWindowDrawingTest)
85 iBackedUpWindow=RBackedUpWindow(iWs);
86 iWindowPtr=&iBackedUpWindow;
87 iBackedUpWindow.Construct(iGroup,EGray4,ENullWsHandle);
93 iWindow.Construct(iGroup,ENullWsHandle);
95 User::LeaveIfError(iWindowPtr->SetExtentErr(TPoint(), iDevice->SizeInPixels()));
96 iWindowPtr->Activate();
98 iDevice->CreateContext(iGc);
99 iGc->Activate(*iWindowPtr);
100 if (iWindowPtr==&iWindow)
102 iWindow.BeginRedraw();
109 DrawBitmapTestL(aParam1, aParam2);
112 XorTest(aParam1, aParam2);
114 case ESmallClearTest:
115 SmallClearTest(aParam1, aParam2);
117 case ERectCompareTest:
118 RectCompareTest(aParam1, aParam2);
121 UseFontTestL(aParam1, aParam2);
124 BitBltTestL(aParam1, aParam2);
126 case EFullScreenBitBltTest:
127 FullScreenBitBltTestL(aParam1, aParam2);
129 case EMaskedBitBltTest:
130 MaskedBitBltTestL(aParam1, aParam2);
132 case EFillPatternTest:
133 FillPatternTestL(aParam1, aParam2);
135 case EBackupWindowDrawingTest:
136 BackedUpWindowDrawingL(aParam1, aParam2);
150 void TGraphicsTest::DrawBitmapTestL(TInt , TAny *)
152 CFbsBitmap *bitmap=new(ELeave) CFbsBitmap;
153 User::LeaveIfError(bitmap->Load(TEST_BITMAP_NAME,0));
154 for(TInt nTimes=0;nTimes<10;nTimes++)
157 TSize size(iDevice->SizeInPixels());
158 iGc->DrawBitmap(TRect(-size.iWidth,-size.iHeight,size.iWidth<<1,size.iHeight<<1),bitmap);
164 TInt DrawBitmapTestFunc(TInt aOwningGroup)
166 return(CreateGraphicsTest(aOwningGroup, EBitmapTest, 0, NULL));
169 GLDEF_D TTimeTestHeader DrawBitmapTest={_S("Draw bitmap"),DrawBitmapTestFunc};
173 void TGraphicsTest::XorTest(TInt , TAny *)
175 iGc->SetDrawMode(CGraphicsContext::EDrawModeXOR);
176 iGc->SetBrushColor(TRgb::Gray256(255));
177 iGc->SetPenStyle(CGraphicsContext::ENullPen);
178 iGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
179 for(TInt count=0;count<10;count++)
181 for(TInt wid=1;wid<320;wid+=3)
183 iGc->DrawRect(TRect(10,10,10+wid,150));
189 TInt XorIngTestFunc(TInt aOwningGroup)
191 return(CreateGraphicsTest(aOwningGroup, EXorTest, 0, NULL));
194 GLDEF_D TTimeTestHeader XorIngTest={_S("Xor'ing"),XorIngTestFunc};
198 void TGraphicsTest::SmallClearTest(TInt , TAny *)
200 iGc->SetBrushColor(TRgb::Gray256(255));
201 iGc->SetPenStyle(CGraphicsContext::ENullPen);
202 iGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
203 for(TInt count=0;count<500;count++)
205 for(TInt wid=1;wid<30;wid++)
207 iGc->DrawRect(TRect(1,0,10+wid,100));
213 TInt SmallClearTestFunc(TInt aOwningGroup)
215 return(CreateGraphicsTest(aOwningGroup, ESmallClearTest, 0, NULL));
218 GLDEF_D TTimeTestHeader SmallClearTest={_S("Small clear rect"),SmallClearTestFunc};
222 enum {EMaxWidth=100};
224 void TGraphicsTest::RectCompareTest(TInt , TAny *)
226 TSize size(iDevice->SizeInPixels());
227 for(TInt count=0;count<10;count++)
228 iDevice->RectCompare(TRect(0,0,size.iWidth>>1,size.iHeight),TRect(size.iWidth>>1,0,size.iWidth,size.iHeight));
231 TInt RectCompareTestFunc(TInt aOwningGroup)
233 return(CreateGraphicsTest(aOwningGroup, ERectCompareTest, 0, NULL));
236 GLDEF_D TTimeTestHeader RectCompareTest={_S("RectCompare"),RectCompareTestFunc};
240 void TGraphicsTest::UseFontTestL(TInt , TAny *)
243 TFontSpec fspec(KTestFontTypefaceName,200);
244 User::LeaveIfError(iDevice->GetNearestFontToDesignHeightInTwips((CFont *&)font, fspec));
245 for(TInt count=0;count<1000;count++)
247 iDevice->ReleaseFont(font);
250 TInt UseFontTestFunc(TInt aOwningGroup)
252 return(CreateGraphicsTest(aOwningGroup, EUseFontTest, 0, NULL));
255 GLDEF_D TTimeTestHeader UseFontTest={_S("UseFont(x1000)"),UseFontTestFunc};
259 void TGraphicsTest::BitBltTestL(TInt , TAny *)
261 CWsBitmap *bitmap=new(ELeave) CWsBitmap(iWs);
263 bitmap->Create(size,EGray4);
264 CFbsDevice *bitmapDevice=CFbsBitmapDevice::NewL(bitmap);
265 CFbsBitGc *gc=CFbsBitGc::NewL();
266 gc->Activate(bitmapDevice);
267 gc->DrawEllipse(TRect(size));
270 for(TInt count=0;count<10;count++)
274 for(TInt xcount=0;xcount<25;xcount++,pos.iX+=size.iWidth)
277 for(TInt ycount=0;ycount<4;ycount++,pos.iY+=size.iHeight)
278 iGc->BitBlt(pos,bitmap);
284 TInt BitBltTestFunc(TInt aOwningGroup)
286 return(CreateGraphicsTest(aOwningGroup, EBitBltTest, 0, NULL));
289 GLDEF_D TTimeTestHeader BitBltTest={_S("BitBlt"),BitBltTestFunc};
291 // Full Screen BitBlt //
293 void TGraphicsTest::FullScreenBitBltTestL(TInt , TAny *)
295 CWsBitmap *bitmap=new(ELeave) CWsBitmap(iWs);
297 User::LeaveIfError(bitmap->Create(size,EGray4));
298 CFbsDevice *bitmapDevice=CFbsBitmapDevice::NewL(bitmap);
299 CFbsBitGc *gc=CFbsBitGc::NewL();
300 gc->Activate(bitmapDevice);
301 for(TInt pos=0;pos<size.iWidth;pos+=8)
303 gc->DrawRect(TRect(pos,0,pos+16,size.iHeight));
304 iGc->BitBlt(TPoint(0,0),bitmap);
312 TInt FullScreenBitBltTestFunc(TInt aOwningGroup)
314 return(CreateGraphicsTest(aOwningGroup, EFullScreenBitBltTest, 0, NULL));
317 GLDEF_D TTimeTestHeader FullScreenBitBltTest={_S("FullScreenBitBlt"),FullScreenBitBltTestFunc};
321 void TGraphicsTest::MaskedBitBltTestL(TInt , TAny *)
324 CWsBitmap *bitmap=new(ELeave) CWsBitmap(iWs);
325 bitmap->Create(size,EGray4);
326 CFbsDevice *bitmapDevice=CFbsBitmapDevice::NewL(bitmap);
327 CFbsBitGc *gc=CFbsBitGc::NewL();
328 gc->Activate(bitmapDevice);
329 gc->DrawEllipse(TRect(size));
332 CWsBitmap *mask=new(ELeave) CWsBitmap(iWs);
333 mask->Create(size,EGray4);
334 bitmapDevice=CFbsBitmapDevice::NewL(mask);
335 gc->Activate(bitmapDevice);
336 gc->SetPenColor(TRgb::Gray4(3));
337 gc->DrawEllipse(TRect(size));
341 for(TInt count=0;count<10;count++)
345 for(TInt xcount=0;xcount<25;xcount++,pos.iX+=size.iWidth+1)
348 for(TInt ycount=0;ycount<4;ycount++,pos.iY+=size.iHeight)
349 iGc->BitBltMasked(pos,bitmap,TRect(size),mask,EFalse);
356 TInt MaskedBitBltTestFunc(TInt aOwningGroup)
358 return(CreateGraphicsTest(aOwningGroup, EMaskedBitBltTest, 0, NULL));
361 GLDEF_D TTimeTestHeader MaskedBitBltTest={_S("MaskedBitBlt"),MaskedBitBltTestFunc};
365 void TGraphicsTest::FillPatternTestL(TInt , TAny *)
367 TSize scrSize(iDevice->SizeInPixels());
368 TSize rectSize(scrSize.iWidth/5-1,scrSize.iHeight/2);
370 CWsBitmap *bitmap=new(ELeave) CWsBitmap(iWs);
372 TSize bitmapSize(50,40);
373 bitmap->Create(bitmapSize,EGray4);
374 CFbsDevice *bitmapDevice=CFbsBitmapDevice::NewL(bitmap);
375 CFbsBitGc *gc=CFbsBitGc::NewL();
376 gc->Activate(bitmapDevice);
377 gc->SetBrushColor(TRgb::Gray4(2));
378 gc->SetBrushStyle(CGraphicsContext::ESolidBrush);
379 gc->DrawEllipse(TRect(bitmapSize));
383 iGc->UseBrushPattern(bitmap);
384 iGc->SetBrushStyle(CGraphicsContext::EPatternedBrush);
385 iGc->SetPenStyle(CGraphicsContext::ESolidPen);
386 for(TInt count=0;count<50;count++)
390 for(TInt xcount=0;xcount<5;xcount++,pos.iX+=rectSize.iWidth)
393 for(TInt ycount=0;ycount<2;ycount++,pos.iY+=rectSize.iHeight)
394 iGc->DrawRect(TRect(pos,rectSize));
400 TInt FillPatternTestFunc(TInt aOwningGroup)
402 return(CreateGraphicsTest(aOwningGroup, EFillPatternTest, 0, NULL));
405 GLDEF_D TTimeTestHeader FillPatternTest={_S("FillPattern"),FillPatternTestFunc};
407 // Backup Window Drawing //
409 void TGraphicsTest::BackedUpWindowDrawingL(TInt aMode, TAny *)
411 TSize scrSize(iDevice->SizeInPixels());
415 TFontSpec fspec(KTestFontTypefaceName,200);
416 User::LeaveIfError(iDevice->GetNearestFontToDesignHeightInTwips((CFont *&)font, fspec));
419 iGc->SetPenStyle(CGraphicsContext::ESolidPen);
421 for(TInt count=0;count<10;count++)
424 for(pos.iY=0;pos.iY<scrSize.iHeight;pos.iY++)
425 iGc->DrawLine(pos,pos+TSize(scrSize.iWidth,0));
428 iDevice->ReleaseFont(font);
431 TInt BackupWindowDrawingFunc1(TInt aOwningGroup)
433 return(CreateGraphicsTest(aOwningGroup, EBackupWindowDrawingTest, 0, NULL));
436 GLDEF_D TTimeTestHeader BackupWindowDrawingCreate1={_S("BackupWindowDrawing 1"),BackupWindowDrawingFunc1};
438 TInt BackupWindowDrawingFunc2(TInt aOwningGroup)
440 return(CreateGraphicsTest(aOwningGroup, EBackupWindowDrawingTest, 1, NULL));
443 GLDEF_D TTimeTestHeader BackupWindowDrawingCreate2={_S("BackupWindowDrawing 2"),BackupWindowDrawingFunc2};