os/graphics/graphicstest/uibench/src/tbitbltperf.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 "tbitbltperf.h"
    23 #include <bitdrawinterfaceid.h>
    24 #include <bmalphablend.h>
    25 #include <bitdraw.h>
    26 
    27 _LIT(KBitmap12bit, "z:\\system\\data\\uibench_12bit.mbm");
    28 _LIT(KBitmap16bit, "z:\\system\\data\\uibench_16bit.mbm");
    29 _LIT(KBitmap24bit, "z:\\system\\data\\uibench_24bit.mbm");
    30 _LIT(KBitmap32bit, "z:\\system\\data\\uibench_32bit.mbm");
    31 _LIT(KBitmapTile, "z:\\system\\data\\uibench_tile.mbm");
    32 
    33 const TInt KIterationsToTest = 51; 		// Number of iterations to run tests
    34 
    35 CTBitBltPerf::~CTBitBltPerf()
    36 	{
    37 	delete iBitmap12bit;
    38 	delete iBitmap16bit;
    39 	delete iBitmap24bit;
    40 	delete iBitmap32bit;
    41 	delete iTile;
    42 	delete iTile16bit;
    43 	delete iTile32bit;				
    44 	delete iAlpha8bit;
    45 	}
    46 
    47 CTBitBltPerf::CTBitBltPerf()
    48 	{
    49 	SetTestStepName(KTBitBltPerfName);
    50 	}
    51 
    52 /**
    53 Override of base class virtual
    54 
    55 @return - TVerdict code
    56 */
    57 TVerdict CTBitBltPerf::doTestStepPreambleL()
    58 	{	
    59 	CTe_graphicsperformanceSuiteStepBase::doTestStepPreambleL();
    60 
    61 	iBitmap12bit = LoadBitmapL(KBitmap12bit, 0);
    62 	iBitmap16bit = LoadBitmapL(KBitmap16bit, 0);
    63 	iBitmap24bit = LoadBitmapL(KBitmap24bit, 0);
    64 	iBitmap32bit = LoadBitmapL(KBitmap32bit, 0);
    65 	iTile = LoadBitmapL(KBitmapTile, 0);
    66 	
    67 	iTile16bit = CopyIntoNewBitmapL(iTile, EColor64K);
    68 	iTile32bit = CopyIntoNewBitmapL(iTile, EColor16M);
    69 	iAlpha8bit = CopyIntoNewBitmapL(iBitmap12bit, EGray256);
    70 		
    71 	return TestStepResult();
    72 	}
    73 
    74 /**
    75 Override of base class pure virtual
    76 Our implementation only gets called if the base class doTestStepPreambleL() did
    77 not leave. That being the case, the current test result value will be EPass.
    78 
    79 @return - TVerdict code
    80 */
    81 TVerdict CTBitBltPerf::doTestStepL()
    82 	{
    83 	SetTestStepID(_L("GRAPHICS-UI-BENCH-0005"));
    84 	MaskedBitBltAlphaL();
    85 	RecordTestResultL();
    86 	SetTestStepID(_L("GRAPHICS-UI-BENCH-0004"));
    87 	MaskedBitBltFlickerL();
    88 	RecordTestResultL();
    89 	SetTestStepID(_L("GRAPHICS-UI-BENCH-0003"));
    90 	MaskedBitBltSameL();
    91 	RecordTestResultL();
    92 	SetTestStepID(_L("GRAPHICS-UI-BENCH-0001"));
    93 	SimpleBitBltL();
    94 	RecordTestResultL();
    95 	SetTestStepID(_L("GRAPHICS-UI-BENCH-0002"));
    96 	MaskedBitBltL();
    97 	RecordTestResultL();
    98 	SetTestStepID(_L("GRAPHICS-UI-BENCH-0056"));
    99 	WriteAlphaLineExTestL();
   100 	RecordTestResultL();
   101 
   102 	return TestStepResult();
   103 	}
   104 
   105 /**
   106 Helper function to test bitblt bitmaps for different types of blitting. The bitmap is tiled
   107 across the target, avoiding any overlapping or clipping. 
   108 
   109 @param aBitBltTest the bitblt test to carry out
   110 @param aBitmapToBlt the bitmap to bitblt
   111 @param aBitmapMask the bitmap mask
   112 @param aCrop rectangle to crop bitblt to
   113 @param aOrientation the orientation of the display
   114 @param aTestName the name of the test
   115 @param aGc the graphics context to bitblt to
   116 */
   117 void CTBitBltPerf::BitBltBitmapTestL(TBitBltTest aBitBltTest, CFbsBitmap* aBitmapToBlt, CFbsBitmap* aBitmapMask, TRect aCropTo, TInt aOrientation, const TDesC& aTestName, CFbsBitGc* aGc)
   118 	{
   119 	aGc->Clear();
   120 	
   121 	const TSize targetSize = iScreenDevice->BitmapDevice().SizeInPixels();	
   122 
   123 	// Calculate the number of tiles that will fit fully on the pixmap
   124 	const TInt tileWidth = aCropTo.Width();
   125 	const TInt tileHeight = aCropTo.Height();
   126 	const TInt tileColumns = targetSize.iWidth / tileWidth;
   127 	const TInt tileRows = targetSize.iHeight / tileHeight;
   128 	const TInt numTiles = tileColumns * tileRows;
   129 	const TInt numPixelsPerIteration = numTiles * tileWidth * tileHeight;
   130 
   131 	iProfiler->InitResults();
   132 			
   133 	switch (aBitBltTest)
   134 	{
   135 	case EBitBlt:
   136 		{
   137 		for(TInt count=KIterationsToTest; count>0; --count)
   138 			{
   139 			TPoint bitmapPosition = TPoint(0,0);
   140 			for (TInt tile = numTiles - 1; tile >= 0; --tile)
   141 				{
   142 				aGc->BitBlt(bitmapPosition, aBitmapToBlt, aCropTo);
   143 				bitmapPosition.iX += tileWidth;
   144 				if (bitmapPosition.iX + tileWidth > targetSize.iWidth)
   145 					{
   146 					bitmapPosition.iX = 0;
   147 					bitmapPosition.iY += tileHeight;
   148 					}
   149 				}
   150 			}
   151 		}
   152 		break;
   153 	case EBitBltMasked:
   154 		{
   155 		for(TInt count=KIterationsToTest; count>0; --count)
   156 			{
   157 			TPoint bitmapPosition = TPoint(0,0);
   158 			for (TInt tile = numTiles - 1; tile >= 0; --tile)
   159 				{
   160 				aGc->BitBltMasked(bitmapPosition, aBitmapToBlt, aCropTo, aBitmapMask, EFalse);
   161 				bitmapPosition.iX += tileWidth;
   162 				if (bitmapPosition.iX + tileWidth > targetSize.iWidth)
   163 					{
   164 					bitmapPosition.iX = 0;
   165 					bitmapPosition.iY += tileHeight;
   166 					}
   167 				}
   168 			}
   169 		}
   170 		break;
   171 	}
   172 
   173 	iProfiler->MarkResultSetL();
   174 	iProfiler->ResultsAnalysisPixelRate(aTestName, aOrientation, aBitmapToBlt->DisplayMode(), iScreenDevice->BitmapDevice().DisplayMode(), KIterationsToTest, numPixelsPerIteration);	
   175 	}
   176 
   177 
   178 /**
   179 @SYMTestCaseID
   180 GRAPHICS-UI-BENCH-0001
   181 
   182 @SYMTestCaseDesc
   183 Tests how long it takes to bitblt a bitmap with different screen modes
   184 
   185 @SYMTestActions
   186 Compare the results over time, and before and after changes to bitblt code.
   187 
   188 @SYMTestExpectedResults
   189 Test should pass and display total test time and time per bitmap
   190 */
   191 void CTBitBltPerf::SimpleBitBltL()
   192 	{
   193 	INFO_PRINTF1(_L("CTBitBltPerf::SimpleBitBlt"));
   194 	
   195 	_LIT(KTestName, "BitBlt");
   196 	TBool orientation[4];
   197 	TRect cropTo(0,0,200,200);
   198 	
   199 	// Bitblt for each display mode
   200 	for(TInt dispModeIndex = 0; dispModeIndex < KNumValidDisplayModes; dispModeIndex++)
   201 		{
   202 		SetScreenModeL(KValidDisplayModes[dispModeIndex]);			
   203 		iGc->OrientationsAvailable(orientation);
   204 		for (TInt orient = CFbsBitGc::EGraphicsOrientationNormal; orient <= CFbsBitGc::EGraphicsOrientationRotated270; orient++)
   205 			{
   206 			if (orientation[orient])
   207 				{
   208 				iGc->SetOrientation((CFbsBitGc::TGraphicsOrientation)orient);
   209 				
   210 				BitBltBitmapTestL(EBitBlt, iBitmap12bit, NULL, cropTo, orient, KTestName, iGc);
   211 				BitBltBitmapTestL(EBitBlt, iBitmap16bit, NULL, cropTo, orient, KTestName, iGc);
   212 				BitBltBitmapTestL(EBitBlt, iBitmap24bit, NULL, cropTo, orient, KTestName, iGc);
   213 				BitBltBitmapTestL(EBitBlt, iBitmap32bit, NULL, cropTo, orient, KTestName, iGc);
   214 				}
   215 			}		
   216 		}
   217 	iGc->SetOrientation(CFbsBitGc::EGraphicsOrientationNormal);
   218 	}
   219 
   220 /**
   221 @SYMTestCaseID
   222 GRAPHICS-UI-BENCH-0002
   223 
   224 @SYMTestCaseDesc
   225 Tests how long it takes to bitblt a masked bitmap with different screen modes
   226 
   227 @SYMTestActions
   228 Compare the results over time, and before and after changes to bitblt code.
   229 
   230 @SYMTestExpectedResults
   231 Test should pass and display total test time and time per bitmap
   232 */
   233 void CTBitBltPerf::MaskedBitBltL()
   234 	{
   235 	INFO_PRINTF1(_L("CTBitBltPerf::MaskedBitBlt"));
   236 	
   237 	_LIT(KTestName, "MBitBlt");
   238 	TBool orientation[4];
   239 	TRect cropTo(0,0,200,200);
   240 	
   241 	// test for each display mode
   242 	for(TInt dispModeIndex = 0; dispModeIndex < KNumValidDisplayModes; dispModeIndex++)
   243 		{
   244 		SetScreenModeL(KValidDisplayModes[dispModeIndex]);			
   245 		iGc->OrientationsAvailable(orientation);
   246 		for (TInt orient = CFbsBitGc::EGraphicsOrientationNormal; orient <= CFbsBitGc::EGraphicsOrientationRotated270; orient++)
   247 			{
   248 			if (orientation[orient])
   249 				{
   250 				iGc->SetOrientation((CFbsBitGc::TGraphicsOrientation)orient);
   251 				
   252 				BitBltBitmapTestL(EBitBltMasked, iBitmap12bit, iTile, cropTo, orient, KTestName, iGc);
   253 				BitBltBitmapTestL(EBitBltMasked, iBitmap16bit, iTile, cropTo, orient, KTestName, iGc);
   254 				BitBltBitmapTestL(EBitBltMasked, iBitmap24bit, iTile, cropTo, orient, KTestName, iGc);
   255 				BitBltBitmapTestL(EBitBltMasked, iBitmap32bit, iTile, cropTo, orient, KTestName, iGc);
   256 				}
   257 			}		
   258 		}
   259 	iGc->SetOrientation(CFbsBitGc::EGraphicsOrientationNormal);		
   260 	}
   261 
   262 /**
   263 @SYMTestCaseID
   264 GRAPHICS-UI-BENCH-0003
   265 
   266 @SYMTestCaseDesc
   267 Tests how long it takes to bitblt the same bitmap as a mask with different screen modes
   268 
   269 @SYMTestActions
   270 Compare the results over time, and before and after changes to bitblt code.
   271 
   272 @SYMTestExpectedResults
   273 Test should pass and display total test time and time per bitmap
   274 */	
   275 void CTBitBltPerf::MaskedBitBltSameL()
   276 	{
   277 	INFO_PRINTF1(_L("CTBitBltPerf::MaskedBitBltSame"));
   278 	
   279 	_LIT(KTestName, "MBitBltS");
   280 	TBool orientation[4];
   281 	TRect cropTo(0,0,200,200);
   282 	
   283 	// test for each display mode
   284 	for(TInt dispModeIndex = 0; dispModeIndex < KNumValidDisplayModes; dispModeIndex++)
   285 		{		
   286 		SetScreenModeL(KValidDisplayModes[dispModeIndex]);			
   287 		iGc->OrientationsAvailable(orientation);
   288 		for (TInt orient = CFbsBitGc::EGraphicsOrientationNormal; orient <= CFbsBitGc::EGraphicsOrientationRotated270; orient++)
   289 			{
   290 			if (orientation[orient])
   291 				{
   292 				iGc->SetOrientation((CFbsBitGc::TGraphicsOrientation)orient);
   293 				
   294 				BitBltBitmapTestL(EBitBltMasked, iTile, iTile, cropTo, orient, KTestName, iGc);
   295 				BitBltBitmapTestL(EBitBltMasked, iTile16bit, iTile16bit, cropTo, orient, KTestName, iGc);
   296 				BitBltBitmapTestL(EBitBltMasked, iTile32bit, iTile32bit, cropTo, orient, KTestName, iGc);					
   297 				}
   298 			}		
   299 		}
   300 	iGc->SetOrientation(CFbsBitGc::EGraphicsOrientationNormal);		
   301 	}
   302 
   303 /**
   304 @SYMTestCaseID
   305 GRAPHICS-UI-BENCH-0004
   306 
   307 @SYMTestCaseDesc
   308 Tests how long it takes to bitblt a masked bitmap to another bitmap
   309 
   310 @SYMTestActions
   311 Compare the results over time, and before and after changes to bitblt code.
   312 
   313 @SYMTestExpectedResults
   314 Test should pass and display total test time and time per bitmap
   315 */
   316 void CTBitBltPerf::MaskedBitBltFlickerL()
   317 	{
   318 	INFO_PRINTF1(_L("CTBitBltPerf::MaskedBitBltFlickerL"));
   319 	
   320 	_LIT(KTestName, "MBitBltF");
   321 	TBool orientation[4];
   322 	TRect cropTo(0,0,200,200);
   323 	
   324 	// Test for each display mode
   325 	for(TInt dispModeIndex = 0; dispModeIndex < KNumValidDisplayModes; dispModeIndex++)
   326 		{
   327 		SetScreenModeL(KValidDisplayModes[dispModeIndex]);
   328 		CFbsBitmap* flickerBitmap=new(ELeave) CFbsBitmap;
   329 		CleanupStack::PushL(flickerBitmap);
   330 		TInt ret=flickerBitmap->Create(iTile->SizeInPixels(), KValidDisplayModes[dispModeIndex]);
   331 		User::LeaveIfError(ret);
   332 		
   333 		iBitmapDevice = CFbsBitmapDevice::NewL(flickerBitmap);
   334 		CFbsBitGc* gc;
   335 		ret = iBitmapDevice->CreateContext(gc);
   336 		User::LeaveIfError(ret);
   337 		CleanupStack::PushL(gc);
   338 		
   339 		// Why is this gc not used? Should be used instead of iGc?
   340 		gc->OrientationsAvailable(orientation);
   341 		for (TInt orient = CFbsBitGc::EGraphicsOrientationNormal; orient <= CFbsBitGc::EGraphicsOrientationRotated270; orient++)
   342 			{
   343 			if (orientation[orient])
   344 				{
   345 				gc->SetOrientation((CFbsBitGc::TGraphicsOrientation)orient);
   346 
   347 				BitBltBitmapTestL(EBitBltMasked, iBitmap12bit, iTile, cropTo, orient, KTestName, gc);
   348 				BitBltBitmapTestL(EBitBltMasked, iBitmap16bit, iTile, cropTo, orient, KTestName, gc);
   349 				BitBltBitmapTestL(EBitBltMasked, iBitmap24bit, iTile, cropTo, orient, KTestName, gc);
   350 				BitBltBitmapTestL(EBitBltMasked, iBitmap32bit, iTile, cropTo, orient, KTestName, gc);		
   351 				}			
   352 			}
   353 		gc->SetOrientation(CFbsBitGc::EGraphicsOrientationNormal);
   354 		
   355 		delete iBitmapDevice;
   356 		iBitmapDevice = NULL;		
   357 		CleanupStack::PopAndDestroy(2, flickerBitmap);
   358 		}
   359 	}
   360 
   361 /**
   362 @SYMTestCaseID
   363 GRAPHICS-UI-BENCH-0005
   364 
   365 @SYMTestCaseDesc
   366 Tests how long it takes to bitblt a masked alpha bitmap with different screen modes
   367 
   368 @SYMTestActions
   369 Compare the results over time, and before and after changes to bitblt code.
   370 
   371 @SYMTestExpectedResults
   372 Test should pass and display total test time and time per bitmap
   373 */
   374 void CTBitBltPerf::MaskedBitBltAlphaL()
   375 	{
   376 	INFO_PRINTF1(_L("CTBitBltPerf::MaskedBitBltAlpha"));	
   377 	
   378 	_LIT(KTestName, "MBitBltA");
   379 	TBool orientation[4];
   380 	TRect cropTo(0,0,200,200);
   381 	
   382 	// test for each display mode
   383 	for(TInt dispModeIndex = 0; dispModeIndex < KNumValidDisplayModes; dispModeIndex++)
   384 		{
   385 		SetScreenModeL(KValidDisplayModes[dispModeIndex]);		
   386 		iGc->OrientationsAvailable(orientation);
   387 		for (TInt orient = CFbsBitGc::EGraphicsOrientationNormal; orient <= CFbsBitGc::EGraphicsOrientationRotated270; orient++)
   388 			{
   389 			if (orientation[orient])
   390 				{
   391 				iGc->SetOrientation((CFbsBitGc::TGraphicsOrientation)orient);
   392 		
   393 				BitBltBitmapTestL(EBitBltMasked, iBitmap12bit, iAlpha8bit, cropTo, orient, KTestName, iGc);
   394 				BitBltBitmapTestL(EBitBltMasked, iBitmap16bit, iAlpha8bit, cropTo, orient, KTestName, iGc);
   395 				BitBltBitmapTestL(EBitBltMasked, iBitmap24bit, iAlpha8bit, cropTo, orient, KTestName, iGc);
   396 				BitBltBitmapTestL(EBitBltMasked, iBitmap32bit, iAlpha8bit, cropTo, orient, KTestName, iGc);		
   397 				}
   398 			}		
   399 		}
   400 	iGc->SetOrientation(CFbsBitGc::EGraphicsOrientationNormal);
   401 	}
   402 
   403 /**
   404 @SYMTestCaseID
   405 GRAPHICS-UI-BENCH-0056
   406 
   407 @SYMDEF PDEF096994
   408 
   409 @SYMTestCaseDesc
   410 Tests the performace of CopyPixel and CopyTwoPixels called from WriteAlphaLineEx 
   411 
   412 @SYMTestActions
   413 Compare the results over time, and before and after changes to CopyPixel and CopyTwoPixels code.
   414 
   415 @SYMTestExpectedResults
   416 Test should pass and display total test time and average time
   417 */
   418 
   419 void CTBitBltPerf::WriteAlphaLineExTestL()
   420 	{
   421 	_LIT(KTestName, "WriteAlphaLineEx");
   422 
   423 	TDisplayMode displayMode = EColor16MU;
   424 	TDisplayMode sourceFormat = EColor64K;
   425 	TInt err;
   426 	FOREVER
   427 		{
   428 		TRAP(err,SetDrawDeviceModeL(displayMode));
   429 		if (err==KErrNone)
   430 			break;
   431 		_LIT(KLog,"Failed to create draw device of mode %S, error %d");
   432 		INFO_PRINTF3(KLog,&ColorModeName(displayMode),err);
   433 		if (displayMode==EColor16MA)
   434 			User::Leave(err);
   435 		displayMode=EColor16MA;
   436 		}
   437 	_LIT(KLog,"Created draw device of mode %S");
   438 	INFO_PRINTF2(KLog,&ColorModeName(displayMode));
   439 
   440 	TAny* interface = NULL;
   441 	err = GetDrawDeviceInterfaceL(KFastBlitInterfaceID, interface);
   442 	if (err!=KErrNone)
   443 		{
   444 		_LIT(KLog,"No WriteAlphaLineExTest performed as getting draw device interface returned error %d");
   445 		INFO_PRINTF2(KLog,err);
   446 		}
   447 	else
   448 		{
   449 		ClearDrawDeviceL(KRgbWhite);
   450 
   451 		TSize size = TSize(50,50);
   452 		TRect rect = TRect(size);
   453 		TUint16* writeBuffer = new (ELeave) TUint16[size.iWidth];
   454 		CleanupStack::PushL(writeBuffer);
   455 		TUint8* maskBuffer =  new (ELeave) TUint8[size.iWidth];
   456 		CleanupStack::PushL(maskBuffer);
   457 		TInt nOffset = sizeof(TUint16) * size.iWidth;
   458 
   459 		Mem::Fill(writeBuffer,nOffset,0xff);
   460 		Mem::Fill(maskBuffer,size.iWidth/2,0x8e);
   461 		Mem::Fill((maskBuffer+size.iWidth/2),size.iWidth/2,0xff);
   462 
   463 		MFastBlit* fastBlit = reinterpret_cast<MFastBlit*>(interface);
   464 
   465 		iProfiler->InitResults();
   466 		for(TInt count=0;count<KIterationsToTest;count++)
   467 			{
   468 			for (TInt yy = rect.iTl.iY; yy < rect.iBr.iY; yy++)
   469 				{
   470 				fastBlit->WriteAlphaLineEx(rect.iTl.iX,yy,rect.Width(),0,(TUint32*)writeBuffer,sourceFormat,0,(TUint32*)maskBuffer,MAlphaBlend::EShdwBefore);
   471 				}
   472 			iProfiler->MarkResultSetL();
   473 			}
   474 		
   475 		CleanupStack::PopAndDestroy(2, writeBuffer);//maskBuffer, writeBuffer
   476 		iProfiler->ResultsAnalysis(KTestName, CFbsBitGc::EGraphicsOrientationNormal, sourceFormat, displayMode, KIterationsToTest);	
   477 		}
   478 	}
   479 
   480