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 <derek.foreman@collabora.com>
This commit is contained in:
Derek Foreman 2025-12-12 10:07:39 -06:00
parent ed77aca2d8
commit 65227cb7d4

View file

@ -3921,6 +3921,10 @@ weston_output_repaint_from_present(const struct weston_output *output,
const struct timespec *present_time) const struct timespec *present_time)
{ {
struct timespec repaint_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; bool late = false;
if (timespec_sub_to_nsec(now, present_time) > 0) 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) output->vrr_mode == WESTON_VRR_MODE_GAME)
return late ? *now : *present_time; return late ? *now : *present_time;
timespec_add_msec(&repaint_time, present_time, /* The provided time might be in the middle of a frame, so round it
-weston_output_repaint_msec(output)); * 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; return repaint_time;
} }