os/graphics/graphicstest/uibench/s60/src/tests_scale/tscale.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/graphicstest/uibench/s60/src/tests_scale/tscale.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,205 @@
     1.4 +// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +/**
    1.20 + @file
    1.21 + @test
    1.22 + @internalComponent - Internal Symbian test code 
    1.23 +*/
    1.24 +
    1.25 +
    1.26 +#include "tscale.h"
    1.27 +#include "te_gesturegenerator.h"
    1.28 +#include "twindow.h"
    1.29 +
    1.30 +
    1.31 +_LIT(KSemaphore, "SemTScaleSync"); // Name of the global semaphore
    1.32 +
    1.33 +const TInt KGestureGenerationLimit = 50;
    1.34 +
    1.35 +// Test bitmap file location
    1.36 +_LIT(KBigBitmap,"z:\\resource\\apps\\uibench_s60_big.mbm");
    1.37 +_LIT(KTestStep0007,"GRAPHICS-UI-BENCH-S60-0007");
    1.38 +
    1.39 +CTScale::CTScale()
    1.40 +	{
    1.41 +	SetTestStepName(KTScale);	
    1.42 +	}
    1.43 +
    1.44 +TVerdict CTScale::doTestStepPreambleL()
    1.45 +    {
    1.46 +    // The semaphore has to be created before, otherwise the control can't open it.
    1.47 +    TESTNOERRORL(iSemaphore.CreateGlobal(KSemaphore, 0));
    1.48 +    return CTe_ConeStepBase::doTestStepPreambleL();
    1.49 +    }
    1.50 +
    1.51 +TVerdict CTScale::doTestStepPostambleL()
    1.52 +    {
    1.53 +    iSemaphore.Close();
    1.54 +    return CTe_ConeStepBase::doTestStepPostambleL(); 
    1.55 +    }
    1.56 +
    1.57 +/**
    1.58 +   @SYMTestCaseID GRAPHICS-UI-BENCH-S60-0007
    1.59 +   @SYMTestCaseDesc Measures the time for scaling in reaction to pointer events.
    1.60 +   @SYMTestActions Simulate horizontal and vertical drag pointer events and scales a bitmap.
    1.61 +   @SYMTestExpectedResults Measure and display the average framerate for the whole test.
    1.62 +*/
    1.63 +TVerdict CTScale::doTestStepL()
    1.64 +	{
    1.65 +	iProfiler->InitResults();
    1.66 +    // Use CGestureGenerator to simulate some horizontal drag pointer events.
    1.67 +	GestureGenerator::SimulateFlickGestureL(iSemaphore, TPoint(0, 0), 
    1.68 +	    TPoint(KGestureGenerationLimit, 0));
    1.69 +    
    1.70 +    // now some vertical drag
    1.71 +	GestureGenerator::SimulateFlickGestureL(iSemaphore, TPoint(KGestureGenerationLimit, 0), 
    1.72 +    	    TPoint(KGestureGenerationLimit, KGestureGenerationLimit));
    1.73 +    
    1.74 +	iProfiler->MarkResultSetL();
    1.75 +    TSize screenSize = CTWindow::GetDisplaySizeInPixels();
    1.76 +    iProfiler->ResultsAnalysisFrameRate(KTestStep0007, 0, 0, 0, iAppUi->ScaleControl()->Iterations(), screenSize.iWidth * screenSize.iHeight);
    1.77 +    return TestStepResult();
    1.78 +	} 
    1.79 +
    1.80 +void CTScale::InitUIL(CCoeEnv* aCoeEnv)
    1.81 +	{
    1.82 +  	iAppUi = new(ELeave) CScaleAppUi();
    1.83 +  	// iAppUi needs to be put on the cleanupstack until CCoeEnv takes ownership of iAppUi
    1.84 +  	CleanupStack::PushL(iAppUi);
    1.85 +   	iAppUi->ConstructL();
    1.86 +   	CleanupStack::Pop(iAppUi);
    1.87 +   	aCoeEnv->SetAppUi(iAppUi);
    1.88 +  	}
    1.89 +
    1.90 +
    1.91 +CScaleControl* CScaleControl::NewL(const TRect& aRect,const CCoeControl* aParent)
    1.92 +    {
    1.93 +    CScaleControl* self = CScaleControl::NewLC(aRect,aParent);
    1.94 +    CleanupStack::Pop(self);
    1.95 +    return self;
    1.96 +    }
    1.97 + 
    1.98 +CScaleControl* CScaleControl::NewLC(const TRect& aRect,const CCoeControl* aParent)
    1.99 +    {
   1.100 +    CScaleControl* self = new(ELeave) CScaleControl();
   1.101 +    CleanupStack::PushL(self);
   1.102 +    self->ConstructL(aRect,aParent);
   1.103 +    return self;
   1.104 +    }
   1.105 + 
   1.106 +CScaleControl::CScaleControl() : iWsSession(CCoeEnv::Static()->WsSession())
   1.107 +	{
   1.108 +	// empty
   1.109 +    }
   1.110 + 
   1.111 +CScaleControl::~CScaleControl()
   1.112 +    {
   1.113 +    delete iSourceBitmap;
   1.114 +    iSemaphore.Close();
   1.115 +    }
   1.116 + 
   1.117 +void CScaleControl::ConstructL(const TRect& aRect,const CCoeControl* aParent)
   1.118 +    {
   1.119 +    User::LeaveIfError(iSemaphore.OpenGlobal(KSemaphore));
   1.120 +    // No owner, so create an own window
   1.121 +    if(!aParent)     
   1.122 +        {
   1.123 +        CreateWindowL();
   1.124 +        DrawableWindow()->PointerFilter(EPointerFilterDrag, 0);
   1.125 +        SetRect(aRect);
   1.126 +        ActivateL();
   1.127 +        }
   1.128 +    // Use Parent's window
   1.129 +    else
   1.130 +        {
   1.131 +        // This is component in a compound control
   1.132 +        SetContainerWindowL(*aParent);
   1.133 +        SetRect(aRect);
   1.134 +        }
   1.135 +    
   1.136 +    iSourceBitmap = new(ELeave) CFbsBitmap;
   1.137 +	User::LeaveIfError(iSourceBitmap->Load(KBigBitmap, 0));
   1.138 +    iSourceRect = iSourceBitmap->SizeInPixels();
   1.139 +    iSourceRatio = (TReal)iSourceRect.Height()/(TReal)iSourceRect.Width();    
   1.140 +    }
   1.141 + 
   1.142 +/**
   1.143 + * Compute the new zoom rectangle based on the type of pointer event.
   1.144 + * Horizontal events make the source rectangle smaller (zooming in)
   1.145 + * and vertical events make it larger (zooming out).
   1.146 + * @param aPointerEvent Current Pointer position.
   1.147 + */
   1.148 +void CScaleControl::HandlePointerEventL(const TPointerEvent& aPointerEvent)
   1.149 +	{
   1.150 +	if(aPointerEvent.iType == TPointerEvent::EDrag)
   1.151 +		{
   1.152 +		if (iCurrentPointerPos.iY == aPointerEvent.iPosition.iY)
   1.153 +			{
   1.154 +			iSourceRect.Shrink(1,0);
   1.155 +			// After shrinking the width, calculate amount to shrink height.
   1.156 +			iSourceRect.Shrink(0, iSourceRect.Height() - (iSourceRect.Width()*iSourceRatio));
   1.157 +			}
   1.158 +		else 
   1.159 +			{
   1.160 +			iSourceRect.Grow(1, 0);
   1.161 +		    iSourceRect.Grow(0, (iSourceRect.Width()*iSourceRatio) - iSourceRect.Height());
   1.162 +			}
   1.163 +		iCurrentPointerPos = aPointerEvent.iPosition;
   1.164 +		}	
   1.165 +	DrawNow(); // Draws the entire control
   1.166 +	iWsSession.Finish(); // Wait until WServ has finished drawing
   1.167 +	iIterations++; // Update frame counter
   1.168 +	iSemaphore.Signal(); // Signal test that control was drawn
   1.169 +	}
   1.170 +
   1.171 +/**
   1.172 + * Scales and draws the bitmap to the screen.
   1.173 + * @param aRect Region that covered by this control
   1.174 + */
   1.175 +void CScaleControl::Draw(const TRect& aRect) const
   1.176 +    {
   1.177 +    CWindowGc& gc = SystemGc();
   1.178 +    gc.DrawBitmap(aRect, iSourceBitmap, iSourceRect); // scale and draw the bitmap
   1.179 +    }
   1.180 +
   1.181 +TInt CScaleControl::Iterations()
   1.182 +    {
   1.183 +    return iIterations;
   1.184 +    }
   1.185 +
   1.186 +
   1.187 +CScaleAppUi::CScaleAppUi()
   1.188 +	{
   1.189 +	// empty
   1.190 +	}
   1.191 +
   1.192 +void CScaleAppUi::ConstructL()
   1.193 +    {
   1.194 +    BaseConstructL(ENoAppResourceFile);
   1.195 +    iScale = CScaleControl::NewL(TRect(CTWindow::GetDisplaySizeInPixels()));
   1.196 +    AddToStackL(iScale);
   1.197 +    } 
   1.198 +
   1.199 +CScaleAppUi::~CScaleAppUi()
   1.200 +	{
   1.201 +	RemoveFromStack(iScale);
   1.202 +	delete iScale;
   1.203 +	}
   1.204 +
   1.205 +CScaleControl* CScaleAppUi::ScaleControl()
   1.206 +    {
   1.207 +    return iScale;
   1.208 +    }