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

git pushed a commit to reference refs/pull/232/head
in repository enlightenment.

View the commit online.

commit 20a1701b481e1f83654f1ebcce03cbedeb1e0478
Author: Cedric BAIL <[email protected]>
AuthorDate: Mon Nov 30 20:48:11 2026 -0600

    e_comp_wl - add wp_content_type_v1
    
    A client tags a surface as showing a photo, a video or a game, so that a
    compositor can adapt: favour timing over latency, hold an effect back,
    or set the DRM "content type" property of a connector so that a
    television stops interpolating a game. Browsers send it for video.
    
    E keeps the hint and acts on none of it yet. That is all the protocol
    asks of a compositor, every use of the hint being optional, and keeping
    it lets a backend or a policy read it later without another protocol
    change.
    
    The type is double buffered like the rest of the surface state, and
    destroying the object means going back to none at the next commit, so
    it lives in the pending state and is copied at commit, as the viewport
    is, and carried to the cache of a synchronized subsurface.
    
    Two requests are refused: a second wp_content_type_v1 for one surface,
    with the protocol's already_constructed, and a type outside the enum, as
    a malformed request. The test checks both, the four valid types, and an
    object made again after it was destroyed. Removing either check makes
    it fail.
    
    When the surface goes away first, the object's user data is cleared, as
    for the surface's viewport and fractional scale objects, so a request on
    it afterwards is ignored. The test sends one, but a dangling pointer
    need not crash, and the test also passes without that line.
    
    Co-Authored-By: Claude Opus 5 <[email protected]>
    Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
 src/bin/e_comp_wl.c                   |   4 ++
 src/bin/e_comp_wl.h                   |   9 +++
 src/bin/e_comp_wl_extensions.c        |  92 +++++++++++++++++++++++++
 src/bin/generated/meson.build         |   1 +
 src/tests/wayland/globals.expected    |   1 +
 src/tests/wayland/meson.build         |   2 +
 src/tests/wayland/test_content_type.c | 122 ++++++++++++++++++++++++++++++++++
 7 files changed, 231 insertions(+)

diff --git a/src/bin/e_comp_wl.c b/src/bin/e_comp_wl.c
index 4641493cc..12a8afe38 100644
--- a/src/bin/e_comp_wl.c
+++ b/src/bin/e_comp_wl.c
@@ -1871,6 +1871,7 @@ _e_comp_wl_surface_state_commit(E_Client *ec, E_Comp_Wl_Surface_State *state)
    ec->comp_data->buffer_scale = state->buffer_scale;
    ec->comp_data->buffer_transform = state->buffer_transform;
    ec->comp_data->viewport = state->viewport;
+   ec->comp_data->content_type = state->content_type;
    if (ec->ignored && ec->comp_data->shell.surface)
      {
         EC_CHANGED(ec);
@@ -2856,6 +2857,7 @@ _e_comp_wl_subsurface_commit_to_cache(E_Client *ec)
    sdata->cached.buffer_scale = cdata->pending.buffer_scale;
    sdata->cached.buffer_transform = cdata->pending.buffer_transform;
    sdata->cached.viewport = cdata->pending.viewport;
+   sdata->cached.content_type = cdata->pending.content_type;
 
    if (cdata->pending.new_attach)
      {
@@ -3328,6 +3330,8 @@ _e_comp_wl_client_cb_del(void *data EINA_UNUSED, E_Client *ec)
      wl_resource_set_user_data(ec->comp_data->viewport_resource, NULL);
    if (ec->comp_data->fractional_scale_resource)
      wl_resource_set_user_data(ec->comp_data->fractional_scale_resource, NULL);
+   if (ec->comp_data->content_type_resource)
+     wl_resource_set_user_data(ec->comp_data->content_type_resource, NULL);
    _e_comp_wl_touch_points_drop(ec);
 
    /* remove sub list */
diff --git a/src/bin/e_comp_wl.h b/src/bin/e_comp_wl.h
index 6e18cfca5..e6e93d3b1 100644
--- a/src/bin/e_comp_wl.h
+++ b/src/bin/e_comp_wl.h
@@ -101,6 +101,7 @@ struct _E_Comp_Wl_Surface_State
    int buffer_scale;
    int buffer_transform;
    E_Comp_Wl_Viewport viewport;
+   int content_type;
    Eina_Bool new_attach E_BITFIELD;
    Eina_Bool has_data E_BITFIELD;
 };
@@ -195,6 +196,10 @@ typedef struct E_Comp_Wl_Extension_Data
      {
         struct wl_global *global;
      } wp_viewporter;
+   struct
+     {
+        struct wl_global *global;
+     } wp_content_type_manager_v1;
    struct
      {
         struct wl_global *global;
@@ -415,6 +420,10 @@ struct _E_Comp_Wl_Client_Data
     * most one of each. */
    struct wl_resource *viewport_resource;
    struct wl_resource *fractional_scale_resource;
+   /* wp_content_type_v1, at most one, and the type in effect. Only a hint:
+    * nothing in E acts on it yet. */
+   struct wl_resource *content_type_resource;
+   int content_type;
    /* The preferred_scale last sent on it, in 120ths. */
    int fractional_scale;
 
diff --git a/src/bin/e_comp_wl_extensions.c b/src/bin/e_comp_wl_extensions.c
index ae33c0994..3e86b7872 100644
--- a/src/bin/e_comp_wl_extensions.c
+++ b/src/bin/e_comp_wl_extensions.c
@@ -16,6 +16,7 @@
 #include "viewporter-server-protocol.h"
 #include "fractional-scale-v1-server-protocol.h"
 #include "single-pixel-buffer-v1-server-protocol.h"
+#include "content-type-v1-server-protocol.h"
 
 /* mutter uses 32, seems reasonable */
 #define HANDLE_LEN 32
@@ -1952,6 +1953,95 @@ static const struct wp_single_pixel_buffer_manager_v1_interface _e_wp_single_pix
    _e_wp_single_pixel_buffer_manager_v1_cb_create_u32_rgba_buffer,
 };
 
+/* wp_content_type_v1: a client says whether a surface shows a photo, a video
+ * or a game. Every use of the hint is optional; E keeps it for whatever comes
+ * to read it, a DRM backend setting the connector's "content type" for one. */
+
+static void
+_e_wp_content_type_v1_cb_destroy(struct wl_client *client EINA_UNUSED, struct wl_resource *resource)
+{
+   wl_resource_destroy(resource);
+}
+
+static void
+_e_wp_content_type_v1_cb_set_content_type(struct wl_client *client EINA_UNUSED, struct wl_resource *resource, uint32_t content_type)
+{
+   E_Client *ec = wl_resource_get_user_data(resource);
+
+   if ((!ec) || e_object_is_del(E_OBJECT(ec)) || (!ec->comp_data)) return;
+
+   if (content_type > WP_CONTENT_TYPE_V1_TYPE_GAME)
+     {
+        wl_resource_post_error(resource, WL_DISPLAY_ERROR_INVALID_METHOD,
+                               "content type %u is not a wp_content_type_v1.type",
+                               content_type);
+        return;
+     }
+
+   ec->comp_data->pending.content_type = (int)content_type;
+}
+
+static const struct wp_content_type_v1_interface _e_wp_content_type_v1_interface =
+{
+   _e_wp_content_type_v1_cb_destroy,
+   _e_wp_content_type_v1_cb_set_content_type,
+};
+
+static void
+_e_wp_content_type_v1_res_destroy(struct wl_resource *resource)
+{
+   E_Client *ec = wl_resource_get_user_data(resource);
+
+   if ((!ec) || e_object_is_del(E_OBJECT(ec)) || (!ec->comp_data)) return;
+   if (ec->comp_data->content_type_resource != resource) return;
+
+   ec->comp_data->content_type_resource = NULL;
+   /* Back to none, at the next commit like any other change. */
+   ec->comp_data->pending.content_type = WP_CONTENT_TYPE_V1_TYPE_NONE;
+}
+
+static void
+_e_wp_content_type_manager_v1_cb_destroy(struct wl_client *client EINA_UNUSED, struct wl_resource *resource)
+{
+   wl_resource_destroy(resource);
+}
+
+static void
+_e_wp_content_type_manager_v1_cb_get_surface_content_type(struct wl_client *client, struct wl_resource *resource, uint32_t id, struct wl_resource *surface)
+{
+   E_Client *ec;
+   struct wl_resource *res;
+
+   if (!(ec = wl_resource_get_user_data(surface))) return;
+   if (e_object_is_del(E_OBJECT(ec)) || (!ec->comp_data)) return;
+
+   if (ec->comp_data->content_type_resource)
+     {
+        wl_resource_post_error(resource,
+                               WP_CONTENT_TYPE_MANAGER_V1_ERROR_ALREADY_CONSTRUCTED,
+                               "wl_surface already has a wp_content_type_v1");
+        return;
+     }
+
+   res = wl_resource_create(client, &wp_content_type_v1_interface,
+                            wl_resource_get_version(resource), id);
+   if (!res)
+     {
+        wl_resource_post_no_memory(resource);
+        return;
+     }
+
+   wl_resource_set_implementation(res, &_e_wp_content_type_v1_interface, ec,
+                                  _e_wp_content_type_v1_res_destroy);
+   ec->comp_data->content_type_resource = res;
+}
+
+static const struct wp_content_type_manager_v1_interface _e_wp_content_type_manager_v1_interface =
+{
+   _e_wp_content_type_manager_v1_cb_destroy,
+   _e_wp_content_type_manager_v1_cb_get_surface_content_type,
+};
+
 #define GLOBAL_BIND_CB(NAME, IFACE, ...) \
 static void \
 _e_comp_wl_##NAME##_cb_bind(struct wl_client *client, void *data EINA_UNUSED, uint32_t version, uint32_t id) \
@@ -1983,6 +2073,7 @@ GLOBAL_BIND_CB(zwp_keyboard_shortcuts_inhibit_manager_v1, zwp_keyboard_shortcuts
 GLOBAL_BIND_CB(wp_viewporter, wp_viewporter_interface)
 GLOBAL_BIND_CB(wp_fractional_scale_manager_v1, wp_fractional_scale_manager_v1_interface)
 GLOBAL_BIND_CB(wp_single_pixel_buffer_manager_v1, wp_single_pixel_buffer_manager_v1_interface)
+GLOBAL_BIND_CB(wp_content_type_manager_v1, wp_content_type_manager_v1_interface)
 GLOBAL_BIND_CB(wp_presentation, wp_presentation_interface,
      wp_presentation_send_clock_id(res, CLOCK_MONOTONIC);
 )
@@ -2093,6 +2184,7 @@ e_comp_wl_extensions_init(void)
    GLOBAL_CREATE_OR_RETURN(wp_viewporter, wp_viewporter_interface, 1);
    GLOBAL_CREATE_OR_RETURN(wp_fractional_scale_manager_v1, wp_fractional_scale_manager_v1_interface, 1);
    GLOBAL_CREATE_OR_RETURN(wp_single_pixel_buffer_manager_v1, wp_single_pixel_buffer_manager_v1_interface, 1);
+   GLOBAL_CREATE_OR_RETURN(wp_content_type_manager_v1, wp_content_type_manager_v1_interface, 1);
    if (!e_comp_wl_text_input_init()) return EINA_FALSE;
    e_comp_wl_privileges_init();
 
diff --git a/src/bin/generated/meson.build b/src/bin/generated/meson.build
index 19098ec33..78bfd51d2 100644
--- a/src/bin/generated/meson.build
+++ b/src/bin/generated/meson.build
@@ -13,6 +13,7 @@ protos = [
   '@0@/stable/viewporter/viewporter.xml'.format(dir_wayland_protocols),
   '@0@/staging/fractional-scale/fractional-scale-v1.xml'.format(dir_wayland_protocols),
   '@0@/staging/single-pixel-buffer/single-pixel-buffer-v1.xml'.format(dir_wayland_protocols),
+  '@0@/staging/content-type/content-type-v1.xml'.format(dir_wayland_protocols),
   '@0@/unstable/keyboard-shortcuts-inhibit/keyboard-shortcuts-inhibit-unstable-v1.xml'.format(dir_wayland_protocols),
   '@0@/unstable/idle-inhibit/idle-inhibit-unstable-v1.xml'.format(dir_wayland_protocols),
   '@0@/unstable/primary-selection/primary-selection-unstable-v1.xml'.format(dir_wayland_protocols),
diff --git a/src/tests/wayland/globals.expected b/src/tests/wayland/globals.expected
index 9cb0f25e5..18349bd2b 100644
--- a/src/tests/wayland/globals.expected
+++ b/src/tests/wayland/globals.expected
@@ -7,6 +7,7 @@ wl_seat	8
 wl_shell	1
 wl_shm	>=1
 wl_subcompositor	1
+wp_content_type_manager_v1	1
 wp_fractional_scale_manager_v1	1
 wp_presentation	1
 wp_single_pixel_buffer_manager_v1	1
diff --git a/src/tests/wayland/meson.build b/src/tests/wayland/meson.build
index 238824473..d7f6e990f 100644
--- a/src/tests/wayland/meson.build
+++ b/src/tests/wayland/meson.build
@@ -35,6 +35,7 @@ foreach p: [
   '@0@/stable/viewporter/viewporter.xml'.format(dir_wayland_protocols),
   '@0@/staging/fractional-scale/fractional-scale-v1.xml'.format(dir_wayland_protocols),
   '@0@/staging/single-pixel-buffer/single-pixel-buffer-v1.xml'.format(dir_wayland_protocols),
+  '@0@/staging/content-type/content-type-v1.xml'.format(dir_wayland_protocols),
   '@0@/staging/xdg-toplevel-drag/xdg-toplevel-drag-v1.xml'.format(dir_wayland_protocols),
   '@0@/unstable/keyboard-shortcuts-inhibit/keyboard-shortcuts-inhibit-unstable-v1.xml'.format(dir_wayland_protocols),
   '@0@/unstable/idle-inhibit/idle-inhibit-unstable-v1.xml'.format(dir_wayland_protocols),
@@ -119,6 +120,7 @@ wl_protocol_tests = [
    {'ELM_TRANSITION_DURATION_FACTOR': '4'}],
   ['format-alpha', 'test_format_alpha.c'],
   ['dmabuf-feedback', 'test_dmabuf_feedback.c'],
+  ['content-type', 'test_content_type.c'],
 ]
 
 tk_src = files('e_wl_testkit.c')
diff --git a/src/tests/wayland/test_content_type.c b/src/tests/wayland/test_content_type.c
new file mode 100644
index 000000000..a53ca1a06
--- /dev/null
+++ b/src/tests/wayland/test_content_type.c
@@ -0,0 +1,122 @@
+/* wp_content_type_v1: a client saying what kind of thing it is showing.
+ *
+ * E stores the hint and acts on none of it, so what a client can see go wrong
+ * is the protocol around it:
+ *
+ *   * every value of the enum is accepted, and the object can be destroyed
+ *     and made again - destroying it means "back to none", so the surface
+ *     must be free to get another;
+ *   * the object outliving its surface is harmless;
+ *   * a second object on one surface is already_constructed;
+ *   * a value outside the enum is refused.
+ *
+ * A protocol error ends the connection, so each error case has its own.
+ */
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "e_wl_testkit.h"
+#include "content-type-v1-client-protocol.h"
+
+#define PROG "test-content-type"
+#define APP_ID "content-type"
+
+static struct wp_content_type_manager_v1 *
+_manager_get(Tk *tk)
+{
+   if (tk_global_version(tk, "wp_content_type_manager_v1") < 1)
+     tk_fail(tk, "no wp_content_type_manager_v1");
+   return tk_bind(tk, &wp_content_type_manager_v1_interface, 1);
+}
+
+static void
+_error_expect(Tk *tk, const struct wl_interface *iface, int code,
+              const char *what)
+{
+   const struct wl_interface *got = NULL;
+   int err;
+
+   err = tk_protocol_error(tk, &got);
+   if (err < 0) tk_fail(tk, "%s was accepted", what);
+   if ((err != code) || (got != iface))
+     tk_fail(tk, "%s: error %d on %s, wanted %d on %s", what, err,
+             got ? got->name : "nothing", code, iface->name);
+   printf(PROG ": %s is refused\n", what);
+}
+
+int
+main(void)
+{
+   static const uint32_t types[] =
+     {
+        WP_CONTENT_TYPE_V1_TYPE_NONE,
+        WP_CONTENT_TYPE_V1_TYPE_PHOTO,
+        WP_CONTENT_TYPE_V1_TYPE_VIDEO,
+        WP_CONTENT_TYPE_V1_TYPE_GAME,
+     };
+   struct wp_content_type_manager_v1 *mgr;
+   struct wp_content_type_v1 *ct;
+   struct wl_surface *surface;
+   Tk_Toplevel *top;
+   unsigned int i;
+   Tk *tk;
+
+   tk = tk_connect(PROG);
+   mgr = _manager_get(tk);
+   top = tk_toplevel_new(tk, APP_ID, "content type", 200, 150);
+   tk_settle(tk);
+   tk_expect(tk, APP_ID);
+   surface = tk_toplevel_surface(top);
+   for (i = 0; i < sizeof(types) / sizeof(types[0]); i++)
+     {
+        ct = wp_content_type_manager_v1_get_surface_content_type(mgr, surface);
+        wp_content_type_v1_set_content_type(ct, types[i]);
+        wl_surface_commit(surface);
+        if (tk_protocol_error(tk, NULL) >= 0)
+          tk_fail(tk, "content type %u was refused", types[i]);
+        wp_content_type_v1_destroy(ct);
+        wl_surface_commit(surface);
+        if (tk_protocol_error(tk, NULL) >= 0)
+          tk_fail(tk, "destroying the object for type %u failed", types[i]);
+     }
+   printf(PROG ": every type is accepted, and the object can be made again\n");
+
+   ct = wp_content_type_manager_v1_get_surface_content_type(mgr, surface);
+   wp_content_type_v1_set_content_type(ct, WP_CONTENT_TYPE_V1_TYPE_VIDEO);
+   wl_surface_commit(surface);
+   tk_toplevel_del(top);
+   tk_sync(tk);
+   wp_content_type_v1_set_content_type(ct, WP_CONTENT_TYPE_V1_TYPE_GAME);
+   wp_content_type_v1_destroy(ct);
+   if (tk_protocol_error(tk, NULL) >= 0)
+     tk_fail(tk, "an object that outlived its surface was refused");
+   tk_sync(tk);
+   printf(PROG ": an object outliving its surface is inert\n");
+   tk_disconnect(tk);
+
+   tk = tk_connect(PROG);
+   mgr = _manager_get(tk);
+   top = tk_toplevel_new(tk, APP_ID, "content type", 200, 150);
+   tk_settle(tk);
+   surface = tk_toplevel_surface(top);
+   wp_content_type_manager_v1_get_surface_content_type(mgr, surface);
+   wp_content_type_manager_v1_get_surface_content_type(mgr, surface);
+   _error_expect(tk, &wp_content_type_manager_v1_interface,
+                 WP_CONTENT_TYPE_MANAGER_V1_ERROR_ALREADY_CONSTRUCTED,
+                 "a second object on one surface");
+   tk_disconnect(tk);
+
+   tk = tk_connect(PROG);
+   mgr = _manager_get(tk);
+   top = tk_toplevel_new(tk, APP_ID, "content type", 200, 150);
+   tk_settle(tk);
+   ct = wp_content_type_manager_v1_get_surface_content_type
+     (mgr, tk_toplevel_surface(top));
+   wp_content_type_v1_set_content_type(ct, WP_CONTENT_TYPE_V1_TYPE_GAME + 1);
+   _error_expect(tk, &wp_content_type_v1_interface,
+                 WL_DISPLAY_ERROR_INVALID_METHOD, "a type outside the enum");
+   tk_disconnect(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