gl_common: Make secsym_eglCreateImage a wrapper
authorDerek Foreman <derekf@osg.samsung.com>
Mon, 19 Dec 2016 20:33:09 +0000 (14:33 -0600)
committerDerek Foreman <derekf@osg.samsung.com>
Mon, 19 Dec 2016 21:52:58 +0000 (15:52 -0600)
eglCreateImage and eglCreateImageKHR are subtly different.  Now we try to
handle them both properly by exposing an abstraction.

src/modules/evas/engines/gl_common/evas_gl_common.h
src/modules/evas/engines/gl_common/evas_gl_context.c
src/modules/evas/engines/gl_common/evas_gl_texture.c

index c83a828..eaff927 100644 (file)
@@ -32,6 +32,7 @@
 #  endif
 # else
 #  ifdef GL_GLES
+#   include <EGL/egl.h>
 #   include <GLES2/gl2.h>
 #   include <GLES2/gl2ext.h>
 #  else
@@ -713,7 +714,7 @@ extern void      *(*glsym_glMapBuffer)            (GLenum a, GLenum b);
 extern GLboolean  (*glsym_glUnmapBuffer)          (GLenum a);
 
 #ifdef GL_GLES
-extern void          *(*secsym_eglCreateImage)               (void *a, void *b, GLenum c, void *d, const int *e);
+EAPI void *           evas_gl_common_eglCreateImage          (EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLAttrib *attrib_list);
 extern unsigned int   (*secsym_eglDestroyImage)              (void *a, void *b);
 extern void           (*secsym_glEGLImageTargetTexture2DOES) (int a, void *b);
 extern void          *(*secsym_eglMapImageSEC)               (void *a, void *b, int c, int d);
@@ -873,7 +874,8 @@ __evas_gl_errdyn(int err, const char *file, const char *func, int line, const ch
 #  define glsym_glReleaseShaderCompiler(...) GL_ERROR_TRACE(glsym_glReleaseShaderCompiler, #__VA_ARGS__, __VA_ARGS__)
 #  define glsym_glMapBuffer(...) GL_ERROR_TRACE_RET(void *, glsym_glMapBuffer, #__VA_ARGS__, __VA_ARGS__)
 #  define glsym_glUnmapBuffer(...) GL_ERROR_TRACE_RET(unsigned int, glsym_glUnmapBuffer, #__VA_ARGS__, __VA_ARGS__)
-#  define secsym_eglCreateImage(...) GL_ERROR_TRACE_RET(void *, secsym_eglCreateImage, #__VA_ARGS__, __VA_ARGS__)
+#  define eglsym_eglCreateImage(...) GL_ERROR_TRACE_RET(void *, eglsym_eglCreateImage, #__VA_ARGS__, __VA_ARGS__)
+#  define eglsym_eglCreateImageKHR(...) GL_ERROR_TRACE_RET(void *, eglsym_eglCreateImageKHR, #__VA_ARGS__, __VA_ARGS__)
 #  define secsym_eglDestroyImage(...) GL_ERROR_TRACE_RET(unsigned int, secsym_eglDestroyImage, #__VA_ARGS__, __VA_ARGS__)
 #  define secsym_glEGLImageTargetTexture2DOES(...) GL_ERROR_TRACE(secsym_glEGLImageTargetTexture2DOES, #__VA_ARGS__, __VA_ARGS__)
 #  define secsym_eglMapImageSEC(...) GL_ERROR_TRACE_RET(void *, secsym_eglMapImageSEC, #__VA_ARGS__, __VA_ARGS__)
index e0cd1f7..8cca90a 100644 (file)
@@ -49,13 +49,18 @@ typedef int  (*secsym_func_int) ();
 typedef unsigned int  (*secsym_func_uint) ();
 typedef void         *(*secsym_func_void_ptr) ();
 
-void          *(*secsym_eglCreateImage)               (void *a, void *b, GLenum c, void *d, const int *e) = NULL;
 unsigned int   (*secsym_eglDestroyImage)              (void *a, void *b) = NULL;
 void           (*secsym_glEGLImageTargetTexture2DOES) (int a, void *b) = NULL;
 void          *(*secsym_eglMapImageSEC)               (void *a, void *b, int c, int d) = NULL;
 unsigned int   (*secsym_eglUnmapImageSEC)             (void *a, void *b, int c) = NULL;
 unsigned int   (*secsym_eglGetImageAttribSEC)         (void *a, void *b, int c, int *d) = NULL;
 
+
+/* This one is now a local wrapper to avoid type mixups */
+void *        evas_gl_common_eglCreateImage           (EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLAttrib *attrib_list);
+static void * (*eglsym_eglCreateImage)                (EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLAttrib *attrib_list) = NULL;
+static void * (*eglsym_eglCreateImageKHR)             (EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLint *e) = NULL;
+
 ////////////////////////////////////
 //libtbm.so.1
 static void *tbm_lib_handle;
@@ -114,6 +119,32 @@ _has_ext(const char *ext, const char **pexts, int *pnum)
      }
 }
 
+#ifdef GL_GLES
+void *
+evas_gl_common_eglCreateImage(EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLAttrib *attrib_list)
+{
+   if (eglsym_eglCreateImage)
+     return eglsym_eglCreateImage(dpy, ctx, target, buffer, attrib_list);
+   if (eglsym_eglCreateImageKHR)
+     {
+        int count, i;
+        EGLint *ints = NULL;
+
+        if (attrib_list)
+          {
+             for (count = 0; attrib_list[count] != EGL_NONE; count += 2);
+             count++;
+             ints = alloca(count * sizeof(EGLint));
+             for (i = 0; i < count; i++)
+               ints[i] = attrib_list[i];
+          }
+        return eglsym_eglCreateImageKHR(dpy, ctx, target, buffer, ints);
+     }
+   return NULL;
+}
+
+#endif
+
 /* FIXME: return error if a required symbol was not found */
 EAPI void
 evas_gl_symbols(void *(*GetProcAddress)(const char *name))
@@ -267,11 +298,11 @@ evas_gl_symbols(void *(*GetProcAddress)(const char *name))
 // wrong as this is not x11 (output) layer specific like the native surface
 // stuff. this is generic zero-copy textures for gl
 
-   FINDSYM(secsym_eglCreateImage, "eglCreateImage", NULL, secsym_func_void_ptr);
-   FINDSYM(secsym_eglCreateImage, "eglCreateImageKHR", "EGL_KHR_image_base", secsym_func_void_ptr);
-   FINDSYM(secsym_eglCreateImage, "eglCreateImageKHR", "EGL_KHR_image", secsym_func_void_ptr);
-   FINDSYM(secsym_eglCreateImage, "eglCreateImageOES", "GL_OES_EGL_image_base", secsym_func_void_ptr);
-   FINDSYM(secsym_eglCreateImage, "eglCreateImageOES", "GL_OES_EGL_image", secsym_func_void_ptr);
+   FINDSYM(eglsym_eglCreateImage, "eglCreateImage", NULL, secsym_func_void_ptr);
+   FINDSYM(eglsym_eglCreateImageKHR, "eglCreateImageKHR", "EGL_KHR_image_base", secsym_func_void_ptr);
+   FINDSYM(eglsym_eglCreateImageKHR, "eglCreateImageKHR", "EGL_KHR_image", secsym_func_void_ptr);
+   FINDSYM(eglsym_eglCreateImageKHR, "eglCreateImageOES", "GL_OES_EGL_image_base", secsym_func_void_ptr);
+   FINDSYM(eglsym_eglCreateImageKHR, "eglCreateImageOES", "GL_OES_EGL_image", secsym_func_void_ptr);
 
    FINDSYM(secsym_eglDestroyImage, "eglDestroyImage", NULL, secsym_func_uint);
    FINDSYM(secsym_eglDestroyImage, "eglDestroyImageKHR", "EGL_KHR_image_base", secsym_func_uint);
@@ -842,8 +873,7 @@ evas_gl_common_context_new(void)
                {
                   // test for all needed symbols - be "conservative" and
                   // need all of it
-                  if ((secsym_eglCreateImage) &&
-                      (secsym_eglDestroyImage) &&
+                  if ((secsym_eglDestroyImage) &&
                       (secsym_glEGLImageTargetTexture2DOES) &&
                       (secsym_eglMapImageSEC) &&
                       (secsym_eglUnmapImageSEC) &&
index 7158e30..903a60b 100644 (file)
@@ -849,10 +849,10 @@ _pool_tex_dynamic_new(Evas_Engine_GL_Context *gc, int w, int h, int intformat, i
                                                            buffer_format);
         if (!pt->dyn.buffer) goto error;
 
-        pt->dyn.img = secsym_eglCreateImage(egldisplay,
-                                            EGL_NO_CONTEXT,
-                                            EGL_NATIVE_SURFACE_TIZEN,
-                                            pt->dyn.buffer, NULL);
+        pt->dyn.img = evas_gl_common_eglCreateImage(egldisplay,
+                                                    EGL_NO_CONTEXT,
+                                                    EGL_NATIVE_SURFACE_TIZEN,
+                                                    pt->dyn.buffer, NULL);
         if (!pt->dyn.img)
           {
              secsym_tbm_surface_destroy(pt->dyn.buffer);
@@ -867,7 +867,7 @@ _pool_tex_dynamic_new(Evas_Engine_GL_Context *gc, int w, int h, int intformat, i
      {
         int fmt; // EGL_MAP_GL_TEXTURE_RGBA_SEC or EGL_MAP_GL_TEXTURE_RGB_SEC or bust
         int pixtype; // EGL_MAP_GL_TEXTURE_UNSIGNED_BYTE_SEC or bust
-        int attr[] =
+        EGLAttrib attr[] =
           {
              EGL_MAP_GL_TEXTURE_WIDTH_SEC, 32,
              EGL_MAP_GL_TEXTURE_HEIGHT_SEC, 32,
@@ -894,10 +894,10 @@ _pool_tex_dynamic_new(Evas_Engine_GL_Context *gc, int w, int h, int intformat, i
 
         // FIXME: seems a bit slower than i'd like - maybe too many flushes?
         // FIXME: YCbCr no support as yet
-        pt->dyn.img = secsym_eglCreateImage(egldisplay,
-                                            EGL_NO_CONTEXT,
-                                            EGL_MAP_GL_TEXTURE_2D_SEC,
-                                            0, attr);
+        pt->dyn.img = evas_gl_common_eglCreateImage(egldisplay,
+                                                    EGL_NO_CONTEXT,
+                                                    EGL_MAP_GL_TEXTURE_2D_SEC,
+                                                    0, attr);
         if (!pt->dyn.img) goto error;
 
         if (secsym_eglGetImageAttribSEC(egldisplay,