os/graphics/graphicstest/uibench/src/tdirectgdiperf.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/graphicstest/uibench/src/tdirectgdiperf.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,277 @@
     1.4 +// Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +/**
    1.20 + @file
    1.21 + @test
    1.22 + @internalComponent - Internal Symbian test code 
    1.23 +*/
    1.24 +
    1.25 +#include "tdirectgdiperf.h"
    1.26 +#include <graphics/directgdidriver.h>
    1.27 +#include <graphics/directgdicontext.h>
    1.28 +#include <graphics/directgdiimagetarget.h>
    1.29 +#ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
    1.30 +#include <graphics/sgimage.h>
    1.31 +
    1.32 +// The number of iterations to perform for each test in this suite.
    1.33 +const TInt KIterationsToTest = 1000;
    1.34 +
    1.35 +_LIT(KTileBitmap, "z:\\system\\data\\uibench_tile.mbm");
    1.36 +#endif
    1.37 +
    1.38 +CTDirectGdiPerf::CTDirectGdiPerf()
    1.39 +	{
    1.40 +	SetTestStepName(KTDirectGdiPerfTest);
    1.41 +	}
    1.42 +
    1.43 +CTDirectGdiPerf::~CTDirectGdiPerf()
    1.44 +	{
    1.45 +	}
    1.46 +
    1.47 +/**
    1.48 +Override of base class pure virtual
    1.49 +Our implementation only gets called if the base class doTestStepPreambleL() did
    1.50 +not leave. That being the case, the current test result value will be EPass.
    1.51 +
    1.52 +@return - TVerdict code
    1.53 +*/
    1.54 +TVerdict CTDirectGdiPerf::doTestStepL()
    1.55 +	{
    1.56 +#ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
    1.57 +    INFO_PRINTF1(_L("CTDirectGdiPerf can only be run with RSgImage legacy"));
    1.58 +    return TestStepResult();
    1.59 +#else
    1.60 +	iContext = CDirectGdiContext::NewL(*iDGdiDriver);
    1.61 +	iDGdiImageTarget->Close();
    1.62 +		
    1.63 +	// for each display mode
    1.64 +	for(TInt dispModeIndex = 0; dispModeIndex < iTargetPixelFormatArray.Count(); ++dispModeIndex)
    1.65 +		{
    1.66 +		iDisplayMode = TDisplayModeMapping::MapPixelFormatToDisplayMode(iTargetPixelFormatArray[dispModeIndex]);
    1.67 +		
    1.68 +		SetTestStepID(_L("GRAPHICS-UI-BENCH-0095"));
    1.69 +		CreatingTargetsL();
    1.70 +		RecordTestResultL();
    1.71 +		SetTestStepID(_L("GRAPHICS-UI-BENCH-0096"));
    1.72 +		MakeCurrentOnDifferentFormatTargetL();
    1.73 +		RecordTestResultL();
    1.74 +		SetTestStepID(_L("GRAPHICS-UI-BENCH-0097"));
    1.75 +		MakeCurrentOnSameFormatTargetL();
    1.76 +		RecordTestResultL();
    1.77 +		}
    1.78 +	
    1.79 +	delete iContext;
    1.80 +	iContext = NULL;
    1.81 +	
    1.82 +    CloseTMSGraphicsStep();
    1.83 +	return TestStepResult();
    1.84 +#endif	
    1.85 +	}
    1.86 +
    1.87 +#ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
    1.88 +/**
    1.89 +@SYMTestCaseID
    1.90 +GRAPHICS-UI-BENCH-0095
    1.91 +
    1.92 +@SYMPREQ PREQ39
    1.93 +
    1.94 +@SYMREQ REQ9236 
    1.95 +@SYMREQ REQ9237
    1.96 +
    1.97 +@SYMTestCaseDesc
    1.98 +Tests how long it takes to create, activate and destroy a DirectGDI target.
    1.99 +
   1.100 +@SYMTestActions
   1.101 +Setup an RSgImage for the target to be constructed from.
   1.102 +For KIterationsToTest, create an image target, activate the context on it, and close the target.
   1.103 +Cleanup.
   1.104 +
   1.105 +@SYMTestExpectedResults
   1.106 +The time taken to perform the creation/destruction of the test to be logged.
   1.107 +The driver should report no errors.
   1.108 +*/
   1.109 +void CTDirectGdiPerf::CreatingTargetsL()
   1.110 +	{
   1.111 +	TInt result = KErrNone;
   1.112 +	_LIT(KTestName, "CreatingTargets");
   1.113 +	
   1.114 +	RSgImage rsgImage;		
   1.115 +	// Set the bitmap up...
   1.116 +	TSgImageInfo imageInfo;
   1.117 +	imageInfo.iSizeInPixels = TSize (320, 240);
   1.118 +	imageInfo.iPixelFormat = TDisplayModeMapping::MapDisplayModeToPixelFormat(iDisplayMode);
   1.119 +	imageInfo.iUsage = ESgUsageDirectGdiTarget;
   1.120 +	result = rsgImage.Create(imageInfo, NULL,0);
   1.121 +	TESTL(result == KErrNone);
   1.122 +	CleanupClosePushL(rsgImage);
   1.123 +	
   1.124 +	iProfiler->InitResults();
   1.125 +	for(TInt lc=KIterationsToTest; lc>0; --lc)
   1.126 +		{		
   1.127 +		RDirectGdiImageTarget dgdiImageTarget(*iDGdiDriver);
   1.128 +		TESTNOERRORL(dgdiImageTarget.Create(rsgImage));
   1.129 +		TESTNOERRORL(iContext->Activate(dgdiImageTarget));
   1.130 +		
   1.131 +		dgdiImageTarget.Close();
   1.132 +		iProfiler->MarkResultSetL();
   1.133 +		}
   1.134 +	TESTNOERRORL(iDGdiDriver->GetError());
   1.135 +	
   1.136 +	CleanupStack::PopAndDestroy(1, &rsgImage);
   1.137 +	
   1.138 +	
   1.139 +	iProfiler->ResultsAnalysis(KTestName, 0, iDisplayMode, iDisplayMode, KIterationsToTest);	
   1.140 +	}
   1.141 +
   1.142 +/**
   1.143 +@SYMTestCaseID
   1.144 +GRAPHICS-UI-BENCH-0096
   1.145 +
   1.146 +@SYMPREQ PREQ39
   1.147 +
   1.148 +@SYMREQ REQ9236 
   1.149 +@SYMREQ REQ9237
   1.150 +
   1.151 +@SYMTestCaseDesc
   1.152 +Tests how long it takes to make a different target current on the context after performing
   1.153 +some drawing on a previous target. The two targets have different pixel formats.
   1.154 +
   1.155 +@SYMTestActions
   1.156 +Initialise the DirectGDI driver.
   1.157 +Create a context.
   1.158 +Setup an RSgImage for the target to be constructed from.
   1.159 +For KIterationsToTest, create two targets, activate and draw to the first one,
   1.160 +then start the timer and activate the second target.
   1.161 +Cleanup.
   1.162 +
   1.163 +@SYMTestExpectedResults
   1.164 +The time taken to perform the test should be logged.
   1.165 +The driver should report no errors.
   1.166 +*/
   1.167 +void CTDirectGdiPerf::MakeCurrentOnDifferentFormatTargetL()
   1.168 +	{
   1.169 +	_LIT(KTestName, "MakeCurrentOnDifferentTargets");
   1.170 +	DoMakeCurrentTestL(KTestName(), EFalse);
   1.171 +	}
   1.172 +
   1.173 +/**
   1.174 +@SYMTestCaseID
   1.175 +GRAPHICS-UI-BENCH-0097
   1.176 +
   1.177 +@SYMPREQ PREQ39
   1.178 +
   1.179 +@SYMREQ REQ9236 
   1.180 +@SYMREQ REQ9237
   1.181 +
   1.182 +@SYMTestCaseDesc
   1.183 +Tests how long it takes to make a different target current on the context after performing
   1.184 +some drawing on a previous target. The targets have the same pixel formats.
   1.185 +
   1.186 +@SYMTestActions
   1.187 +Setup an RSgImage for the target to be constructed from.
   1.188 +For KIterationsToTest, create two targets, activate and draw to the first one,
   1.189 +then start the timer and activate the second target.
   1.190 +Cleanup.
   1.191 +
   1.192 +@SYMTestExpectedResults
   1.193 +The time taken to perform the test should be logged.
   1.194 +The driver should report no errors.
   1.195 +*/
   1.196 +void CTDirectGdiPerf::MakeCurrentOnSameFormatTargetL()
   1.197 +	{
   1.198 +	_LIT(KTestName, "MakeCurrentOnSameFormatTarget");		
   1.199 +	DoMakeCurrentTestL(KTestName(), ETrue);
   1.200 +	}
   1.201 +
   1.202 +
   1.203 +/**
   1.204 +Helper function to share the common code for the MakeCurrent() tests.
   1.205 +
   1.206 +@param aTestName The name of the test being run, for logging.
   1.207 +@param aMatchingFormats If ETrue, will only run the test when the source and target display modes are 
   1.208 +       the same. If EFalse, will only run the test if the source and target display modes are different.
   1.209 +*/
   1.210 +void CTDirectGdiPerf::DoMakeCurrentTestL(TPtrC aTestName, TBool aMatchingFormats)
   1.211 +	{
   1.212 +	TInt result = KErrNone;
   1.213 +	RSgImage rsgImage1;
   1.214 +	RSgImage rsgImage2;
   1.215 +	
   1.216 +	// Use the other target display modes for the second pixel format. 
   1.217 +	for(TInt dispModeIndex = 0; dispModeIndex < iTargetPixelFormatArray.Count(); ++dispModeIndex)
   1.218 +		{
   1.219 +		const TDisplayMode displayModeOther = TDisplayModeMapping::MapPixelFormatToDisplayMode(iTargetPixelFormatArray[dispModeIndex]);
   1.220 +		if (aMatchingFormats && displayModeOther != iDisplayMode) continue;
   1.221 +		if (!aMatchingFormats && displayModeOther == iDisplayMode) continue;
   1.222 +	
   1.223 +		// Set the bitmap up...
   1.224 +		TSgImageInfo imageInfo;
   1.225 +		imageInfo.iSizeInPixels = TSize (150, 150);
   1.226 +		imageInfo.iPixelFormat = TDisplayModeMapping::MapDisplayModeToPixelFormat(displayModeOther);
   1.227 +		imageInfo.iUsage = ESgUsageDirectGdiTarget;
   1.228 +		result = rsgImage1.Create(imageInfo, NULL,0);
   1.229 +		TESTL(result == KErrNone);
   1.230 +		CleanupClosePushL(rsgImage1);
   1.231 +	
   1.232 +		imageInfo.iPixelFormat = TDisplayModeMapping::MapDisplayModeToPixelFormat(iDisplayMode);
   1.233 +		result = rsgImage2.Create(imageInfo, NULL,0);
   1.234 +		TESTL(result == KErrNone);
   1.235 +		CleanupClosePushL(rsgImage2);
   1.236 +		
   1.237 +		CFbsBitmap* bitmap1 = LoadBitmapL(KTileBitmap, 0);	
   1.238 +		CleanupStack::PushL(bitmap1);
   1.239 +		CFbsBitmap* bitmap2 = LoadBitmapL(KTileBitmap, 0);		
   1.240 +		CleanupStack::PushL(bitmap2);
   1.241 +		
   1.242 +		RDirectGdiImageTarget dgdiImageTarget1(*iDGdiDriver);
   1.243 +		RDirectGdiImageTarget dgdiImageTarget2(*iDGdiDriver);
   1.244 +		
   1.245 +		iProfiler->InitResults();
   1.246 +		for(TInt lc=KIterationsToTest; lc>0; --lc)
   1.247 +			{			
   1.248 +			result = dgdiImageTarget1.Create(rsgImage1);
   1.249 +			TESTL(result == KErrNone);
   1.250 +			CleanupClosePushL(dgdiImageTarget1);
   1.251 +			result = dgdiImageTarget2.Create(rsgImage2);
   1.252 +			TESTL(result == KErrNone);
   1.253 +			CleanupClosePushL(dgdiImageTarget2);					
   1.254 +	
   1.255 +			result = iContext->Activate (dgdiImageTarget1);		
   1.256 +			TESTL(result == KErrNone);
   1.257 +			
   1.258 +			iContext->Reset();
   1.259 +			iContext->Clear();
   1.260 +			iContext->BitBlt(TPoint(20, 20), *bitmap1);		
   1.261 +			
   1.262 +			iProfiler->StartTimer();
   1.263 +			result = iContext->Activate (dgdiImageTarget2);
   1.264 +			TESTL(result == KErrNone);
   1.265 +			iProfiler->MarkResultSetL();
   1.266 +			
   1.267 +			iContext->Reset();
   1.268 +			iContext->Clear();
   1.269 +			iContext->BitBlt(TPoint(30, 30), *bitmap2);
   1.270 +			
   1.271 +			// Close the targets.
   1.272 +			CleanupStack::PopAndDestroy(2, &dgdiImageTarget1);
   1.273 +			}
   1.274 +		TESTNOERRORL(iDGdiDriver->GetError());
   1.275 +		
   1.276 +		CleanupStack::PopAndDestroy(4, &rsgImage1);		
   1.277 +		iProfiler->ResultsAnalysis(aTestName, 0, displayModeOther, iDisplayMode, KIterationsToTest);
   1.278 +		}
   1.279 +	}
   1.280 +#endif