uiacceltk/hitchcock/tsrc/alfperfapp/src/alfperfappgallerytestcase.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:  CAlfPerfAppGalleryTestCase implementation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "alfperfappgallerytestcase.h"
       
    20 #include "alfperfappappui.h"
       
    21 #include "alfperfapp.hrh"
       
    22 
       
    23 #include <aknutils.h>
       
    24 #include <alf/alfenv.h>
       
    25 #include <alf/alfdisplay.h>
       
    26 #include <alf/alfcontrol.h>
       
    27 #include <alf/alfcontrolgroup.h>
       
    28 #include <alf/alfroster.h>
       
    29 #include <alf/alfcommand.h>
       
    30 #include <alf/alfevent.h>
       
    31 #include <alf/alftexturemanager.h>
       
    32 #include <alf/alfimagevisual.h>
       
    33 #include <alf/alfimageloaderutil.h>
       
    34 #include <alf/alfutil.h>
       
    35 #include <alf/alflayout.h>
       
    36 #include <alf/alfviewportlayout.h>
       
    37 #include <alf/alfgridlayout.h>
       
    38 #include <alf/alftransformation.h>
       
    39 #include <alf/alfgradientbrush.h>
       
    40 #include <alf/alfimagebrush.h>
       
    41 #include <alf/alftextvisual.h>
       
    42 #include <alf/alfbrusharray.h>
       
    43 #include <alf/alfshadowborderbrush.h>
       
    44 #include <alf/alfdecklayout.h>
       
    45 #include <alf/alflayout.h>
       
    46 #include <alf/alfborderbrush.h>
       
    47 
       
    48 #include <alfperfapp_imagetest.mbg>
       
    49 
       
    50 /**
       
    51  * Control group for image test cases.
       
    52  */
       
    53 const TInt KAlfPerfAppGalleryControlGroup = 3;
       
    54 
       
    55 /**
       
    56  * Complete now command.
       
    57  */
       
    58 const TInt KAlfPerfAppGalleryCmdCompleteNow = 0x7000;
       
    59 
       
    60 /**
       
    61  * Abstract gallery test case control.
       
    62  */
       
    63 class CAlfPerfAppGalleryTestCaseControl : public CAlfControl,
       
    64 	public MAlfTextureLoadingCompletedObserver
       
    65     {
       
    66 public:
       
    67 
       
    68     // Common constants
       
    69     static const TInt KTransitionTime;
       
    70     static const TInt KTransitionWaitTime;
       
    71 
       
    72     /**
       
    73      * Constructor.
       
    74      */
       
    75     CAlfPerfAppGalleryTestCaseControl();
       
    76 
       
    77     /**
       
    78      * Destructor.
       
    79      */
       
    80     ~CAlfPerfAppGalleryTestCaseControl();
       
    81 
       
    82     static CAlfPerfAppGalleryTestCaseControl* NewL(
       
    83     		CAlfEnv& aEnv, TInt aCaseId, const TRect& /*aVisibleArea*/);
       
    84 
       
    85     /**
       
    86      * Base class constructor. Derived classes may
       
    87      * override this, but base class needs to be called.
       
    88      */
       
    89     virtual void ConstructL(
       
    90         CAlfEnv& aEnv, TInt aCaseId, const TRect& aVisibleArea );
       
    91 
       
    92     /**
       
    93      * Starts execution of the test case. By default,
       
    94      * request status is stored to local variable.
       
    95      */
       
    96     void StartExecuteL( TRequestStatus& aStatus );
       
    97 
       
    98     /**
       
    99      * Cancels execution. This control and environment will be
       
   100      * deleted soon after calling this method.
       
   101      */
       
   102     void CancelExecution();
       
   103 
       
   104     /**
       
   105      * Sets observer for texture loading.
       
   106      * @param aObserver Observer class.
       
   107      */
       
   108     void SetImagesLoadedObserver( MImagesLoadedObserver* aObserver );
       
   109 
       
   110     /**
       
   111      * Sets focused image.
       
   112      * @param aImageTag Tag for the image to be focused.
       
   113      */
       
   114     void SetImageFocusL( const TDesC8& aImageTag );
       
   115 
       
   116     /**
       
   117      * Starts execution.
       
   118      * If this method leaves, then request must not be completed.
       
   119      * By default, this method completes immediately.
       
   120      */
       
   121     virtual void DoStartExecuteL();
       
   122 
       
   123     /**
       
   124      * Sets visible area.
       
   125      * @param aVisibleArea visible area.
       
   126      */
       
   127     virtual void SetVisibleArea( const TRect& aVisibleArea );
       
   128 
       
   129     // From base class CAlfControl:
       
   130 
       
   131     /**
       
   132      * Handles events.
       
   133      * Derived classes should forward to base class.
       
   134      * @param aEvent event to be handled.
       
   135      * @return ETrue if consumed, EFalse otherwise.
       
   136      */
       
   137     virtual TBool OfferEventL( const TAlfEvent& aEvent );
       
   138 
       
   139     // From base class MAlfTextureLoadingCompletedObserver
       
   140     void TextureLoadingCompleted( CAlfTexture& aTexture, TInt aTextureId,
       
   141 			TInt aErrorCode );
       
   142 
       
   143 
       
   144 protected:
       
   145     void MoveImages(
       
   146         TReal32 aAmount,
       
   147         TReal32 aTransitionTime = KTransitionTime );
       
   148 
       
   149 	/**
       
   150 	 * Next cycle for scrolling the Grid layout.
       
   151 	 */
       
   152 	void NextScrollCycleL();
       
   153 
       
   154 	/**
       
   155 	 * Next cycle for focusing image.
       
   156 	 */
       
   157 	void NextFocusCycleL();
       
   158 
       
   159 	/**
       
   160 	 * Sets image focus based on event cycle.
       
   161 	 */
       
   162     void UpdateImageFocus( TInt aCycle );
       
   163 
       
   164     /**
       
   165      * Completes automatically after specified duration.
       
   166      * @param aDuration duration in ms
       
   167      */
       
   168     void CompleteAfterL( TInt aDuration );
       
   169 
       
   170     /**
       
   171      * Completes current request.
       
   172      */
       
   173     void CompleteNow( TInt aErrorCode );
       
   174 
       
   175     /**
       
   176      * Returns test case id.
       
   177      */
       
   178     inline TInt CaseId() const;
       
   179 
       
   180     /**
       
   181      * Returns ETrue if test case execution is still ongoing.
       
   182      */
       
   183     inline TBool IsExecutionOngoing() const;
       
   184 
       
   185     /**
       
   186      * Test case id.
       
   187      */
       
   188     TInt iCaseId;
       
   189 
       
   190 
       
   191 private:
       
   192     /**
       
   193      * Pointer to request status.
       
   194      * Not owned.
       
   195      */
       
   196     TRequestStatus* iStatus;
       
   197 
       
   198     CAlfLayout* iGridLayout;
       
   199     TReal32 iViewportPosition;
       
   200     TReal32 iPreviousViewportPosition;
       
   201     CAlfViewportLayout* iViewport;
       
   202     CAlfLayout* iImageInfoLayout;
       
   203 
       
   204     TInt iCycleCount;
       
   205     TInt iFocusChangedCount;
       
   206     TInt iGridScrolledCount;
       
   207     TInt iLoadedImages;
       
   208 
       
   209 	CAlfImageVisual* iFocusedVisual;
       
   210 
       
   211     MImagesLoadedObserver* iObserver;
       
   212 
       
   213 	RPointerArray<TDesC> iImageCaptions;
       
   214 
       
   215 	RPointerArray<TDesC8> iImagesToBeFocused;
       
   216     };
       
   217 
       
   218 // ============================ MEMBER FUNCTIONS ===============================
       
   219 const TInt CAlfPerfAppGalleryTestCaseControl::KTransitionTime = 1000;
       
   220 const TInt CAlfPerfAppGalleryTestCaseControl::KTransitionWaitTime = 1000;
       
   221 // -----------------------------------------------------------------------------
       
   222 // Checks if specified case is supported by this class.
       
   223 // -----------------------------------------------------------------------------
       
   224 //
       
   225 TBool CAlfPerfAppGalleryTestCase::IsSupported( TInt aCaseId )
       
   226     {
       
   227     return aCaseId > EAlfPerfAppGalleryMin &&
       
   228            aCaseId < EAlfPerfAppGalleryMax;
       
   229     }
       
   230 
       
   231 CAlfPerfAppGalleryTestCase* CAlfPerfAppGalleryTestCase::NewL( TInt aCaseId, TInt aSequenceIndex )
       
   232     {
       
   233     if ( !IsSupported( aCaseId ) )
       
   234         {
       
   235         User::Leave( KErrNotSupported );
       
   236         }
       
   237 
       
   238     CAlfPerfAppGalleryTestCase* self =
       
   239         new (ELeave) CAlfPerfAppGalleryTestCase( aCaseId, aSequenceIndex );
       
   240     CleanupStack::PushL( self );
       
   241     self->ConstructL();
       
   242     CleanupStack::Pop( self );
       
   243     return self;
       
   244     }
       
   245 
       
   246 CAlfPerfAppGalleryTestCase::~CAlfPerfAppGalleryTestCase()
       
   247     {
       
   248     if ( iEnv && iControl )
       
   249         {
       
   250         iEnv->TextureManager().RemoveLoadObserver( iControl );
       
   251         iControl->CancelExecution();
       
   252         iEnv->DeleteControlGroup( KAlfPerfAppGalleryControlGroup );
       
   253         }
       
   254     iImages.Close();
       
   255     delete iLoader;
       
   256     }
       
   257 
       
   258 void CAlfPerfAppGalleryTestCase::ImagesLoaded( TInt aErrorCode )
       
   259 	{
       
   260 	if( iStatus )
       
   261 		{
       
   262 		CAlfPerfAppTestCase::CompleteNow( *iStatus, aErrorCode );
       
   263 		iStatus = 0;
       
   264 		}
       
   265 	}
       
   266 
       
   267 // -----------------------------------------------------------------------------
       
   268 // Starts setup phase.
       
   269 // -----------------------------------------------------------------------------
       
   270 //
       
   271 void CAlfPerfAppGalleryTestCase::SetupL(
       
   272         CAlfEnv& aEnv, const TRect& /*aVisibleArea*/, TRequestStatus& aStatus )
       
   273     {
       
   274     iEnv = &aEnv;
       
   275 
       
   276     iStatus = &aStatus;
       
   277 
       
   278     CAlfPerfAppAppUi* appUi = (CAlfPerfAppAppUi*) EikonEnv()->AppUi();
       
   279 
       
   280     iOrientation = appUi->Orientation();
       
   281 
       
   282     switch ( iCaseId )
       
   283         {
       
   284         case EAlfPerfAppGallery:
       
   285         	{
       
   286         	appUi->SetOrientationL( CAknAppUiBase::EAppUiOrientationPortrait );
       
   287             break;
       
   288         	}
       
   289         case EAlfPerfAppGalleryLandscape:
       
   290         	{
       
   291         	appUi->SetOrientationL( CAknAppUiBase::EAppUiOrientationLandscape );
       
   292             break;
       
   293         	}
       
   294         default:
       
   295             User::Leave( KErrNotSupported );
       
   296             break;
       
   297         }
       
   298 
       
   299     TRect rect;
       
   300     AknLayoutUtils::LayoutMetricsRect(
       
   301         AknLayoutUtils::EApplicationWindow,
       
   302         rect );
       
   303 
       
   304     iEnv->SetFullScreenDrawing( ETrue );
       
   305     CAlfDisplay& display =
       
   306         iEnv->NewDisplayL( rect, CAlfEnv::ENewDisplayFullScreen );
       
   307     display.SetClearBackgroundL( CAlfDisplay::EClearWithSkinBackground );
       
   308 
       
   309     CAlfControlGroup& group =
       
   310         iEnv->NewControlGroupL( KAlfPerfAppGalleryControlGroup );
       
   311 
       
   312     iControl = CAlfPerfAppGalleryTestCaseControl::NewL(*iEnv, iCaseId, rect );
       
   313 
       
   314     group.AppendL( iControl ); // ownership passed to control group.
       
   315     iControl->SetImagesLoadedObserver( this );
       
   316 
       
   317     display.Roster().ShowL( group );
       
   318     }
       
   319 
       
   320 // -----------------------------------------------------------------------------
       
   321 // Starts execution phase.
       
   322 // -----------------------------------------------------------------------------
       
   323 //
       
   324 void CAlfPerfAppGalleryTestCase::ExecuteL( TRequestStatus& aStatus )
       
   325     {
       
   326     // SetupL must have been called first.
       
   327     __ASSERT_ALWAYS( iEnv, User::Invariant() );
       
   328     __ASSERT_ALWAYS( iControl, User::Invariant() );
       
   329     iControl->StartExecuteL( aStatus );
       
   330     }
       
   331 
       
   332 // -----------------------------------------------------------------------------
       
   333 // Tears down.
       
   334 // -----------------------------------------------------------------------------
       
   335 //
       
   336 void CAlfPerfAppGalleryTestCase::TearDown()
       
   337     {
       
   338     CAlfPerfAppAppUi* appUi = (CAlfPerfAppAppUi*) EikonEnv()->AppUi();
       
   339     TRAP_IGNORE( appUi->SetOrientationL( iOrientation ) );
       
   340     // Execution side will delete CAlfEnv, so it will delete everything
       
   341     // related to this.
       
   342     iEnv = NULL;
       
   343     iControl = NULL;
       
   344     }
       
   345 
       
   346 void CAlfPerfAppGalleryTestCase::HandleVisibleAreaChange( const TRect& aRect )
       
   347     {
       
   348     if ( iEnv && iControl )
       
   349         {
       
   350         if ( iEnv->DisplayCount() > 0 )
       
   351             {
       
   352             iEnv->PrimaryDisplay().SetVisibleArea( aRect );
       
   353             }
       
   354         iControl->SetVisibleArea( aRect );
       
   355         }
       
   356     }
       
   357 
       
   358 TInt CAlfPerfAppGalleryTestCase::CaseID()
       
   359     {
       
   360         return iCaseId;
       
   361     }
       
   362 
       
   363 CAlfPerfAppGalleryTestCase::CAlfPerfAppGalleryTestCase( TInt aCaseId, TInt aSequenceIndex )
       
   364     : CAlfPerfAppTestCase(aSequenceIndex), iCaseId ( aCaseId )
       
   365     {
       
   366     }
       
   367 
       
   368 void CAlfPerfAppGalleryTestCase::ConstructL()
       
   369     {
       
   370     }
       
   371 
       
   372 // Implementation of CAlfPerfAppGalleryTestCaseControl:
       
   373 
       
   374 static void GetImageTestCasePrivatePath( TFileName& aPath )
       
   375     {
       
   376     CEikonEnv::Static()->FsSession().PrivatePath( aPath );
       
   377     ::CompleteWithAppPath( aPath );
       
   378     }
       
   379 
       
   380 CAlfPerfAppGalleryTestCaseControl::CAlfPerfAppGalleryTestCaseControl()
       
   381     {
       
   382     }
       
   383 
       
   384 CAlfPerfAppGalleryTestCaseControl* CAlfPerfAppGalleryTestCaseControl::NewL(
       
   385 	CAlfEnv& aEnv, TInt aCaseId, const TRect& aVisibleArea )
       
   386 	{
       
   387 	CAlfPerfAppGalleryTestCaseControl* self = new (ELeave) CAlfPerfAppGalleryTestCaseControl();
       
   388     CleanupStack::PushL( self );
       
   389     self->ConstructL( aEnv, aCaseId, aVisibleArea );
       
   390     CleanupStack::Pop( self );
       
   391     return self;
       
   392 	}
       
   393 
       
   394 const TInt KNumberOfImages = 10;
       
   395 const TInt KImagePadding = 5;
       
   396 const TReal32 KNumberOfLinesInView = 3.5;
       
   397 //const TReal32 KNumberOfColumnsInView = 4.0;
       
   398 const TReal32 KNumberOfLinesInGrid = 5.0;
       
   399 const TReal32 KNumberOfColumnsInGrid = 4.0;
       
   400 
       
   401 void CAlfPerfAppGalleryTestCaseControl::ConstructL(
       
   402         CAlfEnv& aEnv, TInt aCaseId, const TRect& aVisibleArea )
       
   403     {
       
   404     iCaseId = aCaseId;
       
   405     CAlfControl::ConstructL( aEnv );
       
   406 
       
   407     TFileName privatePath;
       
   408     GetImageTestCasePrivatePath( privatePath );
       
   409     aEnv.TextureManager().SetImagePathL( privatePath );
       
   410 
       
   411     iLoadedImages = 0;
       
   412 
       
   413     // Viewport for grid
       
   414     iViewport = CAlfViewportLayout::AddNewL( *this, 0 );
       
   415     iViewport->SetClipping( EFalse );
       
   416     iViewport->SetVirtualSize( TAlfRealSize( 1.0, KNumberOfLinesInGrid ), 0 );
       
   417     iViewport->SetViewportSize( TAlfRealSize( 1.0, KNumberOfLinesInView ), 0 );
       
   418     iViewport->SetViewportPos( TAlfRealPoint( iViewportPosition, 0 ), 0 );
       
   419 
       
   420     // Background for viewport
       
   421     CAlfGradientBrush* brush = CAlfGradientBrush::NewLC( aEnv );
       
   422     brush->SetDirection( CAlfGradientBrush::EDirectionDown );
       
   423     brush->SetLayer( EAlfBrushLayerBackground );
       
   424     brush->SetColor( KRgbBlack );
       
   425     brush->AppendColorL( 1.0f, KRgbGray );
       
   426     iViewport->EnableBrushesL( ETrue );
       
   427     iViewport->Brushes()->AppendL( brush, EAlfHasOwnership );
       
   428     CleanupStack::Pop( brush );
       
   429 
       
   430     // Grid for images
       
   431     iGridLayout = CAlfGridLayout::AddNewL(
       
   432         *this,
       
   433         KNumberOfColumnsInGrid,
       
   434         KNumberOfLinesInGrid,  // lines of images
       
   435         iViewport );
       
   436 
       
   437     // Images
       
   438     // NOTE: Now using small images for OpenVG, because of memory issues.
       
   439     // These files may be replaced for BitGDI if needed. 
       
   440     _LIT( KImage1, "alfphotos_small1.jpg" );
       
   441     _LIT( KImage2, "alfphotos_small2.jpg" );
       
   442     _LIT( KImage3, "alfphotos_small3.jpg" );
       
   443     _LIT( KImage4, "alfphotos_small4.jpg" );
       
   444     _LIT( KImage5, "alfphotos_small5.jpg" );
       
   445     _LIT( KImage6, "alfphotos_small6.jpg" );
       
   446     _LIT( KImage7, "alfphotos_small7.jpg" );
       
   447     _LIT( KImage8, "alfphotos_small8.jpg" );
       
   448     _LIT( KImage9, "alfphotos_small9.jpg" );
       
   449     _LIT( KImage10, "jpg_sun_small.jpg" );
       
   450     
       
   451     // Visual tags
       
   452     _LIT8( KVisual1, "visual1" );
       
   453     _LIT8( KVisual2, "visual2" );
       
   454     _LIT8( KVisual3, "visual3" );
       
   455     _LIT8( KVisual4, "visual4" );
       
   456     _LIT8( KVisual5, "visual5" );
       
   457     _LIT8( KVisual6, "visual6" );
       
   458     _LIT8( KVisual7, "visual7" );
       
   459     _LIT8( KVisual8, "visual8" );
       
   460     _LIT8( KVisual9, "visual9" );
       
   461     _LIT8( KVisual10, "visual10" );
       
   462     _LIT8( KVisual11, "visual11" );
       
   463     _LIT8( KVisual12, "visual12" );
       
   464     _LIT8( KVisual13, "visual13" );
       
   465     _LIT8( KVisual14, "visual14" );
       
   466     _LIT8( KVisual15, "visual15" );
       
   467     _LIT8( KVisual16, "visual16" );
       
   468     _LIT8( KVisual17, "visual17" );
       
   469     _LIT8( KVisual18, "visual18" );
       
   470     _LIT8( KVisual19, "visual19" );
       
   471     _LIT8( KVisual20, "visual20" );
       
   472 
       
   473     // Captions for image metadata text field
       
   474     _LIT( KImageCaption1, "alfphotos1" );
       
   475     _LIT( KImageCaption5, "alfphotos5" );
       
   476     _LIT( KImageCaption8, "alfphotos8" );
       
   477 
       
   478     // The order of the visuals in image focusing
       
   479     iImagesToBeFocused.Append( &KVisual17 );
       
   480     iImagesToBeFocused.Append( &KVisual5 );
       
   481     iImagesToBeFocused.Append( &KVisual1 );
       
   482 
       
   483     // The corresponding image captions in image focusing
       
   484     iImageCaptions.Append( &KImageCaption8 );
       
   485     iImageCaptions.Append( &KImageCaption5 );
       
   486     iImageCaptions.Append( &KImageCaption1 );
       
   487 
       
   488     aEnv.TextureManager().AddLoadObserverL( this );
       
   489 
       
   490     // Load textures for images
       
   491     CAlfTexture& texture1 = aEnv.TextureManager().LoadTextureL(
       
   492         KImage1,
       
   493         EAlfTextureFlagRetainResolution,
       
   494         KAlfAutoGeneratedTextureId );
       
   495     CAlfTexture& texture2 = aEnv.TextureManager().LoadTextureL(
       
   496         KImage2,
       
   497         EAlfTextureFlagRetainResolution,
       
   498         KAlfAutoGeneratedTextureId );
       
   499     CAlfTexture& texture3 = aEnv.TextureManager().LoadTextureL(
       
   500         KImage3,
       
   501         EAlfTextureFlagRetainResolution,
       
   502         KAlfAutoGeneratedTextureId );
       
   503     CAlfTexture& texture4 = aEnv.TextureManager().LoadTextureL(
       
   504         KImage4,
       
   505         EAlfTextureFlagRetainResolution,
       
   506         KAlfAutoGeneratedTextureId );
       
   507     CAlfTexture& texture5 = aEnv.TextureManager().LoadTextureL(
       
   508         KImage5,
       
   509         EAlfTextureFlagRetainResolution,
       
   510         KAlfAutoGeneratedTextureId );
       
   511     CAlfTexture& texture6 = aEnv.TextureManager().LoadTextureL(
       
   512         KImage6,
       
   513         EAlfTextureFlagRetainResolution,
       
   514         KAlfAutoGeneratedTextureId );
       
   515     CAlfTexture& texture7 = aEnv.TextureManager().LoadTextureL(
       
   516         KImage7,
       
   517         EAlfTextureFlagRetainResolution,
       
   518         KAlfAutoGeneratedTextureId );
       
   519     CAlfTexture& texture8 = aEnv.TextureManager().LoadTextureL(
       
   520         KImage8,
       
   521         EAlfTextureFlagRetainResolution,
       
   522         KAlfAutoGeneratedTextureId );
       
   523     CAlfTexture& texture9 = aEnv.TextureManager().LoadTextureL(
       
   524         KImage9,
       
   525         EAlfTextureFlagRetainResolution,
       
   526         KAlfAutoGeneratedTextureId );
       
   527     CAlfTexture& texture10 = aEnv.TextureManager().LoadTextureL(
       
   528         KImage10,
       
   529         EAlfTextureFlagRetainResolution,
       
   530         KAlfAutoGeneratedTextureId );
       
   531 
       
   532     // Add visuals to image grid
       
   533     CAlfImageVisual* visual1 = CAlfImageVisual::AddNewL( *this, iGridLayout );
       
   534     visual1->SetImage( TAlfImage( texture1 ) );
       
   535     visual1->SetPadding( KImagePadding );
       
   536     visual1->SetTagL( KVisual1 );
       
   537     CAlfImageVisual* visual2 = CAlfImageVisual::AddNewL( *this, iGridLayout );
       
   538     visual2->SetImage( TAlfImage( texture2 ) );
       
   539     visual2->SetPadding( KImagePadding );
       
   540     visual2->SetTagL( KVisual2 );
       
   541     CAlfImageVisual* visual3 = CAlfImageVisual::AddNewL( *this, iGridLayout );
       
   542     visual3->SetImage( TAlfImage( texture3 ) );
       
   543     visual3->SetPadding( KImagePadding );
       
   544     visual3->SetTagL( KVisual3 );
       
   545     CAlfImageVisual* visual4 = CAlfImageVisual::AddNewL( *this, iGridLayout );
       
   546     visual4->SetImage( TAlfImage( texture4 ) );
       
   547     visual4->SetPadding( KImagePadding );
       
   548     visual4->SetTagL( KVisual4 );
       
   549     CAlfImageVisual* visual5 = CAlfImageVisual::AddNewL( *this, iGridLayout );
       
   550     visual5->SetImage( TAlfImage( texture5 ) );
       
   551     visual5->SetPadding( KImagePadding );
       
   552     visual5->SetTagL( KVisual5 );
       
   553     CAlfImageVisual* visual6 = CAlfImageVisual::AddNewL( *this, iGridLayout );
       
   554     visual6->SetImage( TAlfImage( texture6 ) );
       
   555     visual6->SetPadding( KImagePadding );
       
   556     visual6->SetTagL( KVisual6 );
       
   557     CAlfImageVisual* visual7 = CAlfImageVisual::AddNewL( *this, iGridLayout );
       
   558     visual7->SetImage( TAlfImage( texture7 ) );
       
   559     visual7->SetPadding( KImagePadding );
       
   560     visual7->SetTagL( KVisual7 );
       
   561     CAlfImageVisual* visual8 = CAlfImageVisual::AddNewL( *this, iGridLayout );
       
   562     visual8->SetImage( TAlfImage( texture8 ) );
       
   563     visual8->SetPadding( KImagePadding );
       
   564     visual8->SetTagL( KVisual8 );
       
   565     CAlfImageVisual* visual9 = CAlfImageVisual::AddNewL( *this, iGridLayout );
       
   566     visual9->SetImage( TAlfImage( texture9 ) );
       
   567     visual9->SetPadding( KImagePadding );
       
   568     visual9->SetTagL( KVisual9 );
       
   569     CAlfImageVisual* visual10 = CAlfImageVisual::AddNewL( *this, iGridLayout );
       
   570     visual10->SetImage( TAlfImage( texture10 ) );
       
   571     visual10->SetPadding( KImagePadding );
       
   572     visual10->SetTagL( KVisual10 );
       
   573     CAlfImageVisual* visual11 = CAlfImageVisual::AddNewL( *this, iGridLayout );
       
   574     visual11->SetImage( TAlfImage( texture2 ) );
       
   575     visual11->SetPadding( KImagePadding );
       
   576     visual11->SetTagL( KVisual11 );
       
   577     CAlfImageVisual* visual12 = CAlfImageVisual::AddNewL( *this, iGridLayout );
       
   578     visual12->SetImage( TAlfImage( texture3 ) );
       
   579     visual12->SetPadding( KImagePadding );
       
   580     visual12->SetTagL( KVisual12 );
       
   581     CAlfImageVisual* visual13 = CAlfImageVisual::AddNewL( *this, iGridLayout );
       
   582     visual13->SetImage( TAlfImage( texture4 ) );
       
   583     visual13->SetPadding( KImagePadding );
       
   584     visual13->SetTagL( KVisual13 );
       
   585     CAlfImageVisual* visual14 = CAlfImageVisual::AddNewL( *this, iGridLayout );
       
   586     visual14->SetImage( TAlfImage( texture5 ) );
       
   587     visual14->SetPadding( KImagePadding );
       
   588     visual14->SetTagL( KVisual14 );
       
   589     CAlfImageVisual* visual15 = CAlfImageVisual::AddNewL( *this, iGridLayout );
       
   590     visual15->SetImage( TAlfImage( texture6 ) );
       
   591     visual15->SetPadding( KImagePadding );
       
   592     visual15->SetTagL( KVisual15 );
       
   593     CAlfImageVisual* visual16 = CAlfImageVisual::AddNewL( *this, iGridLayout );
       
   594     visual16->SetImage( TAlfImage( texture7 ) );
       
   595     visual16->SetPadding( KImagePadding );
       
   596     visual16->SetTagL( KVisual16 );
       
   597     CAlfImageVisual* visual17 = CAlfImageVisual::AddNewL( *this, iGridLayout );
       
   598     visual17->SetImage( TAlfImage( texture8 ) );
       
   599     visual17->SetPadding( KImagePadding );
       
   600     visual17->SetTagL( KVisual17 );
       
   601     CAlfImageVisual* visual18 = CAlfImageVisual::AddNewL( *this, iGridLayout );
       
   602     visual18->SetImage( TAlfImage( texture9 ) );
       
   603     visual18->SetPadding( KImagePadding );
       
   604     visual18->SetTagL( KVisual18 );
       
   605     CAlfImageVisual* visual19 = CAlfImageVisual::AddNewL( *this, iGridLayout );
       
   606     visual19->SetImage( TAlfImage( texture1 ) );
       
   607     visual19->SetPadding( KImagePadding );
       
   608     visual19->SetTagL( KVisual19 );
       
   609     CAlfImageVisual* visual20 = CAlfImageVisual::AddNewL( *this, iGridLayout );
       
   610     visual20->SetImage( TAlfImage( texture2 ) );
       
   611     visual20->SetPadding( KImagePadding );
       
   612     visual20->SetTagL( KVisual20 );
       
   613 
       
   614     // Focus on visual 1
       
   615 	CAlfBorderBrush* actualBorder = CAlfBorderBrush::NewLC( Env(), 4, 4, 0, 0 );
       
   616 	actualBorder->SetColor( KRgbBlue );
       
   617 	visual1->EnableBrushesL( ETrue );
       
   618 	visual1->Brushes()->AppendL( actualBorder, EAlfHasOwnership );
       
   619 	CleanupStack::Pop( actualBorder );
       
   620 
       
   621     // Area for image metadata
       
   622     TRect textFieldArea;
       
   623     textFieldArea.SetWidth( aVisibleArea.Width() );
       
   624     textFieldArea.SetHeight( aVisibleArea.Height() / 7 );
       
   625 
       
   626     // Layout for image metadata
       
   627     CAlfGridLayout* iImageInfoLayout = CAlfGridLayout::AddNewL( *this, 1, 1, 0 );
       
   628     iImageInfoLayout->EnableBrushesL( ETrue );
       
   629     iImageInfoLayout->SetFlag( EAlfVisualFlagManualSize );
       
   630     iImageInfoLayout->SetFlag( EAlfVisualFlagManualPosition );
       
   631     iImageInfoLayout->SetRect( textFieldArea, 0 );
       
   632     iImageInfoLayout->SetPos( TAlfRealPoint( 0 , aVisibleArea.Height() - textFieldArea.Height() ) , 0 );
       
   633 
       
   634     // Text for image metadata
       
   635     CAlfTextVisual* text = CAlfTextVisual::AddNewL( *this, iImageInfoLayout );
       
   636     text->SetTextL( KImageCaption1 );
       
   637     text->EnableBrushesL( ETrue );
       
   638     text->SetColor( KRgbWhite );
       
   639     text->SetTagL( _L8( "text1" ) );
       
   640 
       
   641     // Background for image metadata
       
   642     CAlfGradientBrush* textBackgroundBrush = CAlfGradientBrush::NewLC( aEnv );
       
   643     textBackgroundBrush->SetColor( KRgbGray );
       
   644     textBackgroundBrush->SetOpacity( 0.5f );
       
   645     textBackgroundBrush->SetLayer( EAlfBrushLayerBackground );
       
   646     iImageInfoLayout->Brushes()->AppendL( textBackgroundBrush, EAlfHasOwnership );
       
   647     CleanupStack::Pop( textBackgroundBrush );
       
   648 
       
   649     // Border for image metadata
       
   650     CAlfBorderBrush* border = CAlfBorderBrush::NewLC( aEnv, 2, 2, 5, 5 );
       
   651     border->SetOpacity( 0.5f );
       
   652     iImageInfoLayout->Brushes()->AppendL( border, EAlfHasOwnership );
       
   653     CleanupStack::Pop( border );
       
   654     }
       
   655 
       
   656 CAlfPerfAppGalleryTestCaseControl::~CAlfPerfAppGalleryTestCaseControl()
       
   657     {
       
   658     CompleteNow( KErrCancel );
       
   659     iImageCaptions.Reset();
       
   660     iImagesToBeFocused.Reset();
       
   661     }
       
   662 
       
   663 void CAlfPerfAppGalleryTestCaseControl::SetImagesLoadedObserver( MImagesLoadedObserver* aObserver )
       
   664 	{
       
   665 	iObserver = aObserver;
       
   666 	}
       
   667 
       
   668 // -----------------------------------------------------------------------------
       
   669 // Notify observers that all images have been loaded.
       
   670 // -----------------------------------------------------------------------------
       
   671 //
       
   672 void CAlfPerfAppGalleryTestCaseControl::TextureLoadingCompleted(
       
   673 		CAlfTexture& /*aTexture*/, TInt /*aTextureId*/, TInt aErrorCode)
       
   674 	{
       
   675 	// inform if there is any error
       
   676 	if( aErrorCode != KErrNone )
       
   677 	    {
       
   678 	    iObserver->ImagesLoaded( aErrorCode );
       
   679 	    }
       
   680 
       
   681 	iLoadedImages++;
       
   682 	if (iLoadedImages == KNumberOfImages)
       
   683 		{
       
   684 		iObserver->ImagesLoaded( KErrNone );
       
   685 		}
       
   686 	}
       
   687 
       
   688 void CAlfPerfAppGalleryTestCaseControl::StartExecuteL( TRequestStatus& aStatus )
       
   689     {
       
   690     iCycleCount = 0;
       
   691     iFocusChangedCount = 0;
       
   692     iGridScrolledCount = 0;
       
   693     iViewportPosition = 0;
       
   694     iPreviousViewportPosition = -1; // no previous position
       
   695     iStatus = &aStatus;
       
   696     *iStatus = KRequestPending;
       
   697 
       
   698     TRAPD( err, DoStartExecuteL() );
       
   699     if ( err != KErrNone )
       
   700         {
       
   701         iStatus = NULL;
       
   702         User::Leave( err );
       
   703         }
       
   704     }
       
   705 
       
   706 void CAlfPerfAppGalleryTestCaseControl::CancelExecution()
       
   707     {
       
   708     CompleteNow( KErrCancel );
       
   709     }
       
   710 
       
   711 void CAlfPerfAppGalleryTestCaseControl::DoStartExecuteL()
       
   712     {
       
   713     NextScrollCycleL();
       
   714     CompleteAfterL( KTransitionWaitTime );
       
   715     }
       
   716 
       
   717 void CAlfPerfAppGalleryTestCaseControl::SetVisibleArea(
       
   718         const TRect& /*aVisibleArea*/ )
       
   719     {
       
   720     }
       
   721 
       
   722 TBool CAlfPerfAppGalleryTestCaseControl::OfferEventL( const TAlfEvent& aEvent )
       
   723     {
       
   724     if ( aEvent.IsCustomEvent() &&
       
   725          aEvent.CustomParameter() == KAlfPerfAppGalleryCmdCompleteNow )
       
   726         {
       
   727         const TInt KNumberOfExecutedMovements = 15;
       
   728         if ( iCycleCount < KNumberOfExecutedMovements )
       
   729         	{
       
   730 // Disabling the image focusing between scroll cycles
       
   731 #if 0
       
   732         	TInt odd = iCycleCount % 2;
       
   733         	if( odd == 0 )
       
   734         		{
       
   735 #endif
       
   736         		NextScrollCycleL();
       
   737         		CompleteAfterL( KTransitionWaitTime );
       
   738 #if 0
       
   739         		}
       
   740         	else
       
   741         		{
       
   742         		NextFocusCycleL();
       
   743         		CompleteAfterL( 0 );
       
   744         		}
       
   745 #endif
       
   746         	}
       
   747         else
       
   748         	{
       
   749         	CompleteNow( KErrNone );
       
   750         	}
       
   751 
       
   752         return ETrue;
       
   753         }
       
   754 
       
   755     return CAlfControl::OfferEventL( aEvent );
       
   756     }
       
   757 
       
   758 void CAlfPerfAppGalleryTestCaseControl::NextScrollCycleL()
       
   759 	{
       
   760 	static const TReal32 movements[] = { -2, 1, 1 };
       
   761 
       
   762 	const TInt size = 3; //sizeof movements;
       
   763 	const TInt index = iGridScrolledCount % size;
       
   764 
       
   765 	MoveImages(movements[ index ]);
       
   766 
       
   767 	++iCycleCount;
       
   768 	++iGridScrolledCount;
       
   769 	}
       
   770 
       
   771 
       
   772 void CAlfPerfAppGalleryTestCaseControl::NextFocusCycleL()
       
   773 	{
       
   774 	const TInt size = 3;
       
   775 	const TInt index = iFocusChangedCount % size;
       
   776 
       
   777 	UpdateImageFocus( index );
       
   778 
       
   779 	++iCycleCount;
       
   780 	++iFocusChangedCount;
       
   781 	}
       
   782 
       
   783 
       
   784 
       
   785 void CAlfPerfAppGalleryTestCaseControl::UpdateImageFocus( TInt aIndex )
       
   786 	{
       
   787 	// TODO: Checking if textVisual can be found
       
   788 	CAlfTextVisual* textVisual = static_cast<CAlfTextVisual*>( FindTag( _L8( "text1" ) ) );
       
   789     TRAP_IGNORE(textVisual->SetTextL( *iImageCaptions.operator[]( aIndex ) ));
       
   790     TRAP_IGNORE(SetImageFocusL( *iImagesToBeFocused.operator[]( aIndex ) ));
       
   791 	}
       
   792 
       
   793 
       
   794 void CAlfPerfAppGalleryTestCaseControl::MoveImages(
       
   795     TReal32 aAmount,
       
   796     TReal32 aTransitionTime )
       
   797     {
       
   798     iPreviousViewportPosition = iViewportPosition;
       
   799     iViewportPosition -= aAmount;
       
   800 
       
   801     if ( iViewportPosition < 0 )
       
   802         {
       
   803         iViewportPosition = 0;
       
   804         }
       
   805     else if ( iViewportPosition > ( KNumberOfLinesInView - 1.0 ) )
       
   806         {
       
   807         iViewportPosition = KNumberOfLinesInView - 1.0;
       
   808         }
       
   809 
       
   810     iViewport->SetViewportPos(
       
   811             TAlfRealPoint( 0, iViewportPosition ),
       
   812         aTransitionTime );
       
   813     }
       
   814 
       
   815 
       
   816 void CAlfPerfAppGalleryTestCaseControl::SetImageFocusL( const TDesC8& aImageTag )
       
   817 	{
       
   818 
       
   819 	//TODO: No checking if FindTag finds anything
       
   820 	CAlfImageVisual* visual =
       
   821 			static_cast<CAlfImageVisual*>( FindTag( aImageTag ) );
       
   822 
       
   823 	if( iFocusedVisual && iFocusedVisual->Brushes() )
       
   824 		{
       
   825 		// TODO: At the moment, no checking of the brush type
       
   826 		CAlfBorderBrush* brush =
       
   827 				static_cast<CAlfBorderBrush*>( &iFocusedVisual->Brushes()->At( 0 ) );
       
   828 		iFocusedVisual->Brushes()->Remove( 0 );
       
   829 		}
       
   830 
       
   831 	if( visual )
       
   832 		{
       
   833 		CAlfBorderBrush* actualBorder = CAlfBorderBrush::NewLC( Env(), 4, 4, 0, 0 );
       
   834 		if(actualBorder)
       
   835 		    {
       
   836 		    actualBorder->SetColor( KRgbBlue );
       
   837 		    }
       
   838 		visual->EnableBrushesL( ETrue );
       
   839 		visual->Brushes()->AppendL( actualBorder, EAlfHasOwnership );
       
   840 		CleanupStack::Pop( actualBorder );
       
   841 		}
       
   842 
       
   843 	iFocusedVisual = visual;
       
   844 	}
       
   845 
       
   846 void CAlfPerfAppGalleryTestCaseControl::CompleteAfterL( TInt aDuration )
       
   847     {
       
   848     // In order to use this service, base class StartExecuteL must
       
   849     // have been called.
       
   850     __ASSERT_ALWAYS( iStatus, User::Invariant() );
       
   851 
       
   852     TAlfCustomEventCommand command( KAlfPerfAppGalleryCmdCompleteNow, this );
       
   853     User::LeaveIfError( Env().Send( command, aDuration ) );
       
   854     }
       
   855 
       
   856 void CAlfPerfAppGalleryTestCaseControl::CompleteNow( TInt aErrorCode )
       
   857     {
       
   858     if ( iStatus )
       
   859         {
       
   860         User::RequestComplete( iStatus, aErrorCode );
       
   861         iStatus = NULL;
       
   862         }
       
   863     }
       
   864 
       
   865 inline TInt CAlfPerfAppGalleryTestCaseControl::CaseId() const
       
   866     {
       
   867     return iCaseId;
       
   868     }
       
   869 
       
   870 inline TBool CAlfPerfAppGalleryTestCaseControl::IsExecutionOngoing() const
       
   871     {
       
   872     return ( iStatus != NULL );
       
   873     }
       
   874