From 4c6826386d2d00df852f7e84880d9a2c3a24c3e8 Mon Sep 17 00:00:00 2001 From: William McKinnon Date: Tue, 30 May 2023 00:33:31 -0400 Subject: [PATCH] optimized math of alpha_step --- include/sway/output.h | 1 + sway/desktop/output.c | 11 +++++------ 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/include/sway/output.h b/include/sway/output.h index 3215c853..6e9f26e4 100644 --- a/include/sway/output.h +++ b/include/sway/output.h @@ -64,6 +64,7 @@ struct sway_output { struct timespec last_presentation; uint32_t refresh_nsec; + float refresh_sec; int max_render_time; // In milliseconds struct wl_event_source *repaint_timer; }; diff --git a/sway/desktop/output.c b/sway/desktop/output.c index e7b27864..ba778934 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -525,17 +525,13 @@ static void containers_tick_alpha(list_t *containers, struct sway_output *output // TODO: config for animation_duration float animation_duration = 0.5; - const long NSEC_IN_SECONDS = 1000000000; - float output_refresh_seconds = (float)output->refresh_nsec / NSEC_IN_SECONDS; - float num_refreshes_to_animate = animation_duration / output_refresh_seconds; - float alpha_step; for (int i = 0; i < containers->length; ++i) { struct sway_container *con = containers->items[i]; if (con->pending.children) { containers_tick_alpha(con->pending.children, output); } else if (con->alpha < con->target_alpha) { - alpha_step = (con->target_alpha) / num_refreshes_to_animate; + alpha_step = (con->target_alpha * output->refresh_sec) / animation_duration; // ensure that the alpha does not exceed the target_alpha con->alpha = MIN(con->alpha + alpha_step, con->target_alpha); output_damage_whole_container(output, con); @@ -642,7 +638,7 @@ static void handle_frame(struct wl_listener *listener, void *user_data) { const long NSEC_IN_SECONDS = 1000000000; struct timespec predicted_refresh = output->last_presentation; predicted_refresh.tv_nsec += output->refresh_nsec % NSEC_IN_SECONDS; - predicted_refresh.tv_sec += output->refresh_nsec / NSEC_IN_SECONDS; + predicted_refresh.tv_sec += output->refresh_sec; if (predicted_refresh.tv_nsec >= NSEC_IN_SECONDS) { predicted_refresh.tv_sec += 1; predicted_refresh.tv_nsec -= NSEC_IN_SECONDS; @@ -932,6 +928,9 @@ static void handle_present(struct wl_listener *listener, void *data) { output->last_presentation = *output_event->when; output->refresh_nsec = output_event->refresh; + + const long NSEC_IN_SECONDS = 1000000000; + output->refresh_sec = (float)output_event->refresh / NSEC_IN_SECONDS; } static unsigned int last_headless_num = 0;