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

git pushed a commit to branch gl-drm-offscreen
in repository efl.

View the commit online.

commit 47f2479bfce387c17d46c75fb5a57d88a9c944fb
Author: Cedric BAIL <[email protected]>
AuthorDate: Wed Dec 2 10:46:26 2026 -0600

    evas:gl_drm: render on a DRM node with no device, deliver the frames
    
    A compositor with no monitor, such as a remote desktop session, still
    wants to draw with the GPU. gl_drm could only start from an
    Ecore_Drm2_Device and an output: it took the gbm device from the device
    descriptor and handed every frame to KMS.
    
    When info.dev is NULL, the engine now takes info.fd, a DRM node the
    caller opened (a render node is enough, no card node is touched), and
    hands each finished frame to info.frame.func with the damage of that
    render. Nothing is queued for a page flip, no plane is assigned and no
    ecore_drm2 call is made. With a device the behaviour is the one it
    always had and the callback is never called: every new branch tests the
    device, not the output, because ecore_evas already passes a NULL output
    with a real device when it finds none.
    
    The damage is rects_prev[0] of the software generic engine, what was
    drawn since the last delivered frame whatever the buffer age, so a
    consumer does not need to know how many buffers the surface cycles
    through. The frame is the gbm_bo, locked until the consumer releases it.
    It is made with GBM_BO_USE_LINEAR so that it can be mapped, or exported
    to an encoder, without a modifier: gbm_bo_get_modifier() answers
    DRM_FORMAT_MOD_INVALID for a surface made without modifiers, linear or
    not. A canvas with no device is not rotated: the damage is in canvas
    coordinates and the buffer would not be, so it is refused.
    
    A gbm surface has a few buffers (four with Mesa). A consumer that keeps
    them all makes eglSwapBuffers() fail with EGL_BAD_ALLOC and leaves the
    surface with no front buffer. The engine checks for a free buffer
    before it starts a render and skips the render when there is none.
    Evas has already cleared the changed flags of the objects by then, so
    the consumer has to damage the canvas and render again once it released
    a frame; that frame is a whole one, since the age of the buffer it gets
    back says nothing about what was skipped. The same holds for frames
    nobody asked for: with no callback they are released at once, and the
    first frame given to a callback set later is a whole one.
    
    Mesa destroys the buffers with the EGL surface, locked or not, so a
    frame still held when the output is resized or freed has no buffer
    left. The frame is a small allocation tied to the buffer through its
    user data: it is freed when the buffer is gone and the consumer gave it
    back, in either order, and its bo reads NULL in between.
    
    Only one gbm device exists per process. A canvas asking for another node
    than the one it was created on, or mixing a device with a node, or
    giving no node at all, now fails with an error instead of silently
    using the first.
    
    The tests draw on a real render node and walk the whole life of a
    canvas: first frame, orientation (rows run top to bottom), damage, one
    callback per render, a consumer that holds every frame, a consumer that
    comes late, a rotated canvas, resizes, freeing with a frame held and the
    card node staying closed. The real DRM path cannot be run in a test.
    
    Co-Authored-By: Claude Fable 5.2 <[email protected]>
---
 .../evas/engines/gl_drm/Evas_Engine_GL_Drm.h       |  76 ++
 src/modules/evas/engines/gl_drm/evas_engine.c      |  43 +-
 src/modules/evas/engines/gl_drm/evas_engine.h      |   4 +
 src/modules/evas/engines/gl_drm/evas_outbuf.c      | 146 +++-
 src/tests/evas/evas_suite.c                        |   3 +
 src/tests/evas/evas_suite.h                        |   1 +
 src/tests/evas/evas_test_gl_drm.c                  | 949 +++++++++++++++++++++
 src/tests/evas/meson.build                         |   8 +
 8 files changed, 1221 insertions(+), 9 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 d7a14fdafb..474666e3e8 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
@@ -5,9 +5,34 @@
 
 # include <Ecore_Drm2.h>
 # include <gbm.h>
+# include <stdint.h>
 
 typedef struct _Evas_Engine_Info_GL_Drm Evas_Engine_Info_GL_Drm;
 
+/* A finished frame, handed to Evas_Engine_Info_GL_Drm.frame.func.
+ *
+ * Only these two fields may be read.  The frame belongs to the engine and
+ * is given back, exactly once, with
+ * Evas_Engine_Info_GL_Drm.func.frame_release(). */
+typedef struct _Evas_Engine_GL_Drm_Frame Evas_Engine_GL_Drm_Frame;
+
+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
+    * 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. */
+   struct gbm_bo *bo;
+   /* Names the buffer, not the frame: the engine cycles through a few
+    * buffers and the same buffer always comes back with the same id, so a
+    * consumer can cache what it derived from it.  Never reused. */
+   uint64_t id;
+};
+
 struct _Evas_Engine_Info_GL_Drm
 {
    /* PRIVATE - don't mess with this baby or evas will poke its tongue out */
@@ -25,6 +50,15 @@ struct _Evas_Engine_Info_GL_Drm
 
         Ecore_Drm2_Output *output;
 
+        /* DRM node to render on when dev is NULL, -1 otherwise.  Use a
+         * render node: nothing here needs, or opens, a card node.  The
+         * engine does not own the descriptor and does not close it, but
+         * it must stay open while any canvas uses it, and every canvas
+         * of the process must use the same one.  With dev NULL, also set
+         * format to DRM_FORMAT_XRGB8888, as for a device, and leave
+         * rotation at 0: a rotated canvas needs a device. */
+        int fd;
+
         Eina_Bool destination_alpha : 1;
         Eina_Bool vsync : 1;
         Eina_Bool indirect : 1;
@@ -40,6 +74,48 @@ struct _Evas_Engine_Info_GL_Drm
 
    /* non-blocking or blocking mode */
    Evas_Engine_Render_Mode render_mode;
+
+   /* Frame delivery, used only when dev is NULL.  With a device the
+    * frames go to the output and func is never called.
+    *
+    * func runs on the main loop, from inside the render, after the buffer
+    * was swapped.  It must not render, resize or free the canvas.  The
+    * frame is locked: the engine does not draw into its buffer until
+    * func.frame_release() is called on it, which may be done from func or
+    * later from the main loop, and must be done exactly once, before
+    * evas_shutdown().  A frame whose buffer is not valid any more because
+    * the output was resized or freed is still released the same way.
+    * Without a func the frames are released at once and the first frame
+    * given to a func set later is a whole one.
+    *
+    * damage is what changed since the frame given to func before, in
+    * canvas coordinates (origin at the top left), and does not depend on
+    * how many buffers the engine cycles through.  It covers the whole
+    * canvas for the first frame, after a resize and after a skipped
+    * render, and may cover more than what changed.  It is only valid
+    * during the call.
+    *
+    * The engine draws a frame only when it has a free buffer.  A consumer
+    * that holds frames back long enough to hold them all makes the engine
+    * skip renders, without blocking.  Evas counts a skipped render as
+    * drawn, so its changes are not drawn again by themselves: after
+    * releasing a frame that followed a skipped render, the consumer has to
+    * add damage (evas_damage_rectangle_add()) and render to get them.  The
+    * frame that comes then is a whole one.  Holding fewer frames than the
+    * engine has buffers is not noticed. */
+   struct
+     {
+        void (*func)(void *data, Evas_Engine_GL_Drm_Frame *frame,
+                     const Eina_Rectangle *damage, unsigned int damage_count);
+        void *data;
+     } frame;
+
+   /* Filled by the engine when the info is created.  The info goes with
+    * the canvas and the frames may outlive it: keep the pointer. */
+   struct
+     {
+        void (*frame_release)(Evas_Engine_GL_Drm_Frame *frame);
+     } func;
 };
 
 #endif
diff --git a/src/modules/evas/engines/gl_drm/evas_engine.c b/src/modules/evas/engines/gl_drm/evas_engine.c
index f1629d8e7f..c57f63bb25 100644
--- a/src/modules/evas/engines/gl_drm/evas_engine.c
+++ b/src/modules/evas/engines/gl_drm/evas_engine.c
@@ -30,6 +30,9 @@ static Eina_Bool initted = EINA_FALSE;
 static int gl_wins = 0;
 static struct gbm_device *gbm_dev = NULL;
 static int gbm_dev_refs = 0;
+/* The node gbm_dev was created from when there was no device, -1 if it
+ * came from a device */
+static int gbm_dev_fd = -1;
 
 /* local function prototype types */
 typedef void *(*glsym_func_void_ptr)(void);
@@ -118,17 +121,32 @@ static const EVGL_Interface evgl_funcs =
 Eina_Bool
 eng_gbm_init(Evas_Engine_Info_GL_Drm *info)
 {
-   int fd;
+   int fd, node_fd;
    if (!info) return EINA_FALSE;
 
+   node_fd = info->info.dev ? -1 : info->info.fd;
+
+   if ((!info->info.dev) && (node_fd < 0))
+     {
+        ERR("Neither a DRM device nor a node to render on");
+        return EINA_FALSE;
+     }
+
    if (gbm_dev)
      {
+        if (gbm_dev_fd != node_fd)
+          {
+             ERR("The gbm device is already open on another node");
+             return EINA_FALSE;
+          }
         info->info.gbm = gbm_dev;
         gbm_dev_refs++;
         return EINA_TRUE;
      }
 
-   fd = ecore_drm2_device_fd_get(info->info.dev);
+   if (info->info.dev) fd = ecore_drm2_device_fd_get(info->info.dev);
+   else fd = info->info.fd;
+
    if (!(info->info.gbm = gbm_create_device(fd)))
      {
         ERR("Coult not create gbm device");
@@ -136,6 +154,7 @@ eng_gbm_init(Evas_Engine_Info_GL_Drm *info)
      }
 
    gbm_dev = info->info.gbm;
+   gbm_dev_fd = node_fd;
    gbm_dev_refs = 1;
    return EINA_TRUE;
 }
@@ -366,7 +385,7 @@ evgl_eng_native_window_create(void *data)
    struct gbm_surface *surface;
    Evas_Engine_Info_GL_Drm *info;
    unsigned int format = GBM_FORMAT_XRGB8888;
-   unsigned int flags = GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING;
+   unsigned int flags = GBM_BO_USE_RENDERING;
 
    re = (Render_Engine *)data;
    if (!re)
@@ -382,6 +401,8 @@ evgl_eng_native_window_create(void *data)
         return NULL;
      }
 
+   if (eng_get_ob(re)->dev) flags |= GBM_BO_USE_SCANOUT;
+
    surface =
      gbm_surface_create(info->info.gbm,
                         eng_get_ob(re)->w, eng_get_ob(re)->h, format, flags);
@@ -731,6 +752,8 @@ eng_image_plane_assign(void *data, void *image, int x, int y)
    ob = eng_get_ob(re);
    EINA_SAFETY_ON_NULL_RETURN_VAL(ob, NULL);
 
+   if (!re->dev) return NULL;
+
    img = image;
    n = img->native.data;
 
@@ -815,6 +838,8 @@ eng_output_info_setup(void *info)
    Evas_Engine_Info_GL_Drm *einfo = info;
 
    einfo->render_mode = EVAS_RENDER_MODE_BLOCKING;
+   einfo->info.fd = -1;
+   einfo->func.frame_release = evas_outbuf_frame_release;
 }
 
 static void *
@@ -825,6 +850,12 @@ eng_output_setup(void *engine, void *in, unsigned int w, unsigned int h)
    Outbuf *ob;
    Render_Output_Swap_Mode swap_mode;
 
+   if ((!info->info.dev) && (info->info.rotation))
+     {
+        ERR("A canvas with no DRM device cannot be rotated");
+        return NULL;
+     }
+
    swap_mode = evas_render_engine_gl_swap_mode_get(info->info.swap_mode);
 
    if (!initted)
@@ -899,6 +930,12 @@ eng_output_update(void *engine EINA_UNUSED, void *data, void *in, unsigned int w
    Evas_Engine_Info_GL_Drm *info = (Evas_Engine_Info_GL_Drm *)in;
    Render_Engine *re = data;
 
+   if ((!info->info.dev) && (info->info.rotation))
+     {
+        ERR("A canvas with no DRM device cannot be rotated");
+        return 0;
+     }
+
    if (eng_get_ob(re) && _re_wincheck(eng_get_ob(re)))
      {
         if ((info->info.depth != eng_get_ob(re)->depth) ||
diff --git a/src/modules/evas/engines/gl_drm/evas_engine.h b/src/modules/evas/engines/gl_drm/evas_engine.h
index d21bd5e67d..05d8805280 100644
--- a/src/modules/evas/engines/gl_drm/evas_engine.h
+++ b/src/modules/evas/engines/gl_drm/evas_engine.h
@@ -117,6 +117,9 @@ struct _Outbuf
    Eina_Bool lost_back : 1;
    Eina_Bool surf : 1;
    Eina_Bool drew : 1;
+   /* The render under way, or the last one, produced no frame for the
+    * consumer: the next one has to redraw everything */
+   Eina_Bool frame_lost : 1;
 };
 
 Eina_Bool eng_gbm_init(Evas_Engine_Info_GL_Drm *info);
@@ -135,6 +138,7 @@ void *evas_outbuf_update_region_new(Outbuf *ob, int x, int y, int w, int h, int
 void evas_outbuf_update_region_push(Outbuf *ob, RGBA_Image *update, int x, int y, int w, int h);
 void evas_outbuf_flush(Outbuf *ob, Tilebuf_Rect *surface_damage, Tilebuf_Rect *buffer_damage, Evas_Render_Mode render_mode);
 void evas_outbuf_release_fb(void *, void *);
+void evas_outbuf_frame_release(Evas_Engine_GL_Drm_Frame *frame);
 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 0f825ca48c..614115d0ea 100644
--- a/src/modules/evas/engines/gl_drm/evas_outbuf.c
+++ b/src/modules/evas/engines/gl_drm/evas_outbuf.c
@@ -10,6 +10,18 @@ static PFNEGLGETPLATFORMDISPLAYEXTPROC dlsym_eglGetPlatformDisplayEXT = NULL;
 static PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC dlsym_eglCreatePlatformWindowSurfaceEXT = NULL;
 #endif
 
+typedef struct _Outbuf_Frame Outbuf_Frame;
+
+/* 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. */
+struct _Outbuf_Frame
+{
+   Evas_Engine_GL_Drm_Frame frame;
+   struct gbm_surface *surface;
+   Eina_Bool held : 1;
+};
+
 static void
 _evas_outbuf_gbm_surface_destroy(Outbuf *ob)
 {
@@ -25,10 +37,13 @@ static void
 _evas_outbuf_gbm_surface_create(Outbuf *ob, int w, int h)
 {
    unsigned int format = GBM_FORMAT_XRGB8888;
-   unsigned int flags = GBM_BO_USE_SCANOUT | GBM_BO_USE_RENDERING;
+   unsigned int flags = GBM_BO_USE_RENDERING;
 
    if (!ob) return;
 
+   if (ob->dev) flags |= GBM_BO_USE_SCANOUT;
+   else flags |= GBM_BO_USE_LINEAR;
+
    ob->surface =
      gbm_surface_create(ob->info->info.gbm, w, h, format, flags);
 
@@ -92,11 +107,106 @@ _evas_outbuf_fb_get(Outbuf *ob, struct gbm_bo *bo)
 }
 
 static void
-_evas_outbuf_buffer_swap(Outbuf *ob)
+_evas_outbuf_frame_bo_destroy(struct gbm_bo *bo EINA_UNUSED, void *data)
+{
+   Outbuf_Frame *frame = data;
+
+   frame->frame.bo = NULL;
+   if (!frame->held) free(frame);
+}
+
+static Outbuf_Frame *
+_evas_outbuf_frame_get(Outbuf *ob, struct gbm_bo *bo)
+{
+   static uint64_t frame_count = 0;
+   Outbuf_Frame *frame;
+
+   frame = gbm_bo_get_user_data(bo);
+   if (frame) return frame;
+
+   frame = calloc(1, sizeof(Outbuf_Frame));
+   if (!frame) return NULL;
+
+   frame->frame.bo = bo;
+   frame->frame.id = ++frame_count;
+   frame->surface = ob->surface;
+   gbm_bo_set_user_data(bo, frame, _evas_outbuf_frame_bo_destroy);
+
+   return frame;
+}
+
+void
+evas_outbuf_frame_release(Evas_Engine_GL_Drm_Frame *released)
+{
+   Outbuf_Frame *frame = (Outbuf_Frame *)released;
+
+   EINA_SAFETY_ON_NULL_RETURN(released);
+
+   frame->held = EINA_FALSE;
+   if (!frame->frame.bo)
+     {
+        free(frame);
+        return;
+     }
+   gbm_surface_release_buffer(frame->surface, frame->frame.bo);
+}
+
+static void
+_evas_outbuf_frame_deliver(Outbuf *ob, Tilebuf_Rect *surface_damage)
+{
+   struct gbm_bo *bo;
+   Outbuf_Frame *frame;
+   Eina_Rectangle *damage;
+   Tilebuf_Rect *r;
+   unsigned int count, i = 0;
+
+   bo = gbm_surface_lock_front_buffer(ob->surface);
+   if (!bo)
+     {
+        WRN("Could not lock the front buffer");
+        ob->frame_lost = EINA_TRUE;
+        return;
+     }
+
+   frame = _evas_outbuf_frame_get(ob, bo);
+   if (!frame)
+     {
+        gbm_surface_release_buffer(ob->surface, bo);
+        ob->frame_lost = EINA_TRUE;
+        return;
+     }
+
+   frame->held = EINA_TRUE;
+   if (!ob->info->frame.func)
+     {
+        evas_outbuf_frame_release(&frame->frame);
+        ob->frame_lost = EINA_TRUE;
+        return;
+     }
+
+   count = eina_inlist_count(EINA_INLIST_GET(surface_damage));
+   damage = alloca(sizeof(Eina_Rectangle) * count);
+   EINA_INLIST_FOREACH(EINA_INLIST_GET(surface_damage), r)
+     {
+        EINA_RECTANGLE_SET(&damage[i], r->x, r->y, r->w, r->h);
+        i++;
+     }
+
+   ob->info->frame.func(ob->info->frame.data, &frame->frame, damage, count);
+}
+
+static void
+_evas_outbuf_buffer_swap(Outbuf *ob, Tilebuf_Rect *surface_damage)
 {
    struct gbm_bo *bo;
    Ecore_Drm2_Fb *fb = NULL;
 
+   if (!ob->dev)
+     {
+        _evas_outbuf_frame_deliver(ob, surface_damage);
+        return;
+     }
+
    bo = gbm_surface_lock_front_buffer(ob->surface);
    if (!bo)
      {
@@ -564,7 +674,8 @@ evas_outbuf_reconfigure(Outbuf *ob, int w, int h, int rot, Outbuf_Depth depth)
 {
    if (depth == OUTBUF_DEPTH_INHERIT) depth = ob->depth;
 
-   while (ecore_drm2_fb_release(ob->priv.output, EINA_TRUE));
+   if (ob->dev)
+     while (ecore_drm2_fb_release(ob->priv.output, EINA_TRUE));
 
    ob->w = w;
    ob->h = h;
@@ -586,7 +697,11 @@ evas_outbuf_buffer_state_get(Outbuf *ob)
    /* check for valid output buffer */
    if (!ob) return MODE_FULL;
 
-   ecore_drm2_fb_release(ob->priv.output, EINA_FALSE);
+   if (ob->dev) ecore_drm2_fb_release(ob->priv.output, EINA_FALSE);
+   else if (ob->frame_lost)
+     /* This render is skipped: no buffer to query the age of, and a failed
+      * query would reset prev_age for nothing. */
+     return MODE_FULL;
 
    if (ob->swap_mode == MODE_AUTO && _extn_have_buffer_age)
      {
@@ -634,6 +749,8 @@ evas_outbuf_rot_get(Outbuf *ob)
 Eina_Bool
 evas_outbuf_update_region_first_rect(Outbuf *ob)
 {
+   Eina_Bool was_lost = EINA_FALSE;
+
    /* ob->gl_context->preserve_bit = GL_COLOR_BUFFER_BIT0_QCOM; */
 
    glsym_evas_gl_preload_render_lock(_evas_outbuf_make_current, ob);
@@ -641,11 +758,22 @@ evas_outbuf_update_region_first_rect(Outbuf *ob)
 
    if (!_re_wincheck(ob)) return EINA_TRUE;
 
+   if (!ob->dev)
+     {
+        was_lost = ob->frame_lost;
+        ob->frame_lost = !gbm_surface_has_free_buffers(ob->surface);
+        if (ob->frame_lost)
+          {
+             glsym_evas_gl_preload_render_unlock(_evas_outbuf_make_current, ob);
+             return EINA_TRUE;
+          }
+     }
+
    glsym_evas_gl_common_context_resize(ob->gl_context, ob->w, ob->h, ob->rotation);
    glsym_evas_gl_common_context_flush(ob->gl_context);
    glsym_evas_gl_common_context_newframe(ob->gl_context);
 
-   return EINA_FALSE;
+   return was_lost;
 }
 
 static void
@@ -689,6 +817,10 @@ _glcoords_convert(int *result, Outbuf *ob, int x, int y, int w, int h)
 void
 evas_outbuf_damage_region_set(Outbuf *ob, Tilebuf_Rect *damage)
 {
+   /* No swap follows a skipped render, and a second damage region set
+    * before a swap can fail (EGL_KHR_partial_update). */
+   if (ob->frame_lost) return;
+
    if (glsym_eglSetDamageRegionKHR)
      {
         Tilebuf_Rect *tr;
@@ -709,6 +841,8 @@ evas_outbuf_damage_region_set(Outbuf *ob, Tilebuf_Rect *damage)
 void *
 evas_outbuf_update_region_new(Outbuf *ob, int x, int y, int w, int h, int *cx EINA_UNUSED, int *cy EINA_UNUSED, int *cw EINA_UNUSED, int *ch EINA_UNUSED)
 {
+   if (ob->frame_lost) return NULL;
+
    if ((w == ob->w) && (h == ob->h))
      ob->gl_context->master_clip.enabled = EINA_FALSE;
    else
@@ -781,7 +915,7 @@ evas_outbuf_flush(Outbuf *ob, Tilebuf_Rect *surface_damage, Tilebuf_Rect *buffer
    /* if (ob->info->callback.post_swap) */
    /*   ob->info->callback.post_swap(ob->info->callback.data, ob->evas); */
 
-   _evas_outbuf_buffer_swap(ob);
+   _evas_outbuf_buffer_swap(ob, surface_damage);
 
 end:
    //TODO: Need render unlock after drm page flip?
diff --git a/src/tests/evas/evas_suite.c b/src/tests/evas/evas_suite.c
index 035842a8ca..3d228ed7f3 100644
--- a/src/tests/evas/evas_suite.c
+++ b/src/tests/evas/evas_suite.c
@@ -35,6 +35,9 @@ static const Efl_Test_Case etc[] = {
 #endif
 #ifdef HAVE_DRM_TEST
   { "DRM", evas_test_drm },
+#endif
+#ifdef HAVE_GL_DRM_TEST
+  { "GL DRM", evas_test_gl_drm },
 #endif
   { NULL, NULL }
 };
diff --git a/src/tests/evas/evas_suite.h b/src/tests/evas/evas_suite.h
index 4ade80da1b..325ad86f20 100644
--- a/src/tests/evas/evas_suite.h
+++ b/src/tests/evas/evas_suite.h
@@ -29,5 +29,6 @@ void evas_test_native_orient(TCase *tc);
 #endif
 
 void evas_test_drm(TCase *tc);
+void evas_test_gl_drm(TCase *tc);
 
 #endif /* _EVAS_SUITE_H */
diff --git a/src/tests/evas/evas_test_gl_drm.c b/src/tests/evas/evas_test_gl_drm.c
new file mode 100644
index 0000000000..0ef569d036
--- /dev/null
+++ b/src/tests/evas/evas_test_gl_drm.c
@@ -0,0 +1,949 @@
+/* The gl_drm engine rendering on a render node, with no DRM device and no
+ * output: every finished frame goes to a callback.
+ *
+ * These tests need a render node the GPU driver can draw on and return
+ * quietly, saying why, when there is none, when it cannot be opened or when
+ * the engine refuses it (software GL is refused on purpose).
+ */
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <dirent.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <limits.h>
+#include <stdio.h>
+#include <string.h>
+#include <sys/ioctl.h>
+#include <sys/mman.h>
+#include <unistd.h>
+
+#ifdef __linux__
+# include <linux/dma-buf.h>
+# define HAVE_DMABUF_SYNC 1
+#endif
+
+#include <xf86drm.h>
+#include <drm_fourcc.h>
+#include <EGL/egl.h>
+#include <EGL/eglext.h>
+
+#include <Evas.h>
+
+#include "../../modules/evas/engines/gl_drm/Evas_Engine_GL_Drm.h"
+
+#include "evas_suite.h"
+
+#define CANVAS_W 128
+#define CANVAS_H 96
+#define DAMAGE_MAX 64
+#define HELD_MAX 32
+
+#define RED 0x00ff0000u
+#define GREEN 0x0000ff00u
+#define BLUE 0x000000ffu
+#define YELLOW 0x00ffff00u
+
+/* Frames are read back through their dmabuf, bracketed by
+ * DMA_BUF_IOCTL_SYNC. */
+#ifdef HAVE_DMABUF_SYNC
+# define READBACK_OR_RETURN() do { } while (0)
+#else
+# define READBACK_OR_RETURN() \
+   do { \
+      fprintf(stderr, "gl_drm: skipped, no DMA_BUF_IOCTL_SYNC here\n"); \
+      return; \
+   } while (0)
+#endif
+
+typedef struct _Test_Canvas Test_Canvas;
+
+struct _Test_Canvas
+{
+   Evas *evas;
+   Evas_Engine_Info_GL_Drm *info;
+   /* Kept apart because frames outlive the info, which goes with the canvas */
+   void (*release)(Evas_Engine_GL_Drm_Frame *frame);
+   Evas_Object *background;
+   Evas_Object *top_left;
+   Evas_Object *bottom_right;
+   Evas_Object *mover;
+   Evas_Engine_GL_Drm_Frame *held[HELD_MAX];
+
+   uint64_t ids[HELD_MAX];
+
+   Eina_Rectangle damage[DAMAGE_MAX];
+   Eina_Rectangle mover_rect;
+
+   unsigned int held_count;
+   unsigned int warnings;
+   unsigned int damage_count;
+   unsigned int id_count;
+   unsigned int frame_count;
+   unsigned int rotation;
+   int fd;
+   int w, h;
+
+   Eina_Bool hold : 1;
+   Eina_Bool owns_fd : 1;
+   Eina_Bool damage_overflow : 1;
+};
+
+static int
+_fd_count_on(const char *prefix)
+{
+   char link[PATH_MAX], path[320];
+   struct dirent *entry;
+   DIR *dir;
+   int count = 0;
+
+   dir = opendir("/proc/self/fd");
+   if (!dir) return -1;
+   while ((entry = readdir(dir)))
+     {
+        ssize_t len;
+
+        snprintf(path, sizeof(path), "/proc/self/fd/%s", entry->d_name);
+        len = readlink(path, link, sizeof(link) - 1);
+        if (len < 0) continue;
+        link[len] = '\0';
+        if (!strncmp(link, prefix, strlen(prefix))) count++;
+     }
+   closedir(dir);
+
+   return count;
+}
+
+/* The engine reports what went wrong in a frame it could not deliver, so
+ * a test that expects no trouble counts what the engine logs. */
+static void
+_log_count_cb(const Eina_Log_Domain *domain, Eina_Log_Level level,
+              const char *file, const char *fnc, int line, const char *fmt,
+              void *data, va_list args)
+{
+   Test_Canvas *c = data;
+
+   if ((level <= EINA_LOG_LEVEL_WARN) && (domain) && (domain->name) &&
+       (!strcmp(domain->name, "evas-gl-drm")))
+     c->warnings++;
+   eina_log_print_cb_stderr(domain, level, file, fnc, line, fmt, NULL, args);
+}
+
+static void
+_frame_cb(void *data, Evas_Engine_GL_Drm_Frame *frame,
+          const Eina_Rectangle *damage, unsigned int damage_count)
+{
+   Test_Canvas *c = data;
+   unsigned int i;
+
+   for (i = 0; i < c->id_count; i++)
+     if (c->ids[i] == frame->id) break;
+   if ((i == c->id_count) && (i < HELD_MAX)) c->ids[c->id_count++] = frame->id;
+
+   c->frame_count++;
+   if (damage_count > DAMAGE_MAX)
+     {
+        c->damage_overflow = EINA_TRUE;
+        damage_count = DAMAGE_MAX;
+     }
+   c->damage_count = damage_count;
+   memcpy(c->damage, damage, sizeof(Eina_Rectangle) * damage_count);
+
+   if (c->hold)
+     {
+        ck_assert_uint_lt(c->held_count, HELD_MAX);
+        c->held[c->held_count++] = frame;
+     }
+   else
+     c->release(frame);
+}
+
+static void
+_held_release_all(Test_Canvas *c)
+{
+   while (c->held_count)
+     c->release(c->held[--c->held_count]);
+}
+
+static Evas_Object *
+_rect_add(Test_Canvas *c, unsigned int rgb, int x, int y, int w, int h)
+{
+   Evas_Object *rect = evas_object_rectangle_add(c->evas);
+
+   evas_object_color_set(rect, (rgb >> 16) & 0xff, (rgb >> 8) & 0xff,
+                         rgb & 0xff, 255);
+   evas_object_move(rect, x, y);
+   evas_object_resize(rect, w, h);
+   evas_object_show(rect);
+   return rect;
+}
+
+static void
+_scene_build(Test_Canvas *c)
+{
+   c->background = "" BLUE, 0, 0, c->w, c->h);
+   c->top_left = _rect_add(c, RED, 8, 8, 32, 16);
+   c->bottom_right = _rect_add(c, GREEN, c->w - 40, c->h - 24, 32, 16);
+   EINA_RECTANGLE_SET(&c->mover_rect, 56, 40, 16, 16);
+   c->mover = _rect_add(c, YELLOW, c->mover_rect.x, c->mover_rect.y,
+                        c->mover_rect.w, c->mover_rect.h);
+}
+
+static void
+_mover_move(Test_Canvas *c, int x, int y)
+{
+   c->mover_rect.x = x;
+   c->mover_rect.y = y;
+   evas_object_move(c->mover, x, y);
+}
+
+static void
+_canvas_size_set(Test_Canvas *c, int w, int h)
+{
+   c->w = w;
+   c->h = h;
+   evas_output_size_set(c->evas, w, h);
+   evas_output_viewport_set(c->evas, 0, 0, w, h);
+}
+
+static void
+_canvas_resize(Test_Canvas *c, int w, int h)
+{
+   _canvas_size_set(c, w, h);
+   evas_object_resize(c->background, w, h);
+   evas_object_move(c->bottom_right, w - 40, h - 24);
+}
+
+static void
+_info_fill(Test_Canvas *c)
+{
+   c->info->info.fd = c->fd;
+   c->info->info.format = DRM_FORMAT_XRGB8888;
+   c->info->info.rotation = c->rotation;
+   c->info->frame.func = _frame_cb;
+   c->info->frame.data = ""
+}
+
+static Eina_Bool
+_canvas_open_on(Test_Canvas *c, int fd)
+{
+   int method;
+
+   method = evas_render_method_lookup("gl_drm");
+   if (!method)
+     {
+        fprintf(stderr, "gl_drm: skipped, the engine is not available\n");
+        return EINA_FALSE;
+     }
+
+   c->fd = fd;
+   c->evas = evas_new();
+   _canvas_size_set(c, CANVAS_W, CANVAS_H);
+   evas_output_method_set(c->evas, method);
+   c->info = (Evas_Engine_Info_GL_Drm *)evas_engine_info_get(c->evas);
+   if (!c->info)
+     {
+        evas_free(c->evas);
+        c->evas = NULL;
+        return EINA_FALSE;
+     }
+
+   _info_fill(c);
+   c->release = c->info->func.frame_release;
+   if (!evas_engine_info_set(c->evas, (Evas_Engine_Info *)c->info))
+     {
+        evas_free(c->evas);
+        c->evas = NULL;
+        return EINA_FALSE;
+     }
+
+   _scene_build(c);
+   return EINA_TRUE;
+}
+
+/* Walks the render nodes until the engine accepts one. */
+static Test_Canvas *
+_canvas_new(void)
+{
+   Test_Canvas *c;
+   drmDevicePtr devices[16];
+   int count, i;
+
+   c = calloc(1, sizeof(Test_Canvas));
+   ck_assert_ptr_nonnull(c);
+   /* The tests expect the partial updates the driver offers */
+   unsetenv("EVAS_GL_PARTIAL_DISABLE");
+   unsetenv("EVAS_GL_SWAP_MODE");
+   eina_log_domain_level_set("evas-gl-drm", EINA_LOG_LEVEL_WARN);
+   eina_log_print_cb_set(_log_count_cb, c);
+
+   count = drmGetDevices2(0, devices, 16);
+   if (count <= 0)
+     {
+        fprintf(stderr, "gl_drm: skipped, no DRM device\n");
+        goto skip;
+     }
+
+   for (i = 0; i < count; i++)
+     {
+        int fd;
+
+        if (!(devices[i]->available_nodes & (1 << DRM_NODE_RENDER))) continue;
+
+        fd = open(devices[i]->nodes[DRM_NODE_RENDER], O_RDWR | O_CLOEXEC);
+        if (fd < 0)
+          {
+             fprintf(stderr, "gl_drm: %s: %s\n",
+                     devices[i]->nodes[DRM_NODE_RENDER], strerror(errno));
+             continue;
+          }
+
+        if (_canvas_open_on(c, fd))
+          {
+             c->owns_fd = EINA_TRUE;
+             c->warnings = 0;
+             drmFreeDevices(devices, count);
+             return c;
+          }
+        fprintf(stderr, "gl_drm: %s: the engine refuses it\n",
+                devices[i]->nodes[DRM_NODE_RENDER]);
+        close(fd);
+     }
+   drmFreeDevices(devices, count);
+   fprintf(stderr, "gl_drm: skipped, no render node to draw on\n");
+
+skip:
+   eina_log_print_cb_set(NULL, NULL);
+   free(c);
+   return NULL;
+}
+
+static void
+_canvas_free(Test_Canvas *c)
+{
+   if (c->evas) evas_free(c->evas);
+   _held_release_all(c);
+   eina_log_print_cb_set(NULL, NULL);
+   ck_assert_uint_eq(c->warnings, 0);
+   if (c->owns_fd) close(c->fd);
+   free(c);
+}
+
+static void
+_render(Test_Canvas *c)
+{
+   evas_render(c->evas);
+}
+
+/* A change that is certain to be drawn. */
+static void
+_change_and_render(Test_Canvas *c)
+{
+   _mover_move(c, (c->mover_rect.x == 56) ? 60 : 56, 40);
+   _render(c);
+}
+
+#ifdef HAVE_DMABUF_SYNC
+static uint32_t
+_pixel_get(Evas_Engine_GL_Drm_Frame *frame, int x, int y)
+{
+   struct dma_buf_sync sync = { 0 };
+   uint32_t stride, pixel;
+   uint32_t *map;
+   size_t size;
+   int fd;
+
+   ck_assert_ptr_nonnull(frame->bo);
+   stride = gbm_bo_get_stride(frame->bo);
+   size = (size_t)stride * gbm_bo_get_height(frame->bo);
+   fd = gbm_bo_get_fd(frame->bo);
+   ck_assert_int_ge(fd, 0);
+   map = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 0);
+   ck_assert_ptr_ne(map, MAP_FAILED);
+
+   /* Waits for the GPU to be done with the buffer */
+   sync.flags = DMA_BUF_SYNC_START | DMA_BUF_SYNC_READ;
+   ck_assert_int_eq(ioctl(fd, DMA_BUF_IOCTL_SYNC, &sync), 0);
+   pixel = map[(y * (stride / 4)) + x] & 0x00ffffff;
+   sync.flags = DMA_BUF_SYNC_END | DMA_BUF_SYNC_READ;
+   ck_assert_int_eq(ioctl(fd, DMA_BUF_IOCTL_SYNC, &sync), 0);
+
+   munmap(map, size);
+   close(fd);
+   return pixel;
+}
+
+static Eina_Bool
+_pixel_is(Evas_Engine_GL_Drm_Frame *frame, int x, int y, uint32_t rgb)
+{
+   uint32_t got = _pixel_get(frame, x, y);
+
+   if (got != rgb)
+     fprintf(stderr, "pixel %d,%d is %06x, expected %06x\n", x, y, got, rgb);
+   return got == rgb;
+}
+#else
+static Eina_Bool
+_pixel_is(Evas_Engine_GL_Drm_Frame *frame EINA_UNUSED, int x EINA_UNUSED,
+          int y EINA_UNUSED, uint32_t rgb EINA_UNUSED)
+{
+   return EINA_FALSE;
+}
+#endif
+
+/* Unions the damage of the last frame into a mask of the canvas and counts
+ * how many of the pixels of rect it covers. */
+static int
+_damage_covered(Test_Canvas *c, const Eina_Rectangle *rect)
+{
+   unsigned char *mask;
+   int x, y, covered = 0;
+   unsigned int i;
+
+   ck_assert(!c->damage_overflow);
+   mask = calloc(c->w * c->h, 1);
+   ck_assert_ptr_nonnull(mask);
+   for (i = 0; i < c->damage_count; i++)
+     {
+        const Eina_Rectangle *d = &c->damage[i];
+
+        ck_assert_int_ge(d->x, 0);
+        ck_assert_int_ge(d->y, 0);
+        ck_assert_int_le(d->x + d->w, c->w);
+        ck_assert_int_le(d->y + d->h, c->h);
+        for (y = d->y; y < d->y + d->h; y++)
+          memset(mask + (y * c->w) + d->x, 1, d->w);
+     }
+
+   for (y = rect->y; y < rect->y + rect->h; y++)
+     for (x = rect->x; x < rect->x + rect->w; x++)
+       covered += mask[(y * c->w) + x];
+   free(mask);
+
+   return covered;
+}
+
+static Eina_Bool
+_damage_is_all(Test_Canvas *c)
+{
+   Eina_Rectangle all;
+
+   EINA_RECTANGLE_SET(&all, 0, 0, c->w, c->h);
+   return _damage_covered(c, &all) == (c->w * c->h);
+}
+
+static Eina_Bool
+_damage_covers(Test_Canvas *c, const Eina_Rectangle *rect)
+{
+   return _damage_covered(c, rect) == (rect->w * rect->h);
+}
+
+/* The canvas the engine draws on has partial damage to offer only where the
+ * driver tells the age of its buffers. */
+static Eina_Bool
+_driver_has_buffer_age(int fd)
+{
+   struct gbm_device *gbm;
+   EGLDisplay disp;
+   const char *exts;
+   Eina_Bool has = EINA_FALSE;
+   EGLint major, minor;
+   PFNEGLGETPLATFORMDISPLAYEXTPROC get_display;
+
+   gbm = gbm_create_device(fd);
+   ck_assert_ptr_nonnull(gbm);
+   get_display = (PFNEGLGETPLATFORMDISPLAYEXTPROC)
+     eglGetProcAddress("eglGetPlatformDisplayEXT");
+   if (get_display)
+     {
+        disp = get_display(EGL_PLATFORM_GBM_MESA, gbm, NULL);
+        if ((disp != EGL_NO_DISPLAY) && (eglInitialize(disp, &major, &minor)))
+          {
+             exts = eglQueryString(disp, EGL_EXTENSIONS);
+             has = (exts) && (strstr(exts, "EGL_EXT_buffer_age"));
+             eglTerminate(disp);
+          }
+     }
+   gbm_device_destroy(gbm);
+
+   return has;
+}
+
+/* Fills every buffer and renders on until the engine has none left to draw
+ * in. Returns the number of frames the consumer holds by then. */
+static unsigned int
+_buffers_use_up(Test_Canvas *c)
+{
+   c->hold = EINA_TRUE;
+   if (!c->frame_count) _render(c);
+   while (c->held_count < HELD_MAX)
+     {
+        unsigned int before = c->frame_count;
+
+        _change_and_render(c);
+        if (c->frame_count == before) break;
+     }
+   ck_assert_uint_lt(c->held_count, HELD_MAX);
+   ck_assert_uint_ge(c->held_count, 2);
+
+   return c->held_count;
+}
+
+static void
+_frame_release_one(Test_Canvas *c)
+{
+   c->release(c->held[--c->held_count]);
+}
+
+static void
+_frame_release_oldest(Test_Canvas *c)
+{
+   c->release(c->held[0]);
+   c->held_count--;
+   memmove(c->held, c->held + 1, sizeof(c->held[0]) * c->held_count);
+}
+
+EFL_START_TEST(evas_test_gl_drm_first_frame)
+{
+   Test_Canvas *c = _canvas_new();
+   Evas_Engine_GL_Drm_Frame *frame;
+
+   if (!c) return;
+
+   c->hold = EINA_TRUE;
+   _render(c);
+
+   ck_assert_uint_eq(c->frame_count, 1);
+   frame = c->held[0];
+   ck_assert_ptr_nonnull(frame->bo);
+   ck_assert_uint_ne(frame->id, 0);
+   ck_assert_uint_eq(gbm_bo_get_width(frame->bo), c->w);
+   ck_assert_uint_eq(gbm_bo_get_height(frame->bo), c->h);
+   ck_assert_uint_eq(gbm_bo_get_format(frame->bo), GBM_FORMAT_XRGB8888);
+   ck_assert(_damage_is_all(c));
+
+   _canvas_free(c);
+}
+EFL_END_TEST
+
+EFL_START_TEST(evas_test_gl_drm_orientation)
+{
+   Test_Canvas *c;
+   Evas_Engine_GL_Drm_Frame *frame;
+
+   READBACK_OR_RETURN();
+   c = _canvas_new();
+
+   if (!c) return;
+
+   c->hold = EINA_TRUE;
+   _render(c);
+   ck_assert_uint_eq(c->held_count, 1);
+   frame = c->held[0];
+
+   /* Rows run top to bottom: what is at the top of the canvas is in the
+    * first rows of the buffer. */
+   ck_assert(_pixel_is(frame, 24, 16, RED));
+   ck_assert(_pixel_is(frame, c->w - 24, c->h - 16, GREEN));
+   ck_assert(_pixel_is(frame, c->w - 24, 16, BLUE));
+   ck_assert(_pixel_is(frame, 24, c->h - 16, BLUE));
+   ck_assert(_pixel_is(frame, 64, 48, YELLOW));
+
+   _canvas_free(c);
+}
+EFL_END_TEST
+
+EFL_START_TEST(evas_test_gl_drm_damage)
+{
+   Test_Canvas *c = _canvas_new();
+   Eina_Bool partial = EINA_FALSE;
+   int i;
+
+   if (!c) return;
+
+   _render(c);
+   for (i = 0; i < 12; i++)
+     {
+        Eina_Rectangle old = c->mover_rect;
+
+        _mover_move(c, 20 + ((i % 2) * 40), 30 + (i * 3));
+        c->frame_count = 0;
+        _render(c);
+        ck_assert_uint_eq(c->frame_count, 1);
+        ck_assert(_damage_covers(c, &old));
+        ck_assert(_damage_covers(c, &c->mover_rect));
+        if (!_damage_is_all(c)) partial = EINA_TRUE;
+     }
+
+   /* The damage is what changed, not the whole canvas, as soon as the
+    * driver tells how old the buffer it gives back is. */
+   if (_driver_has_buffer_age(c->fd)) ck_assert(partial);
+
+   _canvas_free(c);
+}
+EFL_END_TEST
+
+EFL_START_TEST(evas_test_gl_drm_one_frame_per_render)
+{
+   Test_Canvas *c = _canvas_new();
+   int i;
+
+   if (!c) return;
+
+   _render(c);
+   ck_assert_uint_eq(c->frame_count, 1);
+
+   for (i = 0; i < 6; i++)
+     {
+        _render(c);
+        ck_assert_uint_eq(c->frame_count, (unsigned int)i + 1);
+
+        _change_and_render(c);
+        ck_assert_uint_eq(c->frame_count, (unsigned int)i + 2);
+     }
+
+   _canvas_free(c);
+}
+EFL_END_TEST
+
+EFL_START_TEST(evas_test_gl_drm_frame_id)
+{
+   Test_Canvas *c = _canvas_new();
+   int i;
+
+   if (!c) return;
+
+   for (i = 0; i < 20; i++) _change_and_render(c);
+
+   /* The engine goes round a few buffers and each one keeps its name. */
+   ck_assert_uint_eq(c->frame_count, 20);
+   ck_assert_uint_ge(c->id_count, 1);
+   ck_assert_uint_lt(c->id_count, 20);
+
+   _canvas_free(c);
+}
+EFL_END_TEST
+
+EFL_START_TEST(evas_test_gl_drm_no_callback)
+{
+   Test_Canvas *c = _canvas_new();
+   int i;
+
+   if (!c) return;
+
+   c->info->frame.func = NULL;
+   ck_assert(evas_engine_info_set(c->evas, (Evas_Engine_Info *)c->info));
+
+   /* Frames nobody asked for must not use up the buffers, and the first
+    * one somebody asks for later has to be whole: its buffer never saw
+    * what was drawn in the others. */
+   for (i = 0; i < 20; i++) _change_and_render(c);
+   ck_assert_uint_eq(c->frame_count, 0);
+
+   c->info->frame.func = _frame_cb;
+   ck_assert(evas_engine_info_set(c->evas, (Evas_Engine_Info *)c->info));
+   _change_and_render(c);
+   ck_assert_uint_eq(c->frame_count, 1);
+   ck_assert(_damage_is_all(c));
+
+   _change_and_render(c);
+   ck_assert_uint_eq(c->frame_count, 2);
+   ck_assert(_damage_covers(c, &c->mover_rect));
+
+   _canvas_free(c);
+}
+EFL_END_TEST
+
+/* A consumer that keeps every frame must not crash or block the engine: the
+ * renders it cannot draw are skipped. */
+EFL_START_TEST(evas_test_gl_drm_slow_consumer)
+{
+   Test_Canvas *c = _canvas_new();
+   unsigned int held;
+
+   if (!c) return;
+
+   held = _buffers_use_up(c);
+   ck_assert_uint_eq(c->frame_count, held);
+
+   _change_and_render(c);
+   _change_and_render(c);
+   ck_assert_uint_eq(c->frame_count, held);
+
+   _canvas_free(c);
+}
+EFL_END_TEST
+
+/* What changed while the engine could not draw comes with the next frame,
+ * which is a full one, whatever triggers that render. */
+EFL_START_TEST(evas_test_gl_drm_slow_consumer_recovers)
+{
+   Test_Canvas *c;
+   unsigned int held;
+
+   READBACK_OR_RETURN();
+   c = _canvas_new();
+
+   if (!c) return;
+
+   held = _buffers_use_up(c);
+
+   evas_object_color_set(c->top_left, 255, 255, 0, 255);
+   _render(c);
+   ck_assert_uint_eq(c->frame_count, held);
+
+   _frame_release_one(c);
+   _change_and_render(c);
+   ck_assert_uint_eq(c->frame_count, held + 1);
+   ck_assert(_damage_is_all(c));
+   ck_assert(_pixel_is(c->held[held - 1], 24, 16, YELLOW));
+   ck_assert(_pixel_is(c->held[held - 1], c->w - 24, c->h - 16, GREEN));
+
+   _canvas_free(c);
+}
+EFL_END_TEST
+
+EFL_START_TEST(evas_test_gl_drm_slow_consumer_damaged)
+{
+   Test_Canvas *c;
+   unsigned int held;
+
+   READBACK_OR_RETURN();
+   c = _canvas_new();
+
+   if (!c) return;
+
+   held = _buffers_use_up(c);
+
+   evas_object_color_set(c->top_left, 255, 255, 0, 255);
+   _render(c);
+   ck_assert_uint_eq(c->frame_count, held);
+
+   _frame_release_one(c);
+   evas_damage_rectangle_add(c->evas, 0, 0, c->w, c->h);
+   _render(c);
+   ck_assert_uint_eq(c->frame_count, held + 1);
+   ck_assert(_damage_is_all(c));
+   ck_assert(_pixel_is(c->held[held - 1], 24, 16, YELLOW));
+
+   _canvas_free(c);
+}
+EFL_END_TEST
+
+/* The consumer lets go of the oldest frame whenever it has a few, so the
+ * buffers have a steady age when it stops doing so. */
+EFL_START_TEST(evas_test_gl_drm_slow_consumer_steady)
+{
+   Test_Canvas *c;
+   unsigned int held;
+   int i;
+
+   READBACK_OR_RETURN();
+   c = _canvas_new();
+
+   if (!c) return;
+
+   c->hold = EINA_TRUE;
+   for (i = 0; i < 12; i++)
+     {
+        _change_and_render(c);
+        if (c->held_count > 3) _frame_release_oldest(c);
+     }
+   ck_assert_uint_eq(c->held_count, 3);
+
+   held = _buffers_use_up(c);
+   evas_object_color_set(c->top_left, 255, 255, 0, 255);
+   _render(c);
+   ck_assert_uint_eq(c->held_count, held);
+
+   _frame_release_oldest(c);
+   _change_and_render(c);
+   ck_assert_uint_eq(c->held_count, held);
+   ck_assert(_damage_is_all(c));
+   ck_assert(_pixel_is(c->held[held - 1], 24, 16, YELLOW));
+
+   _canvas_free(c);
+}
+EFL_END_TEST
+
+EFL_START_TEST(evas_test_gl_drm_resize)
+{
+   Test_Canvas *c;
+   Evas_Engine_GL_Drm_Frame *old;
+
+   READBACK_OR_RETURN();
+   c = _canvas_new();
+
+   if (!c) return;
+
+   c->hold = EINA_TRUE;
+   _render(c);
+   old = c->held[0];
+   ck_assert_ptr_nonnull(old->bo);
+
+   _canvas_resize(c, 160, 120);
+   _render(c);
+   ck_assert_uint_eq(c->frame_count, 2);
+   ck_assert_uint_eq(gbm_bo_get_width(c->held[1]->bo), 160);
+   ck_assert_uint_eq(gbm_bo_get_height(c->held[1]->bo), 120);
+   ck_assert(_damage_is_all(c));
+   ck_assert(_pixel_is(c->held[1], 24, 16, RED));
+   ck_assert(_pixel_is(c->held[1], 160 - 24, 120 - 16, GREEN));
+
+   /* The buffer of the frame held across the resize went away with the
+    * surface it came from. */
+   ck_assert_ptr_null(old->bo);
+   _held_release_all(c);
+
+   _canvas_resize(c, 64, 48);
+   c->hold = EINA_FALSE;
+   _render(c);
+   ck_assert_uint_eq(c->frame_count, 3);
+   ck_assert(_damage_is_all(c));
+
+   _canvas_free(c);
+}
+EFL_END_TEST
+
+EFL_START_TEST(evas_test_gl_drm_free_with_frame_held)
+{
+   Test_Canvas *c = _canvas_new();
+   Evas_Engine_GL_Drm_Frame *frame;
+
+   if (!c) return;
+
+   c->hold = EINA_TRUE;
+   _render(c);
+   frame = c->held[0];
+   ck_assert_ptr_nonnull(frame->bo);
+
+   evas_free(c->evas);
+   c->evas = NULL;
+   ck_assert_ptr_null(frame->bo);
+
+   _canvas_free(c);
+}
+EFL_END_TEST
+
+EFL_START_TEST(evas_test_gl_drm_no_card_node)
+{
+   Test_Canvas *c;
+   int before;
+
+   before = _fd_count_on("/dev/dri/card");
+   c = _canvas_new();
+   if (!c) return;
+
+   _render(c);
+   _canvas_resize(c, 160, 120);
+   _render(c);
+   ck_assert_uint_eq(c->frame_count, 2);
+   ck_assert_int_eq(_fd_count_on("/dev/dri/card"), before);
+
+   _canvas_free(c);
+}
+EFL_END_TEST
+
+EFL_START_TEST(evas_test_gl_drm_same_node)
+{
+   Test_Canvas *c = _canvas_new(), *other;
+   int fd;
+
+   if (!c) return;
+
+   other = calloc(1, sizeof(Test_Canvas));
+   ck_assert_ptr_nonnull(other);
+   ck_assert(_canvas_open_on(other, c->fd));
+
+   _render(c);
+   _render(other);
+   ck_assert_uint_eq(c->frame_count, 1);
+   ck_assert_uint_eq(other->frame_count, 1);
+
+   /* One gbm device serves the process: another descriptor, even of the
+    * same node, is refused and not silently mixed up with it. */
+   fd = dup(c->fd);
+   ck_assert_int_ge(fd, 0);
+   EXPECT_ERROR_START;
+   ck_assert(!_canvas_open_on(&(Test_Canvas){ 0 }, fd));
+   EXPECT_ERROR_END;
+   close(fd);
+   eina_log_print_cb_set(_log_count_cb, c);
+
+   _canvas_free(other);
+   _canvas_free(c);
+}
+EFL_END_TEST
+
+/* Asking for a node with a DRM device set to none is refused; the same
+ * request while the gbm device was made from a real device (which would
+ * hand the card's gbm to a canvas that gave no node) needs such a device
+ * and cannot be run here. */
+/* A canvas with no device cannot be rotated: the damage is in canvas
+ * coordinates and the buffer would not be. */
+EFL_START_TEST(evas_test_gl_drm_rotation_refused)
+{
+   Test_Canvas *c = _canvas_new();
+   Test_Canvas other = { 0 };
+
+   if (!c) return;
+
+   EXPECT_ERROR_START;
+   other.rotation = 90;
+   ck_assert(!_canvas_open_on(&other, c->fd));
+   EXPECT_ERROR_END;
+   eina_log_print_cb_set(_log_count_cb, c);
+
+   /* Evas does not look at what an update answers: what shows is that the
+    * canvas goes on with the buffers it had. */
+   c->hold = EINA_TRUE;
+   EXPECT_ERROR_START;
+   c->info->info.rotation = 90;
+   evas_engine_info_set(c->evas, (Evas_Engine_Info *)c->info);
+   EXPECT_ERROR_END;
+   eina_log_print_cb_set(_log_count_cb, c);
+
+   _render(c);
+   ck_assert_uint_eq(c->frame_count, 1);
+   ck_assert_uint_eq(gbm_bo_get_width(c->held[0]->bo), c->w);
+   ck_assert_uint_eq(gbm_bo_get_height(c->held[0]->bo), c->h);
+   c->info->info.rotation = 0;
+
+   _canvas_free(c);
+}
+EFL_END_TEST
+
+EFL_START_TEST(evas_test_gl_drm_no_node)
+{
+   Test_Canvas c = { 0 };
+
+   if (!evas_render_method_lookup("gl_drm")) return;
+
+   EXPECT_ERROR_START;
+   ck_assert(!_canvas_open_on(&c, -1));
+   EXPECT_ERROR_END;
+}
+EFL_END_TEST
+
+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_orientation);
+   tcase_add_test(tc, evas_test_gl_drm_damage);
+   tcase_add_test(tc, evas_test_gl_drm_one_frame_per_render);
+   tcase_add_test(tc, evas_test_gl_drm_frame_id);
+   tcase_add_test(tc, evas_test_gl_drm_no_callback);
+   tcase_add_test(tc, evas_test_gl_drm_slow_consumer);
+   tcase_add_test(tc, evas_test_gl_drm_slow_consumer_recovers);
+   tcase_add_test(tc, evas_test_gl_drm_slow_consumer_damaged);
+   tcase_add_test(tc, evas_test_gl_drm_slow_consumer_steady);
+   tcase_add_test(tc, evas_test_gl_drm_resize);
+   tcase_add_test(tc, evas_test_gl_drm_free_with_frame_held);
+   tcase_add_test(tc, evas_test_gl_drm_no_card_node);
+   tcase_add_test(tc, evas_test_gl_drm_same_node);
+   tcase_add_test(tc, evas_test_gl_drm_rotation_refused);
+   tcase_add_test(tc, evas_test_gl_drm_no_node);
+}
diff --git a/src/tests/evas/meson.build b/src/tests/evas/meson.build
index 8cb39f0a6c..f4b4fb5e24 100644
--- a/src/tests/evas/meson.build
+++ b/src/tests/evas/meson.build
@@ -50,6 +50,14 @@ if get_option('drm')
   evas_suite_args += '-DHAVE_DRM_TEST=1'
 endif
 
+# gl_drm drawing on a render node without a device needs the engine and its
+# private header, which pulls in gbm.
+if get_option('drm') and (get_option('opengl') == 'es-egl')
+  evas_suite_src += 'evas_test_gl_drm.c'
+  evas_suite_deps += [dependency('gbm'), dependency('libdrm')] + gl_deps
+  evas_suite_args += '-DHAVE_GL_DRM_TEST=1'
+endif
+
 evas_suite = executable('evas_suite',
   evas_suite_src,
   dependencies: evas_suite_deps, #external deps needed here since tests do include internal headers

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

Reply via email to