From 491f1a6a1cd2266ef19363c6f56e726f45e59064 Mon Sep 17 00:00:00 2001 From: hujianwei Date: Sun, 23 Oct 2022 13:18:32 +0000 Subject: [PATCH] Slightly improve frame prediction cutoff point * frame_clock.c (PostEndFrame): Use 5000 us by default, only reverting to the old algorithm if the presentation time is less than that. --- frame_clock.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/frame_clock.c b/frame_clock.c index 5387e3e..b209e6c 100644 --- a/frame_clock.c +++ b/frame_clock.c @@ -29,7 +29,11 @@ typedef struct _CursorClockCallback CursorClockCallback; enum { /* 150ms. */ - MaxPresentationAge = 150000, + MaxPresentationAge = 150000, + /* 5000 microseconds. This arbitrary value is the longest it + normally takes for a sync counter update to be processed by the + compositor. */ + PresentationThreshold = 5000, }; /* Whether or not the compositor supports frame synchronization. */ @@ -333,10 +337,17 @@ PostEndFrame (FrameClock *clock) return; } - /* Use 3/4ths of the presentation time. Any more and we risk the - counter value change signalling the end of the frame arriving - after the presentation deadline. */ - target = target - (clock->presentation_time / 4 * 3); + /* Use 5000 microseconds before the presentation time, or 3/4th of + it if it is less than 5000. Any more and we risk the counter + value change signalling the end of the frame arriving after the + presentation deadline. */ + if (clock->presentation_time > PresentationThreshold) + target = target - (clock->presentation_time - PresentationThreshold); + else + /* However, if the presentation time is less than 5000 + microseconds, use 3/4ths of it. This computation seems to be a + good enough fallback. */ + target = target - (clock->presentation_time / 4 * 3); /* Add the remainder of now if it was probably truncated by the compositor. */