os/graphics/graphicstest/uibench/src/tfbsbitmaphandleperf.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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 "tfbsbitmaphandleperf.h"
    23 
    24 const TInt KIterationsToTest = 1000;
    25 const TInt KMaxNumSmallTestBitmaps = 40;
    26 const TInt KMaxNumLargeTestBitmaps = 4;
    27 const TInt KNumTestBitmapSizes = 8;
    28 const TDisplayMode KTestDisplayMode = EColor256;
    29 const TDisplayMode KTestDisplayMode2 = EColor64K;
    30 
    31 
    32 CTFbsBitmapHandlePerf::CTFbsBitmapHandlePerf()
    33 	{
    34 	SetTestStepName(KTFbsBitmapHandlePerfName);
    35 	} 
    36 
    37 CTFbsBitmapHandlePerf::~CTFbsBitmapHandlePerf()
    38 	{
    39 	iTestBitmaps.ResetAndDestroy();
    40 	}
    41 
    42 /**
    43 Override of base class pure virtual
    44 Our implementation only gets called if the base class doTestStepPreambleL() did
    45 not leave. That being the case, the current test result value will be EPass.
    46 
    47 @return - TVerdict code
    48 */
    49 TVerdict CTFbsBitmapHandlePerf::doTestStepL()
    50 	{
    51 	SetTestStepID(_L("GRAPHICS-UI-BENCH-0074"));
    52 	SmallBitmapCreationL(KTestDisplayMode, _L("Small Bitmap-Create")); //8 bit
    53 	RecordTestResultL();
    54 	SetTestStepID(_L("GRAPHICS-UI-BENCH-0006"));
    55 	LargeBitmapCreationL(KTestDisplayMode, _L("Large Bitmap-Create"));
    56 	RecordTestResultL();
    57 	SetTestStepID(_L("GRAPHICS-UI-BENCH-0087"));
    58 	SmallBitmapCreationSimpleL();
    59 	RecordTestResultL();
    60 	SetTestStepID(_L("GRAPHICS-UI-BENCH-0088"));
    61 	LargeBitmapCreationSimpleL();
    62 	RecordTestResultL();
    63 	SetTestStepID(_L("GRAPHICS-UI-BENCH-0007"));
    64 	BitmapDuplicateL();		
    65 	RecordTestResultL();
    66 	return TestStepResult();
    67 	}
    68 
    69 /**
    70 Creates and destroys bitmaps KIterationsToTest times with various sizes
    71 using a pseudo-random sequence to try to simulate real usage patterns.
    72 
    73 @param aSizes Array of KNumTestBitmapSizes sizes to create bitmaps with.
    74 @param aMaxNumBitmaps Maximum number of created but not yet deleted bitmaps at any given time.
    75 @param aDisplayMode The display mode to create bitmaps with.
    76 */
    77 void CTFbsBitmapHandlePerf::BitmapCreationL(const TSize aSizes[], TInt aMaxNumBitmaps, const TDisplayMode aDisplayMode)
    78 	{
    79 	TInt64 seed = 0;
    80 	iProfiler->InitResults();
    81 	for (TInt count = KIterationsToTest; count > 0; --count)
    82 		{
    83 		CFbsBitmap* bitmap = new(ELeave) CFbsBitmap;
    84 		CleanupStack::PushL(bitmap);
    85 		TInt err = bitmap->Create(aSizes[count % KNumTestBitmapSizes], aDisplayMode);
    86 		User::LeaveIfError(err);
    87 		iTestBitmaps.AppendL(bitmap);
    88 		CleanupStack::Pop(bitmap);
    89 		if (iTestBitmaps.Count() >= aMaxNumBitmaps)
    90 			{
    91 			TInt i = Math::Rand(seed) % aMaxNumBitmaps;
    92 			delete iTestBitmaps[i];
    93 			iTestBitmaps.Remove(i);
    94 			}
    95 		iProfiler->MarkResultSetL();
    96 		}
    97 	iTestBitmaps.ResetAndDestroy();
    98 	}
    99 
   100 /**
   101 Creates and destroys bitmaps of the same size KIterationsToTest times.
   102 
   103 @param aWidth The width of the created bitmaps.
   104 @param aHeight  The height of the created bitmaps.
   105 @param aDisplayMode The display mode to create bitmaps with.
   106 @param aTestDescription The description of the test.
   107 */
   108 void CTFbsBitmapHandlePerf::BitmapCreationSimpleL(const TInt aWidth, const TInt aHeight, const TDisplayMode aDisplayMode, const TDesC& aTestDescription)
   109 	{
   110 	iProfiler->InitResults();
   111 	for (TInt count = KIterationsToTest; count > 0; --count)
   112 		{
   113 		CFbsBitmap bitmap;
   114 		TInt err = bitmap.Create(TSize(aWidth, aHeight), aDisplayMode);
   115 		User::LeaveIfError(err);
   116 		iProfiler->MarkResultSetL();
   117 		}
   118 	iProfiler->ResultsAnalysis(aTestDescription, aDisplayMode, 0, 0, KIterationsToTest);
   119 	}
   120 
   121 /**
   122 @SYMTestCaseID
   123 GRAPHICS-UI-BENCH-0074
   124 
   125 @SYMTestCaseDesc
   126 The test determines how long it takes to create and destroy small bitmap objects.
   127 
   128 @SYMTestActions
   129 Compare the results over time, and before and after changes to bitmap construction and destruction code.
   130 
   131 @SYMTestExpectedResults
   132 Test should pass and display total test time and time per bitmap
   133 
   134 @param aDisplayMode The display mode to create bitmaps with.
   135 @param aTestDescription The description of the test.
   136 */
   137 void CTFbsBitmapHandlePerf::SmallBitmapCreationL(const TDisplayMode aDisplayMode, const TDesC& aTestDescription)
   138 	{
   139 	// width X height X bytes per pixel < KMaxLargeBitmapAlloc (16KB as of writing)
   140 	const TSize KSmallSizes[KNumTestBitmapSizes] =
   141 		{
   142 		TSize(20, 20), // 1st
   143 		TSize(22, 22), // 2nd
   144 		TSize(24, 24), // 3rd
   145 		TSize(28, 28), // 4th
   146 		TSize(32, 32), // 5th
   147 		TSize(40, 40), // 6th
   148 		TSize(48, 48), // 7th
   149 		TSize(60, 60)  // 8th
   150 		};
   151 	BitmapCreationL(KSmallSizes, KMaxNumSmallTestBitmaps, aDisplayMode);
   152 	iProfiler->ResultsAnalysis(aTestDescription, aDisplayMode, 0, 0, KIterationsToTest);
   153 	}
   154 
   155 /**
   156 @SYMTestCaseID
   157 GRAPHICS-UI-BENCH-0006
   158 
   159 @SYMTestCaseDesc
   160 The test determines how long it takes to create and destroy large bitmap objects.
   161 
   162 @SYMTestActions
   163 Compare the results over time, and before and after changes to bitmap construction and destruction code.
   164 
   165 @SYMTestExpectedResults
   166 Test should pass and display total test time and time per bitmap
   167 
   168 @param aDisplayMode The display mode to create bitmaps with.
   169 @param aTestDescription The description of the test.
   170 */
   171 void CTFbsBitmapHandlePerf::LargeBitmapCreationL(const TDisplayMode aDisplayMode, const TDesC& aTestDescription)
   172 	{
   173 	// width X height X bytes per pixel > KMaxLargeBitmapAlloc (16KB as of writing)
   174 	const TSize KLargeSizes[KNumTestBitmapSizes] =
   175 		{
   176 		TSize(200, 200), // 1st
   177 		TSize(220, 220), // 2nd
   178 		TSize(240, 240), // 3rd
   179 		TSize(280, 280), // 4th
   180 		TSize(320, 320), // 5th
   181 		TSize(400, 400), // 6th
   182 		TSize(480, 480), // 7th
   183 		TSize(600, 600)  // 8th
   184 		};
   185 	BitmapCreationL(KLargeSizes, KMaxNumLargeTestBitmaps, aDisplayMode);
   186 	iProfiler->ResultsAnalysis(aTestDescription, aDisplayMode, 0, 0, KIterationsToTest);
   187 	}
   188 
   189 /**
   190 @SYMTestCaseID
   191 GRAPHICS-UI-BENCH-0007
   192 
   193 @SYMTestCaseDesc
   194 Tests how long it takes to duplicate a bitmap
   195 
   196 @SYMTestActions
   197 Compare the results over time, and before and after changes to bitmap duplication code.
   198 
   199 @SYMTestExpectedResults
   200 Test should pass and display total test time and time per bitmap
   201 */
   202 void CTFbsBitmapHandlePerf::BitmapDuplicateL()
   203 	{
   204 	
   205 	TSize size(200,200);
   206 	TInt err;
   207 	
   208 	RArray<TInt> handles;
   209 	RPointerArray<CFbsBitmap> bitmapArray;
   210 	CleanupClosePushL(bitmapArray);
   211 	
   212 	// Create bitmaps for each display mode and store in array
   213 	for(TInt count=KNumValidBitmapModes-1; count>=0; --count)
   214 		{
   215 		CFbsBitmap* bitmap=new(ELeave) CFbsBitmap;
   216 		CleanupStack::PushL(bitmap);
   217 		TDisplayMode mode = KValidBitmapModes[count];
   218 		err = bitmap->Create(size, mode);
   219 		User::LeaveIfError(err);
   220 		User::LeaveIfError(bitmapArray.Append(bitmap));
   221 		CleanupStack::Pop(bitmap);
   222 		User::LeaveIfError(handles.Append(bitmap->Handle()));		
   223 		}
   224 	
   225 	// Duplicate each bitmap in the array and measure performance
   226 	iProfiler->InitResults();
   227 	for(TInt count=KIterationsToTest; count>=0; --count)
   228 		{
   229 		CFbsBitmap* duplicateBitmap=new (ELeave) CFbsBitmap;
   230 		CleanupStack::PushL(duplicateBitmap);
   231 		TInt hn=count%KNumValidBitmapModes;
   232 		TInt handle=handles[hn];
   233 		err=duplicateBitmap->Duplicate(handle);
   234 		User::LeaveIfError(err);
   235 		CleanupStack::PopAndDestroy(duplicateBitmap);
   236 		iProfiler->MarkResultSetL();
   237 		}	
   238 	iProfiler->ResultsAnalysis(_L("Bitmap-Duplicate"), 0, 0, 0, KIterationsToTest);	
   239 	
   240 	handles.Reset();
   241 	
   242 	bitmapArray.ResetAndDestroy();	
   243 	CleanupStack::PopAndDestroy(&bitmapArray);
   244 	}
   245 
   246 /**
   247 @SYMTestCaseID
   248 GRAPHICS-UI-BENCH-0087
   249 
   250 @SYMTestCaseDesc
   251 The test determines how long it takes to create and destroy small simple bitmap objects.
   252 
   253 @SYMTestActions
   254 Compare the results over time, and before and after changes to bitmap construction and destruction code.
   255 
   256 @SYMTestExpectedResults
   257 Test should pass and display total test time and time per bitmap
   258 
   259 @param aDisplayMode The display mode to create bitmaps with.
   260 @param aTestDescription The description of the test.
   261 */
   262 void CTFbsBitmapHandlePerf::SmallBitmapCreationSimpleL()
   263 	{
   264 	BitmapCreationSimpleL(32, 32, KTestDisplayMode2, _L("Small Bitmap-Create-64K-Simple"));
   265 	}
   266 	
   267 /**
   268 @SYMTestCaseID
   269 GRAPHICS-UI-BENCH-0088
   270 
   271 @SYMTestCaseDesc
   272 The test determines how long it takes to create and destroy large simple bitmap objects.
   273 
   274 @SYMTestActions
   275 Compare the results over time, and before and after changes to bitmap construction and destruction code.
   276 
   277 @SYMTestExpectedResults
   278 Test should pass and display total test time and time per bitmap
   279 
   280 @param aDisplayMode The display mode to create bitmaps with.
   281 @param aTestDescription The description of the test.
   282 */
   283 void CTFbsBitmapHandlePerf::LargeBitmapCreationSimpleL()
   284 	{
   285 	BitmapCreationSimpleL(500, 500, KTestDisplayMode2, _L("Large Bitmap-Create-64K-Simple"));
   286 	}