screencopy: make frame resource inert after copy

This commit is contained in:
emersion 2018-06-23 18:55:37 +01:00
parent c421700f3d
commit 9aaa9ba477
No known key found for this signature in database
GPG key ID: 0FDE7BE0E88F5E48

View file

@ -17,6 +17,17 @@ static struct wlr_screencopy_frame_v1 *frame_from_resource(
return wl_resource_get_user_data(resource); return wl_resource_get_user_data(resource);
} }
static void frame_destroy(struct wlr_screencopy_frame_v1 *frame) {
if (frame == NULL) {
return;
}
wl_list_remove(&frame->link);
wl_list_remove(&frame->output_swap_buffers.link);
// Make the frame resource inert
wl_resource_set_user_data(frame->resource, NULL);
free(frame);
}
static void frame_handle_output_swap_buffers(struct wl_listener *listener, static void frame_handle_output_swap_buffers(struct wl_listener *listener,
void *_data) { void *_data) {
struct wlr_screencopy_frame_v1 *frame = struct wlr_screencopy_frame_v1 *frame =
@ -48,6 +59,7 @@ static void frame_handle_output_swap_buffers(struct wl_listener *listener,
if (!ok) { if (!ok) {
zwlr_screencopy_frame_v1_send_failed(frame->resource); zwlr_screencopy_frame_v1_send_failed(frame->resource);
frame_destroy(frame);
return; return;
} }
@ -58,13 +70,17 @@ static void frame_handle_output_swap_buffers(struct wl_listener *listener,
zwlr_screencopy_frame_v1_send_ready(frame->resource, zwlr_screencopy_frame_v1_send_ready(frame->resource,
tv_sec_hi, tv_sec_lo, event->when->tv_nsec); tv_sec_hi, tv_sec_lo, event->when->tv_nsec);
// TODO: make frame resource inert frame_destroy(frame);
} }
static void frame_handle_copy(struct wl_client *client, static void frame_handle_copy(struct wl_client *client,
struct wl_resource *frame_resource, struct wl_resource *frame_resource,
struct wl_resource *buffer_resource) { struct wl_resource *buffer_resource) {
struct wlr_screencopy_frame_v1 *frame = frame_from_resource(frame_resource); struct wlr_screencopy_frame_v1 *frame = frame_from_resource(frame_resource);
if (frame == NULL) {
return;
}
struct wlr_output *output = frame->output; struct wlr_output *output = frame->output;
struct wl_shm_buffer *buffer = wl_shm_buffer_get(buffer_resource); struct wl_shm_buffer *buffer = wl_shm_buffer_get(buffer_resource);
@ -119,9 +135,7 @@ static const struct zwlr_screencopy_frame_v1_interface frame_impl = {
static void frame_handle_resource_destroy(struct wl_resource *frame_resource) { static void frame_handle_resource_destroy(struct wl_resource *frame_resource) {
struct wlr_screencopy_frame_v1 *frame = frame_from_resource(frame_resource); struct wlr_screencopy_frame_v1 *frame = frame_from_resource(frame_resource);
wl_list_remove(&frame->link); frame_destroy(frame);
wl_list_remove(&frame->output_swap_buffers.link);
free(frame);
} }