os/graphics/graphicstest/graphicstestharness/textendedbitmapgc/textendedbitmapgc.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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 "textendedbitmapgc.h"
    17 #include <s32mem.h>
    18 
    19 const TInt KNumBitmapDrawingTests = 10;
    20 const TInt KNumBrushPatternTests = 8;
    21 const TUid KUidExampleExtendedBitmap = {0x10285A78};
    22 
    23 /** Constructor.
    24 @param aCallBack Pointer to a valid implementation of MTestHarnessCallBack, to allow logging and 
    25 test status requests to be passed back to the creator of a CTExtendedBitmapGc object.
    26 @param aGc A graphics context to use for all drawing operations.
    27 @param aDrawMode The mode to draw extended bitmaps in, either EDrawFlag or EDrawWhite.
    28 @param aDisplayMode The display mode to use when creating extended bitmaps, this
    29 must be one of EGray256, EColor64K, EColor16MU or EColor16MAP.
    30 @return a pointer to a newly constructed CTExtendedBitmapGc object. 
    31 @leave KErrNotSupported if an unsupported display mode is passed in aDisplayMode.
    32  */
    33 EXPORT_C CTExtendedBitmapGc* CTExtendedBitmapGc::NewL(MTestHarnessCallBack* aCallBack, 
    34 												CBitmapContext& aGc, 
    35 												TDrawMode aDrawMode,
    36 												TDisplayMode aDisplayMode)
    37 	{	
    38 	CTExtendedBitmapGc* ebgc = new(ELeave) CTExtendedBitmapGc(aCallBack, aGc, aDrawMode);
    39 	CleanupStack::PushL(ebgc);
    40 	ebgc->ConstructL(aDisplayMode);
    41 	CleanupStack::Pop(ebgc);
    42 	return ebgc;
    43 	}
    44 
    45 CTExtendedBitmapGc::CTExtendedBitmapGc(MTestHarnessCallBack* aCallBack, 
    46 										CBitmapContext& aGc, 
    47 										TDrawMode aDrawMode) :
    48 iCallBack(aCallBack), iDrawMode(aDrawMode), iGc(aGc), iIsFbs(aGc.IsFbsBitGc())
    49 	{
    50 	}
    51 
    52 void CTExtendedBitmapGc::ConstructL(TDisplayMode aDisplayMode)
    53 
    54 	{	
    55 	// Check that the display mode chosen is supported by the example rasterizer
    56 	if ((aDisplayMode != EGray256) && (aDisplayMode != EColor64K) && (aDisplayMode != EColor16MU) && (aDisplayMode != EColor16MAP))
    57 		{
    58 		INFO_PRINTF2(_L("Failed to construct CTExtendedBitmapGc with unsupported display mode %d"), aDisplayMode);
    59 		User::Leave(KErrNotSupported);
    60 		}
    61 	iDisplayMode = aDisplayMode; 
    62 	
    63 	// Get a font for use with the DrawText() and DrawTextVertical() tests
    64 	_LIT(KFontName, "DejaVu Sans Condensed");
    65 	TFontSpec fontSpec(KFontName, 75);
    66 	fontSpec.iFontStyle.SetBitmapType(EAntiAliasedGlyphBitmap);
    67 	iCallBack->TestTrue(KErrNone == static_cast<CBitmapDevice*>(iGc.Device())->GetNearestFontToDesignHeightInPixels(iFont, fontSpec));
    68 	iGc.UseFont(iFont);
    69 	}
    70 
    71 EXPORT_C CTExtendedBitmapGc::~CTExtendedBitmapGc()
    72 	{
    73 	if(iFont)
    74 		{
    75 		iGc.DiscardFont();
    76 		static_cast<CBitmapDevice*>(iGc.Device())->ReleaseFont(iFont);
    77 		}
    78 	}
    79 
    80 /** Test case calling function used to test drawing of Extended Bitmaps on graphics contexts.
    81 Utilised by GRAPHICS-BITGDI-0103 to test with CFbsBitGc, and by GRAPHICS-WSERV-0493 with CWindowGc.
    82 @param aCaseNumber Case number to run
    83  */
    84 EXPORT_C void CTExtendedBitmapGc::RunTestCaseL(TInt aCurTestCase)
    85 	{
    86 	--aCurTestCase;
    87 	switch(aCurTestCase / KNumBitmapDrawingTests)
    88 		{
    89 	case 0:
    90 		TestBitmapDrawingL(EFalse, EVerticalStripe, aCurTestCase % KNumBitmapDrawingTests);	
    91 		break;
    92 	case 1:
    93 		TestBitmapDrawingL(EFalse, EHorizontalStripe, aCurTestCase % KNumBitmapDrawingTests);	
    94 		break;
    95 	case 2:
    96 		TestBitmapDrawingL(ETrue, EVerticalStripe, aCurTestCase % KNumBitmapDrawingTests);	
    97 		break;
    98 	case 3:
    99 		TestBitmapDrawingL(ETrue, EHorizontalStripe, aCurTestCase % KNumBitmapDrawingTests);	
   100 		break;
   101 	default:
   102 		{
   103 		TInt brushCase = aCurTestCase - (4 * KNumBitmapDrawingTests);
   104 		if(brushCase < KNumBrushPatternTests)
   105 			{
   106 			TestBrushPatternL(brushCase);
   107 			}
   108 		else
   109 			{
   110 			// Finished tests
   111 			iCallBack->TestComplete();
   112 			}
   113 		}
   114 		}
   115 	}
   116 
   117 /** Test case function used to test drawing of Extended Bitmaps on graphics contexts.
   118 Utilised by GRAPHICS-BITGDI-0103 to test with CFbsBitGc, and by GRAPHICS-WSERV-0493 with CWindowGc.
   119 @param aTestRegionOfInterest ETrue if to set a region of interest before drawing, EFalse not to
   120 @param aStripeStyle Direction to draw the flag stripes, when rasterizer is present
   121 @param aCaseNumber Case number to run - between 0 and (KNumBitmapDrawingTests - 1)
   122  */
   123 void CTExtendedBitmapGc::TestBitmapDrawingL(TBool aTestRegionOfInterest, TStripeStyle aStripeStyle, TInt aCaseNumber)
   124 	{
   125 	_LIT(KVertical, "vertical");
   126 	_LIT(KHorizontal, "horizontal");	
   127 	_LIT(KRegionNotSet, "not set");
   128 	_LIT(KRegionSet, "set");
   129 	const TPtrC KStripeStyle[2] = {KVertical(), KHorizontal()};
   130 	const TPtrC KRegionStyle[2] = {KRegionNotSet(), KRegionSet()};
   131 	const TInt KNumColors = 3;
   132 	const TRgb KColors[KNumColors] = {TRgb(0,255,255), TRgb(255,0,255), TRgb(255,255,0)};
   133 
   134 	const TRgb KMaskColors[KNumColors] = {KRgbBlack, KRgbWhite, KRgbBlack};
   135 	const TRgb KAlphaColors[KNumColors] = {KRgbDarkGray, KRgbGray, KRgbDarkGray};
   136 	const TStripeStyle KMaskBitmapStripeStyle = EVerticalStripe;
   137 	const TStripeStyle KAlphaBitmapStripeStyle = EHorizontalStripe;
   138 
   139 	TInt dataSize = sizeof(KColors)+sizeof(TUint8); // estimate the data size
   140 	TUint8* data = new(ELeave) TUint8[dataSize];
   141 	CleanupStack::PushL(data);
   142 	
   143 	const TSize scrSize = iGc.Device()->SizeInPixels();	
   144 
   145 	// Decide what size the bitmaps should be
   146 	TRect extendedRect;
   147 	extendedRect.SetRect(10,10,(scrSize.iWidth>>1)-10,scrSize.iHeight-10);
   148 	TRect standardRect(extendedRect);
   149 	standardRect.Move(scrSize.iWidth>>1,0);
   150 	const TSize sizeInPixels(extendedRect.Width(),extendedRect.Height());
   151 
   152 	// Rects used for scaling tests
   153 	TRect scaledExtendedRect = extendedRect;
   154 	scaledExtendedRect.SetWidth(sizeInPixels.iWidth*3/4);
   155 	scaledExtendedRect.SetHeight(sizeInPixels.iHeight*3/5);
   156 	TRect scaledStandardRect = standardRect;
   157 	scaledStandardRect.SetWidth(sizeInPixels.iWidth*3/4);
   158 	scaledStandardRect.SetHeight(sizeInPixels.iHeight*3/5);
   159 
   160 	// Positions for drawing extended and normal bitmaps
   161 	TPoint bmpExPos(10,10);
   162 	TPoint bmpNmlPos(10+(scrSize.iWidth>>1),10);
   163 
   164 	// Use black and white vertical stripes as the data for the mask
   165 	WriteExtendedBitmapInfoL(data, dataSize, KMaskColors, KMaskBitmapStripeStyle);
   166 
   167 	// Create an extended bitmap to use as a mask
   168 	CFbsBitmap* bmpMaskEx = new(ELeave) CFbsBitmap;
   169 	CleanupStack::PushL(bmpMaskEx);
   170 	TInt err = bmpMaskEx->CreateExtendedBitmap(sizeInPixels, iDisplayMode, KUidExampleExtendedBitmap, data, dataSize);
   171 	iCallBack->TestTrue(err == KErrNone);
   172 
   173 	// Create a normal mask bitmap to use when testing the extended mask bitmap above
   174 	CFbsBitmap* bmpMaskNml;
   175 	CreateTestBitmapLC(bmpMaskNml, sizeInPixels, iDisplayMode, KRgbBlack, KRgbWhite, KRgbBlack, KMaskBitmapStripeStyle);
   176 
   177 	// Use dark grey and grey horizontal stripes as the data for the alpha bitmap
   178 	WriteExtendedBitmapInfoL(data, dataSize, KAlphaColors, KAlphaBitmapStripeStyle);
   179 
   180 	// Create an EGray256 extended bitmap to use when alpha blending
   181 	CFbsBitmap* bmpAlphaEx = new(ELeave) CFbsBitmap;
   182 	CleanupStack::PushL(bmpAlphaEx);
   183 	err = bmpAlphaEx->CreateExtendedBitmap(sizeInPixels, EGray256, KUidExampleExtendedBitmap, data, dataSize);
   184 	iCallBack->TestTrue(err == KErrNone);
   185 
   186 	// Create a normal EGray256 alpha bitmap to use when testing the extended alpha bitmap above
   187 	CFbsBitmap* bmpAlphaNml;
   188 	CreateTestBitmapLC(bmpAlphaNml, sizeInPixels, EGray256, KRgbDarkGray, KRgbGray, KRgbDarkGray, KAlphaBitmapStripeStyle);
   189 
   190 	// Create a clipping region and a clipping rect, making sure the shape of the region
   191 	// that is set is the same on both sides of the screen
   192 	const TInt KStripeSize = ((scrSize.iWidth>=300)&&(scrSize.iHeight>=100))?50:30;
   193 	TRegionFix<8> clippingRegion;
   194 	clippingRegion.AddRect(TRect(TPoint(0,0), TSize(scrSize.iWidth,KStripeSize)));
   195 	clippingRegion.AddRect(TRect(TPoint(0,scrSize.iHeight>>1), TSize(scrSize.iWidth,KStripeSize)));
   196 	clippingRegion.AddRect(TRect(TPoint(KStripeSize,0), TSize(KStripeSize<<1,scrSize.iHeight)));
   197 	clippingRegion.AddRect(TRect(TPoint((scrSize.iWidth>>1)+KStripeSize,0), TSize(KStripeSize<<1,scrSize.iHeight)));
   198 	iCallBack->TestTrue(clippingRegion.CheckError() == EFalse);
   199 	TRect clippingRect(TPoint(0,KStripeSize>>1), TSize(scrSize.iWidth,scrSize.iHeight-KStripeSize));
   200 
   201 	// Write the colours to be used in the extended bitmap to the extended bitmap data,
   202 	// we run the tests one with horizontal stripes and once with vertical stripes
   203 	WriteExtendedBitmapInfoL(data, dataSize, KColors, aStripeStyle);
   204 
   205 	// Create an extended bitmap
   206 	CFbsBitmap* bmpEx = new(ELeave) CFbsBitmap;
   207 	CleanupStack::PushL(bmpEx);
   208 	err = bmpEx->CreateExtendedBitmap(sizeInPixels, iDisplayMode, KUidExampleExtendedBitmap, data, dataSize);
   209 	iCallBack->TestTrue(err == KErrNone);
   210 
   211 	// Create a normal bitmap to use when testing the extended bitmap above
   212 	CFbsBitmap* bmpNml;
   213 	CreateTestBitmapLC(bmpNml, sizeInPixels, iDisplayMode, KColors[0], KColors[1], KColors[2], aStripeStyle);
   214 
   215 	// Clear to red
   216 	iGc.SetBrushColor(KRgbRed);
   217 	iGc.Clear();
   218 
   219 	if (aTestRegionOfInterest)
   220 		{
   221 		iGc.SetClippingRegion(clippingRegion);
   222 		iGc.SetClippingRect(clippingRect);
   223 		}
   224 
   225 	// Draw the extended bitmap(s) on the left side of the screen and the normal bitmap(s) on the
   226 	// right side of the screen in each case
   227 	switch (aCaseNumber)
   228 		{
   229 		case 0:
   230 			{
   231 			INFO_PRINTF3(_L("Stripe style %S. Region of interest %S"), &KStripeStyle[aStripeStyle], &KRegionStyle[aTestRegionOfInterest]);
   232 			INFO_PRINTF1(_L("... BitBlt()"));
   233 			iGc.BitBlt(bmpExPos, bmpEx);
   234 			iGc.BitBlt(bmpNmlPos, bmpNml);
   235 			break;
   236 			}
   237 		case 1:
   238 			{
   239 			INFO_PRINTF1(_L("... BitBltMasked()"));
   240 			iGc.BitBltMasked(bmpExPos, bmpEx, sizeInPixels, bmpMaskEx, EFalse);
   241 			iGc.BitBltMasked(bmpNmlPos, bmpNml, sizeInPixels, bmpMaskNml, EFalse);
   242 			break;
   243 			}
   244 		case 2:
   245 			{
   246 			INFO_PRINTF1(_L("... DrawBitmap()"));
   247 			iGc.DrawBitmap(extendedRect, bmpEx);
   248 			iGc.DrawBitmap(standardRect, bmpNml);
   249 			break;
   250 			}
   251 		case 3:
   252 			{
   253 			INFO_PRINTF1(_L("... DrawBitmap() with scaling"));
   254 			iGc.DrawBitmap(scaledExtendedRect, bmpEx);
   255 			iGc.DrawBitmap(scaledStandardRect, bmpNml);
   256 			break;
   257 			}
   258 		case 4:
   259 			{
   260 			INFO_PRINTF1(_L("... DrawBitmapMasked()"));
   261 			iGc.DrawBitmapMasked(extendedRect, bmpEx, sizeInPixels, bmpMaskEx, EFalse);
   262 			iGc.DrawBitmapMasked(standardRect, bmpNml, sizeInPixels, bmpMaskNml, EFalse);
   263 			break;
   264 			}
   265 		case 5:
   266 			{
   267 			INFO_PRINTF1(_L("... DrawBitmapMasked() with scaling"));
   268 			iGc.DrawBitmapMasked(scaledExtendedRect, bmpEx, sizeInPixels, bmpMaskEx, EFalse);
   269 			iGc.DrawBitmapMasked(scaledStandardRect, bmpNml, sizeInPixels, bmpMaskNml, EFalse);
   270 			break;
   271 			}
   272 		case 6:
   273 			{
   274 			if(iIsFbs)
   275 				{
   276 				CFbsBitGc& fbsGc = static_cast<CFbsBitGc&>(iGc);
   277 				INFO_PRINTF1(_L("... AlphaBlendBitmaps() - 1"));
   278 				iCallBack->TestTrue(fbsGc.AlphaBlendBitmaps(bmpExPos, bmpEx, bmpMaskEx, sizeInPixels, TPoint(0,0), bmpAlphaEx, TPoint(0,0)) == KErrNone);
   279 				iCallBack->TestTrue(fbsGc.AlphaBlendBitmaps(bmpNmlPos, bmpNml, bmpMaskNml, sizeInPixels, TPoint(0,0), bmpAlphaNml, TPoint(0,0)) == KErrNone);
   280 				}
   281 			break;
   282 			}
   283 		case 7:
   284 			{
   285 			if(iIsFbs)
   286 				{
   287 				CFbsBitGc& fbsGc = static_cast<CFbsBitGc&>(iGc);
   288 				INFO_PRINTF1(_L("... AlphaBlendBitmaps() - 1 with offset"));
   289 				iCallBack->TestTrue(fbsGc.AlphaBlendBitmaps(bmpExPos, bmpEx, bmpMaskEx, TSize(sizeInPixels.iWidth-5, sizeInPixels.iHeight-10), TPoint(5,10), bmpAlphaEx, TPoint(3,2)) == KErrNone);
   290 				iCallBack->TestTrue(fbsGc.AlphaBlendBitmaps(bmpNmlPos, bmpNml, bmpMaskNml, TSize(sizeInPixels.iWidth-5, sizeInPixels.iHeight-10), TPoint(5,10), bmpAlphaNml, TPoint(3,2)) == KErrNone);
   291 				}
   292 			break;
   293 			}
   294 		case 8:
   295 			{
   296 			INFO_PRINTF1(_L("... AlphaBlendBitmaps() - 2"));
   297 			iCallBack->TestTrue(iGc.AlphaBlendBitmaps(bmpExPos, bmpEx, sizeInPixels, bmpAlphaEx, TPoint(0,0)) == KErrNone);
   298 			iCallBack->TestTrue(iGc.AlphaBlendBitmaps(bmpNmlPos, bmpNml, sizeInPixels, bmpAlphaNml, TPoint(0,0)) == KErrNone);
   299 			break;
   300 			}
   301 		case 9:
   302 			{
   303 			INFO_PRINTF1(_L("... AlphaBlendBitmaps() - 2 with offset"));
   304 			iCallBack->TestTrue(iGc.AlphaBlendBitmaps(bmpExPos, bmpEx, TSize(sizeInPixels.iWidth-16, sizeInPixels.iHeight-7), bmpAlphaEx, TPoint(16,7)) == KErrNone);
   305 			iCallBack->TestTrue(iGc.AlphaBlendBitmaps(bmpNmlPos, bmpNml, TSize(sizeInPixels.iWidth-16, sizeInPixels.iHeight-7), bmpAlphaNml, TPoint(16,7)) == KErrNone);
   306 			break;
   307 			}
   308 		default:
   309 			{
   310 			// Should not be reached
   311 			iCallBack->TestTrue(EFalse);
   312 			}
   313 			break;
   314 		}
   315 
   316 	if (aTestRegionOfInterest)
   317 		{
   318 		// Cancel clipping rectangle and region if necessary
   319 		iGc.CancelClippingRegion();
   320 		iGc.CancelClippingRect();
   321 		}
   322 		
   323 	CleanupStack::PopAndDestroy(7, data);
   324 	}
   325 
   326 /** Test case function used to test the use of Extended Bitmaps as brush patterns within graphics contexts.
   327 Utilised by GRAPHICS-BITGDI-0103 to test with CFbsBitGc, and by GRAPHICS-WSERV-0493 with CWindowGc.
   328 @param aCaseNumber Case number to run - between 0 and (KNumBrushPatternTests - 1)
   329  */
   330 void CTExtendedBitmapGc::TestBrushPatternL(TInt aCaseNumber)
   331 	{	
   332 	const TInt KNumColors = 3;
   333 	const TRgb KColors[KNumColors] = {TRgb(0,255,255), TRgb(255,0,255), TRgb(255,255,0)};
   334 	const TSize KBrushSize(63,63);		
   335 	TInt dataSize = sizeof(KColors)+sizeof(TUint8); // estimate the data size
   336 	TUint8* data = new(ELeave) TUint8[dataSize];
   337 	CleanupStack::PushL(data);	
   338 	
   339 	// Write the colours to be used in the extended bitmap to the data	
   340 	WriteExtendedBitmapInfoL(data, dataSize, KColors, EHorizontalStripe);	
   341 	
   342 	// Create the extended bitmap to be used a a brush
   343 	CFbsBitmap* extendedBmp = new(ELeave) CFbsBitmap;
   344 	CleanupStack::PushL(extendedBmp);
   345 	TInt err = extendedBmp->CreateExtendedBitmap(KBrushSize, iDisplayMode, KUidExampleExtendedBitmap, data, dataSize);
   346 	iCallBack->TestTrue(err == KErrNone);
   347 	
   348 	// Create the standard bitmap to also be used as a brush
   349 	CFbsBitmap* standardBmp = new(ELeave) CFbsBitmap;
   350 	CleanupStack::PushL(standardBmp);
   351 	err = standardBmp->Create(KBrushSize, iDisplayMode);
   352 	iCallBack->TestTrue(err == KErrNone);
   353 	
   354 	// Create a bitmap device and a context so that the flag pattern can be drawn on
   355 	// the standard bitmap
   356 	CFbsBitmapDevice* bitDev = CFbsBitmapDevice::NewL(standardBmp);
   357 	CleanupStack::PushL(bitDev);
   358 	CFbsBitGc* bitGc;
   359 	err = bitDev->CreateContext(bitGc);
   360 	iCallBack->TestTrue(err == KErrNone);
   361 	CleanupStack::PushL(bitGc);
   362 	
   363 	// Draw the flag pattern to the standard bitmap if the draw mode is EDrawFlag, 
   364 	// leave as white otehrwise
   365 	if (iDrawMode == EDrawFlag)
   366 		{
   367 		bitGc->SetPenStyle(CGraphicsContext::ENullPen);
   368 		bitGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
   369 		for (TInt i = 0; i < KNumColors; i++)
   370 			{
   371 			bitGc->SetBrushColor(KColors[i]);
   372 			bitGc->DrawRect(TRect(0,(KBrushSize.iHeight/3)*i,KBrushSize.iWidth,(KBrushSize.iHeight/3)*(i+1)));	
   373 			}
   374 		}	
   375 	CleanupStack::PopAndDestroy(2, bitDev);
   376 	
   377 	// Create a screen device and a context to draw to
   378 	TSize scrSize = iGc.Device()->SizeInPixels();
   379 		
   380 	TRect extendedShapeSize;
   381 	extendedShapeSize.SetRect(10,10,(scrSize.iWidth>>1)-10,scrSize.iHeight-10);
   382 	TRect standardShapeSize(extendedShapeSize);
   383 	standardShapeSize.Move(scrSize.iWidth>>1,0);
   384 
   385 	TInt baseline = extendedShapeSize.Height() / 2 + iFont->AscentInPixels() / 2;
   386 	
   387 	iGc.SetBrushColor(KRgbBlue);
   388 	iGc.Clear();
   389 	iGc.SetBrushColor(KRgbWhite);		
   390 	iGc.UseBrushPattern(extendedBmp);
   391 	iGc.SetBrushStyle(CGraphicsContext::EPatternedBrush);		
   392 	
   393 	switch (aCaseNumber)
   394 		{
   395 		case 0: //DrawPie()
   396 			{
   397 			INFO_PRINTF1(_L("Testing brush patterns with an extended bitmap"));
   398 			INFO_PRINTF1(_L("... DrawPie()"));
   399 			iGc.DrawPie(extendedShapeSize, TPoint(extendedShapeSize.iTl.iX,0), TPoint(extendedShapeSize.iBr.iX,0));				
   400 			iGc.UseBrushPattern(standardBmp);					
   401 			iGc.DrawPie(standardShapeSize, TPoint(standardShapeSize.iTl.iX,0), TPoint(standardShapeSize.iBr.iX,0));				
   402 			break;
   403 			}
   404 		case 1: // DrawRoundRect()
   405 			{
   406 			INFO_PRINTF1(_L("... DrawRoundRect()"));
   407 			iGc.DrawRoundRect(extendedShapeSize, TSize(10,10));				
   408 			iGc.UseBrushPattern(standardBmp);				
   409 			iGc.DrawRoundRect(standardShapeSize, TSize(10,10));
   410 			break;
   411 			}
   412 		case 2: // DrawPolygon() 
   413 			{
   414 			INFO_PRINTF1(_L("... DrawPolygon() 1"));
   415 			const TInt KNumPoints = 3;
   416 			CArrayFix<TPoint>* points = new(ELeave) CArrayFixFlat<TPoint>(KNumPoints);
   417 			CleanupStack::PushL(points);
   418 			points->AppendL(TPoint(extendedShapeSize.iTl.iX,extendedShapeSize.iTl.iY)); 
   419 			points->AppendL(TPoint(extendedShapeSize.iBr.iX,extendedShapeSize.iBr.iY));
   420 			points->AppendL(TPoint(extendedShapeSize.iTl.iX,extendedShapeSize.iBr.iY));
   421 			iGc.DrawPolygon(points, CGraphicsContext::EWinding);
   422 			iGc.UseBrushPattern(standardBmp);				
   423 			iGc.SetOrigin(TPoint(standardShapeSize.iTl.iX-10,0));
   424 			iGc.DrawPolygon(points, CGraphicsContext::EWinding);
   425 			iGc.SetOrigin(TPoint(0,0));
   426 			CleanupStack::PopAndDestroy(points);				
   427 			break;
   428 			}
   429 		case 3: // DrawPolygon()
   430 			{
   431 			INFO_PRINTF1(_L("... DrawPolygon() 2"));
   432 			const TInt KNumPoints = 3;
   433 			TPoint* points = static_cast<TPoint*>(User::AllocL(sizeof(TPoint)*KNumPoints));
   434 			CleanupStack::PushL(points);
   435 			points[0] = TPoint(extendedShapeSize.iBr.iX,extendedShapeSize.iTl.iY); 
   436 			points[1] = TPoint(extendedShapeSize.iBr.iX,extendedShapeSize.iBr.iY);
   437 			points[2] = TPoint(extendedShapeSize.iTl.iX,extendedShapeSize.iBr.iY/2);
   438 			iGc.DrawPolygon(points, KNumPoints, CGraphicsContext::EWinding);
   439 			iGc.UseBrushPattern(standardBmp);				
   440 			iGc.SetOrigin(TPoint(standardShapeSize.iTl.iX-10,0));
   441 			iGc.DrawPolygon(points, KNumPoints, CGraphicsContext::EWinding);
   442 			iGc.SetOrigin(TPoint(0,0));		
   443 			CleanupStack::PopAndDestroy(points);
   444 			break;
   445 			}
   446 		case 4: // DrawEllipse()
   447 			{
   448 			INFO_PRINTF1(_L("... DrawEllipse()"));
   449 			iGc.DrawEllipse(extendedShapeSize);
   450 			iGc.UseBrushPattern(standardBmp);				
   451 			iGc.DrawEllipse(standardShapeSize);
   452 			break;
   453 			}
   454 		case 5: // DrawRect()
   455 			{
   456 			INFO_PRINTF1(_L("... DrawRect()"));
   457 			iGc.DrawRect(extendedShapeSize);				
   458 			iGc.UseBrushPattern(standardBmp);				
   459 			iGc.DrawRect(standardShapeSize);
   460 			break;
   461 			}
   462 		case 6: // DrawText()
   463 			{
   464 			INFO_PRINTF1(_L("... DrawText()"));			
   465 			iGc.DrawText(_L("HELLO"), extendedShapeSize, baseline);
   466 			iGc.UseBrushPattern(standardBmp);
   467 			iGc.DrawText(_L("HELLO"), standardShapeSize, baseline);
   468 			break;
   469 			}
   470 		case 7: // DrawTextVertical()
   471 			{				
   472 			INFO_PRINTF1(_L("... DrawTextVertical()"));																		
   473 			iGc.DrawTextVertical(_L("HELLO"), extendedShapeSize, baseline, EFalse);
   474 			iGc.UseBrushPattern(standardBmp);
   475 			iGc.DrawTextVertical(_L("HELLO"), standardShapeSize, baseline, EFalse);
   476 			break;
   477 			}
   478 		default:
   479 			{
   480 			// Should not be reached
   481 			iCallBack->TestTrue(EFalse);
   482 			}
   483 		}			
   484 	CleanupStack::PopAndDestroy(3, data);
   485 	}
   486 
   487 /** Helper method for creating  and filling striped bitmaps equivalent to the extended bitmaps used in the test 
   488 CTExtendedBitmap::TestBitmapDrawingL().
   489 @param aBmpRet The newly created bitmap.
   490 @param aSize The size of the bitmap to create.
   491 @param aDisplayMode The display mode of the bitmap to create.
   492 @param aColor1 The colour of the first stripe.
   493 @param aColor2 The colour of the second stripe.
   494 @param aColor3 The colour of the third stripe.
   495 @param aStripeStyle Horizontal or vertical stripes, 0 for vertical stripe, 1 for horizontal stripes.
   496 @return KErrNone if the bitmap was created successfully and returned in aBmpRet, one of the system
   497 wide error codes otherwise. 
   498 @post Leaves aBmpRet on the clean up stack if it is created successfully 
   499  */
   500 void CTExtendedBitmapGc::CreateTestBitmapLC(CFbsBitmap*& aBmpRet,
   501 										const TSize& aSize,
   502 										TDisplayMode aDisplayMode, 
   503 										const TRgb& aColor1, 
   504 										const TRgb& aColor2, 
   505 										const TRgb& aColor3,
   506 										TStripeStyle aStripeStyle)
   507 	{
   508 	const TInt KNumColors = 3;
   509 	TRgb colors[3] = {aColor1, aColor2, aColor3};
   510 	
   511 	CFbsBitmap* bmp = new(ELeave) CFbsBitmap;
   512 	CleanupStack::PushL(bmp); // This gets left on the cleanup stack when the function returns
   513 	TInt err = bmp->Create(aSize, aDisplayMode);	
   514 	User::LeaveIfError(err);
   515 		
   516 	CFbsBitmapDevice* bmpDev = CFbsBitmapDevice::NewL(bmp);	
   517 	CleanupStack::PushL(bmpDev);	
   518 	CFbsBitGc* gc;
   519 	err = bmpDev->CreateContext(gc);
   520 	User::LeaveIfError(err);
   521 	CleanupStack::PushL(gc);
   522 	
   523 	// Only draw stripes onto the test bitmap if the draw mode is EDrawFlag, otherwise
   524 	// it should be left as cleared to white
   525 	if (iDrawMode == EDrawFlag)
   526 		{
   527 		TInt outerStripeSize;												
   528 		TInt middleStripeSize;							
   529 		TRect stripeRect[3];
   530 		
   531 		if (aStripeStyle == EHorizontalStripe)
   532 			{
   533 			outerStripeSize = aSize.iHeight/3;												
   534 			middleStripeSize = aSize.iHeight-(outerStripeSize<<1);							
   535 			stripeRect[0] = TRect(TPoint(0,0), TSize(aSize.iWidth,outerStripeSize));
   536 			stripeRect[1] = TRect(TPoint(0,outerStripeSize), TSize(aSize.iWidth,middleStripeSize));
   537 			stripeRect[2] = TRect(TPoint(0,outerStripeSize+middleStripeSize), TSize(aSize.iWidth,outerStripeSize));
   538 			}
   539 		else if (aStripeStyle == EVerticalStripe)
   540 			{
   541 			outerStripeSize = aSize.iWidth/3;												
   542 			middleStripeSize = aSize.iWidth-(outerStripeSize<<1);							
   543 			stripeRect[0] = TRect(TPoint(0,0), TSize(outerStripeSize,aSize.iHeight));
   544 			stripeRect[1] = TRect(TPoint(outerStripeSize,0), TSize(middleStripeSize,aSize.iHeight));
   545 			stripeRect[2] = TRect(TPoint(outerStripeSize+middleStripeSize,0), TSize(outerStripeSize,aSize.iHeight));
   546 			}
   547 		else
   548 			{
   549 			INFO_PRINTF2(_L("Unsupported stripe style passed to CTExtendedBitmap::CreateTestBitmapLC: %d"), aStripeStyle);
   550 			User::Leave(KErrArgument);
   551 			}
   552 		
   553 		for (TInt i = 0; i < KNumColors; i++)
   554 			{
   555 			gc->SetBrushColor(colors[i]);
   556 			gc->SetPenStyle(CGraphicsContext::ENullPen);
   557 			gc->SetBrushStyle(CGraphicsContext::ESolidBrush);			
   558 			gc->DrawRect(stripeRect[i]);
   559 			}		
   560 		}
   561 	
   562 	// Only pop the bitmap device and the gc, the created bitmap is left on the cleanup stack
   563 	CleanupStack::PopAndDestroy(2, bmpDev); 	
   564 	
   565 	aBmpRet = bmp; 	
   566 	}
   567 
   568 /** Helper function for writing colour and stripe information used when creating an extended bitmap to
   569 a write stream.
   570 @param aData A pointer to a buffer that is large enough to write three TRgb colours and one TUint8 to.
   571 @param aDataSize The size of buffer pointed to by aData, the actual size written is returned here
   572 @param aColourArray A pointer to an array of the three colours to be written to the buffer
   573 @param aHorizontalStripe ETrue to use horizontal stripes, EFalse for vertcial stripes
   574  */
   575 EXPORT_C void CTExtendedBitmapGc::WriteExtendedBitmapInfoL(TUint8* aData,
   576 												TInt& aDataSize,															
   577 												const TRgb* aColorArray, 
   578 												TStripeStyle aStripeStyle)
   579 	{
   580 	const TInt KNumColors = 3;
   581 
   582 	// We expect an array of three colours
   583 	if (sizeof(aColorArray) == (sizeof(TRgb)*KNumColors))
   584 		{		
   585 		User::Leave(KErrArgument);
   586 		}
   587 	
   588 	RMemWriteStream ws;
   589 	ws.Open(aData, aDataSize);
   590 	CleanupClosePushL(ws);
   591 	ws << aColorArray[0] << aColorArray[1] << aColorArray[2] << static_cast<TUint8>(aStripeStyle); // horizontal stripe
   592 	aDataSize = ws.Sink()->TellL(MStreamBuf::EWrite).Offset(); // get the actual size written
   593 	CleanupStack::PopAndDestroy(1, &ws);
   594 	}