From 98b4e20a68158c98bb367572ebbfbd61ef120c18 Mon Sep 17 00:00:00 2001 From: Pekka Paalanen Date: Mon, 10 May 2021 11:33:23 +0300 Subject: [PATCH] libweston: assert frame times never go backwards Adding this check was prompted by https://gitlab.freedesktop.org/wayland/weston/-/merge_requests/609 There is no reason to allow frame times jump backwards, and apparently we already have code that makes that assumption. DRM KMS uses CLOCK_MONOTONIC as the vblank and page flip timestamps, which by definition cannot go backwards. Other backends call weston_compositor_set_presentation_clock_software(). Frame times are also reported directly to Wayland clients via presentation-time extension, and clients too will not expect that the timestamp could go backwards. So make sure time can never go backwards. Signed-off-by: Pekka Paalanen --- libweston/compositor.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/libweston/compositor.c b/libweston/compositor.c index 6e965372..89f438a2 100644 --- a/libweston/compositor.c +++ b/libweston/compositor.c @@ -3003,7 +3003,15 @@ weston_output_finish_frame(struct weston_output *output, int64_t msec_rel; assert(output->repaint_status == REPAINT_AWAITING_COMPLETION); - assert(stamp || (presented_flags & WP_PRESENTATION_FEEDBACK_INVALID)); + + /* + * If timestamp of latest vblank is given, it must always go forwards. + * If not given, INVALID flag must be set. + */ + if (stamp) + assert(timespec_sub_to_nsec(stamp, &output->frame_time) >= 0); + else + assert(presented_flags & WP_PRESENTATION_FEEDBACK_INVALID); weston_compositor_read_presentation_clock(compositor, &now);