First public contribution.
1 // Copyright (c) 2007-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 "tbitbltperf_directgdi.h"
23 #include <graphics/directgdidriver.h>
24 #include <graphics/directgdidrawablesource.h>
25 #include <bitdrawinterfaceid.h>
26 #include <bmalphablend.h>
29 #ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
30 _LIT(KBitmap12bit, "z:\\system\\data\\uibench_12bit.mbm");
31 _LIT(KBitmap16bit, "z:\\system\\data\\uibench_16bit.mbm");
32 _LIT(KBitmap24bit, "z:\\system\\data\\uibench_24bit.mbm");
33 _LIT(KBitmap32bit, "z:\\system\\data\\uibench_32bit.mbm");
34 _LIT(KBitmapTile, "z:\\system\\data\\uibench_tile.mbm");
37 #ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
38 const TInt KIterationsToTest = 5; // Number of iterations to run tests
40 const TInt KMaxPixelFormats = 30; // Number of bitmaps/tiles to create
42 // For many of these tests, the size of which the destination blit is cropped to.
43 const TRect KCropTo = TRect(0,0,200,200);
45 CTBitBltPerfDirectGdi::~CTBitBltPerfDirectGdi()
49 CTBitBltPerfDirectGdi::CTBitBltPerfDirectGdi()
50 :iBitmapImage(KMaxPixelFormats),
51 iBitmapTile(KMaxPixelFormats)
53 SetTestStepName(KTBitBltPerfDirectGdi);
56 #ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
58 Override of base class virtual
60 @return - TVerdict code
62 TVerdict CTBitBltPerfDirectGdi::doTestStepPreambleL()
64 CTDirectGdiTestBase::doTestStepPreambleL();
66 // Create a CFbsBitmap image for each source mode we are testing.
67 for (TInt srcMode = 0; srcMode < iSourcePixelFormatArray.Count(); ++srcMode)
69 TDisplayMode bitmapDisplayMode = TDisplayModeMapping::MapPixelFormatToDisplayMode(iSourcePixelFormatArray[srcMode]);
71 CFbsBitmap* bitmapImage = NULL;
72 switch(bitmapDisplayMode)
76 bitmapImage = LoadBitmapL(KBitmap12bit, 0);
79 bitmapImage = LoadBitmapL(KBitmap16bit, 0);
82 bitmapImage = LoadBitmapL(KBitmap24bit, 0);
85 bitmapImage = LoadBitmapL(KBitmap32bit, 0);
88 if (bitmapImage && bitmapImage->DisplayMode() != bitmapDisplayMode)
90 CleanupStack::PushL(bitmapImage);
91 CFbsBitmap* tempBitmap = CopyIntoNewBitmapL(bitmapImage, bitmapDisplayMode);
92 CleanupStack::PopAndDestroy(1, bitmapImage); //bitmapImage
93 bitmapImage = tempBitmap;
95 iBitmapImage.AppendL(bitmapImage);
98 // Create 8bit alpha bitmap
99 CFbsBitmap* tempBitmap = LoadBitmapL(KBitmap12bit, 0);
100 CleanupStack::PushL(tempBitmap);
101 iAlpha8bit = CopyIntoNewBitmapL(tempBitmap, EGray256);
102 CleanupStack::PopAndDestroy(tempBitmap); // tempBitmap
104 // Create CFbsBitmaps for the tile images of various pixel formats.
105 // The first entry in the array is always the default pixelformat loaded from the mbm.
106 // Then in the rest of the array are bitmaps converted to the source pixel formats.
107 CFbsBitmap* tile = LoadBitmapL(KBitmapTile, 0);
108 iBitmapTile.AppendL(tile);
109 for (TInt srcMode = 0; srcMode < iSourcePixelFormatArray.Count(); ++srcMode)
111 TDisplayMode bitmapDisplayMode = TDisplayModeMapping::MapPixelFormatToDisplayMode(iSourcePixelFormatArray[srcMode]);
112 CFbsBitmap* tileCopy = CopyIntoNewBitmapL(tile, bitmapDisplayMode);
113 iBitmapTile.AppendL(tileCopy);
116 return TestStepResult();
120 Override of base class virtual
122 @return - TVerdict code
124 TVerdict CTBitBltPerfDirectGdi::doTestStepPostambleL()
129 for (TInt ii = iBitmapImage.Count() - 1; ii >= 0; --ii)
131 delete iBitmapImage[ii];
133 iBitmapImage.Close();
135 for (TInt ii = iBitmapTile.Count() - 1; ii >= 0; --ii)
137 delete iBitmapTile[ii];
141 return CTDirectGdiTestBase::doTestStepPostambleL();
145 Override of base class pure virtual
146 Our implementation only gets called if the base class doTestStepPreambleL() did
147 not leave. That being the case, the current test result value will be EPass.
149 @return - TVerdict code
151 TVerdict CTBitBltPerfDirectGdi::doTestStepL()
153 #ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
154 INFO_PRINTF1(_L("CTBitBltPerfDirectGdi can only be run with RSgImage legacy"));
155 return TestStepResult();
157 // for each display mode
158 for(TInt dispModeIndex = 0; dispModeIndex < iTargetPixelFormatArray.Count(); ++dispModeIndex)
160 TDisplayMode targetDisplayMode = TDisplayModeMapping::MapPixelFormatToDisplayMode(iTargetPixelFormatArray[dispModeIndex]);
161 if(SetTargetPixelFormatL(targetDisplayMode))
163 SetTestStepID(_L("GRAPHICS-UI-BENCH-0150"));
166 SetTestStepID(_L("GRAPHICS-UI-BENCH-0151"));
169 SetTestStepID(_L("GRAPHICS-UI-BENCH-0153"));
170 MaskedBitBltAlphaL();
172 SetTestStepID(_L("GRAPHICS-UI-BENCH-0154"));
175 SetTestStepID(_L("GRAPHICS-UI-BENCH-0155"));
178 SetTestStepID(_L("GRAPHICS-UI-BENCH-0156"));
181 SetTestStepID(_L("GRAPHICS-UI-BENCH-0136"));
182 MaskedDrawBitmapScaledL();
184 SetTestStepID(_L("GRAPHICS-UI-BENCH-0157"));
187 SetTestStepID(_L("GRAPHICS-UI-BENCH-0158"));
188 SimpleDrawResourceL();
193 CloseTMSGraphicsStep();
194 return TestStepResult();
198 #ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
201 GRAPHICS-UI-BENCH-0150
209 Measure the performance of BitBlt() for the current screen mode and for various bitmap pixel formats.
212 Draw an entire bitmap using BitBlt(), with no overlapping or clipping.
213 Measure the time taken.
215 @SYMTestExpectedResults
216 The performance to be logged as a pixel rate, per bitmap.
218 void CTBitBltPerfDirectGdi::SimpleBitBltL()
220 INFO_PRINTF1(_L("CTBitBltPerfDirectGdi::SimpleBitBlt"));
222 _LIT(KTestName, "DirectGdiBitBlt");
223 for (TInt source = 0; source < iBitmapImage.Count(); ++source)
225 BitBltBitmapTestL(EBitBlt, iBitmapImage[source], NULL, KCropTo, KTestName, iContext);
231 GRAPHICS-UI-BENCH-0151
239 Measures the performance of DrawBitmap() for the current screen mode, for various bitmap pixel formats.
240 The bitmap is drawn without scaling.
243 Create a copy of the bitmap, and scale to the required size, prior to running the test.
244 For each required source pixel format, use DrawBitmap() to tile a bitmap across the target, avoiding any
247 @SYMTestExpectedResults
248 The performance to be logged as a pixel rate, per bitmap.
250 void CTBitBltPerfDirectGdi::SimpleDrawBitmapL()
252 INFO_PRINTF1(_L("CTBitBltPerfDirectGdi::SimpleDrawBitmap"));
254 _LIT(KTestName, "DirectGdiDrawBitmap");
256 for (TInt source = 0; source < iBitmapImage.Count(); ++source)
258 // Use a bitmap that needs no scaling.
259 CFbsBitmap* bitmapBitBltImage = CopyIntoNewBitmapL(iBitmapImage[source], iBitmapImage[source]->DisplayMode());
260 CleanupStack::PushL(bitmapBitBltImage);
261 bitmapBitBltImage->Resize(KCropTo.Size());
262 BitBltBitmapTestL(EDrawBitmap, bitmapBitBltImage, NULL, bitmapBitBltImage->SizeInPixels(), KTestName, iContext);
263 CleanupStack::PopAndDestroy(1, bitmapBitBltImage);
269 GRAPHICS-UI-BENCH-0155
277 Measure the performance of BitBltMasked() for the current screen mode, using bitmaps of various
281 Call BitBltMasked() with a bitmap for various pixel formats of bitmap, using the same bitmap
282 as the mask bitmap each time. The bitmap is tiled across the target to avoid overlapping or clipping.
284 @SYMTestExpectedResults
285 The performance to be logged as a pixel rate, per bitmap.
287 void CTBitBltPerfDirectGdi::MaskedBitBltL()
289 INFO_PRINTF1(_L("CTBitBltPerfDirectGdi::MaskedBitBlt"));
291 _LIT(KTestName, "DirectGdiMBitBlt");
293 // for each display mode
294 for (TInt source = 0; source < iBitmapImage.Count(); ++source)
296 BitBltBitmapTestL(EBitBltMasked, iBitmapImage[source], iBitmapTile[0], KCropTo, KTestName, iContext);
302 GRAPHICS-UI-BENCH-0154
310 Measure the performance of BitBlt(), using the same bitmap as a mask with different screen modes.
313 Call BitBltMasked() with a bitmap for various pixel formats of bitmap, using the bitmap
314 as the mask bitmap each time. The bitmap is tiled across the target to avoid overlapping or clipping.
316 @SYMTestExpectedResults
317 The performance to be logged as a pixel rate, per bitmap.
319 void CTBitBltPerfDirectGdi::MaskedBitBltSameL()
321 INFO_PRINTF1(_L("CTBitBltPerfDirectGdi::MaskedBitBltSame"));
323 _LIT(KTestName, "DirectGdiMBitBltS");
325 for (TInt tile = 0; tile < iBitmapTile.Count(); ++tile)
327 BitBltBitmapTestL(EBitBltMasked, iBitmapTile[tile], iBitmapTile[tile], KCropTo, KTestName, iContext);
334 GRAPHICS-UI-BENCH-0153
342 Measure the performance of BitBltMasked(), with an alpha bitmap with different screen modes.
345 Call BitBltMasked() with a bitmap for various pixel formats of bitmap, using the same alpha bitmap
346 as the mask bitmap each time. The bitmap is tiled across the target to avoid overlapping or clipping.
348 @SYMTestExpectedResults
349 The performance to be logged as a pixel rate, per bitmap.
351 void CTBitBltPerfDirectGdi::MaskedBitBltAlphaL()
353 INFO_PRINTF1(_L("CTBitBltPerfDirectGdi::MaskedBitBltAlpha"));
355 _LIT(KTestName, "DirectGdiMBitBltA");
357 for (TInt source = 0; source < iBitmapImage.Count(); ++source)
359 BitBltBitmapTestL(EBitBltMasked, iBitmapImage[source], iAlpha8bit, KCropTo, KTestName, iContext);
365 GRAPHICS-UI-BENCH-0157
373 Measure the performance of BitBlt() for the current screen mode and for various bitmap pixel formats,
374 with a bitmap that is accessed by the CPU via DataAddresss(), and is therefore never cached by DirectGDI.
377 Create a copy of a test bitmap.
378 Call DataAddress() on the bitmap.
379 Draw an entire bitmap using BitBlt(), with no overlapping or clipping.
380 Measure the time taken.
382 @SYMTestExpectedResults
383 The performance to be logged as a pixel rate, per bitmap.
385 void CTBitBltPerfDirectGdi::BitBltCpuAccessL()
387 INFO_PRINTF1(_L("CTBitBltPerfDirectGdi::BitBltCpuAccess"));
389 _LIT(KTestName, "DirectGdiBitBltCpuAccess");
391 for (TInt source = 0; source < iBitmapImage.Count(); ++source)
393 CFbsBitmap* bitmapBitBltImage = CopyIntoNewBitmapL(iBitmapImage[source], iBitmapImage[source]->DisplayMode());
394 TESTL(bitmapBitBltImage != NULL);
395 CleanupStack::PushL(bitmapBitBltImage);
396 bitmapBitBltImage->DataAddress(); // CPU Access so that it is not cached by DirectGDI.
397 BitBltBitmapTestL(EBitBlt, bitmapBitBltImage, NULL, KCropTo, KTestName, iContext);
398 CleanupStack::PopAndDestroy(1, bitmapBitBltImage);
404 GRAPHICS-UI-BENCH-0158
412 Measure the performance of DrawResource() for the current screen mode and for various bitmap pixel formats,
416 Draw an entire bitmap using DrawResource(), by tiling the image across the target to avoid overlapping and
417 clipping. Measure the time taken.
419 @SYMTestExpectedResults
420 The performance to be logged as a pixel rate, per bitmap.
422 void CTBitBltPerfDirectGdi::SimpleDrawResourceL()
424 INFO_PRINTF1(_L("CTBitBltPerfDirectGdi::SimpleDrawResource"));
425 _LIT(KTestName, "DirectGdiDrawResource");
427 for (TInt source = 0; source < iBitmapImage.Count(); ++source)
429 TSgImageInfo imageInfo;
430 imageInfo.iSizeInPixels = iBitmapImage[source]->SizeInPixels();
431 imageInfo.iPixelFormat = TDisplayModeMapping::MapDisplayModeToPixelFormat(iBitmapImage[source]->DisplayMode());
432 imageInfo.iUsage = ESgUsageDirectGdiSource;
434 // Create an RSgImage from the CFbsBitmap.
436 TInt res = sgImage.Create(imageInfo, iBitmapImage[source]->DataAddress(), iBitmapImage[source]->DataStride());
438 CleanupClosePushL(sgImage);
440 CDirectGdiDriver* drv = CDirectGdiDriver::Static();
443 RDirectGdiDrawableSource* imageSrc = new RDirectGdiDrawableSource(*drv);
444 TEST(imageSrc != NULL);
445 res = imageSrc->Create(sgImage);
449 // Tile across the target, and avoid clipping and overlapping of tiles.
450 const TSize targetSize = GetPixmapSizeInPixels();
451 const TSize tileSize = imageInfo.iSizeInPixels;
452 const TInt tileColumns = targetSize.iWidth / tileSize.iWidth;
453 const TInt tileRows = targetSize.iHeight / tileSize.iHeight;
454 const TInt numTiles = tileColumns * tileRows;
455 const TInt numPixelsPerIteration = numTiles * tileSize.iWidth * tileSize.iHeight;
456 iProfiler->InitResults();
457 for(TInt count=KIterationsToTest; count>0; --count)
459 TPoint bitmapPosition = TPoint(0,0);
460 for (TInt tile = numTiles - 1; tile >= 0; --tile)
462 iContext->DrawResource(bitmapPosition, *imageSrc, DirectGdi::EGraphicsRotationNone);
463 bitmapPosition.iX += tileSize.iWidth;
464 if (bitmapPosition.iX + tileSize.iWidth > targetSize.iWidth)
466 bitmapPosition.iX = 0;
467 bitmapPosition.iY += tileSize.iHeight;
470 iDGdiDriver->Finish();
472 iProfiler->MarkResultSetL();
473 TESTNOERRORL(iDGdiDriver->GetError());
475 WriteTargetOutput(KTestName());
476 const TDisplayMode targetDisplayMode = TDisplayModeMapping::MapPixelFormatToDisplayMode(iImageInfo.iPixelFormat);
477 iProfiler->ResultsAnalysisPixelRate(KTestName, CFbsBitGc::EGraphicsOrientationNormal, iBitmapImage[source]->DisplayMode(), targetDisplayMode, KIterationsToTest, numPixelsPerIteration);
481 CleanupStack::PopAndDestroy(1, &sgImage);
488 GRAPHICS-UI-BENCH-0156
496 Measure the performance of DrawBitmapMasked() for the current screen mode, using bitmaps of various
500 Call DrawBitmapMasked() with a bitmap for various pixel formats of bitmap, using the same bitmap
501 as the mask bitmap each time. The bitmap is tiled across the target to avoid overlapping or clipping.
503 @SYMTestExpectedResults
504 The performance to be logged as a pixel rate, per bitmap.
506 void CTBitBltPerfDirectGdi::MaskedDrawBitmapL()
508 INFO_PRINTF1(_L("CTBitBltPerfDirectGdi::MaskedDrawBitmap"));
510 _LIT(KTestName, "DirectGdiDrawBitmapM");
512 // for each display mode
513 for (TInt source = 0; source < iBitmapImage.Count(); ++source)
515 BitBltBitmapTestL(EDrawBitmapMasked, iBitmapImage[source], iBitmapTile[0], KCropTo, KTestName, iContext, EFalse);
521 GRAPHICS-UI-BENCH-0136
529 Measure the performance of DrawBitmapMasked() for the current screen mode, using bitmaps of various
533 Call DrawBitmapMasked() with a bitmap for various pixel formats of bitmap, using the same bitmap
534 as the mask bitmap each time. The bitmap is tiled across the target to avoid overlapping or clipping.
536 @SYMTestExpectedResults
537 The performance to be logged as a pixel rate, per bitmap.
539 void CTBitBltPerfDirectGdi::MaskedDrawBitmapScaledL()
541 INFO_PRINTF1(_L("CTBitBltPerfDirectGdi::MaskedDrawBitmapScaled"));
543 _LIT(KTestName, "DirectGdiDrawBitmapMS");
545 // for each display mode
546 for (TInt source = 0; source < iBitmapImage.Count(); ++source)
548 BitBltBitmapTestL(EDrawBitmapMasked, iBitmapImage[source], iBitmapTile[0], KCropTo, KTestName, iContext, ETrue);
554 Helper function to test bitblt bitmaps for different types of blitting. The bitmap is
555 tiled across the target to avoid any overdraw. Once the target is filled, the process
556 is performed for @c KIterationsToTest times.
558 @param aBitBltTest the bitblt test to carry out
559 @param aBitmapToBlt the bitmap to bitblt
560 @param aBitmapMask the bitmap mask
561 @param aCrop rectangle to crop bitblt to
562 @param aOrientation the orientation of the display
563 @param aTestName the name of the test
564 @param aGc the graphics context to bitblt to
566 void CTBitBltPerfDirectGdi::BitBltBitmapTestL(TBitBltTest aBitBltTest, CFbsBitmap* aBitmapToBlt, CFbsBitmap* aBitmapMask, TRect aCropTo, const TDesC& aTestName, CDirectGdiContext* aGc, TBool aScaled)
569 iDGdiDriver->Finish();
570 const TSize targetSize = GetPixmapSizeInPixels();
572 const TInt scalingFactor = aScaled ? 2 : 1;
573 // Calculate the number of tiles that will fit fully on the pixmap
574 const TSize tileSize = TSize(aCropTo.Width()/scalingFactor, aCropTo.Height()/scalingFactor);
575 const TInt tileColumns = targetSize.iWidth / tileSize.iWidth;
576 const TInt tileRows = targetSize.iHeight / tileSize.iHeight;
577 const TInt numTiles = tileColumns * tileRows;
578 const TInt numPixelsPerIteration = numTiles * tileSize.iWidth * tileSize.iHeight;
584 // Do a draw outside the loop so that we aren't measuring the time to load and cache the bitmap.
585 aGc->DrawBitmap(TRect(0, 0, tileSize.iWidth, tileSize.iHeight), *aBitmapToBlt);
586 iProfiler->InitResults();
587 for(TInt count=KIterationsToTest; count>0; --count)
589 TPoint bitmapPosition = TPoint(0,0);
590 for (TInt tile = numTiles - 1; tile >= 0; --tile)
592 aGc->DrawBitmap(TRect(bitmapPosition.iX, bitmapPosition.iY, bitmapPosition.iX+tileSize.iWidth, bitmapPosition.iY+tileSize.iHeight), *aBitmapToBlt);
593 bitmapPosition.iX += tileSize.iWidth;
594 if (bitmapPosition.iX + tileSize.iWidth > targetSize.iWidth)
596 bitmapPosition.iX = 0;
597 bitmapPosition.iY += tileSize.iHeight;
600 iDGdiDriver->Finish();
604 case EDrawBitmapMasked:
606 // Do a draw outside the loop so that we aren't measuring the time to load and cache the bitmap.
607 aGc->DrawBitmapMasked(TRect(0, 0, tileSize.iWidth, tileSize.iHeight), *aBitmapToBlt, aCropTo, *aBitmapMask, EFalse);
608 iProfiler->InitResults();
609 for(TInt count=KIterationsToTest; count>0; --count)
611 TPoint bitmapPosition = TPoint(0,0);
612 for (TInt tile = numTiles - 1; tile >= 0; --tile)
614 aGc->DrawBitmapMasked(TRect(bitmapPosition.iX, bitmapPosition.iY, bitmapPosition.iX+tileSize.iWidth, bitmapPosition.iY+tileSize.iHeight), *aBitmapToBlt, aCropTo, *aBitmapMask, EFalse);
615 bitmapPosition.iX += tileSize.iWidth;
616 if (bitmapPosition.iX + tileSize.iWidth > targetSize.iWidth)
618 bitmapPosition.iX = 0;
619 bitmapPosition.iY += tileSize.iHeight;
622 iDGdiDriver->Finish();
628 // Do a draw outside the loop so that we aren't measuring the time to load and cache the bitmap.
629 aGc->BitBlt(TPoint(0,0), *aBitmapToBlt, aCropTo);
630 iProfiler->InitResults();
631 for(TInt count=KIterationsToTest; count>0; --count)
633 TPoint bitmapPosition = TPoint(0,0);
634 for (TInt tile = numTiles - 1; tile >= 0; --tile)
636 aGc->BitBlt(bitmapPosition, *aBitmapToBlt, aCropTo);
637 bitmapPosition.iX += tileSize.iWidth;
638 if (bitmapPosition.iX + tileSize.iWidth > targetSize.iWidth)
640 bitmapPosition.iX = 0;
641 bitmapPosition.iY += tileSize.iHeight;
644 iDGdiDriver->Finish();
650 // Do a draw outside the loop so that we aren't measuring the time to load and cache the bitmap.
651 aGc->BitBltMasked(TPoint(0,0), *aBitmapToBlt, aCropTo, *aBitmapMask, EFalse);
652 iProfiler->InitResults();
653 for(TInt count=KIterationsToTest; count>0; --count)
655 TPoint bitmapPosition = TPoint(0,0);
656 for (TInt tile = numTiles - 1; tile >= 0; --tile)
658 aGc->BitBltMasked(bitmapPosition, *aBitmapToBlt, aCropTo, *aBitmapMask, EFalse);
659 bitmapPosition.iX += tileSize.iWidth;
660 if (bitmapPosition.iX + tileSize.iWidth > targetSize.iWidth)
662 bitmapPosition.iX = 0;
663 bitmapPosition.iY += tileSize.iHeight;
666 iDGdiDriver->Finish();
672 TESTNOERRORL(iDGdiDriver->GetError());
673 iProfiler->MarkResultSetL();
675 WriteTargetOutput(aTestName);
677 const TDisplayMode targetDisplayMode = TDisplayModeMapping::MapPixelFormatToDisplayMode(iImageInfo.iPixelFormat);
678 iProfiler->ResultsAnalysisPixelRate(aTestName, CFbsBitGc::EGraphicsOrientationNormal, aBitmapToBlt->DisplayMode(), targetDisplayMode, KIterationsToTest, numPixelsPerIteration);