moved damage expansion to output.c

This commit is contained in:
William McKinnon 2023-05-06 22:41:44 -04:00
parent 434f3ddfce
commit f7851c21ae
4 changed files with 30 additions and 48 deletions

View file

@ -761,6 +761,8 @@ void translate_keysyms(struct input_config *input_config);
void binding_add_translated(struct sway_binding *binding, list_t *bindings); void binding_add_translated(struct sway_binding *binding, list_t *bindings);
int get_config_blur_size();
/* Global config singleton. */ /* Global config singleton. */
extern struct sway_config *config; extern struct sway_config *config;

View file

@ -1084,3 +1084,7 @@ void translate_keysyms(struct input_config *input_config) {
sway_log(SWAY_DEBUG, "Translated keysyms using config for device '%s'", sway_log(SWAY_DEBUG, "Translated keysyms using config for device '%s'",
input_config->identifier); input_config->identifier);
} }
int get_config_blur_size() {
return pow(2, config->blur_params.num_passes) * config->blur_params.radius;
}

View file

@ -745,12 +745,17 @@ static void damage_child_views_iterator(struct sway_container *con,
void output_damage_whole_container(struct sway_output *output, void output_damage_whole_container(struct sway_output *output,
struct sway_container *con) { 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 // Pad the box by 1px, because the width is a double and might be a fraction
struct wlr_box box = { struct wlr_box box = {
.x = con->current.x - output->lx - 1, .x = con->current.x - output->lx - 1 - effect_size,
.y = con->current.y - output->ly - 1, .y = con->current.y - output->ly - 1 - effect_size,
.width = con->current.width + 2, .width = con->current.width + 2 + effect_size * 2,
.height = con->current.height + 2, .height = con->current.height + 2 + effect_size * 2,
}; };
scale_box(&box, output->wlr_output->scale); scale_box(&box, output->wlr_output->scale);
if (wlr_damage_ring_add_box(&output->damage_ring, &box)) { 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(); transaction_commit_dirty();
// From sway upstream (fixes damage_ring bounds being INT_MAX)
int width, height; int width, height;
wlr_output_transformed_resolution(output->wlr_output, &width, &height); wlr_output_transformed_resolution(output->wlr_output, &width, &height);
wlr_damage_ring_set_bounds(&output->damage_ring, width, height); wlr_damage_ring_set_bounds(&output->damage_ring, width, height);

View file

@ -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() { bool should_parameters_blur() {
return config->blur_params.radius > 0 && config->blur_params.num_passes > 0; 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); pixman_region32_copy(&damage, original_damage);
wlr_region_transform(&damage, &damage, transform, wlr_region_transform(&damage, &damage, transform,
monitor_box.width, monitor_box.height); 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 // Initially blur main_buffer content into the effects_buffers
struct fx_framebuffer *current_buffer = &renderer->main_buffer; 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); 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); bool damage_not_empty = pixman_region32_not_empty(damage);
pixman_region32_t extended_damage;
pixman_region32_init(&extended_damage);
if (!fullscreen_con && !server.session_lock.locked && damage_not_empty) {
// Check if there are any windows to blur // Check if there are any windows to blur
if (should_workspace_have_optimized_blur(output)) { bool blur_optimize_should_render = should_workspace_have_optimized_blur(output);
blur_optimize_should_render = true; // 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) {
// Damage the whole output // Damage the whole output
if (blur_optimize_should_render) {
pixman_region32_union_rect(damage, damage, 0, 0, width, height); 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) { if (debug.damage == DAMAGE_HIGHLIGHT && damage_not_empty) {
@ -1994,16 +1964,17 @@ render_overlay:
renderer_end: renderer_end:
// Draw the contents of our buffer into the wlr buffer // Draw the contents of our buffer into the wlr buffer
fx_framebuffer_bind(&renderer->wlr_buffer); fx_framebuffer_bind(&renderer->wlr_buffer);
float clear_color[] = {0.0f, 0.0f, 0.0f, 1.0f}; 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; 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) { for (int i = 0; i < nrects; ++i) {
scissor_output(wlr_output, &rects[i]); scissor_output(wlr_output, &rects[i]);
fx_renderer_clear(clear_color); 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_scissor(NULL);
fx_renderer_end(renderer); fx_renderer_end(renderer);
@ -2016,12 +1987,13 @@ renderer_end:
pixman_region32_t frame_damage; pixman_region32_t frame_damage;
pixman_region32_init(&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 * 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! * 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) { if (debug.damage != DAMAGE_DEFAULT || blur_optimize_should_render) {
pixman_region32_union_rect(&frame_damage, &frame_damage, pixman_region32_union_rect(&frame_damage, &frame_damage,
@ -2030,7 +2002,7 @@ renderer_end:
wlr_output_set_damage(wlr_output, &frame_damage); wlr_output_set_damage(wlr_output, &frame_damage);
pixman_region32_fini(&extended_damage); //pixman_region32_fini(&extended_damage);
pixman_region32_fini(&frame_damage); pixman_region32_fini(&frame_damage);
if (!wlr_output_commit(wlr_output)) { if (!wlr_output_commit(wlr_output)) {