egl/egltest/src/egltestcommonsession.cpp
changeset 36 01a6848ebfd7
parent 0 5d03bc08d59c
child 45 36b2e23a8629
equal deleted inserted replaced
0:5d03bc08d59c 36:01a6848ebfd7
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
     1 // Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
     2 // All rights reserved.
     2 // All rights reserved.
     3 // This component and the accompanying materials are made available
     3 // This component and the accompanying materials are made available
     4 // under the terms of "Eclipse Public License v1.0"
     4 // under the terms of "Eclipse Public License v1.0"
     5 // which accompanies this distribution, and is available
     5 // which accompanies this distribution, and is available
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
    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 		TSgImageInfoOpenVgTarget imageInfo;
   203 		// The created surface will remain un-used, hence we create it with an arbitrary pixel format 
   204 		imageInfo.iSizeInPixels = KPixmapSize;
   204         EGLConfig currentConfig = GetConfigExactMatchL(EPBufferAttribsColor64K);
   205 		imageInfo.iPixelFormat = EUidPixelFormatXRGB_8888;
   205         CreatePbufferSurfaceAndMakeCurrentL(currentConfig, TSize(1,1), EGL_OPENVG_API);
   206 #ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
       
   207 		imageInfo.iUsage = ESgUsageBitOpenVgSurface;
       
   208 #else
       
   209         imageInfo.iUsage = ESgUsageOpenVgTarget;
       
   210 #endif		
       
   211 		CreatePixmapSurfaceAndMakeCurrentAndMatchL(imageInfo,CTestEglSession::EResourceCloseSgImageEarly);
       
   212 
   206 
   213 		extensionsString = (const char*) vgGetString(VG_EXTENSIONS);
   207 		extensionsString = (const char*) vgGetString(VG_EXTENSIONS);
   214 
   208 
   215 		//cleanup the context & surface
   209 		//cleanup the context & surface
   216 		CleanupSurfaceSgImageL();
   210 		CleanupSurfaceSgImageL();
   218 	else
   212 	else
   219 		{
   213 		{
   220 		ERR_PRINTF2(_L("CTestEglSession::QueryExtensionsL() - Unknown extension group provided (%d)."), aExtensionBelongsTo);
   214 		ERR_PRINTF2(_L("CTestEglSession::QueryExtensionsL() - Unknown extension group provided (%d)."), aExtensionBelongsTo);
   221 		User::Leave(KErrArgument);
   215 		User::Leave(KErrArgument);
   222 		}
   216 		}
   223 	CHECK_EXPECTED_ERROR(extensionsString!=NULL);	
   217 	CHECK_EXPECTED_ERROR(extensionsString!=NULL);
   224 	
   218 
   225 	TPtrC8 ptrExtensions((const TUint8 *) extensionsString );
   219 	TPtrC8 ptrExtensions((const TUint8 *) extensionsString );
   226 	TBuf16<128> bufExtensions;
   220 
   227 	bufExtensions.Copy(ptrExtensions.Left(128));
   221 	RBuf buffer;
   228 	INFO_PRINTF3(_L("thread %d: QueryExtensionsL: \"%S\""), iThreadIdx, &bufExtensions);
   222     buffer.CreateL(ptrExtensions.Length());
   229 	
   223     buffer.CleanupClosePushL();
       
   224     buffer.Copy(ptrExtensions);
       
   225 	INFO_PRINTF3(_L("thread %d: QueryExtensionsL: \"%S\""), iThreadIdx, &buffer);
       
   226     CleanupStack::PopAndDestroy(&buffer);
       
   227 
   230 	TInt posSpace=1;
   228 	TInt posSpace=1;
   231 	while (posSpace > 0 && ptrExtensions.Length() > 0)
   229 	while (posSpace > 0 && ptrExtensions.Length() > 0)
   232 		{
   230 		{
   233 		posSpace = ptrExtensions.Locate(' '); // strictly looking for a single space
   231 		posSpace = ptrExtensions.Locate(' '); // strictly looking for a single space
   234 		ASSERT_FALSE(posSpace==0); // Would imply extension starting with a space or with 2 spaces in a row
   232 		ASSERT_FALSE(posSpace==0); // Would imply extension starting with a space or with 2 spaces in a row
   242 			}
   240 			}
   243 		else
   241 		else
   244 			{
   242 			{
   245 			iExtensionStrings.Append(ptrExtensions);
   243 			iExtensionStrings.Append(ptrExtensions);
   246 			}
   244 			}
   247 		} 
   245 		}
   248 	}
   246 	}
   249 
   247 
   250 TBool CTestEglSession::FindExtensionStringL(TExtensionsGroups aExtensionBelongsTo, const TDesC8& aExtensionString)
   248 TBool CTestEglSession::FindExtensionStringL(TExtensionsGroups aExtensionBelongsTo, const TDesC8& aExtensionString)
   251 	{
   249 	{
   252 	//Load the extensions for this group if not already cached
   250 	//Load the extensions for this group if not already cached
   253 	if (iExtensionGroupCached != aExtensionBelongsTo)
   251 	if (iExtensionGroupCached != aExtensionBelongsTo)
   254 		{
   252 		{
   255 		QueryExtensionsL(aExtensionBelongsTo); // Load extension info
   253 		QueryExtensionsL(aExtensionBelongsTo); // Load extension info
   256 		iExtensionGroupCached = aExtensionBelongsTo;
   254 		iExtensionGroupCached = aExtensionBelongsTo;
   257 		}
   255 		}
   258 	
   256 
   259 	TInt countExtensionStrings = iExtensionStrings.Count();
   257 	TInt countExtensionStrings = iExtensionStrings.Count();
   260 	for(TUint i=0; i<countExtensionStrings; i++)
   258 	for(TUint i=0; i<countExtensionStrings; i++)
   261 		{
   259 		{
   262 		if (iExtensionStrings[i].Compare(aExtensionString)==0)
   260 		if (iExtensionStrings[i].Compare(aExtensionString)==0)
   263 			{
   261 			{
   268 
   266 
   269 	// 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
   270 	const TInt KBufLenMissingExtension=128;
   268 	const TInt KBufLenMissingExtension=128;
   271 	TBuf16<KBufLenMissingExtension> bufMissingExtension16;
   269 	TBuf16<KBufLenMissingExtension> bufMissingExtension16;
   272 	bufMissingExtension16.Copy(aExtensionString.Left(KBufLenMissingExtension));
   270 	bufMissingExtension16.Copy(aExtensionString.Left(KBufLenMissingExtension));
   273 	
   271 
   274 	WARN_PRINTF2(_L("EGL extension missing: [%S]"), &bufMissingExtension16);
   272 	WARN_PRINTF2(_L("EGL extension missing: [%S]"), &bufMissingExtension16);
   275 	return EFalse;
   273 	return EFalse;
   276 	}
   274 	}
   277 
   275 
   278 /**
   276 /**
   298 	CHECK_EXPECTED_ERROR(eglGetConfigs(iDisplay, NULL, KMaxTInt, &numConfigs));
   296 	CHECK_EXPECTED_ERROR(eglGetConfigs(iDisplay, NULL, KMaxTInt, &numConfigs));
   299 
   297 
   300 	INFO_PRINTF1(_L("Checking number of configs..."));
   298 	INFO_PRINTF1(_L("Checking number of configs..."));
   301 	ASSERT_TRUE(numConfigs >= 1);
   299 	ASSERT_TRUE(numConfigs >= 1);
   302 	INFO_PRINTF2(_L("Found %d configs"), numConfigs);
   300 	INFO_PRINTF2(_L("Found %d configs"), numConfigs);
   303 	
   301 
   304 	// Get the configs
   302 	// Get the configs
   305 	INFO_PRINTF1(_L("Calling eglGetConfigs to get configs..."));
   303 	INFO_PRINTF1(_L("Calling eglGetConfigs to get configs..."));
   306 	CHECK_EXPECTED_ERROR(eglGetConfigs(iDisplay, configs, KMaxEglConfigs, &numConfigs));
   304 	CHECK_EXPECTED_ERROR(eglGetConfigs(iDisplay, configs, KMaxEglConfigs, &numConfigs));
   307 	
   305 
   308 	for(TUint index = 0; index < numConfigs; index++)
   306 	for(TUint index = 0; index < numConfigs; index++)
   309 		{
   307 		{
   310 		EGLint EGL_BUFFER_SIZE_value;
   308 		EGLint EGL_BUFFER_SIZE_value;
   311 		EGLint EGL_ALPHA_SIZE_value;
   309 		EGLint EGL_ALPHA_SIZE_value;
   312 		EGLint EGL_BLUE_SIZE_value;
   310 		EGLint EGL_BLUE_SIZE_value;
   379 #endif
   377 #endif
   380 		eglGetConfigAttrib(iDisplay, configs[index], EGL_RENDERABLE_TYPE, &EGL_RENDERABLE_TYPE_value);
   378 		eglGetConfigAttrib(iDisplay, configs[index], EGL_RENDERABLE_TYPE, &EGL_RENDERABLE_TYPE_value);
   381 
   379 
   382 		TBool good = ETrue;
   380 		TBool good = ETrue;
   383 
   381 
   384 		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,
   385 				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,
   386 				EGL_ALPHA_SIZE_value);
   384 				EGL_ALPHA_SIZE_value);
   387 		if (!(EGL_RED_SIZE_value == 8 && EGL_GREEN_SIZE_value == 8 && EGL_BLUE_SIZE_value == 8 && EGL_ALPHA_SIZE_value == 0))
   385 		if (!(EGL_RED_SIZE_value == 8 && EGL_GREEN_SIZE_value == 8 && EGL_BLUE_SIZE_value == 8 && EGL_ALPHA_SIZE_value == 0))
   388 			{
   386 			{
   389 			continue;
   387 			continue;
   390 			}
   388 			}
   391 		
   389 
   392 		INFO_PRINTF2(_L("\n\n^^^^^^ CONFIG [%d] VALUES ******"), index);
   390 		INFO_PRINTF2(_L("\n\n^^^^^^ CONFIG [%d] VALUES ******"), index);
   393 		if (EGL_SURFACE_TYPE_value & EGL_PIXMAP_BIT)
   391 		if (EGL_SURFACE_TYPE_value & EGL_PIXMAP_BIT)
   394 			{
   392 			{
   395 			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);
   396 			}
   394 			}
   397 		else
   395 		else
   398 			{
   396 			{
   399 			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);
   400 			good = EFalse;
   398 			good = EFalse;
   401 			}
   399 			}
   402 		
   400 
   403 		if (EGL_RENDERABLE_TYPE_value & EGL_OPENVG_BIT)
   401 		if (EGL_RENDERABLE_TYPE_value & EGL_OPENVG_BIT)
   404 			{
   402 			{
   405 			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);
   406 			}
   404 			}
   407 		else
   405 		else
   408 			{
   406 			{
   409 			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);
   410 			good = EFalse;
   408 			good = EFalse;
   411 			}
   409 			}
   412 		
   410 
   413 		if (good)
   411 		if (good)
   414 			{
   412 			{
   415 			INFO_PRINTF1(_L("^^^^^^^ GOOD ^^^^^^^"));
   413 			INFO_PRINTF1(_L("^^^^^^^ GOOD ^^^^^^^"));
   416 			}
   414 			}
   417 
   415 
   451 		INFO_PRINTF2(_L("\n*********************************\n\n"), index);
   449 		INFO_PRINTF2(_L("\n*********************************\n\n"), index);
   452 #endif
   450 #endif
   453 		}
   451 		}
   454 	}
   452 	}
   455 
   453 
   456 EXPORT_C static TEglConfigMatchType GetMatchType(EGLint aAttrib, TEglConfigMatchRule aMatchRule)
   454 EXPORT_C TEglConfigMatchType GetMatchType(EGLint aAttrib, TEglConfigMatchRule aMatchRule)
   457 	{
   455 	{
   458 	const TConfigMatchRuleItem* curMatchRuleItem = KConfigMatchRules[aMatchRule];
   456 	const TConfigMatchRuleItem* curMatchRuleItem = KConfigMatchRules[aMatchRule];
   459 			
   457 
   460 	while(curMatchRuleItem->iAttrib != EGL_NONE)
   458 	while(curMatchRuleItem->iAttrib != EGL_NONE)
   461 		{
   459 		{
   462 		if (aAttrib == curMatchRuleItem->iAttrib)
   460 		if (aAttrib == curMatchRuleItem->iAttrib)
   463 			{
   461 			{
   464 			return curMatchRuleItem->iMatchType;
   462 			return curMatchRuleItem->iMatchType;
   471 	}
   469 	}
   472 
   470 
   473 /**
   471 /**
   474  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
   475  */
   473  */
   476 TInt CTestEglSession::GetFullMatchConfigIndex(EGLDisplay aDisplay, EGLConfig *aConfigs, TInt aNumConfigs, 
   474 TInt CTestEglSession::GetFullMatchConfigIndex(EGLDisplay aDisplay, EGLConfig *aConfigs, TInt aNumConfigs,
   477 											  const EGLint aWantedAttribs[], TEglConfigMatchRule aMatchRule)
   475 											  const EGLint aWantedAttribs[], TEglConfigMatchRule aMatchRule)
   478 	{
   476 	{
   479 	EGLint value=0;
   477 	EGLint value=0;
   480 	for(TUint idxConfig=0; idxConfig<aNumConfigs; idxConfig++)
   478 	for(TUint idxConfig=0; idxConfig<aNumConfigs; idxConfig++)
   481 		{
   479 		{
   482 		const EGLint *curAttrib = aWantedAttribs;
   480 		const EGLint *curAttrib = aWantedAttribs;
   483 		TBool match = ETrue;
   481 		TBool match = ETrue;
   484 		
   482 
   485 		while(*curAttrib != EGL_NONE && match)
   483 		while(*curAttrib != EGL_NONE && match)
   486 			{
   484 			{
   487 			ASSERT_EGL_TRUE(eglGetConfigAttrib(aDisplay, aConfigs[idxConfig], *curAttrib, &value));
   485 			ASSERT_EGL_TRUE(eglGetConfigAttrib(aDisplay, aConfigs[idxConfig], *curAttrib, &value));
   488 
   486 
   489 			switch(GetMatchType(*curAttrib, aMatchRule))
   487 			switch(GetMatchType(*curAttrib, aMatchRule))
   490 				{
   488 				{
   491 				case eMatchEqual:
   489 				case eMatchEqual:
   492 					if (value != curAttrib[1])
   490 					if (value != curAttrib[1])
   493 						{
   491 						{
   494 						match = EFalse;
   492 						match = EFalse;
   495 						}		
   493 						}
   496 					break;
   494 					break;
   497 				case eMatchAtLeast:
   495 				case eMatchAtLeast:
   498 					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 ">="!
   499 						{
   497 						{
   500 						match = EFalse;
   498 						match = EFalse;
   506 						match = EFalse;
   504 						match = EFalse;
   507 						}
   505 						}
   508 					break;
   506 					break;
   509 				case eMatchAlways:
   507 				case eMatchAlways:
   510 				    break;
   508 				    break;
   511 				    
   509 
   512 				default:
   510 				default:
   513 					// We should not get here.
   511 					// We should not get here.
   514 				    ASSERT(FALSE); 
   512 				    ASSERT(FALSE);
   515 				    break;
   513 				    break;
   516 				}
   514 				}
   517 			curAttrib += 2;
   515 			curAttrib += 2;
   518 			}
   516 			}
   519 		
   517 
   520 		// 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.
   521 		if (match) 
   519 		if (match)
   522 			{
   520 			{
   523 			return idxConfig;
   521 			return idxConfig;
   524 			}
   522 			}
   525 		}
   523 		}
   526 	return KErrNotFound;
   524 	return KErrNotFound;
   537 	}
   535 	}
   538 
   536 
   539 /**
   537 /**
   540  Returns pixel format inforamtion for a given EGL config.
   538  Returns pixel format inforamtion for a given EGL config.
   541  @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.
   542  @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.
   543          Tf the config cannot be mapped, then NULL is returned.
   541          Tf the config cannot be mapped, then NULL is returned.
   544  */
   542  */
   545 EXPORT_C const TMapEglConfigToPixelFormat* CTestEglSession::GetPixelFormatFromEglConfigL(EGLConfig aConfig)
   543 EXPORT_C const TMapEglConfigToPixelFormat* CTestEglSession::GetPixelFormatFromEglConfigL(EGLConfig aConfig)
   546 	{
   544 	{
   547 	EGLint bufferSize=0;
   545 	EGLint bufferSize=0;
   559 	CHECK_EXPECTED_ERROR(eglGetConfigAttrib(iDisplay, aConfig, EGL_BLUE_SIZE, &blueSize));
   557 	CHECK_EXPECTED_ERROR(eglGetConfigAttrib(iDisplay, aConfig, EGL_BLUE_SIZE, &blueSize));
   560 	CHECK_EXPECTED_ERROR(eglGetConfigAttrib(iDisplay, aConfig, EGL_COLOR_BUFFER_TYPE, &colorBufferType));
   558 	CHECK_EXPECTED_ERROR(eglGetConfigAttrib(iDisplay, aConfig, EGL_COLOR_BUFFER_TYPE, &colorBufferType));
   561 	CHECK_EXPECTED_ERROR(eglGetConfigAttrib(iDisplay, aConfig, EGL_SURFACE_TYPE, &surfaceType));
   559 	CHECK_EXPECTED_ERROR(eglGetConfigAttrib(iDisplay, aConfig, EGL_SURFACE_TYPE, &surfaceType));
   562 
   560 
   563 	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);
   564 	
   562 
   565 	for(TUint i=0; i<ConfigToPixelFormatTableLength(); i++)
   563 	for(TUint i=0; i<ConfigToPixelFormatTableLength(); i++)
   566 		{
   564 		{
   567 		if ((ConfigToPixelFormatTable(i).iBufferSize == bufferSize)
   565 		if ((ConfigToPixelFormatTable(i).iBufferSize == bufferSize)
   568 				&& (ConfigToPixelFormatTable(i).iAlphaSize == alphaSize)
   566 				&& (ConfigToPixelFormatTable(i).iAlphaSize == alphaSize)
   569 				&& (ConfigToPixelFormatTable(i).iRedSize == redSize)
   567 				&& (ConfigToPixelFormatTable(i).iRedSize == redSize)
   630 	if(aConfigAttribIndex >= EEglTestConfigMax )
   628 	if(aConfigAttribIndex >= EEglTestConfigMax )
   631 		{
   629 		{
   632 		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"));
   633 		User::Leave(KErrArgument);
   631 		User::Leave(KErrArgument);
   634 		}
   632 		}
   635 	
   633 
   636 	EGLConfig configs[KMaxEglConfigs];
   634 	EGLConfig configs[KMaxEglConfigs];
   637 	EGLint numConfigs=0;
   635 	EGLint numConfigs=0;
   638 	ASSERT_EGL_TRUE(eglChooseConfig(iDisplay, KConfigAttribs[aConfigAttribIndex], configs, KMaxEglConfigs, &numConfigs));
   636 	ASSERT_EGL_TRUE(eglChooseConfig(iDisplay, KConfigAttribs[aConfigAttribIndex], configs, KMaxEglConfigs, &numConfigs));
   639 	if (numConfigs <= 0)
   637 	if (numConfigs <= 0)
   640 		{
   638 		{
   641 		// 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)
   642 		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!"));
   643 		User::Leave(KTestNoMatchingConfig);
   641 		User::Leave(KTestNoMatchingConfig);
   644 		}
   642 		}
   645 	
   643 
   646 	// Check that any of the configs returned matches the desired attributes
   644 	// Check that any of the configs returned matches the desired attributes
   647 	TInt match = GetFullMatchConfigIndex(iDisplay, configs, numConfigs, KConfigAttribs[aConfigAttribIndex], aMatchRule);
   645 	TInt match = GetFullMatchConfigIndex(iDisplay, configs, numConfigs, KConfigAttribs[aConfigAttribIndex], aMatchRule);
   648 	if (match == KErrNotFound)
   646 	if (match == KErrNotFound)
   649 		{
   647 		{
   650 		// 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)
   669 */
   667 */
   670 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)
   671 	{
   669 	{
   672 	CreatePixmapSurfaceAndMakeCurrentL(aConfig, aSize, aDisplayMode);
   670 	CreatePixmapSurfaceAndMakeCurrentL(aConfig, aSize, aDisplayMode);
   673 	DrawOpenVgL();
   671 	DrawOpenVgL();
   674 	
   672 
   675 	// Wait for the drawing to complete
   673 	// Wait for the drawing to complete
   676 	eglWaitClient();
   674 	eglWaitClient();
   677 	
   675 
   678 	CheckImageDataL(iFbsBitmap);
   676 	CheckImageDataL(iFbsBitmap);
   679 	CheckImageDataVgL(VG_sRGB_565);
   677 	CheckImageDataVgL(VG_sRGB_565);
   680 	CleanupSurfaceFbsBitmapL();
   678 	CleanupSurfaceFbsBitmapL();
   681 	CloseFbsSession();
   679 	CloseFbsSession();
   682 	}
   680 	}
   686 */
   684 */
   687 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)
   688 	{
   686 	{
   689 	CreatePixmapSurfaceAndMakeCurrentL(aConfig, aSize, aDisplayMode,EGL_OPENGL_ES_API, aRenderVersion);
   687 	CreatePixmapSurfaceAndMakeCurrentL(aConfig, aSize, aDisplayMode,EGL_OPENGL_ES_API, aRenderVersion);
   690 	DrawOpenGLesL();
   688 	DrawOpenGLesL();
   691 	
   689 
   692 	// Wait for the drawing to complete
   690 	// Wait for the drawing to complete
   693 	eglWaitClient();
   691 	eglWaitClient();
   694 	
   692 
   695 	CheckImageDataFullRedishL(iFbsBitmap);
   693 	CheckImageDataFullRedishL(iFbsBitmap);
   696 	CleanupSurfaceFbsBitmapL();
   694 	CleanupSurfaceFbsBitmapL();
   697 	CloseFbsSession();
   695 	CloseFbsSession();
   698 	}
   696 	}
   699 
   697 
   705 	INFO_PRINTF2(_L("thread %d: TryUsePixmapRSgImageL"), iThreadIdx);
   703 	INFO_PRINTF2(_L("thread %d: TryUsePixmapRSgImageL"), iThreadIdx);
   706 	TSgImageInfo imageInfo;
   704 	TSgImageInfo imageInfo;
   707 	imageInfo.iSizeInPixels = KPixmapSize;
   705 	imageInfo.iSizeInPixels = KPixmapSize;
   708 	imageInfo.iPixelFormat = EUidPixelFormatXRGB_8888;
   706 	imageInfo.iPixelFormat = EUidPixelFormatXRGB_8888;
   709 	// will draw to and read from the image using OpenVg
   707 	// will draw to and read from the image using OpenVg
   710 #ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE	
   708 #ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
   711 	imageInfo.iUsage = ESgUsageBitOpenVgSurface | ESgUsageBitOpenVgImage;
   709 	imageInfo.iUsage = ESgUsageBitOpenVgSurface | ESgUsageBitOpenVgImage;
   712 #else
   710 #else
   713     // will also read from the image using DirectGdi
   711     // will also read from the image using DirectGdi
   714     imageInfo.iUsage = ESgUsageOpenVgTarget | ESgUsageDirectGdiSource;
   712     imageInfo.iUsage = ESgUsageOpenVgTarget | ESgUsageDirectGdiSource;
   715     imageInfo.iShareable = EFalse;
   713     imageInfo.iShareable = EFalse;
   718     imageInfo.iUserAttributes = NULL;
   716     imageInfo.iUserAttributes = NULL;
   719     imageInfo.iUserAttributeCount=0;
   717     imageInfo.iUserAttributeCount=0;
   720 #endif
   718 #endif
   721 	CreatePixmapSurfaceAndMakeCurrentAndMatchL(imageInfo, EResourceCloseSgImageLate);
   719 	CreatePixmapSurfaceAndMakeCurrentAndMatchL(imageInfo, EResourceCloseSgImageLate);
   722 	DrawOpenVgL();
   720 	DrawOpenVgL();
   723 	            
   721 
   724 	// Wait for the drawing to complete
   722 	// Wait for the drawing to complete
   725 	 eglWaitClient();
   723 	 eglWaitClient();
   726 	    
   724 
   727 	//we can't retrieve data directly from the SgImage as 
   725 	//we can't retrieve data directly from the SgImage as
   728 	//non-unified architecture doesn't allow readback from the GPU
   726 	//non-unified architecture doesn't allow readback from the GPU
   729 	CheckImageDataVgL(VG_sXRGB_8888);
   727 	CheckImageDataVgL(VG_sXRGB_8888);
   730 	CleanupSurfaceSgImageL();
   728 	CleanupSurfaceSgImageL();
   731 	CloseSgDriver();
   729 	CloseSgDriver();
   732 	}
   730 	}
   733 
   731 
   734 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)
   735 	{
   733 	{
   736 	CreatePixmapSurfaceAndMakeCurrentL(aConfig, aImageInfo, aResourceCloseRule ,EGL_OPENGL_ES_API, aRenderVersion);
   734 	CreatePixmapSurfaceAndMakeCurrentL(aConfig, aImageInfo, aResourceCloseRule ,EGL_OPENGL_ES_API, aRenderVersion);
   737 		
   735 
   738 	DrawOpenGLesL();
   736 	DrawOpenGLesL();
   739 			
   737 
   740 	// Wait for the drawing to complete
   738 	// Wait for the drawing to complete
   741 	eglWaitClient();
   739 	eglWaitClient();
   742 
   740 
   743 	//we can't retrieve data directly from SgImage as non-unified 
   741 	//we can't retrieve data directly from SgImage as non-unified
   744 	//architecture doesn't allow readback from the GPU
   742 	//architecture doesn't allow readback from the GPU
   745 	
   743 
   746 	if (aImageInfo.iPixelFormat == EUidPixelFormatXRGB_8888  || 
   744 	if (aImageInfo.iPixelFormat == EUidPixelFormatXRGB_8888  ||
   747 		aImageInfo.iPixelFormat == EUidPixelFormatARGB_8888_PRE)
   745 		aImageInfo.iPixelFormat == EUidPixelFormatARGB_8888_PRE)
   748 		{	
   746 		{
   749 		CheckImageDataGLesL();
   747 		CheckImageDataGLesL();
   750 		}
   748 		}
   751 
   749 
   752 	CleanupSurfaceSgImageL();
   750 	CleanupSurfaceSgImageL();
   753 	CloseSgDriver();
   751 	CloseSgDriver();
   765 @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
   766 */
   764 */
   767 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)
   768 	{
   766 	{
   769 	CreatePixmapSurfaceAndMakeCurrentL(aConfig, aImageInfo, aResourceCloseRule);
   767 	CreatePixmapSurfaceAndMakeCurrentL(aConfig, aImageInfo, aResourceCloseRule);
   770 		
   768 
   771 	DrawOpenVgL();
   769 	DrawOpenVgL();
   772 			
   770 
   773 	// Wait for the drawing to complete
   771 	// Wait for the drawing to complete
   774 	eglWaitClient();
   772 	eglWaitClient();
   775 	
   773 
   776 	//we can't retrieve data directly from the SgImage as 
   774 	//we can't retrieve data directly from the SgImage as
   777 	//non-unified architecture doesn't allow readback from the GPU
   775 	//non-unified architecture doesn't allow readback from the GPU
   778 	CheckImageDataVgL(VG_sXRGB_8888);
   776 	CheckImageDataVgL(VG_sXRGB_8888);
   779 	CleanupSurfaceSgImageL();
   777 	CleanupSurfaceSgImageL();
   780 	CloseSgDriver();
   778 	CloseSgDriver();
   781 	return ETrue;
   779 	return ETrue;
   782 	}
   780 	}
   783 
   781 
   784 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)
   785 	{
   783 	{
   786 	ASSERT_EQUALS(iSurface, EGL_NO_SURFACE);
   784 	ASSERT_EQUALS(iSurface, EGL_NO_SURFACE);
   787 	ASSERT_EQUALS(iContext, EGL_NO_CONTEXT);
   785 	ASSERT_EQUALS(iContext, EGL_NO_CONTEXT);
   788 	
   786 
   789 	ASSERT_EGL_TRUE(eglBindAPI(aBindAPI));
   787 	ASSERT_EGL_TRUE(eglBindAPI(aBindAPI));
   790 		
   788 
   791 	// Create a Window surface from the native image
   789 	// Create a Window surface from the native image
   792 	EGLint EGL_RENDERABLE_TYPE_value = 0;
   790 	const EGLint* windowAttribs = (aVgAlphaFormatPre && aBindAPI == EGL_OPENVG_API) ? KPixmapAttribsVgAlphaFormatPre : KPixmapAttribsNone;
   793 	ASSERT_EGL_TRUE(eglGetConfigAttrib(iDisplay, aConfig, EGL_RENDERABLE_TYPE, &EGL_RENDERABLE_TYPE_value));
   791 	iSurface = eglCreateWindowSurface(iDisplay, aConfig, &aWindow, windowAttribs);
   794 	const EGLint* pixmapAttribs = ((aWindow.DisplayMode() == EColor16MAP) && (EGL_RENDERABLE_TYPE_value & EGL_OPENVG_BIT)) ? KPixmapAttribsVgAlphaFormatPre : KPixmapAttribsNone;
       
   795 	iSurface = eglCreateWindowSurface(iDisplay, aConfig, &aWindow, pixmapAttribs);
       
   796 	ASSERT_EGL_TRUE(iSurface != EGL_NO_SURFACE);
   792 	ASSERT_EGL_TRUE(iSurface != EGL_NO_SURFACE);
   797 
   793 
   798 	// 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
   799 	const EGLint KAttribsListCtxNone[] = { EGL_NONE };;
   795 	const EGLint KAttribsListCtxNone[] = { EGL_NONE };;
   800 	const EGLint KAttribsListCtxGles2[] = { EGL_CONTEXT_CLIENT_VERSION, aRenderVersionNumber, EGL_NONE };
   796 	const EGLint KAttribsListCtxGles2[] = { EGL_CONTEXT_CLIENT_VERSION, aRenderVersionNumber, EGL_NONE };
   801 	const EGLint* attrib_list_ctx = (aBindAPI == EGL_OPENGL_ES_API && aRenderVersionNumber == 2) ? KAttribsListCtxGles2 : KAttribsListCtxNone; 
   797 	const EGLint* attrib_list_ctx = (aBindAPI == EGL_OPENGL_ES_API && aRenderVersionNumber == 2) ? KAttribsListCtxGles2 : KAttribsListCtxNone;
   802 	iContext = eglCreateContext(iDisplay, aConfig, EGL_NO_CONTEXT, attrib_list_ctx);
   798 	iContext = eglCreateContext(iDisplay, aConfig, EGL_NO_CONTEXT, attrib_list_ctx);
   803 	ASSERT_EGL_TRUE(iContext != EGL_NO_CONTEXT);	
   799 	ASSERT_EGL_TRUE(iContext != EGL_NO_CONTEXT);
   804 	ASSERT_EGL_TRUE(eglMakeCurrent(iDisplay, iSurface, iSurface, iContext));
   800 	ASSERT_EGL_TRUE(eglMakeCurrent(iDisplay, iSurface, iSurface, iContext));
   805 	}
   801 	}
   806 
   802 
   807 
   803 
   808 EXPORT_C TBool CTestEglSession::CongfigSupportsOpenVgL(EGLConfig aConfig)
   804 EXPORT_C TBool CTestEglSession::CongfigSupportsOpenVgL(EGLConfig aConfig)
   814 
   810 
   815 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)
   816 	{
   812 	{
   817 	ASSERT_EQUALS(iSurface, EGL_NO_SURFACE);
   813 	ASSERT_EQUALS(iSurface, EGL_NO_SURFACE);
   818 	ASSERT_EQUALS(iContext, EGL_NO_CONTEXT);
   814 	ASSERT_EQUALS(iContext, EGL_NO_CONTEXT);
   819 	
   815 
   820     OpenSgDriverL();
   816     OpenSgDriverL();
   821     ASSERT_EQUALS(iSgImage.Create(aImageInfo, NULL, 0), KErrNone);
   817     ASSERT_EQUALS(iSgImage.Create(aImageInfo, NULL, 0), KErrNone);
   822 
   818 
   823 	EGLint renderableType = 0;
   819 	EGLint renderableType = 0;
   824 	if(aBindAPI == EGL_OPENVG_API)
   820 	if(aBindAPI == EGL_OPENVG_API)
   836 	else
   832 	else
   837 		{
   833 		{
   838 		ERR_PRINTF1(_L("CreatePixmapSurfaceAndMakeCurrentAndMatchL - Unkown API requested!"));
   834 		ERR_PRINTF1(_L("CreatePixmapSurfaceAndMakeCurrentAndMatchL - Unkown API requested!"));
   839 		User::Leave(KErrArgument);
   835 		User::Leave(KErrArgument);
   840 		}
   836 		}
   841 	EGLint attrib_list[] = { 
   837 	EGLint attrib_list[] = {
   842 			  EGL_MATCH_NATIVE_PIXMAP,(TInt)&iSgImage,
   838 			  EGL_MATCH_NATIVE_PIXMAP,(TInt)&iSgImage,
   843 			  EGL_RENDERABLE_TYPE,renderableType,
   839 			  EGL_RENDERABLE_TYPE,renderableType,
   844 			  EGL_SURFACE_TYPE,EGL_PIXMAP_BIT,
   840 			  EGL_SURFACE_TYPE,EGL_PIXMAP_BIT,
   845 			  EGL_NONE};
   841 			  EGL_NONE};
   846 
   842 
   863 	EGLint EGL_RENDERABLE_TYPE_value = 0;
   859 	EGLint EGL_RENDERABLE_TYPE_value = 0;
   864 	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));
   865 	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;
   866 	iSurface = eglCreatePixmapSurface(iDisplay, config, &iSgImage, pixmapAttribs);
   862 	iSurface = eglCreatePixmapSurface(iDisplay, config, &iSgImage, pixmapAttribs);
   867 	ASSERT_EGL_TRUE(iSurface != EGL_NO_SURFACE);
   863 	ASSERT_EGL_TRUE(iSurface != EGL_NO_SURFACE);
   868 	
   864 
   869 	if (aResourceCloseRule == EResourceCloseSgImageEarly)
   865 	if (aResourceCloseRule == EResourceCloseSgImageEarly)
   870 		{
   866 		{
   871 		// 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
   872 		// 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.
   873 		iSgImage.Close();
   869 		iSgImage.Close();
   874 		}
   870 		}
   875 	
   871 
   876 	if (aResourceCloseRule == EResourceCloseSgDriverAndImageEarly)
   872 	if (aResourceCloseRule == EResourceCloseSgDriverAndImageEarly)
   877 		{
   873 		{
   878 		// 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
   879 		// 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
   880 		// been closed.
   876 		// been closed.
   881 		iSgImage.Close();
   877 		iSgImage.Close();
   882 		CloseSgDriver();		
   878 		CloseSgDriver();
   883 		}
   879 		}
   884 
   880 
   885 	// 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
   886 	const EGLint KAttribsListCtxNone[] = { EGL_NONE };;
   882 	const EGLint KAttribsListCtxNone[] = { EGL_NONE };
   887 	const EGLint KAttribsListCtxGles2[] = { EGL_CONTEXT_CLIENT_VERSION, aRenderVersionNumber, EGL_NONE };
   883 	const EGLint KAttribsListCtxGles2[] = { EGL_CONTEXT_CLIENT_VERSION, aRenderVersionNumber, EGL_NONE };
   888 	const EGLint* attrib_list_ctx = (aBindAPI == EGL_OPENGL_ES_API && aRenderVersionNumber == 2) ? KAttribsListCtxGles2 : KAttribsListCtxNone; 
   884 	const EGLint* attrib_list_ctx = (aBindAPI == EGL_OPENGL_ES_API && aRenderVersionNumber == 2) ? KAttribsListCtxGles2 : KAttribsListCtxNone; 
   889 	iContext = eglCreateContext(iDisplay, config, EGL_NO_CONTEXT, attrib_list_ctx);
   885 	iContext = eglCreateContext(iDisplay, config, EGL_NO_CONTEXT, attrib_list_ctx);
   890 	ASSERT_EGL_TRUE(iContext != EGL_NO_CONTEXT);	
   886 	ASSERT_EGL_TRUE(iContext != EGL_NO_CONTEXT);	
   891 	ASSERT_EGL_TRUE(eglMakeCurrent(iDisplay, iSurface, iSurface, iContext));
   887 	ASSERT_EGL_TRUE(eglMakeCurrent(iDisplay, iSurface, iSurface, iContext));
   892 	}
   888 	}
   893 
   889 
   894 /**
   890 /**
   895 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.
   896 It then makes it current to the thread.
   892 It then makes it current to the thread.
   897 @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
   898 @param aImageInfo Used to create the RSgImage pixmap
   894 @param aImageInfo Used to create the RSgImage pixmap
   899 @param aCloseNativeImageEarly When ETrue, the RSgImage is closed as soon as the pixmap surface has been
   895 @param aCloseNativeImageEarly When ETrue, the RSgImage is closed as soon as the pixmap surface has been
   900 		created.  Otherwise, the RSgImage is left to be destroyed later by some other method 
   896 		created.  Otherwise, the RSgImage is left to be destroyed later by some other method
   901 		- e.g at the same time as destroying the surface.
   897 		- e.g at the same time as destroying the surface.
   902 @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
   903 */
   899 */
   904 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)
   905 	{
   901 	{
   906 	ASSERT_EQUALS(iSurface, EGL_NO_SURFACE);
   902 	ASSERT_EQUALS(iSurface, EGL_NO_SURFACE);
   907 	ASSERT_EQUALS(iContext, EGL_NO_CONTEXT);
   903 	ASSERT_EQUALS(iContext, EGL_NO_CONTEXT);
   908 	
   904 
   909 	OpenSgDriverL();
   905 	OpenSgDriverL();
   910     ASSERT_EQUALS(iSgImage.Create(aImageInfo, NULL, 0), KErrNone);
   906     ASSERT_EQUALS(iSgImage.Create(aImageInfo, NULL, 0), KErrNone);
   911 		
   907 
   912 	ASSERT_EGL_TRUE(eglBindAPI(aBindAPI));
   908 	ASSERT_EGL_TRUE(eglBindAPI(aBindAPI));
   913 
   909 
   914 	// Create a pixmap surface from the native image
   910 	// Create a pixmap surface from the native image
   915 	EGLint EGL_RENDERABLE_TYPE_value = 0;
   911 	EGLint EGL_RENDERABLE_TYPE_value = 0;
   916 	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));
   917 	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;
   918 	iSurface = eglCreatePixmapSurface(iDisplay, aConfig, &iSgImage, pixmapAttribs);
   914 	iSurface = eglCreatePixmapSurface(iDisplay, aConfig, &iSgImage, pixmapAttribs);
   919 	ASSERT_EGL_TRUE(iSurface != EGL_NO_SURFACE);
   915 	ASSERT_EGL_TRUE(iSurface != EGL_NO_SURFACE);
   920 	
   916 
   921 	if (aResourceCloseRule == EResourceCloseSgImageEarly)
   917 	if (aResourceCloseRule == EResourceCloseSgImageEarly)
   922 		{
   918 		{
   923 		// 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
   924 		// 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.
   925 		iSgImage.Close();
   921 		iSgImage.Close();
   926 		}
   922 		}
   927 	if (aResourceCloseRule == EResourceCloseSgDriverAndImageEarly)
   923 	if (aResourceCloseRule == EResourceCloseSgDriverAndImageEarly)
   928 		{
   924 		{
   929 		// 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
   930 		// 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
   931 		// been closed.
   927 		// been closed.
   932 		iSgImage.Close();
   928 		iSgImage.Close();
   933 		CloseSgDriver();		
   929 		CloseSgDriver();
   934 		}
   930 		}
   935 	
   931 
   936 	// 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
   937 	const EGLint KAttribsListCtxNone[] = { EGL_NONE };;
   933 	const EGLint KAttribsListCtxNone[] = { EGL_NONE };;
   938 	const EGLint KAttribsListCtxGles2[] = { EGL_CONTEXT_CLIENT_VERSION, aRenderVersionNumber, EGL_NONE };
   934 	const EGLint KAttribsListCtxGles2[] = { EGL_CONTEXT_CLIENT_VERSION, aRenderVersionNumber, EGL_NONE };
   939 	const EGLint* attrib_list_ctx = (aBindAPI == EGL_OPENGL_ES_API && aRenderVersionNumber == 2) ? KAttribsListCtxGles2 : KAttribsListCtxNone; 
   935 	const EGLint* attrib_list_ctx = (aBindAPI == EGL_OPENGL_ES_API && aRenderVersionNumber == 2) ? KAttribsListCtxGles2 : KAttribsListCtxNone;
   940 	iContext = eglCreateContext(iDisplay, aConfig, EGL_NO_CONTEXT, attrib_list_ctx);
   936 	iContext = eglCreateContext(iDisplay, aConfig, EGL_NO_CONTEXT, attrib_list_ctx);
   941 	ASSERT_EGL_TRUE(iContext != EGL_NO_CONTEXT);	
   937 	ASSERT_EGL_TRUE(iContext != EGL_NO_CONTEXT);
   942 	ASSERT_EGL_TRUE(eglMakeCurrent(iDisplay, iSurface, iSurface, iContext));
   938 	ASSERT_EGL_TRUE(eglMakeCurrent(iDisplay, iSurface, iSurface, iContext));
   943 	}
   939 	}
   944 
   940 
   945 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)
   946 	{
   942 	{
   947 	//Fist try with CreateHardwareBitmap to check whether we are on hardware
   943 	//Fist try with CreateHardwareBitmap to check whether we are on hardware
   948 	TInt result = aFbsBitmap->CreateHardwareBitmap(aSize, aDisplayMode, KUidEglTestServer);
   944 	TInt result = aFbsBitmap->CreateHardwareBitmap(aSize, aDisplayMode, KUidEglTestServer);
   949 	
   945 
   950 	if(result == KErrNotSupported)
   946 	if(result == KErrNotSupported)
   951 		{
   947 		{
   952 		//we are not on hardware
   948 		//we are not on hardware
   953 		result = aFbsBitmap->Create(aSize, aDisplayMode);
   949 		result = aFbsBitmap->Create(aSize, aDisplayMode);
   954 		}
   950 		}
   957 
   953 
   958 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)
   959 	{
   955 	{
   960 	ASSERT_EQUALS(iSurface, EGL_NO_SURFACE);
   956 	ASSERT_EQUALS(iSurface, EGL_NO_SURFACE);
   961 	ASSERT_EQUALS(iContext, EGL_NO_CONTEXT);
   957 	ASSERT_EQUALS(iContext, EGL_NO_CONTEXT);
   962 	
   958 
   963 	// Create an empty native CFbsBitmap
   959 	// Create an empty native CFbsBitmap
   964 	OpenFbsSessionL();
   960 	OpenFbsSessionL();
   965 	iFbsBitmap = new(ELeave)CFbsBitmap;
   961 	iFbsBitmap = new(ELeave)CFbsBitmap;
   966 	ASSERT_EQUALS(CreateBitmap(iFbsBitmap, aSize, displayMode), KErrNone);
   962 	ASSERT_EQUALS(CreateBitmap(iFbsBitmap, aSize, displayMode), KErrNone);
   967 	
   963 
   968     const EGLint* attrib_list = NULL;
   964     const EGLint* attrib_list = NULL;
   969 	if(aBindAPI == EGL_OPENVG_API)
   965 	if(aBindAPI == EGL_OPENVG_API)
   970 		{
   966 		{
   971 		// no attribs to modify
   967 		// no attribs to modify
   972 		}
   968 		}
   983 		{
   979 		{
   984 		ERR_PRINTF1(_L("CreatePixmapSurfaceAndMakeCurrentL - Unkown API requested!"));
   980 		ERR_PRINTF1(_L("CreatePixmapSurfaceAndMakeCurrentL - Unkown API requested!"));
   985 		User::Leave(KErrArgument);
   981 		User::Leave(KErrArgument);
   986 		}
   982 		}
   987 	ASSERT_EGL_TRUE(eglBindAPI(aBindAPI));
   983 	ASSERT_EGL_TRUE(eglBindAPI(aBindAPI));
   988 	
   984 
   989 	// Create a pixmap surface from the native image
   985 	// Create a pixmap surface from the native image
   990 	EGLint EGL_RENDERABLE_TYPE_value = 0;
   986 	EGLint EGL_RENDERABLE_TYPE_value = 0;
   991 	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));
   992 	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;
   993 	iSurface = eglCreatePixmapSurface(iDisplay, aConfig, iFbsBitmap, pixmapAttribs);
   989 	iSurface = eglCreatePixmapSurface(iDisplay, aConfig, iFbsBitmap, pixmapAttribs);
   994 	ASSERT_EGL_TRUE(iSurface != EGL_NO_SURFACE);
   990 	ASSERT_EGL_TRUE(iSurface != EGL_NO_SURFACE);
   995 	
   991 
   996 	// 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
   997 	iContext = eglCreateContext(iDisplay, aConfig, EGL_NO_CONTEXT, attrib_list);
   993 	iContext = eglCreateContext(iDisplay, aConfig, EGL_NO_CONTEXT, attrib_list);
   998 	ASSERT_EGL_TRUE(iContext != EGL_NO_CONTEXT);	
   994 	ASSERT_EGL_TRUE(iContext != EGL_NO_CONTEXT);
   999 	ASSERT_EGL_TRUE(eglMakeCurrent(iDisplay, iSurface, iSurface, iContext));
   995 	ASSERT_EGL_TRUE(eglMakeCurrent(iDisplay, iSurface, iSurface, iContext));
  1000 	}
   996 	}
  1001 
   997 
  1002 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)
  1003 	{
   999 	{
  1004 	ASSERT_EQUALS(iSurface, EGL_NO_SURFACE);
  1000 	ASSERT_EQUALS(iSurface, EGL_NO_SURFACE);
  1005 	ASSERT_EQUALS(iContext, EGL_NO_CONTEXT);
  1001 	ASSERT_EQUALS(iContext, EGL_NO_CONTEXT);
  1006 	
  1002 
  1007 	OpenFbsSessionL();
  1003 	OpenFbsSessionL();
  1008 	iFbsBitmap = new(ELeave)CFbsBitmap;
  1004 	iFbsBitmap = new(ELeave)CFbsBitmap;
  1009 	ASSERT_EQUALS(CreateBitmap(iFbsBitmap, aSize, displayMode), KErrNone);
  1005 	ASSERT_EQUALS(CreateBitmap(iFbsBitmap, aSize, aDisplayMode), KErrNone);
  1010 
  1006 
  1011 	EGLint renderableType = 0;
  1007 	EGLint renderableType = 0;
  1012 	if(aBindAPI == EGL_OPENVG_API)
  1008 	if(aBindAPI == EGL_OPENVG_API)
  1013 		{
  1009 		{
  1014 		renderableType = EGL_OPENVG_BIT;
  1010 		renderableType = EGL_OPENVG_BIT;
  1024 	else
  1020 	else
  1025 		{
  1021 		{
  1026 		ERR_PRINTF1(_L("CreatePixmapSurfaceAndMakeCurrentAndMatchL - Unkown API requested!"));
  1022 		ERR_PRINTF1(_L("CreatePixmapSurfaceAndMakeCurrentAndMatchL - Unkown API requested!"));
  1027 		User::Leave(KErrArgument);
  1023 		User::Leave(KErrArgument);
  1028 		}
  1024 		}
  1029 	EGLint attrib_list[] = { 
  1025 	EGLint attrib_list[] = {
  1030 			  EGL_MATCH_NATIVE_PIXMAP,(TInt)iFbsBitmap,
  1026 			  EGL_MATCH_NATIVE_PIXMAP,(TInt)iFbsBitmap,
  1031 			  EGL_RENDERABLE_TYPE,renderableType,
  1027 			  EGL_RENDERABLE_TYPE,renderableType,
  1032 			  EGL_SURFACE_TYPE,EGL_PIXMAP_BIT,
  1028 			  EGL_SURFACE_TYPE,EGL_PIXMAP_BIT,
  1033 			  EGL_NONE};
  1029 			  EGL_NONE};
  1034 
  1030 
  1046 		// 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
  1047 		User::Leave(KTestNoMatchingConfig);
  1043 		User::Leave(KTestNoMatchingConfig);
  1048 		}
  1044 		}
  1049 
  1045 
  1050 	// Create a pixmap surface from the native image
  1046 	// Create a pixmap surface from the native image
  1051 	EGLint EGL_RENDERABLE_TYPE_value = 0;
  1047 	const EGLint* pixmapAttribs = (aDisplayMode == EColor16MAP && aBindAPI == EGL_OPENVG_API) ? KPixmapAttribsVgAlphaFormatPre : KPixmapAttribsNone;
  1052 	ASSERT_EGL_TRUE(eglGetConfigAttrib(iDisplay, config, EGL_RENDERABLE_TYPE, &EGL_RENDERABLE_TYPE_value));
       
  1053 	const EGLint* pixmapAttribs = ((displayMode == EColor16MAP) && (EGL_RENDERABLE_TYPE_value & EGL_OPENVG_BIT)) ? KPixmapAttribsVgAlphaFormatPre : KPixmapAttribsNone;
       
  1054 	iSurface = eglCreatePixmapSurface(iDisplay, config, iFbsBitmap, pixmapAttribs);
  1048 	iSurface = eglCreatePixmapSurface(iDisplay, config, iFbsBitmap, pixmapAttribs);
  1055 	ASSERT_EGL_TRUE(iSurface != EGL_NO_SURFACE);
  1049 	ASSERT_EGL_TRUE(iSurface != EGL_NO_SURFACE);
  1056 	
  1050 
  1057 	// 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
  1058 	const EGLint KAttribsListCtxNone[] = { EGL_NONE };;
  1052 	const EGLint KAttribsListCtxNone[] = { EGL_NONE };;
  1059 	const EGLint KAttribsListCtxGles2[] = { EGL_CONTEXT_CLIENT_VERSION, aRenderVersionNumber, EGL_NONE };
  1053 	const EGLint KAttribsListCtxGles2[] = { EGL_CONTEXT_CLIENT_VERSION, aRenderVersionNumber, EGL_NONE };
  1060 	const EGLint* attrib_list_ctx = (aBindAPI == EGL_OPENGL_ES_API && aRenderVersionNumber == 2) ? KAttribsListCtxGles2 : KAttribsListCtxNone; 
  1054 	const EGLint* attrib_list_ctx = (aBindAPI == EGL_OPENGL_ES_API && aRenderVersionNumber == 2) ? KAttribsListCtxGles2 : KAttribsListCtxNone;
  1061 	iContext = eglCreateContext(iDisplay, config, EGL_NO_CONTEXT, attrib_list_ctx);
  1055 	iContext = eglCreateContext(iDisplay, config, EGL_NO_CONTEXT, attrib_list_ctx);
  1062 	ASSERT_EGL_TRUE(iContext != EGL_NO_CONTEXT);	
  1056 	ASSERT_EGL_TRUE(iContext != EGL_NO_CONTEXT);
  1063 	ASSERT_EGL_TRUE(eglMakeCurrent(iDisplay, iSurface, iSurface, iContext));
  1057 	ASSERT_EGL_TRUE(eglMakeCurrent(iDisplay, iSurface, iSurface, iContext));
  1064 	}
  1058 	}
  1065 
  1059 
  1066 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)
  1067 	{
  1061 	{
  1068 	ASSERT_EQUALS(iSurface, EGL_NO_SURFACE);
  1062 	ASSERT_EQUALS(iSurface, EGL_NO_SURFACE);
  1069 	ASSERT_EQUALS(iContext, EGL_NO_CONTEXT);
  1063 	ASSERT_EQUALS(iContext, EGL_NO_CONTEXT);
  1070 
  1064 
  1071 	ASSERT_EQUALS(iSurface, EGL_NO_SURFACE);
  1065 	ASSERT_EQUALS(iSurface, EGL_NO_SURFACE);
  1072 	ASSERT_EQUALS(iContext, EGL_NO_CONTEXT);
  1066 	ASSERT_EQUALS(iContext, EGL_NO_CONTEXT);
  1073 	
  1067 
  1074 	ASSERT_EGL_TRUE(eglBindAPI(aBindAPI));
  1068 	ASSERT_EGL_TRUE(eglBindAPI(aBindAPI));
  1075 	
  1069 
  1076 	//	PBuffer attribs options are:
  1070 	//	PBuffer attribs options are:
  1077 	//		EGL_WIDTH, EGL_HEIGHT, EGL_LARGEST_PBUFFER,
  1071 	//		EGL_WIDTH, EGL_HEIGHT, EGL_LARGEST_PBUFFER,
  1078 	//		EGL_TEXTURE_FORMAT, EGL_TEXTURE_TARGET, EGL_MIPMAP_TEXTURE,
  1072 	//		EGL_TEXTURE_FORMAT, EGL_TEXTURE_TARGET, EGL_MIPMAP_TEXTURE,
  1079 	//		EGL_VG_COLORSPACE, and EGL_VG_ALPHA_FORMAT
  1073 	//		EGL_VG_COLORSPACE, and EGL_VG_ALPHA_FORMAT
  1080 	// Create a pbuffer surface of the given size
  1074 	// Create a pbuffer surface of the given size
  1081 	const EGLint KPbufferAttribs[] = { 
  1075 	const EGLint KPbufferAttribs[] = {
  1082 			EGL_WIDTH,	aSize.iWidth,
  1076 			EGL_WIDTH,	aSize.iWidth,
  1083 			EGL_HEIGHT,	aSize.iHeight,
  1077 			EGL_HEIGHT,	aSize.iHeight,
  1084 			EGL_NONE };
  1078 			EGL_NONE };
  1085 	iSurface = eglCreatePbufferSurface(iDisplay, aConfig, KPbufferAttribs);	
  1079 	iSurface = eglCreatePbufferSurface(iDisplay, aConfig, KPbufferAttribs);
  1086 	ASSERT_EGL_TRUE(iSurface != EGL_NO_SURFACE);
  1080 	ASSERT_EGL_TRUE(iSurface != EGL_NO_SURFACE);
  1087 
  1081 
  1088 	// 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
  1089 	const EGLint KAttribsListCtxNone[] = { EGL_NONE };;
  1083 	const EGLint KAttribsListCtxNone[] = { EGL_NONE };;
  1090 	const EGLint KAttribsListCtxGles2[] = { EGL_CONTEXT_CLIENT_VERSION, aRenderVersionNumber, EGL_NONE };
  1084 	const EGLint KAttribsListCtxGles2[] = { EGL_CONTEXT_CLIENT_VERSION, aRenderVersionNumber, EGL_NONE };
  1091 	const EGLint* attrib_list_ctx = (aBindAPI == EGL_OPENGL_ES_API && aRenderVersionNumber == 2) ? KAttribsListCtxGles2 : KAttribsListCtxNone; 
  1085 	const EGLint* attrib_list_ctx = (aBindAPI == EGL_OPENGL_ES_API && aRenderVersionNumber == 2) ? KAttribsListCtxGles2 : KAttribsListCtxNone;
  1092 	iContext = eglCreateContext(iDisplay, aConfig, EGL_NO_CONTEXT, attrib_list_ctx);
  1086 	iContext = eglCreateContext(iDisplay, aConfig, EGL_NO_CONTEXT, attrib_list_ctx);
  1093 	ASSERT_EGL_TRUE(iContext != EGL_NO_CONTEXT);	
  1087 	ASSERT_EGL_TRUE(iContext != EGL_NO_CONTEXT);
  1094 	ASSERT_EGL_TRUE(eglMakeCurrent(iDisplay, iSurface, iSurface, iContext));
  1088 	ASSERT_EGL_TRUE(eglMakeCurrent(iDisplay, iSurface, iSurface, iContext));
  1095 	}
  1089 	}
  1096 
  1090 
  1097 EXPORT_C void CTestEglSession::DrawOpenVgL()
  1091 EXPORT_C void CTestEglSession::DrawOpenVgL()
  1098 	{
  1092 	{
  1099 	ASSERT_TRUE(iSurface != EGL_NO_SURFACE);
  1093 	ASSERT_TRUE(iSurface != EGL_NO_SURFACE);
  1100 	ASSERT_TRUE(iContext != EGL_NO_CONTEXT);
  1094 	ASSERT_TRUE(iContext != EGL_NO_CONTEXT);
  1101 	
  1095 
  1102 	// Draw to the pixmap surface 
  1096 	// Draw to the pixmap surface
  1103 	// Clear it: redish
  1097 	// Clear it: redish
  1104 	VGfloat colorBackground[4];
  1098 	VGfloat colorBackground[4];
  1105 	ConvertColor(KRgbReddish, colorBackground);
  1099 	ConvertColor(KRgbReddish, colorBackground);
  1106 	vgSetfv(VG_CLEAR_COLOR, 4, colorBackground);
  1100 	vgSetfv(VG_CLEAR_COLOR, 4, colorBackground);
  1107 	vgClear(0, 0, KPixmapSize.iWidth, KPixmapSize.iHeight);
  1101 	vgClear(0, 0, KPixmapSize.iWidth, KPixmapSize.iHeight);
  1108 	
  1102 
  1109 	// And add a square: greenish
  1103 	// And add a square: greenish
  1110 	VGfloat colorSquare[4];
  1104 	VGfloat colorSquare[4];
  1111 	ConvertColor(KRgbGreenish, colorSquare);
  1105 	ConvertColor(KRgbGreenish, colorSquare);
  1112 	vgSetfv(VG_CLEAR_COLOR, 4, colorSquare);
  1106 	vgSetfv(VG_CLEAR_COLOR, 4, colorSquare);
  1113 	vgClear(KPixmapSquare.iTl.iX, KPixmapSquare.iTl.iX, KPixmapSquare.Width(), KPixmapSquare.Height());
  1107 	vgClear(KPixmapSquare.iTl.iX, KPixmapSquare.iTl.iX, KPixmapSquare.Width(), KPixmapSquare.Height());
  1124 	const GLfloat glAlpha = KRgbReddish.Alpha();
  1118 	const GLfloat glAlpha = KRgbReddish.Alpha();
  1125 	const GLfloat glRedBits = 255.f;
  1119 	const GLfloat glRedBits = 255.f;
  1126 	const GLfloat glGreenBits = 255.f;
  1120 	const GLfloat glGreenBits = 255.f;
  1127 	const GLfloat glBlueBits  = 255.f;
  1121 	const GLfloat glBlueBits  = 255.f;
  1128 	const GLfloat glAlphaBits = 255.f;
  1122 	const GLfloat glAlphaBits = 255.f;
  1129 	
  1123 
  1130 	// Disable  cdither - when using exact comparison to reference bitmap
  1124 	// Disable  cdither - when using exact comparison to reference bitmap
  1131 	// because reference bitmap cannot be created to match dither exactly
  1125 	// because reference bitmap cannot be created to match dither exactly
  1132 	glDisable(GL_DITHER);	
  1126 	glDisable(GL_DITHER);
  1133 	// Clear the surface to the colour specified
  1127 	// Clear the surface to the colour specified
  1134 	glClearColor((glRed)/glRedBits, (glGreen)/glGreenBits, (glBlue)/glBlueBits, glAlpha/glAlphaBits);
  1128 	glClearColor((glRed)/glRedBits, (glGreen)/glGreenBits, (glBlue)/glBlueBits, glAlpha/glAlphaBits);
  1135 	
  1129 
  1136 	//glColor3f(KRgbGreenish.Red(),KRgbGreenish.Green(),KRgbGreenish.Blue());
  1130 	//glColor3f(KRgbGreenish.Red(),KRgbGreenish.Green(),KRgbGreenish.Blue());
  1137 	//glRectf(KPixmapSquare.iTl.iX, KPixmapSquare.iTl.iY,KPixmapSquare.iTl.iX + KPixmapSquare.Width(),KPixmapSquare.iTl.iY + KPixmapSquare.Height());
  1131 	//glRectf(KPixmapSquare.iTl.iX, KPixmapSquare.iTl.iY,KPixmapSquare.iTl.iX + KPixmapSquare.Width(),KPixmapSquare.iTl.iY + KPixmapSquare.Height());
  1138 	
  1132 
  1139 	glClear(GL_COLOR_BUFFER_BIT);
  1133 	glClear(GL_COLOR_BUFFER_BIT);
  1140 	}
  1134 	}
  1141 
  1135 
  1142 EXPORT_C void CTestEglSession::CheckImageDataL(CFbsBitmap* aFbsBitmap)
  1136 EXPORT_C void CTestEglSession::CheckImageDataL(CFbsBitmap* aFbsBitmap)
  1143 	{
  1137 	{
  1146 	// Outside the square
  1140 	// Outside the square
  1147 	aFbsBitmap->GetPixel(rgbPixelSample, TPoint(10,10));
  1141 	aFbsBitmap->GetPixel(rgbPixelSample, TPoint(10,10));
  1148 	ASSERT_TRUE(PixelsMatch(KRgbReddish, rgbPixelSample, EFalse));
  1142 	ASSERT_TRUE(PixelsMatch(KRgbReddish, rgbPixelSample, EFalse));
  1149 	aFbsBitmap->GetPixel(rgbPixelSample, TPoint(90,90));
  1143 	aFbsBitmap->GetPixel(rgbPixelSample, TPoint(90,90));
  1150 	ASSERT_TRUE(PixelsMatch(KRgbReddish, rgbPixelSample, EFalse));
  1144 	ASSERT_TRUE(PixelsMatch(KRgbReddish, rgbPixelSample, EFalse));
  1151 	
  1145 
  1152 	// Inside the square
  1146 	// Inside the square
  1153 	aFbsBitmap->GetPixel(rgbPixelSample, TPoint(30,30));
  1147 	aFbsBitmap->GetPixel(rgbPixelSample, TPoint(30,30));
  1154 	ASSERT_TRUE(PixelsMatch(KRgbGreenish, rgbPixelSample, EFalse));
  1148 	ASSERT_TRUE(PixelsMatch(KRgbGreenish, rgbPixelSample, EFalse));
  1155 	aFbsBitmap->GetPixel(rgbPixelSample, TPoint(70,70));
  1149 	aFbsBitmap->GetPixel(rgbPixelSample, TPoint(70,70));
  1156 	ASSERT_TRUE(PixelsMatch(KRgbGreenish, rgbPixelSample, EFalse));
  1150 	ASSERT_TRUE(PixelsMatch(KRgbGreenish, rgbPixelSample, EFalse));
  1163 	// Outside the square
  1157 	// Outside the square
  1164 	aFbsBitmap->GetPixel(rgbPixelSample, TPoint(10,10));
  1158 	aFbsBitmap->GetPixel(rgbPixelSample, TPoint(10,10));
  1165 	ASSERT_TRUE(PixelsMatch(KRgbReddish, rgbPixelSample, EFalse));
  1159 	ASSERT_TRUE(PixelsMatch(KRgbReddish, rgbPixelSample, EFalse));
  1166 	aFbsBitmap->GetPixel(rgbPixelSample, TPoint(90,90));
  1160 	aFbsBitmap->GetPixel(rgbPixelSample, TPoint(90,90));
  1167 	ASSERT_TRUE(PixelsMatch(KRgbReddish, rgbPixelSample, EFalse));
  1161 	ASSERT_TRUE(PixelsMatch(KRgbReddish, rgbPixelSample, EFalse));
  1168 	
  1162 
  1169 	// Inside the square
  1163 	// Inside the square
  1170 	aFbsBitmap->GetPixel(rgbPixelSample, TPoint(30,30));
  1164 	aFbsBitmap->GetPixel(rgbPixelSample, TPoint(30,30));
  1171 	ASSERT_TRUE(PixelsMatch(KRgbReddish, rgbPixelSample, EFalse));
  1165 	ASSERT_TRUE(PixelsMatch(KRgbReddish, rgbPixelSample, EFalse));
  1172 	aFbsBitmap->GetPixel(rgbPixelSample, TPoint(70,70));
  1166 	aFbsBitmap->GetPixel(rgbPixelSample, TPoint(70,70));
  1173 	ASSERT_TRUE(PixelsMatch(KRgbReddish, rgbPixelSample, EFalse));
  1167 	ASSERT_TRUE(PixelsMatch(KRgbReddish, rgbPixelSample, EFalse));
  1182 	switch(aDataFormat)
  1176 	switch(aDataFormat)
  1183 		{
  1177 		{
  1184 		case VG_sRGB_565:
  1178 		case VG_sRGB_565:
  1185 			{
  1179 			{
  1186 			TUint16 intPixelSample=0;
  1180 			TUint16 intPixelSample=0;
  1187 			
  1181 
  1188 			// Outside the square
  1182 			// Outside the square
  1189 			vgReadPixels(&intPixelSample, 1, aDataFormat, 10,10, 1,1);
  1183 			vgReadPixels(&intPixelSample, 1, aDataFormat, 10,10, 1,1);
  1190 			ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color64K(intPixelSample), EFalse));
  1184 			ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color64K(intPixelSample), EFalse));
  1191 			vgReadPixels(&intPixelSample, 1, aDataFormat, 90,90, 1,1);
  1185 			vgReadPixels(&intPixelSample, 1, aDataFormat, 90,90, 1,1);
  1192 			ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color64K(intPixelSample), EFalse));
  1186 			ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color64K(intPixelSample), EFalse));
  1193 			
  1187 
  1194 			// Inside the square
  1188 			// Inside the square
  1195 			vgReadPixels(&intPixelSample, 1, aDataFormat, 30,30, 1,1);
  1189 			vgReadPixels(&intPixelSample, 1, aDataFormat, 30,30, 1,1);
  1196 			ASSERT_TRUE(PixelsMatch(KRgbGreenish, TRgb::Color64K(intPixelSample), EFalse));
  1190 			ASSERT_TRUE(PixelsMatch(KRgbGreenish, TRgb::Color64K(intPixelSample), EFalse));
  1197 			vgReadPixels(&intPixelSample, 1, aDataFormat, 70,70, 1,1);
  1191 			vgReadPixels(&intPixelSample, 1, aDataFormat, 70,70, 1,1);
  1198 			ASSERT_TRUE(PixelsMatch(KRgbGreenish, TRgb::Color64K(intPixelSample), EFalse));
  1192 			ASSERT_TRUE(PixelsMatch(KRgbGreenish, TRgb::Color64K(intPixelSample), EFalse));
  1199 			break;
  1193 			break;
  1200 			}
  1194 			}
  1201 		case VG_sXRGB_8888:		
  1195 		case VG_sXRGB_8888:
  1202 			{
  1196 			{
  1203 			TUint32 intPixelSample=0;
  1197 			TUint32 intPixelSample=0;
  1204 	
  1198 
  1205 			// Outside the square
  1199 			// Outside the square
  1206 			vgReadPixels(&intPixelSample, 1, aDataFormat, 10,10, 1,1);
  1200 			vgReadPixels(&intPixelSample, 1, aDataFormat, 10,10, 1,1);
  1207 			ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color16MU(intPixelSample), EFalse));
  1201 			ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color16MU(intPixelSample), EFalse));
  1208 			vgReadPixels(&intPixelSample, 1, aDataFormat, 90,90, 1,1);
  1202 			vgReadPixels(&intPixelSample, 1, aDataFormat, 90,90, 1,1);
  1209 			ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color16MU(intPixelSample), EFalse));
  1203 			ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color16MU(intPixelSample), EFalse));
  1210 			
  1204 
  1211 			// Inside the square
  1205 			// Inside the square
  1212 			vgReadPixels(&intPixelSample, 1, aDataFormat, 30,30, 1,1);
  1206 			vgReadPixels(&intPixelSample, 1, aDataFormat, 30,30, 1,1);
  1213 			ASSERT_TRUE(PixelsMatch(KRgbGreenish, TRgb::Color16MU(intPixelSample), EFalse));
  1207 			ASSERT_TRUE(PixelsMatch(KRgbGreenish, TRgb::Color16MU(intPixelSample), EFalse));
  1214 			vgReadPixels(&intPixelSample, 1, aDataFormat, 70,70, 1,1);
  1208 			vgReadPixels(&intPixelSample, 1, aDataFormat, 70,70, 1,1);
  1215 			ASSERT_TRUE(PixelsMatch(KRgbGreenish, TRgb::Color16MU(intPixelSample), EFalse));
  1209 			ASSERT_TRUE(PixelsMatch(KRgbGreenish, TRgb::Color16MU(intPixelSample), EFalse));
  1216 			break;
  1210 			break;
  1217 			}
  1211 			}
  1218 		case VG_sARGB_8888:
  1212 		case VG_sARGB_8888:
  1219 			{
  1213 			{
  1220 			TUint32 intPixelSample=0;
  1214 			TUint32 intPixelSample=0;
  1221 	
  1215 
  1222 			// Outside the square
  1216 			// Outside the square
  1223 			vgReadPixels(&intPixelSample, 1, aDataFormat, 10,10, 1,1);
  1217 			vgReadPixels(&intPixelSample, 1, aDataFormat, 10,10, 1,1);
  1224 			ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color16MA(intPixelSample), EFalse));
  1218 			ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color16MA(intPixelSample), EFalse));
  1225 			vgReadPixels(&intPixelSample, 1, aDataFormat, 90,90, 1,1);
  1219 			vgReadPixels(&intPixelSample, 1, aDataFormat, 90,90, 1,1);
  1226 			ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color16MA(intPixelSample), EFalse));
  1220 			ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color16MA(intPixelSample), EFalse));
  1227 			
  1221 
  1228 			// Inside the square
  1222 			// Inside the square
  1229 			vgReadPixels(&intPixelSample, 1, aDataFormat, 30,30, 1,1);
  1223 			vgReadPixels(&intPixelSample, 1, aDataFormat, 30,30, 1,1);
  1230 			ASSERT_TRUE(PixelsMatch(KRgbGreenish, TRgb::Color16MA(intPixelSample), EFalse));
  1224 			ASSERT_TRUE(PixelsMatch(KRgbGreenish, TRgb::Color16MA(intPixelSample), EFalse));
  1231 			vgReadPixels(&intPixelSample, 1, aDataFormat, 70,70, 1,1);
  1225 			vgReadPixels(&intPixelSample, 1, aDataFormat, 70,70, 1,1);
  1232 			ASSERT_TRUE(PixelsMatch(KRgbGreenish, TRgb::Color16MA(intPixelSample), EFalse));
  1226 			ASSERT_TRUE(PixelsMatch(KRgbGreenish, TRgb::Color16MA(intPixelSample), EFalse));
  1245 EXPORT_C void CTestEglSession::CheckImageDataGLesL()
  1239 EXPORT_C void CTestEglSession::CheckImageDataGLesL()
  1246 	{
  1240 	{
  1247 	TUint32 intPixelSample;
  1241 	TUint32 intPixelSample;
  1248 	glReadPixels(10,10,1,1,GL_RGBA,GL_UNSIGNED_BYTE ,&intPixelSample);
  1242 	glReadPixels(10,10,1,1,GL_RGBA,GL_UNSIGNED_BYTE ,&intPixelSample);
  1249 	SwapChannels(intPixelSample);
  1243 	SwapChannels(intPixelSample);
  1250 	ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color16MU(intPixelSample), EFalse));	
  1244 	ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color16MU(intPixelSample), EFalse));
  1251 	
  1245 
  1252 	glReadPixels(45,45,1,1,GL_RGBA,GL_UNSIGNED_BYTE ,&intPixelSample);
  1246 	glReadPixels(45,45,1,1,GL_RGBA,GL_UNSIGNED_BYTE ,&intPixelSample);
  1253 	SwapChannels(intPixelSample);
  1247 	SwapChannels(intPixelSample);
  1254 	ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color16MU(intPixelSample), EFalse));
  1248 	ASSERT_TRUE(PixelsMatch(KRgbReddish, TRgb::Color16MU(intPixelSample), EFalse));
  1255 
  1249 
  1256 	glReadPixels(55,55,1,1,GL_RGBA,GL_UNSIGNED_BYTE ,&intPixelSample);
  1250 	glReadPixels(55,55,1,1,GL_RGBA,GL_UNSIGNED_BYTE ,&intPixelSample);
  1264 	}
  1258 	}
  1265 
  1259 
  1266 EXPORT_C void CTestEglSession::SwapChannels(TUint32 &aSwapMe)
  1260 EXPORT_C void CTestEglSession::SwapChannels(TUint32 &aSwapMe)
  1267 	{
  1261 	{
  1268 	TUint32 buff = aSwapMe;
  1262 	TUint32 buff = aSwapMe;
  1269 	
  1263 
  1270 	aSwapMe = 0;
  1264 	aSwapMe = 0;
  1271 	aSwapMe |= (buff & 0x000000FF) << 16;
  1265 	aSwapMe |= (buff & 0x000000FF) << 16;
  1272 	aSwapMe |= (buff & 0x0000FF00);
  1266 	aSwapMe |= (buff & 0x0000FF00);
  1273 	aSwapMe |= (buff & 0x00FF0000) >> 16;
  1267 	aSwapMe |= (buff & 0x00FF0000) >> 16;
  1274 	aSwapMe |= (buff & 0xFF000000);
  1268 	aSwapMe |= (buff & 0xFF000000);
  1288 /**
  1282 /**
  1289 Resets the internal surface and context handles without destroying them.
  1283 Resets the internal surface and context handles without destroying them.
  1290 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.
  1291 
  1285 
  1292 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
  1293 eglTerminate() is called. 
  1287 eglTerminate() is called.
  1294 */
  1288 */
  1295 EXPORT_C void CTestEglSession::ResetSurfaceAndContextSgImageL()
  1289 EXPORT_C void CTestEglSession::ResetSurfaceAndContextSgImageL()
  1296 	{
  1290 	{
  1297 	INFO_PRINTF1(_L("CTestEglSession::ResetSurfaceAndContextSgImageL()"));
  1291 	INFO_PRINTF1(_L("CTestEglSession::ResetSurfaceAndContextSgImageL()"));
  1298 	
  1292 
  1299 	iContext = EGL_NO_CONTEXT;
  1293 	iContext = EGL_NO_CONTEXT;
  1300 	iSurface = EGL_NO_SURFACE;
  1294 	iSurface = EGL_NO_SURFACE;
  1301 	iSgImage.Close();
  1295 	iSgImage.Close();
  1302 	}
  1296 	}
  1303 
  1297 
  1304 /**
  1298 /**
  1305  Check that the pixel values match within a predefined tolerance
  1299  Check that the pixel values match within a predefined tolerance
  1306  @param aExpected the expected pixel colour vaule
  1300  @param aExpected the expected pixel colour vaule
  1307  @param aActual the actual pixel colour value 
  1301  @param aActual the actual pixel colour value
  1308  @param aCheckAlpha Whether to check the alpha channel value
  1302  @param aCheckAlpha Whether to check the alpha channel value
  1309  @return Whether the pixel values match - within the allowed tolerance
  1303  @return Whether the pixel values match - within the allowed tolerance
  1310  */
  1304  */
  1311 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)
  1312 	{
  1306 	{
  1313 	// 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
  1314 	//	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
  1315 	const TInt KPixelTolerance = 8;
  1309 	const TInt KPixelTolerance = 8;
  1316 
  1310 
  1317 	if (aCheckAlpha && aExpected.Alpha()== 0 && 
  1311 	if (aCheckAlpha && aExpected.Alpha()== 0 &&
  1318 		aActual.Red() == 0 && 
  1312 		aActual.Red() == 0 &&
  1319 		aActual.Green() == 0 && 
  1313 		aActual.Green() == 0 &&
  1320 		aActual.Blue() == 0 && 
  1314 		aActual.Blue() == 0 &&
  1321 		aActual.Alpha() == 0)
  1315 		aActual.Alpha() == 0)
  1322 		{
  1316 		{
  1323 		// 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
  1324 		return ETrue;
  1318 		return ETrue;
  1325 		}
  1319 		}
  1344 	EGLint major=0;
  1338 	EGLint major=0;
  1345 	EGLint minor=0;
  1339 	EGLint minor=0;
  1346 	CHECK_EXPECTED_ERROR(eglInitialize(iDisplay, &major, &minor));
  1340 	CHECK_EXPECTED_ERROR(eglInitialize(iDisplay, &major, &minor));
  1347 	// Remember if the user wants us to terminate the display.
  1341 	// Remember if the user wants us to terminate the display.
  1348 	iTerminateDisplay = aTerminateDisplay;
  1342 	iTerminateDisplay = aTerminateDisplay;
  1349 	
  1343 
  1350 	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);
  1351 	}
  1345 	}
  1352 
  1346 
  1353 
  1347 
  1354 EXPORT_C void CTestEglSession::TerminateDisplayL()
  1348 EXPORT_C void CTestEglSession::TerminateDisplayL()
  1377 EXPORT_C void CTestEglSession::OpenSgDriverL()
  1371 EXPORT_C void CTestEglSession::OpenSgDriverL()
  1378 	{
  1372 	{
  1379 	if (!iSgDriverOpen)
  1373 	if (!iSgDriverOpen)
  1380 		{
  1374 		{
  1381 		VERBOSE_INFO_PRINTF2(_L("CTestEglSession<0x%08x> Opening SgDriver"), this);
  1375 		VERBOSE_INFO_PRINTF2(_L("CTestEglSession<0x%08x> Opening SgDriver"), this);
  1382 #ifdef  SYMBIAN_GRAPHICS_EGL_SGIMAGELITE 		
  1376 #ifdef  SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
  1383 		TInt ret=iSgDriver.Open();
  1377 		TInt ret=iSgDriver.Open();
  1384 #else
  1378 #else
  1385 		TInt ret=SgDriver::Open();
  1379 		TInt ret=SgDriver::Open();
  1386 #endif	//SYMBIAN_GRAPHICS_EGL_SGIMAGELITE	
  1380 #endif	//SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
  1387 		ASSERT_EQUALS(ret, KErrNone);
  1381 		ASSERT_EQUALS(ret, KErrNone);
  1388 		iSgDriverOpen = ETrue;
  1382 		iSgDriverOpen = ETrue;
  1389 		}
  1383 		}
  1390 	}
  1384 	}
  1391 
  1385 
  1392 EXPORT_C void CTestEglSession::CloseSgDriver()
  1386 EXPORT_C void CTestEglSession::CloseSgDriver()
  1393 	{
  1387 	{
  1394 	if (iSgDriverOpen)
  1388 	if (iSgDriverOpen)
  1395 		{
  1389 		{
  1396 		VERBOSE_INFO_PRINTF2(_L("CTestEglSession<0x%08x> Closing SgDriver"), this);
  1390 		VERBOSE_INFO_PRINTF2(_L("CTestEglSession<0x%08x> Closing SgDriver"), this);
  1397 #ifdef  SYMBIAN_GRAPHICS_EGL_SGIMAGELITE        
  1391 #ifdef  SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
  1398         iSgDriver.Close();
  1392         iSgDriver.Close();
  1399 #else
  1393 #else
  1400         SgDriver::Close(); 
  1394         SgDriver::Close();
  1401 #endif  //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
  1395 #endif  //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
  1402 		iSgDriverOpen = EFalse;
  1396 		iSgDriverOpen = EFalse;
  1403 		}
  1397 		}
  1404 	}
  1398 	}
  1405 
  1399 
  1442 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)
  1443 	{
  1437 	{
  1444 	TBool bSuccess = FetchProcEglCreateImageKhr();
  1438 	TBool bSuccess = FetchProcEglCreateImageKhr();
  1445 	ASSERT_TRUE(bSuccess);
  1439 	ASSERT_TRUE(bSuccess);
  1446 	VERBOSE_INFO_PRINTF2(_L("thread %d: Calling eglCreateImageKHR"), iThreadIdx);
  1440 	VERBOSE_INFO_PRINTF2(_L("thread %d: Calling eglCreateImageKHR"), iThreadIdx);
  1447 	EGLImageKHR eglImage = ipfnEglCreateImageKHR(aDisplay,aContext,aTarget,reinterpret_cast<EGLClientBuffer>(aSgImage),const_cast<EGLint *>(aAttr_List));	
  1441 	EGLImageKHR eglImage = ipfnEglCreateImageKHR(aDisplay,aContext,aTarget,reinterpret_cast<EGLClientBuffer>(aSgImage),const_cast<EGLint *>(aAttr_List));
  1448 	return eglImage;
  1442 	return eglImage;
  1449 	}
  1443 	}
  1450 
  1444 
  1451 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)
  1452 	{
  1446 	{
  1453 	TBool bSuccess = FetchProcEglCreateImageKhr();
  1447 	TBool bSuccess = FetchProcEglCreateImageKhr();
  1454 	ASSERT_TRUE(bSuccess);
  1448 	ASSERT_TRUE(bSuccess);
  1455 	INFO_PRINTF2(_L("thread %d: Calling eglCreateImageKHR, with CFBsBitmap)"), iThreadIdx);
  1449 	INFO_PRINTF2(_L("thread %d: Calling eglCreateImageKHR, with CFBsBitmap)"), iThreadIdx);
  1456 	//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
  1457 	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));
  1458 	return eglImage;
  1452 	return eglImage;
  1459 	}
  1453 	}
  1460 
  1454 
  1461 EXPORT_C TBool CTestEglSession::FetchProcEglDestroyImageKhr()
  1455 EXPORT_C TBool CTestEglSession::FetchProcEglDestroyImageKhr()
  1462 	{
  1456 	{
  1484 EXPORT_C TBool CTestEglSession::FetchProcvgCreateImageTargetKhr()
  1478 EXPORT_C TBool CTestEglSession::FetchProcvgCreateImageTargetKhr()
  1485 	{
  1479 	{
  1486 	if (!ipfnvgCreateImageTargetKHR)
  1480 	if (!ipfnvgCreateImageTargetKHR)
  1487 		{
  1481 		{
  1488 		INFO_PRINTF2(_L("thread %d: Calling eglGetProcAddress (\"vgCreateEGLImageTargetKHR\")"), iThreadIdx);
  1482 		INFO_PRINTF2(_L("thread %d: Calling eglGetProcAddress (\"vgCreateEGLImageTargetKHR\")"), iThreadIdx);
  1489 		ipfnvgCreateImageTargetKHR = reinterpret_cast<TFPtrVgCreateEglImageTargetKhr>(eglGetProcAddress("vgCreateEGLImageTargetKHR"));		
  1483 		ipfnvgCreateImageTargetKHR = reinterpret_cast<TFPtrVgCreateEglImageTargetKhr>(eglGetProcAddress("vgCreateEGLImageTargetKHR"));
  1490 		if (ipfnvgCreateImageTargetKHR==NULL)
  1484 		if (ipfnvgCreateImageTargetKHR==NULL)
  1491 			{
  1485 			{
  1492 			EGLint eglError = eglGetError();
  1486 			EGLint eglError = eglGetError();
  1493 			WARN_PRINTF2(_L("vgCreateImageTargetKHR() not found - EGL Error: 0x%x"), eglError);
  1487 			WARN_PRINTF2(_L("vgCreateImageTargetKHR() not found - EGL Error: 0x%x"), eglError);
  1494 			}
  1488 			}
  1512 	EGLint EGL_GREEN_SIZE_value;
  1506 	EGLint EGL_GREEN_SIZE_value;
  1513 	EGLint EGL_RED_SIZE_value;
  1507 	EGLint EGL_RED_SIZE_value;
  1514 	EGLint EGL_SURFACE_TYPE_value;
  1508 	EGLint EGL_SURFACE_TYPE_value;
  1515 	EGLint EGL_RENDERABLE_TYPE_value;
  1509 	EGLint EGL_RENDERABLE_TYPE_value;
  1516 	EGLint EGL_CONFIG_ID_value;
  1510 	EGLint EGL_CONFIG_ID_value;
  1517 	
  1511 
  1518 	eglGetConfigAttrib(iDisplay, aConfig, EGL_CONFIG_ID, &EGL_CONFIG_ID_value);
  1512 	eglGetConfigAttrib(iDisplay, aConfig, EGL_CONFIG_ID, &EGL_CONFIG_ID_value);
  1519 	eglGetConfigAttrib(iDisplay, aConfig, EGL_BUFFER_SIZE, &EGL_BUFFER_SIZE_value);
  1513 	eglGetConfigAttrib(iDisplay, aConfig, EGL_BUFFER_SIZE, &EGL_BUFFER_SIZE_value);
  1520 	eglGetConfigAttrib(iDisplay, aConfig, EGL_ALPHA_SIZE, &EGL_ALPHA_SIZE_value);
  1514 	eglGetConfigAttrib(iDisplay, aConfig, EGL_ALPHA_SIZE, &EGL_ALPHA_SIZE_value);
  1521 	eglGetConfigAttrib(iDisplay, aConfig, EGL_BLUE_SIZE, &EGL_BLUE_SIZE_value);
  1515 	eglGetConfigAttrib(iDisplay, aConfig, EGL_BLUE_SIZE, &EGL_BLUE_SIZE_value);
  1522 	eglGetConfigAttrib(iDisplay, aConfig, EGL_GREEN_SIZE, &EGL_GREEN_SIZE_value);
  1516 	eglGetConfigAttrib(iDisplay, aConfig, EGL_GREEN_SIZE, &EGL_GREEN_SIZE_value);
  1523 	eglGetConfigAttrib(iDisplay, aConfig, EGL_RED_SIZE, &EGL_RED_SIZE_value);
  1517 	eglGetConfigAttrib(iDisplay, aConfig, EGL_RED_SIZE, &EGL_RED_SIZE_value);
  1524 	eglGetConfigAttrib(iDisplay, aConfig, EGL_SURFACE_TYPE, &EGL_SURFACE_TYPE_value);	
  1518 	eglGetConfigAttrib(iDisplay, aConfig, EGL_SURFACE_TYPE, &EGL_SURFACE_TYPE_value);
  1525 	eglGetConfigAttrib(iDisplay, aConfig, EGL_RENDERABLE_TYPE, &EGL_RENDERABLE_TYPE_value);
  1519 	eglGetConfigAttrib(iDisplay, aConfig, EGL_RENDERABLE_TYPE, &EGL_RENDERABLE_TYPE_value);
  1526 #ifdef PRINTG_CONFIGS_LOG
  1520 #ifdef PRINTG_CONFIGS_LOG
  1527 	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,
  1528 					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,
  1529 					EGL_ALPHA_SIZE_value);
  1523 					EGL_ALPHA_SIZE_value);
  1530 	INFO_PRINTF2(_L("RENDERABLE_TYPE %d"),EGL_RENDERABLE_TYPE_value);
  1524 	INFO_PRINTF2(_L("RENDERABLE_TYPE %d"),EGL_RENDERABLE_TYPE_value);
  1531 #endif
  1525 #endif
  1532 	
  1526 
  1533 	if(!(EGL_SURFACE_TYPE_value & EGL_PIXMAP_BIT))
  1527 	if(!(EGL_SURFACE_TYPE_value & EGL_PIXMAP_BIT))
  1534 		{
  1528 		{
  1535 		return EFalse;
  1529 		return EFalse;
  1536 		}
  1530 		}
  1537 	
  1531 
  1538 	TBool good = ETrue;
  1532 	TBool good = ETrue;
  1539 	//requested usage bits
  1533 	//requested usage bits
  1540 	TSgImageInfo requestedImageInfo;
  1534 	TSgImageInfo requestedImageInfo;
  1541 	aImage.GetInfo(requestedImageInfo);
  1535 	aImage.GetInfo(requestedImageInfo);
  1542 	
  1536 
  1543 #ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
  1537 #ifndef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
  1544 	//potential usage bits
  1538 	//potential usage bits
  1545     RSgImage potential;
  1539     RSgImage potential;
  1546     potential.Open(aImage.Id(),ESgDoNotRestrictUsage);
  1540     potential.Open(aImage.Id(),ESgDoNotRestrictUsage);
  1547     TSgImageInfo potentialImageInfo;
  1541     TSgImageInfo potentialImageInfo;
  1548     potential.GetInfo(potentialImageInfo);
  1542     potential.GetInfo(potentialImageInfo);
  1549     potential.Close();
  1543     potential.Close();
  1550 #endif    
  1544 #endif
  1551 	
  1545 
  1552 	switch(requestedImageInfo.iPixelFormat)
  1546 	switch(requestedImageInfo.iPixelFormat)
  1553 		{			
  1547 		{
  1554 		case EUidPixelFormatRGB_565:
  1548 		case EUidPixelFormatRGB_565:
  1555 			if (!(EGL_RED_SIZE_value == 5 && EGL_GREEN_SIZE_value == 6 && EGL_BLUE_SIZE_value == 5 && EGL_ALPHA_SIZE_value == 0))
  1549 			if (!(EGL_RED_SIZE_value == 5 && EGL_GREEN_SIZE_value == 6 && EGL_BLUE_SIZE_value == 5 && EGL_ALPHA_SIZE_value == 0))
  1556 				{
  1550 				{
  1557 				good = EFalse;
  1551 				good = EFalse;
  1558 				}
  1552 				}
  1559 			break;			
  1553 			break;
  1560 		case EUidPixelFormatXRGB_8888:
  1554 		case EUidPixelFormatXRGB_8888:
  1561 			if (!(EGL_RED_SIZE_value == 8 && EGL_GREEN_SIZE_value == 8 && EGL_BLUE_SIZE_value == 8 && EGL_ALPHA_SIZE_value == 0))
  1555 			if (!(EGL_RED_SIZE_value == 8 && EGL_GREEN_SIZE_value == 8 && EGL_BLUE_SIZE_value == 8 && EGL_ALPHA_SIZE_value == 0))
  1562 				{
  1556 				{
  1563 				good = EFalse;
  1557 				good = EFalse;
  1564 				}				
  1558 				}
  1565 			break;			
  1559 			break;
  1566 		case EUidPixelFormatARGB_8888_PRE:
  1560 		case EUidPixelFormatARGB_8888_PRE:
  1567 			if (!(EGL_RED_SIZE_value == 8 && EGL_GREEN_SIZE_value == 8 && EGL_BLUE_SIZE_value == 8 && EGL_ALPHA_SIZE_value == 8))
  1561 			if (!(EGL_RED_SIZE_value == 8 && EGL_GREEN_SIZE_value == 8 && EGL_BLUE_SIZE_value == 8 && EGL_ALPHA_SIZE_value == 8))
  1568 				{
  1562 				{
  1569 				good = EFalse;
  1563 				good = EFalse;
  1570 				}
  1564 				}
  1593 		{
  1587 		{
  1594 		return EFalse;
  1588 		return EFalse;
  1595 		}
  1589 		}
  1596 
  1590 
  1597 #ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
  1591 #ifdef SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
  1598 	// 
  1592 	//
  1599 	//Check if strict matching requirements are met:
  1593 	//Check if strict matching requirements are met:
  1600 	//- 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
  1601 	// EGLConfig must be matched by the corresponding iUsage of RSgImage
  1595 	// EGLConfig must be matched by the corresponding iUsage of RSgImage
  1602 	//- 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
  1603 	// 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:
  1604 	//         ESgUsageBitOpenGlSurface-> EGL_OPENGL_BIT
  1598 	//         ESgUsageBitOpenGlSurface-> EGL_OPENGL_BIT
  1605 	//         ESgUsageBitOpenGlesSurface-> EGL_OPENGL_ES_BIT
  1599 	//         ESgUsageBitOpenGlesSurface-> EGL_OPENGL_ES_BIT
  1606 	//         ESgUsageBitOpenGles2Surface-> EGL_OPENGL_ES2_BIT
  1600 	//         ESgUsageBitOpenGles2Surface-> EGL_OPENGL_ES2_BIT
  1607 	//         ESgUsageBitOpenVgSurface->EGL_OPENVG_BIT
  1601 	//         ESgUsageBitOpenVgSurface->EGL_OPENVG_BIT
  1608 	
  1602 
  1609 	EGLint usageBitsMask = 0;
  1603 	EGLint usageBitsMask = 0;
  1610 	if(requestedImageInfo.iUsage & ESgUsageBitOpenVgSurface)
  1604 	if(requestedImageInfo.iUsage & ESgUsageBitOpenVgSurface)
  1611 		{
  1605 		{
  1612 		usageBitsMask |= EGL_OPENVG_BIT;
  1606 		usageBitsMask |= EGL_OPENVG_BIT;
  1613 		}
  1607 		}
  1645         }
  1639         }
  1646     if(!(usageBitsMask & EGL_RENDERABLE_TYPE_value))
  1640     if(!(usageBitsMask & EGL_RENDERABLE_TYPE_value))
  1647         {
  1641         {
  1648         return EFalse;
  1642         return EFalse;
  1649         }
  1643         }
  1650     
  1644 
  1651     // potential usage >= RENDERABLE_TYPE
  1645     // potential usage >= RENDERABLE_TYPE
  1652     
  1646 
  1653     EGLint potentialUsageBitsMask = 0;
  1647     EGLint potentialUsageBitsMask = 0;
  1654     if(potentialImageInfo.iUsage & ESgUsageOpenVgTarget)
  1648     if(potentialImageInfo.iUsage & ESgUsageOpenVgTarget)
  1655         {
  1649         {
  1656         potentialUsageBitsMask |= EGL_OPENVG_BIT;
  1650         potentialUsageBitsMask |= EGL_OPENVG_BIT;
  1657         }
  1651         }
  1661         }
  1655         }
  1662     if(potentialImageInfo.iUsage & ESgUsageOpenGles2Target)
  1656     if(potentialImageInfo.iUsage & ESgUsageOpenGles2Target)
  1663         {
  1657         {
  1664         potentialUsageBitsMask |= EGL_OPENGL_ES2_BIT;
  1658         potentialUsageBitsMask |= EGL_OPENGL_ES2_BIT;
  1665         }
  1659         }
  1666     
  1660 
  1667     potentialUsageBitsMask = EGL_RENDERABLE_TYPE_value &~ potentialUsageBitsMask;
  1661     potentialUsageBitsMask = EGL_RENDERABLE_TYPE_value &~ potentialUsageBitsMask;
  1668     if(potentialUsageBitsMask)
  1662     if(potentialUsageBitsMask)
  1669         {
  1663         {
  1670         return EFalse;
  1664         return EFalse;
  1671         }
  1665         }
  1672 #endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE	
  1666 #endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
  1673 	return good;
  1667 	return good;
  1674 	}
  1668 	}
  1675 
  1669 
  1676 EXPORT_C TBool  CTestEglSession::CheckNeededExtensionL(TInt aExtension, const TDesC& aExtensionName)
  1670 EXPORT_C TBool  CTestEglSession::CheckNeededExtensionL(TInt aExtension, const TDesC& aExtensionName)
  1677 	{
  1671 	{
  1749             // The extension is not supported
  1743             // The extension is not supported
  1750             return EFalse;
  1744             return EFalse;
  1751             }
  1745             }
  1752         }
  1746         }
  1753 #endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
  1747 #endif //SYMBIAN_GRAPHICS_EGL_SGIMAGELITE
  1754     
  1748 
  1755 	return ETrue;	
  1749 	return ETrue;
  1756 	}
  1750 	}
  1757 
  1751 
  1758 EXPORT_C CFbsBitmap* CTestEglSession::CreateReferenceBitmapL(TDisplayMode aMode)
  1752 EXPORT_C CFbsBitmap* CTestEglSession::CreateReferenceBitmapL(TDisplayMode aMode)
  1759 	{
  1753 	{
  1760 	if(aMode == ENone )
  1754 	if(aMode == ENone )
  1801 	CFbsBitGc* fbsBitGc = CFbsBitGc::NewL();
  1795 	CFbsBitGc* fbsBitGc = CFbsBitGc::NewL();
  1802 	CleanupStack::PushL(fbsBitGc);
  1796 	CleanupStack::PushL(fbsBitGc);
  1803 	fbsBitGc->Activate(bitmapDevice);
  1797 	fbsBitGc->Activate(bitmapDevice);
  1804 	fbsBitGc->SetBrushColor(KRgbBlack);
  1798 	fbsBitGc->SetBrushColor(KRgbBlack);
  1805 	fbsBitGc->Clear();
  1799 	fbsBitGc->Clear();
  1806 	
  1800 
  1807 	// create the penBitmap (same size as the mask bitmap)	
  1801 	// create the penBitmap (same size as the mask bitmap)
  1808 	CFbsBitmap* penBitmap = new(ELeave) CFbsBitmap();
  1802 	CFbsBitmap* penBitmap = new(ELeave) CFbsBitmap();
  1809 	CleanupStack::PushL(penBitmap);
  1803 	CleanupStack::PushL(penBitmap);
  1810 	User::LeaveIfError(penBitmap->Create(aMaskBitmap->SizeInPixels(), aRefBitmapMode));
  1804 	User::LeaveIfError(penBitmap->Create(aMaskBitmap->SizeInPixels(), aRefBitmapMode));
  1811 	CFbsBitmapDevice* penbitmapDevice = CFbsBitmapDevice::NewL(penBitmap);
  1805 	CFbsBitmapDevice* penbitmapDevice = CFbsBitmapDevice::NewL(penBitmap);
  1812 	CleanupStack::PushL(penbitmapDevice);
  1806 	CleanupStack::PushL(penbitmapDevice);
  1815 	penBitGc->Activate(penbitmapDevice);
  1809 	penBitGc->Activate(penbitmapDevice);
  1816 	penBitGc->SetBrushColor(aPenBitmapColor);
  1810 	penBitGc->SetBrushColor(aPenBitmapColor);
  1817 	penBitGc->Clear();
  1811 	penBitGc->Clear();
  1818 
  1812 
  1819 	// perform a masked bitmap transfer to the active refBitmap
  1813 	// perform a masked bitmap transfer to the active refBitmap
  1820 	TRect bmpRect(TPoint(0, 0), refBitmap->SizeInPixels()); 
  1814 	TRect bmpRect(TPoint(0, 0), refBitmap->SizeInPixels());
  1821 	fbsBitGc->Activate(bitmapDevice);
  1815 	fbsBitGc->Activate(bitmapDevice);
  1822 	fbsBitGc->BitBltMasked(TPoint(0, 0), penBitmap, bmpRect, aMaskBitmap, EFalse);	
  1816 	fbsBitGc->BitBltMasked(TPoint(0, 0), penBitmap, bmpRect, aMaskBitmap, EFalse);
  1823 
  1817 
  1824 	CleanupStack::PopAndDestroy(5, bitmapDevice);
  1818 	CleanupStack::PopAndDestroy(5, bitmapDevice);
  1825 	CleanupStack::Pop(refBitmap);
  1819 	CleanupStack::Pop(refBitmap);
  1826 	return refBitmap;
  1820 	return refBitmap;
  1827 	}
  1821 	}
  1835 	User::LeaveIfError(bitmap->Create(aSize,aMode));
  1829 	User::LeaveIfError(bitmap->Create(aSize,aMode));
  1836 
  1830 
  1837 	TInt height = bitmap->SizeInPixels().iHeight;
  1831 	TInt height = bitmap->SizeInPixels().iHeight;
  1838 	TInt width  = bitmap->SizeInPixels().iWidth;
  1832 	TInt width  = bitmap->SizeInPixels().iWidth;
  1839 
  1833 
  1840 	// 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)
  1841 	TInt red=0;
  1835 	TInt red=0;
  1842 	TInt green=127;
  1836 	TInt green=127;
  1843 	TInt blue=127;
  1837 	TInt blue=127;
  1844 	TInt alpha=255;
  1838 	TInt alpha=255;
  1845 
  1839 
  1881 					}
  1875 					}
  1882 				default:
  1876 				default:
  1883 					{
  1877 					{
  1884 					// 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
  1885 					ERR_PRINTF1(_L("CTestEglSession::CreateReferenceBitmapL - Colour mode not supported!"));
  1879 					ERR_PRINTF1(_L("CTestEglSession::CreateReferenceBitmapL - Colour mode not supported!"));
  1886 				    ASSERT(FALSE); 
  1880 				    ASSERT(FALSE);
  1887 					}
  1881 					}
  1888 				}
  1882 				}
  1889 			bmpUtil.IncYPos();
  1883 			bmpUtil.IncYPos();
  1890 
  1884 
  1891 			// Update red bit 
  1885 			// Update red bit
  1892 			red = ++red + aIndex; 
  1886 			red = ++red + aIndex;
  1893 			if (red>255) 
  1887 			if (red>255)
  1894 				red = red - 256;
  1888 				red = red - 256;
  1895 			
  1889 
  1896 			// Update green bit
  1890 			// Update green bit
  1897 			green = --green - aIndex; 
  1891 			green = --green - aIndex;
  1898 			if (green<0) 
  1892 			if (green<0)
  1899 				green = green + 256;
  1893 				green = green + 256;
  1900 			
  1894 
  1901 			// Update blue bit
  1895 			// Update blue bit
  1902 			blue = ++blue + aIndex; 
  1896 			blue = ++blue + aIndex;
  1903 			if (blue>255) 
  1897 			if (blue>255)
  1904 				blue = blue - 256;
  1898 				blue = blue - 256;
  1905 			
  1899 
  1906 			// Update alpha bit
  1900 			// Update alpha bit
  1907 			alpha = --alpha - aIndex; 
  1901 			alpha = --alpha - aIndex;
  1908 			if (alpha<0) 
  1902 			if (alpha<0)
  1909 				alpha = alpha + 256;
  1903 				alpha = alpha + 256;
  1910 			}
  1904 			}
  1911 		}
  1905 		}
  1912 	bmpUtil.End();
  1906 	bmpUtil.End();
  1913 	CleanupStack::Pop(bitmap);
  1907 	CleanupStack::Pop(bitmap);
  1921 	TInt width  = aReferenceBitmap->SizeInPixels().iWidth;
  1915 	TInt width  = aReferenceBitmap->SizeInPixels().iWidth;
  1922 
  1916 
  1923 	switch(aDataFormat)
  1917 	switch(aDataFormat)
  1924 		{
  1918 		{
  1925 		case VG_sRGB_565:
  1919 		case VG_sRGB_565:
  1926 			{			
  1920 			{
  1927 			TUint16* vgPixel = new(ELeave) TUint16[width];
  1921 			TUint16* vgPixel = new(ELeave) TUint16[width];
  1928 			CleanupArrayDeletePushL(vgPixel);
  1922 			CleanupArrayDeletePushL(vgPixel);
  1929 			for (TInt y=0; y < height; y++)
  1923 			for (TInt y=0; y < height; y++)
  1930 				{
  1924 				{
  1931                 // Mind the fact that CFbsBitmap and VGImages use different coordinates origin!
  1925                 // Mind the fact that CFbsBitmap and VGImages use different coordinates origin!
  1932                 vgReadPixels(vgPixel, 1, aDataFormat, 0,height-y-1, width,1);
  1926                 vgReadPixels(vgPixel, 1, aDataFormat, 0,height-y-1, width,1);
  1933 				
  1927 
  1934 				for (TInt x=0; x < width; x++)
  1928 				for (TInt x=0; x < width; x++)
  1935 					{
  1929 					{
  1936 					aReferenceBitmap->GetPixel(refPixel, TPoint(x,y));
  1930 					aReferenceBitmap->GetPixel(refPixel, TPoint(x,y));
  1937 					if(!PixelsMatch(refPixel, TRgb::Color64K(vgPixel[x]), EFalse))
  1931 					if(!PixelsMatch(refPixel, TRgb::Color64K(vgPixel[x]), EFalse))
  1938 						{
  1932 						{
  1939 						User::Leave(KErrTEFUnitFail);
  1933 						User::Leave(KErrTEFUnitFail);
  1940 						}
  1934 						}
  1941 					}		
  1935 					}
  1942 				}
  1936 				}
  1943 			CleanupStack::PopAndDestroy(vgPixel);
  1937 			CleanupStack::PopAndDestroy(vgPixel);
  1944 			break;
  1938 			break;
  1945 			}
  1939 			}
  1946 
  1940 
  1947 		case VG_sXRGB_8888:		
  1941 		case VG_sXRGB_8888:
  1948 			{			
  1942 			{
  1949 			TUint32* vgPixel = new(ELeave) TUint32[width];
  1943 			TUint32* vgPixel = new(ELeave) TUint32[width];
  1950 			CleanupArrayDeletePushL(vgPixel);
  1944 			CleanupArrayDeletePushL(vgPixel);
  1951 			for (TInt y=0; y < height; y++)
  1945 			for (TInt y=0; y < height; y++)
  1952 				{
  1946 				{
  1953                 // Mind the fact that CFbsBitmap and VGImages use different coordinates origin!
  1947                 // Mind the fact that CFbsBitmap and VGImages use different coordinates origin!
  1954                 vgReadPixels(vgPixel, 1, aDataFormat, 0,height-y-1, width,1);
  1948                 vgReadPixels(vgPixel, 1, aDataFormat, 0,height-y-1, width,1);
  1955 			
  1949 
  1956 				for (TInt x=0; x < width; x++)
  1950 				for (TInt x=0; x < width; x++)
  1957 					{
  1951 					{
  1958 					aReferenceBitmap->GetPixel(refPixel, TPoint(x,y));
  1952 					aReferenceBitmap->GetPixel(refPixel, TPoint(x,y));
  1959 					if(!PixelsMatch(refPixel, TRgb::Color16MU(vgPixel[x]), EFalse))
  1953 					if(!PixelsMatch(refPixel, TRgb::Color16MU(vgPixel[x]), EFalse))
  1960 						{
  1954 						{
  1961 						User::Leave(KErrTEFUnitFail);
  1955 						User::Leave(KErrTEFUnitFail);
  1962 						}
  1956 						}
  1963 					}		
  1957 					}
  1964 				}
  1958 				}
  1965 			CleanupStack::PopAndDestroy(vgPixel);
  1959 			CleanupStack::PopAndDestroy(vgPixel);
  1966 			break;
  1960 			break;
  1967 			}
  1961 			}
  1968 			
  1962 
  1969 		case VG_sARGB_8888:		
  1963 		case VG_sARGB_8888:
  1970 			{			
  1964 			{
  1971 			TUint32* vgPixel = new(ELeave) TUint32[width];
  1965 			TUint32* vgPixel = new(ELeave) TUint32[width];
  1972 			CleanupArrayDeletePushL(vgPixel);
  1966 			CleanupArrayDeletePushL(vgPixel);
  1973 			for (TInt y=0; y < height; y++)
  1967 			for (TInt y=0; y < height; y++)
  1974 				{
  1968 				{
  1975                 // Mind the fact that CFbsBitmap and VGImages use different coordinates origin!
  1969                 // Mind the fact that CFbsBitmap and VGImages use different coordinates origin!
  1976                 vgReadPixels(vgPixel, 1, aDataFormat, 0,height-y-1, width,1);
  1970                 vgReadPixels(vgPixel, 1, aDataFormat, 0,height-y-1, width,1);
  1977 			
  1971 
  1978 				for (TInt x=0; x < width; x++)
  1972 				for (TInt x=0; x < width; x++)
  1979 					{
  1973 					{
  1980 					aReferenceBitmap->GetPixel(refPixel, TPoint(x,y));
  1974 					aReferenceBitmap->GetPixel(refPixel, TPoint(x,y));
  1981 					if(!PixelsMatch(refPixel, TRgb::Color16MA(vgPixel[x]), ETrue))
  1975 					if(!PixelsMatch(refPixel, TRgb::Color16MA(vgPixel[x]), ETrue))
  1982 						{
  1976 						{
  1983 						User::Leave(KErrTEFUnitFail);
  1977 						User::Leave(KErrTEFUnitFail);
  1984 						}
  1978 						}
  1985 					}		
  1979 					}
  1986 				}
  1980 				}
  1987 			CleanupStack::PopAndDestroy(vgPixel);
  1981 			CleanupStack::PopAndDestroy(vgPixel);
  1988 			break;
  1982 			break;
  1989 			}
  1983 			}
  1990 			
  1984 
  1991 		case VG_sARGB_8888_PRE:		
  1985 		case VG_sARGB_8888_PRE:
  1992 			{			
  1986 			{
  1993 			TUint32* vgPixel = new(ELeave) TUint32[width];
  1987 			TUint32* vgPixel = new(ELeave) TUint32[width];
  1994 			CleanupArrayDeletePushL(vgPixel);
  1988 			CleanupArrayDeletePushL(vgPixel);
  1995 			for (TInt y=0; y < height; y++)
  1989 			for (TInt y=0; y < height; y++)
  1996 				{
  1990 				{
  1997                 // Mind the fact that CFbsBitmap and VGImages use different coordinates origin!
  1991                 // Mind the fact that CFbsBitmap and VGImages use different coordinates origin!
  1998                 vgReadPixels(vgPixel, 1, aDataFormat, 0,height-y-1, width,1);
  1992                 vgReadPixels(vgPixel, 1, aDataFormat, 0,height-y-1, width,1);
  1999                 
  1993 
  2000 				for (TInt x=0; x < width; x++)
  1994 				for (TInt x=0; x < width; x++)
  2001 					{
  1995 					{
  2002 					aReferenceBitmap->GetPixel(refPixel, TPoint(x,y));
  1996 					aReferenceBitmap->GetPixel(refPixel, TPoint(x,y));
  2003 					if(!PixelsMatch(refPixel, TRgb::Color16MAP(vgPixel[x]), ETrue))
  1997 					if(!PixelsMatch(refPixel, TRgb::Color16MAP(vgPixel[x]), ETrue))
  2004 						{
  1998 						{
  2005 						User::Leave(KErrTEFUnitFail);
  1999 						User::Leave(KErrTEFUnitFail);
  2006 						}
  2000 						}
  2007 					}		
  2001 					}
  2008 				}
  2002 				}
  2009 			CleanupStack::PopAndDestroy(vgPixel);
  2003 			CleanupStack::PopAndDestroy(vgPixel);
  2010 			break;
  2004 			break;
  2011 			}
  2005 			}
  2012 
  2006 
  2013 		default:
  2007 		default:
  2014 			// 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
  2015 			ERR_PRINTF1(_L("CTestEglSession::CheckVgDrawingL - Colour mode not supported!"));
  2009 			ERR_PRINTF1(_L("CTestEglSession::CheckVgDrawingL - Colour mode not supported!"));
  2016 		    ASSERT(FALSE); 
  2010 		    ASSERT(FALSE);
  2017 			break;
  2011 			break;
  2018 		}
  2012 		}
  2019 	}
  2013 	}
  2020 
  2014 
  2021 EXPORT_C TBool CTestEglSession::IsOpenGLESSupported() 
  2015 EXPORT_C TBool CTestEglSession::IsOpenGLESSupported()
  2022     { 
  2016     {
  2023     if(!iIsSupportedRenderInitialized)
  2017     if(!iIsSupportedRenderInitialized)
  2024         {
  2018         {
  2025         CheckAllAvailableRenders();
  2019         CheckAllAvailableRenders();
  2026         }
  2020         }
  2027     return iIsOpenGLESSupported;
  2021     return iIsOpenGLESSupported;
  2028     } 
  2022     }
  2029 
  2023 
  2030 EXPORT_C TBool CTestEglSession::IsOpenGLES2Supported() 
  2024 EXPORT_C TBool CTestEglSession::IsOpenGLES2Supported()
  2031     {
  2025     {
  2032     if(!iIsSupportedRenderInitialized)
  2026     if(!iIsSupportedRenderInitialized)
  2033         {
  2027         {
  2034         CheckAllAvailableRenders();
  2028         CheckAllAvailableRenders();
  2035         }
  2029         }
  2036     return iIsOpenGLES2Supported;
  2030     return iIsOpenGLES2Supported;
  2037     }
  2031     }
  2038 EXPORT_C TBool CTestEglSession::IsOpenVGSupported() 
  2032 EXPORT_C TBool CTestEglSession::IsOpenVGSupported()
  2039     {
  2033     {
  2040     if(!iIsSupportedRenderInitialized)
  2034     if(!iIsSupportedRenderInitialized)
  2041         {
  2035         {
  2042         CheckAllAvailableRenders();
  2036         CheckAllAvailableRenders();
  2043         }
  2037         }
  2047 void CTestEglSession::CheckAllAvailableRenders()
  2041 void CTestEglSession::CheckAllAvailableRenders()
  2048     {
  2042     {
  2049     ASSERT_EGL_TRUE(iDisplay != EGL_NO_DISPLAY);
  2043     ASSERT_EGL_TRUE(iDisplay != EGL_NO_DISPLAY);
  2050     TPtrC8 ptrEglClientApis((const TText8 *)eglQueryString(iDisplay, EGL_CLIENT_APIS));
  2044     TPtrC8 ptrEglClientApis((const TText8 *)eglQueryString(iDisplay, EGL_CLIENT_APIS));
  2051     _LIT8(KOpenGLES, "OpenGL_ES");
  2045     _LIT8(KOpenGLES, "OpenGL_ES");
  2052     EGLint numConfigs= 0;       
  2046     EGLint numConfigs= 0;
  2053     EGLConfig config;
  2047     EGLConfig config;
  2054     if(ptrEglClientApis.Find(KOpenGLES) != KErrNotFound)
  2048     if(ptrEglClientApis.Find(KOpenGLES) != KErrNotFound)
  2055         {
  2049         {
  2056         //check GLES2
  2050         //check GLES2
  2057         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,
  2074             }
  2068             }
  2075         }
  2069         }
  2076     _LIT8(KOpenVG, "OpenVG");
  2070     _LIT8(KOpenVG, "OpenVG");
  2077     if(ptrEglClientApis.Find(KOpenVG) != KErrNotFound)
  2071     if(ptrEglClientApis.Find(KOpenVG) != KErrNotFound)
  2078         {
  2072         {
  2079         numConfigs= 0;       
  2073         numConfigs= 0;
  2080         //check VG
  2074         //check VG
  2081         const EGLint KAttrib_list_vg[] = { EGL_RENDERABLE_TYPE, EGL_OPENVG_BIT,
  2075         const EGLint KAttrib_list_vg[] = { EGL_RENDERABLE_TYPE, EGL_OPENVG_BIT,
  2082                                            EGL_NONE };
  2076                                            EGL_NONE };
  2083         EGLBoolean eglRes = eglChooseConfig(iDisplay, KAttrib_list_vg, &config,1, &numConfigs);
  2077         EGLBoolean eglRes = eglChooseConfig(iDisplay, KAttrib_list_vg, &config,1, &numConfigs);
  2084         ASSERT_EGL_TRUE(eglRes == EGL_TRUE);
  2078         ASSERT_EGL_TRUE(eglRes == EGL_TRUE);