os/graphics/graphicstest/uibench/src/tdirectgditestbase.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 /**
    17  @file
    18  @test
    19  @internalComponent - Internal Symbian test code 
    20 */
    21 
    22 #include "tdirectgditestbase.h"
    23 
    24 #include <graphics/directgdidriver.h>
    25 #include <graphics/directgdiextensioninterfaces.h>
    26 #ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
    27 #include <graphics/sgimage_sw.h>
    28 #endif
    29 TSize GetDisplaySizeInPixels();
    30 
    31 #ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
    32 // Cache size in bytes for DirectGDI Image cache.
    33 const TInt KDirectGdiImageCacheSize = 0x400000;
    34 #endif
    35 
    36 #ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
    37 
    38 /**
    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.
    44 
    45 @leave If initialisation of DirectGDI failed.
    46 @return EPass if successful, otherwise a TVerdict error code.
    47 */
    48 TVerdict CTDirectGdiTestBase::doTestStepPreambleL()
    49 	{
    50 	CTe_graphicsperformanceSuiteStepBase::doTestStepPreambleL();
    51 	
    52 	TPtrC targetPixelFormatInput;
    53 	TEST(GetStringFromConfig(_L("PixelFormats"), _L("TargetPixelFormatEnums"), targetPixelFormatInput));
    54 	TDisplayModeMapping::ConvertPixelFormats(targetPixelFormatInput, iTargetPixelFormatArray);
    55 
    56 	TPtrC sourcePixelFormatInput;
    57 	TEST(GetStringFromConfig(_L("PixelFormats"), _L("SourcePixelFormatEnums"), sourcePixelFormatInput));
    58 	TDisplayModeMapping::ConvertPixelFormats(sourcePixelFormatInput, iSourcePixelFormatArray);
    59 	
    60 	InitializeDirectGdiL();	
    61 	return TestStepResult();
    62 	}
    63 
    64 /**
    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.
    68 
    69 @leave If there was a failure shutting down DirectGDI.
    70 @return EPass if successful, otherwise a TVerdict error code.
    71 */
    72 TVerdict CTDirectGdiTestBase::doTestStepPostambleL()
    73 	{
    74 	iTargetPixelFormatArray.Close();
    75 	iSourcePixelFormatArray.Close();
    76 	UninitializeDirectGdi();
    77 	return CTe_graphicsperformanceSuiteStepBase::doTestStepPostambleL();
    78 	}
    79 #endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
    80 
    81  CTDirectGdiTestBase::~CTDirectGdiTestBase()
    82 	{
    83 	}
    84 
    85 CTDirectGdiTestBase::CTDirectGdiTestBase()
    86 	{
    87 	}
    88 
    89 /**
    90 Sets up DirectGDI for use in the test cases.
    91 
    92 @leave If any failures occur initialising DirectGDI.
    93 */
    94 void CTDirectGdiTestBase::InitializeDirectGdiL()
    95 	{
    96 #ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
    97 	SgDriver::Open();
    98 		
    99 	TESTNOERRORL(CDirectGdiDriver::Open());
   100 	iDGdiDriver = CDirectGdiDriver::Static();
   101 	if (iDGdiDriver == NULL)
   102 		User::Leave(KErrNoMemory);
   103 	
   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))
   107 		{
   108 		cacheInterface->SetMaxImageCacheSize(KDirectGdiImageCacheSize);
   109 		}
   110 	
   111 	iDGdiImageTarget = new (ELeave) RDirectGdiImageTarget(*iDGdiDriver);
   112 			
   113 	// Set up most of RSgImage image info to be used for target
   114 	iImageInfo.iSizeInPixels = GetPixmapSizeInPixels();
   115 	iImageInfo.iUsage = ESgUsageDirectGdiTarget;
   116 	
   117 	iTs = CFbsTypefaceStore::NewL(NULL);	
   118 	TESTNOERRORL(iTs->GetNearestFontToDesignHeightInPixels((CFont *&)iFont, TFontSpec(KFontTypeface, KFontSize)));
   119 	TESTNOERRORL(iTs->GetNearestFontToDesignHeightInPixels((CFont *&)iLargeFont,TFontSpec(KFontTypeface, 40)));	
   120 #endif
   121 	}
   122 
   123 /**
   124 Shuts down DirectGDI when test cases have finished.
   125 */
   126 void CTDirectGdiTestBase::UninitializeDirectGdi()
   127 	{	
   128 	delete iContext;
   129 	iContext = NULL;
   130 	if (iDGdiImageTarget)
   131 		{
   132 		iDGdiImageTarget->Close();	
   133 		delete iDGdiImageTarget;
   134 		iDGdiImageTarget = NULL;
   135 		}
   136 	if (iDGdiDriver)
   137 		{
   138 		iDGdiDriver->Close();
   139 		}
   140 #ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
   141 	iSgImageTarget.Close();
   142 #endif
   143 	iTs->ReleaseFont(iFont);
   144 	iTs->ReleaseFont(iLargeFont);
   145 	delete iTs;
   146 	iTs = NULL;
   147 #ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
   148 	SgDriver::Close();
   149 #endif
   150 	}
   151 
   152  /**
   153 Initialises a target and a DirectGDI Gc.
   154 
   155 @param aPixelFormat The pixel format to be used for the target.
   156 @return ETrue if the target supports the display mode, EFalse otherwise.
   157 */
   158 #ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
   159 TBool CTDirectGdiTestBase::SetTargetPixelFormatL(TDisplayMode aDisplayMode)
   160 	{
   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)
   168 		{
   169 		if(supportedFormats[ii] == pixelFormat)
   170 			{
   171 			supported = ETrue;
   172 			break;
   173 			}
   174 		}
   175 	delete[] supportedFormats;
   176 
   177 	if (supported)
   178 		{
   179 		INFO_PRINTF2(_L("SetTargetPixelFormat - supported: %S"),&ColorModeName(aDisplayMode));
   180 		}
   181 	else
   182 		{
   183 		INFO_PRINTF2(_L("SetTargetPixelFormat - not supported: %S"),&ColorModeName(aDisplayMode));
   184 		return EFalse;
   185 		}
   186 
   187 	delete iContext;
   188 	iContext = NULL;
   189 	TESTL(iDGdiImageTarget != NULL);
   190 	iDGdiImageTarget->Close();
   191 	iSgImageTarget.Close();
   192 	
   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))
   199 		{
   200 		// Activate the context on a rendering target.
   201 		TESTNOERRORL(iDGdiDriver->GetError());
   202 		iContext->Activate(*iDGdiImageTarget);
   203 		}
   204 	TESTNOERRORL(iDGdiDriver->GetError());
   205 	return supported;
   206 	}
   207 #else
   208 TBool CTDirectGdiTestBase::SetTargetPixelFormatL(TDisplayMode /*aDisplayMode*/)
   209     {
   210     return EFalse;
   211     }
   212 #endif
   213 
   214 /* 
   215 Creates a new CFbsBitmap representing the RSgImage. It is down to the client to delete it.
   216 
   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.
   220 */
   221 CFbsBitmap* CTDirectGdiTestBase::GetTargetAsBitmapL()
   222 	{
   223 #ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
   224 	iDGdiDriver->Finish();
   225 
   226 	CFbsBitmap* bitmap = new (ELeave) CFbsBitmap();
   227 	CleanupStack::PushL(bitmap);
   228 	TESTNOERRORL(bitmap->Create(iImageInfo.iSizeInPixels, TDisplayModeMapping::MapPixelFormatToDisplayMode(iImageInfo.iPixelFormat)));
   229 	
   230 	const TInt bitmapDataStride = bitmap->DataStride();
   231 	const TInt numScanlines = iImageInfo.iSizeInPixels.iHeight;	
   232 	
   233 	MSgImage_Sw* sgImageDirectAccess;
   234 	TESTNOERRORL(iSgImageTarget.GetInterface(sgImageDirectAccess));	
   235 	
   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)
   242     	{
   243     	Mem::Copy((TUint8*)bitmapDataAddress + (scanline*bitmapDataStride), (TUint8*)sgImageDataAddress + (scanline*sgImageDataStride), bitmapDataStride);
   244     	}
   245     bitmap->EndDataAccess();
   246     sgImageDirectAccess->EndDataAccess();
   247     
   248 	CleanupStack::Pop(1, bitmap);
   249 	return bitmap;
   250 #else
   251 	return NULL;
   252 #endif	
   253 	}
   254 	
   255