sl@0: // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // sl@0: sl@0: #include "tdirectgdi_test_step_base.h" sl@0: #include sl@0: sl@0: //These reference and test bitmaps are used for image comparison sl@0: //These are saved at sl@0: _LIT(KRefPath, "\\img\\ref\\%S.mbm"); sl@0: _LIT(KTestPath, "\\img\\test\\%S.mbm"); sl@0: sl@0: //The default image cache size to use for the tests. sl@0: const TInt KDriverImageCacheSizeTests = 0x400000; sl@0: sl@0: /** sl@0: Position iterator constructor. sl@0: @param aStartX Start x position. sl@0: @param aEndX End x position. sl@0: @param aStepX Step for x position. sl@0: @param aStartY Start y position. sl@0: @param aEndY End y position. sl@0: @param aStepY Step for y position. sl@0: */ sl@0: TPositionIterator::TPositionIterator(TInt aStartX, TInt aEndX, TInt aStepX, sl@0: TInt aStartY, TInt aEndY, TInt aStepY) : sl@0: iStartX(aStartX), iEndX(aEndX), iStepX(aStepX), sl@0: iStartY(aStartY), iEndY(aEndY), iStepY(aStepY), sl@0: iPosX(aStartX), iPosY(aStartY), iIndexX(0), iIndexY(0) sl@0: { sl@0: } sl@0: sl@0: /** sl@0: Begin iteration. sl@0: All needed variables are initialized to start iteration. sl@0: */ sl@0: void TPositionIterator::Begin() sl@0: { sl@0: iPosX = iStartX; sl@0: iPosY = iStartY; sl@0: iIndexX = 0; sl@0: iIndexY = 0; sl@0: } sl@0: sl@0: /** sl@0: Next iteration. sl@0: Generates next position and position indices. sl@0: @return EFalse is returned if end of iterations else ETrue. sl@0: */ sl@0: TBool TPositionIterator::Next() sl@0: { sl@0: if(iPosX < iEndX) sl@0: { sl@0: iPosX += iStepX; sl@0: iIndexX++; sl@0: return ETrue; sl@0: } sl@0: else sl@0: { sl@0: if(iPosY < iEndY) sl@0: { sl@0: iPosX = iStartX; sl@0: iIndexX = 0; sl@0: iPosY += iStepY; sl@0: iIndexY++; sl@0: return ETrue; sl@0: } sl@0: else sl@0: { sl@0: return EFalse; sl@0: } sl@0: } sl@0: } sl@0: sl@0: CBitmapDevice* CTImageTarget::BitmapDevice() const sl@0: { sl@0: return iBitmapDevice; sl@0: } sl@0: sl@0: /** sl@0: Create a new bitgdi target sl@0: @param aPixelFormat The pixel format for the target sl@0: @param aSize The size of the target to create sl@0: @return On return, contains a pointer to a bitgdi target object sl@0: */ sl@0: CTBitGdiTarget* CTBitGdiTarget::NewL(TUidPixelFormat aPixelFormat, const TSize& aSize) sl@0: { sl@0: CTBitGdiTarget* self = new(ELeave) CTBitGdiTarget(); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aPixelFormat, aSize); sl@0: CleanupStack::Pop(); // self sl@0: return self; sl@0: } sl@0: sl@0: /** sl@0: Second phase constructor of CTBitGdiTarget. Creates a bitmap for use as a target. sl@0: @param aPixelFormat The pixel format for the target to be created sl@0: @param aSize The size of the target to be created sl@0: */ sl@0: void CTBitGdiTarget::ConstructL(TUidPixelFormat aPixelFormat, const TSize& aSize) sl@0: { sl@0: // create a bitmap sl@0: iBitmap = new(ELeave) CFbsBitmap; sl@0: iBitmap->Create(aSize, TDisplayModeMapping::MapPixelFormatToDisplayMode(aPixelFormat)); sl@0: // create an off screen bitmap device sl@0: iBitmapDevice = CFbsBitmapDevice::NewL(iBitmap); sl@0: } sl@0: sl@0: /** sl@0: Create a bitgdi context sl@0: @param aGc A pointer to the created graphics context sl@0: @param aActivate ETrue to create and activate the context aGc, EFalse to just create it. sl@0: @return On return, contains a pointer to the created bitgdi context sl@0: */ sl@0: TInt CTBitGdiTarget::CreateContext(CTContextBase*& aGc, TBool aActivate) sl@0: { sl@0: TInt result = KErrGeneral; sl@0: TRAP(result, aGc = CTBitGdiContext::NewL((CFbsBitmapDevice*)iBitmapDevice, aActivate)); sl@0: return result; sl@0: } sl@0: sl@0: /** sl@0: Sets the object to draw to a particular device sl@0: @param aGc A pointer to the created graphics context sl@0: */ sl@0: TInt CTBitGdiTarget::Activate(CTContextBase*& aGc) sl@0: { sl@0: CTBitGdiContext* gc = (CTBitGdiContext*)aGc; sl@0: // Activate the context on a rendering target. sl@0: return gc->Activate(iBitmapDevice); sl@0: } sl@0: /** sl@0: Get the size of the device area in pixels sl@0: @return On return, The width and height of the target, in pixels sl@0: */ sl@0: TSize CTBitGdiTarget::SizeInPixels() const sl@0: { sl@0: return iBitmapDevice->SizeInPixels(); sl@0: } sl@0: sl@0: sl@0: /** sl@0: Get a target FBsBitmap sl@0: @return The target FBsBitmap sl@0: */ sl@0: CFbsBitmap* CTBitGdiTarget::GetTargetFbsBitmapL() sl@0: { sl@0: return iBitmap; sl@0: } sl@0: sl@0: /** sl@0: Nothing to be implemented for BitGdi Finish() sl@0: */ sl@0: void CTBitGdiTarget::Finish () sl@0: { sl@0: } sl@0: sl@0: sl@0: void CTBitGdiTarget::Close() sl@0: { sl@0: } sl@0: sl@0: sl@0: /** sl@0: Destructor of CTBitGdiTarget sl@0: */ sl@0: CTBitGdiTarget::~CTBitGdiTarget() sl@0: { sl@0: delete iBitmapDevice; sl@0: delete iBitmap; sl@0: } sl@0: sl@0: /** sl@0: Default constructor. sl@0: */ sl@0: CTDirectGdiTarget::CTDirectGdiTarget() sl@0: { sl@0: } sl@0: sl@0: /** sl@0: Create a new directgdi target sl@0: @param aPixelFormat The pixel format for the target sl@0: @param aSize The size of the target to create sl@0: @return On return, contains a pointer to a directgdi target object sl@0: */ sl@0: CTDirectGdiTarget* CTDirectGdiTarget::NewL(TUidPixelFormat aPixelFormat, const TSize& aSize) sl@0: { sl@0: CTDirectGdiTarget* self = new(ELeave) CTDirectGdiTarget(); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aPixelFormat, aSize); sl@0: CleanupStack::Pop(); // self sl@0: return self; sl@0: } sl@0: /** sl@0: Second phase constructor of CTDirectGdiTarget sl@0: @param aPixelFormat The pixel format for the target sl@0: @param aSize The size of the target to create sl@0: */ sl@0: void CTDirectGdiTarget::ConstructL(TUidPixelFormat aPixelFormat, const TSize& aSize) sl@0: { sl@0: // open the driver sl@0: User::LeaveIfError(CDirectGdiDriver::Open()); sl@0: iDGdiDriver = CDirectGdiDriver::Static(); sl@0: if (iDGdiDriver == NULL) sl@0: User::Leave(KErrNoMemory); sl@0: sl@0: // set a large cache size (if available to do so) so the tests execute more quickly. sl@0: MDirectGdiDriverCacheSize* driverCacheInterface = NULL; sl@0: if (KErrNone == iDGdiDriver->GetInterface(TUid::Uid(KDirectGdiDriverCacheSizeUid), (TAny*&)driverCacheInterface)) sl@0: { sl@0: User::LeaveIfError(driverCacheInterface->SetMaxImageCacheSize(KDriverImageCacheSizeTests)); sl@0: } sl@0: sl@0: iDGdiImageTarget = new (ELeave) RDirectGdiImageTarget(*iDGdiDriver); sl@0: // create a bitmap which is used to save the image data from an RSgImage to a file. sl@0: iBitmap = new(ELeave) CFbsBitmap; sl@0: User::LeaveIfError(iBitmap->Create(aSize, TDisplayModeMapping::MapPixelFormatToDisplayMode(aPixelFormat))); sl@0: iBitmapDevice = CFbsBitmapDevice::NewL(iBitmap); sl@0: // Set up image attributes sl@0: iImageInfo.iSizeInPixels = aSize; sl@0: iImageInfo.iPixelFormat = aPixelFormat; sl@0: iImageInfo.iUsage = ESgUsageDirectGdiTarget; sl@0: User::LeaveIfError(iRSgImage.Create(iImageInfo, NULL,0)); sl@0: User::LeaveIfError(iDGdiImageTarget->Create(iRSgImage)); sl@0: } sl@0: sl@0: sl@0: /** sl@0: Create a Direct GDI graphics context. sl@0: sl@0: @param aGc A reference to a pointer to the created graphics context. If return is anything sl@0: other than KErrNone then aGc is set to NULL. sl@0: @param aActivate ETrue to create and activate the context aGc, EFalse to just create it. sl@0: sl@0: @return KErrNone, if successful; otherwise, another of the system-wide error codes. sl@0: */ sl@0: TInt CTDirectGdiTarget::CreateContext(CTContextBase*& aGc, TBool aActivate) sl@0: { sl@0: TInt result = KErrGeneral; sl@0: sl@0: aGc = NULL; sl@0: sl@0: TRAP(result, aGc = CTestDirectGdiContext::NewL()); sl@0: CTestDirectGdiContext* gc = (CTestDirectGdiContext*)aGc; sl@0: sl@0: // If the GC is not NULL, make sure the return code indicates sl@0: // success. sl@0: if (aActivate && aGc) sl@0: { sl@0: if(result != KErrNone) sl@0: { sl@0: return result; sl@0: } sl@0: else sl@0: { sl@0: // Activate the context on a rendering target. sl@0: result = gc->Activate(*iDGdiImageTarget); sl@0: } sl@0: } sl@0: return result; sl@0: } sl@0: sl@0: /** sl@0: Sets the object to draw to a particular device sl@0: @param aGc A pointer to the created graphics context sl@0: */ sl@0: TInt CTDirectGdiTarget::Activate(CTContextBase*& aGc) sl@0: { sl@0: CTestDirectGdiContext* gc = (CTestDirectGdiContext*)aGc; sl@0: // Activate the context on a rendering target. sl@0: return gc->Activate(*iDGdiImageTarget); sl@0: } sl@0: sl@0: /** sl@0: Get the size of the device area in pixels sl@0: @return On return, The width and height of the target, in pixels sl@0: */ sl@0: TSize CTDirectGdiTarget::SizeInPixels() const sl@0: { sl@0: return iImageInfo.iSizeInPixels; sl@0: } sl@0: sl@0: /** sl@0: Get a target FBsBitmap. sl@0: @return The target FBsBitmap sl@0: */ sl@0: CFbsBitmap* CTDirectGdiTarget::GetTargetFbsBitmapL() sl@0: { sl@0: // Create a copy of the RSgImage that is CPU-accessible for mapping. sl@0: RSgImage cpuAccessibleImage; sl@0: TSgImageInfo imageInfo; sl@0: imageInfo.iSizeInPixels = iImageInfo.iSizeInPixels; sl@0: imageInfo.iPixelFormat = iImageInfo.iPixelFormat; sl@0: imageInfo.iCpuAccess = ESgCpuAccessReadOnly; sl@0: User::LeaveIfError(cpuAccessibleImage.Create(imageInfo, iRSgImage)); sl@0: CleanupClosePushL(cpuAccessibleImage); sl@0: sl@0: iBitmap->BeginDataAccess(); sl@0: const TInt bitmapDataStride = iBitmap->DataStride(); sl@0: const TInt numScanlines = imageInfo.iSizeInPixels.iHeight; sl@0: const TAny* sgImageDataAddress; sl@0: TInt sgImageDataStride = 0; sl@0: sl@0: User::LeaveIfError(cpuAccessibleImage.MapReadOnly(sgImageDataAddress, sgImageDataStride)); sl@0: sl@0: TUint32* bitmapDataAddress = iBitmap->DataAddress(); sl@0: for (TInt scanline = 0; scanline < numScanlines; ++scanline) sl@0: { sl@0: Mem::Copy((TUint8*)bitmapDataAddress + (scanline*bitmapDataStride), (TUint8*)sgImageDataAddress + (scanline*sgImageDataStride), bitmapDataStride); sl@0: } sl@0: iBitmap->EndDataAccess(); sl@0: cpuAccessibleImage.Unmap(); sl@0: sl@0: CleanupStack::PopAndDestroy(1); sl@0: sl@0: return iBitmap; sl@0: } sl@0: sl@0: /** sl@0: Force completion of all batched rendering operations. Will not return sl@0: until rendering is complete. sl@0: sl@0: @pre Fully initialised image target. sl@0: */ sl@0: void CTDirectGdiTarget::Finish () sl@0: { sl@0: if (iDGdiDriver) sl@0: iDGdiDriver->Finish(); sl@0: } sl@0: sl@0: sl@0: void CTDirectGdiTarget::Close() sl@0: { sl@0: if (iDGdiImageTarget) sl@0: iDGdiImageTarget->Close(); sl@0: } sl@0: sl@0: /** sl@0: Destructor of CTDirectGdiTarget sl@0: */ sl@0: CTDirectGdiTarget::~CTDirectGdiTarget() sl@0: { sl@0: delete iBitmapDevice; sl@0: delete iBitmap; sl@0: if (iDGdiImageTarget) sl@0: { sl@0: iDGdiImageTarget->Close(); sl@0: delete iDGdiImageTarget; sl@0: } sl@0: if (iDGdiDriver) sl@0: iDGdiDriver->Close(); sl@0: iRSgImage.Close(); sl@0: } sl@0: sl@0: /** sl@0: Implementation of CTestStep base class virtual sl@0: It is used for doing all common initialisation to derived classes. sl@0: Make it being able to leave sl@0: The leave will be picked up by the framework. sl@0: @leave Gets system wide error code sl@0: @return - TVerdict code sl@0: */ sl@0: TVerdict CTDirectGdiStepBase::doTestStepPreambleL() sl@0: { sl@0: SetTestStepResult(EPass); sl@0: sl@0: // Create and install Active Scheduler in case tests require active objects sl@0: iScheduler = new(ELeave) CActiveScheduler; sl@0: CActiveScheduler::Install(iScheduler); sl@0: sl@0: TPtrC targetPixelFormatInput; sl@0: TPtrC sourcePixelFormatInput; sl@0: TPtrC sourceResourcePixelFormatInput; sl@0: sl@0: // get input for tests from .ini file sl@0: _LIT(KDirectgdiTestInput, "DirectgdiTestInput"); sl@0: _LIT(KTargetPixelFormatEnums, "TargetPixelFormatEnums "); sl@0: _LIT(KSourcePixelFormatEnums, "SourcePixelFormatEnums "); sl@0: _LIT(KSourceResourcePixelFormatEnums, "SourceResourcePixelFormatEnums "); sl@0: _LIT(KDoRefImg, "DoRefImg"); sl@0: _LIT(KDoDirectGdi, "DoDirectGdi"); sl@0: _LIT(KRunOomTests, "RunOomTests"); sl@0: TEST(GetStringFromConfig(KDirectgdiTestInput, KTargetPixelFormatEnums, targetPixelFormatInput)); sl@0: TEST(GetStringFromConfig(KDirectgdiTestInput, KSourcePixelFormatEnums, sourcePixelFormatInput)); sl@0: TEST(GetStringFromConfig(KDirectgdiTestInput, KSourceResourcePixelFormatEnums, sourceResourcePixelFormatInput)); sl@0: TEST(GetIntFromConfig(KDirectgdiTestInput, KDoRefImg, iMakeRefImg)); sl@0: TEST(GetIntFromConfig(KDirectgdiTestInput, KDoDirectGdi, iUseDirectGdi)); sl@0: TEST(GetIntFromConfig(KDirectgdiTestInput, KRunOomTests, iDoOomTests)); sl@0: #ifndef _DEBUG sl@0: if(iDoOomTests) sl@0: { sl@0: iDoOomTests = EFalse; sl@0: 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: } sl@0: #endif sl@0: sl@0: ConvertPixelFormats(targetPixelFormatInput, iTargetPixelFormatArray); sl@0: ConvertPixelFormats(sourcePixelFormatInput, iSourcePixelFormatArray); sl@0: ConvertPixelFormats(sourceResourcePixelFormatInput, iSourceResourcePixelFormatArray); sl@0: iRunningOomTests = EFalse; sl@0: sl@0: Logger().ShareAuto(); sl@0: sl@0: __UHEAP_MARK; sl@0: User::LeaveIfError(SgDriver::Open()); sl@0: User::LeaveIfError(RFbsSession::Connect()); sl@0: sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: /** sl@0: Convert the pixel format strings to pixel format enums sl@0: @param aPixelFormatInput The pixel format string for testing sl@0: @param aPixelFormatArray The array of converted pixel formats is returned here sl@0: */ sl@0: void CTDirectGdiStepBase::ConvertPixelFormats(TPtrC aPixelFormatInput, RArray& aPixelFormatArray) sl@0: { sl@0: TPtrC tempBuf = aPixelFormatInput; sl@0: TInt position = tempBuf.Find(_L(",")); sl@0: sl@0: while(KErrNotFound != position) sl@0: { sl@0: aPixelFormatArray.Append(TDisplayModeMapping::ConvertPixelFormatStringToPixelFormat(tempBuf.Left(position))); sl@0: tempBuf.Set(tempBuf.Mid(position + 2)); sl@0: position = tempBuf.Find(_L(",")); sl@0: } sl@0: sl@0: if (position == KErrNotFound) sl@0: { sl@0: aPixelFormatArray.Append(TDisplayModeMapping::ConvertPixelFormatStringToPixelFormat(tempBuf)); sl@0: } sl@0: } sl@0: sl@0: /** sl@0: Implementation of CTestStep base class virtual sl@0: It is used for doing all after test treatment common to derived classes in here. sl@0: Make it being able to leave sl@0: The leave will be picked up by the framework. sl@0: @leave Gets system wide error code sl@0: @return - TVerdict sl@0: */ sl@0: TVerdict CTDirectGdiStepBase::doTestStepPostambleL() sl@0: { sl@0: if(iFontStore) sl@0: { sl@0: if(iFontId) sl@0: { sl@0: iFontStore->RemoveFile(iFontId); sl@0: iFontId = 0; sl@0: } sl@0: delete iFontStore; sl@0: iFontStore = NULL; sl@0: } sl@0: delete iGc; sl@0: iGc = NULL; sl@0: delete iGc2; sl@0: iGc2 = NULL; sl@0: delete iGdiTarget; sl@0: iGdiTarget = NULL; sl@0: delete iGdiTarget2; sl@0: iGdiTarget2 = NULL; sl@0: SgDriver::Close(); sl@0: RFbsSession::Disconnect(); sl@0: __UHEAP_MARKEND; sl@0: delete iScheduler; sl@0: iScheduler = NULL; sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: CTDirectGdiStepBase::~CTDirectGdiStepBase() sl@0: { sl@0: if(iFontStore) sl@0: { sl@0: if(iFontId) sl@0: { sl@0: iFontStore->RemoveFile(iFontId); sl@0: } sl@0: delete iFontStore; sl@0: } sl@0: delete iScheduler; sl@0: delete iGc; sl@0: delete iGc2; sl@0: delete iGdiTarget; sl@0: delete iGdiTarget2; sl@0: iTargetPixelFormatArray.Close(); sl@0: iSourcePixelFormatArray.Close(); sl@0: iSourceResourcePixelFormatArray.Close(); sl@0: } sl@0: sl@0: CTDirectGdiStepBase::CTDirectGdiStepBase() sl@0: { sl@0: } sl@0: sl@0: /** sl@0: Create a name in the format of _< TestCase Name >___ sl@0: @param aParams A structure object of parameters to be passed through sl@0: @param aTestName The test name to be generated sl@0: @param aTestCaseName The test case name passed in, to be used in the resultant filename sl@0: @param aNamePostfix If this is not NULL, it is appended to filename with an underscore in front of it sl@0: */ sl@0: void CTDirectGdiStepBase::CreateFileName(TTestParams& aParams, TDes& aTestName, TPtrC& aTestCaseName, TDesC* aNamePostfix) sl@0: { sl@0: if (iUseDirectGdi) sl@0: { sl@0: aTestName.Append(KDirectGc); sl@0: } sl@0: else sl@0: { sl@0: aTestName.Append(KBitGc); sl@0: } sl@0: sl@0: if (aParams.iDoCompressed) sl@0: { sl@0: aTestName.Append(KSeparator); sl@0: aTestName.Append(KCom); sl@0: } sl@0: sl@0: aTestName.Append(KSeparator); sl@0: aTestName.Append(aTestCaseName); sl@0: aTestName.Append(KSeparator); sl@0: aTestName.Append(KTargetString); sl@0: aTestName.Append(KSeparator); sl@0: aTestName.Append(TDisplayModeMapping::ConvertPixelFormatToShortPixelFormatString(aParams.iTargetPixelFormat)); sl@0: sl@0: if (aNamePostfix) sl@0: { sl@0: aTestName.Append(KSeparator); sl@0: aTestName.Append(*aNamePostfix); sl@0: } sl@0: } sl@0: sl@0: /** sl@0: @see DisplayTargetImageL(TUidPixelFormat, CTImageTarget*) sl@0: */ sl@0: void CTDirectGdiStepBase::DisplayTargetImageL(TUidPixelFormat aPixelFormat) sl@0: { sl@0: DisplayTargetImageL(aPixelFormat, iGdiTarget); sl@0: } sl@0: sl@0: /** sl@0: Bitblt an image to screen sl@0: @param aPixelFormat The pixel format for tests sl@0: @param aGdiTarget The target image to blit sl@0: */ sl@0: void CTDirectGdiStepBase::DisplayTargetImageL(TUidPixelFormat aPixelFormat, CTImageTarget* aGdiTarget) sl@0: { sl@0: // Ensure the image has been completly rendered. sl@0: aGdiTarget->Finish(); sl@0: CFbsScreenDevice* screenDevice = CFbsScreenDevice::NewL(_L("scdv"), TDisplayModeMapping::MapPixelFormatToDisplayMode(aPixelFormat)); sl@0: TEST(screenDevice!=NULL); sl@0: CleanupStack::PushL(screenDevice); sl@0: sl@0: CFbsBitGc* bitGc; sl@0: screenDevice->CreateContext(bitGc); sl@0: TEST(bitGc!=NULL); sl@0: CleanupStack::PushL(bitGc); sl@0: sl@0: TPoint startPoint = TPoint(0, 0); sl@0: bitGc->Clear(); sl@0: bitGc->BitBlt(startPoint, aGdiTarget->GetTargetFbsBitmapL()); sl@0: screenDevice->Update(); sl@0: sl@0: CleanupStack::PopAndDestroy(2, screenDevice); sl@0: } sl@0: sl@0: /** sl@0: Initialises a target (or targets) and a graphics context (or contexts), depending on the value passed in aCase. sl@0: Deletes the previously used target(s) and context(s). sl@0: @param aPixelFormat The pixel format to be applied sl@0: @param aCase The type of test that this target is for, for example when testing with one context and two targets sl@0: this could be EOneContextTwoTargets_SamePixelType, the default value is EOneContextOneTarget. sl@0: @param aSize The size of the target(s) to be created sl@0: */ sl@0: void CTDirectGdiStepBase::SetTargetL(TUidPixelFormat aPixelFormat, const TContextTestCase aCase, const TSize& aSize) sl@0: { sl@0: if(!iRunningOomTests) sl@0: { sl@0: TBuf pixelFormatName(TDisplayModeMapping::ConvertPixelFormatToPixelFormatString(aPixelFormat)); sl@0: INFO_PRINTF4(_L("SetTarget (using off screen bitmap): %S %dx%d"), &pixelFormatName, aSize.iWidth, aSize.iHeight); sl@0: } sl@0: sl@0: delete iGc; sl@0: iGc = NULL; sl@0: delete iGc2; sl@0: iGc2 = NULL; sl@0: delete iGdiTarget; sl@0: iGdiTarget = NULL; sl@0: delete iGdiTarget2; sl@0: iGdiTarget2 = NULL; sl@0: TUidPixelFormat aPixelFormat2 = aPixelFormat; sl@0: switch(aPixelFormat) sl@0: { sl@0: case EUidPixelFormatRGB_565: sl@0: aPixelFormat2 = EUidPixelFormatARGB_8888_PRE; sl@0: break; sl@0: case EUidPixelFormatARGB_8888_PRE: sl@0: aPixelFormat2 = EUidPixelFormatXRGB_8888; sl@0: break; sl@0: case EUidPixelFormatXRGB_8888: sl@0: aPixelFormat2 = EUidPixelFormatRGB_565; sl@0: break; sl@0: } sl@0: sl@0: switch(aCase) sl@0: { sl@0: case EOneContextOneTarget: sl@0: { sl@0: if(iUseDirectGdi) sl@0: { sl@0: iGdiTarget = CTDirectGdiTarget::NewL(aPixelFormat, aSize); sl@0: } sl@0: else sl@0: { sl@0: iGdiTarget = CTBitGdiTarget::NewL(aPixelFormat, aSize); sl@0: } sl@0: User::LeaveIfError(iGdiTarget->CreateContext(iGc)); sl@0: } sl@0: break; sl@0: case EOneContextTwoTargets_SamePixelType: sl@0: { sl@0: if(iUseDirectGdi) sl@0: { sl@0: iGdiTarget = CTDirectGdiTarget::NewL(aPixelFormat, aSize); sl@0: iGdiTarget2 = CTDirectGdiTarget::NewL(aPixelFormat, aSize); sl@0: } sl@0: else sl@0: { sl@0: iGdiTarget = CTBitGdiTarget::NewL(aPixelFormat, aSize); sl@0: iGdiTarget2 = CTBitGdiTarget::NewL(aPixelFormat, aSize); sl@0: } sl@0: User::LeaveIfError(iGdiTarget->CreateContext(iGc)); sl@0: } sl@0: break; sl@0: case EOneContextTwoTargets_DifferentPixelType: sl@0: { sl@0: if(iUseDirectGdi) sl@0: { sl@0: iGdiTarget = CTDirectGdiTarget::NewL(aPixelFormat, aSize); sl@0: iGdiTarget2 = CTDirectGdiTarget::NewL(aPixelFormat2, aSize); sl@0: } sl@0: else sl@0: { sl@0: iGdiTarget = CTBitGdiTarget::NewL(aPixelFormat, aSize); sl@0: iGdiTarget2 = CTBitGdiTarget::NewL(aPixelFormat2, aSize); sl@0: } sl@0: User::LeaveIfError(iGdiTarget->CreateContext(iGc)); sl@0: } sl@0: break; sl@0: case ETwoContextsOneTarget: sl@0: { sl@0: if(iUseDirectGdi) sl@0: { sl@0: iGdiTarget = CTDirectGdiTarget::NewL(aPixelFormat, aSize); sl@0: } sl@0: else sl@0: { sl@0: iGdiTarget = CTBitGdiTarget::NewL(aPixelFormat, aSize); sl@0: } sl@0: User::LeaveIfError(iGdiTarget->CreateContext(iGc, EFalse)); sl@0: User::LeaveIfError(iGdiTarget->CreateContext(iGc2, EFalse)); sl@0: } sl@0: break; sl@0: case ETwoContextsTwoTargets_WithoutSharing_SamePixelType: sl@0: case ETwoContextsTwoTargets_WithSharing_SamePixelType: sl@0: { sl@0: if(iUseDirectGdi) sl@0: { sl@0: iGdiTarget = CTDirectGdiTarget::NewL(aPixelFormat, aSize); sl@0: iGdiTarget2 = CTDirectGdiTarget::NewL(aPixelFormat, aSize); sl@0: } sl@0: else sl@0: { sl@0: iGdiTarget = CTBitGdiTarget::NewL(aPixelFormat, aSize); sl@0: iGdiTarget2 = CTBitGdiTarget::NewL(aPixelFormat, aSize); sl@0: } sl@0: User::LeaveIfError(iGdiTarget->CreateContext(iGc, EFalse)); sl@0: User::LeaveIfError(iGdiTarget2->CreateContext(iGc2, EFalse)); sl@0: } sl@0: break; sl@0: case ETwoContextsTwoTargets_WithoutSharing_DifferentPixelType: sl@0: case ETwoContextsTwoTargets_WithSharing_DifferentPixelType: sl@0: { sl@0: if(iUseDirectGdi) sl@0: { sl@0: iGdiTarget = CTDirectGdiTarget::NewL(aPixelFormat, aSize); sl@0: iGdiTarget2 = CTDirectGdiTarget::NewL(aPixelFormat2, aSize); sl@0: } sl@0: else sl@0: { sl@0: iGdiTarget = CTBitGdiTarget::NewL(aPixelFormat, aSize); sl@0: iGdiTarget2 = CTBitGdiTarget::NewL(aPixelFormat2, aSize); sl@0: } sl@0: User::LeaveIfError(iGdiTarget->CreateContext(iGc, EFalse)); sl@0: User::LeaveIfError(iGdiTarget2->CreateContext(iGc2, EFalse)); sl@0: } sl@0: break; sl@0: case EOneContextOneTarget_TwiceActivate: sl@0: { sl@0: if(iUseDirectGdi) sl@0: { sl@0: iGdiTarget = CTDirectGdiTarget::NewL(aPixelFormat, aSize); sl@0: } sl@0: else sl@0: { sl@0: iGdiTarget = CTBitGdiTarget::NewL(aPixelFormat, aSize); sl@0: } sl@0: User::LeaveIfError(iGdiTarget->CreateContext(iGc)); sl@0: } sl@0: break; sl@0: } sl@0: sl@0: // setup font store sl@0: if(iFontStore) sl@0: { sl@0: if(iFontId) sl@0: { sl@0: iFontStore->RemoveFile(iFontId); sl@0: iFontId = 0; sl@0: } sl@0: delete iFontStore; sl@0: iFontStore = NULL; sl@0: } sl@0: sl@0: iFontStore = CFbsTypefaceStore::NewL(iGdiTarget->BitmapDevice()); sl@0: sl@0: _LIT(KEonFontFileName,"z:\\resource\\fonts\\eon14.gdr"); sl@0: TESTL(KErrNone == iFontStore->AddFile(KEonFontFileName, iFontId)); sl@0: sl@0: // Reset VGImage cache - OpenVG DirectGDI only sl@0: iVgImageCache = NULL; sl@0: if (iUseDirectGdi) sl@0: { sl@0: TInt err = iGc->GetInterface(TUid::Uid(KDirectGdiVgImageCacheUid), (TAny*&) iVgImageCache); sl@0: if (KErrNotSupported == err) sl@0: { sl@0: // Must be using software DirectGDI as this does not have a VGImage cache sl@0: iUseSwDirectGdi = ETrue; sl@0: } sl@0: } sl@0: } sl@0: sl@0: /** sl@0: Get a font by looking for it in the font store. Only gets "DejaVu Sans Mono" at the moment. sl@0: @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: */ sl@0: CFont* CTDirectGdiStepBase::GetFont() sl@0: { sl@0: _LIT(KFontFamily, "DejaVu Sans Mono"); sl@0: sl@0: CFont* font = NULL; sl@0: TFontSpec spec(KFontFamily, 13); sl@0: iFontStore->GetNearestFontInPixels(font, spec); sl@0: return font; sl@0: } sl@0: sl@0: /** sl@0: Releases the passed font in the font store. sl@0: @param aFont A pointer to the font to be released. sl@0: */ sl@0: void CTDirectGdiStepBase::ReleaseFont(CFont* aFont) sl@0: { sl@0: if(aFont && iFontStore) sl@0: { sl@0: iFontStore->ReleaseFont(aFont); sl@0: } sl@0: } sl@0: sl@0: /** sl@0: Create a file and save the target image to the file with a filename created from aTestCaseName and aNamePostfix sl@0: @param aParams A structure object of parameters to be passed through sl@0: @param aTestCaseName The name of the test case sl@0: @param aImageTarget The image target to be written out to the file sl@0: @param aNamePostfix A postfix to be appended to the test case name sl@0: @see CreateFileName() sl@0: @return KErrNone if successful, one of the system wide error codes otherwise sl@0: */ sl@0: TInt CTDirectGdiStepBase::WriteTargetOutput(TTestParams& aParams, TPtrC aTestCaseName, CTImageTarget* aImageTarget, TDesC* aNamePostfix) sl@0: { sl@0: // Finish is called for the OOM tests as well as the normal tests as it is responsible for sl@0: // clearing up the pending image array. Images get left in the array and cause the OOM tests sl@0: // for DrawResource to fail if Finish is not called. sl@0: aImageTarget->Finish(); sl@0: sl@0: if(!iRunningOomTests) // don't want to save test images when running our of memory twsts sl@0: { sl@0: TBuf testFileName; sl@0: CreateFileName(aParams, testFileName, aTestCaseName, aNamePostfix); sl@0: TFileName mbmFile; sl@0: TBuf testPathName; sl@0: #ifdef __WINS__ sl@0: testPathName.Append(_L("c:")); sl@0: #else sl@0: testPathName.Append(_L("e:")); sl@0: #endif sl@0: sl@0: if (iMakeRefImg) sl@0: { sl@0: testPathName.Append(KRefPath); sl@0: mbmFile.Format(testPathName, &testFileName); sl@0: } sl@0: else sl@0: { sl@0: testPathName.Append(KTestPath); sl@0: mbmFile.Format(testPathName, &testFileName); sl@0: } sl@0: INFO_PRINTF1(testFileName); sl@0: sl@0: CFbsBitmap* targetBitmap = NULL; sl@0: TRAPD(err, targetBitmap = aImageTarget->GetTargetFbsBitmapL()); sl@0: return (err != KErrNone) ? err : targetBitmap->Save(mbmFile); sl@0: } sl@0: return KErrNone; sl@0: } sl@0: sl@0: /** sl@0: Create a file and save the current target image to the file with a filename created from aTestCaseName and aNamePostfix sl@0: @param aParams A structure object of parameters to be passed through sl@0: @param aTestCaseName The name of the test case sl@0: @param aNamePostfix A postfix to be appended to the test case name sl@0: @see CreateFileName() sl@0: @return KErrNone if successful, one of the system wide error codes otherwise sl@0: */ sl@0: TInt CTDirectGdiStepBase::WriteTargetOutput(TTestParams& aParams, TPtrC aTestCaseName, TDesC* aNamePostfix) sl@0: { sl@0: return WriteTargetOutput(aParams, aTestCaseName, iGdiTarget, aNamePostfix); sl@0: } sl@0: sl@0: /** sl@0: Reset the graphics context sl@0: */ sl@0: void CTDirectGdiStepBase::ResetGc() sl@0: { sl@0: iGc->Reset(); sl@0: iGc->Clear(); sl@0: } sl@0: sl@0: /** sl@0: Compares the target image pixel by pixel against the given colour. If a pixel with a sl@0: different colour than aColour is found then the test will fail, otherwise the test will pass. sl@0: @param aColour A colour rgba value to find. sl@0: @return ETrue if test passed or EFalse if test failed. sl@0: */ sl@0: TBool CTDirectGdiStepBase::TestTargetL(const TRgb& aColour) sl@0: { sl@0: iGdiTarget->Finish(); sl@0: sl@0: CFbsBitmap* bitmap = iGdiTarget->GetTargetFbsBitmapL(); sl@0: TInt width = bitmap->SizeInPixels().iWidth; sl@0: TInt height = bitmap->SizeInPixels().iHeight; sl@0: sl@0: HBufC8* lineBuf = HBufC8::NewLC(width*4); sl@0: TPtr8 linePtr(lineBuf->Des()); sl@0: sl@0: TBool pass = ETrue; sl@0: sl@0: for(TInt line=0; lineGetScanLine(linePtr, TPoint(0, line), width, EColor16MA); sl@0: sl@0: const TUint8* pPtr = linePtr.Ptr(); sl@0: for(TInt x=0; xGetError() == aDirectGdiErrorCode, aFile, aLine); sl@0: } sl@0: else sl@0: { sl@0: TESTWITHFILENAMEANDLINENUMBERL(iGc->GetError() == aBitGdiErrorCode, aFile, aLine); sl@0: } sl@0: } sl@0: sl@0: /** sl@0: Derived classes should override this method and add their calls to individual test cases in sl@0: the overridden version. sl@0: */ sl@0: void CTDirectGdiStepBase::RunTestsL() sl@0: { sl@0: } sl@0: sl@0: /** sl@0: Runs the tests in RunTestsL checking for Out of Memory conditions and testing for memory leaks. sl@0: */ sl@0: void CTDirectGdiStepBase::RunOomTestsL() sl@0: { sl@0: if (!iDoOomTests) sl@0: { sl@0: // don't run the out of memory tests sl@0: return; sl@0: } sl@0: TInt tryCount = 0; sl@0: INFO_PRINTF1(_L("*****Running Out Of Memory Tests*****")); sl@0: sl@0: // save the current state of test step results sl@0: TVerdict currentTestStepResult = TestStepResult(); sl@0: sl@0: FOREVER sl@0: { sl@0: iRunningOomTests = ETrue; sl@0: TInt err = KErrNone; sl@0: sl@0: // count cells so we can know how many we leaked sl@0: TInt cellsStart = User::CountAllocCells(); sl@0: sl@0: __UHEAP_FAILNEXT(++tryCount); sl@0: __UHEAP_MARK; sl@0: sl@0: TRAP(err, RunTestsL()); sl@0: sl@0: TBool finishedCorrectly = EFalse; sl@0: if ((err == KErrNone)) sl@0: { sl@0: // claims to have finished correctly, and we're not failing every alloc sl@0: finishedCorrectly = CheckForHeapFailNext(); sl@0: } sl@0: __UHEAP_RESET; sl@0: TInt cellsEnd = User::CountAllocCells(); sl@0: if (cellsStart < cellsEnd) sl@0: { sl@0: // leaked. sl@0: TInt leakedCells = cellsEnd - cellsStart; sl@0: ERR_PRINTF3(_L("On loop number %d we leaked %d cells. About to cause panic."),tryCount,leakedCells); sl@0: } sl@0: __UHEAP_MARKEND; sl@0: sl@0: // check to see if we finished all OOM testing successfully sl@0: if ((err == KErrNone) && finishedCorrectly) sl@0: { sl@0: INFO_PRINTF2(_L(" - Test completed successfully after %d iterations."),tryCount); sl@0: break; sl@0: } sl@0: } sl@0: // restore test step result and ignore any test failures the out of memory tests produce sl@0: SetTestStepResult(currentTestStepResult); sl@0: iRunningOomTests = EFalse; sl@0: } sl@0: sl@0: /** sl@0: Tests that the passed condition aCondition is equal to ETrue and reports an error if it is not. sl@0: This method does not report errors when the tests are running in OOM mode. sl@0: @see testBooleanTrue() sl@0: @param aCondition The boolean value to be checked for being equal to ETrue sl@0: @param aFile The filename to use when reporting the error sl@0: @param aLine The line number to use when reporting the error sl@0: */ sl@0: void CTDirectGdiStepBase::testBooleanTrue(TBool aCondition, const TText8* aFile, TInt aLine) sl@0: { sl@0: if(!iRunningOomTests) sl@0: { sl@0: CTestStep::testBooleanTrue(aCondition, aFile, aLine, ETrue); sl@0: } sl@0: } sl@0: sl@0: /** sl@0: A leaving version of testBooleanTrue(). sl@0: @see testBooleanTrue() sl@0: */ sl@0: void CTDirectGdiStepBase::testBooleanTrueL(TBool aCondition, const TText8* aFile, TInt aLine) sl@0: { sl@0: if(!iRunningOomTests) sl@0: { sl@0: CTestStep::testBooleanTrueL(aCondition, aFile, aLine, ETrue); sl@0: } sl@0: else sl@0: { sl@0: if(!aCondition) sl@0: { sl@0: User::Leave(TEST_ERROR_CODE); sl@0: } sl@0: } sl@0: } sl@0: sl@0: /** sl@0: A version of testBooleanTrue() that additionally writes an error code to the output if aCondition is not equal to ETrue. sl@0: @see testBooleanTrue() sl@0: @param aCondition The boolean value to be checked for being equal to ETrue sl@0: @param aErrorCode An error code to be reported if aCondition is EFalse sl@0: @param aFile The filename to use when reporting the error sl@0: @param aLine The line number to use when reporting the error sl@0: */ sl@0: void CTDirectGdiStepBase::testBooleanTrueWithErrorCode(TBool aCondition, TInt aErrorCode, const TText8* aFile, TInt aLine) sl@0: { sl@0: if(!iRunningOomTests) sl@0: { sl@0: if(!aCondition) sl@0: { sl@0: SetTestStepResult(EFail); sl@0: _LIT(KMessage,"Test Failed with error [%d]"); sl@0: Logger().LogExtra(aFile, aLine, ESevrErr, KMessage, aErrorCode); sl@0: } sl@0: } sl@0: } sl@0: sl@0: /** sl@0: A leaving version of testBooleanTrueWithErrorCode() sl@0: @see testBooleanTrueWithErrorCode() sl@0: @param aCondition The boolean value to be checked for being equal to ETrue sl@0: @param aErrorCode An error code to be reported if aCondition is EFalse sl@0: @param aFile The filename to use when reporting the error sl@0: @param aLine The line number to use when reporting the error sl@0: */ sl@0: void CTDirectGdiStepBase::testBooleanTrueWithErrorCodeL(TBool aCondition, TInt aErrorCode, const TText8* aFile, TInt aLine) sl@0: { sl@0: if(!iRunningOomTests) sl@0: { sl@0: testBooleanTrueWithErrorCode(aCondition, aErrorCode, aFile, aLine); sl@0: } sl@0: else sl@0: { sl@0: if(!aCondition) sl@0: { sl@0: User::Leave(aErrorCode); sl@0: } sl@0: } sl@0: } sl@0: sl@0: /** sl@0: Creates a CFbsBitmap that has a pattern of differently coloured concentric rectangles on it for use in test cases. sl@0: @param aPixelFormat The pixel format for create the target bitmap sl@0: @param aSize The size of the bitmap to be created sl@0: */ sl@0: CFbsBitmap* CTDirectGdiStepBase::CreateConcentricRectsBitmapL(TUidPixelFormat aPixelFormat, const TSize& aSize) sl@0: { sl@0: CFbsBitmap* bitmap = new (ELeave) CFbsBitmap; sl@0: CleanupStack::PushL(bitmap); sl@0: sl@0: TESTNOERRORL(bitmap->Create(aSize, TDisplayModeMapping::MapPixelFormatToDisplayMode(aPixelFormat))); sl@0: sl@0: CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL(bitmap); sl@0: TESTL(bitmapDevice!=NULL); sl@0: CleanupStack::PushL(bitmapDevice); sl@0: sl@0: CFbsBitGc* bitGc = NULL; sl@0: User::LeaveIfError(bitmapDevice->CreateContext(bitGc)); sl@0: TESTL(bitGc!=NULL); sl@0: CleanupStack::PushL(bitGc); sl@0: sl@0: for (TInt i = aSize.iWidth/2; i>0; --i) sl@0: { sl@0: bitGc->SetPenColor(KColor16Table[i%16]); sl@0: bitGc->DrawRect(TRect(i,i,aSize.iWidth - i, aSize.iHeight - i)); sl@0: } sl@0: sl@0: CleanupStack::PopAndDestroy(2, bitmapDevice); sl@0: CleanupStack::Pop(bitmap); sl@0: sl@0: return bitmap; sl@0: } sl@0: sl@0: /** sl@0: Creates a bitmap that contains a checked board pattern of coloured rectangles for use in test cases. sl@0: @param aPixelFormat The pixel format for create the target bitmap sl@0: @param aSize The size of the bitmap sl@0: @param aChecksPerAxis Number of checks on X and Y. sl@0: @param aGenAlpha If ETrue then generate pattern in alpha channel. sl@0: */ sl@0: CFbsBitmap* CTDirectGdiStepBase::CreateCheckedBoardBitmapL(TUidPixelFormat aPixelFormat, sl@0: const TSize& aSize, const TSize& aChecksPerAxis, TBool aGenAlpha) sl@0: { sl@0: sl@0: CFbsBitmap* bitmap = new (ELeave) CFbsBitmap; sl@0: CleanupStack::PushL(bitmap); sl@0: TESTNOERRORL(bitmap->Create(aSize, TDisplayModeMapping::MapPixelFormatToDisplayMode(aPixelFormat))); sl@0: sl@0: CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL(bitmap); sl@0: CleanupStack::PushL(bitmapDevice); sl@0: TESTL(bitmapDevice!=NULL); sl@0: sl@0: CFbsBitGc* bitGc = NULL; sl@0: User::LeaveIfError(bitmapDevice->CreateContext(bitGc)); sl@0: CleanupStack::PushL(bitGc); sl@0: TESTL(bitGc!=NULL); sl@0: sl@0: bitGc->Clear(); sl@0: bitGc->SetBrushStyle(CGraphicsContext::ESolidBrush); sl@0: bitGc->SetPenStyle(CGraphicsContext::ENullPen); sl@0: if(aGenAlpha) sl@0: { sl@0: bitGc->SetDrawMode(CGraphicsContext::EDrawModeWriteAlpha); sl@0: } sl@0: TPoint point(0,0); sl@0: const TSize checkerSize(aSize.iWidth/aChecksPerAxis.iWidth,aSize.iHeight/aChecksPerAxis.iHeight); sl@0: TInt brushColour = 0x00; sl@0: for(point.iY = 0; point.iY < aSize.iHeight; point.iY += checkerSize.iHeight) sl@0: { sl@0: for(point.iX = 0; point.iX < aSize.iWidth; point.iX += checkerSize.iWidth) sl@0: { sl@0: TRgb colour = KColor16Table[brushColour++ & 0x0F]; sl@0: if(aGenAlpha) sl@0: { sl@0: // Note that this is converted internally to pre-multiplied alpha sl@0: // for pre-multiplied alpha targets. sl@0: colour.SetAlpha((brushColour*5) & 255); sl@0: sl@0: //Use the following line to simplify test for manual verification. sl@0: //colour.SetAlpha(0x80); sl@0: } sl@0: bitGc->SetBrushColor(colour); sl@0: TRect rect(point, checkerSize); sl@0: bitGc->DrawRect(rect); sl@0: } sl@0: } sl@0: CleanupStack::PopAndDestroy(2, bitmapDevice); sl@0: CleanupStack::Pop(bitmap); sl@0: sl@0: return bitmap; sl@0: } sl@0: sl@0: /** sl@0: Create a black and white checked bitmap sl@0: @param aPixelFormat The pixel format to use when creating the target bitmap sl@0: @param aSize The size of the bitmap to create sl@0: @param aChecksPerAxis Number of checks to draw in the X and Y directions sl@0: @param aIsHardwareBitmap If ETrue, creates a hardware CFbsBitmap. sl@0: */ sl@0: CFbsBitmap* CTDirectGdiStepBase::CreateBlackWhiteBitmapL(TUidPixelFormat aPixelFormat, sl@0: const TSize& aSize, const TSize& aChecksPerAxis) sl@0: { sl@0: CFbsBitmap* bitmap = new (ELeave) CFbsBitmap; sl@0: CleanupStack::PushL(bitmap); sl@0: sl@0: TESTNOERRORL(bitmap->Create(aSize, TDisplayModeMapping::MapPixelFormatToDisplayMode(aPixelFormat))); sl@0: sl@0: CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL(bitmap); sl@0: CleanupStack::PushL(bitmapDevice); sl@0: TESTL(bitmapDevice!=NULL); sl@0: sl@0: CFbsBitGc* bitGc = NULL; sl@0: bitmapDevice->CreateContext(bitGc); sl@0: CleanupStack::PushL(bitGc); sl@0: TESTL(bitGc!=NULL); sl@0: sl@0: bitGc->Clear(); sl@0: bitGc->SetBrushStyle(CGraphicsContext::ESolidBrush); sl@0: bitGc->SetPenStyle(CGraphicsContext::ENullPen); sl@0: TPoint point(0,0); sl@0: const TSize checkerSize(aSize.iWidth/aChecksPerAxis.iWidth,aSize.iHeight/aChecksPerAxis.iHeight); sl@0: for(point.iY = 0; point.iY < aSize.iHeight; point.iY += checkerSize.iHeight) sl@0: { sl@0: TBool isBlack = ETrue; sl@0: for(point.iX = 0; point.iX < aSize.iWidth; point.iX += checkerSize.iWidth) sl@0: { sl@0: if(isBlack) sl@0: bitGc->SetBrushColor(KRgbBlack); sl@0: else sl@0: bitGc->SetBrushColor(KRgbWhite); sl@0: TRect rect(point, checkerSize); sl@0: bitGc->DrawRect(rect); sl@0: isBlack = EFalse; sl@0: } sl@0: } sl@0: CleanupStack::PopAndDestroy(2, bitmapDevice); sl@0: CleanupStack::Pop(bitmap); sl@0: return bitmap; sl@0: } sl@0: sl@0: /** sl@0: Create a bitmap designed for masking tests. sl@0: @param aPixelFormat The pixel format to use when creating the bitmap sl@0: @param aSize The size of the bitmap to create sl@0: */ sl@0: CFbsBitmap* CTDirectGdiStepBase::CreateMaskingPixmapL ( sl@0: TUidPixelFormat aPixelFormat, sl@0: const TSize& aSize) sl@0: { sl@0: sl@0: CFbsBitmap* bitmap = new (ELeave) CFbsBitmap; sl@0: CleanupStack::PushL(bitmap); sl@0: TESTL(KErrNone == bitmap->Create(aSize, TDisplayModeMapping::MapPixelFormatToDisplayMode(aPixelFormat))); sl@0: sl@0: CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL(bitmap); sl@0: CleanupStack::PushL(bitmapDevice); sl@0: TESTL(bitmapDevice!=NULL); sl@0: sl@0: CFbsBitGc* bitGc = NULL; sl@0: bitmapDevice->CreateContext(bitGc); sl@0: CleanupStack::PushL(bitGc); sl@0: TESTL(bitGc!=NULL); sl@0: sl@0: bitGc->Clear(); sl@0: bitGc->SetBrushStyle(CGraphicsContext::ESolidBrush); sl@0: bitGc->SetPenStyle(CGraphicsContext::ENullPen); sl@0: sl@0: bitGc->SetBrushColor(TRgb(0x808080)); sl@0: TRect rect(aSize); sl@0: bitGc->DrawRect(rect); sl@0: sl@0: bitGc->SetBrushColor(TRgb(0x202020)); sl@0: TRect rect2(0, 0, aSize.iWidth, aSize.iHeight>>2); sl@0: bitGc->DrawRect(rect2); sl@0: sl@0: TRect rect3(0, 0, aSize.iWidth>>3, aSize.iHeight); sl@0: bitGc->DrawRect(rect3); sl@0: sl@0: CleanupStack::PopAndDestroy(2, bitmapDevice); sl@0: CleanupStack::Pop(bitmap); sl@0: return bitmap; sl@0: } sl@0: sl@0: /** sl@0: Stack cleanup helper function to use when the cache needs to be reset sl@0: from the cleanup stack. sl@0: This method calls MVgImageCache::ResetCache() on the passed MVgImageCache object sl@0: @param aPtr A pointer to an image cache object, MVgImageCache*, to be reset sl@0: */ sl@0: void CTDirectGdiStepBase::ResetCache(TAny* aPtr) sl@0: { sl@0: MVgImageCache* cache = reinterpret_cast (aPtr); sl@0: cache->ResetCache(); sl@0: } sl@0: sl@0: /** sl@0: Stack cleanup helper function to use when the pen size needs to be reset to (1,1) sl@0: from the cleanup stack. This is needed when SetPenSize() is called when testing the sl@0: DirectGdi SW version as setting a pen size other then (1,1) causes memory to be sl@0: created that is not freed until SetPenSize(1,1) is called (or the related graphics sl@0: engine is destroyed). sl@0: This method calls CTContextBase::SetPenSize(1,1) on the passed CTContextBase object sl@0: @param aPtr A pointer to a test context object, CTContextBase*. sl@0: */ sl@0: void CTDirectGdiStepBase::ResetPenSize(TAny* aPtr) sl@0: { sl@0: if (CTContextBase* context = reinterpret_cast (aPtr)) sl@0: context->SetPenSize(TSize(1,1)); sl@0: }