graphicsdeviceinterface/directgdi/test/tdirectgdiresource.cpp
changeset 0 5d03bc08d59c
equal deleted inserted replaced
-1:000000000000 0:5d03bc08d59c
       
     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".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "tdirectgdiresource.h"
       
    17 #include <s32mem.h>
       
    18 #include <graphics/directgditypes.h>
       
    19 #include <graphics/directgdicontext.h>
       
    20 
       
    21 _LIT(KClip, "Clip");
       
    22 _LIT(KWriteAlpha, "WriteAlpha");
       
    23 
       
    24 const DirectGdi::TGraphicsRotation TestRot[] =
       
    25   	{
       
    26   	DirectGdi::EGraphicsRotationNone,
       
    27   	DirectGdi::EGraphicsRotation90,
       
    28   	DirectGdi::EGraphicsRotation180,
       
    29   	DirectGdi::EGraphicsRotation270
       
    30   	};
       
    31 
       
    32 CTDirectGdiResource::CTDirectGdiResource() :
       
    33 	CActive(CActive::EPriorityStandard),
       
    34 	iCurrentState(EStartup)
       
    35 	{
       
    36 	SetTestStepName(KTDirectGdiResourceStep);
       
    37 	}
       
    38 
       
    39 CTDirectGdiResource::~CTDirectGdiResource()
       
    40 	{
       
    41 	Cancel();
       
    42 	DestroyCommonResource();
       
    43 	}
       
    44 
       
    45 /**
       
    46 Writes output image to file. Append dest + src pixel format to the given file name.
       
    47 */
       
    48 void CTDirectGdiResource::SaveOutput(const TDesC& aName)
       
    49 	{
       
    50 	TBuf<KFileNameLength> postfix;
       
    51 	postfix.Append(KSourceString);
       
    52 	postfix.Append(KSeparator);
       
    53 	postfix.Append(TDisplayModeMapping::ConvertPixelFormatToShortPixelFormatString(
       
    54 				iTestParams.iSourceResourcePixelFormat));
       
    55 
       
    56 	TESTNOERROR(WriteTargetOutput(iTestParams, aName, &postfix));
       
    57 	}
       
    58 
       
    59 /**
       
    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.
       
    62 */
       
    63 TBool CTDirectGdiResource::SourceResourceHasAlpha() const
       
    64 	{
       
    65 	return iTestParams.iSourceResourcePixelFormat==EUidPixelFormatARGB_8888 ||
       
    66 		iTestParams.iSourceResourcePixelFormat==EUidPixelFormatARGB_8888_PRE;
       
    67 	}
       
    68 
       
    69 /**
       
    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.
       
    75 */
       
    76 TBool CTDirectGdiResource::OneTimeTestEnabled() const
       
    77 	{
       
    78 	return iTestParams.iTargetPixelFormat==iTestParams.iSourceResourcePixelFormat &&
       
    79 		iTestParams.iTargetPixelFormat==EUidPixelFormatARGB_8888_PRE;
       
    80 	}
       
    81 
       
    82 /**
       
    83 Draws an image with 4 different orientation using given position as the
       
    84 origin e.g
       
    85 A B
       
    86  o
       
    87 D C
       
    88 */
       
    89 void CTDirectGdiResource::DrawTestPattern1(const TPoint& aPos)
       
    90 	{
       
    91 	const TInt w = iImgSz.iWidth;
       
    92 	const TInt h = iImgSz.iHeight;
       
    93 
       
    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);
       
    98 	}
       
    99 
       
   100 /**
       
   101 Draws two drawables to fit dest rect in the following pattern:
       
   102 AB
       
   103 */
       
   104 void CTDirectGdiResource::DrawTestPattern1(const TRect& aDestRect,
       
   105 			const TDrawableSourceAndEquivRotatedBmps& aDrawable1, const TDrawableSourceAndEquivRotatedBmps& aDrawable2)
       
   106 	{
       
   107 	const TInt dw = aDestRect.Width();
       
   108 	const TInt dh = aDestRect.Height();
       
   109 	const TInt xu = dw/2;
       
   110 	const TInt yu = dh;
       
   111 	
       
   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);
       
   115 	}
       
   116 
       
   117 /**
       
   118 Draws two drawables to fit dest rect in the following pattern:
       
   119 A
       
   120 B
       
   121 */
       
   122 void CTDirectGdiResource::DrawTestPattern2(const TRect& aDestRect,
       
   123 			const TDrawableSourceAndEquivRotatedBmps& aDrawable1, const TDrawableSourceAndEquivRotatedBmps& aDrawable2)
       
   124 	{
       
   125 	const TInt dw = aDestRect.Width();
       
   126 	const TInt dh = aDestRect.Height();
       
   127 	const TInt xu = dw;
       
   128 	const TInt yu = dh/2;
       
   129 	
       
   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);
       
   133 	}
       
   134 
       
   135 /**
       
   136 Draws image rotated to fit dest rect in the following pattern:
       
   137 AB
       
   138 CC
       
   139 DD
       
   140 */
       
   141 void CTDirectGdiResource::DrawTestPattern1(const TRect& aDestRect, const TRect* aSrcRect)
       
   142 	{
       
   143 	const TInt dw = aDestRect.Width();
       
   144 	const TInt dh = aDestRect.Height();
       
   145 	const TInt xu = dw/2;
       
   146 	const TInt yu = dh/5;
       
   147 	
       
   148 	if (aSrcRect)
       
   149 		{
       
   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);
       
   158 		}
       
   159 	else
       
   160 		{
       
   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);
       
   169 		}
       
   170 	}
       
   171 
       
   172 /**
       
   173 Draws image rotated to fit dest rect in the following pattern:
       
   174 ACD
       
   175 BCD
       
   176 */
       
   177 void CTDirectGdiResource::DrawTestPattern2(const TRect& aDestRect, const TRect* aSrcRect)
       
   178 	{
       
   179 	const TInt dw = aDestRect.Width();
       
   180 	const TInt dh = aDestRect.Height();
       
   181 	const TInt xu = dw/5;
       
   182 	const TInt yu = dh/2;
       
   183 
       
   184 	if (aSrcRect)
       
   185 		{
       
   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);
       
   194 		}
       
   195 	else
       
   196 		{
       
   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);
       
   205 		}
       
   206 	}
       
   207 
       
   208 /**
       
   209 Draws image rotated to fit dest rect in the following pattern:
       
   210 AB
       
   211 CD
       
   212 */
       
   213 void CTDirectGdiResource::DrawTestPattern3(const TRect& aDestRect, const TRect* aSrcRect)
       
   214 	{
       
   215 	TInt dw = aDestRect.Width();
       
   216 	TInt dh = aDestRect.Height();
       
   217 	TInt xu = dw/2;
       
   218 	TInt yu = dh/2;
       
   219 
       
   220 	if (aSrcRect)
       
   221 		{
       
   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);
       
   230 		}
       
   231 	else
       
   232 		{
       
   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);
       
   241 		}
       
   242 	}
       
   243 
       
   244 /**
       
   245 @SYMTestCaseID			
       
   246 	GRAPHICS-DIRECTGDI-DRAWRESOURCE-0001
       
   247 
       
   248 @SYMTestPriority		
       
   249 	Critical
       
   250 	
       
   251 @SYMPREQ				
       
   252 	PREQ39
       
   253 
       
   254 @SYMREQ
       
   255 	REQ9178 
       
   256 	REQ9200 
       
   257 	REQ9201 
       
   258 	REQ9202 
       
   259 	REQ9203 
       
   260 	REQ9222 
       
   261 	REQ9228 
       
   262 	REQ9223 
       
   263 	REQ9236 
       
   264 	REQ9237
       
   265 	
       
   266 @SYMTestStatus			
       
   267 	Implemented
       
   268 	
       
   269 @SYMTestCaseDesc		
       
   270 	Draws drawable resources created from RSgDrawable and RSgImage objects.
       
   271 	
       
   272 @SYMTestActions			
       
   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
       
   278 		
       
   279 @SYMTestExpectedResults	
       
   280 	Resources are drawn on the given position, scaled to fit the destination
       
   281 	rectangle, clipped to current clipping region (if set).
       
   282 */
       
   283 void CTDirectGdiResource::TestDrawResource_ImageAsDrawableL()
       
   284 	{
       
   285 	_LIT(KTestName, "DrawResource_ImageAsDrawable");
       
   286 	if(!iRunningOomTests)
       
   287 		{
       
   288 		INFO_PRINTF1(KTestName);
       
   289 		}
       
   290 
       
   291 	TBuf<KFileNameLength> tag;
       
   292 	tag.Append(KTestName);
       
   293 
       
   294 	ResetGc();
       
   295 	if (iEnableClipRegion)
       
   296 		{
       
   297 		iGc->SetClippingRegion(iClip);
       
   298 		tag.Append(KClip);
       
   299 		}
       
   300 
       
   301 	if (iUseWriteAlpha)
       
   302 		{
       
   303 		iGc->SetDrawMode(DirectGdi::EDrawModeWriteAlpha);
       
   304 		tag.Append(KWriteAlpha);
       
   305 		}
       
   306 
       
   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]);
       
   311 
       
   312 	if (iEnableClipRegion)
       
   313 		{
       
   314 		iGc->ResetClippingRegion();
       
   315 		iGc->SetDrawMode(DirectGdi::EDrawModePEN);
       
   316 		}
       
   317 
       
   318 	SaveOutput(tag);
       
   319 	}
       
   320 
       
   321 /**
       
   322 @SYMTestCaseID			
       
   323 	GRAPHICS-DIRECTGDI-DRAWRESOURCE-0002
       
   324 	
       
   325 @SYMTestPriority		
       
   326 	Critical
       
   327 	
       
   328 @SYMPREQ				
       
   329 	PREQ39
       
   330 
       
   331 @SYMREQ
       
   332 	REQ9178 
       
   333 	REQ9200 
       
   334 	REQ9201 
       
   335 	REQ9202 
       
   336 	REQ9203 
       
   337 	REQ9222 
       
   338 	REQ9228 
       
   339 	REQ9223 
       
   340 	REQ9236 
       
   341 	REQ9237
       
   342 	
       
   343 @SYMTestStatus			
       
   344 	Implemented
       
   345 	
       
   346 @SYMTestCaseDesc		
       
   347 	Draw an image resource created from RSgImage object.
       
   348 	
       
   349 @SYMTestActions			
       
   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
       
   355 	
       
   356 @SYMTestExpectedResults	
       
   357 	Resources are drawn on the given position, unscaled, rotated and
       
   358 	clipped to current clipping region (if set).
       
   359 */
       
   360 void CTDirectGdiResource::TestDrawResource_PosL()
       
   361 	{
       
   362 	_LIT(KTestName, "DrawResource_Pos");
       
   363 	if(!iRunningOomTests)
       
   364 		{
       
   365 		INFO_PRINTF1(KTestName);
       
   366 		}
       
   367 
       
   368 	TBuf<KFileNameLength> tag;
       
   369 	tag.Append(KTestName);
       
   370 	
       
   371 	ResetGc();
       
   372 
       
   373 	if (iEnableClipRegion)
       
   374 		{
       
   375 		iGc->SetClippingRegion(iClip);
       
   376 		tag.Append(KClip);
       
   377 		}
       
   378 
       
   379 	if (iUseWriteAlpha)
       
   380 		{
       
   381 		iGc->SetDrawMode(DirectGdi::EDrawModeWriteAlpha);
       
   382 		tag.Append(KWriteAlpha);
       
   383 		}
       
   384 
       
   385 	DrawTestPattern1(TPoint(0,0));
       
   386 	DrawTestPattern1(TPoint(100,0));
       
   387 	DrawTestPattern1(TPoint(200,0));
       
   388 
       
   389 	DrawTestPattern1(TPoint(50,50));
       
   390 	DrawTestPattern1(TPoint(150,50));
       
   391 
       
   392 	DrawTestPattern1(TPoint(0,100));
       
   393 	DrawTestPattern1(TPoint(100,100));
       
   394 	DrawTestPattern1(TPoint(200,100));
       
   395 
       
   396 	DrawTestPattern1(TPoint(50,150));
       
   397 	DrawTestPattern1(TPoint(150,150));
       
   398 
       
   399 	DrawTestPattern1(TPoint(0,200));
       
   400 	DrawTestPattern1(TPoint(100,200));
       
   401 	DrawTestPattern1(TPoint(200,200));
       
   402 
       
   403 	if (iEnableClipRegion)
       
   404 		{
       
   405 		iGc->ResetClippingRegion();
       
   406 		iGc->SetDrawMode(DirectGdi::EDrawModePEN);
       
   407 		}
       
   408 
       
   409 	SaveOutput(tag);
       
   410 	}
       
   411 
       
   412 /**
       
   413 @SYMTestCaseID			
       
   414 	GRAPHICS-DIRECTGDI-DRAWRESOURCE-0003
       
   415 	
       
   416 @SYMTestPriority		
       
   417 	Critical
       
   418 	
       
   419 @SYMPREQ				
       
   420 	PREQ39
       
   421 
       
   422 @SYMREQ
       
   423 	REQ9178 
       
   424 	REQ9200 
       
   425 	REQ9201 
       
   426 	REQ9202 
       
   427 	REQ9203 
       
   428 	REQ9222 
       
   429 	REQ9228 
       
   430 	REQ9223 
       
   431 	REQ9236 
       
   432 	REQ9237
       
   433 	
       
   434 @SYMTestStatus			
       
   435 	Implemented
       
   436 	
       
   437 @SYMTestCaseDesc		
       
   438 	Draw a scaled image resource created from RSgImage object.
       
   439 	
       
   440 @SYMTestActions			
       
   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
       
   446 	
       
   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).
       
   450 */
       
   451 void CTDirectGdiResource::TestDrawResource_DestRectL()
       
   452 	{
       
   453 	_LIT(KTestName, "DrawResource_DestRect");
       
   454 	if(!iRunningOomTests)
       
   455 		{
       
   456 		INFO_PRINTF1(KTestName);
       
   457 		}
       
   458 
       
   459 	TBuf<KFileNameLength> tag;
       
   460 	tag.Append(KTestName);
       
   461 
       
   462 	ResetGc();
       
   463 
       
   464 	if (iEnableClipRegion)
       
   465 		{
       
   466 		iGc->SetClippingRegion(iClip);
       
   467 		tag.Append(KClip);
       
   468 		}
       
   469 
       
   470 	if (iUseWriteAlpha)
       
   471 		{
       
   472 		iGc->SetDrawMode(DirectGdi::EDrawModeWriteAlpha);
       
   473 		tag.Append(KWriteAlpha);
       
   474 		}
       
   475 
       
   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));
       
   482 
       
   483 	if (iEnableClipRegion)
       
   484 		{
       
   485 		iGc->ResetClippingRegion();
       
   486 		iGc->SetDrawMode(DirectGdi::EDrawModePEN);		
       
   487 		}
       
   488 
       
   489 	SaveOutput(tag);
       
   490 	}
       
   491 
       
   492 /**
       
   493 @SYMTestCaseID			
       
   494 	GRAPHICS-DIRECTGDI-DRAWRESOURCE-0004
       
   495 	
       
   496 @SYMTestPriority		
       
   497 	Critical
       
   498 	
       
   499 @SYMPREQ				
       
   500 	PREQ39
       
   501 
       
   502 @SYMREQ
       
   503 	REQ9178 
       
   504 	REQ9200 
       
   505 	REQ9201 
       
   506 	REQ9202 
       
   507 	REQ9203 
       
   508 	REQ9222 
       
   509 	REQ9228 
       
   510 	REQ9223 
       
   511 	REQ9236 
       
   512 	REQ9237
       
   513 	
       
   514 @SYMTestStatus			
       
   515 	Implemented
       
   516 	
       
   517 @SYMTestCaseDesc		
       
   518 	Draw a scaled portion of an image resource created from RSgImage object.
       
   519 	
       
   520 @SYMTestActions			
       
   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
       
   526 	
       
   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).
       
   530 */
       
   531 void CTDirectGdiResource::TestDrawResource_DestRectSrcRectL()
       
   532 	{
       
   533 	_LIT(KTestName, "DrawResource_DestRectSrcRect");
       
   534 	if(!iRunningOomTests)
       
   535 		{
       
   536 		INFO_PRINTF1(KTestName);
       
   537 		}
       
   538 	
       
   539 	TBuf<KFileNameLength> tag;
       
   540 	tag.Append(KTestName);
       
   541 
       
   542 	ResetGc();
       
   543 	if (iEnableClipRegion)
       
   544 		{
       
   545 		iGc->SetClippingRegion(iClip);
       
   546 		tag.Append(KClip);
       
   547 		}
       
   548 
       
   549 	if (iUseWriteAlpha)
       
   550 		{
       
   551 		iGc->SetDrawMode(DirectGdi::EDrawModeWriteAlpha);
       
   552 		tag.Append(KWriteAlpha);
       
   553 		}
       
   554 
       
   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);
       
   562 
       
   563 	if (iEnableClipRegion)
       
   564 		{
       
   565 		iGc->ResetClippingRegion();
       
   566 		iGc->SetDrawMode(DirectGdi::EDrawModePEN);		
       
   567 		}
       
   568 
       
   569 	SaveOutput(tag);
       
   570 	}
       
   571 
       
   572 /**
       
   573 @SYMTestCaseID			
       
   574 	GRAPHICS-DIRECTGDI-DRAWRESOURCE-0005
       
   575 	
       
   576 @SYMTestPriority		
       
   577 	Critical
       
   578 	
       
   579 @SYMPREQ				
       
   580 	PREQ39
       
   581 
       
   582 @SYMREQ
       
   583 	REQ9178 
       
   584 	REQ9200 
       
   585 	REQ9201 
       
   586 	REQ9202 
       
   587 	REQ9203 
       
   588 	REQ9222 
       
   589 	REQ9228 
       
   590 	REQ9223 
       
   591 	REQ9236 
       
   592 	REQ9237
       
   593 	
       
   594 @SYMTestStatus			
       
   595 	Implemented
       
   596 	
       
   597 @SYMTestCaseDesc
       
   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.
       
   600 	
       
   601 @SYMTestActions	
       
   602 	Create an RSgImage,
       
   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.
       
   606 	
       
   607 @SYMTestExpectedResults	
       
   608 	Driver returns KErrBadHandle for each attempt to draw invalid resource.
       
   609  */
       
   610 void CTDirectGdiResource::TestDrawResource_NullHandleL()
       
   611 	{
       
   612 	_LIT(KTestName, "DrawResource_NullHandle");
       
   613 	if(!iRunningOomTests)
       
   614 		{
       
   615 		INFO_PRINTF1(KTestName);
       
   616 		}
       
   617 	
       
   618 	ResetGc();
       
   619 
       
   620 	CDirectGdiDriver* drv = CDirectGdiDriver::Static();
       
   621 	TESTL(drv != NULL);
       
   622 
       
   623 	// null handle
       
   624 	//
       
   625 	RDirectGdiDrawableSource dwb(*drv);
       
   626 	RDirectGdiDrawableSource img(*drv);
       
   627 	
       
   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;
       
   634 
       
   635 	TPoint pos;
       
   636 	TRect dstRect(pos, TSize(100,100));
       
   637 	TRect srcRect(pos, TSize(10,10));	
       
   638 	
       
   639 	// DrawResource(const TRect&, const RDirectGdiDrawableSource&, const TDesC8&)
       
   640 	iGc->DrawResource(dstRect, drawableSource, KNullDesC8);
       
   641 	TESTL(iGc->GetError() == KErrBadHandle);
       
   642 
       
   643 	for (TInt rot=0; rot<sizeof(TestRot)/sizeof(TestRot[0]); ++rot)
       
   644 		{
       
   645 		// DrawResource(const TPoint&, const RDirectGdiDrawableSource&, DirectGdi::TGraphicsRotation)
       
   646 		iGc->DrawResource(pos, imageSource, TestRot[rot]);
       
   647 		TESTL(iGc->GetError() == KErrBadHandle);
       
   648 
       
   649 		// DrawResource(const TRect&, const RDirectGdiDrawableSource&, DirectGdi::TGraphicsRotation)
       
   650 		iGc->DrawResource(dstRect, imageSource, TestRot[rot]);
       
   651 		TESTL(iGc->GetError() == KErrBadHandle);
       
   652 
       
   653 		// DrawResource(const TRectt&, const RDirectGdiDrawableSource&, const TRect&, DirectGdi::TGraphicsRotation)
       
   654 		iGc->DrawResource(dstRect, imageSource, srcRect, TestRot[rot]);
       
   655 		TESTL(iGc->GetError() == KErrBadHandle);
       
   656 		}
       
   657 	}
       
   658 
       
   659 /**
       
   660 @SYMTestCaseID			
       
   661 	GRAPHICS-DIRECTGDI-DRAWRESOURCE-0006
       
   662 	
       
   663 @SYMTestPriority		
       
   664 	Critical
       
   665 	
       
   666 @SYMPREQ				
       
   667 	PREQ39
       
   668 
       
   669 @SYMREQ
       
   670 	REQ9178 
       
   671 	REQ9200 
       
   672 	REQ9201 
       
   673 	REQ9202 
       
   674 	REQ9203 
       
   675 	REQ9222 
       
   676 	REQ9228 
       
   677 	REQ9223 
       
   678 	REQ9236 
       
   679 	REQ9237
       
   680 	
       
   681 @SYMTestStatus			
       
   682 	Implemented
       
   683 	
       
   684 @SYMTestCaseDesc		
       
   685 	Draw onto an RSgImage as a target, then convert to it a source and draw that 
       
   686 	as a resource.
       
   687 	
       
   688 @SYMTestActions			
       
   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.
       
   692 	Clear the target.
       
   693 	Draw the source to the target.
       
   694 	
       
   695 @SYMTestExpectedResults	
       
   696 	The three rectangles should have been appear when the source is copied to the target. 
       
   697 */
       
   698 void CTDirectGdiResource::TestDrawTargetAsSourceL()
       
   699 	{
       
   700 	_LIT(KTestName, "DrawResource_TestDrawTargetAsSource");
       
   701 	if(!iRunningOomTests)
       
   702 		{
       
   703 		INFO_PRINTF1(KTestName);
       
   704 		}
       
   705 	
       
   706 	ResetGc();		
       
   707 	
       
   708 	// draw to the current target
       
   709 	TRect rect(20,20,100,100);	
       
   710 	iGc->SetPenColor(TRgb(255,0,0));
       
   711 	iGc->DrawRect(rect);
       
   712 	iGc->SetPenColor(TRgb(0,255,0));
       
   713 	rect.Move(20,20);
       
   714 	iGc->DrawRect(rect);
       
   715 	iGc->SetPenColor(TRgb(0,0,255));
       
   716 	rect.Move(20,20);
       
   717 	iGc->DrawRect(rect);
       
   718 	TESTNOERROR(iGc->GetError());
       
   719 	
       
   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.
       
   722 	if (iUseDirectGdi)
       
   723 		{
       
   724 		iGdiTarget->Finish();
       
   725 		TESTNOERROR(iGc->GetError());
       
   726 		
       
   727 		// get the target bitmap
       
   728 		CFbsBitmap* bitmap = iGdiTarget->GetTargetFbsBitmapL();
       
   729 		TESTL(bitmap != NULL);
       
   730 		
       
   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;
       
   736 		RSgImage sgImage;	
       
   737 		TInt err = sgImage.Create(imageInfo, bitmap->DataAddress(), bitmap->DataStride());
       
   738 		CleanupClosePushL(sgImage);	
       
   739 		TESTNOERRORL(err);
       
   740 		
       
   741 		CDirectGdiDriver* dgdiDriver = CDirectGdiDriver::Static();	
       
   742 		TESTL(dgdiDriver != NULL);	
       
   743 		
       
   744 		// Create a RDirectGdiDrawableSource from the RSgImage
       
   745 		RDirectGdiDrawableSource dgdiImageSource(*dgdiDriver);
       
   746 		err = dgdiImageSource.Create(sgImage);
       
   747 		TESTNOERRORL(err);
       
   748 		
       
   749 		iGc->Clear();
       
   750 		
       
   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;
       
   756 		
       
   757 		// Draw the RDirectGdiDrawableSource using CDirectGdiContext::DrawResource	
       
   758 		iGc->DrawResource(TPoint(0,0), imageSource);		
       
   759 		
       
   760 		dgdiImageSource.Close();
       
   761 		CleanupStack::PopAndDestroy(1, &sgImage);
       
   762 		}
       
   763 	
       
   764 	// Output the target image to make sure it contains what was drawn onto the source
       
   765 	TESTNOERROR(WriteTargetOutput(iTestParams, KTestName()));
       
   766 	}
       
   767 
       
   768 /**
       
   769 @SYMTestCaseID				
       
   770 	GRAPHICS-DIRECTGDI-DRAWRESOURCE-0007
       
   771 	
       
   772 @SYMTestPriority			
       
   773 	Critical
       
   774 	
       
   775 @SYMPREQ					
       
   776 	PREQ39
       
   777 
       
   778 @SYMREQ
       
   779 	REQ9178 
       
   780 	REQ9200 
       
   781 	REQ9201 
       
   782 	REQ9202 
       
   783 	REQ9203 
       
   784 	REQ9222 
       
   785 	REQ9228 
       
   786 	REQ9223 
       
   787 	REQ9236 
       
   788 	REQ9237
       
   789 	
       
   790 @SYMTestStatus				
       
   791 	Implemented
       
   792 	
       
   793 @SYMTestCaseDesc			
       
   794 	Create two CDirectGdiImageSource object from the same RSgImage
       
   795 	
       
   796 @SYMTestActions				
       
   797 	Test the use case where we:
       
   798 	Create an RSgImage
       
   799 	Create two CDirectGdiImageSource objects.
       
   800 	The CDirectGdiImageSource objects should share the EGL image created from
       
   801 	the RSgImage
       
   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.
       
   805 	
       
   806 @SYMTestExpectedResults		
       
   807 	This test does not output an image, it is just for testing that no errors or panics occur.
       
   808 */
       
   809 void CTDirectGdiResource::TestShareEGLImageBetweenSourcesL()
       
   810 	{
       
   811 	_LIT(KTestName, "ShareEGLImageBetweenSources");
       
   812 	if(!iRunningOomTests)
       
   813 		{
       
   814 		INFO_PRINTF1(KTestName);
       
   815 		}
       
   816 	
       
   817 	ResetGc();	
       
   818 	
       
   819 	CDirectGdiDriver* dgdiDriver = CDirectGdiDriver::Static();
       
   820 	TESTL(dgdiDriver != NULL);	
       
   821 	
       
   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);	
       
   828 	
       
   829 	// Create an RSgImage from the CFbsBitmap
       
   830 	TSgImageInfo imageInfo;
       
   831 	imageInfo.iSizeInPixels = patternSize;
       
   832 	imageInfo.iPixelFormat = iTestParams.iSourceResourcePixelFormat;
       
   833 	imageInfo.iUsage = ESgUsageDirectGdiSource;
       
   834 	RSgImage sgImage;	
       
   835 	TInt res = sgImage.Create(imageInfo, bitmap->DataAddress(), bitmap->DataStride());	
       
   836 	TESTNOERRORL(res);	
       
   837 	CleanupClosePushL(sgImage);
       
   838 	
       
   839 	// Create a RDirectGdiDrawableSource from the RSgImage
       
   840 	RDirectGdiDrawableSource dgdiImageSource1(*dgdiDriver);	
       
   841 	res = dgdiImageSource1.Create(sgImage);		
       
   842 	TESTNOERRORL(res);
       
   843 	CleanupClosePushL(dgdiImageSource1);
       
   844 	
       
   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);		
       
   850 	TESTNOERRORL(res);	
       
   851 	
       
   852 	dgdiImageSource1.Close();
       
   853 	dgdiImageSource2.Close();
       
   854 	CleanupStack::PopAndDestroy(3, bitmap);
       
   855 	}
       
   856 
       
   857 /**
       
   858 @SYMTestCaseID			
       
   859 	GRAPHICS-DIRECTGDI-DRAWRESOURCE-0008
       
   860 	
       
   861 @SYMTestPriority		
       
   862 	Critical
       
   863 	
       
   864 @SYMPREQ				
       
   865 	PREQ39
       
   866 
       
   867 @SYMREQ
       
   868 	REQ9178 
       
   869 	REQ9200 
       
   870 	REQ9201 
       
   871 	REQ9202 
       
   872 	REQ9203 
       
   873 	REQ9222 
       
   874 	REQ9228 
       
   875 	REQ9223 
       
   876 	REQ9236 
       
   877 	REQ9237
       
   878 	
       
   879 @SYMTestStatus			
       
   880 	Implemented
       
   881 	
       
   882 @SYMTestCaseDesc		
       
   883 	Draw resource with valid resource but other invalid parameters
       
   884 	
       
   885 @SYMTestActions			
       
   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
       
   890 	
       
   891 	
       
   892 @SYMTestExpectedResults	
       
   893 	Driver returns KErrArgument for each attempt to draw resource with invalid parameters.
       
   894 */
       
   895 void CTDirectGdiResource::TestDrawResource_InvalidParameterL()
       
   896 	{
       
   897 	_LIT(KTestName, "DrawResource_InvalidParameter");
       
   898 	if(!iRunningOomTests)
       
   899 		{
       
   900 		INFO_PRINTF1(KTestName);
       
   901 		}
       
   902 	
       
   903 	ResetGc();
       
   904 
       
   905 	// destRect can be anything
       
   906 	TPoint pos;
       
   907 	TRect dstRect(pos, iImgSz);
       
   908 
       
   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);
       
   914 	
       
   915 	for (TInt rot=0; rot<sizeof(TestRot)/sizeof(TestRot[0]); ++rot)
       
   916 		{
       
   917 		iGc->DrawResource(dstRect, iImgSrc, srcRect1, TestRot[rot]);
       
   918 		TESTL(iGc->GetError() == KErrArgument);
       
   919 
       
   920 		iGc->DrawResource(dstRect, iImgSrc, srcRect2, TestRot[rot]);
       
   921 		TESTL(iGc->GetError() == KErrArgument);
       
   922 
       
   923 		iGc->DrawResource(dstRect, iImgSrc, srcRect3, TestRot[rot]);
       
   924 		TESTL(iGc->GetError() == KErrArgument);
       
   925 		}
       
   926 	}
       
   927 
       
   928 /**
       
   929 @SYMTestCaseID			
       
   930 	GRAPHICS-DIRECTGDI-DRAWRESOURCE-0009
       
   931 	
       
   932 @SYMTestPriority		
       
   933 	Critical
       
   934 	
       
   935 @SYMPREQ				
       
   936 	PREQ39
       
   937 
       
   938 @SYMREQ
       
   939 	REQ9178 
       
   940 	REQ9200 
       
   941 	REQ9201 
       
   942 	REQ9202 
       
   943 	REQ9203 
       
   944 	REQ9222 
       
   945 	REQ9228 
       
   946 	REQ9223 
       
   947 	REQ9236 
       
   948 	REQ9237
       
   949 	
       
   950 @SYMTestStatus			
       
   951 	Implemented
       
   952 	
       
   953 @SYMTestCaseDesc		
       
   954 	Draw resources with a non-zero origin set.
       
   955 	
       
   956 @SYMTestActions			
       
   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.
       
   960 	
       
   961 @SYMTestExpectedResults	
       
   962 	Resource drawn at the specified location relative to drawing context origin.
       
   963 */
       
   964 void CTDirectGdiResource::TestDrawResource_NonZeroOriginL()
       
   965 	{
       
   966 	_LIT(KTestName, "DrawResource_NonZeroOrigin");
       
   967 	if(!iRunningOomTests)
       
   968 		{
       
   969 		INFO_PRINTF1(KTestName);
       
   970 		}
       
   971 	
       
   972 	const TPoint origin[] = 
       
   973 		{
       
   974 		TPoint(-100,-100),
       
   975 		TPoint(100,-100),
       
   976 		TPoint(100,0),
       
   977 		TPoint(-100,100),
       
   978 		TPoint(0,100),
       
   979 		TPoint(100,100)		
       
   980 		};
       
   981 
       
   982 	for (TInt idx=0; idx<sizeof(origin)/sizeof(origin[0]); ++idx)
       
   983 		{
       
   984 		TBuf<KFileNameLength> tag;
       
   985 		tag.Append(KTestName);
       
   986 		tag.AppendNum(idx);
       
   987 
       
   988 		ResetGc();	
       
   989 		iGc->SetOrigin(origin[idx]);
       
   990 
       
   991 		TRect srcRect(TPoint(0,0), iImgSz);
       
   992 
       
   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);
       
   999 
       
  1000 		SaveOutput(tag);
       
  1001 		}
       
  1002 	}
       
  1003 
       
  1004 /**
       
  1005 @SYMTestCaseID		
       
  1006 	GRAPHICS-DIRECTGDI-DRAWRESOURCE-0010
       
  1007 
       
  1008 @SYMTestPriority
       
  1009 	Critical
       
  1010 
       
  1011 @SYMPREQ
       
  1012 	PREQ39
       
  1013 
       
  1014 @SYMREQ
       
  1015 	REQ9178 
       
  1016 	REQ9200 
       
  1017 	REQ9201 
       
  1018 	REQ9202 
       
  1019 	REQ9203 
       
  1020 	REQ9222 
       
  1021 	REQ9228 
       
  1022 	REQ9223 
       
  1023 	REQ9236 
       
  1024 	REQ9237
       
  1025 
       
  1026 @SYMTestCaseDesc
       
  1027 	Tests if DirectGDI methods returns an error when called on a not constructed RDirectGdiDrawableSource object.
       
  1028 
       
  1029 @SYMTestActions		
       
  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.
       
  1034 
       
  1035 @SYMTestExpectedResults
       
  1036 	CDirectGdiContext::DrawResource should return KErrBadHandle.
       
  1037 */
       
  1038 void CTDirectGdiResource::TestDrawResourceSourceNotCreatedL()
       
  1039 	{
       
  1040 	_LIT(KTestName, "DrawResource_SourceNotCreated");
       
  1041 	if(!iRunningOomTests)
       
  1042 		{
       
  1043 		INFO_PRINTF1(KTestName);
       
  1044 		}
       
  1045 	
       
  1046 	if (iUseDirectGdi)
       
  1047 		{
       
  1048 		ResetGc();
       
  1049 		
       
  1050 		TInt res = CDirectGdiDriver::Open();
       
  1051 		TESTNOERRORL(res);		
       
  1052 		
       
  1053 		CDirectGdiDriver* dgdiDriver = CDirectGdiDriver::Static();
       
  1054 		TESTL(dgdiDriver != NULL);	
       
  1055 		CleanupClosePushL(*dgdiDriver);	
       
  1056 		
       
  1057 		// Create a CFbsBitmap
       
  1058 		TSize patternSize(90,50);
       
  1059 		CFbsBitmap* bitmap = CreateCheckedBoardBitmapL(iTestParams.iSourceResourcePixelFormat, patternSize);
       
  1060 		TESTL(NULL != bitmap);
       
  1061 		CleanupStack::PushL(bitmap);	
       
  1062 		
       
  1063 		// Create an RSgImage from the CFbsBitmap
       
  1064 		TSgImageInfo imageInfo;
       
  1065 		imageInfo.iSizeInPixels = patternSize;
       
  1066 		imageInfo.iPixelFormat = iTestParams.iSourceResourcePixelFormat;
       
  1067 		imageInfo.iUsage = ESgUsageDirectGdiSource;
       
  1068 		RSgImage sgImage;	
       
  1069 		res = sgImage.Create(imageInfo, bitmap->DataAddress(), bitmap->DataStride());
       
  1070 		CleanupClosePushL(sgImage);
       
  1071 		TESTNOERRORL(res);		
       
  1072 		
       
  1073 		//allocate RDirectGdiDrawableSource, but do not call Create() method
       
  1074 		RDirectGdiDrawableSource dgdiImageSource(*dgdiDriver);	
       
  1075 		
       
  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); 
       
  1083 		}
       
  1084 	}
       
  1085 
       
  1086 /** 
       
  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
       
  1092 */	
       
  1093 TVerdict CTDirectGdiResource::doTestStepL()
       
  1094 	{			
       
  1095 	INFO_PRINTF1(_L("DirectGdi Resource Tests"));	
       
  1096 		
       
  1097 	// Test for each target pixel format
       
  1098 	for(TInt targetPixelFormatIndex = iTargetPixelFormatArray.Count() - 1; targetPixelFormatIndex >= 0 ; targetPixelFormatIndex--)
       
  1099 		{ 
       
  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--)
       
  1104 			{
       
  1105 			TBool doOOM = EFalse;
       
  1106 			iTestParams.iSourceResourcePixelFormat = iSourceResourcePixelFormatArray[sourceResourcePixelFormatIndex];
       
  1107 			if(EUidPixelFormatXRGB_8888 == iTestParams.iSourceResourcePixelFormat)
       
  1108 				doOOM = ETrue;
       
  1109 			TBuf<KPixelFormatNameLength> sourcePixelFormatName(TDisplayModeMapping::ConvertPixelFormatToPixelFormatString(iTestParams.iSourceResourcePixelFormat));
       
  1110 			INFO_PRINTF3(_L("Target Pixel Format: %S;  Source Resource Pixel Format: %S"), &targetPixelFormatName, &sourcePixelFormatName);							
       
  1111 					
       
  1112 			SetTargetL(iTestParams.iTargetPixelFormat);
       
  1113 			CreateCommonResourceL();					
       
  1114 			
       
  1115 			RunTestsL();
       
  1116 			
       
  1117 			// only run OOM tests for one target pixel format to prevent duplication of tests
       
  1118 			if (targetPixelFormatIndex == 0 && doOOM)
       
  1119 				{		
       
  1120 				RunOomTestsL(); // from base class
       
  1121 				}
       
  1122 			
       
  1123 			DestroyCommonResource();			
       
  1124 			}
       
  1125 		}
       
  1126 	CloseTMSGraphicsStep();
       
  1127 	return TestStepResult();
       
  1128 	}
       
  1129 
       
  1130 /**
       
  1131 Helper function used to create the resources that are shared between all the tests in this file.
       
  1132  */
       
  1133 void CTDirectGdiResource::CreateCommonResourceL()
       
  1134 	{
       
  1135 	// Create a CFbsBitmap
       
  1136 	CFbsBitmap* bitmap;
       
  1137 	RSgDrawable sgDwb;
       
  1138 
       
  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();
       
  1144 	
       
  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;	
       
  1150 
       
  1151 	// Create an RSgImage from the CFbsBitmap
       
  1152 	TSgImageInfo imageInfo;
       
  1153 	imageInfo.iSizeInPixels = iImgSz;
       
  1154 	imageInfo.iPixelFormat = iTestParams.iSourceResourcePixelFormat;
       
  1155 	imageInfo.iUsage = ESgUsageDirectGdiSource;
       
  1156 
       
  1157 	RSgImage sgImage;	
       
  1158 	TInt res = sgImage.Create(imageInfo, bitmap->DataAddress(), bitmap->DataStride());
       
  1159 	TESTNOERRORL(res);
       
  1160 	CleanupClosePushL(sgImage);	
       
  1161 
       
  1162 	if (iUseDirectGdi)
       
  1163 		{
       
  1164 		// Create a RDirectGdiDrawableSource from the RSgImage
       
  1165 
       
  1166 		// Driver must've been initialised by framework, no need to re-open
       
  1167 		//
       
  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();
       
  1171 		TEST(drv != NULL);
       
  1172 		
       
  1173 		iImgSrc.iDrawableSrc = new RDirectGdiDrawableSource(*drv);
       
  1174 		TEST(iImgSrc.iDrawableSrc != NULL);
       
  1175 		res = iImgSrc.iDrawableSrc->Create(sgImage);		
       
  1176 		TESTNOERRORL(res);	
       
  1177 
       
  1178 		// Create drawable source from drawable
       
  1179 		res = sgDwb.Open(sgImage.Id());
       
  1180 		TESTNOERRORL(res);
       
  1181 		CleanupClosePushL(sgDwb);
       
  1182 
       
  1183 		iDwbSrc[0].iDrawableSrc = new RDirectGdiDrawableSource(*drv);
       
  1184 		TEST(iDwbSrc[0].iDrawableSrc != NULL);
       
  1185 		res = iDwbSrc[0].iDrawableSrc->Create(sgDwb);
       
  1186 		TESTNOERRORL(res);
       
  1187 		
       
  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);
       
  1192 		TESTNOERRORL(res);
       
  1193 		}
       
  1194 	else
       
  1195 		{
       
  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;
       
  1201 		
       
  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;
       
  1207 		}
       
  1208 
       
  1209 	// Create horizontal and vertical stripe clipping region
       
  1210 	TInt w = 1;
       
  1211 	TBool on = EFalse;
       
  1212 	for (TInt x=0; x<50; x+=w)
       
  1213 		{
       
  1214 		on = !on;
       
  1215 		if (on && x+w<50)
       
  1216 			{
       
  1217 			TRect r1(TPoint(x,0), TSize(w, 200));
       
  1218 			TRect r2(TPoint(100+x,0), TSize(w, 200));
       
  1219 			iClip.AddRect(r1);
       
  1220 			iClip.AddRect(r2);
       
  1221 			}
       
  1222 		++w;
       
  1223 		}
       
  1224 	TInt h = 1;
       
  1225 	on = EFalse;
       
  1226 	for (TInt y=0; y<200; y+=h)
       
  1227 		{
       
  1228 		on = !on;
       
  1229 		if (on && y+h<200)
       
  1230 			{
       
  1231 			TRect r1(TPoint(0,y), TSize(100, h));
       
  1232 			TRect r2(TPoint(100,y), TSize(100, h));
       
  1233 			iClip.AddRect(r1);
       
  1234 			iClip.AddRect(r2);
       
  1235 			}
       
  1236 		++h;
       
  1237 		}
       
  1238 	
       
  1239 	if (!iUseDirectGdi)
       
  1240 		{
       
  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);
       
  1245 		SetActive();
       
  1246 		CActiveScheduler::Start();
       
  1247 		}
       
  1248 	
       
  1249 	// Destroy bitmap, image and drawable.
       
  1250 	CleanupStack::PopAndDestroy(iUseDirectGdi ? 2 : 1, &sgImage);
       
  1251 	}
       
  1252 
       
  1253 /**
       
  1254 Helper function used to destroy the resources that are shared between all the tests in this file.
       
  1255  */
       
  1256 void CTDirectGdiResource::DestroyCommonResource()
       
  1257 	{
       
  1258 	if (iImgSrc.iDrawableSrc)
       
  1259 		{
       
  1260 		iImgSrc.iDrawableSrc->Close();
       
  1261 		delete iImgSrc.iDrawableSrc;
       
  1262 		iImgSrc.iDrawableSrc = NULL;
       
  1263 		}
       
  1264 	
       
  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;	
       
  1273 
       
  1274 	for (TInt ii=0; ii<2; ++ii)
       
  1275 		{
       
  1276 		if (iDwbSrc[ii].iDrawableSrc)
       
  1277 			{
       
  1278 			iDwbSrc[ii].iDrawableSrc->Close();
       
  1279 			delete iDwbSrc[ii].iDrawableSrc;
       
  1280 			iDwbSrc[ii].iDrawableSrc = NULL;
       
  1281 			}
       
  1282 		
       
  1283 		iDwbSrc[ii].iBmpRotNone = NULL;
       
  1284 		iDwbSrc[ii].iBmpRot90 = NULL;
       
  1285 		iDwbSrc[ii].iBmpRot180 = NULL;
       
  1286 		iDwbSrc[ii].iBmpRot270 = NULL;		
       
  1287 		}
       
  1288 
       
  1289 	iClip.Close();
       
  1290 	}
       
  1291 
       
  1292 /**
       
  1293 Override of base class virtual
       
  1294 @leave Gets system wide error code
       
  1295 @return - TVerdict code
       
  1296 */
       
  1297 TVerdict CTDirectGdiResource::doTestStepPreambleL()
       
  1298 	{				
       
  1299 	CTDirectGdiStepBase::doTestStepPreambleL();
       
  1300 	CActiveScheduler::Add(this);
       
  1301 	iBitmapRotator = CBitmapRotator::NewL();		
       
  1302 	return TestStepResult();
       
  1303 	}
       
  1304 
       
  1305 /**
       
  1306 Override of base class virtual
       
  1307 @leave Gets system wide error code
       
  1308 @return - TVerdict code
       
  1309 */
       
  1310 TVerdict CTDirectGdiResource::doTestStepPostambleL()
       
  1311 	{		 
       
  1312 	delete iBitmapRotator;	
       
  1313 	iBitmapRotator = NULL;
       
  1314 	CTDirectGdiStepBase::doTestStepPostambleL();
       
  1315 	return TestStepResult();
       
  1316 }
       
  1317 
       
  1318 void CTDirectGdiResource::DoDrawTestL()
       
  1319 	{
       
  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();
       
  1332 	}
       
  1333 
       
  1334 /**
       
  1335 Override of base class pure virtual
       
  1336 Lists the tests to be run
       
  1337 */
       
  1338 void CTDirectGdiResource::RunTestsL()
       
  1339 	{		
       
  1340 	// For all combination of destination and source pixel format do the following tests
       
  1341 	//
       
  1342 	DoDrawTestL();
       
  1343 	
       
  1344 	// Extra test using EDrawModeWriteAlpha. Geometry tests are irrelevant here, only contents tests are.
       
  1345 	//
       
  1346 	if (SourceResourceHasAlpha())
       
  1347 		{
       
  1348 		iUseWriteAlpha = ETrue;
       
  1349 		DoDrawTestL();
       
  1350 		iUseWriteAlpha = EFalse;
       
  1351 		}
       
  1352 
       
  1353 	// Geometry and negative tests doesn't need repeating, do it once
       
  1354 	//
       
  1355 	if (OneTimeTestEnabled())
       
  1356 		{
       
  1357 		iEnableClipRegion = ETrue;
       
  1358 		DoDrawTestL();
       
  1359 		iEnableClipRegion = EFalse;
       
  1360 
       
  1361 		SetTestStepID(_L("GRAPHICS-DIRECTGDI-DRAWRESOURCE-0009"));
       
  1362 		TestDrawResource_NonZeroOriginL();
       
  1363 		RecordTestResultL();
       
  1364 		if (iUseDirectGdi)
       
  1365 			{
       
  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();
       
  1377 			}		
       
  1378 		}
       
  1379 
       
  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
       
  1382 	//
       
  1383 	if (iTestParams.iTargetPixelFormat == iTestParams.iSourceResourcePixelFormat)
       
  1384 		{
       
  1385 		SetTestStepID(_L("GRAPHICS-DIRECTGDI-DRAWRESOURCE-0006"));
       
  1386 		TestDrawTargetAsSourceL();
       
  1387 		RecordTestResultL();
       
  1388 		}
       
  1389 
       
  1390 	if (iUseDirectGdi)
       
  1391 		{
       
  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();
       
  1396 		}
       
  1397 	}
       
  1398 
       
  1399 /**
       
  1400 From CActive
       
  1401  */
       
  1402 void CTDirectGdiResource::RunL()
       
  1403 	{
       
  1404 	switch (iCurrentState)
       
  1405 		{
       
  1406 		case ERotatingBitmap90:
       
  1407 			// Rotate the next bitmap (180)
       
  1408 			iCurrentState = ERotatingBitmap180;
       
  1409 			iBitmapRotator->Rotate(&iStatus, *(iImgSrc.iBmpRotNone), *(iImgSrc.iBmpRot180), CBitmapRotator::ERotation180DegreesClockwise);
       
  1410 			SetActive();
       
  1411 			break;
       
  1412 			
       
  1413 		case ERotatingBitmap180:
       
  1414 			// Rotate the next bitmap (270)
       
  1415 			iCurrentState = ERotatingBitmap270;
       
  1416 			iBitmapRotator->Rotate(&iStatus, *(iImgSrc.iBmpRotNone), *(iImgSrc.iBmpRot270), CBitmapRotator::ERotation270DegreesClockwise);
       
  1417 			SetActive();
       
  1418 			break;
       
  1419 			
       
  1420 		case ERotatingBitmap270:
       
  1421 			// Finished rotating the bitmaps, run the tests now
       
  1422 			iCurrentState = EDone;			
       
  1423 			CActiveScheduler::Stop();
       
  1424 			break;
       
  1425 		}
       
  1426 	}
       
  1427 
       
  1428 /**
       
  1429 From CActive
       
  1430  */
       
  1431 void CTDirectGdiResource::DoCancel()
       
  1432 	{
       
  1433 	}