This is an automated email from the git hooks/post-receive script.

git pushed a commit to branch devs/cedric/wl/gl-x11-dmabuf
in repository efl.

View the commit online.

commit 6b7c788fc7adaeb62d45e1fc855d9b0350e285de
Author: Cedric BAIL <[email protected]>
AuthorDate: Sun Nov 15 18:39:48 2026 -0600

    evas:gl_common: move the wl_dmabuf import out of gl_drm
    
    Importing a linux dmabuf as a texture is EGL_EXT_image_dma_buf_import,
    the same call on any platform with an EGLDisplay. Only gl_drm could do
    it, so a compositor running on gl_x11 cannot take GPU buffers from its
    clients. Rather than copy the code into a second engine, move it to
    gl_common, where every GL engine reaches it through glsym like
    eglCreateImage. The engine only gives its display.
    
    The import now builds the plane attributes from a table instead of four
    unrolled copies, and the extension support is cached for the display it
    was queried on instead of in a static of the engine.
    
    The fallback defines for EGL_DMA_BUF_PLANE2_MODIFIER_HI_EXT tested a
    misspelled name, and DRM_FORMAT_MOD_LINEAR was defined but never used;
    neither comes along.
    
    When eng_image_native_set() was given a dmabuf surface with a wl
    resource but no image, gl_drm went on with a NULL image. It now returns
    NULL, as for every other type it cannot create an image for.
    
    Co-Authored-By: Claude Opus 5 <[email protected]>
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 .../evas/engines/gl_common/evas_gl_common.h        |   5 +
 .../evas/engines/gl_common/evas_gl_native_dmabuf.c | 338 +++++++++++++++++++++
 src/modules/evas/engines/gl_drm/evas_engine.c      | 293 ++----------------
 src/modules/evas/engines/gl_generic/meson.build    |   1 +
 4 files changed, 366 insertions(+), 271 deletions(-)

diff --git a/src/modules/evas/engines/gl_common/evas_gl_common.h b/src/modules/evas/engines/gl_common/evas_gl_common.h
index b11f0886b3..ce44eff2e6 100644
--- a/src/modules/evas/engines/gl_common/evas_gl_common.h
+++ b/src/modules/evas/engines/gl_common/evas_gl_common.h
@@ -870,6 +870,11 @@ extern void       (*glsym_glRenderbufferStorageMultisample)(GLenum target, GLsiz
 #ifdef GL_GLES
 EMODAPI void *           evas_gl_common_eglCreateImage          (EGLDisplay dpy, EGLContext ctx, EGLenum target, EGLClientBuffer buffer, const EGLAttrib *attrib_list);
 EMODAPI int              evas_gl_common_eglDestroyImage         (EGLDisplay dpy, void *im);
+
+EMODAPI Evas_GL_Image *  evas_gl_common_dmabuf_test_image_new   (Evas_Engine_GL_Context *gc, const Evas_Native_Surface *ns, EGLDisplay dpy);
+EMODAPI Evas_GL_Image *  evas_gl_common_dmabuf_native_lookup    (Evas_Engine_GL_Context *gc, Evas_GL_Image *im, const Evas_Native_Surface *ns);
+EMODAPI Eina_Bool        evas_gl_common_dmabuf_native_attach    (Evas_Engine_GL_Context *gc, Evas_GL_Image *im, const Evas_Native_Surface *ns, EGLDisplay dpy);
+
 extern unsigned int   (*eglsym_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);
diff --git a/src/modules/evas/engines/gl_common/evas_gl_native_dmabuf.c b/src/modules/evas/engines/gl_common/evas_gl_native_dmabuf.c
new file mode 100644
index 0000000000..b671de354a
--- /dev/null
+++ b/src/modules/evas/engines/gl_common/evas_gl_native_dmabuf.c
@@ -0,0 +1,338 @@
+/* Import of EVAS_NATIVE_SURFACE_WL_DMABUF buffers through
+ * EGL_EXT_image_dma_buf_import, for any GL engine that has an EGLDisplay.
+ *
+ * evas_gl_common_dmabuf_native_attach() installs the bind, unbind and free
+ * callbacks of this file on the image, so an engine's own native callbacks
+ * never see this surface type.
+ */
+#include "evas_gl_private.h"
+#include "../software_generic/evas_native_common.h"
+
+#ifdef GL_GLES
+
+# include <EGL/eglext.h>
+
+/* For EGL and DRM headers older than the extensions. The values are fixed
+ * by the EGL registry and the kernel. */
+# ifndef DRM_FORMAT_MOD_INVALID
+#  define DRM_FORMAT_MOD_INVALID ((1ULL << 56) - 1)
+# endif
+# ifndef EGL_DMA_BUF_PLANE3_FD_EXT
+#  define EGL_DMA_BUF_PLANE3_FD_EXT 0x3440
+# endif
+# ifndef EGL_DMA_BUF_PLANE3_OFFSET_EXT
+#  define EGL_DMA_BUF_PLANE3_OFFSET_EXT 0x3441
+# endif
+# ifndef EGL_DMA_BUF_PLANE3_PITCH_EXT
+#  define EGL_DMA_BUF_PLANE3_PITCH_EXT 0x3442
+# endif
+# ifndef EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT
+#  define EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT 0x3443
+# endif
+# ifndef EGL_DMA_BUF_PLANE0_MODIFIER_HI_EXT
+#  define EGL_DMA_BUF_PLANE0_MODIFIER_HI_EXT 0x3444
+# endif
+# ifndef EGL_DMA_BUF_PLANE1_MODIFIER_LO_EXT
+#  define EGL_DMA_BUF_PLANE1_MODIFIER_LO_EXT 0x3445
+# endif
+# ifndef EGL_DMA_BUF_PLANE1_MODIFIER_HI_EXT
+#  define EGL_DMA_BUF_PLANE1_MODIFIER_HI_EXT 0x3446
+# endif
+# ifndef EGL_DMA_BUF_PLANE2_MODIFIER_LO_EXT
+#  define EGL_DMA_BUF_PLANE2_MODIFIER_LO_EXT 0x3447
+# endif
+# ifndef EGL_DMA_BUF_PLANE2_MODIFIER_HI_EXT
+#  define EGL_DMA_BUF_PLANE2_MODIFIER_HI_EXT 0x3448
+# endif
+# ifndef EGL_DMA_BUF_PLANE3_MODIFIER_LO_EXT
+#  define EGL_DMA_BUF_PLANE3_MODIFIER_LO_EXT 0x3449
+# endif
+# ifndef EGL_DMA_BUF_PLANE3_MODIFIER_HI_EXT
+#  define EGL_DMA_BUF_PLANE3_MODIFIER_HI_EXT 0x344A
+# endif
+
+/* What the driver supports is a property of the EGLDisplay, so the answer
+ * is cached for the display it was asked about. */
+static EGLDisplay _dmabuf_disp = NULL;
+static Eina_Bool _dmabuf_probed = EINA_FALSE;
+static Eina_Bool _dmabuf_have_import = EINA_FALSE;
+static Eina_Bool _dmabuf_modifiers = EINA_FALSE;
+
+static Eina_Bool
+_dmabuf_probe(EGLDisplay disp)
+{
+   const char *exts;
+
+   if ((_dmabuf_probed) && (_dmabuf_disp == disp)) return _dmabuf_have_import;
+
+   _dmabuf_disp = disp;
+   _dmabuf_probed = EINA_TRUE;
+   _dmabuf_have_import = EINA_FALSE;
+   _dmabuf_modifiers = EINA_FALSE;
+
+   exts = eglQueryString(disp, EGL_EXTENSIONS);
+   if (!exts) return EINA_FALSE;
+
+   _dmabuf_have_import =
+     evas_gl_extension_string_check(exts, "EGL_EXT_image_dma_buf_import");
+   _dmabuf_modifiers =
+     evas_gl_extension_string_check(exts,
+                                    "EGL_EXT_image_dma_buf_import_modifiers");
+
+   return _dmabuf_have_import;
+}
+
+/* Code from weston's gl-renderer, by way of the gl_drm engine. */
+static void *
+_dmabuf_import_attempt(EGLDisplay disp, struct dmabuf_attributes *attr,
+                       Eina_Bool with_modifier)
+{
+   static const EGLint fd_attr[4] =
+     { EGL_DMA_BUF_PLANE0_FD_EXT, EGL_DMA_BUF_PLANE1_FD_EXT,
+       EGL_DMA_BUF_PLANE2_FD_EXT, EGL_DMA_BUF_PLANE3_FD_EXT };
+   static const EGLint off_attr[4] =
+     { EGL_DMA_BUF_PLANE0_OFFSET_EXT, EGL_DMA_BUF_PLANE1_OFFSET_EXT,
+       EGL_DMA_BUF_PLANE2_OFFSET_EXT, EGL_DMA_BUF_PLANE3_OFFSET_EXT };
+   static const EGLint pitch_attr[4] =
+     { EGL_DMA_BUF_PLANE0_PITCH_EXT, EGL_DMA_BUF_PLANE1_PITCH_EXT,
+       EGL_DMA_BUF_PLANE2_PITCH_EXT, EGL_DMA_BUF_PLANE3_PITCH_EXT };
+   static const EGLint mod_lo_attr[4] =
+     { EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT, EGL_DMA_BUF_PLANE1_MODIFIER_LO_EXT,
+       EGL_DMA_BUF_PLANE2_MODIFIER_LO_EXT, EGL_DMA_BUF_PLANE3_MODIFIER_LO_EXT };
+   static const EGLint mod_hi_attr[4] =
+     { EGL_DMA_BUF_PLANE0_MODIFIER_HI_EXT, EGL_DMA_BUF_PLANE1_MODIFIER_HI_EXT,
+       EGL_DMA_BUF_PLANE2_MODIFIER_HI_EXT, EGL_DMA_BUF_PLANE3_MODIFIER_HI_EXT };
+   EGLAttrib attribs[6 + (4 * 10) + 1];
+   Eina_Bool has_modifier = EINA_FALSE;
+   int atti = 0, i;
+
+   /* A driver without EGL_EXT_image_dma_buf_import_modifiers rejects the
+    * whole import with EGL_BAD_ATTRIBUTE when it is given modifiers, which
+    * shows as a black window. Let it guess the layout instead. */
+   if ((with_modifier) && (_dmabuf_modifiers) &&
+       (attr->modifier[0] != DRM_FORMAT_MOD_INVALID))
+     has_modifier = EINA_TRUE;
+
+   attribs[atti++] = EGL_WIDTH;
+   attribs[atti++] = attr->width;
+   attribs[atti++] = EGL_HEIGHT;
+   attribs[atti++] = attr->height;
+   attribs[atti++] = EGL_LINUX_DRM_FOURCC_EXT;
+   attribs[atti++] = attr->format;
+
+   for (i = 0; (i < attr->n_planes) && (i < 4); i++)
+     {
+        attribs[atti++] = fd_attr[i];
+        attribs[atti++] = attr->fd[i];
+        attribs[atti++] = off_attr[i];
+        attribs[atti++] = attr->offset[i];
+        attribs[atti++] = pitch_attr[i];
+        attribs[atti++] = attr->stride[i];
+        if (has_modifier)
+          {
+             attribs[atti++] = mod_lo_attr[i];
+             attribs[atti++] = attr->modifier[i] & 0xFFFFFFFF;
+             attribs[atti++] = mod_hi_attr[i];
+             attribs[atti++] = attr->modifier[i] >> 32;
+          }
+     }
+
+   attribs[atti++] = EGL_NONE;
+
+   /* This requires the Mesa commit in
+    * Mesa 10.3 (08264e5dad4df448e7718e782ad9077902089a07) or
+    * Mesa 10.2.7 (55d28925e6109a4afd61f109e845a8a51bd17652).
+    * Otherwise Mesa closes the fd behind our back and re-importing
+    * will fail.
+    * https://bugs.freedesktop.org/show_bug.cgi?id=76188
+    */
+   return evas_gl_common_eglCreateImage(disp, EGL_NO_CONTEXT,
+                                        EGL_LINUX_DMA_BUF_EXT, NULL, attribs);
+}
+
+static void *
+_dmabuf_import(EGLDisplay disp, struct dmabuf_attributes *attr)
+{
+   void *img;
+
+   if (!attr) return NULL;
+   if (attr->version != EVAS_DMABUF_ATTRIBUTE_VERSION) return NULL;
+   if (!_dmabuf_probe(disp)) return NULL;
+
+   img = _dmabuf_import_attempt(disp, attr, EINA_TRUE);
+   if (img) return img;
+
+   /* A driver can advertise import_modifiers and still refuse a given
+    * modifier. */
+   if ((_dmabuf_modifiers) && (attr->modifier[0] != DRM_FORMAT_MOD_INVALID))
+     {
+        DBG("dmabuf import with modifier %#" PRIx64 " failed (%#x), "
+            "retrying without", attr->modifier[0], eglGetError());
+        img = _dmabuf_import_attempt(disp, attr, EINA_FALSE);
+     }
+
+   return img;
+}
+
+static void
+_dmabuf_native_bind_cb(void *image)
+{
+   Evas_GL_Image *im = image;
+   Native *n;
+
+   if (!im) return;
+   if (!(n = im->native.data)) return;
+
+   /* Must re-import every time for coherency. */
+   if (n->ns_data.wl_surface_dmabuf.image)
+     evas_gl_common_eglDestroyImage(im->native.disp,
+                                    n->ns_data.wl_surface_dmabuf.image);
+   n->ns_data.wl_surface_dmabuf.image =
+     _dmabuf_import(im->native.disp, &n->ns_data.wl_surface_dmabuf.attr);
+   if (!n->ns_data.wl_surface_dmabuf.image)
+     {
+        im->native.invalid = EINA_TRUE;
+        return;
+     }
+   im->native.invalid = EINA_FALSE;
+   if (secsym_glEGLImageTargetTexture2DOES)
+     secsym_glEGLImageTargetTexture2DOES(GL_TEXTURE_2D,
+                                         n->ns_data.wl_surface_dmabuf.image);
+}
+
+static void
+_dmabuf_native_unbind_cb(void *image)
+{
+   Evas_GL_Image *im = image;
+   Native *n;
+
+   if (!im) return;
+   if (!(n = im->native.data)) return;
+
+   if (n->ns_data.wl_surface_dmabuf.image)
+     {
+        evas_gl_common_eglDestroyImage(im->native.disp,
+                                       n->ns_data.wl_surface_dmabuf.image);
+        n->ns_data.wl_surface_dmabuf.image = NULL;
+     }
+}
+
+static void
+_dmabuf_native_free_cb(void *image)
+{
+   Evas_GL_Image *im = image;
+   Native *n;
+   void *key;
+
+   if (!im) return;
+   if (!(n = im->native.data)) return;
+
+   if (im->native.shared)
+     {
+        key = n->ns_data.wl_surface_dmabuf.resource;
+        eina_hash_del(im->native.shared->native_wl_hash, &key, im);
+     }
+   if (n->ns_data.wl_surface_dmabuf.image)
+     {
+        evas_gl_common_eglDestroyImage(im->native.disp,
+                                       n->ns_data.wl_surface_dmabuf.image);
+        GLERRV("eglDestroyImage() failed.");
+        n->ns_data.wl_surface_dmabuf.image = NULL;
+     }
+   im->native.data = ""
+   im->native.func.bind = NULL;
+   im->native.func.unbind = NULL;
+   im->native.func.free = NULL;
+   free(n);
+}
+
+/* A surface with attributes but no wl_resource asks whether such a buffer
+ * can be imported: Enlightenment's e_pixmap_dmabuf_test() does it before it
+ * accepts a buffer from a client. Import it, drop it, and answer with an
+ * image of the right size. */
+EMODAPI Evas_GL_Image *
+evas_gl_common_dmabuf_test_image_new(Evas_Engine_GL_Context *gc,
+                                     const Evas_Native_Surface *ns,
+                                     EGLDisplay disp)
+{
+   struct dmabuf_attributes *attr;
+   void *img;
+
+   if ((!gc) || (!ns)) return NULL;
+   attr = ns->data.wl_dmabuf.attr;
+   if (!attr) return NULL;
+
+   img = _dmabuf_import(disp, attr);
+   if (!img) return NULL;
+   evas_gl_common_eglDestroyImage(disp, img);
+
+   return evas_gl_common_image_new_from_data(gc, attr->width, attr->height,
+                                             NULL, 1, EVAS_COLORSPACE_ARGB8888);
+}
+
+/* Returns the image that already holds this wl_buffer, if any. When it is
+ * not im, it is referenced and im is freed. */
+EMODAPI Evas_GL_Image *
+evas_gl_common_dmabuf_native_lookup(Evas_Engine_GL_Context *gc, Evas_GL_Image *im,
+                                    const Evas_Native_Surface *ns)
+{
+   Evas_GL_Image *im2;
+   void *key;
+
+   if ((!gc) || (!ns)) return NULL;
+   key = ns->data.wl_dmabuf.resource;
+
+   im2 = eina_hash_find(gc->shared->native_wl_hash, &key);
+   if (!im2) return NULL;
+   if (im2 == im) return im;
+   if (!im2->native.data) return NULL;
+
+   evas_gl_common_image_ref(im2);
+   evas_gl_common_image_free(im);
+
+   return im2;
+}
+
+/* Returns EINA_FALSE, leaving im untouched, when the attributes cannot be
+ * used. */
+EMODAPI Eina_Bool
+evas_gl_common_dmabuf_native_attach(Evas_Engine_GL_Context *gc, Evas_GL_Image *im,
+                                    const Evas_Native_Surface *ns,
+                                    EGLDisplay disp)
+{
+   struct dmabuf_attributes *attr;
+   Native *n;
+   void *key;
+
+   if ((!gc) || (!im) || (!ns)) return EINA_FALSE;
+   attr = ns->data.wl_dmabuf.attr;
+   if (!attr) return EINA_FALSE;
+   if (attr->version != EVAS_DMABUF_ATTRIBUTE_VERSION) return EINA_FALSE;
+
+   n = calloc(1, sizeof(Native));
+   if (!n) return EINA_FALSE;
+
+   memcpy(&n->ns, ns, sizeof(Evas_Native_Surface));
+   memcpy(&n->ns_data.wl_surface_dmabuf.attr, attr, sizeof(*attr));
+   n->ns_data.wl_surface_dmabuf.resource = ns->data.wl_dmabuf.resource;
+
+   key = n->ns_data.wl_surface_dmabuf.resource;
+   eina_hash_add(gc->shared->native_wl_hash, &key, im);
+
+   im->native.yinvert = 1;
+   im->native.loose = 0;
+   im->native.disp = disp;
+   im->native.shared = gc->shared;
+   im->native.data = ""
+   im->native.func.bind = _dmabuf_native_bind_cb;
+   im->native.func.unbind = _dmabuf_native_unbind_cb;
+   im->native.func.free = _dmabuf_native_free_cb;
+   im->native.target = GL_TEXTURE_2D;
+   im->native.mipmap = 0;
+
+   evas_gl_common_image_native_enable(im);
+
+   return EINA_TRUE;
+}
+
+#endif
diff --git a/src/modules/evas/engines/gl_drm/evas_engine.c b/src/modules/evas/engines/gl_drm/evas_engine.c
index ea12deecf3..f1629d8e7f 100644
--- a/src/modules/evas/engines/gl_drm/evas_engine.c
+++ b/src/modules/evas/engines/gl_drm/evas_engine.c
@@ -14,47 +14,6 @@
 
 #define EVAS_GL_UPDATE_TILE_SIZE 16
 
-#ifndef DRM_FORMAT_MOD_LINEAR
-# define DRM_FORMAT_MOD_LINEAR 0
-#endif
-#ifndef DRM_FORMAT_MOD_INVALID
-# define DRM_FORMAT_MOD_INVALID ((1ULL << 56) - 1)
-#endif
-
-#ifndef EGL_DMA_BUF_PLANE3_FD_EXT
-# define EGL_DMA_BUF_PLANE3_FD_EXT 0x3440
-#endif
-#ifndef EGL_DMA_BUF_PLANE3_OFFSET_EXT
-# define EGL_DMA_BUF_PLANE3_OFFSET_EXT 0x3441
-#endif
-#ifndef EGL_DMA_BUF_PLANE3_PITCH_EXT
-# define EGL_DMA_BUF_PLANE3_PITCH_EXT 0x3442
-#endif
-#ifndef EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT
-# define EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT 0x3443
-#endif
-#ifndef EGL_DMA_BUF_PLANE0_MODIFIER_HI_EXT
-# define EGL_DMA_BUF_PLANE0_MODIFIER_HI_EXT 0x3444
-#endif
-#ifndef EGL_DMA_BUF_PLANE1_MODIFIER_LO_EXT
-# define EGL_DMA_BUF_PLANE1_MODIFIER_LO_EXT 0x3445
-#endif
-#ifndef EGL_DMA_BUF_PLANE1_MODIFIER_HI_EXT
-# define EGL_DMA_BUF_PLANE1_MODIFIER_HI_EXT 0x3446
-#endif
-#ifndef EGL_DMA_BUF_PLANE2_MODIFIER_LO_EXT
-# define EGL_DMA_BUF_PLANE2_MODIFIER_LO_EXT 0x3447
-#endif
-#ifndef EGL_DMA_BUF_PLANE2_MODIFIER_HIa_EXT
-# define EGL_DMA_BUF_PLANE2_MODIFIER_HI_EXT 0x3448
-#endif
-#ifndef EGL_DMA_BUF_PLANE3_MODIFIER_LO_EXT
-# define EGL_DMA_BUF_PLANE3_MODIFIER_LO_EXT 0x3449
-#endif
-#ifndef EGL_DMA_BUF_PLANE3_MODIFIER_HI_EXT
-# define EGL_DMA_BUF_PLANE3_MODIFIER_HI_EXT 0x344A
-#endif
-
 struct scanout_handle
 {
    Evas_Native_Scanout_Handler handler;
@@ -68,8 +27,6 @@ int _extn_have_context_priority = 0;
 
 /* local variables */
 static Eina_Bool initted = EINA_FALSE;
-static Eina_Bool dmabuf_present = EINA_FALSE;
-static Eina_Bool dmabuf_modifiers_present = EINA_FALSE;
 static int gl_wins = 0;
 static struct gbm_device *gbm_dev = NULL;
 static int gbm_dev_refs = 0;
@@ -110,6 +67,9 @@ glsym_func_void_ptr glsym_evas_gl_common_current_context_get = NULL;
 void *(*glsym_eglGetProcAddress)(const char *a) = NULL;
 EGLImageKHR  (*glsym_evas_gl_common_eglCreateImage) (EGLDisplay a, EGLContext b, EGLenum c, EGLClientBuffer d, const EGLAttrib *e) = NULL;
 int          (*glsym_evas_gl_common_eglDestroyImage) (EGLDisplay a, void *b) = NULL;
+Evas_GL_Image *(*glsym_evas_gl_common_dmabuf_test_image_new) (Evas_Engine_GL_Context *a, const Evas_Native_Surface *b, EGLDisplay c) = NULL;
+Evas_GL_Image *(*glsym_evas_gl_common_dmabuf_native_lookup)  (Evas_Engine_GL_Context *a, Evas_GL_Image *b, const Evas_Native_Surface *c) = NULL;
+Eina_Bool      (*glsym_evas_gl_common_dmabuf_native_attach)  (Evas_Engine_GL_Context *a, Evas_GL_Image *b, const Evas_Native_Surface *c, EGLDisplay d) = NULL;
 void (*glsym_glEGLImageTargetTexture2DOES)(int a, void *b) = NULL;
 unsigned int (*glsym_eglSwapBuffersWithDamage)(EGLDisplay a, void *b, const EGLint *d, EGLint c) = NULL;
 unsigned int (*glsym_eglQueryWaylandBufferWL)(EGLDisplay a, void *b, EGLint c, EGLint *d) = NULL;
@@ -237,6 +197,9 @@ symbols(void)
    LINK2GENERIC(eglGetProcAddress);
    LINK2GENERIC(evas_gl_common_eglCreateImage);
    LINK2GENERIC(evas_gl_common_eglDestroyImage);
+   LINK2GENERIC(evas_gl_common_dmabuf_test_image_new);
+   LINK2GENERIC(evas_gl_common_dmabuf_native_lookup);
+   LINK2GENERIC(evas_gl_common_dmabuf_native_attach);
    LINK2GENERIC(evas_gl_extension_string_check);
 
    _ckext = glsym_evas_gl_extension_string_check;
@@ -302,10 +265,6 @@ gl_extn_veto(Render_Engine *re)
         if ((!_ckext(str, "EGL_EXT_swap_buffers_with_damage")) &&
             (!_ckext(str, "EGL_KHR_swap_buffers_with_damage")))
           glsym_eglSwapBuffersWithDamage = NULL;
-        if (_ckext(str, "EGL_EXT_image_dma_buf_import"))
-          dmabuf_present = EINA_TRUE;
-        if (_ckext(str, "EGL_EXT_image_dma_buf_import_modifiers"))
-          dmabuf_modifiers_present = EINA_TRUE;
      }
    else
      {
@@ -673,137 +632,6 @@ drm_import_simple_dmabuf(Ecore_Drm2_Device *dev, struct dmabuf_attributes *attri
                                       dmabuf_fd, attributes->n_planes);
 }
 
-/* Code from weston's gl-renderer... */
-static EGLImageKHR
-_gl_import_dmabuf(EGLDisplay display, struct dmabuf_attributes *attributes, Eina_Bool with_modifier)
-{
-   EGLAttrib attribs[50];
-   int atti = 0;
-   Eina_Bool has_modifier = EINA_FALSE;
-
-   if (!dmabuf_present) return NULL;
-   if (!glsym_evas_gl_common_eglDestroyImage) return NULL;
-
-   /* This requires the Mesa commit in
-    * Mesa 10.3 (08264e5dad4df448e7718e782ad9077902089a07) or
-    * Mesa 10.2.7 (55d28925e6109a4afd61f109e845a8a51bd17652).
-    * Otherwise Mesa closes the fd behind our back and re-importing
-    * will fail.
-    * https://bugs.freedesktop.org/show_bug.cgi?id=76188
-    */
-
-   attribs[atti++] = EGL_WIDTH;
-   attribs[atti++] = attributes->width;
-   attribs[atti++] = EGL_HEIGHT;
-   attribs[atti++] = attributes->height;
-   attribs[atti++] = EGL_LINUX_DRM_FOURCC_EXT;
-   attribs[atti++] = attributes->format;
-   /* Passing the modifier attributes to a driver without
-    * EGL_EXT_image_dma_buf_import_modifiers gets the whole import rejected
-    * with EGL_BAD_ATTRIBUTE, which surfaces as a silently black window.
-    * Only send them when the driver actually understands them; otherwise
-    * fall back to letting it work the layout out implicitly. */
-   if ((with_modifier) && (dmabuf_modifiers_present) &&
-       (attributes->modifier[0] != DRM_FORMAT_MOD_INVALID))
-     has_modifier = EINA_TRUE;
-
-   if (attributes->n_planes > 0)
-     {
-        attribs[atti++] = EGL_DMA_BUF_PLANE0_FD_EXT;
-        attribs[atti++] = attributes->fd[0];
-        attribs[atti++] = EGL_DMA_BUF_PLANE0_OFFSET_EXT;
-        attribs[atti++] = attributes->offset[0];
-        attribs[atti++] = EGL_DMA_BUF_PLANE0_PITCH_EXT;
-        attribs[atti++] = attributes->stride[0];
-        if (has_modifier)
-          {
-             attribs[atti++] = EGL_DMA_BUF_PLANE0_MODIFIER_LO_EXT;
-             attribs[atti++] = attributes->modifier[0] & 0xFFFFFFFF;
-             attribs[atti++] = EGL_DMA_BUF_PLANE0_MODIFIER_HI_EXT;
-             attribs[atti++] = attributes->modifier[0] >> 32;
-          }
-     }
-
-   if (attributes->n_planes > 1)
-     {
-        attribs[atti++] = EGL_DMA_BUF_PLANE1_FD_EXT;
-        attribs[atti++] = attributes->fd[1];
-        attribs[atti++] = EGL_DMA_BUF_PLANE1_OFFSET_EXT;
-        attribs[atti++] = attributes->offset[1];
-        attribs[atti++] = EGL_DMA_BUF_PLANE1_PITCH_EXT;
-        attribs[atti++] = attributes->stride[1];
-        if (has_modifier)
-          {
-             attribs[atti++] = EGL_DMA_BUF_PLANE1_MODIFIER_LO_EXT;
-             attribs[atti++] = attributes->modifier[1] & 0xFFFFFFFF;
-             attribs[atti++] = EGL_DMA_BUF_PLANE1_MODIFIER_HI_EXT;
-             attribs[atti++] = attributes->modifier[1] >> 32;
-          }
-     }
-
-   if (attributes->n_planes > 2)
-     {
-        attribs[atti++] = EGL_DMA_BUF_PLANE2_FD_EXT;
-        attribs[atti++] = attributes->fd[2];
-        attribs[atti++] = EGL_DMA_BUF_PLANE2_OFFSET_EXT;
-        attribs[atti++] = attributes->offset[2];
-        attribs[atti++] = EGL_DMA_BUF_PLANE2_PITCH_EXT;
-        attribs[atti++] = attributes->stride[2];
-        if (has_modifier)
-          {
-             attribs[atti++] = EGL_DMA_BUF_PLANE2_MODIFIER_LO_EXT;
-             attribs[atti++] = attributes->modifier[2] & 0xFFFFFFFF;
-             attribs[atti++] = EGL_DMA_BUF_PLANE2_MODIFIER_HI_EXT;
-             attribs[atti++] = attributes->modifier[2] >> 32;
-          }
-     }
-
-   if (attributes->n_planes > 3)
-     {
-        attribs[atti++] = EGL_DMA_BUF_PLANE3_FD_EXT;
-        attribs[atti++] = attributes->fd[3];
-        attribs[atti++] = EGL_DMA_BUF_PLANE3_OFFSET_EXT;
-        attribs[atti++] = attributes->offset[3];
-        attribs[atti++] = EGL_DMA_BUF_PLANE3_PITCH_EXT;
-        attribs[atti++] = attributes->stride[3];
-        if (has_modifier)
-          {
-             attribs[atti++] = EGL_DMA_BUF_PLANE3_MODIFIER_LO_EXT;
-             attribs[atti++] = attributes->modifier[3] & 0xFFFFFFFF;
-             attribs[atti++] = EGL_DMA_BUF_PLANE3_MODIFIER_HI_EXT;
-             attribs[atti++] = attributes->modifier[3] >> 32;
-          }
-     }
-
-   attribs[atti++] = EGL_NONE;
-
-   return glsym_evas_gl_common_eglCreateImage(display, EGL_NO_CONTEXT,
-                                              EGL_LINUX_DMA_BUF_EXT,
-                                              NULL, attribs);
-}
-
-static EGLImageKHR
-gl_import_simple_dmabuf(EGLDisplay display, struct dmabuf_attributes *attributes)
-{
-   EGLImageKHR img;
-
-   img = _gl_import_dmabuf(display, attributes, EINA_TRUE);
-   if (img) return img;
-
-   /* The explicit layout was refused - a driver may advertise
-    * import_modifiers and still reject a particular modifier.  Retry
-    * implicitly before giving up and rendering nothing. */
-   if ((dmabuf_modifiers_present) &&
-       (attributes->modifier[0] != DRM_FORMAT_MOD_INVALID))
-     {
-        DBG("dmabuf import with modifier %#" PRIx64 " failed (%#x), "
-            "retrying without", attributes->modifier[0], eglGetError());
-        img = _gl_import_dmabuf(display, attributes, EINA_FALSE);
-     }
-
-   return img;
-}
-
 static void
 _native_cb_bind(void *image)
 {
@@ -813,21 +641,7 @@ _native_cb_bind(void *image)
    if (!(img = image)) return;
    if (!(n = img->native.data)) return;
 
-   if (n->ns.type == EVAS_NATIVE_SURFACE_WL_DMABUF)
-     {
-        /* Must re-import every time for coherency. */
-        if (n->ns_data.wl_surface_dmabuf.image)
-          glsym_evas_gl_common_eglDestroyImage(img->native.disp, n->ns_data.wl_surface_dmabuf.image);
-        n->ns_data.wl_surface_dmabuf.image = gl_import_simple_dmabuf(img->native.disp, &n->ns_data.wl_surface_dmabuf.attr);
-        if (!n->ns_data.wl_surface_dmabuf.image)
-          {
-             img->native.invalid = EINA_TRUE;
-             return;
-          }
-        img->native.invalid = EINA_FALSE;
-        glsym_glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, n->ns_data.wl_surface_dmabuf.image);
-     }
-   else if (n->ns.type == EVAS_NATIVE_SURFACE_WL)
+   if (n->ns.type == EVAS_NATIVE_SURFACE_WL)
      {
         if (n->ns_data.wl_surface.surface)
           {
@@ -855,15 +669,7 @@ _native_cb_unbind(void *image)
    if (!(img = image)) return;
    if (!(n = img->native.data)) return;
 
-   if (n->ns.type == EVAS_NATIVE_SURFACE_WL_DMABUF)
-     {
-        if (n->ns_data.wl_surface_dmabuf.image)
-          {
-             glsym_evas_gl_common_eglDestroyImage(img->native.disp, n->ns_data.wl_surface_dmabuf.image);
-             n->ns_data.wl_surface_dmabuf.image = NULL;
-          }
-     }
-   else if (n->ns.type == EVAS_NATIVE_SURFACE_WL)
+   if (n->ns.type == EVAS_NATIVE_SURFACE_WL)
      {
         //glBindTexture(GL_TEXTURE_2D, 0); //really need?
      }
@@ -973,17 +779,7 @@ _native_cb_free(void *image)
    if (!(n = img->native.data)) return;
    if (!(img->native.shared)) return;
 
-   if (n->ns.type == EVAS_NATIVE_SURFACE_WL_DMABUF)
-     {
-        wlid = n->ns_data.wl_surface_dmabuf.resource;
-        eina_hash_del(img->native.shared->native_wl_hash, &wlid, img);
-        if (glsym_evas_gl_common_eglDestroyImage && n->ns_data.wl_surface_dmabuf.image)
-          {
-             glsym_evas_gl_common_eglDestroyImage(img->native.disp, n->ns_data.wl_surface_dmabuf.image);
-             GLERRV("eglDestroyImage() failed.");
-          }
-     }
-   else if (n->ns.type == EVAS_NATIVE_SURFACE_WL)
+   if (n->ns.type == EVAS_NATIVE_SURFACE_WL)
      {
         wlid = (void*)n->ns_data.wl_surface.wl_buf;
         eina_hash_del(img->native.shared->native_wl_hash, &wlid, img);
@@ -1261,27 +1057,12 @@ eng_image_native_set(void *engine, void *image, void *native)
                                                         NULL, 1,
                                                         EVAS_COLORSPACE_ARGB8888);
           }
-        else if ((ns) && (ns->type == EVAS_NATIVE_SURFACE_WL_DMABUF))
+        else if ((ns) && (ns->type == EVAS_NATIVE_SURFACE_WL_DMABUF) &&
+                 (!ns->data.wl_dmabuf.resource) &&
+                 (glsym_evas_gl_common_dmabuf_test_image_new))
           {
-             if (!ns->data.wl_dmabuf.resource)
-               {
-                  struct dmabuf_attributes *attr;
-                  void *v = NULL;
-
-                  attr = ns->data.wl_dmabuf.attr;
-                  if (attr->version == EVAS_DMABUF_ATTRIBUTE_VERSION)
-                    v = gl_import_simple_dmabuf(ob->egl.disp, attr);
-                  if (!v) return NULL;
-
-                  glsym_evas_gl_common_eglDestroyImage(ob->egl.disp, v);
-                  img =
-                    glsym_evas_gl_common_image_new_from_data(ob->gl_context,
-                                                             attr->width,
-                                                             attr->height,
-                                                             NULL, 1,
-                                                             EVAS_COLORSPACE_ARGB8888);
-                  return img;
-               }
+             return glsym_evas_gl_common_dmabuf_test_image_new(ob->gl_context,
+                                                              ns, ob->egl.disp);
           }
         else
           return NULL;
@@ -1331,17 +1112,11 @@ eng_image_native_set(void *engine, void *image, void *native)
 
    if (ns->type == EVAS_NATIVE_SURFACE_WL_DMABUF)
      {
-        wlid = wl_buf;
-        img2 = eina_hash_find(ob->gl_context->shared->native_wl_hash, &wlid);
-        if (img2 == img) return img;
-        if (img2)
+        if (glsym_evas_gl_common_dmabuf_native_lookup)
           {
-             if((n = img2->native.data))
-               {
-                  glsym_evas_gl_common_image_ref(img2);
-                  glsym_evas_gl_common_image_free(img);
-                  return img2;
-               }
+             img2 = glsym_evas_gl_common_dmabuf_native_lookup(ob->gl_context,
+                                                             img, ns);
+             if (img2) return img2;
           }
      }
    else if (ns->type == EVAS_NATIVE_SURFACE_WL)
@@ -1387,38 +1162,14 @@ eng_image_native_set(void *engine, void *image, void *native)
      {
         if (native)
           {
-             struct dmabuf_attributes *a;
-
-             a = ns->data.wl_dmabuf.attr;
-             if (a->version != EVAS_DMABUF_ATTRIBUTE_VERSION)
+             if ((!glsym_evas_gl_common_dmabuf_native_attach) ||
+                 (!glsym_evas_gl_common_dmabuf_native_attach(ob->gl_context,
+                                                             img, ns,
+                                                             ob->egl.disp)))
                {
                   glsym_evas_gl_common_image_free(img);
                   return NULL;
                }
-             if ((n = calloc(1, sizeof(Native))))
-               {
-                  struct dmabuf_attributes *a2;
-
-                  a2 = ns->data.wl_dmabuf.attr;
-                  memcpy(&(n->ns), ns, sizeof(Evas_Native_Surface));
-                  memcpy(&n->ns_data.wl_surface_dmabuf.attr, a2, sizeof(*a2));
-                  eina_hash_add(ob->gl_context->shared->native_wl_hash,
-                                &wlid, img);
-
-                  n->ns_data.wl_surface_dmabuf.resource = wl_buf;
-                  img->native.yinvert = 1;
-                  img->native.loose = 0;
-                  img->native.disp = ob->egl.disp;
-                  img->native.shared = ob->gl_context->shared;
-                  img->native.data = ""
-                  img->native.func.bind = _native_cb_bind;
-                  img->native.func.unbind = _native_cb_unbind;
-                  img->native.func.free = _native_cb_free;
-                  img->native.target = GL_TEXTURE_2D;
-                  img->native.mipmap = 0;
-
-                  glsym_evas_gl_common_image_native_enable(img);
-               }
           }
      }
    else if (ns->type == EVAS_NATIVE_SURFACE_WL)
diff --git a/src/modules/evas/engines/gl_generic/meson.build b/src/modules/evas/engines/gl_generic/meson.build
index 47aed6d81c..4165d329bc 100644
--- a/src/modules/evas/engines/gl_generic/meson.build
+++ b/src/modules/evas/engines/gl_generic/meson.build
@@ -25,6 +25,7 @@ common_engine_src = [
   'evas_ector_gl_span_types.h',
   'evas_gl_define.h',
   'evas_gl_context.c',
+  'evas_gl_native_dmabuf.c',
   'evas_gl_file_cache.c',
   'evas_gl_shader.c',
   'evas_gl_rectangle.c',

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to