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 "ttranslucent.h"
24 const TInt KIterationsToTest = 100;
29 CTTranslucent::CTTranslucent()
31 SetTestStepName(KTTranslucent);
34 CTTranslucent::~CTTranslucent()
36 iWindowArray.ResetAndDestroy();
49 Override of base class virtual
51 @return - TVerdict code
53 TVerdict CTTranslucent::doTestStepPreambleL()
55 CTe_graphicsperformanceSuiteStepBase::doTestStepPreambleL();
56 SetScreenModeL(EColor16MU);
57 return TestStepResult();
60 TVerdict CTTranslucent::doTestStepL()
62 User::LeaveIfError(iWsSession.Connect());
64 iWindowGroup=RWindowGroup(iWsSession);
65 User::LeaveIfError(iWindowGroup.Construct(2, ETrue)); // meaningless handle; enable focus
67 // construct screen device and graphics context
68 iScreen=new (ELeave) CWsScreenDevice(iWsSession); // make device for this session
69 User::LeaveIfError(iScreen->Construct()); // and complete its construction
70 User::LeaveIfError(iScreen->CreateContext(iGc)); // create graphics context
72 iScreenRect = TRect(0,0,iScreen->SizeInPixels().iWidth, iScreen->SizeInPixels().iHeight);
74 // Construct a gradient bitmap for use by bitmap test
75 CFbsBitmap* bitmap = new (ELeave) CFbsBitmap;
76 CleanupStack::PushL(bitmap);
77 User::LeaveIfError(bitmap->Create(TSize(80,80), EColor16MA));
78 CTe_graphicsperformanceSuiteStepBase::VerticalGradientAlphaL(bitmap, TRgb(0x000000ff), TRgb(0xff000000));
81 CleanupStack::Pop(bitmap);
84 @SYMTestCaseID GRAPHICS-UI-BENCH-0132
86 @SYMTestCaseDesc Measures time taken to redraw 2, 8, 32 and 144 blank translucent
87 partially overlapping windows.
89 1. Create blank translucent partially overlapping windows.
90 2. Cover them all with an "ontop" window.
91 3. Hide the "ontop" window and measure time taken to redraw all overlapping windows underneath.
92 4. Repeat KIterationsToTest times and calculate average time per iteration.
94 @SYMTestExpectedResults
95 As the number of windows increases, so should the time taken to redraw them.
97 SetTestStepID(_L("GRAPHICS-UI-BENCH-0132"));
98 RunTestCaseL(_L("Redraw-BlankWindows2"), EBlankWindows, 2, 1);
99 RunTestCaseL(_L("Redraw-BlankWindows8"), EBlankWindows, 2, 4);
100 RunTestCaseL(_L("Redraw-BlankWindows32"), EBlankWindows, 4, 8);
101 RunTestCaseL(_L("Redraw-BlankWindows144"), EBlankWindows, 12, 12);
105 @SYMTestCaseID GRAPHICS-UI-BENCH-0133
107 @SYMTestCaseDesc Measures time taken to redraw 2, 8, 32 and 144 translucent
108 partially overlapping windows containing drawn text.
110 1. Create translucent partially overlapping windows.
111 2. Cover them all with an "ontop" window.
112 3. Hide the "ontop" window and measure time taken to redraw all overlapping windows underneath.
113 4. Repeat KIterationsToTest times and calculate average time per iteration.
115 @SYMTestExpectedResults
116 As the number of windows increases, so should the time taken to redraw them.
118 SetTestStepID(_L("GRAPHICS-UI-BENCH-0133"));
119 RunTestCaseL(_L("Redraw-TextWindows2"), ETextWindows, 2, 1);
120 RunTestCaseL(_L("Redraw-TextWindows8"), ETextWindows, 2, 4);
121 RunTestCaseL(_L("Redraw-TextWindows32"), ETextWindows, 4, 8);
122 RunTestCaseL(_L("Redraw-TextWindows144"), ETextWindows, 12, 12);
126 @SYMTestCaseID GRAPHICS-UI-BENCH-0134
128 @SYMTestCaseDesc Measures time taken to redraw 2, 8, 32 and 144 translucent
129 partially overlapping windows containing drawn ellipsis.
131 1. Create translucent partially overlapping windows.
132 2. Cover them all with an "ontop" window.
133 3. Hide the "ontop" window and measure time taken to redraw all overlapping windows underneath.
134 4. Repeat KIterationsToTest times and calculate average time per iteration.
136 @SYMTestExpectedResults
137 As the number of windows increases, so should the time taken to redraw them.
139 SetTestStepID(_L("GRAPHICS-UI-BENCH-0134"));
140 RunTestCaseL(_L("Redraw-EllipseWindows2"), EEllipseWindows, 2, 1);
141 RunTestCaseL(_L("Redraw-EllipseWindows8"), EEllipseWindows, 2, 4);
142 RunTestCaseL(_L("Redraw-EllipseWindows32"), EEllipseWindows, 4, 8);
143 RunTestCaseL(_L("Redraw-EllipseWindows144"), EEllipseWindows, 12, 12);
147 @SYMTestCaseID GRAPHICS-UI-BENCH-0135
149 @SYMTestCaseDesc Measures time taken to redraw 2, 8, 32 and 144 translucent
150 partially overlapping windows containing bitmaps.
152 1. Create translucent partially overlapping windows.
153 2. Cover them all with an "ontop" window.
154 3. Hide the "ontop" window and measure time taken to redraw all overlapping windows underneath.
155 4. Repeat KIterationsToTest times and calculate average time per iteration.
157 @SYMTestExpectedResults
158 As the number of windows increases, so should the time taken to redraw them.
160 SetTestStepID(_L("GRAPHICS-UI-BENCH-0135"));
161 RunTestCaseL(_L("Redraw-BitmapWindows2"), EBitmapWindows, 2, 1);
162 RunTestCaseL(_L("Redraw-BitmapWindows8"), EBitmapWindows, 2, 4);
163 RunTestCaseL(_L("Redraw-BitmapWindows32"), EBitmapWindows, 4, 8);
164 RunTestCaseL(_L("Redraw-BitmapWindows144"), EBitmapWindows, 12, 12);
167 return TestStepResult();
170 void CTTranslucent::RunTestCaseL(const TDesC& aTestName, TTestCase aTestCase, TInt aHorizontalWindows, TInt aVerticalWindows)
172 iTestCase = aTestCase;
174 ConstructWindowsL(aHorizontalWindows, aVerticalWindows);
175 iWsSession.Finish(); // Make sure all windows are drawn in their initial state/positions
177 iProfiler->InitResults();
179 // Measure time taken to redraw all overlapping translucent windows
180 // and repeat KIterationsToTest times
181 for (int i = 0; i < KIterationsToTest; i++)
183 iProfiler->StartTimer();
184 iTopWindow->Window().SetVisible(EFalse); // hide ontop window to cause overlapping translucent windows to be redrawn
186 iProfiler->MarkResultSetL();
188 iTopWindow->Window().SetVisible(ETrue); // show ontop window
192 iProfiler->ResultsAnalysis(aTestName, 0, 0, ScreenDevice()->BitmapDevice().DisplayMode(), KIterationsToTest);
197 void CTTranslucent::ConstructWindowsL(TInt aHorizontalWindows, TInt aVerticalWindows)
199 // Create a yellow opaque window to use as the background for the translucent windows
200 iBottomWindow = new (ELeave) CWin(iWsSession, iWindowGroup);
201 iBottomWindow->ConstructL(iScreenRect);
202 iBottomWindow->Window().SetBackgroundColor(TRgb(255, 255, 0));
203 iBottomWindow->Window().SetOrdinalPosition(-1);
204 iBottomWindow->Window().Invalidate();
205 iBottomWindow->Window().BeginRedraw();
206 iBottomWindow->Window().EndRedraw();
207 iBottomWindow->Window().Activate();
209 // Create some green partially overlapping translucent windows.
210 // Each window has roughly the same aspect ratio as the screen.
211 // Each window is the same size for every test, regardless of how many windows are being created.
213 // Maximum number of windows horizontally and vertically that we want to be able to fit onto
214 // the screen. Window size is calculated based on screen width/height and number of windows we want
215 // to fit in with the desired overlap.
216 // KMaxWindows * KMaxWindows gives the total maximum number of windows that will fit on screen without
218 const TInt KMaxWindows = 12;
220 // Calculate 1/4 width of each window
221 const TInt KQuarterWidth = iScreenRect.Width() / (KMaxWindows + 3);
222 // Calculate 1/4 height of each window
223 const TInt KQuarterHeight = iScreenRect.Height() / (KMaxWindows + 3);
225 TRect rect(0, 0, 0, 0);
228 // Calculate size used for all translucent windows
229 TSize size(KQuarterWidth*4, KQuarterHeight*4);
232 for (hCount = 0; hCount < aHorizontalWindows; hCount++)
235 for (vCount = 0; vCount < aVerticalWindows; vCount++)
237 // Construct a vertical column of windows
238 CWin* win = new(ELeave) CWin(iWsSession, iWindowGroup);
239 CleanupStack::PushL(win);
240 iWindowArray.AppendL(win);
241 CleanupStack::Pop(win);
242 rect.iTl = TPoint(x, y);
244 win->ConstructL(rect);
245 User::LeaveIfError(win->Window().SetTransparencyAlphaChannel());
246 win->Window().SetBackgroundColor(TRgb(0, 255, 0, 16));
248 TRect clipRect(size);
249 DrawWindowL(win, clipRect);
250 win->Window().Activate();
256 // Create a red opaque window ontop of all the others
257 iTopWindow = new (ELeave) CWin(iWsSession, iWindowGroup);
258 iTopWindow->ConstructL(iScreenRect);
259 iTopWindow->Window().SetBackgroundColor(TRgb(255, 0, 0));
260 iTopWindow->Window().SetOrdinalPosition(0);
261 iTopWindow->Window().Invalidate();
262 iTopWindow->Window().BeginRedraw();
263 iTopWindow->Window().EndRedraw();
264 iTopWindow->Window().Activate();
267 void CTTranslucent::DestroyWindows()
269 iWindowArray.ResetAndDestroy();
272 delete iBottomWindow;
273 iBottomWindow = NULL;
276 void CTTranslucent::DrawWindowL(CWin* aWindow, const TRect& aRect)
278 iGc->Activate(aWindow->Window());
279 iGc->SetClippingRect(aRect);
280 aWindow->Window().Invalidate();
281 aWindow->Window().BeginRedraw();
283 // Draw the whole window
287 break; // Don't draw anything on the blank windows
293 fontSpec.iHeight = 300;
294 User::LeaveIfError(iGc->Device()->GetNearestFontToDesignHeightInTwips(font, fontSpec));
296 iGc->DrawText(_L("Text"), TPoint(0,20));
297 iGc->DrawText(_L("window"), TPoint(0,40));
299 iGc->Device()->ReleaseFont(font);
303 case EEllipseWindows:
304 iGc->SetPenColor(TRgb(0, 0, 0, 255));
305 iGc->SetBrushColor(TRgb(128, 128, 255, 128));
306 iGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
307 iGc->DrawEllipse(TRect(0,0,79,79));
308 iGc->DrawEllipse(TRect(10,10,69,69));
309 iGc->DrawEllipse(TRect(20,20,59,59));
310 iGc->DrawEllipse(TRect(30,30,49,49));
311 iGc->SetBrushColor(TRgb(255, 0, 0, 150));
312 iGc->SetBrushStyle(CGraphicsContext::EDiamondCrossHatchBrush);
313 iGc->DrawEllipse(TRect(0,0,20,15));
314 iGc->DrawEllipse(TRect(30,10,50,30));
317 iGc->BitBlt(TPoint(0,0), iBitmap);
321 aWindow->Window().EndRedraw();
328 CTTranslucent::CWin::CWin(RWsSession& aWsSession, RWindowGroup& aWindowGroup)
329 :iWsSession(aWsSession), iWindowGroup(aWindowGroup)
333 CTTranslucent::CWin::~CWin()
338 void CTTranslucent::CWin::ConstructL (const TRect& aRect)
340 iWindow=RWindow(iWsSession);
341 User::LeaveIfError(iWindow.Construct(iWindowGroup, (TUint32)this));
343 iWindow.SetExtent(iRect.iTl, iRect.Size());
346 RWindow& CTTranslucent::CWin::Window()