os/graphics/graphicstest/uibench/s60/src/tests_pan/tpan.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) 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 "tpan.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, "SemTPanSync"); // 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(KTestStep0001,"GRAPHICS-UI-BENCH-S60-0001");
sl@0
    35
sl@0
    36
CTPan::CTPan()
sl@0
    37
	{
sl@0
    38
	SetTestStepName(KTPan);
sl@0
    39
	}
sl@0
    40
sl@0
    41
TVerdict CTPan::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 CTPan::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
    Override of base class pure virtual
sl@0
    56
    Our implementation only gets called if the base class doTestStepPreambleL() did
sl@0
    57
    not leave.
sl@0
    58
    
sl@0
    59
    @return - TVerdict code
sl@0
    60
*/
sl@0
    61
TVerdict CTPan::doTestStepL()
sl@0
    62
	{
sl@0
    63
	SetTestStepID(KTestStep0001);
sl@0
    64
	PanBitmapL();
sl@0
    65
	//RecordTestResultL(); // not possible because of heap panic
sl@0
    66
	return TestStepResult();
sl@0
    67
	}
sl@0
    68
sl@0
    69
/**
sl@0
    70
@SYMTestCaseID
sl@0
    71
GRAPHICS-UI-BENCH-S60-0001
sl@0
    72
sl@0
    73
@SYMTestCaseDesc
sl@0
    74
Tests how long it takes to pan a bitmap in reaction to pointer events.
sl@0
    75
sl@0
    76
@SYMTestActions
sl@0
    77
Create the bitmap and generate the pointer events. Depending on the location of the
sl@0
    78
pointer the bitmap is drawn to the screen. 
sl@0
    79
sl@0
    80
@SYMTestExpectedResults
sl@0
    81
Test should pass and display the average framerate for the whole test.
sl@0
    82
*/
sl@0
    83
void CTPan::PanBitmapL()
sl@0
    84
    {
sl@0
    85
    iProfiler->InitResults();
sl@0
    86
sl@0
    87
    // Simulate some horizontal drag pointer events
sl@0
    88
    GestureGenerator::SimulateFlickGestureL(iSemaphore, TPoint(0, 0),           
sl@0
    89
            TPoint(KGestureGenerationLimit, 0));
sl@0
    90
    // Simulate some vertical drag pointer events
sl@0
    91
    GestureGenerator::SimulateFlickGestureL(iSemaphore, TPoint(KGestureGenerationLimit, 0), 
sl@0
    92
            TPoint(KGestureGenerationLimit, KGestureGenerationLimit));   
sl@0
    93
    
sl@0
    94
    iProfiler->MarkResultSetL();
sl@0
    95
    TSize screenSize = CTWindow::GetDisplaySizeInPixels();
sl@0
    96
    iProfiler->ResultsAnalysisFrameRate(KTestStep0001, 0, 0, 0,
sl@0
    97
            iAppUi->PanControl()->Iterations(), screenSize.iWidth * screenSize.iHeight);
sl@0
    98
    }
sl@0
    99
sl@0
   100
void CTPan::InitUIL(CCoeEnv* aCoeEnv)
sl@0
   101
	{
sl@0
   102
	iAppUi = new(ELeave) CPanAppUi();
sl@0
   103
  	// iAppUi needs to be put on the cleanupstack until CCoeEnv takes ownership of iAppUi
sl@0
   104
  	CleanupStack::PushL(iAppUi);
sl@0
   105
  	iAppUi->ConstructL(TRect(CTWindow::GetDisplaySizeInPixels()));
sl@0
   106
   	CleanupStack::Pop(iAppUi);
sl@0
   107
   	aCoeEnv->SetAppUi(iAppUi);
sl@0
   108
  	}
sl@0
   109
sl@0
   110
//=============================================================================
sl@0
   111
sl@0
   112
CPanAppUi::CPanAppUi()
sl@0
   113
    {
sl@0
   114
    // empty
sl@0
   115
    }
sl@0
   116
sl@0
   117
CPanAppUi::~CPanAppUi()
sl@0
   118
    {
sl@0
   119
    RemoveFromStack(iPanControl);
sl@0
   120
    delete iPanControl;
sl@0
   121
    }
sl@0
   122
sl@0
   123
void CPanAppUi::ConstructL(const TRect& aRect)
sl@0
   124
    {
sl@0
   125
    BaseConstructL(ENoAppResourceFile);
sl@0
   126
    iPanControl = CPanControl::NewL(aRect);
sl@0
   127
    AddToStackL(iPanControl);
sl@0
   128
    }
sl@0
   129
sl@0
   130
CPanControl* CPanAppUi::PanControl()
sl@0
   131
    {
sl@0
   132
    return iPanControl;
sl@0
   133
    }
sl@0
   134
sl@0
   135
//=============================================================================
sl@0
   136
sl@0
   137
CPanControl* CPanControl::NewL(const TRect& aRect, const CCoeControl* aParent)
sl@0
   138
    {
sl@0
   139
    CPanControl* self = CPanControl::NewLC(aRect, aParent);
sl@0
   140
    CleanupStack::Pop(self);
sl@0
   141
    return self;
sl@0
   142
    }
sl@0
   143
 
sl@0
   144
CPanControl* CPanControl::NewLC(const TRect& aRect, const CCoeControl* aParent)
sl@0
   145
    {
sl@0
   146
    CPanControl* self = new(ELeave) CPanControl();
sl@0
   147
    CleanupStack::PushL(self);
sl@0
   148
    self->ConstructL(aRect, aParent);
sl@0
   149
    return self;
sl@0
   150
    }
sl@0
   151
 
sl@0
   152
CPanControl::CPanControl() : iWsSession(CCoeEnv::Static()->WsSession())
sl@0
   153
	{
sl@0
   154
	// empty
sl@0
   155
    }
sl@0
   156
 
sl@0
   157
CPanControl::~CPanControl()
sl@0
   158
    {
sl@0
   159
    delete iSourceBitmap;
sl@0
   160
    iSemaphore.Close();
sl@0
   161
    }
sl@0
   162
 
sl@0
   163
void CPanControl::ConstructL(const TRect& aRect, const CCoeControl* aParent)
sl@0
   164
    {
sl@0
   165
    User::LeaveIfError(iSemaphore.OpenGlobal(KSemaphore));
sl@0
   166
    iSourceBitmap = new(ELeave) CFbsBitmap;
sl@0
   167
    User::LeaveIfError(iSourceBitmap->Load(KBigBitmap, 0));
sl@0
   168
    
sl@0
   169
    // No owner, so create an own window
sl@0
   170
    if(!aParent)     
sl@0
   171
        {
sl@0
   172
        CreateWindowL();
sl@0
   173
        DrawableWindow()->PointerFilter(EPointerFilterDrag, 0);
sl@0
   174
        SetRect(aRect);
sl@0
   175
        ActivateL();
sl@0
   176
        }    
sl@0
   177
    else
sl@0
   178
        {
sl@0
   179
        // use parent window as compound control
sl@0
   180
        SetContainerWindowL(*aParent);
sl@0
   181
        SetRect(aRect);
sl@0
   182
        }
sl@0
   183
    }
sl@0
   184
 
sl@0
   185
void CPanControl::HandlePointerEventL(const TPointerEvent& aPointerEvent)
sl@0
   186
	{
sl@0
   187
	if((aPointerEvent.iType == TPointerEvent::EDrag) || (aPointerEvent.iType == TPointerEvent::EButton1Down))
sl@0
   188
        {
sl@0
   189
        iCurrentPointerPos = aPointerEvent.iPosition;
sl@0
   190
        }
sl@0
   191
	DrawNow(); // Draws the entire control
sl@0
   192
	iWsSession.Finish(); // Wait until WServ has finished drawing
sl@0
   193
	iIterations++; // Update frame counter
sl@0
   194
	iSemaphore.Signal(); // Signal test that control was drawn
sl@0
   195
	}
sl@0
   196
 
sl@0
   197
void CPanControl::Draw(const TRect& aRect) const
sl@0
   198
    {
sl@0
   199
    CWindowGc& gc = SystemGc();
sl@0
   200
    TRect sourceRect = Rect();
sl@0
   201
    sourceRect.Move(iCurrentPointerPos);
sl@0
   202
    gc.DrawBitmap(aRect, iSourceBitmap, sourceRect); 
sl@0
   203
    }
sl@0
   204
sl@0
   205
TInt CPanControl::Iterations()
sl@0
   206
    {
sl@0
   207
    return iIterations;
sl@0
   208
    }
sl@0
   209
sl@0
   210
CFbsBitmap* CPanControl::Bitmap()
sl@0
   211
    {
sl@0
   212
    return iSourceBitmap;
sl@0
   213
    }