Update contrib.
1 // Copyright (c) 2005-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.
19 @internalComponent - Internal Symbian test code
22 #include "talphadrawing.h"
25 // When enabled allows testing with a variable windows size rather than fixed size
26 #define _TESTWITHVARIABLEWINDOWSIZE
28 // Test bitmap file location
29 _LIT(KAlphaTestBitmap,"z:\\system\\data\\uibench_24bit.mbm");
31 const TInt KIterationsToTest = 100; // Number of iterations to run tests
32 const TInt KDelay = 100000; // 0.1 seconds
33 const TInt KRotationGranulatity = 8;// Rotation array granularity
36 Clear window to selected colour
38 LOCAL_C void ClearWindow(RWsSession& aSession, RWindow& aWindow, CWindowGc* aGc, TRgb aColor)
40 // clear so we can see bitmap version has completed
42 aWindow.BeginRedraw();
43 aGc->Activate(aWindow);
44 aGc->SetBrushColor(aColor);
52 Draws a b/w checkerboard onto a RWindow
54 LOCAL_C void ChessBoard(RWsSession& aSession, RWindow& aWindow, CWindowGc* aGc)
56 const TSize size = aWindow.Size();
58 aGc->Activate(aWindow);
59 aGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
60 aGc->SetPenStyle(CGraphicsContext::ENullPen);
62 aGc->SetBrushColor(KRgbBlack);
64 aGc->SetBrushColor(KRgbWhite);
67 const TInt checkerSize = 32;
68 for(point.iY=0; point.iY < size.iHeight; point.iY += checkerSize)
70 for(point.iX=x0; point.iX < size.iWidth; point.iX += checkerSize*2)
72 TRect rect(point, TSize(checkerSize, checkerSize));
75 x0 = checkerSize - x0;
82 RBlankWindow on top layer gets set visible/invisible to measure timing of drawing the windows below
84 void CTAlphaDrawing::DrawBlankWindowL (RWindow& /*aForeGndWin*/, TInt aIters)
86 // Create a blank window that is the size of the screen so that we can set this visible to hide the window underneath
87 // and then hide it to force redraw of the window underneath
88 RBlankWindow blankWindow = RBlankWindow(iWsSession);
89 CleanupClosePushL(blankWindow);
90 User::LeaveIfError(blankWindow.Construct(iWinGroup, (TInt)this+1));
91 blankWindow.SetSize(iScreenDevice->SizeInPixels());
92 blankWindow.SetColor(TRgb(0x3399ff));
93 blankWindow.Activate();
95 #ifdef _TESTWITHVARIABLEWINDOWSIZE
96 // Create a small window that moves position
97 RBlankWindow blankWindow2 = RBlankWindow(iWsSession);
98 CleanupClosePushL(blankWindow2);
99 User::LeaveIfError(blankWindow2.Construct(iWinGroup, (TInt)this+2));
100 blankWindow2.SetSize(TSize(10,10));
101 blankWindow2.SetColor(TRgb(0x99ff33));
102 TInt px = iScreenDevice->SizeInPixels().iWidth/2;
103 TInt py = iScreenDevice->SizeInPixels().iHeight/2;
104 blankWindow2.SetPosition(TPoint(px, py));
105 blankWindow2.Activate();
110 iProfiler->InitResults();
111 for(TInt i=aIters; i>=0; i--)
113 blankWindow.SetVisible(onoff=!onoff);
115 #ifdef _TESTWITHVARIABLEWINDOWSIZE
116 blankWindow2.SetSize(TSize(10+i, 10+i));
117 blankWindow2.SetPosition(TPoint(px--, py--));
123 iProfiler->MarkResultSetL();
126 #ifdef _TESTWITHVARIABLEWINDOWSIZE
127 CleanupStack::PopAndDestroy(&blankWindow2);
129 CleanupStack::PopAndDestroy(&blankWindow);
133 Helper function to calculate processor cycles per pixel as a characteristic number for rendering speed
135 TInt CTAlphaDrawing::CyclesPerPixel(TInt64 aDuration, TInt aIters, TInt aWidth, TInt aHeight, TInt aCPUSpeed)
137 TInt64 pixs=aWidth*aHeight;
138 TInt64 cpuHz=aCPUSpeed;
140 TInt64 ret=(aDuration*cpuHz)/pixs/1000/aIters;
145 Helper function that draws a window
147 void CTAlphaDrawing::TestDrawWindowL(TDisplayMode aMode, TInt aIters, TTestCase aTestCase, const TDesC& aTestName)
149 RWindow foregndWindow = RWindow(iWsSession);
150 User::LeaveIfError(foregndWindow.Construct(iWinGroup, (TInt)this+3));
152 CFbsBitmap * bmpModeDep = CreateSoftwareBitmapLC(iScreenDevice->SizeInPixels(), aMode);
153 CopyBitmapL(bmpModeDep, iSourceImage);
155 foregndWindow.BeginRedraw();
156 iWindowGc->Activate(foregndWindow);
157 iWindowGc->SetBrushStyle(CGraphicsContext::ENullBrush);
158 iWindowGc->SetDrawMode(CGraphicsContext::EDrawModePEN);
159 iWindowGc->DrawBitmap(iScreenDevice->SizeInPixels(), bmpModeDep, bmpModeDep->SizeInPixels());
160 iWindowGc->Deactivate();
161 foregndWindow.EndRedraw();
167 foregndWindow.SetNonTransparent();
169 case EUseTransparencyFactor:
170 User::LeaveIfError(foregndWindow.SetTransparencyFactor(TRgb(0xbbbbbb,128)));
174 foregndWindow.Activate();
176 // Start performance test and analyse results
177 DrawBlankWindowL(foregndWindow, aIters);
178 iProfiler->ResultsAnalysis(aTestName, 0, aMode, 0, aIters);
180 foregndWindow.Close();
182 CleanupStack::PopAndDestroy(bmpModeDep);
188 GRAPHICS-UI-BENCH-0013
191 The test determines how long it takes to draw an opaque (non-transparent) window composition.
194 Compare the results over time, and before and after changes to wserv code.
196 @SYMTestExpectedResults
197 Test should pass and display total test time and cycles per pixel
199 void CTAlphaDrawing::DoTestDrawOpaqueWindowL(TDisplayMode aMode, TInt aIters)
201 TestDrawWindowL(aMode, aIters, EUseOpaqueDraw, _L("WinOpaque"));
206 GRAPHICS-UI-BENCH-0014
209 The test determines how long it takes to draw transparent window compositions with window SetTransparencyFactor.
212 Compare the results over time, and before and after changes to wserv code.
214 @SYMTestExpectedResults
215 Test should pass and display total test time and cycles per pixel
217 void CTAlphaDrawing::DoTestDrawTransparentWindowFactorL(TDisplayMode aMode, TInt aIters)
219 TestDrawWindowL(aMode, aIters, EUseTransparencyFactor, _L("WinTrFac"));
224 GRAPHICS-UI-BENCH-0015
227 The test determines how long it takes to draw transparent window compositions with SetTransparencyBitmap.
230 Compare the results over time, and before and after changes to wserv code.
232 @SYMTestExpectedResults
233 Test should pass and display total test time and cycles per pixel
235 void CTAlphaDrawing::DoTestDrawTransparentWindowBitmapL(TDisplayMode aMode, TInt aIters)
237 RWindow foregndWindow;
238 foregndWindow = RWindow(iWsSession);
239 User::LeaveIfError(foregndWindow.Construct(iWinGroup, (TInt)this+5));
241 CFbsBitmap * sourceAlpha = CreateSoftwareBitmapLC(iScreenDevice->SizeInPixels(), EGray256);
242 VerticalGradientAlphaL(sourceAlpha, TRgb(0xffffffff), TRgb(0x00000000));
244 CFbsBitmap * bmpModeDep = CreateSoftwareBitmapLC(iScreenDevice->SizeInPixels(), aMode);
245 CopyBitmapL(bmpModeDep, iSourceImage);
247 foregndWindow.BeginRedraw();
248 iWindowGc->Activate(foregndWindow);
249 iWindowGc->SetBrushStyle(CGraphicsContext::ENullBrush);
250 iWindowGc->SetDrawMode(CGraphicsContext::EDrawModePEN);
251 iWindowGc->DrawBitmap(iScreenDevice->SizeInPixels(), bmpModeDep, bmpModeDep->SizeInPixels());
253 // Set transparency bitmap for this window
254 User::LeaveIfError(foregndWindow.SetTransparencyBitmap(*sourceAlpha));
256 iWindowGc->Deactivate();
257 foregndWindow.EndRedraw();
260 foregndWindow.Activate();
262 DrawBlankWindowL(foregndWindow,aIters);
263 iProfiler->ResultsAnalysis(_L("WinTrBmp"), 0, aMode, 0, aIters);
265 foregndWindow.Close();
267 CleanupStack::PopAndDestroy(2, sourceAlpha);
272 @SYMTestCaseID GRAPHICS-UI-BENCH-0016
273 @SYMTestPriority High
276 Test test determines how long it takes to draw transparent window compositions with SetTransparencyAlphaChannel.
279 Compare the results over time, and before and after changes to wserv code.
281 @SYMTestExpectedResults
282 Test should pass and display total test time and cycles per pixel
284 void CTAlphaDrawing::DoTestDrawTransparentWindowAlphaChannelL(TDisplayMode aMode, TInt aIters)
286 RWindow foregndWindow;
287 foregndWindow = RWindow(iWsSession);
288 User::LeaveIfError(foregndWindow.Construct(iWinGroup, (TInt)this+6));
290 CFbsBitmap * sourceAlpha = CreateSoftwareBitmapLC(iSourceImage->SizeInPixels(), EGray256);
291 VerticalGradientAlphaL(sourceAlpha, TRgb(0xffffffff), TRgb(0x00000000));
293 CFbsBitmap * bmpModeDep = CreateSoftwareBitmapLC(iScreenDevice->SizeInPixels(), aMode);
294 CopyBitmapL(bmpModeDep, iSourceImage);
297 TRect rect(iScreenDevice->SizeInPixels());
299 foregndWindow.BeginRedraw();
300 iWindowGc->Activate(foregndWindow);
301 iWindowGc->SetBrushStyle(CGraphicsContext::ENullBrush);
302 iWindowGc->SetDrawMode(CGraphicsContext::EDrawModePEN);
304 iWindowGc->DrawBitmapMasked(rect, bmpModeDep, bmpModeDep->SizeInPixels(), sourceAlpha, EFalse);
306 User::LeaveIfError(foregndWindow.SetTransparencyAlphaChannel());
308 iWindowGc->Deactivate();
309 foregndWindow.EndRedraw();
312 foregndWindow.Activate();
314 DrawBlankWindowL(foregndWindow,aIters);
315 iProfiler->ResultsAnalysis(_L("WinTrAlphaCh"), 0, aMode, 0, aIters);
317 foregndWindow.Close();
318 CleanupStack::PopAndDestroy(2, sourceAlpha);
324 GRAPHICS-UI-BENCH-0017
327 Creates foreground window with alpha channel transparency.
328 An image with alpha mask is bitblitted to this window.
329 The test determines how long it takes to create a window
332 Compare the results over time, and before and after changes to wserv code.
334 @SYMTestExpectedResults
335 Test should pass and display total test time and cycles per pixel
337 void CTAlphaDrawing::DoTestCreateWindowL(TDisplayMode aMode, TInt aIters)
339 RWindow foregndWindow;
341 CFbsBitmap * sourceAlpha = CreateSoftwareBitmapLC(iSourceImage->SizeInPixels(), EGray256);
342 VerticalGradientAlphaL(sourceAlpha, TRgb(0xffffffff), TRgb(0x00000000));
344 CFbsBitmap * bmpModeDep = CreateSoftwareBitmapLC(iScreenDevice->SizeInPixels(), aMode);
345 CopyBitmapL(bmpModeDep, iSourceImage);
348 TRect rect(iScreenDevice->SizeInPixels());
349 iProfiler->InitResults();
350 for(TInt i=KIterationsToTest; i>=0; i--)
352 foregndWindow = RWindow(iWsSession);
353 User::LeaveIfError(foregndWindow.Construct(iWinGroup, (TInt)this+7));
355 foregndWindow.BeginRedraw();
356 iWindowGc->Activate(foregndWindow);
357 iWindowGc->SetBrushStyle(CGraphicsContext::ENullBrush);
358 iWindowGc->SetDrawMode(CGraphicsContext::EDrawModePEN);
359 iWindowGc->DrawBitmapMasked(rect, bmpModeDep, bmpModeDep->SizeInPixels(), sourceAlpha, EFalse);
361 TInt ret = foregndWindow.SetTransparencyAlphaChannel();
362 if (ret == KErrNotSupported)
363 ERR_PRINTF1(_L("Transparency not enabled - Turn on transparency in wsini.ini file"));
364 User::LeaveIfError(ret);
366 iWindowGc->Deactivate();
367 foregndWindow.EndRedraw();
370 foregndWindow.Activate();
373 iProfiler->MarkResultSetL();
375 foregndWindow.Close();
377 iProfiler->ResultsAnalysis(_L("WinCreation"), 0, aMode, 0, aIters);
378 CleanupStack::PopAndDestroy(2, sourceAlpha);
382 CTAlphaDrawing::~CTAlphaDrawing()
386 delete iScreenDevice;
387 iBackgndWindow.Close();
390 RFbsSession::Disconnect();
393 CTAlphaDrawing::CTAlphaDrawing()
395 SetTestStepName(KTAlphaDrawing);
399 Override of base class virtual
401 @return - TVerdict code
403 TVerdict CTAlphaDrawing::doTestStepPreambleL()
405 CTe_graphicsperformanceSuiteStepBase::doTestStepPreambleL();
407 HAL::Get(HALData::ECPUSpeed,iCPUSpeed);
409 User::LeaveIfError(RFbsSession::Connect());
410 User::LeaveIfError(iWsSession.Connect());
412 iScreenDevice = new (ELeave) CWsScreenDevice(iWsSession);
413 User::LeaveIfError(iScreenDevice->Construct(0)); // screen number (0 is first screen)
415 iSourceImage = LoadBitmapL(KAlphaTestBitmap,0);
417 iWindowGc = new (ELeave) CWindowGc(iScreenDevice);
418 User::LeaveIfError(iWindowGc->Construct());
420 TDisplayMode windowMode = iScreenDevice->DisplayMode();
422 iWinGroup = RWindowGroup(iWsSession);
423 User::LeaveIfError(iWinGroup.Construct(1, EFalse));
425 iBackgndWindow = RWindow(iWsSession);
426 User::LeaveIfError(iBackgndWindow.Construct(iWinGroup, (TInt)this+8));
427 iBackgndWindow.Activate();
429 iBackgndWindow.SetNonTransparent();
430 iBackgndWindow.Invalidate();
433 return TestStepResult();
437 Override of base class pure virtual
438 Our implementation only gets called if the base class doTestStepPreambleL() did
439 not leave. That being the case, the current test result value will be EPass.
441 Creates background window with black & white checker board.
442 This background windows is used for each test case in this file
444 @return TVerdict code
446 TVerdict CTAlphaDrawing::doTestStepL()
448 TInt iters = KIterationsToTest;
450 INFO_PRINTF5(_L("TAlphaDrawing - Iterations:%d, CPUSpeed:%d kHz, Width: %d px, Height: %d px"),iters,iCPUSpeed,iScreenDevice->SizeInPixels().iWidth,iScreenDevice->SizeInPixels().iHeight);
453 TBool iniok; TInt inival;
454 iniok = GetIntFromConfig(_L("AlphaDrawingTests"), _L("testCreateWindowAlpha"), inival);
455 TBool testCreateWindowAlpha = ((iniok==EFalse) || (inival > 0));
456 iniok = GetIntFromConfig(_L("AlphaDrawingTests"), _L("testDrawOpaqueWindow"), inival);
457 TBool testDrawOpaqueWindow = ((iniok==EFalse) || (inival > 0));
458 iniok = GetIntFromConfig(_L("AlphaDrawingTests"), _L("testDrawTransparentFactorWindow"), inival);
459 TBool testDrawTransparentFactorWindow = ((iniok==EFalse) || (inival > 0));
460 iniok = GetIntFromConfig(_L("AlphaDrawingTests"), _L("testDrawTransparentWindowPerPixel"), inival);
461 TBool testDrawTransparentWindowPerPixel = ((iniok==EFalse) || (inival > 0));
462 iniok = GetIntFromConfig(_L("AlphaDrawingTests"), _L("testDrawTransparentWindowPerPixelAlpha"), inival);
463 TBool testDrawTransparentWindowPerPixelAlpha = ((iniok==EFalse) || (inival > 0));
465 const TSize iWindowSize=iBackgndWindow.Size();
467 // Initalise test - clear window and create checker board on background windows
468 ClearWindow(iWsSession, iBackgndWindow, iWindowGc, BLACK_SEMI_TRANSPARENT);
469 ChessBoard(iWsSession, iBackgndWindow, iWindowGc);
473 TInt screenModesCnt=iScreenDevice->NumScreenModes();
474 CArrayFixFlat<TInt> * rotationList=NULL;
476 rotationList = new (ELeave) CArrayFixFlat<TInt>(KRotationGranulatity);
477 CleanupStack::PushL(rotationList);
479 for (TInt scm=0; scm<screenModesCnt; scm++)
481 iScreenDevice->GetRotationsList(scm,rotationList);
483 for (TInt rot = 0; rot < rotationList->Count(); rot++)
485 TPixelsAndRotation pxrot;
486 pxrot.iPixelSize =iWindowSize;
488 iRotation=(CFbsBitGc::TGraphicsOrientation)rotationList->At(rot);
489 pxrot.iRotation =iRotation;
491 iScreenDevice->SetScreenSizeAndRotation(pxrot);
493 for(int m=0; m<1; m++)
495 // test drawing speed of window creation and destruction
496 if ( testCreateWindowAlpha )
498 SetTestStepID(_L("GRAPHICS-UI-BENCH-0017"));
499 DoTestCreateWindowL(KValidDisplayModes[m],iters);
503 // test drawing speed of an opaque window composition
504 if ( testDrawOpaqueWindow )
506 SetTestStepID(_L("GRAPHICS-UI-BENCH-0013"));
507 DoTestDrawOpaqueWindowL(KValidDisplayModes[m],iters);
511 // test drawing speed of a transparent window composition with a transparency factor
512 if ( testDrawTransparentFactorWindow )
514 SetTestStepID(_L("GRAPHICS-UI-BENCH-0014"));
515 DoTestDrawTransparentWindowFactorL(KValidDisplayModes[m],iters);
519 // test drawing speed of a transparent window composition with a transparency bitmap
520 if ( testDrawTransparentWindowPerPixel )
522 SetTestStepID(_L("GRAPHICS-UI-BENCH-0015"));
523 DoTestDrawTransparentWindowBitmapL(KValidDisplayModes[m],iters);
527 // test drawing speed of a transparent window composition with alpha channel transparency
528 if ( testDrawTransparentWindowPerPixelAlpha )
530 SetTestStepID(_L("GRAPHICS-UI-BENCH-0016"));
531 DoTestDrawTransparentWindowAlphaChannelL(KValidDisplayModes[m],iters);
535 } // rot ... Rotations
537 CleanupStack::PopAndDestroy(rotationList);
538 TVerdict a = TestStepResult();
539 return TestStepResult();