Skip to content

RediWM is a Wayland compositor written in Zig (OpenGL ES) that includes everything in one process

scene graph plan, stage 5c: glass drawn by the owned output pass

oxydizerd0a8d1933c71
diff --git a/src/Server.zig b/src/Server.zig
index e5ead5a..340010e 100644
--- a/src/Server.zig
+++ b/src/Server.zig
@@ -474,6 +474,10 @@ pub fn init(server: *Server, scale: ?f32, icon_theme_cfg: icon_theme.Config, io:
// window exists. Without them windows are square, with no ring or shadow.
if (server.output_renderer.enableShapes()) {
@import("chrome.zig").shapes = true;
+ // Glass (stage 5c of docs/plans/scene-graph.md); without the blur program
+ // each glass surface shows its own tint.
+ if (server.glass_engine != null and !server.output_renderer.enableBackdrops())
+ log.err("glass: blur program unavailable, glass surfaces show their tint", .{});
} else {
log.err("window frames: shaped programs unavailable, windows are drawn square", .{});
}
diff --git a/src/glass.c b/src/glass.c
index 70f42d3..8a9803d 100644
--- a/src/glass.c
+++ b/src/glass.c
@@ -23,6 +23,8 @@
#include <wlr/util/log.h>
#include <wlr/util/transform.h>
#include "explicit_sync.h"
+#include "glass.h"
+#include <wlr/util/addon.h>
#include "projection.h"
enum glass_kind { GLASS_TITLEBAR, GLASS_TASKBAR, GLASS_PANEL };
@@ -36,6 +38,8 @@ struct glass_effect {
struct wl_listener destroy, target_destroy;
struct wl_list dependencies;
enum glass_kind kind;
+ struct wlr_addon addon; // on `node`, for rediwm_glass_effect_info
+ uint64_t serial;
float radius, opacity;
uint64_t hash, revision;
bool valid;
@@ -63,6 +67,7 @@ struct glass_engine {
// Camera motion holds every effect; dropping it forces one update.
bool hold_all;
struct wlr_box bounds;
+ uint64_t next_serial;
};
// Each effect observes the source damage independently. Scene output damage is
@@ -403,6 +408,7 @@ static void handle_destroy(struct wl_listener *listener, void *data)
{
(void)data;
struct glass_effect *effect = wl_container_of(listener, effect, destroy);
+ wlr_addon_finish(&effect->addon);
if (effect->engine->held == effect)
effect->engine->held = NULL;
wl_list_remove(&effect->destroy.link);
@@ -429,6 +435,26 @@ static void handle_target_destroy(struct wl_listener *listener, void *data)
struct glass_effect *effect = wl_container_of(listener, effect, target_destroy);
wlr_scene_node_destroy(&effect->node->node);
}
+static void addon_destroy(struct wlr_addon *addon) { wlr_addon_finish(addon); }
+static const struct wlr_addon_interface effect_addon = {.name = "rediwm glass effect",
+ .destroy = addon_destroy};
+bool rediwm_glass_effect_info(struct wlr_scene_node *node, struct rediwm_glass_info *out)
+{
+ struct wlr_addon *addon = wlr_addon_find(&node->addons, NULL, &effect_addon);
+ if (!addon)
+ return false;
+ struct glass_effect *effect = wl_container_of(addon, effect, addon);
+ *out = (struct rediwm_glass_info){
+ .target = effect->target,
+ .sigma = effect->kind == GLASS_TITLEBAR ? 22 : effect->kind == GLASS_TASKBAR ? 24 : 26,
+ .saturation = effect->kind == GLASS_PANEL ? 1.6f : 1.5f,
+ .opacity = effect->opacity,
+ .radius = effect->radius,
+ .serial = effect->serial,
+ .held = effect->engine->hold_all || effect->engine->held == effect,
+ };
+ return true;
+}
static bool accepts_input(struct wlr_scene_buffer *buffer, double *x, double *y)
{
(void)buffer;
@@ -457,6 +483,8 @@ struct glass_effect *rediwm_glass_attach(struct glass_engine *engine,
effect->opacity = 1;
effect->zoom = 1;
effect->node->point_accepts_input = accepts_input;
+ effect->serial = ++engine->next_serial;
+ wlr_addon_init(&effect->addon, &effect->node->node.addons, NULL, &effect_addon);
wlr_scene_buffer_set_filter_mode(effect->node, WLR_SCALE_FILTER_NEAREST);
wlr_scene_node_place_below(&effect->node->node, before);
effect->destroy.notify = handle_destroy;
@@ -1068,33 +1096,10 @@ static void update_tree(struct glass_engine *engine, struct wlr_scene_tree *tree
update_tree(engine, wlr_scene_tree_from_node(node));
}
}
+// Stage 5c: the owned output pass draws glass (scene_output.c); effects are only
+// registered here. The capture machinery above goes in 5d.
void rediwm_glass_update(struct glass_engine *engine, struct wlr_scene_output *output)
{
- if (!engine || engine->failed)
- return;
- if (!engine->resync && !pixman_region32_not_empty(&output->damage_ring.current))
- return;
- engine->resync = false;
- engine->bounds = (struct wlr_box){0};
- struct wlr_scene_output *scene_output;
- wl_list_for_each(scene_output, &engine->scene->outputs, link)
- {
- int width, height;
- wlr_output_effective_resolution(scene_output->output, &width, &height);
- struct wlr_box box = {scene_output->x, scene_output->y, width, height};
- if (wlr_box_empty(&engine->bounds))
- engine->bounds = box;
- else {
- int x = engine->bounds.x < box.x ? engine->bounds.x : box.x;
- int y = engine->bounds.y < box.y ? engine->bounds.y : box.y;
- int right = engine->bounds.x + engine->bounds.width > box.x + box.width
- ? engine->bounds.x + engine->bounds.width
- : box.x + box.width;
- int bottom = engine->bounds.y + engine->bounds.height > box.y + box.height
- ? engine->bounds.y + engine->bounds.height
- : box.y + box.height;
- engine->bounds = (struct wlr_box){x, y, right - x, bottom - y};
- }
- }
- update_tree(engine, &engine->scene->tree);
+ (void)engine;
+ (void)output;
}
diff --git a/src/glass.h b/src/glass.h
new file mode 100644
index 0000000..d1e5c56
--- /dev/null
+++ b/src/glass.h
@@ -0,0 +1,22 @@
+// What the owned output pass needs to know about a glass effect (stage 5 of
+// docs/plans/scene-graph.md). glass.c only registers effects; the pass blurs.
+#pragma once
+#include <stdbool.h>
+#include <stdint.h>
+struct wlr_scene_node;
+struct wlr_scene_buffer;
+struct rediwm_glass_info {
+ // The surface the effect backs: drawn over it, same parent, same box.
+ struct wlr_scene_buffer *target;
+ float sigma; // Gaussian sigma, logical px, before any zoom
+ float saturation; // 1 leaves colours unchanged
+ float opacity;
+ float radius; // logical px; a window's effect takes the window's shape instead
+ // Unique for the effect's life (a node address can be reused).
+ uint64_t serial;
+ // Keep the last blur while the effect moves (a dragged opaque titlebar, camera motion).
+ bool held;
+};
+// False when `node` is not a glass effect node.
+bool rediwm_glass_effect_info(struct wlr_scene_node *node, struct rediwm_glass_info *out);
+bool rediwm_glass_is_effect_node(struct wlr_scene_node *node);
diff --git a/src/ipc/handlers.zig b/src/ipc/handlers.zig
index c4e83a6..093495d 100644
--- a/src/ipc/handlers.zig
+++ b/src/ipc/handlers.zig
@@ -1286,12 +1286,14 @@ fn handleAction(
.startup = startupStats(),
.desktop = stats.global_stats.desktop,
.output_skipped_commits = stats.global_stats.output_skipped_commits,
+ .glass_reblurs = @import("../scene_output.zig").reblurs.*,
} } };
},
.reset_performance_stats => {
server.ensureGpuTimer();
stats.global_stats.reset();
@import("../panel_present.zig").reset();
+ @import("../scene_output.zig").reblurs.* = 0;
return .{ .ok = .handled };
},
diff --git a/src/ipc/protocol.zig b/src/ipc/protocol.zig
index 638aec4..c6993d6 100644
--- a/src/ipc/protocol.zig
+++ b/src/ipc/protocol.zig
@@ -749,6 +749,8 @@ pub const PerformanceStatsResult = struct {
desktop: ?DesktopStats = null,
// Optional so older producers and fixtures omit it.
output_skipped_commits: ?u64 = null,
+ /// Glass blurs re-taken by the output pass (stage 5c), all outputs.
+ glass_reblurs: ?u64 = null,
};
/// The compositor-drawn desktop's repaint work since the last reset.
@@ -3007,6 +3009,9 @@ fn stringifyPerformanceStats(res: PerformanceStatsResult, writer: anytype) !void
if (res.output_skipped_commits) |skipped| {
try writer.print("\"output_skipped_commits\":{d},", .{skipped});
}
+ if (res.glass_reblurs) |reblurs| {
+ try writer.print("\"glass_reblurs\":{d},", .{reblurs});
+ }
try writer.print("\"output_commits\":{d},\"output_failed_commits\":{d},\"fps\":{d:.1},\"frame_time_ms\":{d:.1},\"missed_frames\":{d},\"refresh_hz\":{d:.1},\"titlebar_paints\":{d},\"footer_paints\":{d},\"edge_samples_attempted\":{d},\"edge_samples_succeeded\":{d},\"edge_samples_skipped\":{d},\"edge_sample_ns\":{d},\"panel_paints\":{d},\"panel_allocated_bytes\":{d},\"panel_reused_bytes\":{d},\"icon_cache_hits\":{d},\"icon_cache_misses\":{d},\"icon_decode_ns\":{d},\"icon_decode_count\":{d},\"icon_decoded_bytes\":{d},\"icon_queue_depth_max\":{d},", .{
res.output_commits,
res.output_failed_commits,
diff --git a/src/projection.c b/src/projection.c
index 56a0f38..81c01ba 100644
--- a/src/projection.c
+++ b/src/projection.c
@@ -589,7 +589,20 @@ static uint64_t mirror_opaque(pixman_region32_t *out, const pixman_region32_t *s
return hash;
}
// Glass writes its own projected buffers after this synchronization pass.
-extern bool rediwm_glass_is_effect_node(struct wlr_scene_node *node);
+#include "glass.h"
+// A glass effect covers its target exactly: the box is the target's (same
+// parent), and it is shown only with it. The pass draws the blur (stage 5c).
+static void effect_geometry(struct wlr_scene_node *node, int *x, int *y, int *width,
+ int *height, bool *enabled) {
+ struct rediwm_glass_info info;
+ if (!rediwm_glass_effect_info(node, &info)) return;
+ struct wlr_scene_buffer *t = info.target;
+ *x += t->node.x - node->x;
+ *y += t->node.y - node->y;
+ *enabled = *enabled && t->node.enabled;
+ *width = t->dst_width ? t->dst_width : t->private.buffer_width;
+ *height = t->dst_height ? t->dst_height : t->private.buffer_height;
+}
// A clip's size, radii, border or colour changed: its views did not move, so
// nothing else tells wlroots that the corner arcs and the ring need repainting.
@@ -706,7 +719,12 @@ static void resolve_node(struct rediwm_projection *p, struct group *g,
: REDIWM_ITEM_BUFFER;
item->width = b->dst_width;
item->height = b->dst_height;
- if (!item->width || !item->height) {
+ if (item->kind == REDIWM_ITEM_EFFECT) {
+ int ex = 0, ey = 0;
+ effect_geometry(node, &ex, &ey, &item->width, &item->height, &item->enabled);
+ x += ex;
+ y += ey;
+ } else if (!item->width || !item->height) {
item->width = b->private.buffer_width;
item->height = b->private.buffer_height;
if (b->transform & 1) {
@@ -1091,7 +1109,9 @@ static struct rediwm_item layout_item(struct wlr_scene_node *node, int x, int y)
wlr_scene_surface_try_from_buffer(b) ? REDIWM_ITEM_SURFACE : REDIWM_ITEM_BUFFER;
item.width = b->dst_width;
item.height = b->dst_height;
- if (!item.width || !item.height) {
+ if (item.kind == REDIWM_ITEM_EFFECT) {
+ effect_geometry(node, &x, &y, &item.width, &item.height, &item.enabled);
+ } else if (!item.width || !item.height) {
item.width = b->private.buffer_width;
item.height = b->private.buffer_height;
if (b->transform & 1) { int tmp = item.width; item.width = item.height; item.height = tmp; }
@@ -1127,8 +1147,7 @@ static bool visit_items(struct rediwm_projection *p, struct wlr_scene_node *node
for (struct wl_list *leaf_link = reverse ? g->items.prev : g->items.next;
leaf_link != &g->items; leaf_link = reverse ? leaf_link->prev : leaf_link->next) {
struct leaf *l = wl_container_of(leaf_link, l, paint);
- const struct rediwm_item *item = l->item.kind == REDIWM_ITEM_EFFECT ? &l->effect_item : &l->item;
- if (item->enabled && l->item.enabled && !iterator(item, l->view, data)) return false;
+ if (l->item.enabled && !iterator(&l->item, l->view, data)) return false;
}
}
return true;
diff --git a/src/scene_output.c b/src/scene_output.c
index 28f5755..bf6fda4 100644
--- a/src/scene_output.c
+++ b/src/scene_output.c
@@ -7,6 +7,7 @@
#include "scene_pass.h"
#include "scene_graph.h"
#include "projection.h"
+#include "glass.h"
#include <math.h>
#include <stdlib.h>
#include <wlr/render/drm_syncobj.h>
@@ -21,16 +22,48 @@
#include <wlr/util/region.h>
#include <wlr/util/transform.h>
+// Stage 5c: a glass effect's blur, kept per effect and output between frames
+// (D1, D3 of docs/plans/scene-graph-stage5.md) and re-taken only when something
+// below the effect changed in the region it reads.
+struct effect_cache {
+ struct wl_list link;
+ uint64_t serial; // rediwm_glass_info.serial
+ struct rediwm_backdrop *backdrop;
+ struct wlr_box region; // device pixels the blur covers
+ float sigma; // device pixels
+ bool valid, seen;
+};
+struct output_state {
+ struct wl_list link;
+ struct rediwm_output_renderer *renderer;
+ struct wlr_output *output;
+ struct wl_listener destroy;
+ uint64_t cursor; // into the projection's damage events
+ bool started;
+ struct wl_list caches;
+};
struct entry {
struct rediwm_item item;
struct wlr_scene_node *transport;
struct wlr_box box; // snap of item edges in layout space
pixman_region32_t visible, opaque;
bool sampled;
+ // Effects only: what glass registered, the box the blur reads (layout, the
+ // target's grown by three sigma), the surface drawn over it, and whether
+ // this frame takes a new blur.
+ struct rediwm_glass_info glass;
+ struct wlr_box padded;
+ float sigma; // layout pixels
+ struct wlr_scene_node *front;
+ struct effect_cache *cache;
+ bool reblur;
};
struct rediwm_output_renderer {
struct rediwm_scene_renderer *pass;
struct wl_array entries; // reusable scratch; no retained resource references
+ struct wl_list outputs; // output_state
+ struct rediwm_projection *projection; // of the frame being built
+ bool has_backdrops;
};
struct rediwm_output_renderer *rediwm_output_renderer_create(struct wlr_renderer *renderer) {
struct rediwm_output_renderer *r = calloc(1, sizeof(*r));
@@ -38,13 +71,50 @@ struct rediwm_output_renderer *rediwm_output_renderer_create(struct wlr_renderer
r->pass = rediwm_scene_renderer_create(renderer);
if (!r->pass) { free(r); return NULL; }
wl_array_init(&r->entries);
+ wl_list_init(&r->outputs);
return r;
}
bool rediwm_output_renderer_enable_shapes(struct rediwm_output_renderer *r) {
return rediwm_scene_renderer_enable_shapes(r->pass);
}
+bool rediwm_output_renderer_enable_backdrops(struct rediwm_output_renderer *r) {
+ r->has_backdrops = rediwm_scene_renderer_enable_backdrops(r->pass);
+ return r->has_backdrops;
+}
+static void cache_destroy(struct rediwm_output_renderer *r, struct effect_cache *c) {
+ rediwm_scene_renderer_destroy_backdrop(r->pass, c->backdrop);
+ wl_list_remove(&c->link);
+ free(c);
+}
+static void output_state_destroy(struct output_state *os) {
+ struct effect_cache *c, *next;
+ wl_list_for_each_safe(c, next, &os->caches, link) cache_destroy(os->renderer, c);
+ wl_list_remove(&os->destroy.link);
+ wl_list_remove(&os->link);
+ free(os);
+}
+static void output_destroyed(struct wl_listener *listener, void *data) {
+ (void)data;
+ struct output_state *os = wl_container_of(listener, os, destroy);
+ output_state_destroy(os);
+}
+static struct output_state *output_state_get(struct rediwm_output_renderer *r, struct wlr_output *output) {
+ struct output_state *os;
+ wl_list_for_each(os, &r->outputs, link) if (os->output == output) return os;
+ os = calloc(1, sizeof(*os));
+ if (!os) return NULL;
+ os->renderer = r;
+ os->output = output;
+ wl_list_init(&os->caches);
+ os->destroy.notify = output_destroyed;
+ wl_signal_add(&output->events.destroy, &os->destroy);
+ wl_list_insert(&r->outputs, &os->link);
+ return os;
+}
void rediwm_output_renderer_destroy(struct rediwm_output_renderer *r) {
if (!r) return;
+ struct output_state *os, *next;
+ wl_list_for_each_safe(os, next, &r->outputs, link) output_state_destroy(os);
rediwm_scene_renderer_destroy(r->pass);
wl_array_release(&r->entries);
free(r);
@@ -146,8 +216,15 @@ static bool collect(const struct rediwm_item *item, struct wlr_scene_node *trans
if (s.width <= 0 || s.height <= 0) return true;
struct wlr_box box = {s.x, s.y, s.width, s.height}, intersection;
if (!wlr_box_intersection(&intersection, &box, &collector->view->logical)) return true;
+ struct rediwm_glass_info glass = {0};
if (item->kind == REDIWM_ITEM_RECT) {
if (item->content.color[3] == 0) return true;
+ } else if (item->kind == REDIWM_ITEM_EFFECT) {
+ // Glass is drawn here (stage 5c); without the blur program there is none,
+ // and the surface's own tint shows, as glass.c's fallback did.
+ if (!r->has_backdrops || item->content.opacity == 0 ||
+ !rediwm_glass_effect_info(rediwm_projection_source(transport), &glass) || glass.opacity <= 0)
+ return true;
} else if (item->kind == REDIWM_ITEM_SHADOW) {
// No buffer: the pixels are the shadow's, and never opaque.
if (item->content.opacity == 0 || item->shadow->color[3] == 0) return true;
@@ -168,6 +245,22 @@ static bool collect(const struct rediwm_item *item, struct wlr_scene_node *trans
*e = (struct entry){.item = *item, .transport = transport,
.box = box, .visible = visible};
pixman_region32_init(&e->opaque);
+ if (item->kind == REDIWM_ITEM_EFFECT) {
+ // The blur reads three sigma around the surface, below the effect in
+ // paint order, including what opaque surfaces above hide on screen: those
+ // pixels must not be culled (a re-blur repaints them first).
+ e->glass = glass;
+ e->sigma = glass.sigma * item->scale;
+ const int pad = (int)ceil(3 * e->sigma);
+ e->padded = (struct wlr_box){box.x - pad, box.y - pad, box.width + 2 * pad, box.height + 2 * pad};
+ pixman_region32_t read;
+ pixman_region32_init_rect(&read, e->padded.x, e->padded.y, e->padded.width, e->padded.height);
+ pixman_region32_subtract(&collector->covered, &collector->covered, &read);
+ pixman_region32_fini(&read);
+ struct wlr_scene_node *front = rediwm_projection_node(r->projection, &glass.target->node);
+ e->front = front ? front : &glass.target->node;
+ return true;
+ }
bool full = item->kind == REDIWM_ITEM_RECT && item->content.color[3] == 1;
if (item->kind != REDIWM_ITEM_RECT && item->kind != REDIWM_ITEM_SHADOW) {
struct wlr_scene_buffer *b = wlr_scene_buffer_from_node(transport);
@@ -293,7 +386,157 @@ static bool misses_damage(const struct wlr_box *dst, pixman_region32_t *damage)
return dst->x - 2 >= extents->x2 || dst->x + dst->width + 2 <= extents->x1 ||
dst->y - 2 >= extents->y2 || dst->y + dst->height + 2 <= extents->y1;
}
-static bool render_entry(struct entry *e, struct wlr_scene_output *out,
+// ---- Effects: which blurs this frame re-takes (D1) ---------------------------------
+uint64_t rediwm_scene_output_reblurs; // read and reset by the performance stats
+struct attribution {
+ const struct output_view *view;
+ struct entry *entries;
+ size_t len;
+ struct wl_array events; // struct seen_event
+ pixman_region32_t explained; // device pixels events account for
+};
+struct seen_event { uint64_t leaf; struct wlr_box box; }; // device pixels
+static void note_event(const struct rediwm_damage_event *ev, void *data) {
+ struct attribution *a = data;
+ struct wlr_box box = device_box((struct wlr_box){ev->box.x, ev->box.y, ev->box.width, ev->box.height}, a->view);
+ // wlroots widens a scaled buffer's damage for filtering; so does this.
+ box = (struct wlr_box){box.x - 2, box.y - 2, box.width + 4, box.height + 4};
+ struct seen_event *se = wl_array_add(&a->events, sizeof(*se));
+ if (se) *se = (struct seen_event){ev->leaf, box};
+ pixman_region32_union_rect(&a->explained, &a->explained, box.x, box.y, box.width, box.height);
+}
+// Paint position of a leaf in this frame (0 = top), or -1 when it is not drawn.
+static long position_of(const struct attribution *a, uint64_t leaf) {
+ if (!leaf) return -1;
+ for (size_t i = 0; i < a->len; i++) if (a->entries[i].item.id == leaf) return (long)i;
+ return -1;
+}
+static bool boxes_meet(const struct wlr_box *a, const struct wlr_box *b) {
+ struct wlr_box out;
+ return wlr_box_intersection(&out, a, b);
+}
+static struct effect_cache *cache_for(struct output_state *os, uint64_t serial) {
+ struct effect_cache *c;
+ wl_list_for_each(c, &os->caches, link) if (c->serial == serial) return c;
+ c = calloc(1, sizeof(*c));
+ if (!c) return NULL;
+ c->serial = serial;
+ wl_list_insert(&os->caches, &c->link);
+ return c;
+}
+// Decides, bottom to top, which effects re-blur: a blur is kept unless something
+// painted below the effect, or something no event explains, changed in the region
+// it reads, or the region or sigma changed (a held effect keeps it while moving).
+// A re-blur repaints that whole region from the bottom (`expand`) and changes the
+// effect's own pixels (`changed`). Returns false on allocation failure.
+static bool decide_effects(struct rediwm_output_renderer *r, struct output_state *os,
+ struct wlr_scene_output *out, const struct output_view *v,
+ pixman_region32_t *expand, pixman_region32_t *changed) {
+ struct entry *entries = r->entries.data;
+ const size_t len = r->entries.size / sizeof(*entries);
+ struct attribution a = {.view = v, .entries = entries, .len = len};
+ wl_array_init(&a.events);
+ pixman_region32_init(&a.explained);
+ bool complete = os->started && rediwm_projection_damage_events(r->projection, &os->cursor, note_event, &a);
+ if (!os->started) {
+ os->cursor = rediwm_projection_damage_cursor(r->projection);
+ os->started = true;
+ }
+ pixman_region32_t unexplained;
+ pixman_region32_init(&unexplained);
+ pixman_region32_subtract(&unexplained, &out->private.pending_commit_damage, &a.explained);
+ struct effect_cache *c;
+ wl_list_for_each(c, &os->caches, link) c->seen = false;
+ bool ok = true;
+ for (size_t i = len; i > 0; i--) {
+ struct entry *e = &entries[i - 1];
+ if (e->item.kind != REDIWM_ITEM_EFFECT) continue;
+ e->cache = cache_for(os, e->glass.serial);
+ if (!e->cache) { ok = false; continue; }
+ c = e->cache;
+ c->seen = true;
+ const struct wlr_box region = device_box(e->padded, v);
+ const float sigma = e->sigma * v->scale;
+ const bool same_size = c->valid && c->sigma == sigma && c->region.width == region.width &&
+ c->region.height == region.height;
+ bool reblur = !same_size || !complete;
+ if (!reblur && (c->region.x != region.x || c->region.y != region.y)) {
+ // A held effect carries its last blur along; otherwise a move re-blurs.
+ if (e->glass.held) c->region = region;
+ else reblur = true;
+ }
+ if (!reblur && !e->glass.held) {
+ const long here = (long)(i - 1);
+ struct seen_event *se;
+ wl_array_for_each(se, &a.events) {
+ if (!boxes_meet(&se->box, &region)) continue;
+ const long at = position_of(&a, se->leaf);
+ if (at < 0 || at > here) { reblur = true; break; }
+ }
+ if (!reblur && pixman_region32_contains_rectangle(&unexplained,
+ &(pixman_box32_t){region.x, region.y, region.x + region.width, region.y + region.height}) != PIXMAN_REGION_OUT)
+ reblur = true;
+ // An effect below that re-blurs changes what this one reads.
+ for (size_t j = len; !reblur && j > i; j--) {
+ const struct entry *below = &entries[j - 1];
+ if (below->item.kind == REDIWM_ITEM_EFFECT && below->reblur) {
+ const struct wlr_box bb = device_box(below->box, v);
+ if (boxes_meet(&bb, &region)) reblur = true;
+ }
+ }
+ }
+ e->reblur = reblur;
+ if (reblur) {
+ pixman_region32_union_rect(expand, expand, region.x, region.y, region.width, region.height);
+ const struct wlr_box own = device_box(e->box, v);
+ pixman_region32_union_rect(changed, changed, own.x, own.y, own.width, own.height);
+ }
+ }
+ pixman_region32_fini(&unexplained);
+ pixman_region32_fini(&a.explained);
+ wl_array_release(&a.events);
+ return ok;
+}
+static void render_effect(struct entry *e, struct wlr_render_pass *pass, const struct output_view *v,
+ struct rediwm_output_renderer *r, struct wlr_renderer *renderer, const pixman_region32_t *clip) {
+ struct effect_cache *c = e->cache;
+ if (!c) return;
+ if (e->reblur) {
+ // The whole region was damaged and everything below is drawn: take it.
+ c->region = device_box(e->padded, v);
+ c->sigma = e->sigma * v->scale;
+ rediwm_scene_pass_capture_backdrop(pass, &c->backdrop, c->region, c->sigma);
+ c->valid = true;
+ rediwm_scene_output_reblurs++;
+ }
+ if (!c->valid || !c->backdrop || !pixman_region32_not_empty((pixman_region32_t *)clip)) return;
+ const struct wlr_box dst = device_box(e->box, v);
+ struct rediwm_pass_shape shape = {.box = dst};
+ if (e->item.clip) {
+ shape_for(&shape, e->item.clip, v);
+ } else {
+ const float radius = e->glass.radius * e->item.scale * v->scale;
+ for (int i = 0; i < 4; i++) shape.radii[i] = radius;
+ }
+ shape.border = 0;
+ struct rediwm_pass_backdrop o = {.backdrop = c->backdrop, .saturation = e->glass.saturation,
+ .opacity = e->glass.opacity * e->item.content.opacity, .clip = clip};
+ // The surface over the effect: its alpha is made up to the coverage.
+ struct entry *entries = r->entries.data;
+ const size_t len = r->entries.size / sizeof(*entries);
+ for (size_t i = 0; i < len; i++) {
+ struct entry *f = &entries[i];
+ if (f->transport != e->front || f->item.kind == REDIWM_ITEM_RECT) continue;
+ struct wlr_scene_buffer *b = wlr_scene_buffer_from_node(f->transport);
+ if (b->private.is_single_pixel_buffer || b->transform != WL_OUTPUT_TRANSFORM_NORMAL) break;
+ o.front = buffer_texture(b, renderer);
+ o.front_box = device_box(f->box, v);
+ o.front_opacity = f->item.content.opacity;
+ break;
+ }
+ rediwm_scene_pass_add_backdrop(pass, &shape, dst, &o);
+}
+static bool render_entry(struct rediwm_output_renderer *r, struct entry *e, struct wlr_scene_output *out,
struct wlr_render_pass *pass, const struct output_view *v, pixman_region32_t *damage) {
struct wlr_box dst = device_box(e->box, v);
if (misses_damage(&dst, damage)) return true;
@@ -305,6 +548,11 @@ static bool render_entry(struct entry *e, struct wlr_scene_output *out,
device_region(&clip, v, true);
pixman_region32_intersect(&clip, &clip, damage);
bool ok = true;
+ if (e->item.kind == REDIWM_ITEM_EFFECT) {
+ // A re-blur takes its blur even where the effect itself is hidden.
+ render_effect(e, pass, v, r, out->output->renderer, &clip);
+ goto done;
+ }
if (!pixman_region32_not_empty(&clip)) goto done;
// A clipped item is drawn in two parts: `core` (its interior, which the model
// proves fully covered and opaque) as before, without the shape, and the rest
@@ -430,6 +678,7 @@ bool rediwm_scene_output_build_state(struct rediwm_output_renderer *r,
if (v.scale != output->scale || v.transform != output->transform ||
v.width != output->width || v.height != output->height)
rediwm_scene_output_damage_whole(out);
+ r->projection = projection;
struct collector collector = {.renderer = r, .view = &v};
pixman_region32_init(&collector.covered);
bool collected = rediwm_projection_for_each_item(projection, true, collect, &collector);
@@ -441,6 +690,27 @@ bool rediwm_scene_output_build_state(struct rediwm_output_renderer *r,
}
struct entry *entries = r->entries.data;
size_t len = r->entries.size / sizeof(*entries);
+ // Effects decide before the damage is handed on: a re-blur changes the
+ // effect's pixels (reported and kept in the ring for the other buffers) and
+ // repaints the whole region it reads (this buffer only).
+ pixman_region32_t expand, changed;
+ pixman_region32_init(&expand);
+ pixman_region32_init(&changed);
+ struct output_state *os = r->has_backdrops ? output_state_get(r, output) : NULL;
+ if (os && !decide_effects(r, os, out, &v, &expand, &changed)) {
+ pixman_region32_fini(&expand);
+ pixman_region32_fini(&changed);
+ pixman_region32_fini(&collector.covered);
+ clear_entries(r);
+ return false;
+ }
+ if (pixman_region32_not_empty(&changed)) {
+ pixman_region32_intersect_rect(&changed, &changed, 0, 0, v.width, v.height);
+ wlr_damage_ring_add(&out->damage_ring, &changed);
+ pixman_region32_union(&out->private.pending_commit_damage,
+ &out->private.pending_commit_damage, &changed);
+ }
+ pixman_region32_fini(&changed);
wlr_output_state_set_damage(state, &out->private.pending_commit_damage);
bool scanout = len == 1 && try_scanout(&entries[0], out, state, &v);
if (out->private.prev_scanout != scanout) {
@@ -461,6 +731,7 @@ bool rediwm_scene_output_build_state(struct rediwm_output_renderer *r,
pixman_region32_init(&damage);
pixman_region32_init(&background);
wlr_damage_ring_rotate_buffer(&out->damage_ring, buffer, &damage);
+ pixman_region32_union(&damage, &damage, &expand);
pixman_region32_intersect_rect(&damage, &damage, 0, 0, v.width, v.height);
device_region(&collector.covered, &v, false);
pixman_region32_subtract(&background, &damage, &collector.covered);
@@ -472,7 +743,7 @@ bool rediwm_scene_output_build_state(struct rediwm_output_renderer *r,
.box = {0, 0, buffer->width, buffer->height}, .color = {0, 0, 0, 1}, .clip = &background});
ok = true;
for (size_t i = len; i > 0; i--)
- if (!render_entry(&entries[i - 1], out, pass, &v, &damage)) ok = false;
+ if (!render_entry(r, &entries[i - 1], out, pass, &v, &damage)) ok = false;
wlr_output_add_software_cursors_to_render_pass(output, pass, &damage);
bool submitted = wlr_render_pass_submit(pass);
// Successful reads still need release points when another item failed to
@@ -491,7 +762,17 @@ bool rediwm_scene_output_build_state(struct rediwm_output_renderer *r,
done:
if (buffer) wlr_buffer_unlock(buffer);
if (!ok) rediwm_scene_output_damage_whole(out);
+ pixman_region32_fini(&expand);
pixman_region32_fini(&collector.covered);
+ if (os) {
+ // Outside the pass: drop the blurs of effects this output no longer shows;
+ // after a failed frame, trust none of them.
+ struct effect_cache *c, *next;
+ wl_list_for_each_safe(c, next, &os->caches, link) {
+ if (!ok) c->valid = false;
+ if (!c->seen) cache_destroy(r, c);
+ }
+ }
clear_entries(r);
return ok;
}
diff --git a/src/scene_output.h b/src/scene_output.h
index 1a65d2c..7944de9 100644
--- a/src/scene_output.h
+++ b/src/scene_output.h
@@ -12,6 +12,8 @@ struct rediwm_output_renderer *rediwm_output_renderer_create(struct wlr_renderer
// Builds the programs that draw rounded shapes (see scene_pass.h); false if they
// did not build, in which case no window may be given a shape.
bool rediwm_output_renderer_enable_shapes(struct rediwm_output_renderer *);
+// Glass in the pass (stage 5c); requires shapes. False: glass is the surface's own tint.
+bool rediwm_output_renderer_enable_backdrops(struct rediwm_output_renderer *);
void rediwm_output_renderer_destroy(struct rediwm_output_renderer *);
// Node-subset capture uses the same drawing backend with its own swapchain
// and ReadFence; it must not inherit output culling or screen geometry.
diff --git a/src/scene_output.zig b/src/scene_output.zig
index 27a03cf..3fb3e7d 100644
--- a/src/scene_output.zig
+++ b/src/scene_output.zig
@@ -1,11 +1,17 @@
const wlr = @import("wlroots");
const Projection = @import("projection.zig").Projection;
+extern var rediwm_scene_output_reblurs: u64;
+/// Glass blurs the output pass re-took (stage 5c), for the performance stats.
+pub const reblurs: *u64 = &rediwm_scene_output_reblurs;
+
pub const Renderer = opaque {
extern fn rediwm_output_renderer_create(renderer: *wlr.Renderer) ?*Renderer;
pub const create = rediwm_output_renderer_create;
extern fn rediwm_output_renderer_enable_shapes(renderer: *Renderer) bool;
pub const enableShapes = rediwm_output_renderer_enable_shapes;
+ extern fn rediwm_output_renderer_enable_backdrops(renderer: *Renderer) bool;
+ pub const enableBackdrops = rediwm_output_renderer_enable_backdrops;
extern fn rediwm_output_renderer_destroy(renderer: ?*Renderer) void;
pub const destroy = rediwm_output_renderer_destroy;
extern fn rediwm_scene_output_build_state(renderer: *Renderer, projection: *Projection, output: *wlr.SceneOutput, state: *wlr.Output.State) bool;
diff --git a/tests/glass_reblur.py b/tests/glass_reblur.py
new file mode 100644
index 0000000..750d23f
--- /dev/null
+++ b/tests/glass_reblur.py
@@ -0,0 +1,93 @@
+#!/usr/bin/env python3
+"""When glass re-blurs (stage 5c of docs/plans/scene-graph-stage5.md, D1).
+
+The output pass keeps each glass effect's blur and re-takes it only when
+something painted below the effect changed in the region the blur reads. Two
+clients repaint with full damage every frame:
+
+* window A's own client lies inside its titlebar's blur region but above the
+ effect: A's titlebar must not re-blur;
+* window B, below A and inside that region, must make it re-blur every frame;
+ moved out of the region, it must not;
+* moving A re-blurs its titlebar.
+
+Counts come from `glass_reblurs` in the performance stats. Runs at scales 1 and
+1.5 on GLES2; never connects to the host desktop.
+"""
+import os
+from pathlib import Path
+import subprocess
+import tempfile
+import time
+
+from desktop_zoom import build_client, wait_for
+from ipc_client import IPCClient, spawn_compositor, stop_process
+
+
+def reblurs_over(ipc, seconds):
+ ipc.action("reset_performance_stats")
+ time.sleep(seconds)
+ perf = ipc.get_perf()
+ return perf["glass_reblurs"], perf["output_commits"]
+
+
+def run(scale):
+ with tempfile.TemporaryDirectory(prefix="rediwm-glass-reblur-") as directory:
+ tmp = Path(directory)
+ build_client(tmp)
+ config = '[compositor]\nxwayland = false\n[desktop]\nenabled = false\n[animations]\nreduced_motion = "on"\n'
+ process, log = spawn_compositor(tmp, scale=str(scale), config_content=config,
+ env_extra={"DBUS_SESSION_BUS_ADDRESS": "", "REDIWM_TEST_DECORATION": "server"})
+ clients = []
+ try:
+ with IPCClient(tmp) as ipc:
+ ipc.wait_for("wallpaper_presented", timeout_ms=10000)
+ display = next(p.name for p in tmp.glob("wayland-*") if not p.name.endswith(".lock"))
+
+ def start(name, color):
+ live = tmp / f"{name}.live"
+ live.write_text(f"{color} 400 260 {name}")
+ clients.append(subprocess.Popen(
+ [str(tmp / "client")], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL,
+ env=dict(os.environ, XDG_RUNTIME_DIR=str(tmp), WAYLAND_DISPLAY=display,
+ REDIWM_TEST_LIVE_FILE=str(live))))
+ return wait_for(lambda: next((w for w in ipc.get_windows() if w["title"] == name), None),
+ f"{name} did not map")
+
+ # B first, so A (mapped later) is above it.
+ b = start("B", "ff40a060")
+ a = start("A", "ff203040")
+ ipc.action("move_window_to", {"id": a["id"], "x": 200, "y": 150})
+ ipc.action("move_window_to", {"id": b["id"], "x": 150, "y": 100})
+ ipc.move_cursor(5, 5)
+ time.sleep(.6)
+ assert [w["title"] for w in ipc.get_windows()][-1] in ("A", "B")
+
+ reblurs, commits = reblurs_over(ipc, 1)
+ assert commits > 20, ("clients did not keep repainting", commits)
+ assert reblurs >= commits // 2, ("a window below did not re-blur the titlebar above it", scale, reblurs, commits)
+
+ # B out of the region A's titlebar blur reads: A's own client keeps
+ # repainting under the titlebar, but it is above the effect.
+ ipc.action("move_window_to", {"id": b["id"], "x": 760, "y": 60})
+ time.sleep(.4)
+ reblurs, commits = reblurs_over(ipc, 1)
+ assert commits > 20, ("clients did not keep repainting", commits)
+ assert reblurs == 0, ("glass re-blurred for damage above it", scale, reblurs, commits)
+
+ # Moving the window re-blurs its titlebar.
+ ipc.action("reset_performance_stats")
+ ipc.action("move_window_to", {"id": a["id"], "x": 210, "y": 150})
+ time.sleep(.3)
+ assert ipc.get_perf()["glass_reblurs"] >= 1, ("a moved titlebar kept its old blur", scale)
+ print(f"PASS scale {scale}: glass re-blurs for changes below it, never for its own client")
+ finally:
+ for client in clients:
+ stop_process(client)
+ stop_process(process)
+ log.close()
+
+
+if __name__ == "__main__":
+ for scale in (1, 1.5):
+ run(scale)