From dbf10ebdf1e785ea63c9b1c346fccb3d55ab97ac Mon Sep 17 00:00:00 2001 From: Alexander Orzechowski Date: Sat, 24 Feb 2024 08:35:56 -0500 Subject: [PATCH] wlr_raster: Introduce invalidated signal If this raster becomes invalid meaning that the buffer neither has a buffer or textures. The invalidated signal will be called to signify to its owner that it should be recreated. --- include/wlr/types/wlr_raster.h | 2 ++ types/wlr_raster.c | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/include/wlr/types/wlr_raster.h b/include/wlr/types/wlr_raster.h index 2857dbe3f..c37d49c0b 100644 --- a/include/wlr/types/wlr_raster.h +++ b/include/wlr/types/wlr_raster.h @@ -23,6 +23,7 @@ struct wlr_allocator; struct wlr_raster_source { struct wlr_texture *texture; struct wlr_allocator *allocator; // may be NULL + struct wlr_raster *raster; struct wl_list link; struct wl_listener renderer_destroy; @@ -43,6 +44,7 @@ struct wlr_raster { struct { struct wl_signal destroy; + struct wl_signal invalidated; } events; // private state diff --git a/types/wlr_raster.c b/types/wlr_raster.c index 86303415a..1cf540976 100644 --- a/types/wlr_raster.c +++ b/types/wlr_raster.c @@ -23,6 +23,10 @@ static void raster_handle_buffer_release(struct wl_listener *listener, void *dat raster->buffer = NULL; wl_list_remove(&raster->buffer_release.link); wl_list_init(&raster->buffer_release.link); + + if (wl_list_empty(&raster->sources)) { + wl_signal_emit_mutable(&raster->events.invalidated, NULL); + } } struct wlr_raster *wlr_raster_create(struct wlr_buffer *buffer, @@ -34,6 +38,7 @@ struct wlr_raster *wlr_raster_create(struct wlr_buffer *buffer, wl_list_init(&raster->sources); wl_signal_init(&raster->events.destroy); + wl_signal_init(&raster->events.invalidated); assert(buffer); raster->opaque = buffer_is_opaque(buffer); @@ -58,6 +63,11 @@ static void raster_source_destroy(struct wlr_raster_source *source) { wl_list_remove(&source->link); wl_list_remove(&source->renderer_destroy.link); wl_list_remove(&source->allocator_destroy.link); + + if (!source->raster->buffer && wl_list_empty(&source->raster->sources)) { + wl_signal_emit_mutable(&source->raster->events.invalidated, NULL); + } + free(source); } @@ -68,6 +78,9 @@ static void raster_consider_destroy(struct wlr_raster *raster) { wl_signal_emit_mutable(&raster->events.destroy, NULL); + // we don't want to call invalidation signals as we're destroying the raster + wl_signal_init(&raster->events.invalidated); + struct wlr_raster_source *source, *source_tmp; wl_list_for_each_safe(source, source_tmp, &raster->sources, link) { wlr_texture_destroy(source->texture); @@ -150,6 +163,7 @@ static void raster_attach_with_allocator(struct wlr_raster *raster, wl_list_insert(&raster->sources, &source->link); source->texture = texture; source->allocator = allocator; + source->raster = raster; } static struct wlr_texture *wlr_raster_get_texture(struct wlr_raster *raster,