egl/egltest/src/egltestcommonsession.cpp
branchRCL_3
changeset 26 15986eb6c500
parent 18 5e30ef2e26cb
child 163 bbf46f59e123
equal deleted inserted replaced
19:ac96196b945c 26:15986eb6c500
    13 // Description:
    13 // Description:
    14 //
    14 //
    15 
    15 
    16 /**
    16 /**
    17  @file
    17  @file
    18  @test 
    18  @test
    19 */
    19 */
    20 
    20 
    21 #include "egltestcommonsession.h"
    21 #include "egltestcommonsession.h"
    22 #include "egltestcommonutils.h"
    22 #include "egltestcommonutils.h"
    23 #include "egltestcommonsgimageinfo.h"
    23 #include "egltestcommonsgimageinfo.h"
    80             ret = eglMakeCurrent(iDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
    80             ret = eglMakeCurrent(iDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
    81             if(ret == EGL_FALSE)
    81             if(ret == EGL_FALSE)
    82                 {
    82                 {
    83                 WARN_PRINTF3(_L("thread %d: eglMakeCurrent returned error = %x ~CTestEglSession..."), iThreadIdx, eglGetError());
    83                 WARN_PRINTF3(_L("thread %d: eglMakeCurrent returned error = %x ~CTestEglSession..."), iThreadIdx, eglGetError());
    84                 }
    84                 }
    85             
    85 
    86             // Warn because this should be done by the test, rather than relying on the d'tor
    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)
    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);
    88             WARN_PRINTF2(_L("thread %d: Calling eglDestroyContext() from ~CTestEglSession..."), iThreadIdx);
    89             ret = eglDestroyContext(iDisplay, iContext);
    89             ret = eglDestroyContext(iDisplay, iContext);
    90             if(ret == EGL_FALSE)
    90             if(ret == EGL_FALSE)
    91                 {
    91                 {
    92                 WARN_PRINTF3(_L("thread %d: eglDestroyContext returned error = %x ~CTestEglSession..."), iThreadIdx, eglGetError());
    92                 WARN_PRINTF3(_L("thread %d: eglDestroyContext returned error = %x ~CTestEglSession..."), iThreadIdx, eglGetError());
    93                 }   
    93                 }
    94 		    }
    94 		    }
    95 
    95 
    96 		if (iSurface != EGL_NO_SURFACE)
    96 		if (iSurface != EGL_NO_SURFACE)
    97 			{
    97 			{
    98 			// Warn because this should be done by the test, rather than relying on the d'tor
    98 			// Warn because this should be done by the test, rather than relying on the d'tor
   100 			WARN_PRINTF2(_L("thread %d: Calling eglDestroySurface() from ~CTestEglSession..."), iThreadIdx);
   100 			WARN_PRINTF2(_L("thread %d: Calling eglDestroySurface() from ~CTestEglSession..."), iThreadIdx);
   101 			ret = eglDestroySurface(iDisplay, iSurface);
   101 			ret = eglDestroySurface(iDisplay, iSurface);
   102 			if(ret == EGL_FALSE)
   102 			if(ret == EGL_FALSE)
   103 				{
   103 				{
   104 				WARN_PRINTF3(_L("thread %d: eglDestroySurface returned error = %x ~CTestEglSession..."), iThreadIdx, eglGetError());
   104 				WARN_PRINTF3(_L("thread %d: eglDestroySurface returned error = %x ~CTestEglSession..."), iThreadIdx, eglGetError());
   105 				}	
   105 				}
   106 			}
   106 			}
   107 		
   107 
   108 		if (iTerminateDisplay)
   108 		if (iTerminateDisplay)
   109 			{
   109 			{
   110 			INFO_PRINTF1(_L("Calling eglTerminate..."));
   110 			INFO_PRINTF1(_L("Calling eglTerminate..."));
   111 			ret = eglTerminate(iDisplay);
   111 			ret = eglTerminate(iDisplay);
   112 			iDisplay = EGL_NO_DISPLAY;
   112 			iDisplay = EGL_NO_DISPLAY;
   113 			if(ret == EGL_FALSE)
   113 			if(ret == EGL_FALSE)
   114 				{
   114 				{
   115 				WARN_PRINTF3(_L("thread %d: eglTerminate returned error = %x ~CTestEglSession..."), iThreadIdx, eglGetError());
   115 				WARN_PRINTF3(_L("thread %d: eglTerminate returned error = %x ~CTestEglSession..."), iThreadIdx, eglGetError());
   116 				}	
   116 				}
   117 			}
   117 			}
   118 		}
   118 		}
   119 
   119 
   120 	// Only destroy native resource after the surface and context that wraps it has been destroyed.
   120 	// Only destroy native resource after the surface and context that wraps it has been destroyed.
   121 	delete iFbsBitmap;
   121 	delete iFbsBitmap;
   122 	CloseFbsSession();
   122 	CloseFbsSession();
   123 	
   123 
   124 	iSgImage.Close();
   124 	iSgImage.Close();
   125 	CloseSgDriver();
   125 	CloseSgDriver();
   126 	}
   126 	}
   127 
   127 
   128 EXPORT_C void CTestEglSession::SetExpectedError(EGLint aExpectedErrorCode)
   128 EXPORT_C void CTestEglSession::SetExpectedError(EGLint aExpectedErrorCode)
   129 	{
   129 	{
   130 	VERBOSE_INFO_PRINTF3(_L("thread %d: Setting the expected error code for the next EGL call to %x"), iThreadIdx, aExpectedErrorCode);
   130 	VERBOSE_INFO_PRINTF3(_L("thread %d: Setting the expected error code for the next EGL call to %x"), iThreadIdx, aExpectedErrorCode);
   131 		{
   131 		{
   132 		iExpectedErrorCode = aExpectedErrorCode; 
   132 		iExpectedErrorCode = aExpectedErrorCode;
   133 		}
   133 		}
   134 	}
   134 	}
   135 
   135 
   136 EXPORT_C void CTestEglSession::ResetExpectedError()
   136 EXPORT_C void CTestEglSession::ResetExpectedError()
   137 	{
   137 	{
   147 */
   147 */
   148 EXPORT_C TBool CTestEglSession::CheckExpectedError(EGLint aFunctionReturnValue)
   148 EXPORT_C TBool CTestEglSession::CheckExpectedError(EGLint aFunctionReturnValue)
   149 	{
   149 	{
   150 	TBool isExpectedError = ETrue;
   150 	TBool isExpectedError = ETrue;
   151 	EGLint eglErr = eglGetError();
   151 	EGLint eglErr = eglGetError();
   152 	
   152 
   153 	// First check that we got the correct return value
   153 	// First check that we got the correct return value
   154 	if ((iExpectedErrorCode == EGL_SUCCESS) && !aFunctionReturnValue)
   154 	if ((iExpectedErrorCode == EGL_SUCCESS) && !aFunctionReturnValue)
   155 		{
   155 		{
   156 		ERR_PRINTF3(_L("thread %d: Wrong function return value: %d"), iThreadIdx, aFunctionReturnValue);
   156 		ERR_PRINTF3(_L("thread %d: Wrong function return value: %d"), iThreadIdx, aFunctionReturnValue);
   157 		isExpectedError = EFalse;
   157 		isExpectedError = EFalse;
   158 		}
   158 		}
   159 	// Also check that we got the 
   159 	// Also check that we got the
   160 	if (eglErr != iExpectedErrorCode) 
   160 	if (eglErr != iExpectedErrorCode)
   161 		{
   161 		{
   162 		ERR_PRINTF4(_L("thread %d: eglGetError() returned %x, but expected %x"), iThreadIdx, eglErr, iExpectedErrorCode);
   162 		ERR_PRINTF4(_L("thread %d: eglGetError() returned %x, but expected %x"), iThreadIdx, eglErr, iExpectedErrorCode);
   163 		isExpectedError = EFalse;
   163 		isExpectedError = EFalse;
   164 		}
   164 		}
   165 	else if (eglErr != EGL_SUCCESS)
   165 	else if (eglErr != EGL_SUCCESS)
   166 		{
   166 		{
   167 		VERBOSE_INFO_PRINTF3(_L("thread %d: eglGetError() returned %x, as expected"), iThreadIdx, eglErr);
   167 		VERBOSE_INFO_PRINTF3(_L("thread %d: eglGetError() returned %x, as expected"), iThreadIdx, eglErr);
   168 		}
   168 		}
   169 	
   169 
   170 	// Reset the expected error
   170 	// Reset the expected error
   171 	ResetExpectedError();
   171 	ResetExpectedError();
   172 	
   172 
   173 	return isExpectedError;
   173 	return isExpectedError;
   174 	}
   174 	}
   175 
   175 
   176 EXPORT_C void CTestEglSession::CheckExpectedErrorL(EGLint aExpectedErrorCode)
   176 EXPORT_C void CTestEglSession::CheckExpectedErrorL(EGLint aExpectedErrorCode)
   177 	{
   177 	{
   178 	EGLint eglErr = eglGetError();	
   178 	EGLint eglErr = eglGetError();
   179 	// check that we got the expected error
   179 	// check that we got the expected error
   180 	if (eglErr != aExpectedErrorCode) 
   180 	if (eglErr != aExpectedErrorCode)
   181 		{
   181 		{
   182 		ERR_PRINTF4(_L("thread %d: eglGetError() returned %x, but expected %x"), iThreadIdx, eglErr, aExpectedErrorCode);
   182 		ERR_PRINTF4(_L("thread %d: eglGetError() returned %x, but expected %x"), iThreadIdx, eglErr, aExpectedErrorCode);
   183 		User::Leave(KErrTEFUnitFail);
   183 		User::Leave(KErrTEFUnitFail);
   184 		}
   184 		}
   185 	}
   185 	}
   186 
   186 
   187 void CTestEglSession::QueryExtensionsL(TExtensionsGroups aExtensionBelongsTo)
   187 void CTestEglSession::QueryExtensionsL(TExtensionsGroups aExtensionBelongsTo)
   188 	{
   188 	{
   189 	// reset the cached extensions
   189 	// reset the cached extensions
   190 	iExtensionStrings.Reset();
   190 	iExtensionStrings.Reset();
   191 	
   191 
   192 	const char* extensionsString = NULL;
   192 	const char* extensionsString = NULL;
   193 	if(aExtensionBelongsTo == EIsEGL)
   193 	if(aExtensionBelongsTo == EIsEGL)
   194 		{
   194 		{
   195 		INFO_PRINTF2(_L("thread %d: Calling eglQueryString for EGL_EXTENSIONS)"), iThreadIdx);
   195 		INFO_PRINTF2(_L("thread %d: Calling eglQueryString for EGL_EXTENSIONS)"), iThreadIdx);
   196 		extensionsString = eglQueryString(iDisplay, EGL_EXTENSIONS);
   196 		extensionsString = eglQueryString(iDisplay, EGL_EXTENSIONS);
   197 		}
   197 		}
   198 	else if(aExtensionBelongsTo == EIsVG)
   198 	else if(aExtensionBelongsTo == EIsVG)
   199 		{	
   199 		{
   200 		INFO_PRINTF2(_L("thread %d: Calling vgGetString for VG_EXTENSIONS)"), iThreadIdx);
   200 		INFO_PRINTF2(_L("thread %d: Calling vgGetString for VG_EXTENSIONS)"), iThreadIdx);
   201 
   201 
   202 		// OpenVG needs a current VG context before it will allow the call to vgGetString
   202 		// OpenVG needs a current VG context before it will allow the call to vgGetString
       
   203 		// The created surface will remain un-used, hence we create it with an arbitrary pixel format 
   203         EGLConfig currentConfig = GetConfigExactMatchL(EPBufferAttribsColor64K);
   204         EGLConfig currentConfig = GetConfigExactMatchL(EPBufferAttribsColor64K);
   204         CreatePbufferSurfaceAndMakeCurrentL(currentConfig, TSize(1,1), EGL_OPENVG_API);
   205         CreatePbufferSurfaceAndMakeCurrentL(currentConfig, TSize(1,1), EGL_OPENVG_API);
   205 
   206 
   206 		extensionsString = (const char*) vgGetString(VG_EXTENSIONS);
   207 		extensionsString = (const char*) vgGetString(VG_EXTENSIONS);
   207 
   208 
   211 	else
   212 	else
   212 		{
   213 		{
   213 		ERR_PRINTF2(_L("CTestEglSession::QueryExtensionsL() - Unknown extension group provided (%d)."), aExtensionBelongsTo);
   214 		ERR_PRINTF2(_L("CTestEglSession::QueryExtensionsL() - Unknown extension group provided (%d)."), aExtensionBelongsTo);
   214 		User::Leave(KErrArgument);
   215 		User::Leave(KErrArgument);
   215 		}
   216 		}
   216 	CHECK_EXPECTED_ERROR(extensionsString!=NULL);	
   217 	CHECK_EXPECTED_ERROR(extensionsString!=NULL);
   217 	
   218 
   218 	TPtrC8 ptrExtensions((const TUint8 *) extensionsString );
   219 	TPtrC8 ptrExtensions((const TUint8 *) extensionsString );
   219 	TBuf16<128> bufExtensions;
   220 
   220 	bufExtensions.Copy(ptrExtensions.Left(128));
   221 	RBuf buffer;
   221 	INFO_PRINTF3(_L("thread %d: QueryExtensionsL: \"%S\""), iThreadIdx, &bufExtensions);
   222     buffer.CreateL(ptrExtensions.Length());
   222 	
   223     buffer.CleanupClosePushL();
       
   224     buffer.Copy(ptrExtensions);
       
   225 	INFO_PRINTF3(_L("thread %d: QueryExtensionsL: \"%S\""), iThreadIdx, &buffer);
       
   226     CleanupStack::PopAndDestroy(&buffer);
       
   227 
   223 	TInt posSpace=1;
   228 	TInt posSpace=1;
   224 	while (posSpace > 0 && ptrExtensions.Length() > 0)
   229 	while (posSpace > 0 && ptrExtensions.Length() > 0)
   225 		{
   230 		{
   226 		posSpace = ptrExtensions.Locate(' '); // strictly looking for a single space
   231 		posSpace = ptrExtensions.Locate(' '); // strictly looking for a single space
   227 		ASSERT_FALSE(posSpace==0); // Would imply extension starting with a space or with 2 spaces in a row
   232 		ASSERT_FALSE(posSpace==0); // Would imply extension starting with a space or with 2 spaces in a row
   235 			}
   240 			}
   236 		else
   241 		else
   237 			{
   242 			{
   238 			iExtensionStrings.Append(ptrExtensions);
   243 			iExtensionStrings.Append(ptrExtensions);
   239 			}
   244 			}
   240 		} 
   245 		}
   241 	}
   246 	}
   242 
   247 
   243 TBool CTestEglSession::FindExtensionStringL(TExtensionsGroups aExtensionBelongsTo, const TDesC8& aExtensionString)
   248 TBool CTestEglSession::FindExtensionStringL(TExtensionsGroups aExtensionBelongsTo, const TDesC8& aExtensionString)
   244 	{
   249 	{
   245 	//Load the extensions for this group if not already cached
   250 	//Load the extensions for this group if not already cached
   246 	if (iExtensionGroupCached != aExtensionBelongsTo)
   251 	if (iExtensionGroupCached != aExtensionBelongsTo)
   247 		{
   252 		{
   248 		QueryExtensionsL(aExtensionBelongsTo); // Load extension info
   253 		QueryExtensionsL(aExtensionBelongsTo); // Load extension info
   249 		iExtensionGroupCached = aExtensionBelongsTo;
   254 		iExtensionGroupCached = aExtensionBelongsTo;
   250 		}
   255 		}
   251 	
   256 
   252 	TInt countExtensionStrings = iExtensionStrings.Count();
   257 	TInt countExtensionStrings = iExtensionStrings.Count();
   253 	for(TUint i=0; i<countExtensionStrings; i++)
   258 	for(TUint i=0; i<countExtensionStrings; i++)
   254 		{
   259 		{
   255 		if (iExtensionStrings[i].Compare(aExtensionString)==0)
   260 		if (iExtensionStrings[i].Compare(aExtensionString)==0)
   256 			{
   261 			{
   261 
   266 
   262 	// No match: copy the extension string into a 16 bit buffer for logging
   267 	// No match: copy the extension string into a 16 bit buffer for logging
   263 	const TInt KBufLenMissingExtension=128;
   268 	const TInt KBufLenMissingExtension=128;
   264 	TBuf16<KBufLenMissingExtension> bufMissingExtension16;
   269 	TBuf16<KBufLenMissingExtension> bufMissingExtension16;
   265 	bufMissingExtension16.Copy(aExtensionString.Left(KBufLenMissingExtension));
   270 	bufMissingExtension16.Copy(aExtensionString.Left(KBufLenMissingExtension));
   266 	
   271 
   267 	WARN_PRINTF2(_L("EGL extension missing: [%S]"), &bufMissingExtension16);
   272 	WARN_PRINTF2(_L("EGL extension missing: [%S]"), &bufMissingExtension16);
   268 	return EFalse;
   273 	return EFalse;
   269 	}
   274 	}
   270 
   275 
   271 /**
   276 /**
   291 	CHECK_EXPECTED_ERROR(eglGetConfigs(iDisplay, NULL, KMaxTInt, &numConfigs));
   296 	CHECK_EXPECTED_ERROR(eglGetConfigs(iDisplay, NULL, KMaxTInt, &numConfigs));
   292 
   297 
   293 	INFO_PRINTF1(_L("Checking number of configs..."));
   298 	INFO_PRINTF1(_L("Checking number of configs..."));
   294 	ASSERT_TRUE(numConfigs >= 1);
   299 	ASSERT_TRUE(numConfigs >= 1);
   295 	INFO_PRINTF2(_L("Found %d configs"), numConfigs);
   300 	INFO_PRINTF2(_L("Found %d configs"), numConfigs);
   296 	
   301 
   297 	// Get the configs
   302 	// Get the configs
   298 	INFO_PRINTF1(_L("Calling eglGetConfigs to get configs..."));
   303 	INFO_PRINTF1(_L("Calling eglGetConfigs to get configs..."));
   299 	CHECK_EXPECTED_ERROR(eglGetConfigs(iDisplay, configs, KMaxEglConfigs, &numConfigs));
   304 	CHECK_EXPECTED_ERROR(eglGetConfigs(iDisplay, configs, KMaxEglConfigs, &numConfigs));
   300 	
   305 
   301 	for(TUint index = 0; index < numConfigs; index++)
   306 	for(TUint index = 0; index < numConfigs; index++)
   302 		{
   307 		{
   303 		EGLint EGL_BUFFER_SIZE_value;
   308 		EGLint EGL_BUFFER_SIZE_value;
   304 		EGLint EGL_ALPHA_SIZE_value;
   309 		EGLint EGL_ALPHA_SIZE_value;
   305 		EGLint EGL_BLUE_SIZE_value;
   310 		EGLint EGL_BLUE_SIZE_value;
   372 #endif
   377 #endif
   373 		eglGetConfigAttrib(iDisplay, configs[index], EGL_RENDERABLE_TYPE, &EGL_RENDERABLE_TYPE_value);
   378 		eglGetConfigAttrib(iDisplay, configs[index], EGL_RENDERABLE_TYPE, &EGL_RENDERABLE_TYPE_value);
   374 
   379 
   375 		TBool good = ETrue;
   380 		TBool good = ETrue;
   376 
   381 
   377 		INFO_PRINTF7(_L("(idx: %3d) RGBA=(%2d) %2d,%2d,%2d,%2d"), index, EGL_BUFFER_SIZE_value, 
   382 		INFO_PRINTF7(_L("(idx: %3d) RGBA=(%2d) %2d,%2d,%2d,%2d"), index, EGL_BUFFER_SIZE_value,
   378 				EGL_RED_SIZE_value, EGL_GREEN_SIZE_value, EGL_BLUE_SIZE_value, 
   383 				EGL_RED_SIZE_value, EGL_GREEN_SIZE_value, EGL_BLUE_SIZE_value,
   379 				EGL_ALPHA_SIZE_value);
   384 				EGL_ALPHA_SIZE_value);
   380 		if (!(EGL_RED_SIZE_value == 8 && EGL_GREEN_SIZE_value == 8 && EGL_BLUE_SIZE_value == 8 && EGL_ALPHA_SIZE_value == 0))
   385 		if (!(EGL_RED_SIZE_value == 8 && EGL_GREEN_SIZE_value == 8 && EGL_BLUE_SIZE_value == 8 && EGL_ALPHA_SIZE_value == 0))
   381 			{
   386 			{
   382 			continue;
   387 			continue;
   383 			}
   388 			}
   384 		
   389 
   385 		INFO_PRINTF2(_L("\n\n^^^^^^ CONFIG [%d] VALUES ******"), index);
   390 		INFO_PRINTF2(_L("\n\n^^^^^^ CONFIG [%d] VALUES ******"), index);
   386 		if (EGL_SURFACE_TYPE_value & EGL_PIXMAP_BIT)
   391 		if (EGL_SURFACE_TYPE_value & EGL_PIXMAP_BIT)
   387 			{
   392 			{
   388 			INFO_PRINTF2(_L("EGL_SURFACE_TYPE=%d. <<< Has EGL_PIXMAP_BIT"), EGL_SURFACE_TYPE_value);
   393 			INFO_PRINTF2(_L("EGL_SURFACE_TYPE=%d. <<< Has EGL_PIXMAP_BIT"), EGL_SURFACE_TYPE_value);
   389 			}
   394 			}
   390 		else
   395 		else
   391 			{
   396 			{
   392 			INFO_PRINTF2(_L("EGL_SURFACE_TYPE=%d. <<< BAD (not pixmap)"), EGL_SURFACE_TYPE_value);
   397 			INFO_PRINTF2(_L("EGL_SURFACE_TYPE=%d. <<< BAD (not pixmap)"), EGL_SURFACE_TYPE_value);
   393 			good = EFalse;
   398 			good = EFalse;
   394 			}
   399 			}
   395 		
   400 
   396 		if (EGL_RENDERABLE_TYPE_value & EGL_OPENVG_BIT)
   401 		if (EGL_RENDERABLE_TYPE_value & EGL_OPENVG_BIT)
   397 			{
   402 			{
   398 			INFO_PRINTF2(_L("EGL_RENDERABLE_TYPE=%d. <<< Has EGL_OPENVG_BIT"), EGL_RENDERABLE_TYPE_value);
   403 			INFO_PRINTF2(_L("EGL_RENDERABLE_TYPE=%d. <<< Has EGL_OPENVG_BIT"), EGL_RENDERABLE_TYPE_value);
   399 			}
   404 			}
   400 		else
   405 		else
   401 			{
   406 			{
   402 			INFO_PRINTF2(_L("EGL_RENDERABLE_TYPE=%d. <<< BAD (not open vg)"), EGL_RENDERABLE_TYPE_value);
   407 			INFO_PRINTF2(_L("EGL_RENDERABLE_TYPE=%d. <<< BAD (not open vg)"), EGL_RENDERABLE_TYPE_value);
   403 			good = EFalse;
   408 			good = EFalse;
   404 			}
   409 			}
   405 		
   410 
   406 		if (good)
   411 		if (good)
   407 			{
   412 			{
   408 			INFO_PRINTF1(_L("^^^^^^^ GOOD ^^^^^^^"));
   413 			INFO_PRINTF1(_L("^^^^^^^ GOOD ^^^^^^^"));
   409 			}
   414 			}
   410 
   415 
   447 	}
   452 	}
   448 
   453 
   449 EXPORT_C static TEglConfigMatchType GetMatchType(EGLint aAttrib, TEglConfigMatchRule aMatchRule)
   454 EXPORT_C static TEglConfigMatchType GetMatchType(EGLint aAttrib, TEglConfigMatchRule aMatchRule)
   450 	{
   455 	{
   451 	const TConfigMatchRuleItem* curMatchRuleItem = KConfigMatchRules[aMatchRule];
   456 	const TConfigMatchRuleItem* curMatchRuleItem = KConfigMatchRules[aMatchRule];
   452 			
   457 
   453 	while(curMatchRuleItem->iAttrib != EGL_NONE)
   458 	while(curMatchRuleItem->iAttrib != EGL_NONE)
   454 		{
   459 		{
   455 		if (aAttrib == curMatchRuleItem->iAttrib)
   460 		if (aAttrib == curMatchRuleItem->iAttrib)
   456 			{
   461 			{
   457 			return curMatchRuleItem->iMatchType;
   462 			return curMatchRuleItem->iMatchType;
   464 	}
   469 	}
   465 
   470 
   466 /**
   471 /**
   467  Returns the first index of a config that matches the requested config extactly
   472  Returns the first index of a config that matches the requested config extactly
   468  */
   473  */
   469 TInt CTestEglSession::GetFullMatchConfigIndex(EGLDisplay aDisplay, EGLConfig *aConfigs, TInt aNumConfigs, 
   474 TInt CTestEglSession::GetFullMatchConfigIndex(EGLDisplay aDisplay, EGLConfig *aConfigs, TInt aNumConfigs,
   470 											  const EGLint aWantedAttribs[], TEglConfigMatchRule aMatchRule)
   475 											  const EGLint aWantedAttribs[], TEglConfigMatchRule aMatchRule)
   471 	{
   476 	{
   472 	EGLint value=0;
   477 	EGLint value=0;
   473 	for(TUint idxConfig=0; idxConfig<aNumConfigs; idxConfig++)
   478 	for(TUint idxConfig=0; idxConfig<aNumConfigs; idxConfig++)
   474 		{
   479 		{
   475 		const EGLint *curAttrib = aWantedAttribs;
   480 		const EGLint *curAttrib = aWantedAttribs;
   476 		TBool match = ETrue;
   481 		TBool match = ETrue;
   477 		
   482 
   478 		while(*curAttrib != EGL_NONE && match)
   483 		while(*curAttrib != EGL_NONE && match)
   479 			{
   484 			{
   480 			ASSERT_EGL_TRUE(eglGetConfigAttrib(aDisplay, aConfigs[idxConfig], *curAttrib, &value));
   485 			ASSERT_EGL_TRUE(eglGetConfigAttrib(aDisplay, aConfigs[idxConfig], *curAttrib, &value));
   481 
   486 
   482 			switch(GetMatchType(*curAttrib, aMatchRule))
   487 			switch(GetMatchType(*curAttrib, aMatchRule))
   483 				{
   488 				{
   484 				case eMatchEqual:
   489 				case eMatchEqual:
   485 					if (value != curAttrib[1])
   490 					if (value != curAttrib[1])
   486 						{
   491 						{
   487 						match = EFalse;
   492 						match = EFalse;
   488 						}		
   493 						}
   489 					break;
   494 					break;
   490 				case eMatchAtLeast:
   495 				case eMatchAtLeast:
   491 					if (value < curAttrib[1])   // Note, we detect "failure to match", hence "<" not ">="!
   496 					if (value < curAttrib[1])   // Note, we detect "failure to match", hence "<" not ">="!
   492 						{
   497 						{
   493 						match = EFalse;
   498 						match = EFalse;
   499 						match = EFalse;
   504 						match = EFalse;
   500 						}
   505 						}
   501 					break;
   506 					break;
   502 				case eMatchAlways:
   507 				case eMatchAlways:
   503 				    break;
   508 				    break;
   504 				    
   509 
   505 				default:
   510 				default:
   506 					// We should not get here.
   511 					// We should not get here.
   507 				    ASSERT(FALSE); 
   512 				    ASSERT(FALSE);
   508 				    break;
   513 				    break;
   509 				}
   514 				}
   510 			curAttrib += 2;
   515 			curAttrib += 2;
   511 			}
   516 			}
   512 		
   517 
   513 		// If we get here with match set, we have matched all attributes, and have found a match. 
   518 		// If we get here with match set, we have matched all attributes, and have found a match.
   514 		if (match) 
   519 		if (match)
   515 			{
   520 			{
   516 			return idxConfig;
   521 			return idxConfig;
   517 			}
   522 			}
   518 		}
   523 		}
   519 	return KErrNotFound;
   524 	return KErrNotFound;
   530 	}
   535 	}
   531 
   536 
   532 /**
   537 /**
   533  Returns pixel format inforamtion for a given EGL config.
   538  Returns pixel format inforamtion for a given EGL config.
   534  @param aConfig The EGL config for which pixel format information will be returned.
   539  @param aConfig The EGL config for which pixel format information will be returned.
   535  @return A pointer to the pixel format information for the given EGL config.  
   540  @return A pointer to the pixel format information for the given EGL config.
   536          Tf the config cannot be mapped, then NULL is returned.
   541          Tf the config cannot be mapped, then NULL is returned.
   537  */
   542  */
   538 EXPORT_C const TMapEglConfigToPixelFormat* CTestEglSession::GetPixelFormatFromEglConfigL(EGLConfig aConfig)
   543 EXPORT_C const TMapEglConfigToPixelFormat* CTestEglSession::GetPixelFormatFromEglConfigL(EGLConfig aConfig)
   539 	{
   544 	{
   540 	EGLint bufferSize=0;
   545 	EGLint bufferSize=0;
   552 	CHECK_EXPECTED_ERROR(eglGetConfigAttrib(iDisplay, aConfig, EGL_BLUE_SIZE, &blueSize));
   557 	CHECK_EXPECTED_ERROR(eglGetConfigAttrib(iDisplay, aConfig, EGL_BLUE_SIZE, &blueSize));
   553 	CHECK_EXPECTED_ERROR(eglGetConfigAttrib(iDisplay, aConfig, EGL_COLOR_BUFFER_TYPE, &colorBufferType));
   558 	CHECK_EXPECTED_ERROR(eglGetConfigAttrib(iDisplay, aConfig, EGL_COLOR_BUFFER_TYPE, &colorBufferType));
   554 	CHECK_EXPECTED_ERROR(eglGetConfigAttrib(iDisplay, aConfig, EGL_SURFACE_TYPE, &surfaceType));
   559 	CHECK_EXPECTED_ERROR(eglGetConfigAttrib(iDisplay, aConfig, EGL_SURFACE_TYPE, &surfaceType));
   555 
   560 
   556 	INFO_PRINTF7(_L(">>>>> Config info: %d, %d, %d,%d,%d, 0x%x"), bufferSize, alphaSize, redSize, greenSize, blueSize, colorBufferType);
   561 	INFO_PRINTF7(_L(">>>>> Config info: %d, %d, %d,%d,%d, 0x%x"), bufferSize, alphaSize, redSize, greenSize, blueSize, colorBufferType);
   557 	
   562 
   558 	for(TUint i=0; i<ConfigToPixelFormatTableLength(); i++)
   563 	for(TUint i=0; i<ConfigToPixelFormatTableLength(); i++)
   559 		{
   564 		{
   560 		if ((ConfigToPixelFormatTable(i).iBufferSize == bufferSize)
   565 		if ((ConfigToPixelFormatTable(i).iBufferSize == bufferSize)
   561 				&& (ConfigToPixelFormatTable(i).iAlphaSize == alphaSize)
   566 				&& (ConfigToPixelFormatTable(i).iAlphaSize == alphaSize)
   562 				&& (ConfigToPixelFormatTable(i).iRedSize == redSize)
   567 				&& (ConfigToPixelFormatTable(i).iRedSize == redSize)
   623 	if(aConfigAttribIndex >= EEglTestConfigMax )
   628 	if(aConfigAttribIndex >= EEglTestConfigMax )
   624 		{
   629 		{
   625 		ERR_PRINTF1(_L("Attribute index out of range, please check the INI file"));
   630 		ERR_PRINTF1(_L("Attribute index out of range, please check the INI file"));
   626 		User::Leave(KErrArgument);
   631 		User::Leave(KErrArgument);
   627 		}
   632 		}
   628 	
   633 
   629 	EGLConfig configs[KMaxEglConfigs];
   634 	EGLConfig configs[KMaxEglConfigs];
   630 	EGLint numConfigs=0;
   635 	EGLint numConfigs=0;
   631 	ASSERT_EGL_TRUE(eglChooseConfig(iDisplay, KConfigAttribs[aConfigAttribIndex], configs, KMaxEglConfigs, &numConfigs));
   636 	ASSERT_EGL_TRUE(eglChooseConfig(iDisplay, KConfigAttribs[aConfigAttribIndex], configs, KMaxEglConfigs, &numConfigs));
   632 	if (numConfigs <= 0)
   637 	if (numConfigs <= 0)
   633 		{
   638 		{
   634 		// we just WARN, as we don't know if this is expected yet (if it is, then catch the leaving error)
   639 		// we just WARN, as we don't know if this is expected yet (if it is, then catch the leaving error)
   635 		WARN_PRINTF1(_L("GetConfigExactMatchL - Could not find a matching config, eglChooseConfig returned 0 configs!"));
   640 		WARN_PRINTF1(_L("GetConfigExactMatchL - Could not find a matching config, eglChooseConfig returned 0 configs!"));
   636 		User::Leave(KTestNoMatchingConfig);
   641 		User::Leave(KTestNoMatchingConfig);
   637 		}
   642 		}
   638 	
   643 
   639 	// Check that any of the configs returned matches the desired attributes
   644 	// Check that any of the configs returned matches the desired attributes
   640 	TInt match = GetFullMatchConfigIndex(iDisplay, configs, numConfigs, KConfigAttribs[aConfigAttribIndex], aMatchRule);
   645 	TInt match = GetFullMatchConfigIndex(iDisplay, configs, numConfigs, KConfigAttribs[aConfigAttribIndex], aMatchRule);
   641 	if (match == KErrNotFound)
   646 	if (match == KErrNotFound)
   642 		{
   647 		{
   643 		// we just WARN, as we don't know if this is expected yet (if it is, then catch the leaving error)
   648 		// we just WARN, as we don't know if this is expected yet (if it is, then catch the leaving error)
   662 */
   667 */
   663 EXPORT_C void CTestEglSession::TryUsePixmapCFbsBitmapOpenVgL(EGLConfig aConfig, const TSize& aSize, TDisplayMode aDisplayMode)
   668 EXPORT_C void CTestEglSession::TryUsePixmapCFbsBitmapOpenVgL(EGLConfig aConfig, const TSize& aSize, TDisplayMode aDisplayMode)
   664 	{
   669 	{
   665 	CreatePixmapSurfaceAndMakeCurrentL(aConfig, aSize, aDisplayMode);
   670 	CreatePixmapSurfaceAndMakeCurrentL(aConfig, aSize, aDisplayMode);
   666 	DrawOpenVgL();
   671 	DrawOpenVgL();
   667 	
   672 
   668 	// Wait for the drawing to complete
   673 	// Wait for the drawing to complete
   669 	eglWaitClient();
   674 	eglWaitClient();
   670 	
   675 
   671 	CheckImageDataL(iFbsBitmap);
   676 	CheckImageDataL(iFbsBitmap);
   672 	CheckImageDataVgL(VG_sRGB_565);
   677 	CheckImageDataVgL(VG_sRGB_565);
   673 	CleanupSurfaceFbsBitmapL();
   678 	CleanupSurfaceFbsBitmapL();
   674 	CloseFbsSession();
   679 	CloseFbsSession();
   675 	}
   680 	}
   679 */
   684 */
   680 EXPORT_C void CTestEglSession::TryUsePixmapCFbsBitmapOpenGlesL(EGLConfig aConfig, const TSize& aSize, TDisplayMode aDisplayMode, TInt aRenderVersion)
   685 EXPORT_C void CTestEglSession::TryUsePixmapCFbsBitmapOpenGlesL(EGLConfig aConfig, const TSize& aSize, TDisplayMode aDisplayMode, TInt aRenderVersion)
   681 	{
   686 	{
   682 	CreatePixmapSurfaceAndMakeCurrentL(aConfig, aSize, aDisplayMode,EGL_OPENGL_ES_API, aRenderVersion);
   687 	CreatePixmapSurfaceAndMakeCurrentL(aConfig, aSize, aDisplayMode,EGL_OPENGL_ES_API, aRenderVersion);
   683 	DrawOpenGLesL();
   688 	DrawOpenGLesL();
   684 	
   689 
   685 	// Wait for the drawing to complete
   690 	// Wait for the drawing to complete
   686 	eglWaitClient();
   691 	eglWaitClient();
   687 	
   692 
   688 	CheckImageDataFullRedishL(iFbsBitmap);
   693 	CheckImageDataFullRedishL(iFbsBitmap);
   689 	CleanupSurfaceFbsBitmapL();
   694 	CleanupSurfaceFbsBitmapL();
   690 	CloseFbsSession();
   695 	CloseFbsSession();
   691 	}
   696 	}
   692 
   697 
   698 	INFO_PRINTF2(_L("thread %d: TryUsePixmapRSgImageL"), iThreadIdx);
   703 	INFO_PRINTF2(_L("thread %d: TryUsePixmapRSgImageL"), iThreadIdx);
   699 	TSgImageInfo imageInfo;
   704 	TSgImageInfo imageInfo;
   700 	imageInfo.iSizeInPixels = KPixmapSize;
   705 	imageInfo.iSizeInPixels = KPixmapSize;
   701 	imageInfo.iPixelFormat = EUidPixelFormatXRGB_8888;
   706 	imageInfo.iPixelFormat = EUidPixelFormatXRGB_8888;
   702 	// will draw to and read from the image using OpenVg
   707 	// will draw to and read from the image using OpenVg
   703 #ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE	
   708 #ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
   704 	imageInfo.iUsage = ESgUsageBitOpenVgSurface | ESgUsageBitOpenVgImage;
   709 	imageInfo.iUsage = ESgUsageBitOpenVgSurface | ESgUsageBitOpenVgImage;
   705 #else
   710 #else
   706     // will also read from the image using DirectGdi
   711     // will also read from the image using DirectGdi
   707     imageInfo.iUsage = ESgUsageOpenVgTarget | ESgUsageDirectGdiSource;
   712     imageInfo.iUsage = ESgUsageOpenVgTarget | ESgUsageDirectGdiSource;
   708     imageInfo.iShareable = EFalse;
   713     imageInfo.iShareable = EFalse;
   711     imageInfo.iUserAttributes = NULL;
   716     imageInfo.iUserAttributes = NULL;
   712     imageInfo.iUserAttributeCount=0;
   717     imageInfo.iUserAttributeCount=0;
   713 #endif
   718 #endif
   714 	CreatePixmapSurfaceAndMakeCurrentAndMatchL(imageInfo, EResourceCloseSgImageLate);
   719 	CreatePixmapSurfaceAndMakeCurrentAndMatchL(imageInfo, EResourceCloseSgImageLate);
   715 	DrawOpenVgL();
   720 	DrawOpenVgL();
   716 	            
   721 
   717 	// Wait for the drawing to complete
   722 	// Wait for the drawing to complete
   718 	 eglWaitClient();
   723 	 eglWaitClient();
   719 	    
   724 
   720 	//we can't retrieve data directly from the SgImage as 
   725 	//we can't retrieve data directly from the SgImage as
   721 	//non-unified architecture doesn't allow readback from the GPU
   726 	//non-unified architecture doesn't allow readback from the GPU
   722 	CheckImageDataVgL(VG_sXRGB_8888);
   727 	CheckImageDataVgL(VG_sXRGB_8888);
   723 	CleanupSurfaceSgImageL();
   728 	CleanupSurfaceSgImageL();
   724 	CloseSgDriver();
   729 	CloseSgDriver();
   725 	}
   730 	}
   726 
   731 
   727 EXPORT_C TBool CTestEglSession::TryUsePixmapRSgImageOpenGlesL(EGLConfig aConfig, const TSgImageInfo& aImageInfo, TResourceCloseRule aResourceCloseRule, TInt aRenderVersion)
   732 EXPORT_C TBool CTestEglSession::TryUsePixmapRSgImageOpenGlesL(EGLConfig aConfig, const TSgImageInfo& aImageInfo, TResourceCloseRule aResourceCloseRule, TInt aRenderVersion)
   728 	{
   733 	{
   729 	CreatePixmapSurfaceAndMakeCurrentL(aConfig, aImageInfo, aResourceCloseRule ,EGL_OPENGL_ES_API, aRenderVersion);
   734 	CreatePixmapSurfaceAndMakeCurrentL(aConfig, aImageInfo, aResourceCloseRule ,EGL_OPENGL_ES_API, aRenderVersion);
   730 		
   735 
   731 	DrawOpenGLesL();
   736 	DrawOpenGLesL();
   732 			
   737 
   733 	// Wait for the drawing to complete
   738 	// Wait for the drawing to complete
   734 	eglWaitClient();
   739 	eglWaitClient();
   735 
   740 
   736 	//we can't retrieve data directly from SgImage as non-unified 
   741 	//we can't retrieve data directly from SgImage as non-unified
   737 	//architecture doesn't allow readback from the GPU
   742 	//architecture doesn't allow readback from the GPU
   738 	
   743 
   739 	if (aImageInfo.iPixelFormat == EUidPixelFormatXRGB_8888  || 
   744 	if (aImageInfo.iPixelFormat == EUidPixelFormatXRGB_8888  ||
   740 		aImageInfo.iPixelFormat == EUidPixelFormatARGB_8888_PRE)
   745 		aImageInfo.iPixelFormat == EUidPixelFormatARGB_8888_PRE)
   741 		{	
   746 		{
   742 		CheckImageDataGLesL();
   747 		CheckImageDataGLesL();
   743 		}
   748 		}
   744 
   749 
   745 	CleanupSurfaceSgImageL();
   750 	CleanupSurfaceSgImageL();
   746 	CloseSgDriver();
   751 	CloseSgDriver();
   758 @return Whether it was possible to create an iSgImage for the given aImageInfo
   763 @return Whether it was possible to create an iSgImage for the given aImageInfo
   759 */
   764 */
   760 EXPORT_C TBool CTestEglSession::TryUsePixmapRSgImageOpenVgL(EGLConfig aConfig, const TSgImageInfo& aImageInfo, TResourceCloseRule aResourceCloseRule)
   765 EXPORT_C TBool CTestEglSession::TryUsePixmapRSgImageOpenVgL(EGLConfig aConfig, const TSgImageInfo& aImageInfo, TResourceCloseRule aResourceCloseRule)
   761 	{
   766 	{
   762 	CreatePixmapSurfaceAndMakeCurrentL(aConfig, aImageInfo, aResourceCloseRule);
   767 	CreatePixmapSurfaceAndMakeCurrentL(aConfig, aImageInfo, aResourceCloseRule);
   763 		
   768 
   764 	DrawOpenVgL();
   769 	DrawOpenVgL();
   765 			
   770 
   766 	// Wait for the drawing to complete
   771 	// Wait for the drawing to complete
   767 	eglWaitClient();
   772 	eglWaitClient();
   768 	
   773 
   769 	//we can't retrieve data directly from the SgImage as 
   774 	//we can't retrieve data directly from the SgImage as
   770 	//non-unified architecture doesn't allow readback from the GPU
   775 	//non-unified architecture doesn't allow readback from the GPU
   771 	CheckImageDataVgL(VG_sXRGB_8888);
   776 	CheckImageDataVgL(VG_sXRGB_8888);
   772 	CleanupSurfaceSgImageL();
   777 	CleanupSurfaceSgImageL();
   773 	CloseSgDriver();
   778 	CloseSgDriver();
   774 	return ETrue;
   779 	return ETrue;
   775 	}
   780 	}
   776 
   781 
   777 EXPORT_C void CTestEglSession::CreateWindowSurfaceAndMakeCurrentL(EGLConfig aConfig, RWindow& aWindow, EGLenum aBindAPI, TInt aRenderVersionNumber)
   782 EXPORT_C void CTestEglSession::CreateWindowSurfaceAndMakeCurrentL(EGLConfig aConfig, RWindow& aWindow, TBool aVgAlphaFormatPre, EGLenum aBindAPI, TInt aRenderVersionNumber)
   778 	{
   783 	{
   779 	ASSERT_EQUALS(iSurface, EGL_NO_SURFACE);
   784 	ASSERT_EQUALS(iSurface, EGL_NO_SURFACE);
   780 	ASSERT_EQUALS(iContext, EGL_NO_CONTEXT);
   785 	ASSERT_EQUALS(iContext, EGL_NO_CONTEXT);
   781 	
   786 
   782 	ASSERT_EGL_TRUE(eglBindAPI(aBindAPI));
   787 	ASSERT_EGL_TRUE(eglBindAPI(aBindAPI));
   783 		
   788 
   784 	// Create a Window surface from the native image
   789 	// Create a Window surface from the native image
   785 	EGLint EGL_RENDERABLE_TYPE_value = 0;
   790 	const EGLint* windowAttribs = (aVgAlphaFormatPre && aBindAPI == EGL_OPENVG_API) ? KPixmapAttribsVgAlphaFormatPre : KPixmapAttribsNone;
   786 	ASSERT_EGL_TRUE(eglGetConfigAttrib(iDisplay, aConfig, EGL_RENDERABLE_TYPE, &EGL_RENDERABLE_TYPE_value));
   791 	iSurface = eglCreateWindowSurface(iDisplay, aConfig, &aWindow, windowAttribs);
   787 	const EGLint* pixmapAttribs = ((aWindow.DisplayMode() == EColor16MAP) && (EGL_RENDERABLE_TYPE_value & EGL_OPENVG_BIT)) ? KPixmapAttribsVgAlphaFormatPre : KPixmapAttribsNone;
       
   788 	iSurface = eglCreateWindowSurface(iDisplay, aConfig, &aWindow, pixmapAttribs);
       
   789 	ASSERT_EGL_TRUE(iSurface != EGL_NO_SURFACE);
   792 	ASSERT_EGL_TRUE(iSurface != EGL_NO_SURFACE);
   790 
   793 
   791 	// Create a context for drawing to/reading from the pixmap surface and make it current
   794 	// Create a context for drawing to/reading from the pixmap surface and make it current
   792 	const EGLint KAttribsListCtxNone[] = { EGL_NONE };;
   795 	const EGLint KAttribsListCtxNone[] = { EGL_NONE };;
   793 	const EGLint KAttribsListCtxGles2[] = { EGL_CONTEXT_CLIENT_VERSION, aRenderVersionNumber, EGL_NONE };
   796 	const EGLint KAttribsListCtxGles2[] = { EGL_CONTEXT_CLIENT_VERSION, aRenderVersionNumber, EGL_NONE };
   794 	const EGLint* attrib_list_ctx = (aBindAPI == EGL_OPENGL_ES_API && aRenderVersionNumber == 2) ? KAttribsListCtxGles2 : KAttribsListCtxNone; 
   797 	const EGLint* attrib_list_ctx = (aBindAPI == EGL_OPENGL_ES_API && aRenderVersionNumber == 2) ? KAttribsListCtxGles2 : KAttribsListCtxNone;
   795 	iContext = eglCreateContext(iDisplay, aConfig, EGL_NO_CONTEXT, attrib_list_ctx);
   798 	iContext = eglCreateContext(iDisplay, aConfig, EGL_NO_CONTEXT, attrib_list_ctx);
   796 	ASSERT_EGL_TRUE(iContext != EGL_NO_CONTEXT);	
   799 	ASSERT_EGL_TRUE(iContext != EGL_NO_CONTEXT);
   797 	ASSERT_EGL_TRUE(eglMakeCurrent(iDisplay, iSurface, iSurface, iContext));
   800 	ASSERT_EGL_TRUE(eglMakeCurrent(iDisplay, iSurface, iSurface, iContext));
   798 	}
   801 	}
   799 
   802 
   800 
   803 
   801 EXPORT_C TBool CTestEglSession::CongfigSupportsOpenVgL(EGLConfig aConfig)
   804 EXPORT_C TBool CTestEglSession::CongfigSupportsOpenVgL(EGLConfig aConfig)
   807 
   810 
   808 EXPORT_C void CTestEglSession::CreatePixmapSurfaceAndMakeCurrentAndMatchL(const TSgImageInfo& aImageInfo, TResourceCloseRule aResourceCloseRule, EGLenum aBindAPI, TInt aRenderVersionNumber)
   811 EXPORT_C void CTestEglSession::CreatePixmapSurfaceAndMakeCurrentAndMatchL(const TSgImageInfo& aImageInfo, TResourceCloseRule aResourceCloseRule, EGLenum aBindAPI, TInt aRenderVersionNumber)
   809 	{
   812 	{
   810 	ASSERT_EQUALS(iSurface, EGL_NO_SURFACE);
   813 	ASSERT_EQUALS(iSurface, EGL_NO_SURFACE);
   811 	ASSERT_EQUALS(iContext, EGL_NO_CONTEXT);
   814 	ASSERT_EQUALS(iContext, EGL_NO_CONTEXT);
   812 	
   815 
   813     OpenSgDriverL();
   816     OpenSgDriverL();
   814     ASSERT_EQUALS(iSgImage.Create(aImageInfo, NULL, 0), KErrNone);
   817     ASSERT_EQUALS(iSgImage.Create(aImageInfo, NULL, 0), KErrNone);
   815 
   818 
   816 	EGLint renderableType = 0;
   819 	EGLint renderableType = 0;
   817 	if(aBindAPI == EGL_OPENVG_API)
   820 	if(aBindAPI == EGL_OPENVG_API)
   829 	else
   832 	else
   830 		{
   833 		{
   831 		ERR_PRINTF1(_L("CreatePixmapSurfaceAndMakeCurrentAndMatchL - Unkown API requested!"));
   834 		ERR_PRINTF1(_L("CreatePixmapSurfaceAndMakeCurrentAndMatchL - Unkown API requested!"));
   832 		User::Leave(KErrArgument);
   835 		User::Leave(KErrArgument);
   833 		}
   836 		}
   834 	EGLint attrib_list[] = { 
   837 	EGLint attrib_list[] = {
   835 			  EGL_MATCH_NATIVE_PIXMAP,(TInt)&iSgImage,
   838 			  EGL_MATCH_NATIVE_PIXMAP,(TInt)&iSgImage,
   836 			  EGL_RENDERABLE_TYPE,renderableType,
   839 			  EGL_RENDERABLE_TYPE,renderableType,
   837 			  EGL_SURFACE_TYPE,EGL_PIXMAP_BIT,
   840 			  EGL_SURFACE_TYPE,EGL_PIXMAP_BIT,
   838 			  EGL_NONE};
   841 			  EGL_NONE};
   839 
   842 
   856 	EGLint EGL_RENDERABLE_TYPE_value = 0;
   859 	EGLint EGL_RENDERABLE_TYPE_value = 0;
   857 	ASSERT_EGL_TRUE(eglGetConfigAttrib(iDisplay, config, EGL_RENDERABLE_TYPE, &EGL_RENDERABLE_TYPE_value));
   860 	ASSERT_EGL_TRUE(eglGetConfigAttrib(iDisplay, config, EGL_RENDERABLE_TYPE, &EGL_RENDERABLE_TYPE_value));
   858 	const EGLint* pixmapAttribs = ((aImageInfo.iPixelFormat == EUidPixelFormatARGB_8888_PRE) && (EGL_RENDERABLE_TYPE_value & EGL_OPENVG_BIT)) ? KPixmapAttribsVgAlphaFormatPre : KPixmapAttribsNone;
   861 	const EGLint* pixmapAttribs = ((aImageInfo.iPixelFormat == EUidPixelFormatARGB_8888_PRE) && (EGL_RENDERABLE_TYPE_value & EGL_OPENVG_BIT)) ? KPixmapAttribsVgAlphaFormatPre : KPixmapAttribsNone;
   859 	iSurface = eglCreatePixmapSurface(iDisplay, config, &iSgImage, pixmapAttribs);
   862 	iSurface = eglCreatePixmapSurface(iDisplay, config, &iSgImage, pixmapAttribs);
   860 	ASSERT_EGL_TRUE(iSurface != EGL_NO_SURFACE);
   863 	ASSERT_EGL_TRUE(iSurface != EGL_NO_SURFACE);
   861 	
   864 
   862 	if (aResourceCloseRule == EResourceCloseSgImageEarly)
   865 	if (aResourceCloseRule == EResourceCloseSgImageEarly)
   863 		{
   866 		{
   864 		// EGL should have taken its own reference to the SgImage, so it should be able to continue
   867 		// EGL should have taken its own reference to the SgImage, so it should be able to continue
   865 		// to use the underlying data after this local image has been closed.
   868 		// to use the underlying data after this local image has been closed.
   866 		iSgImage.Close();
   869 		iSgImage.Close();
   867 		}
   870 		}
   868 	
   871 
   869 	if (aResourceCloseRule == EResourceCloseSgDriverAndImageEarly)
   872 	if (aResourceCloseRule == EResourceCloseSgDriverAndImageEarly)
   870 		{
   873 		{
   871 		// EGL should have taken its own reference to the SgDriver, so it should be able to continue
   874 		// EGL should have taken its own reference to the SgDriver, so it should be able to continue
   872 		// to use its reference to the image resource after this local reference to the driver has 
   875 		// to use its reference to the image resource after this local reference to the driver has
   873 		// been closed.
   876 		// been closed.
   874 		iSgImage.Close();
   877 		iSgImage.Close();
   875 		CloseSgDriver();		
   878 		CloseSgDriver();
   876 		}
   879 		}
   877 
   880 
   878 	// Create a context for drawing to/reading from the pixmap surface and make it current
   881 	// Create a context for drawing to/reading from the pixmap surface and make it current
   879 	const EGLint KAttribsListCtxNone[] = { EGL_NONE };
   882 	const EGLint KAttribsListCtxNone[] = { EGL_NONE };
   880 	const EGLint KAttribsListCtxGles2[] = { EGL_CONTEXT_CLIENT_VERSION, aRenderVersionNumber, EGL_NONE };
   883 	const EGLint KAttribsListCtxGles2[] = { EGL_CONTEXT_CLIENT_VERSION, aRenderVersionNumber, EGL_NONE };
   883 	ASSERT_EGL_TRUE(iContext != EGL_NO_CONTEXT);	
   886 	ASSERT_EGL_TRUE(iContext != EGL_NO_CONTEXT);	
   884 	ASSERT_EGL_TRUE(eglMakeCurrent(iDisplay, iSurface, iSurface, iContext));
   887 	ASSERT_EGL_TRUE(eglMakeCurrent(iDisplay, iSurface, iSurface, iContext));
   885 	}
   888 	}
   886 
   889 
   887 /**
   890 /**
   888 Compound operation that constructs an RSgImage and uses it to create a pixmap suface. 
   891 Compound operation that constructs an RSgImage and uses it to create a pixmap suface.
   889 It then makes it current to the thread.
   892 It then makes it current to the thread.
   890 @param aConfig The EGL config to be used when creating the pixmap surface
   893 @param aConfig The EGL config to be used when creating the pixmap surface
   891 @param aImageInfo Used to create the RSgImage pixmap
   894 @param aImageInfo Used to create the RSgImage pixmap
   892 @param aCloseNativeImageEarly When ETrue, the RSgImage is closed as soon as the pixmap surface has been
   895 @param aCloseNativeImageEarly When ETrue, the RSgImage is closed as soon as the pixmap surface has been
   893 		created.  Otherwise, the RSgImage is left to be destroyed later by some other method 
   896 		created.  Otherwise, the RSgImage is left to be destroyed later by some other method
   894 		- e.g at the same time as destroying the surface.
   897 		- e.g at the same time as destroying the surface.
   895 @return Whether it was possible to create an iSgImage for the given aImageInfo
   898 @return Whether it was possible to create an iSgImage for the given aImageInfo
   896 */
   899 */
   897 EXPORT_C void CTestEglSession::CreatePixmapSurfaceAndMakeCurrentL(EGLConfig aConfig, const TSgImageInfo& aImageInfo, TResourceCloseRule aResourceCloseRule, EGLenum aBindAPI, TInt aRenderVersionNumber)
   900 EXPORT_C void CTestEglSession::CreatePixmapSurfaceAndMakeCurrentL(EGLConfig aConfig, const TSgImageInfo& aImageInfo, TResourceCloseRule aResourceCloseRule, EGLenum aBindAPI, TInt aRenderVersionNumber)
   898 	{
   901 	{
   899 	ASSERT_EQUALS(iSurface, EGL_NO_SURFACE);
   902 	ASSERT_EQUALS(iSurface, EGL_NO_SURFACE);
   900 	ASSERT_EQUALS(iContext, EGL_NO_CONTEXT);
   903 	ASSERT_EQUALS(iContext, EGL_NO_CONTEXT);
   901 	
   904 
   902 	OpenSgDriverL();
   905 	OpenSgDriverL();
   903     ASSERT_EQUALS(iSgImage.Create(aImageInfo, NULL, 0), KErrNone);
   906     ASSERT_EQUALS(iSgImage.Create(aImageInfo, NULL, 0), KErrNone);
   904 		
   907 
   905 	ASSERT_EGL_TRUE(eglBindAPI(aBindAPI));
   908 	ASSERT_EGL_TRUE(eglBindAPI(aBindAPI));
   906 
   909 
   907 	// Create a pixmap surface from the native image
   910 	// Create a pixmap surface from the native image
   908 	EGLint EGL_RENDERABLE_TYPE_value = 0;
   911 	EGLint EGL_RENDERABLE_TYPE_value = 0;
   909 	ASSERT_EGL_TRUE(eglGetConfigAttrib(iDisplay, aConfig, EGL_RENDERABLE_TYPE, &EGL_RENDERABLE_TYPE_value));
   912 	ASSERT_EGL_TRUE(eglGetConfigAttrib(iDisplay, aConfig, EGL_RENDERABLE_TYPE, &EGL_RENDERABLE_TYPE_value));
   910 	const EGLint* pixmapAttribs = ((aImageInfo.iPixelFormat == EUidPixelFormatARGB_8888_PRE) && (EGL_RENDERABLE_TYPE_value & EGL_OPENVG_BIT)) ? KPixmapAttribsVgAlphaFormatPre : KPixmapAttribsNone;
   913 	const EGLint* pixmapAttribs = ((aImageInfo.iPixelFormat == EUidPixelFormatARGB_8888_PRE) && (EGL_RENDERABLE_TYPE_value & EGL_OPENVG_BIT)) ? KPixmapAttribsVgAlphaFormatPre : KPixmapAttribsNone;
   911 	iSurface = eglCreatePixmapSurface(iDisplay, aConfig, &iSgImage, pixmapAttribs);
   914 	iSurface = eglCreatePixmapSurface(iDisplay, aConfig, &iSgImage, pixmapAttribs);
   912 	ASSERT_EGL_TRUE(iSurface != EGL_NO_SURFACE);
   915 	ASSERT_EGL_TRUE(iSurface != EGL_NO_SURFACE);
   913 	
   916 
   914 	if (aResourceCloseRule == EResourceCloseSgImageEarly)
   917 	if (aResourceCloseRule == EResourceCloseSgImageEarly)
   915 		{
   918 		{
   916 		// EGL should have taken its own reference to the SgImage, so it should be able to continue
   919 		// EGL should have taken its own reference to the SgImage, so it should be able to continue
   917 		// to use the underlying data after this local image has been closed.
   920 		// to use the underlying data after this local image has been closed.
   918 		iSgImage.Close();
   921 		iSgImage.Close();
   919 		}
   922 		}
   920 	if (aResourceCloseRule == EResourceCloseSgDriverAndImageEarly)
   923 	if (aResourceCloseRule == EResourceCloseSgDriverAndImageEarly)
   921 		{
   924 		{
   922 		// EGL should have taken its own reference to the SgDriver, so it should be able to continue
   925 		// EGL should have taken its own reference to the SgDriver, so it should be able to continue
   923 		// to use its reference to the image resource after this local reference to the driver has 
   926 		// to use its reference to the image resource after this local reference to the driver has
   924 		// been closed.
   927 		// been closed.
   925 		iSgImage.Close();
   928 		iSgImage.Close();
   926 		CloseSgDriver();		
   929 		CloseSgDriver();
   927 		}
   930 		}
   928 	
   931 
   929 	// Create a context for drawing to/reading from the pixmap surface and make it current
   932 	// Create a context for drawing to/reading from the pixmap surface and make it current
   930 	const EGLint KAttribsListCtxNone[] = { EGL_NONE };;
   933 	const EGLint KAttribsListCtxNone[] = { EGL_NONE };;
   931 	const EGLint KAttribsListCtxGles2[] = { EGL_CONTEXT_CLIENT_VERSION, aRenderVersionNumber, EGL_NONE };
   934 	const EGLint KAttribsListCtxGles2[] = { EGL_CONTEXT_CLIENT_VERSION, aRenderVersionNumber, EGL_NONE };
   932 	const EGLint* attrib_list_ctx = (aBindAPI == EGL_OPENGL_ES_API && aRenderVersionNumber == 2) ? KAttribsListCtxGles2 : KAttribsListCtxNone; 
   935 	const EGLint* attrib_list_ctx = (aBindAPI == EGL_OPENGL_ES_API && aRenderVersionNumber == 2) ? KAttribsListCtxGles2 : KAttribsListCtxNone;
   933 	iContext = eglCreateContext(iDisplay, aConfig, EGL_NO_CONTEXT, attrib_list_ctx);
   936 	iContext = eglCreateContext(iDisplay, aConfig, EGL_NO_CONTEXT, attrib_list_ctx);
   934 	ASSERT_EGL_TRUE(iContext != EGL_NO_CONTEXT);	
   937 	ASSERT_EGL_TRUE(iContext != EGL_NO_CONTEXT);
   935 	ASSERT_EGL_TRUE(eglMakeCurrent(iDisplay, iSurface, iSurface, iContext));
   938 	ASSERT_EGL_TRUE(eglMakeCurrent(iDisplay, iSurface, iSurface, iContext));
   936 	}
   939 	}
   937 
   940 
   938 EXPORT_C TInt CTestEglSession::CreateBitmap(CFbsBitmap* aFbsBitmap, const TSize& aSize, TDisplayMode aDisplayMode)
   941 EXPORT_C TInt CTestEglSession::CreateBitmap(CFbsBitmap* aFbsBitmap, const TSize& aSize, TDisplayMode aDisplayMode)
   939 	{
   942 	{
   940 	//Fist try with CreateHardwareBitmap to check whether we are on hardware
   943 	//Fist try with CreateHardwareBitmap to check whether we are on hardware
   941 	TInt result = aFbsBitmap->CreateHardwareBitmap(aSize, aDisplayMode, KUidEglTestServer);
   944 	TInt result = aFbsBitmap->CreateHardwareBitmap(aSize, aDisplayMode, KUidEglTestServer);
   942 	
   945 
   943 	if(result == KErrNotSupported)
   946 	if(result == KErrNotSupported)
   944 		{
   947 		{
   945 		//we are not on hardware
   948 		//we are not on hardware
   946 		result = aFbsBitmap->Create(aSize, aDisplayMode);
   949 		result = aFbsBitmap->Create(aSize, aDisplayMode);
   947 		}
   950 		}
   950 
   953 
   951 EXPORT_C void CTestEglSession::CreatePixmapSurfaceAndMakeCurrentL(EGLConfig aConfig, const TSize& aSize, TDisplayMode displayMode, EGLenum aBindAPI, TInt aRenderVersionNumber)
   954 EXPORT_C void CTestEglSession::CreatePixmapSurfaceAndMakeCurrentL(EGLConfig aConfig, const TSize& aSize, TDisplayMode displayMode, EGLenum aBindAPI, TInt aRenderVersionNumber)
   952 	{
   955 	{
   953 	ASSERT_EQUALS(iSurface, EGL_NO_SURFACE);
   956 	ASSERT_EQUALS(iSurface, EGL_NO_SURFACE);
   954 	ASSERT_EQUALS(iContext, EGL_NO_CONTEXT);
   957 	ASSERT_EQUALS(iContext, EGL_NO_CONTEXT);
   955 	
   958 
   956 	// Create an empty native CFbsBitmap
   959 	// Create an empty native CFbsBitmap
   957 	OpenFbsSessionL();
   960 	OpenFbsSessionL();
   958 	iFbsBitmap = new(ELeave)CFbsBitmap;
   961 	iFbsBitmap = new(ELeave)CFbsBitmap;
   959 	ASSERT_EQUALS(CreateBitmap(iFbsBitmap, aSize, displayMode), KErrNone);
   962 	ASSERT_EQUALS(CreateBitmap(iFbsBitmap, aSize, displayMode), KErrNone);
   960 	
   963 
   961     const EGLint* attrib_list = NULL;
   964     const EGLint* attrib_list = NULL;
   962 	if(aBindAPI == EGL_OPENVG_API)
   965 	if(aBindAPI == EGL_OPENVG_API)
   963 		{
   966 		{
   964 		// no attribs to modify
   967 		// no attribs to modify
   965 		}
   968 		}
   976 		{
   979 		{
   977 		ERR_PRINTF1(_L("CreatePixmapSurfaceAndMakeCurrentL - Unkown API requested!"));
   980 		ERR_PRINTF1(_L("CreatePixmapSurfaceAndMakeCurrentL - Unkown API requested!"));
   978 		User::Leave(KErrArgument);
   981 		User::Leave(KErrArgument);
   979 		}
   982 		}
   980 	ASSERT_EGL_TRUE(eglBindAPI(aBindAPI));
   983 	ASSERT_EGL_TRUE(eglBindAPI(aBindAPI));
   981 	
   984 
   982 	// Create a pixmap surface from the native image
   985 	// Create a pixmap surface from the native image
   983 	EGLint EGL_RENDERABLE_TYPE_value = 0;
   986 	EGLint EGL_RENDERABLE_TYPE_value = 0;
   984 	ASSERT_EGL_TRUE(eglGetConfigAttrib(iDisplay, aConfig, EGL_RENDERABLE_TYPE, &EGL_RENDERABLE_TYPE_value));
   987 	ASSERT_EGL_TRUE(eglGetConfigAttrib(iDisplay, aConfig, EGL_RENDERABLE_TYPE, &EGL_RENDERABLE_TYPE_value));
   985 	const EGLint* pixmapAttribs = ((displayMode == EColor16MAP) && (EGL_RENDERABLE_TYPE_value & EGL_OPENVG_BIT)) ? KPixmapAttribsVgAlphaFormatPre : KPixmapAttribsNone;
   988 	const EGLint* pixmapAttribs = ((displayMode == EColor16MAP) && (EGL_RENDERABLE_TYPE_value & EGL_OPENVG_BIT)) ? KPixmapAttribsVgAlphaFormatPre : KPixmapAttribsNone;
   986 	iSurface = eglCreatePixmapSurface(iDisplay, aConfig, iFbsBitmap, pixmapAttribs);
   989 	iSurface = eglCreatePixmapSurface(iDisplay, aConfig, iFbsBitmap, pixmapAttribs);
   987 	ASSERT_EGL_TRUE(iSurface != EGL_NO_SURFACE);
   990 	ASSERT_EGL_TRUE(iSurface != EGL_NO_SURFACE);
   988 	
   991 
   989 	// Create a context for drawing to/reading from the pixmap surface and make it current
   992 	// Create a context for drawing to/reading from the pixmap surface and make it current
   990 	iContext = eglCreateContext(iDisplay, aConfig, EGL_NO_CONTEXT, attrib_list);
   993 	iContext = eglCreateContext(iDisplay, aConfig, EGL_NO_CONTEXT, attrib_list);
   991 	ASSERT_EGL_TRUE(iContext != EGL_NO_CONTEXT);	
   994 	ASSERT_EGL_TRUE(iContext != EGL_NO_CONTEXT);
   992 	ASSERT_EGL_TRUE(eglMakeCurrent(iDisplay, iSurface, iSurface, iContext));
   995 	ASSERT_EGL_TRUE(eglMakeCurrent(iDisplay, iSurface, iSurface, iContext));
   993 	}
   996 	}
   994 
   997 
   995 EXPORT_C void CTestEglSession::CreatePixmapSurfaceAndMakeCurrentAndMatchL(const TSize& aSize, TDisplayMode displayMode, EGLenum aBindAPI, TInt aRenderVersionNumber)
   998 EXPORT_C void CTestEglSession::CreatePixmapSurfaceAndMakeCurrentAndMatchL(const TSize& aSize, TDisplayMode aDisplayMode, EGLenum aBindAPI, TInt aRenderVersionNumber)
   996 	{
   999 	{
   997 	ASSERT_EQUALS(iSurface, EGL_NO_SURFACE);
  1000 	ASSERT_EQUALS(iSurface, EGL_NO_SURFACE);
   998 	ASSERT_EQUALS(iContext, EGL_NO_CONTEXT);
  1001 	ASSERT_EQUALS(iContext, EGL_NO_CONTEXT);
   999 	
  1002 
  1000 	OpenFbsSessionL();
  1003 	OpenFbsSessionL();
  1001 	iFbsBitmap = new(ELeave)CFbsBitmap;
  1004 	iFbsBitmap = new(ELeave)CFbsBitmap;
  1002 	ASSERT_EQUALS(CreateBitmap(iFbsBitmap, aSize, displayMode), KErrNone);
  1005 	ASSERT_EQUALS(CreateBitmap(iFbsBitmap, aSize, aDisplayMode), KErrNone);
  1003 
  1006 
  1004 	EGLint renderableType = 0;
  1007 	EGLint renderableType = 0;
  1005 	if(aBindAPI == EGL_OPENVG_API)
  1008 	if(aBindAPI == EGL_OPENVG_API)
  1006 		{
  1009 		{
  1007 		renderableType = EGL_OPENVG_BIT;
  1010 		renderableType = EGL_OPENVG_BIT;
  1017 	else
  1020 	else
  1018 		{
  1021 		{
  1019 		ERR_PRINTF1(_L("CreatePixmapSurfaceAndMakeCurrentAndMatchL - Unkown API requested!"));
  1022 		ERR_PRINTF1(_L("CreatePixmapSurfaceAndMakeCurrentAndMatchL - Unkown API requested!"));
  1020 		User::Leave(KErrArgument);
  1023 		User::Leave(KErrArgument);
  1021 		}
  1024 		}
  1022 	EGLint attrib_list[] = { 
  1025 	EGLint attrib_list[] = {
  1023 			  EGL_MATCH_NATIVE_PIXMAP,(TInt)iFbsBitmap,
  1026 			  EGL_MATCH_NATIVE_PIXMAP,(TInt)iFbsBitmap,
  1024 			  EGL_RENDERABLE_TYPE,renderableType,
  1027 			  EGL_RENDERABLE_TYPE,renderableType,
  1025 			  EGL_SURFACE_TYPE,EGL_PIXMAP_BIT,
  1028 			  EGL_SURFACE_TYPE,EGL_PIXMAP_BIT,
  1026 			  EGL_NONE};
  1029 			  EGL_NONE};
  1027 
  1030 
  1039 		// Leave with a unique knonwn error code - useful to catch this error in negative tests
  1042 		// Leave with a unique knonwn error code - useful to catch this error in negative tests
  1040 		User::Leave(KTestNoMatchingConfig);
  1043 		User::Leave(KTestNoMatchingConfig);
  1041 		}
  1044 		}
  1042 
  1045 
  1043 	// Create a pixmap surface from the native image
  1046 	// Create a pixmap surface from the native image
  1044 	EGLint EGL_RENDERABLE_TYPE_value = 0;
  1047 	const EGLint* pixmapAttribs = (aDisplayMode == EColor16MAP && aBindAPI == EGL_OPENVG_API) ? KPixmapAttribsVgAlphaFormatPre : KPixmapAttribsNone;
  1045 	ASSERT_EGL_TRUE(eglGetConfigAttrib(iDisplay, config, EGL_RENDERABLE_TYPE, &EGL_RENDERABLE_TYPE_value));
       
  1046 	const EGLint* pixmapAttribs = ((displayMode == EColor16MAP) && (EGL_RENDERABLE_TYPE_value & EGL_OPENVG_BIT)) ? KPixmapAttribsVgAlphaFormatPre : KPixmapAttribsNone;
       
  1047 	iSurface = eglCreatePixmapSurface(iDisplay, config, iFbsBitmap, pixmapAttribs);
  1048 	iSurface = eglCreatePixmapSurface(iDisplay, config, iFbsBitmap, pixmapAttribs);
  1048 	ASSERT_EGL_TRUE(iSurface != EGL_NO_SURFACE);
  1049 	ASSERT_EGL_TRUE(iSurface != EGL_NO_SURFACE);
  1049 	
  1050 
  1050 	// Create a context for drawing to/reading from the pixmap surface and make it current
  1051 	// Create a context for drawing to/reading from the pixmap surface and make it current
  1051 	const EGLint KAttribsListCtxNone[] = { EGL_NONE };;
  1052 	const EGLint KAttribsListCtxNone[] = { EGL_NONE };;
  1052 	const EGLint KAttribsListCtxGles2[] = { EGL_CONTEXT_CLIENT_VERSION, aRenderVersionNumber, EGL_NONE };
  1053 	const EGLint KAttribsListCtxGles2[] = { EGL_CONTEXT_CLIENT_VERSION, aRenderVersionNumber, EGL_NONE };
  1053 	const EGLint* attrib_list_ctx = (aBindAPI == EGL_OPENGL_ES_API && aRenderVersionNumber == 2) ? KAttribsListCtxGles2 : KAttribsListCtxNone; 
  1054 	const EGLint* attrib_list_ctx = (aBindAPI == EGL_OPENGL_ES_API && aRenderVersionNumber == 2) ? KAttribsListCtxGles2 : KAttribsListCtxNone;
  1054 	iContext = eglCreateContext(iDisplay, config, EGL_NO_CONTEXT, attrib_list_ctx);
  1055 	iContext = eglCreateContext(iDisplay, config, EGL_NO_CONTEXT, attrib_list_ctx);
  1055 	ASSERT_EGL_TRUE(iContext != EGL_NO_CONTEXT);	
  1056 	ASSERT_EGL_TRUE(iContext != EGL_NO_CONTEXT);
  1056 	ASSERT_EGL_TRUE(eglMakeCurrent(iDisplay, iSurface, iSurface, iContext));
  1057 	ASSERT_EGL_TRUE(eglMakeCurrent(iDisplay, iSurface, iSurface, iContext));
  1057 	}
  1058 	}
  1058 
  1059 
  1059 EXPORT_C void CTestEglSession::CreatePbufferSurfaceAndMakeCurrentL(EGLConfig aConfig, const TSize& aSize, EGLenum aBindAPI, TInt aRenderVersionNumber)
  1060 EXPORT_C void CTestEglSession::CreatePbufferSurfaceAndMakeCurrentL(EGLConfig aConfig, const TSize& aSize, EGLenum aBindAPI, TInt aRenderVersionNumber)
  1060 	{
  1061 	{
  1061 	ASSERT_EQUALS(iSurface, EGL_NO_SURFACE);
  1062 	ASSERT_EQUALS(iSurface, EGL_NO_SURFACE);
  1062 	ASSERT_EQUALS(iContext, EGL_NO_CONTEXT);
  1063 	ASSERT_EQUALS(iContext, EGL_NO_CONTEXT);
  1063 
  1064 
  1064 	ASSERT_EQUALS(iSurface, EGL_NO_SURFACE);
  1065 	ASSERT_EQUALS(iSurface, EGL_NO_SURFACE);
  1065 	ASSERT_EQUALS(iContext, EGL_NO_CONTEXT);
  1066 	ASSERT_EQUALS(iContext, EGL_NO_CONTEXT);
  1066 	
  1067 
  1067 	ASSERT_EGL_TRUE(eglBindAPI(aBindAPI));
  1068 	ASSERT_EGL_TRUE(eglBindAPI(aBindAPI));
  1068 	
  1069 
  1069 	//	PBuffer attribs options are:
  1070 	//	PBuffer attribs options are:
  1070 	//		EGL_WIDTH, EGL_HEIGHT, EGL_LARGEST_PBUFFER,
  1071 	//		EGL_WIDTH, EGL_HEIGHT, EGL_LARGEST_PBUFFER,
  1071 	//		EGL_TEXTURE_FORMAT, EGL_TEXTURE_TARGET, EGL_MIPMAP_TEXTURE,
  1072 	//		EGL_TEXTURE_FORMAT, EGL_TEXTURE_TARGET, EGL_MIPMAP_TEXTURE,
  1072 	//		EGL_VG_COLORSPACE, and EGL_VG_ALPHA_FORMAT
  1073 	//		EGL_VG_COLORSPACE, and EGL_VG_ALPHA_FORMAT
  1073 	// Create a pbuffer surface of the given size
  1074 	// Create a pbuffer surface of the given size
  1074 	const EGLint KPbufferAttribs[] = { 
  1075 	const EGLint KPbufferAttribs[] = {
  1075 			EGL_WIDTH,	aSize.iWidth,
  1076 			EGL_WIDTH,	aSize.iWidth,
  1076 			EGL_HEIGHT,	aSize.iHeight,
  1077 			EGL_HEIGHT,	aSize.iHeight,
  1077 			EGL_NONE };
  1078 			EGL_NONE };
  1078 	iSurface = eglCreatePbufferSurface(iDisplay, aConfig, KPbufferAttribs);	
  1079 	iSurface = eglCreatePbufferSurface(iDisplay, aConfig, KPbufferAttribs);
  1079 	ASSERT_EGL_TRUE(iSurface != EGL_NO_SURFACE);
  1080 	ASSERT_EGL_TRUE(iSurface != EGL_NO_SURFACE);
  1080 
  1081 
  1081 	// Create a context for drawing to/reading from the pixmap surface and make it current
  1082 	// Create a context for drawing to/reading from the pixmap surface and make it current
  1082 	const EGLint KAttribsListCtxNone[] = { EGL_NONE };;
  1083 	const EGLint KAttribsListCtxNone[] = { EGL_NONE };;
  1083 	const EGLint KAttribsListCtxGles2[] = { EGL_CONTEXT_CLIENT_VERSION, aRenderVersionNumber, EGL_NONE };
  1084 	const EGLint KAttribsListCtxGles2[] = { EGL_CONTEXT_CLIENT_VERSION, aRenderVersionNumber, EGL_NONE };
  1084 	const EGLint* attrib_list_ctx = (aBindAPI == EGL_OPENGL_ES_API && aRenderVersionNumber == 2) ? KAttribsListCtxGles2 : KAttribsListCtxNone; 
  1085 	const EGLint* attrib_list_ctx = (aBindAPI == EGL_OPENGL_ES_API && aRenderVersionNumber == 2) ? KAttribsListCtxGles2 : KAttribsListCtxNone;
  1085 	iContext = eglCreateContext(iDisplay, aConfig, EGL_NO_CONTEXT, attrib_list_ctx);
  1086 	iContext = eglCreateContext(iDisplay, aConfig, EGL_NO_CONTEXT, attrib_list_ctx);
  1086 	ASSERT_EGL_TRUE(iContext != EGL_NO_CONTEXT);	
  1087 	ASSERT_EGL_TRUE(iContext != EGL_NO_CONTEXT);
  1087 	ASSERT_EGL_TRUE(eglMakeCurrent(iDisplay, iSurface, iSurface, iContext));
  1088 	ASSERT_EGL_TRUE(eglMakeCurrent(iDisplay, iSurface, iSurface, iContext));
  1088 	}
  1089 	}
  1089 
  1090 
  1090 EXPORT_C void CTestEglSession::DrawOpenVgL()
  1091 EXPORT_C void CTestEglSession::DrawOpenVgL()
  1091 	{
  1092 	{
  1092 	ASSERT_TRUE(iSurface != EGL_NO_SURFACE);
  1093 	ASSERT_TRUE(iSurface != EGL_NO_SURFACE);
  1093 	ASSERT_TRUE(iContext != EGL_NO_CONTEXT);
  1094 	ASSERT_TRUE(iContext != EGL_NO_CONTEXT);
  1094 	
  1095 
  1095 	// Draw to the pixmap surface 
  1096 	// Draw to the pixmap surface
  1096 	// Clear it: redish
  1097 	// Clear it: redish
  1097 	VGfloat colorBackground[4];
  1098 	VGfloat colorBackground[4];
  1098 	ConvertColor(KRgbReddish, colorBackground);
  1099 	ConvertColor(KRgbReddish, colorBackground);
  1099 	vgSetfv(VG_CLEAR_COLOR, 4, colorBackground);
  1100 	vgSetfv(VG_CLEAR_COLOR, 4, colorBackground);
  1100 	vgClear(0, 0, KPixmapSize.iWidth, KPixmapSize.iHeight);
  1101 	vgClear(0, 0, KPixmapSize.iWidth, KPixmapSize.iHeight);
  1101 	
  1102 
  1102 	// And add a square: greenish
  1103 	// And add a square: greenish
  1103 	VGfloat colorSquare[4];
  1104 	VGfloat colorSquare[4];
  1104 	ConvertColor(KRgbGreenish, colorSquare);
  1105 	ConvertColor(KRgbGreenish, colorSquare);
  1105 	vgSetfv(VG_CLEAR_COLOR, 4, colorSquare);
  1106 	vgSetfv(VG_CLEAR_COLOR, 4, colorSquare);
  1106 	vgClear(KPixmapSquare.iTl.iX, KPixmapSquare.iTl.iX, KPixmapSquare.Width(), KPixmapSquare.Height());
  1107 	vgClear(KPixmapSquare.iTl.iX, KPixmapSquare.iTl.iX, KPixmapSquare.Width(), KPixmapSquare.Height());
  1117 	const GLfloat glAlpha = KRgbReddish.Alpha();
  1118 	const GLfloat glAlpha = KRgbReddish.Alpha();
  1118 	const GLfloat glRedBits = 255.f;
  1119 	const GLfloat glRedBits = 255.f;
  1119 	const GLfloat glGreenBits = 255.f;
  1120 	const GLfloat glGreenBits = 255.f;
  1120 	const GLfloat glBlueBits  = 255.f;
  1121 	const GLfloat glBlueBits  = 255.f;
  1121 	const GLfloat glAlphaBits = 255.f;
  1122 	const GLfloat glAlphaBits = 255.f;
  1122 	
  1123 
  1123 	// Disable  cdither - when using exact comparison to reference bitmap
  1124 	// Disable  cdither - when using exact comparison to reference bitmap
  1124 	// because reference bitmap cannot be created to match dither exactly
  1125 	// because reference bitmap cannot be created to match dither exactly
  1125 	glDisable(GL_DITHER);	
  1126 	glDisable(GL_DITHER);
  1126 	// Clear the surface to the colour specified
  1127 	// Clear the surface to the colour specified
  1127 	glClearColor((glRed)/glRedBits, (glGreen)/glGreenBits, (glBlue)/glBlueBits, glAlpha/glAlphaBits);
  1128 	glClearColor((glRed)/glRedBits, (glGreen)/glGreenBits, (glBlue)/glBlueBits, glAlpha/glAlphaBits);
  1128 	
  1129 
  1129 	//glColor3f(KRgbGreenish.Red(),KRgbGreenish.Green(),KRgbGreenish.Blue());
  1130 	//glColor3f(KRgbGreenish.Red(),KRgbGreenish.Green(),KRgbGreenish.Blue());
  1130 	//glRectf(KPixmapSquare.iTl.iX, KPixmapSquare.iTl.iY,KPixmapSquare.iTl.iX + KPixmapSquare.Width(),KPixmapSquare.iTl.iY + KPixmapSquare.Height());
  1131 	//glRectf(KPixmapSquare.iTl.iX, KPixmapSquare.iTl.iY,KPixmapSquare.iTl.iX + KPixmapSquare.Width(),KPixmapSquare.iTl.iY + KPixmapSquare.Height());
  1131 	
  1132 
  1132 	glClear(GL_COLOR_BUFFER_BIT);
  1133 	glClear(GL_COLOR_BUFFER_BIT);
  1133 	}
  1134 	}
  1134 
  1135 
  1135 EXPORT_C void CTestEglSession::CheckImageDataL(CFbsBitmap* aFbsBitmap)
  1136 EXPORT_C void CTestEglSession::CheckImageDataL(CFbsBitmap* aFbsBitmap)
  1136 	{
  1137 	{
  1139 	// Outside the square
  1140 	// Outside the square
  1140 	aFbsBitmap->GetPixel(rgbPixelSample, TPoint(10,10));
  1141 	aFbsBitmap->GetPixel(rgbPixelSample, TPoint(10,10));
  1141 	ASSERT_TRUE(PixelsMatch(KRgbReddish, rgbPixelSample, EFalse));
  1142 	ASSERT_TRUE(PixelsMatch(KRgbReddish, rgbPixelSample, EFalse));
  1142 	aFbsBitmap->GetPixel(rgbPixelSample, TPoint(90,90));
  1143 	aFbsBitmap->GetPixel(rgbPixelSample, TPoint(90,90));
  1143 	ASSERT_TRUE(PixelsMatch(KRgbReddish, rgbPixelSample, EFalse));
  1144 	ASSERT_TRUE(PixelsMatch(KRgbReddish, rgbPixelSample, EFalse));
  1144 	
  1145 
  1145 	// Inside the square
  1146 	// Inside the square
  1146 	aFbsBitmap->GetPixel(rgbPixelSample, TPoint(30,30));
  1147 	aFbsBitmap->GetPixel(rgbPixelSample, TPoint(30,30));
  1147 	ASSERT_TRUE(PixelsMatch(KRgbGreenish, rgbPixelSample, EFalse));
  1148 	ASSERT_TRUE(PixelsMatch(KRgbGreenish, rgbPixelSample, EFalse));
  1148 	aFbsBitmap->GetPixel(rgbPixelSample, TPoint(70,70));
  1149 	aFbsBitmap->GetPixel(rgbPixelSample, TPoint(70,70));
  1149 	ASSERT_TRUE(PixelsMatch(KRgbGreenish, rgbPixelSample, EFalse));
  1150 	ASSERT_TRUE(PixelsMatch(KRgbGreenish, rgbPixelSample, EFalse));
  1156 	// Outside the square
  1157 	// Outside the square
  1157 	aFbsBitmap->GetPixel(rgbPixelSample, TPoint(10,10));
  1158 	aFbsBitmap->GetPixel(rgbPixelSample, TPoint(10,10));
  1158 	ASSERT_TRUE(PixelsMatch(KRgbReddish, rgbPixelSample, EFalse));
  1159 	ASSERT_TRUE(PixelsMatch(KRgbReddish, rgbPixelSample, EFalse));
  1159 	aFbsBitmap->GetPixel(rgbPixelSample, TPoint(90,90));
  1160 	aFbsBitmap->GetPixel(rgbPixelSample, TPoint(90,90));
  1160 	ASSERT_TRUE(PixelsMatch(KRgbReddish, rgbPixelSample, EFalse));
  1161 	ASSERT_TRUE(PixelsMatch(KRgbReddish, rgbPixelSample, EFalse));
  1161 	
  1162 
  1162 	// Inside the square
  1163 	// Inside the square
  1163 	aFbsBitmap->GetPixel(rgbPixelSample, TPoint(30,30));
  1164 	aFbsBitmap->GetPixel(rgbPixelSample, TPoint(30,30));
  1164 	ASSERT_TRUE(PixelsMatch(KRgbReddish, rgbPixelSample, EFalse));
  1165 	ASSERT_TRUE(PixelsMatch(KRgbReddish, rgbPixelSample, EFalse));
  1165 	aFbsBitmap->GetPixel(rgbPixelSample, TPoint(70,70));
  1166 	aFbsBitmap->GetPixel(rgbPixelSample, TPoint(70,70));
  1166 	ASSERT_TRUE(PixelsMatch(KRgbReddish, rgbPixelSample, EFalse));
  1167 	ASSERT_TRUE(PixelsMatch(KRgbReddish, rgbPixelSample, EFalse));
  1175 	switch(aDataFormat)
  1176 	switch(aDataFormat)
  1176 		{
  1177 		{
  1177 		case VG_sRGB_565:
  1178 		case VG_sRGB_565:
  1178 			{
  1179 			{
  1179 			TUint16 intPixelSample=0;
  1180 			TUint16 intPixelSample=0;
  1180 			
  1181 
  1181 			// Outside the square
  1182 			// Outside the square
  1182 			vgReadPixels(&intPixelSample, 1, aDataFormat, 10,10, 1,1);
  1183 			vgReadPixels(&intPixelSample, 1, aDataFormat, 10,10, 1,1);
  1183 			ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color64K(intPixelSample), EFalse));
  1184 			ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color64K(intPixelSample), EFalse));
  1184 			vgReadPixels(&intPixelSample, 1, aDataFormat, 90,90, 1,1);
  1185 			vgReadPixels(&intPixelSample, 1, aDataFormat, 90,90, 1,1);
  1185 			ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color64K(intPixelSample), EFalse));
  1186 			ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color64K(intPixelSample), EFalse));
  1186 			
  1187 
  1187 			// Inside the square
  1188 			// Inside the square
  1188 			vgReadPixels(&intPixelSample, 1, aDataFormat, 30,30, 1,1);
  1189 			vgReadPixels(&intPixelSample, 1, aDataFormat, 30,30, 1,1);
  1189 			ASSERT_TRUE(PixelsMatch(KRgbGreenish, TRgb::Color64K(intPixelSample), EFalse));
  1190 			ASSERT_TRUE(PixelsMatch(KRgbGreenish, TRgb::Color64K(intPixelSample), EFalse));
  1190 			vgReadPixels(&intPixelSample, 1, aDataFormat, 70,70, 1,1);
  1191 			vgReadPixels(&intPixelSample, 1, aDataFormat, 70,70, 1,1);
  1191 			ASSERT_TRUE(PixelsMatch(KRgbGreenish, TRgb::Color64K(intPixelSample), EFalse));
  1192 			ASSERT_TRUE(PixelsMatch(KRgbGreenish, TRgb::Color64K(intPixelSample), EFalse));
  1192 			break;
  1193 			break;
  1193 			}
  1194 			}
  1194 		case VG_sXRGB_8888:		
  1195 		case VG_sXRGB_8888:
  1195 			{
  1196 			{
  1196 			TUint32 intPixelSample=0;
  1197 			TUint32 intPixelSample=0;
  1197 	
  1198 
  1198 			// Outside the square
  1199 			// Outside the square
  1199 			vgReadPixels(&intPixelSample, 1, aDataFormat, 10,10, 1,1);
  1200 			vgReadPixels(&intPixelSample, 1, aDataFormat, 10,10, 1,1);
  1200 			ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color16MU(intPixelSample), EFalse));
  1201 			ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color16MU(intPixelSample), EFalse));
  1201 			vgReadPixels(&intPixelSample, 1, aDataFormat, 90,90, 1,1);
  1202 			vgReadPixels(&intPixelSample, 1, aDataFormat, 90,90, 1,1);
  1202 			ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color16MU(intPixelSample), EFalse));
  1203 			ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color16MU(intPixelSample), EFalse));
  1203 			
  1204 
  1204 			// Inside the square
  1205 			// Inside the square
  1205 			vgReadPixels(&intPixelSample, 1, aDataFormat, 30,30, 1,1);
  1206 			vgReadPixels(&intPixelSample, 1, aDataFormat, 30,30, 1,1);
  1206 			ASSERT_TRUE(PixelsMatch(KRgbGreenish, TRgb::Color16MU(intPixelSample), EFalse));
  1207 			ASSERT_TRUE(PixelsMatch(KRgbGreenish, TRgb::Color16MU(intPixelSample), EFalse));
  1207 			vgReadPixels(&intPixelSample, 1, aDataFormat, 70,70, 1,1);
  1208 			vgReadPixels(&intPixelSample, 1, aDataFormat, 70,70, 1,1);
  1208 			ASSERT_TRUE(PixelsMatch(KRgbGreenish, TRgb::Color16MU(intPixelSample), EFalse));
  1209 			ASSERT_TRUE(PixelsMatch(KRgbGreenish, TRgb::Color16MU(intPixelSample), EFalse));
  1209 			break;
  1210 			break;
  1210 			}
  1211 			}
  1211 		case VG_sARGB_8888:
  1212 		case VG_sARGB_8888:
  1212 			{
  1213 			{
  1213 			TUint32 intPixelSample=0;
  1214 			TUint32 intPixelSample=0;
  1214 	
  1215 
  1215 			// Outside the square
  1216 			// Outside the square
  1216 			vgReadPixels(&intPixelSample, 1, aDataFormat, 10,10, 1,1);
  1217 			vgReadPixels(&intPixelSample, 1, aDataFormat, 10,10, 1,1);
  1217 			ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color16MA(intPixelSample), EFalse));
  1218 			ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color16MA(intPixelSample), EFalse));
  1218 			vgReadPixels(&intPixelSample, 1, aDataFormat, 90,90, 1,1);
  1219 			vgReadPixels(&intPixelSample, 1, aDataFormat, 90,90, 1,1);
  1219 			ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color16MA(intPixelSample), EFalse));
  1220 			ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color16MA(intPixelSample), EFalse));
  1220 			
  1221 
  1221 			// Inside the square
  1222 			// Inside the square
  1222 			vgReadPixels(&intPixelSample, 1, aDataFormat, 30,30, 1,1);
  1223 			vgReadPixels(&intPixelSample, 1, aDataFormat, 30,30, 1,1);
  1223 			ASSERT_TRUE(PixelsMatch(KRgbGreenish, TRgb::Color16MA(intPixelSample), EFalse));
  1224 			ASSERT_TRUE(PixelsMatch(KRgbGreenish, TRgb::Color16MA(intPixelSample), EFalse));
  1224 			vgReadPixels(&intPixelSample, 1, aDataFormat, 70,70, 1,1);
  1225 			vgReadPixels(&intPixelSample, 1, aDataFormat, 70,70, 1,1);
  1225 			ASSERT_TRUE(PixelsMatch(KRgbGreenish, TRgb::Color16MA(intPixelSample), EFalse));
  1226 			ASSERT_TRUE(PixelsMatch(KRgbGreenish, TRgb::Color16MA(intPixelSample), EFalse));
  1238 EXPORT_C void CTestEglSession::CheckImageDataGLesL()
  1239 EXPORT_C void CTestEglSession::CheckImageDataGLesL()
  1239 	{
  1240 	{
  1240 	TUint32 intPixelSample;
  1241 	TUint32 intPixelSample;
  1241 	glReadPixels(10,10,1,1,GL_RGBA,GL_UNSIGNED_BYTE ,&intPixelSample);
  1242 	glReadPixels(10,10,1,1,GL_RGBA,GL_UNSIGNED_BYTE ,&intPixelSample);
  1242 	SwapChannels(intPixelSample);
  1243 	SwapChannels(intPixelSample);
  1243 	ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color16MU(intPixelSample), EFalse));	
  1244 	ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color16MU(intPixelSample), EFalse));
  1244 	
  1245 
  1245 	glReadPixels(45,45,1,1,GL_RGBA,GL_UNSIGNED_BYTE ,&intPixelSample);
  1246 	glReadPixels(45,45,1,1,GL_RGBA,GL_UNSIGNED_BYTE ,&intPixelSample);
  1246 	SwapChannels(intPixelSample);
  1247 	SwapChannels(intPixelSample);
  1247 	ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color16MU(intPixelSample), EFalse));
  1248 	ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color16MU(intPixelSample), EFalse));
  1248 
  1249 
  1249 	glReadPixels(55,55,1,1,GL_RGBA,GL_UNSIGNED_BYTE ,&intPixelSample);
  1250 	glReadPixels(55,55,1,1,GL_RGBA,GL_UNSIGNED_BYTE ,&intPixelSample);
  1257 	}
  1258 	}
  1258 
  1259 
  1259 EXPORT_C void CTestEglSession::SwapChannels(TUint32 &aSwapMe)
  1260 EXPORT_C void CTestEglSession::SwapChannels(TUint32 &aSwapMe)
  1260 	{
  1261 	{
  1261 	TUint32 buff = aSwapMe;
  1262 	TUint32 buff = aSwapMe;
  1262 	
  1263 
  1263 	aSwapMe = 0;
  1264 	aSwapMe = 0;
  1264 	aSwapMe |= (buff & 0x000000FF) << 16;
  1265 	aSwapMe |= (buff & 0x000000FF) << 16;
  1265 	aSwapMe |= (buff & 0x0000FF00);
  1266 	aSwapMe |= (buff & 0x0000FF00);
  1266 	aSwapMe |= (buff & 0x00FF0000) >> 16;
  1267 	aSwapMe |= (buff & 0x00FF0000) >> 16;
  1267 	aSwapMe |= (buff & 0xFF000000);
  1268 	aSwapMe |= (buff & 0xFF000000);
  1281 /**
  1282 /**
  1282 Resets the internal surface and context handles without destroying them.
  1283 Resets the internal surface and context handles without destroying them.
  1283 Also closes the internal RSgImage handled that is associated to the surface.
  1284 Also closes the internal RSgImage handled that is associated to the surface.
  1284 
  1285 
  1285 EGL destroys all surface and context handles associated with a display when
  1286 EGL destroys all surface and context handles associated with a display when
  1286 eglTerminate() is called. 
  1287 eglTerminate() is called.
  1287 */
  1288 */
  1288 EXPORT_C void CTestEglSession::ResetSurfaceAndContextSgImageL()
  1289 EXPORT_C void CTestEglSession::ResetSurfaceAndContextSgImageL()
  1289 	{
  1290 	{
  1290 	INFO_PRINTF1(_L("CTestEglSession::ResetSurfaceAndContextSgImageL()"));
  1291 	INFO_PRINTF1(_L("CTestEglSession::ResetSurfaceAndContextSgImageL()"));
  1291 	
  1292 
  1292 	iContext = EGL_NO_CONTEXT;
  1293 	iContext = EGL_NO_CONTEXT;
  1293 	iSurface = EGL_NO_SURFACE;
  1294 	iSurface = EGL_NO_SURFACE;
  1294 	iSgImage.Close();
  1295 	iSgImage.Close();
  1295 	}
  1296 	}
  1296 
  1297 
  1297 /**
  1298 /**
  1298  Check that the pixel values match within a predefined tolerance
  1299  Check that the pixel values match within a predefined tolerance
  1299  @param aExpected the expected pixel colour vaule
  1300  @param aExpected the expected pixel colour vaule
  1300  @param aActual the actual pixel colour value 
  1301  @param aActual the actual pixel colour value
  1301  @param aCheckAlpha Whether to check the alpha channel value
  1302  @param aCheckAlpha Whether to check the alpha channel value
  1302  @return Whether the pixel values match - within the allowed tolerance
  1303  @return Whether the pixel values match - within the allowed tolerance
  1303  */
  1304  */
  1304 EXPORT_C TBool CTestEglSession::PixelsMatch(const TRgb& aExpected, const TRgb& aActual, TBool aCheckAlpha)
  1305 EXPORT_C TBool CTestEglSession::PixelsMatch(const TRgb& aExpected, const TRgb& aActual, TBool aCheckAlpha)
  1305 	{
  1306 	{
  1306 	// This value has been carefully selected. If it is too high it could be hidding genuine pixel value
  1307 	// This value has been carefully selected. If it is too high it could be hidding genuine pixel value
  1307 	//	differences, while too low will be too strict to allow for pixel conversions, i.e. from 16bpp to 32bpp
  1308 	//	differences, while too low will be too strict to allow for pixel conversions, i.e. from 16bpp to 32bpp
  1308 	const TInt KPixelTolerance = 8;
  1309 	const TInt KPixelTolerance = 8;
  1309 
  1310 
  1310 	if (aCheckAlpha && aExpected.Alpha()== 0 && 
  1311 	if (aCheckAlpha && aExpected.Alpha()== 0 &&
  1311 		aActual.Red() == 0 && 
  1312 		aActual.Red() == 0 &&
  1312 		aActual.Green() == 0 && 
  1313 		aActual.Green() == 0 &&
  1313 		aActual.Blue() == 0 && 
  1314 		aActual.Blue() == 0 &&
  1314 		aActual.Alpha() == 0)
  1315 		aActual.Alpha() == 0)
  1315 		{
  1316 		{
  1316 		// if the expected value for alpha is 0, all actual values should be 0
  1317 		// if the expected value for alpha is 0, all actual values should be 0
  1317 		return ETrue;
  1318 		return ETrue;
  1318 		}
  1319 		}
  1337 	EGLint major=0;
  1338 	EGLint major=0;
  1338 	EGLint minor=0;
  1339 	EGLint minor=0;
  1339 	CHECK_EXPECTED_ERROR(eglInitialize(iDisplay, &major, &minor));
  1340 	CHECK_EXPECTED_ERROR(eglInitialize(iDisplay, &major, &minor));
  1340 	// Remember if the user wants us to terminate the display.
  1341 	// Remember if the user wants us to terminate the display.
  1341 	iTerminateDisplay = aTerminateDisplay;
  1342 	iTerminateDisplay = aTerminateDisplay;
  1342 	
  1343 
  1343 	INFO_PRINTF4(_L("thread %d: Initialised: EGL Version %d.%d"), iThreadIdx, major, minor);
  1344 	INFO_PRINTF4(_L("thread %d: Initialised: EGL Version %d.%d"), iThreadIdx, major, minor);
  1344 	}
  1345 	}
  1345 
  1346 
  1346 
  1347 
  1347 EXPORT_C void CTestEglSession::TerminateDisplayL()
  1348 EXPORT_C void CTestEglSession::TerminateDisplayL()
  1370 EXPORT_C void CTestEglSession::OpenSgDriverL()
  1371 EXPORT_C void CTestEglSession::OpenSgDriverL()
  1371 	{
  1372 	{
  1372 	if (!iSgDriverOpen)
  1373 	if (!iSgDriverOpen)
  1373 		{
  1374 		{
  1374 		VERBOSE_INFO_PRINTF2(_L("CTestEglSession<0x%08x> Opening SgDriver"), this);
  1375 		VERBOSE_INFO_PRINTF2(_L("CTestEglSession<0x%08x> Opening SgDriver"), this);
  1375 #ifdef  SYMBIAN_GRAPHICS_EGL_SGIMAGELITE 		
  1376 #ifdef  SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
  1376 		TInt ret=iSgDriver.Open();
  1377 		TInt ret=iSgDriver.Open();
  1377 #else
  1378 #else
  1378 		TInt ret=SgDriver::Open();
  1379 		TInt ret=SgDriver::Open();
  1379 #endif	//SYMBIAN_GRAPHICS_EGL_SGIMAGELITE	
  1380 #endif	//SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
  1380 		ASSERT_EQUALS(ret, KErrNone);
  1381 		ASSERT_EQUALS(ret, KErrNone);
  1381 		iSgDriverOpen = ETrue;
  1382 		iSgDriverOpen = ETrue;
  1382 		}
  1383 		}
  1383 	}
  1384 	}
  1384 
  1385 
  1385 EXPORT_C void CTestEglSession::CloseSgDriver()
  1386 EXPORT_C void CTestEglSession::CloseSgDriver()
  1386 	{
  1387 	{
  1387 	if (iSgDriverOpen)
  1388 	if (iSgDriverOpen)
  1388 		{
  1389 		{
  1389 		VERBOSE_INFO_PRINTF2(_L("CTestEglSession<0x%08x> Closing SgDriver"), this);
  1390 		VERBOSE_INFO_PRINTF2(_L("CTestEglSession<0x%08x> Closing SgDriver"), this);
  1390 #ifdef  SYMBIAN_GRAPHICS_EGL_SGIMAGELITE        
  1391 #ifdef  SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
  1391         iSgDriver.Close();
  1392         iSgDriver.Close();
  1392 #else
  1393 #else
  1393         SgDriver::Close(); 
  1394         SgDriver::Close();
  1394 #endif  //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
  1395 #endif  //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
  1395 		iSgDriverOpen = EFalse;
  1396 		iSgDriverOpen = EFalse;
  1396 		}
  1397 		}
  1397 	}
  1398 	}
  1398 
  1399 
  1435 EXPORT_C EGLImageKHR CTestEglSession::eglCreateImageKhrL(EGLDisplay aDisplay,EGLContext aContext,EGLenum aTarget,RSgImage* aSgImage,const EGLint *aAttr_List)
  1436 EXPORT_C EGLImageKHR CTestEglSession::eglCreateImageKhrL(EGLDisplay aDisplay,EGLContext aContext,EGLenum aTarget,RSgImage* aSgImage,const EGLint *aAttr_List)
  1436 	{
  1437 	{
  1437 	TBool bSuccess = FetchProcEglCreateImageKhr();
  1438 	TBool bSuccess = FetchProcEglCreateImageKhr();
  1438 	ASSERT_TRUE(bSuccess);
  1439 	ASSERT_TRUE(bSuccess);
  1439 	VERBOSE_INFO_PRINTF2(_L("thread %d: Calling eglCreateImageKHR"), iThreadIdx);
  1440 	VERBOSE_INFO_PRINTF2(_L("thread %d: Calling eglCreateImageKHR"), iThreadIdx);
  1440 	EGLImageKHR eglImage = ipfnEglCreateImageKHR(aDisplay,aContext,aTarget,reinterpret_cast<EGLClientBuffer>(aSgImage),const_cast<EGLint *>(aAttr_List));	
  1441 	EGLImageKHR eglImage = ipfnEglCreateImageKHR(aDisplay,aContext,aTarget,reinterpret_cast<EGLClientBuffer>(aSgImage),const_cast<EGLint *>(aAttr_List));
  1441 	return eglImage;
  1442 	return eglImage;
  1442 	}
  1443 	}
  1443 
  1444 
  1444 EXPORT_C EGLImageKHR CTestEglSession::eglCreateImageKhrL(EGLDisplay aDisplay,EGLContext aContext,EGLenum aTarget,CFbsBitmap &aCFbsBitmap, const EGLint *aAttr_List)
  1445 EXPORT_C EGLImageKHR CTestEglSession::eglCreateImageKhrL(EGLDisplay aDisplay,EGLContext aContext,EGLenum aTarget,CFbsBitmap &aCFbsBitmap, const EGLint *aAttr_List)
  1445 	{
  1446 	{
  1446 	TBool bSuccess = FetchProcEglCreateImageKhr();
  1447 	TBool bSuccess = FetchProcEglCreateImageKhr();
  1447 	ASSERT_TRUE(bSuccess);
  1448 	ASSERT_TRUE(bSuccess);
  1448 	INFO_PRINTF2(_L("thread %d: Calling eglCreateImageKHR, with CFBsBitmap)"), iThreadIdx);
  1449 	INFO_PRINTF2(_L("thread %d: Calling eglCreateImageKHR, with CFBsBitmap)"), iThreadIdx);
  1449 	//the following call to eglCreateImageKHR MUST fail, error handling is made outside
  1450 	//the following call to eglCreateImageKHR MUST fail, error handling is made outside
  1450 	EGLImageKHR eglImage = ipfnEglCreateImageKHR(aDisplay,aContext,aTarget,reinterpret_cast<EGLClientBuffer>(&aCFbsBitmap),const_cast<EGLint *>(aAttr_List));	
  1451 	EGLImageKHR eglImage = ipfnEglCreateImageKHR(aDisplay,aContext,aTarget,reinterpret_cast<EGLClientBuffer>(&aCFbsBitmap),const_cast<EGLint *>(aAttr_List));
  1451 	return eglImage;
  1452 	return eglImage;
  1452 	}
  1453 	}
  1453 
  1454 
  1454 EXPORT_C TBool CTestEglSession::FetchProcEglDestroyImageKhr()
  1455 EXPORT_C TBool CTestEglSession::FetchProcEglDestroyImageKhr()
  1455 	{
  1456 	{
  1477 EXPORT_C TBool CTestEglSession::FetchProcvgCreateImageTargetKhr()
  1478 EXPORT_C TBool CTestEglSession::FetchProcvgCreateImageTargetKhr()
  1478 	{
  1479 	{
  1479 	if (!ipfnvgCreateImageTargetKHR)
  1480 	if (!ipfnvgCreateImageTargetKHR)
  1480 		{
  1481 		{
  1481 		INFO_PRINTF2(_L("thread %d: Calling eglGetProcAddress (\"vgCreateEGLImageTargetKHR\")"), iThreadIdx);
  1482 		INFO_PRINTF2(_L("thread %d: Calling eglGetProcAddress (\"vgCreateEGLImageTargetKHR\")"), iThreadIdx);
  1482 		ipfnvgCreateImageTargetKHR = reinterpret_cast<TFPtrVgCreateEglImageTargetKhr>(eglGetProcAddress("vgCreateEGLImageTargetKHR"));		
  1483 		ipfnvgCreateImageTargetKHR = reinterpret_cast<TFPtrVgCreateEglImageTargetKhr>(eglGetProcAddress("vgCreateEGLImageTargetKHR"));
  1483 		if (ipfnvgCreateImageTargetKHR==NULL)
  1484 		if (ipfnvgCreateImageTargetKHR==NULL)
  1484 			{
  1485 			{
  1485 			EGLint eglError = eglGetError();
  1486 			EGLint eglError = eglGetError();
  1486 			WARN_PRINTF2(_L("vgCreateImageTargetKHR() not found - EGL Error: 0x%x"), eglError);
  1487 			WARN_PRINTF2(_L("vgCreateImageTargetKHR() not found - EGL Error: 0x%x"), eglError);
  1487 			}
  1488 			}
  1505 	EGLint EGL_GREEN_SIZE_value;
  1506 	EGLint EGL_GREEN_SIZE_value;
  1506 	EGLint EGL_RED_SIZE_value;
  1507 	EGLint EGL_RED_SIZE_value;
  1507 	EGLint EGL_SURFACE_TYPE_value;
  1508 	EGLint EGL_SURFACE_TYPE_value;
  1508 	EGLint EGL_RENDERABLE_TYPE_value;
  1509 	EGLint EGL_RENDERABLE_TYPE_value;
  1509 	EGLint EGL_CONFIG_ID_value;
  1510 	EGLint EGL_CONFIG_ID_value;
  1510 	
  1511 
  1511 	eglGetConfigAttrib(iDisplay, aConfig, EGL_CONFIG_ID, &EGL_CONFIG_ID_value);
  1512 	eglGetConfigAttrib(iDisplay, aConfig, EGL_CONFIG_ID, &EGL_CONFIG_ID_value);
  1512 	eglGetConfigAttrib(iDisplay, aConfig, EGL_BUFFER_SIZE, &EGL_BUFFER_SIZE_value);
  1513 	eglGetConfigAttrib(iDisplay, aConfig, EGL_BUFFER_SIZE, &EGL_BUFFER_SIZE_value);
  1513 	eglGetConfigAttrib(iDisplay, aConfig, EGL_ALPHA_SIZE, &EGL_ALPHA_SIZE_value);
  1514 	eglGetConfigAttrib(iDisplay, aConfig, EGL_ALPHA_SIZE, &EGL_ALPHA_SIZE_value);
  1514 	eglGetConfigAttrib(iDisplay, aConfig, EGL_BLUE_SIZE, &EGL_BLUE_SIZE_value);
  1515 	eglGetConfigAttrib(iDisplay, aConfig, EGL_BLUE_SIZE, &EGL_BLUE_SIZE_value);
  1515 	eglGetConfigAttrib(iDisplay, aConfig, EGL_GREEN_SIZE, &EGL_GREEN_SIZE_value);
  1516 	eglGetConfigAttrib(iDisplay, aConfig, EGL_GREEN_SIZE, &EGL_GREEN_SIZE_value);
  1516 	eglGetConfigAttrib(iDisplay, aConfig, EGL_RED_SIZE, &EGL_RED_SIZE_value);
  1517 	eglGetConfigAttrib(iDisplay, aConfig, EGL_RED_SIZE, &EGL_RED_SIZE_value);
  1517 	eglGetConfigAttrib(iDisplay, aConfig, EGL_SURFACE_TYPE, &EGL_SURFACE_TYPE_value);	
  1518 	eglGetConfigAttrib(iDisplay, aConfig, EGL_SURFACE_TYPE, &EGL_SURFACE_TYPE_value);
  1518 	eglGetConfigAttrib(iDisplay, aConfig, EGL_RENDERABLE_TYPE, &EGL_RENDERABLE_TYPE_value);
  1519 	eglGetConfigAttrib(iDisplay, aConfig, EGL_RENDERABLE_TYPE, &EGL_RENDERABLE_TYPE_value);
  1519 #ifdef PRINTG_CONFIGS_LOG
  1520 #ifdef PRINTG_CONFIGS_LOG
  1520 	INFO_PRINTF7(_L("(Config: %3d) RGBA=(%2d) %2d,%2d,%2d,%2d"), EGL_CONFIG_ID_value, EGL_BUFFER_SIZE_value, 
  1521 	INFO_PRINTF7(_L("(Config: %3d) RGBA=(%2d) %2d,%2d,%2d,%2d"), EGL_CONFIG_ID_value, EGL_BUFFER_SIZE_value,
  1521 					EGL_RED_SIZE_value, EGL_GREEN_SIZE_value, EGL_BLUE_SIZE_value, 
  1522 					EGL_RED_SIZE_value, EGL_GREEN_SIZE_value, EGL_BLUE_SIZE_value,
  1522 					EGL_ALPHA_SIZE_value);
  1523 					EGL_ALPHA_SIZE_value);
  1523 	INFO_PRINTF2(_L("RENDERABLE_TYPE %d"),EGL_RENDERABLE_TYPE_value);
  1524 	INFO_PRINTF2(_L("RENDERABLE_TYPE %d"),EGL_RENDERABLE_TYPE_value);
  1524 #endif
  1525 #endif
  1525 	
  1526 
  1526 	if(!(EGL_SURFACE_TYPE_value & EGL_PIXMAP_BIT))
  1527 	if(!(EGL_SURFACE_TYPE_value & EGL_PIXMAP_BIT))
  1527 		{
  1528 		{
  1528 		return EFalse;
  1529 		return EFalse;
  1529 		}
  1530 		}
  1530 	
  1531 
  1531 	TBool good = ETrue;
  1532 	TBool good = ETrue;
  1532 	//requested usage bits
  1533 	//requested usage bits
  1533 	TSgImageInfo requestedImageInfo;
  1534 	TSgImageInfo requestedImageInfo;
  1534 	aImage.GetInfo(requestedImageInfo);
  1535 	aImage.GetInfo(requestedImageInfo);
  1535 	
  1536 
  1536 #ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
  1537 #ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
  1537 	//potential usage bits
  1538 	//potential usage bits
  1538     RSgImage potential;
  1539     RSgImage potential;
  1539     potential.Open(aImage.Id(),ESgDoNotRestrictUsage);
  1540     potential.Open(aImage.Id(),ESgDoNotRestrictUsage);
  1540     TSgImageInfo potentialImageInfo;
  1541     TSgImageInfo potentialImageInfo;
  1541     potential.GetInfo(potentialImageInfo);
  1542     potential.GetInfo(potentialImageInfo);
  1542     potential.Close();
  1543     potential.Close();
  1543 #endif    
  1544 #endif
  1544 	
  1545 
  1545 	switch(requestedImageInfo.iPixelFormat)
  1546 	switch(requestedImageInfo.iPixelFormat)
  1546 		{			
  1547 		{
  1547 		case EUidPixelFormatRGB_565:
  1548 		case EUidPixelFormatRGB_565:
  1548 			if (!(EGL_RED_SIZE_value == 5 && EGL_GREEN_SIZE_value == 6 && EGL_BLUE_SIZE_value == 5 && EGL_ALPHA_SIZE_value == 0))
  1549 			if (!(EGL_RED_SIZE_value == 5 && EGL_GREEN_SIZE_value == 6 && EGL_BLUE_SIZE_value == 5 && EGL_ALPHA_SIZE_value == 0))
  1549 				{
  1550 				{
  1550 				good = EFalse;
  1551 				good = EFalse;
  1551 				}
  1552 				}
  1552 			break;			
  1553 			break;
  1553 		case EUidPixelFormatXRGB_8888:
  1554 		case EUidPixelFormatXRGB_8888:
  1554 			if (!(EGL_RED_SIZE_value == 8 && EGL_GREEN_SIZE_value == 8 && EGL_BLUE_SIZE_value == 8 && EGL_ALPHA_SIZE_value == 0))
  1555 			if (!(EGL_RED_SIZE_value == 8 && EGL_GREEN_SIZE_value == 8 && EGL_BLUE_SIZE_value == 8 && EGL_ALPHA_SIZE_value == 0))
  1555 				{
  1556 				{
  1556 				good = EFalse;
  1557 				good = EFalse;
  1557 				}				
  1558 				}
  1558 			break;			
  1559 			break;
  1559 		case EUidPixelFormatARGB_8888_PRE:
  1560 		case EUidPixelFormatARGB_8888_PRE:
  1560 			if (!(EGL_RED_SIZE_value == 8 && EGL_GREEN_SIZE_value == 8 && EGL_BLUE_SIZE_value == 8 && EGL_ALPHA_SIZE_value == 8))
  1561 			if (!(EGL_RED_SIZE_value == 8 && EGL_GREEN_SIZE_value == 8 && EGL_BLUE_SIZE_value == 8 && EGL_ALPHA_SIZE_value == 8))
  1561 				{
  1562 				{
  1562 				good = EFalse;
  1563 				good = EFalse;
  1563 				}
  1564 				}
  1586 		{
  1587 		{
  1587 		return EFalse;
  1588 		return EFalse;
  1588 		}
  1589 		}
  1589 
  1590 
  1590 #ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
  1591 #ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
  1591 	// 
  1592 	//
  1592 	//Check if strict matching requirements are met:
  1593 	//Check if strict matching requirements are met:
  1593 	//- All the supported APIs included in the EGL_RENDERABLE_TYPE of the 
  1594 	//- All the supported APIs included in the EGL_RENDERABLE_TYPE of the
  1594 	// EGLConfig must be matched by the corresponding iUsage of RSgImage
  1595 	// EGLConfig must be matched by the corresponding iUsage of RSgImage
  1595 	//- The following usages included in the iUsage of the RSgImage must be 
  1596 	//- The following usages included in the iUsage of the RSgImage must be
  1596 	// matched by the corresponding API in EGL_RENDERABLE_TYPE of the EGLConfig: 
  1597 	// matched by the corresponding API in EGL_RENDERABLE_TYPE of the EGLConfig:
  1597 	//         ESgUsageBitOpenGlSurface-> EGL_OPENGL_BIT
  1598 	//         ESgUsageBitOpenGlSurface-> EGL_OPENGL_BIT
  1598 	//         ESgUsageBitOpenGlesSurface-> EGL_OPENGL_ES_BIT
  1599 	//         ESgUsageBitOpenGlesSurface-> EGL_OPENGL_ES_BIT
  1599 	//         ESgUsageBitOpenGles2Surface-> EGL_OPENGL_ES2_BIT
  1600 	//         ESgUsageBitOpenGles2Surface-> EGL_OPENGL_ES2_BIT
  1600 	//         ESgUsageBitOpenVgSurface->EGL_OPENVG_BIT
  1601 	//         ESgUsageBitOpenVgSurface->EGL_OPENVG_BIT
  1601 	
  1602 
  1602 	EGLint usageBitsMask = 0;
  1603 	EGLint usageBitsMask = 0;
  1603 	if(requestedImageInfo.iUsage & ESgUsageBitOpenVgSurface)
  1604 	if(requestedImageInfo.iUsage & ESgUsageBitOpenVgSurface)
  1604 		{
  1605 		{
  1605 		usageBitsMask |= EGL_OPENVG_BIT;
  1606 		usageBitsMask |= EGL_OPENVG_BIT;
  1606 		}
  1607 		}
  1638         }
  1639         }
  1639     if(!(usageBitsMask & EGL_RENDERABLE_TYPE_value))
  1640     if(!(usageBitsMask & EGL_RENDERABLE_TYPE_value))
  1640         {
  1641         {
  1641         return EFalse;
  1642         return EFalse;
  1642         }
  1643         }
  1643     
  1644 
  1644     // potential usage >= RENDERABLE_TYPE
  1645     // potential usage >= RENDERABLE_TYPE
  1645     
  1646 
  1646     EGLint potentialUsageBitsMask = 0;
  1647     EGLint potentialUsageBitsMask = 0;
  1647     if(potentialImageInfo.iUsage & ESgUsageOpenVgTarget)
  1648     if(potentialImageInfo.iUsage & ESgUsageOpenVgTarget)
  1648         {
  1649         {
  1649         potentialUsageBitsMask |= EGL_OPENVG_BIT;
  1650         potentialUsageBitsMask |= EGL_OPENVG_BIT;
  1650         }
  1651         }
  1654         }
  1655         }
  1655     if(potentialImageInfo.iUsage & ESgUsageOpenGles2Target)
  1656     if(potentialImageInfo.iUsage & ESgUsageOpenGles2Target)
  1656         {
  1657         {
  1657         potentialUsageBitsMask |= EGL_OPENGL_ES2_BIT;
  1658         potentialUsageBitsMask |= EGL_OPENGL_ES2_BIT;
  1658         }
  1659         }
  1659     
  1660 
  1660     potentialUsageBitsMask = EGL_RENDERABLE_TYPE_value &~ potentialUsageBitsMask;
  1661     potentialUsageBitsMask = EGL_RENDERABLE_TYPE_value &~ potentialUsageBitsMask;
  1661     if(potentialUsageBitsMask)
  1662     if(potentialUsageBitsMask)
  1662         {
  1663         {
  1663         return EFalse;
  1664         return EFalse;
  1664         }
  1665         }
  1665 #endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE	
  1666 #endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
  1666 	return good;
  1667 	return good;
  1667 	}
  1668 	}
  1668 
  1669 
  1669 EXPORT_C TBool  CTestEglSession::CheckNeededExtensionL(TInt aExtension, const TDesC& aExtensionName)
  1670 EXPORT_C TBool  CTestEglSession::CheckNeededExtensionL(TInt aExtension, const TDesC& aExtensionName)
  1670 	{
  1671 	{
  1742             // The extension is not supported
  1743             // The extension is not supported
  1743             return EFalse;
  1744             return EFalse;
  1744             }
  1745             }
  1745         }
  1746         }
  1746 #endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
  1747 #endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
  1747     
  1748 
  1748 	return ETrue;	
  1749 	return ETrue;
  1749 	}
  1750 	}
  1750 
  1751 
  1751 EXPORT_C CFbsBitmap* CTestEglSession::CreateReferenceBitmapL(TDisplayMode aMode)
  1752 EXPORT_C CFbsBitmap* CTestEglSession::CreateReferenceBitmapL(TDisplayMode aMode)
  1752 	{
  1753 	{
  1753 	if(aMode == ENone )
  1754 	if(aMode == ENone )
  1794 	CFbsBitGc* fbsBitGc = CFbsBitGc::NewL();
  1795 	CFbsBitGc* fbsBitGc = CFbsBitGc::NewL();
  1795 	CleanupStack::PushL(fbsBitGc);
  1796 	CleanupStack::PushL(fbsBitGc);
  1796 	fbsBitGc->Activate(bitmapDevice);
  1797 	fbsBitGc->Activate(bitmapDevice);
  1797 	fbsBitGc->SetBrushColor(KRgbBlack);
  1798 	fbsBitGc->SetBrushColor(KRgbBlack);
  1798 	fbsBitGc->Clear();
  1799 	fbsBitGc->Clear();
  1799 	
  1800 
  1800 	// create the penBitmap (same size as the mask bitmap)	
  1801 	// create the penBitmap (same size as the mask bitmap)
  1801 	CFbsBitmap* penBitmap = new(ELeave) CFbsBitmap();
  1802 	CFbsBitmap* penBitmap = new(ELeave) CFbsBitmap();
  1802 	CleanupStack::PushL(penBitmap);
  1803 	CleanupStack::PushL(penBitmap);
  1803 	User::LeaveIfError(penBitmap->Create(aMaskBitmap->SizeInPixels(), aRefBitmapMode));
  1804 	User::LeaveIfError(penBitmap->Create(aMaskBitmap->SizeInPixels(), aRefBitmapMode));
  1804 	CFbsBitmapDevice* penbitmapDevice = CFbsBitmapDevice::NewL(penBitmap);
  1805 	CFbsBitmapDevice* penbitmapDevice = CFbsBitmapDevice::NewL(penBitmap);
  1805 	CleanupStack::PushL(penbitmapDevice);
  1806 	CleanupStack::PushL(penbitmapDevice);
  1808 	penBitGc->Activate(penbitmapDevice);
  1809 	penBitGc->Activate(penbitmapDevice);
  1809 	penBitGc->SetBrushColor(aPenBitmapColor);
  1810 	penBitGc->SetBrushColor(aPenBitmapColor);
  1810 	penBitGc->Clear();
  1811 	penBitGc->Clear();
  1811 
  1812 
  1812 	// perform a masked bitmap transfer to the active refBitmap
  1813 	// perform a masked bitmap transfer to the active refBitmap
  1813 	TRect bmpRect(TPoint(0, 0), refBitmap->SizeInPixels()); 
  1814 	TRect bmpRect(TPoint(0, 0), refBitmap->SizeInPixels());
  1814 	fbsBitGc->Activate(bitmapDevice);
  1815 	fbsBitGc->Activate(bitmapDevice);
  1815 	fbsBitGc->BitBltMasked(TPoint(0, 0), penBitmap, bmpRect, aMaskBitmap, EFalse);	
  1816 	fbsBitGc->BitBltMasked(TPoint(0, 0), penBitmap, bmpRect, aMaskBitmap, EFalse);
  1816 
  1817 
  1817 	CleanupStack::PopAndDestroy(5, bitmapDevice);
  1818 	CleanupStack::PopAndDestroy(5, bitmapDevice);
  1818 	CleanupStack::Pop(refBitmap);
  1819 	CleanupStack::Pop(refBitmap);
  1819 	return refBitmap;
  1820 	return refBitmap;
  1820 	}
  1821 	}
  1828 	User::LeaveIfError(bitmap->Create(aSize,aMode));
  1829 	User::LeaveIfError(bitmap->Create(aSize,aMode));
  1829 
  1830 
  1830 	TInt height = bitmap->SizeInPixels().iHeight;
  1831 	TInt height = bitmap->SizeInPixels().iHeight;
  1831 	TInt width  = bitmap->SizeInPixels().iWidth;
  1832 	TInt width  = bitmap->SizeInPixels().iWidth;
  1832 
  1833 
  1833 	// Initialise colour values to a random value (guarantees pixel uniqueness if update is done accordingly)  
  1834 	// Initialise colour values to a random value (guarantees pixel uniqueness if update is done accordingly)
  1834 	TInt red=0;
  1835 	TInt red=0;
  1835 	TInt green=127;
  1836 	TInt green=127;
  1836 	TInt blue=127;
  1837 	TInt blue=127;
  1837 	TInt alpha=255;
  1838 	TInt alpha=255;
  1838 
  1839 
  1874 					}
  1875 					}
  1875 				default:
  1876 				default:
  1876 					{
  1877 					{
  1877 					// We should not get here - colour mode not supported by these tests
  1878 					// We should not get here - colour mode not supported by these tests
  1878 					ERR_PRINTF1(_L("CTestEglSession::CreateReferenceBitmapL - Colour mode not supported!"));
  1879 					ERR_PRINTF1(_L("CTestEglSession::CreateReferenceBitmapL - Colour mode not supported!"));
  1879 				    ASSERT(FALSE); 
  1880 				    ASSERT(FALSE);
  1880 					}
  1881 					}
  1881 				}
  1882 				}
  1882 			bmpUtil.IncYPos();
  1883 			bmpUtil.IncYPos();
  1883 
  1884 
  1884 			// Update red bit 
  1885 			// Update red bit
  1885 			red = ++red + aIndex; 
  1886 			red = ++red + aIndex;
  1886 			if (red>255) 
  1887 			if (red>255)
  1887 				red = red - 256;
  1888 				red = red - 256;
  1888 			
  1889 
  1889 			// Update green bit
  1890 			// Update green bit
  1890 			green = --green - aIndex; 
  1891 			green = --green - aIndex;
  1891 			if (green<0) 
  1892 			if (green<0)
  1892 				green = green + 256;
  1893 				green = green + 256;
  1893 			
  1894 
  1894 			// Update blue bit
  1895 			// Update blue bit
  1895 			blue = ++blue + aIndex; 
  1896 			blue = ++blue + aIndex;
  1896 			if (blue>255) 
  1897 			if (blue>255)
  1897 				blue = blue - 256;
  1898 				blue = blue - 256;
  1898 			
  1899 
  1899 			// Update alpha bit
  1900 			// Update alpha bit
  1900 			alpha = --alpha - aIndex; 
  1901 			alpha = --alpha - aIndex;
  1901 			if (alpha<0) 
  1902 			if (alpha<0)
  1902 				alpha = alpha + 256;
  1903 				alpha = alpha + 256;
  1903 			}
  1904 			}
  1904 		}
  1905 		}
  1905 	bmpUtil.End();
  1906 	bmpUtil.End();
  1906 	CleanupStack::Pop(bitmap);
  1907 	CleanupStack::Pop(bitmap);
  1914 	TInt width  = aReferenceBitmap->SizeInPixels().iWidth;
  1915 	TInt width  = aReferenceBitmap->SizeInPixels().iWidth;
  1915 
  1916 
  1916 	switch(aDataFormat)
  1917 	switch(aDataFormat)
  1917 		{
  1918 		{
  1918 		case VG_sRGB_565:
  1919 		case VG_sRGB_565:
  1919 			{			
  1920 			{
  1920 			TUint16* vgPixel = new(ELeave) TUint16[width];
  1921 			TUint16* vgPixel = new(ELeave) TUint16[width];
  1921 			CleanupArrayDeletePushL(vgPixel);
  1922 			CleanupArrayDeletePushL(vgPixel);
  1922 			for (TInt y=0; y < height; y++)
  1923 			for (TInt y=0; y < height; y++)
  1923 				{
  1924 				{
  1924                 // Mind the fact that CFbsBitmap and VGImages use different coordinates origin!
  1925                 // Mind the fact that CFbsBitmap and VGImages use different coordinates origin!
  1925                 vgReadPixels(vgPixel, 1, aDataFormat, 0,height-y-1, width,1);
  1926                 vgReadPixels(vgPixel, 1, aDataFormat, 0,height-y-1, width,1);
  1926 				
  1927 
  1927 				for (TInt x=0; x < width; x++)
  1928 				for (TInt x=0; x < width; x++)
  1928 					{
  1929 					{
  1929 					aReferenceBitmap->GetPixel(refPixel, TPoint(x,y));
  1930 					aReferenceBitmap->GetPixel(refPixel, TPoint(x,y));
  1930 					if(!PixelsMatch(refPixel, TRgb::Color64K(vgPixel[x]), EFalse))
  1931 					if(!PixelsMatch(refPixel, TRgb::Color64K(vgPixel[x]), EFalse))
  1931 						{
  1932 						{
  1932 						User::Leave(KErrTEFUnitFail);
  1933 						User::Leave(KErrTEFUnitFail);
  1933 						}
  1934 						}
  1934 					}		
  1935 					}
  1935 				}
  1936 				}
  1936 			CleanupStack::PopAndDestroy(vgPixel);
  1937 			CleanupStack::PopAndDestroy(vgPixel);
  1937 			break;
  1938 			break;
  1938 			}
  1939 			}
  1939 
  1940 
  1940 		case VG_sXRGB_8888:		
  1941 		case VG_sXRGB_8888:
  1941 			{			
  1942 			{
  1942 			TUint32* vgPixel = new(ELeave) TUint32[width];
  1943 			TUint32* vgPixel = new(ELeave) TUint32[width];
  1943 			CleanupArrayDeletePushL(vgPixel);
  1944 			CleanupArrayDeletePushL(vgPixel);
  1944 			for (TInt y=0; y < height; y++)
  1945 			for (TInt y=0; y < height; y++)
  1945 				{
  1946 				{
  1946                 // Mind the fact that CFbsBitmap and VGImages use different coordinates origin!
  1947                 // Mind the fact that CFbsBitmap and VGImages use different coordinates origin!
  1947                 vgReadPixels(vgPixel, 1, aDataFormat, 0,height-y-1, width,1);
  1948                 vgReadPixels(vgPixel, 1, aDataFormat, 0,height-y-1, width,1);
  1948 			
  1949 
  1949 				for (TInt x=0; x < width; x++)
  1950 				for (TInt x=0; x < width; x++)
  1950 					{
  1951 					{
  1951 					aReferenceBitmap->GetPixel(refPixel, TPoint(x,y));
  1952 					aReferenceBitmap->GetPixel(refPixel, TPoint(x,y));
  1952 					if(!PixelsMatch(refPixel, TRgb::Color16MU(vgPixel[x]), EFalse))
  1953 					if(!PixelsMatch(refPixel, TRgb::Color16MU(vgPixel[x]), EFalse))
  1953 						{
  1954 						{
  1954 						User::Leave(KErrTEFUnitFail);
  1955 						User::Leave(KErrTEFUnitFail);
  1955 						}
  1956 						}
  1956 					}		
  1957 					}
  1957 				}
  1958 				}
  1958 			CleanupStack::PopAndDestroy(vgPixel);
  1959 			CleanupStack::PopAndDestroy(vgPixel);
  1959 			break;
  1960 			break;
  1960 			}
  1961 			}
  1961 			
  1962 
  1962 		case VG_sARGB_8888:		
  1963 		case VG_sARGB_8888:
  1963 			{			
  1964 			{
  1964 			TUint32* vgPixel = new(ELeave) TUint32[width];
  1965 			TUint32* vgPixel = new(ELeave) TUint32[width];
  1965 			CleanupArrayDeletePushL(vgPixel);
  1966 			CleanupArrayDeletePushL(vgPixel);
  1966 			for (TInt y=0; y < height; y++)
  1967 			for (TInt y=0; y < height; y++)
  1967 				{
  1968 				{
  1968                 // Mind the fact that CFbsBitmap and VGImages use different coordinates origin!
  1969                 // Mind the fact that CFbsBitmap and VGImages use different coordinates origin!
  1969                 vgReadPixels(vgPixel, 1, aDataFormat, 0,height-y-1, width,1);
  1970                 vgReadPixels(vgPixel, 1, aDataFormat, 0,height-y-1, width,1);
  1970 			
  1971 
  1971 				for (TInt x=0; x < width; x++)
  1972 				for (TInt x=0; x < width; x++)
  1972 					{
  1973 					{
  1973 					aReferenceBitmap->GetPixel(refPixel, TPoint(x,y));
  1974 					aReferenceBitmap->GetPixel(refPixel, TPoint(x,y));
  1974 					if(!PixelsMatch(refPixel, TRgb::Color16MA(vgPixel[x]), ETrue))
  1975 					if(!PixelsMatch(refPixel, TRgb::Color16MA(vgPixel[x]), ETrue))
  1975 						{
  1976 						{
  1976 						User::Leave(KErrTEFUnitFail);
  1977 						User::Leave(KErrTEFUnitFail);
  1977 						}
  1978 						}
  1978 					}		
  1979 					}
  1979 				}
  1980 				}
  1980 			CleanupStack::PopAndDestroy(vgPixel);
  1981 			CleanupStack::PopAndDestroy(vgPixel);
  1981 			break;
  1982 			break;
  1982 			}
  1983 			}
  1983 			
  1984 
  1984 		case VG_sARGB_8888_PRE:		
  1985 		case VG_sARGB_8888_PRE:
  1985 			{			
  1986 			{
  1986 			TUint32* vgPixel = new(ELeave) TUint32[width];
  1987 			TUint32* vgPixel = new(ELeave) TUint32[width];
  1987 			CleanupArrayDeletePushL(vgPixel);
  1988 			CleanupArrayDeletePushL(vgPixel);
  1988 			for (TInt y=0; y < height; y++)
  1989 			for (TInt y=0; y < height; y++)
  1989 				{
  1990 				{
  1990                 // Mind the fact that CFbsBitmap and VGImages use different coordinates origin!
  1991                 // Mind the fact that CFbsBitmap and VGImages use different coordinates origin!
  1991                 vgReadPixels(vgPixel, 1, aDataFormat, 0,height-y-1, width,1);
  1992                 vgReadPixels(vgPixel, 1, aDataFormat, 0,height-y-1, width,1);
  1992                 
  1993 
  1993 				for (TInt x=0; x < width; x++)
  1994 				for (TInt x=0; x < width; x++)
  1994 					{
  1995 					{
  1995 					aReferenceBitmap->GetPixel(refPixel, TPoint(x,y));
  1996 					aReferenceBitmap->GetPixel(refPixel, TPoint(x,y));
  1996 					if(!PixelsMatch(refPixel, TRgb::Color16MAP(vgPixel[x]), ETrue))
  1997 					if(!PixelsMatch(refPixel, TRgb::Color16MAP(vgPixel[x]), ETrue))
  1997 						{
  1998 						{
  1998 						User::Leave(KErrTEFUnitFail);
  1999 						User::Leave(KErrTEFUnitFail);
  1999 						}
  2000 						}
  2000 					}		
  2001 					}
  2001 				}
  2002 				}
  2002 			CleanupStack::PopAndDestroy(vgPixel);
  2003 			CleanupStack::PopAndDestroy(vgPixel);
  2003 			break;
  2004 			break;
  2004 			}
  2005 			}
  2005 
  2006 
  2006 		default:
  2007 		default:
  2007 			// We should not get here - colour mode not supported by these tests
  2008 			// We should not get here - colour mode not supported by these tests
  2008 			ERR_PRINTF1(_L("CTestEglSession::CheckVgDrawingL - Colour mode not supported!"));
  2009 			ERR_PRINTF1(_L("CTestEglSession::CheckVgDrawingL - Colour mode not supported!"));
  2009 		    ASSERT(FALSE); 
  2010 		    ASSERT(FALSE);
  2010 			break;
  2011 			break;
  2011 		}
  2012 		}
  2012 	}
  2013 	}
  2013 
  2014 
  2014 EXPORT_C TBool CTestEglSession::IsOpenGLESSupported() 
  2015 EXPORT_C TBool CTestEglSession::IsOpenGLESSupported()
  2015     { 
  2016     {
  2016     if(!iIsSupportedRenderInitialized)
  2017     if(!iIsSupportedRenderInitialized)
  2017         {
  2018         {
  2018         CheckAllAvailableRenders();
  2019         CheckAllAvailableRenders();
  2019         }
  2020         }
  2020     return iIsOpenGLESSupported;
  2021     return iIsOpenGLESSupported;
  2021     } 
  2022     }
  2022 
  2023 
  2023 EXPORT_C TBool CTestEglSession::IsOpenGLES2Supported() 
  2024 EXPORT_C TBool CTestEglSession::IsOpenGLES2Supported()
  2024     {
  2025     {
  2025     if(!iIsSupportedRenderInitialized)
  2026     if(!iIsSupportedRenderInitialized)
  2026         {
  2027         {
  2027         CheckAllAvailableRenders();
  2028         CheckAllAvailableRenders();
  2028         }
  2029         }
  2029     return iIsOpenGLES2Supported;
  2030     return iIsOpenGLES2Supported;
  2030     }
  2031     }
  2031 EXPORT_C TBool CTestEglSession::IsOpenVGSupported() 
  2032 EXPORT_C TBool CTestEglSession::IsOpenVGSupported()
  2032     {
  2033     {
  2033     if(!iIsSupportedRenderInitialized)
  2034     if(!iIsSupportedRenderInitialized)
  2034         {
  2035         {
  2035         CheckAllAvailableRenders();
  2036         CheckAllAvailableRenders();
  2036         }
  2037         }
  2040 void CTestEglSession::CheckAllAvailableRenders()
  2041 void CTestEglSession::CheckAllAvailableRenders()
  2041     {
  2042     {
  2042     ASSERT_EGL_TRUE(iDisplay != EGL_NO_DISPLAY);
  2043     ASSERT_EGL_TRUE(iDisplay != EGL_NO_DISPLAY);
  2043     TPtrC8 ptrEglClientApis((const TText8 *)eglQueryString(iDisplay, EGL_CLIENT_APIS));
  2044     TPtrC8 ptrEglClientApis((const TText8 *)eglQueryString(iDisplay, EGL_CLIENT_APIS));
  2044     _LIT8(KOpenGLES, "OpenGL_ES");
  2045     _LIT8(KOpenGLES, "OpenGL_ES");
  2045     EGLint numConfigs= 0;       
  2046     EGLint numConfigs= 0;
  2046     EGLConfig config;
  2047     EGLConfig config;
  2047     if(ptrEglClientApis.Find(KOpenGLES) != KErrNotFound)
  2048     if(ptrEglClientApis.Find(KOpenGLES) != KErrNotFound)
  2048         {
  2049         {
  2049         //check GLES2
  2050         //check GLES2
  2050         const EGLint KAttrib_list_gles2[] = { EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
  2051         const EGLint KAttrib_list_gles2[] = { EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
  2067             }
  2068             }
  2068         }
  2069         }
  2069     _LIT8(KOpenVG, "OpenVG");
  2070     _LIT8(KOpenVG, "OpenVG");
  2070     if(ptrEglClientApis.Find(KOpenVG) != KErrNotFound)
  2071     if(ptrEglClientApis.Find(KOpenVG) != KErrNotFound)
  2071         {
  2072         {
  2072         numConfigs= 0;       
  2073         numConfigs= 0;
  2073         //check VG
  2074         //check VG
  2074         const EGLint KAttrib_list_vg[] = { EGL_RENDERABLE_TYPE, EGL_OPENVG_BIT,
  2075         const EGLint KAttrib_list_vg[] = { EGL_RENDERABLE_TYPE, EGL_OPENVG_BIT,
  2075                                            EGL_NONE };
  2076                                            EGL_NONE };
  2076         EGLBoolean eglRes = eglChooseConfig(iDisplay, KAttrib_list_vg, &config,1, &numConfigs);
  2077         EGLBoolean eglRes = eglChooseConfig(iDisplay, KAttrib_list_vg, &config,1, &numConfigs);
  2077         ASSERT_EGL_TRUE(eglRes == EGL_TRUE);
  2078         ASSERT_EGL_TRUE(eglRes == EGL_TRUE);