From 9be33a3425887d868cbe97e415b21c4d922200f0 Mon Sep 17 00:00:00 2001 From: JP Vernooy <82802232+jp-vernooy@users.noreply.github.com> Date: Tue, 10 Nov 2026 20:33:48 +0000 Subject: [PATCH 1/2] feat: add a clip region to SceneFX blur nodes SceneFX runs the whole multi-pass blur once per wlr_scene_blur node, over the node's visible area expanded by the blur size. A compositor that wants to blur an arbitrary region therefore has to create one node per rectangle of that region, and a rounded region is stored as one rectangle per scanline of its corners. Carry a patch that adds wlr_scene_blur_set_clip_region(). The clip is intersected into the node's visible region, so rendering, damage tracking and the blur's damage expansion all stay inside it, and one node can blur any shape. Without a clip the node behaves as before. Assisted-by: Claude Code:claude-opus-5-5 AI-Scope: Wrote the SceneFX clip-region patch from a prompt to cut per-rectangle blur cost. --- .../scenefx-blur-clip-region.patch | 95 +++++++++++++++++++ subprojects/scenefx.wrap | 2 +- 2 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 subprojects/packagefiles/scenefx-blur-clip-region.patch diff --git a/subprojects/packagefiles/scenefx-blur-clip-region.patch b/subprojects/packagefiles/scenefx-blur-clip-region.patch new file mode 100644 index 0000000000..d5a2310c02 --- /dev/null +++ b/subprojects/packagefiles/scenefx-blur-clip-region.patch @@ -0,0 +1,95 @@ +--- a/include/scenefx/types/wlr_scene.h ++++ b/include/scenefx/types/wlr_scene.h +@@ -184,6 +184,10 @@ struct wlr_scene_blur { + bool should_only_blur_bottom_layer; + + struct linked_node transparency_mask_source; ++ ++ // Optional clip in node-local coordinates (see wlr_scene_blur_set_clip_region) ++ bool has_clip_region; ++ pixman_region32_t clip_region; + }; + + /** A scene-graph node telling SceneFX to render the optimized blur */ +@@ -623,6 +627,15 @@ struct wlr_scene_blur *wlr_scene_blur_create(struct wlr_scene_tree *parent, + */ + void wlr_scene_blur_set_size(struct wlr_scene_blur *blur, int width, int height); + ++/** ++ * Limit the blur to a region, in node-local coordinates. The blur is computed ++ * once for the node and only drawn inside the region, so an arbitrary shape ++ * (e.g. a client's rounded or multi-part blur region) needs a single node ++ * instead of one node per rectangle. Pass NULL to blur the whole node again. ++ */ ++void wlr_scene_blur_set_clip_region(struct wlr_scene_blur *blur, ++ const pixman_region32_t *region); ++ + /** + * Change the corner radius of all corners of an existing blur node. + */ +--- a/types/scene/wlr_scene.c ++++ b/types/scene/wlr_scene.c +@@ -189,6 +189,7 @@ void wlr_scene_node_destroy(struct wlr_scene_node *node) { + } else if (node->type == WLR_SCENE_NODE_BLUR) { + struct wlr_scene_blur *blur = wlr_scene_blur_from_node(node); + linked_node_destroy(&blur->transparency_mask_source); ++ pixman_region32_fini(&blur->clip_region); + } + + assert(wl_list_empty(&node->events.destroy.listener_list)); +@@ -696,6 +697,20 @@ static bool scene_node_update_iterator(struct wlr_scene_node *node, + pixman_region32_intersect_rect(&node->visible, &node->visible, + lx, ly, box.width, box.height); + ++ if (node->type == WLR_SCENE_NODE_BLUR) { ++ struct wlr_scene_blur *blur = wlr_scene_blur_from_node(node); ++ if (blur->has_clip_region) { ++ // Only the clip region is visible, so rendering, damage and the ++ // blur's own damage expansion all stay inside it. ++ pixman_region32_t clip; ++ pixman_region32_init(&clip); ++ pixman_region32_copy(&clip, &blur->clip_region); ++ pixman_region32_translate(&clip, lx, ly); ++ pixman_region32_intersect(&node->visible, &node->visible, &clip); ++ pixman_region32_fini(&clip); ++ } ++ } ++ + if (data->calculate_visibility) { + pixman_region32_t opaque; + pixman_region32_init(&opaque); +@@ -1099,6 +1114,8 @@ struct wlr_scene_blur *wlr_scene_blur_create(struct wlr_scene_tree *parent, + blur->transparency_mask_source = linked_node_init(); + blur->width = width; + blur->height = height; ++ blur->has_clip_region = false; ++ pixman_region32_init(&blur->clip_region); + + scene_node_update(&blur->node, NULL); + +@@ -1116,6 +1133,25 @@ void wlr_scene_blur_set_size(struct wlr_scene_blur *blur, int width, int height) + scene_node_update(&blur->node, NULL); + } + ++void wlr_scene_blur_set_clip_region(struct wlr_scene_blur *blur, ++ const pixman_region32_t *region) { ++ if (region == NULL) { ++ if (!blur->has_clip_region) { ++ return; ++ } ++ blur->has_clip_region = false; ++ pixman_region32_clear(&blur->clip_region); ++ } else { ++ if (blur->has_clip_region && ++ pixman_region32_equal(&blur->clip_region, region)) { ++ return; ++ } ++ blur->has_clip_region = true; ++ pixman_region32_copy(&blur->clip_region, region); ++ } ++ scene_node_update(&blur->node, NULL); ++} ++ + inline void wlr_scene_blur_set_corner_radius(struct wlr_scene_blur *blur, int corner_radius) { + wlr_scene_blur_set_corner_radii(blur, corner_radii_all(corner_radius)); + } diff --git a/subprojects/scenefx.wrap b/subprojects/scenefx.wrap index fafc8179be..1f2baee1b0 100644 --- a/subprojects/scenefx.wrap +++ b/subprojects/scenefx.wrap @@ -1,7 +1,7 @@ [wrap-git] url = https://github.com/wlrfx/scenefx.git revision = 37ccd723bef49e6891156ffafce8f549f01446cc -diff_files = scenefx-liquid.patch, scenefx-software-sync.patch +diff_files = scenefx-liquid.patch, scenefx-software-sync.patch, scenefx-blur-clip-region.patch [provide] dependency_names = scenefx-0.5 From f5532c45e32ebc5096ba65cac29507993e93af99 Mon Sep 17 00:00:00 2001 From: JP Vernooy <82802232+jp-vernooy@users.noreply.github.com> Date: Tue, 10 Nov 2026 20:33:48 +0000 Subject: [PATCH 2/2] fix: blur a region with one clipped node instead of one per rectangle Rounded blur regions from clients arrive as one pixman rectangle per scanline of each corner. Creating one SceneFX blur node per rectangle ran the full blur pipeline dozens of times per surface: a single Files window needed 15 nodes, and a desktop with blurred panels dropped to about 12 fps on Apple M4 (hundreds of GPU jobs per frame). Blur the region's extents with a single node clipped to the region. The result is pixel-identical to the per-rectangle nodes, needs no shape detection, and also covers clients that send no corner radius. Liquid blur keeps its per-shape nodes. Assisted-by: Claude Code:claude-opus-5-5 AI-Scope: Wrote the background-effect.c change and its benchmark from the same prompt. --- src/background-effect.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/background-effect.c b/src/background-effect.c index c9aa36bc05..c11ef8fa10 100644 --- a/src/background-effect.c +++ b/src/background-effect.c @@ -559,7 +559,14 @@ blur_nodes_update(struct background_effect_surface *surface) shapes = region_components(&node_region, &n_rects); rects = shapes; } else { - rects = pixman_region32_rectangles(&node_region, &n_rects); + /* + * A rounded region arrives as one rectangle per scanline of + * its corners, and SceneFX runs the whole blur pipeline once + * per node. Blur the region's extents with a single node + * clipped to the region instead of one node per rectangle. + */ + n_rects = pixman_region32_empty(&node_region) ? 0 : 1; + rects = pixman_region32_extents(&node_region); } for (int i = 0; i < n_rects; i++) { int x = offset_x + rects[i].x1; @@ -579,6 +586,13 @@ blur_nodes_update(struct background_effect_surface *surface) if (state->liquid > 0.0f) { wlr_scene_blur_set_corner_radius(blur, state->corner_radius); wlr_scene_blur_set_liquid(blur, state->liquid); + } else if (pixman_region32_n_rects(&node_region) > 1) { + pixman_region32_t clip; + pixman_region32_init(&clip); + pixman_region32_copy(&clip, &node_region); + pixman_region32_translate(&clip, -rects[i].x1, -rects[i].y1); + wlr_scene_blur_set_clip_region(blur, &clip); + pixman_region32_fini(&clip); } /* * Render below the surface content. Required for the fallback