screencopy: listen to buffer destroy

This commit is contained in:
emersion 2018-06-23 19:06:10 +01:00
parent 9aaa9ba477
commit dbb01cbcd0
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48
2 changed files with 13 additions and 2 deletions

View File

@ -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;

View File

@ -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,