Update contrib.
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
19 @internalComponent - Internal Symbian test code
22 #include "toptimisedbmp.h"
23 #include "fbsmessage.h"
24 #include <test/tefunit.h>
27 // The following line must be disabled for testing with the background compression code
28 // When enabled foreground bitmap compression will take place.
29 // #define FORCE_FOREGROUND_COMPRESSION
31 // Number of times to repeat the tests
32 const TInt KRepeatTestCount = 100;
34 // The source bitmaps, only use the bitmaps from UIBENCH
35 _LIT( KmbmFilesInRom, "z:\\system\\data\\uibench_*.mbm" );
37 // The 16bit rle compressed source bitmap on Z drive
38 _LIT( Kmbm16bppRleComprFileInRom, "z:\\system\\data\\rlecompr_16bpp.mbm" );
40 // The 32bit alpha rle compressed source bitmap on Z drive
41 _LIT( Kmbm32abppRleComprFileInRom, "z:\\system\\data\\rlecompr_32abpp.mbm" );
43 // The 16bit rle compressed source bitmap on C drive
44 _LIT( Kmbm16bppRleComprFileOnC, "c:\\compressedBitmaps\\rlecompr_16bpp.mbm" );
47 // The 32bit alpha rle compressed source bitmap on C drive
48 _LIT( Kmbm32abppRleComprFileOnC, "c:\\compressedBitmaps\\rlecompr_32abpp.mbm" );
51 // The resouce mbm file
52 _LIT( KmbmResouceFile, "z:\\resource\\32bit20col.mbm" );
54 // The directory to copy the bitmaps to
55 _LIT( KDirectoryFilesOnC , "c:\\bitmapOptimisation\\" );
57 // The directory to copy the compressed bitmaps to
58 _LIT( KDirectoryComprBmpFilesOnC , "c:\\compressedBitmaps\\" );
60 CTOptimisedBmp::CTOptimisedBmp()
62 SetTestStepName(KTOptimisedBmpStep);
65 CTOptimisedBmp::~CTOptimisedBmp()
71 _LIT(KFormat, "%S*.mbm");
72 filePath.Format(KFormat, &KDirectoryFilesOnC);
73 iFileMan->Delete(filePath);
75 //remove filepath for compressed bitmap
76 filePath.Format(KFormat, &KDirectoryComprBmpFilesOnC);
77 iFileMan->Delete(filePath);
81 iFs.RmDir(KDirectoryFilesOnC);
83 //remove directory for compressed bitmap
84 iFs.RmDir(KDirectoryComprBmpFilesOnC);
89 Override of base class virtual
91 @return - TVerdict code
93 TVerdict CTOptimisedBmp::doTestStepPreambleL()
95 CTe_graphicsperformanceSuiteStepBase::doTestStepPreambleL();
97 // copy all of the files in ROM z: to c:
98 TInt err = iFs.Connect();
99 User::LeaveIfError(err);
100 iFs.ShareProtected();
101 err = iFs.MkDir(KDirectoryFilesOnC);
102 if (err != KErrNone && err != KErrAlreadyExists)
107 //create directory to store rle-compressed bitmap
108 err = iFs.MkDir(KDirectoryComprBmpFilesOnC);
109 if (err != KErrNone && err != KErrAlreadyExists)
114 iFileMan = CFileMan::NewL( iFs );
116 err = iFileMan->Copy( KmbmFilesInRom, KDirectoryFilesOnC );
117 TESTL(err == KErrNone);
119 //Copying compressed mbm files to C drive
120 err = iFileMan->Copy( Kmbm16bppRleComprFileInRom, KDirectoryComprBmpFilesOnC );
121 TESTL(err == KErrNone);
123 err = iFileMan->Copy( Kmbm32abppRleComprFileInRom, KDirectoryComprBmpFilesOnC );
124 TESTL(err == KErrNone);
126 return TestStepResult();
130 Override of base class pure virtual
131 Our implementation only gets called if the base class doTestStepPreambleL() did
132 not leave. That being the case, the current test result value will be EPass.
134 @return - TVerdict code
136 TVerdict CTOptimisedBmp::doTestStepL()
141 GRAPHICS-UI-BENCH-0021
144 The test determines how long it takes to compress bitmaps, and how long it takes to bitblt the original and the compressed bitmaps.
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.
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.
149 3. Over a number of iterations, measure time taken to blit the compressed bitmap loaded from step 1.
150 4. Check that the blits of the uncompressed bitmap and the compressed bitmap are the same.
152 Each of these steps is performed with various screen display modes and various display modes of the bitmap.
154 @SYMTestExpectedResults
155 Test should pass and display total and per bitmap compression, bitblt for uncompressed and compressed time.
157 SetTestStepID(_L("GRAPHICS-UI-BENCH-0021"));
158 CompressedBitmapTestL();
163 GRAPHICS-UI-BENCH-0058
166 The test determines how long it takes to load 16bpp compressed bitmaps.
170 @SYMTestPriority High
173 Compare the results over time.
175 @SYMTestExpectedResults
176 Test should pass and logs the time taken to load compressed bitmap .
178 SetTestStepID(_L("GRAPHICS-UI-BENCH-0058"));
179 TestDecompressBitmapL(Kmbm16bppRleComprFileOnC, _L("Load-Compressed-Bitmap-16bit"));
184 GRAPHICS-UI-BENCH-0059
187 The test determines how long it takes to load 32 bpp compressed alpha bitmaps.
194 Compare the results over time.
196 @SYMTestExpectedResults
197 Test should pass and logs the time taken to load compressed bitmap .
200 //It uses Heap Allocation failure macro
201 //which is supported only for debug mode
203 SetTestStepID(_L("GRAPHICS-UI-BENCH-0059"));
204 TestDecompressBitmapAltL(Kmbm32abppRleComprFileOnC, _L("Load-Compressed-Bitmap-32abit"));
207 SetTestStepID(_L("GRAPHICS-UI-BENCH-0076"));
213 GRAPHICS-UI-BENCH-0085
216 The test determines how long it takes to load a bitmap from the resource folder.
220 @SYMTestPriority Medium
223 Compare the results over time.
225 @SYMTestExpectedResults
226 Test should pass and display load time / bitmap.
228 SetTestStepID(_L("GRAPHICS-UI-BENCH-0085"));
229 ResourceBitmapLoadL(KmbmResouceFile, 0, ETrue, _L("Resouce Bitmap Load"));
232 return TestStepResult();
235 void CTOptimisedBmp::CompressedBitmapTestL()
237 _LIT(KTestName1, "CompressBitmap");
238 _LIT(KTestName2, "BlitUncompressedBitmap");
239 _LIT(KTestName3, "BlitCompressedBitmap");
241 // strings for writing target output
242 _LIT(KTargetString, "_TGT=");
243 _LIT(KSourceString, "_SRC=");
245 // for each of the files in the directory
246 // load, compress & compare size before and after
247 TBufC<KMaxFileName> fileName(KDirectoryFilesOnC);
248 TInt dirLen = KDirectoryFilesOnC().Length();
250 TInt err = iFs.GetDir(KDirectoryFilesOnC, KEntryAttNormal, ESortBySize, fileList);
251 User::LeaveIfError(err);
252 CleanupStack::PushL(fileList);
254 #ifdef FORCE_FOREGROUND_COMPRESSION
255 _LIT(KForceForegroundCompression, "Force Foreground Compression");
256 INFO_PRINTF2(KForceForegroundCompression);
257 RFbsSession* fbs = RFbsSession::GetSession();
260 ERR_PRINTF1("Error: fbs cannot be NULL");
263 fbs->SendCommand(EFbsCompress, 1); // force to compress the bitmaps in the foreground
264 #endif // FORCE_FOREGROUND_COMPRESSION
268 CFbsBitmap* fbsBitmap = new(ELeave) CFbsBitmap;
269 CleanupStack::PushL(fbsBitmap);
270 CFbsBitmap* fbsCompressed = new(ELeave) CFbsBitmap;
271 CleanupStack::PushL(fbsCompressed);
273 for (TInt dispModeIndex = 0; dispModeIndex < KNumValidDisplayModes; dispModeIndex++)
275 SetScreenModeL(KValidDisplayModes[dispModeIndex], ETrue);
276 iGc->SetOrientation(CFbsBitGc::EGraphicsOrientationNormal);
277 TSize scrSize = iScreenDevice->SizeInPixels();
279 TPoint right(scrSize.iWidth / 2, 0);
280 for (TInt ii = 0; ii < fileList->Count(); ++ii)
282 // Load uncompressed bitmap
283 const TEntry entry((*fileList)[ii]);
284 TPtr fnamePtr = fileName.Des();
285 fnamePtr.SetLength(dirLen);
286 fnamePtr.Append(entry.iName);
288 err = fbsBitmap->Load(fnamePtr, 0, EFalse);
291 INFO_PRINTF3(_L("Error %d loading bitmap (%S)"), err, &fnamePtr);
296 TDisplayMode bitmapDispMode = fbsBitmap->DisplayMode(); //same display mode used for fbsCompressed
297 TDisplayMode screenDispMode = iScreenDevice->BitmapDevice().DisplayMode();
300 // Test speed of compressing an image
301 iProfiler->InitResults();
302 for (rpt = 0; rpt < KRepeatTestCount; ++rpt)
304 // Load bitmap to be compressed
305 err = fbsCompressed->Load(fnamePtr, 0, EFalse);
308 INFO_PRINTF4(_L("Error %d loading the bitmap (%S), rpt = %d"), err, &fnamePtr, rpt);
309 fbsCompressed->Reset();
312 iProfiler->StartTimer();
313 fbsCompressed->Compress();
314 iProfiler->MarkResultSetL();
315 // on last iteration, don't reset fbsCompressed
316 if (rpt < KRepeatTestCount-1)
318 fbsCompressed->Reset();
321 iProfiler->ResultsAnalysis(KTestName1, CFbsBitGc::EGraphicsOrientationNormal, bitmapDispMode, screenDispMode, KRepeatTestCount);
323 // Clip rect size to half-screen width and screen height
324 TSize sizeInPixels = fbsBitmap->SizeInPixels();
325 if (sizeInPixels.iWidth > scrSize.iWidth / 2)
326 sizeInPixels.iWidth = scrSize.iWidth / 2;
327 if (sizeInPixels.iHeight > scrSize.iHeight)
328 sizeInPixels.iHeight = scrSize.iHeight;
329 TRect blitRect(TPoint(0,0), sizeInPixels);
330 TInt numPixels = sizeInPixels.iHeight * sizeInPixels.iWidth;
332 // Test pixel rate of blitting uncompressed bitmap
333 iProfiler->InitResults();
334 for (rpt = 0; rpt < KRepeatTestCount; ++rpt)
336 iGc->BitBlt(left, fbsBitmap, blitRect);
338 iProfiler->MarkResultSetL();
339 iProfiler->ResultsAnalysisPixelRate(KTestName2, CFbsBitGc::EGraphicsOrientationNormal, bitmapDispMode, screenDispMode, KRepeatTestCount, numPixels);
341 // Test pixel rate of blitting compressed bitmap
342 iProfiler->InitResults();
343 for (rpt = 0; rpt < KRepeatTestCount; ++rpt)
345 iGc->BitBlt(right, fbsCompressed, blitRect);
347 iProfiler->MarkResultSetL();
348 iProfiler->ResultsAnalysisPixelRate(KTestName3, CFbsBitGc::EGraphicsOrientationNormal, bitmapDispMode, screenDispMode, KRepeatTestCount, numPixels);
350 // Sanity check that uncompressed and compressed bitmaps display the same
351 CBitmapDevice& bmpDevice = iScreenDevice->BitmapDevice();
352 if (iScreenDevice->isScreenDevice())
354 TEST(((CFbsScreenDevice&)bmpDevice).RectCompare(TRect(left, sizeInPixels), (CFbsScreenDevice&)bmpDevice, TRect(right, sizeInPixels)));
358 TEST(((CFbsBitmapDevice&)bmpDevice).RectCompare(TRect(left, sizeInPixels), (CFbsBitmapDevice&)bmpDevice, TRect(right, sizeInPixels)));
361 fbsCompressed->Reset();
363 // Save offscreen bitmap to mbm file
364 TBuf<KMaxFileName> testFileName;
365 testFileName.Append(KTestName1);
366 testFileName.Append(KTargetString);
368 string.Format(_L("%d"),screenDispMode);
369 testFileName.Append(string);
370 testFileName.Append(KSourceString);
371 string.Format(_L("%d"),bitmapDispMode);
372 testFileName.Append(string);
373 WriteTargetOutput(testFileName);
377 CleanupStack::PopAndDestroy(3, fileList); // fbsCompressed, fbsBitmap, fileList
379 #ifdef FORCE_FOREGROUND_COMPRESSION
380 fbs->SendCommand(EFbsCompress, 0); // resume normal background compression
381 #endif // FORCE_FOREGROUND_COMPRESSION
385 void CTOptimisedBmp::StripeBitmap(CFbsBitmap& aBitmap) // Compression friendly bitmap filling
387 TSize size = aBitmap.SizeInPixels();
388 TInt dataLength = CFbsBitmap::ScanLineLength(size.iWidth,aBitmap.DisplayMode()) * size.iHeight;
391 TUint8* bmpBits = (TUint8*)aBitmap.DataAddress();
392 aBitmap.UnlockHeap();
393 TUint8* bmpBitsLimit = bmpBits + dataLength;
394 TInt64 seed = aBitmap.Handle();
396 if (aBitmap.DisplayMode() != EColor4K)
398 while (bmpBits < bmpBitsLimit)
400 TUint8* tempBmpBitsLimit = Min(bmpBitsLimit, bmpBits + (TUint8)Math::Rand(seed));
401 while (bmpBits < tempBmpBitsLimit)
403 tempBmpBitsLimit = Min(bmpBitsLimit, bmpBits + (TUint8)Math::Rand(seed));
404 while (bmpBits < tempBmpBitsLimit)
410 Mem::FillZ(bmpBits,dataLength);
412 while (bmpBits < bmpBitsLimit)
414 TUint8* tempBmpBitsLimit = Min(bmpBitsLimit, bmpBits + (TUint8)(Math::Rand(seed) * 2));
415 while (bmpBits < tempBmpBitsLimit)
420 tempBmpBitsLimit = Min(bmpBitsLimit, bmpBits + (TUint8)Math::Rand(seed));
421 while (bmpBits < tempBmpBitsLimit)
431 Logs the time taken to load the bitmap file identified by the filename.
432 @param aFileName the mbm file that is to be loaded
433 @param aTestCaseName the name of the test case
435 void CTOptimisedBmp::TestDecompressBitmapL(const TDesC& aFileName, const TDesC& aTestCaseName)
438 iProfiler->InitResults(); //initializes the timer
439 for (TInt rpt = 0; rpt < KRepeatTestCount; ++rpt)
441 CFbsBitmap* fbsCompressed = new (ELeave) CFbsBitmap;
442 CleanupStack::PushL( fbsCompressed );
444 //Load mbm file identified by aFileName
445 err = fbsCompressed->Load( aFileName, 0, EFalse ); //when there is no memory constraints
446 TEST(err == KErrNone);
448 fbsCompressed->Reset();
449 CleanupStack::PopAndDestroy( fbsCompressed );
451 iProfiler->MarkResultSetL();
454 //Logs the time taken to load the bmp file
455 iProfiler->ResultsAnalysis(aTestCaseName, 0, 0, 0, KRepeatTestCount);
460 This test will only work correctly under UDEB builds of the OS.
461 It is same as CTOptimisedBmp::TestDecompressBitmapL function except that it also simulates the
462 lack of memory use case while loading bitmap.
464 @param aFileName the mbm file that is to be loaded
465 @param aTestCaseName the name of the test case
467 void CTOptimisedBmp::TestDecompressBitmapAltL(const TDesC& aFileName, const TDesC& aTestCaseName)
470 RFbsSession* fbsSession = RFbsSession::GetSession();
473 INFO_PRINTF1(_L("Error: fbs cannot be NULL"));
474 ASSERT_NOT_NULL(fbsSession);
478 CFbsBitmap* fbsCompressed = new (ELeave) CFbsBitmap;
479 CleanupStack::PushL( fbsCompressed );
480 iProfiler->InitResults(); //initializes the timer
481 for (TInt rpt = 0; rpt < KRepeatTestCount; ++rpt)
483 //Load mbm file identified by aFileName
484 //Consider no memory case
485 for (TInt count = 1; ; count++)
487 //Explicitly make the memory fails to check how will it loads bmp
488 fbsSession->SendCommand(EFbsMessDefaultAllocFail,count);
489 fbsSession->SendCommand(EFbsMessDefaultMark);
490 fbsSession->SendCommand(EFbsMessUserMark);
492 err = fbsCompressed->Load( aFileName, 0, EFalse );
494 if (err == KErrNoMemory)
496 fbsSession->SendCommand(EFbsMessDefaultMarkEnd);
497 fbsSession->SendCommand(EFbsMessUserMarkEnd);
499 else if (err == KErrNone)
501 fbsSession->SendCommand(EFbsMessUserMarkEnd);
505 iProfiler->MarkResultSetL();
506 fbsCompressed->Reset();
509 CleanupStack::PopAndDestroy( fbsCompressed );
510 //Logs the time taken to load the bmp file
511 iProfiler->ResultsAnalysis(aTestCaseName, 0, 0, 0, KRepeatTestCount);
518 GRAPHICS-UI-BENCH-0076
523 Tests the performance of GetScanLine function for various display modes.
524 Also it tests the performance of various GetScanLineColorXX
525 (where XX => display mode, for eg. GetScanLineColor64K)
526 and TScanLineDecompressor::CopyPixel functions.
527 To test the performance of GetScanLineColorXX and other functions for any display mode, it creates
528 a bitmap of that display mode and passes it to CTOptimisedBmp::ScanlineTestL function
529 along with the display mode which was used for creating it and
530 the other display mode which will be used for reading this bitmap while logging the performance.
532 Compare the results over time, and before and after changes to GetScanLine and CopyPixel code.
533 @SYMTestExpectedResults
534 Test should pass and display average time
536 void CTOptimisedBmp::GetScanLineTestL()
539 const TSize bmpSize(22,5);
540 _LIT(KTestCaseName,"GetScanLine");
541 const TDisplayMode KTestDisplayModes[] = {EColor4K, EColor64K, EColor16M, EColor16MU, EColor16MA, EColor16MAP};
542 const TInt KTestDisplayModeCnt = sizeof(KTestDisplayModes)/sizeof(TDisplayMode);
544 for(TInt srcDispModeIndex = 0; srcDispModeIndex < KTestDisplayModeCnt; srcDispModeIndex++)
546 TDisplayMode displayMode = KTestDisplayModes[srcDispModeIndex];
547 User::LeaveIfError(bmp.Create(bmpSize,displayMode));
550 for(TInt destDispModeIndex = 0; destDispModeIndex < KTestDisplayModeCnt; destDispModeIndex++)
552 ScanlineTestL(bmp,displayMode,KTestDisplayModes[destDispModeIndex],KTestCaseName);
559 It reads a bitmap (aBitmap) of given display mode (aSrcDisplayMode) as a bitmap of
560 another display mode (aDestDisplayMode) and logs the performance for it.
561 @param aBitmap a bitmap
562 @param aSrcDisplayMode The used display mode when bitmap was created.
563 It is passed in this function just for logging purpose.
564 @param aDestDisplayMode The display mode used for reading the bitmap aBitmap
565 @param aTestCaseName The name of the test case
567 void CTOptimisedBmp::ScanlineTestL(const CFbsBitmap& aBitmap, TDisplayMode aSrcDisplayMode, TDisplayMode aDestDisplayMode, const TDesC& aTestCaseName)
569 const TSize bmpSize(aBitmap.SizeInPixels());
570 TInt byteWidth = CFbsBitmap::ScanLineLength(bmpSize.iWidth,aDestDisplayMode);
571 TUint8* buffer = new (ELeave) TUint8[byteWidth];
572 CleanupStack::PushL(buffer);
573 TPtr8 scanLine(buffer,byteWidth,byteWidth);
575 iProfiler->InitResults();
576 for(TInt count=0;count<KRepeatTestCount;count++)
578 // For performance testing on same scanline, read the few pixels from bitmap.
579 // And for a comprehensive testing, vary the start pixel and the number of pixels to get.
580 for(TInt xStart = 0; xStart <= 11; xStart++)
582 for (TInt xLength = 1; xLength <= 11; xLength++)
584 TInt xEnd = xStart + xLength;
585 if (xEnd <= bmpSize.iWidth)
587 aBitmap.GetScanLine(scanLine,TPoint(xStart,0),xLength,aDestDisplayMode);
591 // Test the performance of reading different scanlines.
592 for(TInt yy = 0; yy < bmpSize.iHeight; yy++)
594 aBitmap.GetScanLine(scanLine,TPoint(0,yy),bmpSize.iWidth,aDestDisplayMode);
597 iProfiler->MarkResultSetL();
600 iProfiler->ResultsAnalysis(aTestCaseName, 0, aSrcDisplayMode, aDestDisplayMode, KRepeatTestCount);
602 CleanupStack::PopAndDestroy(buffer);
606 Logs the time taken to load the bitmap file identified by the filename and file id.
607 @param aFileName the mbm or rsc file that is to be loaded
608 @param aId The bitmap identifier
609 @param aShareIfLoaded Specifies whether or not the loaded bitmap will be made available for sharing between font and bitmap server clients.
610 @param aTestCaseName the name of the test case
612 void CTOptimisedBmp::ResourceBitmapLoadL(const TDesC& aFileName, TInt32 aId, TBool aShareIfLoaded, const TDesC& aTestCaseName)
615 iProfiler->InitResults(); //initializes the timer
616 for (TInt rpt = 0; rpt < KRepeatTestCount; ++rpt)
618 CFbsBitmap* resourceBitmap = new (ELeave) CFbsBitmap;
619 CleanupStack::PushL(resourceBitmap);
620 iProfiler->StartTimer();
621 //Load mbm or rsc file identified by aFileName
622 err = resourceBitmap->Load( aFileName, aId, aShareIfLoaded ); //when there is no memory constraints
623 iProfiler->MarkResultSetL();
624 TEST(err == KErrNone);
625 resourceBitmap->Reset();
626 CleanupStack::PopAndDestroy( resourceBitmap );
628 //Logs the time taken to load the bmp file
629 iProfiler->ResultsAnalysis(aTestCaseName, 0, 0, 0, KRepeatTestCount);