From e541aea2d760302eeb364de4ddefc7754d03e36b Mon Sep 17 00:00:00 2001
From: Philipp Zabel
Date: Tue, 4 Jul 2023 16:50:08 +0200
Subject: [PATCH] backend-rdp: make sure to finish frames with timestamps in
the past
Round up the ms delay to make sure that the finish_frame_timer always
expires after the next frame_time. That way, finish_frame_handler()
never passes a timestamp in the future to weston_output_finish_frame().
Setting frame_time into the future risks hitting an assert in
weston_output_finish_frame(), when it is called from start_repaint_loop
within the frame interval.
Signed-off-by: Philipp Zabel
---
libweston/backend-rdp/rdp.c | 11 ++++-------
1 file changed, 4 insertions(+), 7 deletions(-)
diff --git a/libweston/backend-rdp/rdp.c b/libweston/backend-rdp/rdp.c
index 79eee839..6c0a0db6 100644
--- a/libweston/backend-rdp/rdp.c
+++ b/libweston/backend-rdp/rdp.c
@@ -280,8 +280,7 @@ rdp_output_repaint(struct weston_output *output_base, pixman_region32_t *damage)
struct rdp_peers_item *peer;
struct timespec now, target;
int refresh_nsec = millihz_to_nsec(output_base->current_mode->refresh);
- int refresh_msec = refresh_nsec / 1000000;
- int next_frame_delta;
+ int64_t delay_nsec;
/* Calculate the time we should complete this frame such that frames
are spaced out by the specified monitor refresh. Note that our timer
@@ -292,10 +291,7 @@ rdp_output_repaint(struct weston_output *output_base, pixman_region32_t *damage)
timespec_add_nsec(&target, &output_base->frame_time, refresh_nsec);
- next_frame_delta = (int)timespec_sub_to_msec(&target, &now);
- if (next_frame_delta < 1 || next_frame_delta > refresh_msec) {
- next_frame_delta = refresh_msec;
- }
+ delay_nsec = CLIP(timespec_sub_to_nsec(&target, &now), 1, refresh_nsec);
assert(output);
@@ -317,7 +313,8 @@ rdp_output_repaint(struct weston_output *output_base, pixman_region32_t *damage)
pixman_region32_fini(&transformed_damage);
}
- wl_event_source_timer_update(output->finish_frame_timer, next_frame_delta);
+ wl_event_source_timer_update(output->finish_frame_timer,
+ DIV_ROUND_UP(delay_nsec, 1000000));
return 0;
}