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