guestrendering/guestegl/src/eglapi.cpp
branchbug235_bringup_0
changeset 13 220791dae4c4
equal deleted inserted replaced
12:a4c94be9fb92 13:220791dae4c4
       
     1 // Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Implementation of guest egl stub functions
       
    15 
       
    16 #include "eglapi.h"
       
    17 #include <e32atomics.h>
       
    18 
       
    19 /*
       
    20  Only having the pointer as "Writeable Static Data" makes it very easy to tell if
       
    21  initialisation has been done: the pointer is not NULL!
       
    22  */
       
    23 CGuestEGL* guestEGL;
       
    24 // Writeable Static Data - causes constructor to be called at load DLL time.
       
    25 XGuestEglInitialiser GuestEglInitialiser;
       
    26 
       
    27 
       
    28 
       
    29 XGuestEglInitialiser::XGuestEglInitialiser()
       
    30 	{
       
    31 	EGL_TRACE("XGuestEglInitialiser::XGuestEglInitialiser() - guestEGL=0x%x", guestEGL);
       
    32 	if (!guestEGL)
       
    33 		{
       
    34 		// ensure VGHW Memory heap is created & channel to LDD is opened
       
    35 		CVghwUtils::InitStatics();
       
    36 		// Multi-Threading safe creation of CGuestEGL instance
       
    37 		if (!guestEGL)
       
    38 			{
       
    39 			// guarantee that initialisation of the object is flushed to memory before the pointer is published
       
    40 			__e32_atomic_store_rel_ptr(&guestEGL, CGuestEGL::New());
       
    41 			}
       
    42 	
       
    43 		// cast away volatile attribute
       
    44 		CGuestEGL* instance = (CGuestEGL*)guestEGL;
       
    45 		// cannot continue if alloc failed
       
    46 		EGLPANIC_ASSERT(guestEGL, EEglPanicCGuestEGLAllocFailed);
       
    47 		CVghwUtils::SetEglManagementApi(instance);
       
    48 	
       
    49 		CVghwUtils::CreateThreadState();
       
    50 		}
       
    51 	}
       
    52 
       
    53 
       
    54 XGuestEglInitialiser::~XGuestEglInitialiser()
       
    55 	{
       
    56 	EGL_TRACE("XGuestEglInitialiser::~XGuestEglInitialiser() - guestEGL=0x%x", guestEGL);
       
    57 	if (guestEGL)
       
    58 		{
       
    59 		delete guestEGL;
       
    60 		guestEGL = NULL;
       
    61 		}
       
    62 	CVghwUtils::DestroyStatics();
       
    63 	}
       
    64 
       
    65 
       
    66 _LIT(KEglPanicCategory, "Guest EGL");
       
    67 
       
    68 void EglPanic(TEglPanic aPanicCode, char* aPanicName, char* aCondition, char* aFile, TInt aLine)
       
    69 	{
       
    70 	if (aPanicName && aCondition && aFile)
       
    71 		{
       
    72 		RDebug::Printf("Guest EGL DLL Panic %s for failed Assert (%s),\n\tat %s:%d", aPanicName, aCondition, aFile, aLine);
       
    73 		}
       
    74 	else if (aPanicName && aFile)
       
    75 		{
       
    76 		RDebug::Printf("Guest EGL DLL Panic %s at %s:%d", aPanicName, aFile, aLine);
       
    77 		}
       
    78 	else
       
    79 		{
       
    80 		RDebug::Printf("Guest EGL DLL Panic %d (line %d)", aPanicCode, aLine);
       
    81 		}
       
    82 
       
    83 	User::Panic(KEglPanicCategory, aPanicCode);
       
    84 	}
       
    85 
       
    86 
       
    87 extern "C" {
       
    88 /*
       
    89  Note: Comments at the start of each EGL api are adapted from the Khronos EGL 1.4 specification.
       
    90  The text has been chosen/adapted to give a helpful overview of the function, and the errors
       
    91  that it may generate.  For more details see the full Khronos EGL specification.
       
    92  */
       
    93 
       
    94 
       
    95 /*
       
    96  Get details of the last EGL api error in this thread.
       
    97 
       
    98  Returns EGL_SUCCESS or an EGL_xxxx error constant.
       
    99  */
       
   100 EXPORT_C EGLint eglGetError(void)
       
   101     {
       
   102 	EGL_TRACE("eglGetError -->");
       
   103 
       
   104 	EGLint eglError = EGL_SUCCESS;
       
   105 	// threadState is non-null if an EGL api has been called in this thread
       
   106 	TEglThreadState* threadState = CVghwUtils::EglThreadState(); // do not create thread object for this API
       
   107 	if (threadState)
       
   108 		{ // get error (may be from parameter checking in this DLL or from Host EGL) - fetching resets error to EGL_SUCCESS
       
   109 		eglError = threadState->EglError();
       
   110 		}
       
   111 	EGL_TRACE("eglGetError returning eglError=0x%x <--", eglError);
       
   112 	return eglError;
       
   113     }
       
   114 
       
   115 /*
       
   116  Get display handle for display with requested properties.
       
   117 
       
   118  If display id is EGL_DEFAULT_DISPLAY, a default display is returned.
       
   119  Multiple calls made to eglGetDisplay with the same display-id will
       
   120  all return the same EGLDisplay handle.
       
   121  If no display matching display id is available, EGL_NO_DISPLAY is
       
   122  returned; no error condition is raised in this case.
       
   123  */
       
   124 EXPORT_C EGLDisplay eglGetDisplay(EGLNativeDisplayType aDisplayId)
       
   125 	{
       
   126 	EGL_TRACE("eglGetDisplay Display Id=%d -->", aDisplayId);
       
   127 
       
   128 	EGLDisplay display = EGL_NO_DISPLAY;
       
   129 	// Most likely eglGetDisplay is the first API called, so try initialising EGL instance first
       
   130 	CGuestEGL& instance = Instance();
       
   131 	TEglThreadState* threadState = CVghwUtils::CreateThreadState();
       
   132 	if (threadState)
       
   133 		{
       
   134 		display = instance.eglGetDisplay(*threadState, aDisplayId);
       
   135 		}
       
   136 	EGL_TRACE("eglGetDisplay result Display=%d <--", display);
       
   137 	return display;
       
   138 	}
       
   139 
       
   140 /*
       
   141  Initialize EGL on a display.
       
   142 
       
   143  EGL_TRUE is returned on success, and major and minor are updated with the major
       
   144  and minor version numbers of the EGL implementation (for example, in an EGL
       
   145  1.2 implementation, the values of *major and *minor would be 1 and 2, respectively).
       
   146  major and minor are not updated if they are specified as NULL.
       
   147  EGL_FALSE is returned on failure and major and minor are not updated. An
       
   148  EGL_BAD_DISPLAY error is generated if the dpy argument does not refer to a valid
       
   149  EGLDisplay. An EGL_NOT_INITIALIZED error is generated if EGL cannot be
       
   150  initialized for an otherwise valid dpy.
       
   151  */
       
   152 EXPORT_C EGLBoolean eglInitialize(EGLDisplay aDisplay, EGLint *aMajor, EGLint *aMinor)
       
   153 	{
       
   154 	EGL_TRACE("eglInitialize Display=%d, Major 0x%x, Minor 0x%x", aDisplay, aMajor, aMinor );
       
   155 
       
   156 	TEglThreadState* threadState = CVghwUtils::CreateThreadState();
       
   157 	EGLBoolean success = EGL_FALSE;
       
   158 	if (threadState)
       
   159 		{
       
   160 		success = Instance().eglInitialize(*threadState, aDisplay, aMajor, aMinor);
       
   161 		}
       
   162 	EGL_TRACE("eglInitialize <- result=%d", success);
       
   163 	return success;
       
   164 	}
       
   165 
       
   166 /*
       
   167  Marks all EGL-specific resources associated with the specified display
       
   168  for deletion.
       
   169 
       
   170  If the dpy argument does not refer to a valid EGLDisplay, EGL_FALSE is
       
   171  returned, and an EGL_BAD_DISPLAY error is generated.
       
   172  */
       
   173 EXPORT_C EGLBoolean eglTerminate(EGLDisplay aDisplay)
       
   174 	{
       
   175 	EGL_TRACE("eglTerminate Display=%d", aDisplay);
       
   176 
       
   177 	EGLBoolean result = EGL_FALSE;
       
   178 	TEglThreadState* threadState = CVghwUtils::CreateThreadState();
       
   179 	if (threadState)
       
   180 		{
       
   181 		result = Instance().eglTerminate(*threadState, aDisplay);
       
   182 		}
       
   183 	return result;
       
   184 	}
       
   185 
       
   186 /*
       
   187  Returns a pointer to a static, zero-terminated string describing some aspect
       
   188  of the EGL implementation running on the specified display. name may be one
       
   189  of EGL_CLIENT_APIS, EGL_EXTENSIONS, EGL_VENDOR, or EGL_VERSION.
       
   190 
       
   191  The EGL_CLIENT_APIS string describes which client rendering APIs are
       
   192  supported. It is zero-terminated and contains a space-separated list of API
       
   193  names, which must include at least one of ‘‘OpenGL’’, ‘‘OpenGL_ES’’ or
       
   194  ‘‘OpenVG’’.
       
   195 
       
   196  The EGL_EXTENSIONS string describes which EGL extensions are supported
       
   197  by the EGL implementation running on the specified display, and for the
       
   198  current client API context. The string is zero terminated and contains a
       
   199  space-separated list of extension names;  extension names themselves do
       
   200  not contain spaces. If there are no extensions to EGL, then the empty string
       
   201  is returned.
       
   202 
       
   203  The format and contents of the EGL_VENDOR string is implementation dependent.
       
   204 
       
   205  The format of the EGL_VERSION string is:
       
   206  <major version.minor version><space><vendor specific info>
       
   207 
       
   208  On failure, NULL is returned. An EGL_NOT_INITIALIZED error is generated
       
   209  if EGL is not initialized for dpy. An EGL_BAD_PARAMETER error is generated if
       
   210  name is not one of the values described above.
       
   211  */
       
   212 EXPORT_C const char* eglQueryString(EGLDisplay aDisplay, EGLint aName)
       
   213     {
       
   214     EGL_TRACE("eglQueryString Display=%d, Name=0x%x", aDisplay, aName);
       
   215 
       
   216     return Instance().eglQueryString(aDisplay, aName);
       
   217     }
       
   218 
       
   219 /*
       
   220  Get the list of all EGLConfigs that are available on the specified display.
       
   221 
       
   222  On failure, EGL_FALSE is returned. An EGL_NOT_INITIALIZED error is generated
       
   223  if EGL is not initialized on dpy. An EGL_BAD_PARAMETER error is generated
       
   224  if num config is NULL.
       
   225  */
       
   226 EXPORT_C EGLBoolean eglGetConfigs(EGLDisplay aDisplay, EGLConfig *aConfigs,
       
   227 			 EGLint aConfigSize, EGLint *aNumConfig)
       
   228 	{
       
   229 	EGL_TRACE("eglGetConfigs Display=%d, ConfigSize=%d , NumConfig=0x%x -->", aDisplay, aConfigSize, aNumConfig);
       
   230 	
       
   231 	EGLBoolean result = EGL_FALSE;
       
   232 	TEglThreadState* threadState = CVghwUtils::CreateThreadState();
       
   233 	if (threadState)
       
   234 		{
       
   235 		result = Instance().eglGetConfigs(*threadState, aDisplay, aConfigs, aConfigSize, aNumConfig);
       
   236 		}
       
   237 	EGL_TRACE("eglGetConfigs hostResult=%d, NumConfig-%d <--", result, aNumConfig ? *aNumConfig : 0);
       
   238 	return result;
       
   239 	}
       
   240 
       
   241 /*
       
   242  Get EGLConfigs that match a list of attributes. The return value and the meaning
       
   243  of configs, config size, and num config are the same as for eglGetConfigs.
       
   244  However, only configurations matching attrib list will be returned.
       
   245 
       
   246  On failure, EGL_FALSE is returned. An EGL_BAD_ATTRIBUTE error is generated
       
   247  if attrib list contains an undefined EGL attribute or an attribute value that is
       
   248  unrecognized or out of range.
       
   249  */
       
   250 EXPORT_C EGLBoolean eglChooseConfig(EGLDisplay aDisplay, const EGLint *aAttribList,
       
   251 			   EGLConfig *aConfigs, EGLint aConfigSize, EGLint *aNumConfig)
       
   252 	{
       
   253 	EGL_TRACE("eglChooseConfig Display=%d, AttribList=0x%x, Configs=0x%x, ConfigSize=%d, NumConfig=0x%x -->",
       
   254 			aDisplay, aAttribList, aConfigs, aConfigSize, aNumConfig);
       
   255 	EGL_TRACE_ATTRIB_LIST(aAttribList);
       
   256 
       
   257 	EGLBoolean result = EGL_FALSE;
       
   258 	TEglThreadState* threadState = CVghwUtils::CreateThreadState();
       
   259 	if (threadState)
       
   260 		{
       
   261 		result = Instance().eglChooseConfig(*threadState, aDisplay, aAttribList, aConfigs, aConfigSize, aNumConfig);
       
   262 		}
       
   263 
       
   264 	EGL_TRACE("eglChooseConfig Result=%s, Num configs=%d, First config=%d <--",
       
   265 			result ? "success" : "fail", 
       
   266 			aNumConfig ? *aNumConfig : 0,
       
   267 			(aConfigs && aNumConfig && (*aNumConfig > 0)) ? *aConfigs : -1);
       
   268 	return result;
       
   269 	}
       
   270 
       
   271 /*
       
   272  Get the value of an EGLConfig attribute.
       
   273 
       
   274  On failure returns EGL_FALSE. If attribute
       
   275  is not a valid attribute then EGL_BAD_ATTRIBUTE is generated.
       
   276  */
       
   277 EXPORT_C EGLBoolean eglGetConfigAttrib(EGLDisplay aDisplay, EGLConfig aConfig,
       
   278 			      EGLint aAttribute, EGLint *aValue)
       
   279 	{
       
   280 	EGLBoolean result = EGL_FALSE;
       
   281 	TEglThreadState* threadState = CVghwUtils::CreateThreadState();
       
   282 	if (threadState)
       
   283 		{
       
   284 		result = Instance().eglGetConfigAttrib(*threadState, aDisplay, aConfig, aAttribute, aValue);
       
   285 		}
       
   286 	return result;
       
   287 	}
       
   288 
       
   289 /*
       
   290  Creates an onscreen EGLSurface and returns a handle to it. Any EGL context created
       
   291  with a compatible EGLConfig can be used to render into this surface.
       
   292 
       
   293  On failure returns EGL_NO_SURFACE. If the attributes of win do not correspond to
       
   294  config, then an EGL_BAD_MATCH error is generated. If config does not support
       
   295  rendering to windows (the EGL_SURFACE_TYPE attribute does not contain
       
   296  EGL_WINDOW_BIT), an EGL_BAD_MATCH error is generated. If config does not support
       
   297  the colorspace or  alpha format attributes specified in attrib list (as defined
       
   298  for eglCreateWindowSurface), an EGL_BAD_MATCH error is generated. If config is
       
   299  not a valid EGLConfig, an EGL_BAD_CONFIG error is generated. If win is not a valid
       
   300  native window handle, then an EGL_BAD_NATIVE_WINDOW error should be generated. If
       
   301  there is already an EGLConfig associated with win (as a result of a previous
       
   302  eglCreateWindowSurface call), then an EGL_BAD_ALLOC error is generated. Finally,
       
   303  if the implementation cannot allocate resources for the new EGL window, an
       
   304  EGL_BAD_ALLOC error is generated.
       
   305  */
       
   306 EXPORT_C EGLSurface eglCreateWindowSurface(EGLDisplay aDisplay, EGLConfig aConfig,
       
   307 				  EGLNativeWindowType aWindow, const EGLint *aAttribList)
       
   308 	{
       
   309 	EGL_TRACE("eglCreateWindowSurface Display=%d, Config=%d, Window=0x%x -->", aDisplay, aConfig, aWindow);
       
   310 
       
   311 	EGLSurface newSurface = EGL_NO_SURFACE;
       
   312 	TEglThreadState* threadState = CVghwUtils::CreateThreadState();
       
   313 	if (threadState)
       
   314 		{
       
   315 		newSurface = Instance().eglCreateWindowSurface(*threadState, aDisplay, aConfig, aWindow, aAttribList);
       
   316 		}
       
   317 	EGL_TRACE("eglCreateWindowSurface new Surface=0x%x <--", newSurface);
       
   318 	return newSurface;
       
   319 	}
       
   320 
       
   321 /*
       
   322  Creates a single off-screen pbuffer surface and returns a handle to it.
       
   323 
       
   324  On failure returns EGL_NO_SURFACE. If the pbuffer could not be created due
       
   325  to insufficient resources, then an EGL_BAD_ALLOC error is generated. If
       
   326  config is not a valid EGLConfig, an EGL_BAD_CONFIG error is generated. If
       
   327  the value specified for either EGL_WIDTH or EGL_HEIGHT is less than zero,
       
   328  an EGL_BAD_PARAMETER error is generated. If config does not support
       
   329  pbuffers, an EGL_BAD_MATCH error is generated. In addition, an EGL_BAD_MATCH
       
   330  error is generated if any of the following conditions are true:
       
   331  * The EGL_TEXTURE_FORMAT attribute is not EGL_NO_TEXTURE, and EGL_WIDTH
       
   332    and/or EGL_HEIGHT specify an invalid size (e.g., the texture size is
       
   333    not a power of two, and the underlying OpenGL ES implementation does not
       
   334    support non-power-of-two textures).
       
   335  * The EGL_TEXTURE_FORMAT attribute is EGL_NO_TEXTURE, and EGL_TEXTURE_TARGET
       
   336    is something other than EGL_NO_TEXTURE; or, EGL_TEXTURE_FORMAT is
       
   337    something other than EGL_NO_TEXTURE, and EGL_TEXTURE_TARGET is
       
   338    EGL_NO_TEXTURE.
       
   339  Finally, an EGL_BAD_ATTRIBUTE error is generated if any of the EGL_-
       
   340  TEXTURE_FORMAT, EGL_TEXTURE_TARGET, or EGL_MIPMAP_TEXTURE attributes
       
   341  are specified, but config does not support OpenGL ES rendering (e.g.
       
   342  the EGL_RENDERABLE_TYPE attribute does not include at least one of EGL_-
       
   343  OPENGL_ES_BIT or EGL_OPENGL_ES2_BIT.
       
   344  */
       
   345 EXPORT_C EGLSurface eglCreatePbufferSurface(EGLDisplay aDisplay, EGLConfig aConfig, const EGLint *aAttribList)
       
   346 	{
       
   347 	EGL_TRACE("eglCreatePbufferSurface Display=%d, Config=%d -->", aDisplay, aConfig);
       
   348 	EGL_TRACE_ATTRIB_LIST(aAttribList);
       
   349 
       
   350 	EGLSurface newSurface = EGL_NO_SURFACE;
       
   351 	TEglThreadState* threadState = CVghwUtils::CreateThreadState();
       
   352 	if (threadState)
       
   353 		{
       
   354 		newSurface = Instance().eglCreatePbufferSurface(*threadState, aDisplay, aConfig, aAttribList);
       
   355 		}
       
   356 	EGL_TRACE("eglCreatePbufferSurface new Surface=0x%x <--", newSurface);
       
   357 	return newSurface;
       
   358 	}
       
   359 
       
   360 /*
       
   361  Creates an offscreen EGLSurface and returns a handle to it. Any EGL context
       
   362  created with a compatible EGLConfig can be used to render into this surface.
       
   363 
       
   364  To create a pixmap rendering surface, first create a native platform pixmap,
       
   365  then select an EGLConfig matching the pixel format of that pixmap (calling
       
   366  eglChooseConfig with an attribute list including EGL_MATCH_NATIVE_PIXMAP
       
   367  returns only EGLConfigs matching the pixmap specified in the attribute list).
       
   368 
       
   369  Returns EGL_NO_SURFACE on failure. If the attributes of pixmap do not
       
   370  correspond to config, then an EGL_BAD_MATCH error is generated. If config does
       
   371  not support rendering to pixmaps (the EGL_SURFACE_TYPE attribute does not
       
   372  contain EGL_PIXMAP_BIT), an EGL_BAD_MATCH error is generated. If config does
       
   373  not support the colorspace or alpha format attributes specified in attrib list
       
   374  (as defined for eglCreateWindowSurface), an EGL_BAD_MATCH error is generated.
       
   375  If config is not a valid EGLConfig, an EGL_BAD_CONFIG error is generated. If
       
   376  pixmap is not a valid native pixmap handle, then an EGL_BAD_NATIVE_PIXMAP
       
   377  error should be generated. If there is already an EGLSurface associated with
       
   378  pixmap (as a result of a previous eglCreatePixmapSurface call), then a
       
   379  EGL_BAD_ALLOC error is generated. Finally, if the implementation cannotallocate
       
   380  resources for the new EGL pixmap, an EGL_BAD_ALLOC error is generated.
       
   381  */
       
   382 EXPORT_C EGLSurface eglCreatePixmapSurface(EGLDisplay aDisplay, EGLConfig aConfig, EGLNativePixmapType aPixmap, const EGLint *aAttribList)
       
   383 	{
       
   384 	EGL_TRACE("eglCreatePixmapSurface Display=%d, Config=%d, Pixmap=0x%x -->", aDisplay, aConfig, aPixmap);
       
   385 
       
   386 	TEglThreadState* threadState = CVghwUtils::CreateThreadState();
       
   387 	EGLSurface newSurface = EGL_NO_SURFACE;
       
   388 	if (threadState)
       
   389 		{
       
   390 		newSurface = Instance().eglCreatePixmapSurface(*threadState, aDisplay, aConfig, aPixmap, aAttribList);
       
   391 		}
       
   392 	EGL_TRACE("eglCreatePixmapSurface new Surface=0x%x <--", newSurface);
       
   393 	return newSurface;
       
   394 	}
       
   395 
       
   396 /*
       
   397  Destroy an EGLSurface of any type (window, pbuffer, or pixmap).
       
   398 
       
   399  All resources associated with surface which were allocated by EGL are marked
       
   400  for deletion as soon as possible. Following eglDestroySurface, the surface
       
   401  and  the handle referring to it are treated in the same fashion as a surface
       
   402  destroyed by eglTerminate.
       
   403 
       
   404  Resources associated with surface but not allocated by EGL, such as native
       
   405  windows, native pixmaps, or client API buffers, are not affected when the
       
   406  surface is destroyed. Only storage actually allocated by EGL is marked for
       
   407  deletion. Furthermore, resources associated with a pbuffer surface are not
       
   408  released until all color buffers of that pbuffer bound to a OpenGL ES texture
       
   409  object have been released.
       
   410 
       
   411  Returns EGL_FALSE on failure. An EGL_BAD_SURFACE error is generated if surface
       
   412  is not a valid rendering surface.
       
   413  */
       
   414 EXPORT_C EGLBoolean eglDestroySurface(EGLDisplay aDisplay, EGLSurface aSurface)
       
   415 	{
       
   416 	EGL_TRACE("eglDestroySurface Display=%d, Surface=0x%x", aDisplay, aSurface);
       
   417 
       
   418 	TEglThreadState* threadState = CVghwUtils::CreateThreadState();
       
   419 	EGLBoolean result = EGL_FALSE;
       
   420 	if (threadState)
       
   421 		{
       
   422 		result = Instance().eglDestroySurface(*threadState, aDisplay, aSurface);
       
   423 		}
       
   424 	return result;
       
   425 	}
       
   426 
       
   427 /*
       
   428  Returns in value the value of attribute for surface. attribute must be set
       
   429  to one of the attributes in table 3.5 of the EGL specification.
       
   430 
       
   431  Returns EGL_FALSE on failure and value is not updated. If attribute is not a
       
   432  valid EGL surface attribute, then an EGL_BAD_ATTRIBUTE error is generated. If
       
   433  surface is not a valid EGLSurface then an EGL_BAD_SURFACE error is generated.
       
   434  */
       
   435 EXPORT_C EGLBoolean eglQuerySurface(EGLDisplay aDisplay, EGLSurface aSurface, EGLint aAttribute, EGLint *aValue)
       
   436     {
       
   437     EGL_TRACE("eglQuerySurface display=%d, surface=%d, attribute=%d", aDisplay, aSurface, aAttribute);
       
   438     TEglThreadState* threadState = CVghwUtils::CreateThreadState();
       
   439     if (threadState)
       
   440     	{
       
   441 		return Instance().eglQuerySurface(*threadState, aDisplay, aSurface, aAttribute, aValue);
       
   442     	}
       
   443     return EGL_FALSE;
       
   444     }
       
   445 
       
   446 /*
       
   447  Set the current rendering API, this is set on a per-thread basis.
       
   448 
       
   449  api must specify one of the supported client APIs , either EGL_OPENVG_API
       
   450  or EGL_OPENGL_ES_API. (EGL_OPENGL_API is not currently supported by Symbian.)
       
   451 
       
   452  Returns EGL_FALSE on failure. If api is not one of the values specified
       
   453  above, or if the client API specified by api is not supported by the
       
   454  implementation, an EGL_BAD_PARAMETER error is generated.
       
   455  */
       
   456 EXPORT_C EGLBoolean eglBindAPI(EGLenum aApi)
       
   457 	{
       
   458 	EGL_TRACE("eglBindAPI 0x%x (%s)", aApi, (aApi == EGL_OPENGL_ES_API) ? "EGL_OPENGL_ES_API" : (aApi == EGL_OPENVG_API) ? "EGL_OPENVG_API" : "???");
       
   459 
       
   460 	TEglThreadState* threadState = CVghwUtils::CreateThreadState();
       
   461 	EGLBoolean result = EGL_FALSE;
       
   462 	if (threadState)
       
   463 		{
       
   464 		if ( (aApi == EGL_OPENGL_ES_API) || (aApi == EGL_OPENVG_API) )
       
   465 			{
       
   466 			threadState->SetEglBoundApi(aApi);
       
   467 			result = EGL_TRUE;
       
   468 			RemoteFunctionCallData rfcdata; EglRFC eglApiData(rfcdata);
       
   469 			eglApiData.Init(EglRFC::EeglBindAPI);
       
   470 			eglApiData.AppendEGLenum(aApi);
       
   471 			EGLBoolean hostResult = threadState->ExecEglBooleanCmd(eglApiData);
       
   472 			// confirm Host EGL matches what we think about the parameter
       
   473 			EGLPANIC_ASSERT_DEBUG(hostResult == result, EEglPanicTemp);
       
   474 			}
       
   475 		else
       
   476 			{
       
   477 			threadState->SetEglError(EGL_BAD_PARAMETER);
       
   478 			}
       
   479 		}
       
   480 	return result;
       
   481 	}
       
   482 
       
   483 /*
       
   484  Get the current rendering API, this is set on a per-thread basis.
       
   485 
       
   486  The value returned will be one of the valid api parameters to eglBindAPI,
       
   487  or EGL_NONE.
       
   488 
       
   489  The initial value of the current rendering API is EGL_OPENGL_ES_API.
       
   490  Applications using multiple client APIs are responsible for ensuring
       
   491  the current rendering API is correct before calling the functions
       
   492  eglCreateContext, eglGetCurrentContext, eglGetCurrentDisplay,
       
   493  eglGetCurrentSurface, eglMakeCurrent (when its ctx parameter is
       
   494  EGL_NO_CONTEXT), eglWaitClient, or eglWaitNative.
       
   495  */
       
   496 EXPORT_C EGLenum eglQueryAPI(void)
       
   497 	{
       
   498 	EGL_TRACE("eglQueryAPI");
       
   499 
       
   500 	EGLenum result = EGL_OPENGL_ES_API;
       
   501 	TEglThreadState* threadState = CVghwUtils::CreateThreadState();
       
   502 	if (threadState)
       
   503 		{ // EGL threadState exists
       
   504 		result = threadState->EglBoundApi();
       
   505 		threadState->SetEglError(EGL_SUCCESS);
       
   506 #ifdef _DEBUG
       
   507 		// Debug build checks that local threadState is in sync with Host EGL state
       
   508 		RemoteFunctionCallData rfcdata; EglRFC eglApiData( rfcdata );
       
   509 		eglApiData.Init(EglRFC::EeglQueryAPI);
       
   510 		threadState->ExecuteEglNeverErrorCmd(eglApiData);
       
   511 		EGLPANIC_ASSERT(result == (EGLenum)eglApiData.ReturnValue(), EEglPanicHostAndClientBoundApiOutOfSync);
       
   512 #endif
       
   513 		}
       
   514 	return result;
       
   515 	}
       
   516 
       
   517 /*
       
   518  Wait for client (Open GL ES, VG, ...) rendering to complete, before
       
   519  using Symbian native rendering.
       
   520 
       
   521  Returns EGL_TRUE on success. If there is no current context for  the current
       
   522  rendering API, the function has no effect but still returns EGL_TRUE. If the
       
   523  surface associated with the calling thread’s current context is no longer valid,
       
   524  EGL_FALSE is returned and an EGL_BAD_CURRENT_SURFACE error is generated.
       
   525  */
       
   526 EXPORT_C EGLBoolean eglWaitClient(void)
       
   527     {
       
   528 	EGL_TRACE("eglWaitClient");
       
   529 
       
   530 	EGLBoolean result = EGL_FALSE;
       
   531 	TEglThreadState* threadState = CVghwUtils::CreateThreadState();
       
   532 	if (threadState)
       
   533 		{
       
   534 		result = Instance().eglWaitClient(*threadState);
       
   535 		}
       
   536 	return result;
       
   537     }
       
   538 
       
   539 /*
       
   540  Return EGL to its state at thread initialization.
       
   541 
       
   542  EGL_TRUE is returned on success, and the following actions are taken:
       
   543  * For each client API supported by EGL, if there is a currently bound context,
       
   544    that context is released. This is equivalent to calling eglMakeCurrent
       
   545    with ctx set to EGL_NO_CONTEXT and both draw and read set to EGL_NO_SURFACE.
       
   546  * The current rendering API is reset to its value at thread initialization.
       
   547  * Any additional implementation-dependent per-thread state maintained by
       
   548    EGL is marked for deletion as soon as possible.
       
   549  Returns EGL_FALSE on failure, there are no defined conditions under which
       
   550  failure will occur.
       
   551  */
       
   552 EXPORT_C EGLBoolean eglReleaseThread(void)
       
   553 	{
       
   554 	EGL_TRACE("eglReleaseThread -->");
       
   555 
       
   556 	TEglThreadState* threadState = CVghwUtils::EglThreadState(); // fetching pre-existing thread state, if any
       
   557 	if (threadState)
       
   558 		{
       
   559 		RemoteFunctionCallData rfcdata; EglRFC eglApiData( rfcdata );
       
   560 		eglApiData.Init(EglRFC::EeglReleaseThread);
       
   561 	    threadState->ExecuteEglNeverErrorCmd(eglApiData);
       
   562 
       
   563 	    // release client side memory
       
   564 		CVghwUtils::ReleaseThreadState();
       
   565 		}
       
   566 
       
   567 	EGL_TRACE("eglReleaseThread <--");
       
   568 	return EGL_TRUE;
       
   569 	}
       
   570 
       
   571 /*
       
   572  Creates a single pbuffer surface bound to the specified buffer for part or
       
   573  all of its buffer storage, and returns a handle to it. The width  and height
       
   574  of the pbuffer are determined by the width and height of buffer.
       
   575 
       
   576  Currently, the only client API resources which may be bound in this fashion
       
   577  are OpenVG VGImage objects.
       
   578 
       
   579  On failure eglCreatePbufferFromClientBuffer returns EGL_NO_SURFACE. In
       
   580  addition to the errors described eglCreatePbufferSurface,
       
   581  eglCreatePbufferFromClientBuffer may fail and generate errors for the
       
   582  following reasons:
       
   583  * If buftype is not a recognized client API resource type (e.g. is not
       
   584    EGL_OPENVG_IMAGE), an EGL_BAD_PARAMETER error is generated.
       
   585  * If buffer is not a valid handle or name of a client API resource of the
       
   586    specified buftype in the currently bound context corresponding to that
       
   587    type, an EGL_BAD_PARAMETER error is generated.
       
   588  * If the buffers contained in buffer do not correspond to a proper subset
       
   589    of the buffers described by config, and match the bit depths for those
       
   590    buffers specified in config, then an EGL_BAD_MATCH error is generated.
       
   591    For example, a VGImage with pixel format VG_lRGBA_8888 corresponds to an
       
   592    EGLConfig with EGL_RED_SIZE, EGL_GREEN_SIZE, EGL_BLUE_SIZE, and
       
   593    EGL_ALPHA_SIZE values of 8.
       
   594  * If no context corresponding to the specified buftype is current, an
       
   595    EGL_BAD_ACCESS error is generated.
       
   596  * There may be additional constraints on which types of buffers may be
       
   597    bound to EGL surfaces, as described in client API specifications. If
       
   598    those constraints are violated, then an EGL_BAD_MATCH error is generated.
       
   599  * If buffer is already bound to another pbuffer, or is in use by a client
       
   600    API an EGL_BAD_ACCESS error is generated.
       
   601  */
       
   602 EXPORT_C EGLSurface eglCreatePbufferFromClientBuffer(EGLDisplay aDisplay, EGLenum aBufType, EGLClientBuffer aBuffer,
       
   603 			EGLConfig aConfig, const EGLint *aAttribList)
       
   604 	{
       
   605 	EGL_TRACE("eglCreatePbufferFromClientBuffer Display=%d, BufType=%d, Config=%d -->", aDisplay, aBufType, aConfig);
       
   606 	EGL_TRACE_ATTRIB_LIST(aAttribList);
       
   607 
       
   608 	EGLSurface newSurface = EGL_NO_SURFACE;
       
   609 	TEglThreadState* threadState = CVghwUtils::CreateThreadState();
       
   610 	if (threadState)
       
   611 		{
       
   612 		newSurface = Instance().eglCreatePbufferFromClientBuffer(*threadState, aDisplay, aBufType, aBuffer, aConfig, aAttribList);
       
   613 		}
       
   614 	EGL_TRACE("eglCreateWindowSurface new Surface=0x%x <--", newSurface);
       
   615 	return newSurface;
       
   616 	}
       
   617 
       
   618 /*
       
   619  Set an attribute for an EGLSurface.
       
   620 
       
   621  The specified attribute of surface is set to value. Attributes that can be
       
   622  specified are EGL_MIPMAP_LEVEL, EGL_MULTISAMPLE_RESOLVE, and EGL_SWAP_BEHAVIOR.
       
   623 
       
   624  Returns EGL_FALSE on failure and value is not updated. If attribute is not a
       
   625  valid EGL surface attribute, then an EGL_BAD_ATTRIBUTE error is generated. If
       
   626  surface is not a valid EGLSurface then an EGL_BAD_SURFACE error is generated.
       
   627  */
       
   628 EXPORT_C EGLBoolean eglSurfaceAttrib(EGLDisplay aDisplay, EGLSurface aSurface,
       
   629 			    EGLint aAttribute, EGLint aValue)
       
   630 	{
       
   631 	EGL_TRACE("eglSurfaceAttrib Display=%d, Surface=0x%x, Attribute=0x%x, Value=%d", aDisplay, aSurface, aAttribute, aValue);
       
   632 
       
   633 	EGLBoolean result = EGL_FALSE;
       
   634 	TEglThreadState* threadState = CVghwUtils::CreateThreadState();
       
   635 	if (threadState)
       
   636 		{
       
   637 		result = Instance().eglSurfaceAttrib(*threadState, aDisplay, aSurface, aAttribute, aValue);
       
   638 		}
       
   639 	return result;
       
   640 	}
       
   641 
       
   642 /*
       
   643  Defines a two-dimensional texture image. The texture image consists of the image
       
   644  data in buffer for the specified surface, and need not be copied. Currently the
       
   645  only value accepted for buffer is EGL_BACK_BUFFER, which indicates the buffer into
       
   646  which OpenGL ES rendering is taking place (this is true even when using a
       
   647  singlebuffered surface, such as a pixmap). In future versions of EGL, additional buffer
       
   648  values may be allowed to bind textures to other buffers in an EGLSurface.
       
   649 
       
   650  eglBindTexImage is ignored if there is no current rendering context.
       
   651 
       
   652  If eglBindTexImage is called and the surface attribute EGL_TEXTURE_FORMAT is set
       
   653  to EGL_NO_TEXTURE, then an EGL_BAD_MATCH error is returned. If buffer is already
       
   654  bound to a texture then an EGL_BAD_ACCESS error is returned. If buffer is not a
       
   655  valid buffer, then an EGL_BAD_PARAMETER error is generated. If surface is not a
       
   656  valid EGLSurface, or is not a pbuffer surface supporting texture
       
   657  binding, then an EGL_BAD_SURFACE error is generated.
       
   658  */
       
   659 EXPORT_C EGLBoolean eglBindTexImage(EGLDisplay aDisplay, EGLSurface aSurface, EGLint aBuffer)
       
   660 	{
       
   661 	EGL_TRACE("eglBindTexImage Display=%d, Surface=0x%x, Buffer=%d", aDisplay, aSurface, aBuffer);
       
   662 
       
   663 	EGLBoolean result = EGL_FALSE;
       
   664 	TEglThreadState* threadState = CVghwUtils::CreateThreadState();
       
   665 	if (threadState)
       
   666 		{
       
   667 		result = Instance().eglBindTexImage(*threadState, aDisplay, aSurface, aBuffer);
       
   668 		}
       
   669 	return result;
       
   670 	}
       
   671 
       
   672 /*
       
   673  The specified color buffer is released back to the surface. The surface is
       
   674  made  available for reading and writing when it no longer has any color
       
   675  buffers bound as textures.
       
   676 
       
   677  If the value of surface attribute EGL_TEXTURE_FORMAT is EGL_NO_TEXTURE,
       
   678  then an EGL_BAD_MATCH error is returned. If buffer is not a valid buffer
       
   679  (currently only EGL_BACK_BUFFER may  be specified), then an
       
   680  EGL_BAD_PARAMETER error is generated. If surface is not a valid EGLSurface,
       
   681  or is not a bound pbuffer surface, then an EGL_BAD_SURFACE error is
       
   682  returned.
       
   683  */
       
   684 EXPORT_C EGLBoolean eglReleaseTexImage(EGLDisplay aDisplay, EGLSurface aSurface, EGLint aBuffer)
       
   685 	{
       
   686 	EGL_TRACE("eglReleaseTexImage Display=%d, Surface=0x%x, Buffer=%d", aDisplay, aSurface, aBuffer);
       
   687 
       
   688 	EGLBoolean result = EGL_FALSE;
       
   689 	TEglThreadState* threadState = CVghwUtils::CreateThreadState();
       
   690 	if (threadState)
       
   691 		{
       
   692 		result = Instance().eglReleaseTexImage(*threadState, aDisplay, aSurface, aBuffer);
       
   693 		}
       
   694 	return result;
       
   695 	}
       
   696 
       
   697 /*
       
   698  Specifies the minimum number of video frame periods per buffer swap for
       
   699  the window associated with the current context. The interval takes effect when
       
   700  eglSwapBuffers is first called subsequent to the eglSwapInterval call.
       
   701 
       
   702  Returns EGL_FALSE on failure. If there is no current context on the calling
       
   703  thread, a EGL_BAD_CONTEXT error is generated. If there is no surface bound
       
   704  to the current context, a EGL_BAD_SURFACE error is generated.
       
   705  */
       
   706 EXPORT_C EGLBoolean eglSwapInterval(EGLDisplay aDisplay, EGLint aInterval)
       
   707 	{
       
   708 	EGL_TRACE("eglSwapInterval Display=%d, Interval=%d frames", aDisplay, aInterval);
       
   709 
       
   710 	EGLBoolean result = EGL_FALSE;
       
   711 	TEglThreadState* threadState = CVghwUtils::CreateThreadState();
       
   712 	if (threadState)
       
   713 		{
       
   714 		result = Instance().eglSwapInterval(*threadState, aDisplay, aInterval);
       
   715 		}
       
   716 	return result;
       
   717 	}
       
   718 
       
   719 /*
       
   720  Create a rendering context for the current rendering API.
       
   721 
       
   722  If eglCreateContext succeeds, it initializes the context to the initial
       
   723  state defined for the current rendering API, and returns a handle to it.
       
   724  The context can be used to render to any compatible EGLSurface. Although
       
   725  contexts are specific to a single client API , all contexts created in
       
   726  EGL exist in a single namespace. This allows many EGL calls which manage
       
   727  contexts to avoid use of the current rendering API.
       
   728 
       
   729  On failure returns EGL_NO_CONTEXT. If the current rendering api is EGL_NONE,
       
   730  then an EGL_BAD_MATCH error is generated (this situation can only arise in
       
   731  an implementation which does not support OpenGL ES, and prior to the first
       
   732  call to eglBindAPI). If share context is neither zero nor a valid context
       
   733  of the same client API type as the newly created context, then an EGL_-
       
   734  BAD_CONTEXT error is generated.
       
   735 
       
   736  If config is not a valid EGLConfig, or does not support the requested client
       
   737  API , then an EGL_BAD_CONFIG error is generated (this includes requesting creation
       
   738  of an OpenGL ES 1.x context when the EGL_RENDERABLE_TYPE attribute
       
   739  of config does not contain EGL_OPENGL_ES_BIT, or creation of an OpenGL ES
       
   740  2.x context when the attribute does not contain EGL_OPENGL_ES2_BIT).
       
   741 
       
   742  If the OpenGL or OpenGL ES server context state for share context exists in
       
   743  an address space that cannot be shared with the newly created context, if share -
       
   744  context was created on a different display than the one referenced by config, or if
       
   745  the contexts are otherwise incompatible (for example, one context being associated
       
   746  with a hardware device driver and the other with a software renderer), then an
       
   747  EGL_BAD_MATCH error is generated. If the server does not have enough resources
       
   748  to allocate the new context, then an EGL_BAD_ALLOC error is generated.
       
   749  */
       
   750 EXPORT_C EGLContext eglCreateContext(EGLDisplay aDisplay, EGLConfig aConfig,
       
   751 				EGLContext aShareContext, const EGLint *aAttribList)
       
   752 	{
       
   753 	EGL_TRACE("eglCreateContext Display=%d, Config=%d, ShareContext=%d -->", aDisplay, aConfig, aShareContext);
       
   754 	EGL_TRACE_ATTRIB_LIST(aAttribList);
       
   755 
       
   756 	EGLContext result = EGL_NO_CONTEXT;
       
   757 	TEglThreadState* threadState = CVghwUtils::CreateThreadState();
       
   758 	if (threadState)
       
   759 		{
       
   760 		result = Instance().eglCreateContext(*threadState, aDisplay, aConfig, aShareContext, aAttribList);
       
   761 		}
       
   762 	EGL_TRACE("eglCreateContext new context=%d <--", result);
       
   763 	return result;
       
   764 	}
       
   765 
       
   766 /*
       
   767  Destroy a rendering context.
       
   768 
       
   769  All resources associated with ctx are marked for deletion as soon as possible.
       
   770  Following eglDestroyContext, the context and the handle referring to it are
       
   771  treated in the same fashion as a context destroyed by eglTerminate.
       
   772 
       
   773  Returns EGL_FALSE on failure. An EGL_BAD_CONTEXT error is generated if ctx is
       
   774  not a valid context.
       
   775  */
       
   776 EXPORT_C EGLBoolean eglDestroyContext(EGLDisplay aDisplay, EGLContext aContext)
       
   777 	{
       
   778 	EGL_TRACE("eglDestroyContext Display=%d, Context=%d", aDisplay, aContext);
       
   779 
       
   780 	EGLBoolean result = EGL_FALSE;
       
   781 	TEglThreadState* threadState = CVghwUtils::CreateThreadState();
       
   782 	if (threadState)
       
   783 		{
       
   784 		result = Instance().eglDestroyContext(*threadState, aDisplay, aContext);
       
   785 		}
       
   786 	return result;
       
   787 	}
       
   788 
       
   789 /*
       
   790  Make a context current, binds ctx to the current rendering thread
       
   791  and to the draw and read surfaces.
       
   792 
       
   793  For an OpenVG context, the same EGLSurface must be specified for both
       
   794  draw and read.
       
   795 
       
   796  If the calling thread already has a current context of the same client
       
   797  API type as ctx, then that context is flushed and marked as no longer
       
   798  current. ctx is then made the current context for the calling thread.
       
   799 
       
   800  To release the current context without assigning a new one, set ctx to
       
   801  EGL_NO_CONTEXT and set draw and read to EGL_NO_SURFACE. The currently
       
   802  bound context for the client API specified by the current rendering API
       
   803  is flushed and marked as no longer current, and there will be no current
       
   804  context for that client API after eglMakeCurrent returns. This is the
       
   805  only case in which eglMakeCurrent respects the current rendering API.
       
   806  In all other cases, the client API affected is determined by ctx. This
       
   807  is the only case where an uninitialized display may be passed to
       
   808  eglMakeCurrent.
       
   809 
       
   810  Returns EGL_FALSE on failure. Errors generated may include:
       
   811  * If draw or read are not compatible with ctx, then an EGL_BAD_MATCH
       
   812    error is generated.
       
   813  * If ctx is current to some other thread, or if either draw or read are
       
   814    bound to contexts in another thread, an EGL_BAD_ACCESS error is
       
   815    generated.
       
   816  * If binding ctx would exceed the number of current contexts of that
       
   817    client API type supported by the implementation, an EGL_BAD_ACCESS
       
   818    error is generated.
       
   819  * If either draw or read are pbuffers created with eglCreatePbufferFrom-
       
   820    ClientBuffer, and the underlying bound client API buffers are in use
       
   821    by the client API that created them, an EGL_BAD_ACCESS error is
       
   822    generated.
       
   823  * If ctx is not a valid context, an EGL_BAD_CONTEXT error is generated.
       
   824  * If either draw or read are not valid EGL surfaces, an EGL_BAD_SURFACE
       
   825    error is generated.
       
   826  * If a native window underlying either draw or read is no longer valid,
       
   827    an EGL_BAD_NATIVE_WINDOW error is generated.
       
   828  * If draw and read cannot fit into graphics memory simultaneously, an
       
   829    EGL_BAD_MATCH error is generated.
       
   830  * If the previous context of the calling thread has unflushed commands,
       
   831    and the previous surface is no longer valid, an EGL_BAD_CURRENT_SURFACE
       
   832    error is generated.
       
   833  * If the ancillary buffers for draw and read cannot be allocated, an
       
   834    EGL_BAD_ALLOC error is generated.
       
   835  * If a power management event has occurred, an EGL_CONTEXT_LOST error
       
   836    is generated.
       
   837  * As with other commands taking EGLDisplay parameters, if dpy is not a
       
   838    valid EGLDisplay handle, an EGL_BAD_DISPLAY error is generated.
       
   839  Other errors may arise when the context state is inconsistent with the
       
   840  surface state, as described in the EGL specification.
       
   841  */
       
   842 EXPORT_C EGLBoolean eglMakeCurrent(EGLDisplay aDisplay, EGLSurface aDraw, EGLSurface aRead, EGLContext aContext)
       
   843 	{
       
   844 	EGL_TRACE("eglMakeCurrent Display=%d, DrawSurface=0x%x, ReadSurface=0x%x, Context=%d", aDisplay, aDraw, aRead, aContext);
       
   845 
       
   846 	TEglThreadState* threadState = CVghwUtils::CreateThreadState();
       
   847 	if (threadState)
       
   848 		{
       
   849 		return Instance().eglMakeCurrent(*threadState, aDisplay, aDraw, aRead, aContext);
       
   850 		}
       
   851 	return EGL_FALSE;
       
   852 	}
       
   853 
       
   854 /*
       
   855  Get the current context for the current rendering API.
       
   856 
       
   857  If there is no current context for the current rendering API, or if the
       
   858  current rendering API is EGL_NONE, then EGL_NO_CONTEXT is returned (this
       
   859  is not an error).
       
   860  If the current context has been marked for deletion as a result of calling
       
   861  eglTerminate or eglDestroyContext, the handle returned by eglGetCurrentContext
       
   862  is not valid, and cannot be passed successfully to any other EGL function,
       
   863  as discussed in section 3.2 of the EGL Specification.
       
   864  */
       
   865 EXPORT_C EGLContext eglGetCurrentContext(void)
       
   866 	{
       
   867 	EGL_TRACE("eglGetCurrentContext -->");
       
   868 
       
   869 	EGLContext context = EGL_NO_SURFACE;
       
   870 	TEglThreadState* threadState = CVghwUtils::CreateThreadState();
       
   871 	if (threadState)
       
   872 		{
       
   873 		context = Instance().eglGetCurrentContext(*threadState);
       
   874 		}
       
   875 	EGL_TRACE("eglGetCurrentContext context=%d <--", context);
       
   876 	return context;
       
   877 	}
       
   878 
       
   879 /*
       
   880  Get the surfaces used for rendering by a current context.
       
   881 
       
   882  readdraw is either EGL_READ or EGL_DRAW, to return respectively the read or
       
   883  draw surfaces bound to the current context in the calling thread, for the
       
   884  current rendering API.
       
   885 
       
   886  If there is no current context for the current rendering API, then
       
   887  EGL_NO_SURFACE is returned (this is not an error). If readdraw is neither
       
   888  EGL_READ nor EGL_DRAW, EGL_NO_SURFACE is returned and an EGL_BAD_PARAMETER
       
   889  error is generated. If a current surface has been marked for deletion as
       
   890  a result of calling eglTerminate or eglDestroySurface, the handle returned
       
   891  by eglGetCurrentSurface is not valid, and cannot be passed successfully to
       
   892  any other EGL function, as discussed in section 3.2 of the EGL Specification.
       
   893  */
       
   894 EXPORT_C EGLSurface eglGetCurrentSurface(EGLint aReadDraw)
       
   895 	{
       
   896 	EGL_TRACE("eglGetCurrentSurface ReadDraw=%d -->", aReadDraw);
       
   897 
       
   898 	EGLSurface surface = EGL_NO_SURFACE;
       
   899 	TEglThreadState* threadState = CVghwUtils::CreateThreadState();
       
   900 	if (threadState)
       
   901 		{
       
   902 		surface = Instance().eglGetCurrentSurface(*threadState, aReadDraw);
       
   903 		}
       
   904 	EGL_TRACE("eglGetCurrentSurface surface=0x%x <--", surface);
       
   905 	return surface;
       
   906 	}
       
   907 
       
   908 /*
       
   909  Get the display associated with a current context.
       
   910 
       
   911  The display for the current context in the calling thread, for the current
       
   912  rendering API, is returned. If there is no current context for the current
       
   913  rendering API, EGL_NO_DISPLAY is returned (this is not an error).
       
   914 
       
   915  Note that EGL_NO_DISPLAY is used solely to represent an error condition,
       
   916  and is not a valid EGLDisplay handle. Passing EGL_NO_DISPLAY to any command
       
   917  taking an EGLDisplay parameter will generate either an EGL_BAD_DISPLAY
       
   918  error if the EGL implementation validates EGLDisplay handles, or undefined
       
   919  behavior as described at the end of section 3.1 of the EGL Specification.
       
   920  */
       
   921 EXPORT_C EGLDisplay eglGetCurrentDisplay(void)
       
   922 	{
       
   923 	EGL_TRACE("eglGetCurrentDisplay -->");
       
   924 
       
   925 	EGLDisplay display = EGL_NO_DISPLAY;
       
   926 	TEglThreadState* threadState = CVghwUtils::CreateThreadState();
       
   927 	if (threadState)
       
   928 		{
       
   929 		display = Instance().eglGetCurrentDisplay(*threadState);
       
   930 		}
       
   931 	EGL_TRACE("eglGetCurrentDisplay Display=%d <--", display);
       
   932 	return display;
       
   933 	}
       
   934 
       
   935 /*
       
   936  Obtain the value of context attributes.
       
   937 
       
   938  Returns in value the value of attribute for ctx. attribute must be set to
       
   939  EGL_CONFIG_ID, EGL_CONTEXT_CLIENT_TYPE, EGL_CONTEXT_CLIENT_VERSION, or
       
   940  EGL_RENDER_BUFFER.
       
   941 
       
   942  Returns EGL_FALSE on failure and value is not updated. If attribute is not
       
   943  a valid EGL context attribute, then an EGL_BAD_ATTRIBUTE error is generated.
       
   944  If ctx is invalid, an EGL_BAD_CONTEXT error is generated.
       
   945  */
       
   946 EXPORT_C EGLBoolean eglQueryContext(EGLDisplay aDisplay, EGLContext aContext, EGLint aAttribute, EGLint *aValue)
       
   947 	{
       
   948 	EGL_TRACE("eglQueryContext Display=%d, Context=%d, Attribute=0x%x, aValue=0x%x", aDisplay, aContext, aAttribute, aValue);
       
   949 
       
   950 	EGLBoolean result = EGL_FALSE;
       
   951 	TEglThreadState* threadState = CVghwUtils::CreateThreadState();
       
   952 	if (threadState)
       
   953 		{
       
   954 		result = Instance().eglQueryContext(*threadState, aDisplay, aContext, aAttribute, aValue);
       
   955 		}
       
   956 	EGL_TRACE_GET_ATTRIB("eglQueryContext", "context", aDisplay, aContext, aAttribute, aValue, result);
       
   957 	return result;
       
   958 	}
       
   959 
       
   960 /*
       
   961  EGL function is for backwards compatibility only.
       
   962 
       
   963  Equivalent to:
       
   964  EGLenum api = eglQueryAPI();
       
   965  eglBindAPI(EGL_OPENGL_ES_API);
       
   966  eglWaitClient();
       
   967  eglBindAPI(api);
       
   968  */
       
   969 EXPORT_C EGLBoolean eglWaitGL(void)
       
   970 	{
       
   971 	EGL_TRACE("eglWaitGL");
       
   972 
       
   973 	EGLBoolean result = EGL_FALSE;
       
   974 	TEglThreadState* threadState = CVghwUtils::CreateThreadState();
       
   975 	if (threadState)
       
   976 		{
       
   977 		RemoteFunctionCallData rfcdata; EglRFC eglApiData( rfcdata );
       
   978 		eglApiData.Init(EglRFC::EeglWaitGL);
       
   979 		result = threadState->ExecEglBooleanCmd(eglApiData);
       
   980 		}
       
   981 	return result;
       
   982 	}
       
   983 
       
   984 /*
       
   985  Wait for Symbian native rendering to complete, before performing
       
   986  client (Open GL ES, VG, ...) rendering.
       
   987 
       
   988  Returns EGL_TRUE on success. If there is no current context,
       
   989  the function has no effect but still returns EGL_TRUE. If the surface does not support
       
   990  native rendering (e.g. pbuffer and in most cases window surfaces), the function
       
   991  has no effect but still returns EGL_TRUE. If the surface associated with the
       
   992  calling thread’s current context is no longer valid, EGL_FALSE is returned and an
       
   993  EGL_BAD_CURRENT_SURFACE error is generated. If engine does not denote a recognized
       
   994  marking engine, EGL_FALSE is returned and an EGL_BAD_PARAMETER
       
   995  error is generated.
       
   996  */
       
   997 EXPORT_C EGLBoolean eglWaitNative(EGLint aEngine)
       
   998 	{
       
   999 	EGL_TRACE("eglWaitNative %d", aEngine);
       
  1000 
       
  1001 	EGLBoolean result = EGL_FALSE;
       
  1002 	TEglThreadState* threadState = CVghwUtils::CreateThreadState();
       
  1003 	if (threadState)
       
  1004 		{
       
  1005 		RemoteFunctionCallData rfcdata; EglRFC eglApiData( rfcdata );
       
  1006 		eglApiData.Init( EglRFC::EeglWaitNative);
       
  1007 		eglApiData.AppendEGLint(aEngine);
       
  1008 		result = threadState->ExecEglBooleanCmd(eglApiData);
       
  1009 
       
  1010 		if ( EGL_CORE_NATIVE_ENGINE == aEngine )
       
  1011 			{
       
  1012 			//Do native draw api sync
       
  1013 			}
       
  1014 		}
       
  1015 	return result;
       
  1016 	}
       
  1017 
       
  1018 /*
       
  1019  Post the color buffer to a window.
       
  1020 
       
  1021  If surface is a back-buffered window surface, then the color buffer is
       
  1022  copied to the native window associated with that surface. If surface is a
       
  1023  single-buffered window, pixmap, or pbuffer surface, eglSwapBuffers has no
       
  1024  effect.
       
  1025 
       
  1026  The contents of the color buffer of surface may be affected by
       
  1027  eglSwapBuffers, depending on the value of the EGL_SWAP_BEHAVIOR attribute
       
  1028  of surface. See section 3.5.6 of the EGL Specification.
       
  1029 
       
  1030  Returns EGL_FALSE on failure. If surface is not a valid EGL surface, an
       
  1031  EGL_BAD_SURFACE error is generated. If surface is not bound to the calling
       
  1032  thread’s current context, an EGL_BAD_SURFACE error is generated. If target is
       
  1033  not a valid native pixmap handle, an EGL_BAD_NATIVE_PIXMAP error should be
       
  1034  generated. If the format of target is not compatible with the color buffer,
       
  1035  or if the size of target is not the same as the size of the color buffer, and
       
  1036  there is no defined conversion between the source and target formats, an
       
  1037  EGL_BAD_MATCH error is generated. If called after a power management event
       
  1038  has occurred, a EGL_CONTEXT_LOST error is generated. If the native window
       
  1039  associated with surface is no longer valid, an EGL_ BAD_NATIVE_WINDOW error
       
  1040  is generated.
       
  1041  */
       
  1042 EXPORT_C EGLBoolean eglSwapBuffers(EGLDisplay aDisplay, EGLSurface aSurface)
       
  1043 	{
       
  1044 	EGL_TRACE("eglSwapBuffers begin Display=%d, Surface=0x%x -->", aDisplay, aSurface);
       
  1045 
       
  1046 	EGLBoolean result = EGL_FALSE;
       
  1047 	TEglThreadState* threadState = CVghwUtils::CreateThreadState();
       
  1048 	if (threadState)
       
  1049 		{
       
  1050 		result = Instance().eglSwapBuffers(*threadState, aDisplay, aSurface);
       
  1051 		}
       
  1052 
       
  1053 	EGL_TRACE("eglSwapBuffers success=%d <--", result);
       
  1054 	return result;
       
  1055 	}
       
  1056 
       
  1057 /*
       
  1058  Copy the color buffer to a native pixmap.
       
  1059 
       
  1060  The mapping of pixels in the color buffer to pixels in the pixmap is platform
       
  1061  dependent, since the native platform pixel coordinate system may differ from
       
  1062  that of client APIs.
       
  1063 
       
  1064  The color buffer of surface is left unchanged after calling eglCopyBuffers.
       
  1065  Returns EGL_FALSE on failure. If surface is not a valid EGL surface, an
       
  1066  EGL_BAD_SURFACE error is generated. If surface is not bound to the calling
       
  1067  thread’s current context, an EGL_BAD_SURFACE error is generated. If target is
       
  1068  not a valid native pixmap handle, an EGL_BAD_NATIVE_PIXMAP error should be
       
  1069  generated. If the format of target is not compatible with the color buffer,
       
  1070  or if the size of target is not the same as the size of the color buffer, and
       
  1071  there is no defined conversion between the source and target formats, an
       
  1072  EGL_BAD_MATCH error is generated. If called after a power management event
       
  1073  has occurred, a EGL_CONTEXT_LOST error is generated. If the egl
       
  1074  implementation does not support native pixmaps, an EGL_BAD_NATIVE_PIXMAP
       
  1075  error is generated.
       
  1076  */
       
  1077 EXPORT_C EGLBoolean eglCopyBuffers(EGLDisplay aDisplay, EGLSurface aSurface, EGLNativePixmapType aTarget)
       
  1078 	{
       
  1079 	// Note: API supports CFbsBitmap native pixmap but not SgImage
       
  1080 	EGL_TRACE("eglCopyBuffers Display=%d, Surface=0x%x, Target=0x%x", aDisplay, aSurface, aTarget);
       
  1081 
       
  1082 	TEglThreadState* threadState = CVghwUtils::CreateThreadState();
       
  1083 	if (threadState)
       
  1084 		{ // EGL is initialized for thread
       
  1085 		return Instance().eglCopyBuffers(*threadState, aDisplay, aSurface, aTarget);
       
  1086 		}
       
  1087 	return EGL_FALSE;
       
  1088 	}
       
  1089 
       
  1090 /*
       
  1091  * eglCreateImageKHR supports Khronos EGL extension #8, "KHR_image_base"
       
  1092  *
       
  1093  * Supported values for target parameter:
       
  1094  * EGL_NATIVE_PIXMAP_KHR for Khronos EGL extension #9, "KHR_image_pixmap"
       
  1095  */
       
  1096 EGLImageKHR eglCreateImageKHR(EGLDisplay aDisplay, EGLContext aContext, EGLenum aTarget, EGLClientBuffer aBuffer, const EGLint *aAttribList)
       
  1097 	{
       
  1098 	EGL_TRACE("eglCreateImageKHR Display=%d, Context=%d, Target=0x%x, Buffer=0x%x, AttribList=0x%x -->",
       
  1099 			aDisplay, aContext, aTarget, aBuffer, aAttribList);
       
  1100 
       
  1101 	EGLImageKHR image = NULL;
       
  1102 	TEglThreadState* threadState = CVghwUtils::CreateThreadState();
       
  1103 	if (threadState)
       
  1104 		{
       
  1105 		image = Instance().eglCreateImageKHR(*threadState, aDisplay, aContext, aTarget, aBuffer, aAttribList);
       
  1106 		}
       
  1107 	EGL_TRACE("eglCreateImageKHR image=0x%x <--", image);
       
  1108 	return image;
       
  1109 	}
       
  1110 
       
  1111 /*
       
  1112  * eglDestroyImageKHR supports Khronos EGL extension #8, "KHR_image_base"
       
  1113  */
       
  1114 EGLBoolean eglDestroyImageKHR(EGLDisplay aDisplay, EGLImageKHR aImage)
       
  1115 	{
       
  1116 	EGL_TRACE("eglDestroyImageKHR Display=%d, Image=0x%x -->", aDisplay, aImage);
       
  1117 
       
  1118 	EGLBoolean success = EGL_FALSE;
       
  1119 	TEglThreadState* threadState = CVghwUtils::CreateThreadState();
       
  1120 	if (threadState)
       
  1121 		{
       
  1122 		success = Instance().eglDestroyImageKHR(*threadState, aDisplay, aImage);
       
  1123 		}
       
  1124 	EGL_TRACE("eglDestroyImageKHR success=%d <--", success);
       
  1125 	return success;
       
  1126 	}
       
  1127 
       
  1128 
       
  1129 /*
       
  1130  Returns the address of the extension function named by procName. procName
       
  1131  must be a NULL-terminated string. The pointer returned should be cast to
       
  1132  a function pointer type matching the extension function’s definition in
       
  1133  that extension specification.
       
  1134 
       
  1135  A return value of NULL indicates that the specified function does not exist
       
  1136  for the implementation.
       
  1137 
       
  1138  A non-NULL return value for eglGetProcAddress does not guarantee that an
       
  1139  extension function is actually supported at runtime. The client must also make
       
  1140  a corresponding query, such as glGetString(GL_EXTENSIONS) for OpenGL and
       
  1141  OpenGL ES extensions; vgGetString(VG_EXTENSIONS) for OpenVG extensions;
       
  1142  or eglQueryString(dpy, EGL_EXTENSIONS) for EGL extensions, to determine if
       
  1143  an extension is supported by a particular client API context.
       
  1144 
       
  1145  Function pointers returned by eglGetProcAddress are independent of the display
       
  1146  and the currently bound context, and may be used by any context which supports
       
  1147  the extension.
       
  1148 
       
  1149  eglGetProcAddress may be queried for all of the following functions:
       
  1150  * All EGL and client API extension functions supported by the implementation
       
  1151    (whether those extensions are supported by the current context or not).
       
  1152    This includes any mandatory OpenGL ES extensions.
       
  1153  */
       
  1154 EXPORT_C void (*eglGetProcAddress (const char *aProcname))(...)
       
  1155 	{
       
  1156 	EGL_TRACE("eglGetProcAddress");
       
  1157 
       
  1158 	if (aProcname)
       
  1159 		{
       
  1160 		return Instance().eglGetProcAddress(aProcname);
       
  1161 		}
       
  1162 	return NULL;
       
  1163 	}
       
  1164 
       
  1165 } /* extern "C" */