graphicsdeviceinterface/bitgdi/tbit/tbitblt.cpp
changeset 0 5d03bc08d59c
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     1 // Copyright (c) 2008-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 #include <hal.h>
       
    17 #include "tbitblt.h"
       
    18 
       
    19 //_LIT(KBit16BitmapOnZ, "z:\\system\\data\\16bit.mbm");
       
    20 _LIT(KBit32BitmapOnZ, "z:\\system\\data\\32bit_2.mbm");
       
    21 
       
    22 /**
       
    23 Create a new virtual bitmap device
       
    24 */
       
    25 CVirtualBitmapDevice*  CVirtualBitmapDevice::NewL(TDisplayMode aDisplayMode, TSize aSize)
       
    26 	{
       
    27 	CVirtualBitmapDevice* self = new(ELeave) CVirtualBitmapDevice();
       
    28 	CleanupStack::PushL(self);
       
    29 	self->ConstructL(aDisplayMode, aSize);
       
    30 	CleanupStack::Pop(self);
       
    31 	return self;
       
    32 	}
       
    33 
       
    34 void CVirtualBitmapDevice::ConstructL(TDisplayMode aDisplayMode, TSize aSize)
       
    35 	{	
       
    36 	// Attempt to create a screen device
       
    37 	CFbsScreenDevice* screenDevice = NULL;
       
    38 	TRAPD(ret, screenDevice = CFbsScreenDevice::NewL(_L("scdv"), aDisplayMode));
       
    39 	if (ret != KErrNone)
       
    40 		{
       
    41 		// Screen device cannot be created so create a off screen bitmap device
       
    42 		iBitmap = new(ELeave) CFbsBitmap;
       
    43 		iBitmap->Create(aSize, aDisplayMode);
       
    44 		iBitmapDevice = CFbsBitmapDevice::NewL(iBitmap);
       
    45 		iIsScreenDevice = EFalse;
       
    46 		}
       
    47 	else
       
    48 		{
       
    49 		screenDevice->SetAutoUpdate(EFalse);
       
    50 		iBitmapDevice = screenDevice;
       
    51 		iIsScreenDevice = ETrue;
       
    52 		}
       
    53 	}
       
    54 
       
    55 CVirtualBitmapDevice::~CVirtualBitmapDevice()
       
    56 	{
       
    57 	delete iBitmapDevice;
       
    58 	delete iBitmap;
       
    59 	}
       
    60 
       
    61 /**
       
    62 Update implements the same method on CFbsScreenDevice to Update the screen. This only works on a screen device.
       
    63 Off screen bitmaps do not have to be updated and no action will be taken in this case.
       
    64 */
       
    65 void CVirtualBitmapDevice::Update()
       
    66 	{
       
    67 	if (iIsScreenDevice)
       
    68 		{
       
    69 		CFbsScreenDevice* screenDevice = static_cast<CFbsScreenDevice*>(iBitmapDevice);
       
    70 		screenDevice->Update();
       
    71 		}
       
    72 	}
       
    73 
       
    74 /**
       
    75 Returns the actual bitmap device
       
    76 */
       
    77 CBitmapDevice& CVirtualBitmapDevice::BitmapDevice()
       
    78 	{
       
    79 	return *iBitmapDevice;
       
    80 	}
       
    81 
       
    82 //  CTBitBlt Methods
       
    83 CTBitBlt::CTBitBlt(CTestStep* aStep) :
       
    84 	CTGraphicsBase(aStep)
       
    85 	{
       
    86 	}
       
    87 
       
    88 CTBitBlt::~CTBitBlt()
       
    89 	{
       
    90 	delete iBitmap;
       
    91 	}
       
    92 
       
    93 void CTBitBlt::ConstructL()
       
    94 	{
       
    95 	INFO_PRINTF1(_L("Pre-test setup"));
       
    96 	iBitmap=new(ELeave) CFbsBitmap;
       
    97 	User::LeaveIfError(iBitmap->Load(KBit32BitmapOnZ,0,EFalse));  //EMbmTbmpTcolor
       
    98 	}
       
    99 
       
   100 void CTBitBlt::RunTestCaseL(TInt aCurTestCase)
       
   101 	{
       
   102 	((CTBitBltStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
       
   103 	switch(aCurTestCase)
       
   104 		{
       
   105 	case 1:
       
   106 		((CTBitBltStep*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0017"));
       
   107 		TestBitBltPositionsL(EFalse);	// Uncompressed bitmaps
       
   108 		TestBitBltPositionsL(ETrue);	// Compressed bitmaps
       
   109 		break;
       
   110 	case 2:
       
   111 		((CTBitBltStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
       
   112 		((CTBitBltStep*)iStep)->CloseTMSGraphicsStep();
       
   113 		TestComplete();
       
   114 		break;
       
   115 		}
       
   116 	((CTBitBltStep*)iStep)->RecordTestResultL();
       
   117 	}
       
   118 
       
   119 /**
       
   120 Captures the screen data from aDevice and returns it as a TUint8 buffer in EColor256.
       
   121 
       
   122 @param aDevice the bitmap device to capture
       
   123 @param aScreenByteSize the size of the returned data
       
   124 @return the screen data in EColor256
       
   125 */
       
   126 TUint8* CTBitBlt::CaptureDeviceDataLC(CBitmapDevice& aDevice, TInt& aScreenByteSize)
       
   127 	{
       
   128 	TSize scrDevSize = aDevice.SizeInPixels();
       
   129 	TDisplayMode displayMode = aDevice.DisplayMode();
       
   130 
       
   131 	// Create memory to hold device data assuming EColor256
       
   132 	aScreenByteSize = scrDevSize.iWidth * scrDevSize.iHeight;
       
   133 	TUint8* screenData = new (ELeave) TUint8[aScreenByteSize];
       
   134 	CleanupArrayDeletePushL(screenData);
       
   135 
       
   136 	// Fill the blocks with some default value
       
   137 	Mem::Fill(screenData, aScreenByteSize, 0xCA);
       
   138 
       
   139 	// Get screen data and write the data to screenBmp.
       
   140 	for(TInt y=0; y<scrDevSize.iHeight;y++)
       
   141    		{
       
   142 		TPtr8 p(screenData + y * scrDevSize.iWidth, scrDevSize.iWidth, scrDevSize.iWidth);
       
   143 		aDevice.GetScanLine(p, TPoint(0, y), scrDevSize.iWidth, EColor256); // Get Scanline and convert to EColor256 if not already in that display mode
       
   144    		}
       
   145    	return screenData;
       
   146 	}
       
   147 
       
   148 /**
       
   149 Creates a bitmap image of what is meant to be displayed on the screen without using any bitblt methods.
       
   150 This bitmap is compared with the one on screen and returns 0 if they match.
       
   151 
       
   152 @param aDevice the screen device to capture
       
   153 @param aGc graphics context for aDevice
       
   154 @param aScreenSize the size of the display of aDevice
       
   155 @param aBitmapSize the size of the bitmap
       
   156 @param aScreenMode the screen mode to use
       
   157 @param aOffset the offset of the bitmap from the top left corner of the display
       
   158 @param aRect the clipping rectangle for the bitmap
       
   159 @return if bitmap matches what is on the screen 0 is returned
       
   160 */
       
   161 TInt CTBitBlt::CreateBitmapImageAndCompareL(CVirtualBitmapDevice& aDevice, CFbsBitGc& aGc, TSize aScreenSize, TSize aBitmapSize, TDisplayMode aScreenMode, TPoint aOffset, TRect& aRect)
       
   162 	{
       
   163 	// Create Bitmap
       
   164 	CFbsBitmap* tBitmap = new(ELeave) CFbsBitmap;
       
   165 	CleanupStack::PushL(tBitmap);
       
   166 	tBitmap->Create(aScreenSize, aScreenMode);
       
   167 
       
   168 	// Create Bitmap Device
       
   169 	CFbsBitmapDevice* bmpDevice = CFbsBitmapDevice::NewL(tBitmap);
       
   170 	CleanupStack::PushL(bmpDevice);
       
   171 
       
   172 	// Create GC for bitmap device and draw a some graphics
       
   173 	CFbsBitGc* bmpGc;
       
   174 	User::LeaveIfError(bmpDevice->CreateContext(bmpGc));
       
   175 	CleanupStack::PushL(bmpGc);
       
   176 	bmpGc->Clear();
       
   177 	bmpGc->SetClippingRect(TRect(aRect.iTl.iX+aOffset.iX, aRect.iTl.iY+aOffset.iY, aRect.iBr.iX+aOffset.iY, aRect.iBr.iY+aOffset.iY));
       
   178 	for (TInt i = aBitmapSize.iWidth/2; i>0; --i)
       
   179 		{
       
   180 		bmpGc->SetPenColor(TRgb::Color256(i));
       
   181 		bmpGc->DrawRect(TRect(i+aOffset.iX,i+aOffset.iY,aBitmapSize.iWidth - i + aOffset.iX, aBitmapSize.iHeight - i + aOffset.iY));
       
   182 		}
       
   183 	bmpGc->CancelClippingRect();
       
   184 
       
   185 	// Now compare tBitmap with what is on the screen
       
   186 	TInt allocatedSize;
       
   187 	TUint8* screenData = CaptureDeviceDataLC(aDevice.BitmapDevice(), allocatedSize);
       
   188 	TUint8* testData = CaptureDeviceDataLC(*bmpDevice, allocatedSize);
       
   189 	TInt res = Mem::Compare(screenData, allocatedSize, testData, allocatedSize);
       
   190 	// Display on screen
       
   191 	aGc.Clear();
       
   192 	aGc.BitBlt(TPoint(0,0), tBitmap, TRect(TPoint(0,0), aScreenSize));
       
   193 	aDevice.Update();
       
   194 	CleanupStack::PopAndDestroy(5, tBitmap);
       
   195 	return res;
       
   196 	}
       
   197 
       
   198 /**
       
   199 Bitblts a bitmap and compares it with how it should look
       
   200 
       
   201 @param aDevice the screen device to capture
       
   202 @param aGc graphics context for aDevice
       
   203 @param aBitmap the bitmap to bitblt
       
   204 @param aScreenMode the screen mode
       
   205 @param aPointStart the top left point to start displaying the bitmap
       
   206 @param aRect the clipping rectangle for the bitmap
       
   207 */
       
   208 void CTBitBlt::SimpleBitBltAndTestL(CVirtualBitmapDevice& aDevice, CFbsBitGc& aGc, CFbsBitmap& aBitmap, TDisplayMode aScreenMode, TPoint aStartPoint, TRect& aRect)
       
   209 	{
       
   210 	aGc.Clear();
       
   211 	aGc.BitBlt(aStartPoint, &aBitmap, aRect);
       
   212 	aDevice.Update();
       
   213 	TPoint offset(10,10);
       
   214 	TInt res = CreateBitmapImageAndCompareL(aDevice, aGc, aDevice.BitmapDevice().SizeInPixels(), aBitmap.SizeInPixels(), aScreenMode, offset, aRect);
       
   215 	TEST(res == 0);
       
   216 	}
       
   217 
       
   218 /**
       
   219 	@SYMTestCaseID GRAPHICS-BITGDI-0017
       
   220  
       
   221 	@SYMDEF DEF105390
       
   222    
       
   223 	@SYMTestCaseDesc  Tests simple BitBlt using clipping rect is various places.
       
   224  
       
   225 	@SYMTestPriority Low
       
   226   
       
   227 	@SYMTestStatus Implemented
       
   228    
       
   229 	@SYMTestActions Test the BitBlt function for positioning by blitting only some part of the image.
       
   230    
       
   231 	@SYMTestExpectedResults Test should perform graphics operations succesfully.
       
   232 
       
   233  */
       
   234 
       
   235 void CTBitBlt::TestBitBltPositionsL(TBool aDoCompressed)
       
   236 	{
       
   237 	if(aDoCompressed)
       
   238 		{
       
   239 		INFO_PRINTF1(_L("BitBlt Positions testing : Compressed Bitmaps"));
       
   240 		}
       
   241 	else
       
   242 		{
       
   243 		INFO_PRINTF1(_L("BitBlt Positions testing : Uncompressed Bitmaps"));
       
   244 		}
       
   245 
       
   246 	TDisplayMode dstDispMode[] = {EColor16M, EColor16MU, EColor256, EColor4K, EColor64K};	
       
   247 	TDisplayMode dispMode[] = {EColor16MA, EColor16MAP, EColor16M, EColor16MU, EColor256, EColor4K, EColor64K, EGray256, EGray16, EGray4, EGray2, EColor16};	
       
   248 
       
   249 	for(TInt dstDispModeIndex = 0; dstDispModeIndex < TInt(sizeof(dstDispMode)/sizeof(dstDispMode[0])); dstDispModeIndex++)
       
   250 		{
       
   251 		// Test for each display mode
       
   252 		for(TInt dispModeIndex = 0; dispModeIndex < TInt(sizeof(dispMode)/sizeof(dispMode[0])); dispModeIndex++)
       
   253 			{
       
   254 			INFO_PRINTF3(_L("Display Mode Index = %d/%d"), dstDispModeIndex, dispModeIndex);
       
   255 		
       
   256 			// Setup screen device to 16MA
       
   257 			TSize size = TSize(640,200);
       
   258 			iVirtualBmpDevice = CVirtualBitmapDevice::NewL(dstDispMode[dstDispModeIndex], size);
       
   259 			CBitmapDevice& screenDevice = iVirtualBmpDevice->BitmapDevice();		
       
   260 
       
   261 			CFbsBitGc* gc=NULL;
       
   262 			User::LeaveIfError(screenDevice.CreateContext((CGraphicsContext*&)gc));
       
   263 			TEST(gc!=NULL);
       
   264 			CleanupStack::PushL(gc);
       
   265 			for(TInt orientation=0;orientation<=CFbsBitGc::EGraphicsOrientationRotated270;orientation++)
       
   266 				{
       
   267 				gc->Reset();
       
   268 				if (!gc->SetOrientation((CFbsBitGc::TGraphicsOrientation)orientation))
       
   269 					continue;
       
   270 				if (orientation&1 && dispMode[dispModeIndex]==EColor16M)
       
   271 					{//zzz Skipping this case due to DEF120222 that causes the verification code to fail
       
   272 					continue;
       
   273 					}
       
   274 				TSize screenSize = screenDevice.SizeInPixels();
       
   275 
       
   276 				// Create Bitmap
       
   277 				CFbsBitmap* bitmap32 = new(ELeave) CFbsBitmap;
       
   278 				TEST(bitmap32!=NULL);
       
   279 				CleanupStack::PushL(bitmap32);
       
   280 				TSize bitmapSize = screenSize - TSize(20, 20); 	// Make bitmap smaller than screen by 20 pixels
       
   281 				bitmap32->Create(bitmapSize, dispMode[dispModeIndex]);
       
   282 
       
   283 				// Create Bitmap Device
       
   284 				CFbsBitmapDevice* bmpDevice = CFbsBitmapDevice::NewL(bitmap32);
       
   285 				TEST(bmpDevice!=NULL);
       
   286 				CleanupStack::PushL(bmpDevice);
       
   287 
       
   288 				// Create GC for bitmap device and draw some graphics
       
   289 				CFbsBitGc* bmpGc;
       
   290 				User::LeaveIfError(bmpDevice->CreateContext(bmpGc));
       
   291 				TEST(bmpGc!=NULL);
       
   292 				CleanupStack::PushL(bmpGc);
       
   293 				bmpGc->Clear();
       
   294 				for (TInt i = bitmapSize.iWidth/2; i>0; --i)
       
   295 					{
       
   296 					bmpGc->SetPenColor(TRgb::Color256(i));	
       
   297 					bmpGc->DrawRect(TRect(i,i,bitmapSize.iWidth - i, bitmapSize.iHeight - i));
       
   298 					}
       
   299 
       
   300 				if (aDoCompressed)
       
   301 					{
       
   302 					bitmap32->Compress();
       
   303 					}
       
   304 
       
   305 				gc->Clear();
       
   306 
       
   307 				// Display whole bitmap with larger rect
       
   308 				TPoint startPoint(10,10);
       
   309 				TRect rect(0,0,bitmapSize.iWidth+50, bitmapSize.iHeight+50);
       
   310 				SimpleBitBltAndTestL(*iVirtualBmpDevice, *gc, *bitmap32, dispMode[dispModeIndex], startPoint, rect);
       
   311 
       
   312 				// Display whole bitmap
       
   313 				startPoint = TPoint(10,10);
       
   314 				rect = TRect(0,0,bitmapSize.iWidth, bitmapSize.iHeight);
       
   315 				SimpleBitBltAndTestL(*iVirtualBmpDevice, *gc, *bitmap32, dispMode[dispModeIndex], startPoint, rect);
       
   316 
       
   317 				// Display TL of bitmap
       
   318 				startPoint = TPoint(10,10);
       
   319 				rect = TRect(0,0,bitmapSize.iWidth/2, bitmapSize.iHeight/2);
       
   320 				SimpleBitBltAndTestL(*iVirtualBmpDevice, *gc, *bitmap32, dispMode[dispModeIndex], startPoint, rect);
       
   321 
       
   322 				// Display TR of bitmap
       
   323 				startPoint = TPoint(bitmapSize.iWidth/2+10, 10);
       
   324 				rect = TRect(bitmapSize.iWidth/2,0,bitmapSize.iWidth,bitmapSize.iHeight/2);
       
   325 				SimpleBitBltAndTestL(*iVirtualBmpDevice, *gc, *bitmap32, dispMode[dispModeIndex], startPoint, rect);
       
   326 
       
   327 				// Display BL of bitmap
       
   328 				startPoint = TPoint(10, bitmapSize.iHeight/2+10);
       
   329 				rect = TRect(0,bitmapSize.iHeight/2,bitmapSize.iWidth/2,bitmapSize.iHeight);
       
   330 				SimpleBitBltAndTestL(*iVirtualBmpDevice, *gc, *bitmap32, dispMode[dispModeIndex], startPoint, rect);
       
   331 
       
   332 				// Display BR of bitmap
       
   333 				startPoint = TPoint(bitmapSize.iWidth/2+10,bitmapSize.iHeight/2+10);
       
   334 				rect = TRect(bitmapSize.iWidth/2,bitmapSize.iHeight/2,bitmapSize.iWidth,bitmapSize.iHeight);
       
   335 				SimpleBitBltAndTestL(*iVirtualBmpDevice, *gc, *bitmap32, dispMode[dispModeIndex], startPoint, rect);
       
   336 
       
   337 				// Centre of bitmap
       
   338 				startPoint = TPoint(bitmapSize.iWidth/4+10,bitmapSize.iHeight/4+10);
       
   339 				rect = TRect(bitmapSize.iWidth/4,bitmapSize.iHeight/4,bitmapSize.iWidth/4+bitmapSize.iWidth/4,bitmapSize.iHeight/4+bitmapSize.iHeight/4);
       
   340 				SimpleBitBltAndTestL(*iVirtualBmpDevice, *gc, *bitmap32, dispMode[dispModeIndex], startPoint, rect);
       
   341 
       
   342 				CleanupStack::PopAndDestroy(3, bitmap32);
       
   343 				}
       
   344 			CleanupStack::PopAndDestroy(gc);
       
   345 			delete iVirtualBmpDevice;
       
   346 			iVirtualBmpDevice = NULL;
       
   347 			}
       
   348 		}
       
   349 	}
       
   350 
       
   351 //--------------
       
   352 __CONSTRUCT_STEP__(BitBlt)
       
   353 
       
   354 void CTBitBltStep::TestSetupL()
       
   355 	{
       
   356 	}
       
   357 
       
   358 void CTBitBltStep::TestClose()
       
   359 	{
       
   360 	}