|
1 // Copyright (c) 2005-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 |
|
23 #include "tscale.h" |
|
24 #include "te_gesturegenerator.h" |
|
25 #include "twindow.h" |
|
26 |
|
27 |
|
28 _LIT(KSemaphore, "SemTScaleSync"); // Name of the global semaphore |
|
29 |
|
30 const TInt KGestureGenerationLimit = 50; |
|
31 |
|
32 // Test bitmap file location |
|
33 _LIT(KBigBitmap,"z:\\resource\\apps\\uibench_s60_big.mbm"); |
|
34 _LIT(KTestStep0007,"GRAPHICS-UI-BENCH-S60-0007"); |
|
35 |
|
36 CTScale::CTScale() |
|
37 { |
|
38 SetTestStepName(KTScale); |
|
39 } |
|
40 |
|
41 TVerdict CTScale::doTestStepPreambleL() |
|
42 { |
|
43 // The semaphore has to be created before, otherwise the control can't open it. |
|
44 TESTNOERRORL(iSemaphore.CreateGlobal(KSemaphore, 0)); |
|
45 return CTe_ConeStepBase::doTestStepPreambleL(); |
|
46 } |
|
47 |
|
48 TVerdict CTScale::doTestStepPostambleL() |
|
49 { |
|
50 iSemaphore.Close(); |
|
51 return CTe_ConeStepBase::doTestStepPostambleL(); |
|
52 } |
|
53 |
|
54 /** |
|
55 @SYMTestCaseID GRAPHICS-UI-BENCH-S60-0007 |
|
56 @SYMTestCaseDesc Measures the time for scaling in reaction to pointer events. |
|
57 @SYMTestActions Simulate horizontal and vertical drag pointer events and scales a bitmap. |
|
58 @SYMTestExpectedResults Measure and display the average framerate for the whole test. |
|
59 */ |
|
60 TVerdict CTScale::doTestStepL() |
|
61 { |
|
62 iProfiler->InitResults(); |
|
63 // Use CGestureGenerator to simulate some horizontal drag pointer events. |
|
64 GestureGenerator::SimulateFlickGestureL(iSemaphore, TPoint(0, 0), |
|
65 TPoint(KGestureGenerationLimit, 0)); |
|
66 |
|
67 // now some vertical drag |
|
68 GestureGenerator::SimulateFlickGestureL(iSemaphore, TPoint(KGestureGenerationLimit, 0), |
|
69 TPoint(KGestureGenerationLimit, KGestureGenerationLimit)); |
|
70 |
|
71 iProfiler->MarkResultSetL(); |
|
72 TSize screenSize = CTWindow::GetDisplaySizeInPixels(); |
|
73 iProfiler->ResultsAnalysisFrameRate(KTestStep0007, 0, 0, 0, iAppUi->ScaleControl()->Iterations(), screenSize.iWidth * screenSize.iHeight); |
|
74 return TestStepResult(); |
|
75 } |
|
76 |
|
77 void CTScale::InitUIL(CCoeEnv* aCoeEnv) |
|
78 { |
|
79 iAppUi = new(ELeave) CScaleAppUi(); |
|
80 // iAppUi needs to be put on the cleanupstack until CCoeEnv takes ownership of iAppUi |
|
81 CleanupStack::PushL(iAppUi); |
|
82 iAppUi->ConstructL(); |
|
83 CleanupStack::Pop(iAppUi); |
|
84 aCoeEnv->SetAppUi(iAppUi); |
|
85 } |
|
86 |
|
87 |
|
88 CScaleControl* CScaleControl::NewL(const TRect& aRect,const CCoeControl* aParent) |
|
89 { |
|
90 CScaleControl* self = CScaleControl::NewLC(aRect,aParent); |
|
91 CleanupStack::Pop(self); |
|
92 return self; |
|
93 } |
|
94 |
|
95 CScaleControl* CScaleControl::NewLC(const TRect& aRect,const CCoeControl* aParent) |
|
96 { |
|
97 CScaleControl* self = new(ELeave) CScaleControl(); |
|
98 CleanupStack::PushL(self); |
|
99 self->ConstructL(aRect,aParent); |
|
100 return self; |
|
101 } |
|
102 |
|
103 CScaleControl::CScaleControl() : iWsSession(CCoeEnv::Static()->WsSession()) |
|
104 { |
|
105 // empty |
|
106 } |
|
107 |
|
108 CScaleControl::~CScaleControl() |
|
109 { |
|
110 delete iSourceBitmap; |
|
111 iSemaphore.Close(); |
|
112 } |
|
113 |
|
114 void CScaleControl::ConstructL(const TRect& aRect,const CCoeControl* aParent) |
|
115 { |
|
116 User::LeaveIfError(iSemaphore.OpenGlobal(KSemaphore)); |
|
117 // No owner, so create an own window |
|
118 if(!aParent) |
|
119 { |
|
120 CreateWindowL(); |
|
121 DrawableWindow()->PointerFilter(EPointerFilterDrag, 0); |
|
122 SetRect(aRect); |
|
123 ActivateL(); |
|
124 } |
|
125 // Use Parent's window |
|
126 else |
|
127 { |
|
128 // This is component in a compound control |
|
129 SetContainerWindowL(*aParent); |
|
130 SetRect(aRect); |
|
131 } |
|
132 |
|
133 iSourceBitmap = new(ELeave) CFbsBitmap; |
|
134 User::LeaveIfError(iSourceBitmap->Load(KBigBitmap, 0)); |
|
135 iSourceRect = iSourceBitmap->SizeInPixels(); |
|
136 iSourceRatio = (TReal)iSourceRect.Height()/(TReal)iSourceRect.Width(); |
|
137 } |
|
138 |
|
139 /** |
|
140 * Compute the new zoom rectangle based on the type of pointer event. |
|
141 * Horizontal events make the source rectangle smaller (zooming in) |
|
142 * and vertical events make it larger (zooming out). |
|
143 * @param aPointerEvent Current Pointer position. |
|
144 */ |
|
145 void CScaleControl::HandlePointerEventL(const TPointerEvent& aPointerEvent) |
|
146 { |
|
147 if(aPointerEvent.iType == TPointerEvent::EDrag) |
|
148 { |
|
149 if (iCurrentPointerPos.iY == aPointerEvent.iPosition.iY) |
|
150 { |
|
151 iSourceRect.Shrink(1,0); |
|
152 // After shrinking the width, calculate amount to shrink height. |
|
153 iSourceRect.Shrink(0, iSourceRect.Height() - (iSourceRect.Width()*iSourceRatio)); |
|
154 } |
|
155 else |
|
156 { |
|
157 iSourceRect.Grow(1, 0); |
|
158 iSourceRect.Grow(0, (iSourceRect.Width()*iSourceRatio) - iSourceRect.Height()); |
|
159 } |
|
160 iCurrentPointerPos = aPointerEvent.iPosition; |
|
161 } |
|
162 DrawNow(); // Draws the entire control |
|
163 iWsSession.Finish(); // Wait until WServ has finished drawing |
|
164 iIterations++; // Update frame counter |
|
165 iSemaphore.Signal(); // Signal test that control was drawn |
|
166 } |
|
167 |
|
168 /** |
|
169 * Scales and draws the bitmap to the screen. |
|
170 * @param aRect Region that covered by this control |
|
171 */ |
|
172 void CScaleControl::Draw(const TRect& aRect) const |
|
173 { |
|
174 CWindowGc& gc = SystemGc(); |
|
175 gc.DrawBitmap(aRect, iSourceBitmap, iSourceRect); // scale and draw the bitmap |
|
176 } |
|
177 |
|
178 TInt CScaleControl::Iterations() |
|
179 { |
|
180 return iIterations; |
|
181 } |
|
182 |
|
183 |
|
184 CScaleAppUi::CScaleAppUi() |
|
185 { |
|
186 // empty |
|
187 } |
|
188 |
|
189 void CScaleAppUi::ConstructL() |
|
190 { |
|
191 BaseConstructL(ENoAppResourceFile); |
|
192 iScale = CScaleControl::NewL(TRect(CTWindow::GetDisplaySizeInPixels())); |
|
193 AddToStackL(iScale); |
|
194 } |
|
195 |
|
196 CScaleAppUi::~CScaleAppUi() |
|
197 { |
|
198 RemoveFromStack(iScale); |
|
199 delete iScale; |
|
200 } |
|
201 |
|
202 CScaleControl* CScaleAppUi::ScaleControl() |
|
203 { |
|
204 return iScale; |
|
205 } |