|
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". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // |
|
15 |
|
16 /** |
|
17 @file |
|
18 @test |
|
19 @internalComponent - Internal Symbian test code |
|
20 */ |
|
21 |
|
22 #include "tredrawing.h" |
|
23 |
|
24 const TInt KIconSeparationInPixels = 18; |
|
25 const TInt KIconSizePlusSeparation = 34; |
|
26 |
|
27 // Test bitmap files |
|
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"); |
|
31 |
|
32 const TInt KIterationsToTest = 500; |
|
33 |
|
34 // |
|
35 // CRedrawingTest |
|
36 // |
|
37 CRedrawingTest::CRedrawingTest() |
|
38 { |
|
39 SetTestStepName(KRedrawingTest); |
|
40 } |
|
41 |
|
42 CRedrawingTest::~CRedrawingTest() |
|
43 { |
|
44 delete iWsClient; |
|
45 } |
|
46 |
|
47 inline CTProfiler& CRedrawingTest::Profiler() const |
|
48 { |
|
49 return *iProfiler; |
|
50 } |
|
51 |
|
52 /** |
|
53 Override of base class virtual |
|
54 |
|
55 @return - TVerdict code |
|
56 */ |
|
57 TVerdict CRedrawingTest::doTestStepPreambleL() |
|
58 { |
|
59 CTe_graphicsperformanceSuiteStepBase::doTestStepPreambleL(); |
|
60 SetScreenModeL(EColor16MU); |
|
61 return TestStepResult(); |
|
62 } |
|
63 |
|
64 TVerdict CRedrawingTest::doTestStepL() |
|
65 { |
|
66 /** |
|
67 @SYMTestCaseID GRAPHICS-UI-BENCH-0060 |
|
68 @SYMTestType UT |
|
69 @SYMTestPriority Critical |
|
70 @SYMDEF DEF100017 |
|
71 @SYMTestCaseDesc Measures performance of redraws with bitblt |
|
72 @SYMTestActions |
|
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. |
|
76 |
|
77 @SYMTestExpectedResults |
|
78 Measure the performance of swapping the windows so that front window goes behind the back window. |
|
79 */ |
|
80 SetTestStepID(_L("GRAPHICS-UI-BENCH-0060")); |
|
81 RunRedrawWindowTestCaseL(_L("Redraw-Bitblt"), ETwoWindowBitblt); |
|
82 RecordTestResultL(); |
|
83 |
|
84 /** |
|
85 @SYMTestCaseID GRAPHICS-UI-BENCH-0061 |
|
86 @SYMTestType UT |
|
87 @SYMTestPriority Critical |
|
88 @SYMDEF DEF100017 |
|
89 @SYMTestCaseDesc Measures performance of redraws with bitblt masked |
|
90 @SYMTestActions |
|
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. |
|
94 |
|
95 @SYMTestExpectedResults |
|
96 Measure the performance of swapping the windows so that front window goes behind the back window. |
|
97 */ |
|
98 SetTestStepID(_L("GRAPHICS-UI-BENCH-0061")); |
|
99 RunRedrawWindowTestCaseL(_L("Redraw-BitbltMasked"), ETwoWindowBitbltMasked); |
|
100 RecordTestResultL(); |
|
101 |
|
102 /** |
|
103 @SYMTestCaseID GRAPHICS-UI-BENCH-0062 |
|
104 @SYMTestType UT |
|
105 @SYMTestPriority Critical |
|
106 @SYMDEF DEF100017 |
|
107 @SYMTestCaseDesc Measures performance of redraws of window with many small bitmaps |
|
108 |
|
109 @SYMTestActions |
|
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. |
|
113 |
|
114 @SYMTestExpectedResults |
|
115 Measure the performance of invalidating a small region of the window. |
|
116 */ |
|
117 SetTestStepID(_L("GRAPHICS-UI-BENCH-0062")); |
|
118 RunRedrawWindowTestCaseL(_L("Redraw-ManyBitmapsBitblt"), ETwoWindowManyBitmapsBitblt); |
|
119 RecordTestResultL(); |
|
120 |
|
121 return TestStepResult(); |
|
122 } |
|
123 |
|
124 /** |
|
125 This method runs the actual test case given the test name and test case Enum |
|
126 |
|
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 |
|
129 */ |
|
130 void CRedrawingTest::RunRedrawWindowTestCaseL(const TDesC& aTestName, TRedrawTestCase aTestCase) |
|
131 { |
|
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); |
|
138 delete iWsClient; |
|
139 iWsClient=NULL; |
|
140 } |
|
141 |
|
142 // |
|
143 // CWsRedrawer |
|
144 // |
|
145 CWsRedrawer::CWsRedrawer() : CActive(CActive::EPriorityLow) |
|
146 { |
|
147 } |
|
148 |
|
149 void CWsRedrawer::ConstructL(CWsClient* aClient) |
|
150 { |
|
151 iClient = aClient; |
|
152 CActiveScheduler::Add(this); |
|
153 IssueRequest(); |
|
154 } |
|
155 |
|
156 CWsRedrawer::~CWsRedrawer() |
|
157 { |
|
158 Cancel(); |
|
159 } |
|
160 |
|
161 void CWsRedrawer::IssueRequest() |
|
162 { |
|
163 iClient->WsSession().RedrawReady(&iStatus); |
|
164 SetActive(); |
|
165 } |
|
166 |
|
167 void CWsRedrawer::DoCancel() |
|
168 { |
|
169 iClient->WsSession().RedrawReadyCancel(); |
|
170 } |
|
171 |
|
172 void CWsRedrawer::RunL() |
|
173 { |
|
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 |
|
178 if (window) |
|
179 { |
|
180 TRect rect=redrawEvent.Rect(); // and rectangle that needs redrawing |
|
181 // now do drawing |
|
182 iClient->Gc().Activate(window->Window()); |
|
183 window->Window().BeginRedraw(rect); |
|
184 window->Draw(rect); |
|
185 window->Window().EndRedraw(); |
|
186 iClient->Gc().Deactivate(); |
|
187 } |
|
188 // maintain outstanding request |
|
189 IssueRequest(); |
|
190 } |
|
191 |
|
192 // |
|
193 // CWindow |
|
194 // |
|
195 CWindow::CWindow(CWsClient* aClient, TRedrawTestCase aTestCase) |
|
196 : iClient(aClient), iTestCase(aTestCase) |
|
197 { |
|
198 } |
|
199 |
|
200 void CWindow::ConstructL (const TRect& aRect, CWindow* aParent) |
|
201 { |
|
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)); |
|
207 iRect = aRect; |
|
208 iWindow.SetExtent(iRect.iTl, iRect.Size()); // set extent relative to group coords |
|
209 } |
|
210 |
|
211 CWindow::~CWindow() |
|
212 { |
|
213 iWindow.Close(); |
|
214 } |
|
215 |
|
216 RWindow& CWindow::Window() |
|
217 { |
|
218 return iWindow; |
|
219 } |
|
220 |
|
221 void CWindow::Activate() |
|
222 { |
|
223 iWindow.Activate(); |
|
224 } |
|
225 |
|
226 CWindowGc& CWindow::SystemGc() |
|
227 { |
|
228 return iClient->Gc(); |
|
229 } |
|
230 |
|
231 // |
|
232 // CMainWindow |
|
233 // |
|
234 CMainWindow::CMainWindow(CWsClient* aClient, TRedrawTestCase aTestCase) : CWindow (aClient, aTestCase) |
|
235 { |
|
236 } |
|
237 |
|
238 void CMainWindow::ConstructL(const TRect& aRect, CWindow* aParent) |
|
239 { |
|
240 CWindow::ConstructL(aRect,aParent); |
|
241 iBitmapImage = iClient->TestSuite().LoadBitmapL(KAlphaTestBitmap,0); |
|
242 } |
|
243 |
|
244 CMainWindow::~CMainWindow() |
|
245 { |
|
246 delete iBitmapImage; |
|
247 } |
|
248 |
|
249 void CMainWindow::Draw(const TRect& aRect) |
|
250 { |
|
251 CWindowGc& gc=SystemGc(); |
|
252 gc.SetClippingRect(aRect); |
|
253 gc.BitBlt(TPoint(0,0), iBitmapImage); |
|
254 } |
|
255 |
|
256 // |
|
257 // CTestWindow |
|
258 // |
|
259 CTestWindow::CTestWindow(CWsClient* aClient, TRedrawTestCase aTestCase) : CWindow (aClient, aTestCase) |
|
260 { |
|
261 } |
|
262 |
|
263 void CTestWindow::ConstructL(const TRect& aRect, CWindow* aParent) |
|
264 { |
|
265 CWindow::ConstructL(aRect,aParent); |
|
266 // Load all bitmaps |
|
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); |
|
272 } |
|
273 |
|
274 CTestWindow::~CTestWindow() |
|
275 { |
|
276 delete iBitmapImage; |
|
277 delete iBitmap12bit; |
|
278 delete iAlpha8bitMask; |
|
279 delete i16x16Icon; |
|
280 delete i16x16IconMonochrome; |
|
281 iWindow.Close(); |
|
282 } |
|
283 |
|
284 void CTestWindow::Draw(const TRect& aRect) |
|
285 { |
|
286 CWindowGc& gc=SystemGc(); |
|
287 gc.SetClippingRect(aRect); |
|
288 |
|
289 // -*-* Add new test cases here for drawing to test window |
|
290 switch(iTestCase) |
|
291 { |
|
292 case ETwoWindowBitblt: |
|
293 gc.BitBlt(TPoint(0,0), iBitmapImage); |
|
294 break; |
|
295 |
|
296 case ETwoWindowBitbltMasked: |
|
297 { |
|
298 TRect cropTo(0,0,300,300); |
|
299 gc.BitBltMasked(TPoint(0,0), iBitmapImage, cropTo, iAlpha8bitMask, EFalse); |
|
300 break; |
|
301 } |
|
302 |
|
303 case ETwoWindowManyBitmapsBitblt: |
|
304 { |
|
305 // Draw a matrix of bitmaps in the window |
|
306 for (TInt y=10;y>=0;--y) |
|
307 { |
|
308 for (TInt x=10;x>=0;--x) |
|
309 { |
|
310 if (!iBitmapFlag) |
|
311 gc.BitBlt(TPoint(x*KIconSeparationInPixels, y*KIconSeparationInPixels), i16x16Icon); |
|
312 else |
|
313 gc.BitBlt(TPoint(x*KIconSeparationInPixels, y*KIconSeparationInPixels), i16x16IconMonochrome); |
|
314 } |
|
315 } |
|
316 iBitmapFlag=!iBitmapFlag; |
|
317 break; |
|
318 } |
|
319 |
|
320 } |
|
321 |
|
322 } |
|
323 |
|
324 /** |
|
325 Create an application initiated draw by drawing doign a bitblt in a small area of the window |
|
326 */ |
|
327 void CTestWindow::AppInitiatedDraw() |
|
328 { |
|
329 TRect rect(KIconSeparationInPixels,KIconSeparationInPixels,KIconSizePlusSeparation,KIconSizePlusSeparation); |
|
330 CWindowGc& gc=SystemGc(); |
|
331 gc.Activate(iWindow); |
|
332 iWindow.BeginRedraw(rect); |
|
333 if (!iBitmapFlag) |
|
334 gc.BitBlt(TPoint(KIconSeparationInPixels,KIconSeparationInPixels), i16x16IconMonochrome); |
|
335 else |
|
336 gc.BitBlt(TPoint(KIconSeparationInPixels,KIconSeparationInPixels), i16x16Icon); |
|
337 iWindow.EndRedraw(); |
|
338 gc.Deactivate(); |
|
339 iBitmapFlag=!iBitmapFlag; |
|
340 } |
|
341 |
|
342 // |
|
343 // CWsClient |
|
344 // |
|
345 CWsClient::CWsClient(CRedrawingTest& aTestSuite, TRedrawTestCase aTestCase) : CActive(CActive::EPriorityHigh), iTestCase(aTestCase), iTestSuite(aTestSuite) |
|
346 { |
|
347 } |
|
348 |
|
349 void CWsClient::ConstructL() |
|
350 { |
|
351 CActiveScheduler::Add(this); |
|
352 |
|
353 // Connect to windows server |
|
354 User::LeaveIfError(iWs.Connect()); |
|
355 |
|
356 // construct our one and only window group |
|
357 iGroup=RWindowGroup(iWs); |
|
358 User::LeaveIfError(iGroup.Construct(2,ETrue)); // meaningless handle; enable focus |
|
359 |
|
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 |
|
364 |
|
365 iRect = TRect(0,0,iScreen->SizeInPixels().iWidth, iScreen->SizeInPixels().iHeight); |
|
366 |
|
367 // construct redrawer |
|
368 iRedrawer=new (ELeave) CWsRedrawer; |
|
369 iRedrawer->ConstructL(this); |
|
370 |
|
371 // construct main window |
|
372 ConstructMainWindowL(); |
|
373 |
|
374 // request first event and start scheduler |
|
375 IssueRequest(); |
|
376 } |
|
377 |
|
378 CWsClient::~CWsClient() |
|
379 { |
|
380 Cancel(); |
|
381 delete iGc; |
|
382 delete iScreen; |
|
383 delete iRedrawer; |
|
384 delete iMainWindow; |
|
385 delete iTestWindow; |
|
386 delete iTestWindow2; |
|
387 delete iTestActive; |
|
388 |
|
389 iGroup.Close(); |
|
390 iWs.Close(); |
|
391 } |
|
392 |
|
393 void CWsClient::IssueRequest() |
|
394 { |
|
395 iWs.EventReady(&iStatus); // request an event for standard events. i.e. All events except redraws and pointer priority key events |
|
396 SetActive(); |
|
397 } |
|
398 |
|
399 void CWsClient::DoCancel() |
|
400 { |
|
401 iWs.EventReadyCancel(); // cancel event request |
|
402 } |
|
403 |
|
404 void CWsClient::ConstructMainWindowL() |
|
405 { |
|
406 iTestActive = new(ELeave)CWsClient::CRedrawingTestActive(*this); |
|
407 iTestActive->ConstructL(); |
|
408 |
|
409 // -*-* Add new windows for test cases here |
|
410 switch (iTestCase) |
|
411 { |
|
412 case ETwoWindowBitblt: |
|
413 case ETwoWindowBitbltMasked: |
|
414 { |
|
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(); |
|
419 |
|
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(); |
|
426 |
|
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(); |
|
433 break; |
|
434 } |
|
435 |
|
436 case ETwoWindowManyBitmapsBitblt: |
|
437 { |
|
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(); |
|
442 |
|
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(); |
|
449 |
|
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(); |
|
456 } |
|
457 break; |
|
458 } |
|
459 } |
|
460 |
|
461 // Handle standard events from the window server. |
|
462 // Standard events include all events except redraws and priority key events. |
|
463 void CWsClient::RunL() |
|
464 { |
|
465 } |
|
466 |
|
467 // |
|
468 // CWsClient::CRedrawingTestActive inner class |
|
469 // Set to low priority to avoid starving other active objects from being executed. |
|
470 // |
|
471 CWsClient::CRedrawingTestActive::CRedrawingTestActive(CWsClient& aClient) : CActive(CActive::EPriorityLow), iClient(aClient) |
|
472 { |
|
473 CActiveScheduler::Add(this); |
|
474 } |
|
475 |
|
476 CWsClient::CRedrawingTestActive::~CRedrawingTestActive() |
|
477 { |
|
478 Cancel(); |
|
479 } |
|
480 |
|
481 void CWsClient::CRedrawingTestActive::ConstructL() |
|
482 { |
|
483 iClient.iTestSuite.Profiler().InitResults(); |
|
484 // Start active object and run tests |
|
485 RequestComplete(); |
|
486 } |
|
487 |
|
488 void CWsClient::CRedrawingTestActive::DoCancel() |
|
489 { |
|
490 TRequestStatus* status = &iStatus; |
|
491 User::RequestComplete(status, KErrCancel); |
|
492 } |
|
493 |
|
494 void CWsClient::CRedrawingTestActive::RequestComplete() |
|
495 { |
|
496 SetActive(); |
|
497 TRequestStatus* status = &iStatus; |
|
498 User::RequestComplete(status, KErrNone); |
|
499 } |
|
500 |
|
501 /** |
|
502 The test iterates KIterationsToTest times, after which the active scheduler is stopped |
|
503 which passes control back to CRedrawingTest. |
|
504 */ |
|
505 void CWsClient::CRedrawingTestActive::RunL() |
|
506 { |
|
507 TInt status = iStatus.Int(); |
|
508 if (status==KErrNone) |
|
509 { |
|
510 switch(iClient.iTestCase) |
|
511 { |
|
512 // -*-* Add test cases here |
|
513 case ETwoWindowBitblt: |
|
514 case ETwoWindowBitbltMasked: |
|
515 TestTwoWindowsBitBlt(); |
|
516 break; |
|
517 case ETwoWindowManyBitmapsBitblt: |
|
518 TestInvalidateSmallArea(); |
|
519 break; |
|
520 } |
|
521 |
|
522 if (++iIterationCount > KIterationsToTest) // If we reached last iteration then stop the active scheduler |
|
523 { |
|
524 CActiveScheduler::Stop(); |
|
525 } |
|
526 } |
|
527 RequestComplete(); |
|
528 } |
|
529 |
|
530 /** |
|
531 This flips the window ordinals around each time it is called |
|
532 */ |
|
533 void CWsClient::CRedrawingTestActive::TestTwoWindowsBitBlt() |
|
534 { |
|
535 if (iFlipWindow) |
|
536 { |
|
537 iClient.iTestWindow->Window().SetOrdinalPosition(0); |
|
538 iClient.iTestWindow2->Window().SetOrdinalPosition(1); |
|
539 iFlipWindow=EFalse; |
|
540 } |
|
541 else |
|
542 { |
|
543 iClient.iTestWindow->Window().SetOrdinalPosition(1); |
|
544 iClient.iTestWindow2->Window().SetOrdinalPosition(0); |
|
545 iFlipWindow=ETrue; |
|
546 } |
|
547 iClient.iWs.Flush(); |
|
548 } |
|
549 |
|
550 /** |
|
551 This invalidates a small area of the window and causes an appication initiated draw |
|
552 */ |
|
553 void CWsClient::CRedrawingTestActive::TestInvalidateSmallArea() |
|
554 { |
|
555 iClient.iTestWindow->Window().Invalidate(TRect(KIconSeparationInPixels,KIconSeparationInPixels,KIconSizePlusSeparation,KIconSizePlusSeparation)); |
|
556 // Application inititated draw |
|
557 iClient.iTestWindow->AppInitiatedDraw(); |
|
558 |
|
559 iClient.iWs.Flush(); |
|
560 } |