graphicstest/uibench/src/tscaleddrawbitmap.cpp
changeset 0 5d03bc08d59c
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 /**
       
    17  @file
       
    18  @test
       
    19  @internalComponent - Internal Symbian test code 
       
    20 */
       
    21 
       
    22 #include "tscaleddrawbitmap.h"
       
    23 
       
    24 const TInt KIterationsToTest = 55;
       
    25 const TInt KDelay = 500*1000; // 0.5 seconds
       
    26 
       
    27 #define __CyclesPerPixel(__a,__b) ((TInt)(((__a/(TInt64)__b)*((TInt64)iCPUSpeed)/((TInt64)(iWindowSize.iWidth*iWindowSize.iHeight)))/(TInt64)1000))
       
    28 
       
    29 _LIT(KAlphaTestBitmap,"z:\\system\\data\\uibench_24bit.mbm");
       
    30 
       
    31 const TDisplayMode ModeArray[]=
       
    32 	{
       
    33 	EColor64K,
       
    34 	EColor16MU,
       
    35 	EColor16MA,
       
    36 	EColor16MAP
       
    37 	};
       
    38 const TInt ModeCount=sizeof(ModeArray)/sizeof(ModeArray[0]);
       
    39 
       
    40 #define FPSHFT 8
       
    41 #define VARSIZE TSize((actsizexFP>>FPSHFT),(actsizeyFP>>FPSHFT))
       
    42 
       
    43 /**
       
    44    @SYMTestCaseID
       
    45    GRAPHICS-UI-BENCH-0020
       
    46 
       
    47    @SYMTestCaseDesc
       
    48    The test determines how long DrawBitmap function takes when scaling is involved.
       
    49 
       
    50    @SYMTestActions
       
    51    Compare the results over time, and before and after changes to wserv code.
       
    52 
       
    53    @SYMTestExpectedResults
       
    54    Test should pass and display total test time and cycles per pixel
       
    55 */
       
    56 void CTScaledDrawBitmap::DoTestScaledDrawBitmapL(TInt aRotation, TDisplayMode aMode, TDisplayMode aScreenMode, TInt aIters) 
       
    57 	{
       
    58 	TSize siz=iScreenDevice->SizeInPixels();
       
    59 	
       
    60 	CFbsBitmap * bmpModeDep = CreateSoftwareBitmapLC(siz, aMode);
       
    61 	
       
    62 	CFbsBitmap * sourceOverImage = LoadBitmapL(KAlphaTestBitmap,0);
       
    63 	CleanupStack::PushL(sourceOverImage);
       
    64 	
       
    65 	CopyBitmapL(bmpModeDep, sourceOverImage);
       
    66 	
       
    67 	TInt startsizeFP=1<<FPSHFT;
       
    68 	TInt endscale=1;
       
    69 	
       
    70 	TInt endsizexFP= (endscale*iScreenDevice->SizeInPixels().iWidth)<<FPSHFT;
       
    71 	TInt endsizeyFP= (endscale*iScreenDevice->SizeInPixels().iHeight)<<FPSHFT;
       
    72 	
       
    73 	TInt dxFP=(endsizexFP - startsizeFP)/aIters;
       
    74 	TInt dyFP=(endsizeyFP - startsizeFP)/aIters;
       
    75 	
       
    76 	TInt actsizexFP=startsizeFP;
       
    77 	TInt actsizeyFP=startsizeFP;
       
    78 
       
    79 	iProfiler->InitResults();	
       
    80 	for (TInt i=1;i<aIters;i++)
       
    81 	{
       
    82 		iGc->DrawBitmap(siz, bmpModeDep,VARSIZE);
       
    83 		actsizexFP+=dxFP;
       
    84 		actsizeyFP+=dyFP;
       
    85 		iProfiler->MarkResultSetL();
       
    86 	}
       
    87 
       
    88 	iProfiler->ResultsAnalysis(_L("ScaledDrawBmpVarDest"), aRotation, aMode, aScreenMode, aIters);
       
    89 		
       
    90 	startsizeFP=1<<FPSHFT;
       
    91 	endscale=50;
       
    92 	
       
    93 	endsizexFP= (endscale*iScreenDevice->SizeInPixels().iWidth)<<FPSHFT;
       
    94 	endsizeyFP= (endscale*iScreenDevice->SizeInPixels().iHeight)<<FPSHFT;
       
    95 	
       
    96 	dxFP=(endsizexFP - startsizeFP)/aIters;
       
    97 	dyFP=(endsizeyFP - startsizeFP)/aIters;
       
    98 	
       
    99 	actsizexFP=startsizeFP;
       
   100 	actsizeyFP=startsizeFP;
       
   101 
       
   102 	iProfiler->InitResults();	
       
   103 	for (TInt i=1;i<aIters;i++)
       
   104 	{
       
   105 		iGc->DrawBitmap(VARSIZE, bmpModeDep, siz);
       
   106 		actsizexFP+=dxFP;
       
   107 		actsizeyFP+=dyFP;
       
   108 		iProfiler->MarkResultSetL();
       
   109 	}
       
   110 	iProfiler->ResultsAnalysis(_L("ScaledDrawBmpVarSrc"), aRotation, aMode, aScreenMode, aIters);
       
   111 
       
   112 	CFbsBitmap * greyMask = CreateSoftwareBitmapLC(iScreenDevice->SizeInPixels(), EGray256);
       
   113 	VerticalGradientAlphaL(greyMask, TRgb(0xffffffff), TRgb(0x00000000));
       
   114 	
       
   115 	CFbsBitmap * bmpMask = CreateSoftwareBitmapLC(iScreenDevice->SizeInPixels(), EGray2);
       
   116 	CopyBitmapL(bmpMask, greyMask);
       
   117 			
       
   118 	startsizeFP=1<<FPSHFT;
       
   119 	endscale=1;
       
   120 	
       
   121 	endsizexFP= (endscale*iScreenDevice->SizeInPixels().iWidth)<<FPSHFT;
       
   122 	endsizeyFP= (endscale*iScreenDevice->SizeInPixels().iHeight)<<FPSHFT;
       
   123 	
       
   124 	dxFP=(endsizexFP - startsizeFP)/aIters;
       
   125 	dyFP=(endsizeyFP - startsizeFP)/aIters;
       
   126 	
       
   127 	actsizexFP=startsizeFP;
       
   128 	actsizeyFP=startsizeFP;
       
   129 
       
   130 	iProfiler->InitResults();
       
   131 	for (TInt i=1;i<aIters;i++)
       
   132 	{
       
   133 		// Parameters: DrawBitmapMasked(const TRect &aDestRect, const CWsBitmap *aBitmap, const TRect &aSourceRect, const CWsBitmap *aMaskBitmap, TBool aInvertMask)
       
   134 		iGc->DrawBitmapMasked(siz, bmpModeDep, VARSIZE, bmpMask, ETrue);
       
   135 		actsizexFP+=dxFP;
       
   136 		actsizeyFP+=dyFP;
       
   137 		iProfiler->MarkResultSetL();
       
   138 	}
       
   139 	iProfiler->ResultsAnalysis(_L("ScaledDrawBmpMskdVarDest"), aRotation, aMode, aScreenMode, aIters);
       
   140 	
       
   141 	startsizeFP=1<<FPSHFT;
       
   142 	endscale=50;
       
   143 	
       
   144 	endsizexFP= (endscale*iScreenDevice->SizeInPixels().iWidth)<<FPSHFT;
       
   145 	endsizeyFP= (endscale*iScreenDevice->SizeInPixels().iHeight)<<FPSHFT;
       
   146 	
       
   147 	dxFP=(endsizexFP - startsizeFP)/aIters;
       
   148 	dyFP=(endsizeyFP - startsizeFP)/aIters;
       
   149 	
       
   150 	actsizexFP=startsizeFP;
       
   151 	actsizeyFP=startsizeFP;
       
   152 
       
   153 	iProfiler->InitResults();
       
   154 	for (TInt i=1;i<aIters;i++)
       
   155 	{	
       
   156 		iGc->DrawBitmapMasked(VARSIZE, bmpModeDep, siz, bmpMask,ETrue);
       
   157 		actsizexFP+=dxFP;
       
   158 		actsizeyFP+=dyFP;
       
   159 		iProfiler->MarkResultSetL();
       
   160 	}
       
   161 	
       
   162 	iProfiler->ResultsAnalysis(_L("ScaledDrawBmpMskdVarSrc"), aRotation, aMode, aScreenMode, aIters);
       
   163 
       
   164 	CleanupStack::PopAndDestroy(4, bmpModeDep); // bmpMask, greyMask, sourceOverImage, bmpModeDep
       
   165 	User::After(KDelay);
       
   166 	}
       
   167 
       
   168 CTScaledDrawBitmap::CTScaledDrawBitmap()
       
   169 	{
       
   170 	SetTestStepName(KTScaledDrawBitmap);
       
   171 	}
       
   172 	
       
   173 /**
       
   174 @return - TVerdict code
       
   175 Override of base class pure virtual
       
   176 Our implementation only gets called if the base class doTestStepPreambleL() did
       
   177 not leave. That being the case, the current test result value will be EPass.
       
   178 */	
       
   179 TVerdict CTScaledDrawBitmap::doTestStepL()
       
   180 	{	
       
   181 	TBool orientation[4];
       
   182 	TRect blockRect(10, 10, 200, 180);
       
   183 
       
   184 	for(TInt dispModeIndex = 0; dispModeIndex < KNumValidDisplayModes; dispModeIndex++)
       
   185 		{
       
   186 		SetScreenModeL(KValidDisplayModes[dispModeIndex]);		
       
   187 		iGc->OrientationsAvailable(orientation);
       
   188 		for (TInt orient = CFbsBitGc::EGraphicsOrientationNormal; orient <= CFbsBitGc::EGraphicsOrientationRotated270; orient++)
       
   189 			{
       
   190 			if (orientation[orient])
       
   191 				{
       
   192 				iGc->SetOrientation((CFbsBitGc::TGraphicsOrientation)orient);
       
   193 				SetTestStepID(_L(" GRAPHICS-UI-BENCH-0020"));
       
   194 
       
   195 				// test drawing speed of scaled bitmaps
       
   196 				for (TInt m=0; m<ModeCount; m++)
       
   197 					DoTestScaledDrawBitmapL(orient, ModeArray[m], KValidDisplayModes[dispModeIndex], KIterationsToTest);
       
   198 				RecordTestResultL();
       
   199 				}
       
   200 			}
       
   201 		}
       
   202 	return TestStepResult();
       
   203 	}
       
   204