Update contrib.
1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
19 @internalComponent - Internal Symbian test code
22 #include "tdirectgditestbase.h"
24 #include <graphics/directgdidriver.h>
25 #include <graphics/directgdiextensioninterfaces.h>
26 #ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
27 #include <graphics/sgimage_sw.h>
29 TSize GetDisplaySizeInPixels();
31 #ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
32 // Cache size in bytes for DirectGDI Image cache.
33 const TInt KDirectGdiImageCacheSize = 0x400000;
36 #ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
39 Implementation of CTestStep base class virtual.
40 Used to implement all DirectGDI-specific initialisation for any derived test-cases, and
41 reads settings from the configuration file.
42 It will leave if there are any failures as DirectGDI must be initialised correctly for
43 the tests to be run. The leave will be picked up by the framework.
45 @leave If initialisation of DirectGDI failed.
46 @return EPass if successful, otherwise a TVerdict error code.
48 TVerdict CTDirectGdiTestBase::doTestStepPreambleL()
50 CTe_graphicsperformanceSuiteStepBase::doTestStepPreambleL();
52 TPtrC targetPixelFormatInput;
53 TEST(GetStringFromConfig(_L("PixelFormats"), _L("TargetPixelFormatEnums"), targetPixelFormatInput));
54 TDisplayModeMapping::ConvertPixelFormats(targetPixelFormatInput, iTargetPixelFormatArray);
56 TPtrC sourcePixelFormatInput;
57 TEST(GetStringFromConfig(_L("PixelFormats"), _L("SourcePixelFormatEnums"), sourcePixelFormatInput));
58 TDisplayModeMapping::ConvertPixelFormats(sourcePixelFormatInput, iSourcePixelFormatArray);
60 InitializeDirectGdiL();
61 return TestStepResult();
65 Implementation of CTestStep base class virtual
66 Used for doing all post-test treatment common to derived DirectGDI classes, such as
67 shutting down DirectGDI.
69 @leave If there was a failure shutting down DirectGDI.
70 @return EPass if successful, otherwise a TVerdict error code.
72 TVerdict CTDirectGdiTestBase::doTestStepPostambleL()
74 iTargetPixelFormatArray.Close();
75 iSourcePixelFormatArray.Close();
76 UninitializeDirectGdi();
77 return CTe_graphicsperformanceSuiteStepBase::doTestStepPostambleL();
79 #endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
81 CTDirectGdiTestBase::~CTDirectGdiTestBase()
85 CTDirectGdiTestBase::CTDirectGdiTestBase()
90 Sets up DirectGDI for use in the test cases.
92 @leave If any failures occur initialising DirectGDI.
94 void CTDirectGdiTestBase::InitializeDirectGdiL()
96 #ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
99 TESTNOERRORL(CDirectGdiDriver::Open());
100 iDGdiDriver = CDirectGdiDriver::Static();
101 if (iDGdiDriver == NULL)
102 User::Leave(KErrNoMemory);
104 // If using the DirectGDI OpenVG adapter, set a large image cache size to optimize performance.
105 MDirectGdiDriverCacheSize* cacheInterface = NULL;
106 if (KErrNone == iDGdiDriver->GetInterface(TUid::Uid(KDirectGdiDriverCacheSizeUid), (TAny*&)cacheInterface))
108 cacheInterface->SetMaxImageCacheSize(KDirectGdiImageCacheSize);
111 iDGdiImageTarget = new (ELeave) RDirectGdiImageTarget(*iDGdiDriver);
113 // Set up most of RSgImage image info to be used for target
114 iImageInfo.iSizeInPixels = GetPixmapSizeInPixels();
115 iImageInfo.iUsage = ESgUsageDirectGdiTarget;
117 iTs = CFbsTypefaceStore::NewL(NULL);
118 TESTNOERRORL(iTs->GetNearestFontToDesignHeightInPixels((CFont *&)iFont, TFontSpec(KFontTypeface, KFontSize)));
119 TESTNOERRORL(iTs->GetNearestFontToDesignHeightInPixels((CFont *&)iLargeFont,TFontSpec(KFontTypeface, 40)));
124 Shuts down DirectGDI when test cases have finished.
126 void CTDirectGdiTestBase::UninitializeDirectGdi()
130 if (iDGdiImageTarget)
132 iDGdiImageTarget->Close();
133 delete iDGdiImageTarget;
134 iDGdiImageTarget = NULL;
138 iDGdiDriver->Close();
140 #ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
141 iSgImageTarget.Close();
143 iTs->ReleaseFont(iFont);
144 iTs->ReleaseFont(iLargeFont);
147 #ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
153 Initialises a target and a DirectGDI Gc.
155 @param aPixelFormat The pixel format to be used for the target.
156 @return ETrue if the target supports the display mode, EFalse otherwise.
158 #ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
159 TBool CTDirectGdiTestBase::SetTargetPixelFormatL(TDisplayMode aDisplayMode)
161 TUidPixelFormat pixelFormat = TDisplayModeMapping::MapDisplayModeToPixelFormat(aDisplayMode);
162 TInt numSupportedFormats = 0;
163 RSgImage::GetPixelFormats(iImageInfo,NULL,numSupportedFormats);
164 TUidPixelFormat* supportedFormats = new (ELeave) TUidPixelFormat[numSupportedFormats];
165 RSgImage::GetPixelFormats(iImageInfo,supportedFormats,numSupportedFormats);
166 TBool supported = EFalse;
167 for (TInt ii = numSupportedFormats-1; ii >=0; --ii)
169 if(supportedFormats[ii] == pixelFormat)
175 delete[] supportedFormats;
179 INFO_PRINTF2(_L("SetTargetPixelFormat - supported: %S"),&ColorModeName(aDisplayMode));
183 INFO_PRINTF2(_L("SetTargetPixelFormat - not supported: %S"),&ColorModeName(aDisplayMode));
189 TESTL(iDGdiImageTarget != NULL);
190 iDGdiImageTarget->Close();
191 iSgImageTarget.Close();
193 iImageInfo.iPixelFormat = pixelFormat;
194 TESTNOERRORL(iSgImageTarget.Create(iImageInfo, NULL,0));
195 iContext = CDirectGdiContext::NewL (*iDGdiDriver);
196 TESTL(iContext != NULL);
197 TESTNOERRORL(iDGdiDriver->GetError());
198 if (KErrNone == iDGdiImageTarget->Create(iSgImageTarget))
200 // Activate the context on a rendering target.
201 TESTNOERRORL(iDGdiDriver->GetError());
202 iContext->Activate(*iDGdiImageTarget);
204 TESTNOERRORL(iDGdiDriver->GetError());
208 TBool CTDirectGdiTestBase::SetTargetPixelFormatL(TDisplayMode /*aDisplayMode*/)
215 Creates a new CFbsBitmap representing the RSgImage. It is down to the client to delete it.
217 @see CTDirectGdiTestBase::GetTargetAsBitmapL()
218 @return A pointer to the newly created bitmap.
219 @leave If there was a problem copying from the source to the target.
221 CFbsBitmap* CTDirectGdiTestBase::GetTargetAsBitmapL()
223 #ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
224 iDGdiDriver->Finish();
226 CFbsBitmap* bitmap = new (ELeave) CFbsBitmap();
227 CleanupStack::PushL(bitmap);
228 TESTNOERRORL(bitmap->Create(iImageInfo.iSizeInPixels, TDisplayModeMapping::MapPixelFormatToDisplayMode(iImageInfo.iPixelFormat)));
230 const TInt bitmapDataStride = bitmap->DataStride();
231 const TInt numScanlines = iImageInfo.iSizeInPixels.iHeight;
233 MSgImage_Sw* sgImageDirectAccess;
234 TESTNOERRORL(iSgImageTarget.GetInterface(sgImageDirectAccess));
236 const TInt sgImageDataStride = sgImageDirectAccess->DataStride();
237 sgImageDirectAccess->BeginDataAccess(ESgCpuAccessReadOnly);
238 TUint32* sgImageDataAddress = (TUint32*)(sgImageDirectAccess->DataAddress());
239 bitmap->BeginDataAccess();
240 TUint32* bitmapDataAddress = bitmap->DataAddress();
241 for (TInt scanline = 0; scanline < numScanlines; ++scanline)
243 Mem::Copy((TUint8*)bitmapDataAddress + (scanline*bitmapDataStride), (TUint8*)sgImageDataAddress + (scanline*sgImageDataStride), bitmapDataStride);
245 bitmap->EndDataAccess();
246 sgImageDirectAccess->EndDataAccess();
248 CleanupStack::Pop(1, bitmap);