os/graphics/egl/egltest/src/egltestcommonsession.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 //
    15 
    16 /**
    17  @file
    18  @test
    19 */
    20 
    21 #include "egltestcommonsession.h"
    22 #include "egltestcommonutils.h"
    23 #include "egltestcommonsgimageinfo.h"
    24 
    25 #include <test/tefunit.h>
    26 #include <e32cmn.h>
    27 #ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
    28 #include <sgresource/sgresource.h>
    29 #else
    30 #include <graphics/sgresourceinternal.h>
    31 #include <graphics/sgresource.h>
    32 #endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
    33 #include <VG/openvg.h>
    34 #include <GLES/gl.h>
    35 
    36 
    37 #define	CHECK_EXPECTED_ERROR(aFunctionReturnValue) \
    38 	if(!(CheckExpectedError(aFunctionReturnValue))) \
    39 		{ \
    40 		ERR_PRINTF2(_L("thread %d: Unexpected EGL error information"), iThreadIdx); \
    41 		User::Leave(KErrTEFUnitFail); \
    42 		}
    43 
    44 const TMapEglConfigToPixelFormat KMapEglConfigToPixelFormat[] =
    45 	{
    46 	{16, 0, 5,6,5, 0, 							EGL_RGB_BUFFER, EUidPixelFormatRGB_565, EColor64K},
    47 	{32, 0, 8,8,8, 0,							EGL_RGB_BUFFER, EUidPixelFormatXRGB_8888, EColor16MU},
    48     {32, 8, 8,8,8, EGL_VG_ALPHA_FORMAT_NONPRE, 	EGL_RGB_BUFFER, EUidPixelFormatARGB_8888, EColor16MA},
    49 	{32, 8, 8,8,8, EGL_VG_ALPHA_FORMAT_PRE, 	EGL_RGB_BUFFER, EUidPixelFormatARGB_8888_PRE, EColor16MAP}
    50 	};
    51 
    52 EXPORT_C CTestEglSession::CTestEglSession(CTestExecuteLogger& aLogger, EGLDisplay& aDisplay, TInt aThreadIdx)
    53 	: iLogger(aLogger), iThreadIdx(aThreadIdx), iExtensionGroupCached(EIsUndefined), iDisplay(aDisplay), iExpectedErrorCode(EGL_SUCCESS)
    54 	{}
    55 
    56 EXPORT_C CTestEglSession* CTestEglSession::NewLC(CTestExecuteLogger& aLogger, EGLDisplay& aDisplay, TInt aThreadIdx)
    57 	{
    58 	CTestEglSession* self = new (ELeave) CTestEglSession(aLogger, aDisplay, aThreadIdx);
    59 	CleanupStack::PushL(self);
    60 	return self;
    61 	}
    62 
    63 EXPORT_C CTestEglSession* CTestEglSession::NewL(CTestExecuteLogger& aLogger, EGLDisplay& aDisplay, TInt aThreadIdx)
    64 	{
    65 	CTestEglSession* self = CTestEglSession::NewLC(aLogger, aDisplay, aThreadIdx);
    66 	CleanupStack::Pop(self);
    67 	return self;
    68 	}
    69 
    70 EXPORT_C CTestEglSession::~CTestEglSession()
    71 	{
    72 	iExtensionStrings.Reset();
    73 	EGLBoolean ret;
    74 	if (iDisplay != EGL_NO_DISPLAY)
    75 		{
    76 		// Unbind and destroy context only if we successfuly created it
    77 		if (iContext != EGL_NO_CONTEXT)
    78 		    {
    79             INFO_PRINTF2(_L("thread %d: Calling eglMakeCurrent(NULL values) from ~CTestEglSession..."), iThreadIdx);
    80             ret = eglMakeCurrent(iDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
    81             if(ret == EGL_FALSE)
    82                 {
    83                 WARN_PRINTF3(_L("thread %d: eglMakeCurrent returned error = %x ~CTestEglSession..."), iThreadIdx, eglGetError());
    84                 }
    85 
    86             // Warn because this should be done by the test, rather than relying on the d'tor
    87             // which may not leave if there is an error (so no CHECK_EXPECTED_ERROR)
    88             WARN_PRINTF2(_L("thread %d: Calling eglDestroyContext() from ~CTestEglSession..."), iThreadIdx);
    89             ret = eglDestroyContext(iDisplay, iContext);
    90             if(ret == EGL_FALSE)
    91                 {
    92                 WARN_PRINTF3(_L("thread %d: eglDestroyContext returned error = %x ~CTestEglSession..."), iThreadIdx, eglGetError());
    93                 }
    94 		    }
    95 
    96 		if (iSurface != EGL_NO_SURFACE)
    97 			{
    98 			// Warn because this should be done by the test, rather than relying on the d'tor
    99 			// which may not leave if there is an error (so no CHECK_EXPECTED_ERROR)
   100 			WARN_PRINTF2(_L("thread %d: Calling eglDestroySurface() from ~CTestEglSession..."), iThreadIdx);
   101 			ret = eglDestroySurface(iDisplay, iSurface);
   102 			if(ret == EGL_FALSE)
   103 				{
   104 				WARN_PRINTF3(_L("thread %d: eglDestroySurface returned error = %x ~CTestEglSession..."), iThreadIdx, eglGetError());
   105 				}
   106 			}
   107 
   108 		if (iTerminateDisplay)
   109 			{
   110 			INFO_PRINTF1(_L("Calling eglTerminate..."));
   111 			ret = eglTerminate(iDisplay);
   112 			iDisplay = EGL_NO_DISPLAY;
   113 			if(ret == EGL_FALSE)
   114 				{
   115 				WARN_PRINTF3(_L("thread %d: eglTerminate returned error = %x ~CTestEglSession..."), iThreadIdx, eglGetError());
   116 				}
   117 			}
   118 		}
   119 
   120 	// Only destroy native resource after the surface and context that wraps it has been destroyed.
   121 	delete iFbsBitmap;
   122 	CloseFbsSession();
   123 
   124 	iSgImage.Close();
   125 	CloseSgDriver();
   126 	}
   127 
   128 EXPORT_C void CTestEglSession::SetExpectedError(EGLint aExpectedErrorCode)
   129 	{
   130 	VERBOSE_INFO_PRINTF3(_L("thread %d: Setting the expected error code for the next EGL call to %x"), iThreadIdx, aExpectedErrorCode);
   131 		{
   132 		iExpectedErrorCode = aExpectedErrorCode;
   133 		}
   134 	}
   135 
   136 EXPORT_C void CTestEglSession::ResetExpectedError()
   137 	{
   138 	iExpectedErrorCode = EGL_SUCCESS;
   139 	}
   140 
   141 /**
   142 Checks whether the call to an EGL method returned the correct error information.
   143 The method checks whether eglGetError() returns the expected error value as specified by calling SetExpectedError()
   144 It also checks that the value returned by the EGL method was appropriate for the expected error value.
   145 @param aFunctionReturnValue Pass in the value retured from the EGL method
   146 @return Whether the expected error information was returned from a call to an EGL method.
   147 */
   148 EXPORT_C TBool CTestEglSession::CheckExpectedError(EGLint aFunctionReturnValue)
   149 	{
   150 	TBool isExpectedError = ETrue;
   151 	EGLint eglErr = eglGetError();
   152 
   153 	// First check that we got the correct return value
   154 	if ((iExpectedErrorCode == EGL_SUCCESS) && !aFunctionReturnValue)
   155 		{
   156 		ERR_PRINTF3(_L("thread %d: Wrong function return value: %d"), iThreadIdx, aFunctionReturnValue);
   157 		isExpectedError = EFalse;
   158 		}
   159 	// Also check that we got the
   160 	if (eglErr != iExpectedErrorCode)
   161 		{
   162 		ERR_PRINTF4(_L("thread %d: eglGetError() returned %x, but expected %x"), iThreadIdx, eglErr, iExpectedErrorCode);
   163 		isExpectedError = EFalse;
   164 		}
   165 	else if (eglErr != EGL_SUCCESS)
   166 		{
   167 		VERBOSE_INFO_PRINTF3(_L("thread %d: eglGetError() returned %x, as expected"), iThreadIdx, eglErr);
   168 		}
   169 
   170 	// Reset the expected error
   171 	ResetExpectedError();
   172 
   173 	return isExpectedError;
   174 	}
   175 
   176 EXPORT_C void CTestEglSession::CheckExpectedErrorL(EGLint aExpectedErrorCode)
   177 	{
   178 	EGLint eglErr = eglGetError();
   179 	// check that we got the expected error
   180 	if (eglErr != aExpectedErrorCode)
   181 		{
   182 		ERR_PRINTF4(_L("thread %d: eglGetError() returned %x, but expected %x"), iThreadIdx, eglErr, aExpectedErrorCode);
   183 		User::Leave(KErrTEFUnitFail);
   184 		}
   185 	}
   186 
   187 void CTestEglSession::QueryExtensionsL(TExtensionsGroups aExtensionBelongsTo)
   188 	{
   189 	// reset the cached extensions
   190 	iExtensionStrings.Reset();
   191 
   192 	const char* extensionsString = NULL;
   193 	if(aExtensionBelongsTo == EIsEGL)
   194 		{
   195 		INFO_PRINTF2(_L("thread %d: Calling eglQueryString for EGL_EXTENSIONS)"), iThreadIdx);
   196 		extensionsString = eglQueryString(iDisplay, EGL_EXTENSIONS);
   197 		}
   198 	else if(aExtensionBelongsTo == EIsVG)
   199 		{
   200 		INFO_PRINTF2(_L("thread %d: Calling vgGetString for VG_EXTENSIONS)"), iThreadIdx);
   201 
   202 		// OpenVG needs a current VG context before it will allow the call to vgGetString
   203 		// The created surface will remain un-used, hence we create it with an arbitrary pixel format 
   204         EGLConfig currentConfig = GetConfigExactMatchL(EPBufferAttribsColor64K);
   205         CreatePbufferSurfaceAndMakeCurrentL(currentConfig, TSize(1,1), EGL_OPENVG_API);
   206 
   207 		extensionsString = (const char*) vgGetString(VG_EXTENSIONS);
   208 
   209 		//cleanup the context & surface
   210 		CleanupSurfaceSgImageL();
   211 		}
   212 	else
   213 		{
   214 		ERR_PRINTF2(_L("CTestEglSession::QueryExtensionsL() - Unknown extension group provided (%d)."), aExtensionBelongsTo);
   215 		User::Leave(KErrArgument);
   216 		}
   217 	CHECK_EXPECTED_ERROR(extensionsString!=NULL);
   218 
   219 	TPtrC8 ptrExtensions((const TUint8 *) extensionsString );
   220 
   221 	RBuf buffer;
   222     buffer.CreateL(ptrExtensions.Length());
   223     buffer.CleanupClosePushL();
   224     buffer.Copy(ptrExtensions);
   225 	INFO_PRINTF3(_L("thread %d: QueryExtensionsL: \"%S\""), iThreadIdx, &buffer);
   226     CleanupStack::PopAndDestroy(&buffer);
   227 
   228 	TInt posSpace=1;
   229 	while (posSpace > 0 && ptrExtensions.Length() > 0)
   230 		{
   231 		posSpace = ptrExtensions.Locate(' '); // strictly looking for a single space
   232 		ASSERT_FALSE(posSpace==0); // Would imply extension starting with a space or with 2 spaces in a row
   233 		if (posSpace > 0)
   234 			{
   235 			iExtensionStrings.Append(ptrExtensions.Left(posSpace));
   236 			if (posSpace <= ptrExtensions.Length())
   237 				{
   238 				ptrExtensions.Set(ptrExtensions.Mid(posSpace+1));
   239 				}
   240 			}
   241 		else
   242 			{
   243 			iExtensionStrings.Append(ptrExtensions);
   244 			}
   245 		}
   246 	}
   247 
   248 TBool CTestEglSession::FindExtensionStringL(TExtensionsGroups aExtensionBelongsTo, const TDesC8& aExtensionString)
   249 	{
   250 	//Load the extensions for this group if not already cached
   251 	if (iExtensionGroupCached != aExtensionBelongsTo)
   252 		{
   253 		QueryExtensionsL(aExtensionBelongsTo); // Load extension info
   254 		iExtensionGroupCached = aExtensionBelongsTo;
   255 		}
   256 
   257 	TInt countExtensionStrings = iExtensionStrings.Count();
   258 	for(TUint i=0; i<countExtensionStrings; i++)
   259 		{
   260 		if (iExtensionStrings[i].Compare(aExtensionString)==0)
   261 			{
   262 			// We have a match!
   263 			return ETrue;
   264 			}
   265 		}
   266 
   267 	// No match: copy the extension string into a 16 bit buffer for logging
   268 	const TInt KBufLenMissingExtension=128;
   269 	TBuf16<KBufLenMissingExtension> bufMissingExtension16;
   270 	bufMissingExtension16.Copy(aExtensionString.Left(KBufLenMissingExtension));
   271 
   272 	WARN_PRINTF2(_L("EGL extension missing: [%S]"), &bufMissingExtension16);
   273 	return EFalse;
   274 	}
   275 
   276 /**
   277  Converts from TRgb space to Vg floating point colour
   278  */
   279 EXPORT_C void CTestEglSession::ConvertColor(const TRgb& aSource, VGfloat* aTarget)
   280 //static
   281 	{
   282 	aTarget[0] = (VGfloat)aSource.Red() / 255.f;
   283 	aTarget[1] = (VGfloat)aSource.Green() / 255.f;
   284 	aTarget[2] = (VGfloat)aSource.Blue() / 255.f;
   285 	aTarget[3] = (VGfloat)aSource.Alpha() / 255.f;
   286 	}
   287 
   288 /** Breakpoint to manually view available configs while debugging */
   289 EXPORT_C void CTestEglSession::ViewConfigsL()
   290 	{
   291 	EGLConfig configs[KMaxEglConfigs];
   292 	EGLint numConfigs=0;
   293 
   294 	// Query number of configs available
   295 	INFO_PRINTF1(_L("Calling eglGetConfigs to get the number of configs available..."));
   296 	CHECK_EXPECTED_ERROR(eglGetConfigs(iDisplay, NULL, KMaxTInt, &numConfigs));
   297 
   298 	INFO_PRINTF1(_L("Checking number of configs..."));
   299 	ASSERT_TRUE(numConfigs >= 1);
   300 	INFO_PRINTF2(_L("Found %d configs"), numConfigs);
   301 
   302 	// Get the configs
   303 	INFO_PRINTF1(_L("Calling eglGetConfigs to get configs..."));
   304 	CHECK_EXPECTED_ERROR(eglGetConfigs(iDisplay, configs, KMaxEglConfigs, &numConfigs));
   305 
   306 	for(TUint index = 0; index < numConfigs; index++)
   307 		{
   308 		EGLint EGL_BUFFER_SIZE_value;
   309 		EGLint EGL_ALPHA_SIZE_value;
   310 		EGLint EGL_BLUE_SIZE_value;
   311 		EGLint EGL_GREEN_SIZE_value;
   312 		EGLint EGL_RED_SIZE_value;
   313 #ifdef PRINT_ALL_CONFIGS_DETAILS
   314 		EGLint EGL_DEPTH_SIZE_value;
   315 		EGLint EGL_STENCIL_SIZE_value;
   316 		EGLint EGL_CONFIG_CAVEAT_value;
   317 		EGLint EGL_CONFIG_ID_value;
   318 		EGLint EGL_LEVEL_value;
   319 		EGLint EGL_MAX_PBUFFER_HEIGHT_value;
   320 		EGLint EGL_MAX_PBUFFER_PIXELS_value;
   321 		EGLint EGL_MAX_PBUFFER_WIDTH_value;
   322 		EGLint EGL_NATIVE_RENDERABLE_value;
   323 		EGLint EGL_NATIVE_VISUAL_ID_value;
   324 		EGLint EGL_NATIVE_VISUAL_TYPE_value;
   325 		EGLint EGL_SAMPLES_value;
   326 		EGLint EGL_SAMPLE_BUFFERS_value;
   327 #endif
   328 		EGLint EGL_SURFACE_TYPE_value;
   329 #ifdef PRINT_ALL_CONFIGS_DETAILS
   330 		EGLint EGL_TRANSPARENT_TYPE_value;
   331 		EGLint EGL_TRANSPARENT_BLUE_VALUE_value;
   332 		EGLint EGL_TRANSPARENT_GREEN_VALUE_value;
   333 		EGLint EGL_TRANSPARENT_RED_VALUE_value;
   334 		EGLint EGL_BIND_TO_TEXTURE_RGB_value;
   335 		EGLint EGL_BIND_TO_TEXTURE_RGBA_value;
   336 		EGLint EGL_MIN_SWAP_INTERVAL_value;
   337 		EGLint EGL_MAX_SWAP_INTERVAL_value;
   338 		EGLint EGL_LUMINANCE_SIZE_value;
   339 		EGLint EGL_ALPHA_MASK_SIZE_value;
   340 		EGLint EGL_COLOR_BUFFER_TYPE_value;
   341 #endif
   342 		EGLint EGL_RENDERABLE_TYPE_value;
   343 
   344 		eglGetConfigAttrib(iDisplay, configs[index], EGL_BUFFER_SIZE, &EGL_BUFFER_SIZE_value);
   345 		eglGetConfigAttrib(iDisplay, configs[index], EGL_ALPHA_SIZE, &EGL_ALPHA_SIZE_value);
   346 		eglGetConfigAttrib(iDisplay, configs[index], EGL_BLUE_SIZE, &EGL_BLUE_SIZE_value);
   347 		eglGetConfigAttrib(iDisplay, configs[index], EGL_GREEN_SIZE, &EGL_GREEN_SIZE_value);
   348 		eglGetConfigAttrib(iDisplay, configs[index], EGL_RED_SIZE, &EGL_RED_SIZE_value);
   349 #ifdef PRINT_ALL_CONFIGS_DETAILS
   350 		eglGetConfigAttrib(iDisplay, configs[index], EGL_DEPTH_SIZE, &EGL_DEPTH_SIZE_value);
   351 		eglGetConfigAttrib(iDisplay, configs[index], EGL_STENCIL_SIZE, &EGL_STENCIL_SIZE_value);
   352 		eglGetConfigAttrib(iDisplay, configs[index], EGL_CONFIG_CAVEAT, &EGL_CONFIG_CAVEAT_value);
   353 		eglGetConfigAttrib(iDisplay, configs[index], EGL_CONFIG_ID, &EGL_CONFIG_ID_value);
   354 		eglGetConfigAttrib(iDisplay, configs[index], EGL_LEVEL, &EGL_LEVEL_value);
   355 		eglGetConfigAttrib(iDisplay, configs[index], EGL_MAX_PBUFFER_HEIGHT, &EGL_MAX_PBUFFER_HEIGHT_value);
   356 		eglGetConfigAttrib(iDisplay, configs[index], EGL_MAX_PBUFFER_PIXELS, &EGL_MAX_PBUFFER_PIXELS_value);
   357 		eglGetConfigAttrib(iDisplay, configs[index], EGL_MAX_PBUFFER_WIDTH, &EGL_MAX_PBUFFER_WIDTH_value);
   358 		eglGetConfigAttrib(iDisplay, configs[index], EGL_NATIVE_RENDERABLE, &EGL_NATIVE_RENDERABLE_value);
   359 		eglGetConfigAttrib(iDisplay, configs[index], EGL_NATIVE_VISUAL_ID, &EGL_NATIVE_VISUAL_ID_value);
   360 		eglGetConfigAttrib(iDisplay, configs[index], EGL_NATIVE_VISUAL_TYPE, &EGL_NATIVE_VISUAL_TYPE_value);
   361 		eglGetConfigAttrib(iDisplay, configs[index], EGL_SAMPLES, &EGL_SAMPLES_value);
   362 		eglGetConfigAttrib(iDisplay, configs[index], EGL_SAMPLE_BUFFERS, &EGL_SAMPLE_BUFFERS_value);
   363 #endif
   364 		eglGetConfigAttrib(iDisplay, configs[index], EGL_SURFACE_TYPE, &EGL_SURFACE_TYPE_value);
   365 #ifdef PRINT_ALL_CONFIGS_DETAILS
   366 		eglGetConfigAttrib(iDisplay, configs[index], EGL_TRANSPARENT_TYPE, &EGL_TRANSPARENT_TYPE_value);
   367 		eglGetConfigAttrib(iDisplay, configs[index], EGL_TRANSPARENT_BLUE_VALUE, &EGL_TRANSPARENT_BLUE_VALUE_value);
   368 		eglGetConfigAttrib(iDisplay, configs[index], EGL_TRANSPARENT_GREEN_VALUE, &EGL_TRANSPARENT_GREEN_VALUE_value);
   369 		eglGetConfigAttrib(iDisplay, configs[index], EGL_TRANSPARENT_RED_VALUE, &EGL_TRANSPARENT_RED_VALUE_value);
   370 		eglGetConfigAttrib(iDisplay, configs[index], EGL_BIND_TO_TEXTURE_RGB, &EGL_BIND_TO_TEXTURE_RGB_value);
   371 		eglGetConfigAttrib(iDisplay, configs[index], EGL_BIND_TO_TEXTURE_RGBA, &EGL_BIND_TO_TEXTURE_RGBA_value);
   372 		eglGetConfigAttrib(iDisplay, configs[index], EGL_MIN_SWAP_INTERVAL, &EGL_MIN_SWAP_INTERVAL_value);
   373 		eglGetConfigAttrib(iDisplay, configs[index], EGL_MAX_SWAP_INTERVAL, &EGL_MAX_SWAP_INTERVAL_value);
   374 		eglGetConfigAttrib(iDisplay, configs[index], EGL_LUMINANCE_SIZE, &EGL_LUMINANCE_SIZE_value);
   375 		eglGetConfigAttrib(iDisplay, configs[index], EGL_ALPHA_MASK_SIZE, &EGL_ALPHA_MASK_SIZE_value);
   376 		eglGetConfigAttrib(iDisplay, configs[index], EGL_COLOR_BUFFER_TYPE, &EGL_COLOR_BUFFER_TYPE_value);
   377 #endif
   378 		eglGetConfigAttrib(iDisplay, configs[index], EGL_RENDERABLE_TYPE, &EGL_RENDERABLE_TYPE_value);
   379 
   380 		TBool good = ETrue;
   381 
   382 		INFO_PRINTF7(_L("(idx: %3d) RGBA=(%2d) %2d,%2d,%2d,%2d"), index, EGL_BUFFER_SIZE_value,
   383 				EGL_RED_SIZE_value, EGL_GREEN_SIZE_value, EGL_BLUE_SIZE_value,
   384 				EGL_ALPHA_SIZE_value);
   385 		if (!(EGL_RED_SIZE_value == 8 && EGL_GREEN_SIZE_value == 8 && EGL_BLUE_SIZE_value == 8 && EGL_ALPHA_SIZE_value == 0))
   386 			{
   387 			continue;
   388 			}
   389 
   390 		INFO_PRINTF2(_L("\n\n^^^^^^ CONFIG [%d] VALUES ******"), index);
   391 		if (EGL_SURFACE_TYPE_value & EGL_PIXMAP_BIT)
   392 			{
   393 			INFO_PRINTF2(_L("EGL_SURFACE_TYPE=%d. <<< Has EGL_PIXMAP_BIT"), EGL_SURFACE_TYPE_value);
   394 			}
   395 		else
   396 			{
   397 			INFO_PRINTF2(_L("EGL_SURFACE_TYPE=%d. <<< BAD (not pixmap)"), EGL_SURFACE_TYPE_value);
   398 			good = EFalse;
   399 			}
   400 
   401 		if (EGL_RENDERABLE_TYPE_value & EGL_OPENVG_BIT)
   402 			{
   403 			INFO_PRINTF2(_L("EGL_RENDERABLE_TYPE=%d. <<< Has EGL_OPENVG_BIT"), EGL_RENDERABLE_TYPE_value);
   404 			}
   405 		else
   406 			{
   407 			INFO_PRINTF2(_L("EGL_RENDERABLE_TYPE=%d. <<< BAD (not open vg)"), EGL_RENDERABLE_TYPE_value);
   408 			good = EFalse;
   409 			}
   410 
   411 		if (good)
   412 			{
   413 			INFO_PRINTF1(_L("^^^^^^^ GOOD ^^^^^^^"));
   414 			}
   415 
   416 #ifdef PRINT_ALL_CONFIGS_DETAILS
   417 		INFO_PRINTF2(_L("\n\n***** CONFIG [%d] VALUES ******"), index);
   418 		INFO_PRINTF2(_L("EGL_BUFFER_SIZE=%d."), EGL_BUFFER_SIZE_value);
   419 		INFO_PRINTF2(_L("EGL_ALPHA_SIZE=%d."), EGL_ALPHA_SIZE_value);
   420 		INFO_PRINTF2(_L("EGL_BLUE_SIZE=%d."), EGL_BLUE_SIZE_value);
   421 		INFO_PRINTF2(_L("EGL_GREEN_SIZE=%d."), EGL_GREEN_SIZE_value);
   422 		INFO_PRINTF2(_L("EGL_RED_SIZE=%d."), EGL_RED_SIZE_value);
   423 		INFO_PRINTF2(_L("EGL_DEPTH_SIZE=%d."), EGL_DEPTH_SIZE_value);
   424 		INFO_PRINTF2(_L("EGL_STENCIL_SIZE=%d."), EGL_STENCIL_SIZE_value);
   425 		INFO_PRINTF2(_L("EGL_CONFIG_CAVEAT=%d."), EGL_CONFIG_CAVEAT_value);
   426 		INFO_PRINTF2(_L("EGL_CONFIG_ID=%d."), EGL_CONFIG_ID_value);
   427 		INFO_PRINTF2(_L("EGL_LEVEL=%d."), EGL_LEVEL_value);
   428 		INFO_PRINTF2(_L("EGL_MAX_PBUFFER_HEIGHT=%d."), EGL_MAX_PBUFFER_HEIGHT_value);
   429 		INFO_PRINTF2(_L("EGL_MAX_PBUFFER_PIXELS=%d."), EGL_MAX_PBUFFER_PIXELS_value);
   430 		INFO_PRINTF2(_L("EGL_MAX_PBUFFER_WIDTH=%d."), EGL_MAX_PBUFFER_WIDTH_value);
   431 		INFO_PRINTF2(_L("EGL_NATIVE_RENDERABLE=%d."), EGL_NATIVE_RENDERABLE_value);
   432 		INFO_PRINTF2(_L("EGL_NATIVE_VISUAL_ID=%d."), EGL_NATIVE_VISUAL_ID_value);
   433 		INFO_PRINTF2(_L("EGL_NATIVE_VISUAL_TYPE=%d."), EGL_NATIVE_VISUAL_TYPE_value);
   434 		INFO_PRINTF2(_L("EGL_SAMPLES=%d."), EGL_SAMPLES_value);
   435 		INFO_PRINTF2(_L("EGL_SAMPLE_BUFFERS=%d."), EGL_SAMPLE_BUFFERS_value);
   436 		INFO_PRINTF2(_L("EGL_SURFACE_TYPE=%d."), EGL_SURFACE_TYPE_value);
   437 		INFO_PRINTF2(_L("EGL_TRANSPARENT_TYPE=%d."), EGL_TRANSPARENT_TYPE_value);
   438 		INFO_PRINTF2(_L("EGL_TRANSPARENT_BLUE_VALUE=%d."), EGL_TRANSPARENT_BLUE_VALUE_value);
   439 		INFO_PRINTF2(_L("EGL_TRANSPARENT_GREEN_VALUE=%d."), EGL_TRANSPARENT_GREEN_VALUE_value);
   440 		INFO_PRINTF2(_L("EGL_TRANSPARENT_RED_VALUE=%d."), EGL_TRANSPARENT_RED_VALUE_value);
   441 		INFO_PRINTF2(_L("EGL_BIND_TO_TEXTURE_RGB=%d."), EGL_BIND_TO_TEXTURE_RGB_value);
   442 		INFO_PRINTF2(_L("EGL_BIND_TO_TEXTURE_RGBA=%d."), EGL_BIND_TO_TEXTURE_RGBA_value);
   443 		INFO_PRINTF2(_L("EGL_MIN_SWAP_INTERVAL=%d."), EGL_MIN_SWAP_INTERVAL_value);
   444 		INFO_PRINTF2(_L("EGL_MAX_SWAP_INTERVAL=%d."), EGL_MAX_SWAP_INTERVAL_value);
   445 		INFO_PRINTF2(_L("EGL_LUMINANCE_SIZE=%d."), EGL_LUMINANCE_SIZE_value);
   446 		INFO_PRINTF2(_L("EGL_ALPHA_MASK_SIZE=%d."), EGL_ALPHA_MASK_SIZE_value);
   447 		INFO_PRINTF2(_L("EGL_COLOR_BUFFER_TYPE=%d."), EGL_COLOR_BUFFER_TYPE_value);
   448 		INFO_PRINTF2(_L("EGL_RENDERABLE_TYPE=%d."), EGL_RENDERABLE_TYPE_value);
   449 		INFO_PRINTF2(_L("\n*********************************\n\n"), index);
   450 #endif
   451 		}
   452 	}
   453 
   454 LOCAL_C TEglConfigMatchType GetMatchType(EGLint aAttrib, TEglConfigMatchRule aMatchRule)
   455 	{
   456 	const TConfigMatchRuleItem* curMatchRuleItem = KConfigMatchRules[aMatchRule];
   457 
   458 	while(curMatchRuleItem->iAttrib != EGL_NONE)
   459 		{
   460 		if (aAttrib == curMatchRuleItem->iAttrib)
   461 			{
   462 			return curMatchRuleItem->iMatchType;
   463 			}
   464 		curMatchRuleItem++;
   465 		}
   466 
   467 	RDebug::Printf("Unknown attrib %x", aAttrib);
   468 	return eMatchUnknown;
   469 	}
   470 
   471 /**
   472  Returns the first index of a config that matches the requested config extactly
   473  */
   474 TInt CTestEglSession::GetFullMatchConfigIndex(EGLDisplay aDisplay, EGLConfig *aConfigs, TInt aNumConfigs,
   475 											  const EGLint aWantedAttribs[], TEglConfigMatchRule aMatchRule)
   476 	{
   477 	EGLint value=0;
   478 	for(TUint idxConfig=0; idxConfig<aNumConfigs; idxConfig++)
   479 		{
   480 		const EGLint *curAttrib = aWantedAttribs;
   481 		TBool match = ETrue;
   482 
   483 		while(*curAttrib != EGL_NONE && match)
   484 			{
   485 			ASSERT_EGL_TRUE(eglGetConfigAttrib(aDisplay, aConfigs[idxConfig], *curAttrib, &value));
   486 
   487 			switch(GetMatchType(*curAttrib, aMatchRule))
   488 				{
   489 				case eMatchEqual:
   490 					if (value != curAttrib[1])
   491 						{
   492 						match = EFalse;
   493 						}
   494 					break;
   495 				case eMatchAtLeast:
   496 					if (value < curAttrib[1])   // Note, we detect "failure to match", hence "<" not ">="!
   497 						{
   498 						match = EFalse;
   499 						}
   500 					break;
   501 				case eMatchBitMask:
   502 					if ((value & curAttrib[1]) != curAttrib[1])
   503 						{
   504 						match = EFalse;
   505 						}
   506 					break;
   507 				case eMatchAlways:
   508 				    break;
   509 
   510 				default:
   511 					// We should not get here.
   512 				    ASSERT(FALSE);
   513 				    break;
   514 				}
   515 			curAttrib += 2;
   516 			}
   517 
   518 		// If we get here with match set, we have matched all attributes, and have found a match.
   519 		if (match)
   520 			{
   521 			return idxConfig;
   522 			}
   523 		}
   524 	return KErrNotFound;
   525 	}
   526 
   527 TInt CTestEglSession::ConfigToPixelFormatTableLength() const
   528 	{
   529 	return sizeof(KMapEglConfigToPixelFormat) / sizeof(TMapEglConfigToPixelFormat);
   530 	}
   531 
   532 const TMapEglConfigToPixelFormat& CTestEglSession::ConfigToPixelFormatTable(TInt aIndex) const
   533 	{
   534 	return KMapEglConfigToPixelFormat[aIndex];
   535 	}
   536 
   537 /**
   538  Returns pixel format inforamtion for a given EGL config.
   539  @param aConfig The EGL config for which pixel format information will be returned.
   540  @return A pointer to the pixel format information for the given EGL config.
   541          Tf the config cannot be mapped, then NULL is returned.
   542  */
   543 EXPORT_C const TMapEglConfigToPixelFormat* CTestEglSession::GetPixelFormatFromEglConfigL(EGLConfig aConfig)
   544 	{
   545 	EGLint bufferSize=0;
   546 	EGLint alphaSize=0;
   547 	EGLint redSize=0;
   548 	EGLint greenSize=0;
   549 	EGLint blueSize=0;
   550 	EGLint colorBufferType=0;
   551 	EGLint surfaceType = 0;
   552 
   553 	CHECK_EXPECTED_ERROR(eglGetConfigAttrib(iDisplay, aConfig, EGL_BUFFER_SIZE, &bufferSize));
   554 	CHECK_EXPECTED_ERROR(eglGetConfigAttrib(iDisplay, aConfig, EGL_ALPHA_SIZE, &alphaSize));
   555 	CHECK_EXPECTED_ERROR(eglGetConfigAttrib(iDisplay, aConfig, EGL_RED_SIZE, &redSize));
   556 	CHECK_EXPECTED_ERROR(eglGetConfigAttrib(iDisplay, aConfig, EGL_GREEN_SIZE, &greenSize));
   557 	CHECK_EXPECTED_ERROR(eglGetConfigAttrib(iDisplay, aConfig, EGL_BLUE_SIZE, &blueSize));
   558 	CHECK_EXPECTED_ERROR(eglGetConfigAttrib(iDisplay, aConfig, EGL_COLOR_BUFFER_TYPE, &colorBufferType));
   559 	CHECK_EXPECTED_ERROR(eglGetConfigAttrib(iDisplay, aConfig, EGL_SURFACE_TYPE, &surfaceType));
   560 
   561 	INFO_PRINTF7(_L(">>>>> Config info: %d, %d, %d,%d,%d, 0x%x"), bufferSize, alphaSize, redSize, greenSize, blueSize, colorBufferType);
   562 
   563 	for(TUint i=0; i<ConfigToPixelFormatTableLength(); i++)
   564 		{
   565 		if ((ConfigToPixelFormatTable(i).iBufferSize == bufferSize)
   566 				&& (ConfigToPixelFormatTable(i).iAlphaSize == alphaSize)
   567 				&& (ConfigToPixelFormatTable(i).iRedSize == redSize)
   568 				&& (ConfigToPixelFormatTable(i).iGreenSize == greenSize)
   569 				&& (ConfigToPixelFormatTable(i).iBlueSize == blueSize)
   570 				&& (ConfigToPixelFormatTable(i).iColorBufferType == colorBufferType)
   571 				&& ((ConfigToPixelFormatTable(i).iSurfaceTypeFlags & surfaceType) == ConfigToPixelFormatTable(i).iSurfaceTypeFlags))
   572 			{
   573 			return &ConfigToPixelFormatTable(i);
   574 			}
   575 		}
   576 
   577 	return NULL;
   578 	}
   579 
   580 EXPORT_C void CTestEglSession::CleanupSurfaceFbsBitmapL()
   581 	{
   582 	CleanupSurfaceAndContextL();
   583 
   584 	delete iFbsBitmap;
   585 	iFbsBitmap = NULL;
   586 	}
   587 
   588 EXPORT_C void CTestEglSession::CleanupSurfaceAndContextL()
   589 	{
   590 	ASSERT_TRUE(iSurface != EGL_NO_SURFACE);
   591 	ASSERT_TRUE(iContext != EGL_NO_CONTEXT);
   592 
   593 	// Clean up
   594 	INFO_PRINTF1(_L("Calling eglMakeCurrent(NULL values)..."));
   595 	CHECK_EXPECTED_ERROR(eglMakeCurrent(iDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
   596 
   597 	INFO_PRINTF1(_L("Calling eglDestroyContext()..."));
   598 	CHECK_EXPECTED_ERROR(eglDestroyContext(iDisplay, iContext));
   599 	iContext = EGL_NO_CONTEXT;
   600 
   601 	INFO_PRINTF1(_L("Calling eglDestroySurface()..."));
   602 	CHECK_EXPECTED_ERROR(eglDestroySurface(iDisplay, iSurface));
   603 	iSurface = EGL_NO_SURFACE;
   604 	}
   605 
   606 EXPORT_C CFbsBitmap* CTestEglSession::NativeFbsBitmap()
   607 	{
   608 	return iFbsBitmap;
   609 	}
   610 
   611 EXPORT_C RSgImage& CTestEglSession::NativeSgImage()
   612 	{
   613 	return iSgImage;
   614 	}
   615 
   616 EXPORT_C EGLSurface CTestEglSession::Surface() const
   617 	{
   618 	return iSurface;
   619 	}
   620 
   621 EXPORT_C EGLContext CTestEglSession::Context() const
   622 	{
   623 	return iContext;
   624 	}
   625 
   626 EXPORT_C EGLConfig CTestEglSession::GetConfigExactMatchL(TEglTestConfig aConfigAttribIndex, TEglConfigMatchRule aMatchRule)
   627 	{
   628 	if(aConfigAttribIndex >= EEglTestConfigMax )
   629 		{
   630 		ERR_PRINTF1(_L("Attribute index out of range, please check the INI file"));
   631 		User::Leave(KErrArgument);
   632 		}
   633 
   634 	EGLConfig configs[KMaxEglConfigs];
   635 	EGLint numConfigs=0;
   636 	ASSERT_EGL_TRUE(eglChooseConfig(iDisplay, KConfigAttribs[aConfigAttribIndex], configs, KMaxEglConfigs, &numConfigs));
   637 	if (numConfigs <= 0)
   638 		{
   639 		// we just WARN, as we don't know if this is expected yet (if it is, then catch the leaving error)
   640 		WARN_PRINTF1(_L("GetConfigExactMatchL - Could not find a matching config, eglChooseConfig returned 0 configs!"));
   641 		User::Leave(KTestNoMatchingConfig);
   642 		}
   643 
   644 	// Check that any of the configs returned matches the desired attributes
   645 	TInt match = GetFullMatchConfigIndex(iDisplay, configs, numConfigs, KConfigAttribs[aConfigAttribIndex], aMatchRule);
   646 	if (match == KErrNotFound)
   647 		{
   648 		// we just WARN, as we don't know if this is expected yet (if it is, then catch the leaving error)
   649 		WARN_PRINTF1(_L("GetConfigExactMatchL - Could not find a matching config amongst those returned by eglChooseConfig!"));
   650 		User::Leave(KTestNoMatchingConfig);
   651 		}
   652 	return configs[match];
   653 	}
   654 
   655 /**
   656 Creates a pixmap surface from a CFbsBitmap, draws to it and checks that the drawing operation succeeded.
   657 */
   658 EXPORT_C void CTestEglSession::TryUsePixmapCFbsBitmapL()
   659 	{
   660 	INFO_PRINTF2(_L("thread %d: TryUsePixmapCFbsBitmapL"), iThreadIdx);
   661 	EGLConfig currentConfig = GetConfigExactMatchL(EPixmapAttribsColor64K);
   662 	TryUsePixmapCFbsBitmapOpenVgL(currentConfig, KPixmapSize, EColor64K);
   663 	}
   664 
   665 /**
   666 Creates a pixmap surface from a CFbsBitmap, draws to it and checks that the drawing operation succeeded.
   667 */
   668 EXPORT_C void CTestEglSession::TryUsePixmapCFbsBitmapOpenVgL(EGLConfig aConfig, const TSize& aSize, TDisplayMode aDisplayMode)
   669 	{
   670 	CreatePixmapSurfaceAndMakeCurrentL(aConfig, aSize, aDisplayMode);
   671 	DrawOpenVgL();
   672 
   673 	// Wait for the drawing to complete
   674 	eglWaitClient();
   675 
   676 	CheckImageDataL(iFbsBitmap);
   677 	CheckImageDataVgL(VG_sRGB_565);
   678 	CleanupSurfaceFbsBitmapL();
   679 	CloseFbsSession();
   680 	}
   681 
   682 /**
   683 Creates a pixmap surface from a CFbsBitmap, draws to it and checks that the drawing operation succeeded.
   684 */
   685 EXPORT_C void CTestEglSession::TryUsePixmapCFbsBitmapOpenGlesL(EGLConfig aConfig, const TSize& aSize, TDisplayMode aDisplayMode, TInt aRenderVersion)
   686 	{
   687 	CreatePixmapSurfaceAndMakeCurrentL(aConfig, aSize, aDisplayMode,EGL_OPENGL_ES_API, aRenderVersion);
   688 	DrawOpenGLesL();
   689 
   690 	// Wait for the drawing to complete
   691 	eglWaitClient();
   692 
   693 	CheckImageDataFullRedishL(iFbsBitmap);
   694 	CleanupSurfaceFbsBitmapL();
   695 	CloseFbsSession();
   696 	}
   697 
   698 /**
   699  Creates a pixmap surface from a RSgImage, draws to it and checks that the drawing operation succeeded.
   700  */
   701 EXPORT_C void CTestEglSession::TryUsePixmapRSgImageL()
   702 	{
   703 	INFO_PRINTF2(_L("thread %d: TryUsePixmapRSgImageL"), iThreadIdx);
   704 	TSgImageInfo imageInfo;
   705 	imageInfo.iSizeInPixels = KPixmapSize;
   706 	imageInfo.iPixelFormat = EUidPixelFormatXRGB_8888;
   707 	// will draw to and read from the image using OpenVg
   708 #ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
   709 	imageInfo.iUsage = ESgUsageBitOpenVgSurface | ESgUsageBitOpenVgImage;
   710 #else
   711     // will also read from the image using DirectGdi
   712     imageInfo.iUsage = ESgUsageOpenVgTarget | ESgUsageDirectGdiSource;
   713     imageInfo.iShareable = EFalse;
   714     imageInfo.iCpuAccess = ESgCpuAccessNone;
   715     imageInfo.iScreenId = KSgScreenIdMain;
   716     imageInfo.iUserAttributes = NULL;
   717     imageInfo.iUserAttributeCount=0;
   718 #endif
   719 	CreatePixmapSurfaceAndMakeCurrentAndMatchL(imageInfo, EResourceCloseSgImageLate);
   720 	DrawOpenVgL();
   721 
   722 	// Wait for the drawing to complete
   723 	 eglWaitClient();
   724 
   725 	//we can't retrieve data directly from the SgImage as
   726 	//non-unified architecture doesn't allow readback from the GPU
   727 	CheckImageDataVgL(VG_sXRGB_8888);
   728 	CleanupSurfaceSgImageL();
   729 	CloseSgDriver();
   730 	}
   731 
   732 EXPORT_C TBool CTestEglSession::TryUsePixmapRSgImageOpenGlesL(EGLConfig aConfig, const TSgImageInfo& aImageInfo, TResourceCloseRule aResourceCloseRule, TInt aRenderVersion)
   733 	{
   734 	CreatePixmapSurfaceAndMakeCurrentL(aConfig, aImageInfo, aResourceCloseRule ,EGL_OPENGL_ES_API, aRenderVersion);
   735 
   736 	DrawOpenGLesL();
   737 
   738 	// Wait for the drawing to complete
   739 	eglWaitClient();
   740 
   741 	//we can't retrieve data directly from SgImage as non-unified
   742 	//architecture doesn't allow readback from the GPU
   743 
   744 	if (aImageInfo.iPixelFormat == EUidPixelFormatXRGB_8888  ||
   745 		aImageInfo.iPixelFormat == EUidPixelFormatARGB_8888_PRE)
   746 		{
   747 		CheckImageDataGLesL();
   748 		}
   749 
   750 	CleanupSurfaceSgImageL();
   751 	CloseSgDriver();
   752 	return ETrue;
   753 	}
   754 
   755 /**
   756 Compound operation that constructs an RSgImage and uses it to create a pixmap suface.
   757 It then draws to the surface using OpenVG and checks whether the drawing succeeded.
   758 It cleans up the pixmap surface it destroyed.
   759 @param aConfig The EGL config to be used when creating the pixmap surface
   760 @param aImageInfo Used to create the RSgImage pixmap
   761 @param aCloseNativeImageEarly When ETrue, the RSgImage is closed as soon as the pixmap surface has been
   762 		created.  Otherwise, the RSgImage is closed during cleanup, when the pixmap surface is destroyed.
   763 @return Whether it was possible to create an iSgImage for the given aImageInfo
   764 */
   765 EXPORT_C TBool CTestEglSession::TryUsePixmapRSgImageOpenVgL(EGLConfig aConfig, const TSgImageInfo& aImageInfo, TResourceCloseRule aResourceCloseRule)
   766 	{
   767 	CreatePixmapSurfaceAndMakeCurrentL(aConfig, aImageInfo, aResourceCloseRule);
   768 
   769 	DrawOpenVgL();
   770 
   771 	// Wait for the drawing to complete
   772 	eglWaitClient();
   773 
   774 	//we can't retrieve data directly from the SgImage as
   775 	//non-unified architecture doesn't allow readback from the GPU
   776 	CheckImageDataVgL(VG_sXRGB_8888);
   777 	CleanupSurfaceSgImageL();
   778 	CloseSgDriver();
   779 	return ETrue;
   780 	}
   781 
   782 EXPORT_C void CTestEglSession::CreateWindowSurfaceAndMakeCurrentL(EGLConfig aConfig, RWindow& aWindow, TBool aVgAlphaFormatPre, EGLenum aBindAPI, TInt aRenderVersionNumber, EGLint* aAttribList)
   783 	{
   784 	ASSERT_EQUALS(iSurface, EGL_NO_SURFACE);
   785 	ASSERT_EQUALS(iContext, EGL_NO_CONTEXT);
   786 
   787 	ASSERT_EGL_TRUE(eglBindAPI(aBindAPI));
   788 
   789 	// Create a Window surface from the native image
   790 	const EGLint* windowAttribs = aAttribList;
   791     if(!windowAttribs)
   792         {
   793         windowAttribs = (aVgAlphaFormatPre && aBindAPI == EGL_OPENVG_API) ? KPixmapAttribsVgAlphaFormatPre : KPixmapAttribsNone;
   794         }
   795 	iSurface = eglCreateWindowSurface(iDisplay, aConfig, &aWindow, windowAttribs);
   796 	ASSERT_EGL_TRUE(iSurface != EGL_NO_SURFACE);
   797 
   798 	// Create a context for drawing to/reading from the pixmap surface and make it current
   799 	const EGLint KAttribsListCtxNone[] = { EGL_NONE };
   800 	const EGLint KAttribsListCtxGles2[] = { EGL_CONTEXT_CLIENT_VERSION, aRenderVersionNumber, EGL_NONE };
   801 	const EGLint* attrib_list_ctx = (aBindAPI == EGL_OPENGL_ES_API && aRenderVersionNumber == 2) ? KAttribsListCtxGles2 : KAttribsListCtxNone;
   802 	iContext = eglCreateContext(iDisplay, aConfig, EGL_NO_CONTEXT, attrib_list_ctx);
   803 	ASSERT_EGL_TRUE(iContext != EGL_NO_CONTEXT);
   804 	ASSERT_EGL_TRUE(eglMakeCurrent(iDisplay, iSurface, iSurface, iContext));
   805 	}
   806 
   807 
   808 EXPORT_C TBool CTestEglSession::CongfigSupportsOpenVgL(EGLConfig aConfig)
   809 	{
   810 	EGLint EGL_RENDERABLE_TYPE_value = 0;
   811 	ASSERT_EGL_TRUE(eglGetConfigAttrib(iDisplay, aConfig, EGL_RENDERABLE_TYPE, &EGL_RENDERABLE_TYPE_value));
   812 	return (EGL_RENDERABLE_TYPE_value&EGL_OPENVG_BIT)>0;
   813 	}
   814 
   815 EXPORT_C void CTestEglSession::CreatePixmapSurfaceAndMakeCurrentAndMatchL(const TSgImageInfo& aImageInfo, TResourceCloseRule aResourceCloseRule, EGLenum aBindAPI, TInt aRenderVersionNumber)
   816 	{
   817 	ASSERT_EQUALS(iSurface, EGL_NO_SURFACE);
   818 	ASSERT_EQUALS(iContext, EGL_NO_CONTEXT);
   819 
   820     OpenSgDriverL();
   821     ASSERT_EQUALS(iSgImage.Create(aImageInfo, NULL, 0), KErrNone);
   822 
   823 	EGLint renderableType = 0;
   824 	if(aBindAPI == EGL_OPENVG_API)
   825 		{
   826 		renderableType = EGL_OPENVG_BIT;
   827 		}
   828 	else if(aBindAPI == EGL_OPENGL_ES_API && aRenderVersionNumber==1)
   829 		{
   830 		renderableType = EGL_OPENGL_ES_BIT;
   831 		}
   832 	else if(aBindAPI == EGL_OPENGL_ES_API && aRenderVersionNumber==2)
   833 		{
   834 		renderableType = EGL_OPENGL_ES2_BIT;
   835 		}
   836 	else
   837 		{
   838 		ERR_PRINTF1(_L("CreatePixmapSurfaceAndMakeCurrentAndMatchL - Unkown API requested!"));
   839 		User::Leave(KErrArgument);
   840 		}
   841 	EGLint attrib_list[] = {
   842 			  EGL_MATCH_NATIVE_PIXMAP,(TInt)&iSgImage,
   843 			  EGL_RENDERABLE_TYPE,renderableType,
   844 			  EGL_SURFACE_TYPE,EGL_PIXMAP_BIT,
   845 			  EGL_NONE};
   846 
   847 	ASSERT_EGL_TRUE(eglBindAPI(aBindAPI));
   848 
   849 	EGLConfig config;
   850 	EGLint numConfigs;
   851 	ASSERT_EGL_TRUE(eglChooseConfig(iDisplay,attrib_list,&config,1,&numConfigs));
   852 	if (numConfigs <= 0)
   853 		{
   854 		// we just WARN, as we don't know if this is expected yet (if it is, then catch the leaving error)
   855 		WARN_PRINTF1(_L("CreatePixmapSurfaceAndMakeCurrentAndMatchL - Could not find a matching config!"));
   856 		iSgImage.Close();
   857 		CloseSgDriver();
   858 		// Leave with a unique knonwn error code - useful to catch this error in negative tests
   859 		User::Leave(KTestNoMatchingConfig);
   860 		}
   861 
   862 	// Create a pixmap surface from the native image
   863 	EGLint EGL_RENDERABLE_TYPE_value = 0;
   864 	ASSERT_EGL_TRUE(eglGetConfigAttrib(iDisplay, config, EGL_RENDERABLE_TYPE, &EGL_RENDERABLE_TYPE_value));
   865 	const EGLint* pixmapAttribs = ((aImageInfo.iPixelFormat == EUidPixelFormatARGB_8888_PRE) && (EGL_RENDERABLE_TYPE_value & EGL_OPENVG_BIT)) ? KPixmapAttribsVgAlphaFormatPre : KPixmapAttribsNone;
   866 	iSurface = eglCreatePixmapSurface(iDisplay, config, &iSgImage, pixmapAttribs);
   867 	ASSERT_EGL_TRUE(iSurface != EGL_NO_SURFACE);
   868 
   869 	if (aResourceCloseRule == EResourceCloseSgImageEarly)
   870 		{
   871 		// EGL should have taken its own reference to the SgImage, so it should be able to continue
   872 		// to use the underlying data after this local image has been closed.
   873 		iSgImage.Close();
   874 		}
   875 
   876 	if (aResourceCloseRule == EResourceCloseSgDriverAndImageEarly)
   877 		{
   878 		// EGL should have taken its own reference to the SgDriver, so it should be able to continue
   879 		// to use its reference to the image resource after this local reference to the driver has
   880 		// been closed.
   881 		iSgImage.Close();
   882 		CloseSgDriver();
   883 		}
   884 
   885 	// Create a context for drawing to/reading from the pixmap surface and make it current
   886 	const EGLint KAttribsListCtxNone[] = { EGL_NONE };
   887 	const EGLint KAttribsListCtxGles2[] = { EGL_CONTEXT_CLIENT_VERSION, aRenderVersionNumber, EGL_NONE };
   888 	const EGLint* attrib_list_ctx = (aBindAPI == EGL_OPENGL_ES_API && aRenderVersionNumber == 2) ? KAttribsListCtxGles2 : KAttribsListCtxNone; 
   889 	iContext = eglCreateContext(iDisplay, config, EGL_NO_CONTEXT, attrib_list_ctx);
   890 	ASSERT_EGL_TRUE(iContext != EGL_NO_CONTEXT);	
   891 	ASSERT_EGL_TRUE(eglMakeCurrent(iDisplay, iSurface, iSurface, iContext));
   892 	}
   893 
   894 /**
   895 Compound operation that constructs an RSgImage and uses it to create a pixmap suface.
   896 It then makes it current to the thread.
   897 @param aConfig The EGL config to be used when creating the pixmap surface
   898 @param aImageInfo Used to create the RSgImage pixmap
   899 @param aCloseNativeImageEarly When ETrue, the RSgImage is closed as soon as the pixmap surface has been
   900 		created.  Otherwise, the RSgImage is left to be destroyed later by some other method
   901 		- e.g at the same time as destroying the surface.
   902 @return Whether it was possible to create an iSgImage for the given aImageInfo
   903 */
   904 EXPORT_C void CTestEglSession::CreatePixmapSurfaceAndMakeCurrentL(EGLConfig aConfig, const TSgImageInfo& aImageInfo, TResourceCloseRule aResourceCloseRule, EGLenum aBindAPI, TInt aRenderVersionNumber)
   905 	{
   906 	ASSERT_EQUALS(iSurface, EGL_NO_SURFACE);
   907 	ASSERT_EQUALS(iContext, EGL_NO_CONTEXT);
   908 
   909 	OpenSgDriverL();
   910     ASSERT_EQUALS(iSgImage.Create(aImageInfo, NULL, 0), KErrNone);
   911 
   912 	ASSERT_EGL_TRUE(eglBindAPI(aBindAPI));
   913 
   914 	// Create a pixmap surface from the native image
   915 	EGLint EGL_RENDERABLE_TYPE_value = 0;
   916 	ASSERT_EGL_TRUE(eglGetConfigAttrib(iDisplay, aConfig, EGL_RENDERABLE_TYPE, &EGL_RENDERABLE_TYPE_value));
   917 	const EGLint* pixmapAttribs = ((aImageInfo.iPixelFormat == EUidPixelFormatARGB_8888_PRE) && (EGL_RENDERABLE_TYPE_value & EGL_OPENVG_BIT)) ? KPixmapAttribsVgAlphaFormatPre : KPixmapAttribsNone;
   918 	iSurface = eglCreatePixmapSurface(iDisplay, aConfig, &iSgImage, pixmapAttribs);
   919 	ASSERT_EGL_TRUE(iSurface != EGL_NO_SURFACE);
   920 
   921 	if (aResourceCloseRule == EResourceCloseSgImageEarly)
   922 		{
   923 		// EGL should have taken its own reference to the SgImage, so it should be able to continue
   924 		// to use the underlying data after this local image has been closed.
   925 		iSgImage.Close();
   926 		}
   927 	if (aResourceCloseRule == EResourceCloseSgDriverAndImageEarly)
   928 		{
   929 		// EGL should have taken its own reference to the SgDriver, so it should be able to continue
   930 		// to use its reference to the image resource after this local reference to the driver has
   931 		// been closed.
   932 		iSgImage.Close();
   933 		CloseSgDriver();
   934 		}
   935 
   936 	// Create a context for drawing to/reading from the pixmap surface and make it current
   937 	const EGLint KAttribsListCtxNone[] = { EGL_NONE };
   938 	const EGLint KAttribsListCtxGles2[] = { EGL_CONTEXT_CLIENT_VERSION, aRenderVersionNumber, EGL_NONE };
   939 	const EGLint* attrib_list_ctx = (aBindAPI == EGL_OPENGL_ES_API && aRenderVersionNumber == 2) ? KAttribsListCtxGles2 : KAttribsListCtxNone;
   940 	iContext = eglCreateContext(iDisplay, aConfig, EGL_NO_CONTEXT, attrib_list_ctx);
   941 	ASSERT_EGL_TRUE(iContext != EGL_NO_CONTEXT);
   942 	ASSERT_EGL_TRUE(eglMakeCurrent(iDisplay, iSurface, iSurface, iContext));
   943 	}
   944 
   945 EXPORT_C TInt CTestEglSession::CreateBitmap(CFbsBitmap* aFbsBitmap, const TSize& aSize, TDisplayMode aDisplayMode)
   946 	{
   947 	//Fist try with CreateHardwareBitmap to check whether we are on hardware
   948 	TInt result = aFbsBitmap->CreateHardwareBitmap(aSize, aDisplayMode, KUidEglTestServer);
   949 
   950 	if(result == KErrNotSupported)
   951 		{
   952 		//we are not on hardware
   953 		result = aFbsBitmap->Create(aSize, aDisplayMode);
   954 		}
   955 	return result;
   956 	}
   957 
   958 EXPORT_C void CTestEglSession::CreatePixmapSurfaceAndMakeCurrentL(EGLConfig aConfig, const TSize& aSize, TDisplayMode displayMode, EGLenum aBindAPI, TInt aRenderVersionNumber)
   959 	{
   960 	ASSERT_EQUALS(iSurface, EGL_NO_SURFACE);
   961 	ASSERT_EQUALS(iContext, EGL_NO_CONTEXT);
   962 
   963 	// Create an empty native CFbsBitmap
   964 	OpenFbsSessionL();
   965 	iFbsBitmap = new(ELeave)CFbsBitmap;
   966 	ASSERT_EQUALS(CreateBitmap(iFbsBitmap, aSize, displayMode), KErrNone);
   967 
   968     const EGLint* attrib_list = NULL;
   969 	if(aBindAPI == EGL_OPENVG_API)
   970 		{
   971 		// no attribs to modify
   972 		}
   973 	else if(aBindAPI == EGL_OPENGL_ES_API)
   974 		{
   975 		// no attribs to modify
   976 		}
   977 	else if(aBindAPI == EGL_OPENGL_ES_API && aRenderVersionNumber==2)
   978 		{
   979 	    const EGLint KAttribGLES2[] = {EGL_CONTEXT_CLIENT_VERSION, aRenderVersionNumber, EGL_NONE};
   980 		attrib_list=KAttribGLES2;
   981 		}
   982 	else
   983 		{
   984 		ERR_PRINTF1(_L("CreatePixmapSurfaceAndMakeCurrentL - Unkown API requested!"));
   985 		User::Leave(KErrArgument);
   986 		}
   987 	ASSERT_EGL_TRUE(eglBindAPI(aBindAPI));
   988 
   989 	// Create a pixmap surface from the native image
   990 	EGLint EGL_RENDERABLE_TYPE_value = 0;
   991 	ASSERT_EGL_TRUE(eglGetConfigAttrib(iDisplay, aConfig, EGL_RENDERABLE_TYPE, &EGL_RENDERABLE_TYPE_value));
   992 	const EGLint* pixmapAttribs = ((displayMode == EColor16MAP) && (EGL_RENDERABLE_TYPE_value & EGL_OPENVG_BIT)) ? KPixmapAttribsVgAlphaFormatPre : KPixmapAttribsNone;
   993 	iSurface = eglCreatePixmapSurface(iDisplay, aConfig, iFbsBitmap, pixmapAttribs);
   994 	ASSERT_EGL_TRUE(iSurface != EGL_NO_SURFACE);
   995 
   996 	// Create a context for drawing to/reading from the pixmap surface and make it current
   997 	iContext = eglCreateContext(iDisplay, aConfig, EGL_NO_CONTEXT, attrib_list);
   998 	ASSERT_EGL_TRUE(iContext != EGL_NO_CONTEXT);
   999 	ASSERT_EGL_TRUE(eglMakeCurrent(iDisplay, iSurface, iSurface, iContext));
  1000 	}
  1001 
  1002 EXPORT_C void CTestEglSession::CreatePixmapSurfaceAndMakeCurrentAndMatchL(const TSize& aSize, TDisplayMode aDisplayMode, EGLenum aBindAPI, TInt aRenderVersionNumber)
  1003 	{
  1004 	ASSERT_EQUALS(iSurface, EGL_NO_SURFACE);
  1005 	ASSERT_EQUALS(iContext, EGL_NO_CONTEXT);
  1006 
  1007 	OpenFbsSessionL();
  1008 	iFbsBitmap = new(ELeave)CFbsBitmap;
  1009 	ASSERT_EQUALS(CreateBitmap(iFbsBitmap, aSize, aDisplayMode), KErrNone);
  1010 
  1011 	EGLint renderableType = 0;
  1012 	if(aBindAPI == EGL_OPENVG_API)
  1013 		{
  1014 		renderableType = EGL_OPENVG_BIT;
  1015 		}
  1016 	else if(aBindAPI == EGL_OPENGL_ES_API && aRenderVersionNumber==1)
  1017 		{
  1018 		renderableType = EGL_OPENGL_ES_BIT;
  1019 		}
  1020 	else if(aBindAPI == EGL_OPENGL_ES_API && aRenderVersionNumber==2)
  1021 		{
  1022 		renderableType = EGL_OPENGL_ES2_BIT;
  1023 		}
  1024 	else
  1025 		{
  1026 		ERR_PRINTF1(_L("CreatePixmapSurfaceAndMakeCurrentAndMatchL - Unkown API requested!"));
  1027 		User::Leave(KErrArgument);
  1028 		}
  1029 	EGLint attrib_list[] = {
  1030 			  EGL_MATCH_NATIVE_PIXMAP,(TInt)iFbsBitmap,
  1031 			  EGL_RENDERABLE_TYPE,renderableType,
  1032 			  EGL_SURFACE_TYPE,EGL_PIXMAP_BIT,
  1033 			  EGL_NONE};
  1034 
  1035 	ASSERT_EGL_TRUE(eglBindAPI(aBindAPI));
  1036 
  1037 	EGLConfig config;
  1038 	EGLint numConfigs;
  1039 	ASSERT_EGL_TRUE(eglChooseConfig(iDisplay,attrib_list,&config,1,&numConfigs));
  1040 	if (numConfigs <= 0)
  1041 		{
  1042 		// we just WARN, as we don't know if this is expected yet (if it is, then catch the leaving error)
  1043 		WARN_PRINTF1(_L("CreatePixmapSurfaceAndMakeCurrentAndMatchL - Could not find a matching config!"));
  1044 		iSgImage.Close();
  1045 		CloseSgDriver();
  1046 		// Leave with a unique knonwn error code - useful to catch this error in negative tests
  1047 		User::Leave(KTestNoMatchingConfig);
  1048 		}
  1049 
  1050 	// Create a pixmap surface from the native image
  1051 	const EGLint* pixmapAttribs = (aDisplayMode == EColor16MAP && aBindAPI == EGL_OPENVG_API) ? KPixmapAttribsVgAlphaFormatPre : KPixmapAttribsNone;
  1052 	iSurface = eglCreatePixmapSurface(iDisplay, config, iFbsBitmap, pixmapAttribs);
  1053 	ASSERT_EGL_TRUE(iSurface != EGL_NO_SURFACE);
  1054 
  1055 	// Create a context for drawing to/reading from the pixmap surface and make it current
  1056 	const EGLint KAttribsListCtxNone[] = { EGL_NONE };
  1057 	const EGLint KAttribsListCtxGles2[] = { EGL_CONTEXT_CLIENT_VERSION, aRenderVersionNumber, EGL_NONE };
  1058 	const EGLint* attrib_list_ctx = (aBindAPI == EGL_OPENGL_ES_API && aRenderVersionNumber == 2) ? KAttribsListCtxGles2 : KAttribsListCtxNone;
  1059 	iContext = eglCreateContext(iDisplay, config, EGL_NO_CONTEXT, attrib_list_ctx);
  1060 	ASSERT_EGL_TRUE(iContext != EGL_NO_CONTEXT);
  1061 	ASSERT_EGL_TRUE(eglMakeCurrent(iDisplay, iSurface, iSurface, iContext));
  1062 	}
  1063 
  1064 EXPORT_C void CTestEglSession::CreatePbufferSurfaceAndMakeCurrentL(EGLConfig aConfig, const TSize& aSize, EGLenum aBindAPI, TInt aRenderVersionNumber)
  1065 	{
  1066 	ASSERT_EQUALS(iSurface, EGL_NO_SURFACE);
  1067 	ASSERT_EQUALS(iContext, EGL_NO_CONTEXT);
  1068 
  1069 	ASSERT_EQUALS(iSurface, EGL_NO_SURFACE);
  1070 	ASSERT_EQUALS(iContext, EGL_NO_CONTEXT);
  1071 
  1072 	ASSERT_EGL_TRUE(eglBindAPI(aBindAPI));
  1073 
  1074 	//	PBuffer attribs options are:
  1075 	//		EGL_WIDTH, EGL_HEIGHT, EGL_LARGEST_PBUFFER,
  1076 	//		EGL_TEXTURE_FORMAT, EGL_TEXTURE_TARGET, EGL_MIPMAP_TEXTURE,
  1077 	//		EGL_VG_COLORSPACE, and EGL_VG_ALPHA_FORMAT
  1078 	// Create a pbuffer surface of the given size
  1079 	const EGLint KPbufferAttribs[] = {
  1080 			EGL_WIDTH,	aSize.iWidth,
  1081 			EGL_HEIGHT,	aSize.iHeight,
  1082 			EGL_NONE };
  1083 	iSurface = eglCreatePbufferSurface(iDisplay, aConfig, KPbufferAttribs);
  1084 	ASSERT_EGL_TRUE(iSurface != EGL_NO_SURFACE);
  1085 
  1086 	// Create a context for drawing to/reading from the pixmap surface and make it current
  1087 	const EGLint KAttribsListCtxNone[] = { EGL_NONE };
  1088 	const EGLint KAttribsListCtxGles2[] = { EGL_CONTEXT_CLIENT_VERSION, aRenderVersionNumber, EGL_NONE };
  1089 	const EGLint* attrib_list_ctx = (aBindAPI == EGL_OPENGL_ES_API && aRenderVersionNumber == 2) ? KAttribsListCtxGles2 : KAttribsListCtxNone;
  1090 	iContext = eglCreateContext(iDisplay, aConfig, EGL_NO_CONTEXT, attrib_list_ctx);
  1091 	ASSERT_EGL_TRUE(iContext != EGL_NO_CONTEXT);
  1092 	ASSERT_EGL_TRUE(eglMakeCurrent(iDisplay, iSurface, iSurface, iContext));
  1093 	}
  1094 
  1095 EXPORT_C void CTestEglSession::DrawOpenVgL()
  1096 	{
  1097 	ASSERT_TRUE(iSurface != EGL_NO_SURFACE);
  1098 	ASSERT_TRUE(iContext != EGL_NO_CONTEXT);
  1099 
  1100 	// Draw to the pixmap surface
  1101 	// Clear it: redish
  1102 	VGfloat colorBackground[4];
  1103 	ConvertColor(KRgbReddish, colorBackground);
  1104 	vgSetfv(VG_CLEAR_COLOR, 4, colorBackground);
  1105 	vgClear(0, 0, KPixmapSize.iWidth, KPixmapSize.iHeight);
  1106 
  1107 	// And add a square: greenish
  1108 	VGfloat colorSquare[4];
  1109 	ConvertColor(KRgbGreenish, colorSquare);
  1110 	vgSetfv(VG_CLEAR_COLOR, 4, colorSquare);
  1111 	vgClear(KPixmapSquare.iTl.iX, KPixmapSquare.iTl.iX, KPixmapSquare.Width(), KPixmapSquare.Height());
  1112 	}
  1113 
  1114 EXPORT_C void CTestEglSession::DrawOpenGLesL()
  1115 	{
  1116 	ASSERT_TRUE(iSurface != EGL_NO_SURFACE);
  1117 	ASSERT_TRUE(iContext != EGL_NO_CONTEXT);
  1118 	//GreenishRGB 0x46, 0xDC, 0x78
  1119 	const GLfloat glRed = KRgbReddish.Red();
  1120 	const GLfloat glGreen = KRgbReddish.Green();
  1121 	const GLfloat glBlue  = KRgbReddish.Blue();
  1122 	const GLfloat glAlpha = KRgbReddish.Alpha();
  1123 	const GLfloat glRedBits = 255.f;
  1124 	const GLfloat glGreenBits = 255.f;
  1125 	const GLfloat glBlueBits  = 255.f;
  1126 	const GLfloat glAlphaBits = 255.f;
  1127 
  1128 	// Disable  cdither - when using exact comparison to reference bitmap
  1129 	// because reference bitmap cannot be created to match dither exactly
  1130 	glDisable(GL_DITHER);
  1131 	// Clear the surface to the colour specified
  1132 	glClearColor((glRed)/glRedBits, (glGreen)/glGreenBits, (glBlue)/glBlueBits, glAlpha/glAlphaBits);
  1133 
  1134 	//glColor3f(KRgbGreenish.Red(),KRgbGreenish.Green(),KRgbGreenish.Blue());
  1135 	//glRectf(KPixmapSquare.iTl.iX, KPixmapSquare.iTl.iY,KPixmapSquare.iTl.iX + KPixmapSquare.Width(),KPixmapSquare.iTl.iY + KPixmapSquare.Height());
  1136 
  1137 	glClear(GL_COLOR_BUFFER_BIT);
  1138 	}
  1139 
  1140 EXPORT_C void CTestEglSession::CheckImageDataL(CFbsBitmap* aFbsBitmap)
  1141 	{
  1142 	// 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
  1143 	TRgb rgbPixelSample;
  1144 	// Outside the square
  1145 	aFbsBitmap->GetPixel(rgbPixelSample, TPoint(10,10));
  1146 	ASSERT_TRUE(PixelsMatch(KRgbReddish, rgbPixelSample, EFalse));
  1147 	aFbsBitmap->GetPixel(rgbPixelSample, TPoint(90,90));
  1148 	ASSERT_TRUE(PixelsMatch(KRgbReddish, rgbPixelSample, EFalse));
  1149 
  1150 	// Inside the square
  1151 	aFbsBitmap->GetPixel(rgbPixelSample, TPoint(30,30));
  1152 	ASSERT_TRUE(PixelsMatch(KRgbGreenish, rgbPixelSample, EFalse));
  1153 	aFbsBitmap->GetPixel(rgbPixelSample, TPoint(70,70));
  1154 	ASSERT_TRUE(PixelsMatch(KRgbGreenish, rgbPixelSample, EFalse));
  1155 	}
  1156 
  1157 EXPORT_C void CTestEglSession::CheckImageDataFullRedishL(CFbsBitmap* aFbsBitmap)
  1158 	{
  1159 	// 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
  1160 	TRgb rgbPixelSample;
  1161 	// Outside the square
  1162 	aFbsBitmap->GetPixel(rgbPixelSample, TPoint(10,10));
  1163 	ASSERT_TRUE(PixelsMatch(KRgbReddish, rgbPixelSample, EFalse));
  1164 	aFbsBitmap->GetPixel(rgbPixelSample, TPoint(90,90));
  1165 	ASSERT_TRUE(PixelsMatch(KRgbReddish, rgbPixelSample, EFalse));
  1166 
  1167 	// Inside the square
  1168 	aFbsBitmap->GetPixel(rgbPixelSample, TPoint(30,30));
  1169 	ASSERT_TRUE(PixelsMatch(KRgbReddish, rgbPixelSample, EFalse));
  1170 	aFbsBitmap->GetPixel(rgbPixelSample, TPoint(70,70));
  1171 	ASSERT_TRUE(PixelsMatch(KRgbReddish, rgbPixelSample, EFalse));
  1172 	}
  1173 
  1174 /**
  1175 Use OpenVG to check pixel values
  1176 @param aDataFormat The VG image data format of the current surface
  1177 */
  1178 EXPORT_C void CTestEglSession::CheckImageDataVgL(VGImageFormat aDataFormat)
  1179 	{
  1180 	switch(aDataFormat)
  1181 		{
  1182 		case VG_sRGB_565:
  1183 			{
  1184 			TUint16 intPixelSample=0;
  1185 
  1186 			// Outside the square
  1187 			vgReadPixels(&intPixelSample, 1, aDataFormat, 10,10, 1,1);
  1188 			ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color64K(intPixelSample), EFalse));
  1189 			vgReadPixels(&intPixelSample, 1, aDataFormat, 90,90, 1,1);
  1190 			ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color64K(intPixelSample), EFalse));
  1191 
  1192 			// Inside the square
  1193 			vgReadPixels(&intPixelSample, 1, aDataFormat, 30,30, 1,1);
  1194 			ASSERT_TRUE(PixelsMatch(KRgbGreenish, TRgb::Color64K(intPixelSample), EFalse));
  1195 			vgReadPixels(&intPixelSample, 1, aDataFormat, 70,70, 1,1);
  1196 			ASSERT_TRUE(PixelsMatch(KRgbGreenish, TRgb::Color64K(intPixelSample), EFalse));
  1197 			break;
  1198 			}
  1199 		case VG_sXRGB_8888:
  1200 			{
  1201 			TUint32 intPixelSample=0;
  1202 
  1203 			// Outside the square
  1204 			vgReadPixels(&intPixelSample, 1, aDataFormat, 10,10, 1,1);
  1205 			ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color16MU(intPixelSample), EFalse));
  1206 			vgReadPixels(&intPixelSample, 1, aDataFormat, 90,90, 1,1);
  1207 			ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color16MU(intPixelSample), EFalse));
  1208 
  1209 			// Inside the square
  1210 			vgReadPixels(&intPixelSample, 1, aDataFormat, 30,30, 1,1);
  1211 			ASSERT_TRUE(PixelsMatch(KRgbGreenish, TRgb::Color16MU(intPixelSample), EFalse));
  1212 			vgReadPixels(&intPixelSample, 1, aDataFormat, 70,70, 1,1);
  1213 			ASSERT_TRUE(PixelsMatch(KRgbGreenish, TRgb::Color16MU(intPixelSample), EFalse));
  1214 			break;
  1215 			}
  1216 		case VG_sARGB_8888:
  1217 			{
  1218 			TUint32 intPixelSample=0;
  1219 
  1220 			// Outside the square
  1221 			vgReadPixels(&intPixelSample, 1, aDataFormat, 10,10, 1,1);
  1222 			ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color16MA(intPixelSample), EFalse));
  1223 			vgReadPixels(&intPixelSample, 1, aDataFormat, 90,90, 1,1);
  1224 			ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color16MA(intPixelSample), EFalse));
  1225 
  1226 			// Inside the square
  1227 			vgReadPixels(&intPixelSample, 1, aDataFormat, 30,30, 1,1);
  1228 			ASSERT_TRUE(PixelsMatch(KRgbGreenish, TRgb::Color16MA(intPixelSample), EFalse));
  1229 			vgReadPixels(&intPixelSample, 1, aDataFormat, 70,70, 1,1);
  1230 			ASSERT_TRUE(PixelsMatch(KRgbGreenish, TRgb::Color16MA(intPixelSample), EFalse));
  1231 			break;
  1232 			}
  1233 		default:
  1234 			WARN_PRINTF2(_L("Unexpected image data format %d in CTestEglSession::CheckImageDataVgL"), aDataFormat);
  1235 			ASSERT_TRUE(EFalse);
  1236 		}
  1237 	}
  1238 
  1239 /**
  1240 Use OpenGLes to check pixel values
  1241 @param aDataFormat The VG image data format of the current surface
  1242 */
  1243 EXPORT_C void CTestEglSession::CheckImageDataGLesL()
  1244 	{
  1245 	TUint32 intPixelSample;
  1246 	glReadPixels(10,10,1,1,GL_RGBA,GL_UNSIGNED_BYTE ,&intPixelSample);
  1247 	SwapChannels(intPixelSample);
  1248 	ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color16MU(intPixelSample), EFalse));
  1249 
  1250 	glReadPixels(45,45,1,1,GL_RGBA,GL_UNSIGNED_BYTE ,&intPixelSample);
  1251 	SwapChannels(intPixelSample);
  1252 	ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color16MU(intPixelSample), EFalse));
  1253 
  1254 	glReadPixels(55,55,1,1,GL_RGBA,GL_UNSIGNED_BYTE ,&intPixelSample);
  1255 	SwapChannels(intPixelSample);
  1256 	ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color16MU(intPixelSample), EFalse));
  1257 
  1258 	glReadPixels(99,99,1,1,GL_RGBA,GL_UNSIGNED_BYTE ,&intPixelSample);
  1259 	SwapChannels(intPixelSample);
  1260 	ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color16MU(intPixelSample), EFalse));
  1261 
  1262 	}
  1263 
  1264 EXPORT_C void CTestEglSession::SwapChannels(TUint32 &aSwapMe)
  1265 	{
  1266 	TUint32 buff = aSwapMe;
  1267 
  1268 	aSwapMe = 0;
  1269 	aSwapMe |= (buff & 0x000000FF) << 16;
  1270 	aSwapMe |= (buff & 0x0000FF00);
  1271 	aSwapMe |= (buff & 0x00FF0000) >> 16;
  1272 	aSwapMe |= (buff & 0xFF000000);
  1273 	}
  1274 
  1275 /**
  1276 Destroys the surface and underlying RSgImage object.
  1277 Nulls the current context.
  1278 */
  1279 EXPORT_C void CTestEglSession::CleanupSurfaceSgImageL()
  1280 	{
  1281 	CleanupSurfaceAndContextL();
  1282 
  1283 	iSgImage.Close();
  1284 	}
  1285 
  1286 /**
  1287 Resets the internal surface and context handles without destroying them.
  1288 Also closes the internal RSgImage handled that is associated to the surface.
  1289 
  1290 EGL destroys all surface and context handles associated with a display when
  1291 eglTerminate() is called.
  1292 */
  1293 EXPORT_C void CTestEglSession::ResetSurfaceAndContextSgImageL()
  1294 	{
  1295 	INFO_PRINTF1(_L("CTestEglSession::ResetSurfaceAndContextSgImageL()"));
  1296 
  1297 	iContext = EGL_NO_CONTEXT;
  1298 	iSurface = EGL_NO_SURFACE;
  1299 	iSgImage.Close();
  1300 	}
  1301 
  1302 /**
  1303  Check that the pixel values match within a predefined tolerance
  1304  @param aExpected the expected pixel colour vaule
  1305  @param aActual the actual pixel colour value
  1306  @param aCheckAlpha Whether to check the alpha channel value
  1307  @return Whether the pixel values match - within the allowed tolerance
  1308  */
  1309 EXPORT_C TBool CTestEglSession::PixelsMatch(const TRgb& aExpected, const TRgb& aActual, TBool aCheckAlpha)
  1310 	{
  1311 	// This value has been carefully selected. If it is too high it could be hidding genuine pixel value
  1312 	//	differences, while too low will be too strict to allow for pixel conversions, i.e. from 16bpp to 32bpp
  1313 	const TInt KPixelTolerance = 8;
  1314 
  1315 	if (aCheckAlpha && aExpected.Alpha()== 0 &&
  1316 		aActual.Red() == 0 &&
  1317 		aActual.Green() == 0 &&
  1318 		aActual.Blue() == 0 &&
  1319 		aActual.Alpha() == 0)
  1320 		{
  1321 		// if the expected value for alpha is 0, all actual values should be 0
  1322 		return ETrue;
  1323 		}
  1324 	else if (Abs(aExpected.Red() - aActual.Red()) > KPixelTolerance ||
  1325 			 Abs(aExpected.Green() - aActual.Green()) > KPixelTolerance ||
  1326 			 Abs(aExpected.Blue() - aActual.Blue()) > KPixelTolerance ||
  1327 			 aCheckAlpha && Abs(aExpected.Alpha() - aActual.Alpha()) > KPixelTolerance)
  1328 		{
  1329 		// one or more of the actual values differ by more than the allowed tolerance
  1330 		ERR_PRINTF6(_L("thread %d: Expected r:%d g:%d b:%d a:%d"), iThreadIdx, aExpected.Red(), aExpected.Green(), aExpected.Blue(), aExpected.Alpha());
  1331 		ERR_PRINTF6(_L("thread %d: Actual r:%d g:%d b:%d a:%d"), iThreadIdx, aActual.Red(), aActual.Green(), aActual.Blue(), aActual.Alpha());
  1332 		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()));
  1333 		return EFalse;
  1334 		}
  1335 	return ETrue;
  1336 	}
  1337 
  1338 EXPORT_C void CTestEglSession::InitializeL(TBool aTerminateDisplay)
  1339 	{
  1340 	// Initialize display object
  1341 	INFO_PRINTF2(_L("thread %d: Calling eglInitialize..."), iThreadIdx);
  1342 	EGLint major=0;
  1343 	EGLint minor=0;
  1344 	CHECK_EXPECTED_ERROR(eglInitialize(iDisplay, &major, &minor));
  1345 	// Remember if the user wants us to terminate the display.
  1346 	iTerminateDisplay = aTerminateDisplay;
  1347 
  1348 	INFO_PRINTF4(_L("thread %d: Initialised: EGL Version %d.%d"), iThreadIdx, major, minor);
  1349 	}
  1350 
  1351 
  1352 EXPORT_C void CTestEglSession::TerminateDisplayL()
  1353 	{
  1354 	if (iSurface != EGL_NO_SURFACE)
  1355 		{
  1356 		WARN_PRINTF2(_L("thread %d: iSurface has not been destoroyed in TerminateDisplayL..."), iThreadIdx);
  1357 		}
  1358 	if (iContext != EGL_NO_CONTEXT)
  1359 		{
  1360 		WARN_PRINTF2(_L("thread %d: iContext has not been destoroyed in TerminateDisplayL..."), iThreadIdx);
  1361 		}
  1362 	if (iDisplay != EGL_NO_DISPLAY)
  1363 		{
  1364 		INFO_PRINTF2(_L("thread %d: Calling eglMakeCurrent(NULL values) from TerminateDisplayL..."), iThreadIdx);
  1365 
  1366 		ASSERT_EGL_TRUE(eglMakeCurrent(iDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT));
  1367 
  1368 		INFO_PRINTF1(_L("Calling eglTerminate..."));
  1369 		ASSERT_EGL_TRUE(eglTerminate(iDisplay));
  1370 		iDisplay = EGL_NO_DISPLAY;
  1371 		}
  1372 	iTerminateDisplay = EFalse;
  1373 	}
  1374 
  1375 EXPORT_C void CTestEglSession::OpenSgDriverL()
  1376 	{
  1377 	if (!iSgDriverOpen)
  1378 		{
  1379 		VERBOSE_INFO_PRINTF2(_L("CTestEglSession<0x%08x> Opening SgDriver"), this);
  1380 #ifdef  SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
  1381 		TInt ret=iSgDriver.Open();
  1382 #else
  1383 		TInt ret=SgDriver::Open();
  1384 #endif	//SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
  1385 		ASSERT_EQUALS(ret, KErrNone);
  1386 		iSgDriverOpen = ETrue;
  1387 		}
  1388 	}
  1389 
  1390 EXPORT_C void CTestEglSession::CloseSgDriver()
  1391 	{
  1392 	if (iSgDriverOpen)
  1393 		{
  1394 		VERBOSE_INFO_PRINTF2(_L("CTestEglSession<0x%08x> Closing SgDriver"), this);
  1395 #ifdef  SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
  1396         iSgDriver.Close();
  1397 #else
  1398         SgDriver::Close();
  1399 #endif  //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
  1400 		iSgDriverOpen = EFalse;
  1401 		}
  1402 	}
  1403 
  1404 EXPORT_C void CTestEglSession::OpenFbsSessionL()
  1405 	{
  1406 	if (!iFbsSessionOpen)
  1407 		{
  1408 		INFO_PRINTF2(_L("CTestEglSession<0x%08x> Opening FbsSession"), this);
  1409 		TInt ret=RFbsSession::Connect();
  1410 		ASSERT_EQUALS(ret, KErrNone);
  1411 		iFbsSessionOpen = ETrue;
  1412 		}
  1413 	}
  1414 
  1415 EXPORT_C void CTestEglSession::CloseFbsSession()
  1416 	{
  1417 	if (iFbsSessionOpen)
  1418 		{
  1419 		INFO_PRINTF2(_L("CTestEglSession<0x%08x> Closing FbsSession"), this);
  1420 		RFbsSession::Disconnect();
  1421 		iFbsSessionOpen = EFalse;
  1422 		}
  1423 	}
  1424 
  1425 EXPORT_C TBool CTestEglSession::FetchProcEglCreateImageKhr()
  1426 	{
  1427 	if (!ipfnEglCreateImageKHR)
  1428 		{
  1429 		INFO_PRINTF2(_L("thread %d: Calling eglGetProcAddress(\"eglCreateImageKHR\")"), iThreadIdx);
  1430 		ipfnEglCreateImageKHR = reinterpret_cast<TFPtrEglCreateImageKhr>(eglGetProcAddress("eglCreateImageKHR"));
  1431 		if (ipfnEglCreateImageKHR==NULL)
  1432 			{
  1433 			EGLint eglError = eglGetError();
  1434 			WARN_PRINTF2(_L("eglCreateImageKHR() not found - EGL Error: 0x%x"), eglError);
  1435 			}
  1436 		}
  1437 	return (ipfnEglCreateImageKHR!=NULL);
  1438 	}
  1439 
  1440 EXPORT_C EGLImageKHR CTestEglSession::eglCreateImageKhrL(EGLDisplay aDisplay,EGLContext aContext,EGLenum aTarget,RSgImage* aSgImage,const EGLint *aAttr_List)
  1441 	{
  1442 	TBool bSuccess = FetchProcEglCreateImageKhr();
  1443 	ASSERT_TRUE(bSuccess);
  1444 	VERBOSE_INFO_PRINTF2(_L("thread %d: Calling eglCreateImageKHR"), iThreadIdx);
  1445 	EGLImageKHR eglImage = ipfnEglCreateImageKHR(aDisplay,aContext,aTarget,reinterpret_cast<EGLClientBuffer>(aSgImage),const_cast<EGLint *>(aAttr_List));
  1446 	return eglImage;
  1447 	}
  1448 
  1449 EXPORT_C EGLImageKHR CTestEglSession::eglCreateImageKhrL(EGLDisplay aDisplay,EGLContext aContext,EGLenum aTarget,CFbsBitmap &aCFbsBitmap, const EGLint *aAttr_List)
  1450 	{
  1451 	TBool bSuccess = FetchProcEglCreateImageKhr();
  1452 	ASSERT_TRUE(bSuccess);
  1453 	INFO_PRINTF2(_L("thread %d: Calling eglCreateImageKHR, with CFBsBitmap)"), iThreadIdx);
  1454 	//the following call to eglCreateImageKHR MUST fail, error handling is made outside
  1455 	EGLImageKHR eglImage = ipfnEglCreateImageKHR(aDisplay,aContext,aTarget,reinterpret_cast<EGLClientBuffer>(&aCFbsBitmap),const_cast<EGLint *>(aAttr_List));
  1456 	return eglImage;
  1457 	}
  1458 
  1459 EXPORT_C TBool CTestEglSession::FetchProcEglDestroyImageKhr()
  1460 	{
  1461 	if (!ipfnEglDestroyImageKHR)
  1462 		{
  1463 		INFO_PRINTF2(_L("thread %d: Calling eglGetProcAddress(\"eglDestroyImageKHR\")"), iThreadIdx);
  1464 		ipfnEglDestroyImageKHR = reinterpret_cast<TFPtrEglDestroyImageKhr>(eglGetProcAddress("eglDestroyImageKHR"));
  1465 		if (ipfnEglDestroyImageKHR==NULL)
  1466 			{
  1467 			EGLint eglError = eglGetError();
  1468 			WARN_PRINTF2(_L("eglDestroyImageKHR() not found - EGL Error: 0x%x"), eglError);
  1469 			}
  1470 		}
  1471 	return (ipfnEglDestroyImageKHR!=NULL);
  1472 	}
  1473 
  1474 EXPORT_C TBool CTestEglSession::DestroyEGLImage(EGLDisplay aDisplay, EGLImageKHR aEGLImageKHR)
  1475 	{
  1476 	TBool bSuccess = FetchProcEglDestroyImageKhr();
  1477 	ASSERT_TRUE(bSuccess);
  1478 	VERBOSE_INFO_PRINTF2(_L("thread %d: Calling eglDestroyImageKHR"), iThreadIdx);
  1479 	return ipfnEglDestroyImageKHR(aDisplay,aEGLImageKHR);
  1480 	}
  1481 
  1482 EXPORT_C TBool CTestEglSession::FetchProcvgCreateImageTargetKhr()
  1483 	{
  1484 	if (!ipfnvgCreateImageTargetKHR)
  1485 		{
  1486 		INFO_PRINTF2(_L("thread %d: Calling eglGetProcAddress (\"vgCreateEGLImageTargetKHR\")"), iThreadIdx);
  1487 		ipfnvgCreateImageTargetKHR = reinterpret_cast<TFPtrVgCreateEglImageTargetKhr>(eglGetProcAddress("vgCreateEGLImageTargetKHR"));
  1488 		if (ipfnvgCreateImageTargetKHR==NULL)
  1489 			{
  1490 			EGLint eglError = eglGetError();
  1491 			WARN_PRINTF2(_L("vgCreateImageTargetKHR() not found - EGL Error: 0x%x"), eglError);
  1492 			}
  1493 		}
  1494 	return (ipfnvgCreateImageTargetKHR!=NULL);
  1495 	}
  1496 
  1497 EXPORT_C VGImage CTestEglSession::vgCreateImageTargetKHR(VGeglImageKHR aImage)
  1498 	{
  1499 	TBool bSuccess = FetchProcvgCreateImageTargetKhr();
  1500 	ASSERT_TRUE(bSuccess);
  1501 	VERBOSE_INFO_PRINTF2(_L("thread %d: Calling vgCreateEGLImageTargetKHR"), iThreadIdx);
  1502 	return ipfnvgCreateImageTargetKHR(aImage);
  1503 	}
  1504 
  1505 EXPORT_C TBool CTestEglSession::IsACompatibleConfig(EGLConfig aConfig,RSgImage& aImage,TBool aLog)
  1506 	{
  1507 	EGLint EGL_BUFFER_SIZE_value;
  1508 	EGLint EGL_ALPHA_SIZE_value;
  1509 	EGLint EGL_BLUE_SIZE_value;
  1510 	EGLint EGL_GREEN_SIZE_value;
  1511 	EGLint EGL_RED_SIZE_value;
  1512 	EGLint EGL_SURFACE_TYPE_value;
  1513 	EGLint EGL_RENDERABLE_TYPE_value;
  1514 	EGLint EGL_CONFIG_ID_value;
  1515 
  1516 	eglGetConfigAttrib(iDisplay, aConfig, EGL_CONFIG_ID, &EGL_CONFIG_ID_value);
  1517 	eglGetConfigAttrib(iDisplay, aConfig, EGL_BUFFER_SIZE, &EGL_BUFFER_SIZE_value);
  1518 	eglGetConfigAttrib(iDisplay, aConfig, EGL_ALPHA_SIZE, &EGL_ALPHA_SIZE_value);
  1519 	eglGetConfigAttrib(iDisplay, aConfig, EGL_BLUE_SIZE, &EGL_BLUE_SIZE_value);
  1520 	eglGetConfigAttrib(iDisplay, aConfig, EGL_GREEN_SIZE, &EGL_GREEN_SIZE_value);
  1521 	eglGetConfigAttrib(iDisplay, aConfig, EGL_RED_SIZE, &EGL_RED_SIZE_value);
  1522 	eglGetConfigAttrib(iDisplay, aConfig, EGL_SURFACE_TYPE, &EGL_SURFACE_TYPE_value);
  1523 	eglGetConfigAttrib(iDisplay, aConfig, EGL_RENDERABLE_TYPE, &EGL_RENDERABLE_TYPE_value);
  1524 #ifdef PRINTG_CONFIGS_LOG
  1525 	INFO_PRINTF7(_L("(Config: %3d) RGBA=(%2d) %2d,%2d,%2d,%2d"), EGL_CONFIG_ID_value, EGL_BUFFER_SIZE_value,
  1526 					EGL_RED_SIZE_value, EGL_GREEN_SIZE_value, EGL_BLUE_SIZE_value,
  1527 					EGL_ALPHA_SIZE_value);
  1528 	INFO_PRINTF2(_L("RENDERABLE_TYPE %d"),EGL_RENDERABLE_TYPE_value);
  1529 #endif
  1530 
  1531 	if(!(EGL_SURFACE_TYPE_value & EGL_PIXMAP_BIT))
  1532 		{
  1533 		return EFalse;
  1534 		}
  1535 
  1536 	TBool good = ETrue;
  1537 	//requested usage bits
  1538 	TSgImageInfo requestedImageInfo;
  1539 	aImage.GetInfo(requestedImageInfo);
  1540 
  1541 #ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
  1542 	//potential usage bits
  1543     RSgImage potential;
  1544     potential.Open(aImage.Id(),ESgDoNotRestrictUsage);
  1545     TSgImageInfo potentialImageInfo;
  1546     potential.GetInfo(potentialImageInfo);
  1547     potential.Close();
  1548 #endif
  1549 
  1550 	switch(requestedImageInfo.iPixelFormat)
  1551 		{
  1552 		case EUidPixelFormatRGB_565:
  1553 			if (!(EGL_RED_SIZE_value == 5 && EGL_GREEN_SIZE_value == 6 && EGL_BLUE_SIZE_value == 5 && EGL_ALPHA_SIZE_value == 0))
  1554 				{
  1555 				good = EFalse;
  1556 				}
  1557 			break;
  1558 		case EUidPixelFormatXRGB_8888:
  1559 			if (!(EGL_RED_SIZE_value == 8 && EGL_GREEN_SIZE_value == 8 && EGL_BLUE_SIZE_value == 8 && EGL_ALPHA_SIZE_value == 0))
  1560 				{
  1561 				good = EFalse;
  1562 				}
  1563 			break;
  1564 		case EUidPixelFormatARGB_8888_PRE:
  1565 			if (!(EGL_RED_SIZE_value == 8 && EGL_GREEN_SIZE_value == 8 && EGL_BLUE_SIZE_value == 8 && EGL_ALPHA_SIZE_value == 8))
  1566 				{
  1567 				good = EFalse;
  1568 				}
  1569 			//just OVG cares about the premultiplied alpha
  1570 			if(EGL_RENDERABLE_TYPE_value& EGL_OPENVG_BIT)
  1571 			//if(requestedImageInfo.iUsage & ESgUsageBitOpenVgSurface)
  1572 				{
  1573 				if(!(EGL_SURFACE_TYPE_value & EGL_VG_ALPHA_FORMAT_PRE_BIT))
  1574 					{
  1575 					if(aLog)
  1576 						{
  1577 						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);
  1578 						}
  1579 					good = EFalse;
  1580 					}
  1581 				}
  1582 			break;
  1583 		default:
  1584 			if(aLog)
  1585 				{
  1586 				ERR_PRINTF2(_L("Wrong PixelFormat for a target, %x"), requestedImageInfo.iPixelFormat);
  1587 				}
  1588 			good = EFalse;
  1589 		}
  1590 	if(!good)
  1591 		{
  1592 		return EFalse;
  1593 		}
  1594 
  1595 #ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
  1596 	//
  1597 	//Check if strict matching requirements are met:
  1598 	//- All the supported APIs included in the EGL_RENDERABLE_TYPE of the
  1599 	// EGLConfig must be matched by the corresponding iUsage of RSgImage
  1600 	//- The following usages included in the iUsage of the RSgImage must be
  1601 	// matched by the corresponding API in EGL_RENDERABLE_TYPE of the EGLConfig:
  1602 	//         ESgUsageBitOpenGlSurface-> EGL_OPENGL_BIT
  1603 	//         ESgUsageBitOpenGlesSurface-> EGL_OPENGL_ES_BIT
  1604 	//         ESgUsageBitOpenGles2Surface-> EGL_OPENGL_ES2_BIT
  1605 	//         ESgUsageBitOpenVgSurface->EGL_OPENVG_BIT
  1606 
  1607 	EGLint usageBitsMask = 0;
  1608 	if(requestedImageInfo.iUsage & ESgUsageBitOpenVgSurface)
  1609 		{
  1610 		usageBitsMask |= EGL_OPENVG_BIT;
  1611 		}
  1612 	if(requestedImageInfo.iUsage & ESgUsageBitOpenGles2Surface)
  1613 		{
  1614 		usageBitsMask |= EGL_OPENGL_ES2_BIT;
  1615 		}
  1616     if(requestedImageInfo.iUsage & ESgUsageBitOpenGlesSurface)
  1617         {
  1618         usageBitsMask |= EGL_OPENGL_ES_BIT;
  1619         }
  1620     if(requestedImageInfo.iUsage & ESgUsageBitOpenGlSurface)
  1621         {
  1622         usageBitsMask |= EGL_OPENGL_BIT;
  1623         }
  1624 
  1625 	if(usageBitsMask  != EGL_RENDERABLE_TYPE_value)
  1626 		{
  1627 		return EFalse;
  1628 		}
  1629 #else
  1630     // requested usage & RENDERABLE_TYPE > 0
  1631     EGLint usageBitsMask = 0;
  1632     if(requestedImageInfo.iUsage & ESgUsageOpenVgTarget)
  1633         {
  1634         usageBitsMask |= EGL_OPENVG_BIT;
  1635         }
  1636     if(requestedImageInfo.iUsage & ESgUsageOpenGlesTarget)
  1637         {
  1638         usageBitsMask |= EGL_OPENGL_ES_BIT;
  1639         }
  1640     if(requestedImageInfo.iUsage & ESgUsageOpenGles2Target)
  1641         {
  1642         usageBitsMask |= EGL_OPENGL_ES2_BIT;
  1643         }
  1644     if(!(usageBitsMask & EGL_RENDERABLE_TYPE_value))
  1645         {
  1646         return EFalse;
  1647         }
  1648 
  1649     // potential usage >= RENDERABLE_TYPE
  1650 
  1651     EGLint potentialUsageBitsMask = 0;
  1652     if(potentialImageInfo.iUsage & ESgUsageOpenVgTarget)
  1653         {
  1654         potentialUsageBitsMask |= EGL_OPENVG_BIT;
  1655         }
  1656     if(potentialImageInfo.iUsage & ESgUsageOpenGlesTarget)
  1657         {
  1658         potentialUsageBitsMask |= EGL_OPENGL_ES_BIT;
  1659         }
  1660     if(potentialImageInfo.iUsage & ESgUsageOpenGles2Target)
  1661         {
  1662         potentialUsageBitsMask |= EGL_OPENGL_ES2_BIT;
  1663         }
  1664 
  1665     potentialUsageBitsMask = EGL_RENDERABLE_TYPE_value &~ potentialUsageBitsMask;
  1666     if(potentialUsageBitsMask)
  1667         {
  1668         return EFalse;
  1669         }
  1670 #endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
  1671 	return good;
  1672 	}
  1673 
  1674 EXPORT_C TBool  CTestEglSession::CheckNeededExtensionL(TInt aExtension, const TDesC& aExtensionName)
  1675 	{
  1676 	TBuf8<128> extensionName;
  1677 	extensionName.Copy(aExtensionName);
  1678 	if(aExtension & KEGL_RSgimage || extensionName.Compare(KEglRSgImage)==0)
  1679 		{
  1680 		TBool bFoundExtensionEGL_NOK_pixmap_type_rsgimage = FindExtensionStringL(EIsEGL,KEglRSgImage);
  1681 		if (!bFoundExtensionEGL_NOK_pixmap_type_rsgimage)
  1682 			{
  1683 			// The extension is not supported
  1684 			return EFalse;
  1685 			}
  1686 		}
  1687 	if(aExtension & KEGL_KHR_image_base || extensionName.Compare(KEglKhrImageBase)==0)
  1688 		{
  1689 		TBool bFoundExtensionEGL_KHR_image = FindExtensionStringL(EIsEGL,KEglKhrImageBase);
  1690 		if (!bFoundExtensionEGL_KHR_image)
  1691 			{
  1692 			// The extension is not supported
  1693 			return EFalse;
  1694 			}
  1695 		}
  1696 	if(aExtension & KEGL_KHR_image_pixmap || extensionName.Compare(KEglKhrImagePixmap)==0)
  1697 		{
  1698 		TBool bFoundExtensionEGL_KHR_image = FindExtensionStringL(EIsEGL,KEglKhrImagePixmap);
  1699 		if (!bFoundExtensionEGL_KHR_image)
  1700 			{
  1701 			// The extension is not supported
  1702 			return EFalse;
  1703 			}
  1704 		}
  1705 	if(aExtension & KVG_KHR_EGL_image || extensionName.Compare(KVgKhrEglImage)==0)
  1706 		{
  1707 		TBool bFoundExtensionVG_KHR_EGL_image = FindExtensionStringL(EIsVG,KVgKhrEglImage);
  1708 		if (!bFoundExtensionVG_KHR_EGL_image)
  1709 			{
  1710 			// The extension is not supported
  1711 			return EFalse;
  1712 			}
  1713 		}
  1714 	if(aExtension & KEGL_KHR_reusable_sync || extensionName.Compare(KEglKhrReusableSync)==0)
  1715 		{
  1716 		TBool bFoundExtensionEGL_KHR_reusable_sync = FindExtensionStringL(EIsEGL,KEglKhrReusableSync);
  1717 		if (!bFoundExtensionEGL_KHR_reusable_sync)
  1718 			{
  1719 			// The extension is not supported
  1720 			return EFalse;
  1721 			}
  1722 		}
  1723     if(aExtension & KEGL_NOK__private__signal_sync || extensionName.Compare(KEglNokPrivateSignalSync)==0)
  1724         {
  1725         TBool bFoundExtensionEGL_NOK__private__signal_sync = FindExtensionStringL(EIsEGL,KEglNokPrivateSignalSync);
  1726         if (!bFoundExtensionEGL_NOK__private__signal_sync)
  1727             {
  1728             // The extension is not supported
  1729             return EFalse;
  1730             }
  1731         }
  1732     if(aExtension & KEGL_NOKIA_swap_buffers || extensionName.Compare(KEglNokiaSwapBuffers)==0)
  1733         {
  1734         TBool bFoundExtensionEGL_NOKIA_swap_buffer = FindExtensionStringL(EIsEGL,KEglNokiaSwapBuffers);
  1735         if (!bFoundExtensionEGL_NOKIA_swap_buffer)
  1736             {
  1737             // The extension is not supported
  1738             return EFalse;
  1739             }
  1740         }
  1741 #ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
  1742     if(aExtension & KEGL_SYMBIAN_image_preserved || extensionName.Compare(KEglSymbianImagePreserved)
  1743         {
  1744         TBool bFoundExtensionEGL_SYMBIAN_image_preserved = FindExtensionStringL(EIsEGL,KEglSymbianImagePreserved);
  1745         if (!bFoundExtensionEGL_SYMBIAN_image_preserved)
  1746             {
  1747             // The extension is not supported
  1748             return EFalse;
  1749             }
  1750         }
  1751 #endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
  1752     if(aExtension & KEGL_NOK_image_endpoint || extensionName.Compare(KEglNokiaImageEndpoint)==0)
  1753         {
  1754         TBool bFoundExtensionEGL_NOK_image_endpoint = FindExtensionStringL(EIsEGL,KEglNokiaImageEndpoint);
  1755         if (!bFoundExtensionEGL_NOK_image_endpoint)
  1756             {
  1757             // The extension is not supported
  1758             return EFalse;
  1759             }
  1760         }
  1761     if(aExtension & KEGL_NOK_surface_scaling || extensionName.Compare(KEglNokiaSurfaceScaling)==0)
  1762         {
  1763         TBool bFoundExtensionEGL_NOK_surface_scaling = FindExtensionStringL(EIsEGL,KEglNokiaSurfaceScaling);
  1764         if (!bFoundExtensionEGL_NOK_surface_scaling)
  1765             {
  1766             // The extension is not supported
  1767             return EFalse;
  1768             }
  1769         }
  1770 	return ETrue;
  1771 	}
  1772 
  1773 EXPORT_C CFbsBitmap* CTestEglSession::CreateReferenceBitmapL(TDisplayMode aMode)
  1774 	{
  1775 	if(aMode == ENone )
  1776 		{
  1777 		ERR_PRINTF1(_L("Queried Reference Bitmap dispaly mode equal to ENone"));
  1778 		User::Leave(KErrTEFUnitFail);
  1779 		}
  1780 	return CreateReferenceBitmapL(aMode,KRgbGreenish);
  1781 	}
  1782 
  1783 EXPORT_C CFbsBitmap* CTestEglSession::CreateReferenceBitmapL(TDisplayMode aMode,const TRgb& aColour)
  1784 	{
  1785 	OpenFbsSessionL();
  1786 	CFbsBitmap* bitmap = new(ELeave) CFbsBitmap();
  1787 	CleanupStack::PushL(bitmap);
  1788 	if(bitmap->Create(KPixmapSize,aMode) != KErrNone)
  1789 		{
  1790 		return NULL;
  1791 		}
  1792 	CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL(bitmap);
  1793 	CleanupStack::PushL(bitmapDevice);
  1794 	CFbsBitGc* fbsBitGc = CFbsBitGc::NewL();
  1795 	CleanupStack::PushL(fbsBitGc);
  1796 	fbsBitGc->Activate(bitmapDevice);
  1797 	fbsBitGc->SetBrushColor(aColour);
  1798 	fbsBitGc->Clear();
  1799 	CleanupStack::PopAndDestroy(2,bitmapDevice);
  1800 	CleanupStack::Pop(bitmap);
  1801 	return bitmap;
  1802 	}
  1803 
  1804 EXPORT_C CFbsBitmap* CTestEglSession::CreateReferenceMaskedBitmapL(TDisplayMode aRefBitmapMode, const TRgb& aPenBitmapColor, const CFbsBitmap* aMaskBitmap)
  1805 	{
  1806 	OpenFbsSessionL();
  1807 
  1808 	// create the refBitmat (same size as the mask bitmap)
  1809 	// Note that we clear it to 'opaque black' as we assume the target surface has been cleared to 'opaque black' too
  1810 	// If either the surface or the refBitmap are cleared to another colour, update the other accordingly
  1811 	CFbsBitmap* refBitmap = new(ELeave) CFbsBitmap();
  1812 	CleanupStack::PushL(refBitmap);
  1813 	User::LeaveIfError(refBitmap->Create(aMaskBitmap->SizeInPixels(), aRefBitmapMode));
  1814 	CFbsBitmapDevice* bitmapDevice = CFbsBitmapDevice::NewL(refBitmap);
  1815 	CleanupStack::PushL(bitmapDevice);
  1816 	CFbsBitGc* fbsBitGc = CFbsBitGc::NewL();
  1817 	CleanupStack::PushL(fbsBitGc);
  1818 	fbsBitGc->Activate(bitmapDevice);
  1819 	fbsBitGc->SetBrushColor(KRgbBlack);
  1820 	fbsBitGc->Clear();
  1821 
  1822 	// create the penBitmap (same size as the mask bitmap)
  1823 	CFbsBitmap* penBitmap = new(ELeave) CFbsBitmap();
  1824 	CleanupStack::PushL(penBitmap);
  1825 	User::LeaveIfError(penBitmap->Create(aMaskBitmap->SizeInPixels(), aRefBitmapMode));
  1826 	CFbsBitmapDevice* penbitmapDevice = CFbsBitmapDevice::NewL(penBitmap);
  1827 	CleanupStack::PushL(penbitmapDevice);
  1828 	CFbsBitGc* penBitGc = CFbsBitGc::NewL();
  1829 	CleanupStack::PushL(penBitGc);
  1830 	penBitGc->Activate(penbitmapDevice);
  1831 	penBitGc->SetBrushColor(aPenBitmapColor);
  1832 	penBitGc->Clear();
  1833 
  1834 	// perform a masked bitmap transfer to the active refBitmap
  1835 	TRect bmpRect(TPoint(0, 0), refBitmap->SizeInPixels());
  1836 	fbsBitGc->Activate(bitmapDevice);
  1837 	fbsBitGc->BitBltMasked(TPoint(0, 0), penBitmap, bmpRect, aMaskBitmap, EFalse);
  1838 
  1839 	CleanupStack::PopAndDestroy(5, bitmapDevice);
  1840 	CleanupStack::Pop(refBitmap);
  1841 	return refBitmap;
  1842 	}
  1843 
  1844 
  1845 EXPORT_C CFbsBitmap* CTestEglSession::CreateReferenceBitmapL(TDisplayMode aMode, const TSize &aSize, const TInt aIndex)
  1846 	{
  1847 	OpenFbsSessionL();
  1848 	CFbsBitmap* bitmap = new(ELeave) CFbsBitmap();
  1849 	CleanupStack::PushL(bitmap);
  1850 	User::LeaveIfError(bitmap->Create(aSize,aMode));
  1851 
  1852 	TInt height = bitmap->SizeInPixels().iHeight;
  1853 	TInt width  = bitmap->SizeInPixels().iWidth;
  1854 
  1855 	// Initialise colour values to a random value (guarantees pixel uniqueness if update is done accordingly)
  1856 	TInt red=0;
  1857 	TInt green=127;
  1858 	TInt blue=127;
  1859 	TInt alpha=255;
  1860 
  1861 	TBitmapUtil bmpUtil(bitmap);
  1862 	bmpUtil.Begin(TPoint(0,0));
  1863 	for (TInt colIndex = 0; colIndex < width; ++colIndex)
  1864 		{
  1865 		bmpUtil.SetPos(TPoint(colIndex, 0));
  1866 		for (TInt rowIndex =0; rowIndex < height; ++rowIndex)
  1867 			{
  1868 			TRgb rgb(red, green, blue, alpha);
  1869 			switch(bitmap->DisplayMode())
  1870 				{
  1871 				case EColor64K:
  1872 					{
  1873 					bmpUtil.SetPixel(rgb.Color64K());
  1874 					break;
  1875 					}
  1876 				case EColor16MU:
  1877 					{
  1878 					bmpUtil.SetPixel(rgb.Color16MU());
  1879 					break;
  1880 					}
  1881 				case EColor16MA:
  1882 					{
  1883 					bmpUtil.SetPixel(rgb.Color16MA());
  1884 					break;
  1885 					}
  1886 				case EColor16MAP:
  1887 					{
  1888 					bmpUtil.SetPixel(rgb.Color16MAP());
  1889 					break;
  1890 					}
  1891 				case EGray256:
  1892 					{
  1893 					bmpUtil.SetPixel(rgb.Gray256());
  1894 					break;
  1895 					}
  1896 				default:
  1897 					{
  1898 					// We should not get here - colour mode not supported by these tests
  1899 					ERR_PRINTF1(_L("CTestEglSession::CreateReferenceBitmapL - Colour mode not supported!"));
  1900 				    ASSERT(FALSE);
  1901 					}
  1902 				}
  1903 			bmpUtil.IncYPos();
  1904 
  1905 			// Update red bit
  1906 			red = ++red + aIndex;
  1907 			if (red>255)
  1908 				red = red - 256;
  1909 
  1910 			// Update green bit
  1911 			green = --green - aIndex;
  1912 			if (green<0)
  1913 				green = green + 256;
  1914 
  1915 			// Update blue bit
  1916 			blue = ++blue + aIndex;
  1917 			if (blue>255)
  1918 				blue = blue - 256;
  1919 
  1920 			// Update alpha bit
  1921 			alpha = --alpha - aIndex;
  1922 			if (alpha<0)
  1923 				alpha = alpha + 256;
  1924 			}
  1925 		}
  1926 	bmpUtil.End();
  1927 	CleanupStack::Pop(bitmap);
  1928 	return bitmap;
  1929 	}
  1930 
  1931 EXPORT_C void CTestEglSession::CheckVgDrawingL(VGImageFormat aDataFormat, const CFbsBitmap* aReferenceBitmap)
  1932 	{
  1933 	TRgb refPixel;
  1934 	TInt height = aReferenceBitmap->SizeInPixels().iHeight;
  1935 	TInt width  = aReferenceBitmap->SizeInPixels().iWidth;
  1936 
  1937 	switch(aDataFormat)
  1938 		{
  1939 		case VG_sRGB_565:
  1940 			{
  1941 			TUint16* vgPixel = new(ELeave) TUint16[width];
  1942 			CleanupArrayDeletePushL(vgPixel);
  1943 			for (TInt y=0; y < height; y++)
  1944 				{
  1945                 // Mind the fact that CFbsBitmap and VGImages use different coordinates origin!
  1946                 vgReadPixels(vgPixel, 1, aDataFormat, 0,height-y-1, width,1);
  1947 
  1948 				for (TInt x=0; x < width; x++)
  1949 					{
  1950 					aReferenceBitmap->GetPixel(refPixel, TPoint(x,y));
  1951 					if(!PixelsMatch(refPixel, TRgb::Color64K(vgPixel[x]), EFalse))
  1952 						{
  1953 						User::Leave(KErrTEFUnitFail);
  1954 						}
  1955 					}
  1956 				}
  1957 			CleanupStack::PopAndDestroy(vgPixel);
  1958 			break;
  1959 			}
  1960 
  1961 		case VG_sXRGB_8888:
  1962 			{
  1963 			TUint32* vgPixel = new(ELeave) TUint32[width];
  1964 			CleanupArrayDeletePushL(vgPixel);
  1965 			for (TInt y=0; y < height; y++)
  1966 				{
  1967                 // Mind the fact that CFbsBitmap and VGImages use different coordinates origin!
  1968                 vgReadPixels(vgPixel, 1, aDataFormat, 0,height-y-1, width,1);
  1969 
  1970 				for (TInt x=0; x < width; x++)
  1971 					{
  1972 					aReferenceBitmap->GetPixel(refPixel, TPoint(x,y));
  1973 					if(!PixelsMatch(refPixel, TRgb::Color16MU(vgPixel[x]), EFalse))
  1974 						{
  1975 						User::Leave(KErrTEFUnitFail);
  1976 						}
  1977 					}
  1978 				}
  1979 			CleanupStack::PopAndDestroy(vgPixel);
  1980 			break;
  1981 			}
  1982 
  1983 		case VG_sARGB_8888:
  1984 			{
  1985 			TUint32* vgPixel = new(ELeave) TUint32[width];
  1986 			CleanupArrayDeletePushL(vgPixel);
  1987 			for (TInt y=0; y < height; y++)
  1988 				{
  1989                 // Mind the fact that CFbsBitmap and VGImages use different coordinates origin!
  1990                 vgReadPixels(vgPixel, 1, aDataFormat, 0,height-y-1, width,1);
  1991 
  1992 				for (TInt x=0; x < width; x++)
  1993 					{
  1994 					aReferenceBitmap->GetPixel(refPixel, TPoint(x,y));
  1995 					if(!PixelsMatch(refPixel, TRgb::Color16MA(vgPixel[x]), ETrue))
  1996 						{
  1997 						User::Leave(KErrTEFUnitFail);
  1998 						}
  1999 					}
  2000 				}
  2001 			CleanupStack::PopAndDestroy(vgPixel);
  2002 			break;
  2003 			}
  2004 
  2005 		case VG_sARGB_8888_PRE:
  2006 			{
  2007 			TUint32* vgPixel = new(ELeave) TUint32[width];
  2008 			CleanupArrayDeletePushL(vgPixel);
  2009 			for (TInt y=0; y < height; y++)
  2010 				{
  2011                 // Mind the fact that CFbsBitmap and VGImages use different coordinates origin!
  2012                 vgReadPixels(vgPixel, 1, aDataFormat, 0,height-y-1, width,1);
  2013 
  2014 				for (TInt x=0; x < width; x++)
  2015 					{
  2016 					aReferenceBitmap->GetPixel(refPixel, TPoint(x,y));
  2017 					if(!PixelsMatch(refPixel, TRgb::Color16MAP(vgPixel[x]), ETrue))
  2018 						{
  2019 						User::Leave(KErrTEFUnitFail);
  2020 						}
  2021 					}
  2022 				}
  2023 			CleanupStack::PopAndDestroy(vgPixel);
  2024 			break;
  2025 			}
  2026 
  2027 		default:
  2028 			// We should not get here - colour mode not supported by these tests
  2029 			ERR_PRINTF1(_L("CTestEglSession::CheckVgDrawingL - Colour mode not supported!"));
  2030 		    ASSERT(FALSE);
  2031 			break;
  2032 		}
  2033 	}
  2034 
  2035 EXPORT_C TBool CTestEglSession::IsOpenGLESSupported()
  2036     {
  2037     if(!iIsSupportedRenderInitialized)
  2038         {
  2039         CheckAllAvailableRenders();
  2040         }
  2041     return iIsOpenGLESSupported;
  2042     }
  2043 
  2044 EXPORT_C TBool CTestEglSession::IsOpenGLES2Supported()
  2045     {
  2046     if(!iIsSupportedRenderInitialized)
  2047         {
  2048         CheckAllAvailableRenders();
  2049         }
  2050     return iIsOpenGLES2Supported;
  2051     }
  2052 EXPORT_C TBool CTestEglSession::IsOpenVGSupported()
  2053     {
  2054     if(!iIsSupportedRenderInitialized)
  2055         {
  2056         CheckAllAvailableRenders();
  2057         }
  2058     return iIsOpenVGSupported;
  2059     }
  2060 
  2061 void CTestEglSession::CheckAllAvailableRenders()
  2062     {
  2063     ASSERT_EGL_TRUE(iDisplay != EGL_NO_DISPLAY);
  2064     TPtrC8 ptrEglClientApis((const TText8 *)eglQueryString(iDisplay, EGL_CLIENT_APIS));
  2065     _LIT8(KOpenGLES, "OpenGL_ES");
  2066     EGLint numConfigs= 0;
  2067     EGLConfig config;
  2068     if(ptrEglClientApis.Find(KOpenGLES) != KErrNotFound)
  2069         {
  2070         //check GLES2
  2071         const EGLint KAttrib_list_gles2[] = { EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
  2072                                               EGL_NONE };
  2073         EGLBoolean eglRes = eglChooseConfig(iDisplay, KAttrib_list_gles2, &config,1, &numConfigs);
  2074         ASSERT_EGL_TRUE(eglRes == EGL_TRUE);
  2075         if(numConfigs > 0)
  2076             {
  2077             iIsOpenGLES2Supported = ETrue;
  2078             }
  2079         //check GLES
  2080         numConfigs = 0;
  2081         const EGLint KAttrib_list_gles[] = { EGL_RENDERABLE_TYPE, EGL_OPENGL_ES_BIT,
  2082                                              EGL_NONE };
  2083         eglRes = eglChooseConfig(iDisplay, KAttrib_list_gles, &config,1, &numConfigs);
  2084         ASSERT_EGL_TRUE(eglRes == EGL_TRUE);
  2085         if(numConfigs > 0)
  2086             {
  2087             iIsOpenGLESSupported = ETrue;
  2088             }
  2089         }
  2090     _LIT8(KOpenVG, "OpenVG");
  2091     if(ptrEglClientApis.Find(KOpenVG) != KErrNotFound)
  2092         {
  2093         numConfigs= 0;
  2094         //check VG
  2095         const EGLint KAttrib_list_vg[] = { EGL_RENDERABLE_TYPE, EGL_OPENVG_BIT,
  2096                                            EGL_NONE };
  2097         EGLBoolean eglRes = eglChooseConfig(iDisplay, KAttrib_list_vg, &config,1, &numConfigs);
  2098         ASSERT_EGL_TRUE(eglRes == EGL_TRUE);
  2099         if(numConfigs > 0)
  2100             {
  2101             iIsOpenVGSupported = ETrue;
  2102             }
  2103         }
  2104     iIsSupportedRenderInitialized = ETrue;
  2105     }
  2106 
  2107