buffer: listen to renderer destroy in wlr_client_buffer

When a renderer is destroyed, so are all textures. Reset the
texture in that case.
This commit is contained in:
Simon Ser 2024-03-14 13:51:01 +01:00
parent 5bef385ffc
commit 9e3576426d
2 changed files with 17 additions and 0 deletions

View File

@ -151,6 +151,7 @@ struct wlr_client_buffer {
// private state // private state
struct wl_listener source_destroy; struct wl_listener source_destroy;
struct wl_listener renderer_destroy;
size_t n_ignore_locks; size_t n_ignore_locks;
}; };

View File

@ -25,6 +25,7 @@ static struct wlr_client_buffer *client_buffer_from_buffer(
static void client_buffer_destroy(struct wlr_buffer *buffer) { static void client_buffer_destroy(struct wlr_buffer *buffer) {
struct wlr_client_buffer *client_buffer = client_buffer_from_buffer(buffer); struct wlr_client_buffer *client_buffer = client_buffer_from_buffer(buffer);
wl_list_remove(&client_buffer->source_destroy.link); wl_list_remove(&client_buffer->source_destroy.link);
wl_list_remove(&client_buffer->renderer_destroy.link);
wlr_texture_destroy(client_buffer->texture); wlr_texture_destroy(client_buffer->texture);
free(client_buffer); free(client_buffer);
} }
@ -54,6 +55,15 @@ static void client_buffer_handle_source_destroy(struct wl_listener *listener,
client_buffer->source = NULL; client_buffer->source = NULL;
} }
static void client_buffer_handle_renderer_destroy(struct wl_listener *listener,
void *data) {
struct wlr_client_buffer *client_buffer =
wl_container_of(listener, client_buffer, renderer_destroy);
wl_list_remove(&client_buffer->renderer_destroy.link);
wl_list_init(&client_buffer->renderer_destroy.link);
client_buffer->texture = NULL;
}
struct wlr_client_buffer *wlr_client_buffer_create(struct wlr_buffer *buffer, struct wlr_client_buffer *wlr_client_buffer_create(struct wlr_buffer *buffer,
struct wlr_renderer *renderer) { struct wlr_renderer *renderer) {
struct wlr_texture *texture = wlr_texture_from_buffer(renderer, buffer); struct wlr_texture *texture = wlr_texture_from_buffer(renderer, buffer);
@ -75,6 +85,9 @@ struct wlr_client_buffer *wlr_client_buffer_create(struct wlr_buffer *buffer,
wl_signal_add(&buffer->events.destroy, &client_buffer->source_destroy); wl_signal_add(&buffer->events.destroy, &client_buffer->source_destroy);
client_buffer->source_destroy.notify = client_buffer_handle_source_destroy; client_buffer->source_destroy.notify = client_buffer_handle_source_destroy;
wl_signal_add(&texture->renderer->events.destroy, &client_buffer->renderer_destroy);
client_buffer->renderer_destroy.notify = client_buffer_handle_renderer_destroy;
// Ensure the buffer will be released before being destroyed // Ensure the buffer will be released before being destroyed
wlr_buffer_lock(&client_buffer->base); wlr_buffer_lock(&client_buffer->base);
wlr_buffer_drop(&client_buffer->base); wlr_buffer_drop(&client_buffer->base);
@ -88,6 +101,9 @@ bool wlr_client_buffer_apply_damage(struct wlr_client_buffer *client_buffer,
// Someone else still has a reference to the buffer // Someone else still has a reference to the buffer
return false; return false;
} }
if (client_buffer->texture == NULL) {
return false;
}
return wlr_texture_update_from_buffer(client_buffer->texture, next, damage); return wlr_texture_update_from_buffer(client_buffer->texture, next, damage);
} }