os/graphics/graphicstest/uibench/src/textendedbitmap.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2008-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 #include "textendedbitmap.h"
    17 #include "tdirectgditestbase.h"
    18 #include <gdi.h>
    19 #include <s32mem.h>
    20 #include <e32base.h>
    21 #include <e32uid.h>
    22 
    23 
    24 const TInt KIterationsToTest = 1000;
    25 const TDisplayMode KDisplayMode = EColor64K;
    26 // Test the performance of extended bitmaps using the extended bitmap
    27 // Uid supported by the test example rasterizer
    28 const TUid KExtendedBitmapUid = {0x10285A78};
    29 
    30 
    31 CTExtendedBitmap::CTExtendedBitmap()
    32 	{
    33 	SetTestStepName(KTExtendedBitmap);
    34 	}
    35 
    36 CTExtendedBitmap::~CTExtendedBitmap()
    37 	{		
    38 	delete iExtendedBmp;
    39 	delete [] iExtendedBmpData;
    40 	delete iNormalBmp;
    41 	delete iTargetBmp;
    42 	delete iBitmapDevice;
    43 	delete iBitGc;		
    44 	}
    45 
    46 /**
    47 Override of base class pure virtual
    48 Our implementation only gets called if the base class doTestStepPreambleL() did
    49 not leave. That being the case, the current test result value will be EPass.
    50 
    51 @return - TVerdict code
    52 */
    53 TVerdict CTExtendedBitmap::doTestStepL()
    54 	{
    55 	SetTestStepID(_L("GRAPHICS-UI-BENCH-0159"));
    56 	CreateExtendedBitmapL();	
    57 	RecordTestResultL();
    58 	SetTestStepID(_L("GRAPHICS-UI-BENCH-0160"));
    59 	DeleteExtendedBitmapL();
    60 	RecordTestResultL();
    61 	SetTestStepID(_L("GRAPHICS-UI-BENCH-0161"));
    62 	GetScanlinePreRenderedExtendedBitmapL();
    63 	RecordTestResultL();
    64 	SetTestStepID(_L("GRAPHICS-UI-BENCH-0162"));
    65 	GetScanlineNonPreRenderedExtendedBitmapL();
    66 	RecordTestResultL();
    67 	SetTestStepID(_L("GRAPHICS-UI-BENCH-0163"));
    68 	BitBltExtendedBitmapL();
    69 	RecordTestResultL();
    70 	SetTestStepID(_L("GRAPHICS-UI-BENCH-0164"));
    71 	BitBltNormalBitmapL();
    72 	RecordTestResultL();
    73 	SetTestStepID(_L("GRAPHICS-UI-BENCH-0165"));
    74 	DrawBitmapExtendedBitmapL();
    75 	RecordTestResultL();
    76 	SetTestStepID(_L("GRAPHICS-UI-BENCH-0166"));
    77 	DrawBitmapNormalBitmapL();
    78 	RecordTestResultL();
    79 	SetTestStepID(_L("GRAPHICS-UI-BENCH-0173"));
    80 	GetPixelL(ETrue);	// extended bitmap
    81 	RecordTestResultL();
    82 	SetTestStepID(_L("GRAPHICS-UI-BENCH-0173"));
    83 	GetPixelL(EFalse);	// normal bitmap
    84 	RecordTestResultL();
    85 		
    86 	return TestStepResult();
    87 	}
    88 
    89 /**
    90 Called before doTestStepL() to allow
    91 initialization steps common to each test case to take place.
    92 
    93 @return - TVerdict code
    94 */
    95 TVerdict CTExtendedBitmap::doTestStepPreambleL()
    96 	{
    97 	TVerdict res = CTe_graphicsperformanceSuiteStepBase::doTestStepPreambleL();
    98 	
    99 	const TRgb colors[] = {TRgb(0,255,255), TRgb(255,0,255), TRgb(255,255,0)};
   100 	const TInt numColors = sizeof(colors)/sizeof(colors[0]);
   101 	const TUint8 stripe = 1; // 1 mean draw horizontal stripes, 0 means draw vertical stripes
   102 	iExtendedBmpDataSize = sizeof(colors)+sizeof(stripe); // estimate the data size
   103 	iExtendedBmpData = new(ELeave) TUint8[iExtendedBmpDataSize];
   104 	RMemWriteStream ws;
   105 	ws.Open(iExtendedBmpData, iExtendedBmpDataSize);
   106 	CleanupClosePushL(ws);
   107 	for (TInt i = 0; i < numColors; i++)
   108 		{
   109 		ws << colors[i];
   110 		}
   111 	ws << stripe;
   112 	iExtendedBmpDataSize = ws.Sink()->TellL(MStreamBuf::EWrite).Offset(); // get the actual size written
   113 	CleanupStack::PopAndDestroy(&ws);
   114 	
   115 	iExtendedBmp = new(ELeave) CFbsBitmap;	
   116 	TInt err = iExtendedBmp->CreateExtendedBitmap(KBitmapSize, KDisplayMode, KExtendedBitmapUid, iExtendedBmpData, iExtendedBmpDataSize);
   117 	TESTL(err == KErrNone);
   118 	
   119 	iNormalBmp = new(ELeave) CFbsBitmap;
   120 	err = iNormalBmp->Create(KBitmapSize, KDisplayMode);
   121 	TESTL(err == KErrNone);
   122 	
   123 	iTargetBmp = new(ELeave) CFbsBitmap;
   124 	err = iTargetBmp->Create(KBitmapSize, KDisplayMode);
   125 	TESTL(err == KErrNone);
   126 	
   127 	iBitmapDevice = CFbsBitmapDevice::NewL(iTargetBmp);
   128 	TESTL(iBitmapDevice != NULL);
   129 	
   130 	iBitGc = CFbsBitGc::NewL();
   131 	iBitGc->Activate(iBitmapDevice);	
   132 		
   133 	iRasterizer = CFbsBitmap::Rasterizer();
   134 	if (iRasterizer == NULL)
   135 		{
   136 		INFO_PRINTF1(_L("Error: Extended bitmap tests only work when the example rasterizer is available, make sure \"-DFBSRASTERIZER_DLL=fbsrasterizer_test.dll\" is included in your rombuild command."));
   137 		User::Leave(KErrGeneral);
   138 		}
   139 	
   140 	return res;
   141 	}
   142 
   143 /**
   144 @SYMTestCaseID
   145 GRAPHICS-UI-BENCH-0159
   146 
   147 @SYMPREQ 
   148 PREQ2096
   149 
   150 @SYMREQ
   151 REQ10847
   152 REQ10849
   153 
   154 @SYMTestCaseDesc
   155 The test determines how long it takes to create an extended bitmap.
   156 
   157 @SYMTestActions
   158 Measure the average time taken to create an extended bitmap by creating an
   159 extended bitmap 1000 times and then calculating the average time.
   160 
   161 @SYMTestExpectedResults
   162 Test should pass and display total test time and time per extended bitmap creation.
   163 */
   164 void CTExtendedBitmap::CreateExtendedBitmapL()
   165 	{		
   166 	CFbsBitmap* bmp = new(ELeave) CFbsBitmap;
   167 	TESTL(bmp != NULL);
   168 	CleanupStack::PushL(bmp);
   169 	
   170 	iProfiler->InitResults();	
   171 	for(TInt count=KIterationsToTest; count>0; --count)
   172 		{		
   173 		iProfiler->StartTimer();		
   174 		TInt err = bmp->CreateExtendedBitmap(KBitmapSize, EColor64K, KExtendedBitmapUid, iExtendedBmpData, iExtendedBmpDataSize);						
   175 		iProfiler->MarkResultSetL();
   176 		TESTL(err == KErrNone);
   177 		
   178 		// Reset the bitmap so the time taken to reset it the next time CreateExtendedBitmap()
   179 		// is called is not included in the test
   180 		bmp->Reset();
   181 		
   182 		}	
   183 	iProfiler->ResultsAnalysis(_L("Create-ExtendedBitmap-64K"), 0, EColor64K, EColor64K, KIterationsToTest);
   184 	
   185 	CleanupStack::PopAndDestroy(bmp);
   186 	}
   187 
   188 /**
   189 @SYMTestCaseID
   190 GRAPHICS-UI-BENCH-0160
   191 
   192 @SYMPREQ 
   193 PREQ2096
   194 
   195 @SYMREQ
   196 REQ10847
   197 REQ10849
   198 
   199 @SYMTestCaseDesc
   200 The test determines how long it takes to delete an extended bitmap.
   201 
   202 @SYMTestActions
   203 Measure the average time taken to delete an extended bitmap by creating and
   204 deleting an extended bitmap 1000 times and then calculating the average time for the deletion.
   205 
   206 @SYMTestExpectedResults
   207 Test should pass and display total test time and time per extended bitmap deletion.
   208 */
   209 void CTExtendedBitmap::DeleteExtendedBitmapL()
   210 	{		
   211 	CFbsBitmap* bmp = new(ELeave) CFbsBitmap;
   212 	TESTL(bmp != NULL);
   213 	CleanupStack::PushL(bmp);
   214 	
   215 	iProfiler->InitResults();	
   216 	for(TInt count=KIterationsToTest; count>0; --count)
   217 		{						
   218 		TInt err = bmp->CreateExtendedBitmap(KBitmapSize, EColor64K, KExtendedBitmapUid, iExtendedBmpData, iExtendedBmpDataSize);
   219 		TESTL(err == KErrNone);		
   220 		CleanupStack::Pop(bmp);
   221 		
   222 		iProfiler->StartTimer();
   223 		delete bmp;
   224 		iProfiler->MarkResultSetL();
   225 		
   226 		bmp = new(ELeave) CFbsBitmap;		
   227 		TESTL(bmp != NULL);
   228 		CleanupStack::PushL(bmp);
   229 		}	
   230 	iProfiler->ResultsAnalysis(_L("Delete-ExtendedBitmap-64K"), 0, EColor64K, EColor64K, KIterationsToTest);
   231 	
   232 	CleanupStack::PopAndDestroy(bmp);
   233 	}
   234 
   235 /**
   236 @SYMTestCaseID
   237 GRAPHICS-UI-BENCH-0161
   238 
   239 @SYMPREQ 
   240 PREQ2096
   241 
   242 @SYMREQ 
   243 REQ10847 
   244 REQ10860
   245 
   246 @SYMTestCaseDesc
   247 Measure the average time taken to get a scanline from an extended bitmap directly using
   248 the example rasterizer where there is one call to BeginBitmap() and EndBitmap() for 
   249 many GetScanLine() calls. This test only measures the performance of the example rasterizer. 
   250 It is included here to help isolate performance changes in CTExtendedBitmap::BitBltExtendedBitmapL() 
   251 and CTExtendedBitmap::DrawBitmapExtendedBitmapL().
   252 
   253 @SYMTestActions
   254 Measure the average time taken to get a scanline from an extended bitmap directly using
   255 the example rasterizer by calling CFbsRasterizer::ScanLine() 1000 times for an extended
   256 bitmap.
   257 
   258 @SYMTestExpectedResults
   259 Test should pass and display total test time and time per scanline.
   260 
   261 @see GetScanlineNonPreRenderedExtendedBitmapL()
   262 */
   263 void CTExtendedBitmap::GetScanlinePreRenderedExtendedBitmapL()
   264 	{			
   265 	CFbsRasterizer::TBitmapDesc bitmapDesc;
   266 	TInt64 bitmapId = iExtendedBmp->SerialNumber();
   267 	bitmapDesc.iSizeInPixels = KBitmapSize;
   268 	bitmapDesc.iDispMode = KDisplayMode;
   269 	bitmapDesc.iDataType = KExtendedBitmapUid;
   270 	bitmapDesc.iData = iExtendedBmpData;
   271 	bitmapDesc.iDataSize = iExtendedBmpDataSize;	
   272 	iRasterizer->BeginBitmap(bitmapId, bitmapDesc, NULL);
   273 		
   274 	TInt h;
   275 	const TUint32* scanline;
   276 	TPoint point(0,0);
   277 	
   278 	iProfiler->InitResults();
   279 	for(TInt count=KIterationsToTest; count>0; --count)
   280 		{								
   281 		for (h = 0; h < KBitmapSize.iHeight; h++)
   282 			{
   283 			point.iY = h;
   284 			scanline = iRasterizer->ScanLine(bitmapId, point, KBitmapSize.iWidth);
   285 			TESTL(scanline != NULL);
   286 			}
   287 		iProfiler->MarkResultSetL();
   288 		}	
   289 	iProfiler->ResultsAnalysis(_L("GetScanline-PreRendered-64K"), 0, EColor64K, EColor64K, KIterationsToTest);
   290 	
   291 	iRasterizer->EndBitmap(bitmapId);
   292 	}
   293 
   294 /**
   295 @SYMTestCaseID
   296 GRAPHICS-UI-BENCH-0162
   297 
   298 @SYMPREQ PREQ2096
   299 
   300 @SYMREQ 
   301 REQ10847 
   302 REQ10860
   303 
   304 @SYMTestCaseDesc
   305 Measure the average time taken to get a scanline from an extended bitmap directly using
   306 the example rasterizer where the calls to BeginBitmap() and EndBitmap() are done for each 
   307 GetScanLine().
   308 
   309 @SYMTestActions
   310 Call CFbsRasterizer::ScanLine() 1000 times for an extended bitmap. This test case is similar 
   311 to GetScanlinePreRenderedExtendedBitmapL() but in this case each CFbsRasterizer::ScanLine() 
   312 call is bracketed by CFbsRasterizer::BeginBitmap() and CFbsRasterizer::EndBitmap() to highlight 
   313 the performance hit that would be seen by an application calling CFbsBitmap::GetScanLine() 
   314 when using an extended bitmap rasterizer that does not have a cache. 
   315 
   316 @SYMTestExpectedResults
   317 Test should pass and display total test time and time per scanline when bracketed by 
   318 CFbsRasterizer::BeginBitmap() and CFbsRasterizer::EndBitmap().
   319 
   320 @see GetScanlinePreRenderedExtendedBitmapL()
   321 */
   322 void CTExtendedBitmap::GetScanlineNonPreRenderedExtendedBitmapL()
   323 	{				
   324 	CFbsRasterizer::TBitmapDesc bitmapDesc;
   325 	TInt64 bitmapId = iExtendedBmp->SerialNumber();
   326 	bitmapDesc.iSizeInPixels = KBitmapSize;
   327 	bitmapDesc.iDispMode = KDisplayMode;
   328 	bitmapDesc.iDataType = KExtendedBitmapUid;
   329 	bitmapDesc.iData = iExtendedBmpData;
   330 	bitmapDesc.iDataSize = iExtendedBmpDataSize;		
   331 		
   332 	TInt h;
   333 	const TUint32* scanline;
   334 	TPoint point(0,0);
   335 	
   336 	iProfiler->InitResults();
   337 	for(TInt count=KIterationsToTest; count>0; --count)
   338 		{
   339 		for (h = 0; h < KBitmapSize.iHeight; h++)
   340 			{
   341 			// Only the first call to BeginBitmap() should cause rasterization of the bitmap,
   342 			// since the test rasterizer has a cache of recently used bitmaps.
   343 			iRasterizer->BeginBitmap(bitmapId, bitmapDesc, NULL);
   344 			point.iY = h;
   345 			scanline = iRasterizer->ScanLine(bitmapId, point, KBitmapSize.iWidth);
   346 			TESTL(scanline != NULL);
   347 			iRasterizer->EndBitmap(bitmapId);
   348 			}
   349 		iProfiler->MarkResultSetL();
   350 		}
   351 	iProfiler->ResultsAnalysis(_L("GetScanline-NonPreRendered-64K"), 0, EColor64K, EColor64K, KIterationsToTest);
   352 	}
   353 
   354 /**
   355 @SYMTestCaseID
   356 GRAPHICS-UI-BENCH-0163
   357 
   358 @SYMPREQ 
   359 PREQ2096
   360 
   361 @SYMREQ
   362 REQ10857
   363 REQ10859
   364 
   365 @SYMTestCaseDesc
   366 The test determines how long it takes to BitBlt() an extended bitmap to an offscreen bitmap.
   367 This test is paired with BitBltNormalBitmapL().
   368 
   369 @SYMTestActions
   370 Measure the time taken to BitBlt() an extended bitmap to an offscreen buffer 1000 times
   371 and calculate the average time taken. 
   372 
   373 @SYMTestExpectedResults
   374 Test should pass and display total test time and time per image BitBlt().
   375 
   376 @see BitBltNormalBitmapL()
   377 */
   378 void CTExtendedBitmap::BitBltExtendedBitmapL()
   379 	{			
   380 	const TPoint pt(0,0);
   381 	
   382 	iProfiler->InitResults();	
   383 	for(TInt count=KIterationsToTest; count>0; --count)
   384 		{
   385 		iBitGc->BitBlt(pt, iExtendedBmp);
   386 		iProfiler->MarkResultSetL();
   387 		}	
   388 	iProfiler->ResultsAnalysis(_L("BitBlt-ExtendedBitmap-64K"), 0, EColor64K, EColor64K, KIterationsToTest);
   389 	}
   390 
   391 /**
   392 @SYMTestCaseID
   393 GRAPHICS-UI-BENCH-0164
   394 
   395 @SYMPREQ PREQ2096
   396 
   397 @SYMTestCaseDesc
   398 The test determines how long it takes to BitBlt() a standard bitmap that is the same size
   399 as the extended bitmap used in the previous test case BitBltExtendedBitmapL().
   400 This test is paired with BitBltExtendedBitmapL().
   401 
   402 @SYMTestActions
   403 Measure the time taken to BitBlt() a normal bitmap to an offscreen buffer 1000 times
   404 and calculate the average time taken.
   405 
   406 @SYMTestExpectedResults
   407 Test should pass and display total test time and time per image BitBlt().
   408 
   409 @see BitBltExtendedBitmapL()
   410 */
   411 void CTExtendedBitmap::BitBltNormalBitmapL()
   412 	{		
   413 	const TPoint pt(0,0);
   414 	
   415 	iProfiler->InitResults();	
   416 	for(TInt count=KIterationsToTest; count>0; --count)
   417 		{
   418 		iBitGc->BitBlt(pt, iNormalBmp);
   419 		iProfiler->MarkResultSetL();
   420 		}	
   421 	iProfiler->ResultsAnalysis(_L("BitBlt-NormalBitmap-64K"), 0, EColor64K, EColor64K, KIterationsToTest);
   422 	}
   423 
   424 /**
   425 @SYMTestCaseID
   426 GRAPHICS-UI-BENCH-0165
   427 
   428 @SYMPREQ 
   429 PREQ2096
   430 
   431 @SYMREQ
   432 REQ10857
   433 REQ10859
   434 
   435 @SYMTestCaseDesc
   436 The test determines how long it takes to draw an extended bitmap to an offscreen bitmap
   437 using DrawBitmap(). This test is paired with DrawBitmapNormalBitmapL().
   438 
   439 @SYMTestActions
   440 Measure the time taken to DrawBitmap() an extended bitmap to an offscreen buffer 1000 times
   441 and calculate the average time taken. This test is paired with DrawBitmapNormalBitmapL().
   442 
   443 @SYMTestExpectedResults
   444 Test should pass and display total test time and time per image DrawBitmap().
   445 
   446 @see DrawBitmapNormalBitmapL()
   447 */
   448 void CTExtendedBitmap::DrawBitmapExtendedBitmapL()
   449 	{			
   450 	const TPoint pt(0,0);
   451 	const TRect rect(pt, KBitmapSize);
   452 	
   453 	iProfiler->InitResults();	
   454 	for(TInt count=KIterationsToTest; count>0; --count)
   455 		{
   456 		iBitGc->DrawBitmap(rect, iExtendedBmp, rect);
   457 		iProfiler->MarkResultSetL();
   458 		}	
   459 	iProfiler->ResultsAnalysis(_L("DrawBitmap-ExtendedBitmap-64K"), 0, EColor64K, EColor64K, KIterationsToTest);
   460 	}
   461 
   462 /**
   463 @SYMTestCaseID
   464 GRAPHICS-UI-BENCH-0166
   465 
   466 @SYMPREQ PREQ2096
   467 
   468 @SYMTestCaseDesc
   469 The test determines how long it takes to draw a standard bitmap that is the same size
   470 as the extended bitmap used in the previous test case (DrawBitmapExtendedBitmapL()) 
   471 using DrawBitmap(). This test is paired with DrawBitmapExtendedBitmapL().
   472 This test is paired with DrawBitmapExtendedBitmapL().
   473 
   474 @SYMTestActions
   475 Measure the time taken to DrawBitmap() a normal bitmap to an offscreen buffer 1000 times
   476 and calculate the average time taken.
   477 
   478 @SYMTestExpectedResults
   479 Test should pass and display total test time and time per image DrawBitmap().
   480 
   481 @see DrawBitmapExtendedBitmapL()
   482 */
   483 void CTExtendedBitmap::DrawBitmapNormalBitmapL()
   484 	{		
   485 	const TPoint pt(0,0);
   486 	const TRect rect(pt, KBitmapSize);
   487 	
   488 	iProfiler->InitResults();	
   489 	for(TInt count=KIterationsToTest; count>0; --count)
   490 		{
   491 		iBitGc->DrawBitmap(rect, iNormalBmp, rect);
   492 		iProfiler->MarkResultSetL();
   493 		}	
   494 	iProfiler->ResultsAnalysis(_L("DrawBitmap-NormalBitmap-64K"), 0, EColor64K, EColor64K, KIterationsToTest);
   495 	}
   496 
   497 /**
   498 @SYMTestCaseID
   499 GRAPHICS-UI-BENCH-0173
   500 
   501 @SYMCR
   502 CR1804
   503 
   504 @SYMREQ 
   505 REQ10858
   506 
   507 @SYMTestCaseDesc
   508 Measure the average time taken to get 128 pixels from a normal or extended bitmap.
   509 
   510 @SYMTestActions
   511 Measure the average time taken to get 128 pixels from a normal or extended bitmap 
   512 by calling CFbsBitmap::GetPixel() 1000 times on the bitmap.
   513 
   514 @SYMTestExpectedResults
   515 Test should pass and display total test time and time per 128 pixels.
   516 */
   517 void CTExtendedBitmap::GetPixelL(TBool aIsExtendedBmp)
   518 	{
   519 	CFbsBitmap* bmp = NULL;
   520 	_LIT(KTestName, "GetPixel-%S-64K");
   521 	TBuf<30> buf;
   522 
   523 	if (aIsExtendedBmp)
   524 		{
   525 		_LIT(KExtBmpName, "ExtendedBitmap");
   526 		buf.Format(KTestName, &KExtBmpName);
   527 		bmp= iExtendedBmp;
   528 		}
   529 	else
   530 		{
   531 		_LIT(KNormalBmpName, "NormalBitmap");
   532 		buf.Format(KTestName, &KNormalBmpName);
   533 		bmp = iNormalBmp;
   534 		}
   535 
   536 	TInt y;
   537 	TPoint point(0,0);
   538 	TRgb color;
   539 	iProfiler->InitResults();
   540 	for(TInt count=KIterationsToTest; count>0; --count)
   541 		{								
   542 		for (y = 0; y < KBitmapSize.iHeight; ++y)
   543 			{
   544 			point.iY = y;
   545 			bmp->GetPixel(color, point);
   546 			}
   547 		iProfiler->MarkResultSetL();
   548 		}
   549 	iProfiler->ResultsAnalysis(buf, 0, KDisplayMode, KDisplayMode, KIterationsToTest);
   550 	}