uiacceltk/hitchcock/tsrc/alfperfapp/src/alfperfappavkontestcase.cpp
changeset 0 15bf7259bb7c
equal deleted inserted replaced
-1:000000000000 0:15bf7259bb7c
       
     1 /*
       
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  CAlfPerfAppAvkonTestCase implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "alfperfappbasetestcasecontrol.h"
       
    20 #include "alfperfappavkontestcase.h"
       
    21 #include "alfperfapp.hrh"
       
    22 
       
    23 #include <aknutils.h>
       
    24 #include <e32math.h>
       
    25 
       
    26 #include <coemain.h>
       
    27 #include <coecntrl.h>
       
    28 #include <eikapp.h>
       
    29 
       
    30 #include <alf/alfenv.h>
       
    31 #include <alf/alfevent.h>
       
    32 #include <alf/alfdisplay.h>
       
    33 #include <alf/alfcontrolgroup.h>
       
    34 #include <alf/alfroster.h>
       
    35 
       
    36 /**
       
    37  * Control group for Avkon test cases.
       
    38  */
       
    39 const TInt KAlfPerfAppAvkonControlGroup = 1;
       
    40 
       
    41 /**
       
    42  * Start next 'cycle' command.
       
    43  */
       
    44 const TInt KAlfPerfAppAvkonCmdNext = 0x5001;
       
    45 
       
    46 /**
       
    47  * Delay between frames
       
    48  */
       
    49 const TInt KAnimSleepTimeUs = 0;
       
    50 
       
    51 /**
       
    52  * Cycle time, contais several frames
       
    53  */
       
    54 const TInt KCycleDurationMs = 1000;
       
    55 
       
    56 /**
       
    57  * The whole test case duration
       
    58  */
       
    59 const TInt KCaseDurationMs = KCycleDurationMs * 10;
       
    60 
       
    61 /**
       
    62  * Avkon test coe control
       
    63  */
       
    64 
       
    65 class CAvkonTestCoeControl: public CCoeControl
       
    66 {
       
    67 public:
       
    68     // Construction & destruction
       
    69     CAvkonTestCoeControl();
       
    70     ~CAvkonTestCoeControl();
       
    71     void ConstructL(const TRect& aRect);
       
    72     RWindow* GetWindow();
       
    73 
       
    74 private:
       
    75 
       
    76     // from CCoeControl
       
    77     void Draw(const TRect&) const;
       
    78     TInt CountComponentControls() const {return 0;}
       
    79     CCoeControl* ComponentControl( TInt /*aIndex*/ ) const {return NULL;}
       
    80 
       
    81 public: 
       
    82     
       
    83 };
       
    84 
       
    85 // ============================ MEMBER FUNCTIONS ===============================
       
    86 
       
    87 CAvkonTestCoeControl::CAvkonTestCoeControl()
       
    88     {
       
    89     }
       
    90 
       
    91 
       
    92 void CAvkonTestCoeControl::ConstructL(const TRect& aRect)
       
    93     {
       
    94     // Create window
       
    95     CreateWindowL();
       
    96     SetRect(aRect);
       
    97     ActivateL();
       
    98     }
       
    99 
       
   100 CAvkonTestCoeControl::~CAvkonTestCoeControl()
       
   101     {
       
   102     }
       
   103 
       
   104 RWindow* CAvkonTestCoeControl::GetWindow()
       
   105     {
       
   106     return &Window();   
       
   107     }
       
   108 
       
   109 
       
   110 void CAvkonTestCoeControl::Draw(const TRect& /*aRect*/) const
       
   111     {
       
   112     }
       
   113 
       
   114 /**
       
   115  * Basic WindGC tests.
       
   116  */
       
   117 class CAlfPerfAppAvkonTestCaseBasic : public CAlfPerfAppBaseTestCaseControl
       
   118     {
       
   119 public:
       
   120     CAlfPerfAppAvkonTestCaseBasic();
       
   121     ~CAlfPerfAppAvkonTestCaseBasic();
       
   122     
       
   123     virtual void ConstructL( 
       
   124         CAlfEnv& aEnv, TInt aCaseId, const TRect& aVisibleArea );      
       
   125     virtual void DoStartExecuteL();
       
   126     virtual TBool OfferEventL( const TAlfEvent& aEvent );
       
   127     virtual void SetVisibleArea( const TRect& aVisibleArea );    
       
   128 
       
   129     /**
       
   130      * animation timer callback
       
   131      */
       
   132     static TInt AnimTimerCbL(TAny* aThis);
       
   133    
       
   134     /**
       
   135      * Calculate fps for the current phase
       
   136      */
       
   137     double CalcPhaseFpsL();   
       
   138     
       
   139 private:
       
   140     
       
   141     /**
       
   142      * Next cycle.
       
   143      */
       
   144     void NextCycleL();
       
   145     
       
   146     /**
       
   147      * Next frame inside cycle
       
   148      */
       
   149     void NextAnimFrameL();
       
   150 
       
   151 private:
       
   152        
       
   153     CAvkonTestCoeControl* iAvkonControl; // Owned
       
   154     TRect iWinRect;
       
   155  
       
   156 private:
       
   157 
       
   158    /**
       
   159      * Cycle counter.
       
   160      */        
       
   161     TInt iCycleCounter;
       
   162     
       
   163     /**
       
   164      * animation timer
       
   165      */        
       
   166    CPeriodic* iAnimTimer;
       
   167     
       
   168    /**
       
   169     * Current frame number
       
   170     */        
       
   171     TInt iAnimFrameNum;
       
   172     
       
   173     /**
       
   174      * 
       
   175      */        
       
   176     TTime iCycleStartTime;
       
   177 
       
   178     /**
       
   179      * Font
       
   180      */        
       
   181     CFont* iFont;
       
   182 
       
   183     /**
       
   184      * Test bitmap and mask 
       
   185      */        
       
   186     CFbsBitmap* iPictureBm;
       
   187     CFbsBitmap* iMaskBm;
       
   188 
       
   189     /**
       
   190      * Client performace data
       
   191      */        
       
   192    TTime iTestCaseStartTime_ys;
       
   193    TUint iTestCaseFrameCount;
       
   194 };
       
   195         
       
   196         
       
   197 // ============================ MEMBER FUNCTIONS ===============================
       
   198 
       
   199 // -----------------------------------------------------------------------------
       
   200 // Checks if specified case is supported by this class.
       
   201 // -----------------------------------------------------------------------------
       
   202 //
       
   203 TBool CAlfPerfAppAvkonTestCase::IsSupported( TInt aCaseId )
       
   204     {
       
   205     return aCaseId > EAlfPerfAppAvkonMin && 
       
   206            aCaseId < EAlfPerfAppAvkonMax;
       
   207     }
       
   208 
       
   209 CAlfPerfAppAvkonTestCase* CAlfPerfAppAvkonTestCase::NewL( TInt aCaseId, TInt aSequenceIndex )
       
   210     {
       
   211     if ( !IsSupported( aCaseId ) )
       
   212         {
       
   213         User::Leave( KErrNotSupported );
       
   214         }
       
   215 
       
   216     CAlfPerfAppAvkonTestCase* self = 
       
   217         new (ELeave) CAlfPerfAppAvkonTestCase( aCaseId, aSequenceIndex );
       
   218     CleanupStack::PushL( self );
       
   219     self->ConstructL();
       
   220     CleanupStack::Pop( self );
       
   221     return self;
       
   222     }
       
   223 
       
   224 CAlfPerfAppAvkonTestCase::~CAlfPerfAppAvkonTestCase()
       
   225     {
       
   226     if ( iEnv && iControl )
       
   227         {
       
   228         iControl->CancelExecution();
       
   229         iEnv->DeleteControlGroup( KAlfPerfAppAvkonControlGroup );
       
   230         }
       
   231     }
       
   232 
       
   233 // -----------------------------------------------------------------------------
       
   234 // Starts setup phase.
       
   235 // -----------------------------------------------------------------------------
       
   236 //
       
   237 void CAlfPerfAppAvkonTestCase::SetupL( 
       
   238         CAlfEnv& aEnv, const TRect& /*aVisibleArea*/, TRequestStatus& aStatus )
       
   239     {
       
   240     // Note: we could remove usage of Alf client API as it is not mandatory for the test case
       
   241     
       
   242     iEnv = &aEnv;
       
   243 
       
   244     CAlfDisplay* display = 0;
       
   245     CAlfControlGroup& group = iEnv->NewControlGroupL( KAlfPerfAppAvkonControlGroup );
       
   246     CAlfPerfAppBaseTestCaseControl* control = 0;
       
   247     
       
   248     TRect rect;
       
   249     AknLayoutUtils::LayoutMetricsRect(
       
   250         AknLayoutUtils::EApplicationWindow,
       
   251         rect );
       
   252     display = &iEnv->NewDisplayL( rect, CAlfEnv::ENewDisplayAsCoeControl);
       
   253     display->SetClearBackgroundL( CAlfDisplay::EClearWithSkinBackground );
       
   254 
       
   255     switch ( iCaseId )
       
   256         {
       
   257         case EAlfPerfAppAvkonBasicWinGc:
       
   258             control = new (ELeave) CAlfPerfAppAvkonTestCaseBasic;
       
   259             CleanupStack::PushL( control );
       
   260             control->ConstructL( *iEnv, iCaseId, rect );
       
   261             break;
       
   262             
       
   263         default:
       
   264             User::Leave( KErrNotSupported );
       
   265             break;
       
   266         }
       
   267 
       
   268     group.AppendL( control ); // ownership passed to control group.
       
   269     iControl = control;
       
   270     CleanupStack::Pop( control );    
       
   271     
       
   272     display->Roster().ShowL( group );
       
   273     
       
   274     // This must be the last statement.
       
   275     CAlfPerfAppTestCase::CompleteNow( aStatus, KErrNone );
       
   276     }
       
   277 
       
   278 // -----------------------------------------------------------------------------
       
   279 // Starts execution phase.
       
   280 // -----------------------------------------------------------------------------
       
   281 //
       
   282 void CAlfPerfAppAvkonTestCase::ExecuteL( TRequestStatus& aStatus )
       
   283     {
       
   284     // SetupL must have been called first.
       
   285     __ASSERT_ALWAYS( iEnv, User::Invariant() );
       
   286     __ASSERT_ALWAYS( iControl, User::Invariant() );
       
   287     
       
   288     iControl->StartExecuteL( aStatus );
       
   289     }
       
   290 
       
   291 // -----------------------------------------------------------------------------
       
   292 // Tears down.
       
   293 // -----------------------------------------------------------------------------
       
   294 //
       
   295 void CAlfPerfAppAvkonTestCase::TearDown()
       
   296     {
       
   297     // Execution side will delete CAlfEnv, so it will delete everything
       
   298     // related to this.
       
   299     iEnv = NULL;
       
   300     iControl = NULL;
       
   301     }
       
   302 
       
   303 void CAlfPerfAppAvkonTestCase::HandleVisibleAreaChange( const TRect& /*aRect*/ )
       
   304     {
       
   305     }
       
   306 
       
   307 TInt CAlfPerfAppAvkonTestCase::CaseID()
       
   308     {
       
   309     return iCaseId;
       
   310     }
       
   311 
       
   312 CAlfPerfAppAvkonTestCase::CAlfPerfAppAvkonTestCase( TInt aCaseId, TInt aSequenceIndex )
       
   313     : CAlfPerfAppTestCase(aSequenceIndex), iCaseId ( aCaseId )
       
   314     {
       
   315     }
       
   316 
       
   317 void CAlfPerfAppAvkonTestCase::ConstructL()
       
   318     {
       
   319     }
       
   320 
       
   321 TTestCaseSpecificResultText CAlfPerfAppAvkonTestCase::getCaseSpecificResultL()
       
   322     {
       
   323     TTestCaseSpecificResultText result = HBufC::NewL(KAlfPerfAppMaxCharsInSpecificResultText);
       
   324     double fps = 0.0;
       
   325     if (iControl)
       
   326         {
       
   327         fps = ((CAlfPerfAppAvkonTestCaseBasic*)iControl)->CalcPhaseFpsL();
       
   328         }
       
   329     result->Des().AppendFormat(_L("Client fps: %3.2f"), fps);
       
   330     return result;        
       
   331     }
       
   332 
       
   333 // ********
       
   334 
       
   335 // Implementation of CAlfPerfAppAvkonTestCaseBasic:
       
   336 CAlfPerfAppAvkonTestCaseBasic::CAlfPerfAppAvkonTestCaseBasic()
       
   337     {
       
   338     }
       
   339 
       
   340 CAlfPerfAppAvkonTestCaseBasic::~CAlfPerfAppAvkonTestCaseBasic()
       
   341     {
       
   342     delete iPictureBm;
       
   343     delete iMaskBm;
       
   344     
       
   345    if (iFont)
       
   346         {
       
   347         CCoeEnv::Static()->ScreenDevice()->ReleaseFont(iFont);
       
   348         }
       
   349     delete iAnimTimer;
       
   350     delete iAvkonControl;    
       
   351     }
       
   352 
       
   353 void CAlfPerfAppAvkonTestCaseBasic::ConstructL( 
       
   354         CAlfEnv& aEnv, TInt aCaseId, const TRect& aVisibleArea )
       
   355     {
       
   356     CAlfPerfAppBaseTestCaseControl::ConstructL( aEnv, aCaseId, aVisibleArea );   
       
   357     
       
   358     iWinRect = aVisibleArea;
       
   359     
       
   360     iAvkonControl = new(ELeave) CAvkonTestCoeControl();
       
   361     iAvkonControl->ConstructL(iWinRect);
       
   362 
       
   363     iAnimTimer = CPeriodic::NewL(CActive::EPriorityStandard);
       
   364     
       
   365     TFontSpec myFontSpec(_L("Arial"), 3*120);
       
   366     CCoeEnv::Static()->ScreenDevice()->GetNearestFontInTwips(iFont, myFontSpec);
       
   367     
       
   368     // Find my private path
       
   369     TFileName pathWithoutDrive;
       
   370     TFileName driveAndPath;
       
   371     CEikonEnv::Static()->FsSession().PrivatePath( pathWithoutDrive );
       
   372     driveAndPath.Copy(CEikonEnv::Static()->EikAppUi()->Application()->AppFullName().Left(2));
       
   373     driveAndPath.Append(pathWithoutDrive);
       
   374     
       
   375     // Create pictures
       
   376     iPictureBm = new(ELeave) CFbsBitmap;
       
   377     driveAndPath.Append(_L("alfperfapp_test1.mbm"));
       
   378     User::LeaveIfError(iPictureBm->Load(driveAndPath));
       
   379     iMaskBm = new(ELeave) CFbsBitmap;
       
   380     User::LeaveIfError(iMaskBm->Create(iPictureBm->SizeInPixels(), EGray256));
       
   381  
       
   382     iTestCaseStartTime_ys.UniversalTime();
       
   383     iTestCaseFrameCount = 0;
       
   384    }
       
   385     
       
   386 
       
   387 void CAlfPerfAppAvkonTestCaseBasic::DoStartExecuteL()
       
   388     {
       
   389     iTestCaseStartTime_ys.UniversalTime();
       
   390     iTestCaseFrameCount = 0;
       
   391     
       
   392     NextCycleL();
       
   393     
       
   394     CompleteAfterL( KCaseDurationMs );
       
   395     }
       
   396 
       
   397 void CAlfPerfAppAvkonTestCaseBasic::SetVisibleArea( 
       
   398         const TRect& /*aVisibleArea*/ )
       
   399     {
       
   400     if ( IsExecutionOngoing() )
       
   401         {
       
   402         Env().CancelCustomCommands( this, KAlfPerfAppAvkonCmdNext );
       
   403         TRAPD( err, NextCycleL() );
       
   404         if ( err != KErrNone )
       
   405             {
       
   406             CompleteNow( err );
       
   407             }
       
   408         }
       
   409     }
       
   410 
       
   411 TBool CAlfPerfAppAvkonTestCaseBasic::OfferEventL( const TAlfEvent& aEvent )
       
   412     {
       
   413     if ( aEvent.IsCustomEvent() && 
       
   414          aEvent.CustomParameter() == KAlfPerfAppAvkonCmdNext )
       
   415         {
       
   416         TRAPD( err, NextCycleL() );
       
   417         if ( err != KErrNone )
       
   418             {
       
   419             CompleteNow( err );
       
   420             }
       
   421         return ETrue;
       
   422         }    
       
   423     return CAlfPerfAppBaseTestCaseControl::OfferEventL( aEvent );
       
   424     }
       
   425 
       
   426 void CAlfPerfAppAvkonTestCaseBasic::NextCycleL()
       
   427     {
       
   428     TAlfCustomEventCommand command( KAlfPerfAppAvkonCmdNext, this );
       
   429     User::LeaveIfError( Env().Send( command, KCycleDurationMs ) );
       
   430     
       
   431     iCycleCounter++;
       
   432    
       
   433     iAnimTimer->Cancel();
       
   434     iAnimTimer->Start(KAnimSleepTimeUs, KAnimSleepTimeUs, TCallBack(AnimTimerCbL, this));
       
   435     iAnimFrameNum = 0;
       
   436     iCycleStartTime.UniversalTime();
       
   437     }
       
   438 
       
   439 
       
   440 TInt CAlfPerfAppAvkonTestCaseBasic::AnimTimerCbL(TAny* aThis)
       
   441         {
       
   442         static_cast<CAlfPerfAppAvkonTestCaseBasic*>(aThis)->NextAnimFrameL();
       
   443         return NULL;
       
   444         }
       
   445 
       
   446 void CAlfPerfAppAvkonTestCaseBasic::NextAnimFrameL()
       
   447     {
       
   448     // Begin drawing
       
   449     RWindow& window = static_cast< RWindow& >( *iAvkonControl->DrawableWindow() );
       
   450     CWindowGc& gc = iAvkonControl->SystemGc();
       
   451     TRect updateRect(iAvkonControl->Rect());
       
   452     window.Invalidate( updateRect );
       
   453     window.BeginRedraw( updateRect );
       
   454     gc.Activate(window);
       
   455 
       
   456     // Draw background
       
   457     TRgb color (KRgbWhite);
       
   458     gc.SetBrushColor(color);
       
   459     gc.SetBrushStyle(CGraphicsContext::ESolidBrush);
       
   460     gc.SetPenStyle(CGraphicsContext::ESolidPen);
       
   461     gc.SetPenSize(TSize(10,10));
       
   462     gc.SetPenColor(color);    
       
   463     gc.DrawRect(updateRect);  
       
   464        
       
   465     // Calc timeline
       
   466     TTime now;
       
   467     now.UniversalTime();
       
   468     TUint millisecondFromCycleStart = now.MicroSecondsFrom(iCycleStartTime).Int64() / 1000;
       
   469     double timelinePercentage = (double)millisecondFromCycleStart / KCycleDurationMs; 
       
   470     timelinePercentage *= 0.5; // scale it a bit...
       
   471    
       
   472     // Calc rect
       
   473     TRect fullRect(updateRect);
       
   474     TSize size(fullRect.Width()*(1.0 - timelinePercentage), fullRect.Height()*(1.0 - timelinePercentage));
       
   475     TPoint windowCenter = fullRect.Center();
       
   476     TPoint tl(windowCenter.iX - size.iWidth/2, windowCenter.iY - size.iHeight/2);
       
   477     TRect rect(tl, size);
       
   478         
       
   479     // Draw
       
   480     gc.SetPenColor(KRgbBlue);
       
   481     gc.SetBrushColor(KRgbRed);
       
   482     const TPoint Point1(rect.iTl);
       
   483     const TPoint Point2(rect.iBr.iX, rect.iTl.iY);
       
   484     const TPoint Point3(rect.iBr);
       
   485     const TPoint Point4(rect.iTl.iX, rect.iBr.iY);
       
   486     const TPoint center(rect.Center());
       
   487 
       
   488     switch (iCycleCounter)
       
   489         {
       
   490         case 1: // DrawEllipse
       
   491             {
       
   492             gc.DrawEllipse(rect);   
       
   493             break;
       
   494             }
       
   495         case 2: // DrawRect
       
   496             {
       
   497             gc.DrawRect(rect);    
       
   498             break;
       
   499             }
       
   500         case 3: // DrawRoundRect
       
   501             {
       
   502             TSize corner(rect.Width()/5, rect.Height()/5);
       
   503             gc.DrawRoundRect(rect, corner);   
       
   504             break;
       
   505             }
       
   506         case 4: // Draw lines
       
   507             {
       
   508             gc.SetPenColor(TRgb(255,0,0));
       
   509             gc.DrawLine(Point1, Point2);       
       
   510             
       
   511             gc.SetPenColor(TRgb(200,50,0));
       
   512             gc.DrawLineTo(Point3);
       
   513             
       
   514             gc.SetPenColor(TRgb(150,100,0));
       
   515             gc.DrawLineTo(Point4);
       
   516             
       
   517             gc.SetPenColor(TRgb(100,150,0));
       
   518             gc.DrawLineBy(TPoint(0, -rect.Height()));
       
   519             
       
   520             gc.SetPenColor(TRgb(50,200,0));
       
   521             gc.MoveTo(Point2);
       
   522             gc.DrawLineTo(Point4);
       
   523                        
       
   524             gc.SetPenColor(TRgb(0,255,0));
       
   525             gc.MoveBy(TPoint(0, -rect.Height()));
       
   526             gc.DrawLineTo(Point3);
       
   527             
       
   528             gc.SetPenColor(TRgb(255,0,0));
       
   529             gc.Plot(center);
       
   530             
       
   531             break;
       
   532            }
       
   533             
       
   534         case 5: // Draw 
       
   535             {
       
   536             gc.SetPenColor(TRgb(255,0,0));
       
   537             gc.DrawArc(rect, Point2, Point1);
       
   538             gc.DrawPie(rect, Point4, Point3);
       
   539             break;
       
   540             }
       
   541             
       
   542         case 6: // Draw polygons
       
   543             {
       
   544             const TInt KNumPoints = 9;
       
   545             TPoint pointList[KNumPoints];
       
   546             pointList[0] = TPoint(Point1.iX+rect.Width()*0.25, Point1.iY);
       
   547             pointList[1] = TPoint(Point1.iX+rect.Width()*0.75, Point1.iY);
       
   548             pointList[2] = TPoint(Point2.iX, Point2.iY+rect.Height()*0.25);
       
   549             pointList[3] = TPoint(Point2.iX, Point2.iY+rect.Height()*0.75);
       
   550             pointList[4] = TPoint(Point3.iX-rect.Width()*0.25, Point3.iY);
       
   551             pointList[5] = TPoint(Point3.iX-rect.Width()*0.75, Point3.iY);
       
   552             pointList[6] = TPoint(Point4.iX, Point4.iY-rect.Height()*0.25);
       
   553             pointList[7] = TPoint(Point4.iX, Point4.iY-rect.Height()*0.75);
       
   554             pointList[8] = TPoint(Point1.iX+rect.Width()*0.25, Point1.iY);
       
   555             
       
   556             CArrayFix<TPoint>* mypoints = new CArrayFixFlat<TPoint>(KNumPoints);
       
   557             CleanupStack::PushL(mypoints);
       
   558             for(TInt i=0; i<KNumPoints; i++)
       
   559                 {
       
   560                 mypoints->AppendL(pointList[i]);
       
   561                 }
       
   562 
       
   563             gc.SetPenColor(TRgb(255,0,0));
       
   564             gc.SetPenSize(TSize(20,20));
       
   565             gc.DrawPolyLine(mypoints);
       
   566             
       
   567             gc.SetPenColor(TRgb(0,255,0));
       
   568             gc.SetPenSize(TSize(15,15));
       
   569             gc.DrawPolyLine(pointList, KNumPoints);
       
   570             
       
   571             gc.SetPenColor(TRgb(255,255,0));
       
   572             gc.SetPenSize(TSize(10,10));
       
   573             gc.DrawPolygon(mypoints);
       
   574             
       
   575             gc.SetPenColor(TRgb(0,0,255));
       
   576             gc.SetPenSize(TSize(5,5));
       
   577             gc.DrawPolygon(pointList, KNumPoints);
       
   578             
       
   579             CleanupStack::PopAndDestroy(); // mypoints           
       
   580             break;
       
   581             }
       
   582             
       
   583         case 7: // Draw texts
       
   584             {
       
   585             gc.UseFont(iFont);
       
   586             gc.SetDrawMode(CGraphicsContext::EDrawModePEN);
       
   587             gc.SetPenStyle(CGraphicsContext::ESolidPen);
       
   588             gc.SetBrushStyle(CGraphicsContext::ESolidBrush);    
       
   589             
       
   590             TInt h = rect.Height() / 3;
       
   591             TInt y = rect.iTl.iY;
       
   592             TRect tinyBox(rect);
       
   593             tinyBox.SetHeight(h);
       
   594             TInt fontDescent=iFont->DescentInPixels();
       
   595             gc.SetBrushColor(TRgb(0, 0, 255)); // blue
       
   596             
       
   597             gc.SetPenColor(TRgb(0,255,0)); // green
       
   598             gc.DrawText(_L("Ilves"), tinyBox.iTl+TPoint(0, fontDescent));
       
   599             
       
   600             tinyBox.Move(0,h);
       
   601             TInt posY = tinyBox.Height()-fontDescent;
       
   602             gc.SetPenColor(TRgb(255,0,0)); 
       
   603             gc.DrawText(_L("Tappara"), tinyBox, posY);
       
   604             
       
   605             gc.SetPenColor(TRgb(0,255,0)); // green
       
   606             gc.DrawTextVertical(_L("Ilves"), tinyBox.iTl+TPoint(fontDescent, 0 ), ETrue);
       
   607             
       
   608             tinyBox.Move(0,h);
       
   609             posY = tinyBox.Height()-fontDescent;
       
   610             gc.SetPenColor(TRgb(255,0,0)); 
       
   611             gc.DrawTextVertical(_L("Tappara"), tinyBox, posY, ETrue);
       
   612             
       
   613             break;
       
   614             }
       
   615 
       
   616         case 8: // Draw bitmaps
       
   617             {
       
   618             TPoint pos(rect.iTl);
       
   619             gc.BitBlt(pos, iPictureBm);
       
   620             
       
   621             pos = TPoint(rect.iTl.iX + rect.Width()/3, rect.iTl.iY);
       
   622             gc.BitBlt(pos, iPictureBm, TRect(iPictureBm->SizeInPixels()));
       
   623 
       
   624             pos = TPoint(rect.iTl.iX + rect.Width()*2/3, rect.iTl.iY);
       
   625             gc.BitBltMasked(pos, iPictureBm, TRect(iPictureBm->SizeInPixels()), iMaskBm, EFalse);
       
   626 
       
   627             pos = TPoint(rect.iTl.iX, rect.iTl.iY+ rect.Height()/3);
       
   628             TRect dstRect(pos, TSize(rect.Width()/3, rect.Height()/3));
       
   629             gc.DrawBitmap(dstRect, iPictureBm, TRect(iPictureBm->SizeInPixels()));
       
   630 
       
   631             pos = TPoint(rect.iTl.iX + rect.Width()/3, rect.iTl.iY+ rect.Height()/3);
       
   632             dstRect =  TRect(pos, dstRect.Size());
       
   633             gc.DrawBitmap(dstRect, iPictureBm);
       
   634 
       
   635             pos = TPoint(rect.iTl.iX, rect.iTl.iY+ rect.Height()*2/3);
       
   636             gc.DrawBitmap(pos, iPictureBm);
       
   637 
       
   638             pos = TPoint(rect.iTl.iX + rect.Width()/3, rect.iTl.iY+ rect.Height()*2/3);
       
   639             dstRect =  TRect(pos, dstRect.Size());
       
   640             gc.DrawBitmapMasked(dstRect, iPictureBm, TRect(iPictureBm->SizeInPixels()), iMaskBm, EFalse);
       
   641 
       
   642             break;
       
   643             }
       
   644             
       
   645          case 9: // Miscellanious
       
   646             {
       
   647             TRect rect1(rect);
       
   648             rect1.SetWidth(rect.Width()/2);
       
   649             rect1.SetHeight(rect.Height()/2);
       
   650             TRect rect2(rect1);
       
   651             rect2.Move(rect1.Width(),0);
       
   652             TRect rect3(rect1);
       
   653             rect3.Move(0, rect1.Height());
       
   654             TRect rect4(rect1);
       
   655             rect4.Move(rect1.Width(), rect1.Height());
       
   656             
       
   657             // Clear
       
   658             gc.Clear();
       
   659             // Brush pattern
       
   660             gc.UseBrushPattern(iPictureBm);
       
   661             gc.SetBrushStyle(CGraphicsContext::EPatternedBrush);
       
   662             gc.DrawRect(rect1);
       
   663             gc.DiscardBrushPattern();
       
   664             // Fading & copy rect
       
   665             gc.SetFaded(ETrue);
       
   666             gc.CopyRect(rect2.iTl, rect1);
       
   667             gc.SetFadingParameters(255,0);
       
   668             gc.CopyRect(rect3.iTl, rect1);
       
   669             // Map colors  
       
   670             gc.SetPenColor(KRgbBlue);
       
   671             gc.SetBrushColor(KRgbRed);
       
   672             gc.DrawRect(rect4);   
       
   673             TRgb colors[2] = {KRgbRed, KRgbGreen}; // change brush color
       
   674             gc.MapColors(rect4,colors,1,ETrue);
       
   675              
       
   676             break;
       
   677             }
       
   678             
       
   679      default:
       
   680            gc.DrawRect(rect);          
       
   681        }
       
   682 
       
   683     // End drawing
       
   684     gc.Deactivate();
       
   685     window.EndRedraw();
       
   686  
       
   687     iTestCaseFrameCount++;
       
   688     }
       
   689 
       
   690 
       
   691 double CAlfPerfAppAvkonTestCaseBasic::CalcPhaseFpsL()
       
   692     {
       
   693     // Calc time spend in the phase
       
   694     TTime now;
       
   695     now.UniversalTime();
       
   696     TUint millisecondsFromCaseStart = now.MicroSecondsFrom(iTestCaseStartTime_ys).Int64() / 1000;
       
   697     double fps = 0.0;
       
   698     if (millisecondsFromCaseStart)
       
   699         {
       
   700         fps = (double)iTestCaseFrameCount * 1000 / millisecondsFromCaseStart;       
       
   701         }
       
   702     iTestCaseStartTime_ys.UniversalTime();
       
   703     iTestCaseFrameCount = 0;
       
   704     
       
   705     return fps;
       
   706     }
       
   707