Update contrib.
1 // Copyright (c) 2008-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 "tspriteperf.h"
24 const TInt KIterationsToTest = 60; // Number of iterations to run tests
26 RTAnim::RTAnim() : RAnim()
30 RTAnim::RTAnim(RAnimDll& aDll) : RAnim(aDll)
34 CTSpritePerf::~CTSpritePerf()
38 CTSpritePerf::CTSpritePerf()
40 SetTestStepName(KTSpritePerfName);
44 Override of base class virtual
46 @return - TVerdict code
48 TVerdict CTSpritePerf::doTestStepPreambleL()
50 User::LeaveIfError(iWs.Connect());
51 CTe_graphicsperformanceSuiteStepBase::doTestStepPreambleL();
53 return TestStepResult();
57 TVerdict CTSpritePerf::doTestStepPostambleL()
61 return TestStepResult();
64 /** Override of base class pure virtual
65 Our implementation only gets called if the base class doTestStepPreambleL() did
66 not leave. That being the case, the current test result value will be EPass.
68 @return - TVerdict code
70 TVerdict CTSpritePerf::doTestStepL()
72 SetTestStepID(_L("GRAPHICS-UI-BENCH-0128"));
73 SpriteAnimOverWholeScreenL();
75 SetTestStepID(_L("GRAPHICS-UI-BENCH-0129"));
76 SpriteAnimUnderTranslucentWindowsL();
78 SetTestStepID(_L("GRAPHICS-UI-BENCH-0130"));
79 SpriteAnimWithSemitransparentMaskOverWholeScreenL();
81 SetTestStepID(_L("GRAPHICS-UI-BENCH-0131"));
82 SpriteAnimWithSemitransparentMaskUnderTranslucentWindowsL();
85 SetTestStepID(_L("GRAPHICS-UI-BENCH-0143"));
86 OpaqueFloatingSpriteNonOverlapUpdateAreaL();
88 SetTestStepID(_L("GRAPHICS-UI-BENCH-0144"));
89 SemitransparentFloatingSpriteNonOverlapUpdateAreaL();
91 SetTestStepID(_L("GRAPHICS-UI-BENCH-0145"));
92 OpaqueFloatingSpriteOverlapUpdateAreaL();
94 SetTestStepID(_L("GRAPHICS-UI-BENCH-0146"));
95 SemitransparentFloatingSpriteOverlapUpdateAreaL();
97 return TestStepResult();
100 /** Set up the window server environment and load the animation DLL which will be used for
101 the sprite performance test cases.
102 The RWsSession is connected to the window server, the CWsScreenDevice and the RWindowGroup
103 members are constructed. Also the client-side interface to the server-side animation DLL is
104 constructed and the animation DLL is loaded.
106 void CTSpritePerf::SetUpWindowEnvironmentL(RAnimDll* aAnimDll)
108 SetScreenModeL(EColor16MA);
112 TInt err = aAnimDll->Load(KAnimDLLName);
115 INFO_PRINTF3(_L("DLL file %S was not loaded properly, leave with error code %i"),KAnimDLLName,err);
120 iWsScreenDev = new(ELeave) CWsScreenDevice(iWs);
121 User::LeaveIfError(iWsScreenDev->Construct());
122 TSize screenSize = iWsScreenDev->SizeInPixels();
124 iWinGroup = new(ELeave) RWindowGroup(iWs);
125 User::LeaveIfError(iWinGroup->Construct(reinterpret_cast<TUint32>(iWinGroup),iWsScreenDev));
128 /** Populate the RWindow array member by constructing RWindow objects. Set the background colour of the windows according to the
129 tranparency flag. Make the windows visible, activate them and draw them.
131 @param aUseTransparency the transparency flag of the windows
133 void CTSpritePerf::ConstructArrayOfWindowsL(TBool aUseTransparency)
135 TRect rect(TPoint(0,0),iWsScreenDev->SizeInPixels());
138 for (i=0;i<ENumWins;++i)
140 iWins[i]=new(ELeave) RWindow(iWs);
141 winID = reinterpret_cast<TUint32>(iWinGroup+i+1);
143 User::LeaveIfError(iWins[i]->Construct(*iWinGroup,winID)); //iWinGroup is the parent of iWins[0]
145 User::LeaveIfError(iWins[i]->Construct(*iWins[0],winID)); //iWins[0] is the the parent for every subsequent window
146 rect.Resize(-rect.Width()/10,-rect.Height()/10);
147 iWins[i]->SetExtent(TPoint(0,0),rect.Size());
148 if (aUseTransparency)
150 iWins[i]->SetTransparencyAlphaChannel();
151 iBackColour[i]= TRgb(240,(200*i)/ENumWins,170-(20*i)/ENumWins,(60*(i+1))/ENumWins); //assign a different background colour to each window in a pseudo-random manner
152 iWins[i]->SetBackgroundColor(iBackColour[i]); //semi-transparent window (R,G,B,Alpha)
156 iBackColour[i]= TRgb(180,(200*i)/ENumWins,170-(20*i)/ENumWins,255);
157 iWins[i]->SetBackgroundColor(iBackColour[i]); //opaque window
160 iWins[i]->SetVisible(ETrue);
161 iWins[i]->Activate();
162 iWins[i]->Invalidate();
163 iWins[i]->BeginRedraw();
164 iWins[i]->EndRedraw();
171 /** Release the resources that the window server environment, the window construction and the client-side
172 interface to animation DLL have allocated.
174 void CTSpritePerf::ReleaseWindowsAndEnvironment()
176 for (TInt i=0;i<ENumWins;++i)
196 GRAPHICS-UI-BENCH-0128
201 Tests how long it takes to draw the bitmap of a sprite over the whole screen
204 Set up the window server environment, load the animation DLL and construct an array of opaque windows.
205 Construct an opaque sprite having the window group as parent. Append a single member (appropriately initialised) to it
206 and construct a sprite animation linked to the sprite. Over a specific number of iterations perform some
207 draw operations on the sprite animation. Record the time the draw requests and the actual drawing require
208 and release the resources.
210 @SYMTestExpectedResults
211 Test should pass and display average test time per iteration
213 void CTSpritePerf::SpriteAnimOverWholeScreenL()
215 _LIT(KTestName, "SpriteAnimOverWholeScreenL");
216 SpriteAnimTestL(KTestName, ETrue, EFalse);
221 GRAPHICS-UI-BENCH-0129
226 Tests how long it takes to draw the bitmap of a sprite under transparent windows
229 Set up the window server environment, load the animation DLL and construct an array of translucent windows.
230 Construct an opaque sprite having the bottom window as parent. Append a single member (appropriately initialised) to it.
231 and construct a sprite animation linked to the sprite. Over a specific number of iterations perform some draw
232 operations on the sprite animation. Record the time the draw requests and the actual drawing require and release the
235 @SYMTestExpectedResults
236 Test should pass and display average test time per iteration
238 void CTSpritePerf::SpriteAnimUnderTranslucentWindowsL()
240 _LIT(KTestName, "SpriteAnimUnderTranslucentWindowsL");
241 SpriteAnimTestL(KTestName, EFalse, EFalse);
246 GRAPHICS-UI-BENCH-0130
251 Tests how long it takes to draw the bitmap of a sprite over the whole screen, when the bitmap mask is partially transparent
254 Set up the window server environment, load the animation DLL and construct an array of opaque windows.
255 Construct a semitransparent sprite having the window group as parent. Append a single member (appropriately initialised)
256 to it and construct a sprite animation linked to the sprite. Over a specific number of iterations perform some draw
257 operations on the sprite animation. Record the time the draw requests and the actual drawing require and release the resources.
259 @SYMTestExpectedResults
260 Test should pass and display average test time per iteration
262 void CTSpritePerf::SpriteAnimWithSemitransparentMaskOverWholeScreenL()
264 _LIT(KTestName, "SpriteAnimWithSemitransparentMaskOverWholeScreenL");
265 SpriteAnimTestL(KTestName, ETrue, ETrue);
270 GRAPHICS-UI-BENCH-0131
275 Tests how long it takes to draw the bitmap of a sprite under translucent windows, when the bitmap mask is partially transparent
278 Set up the window server environment, load the animation DLL and construct an array of translucent windows.
279 Construct a semitransparent sprite having the bottom window as parent. Append a single member (appropriately initialised)
280 to it and construct a sprite animation linked to the sprite. Over a specific number of iterations perform some draw
281 operations on the sprite animation. Record the time the draw requests and the actual drawing require and release the resources.
283 @SYMTestExpectedResults
284 Test should pass and display average test time per iteration
286 void CTSpritePerf::SpriteAnimWithSemitransparentMaskUnderTranslucentWindowsL()
288 _LIT(KTestName, "SpriteAnimWithSemitransparentMaskUnderTranslucentWindowsL");
289 SpriteAnimTestL(KTestName, EFalse, ETrue);
292 static void CleanupWindows(TAny* aPtr)
294 RWindow** wins = static_cast<RWindow**>(aPtr);
295 for (TInt i=0;i<CTSpritePerf::ENumWins;++i)
306 static void CleanupWindowGroup(TAny* aPtr)
308 RWindowGroup** windowGroup = static_cast<RWindowGroup**>(aPtr);
311 (*windowGroup)->Close();
317 static void CleanupScreenDevice(TAny* aPtr)
319 CWsScreenDevice** screenDevice = static_cast<CWsScreenDevice**>(aPtr);
320 delete *screenDevice;
325 Set up the window server environment, load the animation DLL and construct an array of (opaque/translucent) windows.
326 Construct an opaque/semitransparent sprite with a single member, initialise it and construct a sprite animation linked to the sprite.
327 Over a specific number of iterations perform some draw operations on the sprite animation. Record the time
328 the draw requests and the actual drawing require and release the resources.
330 @param aTestName the name of the test case
331 @param aOverWholeScreen the flag deciding whether the windows are opaque or tranparent and thus deciding whether
332 the sprite is drawn over the whole screen or under transparent windows
333 @param aTransparentMask the transparency flag of the sprite bitmap mask
335 void CTSpritePerf::SpriteAnimTestL(const TDesC& aTestName,TBool aOverWholeScreen, TBool aTransparentMask)
337 RAnimDll animDll(iWs);
338 CleanupClosePushL(animDll);
340 TCleanupItem cleanupScreenDevice(CleanupScreenDevice,&iWsScreenDev);
341 CleanupStack::PushL(cleanupScreenDevice);
342 TCleanupItem cleanupWindowGroup(CleanupWindowGroup,&iWinGroup);
343 CleanupStack::PushL(cleanupWindowGroup);
344 SetUpWindowEnvironmentL(&animDll);
346 TCleanupItem cleanupWindows(CleanupWindows,iWins);
347 CleanupStack::PushL(cleanupWindows);
348 ConstructArrayOfWindowsL(!aOverWholeScreen);
350 RWsSprite sprite(iWs);
351 CleanupClosePushL(sprite);
352 if (aOverWholeScreen)
353 User::LeaveIfError(sprite.Construct(*iWinGroup,TPoint(10,10),ESpriteNoChildClip));
355 User::LeaveIfError(sprite.Construct(*iWins[0],TPoint(10,10),ESpriteNoChildClip));
357 CFbsBitmap* bitmap=new(ELeave) CFbsBitmap();
358 CleanupStack::PushL(bitmap);
359 User::LeaveIfError(bitmap->Create(TSize(40,42),EColor16MA));
361 CFbsBitmap* bitmap2 = NULL; //used as bitmap mask for sprite member of opaque sprite
362 CFbsBitmap* bitmap3 = NULL; //used as bitmap mask for sprite member of semitransparent sprite
364 if (!aTransparentMask)
366 //opaque sprite uses a bitmap mask set to white
367 bitmap2=new(ELeave) CFbsBitmap();
368 CleanupStack::PushL(bitmap2);
369 User::LeaveIfError(bitmap2->Create(TSize(40,42),EColor16MA));
373 //semitransparent sprite uses a bitmap mask, in which
374 // *the bottom right quarter is set to black making the sprite fully transparent in this area
375 // *the remaining region is set to a gray shade allowing the sprite to be semitransparent in this area
376 bitmap3=new(ELeave) CFbsBitmap();
377 CleanupStack::PushL(bitmap3);
378 User::LeaveIfError(bitmap3->Create(TSize(40,42),EColor16MA));
380 CFbsBitmapDevice *device=CFbsBitmapDevice::NewL(bitmap3);
381 CleanupStack::PushL(device);
383 User::LeaveIfError(device->CreateContext(gc));
384 CleanupStack::PushL(gc);
386 gc->SetBrushStyle(CGraphicsContext::ESolidBrush);
387 gc->SetPenSize(TSize());
388 TSize bitmapSize=bitmap3->SizeInPixels();
389 TSize size=bitmapSize;
390 size.SetSize(size.iWidth/2,size.iHeight/2);
391 TPoint point=size.AsPoint();
392 gc->SetBrushColor(TRgb(128,128,128));
393 gc->DrawRect(TRect(TPoint(),bitmapSize));
394 gc->SetBrushColor(TRgb(0,0,0));
395 gc->DrawRect(TRect(point,size));
398 TSpriteMember member;
399 member.iBitmap=bitmap;
400 if (aTransparentMask)
401 member.iMaskBitmap=bitmap3;
403 member.iMaskBitmap=bitmap2;
404 member.iInvertMask=EFalse;
405 member.iDrawMode=CGraphicsContext::EDrawModePEN;
406 member.iOffset=TPoint();
407 member.iInterval=TTimeIntervalMicroSeconds32(200000);
409 sprite.AppendMember(member);
411 RTAnim spriteAnim(animDll);
412 CleanupClosePushL(spriteAnim);
415 User::LeaveIfError(spriteAnim.Construct(sprite,ESpriteAnimType,des));
418 iProfiler->InitResults();
419 for (TInt count=KIterationsToTest; count>=0; --count)
421 iProfiler->StartTimer();
422 // draw on sprite member's bitmap and update the sprite member
423 spriteAnim.Command(EADllDraw1);
424 spriteAnim.Command(EADllDraw2);
425 spriteAnim.Command(EADllDraw3);
427 iProfiler->MarkResultSetL();
429 spriteAnim.Command(EADllDrawBlank);
434 iProfiler->ResultsAnalysis(aTestName, 0, EColor16MA, EColor16MA, KIterationsToTest);
436 if (!aTransparentMask)
437 CleanupStack::PopAndDestroy(4); //sprite, bitmaps (2), testanim
439 CleanupStack::PopAndDestroy(6); //sprite, bitmaps (2), device, gc, testanim
440 CleanupStack::Pop(3); //cleanup items(3)
441 CleanupStack::PopAndDestroy(1); //anim Dll
442 ReleaseWindowsAndEnvironment();
447 GRAPHICS-UI-BENCH-0143
452 Tests how long it takes to draw the bitmap of an opaque sprite, when it lies over an area that is not updated.
455 Set up the window server environment and construct an array of opaque windows.
456 Construct an opaque floating sprite and place it over an area that will not be followingly updated.
457 Append a single member to it. Over a specific number of iterations update a screen area. Record the time
458 the actual drawing requires and release the resources.
460 @SYMTestExpectedResults
461 Test should pass and display average test time per iteration
463 void CTSpritePerf::OpaqueFloatingSpriteNonOverlapUpdateAreaL()
465 _LIT(KTestName, "OpaqueFloatingSpriteNonOverlapUpdateAreaL");
466 FloatingSpriteTestL(KTestName, ETrue, EFalse);
471 GRAPHICS-UI-BENCH-0144
476 Tests how long it takes to draw the bitmap of a semitransparent sprite, when it lies over an area that is not updated.
479 Set up the window server environment and construct an array of opaque windows.
480 Construct a semitransparent floating sprite and place it over an area that will not be followingly updated.
481 Append a single member to it. Over a specific number of iterations update a screen area. Record the time
482 the actual drawing requires and release the resources.
484 @SYMTestExpectedResults
485 Test should pass and display average test time per iteration
487 void CTSpritePerf::SemitransparentFloatingSpriteNonOverlapUpdateAreaL()
489 _LIT(KTestName, "SemitransparentFloatingSpriteNonOverlapUpdateAreaL");
490 FloatingSpriteTestL(KTestName, EFalse, EFalse);
495 GRAPHICS-UI-BENCH-0145
500 Tests how long it takes to draw the bitmap of an opaque sprite, when it lies over an area that is updated.
503 Set up the window server environment and construct an array of opaque windows.
504 Construct an opaque floating sprite and place it over an area that will be followingly updated.
505 Append a single member to it. Over a specific number of iterations update a screen area. Record the time
506 the actual drawing requires and release the resources.
508 @SYMTestExpectedResults
509 Test should pass and display average test time per iteration
511 void CTSpritePerf::OpaqueFloatingSpriteOverlapUpdateAreaL()
513 _LIT(KTestName, "OpaqueFloatingSpriteOverlapUpdateAreaL");
514 FloatingSpriteTestL(KTestName, ETrue, ETrue);
519 GRAPHICS-UI-BENCH-0146
524 Tests how long it takes to draw the bitmap of a semitransparent sprite, when it lies over an area that is updated.
527 Set up the window server environment and construct an array of opaque windows.
528 Construct a semitransparent floating sprite and place it over an area that will be followingly updated.
529 Append a single member to it. Over a specific number of iterations update a screen area. Record the time
530 the actual drawing requires and release the resources.
532 @SYMTestExpectedResults
533 Test should pass and display average test time per iteration
535 void CTSpritePerf::SemitransparentFloatingSpriteOverlapUpdateAreaL()
537 _LIT(KTestName, "SemitransparentFloatingSpriteOverlapUpdateAreaL");
538 FloatingSpriteTestL(KTestName, EFalse, ETrue);
542 Set up the window server environment and construct an array of opaque windows.
543 Construct an opaque/semitransparent sprite attached to the window group, thus being a floating sprite.
544 Append a single member to the sprite. Over a specific number of iterations update a screen area by rotating
545 the background colour of the windows (excluding top window). Record the time the actual drawing requires
546 in total (for redrawing the windows and the sprite) and release the resources.
548 @param aTestName the name of the test case
549 @param aIsOpaqueSprite the flag deciding whether the sprite is opaque or semitranparent
550 @param aOverlapUpdateArea the flag deciding whether the sprite overlaps the update area or not
552 void CTSpritePerf::FloatingSpriteTestL(const TDesC& aTestName, TBool aIsOpaqueSprite, TBool aOverlapUpdateArea)
554 TCleanupItem cleanupScreenDevice(CleanupScreenDevice,&iWsScreenDev);
555 CleanupStack::PushL(cleanupScreenDevice);
556 TCleanupItem cleanupWindowGroup(CleanupWindowGroup,&iWinGroup);
557 CleanupStack::PushL(cleanupWindowGroup);
558 SetUpWindowEnvironmentL(NULL);
560 TCleanupItem cleanupWindows(CleanupWindows,iWins);
561 CleanupStack::PushL(cleanupWindows);
562 ConstructArrayOfWindowsL(EFalse);
564 RWsSprite sprite(iWs);
565 CleanupClosePushL(sprite);
566 TPoint point=TPoint();
567 if (aOverlapUpdateArea)
569 //sprite is set to be right over the area off the top window, where the other windows overlap
570 TSize topWinSize= iWins[ENumWins-1]->Size();
571 point=TPoint(0,topWinSize.iHeight);
573 User::LeaveIfError(sprite.Construct(*iWinGroup,point,ESpriteNoChildClip));
575 CFbsBitmap* bitmap = new(ELeave) CFbsBitmap;
576 CleanupStack::PushL(bitmap);
577 User::LeaveIfError(bitmap->Create(iWsScreenDev->SizeInPixels(), iWsScreenDev->DisplayMode()));
578 User::LeaveIfError(bitmap->Load(TEST_BITMAP_NAME,0));
579 TSize bitmapSize=bitmap->SizeInPixels();
581 CFbsBitmap* bitmap2 = new(ELeave) CFbsBitmap;
582 CleanupStack::PushL(bitmap2);
583 User::LeaveIfError(bitmap2->Create(bitmapSize, iWsScreenDev->DisplayMode())); //blank bitmap
585 TSpriteMember member;
587 member.iBitmap=bitmap;
589 member.iMaskBitmap=bitmap2;
591 member.iMaskBitmap=bitmap;
592 member.iInvertMask=EFalse;
593 member.iDrawMode=CGraphicsContext::EDrawModePEN;
594 member.iOffset=TPoint();
595 member.iInterval=TTimeIntervalMicroSeconds32(200000);
596 User::LeaveIfError(sprite.AppendMember(member));
597 User::LeaveIfError(sprite.Activate()); //make the sprite visible
598 User::After(1000000);
600 iProfiler->InitResults();
601 for (TInt count=KIterationsToTest; count>=0; --count)
603 iProfiler->StartTimer();
604 //cause a screen area to be updated by rotating the background colour of the windows in the array
605 //apart from the colour of the top window
606 for (TInt i=0;i<ENumWins-1;i++)
608 TRgb tempBackColour = iBackColour[0];
610 iBackColour[i]=iBackColour[(i+1)%(ENumWins-1)];
612 iBackColour[ENumWins-2]=tempBackColour;
613 iWins[i]->SetBackgroundColor(iBackColour[i]);
614 iWins[i]->Invalidate();
615 iWins[i]->BeginRedraw();
616 iWins[i]->EndRedraw();
620 iProfiler->MarkResultSetL();
624 iProfiler->ResultsAnalysis(aTestName, 0, EColor16MA, EColor16MA, KIterationsToTest);
626 CleanupStack::PopAndDestroy(3); //sprite, bitmaps(2)
627 CleanupStack::Pop(3); //cleanup items(3)
628 ReleaseWindowsAndEnvironment();