os/graphics/graphicstest/uibench/src/te_graphicsperformanceSuiteStepBase.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/graphicstest/uibench/src/te_graphicsperformanceSuiteStepBase.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,710 @@
     1.4 +// Copyright (c) 2005-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 "te_graphicsperformanceSuiteStepBase.h"
    1.26 +#include "te_graphicsperformanceSuiteDefs.h"
    1.27 +#include <hal.h>
    1.28 +#include <fbs.h>
    1.29 +#include <bitdrawinterfaceid.h>
    1.30 +#include <bmalphablend.h>
    1.31 +#include <bitdraw.h>
    1.32 +#include <graphics/gdi/gdiconsts.h>
    1.33 +#include <graphics/fbsdefs.h>
    1.34 +
    1.35 +#ifdef _USE_PROFILER
    1.36 +#include <profiler.h>
    1.37 +#endif
    1.38 +
    1.39 +#ifdef __WINS__
    1.40 +_LIT(KBitmapDrive, "c:");
    1.41 +#else
    1.42 +_LIT(KBitmapDrive, "e:");
    1.43 +#endif
    1.44 +_LIT(KBitmapPath, "\\uibench_sanity\\%S.mbm");
    1.45 +
    1.46 +/**
    1.47 +Gets the size of the hardware display in pixels
    1.48 +@return TSize object containing the screen size
    1.49 +*/
    1.50 +TSize GetDisplaySizeInPixels()
    1.51 +	{
    1.52 +	TInt x;
    1.53 +	HAL::Get(HALData::EDisplayXPixels, x);	// Get number x pixel of screen
    1.54 +	TInt y;
    1.55 +	HAL::Get(HALData::EDisplayYPixels, y);	// Get number y pixel of screen
    1.56 +	return TSize(x,y);
    1.57 +	}
    1.58 +
    1.59 +/**
    1.60 +Returns the size of the target used for off-screen drawing
    1.61 +@return TSize object containing the pixmap size.
    1.62 +*/
    1.63 +TSize GetPixmapSizeInPixels()
    1.64 +	{
    1.65 +	return TSize(1000, 1000);
    1.66 +	}
    1.67 +
    1.68 +/**
    1.69 +Create a new virtual bitmap device
    1.70 +*/
    1.71 +CVirtualBitmapDevice*  CVirtualBitmapDevice::NewL(TDisplayMode aDisplayMode, TBool aForceOffscreen)
    1.72 +	{
    1.73 +	CVirtualBitmapDevice* self = new(ELeave) CVirtualBitmapDevice();
    1.74 +	CleanupStack::PushL(self);
    1.75 +	self->ConstructL(aDisplayMode, aForceOffscreen);	
    1.76 +	CleanupStack::Pop(self);
    1.77 +	return self;
    1.78 +	}
    1.79 +	
    1.80 +/*
    1.81 +@param aDisplayMode The displaymode of the bitmap to create.
    1.82 +@param aForceOffscreen If ETrue, a bitmap device is created instead of a screen device, regardless
    1.83 +          of whether the screen supports the display mode.
    1.84 +*/
    1.85 +void CVirtualBitmapDevice::ConstructL(TDisplayMode aDisplayMode, TBool aForceOffscreen)
    1.86 +	{	
    1.87 +	// Attempt to create a screen device if not asked to use offscreen bitmap.
    1.88 +	CFbsScreenDevice* screenDevice = NULL;
    1.89 +	TInt ret = KErrNone;
    1.90 +	
    1.91 +	if (!aForceOffscreen)
    1.92 +		{
    1.93 +		TRAP(ret, screenDevice = CFbsScreenDevice::NewL(_L("scdv"), aDisplayMode));
    1.94 +		}
    1.95 +	
    1.96 +	if (aForceOffscreen || ret != KErrNone)
    1.97 +		{		
    1.98 +		// Screen device cannot be created, or we didn't want one, so create an off screen bitmap device		
    1.99 +		iBitmap = new(ELeave) CFbsBitmap;
   1.100 +		TSize scsize= (aForceOffscreen) ? GetPixmapSizeInPixels() : GetDisplaySizeInPixels();
   1.101 +		iBitmap->Create(scsize, aDisplayMode);
   1.102 +		iBitmapDevice = CFbsBitmapDevice::NewL(iBitmap);		
   1.103 +		iIsScreenDevice = EFalse;
   1.104 +		}	
   1.105 +	else
   1.106 +		{
   1.107 +		screenDevice->SetAutoUpdate(ETrue);
   1.108 +		iBitmapDevice = screenDevice;
   1.109 +		iIsScreenDevice = ETrue;
   1.110 +		}	
   1.111 +	}
   1.112 +
   1.113 +int CVirtualBitmapDevice::CreateContext(CGraphicsContext *&aGc)
   1.114 +	{	
   1.115 +	return iBitmapDevice->CreateContext(aGc);
   1.116 +	}
   1.117 +
   1.118 +TSize CVirtualBitmapDevice::SizeInPixels() const 
   1.119 +	{
   1.120 +	return iBitmapDevice->SizeInPixels();
   1.121 +	}
   1.122 +
   1.123 +
   1.124 +TInt CVirtualBitmapDevice::isScreenDevice() 
   1.125 +	{
   1.126 +	return iIsScreenDevice;
   1.127 +	}
   1.128 +
   1.129 +CVirtualBitmapDevice::~CVirtualBitmapDevice()
   1.130 +	{
   1.131 +	delete iBitmapDevice;
   1.132 +	delete iBitmap;	
   1.133 +	}
   1.134 +
   1.135 +
   1.136 +/**
   1.137 +Implements the same method on CFbsScreenDevice to Update the screen. This only works on a screen device.
   1.138 +Off screen bitmaps do not have to be updated and no action will be taken in this case.
   1.139 +*/
   1.140 +void CVirtualBitmapDevice::Update()
   1.141 +	{
   1.142 +	if (iIsScreenDevice)
   1.143 +		{
   1.144 +		CFbsScreenDevice* screenDevice = static_cast<CFbsScreenDevice*>(iBitmapDevice);
   1.145 +		if (screenDevice)
   1.146 +			screenDevice->Update();
   1.147 +		}
   1.148 +	}
   1.149 +
   1.150 +/**
   1.151 +Returns the actual bitmap device
   1.152 +*/
   1.153 +CBitmapDevice& CVirtualBitmapDevice::BitmapDevice()
   1.154 +	{
   1.155 +	return *iBitmapDevice;
   1.156 +	}
   1.157 +
   1.158 +/**
   1.159 +Returns the actual bitmap
   1.160 +*/
   1.161 +CFbsBitmap& CVirtualBitmapDevice::Bitmap()
   1.162 +	{
   1.163 +	return *iBitmap;
   1.164 +	}
   1.165 +		
   1.166 +/**
   1.167 +Create a new virtual draw device
   1.168 +*/
   1.169 +CVirtualDrawDevice*  CVirtualDrawDevice::NewL(TDisplayMode aDisplayMode)
   1.170 +	{
   1.171 +	CVirtualDrawDevice* self = new(ELeave) CVirtualDrawDevice();
   1.172 +	CleanupStack::PushL(self);
   1.173 +	self->ConstructL(aDisplayMode);
   1.174 +	CleanupStack::Pop(self);
   1.175 +	return self;
   1.176 +	}
   1.177 +	
   1.178 +void CVirtualDrawDevice::ConstructL(TDisplayMode aDisplayMode)
   1.179 +	{
   1.180 +	// Attempt to create a screen device
   1.181 +	CFbsDrawDevice* drawDevice = NULL;
   1.182 +	TRAPD(ret, drawDevice = CFbsDrawDevice::NewScreenDeviceL(KDefaultScreenNo, aDisplayMode));
   1.183 +	if (ret != KErrNone)
   1.184 +		{
   1.185 +		// Screen device cannot be created so create an off screen bitmap draw device
   1.186 +		iSize = GetDisplaySizeInPixels();
   1.187 +		iDrawDevice  = CFbsDrawDevice::NewBitmapDeviceL(iSize, aDisplayMode, ByteSize(iSize, aDisplayMode) / iSize.iHeight);
   1.188 +		iDeviceMemory = new (ELeave) TUint8[ByteSize(iSize, aDisplayMode)];
   1.189 +		iDrawDevice->SetBits(iDeviceMemory);
   1.190 +		iIsDrawDevice = EFalse;
   1.191 +		}
   1.192 +	else
   1.193 +		{
   1.194 +		iDrawDevice = drawDevice;
   1.195 +		iSize = iDrawDevice->SizeInPixels();
   1.196 +		iDrawDevice->SetAutoUpdate(ETrue);
   1.197 +		iIsDrawDevice = ETrue;
   1.198 +		}
   1.199 +	}
   1.200 +
   1.201 +TInt CVirtualDrawDevice::ByteSize(const TSize& aSize, TDisplayMode aDisplayMode)
   1.202 +	{
   1.203 +	TInt wordSize = aSize.iWidth;
   1.204 +	switch(aDisplayMode)
   1.205 +		{
   1.206 +	case EGray2:
   1.207 +		wordSize = (wordSize + 31) / 32;
   1.208 +		break;
   1.209 +	case EGray4:
   1.210 +		wordSize = (wordSize + 15) / 16;
   1.211 +		break;
   1.212 +	case EGray16:
   1.213 +	case EColor16:
   1.214 +		wordSize = (wordSize + 7) / 8;
   1.215 +		break;
   1.216 +	case EGray256:
   1.217 +	case EColor256:
   1.218 +		wordSize = (wordSize + 3) / 4;
   1.219 +		break;
   1.220 +	case EColor4K:
   1.221 +	case EColor64K:
   1.222 +		wordSize = (wordSize + 1) / 2;
   1.223 +		break;
   1.224 +	case EColor16M:
   1.225 +		wordSize = (((wordSize * 3) + 11) / 12) * 3;
   1.226 +		break;
   1.227 +	case EColor16MU:
   1.228 +	case EColor16MA:
   1.229 +		//Should not be changed!
   1.230 +		break;
   1.231 +	default:
   1.232 +		break;
   1.233 +		};
   1.234 +	return wordSize * aSize.iHeight * 4;
   1.235 +	}
   1.236 +
   1.237 +CFbsDrawDevice& CVirtualDrawDevice::DrawDevice()
   1.238 +	{
   1.239 +	return *iDrawDevice;
   1.240 +	}
   1.241 +
   1.242 +CVirtualDrawDevice::~CVirtualDrawDevice()
   1.243 +	{
   1.244 +	delete iDrawDevice;
   1.245 +	delete[] iDeviceMemory;
   1.246 +	}
   1.247 +
   1.248 +TBool CVirtualDrawDevice::IsDrawDevice()
   1.249 +	{
   1.250 +	return iIsDrawDevice;
   1.251 +	}
   1.252 +
   1.253 +const TDesC& CTe_graphicsperformanceSuiteStepBase::ColorModeName(TDisplayMode aMode)
   1.254 +	{
   1.255 +	_LIT(KColor4K,"Color4K");
   1.256 +	_LIT(KColor64K,"Color64K");
   1.257 +	_LIT(KColor16M,"Color16M");
   1.258 +	_LIT(KColor16MU,"Color16MU");
   1.259 +	_LIT(KColor16MA,"Color16MA");
   1.260 +	_LIT(KColor16MAP,"Color16MAP");
   1.261 +	_LIT(KUnknown,"Unknown");
   1.262 +	switch(aMode)
   1.263 +		{
   1.264 +	case EColor4K:
   1.265 +		return KColor4K;
   1.266 +	case EColor64K:
   1.267 +		return KColor64K;
   1.268 +	case EColor16M:
   1.269 +		return KColor16M;
   1.270 +	case EColor16MU:
   1.271 +		return KColor16MU;
   1.272 +	case EColor16MA:
   1.273 +		return KColor16MA;
   1.274 +	case EColor16MAP:
   1.275 +		return KColor16MAP;
   1.276 +	default:
   1.277 +		return KUnknown;
   1.278 +		}
   1.279 +	}
   1.280 +
   1.281 +/**
   1.282 +Implementation of CTestStep base class virtual
   1.283 +It is used for doing all initialisation common to derived classes in here.
   1.284 +Make it being able to leave if there are any errors here as there's no point in
   1.285 +trying to run a test step if anything fails.
   1.286 +The leave will be picked up by the framework.
   1.287 +
   1.288 +@return - TVerdict
   1.289 +*/
   1.290 +TVerdict CTe_graphicsperformanceSuiteStepBase::doTestStepPreambleL()
   1.291 +	{
   1.292 +	SetTestStepResult(EPass);
   1.293 +	
   1.294 +	// Create and install Active Scheduler in case tests require active objects
   1.295 +	iScheduler = new(ELeave) CActiveScheduler;
   1.296 +	CActiveScheduler::Install(iScheduler);
   1.297 +	
   1.298 +	FbsStartup();
   1.299 +	TESTNOERRORL(RFbsSession::Connect());
   1.300 +	HAL::Get(HALData::ECPUSpeed,iCPUSpeed); 
   1.301 +	INFO_PRINTF2(_L("CPUSpeed: %i	kHz"),iCPUSpeed);
   1.302 +	
   1.303 +	// get input for tests from .ini file
   1.304 +	TEST(GetIntFromConfig(_L("Profiling"), _L("DoProfiling"), iDoProfiling));
   1.305 +	TEST(GetBoolFromConfig(_L("SanityCheck"), _L("Bitmaps"), iShowBitmaps));
   1.306 +	
   1.307 +	if (iDoProfiling>0)	
   1.308 +		{
   1.309 +		__INITPROFILER	
   1.310 +		}
   1.311 +			
   1.312 +	iProfiler = CTProfiler::NewL(*this);
   1.313 +	__UHEAP_MARK;	
   1.314 +	return TestStepResult();
   1.315 +	}
   1.316 +
   1.317 +/**
   1.318 +Implementation of CTestStep base class virtual
   1.319 +It is used for doing all after test treatment common to derived classes in here.
   1.320 +Make it being able to leave
   1.321 +The leave will be picked up by the framework.
   1.322 +
   1.323 +@return - TVerdict
   1.324 +*/
   1.325 + TVerdict CTe_graphicsperformanceSuiteStepBase::doTestStepPostambleL()
   1.326 +	{
   1.327 +	delete iScheduler;
   1.328 +	iScheduler = NULL;
   1.329 +    delete iProfiler;
   1.330 +    iProfiler = NULL;
   1.331 +	return TestStepResult();
   1.332 +	}
   1.333 +
   1.334 +CTe_graphicsperformanceSuiteStepBase::~CTe_graphicsperformanceSuiteStepBase()
   1.335 +	{	
   1.336 +	if (iDoProfiling>0)	
   1.337 +		{
   1.338 +		__CLEANUPPROFILER	
   1.339 +		}	
   1.340 +	delete iScreenDevice;	
   1.341 +	delete iGc;
   1.342 +	delete iDrawDevice;
   1.343 +	RFbsSession::Disconnect();
   1.344 +	__UHEAP_MARKEND;
   1.345 +	}
   1.346 +
   1.347 +CTe_graphicsperformanceSuiteStepBase::CTe_graphicsperformanceSuiteStepBase()
   1.348 +	{
   1.349 +	}
   1.350 +
   1.351 +CVirtualBitmapDevice* CTe_graphicsperformanceSuiteStepBase::ScreenDevice()
   1.352 +	{
   1.353 +	TEST(iScreenDevice!=NULL);	// Ensure it is valid
   1.354 +	return iScreenDevice;
   1.355 +	}
   1.356 +
   1.357 +/**
   1.358 +Destroys and recreates the current target device.
   1.359 +
   1.360 +@param aScreenMode The display mode of the target being created
   1.361 +@param aForceOffscreen If ETrue, an offscreen buffer is used as the target instead of the screen. The
   1.362 +         dimensions of the buffer are retrieved from GetPixmapSizeInPixels.
   1.363 +*/
   1.364 +void CTe_graphicsperformanceSuiteStepBase::SetScreenModeL(TDisplayMode aScreenMode, TBool aForceOffscreen)
   1.365 +	{
   1.366 +	delete iScreenDevice;
   1.367 +	iScreenDevice = NULL;
   1.368 +
   1.369 +	iScreenDevice = CVirtualBitmapDevice::NewL(aScreenMode, aForceOffscreen);
   1.370 +	if (iScreenDevice->isScreenDevice())
   1.371 +		{
   1.372 +		INFO_PRINTF2(_L("SetScreenMode - supported: %S"),&ColorModeName(aScreenMode));
   1.373 +		}
   1.374 +	else
   1.375 +		{
   1.376 +		if (!aForceOffscreen)
   1.377 +			{
   1.378 +			INFO_PRINTF2(_L("SetScreenMode - not supported(using off screen bitmap instead): %S"),&ColorModeName(aScreenMode));
   1.379 +			}
   1.380 +		else
   1.381 +			{
   1.382 +			INFO_PRINTF2(_L("SetScreenMode - using off screen bitmap as requested: %S"),&ColorModeName(aScreenMode));
   1.383 +			}
   1.384 +		}
   1.385 +	delete iGc;
   1.386 +	iGc = NULL;
   1.387 +	User::LeaveIfError(iScreenDevice->CreateContext((CGraphicsContext*&)iGc));
   1.388 +	iScreenSize = iScreenDevice->SizeInPixels();
   1.389 +	}
   1.390 +
   1.391 +void CTe_graphicsperformanceSuiteStepBase::SetDrawDeviceModeL(TDisplayMode aScreenMode)
   1.392 +	{
   1.393 +	delete iDrawDevice;
   1.394 +	iDrawDevice = NULL;
   1.395 +
   1.396 +	iDrawDevice = CVirtualDrawDevice::NewL(aScreenMode);
   1.397 +	if (iDrawDevice->IsDrawDevice())
   1.398 +		{
   1.399 +		INFO_PRINTF2(_L("SetDrawDeviceMode - supported: %S"),&ColorModeName(aScreenMode));
   1.400 +		}
   1.401 +	else
   1.402 +		{
   1.403 +		INFO_PRINTF2(_L("SetDrawDeviceMode - not supported(using off screen bitmap instead): %S"),&ColorModeName(aScreenMode));
   1.404 +		}
   1.405 +	}
   1.406 +
   1.407 +TInt CTe_graphicsperformanceSuiteStepBase::GetDrawDeviceInterfaceL(TInt aInterfaceId, TAny*& aInterface)
   1.408 +	{
   1.409 +	User::LeaveIfNull(iDrawDevice);
   1.410 +	return iDrawDevice->DrawDevice().GetInterface(aInterfaceId, aInterface);	
   1.411 +	}
   1.412 +
   1.413 +void CTe_graphicsperformanceSuiteStepBase::ClearDrawDeviceL(TRgb aColor)
   1.414 +	{
   1.415 +	User::LeaveIfNull(iDrawDevice);
   1.416 +	CFbsDrawDevice& drawDevice = iDrawDevice->DrawDevice();
   1.417 +	TSize size = drawDevice.SizeInPixels();
   1.418 +	drawDevice.SetShadowMode(CFbsDrawDevice::ENoShadow);
   1.419 +	drawDevice.WriteRgbMulti(0,0,size.iWidth,size.iHeight,aColor,CGraphicsContext::EDrawModePEN);
   1.420 +	}
   1.421 +
   1.422 +/**
   1.423 +Creates a bitmap for given size and display mode and leaves it on the cleanup stack
   1.424 +
   1.425 +@return pointer to a created CFbsBitmap 
   1.426 +*/
   1.427 +CFbsBitmap* CTe_graphicsperformanceSuiteStepBase::CreateSoftwareBitmapLC(const TSize& aSize, TDisplayMode aMode)
   1.428 +	{
   1.429 +	CFbsBitmap* bitmap = new (ELeave) CFbsBitmap;
   1.430 +	CleanupStack::PushL(bitmap);
   1.431 +	User::LeaveIfError(bitmap->Create(aSize, aMode));
   1.432 +	return bitmap;
   1.433 +	}
   1.434 +	
   1.435 +/**
   1.436 +Copy a bitmap into another bitmap (generally in a different displaymode)
   1.437 +tiles destination bitmap with source
   1.438 +*/
   1.439 +void CTe_graphicsperformanceSuiteStepBase::CopyBitmapL(CFbsBitmap* aDst, CFbsBitmap* aSrc)
   1.440 +	{
   1.441 +	TSize srcSize = aSrc->SizeInPixels();
   1.442 +	TSize dstSize = aDst->SizeInPixels();
   1.443 +	CFbsBitmapDevice* dev = CFbsBitmapDevice::NewL(aDst);
   1.444 +	CleanupStack::PushL(dev);
   1.445 +	CFbsBitGc* gc = NULL;
   1.446 +	if ( 0 == dev->CreateContext(gc) )
   1.447 +		{
   1.448 +		CleanupStack::PushL(gc);
   1.449 +		TPoint point;
   1.450 +		gc->SetBrushColor(TRANSPARENT_BLACK);
   1.451 +		gc->SetBrushStyle(CGraphicsContext::ENullBrush);
   1.452 +		gc->SetDrawMode(CGraphicsContext::EDrawModeWriteAlpha);
   1.453 +		gc->Clear();
   1.454 +		gc->SetDrawMode(CGraphicsContext::EDrawModePEN);
   1.455 +		for(point.iY=0; point.iY<dstSize.iHeight; point.iY+=srcSize.iHeight)
   1.456 +			{
   1.457 +			for(point.iX=0; point.iX<dstSize.iWidth; point.iX+=srcSize.iWidth)
   1.458 +				{
   1.459 +				gc->BitBlt(point, aSrc);
   1.460 +				}
   1.461 +			}
   1.462 +		CleanupStack::PopAndDestroy(gc);
   1.463 +		}
   1.464 +	CleanupStack::PopAndDestroy(dev);
   1.465 +	}
   1.466 +
   1.467 +/**
   1.468 +Copy a source bitmap into a new bitmap with the specified display mode
   1.469 +*/
   1.470 +CFbsBitmap* CTe_graphicsperformanceSuiteStepBase::CopyIntoNewBitmapL(CFbsBitmap* aSrc, TDisplayMode aDisplayMode)
   1.471 +	{
   1.472 +	CFbsBitmap* dstBmp = new(ELeave) CFbsBitmap;
   1.473 +	CleanupStack::PushL(dstBmp);
   1.474 +	TInt ret=dstBmp->Create(aSrc->SizeInPixels(), aDisplayMode);
   1.475 +	User::LeaveIfError(ret);
   1.476 +	CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL(dstBmp);
   1.477 +	CleanupStack::PushL(bitmapDevice);
   1.478 +	CFbsBitGc* gc;
   1.479 +	ret = bitmapDevice->CreateContext(gc);
   1.480 +	User::LeaveIfError(ret);
   1.481 +	CleanupStack::PushL(gc);
   1.482 +	gc->BitBlt(TPoint(0,0), aSrc);
   1.483 +	CleanupStack::PopAndDestroy(2, bitmapDevice); // gc, bitmapDevice
   1.484 +	CleanupStack::Pop(dstBmp);
   1.485 +	return dstBmp;
   1.486 +	}
   1.487 +
   1.488 +/**
   1.489 +Loads a bitmap from a file
   1.490 +
   1.491 +@param aName the filename of the bitmap to load
   1.492 +@param aIndex the index of the bitmap to load in the file
   1.493 +*/
   1.494 +CFbsBitmap* CTe_graphicsperformanceSuiteStepBase::LoadBitmapL(const TDesC& aName, TInt aIndex)
   1.495 +	{
   1.496 +	CFbsBitmap* bitmap = new (ELeave) CFbsBitmap;
   1.497 +	CleanupStack::PushL(bitmap);
   1.498 +	User::LeaveIfError(bitmap->Load(aName, aIndex));
   1.499 +	CleanupStack::Pop(bitmap);
   1.500 +	return bitmap;
   1.501 +	}
   1.502 +
   1.503 +/**
   1.504 +Interpolates between the two TRgb values aHi and aLo including alpha channel, with the value aX and the denoinator aN
   1.505 +*/	
   1.506 +TRgb CTe_graphicsperformanceSuiteStepBase::InterpolateColour(TRgb aLo, TRgb aHi, TInt aX, TInt aN)
   1.507 +	{
   1.508 +	TInt y = aN - aX;
   1.509 +
   1.510 +	TUint8 a = (TUint8)( (aHi.Alpha()*aX + aLo.Alpha()*y)/aN );
   1.511 +	TUint8 r = (TUint8)( (aHi.Red()*aX + aLo.Red()*y)/aN );
   1.512 +	TUint8 g = (TUint8)( (aHi.Green()*aX + aLo.Green()*y)/aN );
   1.513 +	TUint8 b = (TUint8)( (aHi.Blue()*aX + aLo.Blue()*y)/aN );
   1.514 +	
   1.515 +	return TRgb(r, g, b, a);
   1.516 +	}
   1.517 +
   1.518 +/**
   1.519 +Draws a VerticalGradient onto a CFbsBitmap from top/color aLo to bottom/aHi
   1.520 +*/
   1.521 +void CTe_graphicsperformanceSuiteStepBase::VerticalGradientAlphaL(CFbsBitmap* aBitmap, TRgb aLo, TRgb aHi)
   1.522 +	{
   1.523 +	const TSize size = aBitmap->SizeInPixels();
   1.524 +	const TDisplayMode mode = aBitmap->DisplayMode();
   1.525 +	const TInt scanLineLength = CFbsBitmap::ScanLineLength(size.iWidth, mode);
   1.526 +	HBufC8* buffer = HBufC8::NewL(scanLineLength);
   1.527 +	CleanupStack::PushL(buffer);
   1.528 +	TPtr8 des = buffer->Des();
   1.529 +	des.SetLength(scanLineLength);
   1.530 +	for(TInt i=0; i<size.iHeight; i++)
   1.531 +		{
   1.532 +		TRgb color = InterpolateColour(aLo, aHi, i, size.iHeight);
   1.533 +		switch(mode)
   1.534 +			{
   1.535 +			case EGray256:
   1.536 +				{
   1.537 +				TUint8  g = color.Gray256();
   1.538 +				TUint8* p = (TUint8*)des.Ptr();
   1.539 +				for(TInt j=0; j<size.iWidth; j++)
   1.540 +					{						
   1.541 +					p[j] = g;
   1.542 +					}
   1.543 +				}
   1.544 +				break;
   1.545 +			case EColor64K:
   1.546 +				{
   1.547 +				TUint16  g = color._Color64K();
   1.548 +				TUint16* p = (TUint16*)des.Ptr();
   1.549 +				for(TInt j=0; j<size.iWidth/2; j++)
   1.550 +					{						
   1.551 +					p[j] = g;
   1.552 +					}
   1.553 +				}
   1.554 +				break;
   1.555 +			case EColor16MU:
   1.556 +				{
   1.557 +				TUint32 rgba = color._Color16MU();
   1.558 +				TUint32* p = (TUint32*)des.Ptr();
   1.559 +				for(TInt j=0; j<(size.iWidth/4); j++)
   1.560 +					{						
   1.561 +					p[j] = rgba;
   1.562 +					}
   1.563 +				}
   1.564 +				break;
   1.565 +			case EColor16MA:
   1.566 +				{
   1.567 +				TUint32 rgba = color._Color16MA();
   1.568 +				TUint32* p = (TUint32*)des.Ptr();
   1.569 +				for(TInt j=0; j<(size.iWidth/4); j++)
   1.570 +					{						
   1.571 +					p[j] = rgba;
   1.572 +					}
   1.573 +				}
   1.574 +				break;
   1.575 +			case EColor16MAP:
   1.576 +				{
   1.577 +				TUint32 rgba = color._Color16MAP();
   1.578 +				TUint32* p = (TUint32*)des.Ptr();
   1.579 +				for(TInt j=0; j<(size.iWidth/4); j++)
   1.580 +					{						
   1.581 +					p[j] = rgba;
   1.582 +					}
   1.583 +				}
   1.584 +				break;
   1.585 +			default:
   1.586 +				ASSERT(EFalse);
   1.587 +				break;
   1.588 +			}
   1.589 +		aBitmap->SetScanLine(des, i);
   1.590 +		}
   1.591 +	CleanupStack::PopAndDestroy(buffer);
   1.592 +	}
   1.593 +
   1.594 +/**
   1.595 +Create a checked board
   1.596 +@param aPixelFormat The pixel format for create the target bitmap
   1.597 +@param aSize The size of the bitmap
   1.598 +@param aChecksPerAxis Number of checks on X and Y.
   1.599 + */
   1.600 +CFbsBitmap* CTe_graphicsperformanceSuiteStepBase::CreateCheckedBoardL(TDisplayMode aDisplayMode, TSize aSize, TSize aChecksPerAxis) const
   1.601 +	{
   1.602 +	
   1.603 +	CFbsBitmap* bitmap = new (ELeave) CFbsBitmap;
   1.604 +	CleanupStack::PushL(bitmap);
   1.605 +	bitmap->Create(aSize, aDisplayMode);
   1.606 +	
   1.607 +	CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL(bitmap);
   1.608 +	CleanupStack::PushL(bitmapDevice);
   1.609 +	
   1.610 +	CFbsBitGc* bitGc = NULL;
   1.611 +	User::LeaveIfError(bitmapDevice->CreateContext(bitGc));
   1.612 +	CleanupStack::PushL(bitGc);
   1.613 +	
   1.614 +	bitGc->Clear();
   1.615 +	bitGc->SetBrushStyle(CGraphicsContext::ESolidBrush);
   1.616 +	bitGc->SetPenStyle(CGraphicsContext::ENullPen);
   1.617 +	TPoint point(0,0);
   1.618 +	const TSize checkerSize((TReal)aSize.iWidth/aChecksPerAxis.iWidth,(TReal)aSize.iHeight/aChecksPerAxis.iHeight);
   1.619 +	TInt brushColour = 0;
   1.620 +	for(point.iY = 0; point.iY < aSize.iHeight; point.iY += checkerSize.iHeight)
   1.621 +		{
   1.622 +		for(point.iX = 0; point.iX < aSize.iWidth; point.iX += checkerSize.iWidth)
   1.623 +			{
   1.624 +			bitGc->SetBrushColor(KColor16Table[brushColour++ & 0x0F]);
   1.625 +			TRect rect(point, checkerSize);
   1.626 +			bitGc->DrawRect(rect);
   1.627 +			}
   1.628 +		}
   1.629 +	
   1.630 +	CleanupStack::PopAndDestroy(2, bitmapDevice);
   1.631 +	CleanupStack::Pop(bitmap);
   1.632 +	
   1.633 +	return bitmap;
   1.634 +	}
   1.635 +
   1.636 +/* 
   1.637 +Creates a new CFbsBitmap representing the screen/off-screen bitmap. It is the client's
   1.638 +responsibility to delete it.
   1.639 +
   1.640 +@see CTDirectGdiTestBase::GetTargetAsBitmapL.
   1.641 +@return A pointer to the newly created bitmap.
   1.642 +@leave If there was a problem copying from the source to the target.
   1.643 +*/
   1.644 +CFbsBitmap* CTe_graphicsperformanceSuiteStepBase::GetTargetAsBitmapL()
   1.645 +	{
   1.646 +	iScreenDevice->Update();
   1.647 +	CFbsBitmap* bitmapCopy = CopyIntoNewBitmapL(&(iScreenDevice->Bitmap()), iScreenDevice->BitmapDevice().DisplayMode());
   1.648 +	return bitmapCopy;
   1.649 +	}
   1.650 +
   1.651 +/**
   1.652 +Creates an mbm file showing the state of the target.
   1.653 +
   1.654 +@param aName The name of the mbm file to produce. Any spaces are replaced by underscores
   1.655 +             for easier parsing.
   1.656 +@return KErrNone if bitmap output has been turned off in the config file, or if it was successful.
   1.657 +        KErrNoMemory if there is not enough memory to create the bitmap.
   1.658 +*/
   1.659 +TInt CTe_graphicsperformanceSuiteStepBase::WriteTargetOutput(TPtrC aName)
   1.660 +	{
   1.661 +	if (!iShowBitmaps)
   1.662 +		{
   1.663 +		return KErrNone;
   1.664 +		}
   1.665 +	
   1.666 +	CFbsBitmap* target = NULL;
   1.667 +	TRAPD(err, target = GetTargetAsBitmapL();)
   1.668 +	
   1.669 +	if (err != KErrNone)
   1.670 +		{
   1.671 +		return err;
   1.672 +		}
   1.673 +
   1.674 +	TBuf<KMaxFileName> fileName;
   1.675 +	fileName.Append(aName);
   1.676 +	
   1.677 +	// replace spaces with underscores.
   1.678 +	TInt pos = fileName.Locate(TChar(' '));
   1.679 +	while(pos != KErrNotFound)
   1.680 +		{
   1.681 +		fileName[pos] = TChar('_');
   1.682 +		pos = fileName.Locate(TChar(' '));
   1.683 +		}	
   1.684 +
   1.685 +	TFileName mbmFile;
   1.686 +	mbmFile.Append(KBitmapDrive);
   1.687 +	mbmFile.AppendFormat(KBitmapPath, &fileName);
   1.688 +		
   1.689 +	err = target->Save(mbmFile);
   1.690 +	delete target;	
   1.691 +	return err;
   1.692 +	}
   1.693 +
   1.694 +
   1.695 +
   1.696 +void CTe_graphicsperformanceSuiteStepBase::ExtractListL(TPtrC aList, RArray<TPtrC>& aListItems)
   1.697 +    {
   1.698 +    TPtrC tempBuf = aList;
   1.699 +    TInt position = tempBuf.Find(_L(","));
   1.700 +            
   1.701 +    while(position != KErrNotFound)
   1.702 +        {
   1.703 +        aListItems.AppendL(tempBuf.Left(position));
   1.704 +        tempBuf.Set(tempBuf.Mid(position + 2));
   1.705 +        position = tempBuf.Find(_L(","));
   1.706 +        }   
   1.707 +
   1.708 +    if (position == KErrNotFound)
   1.709 +        {
   1.710 +        aListItems.AppendL(tempBuf);
   1.711 +        }
   1.712 +    }
   1.713 +