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

git pushed a commit to branch wl/dmabuf-import
in repository enlightenment.

View the commit online.

commit 5aa102af8a762fe38bb22099936caa5f831e4b26
Author: Cedric BAIL <[email protected]>
AuthorDate: Sun Nov 29 09:58:08 2026 -0600

    tests - draw a dmabuf that takes over the address of a destroyed one
    
    A GL client that reallocates its buffers, or closes one surface while it
    opens the next, can get a new wl_buffer resource at the address of a
    destroyed one. EFL's GL engines took it for the old buffer, so the
    window stayed on an old frame or was not drawn at all. The fix is in
    EFL; without it this test fails.
    
    The client drops the previous buffer while the next one is being
    created, which is what makes the address be reused. Replacing the buffer
    of one surface hits it every time, replacing the surface as well hits it
    in most runs.
    
    The helpers wl-dmabuf-alpha used move to a header the two share.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 src/tests/wayland/e_wl_dmabufkit.h    | 170 ++++++++++++++++++++++++++++++++++
 src/tests/wayland/meson.build         |  28 +++---
 src/tests/wayland/test_dmabuf_alpha.c | 164 ++------------------------------
 src/tests/wayland/test_dmabuf_reuse.c | 128 +++++++++++++++++++++++++
 4 files changed, 320 insertions(+), 170 deletions(-)

diff --git a/src/tests/wayland/e_wl_dmabufkit.h b/src/tests/wayland/e_wl_dmabufkit.h
new file mode 100644
index 000000000..368e9f25d
--- /dev/null
+++ b/src/tests/wayland/e_wl_dmabufkit.h
@@ -0,0 +1,170 @@
+/* What the tests that draw a client's dmabuf share. They need run-gl.sh. */
+#ifndef E_WL_DMABUFKIT_H
+#define E_WL_DMABUFKIT_H
+
+#include <fcntl.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#include <unistd.h>
+#include <gbm.h>
+
+#include "e_wl_testkit.h"
+#include "linux-dmabuf-unstable-v1-client-protocol.h"
+
+#define BUFFER_W 64
+#define BUFFER_H 64
+
+typedef struct
+{
+   Tk *tk;
+   struct wl_test *tester;
+   unsigned int argb;
+   int answered;
+   struct wl_buffer *buffer;
+   int failed;
+   /* Run once the request for the next buffer is under way. */
+   void (*before_create)(void);
+} Ctx;
+
+static inline void
+_pixel(void *data, struct wl_test *t __attribute__((unused)),
+       int32_t x __attribute__((unused)), int32_t y __attribute__((unused)),
+       uint32_t argb)
+{
+   Ctx *ctx = data;
+
+   ctx->argb = argb;
+   ctx->answered = 1;
+}
+
+/* Only the requests this test sends are answered on its own wl_test. */
+static const struct wl_test_listener _tester_listener =
+{
+   .pixel = _pixel
+};
+
+static inline void
+_created(void *data, struct zwp_linux_buffer_params_v1 *params __attribute__((unused)),
+         struct wl_buffer *buffer)
+{
+   Ctx *ctx = data;
+
+   ctx->buffer = buffer;
+}
+
+static inline void
+_failed(void *data, struct zwp_linux_buffer_params_v1 *params __attribute__((unused)))
+{
+   Ctx *ctx = data;
+
+   ctx->failed = 1;
+}
+
+static const struct zwp_linux_buffer_params_v1_listener _params_listener =
+{
+   _created, _failed
+};
+
+/* E sets dmabuf up only once it is running, which can be after we connect. */
+static inline int
+_dmabuf_wait(Ctx *ctx)
+{
+   struct timespec step = { 0, 50000000 };
+   int i;
+
+   for (i = 0; i < TK_WAIT_SECONDS * 20; i++)
+     {
+        if (tk_global_version(ctx->tk, "zwp_linux_dmabuf_v1") >= 3) return 1;
+        nanosleep(&step, NULL);
+        tk_sync(ctx->tk);
+     }
+   return 0;
+}
+
+static inline struct gbm_device *
+_gbm_open(void)
+{
+   char path[32];
+   int i, fd;
+
+   for (i = 128; i < 136; i++)
+     {
+        snprintf(path, sizeof(path), "/dev/dri/renderD%d", i);
+        fd = open(path, O_RDWR | O_CLOEXEC);
+        if (fd >= 0) return gbm_create_device(fd);
+     }
+   return NULL;
+}
+
+typedef uint32_t (*Fill)(int x, void *data);
+
+/* A linear buffer with each pixel given by fill(). NULL, with ctx->failed
+ * set, when E cannot import it. */
+static inline struct wl_buffer *
+_buffer_new(Ctx *ctx, struct zwp_linux_dmabuf_v1 *dmabuf,
+            struct gbm_device *gbm, uint32_t format, Fill fill, void *data)
+{
+   struct zwp_linux_buffer_params_v1 *params;
+   struct gbm_bo *bo;
+   uint32_t stride = 0;
+   uint64_t modifier;
+   void *map, *map_data = NULL;
+   int x, y, fd;
+
+   bo = gbm_bo_create(gbm, BUFFER_W, BUFFER_H, format,
+                      GBM_BO_USE_LINEAR | GBM_BO_USE_RENDERING);
+   if (!bo) tk_fail(ctx->tk, "cannot allocate a %.4s buffer", (char *)&format);
+   map = gbm_bo_map(bo, 0, 0, BUFFER_W, BUFFER_H, GBM_BO_TRANSFER_WRITE,
+                    &stride, &map_data);
+   if (!map) tk_fail(ctx->tk, "cannot map a %.4s buffer", (char *)&format);
+   for (y = 0; y < BUFFER_H; y++)
+     {
+        uint32_t *row = (uint32_t *)((unsigned char *)map + (y * stride));
+
+        for (x = 0; x < BUFFER_W; x++) row[x] = fill(x, data);
+     }
+   gbm_bo_unmap(bo, map_data);
+
+   fd = gbm_bo_get_fd(bo);
+   modifier = gbm_bo_get_modifier(bo);
+   params = zwp_linux_dmabuf_v1_create_params(dmabuf);
+   zwp_linux_buffer_params_v1_add_listener(params, &_params_listener, ctx);
+   zwp_linux_buffer_params_v1_add(params, fd, 0, 0, gbm_bo_get_stride(bo),
+                                  modifier >> 32, modifier & 0xffffffff);
+   if (ctx->before_create) ctx->before_create();
+   ctx->buffer = NULL;
+   ctx->failed = 0;
+   zwp_linux_buffer_params_v1_create(params, BUFFER_W, BUFFER_H, format, 0);
+   tk_sync(ctx->tk);
+   zwp_linux_buffer_params_v1_destroy(params);
+   close(fd);
+   gbm_bo_destroy(bo);
+   if ((!ctx->buffer) && (!ctx->failed))
+     tk_fail(ctx->tk, "no answer to creating a %.4s buffer", (char *)&format);
+
+   return ctx->buffer;
+}
+
+/* The theme animates a window being shown. */
+static inline void
+_pixel_wait(Ctx *ctx, int x, int y, unsigned int want, const char *what)
+{
+   struct timespec step = { 0, 50000000 };
+   int i;
+
+   for (i = 0; i < TK_WAIT_SECONDS * 20; i++)
+     {
+        ctx->answered = 0;
+        wl_test_get_pixel(ctx->tester, x, y);
+        tk_sync(ctx->tk);
+        if (!ctx->answered) tk_fail(ctx->tk, "no answer to get_pixel");
+        if (ctx->argb == want) return;
+        nanosleep(&step, NULL);
+     }
+   tk_fail(ctx->tk, "%s: pixel %d,%d is %#x, wanted %#x", what, x, y,
+           ctx->argb, want);
+}
+
+#endif
diff --git a/src/tests/wayland/meson.build b/src/tests/wayland/meson.build
index ac928ef09..238824473 100644
--- a/src/tests/wayland/meson.build
+++ b/src/tests/wayland/meson.build
@@ -152,19 +152,21 @@ endforeach
 # gbm is only used to make the buffers.
 dep_gbm = dependency('gbm', required: false)
 if dep_gbm.found()
-  test('wl-dmabuf-alpha',
-    find_program('run-gl.sh'),
-    args: [executable('test_wl_dmabuf_alpha',
-      ['test_dmabuf_alpha.c', tk_src, test_proto_src],
-      dependencies: [dependency('wayland-client'), dep_gbm],
-    )],
-    env: wl_test_env,
-    suite: 'gl',
-    # Two compositors on GL. Alongside the other tests, startup can outlast
-    # E's main loop watchdog.
-    is_parallel: false,
-    timeout: 180,
-  )
+  foreach t : ['alpha', 'reuse']
+    test('wl-dmabuf-' + t,
+      find_program('run-gl.sh'),
+      args: [executable('test_wl_dmabuf_' + t,
+        ['test_dmabuf_' + t + '.c', tk_src, test_proto_src],
+        dependencies: [dependency('wayland-client'), dep_gbm],
+      )],
+      env: wl_test_env,
+      suite: 'gl',
+      # Two compositors on GL. Alongside the other tests, startup can outlast
+      # E's main loop watchdog.
+      is_parallel: false,
+      timeout: 180,
+    )
+  endforeach
 endif
 
 # X clients of the compositor's own Xwayland, so the xwayland module is
diff --git a/src/tests/wayland/test_dmabuf_alpha.c b/src/tests/wayland/test_dmabuf_alpha.c
index eb6d0af7f..ea4713eab 100644
--- a/src/tests/wayland/test_dmabuf_alpha.c
+++ b/src/tests/wayland/test_dmabuf_alpha.c
@@ -6,172 +6,21 @@
  * zeroes, transparent where the format has alpha and black where it does not;
  * the right half is opaque black, so that a buffer which was not drawn at all
  * cannot pass. */
-#include <fcntl.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <stdlib.h>
 #include <string.h>
-#include <time.h>
-#include <unistd.h>
-#include <gbm.h>
 
-#include "e_wl_testkit.h"
-#include "linux-dmabuf-unstable-v1-client-protocol.h"
+#include "e_wl_dmabufkit.h"
 
 #define PROG "test-dmabuf-alpha"
 #define APP_ID "e.test.dmabuf-alpha"
-#define BUFFER_W 64
-#define BUFFER_H 64
 
 #define WHITE 0xffffffff
 #define BLACK 0xff000000
 
-typedef struct
+/* Alpha is the top byte of all four formats, and the colour is black. */
+static uint32_t
+_fill(int x, void *data __attribute__((unused)))
 {
-   Tk *tk;
-   struct wl_test *tester;
-   unsigned int argb;
-   int answered;
-   struct wl_buffer *buffer;
-   int failed;
-} Ctx;
-
-static void
-_pixel(void *data, struct wl_test *t __attribute__((unused)),
-       int32_t x __attribute__((unused)), int32_t y __attribute__((unused)),
-       uint32_t argb)
-{
-   Ctx *ctx = data;
-
-   ctx->argb = argb;
-   ctx->answered = 1;
-}
-
-/* Only the requests this test sends are answered on its own wl_test. */
-static const struct wl_test_listener _tester_listener =
-{
-   .pixel = _pixel
-};
-
-static void
-_created(void *data, struct zwp_linux_buffer_params_v1 *params __attribute__((unused)),
-         struct wl_buffer *buffer)
-{
-   Ctx *ctx = data;
-
-   ctx->buffer = buffer;
-}
-
-static void
-_failed(void *data, struct zwp_linux_buffer_params_v1 *params __attribute__((unused)))
-{
-   Ctx *ctx = data;
-
-   ctx->failed = 1;
-}
-
-static const struct zwp_linux_buffer_params_v1_listener _params_listener =
-{
-   _created, _failed
-};
-
-/* E sets dmabuf up only once it is running, which can be after we connect. */
-static int
-_dmabuf_wait(Ctx *ctx)
-{
-   struct timespec step = { 0, 50000000 };
-   int i;
-
-   for (i = 0; i < TK_WAIT_SECONDS * 20; i++)
-     {
-        if (tk_global_version(ctx->tk, "zwp_linux_dmabuf_v1") >= 3) return 1;
-        nanosleep(&step, NULL);
-        tk_sync(ctx->tk);
-     }
-   return 0;
-}
-
-static struct gbm_device *
-_gbm_open(void)
-{
-   char path[32];
-   int i, fd;
-
-   for (i = 128; i < 136; i++)
-     {
-        snprintf(path, sizeof(path), "/dev/dri/renderD%d", i);
-        fd = open(path, O_RDWR | O_CLOEXEC);
-        if (fd >= 0) return gbm_create_device(fd);
-     }
-   return NULL;
-}
-
-/* NULL, with ctx->failed set, when E cannot import the buffer. */
-static struct wl_buffer *
-_buffer_new(Ctx *ctx, struct zwp_linux_dmabuf_v1 *dmabuf,
-            struct gbm_device *gbm, uint32_t format)
-{
-   static const unsigned char opaque_black[4] = { 0, 0, 0, 0xff };
-   struct zwp_linux_buffer_params_v1 *params;
-   struct gbm_bo *bo;
-   uint32_t stride = 0;
-   uint64_t modifier;
-   void *map, *map_data = NULL;
-   int x, y, fd;
-
-   bo = gbm_bo_create(gbm, BUFFER_W, BUFFER_H, format,
-                      GBM_BO_USE_LINEAR | GBM_BO_USE_RENDERING);
-   if (!bo) tk_fail(ctx->tk, "cannot allocate a %.4s buffer", (char *)&format);
-   map = gbm_bo_map(bo, 0, 0, BUFFER_W, BUFFER_H, GBM_BO_TRANSFER_WRITE,
-                    &stride, &map_data);
-   if (!map) tk_fail(ctx->tk, "cannot map a %.4s buffer", (char *)&format);
-   for (y = 0; y < BUFFER_H; y++)
-     {
-        unsigned char *row = (unsigned char *)map + (y * stride);
-
-        memset(row, 0, BUFFER_W * 4);
-        for (x = BUFFER_W / 2; x < BUFFER_W; x++)
-          memcpy(row + (x * 4), opaque_black, sizeof(opaque_black));
-     }
-   gbm_bo_unmap(bo, map_data);
-
-   fd = gbm_bo_get_fd(bo);
-   modifier = gbm_bo_get_modifier(bo);
-   params = zwp_linux_dmabuf_v1_create_params(dmabuf);
-   zwp_linux_buffer_params_v1_add_listener(params, &_params_listener, ctx);
-   zwp_linux_buffer_params_v1_add(params, fd, 0, 0, gbm_bo_get_stride(bo),
-                                  modifier >> 32, modifier & 0xffffffff);
-   ctx->buffer = NULL;
-   ctx->failed = 0;
-   zwp_linux_buffer_params_v1_create(params, BUFFER_W, BUFFER_H, format, 0);
-   tk_sync(ctx->tk);
-   zwp_linux_buffer_params_v1_destroy(params);
-   close(fd);
-   gbm_bo_destroy(bo);
-   if ((!ctx->buffer) && (!ctx->failed))
-     tk_fail(ctx->tk, "no answer to creating a %.4s buffer", (char *)&format);
-
-   return ctx->buffer;
-}
-
-/* The theme animates a window being shown. */
-static void
-_pixel_wait(Ctx *ctx, int x, int y, unsigned int want, const char *what)
-{
-   struct timespec step = { 0, 50000000 };
-   int i;
-
-   for (i = 0; i < TK_WAIT_SECONDS * 20; i++)
-     {
-        ctx->answered = 0;
-        wl_test_get_pixel(ctx->tester, x, y);
-        tk_sync(ctx->tk);
-        if (!ctx->answered) tk_fail(ctx->tk, "no answer to get_pixel");
-        if (ctx->argb == want) return;
-        nanosleep(&step, NULL);
-     }
-   tk_fail(ctx->tk, "%s: pixel %d,%d is %#x, wanted %#x", what, x, y,
-           ctx->argb, want);
+   return (x < (BUFFER_W / 2)) ? 0 : BLACK;
 }
 
 int
@@ -229,7 +78,8 @@ main(void)
 
    for (i = 0; i < sizeof(formats) / sizeof(formats[0]); i++)
      {
-        buffer = _buffer_new(&ctx, dmabuf, gbm, formats[i].format);
+        buffer = _buffer_new(&ctx, dmabuf, gbm, formats[i].format,
+                             _fill, NULL);
         if (!buffer)
           {
              printf(PROG ": skipped, E cannot import %s: does EFL support "
diff --git a/src/tests/wayland/test_dmabuf_reuse.c b/src/tests/wayland/test_dmabuf_reuse.c
new file mode 100644
index 000000000..0b7909904
--- /dev/null
+++ b/src/tests/wayland/test_dmabuf_reuse.c
@@ -0,0 +1,128 @@
+/* Is a new dmabuf drawn when the wl_buffer before it is gone? The new
+ * wl_buffer resource is often allocated where the old one was, and an image
+ * imported from the old one must not be taken for it.
+ *
+ * Each round asks for a buffer of another colour and drops the previous one
+ * while the request is under way, which is what hands its memory over. First
+ * one surface has its buffer replaced, then each round also replaces the
+ * surface, as closing a menu and opening the next does. */
+#include "e_wl_dmabufkit.h"
+
+#define PROG "test-dmabuf-reuse"
+#define APP_ID "e.test.dmabuf-reuse"
+#define ROUNDS 20
+
+static struct
+{
+   struct wl_buffer *buffer;
+   struct wl_surface *surface;
+   struct wl_subsurface *subsurface;
+} _old;
+
+static void
+_old_drop(void)
+{
+   if (_old.subsurface) wl_subsurface_destroy(_old.subsurface);
+   if (_old.surface) wl_surface_destroy(_old.surface);
+   if (_old.buffer) wl_buffer_destroy(_old.buffer);
+   _old.subsurface = NULL;
+   _old.surface = NULL;
+   _old.buffer = NULL;
+}
+
+static uint32_t
+_fill(int x __attribute__((unused)), void *data)
+{
+   return *(const uint32_t *)data;
+}
+
+int
+main(void)
+{
+   static uint32_t colors[] =
+     { 0xffff0000, 0xff00ff00, 0xff0000ff, 0xffffff00, 0xff00ffff };
+   static const char *what[] = { "same surface", "new surface" };
+   struct wl_compositor *compositor;
+   struct wl_subcompositor *subcompositor;
+   struct zwp_linux_dmabuf_v1 *dmabuf;
+   struct wl_subsurface *subsurface = NULL;
+   struct wl_surface *surface = NULL, *parent;
+   struct wl_buffer *buffer;
+   struct gbm_device *gbm;
+   Tk_Toplevel *top;
+   Ctx ctx = { 0 };
+   uint32_t *color;
+   char label[64];
+   int phase, i, x, y, w, h;
+
+   ctx.tk = tk_connect(PROG);
+   ctx.tester = tk_bind(ctx.tk, &wl_test_interface, 9);
+   if (!ctx.tester) tk_fail(ctx.tk, "no wl_test version 9");
+   wl_test_add_listener(ctx.tester, &_tester_listener, &ctx);
+
+   if (!_dmabuf_wait(&ctx))
+     {
+        printf(PROG ": skipped, E does not offer zwp_linux_dmabuf_v1\n");
+        return 77;
+     }
+   gbm = _gbm_open();
+   if (!gbm)
+     {
+        printf(PROG ": skipped, no gbm device\n");
+        return 77;
+     }
+   compositor = tk_bind(ctx.tk, &wl_compositor_interface, 4);
+   subcompositor = tk_bind(ctx.tk, &wl_subcompositor_interface, 1);
+   dmabuf = tk_bind(ctx.tk, &zwp_linux_dmabuf_v1_interface, 3);
+   ctx.before_create = _old_drop;
+
+   /* The cursor is drawn on the same canvas. */
+   tk_pointer_warp(ctx.tk, 0, 0);
+
+   top = tk_toplevel_new(ctx.tk, APP_ID, "dmabuf reuse", 320, 150);
+   parent = tk_toplevel_surface(top);
+
+   for (phase = 0; phase < 2; phase++)
+     for (i = 0; i < ROUNDS; i++)
+       {
+          color = &colors[i % (sizeof(colors) / sizeof(colors[0]))];
+          buffer = _buffer_new(&ctx, dmabuf, gbm, GBM_FORMAT_XRGB8888,
+                               _fill, color);
+          if (!buffer)
+            {
+               printf(PROG ": skipped, E cannot import XRGB8888: does EFL "
+                      "support dmabuf on this engine?\n");
+               return 77;
+            }
+          if (!surface)
+            {
+               surface = wl_compositor_create_surface(compositor);
+               subsurface = wl_subcompositor_get_subsurface(subcompositor,
+                                                            surface, parent);
+               wl_subsurface_set_position(subsurface, 20, 20);
+               wl_subsurface_set_desync(subsurface);
+            }
+          wl_surface_attach(surface, buffer, 0, 0);
+          wl_surface_damage(surface, 0, 0, BUFFER_W, BUFFER_H);
+          wl_surface_commit(surface);
+          wl_surface_commit(parent);
+          tk_settle(ctx.tk);
+          tk_surface_geometry(ctx.tk, surface, &x, &y, &w, &h);
+
+          snprintf(label, sizeof(label), "%s, round %d", what[phase], i);
+          _pixel_wait(&ctx, x + (BUFFER_W / 2), y + (BUFFER_H / 2), *color,
+                      label);
+
+          _old.buffer = buffer;
+          if (phase == 1)
+            {
+               _old.surface = surface;
+               _old.subsurface = subsurface;
+               surface = NULL;
+            }
+       }
+
+   tk_disconnect(ctx.tk);
+   printf(PROG ": ok\n");
+   return 0;
+}

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

Reply via email to