os/graphics/graphicsdeviceinterface/directgdi/test/tdirectgdi_test_step_base.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#include "tdirectgdi_test_step_base.h"
sl@0
    17
#include <graphics/directgdiextensioninterfaces.h>
sl@0
    18
sl@0
    19
//These reference and test bitmaps are used for image comparison
sl@0
    20
//These are saved at
sl@0
    21
_LIT(KRefPath, "\\img\\ref\\%S.mbm");
sl@0
    22
_LIT(KTestPath, "\\img\\test\\%S.mbm");
sl@0
    23
sl@0
    24
//The default image cache size to use for the tests.
sl@0
    25
const TInt KDriverImageCacheSizeTests = 0x400000;
sl@0
    26
sl@0
    27
/**
sl@0
    28
Position iterator constructor.
sl@0
    29
@param aStartX Start x position.
sl@0
    30
@param aEndX End x position.
sl@0
    31
@param aStepX Step for x position.
sl@0
    32
@param aStartY Start y position.
sl@0
    33
@param aEndY End y position.
sl@0
    34
@param aStepY Step for y position.
sl@0
    35
*/
sl@0
    36
TPositionIterator::TPositionIterator(TInt aStartX, TInt aEndX, TInt aStepX,
sl@0
    37
	TInt aStartY, TInt aEndY, TInt aStepY) :
sl@0
    38
	iStartX(aStartX), iEndX(aEndX), iStepX(aStepX),
sl@0
    39
	iStartY(aStartY), iEndY(aEndY), iStepY(aStepY),
sl@0
    40
	iPosX(aStartX), iPosY(aStartY), iIndexX(0), iIndexY(0)
sl@0
    41
	{
sl@0
    42
	}
sl@0
    43
sl@0
    44
/**
sl@0
    45
Begin iteration.
sl@0
    46
All needed variables are initialized to start iteration.
sl@0
    47
*/
sl@0
    48
void TPositionIterator::Begin()
sl@0
    49
	{
sl@0
    50
	iPosX = iStartX;
sl@0
    51
	iPosY = iStartY;
sl@0
    52
	iIndexX = 0;
sl@0
    53
	iIndexY = 0;
sl@0
    54
	}
sl@0
    55
sl@0
    56
/**
sl@0
    57
Next iteration.
sl@0
    58
Generates next position and position indices.
sl@0
    59
@return EFalse is returned if end of iterations else ETrue.
sl@0
    60
*/
sl@0
    61
TBool TPositionIterator::Next()
sl@0
    62
	{
sl@0
    63
	if(iPosX < iEndX)
sl@0
    64
		{
sl@0
    65
		iPosX += iStepX;
sl@0
    66
		iIndexX++;
sl@0
    67
		return ETrue;
sl@0
    68
		}
sl@0
    69
	else
sl@0
    70
		{
sl@0
    71
		if(iPosY < iEndY)
sl@0
    72
			{
sl@0
    73
			iPosX = iStartX;
sl@0
    74
			iIndexX = 0;
sl@0
    75
			iPosY += iStepY;
sl@0
    76
			iIndexY++;
sl@0
    77
			return ETrue;
sl@0
    78
			}
sl@0
    79
		else
sl@0
    80
			{
sl@0
    81
			return EFalse;
sl@0
    82
			}
sl@0
    83
		}
sl@0
    84
	}
sl@0
    85
sl@0
    86
CBitmapDevice* CTImageTarget::BitmapDevice() const
sl@0
    87
	{
sl@0
    88
	return iBitmapDevice;
sl@0
    89
	}
sl@0
    90
sl@0
    91
/**
sl@0
    92
Create a new bitgdi target
sl@0
    93
@param aPixelFormat The pixel format for the target
sl@0
    94
@param aSize The size of the target to create
sl@0
    95
@return On return, contains a pointer to a bitgdi target object
sl@0
    96
*/
sl@0
    97
CTBitGdiTarget*  CTBitGdiTarget::NewL(TUidPixelFormat aPixelFormat, const TSize& aSize)
sl@0
    98
	{
sl@0
    99
	CTBitGdiTarget* self = new(ELeave) CTBitGdiTarget();
sl@0
   100
	CleanupStack::PushL(self);
sl@0
   101
	self->ConstructL(aPixelFormat, aSize);
sl@0
   102
	CleanupStack::Pop(); // self
sl@0
   103
	return self;
sl@0
   104
	}
sl@0
   105
sl@0
   106
/**
sl@0
   107
Second phase constructor of CTBitGdiTarget. Creates a bitmap for use as a target.
sl@0
   108
@param aPixelFormat The pixel format for the target to be created
sl@0
   109
@param aSize The size of the target to be created
sl@0
   110
*/
sl@0
   111
void CTBitGdiTarget::ConstructL(TUidPixelFormat aPixelFormat, const TSize& aSize)
sl@0
   112
	{	
sl@0
   113
	// create a bitmap
sl@0
   114
	iBitmap = new(ELeave) CFbsBitmap;
sl@0
   115
	iBitmap->Create(aSize, TDisplayModeMapping::MapPixelFormatToDisplayMode(aPixelFormat));
sl@0
   116
	// create an off screen bitmap device
sl@0
   117
	iBitmapDevice = CFbsBitmapDevice::NewL(iBitmap);
sl@0
   118
	}
sl@0
   119
sl@0
   120
/**
sl@0
   121
Create a bitgdi context
sl@0
   122
@param aGc A pointer to the created graphics context
sl@0
   123
@param aActivate ETrue to create and activate the context aGc, EFalse to just create it.
sl@0
   124
@return On return, contains a pointer to the created bitgdi context
sl@0
   125
*/
sl@0
   126
TInt CTBitGdiTarget::CreateContext(CTContextBase*& aGc, TBool aActivate)
sl@0
   127
	{
sl@0
   128
	TInt result = KErrGeneral;
sl@0
   129
	TRAP(result, aGc = CTBitGdiContext::NewL((CFbsBitmapDevice*)iBitmapDevice, aActivate));
sl@0
   130
   	return result;
sl@0
   131
   	}
sl@0
   132
sl@0
   133
/**
sl@0
   134
Sets the object to draw to a particular device 
sl@0
   135
@param aGc A pointer to the created graphics context
sl@0
   136
*/
sl@0
   137
TInt CTBitGdiTarget::Activate(CTContextBase*& aGc)
sl@0
   138
	{
sl@0
   139
	CTBitGdiContext* gc = (CTBitGdiContext*)aGc;
sl@0
   140
	// Activate the context on a rendering target.
sl@0
   141
	return gc->Activate(iBitmapDevice);
sl@0
   142
	}
sl@0
   143
/**
sl@0
   144
Get the size of the device area in pixels
sl@0
   145
@return On return, The width and height of the target, in pixels 
sl@0
   146
*/
sl@0
   147
TSize CTBitGdiTarget::SizeInPixels() const 
sl@0
   148
	{
sl@0
   149
	return iBitmapDevice->SizeInPixels();
sl@0
   150
	}
sl@0
   151
sl@0
   152
sl@0
   153
/**
sl@0
   154
Get a target FBsBitmap
sl@0
   155
@return The target FBsBitmap
sl@0
   156
*/
sl@0
   157
CFbsBitmap* CTBitGdiTarget::GetTargetFbsBitmapL()
sl@0
   158
	{
sl@0
   159
	return iBitmap;
sl@0
   160
	}
sl@0
   161
sl@0
   162
/**
sl@0
   163
Nothing to be implemented for BitGdi Finish()
sl@0
   164
*/
sl@0
   165
void CTBitGdiTarget::Finish ()
sl@0
   166
	{
sl@0
   167
	}
sl@0
   168
sl@0
   169
sl@0
   170
void CTBitGdiTarget::Close() 
sl@0
   171
	{	
sl@0
   172
	}
sl@0
   173
sl@0
   174
sl@0
   175
/**
sl@0
   176
Destructor of CTBitGdiTarget
sl@0
   177
*/
sl@0
   178
CTBitGdiTarget::~CTBitGdiTarget()
sl@0
   179
	{
sl@0
   180
	delete iBitmapDevice;
sl@0
   181
	delete iBitmap;
sl@0
   182
	}
sl@0
   183
sl@0
   184
/**
sl@0
   185
Default constructor.
sl@0
   186
*/
sl@0
   187
CTDirectGdiTarget::CTDirectGdiTarget()
sl@0
   188
	{
sl@0
   189
	}
sl@0
   190
sl@0
   191
/**
sl@0
   192
Create a new directgdi target
sl@0
   193
@param aPixelFormat The pixel format for the target
sl@0
   194
@param aSize The size of the target to create
sl@0
   195
@return On return, contains a pointer to a directgdi target object
sl@0
   196
*/
sl@0
   197
CTDirectGdiTarget*  CTDirectGdiTarget::NewL(TUidPixelFormat aPixelFormat, const TSize& aSize)
sl@0
   198
	{
sl@0
   199
	CTDirectGdiTarget* self = new(ELeave) CTDirectGdiTarget();
sl@0
   200
	CleanupStack::PushL(self);
sl@0
   201
	self->ConstructL(aPixelFormat, aSize);
sl@0
   202
	CleanupStack::Pop(); // self
sl@0
   203
	return self;
sl@0
   204
	}
sl@0
   205
/**
sl@0
   206
Second phase constructor of CTDirectGdiTarget
sl@0
   207
@param aPixelFormat The pixel format for the target
sl@0
   208
@param aSize The size of the target to create
sl@0
   209
*/
sl@0
   210
void CTDirectGdiTarget::ConstructL(TUidPixelFormat aPixelFormat, const TSize& aSize)
sl@0
   211
	{	
sl@0
   212
	// open the driver
sl@0
   213
	User::LeaveIfError(CDirectGdiDriver::Open());
sl@0
   214
	iDGdiDriver = CDirectGdiDriver::Static();
sl@0
   215
	if (iDGdiDriver == NULL)
sl@0
   216
		User::Leave(KErrNoMemory);
sl@0
   217
	
sl@0
   218
	// set a large cache size (if available to do so) so the tests execute more quickly.
sl@0
   219
	MDirectGdiDriverCacheSize* driverCacheInterface = NULL;
sl@0
   220
	if (KErrNone == iDGdiDriver->GetInterface(TUid::Uid(KDirectGdiDriverCacheSizeUid), (TAny*&)driverCacheInterface))
sl@0
   221
		{
sl@0
   222
		User::LeaveIfError(driverCacheInterface->SetMaxImageCacheSize(KDriverImageCacheSizeTests));
sl@0
   223
		}
sl@0
   224
	
sl@0
   225
	iDGdiImageTarget = new (ELeave) RDirectGdiImageTarget(*iDGdiDriver);
sl@0
   226
	// create a bitmap which is used to save the image data from an RSgImage to a file.
sl@0
   227
	iBitmap = new(ELeave) CFbsBitmap;
sl@0
   228
	User::LeaveIfError(iBitmap->Create(aSize, TDisplayModeMapping::MapPixelFormatToDisplayMode(aPixelFormat)));
sl@0
   229
	iBitmapDevice = CFbsBitmapDevice::NewL(iBitmap);
sl@0
   230
	// Set up image attributes
sl@0
   231
	iImageInfo.iSizeInPixels = aSize;
sl@0
   232
	iImageInfo.iPixelFormat = aPixelFormat;
sl@0
   233
	iImageInfo.iUsage = ESgUsageDirectGdiTarget;
sl@0
   234
	User::LeaveIfError(iRSgImage.Create(iImageInfo, NULL,0));
sl@0
   235
	User::LeaveIfError(iDGdiImageTarget->Create(iRSgImage));
sl@0
   236
	}
sl@0
   237
sl@0
   238
sl@0
   239
/**
sl@0
   240
Create a Direct GDI graphics context.
sl@0
   241
sl@0
   242
@param aGc	A reference to a pointer to the created graphics context. If return is anything 
sl@0
   243
			other than KErrNone then aGc is set to NULL.
sl@0
   244
@param aActivate ETrue to create and activate the context aGc, EFalse to just create it.
sl@0
   245
sl@0
   246
@return KErrNone, if successful; otherwise, another of the system-wide error codes.
sl@0
   247
*/
sl@0
   248
TInt CTDirectGdiTarget::CreateContext(CTContextBase*& aGc, TBool aActivate)
sl@0
   249
	{	
sl@0
   250
	TInt result = KErrGeneral;
sl@0
   251
	
sl@0
   252
	aGc = NULL;
sl@0
   253
	
sl@0
   254
    TRAP(result, aGc = CTestDirectGdiContext::NewL());
sl@0
   255
    CTestDirectGdiContext* gc = (CTestDirectGdiContext*)aGc;
sl@0
   256
sl@0
   257
    // If the GC is not NULL, make sure the return code indicates
sl@0
   258
    // success.
sl@0
   259
    if (aActivate && aGc)
sl@0
   260
    	{
sl@0
   261
		if(result != KErrNone)
sl@0
   262
			{
sl@0
   263
			return result;
sl@0
   264
			}		
sl@0
   265
		else
sl@0
   266
			{
sl@0
   267
			// Activate the context on a rendering target.
sl@0
   268
			result = gc->Activate(*iDGdiImageTarget);
sl@0
   269
			}
sl@0
   270
    	}	
sl@0
   271
	return result;
sl@0
   272
	}
sl@0
   273
sl@0
   274
/**
sl@0
   275
Sets the object to draw to a particular device 
sl@0
   276
@param aGc A pointer to the created graphics context
sl@0
   277
*/
sl@0
   278
TInt CTDirectGdiTarget::Activate(CTContextBase*& aGc)
sl@0
   279
	{
sl@0
   280
    CTestDirectGdiContext* gc = (CTestDirectGdiContext*)aGc;
sl@0
   281
	// Activate the context on a rendering target.
sl@0
   282
    return gc->Activate(*iDGdiImageTarget);
sl@0
   283
	}
sl@0
   284
sl@0
   285
/**
sl@0
   286
Get the size of the device area in pixels
sl@0
   287
@return On return, The width and height of the target, in pixels 
sl@0
   288
*/
sl@0
   289
TSize CTDirectGdiTarget::SizeInPixels() const 
sl@0
   290
	{
sl@0
   291
	return iImageInfo.iSizeInPixels;
sl@0
   292
	}
sl@0
   293
sl@0
   294
/**
sl@0
   295
Get a target FBsBitmap.
sl@0
   296
@return The target FBsBitmap
sl@0
   297
*/
sl@0
   298
CFbsBitmap* CTDirectGdiTarget::GetTargetFbsBitmapL()
sl@0
   299
	{
sl@0
   300
	// Create a copy of the RSgImage that is CPU-accessible for mapping.
sl@0
   301
	RSgImage cpuAccessibleImage;
sl@0
   302
	TSgImageInfo imageInfo;
sl@0
   303
	imageInfo.iSizeInPixels = iImageInfo.iSizeInPixels;
sl@0
   304
	imageInfo.iPixelFormat = iImageInfo.iPixelFormat;
sl@0
   305
	imageInfo.iCpuAccess = ESgCpuAccessReadOnly;
sl@0
   306
	User::LeaveIfError(cpuAccessibleImage.Create(imageInfo, iRSgImage));
sl@0
   307
	CleanupClosePushL(cpuAccessibleImage);
sl@0
   308
	
sl@0
   309
	iBitmap->BeginDataAccess();
sl@0
   310
	const TInt bitmapDataStride = iBitmap->DataStride();
sl@0
   311
	const TInt numScanlines = imageInfo.iSizeInPixels.iHeight;
sl@0
   312
	const TAny* sgImageDataAddress;
sl@0
   313
	TInt sgImageDataStride = 0;
sl@0
   314
	
sl@0
   315
	User::LeaveIfError(cpuAccessibleImage.MapReadOnly(sgImageDataAddress, sgImageDataStride));
sl@0
   316
sl@0
   317
    TUint32* bitmapDataAddress = iBitmap->DataAddress();
sl@0
   318
    for (TInt scanline = 0; scanline < numScanlines; ++scanline)
sl@0
   319
    	{
sl@0
   320
    	Mem::Copy((TUint8*)bitmapDataAddress + (scanline*bitmapDataStride), (TUint8*)sgImageDataAddress + (scanline*sgImageDataStride), bitmapDataStride);
sl@0
   321
    	}
sl@0
   322
    iBitmap->EndDataAccess();
sl@0
   323
    cpuAccessibleImage.Unmap();
sl@0
   324
sl@0
   325
	CleanupStack::PopAndDestroy(1);
sl@0
   326
    	
sl@0
   327
    return iBitmap;
sl@0
   328
	}
sl@0
   329
sl@0
   330
/**
sl@0
   331
Force completion of all batched rendering operations. Will not return
sl@0
   332
until rendering is complete.
sl@0
   333
sl@0
   334
@pre	Fully initialised image target.
sl@0
   335
*/
sl@0
   336
void CTDirectGdiTarget::Finish ()
sl@0
   337
	{	
sl@0
   338
	if (iDGdiDriver)
sl@0
   339
		iDGdiDriver->Finish();
sl@0
   340
	}
sl@0
   341
sl@0
   342
sl@0
   343
void CTDirectGdiTarget::Close() 
sl@0
   344
	{
sl@0
   345
	if (iDGdiImageTarget)
sl@0
   346
		iDGdiImageTarget->Close();
sl@0
   347
	}
sl@0
   348
sl@0
   349
/**
sl@0
   350
Destructor of CTDirectGdiTarget
sl@0
   351
*/
sl@0
   352
CTDirectGdiTarget::~CTDirectGdiTarget()
sl@0
   353
	{
sl@0
   354
	delete iBitmapDevice;
sl@0
   355
	delete iBitmap;
sl@0
   356
	if (iDGdiImageTarget)
sl@0
   357
		{
sl@0
   358
		iDGdiImageTarget->Close();	
sl@0
   359
		delete iDGdiImageTarget;
sl@0
   360
		}
sl@0
   361
	if (iDGdiDriver)
sl@0
   362
		iDGdiDriver->Close();
sl@0
   363
	iRSgImage.Close();
sl@0
   364
	}
sl@0
   365
sl@0
   366
/**
sl@0
   367
Implementation of CTestStep base class virtual
sl@0
   368
It is used for doing all common initialisation to derived classes.
sl@0
   369
Make it being able to leave 
sl@0
   370
The leave will be picked up by the framework.
sl@0
   371
@leave Gets system wide error code
sl@0
   372
@return - TVerdict code
sl@0
   373
*/
sl@0
   374
TVerdict CTDirectGdiStepBase::doTestStepPreambleL()
sl@0
   375
	{
sl@0
   376
	SetTestStepResult(EPass);
sl@0
   377
	
sl@0
   378
	// Create and install Active Scheduler in case tests require active objects
sl@0
   379
	iScheduler = new(ELeave) CActiveScheduler;
sl@0
   380
	CActiveScheduler::Install(iScheduler);
sl@0
   381
	
sl@0
   382
	TPtrC targetPixelFormatInput;
sl@0
   383
	TPtrC sourcePixelFormatInput;
sl@0
   384
	TPtrC sourceResourcePixelFormatInput;
sl@0
   385
	
sl@0
   386
	// get input for tests from .ini file
sl@0
   387
	_LIT(KDirectgdiTestInput, "DirectgdiTestInput");
sl@0
   388
	_LIT(KTargetPixelFormatEnums, "TargetPixelFormatEnums ");
sl@0
   389
	_LIT(KSourcePixelFormatEnums, "SourcePixelFormatEnums ");
sl@0
   390
	_LIT(KSourceResourcePixelFormatEnums, "SourceResourcePixelFormatEnums ");
sl@0
   391
	_LIT(KDoRefImg, "DoRefImg");
sl@0
   392
	_LIT(KDoDirectGdi, "DoDirectGdi");
sl@0
   393
	_LIT(KRunOomTests, "RunOomTests");
sl@0
   394
	TEST(GetStringFromConfig(KDirectgdiTestInput, KTargetPixelFormatEnums, targetPixelFormatInput));
sl@0
   395
	TEST(GetStringFromConfig(KDirectgdiTestInput, KSourcePixelFormatEnums, sourcePixelFormatInput));
sl@0
   396
	TEST(GetStringFromConfig(KDirectgdiTestInput, KSourceResourcePixelFormatEnums, sourceResourcePixelFormatInput));
sl@0
   397
	TEST(GetIntFromConfig(KDirectgdiTestInput, KDoRefImg, iMakeRefImg));
sl@0
   398
	TEST(GetIntFromConfig(KDirectgdiTestInput, KDoDirectGdi, iUseDirectGdi));
sl@0
   399
	TEST(GetIntFromConfig(KDirectgdiTestInput, KRunOomTests, iDoOomTests));
sl@0
   400
	#ifndef _DEBUG
sl@0
   401
	if(iDoOomTests)
sl@0
   402
		{
sl@0
   403
		iDoOomTests = EFalse;
sl@0
   404
		INFO_PRINTF1(_L("WARNING: Can't run out of memory tests under a release build. OOM tests set to run in ini file so turning OOM tests off."));
sl@0
   405
		}
sl@0
   406
	#endif
sl@0
   407
sl@0
   408
	ConvertPixelFormats(targetPixelFormatInput, iTargetPixelFormatArray);
sl@0
   409
	ConvertPixelFormats(sourcePixelFormatInput, iSourcePixelFormatArray);
sl@0
   410
	ConvertPixelFormats(sourceResourcePixelFormatInput, iSourceResourcePixelFormatArray);
sl@0
   411
	iRunningOomTests = EFalse;
sl@0
   412
sl@0
   413
	Logger().ShareAuto();
sl@0
   414
sl@0
   415
	__UHEAP_MARK;		
sl@0
   416
	User::LeaveIfError(SgDriver::Open());
sl@0
   417
	User::LeaveIfError(RFbsSession::Connect());	
sl@0
   418
		
sl@0
   419
	return TestStepResult();
sl@0
   420
	}
sl@0
   421
sl@0
   422
/**
sl@0
   423
Convert the pixel format strings to pixel format enums
sl@0
   424
@param aPixelFormatInput The pixel format string for testing
sl@0
   425
@param aPixelFormatArray The array of converted pixel formats is returned here
sl@0
   426
*/
sl@0
   427
void CTDirectGdiStepBase::ConvertPixelFormats(TPtrC aPixelFormatInput, RArray<TUidPixelFormat>& aPixelFormatArray)
sl@0
   428
	{
sl@0
   429
	TPtrC tempBuf = aPixelFormatInput;
sl@0
   430
	TInt position = tempBuf.Find(_L(","));
sl@0
   431
			
sl@0
   432
	while(KErrNotFound != position)
sl@0
   433
		{
sl@0
   434
		aPixelFormatArray.Append(TDisplayModeMapping::ConvertPixelFormatStringToPixelFormat(tempBuf.Left(position)));
sl@0
   435
		tempBuf.Set(tempBuf.Mid(position + 2));
sl@0
   436
		position = tempBuf.Find(_L(","));
sl@0
   437
		}	
sl@0
   438
sl@0
   439
	if (position == KErrNotFound)
sl@0
   440
		{
sl@0
   441
		aPixelFormatArray.Append(TDisplayModeMapping::ConvertPixelFormatStringToPixelFormat(tempBuf));
sl@0
   442
		}
sl@0
   443
	}
sl@0
   444
sl@0
   445
/**
sl@0
   446
Implementation of CTestStep base class virtual
sl@0
   447
It is used for doing all after test treatment common to derived classes in here.
sl@0
   448
Make it being able to leave
sl@0
   449
The leave will be picked up by the framework.
sl@0
   450
@leave Gets system wide error code
sl@0
   451
@return - TVerdict
sl@0
   452
*/
sl@0
   453
 TVerdict CTDirectGdiStepBase::doTestStepPostambleL()
sl@0
   454
	{
sl@0
   455
	if(iFontStore)
sl@0
   456
		{
sl@0
   457
		if(iFontId)
sl@0
   458
			{
sl@0
   459
			iFontStore->RemoveFile(iFontId);
sl@0
   460
			iFontId = 0;
sl@0
   461
			}
sl@0
   462
		delete iFontStore;
sl@0
   463
		iFontStore = NULL;
sl@0
   464
		}
sl@0
   465
	delete iGc;
sl@0
   466
	iGc = NULL;
sl@0
   467
	delete iGc2;
sl@0
   468
	iGc2 = NULL;
sl@0
   469
	delete iGdiTarget;
sl@0
   470
	iGdiTarget = NULL;
sl@0
   471
	delete iGdiTarget2;
sl@0
   472
	iGdiTarget2 = NULL;	
sl@0
   473
	SgDriver::Close();
sl@0
   474
	RFbsSession::Disconnect();
sl@0
   475
	__UHEAP_MARKEND;
sl@0
   476
	delete iScheduler;
sl@0
   477
	iScheduler = NULL;
sl@0
   478
	return TestStepResult();
sl@0
   479
	}
sl@0
   480
sl@0
   481
CTDirectGdiStepBase::~CTDirectGdiStepBase()
sl@0
   482
	{
sl@0
   483
	if(iFontStore)
sl@0
   484
		{
sl@0
   485
		if(iFontId)
sl@0
   486
			{
sl@0
   487
			iFontStore->RemoveFile(iFontId);			
sl@0
   488
			}
sl@0
   489
		delete iFontStore;
sl@0
   490
		}
sl@0
   491
	delete iScheduler;
sl@0
   492
	delete iGc;
sl@0
   493
	delete iGc2;
sl@0
   494
	delete iGdiTarget;
sl@0
   495
	delete iGdiTarget2;
sl@0
   496
	iTargetPixelFormatArray.Close();
sl@0
   497
	iSourcePixelFormatArray.Close();
sl@0
   498
	iSourceResourcePixelFormatArray.Close();
sl@0
   499
	}
sl@0
   500
sl@0
   501
CTDirectGdiStepBase::CTDirectGdiStepBase()
sl@0
   502
	{
sl@0
   503
	}
sl@0
   504
sl@0
   505
/**
sl@0
   506
Create a name in the format of <TestImage / RefImage>_< TestCase Name >_<DisplayModeName>_<Orientation>_<PostFix(optional)>
sl@0
   507
@param aParams A structure object of parameters to be passed through
sl@0
   508
@param aTestName The test name to be generated 
sl@0
   509
@param aTestCaseName The test case name passed in, to be used in the resultant filename
sl@0
   510
@param aNamePostfix If this is not NULL, it is appended to filename with an underscore in front of it
sl@0
   511
*/
sl@0
   512
void CTDirectGdiStepBase::CreateFileName(TTestParams& aParams, TDes& aTestName, TPtrC& aTestCaseName, TDesC* aNamePostfix)
sl@0
   513
	{	
sl@0
   514
	if (iUseDirectGdi)
sl@0
   515
		{
sl@0
   516
		aTestName.Append(KDirectGc);
sl@0
   517
		}
sl@0
   518
	else
sl@0
   519
		{
sl@0
   520
		aTestName.Append(KBitGc);		
sl@0
   521
		}
sl@0
   522
	
sl@0
   523
	if (aParams.iDoCompressed)
sl@0
   524
		{
sl@0
   525
		aTestName.Append(KSeparator);	
sl@0
   526
		aTestName.Append(KCom);
sl@0
   527
		}
sl@0
   528
sl@0
   529
	aTestName.Append(KSeparator);	
sl@0
   530
	aTestName.Append(aTestCaseName);
sl@0
   531
	aTestName.Append(KSeparator);
sl@0
   532
	aTestName.Append(KTargetString);
sl@0
   533
	aTestName.Append(KSeparator);
sl@0
   534
	aTestName.Append(TDisplayModeMapping::ConvertPixelFormatToShortPixelFormatString(aParams.iTargetPixelFormat));
sl@0
   535
	
sl@0
   536
	if (aNamePostfix)
sl@0
   537
		{
sl@0
   538
		aTestName.Append(KSeparator);
sl@0
   539
		aTestName.Append(*aNamePostfix);
sl@0
   540
		}
sl@0
   541
	}
sl@0
   542
sl@0
   543
/**
sl@0
   544
@see DisplayTargetImageL(TUidPixelFormat, CTImageTarget*)
sl@0
   545
 */
sl@0
   546
void CTDirectGdiStepBase::DisplayTargetImageL(TUidPixelFormat aPixelFormat)
sl@0
   547
	{
sl@0
   548
	DisplayTargetImageL(aPixelFormat, iGdiTarget);
sl@0
   549
	}
sl@0
   550
sl@0
   551
/**
sl@0
   552
Bitblt an image to screen
sl@0
   553
@param aPixelFormat The pixel format for tests
sl@0
   554
@param aGdiTarget The target image to blit
sl@0
   555
*/
sl@0
   556
void CTDirectGdiStepBase::DisplayTargetImageL(TUidPixelFormat aPixelFormat, CTImageTarget* aGdiTarget)
sl@0
   557
	{
sl@0
   558
	// Ensure the image has been completly rendered.
sl@0
   559
	aGdiTarget->Finish();
sl@0
   560
	CFbsScreenDevice* screenDevice = CFbsScreenDevice::NewL(_L("scdv"), TDisplayModeMapping::MapPixelFormatToDisplayMode(aPixelFormat));
sl@0
   561
	TEST(screenDevice!=NULL);
sl@0
   562
	CleanupStack::PushL(screenDevice);
sl@0
   563
	
sl@0
   564
	CFbsBitGc* bitGc;
sl@0
   565
	screenDevice->CreateContext(bitGc);
sl@0
   566
	TEST(bitGc!=NULL);
sl@0
   567
	CleanupStack::PushL(bitGc);
sl@0
   568
sl@0
   569
 	TPoint startPoint = TPoint(0, 0);
sl@0
   570
	bitGc->Clear();
sl@0
   571
	bitGc->BitBlt(startPoint, aGdiTarget->GetTargetFbsBitmapL()); 		
sl@0
   572
	screenDevice->Update();
sl@0
   573
sl@0
   574
	CleanupStack::PopAndDestroy(2, screenDevice);	
sl@0
   575
	}
sl@0
   576
sl@0
   577
/**
sl@0
   578
Initialises a target (or targets) and a graphics context (or contexts), depending on the value passed in aCase.
sl@0
   579
Deletes the previously used target(s) and context(s).
sl@0
   580
@param aPixelFormat The pixel format to be applied
sl@0
   581
@param aCase The type of test that this target is for, for example when testing with one context and two targets
sl@0
   582
this could be EOneContextTwoTargets_SamePixelType, the default value is EOneContextOneTarget.
sl@0
   583
@param aSize The size of the target(s) to be created
sl@0
   584
*/
sl@0
   585
void CTDirectGdiStepBase::SetTargetL(TUidPixelFormat aPixelFormat, const TContextTestCase aCase, const TSize& aSize)
sl@0
   586
	{
sl@0
   587
	if(!iRunningOomTests)
sl@0
   588
		{
sl@0
   589
		TBuf<KPixelFormatNameLength> pixelFormatName(TDisplayModeMapping::ConvertPixelFormatToPixelFormatString(aPixelFormat));
sl@0
   590
		INFO_PRINTF4(_L("SetTarget (using off screen bitmap): %S %dx%d"), &pixelFormatName, aSize.iWidth, aSize.iHeight);
sl@0
   591
		}
sl@0
   592
	
sl@0
   593
	delete iGc;
sl@0
   594
	iGc = NULL;	
sl@0
   595
	delete iGc2;
sl@0
   596
	iGc2 = NULL;	
sl@0
   597
	delete iGdiTarget;
sl@0
   598
	iGdiTarget = NULL;
sl@0
   599
	delete iGdiTarget2;
sl@0
   600
	iGdiTarget2 = NULL;
sl@0
   601
	TUidPixelFormat aPixelFormat2 = aPixelFormat;
sl@0
   602
	switch(aPixelFormat)
sl@0
   603
		{
sl@0
   604
		case EUidPixelFormatRGB_565:
sl@0
   605
			aPixelFormat2 = EUidPixelFormatARGB_8888_PRE;
sl@0
   606
			break;			
sl@0
   607
		case EUidPixelFormatARGB_8888_PRE:	
sl@0
   608
			aPixelFormat2 = EUidPixelFormatXRGB_8888;	
sl@0
   609
			break;			
sl@0
   610
		case EUidPixelFormatXRGB_8888:		
sl@0
   611
			aPixelFormat2 = EUidPixelFormatRGB_565;	
sl@0
   612
			break;
sl@0
   613
		}	
sl@0
   614
		
sl@0
   615
	switch(aCase)
sl@0
   616
		{
sl@0
   617
		case EOneContextOneTarget:				
sl@0
   618
			{
sl@0
   619
			if(iUseDirectGdi)
sl@0
   620
				{
sl@0
   621
				iGdiTarget = CTDirectGdiTarget::NewL(aPixelFormat, aSize);		
sl@0
   622
				}
sl@0
   623
			else
sl@0
   624
				{
sl@0
   625
				iGdiTarget = CTBitGdiTarget::NewL(aPixelFormat, aSize);
sl@0
   626
				}
sl@0
   627
			User::LeaveIfError(iGdiTarget->CreateContext(iGc));	
sl@0
   628
			}
sl@0
   629
			break;
sl@0
   630
		case EOneContextTwoTargets_SamePixelType:
sl@0
   631
			{			
sl@0
   632
			if(iUseDirectGdi)
sl@0
   633
				{
sl@0
   634
				iGdiTarget = CTDirectGdiTarget::NewL(aPixelFormat, aSize);		
sl@0
   635
				iGdiTarget2 = CTDirectGdiTarget::NewL(aPixelFormat, aSize);		
sl@0
   636
				}
sl@0
   637
			else
sl@0
   638
				{
sl@0
   639
				iGdiTarget = CTBitGdiTarget::NewL(aPixelFormat, aSize);
sl@0
   640
				iGdiTarget2 = CTBitGdiTarget::NewL(aPixelFormat, aSize);		
sl@0
   641
				}
sl@0
   642
			User::LeaveIfError(iGdiTarget->CreateContext(iGc));				
sl@0
   643
			}
sl@0
   644
			break;
sl@0
   645
		case EOneContextTwoTargets_DifferentPixelType:
sl@0
   646
			{	
sl@0
   647
			if(iUseDirectGdi)
sl@0
   648
				{
sl@0
   649
				iGdiTarget = CTDirectGdiTarget::NewL(aPixelFormat, aSize);		
sl@0
   650
				iGdiTarget2 = CTDirectGdiTarget::NewL(aPixelFormat2, aSize);		
sl@0
   651
				}
sl@0
   652
			else
sl@0
   653
				{
sl@0
   654
				iGdiTarget = CTBitGdiTarget::NewL(aPixelFormat, aSize);
sl@0
   655
				iGdiTarget2 = CTBitGdiTarget::NewL(aPixelFormat2, aSize);		
sl@0
   656
				}
sl@0
   657
			User::LeaveIfError(iGdiTarget->CreateContext(iGc));				
sl@0
   658
			}
sl@0
   659
			break;
sl@0
   660
		case ETwoContextsOneTarget:
sl@0
   661
			{
sl@0
   662
			if(iUseDirectGdi)
sl@0
   663
				{
sl@0
   664
				iGdiTarget = CTDirectGdiTarget::NewL(aPixelFormat, aSize);		
sl@0
   665
				}
sl@0
   666
			else
sl@0
   667
				{
sl@0
   668
				iGdiTarget = CTBitGdiTarget::NewL(aPixelFormat, aSize);
sl@0
   669
				}
sl@0
   670
			User::LeaveIfError(iGdiTarget->CreateContext(iGc, EFalse));	
sl@0
   671
			User::LeaveIfError(iGdiTarget->CreateContext(iGc2, EFalse));		
sl@0
   672
			}		
sl@0
   673
			break;
sl@0
   674
		case ETwoContextsTwoTargets_WithoutSharing_SamePixelType:
sl@0
   675
		case ETwoContextsTwoTargets_WithSharing_SamePixelType:
sl@0
   676
			{
sl@0
   677
			if(iUseDirectGdi)
sl@0
   678
				{
sl@0
   679
				iGdiTarget = CTDirectGdiTarget::NewL(aPixelFormat, aSize);		
sl@0
   680
				iGdiTarget2 = CTDirectGdiTarget::NewL(aPixelFormat, aSize);		
sl@0
   681
				}
sl@0
   682
			else
sl@0
   683
				{
sl@0
   684
				iGdiTarget = CTBitGdiTarget::NewL(aPixelFormat, aSize);
sl@0
   685
				iGdiTarget2 = CTBitGdiTarget::NewL(aPixelFormat, aSize);
sl@0
   686
				}
sl@0
   687
			User::LeaveIfError(iGdiTarget->CreateContext(iGc, EFalse));	
sl@0
   688
			User::LeaveIfError(iGdiTarget2->CreateContext(iGc2, EFalse));	
sl@0
   689
			}
sl@0
   690
			break;
sl@0
   691
		case ETwoContextsTwoTargets_WithoutSharing_DifferentPixelType:
sl@0
   692
		case ETwoContextsTwoTargets_WithSharing_DifferentPixelType:
sl@0
   693
			{
sl@0
   694
			if(iUseDirectGdi)
sl@0
   695
				{
sl@0
   696
				iGdiTarget = CTDirectGdiTarget::NewL(aPixelFormat, aSize);		
sl@0
   697
				iGdiTarget2 = CTDirectGdiTarget::NewL(aPixelFormat2, aSize);		
sl@0
   698
				}
sl@0
   699
			else
sl@0
   700
				{
sl@0
   701
				iGdiTarget = CTBitGdiTarget::NewL(aPixelFormat, aSize);
sl@0
   702
				iGdiTarget2 = CTBitGdiTarget::NewL(aPixelFormat2, aSize);
sl@0
   703
				}
sl@0
   704
			User::LeaveIfError(iGdiTarget->CreateContext(iGc, EFalse));	
sl@0
   705
			User::LeaveIfError(iGdiTarget2->CreateContext(iGc2, EFalse));	
sl@0
   706
			}
sl@0
   707
			break;									
sl@0
   708
		case EOneContextOneTarget_TwiceActivate:
sl@0
   709
			{
sl@0
   710
			if(iUseDirectGdi)
sl@0
   711
				{
sl@0
   712
				iGdiTarget = CTDirectGdiTarget::NewL(aPixelFormat, aSize);		
sl@0
   713
				}
sl@0
   714
			else
sl@0
   715
				{
sl@0
   716
				iGdiTarget = CTBitGdiTarget::NewL(aPixelFormat, aSize);
sl@0
   717
				}
sl@0
   718
			User::LeaveIfError(iGdiTarget->CreateContext(iGc));	
sl@0
   719
			}
sl@0
   720
			break;		
sl@0
   721
		}	
sl@0
   722
sl@0
   723
	// setup font store
sl@0
   724
	if(iFontStore)
sl@0
   725
		{
sl@0
   726
		if(iFontId)
sl@0
   727
			{
sl@0
   728
			iFontStore->RemoveFile(iFontId);
sl@0
   729
			iFontId = 0;
sl@0
   730
			}
sl@0
   731
		delete iFontStore;
sl@0
   732
		iFontStore = NULL;
sl@0
   733
		}
sl@0
   734
	
sl@0
   735
	iFontStore = CFbsTypefaceStore::NewL(iGdiTarget->BitmapDevice());
sl@0
   736
sl@0
   737
	_LIT(KEonFontFileName,"z:\\resource\\fonts\\eon14.gdr");
sl@0
   738
	TESTL(KErrNone == iFontStore->AddFile(KEonFontFileName, iFontId));
sl@0
   739
	
sl@0
   740
	// Reset VGImage cache - OpenVG DirectGDI only
sl@0
   741
	iVgImageCache = NULL;
sl@0
   742
	if (iUseDirectGdi)
sl@0
   743
		{
sl@0
   744
		TInt err = iGc->GetInterface(TUid::Uid(KDirectGdiVgImageCacheUid), (TAny*&) iVgImageCache);
sl@0
   745
		if (KErrNotSupported == err)
sl@0
   746
			{
sl@0
   747
			// Must be using software DirectGDI as this does not have a VGImage cache
sl@0
   748
			iUseSwDirectGdi = ETrue;
sl@0
   749
			}
sl@0
   750
		}
sl@0
   751
	}
sl@0
   752
sl@0
   753
/**
sl@0
   754
Get a font by looking for it in the font store. Only gets "DejaVu Sans Mono" at the moment.
sl@0
   755
@return Returns a pointer to the "DejaVu Sans Mono" font if it is found in the font store, returns NULL if it not found.
sl@0
   756
*/
sl@0
   757
CFont* CTDirectGdiStepBase::GetFont()
sl@0
   758
	{
sl@0
   759
	_LIT(KFontFamily, "DejaVu Sans Mono");
sl@0
   760
sl@0
   761
	CFont* font = NULL;
sl@0
   762
	TFontSpec spec(KFontFamily, 13);
sl@0
   763
	iFontStore->GetNearestFontInPixels(font, spec);
sl@0
   764
	return font;
sl@0
   765
	}
sl@0
   766
sl@0
   767
/**
sl@0
   768
Releases the passed font in the font store.
sl@0
   769
@param aFont A pointer to the font to be released.
sl@0
   770
 */
sl@0
   771
void CTDirectGdiStepBase::ReleaseFont(CFont* aFont)
sl@0
   772
	{
sl@0
   773
	if(aFont && iFontStore)
sl@0
   774
		{
sl@0
   775
		iFontStore->ReleaseFont(aFont);
sl@0
   776
		}
sl@0
   777
	}
sl@0
   778
sl@0
   779
/**
sl@0
   780
Create a file and save the target image to the file with a filename created from aTestCaseName and aNamePostfix
sl@0
   781
@param aParams A structure object of parameters to be passed through
sl@0
   782
@param aTestCaseName The name of the test case
sl@0
   783
@param aImageTarget The image target to be written out to the file
sl@0
   784
@param aNamePostfix A postfix to be appended to the test case name
sl@0
   785
@see CreateFileName()
sl@0
   786
@return KErrNone if successful, one of the system wide error codes otherwise
sl@0
   787
*/
sl@0
   788
TInt CTDirectGdiStepBase::WriteTargetOutput(TTestParams& aParams, TPtrC aTestCaseName, CTImageTarget* aImageTarget, TDesC* aNamePostfix)
sl@0
   789
	{
sl@0
   790
	// Finish is called for the OOM tests as well as the normal tests as it is responsible for
sl@0
   791
	// clearing up the pending image array. Images get left in the array and cause the OOM tests
sl@0
   792
	// for DrawResource to fail if Finish is not called.
sl@0
   793
	aImageTarget->Finish();
sl@0
   794
	
sl@0
   795
	if(!iRunningOomTests) // don't want to save test images when running our of memory twsts
sl@0
   796
		{
sl@0
   797
		TBuf<KFileNameLength> testFileName;
sl@0
   798
		CreateFileName(aParams, testFileName, aTestCaseName, aNamePostfix);
sl@0
   799
		TFileName mbmFile;
sl@0
   800
		TBuf<KFileNameLength> testPathName;
sl@0
   801
		#ifdef __WINS__
sl@0
   802
			testPathName.Append(_L("c:"));
sl@0
   803
		#else
sl@0
   804
			testPathName.Append(_L("e:"));
sl@0
   805
		#endif
sl@0
   806
	
sl@0
   807
		if (iMakeRefImg)
sl@0
   808
			{
sl@0
   809
			testPathName.Append(KRefPath);
sl@0
   810
			mbmFile.Format(testPathName, &testFileName);
sl@0
   811
			}
sl@0
   812
		else
sl@0
   813
			{
sl@0
   814
			testPathName.Append(KTestPath);
sl@0
   815
			mbmFile.Format(testPathName, &testFileName);
sl@0
   816
			}
sl@0
   817
		INFO_PRINTF1(testFileName);
sl@0
   818
		
sl@0
   819
		CFbsBitmap* targetBitmap = NULL;
sl@0
   820
		TRAPD(err, targetBitmap = aImageTarget->GetTargetFbsBitmapL());
sl@0
   821
		return (err != KErrNone) ? err : targetBitmap->Save(mbmFile);		
sl@0
   822
		}
sl@0
   823
	return KErrNone;
sl@0
   824
	}
sl@0
   825
sl@0
   826
/**
sl@0
   827
Create a file and save the current target image to the file with a filename created from aTestCaseName and aNamePostfix
sl@0
   828
@param aParams A structure object of parameters to be passed through
sl@0
   829
@param aTestCaseName The name of the test case
sl@0
   830
@param aNamePostfix A postfix to be appended to the test case name
sl@0
   831
@see CreateFileName()
sl@0
   832
@return KErrNone if successful, one of the system wide error codes otherwise
sl@0
   833
*/
sl@0
   834
TInt CTDirectGdiStepBase::WriteTargetOutput(TTestParams& aParams, TPtrC aTestCaseName, TDesC* aNamePostfix)
sl@0
   835
	{
sl@0
   836
	return WriteTargetOutput(aParams, aTestCaseName, iGdiTarget, aNamePostfix);
sl@0
   837
	}
sl@0
   838
sl@0
   839
/**
sl@0
   840
Reset the graphics context
sl@0
   841
*/
sl@0
   842
void CTDirectGdiStepBase::ResetGc()
sl@0
   843
	{
sl@0
   844
	iGc->Reset();
sl@0
   845
	iGc->Clear();
sl@0
   846
	}
sl@0
   847
sl@0
   848
/**
sl@0
   849
Compares the target image pixel by pixel against the given colour. If a pixel with a  
sl@0
   850
different colour than aColour is found then the test will fail, otherwise the test will pass.
sl@0
   851
@param aColour A colour rgba value to find.
sl@0
   852
@return ETrue if test passed or EFalse if test failed.
sl@0
   853
*/
sl@0
   854
TBool CTDirectGdiStepBase::TestTargetL(const TRgb& aColour)
sl@0
   855
	{
sl@0
   856
	iGdiTarget->Finish();
sl@0
   857
		
sl@0
   858
	CFbsBitmap* bitmap = iGdiTarget->GetTargetFbsBitmapL();
sl@0
   859
	TInt width = bitmap->SizeInPixels().iWidth;
sl@0
   860
	TInt height = bitmap->SizeInPixels().iHeight;
sl@0
   861
sl@0
   862
	HBufC8* lineBuf = HBufC8::NewLC(width*4);
sl@0
   863
	TPtr8 linePtr(lineBuf->Des());
sl@0
   864
sl@0
   865
	TBool pass = ETrue;
sl@0
   866
sl@0
   867
	for(TInt line=0; line<height; line++)
sl@0
   868
		{
sl@0
   869
		bitmap->GetScanLine(linePtr, TPoint(0, line), width, EColor16MA);
sl@0
   870
sl@0
   871
		const TUint8* pPtr = linePtr.Ptr();
sl@0
   872
		for(TInt x=0; x<width; x++)
sl@0
   873
			{
sl@0
   874
			// EColor16MA pixel representation is 32-bit BGRA
sl@0
   875
			TRgb pColour(pPtr[2], pPtr[1], pPtr[0], pPtr[3]);
sl@0
   876
			pPtr += 4;
sl@0
   877
			
sl@0
   878
			if (iTestParams.iTargetPixelFormat == EUidPixelFormatXRGB_8888)
sl@0
   879
				{
sl@0
   880
				if ((pColour.Value() & 0xFFFFFF) != (aColour.Value() & 0xFFFFFF))
sl@0
   881
					{
sl@0
   882
					pass = EFalse;
sl@0
   883
					break; // break inner loop
sl@0
   884
					}
sl@0
   885
				}
sl@0
   886
			else if(pColour != aColour)
sl@0
   887
				{
sl@0
   888
				pass = EFalse;
sl@0
   889
				break; // break inner loop
sl@0
   890
				}
sl@0
   891
			}
sl@0
   892
sl@0
   893
		if(!pass)
sl@0
   894
			break; // break outer loop if test failed in inner loop
sl@0
   895
		}
sl@0
   896
sl@0
   897
	CleanupStack::PopAndDestroy(lineBuf);
sl@0
   898
sl@0
   899
	return pass;
sl@0
   900
	}
sl@0
   901
sl@0
   902
/**
sl@0
   903
Checks the graphics context for the passed error codes and logs an error if the codes do not match. 
sl@0
   904
If the tests are running using DirectGdi then aDirectGdiErrorCode is checked against the current error in the
sl@0
   905
graphics context, if the tests are running using BitGdi then aBitGdiErrorCode is checked against the current 
sl@0
   906
error in the graphics context.
sl@0
   907
@param aDirectGdiErrorCode The DirectGdi error code to check when the tests are running using DirectGdi
sl@0
   908
@param aBitGdiErrorCode The BitGdi error code to check when the tests are running using BitGdi
sl@0
   909
@param aFile The filename to use when reporting the error
sl@0
   910
@param aLine The line number to use when reporting the error
sl@0
   911
*/
sl@0
   912
void CTDirectGdiStepBase::CheckErrorsL(TInt aDirectGdiErrorCode, TInt aBitGdiErrorCode, const TText8* aFile, TInt aLine)
sl@0
   913
	{
sl@0
   914
	if(iUseDirectGdi)
sl@0
   915
		{
sl@0
   916
		TESTWITHFILENAMEANDLINENUMBERL(iGc->GetError() == aDirectGdiErrorCode, aFile, aLine);
sl@0
   917
		}
sl@0
   918
	else
sl@0
   919
		{
sl@0
   920
		TESTWITHFILENAMEANDLINENUMBERL(iGc->GetError() == aBitGdiErrorCode, aFile, aLine);
sl@0
   921
		}
sl@0
   922
	}
sl@0
   923
sl@0
   924
/**
sl@0
   925
Derived classes should override this method and add their calls to individual test cases in
sl@0
   926
the overridden version.
sl@0
   927
*/
sl@0
   928
void CTDirectGdiStepBase::RunTestsL()
sl@0
   929
	{
sl@0
   930
	}
sl@0
   931
sl@0
   932
/**
sl@0
   933
Runs the tests in RunTestsL checking for Out of Memory conditions and testing for memory leaks.
sl@0
   934
*/
sl@0
   935
void CTDirectGdiStepBase::RunOomTestsL()
sl@0
   936
	{
sl@0
   937
	if (!iDoOomTests)
sl@0
   938
		{
sl@0
   939
		// don't run the out of memory tests
sl@0
   940
		return;
sl@0
   941
		}
sl@0
   942
	TInt tryCount = 0;
sl@0
   943
	INFO_PRINTF1(_L("*****Running Out Of Memory Tests*****"));
sl@0
   944
	
sl@0
   945
	// save the current state of test step results
sl@0
   946
	TVerdict currentTestStepResult = TestStepResult();
sl@0
   947
sl@0
   948
	FOREVER
sl@0
   949
		{		
sl@0
   950
		iRunningOomTests = ETrue;
sl@0
   951
		TInt err = KErrNone;
sl@0
   952
		
sl@0
   953
		// count cells so we can know how many we leaked
sl@0
   954
		TInt cellsStart = User::CountAllocCells();
sl@0
   955
		
sl@0
   956
		__UHEAP_FAILNEXT(++tryCount);
sl@0
   957
		__UHEAP_MARK;
sl@0
   958
		
sl@0
   959
		TRAP(err, RunTestsL());
sl@0
   960
sl@0
   961
		TBool finishedCorrectly = EFalse;
sl@0
   962
		if ((err == KErrNone))
sl@0
   963
			{
sl@0
   964
			// claims to have finished correctly, and we're not failing every alloc
sl@0
   965
			finishedCorrectly = CheckForHeapFailNext();
sl@0
   966
			}		
sl@0
   967
		__UHEAP_RESET;
sl@0
   968
		TInt cellsEnd = User::CountAllocCells();
sl@0
   969
		if (cellsStart < cellsEnd)
sl@0
   970
			{
sl@0
   971
			// leaked.
sl@0
   972
			TInt leakedCells = cellsEnd - cellsStart;
sl@0
   973
			ERR_PRINTF3(_L("On loop number %d we leaked %d cells. About to cause panic."),tryCount,leakedCells);				
sl@0
   974
			}
sl@0
   975
		__UHEAP_MARKEND;
sl@0
   976
		
sl@0
   977
		// check to see if we finished all OOM testing successfully
sl@0
   978
		if ((err == KErrNone) && finishedCorrectly)
sl@0
   979
			{
sl@0
   980
			INFO_PRINTF2(_L(" - Test completed successfully after %d iterations."),tryCount);
sl@0
   981
			break;
sl@0
   982
			}
sl@0
   983
		}
sl@0
   984
	// restore test step result and ignore any test failures the out of memory tests produce
sl@0
   985
	SetTestStepResult(currentTestStepResult);
sl@0
   986
	iRunningOomTests = EFalse;
sl@0
   987
	}
sl@0
   988
sl@0
   989
/**
sl@0
   990
Tests that the passed condition aCondition is equal to ETrue and reports an error if it is not.
sl@0
   991
This method does not report errors when the tests are running in OOM mode.
sl@0
   992
@see testBooleanTrue()
sl@0
   993
@param aCondition The boolean value to be checked for being equal to ETrue
sl@0
   994
@param aFile The filename to use when reporting the error
sl@0
   995
@param aLine The line number to use when reporting the error
sl@0
   996
*/
sl@0
   997
void CTDirectGdiStepBase::testBooleanTrue(TBool aCondition, const TText8* aFile, TInt aLine) 
sl@0
   998
	{
sl@0
   999
	if(!iRunningOomTests)
sl@0
  1000
		{
sl@0
  1001
		CTestStep::testBooleanTrue(aCondition, aFile, aLine, ETrue);
sl@0
  1002
		}
sl@0
  1003
	}
sl@0
  1004
sl@0
  1005
/**
sl@0
  1006
A leaving version of testBooleanTrue().
sl@0
  1007
@see testBooleanTrue()
sl@0
  1008
*/
sl@0
  1009
void CTDirectGdiStepBase::testBooleanTrueL(TBool aCondition, const TText8* aFile, TInt aLine) 
sl@0
  1010
	{
sl@0
  1011
	if(!iRunningOomTests)
sl@0
  1012
		{
sl@0
  1013
		CTestStep::testBooleanTrueL(aCondition, aFile, aLine, ETrue);
sl@0
  1014
		}
sl@0
  1015
	else
sl@0
  1016
		{
sl@0
  1017
		if(!aCondition)
sl@0
  1018
			{
sl@0
  1019
			User::Leave(TEST_ERROR_CODE);
sl@0
  1020
			}
sl@0
  1021
		}
sl@0
  1022
	}
sl@0
  1023
sl@0
  1024
/**
sl@0
  1025
A version of testBooleanTrue() that additionally writes an error code to the output if aCondition is not equal to ETrue.
sl@0
  1026
@see testBooleanTrue()
sl@0
  1027
@param aCondition The boolean value to be checked for being equal to ETrue
sl@0
  1028
@param aErrorCode An error code to be reported if aCondition is EFalse
sl@0
  1029
@param aFile The filename to use when reporting the error
sl@0
  1030
@param aLine The line number to use when reporting the error
sl@0
  1031
*/
sl@0
  1032
void CTDirectGdiStepBase::testBooleanTrueWithErrorCode(TBool aCondition, TInt aErrorCode, const TText8* aFile, TInt aLine)
sl@0
  1033
	{
sl@0
  1034
	if(!iRunningOomTests)
sl@0
  1035
		{
sl@0
  1036
		if(!aCondition)			
sl@0
  1037
			{
sl@0
  1038
			SetTestStepResult(EFail);
sl@0
  1039
			_LIT(KMessage,"Test Failed with error [%d]");
sl@0
  1040
			Logger().LogExtra(aFile, aLine, ESevrErr, KMessage, aErrorCode);
sl@0
  1041
			}
sl@0
  1042
		}
sl@0
  1043
	}
sl@0
  1044
sl@0
  1045
/**
sl@0
  1046
A leaving version of testBooleanTrueWithErrorCode()
sl@0
  1047
@see testBooleanTrueWithErrorCode()
sl@0
  1048
@param aCondition The boolean value to be checked for being equal to ETrue
sl@0
  1049
@param aErrorCode An error code to be reported if aCondition is EFalse
sl@0
  1050
@param aFile The filename to use when reporting the error
sl@0
  1051
@param aLine The line number to use when reporting the error
sl@0
  1052
*/
sl@0
  1053
void CTDirectGdiStepBase::testBooleanTrueWithErrorCodeL(TBool aCondition, TInt aErrorCode, const TText8* aFile, TInt aLine)
sl@0
  1054
	{
sl@0
  1055
	if(!iRunningOomTests)
sl@0
  1056
		{
sl@0
  1057
		testBooleanTrueWithErrorCode(aCondition, aErrorCode, aFile, aLine);
sl@0
  1058
		}
sl@0
  1059
	else
sl@0
  1060
		{
sl@0
  1061
		if(!aCondition)
sl@0
  1062
			{
sl@0
  1063
			User::Leave(aErrorCode);
sl@0
  1064
			}
sl@0
  1065
		}
sl@0
  1066
	}
sl@0
  1067
sl@0
  1068
/**
sl@0
  1069
Creates a CFbsBitmap that has a pattern of differently coloured concentric rectangles on it for use in test cases.
sl@0
  1070
@param aPixelFormat The pixel format for create the target bitmap
sl@0
  1071
@param aSize The size of the bitmap to be created
sl@0
  1072
*/
sl@0
  1073
CFbsBitmap* CTDirectGdiStepBase::CreateConcentricRectsBitmapL(TUidPixelFormat aPixelFormat, const TSize& aSize)
sl@0
  1074
	{
sl@0
  1075
	CFbsBitmap* bitmap = new (ELeave) CFbsBitmap;
sl@0
  1076
	CleanupStack::PushL(bitmap);
sl@0
  1077
sl@0
  1078
	TESTNOERRORL(bitmap->Create(aSize, TDisplayModeMapping::MapPixelFormatToDisplayMode(aPixelFormat)));
sl@0
  1079
sl@0
  1080
	CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL(bitmap);
sl@0
  1081
	TESTL(bitmapDevice!=NULL);
sl@0
  1082
	CleanupStack::PushL(bitmapDevice);
sl@0
  1083
	
sl@0
  1084
	CFbsBitGc* bitGc = NULL;
sl@0
  1085
	User::LeaveIfError(bitmapDevice->CreateContext(bitGc));
sl@0
  1086
	TESTL(bitGc!=NULL);
sl@0
  1087
	CleanupStack::PushL(bitGc);
sl@0
  1088
sl@0
  1089
	for (TInt i = aSize.iWidth/2; i>0; --i)
sl@0
  1090
		{
sl@0
  1091
		bitGc->SetPenColor(KColor16Table[i%16]);	
sl@0
  1092
		bitGc->DrawRect(TRect(i,i,aSize.iWidth - i, aSize.iHeight - i));
sl@0
  1093
		}
sl@0
  1094
sl@0
  1095
	CleanupStack::PopAndDestroy(2, bitmapDevice);
sl@0
  1096
	CleanupStack::Pop(bitmap);
sl@0
  1097
	
sl@0
  1098
	return bitmap;
sl@0
  1099
	}
sl@0
  1100
sl@0
  1101
/**
sl@0
  1102
Creates a bitmap that contains a checked board pattern of coloured rectangles for use in test cases.
sl@0
  1103
@param aPixelFormat The pixel format for create the target bitmap
sl@0
  1104
@param aSize The size of the bitmap
sl@0
  1105
@param aChecksPerAxis Number of checks on X and Y.
sl@0
  1106
@param aGenAlpha If ETrue then generate pattern in alpha channel.
sl@0
  1107
*/
sl@0
  1108
CFbsBitmap* CTDirectGdiStepBase::CreateCheckedBoardBitmapL(TUidPixelFormat aPixelFormat,
sl@0
  1109
		const TSize& aSize, const TSize& aChecksPerAxis, TBool aGenAlpha)
sl@0
  1110
	{
sl@0
  1111
	
sl@0
  1112
	CFbsBitmap* bitmap = new (ELeave) CFbsBitmap;
sl@0
  1113
	CleanupStack::PushL(bitmap);
sl@0
  1114
	TESTNOERRORL(bitmap->Create(aSize, TDisplayModeMapping::MapPixelFormatToDisplayMode(aPixelFormat)));
sl@0
  1115
	
sl@0
  1116
	CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL(bitmap);
sl@0
  1117
	CleanupStack::PushL(bitmapDevice);
sl@0
  1118
	TESTL(bitmapDevice!=NULL);
sl@0
  1119
	
sl@0
  1120
	CFbsBitGc* bitGc = NULL;
sl@0
  1121
	User::LeaveIfError(bitmapDevice->CreateContext(bitGc));
sl@0
  1122
	CleanupStack::PushL(bitGc);
sl@0
  1123
	TESTL(bitGc!=NULL);
sl@0
  1124
	
sl@0
  1125
	bitGc->Clear();
sl@0
  1126
	bitGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
sl@0
  1127
	bitGc->SetPenStyle(CGraphicsContext::ENullPen);
sl@0
  1128
	if(aGenAlpha)
sl@0
  1129
		{
sl@0
  1130
		bitGc->SetDrawMode(CGraphicsContext::EDrawModeWriteAlpha);
sl@0
  1131
		}
sl@0
  1132
	TPoint point(0,0);
sl@0
  1133
	const TSize checkerSize(aSize.iWidth/aChecksPerAxis.iWidth,aSize.iHeight/aChecksPerAxis.iHeight);
sl@0
  1134
	TInt brushColour = 0x00;
sl@0
  1135
	for(point.iY = 0; point.iY < aSize.iHeight; point.iY += checkerSize.iHeight)
sl@0
  1136
		{
sl@0
  1137
		for(point.iX = 0; point.iX < aSize.iWidth; point.iX += checkerSize.iWidth)
sl@0
  1138
			{
sl@0
  1139
			TRgb colour = KColor16Table[brushColour++ & 0x0F];
sl@0
  1140
			if(aGenAlpha)
sl@0
  1141
				{
sl@0
  1142
				// Note that this is converted internally to pre-multiplied alpha
sl@0
  1143
				// for pre-multiplied alpha targets.
sl@0
  1144
				colour.SetAlpha((brushColour*5) & 255);
sl@0
  1145
				
sl@0
  1146
				//Use the following line to simplify test for manual verification.
sl@0
  1147
				//colour.SetAlpha(0x80);
sl@0
  1148
				}
sl@0
  1149
			bitGc->SetBrushColor(colour);
sl@0
  1150
			TRect rect(point, checkerSize);
sl@0
  1151
			bitGc->DrawRect(rect);
sl@0
  1152
			}
sl@0
  1153
		}
sl@0
  1154
	CleanupStack::PopAndDestroy(2, bitmapDevice);
sl@0
  1155
	CleanupStack::Pop(bitmap);
sl@0
  1156
	
sl@0
  1157
	return bitmap;
sl@0
  1158
	}
sl@0
  1159
sl@0
  1160
/**
sl@0
  1161
Create a black and white checked bitmap
sl@0
  1162
@param aPixelFormat The pixel format to use when creating the target bitmap
sl@0
  1163
@param aSize The size of the bitmap to create
sl@0
  1164
@param aChecksPerAxis Number of checks to draw in the X and Y directions
sl@0
  1165
@param aIsHardwareBitmap If ETrue, creates a hardware CFbsBitmap.
sl@0
  1166
*/
sl@0
  1167
CFbsBitmap* CTDirectGdiStepBase::CreateBlackWhiteBitmapL(TUidPixelFormat aPixelFormat,
sl@0
  1168
		const TSize& aSize, const TSize& aChecksPerAxis)
sl@0
  1169
	{
sl@0
  1170
	CFbsBitmap* bitmap = new (ELeave) CFbsBitmap;
sl@0
  1171
	CleanupStack::PushL(bitmap);
sl@0
  1172
	
sl@0
  1173
	TESTNOERRORL(bitmap->Create(aSize, TDisplayModeMapping::MapPixelFormatToDisplayMode(aPixelFormat)));
sl@0
  1174
	
sl@0
  1175
	CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL(bitmap);
sl@0
  1176
	CleanupStack::PushL(bitmapDevice);
sl@0
  1177
	TESTL(bitmapDevice!=NULL);
sl@0
  1178
sl@0
  1179
	CFbsBitGc* bitGc = NULL;
sl@0
  1180
	bitmapDevice->CreateContext(bitGc);
sl@0
  1181
	CleanupStack::PushL(bitGc);
sl@0
  1182
	TESTL(bitGc!=NULL);
sl@0
  1183
sl@0
  1184
	bitGc->Clear();
sl@0
  1185
	bitGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
sl@0
  1186
	bitGc->SetPenStyle(CGraphicsContext::ENullPen);
sl@0
  1187
	TPoint point(0,0);	
sl@0
  1188
	const TSize checkerSize(aSize.iWidth/aChecksPerAxis.iWidth,aSize.iHeight/aChecksPerAxis.iHeight);
sl@0
  1189
	for(point.iY = 0; point.iY < aSize.iHeight; point.iY += checkerSize.iHeight)
sl@0
  1190
		{
sl@0
  1191
		TBool isBlack = ETrue;
sl@0
  1192
		for(point.iX = 0; point.iX < aSize.iWidth; point.iX += checkerSize.iWidth)
sl@0
  1193
			{
sl@0
  1194
			if(isBlack)
sl@0
  1195
				bitGc->SetBrushColor(KRgbBlack);
sl@0
  1196
			else 
sl@0
  1197
				bitGc->SetBrushColor(KRgbWhite);
sl@0
  1198
			TRect rect(point, checkerSize);
sl@0
  1199
			bitGc->DrawRect(rect);
sl@0
  1200
			isBlack = EFalse;
sl@0
  1201
			}
sl@0
  1202
		}	
sl@0
  1203
	CleanupStack::PopAndDestroy(2, bitmapDevice);
sl@0
  1204
	CleanupStack::Pop(bitmap);	
sl@0
  1205
	return bitmap;
sl@0
  1206
	}
sl@0
  1207
sl@0
  1208
/**
sl@0
  1209
Create a bitmap designed for masking tests.
sl@0
  1210
@param aPixelFormat The pixel format to use when creating the bitmap
sl@0
  1211
@param aSize The size of the bitmap to create
sl@0
  1212
*/
sl@0
  1213
CFbsBitmap* CTDirectGdiStepBase::CreateMaskingPixmapL (
sl@0
  1214
		TUidPixelFormat aPixelFormat, 
sl@0
  1215
		const TSize& aSize)
sl@0
  1216
	{
sl@0
  1217
	
sl@0
  1218
	CFbsBitmap* bitmap = new (ELeave) CFbsBitmap;
sl@0
  1219
	CleanupStack::PushL(bitmap);
sl@0
  1220
	TESTL(KErrNone == bitmap->Create(aSize, TDisplayModeMapping::MapPixelFormatToDisplayMode(aPixelFormat)));
sl@0
  1221
	
sl@0
  1222
	CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL(bitmap);
sl@0
  1223
	CleanupStack::PushL(bitmapDevice);
sl@0
  1224
	TESTL(bitmapDevice!=NULL);
sl@0
  1225
	
sl@0
  1226
	CFbsBitGc* bitGc = NULL;
sl@0
  1227
	bitmapDevice->CreateContext(bitGc);
sl@0
  1228
	CleanupStack::PushL(bitGc);
sl@0
  1229
	TESTL(bitGc!=NULL);
sl@0
  1230
	
sl@0
  1231
	bitGc->Clear();
sl@0
  1232
	bitGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
sl@0
  1233
	bitGc->SetPenStyle(CGraphicsContext::ENullPen);
sl@0
  1234
sl@0
  1235
	bitGc->SetBrushColor(TRgb(0x808080));
sl@0
  1236
	TRect rect(aSize);
sl@0
  1237
	bitGc->DrawRect(rect);
sl@0
  1238
sl@0
  1239
	bitGc->SetBrushColor(TRgb(0x202020));
sl@0
  1240
	TRect rect2(0, 0, aSize.iWidth, aSize.iHeight>>2);
sl@0
  1241
	bitGc->DrawRect(rect2);
sl@0
  1242
	
sl@0
  1243
	TRect rect3(0, 0, aSize.iWidth>>3, aSize.iHeight);
sl@0
  1244
	bitGc->DrawRect(rect3);
sl@0
  1245
sl@0
  1246
	CleanupStack::PopAndDestroy(2, bitmapDevice);
sl@0
  1247
	CleanupStack::Pop(bitmap);
sl@0
  1248
	return bitmap;
sl@0
  1249
	}
sl@0
  1250
sl@0
  1251
/** 
sl@0
  1252
Stack cleanup helper function to use when the cache needs to be reset
sl@0
  1253
from the cleanup stack.
sl@0
  1254
This method calls MVgImageCache::ResetCache() on the passed MVgImageCache object
sl@0
  1255
@param aPtr A pointer to an image cache object, MVgImageCache*, to be reset
sl@0
  1256
*/
sl@0
  1257
void CTDirectGdiStepBase::ResetCache(TAny* aPtr)
sl@0
  1258
	{
sl@0
  1259
	MVgImageCache* cache = reinterpret_cast <MVgImageCache*> (aPtr);
sl@0
  1260
	cache->ResetCache();
sl@0
  1261
	}
sl@0
  1262
sl@0
  1263
/** 
sl@0
  1264
Stack cleanup helper function to use when the pen size needs to be reset to (1,1)
sl@0
  1265
from the cleanup stack. This is needed when SetPenSize() is called when testing the
sl@0
  1266
DirectGdi SW version as setting a pen size other then (1,1) causes memory to be
sl@0
  1267
created that is not freed until SetPenSize(1,1) is called (or the related graphics
sl@0
  1268
engine is destroyed).
sl@0
  1269
This method calls CTContextBase::SetPenSize(1,1) on the passed CTContextBase object
sl@0
  1270
@param aPtr A pointer to a test context object, CTContextBase*.
sl@0
  1271
*/
sl@0
  1272
void CTDirectGdiStepBase::ResetPenSize(TAny* aPtr)
sl@0
  1273
	{
sl@0
  1274
	if (CTContextBase* context = reinterpret_cast <CTContextBase*> (aPtr))
sl@0
  1275
		context->SetPenSize(TSize(1,1));
sl@0
  1276
	}