From 67a3715ded0f36fd03193adafb72e079460b7167 Mon Sep 17 00:00:00 2001 From: Daniel van Vugt Date: Thu, 6 Jun 2019 15:39:26 +0800 Subject: [PATCH] clutter/stage-cogl: Reduce while loop iterations If `last_presentation_time` is zero (unsupported) or just very old (system was idle) then we would like to avoid that triggering a large number of loop interations. This will get us closer to the right answer without iterating. https://gitlab.gnome.org/GNOME/mutter/merge_requests/363 --- clutter/clutter/cogl/clutter-stage-cogl.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/clutter/clutter/cogl/clutter-stage-cogl.c b/clutter/clutter/cogl/clutter-stage-cogl.c index 229015b90..03f067267 100644 --- a/clutter/clutter/cogl/clutter-stage-cogl.c +++ b/clutter/clutter/cogl/clutter-stage-cogl.c @@ -204,6 +204,19 @@ clutter_stage_cogl_schedule_update (ClutterStageWindow *stage_window, next_presentation_time = stage_cogl->last_presentation_time + refresh_interval; + /* Get next_presentation_time closer to its final value, to reduce + * the number of while iterations below. + */ + if (next_presentation_time < now) + { + int64_t last_virtual_presentation_time = now - now % refresh_interval; + int64_t hardware_clock_phase = + stage_cogl->last_presentation_time % refresh_interval; + + next_presentation_time = + last_virtual_presentation_time + hardware_clock_phase; + } + while (next_presentation_time < now + min_render_time_allowed) next_presentation_time += refresh_interval;