os/graphics/graphicstest/uibench/src/tgraphicsresource.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200 (2012-06-15)
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     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 "tgraphicsresource.h"
    23 #include "tdirectgditestbase.h"
    24 #ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
    25 #include <graphics/sgimage_sw.h>
    26 #endif
    27 
    28 #ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
    29 const TInt KIterationsToTest = 1000;
    30 #endif
    31 
    32 CTGraphicsResource::CTGraphicsResource()
    33 	{
    34 	SetTestStepName(KTGraphicsResource);
    35 	
    36 #ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
    37 	iImageInfo.iCpuAccess = ESgCpuAccessReadWrite;
    38 	iImageInfo.iUsage = ESgUsageDirectGdiSource;
    39 	iImageInfo.iPixelFormat = EUidPixelFormatRGB_565;
    40 	iImageInfo.iShareable = ETrue;
    41 	
    42 	Mem::FillZ(iImageData, KMaxArraySize * sizeof(TUint16));
    43 	TEST(KErrNone == SgDriver::Open());
    44 #endif
    45 	}
    46 
    47 CTGraphicsResource::~CTGraphicsResource()
    48 	{	
    49 #ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
    50 	TInt temp = SgDriver::ResourceCount();
    51 	SgDriver::Close();
    52 #endif
    53 	}
    54 
    55 /**
    56 Override of base class pure virtual
    57 Our implementation only gets called if the base class doTestStepPreambleL() did
    58 not leave. That being the case, the current test result value will be EPass.
    59 
    60 @return - TVerdict code
    61 */
    62 TVerdict CTGraphicsResource::doTestStepL()
    63 	{
    64 #ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
    65     INFO_PRINTF1(_L("CTGraphicsResource can only be run with RSgImage legacy"));
    66     return TestStepResult();
    67 #else
    68 	SetTestStepID(_L("GRAPHICS-UI-BENCH-0089"));
    69 	SmallImageCreationSimpleL();
    70 	RecordTestResultL();
    71 	SetTestStepID(_L("GRAPHICS-UI-BENCH-0090"));
    72 	LargeImageCreationSimpleL();
    73 	RecordTestResultL();
    74 	SetTestStepID(_L("GRAPHICS-UI-BENCH-0091"));
    75 	ImageDuplicateL();	
    76 	RecordTestResultL();
    77 	SetTestStepID(_L("GRAPHICS-UI-BENCH-0092"));
    78 	ImageDuplicateHandleL();
    79 	RecordTestResultL();
    80 	SetTestStepID(_L("GRAPHICS-UI-BENCH-0093"));
    81 	ImageMapL();
    82 	RecordTestResultL();
    83     CloseTMSGraphicsStep();
    84 	return TestStepResult();
    85 #endif	
    86 	}
    87 
    88 #ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
    89 /**
    90 Helper function.
    91 Creates and destroys images of the same size KIterationsToTest times.
    92 
    93 @param aWidth The width of the created bitmaps.
    94 @param aHeight  The height of the created bitmaps.
    95 @param aTestDescription The description of the test.
    96 */
    97 void CTGraphicsResource::ImageCreationSimpleL(const TInt aWidth, const TInt aHeight, const TDesC& aTestDescription)
    98 	{
    99 	iImageInfo.iSizeInPixels = TSize(aWidth, aHeight);
   100 	TInt sizeInBytes = aWidth*aHeight*2;
   101 	RSgImage image;
   102 	
   103 	iProfiler->InitResults();	
   104 	for(TInt count=KIterationsToTest; count>=0; --count)
   105 		{
   106 		TInt err = image.Create(iImageInfo, NULL, 0);
   107 		TESTL(err == KErrNone);
   108 		MSgImage_Sw* data;
   109 		TESTNOERRORL(image.GetInterface(data));
   110 		Mem::Fill(data->DataAddress(), sizeInBytes, 0xFF);
   111 		image.Close();
   112 		iProfiler->MarkResultSetL();
   113 		}	
   114 	iProfiler->ResultsAnalysis(aTestDescription, TDisplayModeMapping::MapPixelFormatToDisplayMode(iImageInfo.iPixelFormat), 0, 0, KIterationsToTest);
   115 	}
   116 
   117 /**
   118 @SYMTestCaseID
   119 GRAPHICS-UI-BENCH-0089
   120 
   121 @SYMPREQ PREQ39
   122 
   123 @SYMREQ REQ9236 
   124 @SYMREQ REQ9237
   125 
   126 @SYMTestCaseDesc
   127 The test determines how long it takes to create and destroy small simple RSgImage objects.
   128 
   129 @SYMTestActions
   130 Compare the results over time, and before and after changes to image construction and destruction code.
   131 
   132 @SYMTestExpectedResults
   133 Test should pass and display total test time and time per image
   134 */
   135 void CTGraphicsResource::SmallImageCreationSimpleL()
   136 	{
   137 	ImageCreationSimpleL(32, 32, _L("Small-RSgImage-Create-64K-Simple"));
   138 	}
   139 
   140 /**
   141 @SYMTestCaseID
   142 GRAPHICS-UI-BENCH-0090
   143 
   144 @SYMPREQ PREQ39
   145 
   146 @SYMREQ REQ9236 
   147 @SYMREQ REQ9237
   148 
   149 @SYMTestCaseDesc
   150 The test determines how long it takes to create and destroy large simple RSgImage objects.
   151 
   152 @SYMTestActions
   153 Compare the results over time, and before and after changes to image construction and destruction code.
   154 
   155 @SYMTestExpectedResults
   156 Test should pass and display total test time and time per image
   157 */
   158 void CTGraphicsResource::LargeImageCreationSimpleL()
   159 	{
   160 	ImageCreationSimpleL(500, 500, _L("Large-RSgImage-Create-64K-Simple"));
   161 	}
   162 
   163 /**
   164 @SYMTestCaseID
   165 GRAPHICS-UI-BENCH-0091
   166 
   167 @SYMPREQ PREQ39
   168 
   169 @SYMREQ REQ9236 
   170 @SYMREQ REQ9237
   171 
   172 @SYMTestCaseDesc
   173 Tests how long it takes to duplicate an RSgImage.
   174 
   175 @SYMTestActions
   176 Compare the results over time, and before and after changes to bitmap duplication code.
   177 
   178 @SYMTestExpectedResults
   179 Test should pass and display total test time and time per image.
   180 */
   181 void CTGraphicsResource::ImageDuplicateL()
   182 	{
   183 	//prepare an image to duplicate
   184 	iImageInfo.iSizeInPixels = TSize(300, 300);
   185 	
   186 	RSgImage image;
   187 	TInt err = image.Create(iImageInfo, iImageData, KImageDataStride);
   188 	TESTL(err == KErrNone);
   189 	
   190 	iProfiler->InitResults();
   191 	for(TInt count=KIterationsToTest; count>=0; --count)
   192 		{
   193 		RSgImage image2;
   194 		err = image2.Create(iImageInfo, image);
   195 		TESTL(err == KErrNone);
   196 		image2.Close();
   197 		iProfiler->MarkResultSetL();
   198 		}	
   199 	iProfiler->ResultsAnalysis(_L("RSgImage-Duplicate           "), TDisplayModeMapping::MapPixelFormatToDisplayMode(iImageInfo.iPixelFormat), 0, 0, KIterationsToTest);	
   200 	
   201 	image.Close();
   202 	}
   203 
   204 /**
   205 @SYMTestCaseID
   206 GRAPHICS-UI-BENCH-0092
   207 
   208 @SYMPREQ PREQ39
   209 
   210 @SYMREQ REQ9236 
   211 @SYMREQ REQ9237
   212 
   213 @SYMTestCaseDesc
   214 Tests how long it takes to duplicate an image handle.
   215 
   216 @SYMTestActions
   217 Compare the results over time, and before and after changes to image duplication code.
   218 
   219 @SYMTestExpectedResults
   220 Test should pass and display total test time and time per image.
   221 */
   222 void CTGraphicsResource::ImageDuplicateHandleL()
   223 	{
   224 	//prepare an image to duplicate
   225 	iImageInfo.iSizeInPixels = TSize(300, 300);
   226 	
   227 	RSgImage image;
   228 	TInt err = image.Create(iImageInfo, iImageData, KImageDataStride);
   229 	TESTL(err == KErrNone);
   230 	TSgDrawableId id = image.Id();	
   231 	
   232 	iProfiler->InitResults();
   233 	for(TInt count=KIterationsToTest; count>=0; --count)
   234 		{
   235 		RSgImage image2;
   236 		err = image2.Open(id);
   237 		TESTL(KErrNone == err);
   238 		image2.Close();
   239 		iProfiler->MarkResultSetL();
   240 		}	
   241 	iProfiler->ResultsAnalysis(_L("RSgImage-Duplicate-Handle"), TDisplayModeMapping::MapPixelFormatToDisplayMode(iImageInfo.iPixelFormat), 0, 0, KIterationsToTest);	
   242 	
   243 	image.Close();
   244 	}
   245 
   246 /**
   247 @SYMTestCaseID
   248 GRAPHICS-UI-BENCH-0093
   249 
   250 @SYMPREQ PREQ39
   251 
   252 @SYMREQ REQ9236 
   253 @SYMREQ REQ9237
   254 
   255 @SYMTestCaseDesc
   256 Measure performance of Map() and Unmap() of an RSgImage.
   257 
   258 @SYMTestActions
   259 Compare the results over time, and before and after changes to image mapping code.
   260 
   261 @SYMTestExpectedResults
   262 Test should pass and display total test time and time per image.
   263 */
   264 void CTGraphicsResource::ImageMapL()
   265 	{
   266 	//prepare an image
   267 	iImageInfo.iSizeInPixels = TSize(300, 300);
   268 	
   269 	RSgImage image;
   270 	TInt err = image.Create(iImageInfo, iImageData, KImageDataStride);
   271 	TESTL(err == KErrNone);
   272 	
   273 	const TAny* dataAddressRead;
   274 	TAny* dataAddressWrite;
   275 	TInt dataStride;
   276 	
   277 	iProfiler->InitResults();
   278 	for(TInt count=KIterationsToTest; count>=0; --count)
   279 		{
   280 		err = image.MapReadOnly(dataAddressRead, dataStride);
   281 		TESTL(err == KErrNone);
   282 		image.Unmap();
   283 		iProfiler->MarkResultSetL();
   284 		}	
   285 	iProfiler->ResultsAnalysis(_L("RSgImage-MapReadOnly          "), TDisplayModeMapping::MapPixelFormatToDisplayMode(iImageInfo.iPixelFormat), 0, 0, KIterationsToTest);	
   286 	
   287 	iProfiler->InitResults();
   288 	for(TInt count=KIterationsToTest; count>=0; --count)
   289 		{
   290 		err = image.MapWriteOnly(dataAddressWrite, dataStride);
   291 		TESTL(err == KErrNone);
   292 		image.Unmap();
   293 		iProfiler->MarkResultSetL();
   294 		}	
   295 	iProfiler->ResultsAnalysis(_L("RSgImage-MapWriteOnly          "), TDisplayModeMapping::MapPixelFormatToDisplayMode(iImageInfo.iPixelFormat), 0, 0, KIterationsToTest);
   296 	
   297 	iProfiler->InitResults();
   298 	for(TInt count=KIterationsToTest; count>=0; --count)
   299 		{
   300 		err = image.MapReadWrite(dataAddressWrite, dataStride);
   301 		TESTL(err == KErrNone);
   302 		image.Unmap();
   303 		iProfiler->MarkResultSetL();
   304 		}	
   305 	iProfiler->ResultsAnalysis(_L("RSgImage-MapReadWrite              "), TDisplayModeMapping::MapPixelFormatToDisplayMode(iImageInfo.iPixelFormat), 0, 0, KIterationsToTest);
   306 	
   307 	image.Close();
   308 	}
   309 #endif