From 65227cb7d42a064031eeb08cb37e92bfc92b7815 Mon Sep 17 00:00:00 2001 From: Derek Foreman Date: Fri, 12 Dec 2025 10:07:39 -0600 Subject: [PATCH] compositor: Round repaint times down to possible presentation times Currently this shouldn't result in any change, since the times we pass in are real presentation times. Later when commit-timing lets applications pass in arbitrary times, it will be more interesting. Signed-off-by: Derek Foreman --- libweston/compositor.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/libweston/compositor.c b/libweston/compositor.c index 109c41628..c98c71f68 100644 --- a/libweston/compositor.c +++ b/libweston/compositor.c @@ -3921,6 +3921,10 @@ weston_output_repaint_from_present(const struct weston_output *output, const struct timespec *present_time) { struct timespec repaint_time; + int64_t time_since; + int64_t frames_since; + int refresh_nsec = millihz_to_nsec(output->current_mode->refresh); + struct timespec actual_present_time; bool late = false; if (timespec_sub_to_nsec(now, present_time) > 0) @@ -3937,8 +3941,16 @@ weston_output_repaint_from_present(const struct weston_output *output, output->vrr_mode == WESTON_VRR_MODE_GAME) return late ? *now : *present_time; - timespec_add_msec(&repaint_time, present_time, - -weston_output_repaint_msec(output)); + /* The provided time might be in the middle of a frame, so round it + * back to the start of the frame that time is in. + */ + time_since = timespec_sub_to_nsec(present_time, &output->frame_time); + time_since--; + frames_since = time_since / refresh_nsec; + timespec_add_nsec(&actual_present_time, &output->frame_time, refresh_nsec * (frames_since + 1)); + + /* Subtract the "repaint window" time to get the deadline for the presentation time */ + timespec_add_msec(&repaint_time, &actual_present_time, -weston_output_repaint_msec(output)); return repaint_time; }