Update contrib.
1 // Copyright (c) 2006-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 "tredrawing.h"
24 const TInt KIconSeparationInPixels = 18;
25 const TInt KIconSizePlusSeparation = 34;
28 _LIT(KAlphaTestBitmap,"z:\\system\\data\\uibench_24bit.mbm");
29 _LIT(K12BitBitmap, "z:\\system\\data\\uibench_12bit.mbm");
30 _LIT(K16x16Icon,"z:\\system\\data\\16x16icon.mbm");
32 const TInt KIterationsToTest = 500;
37 CRedrawingTest::CRedrawingTest()
39 SetTestStepName(KRedrawingTest);
42 CRedrawingTest::~CRedrawingTest()
47 inline CTProfiler& CRedrawingTest::Profiler() const
53 Override of base class virtual
55 @return - TVerdict code
57 TVerdict CRedrawingTest::doTestStepPreambleL()
59 CTe_graphicsperformanceSuiteStepBase::doTestStepPreambleL();
60 SetScreenModeL(EColor16MU);
61 return TestStepResult();
64 TVerdict CRedrawingTest::doTestStepL()
67 @SYMTestCaseID GRAPHICS-UI-BENCH-0060
69 @SYMTestPriority Critical
71 @SYMTestCaseDesc Measures performance of redraws with bitblt
73 1. Create a background window with an opaque bitmap.
74 2. Create two test windows both transparent with bitmaps bitblt masked to the windows.
75 3. Repeatly swap the order of the two test windows in a loop and measure the average performance after many iterations.
77 @SYMTestExpectedResults
78 Measure the performance of swapping the windows so that front window goes behind the back window.
80 SetTestStepID(_L("GRAPHICS-UI-BENCH-0060"));
81 RunRedrawWindowTestCaseL(_L("Redraw-Bitblt"), ETwoWindowBitblt);
85 @SYMTestCaseID GRAPHICS-UI-BENCH-0061
87 @SYMTestPriority Critical
89 @SYMTestCaseDesc Measures performance of redraws with bitblt masked
91 1. Create a background window with an opaque bitmap.
92 2. Create two test windows both transparent with bitmaps bitblt masked to the windows.
93 3. Repeatly swap the order of the two test windows in a loop and measure the average performance after many iterations.
95 @SYMTestExpectedResults
96 Measure the performance of swapping the windows so that front window goes behind the back window.
98 SetTestStepID(_L("GRAPHICS-UI-BENCH-0061"));
99 RunRedrawWindowTestCaseL(_L("Redraw-BitbltMasked"), ETwoWindowBitbltMasked);
103 @SYMTestCaseID GRAPHICS-UI-BENCH-0062
105 @SYMTestPriority Critical
107 @SYMTestCaseDesc Measures performance of redraws of window with many small bitmaps
110 1. Create a background window with an opaque bitmap.
111 2. Create two test windows both transparent with many small bitmaps bitblt to the windows.
112 3. Repeatly invalidate a small region of the window in a loop and measure performance.
114 @SYMTestExpectedResults
115 Measure the performance of invalidating a small region of the window.
117 SetTestStepID(_L("GRAPHICS-UI-BENCH-0062"));
118 RunRedrawWindowTestCaseL(_L("Redraw-ManyBitmapsBitblt"), ETwoWindowManyBitmapsBitblt);
121 return TestStepResult();
125 This method runs the actual test case given the test name and test case Enum
127 @param aTestName is the test case name to be displayed in the log file - must be unique for each test case
128 @param aTestCase the test case to run
130 void CRedrawingTest::RunRedrawWindowTestCaseL(const TDesC& aTestName, TRedrawTestCase aTestCase)
132 iWsClient = new(ELeave) CWsClient(*this, aTestCase);
133 iProfiler->StartTimer();
134 iWsClient->ConstructL();
135 CActiveScheduler::Start(); // Starts the active schedule that starts the test
136 iProfiler->MarkResultSetL(); // Returns here once the test has completed.
137 iProfiler->ResultsAnalysisAverageByIterations(aTestName, 0, 0, ScreenDevice()->BitmapDevice().DisplayMode(), KIterationsToTest);
145 CWsRedrawer::CWsRedrawer() : CActive(CActive::EPriorityLow)
149 void CWsRedrawer::ConstructL(CWsClient* aClient)
152 CActiveScheduler::Add(this);
156 CWsRedrawer::~CWsRedrawer()
161 void CWsRedrawer::IssueRequest()
163 iClient->WsSession().RedrawReady(&iStatus);
167 void CWsRedrawer::DoCancel()
169 iClient->WsSession().RedrawReadyCancel();
172 void CWsRedrawer::RunL()
174 // find out what needs to be done
175 TWsRedrawEvent redrawEvent;
176 iClient->WsSession().GetRedraw(redrawEvent); // get event
177 CWindow* window=(CWindow*)(redrawEvent.Handle()); // get window
180 TRect rect=redrawEvent.Rect(); // and rectangle that needs redrawing
182 iClient->Gc().Activate(window->Window());
183 window->Window().BeginRedraw(rect);
185 window->Window().EndRedraw();
186 iClient->Gc().Deactivate();
188 // maintain outstanding request
195 CWindow::CWindow(CWsClient* aClient, TRedrawTestCase aTestCase)
196 : iClient(aClient), iTestCase(aTestCase)
200 void CWindow::ConstructL (const TRect& aRect, CWindow* aParent)
202 // If a parent window was specified, use it; if not, use the window group
203 // (aParent defaults to 0).
204 RWindowTreeNode* parent= aParent ? (RWindowTreeNode*) &(aParent->Window()) : &(iClient->WindowGroup());
205 iWindow=RWindow(iClient->WsSession()); // use app's session to window server
206 User::LeaveIfError(iWindow.Construct(*parent,(TUint32)this));
208 iWindow.SetExtent(iRect.iTl, iRect.Size()); // set extent relative to group coords
216 RWindow& CWindow::Window()
221 void CWindow::Activate()
226 CWindowGc& CWindow::SystemGc()
228 return iClient->Gc();
234 CMainWindow::CMainWindow(CWsClient* aClient, TRedrawTestCase aTestCase) : CWindow (aClient, aTestCase)
238 void CMainWindow::ConstructL(const TRect& aRect, CWindow* aParent)
240 CWindow::ConstructL(aRect,aParent);
241 iBitmapImage = iClient->TestSuite().LoadBitmapL(KAlphaTestBitmap,0);
244 CMainWindow::~CMainWindow()
249 void CMainWindow::Draw(const TRect& aRect)
251 CWindowGc& gc=SystemGc();
252 gc.SetClippingRect(aRect);
253 gc.BitBlt(TPoint(0,0), iBitmapImage);
259 CTestWindow::CTestWindow(CWsClient* aClient, TRedrawTestCase aTestCase) : CWindow (aClient, aTestCase)
263 void CTestWindow::ConstructL(const TRect& aRect, CWindow* aParent)
265 CWindow::ConstructL(aRect,aParent);
267 iBitmapImage = iClient->TestSuite().LoadBitmapL(KAlphaTestBitmap,0);
268 iBitmap12bit = iClient->TestSuite().LoadBitmapL(K12BitBitmap, 0);
269 iAlpha8bitMask = iClient->TestSuite().CopyIntoNewBitmapL(iBitmap12bit, EGray256);
270 i16x16Icon = iClient->TestSuite().LoadBitmapL(K16x16Icon, 0);
271 i16x16IconMonochrome = iClient->TestSuite().LoadBitmapL(K16x16Icon, 1);
274 CTestWindow::~CTestWindow()
278 delete iAlpha8bitMask;
280 delete i16x16IconMonochrome;
284 void CTestWindow::Draw(const TRect& aRect)
286 CWindowGc& gc=SystemGc();
287 gc.SetClippingRect(aRect);
289 // -*-* Add new test cases here for drawing to test window
292 case ETwoWindowBitblt:
293 gc.BitBlt(TPoint(0,0), iBitmapImage);
296 case ETwoWindowBitbltMasked:
298 TRect cropTo(0,0,300,300);
299 gc.BitBltMasked(TPoint(0,0), iBitmapImage, cropTo, iAlpha8bitMask, EFalse);
303 case ETwoWindowManyBitmapsBitblt:
305 // Draw a matrix of bitmaps in the window
306 for (TInt y=10;y>=0;--y)
308 for (TInt x=10;x>=0;--x)
311 gc.BitBlt(TPoint(x*KIconSeparationInPixels, y*KIconSeparationInPixels), i16x16Icon);
313 gc.BitBlt(TPoint(x*KIconSeparationInPixels, y*KIconSeparationInPixels), i16x16IconMonochrome);
316 iBitmapFlag=!iBitmapFlag;
325 Create an application initiated draw by drawing doign a bitblt in a small area of the window
327 void CTestWindow::AppInitiatedDraw()
329 TRect rect(KIconSeparationInPixels,KIconSeparationInPixels,KIconSizePlusSeparation,KIconSizePlusSeparation);
330 CWindowGc& gc=SystemGc();
331 gc.Activate(iWindow);
332 iWindow.BeginRedraw(rect);
334 gc.BitBlt(TPoint(KIconSeparationInPixels,KIconSeparationInPixels), i16x16IconMonochrome);
336 gc.BitBlt(TPoint(KIconSeparationInPixels,KIconSeparationInPixels), i16x16Icon);
339 iBitmapFlag=!iBitmapFlag;
345 CWsClient::CWsClient(CRedrawingTest& aTestSuite, TRedrawTestCase aTestCase) : CActive(CActive::EPriorityHigh), iTestCase(aTestCase), iTestSuite(aTestSuite)
349 void CWsClient::ConstructL()
351 CActiveScheduler::Add(this);
353 // Connect to windows server
354 User::LeaveIfError(iWs.Connect());
356 // construct our one and only window group
357 iGroup=RWindowGroup(iWs);
358 User::LeaveIfError(iGroup.Construct(2,ETrue)); // meaningless handle; enable focus
360 // construct screen device and graphics context
361 iScreen=new (ELeave) CWsScreenDevice(iWs); // make device for this session
362 User::LeaveIfError(iScreen->Construct()); // and complete its construction
363 User::LeaveIfError(iScreen->CreateContext(iGc)); // create graphics context
365 iRect = TRect(0,0,iScreen->SizeInPixels().iWidth, iScreen->SizeInPixels().iHeight);
367 // construct redrawer
368 iRedrawer=new (ELeave) CWsRedrawer;
369 iRedrawer->ConstructL(this);
371 // construct main window
372 ConstructMainWindowL();
374 // request first event and start scheduler
378 CWsClient::~CWsClient()
393 void CWsClient::IssueRequest()
395 iWs.EventReady(&iStatus); // request an event for standard events. i.e. All events except redraws and pointer priority key events
399 void CWsClient::DoCancel()
401 iWs.EventReadyCancel(); // cancel event request
404 void CWsClient::ConstructMainWindowL()
406 iTestActive = new(ELeave)CWsClient::CRedrawingTestActive(*this);
407 iTestActive->ConstructL();
409 // -*-* Add new windows for test cases here
412 case ETwoWindowBitblt:
413 case ETwoWindowBitbltMasked:
415 // Create the main background window with a bitmap image. This window is not transparent.
416 iMainWindow=new (ELeave) CMainWindow(this, iTestCase);
417 iMainWindow->ConstructL(iRect);
418 iMainWindow->Activate();
420 // Create the first test window. This window is transparent.
421 iTestWindow = new(ELeave) CTestWindow(this, iTestCase);
422 iTestWindow->ConstructL(TRect (TPoint (10, 10), TSize (200, 200)), iMainWindow);
423 TInt ret = iTestWindow->Window().SetTransparencyFactor(TRgb(0xbbbbbb,128));
424 User::LeaveIfError(ret);
425 iTestWindow->Activate();
427 // Create the second test window. This window is also transparent.
428 iTestWindow2 = new(ELeave) CTestWindow(this, iTestCase);
429 iTestWindow2->ConstructL(TRect (TPoint (30, 30), TSize (250, 200)), iMainWindow);
430 ret = iTestWindow2->Window().SetTransparencyFactor(TRgb(0xddaa55,200));
431 User::LeaveIfError(ret);
432 iTestWindow2->Activate();
436 case ETwoWindowManyBitmapsBitblt:
438 // Create the main background window with a bitmap image. This window is not transparent.
439 iMainWindow=new (ELeave) CMainWindow(this, iTestCase);
440 iMainWindow->ConstructL(iRect);
441 iMainWindow->Activate();
443 // Create the first test window. This window is transparent.
444 iTestWindow = new(ELeave) CTestWindow(this, iTestCase);
445 iTestWindow->ConstructL(TRect (TPoint (10, 10), TSize (200, 200)), iMainWindow);
446 TInt ret = iTestWindow->Window().SetTransparencyFactor(TRgb(0xbbbbbb,128));
447 User::LeaveIfError(ret);
448 iTestWindow->Activate();
450 // Create the second test window. This window is also transparent.
451 iTestWindow2 = new(ELeave) CTestWindow(this, iTestCase);
452 iTestWindow2->ConstructL(TRect (TPoint (10, 10), TSize (250, 200)), iMainWindow);
453 ret = iTestWindow2->Window().SetTransparencyFactor(TRgb(0xddaa55,200));
454 User::LeaveIfError(ret);
455 iTestWindow2->Activate();
461 // Handle standard events from the window server.
462 // Standard events include all events except redraws and priority key events.
463 void CWsClient::RunL()
468 // CWsClient::CRedrawingTestActive inner class
469 // Set to low priority to avoid starving other active objects from being executed.
471 CWsClient::CRedrawingTestActive::CRedrawingTestActive(CWsClient& aClient) : CActive(CActive::EPriorityLow), iClient(aClient)
473 CActiveScheduler::Add(this);
476 CWsClient::CRedrawingTestActive::~CRedrawingTestActive()
481 void CWsClient::CRedrawingTestActive::ConstructL()
483 iClient.iTestSuite.Profiler().InitResults();
484 // Start active object and run tests
488 void CWsClient::CRedrawingTestActive::DoCancel()
490 TRequestStatus* status = &iStatus;
491 User::RequestComplete(status, KErrCancel);
494 void CWsClient::CRedrawingTestActive::RequestComplete()
497 TRequestStatus* status = &iStatus;
498 User::RequestComplete(status, KErrNone);
502 The test iterates KIterationsToTest times, after which the active scheduler is stopped
503 which passes control back to CRedrawingTest.
505 void CWsClient::CRedrawingTestActive::RunL()
507 TInt status = iStatus.Int();
508 if (status==KErrNone)
510 switch(iClient.iTestCase)
512 // -*-* Add test cases here
513 case ETwoWindowBitblt:
514 case ETwoWindowBitbltMasked:
515 TestTwoWindowsBitBlt();
517 case ETwoWindowManyBitmapsBitblt:
518 TestInvalidateSmallArea();
522 if (++iIterationCount > KIterationsToTest) // If we reached last iteration then stop the active scheduler
524 CActiveScheduler::Stop();
531 This flips the window ordinals around each time it is called
533 void CWsClient::CRedrawingTestActive::TestTwoWindowsBitBlt()
537 iClient.iTestWindow->Window().SetOrdinalPosition(0);
538 iClient.iTestWindow2->Window().SetOrdinalPosition(1);
543 iClient.iTestWindow->Window().SetOrdinalPosition(1);
544 iClient.iTestWindow2->Window().SetOrdinalPosition(0);
551 This invalidates a small area of the window and causes an appication initiated draw
553 void CWsClient::CRedrawingTestActive::TestInvalidateSmallArea()
555 iClient.iTestWindow->Window().Invalidate(TRect(KIconSeparationInPixels,KIconSeparationInPixels,KIconSizePlusSeparation,KIconSizePlusSeparation));
556 // Application inititated draw
557 iClient.iTestWindow->AppInitiatedDraw();