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

git pushed a commit to branch devs/cedric/wl/drm-device
in repository efl.

View the commit online.

commit 84c2c70c7e5118d73275ff2ab1895e2e8b628aee
Author: Cedric BAIL <[email protected]>
AuthorDate: Sun Nov 29 18:30:54 2026 -0600

    evas:gl: expose the DRM device behind Evas GL
    
    zwp_linux_dmabuf_v1 version 4 replaces the format and modifier events
    with feedback objects, and every feedback object has to carry a
    main_device: the dev_t of the DRM node the compositor imports buffers
    on. A client resolves that number to a real device and allocates there,
    so on a multi-GPU machine it is what keeps the buffer on the GPU the
    compositor composites with instead of copying across every frame.
    
    A compositor built on Evas cannot answer that today. The EGLDisplay that
    knows the device lives inside Evas and is not reachable from outside, so
    add the one entry that exposes it, next to evasglQueryDmaBufFormats and
    evasglQueryDmaBufModifiers which exist for the same reason.
    
    Every failure path returns EINA_FALSE and leaves the caller's value
    alone - no EGL, no EGL_EXT_device_query, software rendering. There is
    deliberately no default: /dev/dri/renderD128 is right on the machines
    where it does not matter and wrong on the multi-GPU laptop that dmabuf
    feedback was invented for, and a wrong device silently sends clients to
    the wrong GPU. A caller that cannot get an answer must advertise
    version 3 instead, which is what the NULL entry and EINA_FALSE are for.
    
    Two things did not transfer from the neighbouring extension blocks.
    eglQueryDisplayAttribEXT and eglQueryDeviceStringEXT come from
    EGL_EXT_device_query, which is a client extension: it is reported by
    eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS) and never by the display,
    so the support scan had to learn to consult the client extension string.
    The GL and GLES scans go through the EGL blocks too, as they fill in
    the evasgl* entries of the API they hand out, so all four learnt it.
    That match is on whole tokens rather than by strstr(), because
    GL_KHR_debug is a suffix of the client extension EGL_KHR_debug and would
    otherwise light up its block on drivers that do not have it. The device
    extensions are matched the same way: EGL_EXT_device_drm is a prefix of
    EGL_EXT_device_drm_render_node, and asking a device for a string it
    does not implement leaves an EGL error behind. And the
    block is kept separate from EGL_EXT_image_dma_buf_import_modifiers:
    folded in, a driver without device_query would discard support for the
    whole block and lose the format and modifier queries that work today.
    
    The device is a property of the display, so it is read from the display
    of the Evas_GL given, through the previous commit's output, and not of
    whatever Evas GL context happens to be current. A compositor asks once
    the canvas has long made its own context current to render with, and
    got EINA_FALSE when the lookup followed that.
    
    The test asks with the context current, without it, after the canvas
    rendered, and with another Evas_GL current, and expects the same device
    each time. It skips where the display has no DRM device.
    
    dev_t crosses the API as uint64_t. Its width is not guaranteed by the
    ABI and the wire format the callers feed wants a fixed size anyway.
    
    Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 src/lib/evas/Evas_GL.h                             |  38 ++++++-
 .../evas/engines/gl_common/evas_gl_api_ext.c       | 110 ++++++++++++++++++++-
 .../evas/engines/gl_common/evas_gl_api_ext.h       |  17 ++++
 .../evas/engines/gl_common/evas_gl_api_ext_def.h   |  22 +++++
 src/tests/evas/evas_test_evasgl.c                  |  67 +++++++++++++
 5 files changed, 249 insertions(+), 5 deletions(-)

diff --git a/src/lib/evas/Evas_GL.h b/src/lib/evas/Evas_GL.h
index c740439d31..f7d458771f 100644
--- a/src/lib/evas/Evas_GL.h
+++ b/src/lib/evas/Evas_GL.h
@@ -5118,8 +5118,9 @@ typedef unsigned long long EvasGLTime;
  * Version 5: [version 4] + GLES3.1
  * Version 6: [version 5] + GLES3.2
  * Version 7: [version 7] + query formats + modifiers
+ * Version 8: [version 7] + query the DRM device
  */
-#define EVAS_GL_API_VERSION 7
+#define EVAS_GL_API_VERSION 8
 
 /**
  * @brief The Evas GL API
@@ -6126,6 +6127,41 @@ EvasGLImage *img = glapi->evasglCreateImageForContext
     */
    Eina_Bool    (*evasglQueryDmaBufModifiers) (Evas_GL *evas_gl, int format, int max_modifiers, uint64_t *modifiers, Eina_Bool *external_only, int *num_modifiers);
    /** @} */
+
+   /**
+    * @name Evas GL DRM device functions
+    *
+    * Evas_GL_API version 8 or higher.
+    *
+    * @since 1.30
+    * @{ */
+   /**
+    * @anchor evasglQueryDrmDevice
+    * @brief Get the DRM device this Evas_GL renders on.
+    *
+    * @param[in]  evas_gl  The Evas_GL object.
+    * @param[out] device   The dev_t of the DRM node, widened to a fixed size.
+    *
+    * @return @c EINA_TRUE and a device on success, @c EINA_FALSE otherwise.
+    *
+    * A Wayland compositor needs this to fill in the main_device of a
+    * zwp_linux_dmabuf_v1 feedback object, so that a client allocates its
+    * buffers on the GPU the compositor will import them on.
+    *
+    * There is no fallback and no default. @c EINA_FALSE is returned whenever
+    * the device cannot be determined - no EGL, a driver without
+    * EGL_EXT_device_query, or software rendering - and @p device is left
+    * untouched. A caller that gets @c EINA_FALSE must not substitute a guess:
+    * naming the wrong device sends a client to the wrong GPU, which is a
+    * worse outcome than naming none.
+    *
+    * Use major()/minor() to resolve the value back to a /dev/dri node. It may
+    * name either the render node or the primary node.
+    *
+    * No context needs to be current, and the answer is the same whichever is.
+    */
+   Eina_Bool    (*evasglQueryDrmDevice) (Evas_GL *evas_gl, uint64_t *device);
+   /** @} */
 };
 
 /**
diff --git a/src/modules/evas/engines/gl_common/evas_gl_api_ext.c b/src/modules/evas/engines/gl_common/evas_gl_api_ext.c
index 41f81e65de..9653e5ccb1 100644
--- a/src/modules/evas/engines/gl_common/evas_gl_api_ext.c
+++ b/src/modules/evas/engines/gl_common/evas_gl_api_ext.c
@@ -8,6 +8,11 @@
 # include <dlfcn.h>
 #endif
 
+#ifdef GL_GLES
+# include <sys/types.h>
+# include <sys/stat.h>
+#endif
+
 #define EVGL_FUNC_BEGIN() if (UNLIKELY(_need_context_restore)) _context_restore()
 
 // list of egl extensions
@@ -435,6 +440,99 @@ _evgl_evasglQueryDmaBufModifiers(Evas_GL *evas_gl,
    return EXT_FUNC_EGL(eglQueryDmaBufModifiersEXT)(dpy, format, max_modifiers, modifiers, external_only, num_modifiers);
 }
 
+/* Is name one of the space separated tokens of list? Not strstr(): extension
+ * names are prefixes of one another, EGL_EXT_device_drm of
+ * EGL_EXT_device_drm_render_node for one. */
+static Eina_Bool
+_evgl_ext_token_find(const char *list, const char *name)
+{
+   const char *p = list;
+   size_t len = strlen(name);
+
+   while ((p = strstr(p, name)))
+     {
+        if (((p == list) || (p[-1] == ' ')) &&
+            ((p[len] == ' ') || (p[len] == '\0')))
+          return EINA_TRUE;
+        p += len;
+     }
+   return EINA_FALSE;
+}
+
+/* EGL client extensions - the ones reported by eglQueryString(EGL_NO_DISPLAY,
+ * EGL_EXTENSIONS) rather than by a display. The engines only ever hand us a
+ * display extension string, so without this an extension block naming a client
+ * extension could never match. Queried once and cached. */
+static Eina_Bool
+_evgl_egl_client_ext_supported(const char *name)
+{
+   static const char *exts = NULL;
+
+   if (!exts)
+     {
+        exts = eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS);
+        /* EGL_EXT_client_extensions is itself optional: without it this is an
+         * EGL_BAD_DISPLAY that must not be left latched for the next caller. */
+        if (!exts)
+          {
+             eglGetError();
+             exts = "";
+          }
+     }
+   return _evgl_ext_token_find(exts, name);
+}
+
+/* See evasglQueryDrmDevice in Evas_GL.h. The display is the one of evas_gl,
+ * not of the current engine: EGLDISPLAY_GET() follows whatever is current, and
+ * the device of a display does not depend on that. */
+static Eina_Bool
+_evgl_evasglQueryDrmDevice(Evas_GL *evas_gl, uint64_t *device)
+{
+   EGLDisplay dpy;
+   const char *exts, *path = NULL;
+   EGLDeviceEXT dev;
+   EGLAttrib attr = 0;
+   struct stat st;
+
+   if ((!evas_gl) || (!device)) return EINA_FALSE;
+   if ((!evgl_engine) || (!evgl_engine->funcs) || (!evgl_engine->funcs->display_get))
+     return EINA_FALSE;
+   dpy = (EGLDisplay)evgl_engine->funcs->display_get(_evgl_engine_data_get(evas_gl));
+   if (!dpy) return EINA_FALSE;
+   if (!EXT_FUNC_EGL(eglQueryDisplayAttribEXT) ||
+       !EXT_FUNC_EGL(eglQueryDeviceStringEXT))
+     return EINA_FALSE;
+
+   /* Which EGLDevice is behind this display... */
+   if (!EXT_FUNC_EGL(eglQueryDisplayAttribEXT)(dpy, EGL_DEVICE_EXT, &attr))
+     return EINA_FALSE;
+   dev = (EGLDeviceEXT)attr;
+   if (!dev) return EINA_FALSE;
+
+   /* ...and which DRM node is behind that. Ask the device what it can answer
+    * first: querying a string it does not implement latches an EGL error that
+    * unrelated code would then trip over. Software rendering answers neither,
+    * which is the honest EINA_FALSE below. */
+   exts = EXT_FUNC_EGL(eglQueryDeviceStringEXT)(dev, EGL_EXTENSIONS);
+   if (!exts) return EINA_FALSE;
+
+   /* The render node is the one a client wants to allocate on. The primary
+    * node is the fallback for drivers that do not expose one - the dmabuf
+    * feedback spec leaves the node type unspecified. */
+   if (_evgl_ext_token_find(exts, "EGL_EXT_device_drm_render_node"))
+     path = EXT_FUNC_EGL(eglQueryDeviceStringEXT)(dev, EGL_DRM_RENDER_NODE_FILE_EXT);
+   if (!path && _evgl_ext_token_find(exts, "EGL_EXT_device_drm"))
+     path = EXT_FUNC_EGL(eglQueryDeviceStringEXT)(dev, EGL_DRM_DEVICE_FILE_EXT);
+   if (!path) return EINA_FALSE;
+
+   if (stat(path, &st) != 0) return EINA_FALSE;
+
+   /* dev_t crosses the API as uint64_t: its width is not part of the ABI, and
+    * the consumers of this (a wl_array on the wire) want a fixed size. */
+   *device = (uint64_t)st.st_rdev;
+   return EINA_TRUE;
+}
+
 #else
 #endif
 
@@ -650,7 +748,8 @@ evgl_api_egl_ext_init(void *getproc, const char *glueexts)
      }
 
 #define _EVASGL_EXT_CHECK_SUPPORT(name) \
-   (strstr(glueexts, name) != NULL)
+   ((strstr(glueexts, name) != NULL) || \
+    _evgl_egl_client_ext_supported(name))
 
 #define _EVASGL_EXT_DISCARD_SUPPORT() \
    *ext_support = 0;
@@ -830,7 +929,8 @@ _evgl_api_gles2_ext_init(void *getproc, const char *glueexts)
      }
 
 #define _EVASGL_EXT_CHECK_SUPPORT(name) \
-   (strstr(glexts, name) != NULL || strstr(glueexts, name) != NULL)
+   (strstr(glexts, name) != NULL || strstr(glueexts, name) != NULL || \
+    _evgl_egl_client_ext_supported(name))
 
 #define _EVASGL_EXT_DISCARD_SUPPORT() \
    *ext_support = 0;
@@ -1109,7 +1209,8 @@ _evgl_api_gles1_ext_init(void *getproc, const char *glueexts)
    }
 
 #define _EVASGL_EXT_CHECK_SUPPORT(name) \
-   ((strstr(glexts, name) != NULL) || (strstr(glueexts, name) != NULL))
+   ((strstr(glexts, name) != NULL) || (strstr(glueexts, name) != NULL) || \
+    _evgl_egl_client_ext_supported(name))
 
 #define _EVASGL_EXT_DISCARD_SUPPORT() \
    *ext_support = 0;
@@ -1398,7 +1499,8 @@ _evgl_api_gles3_ext_init(void *getproc, const char *glueexts)
    }
 
 #define _EVASGL_EXT_CHECK_SUPPORT(name) \
-   ((strstr(glexts, name) != NULL) || (strstr(glueexts, name) != NULL))
+   ((strstr(glexts, name) != NULL) || (strstr(glueexts, name) != NULL) || \
+    _evgl_egl_client_ext_supported(name))
 
 #define _EVASGL_EXT_DISCARD_SUPPORT() \
    *ext_support = 0;
diff --git a/src/modules/evas/engines/gl_common/evas_gl_api_ext.h b/src/modules/evas/engines/gl_common/evas_gl_api_ext.h
index 118e409cf3..654ff7d316 100644
--- a/src/modules/evas/engines/gl_common/evas_gl_api_ext.h
+++ b/src/modules/evas/engines/gl_common/evas_gl_api_ext.h
@@ -6,6 +6,23 @@
 #ifdef GL_GLES
 #include <EGL/egl.h>
 #include <EGL/eglext.h>
+
+/* EGL headers older than EGL_EXT_device_base know nothing about EGLDevice,
+ * and the DRM node strings are younger still. Declare what we need so that
+ * evasglQueryDrmDevice() builds against any vintage of eglext.h; whether the
+ * driver actually implements it is decided at run time. */
+# ifndef EGL_EXT_device_base
+typedef void *EGLDeviceEXT;
+# endif
+# ifndef EGL_DEVICE_EXT
+#  define EGL_DEVICE_EXT 0x322C
+# endif
+# ifndef EGL_DRM_DEVICE_FILE_EXT
+#  define EGL_DRM_DEVICE_FILE_EXT 0x3233
+# endif
+# ifndef EGL_DRM_RENDER_NODE_FILE_EXT
+#  define EGL_DRM_RENDER_NODE_FILE_EXT 0x3377
+# endif
 #else
 # ifdef BUILD_ENGINE_GL_COCOA
 #  include <OpenGL/gl.h>
diff --git a/src/modules/evas/engines/gl_common/evas_gl_api_ext_def.h b/src/modules/evas/engines/gl_common/evas_gl_api_ext_def.h
index 3a5afcbdfc..f76df528c7 100644
--- a/src/modules/evas/engines/gl_common/evas_gl_api_ext_def.h
+++ b/src/modules/evas/engines/gl_common/evas_gl_api_ext_def.h
@@ -1694,6 +1694,28 @@ _EVASGL_EXT_BEGIN(EGL_EXT_image_dma_buf_import_modifiers)
         _EVASGL_EXT_FUNCTION_END()
 _EVASGL_EXT_END()
 
+/* This one is a client extension: it is reported by
+ * eglQueryString(EGL_NO_DISPLAY, EGL_EXTENSIONS), not by the display, which is
+ * why the support scan has to consult the client extension string too. Keep it
+ * in a block of its own - folded into the dmabuf block above, a driver without
+ * it would discard support for the whole block and lose the format and
+ * modifier queries that work today. */
+_EVASGL_EXT_BEGIN(EGL_EXT_device_query)
+
+        _EVASGL_EXT_DRVNAME(EGL_EXT_device_query)
+
+        _EVASGL_EXT_FUNCTION_PRIVATE_BEGIN(EGLBoolean, eglQueryDisplayAttribEXT, (EGLDisplay dpy, EGLint attribute, EGLAttrib *value), (dpy, attribute, value))
+                _EVASGL_EXT_FUNCTION_DRVFUNC_PROCADDR("eglQueryDisplayAttribEXT")
+        _EVASGL_EXT_FUNCTION_PRIVATE_END()
+        _EVASGL_EXT_FUNCTION_PRIVATE_BEGIN(const char *, eglQueryDeviceStringEXT, (EGLDeviceEXT device, EGLint name), (device, name))
+                _EVASGL_EXT_FUNCTION_DRVFUNC_PROCADDR("eglQueryDeviceStringEXT")
+        _EVASGL_EXT_FUNCTION_PRIVATE_END()
+
+        _EVASGL_EXT_FUNCTION_BEGIN(Eina_Bool, evasglQueryDrmDevice, (Evas_GL *evas_gl, uint64_t *device), (evas_gl, device))
+                _EVASGL_EXT_FUNCTION_DRVFUNC(_evgl_evasglQueryDrmDevice)
+        _EVASGL_EXT_FUNCTION_END()
+_EVASGL_EXT_END()
+
 
 #if 0
 _EVASGL_EXT_BEGIN(EGL_SEC_map_image)
diff --git a/src/tests/evas/evas_test_evasgl.c b/src/tests/evas/evas_test_evasgl.c
index 8e04a74721..88867e72ae 100644
--- a/src/tests/evas/evas_test_evasgl.c
+++ b/src/tests/evas/evas_test_evasgl.c
@@ -519,6 +519,70 @@ end:
    END_EVASGL_TEST();
 }
 
+static void
+_test_evasgl_drm_device(const char *engine)
+{
+   /* the DRM device is a property of the display, not of what is current */
+
+   START_EVASGL_TEST(engine, NULL);
+   Evas_GL_Context *ctx, *ctx2;
+   Evas_GL_Surface *sfc, *sfc2;
+   Evas_GL_Config *cfg;
+   Evas_GL_API *gl;
+   Evas_GL *evgl, *evgl2;
+   uint64_t device = 0, again;
+
+   fail_if(!(evgl = evas_gl_new(evas)));
+   fail_if(!(cfg = evas_gl_config_new()));
+   fail_if(!(sfc = evas_gl_surface_create(evgl, cfg, 1, 1)));
+   fail_if(!(ctx = evas_gl_context_create(evgl, NULL)));
+   fail_if(!evas_gl_make_current(evgl, sfc, ctx));
+   fail_if(!(gl = evas_gl_context_api_get(evgl, ctx)));
+
+   if (!gl->evasglQueryDrmDevice || !gl->evasglQueryDrmDevice(evgl, &device))
+     {
+        printf("No DRM device behind this display. Skipping.\n");
+        goto end;
+     }
+   fail_if(!device);
+
+   again = 0;
+   fail_if(!gl->evasglQueryDrmDevice(evgl, &again));
+   fail_if(again != device);
+
+   fail_if(!evas_gl_make_current(evgl, NULL, NULL));
+   again = 0;
+   fail_if(!gl->evasglQueryDrmDevice(evgl, &again));
+   fail_if(again != device);
+
+   /* the canvas renders with a context of its own */
+   evas_object_geometry_set(im, 0, 0, 1, 1);
+   ecore_evas_manual_render(ee);
+   again = 0;
+   fail_if(!gl->evasglQueryDrmDevice(evgl, &again));
+   fail_if(again != device);
+
+   fail_if(!(evgl2 = evas_gl_new(evas)));
+   fail_if(!(sfc2 = evas_gl_surface_create(evgl2, cfg, 1, 1)));
+   fail_if(!(ctx2 = evas_gl_context_create(evgl2, NULL)));
+   fail_if(!evas_gl_make_current(evgl2, sfc2, ctx2));
+   again = 0;
+   fail_if(!gl->evasglQueryDrmDevice(evgl, &again));
+   fail_if(again != device);
+   fail_if(!evas_gl_make_current(evgl2, NULL, NULL));
+   evas_gl_context_destroy(evgl2, ctx2);
+   evas_gl_surface_destroy(evgl2, sfc2);
+   evas_gl_free(evgl2);
+
+end:
+   fail_if(!evas_gl_make_current(evgl, NULL, NULL));
+   evas_gl_context_destroy(evgl, ctx);
+   evas_gl_surface_destroy(evgl, sfc);
+   evas_gl_config_free(cfg);
+   evas_gl_free(evgl);
+   END_EVASGL_TEST();
+}
+
 #define TEST_ADD_OPT(name, opt) \
    EFL_START_TEST(evas ## name ## _opengl_x11) \
    { name("opengl_x11"); } \
@@ -537,6 +601,7 @@ TEST_ADD(_test_evasgl_fbo)
 TEST_ADD(_test_evasgl_formats)
 TEST_ADD(_test_evasgl_pbuffer)
 TEST_ADD(_test_evasgl_dmabuf_formats)
+TEST_ADD(_test_evasgl_drm_device)
 
 /* APIs still to test:
  *
@@ -565,6 +630,7 @@ void evas_test_evasgl(TCase *tc)
         TEST_ADD(_test_evasgl_pbuffer);
         TEST_ADD(_test_evasgl_formats);
         TEST_ADD(_test_evasgl_dmabuf_formats);
+        TEST_ADD(_test_evasgl_drm_device);
      }
 
 #undef TEST_ADD
@@ -579,4 +645,5 @@ void evas_test_evasgl(TCase *tc)
    TEST_ADD(_test_evasgl_pbuffer);
    TEST_ADD(_test_evasgl_formats);
    TEST_ADD(_test_evasgl_dmabuf_formats);
+   TEST_ADD(_test_evasgl_drm_device);
 }

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

Reply via email to