From 8306f46dfb93bd8d791803897927f43e0888e2bd Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Wed, 9 Aug 2017 15:58:41 -0400 Subject: implement surface frame The surface frame callback lets a window know when it is a good time to show the next frame if it is animating. In particular, this callback is used by weston-simple-shm to throttle drawing. --- examples/compositor/main.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'examples') diff --git a/examples/compositor/main.c b/examples/compositor/main.c index 9d320c97..7ac549e5 100644 --- a/examples/compositor/main.c +++ b/examples/compositor/main.c @@ -23,6 +23,13 @@ struct sample_state { struct xdg_shell_state xdg_shell; }; +/* + * Convert timespec to milliseconds + */ +static inline int64_t timespec_to_msec(const struct timespec *a) { + return (int64_t)a->tv_sec * 1000 + a->tv_nsec / 1000000; +} + void handle_output_frame(struct output_state *output, struct timespec *ts) { struct compositor_state *state = output->compositor; struct sample_state *sample = state->data; @@ -39,6 +46,12 @@ void handle_output_frame(struct output_state *output, struct timespec *ts) { wlr_texture_get_matrix(surface->texture, &matrix, &wlr_output->transform_matrix, 200, 200); wlr_render_with_matrix(sample->renderer, surface->texture, &matrix); + + struct wlr_frame_callback *cb, *cnext; + wl_list_for_each_safe(cb, cnext, &surface->frame_callback_list, link) { + wl_callback_send_done(cb->resource, timespec_to_msec(ts)); + wl_resource_destroy(cb->resource); + } } } -- cgit v1.2.3