From f0d8377732333f44f6e366ee22b3c3e4b1285817 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Thu, 14 Mar 2024 13:52:09 +0100 Subject: [PATCH] output: listen to renderer destroy in wlr_output_cursor When a renderer is destroyed, so are all textures. Reset the texture in that case. --- include/wlr/types/wlr_output.h | 1 + types/output/cursor.c | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/include/wlr/types/wlr_output.h b/include/wlr/types/wlr_output.h index 865bc5e5..d349f8ff 100644 --- a/include/wlr/types/wlr_output.h +++ b/include/wlr/types/wlr_output.h @@ -45,6 +45,7 @@ struct wlr_output_cursor { int32_t hotspot_x, hotspot_y; struct wlr_texture *texture; bool own_texture; + struct wl_listener renderer_destroy; struct wl_list link; }; diff --git a/types/output/cursor.c b/types/output/cursor.c index 6c2ba4c4..22654b0a 100644 --- a/types/output/cursor.c +++ b/types/output/cursor.c @@ -334,6 +334,13 @@ bool wlr_output_cursor_set_buffer(struct wlr_output_cursor *cursor, dst_width, dst_height, WL_OUTPUT_TRANSFORM_NORMAL, hotspot_x, hotspot_y); } +static void output_cursor_handle_renderer_destroy(struct wl_listener *listener, + void *data) { + struct wlr_output_cursor *cursor = wl_container_of(listener, cursor, renderer_destroy); + output_cursor_set_texture(cursor, NULL, false, NULL, 0, 0, + WL_OUTPUT_TRANSFORM_NORMAL, 0, 0); +} + bool output_cursor_set_texture(struct wlr_output_cursor *cursor, struct wlr_texture *texture, bool own_texture, const struct wlr_fbox *src_box, int dst_width, int dst_height, enum wl_output_transform transform, @@ -364,6 +371,14 @@ bool output_cursor_set_texture(struct wlr_output_cursor *cursor, cursor->texture = texture; cursor->own_texture = own_texture; + wl_list_remove(&cursor->renderer_destroy.link); + if (texture != NULL) { + cursor->renderer_destroy.notify = output_cursor_handle_renderer_destroy; + wl_signal_add(&texture->renderer->events.destroy, &cursor->renderer_destroy); + } else { + wl_list_init(&cursor->renderer_destroy.link); + } + if (output_cursor_attempt_hardware(cursor)) { return true; } @@ -415,6 +430,7 @@ struct wlr_output_cursor *wlr_output_cursor_create(struct wlr_output *output) { cursor->output = output; wl_list_insert(&output->cursors, &cursor->link); cursor->visible = true; // default position is at (0, 0) + wl_list_init(&cursor->renderer_destroy.link); return cursor; } @@ -428,6 +444,7 @@ void wlr_output_cursor_destroy(struct wlr_output_cursor *cursor) { output_set_hardware_cursor(cursor->output, NULL, 0, 0); cursor->output->hardware_cursor = NULL; } + wl_list_remove(&cursor->renderer_destroy.link); if (cursor->own_texture) { wlr_texture_destroy(cursor->texture); }