diff --git a/include/wlr/types/wlr_buffer.h b/include/wlr/types/wlr_buffer.h index b24c0ccd..bb0444bf 100644 --- a/include/wlr/types/wlr_buffer.h +++ b/include/wlr/types/wlr_buffer.h @@ -151,6 +151,8 @@ struct wlr_client_buffer { // private state struct wl_listener source_destroy; + + size_t n_ignore_locks; }; /** diff --git a/types/buffer/client.c b/types/buffer/client.c index 50c19691..6bcda941 100644 --- a/types/buffer/client.c +++ b/types/buffer/client.c @@ -84,7 +84,7 @@ struct wlr_client_buffer *wlr_client_buffer_create(struct wlr_buffer *buffer, bool wlr_client_buffer_apply_damage(struct wlr_client_buffer *client_buffer, struct wlr_buffer *next, pixman_region32_t *damage) { - if (client_buffer->base.n_locks > 1) { + if (client_buffer->base.n_locks - client_buffer->n_ignore_locks > 1) { // Someone else still has a reference to the buffer return false; } diff --git a/types/scene/surface.c b/types/scene/surface.c index f8bb5538..553cc421 100644 --- a/types/scene/surface.c +++ b/types/scene/surface.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -55,6 +56,28 @@ static void scene_surface_handle_surface_destroy( wlr_scene_node_destroy(&surface->buffer->node); } +// This is used for wlr_scene where it unconditionally locks buffers preventing +// reuse of the existing texture for shm clients. With the usage pattern of +// wlr_scene surface handling, we can mark its locked buffer as safe +// for mutation. +static void client_buffer_mark_next_can_damage(struct wlr_client_buffer *buffer) { + buffer->n_ignore_locks++; +} + +static void scene_buffer_unmark_client_buffer(struct wlr_scene_buffer *scene_buffer) { + if (!scene_buffer->buffer) { + return; + } + + struct wlr_client_buffer *buffer = wlr_client_buffer_get(scene_buffer->buffer); + if (!buffer) { + return; + } + + assert(buffer->n_ignore_locks > 0); + buffer->n_ignore_locks--; +} + static void set_buffer_with_surface_state(struct wlr_scene_buffer *scene_buffer, struct wlr_surface *surface) { struct wlr_surface_state *state = &surface->current; @@ -68,7 +91,11 @@ static void set_buffer_with_surface_state(struct wlr_scene_buffer *scene_buffer, wlr_scene_buffer_set_dest_size(scene_buffer, state->width, state->height); wlr_scene_buffer_set_transform(scene_buffer, state->transform); + scene_buffer_unmark_client_buffer(scene_buffer); + if (surface->buffer) { + client_buffer_mark_next_can_damage(surface->buffer); + wlr_scene_buffer_set_buffer_with_damage(scene_buffer, &surface->buffer->base, &surface->buffer_damage); } else { @@ -109,6 +136,8 @@ static bool scene_buffer_point_accepts_input(struct wlr_scene_buffer *scene_buff static void surface_addon_destroy(struct wlr_addon *addon) { struct wlr_scene_surface *surface = wl_container_of(addon, surface, addon); + scene_buffer_unmark_client_buffer(surface->buffer); + wlr_addon_finish(&surface->addon); wl_list_remove(&surface->output_enter.link);