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

git pushed a commit to branch tests/fullscreen-maximize-restore
in repository enlightenment.

View the commit online.

commit 4eb990b2a8c4d362ca6cab3733186cf227872558
Author: Cedric BAIL <[email protected]>
AuthorDate: Sat Nov 28 23:31:02 2026 -0600

    tests - draw dmabufs with and without alpha on a GL canvas
    
    Whether a client's dmabuf is blended could only be asked of E, not seen:
    no test backend offered dmabuf or could read back a GL canvas.
    run-gl.sh nests E in a headless Weston, which needs a GPU but no
    display, and wl_test.get_pixel now reads a GL canvas through a snapshot.
    
    The test is skipped without Weston, a GPU or an EFL that can import on
    wayland_egl. It runs on its own: several at once kept E starting up for
    longer than its main loop watchdog allows. It uses libgbm, for the test
    only and only when found.
    
    The buffers stay alive together on purpose. Destroying each before the
    next, about one run in three leaves a later buffer undrawn; the new
    wl_buffer has the old one's id, and evas looks imports up by the
    resource address, so a stale import is the likely cause.
    
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 src/modules/wl_test/e_mod_main.c      |  57 +++++++-
 src/protocol/wl-test.xml              |   4 +-
 src/tests/wayland/meson.build         |  20 +++
 src/tests/wayland/run-gl.sh           |  55 +++++++
 src/tests/wayland/test_dmabuf_alpha.c | 260 ++++++++++++++++++++++++++++++++++
 5 files changed, 389 insertions(+), 7 deletions(-)

diff --git a/src/modules/wl_test/e_mod_main.c b/src/modules/wl_test/e_mod_main.c
index 55aa306b5..ad360f009 100644
--- a/src/modules/wl_test/e_mod_main.c
+++ b/src/modules/wl_test/e_mod_main.c
@@ -340,18 +340,65 @@ _wl_test_cb_key_modified(struct wl_client *client EINA_UNUSED, struct wl_resourc
    e_comp_wl_input_keyboard_event_generate(keyname, modifiers, !pressed);
 }
 
+typedef struct
+{
+   Evas_Object *snapshot;
+   unsigned int argb;
+} Wl_Test_Pixel;
+
+static void
+_wl_test_cb_render_post(void *data, Evas *e EINA_UNUSED, void *event EINA_UNUSED)
+{
+   Wl_Test_Pixel *pixel = data;
+   const unsigned int *pixels;
+
+   pixels = evas_object_image_data_get(pixel->snapshot, 0);
+   if (pixels) pixel->argb = pixels[0];
+}
+
+/* A GL canvas has no buffer to read, so render once with a snapshot of the
+ * pixel on top, as the shot module does. */
+static unsigned int
+_wl_test_pixel_snapshot(int x, int y)
+{
+   Wl_Test_Pixel pixel = { 0 };
+
+   pixel.snapshot = evas_object_image_filled_add(e_comp->evas);
+   evas_object_pass_events_set(pixel.snapshot, 1);
+   evas_object_layer_set(pixel.snapshot, EVAS_LAYER_MAX);
+   evas_object_image_snapshot_set(pixel.snapshot, 1);
+   evas_object_geometry_set(pixel.snapshot, x, y, 1, 1);
+   evas_object_show(pixel.snapshot);
+   evas_object_image_data_update_add(pixel.snapshot, 0, 0, 1, 1);
+   evas_object_image_pixels_dirty_set(pixel.snapshot, 1);
+   evas_event_callback_add(e_comp->evas, EVAS_CALLBACK_RENDER_POST,
+                           _wl_test_cb_render_post, &pixel);
+   ecore_evas_manual_render(e_comp->ee);
+   evas_event_callback_del_full(e_comp->evas, EVAS_CALLBACK_RENDER_POST,
+                                _wl_test_cb_render_post, &pixel);
+   evas_object_del(pixel.snapshot);
+
+   return pixel.argb;
+}
+
 static void
 _wl_test_cb_get_pixel(struct wl_client *client EINA_UNUSED, struct wl_resource *resource, int32_t x, int32_t y)
 {
-   const unsigned int *pixels = NULL;
+   const unsigned int *pixels;
    unsigned int argb = 0;
    int w, h;
 
    ecore_evas_geometry_get(e_comp->ee, NULL, NULL, &w, &h);
-   if (!strcmp(ecore_evas_engine_name_get(e_comp->ee), "buffer"))
-     pixels = ecore_evas_buffer_pixels_get(e_comp->ee);
-   if (pixels && (x >= 0) && (y >= 0) && (x < w) && (y < h))
-     argb = pixels[(y * w) + x];
+   if ((x >= 0) && (y >= 0) && (x < w) && (y < h))
+     {
+        if (!strcmp(ecore_evas_engine_name_get(e_comp->ee), "buffer"))
+          {
+             pixels = ecore_evas_buffer_pixels_get(e_comp->ee);
+             if (pixels) argb = pixels[(y * w) + x];
+          }
+        else
+          argb = _wl_test_pixel_snapshot(x, y);
+     }
    wl_test_send_pixel(resource, x, y, argb);
 }
 
diff --git a/src/protocol/wl-test.xml b/src/protocol/wl-test.xml
index 3225ebe5f..87e22d7c7 100644
--- a/src/protocol/wl-test.xml
+++ b/src/protocol/wl-test.xml
@@ -350,8 +350,8 @@
     <request name="get_pixel" since="9">
       <description summary="read a pixel of the composited screen">
         Renders the canvas and answers with a pixel event, so that a test
-        can check what E drew and not only where. Only the buffer backend
-        has pixels to read; elsewhere the answer is 0.
+        can check what E drew and not only where. The answer is 0 outside
+        the canvas, or when it cannot be read.
       </description>
       <arg name="x" type="int"/>
       <arg name="y" type="int"/>
diff --git a/src/tests/wayland/meson.build b/src/tests/wayland/meson.build
index 57b08a40e..ac928ef09 100644
--- a/src/tests/wayland/meson.build
+++ b/src/tests/wayland/meson.build
@@ -147,6 +147,26 @@ foreach t: wl_protocol_tests
   )
 endforeach
 
+# Drawing a client's dmabuf takes a GL canvas on a real GPU, which no backend
+# above has: run-gl.sh nests E in a headless Weston, and skips without one.
+# 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,
+  )
+endif
+
 # X clients of the compositor's own Xwayland, so the xwayland module is
 # loaded as well, and the client speaks X through ecore_x. One program, run
 # once per scenario.
diff --git a/src/tests/wayland/run-gl.sh b/src/tests/wayland/run-gl.sh
new file mode 100755
index 000000000..2624fcf51
--- /dev/null
+++ b/src/tests/wayland/run-gl.sh
@@ -0,0 +1,55 @@
+#!/bin/sh
+# Run a Wayland client against a throwaway Enlightenment that draws with GL.
+#
+#   run-gl.sh <client> [args...]
+#
+# E runs on its wl backend, nested in a headless Weston of its own, so it
+# needs a GPU but no display, and never touches the session it is run from.
+# Exits 77, a skip, without Weston or a GPU.
+#
+# Otherwise as run-nested.sh, which starts E.
+
+set -eu
+
+if ! command -v weston >/dev/null 2>&1; then
+    echo "run-gl.sh: skipped, weston is not installed" >&2
+    exit 77
+fi
+if ! ls /dev/dri/renderD* >/dev/null 2>&1; then
+    echo "run-gl.sh: skipped, no DRM render node" >&2
+    exit 77
+fi
+
+# A short path: it holds a socket, whose name is limited to 108 bytes.
+HOST=$(mktemp -d "${TMPDIR:-/tmp}/e-wl-host.XXXXXX")
+chmod 0700 "$HOST"
+unset DISPLAY WAYLAND_DISPLAY
+
+XDG_RUNTIME_DIR="$HOST" weston --backend=headless --renderer=gl \
+    --width=1536 --height=1152 --socket=host --idle-time=0 \
+    >"$HOST/weston.log" 2>&1 &
+WESTON_PID=$!
+
+cleanup() {
+    status=$?
+    kill "$WESTON_PID" 2>/dev/null || :
+    wait "$WESTON_PID" 2>/dev/null || :
+    rm -rf "$HOST"
+    exit $status
+}
+trap cleanup EXIT INT TERM
+
+i=0
+while [ ! -S "$HOST/host" ] && [ $i -lt 100 ]; do
+    if ! kill -0 "$WESTON_PID" 2>/dev/null; then break; fi
+    i=$((i + 1))
+    sleep 0.1
+done
+if [ ! -S "$HOST/host" ] || ! grep -q 'Using GL renderer' "$HOST/weston.log"; then
+    echo "run-gl.sh: skipped, weston has no GL renderer here" >&2
+    cat "$HOST/weston.log" >&2
+    exit 77
+fi
+
+E_TEST_BACKEND=wl E_COMP_ENGINE=gl WAYLAND_DISPLAY="$HOST/host" \
+    sh "$(dirname "$0")/run-nested.sh" "$@"
diff --git a/src/tests/wayland/test_dmabuf_alpha.c b/src/tests/wayland/test_dmabuf_alpha.c
new file mode 100644
index 000000000..eb6d0af7f
--- /dev/null
+++ b/src/tests/wayland/test_dmabuf_alpha.c
@@ -0,0 +1,260 @@
+/* Is a dmabuf with alpha blended over what is behind it? Taken as opaque, the
+ * transparent pixels of a menu come out black.
+ *
+ * Each format is shown as a subsurface over a white window, side by side so
+ * that none can be seen in place of another. The left half of a buffer is all
+ * 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"
+
+#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
+{
+   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);
+}
+
+int
+main(void)
+{
+   static const struct
+   {
+      uint32_t format;
+      unsigned int behind_zeroes;
+      const char *name;
+   } formats[] =
+   {
+      { GBM_FORMAT_ARGB8888, WHITE, "ARGB8888" },
+      { GBM_FORMAT_ABGR8888, WHITE, "ABGR8888" },
+      { GBM_FORMAT_XRGB8888, BLACK, "XRGB8888" },
+      { GBM_FORMAT_XBGR8888, BLACK, "XBGR8888" },
+   };
+   struct wl_compositor *compositor;
+   struct wl_subcompositor *subcompositor;
+   struct zwp_linux_dmabuf_v1 *dmabuf;
+   struct wl_subsurface *subsurface;
+   struct wl_surface *surface, *parent;
+   struct wl_buffer *buffer;
+   struct gbm_device *gbm;
+   Tk_Toplevel *top;
+   Ctx ctx = { 0 };
+   unsigned int i;
+   int 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);
+
+   /* The cursor is drawn on the same canvas. */
+   tk_pointer_warp(ctx.tk, 0, 0);
+
+   top = tk_toplevel_new(ctx.tk, APP_ID, "dmabuf alpha", 320, 150);
+   parent = tk_toplevel_surface(top);
+
+   for (i = 0; i < sizeof(formats) / sizeof(formats[0]); i++)
+     {
+        buffer = _buffer_new(&ctx, dmabuf, gbm, formats[i].format);
+        if (!buffer)
+          {
+             printf(PROG ": skipped, E cannot import %s: does EFL support "
+                    "dmabuf on this engine?\n", formats[i].name);
+             return 77;
+          }
+        surface = wl_compositor_create_surface(compositor);
+        subsurface = wl_subcompositor_get_subsurface(subcompositor, surface,
+                                                     parent);
+        wl_subsurface_set_position(subsurface, 20 + (i * (BUFFER_W + 8)), 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);
+
+        _pixel_wait(&ctx, x + (BUFFER_W * 3 / 4), y + (BUFFER_H / 2), BLACK,
+                    formats[i].name);
+        _pixel_wait(&ctx, x + (BUFFER_W / 4), y + (BUFFER_H / 2),
+                    formats[i].behind_zeroes, formats[i].name);
+     }
+
+   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