os/graphics/windowing/windowserver/test/tauto/tdrawresource.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/windowing/windowserver/test/tauto/tdrawresource.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,1144 @@
     1.4 +// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +//
    1.18 +
    1.19 +/**
    1.20 + @file
    1.21 + @test
    1.22 + @internalComponent - Internal Symbian test code
    1.23 +*/
    1.24 +
    1.25 +#include "tdrawresource.h"
    1.26 +#include <graphics/sgimage.h>
    1.27 +#include <graphics/sgutils.h>
    1.28 +#include <graphics/directgdidrawablesource.h>
    1.29 +#include <graphics/sgresourceinternal.h>
    1.30 +#include <graphics/wsdrawresource.h>
    1.31 +
    1.32 +
    1.33 +__WS_CONSTRUCT_STEP__(DrawResource);
    1.34 +
    1.35 +
    1.36 +#if defined(__X86GCC__)
    1.37 +extern "C" TInt atexit(void (*function)(void))
    1.38 +	{
    1.39 +	return KErrNone;
    1.40 +	}
    1.41 +#endif
    1.42 +
    1.43 +//
    1.44 +// class CTestWsGraphicsContext
    1.45 +//
    1.46 +CTestWsGraphicsContext* CTestWsGraphicsContext::NewL(RDirectGdiImageTarget& aTarget)
    1.47 +	{
    1.48 +	CTestWsGraphicsContext* self = new(ELeave) CTestWsGraphicsContext;
    1.49 +	CleanupStack::PushL(self);
    1.50 +	self->ConstructL(aTarget);
    1.51 +	CleanupStack::Pop(self);
    1.52 +	return self;
    1.53 +	}
    1.54 +
    1.55 +void CTestWsGraphicsContext::ConstructL(RDirectGdiImageTarget& aTarget)
    1.56 +	{
    1.57 +	CDirectGdiDriver* driver = CDirectGdiDriver::Static();
    1.58 +	User::LeaveIfNull(driver);
    1.59 +	iContext = CDirectGdiContext::NewL(*driver);
    1.60 +	TInt err = iContext->Activate(aTarget);
    1.61 +	User::LeaveIfError(err);
    1.62 +	}
    1.63 +
    1.64 +CTestWsGraphicsContext::~CTestWsGraphicsContext()
    1.65 +	{
    1.66 +	delete iContext;
    1.67 +	}
    1.68 +
    1.69 +TAny* CTestWsGraphicsContext::ResolveObjectInterface(TUint aTypeId)
    1.70 +	{
    1.71 +	switch(aTypeId)
    1.72 +		{
    1.73 +	case MWsDrawableSourceProvider::EWsObjectInterfaceId:
    1.74 +		return static_cast<MWsDrawableSourceProvider*>(this);
    1.75 +		}
    1.76 +	return NULL;
    1.77 +
    1.78 +	}
    1.79 +	
    1.80 +TInt CTestWsGraphicsContext::CreateDrawableSource(const TSgDrawableId& aDrawableId, TAny*& aSource)
    1.81 +	{
    1.82 +	TRAPD(err, DoCreateDrawableSourceL(aDrawableId, aSource));
    1.83 +	return err;
    1.84 +	}
    1.85 +
    1.86 +void CTestWsGraphicsContext::DoCreateDrawableSourceL(const TSgDrawableId& aDrawableId, TAny*& aSource)
    1.87 +	{
    1.88 +	CDirectGdiDriver* driver = CDirectGdiDriver::Static();
    1.89 +	if (!driver)
    1.90 +		{
    1.91 +		User::Leave(KErrNotReady);
    1.92 +		}
    1.93 +	RDirectGdiDrawableSource* drawableSource = new(ELeave) RDirectGdiDrawableSource(*driver);
    1.94 +	CleanupStack::PushL(drawableSource);
    1.95 +	RSgDrawable drawable;
    1.96 +	User::LeaveIfError(drawable.Open(aDrawableId, ESgDoNotRestrictUsage));
    1.97 +	CleanupClosePushL(drawable);
    1.98 +	User::LeaveIfError(drawableSource->Create(drawable));
    1.99 +	CleanupStack::PopAndDestroy();
   1.100 +	CleanupStack::Pop(drawableSource);
   1.101 +	aSource = drawableSource;
   1.102 +	}
   1.103 +
   1.104 +void CTestWsGraphicsContext::CloseDrawableSource(TAny* aSource)
   1.105 +	{
   1.106 +	RDirectGdiDrawableSource* drawableSource = static_cast<RDirectGdiDrawableSource*>(aSource);
   1.107 +	drawableSource->Close();
   1.108 +	delete drawableSource;
   1.109 +	}
   1.110 +
   1.111 +void CTestWsGraphicsContext::DrawResource(const TAny* aSource, const TPoint& aPos, CWindowGc::TGraphicsRotation aRotation)
   1.112 +	{
   1.113 +	const RDirectGdiDrawableSource* drawableSource = static_cast<const RDirectGdiDrawableSource*>(aSource);
   1.114 +	iContext->DrawResource(aPos, *drawableSource, (DirectGdi::TGraphicsRotation)aRotation);
   1.115 +	iPos = aPos;
   1.116 +	iRotation = (DirectGdi::TGraphicsRotation)aRotation;
   1.117 +	}
   1.118 +
   1.119 +void CTestWsGraphicsContext::DrawResource(const TAny* aSource, const TRect& aRect, CWindowGc::TGraphicsRotation aRotation)
   1.120 +	{
   1.121 +	const RDirectGdiDrawableSource* drawableSource = static_cast<const RDirectGdiDrawableSource*>(aSource);
   1.122 +	iContext->DrawResource(aRect, *drawableSource, (DirectGdi::TGraphicsRotation)aRotation);
   1.123 +	iDestRect = aRect;
   1.124 +	iRotation = (DirectGdi::TGraphicsRotation)aRotation;
   1.125 +	}
   1.126 +
   1.127 +void CTestWsGraphicsContext::DrawResource(const TAny* aSource, const TRect& aRectDest, const TRect& aRectSrc, CWindowGc::TGraphicsRotation aRotation)
   1.128 +	{
   1.129 +	const RDirectGdiDrawableSource* drawableSource = static_cast<const RDirectGdiDrawableSource*>(aSource);
   1.130 +	iContext->DrawResource(aRectDest, *drawableSource, aRectSrc, (DirectGdi::TGraphicsRotation)aRotation);
   1.131 +	iDestRect = aRectDest;
   1.132 +	iSrcRect = aRectSrc;
   1.133 +	iRotation = (DirectGdi::TGraphicsRotation)aRotation;
   1.134 +	}
   1.135 +
   1.136 +void CTestWsGraphicsContext::DrawResource(const TAny* aSource, const TRect& aRect, const TDesC8& aParam)
   1.137 +	{
   1.138 +	const RDirectGdiDrawableSource* drawableSource = static_cast<const RDirectGdiDrawableSource*>(aSource);
   1.139 +	iContext->DrawResource(aRect, *drawableSource, aParam);
   1.140 +	iDestRect = aRect;
   1.141 +	}
   1.142 +
   1.143 +
   1.144 +void CTestWsGraphicsContext::Clear()
   1.145 +	{
   1.146 +	iContext->Clear();
   1.147 +	}
   1.148 +
   1.149 +//
   1.150 +// class CTDrawResource
   1.151 +//
   1.152 +
   1.153 +CTDrawResource::CTDrawResource(CTestStep* aStep)
   1.154 +	: CTWsGraphicsBase(aStep)
   1.155 +	{
   1.156 +	}
   1.157 +
   1.158 +CTDrawResource::~CTDrawResource()
   1.159 +	{
   1.160 +	iWindow.Close();
   1.161 +	delete iRefBitmap;
   1.162 +	delete iRotatedRefBitmap;
   1.163 +	delete iScaledBitmap;
   1.164 +	delete iScaledCroppedBitmap;
   1.165 +	delete iCopyBitmap;
   1.166 +	delete iBitmapWrongScreenNumber;
   1.167 +
   1.168 +	delete iWsGrapicResolver;
   1.169 +	delete iGraphicsCon;
   1.170 +
   1.171 +	iWsDrawableSource.Close();
   1.172 +	iImage.Close();
   1.173 +	iImageTarget.Close();
   1.174 +	iImageCollection.Close();
   1.175 +
   1.176 +	CDirectGdiDriver* dGdiDriver = CDirectGdiDriver::Static();
   1.177 +	if(dGdiDriver)
   1.178 +		{
   1.179 +		dGdiDriver->Close();
   1.180 +		}
   1.181 +	SgDriver::Close();
   1.182 +	}
   1.183 +
   1.184 +void CTDrawResource::ConstructL()
   1.185 +	{
   1.186 +	//Constrcut and setup window to be drawn to
   1.187 +	iWindow = RWindow(TheClient->iWs);
   1.188 +    User::LeaveIfError(iWindow.Construct(*TheClient->iGroup->GroupWin(),ENullWsHandle));
   1.189 +    TSize iWinSize=TSize(TheClient->iScreen->SizeInPixels());
   1.190 +    iWindow.SetExtent(TPoint(0,0),iWinSize);
   1.191 +	iWindow.Activate();
   1.192 +	iWindow.BeginRedraw();
   1.193 +	iWindow.EndRedraw();
   1.194 +	
   1.195 +	//Creates all reference and copy bitmaps required for all tests
   1.196 +	CreateReferenceAndCopyBitmapsL();
   1.197 +
   1.198 +	TInt err = CDirectGdiDriver::Open();
   1.199 +	User::LeaveIfError(err);
   1.200 +	err = SgDriver::Open();
   1.201 +	User::LeaveIfError(err);
   1.202 +	
   1.203 +	//create image target
   1.204 +	CDirectGdiDriver* theDGdiDriver = CDirectGdiDriver::Static();
   1.205 +	if(!theDGdiDriver)
   1.206 +		{
   1.207 +		User::Leave(KErrNotReady);
   1.208 +		}
   1.209 +	TSgImageInfo info;
   1.210 +	info.iUsage = ESgUsageDirectGdiTarget | ESgUsageDirectGdiSource | ESgUsageCompositionSource;
   1.211 +	info.iPixelFormat = EUidPixelFormatRGB_565;
   1.212 +	info.iSizeInPixels = TSize(200, 200);
   1.213 +	info.iShareable = ETrue;
   1.214 +	const TInt KImageCount = 1;
   1.215 +	err = iImageCollection.Create(info, KImageCount);
   1.216 +	User::LeaveIfError(err);
   1.217 +	
   1.218 +	err = iImageCollection.OpenImage(0, iImage);
   1.219 +	User::LeaveIfError(err);
   1.220 +	iImageTarget = RDirectGdiImageTarget(*theDGdiDriver);
   1.221 +	err = iImageTarget.Create(iImage);
   1.222 +	User::LeaveIfError(err);
   1.223 +	
   1.224 +	// construction of image source
   1.225 +	RSgImage sgImage;
   1.226 +	CreateSgImageFromBitmapL(sgImage);
   1.227 +	CleanupClosePushL(sgImage);
   1.228 +	iWsDrawableSource = RWsDrawableSource(TheClient->iWs);
   1.229 +	User::LeaveIfError(iWsDrawableSource.Create(sgImage, TheClient->iScreen->GetScreenNumber()));
   1.230 +	
   1.231 +    //Create dummy MWsGraphicResolver - required RemoteGc testing
   1.232 +	iWsGrapicResolver = new (ELeave) CWSGraphicsRes();
   1.233 +	
   1.234 +	//Create dummy MWsGraphicsContext - required RemoteGc testing
   1.235 +	iGraphicsCon =  CTestWsGraphicsContext::NewL(iImageTarget);
   1.236 +	
   1.237 +	CleanupStack::PopAndDestroy(&sgImage);
   1.238 +	}
   1.239 +
   1.240 +void CTDrawResource::RunTestCaseL(TInt aCurTestCase)
   1.241 +	{	
   1.242 +	((CTDrawResourceStep*)iStep)->SetTestStepID(KUnknownSYMTestCaseIDName);
   1.243 +	switch(aCurTestCase)
   1.244 +		{
   1.245 +	case 1:		
   1.246 +		((CTDrawResourceStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-DRAWRESOURCE-0001"));
   1.247 +		INFO_PRINTF1(_L("DrawResourcePos Test"));		
   1.248 +		TestDrawResourcePos();
   1.249 +		break;
   1.250 +	case 2:
   1.251 +		((CTDrawResourceStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-DRAWRESOURCE-0002"));
   1.252 +		INFO_PRINTF1(_L("DrawResourceRect Test"));	
   1.253 +		TestDrawResourceRect();
   1.254 +		break;
   1.255 +	case 3:
   1.256 +		((CTDrawResourceStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-DRAWRESOURCE-0003"));
   1.257 +		INFO_PRINTF1(_L("DrawResourceScale Test"));		
   1.258 +		TestDrawResourceScale();
   1.259 +		break;
   1.260 +	case 4:
   1.261 +		((CTDrawResourceStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-DRAWRESOURCE-0004"));
   1.262 +		INFO_PRINTF1(_L("RWsDrawableSource Reference Counting Test"));		
   1.263 +		TestRWsDrawableSourceReferenceCountingL();
   1.264 +		break;	
   1.265 +	case 5:
   1.266 +		((CTDrawResourceStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-DRAWRESOURCE-0005"));
   1.267 +		INFO_PRINTF1(_L("RemoteGcDrawResourcePos Test"));	
   1.268 +		TestRemoteGcDrawResourcePosL();
   1.269 +		break;
   1.270 +	case 6:
   1.271 +		((CTDrawResourceStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-DRAWRESOURCE-0006"));
   1.272 +		INFO_PRINTF1(_L("RemoteGcDrawResourceRect Test"));	
   1.273 +		TestRemoteGcDrawResourceRectL();
   1.274 +		break;
   1.275 +	case 7:
   1.276 +		((CTDrawResourceStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-DRAWRESOURCE-0007"));
   1.277 +		INFO_PRINTF1(_L("RemoteGcDrawResourceScale Test"));	
   1.278 +		TestRemoteGcDrawResourceScaleL();
   1.279 +		break;
   1.280 +	case 8:
   1.281 +		((CTDrawResourceStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-DRAWRESOURCE-0008"));
   1.282 +		INFO_PRINTF1(_L("DrawResourceScreens Test"));	
   1.283 +		TestDrawResourceScreensL();
   1.284 +		break;
   1.285 +	case 9:
   1.286 +		((CTDrawResourceStep*)iStep)->SetTestStepID(_L("GRAPHICS-WSERV-TestCopyScreenToBitmapWithDifferentDisplayModes-0001"));
   1.287 +		INFO_PRINTF1(_L("CopyScreenToBitmapWithDifferentDisplayModes Test\n"));
   1.288 +		TestCopyScreenToBitmapWithDifferentDisplayModesL();
   1.289 +		break;
   1.290 +	case 10:
   1.291 +		((CTDrawResourceStep*)iStep)->SetTestStepID(KNotATestSYMTestCaseIDName);
   1.292 +		((CTDrawResourceStep*)iStep)->CloseTMSGraphicsStep();
   1.293 +		INFO_PRINTF1(_L("Test complete\n"));
   1.294 +		TestComplete();
   1.295 +		break;
   1.296 +		}
   1.297 +	((CTDrawResourceStep*)iStep)->RecordTestResultL();
   1.298 +	}
   1.299 +
   1.300 +/**
   1.301 +@SYMTestCaseID           GRAPHICS-WSERV-DRAWRESOURCE-0001
   1.302 +@SYMPREQ                 PREQ2095
   1.303 +@SYMTestPriority         High
   1.304 +@SYMTestCaseDesc         Draw RSgImage using DrawResource(const TPoint&, const RWsDrawableSource&, TGraphicsRotation)
   1.305 +@SYMTestActions          Draw to position (0,0) with default rotation (none)
   1.306 +						 Draw to position (10,10) with 90 degrees rotation 
   1.307 +@SYMTestExpectedResults  Drawn images should match reference CFbsBitmap
   1.308 +*/
   1.309 +void CTDrawResource::TestDrawResourcePos()
   1.310 +	{
   1.311 +	// Draw to TPoint(0,0) with EGraphicsRotationNone
   1.312 +	iWindow.BeginRedraw();
   1.313 +	TheGc->Activate(iWindow);
   1.314 +	TheGc->Clear();
   1.315 +	MWsDrawResource* dr = static_cast<MWsDrawResource*>(TheGc->Interface(KMWsDrawResourceInterfaceUid));
   1.316 +	TEST(dr != NULL);
   1.317 +	dr->DrawResource(KDestPoint, iWsDrawableSource, CWindowGc::EGraphicsRotationNone);
   1.318 +	TheGc->Deactivate();
   1.319 +	iWindow.EndRedraw();
   1.320 +	TheClient->iWs.Finish();  
   1.321 +	TheClient->WaitForRedrawsToFinish();
   1.322 +
   1.323 +	//Copy the screen to the copy bitmap
   1.324 +	TheClient->iScreen->CopyScreenToBitmap(iCopyBitmap, KCopyTestRect);
   1.325 +
   1.326 +	//Compare the bitmaps
   1.327 +	INFO_PRINTF1(_L("Draw to TPoint(0,0) with EGraphicsRotationNone"));
   1.328 +	TBool compRes = CompareBitmapsByPixel(iCopyBitmap, iRefBitmap);
   1.329 +	TEST(compRes);
   1.330 +
   1.331 +	/*** Draw to position (10,10) with 90 degrees rotation ***/
   1.332 +	TPoint const KDestPoint2(10,10);
   1.333 +	iWindow.BeginRedraw();
   1.334 +	TheGc->Activate(iWindow);
   1.335 +    TheGc->Clear();
   1.336 +	dr->DrawResource(KDestPoint2, iWsDrawableSource, KTestRotation);
   1.337 +    TheGc->Deactivate();
   1.338 +	iWindow.EndRedraw();
   1.339 +	TheClient->iWs.Finish(); 
   1.340 +	TheClient->WaitForRedrawsToFinish();
   1.341 +
   1.342 +	//Copy the screen to the copy bitmap
   1.343 +	TheClient->iScreen->CopyScreenToBitmap(iCopyBitmap, TRect(KDestPoint2, KSourceSize));
   1.344 +
   1.345 +	//Compare the bitmaps
   1.346 +	INFO_PRINTF1(_L("Draw to position (10,10) with 90 degrees rotation"));
   1.347 +	compRes = CompareBitmapsByPixel(iCopyBitmap, iRotatedRefBitmap);
   1.348 +	TEST(compRes);
   1.349 +	}
   1.350 +
   1.351 +/**
   1.352 +@SYMTestCaseID           GRAPHICS-WSERV-DRAWRESOURCE-0002
   1.353 +@SYMPREQ                 PREQ2095
   1.354 +@SYMTestPriority         High
   1.355 +@SYMTestCaseDesc         Draw RSgImage using DrawResource(const TRect& , const RWsDrawableSource&, TGraphicsRotation aRotation)
   1.356 +@SYMTestActions          Draw to rect pos (10,10), rect size (60,60) with 90 degrees rotation
   1.357 +@SYMTestExpectedResults  Drawn images should match the reference CFbsBitmap
   1.358 +*/
   1.359 +void CTDrawResource::TestDrawResourceRect()
   1.360 +	{
   1.361 +	//Use DrawResource
   1.362 +	iWindow.BeginRedraw();
   1.363 +	TheGc->Activate(iWindow);
   1.364 +	TheGc->Clear();
   1.365 +	MWsDrawResource* dr = static_cast<MWsDrawResource*>(TheGc->Interface(KMWsDrawResourceInterfaceUid));
   1.366 +	TEST(dr != NULL);
   1.367 +	dr->DrawResource(KDestRect, iWsDrawableSource, KTestRotation);
   1.368 +	TheGc->Deactivate();
   1.369 +	iWindow.EndRedraw();
   1.370 +	TheClient->iWs.Finish();  
   1.371 +	TheClient->WaitForRedrawsToFinish();
   1.372 +
   1.373 +	//Copy the screen to the copy bitmap
   1.374 +	TheClient->iScreen->CopyScreenToBitmap(iCopyBitmap, KCopyTestRect);
   1.375 +
   1.376 +	//Compare the bitmaps
   1.377 +	INFO_PRINTF1(_L("Draw to rect pos (10,10), rect size (60,60) with 90 degrees rotation"));
   1.378 +	TInt compRes = CompareBitmapsByPixel(iCopyBitmap, iScaledBitmap);
   1.379 +	TEST(compRes);
   1.380 +	}
   1.381 +
   1.382 +/**
   1.383 +@SYMTestCaseID           GRAPHICS-WSERV-DRAWRESOURCE-0003
   1.384 +@SYMPREQ                 PREQ2095
   1.385 +@SYMTestPriority         High
   1.386 +@SYMTestCaseDesc         Draw RSgImage using DrawResource(const TRect& , const RWsDrawableSource&, const TRect&, TGraphicsRotation aRotation)
   1.387 +@SYMTestActions          Draw the part of the source image (rect Pos (0,0), rect size(50,50))
   1.388 +						 to rect pos(10,10), rect size(60,60) and and 90 degrees rotation
   1.389 +@SYMTestExpectedResults  Drawn images should match the reference CFbsBitmap
   1.390 +*/
   1.391 +void CTDrawResource::TestDrawResourceScale()
   1.392 +	{
   1.393 +	//Use DrawResource
   1.394 +	iWindow.BeginRedraw();
   1.395 +	TheGc->Activate(iWindow);
   1.396 +	TheGc->Clear();
   1.397 +	MWsDrawResource* dr = static_cast<MWsDrawResource*>(TheGc->Interface(KMWsDrawResourceInterfaceUid));
   1.398 +	TEST(dr != NULL);
   1.399 +	dr->DrawResource(KDestRect, iWsDrawableSource, KSourceRect, KTestRotation);
   1.400 +	TheGc->Deactivate();
   1.401 +	iWindow.EndRedraw();
   1.402 +	TheClient->iWs.Finish();  
   1.403 +	TheClient->WaitForRedrawsToFinish();
   1.404 +
   1.405 +	//Copy the screen to the copy bitmap
   1.406 +	TheClient->iScreen->CopyScreenToBitmap(iCopyBitmap, KCopyTestRect);
   1.407 +
   1.408 +	//Compare the bitmaps
   1.409 +	INFO_PRINTF1(_L("Draw the part of the source image to rect pos(10,10), rect size(60,60) and and 90 degrees rotation"));
   1.410 +	TInt compRes = CompareBitmapsByPixel(iCopyBitmap, iScaledCroppedBitmap);
   1.411 +	TEST(compRes);
   1.412 +	}
   1.413 +
   1.414 +/**
   1.415 +@SYMTestCaseID           GRAPHICS-WSERV-DRAWRESOURCE-0004
   1.416 +@SYMPREQ                 PREQ2095
   1.417 +@SYMTestPriority         High
   1.418 +@SYMTestCaseDesc         Draw RSgImage using DrawResource(const TPoint&, const RWsDrawableSource&, TGraphicsRotation) after closing the image source
   1.419 +@SYMTestActions          Draw to position (0,0) with default rotation (none) after closing the image source
   1.420 +@SYMTestExpectedResults  Drawn image should match reference CFbsBitmap
   1.421 +*/
   1.422 +void CTDrawResource::TestRWsDrawableSourceReferenceCountingL()
   1.423 +	{	
   1.424 +	// construction of image source
   1.425 +	RSgImage sgImage;
   1.426 +	CreateSgImageFromBitmapL(sgImage);
   1.427 +	CleanupClosePushL(sgImage);
   1.428 +	RWsDrawableSource drawableSource(TheClient->iWs);
   1.429 +	CleanupClosePushL(drawableSource);
   1.430 +	User::LeaveIfError(drawableSource.Create(sgImage, TheClient->iScreen->GetScreenNumber())); 
   1.431 +
   1.432 +	//Draw using DrawResource
   1.433 +	iWindow.BeginRedraw();
   1.434 +	TheGc->Activate(iWindow);
   1.435 +	TheGc->Clear();
   1.436 +	MWsDrawResource* dr = static_cast<MWsDrawResource*>(TheGc->Interface(KMWsDrawResourceInterfaceUid));
   1.437 +	TEST(dr != NULL);
   1.438 +	dr->DrawResource(KDestPoint, drawableSource, CWindowGc::EGraphicsRotationNone);
   1.439 +	TheGc->Deactivate();
   1.440 +	iWindow.EndRedraw();
   1.441 +
   1.442 +	//Close the image source but this should not stop the source from being drawn 
   1.443 +	drawableSource.Close();
   1.444 +	TheClient->iWs.Finish();
   1.445 +	TheClient->WaitForRedrawsToFinish();
   1.446 +
   1.447 +	//Copy the screen to the copy bitmap
   1.448 +	TheClient->iScreen->CopyScreenToBitmap(iCopyBitmap, KCopyTestRect);
   1.449 +
   1.450 +	//Compare the bitmaps
   1.451 +	INFO_PRINTF1(_L("Draw to TPoint(0,0) with EGraphicsRotationNone"));
   1.452 +	TBool compRes = CompareBitmapsByPixel(iCopyBitmap, iRefBitmap);
   1.453 +	TEST(compRes);
   1.454 +
   1.455 +	CleanupStack::PopAndDestroy(2, &sgImage);
   1.456 +	}
   1.457 +
   1.458 +/**
   1.459 +@SYMTestCaseID           GRAPHICS-WSERV-DRAWRESOURCE-0005
   1.460 +@SYMPREQ                 PREQ2095
   1.461 +@SYMTestPriority         High
   1.462 +@SYMTestCaseDesc         Draw RSgImage using RemotGc->DrawResource(const TPoint&, const RWsDrawableSource&, TGraphicsRotation)
   1.463 +@SYMTestActions          Record the draw resource commands using CRemoteGc and play the recorded commands on a window using
   1.464 + 						 Play(const TPoint&, const TRect&, RWsSession&, CWindowGc&) and then play the recorded commands using . 
   1.465 +						 Play(const TPoint&, const TRect&, const MWsGraphicResolver&, MWsGraphicsContext&).
   1.466 +@SYMTestExpectedResults  Drawn images should match reference CFbsBitmap and also values received by MWsGraphicsContext should 
   1.467 + 						 match what was originally sent to DrawResource.
   1.468 +*/
   1.469 +void CTDrawResource::TestRemoteGcDrawResourcePosL()
   1.470 +	{
   1.471 +	const TRect KRemotGcSourceRect(0, 0, iWindow.Size().iWidth, iWindow.Size().iHeight);
   1.472 +	const TRegionFix<1> KClippingRegion(KRemotGcSourceRect);
   1.473 +	CWindowGc::TGraphicsRotation testRotation= CWindowGc::EGraphicsRotationNone;
   1.474 +	
   1.475 +	//Create remote gc - required RemoteGc testing
   1.476 +	CRemoteGc* remoteGc = CRemoteGc::NewL(TheClient->iScreen);
   1.477 +	CleanupStack::PushL(remoteGc);
   1.478 +
   1.479 +	//Record draw messages
   1.480 +	remoteGc->ResetCommandBuffer();
   1.481 +	remoteGc->BeginDraw(KRemotGcSourceRect);
   1.482 +	MWsDrawResource* dr = static_cast<MWsDrawResource*>(remoteGc->Interface(KMWsDrawResourceInterfaceUid));
   1.483 +	TEST(dr != NULL);
   1.484 +	dr->DrawResource(KDestPoint, iWsDrawableSource, CWindowGc::EGraphicsRotationNone);
   1.485 +	remoteGc->EndDraw();
   1.486 +	
   1.487 +	RWsGraphicMsgBuf msgBuf;
   1.488 +	CleanupClosePushL(msgBuf);
   1.489 +	//Externalize the captured commands from remote gc in to a buffer
   1.490 +	remoteGc->ExternalizeL(msgBuf, ETrue);
   1.491 +	//Create command buffer - required RemoteGc testing
   1.492 +	CCommandBuffer* cmdBuffer = CCommandBuffer::NewL();
   1.493 +	CleanupStack::PushL(cmdBuffer);
   1.494 +	//Internalize the buffer with captured commands (from CRemoteGC) in to CCommandBuffer
   1.495 +	cmdBuffer->InternalizeL(msgBuf.Pckg());
   1.496 +
   1.497 +	// Play stored commands using Play(const TPoint&, const TRect&, RWsSession&, CWindowGc&) 
   1.498 +	remoteGc->ResetCommandBuffer();
   1.499 +	iWindow.Invalidate();
   1.500 +	iWindow.BeginRedraw();
   1.501 +	TheGc->Activate(iWindow);
   1.502 +	TheGc->Clear();
   1.503 +	cmdBuffer->Play(KPlayOffset, &KClippingRegion, KRemotGcSourceRect, TheClient->iWs, *TheGc);
   1.504 +	TheGc->Deactivate();
   1.505 +	iWindow.EndRedraw();
   1.506 +	TheClient->iWs.Finish();
   1.507 +	TheClient->WaitForRedrawsToFinish();
   1.508 +
   1.509 +	//Copy the screen to the copy bitmap
   1.510 +	TheClient->iScreen->CopyScreenToBitmap(iCopyBitmap, KCopyTestRect);
   1.511 +
   1.512 +	//Compare the bitmaps
   1.513 +	INFO_PRINTF1(_L("Using Play(const TPoint&, const TRect&, RWsSession&, CWindowGc&)"));
   1.514 +	TBool compRes = CompareBitmapsByPixel(iCopyBitmap, iRefBitmap);
   1.515 +	TEST(compRes);
   1.516 +
   1.517 +	// Play stored commands using Play(const TPoint&, const TRect&, const MWsGraphicResolver&, MWsGraphicsContext&) 
   1.518 +	remoteGc->ResetCommandBuffer();
   1.519 +	iWindow.Invalidate();
   1.520 +	iWindow.BeginRedraw();
   1.521 +	TheGc->Activate(iWindow);
   1.522 +	TheGc->Clear();
   1.523 +	cmdBuffer->Play(KPlayOffset,&KClippingRegion,KRemotGcSourceRect,*iWsGrapicResolver,*iGraphicsCon);
   1.524 +	TheGc->Deactivate();
   1.525 +	iWindow.EndRedraw();
   1.526 +	TheClient->iWs.Finish();
   1.527 +
   1.528 +	//Compare the values received by CTestWsGraphicsContext and the values sent to it
   1.529 +	INFO_PRINTF1(_L("Using Play(const TPoint&, const TRect&, const MWsGraphicResolver&, MWsGraphicsContext&)"));
   1.530 +	TBool valuesSame = EFalse;
   1.531 +	CFbsBitmap* bmp;
   1.532 +	BitmapLC(bmp);
   1.533 +	compRes = CompareBitmapsByPixel(bmp, iRefBitmap);
   1.534 +	CleanupStack::PopAndDestroy(bmp);
   1.535 +
   1.536 +	if((iGraphicsCon->iPos == KDestPoint) && (compRes)
   1.537 +									&& (reinterpret_cast<TInt&>(iGraphicsCon->iRotation)==reinterpret_cast<TInt&>(testRotation)))
   1.538 +		valuesSame = ETrue;
   1.539 +	TEST(valuesSame);
   1.540 +	CleanupStack::PopAndDestroy(3, remoteGc);
   1.541 +	}
   1.542 +
   1.543 +/**
   1.544 +@SYMTestCaseID           GRAPHICS-WSERV-DRAWRESOURCE-0006
   1.545 +@SYMPREQ                 PREQ2095
   1.546 +@SYMTestPriority         High
   1.547 +@SYMTestCaseDesc         Draw RSgImage using RemotGc->DrawResource(const TRect&, const RWsDrawableSource&, TGraphicsRotation)
   1.548 +@SYMTestActions          Record the draw resource commands using CRemoteGc and play the recorded commands on a window using
   1.549 + 						 Play(const TPoint&, const TRect&, RWsSession&, CWindowGc&) and then play the recorded commands using . 
   1.550 +						 Play(const TPoint&, const TRect&, const MWsGraphicResolver&, MWsGraphicsContext&).
   1.551 +@SYMTestExpectedResults  Drawn images should match reference CFbsBitmap and also values received by MWsGraphicsContext should 
   1.552 + 						 match what was originally sent to DrawResource.
   1.553 +*/
   1.554 +void CTDrawResource::TestRemoteGcDrawResourceRectL()
   1.555 +	{
   1.556 +	const TRect KRemotGcSourceRect(0, 0, iWindow.Size().iWidth, iWindow.Size().iHeight);
   1.557 +	const TRegionFix<1> KClippingRegion(KRemotGcSourceRect);
   1.558 +	
   1.559 +	//Create remote gc - required RemoteGc testing
   1.560 +	CRemoteGc* remoteGc = CRemoteGc::NewL(TheClient->iScreen);
   1.561 +	CleanupStack::PushL(remoteGc);
   1.562 +
   1.563 +	//Record draw messages
   1.564 +	remoteGc->BeginDraw(KRemotGcSourceRect);
   1.565 +	MWsDrawResource* dr = static_cast<MWsDrawResource*>(remoteGc->Interface(KMWsDrawResourceInterfaceUid));
   1.566 +	TEST(dr != NULL);
   1.567 +	dr->DrawResource(KDestRect, iWsDrawableSource, KTestRotation);
   1.568 +	remoteGc->EndDraw();
   1.569 +	
   1.570 +	RWsGraphicMsgBuf msgBuf;
   1.571 +	CleanupClosePushL(msgBuf);
   1.572 +	//Externalize the captured commands from remote gc in to a buffer
   1.573 +	remoteGc->ExternalizeL(msgBuf, ETrue);
   1.574 +
   1.575 +	//Create command buffer - required RemoteGc testing
   1.576 +	CCommandBuffer* cmdBuffer = CCommandBuffer::NewL();
   1.577 +	CleanupStack::PushL(cmdBuffer);
   1.578 +	//Internalize the buffer with captured commands (from CRemoteGC) in to CCommandBuffer
   1.579 +	cmdBuffer->InternalizeL(msgBuf.Pckg());
   1.580 +
   1.581 +	// Play stored commands using Play(const TRect&, const TRect&, RWsSession&, CWindowGc&)
   1.582 +	iWindow.Invalidate();
   1.583 +	iWindow.BeginRedraw();
   1.584 +	TheGc->Activate(iWindow);
   1.585 +	TheGc->Clear();
   1.586 +	cmdBuffer->Play(KPlayOffset, &KClippingRegion, KRemotGcSourceRect, TheClient->iWs, *TheGc);
   1.587 +	TheGc->Deactivate();
   1.588 +	iWindow.EndRedraw();
   1.589 +	TheClient->iWs.Finish();
   1.590 +	TheClient->WaitForRedrawsToFinish();
   1.591 +
   1.592 +	//Copy the screen to the copy bitmap
   1.593 +	TheClient->iScreen->CopyScreenToBitmap(iCopyBitmap, KCopyTestRect);
   1.594 +
   1.595 +	//Compare the bitmaps
   1.596 +	INFO_PRINTF1(_L("Using Play(const TPoint&, const TRect&, RWsSession&, CWindowGc&)"));
   1.597 +	TBool compRes = CompareBitmapsByPixel(iCopyBitmap, iScaledBitmap);
   1.598 +	TEST(compRes);
   1.599 +
   1.600 +	// Play stored commands using Play(const TPoint&, const TRect&, const MWsGraphicResolver&, MWsGraphicsContext&) 
   1.601 +	iWindow.Invalidate();
   1.602 +	iWindow.BeginRedraw();
   1.603 +	TheGc->Activate(iWindow);
   1.604 +	TheGc->Clear();
   1.605 +	iGraphicsCon->Clear();
   1.606 +	cmdBuffer->Play(KPlayOffset,&KClippingRegion,KRemotGcSourceRect,*iWsGrapicResolver,*iGraphicsCon);
   1.607 +	TheGc->Deactivate();
   1.608 +	iWindow.EndRedraw();
   1.609 +	TheClient->iWs.Finish();
   1.610 +	TheClient->WaitForRedrawsToFinish();
   1.611 +
   1.612 +	//Compare the values received by CTestWsGraphicsContext and the values sent to it
   1.613 +	INFO_PRINTF1(_L("Using Play(const TPoint&, const TRect&, const MWsGraphicResolver&, MWsGraphicsContext&)"));
   1.614 +	TBool valuesSame = EFalse;
   1.615 +
   1.616 +	CFbsBitmap* bmp;
   1.617 +	BitmapLC(bmp);
   1.618 +	compRes = CompareBitmapsByPixel(bmp, iScaledBitmap);
   1.619 +	CleanupStack::PopAndDestroy(bmp);
   1.620 +
   1.621 +	if((iGraphicsCon->iDestRect == KDestRect) && (compRes)
   1.622 +								&& (reinterpret_cast<TInt&>(iGraphicsCon->iRotation)==reinterpret_cast<const TInt&>(KTestRotation)))
   1.623 +		valuesSame = ETrue;
   1.624 +	TEST(valuesSame);
   1.625 +	CleanupStack::PopAndDestroy(3, remoteGc);
   1.626 +	}
   1.627 +
   1.628 +/**
   1.629 +@SYMTestCaseID           GRAPHICS-WSERV-DRAWRESOURCE-0007
   1.630 +@SYMPREQ                 PREQ2095
   1.631 +@SYMTestPriority         High
   1.632 +@SYMTestCaseDesc         Draw RSgImage using RemotGc->DrawResource(const TRect&, const RWsDrawableSource&, const TRect&, TGraphicsRotation)
   1.633 +@SYMTestActions          Record the draw resource commands using CRemoteGc and play the recorded commands on a window using
   1.634 + 						 Play(const TPoint&, const TRect&, RWsSession&, CWindowGc&) and then play the recorded commands using . 
   1.635 +						 Play(const TPoint&, const TRect&, const MWsGraphicResolver&, MWsGraphicsContext&).
   1.636 +@SYMTestExpectedResults  Drawn images should match reference CFbsBitmap and also values received by MWsGraphicsContext should 
   1.637 + 						 match what was originally sent to DrawResource.
   1.638 +*/
   1.639 +void CTDrawResource::TestRemoteGcDrawResourceScaleL()
   1.640 +	{
   1.641 +	const TRect KRemotGcSourceRect(0, 0, iWindow.Size().iWidth, iWindow.Size().iHeight);
   1.642 +	const TRegionFix<1> KClippingRegion(KRemotGcSourceRect);
   1.643 +	
   1.644 +	//Create remote gc - required RemoteGc testing
   1.645 +	CRemoteGc* remoteGc = CRemoteGc::NewL(TheClient->iScreen);
   1.646 +	CleanupStack::PushL(remoteGc);
   1.647 +
   1.648 +	//Record draw messages
   1.649 +	remoteGc->BeginDraw(KRemotGcSourceRect);
   1.650 +	MWsDrawResource* dr = static_cast<MWsDrawResource*>(remoteGc->Interface(KMWsDrawResourceInterfaceUid));
   1.651 +	TEST(dr != NULL);
   1.652 +	dr->DrawResource(KDestRect, iWsDrawableSource, KSourceRect, KTestRotation);
   1.653 +	remoteGc->EndDraw();
   1.654 +	
   1.655 +	RWsGraphicMsgBuf msgBuf;
   1.656 +	CleanupClosePushL(msgBuf);
   1.657 +	//Externalize the captured commands from remote gc in to a buffer
   1.658 +	remoteGc->ExternalizeL(msgBuf, ETrue);
   1.659 +
   1.660 +	//Create command buffer - required RemoteGc testing
   1.661 +	CCommandBuffer* cmdBuffer = CCommandBuffer::NewL();
   1.662 +	CleanupStack::PushL(cmdBuffer);
   1.663 +	//Internalize the buffer with captured commands (from CRemoteGC) in to CCommandBuffer
   1.664 +	cmdBuffer->InternalizeL(msgBuf.Pckg());
   1.665 +
   1.666 +	// Play the stored commands using Play(const TRect&, const TRect&, RWsSession&, CWindowGc&)
   1.667 +	remoteGc->ResetCommandBuffer();
   1.668 +	iWindow.Invalidate();
   1.669 +	iWindow.BeginRedraw();
   1.670 +	TheGc->Activate(iWindow);
   1.671 +	TheGc->Clear();
   1.672 +	cmdBuffer->Play(KPlayOffset, &KClippingRegion, KRemotGcSourceRect, TheClient->iWs, *TheGc);
   1.673 +	TheGc->Deactivate();
   1.674 +	iWindow.EndRedraw();
   1.675 +	TheClient->iWs.Finish();
   1.676 +	TheClient->WaitForRedrawsToFinish();
   1.677 +	//Copy the screen to the copy bitmap
   1.678 +	TheClient->iScreen->CopyScreenToBitmap(iCopyBitmap, KCopyTestRect);
   1.679 +
   1.680 +	//Compare the bitmaps
   1.681 +	INFO_PRINTF1(_L("Using Play(const TPoint&, const TRect&, RWsSession&, CWindowGc&)"));
   1.682 +	TBool compRes = CompareBitmapsByPixel(iCopyBitmap, iScaledCroppedBitmap);
   1.683 +	TEST(compRes);
   1.684 +
   1.685 +	// Play the stored commands using Play(const TPoint&, const TRect&, const MWsGraphicResolver&, MWsGraphicsContext&) 	
   1.686 +	iWindow.Invalidate();
   1.687 +	iWindow.BeginRedraw();
   1.688 +	TheGc->Activate(iWindow);
   1.689 +	TheGc->Clear();
   1.690 +	iGraphicsCon->Clear();
   1.691 +	cmdBuffer->Play(KPlayOffset,&KClippingRegion,KRemotGcSourceRect,*iWsGrapicResolver,*iGraphicsCon);
   1.692 +	TheGc->Deactivate();
   1.693 +	iWindow.EndRedraw();
   1.694 +	TheClient->iWs.Finish();
   1.695 +	TheClient->WaitForRedrawsToFinish();
   1.696 +
   1.697 +	//Compare the values received by CTestWsGraphicsContext and the values sent to it
   1.698 +	INFO_PRINTF1(_L("Using Play(const TPoint&, const TRect&, const MWsGraphicResolver&, MWsGraphicsContext&)"));
   1.699 +	TBool valuesSame = EFalse;
   1.700 +
   1.701 +	CFbsBitmap* bmp;
   1.702 +	BitmapLC(bmp);
   1.703 +	compRes = CompareBitmapsByPixel(bmp, iScaledCroppedBitmap);
   1.704 +	CleanupStack::PopAndDestroy(bmp);
   1.705 +
   1.706 +	if((iGraphicsCon->iDestRect == KDestRect) && (compRes) && (iGraphicsCon->iSrcRect == KSourceRect)
   1.707 +								&& (reinterpret_cast<TInt&>(iGraphicsCon->iRotation)==reinterpret_cast<const TInt&>(KTestRotation)))
   1.708 +		valuesSame = ETrue;
   1.709 +	TEST(valuesSame);
   1.710 +	CleanupStack::PopAndDestroy(3, remoteGc);
   1.711 +	}
   1.712 +
   1.713 +/**
   1.714 +@SYMTestCaseID          GRAPHICS-WSERV-DRAWRESOURCE-0008
   1.715 +@SYMPREQ                PREQ2095
   1.716 +@SYMTestPriority        High
   1.717 +@SYMTestCaseDesc        Negative testing. Draw graphics recourses which associated with different screens.
   1.718 +@SYMTestActions         Open RWsDrawableSource associated with the screen which doesn’ exist.  
   1.719 +						Open RWsDrawableSource associated with the screen which exists but differes from drawing target.
   1.720 +						Draw Rectangle and Resource to the screen via CWindowGc
   1.721 +						Draw Rectangle and Resource to the screen via CRemoteGc
   1.722 +@SYMTestExpectedResults  Opening drawable resource on the screen which doesn’t exist must fail with error code KErrArgument 
   1.723 +						Drawing primitives will result only rectangles be drawn as drawable recourses get associated with different screen
   1.724 +*/
   1.725 +void CTDrawResource::TestDrawResourceScreensL()
   1.726 +	{
   1.727 +	TInt numOfScreens = TheClient->iWs.NumberOfScreens();
   1.728 +	if(numOfScreens < 2)
   1.729 +		{
   1.730 +		INFO_PRINTF2(_L("This test case will be running if the number of available screens more than 1, current number is %d"), numOfScreens);
   1.731 +		return;
   1.732 +		}
   1.733 +	TInt screenNumber = TheClient->iScreen->GetScreenNumber();
   1.734 +	TInt differentScreen = (screenNumber == 0) ? 1 : 0;
   1.735 +
   1.736 +	RSgImage sgImage;
   1.737 +	CreateSgImageFromBitmapL(sgImage);
   1.738 +	CleanupClosePushL(sgImage);
   1.739 +
   1.740 +	RWsDrawableSource drawableSource(TheClient->iWs);
   1.741 +	TInt res = drawableSource.Create(sgImage, differentScreen + 200); //wrong screen number
   1.742 +	TEST(res == KErrArgument);
   1.743 +
   1.744 +	res = drawableSource.Create(iImage, differentScreen);
   1.745 +	TEST(res == KErrNotSupported); //in order to succeed the image must be created with flag usage ESgUsageWindowGcSource
   1.746 +	
   1.747 +	TSgImageInfo info; 
   1.748 +	User::LeaveIfError(sgImage.GetInfo(info));
   1.749 +
   1.750 +	res = drawableSource.Create(sgImage, differentScreen);
   1.751 +	if(res == KErrNotSupported)
   1.752 +		{
   1.753 +		INFO_PRINTF1(_L("The second screen is not supports drawable source. This test case terminates now."));
   1.754 +		CleanupStack::PopAndDestroy(&sgImage);
   1.755 +		return;
   1.756 +		}
   1.757 +	TEST(res == KErrNone);
   1.758 +	User::LeaveIfError(res);
   1.759 +	CleanupClosePushL(drawableSource);
   1.760 +	
   1.761 +	iWindow.BeginRedraw();
   1.762 +	TheGc->Activate(iWindow);
   1.763 +	TheGc->Clear();
   1.764 +	TheGc->SetBrushStyle(CFbsBitGc::ESolidBrush);
   1.765 +	TheGc->SetPenStyle(CFbsBitGc::ENullPen);
   1.766 +	TheGc->SetBrushColor(KRgbGreen);
   1.767 +	TheGc->DrawRect(TRect(KDestPoint, info.iSizeInPixels));
   1.768 +	// Draw to TPoint(0,0) with EGraphicsRotationNone but to the different screen
   1.769 +	MWsDrawResource* winDr = static_cast<MWsDrawResource*>(TheGc->Interface(KMWsDrawResourceInterfaceUid));
   1.770 +	TEST(winDr != NULL);
   1.771 +	winDr->DrawResource(KDestPoint, drawableSource, CWindowGc::EGraphicsRotationNone);
   1.772 +	TheGc->Deactivate();
   1.773 +	iWindow.EndRedraw();
   1.774 +	TheClient->iWs.Finish();  
   1.775 +	TheClient->WaitForRedrawsToFinish();
   1.776 +
   1.777 +	//Copy the screen to the copy bitmap
   1.778 +	TheClient->iScreen->CopyScreenToBitmap(iCopyBitmap, KCopyTestRect);
   1.779 +
   1.780 +	//Compare the bitmaps
   1.781 +	INFO_PRINTF1(_L("Draw to TPoint(0,0) with EGraphicsRotationNone but to different screen"));
   1.782 +	TBool compRes = CompareBitmapsByPixel(iCopyBitmap, iBitmapWrongScreenNumber);
   1.783 +	TEST(compRes);
   1.784 +
   1.785 +	//--------------------------- remoteGc 
   1.786 +	const TRect KRemotGcSourceRect(0, 0, iWindow.Size().iWidth, iWindow.Size().iHeight);
   1.787 +	const TRegionFix<1> KClippingRegion(KRemotGcSourceRect);
   1.788 +	
   1.789 +	//Create remote gc - required RemoteGc testing
   1.790 +	CRemoteGc* remoteGc = CRemoteGc::NewL(TheClient->iScreen);
   1.791 +	CleanupStack::PushL(remoteGc);
   1.792 +
   1.793 +	//Record draw messages
   1.794 +	remoteGc->BeginDraw(KRemotGcSourceRect);
   1.795 +	remoteGc->SetBrushStyle(CFbsBitGc::ESolidBrush);
   1.796 +	remoteGc->SetPenStyle(CFbsBitGc::ENullPen);
   1.797 +	remoteGc->SetBrushColor(KRgbGreen);
   1.798 +	remoteGc->DrawRect(TRect(KDestPoint, info.iSizeInPixels));
   1.799 +	MWsDrawResource* remDr = static_cast<MWsDrawResource*>(remoteGc->Interface(KMWsDrawResourceInterfaceUid));
   1.800 +	TEST(remDr != NULL);
   1.801 +	remDr->DrawResource(KDestRect, drawableSource, CWindowGc::EGraphicsRotationNone);
   1.802 +	remoteGc->EndDraw();
   1.803 +	
   1.804 +	RWsGraphicMsgBuf msgBuf;
   1.805 +	CleanupClosePushL(msgBuf);
   1.806 +	//Externalize the captured commands from remote gc in to a buffer
   1.807 +	remoteGc->ExternalizeL(msgBuf, ETrue);
   1.808 +
   1.809 +	//Create command buffer - required RemoteGc testing
   1.810 +	CCommandBuffer* cmdBuffer = CCommandBuffer::NewL();
   1.811 +	CleanupStack::PushL(cmdBuffer);
   1.812 +	//Internalize the buffer with captured commands (from CRemoteGC) in to CCommandBuffer
   1.813 +	cmdBuffer->InternalizeL(msgBuf.Pckg());
   1.814 +	
   1.815 +	// Play stored commands using Play(const TRect&, const TRect&, RWsSession&, CWindowGc&)
   1.816 +	iWindow.Invalidate();
   1.817 +	iWindow.BeginRedraw();
   1.818 +	TheGc->Activate(iWindow);
   1.819 +	TheGc->Clear();
   1.820 +	cmdBuffer->Play(KPlayOffset, &KClippingRegion, KRemotGcSourceRect, TheClient->iWs, *TheGc);
   1.821 +	TheGc->Deactivate();
   1.822 +	iWindow.EndRedraw();
   1.823 +	TheClient->iWs.Finish();
   1.824 +	TheClient->WaitForRedrawsToFinish();
   1.825 +
   1.826 +	//Copy the screen to the copy bitmap
   1.827 +	TheClient->iScreen->CopyScreenToBitmap(iCopyBitmap, KCopyTestRect);
   1.828 +
   1.829 +	INFO_PRINTF1(_L("Draw to TPoint(0,0) with EGraphicsRotationNone but to different screen"));
   1.830 +	TBool compRes1 = CompareBitmapsByPixel(iCopyBitmap, iBitmapWrongScreenNumber);
   1.831 +	TEST(compRes1);
   1.832 +
   1.833 +	CleanupStack::PopAndDestroy(5, &sgImage);
   1.834 +	}
   1.835 +
   1.836 +/**
   1.837 +@SYMTestCaseID          GRAPHICS-WSERV-TestCopyScreenToBitmapWithDifferentDisplayModes-0001
   1.838 +@SYMPREQ                PREQ2095
   1.839 +@SYMTestPriority        High
   1.840 +@SYMTestCaseDesc        Get bitmap and scanline from the screen.  
   1.841 +@SYMTestActions         Draw bitmap in various display modes to the screen. 
   1.842 +						Retrieve scan line and bitmap from the screen using standard WSERV API.  
   1.843 +
   1.844 +@SYMTestExpectedResults Checks that obtained bitmap matches with the reference bitmap.
   1.845 +*/
   1.846 +void CTDrawResource::TestCopyScreenToBitmapWithDifferentDisplayModesL()
   1.847 +	{
   1.848 +	TDisplayMode mode = TheClient->iScreen->DisplayMode();
   1.849 +    INFO_PRINTF2(_L("Screen display mode %d"), mode);
   1.850 +	CFbsBitmap* bitmap = NULL;
   1.851 +	
   1.852 +	TSize bitmapSize(163, 120);
   1.853 +	CreateBitmapLC(bitmap, bitmapSize, mode);
   1.854 +	
   1.855 +	iWindow.BeginRedraw();
   1.856 +	TheGc->Activate(iWindow);
   1.857 +	TheGc->SetBrushStyle(CWindowGc::ESolidBrush);
   1.858 +	TheGc->SetBrushColor(KRgbYellow);
   1.859 +	TheGc->Clear();
   1.860 +	const TPoint ptOffset(10, 15);
   1.861 +	TheGc->BitBlt(KDestPoint + ptOffset, bitmap);
   1.862 +
   1.863 +	TheGc->Deactivate();
   1.864 +	iWindow.EndRedraw();
   1.865 +	TheClient->iWs.Finish();
   1.866 +	TheClient->WaitForRedrawsToFinish();
   1.867 +
   1.868 +	const TInt length = bitmapSize.iWidth;
   1.869 +	const TInt height = bitmapSize.iHeight;
   1.870 +	const TInt buffersSize = length * 4;
   1.871 +	TUint8 *screenData = (TUint8*) User::AllocL(buffersSize);
   1.872 +	CleanupStack::PushL(screenData);
   1.873 +	TUint8 *bitmapData = (TUint8*) User::AllocL(buffersSize);
   1.874 +	CleanupStack::PushL(bitmapData);
   1.875 +	TPtr8 ptrScreen (screenData, buffersSize, buffersSize);
   1.876 +	TPtr8 ptrBitmap (bitmapData, buffersSize, buffersSize);
   1.877 +	
   1.878 +	//EGray mode uses dithering in BitGdi, wserv doesnt support this, thus skipping the first mode 
   1.879 +	for(TInt ii =2; ; ii++)
   1.880 +		{
   1.881 +		TDisplayMode dispMode = (TDisplayMode)ii; 
   1.882 +		if(dispMode >= EColorLast)
   1.883 +			break;
   1.884 +		if(dispMode == ERgb)
   1.885 +			continue;
   1.886 +
   1.887 +	    INFO_PRINTF2(_L("Copy Screen to bitmap, destination mode %d"), dispMode);
   1.888 +		
   1.889 +		CFbsBitmap *bmp = new (ELeave) CFbsBitmap;
   1.890 +		CleanupStack::PushL(bmp);
   1.891 +		User::LeaveIfError(bmp->Create(bitmapSize, dispMode));
   1.892 +		TUidPixelFormat pixelFormat = SgUtils::DisplayModeToPixelFormat(dispMode);
   1.893 +    	const TInt minStride = SgUtils::MinDataStride(length, pixelFormat);
   1.894 +    	const TInt bitmapStride = bmp->DataStride();
   1.895 +    	TEST(minStride <= bitmapStride);
   1.896 +	
   1.897 +	//Copy the screen to the copy bitmap
   1.898 +		TRect rc = bitmapSize;
   1.899 +		rc.Move(ptOffset);
   1.900 +		TheClient->iScreen->CopyScreenToBitmap(bmp, rc);
   1.901 +		CFbsBitmap *bmpRef = NULL;
   1.902 +		CreateReferenceBitmapLC(bmpRef, bitmap, dispMode);
   1.903 +		TEST(bmpRef->DisplayMode() == dispMode);
   1.904 +		
   1.905 +		//Compare the bitmaps
   1.906 +	    TBool compRes = CompareBitmapsByPixel(bmp, bmpRef);
   1.907 +	    TEST(compRes);
   1.908 +	    
   1.909 +	    for(TInt jj = 0; jj < height; jj++)
   1.910 +	    	{
   1.911 +	    	TPoint pt(0, jj);
   1.912 +	    	TPoint ptScreen = pt + ptOffset;
   1.913 +	    	
   1.914 +	    	Mem::Fill(screenData, bitmapStride, 0xff);
   1.915 +	    	Mem::Fill(bitmapData, bitmapStride, 0xff);
   1.916 +	    	
   1.917 +	    	TheClient->iScreen->GetScanLine(ptrScreen, ptScreen, length, dispMode);
   1.918 +	    	bitmap->GetScanLine(ptrBitmap, pt, length, dispMode);
   1.919 +	    	TInt length1 = ptrScreen.Length();
   1.920 +	    	
   1.921 +	    	TInt res = Mem::Compare(screenData, length1, bitmapData, length1);
   1.922 +	    	TEST(res == 0);
   1.923 +	    	}
   1.924 +	    CleanupStack::PopAndDestroy(2, bmp);
   1.925 +		}//screen modes;
   1.926 +		
   1.927 +	CleanupStack::PopAndDestroy(3, bitmap);
   1.928 +	}
   1.929 +
   1.930 +//Helper function: Creates reference bitmap with specified display mode
   1.931 +void CTDrawResource::CreateReferenceBitmapLC(CFbsBitmap*& aBmpTarget, CFbsBitmap* aBmpSrc, TDisplayMode aDestMode) 
   1.932 +	{
   1.933 +	TSize size = aBmpSrc->SizeInPixels();
   1.934 +	aBmpTarget = new (ELeave) CFbsBitmap;
   1.935 +	CleanupStack::PushL(aBmpTarget);
   1.936 +	User::LeaveIfError(aBmpTarget->Create(size, aDestMode));
   1.937 +    CFbsBitmapDevice *refBitmapDev = CFbsBitmapDevice::NewL(aBmpTarget);
   1.938 +    CleanupStack::PushL(refBitmapDev);
   1.939 +    CFbsBitGc *originalBitGc;
   1.940 +	User::LeaveIfError(refBitmapDev->CreateContext(originalBitGc));
   1.941 +	CleanupStack::PushL(originalBitGc);
   1.942 +	originalBitGc->BitBlt(TPoint(0,0), aBmpSrc);
   1.943 +	CleanupStack::PopAndDestroy(2, refBitmapDev);
   1.944 +	}
   1.945 +
   1.946 +//Helper function: Creates reference bitmap with specified display mode
   1.947 +void CTDrawResource::CreateBitmapLC(CFbsBitmap*& aBmpTarget, const TSize& aSize, TDisplayMode aDispMode) const
   1.948 +	{
   1.949 +	aBmpTarget = new (ELeave) CFbsBitmap;
   1.950 +	CleanupStack::PushL(aBmpTarget);
   1.951 +	User::LeaveIfError(aBmpTarget->Create(aSize, aDispMode));
   1.952 +    CFbsBitmapDevice *refBitmapDev = CFbsBitmapDevice::NewL(aBmpTarget);
   1.953 +    CleanupStack::PushL(refBitmapDev);
   1.954 +    CFbsBitGc *originalBitGc;
   1.955 +	User::LeaveIfError(refBitmapDev->CreateContext(originalBitGc));
   1.956 +	CleanupStack::PushL(originalBitGc);
   1.957 +	
   1.958 +	TRect rect = TRect(aSize); 
   1.959 +	rect.Shrink(21, 15);
   1.960 +	
   1.961 +	originalBitGc->SetBrushStyle(CFbsBitGc::ESolidBrush);
   1.962 +	originalBitGc->SetBrushColor(TRgb(0,150,150));
   1.963 +	originalBitGc->DrawRect(TRect(TPoint(0,0), TSize(aSize.iWidth, aSize.iHeight / 2)));
   1.964 +	originalBitGc->SetBrushColor(TRgb(150,100,150));
   1.965 +	originalBitGc->DrawRect(TRect(TPoint(0,aSize.iHeight / 2), TSize(aSize.iWidth, aSize.iHeight)));
   1.966 +
   1.967 +	originalBitGc->SetBrushColor(TRgb(0,0,128));
   1.968 +	originalBitGc->DrawRect(rect);
   1.969 +	
   1.970 +	
   1.971 +	CleanupStack::PopAndDestroy(2, refBitmapDev);
   1.972 +	}
   1.973 +
   1.974 +//Helper function: Creates a RSgImage from a bitmap
   1.975 +void CTDrawResource::CreateSgImageFromBitmapL(RSgImage& aSgImage)
   1.976 +	{
   1.977 +	TUint32* data = iRefBitmap->DataAddress();
   1.978 +	TInt stride = iRefBitmap->DataStride();
   1.979 +	TSize size = iRefBitmap->SizeInPixels();
   1.980 +
   1.981 +	TSgImageInfo info;
   1.982 +	info.iSizeInPixels = size;
   1.983 +	info.iScreenId = TheClient->iScreen->CurrentScreenMode();
   1.984 +	info.iShareable = ETrue; //must be shareable since wserv is in other process
   1.985 +	info.iUsage = ESgUsageWindowGcSource;
   1.986 +	info.iPixelFormat = SgUtils::DisplayModeToPixelFormat(iRefBitmap->DisplayMode());
   1.987 +
   1.988 +	User::LeaveIfError(aSgImage.Create(info, data, stride));
   1.989 +	}
   1.990 +
   1.991 +//Helper function: Creates all reference bitmaps required for all tests
   1.992 +void CTDrawResource::CreateReferenceAndCopyBitmapsL()
   1.993 +	{
   1.994 +	//Create reference bitmap
   1.995 +	iRefBitmap = new (ELeave) CFbsBitmap();
   1.996 +	User::LeaveIfError(iRefBitmap->Create(TSize(160,120),EColor64K));
   1.997 +	
   1.998 +	//Setup to draw to original reference bitmap
   1.999 +    CFbsBitmapDevice *refBitmapDev = CFbsBitmapDevice::NewL(iRefBitmap);
  1.1000 +    CleanupStack::PushL(refBitmapDev);
  1.1001 +    CFbsBitGc *originalBitGc;
  1.1002 +	User::LeaveIfError(refBitmapDev->CreateContext(originalBitGc));
  1.1003 +	CleanupStack::PushL(originalBitGc);
  1.1004 +	
  1.1005 +	//Draw to reference bitmap
  1.1006 +	originalBitGc->SetBrushStyle(CFbsBitGc::ESolidBrush);
  1.1007 +	originalBitGc->SetBrushColor(TRgb(0,150,150));
  1.1008 +	originalBitGc->DrawRect(TRect(TPoint(0,0), TSize(160,60)));
  1.1009 +	originalBitGc->SetBrushColor(TRgb(150,100,150));
  1.1010 +	originalBitGc->DrawRect(TRect(TPoint(0,60), TSize(160,60)));
  1.1011 +	
  1.1012 +	//create a rotated version of the reference bitmap
  1.1013 +	iRotatedRefBitmap = new (ELeave) CFbsBitmap();
  1.1014 +	User::LeaveIfError(iRotatedRefBitmap->Create(TSize(120,160),EColor64K));
  1.1015 +	
  1.1016 +	//Setup to draw to rotated reference bitmap
  1.1017 +    CFbsBitmapDevice *rotRefBitmapDev = CFbsBitmapDevice::NewL(iRotatedRefBitmap);
  1.1018 +    CleanupStack::PushL(rotRefBitmapDev);
  1.1019 +    CFbsBitGc *rotatedBitGc;
  1.1020 +	User::LeaveIfError(rotRefBitmapDev->CreateContext(rotatedBitGc));
  1.1021 +	CleanupStack::PushL(rotatedBitGc);
  1.1022 +	
  1.1023 +	//Draw to rotated reference bitmap
  1.1024 +	rotatedBitGc->SetBrushStyle(CFbsBitGc::ESolidBrush);
  1.1025 +	rotatedBitGc->SetBrushColor(TRgb(0,150,150));
  1.1026 +	rotatedBitGc->DrawRect(TRect(TPoint(60,0), TSize(60,160)));
  1.1027 +	rotatedBitGc->SetBrushColor(TRgb(150,100,150));
  1.1028 +	rotatedBitGc->DrawRect(TRect(TPoint(0,0), TSize(60,160)));
  1.1029 +	
  1.1030 +	//Prepare a scaled version of the rotated reference bitmap to later compare against
  1.1031 +    iScaledBitmap = new (ELeave) CFbsBitmap();
  1.1032 +    User::LeaveIfError(iScaledBitmap->Create(TSize(160,120),EColor64K));
  1.1033 +	//Setup to draw to bitmap
  1.1034 +    CFbsBitmapDevice *scaledBitDev = CFbsBitmapDevice::NewL(iScaledBitmap);
  1.1035 +    CleanupStack::PushL(scaledBitDev);
  1.1036 +    CFbsBitGc *scaledBitGc;
  1.1037 +	User::LeaveIfError(scaledBitDev->CreateContext(scaledBitGc));
  1.1038 +	CleanupStack::PushL(scaledBitGc);
  1.1039 +	//Draw the rotated reference bitmap scaled
  1.1040 +	scaledBitGc->DrawBitmap(KDestRect, iRotatedRefBitmap); 
  1.1041 +	
  1.1042 +	//Prepare a scaled version of the rotated reference bitmap to later compare against
  1.1043 +	iScaledCroppedBitmap = new (ELeave) CFbsBitmap();
  1.1044 +	User::LeaveIfError(iScaledCroppedBitmap->Create(TSize(160,120),EColor64K));
  1.1045 +    
  1.1046 +	//Setup to draw to bitmap
  1.1047 +    CFbsBitmapDevice *scaledCroppedBitDev = CFbsBitmapDevice::NewL(iScaledCroppedBitmap);
  1.1048 +    CleanupStack::PushL(scaledCroppedBitDev);
  1.1049 +    CFbsBitGc *scaledCroppedBitGc;
  1.1050 +	User::LeaveIfError(scaledCroppedBitDev->CreateContext(scaledCroppedBitGc));
  1.1051 +	CleanupStack::PushL(scaledCroppedBitGc);
  1.1052 +	
  1.1053 +	//Draw the rotated reference bitmap scaled
  1.1054 +	TInt width = iRotatedRefBitmap->SizeInPixels().iWidth;
  1.1055 +	TInt height = iRotatedRefBitmap->SizeInPixels().iHeight; 
  1.1056 +	
  1.1057 +	TRect rectSrc;
  1.1058 +	rectSrc.iTl.iX= width - KSourceRect.Height();
  1.1059 +	rectSrc.iTl.iY= 0;
  1.1060 +	rectSrc.iBr.iX= width;
  1.1061 +	rectSrc.iBr.iY= KSourceRect.Width();
  1.1062 +
  1.1063 +	scaledCroppedBitGc->DrawBitmap(KDestRect, iRotatedRefBitmap, rectSrc); 
  1.1064 +	
  1.1065 +	//Prepare bitmap for testing drawable which opened with different screen number
  1.1066 +	iBitmapWrongScreenNumber = new (ELeave) CFbsBitmap();
  1.1067 +    User::LeaveIfError(iBitmapWrongScreenNumber->Create(TSize(160,120),EColor64K));
  1.1068 +	//Setup to draw to bitmap
  1.1069 +    CFbsBitmapDevice *wrongScreenNumberBitDev = CFbsBitmapDevice::NewL(iBitmapWrongScreenNumber);
  1.1070 +    CleanupStack::PushL(wrongScreenNumberBitDev);
  1.1071 +    CFbsBitGc *wrongScreenNumberBitGc;
  1.1072 +	User::LeaveIfError(wrongScreenNumberBitDev->CreateContext(wrongScreenNumberBitGc));
  1.1073 +	CleanupStack::PushL(wrongScreenNumberBitGc);
  1.1074 +	//Draw the rotated reference bitmap scaled
  1.1075 +	wrongScreenNumberBitGc->SetBrushColor(KRgbGreen);
  1.1076 +	wrongScreenNumberBitGc->SetBrushStyle(CFbsBitGc::ESolidBrush);
  1.1077 +	wrongScreenNumberBitGc->SetPenStyle(CFbsBitGc::ENullPen);
  1.1078 +	wrongScreenNumberBitGc->DrawRect(TRect(0, 0, 160, 120)); //
  1.1079 +	
  1.1080 +	//Create a bitmap  to copy to with the same display mode as the reference bitmap
  1.1081 +	iCopyBitmap = new (ELeave) CFbsBitmap();
  1.1082 +	User::LeaveIfError(iCopyBitmap->Create(TSize(640,240),EColor64K));
  1.1083 +	
  1.1084 +	CleanupStack::PopAndDestroy(10, refBitmapDev);
  1.1085 +	}
  1.1086 +
  1.1087 +//Helper function: This function compares two bitmaps on a pixel by pixel basis */
  1.1088 +TBool CTDrawResource::CompareBitmapsByPixel(CFbsBitmap* aCandidateBitmap, CFbsBitmap* aReferenceBitmap)
  1.1089 +	{
  1.1090 +	TBool result = ETrue;
  1.1091 +
  1.1092 +	TSize candidateSize = aCandidateBitmap->SizeInPixels();
  1.1093 +	TSize referenceSize = aReferenceBitmap->SizeInPixels();
  1.1094 +
  1.1095 +	TInt mismatchedPixels = 0;
  1.1096 +	
  1.1097 +	TRgb nativePixel;
  1.1098 +	TRgb referencePixel;
  1.1099 +	for (TInt x = 0; x < referenceSize.iWidth; x++)
  1.1100 +		{
  1.1101 +		for (TInt y = 0; y < referenceSize.iHeight; y++)
  1.1102 +			{
  1.1103 +			TPoint point(x,y);
  1.1104 +			nativePixel = TRgb(0,0,0,0);
  1.1105 +			referencePixel = TRgb(0,0,0,0);
  1.1106 +			aCandidateBitmap->GetPixel(nativePixel, point);
  1.1107 +			aReferenceBitmap->GetPixel(referencePixel, point);
  1.1108 +
  1.1109 +			if (nativePixel != referencePixel)
  1.1110 +				{
  1.1111 +				mismatchedPixels++;
  1.1112 +				result = EFalse;
  1.1113 +				}
  1.1114 +			}
  1.1115 +		}
  1.1116 +	
  1.1117 +	INFO_PRINTF2(_L("Number of different pixels: %i"), mismatchedPixels);
  1.1118 +	return result;
  1.1119 +	}
  1.1120 +//Helper function: This function extracts content of the image associated with the image target and copies it into bitmap
  1.1121 +void CTDrawResource::BitmapLC(CFbsBitmap*& aBmp)
  1.1122 +	{
  1.1123 +	aBmp = new(ELeave) CFbsBitmap;
  1.1124 +    CleanupStack::PushL(aBmp);
  1.1125 +	
  1.1126 +	TSgImageInfo info;
  1.1127 +	TInt res = iImage.GetInfo(info);
  1.1128 +	User::LeaveIfError(res);
  1.1129 +	
  1.1130 +	res = aBmp ->Create(info.iSizeInPixels, SgUtils::PixelFormatToDisplayMode(info.iPixelFormat));
  1.1131 +	User::LeaveIfError(res);
  1.1132 +	TUint32* dataAddressDest = aBmp->DataAddress();
  1.1133 +	
  1.1134 +	RSgImage image;
  1.1135 +	info.iUsage = ESgUsageNone;
  1.1136 +	info.iCpuAccess = ESgCpuAccessReadOnly;
  1.1137 +	res = image.Create(info, iImage);
  1.1138 +	User::LeaveIfError(res);
  1.1139 +	CleanupClosePushL(image);
  1.1140 +	const TAny* dataAddress = NULL; 
  1.1141 +	TInt dataStride;
  1.1142 +	res = image.MapReadOnly(dataAddress, dataStride);
  1.1143 +	User::LeaveIfError(res);
  1.1144 +	Mem::Copy(dataAddressDest, dataAddress, dataStride * info.iSizeInPixels.iHeight);
  1.1145 +	image.Unmap();
  1.1146 +	CleanupStack::PopAndDestroy(&image);
  1.1147 +	}