Skip to content

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

scene graph plan, stage 5f: quarter-size backdrops

oxydizer276c5769ac68
diff --git a/AGENTS.md b/AGENTS.md
index 7bec4f2..78cb4fa 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -49,18 +49,21 @@ the one for the directory you work in: `src/files`, `src/editor`,
stays): persist raster sizes.
* **Glass is drawn by the output pass** (stage 5, `docs/plans/scene-graph-stage5.md`).
`glass.c` only registers effects: a bufferless node just below its target, to
- which resolve gives the target's box. `scene_output.c` copies the framebuffer
- under the effect's padded extent (target + 3 sigma), blurs it at quarter size
- and composites it through the shape (shaped program mode 3), keeping one blur
- per effect and output. A kept blur is re-taken only when a damage event from a
- leaf painted *below* the effect, or damage no event explains, meets that
- extent, or the region or sigma changed; a re-blur repaints the whole extent
- first (with buffer age, pixels outside damage are last frame's final image),
- and collect never culls items below an effect inside it. Damage a new kind of
- change through the projection's events or it counts as below (safe, slower).
- Holds (a dragged titlebar at ≥ 0.98 opacity, camera motion) carry the blur and
- re-take it once released. Per output, so mixed scales stay idle
- (`glass_hold.py`); attribution is checked by `glass_reblur.py`.
+ which resolve gives the target's box. When an effect re-blurs, `scene_output.c`
+ redirects the pass (`rediwm_scene_pass_begin_backdrop`) and draws the items
+ below it into an image a quarter of the logical size of its padded extent
+ (target + 3 sigma), blurs that and composites it through the shape (shaped
+ program mode 3), keeping one blur per effect and output. A kept blur is
+ re-taken only when a damage event from a leaf painted *below* the effect, or
+ damage no event explains, meets that extent, or the region or sigma changed.
+ Only leaves that put pixels on screen have damage events (an input-only node
+ must not, or it reads as a change below glass), and the software cursor's
+ damage counts as explained. Damage a new kind of change through the
+ projection's events or it counts as below (safe, slower). Collect keeps items an
+ effect reads even where surfaces above hide them (`reads`). Holds (a dragged
+ titlebar at ≥ 0.98 opacity, camera motion) carry the blur and re-take it once
+ released. Per output, so mixed scales stay idle (`glass_hold.py`); attribution
+ is checked by `glass_reblur.py`.
* **Owned GL beside wlroots:** wlroots draws with client-side vertex arrays, so
any GL work of ours must put `GL_ARRAY_BUFFER` (and the rest of the state it
touched) back before a wlroots pass runs, as `scene_pass.c`'s `leave()` does; a quad
diff --git a/docs/plans/scene-graph-stage5.md b/docs/plans/scene-graph-stage5.md
index 60340b3..9042996 100644
--- a/docs/plans/scene-graph-stage5.md
+++ b/docs/plans/scene-graph-stage5.md
@@ -1,6 +1,6 @@
# Scene graph plan, stage 5: backdrop effects in the pass
-Status: **5a to 5e done; the gate leaves one finding open (GPU at fractional scale)**, 2026-10-11. Decisions taken (all as recommended). Stage 4 of
+Status: **done**, 2026-10-11: 5a to 5f; 5f resolved the stage gate's GPU finding. Decisions taken (all as recommended). Stage 4 of
[scene-graph.md](scene-graph.md) is done (window shapes, analytic shadows, the
owned pass as the only presenter). This stage moves glass, the blurred backdrop
behind titlebars, the taskbar and the start and power menus, from its side
@@ -250,6 +250,44 @@ once, after 5e (see [scene-graph-stage4.md](scene-graph-stage4.md), Measurement)
the effect into the small target.
* glass_hold.py's drag comparison and the start menu's outer column (5c).
+## 5f. Quarter-size backdrops (decided 2026-10-11: fix the GPU finding)
+
+A re-blur draws the items below the effect, bottom up, straight into a
+quarter-size image of its padded extent inside the pass (a redirect: between
+`rediwm_scene_pass_begin_backdrop` and `_end_backdrop` every draw lands in the
+small image, boxes and scissors scaled by a quarter), then blurs that image. No
+framebuffer copy, no repaint of the extent at full resolution, no damage
+expansion: a re-blur changes only the effect's own box. Collect keeps items an
+effect reads even where opaque surfaces above hide them, as backdrop-only
+entries the main pass does not draw. Gates: the 5b pixel gates on the new
+capture, `glass_reblur.py`, the glass comparison against glass.c, and a
+same-day GPU comparison against 5e at scale 1.5.
+
+*Done.* Three changes, each measured in a same-session A/B against stage 4
+(ReleaseSafe, performance profile, `scene_baseline.py`, which now records
+`glass_reblurs`):
+* **Draw below, at reduced size.** `rediwm_scene_pass_begin_backdrop`/`_end_backdrop`
+ redirect the pass (boxes, shape origins and scissors move into the image) and
+ `render_entry` draws the items below in a backdrop mode (whole box, not what is
+ visible on screen), skipping items that opaque items below the effect hide.
+ `capture_backdrop`, the framebuffer copy and the damage expansion are gone.
+* **A quarter of the logical size**, as glass.c blurred (factor 4 times the
+ output scale): a quarter of the device size cost 2.25 times the pixels at 1.5.
+ At factor 6 a band edge moves by up to half a reduced pixel, so the blur gate
+ bounds it at 15 levels there (2 where the grid aligns); glass.c had the same.
+* **Damage events only for leaves that paint.** A drag re-blurred 2.74 effects
+ a frame: the dragged window's resize grab, an input-only node, moved with it,
+ was in no frame's list and so read as a change below two other titlebars. Now
+ a drag re-blurs once a frame (its own titlebar), a resize 1.28 times.
+Result (final run): against stage 4, GPU in the glass cells -3 to -38 % except
+`drag` (+1 % at scale 1, -7 % at 1.5, +4 % mixed) and `zoom_70` at scale 1
+(+11 %, within its stage 4 pair's 50 % spread); whole-frame CPU -8 to -43 %; anonymous memory
+0.05 to 0.6 MiB below stage 4 in every cell; idle zero. The fullscreen cell is
+not comparable across sessions (the client's own rate varied from 118 to 229
+commits). Glass against glass.c: titlebar within 5 levels, taskbar within 1,
+start menu as in 5c. The software cursor's boxes now count as explained damage
+(it is drawn over everything), which keeps headless and nested runs honest.
+
## Risks
* **Stale blur.** Missing a below-damage leaves an old blur on screen. The
diff --git a/docs/plans/scene-graph.md b/docs/plans/scene-graph.md
index c9bdfd8..47a7919 100644
--- a/docs/plans/scene-graph.md
+++ b/docs/plans/scene-graph.md
@@ -158,7 +158,7 @@ environment variable: no test hooks in production), removed in stage 6.
Clip groups on frames, analytic borders and
shadows, shape-aware hit testing; delete the skirt, `probeClientEdge`,
`side_fills`, the dual border path and `edge_sampling.py`; shrink the footer.
-5. **Backdrop effects in the pass.** *Done 2026-10-11 apart from one gate finding (GPU at fractional scale while glass re-blurs):
+5. **Backdrop effects in the pass.** *Done 2026-10-11 (CPU and GPU at or below stage 4 where glass re-blurs, memory below it):
[scene-graph-stage5.md](scene-graph-stage5.md).* Delete `glass.c`'s prefix capture,
per-effect contexts, dependency hashing and the drag hold; keep glass pixel
tests, converted.
diff --git a/src/projection.c b/src/projection.c
index a2859f6..1637d6b 100644
--- a/src/projection.c
+++ b/src/projection.c
@@ -833,13 +833,26 @@ static void present_leaf(struct group *g, struct leaf *l,
next.content = item->content;
// Damage events: a moved, resized, shown, hidden or restyled leaf changes its
// old and its new box; otherwise only what a new buffer or commit damaged.
- const bool restyled = !l->has_shown || !next.enabled || snap.x != l->shown.x ||
+ // Only a leaf that puts pixels on screen has them: an input-only node (a
+ // resize grab) moving with its window must not read as a change below glass,
+ // and the pass draws effects itself (shadows report in damage_shadow).
+ bool paints = next.enabled;
+ if (item->kind == REDIWM_ITEM_RECT) {
+ paints = paints && item->content.color[3] > 0;
+ } else if (item->kind == REDIWM_ITEM_EFFECT || item->kind == REDIWM_ITEM_SHADOW) {
+ paints = false;
+ } else {
+ const struct wlr_scene_buffer *sb = wlr_scene_buffer_from_node(l->source);
+ paints = paints && item->content.opacity > 0 &&
+ (sb->buffer || (l->surface && l->surface->surface->buffer));
+ }
+ const bool restyled = !l->has_shown || !paints || snap.x != l->shown.x ||
snap.y != l->shown.y || snap.width != l->shown.width ||
snap.height != l->shown.height ||
!rediwm_content_equal(&item->content, &l->shown_content);
if (restyled) {
forget_shown(l);
- if (next.enabled) {
+ if (paints) {
emit_snap(l, snap);
l->shown = snap;
l->shown_content = item->content;
diff --git a/src/projection_test.c b/src/projection_test.c
index 1682cbc..6f85e14 100644
--- a/src/projection_test.c
+++ b/src/projection_test.c
@@ -778,6 +778,16 @@ static void test_damage_events(struct wlr_scene *scene) {
seen = events_since(p, &cursor, NULL);
assert(seen.count == 1 && event_is(&seen.last[0], gone, 50, 130, 20, 20));
+ // A leaf that draws nothing (an input-only node such as a resize grab) has no
+ // events, however it moves: glass would otherwise take it for a change below.
+ struct wlr_scene_buffer *grab = wlr_scene_buffer_create(window, NULL);
+ wlr_scene_buffer_set_dest_size(grab, 300, 300);
+ rediwm_projection_sync(p, 1, 0, 0, 0, 0);
+ wlr_scene_node_set_position(&grab->node, 5, 5);
+ rediwm_projection_sync(p, 1, 0, 0, 0, 0);
+ wlr_scene_node_destroy(&grab->node);
+ assert(events_since(p, &cursor, NULL).count == 0);
+
// A second consumer read nothing yet and sees everything since its cursor.
bool complete = false;
seen = events_since(p, &other, &complete);
diff --git a/src/scene_output.c b/src/scene_output.c
index 15c8f3c..d07aad9 100644
--- a/src/scene_output.c
+++ b/src/scene_output.c
@@ -42,6 +42,9 @@ struct output_state {
struct wl_listener destroy;
uint64_t cursor; // into the projection's damage events
bool started;
+ // Software cursors drawn last frame (device pixels), whose damage now is old.
+ struct wlr_box cursors[4];
+ int ncursors;
struct wl_list caches;
};
struct entry {
@@ -60,6 +63,8 @@ struct entry {
struct effect_cache *cache;
bool reblur;
};
+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, bool backdrop);
struct rediwm_output_renderer {
struct rediwm_scene_renderer *pass;
struct wl_array entries; // reusable scratch; no retained resource references
@@ -203,6 +208,9 @@ struct collector {
struct rediwm_clip cover_of;
pixman_region32_t cover;
bool has_cover;
+ // What the effects visited so far read (layout): items there are kept even
+ // where surfaces above hide them, for the blurs only (stage 5f).
+ pixman_region32_t reads;
};
static bool same_clip(const struct rediwm_clip *a, const struct rediwm_clip *b) {
if (a->edges.x1 != b->edges.x1 || a->edges.y1 != b->edges.y1 || a->edges.x2 != b->edges.x2 ||
@@ -241,7 +249,12 @@ static bool collect(const struct rediwm_item *item, struct wlr_scene_node *trans
pixman_region32_t visible;
pixman_region32_init_rect(&visible, intersection.x, intersection.y, intersection.width, intersection.height);
pixman_region32_subtract(&visible, &visible, &collector->covered);
- if (!pixman_region32_not_empty(&visible)) { pixman_region32_fini(&visible); return true; }
+ if (!pixman_region32_not_empty(&visible) &&
+ pixman_region32_contains_rectangle(&collector->reads, &(pixman_box32_t){intersection.x, intersection.y,
+ intersection.x + intersection.width, intersection.y + intersection.height}) == PIXMAN_REGION_OUT) {
+ pixman_region32_fini(&visible);
+ return true;
+ }
struct entry *e = wl_array_add(&r->entries, sizeof(*e));
if (!e) { pixman_region32_fini(&visible); return false; }
*e = (struct entry){.item = *item, .transport = transport,
@@ -249,16 +262,14 @@ static bool collect(const struct rediwm_item *item, struct wlr_scene_node *trans
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).
+ // paint order, including what opaque surfaces above hide on screen: items
+ // there stay in the list for it (`reads`), not for the screen.
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);
+ pixman_region32_union_rect(&collector->reads, &collector->reads,
+ e->padded.x, e->padded.y, e->padded.width, e->padded.height);
struct wlr_scene_node *front = rediwm_projection_node(r->projection, &glass.target->node);
e->front = front ? front : &glass.target->node;
return true;
@@ -429,11 +440,10 @@ static struct effect_cache *cache_for(struct output_state *os, uint64_t serial)
// 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.
+// A re-blur 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 wlr_scene_output *out, const struct output_view *v, 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};
@@ -444,6 +454,25 @@ static bool decide_effects(struct rediwm_output_renderer *r, struct output_state
os->cursor = rediwm_projection_damage_cursor(r->projection);
os->started = true;
}
+ // A software cursor is drawn over everything, so its damage (where it was and
+ // where it is) never changes what a blur reads.
+ struct wlr_output_cursor *cursor;
+ int ncursors = 0;
+ struct wlr_box cursors[4];
+ wl_list_for_each(cursor, &out->output->cursors, link) {
+ if (ncursors == 4 || !cursor->enabled || !cursor->visible || cursor == out->output->hardware_cursor) continue;
+ cursors[ncursors++] = (struct wlr_box){(int)floor(cursor->x) - cursor->hotspot_x - 4,
+ (int)floor(cursor->y) - cursor->hotspot_y - 4, (int)cursor->width + 8, (int)cursor->height + 8};
+ }
+ for (int i = 0; i < os->ncursors; i++)
+ pixman_region32_union_rect(&a.explained, &a.explained, os->cursors[i].x, os->cursors[i].y,
+ os->cursors[i].width, os->cursors[i].height);
+ for (int i = 0; i < ncursors; i++) {
+ pixman_region32_union_rect(&a.explained, &a.explained, cursors[i].x, cursors[i].y,
+ cursors[i].width, cursors[i].height);
+ os->cursors[i] = cursors[i];
+ }
+ os->ncursors = ncursors;
pixman_region32_t unexplained;
pixman_region32_init(&unexplained);
pixman_region32_subtract(&unexplained, &out->private.pending_commit_damage, &a.explained);
@@ -493,7 +522,6 @@ static bool decide_effects(struct rediwm_output_renderer *r, struct output_state
}
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);
}
@@ -504,14 +532,55 @@ static bool decide_effects(struct rediwm_output_renderer *r, struct output_state
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 rediwm_output_renderer *r, struct wlr_scene_output *out, const pixman_region32_t *clip,
+ bool backdrop) {
struct effect_cache *c = e->cache;
if (!c) return;
- if (e->reblur) {
- // The whole region was damaged and everything below is drawn: take it.
+ struct wlr_renderer *renderer = out->output->renderer;
+ if (e->reblur && !backdrop && !pixman_region32_not_empty((pixman_region32_t *)clip)) {
+ // Hidden here (kept only for another effect's blur): re-take it when shown.
+ c->valid = false;
+ return;
+ }
+ if (e->reblur && !backdrop) {
+ // Draw what lies below the effect, bottom up, into a quarter-size image of
+ // the region the blur reads, and blur that (stage 5f): no full-size copy.
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);
+ // A quarter of the logical size, as glass.c blurred: the same pixels at any
+ // scale (a quarter of the device size cost 2.25 times more at 1.5).
+ rediwm_scene_pass_begin_backdrop(pass, c->region, 4 * (float)v->scale);
+ struct entry *entries = r->entries.data;
+ const size_t len = r->entries.size / sizeof(*entries);
+ const size_t here = (size_t)(e - entries);
+ // Cull within the blur's region as the screen is culled: walking down from
+ // the effect, an item that opaque items below the effect hide entirely is
+ // not drawn (a fullscreen client under the taskbar hides everything else).
+ pixman_region32_t region, hidden;
+ pixman_region32_init_rect(&region, c->region.x, c->region.y, c->region.width, c->region.height);
+ pixman_region32_init(&hidden);
+ bool draw[len];
+ for (size_t j = here + 1; j < len; j++) {
+ struct entry *below = &entries[j];
+ const struct wlr_box b = device_box(below->box, v);
+ draw[j] = pixman_region32_contains_rectangle(&region, &(pixman_box32_t){b.x, b.y, b.x + b.width,
+ b.y + b.height}) != PIXMAN_REGION_OUT &&
+ pixman_region32_contains_rectangle(&hidden, &(pixman_box32_t){b.x, b.y, b.x + b.width,
+ b.y + b.height}) != PIXMAN_REGION_IN;
+ if (draw[j] && pixman_region32_not_empty(&below->opaque)) {
+ pixman_region32_t opaque;
+ pixman_region32_init(&opaque);
+ pixman_region32_copy(&opaque, &below->opaque);
+ device_region(&opaque, v, false);
+ pixman_region32_union(&hidden, &hidden, &opaque);
+ pixman_region32_fini(&opaque);
+ }
+ }
+ for (size_t j = len; j > here + 1; j--)
+ if (draw[j - 1]) render_entry(r, &entries[j - 1], out, pass, v, &region, true);
+ pixman_region32_fini(&hidden);
+ pixman_region32_fini(&region);
+ rediwm_scene_pass_end_backdrop(pass, &c->backdrop, c->sigma);
c->valid = true;
c->carried = false;
rediwm_scene_output_reblurs++;
@@ -543,21 +612,27 @@ static void render_effect(struct entry *e, struct wlr_render_pass *pass, const s
}
rediwm_scene_pass_add_backdrop(pass, &shape, dst, &o);
}
+// `backdrop`: drawing into an effect's quarter-size image (stage 5f), where an
+// item counts with its whole box, not what is visible of it on screen, and
+// `damage` is the region the blur reads.
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_render_pass *pass, const struct output_view *v, pixman_region32_t *damage, bool backdrop) {
struct wlr_box dst = device_box(e->box, v);
if (misses_damage(&dst, damage)) return true;
pixman_region32_t clip, blend, core;
pixman_region32_init(&clip);
pixman_region32_init(&blend);
pixman_region32_init(&core);
- pixman_region32_copy(&clip, &e->visible);
- device_region(&clip, v, true);
+ if (backdrop) pixman_region32_init_rect(&clip, dst.x, dst.y, dst.width, dst.height);
+ else {
+ pixman_region32_copy(&clip, &e->visible);
+ 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);
+ render_effect(e, pass, v, r, out, &clip, backdrop);
goto done;
}
if (!pixman_region32_not_empty(&clip)) goto done;
@@ -688,8 +763,10 @@ bool rediwm_scene_output_build_state(struct rediwm_output_renderer *r,
r->projection = projection;
struct collector collector = {.renderer = r, .view = &v};
pixman_region32_init(&collector.covered);
+ pixman_region32_init(&collector.reads);
bool collected = rediwm_projection_for_each_item(projection, true, collect, &collector);
if (collector.has_cover) pixman_region32_fini(&collector.cover);
+ pixman_region32_fini(&collector.reads);
if (!collected) {
pixman_region32_fini(&collector.covered);
clear_entries(r);
@@ -700,12 +777,10 @@ bool rediwm_scene_output_build_state(struct rediwm_output_renderer *r,
// 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_t changed;
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);
+ if (os && !decide_effects(r, os, out, &v, &changed)) {
pixman_region32_fini(&changed);
pixman_region32_fini(&collector.covered);
clear_entries(r);
@@ -738,7 +813,6 @@ 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);
@@ -750,7 +824,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(r, &entries[i - 1], out, pass, &v, &damage)) ok = false;
+ if (!render_entry(r, &entries[i - 1], out, pass, &v, &damage, false)) 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
@@ -769,7 +843,6 @@ 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;
diff --git a/src/scene_pass.c b/src/scene_pass.c
index c30a963..dc57815 100644
--- a/src/scene_pass.c
+++ b/src/scene_pass.c
@@ -29,8 +29,9 @@ struct program {
};
struct rediwm_backdrop {
GLuint tex, fbo;
- int width, height; // quarter size
- struct wlr_box region; // device pixels the blur covers
+ int width, height; // the reduced size
+ int x, y; // device pixel the image starts at
+ float extent_w, extent_h; // device pixels it covers (width * factor)
};
struct attrib_state {
GLint enabled, size, type, normalized, stride, buffer;
@@ -55,8 +56,8 @@ struct rediwm_scene_renderer {
// Backdrops (stage 5b), built by enable_backdrops: the blur, and scratch the
// size of the largest region so far: the copy, and the horizontal pass.
struct program blur;
- GLuint copy_tex, small_tex, small_fbo;
- int copy_w, copy_h, small_w, small_h;
+ GLuint prefix_tex, prefix_fbo, small_tex, small_fbo;
+ int small_w, small_h;
bool has_backdrops, backdrops_tried;
bool active, has_external, has_sync, has_vao, has_shapes, shapes_tried;
GLuint vertex_array, vertices;
@@ -79,6 +80,12 @@ struct pass {
GLuint program;
unsigned targets_set;
int blend_mode;
+ // Between begin_backdrop and end_backdrop draws land in a quarter-size image
+ // of `region` (stage 5f): boxes move by its origin, scissors shrink by four.
+ bool redirected;
+ struct wlr_box region, valid; // device pixels; `valid` is the part in the buffer
+ float factor; // device pixels per pixel of the image
+ int small_w, small_h;
};
static bool enter(struct rediwm_scene_renderer *r, struct gl_state *s) {
@@ -358,7 +365,8 @@ void rediwm_scene_renderer_destroy(struct rediwm_scene_renderer *r) {
glDeleteProgram(r->shaped.id);
glDeleteProgram(r->shaped_external.id);
glDeleteProgram(r->blur.id);
- glDeleteTextures(1, &r->copy_tex);
+ glDeleteTextures(1, &r->prefix_tex);
+ glDeleteFramebuffers(1, &r->prefix_fbo);
glDeleteTextures(1, &r->small_tex);
glDeleteFramebuffers(1, &r->small_fbo);
leave(r, &state);
@@ -373,16 +381,21 @@ static void setup(struct pass *p, struct program *program, struct wlr_box box,
p->program = program->id;
}
if (!(p->targets_set & program->bit)) {
- glUniform2f(program->target, p->buffer->width, p->buffer->height);
+ if (p->redirected) glUniform2f(program->target, p->small_w * p->factor, p->small_h * p->factor);
+ else glUniform2f(program->target, p->buffer->width, p->buffer->height);
p->targets_set |= program->bit;
}
+ if (p->redirected) {
+ box.x -= p->region.x;
+ box.y -= p->region.y;
+ }
glUniform4f(program->dst, box.x, box.y, box.width, box.height);
if (p->blend_mode != (int)blend) {
(blend == WLR_RENDER_BLEND_MODE_NONE ? glDisable : glEnable)(GL_BLEND);
p->blend_mode = blend;
}
}
-static void draw(const pixman_region32_t *clip) {
+static void draw(const struct pass *p, const pixman_region32_t *clip) {
if (!clip) {
glDisable(GL_SCISSOR_TEST);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
@@ -392,7 +405,16 @@ static void draw(const pixman_region32_t *clip) {
const pixman_box32_t *boxes = pixman_region32_rectangles((pixman_region32_t *)clip, &n);
glEnable(GL_SCISSOR_TEST);
for (int i = 0; i < n; i++) {
- glScissor(boxes[i].x1, boxes[i].y1, boxes[i].x2 - boxes[i].x1, boxes[i].y2 - boxes[i].y1);
+ if (p->redirected) {
+ // Outward to whole small pixels; the region's origin is a multiple of none.
+ const int x1 = (int)floorf((boxes[i].x1 - p->region.x) / p->factor);
+ const int y1 = (int)floorf((boxes[i].y1 - p->region.y) / p->factor);
+ const int x2 = (int)ceilf((boxes[i].x2 - p->region.x) / p->factor);
+ const int y2 = (int)ceilf((boxes[i].y2 - p->region.y) / p->factor);
+ glScissor(x1, y1, x2 - x1, y2 - y1);
+ } else {
+ glScissor(boxes[i].x1, boxes[i].y1, boxes[i].x2 - boxes[i].x1, boxes[i].y2 - boxes[i].y1);
+ }
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
}
@@ -404,9 +426,10 @@ static bool shape_usable(const struct rediwm_pass_shape *s) {
for (int i = 0; i < 4; i++) if (!isfinite(s->border_color[i])) return false;
return true;
}
-static void set_shape(const struct program *g, const struct rediwm_pass_shape *s) {
+static void set_shape(const struct pass *p, const struct program *g, const struct rediwm_pass_shape *s) {
glUniform1f(g->use_shape, 1.f);
- glUniform2f(g->origin, s->box.x, s->box.y);
+ if (p->redirected) glUniform2f(g->origin, s->box.x - p->region.x, s->box.y - p->region.y);
+ else glUniform2f(g->origin, s->box.x, s->box.y);
glUniform2f(g->size, s->box.width, s->box.height);
glUniform4f(g->radii, s->radii[0], s->radii[1], s->radii[2], s->radii[3]);
glUniform1f(g->border, s->border);
@@ -423,7 +446,7 @@ static void add_rect(struct wlr_render_pass *base, const struct wlr_render_rect_
glUniform4f(g->color, o->color.r, o->color.g, o->color.b, o->color.a);
glUniform1f(g->mode, 1.f);
glUniform1f(g->use_shape, 0.f);
- draw(o->clip);
+ draw(p, o->clip);
}
static void rect_shaped(struct pass *p, const struct wlr_render_rect_options *o,
const struct rediwm_pass_shape *shape) {
@@ -435,8 +458,8 @@ static void rect_shaped(struct pass *p, const struct wlr_render_rect_options *o,
setup(p, g, box, o->blend_mode);
glUniform4f(g->color, o->color.r, o->color.g, o->color.b, o->color.a);
glUniform1f(g->mode, 1.f);
- set_shape(g, shape);
- draw(o->clip);
+ set_shape(p, g, shape);
+ draw(p, o->clip);
}
static bool wait_point(struct pass *p, struct wlr_drm_syncobj_timeline *timeline, uint64_t point) {
if (!timeline) return true;
@@ -491,9 +514,9 @@ static void texture_draw(struct pass *p, const struct wlr_render_texture_options
}
glUniform4fv(program->coords, 2, uv);
glUniform1f(program->mode, 0.f);
- if (shape) set_shape(program, shape);
+ if (shape) set_shape(p, program, shape);
else glUniform1f(program->use_shape, 0.f);
- draw(o->clip);
+ draw(p, o->clip);
}
static void texture_add(struct wlr_render_pass *base, const struct wlr_render_texture_options *o,
const struct rediwm_pass_shape *shape) {
@@ -620,12 +643,12 @@ void rediwm_scene_pass_add_shadow(struct wlr_render_pass *base,
glUniform4f(g->color, shadow->color[0], shadow->color[1], shadow->color[2], shadow->color[3]);
struct rediwm_pass_shape bare = *shape; // the shadow has no border of its own
bare.border = 0;
- set_shape(g, &bare);
+ set_shape(p, g, &bare);
glUniform1f(g->mode, 2.f);
glUniform2f(g->offset, shadow->offset_x, shadow->offset_y);
glUniform1f(g->softness, softness);
glUniform1f(g->hide, shadow->hide_inside ? 1.f : 0.f);
- draw(shadow->clip);
+ draw(p, shadow->clip);
}
// ---- Backdrops (stage 5b) -------------------------------------------------------
@@ -658,23 +681,19 @@ static bool attach(GLuint fbo, GLuint tex) {
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex, 0);
return glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE;
}
-// Scratch grows to the largest region seen; it is shared by every effect.
-static bool scratch(struct rediwm_scene_renderer *r, int copy_w, int copy_h, int small_w, int small_h) {
- if (!r->copy_tex) glGenTextures(1, &r->copy_tex);
+// Two quarter-size scratch images shared by every effect, grown to the largest
+// so far: what lies below the effect, and the horizontal blur pass.
+static bool scratch(struct rediwm_scene_renderer *r, int small_w, int small_h) {
+ if (!r->prefix_tex) glGenTextures(1, &r->prefix_tex);
+ if (!r->prefix_fbo) glGenFramebuffers(1, &r->prefix_fbo);
if (!r->small_tex) glGenTextures(1, &r->small_tex);
if (!r->small_fbo) glGenFramebuffers(1, &r->small_fbo);
- if (copy_w > r->copy_w || copy_h > r->copy_h) {
- r->copy_w = copy_w > r->copy_w ? copy_w : r->copy_w;
- r->copy_h = copy_h > r->copy_h ? copy_h : r->copy_h;
- // RGB: a scanout buffer may have no alpha, and GLES2 copies an alpha-less
- // framebuffer only into a texture without one. The backdrop is opaque.
- texture_storage(r->copy_tex, GL_RGB, r->copy_w, r->copy_h);
- }
if (small_w > r->small_w || small_h > r->small_h) {
r->small_w = small_w > r->small_w ? small_w : r->small_w;
r->small_h = small_h > r->small_h ? small_h : r->small_h;
+ texture_storage(r->prefix_tex, GL_RGBA, r->small_w, r->small_h);
texture_storage(r->small_tex, GL_RGBA, r->small_w, r->small_h);
- if (!attach(r->small_fbo, r->small_tex)) return false;
+ if (!attach(r->prefix_fbo, r->prefix_tex) || !attach(r->small_fbo, r->small_tex)) return false;
}
return true;
}
@@ -689,16 +708,49 @@ void rediwm_scene_renderer_destroy_backdrop(struct rediwm_scene_renderer *r, str
}
free(b);
}
-void rediwm_scene_pass_capture_backdrop(struct wlr_render_pass *base, struct rediwm_backdrop **out,
- struct wlr_box region, float sigma) {
+void rediwm_scene_pass_begin_backdrop(struct wlr_render_pass *base, struct wlr_box region, float factor) {
struct pass *p = owned_pass(base);
struct rediwm_scene_renderer *r = p->renderer;
if (p->failed) return;
- if (!r->has_backdrops || region.width <= 0 || region.height <= 0 || !isfinite(sigma) ||
- sigma <= 0 || sigma > 1024 || region.width > 16384 || region.height > 16384) {
+ if (!r->has_backdrops || p->redirected || region.width <= 0 || region.height <= 0 ||
+ region.width > 16384 || region.height > 16384 || !isfinite(factor) || factor < 1 || factor > 64) {
p->failed = true;
return;
}
+ // Whole pixels of the image: it covers a little more than the region.
+ const int small_w = (int)ceilf(region.width / factor), small_h = (int)ceilf(region.height / factor);
+ if (!scratch(r, small_w, small_h)) { p->failed = true; return; }
+ p->factor = factor;
+ p->small_w = small_w;
+ p->small_h = small_h;
+ struct wlr_box buffer = {0, 0, p->buffer->width, p->buffer->height};
+ if (!wlr_box_intersection(&p->valid, &region, &buffer)) { p->failed = true; return; }
+ p->region = region;
+ p->redirected = true;
+ p->targets_set = 0;
+ glBindFramebuffer(GL_FRAMEBUFFER, r->prefix_fbo);
+ glViewport(0, 0, small_w, small_h);
+ // Black where nothing is drawn, as the output is; the blur never reads
+ // outside the buffer (see end_backdrop).
+ glDisable(GL_SCISSOR_TEST);
+ glClearColor(0, 0, 0, 1);
+ glClear(GL_COLOR_BUFFER_BIT);
+}
+void rediwm_scene_pass_end_backdrop(struct wlr_render_pass *base, struct rediwm_backdrop **out, float sigma) {
+ struct pass *p = owned_pass(base);
+ struct rediwm_scene_renderer *r = p->renderer;
+ if (!p->redirected) { p->failed = true; return; }
+ p->redirected = false;
+ p->targets_set = 0;
+ p->program = 0;
+ p->blend_mode = -1;
+ GLuint pass_fbo = wlr_gles2_renderer_get_buffer_fbo(r->renderer, p->buffer);
+ if (p->failed || !isfinite(sigma) || sigma <= 0 || sigma > 1024) {
+ p->failed = true;
+ glBindFramebuffer(GL_FRAMEBUFFER, pass_fbo);
+ glViewport(0, 0, p->buffer->width, p->buffer->height);
+ return;
+ }
struct rediwm_backdrop *b = *out;
if (!b) {
b = calloc(1, sizeof(*b));
@@ -707,54 +759,44 @@ void rediwm_scene_pass_capture_backdrop(struct wlr_render_pass *base, struct red
glGenFramebuffers(1, &b->fbo);
*out = b;
}
- const int small_w = (region.width + 3) / 4, small_h = (region.height + 3) / 4;
+ const int small_w = p->small_w, small_h = p->small_h;
if (b->width != small_w || b->height != small_h) {
texture_storage(b->tex, GL_RGBA, small_w, small_h);
if (!attach(b->fbo, b->tex)) { p->failed = true; return; }
b->width = small_w;
b->height = small_h;
}
- b->region = region;
- if (!scratch(r, region.width, region.height, small_w, small_h)) { p->failed = true; return; }
- // 1. Copy what lies in the buffer; texels outside are clamped away below.
- const int x0 = region.x, y0 = region.y;
- const int cx0 = x0 < 0 ? 0 : x0, cy0 = y0 < 0 ? 0 : y0;
- const int cx1 = x0 + region.width > p->buffer->width ? p->buffer->width : x0 + region.width;
- const int cy1 = y0 + region.height > p->buffer->height ? p->buffer->height : y0 + region.height;
- if (cx1 <= cx0 || cy1 <= cy0) { p->failed = true; return; }
- GLuint pass_fbo = wlr_gles2_renderer_get_buffer_fbo(r->renderer, p->buffer);
- glBindFramebuffer(GL_FRAMEBUFFER, pass_fbo);
+ b->x = p->region.x;
+ b->y = p->region.y;
+ b->extent_w = small_w * p->factor;
+ b->extent_h = small_h * p->factor;
+ // Separable blur: horizontal into scratch, vertical into the backdrop. Only
+ // what lies in the buffer is read: beyond it the edge is replicated.
+ struct program *g = &r->blur;
glDisable(GL_SCISSOR_TEST);
glDisable(GL_BLEND);
glActiveTexture(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D, r->copy_tex);
- glCopyTexSubImage2D(GL_TEXTURE_2D, 0, cx0 - x0, cy0 - y0, cx0, cy0, cx1 - cx0, cy1 - cy0);
- // 2. Horizontal at quarter size into scratch, vertical into the backdrop.
- struct program *g = &r->blur;
glUseProgram(g->id);
glUniform1i(g->sampler, 0);
- const float cw = r->copy_w, ch = r->copy_h, aw = r->small_w, ah = r->small_h;
+ const float aw = r->small_w, ah = r->small_h;
+ const float vx1 = (p->valid.x - p->region.x) / p->factor, vy1 = (p->valid.y - p->region.y) / p->factor;
+ const float vx2 = fminf(small_w, (p->valid.x + p->valid.width - p->region.x) / p->factor);
+ const float vy2 = fminf(small_h, (p->valid.y + p->valid.height - p->region.y) / p->factor);
+ glUniform2f(g->src_scale, small_w / aw, small_h / ah);
+ glUniform1f(g->sigma, sigma / p->factor);
glBindFramebuffer(GL_FRAMEBUFFER, r->small_fbo);
glViewport(0, 0, small_w, small_h);
- glUniform2f(g->src_scale, region.width / cw, region.height / ch);
- glUniform2f(g->step_uv, (float)region.width / small_w / cw, 0);
- glUniform1f(g->sigma, sigma * small_w / region.width);
- glUniform4f(g->limits, (cx0 - x0 + .5f) / cw, (cy0 - y0 + .5f) / ch,
- (cx1 - x0 - .5f) / cw, (cy1 - y0 - .5f) / ch);
+ glBindTexture(GL_TEXTURE_2D, r->prefix_tex);
+ glUniform2f(g->step_uv, 1.f / aw, 0);
+ glUniform4f(g->limits, (vx1 + .5f) / aw, (vy1 + .5f) / ah, (vx2 - .5f) / aw, (vy2 - .5f) / ah);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glBindFramebuffer(GL_FRAMEBUFFER, b->fbo);
glBindTexture(GL_TEXTURE_2D, r->small_tex);
- glUniform2f(g->src_scale, small_w / aw, small_h / ah);
glUniform2f(g->step_uv, 0, 1.f / ah);
- glUniform1f(g->sigma, sigma * small_h / region.height);
- glUniform4f(g->limits, .5f / aw, .5f / ah, (small_w - .5f) / aw, (small_h - .5f) / ah);
+ glUniform4f(g->limits, .5f / aw, (vy1 + .5f) / ah, (small_w - .5f) / aw, (vy2 - .5f) / ah);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
- // Back to the pass: its buffer, viewport and blending; the next draw sets the
- // program and the scissor again.
glBindFramebuffer(GL_FRAMEBUFFER, pass_fbo);
glViewport(0, 0, p->buffer->width, p->buffer->height);
- p->program = 0;
- p->blend_mode = -1;
}
void rediwm_scene_pass_add_backdrop(struct wlr_render_pass *base, const struct rediwm_pass_shape *shape,
struct wlr_box box, const struct rediwm_pass_backdrop *o) {
@@ -779,12 +821,11 @@ void rediwm_scene_pass_add_backdrop(struct wlr_render_pass *base, const struct r
setup(p, g, box, WLR_RENDER_BLEND_MODE_PREMULTIPLIED);
struct rediwm_pass_shape bare = *shape; // the ring belongs to the surface over it
bare.border = 0;
- set_shape(g, &bare);
+ set_shape(p, g, &bare);
glUniform1f(g->mode, 3.f);
glUniform1f(g->alpha, o->opacity);
glUniform1f(g->saturation, o->saturation);
- glUniform4f(g->bmap, shape->box.x - b->region.x, shape->box.y - b->region.y,
- 1.f / b->region.width, 1.f / b->region.height);
+ glUniform4f(g->bmap, shape->box.x - b->x, shape->box.y - b->y, 1.f / b->extent_w, 1.f / b->extent_h);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, has_front ? front.tex : 0);
if (has_front) {
@@ -798,7 +839,7 @@ void rediwm_scene_pass_add_backdrop(struct wlr_render_pass *base, const struct r
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, b->tex);
glUniform1i(g->sampler, 0);
- draw(o->clip);
+ draw(p, o->clip);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, 0);
glActiveTexture(GL_TEXTURE0);
diff --git a/src/scene_pass.h b/src/scene_pass.h
index ca236a6..84e7f69 100644
--- a/src/scene_pass.h
+++ b/src/scene_pass.h
@@ -85,13 +85,17 @@ struct rediwm_backdrop;
bool rediwm_scene_renderer_enable_backdrops(struct rediwm_scene_renderer *);
// Frees a backdrop's GL resources; outside a pass. NULL is a no-op.
void rediwm_scene_renderer_destroy_backdrop(struct rediwm_scene_renderer *, struct rediwm_backdrop *);
-// Copies `region` (device pixels of this pass's buffer; the part outside the
-// buffer replicates its edge) as drawn so far and blurs it at quarter size with
-// a Gaussian of `sigma` device pixels into `*backdrop`, creating it if NULL. Not
-// limited by any clip: the caller must have drawn everything below the effect
-// in the whole region first (with buffer age, that means damaging all of it).
-void rediwm_scene_pass_capture_backdrop(struct wlr_render_pass *, struct rediwm_backdrop **,
- struct wlr_box region, float sigma);
+// Draws what lies below an effect into an image of `region` (device pixels of
+// this pass's buffer) reduced by `factor` (at least 1; glass uses 4 times the
+// output scale, a quarter of the logical size, as glass.c did): from here to
+// rediwm_scene_pass_end_backdrop every draw of this pass lands in that image,
+// which starts black. The caller draws the items below the effect, bottom up,
+// clipped as it likes; nothing reaches the buffer meanwhile.
+void rediwm_scene_pass_begin_backdrop(struct wlr_render_pass *, struct wlr_box region, float factor);
+// Blurs that image with a Gaussian of `sigma` device pixels into `*backdrop`
+// (created if NULL) and returns drawing to the buffer. Beyond the buffer's edge
+// the blur replicates it.
+void rediwm_scene_pass_end_backdrop(struct wlr_render_pass *, struct rediwm_backdrop **, float sigma);
struct rediwm_pass_backdrop {
const struct rediwm_backdrop *backdrop;
float saturation; // 1 leaves colours as they are
diff --git a/src/scene_pass_test.c b/src/scene_pass_test.c
index b1b3df8..746f060 100644
--- a/src/scene_pass_test.c
+++ b/src/scene_pass_test.c
@@ -916,15 +916,26 @@ static struct wlr_buffer *target_format(struct wlr_allocator *allocator, int w,
return b;
}
static const float BANDS[5][4] = {{1, 0, 0, 1}, {0, .8f, 0, 1}, {0, 0, 1, 1}, {1, 1, 1, 1}, {.1f, .1f, .1f, 1}};
+static void bands(struct wlr_render_pass *pass, int width, int height) {
+ for (int x = 0, i = 0; x < width; x += 40, i++)
+ wlr_render_pass_add_rect(pass, &(struct wlr_render_rect_options){
+ .box = {x, 0, 40, height}, .color = {BANDS[i % 5][0], BANDS[i % 5][1], BANDS[i % 5][2], 1}});
+}
+static void fill(struct wlr_render_pass *pass, const float color[4]) {
+ wlr_render_pass_add_rect(pass, &(struct wlr_render_rect_options){
+ .box = {0, 0, GW, GH}, .color = {color[0], color[1], color[2], color[3]}});
+}
// Vertical bands 40 px wide, then a backdrop of `region` composited over `box`.
+static float backdrop_factor = 4;
static struct rediwm_backdrop *draw_backdrop(struct rediwm_scene_renderer *r, struct wlr_buffer *buf,
struct rediwm_backdrop *b, struct wlr_box region, struct wlr_box box, float sigma,
const struct rediwm_pass_backdrop *opts, const pixman_region32_t *clip) {
struct wlr_render_pass *pass = begin_fill(r, buf, BG, NULL);
- for (int x = 0, i = 0; x < buf->width; x += 40, i++)
- wlr_render_pass_add_rect(pass, &(struct wlr_render_rect_options){
- .box = {x, 0, 40, buf->height}, .color = {BANDS[i % 5][0], BANDS[i % 5][1], BANDS[i % 5][2], 1}});
- rediwm_scene_pass_capture_backdrop(pass, &b, region, sigma);
+ bands(pass, buf->width, buf->height);
+ // What lies below the effect, drawn again into the quarter-size backdrop.
+ rediwm_scene_pass_begin_backdrop(pass, region, backdrop_factor);
+ bands(pass, buf->width, buf->height);
+ rediwm_scene_pass_end_backdrop(pass, &b, sigma);
struct rediwm_pass_backdrop o = opts ? *opts : (struct rediwm_pass_backdrop){.saturation = 1, .opacity = 1};
o.backdrop = b;
o.clip = clip;
@@ -939,11 +950,15 @@ static double band_channel(int x, int width, int c) {
return BANDS[(x / 40) % 5][c];
}
static void gate_backdrop_blur(struct rediwm_scene_renderer *r, struct wlr_allocator *allocator, struct image *img) {
- const float sigma = 16;
const struct wlr_box region = {100, 100, 400, 200}, box = {148, 148, 304, 104};
- int worst = 0;
- for (int f = 0; f < 2; f++) {
- struct wlr_buffer *buf = target_format(allocator, GW, GH, f ? DRM_FORMAT_XRGB8888 : DRM_FORMAT_ARGB8888);
+ int worst[4] = {0};
+ for (int f = 0; f < 4; f++) {
+ // ARGB and XRGB buffers, reduced by 4 (scale 1) and by 6 (glass at 1.5).
+ backdrop_factor = f < 2 ? 4 : 6;
+ // Sigma in reduced pixels as glass has it (22 logical px over a quarter of
+ // the logical size): the same at every scale.
+ const float sigma = 4 * backdrop_factor;
+ struct wlr_buffer *buf = target_format(allocator, GW, GH, f % 2 ? DRM_FORMAT_XRGB8888 : DRM_FORMAT_ARGB8888);
struct rediwm_backdrop *b = draw_backdrop(r, buf, NULL, region, box, sigma, NULL, NULL);
read_image(r, buf, img);
for (int x = box.x; x < box.x + box.width; x++) {
@@ -960,14 +975,21 @@ static void gate_backdrop_blur(struct rediwm_scene_renderer *r, struct wlr_alloc
for (int y = box.y; y < box.y + box.height; y += 13)
for (int c = 0; c < 3; c++) {
const int d = diff(at(img, x, y)[c], (int)lround(255 * want[c] / weight));
- if (d > worst) worst = d;
+ if (d > worst[f]) worst[f] = d;
}
}
rediwm_scene_renderer_destroy_backdrop(r, b);
wlr_buffer_drop(buf);
}
- check(worst <= 6, "the quarter-size blur differs from the exact Gaussian by %d levels", worst);
- printf("PASS: backdrop blur within %d levels of the exact Gaussian, ARGB and XRGB buffers\n", worst);
+ // Reduced by 4 the bands' edges fall on whole pixels of the image; by 6 they do
+ // not, and an edge drawn at reduced size moves by up to half a pixel (3 device
+ // pixels), which on a blurred step of sigma 24 is 255 / (sqrt(2 pi) 24) levels
+ // per pixel: 13. glass.c drew its reduced capture the same way.
+ for (int f = 0; f < 4; f++)
+ check(worst[f] <= (f < 2 ? 2 : 15), "the reduced blur differs from the exact Gaussian by %d levels (case %d)", worst[f], f);
+ backdrop_factor = 4;
+ printf("PASS: backdrop blur against the exact Gaussian: %d levels reduced by 4, %d by 6 (edge quantisation), ARGB and XRGB\n",
+ worst[0] > worst[1] ? worst[0] : worst[1], worst[2] > worst[3] ? worst[2] : worst[3]);
}
static void gate_backdrop_properties(struct rediwm_scene_renderer *r, struct wlr_allocator *allocator, struct image *img) {
struct wlr_buffer *buf = target_sized(allocator, GW, GH);
@@ -977,7 +999,10 @@ static void gate_backdrop_properties(struct rediwm_scene_renderer *r, struct wlr
struct wlr_render_pass *pass = begin_fill(r, buf, (float[4]){1, 0, 0, 1}, NULL);
wlr_render_pass_add_rect(pass, &(struct wlr_render_rect_options){.box = {320, 0, 320, GH}, .color = {0, 0, 1, 1}});
const struct wlr_box region = {120, 100, 400, 200}, box = {168, 148, 304, 104};
- rediwm_scene_pass_capture_backdrop(pass, &b, region, 16);
+ rediwm_scene_pass_begin_backdrop(pass, region, 4);
+ fill(pass, (float[4]){1, 0, 0, 1});
+ wlr_render_pass_add_rect(pass, &(struct wlr_render_rect_options){.box = {320, 0, 320, GH}, .color = {0, 0, 1, 1}});
+ rediwm_scene_pass_end_backdrop(pass, &b, 16);
rediwm_scene_pass_add_backdrop(pass, &(struct rediwm_pass_shape){.box = box}, box,
&(struct rediwm_pass_backdrop){.backdrop = b, .saturation = 1, .opacity = 1});
finish(pass);
@@ -992,7 +1017,9 @@ static void gate_backdrop_properties(struct rediwm_scene_renderer *r, struct wlr
// At the buffer edge the blur replicates it: no black comes in.
pass = begin_fill(r, buf, (float[4]){0, 1, 0, 1}, NULL);
const struct wlr_box edge_region = {-60, 100, 200, 200}, edge_box = {0, 148, 92, 104};
- rediwm_scene_pass_capture_backdrop(pass, &b, edge_region, 16);
+ rediwm_scene_pass_begin_backdrop(pass, edge_region, 4);
+ fill(pass, (float[4]){0, 1, 0, 1});
+ rediwm_scene_pass_end_backdrop(pass, &b, 16);
rediwm_scene_pass_add_backdrop(pass, &(struct rediwm_pass_shape){.box = edge_box}, edge_box,
&(struct rediwm_pass_backdrop){.backdrop = b, .saturation = 1, .opacity = 1});
finish(pass);
@@ -1002,7 +1029,9 @@ static void gate_backdrop_properties(struct rediwm_scene_renderer *r, struct wlr
// Saturation as glass.c applies it, on a uniform colour the blur keeps.
const float c[3] = {.2f, .4f, .6f};
pass = begin_fill(r, buf, (float[4]){c[0], c[1], c[2], 1}, NULL);
- rediwm_scene_pass_capture_backdrop(pass, &b, region, 16);
+ rediwm_scene_pass_begin_backdrop(pass, region, 4);
+ fill(pass, (float[4]){c[0], c[1], c[2], 1});
+ rediwm_scene_pass_end_backdrop(pass, &b, 16);
rediwm_scene_pass_add_backdrop(pass, &(struct rediwm_pass_shape){.box = box}, box,
&(struct rediwm_pass_backdrop){.backdrop = b, .saturation = 1.5f, .opacity = 1});
finish(pass);
@@ -1026,7 +1055,9 @@ static void gate_backdrop_front(struct rediwm_scene_renderer *r, struct wlr_allo
const struct wlr_box region = {100, 100, 200, 200}, box = {150, 150, 100, 100};
// On a transparent buffer the composite's alpha is what it adds to the front.
struct wlr_render_pass *pass = begin_fill(r, buf, (float[4]){1, 1, 1, 1}, NULL);
- rediwm_scene_pass_capture_backdrop(pass, &b, region, 8);
+ rediwm_scene_pass_begin_backdrop(pass, region, 4);
+ fill(pass, (float[4]){1, 1, 1, 1});
+ rediwm_scene_pass_end_backdrop(pass, &b, 8);
wlr_render_pass_add_rect(pass, &(struct wlr_render_rect_options){.box = {0, 0, GW, GH},
.color = {0, 0, 0, 0}, .blend_mode = WLR_RENDER_BLEND_MODE_NONE});
rediwm_scene_pass_add_backdrop(pass, &(struct rediwm_pass_shape){.box = box}, box,
@@ -1039,7 +1070,9 @@ static void gate_backdrop_front(struct rediwm_scene_renderer *r, struct wlr_allo
at(img, 200, 200)[3], (int)lround(255 * want));
// An opaque front leaves nothing for the effect to add.
pass = begin_fill(r, buf, (float[4]){1, 1, 1, 1}, NULL);
- rediwm_scene_pass_capture_backdrop(pass, &b, region, 8);
+ rediwm_scene_pass_begin_backdrop(pass, region, 4);
+ fill(pass, (float[4]){1, 1, 1, 1});
+ rediwm_scene_pass_end_backdrop(pass, &b, 8);
wlr_render_pass_add_rect(pass, &(struct wlr_render_rect_options){.box = {0, 0, GW, GH},
.color = {0, 0, 0, 0}, .blend_mode = WLR_RENDER_BLEND_MODE_NONE});
rediwm_scene_pass_add_backdrop(pass, &(struct rediwm_pass_shape){.box = box}, box,
@@ -1066,11 +1099,51 @@ static void gate_backdrop_front(struct rediwm_scene_renderer *r, struct wlr_allo
wlr_buffer_drop(buf);
puts("PASS: the backdrop makes up the front's alpha to the coverage; a clipped composite equals a full one");
}
+// The redirect moves boxes, shape origins and scissors into the quarter-size
+// image: a rounded piece and a clipped rect land where they belong in it.
+static void gate_backdrop_redirect(struct rediwm_scene_renderer *r, struct wlr_allocator *allocator, struct image *img) {
+ struct wlr_buffer *buf = target_sized(allocator, GW, GH);
+ struct rediwm_backdrop *b = NULL;
+ const struct wlr_box region = {100, 80, 400, 240};
+ const float gray[4] = {.5f, .5f, .5f, 1};
+ struct wlr_render_pass *pass = begin_fill(r, buf, BG, NULL);
+ rediwm_scene_pass_begin_backdrop(pass, region, 4);
+ fill(pass, gray);
+ const struct rediwm_pass_shape shape = {.box = {148, 120, 200, 120}, .radii = {40, 40, 40, 40}};
+ rediwm_scene_pass_add_rect_shaped(pass, &(struct wlr_render_rect_options){
+ .box = shape.box, .color = {1, 0, 0, 1}}, &shape);
+ pixman_region32_t left;
+ pixman_region32_init_rect(&left, 380, 200, 32, 60);
+ wlr_render_pass_add_rect(pass, &(struct wlr_render_rect_options){
+ .box = {380, 200, 64, 60}, .color = {0, 0, 1, 1}, .clip = &left});
+ rediwm_scene_pass_end_backdrop(pass, &b, .5f);
+ rediwm_scene_pass_add_backdrop(pass, &(struct rediwm_pass_shape){.box = region}, region,
+ &(struct rediwm_pass_backdrop){.backdrop = b, .saturation = 1, .opacity = 1});
+ finish(pass);
+ read_image(r, buf, img);
+ struct { int x, y; float c[3]; const char *what; } probes[] = {
+ {248, 180, {1, 0, 0}, "inside the rounded piece"},
+ {152, 124, {.5f, .5f, .5f}, "a corner the arc cuts away"},
+ {392, 230, {0, 0, 1}, "the clipped rect"},
+ {432, 230, {.5f, .5f, .5f}, "outside the clip"},
+ {110, 90, {.5f, .5f, .5f}, "the region's corner"},
+ };
+ for (size_t i = 0; i < sizeof(probes) / sizeof(probes[0]); i++)
+ for (int c = 0; c < 3; c++)
+ check(diff(at(img, probes[i].x, probes[i].y)[c], (int)lround(255 * probes[i].c[c])) <= 10,
+ "redirected drawing: %s is %d,%d,%d", probes[i].what, at(img, probes[i].x, probes[i].y)[0],
+ at(img, probes[i].x, probes[i].y)[1], at(img, probes[i].x, probes[i].y)[2]);
+ pixman_region32_fini(&left);
+ rediwm_scene_renderer_destroy_backdrop(r, b);
+ wlr_buffer_drop(buf);
+ puts("PASS: redirected draws land in the quarter-size image with their shape, offset and clip");
+}
static void backdrop_gates(struct rediwm_scene_renderer *r, struct wlr_allocator *allocator) {
struct image img = {0};
gate_backdrop_blur(r, allocator, &img);
gate_backdrop_properties(r, allocator, &img);
gate_backdrop_front(r, allocator, &img);
+ gate_backdrop_redirect(r, allocator, &img);
free(img.p);
}
int main(void) {
diff --git a/tests/scene_baseline.py b/tests/scene_baseline.py
index 360bb2a..dd158b1 100644
--- a/tests/scene_baseline.py
+++ b/tests/scene_baseline.py
@@ -349,7 +349,7 @@ def condense(perf):
for name in STAGES if name in work}
flat = {"output_commits": perf["output_commits"], "output_skipped_commits": perf.get("output_skipped_commits"),
"output_failed_commits": perf["output_failed_commits"], "missed_frames": perf.get("missed_frames"),
- "gpu_timing_available": work["gpu_timing_available"], "titlebar_paints": perf.get("titlebar_paints"),
+ "gpu_timing_available": work["gpu_timing_available"], "titlebar_paints": perf.get("titlebar_paints"), "glass_reblurs": perf.get("glass_reblurs"),
"footer_paints": perf.get("footer_paints"), "edge_samples_attempted": perf.get("edge_samples_attempted"),
"edge_samples_succeeded": perf.get("edge_samples_succeeded"), "frame_work": out}
for name in STAGES: