Simplified detection of blur on workspace

This commit is contained in:
Erik Reider 2023-08-12 14:45:43 +02:00
parent 657da122ab
commit be1d93b2cd
3 changed files with 16 additions and 52 deletions

View file

@ -92,9 +92,7 @@ struct sway_output *workspace_output_get_highest_available(
void workspace_detect_urgent(struct sway_workspace *workspace); void workspace_detect_urgent(struct sway_workspace *workspace);
bool should_workspace_have_blur(struct sway_workspace *ws); bool workspace_get_blur_info(struct sway_workspace *ws,
void workspace_get_blur_region(struct sway_workspace *ws,
pixman_region32_t *blur_region); pixman_region32_t *blur_region);
void workspace_for_each_container(struct sway_workspace *ws, void workspace_for_each_container(struct sway_workspace *ws,

View file

@ -1791,8 +1791,13 @@ void output_render(struct sway_output *output, struct timespec *when,
render_unmanaged(output, damage, &root->xwayland_unmanaged); render_unmanaged(output, damage, &root->xwayland_unmanaged);
#endif #endif
} else { } else {
bool workspace_has_blur = should_workspace_have_blur(workspace); // Gather the whole region where blur is drawn (all surfaces on
if (workspace_has_blur && config_should_parameters_blur()) { // the focused workspace)
pixman_region32_t blur_region;
pixman_region32_init(&blur_region);
bool workspace_has_blur = workspace_get_blur_info(workspace, &blur_region);
// Expend the damage to compensate for blur
if (workspace_has_blur) {
// Skip all of the blur artifact prevention if we're damaging the // Skip all of the blur artifact prevention if we're damaging the
// whole viewport // whole viewport
if (renderer->blur_buffer_dirty) { if (renderer->blur_buffer_dirty) {
@ -1818,15 +1823,8 @@ void output_render(struct sway_output *output, struct timespec *when,
wlr_region_expand(damage, damage, config_get_blur_size()); wlr_region_expand(damage, damage, config_get_blur_size());
} }
pixman_region32_t blur_region;
pixman_region32_init(&blur_region);
pixman_region32_t extended_damage; pixman_region32_t extended_damage;
pixman_region32_init(&extended_damage); pixman_region32_init(&extended_damage);
// Gather the whole region where blur is drawn (all surfaces on
// the focused workspace)
workspace_get_blur_region(workspace, &blur_region);
pixman_region32_intersect(&extended_damage, damage, &blur_region); pixman_region32_intersect(&extended_damage, damage, &blur_region);
// Expand the region to compensate for blur artifacts // Expand the region to compensate for blur artifacts
wlr_region_expand(&extended_damage, &extended_damage, config_get_blur_size()); wlr_region_expand(&extended_damage, &extended_damage, config_get_blur_size());
@ -1842,6 +1840,7 @@ void output_render(struct sway_output *output, struct timespec *when,
// Combine into the surface damage (we need to redraw the padding // Combine into the surface damage (we need to redraw the padding
// area as well) // area as well)
pixman_region32_union(damage, damage, &extended_damage); pixman_region32_union(damage, damage, &extended_damage);
pixman_region32_fini(&extended_damage);
// Capture the padding pixels before blur for later use // Capture the padding pixels before blur for later use
fx_framebuffer_bind(&renderer->blur_saved_pixels_buffer); fx_framebuffer_bind(&renderer->blur_saved_pixels_buffer);
@ -1849,11 +1848,9 @@ void output_render(struct sway_output *output, struct timespec *when,
render_whole_output(renderer, wlr_output, render_whole_output(renderer, wlr_output,
&renderer->blur_padding_region, &renderer->wlr_buffer.texture); &renderer->blur_padding_region, &renderer->wlr_buffer.texture);
fx_framebuffer_bind(&renderer->wlr_buffer); fx_framebuffer_bind(&renderer->wlr_buffer);
}
}
pixman_region32_fini(&blur_region); pixman_region32_fini(&blur_region);
pixman_region32_fini(&extended_damage);
}
}
float clear_color[] = {0.25f, 0.25f, 0.25f, 1.0f}; float clear_color[] = {0.25f, 0.25f, 0.25f, 1.0f};
@ -1870,7 +1867,7 @@ void output_render(struct sway_output *output, struct timespec *when,
&output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM]); &output->layers[ZWLR_LAYER_SHELL_V1_LAYER_BOTTOM]);
// check if the background needs to be blurred // check if the background needs to be blurred
if (config_should_parameters_blur() && renderer->blur_buffer_dirty && workspace_has_blur) { if (workspace_has_blur && renderer->blur_buffer_dirty) {
render_output_blur(output, damage); render_output_blur(output, damage);
} }

View file

@ -692,39 +692,6 @@ void workspace_detect_urgent(struct sway_workspace *workspace) {
} }
} }
static bool find_blurred_con_iterator(struct sway_container *con, void *data) {
struct sway_view *view = con->view;
if (!view) {
return false;
}
return con->blur_enabled && !view->surface->opaque;
}
bool should_workspace_have_blur(struct sway_workspace *ws) {
if (!workspace_is_visible(ws)) {
return false;
}
if ((bool)workspace_find_container(ws, find_blurred_con_iterator, NULL)) {
return true;
}
// Check if any layer-shell surfaces will render effects
struct sway_output *sway_output = ws->output;
size_t len = sizeof(sway_output->layers) / sizeof(sway_output->layers[0]);
for (size_t i = 0; i < len; ++i) {
struct sway_layer_surface *lsurface;
wl_list_for_each(lsurface, &sway_output->layers[i], link) {
if (lsurface->has_blur && !lsurface->layer_surface->surface->opaque
&& lsurface->layer != ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND) {
return true;
}
}
}
return false;
}
struct blur_region_data { struct blur_region_data {
struct sway_workspace *ws; struct sway_workspace *ws;
pixman_region32_t *blur_region; pixman_region32_t *blur_region;
@ -748,9 +715,9 @@ static void find_blurred_region_iterator(struct sway_container *con, void *data)
} }
} }
void workspace_get_blur_region(struct sway_workspace *ws, pixman_region32_t *blur_region) { bool workspace_get_blur_info(struct sway_workspace *ws, pixman_region32_t *blur_region) {
if (!workspace_is_visible(ws)) { if (!workspace_is_visible(ws) || !config_should_parameters_blur()) {
return; return false;
} }
// Each toplevel // Each toplevel
@ -771,6 +738,8 @@ void workspace_get_blur_region(struct sway_workspace *ws, pixman_region32_t *blu
} }
} }
} }
return pixman_region32_not_empty(blur_region);
} }
void workspace_for_each_container(struct sway_workspace *ws, void workspace_for_each_container(struct sway_workspace *ws,