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