export-dmabuf: wait for the frame to be ready, send timestamp

This commit is contained in:
emersion 2018-05-23 09:02:19 +01:00
parent 5ba1a9af56
commit e26f4dff98
No known key found for this signature in database
GPG key ID: 0FDE7BE0E88F5E48
4 changed files with 34 additions and 6 deletions

View file

@ -11,6 +11,8 @@ struct wlr_export_dmabuf_frame_v1 {
struct wl_list link; struct wl_list link;
struct wlr_output *output; struct wlr_output *output;
struct wl_listener output_swap_buffers;
}; };
struct wlr_export_dmabuf_manager_v1 { struct wlr_export_dmabuf_manager_v1 {

View file

@ -82,7 +82,7 @@ struct wlr_output {
struct { struct {
struct wl_signal frame; struct wl_signal frame;
struct wl_signal needs_swap; struct wl_signal needs_swap;
struct wl_signal swap_buffers; struct wl_signal swap_buffers; // wlr_output_event_swap_buffers
struct wl_signal enable; struct wl_signal enable;
struct wl_signal mode; struct wl_signal mode;
struct wl_signal scale; struct wl_signal scale;
@ -108,6 +108,12 @@ struct wlr_output {
void *data; void *data;
}; };
struct wlr_output_event_swap_buffers {
struct wlr_output *output;
struct timespec *when;
pixman_region32_t *damage;
};
struct wlr_surface; struct wlr_surface;
void wlr_output_enable(struct wlr_output *output, bool enable); void wlr_output_enable(struct wlr_output *output, bool enable);

View file

@ -30,9 +30,25 @@ static const struct zwlr_export_dmabuf_frame_v1_interface frame_impl = {
static void frame_handle_resource_destroy(struct wl_resource *resource) { static void frame_handle_resource_destroy(struct wl_resource *resource) {
struct wlr_export_dmabuf_frame_v1 *frame = frame_from_resource(resource); struct wlr_export_dmabuf_frame_v1 *frame = frame_from_resource(resource);
wl_list_remove(&frame->link); wl_list_remove(&frame->link);
wl_list_remove(&frame->output_swap_buffers.link);
free(frame); free(frame);
} }
static void frame_output_handle_swap_buffers(struct wl_listener *listener,
void *data) {
struct wlr_export_dmabuf_frame_v1 *frame =
wl_container_of(listener, frame, output_swap_buffers);
struct wlr_output_event_swap_buffers *event = data;
wl_list_remove(&frame->output_swap_buffers.link);
wl_list_init(&frame->output_swap_buffers.link);
uint32_t tv_sec_hi = event->when->tv_sec << 32;
uint32_t tv_sec_lo = event->when->tv_sec & 0xFFFFFFFF;
zwlr_export_dmabuf_frame_v1_send_ready(frame->resource,
tv_sec_hi, tv_sec_lo, event->when->tv_nsec);
}
static const struct zwlr_export_dmabuf_manager_v1_interface manager_impl; static const struct zwlr_export_dmabuf_manager_v1_interface manager_impl;
@ -87,7 +103,7 @@ static void manager_handle_capture_output(struct wl_client *client,
uint32_t frame_flags = 0; uint32_t frame_flags = 0;
uint32_t mod_high = attribs.modifier[0] >> 32; uint32_t mod_high = attribs.modifier[0] >> 32;
uint32_t mod_low = attribs.modifier[0]; uint32_t mod_low = attribs.modifier[0] & 0xFFFFFFFF;
zwlr_export_dmabuf_frame_v1_send_frame(frame->resource, zwlr_export_dmabuf_frame_v1_send_frame(frame->resource,
output->width, output->height, output->scale, output->transform, output->width, output->height, output->scale, output->transform,
@ -106,9 +122,8 @@ static void manager_handle_capture_output(struct wl_client *client,
attribs.offset[i], attribs.stride[i]); attribs.offset[i], attribs.stride[i]);
} }
// TODO: wait for the frame to be ready frame->output_swap_buffers.notify = frame_output_handle_swap_buffers;
// TODO: timestamps wl_signal_add(&output->events.swap_buffers, &frame->output_swap_buffers);
zwlr_export_dmabuf_frame_v1_send_ready(frame->resource, 0, 0, 0);
} }
static const struct zwlr_export_dmabuf_manager_v1_interface manager_impl = { static const struct zwlr_export_dmabuf_manager_v1_interface manager_impl = {

View file

@ -467,7 +467,12 @@ bool wlr_output_swap_buffers(struct wlr_output *output, struct timespec *when,
output->idle_frame = NULL; output->idle_frame = NULL;
} }
wlr_signal_emit_safe(&output->events.swap_buffers, damage); struct wlr_output_event_swap_buffers event = {
.output = output,
.when = when,
.damage = damage,
};
wlr_signal_emit_safe(&output->events.swap_buffers, &event);
int width, height; int width, height;
wlr_output_transformed_resolution(output, &width, &height); wlr_output_transformed_resolution(output, &width, &height);