sl@0: // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: /** sl@0: @file sl@0: @test sl@0: @internalComponent - Internal Symbian test code sl@0: */ sl@0: sl@0: sl@0: #include "tscale.h" sl@0: #include "te_gesturegenerator.h" sl@0: #include "twindow.h" sl@0: sl@0: sl@0: _LIT(KSemaphore, "SemTScaleSync"); // Name of the global semaphore sl@0: sl@0: const TInt KGestureGenerationLimit = 50; sl@0: sl@0: // Test bitmap file location sl@0: _LIT(KBigBitmap,"z:\\resource\\apps\\uibench_s60_big.mbm"); sl@0: _LIT(KTestStep0007,"GRAPHICS-UI-BENCH-S60-0007"); sl@0: sl@0: CTScale::CTScale() sl@0: { sl@0: SetTestStepName(KTScale); sl@0: } sl@0: sl@0: TVerdict CTScale::doTestStepPreambleL() sl@0: { sl@0: // The semaphore has to be created before, otherwise the control can't open it. sl@0: TESTNOERRORL(iSemaphore.CreateGlobal(KSemaphore, 0)); sl@0: return CTe_ConeStepBase::doTestStepPreambleL(); sl@0: } sl@0: sl@0: TVerdict CTScale::doTestStepPostambleL() sl@0: { sl@0: iSemaphore.Close(); sl@0: return CTe_ConeStepBase::doTestStepPostambleL(); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID GRAPHICS-UI-BENCH-S60-0007 sl@0: @SYMTestCaseDesc Measures the time for scaling in reaction to pointer events. sl@0: @SYMTestActions Simulate horizontal and vertical drag pointer events and scales a bitmap. sl@0: @SYMTestExpectedResults Measure and display the average framerate for the whole test. sl@0: */ sl@0: TVerdict CTScale::doTestStepL() sl@0: { sl@0: iProfiler->InitResults(); sl@0: // Use CGestureGenerator to simulate some horizontal drag pointer events. sl@0: GestureGenerator::SimulateFlickGestureL(iSemaphore, TPoint(0, 0), sl@0: TPoint(KGestureGenerationLimit, 0)); sl@0: sl@0: // now some vertical drag sl@0: GestureGenerator::SimulateFlickGestureL(iSemaphore, TPoint(KGestureGenerationLimit, 0), sl@0: TPoint(KGestureGenerationLimit, KGestureGenerationLimit)); sl@0: sl@0: iProfiler->MarkResultSetL(); sl@0: TSize screenSize = CTWindow::GetDisplaySizeInPixels(); sl@0: iProfiler->ResultsAnalysisFrameRate(KTestStep0007, 0, 0, 0, iAppUi->ScaleControl()->Iterations(), screenSize.iWidth * screenSize.iHeight); sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: void CTScale::InitUIL(CCoeEnv* aCoeEnv) sl@0: { sl@0: iAppUi = new(ELeave) CScaleAppUi(); sl@0: // iAppUi needs to be put on the cleanupstack until CCoeEnv takes ownership of iAppUi sl@0: CleanupStack::PushL(iAppUi); sl@0: iAppUi->ConstructL(); sl@0: CleanupStack::Pop(iAppUi); sl@0: aCoeEnv->SetAppUi(iAppUi); sl@0: } sl@0: sl@0: sl@0: CScaleControl* CScaleControl::NewL(const TRect& aRect,const CCoeControl* aParent) sl@0: { sl@0: CScaleControl* self = CScaleControl::NewLC(aRect,aParent); sl@0: CleanupStack::Pop(self); sl@0: return self; sl@0: } sl@0: sl@0: CScaleControl* CScaleControl::NewLC(const TRect& aRect,const CCoeControl* aParent) sl@0: { sl@0: CScaleControl* self = new(ELeave) CScaleControl(); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aRect,aParent); sl@0: return self; sl@0: } sl@0: sl@0: CScaleControl::CScaleControl() : iWsSession(CCoeEnv::Static()->WsSession()) sl@0: { sl@0: // empty sl@0: } sl@0: sl@0: CScaleControl::~CScaleControl() sl@0: { sl@0: delete iSourceBitmap; sl@0: iSemaphore.Close(); sl@0: } sl@0: sl@0: void CScaleControl::ConstructL(const TRect& aRect,const CCoeControl* aParent) sl@0: { sl@0: User::LeaveIfError(iSemaphore.OpenGlobal(KSemaphore)); sl@0: // No owner, so create an own window sl@0: if(!aParent) sl@0: { sl@0: CreateWindowL(); sl@0: DrawableWindow()->PointerFilter(EPointerFilterDrag, 0); sl@0: SetRect(aRect); sl@0: ActivateL(); sl@0: } sl@0: // Use Parent's window sl@0: else sl@0: { sl@0: // This is component in a compound control sl@0: SetContainerWindowL(*aParent); sl@0: SetRect(aRect); sl@0: } sl@0: sl@0: iSourceBitmap = new(ELeave) CFbsBitmap; sl@0: User::LeaveIfError(iSourceBitmap->Load(KBigBitmap, 0)); sl@0: iSourceRect = iSourceBitmap->SizeInPixels(); sl@0: iSourceRatio = (TReal)iSourceRect.Height()/(TReal)iSourceRect.Width(); sl@0: } sl@0: sl@0: /** sl@0: * Compute the new zoom rectangle based on the type of pointer event. sl@0: * Horizontal events make the source rectangle smaller (zooming in) sl@0: * and vertical events make it larger (zooming out). sl@0: * @param aPointerEvent Current Pointer position. sl@0: */ sl@0: void CScaleControl::HandlePointerEventL(const TPointerEvent& aPointerEvent) sl@0: { sl@0: if(aPointerEvent.iType == TPointerEvent::EDrag) sl@0: { sl@0: if (iCurrentPointerPos.iY == aPointerEvent.iPosition.iY) sl@0: { sl@0: iSourceRect.Shrink(1,0); sl@0: // After shrinking the width, calculate amount to shrink height. sl@0: iSourceRect.Shrink(0, iSourceRect.Height() - (iSourceRect.Width()*iSourceRatio)); sl@0: } sl@0: else sl@0: { sl@0: iSourceRect.Grow(1, 0); sl@0: iSourceRect.Grow(0, (iSourceRect.Width()*iSourceRatio) - iSourceRect.Height()); sl@0: } sl@0: iCurrentPointerPos = aPointerEvent.iPosition; sl@0: } sl@0: DrawNow(); // Draws the entire control sl@0: iWsSession.Finish(); // Wait until WServ has finished drawing sl@0: iIterations++; // Update frame counter sl@0: iSemaphore.Signal(); // Signal test that control was drawn sl@0: } sl@0: sl@0: /** sl@0: * Scales and draws the bitmap to the screen. sl@0: * @param aRect Region that covered by this control sl@0: */ sl@0: void CScaleControl::Draw(const TRect& aRect) const sl@0: { sl@0: CWindowGc& gc = SystemGc(); sl@0: gc.DrawBitmap(aRect, iSourceBitmap, iSourceRect); // scale and draw the bitmap sl@0: } sl@0: sl@0: TInt CScaleControl::Iterations() sl@0: { sl@0: return iIterations; sl@0: } sl@0: sl@0: sl@0: CScaleAppUi::CScaleAppUi() sl@0: { sl@0: // empty sl@0: } sl@0: sl@0: void CScaleAppUi::ConstructL() sl@0: { sl@0: BaseConstructL(ENoAppResourceFile); sl@0: iScale = CScaleControl::NewL(TRect(CTWindow::GetDisplaySizeInPixels())); sl@0: AddToStackL(iScale); sl@0: } sl@0: sl@0: CScaleAppUi::~CScaleAppUi() sl@0: { sl@0: RemoveFromStack(iScale); sl@0: delete iScale; sl@0: } sl@0: sl@0: CScaleControl* CScaleAppUi::ScaleControl() sl@0: { sl@0: return iScale; sl@0: }