[Mesa-dev] [PATCH] egl: Check if API is supported when using eglBindAPI.

Plamena Manolova plamena.manolova at intel.com
Fri May 13 16:03:43 UTC 2016


According to the EGL specifications before binding an API
we must check whether it's supported first. If not eglBindAPI
should return EGL_FALSE and generate a EGL_BAD_PARAMETER error.

Signed-off-by: Plamena Manolova <plamena.manolova at intel.com>
---
 src/egl/main/eglapi.c     |  2 ++
 src/egl/main/eglcurrent.h | 22 +++++++++++++++++++++-
 src/egl/main/eglglobals.h |  1 +
 3 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c
index eb612c0..0931c3d 100644
--- a/src/egl/main/eglapi.c
+++ b/src/egl/main/eglapi.c
@@ -444,6 +444,8 @@ _eglCreateAPIsString(_EGLDisplay *dpy)
       strcat(dpy->ClientAPIsString, "OpenVG ");
 
    assert(strlen(dpy->ClientAPIsString) < sizeof(dpy->ClientAPIsString));
+
+   _eglGlobal.ClientAPIsString = dpy->ClientAPIsString;
 }
 
 static void
diff --git a/src/egl/main/eglcurrent.h b/src/egl/main/eglcurrent.h
index 1e386ac..0e3bd56 100644
--- a/src/egl/main/eglcurrent.h
+++ b/src/egl/main/eglcurrent.h
@@ -32,6 +32,7 @@
 #include "c99_compat.h"
 
 #include "egltypedefs.h"
+#include "eglglobals.h"
 
 
 #ifdef __cplusplus
@@ -69,7 +70,26 @@ struct _egl_thread_info
 static inline EGLBoolean
 _eglIsApiValid(EGLenum api)
 {
-   return (api >= _EGL_API_FIRST_API && api <= _EGL_API_LAST_API);
+   char *api_string;
+   switch (api) {
+      case EGL_OPENGL_API:
+         api_string = "OpenGL";
+         break;
+      case EGL_OPENGL_ES_API:
+         api_string = "OpenGL_ES";
+         break;
+      case EGL_OPENVG_API:
+         api_string = "OpenVG";
+         break;
+      default:
+         return EGL_FALSE;
+      break;
+   }
+
+   if (strstr(api_string, _eglGlobal.ClientAPIsString))
+      return EGL_TRUE;
+   else
+      return EGL_FALSE;
 }
 
 
diff --git a/src/egl/main/eglglobals.h b/src/egl/main/eglglobals.h
index ae1b75b..b770d4b 100644
--- a/src/egl/main/eglglobals.h
+++ b/src/egl/main/eglglobals.h
@@ -51,6 +51,7 @@ struct _egl_global
    void (*AtExitCalls[10])(void);
 
    const char *ClientExtensionString;
+   const char *ClientAPIsString;
 };
 
 
-- 
2.7.4



More information about the mesa-dev mailing list