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