Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
19 @internalComponent - Internal Symbian test code
24 #include "te_gesturegenerator.h"
28 _LIT(KSemaphore, "SemTScaleSync"); // Name of the global semaphore
30 const TInt KGestureGenerationLimit = 50;
32 // Test bitmap file location
33 _LIT(KBigBitmap,"z:\\resource\\apps\\uibench_s60_big.mbm");
34 _LIT(KTestStep0007,"GRAPHICS-UI-BENCH-S60-0007");
38 SetTestStepName(KTScale);
41 TVerdict CTScale::doTestStepPreambleL()
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();
48 TVerdict CTScale::doTestStepPostambleL()
51 return CTe_ConeStepBase::doTestStepPostambleL();
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.
60 TVerdict CTScale::doTestStepL()
62 iProfiler->InitResults();
63 // Use CGestureGenerator to simulate some horizontal drag pointer events.
64 GestureGenerator::SimulateFlickGestureL(iSemaphore, TPoint(0, 0),
65 TPoint(KGestureGenerationLimit, 0));
67 // now some vertical drag
68 GestureGenerator::SimulateFlickGestureL(iSemaphore, TPoint(KGestureGenerationLimit, 0),
69 TPoint(KGestureGenerationLimit, KGestureGenerationLimit));
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();
77 void CTScale::InitUIL(CCoeEnv* aCoeEnv)
79 iAppUi = new(ELeave) CScaleAppUi();
80 // iAppUi needs to be put on the cleanupstack until CCoeEnv takes ownership of iAppUi
81 CleanupStack::PushL(iAppUi);
83 CleanupStack::Pop(iAppUi);
84 aCoeEnv->SetAppUi(iAppUi);
88 CScaleControl* CScaleControl::NewL(const TRect& aRect,const CCoeControl* aParent)
90 CScaleControl* self = CScaleControl::NewLC(aRect,aParent);
91 CleanupStack::Pop(self);
95 CScaleControl* CScaleControl::NewLC(const TRect& aRect,const CCoeControl* aParent)
97 CScaleControl* self = new(ELeave) CScaleControl();
98 CleanupStack::PushL(self);
99 self->ConstructL(aRect,aParent);
103 CScaleControl::CScaleControl() : iWsSession(CCoeEnv::Static()->WsSession())
108 CScaleControl::~CScaleControl()
110 delete iSourceBitmap;
114 void CScaleControl::ConstructL(const TRect& aRect,const CCoeControl* aParent)
116 User::LeaveIfError(iSemaphore.OpenGlobal(KSemaphore));
117 // No owner, so create an own window
121 DrawableWindow()->PointerFilter(EPointerFilterDrag, 0);
125 // Use Parent's window
128 // This is component in a compound control
129 SetContainerWindowL(*aParent);
133 iSourceBitmap = new(ELeave) CFbsBitmap;
134 User::LeaveIfError(iSourceBitmap->Load(KBigBitmap, 0));
135 iSourceRect = iSourceBitmap->SizeInPixels();
136 iSourceRatio = (TReal)iSourceRect.Height()/(TReal)iSourceRect.Width();
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.
145 void CScaleControl::HandlePointerEventL(const TPointerEvent& aPointerEvent)
147 if(aPointerEvent.iType == TPointerEvent::EDrag)
149 if (iCurrentPointerPos.iY == aPointerEvent.iPosition.iY)
151 iSourceRect.Shrink(1,0);
152 // After shrinking the width, calculate amount to shrink height.
153 iSourceRect.Shrink(0, iSourceRect.Height() - (iSourceRect.Width()*iSourceRatio));
157 iSourceRect.Grow(1, 0);
158 iSourceRect.Grow(0, (iSourceRect.Width()*iSourceRatio) - iSourceRect.Height());
160 iCurrentPointerPos = aPointerEvent.iPosition;
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
169 * Scales and draws the bitmap to the screen.
170 * @param aRect Region that covered by this control
172 void CScaleControl::Draw(const TRect& aRect) const
174 CWindowGc& gc = SystemGc();
175 gc.DrawBitmap(aRect, iSourceBitmap, iSourceRect); // scale and draw the bitmap
178 TInt CScaleControl::Iterations()
184 CScaleAppUi::CScaleAppUi()
189 void CScaleAppUi::ConstructL()
191 BaseConstructL(ENoAppResourceFile);
192 iScale = CScaleControl::NewL(TRect(CTWindow::GetDisplaySizeInPixels()));
196 CScaleAppUi::~CScaleAppUi()
198 RemoveFromStack(iScale);
202 CScaleControl* CScaleAppUi::ScaleControl()