Update contrib.
1 // Copyright (c) 2007-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 "tdrawbitmapmasked.h"
18 CTDrawBitmapMasked::CTDrawBitmapMasked()
20 SetTestStepName(KTDirectGdiDrawBitmapMaskedStep);
23 CTDrawBitmapMasked::~CTDrawBitmapMasked()
28 Override of base class pure virtual
29 Lists the tests to be run
31 void CTDrawBitmapMasked::RunTestsL()
33 if (iUseDirectGdi && !iUseSwDirectGdi)
35 // In the event that a test leaves after a BitBlt() or DrawBitmap() has occurred
36 // the vgimage cache will need to be reset.
37 // This needs to be the first item on the cleanupstack,
38 // as some tests perform pushes and pops of bitmaps.
39 CleanupStack::PushL(TCleanupItem(ResetCache, iVgImageCache));
43 // to minimize tests call number these tests are processed only for one mask
46 SetTestStepID(_L("GRAPHICS-DIRECTGDI-DRAWBITMAPMASKED-0003"));
47 TestInvalidParametersL();
49 SetTestStepID(_L("GRAPHICS-DIRECTGDI-DRAWBITMAPMASKED-0005"));
50 TestSourceBitmapCloningL();
52 SetTestStepID(_L("GRAPHICS-DIRECTGDI-DRAWBITMAPMASKED-0006"));
60 iTestParams.iDoCompressed = ETrue;
61 SetTestStepID(_L("GRAPHICS-DIRECTGDI-DRAWBITMAPMASKED-0001"));
64 iTestParams.iDoCompressed = EFalse;
65 SetTestStepID(_L("GRAPHICS-DIRECTGDI-DRAWBITMAPMASKED-0007"));
68 SetTestStepID(_L("GRAPHICS-DIRECTGDI-DRAWBITMAPMASKED-0008"));
69 TestWithSameBitmapsL();
71 SetTestStepID(_L("GRAPHICS-DIRECTGDI-DRAWBITMAPMASKED-0009"));
77 SetTestStepID(_L("GRAPHICS-DIRECTGDI-DRAWBITMAPMASKED-0002"));
80 SetTestStepID(_L("GRAPHICS-DIRECTGDI-DRAWBITMAPMASKED-0004"));
84 if (iMaskType == EMaskL8)
86 iTestParams.iDoCompressed = ETrue;
87 SetTestStepID(_L("GRAPHICS-DIRECTGDI-DRAWBITMAPMASKED-0004"));
90 iTestParams.iDoCompressed = EFalse;
94 while(NextMaskIteration());
95 if (iUseDirectGdi && !iUseSwDirectGdi)
97 CleanupStack::PopAndDestroy(iVgImageCache);
103 GRAPHICS-DIRECTGDI-DRAWBITMAPMASKED-0001
120 Bitmap drawing with masking basic functionality test.
129 Test bitmap drawing with masking for simple and valid parameters.
131 @SYMTestExpectedResults
132 Source bitmap should be drawn masked in the target area. Valid bitmap
133 should be created. This bitmap shall be compared to a reference bitmap.
135 void CTDrawBitmapMasked::TestBasicL()
137 _LIT(KTestName, "DrawBitmapMasked-Basic");
138 if(!iRunningOomTests)
140 INFO_PRINTF1(KTestName);
147 if(iTestParams.iDoCompressed)
149 bitmap = iCompressedBitmap;
150 mask = iCompressedMaskL8;
154 bitmap = iCheckedBoardBitmap2;
155 mask = iCurrentMask1;
158 TSize bmpSize(bitmap->SizeInPixels());
160 iGc->DrawBitmapMasked(TRect(TPoint(20, 20), bmpSize), *bitmap, TRect(TPoint(0, 0), bmpSize), *mask, iInvertMask);
162 TESTNOERRORL(iGc->GetError());
163 if(!iTestParams.iDoCompressed)
164 WriteTargetOutput(KTestName());
169 GRAPHICS-DIRECTGDI-DRAWBITMAPMASKED-0002
186 Test regularity of bitmap with masking positioning.
195 Test positioning functionality of DrawBitmapMasked() methods.
196 Test boundary conditions and clipping to surface area.
198 @SYMTestExpectedResults
200 void CTDrawBitmapMasked::TestPositioningL()
202 _LIT(KTestName, "DrawBitmapMasked-Positioning");
203 if(!iRunningOomTests)
205 INFO_PRINTF1(KTestName);
208 iTestParams.iDoCompressed = ETrue;
209 TestPositioningBaseL(KTestName(), EDrawBitmapMasked);
210 iTestParams.iDoCompressed = EFalse;
211 TestPositioningBaseL(KTestName(), EDrawBitmapMasked);
216 GRAPHICS-DIRECTGDI-DRAWBITMAPMASKED-0003
231 Test functions behaviour after calling with invalid parameters.
240 Replace valid parameters with invalid ones:
244 see DrawBitmap-InvalidParameters for rest of invalid parameters.
246 @SYMTestExpectedResults
247 Function should detect invalid parameters and return. Nothing should be
248 drawn in target area.
250 void CTDrawBitmapMasked::TestInvalidParametersL()
252 _LIT(KTestName, "DrawBitmapMasked-InvalidParameters");
253 if(!iRunningOomTests)
255 INFO_PRINTF1(KTestName);
258 TestInvalidParametersBaseL(KTestName(), EDrawBitmapMasked);
263 GRAPHICS-DIRECTGDI-DRAWBITMAPMASKED-0004
280 Test regularity of bitmap scaling.
289 Test scaling down and up of a source bitmap. Test scaling down and tiling of a mask.
291 @SYMTestExpectedResults
292 Scaled bitmap should be drawn in a target area. Masking should be proceeded
293 correctly. Valid bitmap should be created. The bitmap should be properly
294 scaled. This bitmap shall be compared to a reference bitmap.
296 void CTDrawBitmapMasked::TestScalingL()
298 _LIT(KTestName, "DrawBitmapMasked-Scaling");
299 if(!iRunningOomTests)
301 INFO_PRINTF1(KTestName);
304 TInt width = iGdiTarget->SizeInPixels().iWidth;
305 TInt height = iGdiTarget->SizeInPixels().iHeight;
307 CFbsBitmap* bitmap1 = NULL;
308 CFbsBitmap* bitmap2 = NULL;
309 CFbsBitmap* mask = NULL;
310 if(iTestParams.iDoCompressed)
312 bitmap1 = iCompressedBitmapSmall;
313 bitmap2 = iCompressedBitmap;
314 mask = iCompressedMaskL8;
318 bitmap1 = iCheckedBoardBitmap1;
319 bitmap2 = iCheckedBoardBitmap2;
320 mask = iCurrentMask1;
322 TInt bmp1Width = bitmap1->SizeInPixels().iWidth;
323 TInt bmp1Height = bitmap1->SizeInPixels().iHeight;
325 TInt bmp2Width = bitmap2->SizeInPixels().iWidth;
326 TInt bmp2Height = bitmap2->SizeInPixels().iHeight;
330 // small bitmap - extreme magnification
331 TReal32 scale = 1.0f;
332 TReal32 scaleFactor = 1.55f;
334 for(TInt jj=0; jj<6; jj++)
336 TSize size(static_cast<TInt>(bmp1Width*scale), static_cast<TInt>(bmp1Height*scale));
337 TPoint pos(posX, height/4-size.iHeight/2);
339 iGc->DrawBitmapMasked(TRect(pos, size), *bitmap1,
340 TRect(TPoint(0, 0), TSize(bmp1Width, bmp1Height)), *mask, iInvertMask);
342 posX += size.iWidth+2;
343 scale *= scaleFactor;
346 // large bitmap - extreme minification
347 scale /= scaleFactor;
349 for(TInt jj=5; jj>=0; jj--)
351 TSize size(static_cast<TInt>(bmp1Width*scale), static_cast<TInt>(bmp1Height*scale));
352 TPoint pos(posX, 3*height/4-size.iHeight/2);
354 iGc->DrawBitmapMasked(TRect(pos, size), *bitmap2,
355 TRect(TPoint(0, 0), bitmap2->SizeInPixels()), *mask, iInvertMask);
357 posX += size.iWidth+2;
358 scale /= scaleFactor;
361 TESTNOERRORL(iGc->GetError());
363 WriteTargetOutput(KTestName());
368 GRAPHICS-DIRECTGDI-DRAWBITMAPMASKED-0005
385 Deleting source bitmap object after issuing draw bitmap with masking requests.
394 1. Call method with valid parameters (see DrawBitmapMasked-Basic).
395 2. Right after returning from method call, destroy the source bitmap.
396 3. Call the method again with the same bitmap parameter.
397 Repeat p. 1-3 a few times.
399 @SYMTestExpectedResults
400 Source bitmap should be copied into target area. Memory leaks should not
401 be created. Valid bitmap should be created. This bitmap should be the same
402 as a reference bitmap.
404 void CTDrawBitmapMasked::TestSourceBitmapCloningL()
406 _LIT(KTestName, "DrawBitmapMasked-SourceBitmapCloning");
407 if(!iRunningOomTests)
409 INFO_PRINTF1(KTestName);
412 iTestParams.iDoCompressed = ETrue;
413 TestSourceBitmapCloningBaseL(KTestName(), EDrawBitmapMasked);
414 iTestParams.iDoCompressed = EFalse;
415 TestSourceBitmapCloningBaseL(KTestName(), EDrawBitmapMasked);
420 GRAPHICS-DIRECTGDI-DRAWBITMAPMASKED-0006
437 Deleting mask objects after issuing draw bitmap with masking request.
446 1. Call DrawBitmapMasked() method with valid parameters (see DrawBitmapMasked-Basic).
447 2. Right after returning from DrawBitmapMasked() call, destroy the source mask (aMaskBitmap).
448 3. Call the DrawBitmapMasked() method again with the same mask parameter.
449 Repeat p. 1-3 a few times.
451 @SYMTestExpectedResults
452 Source bitmap should be copied into target area based on a mask data.
453 Memory leaks should not be created. Valid bitmap should be created. This bitmap
454 should be the same as a reference bitmap.
456 void CTDrawBitmapMasked::TestMaskCloningL()
458 _LIT(KTestName, "DrawBitmapMasked-MaskCloning");
459 if(!iRunningOomTests)
461 INFO_PRINTF1(KTestName);
464 iTestParams.iDoCompressed = ETrue;
465 TestMaskCloningBaseL(KTestName(), EDrawBitmapMasked);
466 iTestParams.iDoCompressed = EFalse;
467 TestMaskCloningBaseL(KTestName(), EDrawBitmapMasked);
472 GRAPHICS-DIRECTGDI-DRAWBITMAPMASKED-0007
489 Test correctness of bitmap drawing with mask in all possible draw modes.
498 Set valid parameters (see DrawBitmapMasked-Basic).
499 Use the semi-transparent source bitmap (aBitmap).
500 Set drawmode to EDrawModeWriteAlpha and call the methods.
501 Set drawmode to EDrawModePEN and call the methods.
502 Set drawmode to EDrawModeWriteAlpha and call the methods.
504 @SYMTestExpectedResults
505 The image drawn in the center should be drawn masked and blended
506 (EDrawModePEN) and the images at the right and left should be drawn masked and
507 opaque (EDrawModeWriteAlpha). Valid bitmap should be created.
508 This bitmap should be the same as a reference bitmap.
510 void CTDrawBitmapMasked::TestDrawModeL()
512 _LIT(KTestName, "DrawBitmapMasked-DrawMode");
513 if(!iRunningOomTests)
515 INFO_PRINTF1(KTestName);
520 TSize bmpSize(iCheckedBoardWithAlphaBitmap->SizeInPixels());
522 TInt halfHeight = (bmpSize.iHeight >> 1);
523 TInt quaterWidth = (bmpSize.iWidth >> 2);
524 TInt y1 = halfHeight - (bmpSize.iHeight >> 2);
525 TSize vertRectSize (quaterWidth, bmpSize.iHeight);
526 TSize horizRectSize (bmpSize.iWidth, halfHeight);
528 // EDrawModeWriteAlpha is not supported in the following modes
529 // This is tested under invalid parameter tests.
530 if (!((iMaskPixelFormat == EUidPixelFormatL_8) &&
531 ((iTestParams.iSourcePixelFormat == EUidPixelFormatARGB_8888) ||
532 (iTestParams.iSourcePixelFormat == EUidPixelFormatARGB_8888_PRE))))
534 // Render column to left
535 iGc->SetDrawMode(DirectGdi::EDrawModeWriteAlpha);
536 iGc->DrawBitmapMasked(
537 TRect (TPoint(0, 0), vertRectSize),
538 *iCheckedBoardWithAlphaBitmap,
539 TRect(TPoint(0, 0), vertRectSize), *iCurrentMask2, iInvertMask);
542 // Render row in center
543 iGc->SetDrawMode(DirectGdi::EDrawModePEN);
544 iGc->DrawBitmapMasked(
545 TRect (TPoint(0, y1), horizRectSize),
546 *iCheckedBoardWithAlphaBitmap,
547 TRect(TPoint(0, 0), horizRectSize), *iCurrentMask2, iInvertMask);
549 // EDrawModeWriteAlpha is not supported in the following modes
550 // This is tested under invalid parameter tests.
551 if (!((iMaskPixelFormat == EUidPixelFormatL_8) &&
552 ((iTestParams.iSourcePixelFormat == EUidPixelFormatARGB_8888) ||
553 (iTestParams.iSourcePixelFormat == EUidPixelFormatARGB_8888_PRE))))
555 // Render column to right
556 iGc->SetDrawMode(DirectGdi::EDrawModeWriteAlpha);
557 iGc->DrawBitmapMasked(
558 TRect (TPoint(bmpSize.iWidth - quaterWidth, 0), vertRectSize),
559 *iCheckedBoardWithAlphaBitmap,
560 TRect(TPoint(0, 0), vertRectSize), *iCurrentMask2, iInvertMask);
563 TESTNOERRORL(iGc->GetError());
564 WriteTargetOutput(KTestName());
569 GRAPHICS-DIRECTGDI-DRAWBITMAPMASKED-0008
586 Test the basic functionality of bit blitting with masking.
595 Test bitmap drawing with masking for same source and mask bitmaps.
597 @SYMTestExpectedResults
598 Source bitmap should be copied into target area. A mask should be
599 considered during coping. Valid bitmap should be created. This bitmap
600 shall be compared to a reference bitmap.
602 void CTDrawBitmapMasked::TestWithSameBitmapsL()
604 _LIT(KTestName, "DrawBitmapMasked-SameBitmaps");
606 TSize bmpSize1(iBlackWhiteBitmap->SizeInPixels());
607 iGc->DrawBitmapMasked(TRect(TPoint(0, 0), bmpSize1), *iBlackWhiteBitmap, TRect(TPoint(0, 0), bmpSize1), *iBlackWhiteBitmap, ETrue);
608 iGc->DrawBitmapMasked(TRect(TPoint(0, 0), bmpSize1), *iBlackWhiteBitmap, TRect(TPoint(0, 0), bmpSize1), *iBlackWhiteBitmap, EFalse);
609 TESTNOERROR(iGc->GetError());
610 //Write target only if image is not empty. BitGDI is producing white images when Mask pixel format is EUidPixelFormatL_8
611 TBool pass = TestTargetL(KRgbWhite);
614 WriteTargetOutput(KTestName());
620 GRAPHICS-DIRECTGDI-DRAWBITMAPMASKED-0009
637 Test that DrawBitmapMasked() performs correctly if it is called after SetOrigin().
647 Call DrawBitmapMasked().
649 @SYMTestExpectedResults
650 Source bitmap should be drawn masked in the target area. Valid bitmap
651 should be created. This bitmap shall be compared to a reference bitmap.
653 void CTDrawBitmapMasked::TestSetOriginL()
655 _LIT(KTestName, "DrawBitmapMasked-SetOrigin");
657 // Only do test for one pixel format to cut down on the number of images produced
658 // as this is just a positional test and we don't need to test for all pixel formats.
659 if (!((iTestParams.iTargetPixelFormat == EUidPixelFormatRGB_565) && (iTestParams.iSourcePixelFormat == EUidPixelFormatRGB_565)))
664 if(!iRunningOomTests)
666 INFO_PRINTF1(KTestName);
671 CFbsBitmap* bitmap = iCheckedBoardBitmap2;
672 CFbsBitmap* mask = iCurrentMask1;
673 TSize bmpSize(bitmap->SizeInPixels());
675 iGc->SetOrigin(TPoint(-35, 80));
676 iGc->DrawBitmapMasked(TRect(TPoint(55, -60), bmpSize), *bitmap, TRect(TPoint(0, 0), bmpSize), *mask, iInvertMask);
678 TESTNOERRORL(iGc->GetError());
679 WriteTargetOutput(KTestName());