os/graphics/graphicsdeviceinterface/bitgdi/tbit/textendedbitmap.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.
     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 "textendedbitmap.h"
    17 
    18 const TDisplayMode KDisplayMode[] = {EColor16MAP, EColor16MA, EColor16MU, EColor16M, EColor64K, 
    19 						   EColor4K, EColor256, EColor16, EGray256, EGray16, EGray4, EGray2};
    20 // The only display modes supported by the example rasterizer are EGray256, EColor64K,
    21 // EColor16MU and EColor16MAP, these tests will fail if KBitmapMode is changed to a
    22 // display mode that is not one of these modes.
    23 const TDisplayMode KBitmapMode = EColor16MAP;
    24 const TSize KBitmapSize(640,240);
    25 
    26 const TInt KNumColors = 3;
    27 const TRgb KColors[KNumColors] = {TRgb(0,255,255), TRgb(255,0,255), TRgb(255,255,0)};
    28 const TUid KUidExampleExtendedBitmap = {0x10285A78};
    29 
    30 //----------------------------------------------------------------------------
    31 // Positive Extended Bitmap Tests
    32 //----------------------------------------------------------------------------
    33 CTExtendedBitmap::CTExtendedBitmap(CTestStep* aStep) :
    34 	CTGraphicsBase(aStep)
    35 	{
    36 	}
    37 
    38 void CTExtendedBitmap::ConstructL()
    39 	{
    40 #ifdef USE_SCREEN_DEVICE
    41 	// Create a screen device
    42 	TInt ii = 0;
    43 	TInt err = KErrNotSupported;
    44 	for(;(ii<TInt(sizeof(KDisplayMode)/sizeof(KDisplayMode[0]))) && (err == KErrNotSupported);++ii)
    45 		{
    46 		TRAP(err, iDevice = CFbsScreenDevice::NewL(_L("scdv"),KDisplayMode[ii]));
    47 		}
    48 	if (err != KErrNone)
    49 		{
    50 		_LIT(KLog,"Failed to create screen device %S return value %d");
    51 		INFO_PRINTF3(KLog,&ColorModeName(KDisplayMode[ii]),err);
    52 		User::Leave(err);
    53 		}
    54 	else
    55 		{
    56 		_LIT(KLog,"Created Screen Device with mode %S");
    57 		INFO_PRINTF2(KLog,&ColorModeName(KDisplayMode[ii]));
    58 		}
    59 	static_cast<CFbsScreenDevice*>(iDevice)->SetAutoUpdate(ETrue);
    60 #else
    61 	// Create a standard bitmap, bitmap device
    62 	iBitmap = new(ELeave) CFbsBitmap;
    63 	User::LeaveIfError(iBitmap->Create(KBitmapSize, KBitmapMode));
    64 	iDevice = CFbsBitmapDevice::NewL(iBitmap);
    65 #endif
    66 
    67 	INFO_PRINTF2(_L("Testing CFbsBitGc with an extended bitmap, display mode %d"), KBitmapMode);
    68 
    69 	// Create a graphics context from chosen device
    70 	User::LeaveIfError(iDevice->CreateContext(iBitGc));
    71 	
    72 	// Check to see if the example rasterizer is available
    73 	CTExtendedBitmapGc::TDrawMode drawMode = CTExtendedBitmapGc::EDrawFlag;
    74 	if (CFbsBitmap::Rasterizer() == NULL)
    75 		drawMode = CTExtendedBitmapGc::EDrawWhite;
    76 	
    77 	switch (drawMode)
    78 		{
    79 		case CTExtendedBitmapGc::EDrawFlag:
    80 			INFO_PRINTF1(_L("Testing WITH the example rasterizer - Rasterizer Available"));
    81 			break;
    82 		case CTExtendedBitmapGc::EDrawWhite:
    83 			INFO_PRINTF1(_L("Testing WITHOUT the example rasterizer - Rasterizer NOT Available"));
    84 			break;
    85 		default:
    86 			ERR_PRINTF1(_L("Unknown draw mode"));
    87 			break;
    88 		}				
    89 	
    90 	
    91 	iExtendedBitmapGcTests = CTExtendedBitmapGc::NewL(this, *iBitGc, drawMode, KBitmapMode);
    92 	}
    93 
    94 CTExtendedBitmap::~CTExtendedBitmap()
    95 	{
    96 	((CTExtendedBitmapStep*)iStep)->CloseTMSGraphicsStep();
    97 	delete iExtendedBitmapGcTests;
    98 	delete iBitGc;
    99 	delete iDevice;
   100 #ifndef USE_SCREEN_DEVICE
   101 	delete iBitmap;
   102 #endif
   103 	}
   104 
   105 /**
   106 @SYMTestCaseID
   107 	GRAPHICS-BITGDI-0103
   108 
   109 @SYMTestCaseDesc
   110 	Test extended bitmaps are drawn correctly to an offscreen bitmap using CFbsBitGc.
   111 	Test that shapes are filled correctly when an extended bitmap is set as the brush pattern 
   112 	using CFbsBitGc::UseBrushPattern().
   113 
   114 @SYMPREQ 
   115 	PREQ2096
   116 
   117 @SYMREQ
   118 	REQ10847
   119 	REQ10857
   120 	REQ10859
   121 
   122 @SYMTestPriority  
   123 	High
   124 
   125 @SYMTestStatus 
   126 	Implemented
   127 
   128 @SYMTestActions
   129 	Create an extended bitmap with extended data to generate a flag pattern when rendered,
   130 	if the example rasterizer is available.	
   131 	
   132 	Create a matching standard bitmap.
   133 
   134 	Draw the extended bitmap on the left of the screen and the standard bitmap on the right, 
   135 	using each of the following CFbsBitGc APIs.
   136 	This is done with both vertical and horizonatal flag orientations,
   137 	and with and without an active region of interest:	 	
   138 		- BitBlt() (one version tested as both versions call through to DoBitBlt())
   139 		- BitBltMasked()
   140 		- DrawBitmap() (one version tested as both versions call through to DoDrawBitmap())
   141 		- DrawBitmapMasked()
   142 		- UseBrushPattern()
   143 		- AlphaBlendBitmaps(const TPoint& aDestPt, const CFbsBitmap* aSrcBmp1, const CFbsBitmap* aSrcBmp2, const TRect& aSrcRect1, const TPoint& aSrcPt2, 
   144 				const CFbsBitmap* aAlphaBmp, const TPoint& aAlphaPt);
   145 		- AlphaBlendBitmaps(const TPoint& aDestPt, const CFbsBitmap* aSrcBmp, const TRect& aSrcRect, const CFbsBitmap* aAlphaBmp, const TPoint& aAlphaPt);
   146 		
   147 	To test that shapes are filled correctly using an extended bitmap, an extended bitmap that would generate 
   148 	a flag pattern if the example rasterizer is available, and a matching standard bitmap are in turn set as 
   149 	the brush pattern using CFbsBitGc::UseBrushPattern(). Each of the following APIs are used to draw a shape,
   150 	using the extended bitmap as a brush on the left, and the standard bitmap on the right. Calling each
   151 	of these APIs is necessary as each one contains code specific to extended bitmaps.
   152 		- DrawPie()
   153 		- DrawRoundRect()
   154 		- DrawPolygon() (2 versions)
   155 		- DrawEllipse()
   156 		- DrawRect()
   157 		- DrawText()
   158 		- DrawTextVertical()
   159 		
   160 	Note that the test cases are actually run from a separate test DLL that is built as part of the FbServ
   161 	tests (textendedbitmapgc.dll). This DLL allows the same extended bitmap tests to be run using different graphics
   162 	contexts. 
   163 
   164 @SYMTestExpectedResults
   165 	When the rasterizer is available both sides of the test screen should show a horizontally/vertically striped rectangle for every 
   166 	test case, when the rasterizer is not present both sides of the test screen should show a white rectangle for each test case.
   167 	The left and right side of the test should always match exactly for each test case, i.e. what is drawn using an
   168 	extended bitmap on the left of the screen should match what is drawn using a corresponding standard bitmap on the right of
   169 	the screen.
   170 */
   171 void CTExtendedBitmap::RunTestCaseL(TInt aCurTestCase)
   172 	{
   173 	((CTExtendedBitmapStep*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0103"));
   174 	iExtendedBitmapGcTests->RunTestCaseL(aCurTestCase);
   175 	
   176 	// Compare the two sides of the screen, they should match exactly
   177 	TSize scrSize = iDevice->SizeInPixels();
   178 	TEST(iDevice->RectCompare(TRect(0,0,scrSize.iWidth>>1,scrSize.iHeight), *iDevice, TRect(scrSize.iWidth>>1,0,scrSize.iWidth,scrSize.iHeight)));
   179 	((CTExtendedBitmapStep*)iStep)->RecordTestResultL();
   180 	}
   181 
   182 CTestExecuteLogger& CTExtendedBitmap::Logger()
   183 	{
   184 	return CTGraphicsBase::Logger();
   185 	}
   186 
   187 void CTExtendedBitmap::TestTrue(TBool aCondition)
   188 	{
   189 	TEST(aCondition);
   190 	}
   191 
   192 void CTExtendedBitmap::TestComplete()
   193 	{
   194 	CTGraphicsBase::TestComplete();
   195 	}
   196 
   197 __CONSTRUCT_STEP__(ExtendedBitmap)
   198 
   199 
   200 //----------------------------------------------------------------------------
   201 // Negative Extended Bitmap Tests
   202 //----------------------------------------------------------------------------
   203 CTExtendedBitmapNegative::CTExtendedBitmapNegative(CTestStep* aStep) :
   204 	CTGraphicsBase(aStep)
   205 	{
   206 	}
   207 
   208 void CTExtendedBitmapNegative::RunTestCaseL(TInt aCurTestCase)
   209 	{	
   210 	((CTExtendedBitmapNegativeStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
   211 	switch(aCurTestCase)
   212 		{	
   213 	case 1:
   214 		((CTExtendedBitmapNegativeStep*)iStep)->SetTestStepID(_L("GRAPHICS-BITGDI-0104"));
   215 		TestCFbsBitmapDeviceNewLLeavesL();
   216 		break;
   217 	default:
   218 		((CTExtendedBitmapNegativeStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
   219 		((CTExtendedBitmapNegativeStep*)iStep)->CloseTMSGraphicsStep();
   220 		TestComplete();
   221 		break;	
   222 		}	
   223 	((CTExtendedBitmapNegativeStep*)iStep)->RecordTestResultL();
   224 	}
   225 
   226 /**
   227 @SYMTestCaseID
   228 	GRAPHICS-BITGDI-0104
   229 
   230 @SYMTestCaseDesc
   231 	Test that passing an extended bitmap to CFbsBitmapDevice::NewL() leaves with error KErrAccessDenied.
   232 
   233 @SYMPREQ 
   234 	PREQ2096
   235 	
   236 @SYMREQ
   237 	REQ10847
   238 	REQ10856	
   239 
   240 @SYMTestPriority  
   241 	High
   242 	
   243 @SYMTestStatus 
   244 	Implemented
   245 	
   246 @SYMTestActions
   247 	Create an extended bitmap using test data and test Uid.
   248 	Call CFbsBitmapDevice::NewL() with the extended bitmap as the parameter.
   249 		
   250 @SYMTestExpectedResults
   251 	CFbsBitmapDevice::NewL() leaves with error KErrAccessDenied.
   252 */
   253 void CTExtendedBitmapNegative::TestCFbsBitmapDeviceNewLLeavesL()
   254 	{
   255 	INFO_PRINTF1(_L("Test that CFbsBitmapDevice leaves with KErrAccessDenied when created with an extended bitmap"));			
   256 	TInt dataSize = sizeof(KColors)+sizeof(TUint8); // estimate the data size
   257 	TUint8* data = new(ELeave) TUint8[dataSize];
   258 	CleanupStack::PushL(data);	
   259 	
   260 	// Write the colours to be used in the extended bitmap to the data	
   261 	CTExtendedBitmapGc::WriteExtendedBitmapInfoL(data, dataSize, KColors, CTExtendedBitmapGc::EHorizontalStripe);
   262 	
   263 	CFbsBitmap* bmp = new(ELeave) CFbsBitmap;
   264 	CleanupStack::PushL(bmp);
   265 	TInt err = bmp->CreateExtendedBitmap(TSize(10,10), KBitmapMode, KUidExampleExtendedBitmap, data, dataSize);
   266 	TEST(err == KErrNone);
   267 	
   268 	// CFbsBitmapDevice::NewL() should leave with KErrAccessDenied
   269 	CFbsBitmapDevice* bmpDevice1 = NULL;
   270 	TRAPD(error, bmpDevice1 = CFbsBitmapDevice::NewL(bmp));	
   271 	TEST(error == KErrAccessDenied);	
   272 	
   273 	delete bmpDevice1;
   274 	CleanupStack::PopAndDestroy(2, data);
   275 	}
   276 
   277 __CONSTRUCT_STEP__(ExtendedBitmapNegative)