graphicstest/uibench/src/tdirectgdiperf.cpp
changeset 0 5d03bc08d59c
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 // Copyright (c) 2006-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 "tdirectgdiperf.h"
       
    23 #include <graphics/directgdidriver.h>
       
    24 #include <graphics/directgdicontext.h>
       
    25 #include <graphics/directgdiimagetarget.h>
       
    26 #ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
       
    27 #include <graphics/sgimage.h>
       
    28 
       
    29 // The number of iterations to perform for each test in this suite.
       
    30 const TInt KIterationsToTest = 1000;
       
    31 
       
    32 _LIT(KTileBitmap, "z:\\system\\data\\uibench_tile.mbm");
       
    33 #endif
       
    34 
       
    35 CTDirectGdiPerf::CTDirectGdiPerf()
       
    36 	{
       
    37 	SetTestStepName(KTDirectGdiPerfTest);
       
    38 	}
       
    39 
       
    40 CTDirectGdiPerf::~CTDirectGdiPerf()
       
    41 	{
       
    42 	}
       
    43 
       
    44 /**
       
    45 Override of base class pure virtual
       
    46 Our implementation only gets called if the base class doTestStepPreambleL() did
       
    47 not leave. That being the case, the current test result value will be EPass.
       
    48 
       
    49 @return - TVerdict code
       
    50 */
       
    51 TVerdict CTDirectGdiPerf::doTestStepL()
       
    52 	{
       
    53 #ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
       
    54     INFO_PRINTF1(_L("CTDirectGdiPerf can only be run with RSgImage legacy"));
       
    55     return TestStepResult();
       
    56 #else
       
    57 	iContext = CDirectGdiContext::NewL(*iDGdiDriver);
       
    58 	iDGdiImageTarget->Close();
       
    59 		
       
    60 	// for each display mode
       
    61 	for(TInt dispModeIndex = 0; dispModeIndex < iTargetPixelFormatArray.Count(); ++dispModeIndex)
       
    62 		{
       
    63 		iDisplayMode = TDisplayModeMapping::MapPixelFormatToDisplayMode(iTargetPixelFormatArray[dispModeIndex]);
       
    64 		
       
    65 		SetTestStepID(_L("GRAPHICS-UI-BENCH-0095"));
       
    66 		CreatingTargetsL();
       
    67 		RecordTestResultL();
       
    68 		SetTestStepID(_L("GRAPHICS-UI-BENCH-0096"));
       
    69 		MakeCurrentOnDifferentFormatTargetL();
       
    70 		RecordTestResultL();
       
    71 		SetTestStepID(_L("GRAPHICS-UI-BENCH-0097"));
       
    72 		MakeCurrentOnSameFormatTargetL();
       
    73 		RecordTestResultL();
       
    74 		}
       
    75 	
       
    76 	delete iContext;
       
    77 	iContext = NULL;
       
    78 	
       
    79     CloseTMSGraphicsStep();
       
    80 	return TestStepResult();
       
    81 #endif	
       
    82 	}
       
    83 
       
    84 #ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
       
    85 /**
       
    86 @SYMTestCaseID
       
    87 GRAPHICS-UI-BENCH-0095
       
    88 
       
    89 @SYMPREQ PREQ39
       
    90 
       
    91 @SYMREQ REQ9236 
       
    92 @SYMREQ REQ9237
       
    93 
       
    94 @SYMTestCaseDesc
       
    95 Tests how long it takes to create, activate and destroy a DirectGDI target.
       
    96 
       
    97 @SYMTestActions
       
    98 Setup an RSgImage for the target to be constructed from.
       
    99 For KIterationsToTest, create an image target, activate the context on it, and close the target.
       
   100 Cleanup.
       
   101 
       
   102 @SYMTestExpectedResults
       
   103 The time taken to perform the creation/destruction of the test to be logged.
       
   104 The driver should report no errors.
       
   105 */
       
   106 void CTDirectGdiPerf::CreatingTargetsL()
       
   107 	{
       
   108 	TInt result = KErrNone;
       
   109 	_LIT(KTestName, "CreatingTargets");
       
   110 	
       
   111 	RSgImage rsgImage;		
       
   112 	// Set the bitmap up...
       
   113 	TSgImageInfo imageInfo;
       
   114 	imageInfo.iSizeInPixels = TSize (320, 240);
       
   115 	imageInfo.iPixelFormat = TDisplayModeMapping::MapDisplayModeToPixelFormat(iDisplayMode);
       
   116 	imageInfo.iUsage = ESgUsageDirectGdiTarget;
       
   117 	result = rsgImage.Create(imageInfo, NULL,0);
       
   118 	TESTL(result == KErrNone);
       
   119 	CleanupClosePushL(rsgImage);
       
   120 	
       
   121 	iProfiler->InitResults();
       
   122 	for(TInt lc=KIterationsToTest; lc>0; --lc)
       
   123 		{		
       
   124 		RDirectGdiImageTarget dgdiImageTarget(*iDGdiDriver);
       
   125 		TESTNOERRORL(dgdiImageTarget.Create(rsgImage));
       
   126 		TESTNOERRORL(iContext->Activate(dgdiImageTarget));
       
   127 		
       
   128 		dgdiImageTarget.Close();
       
   129 		iProfiler->MarkResultSetL();
       
   130 		}
       
   131 	TESTNOERRORL(iDGdiDriver->GetError());
       
   132 	
       
   133 	CleanupStack::PopAndDestroy(1, &rsgImage);
       
   134 	
       
   135 	
       
   136 	iProfiler->ResultsAnalysis(KTestName, 0, iDisplayMode, iDisplayMode, KIterationsToTest);	
       
   137 	}
       
   138 
       
   139 /**
       
   140 @SYMTestCaseID
       
   141 GRAPHICS-UI-BENCH-0096
       
   142 
       
   143 @SYMPREQ PREQ39
       
   144 
       
   145 @SYMREQ REQ9236 
       
   146 @SYMREQ REQ9237
       
   147 
       
   148 @SYMTestCaseDesc
       
   149 Tests how long it takes to make a different target current on the context after performing
       
   150 some drawing on a previous target. The two targets have different pixel formats.
       
   151 
       
   152 @SYMTestActions
       
   153 Initialise the DirectGDI driver.
       
   154 Create a context.
       
   155 Setup an RSgImage for the target to be constructed from.
       
   156 For KIterationsToTest, create two targets, activate and draw to the first one,
       
   157 then start the timer and activate the second target.
       
   158 Cleanup.
       
   159 
       
   160 @SYMTestExpectedResults
       
   161 The time taken to perform the test should be logged.
       
   162 The driver should report no errors.
       
   163 */
       
   164 void CTDirectGdiPerf::MakeCurrentOnDifferentFormatTargetL()
       
   165 	{
       
   166 	_LIT(KTestName, "MakeCurrentOnDifferentTargets");
       
   167 	DoMakeCurrentTestL(KTestName(), EFalse);
       
   168 	}
       
   169 
       
   170 /**
       
   171 @SYMTestCaseID
       
   172 GRAPHICS-UI-BENCH-0097
       
   173 
       
   174 @SYMPREQ PREQ39
       
   175 
       
   176 @SYMREQ REQ9236 
       
   177 @SYMREQ REQ9237
       
   178 
       
   179 @SYMTestCaseDesc
       
   180 Tests how long it takes to make a different target current on the context after performing
       
   181 some drawing on a previous target. The targets have the same pixel formats.
       
   182 
       
   183 @SYMTestActions
       
   184 Setup an RSgImage for the target to be constructed from.
       
   185 For KIterationsToTest, create two targets, activate and draw to the first one,
       
   186 then start the timer and activate the second target.
       
   187 Cleanup.
       
   188 
       
   189 @SYMTestExpectedResults
       
   190 The time taken to perform the test should be logged.
       
   191 The driver should report no errors.
       
   192 */
       
   193 void CTDirectGdiPerf::MakeCurrentOnSameFormatTargetL()
       
   194 	{
       
   195 	_LIT(KTestName, "MakeCurrentOnSameFormatTarget");		
       
   196 	DoMakeCurrentTestL(KTestName(), ETrue);
       
   197 	}
       
   198 
       
   199 
       
   200 /**
       
   201 Helper function to share the common code for the MakeCurrent() tests.
       
   202 
       
   203 @param aTestName The name of the test being run, for logging.
       
   204 @param aMatchingFormats If ETrue, will only run the test when the source and target display modes are 
       
   205        the same. If EFalse, will only run the test if the source and target display modes are different.
       
   206 */
       
   207 void CTDirectGdiPerf::DoMakeCurrentTestL(TPtrC aTestName, TBool aMatchingFormats)
       
   208 	{
       
   209 	TInt result = KErrNone;
       
   210 	RSgImage rsgImage1;
       
   211 	RSgImage rsgImage2;
       
   212 	
       
   213 	// Use the other target display modes for the second pixel format. 
       
   214 	for(TInt dispModeIndex = 0; dispModeIndex < iTargetPixelFormatArray.Count(); ++dispModeIndex)
       
   215 		{
       
   216 		const TDisplayMode displayModeOther = TDisplayModeMapping::MapPixelFormatToDisplayMode(iTargetPixelFormatArray[dispModeIndex]);
       
   217 		if (aMatchingFormats && displayModeOther != iDisplayMode) continue;
       
   218 		if (!aMatchingFormats && displayModeOther == iDisplayMode) continue;
       
   219 	
       
   220 		// Set the bitmap up...
       
   221 		TSgImageInfo imageInfo;
       
   222 		imageInfo.iSizeInPixels = TSize (150, 150);
       
   223 		imageInfo.iPixelFormat = TDisplayModeMapping::MapDisplayModeToPixelFormat(displayModeOther);
       
   224 		imageInfo.iUsage = ESgUsageDirectGdiTarget;
       
   225 		result = rsgImage1.Create(imageInfo, NULL,0);
       
   226 		TESTL(result == KErrNone);
       
   227 		CleanupClosePushL(rsgImage1);
       
   228 	
       
   229 		imageInfo.iPixelFormat = TDisplayModeMapping::MapDisplayModeToPixelFormat(iDisplayMode);
       
   230 		result = rsgImage2.Create(imageInfo, NULL,0);
       
   231 		TESTL(result == KErrNone);
       
   232 		CleanupClosePushL(rsgImage2);
       
   233 		
       
   234 		CFbsBitmap* bitmap1 = LoadBitmapL(KTileBitmap, 0);	
       
   235 		CleanupStack::PushL(bitmap1);
       
   236 		CFbsBitmap* bitmap2 = LoadBitmapL(KTileBitmap, 0);		
       
   237 		CleanupStack::PushL(bitmap2);
       
   238 		
       
   239 		RDirectGdiImageTarget dgdiImageTarget1(*iDGdiDriver);
       
   240 		RDirectGdiImageTarget dgdiImageTarget2(*iDGdiDriver);
       
   241 		
       
   242 		iProfiler->InitResults();
       
   243 		for(TInt lc=KIterationsToTest; lc>0; --lc)
       
   244 			{			
       
   245 			result = dgdiImageTarget1.Create(rsgImage1);
       
   246 			TESTL(result == KErrNone);
       
   247 			CleanupClosePushL(dgdiImageTarget1);
       
   248 			result = dgdiImageTarget2.Create(rsgImage2);
       
   249 			TESTL(result == KErrNone);
       
   250 			CleanupClosePushL(dgdiImageTarget2);					
       
   251 	
       
   252 			result = iContext->Activate (dgdiImageTarget1);		
       
   253 			TESTL(result == KErrNone);
       
   254 			
       
   255 			iContext->Reset();
       
   256 			iContext->Clear();
       
   257 			iContext->BitBlt(TPoint(20, 20), *bitmap1);		
       
   258 			
       
   259 			iProfiler->StartTimer();
       
   260 			result = iContext->Activate (dgdiImageTarget2);
       
   261 			TESTL(result == KErrNone);
       
   262 			iProfiler->MarkResultSetL();
       
   263 			
       
   264 			iContext->Reset();
       
   265 			iContext->Clear();
       
   266 			iContext->BitBlt(TPoint(30, 30), *bitmap2);
       
   267 			
       
   268 			// Close the targets.
       
   269 			CleanupStack::PopAndDestroy(2, &dgdiImageTarget1);
       
   270 			}
       
   271 		TESTNOERRORL(iDGdiDriver->GetError());
       
   272 		
       
   273 		CleanupStack::PopAndDestroy(4, &rsgImage1);		
       
   274 		iProfiler->ResultsAnalysis(aTestName, 0, displayModeOther, iDisplayMode, KIterationsToTest);
       
   275 		}
       
   276 	}
       
   277 #endif