From 1fd726eed71fe563addb7cdfbb356a353e8464f3 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Mon, 9 Aug 2021 15:51:01 +1000 Subject: [PATCH] [client] x11: be less sensitive to frame skips External events like launching other applications can cause latency spikes while X11 initializes the application, we should only start adjusting our delay if we see excessive skips over a 1s period. --- client/displayservers/X11/x11.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/client/displayservers/X11/x11.c b/client/displayservers/X11/x11.c index 94ab8f27..2a75dcb8 100644 --- a/client/displayservers/X11/x11.c +++ b/client/displayservers/X11/x11.c @@ -1311,19 +1311,26 @@ static bool x11WaitFrame(void) /* adjustments if we are still seeing odd skips */ const uint64_t lastWMEvent = atomic_load(&x11.lastWMEvent); const uint64_t eventDelta = ust > lastWMEvent ? ust - lastWMEvent : 0; + + static int skipCount = 0; + static uint64_t lastSkipTime = 0; + + if (skipCount > 0 && ust - lastSkipTime > 1000000UL) + skipCount = 0; + if (delay > 0 && deltamsc > 1 && eventDelta > 1000000UL) { /* only adjust if the last skip was less then 1s ago */ - static uint64_t lastSkip = 0; - const bool adjust = ust - lastSkip < 1000000UL; - lastSkip = ust; + const bool flag = ust - lastSkipTime < 1000000UL; + lastSkipTime = ust; - if (adjust) + if (flag && ++skipCount > 10) { if (delay - 500 < delay) { delay -= 500; DEBUG_INFO("Excessing skipping detected, reduced calibration delay to %lu us", delay); + skipCount = 0; } else {