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 "tdirectgdiresource.h"
18 #include <graphics/directgditypes.h>
19 #include <graphics/directgdicontext.h>
22 _LIT(KWriteAlpha, "WriteAlpha");
24 const DirectGdi::TGraphicsRotation TestRot[] =
26 DirectGdi::EGraphicsRotationNone,
27 DirectGdi::EGraphicsRotation90,
28 DirectGdi::EGraphicsRotation180,
29 DirectGdi::EGraphicsRotation270
32 CTDirectGdiResource::CTDirectGdiResource() :
33 CActive(CActive::EPriorityStandard),
34 iCurrentState(EStartup)
36 SetTestStepName(KTDirectGdiResourceStep);
39 CTDirectGdiResource::~CTDirectGdiResource()
42 DestroyCommonResource();
46 Writes output image to file. Append dest + src pixel format to the given file name.
48 void CTDirectGdiResource::SaveOutput(const TDesC& aName)
50 TBuf<KFileNameLength> postfix;
51 postfix.Append(KSourceString);
52 postfix.Append(KSeparator);
53 postfix.Append(TDisplayModeMapping::ConvertPixelFormatToShortPixelFormatString(
54 iTestParams.iSourceResourcePixelFormat));
56 TESTNOERROR(WriteTargetOutput(iTestParams, aName, &postfix));
60 Check to see if the current source resource pixel format contains alpha.
61 @return ETrue if the current source resource pixel format contais alpha, EFalse otherwise.
63 TBool CTDirectGdiResource::SourceResourceHasAlpha() const
65 return iTestParams.iSourceResourcePixelFormat==EUidPixelFormatARGB_8888 ||
66 iTestParams.iSourceResourcePixelFormat==EUidPixelFormatARGB_8888_PRE;
70 Check to see if tests should run that only need to be run with one pixel format,
71 for example tests to check that clipping regions are working correctly. Tests that are
72 only run once are run when the target pixel format and the source pixel format are
73 both EUidPixelFormatARGB_8888_PRE.
74 @return ETrue if both the current source and target pixel formats are EUidPixelFormatARGB_8888_PRE.
76 TBool CTDirectGdiResource::OneTimeTestEnabled() const
78 return iTestParams.iTargetPixelFormat==iTestParams.iSourceResourcePixelFormat &&
79 iTestParams.iTargetPixelFormat==EUidPixelFormatARGB_8888_PRE;
83 Draws an image with 4 different orientation using given position as the
89 void CTDirectGdiResource::DrawTestPattern1(const TPoint& aPos)
91 const TInt w = iImgSz.iWidth;
92 const TInt h = iImgSz.iHeight;
94 iGc->DrawResource(TPoint(aPos.iX-w, aPos.iY-h), iImgSrc, DirectGdi::EGraphicsRotationNone);
95 iGc->DrawResource(TPoint(aPos.iX, aPos.iY-w), iImgSrc, DirectGdi::EGraphicsRotation90);
96 iGc->DrawResource(aPos, iImgSrc, DirectGdi::EGraphicsRotation180);
97 iGc->DrawResource(TPoint(aPos.iX-h, aPos.iY), iImgSrc, DirectGdi::EGraphicsRotation270);
101 Draws two drawables to fit dest rect in the following pattern:
104 void CTDirectGdiResource::DrawTestPattern1(const TRect& aDestRect,
105 const TDrawableSourceAndEquivRotatedBmps& aDrawable1, const TDrawableSourceAndEquivRotatedBmps& aDrawable2)
107 const TInt dw = aDestRect.Width();
108 const TInt dh = aDestRect.Height();
109 const TInt xu = dw/2;
112 iGc->DrawResource(TRect(aDestRect.iTl, TSize(xu, yu)), aDrawable1, KNullDesC8);
113 iGc->DrawResource(TRect(TPoint(aDestRect.iTl.iX+xu, aDestRect.iTl.iY), TSize(xu, yu)),
114 aDrawable2, KNullDesC8);
118 Draws two drawables to fit dest rect in the following pattern:
122 void CTDirectGdiResource::DrawTestPattern2(const TRect& aDestRect,
123 const TDrawableSourceAndEquivRotatedBmps& aDrawable1, const TDrawableSourceAndEquivRotatedBmps& aDrawable2)
125 const TInt dw = aDestRect.Width();
126 const TInt dh = aDestRect.Height();
128 const TInt yu = dh/2;
130 iGc->DrawResource(TRect(aDestRect.iTl, TSize(xu, yu)), aDrawable1, KNullDesC8);
131 iGc->DrawResource(TRect(TPoint(aDestRect.iTl.iX, aDestRect.iTl.iY+yu), TSize(xu, yu)),
132 aDrawable2, KNullDesC8);
136 Draws image rotated to fit dest rect in the following pattern:
141 void CTDirectGdiResource::DrawTestPattern1(const TRect& aDestRect, const TRect* aSrcRect)
143 const TInt dw = aDestRect.Width();
144 const TInt dh = aDestRect.Height();
145 const TInt xu = dw/2;
146 const TInt yu = dh/5;
150 // use DrawResource(destRect, img, srcRect, rot) API
151 iGc->DrawResource(TRect(aDestRect.iTl, TSize(xu, yu)), iImgSrc, *aSrcRect, DirectGdi::EGraphicsRotationNone);
152 iGc->DrawResource(TRect(TPoint(aDestRect.iTl.iX+xu, aDestRect.iTl.iY), TSize(xu, yu)), iImgSrc,
153 *aSrcRect, DirectGdi::EGraphicsRotation180);
154 iGc->DrawResource(TRect(TPoint(aDestRect.iTl.iX, aDestRect.iTl.iY+yu), TSize(dw, 2*yu)), iImgSrc,
155 *aSrcRect, DirectGdi::EGraphicsRotationNone);
156 iGc->DrawResource(TRect(TPoint(aDestRect.iTl.iX, aDestRect.iTl.iY+3*yu), TSize(dw, 2*yu)), iImgSrc,
157 *aSrcRect, DirectGdi::EGraphicsRotation180);
161 // use DrawResource(destRect, img, rot) API
162 iGc->DrawResource(TRect(aDestRect.iTl, TSize(xu, yu)), iImgSrc, DirectGdi::EGraphicsRotationNone);
163 iGc->DrawResource(TRect(TPoint(aDestRect.iTl.iX+xu, aDestRect.iTl.iY), TSize(xu, yu)), iImgSrc,
164 DirectGdi::EGraphicsRotation180);
165 iGc->DrawResource(TRect(TPoint(aDestRect.iTl.iX, aDestRect.iTl.iY+yu), TSize(dw, 2*yu)), iImgSrc,
166 DirectGdi::EGraphicsRotationNone);
167 iGc->DrawResource(TRect(TPoint(aDestRect.iTl.iX, aDestRect.iTl.iY+3*yu), TSize(dw, 2*yu)), iImgSrc,
168 DirectGdi::EGraphicsRotation180);
173 Draws image rotated to fit dest rect in the following pattern:
177 void CTDirectGdiResource::DrawTestPattern2(const TRect& aDestRect, const TRect* aSrcRect)
179 const TInt dw = aDestRect.Width();
180 const TInt dh = aDestRect.Height();
181 const TInt xu = dw/5;
182 const TInt yu = dh/2;
186 // use DrawResource(destRect, img, srcRect, rot) API
187 iGc->DrawResource(TRect(aDestRect.iTl, TSize(xu, yu)), iImgSrc, *aSrcRect, DirectGdi::EGraphicsRotation90);
188 iGc->DrawResource(TRect(TPoint(aDestRect.iTl.iX, aDestRect.iTl.iY+yu), TSize(xu, yu)), iImgSrc,
189 *aSrcRect, DirectGdi::EGraphicsRotation270);
190 iGc->DrawResource(TRect(TPoint(aDestRect.iTl.iX+xu, aDestRect.iTl.iY), TSize(2*xu, dh)), iImgSrc,
191 *aSrcRect, DirectGdi::EGraphicsRotation90);
192 iGc->DrawResource(TRect(TPoint(aDestRect.iTl.iX+3*xu, aDestRect.iTl.iY), TSize(2*xu, dh)), iImgSrc,
193 *aSrcRect, DirectGdi::EGraphicsRotation270);
197 // use DrawResource(destRect, img, rot) API
198 iGc->DrawResource(TRect(aDestRect.iTl, TSize(xu, yu)), iImgSrc, DirectGdi::EGraphicsRotation90);
199 iGc->DrawResource(TRect(TPoint(aDestRect.iTl.iX, aDestRect.iTl.iY+yu), TSize(xu, yu)), iImgSrc,
200 DirectGdi::EGraphicsRotation270);
201 iGc->DrawResource(TRect(TPoint(aDestRect.iTl.iX+xu, aDestRect.iTl.iY), TSize(2*xu, dh)), iImgSrc,
202 DirectGdi::EGraphicsRotation90);
203 iGc->DrawResource(TRect(TPoint(aDestRect.iTl.iX+3*xu, aDestRect.iTl.iY), TSize(2*xu, dh)), iImgSrc,
204 DirectGdi::EGraphicsRotation270);
209 Draws image rotated to fit dest rect in the following pattern:
213 void CTDirectGdiResource::DrawTestPattern3(const TRect& aDestRect, const TRect* aSrcRect)
215 TInt dw = aDestRect.Width();
216 TInt dh = aDestRect.Height();
222 // use DrawResource(destRect, img, srcRect, rot) API
223 iGc->DrawResource(TRect(aDestRect.iTl, TSize(xu, yu)), iImgSrc, *aSrcRect, DirectGdi::EGraphicsRotationNone);
224 iGc->DrawResource(TRect(TPoint(aDestRect.iTl.iX+xu, aDestRect.iTl.iY), TSize(xu, yu)), iImgSrc,
225 *aSrcRect, DirectGdi::EGraphicsRotation180);
226 iGc->DrawResource(TRect(TPoint(aDestRect.iTl.iX, aDestRect.iTl.iY+yu), TSize(xu, yu)), iImgSrc,
227 *aSrcRect, DirectGdi::EGraphicsRotation90);
228 iGc->DrawResource(TRect(TPoint(aDestRect.iTl.iX+xu, aDestRect.iTl.iY+yu), TSize(xu, yu)), iImgSrc,
229 *aSrcRect, DirectGdi::EGraphicsRotation270);
233 // use DrawResource(destRect, img, rot) API
234 iGc->DrawResource(TRect(aDestRect.iTl, TSize(xu, yu)), iImgSrc, DirectGdi::EGraphicsRotationNone);
235 iGc->DrawResource(TRect(TPoint(aDestRect.iTl.iX+xu, aDestRect.iTl.iY), TSize(xu, yu)), iImgSrc,
236 DirectGdi::EGraphicsRotation180);
237 iGc->DrawResource(TRect(TPoint(aDestRect.iTl.iX, aDestRect.iTl.iY+yu), TSize(xu, yu)), iImgSrc,
238 DirectGdi::EGraphicsRotation90);
239 iGc->DrawResource(TRect(TPoint(aDestRect.iTl.iX+xu, aDestRect.iTl.iY+yu), TSize(xu, yu)), iImgSrc,
240 DirectGdi::EGraphicsRotation270);
246 GRAPHICS-DIRECTGDI-DRAWRESOURCE-0001
270 Draws drawable resources created from RSgDrawable and RSgImage objects.
273 Draw drawble resources with the various combination of parameters:
274 -with and without clipping region
275 -drawable from RSgDrawable and RSgImage
276 -in various destination positions and scaling factor
277 -using write or blend
279 @SYMTestExpectedResults
280 Resources are drawn on the given position, scaled to fit the destination
281 rectangle, clipped to current clipping region (if set).
283 void CTDirectGdiResource::TestDrawResource_ImageAsDrawableL()
285 _LIT(KTestName, "DrawResource_ImageAsDrawable");
286 if(!iRunningOomTests)
288 INFO_PRINTF1(KTestName);
291 TBuf<KFileNameLength> tag;
292 tag.Append(KTestName);
295 if (iEnableClipRegion)
297 iGc->SetClippingRegion(iClip);
303 iGc->SetDrawMode(DirectGdi::EDrawModeWriteAlpha);
304 tag.Append(KWriteAlpha);
307 DrawTestPattern1(TRect(0,0,100,20), iDwbSrc[0], iDwbSrc[1]);
308 DrawTestPattern2(TRect(0,20,100,100), iDwbSrc[0], iDwbSrc[1]);
309 DrawTestPattern1(TRect(0,100,100,200), iDwbSrc[0], iDwbSrc[1]);
310 DrawTestPattern2(TRect(100,0,200,200), iDwbSrc[0], iDwbSrc[1]);
312 if (iEnableClipRegion)
314 iGc->ResetClippingRegion();
315 iGc->SetDrawMode(DirectGdi::EDrawModePEN);
323 GRAPHICS-DIRECTGDI-DRAWRESOURCE-0002
347 Draw an image resource created from RSgImage object.
350 Draw an image resource with the various combination of parameters:
351 -with and without clipping region
352 -in various destination positions on/off target
353 -using write or blend
354 -no scaling is performed in this test
356 @SYMTestExpectedResults
357 Resources are drawn on the given position, unscaled, rotated and
358 clipped to current clipping region (if set).
360 void CTDirectGdiResource::TestDrawResource_PosL()
362 _LIT(KTestName, "DrawResource_Pos");
363 if(!iRunningOomTests)
365 INFO_PRINTF1(KTestName);
368 TBuf<KFileNameLength> tag;
369 tag.Append(KTestName);
373 if (iEnableClipRegion)
375 iGc->SetClippingRegion(iClip);
381 iGc->SetDrawMode(DirectGdi::EDrawModeWriteAlpha);
382 tag.Append(KWriteAlpha);
385 DrawTestPattern1(TPoint(0,0));
386 DrawTestPattern1(TPoint(100,0));
387 DrawTestPattern1(TPoint(200,0));
389 DrawTestPattern1(TPoint(50,50));
390 DrawTestPattern1(TPoint(150,50));
392 DrawTestPattern1(TPoint(0,100));
393 DrawTestPattern1(TPoint(100,100));
394 DrawTestPattern1(TPoint(200,100));
396 DrawTestPattern1(TPoint(50,150));
397 DrawTestPattern1(TPoint(150,150));
399 DrawTestPattern1(TPoint(0,200));
400 DrawTestPattern1(TPoint(100,200));
401 DrawTestPattern1(TPoint(200,200));
403 if (iEnableClipRegion)
405 iGc->ResetClippingRegion();
406 iGc->SetDrawMode(DirectGdi::EDrawModePEN);
414 GRAPHICS-DIRECTGDI-DRAWRESOURCE-0003
438 Draw a scaled image resource created from RSgImage object.
441 Draw a scaled image resource with the various combination of parameters:
442 -with and without clipping region
443 -in various destination positions and scaling factor
444 -using write or blend
445 -the destination rectangle that the image is drawn to scaled
447 @SYMTestExpectedResults
448 Resources are drawn on the given position, scaled to fit the
449 destination rectangle, rotated and clipped to current clipping region (if set).
451 void CTDirectGdiResource::TestDrawResource_DestRectL()
453 _LIT(KTestName, "DrawResource_DestRect");
454 if(!iRunningOomTests)
456 INFO_PRINTF1(KTestName);
459 TBuf<KFileNameLength> tag;
460 tag.Append(KTestName);
464 if (iEnableClipRegion)
466 iGc->SetClippingRegion(iClip);
472 iGc->SetDrawMode(DirectGdi::EDrawModeWriteAlpha);
473 tag.Append(KWriteAlpha);
476 DrawTestPattern1(TRect(0,0,100,100));
477 DrawTestPattern2(TRect(100,0,200,100));
478 DrawTestPattern3(TRect(0,100,100,200));
479 DrawTestPattern1(TRect(100,100,150,150));
480 DrawTestPattern2(TRect(150,100,200,150));
481 DrawTestPattern3(TRect(100,150,200,200));
483 if (iEnableClipRegion)
485 iGc->ResetClippingRegion();
486 iGc->SetDrawMode(DirectGdi::EDrawModePEN);
494 GRAPHICS-DIRECTGDI-DRAWRESOURCE-0004
518 Draw a scaled portion of an image resource created from RSgImage object.
521 Draw a scaled portion of an image resource with the various combination of parameters:
522 -with and without clipping region
523 -various destination positions and size
524 -using write or blend
525 -only a portion of the image resource is drawn, it is drawn scaled
527 @SYMTestExpectedResults
528 Resources are drawn on the given position, scaled to fit the
529 destination rectangle, rotated and clipped to current clipping region (if set).
531 void CTDirectGdiResource::TestDrawResource_DestRectSrcRectL()
533 _LIT(KTestName, "DrawResource_DestRectSrcRect");
534 if(!iRunningOomTests)
536 INFO_PRINTF1(KTestName);
539 TBuf<KFileNameLength> tag;
540 tag.Append(KTestName);
543 if (iEnableClipRegion)
545 iGc->SetClippingRegion(iClip);
551 iGc->SetDrawMode(DirectGdi::EDrawModeWriteAlpha);
552 tag.Append(KWriteAlpha);
555 TRect srcRect(TPoint(1,1), TSize(48,18));
556 DrawTestPattern1(TRect(0,0,100,100), &srcRect);
557 DrawTestPattern2(TRect(100,0,200,100), &srcRect);
558 DrawTestPattern3(TRect(0,100,100,200), &srcRect);
559 DrawTestPattern1(TRect(100,100,150,150), &srcRect);
560 DrawTestPattern2(TRect(150,100,200,150), &srcRect);
561 DrawTestPattern3(TRect(100,150,200,200), &srcRect);
563 if (iEnableClipRegion)
565 iGc->ResetClippingRegion();
566 iGc->SetDrawMode(DirectGdi::EDrawModePEN);
574 GRAPHICS-DIRECTGDI-DRAWRESOURCE-0005
598 Attempt to draw a resource with a NULL handle for each of the DrawResource methods
599 that draw image sources to improve code coverage.
603 Create a RDirectGdiDrawableSource from it,
604 Attempt to draw the RDirectGdiDrawableSource with each of the DrawResource methods.
605 Each method should set an error of KErrBadHandle.
607 @SYMTestExpectedResults
608 Driver returns KErrBadHandle for each attempt to draw invalid resource.
610 void CTDirectGdiResource::TestDrawResource_NullHandleL()
612 _LIT(KTestName, "DrawResource_NullHandle");
613 if(!iRunningOomTests)
615 INFO_PRINTF1(KTestName);
620 CDirectGdiDriver* drv = CDirectGdiDriver::Static();
625 RDirectGdiDrawableSource dwb(*drv);
626 RDirectGdiDrawableSource img(*drv);
628 // Convert the image source, drawable source and bitmaps to TDrawableSourceAndEquivRotatedBmps so it can be
629 // drawn using the BitGdi test code as well as the DirectGdi code
630 TDrawableSourceAndEquivRotatedBmps imageSource;
631 imageSource.iDrawableSrc = &img;
632 TDrawableSourceAndEquivRotatedBmps drawableSource;
633 drawableSource.iDrawableSrc = &dwb;
636 TRect dstRect(pos, TSize(100,100));
637 TRect srcRect(pos, TSize(10,10));
639 // DrawResource(const TRect&, const RDirectGdiDrawableSource&, const TDesC8&)
640 iGc->DrawResource(dstRect, drawableSource, KNullDesC8);
641 TESTL(iGc->GetError() == KErrBadHandle);
643 for (TInt rot=0; rot<sizeof(TestRot)/sizeof(TestRot[0]); ++rot)
645 // DrawResource(const TPoint&, const RDirectGdiDrawableSource&, DirectGdi::TGraphicsRotation)
646 iGc->DrawResource(pos, imageSource, TestRot[rot]);
647 TESTL(iGc->GetError() == KErrBadHandle);
649 // DrawResource(const TRect&, const RDirectGdiDrawableSource&, DirectGdi::TGraphicsRotation)
650 iGc->DrawResource(dstRect, imageSource, TestRot[rot]);
651 TESTL(iGc->GetError() == KErrBadHandle);
653 // DrawResource(const TRectt&, const RDirectGdiDrawableSource&, const TRect&, DirectGdi::TGraphicsRotation)
654 iGc->DrawResource(dstRect, imageSource, srcRect, TestRot[rot]);
655 TESTL(iGc->GetError() == KErrBadHandle);
661 GRAPHICS-DIRECTGDI-DRAWRESOURCE-0006
685 Draw onto an RSgImage as a target, then convert to it a source and draw that
689 Test the use case where we:
690 Draw red, green and blue rectangles to a target.
691 Create a source from the targets' bitmap.
693 Draw the source to the target.
695 @SYMTestExpectedResults
696 The three rectangles should have been appear when the source is copied to the target.
698 void CTDirectGdiResource::TestDrawTargetAsSourceL()
700 _LIT(KTestName, "DrawResource_TestDrawTargetAsSource");
701 if(!iRunningOomTests)
703 INFO_PRINTF1(KTestName);
708 // draw to the current target
709 TRect rect(20,20,100,100);
710 iGc->SetPenColor(TRgb(255,0,0));
712 iGc->SetPenColor(TRgb(0,255,0));
715 iGc->SetPenColor(TRgb(0,0,255));
718 TESTNOERROR(iGc->GetError());
720 // Only do the second part of the test if using DirectGdi. The resultant test bitmap should looks the
721 // same when using DirectGdi as the one drawn using BitGdi that only uses the above calls.
724 iGdiTarget->Finish();
725 TESTNOERROR(iGc->GetError());
727 // get the target bitmap
728 CFbsBitmap* bitmap = iGdiTarget->GetTargetFbsBitmapL();
729 TESTL(bitmap != NULL);
731 // Create an RSgImage using the target bitmap
732 TSgImageInfo imageInfo;
733 imageInfo.iSizeInPixels = bitmap->SizeInPixels();
734 imageInfo.iPixelFormat = iTestParams.iTargetPixelFormat; // only call this test when the target and the source resource pixel format are the same
735 imageInfo.iUsage = ESgUsageDirectGdiSource;
737 TInt err = sgImage.Create(imageInfo, bitmap->DataAddress(), bitmap->DataStride());
738 CleanupClosePushL(sgImage);
741 CDirectGdiDriver* dgdiDriver = CDirectGdiDriver::Static();
742 TESTL(dgdiDriver != NULL);
744 // Create a RDirectGdiDrawableSource from the RSgImage
745 RDirectGdiDrawableSource dgdiImageSource(*dgdiDriver);
746 err = dgdiImageSource.Create(sgImage);
751 // Convert the image source and bitmap to TDrawableSourceAndEquivRotatedBmps so it can be
752 // drawn using the BitGdi test code as well as the DirectGdi code
753 TDrawableSourceAndEquivRotatedBmps imageSource;
754 imageSource.iDrawableSrc = &dgdiImageSource;
755 imageSource.iBmpRotNone = bitmap;
757 // Draw the RDirectGdiDrawableSource using CDirectGdiContext::DrawResource
758 iGc->DrawResource(TPoint(0,0), imageSource);
760 dgdiImageSource.Close();
761 CleanupStack::PopAndDestroy(1, &sgImage);
764 // Output the target image to make sure it contains what was drawn onto the source
765 TESTNOERROR(WriteTargetOutput(iTestParams, KTestName()));
770 GRAPHICS-DIRECTGDI-DRAWRESOURCE-0007
794 Create two CDirectGdiImageSource object from the same RSgImage
797 Test the use case where we:
799 Create two CDirectGdiImageSource objects.
800 The CDirectGdiImageSource objects should share the EGL image created from
802 as only one EGL image can be created per RSgImage per process.
803 If the EGL image sharing is not working an error will occur when creating the
804 second CDirectGdiImageSource object.
806 @SYMTestExpectedResults
807 This test does not output an image, it is just for testing that no errors or panics occur.
809 void CTDirectGdiResource::TestShareEGLImageBetweenSourcesL()
811 _LIT(KTestName, "ShareEGLImageBetweenSources");
812 if(!iRunningOomTests)
814 INFO_PRINTF1(KTestName);
819 CDirectGdiDriver* dgdiDriver = CDirectGdiDriver::Static();
820 TESTL(dgdiDriver != NULL);
822 // Create a CFbsBitmap
823 TSize patternSize(90,50);
824 TRect rect(0,0,90,50);
825 CFbsBitmap* bitmap = CreateCheckedBoardBitmapL(iTestParams.iSourceResourcePixelFormat, patternSize);
826 TESTL(NULL != bitmap);
827 CleanupStack::PushL(bitmap);
829 // Create an RSgImage from the CFbsBitmap
830 TSgImageInfo imageInfo;
831 imageInfo.iSizeInPixels = patternSize;
832 imageInfo.iPixelFormat = iTestParams.iSourceResourcePixelFormat;
833 imageInfo.iUsage = ESgUsageDirectGdiSource;
835 TInt res = sgImage.Create(imageInfo, bitmap->DataAddress(), bitmap->DataStride());
837 CleanupClosePushL(sgImage);
839 // Create a RDirectGdiDrawableSource from the RSgImage
840 RDirectGdiDrawableSource dgdiImageSource1(*dgdiDriver);
841 res = dgdiImageSource1.Create(sgImage);
843 CleanupClosePushL(dgdiImageSource1);
845 // Create a second RDirectGdiDrawableSource from the same RSgImage,
846 // no error should occur here, the underlying EGL images created should be
847 // shared between sources
848 RDirectGdiDrawableSource dgdiImageSource2(*dgdiDriver);
849 res = dgdiImageSource2.Create(sgImage);
852 dgdiImageSource1.Close();
853 dgdiImageSource2.Close();
854 CleanupStack::PopAndDestroy(3, bitmap);
859 GRAPHICS-DIRECTGDI-DRAWRESOURCE-0008
883 Draw resource with valid resource but other invalid parameters
886 Draw valid RDirectGdiDrawableSource objects with invalid
887 parameters. Test the following for each valid rotation:
888 - drawing a resource where the source rectangle does not intersect the actual image extent
889 - drawing a resource where the source rectangle is not fully contained by the image extent
892 @SYMTestExpectedResults
893 Driver returns KErrArgument for each attempt to draw resource with invalid parameters.
895 void CTDirectGdiResource::TestDrawResource_InvalidParameterL()
897 _LIT(KTestName, "DrawResource_InvalidParameter");
898 if(!iRunningOomTests)
900 INFO_PRINTF1(KTestName);
905 // destRect can be anything
907 TRect dstRect(pos, iImgSz);
909 // srcRect doesn't intersect image extent at all
910 TRect srcRect1(TPoint(1000,1000), TSize(1,1));
911 // srcRect is not fully contained within image extent
912 TRect srcRect2(TPoint(10,10), TSize(1000,1000));
913 TRect srcRect3(TPoint(-10,0), iImgSz);
915 for (TInt rot=0; rot<sizeof(TestRot)/sizeof(TestRot[0]); ++rot)
917 iGc->DrawResource(dstRect, iImgSrc, srcRect1, TestRot[rot]);
918 TESTL(iGc->GetError() == KErrArgument);
920 iGc->DrawResource(dstRect, iImgSrc, srcRect2, TestRot[rot]);
921 TESTL(iGc->GetError() == KErrArgument);
923 iGc->DrawResource(dstRect, iImgSrc, srcRect3, TestRot[rot]);
924 TESTL(iGc->GetError() == KErrArgument);
930 GRAPHICS-DIRECTGDI-DRAWRESOURCE-0009
954 Draw resources with a non-zero origin set.
957 Set drawing context origin to various non-zero values and draw RDirectGdiDrawableSource
958 objects using generic underlying DrawResource implementation that takes destination
959 and source rectangle.
961 @SYMTestExpectedResults
962 Resource drawn at the specified location relative to drawing context origin.
964 void CTDirectGdiResource::TestDrawResource_NonZeroOriginL()
966 _LIT(KTestName, "DrawResource_NonZeroOrigin");
967 if(!iRunningOomTests)
969 INFO_PRINTF1(KTestName);
972 const TPoint origin[] =
982 for (TInt idx=0; idx<sizeof(origin)/sizeof(origin[0]); ++idx)
984 TBuf<KFileNameLength> tag;
985 tag.Append(KTestName);
989 iGc->SetOrigin(origin[idx]);
991 TRect srcRect(TPoint(0,0), iImgSz);
993 DrawTestPattern1(TRect(0,0,100,100), &srcRect);
994 DrawTestPattern2(TRect(100,0,200,100), &srcRect);
995 DrawTestPattern3(TRect(0,100,100,200), &srcRect);
996 DrawTestPattern1(TRect(100,100,150,150), &srcRect);
997 DrawTestPattern2(TRect(150,100,200,150), &srcRect);
998 DrawTestPattern3(TRect(100,150,200,200), &srcRect);
1006 GRAPHICS-DIRECTGDI-DRAWRESOURCE-0010
1027 Tests if DirectGDI methods returns an error when called on a not constructed RDirectGdiDrawableSource object.
1030 Create a CFbsBitmap.
1031 Create an RSgImage from the CFbsBitmap.
1032 Allocate a RDirectGdiDrawableSource but do not call Create() method.
1033 Draw the RDirectGdiDrawableSource using CDirectGdiContext::DrawResource.
1035 @SYMTestExpectedResults
1036 CDirectGdiContext::DrawResource should return KErrBadHandle.
1038 void CTDirectGdiResource::TestDrawResourceSourceNotCreatedL()
1040 _LIT(KTestName, "DrawResource_SourceNotCreated");
1041 if(!iRunningOomTests)
1043 INFO_PRINTF1(KTestName);
1050 TInt res = CDirectGdiDriver::Open();
1053 CDirectGdiDriver* dgdiDriver = CDirectGdiDriver::Static();
1054 TESTL(dgdiDriver != NULL);
1055 CleanupClosePushL(*dgdiDriver);
1057 // Create a CFbsBitmap
1058 TSize patternSize(90,50);
1059 CFbsBitmap* bitmap = CreateCheckedBoardBitmapL(iTestParams.iSourceResourcePixelFormat, patternSize);
1060 TESTL(NULL != bitmap);
1061 CleanupStack::PushL(bitmap);
1063 // Create an RSgImage from the CFbsBitmap
1064 TSgImageInfo imageInfo;
1065 imageInfo.iSizeInPixels = patternSize;
1066 imageInfo.iPixelFormat = iTestParams.iSourceResourcePixelFormat;
1067 imageInfo.iUsage = ESgUsageDirectGdiSource;
1069 res = sgImage.Create(imageInfo, bitmap->DataAddress(), bitmap->DataStride());
1070 CleanupClosePushL(sgImage);
1073 //allocate RDirectGdiDrawableSource, but do not call Create() method
1074 RDirectGdiDrawableSource dgdiImageSource(*dgdiDriver);
1076 // Draw the RDirectGdiDrawableSource using CDirectGdiContext::DrawResource
1077 TDrawableSourceAndEquivRotatedBmps imageSource;
1078 imageSource.iDrawableSrc = &dgdiImageSource;
1079 iGc->DrawResource(TPoint(10,10), imageSource);
1080 TESTL(iGc->GetError() == KErrBadHandle);
1081 dgdiImageSource.Close();
1082 CleanupStack::PopAndDestroy(3, dgdiDriver);
1087 Override of base class pure virtual
1088 Our implementation only gets called if the base class doTestStepPreambleL() did
1089 not leave. That being the case, the current test result value will be EPass.
1090 @leave Gets system wide error code
1091 @return TVerdict code
1093 TVerdict CTDirectGdiResource::doTestStepL()
1095 INFO_PRINTF1(_L("DirectGdi Resource Tests"));
1097 // Test for each target pixel format
1098 for(TInt targetPixelFormatIndex = iTargetPixelFormatArray.Count() - 1; targetPixelFormatIndex >= 0 ; targetPixelFormatIndex--)
1100 iTestParams.iTargetPixelFormat = iTargetPixelFormatArray[targetPixelFormatIndex];
1101 TBuf<KPixelFormatNameLength> targetPixelFormatName(TDisplayModeMapping::ConvertPixelFormatToPixelFormatString(iTestParams.iTargetPixelFormat));
1102 // Test for each source pixel format
1103 for (TInt sourceResourcePixelFormatIndex = iSourceResourcePixelFormatArray.Count() - 1; sourceResourcePixelFormatIndex >= 0; sourceResourcePixelFormatIndex--)
1105 TBool doOOM = EFalse;
1106 iTestParams.iSourceResourcePixelFormat = iSourceResourcePixelFormatArray[sourceResourcePixelFormatIndex];
1107 if(EUidPixelFormatXRGB_8888 == iTestParams.iSourceResourcePixelFormat)
1109 TBuf<KPixelFormatNameLength> sourcePixelFormatName(TDisplayModeMapping::ConvertPixelFormatToPixelFormatString(iTestParams.iSourceResourcePixelFormat));
1110 INFO_PRINTF3(_L("Target Pixel Format: %S; Source Resource Pixel Format: %S"), &targetPixelFormatName, &sourcePixelFormatName);
1112 SetTargetL(iTestParams.iTargetPixelFormat);
1113 CreateCommonResourceL();
1117 // only run OOM tests for one target pixel format to prevent duplication of tests
1118 if (targetPixelFormatIndex == 0 && doOOM)
1120 RunOomTestsL(); // from base class
1123 DestroyCommonResource();
1126 CloseTMSGraphicsStep();
1127 return TestStepResult();
1131 Helper function used to create the resources that are shared between all the tests in this file.
1133 void CTDirectGdiResource::CreateCommonResourceL()
1135 // Create a CFbsBitmap
1139 // Generate tiled color pattern, test expects original image size to be 50x20 and has alpha values
1140 TSize patternSize(50,20);
1141 bitmap = CreateCheckedBoardBitmapL(iTestParams.iSourceResourcePixelFormat, patternSize, TSize(10, 10), ETrue);
1142 iImgSrc.iBmpRotNone = bitmap;
1143 iImgSz = bitmap->SizeInPixels();
1145 // Create rotated versions of the bitmap so they can be used when drawing BitGdi equivalent
1146 // test images for the new DrawResource methods
1147 iImgSrc.iBmpRot90 = new(ELeave) CFbsBitmap;
1148 iImgSrc.iBmpRot180 = new(ELeave) CFbsBitmap;
1149 iImgSrc.iBmpRot270 = new(ELeave) CFbsBitmap;
1151 // Create an RSgImage from the CFbsBitmap
1152 TSgImageInfo imageInfo;
1153 imageInfo.iSizeInPixels = iImgSz;
1154 imageInfo.iPixelFormat = iTestParams.iSourceResourcePixelFormat;
1155 imageInfo.iUsage = ESgUsageDirectGdiSource;
1158 TInt res = sgImage.Create(imageInfo, bitmap->DataAddress(), bitmap->DataStride());
1160 CleanupClosePushL(sgImage);
1164 // Create a RDirectGdiDrawableSource from the RSgImage
1166 // Driver must've been initialised by framework, no need to re-open
1168 // Driver behaviour i.e. Sg::Open/Close, CDirectGdiDriver::Open/Close should be tested
1169 // somewhere else not in details drawing ops test like this
1170 CDirectGdiDriver* drv = CDirectGdiDriver::Static();
1173 iImgSrc.iDrawableSrc = new RDirectGdiDrawableSource(*drv);
1174 TEST(iImgSrc.iDrawableSrc != NULL);
1175 res = iImgSrc.iDrawableSrc->Create(sgImage);
1178 // Create drawable source from drawable
1179 res = sgDwb.Open(sgImage.Id());
1181 CleanupClosePushL(sgDwb);
1183 iDwbSrc[0].iDrawableSrc = new RDirectGdiDrawableSource(*drv);
1184 TEST(iDwbSrc[0].iDrawableSrc != NULL);
1185 res = iDwbSrc[0].iDrawableSrc->Create(sgDwb);
1188 // Create drawable source from image
1189 iDwbSrc[1].iDrawableSrc = new RDirectGdiDrawableSource(*drv);
1190 TEST(iDwbSrc[1].iDrawableSrc != NULL);
1191 res = iDwbSrc[1].iDrawableSrc->Create(sgImage);
1196 // Share the bitmaps from iImgSrc with this drawable for testing
1197 iDwbSrc[0].iBmpRotNone = iImgSrc.iBmpRotNone;
1198 iDwbSrc[0].iBmpRot90 = iImgSrc.iBmpRot90;
1199 iDwbSrc[0].iBmpRot180 = iImgSrc.iBmpRot180;
1200 iDwbSrc[0].iBmpRot270 = iImgSrc.iBmpRot270;
1202 // Share the bitmaps from iImgSrc with this drawable for testing
1203 iDwbSrc[1].iBmpRotNone = iImgSrc.iBmpRotNone;
1204 iDwbSrc[1].iBmpRot90 = iImgSrc.iBmpRot90;
1205 iDwbSrc[1].iBmpRot180 = iImgSrc.iBmpRot180;
1206 iDwbSrc[1].iBmpRot270 = iImgSrc.iBmpRot270;
1209 // Create horizontal and vertical stripe clipping region
1212 for (TInt x=0; x<50; x+=w)
1217 TRect r1(TPoint(x,0), TSize(w, 200));
1218 TRect r2(TPoint(100+x,0), TSize(w, 200));
1226 for (TInt y=0; y<200; y+=h)
1231 TRect r1(TPoint(0,y), TSize(100, h));
1232 TRect r2(TPoint(100,y), TSize(100, h));
1241 // We need to create 3 rotated copies of the bitmap we are drawing when testing using BitGdi
1242 // using the CBitmapRotator active object, start rotating the first one here
1243 iCurrentState = ERotatingBitmap90;
1244 iBitmapRotator->Rotate(&iStatus, *bitmap, *(iImgSrc.iBmpRot90), CBitmapRotator::ERotation90DegreesClockwise);
1246 CActiveScheduler::Start();
1249 // Destroy bitmap, image and drawable.
1250 CleanupStack::PopAndDestroy(iUseDirectGdi ? 2 : 1, &sgImage);
1254 Helper function used to destroy the resources that are shared between all the tests in this file.
1256 void CTDirectGdiResource::DestroyCommonResource()
1258 if (iImgSrc.iDrawableSrc)
1260 iImgSrc.iDrawableSrc->Close();
1261 delete iImgSrc.iDrawableSrc;
1262 iImgSrc.iDrawableSrc = NULL;
1265 delete iImgSrc.iBmpRotNone;
1266 iImgSrc.iBmpRotNone = NULL;
1267 delete iImgSrc.iBmpRot90;
1268 iImgSrc.iBmpRot90 = NULL;
1269 delete iImgSrc.iBmpRot180;
1270 iImgSrc.iBmpRot180 = NULL;
1271 delete iImgSrc.iBmpRot270;
1272 iImgSrc.iBmpRot270 = NULL;
1274 for (TInt ii=0; ii<2; ++ii)
1276 if (iDwbSrc[ii].iDrawableSrc)
1278 iDwbSrc[ii].iDrawableSrc->Close();
1279 delete iDwbSrc[ii].iDrawableSrc;
1280 iDwbSrc[ii].iDrawableSrc = NULL;
1283 iDwbSrc[ii].iBmpRotNone = NULL;
1284 iDwbSrc[ii].iBmpRot90 = NULL;
1285 iDwbSrc[ii].iBmpRot180 = NULL;
1286 iDwbSrc[ii].iBmpRot270 = NULL;
1293 Override of base class virtual
1294 @leave Gets system wide error code
1295 @return - TVerdict code
1297 TVerdict CTDirectGdiResource::doTestStepPreambleL()
1299 CTDirectGdiStepBase::doTestStepPreambleL();
1300 CActiveScheduler::Add(this);
1301 iBitmapRotator = CBitmapRotator::NewL();
1302 return TestStepResult();
1306 Override of base class virtual
1307 @leave Gets system wide error code
1308 @return - TVerdict code
1310 TVerdict CTDirectGdiResource::doTestStepPostambleL()
1312 delete iBitmapRotator;
1313 iBitmapRotator = NULL;
1314 CTDirectGdiStepBase::doTestStepPostambleL();
1315 return TestStepResult();
1318 void CTDirectGdiResource::DoDrawTestL()
1320 SetTestStepID(_L("GRAPHICS-DIRECTGDI-DRAWRESOURCE-0001"));
1321 TestDrawResource_ImageAsDrawableL();
1322 RecordTestResultL();
1323 SetTestStepID(_L("GRAPHICS-DIRECTGDI-DRAWRESOURCE-0002"));
1324 TestDrawResource_PosL();
1325 RecordTestResultL();
1326 SetTestStepID(_L("GRAPHICS-DIRECTGDI-DRAWRESOURCE-0003"));
1327 TestDrawResource_DestRectL();
1328 RecordTestResultL();
1329 SetTestStepID(_L("GRAPHICS-DIRECTGDI-DRAWRESOURCE-0004"));
1330 TestDrawResource_DestRectSrcRectL();
1331 RecordTestResultL();
1335 Override of base class pure virtual
1336 Lists the tests to be run
1338 void CTDirectGdiResource::RunTestsL()
1340 // For all combination of destination and source pixel format do the following tests
1344 // Extra test using EDrawModeWriteAlpha. Geometry tests are irrelevant here, only contents tests are.
1346 if (SourceResourceHasAlpha())
1348 iUseWriteAlpha = ETrue;
1350 iUseWriteAlpha = EFalse;
1353 // Geometry and negative tests doesn't need repeating, do it once
1355 if (OneTimeTestEnabled())
1357 iEnableClipRegion = ETrue;
1359 iEnableClipRegion = EFalse;
1361 SetTestStepID(_L("GRAPHICS-DIRECTGDI-DRAWRESOURCE-0009"));
1362 TestDrawResource_NonZeroOriginL();
1363 RecordTestResultL();
1366 // These test for errors being set that are specific to DirectGdi and
1367 // have no output so there is no need to run for BitGdi
1368 SetTestStepID(_L("GRAPHICS-DIRECTGDI-DRAWRESOURCE-0005"));
1369 TestDrawResource_NullHandleL();
1370 RecordTestResultL();
1371 SetTestStepID(_L("GRAPHICS-DIRECTGDI-DRAWRESOURCE-0008"));
1372 TestDrawResource_InvalidParameterL();
1373 RecordTestResultL();
1374 SetTestStepID(_L("GRAPHICS-DIRECTGDI-DRAWRESOURCE-0010"));
1375 TestDrawResourceSourceNotCreatedL();
1376 RecordTestResultL();
1380 // This test uses the target as a source, so only call it when the target
1381 // pixel format is the same as the source resource pixel format
1383 if (iTestParams.iTargetPixelFormat == iTestParams.iSourceResourcePixelFormat)
1385 SetTestStepID(_L("GRAPHICS-DIRECTGDI-DRAWRESOURCE-0006"));
1386 TestDrawTargetAsSourceL();
1387 RecordTestResultL();
1392 // This test is only appropriate when using DirectGdi as it tests sharing of EGL images
1393 SetTestStepID(_L("GRAPHICS-DIRECTGDI-DRAWRESOURCE-0007"));
1394 TestShareEGLImageBetweenSourcesL();
1395 RecordTestResultL();
1402 void CTDirectGdiResource::RunL()
1404 switch (iCurrentState)
1406 case ERotatingBitmap90:
1407 // Rotate the next bitmap (180)
1408 iCurrentState = ERotatingBitmap180;
1409 iBitmapRotator->Rotate(&iStatus, *(iImgSrc.iBmpRotNone), *(iImgSrc.iBmpRot180), CBitmapRotator::ERotation180DegreesClockwise);
1413 case ERotatingBitmap180:
1414 // Rotate the next bitmap (270)
1415 iCurrentState = ERotatingBitmap270;
1416 iBitmapRotator->Rotate(&iStatus, *(iImgSrc.iBmpRotNone), *(iImgSrc.iBmpRot270), CBitmapRotator::ERotation270DegreesClockwise);
1420 case ERotatingBitmap270:
1421 // Finished rotating the bitmaps, run the tests now
1422 iCurrentState = EDone;
1423 CActiveScheduler::Stop();
1431 void CTDirectGdiResource::DoCancel()