Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
19 @internalComponent - Internal Symbian test code
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>
29 // The number of iterations to perform for each test in this suite.
30 const TInt KIterationsToTest = 1000;
32 _LIT(KTileBitmap, "z:\\system\\data\\uibench_tile.mbm");
35 CTDirectGdiPerf::CTDirectGdiPerf()
37 SetTestStepName(KTDirectGdiPerfTest);
40 CTDirectGdiPerf::~CTDirectGdiPerf()
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.
49 @return - TVerdict code
51 TVerdict CTDirectGdiPerf::doTestStepL()
53 #ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
54 INFO_PRINTF1(_L("CTDirectGdiPerf can only be run with RSgImage legacy"));
55 return TestStepResult();
57 iContext = CDirectGdiContext::NewL(*iDGdiDriver);
58 iDGdiImageTarget->Close();
60 // for each display mode
61 for(TInt dispModeIndex = 0; dispModeIndex < iTargetPixelFormatArray.Count(); ++dispModeIndex)
63 iDisplayMode = TDisplayModeMapping::MapPixelFormatToDisplayMode(iTargetPixelFormatArray[dispModeIndex]);
65 SetTestStepID(_L("GRAPHICS-UI-BENCH-0095"));
68 SetTestStepID(_L("GRAPHICS-UI-BENCH-0096"));
69 MakeCurrentOnDifferentFormatTargetL();
71 SetTestStepID(_L("GRAPHICS-UI-BENCH-0097"));
72 MakeCurrentOnSameFormatTargetL();
79 CloseTMSGraphicsStep();
80 return TestStepResult();
84 #ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
87 GRAPHICS-UI-BENCH-0095
95 Tests how long it takes to create, activate and destroy a DirectGDI target.
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.
102 @SYMTestExpectedResults
103 The time taken to perform the creation/destruction of the test to be logged.
104 The driver should report no errors.
106 void CTDirectGdiPerf::CreatingTargetsL()
108 TInt result = KErrNone;
109 _LIT(KTestName, "CreatingTargets");
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);
121 iProfiler->InitResults();
122 for(TInt lc=KIterationsToTest; lc>0; --lc)
124 RDirectGdiImageTarget dgdiImageTarget(*iDGdiDriver);
125 TESTNOERRORL(dgdiImageTarget.Create(rsgImage));
126 TESTNOERRORL(iContext->Activate(dgdiImageTarget));
128 dgdiImageTarget.Close();
129 iProfiler->MarkResultSetL();
131 TESTNOERRORL(iDGdiDriver->GetError());
133 CleanupStack::PopAndDestroy(1, &rsgImage);
136 iProfiler->ResultsAnalysis(KTestName, 0, iDisplayMode, iDisplayMode, KIterationsToTest);
141 GRAPHICS-UI-BENCH-0096
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.
153 Initialise the DirectGDI driver.
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.
160 @SYMTestExpectedResults
161 The time taken to perform the test should be logged.
162 The driver should report no errors.
164 void CTDirectGdiPerf::MakeCurrentOnDifferentFormatTargetL()
166 _LIT(KTestName, "MakeCurrentOnDifferentTargets");
167 DoMakeCurrentTestL(KTestName(), EFalse);
172 GRAPHICS-UI-BENCH-0097
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.
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.
189 @SYMTestExpectedResults
190 The time taken to perform the test should be logged.
191 The driver should report no errors.
193 void CTDirectGdiPerf::MakeCurrentOnSameFormatTargetL()
195 _LIT(KTestName, "MakeCurrentOnSameFormatTarget");
196 DoMakeCurrentTestL(KTestName(), ETrue);
201 Helper function to share the common code for the MakeCurrent() tests.
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.
207 void CTDirectGdiPerf::DoMakeCurrentTestL(TPtrC aTestName, TBool aMatchingFormats)
209 TInt result = KErrNone;
213 // Use the other target display modes for the second pixel format.
214 for(TInt dispModeIndex = 0; dispModeIndex < iTargetPixelFormatArray.Count(); ++dispModeIndex)
216 const TDisplayMode displayModeOther = TDisplayModeMapping::MapPixelFormatToDisplayMode(iTargetPixelFormatArray[dispModeIndex]);
217 if (aMatchingFormats && displayModeOther != iDisplayMode) continue;
218 if (!aMatchingFormats && displayModeOther == iDisplayMode) continue;
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);
229 imageInfo.iPixelFormat = TDisplayModeMapping::MapDisplayModeToPixelFormat(iDisplayMode);
230 result = rsgImage2.Create(imageInfo, NULL,0);
231 TESTL(result == KErrNone);
232 CleanupClosePushL(rsgImage2);
234 CFbsBitmap* bitmap1 = LoadBitmapL(KTileBitmap, 0);
235 CleanupStack::PushL(bitmap1);
236 CFbsBitmap* bitmap2 = LoadBitmapL(KTileBitmap, 0);
237 CleanupStack::PushL(bitmap2);
239 RDirectGdiImageTarget dgdiImageTarget1(*iDGdiDriver);
240 RDirectGdiImageTarget dgdiImageTarget2(*iDGdiDriver);
242 iProfiler->InitResults();
243 for(TInt lc=KIterationsToTest; lc>0; --lc)
245 result = dgdiImageTarget1.Create(rsgImage1);
246 TESTL(result == KErrNone);
247 CleanupClosePushL(dgdiImageTarget1);
248 result = dgdiImageTarget2.Create(rsgImage2);
249 TESTL(result == KErrNone);
250 CleanupClosePushL(dgdiImageTarget2);
252 result = iContext->Activate (dgdiImageTarget1);
253 TESTL(result == KErrNone);
257 iContext->BitBlt(TPoint(20, 20), *bitmap1);
259 iProfiler->StartTimer();
260 result = iContext->Activate (dgdiImageTarget2);
261 TESTL(result == KErrNone);
262 iProfiler->MarkResultSetL();
266 iContext->BitBlt(TPoint(30, 30), *bitmap2);
268 // Close the targets.
269 CleanupStack::PopAndDestroy(2, &dgdiImageTarget1);
271 TESTNOERRORL(iDGdiDriver->GetError());
273 CleanupStack::PopAndDestroy(4, &rsgImage1);
274 iProfiler->ResultsAnalysis(aTestName, 0, displayModeOther, iDisplayMode, KIterationsToTest);