This is an automated email from the git hooks/post-receive script.
git pushed a commit to reference refs/pull/233/head
in repository enlightenment.
View the commit online.
commit 3f224b3c5600fada77ceecfa18d279954f7010c0
Author: Cedric BAIL <[email protected]>
AuthorDate: Mon Nov 30 21:35:37 2026 -0600
e_comp_wl_dmabuf - only offer and accept the dmabuf layouts E can draw
E advertised every format and modifier the driver lists for import, and
then took any buffer a client sent. Both were too generous now that
dmabuf is offered on X11 and nested as well as on DRM.
A modifier the driver flags external_only gives an EGLImage that only
GL_TEXTURE_EXTERNAL_OES can sample, and evas binds a native surface to
GL_TEXTURE_2D: a client that picks one gets its buffer drawn as
garbage, and nothing is logged. E asked for the formats and modifiers
without asking for that flag. Those modifiers are no longer offered,
nor a format left with none of its modifiers usable, in the version 3
events and in the version 4 format table alike. On Panfrost here that
is 187 format and modifier pairs instead of 229.
A buffer in a format or with a modifier E did not advertise is now
refused with INVALID_FORMAT, the protocol having no error of its own
for a modifier, instead of being handed to an import that may fail
quietly or show garbage. As before, a buffer made without modifiers is
taken for any advertised format, and a linear one for a format
advertised with no modifier of its own.
The list is built once: asking EGL for it took 0.5 to 2 ms, measured
around each check in the GL tests, too long for every buffer a client
makes.
test_dmabuf_format_check.c makes a buffer in a format nothing
advertises and one with a modifier nothing advertises, and expects
INVALID_FORMAT for each, and a buffer made as advertised to go through.
Without this change the first is accepted and only its import fails.
It runs in the GL suite, through run-gl.sh. No test can see the
external_only filtering itself: a client cannot tell which modifiers
the driver flagged.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
src/bin/e_comp_wl_dmabuf.c | 83 ++++++++++++++++
src/bin/e_pixmap.c | 79 ++++++++++-----
src/tests/wayland/meson.build | 4 +-
src/tests/wayland/test_dmabuf_format_check.c | 142 +++++++++++++++++++++++++++
4 files changed, 281 insertions(+), 27 deletions(-)
diff --git a/src/bin/e_comp_wl_dmabuf.c b/src/bin/e_comp_wl_dmabuf.c
index cd4c215d1..ac8e1f402 100644
--- a/src/bin/e_comp_wl_dmabuf.c
+++ b/src/bin/e_comp_wl_dmabuf.c
@@ -179,6 +179,78 @@ destroy_linux_dmabuf_wl_buffer(struct wl_resource *resource)
linux_dmabuf_buffer_destroy(buffer);
}
+typedef struct
+{
+ uint32_t format;
+ uint64_t modifier;
+} Dmabuf_Advertised;
+
+/* What E advertises, a format with no modifier of its own as
+ * DRM_FORMAT_MOD_INVALID. Built on first use: it cannot change while E runs,
+ * and asking EGL for it takes about a millisecond, too long to do for each
+ * buffer a client makes. */
+static Dmabuf_Advertised *dmabuf_advertised = NULL;
+static int dmabuf_advertised_num = -1;
+
+static void
+_dmabuf_advertised_build(void)
+{
+ uint64_t *modifiers;
+ int *formats = NULL;
+ int num_formats = 0, num_modifiers, i, j, n = 0;
+
+ dmabuf_advertised_num = 0;
+ if (!e_pixmap_dmabuf_formats_query(&formats, &num_formats)) return;
+ for (i = 0; i < num_formats; i++)
+ {
+ Dmabuf_Advertised *grown;
+
+ modifiers = NULL;
+ if (!e_pixmap_dmabuf_modifiers_query(formats[i], &modifiers,
+ &num_modifiers))
+ num_modifiers = 0;
+ grown = realloc(dmabuf_advertised, (n + num_modifiers + 1) *
+ sizeof(Dmabuf_Advertised));
+ if (!grown)
+ {
+ free(modifiers);
+ break;
+ }
+ dmabuf_advertised = grown;
+ dmabuf_advertised[n].format = formats[i];
+ dmabuf_advertised[n++].modifier = DRM_FORMAT_MOD_INVALID;
+ for (j = 0; j < num_modifiers; j++)
+ {
+ dmabuf_advertised[n].format = formats[i];
+ dmabuf_advertised[n++].modifier = modifiers[j];
+ }
+ free(modifiers);
+ }
+ free(formats);
+ dmabuf_advertised_num = n;
+}
+
+/* Whether a buffer with format and modifier is one E advertised. A buffer
+ * made without modifiers carries DRM_FORMAT_MOD_INVALID, and one with an
+ * advertised format and no modifier of its own may be linear. */
+static Eina_Bool
+_dmabuf_advertised(uint32_t format, uint64_t modifier)
+{
+ Eina_Bool explicit = EINA_FALSE, known = EINA_FALSE;
+ int i;
+
+ if (dmabuf_advertised_num < 0) _dmabuf_advertised_build();
+ for (i = 0; i < dmabuf_advertised_num; i++)
+ {
+ if (dmabuf_advertised[i].format != format) continue;
+ known = EINA_TRUE;
+ if (dmabuf_advertised[i].modifier == modifier) return EINA_TRUE;
+ if (dmabuf_advertised[i].modifier != DRM_FORMAT_MOD_INVALID)
+ explicit = EINA_TRUE;
+ }
+ return known && (!explicit) && (modifier == DRM_FORMAT_MOD_LINEAR);
+}
+
static void
params_create_common(struct wl_client *client, struct wl_resource *params_resource,
uint32_t buffer_id, int32_t width, int32_t height,
@@ -296,6 +368,17 @@ params_create_common(struct wl_client *client, struct wl_resource *params_resour
}
}
+ /* The protocol has no error of its own for a modifier. */
+ if (!_dmabuf_advertised(format, buffer->attributes.modifier[0]))
+ {
+ wl_resource_post_error(params_resource,
+ ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INVALID_FORMAT,
+ "format %#x with modifier %#llx was not advertised",
+ format,
+ (unsigned long long)buffer->attributes.modifier[0]);
+ goto err_out;
+ }
+
/* XXX: Some additional sanity checks could be done with respect
* to the fourcc format. A centralized collection (kernel or
* libdrm) would be useful to avoid code duplication for these
diff --git a/src/bin/e_pixmap.c b/src/bin/e_pixmap.c
index 338c9127c..f44b88756 100644
--- a/src/bin/e_pixmap.c
+++ b/src/bin/e_pixmap.c
@@ -1341,6 +1341,46 @@ if (weston_check_egl_extension(extensions,
extern Eina_Bool e_comp_wl_query_dmabuf_formats(int max_formats, int *formats, int *num_formats);
extern Eina_Bool e_comp_wl_query_dmabuf_modifiers(int format, int max_modifiers, uint64_t *modifiers, Eina_Bool *external_only, int *num_modifiers);
+/* The modifiers of format that E can show, in a new array. An external_only
+ * modifier makes an EGLImage that only GL_TEXTURE_EXTERNAL_OES can sample,
+ * and evas binds a native surface to GL_TEXTURE_2D: a buffer with one is
+ * drawn as garbage. False, with no array, when the driver lists modifiers
+ * for the format and all of them are external_only. True with none when it
+ * lists no modifier at all, which leaves the layout to the buffer. */
+static Eina_Bool
+_e_pixmap_dmabuf_modifiers_usable(int format, uint64_t **modifiers, int *num_modifiers)
+{
+ Eina_Bool *external = NULL;
+ uint64_t *mods = NULL;
+ int num = 0, i, keep = 0;
+
+ *modifiers = NULL;
+ *num_modifiers = 0;
+ if ((!e_comp_wl_query_dmabuf_modifiers(format, 0, NULL, NULL, &num)) ||
+ (num <= 0))
+ return EINA_TRUE;
+ mods = calloc(num, sizeof(uint64_t));
+ external = calloc(num, sizeof(Eina_Bool));
+ if ((!mods) || (!external) ||
+ (!e_comp_wl_query_dmabuf_modifiers(format, num, mods, external, &num)))
+ {
+ free(mods);
+ free(external);
+ return EINA_TRUE;
+ }
+ for (i = 0; i < num; i++)
+ if (!external[i]) mods[keep++] = mods[i];
+ free(external);
+ if (!keep)
+ {
+ free(mods);
+ return EINA_FALSE;
+ }
+ *modifiers = mods;
+ *num_modifiers = keep;
+ return EINA_TRUE;
+}
+
E_API Eina_Bool
e_pixmap_dmabuf_formats_query(int **formats, int *num_formats)
{
@@ -1356,7 +1396,8 @@ e_pixmap_dmabuf_formats_query(int **formats, int *num_formats)
// DRM_FORMAT_XYUV8888,
};
Eina_Bool fallback = EINA_FALSE;
- int num = 0;
+ uint64_t *modifiers;
+ int num = 0, i, keep = 0, num_modifiers;
if (!e_comp_wl_query_dmabuf_formats(0, NULL, &num))
{
@@ -1381,36 +1422,24 @@ e_pixmap_dmabuf_formats_query(int **formats, int *num_formats)
free(*formats);
return EINA_FALSE;
}
- *num_formats = num;
+ for (i = 0; i < num; i++)
+ {
+ if (!_e_pixmap_dmabuf_modifiers_usable((*formats)[i], &modifiers,
+ &num_modifiers))
+ continue;
+ free(modifiers);
+ (*formats)[keep++] = (*formats)[i];
+ }
+ *num_formats = keep;
return EINA_TRUE;
}
E_API Eina_Bool
e_pixmap_dmabuf_modifiers_query(int format, uint64_t **modifiers, int *num_modifiers)
{
- int num;
-
- if (!e_comp_wl_query_dmabuf_modifiers(format, 0, NULL, NULL, &num) ||
- (num == 0))
- {
- *num_modifiers = 0;
- return EINA_FALSE;
- }
- *modifiers = calloc(num, sizeof(uint64_t));
- if (!(*modifiers))
- {
- *num_modifiers = 0;
- return EINA_FALSE;
- }
- if (!e_comp_wl_query_dmabuf_modifiers
- (format, num, *modifiers, NULL, &num))
- {
- *num_modifiers = 0;
- free(*modifiers);
- return EINA_FALSE;
- }
- *num_modifiers = num;
- return EINA_TRUE;
+ if (!_e_pixmap_dmabuf_modifiers_usable(format, modifiers, num_modifiers))
+ return EINA_FALSE;
+ return *num_modifiers > 0;
}
#endif
diff --git a/src/tests/wayland/meson.build b/src/tests/wayland/meson.build
index 238824473..6f0bb76fc 100644
--- a/src/tests/wayland/meson.build
+++ b/src/tests/wayland/meson.build
@@ -152,8 +152,8 @@ endforeach
# gbm is only used to make the buffers.
dep_gbm = dependency('gbm', required: false)
if dep_gbm.found()
- foreach t : ['alpha', 'reuse']
- test('wl-dmabuf-' + t,
+ foreach t : ['alpha', 'reuse', 'format_check']
+ test('wl-dmabuf-' + t.replace('_', '-'),
find_program('run-gl.sh'),
args: [executable('test_wl_dmabuf_' + t,
['test_dmabuf_' + t + '.c', tk_src, test_proto_src],
diff --git a/src/tests/wayland/test_dmabuf_format_check.c b/src/tests/wayland/test_dmabuf_format_check.c
new file mode 100644
index 000000000..a8a954df8
--- /dev/null
+++ b/src/tests/wayland/test_dmabuf_format_check.c
@@ -0,0 +1,142 @@
+/* A client is held to the formats and modifiers E advertises: a buffer with
+ * anything else is refused with INVALID_FORMAT, rather than imported into a
+ * texture E cannot sample. A buffer made as advertised still goes through.
+ *
+ * A protocol error ends the connection, so each refusal has its own. */
+#include <string.h>
+
+#include "e_wl_dmabufkit.h"
+
+#define PROG "test-dmabuf-format-check"
+
+#define MODIFIER_LINEAR 0ULL
+#define FORMAT_NOWHERE 0x5a5a5a5a
+/* Vendor 0x0f is not one drm_fourcc.h knows. */
+#define MODIFIER_NOWHERE ((0x0fULL << 56) | 0x123)
+
+typedef struct
+{
+ Ctx ctx;
+ struct zwp_linux_dmabuf_v1 *dmabuf;
+ struct gbm_device *gbm;
+ unsigned int pairs;
+ int xrgb;
+} Check;
+
+static void
+_format(void *data __attribute__((unused)), struct zwp_linux_dmabuf_v1 *d __attribute__((unused)),
+ uint32_t format __attribute__((unused)))
+{
+}
+
+static void
+_modifier(void *data, struct zwp_linux_dmabuf_v1 *d __attribute__((unused)),
+ uint32_t format, uint32_t hi __attribute__((unused)),
+ uint32_t lo __attribute__((unused)))
+{
+ Check *c = data;
+
+ c->pairs++;
+ if (format == GBM_FORMAT_XRGB8888) c->xrgb = 1;
+}
+
+static const struct zwp_linux_dmabuf_v1_listener _dmabuf_listener =
+{
+ _format, _modifier
+};
+
+static void
+_connect(Check *c)
+{
+ memset(c, 0, sizeof(*c));
+ c->ctx.tk = tk_connect(PROG);
+ c->ctx.tester = tk_bind(c->ctx.tk, &wl_test_interface, 9);
+ if (!c->ctx.tester) tk_fail(c->ctx.tk, "no wl_test version 9");
+ wl_test_add_listener(c->ctx.tester, &_tester_listener, &c->ctx);
+ _dmabuf_require(&c->ctx, PROG);
+ c->gbm = _gbm_open();
+ if (!c->gbm)
+ {
+ printf(PROG ": skipped, no gbm device\n");
+ exit(77);
+ }
+ c->dmabuf = tk_bind(c->ctx.tk, &zwp_linux_dmabuf_v1_interface, 3);
+ zwp_linux_dmabuf_v1_add_listener(c->dmabuf, &_dmabuf_listener, c);
+ tk_sync(c->ctx.tk);
+ if (!c->xrgb)
+ tk_fail(c->ctx.tk, "XRGB8888 is not advertised, out of %u pairs",
+ c->pairs);
+}
+
+/* A linear XRGB8888 buffer, declared as format with modifier. */
+static void
+_create(Check *c, uint32_t format, uint64_t modifier)
+{
+ struct zwp_linux_buffer_params_v1 *params;
+ struct gbm_bo *bo;
+ int fd;
+
+ bo = gbm_bo_create(c->gbm, BUFFER_W, BUFFER_H, GBM_FORMAT_XRGB8888,
+ GBM_BO_USE_LINEAR | GBM_BO_USE_RENDERING);
+ if (!bo) tk_fail(c->ctx.tk, "cannot allocate a buffer");
+ fd = gbm_bo_get_fd(bo);
+ params = zwp_linux_dmabuf_v1_create_params(c->dmabuf);
+ zwp_linux_buffer_params_v1_add_listener(params, &_params_listener, &c->ctx);
+ zwp_linux_buffer_params_v1_add(params, fd, 0, 0, gbm_bo_get_stride(bo),
+ modifier >> 32, modifier & 0xffffffff);
+ c->ctx.buffer = NULL;
+ c->ctx.failed = 0;
+ zwp_linux_buffer_params_v1_create(params, BUFFER_W, BUFFER_H, format, 0);
+ close(fd);
+ gbm_bo_destroy(bo);
+}
+
+static uint32_t
+_black(int x __attribute__((unused)), void *data __attribute__((unused)))
+{
+ return 0xff000000;
+}
+
+static void
+_refused(Check *c, const char *what)
+{
+ const struct wl_interface *iface = NULL;
+ int err;
+
+ err = tk_protocol_error(c->ctx.tk, &iface);
+ if (err < 0)
+ tk_fail(c->ctx.tk, "%s was not refused (%s)", what,
+ c->ctx.failed ? "its import failed" : "it was imported");
+ if ((err != ZWP_LINUX_BUFFER_PARAMS_V1_ERROR_INVALID_FORMAT) ||
+ (iface != &zwp_linux_buffer_params_v1_interface))
+ tk_fail(c->ctx.tk, "%s: error %d on %s, not INVALID_FORMAT", what, err,
+ iface ? iface->name : "nothing");
+ printf(PROG ": %s is refused\n", what);
+}
+
+int
+main(void)
+{
+ Check c;
+
+ _connect(&c);
+ printf(PROG ": %u format and modifier pairs advertised\n", c.pairs);
+ _buffer_new(&c.ctx, c.dmabuf, c.gbm, GBM_FORMAT_XRGB8888, _black, NULL);
+ if (!c.ctx.buffer)
+ tk_fail(c.ctx.tk, "an advertised linear XRGB8888 buffer was refused");
+ printf(PROG ": an advertised buffer is created\n");
+ tk_disconnect(c.ctx.tk);
+
+ _connect(&c);
+ _create(&c, FORMAT_NOWHERE, MODIFIER_LINEAR);
+ _refused(&c, "a format never advertised");
+ tk_disconnect(c.ctx.tk);
+
+ _connect(&c);
+ _create(&c, GBM_FORMAT_XRGB8888, MODIFIER_NOWHERE);
+ _refused(&c, "a modifier never advertised");
+ tk_disconnect(c.ctx.tk);
+
+ printf(PROG ": ok\n");
+ return 0;
+}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.