os/graphics/graphicstest/uibench/src/toptimisedbmp.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
/**
sl@0
    17
 @file
sl@0
    18
 @test
sl@0
    19
 @internalComponent - Internal Symbian test code 
sl@0
    20
*/
sl@0
    21
sl@0
    22
#include "toptimisedbmp.h"
sl@0
    23
#include "fbsmessage.h"
sl@0
    24
#include <test/tefunit.h>
sl@0
    25
#include <hal.h>
sl@0
    26
sl@0
    27
// The following line must be disabled for testing with the background compression code
sl@0
    28
// When enabled foreground bitmap compression will take place.
sl@0
    29
// #define FORCE_FOREGROUND_COMPRESSION
sl@0
    30
sl@0
    31
// Number of times to repeat the tests
sl@0
    32
const TInt KRepeatTestCount = 100;
sl@0
    33
sl@0
    34
// The source bitmaps, only use the bitmaps from UIBENCH
sl@0
    35
_LIT( KmbmFilesInRom, "z:\\system\\data\\uibench_*.mbm" );
sl@0
    36
sl@0
    37
// The 16bit rle compressed source bitmap on Z drive
sl@0
    38
_LIT( Kmbm16bppRleComprFileInRom, "z:\\system\\data\\rlecompr_16bpp.mbm" );
sl@0
    39
sl@0
    40
// The 32bit alpha rle compressed source bitmap on Z drive
sl@0
    41
_LIT( Kmbm32abppRleComprFileInRom, "z:\\system\\data\\rlecompr_32abpp.mbm" );
sl@0
    42
sl@0
    43
// The 16bit rle compressed source bitmap on C drive
sl@0
    44
_LIT( Kmbm16bppRleComprFileOnC, "c:\\compressedBitmaps\\rlecompr_16bpp.mbm" );
sl@0
    45
sl@0
    46
#ifdef _DEBUG
sl@0
    47
// The 32bit alpha  rle compressed source bitmap on C drive
sl@0
    48
_LIT( Kmbm32abppRleComprFileOnC, "c:\\compressedBitmaps\\rlecompr_32abpp.mbm" );
sl@0
    49
#endif
sl@0
    50
sl@0
    51
// The resouce mbm file
sl@0
    52
_LIT( KmbmResouceFile, "z:\\resource\\32bit20col.mbm" );
sl@0
    53
sl@0
    54
// The directory to copy the bitmaps to
sl@0
    55
_LIT( KDirectoryFilesOnC , "c:\\bitmapOptimisation\\" );
sl@0
    56
sl@0
    57
// The directory to copy the compressed bitmaps to
sl@0
    58
_LIT( KDirectoryComprBmpFilesOnC , "c:\\compressedBitmaps\\" );
sl@0
    59
sl@0
    60
CTOptimisedBmp::CTOptimisedBmp()
sl@0
    61
	{
sl@0
    62
	SetTestStepName(KTOptimisedBmpStep);
sl@0
    63
	}
sl@0
    64
sl@0
    65
CTOptimisedBmp::~CTOptimisedBmp()
sl@0
    66
	{
sl@0
    67
	// clear test files
sl@0
    68
	if (iFileMan)
sl@0
    69
		{
sl@0
    70
		TBuf <255> filePath;
sl@0
    71
		_LIT(KFormat, "%S*.mbm");
sl@0
    72
		filePath.Format(KFormat, &KDirectoryFilesOnC);
sl@0
    73
		iFileMan->Delete(filePath);
sl@0
    74
		
sl@0
    75
		//remove filepath for compressed bitmap
sl@0
    76
		filePath.Format(KFormat, &KDirectoryComprBmpFilesOnC);		
sl@0
    77
		iFileMan->Delete(filePath);
sl@0
    78
		
sl@0
    79
		delete iFileMan;
sl@0
    80
		}	
sl@0
    81
	iFs.RmDir(KDirectoryFilesOnC);
sl@0
    82
	
sl@0
    83
	//remove directory for compressed bitmap
sl@0
    84
	iFs.RmDir(KDirectoryComprBmpFilesOnC);	
sl@0
    85
	iFs.Close();
sl@0
    86
	}
sl@0
    87
		
sl@0
    88
/**
sl@0
    89
Override of base class virtual
sl@0
    90
 
sl@0
    91
@return - TVerdict code
sl@0
    92
*/
sl@0
    93
TVerdict CTOptimisedBmp::doTestStepPreambleL()
sl@0
    94
	{
sl@0
    95
	CTe_graphicsperformanceSuiteStepBase::doTestStepPreambleL();
sl@0
    96
	
sl@0
    97
	// copy all of the files in ROM z: to c:
sl@0
    98
	TInt err =  iFs.Connect();
sl@0
    99
	User::LeaveIfError(err);		
sl@0
   100
	iFs.ShareProtected();
sl@0
   101
	err =  iFs.MkDir(KDirectoryFilesOnC);
sl@0
   102
	if (err != KErrNone && err != KErrAlreadyExists)
sl@0
   103
		{
sl@0
   104
		User::Leave(err);
sl@0
   105
		}
sl@0
   106
	
sl@0
   107
	//create directory to store rle-compressed bitmap	
sl@0
   108
	err =  iFs.MkDir(KDirectoryComprBmpFilesOnC);
sl@0
   109
	if (err != KErrNone && err != KErrAlreadyExists)
sl@0
   110
		{
sl@0
   111
		User::Leave(err);
sl@0
   112
		}
sl@0
   113
		
sl@0
   114
	iFileMan = CFileMan::NewL( iFs );
sl@0
   115
	
sl@0
   116
	err =  iFileMan->Copy( KmbmFilesInRom, KDirectoryFilesOnC );
sl@0
   117
	TESTL(err == KErrNone);
sl@0
   118
	
sl@0
   119
	//Copying compressed mbm files to C drive
sl@0
   120
	err =  iFileMan->Copy( Kmbm16bppRleComprFileInRom, KDirectoryComprBmpFilesOnC );
sl@0
   121
	TESTL(err == KErrNone);
sl@0
   122
sl@0
   123
	err =  iFileMan->Copy( Kmbm32abppRleComprFileInRom, KDirectoryComprBmpFilesOnC );
sl@0
   124
	TESTL(err == KErrNone);
sl@0
   125
	
sl@0
   126
	return TestStepResult();
sl@0
   127
	}
sl@0
   128
	
sl@0
   129
/**
sl@0
   130
Override of base class pure virtual
sl@0
   131
Our implementation only gets called if the base class doTestStepPreambleL() did
sl@0
   132
not leave. That being the case, the current test result value will be EPass.
sl@0
   133
sl@0
   134
@return - TVerdict code
sl@0
   135
*/
sl@0
   136
TVerdict CTOptimisedBmp::doTestStepL()
sl@0
   137
	{
sl@0
   138
	
sl@0
   139
/**
sl@0
   140
@SYMTestCaseID
sl@0
   141
GRAPHICS-UI-BENCH-0021
sl@0
   142
sl@0
   143
@SYMTestCaseDesc
sl@0
   144
The test determines how long it takes to compress bitmaps, and how long it takes to bitblt the original and the compressed bitmaps.
sl@0
   145
sl@0
   146
@SYMTestActions
sl@0
   147
1. Over a number of iterations, measure time taken to compress a bitmap loaded from mbm file.  Each iteration the mbm is loaded from scratch.
sl@0
   148
2. Over a number of iterations, measure time taken to blit an uncompressed bitmap loaded from mbm file. This mbm file is the same as in step 1.
sl@0
   149
3. Over a number of iterations, measure time taken to blit the compressed bitmap loaded from step 1.
sl@0
   150
4. Check that the blits of the uncompressed bitmap and the compressed bitmap are the same.
sl@0
   151
sl@0
   152
Each of these steps is performed with various screen display modes and various display modes of the bitmap.
sl@0
   153
sl@0
   154
@SYMTestExpectedResults
sl@0
   155
Test should pass and display total and per bitmap compression, bitblt for uncompressed and compressed time.
sl@0
   156
*/
sl@0
   157
	SetTestStepID(_L("GRAPHICS-UI-BENCH-0021"));
sl@0
   158
	CompressedBitmapTestL();	
sl@0
   159
	RecordTestResultL();
sl@0
   160
	
sl@0
   161
/**
sl@0
   162
@SYMTestCaseID
sl@0
   163
GRAPHICS-UI-BENCH-0058
sl@0
   164
sl@0
   165
@SYMTestCaseDesc
sl@0
   166
The test determines how long it takes to load 16bpp compressed bitmaps.
sl@0
   167
sl@0
   168
@SYMDEF INC095318
sl@0
   169
sl@0
   170
@SYMTestPriority High
sl@0
   171
sl@0
   172
@SYMTestActions
sl@0
   173
Compare the results over time.
sl@0
   174
sl@0
   175
@SYMTestExpectedResults
sl@0
   176
Test should pass and logs the time taken to load compressed bitmap .
sl@0
   177
*/
sl@0
   178
	SetTestStepID(_L("GRAPHICS-UI-BENCH-0058"));
sl@0
   179
	TestDecompressBitmapL(Kmbm16bppRleComprFileOnC, _L("Load-Compressed-Bitmap-16bit"));
sl@0
   180
	RecordTestResultL();
sl@0
   181
sl@0
   182
/**
sl@0
   183
@SYMTestCaseID
sl@0
   184
GRAPHICS-UI-BENCH-0059
sl@0
   185
sl@0
   186
@SYMTestCaseDesc
sl@0
   187
The test determines how long it takes to load 32 bpp compressed alpha bitmaps.
sl@0
   188
sl@0
   189
@SYMDEF DEF095361
sl@0
   190
sl@0
   191
@SYMTestPriority Low
sl@0
   192
sl@0
   193
@SYMTestActions
sl@0
   194
Compare the results over time.
sl@0
   195
sl@0
   196
@SYMTestExpectedResults
sl@0
   197
Test should pass and logs the time taken to load compressed bitmap .
sl@0
   198
*/
sl@0
   199
#ifdef _DEBUG
sl@0
   200
	//It uses Heap Allocation failure macro 
sl@0
   201
	//which is supported only for debug mode	
sl@0
   202
sl@0
   203
	SetTestStepID(_L("GRAPHICS-UI-BENCH-0059"));
sl@0
   204
	TestDecompressBitmapAltL(Kmbm32abppRleComprFileOnC, _L("Load-Compressed-Bitmap-32abit"));
sl@0
   205
	RecordTestResultL();
sl@0
   206
#endif
sl@0
   207
	SetTestStepID(_L("GRAPHICS-UI-BENCH-0076"));
sl@0
   208
	GetScanLineTestL();
sl@0
   209
	RecordTestResultL();
sl@0
   210
sl@0
   211
/**
sl@0
   212
@SYMTestCaseID
sl@0
   213
GRAPHICS-UI-BENCH-0085
sl@0
   214
sl@0
   215
@SYMTestCaseDesc
sl@0
   216
The test determines how long it takes to load a bitmap from the resource folder.
sl@0
   217
sl@0
   218
@SYMDEF DEF105049
sl@0
   219
sl@0
   220
@SYMTestPriority Medium
sl@0
   221
sl@0
   222
@SYMTestActions
sl@0
   223
Compare the results over time.
sl@0
   224
sl@0
   225
@SYMTestExpectedResults
sl@0
   226
Test should pass and display load time / bitmap.
sl@0
   227
*/
sl@0
   228
	SetTestStepID(_L("GRAPHICS-UI-BENCH-0085"));
sl@0
   229
	ResourceBitmapLoadL(KmbmResouceFile, 0, ETrue, _L("Resouce Bitmap Load"));
sl@0
   230
	RecordTestResultL();
sl@0
   231
sl@0
   232
	return TestStepResult();
sl@0
   233
	}
sl@0
   234
	
sl@0
   235
void CTOptimisedBmp::CompressedBitmapTestL()
sl@0
   236
	{
sl@0
   237
	_LIT(KTestName1, "CompressBitmap");
sl@0
   238
	_LIT(KTestName2, "BlitUncompressedBitmap");
sl@0
   239
	_LIT(KTestName3, "BlitCompressedBitmap");
sl@0
   240
	
sl@0
   241
	// strings for writing target output
sl@0
   242
	_LIT(KTargetString, "_TGT=");
sl@0
   243
	_LIT(KSourceString, "_SRC=");
sl@0
   244
sl@0
   245
	// for each of the files in the directory
sl@0
   246
	// load, compress & compare size before and after
sl@0
   247
	TBufC<KMaxFileName> fileName(KDirectoryFilesOnC);
sl@0
   248
	TInt dirLen = KDirectoryFilesOnC().Length();
sl@0
   249
	CDir* fileList;
sl@0
   250
	TInt err = iFs.GetDir(KDirectoryFilesOnC, KEntryAttNormal, ESortBySize, fileList);
sl@0
   251
	User::LeaveIfError(err);
sl@0
   252
	CleanupStack::PushL(fileList);
sl@0
   253
sl@0
   254
#ifdef FORCE_FOREGROUND_COMPRESSION
sl@0
   255
	_LIT(KForceForegroundCompression, "Force Foreground Compression");
sl@0
   256
	INFO_PRINTF2(KForceForegroundCompression);
sl@0
   257
	RFbsSession* fbs = RFbsSession::GetSession();
sl@0
   258
	if (!fbs)
sl@0
   259
		{
sl@0
   260
		ERR_PRINTF1("Error: fbs cannot be NULL");
sl@0
   261
		SetTestStepError();
sl@0
   262
		}		
sl@0
   263
	fbs->SendCommand(EFbsCompress, 1); // force to compress the bitmaps in the foreground
sl@0
   264
#endif // FORCE_FOREGROUND_COMPRESSION
sl@0
   265
sl@0
   266
sl@0
   267
sl@0
   268
	CFbsBitmap* fbsBitmap = new(ELeave) CFbsBitmap;
sl@0
   269
	CleanupStack::PushL(fbsBitmap);
sl@0
   270
	CFbsBitmap* fbsCompressed = new(ELeave) CFbsBitmap;
sl@0
   271
	CleanupStack::PushL(fbsCompressed);
sl@0
   272
sl@0
   273
	for (TInt dispModeIndex = 0; dispModeIndex < KNumValidDisplayModes; dispModeIndex++)
sl@0
   274
		{
sl@0
   275
		SetScreenModeL(KValidDisplayModes[dispModeIndex], ETrue);
sl@0
   276
		iGc->SetOrientation(CFbsBitGc::EGraphicsOrientationNormal);
sl@0
   277
		TSize scrSize = iScreenDevice->SizeInPixels();
sl@0
   278
		TPoint left(0 ,0);
sl@0
   279
		TPoint right(scrSize.iWidth / 2, 0);
sl@0
   280
		for (TInt ii = 0; ii < fileList->Count(); ++ii)
sl@0
   281
			{
sl@0
   282
			// Load uncompressed bitmap
sl@0
   283
			const TEntry entry((*fileList)[ii]);
sl@0
   284
			TPtr fnamePtr = fileName.Des();
sl@0
   285
			fnamePtr.SetLength(dirLen);
sl@0
   286
			fnamePtr.Append(entry.iName);
sl@0
   287
sl@0
   288
			err = fbsBitmap->Load(fnamePtr, 0, EFalse);
sl@0
   289
			if (err != KErrNone)
sl@0
   290
				{
sl@0
   291
				INFO_PRINTF3(_L("Error %d loading bitmap (%S)"), err, &fnamePtr);
sl@0
   292
				fbsBitmap->Reset();
sl@0
   293
				continue;
sl@0
   294
				}
sl@0
   295
sl@0
   296
			TDisplayMode bitmapDispMode = fbsBitmap->DisplayMode();  //same display mode used for fbsCompressed
sl@0
   297
			TDisplayMode screenDispMode = iScreenDevice->BitmapDevice().DisplayMode();
sl@0
   298
			TInt rpt;
sl@0
   299
sl@0
   300
			// Test speed of compressing an image
sl@0
   301
			iProfiler->InitResults();
sl@0
   302
			for (rpt = 0; rpt < KRepeatTestCount; ++rpt)
sl@0
   303
				{
sl@0
   304
				// Load bitmap to be compressed
sl@0
   305
				err = fbsCompressed->Load(fnamePtr, 0, EFalse);
sl@0
   306
				if (err != KErrNone)
sl@0
   307
					{
sl@0
   308
					INFO_PRINTF4(_L("Error %d loading the bitmap (%S), rpt = %d"), err, &fnamePtr, rpt);
sl@0
   309
					fbsCompressed->Reset();
sl@0
   310
					break;
sl@0
   311
					}
sl@0
   312
				iProfiler->StartTimer();
sl@0
   313
				fbsCompressed->Compress();
sl@0
   314
				iProfiler->MarkResultSetL();
sl@0
   315
				// on last iteration, don't reset fbsCompressed
sl@0
   316
				if (rpt < KRepeatTestCount-1)
sl@0
   317
					{
sl@0
   318
					fbsCompressed->Reset();
sl@0
   319
					}
sl@0
   320
				}
sl@0
   321
			iProfiler->ResultsAnalysis(KTestName1, CFbsBitGc::EGraphicsOrientationNormal, bitmapDispMode, screenDispMode, KRepeatTestCount);
sl@0
   322
sl@0
   323
			// Clip rect size to half-screen width and screen height
sl@0
   324
			TSize sizeInPixels = fbsBitmap->SizeInPixels();
sl@0
   325
			if (sizeInPixels.iWidth > scrSize.iWidth / 2)
sl@0
   326
				sizeInPixels.iWidth = scrSize.iWidth / 2;
sl@0
   327
			if (sizeInPixels.iHeight > scrSize.iHeight)
sl@0
   328
				sizeInPixels.iHeight = scrSize.iHeight;
sl@0
   329
			TRect blitRect(TPoint(0,0), sizeInPixels);
sl@0
   330
			TInt numPixels = sizeInPixels.iHeight * sizeInPixels.iWidth;
sl@0
   331
sl@0
   332
			// Test pixel rate of blitting uncompressed bitmap
sl@0
   333
			iProfiler->InitResults();
sl@0
   334
			for (rpt = 0; rpt < KRepeatTestCount; ++rpt)
sl@0
   335
				{
sl@0
   336
				iGc->BitBlt(left, fbsBitmap, blitRect);
sl@0
   337
				}
sl@0
   338
			iProfiler->MarkResultSetL();
sl@0
   339
			iProfiler->ResultsAnalysisPixelRate(KTestName2, CFbsBitGc::EGraphicsOrientationNormal, bitmapDispMode, screenDispMode, KRepeatTestCount, numPixels);
sl@0
   340
sl@0
   341
			// Test pixel rate of blitting compressed bitmap
sl@0
   342
			iProfiler->InitResults();
sl@0
   343
			for (rpt = 0; rpt < KRepeatTestCount; ++rpt)
sl@0
   344
				{
sl@0
   345
				iGc->BitBlt(right, fbsCompressed, blitRect);
sl@0
   346
				}
sl@0
   347
			iProfiler->MarkResultSetL();
sl@0
   348
			iProfiler->ResultsAnalysisPixelRate(KTestName3, CFbsBitGc::EGraphicsOrientationNormal, bitmapDispMode, screenDispMode, KRepeatTestCount, numPixels);
sl@0
   349
sl@0
   350
			// Sanity check that uncompressed and compressed bitmaps display the same
sl@0
   351
			CBitmapDevice& bmpDevice = iScreenDevice->BitmapDevice();
sl@0
   352
			if (iScreenDevice->isScreenDevice())
sl@0
   353
				{
sl@0
   354
				TEST(((CFbsScreenDevice&)bmpDevice).RectCompare(TRect(left, sizeInPixels), (CFbsScreenDevice&)bmpDevice, TRect(right, sizeInPixels)));
sl@0
   355
				}
sl@0
   356
			else
sl@0
   357
				{
sl@0
   358
				TEST(((CFbsBitmapDevice&)bmpDevice).RectCompare(TRect(left, sizeInPixels), (CFbsBitmapDevice&)bmpDevice, TRect(right, sizeInPixels)));
sl@0
   359
				}
sl@0
   360
			fbsBitmap->Reset();
sl@0
   361
			fbsCompressed->Reset();
sl@0
   362
sl@0
   363
			// Save offscreen bitmap to mbm file
sl@0
   364
			TBuf<KMaxFileName> testFileName;
sl@0
   365
			testFileName.Append(KTestName1);
sl@0
   366
			testFileName.Append(KTargetString);
sl@0
   367
			TBuf<10> string;
sl@0
   368
			string.Format(_L("%d"),screenDispMode);
sl@0
   369
			testFileName.Append(string);
sl@0
   370
			testFileName.Append(KSourceString);
sl@0
   371
			string.Format(_L("%d"),bitmapDispMode);
sl@0
   372
			testFileName.Append(string);
sl@0
   373
			WriteTargetOutput(testFileName);
sl@0
   374
			}
sl@0
   375
		}
sl@0
   376
sl@0
   377
	CleanupStack::PopAndDestroy(3, fileList); // fbsCompressed, fbsBitmap, fileList
sl@0
   378
	
sl@0
   379
#ifdef FORCE_FOREGROUND_COMPRESSION
sl@0
   380
	fbs->SendCommand(EFbsCompress, 0); // resume normal background compression
sl@0
   381
#endif // FORCE_FOREGROUND_COMPRESSION
sl@0
   382
	}
sl@0
   383
sl@0
   384
sl@0
   385
void CTOptimisedBmp::StripeBitmap(CFbsBitmap& aBitmap) // Compression friendly bitmap filling
sl@0
   386
	{
sl@0
   387
	TSize size = aBitmap.SizeInPixels();
sl@0
   388
	TInt dataLength = CFbsBitmap::ScanLineLength(size.iWidth,aBitmap.DisplayMode()) * size.iHeight;
sl@0
   389
sl@0
   390
	aBitmap.LockHeap();
sl@0
   391
	TUint8* bmpBits = (TUint8*)aBitmap.DataAddress();
sl@0
   392
	aBitmap.UnlockHeap();
sl@0
   393
	TUint8* bmpBitsLimit = bmpBits + dataLength;
sl@0
   394
	TInt64 seed = aBitmap.Handle();
sl@0
   395
sl@0
   396
	if (aBitmap.DisplayMode() != EColor4K)
sl@0
   397
		{
sl@0
   398
		while (bmpBits < bmpBitsLimit)
sl@0
   399
			{
sl@0
   400
			TUint8* tempBmpBitsLimit = Min(bmpBitsLimit, bmpBits + (TUint8)Math::Rand(seed));
sl@0
   401
			while (bmpBits < tempBmpBitsLimit)
sl@0
   402
				*bmpBits++ = 0;
sl@0
   403
			tempBmpBitsLimit = Min(bmpBitsLimit, bmpBits + (TUint8)Math::Rand(seed));
sl@0
   404
			while (bmpBits < tempBmpBitsLimit)
sl@0
   405
				*bmpBits++ = 0xff;
sl@0
   406
			}
sl@0
   407
		}
sl@0
   408
	else
sl@0
   409
		{
sl@0
   410
		Mem::FillZ(bmpBits,dataLength);
sl@0
   411
sl@0
   412
		while (bmpBits < bmpBitsLimit)
sl@0
   413
			{
sl@0
   414
			TUint8* tempBmpBitsLimit = Min(bmpBitsLimit, bmpBits + (TUint8)(Math::Rand(seed) * 2));
sl@0
   415
			while (bmpBits < tempBmpBitsLimit)
sl@0
   416
				{
sl@0
   417
				*bmpBits++ = 0;
sl@0
   418
				*bmpBits++ = 0;
sl@0
   419
				}
sl@0
   420
			tempBmpBitsLimit = Min(bmpBitsLimit, bmpBits + (TUint8)Math::Rand(seed));
sl@0
   421
			while (bmpBits < tempBmpBitsLimit)
sl@0
   422
				{
sl@0
   423
				*bmpBits++ = 0xff;
sl@0
   424
				*bmpBits++ = 0x0f;
sl@0
   425
				}
sl@0
   426
			}		
sl@0
   427
		}
sl@0
   428
	}
sl@0
   429
sl@0
   430
/**
sl@0
   431
Logs the time taken to load the bitmap file identified by the filename.
sl@0
   432
@param aFileName the mbm file that is to be loaded
sl@0
   433
@param aTestCaseName the name of the test case
sl@0
   434
*/
sl@0
   435
void CTOptimisedBmp::TestDecompressBitmapL(const TDesC& aFileName, const TDesC& aTestCaseName)
sl@0
   436
	{
sl@0
   437
	TInt err = KErrNone;
sl@0
   438
	iProfiler->InitResults(); //initializes the timer
sl@0
   439
	for (TInt rpt = 0; rpt < KRepeatTestCount; ++rpt)
sl@0
   440
		{
sl@0
   441
		CFbsBitmap* fbsCompressed = new (ELeave) CFbsBitmap;
sl@0
   442
		CleanupStack::PushL( fbsCompressed );
sl@0
   443
		
sl@0
   444
		//Load mbm file identified by aFileName
sl@0
   445
		err = fbsCompressed->Load( aFileName, 0, EFalse ); //when there is no memory constraints
sl@0
   446
		TEST(err == KErrNone);
sl@0
   447
sl@0
   448
		fbsCompressed->Reset();
sl@0
   449
		CleanupStack::PopAndDestroy( fbsCompressed );
sl@0
   450
		
sl@0
   451
		iProfiler->MarkResultSetL();
sl@0
   452
		} // rpt loop
sl@0
   453
	
sl@0
   454
	//Logs the time taken to load the bmp file	
sl@0
   455
	iProfiler->ResultsAnalysis(aTestCaseName, 0, 0, 0, KRepeatTestCount);
sl@0
   456
	}
sl@0
   457
sl@0
   458
#ifdef _DEBUG
sl@0
   459
/**
sl@0
   460
This test will only work correctly under UDEB builds of the OS.
sl@0
   461
It is same as CTOptimisedBmp::TestDecompressBitmapL function except that it also simulates the 
sl@0
   462
lack of memory use case while loading bitmap.
sl@0
   463
sl@0
   464
@param aFileName the mbm file that is to be loaded
sl@0
   465
@param aTestCaseName the name of the test case
sl@0
   466
*/
sl@0
   467
void CTOptimisedBmp::TestDecompressBitmapAltL(const TDesC& aFileName, const TDesC& aTestCaseName)
sl@0
   468
	{
sl@0
   469
	TInt err = KErrNone;
sl@0
   470
	RFbsSession* fbsSession = RFbsSession::GetSession();
sl@0
   471
	if (!fbsSession)
sl@0
   472
		{
sl@0
   473
		INFO_PRINTF1(_L("Error: fbs cannot be NULL"));
sl@0
   474
		ASSERT_NOT_NULL(fbsSession);
sl@0
   475
		}
sl@0
   476
	else
sl@0
   477
		{
sl@0
   478
		CFbsBitmap* fbsCompressed = new (ELeave) CFbsBitmap;
sl@0
   479
		CleanupStack::PushL( fbsCompressed );
sl@0
   480
		iProfiler->InitResults(); //initializes the timer
sl@0
   481
		for (TInt rpt = 0; rpt < KRepeatTestCount; ++rpt)
sl@0
   482
			{
sl@0
   483
			//Load mbm file identified by aFileName
sl@0
   484
			//Consider no memory case
sl@0
   485
			for (TInt count = 1; ; count++)
sl@0
   486
				{
sl@0
   487
				//Explicitly make the memory fails to check how will it loads bmp
sl@0
   488
				fbsSession->SendCommand(EFbsMessDefaultAllocFail,count);
sl@0
   489
				fbsSession->SendCommand(EFbsMessDefaultMark);
sl@0
   490
				fbsSession->SendCommand(EFbsMessUserMark);
sl@0
   491
sl@0
   492
				err = fbsCompressed->Load( aFileName, 0, EFalse );
sl@0
   493
sl@0
   494
				if (err == KErrNoMemory)
sl@0
   495
					{
sl@0
   496
					fbsSession->SendCommand(EFbsMessDefaultMarkEnd);
sl@0
   497
					fbsSession->SendCommand(EFbsMessUserMarkEnd);
sl@0
   498
					}
sl@0
   499
				else if (err == KErrNone)
sl@0
   500
					{
sl@0
   501
					fbsSession->SendCommand(EFbsMessUserMarkEnd);
sl@0
   502
					break;
sl@0
   503
					}
sl@0
   504
				}
sl@0
   505
			iProfiler->MarkResultSetL();
sl@0
   506
				fbsCompressed->Reset();
sl@0
   507
			} // rpt loop
sl@0
   508
sl@0
   509
		CleanupStack::PopAndDestroy( fbsCompressed );
sl@0
   510
		//Logs the time taken to load the bmp file	
sl@0
   511
		iProfiler->ResultsAnalysis(aTestCaseName, 0, 0, 0, KRepeatTestCount);
sl@0
   512
		}
sl@0
   513
	}
sl@0
   514
#endif
sl@0
   515
sl@0
   516
/**
sl@0
   517
@SYMTestCaseID
sl@0
   518
GRAPHICS-UI-BENCH-0076
sl@0
   519
sl@0
   520
@SYMDEF DEF105392
sl@0
   521
sl@0
   522
@SYMTestCaseDesc
sl@0
   523
Tests the performance of GetScanLine function for various display modes.
sl@0
   524
Also it tests the performance of various GetScanLineColorXX
sl@0
   525
(where XX => display mode, for eg. GetScanLineColor64K)
sl@0
   526
and TScanLineDecompressor::CopyPixel functions.
sl@0
   527
To test the performance of GetScanLineColorXX and other functions for any display mode, it creates
sl@0
   528
a bitmap of that display mode and passes it to CTOptimisedBmp::ScanlineTestL function
sl@0
   529
along with the display mode which was used for creating it and
sl@0
   530
the other display mode which will be used for reading this bitmap while logging the performance.
sl@0
   531
@SYMTestActions
sl@0
   532
Compare the results over time, and before and after changes to GetScanLine and CopyPixel code.
sl@0
   533
@SYMTestExpectedResults
sl@0
   534
Test should pass and display average time
sl@0
   535
*/
sl@0
   536
void CTOptimisedBmp::GetScanLineTestL()
sl@0
   537
	{
sl@0
   538
	CFbsBitmap bmp;
sl@0
   539
	const TSize bmpSize(22,5);
sl@0
   540
	_LIT(KTestCaseName,"GetScanLine");
sl@0
   541
	const TDisplayMode KTestDisplayModes[] = {EColor4K, EColor64K, EColor16M, EColor16MU, EColor16MA, EColor16MAP};
sl@0
   542
	const TInt KTestDisplayModeCnt = sizeof(KTestDisplayModes)/sizeof(TDisplayMode);
sl@0
   543
sl@0
   544
	for(TInt srcDispModeIndex = 0; srcDispModeIndex < KTestDisplayModeCnt; srcDispModeIndex++)
sl@0
   545
		{
sl@0
   546
		TDisplayMode displayMode = KTestDisplayModes[srcDispModeIndex];
sl@0
   547
		User::LeaveIfError(bmp.Create(bmpSize,displayMode));
sl@0
   548
		StripeBitmap(bmp);
sl@0
   549
		bmp.Compress();
sl@0
   550
		for(TInt destDispModeIndex = 0; destDispModeIndex < KTestDisplayModeCnt; destDispModeIndex++)
sl@0
   551
			{
sl@0
   552
			ScanlineTestL(bmp,displayMode,KTestDisplayModes[destDispModeIndex],KTestCaseName);
sl@0
   553
			}
sl@0
   554
		bmp.Reset();
sl@0
   555
		}
sl@0
   556
	}
sl@0
   557
sl@0
   558
/**
sl@0
   559
It reads a bitmap (aBitmap) of given display mode (aSrcDisplayMode) as a bitmap of
sl@0
   560
another display mode (aDestDisplayMode) and logs the performance for it.
sl@0
   561
@param aBitmap a bitmap
sl@0
   562
@param aSrcDisplayMode The used display mode when bitmap was created. 
sl@0
   563
						It is passed in this function just for logging purpose.
sl@0
   564
@param aDestDisplayMode The display mode used for reading the bitmap aBitmap
sl@0
   565
@param aTestCaseName The name of the test case
sl@0
   566
*/
sl@0
   567
void CTOptimisedBmp::ScanlineTestL(const CFbsBitmap& aBitmap, TDisplayMode aSrcDisplayMode, TDisplayMode aDestDisplayMode, const TDesC& aTestCaseName)
sl@0
   568
	{
sl@0
   569
	const TSize bmpSize(aBitmap.SizeInPixels());
sl@0
   570
	TInt byteWidth = CFbsBitmap::ScanLineLength(bmpSize.iWidth,aDestDisplayMode);
sl@0
   571
	TUint8* buffer = new (ELeave) TUint8[byteWidth];
sl@0
   572
	CleanupStack::PushL(buffer);
sl@0
   573
	TPtr8 scanLine(buffer,byteWidth,byteWidth);
sl@0
   574
sl@0
   575
	iProfiler->InitResults();
sl@0
   576
	for(TInt count=0;count<KRepeatTestCount;count++)
sl@0
   577
		{
sl@0
   578
		// For performance testing on same scanline, read the few pixels from bitmap.
sl@0
   579
		// And for a comprehensive testing, vary the start pixel and the number of pixels to get.
sl@0
   580
		for(TInt xStart = 0; xStart <= 11; xStart++)
sl@0
   581
			{
sl@0
   582
			for (TInt xLength = 1; xLength <= 11; xLength++)
sl@0
   583
				{
sl@0
   584
				TInt xEnd = xStart + xLength;
sl@0
   585
				if (xEnd <= bmpSize.iWidth)
sl@0
   586
					{
sl@0
   587
					aBitmap.GetScanLine(scanLine,TPoint(xStart,0),xLength,aDestDisplayMode);
sl@0
   588
					}
sl@0
   589
				}
sl@0
   590
			}
sl@0
   591
		// Test the performance of reading different scanlines.
sl@0
   592
		for(TInt yy = 0; yy < bmpSize.iHeight; yy++)
sl@0
   593
			{
sl@0
   594
			aBitmap.GetScanLine(scanLine,TPoint(0,yy),bmpSize.iWidth,aDestDisplayMode);
sl@0
   595
			}
sl@0
   596
sl@0
   597
		iProfiler->MarkResultSetL();
sl@0
   598
		}
sl@0
   599
sl@0
   600
	iProfiler->ResultsAnalysis(aTestCaseName, 0, aSrcDisplayMode, aDestDisplayMode, KRepeatTestCount);
sl@0
   601
sl@0
   602
	CleanupStack::PopAndDestroy(buffer);
sl@0
   603
	}
sl@0
   604
sl@0
   605
/**
sl@0
   606
Logs the time taken to load the bitmap file identified by the filename and file id.
sl@0
   607
@param aFileName the mbm or rsc file that is to be loaded
sl@0
   608
@param aId The bitmap identifier
sl@0
   609
@param aShareIfLoaded Specifies whether or not the loaded bitmap will be made available for sharing between font and bitmap server clients.
sl@0
   610
@param aTestCaseName the name of the test case
sl@0
   611
*/
sl@0
   612
void CTOptimisedBmp::ResourceBitmapLoadL(const TDesC& aFileName, TInt32 aId, TBool aShareIfLoaded, const TDesC& aTestCaseName)
sl@0
   613
	{
sl@0
   614
	TInt err = KErrNone;
sl@0
   615
	iProfiler->InitResults(); //initializes the timer
sl@0
   616
	for (TInt rpt = 0; rpt < KRepeatTestCount; ++rpt)
sl@0
   617
		{
sl@0
   618
		CFbsBitmap* resourceBitmap = new (ELeave) CFbsBitmap;
sl@0
   619
		CleanupStack::PushL(resourceBitmap);
sl@0
   620
		iProfiler->StartTimer();
sl@0
   621
		//Load mbm or rsc file identified by aFileName
sl@0
   622
		err = resourceBitmap->Load( aFileName, aId, aShareIfLoaded ); //when there is no memory constraints
sl@0
   623
		iProfiler->MarkResultSetL();
sl@0
   624
		TEST(err == KErrNone);
sl@0
   625
		resourceBitmap->Reset();
sl@0
   626
		CleanupStack::PopAndDestroy( resourceBitmap );
sl@0
   627
		}
sl@0
   628
	//Logs the time taken to load the bmp file
sl@0
   629
	iProfiler->ResultsAnalysis(aTestCaseName, 0, 0, 0, KRepeatTestCount);
sl@0
   630
	}