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.
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
/**
sl@0
    17
 @file
sl@0
    18
 @test
sl@0
    19
 @internalComponent - Internal Symbian test code 
sl@0
    20
*/
sl@0
    21
sl@0
    22
#include "tdirectgditestbase.h"
sl@0
    23
sl@0
    24
#include <graphics/directgdidriver.h>
sl@0
    25
#include <graphics/directgdiextensioninterfaces.h>
sl@0
    26
#ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
sl@0
    27
#include <graphics/sgimage_sw.h>
sl@0
    28
#endif
sl@0
    29
TSize GetDisplaySizeInPixels();
sl@0
    30
sl@0
    31
#ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
sl@0
    32
// Cache size in bytes for DirectGDI Image cache.
sl@0
    33
const TInt KDirectGdiImageCacheSize = 0x400000;
sl@0
    34
#endif
sl@0
    35
sl@0
    36
#ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
sl@0
    37
sl@0
    38
/**
sl@0
    39
Implementation of CTestStep base class virtual.
sl@0
    40
Used to implement all DirectGDI-specific initialisation for any derived test-cases, and
sl@0
    41
reads settings from the configuration file.
sl@0
    42
It will leave if there are any failures as DirectGDI must be initialised correctly for
sl@0
    43
the tests to be run. The leave will be picked up by the framework.
sl@0
    44
sl@0
    45
@leave If initialisation of DirectGDI failed.
sl@0
    46
@return EPass if successful, otherwise a TVerdict error code.
sl@0
    47
*/
sl@0
    48
TVerdict CTDirectGdiTestBase::doTestStepPreambleL()
sl@0
    49
	{
sl@0
    50
	CTe_graphicsperformanceSuiteStepBase::doTestStepPreambleL();
sl@0
    51
	
sl@0
    52
	TPtrC targetPixelFormatInput;
sl@0
    53
	TEST(GetStringFromConfig(_L("PixelFormats"), _L("TargetPixelFormatEnums"), targetPixelFormatInput));
sl@0
    54
	TDisplayModeMapping::ConvertPixelFormats(targetPixelFormatInput, iTargetPixelFormatArray);
sl@0
    55
sl@0
    56
	TPtrC sourcePixelFormatInput;
sl@0
    57
	TEST(GetStringFromConfig(_L("PixelFormats"), _L("SourcePixelFormatEnums"), sourcePixelFormatInput));
sl@0
    58
	TDisplayModeMapping::ConvertPixelFormats(sourcePixelFormatInput, iSourcePixelFormatArray);
sl@0
    59
	
sl@0
    60
	InitializeDirectGdiL();	
sl@0
    61
	return TestStepResult();
sl@0
    62
	}
sl@0
    63
sl@0
    64
/**
sl@0
    65
Implementation of CTestStep base class virtual
sl@0
    66
Used for doing all post-test treatment common to derived DirectGDI classes, such as
sl@0
    67
shutting down DirectGDI.
sl@0
    68
sl@0
    69
@leave If there was a failure shutting down DirectGDI.
sl@0
    70
@return EPass if successful, otherwise a TVerdict error code.
sl@0
    71
*/
sl@0
    72
TVerdict CTDirectGdiTestBase::doTestStepPostambleL()
sl@0
    73
	{
sl@0
    74
	iTargetPixelFormatArray.Close();
sl@0
    75
	iSourcePixelFormatArray.Close();
sl@0
    76
	UninitializeDirectGdi();
sl@0
    77
	return CTe_graphicsperformanceSuiteStepBase::doTestStepPostambleL();
sl@0
    78
	}
sl@0
    79
#endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
sl@0
    80
sl@0
    81
 CTDirectGdiTestBase::~CTDirectGdiTestBase()
sl@0
    82
	{
sl@0
    83
	}
sl@0
    84
sl@0
    85
CTDirectGdiTestBase::CTDirectGdiTestBase()
sl@0
    86
	{
sl@0
    87
	}
sl@0
    88
sl@0
    89
/**
sl@0
    90
Sets up DirectGDI for use in the test cases.
sl@0
    91
sl@0
    92
@leave If any failures occur initialising DirectGDI.
sl@0
    93
*/
sl@0
    94
void CTDirectGdiTestBase::InitializeDirectGdiL()
sl@0
    95
	{
sl@0
    96
#ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
sl@0
    97
	SgDriver::Open();
sl@0
    98
		
sl@0
    99
	TESTNOERRORL(CDirectGdiDriver::Open());
sl@0
   100
	iDGdiDriver = CDirectGdiDriver::Static();
sl@0
   101
	if (iDGdiDriver == NULL)
sl@0
   102
		User::Leave(KErrNoMemory);
sl@0
   103
	
sl@0
   104
	// If using the DirectGDI OpenVG adapter, set a large image cache size to optimize performance.
sl@0
   105
	MDirectGdiDriverCacheSize* cacheInterface = NULL;
sl@0
   106
	if (KErrNone == iDGdiDriver->GetInterface(TUid::Uid(KDirectGdiDriverCacheSizeUid), (TAny*&)cacheInterface))
sl@0
   107
		{
sl@0
   108
		cacheInterface->SetMaxImageCacheSize(KDirectGdiImageCacheSize);
sl@0
   109
		}
sl@0
   110
	
sl@0
   111
	iDGdiImageTarget = new (ELeave) RDirectGdiImageTarget(*iDGdiDriver);
sl@0
   112
			
sl@0
   113
	// Set up most of RSgImage image info to be used for target
sl@0
   114
	iImageInfo.iSizeInPixels = GetPixmapSizeInPixels();
sl@0
   115
	iImageInfo.iUsage = ESgUsageDirectGdiTarget;
sl@0
   116
	
sl@0
   117
	iTs = CFbsTypefaceStore::NewL(NULL);	
sl@0
   118
	TESTNOERRORL(iTs->GetNearestFontToDesignHeightInPixels((CFont *&)iFont, TFontSpec(KFontTypeface, KFontSize)));
sl@0
   119
	TESTNOERRORL(iTs->GetNearestFontToDesignHeightInPixels((CFont *&)iLargeFont,TFontSpec(KFontTypeface, 40)));	
sl@0
   120
#endif
sl@0
   121
	}
sl@0
   122
sl@0
   123
/**
sl@0
   124
Shuts down DirectGDI when test cases have finished.
sl@0
   125
*/
sl@0
   126
void CTDirectGdiTestBase::UninitializeDirectGdi()
sl@0
   127
	{	
sl@0
   128
	delete iContext;
sl@0
   129
	iContext = NULL;
sl@0
   130
	if (iDGdiImageTarget)
sl@0
   131
		{
sl@0
   132
		iDGdiImageTarget->Close();	
sl@0
   133
		delete iDGdiImageTarget;
sl@0
   134
		iDGdiImageTarget = NULL;
sl@0
   135
		}
sl@0
   136
	if (iDGdiDriver)
sl@0
   137
		{
sl@0
   138
		iDGdiDriver->Close();
sl@0
   139
		}
sl@0
   140
#ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
sl@0
   141
	iSgImageTarget.Close();
sl@0
   142
#endif
sl@0
   143
	iTs->ReleaseFont(iFont);
sl@0
   144
	iTs->ReleaseFont(iLargeFont);
sl@0
   145
	delete iTs;
sl@0
   146
	iTs = NULL;
sl@0
   147
#ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
sl@0
   148
	SgDriver::Close();
sl@0
   149
#endif
sl@0
   150
	}
sl@0
   151
sl@0
   152
 /**
sl@0
   153
Initialises a target and a DirectGDI Gc.
sl@0
   154
sl@0
   155
@param aPixelFormat The pixel format to be used for the target.
sl@0
   156
@return ETrue if the target supports the display mode, EFalse otherwise.
sl@0
   157
*/
sl@0
   158
#ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
sl@0
   159
TBool CTDirectGdiTestBase::SetTargetPixelFormatL(TDisplayMode aDisplayMode)
sl@0
   160
	{
sl@0
   161
	TUidPixelFormat pixelFormat = TDisplayModeMapping::MapDisplayModeToPixelFormat(aDisplayMode);
sl@0
   162
	TInt numSupportedFormats = 0;
sl@0
   163
	RSgImage::GetPixelFormats(iImageInfo,NULL,numSupportedFormats);
sl@0
   164
	TUidPixelFormat* supportedFormats = new (ELeave) TUidPixelFormat[numSupportedFormats];
sl@0
   165
	RSgImage::GetPixelFormats(iImageInfo,supportedFormats,numSupportedFormats);
sl@0
   166
    TBool supported = EFalse;
sl@0
   167
	for (TInt ii = numSupportedFormats-1; ii >=0; --ii)
sl@0
   168
		{
sl@0
   169
		if(supportedFormats[ii] == pixelFormat)
sl@0
   170
			{
sl@0
   171
			supported = ETrue;
sl@0
   172
			break;
sl@0
   173
			}
sl@0
   174
		}
sl@0
   175
	delete[] supportedFormats;
sl@0
   176
sl@0
   177
	if (supported)
sl@0
   178
		{
sl@0
   179
		INFO_PRINTF2(_L("SetTargetPixelFormat - supported: %S"),&ColorModeName(aDisplayMode));
sl@0
   180
		}
sl@0
   181
	else
sl@0
   182
		{
sl@0
   183
		INFO_PRINTF2(_L("SetTargetPixelFormat - not supported: %S"),&ColorModeName(aDisplayMode));
sl@0
   184
		return EFalse;
sl@0
   185
		}
sl@0
   186
sl@0
   187
	delete iContext;
sl@0
   188
	iContext = NULL;
sl@0
   189
	TESTL(iDGdiImageTarget != NULL);
sl@0
   190
	iDGdiImageTarget->Close();
sl@0
   191
	iSgImageTarget.Close();
sl@0
   192
	
sl@0
   193
	iImageInfo.iPixelFormat = pixelFormat;
sl@0
   194
	TESTNOERRORL(iSgImageTarget.Create(iImageInfo, NULL,0));
sl@0
   195
	iContext = CDirectGdiContext::NewL (*iDGdiDriver);
sl@0
   196
	TESTL(iContext != NULL);
sl@0
   197
	TESTNOERRORL(iDGdiDriver->GetError());
sl@0
   198
	if (KErrNone == iDGdiImageTarget->Create(iSgImageTarget))
sl@0
   199
		{
sl@0
   200
		// Activate the context on a rendering target.
sl@0
   201
		TESTNOERRORL(iDGdiDriver->GetError());
sl@0
   202
		iContext->Activate(*iDGdiImageTarget);
sl@0
   203
		}
sl@0
   204
	TESTNOERRORL(iDGdiDriver->GetError());
sl@0
   205
	return supported;
sl@0
   206
	}
sl@0
   207
#else
sl@0
   208
TBool CTDirectGdiTestBase::SetTargetPixelFormatL(TDisplayMode /*aDisplayMode*/)
sl@0
   209
    {
sl@0
   210
    return EFalse;
sl@0
   211
    }
sl@0
   212
#endif
sl@0
   213
sl@0
   214
/* 
sl@0
   215
Creates a new CFbsBitmap representing the RSgImage. It is down to the client to delete it.
sl@0
   216
sl@0
   217
@see CTDirectGdiTestBase::GetTargetAsBitmapL()
sl@0
   218
@return A pointer to the newly created bitmap.
sl@0
   219
@leave If there was a problem copying from the source to the target.
sl@0
   220
*/
sl@0
   221
CFbsBitmap* CTDirectGdiTestBase::GetTargetAsBitmapL()
sl@0
   222
	{
sl@0
   223
#ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
sl@0
   224
	iDGdiDriver->Finish();
sl@0
   225
sl@0
   226
	CFbsBitmap* bitmap = new (ELeave) CFbsBitmap();
sl@0
   227
	CleanupStack::PushL(bitmap);
sl@0
   228
	TESTNOERRORL(bitmap->Create(iImageInfo.iSizeInPixels, TDisplayModeMapping::MapPixelFormatToDisplayMode(iImageInfo.iPixelFormat)));
sl@0
   229
	
sl@0
   230
	const TInt bitmapDataStride = bitmap->DataStride();
sl@0
   231
	const TInt numScanlines = iImageInfo.iSizeInPixels.iHeight;	
sl@0
   232
	
sl@0
   233
	MSgImage_Sw* sgImageDirectAccess;
sl@0
   234
	TESTNOERRORL(iSgImageTarget.GetInterface(sgImageDirectAccess));	
sl@0
   235
	
sl@0
   236
    const TInt sgImageDataStride = sgImageDirectAccess->DataStride();    
sl@0
   237
    sgImageDirectAccess->BeginDataAccess(ESgCpuAccessReadOnly);
sl@0
   238
    TUint32* sgImageDataAddress = (TUint32*)(sgImageDirectAccess->DataAddress());    
sl@0
   239
    bitmap->BeginDataAccess();
sl@0
   240
    TUint32* bitmapDataAddress = bitmap->DataAddress();
sl@0
   241
    for (TInt scanline = 0; scanline < numScanlines; ++scanline)
sl@0
   242
    	{
sl@0
   243
    	Mem::Copy((TUint8*)bitmapDataAddress + (scanline*bitmapDataStride), (TUint8*)sgImageDataAddress + (scanline*sgImageDataStride), bitmapDataStride);
sl@0
   244
    	}
sl@0
   245
    bitmap->EndDataAccess();
sl@0
   246
    sgImageDirectAccess->EndDataAccess();
sl@0
   247
    
sl@0
   248
	CleanupStack::Pop(1, bitmap);
sl@0
   249
	return bitmap;
sl@0
   250
#else
sl@0
   251
	return NULL;
sl@0
   252
#endif	
sl@0
   253
	}
sl@0
   254
	
sl@0
   255