This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch master
in repository efl.
View the commit online.
commit 74360d9301a0f483122cd5d777b77bd841783d4e
Author: Cedric BAIL <[email protected]>
AuthorDate: Wed Dec 2 11:29:31 2026 -0600
evas:gl_drm: export the buffer of a frame as a dmabuf
A consumer that hands the frames to another process or to a hardware
encoder needs them as dmabufs. The frame holds a gbm_bo, and the
header of the engine is not installed, so the consumer cannot ask gbm
itself.
Add func.frame_dmabuf_get() next to func.frame_release(). It makes new
descriptors for each call, as gbm_bo_get_fd() does, so what a consumer
imported stays valid after the frame is released or its canvas resized;
only the content stops being the frame's at the release. It fails for
a frame whose buffer is gone.
The modifier is DRM_FORMAT_MOD_LINEAR, not what gbm_bo_get_modifier()
answers. gbm has no modifier to report for a surface made without any,
and gives DRM_FORMAT_MOD_INVALID, which an importer reads as "layout
unknown, to be guessed" when the engine knows it asked for linear
buffers. Saying so lets a consumer import with EGL_EXT_image_dma_buf_
import_modifiers or VA-API and get the answer it expects.
That is checked, not assumed. When gbm can say how many planes the
buffer has and which modifier, an answer other than one plane and
linear or invalid makes the export fail with an error, instead of
describing a buffer wrongly. Both queries come with recent gbm only,
so they are looked up at run time, as ecore_wl2 does, and the engine
keeps its unversioned dependency on gbm: when they are missing, the
buffer is taken for what the engine asked for. The rest of the layout
needs gbm_bo_get_fd() and gbm_bo_get_stride(), which every gbm has.
Co-Authored-By: Claude Fable 5.2 <[email protected]>
---
.../evas/engines/gl_drm/Evas_Engine_GL_Drm.h | 34 ++++++-
src/modules/evas/engines/gl_drm/evas_engine.c | 1 +
src/modules/evas/engines/gl_drm/evas_engine.h | 2 +
src/modules/evas/engines/gl_drm/evas_outbuf.c | 103 +++++++++++++++++++++
src/tests/evas/evas_test_gl_drm.c | 90 ++++++++++++++++++
5 files changed, 228 insertions(+), 2 deletions(-)
diff --git a/src/modules/evas/engines/gl_drm/Evas_Engine_GL_Drm.h b/src/modules/evas/engines/gl_drm/Evas_Engine_GL_Drm.h
index 95fd14612e..1a970dd4ea 100644
--- a/src/modules/evas/engines/gl_drm/Evas_Engine_GL_Drm.h
+++ b/src/modules/evas/engines/gl_drm/Evas_Engine_GL_Drm.h
@@ -16,13 +16,33 @@ typedef struct _Evas_Engine_Info_GL_Drm Evas_Engine_Info_GL_Drm;
* Evas_Engine_Info_GL_Drm.func.frame_release(). */
typedef struct _Evas_Engine_GL_Drm_Frame Evas_Engine_GL_Drm_Frame;
+/* How a frame is laid out as a dmabuf, filled by func.frame_dmabuf_get(). */
+typedef struct _Evas_Engine_GL_Drm_Dmabuf Evas_Engine_GL_Drm_Dmabuf;
+
+struct _Evas_Engine_GL_Drm_Dmabuf
+{
+ /* Of every plane. The engine asked for linear buffers, and says so:
+ * DRM_FORMAT_MOD_LINEAR, not the DRM_FORMAT_MOD_INVALID of gbm, which
+ * would leave an importer to guess. */
+ uint64_t modifier;
+ /* Of the first plane_count planes, -1 for the others. Descriptors made
+ * for this call that the caller closes. */
+ int fd[4];
+ unsigned int stride[4];
+ unsigned int offset[4];
+ /* A DRM fourcc */
+ unsigned int format;
+ int w, h;
+ unsigned int plane_count;
+};
+
struct _Evas_Engine_GL_Drm_Frame
{
/* The buffer holding the frame. Today it is always XRGB8888 and
* linear, made with GBM_BO_USE_LINEAR, whatever gbm_bo_get_modifier()
* says (DRM_FORMAT_MOD_INVALID): a consumer can map it or export it
- * without a modifier. The layout will be reported explicitly when the
- * dmabuf export lands. Its rows run top to bottom. A reader must
+ * without a modifier. func.frame_dmabuf_get() reports its layout. Its
+ * rows run top to bottom. A reader must
* import the dmabuf or bracket its mapping with DMA_BUF_IOCTL_SYNC to
* wait for the GPU. NULL once the output that drew it has been
* resized or freed: the buffer is gone with it. */
@@ -130,6 +150,16 @@ struct _Evas_Engine_Info_GL_Drm
* it tells how many buffers the engine has without assuming a
* number. */
Eina_Bool (*frame_buffer_available)(const Evas_Engine_Info_GL_Drm *info);
+ /* Exports the buffer of a frame as a dmabuf. Fresh descriptors
+ * come with each call, and they stay valid after the frame is
+ * released or its canvas resized; only what they hold is the
+ * frame's until it is released. The GPU may still be drawing when
+ * this returns, and no fence is given: an importer waits by
+ * importing the dmabuf, and a reader that maps it brackets the
+ * mapping with DMA_BUF_IOCTL_SYNC. EINA_FALSE, and dmabuf left
+ * alone, when the buffer is gone or cannot be exported. */
+ Eina_Bool (*frame_dmabuf_get)(const Evas_Engine_GL_Drm_Frame *frame,
+ Evas_Engine_GL_Drm_Dmabuf *dmabuf);
} func;
};
diff --git a/src/modules/evas/engines/gl_drm/evas_engine.c b/src/modules/evas/engines/gl_drm/evas_engine.c
index 8d7ea48e67..fc09345750 100644
--- a/src/modules/evas/engines/gl_drm/evas_engine.c
+++ b/src/modules/evas/engines/gl_drm/evas_engine.c
@@ -841,6 +841,7 @@ eng_output_info_setup(void *info)
einfo->info.fd = -1;
einfo->func.frame_release = evas_outbuf_frame_release;
einfo->func.frame_buffer_available = evas_outbuf_frame_buffer_available;
+ einfo->func.frame_dmabuf_get = evas_outbuf_frame_dmabuf_get;
}
static void *
diff --git a/src/modules/evas/engines/gl_drm/evas_engine.h b/src/modules/evas/engines/gl_drm/evas_engine.h
index dca1037e64..01cf73d935 100644
--- a/src/modules/evas/engines/gl_drm/evas_engine.h
+++ b/src/modules/evas/engines/gl_drm/evas_engine.h
@@ -140,6 +140,8 @@ void evas_outbuf_flush(Outbuf *ob, Tilebuf_Rect *surface_damage, Tilebuf_Rect *b
void evas_outbuf_release_fb(void *, void *);
void evas_outbuf_frame_release(Evas_Engine_GL_Drm_Frame *frame);
Eina_Bool evas_outbuf_frame_buffer_available(const Evas_Engine_Info_GL_Drm *info);
+Eina_Bool evas_outbuf_frame_dmabuf_get(const Evas_Engine_GL_Drm_Frame *frame,
+ Evas_Engine_GL_Drm_Dmabuf *dmabuf);
void evas_outbuf_damage_region_set(Outbuf *ob, Tilebuf_Rect *damage);
Evas_Engine_GL_Context* evas_outbuf_gl_context_get(Outbuf *ob);
diff --git a/src/modules/evas/engines/gl_drm/evas_outbuf.c b/src/modules/evas/engines/gl_drm/evas_outbuf.c
index 728698d5a9..b0f7f64e4a 100644
--- a/src/modules/evas/engines/gl_drm/evas_outbuf.c
+++ b/src/modules/evas/engines/gl_drm/evas_outbuf.c
@@ -1,5 +1,15 @@
#include "evas_engine.h"
+#include <dlfcn.h>
+
+/* Not in the drm_fourcc.h that the EFL carries */
+#ifndef DRM_FORMAT_MOD_LINEAR
+# define DRM_FORMAT_MOD_LINEAR 0ULL
+#endif
+#ifndef DRM_FORMAT_MOD_INVALID
+# define DRM_FORMAT_MOD_INVALID ((1ULL << 56) - 1)
+#endif
+
/* local variables */
static Outbuf *_evas_gl_drm_window = NULL;
static EGLContext context = EGL_NO_CONTEXT;
@@ -12,6 +22,10 @@ static PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC dlsym_eglCreatePlatformWindowSur
typedef struct _Outbuf_Frame Outbuf_Frame;
+/* Only in recent gbm, see _evas_outbuf_gbm_layout_symbols_resolve() */
+static uint64_t (*sym_gbm_bo_get_modifier)(struct gbm_bo *bo) = NULL;
+static int (*sym_gbm_bo_get_plane_count)(struct gbm_bo *bo) = NULL;
+
/* What an Evas_Engine_GL_Drm_Frame really is: one per gbm_bo, kept as the
* user data of the buffer. It is freed once the buffer is gone and the
* consumer gave it back, in whichever order those happen. */
@@ -164,6 +178,95 @@ evas_outbuf_frame_buffer_available(const Evas_Engine_Info_GL_Drm *info)
return !!gbm_surface_has_free_buffers(info->info.surface);
}
+/* Recent gbm answers more than the engine needs to know: resolved at run
+ * time so that an older one is no reason to refuse to draw. */
+static void
+_evas_outbuf_gbm_layout_symbols_resolve(void)
+{
+ static Eina_Bool resolved = EINA_FALSE;
+
+ if (resolved) return;
+ resolved = EINA_TRUE;
+
+ sym_gbm_bo_get_modifier = dlsym(RTLD_DEFAULT, "gbm_bo_get_modifier");
+ sym_gbm_bo_get_plane_count = dlsym(RTLD_DEFAULT, "gbm_bo_get_plane_count");
+}
+
+/* The buffers are made linear, XRGB8888, and so with one plane. gbm says
+ * so when it can, and an answer that differs is a layout this export would
+ * describe wrongly. */
+static Eina_Bool
+_evas_outbuf_frame_layout_check(struct gbm_bo *bo)
+{
+ _evas_outbuf_gbm_layout_symbols_resolve();
+
+ if (sym_gbm_bo_get_plane_count)
+ {
+ int planes = sym_gbm_bo_get_plane_count(bo);
+
+ if (planes != 1)
+ {
+ ERR("A frame has %d planes, one is expected", planes);
+ return EINA_FALSE;
+ }
+ }
+
+ if (sym_gbm_bo_get_modifier)
+ {
+ uint64_t modifier = sym_gbm_bo_get_modifier(bo);
+
+ /* gbm has no modifier to give for a surface made without any */
+ if ((modifier != DRM_FORMAT_MOD_INVALID) &&
+ (modifier != DRM_FORMAT_MOD_LINEAR))
+ {
+ ERR("A frame has the modifier %#llx, linear is expected",
+ (unsigned long long)modifier);
+ return EINA_FALSE;
+ }
+ }
+
+ return EINA_TRUE;
+}
+
+Eina_Bool
+evas_outbuf_frame_dmabuf_get(const Evas_Engine_GL_Drm_Frame *frame,
+ Evas_Engine_GL_Drm_Dmabuf *dmabuf)
+{
+ int fd, i;
+
+ EINA_SAFETY_ON_NULL_RETURN_VAL(frame, EINA_FALSE);
+ EINA_SAFETY_ON_NULL_RETURN_VAL(dmabuf, EINA_FALSE);
+
+ if (!frame->bo) return EINA_FALSE;
+
+ if (!_evas_outbuf_frame_layout_check(frame->bo)) return EINA_FALSE;
+
+ fd = gbm_bo_get_fd(frame->bo);
+ if (fd < 0)
+ {
+ ERR("Could not export the buffer of a frame as a dmabuf");
+ return EINA_FALSE;
+ }
+
+ /* One plane, starting at the beginning of the buffer, and the modifier
+ * the engine asked for, which is not what gbm answers for a surface
+ * made without any. */
+ memset(dmabuf, 0, sizeof(Evas_Engine_GL_Drm_Dmabuf));
+ for (i = 1; i < 4; i++)
+ {
+ dmabuf->fd[i] = -1;
+ }
+ dmabuf->modifier = DRM_FORMAT_MOD_LINEAR;
+ dmabuf->fd[0] = fd;
+ dmabuf->stride[0] = gbm_bo_get_stride(frame->bo);
+ dmabuf->format = gbm_bo_get_format(frame->bo);
+ dmabuf->w = frame->w;
+ dmabuf->h = frame->h;
+ dmabuf->plane_count = 1;
+
+ return EINA_TRUE;
+}
+
static void
_evas_outbuf_frame_deliver(Outbuf *ob, Tilebuf_Rect *surface_damage)
{
diff --git a/src/tests/evas/evas_test_gl_drm.c b/src/tests/evas/evas_test_gl_drm.c
index 8c3206a0ce..9122530011 100644
--- a/src/tests/evas/evas_test_gl_drm.c
+++ b/src/tests/evas/evas_test_gl_drm.c
@@ -18,6 +18,7 @@
#include <string.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
+#include <sys/stat.h>
#include <unistd.h>
#ifdef __linux__
@@ -36,6 +37,11 @@
#include "evas_suite.h"
+/* Not in every drm_fourcc.h */
+#ifndef DRM_FORMAT_MOD_LINEAR
+# define DRM_FORMAT_MOD_LINEAR 0ULL
+#endif
+
#define CANVAS_W 128
#define CANVAS_H 96
#define DAMAGE_MAX 64
@@ -542,6 +548,88 @@ EFL_START_TEST(evas_test_gl_drm_first_frame)
}
EFL_END_TEST
+/* Only the descriptors of dmabufs: the driver opens files of its own */
+static int
+_dmabuf_fd_count(void)
+{
+ return _fd_count_on("/dmabuf:") + _fd_count_on("anon_inode:dmabuf");
+}
+
+/* The layout of a frame as a dmabuf is what the engine asked for, and each
+ * export is made of new descriptors. */
+EFL_START_TEST(evas_test_gl_drm_dmabuf)
+{
+ Test_Canvas *c = _canvas_new();
+ Evas_Engine_GL_Drm_Dmabuf first, second;
+ struct stat first_stat, second_stat;
+ int fds;
+
+ if (!c) return;
+
+ c->hold = EINA_TRUE;
+ _render(c);
+ ck_assert_uint_eq(c->held_count, 1);
+ fds = _dmabuf_fd_count();
+
+ ck_assert(c->info->func.frame_dmabuf_get(c->held[0], &first));
+ ck_assert(c->info->func.frame_dmabuf_get(c->held[0], &second));
+ ck_assert_int_eq(_dmabuf_fd_count(), fds + 2);
+
+ ck_assert_uint_eq(first.plane_count, 1);
+ ck_assert_int_gt(first.fd[0], 2);
+ ck_assert_int_eq(first.fd[1], -1);
+ ck_assert_int_eq(first.fd[2], -1);
+ ck_assert_int_eq(first.fd[3], -1);
+ ck_assert_uint_eq(first.format, DRM_FORMAT_XRGB8888);
+ ck_assert(first.modifier == DRM_FORMAT_MOD_LINEAR);
+ ck_assert_int_eq(first.w, c->w);
+ ck_assert_int_eq(first.h, c->h);
+ ck_assert_uint_ge(first.stride[0], c->w * 4);
+ ck_assert_uint_eq(first.offset[0], 0);
+
+ /* Two descriptors of one buffer */
+ ck_assert_int_ne(first.fd[0], second.fd[0]);
+ ck_assert_int_eq(fstat(first.fd[0], &first_stat), 0);
+ ck_assert_int_eq(fstat(second.fd[0], &second_stat), 0);
+ ck_assert(first_stat.st_ino == second_stat.st_ino);
+ ck_assert_uint_eq(first.stride[0], second.stride[0]);
+
+ close(first.fd[0]);
+ close(second.fd[0]);
+ ck_assert_int_eq(_dmabuf_fd_count(), fds);
+
+ _canvas_free(c);
+}
+EFL_END_TEST
+
+/* The frame of a buffer that is gone has nothing to export. */
+EFL_START_TEST(evas_test_gl_drm_dmabuf_gone)
+{
+ Test_Canvas *c = _canvas_new();
+ Evas_Engine_GL_Drm_Dmabuf dmabuf;
+
+ if (!c) return;
+
+ c->hold = EINA_TRUE;
+ _render(c);
+ _canvas_resize(c, 160, 120);
+ _render(c);
+ ck_assert_uint_eq(c->held_count, 2);
+ ck_assert_ptr_null(c->held[0]->bo);
+
+ memset(&dmabuf, 0xa5, sizeof(dmabuf));
+ ck_assert(!c->info->func.frame_dmabuf_get(c->held[0], &dmabuf));
+ ck_assert_uint_eq(dmabuf.plane_count, 0xa5a5a5a5);
+
+ ck_assert(c->info->func.frame_dmabuf_get(c->held[1], &dmabuf));
+ ck_assert_int_eq(dmabuf.w, 160);
+ ck_assert_int_eq(dmabuf.h, 120);
+ close(dmabuf.fd[0]);
+
+ _canvas_free(c);
+}
+EFL_END_TEST
+
EFL_START_TEST(evas_test_gl_drm_orientation)
{
Test_Canvas *c;
@@ -1040,6 +1128,8 @@ void
evas_test_gl_drm(TCase *tc)
{
tcase_add_test(tc, evas_test_gl_drm_first_frame);
+ tcase_add_test(tc, evas_test_gl_drm_dmabuf);
+ tcase_add_test(tc, evas_test_gl_drm_dmabuf_gone);
tcase_add_test(tc, evas_test_gl_drm_orientation);
tcase_add_test(tc, evas_test_gl_drm_damage);
tcase_add_test(tc, evas_test_gl_drm_one_frame_per_render);
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.