|
1 // Copyright (c) 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 <graphics/directgdidriver.h> |
|
23 #include <hal.h> |
|
24 #include "tflipframerate.h" |
|
25 |
|
26 #ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE |
|
27 const TInt KWindowGroupHandle = 1; |
|
28 const TInt KWindowHandle = 2; |
|
29 |
|
30 const TInt KTextPhraseFontSize = 40; |
|
31 const TReal KTextPhraseSpeed = 200.f; |
|
32 |
|
33 const TRgb KBackgroundColour = TRgb(255, 127, 0); // Orange |
|
34 const TRgb KBrushColour = TRgb(255, 255, 0); // Yellow |
|
35 const TRgb KPenColour = TRgb(0, 0, 255, 255); // Blue |
|
36 |
|
37 const TUint KMinFrames = 51;// uibench, needs more than 50 results for the trimmed mean |
|
38 |
|
39 _LIT(KTextPhrase, "Flip Performance"); |
|
40 |
|
41 TVerdict CTFlipFramerate::doTestStepPreambleL() |
|
42 { |
|
43 // Window related Setup |
|
44 // Connect to windows server session |
|
45 TESTL(KErrNone==iWs.Connect()); |
|
46 |
|
47 // Make device for this session |
|
48 iScreenDev = new (ELeave) CWsScreenDevice(iWs); |
|
49 TESTL(KErrNone==iScreenDev->Construct(KSgScreenIdMain)); |
|
50 |
|
51 // Create a window group |
|
52 iWinGroup = RWindowGroup(iWs); |
|
53 TESTL(KErrNone==iWinGroup.Construct(KWindowGroupHandle)); |
|
54 |
|
55 // Create a window with the window group as a parent |
|
56 iWindow = RWindow(iWs); |
|
57 TESTL(KErrNone==iWindow.Construct(iWinGroup, KWindowHandle)); |
|
58 |
|
59 // Activate window and set visible |
|
60 iWindow.Activate(); |
|
61 iWindow.SetVisible(ETrue); |
|
62 |
|
63 // Connect to surface update session |
|
64 TESTL(KErrNone==iUpdateSession.Connect()); |
|
65 CTDirectGdiTestBase::doTestStepPreambleL(); |
|
66 iContext = CDirectGdiContext::NewL(*iDGdiDriver); |
|
67 |
|
68 // Image Related Setup |
|
69 // Setup off screen image |
|
70 iSurfaceSize=iWindow.Size(); |
|
71 iImageInfo.iSizeInPixels = iSurfaceSize; |
|
72 iImageInfo.iPixelFormat = EUidPixelFormatXRGB_8888; |
|
73 iImageInfo.iCpuAccess = ESgCpuAccessNone; |
|
74 iImageInfo.iUsage = ESgUsageOpenGlesTarget| ESgUsageDirectGdiSource | ESgUsageDirectGdiTarget; |
|
75 iImageInfo.iShareable = ETrue; |
|
76 iImageInfo.iScreenId = iScreenDev->GetScreenNumber(); |
|
77 |
|
78 TESTL(KErrNone==iImgCol.Create(iImageInfo, 1)); |
|
79 TESTL(KErrNone==iImgCol.OpenImage(0, iImage)); |
|
80 |
|
81 TESTL(KErrNone==iDGdiImageTarget->Create(iImage)); |
|
82 |
|
83 TESTL(KErrNone==iSurfaceConfiguration.SetSurfaceId(iImgCol.SurfaceId())); |
|
84 TESTL(KErrNone==iSurfaceConfiguration.SetExtent(iWindow.Size())); |
|
85 |
|
86 GetFontL(); |
|
87 |
|
88 TInt fastCounterFrequency; |
|
89 TESTL(KErrNone==HAL::Get(HALData::EFastCounterFrequency, fastCounterFrequency)); |
|
90 |
|
91 // Initialise text scrolling variables |
|
92 iTextPhraseSpeed = KTextPhraseSpeed / fastCounterFrequency; |
|
93 iLastFrameTime = User::FastCounter(); |
|
94 |
|
95 return TestStepResult(); |
|
96 } |
|
97 |
|
98 TVerdict CTFlipFramerate::doTestStepPostambleL() |
|
99 { |
|
100 iImage.Close(); |
|
101 iImgCol.Close(); |
|
102 |
|
103 CTDirectGdiTestBase::doTestStepPostambleL(); |
|
104 |
|
105 delete iContext; |
|
106 iWindow.Close(); |
|
107 iWinGroup.Close(); |
|
108 |
|
109 iUpdateSession.Close(); |
|
110 delete iScreenDev; |
|
111 iWs.Close(); |
|
112 |
|
113 iTsStore->ReleaseFont(iFont); |
|
114 delete iTsStore; |
|
115 iTsStore = NULL; |
|
116 return TestStepResult(); |
|
117 } |
|
118 |
|
119 /** |
|
120 Set-up a font to be used in the rendering |
|
121 */ |
|
122 void CTFlipFramerate::GetFontL() |
|
123 { |
|
124 _LIT(KFontFamily, "NewCourier"); |
|
125 iTsStore = CFbsTypefaceStore::NewL(NULL); |
|
126 TFontSpec spec(KFontFamily, KTextPhraseFontSize); |
|
127 spec.iFontStyle.SetBitmapType(EAntiAliasedGlyphBitmap); |
|
128 spec.iFontStyle.SetStrokeWeight(EStrokeWeightBold); |
|
129 TESTL(KErrNone==iTsStore->GetNearestFontInPixels(iFont, spec)); |
|
130 |
|
131 iTextPhraseLength = iFont->MeasureText(KTextPhrase, NULL, NULL); |
|
132 } |
|
133 |
|
134 /** |
|
135 Draw some content |
|
136 */ |
|
137 void CTFlipFramerate::RenderL() |
|
138 { |
|
139 iContext->Activate(*iDGdiImageTarget); |
|
140 iContext->SetBrushColor(KBackgroundColour); |
|
141 iContext->Clear(); |
|
142 |
|
143 // Draw Text |
|
144 iContext->SetFont(iFont); |
|
145 iContext->SetBrushStyle(DirectGdi::ENullBrush); |
|
146 TPoint textPos(iTextPos,iSurfaceSize.iHeight/2); |
|
147 |
|
148 TReal fastCounter = User::FastCounter(); |
|
149 |
|
150 if(fastCounter<iLastFrameTime) |
|
151 { |
|
152 // Handle single roll-over of fastcounter |
|
153 TReal actualCount = static_cast<TReal>(KMaxTUint) + fastCounter; |
|
154 iTextPos+=(iTextPhraseSpeed * (actualCount-iLastFrameTime)); |
|
155 } |
|
156 else |
|
157 { |
|
158 iTextPos+=(iTextPhraseSpeed * (fastCounter-iLastFrameTime)); |
|
159 } |
|
160 |
|
161 iContext->SetBrushColor(KBrushColour); |
|
162 iContext->SetPenColor(KPenColour); |
|
163 iContext->DrawText(KTextPhrase,NULL, textPos); |
|
164 |
|
165 // Update the last frame time, used to animate that which is drawn in RenderL() |
|
166 iLastFrameTime = User::FastCounter(); |
|
167 |
|
168 iDGdiDriver->Finish(); |
|
169 } |
|
170 |
|
171 /* |
|
172 Set the size of the displayed window as a fraction of the screens size. |
|
173 |
|
174 @param aWindowSizeDivisor Controls the displayed window size |
|
175 */ |
|
176 void CTFlipFramerate::SetSizeL(const TScreenSizeDivisors aWindowSizeDivisor) |
|
177 { |
|
178 TSize size = iScreenDev->SizeInPixels(); |
|
179 size.iHeight/=aWindowSizeDivisor; |
|
180 size.iWidth/=aWindowSizeDivisor; |
|
181 iWindow.SetSize(size); |
|
182 iImageInfo.iSizeInPixels = size; |
|
183 TESTL(KErrNone==iSurfaceConfiguration.SetExtent(size)); |
|
184 } |
|
185 |
|
186 /* |
|
187 Time how long it takes to display a submitted update |
|
188 |
|
189 @param aIsFlipped Whether or not the surface is to be vertically flipped before it it displayed |
|
190 @param aWindowSizeDivisor Controls the displayed window size to be tested |
|
191 @param aOrientation The surface rotation to be tested |
|
192 @param aStepName The name of the test, for logging. |
|
193 */ |
|
194 void CTFlipFramerate::TestFramerateOrientationL( const TFlipped aIsFlipped, |
|
195 const TScreenSizeDivisors aWindowSizeDivisor, |
|
196 const CFbsBitGc::TGraphicsOrientation aOrientation) |
|
197 { |
|
198 // Simulate small sized window (e.g. like video call) and implicitly disable fast pathing. |
|
199 SetSizeL(aWindowSizeDivisor); |
|
200 |
|
201 // Set-up the timer |
|
202 iProfiler->InitResults(); |
|
203 |
|
204 TESTL(KErrNone==iSurfaceConfiguration.SetOrientation(aOrientation)); |
|
205 TESTL(KErrNone==iSurfaceConfiguration.SetFlip(aIsFlipped)); |
|
206 TESTL(KErrNone==iWindow.SetBackgroundSurface(iSurfaceConfiguration, ETrue)); |
|
207 |
|
208 TRequestStatus availabilityStatus; |
|
209 TRequestStatus displayedStatus; |
|
210 TTimeStamp dummyTimeStamp; |
|
211 TInt framesDone=0; |
|
212 |
|
213 iUpdateSession.NotifyWhenAvailable(availabilityStatus); |
|
214 TESTL(KErrNone==iUpdateSession.SubmitUpdate(KSgScreenIdMain, iImgCol.SurfaceId(), 0)); |
|
215 |
|
216 // uibench, needs more than 50 results for the trimmed mean, so repeat as required. |
|
217 while(framesDone < KMinFrames) |
|
218 { |
|
219 iTextPos = -iTextPhraseLength; // enter stage left |
|
220 |
|
221 // scroll the text from left to right across the surface. |
|
222 while(iTextPos<=iSurfaceSize.iWidth) |
|
223 { |
|
224 User::WaitForRequest(availabilityStatus); |
|
225 // Draw something |
|
226 RenderL(); |
|
227 |
|
228 // Request Notifications |
|
229 iUpdateSession.NotifyWhenAvailable(availabilityStatus); |
|
230 iUpdateSession.NotifyWhenDisplayed(displayedStatus, dummyTimeStamp); |
|
231 |
|
232 // Start Timer & Submit Update |
|
233 iProfiler->StartTimer(); |
|
234 TESTL(KErrNone==iUpdateSession.SubmitUpdate(KSgScreenIdMain, iImgCol.SurfaceId(), 0)); |
|
235 |
|
236 // Wait for the update to have been displayed and stop the timer |
|
237 User::WaitForRequest(displayedStatus); |
|
238 iProfiler->MarkResultSetL(); |
|
239 framesDone++; |
|
240 } |
|
241 } |
|
242 iProfiler->ResultsAnalysis(KTFlipFramerate,aOrientation,ENone,iScreenDev->CurrentScreenMode(),framesDone); |
|
243 } |
|
244 |
|
245 void CTFlipFramerate::TestStepFramerateL( const TFlipped aIsFlipped, |
|
246 const TScreenSizeDivisors aWindowSizeDivisor, |
|
247 const TDesC& aStepName) |
|
248 { |
|
249 SetTestStepID(aStepName); |
|
250 TestFramerateOrientationL(aIsFlipped, aWindowSizeDivisor, CFbsBitGc::EGraphicsOrientationNormal); |
|
251 TestFramerateOrientationL(aIsFlipped, aWindowSizeDivisor, CFbsBitGc::EGraphicsOrientationRotated90); |
|
252 TestFramerateOrientationL(aIsFlipped, aWindowSizeDivisor, CFbsBitGc::EGraphicsOrientationRotated180); |
|
253 TestFramerateOrientationL(aIsFlipped, aWindowSizeDivisor, CFbsBitGc::EGraphicsOrientationRotated270); |
|
254 RecordTestResultL(); |
|
255 } |
|
256 #endif |
|
257 |
|
258 TVerdict CTFlipFramerate::doTestStepL() |
|
259 { |
|
260 #ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE |
|
261 INFO_PRINTF1(_L("CTBitBltPerfDirectGdi can only be run with RSgImage legacy")); |
|
262 return TestStepResult(); |
|
263 #else |
|
264 // Test to allow comparison between flipped and non-flipped performance |
|
265 // This is because camera data needs to be flipped abuot vertical axis to show the user what they expect, |
|
266 // e.g. during a voice call. |
|
267 // No API exists for a flip about a vertical axis so this is achieved by a flip about horizontal axis, |
|
268 // and a 180degree rotation. |
|
269 // Therefore this test generates results for flipped and non-flipped performance at all four orientations. |
|
270 // Additionally it tests at both full screen and quarter screen. It does this for two reasons :- |
|
271 // 1) Full screen, non-flipped, non-rotated can be (and at the time of writing is) fast-pathed. |
|
272 // This makes it awkward to use as a comparison. |
|
273 // 2) Some use-cases are likely to use a non-fullscreen window, e.g. voice call. |
|
274 #ifdef __WINS__ |
|
275 INFO_PRINTF1(_L("Fullscreen, NotFlipped")); |
|
276 TestStepFramerateL(ENotFlipped,EScreensizeFull,_L("GRAPHICS-UI-BENCH-0173")); |
|
277 INFO_PRINTF1(_L("Fullscreen, Flipped")); |
|
278 TestStepFramerateL(EFlipped,EScreensizeFull,_L("GRAPHICS-UI-BENCH-0174")); |
|
279 INFO_PRINTF1(_L("Quarterscreen, NotFlipped")); |
|
280 TestStepFramerateL(ENotFlipped,EScreenSizeQuarter,_L("GRAPHICS-UI-BENCH-0175")); |
|
281 INFO_PRINTF1(_L("Quarterscreen, Flipped")); |
|
282 TestStepFramerateL(EFlipped,EScreenSizeQuarter,_L("GRAPHICS-UI-BENCH-0176")); |
|
283 |
|
284 CloseTMSGraphicsStep(); |
|
285 return TestStepResult(); |
|
286 #else |
|
287 INFO_PRINTF1(_L("Flip tests are running on emulator only, tests skipped.")); |
|
288 return TestStepResult(); |
|
289 #endif |
|
290 #endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE |
|
291 } |
|
292 |