From dbb01cbcd01d191e406d99d2837c84a9d73d34a0 Mon Sep 17 00:00:00 2001 From: emersion Date: Sat, 23 Jun 2018 19:06:10 +0100 Subject: screencopy: listen to buffer destroy --- include/wlr/types/wlr_screencopy_v1.h | 1 + types/wlr_screencopy_v1.c | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/include/wlr/types/wlr_screencopy_v1.h b/include/wlr/types/wlr_screencopy_v1.h index 69f62437..892687aa 100644 --- a/include/wlr/types/wlr_screencopy_v1.h +++ b/include/wlr/types/wlr_screencopy_v1.h @@ -23,6 +23,7 @@ struct wlr_screencopy_frame_v1 { int stride; struct wl_shm_buffer *buffer; + struct wl_listener buffer_destroy; struct wlr_output *output; struct wl_listener output_swap_buffers; diff --git a/types/wlr_screencopy_v1.c b/types/wlr_screencopy_v1.c index c897e41e..0760eaaf 100644 --- a/types/wlr_screencopy_v1.c +++ b/types/wlr_screencopy_v1.c @@ -23,6 +23,7 @@ static void frame_destroy(struct wlr_screencopy_frame_v1 *frame) { } wl_list_remove(&frame->link); wl_list_remove(&frame->output_swap_buffers.link); + wl_list_remove(&frame->buffer_destroy.link); // Make the frame resource inert wl_resource_set_user_data(frame->resource, NULL); free(frame); @@ -73,6 +74,14 @@ static void frame_handle_output_swap_buffers(struct wl_listener *listener, frame_destroy(frame); } +static void frame_handle_buffer_destroy(struct wl_listener *listener, + void *data) { + struct wlr_screencopy_frame_v1 *frame = + wl_container_of(listener, frame, buffer_destroy); + zwlr_screencopy_frame_v1_send_failed(frame->resource); + frame_destroy(frame); +} + static void frame_handle_copy(struct wl_client *client, struct wl_resource *frame_resource, struct wl_resource *buffer_resource) { @@ -116,11 +125,12 @@ static void frame_handle_copy(struct wl_client *client, wl_signal_add(&output->events.swap_buffers, &frame->output_swap_buffers); frame->output_swap_buffers.notify = frame_handle_output_swap_buffers; + wl_resource_add_destroy_listener(buffer_resource, &frame->buffer_destroy); + frame->buffer_destroy.notify = frame_handle_buffer_destroy; + // Schedule a buffer swap output->needs_swap = true; wlr_output_schedule_frame(output); - - // TODO: listen to buffer destroy } static void frame_handle_destroy(struct wl_client *client, -- cgit v1.2.3