From 4c1afb126b9a49aee367276f634f8686428d6147 Mon Sep 17 00:00:00 2001 From: Isaac Freund Date: Thu, 30 Jun 2022 14:01:46 +0200 Subject: [PATCH] wlr-output-management: Implement version 3 release requests Head/mode resources older than version 3 and lacking a release request are intentionally leaked as this is the only way to fix the race. Implements: https://gitlab.freedesktop.org/wlroots/wlr-protocols/-/merge_requests/114 --- .../wlr-output-management-unstable-v1.xml | 47 +++++++++++++------ types/wlr_output_management_v1.c | 37 ++++++++++++--- 2 files changed, 63 insertions(+), 21 deletions(-) diff --git a/protocol/wlr-output-management-unstable-v1.xml b/protocol/wlr-output-management-unstable-v1.xml index cadc45fb..3568e04c 100644 --- a/protocol/wlr-output-management-unstable-v1.xml +++ b/protocol/wlr-output-management-unstable-v1.xml @@ -39,7 +39,7 @@ interface version number is reset. - + This interface is a manager that allows reading and writing the current output device configuration. @@ -115,7 +115,7 @@ - + This event indicates that the compositor is done sending manager events. The compositor will destroy the object immediately after sending this @@ -125,7 +125,7 @@ - + A head is an output device. The difference between a wl_output object and a head is that heads are advertised even if they are turned off. A head @@ -251,14 +251,15 @@ - - The compositor will destroy the object immediately after sending this - event, so it will become invalid and the client should release any - resources associated with it. + + This event indicates that the head is no longer available. The head + object becomes inert. Clients should send a destroy request and release + any resources associated with it. + This event describes the manufacturer of the head. @@ -328,9 +329,18 @@ + + + + + + This request indicates that the client will no longer use this head + object. + + - + This object describes an output mode. @@ -368,15 +378,24 @@ - - The compositor will destroy the object immediately after sending this - event, so it will become invalid and the client should release any - resources associated with it. + + This event indicates that the mode is no longer available. The mode + object becomes inert. Clients should send a destroy request and release + any resources associated with it. + + + + + + This request indicates that the client will no longer use this mode + object. + + - + This object is used by the client to describe a full output configuration. @@ -494,7 +513,7 @@ - + This object is used by the client to update a single head's configuration. diff --git a/types/wlr_output_management_v1.c b/types/wlr_output_management_v1.c index 64eff211..f7ac5dcf 100644 --- a/types/wlr_output_management_v1.c +++ b/types/wlr_output_management_v1.c @@ -5,7 +5,7 @@ #include #include "wlr-output-management-unstable-v1-protocol.h" -#define OUTPUT_MANAGER_VERSION 2 +#define OUTPUT_MANAGER_VERSION 3 enum { HEAD_STATE_ENABLED = 1 << 0, @@ -27,6 +27,7 @@ static struct wlr_output_head_v1 *head_from_resource( return wl_resource_get_user_data(resource); } +// Can return NULL if the mode is inert static struct wlr_output_mode *mode_from_resource( struct wl_resource *resource) { assert(wl_resource_instance_of(resource, @@ -41,11 +42,15 @@ static void head_destroy(struct wlr_output_head_v1 *head) { struct wl_resource *resource, *tmp; wl_resource_for_each_safe(resource, tmp, &head->mode_resources) { zwlr_output_mode_v1_send_finished(resource); - wl_resource_destroy(resource); + wl_list_remove(wl_resource_get_link(resource)); + wl_list_init(wl_resource_get_link(resource)); + wl_resource_set_user_data(resource, NULL); } wl_resource_for_each_safe(resource, tmp, &head->resources) { zwlr_output_head_v1_send_finished(resource); - wl_resource_destroy(resource); + wl_list_remove(wl_resource_get_link(resource)); + wl_list_init(wl_resource_get_link(resource)); + wl_resource_set_user_data(resource, NULL); } wl_list_remove(&head->link); wl_list_remove(&head->output_destroy.link); @@ -648,10 +653,19 @@ static void send_mode_state(struct wl_resource *mode_resource, } } -static void mode_handle_resource_destroy(struct wl_resource *resource) { +static void output_mode_handle_resource_destroy(struct wl_resource *resource) { wl_list_remove(wl_resource_get_link(resource)); } +static void output_mode_handle_release(struct wl_client *client, + struct wl_resource *resource) { + wl_resource_destroy(resource); +} + +static const struct zwlr_output_mode_v1_interface output_mode_impl = { + .release = output_mode_handle_release, +}; + static struct wl_resource *head_send_mode(struct wlr_output_head_v1 *head, struct wl_resource *head_resource, struct wlr_output_mode *mode) { struct wl_client *client = wl_resource_get_client(head_resource); @@ -662,8 +676,8 @@ static struct wl_resource *head_send_mode(struct wlr_output_head_v1 *head, wl_resource_post_no_memory(head_resource); return NULL; } - wl_resource_set_implementation(mode_resource, NULL, mode, - mode_handle_resource_destroy); + wl_resource_set_implementation(mode_resource, &output_mode_impl, mode, + output_mode_handle_resource_destroy); wl_list_insert(&head->mode_resources, wl_resource_get_link(mode_resource)); zwlr_output_head_v1_send_mode(head_resource, mode_resource); @@ -739,6 +753,15 @@ static void head_handle_resource_destroy(struct wl_resource *resource) { wl_list_remove(wl_resource_get_link(resource)); } +static void head_handle_release(struct wl_client *client, + struct wl_resource *resource) { + wl_resource_destroy(resource); +} + +static const struct zwlr_output_head_v1_interface head_impl = { + .release = head_handle_release, +}; + static void manager_send_head(struct wlr_output_manager_v1 *manager, struct wlr_output_head_v1 *head, struct wl_resource *manager_resource) { struct wlr_output *output = head->state.output; @@ -751,7 +774,7 @@ static void manager_send_head(struct wlr_output_manager_v1 *manager, wl_resource_post_no_memory(manager_resource); return; } - wl_resource_set_implementation(head_resource, NULL, head, + wl_resource_set_implementation(head_resource, &head_impl, head, head_handle_resource_destroy); wl_list_insert(&head->resources, wl_resource_get_link(head_resource));