From 9f8283a95a92e12e165e6fbad0fe77091d8c9a43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michel=20D=C3=A4nzer?= Date: Mon, 7 Aug 2023 18:48:42 +0200 Subject: [PATCH] clutter/frame-clock: Simplify next_presentation_time_us calculation When more than one refresh interval has passed since last_presentation_time_us. I honestly can't tell if the previous calculation was correct or not, but I'm confident the new one is, and it's simpler. v2: * ASCII art diagram didn't make sense anymore, try to improve (Ivan Molodetskikh) Part-of: --- clutter/clutter/clutter-frame-clock.c | 49 ++++++++------------------- 1 file changed, 15 insertions(+), 34 deletions(-) diff --git a/clutter/clutter/clutter-frame-clock.c b/clutter/clutter/clutter-frame-clock.c index 30cc6fb12..207a607a7 100644 --- a/clutter/clutter/clutter-frame-clock.c +++ b/clutter/clutter/clutter-frame-clock.c @@ -511,48 +511,29 @@ calculate_next_update_time_us (ClutterFrameClock *frame_clock, */ if (next_presentation_time_us < now_us) { - int64_t presentation_phase_us; int64_t current_phase_us; - int64_t current_refresh_interval_start_us; /* * Let's say we're just past next_presentation_time_us. * - * First, we compute presentation_phase_us. Real presentation times don't - * have to be exact multiples of refresh_interval_us and - * presentation_phase_us represents this difference. Next, we compute - * current phase and the refresh interval start corresponding to now_us. - * Finally, add presentation_phase_us and a refresh interval to get the - * next presentation after now_us. - * - * last_presentation_time_us - * / next_presentation_time_us - * / / now_us - * / / / new next_presentation_time_us - * |--|-------|---o---|-------|--> presentation times - * | __| - * | |presentation_phase_us - * | | - * | | now_us - presentation_phase_us - * | | / - * |-------|---o---|-------|-----> integer multiples of refresh_interval_us - * | \__/ - * | |current_phase_us - * | \ - * | current_refresh_interval_start_us - * 0 + * First, we calculate current_phase_us, corresponding to the time since + * the last integer multiple of the refresh interval passed after the last + * presentation time. Subtracting this phase from now_us and adding a + * refresh interval gets us the next possible presentation time after + * now_us. * + * last_presentation_time_us + * / next_presentation_time_us + * / / now_us + * / / / new next_presentation_time_us + * |-------|---o---|-------|--> possible presentation times + * \_/ \_____/ + * / \ + * current_phase_us refresh_interval_us */ - presentation_phase_us = last_presentation_time_us % refresh_interval_us; - current_phase_us = (now_us - presentation_phase_us) % refresh_interval_us; - current_refresh_interval_start_us = - now_us - presentation_phase_us - current_phase_us; - - next_presentation_time_us = - current_refresh_interval_start_us + - presentation_phase_us + - refresh_interval_us; + current_phase_us = (now_us - last_presentation_time_us) % refresh_interval_us; + next_presentation_time_us = now_us - current_phase_us + refresh_interval_us; } if (frame_clock->is_next_presentation_time_valid)