From f7851c21ae61496d82556ae72859f52714076d87 Mon Sep 17 00:00:00 2001 From: William McKinnon Date: Sat, 6 May 2023 22:41:44 -0400 Subject: [PATCH] moved damage expansion to output.c --- include/sway/config.h | 2 ++ sway/config.c | 4 +++ sway/desktop/output.c | 14 +++++++---- sway/desktop/render.c | 58 +++++++++++-------------------------------- 4 files changed, 30 insertions(+), 48 deletions(-) diff --git a/include/sway/config.h b/include/sway/config.h index cabc9cf5..8dcf6a32 100644 --- a/include/sway/config.h +++ b/include/sway/config.h @@ -761,6 +761,8 @@ void translate_keysyms(struct input_config *input_config); void binding_add_translated(struct sway_binding *binding, list_t *bindings); +int get_config_blur_size(); + /* Global config singleton. */ extern struct sway_config *config; diff --git a/sway/config.c b/sway/config.c index 85e53679..43201bf4 100644 --- a/sway/config.c +++ b/sway/config.c @@ -1084,3 +1084,7 @@ void translate_keysyms(struct input_config *input_config) { sway_log(SWAY_DEBUG, "Translated keysyms using config for device '%s'", input_config->identifier); } + +int get_config_blur_size() { + return pow(2, config->blur_params.num_passes) * config->blur_params.radius; +} diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 45c2f1c4..a27dc51d 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -745,12 +745,17 @@ static void damage_child_views_iterator(struct sway_container *con, void output_damage_whole_container(struct sway_output *output, struct sway_container *con) { + int shadow_sigma = con->shadow_enabled ? config->shadow_blur_sigma : 0; + int blur_size = con->blur_enabled ? get_config_blur_size() : 0; + // +1 as a margin of error + int effect_size = MAX(shadow_sigma, blur_size) + 1; + // Pad the box by 1px, because the width is a double and might be a fraction struct wlr_box box = { - .x = con->current.x - output->lx - 1, - .y = con->current.y - output->ly - 1, - .width = con->current.width + 2, - .height = con->current.height + 2, + .x = con->current.x - output->lx - 1 - effect_size, + .y = con->current.y - output->ly - 1 - effect_size, + .width = con->current.width + 2 + effect_size * 2, + .height = con->current.height + 2 + effect_size * 2, }; scale_box(&box, output->wlr_output->scale); if (wlr_damage_ring_add_box(&output->damage_ring, &box)) { @@ -973,7 +978,6 @@ void handle_new_output(struct wl_listener *listener, void *data) { transaction_commit_dirty(); - // From sway upstream (fixes damage_ring bounds being INT_MAX) int width, height; wlr_output_transformed_resolution(output->wlr_output, &width, &height); wlr_damage_ring_set_bounds(&output->damage_ring, width, height); diff --git a/sway/desktop/render.c b/sway/desktop/render.c index 1de797b9..a88648c6 100644 --- a/sway/desktop/render.c +++ b/sway/desktop/render.c @@ -50,10 +50,6 @@ struct decoration_data get_undecorated_decoration_data() { }; } -int get_blur_size() { - return pow(2, config->blur_params.num_passes) * config->blur_params.radius; -} - bool should_parameters_blur() { return config->blur_params.radius > 0 && config->blur_params.num_passes > 0; } @@ -250,7 +246,7 @@ struct fx_framebuffer *get_main_buffer_blur(struct fx_renderer *renderer, struct pixman_region32_copy(&damage, original_damage); wlr_region_transform(&damage, &damage, transform, monitor_box.width, monitor_box.height); - wlr_region_expand(&damage, &damage, get_blur_size()); + wlr_region_expand(&damage, &damage, get_config_blur_size()); // Initially blur main_buffer content into the effects_buffers struct fx_framebuffer *current_buffer = &renderer->main_buffer; @@ -1811,42 +1807,16 @@ void output_render(struct sway_output *output, struct timespec *when, pixman_region32_union_rect(damage, damage, 0, 0, width, height); } - bool blur_optimize_should_render = false; bool damage_not_empty = pixman_region32_not_empty(damage); - pixman_region32_t extended_damage; - pixman_region32_init(&extended_damage); + // Check if there are any windows to blur + bool blur_optimize_should_render = should_workspace_have_optimized_blur(output); + // TODO: can this be put elsewhere? blur_optimize_should_render isn't used until much later + // additionally, do we check for non fullscreen con elsewhere? if (!fullscreen_con && !server.session_lock.locked && damage_not_empty) { - // Check if there are any windows to blur - if (should_workspace_have_optimized_blur(output)) { - blur_optimize_should_render = true; - // Damage the whole output + // Damage the whole output + if (blur_optimize_should_render) { pixman_region32_union_rect(damage, damage, 0, 0, width, height); } - - // TODO: move me to output.c - bool shadow_enabled = config->shadow_enabled; - int shadow_sigma = shadow_enabled ? config->shadow_blur_sigma : 0; - bool blur_enabled = config->blur_enabled; - int blur_size = blur_enabled ? get_blur_size() : 0; - // +1 as a margin of error - int expanded_size = MAX(shadow_sigma, blur_size) + 1; - - if (expanded_size > 0) { - int32_t damage_width = damage->extents.x2 - damage->extents.x1; - int32_t damage_height = damage->extents.y2 - damage->extents.y1; - // Limit the damage extent to the size of the monitor to prevent overflow - if (damage_width > width || damage_height > height) { - pixman_region32_intersect_rect(damage, damage, 0, 0, width, height); - } - - wlr_region_expand(damage, damage, expanded_size); - pixman_region32_copy(&extended_damage, damage); - wlr_region_expand(damage, damage, expanded_size); - } else { - pixman_region32_copy(&extended_damage, damage); - } - } else { - pixman_region32_copy(&extended_damage, damage); } if (debug.damage == DAMAGE_HIGHLIGHT && damage_not_empty) { @@ -1994,16 +1964,17 @@ render_overlay: renderer_end: // Draw the contents of our buffer into the wlr buffer fx_framebuffer_bind(&renderer->wlr_buffer); + float clear_color[] = {0.0f, 0.0f, 0.0f, 1.0f}; - if (pixman_region32_not_empty(&extended_damage)) { + if (pixman_region32_not_empty(damage)) { int nrects; - pixman_box32_t *rects = pixman_region32_rectangles(&extended_damage, &nrects); + pixman_box32_t *rects = pixman_region32_rectangles(damage, &nrects); for (int i = 0; i < nrects; ++i) { scissor_output(wlr_output, &rects[i]); fx_renderer_clear(clear_color); } } - render_whole_output(renderer, wlr_output, &extended_damage, &renderer->main_buffer.texture); + render_whole_output(renderer, wlr_output, damage, &renderer->main_buffer.texture); fx_renderer_scissor(NULL); fx_renderer_end(renderer); @@ -2016,12 +1987,13 @@ renderer_end: pixman_region32_t frame_damage; pixman_region32_init(&frame_damage); - enum wl_output_transform transform = wlr_output_transform_invert(wlr_output->transform); /* * Extend the frame damage by the blur size to properly calc damage for the * next buffer swap. Thanks Emersion for your excellent damage tracking blog-post! */ - wlr_region_transform(&frame_damage, &extended_damage, transform, width, height); + + enum wl_output_transform transform = wlr_output_transform_invert(wlr_output->transform); + wlr_region_transform(&frame_damage, damage, transform, width, height); if (debug.damage != DAMAGE_DEFAULT || blur_optimize_should_render) { pixman_region32_union_rect(&frame_damage, &frame_damage, @@ -2030,7 +2002,7 @@ renderer_end: wlr_output_set_damage(wlr_output, &frame_damage); - pixman_region32_fini(&extended_damage); + //pixman_region32_fini(&extended_damage); pixman_region32_fini(&frame_damage); if (!wlr_output_commit(wlr_output)) {