Skip to content

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

scene graph plan, stage 5d: glass.c reduced to a registry

oxydizer0f95279b7ecd
diff --git a/AGENTS.md b/AGENTS.md
index 2936948..7bec4f2 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -47,17 +47,23 @@ the one for the directory you work in: `src/files`, `src/editor`,
host `grim`. Brief vanishing after a startup scale mismatch is not a bug.
* **GLES can NULL `wlr_scene_buffer.buffer`** after upload (the texture
stays): persist raster sizes.
-* **Glass** samples `wlr_client_buffer_get(buffer)->texture` and tracks
- source-surface damage per effect. Empty commits and buffer rotation keep the
- blur. Drags may hold titlebar blur at ≥ 0.98 opacity (the default theme is
- 0.80, so it follows), so every path ending a move schedules a frame. An
- effect's scale comes from the outputs its target overlaps (`effect_scale`),
- never from the output being updated: it is in the effect's hash, and an
- output-dependent value made outputs of different scales re-blur and damage
- each other forever (`glass_hold.py`).
+* **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`.
* **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 `glass.c`'s `leave()` does; a quad
+ touched) back before a wlroots pass runs, as `scene_pass.c`'s `leave()` does; a quad
VBO left bound makes wlroots draw half a rectangle. A border is drawn in the
same pass as its body, never over it (`docs/plans/scene-graph-stage1.md`).
* **Commit only via `Output.commitFrameState`**, never
diff --git a/TESTING.md b/TESTING.md
index fea1e99..d829189 100644
--- a/TESTING.md
+++ b/TESTING.md
@@ -14,7 +14,7 @@ debugging on the host, see AGENTS.md, "Rendering".
| Command | What it checks |
| --- | --- |
| `zig build test` | In-process unit tests: rasterizers vs. full rasters, UI, config, IPC parser/serializer fixtures, glass damage, projection damage and its typed graph (paint order, unrounded edges, list lifetime), lifecycle/allocation failures, Files/desktop logic. No compositor or bus. |
-| `zig build test-glass` | Real GLES2 pixels on a headless backend (needs a DRM render node). |
+| `zig build test-glass` | The glass registry and an effect's geometry in the graph at every zoom (no GPU). Glass pixels are gated in `test-scene-pass` (stage 5b) and by `tests/glass_reblur.py`. |
| `zig build test-pass-spike` | The owned-pass spike of `docs/plans/scene-graph-stage1.md`: rounded clip, border, shadow, external-OES texture, backdrop blur, buffer-age damage and cost on headless GLES2 (needs a render node; `-Doptimize=ReleaseSafe` for cost). |
| `zig build test-scene-pass` | Stage 3's owned GLES2 drawing backend against wlroots: transforms, crops, filters, premultiplied alpha, damage, external-OES (an RGB EGLImage and a linear NV12 dmabuf; needs gbm), GL/EGL state and acquire/release timelines. Needs a compatible render node (`WLR_RENDER_DRM_DEVICE` on multi-GPU machines); also run with `-Doptimize=ReleaseSafe`. The unavailable-acquire test intentionally logs `drmSyncobjTransfer failed`. Stage 4b's rounded-shape gates are in the same fixture: clip against a supersampled reference, piece joins, border/body, premultiplied edges, the opaque cover, shadow, and partial repaint across a clip edge; the 128 parity cases also run through the shaped programs. Stage 4d's shadow gate compares every pixel with the CPU chrome's shadow formula. |
| `zig build test-lock` | Lock/greeter painter, password editing, PAM transitions (PAM is replaced at link time in test binaries only), greeter↔rediwm-dm conversation. |
@@ -122,8 +122,9 @@ Network settings, password/hidden forms, saved and open joins, radio, wired
details, connect/disconnect and permission errors, service restart and scrolling;
`--settings-only` runs just the settings checks), `battery_popup.py` (fake sysfs and private power-profile
service; charge states, missing details, selection and dismissal),
-`keyboard_shortcuts.py`, `panel_damage.py`, `glass_hold.py` (defaults to
-gles2), `animations.py`, `hotspots.py`, `launch_feedback.py`,
+`keyboard_shortcuts.py`, `panel_damage.py`, `glass_hold.py` (holds and
+mixed-scale idle), `glass_reblur.py` (glass re-blurs for changes below it,
+never for its own client), `animations.py`, `hotspots.py`, `launch_feedback.py`,
`launch_placeholder.py`, `appearance_*.py`, `desktop_canvas.py`,
`layout_autosave.py`, `mini_map.py` (settings, pixels, timeout and dragging),
`mini_map_lifecycle.py` (focus, multiple outputs, cancellation and idle wakeups),
@@ -350,7 +351,9 @@ scale, input rate and compiler backend identical across comparisons.
- `GetPerformanceStats.frame_time_ms` is the interval between commits, not
frame cost. `frame_work` has per-stage wall times over the last 512 samples
(`cpu_frame`, `taskbar_cpu`, `chrome_cpu`, `panels_cpu`, `projection_cpu`,
- `glass_cpu`, `scene_commit_cpu`, `gpu_elapsed`). CPU and GPU overlap; don't
+ `glass_cpu`, `scene_commit_cpu`, `gpu_elapsed`; `glass_cpu` stays empty since
+ the output pass draws glass, which `scene_commit_cpu` now includes, and
+ `glass_reblurs` counts the blurs it re-took). CPU and GPU overlap; don't
add them or invert them into FPS.
- The GPU timer starts on the first stats request and stops after five idle
minutes; it costs CPU per frame. For CPU A/B runs, make no stats requests and
diff --git a/build.zig b/build.zig
index 0a3532a..6b4836b 100644
--- a/build.zig
+++ b/build.zig
@@ -682,16 +682,15 @@ pub fn build(b: *std.Build) void {
.name = "glass-tests",
.root_module = b.createModule(.{ .target = target, .optimize = .Debug, .link_libc = true }),
});
- glass_tests.root_module.addCSourceFile(.{ .file = b.path("src/glass_test.c"), .flags = &.{ "-std=c11", "-Wall", "-Wextra" } });
+ glass_tests.root_module.addCSourceFile(.{ .file = b.path("src/glass_test.c"), .flags = &.{ "-std=c11", "-Wall", "-Wextra", "-Werror" } });
inline for (.{ "wlroots-0.20", "wayland-server", "pixman-1", "egl", "glesv2" }) |lib| {
glass_tests.root_module.linkSystemLibrary(lib, .{});
}
glass_tests.root_module.addCSourceFile(.{ .file = b.path("src/projection.c"), .flags = &.{ "-std=c11", "-Wall", "-Wextra" } });
glass_tests.root_module.addCSourceFile(.{ .file = b.path("src/scene_damage.c"), .flags = &.{ "-std=c11", "-Wall", "-Wextra", "-Werror" } });
- glass_tests.root_module.addCSourceFile(.{ .file = b.path("src/explicit_sync.c"), .flags = &.{ "-std=c11", "-Wall", "-Wextra", "-Werror" } });
const run_glass_tests = b.addRunArtifact(glass_tests);
run_glass_tests.setEnvironmentVariable("WLR_RENDERER", "gles2");
- b.step("test-glass", "Run backdrop pixel checks with a headless GLES2 renderer").dependOn(&run_glass_tests.step);
+ b.step("test-glass", "Test the glass registry and its geometry in the graph (no GPU)").dependOn(&run_glass_tests.step);
// Stage 1 spike of docs/plans/scene-graph.md: the owned pass's primitives, pixel-tested.
const pass_spike_tests = b.addExecutable(.{
.name = "pass-spike-tests",
@@ -716,8 +715,7 @@ pub fn build(b: *std.Build) void {
run_scene_pass_tests.setEnvironmentVariable("WLR_RENDERER", "gles2");
b.step("test-scene-pass", "Compare the owned GLES2 pass with wlroots on a headless renderer").dependOn(&run_scene_pass_tests.step);
const run_glass_damage_tests = b.addRunArtifact(glass_tests);
- run_glass_damage_tests.addArg("--damage-only");
- b.step("test-glass-damage", "Test backdrop invalidation without a GPU").dependOn(&run_glass_damage_tests.step);
+ b.step("test-glass-damage", "Same as test-glass (kept for scripts)").dependOn(&run_glass_damage_tests.step);
test_step.dependOn(&run_glass_damage_tests.step);
const run_cmd = b.addRunArtifact(compositor);
diff --git a/docs/plans/scene-graph-stage5.md b/docs/plans/scene-graph-stage5.md
index 9a03011..a425e4d 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 and 5b done, 5c next**, 2026-10-11. Decisions taken (all as recommended). Stage 4 of
+Status: **5a to 5d done, 5e (the stage cost gate) next**, 2026-10-11. 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
@@ -165,10 +165,44 @@ once, after 5e (see [scene-graph-stage4.md](scene-graph-stage4.md), Measurement)
`glass.c` stops rendering but still owns attach/configure. Gates: `glass_test`
converted to the pass, `glass_hold.py`, appearance and window suites, IPC
screenshots against stage 4 glass within tolerance at 1, 1.5 and mixed.
+ *Done.* An effect's box is its target's, derived in resolve (`effect_geometry`
+ in `projection.c`, from `rediwm_glass_effect_info`, `glass.h`); collect lifts
+ culling inside its padded extent; `decide_effects` reads the output's damage
+ events before the damage is handed on and re-takes a blur only for a change
+ below it, damage no event explains, a changed region or sigma, or the end of a
+ hold that carried it (a moved held blur would otherwise stay frozen after
+ release). A re-blur reports the effect box as changed (the damage ring and the
+ commit) and repaints the padded extent in this buffer. `glass_reblurs` in the
+ performance stats counts re-blurs.
+ Gates: `tests/glass_reblur.py` at scales 1 and 1.5: a window's own client
+ repainting at full rate under its titlebar re-blurs nothing; a window below
+ inside the extent re-blurs it every frame; moved out of it, nothing; moving the
+ window re-blurs. Glass against `glass.c` (the 5b binary, IPC screenshots over a
+ busy wallpaper): titlebar within **5 levels**, taskbar within **3**, the start
+ menu within 3 except its outermost right column (up to **17 levels**, 0.08 to
+ 0.14 % of the menu's pixels, where it borders a bright window), at scales 1 and
+ 1.5. `glass_hold.py`: mixed-scale idle passes; the drag comparison fails as on
+ HEAD before this stage (the drag frame differs by up to 10 levels across the
+ titlebar, the released frame matches exactly). The other glass, window, panel,
+ damage and capture suites fail only where they did before stage 5.
+ Known limit: a software cursor's damage is unexplained, so moving it near glass
+ re-blurs (nested and headless sessions only; on KMS the cursor is a plane).
* **5d. Delete.** The capture walk, dependencies, contexts, effect output
buffers, intermediate textures, `effect_scale`, `rediwm_glass_project` and the
effect scene nodes; the Zig `glass.Effect` API shrinks to attach/configure.
Rewrite the Glass notes in `AGENTS.md`.
+ *Done.* `glass.c` is a registry of about 150 lines (attach, configure, holds,
+ `rediwm_glass_effect_info`), with no GL, allocator, read fence or projection;
+ `rediwm_glass_update`, `rediwm_glass_project` and
+ `rediwm_projection_effect_updated` are gone, and `glass_cpu` is no longer
+ recorded (the field stays for readers; the work is in `scene_commit_cpu`).
+ `glass_test.c` now tests the registry (info, serials, holds, target lifetime,
+ allocation failure) and an effect's geometry in the graph at every zoom, with
+ no GPU. Writing it found a 5c bug, fixed here: a blur carried by a hold kept
+ its moved position after release and was never re-taken; a carried blur is now
+ re-taken once the hold ends (`glass_hold.py`'s held case passes: frozen while
+ dragged, equal to the reference after release). 5c's `glass_reblurs` field also
+ needed the populated serializer fixture.
* **5e. Stage cost gate** against stage 4 (and the stage 0 baseline): the same
harness as 4e, clean sessions for CPU and memory; a same-session GPU
comparison if the stats timers stay too noisy across builds.
diff --git a/src/Output.zig b/src/Output.zig
index 1f5a431..3feae9e 100644
--- a/src/Output.zig
+++ b/src/Output.zig
@@ -1278,10 +1278,9 @@ fn runFrame(output: *Output) void {
stats.global_stats.projection_cpu.record(stats.nowNs() -% projection_started);
output.server.world.flushCameraEvent();
const mini_map_animating = output.server.world.mini_map.tick(output, now_ms);
- // GPU timestamps enclose glass capture/blur plus the scene submission.
- // Polling happens later; no glFinish or synchronous query-result reads.
+ // GPU timestamps enclose the scene submission, glass included (the output
+ // pass blurs it). Polling happens later; no glFinish or synchronous reads.
const gpu_active = if (output.server.gpu_timer) |timer| timer.begin() else false;
- const glass_started = stats.nowNs();
const lock_animating = output.lock_view.sync(output);
const polkit_animating = if (output.server.polkit_dialog) |dialog|
dialog.output == output.wlr_output and dialog.frame(now_ms)
@@ -1289,8 +1288,6 @@ fn runFrame(output: *Output) void {
false;
glass.Engine.hold(output.server.glass_engine, output.server.input.heldGlass());
glass.Engine.holdAll(output.server.glass_engine, output.server.world.holdingGlass());
- glass.Engine.update(output.server.glass_engine, scene_output);
- stats.global_stats.glass_cpu.record(stats.nowNs() -% glass_started);
var captured = false;
if (output.server.screenshot_mgr) |sm| {
captured = sm.handleOutputFrame(output);
diff --git a/src/Server.zig b/src/Server.zig
index 340010e..ce5d885 100644
--- a/src/Server.zig
+++ b/src/Server.zig
@@ -465,7 +465,7 @@ pub fn init(server: *Server, scale: ?f32, icon_theme_cfg: icon_theme.Config, io:
// REDIWM_NO_GLASS=1 skips the backdrop blur for A/B frame-cost
// measurements; every glass call already accepts a null engine.
- server.glass_engine = if (environ.getPosix("REDIWM_NO_GLASS") != null) null else glass.Engine.create(renderer, wlr_allocator, scene, server.read_fence);
+ server.glass_engine = if (environ.getPosix("REDIWM_NO_GLASS") != null) null else glass.Engine.create();
errdefer glass.Engine.destroy(server.glass_engine);
server.output_renderer = scene_output_mod.Renderer.create(renderer) orelse return error.RendererInitFailed;
errdefer scene_output_mod.Renderer.destroy(server.output_renderer);
diff --git a/src/World.zig b/src/World.zig
index 1799a43..2c651f9 100644
--- a/src/World.zig
+++ b/src/World.zig
@@ -488,7 +488,6 @@ pub fn syncPresentation(world: *World) void {
toplevel.syncOutputScale();
}
Projection.syncFixed(world.projection, world.camera.zoom(), world.camera.offset_x, world.camera.offset_y, world.bounds.origin_x, world.bounds.origin_y, if (world.server.config.compositor.desktop_icons_fixed) world.server.world_desktop_tree else null);
- glass.Engine.project(world.server.glass_engine, world.projection, @floatCast(world.camera.zoom()));
if (world.server.text_input) |relay| relay.updatePopups();
if (world.server.desktop) |desktop| desktop.syncOverlayPosition();
}
diff --git a/src/glass.c b/src/glass.c
index 8a9803d..a462ea2 100644
--- a/src/glass.c
+++ b/src/glass.c
@@ -1,409 +1,44 @@
-// CSS backdrop-filter for the compositor-owned glass surfaces. Capture only
-// the scene prefix behind each surface, then blur on the GPU. No readback.
-// The wlroots scene ABI is deliberately pinned to 0.20 by build.zig.zon.
+// Glass: the CSS backdrop-filter behind the compositor's own surfaces (window
+// titlebars, the taskbar, the start and power menus). This file only registers
+// effects; the owned output pass blurs and composites them (scene_output.c,
+// stage 5 of docs/plans/scene-graph.md). An effect is a scene node without a
+// buffer placed below its target: its place in paint order is where the blur
+// reads the framebuffer, and resolve gives it the target's box (projection.c).
#define WLR_USE_UNSTABLE
-#define WLR_PRIVATE private
-#include <EGL/egl.h>
-#include <GLES2/gl2.h>
-#include <assert.h>
-#include <drm_fourcc.h>
-#include <math.h>
-#include <stdint.h>
#include <stdlib.h>
-#include <string.h>
-#include <wlr/render/allocator.h>
-#include <wlr/render/egl.h>
-#include <wlr/render/gles2.h>
-#include <wlr/render/pass.h>
-#include <wlr/render/wlr_texture.h>
-#include <wlr/types/wlr_buffer.h>
-#include <wlr/types/wlr_compositor.h>
-#include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_scene.h>
-#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"
+#include "glass.h"
enum glass_kind { GLASS_TITLEBAR, GLASS_TASKBAR, GLASS_PANEL };
-struct glass_engine;
+struct glass_effect;
+struct glass_engine {
+ struct wl_list effects;
+ // A dragged opaque titlebar, or every effect during camera motion, keeps
+ // its last blur (stage 5, D2).
+ struct glass_effect *held;
+ bool hold_all;
+ uint64_t next_serial;
+};
struct glass_effect {
struct glass_engine *engine;
struct wl_list link;
struct wlr_scene_buffer *node, *target;
- struct wlr_scene_buffer *projected_node, *projected_target;
- float zoom;
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
+ enum glass_kind kind;
uint64_t serial;
float radius, opacity;
- uint64_t hash, revision;
- bool valid;
- // Logical size and scale of the current output buffer.
- int width, height;
- float scale;
- struct wlr_buffer *capture, *output[2];
- struct wlr_texture *capture_texture;
- GLuint intermediate[2], intermediate_fbo[2];
- int intermediate_width, intermediate_height;
-};
-struct glass_engine {
- struct wlr_renderer *renderer;
- struct wlr_allocator *allocator;
- struct wlr_scene *scene;
- // Release points for explicit-sync clients read by backdrop captures.
- struct rediwm_read_fence *read_fence;
- struct wl_list effects;
- GLuint blur, finish, vertices;
- bool failed;
- bool warned;
- // A held effect keeps its last blur; releasing it forces one update.
- struct glass_effect *held;
- bool resync;
- // 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
-// visibility-culled, but backdrop capture also samples beneath opaque windows.
-// Keep all commits until this effect next examines the source, including while
-// its blur is held or it is outside the outputs.
-struct glass_dependency {
- struct wl_list link;
- struct glass_effect *effect;
- struct wlr_scene_buffer *node;
- struct wlr_surface *surface;
- struct wl_listener commit, node_destroy, surface_destroy;
- pixman_region32_t damage;
- int width, height;
- bool full_damage, seen;
- uint64_t revision;
-};
-
-static void dependency_destroy(struct glass_dependency *dependency)
-{
- wl_list_remove(&dependency->commit.link);
- wl_list_remove(&dependency->node_destroy.link);
- wl_list_remove(&dependency->surface_destroy.link);
- wl_list_remove(&dependency->link);
- pixman_region32_fini(&dependency->damage);
- free(dependency);
-}
-static void dependency_schedule(struct glass_dependency *dependency)
+struct glass_engine *rediwm_glass_create(void)
{
- dependency->effect->engine->resync = true;
- struct wlr_scene_output *out;
- wl_list_for_each(out, &dependency->effect->engine->scene->outputs, link)
- wlr_output_schedule_frame(out->output);
-}
-static void dependency_node_destroy(struct wl_listener *listener, void *data)
-{
- (void)data;
- struct glass_dependency *dependency = wl_container_of(listener, dependency, node_destroy);
- dependency_schedule(dependency);
- dependency_destroy(dependency);
-}
-static void dependency_surface_destroy(struct wl_listener *listener, void *data)
-{
- (void)data;
- struct glass_dependency *dependency = wl_container_of(listener, dependency, surface_destroy);
- dependency_schedule(dependency);
- dependency_destroy(dependency);
-}
-static void dependency_commit(struct wl_listener *listener, void *data)
-{
- (void)data;
- struct glass_dependency *dependency = wl_container_of(listener, dependency, commit);
- const struct wlr_surface_state *state = &dependency->surface->current;
- if (state->buffer_width != dependency->width || state->buffer_height != dependency->height ||
- rediwm_surface_state_remapped(state))
- dependency->full_damage = true;
- dependency->width = state->buffer_width;
- dependency->height = state->buffer_height;
- if (!dependency->full_damage &&
- !pixman_region32_union(&dependency->damage, &dependency->damage,
- &dependency->surface->buffer_damage))
- dependency->full_damage = true;
- if (dependency->full_damage || pixman_region32_not_empty(&dependency->damage))
- dependency_schedule(dependency);
-}
-static struct glass_dependency *dependency_get(struct glass_effect *effect,
- struct wlr_scene_buffer *node, struct wlr_surface *surface)
-{
- struct glass_dependency *dependency;
- wl_list_for_each(dependency, &effect->dependencies, link)
- if (dependency->node == node) {
- dependency->seen = true;
- return dependency;
- }
- dependency = calloc(1, sizeof(*dependency));
- if (!dependency)
- return NULL;
- dependency->effect = effect;
- dependency->node = node;
- dependency->surface = surface;
- dependency->width = surface->current.buffer_width;
- dependency->height = surface->current.buffer_height;
- dependency->revision = 1;
- dependency->seen = true;
- pixman_region32_init(&dependency->damage);
- dependency->commit.notify = dependency_commit;
- dependency->node_destroy.notify = dependency_node_destroy;
- dependency->surface_destroy.notify = dependency_surface_destroy;
- wl_signal_add(&surface->events.commit, &dependency->commit);
- wl_signal_add(&surface->events.destroy, &dependency->surface_destroy);
- wl_signal_add(&node->node.events.destroy, &dependency->node_destroy);
- wl_list_insert(&effect->dependencies, &dependency->link);
- return dependency;
-}
-
-static void dependencies_begin(struct glass_effect *effect)
-{
- struct glass_dependency *dependency;
- wl_list_for_each(dependency, &effect->dependencies, link)
- dependency->seen = false;
-}
-static void dependencies_prune(struct glass_effect *effect)
-{
- struct glass_dependency *dependency, *next;
- wl_list_for_each_safe(dependency, next, &effect->dependencies, link)
- if (!dependency->seen)
- dependency_destroy(dependency);
-}
-
-static uint64_t dependency_revision(struct glass_dependency *dependency,
- const struct wlr_box *bounds, const struct wlr_box *intersection,
- double capture_pixel_width, double capture_pixel_height)
-{
- struct wlr_scene_buffer *node = dependency->node;
- bool changed = dependency->full_damage;
- if (pixman_region32_not_empty(&dependency->damage)) {
- // Non-normal transforms remain conservative until their texture mapping
- // is supported here. Buffer scale and viewporter cropping are represented
- // by the scene's source box and destination dimensions.
- if (node->transform != WL_OUTPUT_TRANSFORM_NORMAL || bounds->width <= 0 || bounds->height <= 0) {
- changed = true;
- } else {
- struct wlr_fbox src = node->src_box;
- if (wlr_fbox_empty(&src))
- src = (struct wlr_fbox){0, 0, dependency->width, dependency->height};
- double sx = src.width / bounds->width, sy = src.height / bounds->height;
- // The quarter-size destination is rounded and bilinearly sampled.
- // Include one capture pixel plus one source texel on each edge.
- double pad_x = capture_pixel_width * sx + 1, pad_y = capture_pixel_height * sy + 1;
- pixman_box32_t sample = {
- .x1 = floor(src.x + (intersection->x - bounds->x) * sx - pad_x),
- .y1 = floor(src.y + (intersection->y - bounds->y) * sy - pad_y),
- .x2 = ceil(src.x + (intersection->x + intersection->width - bounds->x) * sx + pad_x),
- .y2 = ceil(src.y + (intersection->y + intersection->height - bounds->y) * sy + pad_y),
- };
- changed |= pixman_region32_contains_rectangle(&dependency->damage, &sample) != PIXMAN_REGION_OUT;
- }
- }
- if (changed)
- dependency->revision++;
- dependency->full_damage = false;
- pixman_region32_clear(&dependency->damage);
- return dependency->revision;
-}
-
-// Save both EGL and the GL state touched here. All custom GL work happens
-// outside a wlroots render pass, in the renderer's own context.
-struct gl_context {
- EGLDisplay display, previous_display;
- EGLContext previous_context;
- EGLSurface draw, read;
- GLint fbo, program, array_buffer, active_texture, texture, alpha_texture, viewport[4];
- GLint attr_enabled, attr_size, attr_type, attr_normalized, attr_stride, attr_buffer;
- void *attr_pointer;
- GLboolean blend, scissor;
-};
-static bool enter(struct glass_engine *engine, struct gl_context *state)
-{
- struct wlr_egl *egl = wlr_gles2_renderer_get_egl(engine->renderer);
- state->display = wlr_egl_get_display(egl);
- state->previous_display = eglGetCurrentDisplay();
- state->previous_context = eglGetCurrentContext();
- state->draw = eglGetCurrentSurface(EGL_DRAW);
- state->read = eglGetCurrentSurface(EGL_READ);
- if (!eglMakeCurrent(state->display, EGL_NO_SURFACE, EGL_NO_SURFACE,
- wlr_egl_get_context(egl)))
- return false;
- glGetIntegerv(GL_FRAMEBUFFER_BINDING, &state->fbo);
- glGetIntegerv(GL_CURRENT_PROGRAM, &state->program);
- glGetIntegerv(GL_ARRAY_BUFFER_BINDING, &state->array_buffer);
- glGetIntegerv(GL_ACTIVE_TEXTURE, &state->active_texture);
- glActiveTexture(GL_TEXTURE1);
- glGetIntegerv(GL_TEXTURE_BINDING_2D, &state->alpha_texture);
- glActiveTexture(GL_TEXTURE0);
- glGetIntegerv(GL_TEXTURE_BINDING_2D, &state->texture);
- glGetIntegerv(GL_VIEWPORT, state->viewport);
- state->blend = glIsEnabled(GL_BLEND);
- state->scissor = glIsEnabled(GL_SCISSOR_TEST);
- glGetVertexAttribiv(0, GL_VERTEX_ATTRIB_ARRAY_ENABLED, &state->attr_enabled);
- glGetVertexAttribiv(0, GL_VERTEX_ATTRIB_ARRAY_SIZE, &state->attr_size);
- glGetVertexAttribiv(0, GL_VERTEX_ATTRIB_ARRAY_TYPE, &state->attr_type);
- glGetVertexAttribiv(0, GL_VERTEX_ATTRIB_ARRAY_NORMALIZED, &state->attr_normalized);
- glGetVertexAttribiv(0, GL_VERTEX_ATTRIB_ARRAY_STRIDE, &state->attr_stride);
- glGetVertexAttribiv(0, GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING, &state->attr_buffer);
- glGetVertexAttribPointerv(0, GL_VERTEX_ATTRIB_ARRAY_POINTER, &state->attr_pointer);
- glDisable(GL_BLEND);
- glDisable(GL_SCISSOR_TEST);
- return true;
-}
-static void leave(struct gl_context *state)
-{
- glBindFramebuffer(GL_FRAMEBUFFER, state->fbo);
- glUseProgram(state->program);
- glBindTexture(GL_TEXTURE_2D, state->texture);
- glActiveTexture(GL_TEXTURE1);
- glBindTexture(GL_TEXTURE_2D, state->alpha_texture);
- glActiveTexture(state->active_texture);
- glViewport(state->viewport[0], state->viewport[1], state->viewport[2], state->viewport[3]);
- if (state->blend)
- glEnable(GL_BLEND);
- else
- glDisable(GL_BLEND);
- if (state->scissor)
- glEnable(GL_SCISSOR_TEST);
- else
- glDisable(GL_SCISSOR_TEST);
- glBindBuffer(GL_ARRAY_BUFFER, state->attr_buffer);
- glVertexAttribPointer(0, state->attr_size, state->attr_type, state->attr_normalized,
- state->attr_stride, state->attr_pointer);
- if (state->attr_enabled)
- glEnableVertexAttribArray(0);
- else
- glDisableVertexAttribArray(0);
- glBindBuffer(GL_ARRAY_BUFFER, state->array_buffer);
- if (state->previous_display != EGL_NO_DISPLAY) {
- eglMakeCurrent(state->previous_display, state->draw, state->read,
- state->previous_context);
- } else {
- eglMakeCurrent(state->display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
- }
-}
-
-static const char vertex_source[] =
- "attribute vec2 position; varying vec2 uv;"
- "void main(){ uv=position*.5+.5; gl_Position=vec4(position,0.,1.); }";
-// CSS blur length is Gaussian sigma. A 3-sigma kernel on a quarter-size
-// capture keeps the filter inexpensive; geometry and corner AA stay native.
-static const char blur_source[] =
- "precision highp float; varying vec2 uv; uniform sampler2D tex;"
- "uniform vec2 step_uv; uniform float sigma; uniform vec4 limits;"
- "void main(){ vec4 sum=vec4(0.); float weight=0.;"
- "for(int i=-24;i<=24;i++){ float x=float(i);"
- "float w=exp(-.5*x*x/(sigma*sigma));"
- "sum+=texture2D(tex,clamp(uv+x*step_uv,limits.xy,limits.zw))*w; weight+=w; }"
- "gl_FragColor=sum/weight; }";
-static const char finish_source[] =
- "precision highp float; varying vec2 uv; uniform sampler2D tex, alpha_tex;"
- "uniform float has_alpha_tex, target_opacity;"
- "uniform vec2 capture_size, size; uniform float padding, radius, scale, saturation, opacity, "
- "top_only;"
- "void main(){ vec2 p=uv*size; vec2 at=(p+padding)/capture_size;"
- "vec3 rgb=texture2D(tex,at).rgb; float l=dot(rgb,vec3(.213,.715,.072));"
- "rgb=clamp(vec3(l)+(rgb-vec3(l))*saturation,0.,1.);"
- "vec2 frame=size; if(top_only>.5) frame.y+=2.*radius;"
- "vec2 q=abs(p-frame*.5)-(frame*.5-vec2(radius));"
- "float d=length(max(q,0.))+min(max(q.x,q.y),0.)-radius;"
- "float coverage=clamp(.5-d*scale,0.,1.)*opacity;"
- // Target pixels already contain their tint, text, coverage and panel fade.
- // Choose the backing alpha so the pair has exactly coverage*opacity,
- // avoiding double coverage on curved edges and a double fade on panels.
- "float front=texture2D(alpha_tex,uv).a*has_alpha_tex*target_opacity;"
- "float a=front>=.99999?0.:clamp((coverage-front)/(1.-front),0.,1.);"
- "gl_FragColor=vec4(rgb*a,a); }";
-
-static GLuint shader(GLenum type, const char *source)
-{
- GLuint id = glCreateShader(type);
- glShaderSource(id, 1, &source, NULL);
- glCompileShader(id);
- GLint ok;
- glGetShaderiv(id, GL_COMPILE_STATUS, &ok);
- if (!ok) {
- char log[1024];
- glGetShaderInfoLog(id, sizeof(log), NULL, log);
- wlr_log(WLR_ERROR, "glass shader: %s", log);
- glDeleteShader(id);
- return 0;
- }
- return id;
-}
-static GLuint program(const char *fragment)
-{
- GLuint vs = shader(GL_VERTEX_SHADER, vertex_source),
- fs = shader(GL_FRAGMENT_SHADER, fragment);
- if (!vs || !fs) {
- glDeleteShader(vs);
- glDeleteShader(fs);
- return 0;
- }
- GLuint id = glCreateProgram();
- glAttachShader(id, vs);
- glAttachShader(id, fs);
- glBindAttribLocation(id, 0, "position");
- glLinkProgram(id);
- glDeleteShader(vs);
- glDeleteShader(fs);
- GLint ok;
- glGetProgramiv(id, GL_LINK_STATUS, &ok);
- if (!ok) {
- glDeleteProgram(id);
- return 0;
- }
- return id;
-}
-
-struct glass_engine *rediwm_glass_create(struct wlr_renderer *renderer,
- struct wlr_allocator *allocator, struct wlr_scene *scene,
- struct rediwm_read_fence *read_fence)
-{
- if (!wlr_renderer_is_gles2(renderer)) {
- wlr_log(WLR_INFO, "glass: backdrop filters require GLES2; using CSS tints only");
- return NULL;
- }
struct glass_engine *engine = calloc(1, sizeof(*engine));
if (!engine)
return NULL;
- engine->renderer = renderer;
- engine->allocator = allocator;
- engine->scene = scene;
- engine->read_fence = read_fence;
wl_list_init(&engine->effects);
- struct gl_context state;
- if (!enter(engine, &state)) {
- free(engine);
- return NULL;
- }
- engine->blur = program(blur_source);
- engine->finish = program(finish_source);
- const GLfloat vertices[] = {-1, -1, 1, -1, -1, 1, 1, 1};
- glGenBuffers(1, &engine->vertices);
- glBindBuffer(GL_ARRAY_BUFFER, engine->vertices);
- glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
- engine->failed = !engine->blur || !engine->finish;
- leave(&state);
return engine;
}
-
-static void release_capture(struct glass_effect *effect)
-{
- if (effect->capture_texture)
- wlr_texture_destroy(effect->capture_texture);
- if (effect->capture)
- wlr_buffer_drop(effect->capture);
- effect->capture_texture = NULL;
- effect->capture = NULL;
-}
static void handle_destroy(struct wl_listener *listener, void *data)
{
(void)data;
@@ -414,19 +49,6 @@ static void handle_destroy(struct wl_listener *listener, void *data)
wl_list_remove(&effect->destroy.link);
wl_list_remove(&effect->target_destroy.link);
wl_list_remove(&effect->link);
- struct glass_dependency *dependency, *next;
- wl_list_for_each_safe(dependency, next, &effect->dependencies, link)
- dependency_destroy(dependency);
- release_capture(effect);
- for (int i = 0; i < 2; i++)
- if (effect->output[i])
- wlr_buffer_drop(effect->output[i]);
- struct gl_context state;
- if (enter(effect->engine, &state)) {
- glDeleteTextures(2, effect->intermediate);
- glDeleteFramebuffers(2, effect->intermediate_fbo);
- leave(&state);
- }
free(effect);
}
static void handle_target_destroy(struct wl_listener *listener, void *data)
@@ -438,12 +60,17 @@ static void handle_target_destroy(struct wl_listener *listener, void *data)
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)
+static struct glass_effect *effect_of(struct wlr_scene_node *node)
{
struct wlr_addon *addon = wlr_addon_find(&node->addons, NULL, &effect_addon);
- if (!addon)
+ struct glass_effect *effect;
+ return addon ? (effect = wl_container_of(addon, effect, addon)) : NULL;
+}
+bool rediwm_glass_effect_info(struct wlr_scene_node *node, struct rediwm_glass_info *out)
+{
+ struct glass_effect *effect = effect_of(node);
+ if (!effect)
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,
@@ -455,6 +82,10 @@ bool rediwm_glass_effect_info(struct wlr_scene_node *node, struct rediwm_glass_i
};
return true;
}
+bool rediwm_glass_is_effect_node(struct wlr_scene_node *node)
+{
+ return node->type == WLR_SCENE_NODE_BUFFER && effect_of(node);
+}
static bool accepts_input(struct wlr_scene_buffer *buffer, double *x, double *y)
{
(void)buffer;
@@ -466,7 +97,7 @@ struct glass_effect *rediwm_glass_attach(struct glass_engine *engine,
struct wlr_scene_buffer *target,
struct wlr_scene_node *before, enum glass_kind kind)
{
- if (!engine || engine->failed)
+ if (!engine)
return NULL;
struct glass_effect *effect = calloc(1, sizeof(*effect));
if (!effect)
@@ -477,15 +108,12 @@ struct glass_effect *rediwm_glass_attach(struct glass_engine *engine,
return NULL;
}
effect->engine = engine;
- wl_list_init(&effect->dependencies);
effect->target = target;
effect->kind = kind;
effect->opacity = 1;
- effect->zoom = 1;
- effect->node->point_accepts_input = accepts_input;
effect->serial = ++engine->next_serial;
+ effect->node->point_accepts_input = accepts_input;
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;
wl_signal_add(&effect->node->node.events.destroy, &effect->destroy);
@@ -494,29 +122,20 @@ struct glass_effect *rediwm_glass_attach(struct glass_engine *engine,
wl_list_insert(&engine->effects, &effect->link);
return effect;
}
-// Moving a nearly opaque surface would repaint its blur every frame for an
-// imperceptible change. The caller decides opacity and schedules a frame on
-// release; that frame refreshes the formerly held effect even without damage.
void rediwm_glass_hold(struct glass_engine *engine, struct glass_effect *effect)
{
- if (!engine || engine->held == effect)
- return;
- engine->held = effect;
- engine->resync = true;
+ if (engine)
+ engine->held = effect;
}
void rediwm_glass_hold_all(struct glass_engine *engine, bool hold)
{
- if (!engine || engine->hold_all == hold)
- return;
- engine->hold_all = hold;
- engine->resync = true;
+ if (engine)
+ engine->hold_all = hold;
}
void rediwm_glass_configure(struct glass_effect *effect, float radius, float opacity)
{
if (!effect)
return;
- if (effect->radius != radius || effect->opacity != opacity)
- effect->valid = false;
effect->radius = radius;
effect->opacity = opacity;
}
@@ -526,580 +145,6 @@ void rediwm_glass_destroy(struct glass_engine *engine)
return;
struct glass_effect *effect, *tmp;
wl_list_for_each_safe(effect, tmp, &engine->effects, link)
- wlr_scene_node_destroy(&effect->node->node);
- struct gl_context state;
- if (enter(engine, &state)) {
- glDeleteProgram(engine->blur);
- glDeleteProgram(engine->finish);
- glDeleteBuffers(1, &engine->vertices);
- leave(&state);
- }
+ wlr_scene_node_destroy(&effect->node->node);
free(engine);
}
-
-static struct wlr_buffer *allocate(struct glass_engine *engine, int width, int height)
-{
- // Implicit modifiers let GBM choose a renderable layout. Using all the
- // sampling modifiers can select a layout that cannot be a render target.
- uint64_t modifier = DRM_FORMAT_MOD_INVALID;
- struct wlr_drm_format format = {
- .format = DRM_FORMAT_ARGB8888,
- .len = 1,
- .capacity = 1,
- .modifiers = &modifier,
- };
- return wlr_allocator_create_buffer(engine->allocator, width, height, &format);
-}
-static struct glass_effect *effect_for(struct glass_engine *engine, struct wlr_scene_node *node)
-{
- struct glass_effect *effect;
- wl_list_for_each(effect, &engine->effects,
- link) if (&effect->node->node == node || (effect->projected_node && &effect->projected_node->node == node)) return effect;
- return NULL;
-}
-static void hash_bytes(uint64_t *hash, const void *data, size_t size)
-{
- const uint8_t *p = data;
- for (size_t i = 0; i < size; i++) {
- *hash ^= p[i];
- *hash *= UINT64_C(1099511628211);
- }
-}
-#define HASH(h, value) hash_bytes(h, &(value), sizeof(value))
-struct capture {
- struct glass_effect *effect;
- struct wlr_box box;
- int width, height;
- uint64_t hash;
- struct wlr_render_pass *pass;
- bool failed;
- // The prefix includes an explicit-sync client buffer; found while hashing.
- bool explicit_sync;
- struct wl_list textures;
-};
-struct temporary_texture {
- struct wl_list link;
- struct wlr_texture *texture;
-};
-static struct wlr_box destination(struct capture *capture, int x, int y, int w, int h)
-{
- double sx = (double)capture->width / capture->box.width;
- double sy = (double)capture->height / capture->box.height;
- int left = lround((x - capture->box.x) * sx), top = lround((y - capture->box.y) * sy);
- return (struct wlr_box){left, top, lround((x + w - capture->box.x) * sx) - left,
- lround((y + h - capture->box.y) * sy) - top};
-}
-
-static void capture_buffer_hash(struct capture *capture, struct wlr_scene_buffer *buffer,
- struct wlr_surface *surface, const struct wlr_box *bounds,
- const struct wlr_box *intersection)
-{
- struct glass_dependency *dependency = surface ?
- dependency_get(capture->effect, buffer, surface) : NULL;
- if (dependency) {
- uint64_t revision = dependency_revision(dependency, bounds, intersection,
- (double)capture->box.width / capture->width,
- (double)capture->box.height / capture->height);
- HASH(&capture->hash, revision);
- // Presence is a mapping change; rotating equally sized client buffers
- // with empty damage does not change the sampled content.
- struct wlr_client_buffer *client = buffer->buffer ? wlr_client_buffer_get(buffer->buffer) : NULL;
- bool present = buffer->private.is_single_pixel_buffer || buffer->private.texture ||
- (client && client->texture);
- HASH(&capture->hash, present);
- HASH(&capture->hash, buffer->private.buffer_is_opaque);
- } else {
- HASH(&capture->hash, buffer->buffer);
- HASH(&capture->hash, buffer->private.texture);
- // Allocation failure retains the conservative previous behavior.
- if (surface)
- HASH(&capture->hash, surface->current.seq);
- }
- HASH(&capture->hash, buffer->src_box);
- HASH(&capture->hash, buffer->filter_mode);
- HASH(&capture->hash, buffer->opacity);
- HASH(&capture->hash, buffer->transform);
- HASH(&capture->hash, buffer->transfer_function);
- HASH(&capture->hash, buffer->primaries);
- HASH(&capture->hash, buffer->color_encoding);
- HASH(&capture->hash, buffer->color_range);
- if (buffer->private.is_single_pixel_buffer)
- HASH(&capture->hash, buffer->private.single_pixel_buffer_color);
- struct glass_effect *previous = effect_for(capture->effect->engine, &buffer->node);
- if (previous)
- HASH(&capture->hash, previous->revision);
-}
-
-// Iterate in paint order, stopping BEFORE the glass and its own shadow.
-// Do not use scene visibility: it culls opaque occluders, whereas the blur
-// needs pixels outside the glass and underneath foreground windows too.
-static bool capture_prefix(struct capture *capture, struct wlr_scene_node *node, int x, int y)
-{
- if (node == &capture->effect->node->node)
- return true;
- if (!node->enabled)
- return false;
- x += node->x;
- y += node->y;
- if (node->type == WLR_SCENE_NODE_TREE) {
- struct wlr_scene_tree *tree = wlr_scene_tree_from_node(node);
- struct wlr_scene_node *child;
- wl_list_for_each(child, &tree->children, link)
- {
- if (capture_prefix(capture, child, x, y))
- return true;
- }
- return false;
- }
- int width, height;
- struct wlr_scene_buffer *buffer = NULL;
- struct wlr_scene_rect *rect = NULL;
- if (node->type == WLR_SCENE_NODE_RECT) {
- rect = wlr_scene_rect_from_node(node);
- width = rect->width;
- height = rect->height;
- } else {
- buffer = wlr_scene_buffer_from_node(node);
- width = buffer->dst_width;
- height = buffer->dst_height;
- if (!width || !height) {
- width = buffer->private.buffer_width;
- height = buffer->private.buffer_height;
- if (buffer->transform & 1) {
- int tmp = width;
- width = height;
- height = tmp;
- }
- }
- }
- struct wlr_box bounds = {x, y, width, height}, intersection;
- if (!wlr_box_intersection(&intersection, &bounds, &capture->box))
- return false;
- HASH(&capture->hash, node);
- HASH(&capture->hash, bounds);
- struct wlr_box dst = destination(capture, x, y, width, height);
- if (dst.width <= 0 || dst.height <= 0)
- return false;
- if (rect) {
- HASH(&capture->hash, rect->color);
- if (capture->pass)
- wlr_render_pass_add_rect(capture->pass,
- &(struct wlr_render_rect_options){
- .box = dst,
- .color = {rect->color[0], rect->color[1],
- rect->color[2], rect->color[3]},
- });
- return false;
- }
- struct wlr_scene_node *source = rediwm_projection_source(&buffer->node);
- struct wlr_scene_surface *surface = wlr_scene_surface_try_from_buffer(wlr_scene_buffer_from_node(source));
- capture_buffer_hash(capture, buffer, surface ? surface->surface : NULL, &bounds, &intersection);
- if (surface && rediwm_surface_explicit_sync(surface->surface)) {
- capture->explicit_sync = true;
- rediwm_read_fence_note(capture->effect->engine->read_fence, surface->surface);
- }
- if (!capture->pass)
- return false;
- if (buffer->private.is_single_pixel_buffer) {
- const uint32_t *c = buffer->private.single_pixel_buffer_color;
- double alpha = (double)c[3] / UINT32_MAX * buffer->opacity;
- wlr_render_pass_add_rect(
- capture->pass,
- &(struct wlr_render_rect_options){
- .box = dst,
- .color = {(double)c[0] / UINT32_MAX * buffer->opacity,
- (double)c[1] / UINT32_MAX * buffer->opacity,
- (double)c[2] / UINT32_MAX * buffer->opacity, alpha},
- });
- return false;
- }
- struct wlr_texture *texture = buffer->private.texture;
- // wlr_scene keeps a surface's texture on its client buffer, never in
- // private.texture. Re-importing it would upload a whole shm window, or
- // create an EGLImage for each new dmabuf, on every glass repaint. A
- // client buffer without a texture is not drawn by the scene either.
- struct wlr_client_buffer *client_buffer =
- buffer->buffer ? wlr_client_buffer_get(buffer->buffer) : NULL;
- if (!texture && client_buffer)
- texture = client_buffer->texture;
- else if (!texture && buffer->buffer) {
- // Imports live until submit, including on deferred renderer backends.
- struct temporary_texture *temp = calloc(1, sizeof(*temp));
- if (!temp) {
- capture->failed = true;
- return false;
- }
- temp->texture =
- wlr_texture_from_buffer(capture->effect->engine->renderer, buffer->buffer);
- if (!temp->texture) {
- free(temp);
- capture->failed = true;
- return false;
- }
- texture = temp->texture;
- wl_list_insert(&capture->textures, &temp->link);
- }
- if (!texture)
- return false;
- struct wlr_color_primaries primaries;
- wlr_color_primaries_from_named(
- &primaries, buffer->primaries ? buffer->primaries : WLR_COLOR_NAMED_PRIMARIES_SRGB);
- wlr_render_pass_add_texture(capture->pass,
- &(struct wlr_render_texture_options){
- .texture = texture,
- .src_box = buffer->src_box,
- .dst_box = dst,
- .alpha = &buffer->opacity,
- .transform = wlr_output_transform_invert(buffer->transform),
- .filter_mode = WLR_SCALE_FILTER_BILINEAR,
- .transfer_function = buffer->transfer_function,
- .primaries = &primaries,
- .color_encoding = buffer->color_encoding,
- .color_range = buffer->color_range,
- .wait_timeline = buffer->private.wait_timeline,
- .wait_point = buffer->private.wait_point,
- });
- return false;
-}
-
-static void uniform1(GLuint program_id, const char *name, float value)
-{
- glUniform1f(glGetUniformLocation(program_id, name), value);
-}
-static void uniform2(GLuint program_id, const char *name, float x, float y)
-{
- glUniform2f(glGetUniformLocation(program_id, name), x, y);
-}
-static void draw_setup(struct glass_engine *engine, GLuint program_id, GLuint texture, GLuint fbo,
- int w, int h)
-{
- glBindFramebuffer(GL_FRAMEBUFFER, fbo);
- glViewport(0, 0, w, h);
- glUseProgram(program_id);
- glBindTexture(GL_TEXTURE_2D, texture);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- glUniform1i(glGetUniformLocation(program_id, "tex"), 0);
- glBindBuffer(GL_ARRAY_BUFFER, engine->vertices);
- glEnableVertexAttribArray(0);
- glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 0, NULL);
-}
-
-static bool render_effect(struct glass_effect *effect, struct capture *capture, int width,
- int height, int padding, float sigma, float saturation, float scale)
-{
- struct glass_engine *engine = effect->engine;
- if (!effect->capture || effect->capture->width != capture->width ||
- effect->capture->height != capture->height) {
- release_capture(effect);
- effect->capture = allocate(engine, capture->width, capture->height);
- if (!effect->capture)
- return false;
- effect->capture_texture =
- wlr_texture_from_buffer(engine->renderer, effect->capture);
- if (!effect->capture_texture) {
- release_capture(effect);
- return false;
- }
- }
- // The scene registers release points only for what outputs draw, and this
- // also samples beneath opaque windows.
- struct wlr_buffer_pass_options options = {0};
- if (capture->explicit_sync)
- rediwm_read_fence_begin(engine->read_fence, &options);
- capture->pass = wlr_renderer_begin_buffer_pass(engine->renderer, effect->capture, &options);
- if (!capture->pass) {
- rediwm_read_fence_end(engine->read_fence, false);
- return false;
- }
- wl_list_init(&capture->textures);
- wlr_render_pass_add_rect(capture->pass, &(struct wlr_render_rect_options){
- .box = {0, 0, capture->width, capture->height},
- .color = {0, 0, 0, 1},
- .blend_mode = WLR_RENDER_BLEND_MODE_NONE,
- });
- capture_prefix(capture, &engine->scene->tree.node, 0, 0);
- bool ok = wlr_render_pass_submit(capture->pass);
- rediwm_read_fence_end(engine->read_fence, ok);
- struct temporary_texture *temp, *tmp;
- wl_list_for_each_safe(temp, tmp, &capture->textures, link)
- {
- wlr_texture_destroy(temp->texture);
- wl_list_remove(&temp->link);
- free(temp);
- }
- if (!ok || capture->failed)
- return false;
- int dw = lround(width * scale), dh = lround(height * scale);
- int slot = effect->output[0] && effect->output[0]->n_locks ? 1 : 0;
- struct wlr_buffer *out = effect->output[slot];
- if (out && (out->width != dw || out->height != dh || out->n_locks)) {
- wlr_buffer_drop(out);
- effect->output[slot] = out = NULL;
- }
- if (!out)
- effect->output[slot] = out = allocate(engine, dw, dh);
- if (!out)
- return false;
- struct wlr_texture *alpha_texture = effect->target->private.texture;
- bool own_alpha = false;
- if (!alpha_texture && effect->target->buffer) {
- alpha_texture = wlr_texture_from_buffer(engine->renderer, effect->target->buffer);
- if (!alpha_texture)
- return false;
- own_alpha = true;
- }
- struct gl_context state;
- if (!enter(engine, &state)) {
- if (own_alpha)
- wlr_texture_destroy(alpha_texture);
- return false;
- }
- GLuint output_fbo = wlr_gles2_renderer_get_buffer_fbo(engine->renderer, out);
- struct wlr_gles2_texture_attribs attribs;
- GLint alpha_min = GL_NEAREST, alpha_mag = GL_NEAREST;
- GLuint alpha_id = 0;
- wlr_gles2_texture_get_attribs(effect->capture_texture, &attribs);
- if (!output_fbo || attribs.target != GL_TEXTURE_2D) {
- ok = false;
- goto done;
- }
- if (!effect->intermediate[0]) {
- glGenTextures(2, effect->intermediate);
- glGenFramebuffers(2, effect->intermediate_fbo);
- }
- for (int i = 0; i < 2; i++) {
- glBindTexture(GL_TEXTURE_2D, effect->intermediate[i]);
- if (effect->intermediate_width != capture->width ||
- effect->intermediate_height != capture->height) {
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, capture->width, capture->height, 0,
- GL_RGBA, GL_UNSIGNED_BYTE, NULL);
- }
- glBindFramebuffer(GL_FRAMEBUFFER, effect->intermediate_fbo[i]);
- glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
- effect->intermediate[i], 0);
- if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
- ok = false;
- goto done;
- }
- draw_setup(engine, engine->blur, i ? effect->intermediate[0] : attribs.tex,
- effect->intermediate_fbo[i], capture->width, capture->height);
- uniform2(engine->blur, "step_uv", i ? 0 : 1.f / capture->width,
- i ? 1.f / capture->height : 0);
- uniform1(engine->blur, "sigma",
- sigma * (i ? (float)capture->height / capture->box.height
- : (float)capture->width / capture->box.width));
- // Duplicate the root backdrop's edge pixels, as CSS filters do, so
- // the taskbar does not mix black from below the output into its glass.
- struct wlr_box root = engine->bounds;
- if (wlr_box_empty(&root))
- root = capture->box;
- float left = fmaxf(.5f / capture->width,
- (float)(root.x - capture->box.x) / capture->box.width +
- .5f / capture->width);
- float top = fmaxf(.5f / capture->height,
- (float)(root.y - capture->box.y) / capture->box.height +
- .5f / capture->height);
- float right =
- fminf(1 - .5f / capture->width,
- (float)(root.x + root.width - capture->box.x) / capture->box.width -
- .5f / capture->width);
- float bottom =
- fminf(1 - .5f / capture->height,
- (float)(root.y + root.height - capture->box.y) / capture->box.height -
- .5f / capture->height);
- glUniform4f(glGetUniformLocation(engine->blur, "limits"), left, top,
- fmaxf(left, right), fmaxf(top, bottom));
- glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
- }
- effect->intermediate_width = capture->width;
- effect->intermediate_height = capture->height;
- draw_setup(engine, engine->finish, effect->intermediate[1], output_fbo, dw, dh);
- struct wlr_gles2_texture_attribs alpha_attribs = {.target = GL_TEXTURE_2D,
- .tex = effect->intermediate[1]};
- if (alpha_texture)
- wlr_gles2_texture_get_attribs(alpha_texture, &alpha_attribs);
- if (alpha_attribs.target != GL_TEXTURE_2D) {
- ok = false;
- goto done;
- }
- glActiveTexture(GL_TEXTURE1);
- glBindTexture(GL_TEXTURE_2D, alpha_attribs.tex);
- alpha_id = alpha_attribs.tex;
- glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, &alpha_min);
- glGetTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, &alpha_mag);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- glUniform1i(glGetUniformLocation(engine->finish, "alpha_tex"), 1);
- uniform1(engine->finish, "has_alpha_tex", alpha_texture != NULL);
- uniform1(engine->finish, "target_opacity", effect->target->opacity);
- glActiveTexture(GL_TEXTURE0);
- uniform2(engine->finish, "capture_size", capture->box.width, capture->box.height);
- uniform2(engine->finish, "size", width, height);
- uniform1(engine->finish, "padding", padding);
- uniform1(engine->finish, "radius", fminf(effect->radius, fminf(width, height) / 2));
- uniform1(engine->finish, "scale", scale);
- uniform1(engine->finish, "saturation", saturation);
- uniform1(engine->finish, "opacity", effect->opacity);
- uniform1(engine->finish, "top_only", effect->kind == GLASS_TITLEBAR);
- glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
- glFlush();
- ok = glGetError() == GL_NO_ERROR;
-done:
- if (alpha_id) {
- glActiveTexture(GL_TEXTURE1);
- glBindTexture(GL_TEXTURE_2D, alpha_id);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, alpha_min);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, alpha_mag);
- glActiveTexture(GL_TEXTURE0);
- }
- leave(&state);
- if (own_alpha)
- wlr_texture_destroy(alpha_texture);
- if (!ok)
- return false;
- wlr_scene_buffer_set_buffer(effect->node, out);
- wlr_scene_buffer_set_dest_size(effect->node, width, height);
- effect->width = width;
- effect->height = height;
- effect->scale = scale;
- effect->revision++;
- return true;
-}
-
-static void update_effect_inner(struct glass_effect *effect, float scale)
-{
- struct wlr_scene_buffer *target = effect->target;
- int x = 0, y = 0;
- bool visible = wlr_scene_node_coords(&target->node, &x, &y) && target->dst_width > 0 &&
- target->dst_height > 0;
- struct wlr_box target_box = {x, y, target->dst_width, target->dst_height}, intersection;
- if (visible && !wlr_box_empty(&effect->engine->bounds))
- visible = wlr_box_intersection(&intersection, &target_box, &effect->engine->bounds);
- wlr_scene_node_set_enabled(&effect->node->node, visible);
- if (!visible)
- return;
- wlr_scene_node_set_position(&effect->node->node, target->node.x, target->node.y);
- // The held blur travels with its target. Skip even the hash walk, but
- // never show a buffer rendered for a different size or scale.
- if ((effect == effect->engine->held || effect->engine->hold_all) && effect->valid &&
- effect->width == target->dst_width && effect->height == target->dst_height &&
- effect->scale == scale)
- return;
- float sigma = (effect->kind == GLASS_TITLEBAR ? 22 : effect->kind == GLASS_TASKBAR ? 24 : 26) * effect->zoom;
- float saturation = effect->kind == GLASS_PANEL ? 1.6f : 1.5f;
- int padding = ceilf(3 * sigma), width = target->dst_width, height = target->dst_height;
- struct capture capture = {
- .effect = effect,
- .box = {x - padding, y - padding, width + 2 * padding, height + 2 * padding},
- .width = (width + 2 * padding + 3) / 4,
- .height = (height + 2 * padding + 3) / 4,
- .hash = UINT64_C(14695981039346656037),
- };
- HASH(&capture.hash, capture.box);
- HASH(&capture.hash, scale);
- HASH(&capture.hash, effect->radius);
- HASH(&capture.hash, effect->opacity);
- HASH(&capture.hash, effect->engine->bounds);
- HASH(&capture.hash, target->buffer);
- HASH(&capture.hash, target->private.texture);
- HASH(&capture.hash, target->opacity);
- dependencies_begin(effect);
- capture_prefix(&capture, &effect->engine->scene->tree.node, 0, 0);
- dependencies_prune(effect);
- uint64_t hash = capture.hash;
- if (effect->valid && effect->hash == hash)
- return;
- if (render_effect(effect, &capture, width, height, padding, sigma, saturation, scale)) {
- effect->hash = hash;
- effect->valid = true;
- } else {
- wlr_scene_buffer_set_buffer(effect->node, NULL);
- effect->valid = false;
- if (!effect->engine->warned)
- wlr_log(WLR_ERROR, "glass: backdrop render failed; using CSS tint");
- effect->engine->warned = true;
- }
-}
-// Source glass is skipped with the disabled world. Render the same effect into
-// its presentation leaf, using projected bounds and world-scaled blur geometry.
-static void update_effect(struct glass_effect *effect, float scale) {
- struct wlr_scene_buffer *node = effect->node, *target = effect->target;
- float radius = effect->radius;
- if (effect->projected_node && effect->projected_target) {
- effect->node = effect->projected_node;
- effect->target = effect->projected_target;
- effect->radius *= effect->zoom;
- }
- update_effect_inner(effect, scale);
- rediwm_projection_effect_updated(effect->node, effect->target);
- effect->node = node; effect->target = target; effect->radius = radius;
-}
-bool rediwm_glass_is_effect_node(struct wlr_scene_node *node) {
- return node->type == WLR_SCENE_NODE_BUFFER &&
- wlr_scene_buffer_from_node(node)->point_accepts_input == accepts_input;
-}
-void rediwm_glass_project(struct glass_engine *engine, struct rediwm_projection *p, float zoom) {
- (void)zoom;
- if (!engine) return;
- struct glass_effect *effect;
- wl_list_for_each(effect, &engine->effects, link) {
- struct wlr_scene_node *node = rediwm_projection_node(p, &effect->node->node);
- struct wlr_scene_node *target = rediwm_projection_node(p, &effect->target->node);
- effect->projected_node = node ? wlr_scene_buffer_from_node(node) : NULL;
- effect->projected_target = target ? wlr_scene_buffer_from_node(target) : NULL;
- effect->zoom = node ? rediwm_projection_node_zoom(node) : 1;
- }
-}
-// The highest scale among the outputs showing the effect's target, or among all
-// outputs when it is on none. A scene node shows one buffer, so the blur is
-// rendered once for every output it spans, at the sharpest scale. It must not
-// depend on which output is being updated: the scale is part of the effect's
-// hash, so with outputs of different scales each output's update used to see a
-// new scale, re-render the blur and damage the others, and such a desktop never
-// went idle.
-static float effect_scale(struct glass_engine *engine, struct glass_effect *effect)
-{
- struct wlr_scene_buffer *target =
- effect->projected_node && effect->projected_target ? effect->projected_target : effect->target;
- struct wlr_box box = {0};
- int x = 0, y = 0;
- if (wlr_scene_node_coords(&target->node, &x, &y))
- box = (struct wlr_box){x, y, target->dst_width, target->dst_height};
- float shown = 0, any = 0;
- struct wlr_scene_output *out;
- wl_list_for_each(out, &engine->scene->outputs, link)
- {
- if (!out->output->enabled)
- continue;
- float scale = out->output->scale;
- any = fmaxf(any, scale);
- int width, height;
- wlr_output_effective_resolution(out->output, &width, &height);
- struct wlr_box area = {out->x, out->y, width, height}, overlap;
- if (!wlr_box_empty(&box) && wlr_box_intersection(&overlap, &box, &area))
- shown = fmaxf(shown, scale);
- }
- return shown > 0 ? shown : any > 0 ? any : 1;
-}
-static void update_tree(struct glass_engine *engine, struct wlr_scene_tree *tree)
-{
- struct wlr_scene_node *node;
- wl_list_for_each(node, &tree->children, link)
- {
- struct glass_effect *effect = effect_for(engine, node);
- if (effect)
- update_effect(effect, effect_scale(engine, effect));
- else if (node->enabled && node->type == WLR_SCENE_NODE_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)
-{
- (void)engine;
- (void)output;
-}
diff --git a/src/glass.zig b/src/glass.zig
index e5cddaa..674b763 100644
--- a/src/glass.zig
+++ b/src/glass.zig
@@ -1,5 +1,5 @@
-// The scene API has no backdrop-filter primitive. Keep the GLES/EGL bridge
-// in C, using wlroots' installed headers for its renderer and scene ABI.
+// Glass effects are registered here and drawn by the owned output pass
+// (scene_output.c); see glass.c.
const wlr = @import("wlroots");
pub const Kind = enum(c_int) { titlebar, taskbar, panel };
@@ -8,7 +8,7 @@ pub const Effect = opaque {
pub const configure = rediwm_glass_configure;
};
pub const Engine = opaque {
- extern fn rediwm_glass_create(renderer: *wlr.Renderer, allocator: *wlr.Allocator, scene: *wlr.Scene, read_fence: ?*@import("explicit_sync.zig").ReadFence) ?*Engine;
+ extern fn rediwm_glass_create() ?*Engine;
pub const create = rediwm_glass_create;
extern fn rediwm_glass_destroy(engine: ?*Engine) void;
pub const destroy = rediwm_glass_destroy;
@@ -18,8 +18,4 @@ pub const Engine = opaque {
pub const hold = rediwm_glass_hold;
extern fn rediwm_glass_hold_all(engine: ?*Engine, hold: bool) void;
pub const holdAll = rediwm_glass_hold_all;
- extern fn rediwm_glass_update(engine: ?*Engine, output: *wlr.SceneOutput) void;
- pub const update = rediwm_glass_update;
- extern fn rediwm_glass_project(engine: ?*Engine, projection: ?*anyopaque, zoom: f32) void;
- pub const project = rediwm_glass_project;
};
diff --git a/src/glass_test.c b/src/glass_test.c
index dfd2358..25828ea 100644
--- a/src/glass_test.c
+++ b/src/glass_test.c
@@ -1,4 +1,6 @@
-// GPU integration checks; run with `zig build test-glass` on a GLES2 host.
+// Glass registry and its geometry in the graph (stage 5 of docs/plans/scene-graph.md).
+// The output pass blurs; its pixel gates are in scene_pass_test.c and
+// tests/glass_reblur.py. Needs no GPU.
#include <stdbool.h>
#include <stdlib.h>
static bool fail_next_glass_allocation;
@@ -13,253 +15,77 @@ static void *glass_test_calloc(size_t count, size_t size)
#define calloc glass_test_calloc
#include "glass.c"
#undef calloc
+#include <assert.h>
+#include <math.h>
#include <stdio.h>
-#include <wlr/backend/headless.h>
+#include <drm_fourcc.h>
#include <wlr/interfaces/wlr_buffer.h>
+#include <wlr/util/log.h>
+#include "projection.h"
+#include "scene_graph.h"
struct test_buffer {
struct wlr_buffer base;
- uint32_t *pixels;
};
static void buffer_destroy(struct wlr_buffer *base)
{
struct test_buffer *buffer = wl_container_of(base, buffer, base);
- free(buffer->pixels);
free(buffer);
}
-static bool buffer_access(struct wlr_buffer *base, uint32_t flags, void **data, uint32_t *format,
- size_t *stride)
-{
- (void)flags;
- struct test_buffer *buffer = wl_container_of(base, buffer, base);
- *data = buffer->pixels;
- *format = DRM_FORMAT_ARGB8888;
- *stride = base->width * 4;
- return true;
-}
-static void buffer_end(struct wlr_buffer *base) { (void)base; }
-static const struct wlr_buffer_impl buffer_impl = {
- .destroy = buffer_destroy,
- .begin_data_ptr_access = buffer_access,
- .end_data_ptr_access = buffer_end,
-};
-static struct test_buffer *buffer_create(int width, int height, uint32_t top, uint32_t bottom)
+static const struct wlr_buffer_impl buffer_impl = {.destroy = buffer_destroy};
+static struct test_buffer *buffer_create(int width, int height)
{
struct test_buffer *buffer = calloc(1, sizeof(*buffer));
assert(buffer);
- buffer->pixels = calloc(width * height, 4);
- assert(buffer->pixels);
wlr_buffer_init(&buffer->base, &buffer_impl, width, height);
- for (int y = 0; y < height; y++)
- for (int x = 0; x < width; x++)
- buffer->pixels[y * width + x] = y < height / 2 ? top : bottom;
return buffer;
}
-
-static uint32_t pixel(struct glass_effect *effect, int x, int y)
-{
- struct wlr_texture *texture =
- wlr_texture_from_buffer(effect->engine->renderer, effect->node->buffer);
- assert(texture);
- uint32_t result = 0;
- assert(wlr_texture_read_pixels(texture, &(struct wlr_texture_read_pixels_options){
- .data = &result,
- .format = DRM_FORMAT_ARGB8888,
- .stride = 4,
- .src_box = {x, y, 1, 1},
- }));
- wlr_texture_destroy(texture);
- return result;
-}
-static void near_channel(uint32_t pixel_value, int shift, int expected, int tolerance)
-{
- int actual = (pixel_value >> shift) & 255;
- if (abs(actual - expected) > tolerance) {
- fprintf(stderr, "channel %d: got %d expected %d (+/-%d), pixel %08x\n", shift,
- actual, expected, tolerance, pixel_value);
- abort();
- }
-}
-
-static void damage_commit(struct wlr_surface *surface, int x, int y, int width, int height)
-{
- pixman_region32_clear(&surface->buffer_damage);
- assert(pixman_region32_union_rect(&surface->buffer_damage, &surface->buffer_damage,
- x, y, width, height));
- surface->current.seq++;
- wl_signal_emit_mutable(&surface->events.commit, surface);
-}
-static uint64_t damage_hash(struct glass_effect *effect, struct wlr_scene_buffer *node,
- struct wlr_surface *surface, const struct wlr_box *bounds,
- const struct wlr_box *sample)
-{
- struct capture capture = {
- .effect = effect, .box = *sample, .width = sample->width / 4,
- .height = sample->height / 4, .hash = UINT64_C(14695981039346656037),
- };
- struct wlr_scene_node *leaf = &node->node;
- HASH(&capture.hash, leaf);
- HASH(&capture.hash, *bounds);
- capture_buffer_hash(&capture, node, surface, bounds, sample);
- return capture.hash;
-}
-static void damage_checks(void)
+static void registry_checks(void)
{
struct wlr_scene *scene = wlr_scene_create();
assert(scene);
- struct glass_engine engine = {.scene = scene};
- wl_list_init(&engine.effects);
- struct glass_effect first = {.engine = &engine}, second = {.engine = &engine};
- wl_list_init(&first.dependencies);
- wl_list_init(&second.dependencies);
- struct wlr_scene_buffer *node = wlr_scene_buffer_create(&scene->tree, NULL);
- assert(node);
- wlr_scene_buffer_set_source_box(node, &(struct wlr_fbox){20, 10, 600, 400});
- struct wlr_surface surface = {.current = {.buffer_width = 1200, .buffer_height = 800}};
- wl_signal_init(&surface.events.commit);
- wl_signal_init(&surface.events.destroy);
- pixman_region32_init(&surface.buffer_damage);
- struct glass_dependency *a = dependency_get(&first, node, &surface);
- struct glass_dependency *b = dependency_get(&second, node, &surface);
- assert(a && b && a != b && dependency_get(&first, node, &surface) == a);
- struct wlr_box bounds = {100, 50, 300, 200}, sample = {200, 100, 50, 40};
- uint64_t revision = dependency_revision(a, &bounds, &sample, 4, 4);
-
- // A surface covering the whole output must not repaint a distant blur.
- damage_commit(&surface, 40, 20, 10, 10);
- assert(engine.resync);
- assert(dependency_revision(a, &bounds, &sample, 4, 4) == revision);
- // Empty commits/buffer rotation are not new pixels and cannot discard
- // relevant damage from earlier commits while a blur is held.
- engine.resync = false;
- damage_commit(&surface, 230, 120, 4, 4);
- damage_commit(&surface, 40, 20, 4, 4);
- damage_commit(&surface, 0, 0, 0, 0);
- assert(dependency_revision(a, &bounds, &sample, 4, 4) == ++revision);
- assert(dependency_revision(a, &bounds, &sample, 4, 4) == revision);
- // Another effect (or another output's effect) owns its accumulated damage.
- assert(pixman_region32_contains_point(&b->damage, 231, 121, NULL));
- assert(dependency_revision(b, &bounds, &sample, 4, 4) == 2);
- engine.resync = false;
- damage_commit(&surface, 0, 0, 0, 0);
- assert(!engine.resync);
- assert(dependency_revision(a, &bounds, &sample, 4, 4) == revision);
-
- // Fractional source/destination ratios include bilinear and quarter-size
- // capture rounding footprints. Buffer scale and viewporter use this path.
- damage_commit(&surface, 211, 120, 1, 1);
- assert(dependency_revision(a, &bounds, &sample, 4, 4) == ++revision);
- wlr_scene_buffer_set_source_box(node, &(struct wlr_fbox){20.5, 10.5, 601, 401});
- damage_commit(&surface, 230, 120, 1, 1);
- assert(dependency_revision(a, &bounds, &sample, 4, 4) == ++revision);
- wlr_scene_buffer_set_source_box(node, NULL);
- damage_commit(&surface, 500, 250, 1, 1);
- assert(dependency_revision(a, &bounds, &sample, 4, 4) == ++revision);
-
- // Changed-and-restored mappings cannot cancel a required repaint.
- const uint32_t mappings[] = {WLR_SURFACE_STATE_TRANSFORM, WLR_SURFACE_STATE_SCALE,
- WLR_SURFACE_STATE_VIEWPORT, WLR_SURFACE_STATE_OFFSET};
- for (size_t i = 0; i < sizeof(mappings) / sizeof(mappings[0]); i++) {
- surface.current.committed = mappings[i];
- surface.current.dx = mappings[i] == WLR_SURFACE_STATE_OFFSET;
- damage_commit(&surface, 0, 0, 0, 0);
- surface.current.committed = 0;
- surface.current.dx = 0;
- damage_commit(&surface, 0, 0, 0, 0);
- assert(dependency_revision(a, &bounds, &sample, 4, 4) == ++revision);
- }
- // wl_surface before v5 sets OFFSET on every attach(buffer, 0, 0). A zero
- // delta maps nothing differently and must not re-blur on every frame.
- surface.current.committed = WLR_SURFACE_STATE_OFFSET;
- damage_commit(&surface, 0, 0, 0, 0);
- surface.current.committed = 0;
- assert(dependency_revision(a, &bounds, &sample, 4, 4) == revision);
- surface.current.buffer_width = 1300;
- damage_commit(&surface, 0, 0, 0, 0);
- surface.current.buffer_width = 1200;
- damage_commit(&surface, 0, 0, 0, 0);
- assert(dependency_revision(a, &bounds, &sample, 4, 4) == ++revision);
- wlr_scene_buffer_set_transform(node, WL_OUTPUT_TRANSFORM_90);
- damage_commit(&surface, 5, 5, 1, 1);
- assert(dependency_revision(a, &bounds, &sample, 4, 4) == ++revision);
-
- // Exercise the actual capture hashing path, not only its damage helper.
- // Buffer pointer/sequence changes with empty damage leave the hash stable;
- // sampled pixels and all texture-mapping metadata still invalidate it.
- wlr_scene_buffer_set_transform(node, WL_OUTPUT_TRANSFORM_NORMAL);
- wlr_scene_buffer_set_source_box(node, &(struct wlr_fbox){20, 10, 600, 400});
- struct test_buffer *one = buffer_create(2, 2, 0xff000000, 0xff000000);
- struct test_buffer *two = buffer_create(2, 2, 0xff000000, 0xff000000);
- wlr_scene_buffer_set_buffer(node, &one->base);
- uint64_t hash = damage_hash(&first, node, &surface, &bounds, &sample);
- wlr_scene_buffer_set_buffer(node, &two->base);
- damage_commit(&surface, 0, 0, 0, 0);
- assert(damage_hash(&first, node, &surface, &bounds, &sample) == hash);
- damage_commit(&surface, 40, 20, 4, 4);
- assert(damage_hash(&first, node, &surface, &bounds, &sample) == hash);
- damage_commit(&surface, 230, 120, 4, 4);
- uint64_t changed = damage_hash(&first, node, &surface, &bounds, &sample);
- assert(changed != hash);
- hash = changed;
- struct wlr_box moved = bounds;
- moved.x++;
- assert(damage_hash(&first, node, &surface, &moved, &sample) != hash);
- wlr_scene_buffer_set_source_box(node, &(struct wlr_fbox){30, 10, 600, 400});
- assert(damage_hash(&first, node, &surface, &bounds, &sample) != hash);
- wlr_scene_buffer_set_source_box(node, &(struct wlr_fbox){20, 10, 600, 400});
- wlr_scene_buffer_set_opacity(node, .5f);
- assert(damage_hash(&first, node, &surface, &bounds, &sample) != hash);
- wlr_scene_buffer_set_opacity(node, 1);
- enum wlr_scale_filter_mode filter = node->filter_mode;
- wlr_scene_buffer_set_filter_mode(node, filter == WLR_SCALE_FILTER_BILINEAR ?
- WLR_SCALE_FILTER_NEAREST : WLR_SCALE_FILTER_BILINEAR);
- assert(damage_hash(&first, node, &surface, &bounds, &sample) != hash);
- wlr_scene_buffer_set_filter_mode(node, filter);
- // A client buffer whose texture was unavailable must not retain fallback
- // pixels once the drawable texture appears. No GL access is needed here.
- struct wlr_texture texture = {0};
- node->private.texture = &texture;
- assert(damage_hash(&first, node, &surface, &bounds, &sample) != hash);
- node->private.texture = NULL;
- // If dependency allocation fails, each source commit conservatively
- // changes the capture hash instead of silently keeping stale pixels.
- struct glass_effect fallback = {.engine = &engine};
- wl_list_init(&fallback.dependencies);
- fail_next_glass_allocation = true;
- hash = damage_hash(&fallback, node, &surface, &bounds, &sample);
- assert(wl_list_empty(&fallback.dependencies));
- damage_commit(&surface, 0, 0, 0, 0);
+ struct glass_engine *engine = rediwm_glass_create();
+ assert(engine);
+ struct wlr_scene_buffer *target = wlr_scene_buffer_create(&scene->tree, NULL);
+ wlr_scene_buffer_set_dest_size(target, 200, 60);
+ struct glass_effect *effect = rediwm_glass_attach(engine, target, &target->node, GLASS_TITLEBAR);
+ assert(effect && rediwm_glass_is_effect_node(&effect->node->node));
+ assert(!rediwm_glass_is_effect_node(&target->node));
+ // Below its target, so the blur reads what lies under the surface.
+ assert(effect->node->node.link.next == &target->node.link);
+ struct rediwm_glass_info info;
+ assert(!rediwm_glass_effect_info(&target->node, &info));
+ assert(rediwm_glass_effect_info(&effect->node->node, &info));
+ assert(info.target == target && info.sigma == 22 && info.saturation == 1.5f && info.opacity == 1);
+ assert(!info.held && info.serial);
+ rediwm_glass_configure(effect, 10, .5f);
+ assert(rediwm_glass_effect_info(&effect->node->node, &info) && info.radius == 10 && info.opacity == .5f);
+ // A node address may be reused; the serial is not.
+ struct wlr_scene_buffer *panel = wlr_scene_buffer_create(&scene->tree, NULL);
+ struct glass_effect *other = rediwm_glass_attach(engine, panel, &panel->node, GLASS_PANEL);
+ struct rediwm_glass_info other_info;
+ assert(rediwm_glass_effect_info(&other->node->node, &other_info));
+ assert(other_info.serial != info.serial && other_info.sigma == 26 && other_info.saturation == 1.6f);
+ // Holds: one dragged effect, or every effect during camera motion.
+ rediwm_glass_hold(engine, effect);
+ assert(rediwm_glass_effect_info(&effect->node->node, &info) && info.held);
+ assert(rediwm_glass_effect_info(&other->node->node, &other_info) && !other_info.held);
+ rediwm_glass_hold(engine, NULL);
+ rediwm_glass_hold_all(engine, true);
+ assert(rediwm_glass_effect_info(&other->node->node, &other_info) && other_info.held);
+ rediwm_glass_hold_all(engine, false);
+ rediwm_glass_hold(engine, effect);
+ // Removing the target removes its effect, and a held one is released.
+ wlr_scene_node_destroy(&target->node);
+ assert(engine->held == NULL);
+ assert(engine->effects.next == &other->link && other->link.next == &engine->effects);
+ // Allocation failure leaves nothing behind.
fail_next_glass_allocation = true;
- assert(damage_hash(&fallback, node, &surface, &bounds, &sample) != hash);
- assert(wl_list_empty(&fallback.dependencies));
- wlr_buffer_drop(&one->base);
- wlr_buffer_drop(&two->base);
-
- // A source no longer in an effect's capture stops waking that effect.
- dependencies_begin(&second);
- dependencies_prune(&second);
- assert(wl_list_empty(&second.dependencies));
- dependencies_begin(&first);
- assert(dependency_get(&first, node, &surface) == a);
- dependencies_prune(&first);
- assert(!wl_list_empty(&first.dependencies));
-
- // Source destruction must refresh the blur even when opaque foreground
- // windows hide all of the source's ordinary scene damage.
- engine.resync = false;
- wlr_scene_node_destroy(&node->node);
- assert(engine.resync);
- assert(wl_list_empty(&first.dependencies) && wl_list_empty(&second.dependencies));
- assert(wl_list_empty(&surface.events.commit.listener_list));
- node = wlr_scene_buffer_create(&scene->tree, NULL);
- assert(node && dependency_get(&first, node, &surface));
- engine.resync = false;
- wl_signal_emit_mutable(&surface.events.destroy, &surface);
- assert(engine.resync);
- assert(wl_list_empty(&first.dependencies));
+ assert(!rediwm_glass_attach(engine, panel, &panel->node, GLASS_PANEL));
+ rediwm_glass_destroy(engine);
+ assert(wl_list_length(&scene->tree.children) == 1); // the panel; its effect went
wlr_scene_node_destroy(&scene->tree.node);
- pixman_region32_fini(&surface.buffer_damage);
- fputs("PASS: glass source damage accumulation, mapping, independent effects and lifetime\n", stderr);
+ fputs("PASS: glass registry: info, serials, holds, target lifetime, allocation failure\n", stderr);
}
static bool projection_input(struct wlr_scene_buffer *buffer, double *x, double *y) {
(void)buffer;
@@ -268,6 +94,15 @@ static bool projection_input(struct wlr_scene_buffer *buffer, double *x, double
*x += 7; *y += 9;
return true;
}
+struct items { struct rediwm_item effect, target; };
+static bool find_items(const struct rediwm_item *item, struct wlr_scene_node *transport, void *data) {
+ struct items *found = data;
+ struct wlr_scene_node *source = rediwm_projection_source(transport);
+ if (item->kind == REDIWM_ITEM_EFFECT) found->effect = *item;
+ else if (source->type == WLR_SCENE_NODE_BUFFER && !wlr_scene_buffer_from_node(source)->buffer &&
+ item->width == 200) found->target = *item;
+ return true;
+}
static void projection_checks(struct wlr_scene *scene, struct glass_engine *engine) {
struct wlr_scene_tree *source = wlr_scene_tree_create(&scene->tree);
struct wlr_scene_tree *view = wlr_scene_tree_create(&scene->tree);
@@ -275,7 +110,7 @@ static void projection_checks(struct wlr_scene *scene, struct glass_engine *engi
assert(p);
struct wlr_scene_tree *frame = wlr_scene_tree_create(source);
wlr_scene_node_set_position(&frame->node, 101, 51);
- struct test_buffer *image = buffer_create(400, 260, 0xffff0000, 0xff0000ff);
+ struct test_buffer *image = buffer_create(400, 260);
struct wlr_scene_buffer *client = wlr_scene_buffer_create(frame, &image->base);
wlr_buffer_drop(&image->base);
wlr_scene_buffer_set_source_box(client, &(struct wlr_fbox){10, 10, 380, 240});
@@ -307,168 +142,45 @@ static void projection_checks(struct wlr_scene *scene, struct glass_engine *engi
assert(!wlr_scene_node_at(&view->node, displayed_x + 1, displayed_y + 1, &x, &y));
}
}
+ // An effect has its target's box at every zoom, and is shown only with it.
assert(rediwm_projection_set_tree_zoom(&frame->node, .70));
struct wlr_scene_buffer *target = wlr_scene_buffer_create(frame, NULL);
+ wlr_scene_node_set_position(&target->node, 0, 0);
wlr_scene_buffer_set_dest_size(target, 200, 60);
struct glass_effect *effect = rediwm_glass_attach(engine, target, &target->node, GLASS_TITLEBAR);
- rediwm_glass_configure(effect, 10, 1);
- rediwm_projection_sync(p, .55, 0, 0, 0, 0);
- rediwm_glass_project(engine, p, .55);
- engine->bounds = (struct wlr_box){0, 0, 1280, 720};
- update_effect(effect, 1);
- assert(effect->valid && effect->projected_node->dst_width == 77);
- assert(fabs(effect->zoom - .70*.55) < .0001);
- uint64_t revision = effect->revision;
- rediwm_projection_sync(p, .55, 0, 0, 0, 0);
- rediwm_glass_project(engine, p, .55);
- update_effect(effect, 1);
- assert(effect->revision == revision);
- wlr_scene_node_set_enabled(&frame->node, false);
+ assert(effect);
+ for (size_t i = 0; i < sizeof(levels)/sizeof(levels[0]); i++) {
+ rediwm_projection_sync(p, levels[i], 0, 0, 0, 0);
+ struct items found = {0};
+ rediwm_projection_for_each_item(p, false, find_items, &found);
+ assert(found.effect.kind == REDIWM_ITEM_EFFECT && found.target.width == 200);
+ assert(found.effect.edges.x1 == found.target.edges.x1 && found.effect.edges.y2 == found.target.edges.y2);
+ assert(found.effect.width == 200 && found.effect.height == 60);
+ assert(fabs(found.effect.scale - .70 * levels[i]) < .0001);
+ }
+ wlr_scene_node_set_enabled(&target->node, false);
rediwm_projection_sync(p, .55, 0, 0, 0, 0);
- update_effect(effect, 1);
- assert(!effect->projected_node->node.enabled);
- // Source destruction tears down all mirrors, including effect targets.
+ struct items hidden = {0};
+ rediwm_projection_for_each_item(p, false, find_items, &hidden);
+ assert(hidden.effect.kind != REDIWM_ITEM_EFFECT);
+ // Source destruction tears down all mirrors, including effects.
wlr_scene_node_destroy(&frame->node);
assert(wl_list_empty(&view->children));
rediwm_projection_destroy(p);
wlr_scene_node_destroy(&source->node);
wlr_scene_node_destroy(&view->node);
- fputs("projection geometry, input, glass and destruction checks passed\n", stderr);
+ fputs("PASS: projection geometry, input, glass geometry and destruction\n", stderr);
}
-
-int main(int argc, char **argv)
+int main(void)
{
wlr_log_init(WLR_ERROR, NULL);
- damage_checks();
- if (argc == 2 && strcmp(argv[1], "--damage-only") == 0)
- return 0;
- struct wl_display *display = wl_display_create();
- assert(display);
- struct wlr_backend *backend =
- wlr_headless_backend_create(wl_display_get_event_loop(display));
- assert(backend);
- struct wlr_renderer *renderer = wlr_renderer_autocreate(backend);
- assert(renderer);
- struct wlr_allocator *allocator = wlr_allocator_autocreate(backend, renderer);
- assert(allocator);
+ registry_checks();
struct wlr_scene *scene = wlr_scene_create();
assert(scene);
- struct glass_engine *engine = rediwm_glass_create(renderer, allocator, scene, NULL);
- assert(engine && !engine->failed);
- float color[] = {.2, .4, .6, 1};
- struct wlr_scene_rect *background = wlr_scene_rect_create(&scene->tree, 2000, 2000, color);
- wlr_scene_node_set_position(&background->node, -500, -500);
- struct wlr_scene_buffer *target = wlr_scene_buffer_create(&scene->tree, NULL);
- wlr_scene_buffer_set_dest_size(target, 200, 200);
- struct glass_effect *effect =
- rediwm_glass_attach(engine, target, &target->node, GLASS_TITLEBAR);
- rediwm_glass_configure(effect, 10, 1);
- // A foreground window must never feed back into this window's filter.
- float green[] = {0, 1, 0, 1};
- struct wlr_scene_rect *foreground = wlr_scene_rect_create(&scene->tree, 200, 200, green);
- update_effect(effect, 1);
- assert(effect->valid && !engine->failed);
- uint32_t center = pixel(effect, 100, 100);
- // CSS saturate(150%) of RGB(51,102,153).
- near_channel(center, 24, 255, 0);
- near_channel(center, 16, 29, 2);
- near_channel(center, 8, 106, 2);
- near_channel(center, 0, 182, 2);
- assert(pixel(effect, 0, 0) == 0);
- assert(pixel(effect, 0, 199) >> 24 == 255); // only the top corners are round
- uint64_t revision = effect->revision;
- update_effect(effect, 1);
- assert(effect->revision == revision);
- wlr_scene_rect_set_color(foreground, color);
- update_effect(effect, 1);
- assert(effect->revision == revision);
-
- // Vertical asymmetry detects an upside-down FBO or source transform.
- float red[] = {1, 0, 0, 1}, blue[] = {0, 0, 1, 1};
- wlr_scene_rect_set_color(background, blue);
- struct wlr_scene_rect *upper = wlr_scene_rect_create(&scene->tree, 2000, 600, red);
- wlr_scene_node_set_position(&upper->node, -500, -500);
- wlr_scene_node_place_below(&upper->node, &effect->node->node);
- update_effect(effect, 1);
- assert(effect->revision > revision);
- near_channel(pixel(effect, 100, 20), 16, 255, 2);
- near_channel(pixel(effect, 100, 180), 0, 255, 2);
- uint32_t boundary = pixel(effect, 100, 100);
- assert(((boundary >> 16) & 255) > 90 && (boundary & 255) > 90);
- // Fractional scale keeps the same logical blur radius and clipped arcs.
- update_effect(effect, 1.5);
- near_channel(pixel(effect, 150, 30), 16, 255, 2);
- near_channel(pixel(effect, 150, 270), 0, 255, 2);
- assert(pixel(effect, 0, 0) == 0);
-
- // A real texture, cropped and scaled like a viewporter/buffer-scale
- // client, must agree with the same scene geometry made from rectangles.
- wlr_scene_node_set_enabled(&upper->node, false);
- struct test_buffer *image = buffer_create(160, 160, 0xffff0000, 0xff0000ff);
- struct wlr_scene_buffer *client = wlr_scene_buffer_create(&scene->tree, &image->base);
- wlr_buffer_drop(&image->base);
- wlr_scene_buffer_set_source_box(client, &(struct wlr_fbox){40, 40, 80, 80});
- wlr_scene_buffer_set_dest_size(client, 200, 200);
- wlr_scene_node_place_below(&client->node, &effect->node->node);
- update_effect(effect, 1);
- near_channel(pixel(effect, 100, 40), 16, 255, 5);
- near_channel(pixel(effect, 100, 160), 0, 255, 5);
- wlr_scene_buffer_set_transform(client, WL_OUTPUT_TRANSFORM_180);
- update_effect(effect, 1);
- near_channel(pixel(effect, 100, 40), 0, 255, 5);
- near_channel(pixel(effect, 100, 160), 16, 255, 5);
-
- // Screen-edge clamping: glass at the bottom must not blur in black
- // from beyond the wallpaper/output. All samples remain the same blue.
- wlr_scene_node_set_enabled(&client->node, false);
- wlr_scene_node_set_position(&background->node, 0, 0);
- wlr_scene_rect_set_size(background, 200, 200);
- engine->bounds = (struct wlr_box){0, 0, 200, 200};
- update_effect(effect, 1);
- near_channel(pixel(effect, 100, 199), 0, 255, 2);
- near_channel(pixel(effect, 199, 100), 0, 255, 2);
-
- // Fade the panel and its backing as one group: if the front has alpha
- // .37 at t=.5, the backing must be (.5-.37)/(1-.37), not another .5.
- struct test_buffer *panel = buffer_create(200, 200, 0x5e05060b, 0x5e05060b);
- wlr_scene_buffer_set_buffer(target, &panel->base);
- wlr_buffer_drop(&panel->base);
- effect->kind = GLASS_PANEL;
- rediwm_glass_configure(effect, 10, .5);
- update_effect(effect, 1);
- uint32_t faded = pixel(effect, 100, 100);
- near_channel(faded, 24, 53, 2);
- near_channel(faded, 0, 53, 2);
- assert(pixel(effect, 199, 199) == 0);
-
- // Scene-buffer opacity with full-opacity pixels (the panel-reuse path)
- // must match the CPU-faded buffer above: front = 0.737 * 0.5 = 0.37.
- wlr_scene_buffer_set_opacity(target, .5);
- struct test_buffer *full = buffer_create(200, 200, 0xbc0a0c16, 0xbc0a0c16);
- wlr_scene_buffer_set_buffer(target, &full->base);
- wlr_buffer_drop(&full->base);
- rediwm_glass_configure(effect, 10, .5);
- update_effect(effect, 1);
- uint32_t scene_faded = pixel(effect, 100, 100);
- near_channel(scene_faded, 24, 53, 2);
- near_channel(scene_faded, 0, 53, 2);
-
- // Power menu: glass stays at opacity 1 while the panel fades.
- rediwm_glass_configure(effect, 10, 1);
- update_effect(effect, 1);
- near_channel(pixel(effect, 100, 100), 24, 255, 2);
- wlr_scene_buffer_set_opacity(target, 1);
-
- // Removing the target owns and removes its effect, including GPU buffers.
- wlr_scene_node_destroy(&target->node);
- assert(wl_list_empty(&engine->effects));
- projection_checks(scene, engine);
+ struct glass_engine *engine = rediwm_glass_create();
+ assert(engine);
+ projection_checks(scene, engine);
rediwm_glass_destroy(engine);
wlr_scene_node_destroy(&scene->tree.node);
- wlr_allocator_destroy(allocator);
- wlr_renderer_destroy(renderer);
- wlr_backend_destroy(backend);
- wl_display_destroy(display);
- fputs("glass GPU checks passed\n", stderr);
return 0;
}
diff --git a/src/ipc/stats.zig b/src/ipc/stats.zig
index ec969b2..16e7380 100644
--- a/src/ipc/stats.zig
+++ b/src/ipc/stats.zig
@@ -26,6 +26,8 @@ pub const PerformanceStats = struct {
panels_cpu: metrics.Window = .{},
anim_cpu: metrics.Window = .{},
projection_cpu: metrics.Window = .{},
+ // Not recorded since the output pass draws glass (stage 5d); kept so the
+ // frame_work wire format and its readers stay unchanged.
glass_cpu: metrics.Window = .{},
scene_commit_cpu: metrics.Window = .{},
gpu_elapsed: metrics.Window = .{},
diff --git a/src/ipc_serializers.jsonl b/src/ipc_serializers.jsonl
index be84c16..5c443f4 100644
--- a/src/ipc_serializers.jsonl
+++ b/src/ipc_serializers.jsonl
@@ -63,7 +63,7 @@
{"Ok":{"SamplePixels":{"output":"text \"quoted\"\n\\","x":0,"y":0,"width":0,"height":0,"gpu_readback":false,"pixels":[0]}}}
{"Ok":{"SamplePixels":{"output":"text \"quoted\"\n\\","x":7,"y":7,"width":7,"height":7,"gpu_readback":true,"pixels":[7]}}}
{"Ok":{"PerformanceStats":{"output_commits":0,"output_failed_commits":0,"fps":0.0,"frame_time_ms":0.0,"missed_frames":0,"refresh_hz":0.0,"titlebar_paints":0,"footer_paints":0,"edge_samples_attempted":0,"edge_samples_succeeded":0,"edge_samples_skipped":0,"edge_sample_ns":0,"panel_paints":0,"panel_allocated_bytes":0,"panel_reused_bytes":0,"icon_cache_hits":0,"icon_cache_misses":0,"icon_decode_ns":0,"icon_decode_count":0,"icon_decoded_bytes":0,"icon_queue_depth_max":0,"taskbar_paints":0,"taskbar_paint_ns":0,"taskbar_raster_pixels":0,"taskbar_clock_frame_requests":0,"taskbar_clock_paints":0,"taskbar_start_paints":0,"taskbar_chip_paints":0,"taskbar_tray_paints":0,"taskbar_hover_paints":0,"taskbar_press_paints":0,"taskbar_audio_paints":0,"recent_errors_count":0,"anim_frames_scheduled":0,"anim_wasted_wakeups":0,"anim_longest_ms":0,"anim_speed":0,"anim_enabled":false,"anim_reduced_motion":false}}}
-{"Ok":{"PerformanceStats":{"screenshot_selection":{"motion_events":7,"updates":7,"update_ns":7,"toolbar_paints":7,"label_paints":7,"scene_nodes_created":7},"frame_work":{"cpu_frame":{"samples":7,"total_samples":7,"avg_ms":1.23456,"p50_ms":1.23456,"p95_ms":1.23456,"p99_ms":1.23456,"max_ms":1.23456},"taskbar_cpu":{"samples":7,"total_samples":7,"avg_ms":1.23456,"p50_ms":1.23456,"p95_ms":1.23456,"p99_ms":1.23456,"max_ms":1.23456},"chrome_cpu":{"samples":7,"total_samples":7,"avg_ms":1.23456,"p50_ms":1.23456,"p95_ms":1.23456,"p99_ms":1.23456,"max_ms":1.23456},"panels_cpu":{"samples":7,"total_samples":7,"avg_ms":1.23456,"p50_ms":1.23456,"p95_ms":1.23456,"p99_ms":1.23456,"max_ms":1.23456},"anim_cpu":{"samples":7,"total_samples":7,"avg_ms":1.23456,"p50_ms":1.23456,"p95_ms":1.23456,"p99_ms":1.23456,"max_ms":1.23456},"projection_cpu":{"samples":7,"total_samples":7,"avg_ms":1.23456,"p50_ms":1.23456,"p95_ms":1.23456,"p99_ms":1.23456,"max_ms":1.23456},"glass_cpu":{"samples":7,"total_samples":7,"avg_ms":1.23456,"p50_ms":1.23456,"p95_ms":1.23456,"p99_ms":1.23456,"max_ms":1.23456},"scene_commit_cpu":{"samples":7,"total_samples":7,"avg_ms":1.23456,"p50_ms":1.23456,"p95_ms":1.23456,"p99_ms":1.23456,"max_ms":1.23456},"gpu_elapsed":{"samples":7,"total_samples":7,"avg_ms":1.23456,"p50_ms":1.23456,"p95_ms":1.23456,"p99_ms":1.23456,"max_ms":1.23456},"gpu_timing_available":true,"gpu_samples_dropped":7},"output_commits":7,"output_failed_commits":7,"fps":1.2,"frame_time_ms":1.2,"missed_frames":7,"refresh_hz":1.2,"titlebar_paints":7,"footer_paints":7,"edge_samples_attempted":7,"edge_samples_succeeded":7,"edge_samples_skipped":7,"edge_sample_ns":7,"panel_paints":7,"panel_allocated_bytes":7,"panel_reused_bytes":7,"icon_cache_hits":7,"icon_cache_misses":7,"icon_decode_ns":7,"icon_decode_count":7,"icon_decoded_bytes":7,"icon_queue_depth_max":7,"taskbar_paints":7,"taskbar_paint_ns":7,"taskbar_raster_pixels":7,"taskbar_clock_frame_requests":7,"taskbar_clock_paints":7,"taskbar_start_paints":7,"taskbar_chip_paints":7,"taskbar_tray_paints":7,"taskbar_hover_paints":7,"taskbar_press_paints":7,"taskbar_audio_paints":7,"recent_errors_count":7,"anim_frames_scheduled":7,"anim_wasted_wakeups":7,"anim_longest_ms":7,"anim_speed":1.23456,"anim_enabled":true,"anim_reduced_motion":true,"startup":{"build_mode":"text \"quoted\"\n\\","renderer":"text \"quoted\"\n\\","scale":1.23,"output_count":7,"catalog_entries":7,"autostart_count":7,"catalog_state":"text \"quoted\"\n\\","wallpaper_state":"text \"quoted\"\n\\","catalog_provisional":true,"catalog_loading":true,"catalog_generation":7,"renderer_ready_ns":7,"config_ready_ns":7,"catalog_cache_read_ns":7,"catalog_scan_ns":7,"wallpaper_decode_ns":7,"socket_ready_ns":7,"ipc_ready_ns":7,"session_ready_ns":7,"session_clients_started_ns":7,"xwayland_ready_ns":7,"first_presented_ns":7,"first_ipc_ns":7,"first_input_ns":7,"catalog_published_ns":7,"wallpaper_presented_ns":7,"catalog_cache_read_duration_ns":7,"catalog_scan_duration_ns":7,"wallpaper_decode_duration_ns":7},"desktop":{"paints":7,"damage_pixels":7,"tile_presents":7,"texture_uploads":7},"output_skipped_commits":7}}}
+{"Ok":{"PerformanceStats":{"screenshot_selection":{"motion_events":7,"updates":7,"update_ns":7,"toolbar_paints":7,"label_paints":7,"scene_nodes_created":7},"frame_work":{"cpu_frame":{"samples":7,"total_samples":7,"avg_ms":1.23456,"p50_ms":1.23456,"p95_ms":1.23456,"p99_ms":1.23456,"max_ms":1.23456},"taskbar_cpu":{"samples":7,"total_samples":7,"avg_ms":1.23456,"p50_ms":1.23456,"p95_ms":1.23456,"p99_ms":1.23456,"max_ms":1.23456},"chrome_cpu":{"samples":7,"total_samples":7,"avg_ms":1.23456,"p50_ms":1.23456,"p95_ms":1.23456,"p99_ms":1.23456,"max_ms":1.23456},"panels_cpu":{"samples":7,"total_samples":7,"avg_ms":1.23456,"p50_ms":1.23456,"p95_ms":1.23456,"p99_ms":1.23456,"max_ms":1.23456},"anim_cpu":{"samples":7,"total_samples":7,"avg_ms":1.23456,"p50_ms":1.23456,"p95_ms":1.23456,"p99_ms":1.23456,"max_ms":1.23456},"projection_cpu":{"samples":7,"total_samples":7,"avg_ms":1.23456,"p50_ms":1.23456,"p95_ms":1.23456,"p99_ms":1.23456,"max_ms":1.23456},"glass_cpu":{"samples":7,"total_samples":7,"avg_ms":1.23456,"p50_ms":1.23456,"p95_ms":1.23456,"p99_ms":1.23456,"max_ms":1.23456},"scene_commit_cpu":{"samples":7,"total_samples":7,"avg_ms":1.23456,"p50_ms":1.23456,"p95_ms":1.23456,"p99_ms":1.23456,"max_ms":1.23456},"gpu_elapsed":{"samples":7,"total_samples":7,"avg_ms":1.23456,"p50_ms":1.23456,"p95_ms":1.23456,"p99_ms":1.23456,"max_ms":1.23456},"gpu_timing_available":true,"gpu_samples_dropped":7},"output_commits":7,"output_failed_commits":7,"fps":1.2,"frame_time_ms":1.2,"missed_frames":7,"refresh_hz":1.2,"titlebar_paints":7,"footer_paints":7,"edge_samples_attempted":7,"edge_samples_succeeded":7,"edge_samples_skipped":7,"edge_sample_ns":7,"panel_paints":7,"panel_allocated_bytes":7,"panel_reused_bytes":7,"icon_cache_hits":7,"icon_cache_misses":7,"icon_decode_ns":7,"icon_decode_count":7,"icon_decoded_bytes":7,"icon_queue_depth_max":7,"taskbar_paints":7,"taskbar_paint_ns":7,"taskbar_raster_pixels":7,"taskbar_clock_frame_requests":7,"taskbar_clock_paints":7,"taskbar_start_paints":7,"taskbar_chip_paints":7,"taskbar_tray_paints":7,"taskbar_hover_paints":7,"taskbar_press_paints":7,"taskbar_audio_paints":7,"recent_errors_count":7,"anim_frames_scheduled":7,"anim_wasted_wakeups":7,"anim_longest_ms":7,"anim_speed":1.23456,"anim_enabled":true,"anim_reduced_motion":true,"startup":{"build_mode":"text \"quoted\"\n\\","renderer":"text \"quoted\"\n\\","scale":1.23,"output_count":7,"catalog_entries":7,"autostart_count":7,"catalog_state":"text \"quoted\"\n\\","wallpaper_state":"text \"quoted\"\n\\","catalog_provisional":true,"catalog_loading":true,"catalog_generation":7,"renderer_ready_ns":7,"config_ready_ns":7,"catalog_cache_read_ns":7,"catalog_scan_ns":7,"wallpaper_decode_ns":7,"socket_ready_ns":7,"ipc_ready_ns":7,"session_ready_ns":7,"session_clients_started_ns":7,"xwayland_ready_ns":7,"first_presented_ns":7,"first_ipc_ns":7,"first_input_ns":7,"catalog_published_ns":7,"wallpaper_presented_ns":7,"catalog_cache_read_duration_ns":7,"catalog_scan_duration_ns":7,"wallpaper_decode_duration_ns":7},"desktop":{"paints":7,"damage_pixels":7,"tile_presents":7,"texture_uploads":7},"output_skipped_commits":7,"glass_reblurs":7}}}
{"Ok":{"IdleState":{"enabled":false,"state":"text \"quoted\"\n\\","blank_after_seconds":0,"suspend_after_seconds":0,"idle_ms":0,"is_inhibited":false,"inhibitor_count":0,"suspend_request_count":0,"inhibitors":[{"surface_ptr":0,"window_id":null,"app_id":null,"title":null,"is_active":false,"reason":null}]}}}
{"Ok":{"IdleState":{"enabled":true,"state":"text \"quoted\"\n\\","blank_after_seconds":7,"suspend_after_seconds":7,"idle_ms":7,"is_inhibited":true,"inhibitor_count":7,"suspend_request_count":7,"inhibitors":[{"surface_ptr":7,"window_id":7,"app_id":"text \"quoted\"\n\\","title":"text \"quoted\"\n\\","is_active":true,"reason":"text \"quoted\"\n\\"}]}}}
{"Ok":{"CaptureState":{"supported":false,"active_sessions":0,"sessions":[{"output":null,"window_id":null}],"last_failure":null,"indicator":null}}}
diff --git a/src/projection.c b/src/projection.c
index 81c01ba..a2859f6 100644
--- a/src/projection.c
+++ b/src/projection.c
@@ -103,10 +103,6 @@ struct leaf {
// points at `clip` when the leaf is under a clipped tree.
struct rediwm_item item;
struct rediwm_clip clip;
- // Glass's raster is published after resolve; its target still supplies the
- // geometry. Kept separately so an unchanged/held blur survives the next sync.
- struct rediwm_item effect_item;
- struct rediwm_clip effect_clip;
// `item.shadow` points at `shadow` when the leaf is under a shadow tree. A
// shadow's view has no buffer, so wlroots damages nothing for it: present()
// damages the footprint it last drew (`shadow_drawn`) and the new one.
@@ -1125,17 +1121,6 @@ static struct rediwm_item layout_item(struct wlr_scene_node *node, int x, int y)
item.edges = rediwm_xform_rect((struct rediwm_xform){1, 0, 0}, x, y, item.width, item.height);
return item;
}
-void rediwm_projection_effect_updated(struct wlr_scene_buffer *effect, struct wlr_scene_buffer *target) {
- struct leaf *l = lookup(&effect->node), *t = lookup(&target->node);
- if (!l || !t) return;
- const struct rediwm_snap snap = rediwm_edges_snap(t->item.edges);
- l->effect_item = layout_item(&effect->node, snap.x, snap.y);
- // The blur takes the shape of the titlebar it sits under.
- if (t->item.clip) {
- l->effect_clip = *t->item.clip;
- l->effect_item.clip = &l->effect_clip;
- }
-}
static bool visit_items(struct rediwm_projection *p, struct wlr_scene_node *node,
int x, int y, bool reverse, rediwm_item_iterator iterator, void *data) {
if (!node->enabled) return true;
diff --git a/src/projection.h b/src/projection.h
index a6995cf..6f19a8d 100644
--- a/src/projection.h
+++ b/src/projection.h
@@ -17,8 +17,6 @@ struct rediwm_clip_spec;
typedef bool (*rediwm_item_iterator)(const struct rediwm_item *,
struct wlr_scene_node *transport, void *);
bool rediwm_projection_for_each_item(struct rediwm_projection *, bool reverse, rediwm_item_iterator, void *);
-// Glass publishes its current raster against the resolved target geometry.
-void rediwm_projection_effect_updated(struct wlr_scene_buffer *, struct wlr_scene_buffer *);
// Whether a commit changed how buffer pixels map onto the surface, so damage
// from before it cannot be combined with damage after it.
bool rediwm_surface_state_remapped(const struct wlr_surface_state *);
diff --git a/src/projection_test.c b/src/projection_test.c
index f5b450d..1682cbc 100644
--- a/src/projection_test.c
+++ b/src/projection_test.c
@@ -11,6 +11,12 @@ static struct wlr_scene_node *effect_node;
bool rediwm_glass_is_effect_node(struct wlr_scene_node *node) {
return node == effect_node;
}
+// glass.c is not linked here: the stub effect keeps its own box.
+bool rediwm_glass_effect_info(struct wlr_scene_node *node, struct rediwm_glass_info *out) {
+ (void)node;
+ (void)out;
+ return false;
+}
static void buffer_destroy(struct wlr_buffer *buffer) { free(buffer); }
static const struct wlr_buffer_impl buffer_impl = {.destroy = buffer_destroy};
static struct wlr_buffer *buffer_create(void) {
@@ -457,16 +463,6 @@ static void test_clip_projection(struct wlr_scene *scene) {
near(client_leaf->item.clip->radii[0], 10 * .85 * .5));
resolve(p, 1, 0, 0, 0, 0, NULL);
- // The graph consumer sees the pointer too, and a glass effect takes the shape
- // of the titlebar it sits under, in storage of its own.
- // Glass works on the projected nodes, as the compositor calls it.
- rediwm_projection_effect_updated(wlr_scene_buffer_from_node(glass_leaf->view),
- wlr_scene_buffer_from_node(title_leaf->view));
- assert(glass_leaf->effect_item.clip == &glass_leaf->effect_clip);
- assert(glass_leaf->effect_item.clip != title_leaf->item.clip);
- assert(near(glass_leaf->effect_item.clip->edges.x1, want.edges.x1) &&
- near(glass_leaf->effect_item.clip->radii[1], 10 * .85));
-
// A popup lives under its parent's tree but is no part of the window's shape;
// its siblings, such as subsurfaces, still are. The barrier can be lifted.
struct wlr_scene_tree *subsurface = wlr_scene_tree_create(nested);
diff --git a/src/scene_output.c b/src/scene_output.c
index bf6fda4..15c8f3c 100644
--- a/src/scene_output.c
+++ b/src/scene_output.c
@@ -32,6 +32,8 @@ struct effect_cache {
struct wlr_box region; // device pixels the blur covers
float sigma; // device pixels
bool valid, seen;
+ // A hold moved the blur without re-taking it: re-take it once released.
+ bool carried;
};
struct output_state {
struct wl_list link;
@@ -459,11 +461,15 @@ static bool decide_effects(struct rediwm_output_renderer *r, struct output_state
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;
+ bool reblur = !same_size || !complete || (c->carried && !e->glass.held);
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 (e->glass.held) {
+ c->region = region;
+ c->carried = true;
+ } else {
+ reblur = true;
+ }
}
if (!reblur && !e->glass.held) {
const long here = (long)(i - 1);
@@ -507,6 +513,7 @@ static void render_effect(struct entry *e, struct wlr_render_pass *pass, const s
c->sigma = e->sigma * v->scale;
rediwm_scene_pass_capture_backdrop(pass, &c->backdrop, c->region, c->sigma);
c->valid = true;
+ c->carried = false;
rediwm_scene_output_reblurs++;
}
if (!c->valid || !c->backdrop || !pixman_region32_not_empty((pixman_region32_t *)clip)) return;