os/graphics/graphicstest/graphicstestharness/textendedbitmapgc/textendedbitmapgc.cpp
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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #include "textendedbitmapgc.h"
19 const TInt KNumBitmapDrawingTests = 10;
20 const TInt KNumBrushPatternTests = 8;
21 const TUid KUidExampleExtendedBitmap = {0x10285A78};
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.
33 EXPORT_C CTExtendedBitmapGc* CTExtendedBitmapGc::NewL(MTestHarnessCallBack* aCallBack,
36 TDisplayMode aDisplayMode)
38 CTExtendedBitmapGc* ebgc = new(ELeave) CTExtendedBitmapGc(aCallBack, aGc, aDrawMode);
39 CleanupStack::PushL(ebgc);
40 ebgc->ConstructL(aDisplayMode);
41 CleanupStack::Pop(ebgc);
45 CTExtendedBitmapGc::CTExtendedBitmapGc(MTestHarnessCallBack* aCallBack,
47 TDrawMode aDrawMode) :
48 iCallBack(aCallBack), iDrawMode(aDrawMode), iGc(aGc), iIsFbs(aGc.IsFbsBitGc())
52 void CTExtendedBitmapGc::ConstructL(TDisplayMode aDisplayMode)
55 // Check that the display mode chosen is supported by the example rasterizer
56 if ((aDisplayMode != EGray256) && (aDisplayMode != EColor64K) && (aDisplayMode != EColor16MU) && (aDisplayMode != EColor16MAP))
58 INFO_PRINTF2(_L("Failed to construct CTExtendedBitmapGc with unsupported display mode %d"), aDisplayMode);
59 User::Leave(KErrNotSupported);
61 iDisplayMode = aDisplayMode;
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));
71 EXPORT_C CTExtendedBitmapGc::~CTExtendedBitmapGc()
76 static_cast<CBitmapDevice*>(iGc.Device())->ReleaseFont(iFont);
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
84 EXPORT_C void CTExtendedBitmapGc::RunTestCaseL(TInt aCurTestCase)
87 switch(aCurTestCase / KNumBitmapDrawingTests)
90 TestBitmapDrawingL(EFalse, EVerticalStripe, aCurTestCase % KNumBitmapDrawingTests);
93 TestBitmapDrawingL(EFalse, EHorizontalStripe, aCurTestCase % KNumBitmapDrawingTests);
96 TestBitmapDrawingL(ETrue, EVerticalStripe, aCurTestCase % KNumBitmapDrawingTests);
99 TestBitmapDrawingL(ETrue, EHorizontalStripe, aCurTestCase % KNumBitmapDrawingTests);
103 TInt brushCase = aCurTestCase - (4 * KNumBitmapDrawingTests);
104 if(brushCase < KNumBrushPatternTests)
106 TestBrushPatternL(brushCase);
111 iCallBack->TestComplete();
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)
123 void CTExtendedBitmapGc::TestBitmapDrawingL(TBool aTestRegionOfInterest, TStripeStyle aStripeStyle, TInt aCaseNumber)
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)};
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;
139 TInt dataSize = sizeof(KColors)+sizeof(TUint8); // estimate the data size
140 TUint8* data = new(ELeave) TUint8[dataSize];
141 CleanupStack::PushL(data);
143 const TSize scrSize = iGc.Device()->SizeInPixels();
145 // Decide what size the bitmaps should be
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());
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);
160 // Positions for drawing extended and normal bitmaps
161 TPoint bmpExPos(10,10);
162 TPoint bmpNmlPos(10+(scrSize.iWidth>>1),10);
164 // Use black and white vertical stripes as the data for the mask
165 WriteExtendedBitmapInfoL(data, dataSize, KMaskColors, KMaskBitmapStripeStyle);
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);
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);
177 // Use dark grey and grey horizontal stripes as the data for the alpha bitmap
178 WriteExtendedBitmapInfoL(data, dataSize, KAlphaColors, KAlphaBitmapStripeStyle);
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);
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);
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));
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);
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);
211 // Create a normal bitmap to use when testing the extended bitmap above
213 CreateTestBitmapLC(bmpNml, sizeInPixels, iDisplayMode, KColors[0], KColors[1], KColors[2], aStripeStyle);
216 iGc.SetBrushColor(KRgbRed);
219 if (aTestRegionOfInterest)
221 iGc.SetClippingRegion(clippingRegion);
222 iGc.SetClippingRect(clippingRect);
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
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);
239 INFO_PRINTF1(_L("... BitBltMasked()"));
240 iGc.BitBltMasked(bmpExPos, bmpEx, sizeInPixels, bmpMaskEx, EFalse);
241 iGc.BitBltMasked(bmpNmlPos, bmpNml, sizeInPixels, bmpMaskNml, EFalse);
246 INFO_PRINTF1(_L("... DrawBitmap()"));
247 iGc.DrawBitmap(extendedRect, bmpEx);
248 iGc.DrawBitmap(standardRect, bmpNml);
253 INFO_PRINTF1(_L("... DrawBitmap() with scaling"));
254 iGc.DrawBitmap(scaledExtendedRect, bmpEx);
255 iGc.DrawBitmap(scaledStandardRect, bmpNml);
260 INFO_PRINTF1(_L("... DrawBitmapMasked()"));
261 iGc.DrawBitmapMasked(extendedRect, bmpEx, sizeInPixels, bmpMaskEx, EFalse);
262 iGc.DrawBitmapMasked(standardRect, bmpNml, sizeInPixels, bmpMaskNml, EFalse);
267 INFO_PRINTF1(_L("... DrawBitmapMasked() with scaling"));
268 iGc.DrawBitmapMasked(scaledExtendedRect, bmpEx, sizeInPixels, bmpMaskEx, EFalse);
269 iGc.DrawBitmapMasked(scaledStandardRect, bmpNml, sizeInPixels, bmpMaskNml, EFalse);
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);
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);
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);
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);
310 // Should not be reached
311 iCallBack->TestTrue(EFalse);
316 if (aTestRegionOfInterest)
318 // Cancel clipping rectangle and region if necessary
319 iGc.CancelClippingRegion();
320 iGc.CancelClippingRect();
323 CleanupStack::PopAndDestroy(7, data);
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)
330 void CTExtendedBitmapGc::TestBrushPatternL(TInt aCaseNumber)
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);
339 // Write the colours to be used in the extended bitmap to the data
340 WriteExtendedBitmapInfoL(data, dataSize, KColors, EHorizontalStripe);
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);
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);
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);
359 err = bitDev->CreateContext(bitGc);
360 iCallBack->TestTrue(err == KErrNone);
361 CleanupStack::PushL(bitGc);
363 // Draw the flag pattern to the standard bitmap if the draw mode is EDrawFlag,
364 // leave as white otehrwise
365 if (iDrawMode == EDrawFlag)
367 bitGc->SetPenStyle(CGraphicsContext::ENullPen);
368 bitGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
369 for (TInt i = 0; i < KNumColors; i++)
371 bitGc->SetBrushColor(KColors[i]);
372 bitGc->DrawRect(TRect(0,(KBrushSize.iHeight/3)*i,KBrushSize.iWidth,(KBrushSize.iHeight/3)*(i+1)));
375 CleanupStack::PopAndDestroy(2, bitDev);
377 // Create a screen device and a context to draw to
378 TSize scrSize = iGc.Device()->SizeInPixels();
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);
385 TInt baseline = extendedShapeSize.Height() / 2 + iFont->AscentInPixels() / 2;
387 iGc.SetBrushColor(KRgbBlue);
389 iGc.SetBrushColor(KRgbWhite);
390 iGc.UseBrushPattern(extendedBmp);
391 iGc.SetBrushStyle(CGraphicsContext::EPatternedBrush);
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));
404 case 1: // DrawRoundRect()
406 INFO_PRINTF1(_L("... DrawRoundRect()"));
407 iGc.DrawRoundRect(extendedShapeSize, TSize(10,10));
408 iGc.UseBrushPattern(standardBmp);
409 iGc.DrawRoundRect(standardShapeSize, TSize(10,10));
412 case 2: // DrawPolygon()
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);
429 case 3: // DrawPolygon()
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);
446 case 4: // DrawEllipse()
448 INFO_PRINTF1(_L("... DrawEllipse()"));
449 iGc.DrawEllipse(extendedShapeSize);
450 iGc.UseBrushPattern(standardBmp);
451 iGc.DrawEllipse(standardShapeSize);
454 case 5: // DrawRect()
456 INFO_PRINTF1(_L("... DrawRect()"));
457 iGc.DrawRect(extendedShapeSize);
458 iGc.UseBrushPattern(standardBmp);
459 iGc.DrawRect(standardShapeSize);
462 case 6: // DrawText()
464 INFO_PRINTF1(_L("... DrawText()"));
465 iGc.DrawText(_L("HELLO"), extendedShapeSize, baseline);
466 iGc.UseBrushPattern(standardBmp);
467 iGc.DrawText(_L("HELLO"), standardShapeSize, baseline);
470 case 7: // DrawTextVertical()
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);
480 // Should not be reached
481 iCallBack->TestTrue(EFalse);
484 CleanupStack::PopAndDestroy(3, data);
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
500 void CTExtendedBitmapGc::CreateTestBitmapLC(CFbsBitmap*& aBmpRet,
502 TDisplayMode aDisplayMode,
506 TStripeStyle aStripeStyle)
508 const TInt KNumColors = 3;
509 TRgb colors[3] = {aColor1, aColor2, aColor3};
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);
516 CFbsBitmapDevice* bmpDev = CFbsBitmapDevice::NewL(bmp);
517 CleanupStack::PushL(bmpDev);
519 err = bmpDev->CreateContext(gc);
520 User::LeaveIfError(err);
521 CleanupStack::PushL(gc);
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)
527 TInt outerStripeSize;
528 TInt middleStripeSize;
531 if (aStripeStyle == EHorizontalStripe)
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));
539 else if (aStripeStyle == EVerticalStripe)
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));
549 INFO_PRINTF2(_L("Unsupported stripe style passed to CTExtendedBitmap::CreateTestBitmapLC: %d"), aStripeStyle);
550 User::Leave(KErrArgument);
553 for (TInt i = 0; i < KNumColors; i++)
555 gc->SetBrushColor(colors[i]);
556 gc->SetPenStyle(CGraphicsContext::ENullPen);
557 gc->SetBrushStyle(CGraphicsContext::ESolidBrush);
558 gc->DrawRect(stripeRect[i]);
562 // Only pop the bitmap device and the gc, the created bitmap is left on the cleanup stack
563 CleanupStack::PopAndDestroy(2, bmpDev);
568 /** Helper function for writing colour and stripe information used when creating an extended bitmap to
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
575 EXPORT_C void CTExtendedBitmapGc::WriteExtendedBitmapInfoL(TUint8* aData,
577 const TRgb* aColorArray,
578 TStripeStyle aStripeStyle)
580 const TInt KNumColors = 3;
582 // We expect an array of three colours
583 if (sizeof(aColorArray) == (sizeof(TRgb)*KNumColors))
585 User::Leave(KErrArgument);
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);