os/graphics/egl/egltest/src/egltestcommonsession.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/graphics/egl/egltest/src/egltestcommonsession.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,2107 @@
     1.4 +// Copyright (c) 2007-2010 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 +*/
    1.23 +
    1.24 +#include "egltestcommonsession.h"
    1.25 +#include "egltestcommonutils.h"
    1.26 +#include "egltestcommonsgimageinfo.h"
    1.27 +
    1.28 +#include <test/tefunit.h>
    1.29 +#include <e32cmn.h>
    1.30 +#ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
    1.31 +#include <sgresource/sgresource.h>
    1.32 +#else
    1.33 +#include <graphics/sgresourceinternal.h>
    1.34 +#include <graphics/sgresource.h>
    1.35 +#endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
    1.36 +#include <VG/openvg.h>
    1.37 +#include <GLES/gl.h>
    1.38 +
    1.39 +
    1.40 +#define	CHECK_EXPECTED_ERROR(aFunctionReturnValue) \
    1.41 +	if(!(CheckExpectedError(aFunctionReturnValue))) \
    1.42 +		{ \
    1.43 +		ERR_PRINTF2(_L("thread %d: Unexpected EGL error information"), iThreadIdx); \
    1.44 +		User::Leave(KErrTEFUnitFail); \
    1.45 +		}
    1.46 +
    1.47 +const TMapEglConfigToPixelFormat KMapEglConfigToPixelFormat[] =
    1.48 +	{
    1.49 +	{16, 0, 5,6,5, 0, 							EGL_RGB_BUFFER, EUidPixelFormatRGB_565, EColor64K},
    1.50 +	{32, 0, 8,8,8, 0,							EGL_RGB_BUFFER, EUidPixelFormatXRGB_8888, EColor16MU},
    1.51 +    {32, 8, 8,8,8, EGL_VG_ALPHA_FORMAT_NONPRE, 	EGL_RGB_BUFFER, EUidPixelFormatARGB_8888, EColor16MA},
    1.52 +	{32, 8, 8,8,8, EGL_VG_ALPHA_FORMAT_PRE, 	EGL_RGB_BUFFER, EUidPixelFormatARGB_8888_PRE, EColor16MAP}
    1.53 +	};
    1.54 +
    1.55 +EXPORT_C CTestEglSession::CTestEglSession(CTestExecuteLogger& aLogger, EGLDisplay& aDisplay, TInt aThreadIdx)
    1.56 +	: iLogger(aLogger), iThreadIdx(aThreadIdx), iExtensionGroupCached(EIsUndefined), iDisplay(aDisplay), iExpectedErrorCode(EGL_SUCCESS)
    1.57 +	{}
    1.58 +
    1.59 +EXPORT_C CTestEglSession* CTestEglSession::NewLC(CTestExecuteLogger& aLogger, EGLDisplay& aDisplay, TInt aThreadIdx)
    1.60 +	{
    1.61 +	CTestEglSession* self = new (ELeave) CTestEglSession(aLogger, aDisplay, aThreadIdx);
    1.62 +	CleanupStack::PushL(self);
    1.63 +	return self;
    1.64 +	}
    1.65 +
    1.66 +EXPORT_C CTestEglSession* CTestEglSession::NewL(CTestExecuteLogger& aLogger, EGLDisplay& aDisplay, TInt aThreadIdx)
    1.67 +	{
    1.68 +	CTestEglSession* self = CTestEglSession::NewLC(aLogger, aDisplay, aThreadIdx);
    1.69 +	CleanupStack::Pop(self);
    1.70 +	return self;
    1.71 +	}
    1.72 +
    1.73 +EXPORT_C CTestEglSession::~CTestEglSession()
    1.74 +	{
    1.75 +	iExtensionStrings.Reset();
    1.76 +	EGLBoolean ret;
    1.77 +	if (iDisplay != EGL_NO_DISPLAY)
    1.78 +		{
    1.79 +		// Unbind and destroy context only if we successfuly created it
    1.80 +		if (iContext != EGL_NO_CONTEXT)
    1.81 +		    {
    1.82 +            INFO_PRINTF2(_L("thread %d: Calling eglMakeCurrent(NULL values) from ~CTestEglSession..."), iThreadIdx);
    1.83 +            ret = eglMakeCurrent(iDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
    1.84 +            if(ret == EGL_FALSE)
    1.85 +                {
    1.86 +                WARN_PRINTF3(_L("thread %d: eglMakeCurrent returned error = %x ~CTestEglSession..."), iThreadIdx, eglGetError());
    1.87 +                }
    1.88 +
    1.89 +            // Warn because this should be done by the test, rather than relying on the d'tor
    1.90 +            // which may not leave if there is an error (so no CHECK_EXPECTED_ERROR)
    1.91 +            WARN_PRINTF2(_L("thread %d: Calling eglDestroyContext() from ~CTestEglSession..."), iThreadIdx);
    1.92 +            ret = eglDestroyContext(iDisplay, iContext);
    1.93 +            if(ret == EGL_FALSE)
    1.94 +                {
    1.95 +                WARN_PRINTF3(_L("thread %d: eglDestroyContext returned error = %x ~CTestEglSession..."), iThreadIdx, eglGetError());
    1.96 +                }
    1.97 +		    }
    1.98 +
    1.99 +		if (iSurface != EGL_NO_SURFACE)
   1.100 +			{
   1.101 +			// Warn because this should be done by the test, rather than relying on the d'tor
   1.102 +			// which may not leave if there is an error (so no CHECK_EXPECTED_ERROR)
   1.103 +			WARN_PRINTF2(_L("thread %d: Calling eglDestroySurface() from ~CTestEglSession..."), iThreadIdx);
   1.104 +			ret = eglDestroySurface(iDisplay, iSurface);
   1.105 +			if(ret == EGL_FALSE)
   1.106 +				{
   1.107 +				WARN_PRINTF3(_L("thread %d: eglDestroySurface returned error = %x ~CTestEglSession..."), iThreadIdx, eglGetError());
   1.108 +				}
   1.109 +			}
   1.110 +
   1.111 +		if (iTerminateDisplay)
   1.112 +			{
   1.113 +			INFO_PRINTF1(_L("Calling eglTerminate..."));
   1.114 +			ret = eglTerminate(iDisplay);
   1.115 +			iDisplay = EGL_NO_DISPLAY;
   1.116 +			if(ret == EGL_FALSE)
   1.117 +				{
   1.118 +				WARN_PRINTF3(_L("thread %d: eglTerminate returned error = %x ~CTestEglSession..."), iThreadIdx, eglGetError());
   1.119 +				}
   1.120 +			}
   1.121 +		}
   1.122 +
   1.123 +	// Only destroy native resource after the surface and context that wraps it has been destroyed.
   1.124 +	delete iFbsBitmap;
   1.125 +	CloseFbsSession();
   1.126 +
   1.127 +	iSgImage.Close();
   1.128 +	CloseSgDriver();
   1.129 +	}
   1.130 +
   1.131 +EXPORT_C void CTestEglSession::SetExpectedError(EGLint aExpectedErrorCode)
   1.132 +	{
   1.133 +	VERBOSE_INFO_PRINTF3(_L("thread %d: Setting the expected error code for the next EGL call to %x"), iThreadIdx, aExpectedErrorCode);
   1.134 +		{
   1.135 +		iExpectedErrorCode = aExpectedErrorCode;
   1.136 +		}
   1.137 +	}
   1.138 +
   1.139 +EXPORT_C void CTestEglSession::ResetExpectedError()
   1.140 +	{
   1.141 +	iExpectedErrorCode = EGL_SUCCESS;
   1.142 +	}
   1.143 +
   1.144 +/**
   1.145 +Checks whether the call to an EGL method returned the correct error information.
   1.146 +The method checks whether eglGetError() returns the expected error value as specified by calling SetExpectedError()
   1.147 +It also checks that the value returned by the EGL method was appropriate for the expected error value.
   1.148 +@param aFunctionReturnValue Pass in the value retured from the EGL method
   1.149 +@return Whether the expected error information was returned from a call to an EGL method.
   1.150 +*/
   1.151 +EXPORT_C TBool CTestEglSession::CheckExpectedError(EGLint aFunctionReturnValue)
   1.152 +	{
   1.153 +	TBool isExpectedError = ETrue;
   1.154 +	EGLint eglErr = eglGetError();
   1.155 +
   1.156 +	// First check that we got the correct return value
   1.157 +	if ((iExpectedErrorCode == EGL_SUCCESS) && !aFunctionReturnValue)
   1.158 +		{
   1.159 +		ERR_PRINTF3(_L("thread %d: Wrong function return value: %d"), iThreadIdx, aFunctionReturnValue);
   1.160 +		isExpectedError = EFalse;
   1.161 +		}
   1.162 +	// Also check that we got the
   1.163 +	if (eglErr != iExpectedErrorCode)
   1.164 +		{
   1.165 +		ERR_PRINTF4(_L("thread %d: eglGetError() returned %x, but expected %x"), iThreadIdx, eglErr, iExpectedErrorCode);
   1.166 +		isExpectedError = EFalse;
   1.167 +		}
   1.168 +	else if (eglErr != EGL_SUCCESS)
   1.169 +		{
   1.170 +		VERBOSE_INFO_PRINTF3(_L("thread %d: eglGetError() returned %x, as expected"), iThreadIdx, eglErr);
   1.171 +		}
   1.172 +
   1.173 +	// Reset the expected error
   1.174 +	ResetExpectedError();
   1.175 +
   1.176 +	return isExpectedError;
   1.177 +	}
   1.178 +
   1.179 +EXPORT_C void CTestEglSession::CheckExpectedErrorL(EGLint aExpectedErrorCode)
   1.180 +	{
   1.181 +	EGLint eglErr = eglGetError();
   1.182 +	// check that we got the expected error
   1.183 +	if (eglErr != aExpectedErrorCode)
   1.184 +		{
   1.185 +		ERR_PRINTF4(_L("thread %d: eglGetError() returned %x, but expected %x"), iThreadIdx, eglErr, aExpectedErrorCode);
   1.186 +		User::Leave(KErrTEFUnitFail);
   1.187 +		}
   1.188 +	}
   1.189 +
   1.190 +void CTestEglSession::QueryExtensionsL(TExtensionsGroups aExtensionBelongsTo)
   1.191 +	{
   1.192 +	// reset the cached extensions
   1.193 +	iExtensionStrings.Reset();
   1.194 +
   1.195 +	const char* extensionsString = NULL;
   1.196 +	if(aExtensionBelongsTo == EIsEGL)
   1.197 +		{
   1.198 +		INFO_PRINTF2(_L("thread %d: Calling eglQueryString for EGL_EXTENSIONS)"), iThreadIdx);
   1.199 +		extensionsString = eglQueryString(iDisplay, EGL_EXTENSIONS);
   1.200 +		}
   1.201 +	else if(aExtensionBelongsTo == EIsVG)
   1.202 +		{
   1.203 +		INFO_PRINTF2(_L("thread %d: Calling vgGetString for VG_EXTENSIONS)"), iThreadIdx);
   1.204 +
   1.205 +		// OpenVG needs a current VG context before it will allow the call to vgGetString
   1.206 +		// The created surface will remain un-used, hence we create it with an arbitrary pixel format 
   1.207 +        EGLConfig currentConfig = GetConfigExactMatchL(EPBufferAttribsColor64K);
   1.208 +        CreatePbufferSurfaceAndMakeCurrentL(currentConfig, TSize(1,1), EGL_OPENVG_API);
   1.209 +
   1.210 +		extensionsString = (const char*) vgGetString(VG_EXTENSIONS);
   1.211 +
   1.212 +		//cleanup the context & surface
   1.213 +		CleanupSurfaceSgImageL();
   1.214 +		}
   1.215 +	else
   1.216 +		{
   1.217 +		ERR_PRINTF2(_L("CTestEglSession::QueryExtensionsL() - Unknown extension group provided (%d)."), aExtensionBelongsTo);
   1.218 +		User::Leave(KErrArgument);
   1.219 +		}
   1.220 +	CHECK_EXPECTED_ERROR(extensionsString!=NULL);
   1.221 +
   1.222 +	TPtrC8 ptrExtensions((const TUint8 *) extensionsString );
   1.223 +
   1.224 +	RBuf buffer;
   1.225 +    buffer.CreateL(ptrExtensions.Length());
   1.226 +    buffer.CleanupClosePushL();
   1.227 +    buffer.Copy(ptrExtensions);
   1.228 +	INFO_PRINTF3(_L("thread %d: QueryExtensionsL: \"%S\""), iThreadIdx, &buffer);
   1.229 +    CleanupStack::PopAndDestroy(&buffer);
   1.230 +
   1.231 +	TInt posSpace=1;
   1.232 +	while (posSpace > 0 && ptrExtensions.Length() > 0)
   1.233 +		{
   1.234 +		posSpace = ptrExtensions.Locate(' '); // strictly looking for a single space
   1.235 +		ASSERT_FALSE(posSpace==0); // Would imply extension starting with a space or with 2 spaces in a row
   1.236 +		if (posSpace > 0)
   1.237 +			{
   1.238 +			iExtensionStrings.Append(ptrExtensions.Left(posSpace));
   1.239 +			if (posSpace <= ptrExtensions.Length())
   1.240 +				{
   1.241 +				ptrExtensions.Set(ptrExtensions.Mid(posSpace+1));
   1.242 +				}
   1.243 +			}
   1.244 +		else
   1.245 +			{
   1.246 +			iExtensionStrings.Append(ptrExtensions);
   1.247 +			}
   1.248 +		}
   1.249 +	}
   1.250 +
   1.251 +TBool CTestEglSession::FindExtensionStringL(TExtensionsGroups aExtensionBelongsTo, const TDesC8& aExtensionString)
   1.252 +	{
   1.253 +	//Load the extensions for this group if not already cached
   1.254 +	if (iExtensionGroupCached != aExtensionBelongsTo)
   1.255 +		{
   1.256 +		QueryExtensionsL(aExtensionBelongsTo); // Load extension info
   1.257 +		iExtensionGroupCached = aExtensionBelongsTo;
   1.258 +		}
   1.259 +
   1.260 +	TInt countExtensionStrings = iExtensionStrings.Count();
   1.261 +	for(TUint i=0; i<countExtensionStrings; i++)
   1.262 +		{
   1.263 +		if (iExtensionStrings[i].Compare(aExtensionString)==0)
   1.264 +			{
   1.265 +			// We have a match!
   1.266 +			return ETrue;
   1.267 +			}
   1.268 +		}
   1.269 +
   1.270 +	// No match: copy the extension string into a 16 bit buffer for logging
   1.271 +	const TInt KBufLenMissingExtension=128;
   1.272 +	TBuf16<KBufLenMissingExtension> bufMissingExtension16;
   1.273 +	bufMissingExtension16.Copy(aExtensionString.Left(KBufLenMissingExtension));
   1.274 +
   1.275 +	WARN_PRINTF2(_L("EGL extension missing: [%S]"), &bufMissingExtension16);
   1.276 +	return EFalse;
   1.277 +	}
   1.278 +
   1.279 +/**
   1.280 + Converts from TRgb space to Vg floating point colour
   1.281 + */
   1.282 +EXPORT_C void CTestEglSession::ConvertColor(const TRgb& aSource, VGfloat* aTarget)
   1.283 +//static
   1.284 +	{
   1.285 +	aTarget[0] = (VGfloat)aSource.Red() / 255.f;
   1.286 +	aTarget[1] = (VGfloat)aSource.Green() / 255.f;
   1.287 +	aTarget[2] = (VGfloat)aSource.Blue() / 255.f;
   1.288 +	aTarget[3] = (VGfloat)aSource.Alpha() / 255.f;
   1.289 +	}
   1.290 +
   1.291 +/** Breakpoint to manually view available configs while debugging */
   1.292 +EXPORT_C void CTestEglSession::ViewConfigsL()
   1.293 +	{
   1.294 +	EGLConfig configs[KMaxEglConfigs];
   1.295 +	EGLint numConfigs=0;
   1.296 +
   1.297 +	// Query number of configs available
   1.298 +	INFO_PRINTF1(_L("Calling eglGetConfigs to get the number of configs available..."));
   1.299 +	CHECK_EXPECTED_ERROR(eglGetConfigs(iDisplay, NULL, KMaxTInt, &numConfigs));
   1.300 +
   1.301 +	INFO_PRINTF1(_L("Checking number of configs..."));
   1.302 +	ASSERT_TRUE(numConfigs >= 1);
   1.303 +	INFO_PRINTF2(_L("Found %d configs"), numConfigs);
   1.304 +
   1.305 +	// Get the configs
   1.306 +	INFO_PRINTF1(_L("Calling eglGetConfigs to get configs..."));
   1.307 +	CHECK_EXPECTED_ERROR(eglGetConfigs(iDisplay, configs, KMaxEglConfigs, &numConfigs));
   1.308 +
   1.309 +	for(TUint index = 0; index < numConfigs; index++)
   1.310 +		{
   1.311 +		EGLint EGL_BUFFER_SIZE_value;
   1.312 +		EGLint EGL_ALPHA_SIZE_value;
   1.313 +		EGLint EGL_BLUE_SIZE_value;
   1.314 +		EGLint EGL_GREEN_SIZE_value;
   1.315 +		EGLint EGL_RED_SIZE_value;
   1.316 +#ifdef PRINT_ALL_CONFIGS_DETAILS
   1.317 +		EGLint EGL_DEPTH_SIZE_value;
   1.318 +		EGLint EGL_STENCIL_SIZE_value;
   1.319 +		EGLint EGL_CONFIG_CAVEAT_value;
   1.320 +		EGLint EGL_CONFIG_ID_value;
   1.321 +		EGLint EGL_LEVEL_value;
   1.322 +		EGLint EGL_MAX_PBUFFER_HEIGHT_value;
   1.323 +		EGLint EGL_MAX_PBUFFER_PIXELS_value;
   1.324 +		EGLint EGL_MAX_PBUFFER_WIDTH_value;
   1.325 +		EGLint EGL_NATIVE_RENDERABLE_value;
   1.326 +		EGLint EGL_NATIVE_VISUAL_ID_value;
   1.327 +		EGLint EGL_NATIVE_VISUAL_TYPE_value;
   1.328 +		EGLint EGL_SAMPLES_value;
   1.329 +		EGLint EGL_SAMPLE_BUFFERS_value;
   1.330 +#endif
   1.331 +		EGLint EGL_SURFACE_TYPE_value;
   1.332 +#ifdef PRINT_ALL_CONFIGS_DETAILS
   1.333 +		EGLint EGL_TRANSPARENT_TYPE_value;
   1.334 +		EGLint EGL_TRANSPARENT_BLUE_VALUE_value;
   1.335 +		EGLint EGL_TRANSPARENT_GREEN_VALUE_value;
   1.336 +		EGLint EGL_TRANSPARENT_RED_VALUE_value;
   1.337 +		EGLint EGL_BIND_TO_TEXTURE_RGB_value;
   1.338 +		EGLint EGL_BIND_TO_TEXTURE_RGBA_value;
   1.339 +		EGLint EGL_MIN_SWAP_INTERVAL_value;
   1.340 +		EGLint EGL_MAX_SWAP_INTERVAL_value;
   1.341 +		EGLint EGL_LUMINANCE_SIZE_value;
   1.342 +		EGLint EGL_ALPHA_MASK_SIZE_value;
   1.343 +		EGLint EGL_COLOR_BUFFER_TYPE_value;
   1.344 +#endif
   1.345 +		EGLint EGL_RENDERABLE_TYPE_value;
   1.346 +
   1.347 +		eglGetConfigAttrib(iDisplay, configs[index], EGL_BUFFER_SIZE, &EGL_BUFFER_SIZE_value);
   1.348 +		eglGetConfigAttrib(iDisplay, configs[index], EGL_ALPHA_SIZE, &EGL_ALPHA_SIZE_value);
   1.349 +		eglGetConfigAttrib(iDisplay, configs[index], EGL_BLUE_SIZE, &EGL_BLUE_SIZE_value);
   1.350 +		eglGetConfigAttrib(iDisplay, configs[index], EGL_GREEN_SIZE, &EGL_GREEN_SIZE_value);
   1.351 +		eglGetConfigAttrib(iDisplay, configs[index], EGL_RED_SIZE, &EGL_RED_SIZE_value);
   1.352 +#ifdef PRINT_ALL_CONFIGS_DETAILS
   1.353 +		eglGetConfigAttrib(iDisplay, configs[index], EGL_DEPTH_SIZE, &EGL_DEPTH_SIZE_value);
   1.354 +		eglGetConfigAttrib(iDisplay, configs[index], EGL_STENCIL_SIZE, &EGL_STENCIL_SIZE_value);
   1.355 +		eglGetConfigAttrib(iDisplay, configs[index], EGL_CONFIG_CAVEAT, &EGL_CONFIG_CAVEAT_value);
   1.356 +		eglGetConfigAttrib(iDisplay, configs[index], EGL_CONFIG_ID, &EGL_CONFIG_ID_value);
   1.357 +		eglGetConfigAttrib(iDisplay, configs[index], EGL_LEVEL, &EGL_LEVEL_value);
   1.358 +		eglGetConfigAttrib(iDisplay, configs[index], EGL_MAX_PBUFFER_HEIGHT, &EGL_MAX_PBUFFER_HEIGHT_value);
   1.359 +		eglGetConfigAttrib(iDisplay, configs[index], EGL_MAX_PBUFFER_PIXELS, &EGL_MAX_PBUFFER_PIXELS_value);
   1.360 +		eglGetConfigAttrib(iDisplay, configs[index], EGL_MAX_PBUFFER_WIDTH, &EGL_MAX_PBUFFER_WIDTH_value);
   1.361 +		eglGetConfigAttrib(iDisplay, configs[index], EGL_NATIVE_RENDERABLE, &EGL_NATIVE_RENDERABLE_value);
   1.362 +		eglGetConfigAttrib(iDisplay, configs[index], EGL_NATIVE_VISUAL_ID, &EGL_NATIVE_VISUAL_ID_value);
   1.363 +		eglGetConfigAttrib(iDisplay, configs[index], EGL_NATIVE_VISUAL_TYPE, &EGL_NATIVE_VISUAL_TYPE_value);
   1.364 +		eglGetConfigAttrib(iDisplay, configs[index], EGL_SAMPLES, &EGL_SAMPLES_value);
   1.365 +		eglGetConfigAttrib(iDisplay, configs[index], EGL_SAMPLE_BUFFERS, &EGL_SAMPLE_BUFFERS_value);
   1.366 +#endif
   1.367 +		eglGetConfigAttrib(iDisplay, configs[index], EGL_SURFACE_TYPE, &EGL_SURFACE_TYPE_value);
   1.368 +#ifdef PRINT_ALL_CONFIGS_DETAILS
   1.369 +		eglGetConfigAttrib(iDisplay, configs[index], EGL_TRANSPARENT_TYPE, &EGL_TRANSPARENT_TYPE_value);
   1.370 +		eglGetConfigAttrib(iDisplay, configs[index], EGL_TRANSPARENT_BLUE_VALUE, &EGL_TRANSPARENT_BLUE_VALUE_value);
   1.371 +		eglGetConfigAttrib(iDisplay, configs[index], EGL_TRANSPARENT_GREEN_VALUE, &EGL_TRANSPARENT_GREEN_VALUE_value);
   1.372 +		eglGetConfigAttrib(iDisplay, configs[index], EGL_TRANSPARENT_RED_VALUE, &EGL_TRANSPARENT_RED_VALUE_value);
   1.373 +		eglGetConfigAttrib(iDisplay, configs[index], EGL_BIND_TO_TEXTURE_RGB, &EGL_BIND_TO_TEXTURE_RGB_value);
   1.374 +		eglGetConfigAttrib(iDisplay, configs[index], EGL_BIND_TO_TEXTURE_RGBA, &EGL_BIND_TO_TEXTURE_RGBA_value);
   1.375 +		eglGetConfigAttrib(iDisplay, configs[index], EGL_MIN_SWAP_INTERVAL, &EGL_MIN_SWAP_INTERVAL_value);
   1.376 +		eglGetConfigAttrib(iDisplay, configs[index], EGL_MAX_SWAP_INTERVAL, &EGL_MAX_SWAP_INTERVAL_value);
   1.377 +		eglGetConfigAttrib(iDisplay, configs[index], EGL_LUMINANCE_SIZE, &EGL_LUMINANCE_SIZE_value);
   1.378 +		eglGetConfigAttrib(iDisplay, configs[index], EGL_ALPHA_MASK_SIZE, &EGL_ALPHA_MASK_SIZE_value);
   1.379 +		eglGetConfigAttrib(iDisplay, configs[index], EGL_COLOR_BUFFER_TYPE, &EGL_COLOR_BUFFER_TYPE_value);
   1.380 +#endif
   1.381 +		eglGetConfigAttrib(iDisplay, configs[index], EGL_RENDERABLE_TYPE, &EGL_RENDERABLE_TYPE_value);
   1.382 +
   1.383 +		TBool good = ETrue;
   1.384 +
   1.385 +		INFO_PRINTF7(_L("(idx: %3d) RGBA=(%2d) %2d,%2d,%2d,%2d"), index, EGL_BUFFER_SIZE_value,
   1.386 +				EGL_RED_SIZE_value, EGL_GREEN_SIZE_value, EGL_BLUE_SIZE_value,
   1.387 +				EGL_ALPHA_SIZE_value);
   1.388 +		if (!(EGL_RED_SIZE_value == 8 && EGL_GREEN_SIZE_value == 8 && EGL_BLUE_SIZE_value == 8 && EGL_ALPHA_SIZE_value == 0))
   1.389 +			{
   1.390 +			continue;
   1.391 +			}
   1.392 +
   1.393 +		INFO_PRINTF2(_L("\n\n^^^^^^ CONFIG [%d] VALUES ******"), index);
   1.394 +		if (EGL_SURFACE_TYPE_value & EGL_PIXMAP_BIT)
   1.395 +			{
   1.396 +			INFO_PRINTF2(_L("EGL_SURFACE_TYPE=%d. <<< Has EGL_PIXMAP_BIT"), EGL_SURFACE_TYPE_value);
   1.397 +			}
   1.398 +		else
   1.399 +			{
   1.400 +			INFO_PRINTF2(_L("EGL_SURFACE_TYPE=%d. <<< BAD (not pixmap)"), EGL_SURFACE_TYPE_value);
   1.401 +			good = EFalse;
   1.402 +			}
   1.403 +
   1.404 +		if (EGL_RENDERABLE_TYPE_value & EGL_OPENVG_BIT)
   1.405 +			{
   1.406 +			INFO_PRINTF2(_L("EGL_RENDERABLE_TYPE=%d. <<< Has EGL_OPENVG_BIT"), EGL_RENDERABLE_TYPE_value);
   1.407 +			}
   1.408 +		else
   1.409 +			{
   1.410 +			INFO_PRINTF2(_L("EGL_RENDERABLE_TYPE=%d. <<< BAD (not open vg)"), EGL_RENDERABLE_TYPE_value);
   1.411 +			good = EFalse;
   1.412 +			}
   1.413 +
   1.414 +		if (good)
   1.415 +			{
   1.416 +			INFO_PRINTF1(_L("^^^^^^^ GOOD ^^^^^^^"));
   1.417 +			}
   1.418 +
   1.419 +#ifdef PRINT_ALL_CONFIGS_DETAILS
   1.420 +		INFO_PRINTF2(_L("\n\n***** CONFIG [%d] VALUES ******"), index);
   1.421 +		INFO_PRINTF2(_L("EGL_BUFFER_SIZE=%d."), EGL_BUFFER_SIZE_value);
   1.422 +		INFO_PRINTF2(_L("EGL_ALPHA_SIZE=%d."), EGL_ALPHA_SIZE_value);
   1.423 +		INFO_PRINTF2(_L("EGL_BLUE_SIZE=%d."), EGL_BLUE_SIZE_value);
   1.424 +		INFO_PRINTF2(_L("EGL_GREEN_SIZE=%d."), EGL_GREEN_SIZE_value);
   1.425 +		INFO_PRINTF2(_L("EGL_RED_SIZE=%d."), EGL_RED_SIZE_value);
   1.426 +		INFO_PRINTF2(_L("EGL_DEPTH_SIZE=%d."), EGL_DEPTH_SIZE_value);
   1.427 +		INFO_PRINTF2(_L("EGL_STENCIL_SIZE=%d."), EGL_STENCIL_SIZE_value);
   1.428 +		INFO_PRINTF2(_L("EGL_CONFIG_CAVEAT=%d."), EGL_CONFIG_CAVEAT_value);
   1.429 +		INFO_PRINTF2(_L("EGL_CONFIG_ID=%d."), EGL_CONFIG_ID_value);
   1.430 +		INFO_PRINTF2(_L("EGL_LEVEL=%d."), EGL_LEVEL_value);
   1.431 +		INFO_PRINTF2(_L("EGL_MAX_PBUFFER_HEIGHT=%d."), EGL_MAX_PBUFFER_HEIGHT_value);
   1.432 +		INFO_PRINTF2(_L("EGL_MAX_PBUFFER_PIXELS=%d."), EGL_MAX_PBUFFER_PIXELS_value);
   1.433 +		INFO_PRINTF2(_L("EGL_MAX_PBUFFER_WIDTH=%d."), EGL_MAX_PBUFFER_WIDTH_value);
   1.434 +		INFO_PRINTF2(_L("EGL_NATIVE_RENDERABLE=%d."), EGL_NATIVE_RENDERABLE_value);
   1.435 +		INFO_PRINTF2(_L("EGL_NATIVE_VISUAL_ID=%d."), EGL_NATIVE_VISUAL_ID_value);
   1.436 +		INFO_PRINTF2(_L("EGL_NATIVE_VISUAL_TYPE=%d."), EGL_NATIVE_VISUAL_TYPE_value);
   1.437 +		INFO_PRINTF2(_L("EGL_SAMPLES=%d."), EGL_SAMPLES_value);
   1.438 +		INFO_PRINTF2(_L("EGL_SAMPLE_BUFFERS=%d."), EGL_SAMPLE_BUFFERS_value);
   1.439 +		INFO_PRINTF2(_L("EGL_SURFACE_TYPE=%d."), EGL_SURFACE_TYPE_value);
   1.440 +		INFO_PRINTF2(_L("EGL_TRANSPARENT_TYPE=%d."), EGL_TRANSPARENT_TYPE_value);
   1.441 +		INFO_PRINTF2(_L("EGL_TRANSPARENT_BLUE_VALUE=%d."), EGL_TRANSPARENT_BLUE_VALUE_value);
   1.442 +		INFO_PRINTF2(_L("EGL_TRANSPARENT_GREEN_VALUE=%d."), EGL_TRANSPARENT_GREEN_VALUE_value);
   1.443 +		INFO_PRINTF2(_L("EGL_TRANSPARENT_RED_VALUE=%d."), EGL_TRANSPARENT_RED_VALUE_value);
   1.444 +		INFO_PRINTF2(_L("EGL_BIND_TO_TEXTURE_RGB=%d."), EGL_BIND_TO_TEXTURE_RGB_value);
   1.445 +		INFO_PRINTF2(_L("EGL_BIND_TO_TEXTURE_RGBA=%d."), EGL_BIND_TO_TEXTURE_RGBA_value);
   1.446 +		INFO_PRINTF2(_L("EGL_MIN_SWAP_INTERVAL=%d."), EGL_MIN_SWAP_INTERVAL_value);
   1.447 +		INFO_PRINTF2(_L("EGL_MAX_SWAP_INTERVAL=%d."), EGL_MAX_SWAP_INTERVAL_value);
   1.448 +		INFO_PRINTF2(_L("EGL_LUMINANCE_SIZE=%d."), EGL_LUMINANCE_SIZE_value);
   1.449 +		INFO_PRINTF2(_L("EGL_ALPHA_MASK_SIZE=%d."), EGL_ALPHA_MASK_SIZE_value);
   1.450 +		INFO_PRINTF2(_L("EGL_COLOR_BUFFER_TYPE=%d."), EGL_COLOR_BUFFER_TYPE_value);
   1.451 +		INFO_PRINTF2(_L("EGL_RENDERABLE_TYPE=%d."), EGL_RENDERABLE_TYPE_value);
   1.452 +		INFO_PRINTF2(_L("\n*********************************\n\n"), index);
   1.453 +#endif
   1.454 +		}
   1.455 +	}
   1.456 +
   1.457 +LOCAL_C TEglConfigMatchType GetMatchType(EGLint aAttrib, TEglConfigMatchRule aMatchRule)
   1.458 +	{
   1.459 +	const TConfigMatchRuleItem* curMatchRuleItem = KConfigMatchRules[aMatchRule];
   1.460 +
   1.461 +	while(curMatchRuleItem->iAttrib != EGL_NONE)
   1.462 +		{
   1.463 +		if (aAttrib == curMatchRuleItem->iAttrib)
   1.464 +			{
   1.465 +			return curMatchRuleItem->iMatchType;
   1.466 +			}
   1.467 +		curMatchRuleItem++;
   1.468 +		}
   1.469 +
   1.470 +	RDebug::Printf("Unknown attrib %x", aAttrib);
   1.471 +	return eMatchUnknown;
   1.472 +	}
   1.473 +
   1.474 +/**
   1.475 + Returns the first index of a config that matches the requested config extactly
   1.476 + */
   1.477 +TInt CTestEglSession::GetFullMatchConfigIndex(EGLDisplay aDisplay, EGLConfig *aConfigs, TInt aNumConfigs,
   1.478 +											  const EGLint aWantedAttribs[], TEglConfigMatchRule aMatchRule)
   1.479 +	{
   1.480 +	EGLint value=0;
   1.481 +	for(TUint idxConfig=0; idxConfig<aNumConfigs; idxConfig++)
   1.482 +		{
   1.483 +		const EGLint *curAttrib = aWantedAttribs;
   1.484 +		TBool match = ETrue;
   1.485 +
   1.486 +		while(*curAttrib != EGL_NONE && match)
   1.487 +			{
   1.488 +			ASSERT_EGL_TRUE(eglGetConfigAttrib(aDisplay, aConfigs[idxConfig], *curAttrib, &value));
   1.489 +
   1.490 +			switch(GetMatchType(*curAttrib, aMatchRule))
   1.491 +				{
   1.492 +				case eMatchEqual:
   1.493 +					if (value != curAttrib[1])
   1.494 +						{
   1.495 +						match = EFalse;
   1.496 +						}
   1.497 +					break;
   1.498 +				case eMatchAtLeast:
   1.499 +					if (value < curAttrib[1])   // Note, we detect "failure to match", hence "<" not ">="!
   1.500 +						{
   1.501 +						match = EFalse;
   1.502 +						}
   1.503 +					break;
   1.504 +				case eMatchBitMask:
   1.505 +					if ((value & curAttrib[1]) != curAttrib[1])
   1.506 +						{
   1.507 +						match = EFalse;
   1.508 +						}
   1.509 +					break;
   1.510 +				case eMatchAlways:
   1.511 +				    break;
   1.512 +
   1.513 +				default:
   1.514 +					// We should not get here.
   1.515 +				    ASSERT(FALSE);
   1.516 +				    break;
   1.517 +				}
   1.518 +			curAttrib += 2;
   1.519 +			}
   1.520 +
   1.521 +		// If we get here with match set, we have matched all attributes, and have found a match.
   1.522 +		if (match)
   1.523 +			{
   1.524 +			return idxConfig;
   1.525 +			}
   1.526 +		}
   1.527 +	return KErrNotFound;
   1.528 +	}
   1.529 +
   1.530 +TInt CTestEglSession::ConfigToPixelFormatTableLength() const
   1.531 +	{
   1.532 +	return sizeof(KMapEglConfigToPixelFormat) / sizeof(TMapEglConfigToPixelFormat);
   1.533 +	}
   1.534 +
   1.535 +const TMapEglConfigToPixelFormat& CTestEglSession::ConfigToPixelFormatTable(TInt aIndex) const
   1.536 +	{
   1.537 +	return KMapEglConfigToPixelFormat[aIndex];
   1.538 +	}
   1.539 +
   1.540 +/**
   1.541 + Returns pixel format inforamtion for a given EGL config.
   1.542 + @param aConfig The EGL config for which pixel format information will be returned.
   1.543 + @return A pointer to the pixel format information for the given EGL config.
   1.544 +         Tf the config cannot be mapped, then NULL is returned.
   1.545 + */
   1.546 +EXPORT_C const TMapEglConfigToPixelFormat* CTestEglSession::GetPixelFormatFromEglConfigL(EGLConfig aConfig)
   1.547 +	{
   1.548 +	EGLint bufferSize=0;
   1.549 +	EGLint alphaSize=0;
   1.550 +	EGLint redSize=0;
   1.551 +	EGLint greenSize=0;
   1.552 +	EGLint blueSize=0;
   1.553 +	EGLint colorBufferType=0;
   1.554 +	EGLint surfaceType = 0;
   1.555 +
   1.556 +	CHECK_EXPECTED_ERROR(eglGetConfigAttrib(iDisplay, aConfig, EGL_BUFFER_SIZE, &bufferSize));
   1.557 +	CHECK_EXPECTED_ERROR(eglGetConfigAttrib(iDisplay, aConfig, EGL_ALPHA_SIZE, &alphaSize));
   1.558 +	CHECK_EXPECTED_ERROR(eglGetConfigAttrib(iDisplay, aConfig, EGL_RED_SIZE, &redSize));
   1.559 +	CHECK_EXPECTED_ERROR(eglGetConfigAttrib(iDisplay, aConfig, EGL_GREEN_SIZE, &greenSize));
   1.560 +	CHECK_EXPECTED_ERROR(eglGetConfigAttrib(iDisplay, aConfig, EGL_BLUE_SIZE, &blueSize));
   1.561 +	CHECK_EXPECTED_ERROR(eglGetConfigAttrib(iDisplay, aConfig, EGL_COLOR_BUFFER_TYPE, &colorBufferType));
   1.562 +	CHECK_EXPECTED_ERROR(eglGetConfigAttrib(iDisplay, aConfig, EGL_SURFACE_TYPE, &surfaceType));
   1.563 +
   1.564 +	INFO_PRINTF7(_L(">>>>> Config info: %d, %d, %d,%d,%d, 0x%x"), bufferSize, alphaSize, redSize, greenSize, blueSize, colorBufferType);
   1.565 +
   1.566 +	for(TUint i=0; i<ConfigToPixelFormatTableLength(); i++)
   1.567 +		{
   1.568 +		if ((ConfigToPixelFormatTable(i).iBufferSize == bufferSize)
   1.569 +				&& (ConfigToPixelFormatTable(i).iAlphaSize == alphaSize)
   1.570 +				&& (ConfigToPixelFormatTable(i).iRedSize == redSize)
   1.571 +				&& (ConfigToPixelFormatTable(i).iGreenSize == greenSize)
   1.572 +				&& (ConfigToPixelFormatTable(i).iBlueSize == blueSize)
   1.573 +				&& (ConfigToPixelFormatTable(i).iColorBufferType == colorBufferType)
   1.574 +				&& ((ConfigToPixelFormatTable(i).iSurfaceTypeFlags & surfaceType) == ConfigToPixelFormatTable(i).iSurfaceTypeFlags))
   1.575 +			{
   1.576 +			return &ConfigToPixelFormatTable(i);
   1.577 +			}
   1.578 +		}
   1.579 +
   1.580 +	return NULL;
   1.581 +	}
   1.582 +
   1.583 +EXPORT_C void CTestEglSession::CleanupSurfaceFbsBitmapL()
   1.584 +	{
   1.585 +	CleanupSurfaceAndContextL();
   1.586 +
   1.587 +	delete iFbsBitmap;
   1.588 +	iFbsBitmap = NULL;
   1.589 +	}
   1.590 +
   1.591 +EXPORT_C void CTestEglSession::CleanupSurfaceAndContextL()
   1.592 +	{
   1.593 +	ASSERT_TRUE(iSurface != EGL_NO_SURFACE);
   1.594 +	ASSERT_TRUE(iContext != EGL_NO_CONTEXT);
   1.595 +
   1.596 +	// Clean up
   1.597 +	INFO_PRINTF1(_L("Calling eglMakeCurrent(NULL values)..."));
   1.598 +	CHECK_EXPECTED_ERROR(eglMakeCurrent(iDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
   1.599 +
   1.600 +	INFO_PRINTF1(_L("Calling eglDestroyContext()..."));
   1.601 +	CHECK_EXPECTED_ERROR(eglDestroyContext(iDisplay, iContext));
   1.602 +	iContext = EGL_NO_CONTEXT;
   1.603 +
   1.604 +	INFO_PRINTF1(_L("Calling eglDestroySurface()..."));
   1.605 +	CHECK_EXPECTED_ERROR(eglDestroySurface(iDisplay, iSurface));
   1.606 +	iSurface = EGL_NO_SURFACE;
   1.607 +	}
   1.608 +
   1.609 +EXPORT_C CFbsBitmap* CTestEglSession::NativeFbsBitmap()
   1.610 +	{
   1.611 +	return iFbsBitmap;
   1.612 +	}
   1.613 +
   1.614 +EXPORT_C RSgImage& CTestEglSession::NativeSgImage()
   1.615 +	{
   1.616 +	return iSgImage;
   1.617 +	}
   1.618 +
   1.619 +EXPORT_C EGLSurface CTestEglSession::Surface() const
   1.620 +	{
   1.621 +	return iSurface;
   1.622 +	}
   1.623 +
   1.624 +EXPORT_C EGLContext CTestEglSession::Context() const
   1.625 +	{
   1.626 +	return iContext;
   1.627 +	}
   1.628 +
   1.629 +EXPORT_C EGLConfig CTestEglSession::GetConfigExactMatchL(TEglTestConfig aConfigAttribIndex, TEglConfigMatchRule aMatchRule)
   1.630 +	{
   1.631 +	if(aConfigAttribIndex >= EEglTestConfigMax )
   1.632 +		{
   1.633 +		ERR_PRINTF1(_L("Attribute index out of range, please check the INI file"));
   1.634 +		User::Leave(KErrArgument);
   1.635 +		}
   1.636 +
   1.637 +	EGLConfig configs[KMaxEglConfigs];
   1.638 +	EGLint numConfigs=0;
   1.639 +	ASSERT_EGL_TRUE(eglChooseConfig(iDisplay, KConfigAttribs[aConfigAttribIndex], configs, KMaxEglConfigs, &numConfigs));
   1.640 +	if (numConfigs <= 0)
   1.641 +		{
   1.642 +		// we just WARN, as we don't know if this is expected yet (if it is, then catch the leaving error)
   1.643 +		WARN_PRINTF1(_L("GetConfigExactMatchL - Could not find a matching config, eglChooseConfig returned 0 configs!"));
   1.644 +		User::Leave(KTestNoMatchingConfig);
   1.645 +		}
   1.646 +
   1.647 +	// Check that any of the configs returned matches the desired attributes
   1.648 +	TInt match = GetFullMatchConfigIndex(iDisplay, configs, numConfigs, KConfigAttribs[aConfigAttribIndex], aMatchRule);
   1.649 +	if (match == KErrNotFound)
   1.650 +		{
   1.651 +		// we just WARN, as we don't know if this is expected yet (if it is, then catch the leaving error)
   1.652 +		WARN_PRINTF1(_L("GetConfigExactMatchL - Could not find a matching config amongst those returned by eglChooseConfig!"));
   1.653 +		User::Leave(KTestNoMatchingConfig);
   1.654 +		}
   1.655 +	return configs[match];
   1.656 +	}
   1.657 +
   1.658 +/**
   1.659 +Creates a pixmap surface from a CFbsBitmap, draws to it and checks that the drawing operation succeeded.
   1.660 +*/
   1.661 +EXPORT_C void CTestEglSession::TryUsePixmapCFbsBitmapL()
   1.662 +	{
   1.663 +	INFO_PRINTF2(_L("thread %d: TryUsePixmapCFbsBitmapL"), iThreadIdx);
   1.664 +	EGLConfig currentConfig = GetConfigExactMatchL(EPixmapAttribsColor64K);
   1.665 +	TryUsePixmapCFbsBitmapOpenVgL(currentConfig, KPixmapSize, EColor64K);
   1.666 +	}
   1.667 +
   1.668 +/**
   1.669 +Creates a pixmap surface from a CFbsBitmap, draws to it and checks that the drawing operation succeeded.
   1.670 +*/
   1.671 +EXPORT_C void CTestEglSession::TryUsePixmapCFbsBitmapOpenVgL(EGLConfig aConfig, const TSize& aSize, TDisplayMode aDisplayMode)
   1.672 +	{
   1.673 +	CreatePixmapSurfaceAndMakeCurrentL(aConfig, aSize, aDisplayMode);
   1.674 +	DrawOpenVgL();
   1.675 +
   1.676 +	// Wait for the drawing to complete
   1.677 +	eglWaitClient();
   1.678 +
   1.679 +	CheckImageDataL(iFbsBitmap);
   1.680 +	CheckImageDataVgL(VG_sRGB_565);
   1.681 +	CleanupSurfaceFbsBitmapL();
   1.682 +	CloseFbsSession();
   1.683 +	}
   1.684 +
   1.685 +/**
   1.686 +Creates a pixmap surface from a CFbsBitmap, draws to it and checks that the drawing operation succeeded.
   1.687 +*/
   1.688 +EXPORT_C void CTestEglSession::TryUsePixmapCFbsBitmapOpenGlesL(EGLConfig aConfig, const TSize& aSize, TDisplayMode aDisplayMode, TInt aRenderVersion)
   1.689 +	{
   1.690 +	CreatePixmapSurfaceAndMakeCurrentL(aConfig, aSize, aDisplayMode,EGL_OPENGL_ES_API, aRenderVersion);
   1.691 +	DrawOpenGLesL();
   1.692 +
   1.693 +	// Wait for the drawing to complete
   1.694 +	eglWaitClient();
   1.695 +
   1.696 +	CheckImageDataFullRedishL(iFbsBitmap);
   1.697 +	CleanupSurfaceFbsBitmapL();
   1.698 +	CloseFbsSession();
   1.699 +	}
   1.700 +
   1.701 +/**
   1.702 + Creates a pixmap surface from a RSgImage, draws to it and checks that the drawing operation succeeded.
   1.703 + */
   1.704 +EXPORT_C void CTestEglSession::TryUsePixmapRSgImageL()
   1.705 +	{
   1.706 +	INFO_PRINTF2(_L("thread %d: TryUsePixmapRSgImageL"), iThreadIdx);
   1.707 +	TSgImageInfo imageInfo;
   1.708 +	imageInfo.iSizeInPixels = KPixmapSize;
   1.709 +	imageInfo.iPixelFormat = EUidPixelFormatXRGB_8888;
   1.710 +	// will draw to and read from the image using OpenVg
   1.711 +#ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
   1.712 +	imageInfo.iUsage = ESgUsageBitOpenVgSurface | ESgUsageBitOpenVgImage;
   1.713 +#else
   1.714 +    // will also read from the image using DirectGdi
   1.715 +    imageInfo.iUsage = ESgUsageOpenVgTarget | ESgUsageDirectGdiSource;
   1.716 +    imageInfo.iShareable = EFalse;
   1.717 +    imageInfo.iCpuAccess = ESgCpuAccessNone;
   1.718 +    imageInfo.iScreenId = KSgScreenIdMain;
   1.719 +    imageInfo.iUserAttributes = NULL;
   1.720 +    imageInfo.iUserAttributeCount=0;
   1.721 +#endif
   1.722 +	CreatePixmapSurfaceAndMakeCurrentAndMatchL(imageInfo, EResourceCloseSgImageLate);
   1.723 +	DrawOpenVgL();
   1.724 +
   1.725 +	// Wait for the drawing to complete
   1.726 +	 eglWaitClient();
   1.727 +
   1.728 +	//we can't retrieve data directly from the SgImage as
   1.729 +	//non-unified architecture doesn't allow readback from the GPU
   1.730 +	CheckImageDataVgL(VG_sXRGB_8888);
   1.731 +	CleanupSurfaceSgImageL();
   1.732 +	CloseSgDriver();
   1.733 +	}
   1.734 +
   1.735 +EXPORT_C TBool CTestEglSession::TryUsePixmapRSgImageOpenGlesL(EGLConfig aConfig, const TSgImageInfo& aImageInfo, TResourceCloseRule aResourceCloseRule, TInt aRenderVersion)
   1.736 +	{
   1.737 +	CreatePixmapSurfaceAndMakeCurrentL(aConfig, aImageInfo, aResourceCloseRule ,EGL_OPENGL_ES_API, aRenderVersion);
   1.738 +
   1.739 +	DrawOpenGLesL();
   1.740 +
   1.741 +	// Wait for the drawing to complete
   1.742 +	eglWaitClient();
   1.743 +
   1.744 +	//we can't retrieve data directly from SgImage as non-unified
   1.745 +	//architecture doesn't allow readback from the GPU
   1.746 +
   1.747 +	if (aImageInfo.iPixelFormat == EUidPixelFormatXRGB_8888  ||
   1.748 +		aImageInfo.iPixelFormat == EUidPixelFormatARGB_8888_PRE)
   1.749 +		{
   1.750 +		CheckImageDataGLesL();
   1.751 +		}
   1.752 +
   1.753 +	CleanupSurfaceSgImageL();
   1.754 +	CloseSgDriver();
   1.755 +	return ETrue;
   1.756 +	}
   1.757 +
   1.758 +/**
   1.759 +Compound operation that constructs an RSgImage and uses it to create a pixmap suface.
   1.760 +It then draws to the surface using OpenVG and checks whether the drawing succeeded.
   1.761 +It cleans up the pixmap surface it destroyed.
   1.762 +@param aConfig The EGL config to be used when creating the pixmap surface
   1.763 +@param aImageInfo Used to create the RSgImage pixmap
   1.764 +@param aCloseNativeImageEarly When ETrue, the RSgImage is closed as soon as the pixmap surface has been
   1.765 +		created.  Otherwise, the RSgImage is closed during cleanup, when the pixmap surface is destroyed.
   1.766 +@return Whether it was possible to create an iSgImage for the given aImageInfo
   1.767 +*/
   1.768 +EXPORT_C TBool CTestEglSession::TryUsePixmapRSgImageOpenVgL(EGLConfig aConfig, const TSgImageInfo& aImageInfo, TResourceCloseRule aResourceCloseRule)
   1.769 +	{
   1.770 +	CreatePixmapSurfaceAndMakeCurrentL(aConfig, aImageInfo, aResourceCloseRule);
   1.771 +
   1.772 +	DrawOpenVgL();
   1.773 +
   1.774 +	// Wait for the drawing to complete
   1.775 +	eglWaitClient();
   1.776 +
   1.777 +	//we can't retrieve data directly from the SgImage as
   1.778 +	//non-unified architecture doesn't allow readback from the GPU
   1.779 +	CheckImageDataVgL(VG_sXRGB_8888);
   1.780 +	CleanupSurfaceSgImageL();
   1.781 +	CloseSgDriver();
   1.782 +	return ETrue;
   1.783 +	}
   1.784 +
   1.785 +EXPORT_C void CTestEglSession::CreateWindowSurfaceAndMakeCurrentL(EGLConfig aConfig, RWindow& aWindow, TBool aVgAlphaFormatPre, EGLenum aBindAPI, TInt aRenderVersionNumber, EGLint* aAttribList)
   1.786 +	{
   1.787 +	ASSERT_EQUALS(iSurface, EGL_NO_SURFACE);
   1.788 +	ASSERT_EQUALS(iContext, EGL_NO_CONTEXT);
   1.789 +
   1.790 +	ASSERT_EGL_TRUE(eglBindAPI(aBindAPI));
   1.791 +
   1.792 +	// Create a Window surface from the native image
   1.793 +	const EGLint* windowAttribs = aAttribList;
   1.794 +    if(!windowAttribs)
   1.795 +        {
   1.796 +        windowAttribs = (aVgAlphaFormatPre && aBindAPI == EGL_OPENVG_API) ? KPixmapAttribsVgAlphaFormatPre : KPixmapAttribsNone;
   1.797 +        }
   1.798 +	iSurface = eglCreateWindowSurface(iDisplay, aConfig, &aWindow, windowAttribs);
   1.799 +	ASSERT_EGL_TRUE(iSurface != EGL_NO_SURFACE);
   1.800 +
   1.801 +	// Create a context for drawing to/reading from the pixmap surface and make it current
   1.802 +	const EGLint KAttribsListCtxNone[] = { EGL_NONE };
   1.803 +	const EGLint KAttribsListCtxGles2[] = { EGL_CONTEXT_CLIENT_VERSION, aRenderVersionNumber, EGL_NONE };
   1.804 +	const EGLint* attrib_list_ctx = (aBindAPI == EGL_OPENGL_ES_API && aRenderVersionNumber == 2) ? KAttribsListCtxGles2 : KAttribsListCtxNone;
   1.805 +	iContext = eglCreateContext(iDisplay, aConfig, EGL_NO_CONTEXT, attrib_list_ctx);
   1.806 +	ASSERT_EGL_TRUE(iContext != EGL_NO_CONTEXT);
   1.807 +	ASSERT_EGL_TRUE(eglMakeCurrent(iDisplay, iSurface, iSurface, iContext));
   1.808 +	}
   1.809 +
   1.810 +
   1.811 +EXPORT_C TBool CTestEglSession::CongfigSupportsOpenVgL(EGLConfig aConfig)
   1.812 +	{
   1.813 +	EGLint EGL_RENDERABLE_TYPE_value = 0;
   1.814 +	ASSERT_EGL_TRUE(eglGetConfigAttrib(iDisplay, aConfig, EGL_RENDERABLE_TYPE, &EGL_RENDERABLE_TYPE_value));
   1.815 +	return (EGL_RENDERABLE_TYPE_value&EGL_OPENVG_BIT)>0;
   1.816 +	}
   1.817 +
   1.818 +EXPORT_C void CTestEglSession::CreatePixmapSurfaceAndMakeCurrentAndMatchL(const TSgImageInfo& aImageInfo, TResourceCloseRule aResourceCloseRule, EGLenum aBindAPI, TInt aRenderVersionNumber)
   1.819 +	{
   1.820 +	ASSERT_EQUALS(iSurface, EGL_NO_SURFACE);
   1.821 +	ASSERT_EQUALS(iContext, EGL_NO_CONTEXT);
   1.822 +
   1.823 +    OpenSgDriverL();
   1.824 +    ASSERT_EQUALS(iSgImage.Create(aImageInfo, NULL, 0), KErrNone);
   1.825 +
   1.826 +	EGLint renderableType = 0;
   1.827 +	if(aBindAPI == EGL_OPENVG_API)
   1.828 +		{
   1.829 +		renderableType = EGL_OPENVG_BIT;
   1.830 +		}
   1.831 +	else if(aBindAPI == EGL_OPENGL_ES_API && aRenderVersionNumber==1)
   1.832 +		{
   1.833 +		renderableType = EGL_OPENGL_ES_BIT;
   1.834 +		}
   1.835 +	else if(aBindAPI == EGL_OPENGL_ES_API && aRenderVersionNumber==2)
   1.836 +		{
   1.837 +		renderableType = EGL_OPENGL_ES2_BIT;
   1.838 +		}
   1.839 +	else
   1.840 +		{
   1.841 +		ERR_PRINTF1(_L("CreatePixmapSurfaceAndMakeCurrentAndMatchL - Unkown API requested!"));
   1.842 +		User::Leave(KErrArgument);
   1.843 +		}
   1.844 +	EGLint attrib_list[] = {
   1.845 +			  EGL_MATCH_NATIVE_PIXMAP,(TInt)&iSgImage,
   1.846 +			  EGL_RENDERABLE_TYPE,renderableType,
   1.847 +			  EGL_SURFACE_TYPE,EGL_PIXMAP_BIT,
   1.848 +			  EGL_NONE};
   1.849 +
   1.850 +	ASSERT_EGL_TRUE(eglBindAPI(aBindAPI));
   1.851 +
   1.852 +	EGLConfig config;
   1.853 +	EGLint numConfigs;
   1.854 +	ASSERT_EGL_TRUE(eglChooseConfig(iDisplay,attrib_list,&config,1,&numConfigs));
   1.855 +	if (numConfigs <= 0)
   1.856 +		{
   1.857 +		// we just WARN, as we don't know if this is expected yet (if it is, then catch the leaving error)
   1.858 +		WARN_PRINTF1(_L("CreatePixmapSurfaceAndMakeCurrentAndMatchL - Could not find a matching config!"));
   1.859 +		iSgImage.Close();
   1.860 +		CloseSgDriver();
   1.861 +		// Leave with a unique knonwn error code - useful to catch this error in negative tests
   1.862 +		User::Leave(KTestNoMatchingConfig);
   1.863 +		}
   1.864 +
   1.865 +	// Create a pixmap surface from the native image
   1.866 +	EGLint EGL_RENDERABLE_TYPE_value = 0;
   1.867 +	ASSERT_EGL_TRUE(eglGetConfigAttrib(iDisplay, config, EGL_RENDERABLE_TYPE, &EGL_RENDERABLE_TYPE_value));
   1.868 +	const EGLint* pixmapAttribs = ((aImageInfo.iPixelFormat == EUidPixelFormatARGB_8888_PRE) && (EGL_RENDERABLE_TYPE_value & EGL_OPENVG_BIT)) ? KPixmapAttribsVgAlphaFormatPre : KPixmapAttribsNone;
   1.869 +	iSurface = eglCreatePixmapSurface(iDisplay, config, &iSgImage, pixmapAttribs);
   1.870 +	ASSERT_EGL_TRUE(iSurface != EGL_NO_SURFACE);
   1.871 +
   1.872 +	if (aResourceCloseRule == EResourceCloseSgImageEarly)
   1.873 +		{
   1.874 +		// EGL should have taken its own reference to the SgImage, so it should be able to continue
   1.875 +		// to use the underlying data after this local image has been closed.
   1.876 +		iSgImage.Close();
   1.877 +		}
   1.878 +
   1.879 +	if (aResourceCloseRule == EResourceCloseSgDriverAndImageEarly)
   1.880 +		{
   1.881 +		// EGL should have taken its own reference to the SgDriver, so it should be able to continue
   1.882 +		// to use its reference to the image resource after this local reference to the driver has
   1.883 +		// been closed.
   1.884 +		iSgImage.Close();
   1.885 +		CloseSgDriver();
   1.886 +		}
   1.887 +
   1.888 +	// Create a context for drawing to/reading from the pixmap surface and make it current
   1.889 +	const EGLint KAttribsListCtxNone[] = { EGL_NONE };
   1.890 +	const EGLint KAttribsListCtxGles2[] = { EGL_CONTEXT_CLIENT_VERSION, aRenderVersionNumber, EGL_NONE };
   1.891 +	const EGLint* attrib_list_ctx = (aBindAPI == EGL_OPENGL_ES_API && aRenderVersionNumber == 2) ? KAttribsListCtxGles2 : KAttribsListCtxNone; 
   1.892 +	iContext = eglCreateContext(iDisplay, config, EGL_NO_CONTEXT, attrib_list_ctx);
   1.893 +	ASSERT_EGL_TRUE(iContext != EGL_NO_CONTEXT);	
   1.894 +	ASSERT_EGL_TRUE(eglMakeCurrent(iDisplay, iSurface, iSurface, iContext));
   1.895 +	}
   1.896 +
   1.897 +/**
   1.898 +Compound operation that constructs an RSgImage and uses it to create a pixmap suface.
   1.899 +It then makes it current to the thread.
   1.900 +@param aConfig The EGL config to be used when creating the pixmap surface
   1.901 +@param aImageInfo Used to create the RSgImage pixmap
   1.902 +@param aCloseNativeImageEarly When ETrue, the RSgImage is closed as soon as the pixmap surface has been
   1.903 +		created.  Otherwise, the RSgImage is left to be destroyed later by some other method
   1.904 +		- e.g at the same time as destroying the surface.
   1.905 +@return Whether it was possible to create an iSgImage for the given aImageInfo
   1.906 +*/
   1.907 +EXPORT_C void CTestEglSession::CreatePixmapSurfaceAndMakeCurrentL(EGLConfig aConfig, const TSgImageInfo& aImageInfo, TResourceCloseRule aResourceCloseRule, EGLenum aBindAPI, TInt aRenderVersionNumber)
   1.908 +	{
   1.909 +	ASSERT_EQUALS(iSurface, EGL_NO_SURFACE);
   1.910 +	ASSERT_EQUALS(iContext, EGL_NO_CONTEXT);
   1.911 +
   1.912 +	OpenSgDriverL();
   1.913 +    ASSERT_EQUALS(iSgImage.Create(aImageInfo, NULL, 0), KErrNone);
   1.914 +
   1.915 +	ASSERT_EGL_TRUE(eglBindAPI(aBindAPI));
   1.916 +
   1.917 +	// Create a pixmap surface from the native image
   1.918 +	EGLint EGL_RENDERABLE_TYPE_value = 0;
   1.919 +	ASSERT_EGL_TRUE(eglGetConfigAttrib(iDisplay, aConfig, EGL_RENDERABLE_TYPE, &EGL_RENDERABLE_TYPE_value));
   1.920 +	const EGLint* pixmapAttribs = ((aImageInfo.iPixelFormat == EUidPixelFormatARGB_8888_PRE) && (EGL_RENDERABLE_TYPE_value & EGL_OPENVG_BIT)) ? KPixmapAttribsVgAlphaFormatPre : KPixmapAttribsNone;
   1.921 +	iSurface = eglCreatePixmapSurface(iDisplay, aConfig, &iSgImage, pixmapAttribs);
   1.922 +	ASSERT_EGL_TRUE(iSurface != EGL_NO_SURFACE);
   1.923 +
   1.924 +	if (aResourceCloseRule == EResourceCloseSgImageEarly)
   1.925 +		{
   1.926 +		// EGL should have taken its own reference to the SgImage, so it should be able to continue
   1.927 +		// to use the underlying data after this local image has been closed.
   1.928 +		iSgImage.Close();
   1.929 +		}
   1.930 +	if (aResourceCloseRule == EResourceCloseSgDriverAndImageEarly)
   1.931 +		{
   1.932 +		// EGL should have taken its own reference to the SgDriver, so it should be able to continue
   1.933 +		// to use its reference to the image resource after this local reference to the driver has
   1.934 +		// been closed.
   1.935 +		iSgImage.Close();
   1.936 +		CloseSgDriver();
   1.937 +		}
   1.938 +
   1.939 +	// Create a context for drawing to/reading from the pixmap surface and make it current
   1.940 +	const EGLint KAttribsListCtxNone[] = { EGL_NONE };
   1.941 +	const EGLint KAttribsListCtxGles2[] = { EGL_CONTEXT_CLIENT_VERSION, aRenderVersionNumber, EGL_NONE };
   1.942 +	const EGLint* attrib_list_ctx = (aBindAPI == EGL_OPENGL_ES_API && aRenderVersionNumber == 2) ? KAttribsListCtxGles2 : KAttribsListCtxNone;
   1.943 +	iContext = eglCreateContext(iDisplay, aConfig, EGL_NO_CONTEXT, attrib_list_ctx);
   1.944 +	ASSERT_EGL_TRUE(iContext != EGL_NO_CONTEXT);
   1.945 +	ASSERT_EGL_TRUE(eglMakeCurrent(iDisplay, iSurface, iSurface, iContext));
   1.946 +	}
   1.947 +
   1.948 +EXPORT_C TInt CTestEglSession::CreateBitmap(CFbsBitmap* aFbsBitmap, const TSize& aSize, TDisplayMode aDisplayMode)
   1.949 +	{
   1.950 +	//Fist try with CreateHardwareBitmap to check whether we are on hardware
   1.951 +	TInt result = aFbsBitmap->CreateHardwareBitmap(aSize, aDisplayMode, KUidEglTestServer);
   1.952 +
   1.953 +	if(result == KErrNotSupported)
   1.954 +		{
   1.955 +		//we are not on hardware
   1.956 +		result = aFbsBitmap->Create(aSize, aDisplayMode);
   1.957 +		}
   1.958 +	return result;
   1.959 +	}
   1.960 +
   1.961 +EXPORT_C void CTestEglSession::CreatePixmapSurfaceAndMakeCurrentL(EGLConfig aConfig, const TSize& aSize, TDisplayMode displayMode, EGLenum aBindAPI, TInt aRenderVersionNumber)
   1.962 +	{
   1.963 +	ASSERT_EQUALS(iSurface, EGL_NO_SURFACE);
   1.964 +	ASSERT_EQUALS(iContext, EGL_NO_CONTEXT);
   1.965 +
   1.966 +	// Create an empty native CFbsBitmap
   1.967 +	OpenFbsSessionL();
   1.968 +	iFbsBitmap = new(ELeave)CFbsBitmap;
   1.969 +	ASSERT_EQUALS(CreateBitmap(iFbsBitmap, aSize, displayMode), KErrNone);
   1.970 +
   1.971 +    const EGLint* attrib_list = NULL;
   1.972 +	if(aBindAPI == EGL_OPENVG_API)
   1.973 +		{
   1.974 +		// no attribs to modify
   1.975 +		}
   1.976 +	else if(aBindAPI == EGL_OPENGL_ES_API)
   1.977 +		{
   1.978 +		// no attribs to modify
   1.979 +		}
   1.980 +	else if(aBindAPI == EGL_OPENGL_ES_API && aRenderVersionNumber==2)
   1.981 +		{
   1.982 +	    const EGLint KAttribGLES2[] = {EGL_CONTEXT_CLIENT_VERSION, aRenderVersionNumber, EGL_NONE};
   1.983 +		attrib_list=KAttribGLES2;
   1.984 +		}
   1.985 +	else
   1.986 +		{
   1.987 +		ERR_PRINTF1(_L("CreatePixmapSurfaceAndMakeCurrentL - Unkown API requested!"));
   1.988 +		User::Leave(KErrArgument);
   1.989 +		}
   1.990 +	ASSERT_EGL_TRUE(eglBindAPI(aBindAPI));
   1.991 +
   1.992 +	// Create a pixmap surface from the native image
   1.993 +	EGLint EGL_RENDERABLE_TYPE_value = 0;
   1.994 +	ASSERT_EGL_TRUE(eglGetConfigAttrib(iDisplay, aConfig, EGL_RENDERABLE_TYPE, &EGL_RENDERABLE_TYPE_value));
   1.995 +	const EGLint* pixmapAttribs = ((displayMode == EColor16MAP) && (EGL_RENDERABLE_TYPE_value & EGL_OPENVG_BIT)) ? KPixmapAttribsVgAlphaFormatPre : KPixmapAttribsNone;
   1.996 +	iSurface = eglCreatePixmapSurface(iDisplay, aConfig, iFbsBitmap, pixmapAttribs);
   1.997 +	ASSERT_EGL_TRUE(iSurface != EGL_NO_SURFACE);
   1.998 +
   1.999 +	// Create a context for drawing to/reading from the pixmap surface and make it current
  1.1000 +	iContext = eglCreateContext(iDisplay, aConfig, EGL_NO_CONTEXT, attrib_list);
  1.1001 +	ASSERT_EGL_TRUE(iContext != EGL_NO_CONTEXT);
  1.1002 +	ASSERT_EGL_TRUE(eglMakeCurrent(iDisplay, iSurface, iSurface, iContext));
  1.1003 +	}
  1.1004 +
  1.1005 +EXPORT_C void CTestEglSession::CreatePixmapSurfaceAndMakeCurrentAndMatchL(const TSize& aSize, TDisplayMode aDisplayMode, EGLenum aBindAPI, TInt aRenderVersionNumber)
  1.1006 +	{
  1.1007 +	ASSERT_EQUALS(iSurface, EGL_NO_SURFACE);
  1.1008 +	ASSERT_EQUALS(iContext, EGL_NO_CONTEXT);
  1.1009 +
  1.1010 +	OpenFbsSessionL();
  1.1011 +	iFbsBitmap = new(ELeave)CFbsBitmap;
  1.1012 +	ASSERT_EQUALS(CreateBitmap(iFbsBitmap, aSize, aDisplayMode), KErrNone);
  1.1013 +
  1.1014 +	EGLint renderableType = 0;
  1.1015 +	if(aBindAPI == EGL_OPENVG_API)
  1.1016 +		{
  1.1017 +		renderableType = EGL_OPENVG_BIT;
  1.1018 +		}
  1.1019 +	else if(aBindAPI == EGL_OPENGL_ES_API && aRenderVersionNumber==1)
  1.1020 +		{
  1.1021 +		renderableType = EGL_OPENGL_ES_BIT;
  1.1022 +		}
  1.1023 +	else if(aBindAPI == EGL_OPENGL_ES_API && aRenderVersionNumber==2)
  1.1024 +		{
  1.1025 +		renderableType = EGL_OPENGL_ES2_BIT;
  1.1026 +		}
  1.1027 +	else
  1.1028 +		{
  1.1029 +		ERR_PRINTF1(_L("CreatePixmapSurfaceAndMakeCurrentAndMatchL - Unkown API requested!"));
  1.1030 +		User::Leave(KErrArgument);
  1.1031 +		}
  1.1032 +	EGLint attrib_list[] = {
  1.1033 +			  EGL_MATCH_NATIVE_PIXMAP,(TInt)iFbsBitmap,
  1.1034 +			  EGL_RENDERABLE_TYPE,renderableType,
  1.1035 +			  EGL_SURFACE_TYPE,EGL_PIXMAP_BIT,
  1.1036 +			  EGL_NONE};
  1.1037 +
  1.1038 +	ASSERT_EGL_TRUE(eglBindAPI(aBindAPI));
  1.1039 +
  1.1040 +	EGLConfig config;
  1.1041 +	EGLint numConfigs;
  1.1042 +	ASSERT_EGL_TRUE(eglChooseConfig(iDisplay,attrib_list,&config,1,&numConfigs));
  1.1043 +	if (numConfigs <= 0)
  1.1044 +		{
  1.1045 +		// we just WARN, as we don't know if this is expected yet (if it is, then catch the leaving error)
  1.1046 +		WARN_PRINTF1(_L("CreatePixmapSurfaceAndMakeCurrentAndMatchL - Could not find a matching config!"));
  1.1047 +		iSgImage.Close();
  1.1048 +		CloseSgDriver();
  1.1049 +		// Leave with a unique knonwn error code - useful to catch this error in negative tests
  1.1050 +		User::Leave(KTestNoMatchingConfig);
  1.1051 +		}
  1.1052 +
  1.1053 +	// Create a pixmap surface from the native image
  1.1054 +	const EGLint* pixmapAttribs = (aDisplayMode == EColor16MAP && aBindAPI == EGL_OPENVG_API) ? KPixmapAttribsVgAlphaFormatPre : KPixmapAttribsNone;
  1.1055 +	iSurface = eglCreatePixmapSurface(iDisplay, config, iFbsBitmap, pixmapAttribs);
  1.1056 +	ASSERT_EGL_TRUE(iSurface != EGL_NO_SURFACE);
  1.1057 +
  1.1058 +	// Create a context for drawing to/reading from the pixmap surface and make it current
  1.1059 +	const EGLint KAttribsListCtxNone[] = { EGL_NONE };
  1.1060 +	const EGLint KAttribsListCtxGles2[] = { EGL_CONTEXT_CLIENT_VERSION, aRenderVersionNumber, EGL_NONE };
  1.1061 +	const EGLint* attrib_list_ctx = (aBindAPI == EGL_OPENGL_ES_API && aRenderVersionNumber == 2) ? KAttribsListCtxGles2 : KAttribsListCtxNone;
  1.1062 +	iContext = eglCreateContext(iDisplay, config, EGL_NO_CONTEXT, attrib_list_ctx);
  1.1063 +	ASSERT_EGL_TRUE(iContext != EGL_NO_CONTEXT);
  1.1064 +	ASSERT_EGL_TRUE(eglMakeCurrent(iDisplay, iSurface, iSurface, iContext));
  1.1065 +	}
  1.1066 +
  1.1067 +EXPORT_C void CTestEglSession::CreatePbufferSurfaceAndMakeCurrentL(EGLConfig aConfig, const TSize& aSize, EGLenum aBindAPI, TInt aRenderVersionNumber)
  1.1068 +	{
  1.1069 +	ASSERT_EQUALS(iSurface, EGL_NO_SURFACE);
  1.1070 +	ASSERT_EQUALS(iContext, EGL_NO_CONTEXT);
  1.1071 +
  1.1072 +	ASSERT_EQUALS(iSurface, EGL_NO_SURFACE);
  1.1073 +	ASSERT_EQUALS(iContext, EGL_NO_CONTEXT);
  1.1074 +
  1.1075 +	ASSERT_EGL_TRUE(eglBindAPI(aBindAPI));
  1.1076 +
  1.1077 +	//	PBuffer attribs options are:
  1.1078 +	//		EGL_WIDTH, EGL_HEIGHT, EGL_LARGEST_PBUFFER,
  1.1079 +	//		EGL_TEXTURE_FORMAT, EGL_TEXTURE_TARGET, EGL_MIPMAP_TEXTURE,
  1.1080 +	//		EGL_VG_COLORSPACE, and EGL_VG_ALPHA_FORMAT
  1.1081 +	// Create a pbuffer surface of the given size
  1.1082 +	const EGLint KPbufferAttribs[] = {
  1.1083 +			EGL_WIDTH,	aSize.iWidth,
  1.1084 +			EGL_HEIGHT,	aSize.iHeight,
  1.1085 +			EGL_NONE };
  1.1086 +	iSurface = eglCreatePbufferSurface(iDisplay, aConfig, KPbufferAttribs);
  1.1087 +	ASSERT_EGL_TRUE(iSurface != EGL_NO_SURFACE);
  1.1088 +
  1.1089 +	// Create a context for drawing to/reading from the pixmap surface and make it current
  1.1090 +	const EGLint KAttribsListCtxNone[] = { EGL_NONE };
  1.1091 +	const EGLint KAttribsListCtxGles2[] = { EGL_CONTEXT_CLIENT_VERSION, aRenderVersionNumber, EGL_NONE };
  1.1092 +	const EGLint* attrib_list_ctx = (aBindAPI == EGL_OPENGL_ES_API && aRenderVersionNumber == 2) ? KAttribsListCtxGles2 : KAttribsListCtxNone;
  1.1093 +	iContext = eglCreateContext(iDisplay, aConfig, EGL_NO_CONTEXT, attrib_list_ctx);
  1.1094 +	ASSERT_EGL_TRUE(iContext != EGL_NO_CONTEXT);
  1.1095 +	ASSERT_EGL_TRUE(eglMakeCurrent(iDisplay, iSurface, iSurface, iContext));
  1.1096 +	}
  1.1097 +
  1.1098 +EXPORT_C void CTestEglSession::DrawOpenVgL()
  1.1099 +	{
  1.1100 +	ASSERT_TRUE(iSurface != EGL_NO_SURFACE);
  1.1101 +	ASSERT_TRUE(iContext != EGL_NO_CONTEXT);
  1.1102 +
  1.1103 +	// Draw to the pixmap surface
  1.1104 +	// Clear it: redish
  1.1105 +	VGfloat colorBackground[4];
  1.1106 +	ConvertColor(KRgbReddish, colorBackground);
  1.1107 +	vgSetfv(VG_CLEAR_COLOR, 4, colorBackground);
  1.1108 +	vgClear(0, 0, KPixmapSize.iWidth, KPixmapSize.iHeight);
  1.1109 +
  1.1110 +	// And add a square: greenish
  1.1111 +	VGfloat colorSquare[4];
  1.1112 +	ConvertColor(KRgbGreenish, colorSquare);
  1.1113 +	vgSetfv(VG_CLEAR_COLOR, 4, colorSquare);
  1.1114 +	vgClear(KPixmapSquare.iTl.iX, KPixmapSquare.iTl.iX, KPixmapSquare.Width(), KPixmapSquare.Height());
  1.1115 +	}
  1.1116 +
  1.1117 +EXPORT_C void CTestEglSession::DrawOpenGLesL()
  1.1118 +	{
  1.1119 +	ASSERT_TRUE(iSurface != EGL_NO_SURFACE);
  1.1120 +	ASSERT_TRUE(iContext != EGL_NO_CONTEXT);
  1.1121 +	//GreenishRGB 0x46, 0xDC, 0x78
  1.1122 +	const GLfloat glRed = KRgbReddish.Red();
  1.1123 +	const GLfloat glGreen = KRgbReddish.Green();
  1.1124 +	const GLfloat glBlue  = KRgbReddish.Blue();
  1.1125 +	const GLfloat glAlpha = KRgbReddish.Alpha();
  1.1126 +	const GLfloat glRedBits = 255.f;
  1.1127 +	const GLfloat glGreenBits = 255.f;
  1.1128 +	const GLfloat glBlueBits  = 255.f;
  1.1129 +	const GLfloat glAlphaBits = 255.f;
  1.1130 +
  1.1131 +	// Disable  cdither - when using exact comparison to reference bitmap
  1.1132 +	// because reference bitmap cannot be created to match dither exactly
  1.1133 +	glDisable(GL_DITHER);
  1.1134 +	// Clear the surface to the colour specified
  1.1135 +	glClearColor((glRed)/glRedBits, (glGreen)/glGreenBits, (glBlue)/glBlueBits, glAlpha/glAlphaBits);
  1.1136 +
  1.1137 +	//glColor3f(KRgbGreenish.Red(),KRgbGreenish.Green(),KRgbGreenish.Blue());
  1.1138 +	//glRectf(KPixmapSquare.iTl.iX, KPixmapSquare.iTl.iY,KPixmapSquare.iTl.iX + KPixmapSquare.Width(),KPixmapSquare.iTl.iY + KPixmapSquare.Height());
  1.1139 +
  1.1140 +	glClear(GL_COLOR_BUFFER_BIT);
  1.1141 +	}
  1.1142 +
  1.1143 +EXPORT_C void CTestEglSession::CheckImageDataL(CFbsBitmap* aFbsBitmap)
  1.1144 +	{
  1.1145 +	// Use native API's to check pixel values in the surface - note that this is not an OpenVG test, so no boundary pixels are tested
  1.1146 +	TRgb rgbPixelSample;
  1.1147 +	// Outside the square
  1.1148 +	aFbsBitmap->GetPixel(rgbPixelSample, TPoint(10,10));
  1.1149 +	ASSERT_TRUE(PixelsMatch(KRgbReddish, rgbPixelSample, EFalse));
  1.1150 +	aFbsBitmap->GetPixel(rgbPixelSample, TPoint(90,90));
  1.1151 +	ASSERT_TRUE(PixelsMatch(KRgbReddish, rgbPixelSample, EFalse));
  1.1152 +
  1.1153 +	// Inside the square
  1.1154 +	aFbsBitmap->GetPixel(rgbPixelSample, TPoint(30,30));
  1.1155 +	ASSERT_TRUE(PixelsMatch(KRgbGreenish, rgbPixelSample, EFalse));
  1.1156 +	aFbsBitmap->GetPixel(rgbPixelSample, TPoint(70,70));
  1.1157 +	ASSERT_TRUE(PixelsMatch(KRgbGreenish, rgbPixelSample, EFalse));
  1.1158 +	}
  1.1159 +
  1.1160 +EXPORT_C void CTestEglSession::CheckImageDataFullRedishL(CFbsBitmap* aFbsBitmap)
  1.1161 +	{
  1.1162 +	// Use native API's to check pixel values in the surface - note that this is not an OpenVG test, so no boundary pixels are tested
  1.1163 +	TRgb rgbPixelSample;
  1.1164 +	// Outside the square
  1.1165 +	aFbsBitmap->GetPixel(rgbPixelSample, TPoint(10,10));
  1.1166 +	ASSERT_TRUE(PixelsMatch(KRgbReddish, rgbPixelSample, EFalse));
  1.1167 +	aFbsBitmap->GetPixel(rgbPixelSample, TPoint(90,90));
  1.1168 +	ASSERT_TRUE(PixelsMatch(KRgbReddish, rgbPixelSample, EFalse));
  1.1169 +
  1.1170 +	// Inside the square
  1.1171 +	aFbsBitmap->GetPixel(rgbPixelSample, TPoint(30,30));
  1.1172 +	ASSERT_TRUE(PixelsMatch(KRgbReddish, rgbPixelSample, EFalse));
  1.1173 +	aFbsBitmap->GetPixel(rgbPixelSample, TPoint(70,70));
  1.1174 +	ASSERT_TRUE(PixelsMatch(KRgbReddish, rgbPixelSample, EFalse));
  1.1175 +	}
  1.1176 +
  1.1177 +/**
  1.1178 +Use OpenVG to check pixel values
  1.1179 +@param aDataFormat The VG image data format of the current surface
  1.1180 +*/
  1.1181 +EXPORT_C void CTestEglSession::CheckImageDataVgL(VGImageFormat aDataFormat)
  1.1182 +	{
  1.1183 +	switch(aDataFormat)
  1.1184 +		{
  1.1185 +		case VG_sRGB_565:
  1.1186 +			{
  1.1187 +			TUint16 intPixelSample=0;
  1.1188 +
  1.1189 +			// Outside the square
  1.1190 +			vgReadPixels(&intPixelSample, 1, aDataFormat, 10,10, 1,1);
  1.1191 +			ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color64K(intPixelSample), EFalse));
  1.1192 +			vgReadPixels(&intPixelSample, 1, aDataFormat, 90,90, 1,1);
  1.1193 +			ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color64K(intPixelSample), EFalse));
  1.1194 +
  1.1195 +			// Inside the square
  1.1196 +			vgReadPixels(&intPixelSample, 1, aDataFormat, 30,30, 1,1);
  1.1197 +			ASSERT_TRUE(PixelsMatch(KRgbGreenish, TRgb::Color64K(intPixelSample), EFalse));
  1.1198 +			vgReadPixels(&intPixelSample, 1, aDataFormat, 70,70, 1,1);
  1.1199 +			ASSERT_TRUE(PixelsMatch(KRgbGreenish, TRgb::Color64K(intPixelSample), EFalse));
  1.1200 +			break;
  1.1201 +			}
  1.1202 +		case VG_sXRGB_8888:
  1.1203 +			{
  1.1204 +			TUint32 intPixelSample=0;
  1.1205 +
  1.1206 +			// Outside the square
  1.1207 +			vgReadPixels(&intPixelSample, 1, aDataFormat, 10,10, 1,1);
  1.1208 +			ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color16MU(intPixelSample), EFalse));
  1.1209 +			vgReadPixels(&intPixelSample, 1, aDataFormat, 90,90, 1,1);
  1.1210 +			ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color16MU(intPixelSample), EFalse));
  1.1211 +
  1.1212 +			// Inside the square
  1.1213 +			vgReadPixels(&intPixelSample, 1, aDataFormat, 30,30, 1,1);
  1.1214 +			ASSERT_TRUE(PixelsMatch(KRgbGreenish, TRgb::Color16MU(intPixelSample), EFalse));
  1.1215 +			vgReadPixels(&intPixelSample, 1, aDataFormat, 70,70, 1,1);
  1.1216 +			ASSERT_TRUE(PixelsMatch(KRgbGreenish, TRgb::Color16MU(intPixelSample), EFalse));
  1.1217 +			break;
  1.1218 +			}
  1.1219 +		case VG_sARGB_8888:
  1.1220 +			{
  1.1221 +			TUint32 intPixelSample=0;
  1.1222 +
  1.1223 +			// Outside the square
  1.1224 +			vgReadPixels(&intPixelSample, 1, aDataFormat, 10,10, 1,1);
  1.1225 +			ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color16MA(intPixelSample), EFalse));
  1.1226 +			vgReadPixels(&intPixelSample, 1, aDataFormat, 90,90, 1,1);
  1.1227 +			ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color16MA(intPixelSample), EFalse));
  1.1228 +
  1.1229 +			// Inside the square
  1.1230 +			vgReadPixels(&intPixelSample, 1, aDataFormat, 30,30, 1,1);
  1.1231 +			ASSERT_TRUE(PixelsMatch(KRgbGreenish, TRgb::Color16MA(intPixelSample), EFalse));
  1.1232 +			vgReadPixels(&intPixelSample, 1, aDataFormat, 70,70, 1,1);
  1.1233 +			ASSERT_TRUE(PixelsMatch(KRgbGreenish, TRgb::Color16MA(intPixelSample), EFalse));
  1.1234 +			break;
  1.1235 +			}
  1.1236 +		default:
  1.1237 +			WARN_PRINTF2(_L("Unexpected image data format %d in CTestEglSession::CheckImageDataVgL"), aDataFormat);
  1.1238 +			ASSERT_TRUE(EFalse);
  1.1239 +		}
  1.1240 +	}
  1.1241 +
  1.1242 +/**
  1.1243 +Use OpenGLes to check pixel values
  1.1244 +@param aDataFormat The VG image data format of the current surface
  1.1245 +*/
  1.1246 +EXPORT_C void CTestEglSession::CheckImageDataGLesL()
  1.1247 +	{
  1.1248 +	TUint32 intPixelSample;
  1.1249 +	glReadPixels(10,10,1,1,GL_RGBA,GL_UNSIGNED_BYTE ,&intPixelSample);
  1.1250 +	SwapChannels(intPixelSample);
  1.1251 +	ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color16MU(intPixelSample), EFalse));
  1.1252 +
  1.1253 +	glReadPixels(45,45,1,1,GL_RGBA,GL_UNSIGNED_BYTE ,&intPixelSample);
  1.1254 +	SwapChannels(intPixelSample);
  1.1255 +	ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color16MU(intPixelSample), EFalse));
  1.1256 +
  1.1257 +	glReadPixels(55,55,1,1,GL_RGBA,GL_UNSIGNED_BYTE ,&intPixelSample);
  1.1258 +	SwapChannels(intPixelSample);
  1.1259 +	ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color16MU(intPixelSample), EFalse));
  1.1260 +
  1.1261 +	glReadPixels(99,99,1,1,GL_RGBA,GL_UNSIGNED_BYTE ,&intPixelSample);
  1.1262 +	SwapChannels(intPixelSample);
  1.1263 +	ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color16MU(intPixelSample), EFalse));
  1.1264 +
  1.1265 +	}
  1.1266 +
  1.1267 +EXPORT_C void CTestEglSession::SwapChannels(TUint32 &aSwapMe)
  1.1268 +	{
  1.1269 +	TUint32 buff = aSwapMe;
  1.1270 +
  1.1271 +	aSwapMe = 0;
  1.1272 +	aSwapMe |= (buff & 0x000000FF) << 16;
  1.1273 +	aSwapMe |= (buff & 0x0000FF00);
  1.1274 +	aSwapMe |= (buff & 0x00FF0000) >> 16;
  1.1275 +	aSwapMe |= (buff & 0xFF000000);
  1.1276 +	}
  1.1277 +
  1.1278 +/**
  1.1279 +Destroys the surface and underlying RSgImage object.
  1.1280 +Nulls the current context.
  1.1281 +*/
  1.1282 +EXPORT_C void CTestEglSession::CleanupSurfaceSgImageL()
  1.1283 +	{
  1.1284 +	CleanupSurfaceAndContextL();
  1.1285 +
  1.1286 +	iSgImage.Close();
  1.1287 +	}
  1.1288 +
  1.1289 +/**
  1.1290 +Resets the internal surface and context handles without destroying them.
  1.1291 +Also closes the internal RSgImage handled that is associated to the surface.
  1.1292 +
  1.1293 +EGL destroys all surface and context handles associated with a display when
  1.1294 +eglTerminate() is called.
  1.1295 +*/
  1.1296 +EXPORT_C void CTestEglSession::ResetSurfaceAndContextSgImageL()
  1.1297 +	{
  1.1298 +	INFO_PRINTF1(_L("CTestEglSession::ResetSurfaceAndContextSgImageL()"));
  1.1299 +
  1.1300 +	iContext = EGL_NO_CONTEXT;
  1.1301 +	iSurface = EGL_NO_SURFACE;
  1.1302 +	iSgImage.Close();
  1.1303 +	}
  1.1304 +
  1.1305 +/**
  1.1306 + Check that the pixel values match within a predefined tolerance
  1.1307 + @param aExpected the expected pixel colour vaule
  1.1308 + @param aActual the actual pixel colour value
  1.1309 + @param aCheckAlpha Whether to check the alpha channel value
  1.1310 + @return Whether the pixel values match - within the allowed tolerance
  1.1311 + */
  1.1312 +EXPORT_C TBool CTestEglSession::PixelsMatch(const TRgb& aExpected, const TRgb& aActual, TBool aCheckAlpha)
  1.1313 +	{
  1.1314 +	// This value has been carefully selected. If it is too high it could be hidding genuine pixel value
  1.1315 +	//	differences, while too low will be too strict to allow for pixel conversions, i.e. from 16bpp to 32bpp
  1.1316 +	const TInt KPixelTolerance = 8;
  1.1317 +
  1.1318 +	if (aCheckAlpha && aExpected.Alpha()== 0 &&
  1.1319 +		aActual.Red() == 0 &&
  1.1320 +		aActual.Green() == 0 &&
  1.1321 +		aActual.Blue() == 0 &&
  1.1322 +		aActual.Alpha() == 0)
  1.1323 +		{
  1.1324 +		// if the expected value for alpha is 0, all actual values should be 0
  1.1325 +		return ETrue;
  1.1326 +		}
  1.1327 +	else if (Abs(aExpected.Red() - aActual.Red()) > KPixelTolerance ||
  1.1328 +			 Abs(aExpected.Green() - aActual.Green()) > KPixelTolerance ||
  1.1329 +			 Abs(aExpected.Blue() - aActual.Blue()) > KPixelTolerance ||
  1.1330 +			 aCheckAlpha && Abs(aExpected.Alpha() - aActual.Alpha()) > KPixelTolerance)
  1.1331 +		{
  1.1332 +		// one or more of the actual values differ by more than the allowed tolerance
  1.1333 +		ERR_PRINTF6(_L("thread %d: Expected r:%d g:%d b:%d a:%d"), iThreadIdx, aExpected.Red(), aExpected.Green(), aExpected.Blue(), aExpected.Alpha());
  1.1334 +		ERR_PRINTF6(_L("thread %d: Actual r:%d g:%d b:%d a:%d"), iThreadIdx, aActual.Red(), aActual.Green(), aActual.Blue(), aActual.Alpha());
  1.1335 +		ERR_PRINTF6(_L("thread %d: diff r:%d g:%d b:%d a:%d"), iThreadIdx, Abs(aExpected.Red() - aActual.Red()), Abs(aExpected.Green() - aActual.Green()), Abs(aExpected.Blue() - aActual.Blue()), Abs(aExpected.Alpha() - aActual.Alpha()));
  1.1336 +		return EFalse;
  1.1337 +		}
  1.1338 +	return ETrue;
  1.1339 +	}
  1.1340 +
  1.1341 +EXPORT_C void CTestEglSession::InitializeL(TBool aTerminateDisplay)
  1.1342 +	{
  1.1343 +	// Initialize display object
  1.1344 +	INFO_PRINTF2(_L("thread %d: Calling eglInitialize..."), iThreadIdx);
  1.1345 +	EGLint major=0;
  1.1346 +	EGLint minor=0;
  1.1347 +	CHECK_EXPECTED_ERROR(eglInitialize(iDisplay, &major, &minor));
  1.1348 +	// Remember if the user wants us to terminate the display.
  1.1349 +	iTerminateDisplay = aTerminateDisplay;
  1.1350 +
  1.1351 +	INFO_PRINTF4(_L("thread %d: Initialised: EGL Version %d.%d"), iThreadIdx, major, minor);
  1.1352 +	}
  1.1353 +
  1.1354 +
  1.1355 +EXPORT_C void CTestEglSession::TerminateDisplayL()
  1.1356 +	{
  1.1357 +	if (iSurface != EGL_NO_SURFACE)
  1.1358 +		{
  1.1359 +		WARN_PRINTF2(_L("thread %d: iSurface has not been destoroyed in TerminateDisplayL..."), iThreadIdx);
  1.1360 +		}
  1.1361 +	if (iContext != EGL_NO_CONTEXT)
  1.1362 +		{
  1.1363 +		WARN_PRINTF2(_L("thread %d: iContext has not been destoroyed in TerminateDisplayL..."), iThreadIdx);
  1.1364 +		}
  1.1365 +	if (iDisplay != EGL_NO_DISPLAY)
  1.1366 +		{
  1.1367 +		INFO_PRINTF2(_L("thread %d: Calling eglMakeCurrent(NULL values) from TerminateDisplayL..."), iThreadIdx);
  1.1368 +
  1.1369 +		ASSERT_EGL_TRUE(eglMakeCurrent(iDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
  1.1370 +
  1.1371 +		INFO_PRINTF1(_L("Calling eglTerminate..."));
  1.1372 +		ASSERT_EGL_TRUE(eglTerminate(iDisplay));
  1.1373 +		iDisplay = EGL_NO_DISPLAY;
  1.1374 +		}
  1.1375 +	iTerminateDisplay = EFalse;
  1.1376 +	}
  1.1377 +
  1.1378 +EXPORT_C void CTestEglSession::OpenSgDriverL()
  1.1379 +	{
  1.1380 +	if (!iSgDriverOpen)
  1.1381 +		{
  1.1382 +		VERBOSE_INFO_PRINTF2(_L("CTestEglSession<0x%08x> Opening SgDriver"), this);
  1.1383 +#ifdef  SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
  1.1384 +		TInt ret=iSgDriver.Open();
  1.1385 +#else
  1.1386 +		TInt ret=SgDriver::Open();
  1.1387 +#endif	//SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
  1.1388 +		ASSERT_EQUALS(ret, KErrNone);
  1.1389 +		iSgDriverOpen = ETrue;
  1.1390 +		}
  1.1391 +	}
  1.1392 +
  1.1393 +EXPORT_C void CTestEglSession::CloseSgDriver()
  1.1394 +	{
  1.1395 +	if (iSgDriverOpen)
  1.1396 +		{
  1.1397 +		VERBOSE_INFO_PRINTF2(_L("CTestEglSession<0x%08x> Closing SgDriver"), this);
  1.1398 +#ifdef  SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
  1.1399 +        iSgDriver.Close();
  1.1400 +#else
  1.1401 +        SgDriver::Close();
  1.1402 +#endif  //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
  1.1403 +		iSgDriverOpen = EFalse;
  1.1404 +		}
  1.1405 +	}
  1.1406 +
  1.1407 +EXPORT_C void CTestEglSession::OpenFbsSessionL()
  1.1408 +	{
  1.1409 +	if (!iFbsSessionOpen)
  1.1410 +		{
  1.1411 +		INFO_PRINTF2(_L("CTestEglSession<0x%08x> Opening FbsSession"), this);
  1.1412 +		TInt ret=RFbsSession::Connect();
  1.1413 +		ASSERT_EQUALS(ret, KErrNone);
  1.1414 +		iFbsSessionOpen = ETrue;
  1.1415 +		}
  1.1416 +	}
  1.1417 +
  1.1418 +EXPORT_C void CTestEglSession::CloseFbsSession()
  1.1419 +	{
  1.1420 +	if (iFbsSessionOpen)
  1.1421 +		{
  1.1422 +		INFO_PRINTF2(_L("CTestEglSession<0x%08x> Closing FbsSession"), this);
  1.1423 +		RFbsSession::Disconnect();
  1.1424 +		iFbsSessionOpen = EFalse;
  1.1425 +		}
  1.1426 +	}
  1.1427 +
  1.1428 +EXPORT_C TBool CTestEglSession::FetchProcEglCreateImageKhr()
  1.1429 +	{
  1.1430 +	if (!ipfnEglCreateImageKHR)
  1.1431 +		{
  1.1432 +		INFO_PRINTF2(_L("thread %d: Calling eglGetProcAddress(\"eglCreateImageKHR\")"), iThreadIdx);
  1.1433 +		ipfnEglCreateImageKHR = reinterpret_cast<TFPtrEglCreateImageKhr>(eglGetProcAddress("eglCreateImageKHR"));
  1.1434 +		if (ipfnEglCreateImageKHR==NULL)
  1.1435 +			{
  1.1436 +			EGLint eglError = eglGetError();
  1.1437 +			WARN_PRINTF2(_L("eglCreateImageKHR() not found - EGL Error: 0x%x"), eglError);
  1.1438 +			}
  1.1439 +		}
  1.1440 +	return (ipfnEglCreateImageKHR!=NULL);
  1.1441 +	}
  1.1442 +
  1.1443 +EXPORT_C EGLImageKHR CTestEglSession::eglCreateImageKhrL(EGLDisplay aDisplay,EGLContext aContext,EGLenum aTarget,RSgImage* aSgImage,const EGLint *aAttr_List)
  1.1444 +	{
  1.1445 +	TBool bSuccess = FetchProcEglCreateImageKhr();
  1.1446 +	ASSERT_TRUE(bSuccess);
  1.1447 +	VERBOSE_INFO_PRINTF2(_L("thread %d: Calling eglCreateImageKHR"), iThreadIdx);
  1.1448 +	EGLImageKHR eglImage = ipfnEglCreateImageKHR(aDisplay,aContext,aTarget,reinterpret_cast<EGLClientBuffer>(aSgImage),const_cast<EGLint *>(aAttr_List));
  1.1449 +	return eglImage;
  1.1450 +	}
  1.1451 +
  1.1452 +EXPORT_C EGLImageKHR CTestEglSession::eglCreateImageKhrL(EGLDisplay aDisplay,EGLContext aContext,EGLenum aTarget,CFbsBitmap &aCFbsBitmap, const EGLint *aAttr_List)
  1.1453 +	{
  1.1454 +	TBool bSuccess = FetchProcEglCreateImageKhr();
  1.1455 +	ASSERT_TRUE(bSuccess);
  1.1456 +	INFO_PRINTF2(_L("thread %d: Calling eglCreateImageKHR, with CFBsBitmap)"), iThreadIdx);
  1.1457 +	//the following call to eglCreateImageKHR MUST fail, error handling is made outside
  1.1458 +	EGLImageKHR eglImage = ipfnEglCreateImageKHR(aDisplay,aContext,aTarget,reinterpret_cast<EGLClientBuffer>(&aCFbsBitmap),const_cast<EGLint *>(aAttr_List));
  1.1459 +	return eglImage;
  1.1460 +	}
  1.1461 +
  1.1462 +EXPORT_C TBool CTestEglSession::FetchProcEglDestroyImageKhr()
  1.1463 +	{
  1.1464 +	if (!ipfnEglDestroyImageKHR)
  1.1465 +		{
  1.1466 +		INFO_PRINTF2(_L("thread %d: Calling eglGetProcAddress(\"eglDestroyImageKHR\")"), iThreadIdx);
  1.1467 +		ipfnEglDestroyImageKHR = reinterpret_cast<TFPtrEglDestroyImageKhr>(eglGetProcAddress("eglDestroyImageKHR"));
  1.1468 +		if (ipfnEglDestroyImageKHR==NULL)
  1.1469 +			{
  1.1470 +			EGLint eglError = eglGetError();
  1.1471 +			WARN_PRINTF2(_L("eglDestroyImageKHR() not found - EGL Error: 0x%x"), eglError);
  1.1472 +			}
  1.1473 +		}
  1.1474 +	return (ipfnEglDestroyImageKHR!=NULL);
  1.1475 +	}
  1.1476 +
  1.1477 +EXPORT_C TBool CTestEglSession::DestroyEGLImage(EGLDisplay aDisplay, EGLImageKHR aEGLImageKHR)
  1.1478 +	{
  1.1479 +	TBool bSuccess = FetchProcEglDestroyImageKhr();
  1.1480 +	ASSERT_TRUE(bSuccess);
  1.1481 +	VERBOSE_INFO_PRINTF2(_L("thread %d: Calling eglDestroyImageKHR"), iThreadIdx);
  1.1482 +	return ipfnEglDestroyImageKHR(aDisplay,aEGLImageKHR);
  1.1483 +	}
  1.1484 +
  1.1485 +EXPORT_C TBool CTestEglSession::FetchProcvgCreateImageTargetKhr()
  1.1486 +	{
  1.1487 +	if (!ipfnvgCreateImageTargetKHR)
  1.1488 +		{
  1.1489 +		INFO_PRINTF2(_L("thread %d: Calling eglGetProcAddress (\"vgCreateEGLImageTargetKHR\")"), iThreadIdx);
  1.1490 +		ipfnvgCreateImageTargetKHR = reinterpret_cast<TFPtrVgCreateEglImageTargetKhr>(eglGetProcAddress("vgCreateEGLImageTargetKHR"));
  1.1491 +		if (ipfnvgCreateImageTargetKHR==NULL)
  1.1492 +			{
  1.1493 +			EGLint eglError = eglGetError();
  1.1494 +			WARN_PRINTF2(_L("vgCreateImageTargetKHR() not found - EGL Error: 0x%x"), eglError);
  1.1495 +			}
  1.1496 +		}
  1.1497 +	return (ipfnvgCreateImageTargetKHR!=NULL);
  1.1498 +	}
  1.1499 +
  1.1500 +EXPORT_C VGImage CTestEglSession::vgCreateImageTargetKHR(VGeglImageKHR aImage)
  1.1501 +	{
  1.1502 +	TBool bSuccess = FetchProcvgCreateImageTargetKhr();
  1.1503 +	ASSERT_TRUE(bSuccess);
  1.1504 +	VERBOSE_INFO_PRINTF2(_L("thread %d: Calling vgCreateEGLImageTargetKHR"), iThreadIdx);
  1.1505 +	return ipfnvgCreateImageTargetKHR(aImage);
  1.1506 +	}
  1.1507 +
  1.1508 +EXPORT_C TBool CTestEglSession::IsACompatibleConfig(EGLConfig aConfig,RSgImage& aImage,TBool aLog)
  1.1509 +	{
  1.1510 +	EGLint EGL_BUFFER_SIZE_value;
  1.1511 +	EGLint EGL_ALPHA_SIZE_value;
  1.1512 +	EGLint EGL_BLUE_SIZE_value;
  1.1513 +	EGLint EGL_GREEN_SIZE_value;
  1.1514 +	EGLint EGL_RED_SIZE_value;
  1.1515 +	EGLint EGL_SURFACE_TYPE_value;
  1.1516 +	EGLint EGL_RENDERABLE_TYPE_value;
  1.1517 +	EGLint EGL_CONFIG_ID_value;
  1.1518 +
  1.1519 +	eglGetConfigAttrib(iDisplay, aConfig, EGL_CONFIG_ID, &EGL_CONFIG_ID_value);
  1.1520 +	eglGetConfigAttrib(iDisplay, aConfig, EGL_BUFFER_SIZE, &EGL_BUFFER_SIZE_value);
  1.1521 +	eglGetConfigAttrib(iDisplay, aConfig, EGL_ALPHA_SIZE, &EGL_ALPHA_SIZE_value);
  1.1522 +	eglGetConfigAttrib(iDisplay, aConfig, EGL_BLUE_SIZE, &EGL_BLUE_SIZE_value);
  1.1523 +	eglGetConfigAttrib(iDisplay, aConfig, EGL_GREEN_SIZE, &EGL_GREEN_SIZE_value);
  1.1524 +	eglGetConfigAttrib(iDisplay, aConfig, EGL_RED_SIZE, &EGL_RED_SIZE_value);
  1.1525 +	eglGetConfigAttrib(iDisplay, aConfig, EGL_SURFACE_TYPE, &EGL_SURFACE_TYPE_value);
  1.1526 +	eglGetConfigAttrib(iDisplay, aConfig, EGL_RENDERABLE_TYPE, &EGL_RENDERABLE_TYPE_value);
  1.1527 +#ifdef PRINTG_CONFIGS_LOG
  1.1528 +	INFO_PRINTF7(_L("(Config: %3d) RGBA=(%2d) %2d,%2d,%2d,%2d"), EGL_CONFIG_ID_value, EGL_BUFFER_SIZE_value,
  1.1529 +					EGL_RED_SIZE_value, EGL_GREEN_SIZE_value, EGL_BLUE_SIZE_value,
  1.1530 +					EGL_ALPHA_SIZE_value);
  1.1531 +	INFO_PRINTF2(_L("RENDERABLE_TYPE %d"),EGL_RENDERABLE_TYPE_value);
  1.1532 +#endif
  1.1533 +
  1.1534 +	if(!(EGL_SURFACE_TYPE_value & EGL_PIXMAP_BIT))
  1.1535 +		{
  1.1536 +		return EFalse;
  1.1537 +		}
  1.1538 +
  1.1539 +	TBool good = ETrue;
  1.1540 +	//requested usage bits
  1.1541 +	TSgImageInfo requestedImageInfo;
  1.1542 +	aImage.GetInfo(requestedImageInfo);
  1.1543 +
  1.1544 +#ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
  1.1545 +	//potential usage bits
  1.1546 +    RSgImage potential;
  1.1547 +    potential.Open(aImage.Id(),ESgDoNotRestrictUsage);
  1.1548 +    TSgImageInfo potentialImageInfo;
  1.1549 +    potential.GetInfo(potentialImageInfo);
  1.1550 +    potential.Close();
  1.1551 +#endif
  1.1552 +
  1.1553 +	switch(requestedImageInfo.iPixelFormat)
  1.1554 +		{
  1.1555 +		case EUidPixelFormatRGB_565:
  1.1556 +			if (!(EGL_RED_SIZE_value == 5 && EGL_GREEN_SIZE_value == 6 && EGL_BLUE_SIZE_value == 5 && EGL_ALPHA_SIZE_value == 0))
  1.1557 +				{
  1.1558 +				good = EFalse;
  1.1559 +				}
  1.1560 +			break;
  1.1561 +		case EUidPixelFormatXRGB_8888:
  1.1562 +			if (!(EGL_RED_SIZE_value == 8 && EGL_GREEN_SIZE_value == 8 && EGL_BLUE_SIZE_value == 8 && EGL_ALPHA_SIZE_value == 0))
  1.1563 +				{
  1.1564 +				good = EFalse;
  1.1565 +				}
  1.1566 +			break;
  1.1567 +		case EUidPixelFormatARGB_8888_PRE:
  1.1568 +			if (!(EGL_RED_SIZE_value == 8 && EGL_GREEN_SIZE_value == 8 && EGL_BLUE_SIZE_value == 8 && EGL_ALPHA_SIZE_value == 8))
  1.1569 +				{
  1.1570 +				good = EFalse;
  1.1571 +				}
  1.1572 +			//just OVG cares about the premultiplied alpha
  1.1573 +			if(EGL_RENDERABLE_TYPE_value& EGL_OPENVG_BIT)
  1.1574 +			//if(requestedImageInfo.iUsage & ESgUsageBitOpenVgSurface)
  1.1575 +				{
  1.1576 +				if(!(EGL_SURFACE_TYPE_value & EGL_VG_ALPHA_FORMAT_PRE_BIT))
  1.1577 +					{
  1.1578 +					if(aLog)
  1.1579 +						{
  1.1580 +						WARN_PRINTF2(_L("This Config can't be used with Pre-multipliedAlpha becasue EGL_SURFACE_TYPE has the wrong bits = %x"), EGL_SURFACE_TYPE_value);
  1.1581 +						}
  1.1582 +					good = EFalse;
  1.1583 +					}
  1.1584 +				}
  1.1585 +			break;
  1.1586 +		default:
  1.1587 +			if(aLog)
  1.1588 +				{
  1.1589 +				ERR_PRINTF2(_L("Wrong PixelFormat for a target, %x"), requestedImageInfo.iPixelFormat);
  1.1590 +				}
  1.1591 +			good = EFalse;
  1.1592 +		}
  1.1593 +	if(!good)
  1.1594 +		{
  1.1595 +		return EFalse;
  1.1596 +		}
  1.1597 +
  1.1598 +#ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
  1.1599 +	//
  1.1600 +	//Check if strict matching requirements are met:
  1.1601 +	//- All the supported APIs included in the EGL_RENDERABLE_TYPE of the
  1.1602 +	// EGLConfig must be matched by the corresponding iUsage of RSgImage
  1.1603 +	//- The following usages included in the iUsage of the RSgImage must be
  1.1604 +	// matched by the corresponding API in EGL_RENDERABLE_TYPE of the EGLConfig:
  1.1605 +	//         ESgUsageBitOpenGlSurface-> EGL_OPENGL_BIT
  1.1606 +	//         ESgUsageBitOpenGlesSurface-> EGL_OPENGL_ES_BIT
  1.1607 +	//         ESgUsageBitOpenGles2Surface-> EGL_OPENGL_ES2_BIT
  1.1608 +	//         ESgUsageBitOpenVgSurface->EGL_OPENVG_BIT
  1.1609 +
  1.1610 +	EGLint usageBitsMask = 0;
  1.1611 +	if(requestedImageInfo.iUsage & ESgUsageBitOpenVgSurface)
  1.1612 +		{
  1.1613 +		usageBitsMask |= EGL_OPENVG_BIT;
  1.1614 +		}
  1.1615 +	if(requestedImageInfo.iUsage & ESgUsageBitOpenGles2Surface)
  1.1616 +		{
  1.1617 +		usageBitsMask |= EGL_OPENGL_ES2_BIT;
  1.1618 +		}
  1.1619 +    if(requestedImageInfo.iUsage & ESgUsageBitOpenGlesSurface)
  1.1620 +        {
  1.1621 +        usageBitsMask |= EGL_OPENGL_ES_BIT;
  1.1622 +        }
  1.1623 +    if(requestedImageInfo.iUsage & ESgUsageBitOpenGlSurface)
  1.1624 +        {
  1.1625 +        usageBitsMask |= EGL_OPENGL_BIT;
  1.1626 +        }
  1.1627 +
  1.1628 +	if(usageBitsMask  != EGL_RENDERABLE_TYPE_value)
  1.1629 +		{
  1.1630 +		return EFalse;
  1.1631 +		}
  1.1632 +#else
  1.1633 +    // requested usage & RENDERABLE_TYPE > 0
  1.1634 +    EGLint usageBitsMask = 0;
  1.1635 +    if(requestedImageInfo.iUsage & ESgUsageOpenVgTarget)
  1.1636 +        {
  1.1637 +        usageBitsMask |= EGL_OPENVG_BIT;
  1.1638 +        }
  1.1639 +    if(requestedImageInfo.iUsage & ESgUsageOpenGlesTarget)
  1.1640 +        {
  1.1641 +        usageBitsMask |= EGL_OPENGL_ES_BIT;
  1.1642 +        }
  1.1643 +    if(requestedImageInfo.iUsage & ESgUsageOpenGles2Target)
  1.1644 +        {
  1.1645 +        usageBitsMask |= EGL_OPENGL_ES2_BIT;
  1.1646 +        }
  1.1647 +    if(!(usageBitsMask & EGL_RENDERABLE_TYPE_value))
  1.1648 +        {
  1.1649 +        return EFalse;
  1.1650 +        }
  1.1651 +
  1.1652 +    // potential usage >= RENDERABLE_TYPE
  1.1653 +
  1.1654 +    EGLint potentialUsageBitsMask = 0;
  1.1655 +    if(potentialImageInfo.iUsage & ESgUsageOpenVgTarget)
  1.1656 +        {
  1.1657 +        potentialUsageBitsMask |= EGL_OPENVG_BIT;
  1.1658 +        }
  1.1659 +    if(potentialImageInfo.iUsage & ESgUsageOpenGlesTarget)
  1.1660 +        {
  1.1661 +        potentialUsageBitsMask |= EGL_OPENGL_ES_BIT;
  1.1662 +        }
  1.1663 +    if(potentialImageInfo.iUsage & ESgUsageOpenGles2Target)
  1.1664 +        {
  1.1665 +        potentialUsageBitsMask |= EGL_OPENGL_ES2_BIT;
  1.1666 +        }
  1.1667 +
  1.1668 +    potentialUsageBitsMask = EGL_RENDERABLE_TYPE_value &~ potentialUsageBitsMask;
  1.1669 +    if(potentialUsageBitsMask)
  1.1670 +        {
  1.1671 +        return EFalse;
  1.1672 +        }
  1.1673 +#endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
  1.1674 +	return good;
  1.1675 +	}
  1.1676 +
  1.1677 +EXPORT_C TBool  CTestEglSession::CheckNeededExtensionL(TInt aExtension, const TDesC& aExtensionName)
  1.1678 +	{
  1.1679 +	TBuf8<128> extensionName;
  1.1680 +	extensionName.Copy(aExtensionName);
  1.1681 +	if(aExtension & KEGL_RSgimage || extensionName.Compare(KEglRSgImage)==0)
  1.1682 +		{
  1.1683 +		TBool bFoundExtensionEGL_NOK_pixmap_type_rsgimage = FindExtensionStringL(EIsEGL,KEglRSgImage);
  1.1684 +		if (!bFoundExtensionEGL_NOK_pixmap_type_rsgimage)
  1.1685 +			{
  1.1686 +			// The extension is not supported
  1.1687 +			return EFalse;
  1.1688 +			}
  1.1689 +		}
  1.1690 +	if(aExtension & KEGL_KHR_image_base || extensionName.Compare(KEglKhrImageBase)==0)
  1.1691 +		{
  1.1692 +		TBool bFoundExtensionEGL_KHR_image = FindExtensionStringL(EIsEGL,KEglKhrImageBase);
  1.1693 +		if (!bFoundExtensionEGL_KHR_image)
  1.1694 +			{
  1.1695 +			// The extension is not supported
  1.1696 +			return EFalse;
  1.1697 +			}
  1.1698 +		}
  1.1699 +	if(aExtension & KEGL_KHR_image_pixmap || extensionName.Compare(KEglKhrImagePixmap)==0)
  1.1700 +		{
  1.1701 +		TBool bFoundExtensionEGL_KHR_image = FindExtensionStringL(EIsEGL,KEglKhrImagePixmap);
  1.1702 +		if (!bFoundExtensionEGL_KHR_image)
  1.1703 +			{
  1.1704 +			// The extension is not supported
  1.1705 +			return EFalse;
  1.1706 +			}
  1.1707 +		}
  1.1708 +	if(aExtension & KVG_KHR_EGL_image || extensionName.Compare(KVgKhrEglImage)==0)
  1.1709 +		{
  1.1710 +		TBool bFoundExtensionVG_KHR_EGL_image = FindExtensionStringL(EIsVG,KVgKhrEglImage);
  1.1711 +		if (!bFoundExtensionVG_KHR_EGL_image)
  1.1712 +			{
  1.1713 +			// The extension is not supported
  1.1714 +			return EFalse;
  1.1715 +			}
  1.1716 +		}
  1.1717 +	if(aExtension & KEGL_KHR_reusable_sync || extensionName.Compare(KEglKhrReusableSync)==0)
  1.1718 +		{
  1.1719 +		TBool bFoundExtensionEGL_KHR_reusable_sync = FindExtensionStringL(EIsEGL,KEglKhrReusableSync);
  1.1720 +		if (!bFoundExtensionEGL_KHR_reusable_sync)
  1.1721 +			{
  1.1722 +			// The extension is not supported
  1.1723 +			return EFalse;
  1.1724 +			}
  1.1725 +		}
  1.1726 +    if(aExtension & KEGL_NOK__private__signal_sync || extensionName.Compare(KEglNokPrivateSignalSync)==0)
  1.1727 +        {
  1.1728 +        TBool bFoundExtensionEGL_NOK__private__signal_sync = FindExtensionStringL(EIsEGL,KEglNokPrivateSignalSync);
  1.1729 +        if (!bFoundExtensionEGL_NOK__private__signal_sync)
  1.1730 +            {
  1.1731 +            // The extension is not supported
  1.1732 +            return EFalse;
  1.1733 +            }
  1.1734 +        }
  1.1735 +    if(aExtension & KEGL_NOKIA_swap_buffers || extensionName.Compare(KEglNokiaSwapBuffers)==0)
  1.1736 +        {
  1.1737 +        TBool bFoundExtensionEGL_NOKIA_swap_buffer = FindExtensionStringL(EIsEGL,KEglNokiaSwapBuffers);
  1.1738 +        if (!bFoundExtensionEGL_NOKIA_swap_buffer)
  1.1739 +            {
  1.1740 +            // The extension is not supported
  1.1741 +            return EFalse;
  1.1742 +            }
  1.1743 +        }
  1.1744 +#ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
  1.1745 +    if(aExtension & KEGL_SYMBIAN_image_preserved || extensionName.Compare(KEglSymbianImagePreserved)
  1.1746 +        {
  1.1747 +        TBool bFoundExtensionEGL_SYMBIAN_image_preserved = FindExtensionStringL(EIsEGL,KEglSymbianImagePreserved);
  1.1748 +        if (!bFoundExtensionEGL_SYMBIAN_image_preserved)
  1.1749 +            {
  1.1750 +            // The extension is not supported
  1.1751 +            return EFalse;
  1.1752 +            }
  1.1753 +        }
  1.1754 +#endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
  1.1755 +    if(aExtension & KEGL_NOK_image_endpoint || extensionName.Compare(KEglNokiaImageEndpoint)==0)
  1.1756 +        {
  1.1757 +        TBool bFoundExtensionEGL_NOK_image_endpoint = FindExtensionStringL(EIsEGL,KEglNokiaImageEndpoint);
  1.1758 +        if (!bFoundExtensionEGL_NOK_image_endpoint)
  1.1759 +            {
  1.1760 +            // The extension is not supported
  1.1761 +            return EFalse;
  1.1762 +            }
  1.1763 +        }
  1.1764 +    if(aExtension & KEGL_NOK_surface_scaling || extensionName.Compare(KEglNokiaSurfaceScaling)==0)
  1.1765 +        {
  1.1766 +        TBool bFoundExtensionEGL_NOK_surface_scaling = FindExtensionStringL(EIsEGL,KEglNokiaSurfaceScaling);
  1.1767 +        if (!bFoundExtensionEGL_NOK_surface_scaling)
  1.1768 +            {
  1.1769 +            // The extension is not supported
  1.1770 +            return EFalse;
  1.1771 +            }
  1.1772 +        }
  1.1773 +	return ETrue;
  1.1774 +	}
  1.1775 +
  1.1776 +EXPORT_C CFbsBitmap* CTestEglSession::CreateReferenceBitmapL(TDisplayMode aMode)
  1.1777 +	{
  1.1778 +	if(aMode == ENone )
  1.1779 +		{
  1.1780 +		ERR_PRINTF1(_L("Queried Reference Bitmap dispaly mode equal to ENone"));
  1.1781 +		User::Leave(KErrTEFUnitFail);
  1.1782 +		}
  1.1783 +	return CreateReferenceBitmapL(aMode,KRgbGreenish);
  1.1784 +	}
  1.1785 +
  1.1786 +EXPORT_C CFbsBitmap* CTestEglSession::CreateReferenceBitmapL(TDisplayMode aMode,const TRgb& aColour)
  1.1787 +	{
  1.1788 +	OpenFbsSessionL();
  1.1789 +	CFbsBitmap* bitmap = new(ELeave) CFbsBitmap();
  1.1790 +	CleanupStack::PushL(bitmap);
  1.1791 +	if(bitmap->Create(KPixmapSize,aMode) != KErrNone)
  1.1792 +		{
  1.1793 +		return NULL;
  1.1794 +		}
  1.1795 +	CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL(bitmap);
  1.1796 +	CleanupStack::PushL(bitmapDevice);
  1.1797 +	CFbsBitGc* fbsBitGc = CFbsBitGc::NewL();
  1.1798 +	CleanupStack::PushL(fbsBitGc);
  1.1799 +	fbsBitGc->Activate(bitmapDevice);
  1.1800 +	fbsBitGc->SetBrushColor(aColour);
  1.1801 +	fbsBitGc->Clear();
  1.1802 +	CleanupStack::PopAndDestroy(2,bitmapDevice);
  1.1803 +	CleanupStack::Pop(bitmap);
  1.1804 +	return bitmap;
  1.1805 +	}
  1.1806 +
  1.1807 +EXPORT_C CFbsBitmap* CTestEglSession::CreateReferenceMaskedBitmapL(TDisplayMode aRefBitmapMode, const TRgb& aPenBitmapColor, const CFbsBitmap* aMaskBitmap)
  1.1808 +	{
  1.1809 +	OpenFbsSessionL();
  1.1810 +
  1.1811 +	// create the refBitmat (same size as the mask bitmap)
  1.1812 +	// Note that we clear it to 'opaque black' as we assume the target surface has been cleared to 'opaque black' too
  1.1813 +	// If either the surface or the refBitmap are cleared to another colour, update the other accordingly
  1.1814 +	CFbsBitmap* refBitmap = new(ELeave) CFbsBitmap();
  1.1815 +	CleanupStack::PushL(refBitmap);
  1.1816 +	User::LeaveIfError(refBitmap->Create(aMaskBitmap->SizeInPixels(), aRefBitmapMode));
  1.1817 +	CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL(refBitmap);
  1.1818 +	CleanupStack::PushL(bitmapDevice);
  1.1819 +	CFbsBitGc* fbsBitGc = CFbsBitGc::NewL();
  1.1820 +	CleanupStack::PushL(fbsBitGc);
  1.1821 +	fbsBitGc->Activate(bitmapDevice);
  1.1822 +	fbsBitGc->SetBrushColor(KRgbBlack);
  1.1823 +	fbsBitGc->Clear();
  1.1824 +
  1.1825 +	// create the penBitmap (same size as the mask bitmap)
  1.1826 +	CFbsBitmap* penBitmap = new(ELeave) CFbsBitmap();
  1.1827 +	CleanupStack::PushL(penBitmap);
  1.1828 +	User::LeaveIfError(penBitmap->Create(aMaskBitmap->SizeInPixels(), aRefBitmapMode));
  1.1829 +	CFbsBitmapDevice* penbitmapDevice = CFbsBitmapDevice::NewL(penBitmap);
  1.1830 +	CleanupStack::PushL(penbitmapDevice);
  1.1831 +	CFbsBitGc* penBitGc = CFbsBitGc::NewL();
  1.1832 +	CleanupStack::PushL(penBitGc);
  1.1833 +	penBitGc->Activate(penbitmapDevice);
  1.1834 +	penBitGc->SetBrushColor(aPenBitmapColor);
  1.1835 +	penBitGc->Clear();
  1.1836 +
  1.1837 +	// perform a masked bitmap transfer to the active refBitmap
  1.1838 +	TRect bmpRect(TPoint(0, 0), refBitmap->SizeInPixels());
  1.1839 +	fbsBitGc->Activate(bitmapDevice);
  1.1840 +	fbsBitGc->BitBltMasked(TPoint(0, 0), penBitmap, bmpRect, aMaskBitmap, EFalse);
  1.1841 +
  1.1842 +	CleanupStack::PopAndDestroy(5, bitmapDevice);
  1.1843 +	CleanupStack::Pop(refBitmap);
  1.1844 +	return refBitmap;
  1.1845 +	}
  1.1846 +
  1.1847 +
  1.1848 +EXPORT_C CFbsBitmap* CTestEglSession::CreateReferenceBitmapL(TDisplayMode aMode, const TSize &aSize, const TInt aIndex)
  1.1849 +	{
  1.1850 +	OpenFbsSessionL();
  1.1851 +	CFbsBitmap* bitmap = new(ELeave) CFbsBitmap();
  1.1852 +	CleanupStack::PushL(bitmap);
  1.1853 +	User::LeaveIfError(bitmap->Create(aSize,aMode));
  1.1854 +
  1.1855 +	TInt height = bitmap->SizeInPixels().iHeight;
  1.1856 +	TInt width  = bitmap->SizeInPixels().iWidth;
  1.1857 +
  1.1858 +	// Initialise colour values to a random value (guarantees pixel uniqueness if update is done accordingly)
  1.1859 +	TInt red=0;
  1.1860 +	TInt green=127;
  1.1861 +	TInt blue=127;
  1.1862 +	TInt alpha=255;
  1.1863 +
  1.1864 +	TBitmapUtil bmpUtil(bitmap);
  1.1865 +	bmpUtil.Begin(TPoint(0,0));
  1.1866 +	for (TInt colIndex = 0; colIndex < width; ++colIndex)
  1.1867 +		{
  1.1868 +		bmpUtil.SetPos(TPoint(colIndex, 0));
  1.1869 +		for (TInt rowIndex =0; rowIndex < height; ++rowIndex)
  1.1870 +			{
  1.1871 +			TRgb rgb(red, green, blue, alpha);
  1.1872 +			switch(bitmap->DisplayMode())
  1.1873 +				{
  1.1874 +				case EColor64K:
  1.1875 +					{
  1.1876 +					bmpUtil.SetPixel(rgb.Color64K());
  1.1877 +					break;
  1.1878 +					}
  1.1879 +				case EColor16MU:
  1.1880 +					{
  1.1881 +					bmpUtil.SetPixel(rgb.Color16MU());
  1.1882 +					break;
  1.1883 +					}
  1.1884 +				case EColor16MA:
  1.1885 +					{
  1.1886 +					bmpUtil.SetPixel(rgb.Color16MA());
  1.1887 +					break;
  1.1888 +					}
  1.1889 +				case EColor16MAP:
  1.1890 +					{
  1.1891 +					bmpUtil.SetPixel(rgb.Color16MAP());
  1.1892 +					break;
  1.1893 +					}
  1.1894 +				case EGray256:
  1.1895 +					{
  1.1896 +					bmpUtil.SetPixel(rgb.Gray256());
  1.1897 +					break;
  1.1898 +					}
  1.1899 +				default:
  1.1900 +					{
  1.1901 +					// We should not get here - colour mode not supported by these tests
  1.1902 +					ERR_PRINTF1(_L("CTestEglSession::CreateReferenceBitmapL - Colour mode not supported!"));
  1.1903 +				    ASSERT(FALSE);
  1.1904 +					}
  1.1905 +				}
  1.1906 +			bmpUtil.IncYPos();
  1.1907 +
  1.1908 +			// Update red bit
  1.1909 +			red = ++red + aIndex;
  1.1910 +			if (red>255)
  1.1911 +				red = red - 256;
  1.1912 +
  1.1913 +			// Update green bit
  1.1914 +			green = --green - aIndex;
  1.1915 +			if (green<0)
  1.1916 +				green = green + 256;
  1.1917 +
  1.1918 +			// Update blue bit
  1.1919 +			blue = ++blue + aIndex;
  1.1920 +			if (blue>255)
  1.1921 +				blue = blue - 256;
  1.1922 +
  1.1923 +			// Update alpha bit
  1.1924 +			alpha = --alpha - aIndex;
  1.1925 +			if (alpha<0)
  1.1926 +				alpha = alpha + 256;
  1.1927 +			}
  1.1928 +		}
  1.1929 +	bmpUtil.End();
  1.1930 +	CleanupStack::Pop(bitmap);
  1.1931 +	return bitmap;
  1.1932 +	}
  1.1933 +
  1.1934 +EXPORT_C void CTestEglSession::CheckVgDrawingL(VGImageFormat aDataFormat, const CFbsBitmap* aReferenceBitmap)
  1.1935 +	{
  1.1936 +	TRgb refPixel;
  1.1937 +	TInt height = aReferenceBitmap->SizeInPixels().iHeight;
  1.1938 +	TInt width  = aReferenceBitmap->SizeInPixels().iWidth;
  1.1939 +
  1.1940 +	switch(aDataFormat)
  1.1941 +		{
  1.1942 +		case VG_sRGB_565:
  1.1943 +			{
  1.1944 +			TUint16* vgPixel = new(ELeave) TUint16[width];
  1.1945 +			CleanupArrayDeletePushL(vgPixel);
  1.1946 +			for (TInt y=0; y < height; y++)
  1.1947 +				{
  1.1948 +                // Mind the fact that CFbsBitmap and VGImages use different coordinates origin!
  1.1949 +                vgReadPixels(vgPixel, 1, aDataFormat, 0,height-y-1, width,1);
  1.1950 +
  1.1951 +				for (TInt x=0; x < width; x++)
  1.1952 +					{
  1.1953 +					aReferenceBitmap->GetPixel(refPixel, TPoint(x,y));
  1.1954 +					if(!PixelsMatch(refPixel, TRgb::Color64K(vgPixel[x]), EFalse))
  1.1955 +						{
  1.1956 +						User::Leave(KErrTEFUnitFail);
  1.1957 +						}
  1.1958 +					}
  1.1959 +				}
  1.1960 +			CleanupStack::PopAndDestroy(vgPixel);
  1.1961 +			break;
  1.1962 +			}
  1.1963 +
  1.1964 +		case VG_sXRGB_8888:
  1.1965 +			{
  1.1966 +			TUint32* vgPixel = new(ELeave) TUint32[width];
  1.1967 +			CleanupArrayDeletePushL(vgPixel);
  1.1968 +			for (TInt y=0; y < height; y++)
  1.1969 +				{
  1.1970 +                // Mind the fact that CFbsBitmap and VGImages use different coordinates origin!
  1.1971 +                vgReadPixels(vgPixel, 1, aDataFormat, 0,height-y-1, width,1);
  1.1972 +
  1.1973 +				for (TInt x=0; x < width; x++)
  1.1974 +					{
  1.1975 +					aReferenceBitmap->GetPixel(refPixel, TPoint(x,y));
  1.1976 +					if(!PixelsMatch(refPixel, TRgb::Color16MU(vgPixel[x]), EFalse))
  1.1977 +						{
  1.1978 +						User::Leave(KErrTEFUnitFail);
  1.1979 +						}
  1.1980 +					}
  1.1981 +				}
  1.1982 +			CleanupStack::PopAndDestroy(vgPixel);
  1.1983 +			break;
  1.1984 +			}
  1.1985 +
  1.1986 +		case VG_sARGB_8888:
  1.1987 +			{
  1.1988 +			TUint32* vgPixel = new(ELeave) TUint32[width];
  1.1989 +			CleanupArrayDeletePushL(vgPixel);
  1.1990 +			for (TInt y=0; y < height; y++)
  1.1991 +				{
  1.1992 +                // Mind the fact that CFbsBitmap and VGImages use different coordinates origin!
  1.1993 +                vgReadPixels(vgPixel, 1, aDataFormat, 0,height-y-1, width,1);
  1.1994 +
  1.1995 +				for (TInt x=0; x < width; x++)
  1.1996 +					{
  1.1997 +					aReferenceBitmap->GetPixel(refPixel, TPoint(x,y));
  1.1998 +					if(!PixelsMatch(refPixel, TRgb::Color16MA(vgPixel[x]), ETrue))
  1.1999 +						{
  1.2000 +						User::Leave(KErrTEFUnitFail);
  1.2001 +						}
  1.2002 +					}
  1.2003 +				}
  1.2004 +			CleanupStack::PopAndDestroy(vgPixel);
  1.2005 +			break;
  1.2006 +			}
  1.2007 +
  1.2008 +		case VG_sARGB_8888_PRE:
  1.2009 +			{
  1.2010 +			TUint32* vgPixel = new(ELeave) TUint32[width];
  1.2011 +			CleanupArrayDeletePushL(vgPixel);
  1.2012 +			for (TInt y=0; y < height; y++)
  1.2013 +				{
  1.2014 +                // Mind the fact that CFbsBitmap and VGImages use different coordinates origin!
  1.2015 +                vgReadPixels(vgPixel, 1, aDataFormat, 0,height-y-1, width,1);
  1.2016 +
  1.2017 +				for (TInt x=0; x < width; x++)
  1.2018 +					{
  1.2019 +					aReferenceBitmap->GetPixel(refPixel, TPoint(x,y));
  1.2020 +					if(!PixelsMatch(refPixel, TRgb::Color16MAP(vgPixel[x]), ETrue))
  1.2021 +						{
  1.2022 +						User::Leave(KErrTEFUnitFail);
  1.2023 +						}
  1.2024 +					}
  1.2025 +				}
  1.2026 +			CleanupStack::PopAndDestroy(vgPixel);
  1.2027 +			break;
  1.2028 +			}
  1.2029 +
  1.2030 +		default:
  1.2031 +			// We should not get here - colour mode not supported by these tests
  1.2032 +			ERR_PRINTF1(_L("CTestEglSession::CheckVgDrawingL - Colour mode not supported!"));
  1.2033 +		    ASSERT(FALSE);
  1.2034 +			break;
  1.2035 +		}
  1.2036 +	}
  1.2037 +
  1.2038 +EXPORT_C TBool CTestEglSession::IsOpenGLESSupported()
  1.2039 +    {
  1.2040 +    if(!iIsSupportedRenderInitialized)
  1.2041 +        {
  1.2042 +        CheckAllAvailableRenders();
  1.2043 +        }
  1.2044 +    return iIsOpenGLESSupported;
  1.2045 +    }
  1.2046 +
  1.2047 +EXPORT_C TBool CTestEglSession::IsOpenGLES2Supported()
  1.2048 +    {
  1.2049 +    if(!iIsSupportedRenderInitialized)
  1.2050 +        {
  1.2051 +        CheckAllAvailableRenders();
  1.2052 +        }
  1.2053 +    return iIsOpenGLES2Supported;
  1.2054 +    }
  1.2055 +EXPORT_C TBool CTestEglSession::IsOpenVGSupported()
  1.2056 +    {
  1.2057 +    if(!iIsSupportedRenderInitialized)
  1.2058 +        {
  1.2059 +        CheckAllAvailableRenders();
  1.2060 +        }
  1.2061 +    return iIsOpenVGSupported;
  1.2062 +    }
  1.2063 +
  1.2064 +void CTestEglSession::CheckAllAvailableRenders()
  1.2065 +    {
  1.2066 +    ASSERT_EGL_TRUE(iDisplay != EGL_NO_DISPLAY);
  1.2067 +    TPtrC8 ptrEglClientApis((const TText8 *)eglQueryString(iDisplay, EGL_CLIENT_APIS));
  1.2068 +    _LIT8(KOpenGLES, "OpenGL_ES");
  1.2069 +    EGLint numConfigs= 0;
  1.2070 +    EGLConfig config;
  1.2071 +    if(ptrEglClientApis.Find(KOpenGLES) != KErrNotFound)
  1.2072 +        {
  1.2073 +        //check GLES2
  1.2074 +        const EGLint KAttrib_list_gles2[] = { EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
  1.2075 +                                              EGL_NONE };
  1.2076 +        EGLBoolean eglRes = eglChooseConfig(iDisplay, KAttrib_list_gles2, &config,1, &numConfigs);
  1.2077 +        ASSERT_EGL_TRUE(eglRes == EGL_TRUE);
  1.2078 +        if(numConfigs > 0)
  1.2079 +            {
  1.2080 +            iIsOpenGLES2Supported = ETrue;
  1.2081 +            }
  1.2082 +        //check GLES
  1.2083 +        numConfigs = 0;
  1.2084 +        const EGLint KAttrib_list_gles[] = { EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT,
  1.2085 +                                             EGL_NONE };
  1.2086 +        eglRes = eglChooseConfig(iDisplay, KAttrib_list_gles, &config,1, &numConfigs);
  1.2087 +        ASSERT_EGL_TRUE(eglRes == EGL_TRUE);
  1.2088 +        if(numConfigs > 0)
  1.2089 +            {
  1.2090 +            iIsOpenGLESSupported = ETrue;
  1.2091 +            }
  1.2092 +        }
  1.2093 +    _LIT8(KOpenVG, "OpenVG");
  1.2094 +    if(ptrEglClientApis.Find(KOpenVG) != KErrNotFound)
  1.2095 +        {
  1.2096 +        numConfigs= 0;
  1.2097 +        //check VG
  1.2098 +        const EGLint KAttrib_list_vg[] = { EGL_RENDERABLE_TYPE, EGL_OPENVG_BIT,
  1.2099 +                                           EGL_NONE };
  1.2100 +        EGLBoolean eglRes = eglChooseConfig(iDisplay, KAttrib_list_vg, &config,1, &numConfigs);
  1.2101 +        ASSERT_EGL_TRUE(eglRes == EGL_TRUE);
  1.2102 +        if(numConfigs > 0)
  1.2103 +            {
  1.2104 +            iIsOpenVGSupported = ETrue;
  1.2105 +            }
  1.2106 +        }
  1.2107 +    iIsSupportedRenderInitialized = ETrue;
  1.2108 +    }
  1.2109 +
  1.2110 +