optimized math of alpha_step
This commit is contained in:
parent
2d14d1eaa4
commit
4c6826386d
2 changed files with 6 additions and 6 deletions
|
@ -64,6 +64,7 @@ struct sway_output {
|
||||||
|
|
||||||
struct timespec last_presentation;
|
struct timespec last_presentation;
|
||||||
uint32_t refresh_nsec;
|
uint32_t refresh_nsec;
|
||||||
|
float refresh_sec;
|
||||||
int max_render_time; // In milliseconds
|
int max_render_time; // In milliseconds
|
||||||
struct wl_event_source *repaint_timer;
|
struct wl_event_source *repaint_timer;
|
||||||
};
|
};
|
||||||
|
|
|
@ -525,17 +525,13 @@ static void containers_tick_alpha(list_t *containers, struct sway_output *output
|
||||||
// TODO: config for animation_duration
|
// TODO: config for animation_duration
|
||||||
float animation_duration = 0.5;
|
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;
|
float alpha_step;
|
||||||
for (int i = 0; i < containers->length; ++i) {
|
for (int i = 0; i < containers->length; ++i) {
|
||||||
struct sway_container *con = containers->items[i];
|
struct sway_container *con = containers->items[i];
|
||||||
if (con->pending.children) {
|
if (con->pending.children) {
|
||||||
containers_tick_alpha(con->pending.children, output);
|
containers_tick_alpha(con->pending.children, output);
|
||||||
} else if (con->alpha < con->target_alpha) {
|
} 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
|
// ensure that the alpha does not exceed the target_alpha
|
||||||
con->alpha = MIN(con->alpha + alpha_step, con->target_alpha);
|
con->alpha = MIN(con->alpha + alpha_step, con->target_alpha);
|
||||||
output_damage_whole_container(output, con);
|
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;
|
const long NSEC_IN_SECONDS = 1000000000;
|
||||||
struct timespec predicted_refresh = output->last_presentation;
|
struct timespec predicted_refresh = output->last_presentation;
|
||||||
predicted_refresh.tv_nsec += output->refresh_nsec % NSEC_IN_SECONDS;
|
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) {
|
if (predicted_refresh.tv_nsec >= NSEC_IN_SECONDS) {
|
||||||
predicted_refresh.tv_sec += 1;
|
predicted_refresh.tv_sec += 1;
|
||||||
predicted_refresh.tv_nsec -= NSEC_IN_SECONDS;
|
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->last_presentation = *output_event->when;
|
||||||
output->refresh_nsec = output_event->refresh;
|
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;
|
static unsigned int last_headless_num = 0;
|
||||||
|
|
Loading…
Add table
Reference in a new issue