From 01846ffd913c68d848fb415b11b0ca290d50963e Mon Sep 17 00:00:00 2001 From: Dor Askayo Date: Sat, 13 Mar 2021 12:55:09 +0200 Subject: [PATCH] clutter/frame-clock: Simplify early presented event handling A few calculations and assignments are done unnecessarily when the last next presentation time is invalid. This increases the cognitive complexity of the function for no reason. No change in behavior. Part-of: --- clutter/clutter/clutter-frame-clock.c | 51 ++++++++++++++------------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/clutter/clutter/clutter-frame-clock.c b/clutter/clutter/clutter-frame-clock.c index cf740adc3..b223b8545 100644 --- a/clutter/clutter/clutter-frame-clock.c +++ b/clutter/clutter/clutter-frame-clock.c @@ -407,8 +407,6 @@ calculate_next_update_time_us (ClutterFrameClock *frame_clock, int64_t refresh_interval_us; int64_t min_render_time_allowed_us; int64_t max_render_time_allowed_us; - int64_t last_next_presentation_time_us; - int64_t time_since_last_next_presentation_time_us; int64_t next_presentation_time_us; int64_t next_update_time_us; @@ -510,29 +508,34 @@ calculate_next_update_time_us (ClutterFrameClock *frame_clock, refresh_interval_us; } - /* - * Skip one interval if we got an early presented event. - * - * last frame this was last_presentation_time - * / frame_clock->next_presentation_time_us - * / / - * |---|-o-----|-x-----> - * | \ - * \ next_presentation_time_us is thus right after the last one - * but got an unexpected early presentation - * \_/ - * time_since_last_next_presentation_time_us - * - */ - last_next_presentation_time_us = frame_clock->next_presentation_time_us; - time_since_last_next_presentation_time_us = - next_presentation_time_us - last_next_presentation_time_us; - if (frame_clock->is_next_presentation_time_valid && - time_since_last_next_presentation_time_us > 0 && - time_since_last_next_presentation_time_us < (refresh_interval_us / 2)) + if (frame_clock->is_next_presentation_time_valid) { - next_presentation_time_us = - frame_clock->next_presentation_time_us + refresh_interval_us; + int64_t last_next_presentation_time_us; + int64_t time_since_last_next_presentation_time_us; + + /* + * Skip one interval if we got an early presented event. + * + * last frame this was last_presentation_time + * / frame_clock->next_presentation_time_us + * / / + * |---|-o-----|-x-----> + * | \ + * \ next_presentation_time_us is thus right after the last one + * but got an unexpected early presentation + * \_/ + * time_since_last_next_presentation_time_us + * + */ + last_next_presentation_time_us = frame_clock->next_presentation_time_us; + time_since_last_next_presentation_time_us = + next_presentation_time_us - last_next_presentation_time_us; + if (time_since_last_next_presentation_time_us > 0 && + time_since_last_next_presentation_time_us < (refresh_interval_us / 2)) + { + next_presentation_time_us = + frame_clock->next_presentation_time_us + refresh_interval_us; + } } while (next_presentation_time_us < now_us + min_render_time_allowed_us)