RediWM is a Wayland compositor written in Zig (OpenGL ES) that includes everything in one process
scene graph plan, stage 4c: analytic window frames on the owned path
oxydizerac4ce3cbd2d5
diff --git a/AGENTS.md b/AGENTS.mdindex 834784a..efce0e6 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -22,13 +22,24 @@ the one for the directory you work in: `src/files`, `src/editor`,`col.Straight`. Create/recolour rects only via `col.createRect`/`setRect`,pack pixels with `Straight.argb()`/`Premul.argb()`. Symptom of a mix-up:white border edges.-* **Borders have two paths; change both:** `chrome.ChromeBuffer` draws curved- corners, `Toplevel.syncBorders` straight `SceneRect`s inset by- `ceil(frame_radius)`, with `side_fills` behind them. Chrome is a title band- plus a footer skirt under the client (wlroots 0.20 can't mask clients):- check `frame.band`, not `py`; `footerHeight()` keeps the skirt ≥- `ceil(frame_radius)`.-* **Skirt colour** comes from `probeClientEdge` (median of the last buffer+* **Borders have three paths until stage 4e; change all that apply.** Legacy:+ `chrome.ChromeBuffer` draws curved corners, `Toplevel.syncBorders` straight+ `SceneRect`s inset by `ceil(frame_radius)`, `side_fills` behind them, and a+ footer skirt under the client (wlroots 0.20 can't mask clients): check+ `frame.band`, not `py`; `footerHeight()` keeps the skirt ≥ `ceil(frame_radius)`.+ Owned (`chrome.analytic_frames`, set in `Server.init` once `enable_shapes`+ worked): `Toplevel.applyShape` gives `frame_tree` one rounded clip carrying the+ ring colour (× window opacity), the shader composites the ring over the body,+ the chrome buffers are plain bands (`ChromeState.radius` 0), the footer is+ `frame_border`, border rects are off, and `shadow_tree`, the resize-grab tree+ and every xdg popup carry `setTreeUnclipped` (a new node that hangs outside the+ window needs it too). CSD windows have no shape and keep their rect outline.+ A changed clip damages its rim itself (`projection.c`); a point the shape cuts+ away is declined in `accepts()`, so the pick falls to what is below. Window+ capture draws the client alone and is handed the shape explicitly.+ The ring is one `max(1, round(border * scale))`, not the legacy snapped rect+ width, so the two differ by a pixel on a fractional-scale edge.+* **Skirt colour** (legacy frames only) comes from `probeClientEdge` (median of the last bufferrow; shm is premultiplied). Resample only on damage to that row or amapping change; pointer reuse proves nothing. `readFormat` stays memoizedper texture (it binds GL).@@ -67,8 +78,10 @@ the one for the directory you work in: `src/files`, `src/editor`,the caller. The programs cost the driver about 430 KiB (a GL program costs130-150 KiB whatever its size), so `enable_shapes` builds them on request, neverwith the renderer; before it a shaped draw fails the pass. Blend NONE is only- valid inside `rediwm_clip_opaque`. The distance ramp is not area coverage (up- to 18 of 208 levels at one pixel of a curved edge): that is expected.+ valid inside `rediwm_clip_opaque`, minus the ring (`scene_output.c` draws a+ clipped item's ring-free core plain and the rest through the shape). The+ distance ramp is not area coverage (up to 18 of 208 levels at one pixel of a+ curved edge): that is expected.* **Idle makes no wakeups:** timers only for real deadlines, workers signal aneventfd, `text.applySize` instead of re-sizing faces, title changes repaintonly their span and taskbar chip. Measure with per-thread context switches.diff --git a/TESTING.md b/TESTING.mdindex 0a43393..c2f6ebb 100644--- a/TESTING.md+++ b/TESTING.md@@ -51,7 +51,10 @@ compiler, `wayland-scanner` and wayland-protocols; D-Bus suites need PyGObject,stage 3's owned output/capture path. Python fixtures write the temporary`[compositor] scene_renderer` config key; production reads no test variable.Use `legacy` for the comparison. Details and gate results:- `docs/plans/scene-graph-stage3.md`.+ `docs/plans/scene-graph-stage3.md`. With `owned` the compositor also draws+ rounded window frames (stage 4c, `docs/plans/scene-graph-stage4.md`): the frame+ is 9 px shorter at the default radius, so a pinned frame height differs by+ presenter. Run a test under both before calling a failure a regression.- `python3 tests/scene_baseline.py --modes paired --configs scale1,scale1.5,mixed --out /tmp/scene-cost.json`:run owned/legacy/legacy/owned in the same binary, with small repaints clear ofand under glass. Records instructions per committed frame, frame timers, RSS@@ -107,7 +110,11 @@ origin), `zoom_osd.py` (shared zoom OSD,100% camera cap, pixels, timeout and input), `decorations.py`, `kde_decorations.py`, `window_corners.py`(border antialiasing and filled side edges on dark/light backgrounds atinteger/fractional scales, plus workspace focus outlines on server/client-decorations, mode transitions, fullscreen and default/explicit gaps), `switcher.py`,+decorations, mode transitions, fullscreen and default/explicit gaps; under+`REDIWM_TEST_SCENE_RENDERER=owned` it also runs `frame_parity` (titlebar, sides,+client and shadow bit-identical to the legacy frame at scales 1 to 2, the+rightmost column excepted on fractional scales) and checks transparent client+corners and that a click on a clipped corner reaches the window below), `switcher.py`,`switcher_live.py`, `workspaces.py` (floating rules, Settings/IPC layout controls,versioned restart/named-save restoration, duplicate app occurrences, restored tab groups,saved canvas state and multi-window layout undo, both sides of tiled/floating@@ -189,7 +196,8 @@ saved positions, windows carried along, main display, hidden with one output),**Capture**: `capture.py` (ext-image-copy-capture for outputs and windows overshm and, with a render node, dmabuf; occlusion, camera, resize, destroy,-minimize, idle blank, unplug, `get_capture_state`), `screencast.py` (portal+minimize, idle blank, unplug, `get_capture_state`; under `owned` a captured+server-decorated window has transparent bottom corners), `screencast.py` (portalconfig packaging, `rediwm-share-picker --xdpw-dmenu` contract, Stop sharingindicator), `screenshot_tool.py`, `screenshot_regressions.py` (save hookinjects write failures).diff --git a/build.zig b/build.zigindex 32ce393..0a3532a 100644--- a/build.zig+++ b/build.zig@@ -670,6 +670,7 @@ pub fn build(b: *std.Build) void {.root_module = b.createModule(.{ .target = target, .optimize = .Debug, .link_libc = true }),});projection_tests.root_module.addCSourceFile(.{ .file = b.path("src/projection_test.c"), .flags = &.{ "-std=c11", "-Wall", "-Wextra", "-Werror" } });+ projection_tests.root_module.addCSourceFile(.{ .file = b.path("src/scene_damage.c"), .flags = &.{ "-std=c11", "-Wall", "-Wextra", "-Werror" } });inline for (.{ "wlroots-0.20", "wayland-server", "pixman-1" }) |lib| {projection_tests.root_module.linkSystemLibrary(lib, .{});}@@ -686,6 +687,7 @@ pub fn build(b: *std.Build) void {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");@@ -775,6 +777,7 @@ fn addGlass(b: *std.Build, module: *std.Build.Module) void {module.addCSourceFile(.{ .file = b.path("src/projection.c"), .flags = &.{ "-std=c11", "-Wall", "-Wextra" } });module.addCSourceFile(.{ .file = b.path("src/scene_pass.c"), .flags = &.{ "-std=c11", "-Wall", "-Wextra", "-Werror" } });module.addCSourceFile(.{ .file = b.path("src/scene_output.c"), .flags = &.{ "-std=c11", "-Wall", "-Wextra", "-Werror" } });+ module.addCSourceFile(.{ .file = b.path("src/scene_damage.c"), .flags = &.{ "-std=c11", "-Wall", "-Wextra", "-Werror" } });module.addCSourceFile(.{ .file = b.path("src/glass.c"), .flags = &.{ "-std=c11", "-Wall", "-Wextra" } });module.addCSourceFile(.{ .file = b.path("src/explicit_sync.c"), .flags = &.{ "-std=c11", "-Wall", "-Wextra", "-Werror" } });module.addCSourceFile(.{ .file = b.path("src/extra_protocols.c"), .flags = &.{ "-std=c11", "-Wall", "-Wextra", "-Werror" } });diff --git a/docs/plans/scene-graph-stage4-results.json b/docs/plans/scene-graph-stage4-results.jsonnew file mode 100644index 0000000..1f6a7da--- /dev/null+++ b/docs/plans/scene-graph-stage4-results.json@@ -0,0 +1,655 @@+{+ "note": "Stage 4c cost reference, 2026-10-10, i9-12900H, Intel render node, AC, performance profile, ReleaseSafe, headless GLES2 owned presenter.",+ "ab_4b_before_4c": {+ "what": "tests/scene_ab.py on the 4b commit (legacy vs owned presenter, frame blocks); mixed/glass reads 5.1% against the 5% limit, the cell that read 4.4% in stage 3",+ "result": {+ "scale1/clear": {+ "cells": {+ "build_cpu": {+ "n": 3000,+ "legacy": {+ "mean": 209269,+ "median": 205912,+ "p10": 155159,+ "p90": 262000+ },+ "owned": {+ "mean": 206498,+ "median": 204437,+ "p10": 154025,+ "p90": 257986+ }+ },+ "build_wall": {+ "n": 3000,+ "legacy": {+ "mean": 215768,+ "median": 211907,+ "p10": 158021,+ "p90": 270573+ },+ "owned": {+ "mean": 213073,+ "median": 209359,+ "p10": 157370,+ "p90": 266536+ }+ },+ "commit_wall": {+ "n": 3000,+ "legacy": {+ "mean": 227770,+ "median": 224552,+ "p10": 166860,+ "p90": 285451+ },+ "owned": {+ "mean": 224902,+ "median": 221633,+ "p10": 165344,+ "p90": 281540+ }+ },+ "gpu": {+ "n": 3000,+ "legacy": {+ "mean": 261441,+ "median": 264844,+ "p10": 154688,+ "p90": 358958+ },+ "owned": {+ "mean": 254685,+ "median": 258073,+ "p10": 149740,+ "p90": 346875+ }+ }+ },+ "power_before": {+ "ac_online": true,+ "battery": "Charging",+ "platform_profile": "performance",+ "governor": "schedutil",+ "epp": "performance",+ "no_turbo": "0"+ },+ "power_after": {+ "ac_online": true,+ "battery": "Charging",+ "platform_profile": "performance",+ "governor": "schedutil",+ "epp": "performance",+ "no_turbo": "0"+ }+ },+ "scale1/glass": {+ "cells": {+ "build_cpu": {+ "n": 3000,+ "legacy": {+ "mean": 230454,+ "median": 240136,+ "p10": 168624,+ "p90": 276840+ },+ "owned": {+ "mean": 236672,+ "median": 246681,+ "p10": 173355,+ "p90": 284656+ }+ },+ "build_wall": {+ "n": 3000,+ "legacy": {+ "mean": 236394,+ "median": 243204,+ "p10": 170697,+ "p90": 288442+ },+ "owned": {+ "mean": 243022,+ "median": 249857,+ "p10": 175778,+ "p90": 296348+ }+ },+ "commit_wall": {+ "n": 3000,+ "legacy": {+ "mean": 248235,+ "median": 254831,+ "p10": 179186,+ "p90": 302935+ },+ "owned": {+ "mean": 254791,+ "median": 261440,+ "p10": 183976,+ "p90": 310853+ }+ },+ "gpu": {+ "n": 3000,+ "legacy": {+ "mean": 678942,+ "median": 694947,+ "p10": 465834,+ "p90": 854010+ },+ "owned": {+ "mean": 681999,+ "median": 697240,+ "p10": 468281,+ "p90": 852084+ }+ }+ },+ "power_before": {+ "ac_online": true,+ "battery": "Charging",+ "platform_profile": "performance",+ "governor": "schedutil",+ "epp": "performance",+ "no_turbo": "0"+ },+ "power_after": {+ "ac_online": true,+ "battery": "Charging",+ "platform_profile": "performance",+ "governor": "schedutil",+ "epp": "performance",+ "no_turbo": "0"+ }+ },+ "scale1.5/clear": {+ "cells": {+ "build_cpu": {+ "n": 3000,+ "legacy": {+ "mean": 223337,+ "median": 218183,+ "p10": 168229,+ "p90": 272090+ },+ "owned": {+ "mean": 209737,+ "median": 205764,+ "p10": 159362,+ "p90": 258332+ }+ },+ "build_wall": {+ "n": 3000,+ "legacy": {+ "mean": 229792,+ "median": 225240,+ "p10": 171883,+ "p90": 280317+ },+ "owned": {+ "mean": 215783,+ "median": 212877,+ "p10": 162885,+ "p90": 265899+ }+ },+ "commit_wall": {+ "n": 3000,+ "legacy": {+ "mean": 242233,+ "median": 237897,+ "p10": 180610,+ "p90": 295995+ },+ "owned": {+ "mean": 227853,+ "median": 224951,+ "p10": 171214,+ "p90": 280831+ }+ },+ "gpu": {+ "n": 3000,+ "legacy": {+ "mean": 278516,+ "median": 281875,+ "p10": 169531,+ "p90": 366563+ },+ "owned": {+ "mean": 257885,+ "median": 259062,+ "p10": 158489,+ "p90": 344844+ }+ }+ },+ "power_before": {+ "ac_online": true,+ "battery": "Charging",+ "platform_profile": "performance",+ "governor": "schedutil",+ "epp": "performance",+ "no_turbo": "0"+ },+ "power_after": {+ "ac_online": true,+ "battery": "Charging",+ "platform_profile": "performance",+ "governor": "schedutil",+ "epp": "performance",+ "no_turbo": "0"+ }+ },+ "scale1.5/glass": {+ "cells": {+ "build_cpu": {+ "n": 3000,+ "legacy": {+ "mean": 251443,+ "median": 258123,+ "p10": 183023,+ "p90": 298023+ },+ "owned": {+ "mean": 257174,+ "median": 263531,+ "p10": 190779,+ "p90": 304293+ }+ },+ "build_wall": {+ "n": 3000,+ "legacy": {+ "mean": 257999,+ "median": 261822,+ "p10": 185652,+ "p90": 309525+ },+ "owned": {+ "mean": 263686,+ "median": 268048,+ "p10": 196184,+ "p90": 315662+ }+ },+ "commit_wall": {+ "n": 3000,+ "legacy": {+ "mean": 270205,+ "median": 274098,+ "p10": 194814,+ "p90": 323578+ },+ "owned": {+ "mean": 275819,+ "median": 280262,+ "p10": 205394,+ "p90": 329819+ }+ },+ "gpu": {+ "n": 3000,+ "legacy": {+ "mean": 728277,+ "median": 737709,+ "p10": 521875,+ "p90": 887500+ },+ "owned": {+ "mean": 730885,+ "median": 737968,+ "p10": 544114,+ "p90": 886927+ }+ }+ },+ "power_before": {+ "ac_online": true,+ "battery": "Charging",+ "platform_profile": "performance",+ "governor": "schedutil",+ "epp": "performance",+ "no_turbo": "0"+ },+ "power_after": {+ "ac_online": true,+ "battery": "Charging",+ "platform_profile": "performance",+ "governor": "schedutil",+ "epp": "performance",+ "no_turbo": "0"+ }+ },+ "mixed/clear": {+ "cells": {+ "build_cpu": {+ "n": 3000,+ "legacy": {+ "mean": 205123,+ "median": 200058,+ "p10": 153695,+ "p90": 255068+ },+ "owned": {+ "mean": 204523,+ "median": 202528,+ "p10": 154176,+ "p90": 253180+ }+ },+ "build_wall": {+ "n": 3000,+ "legacy": {+ "mean": 210965,+ "median": 204116,+ "p10": 156181,+ "p90": 262051+ },+ "owned": {+ "mean": 210343,+ "median": 206528,+ "p10": 157378,+ "p90": 261705+ }+ },+ "commit_wall": {+ "n": 3000,+ "legacy": {+ "mean": 220876,+ "median": 214265,+ "p10": 163232,+ "p90": 274809+ },+ "owned": {+ "mean": 220098,+ "median": 216515,+ "p10": 164595,+ "p90": 274359+ }+ },+ "gpu": {+ "n": 3000,+ "legacy": {+ "mean": 146915,+ "median": 84427,+ "p10": 10677,+ "p90": 328854+ },+ "owned": {+ "mean": 143605,+ "median": 79844,+ "p10": 10677,+ "p90": 319583+ }+ }+ },+ "power_before": {+ "ac_online": true,+ "battery": "Charging",+ "platform_profile": "performance",+ "governor": "schedutil",+ "epp": "performance",+ "no_turbo": "0"+ },+ "power_after": {+ "ac_online": true,+ "battery": "Charging",+ "platform_profile": "performance",+ "governor": "schedutil",+ "epp": "performance",+ "no_turbo": "0"+ }+ },+ "mixed/glass": {+ "cells": {+ "build_cpu": {+ "n": 3000,+ "legacy": {+ "mean": 163277,+ "median": 161290,+ "p10": 115554,+ "p90": 203699+ },+ "owned": {+ "mean": 171615,+ "median": 165154,+ "p10": 121438,+ "p90": 221156+ }+ },+ "build_wall": {+ "n": 3000,+ "legacy": {+ "mean": 167115,+ "median": 165184,+ "p10": 117212,+ "p90": 208344+ },+ "owned": {+ "mean": 175690,+ "median": 168592,+ "p10": 123640,+ "p90": 227309+ }+ },+ "commit_wall": {+ "n": 3000,+ "legacy": {+ "mean": 173210,+ "median": 169836,+ "p10": 120313,+ "p90": 219092+ },+ "owned": {+ "mean": 182071,+ "median": 175045,+ "p10": 126937,+ "p90": 238248+ }+ },+ "gpu": {+ "n": 3000,+ "legacy": {+ "mean": 435729,+ "median": 351406,+ "p10": 191094,+ "p90": 731979+ },+ "owned": {+ "mean": 448717,+ "median": 358125,+ "p10": 198593,+ "p90": 757396+ }+ }+ },+ "power_before": {+ "ac_online": true,+ "battery": "Charging",+ "platform_profile": "performance",+ "governor": "schedutil",+ "epp": "performance",+ "no_turbo": "0"+ },+ "power_after": {+ "ac_online": true,+ "battery": "Charging",+ "platform_profile": "performance",+ "governor": "schedutil",+ "epp": "performance",+ "no_turbo": "0"+ }+ }+ }+ },+ "analytic_on_vs_off_scale1": {+ "what": "one binary, interleaved on/off/off/on sessions of scene_baseline --modes stats; per-frame microseconds, mean of two sessions each (pair spread 0.1-23%)",+ "frame_work": {+ "scene_commit_cpu": {+ "spinner_clear": {+ "off_us": 215.7,+ "on_us": 225.6+ },+ "spinner_glass": {+ "off_us": 263.6,+ "on_us": 269.6+ },+ "damage_full": {+ "off_us": 284.2,+ "on_us": 325.5+ },+ "drag": {+ "off_us": 416.4,+ "on_us": 469.2+ },+ "resize": {+ "off_us": 412.1,+ "on_us": 414.7+ },+ "zoom_85": {+ "off_us": 245.8,+ "on_us": 272.6+ },+ "zoom_70": {+ "off_us": 268.2,+ "on_us": 275.9+ },+ "zoom_55": {+ "off_us": 250.1,+ "on_us": 267.2+ },+ "zoom_min_hold": {+ "off_us": 241.9,+ "on_us": 269.7+ }+ },+ "gpu_elapsed": {+ "spinner_clear": {+ "off_us": 243.9,+ "on_us": 260.8+ },+ "spinner_glass": {+ "off_us": 703.2,+ "on_us": 706.9+ },+ "damage_full": {+ "off_us": 710.8,+ "on_us": 796.5+ },+ "drag": {+ "off_us": 1053.0,+ "on_us": 1154.4+ },+ "resize": {+ "off_us": 1521.5,+ "on_us": 1502.8+ },+ "zoom_85": {+ "off_us": 672.9,+ "on_us": 713.5+ },+ "zoom_70": {+ "off_us": 711.4,+ "on_us": 723.2+ },+ "zoom_55": {+ "off_us": 684.7,+ "on_us": 698.6+ },+ "zoom_min_hold": {+ "off_us": 246.5,+ "on_us": 281.6+ }+ },+ "cpu_frame": {+ "spinner_clear": {+ "off_us": 537.6,+ "on_us": 555.1+ },+ "spinner_glass": {+ "off_us": 992.1,+ "on_us": 988.9+ },+ "damage_full": {+ "off_us": 940.8,+ "on_us": 1037.6+ },+ "drag": {+ "off_us": 1401.5,+ "on_us": 1537.6+ },+ "resize": {+ "off_us": 2030.7,+ "on_us": 1925.9+ },+ "zoom_85": {+ "off_us": 965.2,+ "on_us": 1021.6+ },+ "zoom_70": {+ "off_us": 1005.9,+ "on_us": 1020.5+ },+ "zoom_55": {+ "off_us": 986.3,+ "on_us": 996.6+ },+ "zoom_min_hold": {+ "off_us": 554.3,+ "on_us": 589.8+ }+ },+ "projection_cpu": {+ "spinner_clear": {+ "off_us": 48.5,+ "on_us": 51.8+ },+ "spinner_glass": {+ "off_us": 52.5,+ "on_us": 53.5+ },+ "damage_full": {+ "off_us": 45.5,+ "on_us": 52.4+ },+ "drag": {+ "off_us": 143.6,+ "on_us": 151.3+ },+ "resize": {+ "off_us": 469.6,+ "on_us": 387.4+ },+ "zoom_85": {+ "off_us": 51.1,+ "on_us": 58.0+ },+ "zoom_70": {+ "off_us": 52.2,+ "on_us": 56.4+ },+ "zoom_55": {+ "off_us": 52.2,+ "on_us": 54.9+ },+ "zoom_min_hold": {+ "off_us": 48.6,+ "on_us": 51.6+ }+ }+ },+ "idle_rss_anon_kb": {+ "off": [+ 46324,+ 45612+ ],+ "on": [+ 45060,+ 46328+ ]+ }+ }+}\ No newline at end of filediff --git a/docs/plans/scene-graph-stage4.md b/docs/plans/scene-graph-stage4.mdindex 3c689d9..d9965ad 100644--- a/docs/plans/scene-graph-stage4.md+++ b/docs/plans/scene-graph-stage4.md@@ -1,6 +1,6 @@# Scene graph plan, stage 4: clipping and primitives-Status: **4a and 4b done, 4c to 4e not started**, 2026-10-10. Stage 3 of+Status: **4a to 4c done, 4d and 4e not started**, 2026-10-10. Stage 3 of[scene-graph.md](scene-graph.md) (the owned output pass, radius zero) is doneapart from hardware qualification; this stage is why the plan exists: the userrequires clipped client corners, and wlroots 0.20 cannot mask a client. The five@@ -271,24 +271,112 @@ program with no shape is exactly the plain one, so 4e could replace the threeplain programs by the two shaped ones and give back about 410 KiB, if the cost ofthe solid fill (every rectangle goes through it) is acceptable. It is not done here.-**4c. Analytic frames, owned path only.** When the owned presenter is selected,-`Toplevel` sets the group clip, the footer is `frame_border`, the titlebar raster-has no arcs, and the footer buffer, skirt, probe, side fills and straight border-rects are not created. `chrome.footerHeight` reads one process-wide flag, so every-consumer follows without edits. The legacy path is untouched and keeps its own-geometry. Hit tests become shape-aware. Gates:--* The frame is shorter, so goldens cannot match whole: the titlebar band, the side- borders and the client interior down to the legacy client's last row are- bit-identical to the legacy goldens (the same test clients draw both), and- the bottom band and all four corners are checked against the supersampled- reference instead.-* No fringe or seam across the scale and zoom grid; a CSD window, a maximized- window and a `.shell` window unchanged or as specified.-* `window_corners.py` extended with the corner-transparency check, and the- hit-test check at a clipped corner pixel (click reaches the window below).-* Cost: stage 0 baseline and stage 3 figures. Expect lower resize/move CPU and no- `edge_sample_*` activity; any rise in build CPU or GPU is a finding.+**4c. Analytic frames, owned path only. Done.** When the owned presenter starts+and `enable_shapes` works, `Server.init` sets `chrome.analytic_frames` (before any+window exists: every frame height depends on it) and the legacy path is untouched.++What a decorated window is then:++* `Toplevel.applyShape` gives `frame_tree` one clip (frame size, the radius on all+ four corners, `frame_border`, and the ring colour times the window opacity), from+ `syncChrome` and `applyOpacity`. A maximized window has a square one, for its+ border; CSD and fullscreen windows have none and keep the rect outline.+* The footer is `frame_border`, so the frame is 9 px shorter at the default radius+ and the client reaches the bottom. `chrome.footerHeight` reads the flag, so the+ ~20 call sites followed without edits. Saved layouts store client geometry, so+ they restore at the same client size.+* Titlebar and footer are plain bands (`ChromeState.radius` 0, no outer+ anti-aliasing: the shader gives them corners and edge); the footer buffer stays as+ a one-row fill and is deleted in 4e. Border rects are off; side fills stay rects.+ No edge probe runs (`applyEdgeSample`), so a commit no longer pays its GL+ readback and acquire wait.+* `shadow_tree`, a new tree holding only the invisible resize grab, and every xdg+ popup carry `setTreeUnclipped`. Window capture, which draws the client alone in its+ own loop, is handed the frame's shape (`PassShape`) so a captured window keeps+ transparent bottom corners (D3).+* **Hit tests** needed no post-filter after all: the view's `point_accepts_input`+ (`accepts()` in `projection.c`) evaluates the shape, and `wlr_scene_node_at`+ already goes on to the next node under a point that declines. Pointer constraints,+ tablets and touch share it. A rect cannot decline, but the only rects under a+ shape are the 1 px side fills, which are resize edges anyway.+* **A changed clip damages its rim** (`damage_clip_change`, new `scene_damage.c`,+ tested without a GPU): the border colour changes on hover with no view moving, so+ nothing else would tell wlroots. The rim is as wide as the largest radius plus the+ border and a margin.++Deviations from the plan, each forced by something found on the way:++* **The ring is composited over the body, not split from it.** The default+ `window_border` is `rgba(1,1,1,0.09)`; the spike's partition (body keeps the inset+ shape, the ring the rest) assumes an opaque ring and would draw a nearly invisible+ one over a transparent window. The shader now computes+ `(body * (1 - ring.a * w) + ring * w) * coverage`, which equals the partition for+ an opaque ring and matches the legacy border rects for a translucent one (gate 3+ has the case). This changed the 4b shader.+* **The ring is uniform: `max(1, round(border * scale))`.** The legacy straight edge+ is a snapped rect whose width follows the device grid (at 1.25 the right edge is two+ pixels, the left one). The two agree on integer scales; `frame_parity` leaves the+ rightmost column out on fractional scales.+* **A clipped item is drawn in two parts** (`scene_output.c`): the ring-free interior+ as before, one rectangle deeper than the corner arcs and the ring (a cross of three+ rectangles cost about twelve scissored draws per window), and the rest through the+ shape. Only that interior may block what is below or skip blending; the model's+ cover is used for occlusion, minus a margin for the ring. A window's items share one+ clip, so its cover is built once per run. Scanout refuses a clipped item.+* Output transforms permute the radii (`device_radii`, derived from the same+ function that places the boxes).++Gates:++* **Screenshots, legacy and owned side by side** (`frame_parity`, at 1, 1.25, 1.5 and+ 2): titlebar band, left and right side columns, the client interior and the shadow+ are **bit-identical** (maximum difference 0); the frame is 9 px shorter and its+ client box equal. The corner arcs differ by at most one level. The goldens cannot+ match whole any more (the bottom band differs, and the shadow moves up with it),+ and a recapture at scale 1 shows the client regions at the same positions.+* **Corners and clicks** (`window_corners.py`, owned): the client's bottom corner+ pixels are the wallpaper, the interior next to the arc keeps the client colour, a+ hit test at a clipped corner reaches nothing (`none`) while the interior is the+ window's. Unit tests in `projection_test.c`: the same point falls through to a+ window below, and a changed border colour, a new shape and a removed one damage the+ rim and only the rim, nothing for an unchanged one or a hidden window.+* **Window capture** (`capture.py`, owned, server-decorated fixture): bottom corners+ are transparent (premultiplied black, alpha 0), interior intact.+* Skirt check of `window_corners.py` made footer-aware; the Xwayland titlebar pin+ (41, stale since the default `chrome_height` became 46; the code gives+ `round(46 * 0.75)` = 35) is corrected and `test_native_scaling_managed_window`+ passes on both presenters.+* Owned-path runs of `appearance_chrome`, `decorations`, `kde_decorations`,+ `window_snapping`, `window_tabs`, `direct_scanout`, `explicit_sync`,+ `desktop_damage`, `panel_damage`, `capture`, `screenshot_regressions`,+ `output_scale`, `popup_constraint`, `focus_zoom`, `initial_window_state`,+ `workspaces`, `output_destroy`, `pointer_constraints` and `mini_map_windows` pass.+ Failures that also occur identically on legacy (`desktop_canvas`, `desktop_zoom`,+ `mini_map`, `mini_map_canvas`, `files_decoration`, `glass_hold`, `wifi_popup`, and+ `window_titles`, whose client sends an invalid UTF-8 title) are not this stage's.+ `workspace_focus` in `window_corners.py` flaked on both presenters.++Cost, measured on one binary with analytic frames on and off, interleaved on, off,+off, on at scale 1 (`scene-graph-stage4-results.json`; pair spread 0.1 to 23 %, so+read only the larger differences): resize is cheaper (`projection_cpu` -17 %,+`cpu_frame` -5 %). Where a whole window repaints it is dearer: `damage_full` and+drag read **+10 to +14 % output-build CPU and +10 to +12 % GPU** (about +40 to +90+us a frame), the lighter scenarios 0 to +7 %. That is a finding against "no rise in+build CPU or GPU": the shaded rim, program switches between the plain and the shaped+program, and about five draws per window item instead of one. Memory: nothing from+the frames themselves, but `enable_shapes` costs **about 1.3 MiB of anonymous+memory** in the real compositor (the isolated link measured 430 KiB; the driver+holds more once the programs exist), on top of the 0.44 MiB of stage 3. Both are+expected to come back in 4e (footer buffers, the plain programs, the probe's state),+and 4d removes the shadow patch cache if it passes.++Consequence for input: with the client reaching the bottom edge, the resize grab+inside the frame at the bottom shrinks from the 10 px footer to about 1 px (the 10 px+reach outside is unchanged), like the left and right edges, and the south corner+zones shrink with it. Revisit if it is felt.++Leftover: the 4b A/B reference (legacy vs owned, before 4c) reads +5.1 % in+mixed/glass, 0.1 point over its limit and the same cell that read +4.4 % in stage 3.**4d. Analytic shadows (owned path).** Replace the CPU patch set with thespike's analytic shadow. Gate: side-by-side against the CPU shadow, especiallydiff --git a/src/Popup.zig b/src/Popup.zigindex abfb6c6..969544c 100644--- a/src/Popup.zig+++ b/src/Popup.zig@@ -43,6 +43,9 @@ pub fn create(server: *Server, xdg_popup: *wlr.XdgPopup) !void {return err;};errdefer scene_tree.node.destroy(); // gpa.create below must not leak the node+ // The popup hangs under its parent's tree, which a window's rounded shape+ // clips; a menu is no part of that window's shape and may leave it.+ _ = @import("projection.zig").setTreeUnclipped(&scene_tree.node, true);const popup = gpa.create(Popup) catch |err| {log.err("Popup.create: could not allocate popup: {}", .{err});diff --git a/src/Server.zig b/src/Server.zigindex dd3b562..f64432e 100644--- a/src/Server.zig+++ b/src/Server.zig@@ -461,6 +461,15 @@ pub fn init(server: *Server, scale: ?f32, icon_theme_cfg: icon_theme.Config, io:if (loaded.compositor.scene_renderer == .owned) {server.output_renderer = scene_output_mod.Renderer.create(renderer) orelse return error.RendererInitFailed;log.info("scene renderer: owned GLES2 output pass", .{});+ // Rounded shapes are what lets the frame drop its CPU corners, skirt and+ // border rects. Decided here, before any window exists: the height of+ // every frame depends on it.+ if (server.output_renderer.?.enableShapes()) {+ @import("chrome.zig").analytic_frames = true;+ log.info("window frames: rounded shapes drawn by the output pass", .{});+ } else {+ log.warn("window frames: shaped programs unavailable, keeping CPU corners", .{});+ }}errdefer scene_output_mod.Renderer.destroy(server.output_renderer);server.outputs.init();diff --git a/src/Toplevel.zig b/src/Toplevel.zigindex 2fa7084..2e6b187 100644--- a/src/Toplevel.zig+++ b/src/Toplevel.zig@@ -19,6 +19,7 @@ const icon_service = @import("icon_service.zig");const resize = @import("resize.zig");const tiling = @import("snap.zig");const scene_data = @import("scene_data.zig");+const projection = @import("projection.zig");const theme = @import("ui").theme;const events = @import("ipc/events.zig");const stats = @import("ipc/stats.zig");@@ -235,6 +236,9 @@ chip_pos: anim.Anim = .{},chip_alpha: anim.Anim = .{ .property = .opacity },last_painted_hover: f32 = 0,skirt_fill: ?[4]f32 = null,+/// The window opacity the border colour of the shape was last given, so a+/// hover or focus repaint keeps the ring as faded as the body.+shape_opacity: f32 = 1,edge_kind: chrome.EdgeSampleKind = .uninitialized,edge_mapping: ?chrome.EdgeMapping = null,pending_edge_sample: bool = false,@@ -325,11 +329,18 @@ fn createChromeNodes(server: *Server) !ChromeNodes {if (!@import("projection.zig").setTreeZoom(&frame_tree.node, 1)) return error.OutOfMemory;// Input only: no buffer, so never drawn. Gives the edges their reach past- // the frame without depending on the shadow (`shadow_size = 0`).- const resize_grab = try frame_tree.createSceneBuffer(null);+ // the frame without depending on the shadow (`shadow_size = 0`). It sits in+ // a tree of its own so that the window's shape, which cuts the corners off+ // everything else under the frame, does not cut its reach: that must accept+ // points the shape declines.+ const reach_tree = try frame_tree.createSceneTree();+ _ = @import("projection.zig").setTreeUnclipped(&reach_tree.node, true);+ const resize_grab = try reach_tree.createSceneBuffer(null);resize_grab.point_accepts_input = chromeAcceptsInput;const shadow_tree = try frame_tree.createSceneTree();+ // The shadow is outside the shape by definition.+ _ = @import("projection.zig").setTreeUnclipped(&shadow_tree.node, true);var shadow_corners: [4]*wlr.SceneBuffer = undefined;for (&shadow_corners) |*buf| {buf.* = try shadow_tree.createSceneBuffer(null);@@ -2838,7 +2849,10 @@ pub fn syncChrome(toplevel: *Toplevel, sample_edge: bool, rebuild_shadow: bool,toplevel.titlebar_buffer.node.setEnabled(decorated);toplevel.footer_buffer.node.setEnabled(decorated);for (toplevel.side_fills) |rect| rect.node.setEnabled(decorated);- for (toplevel.border_rects) |rect| rect.node.setEnabled(decorated or toplevel.hasWorkspaceFocusBorder());+ // With a shape the border is the shader's; the rects only outline windows+ // that draw their own decorations.+ const shaped = chrome.analytic_frames and decorated;+ for (toplevel.border_rects) |rect| rect.node.setEnabled(!shaped and (decorated or toplevel.hasWorkspaceFocusBorder()));if (!decorated) {toplevel.resetEdgeSample();toplevel.releaseIcon();@@ -2858,6 +2872,7 @@ pub fn syncChrome(toplevel: *Toplevel, sample_edge: bool, rebuild_shadow: bool,toplevel.resetChip();toplevel.last_painted_hover = 0;toplevel.syncBorders(animated.w, animated.h);+ toplevel.applyShape();return;}@@ -2876,15 +2891,17 @@ pub fn syncChrome(toplevel: *Toplevel, sample_edge: bool, rebuild_shadow: bool,.pending, .missing => null,};toplevel.updateHeldIcon(icon);- if (sample_edge) toplevel.applyEdgeSample();+ // A shape clips the client itself, so there is no skirt to colour.+ if (sample_edge and !chrome.analytic_frames) toplevel.applyEdgeSample();// The settings body is one opaque colour: the skirt continues it exactly.- if (toplevel.backend == .shell) toplevel.skirt_fill = @import("control_center/panel.zig").bodyColor();+ if (toplevel.backend == .shell and !chrome.analytic_frames) toplevel.skirt_fill = @import("control_center/panel.zig").bodyColor();const hover = toplevel.hover_anim.value(now_ms);const chip_alpha = toplevel.chip_alpha.value(now_ms);var tab_storage: [@import("window_tabs.zig").max_tabs]@import("chrome_tabs.zig").Tab = undefined;const state: chrome.ChromeState = .{.tabs = toplevel.tabStrip(&tab_storage),- .radius = radius,+ // The shader draws the corners and the border; the raster is a plain band.+ .radius = if (chrome.analytic_frames) 0 else radius,.active = toplevel.activated,.workspace_focus = toplevel.hasWorkspaceFocusBorder(),.maximized = toplevel.isMaximized(),@@ -2937,6 +2954,7 @@ pub fn syncChrome(toplevel: *Toplevel, sample_edge: bool, rebuild_shadow: bool,toplevel.footer_buffer.setDestSize(width, footer);toplevel.syncBorders(width, height);+ toplevel.applyShape();toplevel.syncResizeGrab(width, height);if (rebuild_shadow) try toplevel.syncShadow(width, height, radius);@@ -3065,6 +3083,30 @@ fn syncResizeGrab(toplevel: *Toplevel, width: i32, height: i32) void {toplevel.resize_grab.setDestSize(width + 2 * reach, height + 2 * reach);}+/// The shape that clips the whole window, titlebar, client and subsurfaces, in+/// the output pass (see `chrome.analytic_frames`). Windows that draw their own+/// decorations, and fullscreen ones, have none; a maximized one has a square one,+/// for its border. Nothing changes if the shape is the one already set.+fn applyShape(toplevel: *Toplevel) void {+ if (!chrome.analytic_frames) return;+ const node = &toplevel.frame_tree.node;+ if (!toplevel.hasServerDecorations() or toplevel.chrome_width <= 0 or toplevel.chrome_height <= 0) {+ _ = projection.setTreeClip(node, null);+ return;+ }+ const radius: f64 = toplevel.cornerRadius();+ const ring = toplevel.borderColor().scale(toplevel.shape_opacity);+ if (!projection.setTreeClip(node, .{+ .width = toplevel.chrome_width,+ .height = toplevel.chrome_height,+ .radii = .{ radius, radius, radius, radius },+ .border = @floatFromInt(chrome.frame_border),+ .border_color = ring.rgba,+ })) {+ log.warn("could not set the window shape ({d}x{d})", .{ toplevel.chrome_width, toplevel.chrome_height });+ }+}+fn syncBorders(toplevel: *Toplevel, width: i32, height: i32) void {const color = toplevel.borderColor();for (toplevel.border_rects) |rect| col.setRect(rect, color);@@ -3096,6 +3138,8 @@ fn syncBorders(toplevel: *Toplevel, width: i32, height: i32) void {rect.node.setPosition(if (i == 0) 0 else width - chrome.frame_border, body_top);rect.setSize(chrome.frame_border, body_height);}+ // The ring over the fills, the titlebar and the client's edge is the shape's.+ if (chrome.analytic_frames) return;// Every straight edge runs between two rasterized corner arcs, so all four// are inset at both ends.@@ -3141,6 +3185,8 @@ pub fn applyOpacity(toplevel: *Toplevel, now_ms: i64) void {const color = toplevel.borderColor().scale(opacity);for (toplevel.border_rects) |rect| col.setRect(rect, color);for (toplevel.side_fills) |rect| col.setRect(rect, chrome.fillColor().scale(opacity));+ toplevel.shape_opacity = opacity;+ toplevel.applyShape();glass.Effect.configure(toplevel.glass_effect, toplevel.cornerRadius(), opacity);switch (toplevel.backend) {.placeholder => |*ph| col.setRect(ph.body_rect, col.Straight.fromRgba(theme.global.window_bg).premultiply().scale(opacity)),diff --git a/src/capture/window_source.zig b/src/capture/window_source.zigindex 74064b2..21c8386 100644--- a/src/capture/window_source.zig+++ b/src/capture/window_source.zig@@ -33,9 +33,22 @@ const Toplevel = @import("../Toplevel.zig");const gpa = @import("../main.zig").gpa;const log = std.log.scoped(.capture);+const chrome = @import("../chrome.zig");const DRM_FORMAT_ARGB8888: u32 = 0x34325241;+/// The window's rounded shape in capture pixels (see `chrome.analytic_frames`+/// and scene_pass.h). The capture is of the client alone, so the shape only+/// matters where it cuts the client: its two bottom corners, which stay+/// transparent here as they are on screen.+const PassShape = extern struct {+ box: wlr.Box,+ radii: [4]f32,+ border: f32 = 0,+ border_color: [4]f32 = @splat(0),+};+extern fn rediwm_scene_pass_add_texture_shaped(pass: *wlr.RenderPass, options: *const wlr.RenderPass.TextureOptions, shape: *const PassShape) void;+// Not bound in the pinned zig-wlroots package; declared directly the same// way every other binding file in that package declares its extern fns.// Fills in the well-known CIE1931 xy chromaticities for a named primary set@@ -155,6 +168,24 @@ pub const WindowCaptureSource = struct {};}+ /// The frame's shape relative to the capture: the frame's origin lies up and+ /// left of the content by the content's own offset in it.+ fn frameShape(self: *WindowCaptureSource, off_x: i32, off_y: i32) ?PassShape {+ if (!chrome.analytic_frames) return null;+ const toplevel = self.manager.server.findToplevelById(self.window_id) orelse return null;+ const radius = toplevel.cornerRadius();+ if (!toplevel.hasServerDecorations() or radius <= 0 or toplevel.chrome_width <= 0 or toplevel.chrome_height <= 0) return null;+ return .{+ .box = .{+ .x = -self.content_node.x - off_x,+ .y = -self.content_node.y - off_y,+ .width = toplevel.chrome_width,+ .height = toplevel.chrome_height,+ },+ .radii = @splat(radius),+ };+ }+const RenderCtx = struct {pass: *wlr.RenderPass,renderer: *wlr.Renderer,@@ -162,6 +193,7 @@ pub const WindowCaptureSource = struct {primaries: *const wlr.color.Primaries,off_x: i32,off_y: i32,+ shape: ?PassShape,};fn renderFrame(self: *WindowCaptureSource) !void {@@ -217,6 +249,7 @@ pub const WindowCaptureSource = struct {.primaries = &primaries,.off_x = geom.x,.off_y = geom.y,+ .shape = self.frameShape(geom.x, geom.y),};self.content_node.forEachBuffer(*RenderCtx, renderNodeBuffer, &ctx);@@ -254,7 +287,7 @@ pub const WindowCaptureSource = struct {var alpha = scene_buffer.opacity;var luminance_multiplier: f32 = 1.0;- ctx.pass.addTexture(&.{+ const options: wlr.RenderPass.TextureOptions = .{.texture = texture,.src_box = scene_buffer.src_box,.dst_box = .{@@ -275,7 +308,12 @@ pub const WindowCaptureSource = struct {.luminance_multiplier = &luminance_multiplier,.wait_timeline = scene_buffer.private.wait_timeline,.wait_point = scene_buffer.private.wait_point,- });+ };+ if (ctx.shape) |*shape| {+ rediwm_scene_pass_add_texture_shaped(ctx.pass, &options, shape);+ } else {+ ctx.pass.addTexture(&options);+ }}fn copyFrame(diff --git a/src/chrome.zig b/src/chrome.zigindex 0b05ad7..7d5fb6e 100644--- a/src/chrome.zig+++ b/src/chrome.zig@@ -35,9 +35,18 @@ const title_inset = window_chrome.title_inset;pub const title_icon_size = window_chrome.title_icon_size;const title_icon_gap = window_chrome.title_icon_gap;-// The client's surface has square corners of its own, so the frame reserves a-// band of chrome below it deep enough to hold the bottom corner arcs.+/// Set once at startup, before any window exists, when the owned output pass can+/// draw rounded shapes (stage 4c of docs/plans/scene-graph-stage4.md). Then the+/// compositor gives every decorated window a shape that clips the titlebar, the+/// client and its subsurfaces together, draws the corners and the border in the+/// shader, and the frame needs no band of chrome below the client: the footer is+/// the border. Otherwise the legacy frame is drawn: CPU arcs, a skirt, border rects.+pub var analytic_frames: bool = false;++// Without a shape the client's surface has square corners of its own, so the+// frame reserves a band of chrome below it deep enough to hold the bottom arcs.pub fn footerHeight(radius: f32) i32 {+ if (analytic_frames) return frame_border;return @max(frame_border, @as(i32, @intFromFloat(@ceil(radius))));}@@ -577,7 +586,8 @@ pub const ChromeBuffer = struct {frame.state = state;frame.base.init(&impl, frame.width, frame.height);const corners: i32 = @min(frame.logical_width, @as(i32, @intFromFloat(@ceil(state.radius))) + 1);- const border_changed = previous.state.hover != state.hover or previous.state.workspace_focus != state.workspace_focus;+ // The border is the shader's with a shape: nothing in the raster changes.+ const border_changed = !analytic_frames and (previous.state.hover != state.hover or previous.state.workspace_focus != state.workspace_focus);if (state.tabs.tabs.len > 0 and frame.band == .titlebar) {const tabs = @import("chrome_tabs.zig");if (!border_changed and previous.tabs_layout_hash == tabs.layoutHash(state.tabs) and@@ -713,7 +723,9 @@ pub const ChromeBuffer = struct {// Away from the corners and the side antialiasing ramp, every pixel// in a row has the same fill and outer coverage. Pack that colour once// instead of repeating four rounded float conversions across the bar.- const flat_inset = @max(radius, 1 / scale);+ // With a shape the buffer is plain: the shader gives it its corners, edge+ // and border, so no pixel is shaped (or anti-aliased) here a second time.+ const flat_inset = if (analytic_frames) 0 else @max(radius, 1 / scale);const stride: usize = @intCast(frame.width);const x0: usize = if (clip) |box| @intCast(@min(frame.width, @max(0, @as(i32, @intFromFloat(@round(@as(f32, @floatFromInt(box.x)) * scale)))))) else 0;@@ -726,7 +738,7 @@ pub const ChromeBuffer = struct {const row = device_y * stride;var row_color = base;if (frame.band == .titlebar and yi == m.titlebarHeight() - 1) row_color = Color.divider().over(row_color);- const flat_color = row_color.scaled(edgeCoverage(sdRoundedBox(fw / 2, py, 0, 0, fw, fh, radius), scale)).argb();+ const flat_color = row_color.scaled(if (analytic_frames) 1 else edgeCoverage(sdRoundedBox(fw / 2, py, 0, 0, fw, fh, radius), scale)).argb();const control_row = frame.band == .titlebar and py >= control_top and py <= control_bottom;const icon_row = frame.band == .titlebar and frame.state.tabs.tabs.len == 0 and frame.state.icon != null andpy >= icon_top and py < icon_top + @as(f32, @floatFromInt(m.iconSize()));@@ -739,7 +751,7 @@ pub const ChromeBuffer = struct {continue;}- const outer_cov = edgeCoverage(sdRoundedBox(px, py, 0, 0, fw, fh, radius), scale);+ const outer_cov = if (analytic_frames) 1 else edgeCoverage(sdRoundedBox(px, py, 0, 0, fw, fh, radius), scale);if (outer_cov == 0) {frame.pixels[row + x] = 0;continue;diff --git a/src/projection.c b/src/projection.cindex 91f415f..954d1f8 100644--- a/src/projection.c+++ b/src/projection.c@@ -4,6 +4,7 @@#define WLR_PRIVATE private#include "projection.h"#include "scene_graph.h"+#include "scene_damage.h"#include <math.h>#include <stdlib.h>#include <string.h>@@ -121,6 +122,10 @@ struct tree_props {bool has_zoom, has_scale, has_clip, unclipped;double zoom, scale;struct rediwm_clip_spec clip;+ // The clip as the last resolve() saw it in layout space, to tell a changed+ // shape (to be damaged) from a moved window (whose views damage themselves).+ struct rediwm_clip applied;+ bool has_applied;};static void destroy_tree_props(struct wlr_addon *addon) {struct tree_props *props = wl_container_of(addon, props, addon);@@ -167,7 +172,7 @@ bool rediwm_projection_set_tree_clip(struct wlr_scene_node *node,}if (spec->width <= 0 || spec->height <= 0 || !finite_at_least_zero(spec->border)) return false;for (int i = 0; i < 4; i++)- if (!finite_at_least_zero(spec->radii[i])) return false;+ if (!finite_at_least_zero(spec->radii[i]) || !isfinite(spec->border_color[i])) return false;struct tree_props *props = tree_props_get(node);if (!props) return false;props->clip = *spec;@@ -400,6 +405,16 @@ static bool accepts(struct wlr_scene_buffer *buffer, double *x, double *y) {return false;*x *= (double)l->item.width / buffer->dst_width;*y *= (double)l->item.height / buffer->dst_height;+ // A window's rounded corners are transparent: a point the shape cuts away goes+ // to whatever is below, which wlroots finds by asking the next node. The point+ // is now in source units; the shape is in layout space.+ if (l->item.clip && l->item.width > 0 && l->item.height > 0) {+ const struct rediwm_edges *e = &l->item.edges;+ const double px = e->x1 + *x * (e->x2 - e->x1) / l->item.width;+ const double py = e->y1 + *y * (e->y2 - e->y1) / l->item.height;+ if (rediwm_clip_distance(l->item.clip, px, py) > 0)+ return false;+ }struct wlr_scene_buffer *source = wlr_scene_buffer_from_node(l->source);return !source->point_accepts_input ||source->point_accepts_input(source, x, y);@@ -503,6 +518,46 @@ static uint64_t mirror_opaque(pixman_region32_t *out, const pixman_region32_t *s// Glass writes its own projected buffers after this synchronization pass.extern bool rediwm_glass_is_effect_node(struct wlr_scene_node *node);+// A clip's size, radii, border or colour changed: its views did not move, so+// nothing else tells wlroots that the corner arcs and the ring need repainting.+// The zone is the frame's rim, as wide as the largest radius plus the border and+// a margin; where the frame is thinner than twice that it is the whole box.+static bool clip_same_shape(const struct rediwm_clip *a, const struct rediwm_clip *b) {+ if (a->edges.x2 - a->edges.x1 != b->edges.x2 - b->edges.x1 ||+ a->edges.y2 - a->edges.y1 != b->edges.y2 - b->edges.y1 || a->border != b->border)+ return false;+ for (int i = 0; i < 4; i++)+ if (a->radii[i] != b->radii[i] || a->border_color[i] != b->border_color[i]) return false;+ return true;+}+static void clip_rim(pixman_region32_t *out, const struct rediwm_clip *c) {+ const struct rediwm_snap f = rediwm_edges_snap(c->edges);+ if (f.width <= 0 || f.height <= 0) return;+ double radius = 0;+ for (int i = 0; i < 4; i++)+ if (c->radii[i] > radius) radius = c->radii[i];+ const int inset = (int)ceil(radius) + (int)ceil(c->border) + 2;+ pixman_region32_t rim;+ pixman_region32_init_rect(&rim, f.x, f.y, f.width, f.height);+ if (f.width > 2 * inset && f.height > 2 * inset) {+ pixman_region32_t inner;+ pixman_region32_init_rect(&inner, f.x + inset, f.y + inset, f.width - 2 * inset,+ f.height - 2 * inset);+ pixman_region32_subtract(&rim, &rim, &inner);+ pixman_region32_fini(&inner);+ }+ pixman_region32_union(out, out, &rim);+ pixman_region32_fini(&rim);+}+static void damage_clip_change(struct rediwm_projection *p, const struct rediwm_clip *before,+ const struct rediwm_clip *after) {+ pixman_region32_t region;+ pixman_region32_init(®ion);+ if (before) clip_rim(®ion, before);+ if (after) clip_rim(®ion, after);+ if (pixman_region32_not_empty(®ion)) rediwm_scene_damage_layout(p->scene, ®ion);+ pixman_region32_fini(®ion);+}// resolve(): source tree -> graph. Writes items, group origins, `seen` flags and// the paint-order lists; creates adapters for nodes it meets the first time, but// moves, sizes and shows nothing in the view tree.@@ -515,7 +570,7 @@ static void resolve_node(struct rediwm_projection *p, struct group *g,enabled = enabled && node->enabled;if (node->type == WLR_SCENE_NODE_TREE) {struct rediwm_clip here;- const struct tree_props *props = tree_props_find(node);+ struct tree_props *props = tree_props_find(node);if (props) {// Window zoom composes with the camera, around the frame origin.if (props->has_zoom) t = rediwm_xform_scale_about(t, props->zoom, x, y);@@ -524,6 +579,14 @@ static void resolve_node(struct rediwm_projection *p, struct group *g,if (props->has_clip) {here = rediwm_clip_resolve(t, x, y, &props->clip);clip = &here;+ // A hidden window damages nothing; showing it will.+ if (enabled && (!props->has_applied || !clip_same_shape(&props->applied, &here)))+ damage_clip_change(p, props->has_applied ? &props->applied : NULL, &here);+ props->applied = here;+ props->has_applied = true;+ } else if (props->has_applied) {+ if (enabled) damage_clip_change(p, &props->applied, NULL);+ props->has_applied = false;}}struct wlr_scene_node *child;diff --git a/src/projection.zig b/src/projection.zigindex 7807801..9a40c15 100644--- a/src/projection.zig+++ b/src/projection.zig@@ -26,3 +26,26 @@ extern fn rediwm_projection_set_tree_zoom(node: *wlr.SceneNode, scale: f64) boolpub const setTreeZoom = rediwm_projection_set_tree_zoom;extern fn rediwm_projection_set_tree_scale(node: *wlr.SceneNode, factor: f64) bool;pub const setTreeScale = rediwm_projection_set_tree_scale;++/// One rounded-rectangle shape for every leaf under a tree (see scene_graph.h):+/// source units, anchored at the tree's origin. `border_color` is premultiplied,+/// with the window's opacity applied.+pub const ClipSpec = extern struct {+ width: c_int,+ height: c_int,+ /// Top-left, top-right, bottom-right, bottom-left.+ radii: [4]f64,+ border: f64,+ border_color: [4]f32,+};+extern fn rediwm_projection_set_tree_clip(node: *wlr.SceneNode, spec: ?*const ClipSpec) bool;+/// A null spec removes the clip. False for a size that is not positive or a+/// radius, border or colour that is negative or not finite.+pub fn setTreeClip(node: *wlr.SceneNode, spec: ?ClipSpec) bool {+ if (spec) |value| return rediwm_projection_set_tree_clip(node, &value);+ return rediwm_projection_set_tree_clip(node, null);+}+/// Ends the clip inherited from an ancestor for this subtree: an xdg popup or a+/// window's shadow hangs under the window's tree but is no part of its shape.+extern fn rediwm_projection_set_tree_unclipped(node: *wlr.SceneNode, unclipped: bool) bool;+pub const setTreeUnclipped = rediwm_projection_set_tree_unclipped;diff --git a/src/projection_test.c b/src/projection_test.cindex 1f7acc2..9ce04a9 100644--- a/src/projection_test.c+++ b/src/projection_test.c@@ -395,8 +395,8 @@ static void test_clip_opaque(void) {// pill keeps the full-height column between its two semicircles.struct rediwm_snap one[3];const struct rediwm_xform identity = {1, 0, 0};- assert(rediwm_clip_opaque(&(struct rediwm_clip){rediwm_xform_rect(identity, 0, 0, 8, 8), {4, 4, 4, 4}, 0}, one) == 0);- assert(rediwm_clip_opaque(&(struct rediwm_clip){rediwm_xform_rect(identity, 5, 7, 120, 80), {40, 40, 40, 40}, 0}, one) == 1);+ assert(rediwm_clip_opaque(&(struct rediwm_clip){rediwm_xform_rect(identity, 0, 0, 8, 8), {4, 4, 4, 4}, 0, {0}}, one) == 0);+ assert(rediwm_clip_opaque(&(struct rediwm_clip){rediwm_xform_rect(identity, 5, 7, 120, 80), {40, 40, 40, 40}, 0, {0}}, one) == 1);assert(one[0].x == 5 + 42 && one[0].y == 7 && one[0].width == 120 - 84 && one[0].height == 80);}static void test_clip_projection(struct wlr_scene *scene) {@@ -539,6 +539,106 @@ static void test_clip_projection(struct wlr_scene *scene) {wlr_buffer_drop(popup_buffer);wlr_buffer_drop(sub_buffer);}+// What a changed shape does to the output, and to the pointer. The views of a+// window do not move when its border colour changes, so the rim is damaged by the+// projection itself; and a point the shape cuts away goes to what is below.+// Damage is in output pixels and the points below are in layout coordinates, at+// whatever scale an earlier test left the output.+static bool layout_damaged(struct wlr_scene_output *out, double x, double y) {+ return damaged(out, (int)(x * out->output->scale), (int)(y * out->output->scale));+}+static void test_clip_output(struct wlr_scene *scene, struct wlr_scene_output *out) {+ struct wlr_scene_tree *source = wlr_scene_tree_create(&scene->tree);+ struct wlr_scene_tree *view = wlr_scene_tree_create(&scene->tree);+ struct rediwm_projection *p = rediwm_projection_create(source, view, scene);+ assert(p);+ struct wlr_scene_tree *under_tree = wlr_scene_tree_create(source);+ struct wlr_scene_tree *frame = wlr_scene_tree_create(source);+ struct wlr_buffer *under_buffer = buffer_create(), *client_buffer = buffer_create();+ struct wlr_scene_buffer *under = wlr_scene_buffer_create(under_tree, under_buffer);+ struct wlr_scene_buffer *client = wlr_scene_buffer_create(frame, client_buffer);+ assert(under_tree && frame && under && client);+ wlr_scene_node_set_position(&under_tree->node, 300, 200);+ wlr_scene_node_set_position(&frame->node, 300, 200);+ wlr_scene_buffer_set_dest_size(under, 120, 80);+ wlr_scene_buffer_set_dest_size(client, 120, 80);+ struct rediwm_clip_spec spec = {.width = 120, .height = 80, .radii = {10, 10, 10, 10}, .border = 1,+ .border_color = {.1f, .1f, .1f, .1f}};+ assert(rediwm_projection_set_tree_clip(&frame->node, &spec));+ rediwm_projection_sync(p, 1, 0, 0, 0, 0);+ struct leaf *client_leaf = get_leaf(p, &client->node), *under_leaf = get_leaf(p, &under->node);++ // Points inside the window reach it; the corner pixel, which the arc cuts away,+ // goes to the window below, and so does the one just outside the box.+ double nx, ny;+ struct wlr_scene_node *hit = wlr_scene_node_at(&view->node, 360, 240, &nx, &ny);+ assert(hit == client_leaf->view);+ hit = wlr_scene_node_at(&view->node, 300.5, 200.5, &nx, &ny);+ assert(hit == under_leaf->view);+ hit = wlr_scene_node_at(&view->node, 419.5, 279.5, &nx, &ny); // bottom-right corner+ assert(hit == under_leaf->view);+ hit = wlr_scene_node_at(&view->node, 310.5, 200.5, &nx, &ny); // on the straight edge+ assert(hit == client_leaf->view);+ // Without a shape the corner is the window's again.+ assert(rediwm_projection_set_tree_clip(&frame->node, NULL));+ rediwm_projection_sync(p, 1, 0, 0, 0, 0);+ assert(wlr_scene_node_at(&view->node, 300.5, 200.5, &nx, &ny) == client_leaf->view);+ clear_damage(out);++ // A shape appearing, a different border colour, and the shape going away each+ // damage the rim and only the rim. Nothing else moved.+ assert(rediwm_projection_set_tree_clip(&frame->node, &spec));+ rediwm_projection_sync(p, 1, 0, 0, 0, 0);+ assert(layout_damaged(out, 301, 201) && layout_damaged(out, 419, 279) && layout_damaged(out, 360, 202));+ assert(!layout_damaged(out, 360, 240));+ clear_damage(out);+ rediwm_projection_sync(p, 1, 0, 0, 0, 0); // Nothing changed.+ assert(!pixman_region32_not_empty(&out->damage_ring.current));+ spec.border_color[0] = .3f;+ assert(rediwm_projection_set_tree_clip(&frame->node, &spec));+ rediwm_projection_sync(p, 1, 0, 0, 0, 0);+ assert(layout_damaged(out, 301, 201) && layout_damaged(out, 419, 279) && layout_damaged(out, 300, 240));+ assert(!layout_damaged(out, 360, 240) && !layout_damaged(out, 100, 100));+ assert(pixman_region32_not_empty(&out->private.pending_commit_damage));+ clear_damage(out);+ // Setting the same shape again damages nothing.+ assert(rediwm_projection_set_tree_clip(&frame->node, &spec));+ rediwm_projection_sync(p, 1, 0, 0, 0, 0);+ assert(!pixman_region32_not_empty(&out->damage_ring.current));+ // The shape going away damages the rim, not the interior.+ assert(rediwm_projection_set_tree_clip(&frame->node, NULL));+ rediwm_projection_sync(p, 1, 0, 0, 0, 0);+ assert(layout_damaged(out, 301, 201) && layout_damaged(out, 419, 279) && !layout_damaged(out, 360, 240));+ // Moving a window moves its views, which damage themselves; the shape follows+ // without a second, rim-only report of its own.+ assert(rediwm_projection_set_tree_clip(&frame->node, &spec));+ rediwm_projection_sync(p, 1, 0, 0, 0, 0);+ clear_damage(out);+ wlr_scene_node_set_position(&frame->node, 310, 200);+ rediwm_projection_sync(p, 1, 0, 0, 0, 0);+ assert(layout_damaged(out, 370, 240)); // the views of the window moved+ wlr_scene_node_set_position(&frame->node, 300, 200);+ rediwm_projection_sync(p, 1, 0, 0, 0, 0);+ assert(rediwm_projection_set_tree_clip(&frame->node, NULL));+ rediwm_projection_sync(p, 1, 0, 0, 0, 0);+ // A hidden window damages nothing for a shape change.+ wlr_scene_node_set_enabled(&frame->node, false);+ rediwm_projection_sync(p, 1, 0, 0, 0, 0);+ clear_damage(out);+ assert(rediwm_projection_set_tree_clip(&frame->node, &spec));+ rediwm_projection_sync(p, 1, 0, 0, 0, 0);+ assert(!pixman_region32_not_empty(&out->damage_ring.current));+ spec.border_color[1] = .7f;+ assert(rediwm_projection_set_tree_clip(&frame->node, &spec));+ rediwm_projection_sync(p, 1, 0, 0, 0, 0);+ assert(!pixman_region32_not_empty(&out->damage_ring.current));++ wlr_scene_node_destroy(&view->node);+ rediwm_projection_destroy(p);+ wlr_scene_node_destroy(&source->node);+ wlr_buffer_drop(under_buffer);+ wlr_buffer_drop(client_buffer);+}// A client surface's opaque region has to reach its view, or nothing below the// window is ever culled. The buffers here reveal no format, like a// wlr_client_buffer, so only the node's own region can say they are opaque.@@ -901,6 +1001,7 @@ int main(void) {test_clip_geometry();test_clip_opaque();test_clip_projection(scene);+ test_clip_output(scene, out);test_opaque(scene);wlr_scene_node_destroy(&scene->tree.node);wlr_buffer_drop(a);diff --git a/src/scene_damage.c b/src/scene_damage.cnew file mode 100644index 0000000..04a9ec5--- /dev/null+++ b/src/scene_damage.c@@ -0,0 +1,41 @@+// Damage for changes that move no view node. Needs only wlroots' scene, so the+// projection's tests can link it without the GL pass.+#define WLR_USE_UNSTABLE+#define WLR_PRIVATE private+#include "scene_damage.h"+#include "scene_view.h"+#include <wlr/types/wlr_damage_ring.h>+#include <wlr/types/wlr_output.h>+#include <wlr/types/wlr_scene.h>++// Damage a layout-space region on every output it touches, as a node update+// would: the ring and the commit damage, in device pixels, and a frame request.+// For changes the graph shows only as a different clip (a border colour), which+// move no view node.+void rediwm_scene_damage_layout(struct wlr_scene *scene, const pixman_region32_t *region) {+ struct wlr_scene_output *out;+ wl_list_for_each(out, &scene->outputs, link) {+ struct wlr_output *output = out->output;+ struct output_view v = {.width = output->width, .height = output->height,+ .scale = output->scale, .transform = output->transform,+ .logical = {.x = out->x, .y = out->y}};+ v.trans_width = v.width;+ v.trans_height = v.height;+ wlr_output_transform_coords(v.transform, &v.trans_width, &v.trans_height);+ v.logical.width = v.trans_width / v.scale;+ v.logical.height = v.trans_height / v.scale;+ pixman_region32_t device;+ pixman_region32_init(&device);+ pixman_region32_intersect_rect(&device, (pixman_region32_t *)region, v.logical.x, v.logical.y,+ v.logical.width, v.logical.height);+ if (pixman_region32_not_empty(&device)) {+ output_view_region(&device, &v, true);+ pixman_region32_intersect_rect(&device, &device, 0, 0, v.width, v.height);+ wlr_damage_ring_add(&out->damage_ring, &device);+ pixman_region32_union(&out->private.pending_commit_damage,+ &out->private.pending_commit_damage, &device);+ wlr_output_schedule_frame(output);+ }+ pixman_region32_fini(&device);+ }+}diff --git a/src/scene_damage.h b/src/scene_damage.hnew file mode 100644index 0000000..de1e146--- /dev/null+++ b/src/scene_damage.h@@ -0,0 +1,6 @@+#pragma once+struct wlr_scene;+struct pixman_region32;+// Damages a layout-space region on every output it touches, for changes that+// move no view node (a clip's border colour).+void rediwm_scene_damage_layout(struct wlr_scene *, const struct pixman_region32 *);diff --git a/src/scene_graph.h b/src/scene_graph.hindex 2778f71..dbc904b 100644--- a/src/scene_graph.h+++ b/src/scene_graph.h@@ -78,11 +78,15 @@ struct rediwm_clip_spec {// Top-left, top-right, bottom-right, bottom-left.double radii[4];double border;+ // Premultiplied, with the window's opacity already applied: the ring is+ // composited over the body, so a translucent border tints what is under it.+ float border_color[4];};struct rediwm_clip {struct rediwm_edges edges;double radii[4];double border;+ float border_color[4];};// Radii are capped at half the short side before scaling, as the CPU chrome// does, so a small window never asks for an impossible arc.@@ -95,6 +99,7 @@ static inline struct rediwm_clip rediwm_clip_resolve(struct rediwm_xform t, doub.border = spec->border * t.scale};for (int i = 0; i < 4; i++)clip.radii[i] = (spec->radii[i] < cap ? spec->radii[i] : cap) * t.scale;+ for (int i = 0; i < 4; i++) clip.border_color[i] = spec->border_color[i];return clip;}// Signed distance, negative inside, from (px, py) to the rounded rectanglediff --git a/src/scene_output.c b/src/scene_output.cindex 53ca53a..3aaf10c 100644--- a/src/scene_output.c+++ b/src/scene_output.c@@ -3,15 +3,18 @@#define WLR_USE_UNSTABLE#define WLR_PRIVATE private#include "scene_output.h"+#include "scene_view.h"#include "scene_pass.h"#include "scene_graph.h"#include "projection.h"+#include <math.h>#include <stdlib.h>#include <wlr/render/drm_syncobj.h>#include <wlr/render/swapchain.h>#include <wlr/render/wlr_texture.h>#include <wlr/types/wlr_buffer.h>#include <wlr/types/wlr_compositor.h>+#include <wlr/types/wlr_damage_ring.h>#include <wlr/types/wlr_output.h>#include <wlr/types/wlr_scene.h>#include <wlr/util/log.h>@@ -29,12 +32,6 @@ struct rediwm_output_renderer {struct rediwm_scene_renderer *pass;struct wl_array entries; // reusable scratch; no retained resource references};-struct output_view {- struct wlr_box logical;- int width, height, trans_width, trans_height;- float scale;- enum wl_output_transform transform;-};struct rediwm_output_renderer *rediwm_output_renderer_create(struct wlr_renderer *renderer) {struct rediwm_output_renderer *r = calloc(1, sizeof(*r));if (!r) return NULL;@@ -43,6 +40,9 @@ struct rediwm_output_renderer *rediwm_output_renderer_create(struct wlr_rendererwl_array_init(&r->entries);return r;}+bool rediwm_output_renderer_enable_shapes(struct rediwm_output_renderer *r) {+ return rediwm_scene_renderer_enable_shapes(r->pass);+}void rediwm_output_renderer_destroy(struct rediwm_output_renderer *r) {if (!r) return;rediwm_scene_renderer_destroy(r->pass);@@ -76,17 +76,68 @@ static struct wlr_box device_box(struct wlr_box box, const struct output_view *vreturn box;}static void device_region(pixman_region32_t *region, const struct output_view *v, bool expand) {- pixman_region32_translate(region, -v->logical.x, -v->logical.y);- wlr_region_scale(region, region, v->scale);- if (expand && floor(v->scale) != v->scale) wlr_region_expand(region, region, 1);- wlr_region_transform(region, region, wlr_output_transform_invert(v->transform),- v->trans_width, v->trans_height);+ output_view_region(region, v, expand);+}+// Which device corner each logical corner (tl, tr, br, bl) lands on, found by+// moving a one-pixel box in each corner of a small frame through the same+// transform device_box applies, so the two cannot disagree.+static void device_radii(float out[4], const float in[4], enum wl_output_transform transform) {+ enum { W = 3, H = 5 };+ const struct wlr_box corners[4] = {{0, 0, 1, 1}, {W - 1, 0, 1, 1}, {W - 1, H - 1, 1, 1}, {0, H - 1, 1, 1}};+ const int w = (transform & 1) ? H : W, h = (transform & 1) ? W : H;+ for (int i = 0; i < 4; i++) {+ struct wlr_box b;+ wlr_box_transform(&b, &corners[i], wlr_output_transform_invert(transform), W, H);+ out[b.x < w / 2 ? (b.y < h / 2 ? 0 : 3) : (b.y < h / 2 ? 1 : 2)] = in[i];+ }+}+// The pass's shape for a clip: the clip's box snapped in layout space like any+// item's, then taken to device pixels by the same function as the pieces that+// tile it, so the shape and the quads agree on every pixel column. A ring is+// whole device pixels, never thinner than one.+static void shape_for(struct rediwm_pass_shape *s, const struct rediwm_clip *c, const struct output_view *v) {+ const struct rediwm_snap f = rediwm_edges_snap(c->edges);+ s->box = device_box((struct wlr_box){f.x, f.y, f.width, f.height}, v);+ float radii[4];+ for (int i = 0; i < 4; i++) radii[i] = (float)(c->radii[i] * v->scale);+ device_radii(s->radii, radii, v->transform);+ s->border = c->border > 0 ? fmaxf(1.f, roundf((float)(c->border * v->scale))) : 0.f;+ for (int i = 0; i < 4; i++) s->border_color[i] = c->border_color[i];+}+// What of a clipped item may be drawn without the shape and without blending: the+// model's opaque cover, minus a margin around the edge where the ring is drawn.+// Layout space, like the item's own opaque region.+static void clip_cover(pixman_region32_t *out, const struct rediwm_clip *c, double scale) {+ pixman_region32_init(out);+ struct rediwm_snap parts[3];+ const int n = rediwm_clip_opaque(c, parts);+ for (int i = 0; i < n; i++)+ pixman_region32_union_rect(out, out, parts[i].x, parts[i].y, parts[i].width, parts[i].height);+ if (c->border > 0) {+ const struct rediwm_snap f = rediwm_edges_snap(c->edges);+ const int ring = (int)ceil(fmax(c->border, 1.0 / scale)) + 1;+ if (f.width > 2 * ring && f.height > 2 * ring)+ pixman_region32_intersect_rect(out, out, f.x + ring, f.y + ring, f.width - 2 * ring, f.height - 2 * ring);+ else+ pixman_region32_clear(out);+ }}struct collector {struct rediwm_output_renderer *renderer;const struct output_view *view;pixman_region32_t covered;+ // A window's items are contiguous and share one clip, so its cover is built+ // once for the run rather than for each of its six or so items.+ struct rediwm_clip cover_of;+ pixman_region32_t cover;+ bool has_cover;};+static bool same_clip(const struct rediwm_clip *a, const struct rediwm_clip *b) {+ if (a->edges.x1 != b->edges.x1 || a->edges.y1 != b->edges.y1 || a->edges.x2 != b->edges.x2 ||+ a->edges.y2 != b->edges.y2 || a->border != b->border) return false;+ for (int i = 0; i < 4; i++) if (a->radii[i] != b->radii[i]) return false;+ return true;+}static bool collect(const struct rediwm_item *item, struct wlr_scene_node *transport, void *data) {struct collector *collector = data;struct rediwm_output_renderer *r = collector->renderer;@@ -128,6 +179,17 @@ static bool collect(const struct rediwm_item *item, struct wlr_scene_node *trans}}if (full) pixman_region32_union_rect(&e->opaque, &e->opaque, s.x, s.y, s.width, s.height);+ if (item->clip) {+ // The corners are transparent and the ring is drawn by the shape: only+ // the interior may hide what is below or skip blending.+ if (!collector->has_cover || !same_clip(&collector->cover_of, item->clip)) {+ if (collector->has_cover) pixman_region32_fini(&collector->cover);+ clip_cover(&collector->cover, item->clip, collector->view->scale);+ collector->cover_of = *item->clip;+ collector->has_cover = true;+ }+ pixman_region32_intersect(&e->opaque, &e->opaque, &collector->cover);+ }pixman_region32_union(&collector->covered, &collector->covered, &e->opaque);return true;}@@ -178,7 +240,7 @@ static void sample(struct entry *e, struct wlr_scene_output *out, bool scanout)}static bool try_scanout(struct entry *e, struct wlr_scene_output *out,struct wlr_output_state *state, const struct output_view *v) {- if (e->item.kind != REDIWM_ITEM_SURFACE || !out->scene->private.direct_scanout ||+ if (e->item.clip || e->item.kind != REDIWM_ITEM_SURFACE || !out->scene->private.direct_scanout ||(state->committed & (WLR_OUTPUT_STATE_MODE | WLR_OUTPUT_STATE_ENABLED | WLR_OUTPUT_STATE_RENDER_FORMAT)) ||!wlr_output_is_direct_scanout_allowed(out->output)) return false;struct wlr_scene_buffer *b = wlr_scene_buffer_from_node(e->transport);@@ -232,46 +294,97 @@ static bool render_entry(struct entry *e, struct wlr_scene_output *out,struct wlr_render_pass *pass, const struct output_view *v, pixman_region32_t *damage) {struct wlr_box dst = device_box(e->box, v);if (misses_damage(&dst, damage)) return true;- pixman_region32_t clip, blend;+ pixman_region32_t clip, blend, core;pixman_region32_init(&clip);pixman_region32_init(&blend);+ pixman_region32_init(&core);pixman_region32_copy(&clip, &e->visible);device_region(&clip, v, true);pixman_region32_intersect(&clip, &clip, damage);bool ok = true;if (!pixman_region32_not_empty(&clip)) goto done;+ // A clipped item is drawn in two parts: `core` (its interior, which the model+ // proves fully covered and opaque) as before, without the shape, and the rest+ // (corners, ring, anything translucent) through the shape.+ struct rediwm_pass_shape shape;+ const bool shaped = e->item.clip != NULL;+ if (shaped) {+ shape_for(&shape, e->item.clip, v);+ pixman_region32_copy(&core, &e->opaque);+ device_region(&core, v, false);+ // One rectangle, deeper than the corner arcs and the ring. The model's cover+ // is a cross of up to three, which leaves about twelve scissored draws per+ // window for what a rim of a few shaded pixels costs far less than: draws+ // dominated the output build in a drag.+ float depth = fmaxf(fmaxf(shape.radii[0], shape.radii[1]), fmaxf(shape.radii[2], shape.radii[3]));+ const int inset = (int)ceilf(fmaxf(depth, shape.border)) + REDIWM_CLIP_OPAQUE_MARGIN;+ if (shape.box.width > 2 * inset && shape.box.height > 2 * inset)+ pixman_region32_intersect_rect(&core, &core, shape.box.x + inset, shape.box.y + inset,+ shape.box.width - 2 * inset, shape.box.height - 2 * inset);+ else+ pixman_region32_clear(&core);+ pixman_region32_intersect(&core, &core, &clip);+ pixman_region32_subtract(&clip, &clip, &core);+ }const struct rediwm_content *c = &e->item.content;if (e->item.kind == REDIWM_ITEM_RECT) {- wlr_render_pass_add_rect(pass, &(struct wlr_render_rect_options){.box = dst, .clip = &clip,- .color = {c->color[0], c->color[1], c->color[2], c->color[3]}});+ struct wlr_render_rect_options rect = {.box = dst,+ .color = {c->color[0], c->color[1], c->color[2], c->color[3]}};+ if (pixman_region32_not_empty(&core)) {+ rect.clip = &core;+ wlr_render_pass_add_rect(pass, &rect);+ }+ rect.clip = &clip;+ if (!shaped) wlr_render_pass_add_rect(pass, &rect);+ else if (pixman_region32_not_empty(&clip)) rediwm_scene_pass_add_rect_shaped(pass, &rect, &shape);} else {struct wlr_scene_buffer *b = wlr_scene_buffer_from_node(e->transport);if (b->private.is_single_pixel_buffer) {const uint32_t *color = b->private.single_pixel_buffer_color;// Match wlroots' single-pixel path during parity, including its// treatment of opacity (only alpha is multiplied there).- wlr_render_pass_add_rect(pass, &(struct wlr_render_rect_options){.box = dst, .clip = &clip,+ struct wlr_render_rect_options rect = {.box = dst,.color = {(float)color[0] / (float)UINT32_MAX, (float)color[1] / (float)UINT32_MAX,- (float)color[2] / (float)UINT32_MAX, (float)color[3] / (float)UINT32_MAX * c->opacity}});+ (float)color[2] / (float)UINT32_MAX, (float)color[3] / (float)UINT32_MAX * c->opacity}};+ if (pixman_region32_not_empty(&core)) {+ rect.clip = &core;+ wlr_render_pass_add_rect(pass, &rect);+ }+ rect.clip = &clip;+ if (!shaped) wlr_render_pass_add_rect(pass, &rect);+ else if (pixman_region32_not_empty(&clip)) rediwm_scene_pass_add_rect_shaped(pass, &rect, &shape);} else {struct wlr_texture *texture = buffer_texture(b, out->output->renderer);if (!texture) { ok = false; goto done; }- pixman_region32_copy(&blend, &e->opaque);- device_region(&blend, v, false);- pixman_region32_subtract(&blend, &clip, &blend);- wlr_render_pass_add_texture(pass, &(struct wlr_render_texture_options){+ struct wlr_render_texture_options t = {.texture = texture, .dst_box = dst, .src_box = c->src_box,.transform = wlr_output_transform_compose(wlr_output_transform_invert(c->transform), v->transform),- .clip = &clip, .alpha = &c->opacity, .filter_mode = c->filter_mode,- .blend_mode = pixman_region32_not_empty(&blend) ? WLR_RENDER_BLEND_MODE_PREMULTIPLIED : WLR_RENDER_BLEND_MODE_NONE,+ .alpha = &c->opacity, .filter_mode = c->filter_mode,.wait_timeline = b->private.wait_timeline, .wait_point = b->private.wait_point,- });+ };+ if (pixman_region32_not_empty(&core)) {+ t.clip = &core;+ t.blend_mode = WLR_RENDER_BLEND_MODE_NONE;+ wlr_render_pass_add_texture(pass, &t);+ }+ t.clip = &clip;+ if (shaped) {+ t.blend_mode = WLR_RENDER_BLEND_MODE_PREMULTIPLIED;+ if (pixman_region32_not_empty(&clip)) rediwm_scene_pass_add_texture_shaped(pass, &t, &shape);+ } else {+ pixman_region32_copy(&blend, &e->opaque);+ device_region(&blend, v, false);+ pixman_region32_subtract(&blend, &clip, &blend);+ t.blend_mode = pixman_region32_not_empty(&blend) ? WLR_RENDER_BLEND_MODE_PREMULTIPLIED : WLR_RENDER_BLEND_MODE_NONE;+ wlr_render_pass_add_texture(pass, &t);+ }}e->sampled = true;}done:pixman_region32_fini(&clip);pixman_region32_fini(&blend);+ pixman_region32_fini(&core);return ok;}bool rediwm_scene_output_build_state(struct rediwm_output_renderer *r,@@ -299,7 +412,9 @@ bool rediwm_scene_output_build_state(struct rediwm_output_renderer *r,rediwm_scene_output_damage_whole(out);struct collector collector = {.renderer = r, .view = &v};pixman_region32_init(&collector.covered);- if (!rediwm_projection_for_each_item(projection, true, collect, &collector)) {+ bool collected = rediwm_projection_for_each_item(projection, true, collect, &collector);+ if (collector.has_cover) pixman_region32_fini(&collector.cover);+ if (!collected) {pixman_region32_fini(&collector.covered);clear_entries(r);return false;diff --git a/src/scene_output.h b/src/scene_output.hindex 05a469f..1a65d2c 100644--- a/src/scene_output.h+++ b/src/scene_output.h@@ -9,6 +9,9 @@ struct wlr_render_pass;struct wlr_buffer;struct wlr_buffer_pass_options;struct rediwm_output_renderer *rediwm_output_renderer_create(struct wlr_renderer *);+// Builds the programs that draw rounded shapes (see scene_pass.h); false if they+// did not build, in which case no window may be given a shape.+bool rediwm_output_renderer_enable_shapes(struct rediwm_output_renderer *);void rediwm_output_renderer_destroy(struct rediwm_output_renderer *);// Node-subset capture uses the same drawing backend with its own swapchain// and ReadFence; it must not inherit output culling or screen geometry.diff --git a/src/scene_output.zig b/src/scene_output.zigindex 2bd94fc..27a03cf 100644--- a/src/scene_output.zig+++ b/src/scene_output.zig@@ -4,6 +4,8 @@ const Projection = @import("projection.zig").Projection;pub const Renderer = opaque {extern fn rediwm_output_renderer_create(renderer: *wlr.Renderer) ?*Renderer;pub const create = rediwm_output_renderer_create;+ extern fn rediwm_output_renderer_enable_shapes(renderer: *Renderer) bool;+ pub const enableShapes = rediwm_output_renderer_enable_shapes;extern fn rediwm_output_renderer_destroy(renderer: ?*Renderer) void;pub const destroy = rediwm_output_renderer_destroy;extern fn rediwm_scene_output_build_state(renderer: *Renderer, projection: *Projection, output: *wlr.SceneOutput, state: *wlr.Output.State) bool;diff --git a/src/scene_pass.c b/src/scene_pass.cindex 3a5aa7a..9973692 100644--- a/src/scene_pass.c+++ b/src/scene_pass.c@@ -171,10 +171,13 @@ static const char shaped_vertex[] ="vec2 d=abs(q)-(size*.5-vec2(rad));" \"return length(max(d,0.))+min(max(d.x,d.y),0.)-rad; }" \"float cov(float d){ return clamp(.5-d,0.,1.); }"-// A border is part of the same pass as its body: the body keeps the inside of the-// inset shape and the ring the rest, both evaluated at this fragment, so their-// coverages add up to the shape's. As two draws they would multiply, and a seam-// would show where each is partly covered.+// A border is part of the same pass as its body. The ring is composited OVER the+// body inside the shape and the result is scaled by the shape's coverage, which+// is what the border rects of the legacy path do (a translucent border, as the+// default theme has, tints the fill beneath it instead of replacing it). For an+// opaque ring this equals splitting the pixel into body and ring coverage that+// add up to the shape's, the spike's model. As two draws the coverages would+// multiply, and a seam would show where each is partly covered.//// `mode` 0 draws the texture, 1 the solid colour, 2 the shape's shadow: a// Gaussian-blurred copy of the shape, offset, approximated through its distance@@ -192,9 +195,8 @@ static const char shaped_fragment[] = SHAPED_HEAD"if(hide>.5)s*=1.-cov(sdf(local,radii)); gl_FragColor=color*s; return; }""vec4 c=color; if(mode<.5){ c=texture2D(tex,uv); if(opaque>.5)c.a=1.; c*=alpha; }""float d=sdf(local,radii);"- "float inner=border>0.?cov(d+border):cov(d);"- "float ring=border>0.?cov(d)-cov(d+border):0.;"- "gl_FragColor=c*inner+bcolor*ring; }";+ "float w=border>0.?1.-cov(d+border):0.;"+ "gl_FragColor=(c*(1.-bcolor.a*w)+bcolor*w)*cov(d); }";static GLuint shader(GLenum type, const char *prefix, const char *source) {GLuint id = glCreateShader(type);diff --git a/src/scene_pass.h b/src/scene_pass.hindex ea52442..287cf0e 100644--- a/src/scene_pass.h+++ b/src/scene_pass.h@@ -32,9 +32,11 @@ struct rediwm_pass_shape {// Top-left, top-right, bottom-right, bottom-left. A radius larger than half// the short side is capped to it.float radii[4];- // Width of the ring just inside the edge, drawn in `border_color` by the same- // fragment that draws the body, so the two add up to the shape's coverage- // exactly. 0 draws no ring.+ // Width of the ring just inside the edge. The same fragment that draws the body+ // composites the ring over it, then applies the shape's coverage, so a+ // translucent border tints the fill beneath it, as the legacy border rects do,+ // and an opaque one equals splitting the pixel between body and ring exactly.+ // 0 draws no ring.float border;float border_color[4]; // premultiplied};diff --git a/src/scene_pass_test.c b/src/scene_pass_test.cindex 3947cc3..4c4ad14 100644--- a/src/scene_pass_test.c+++ b/src/scene_pass_test.c@@ -543,7 +543,7 @@ struct window {static struct wlr_box box_of(struct rediwm_snap s) { return (struct wlr_box){s.x, s.y, s.width, s.height}; }static struct window make_window(float scale, float zoom, float radius, double border) {const struct rediwm_xform xf = {(double)scale * zoom, 8, 8};- const struct rediwm_clip_spec spec = {200, 140, {radius, radius, radius, radius}, border};+ const struct rediwm_clip_spec spec = {.width = 200, .height = 140, .radii = {radius, radius, radius, radius}, .border = border};struct window w = {.clip = rediwm_clip_resolve(xf, 30, 24, &spec)};w.shape.box = box_of(rediwm_edges_snap(w.clip.edges));for (int i = 0; i < 4; i++) w.shape.radii[i] = w.clip.radii[i];@@ -670,6 +670,18 @@ static void gate_border_partition(struct rediwm_scene_renderer *r, struct wlr_bu"row inside the border is not the body at scale %.2f zoom %.2f", SCALES[si], ZOOMS[zi]);check(at(img, ringed.box.x, ringed.box.y + ringed.box.height / 2)[0] >= 254,"left edge is not the border colour at scale %.2f zoom %.2f", SCALES[si], ZOOMS[zi]);+ // A translucent ring (the default theme's is 9% white) is composited over the+ // body, not in place of it: ring + body * (1 - alpha), per channel.+ const float faint[4] = {.09f, .09f, .09f, .09f};+ memcpy(ringed.border_color, faint, sizeof(faint));+ pass = begin_fill(r, buf, BG, NULL);+ piece(pass, &ringed, ringed.box, BODY, NULL);+ finish(pass);+ read_image(r, buf, img);+ for (int ch = 0; ch < 3; ch++)+ check(diff(at(img, cx, ringed.box.y)[ch], (int)lround(255 * (.09 + BODY[ch] * .91))) <= 1,+ "translucent ring is not over the body at scale %.2f zoom %.2f: channel %d is %d",+ SCALES[si], ZOOMS[zi], ch, at(img, cx, ringed.box.y)[ch]);}check(worst <= 2, "border + body differ from one shape by %d levels", worst);printf("PASS: border ring and body, in one pass, add up to exactly the shape's coverage (max diff %d)\n", worst);diff --git a/src/scene_view.h b/src/scene_view.hnew file mode 100644index 0000000..aeddc81--- /dev/null+++ b/src/scene_view.h@@ -0,0 +1,24 @@+// How a layout-space region maps onto one output's buffer. Shared by the owned+// output pass and by damage that has no view node to carry it.+#pragma once+#include <math.h>+#include <stdbool.h>+#include <pixman.h>+#include <wayland-server-protocol.h>+#include <wlr/util/box.h>+#include <wlr/util/region.h>+#include <wlr/util/transform.h>++struct output_view {+ struct wlr_box logical;+ int width, height, trans_width, trans_height;+ float scale;+ enum wl_output_transform transform;+};+static inline void output_view_region(pixman_region32_t *region, const struct output_view *v, bool expand) {+ pixman_region32_translate(region, -v->logical.x, -v->logical.y);+ wlr_region_scale(region, region, v->scale);+ if (expand && floor(v->scale) != v->scale) wlr_region_expand(region, region, 1);+ wlr_region_transform(region, region, wlr_output_transform_invert(v->transform),+ v->trans_width, v->trans_height);+}diff --git a/tests/capture.py b/tests/capture.pyindex 5da7c17..dcbe7a0 100644--- a/tests/capture.py+++ b/tests/capture.py@@ -56,6 +56,7 @@ def build_client(tmp):# toplevel handle and request a per-window capture source through# ext-image-capture-source-v1's foreign-toplevel manager.("ext-foreign-toplevel-list-v1", "staging/ext-foreign-toplevel-list/ext-foreign-toplevel-list-v1.xml"),+ ("xdg-decoration", "unstable/xdg-decoration/xdg-decoration-unstable-v1.xml"),):for mode, suffix in (("client-header", "client-protocol.h"), ("private-code", "protocol.c")):subprocess.run(["wayland-scanner", mode, str(protocols / path),@@ -193,6 +194,7 @@ def run_window_capture_case(client_binary):"""with tempfile.TemporaryDirectory(prefix="rediwm-window-capture-") as directory:tmp = Path(directory)+ owned = os.environ.get("REDIWM_TEST_SCENE_RENDERER") == "owned"compositor, log = spawn_compositor(tmp, scale="1", outputs="1", renderer=os.environ.get("REDIWM_TEST_RENDERER", "pixman"),config_content="[compositor]\nxwayland = false\n[animations]\nenabled = false\n",@@ -203,6 +205,8 @@ def run_window_capture_case(client_binary):socket_path = wait_for(lambda: next(tmp.glob("rediwm-*.sock"), None), "IPC unavailable")display = next(p.name for p in tmp.glob("wayland-*") if not p.name.endswith(".lock"))env = dict(os.environ, XDG_RUNTIME_DIR=str(tmp), WAYLAND_DISPLAY=display)+ if owned:+ env["CAPTURE_DECORATE"] = "1"with client_log.open("w") as output:client = subprocess.Popen([str(client_binary)], stdin=subprocess.PIPE,stdout=output, stderr=output, text=True, env=env)@@ -211,7 +215,11 @@ def run_window_capture_case(client_binary):win = wait_for(lambda: next((w for w in ipc.get_windows()if w["app_id"] == "rediwm.capture-fixture"), None),"capture-fixture toplevel did not map")- assert (win["width"], win["height"]) == (200, 150), win+ if owned:+ box = ipc.get_window_debug(win["id"])["client_box"]+ assert (box["width"], box["height"]) == (200, 150), (win, box)+ else:+ assert (win["width"], win["height"]) == (200, 150), winwait_for(lambda: "presented\n" in client_log.read_text(), "first frame not presented")before = client_log.read_text()@@ -256,6 +264,17 @@ def run_window_capture_case(client_binary):if fmt in (SHM_FORMAT_ARGB8888, DRM_FORMAT_ARGB8888, DRM_FORMAT_ABGR8888):assert a == 255, a+ if owned:+ # The window's rounded shape clips the client, so a captured window keeps+ # transparent bottom corners (premultiplied: black) and an intact interior.+ for cx in (0, buf_w - 1):+ r, g, b, a = sample(cx, buf_h - 1)+ assert (r, g, b) == (0, 0, 0), ("window capture corner is not transparent", cx, (r, g, b, a))+ if fmt in (SHM_FORMAT_ARGB8888, DRM_FORMAT_ARGB8888, DRM_FORMAT_ABGR8888):+ assert a == 0, ("window capture corner has alpha", cx, a)+ r, g, b, a = sample(20, buf_h - 20)+ assert (r, g, b) == (255, 0, 0), ("window capture interior near the corner", (r, g, b, a))+print(f"capture: window session returned real pixels at its own {buf_w}x{buf_h} "f"content size, not the monitor's (fmt={fmt:#x})")diff --git a/tests/capture_client.c b/tests/capture_client.cindex f47cd48..c269169 100644--- a/tests/capture_client.c+++ b/tests/capture_client.c@@ -13,6 +13,7 @@#include "linux-dmabuf-v1-client-protocol.h"#include "single-pixel-buffer-client-protocol.h"#include "viewporter-client-protocol.h"+#include "xdg-decoration-client-protocol.h"#include "xdg-shell-client-protocol.h"#include <assert.h>#include <drm/drm_fourcc.h>@@ -35,6 +36,7 @@ static struct wl_display *display;static struct wl_compositor *compositor;static struct wl_shm *shm;static struct xdg_wm_base *wm;+static struct zxdg_decoration_manager_v1 *decoration_manager;static struct wp_viewporter *viewporter;static struct wp_single_pixel_buffer_manager_v1 *pixel_mgr;static struct wl_output *output;@@ -150,6 +152,8 @@ static void global(void *data, struct wl_registry *registry, uint32_t id, const} else if (!strcmp(interface, "xdg_wm_base")) {wm = wl_registry_bind(registry, id, &xdg_wm_base_interface, 1);xdg_wm_base_add_listener(wm, &wm_listener, NULL);+ } else if (!strcmp(interface, "zxdg_decoration_manager_v1")) {+ decoration_manager = wl_registry_bind(registry, id, &zxdg_decoration_manager_v1_interface, 1);} else if (!strcmp(interface, "wp_viewporter")) {viewporter = wl_registry_bind(registry, id, &wp_viewporter_interface, 1);} else if (!strcmp(interface, "wp_single_pixel_buffer_manager_v1")) {@@ -469,6 +473,13 @@ int main(void) {struct xdg_toplevel *top = xdg_surface_get_toplevel(xdg);xdg_toplevel_add_listener(top, &top_listener, NULL);xdg_toplevel_set_app_id(top, fixture_app_id);+ // CAPTURE_DECORATE asks for server-side decorations, as an ordinary client would:+ // a captured window's rounded bottom corners belong to a decorated window.+ if (getenv("CAPTURE_DECORATE") && decoration_manager) {+ struct zxdg_toplevel_decoration_v1 *deco =+ zxdg_decoration_manager_v1_get_toplevel_decoration(decoration_manager, top);+ zxdg_toplevel_decoration_v1_set_mode(deco, ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE);+ }wl_surface_commit(surface);// Poll both fds, not a blocking fgets: the initial xdg_surface.configurediff --git a/tests/window_corners.py b/tests/window_corners.pyindex 9659fef..57ab0f2 100644--- a/tests/window_corners.py+++ b/tests/window_corners.py@@ -14,6 +14,12 @@ from ipc_client import IPCClient, spawn_compositor, stop_processfrom ui_driver import UIDriver+# The owned presenter clips the whole window with one shape (stage 4 of+# docs/plans/scene-graph.md): the client's corners are transparent and the frame+# has no skirt, its footer is the border. Select it with REDIWM_TEST_SCENE_RENDERER.+OWNED = os.environ.get("REDIWM_TEST_SCENE_RENDERER") == "owned"++def settings_resize(scale):"""The opaque body joins its skirt, and shadows follow shell resizes."""with tempfile.TemporaryDirectory(prefix="rediwm-settings-corners-") as directory:@@ -53,7 +59,15 @@ def settings_resize(scale):image = image.convert("RGB")x = round((box["x"] + box["width"] / 2) * scale)join = round((box["y"] + box["height"]) * scale)- for y in range(join - 3, join + 3):+ # Below the body the frame continues it for `footer` rows, the last+ # of which is the border: a skirt of 10 on the legacy presenter, the+ # border alone (1) when a shape clips the window.+ footer = frame["y"] + frame["height"] - (box["y"] + box["height"])+ assert footer == (1 if OWNED else 10), ("footer height", footer)+ # The ring is max(1, round(border * scale)) device pixels at the bottom+ # of the frame, so the body colour is certain only above it.+ ring = max(1, round(scale))+ for y in range(join - 3, join - ring + 1 if OWNED else join + 3):pixel = image.getpixel((x, y))assert pixel == (16, 18, 21), ("body/skirt seam", scale, width, height, y, pixel)for sx, sy in ((frame["x"] + frame["width"] + 5, box["y"] + box["height"] / 2),@@ -183,6 +197,104 @@ def workspace_focus(scale):log.close()+def frame_screenshot(scale, presenter):+ """One opaque window on a plain wallpaper, with a shadow, under one presenter."""+ # The harness reads the presenter from the environment when it writes the config.+ previous = os.environ.get("REDIWM_TEST_SCENE_RENDERER")+ os.environ["REDIWM_TEST_SCENE_RENDERER"] = presenter+ try:+ return _frame_screenshot(scale)+ finally:+ if previous is None:+ os.environ.pop("REDIWM_TEST_SCENE_RENDERER", None)+ else:+ os.environ["REDIWM_TEST_SCENE_RENDERER"] = previous+++def _frame_screenshot(scale):+ with tempfile.TemporaryDirectory(prefix="rediwm-frame-parity-") as directory:+ tmp = Path(directory)+ build_client(tmp)+ wallpaper = tmp / "wallpaper.png"+ Image.new("RGB", (64, 64), (48, 50, 56)).save(wallpaper)+ config = (+ f'[compositor]\nxwayland = false\nwallpaper = "{wallpaper}"\n'+ '[desktop]\nenabled = false\n[animations]\nreduced_motion = "on"\n'+ '[theme]\nshadow = "#00000060"\nshadow_size = 16\nradius_lg = 10\n'+ 'window_bg = "rgba(16,18,21,0.8)"\n'+ )+ process, log = spawn_compositor(+ tmp, scale=str(scale), config_content=config,+ renderer=os.environ.get("REDIWM_TEST_RENDERER", "pixman"),+ env_extra={"HOME": str(tmp), "DBUS_SESSION_BUS_ADDRESS": "", "REDIWM_NO_GLASS": "1",+ "REDIWM_THEME": str(tmp / "rediwm-config.toml")},+ )+ client = None+ try:+ with IPCClient(tmp) as ipc:+ ipc.wait_for("wallpaper_presented", timeout_ms=10000)+ display = next(p.name for p in tmp.glob("wayland-*") if not p.name.endswith(".lock"))+ live = tmp / "live"+ live.write_text("ff203040 400 260 Frame parity")+ with (tmp / "client.log").open("w") as client_log:+ client = subprocess.Popen(+ [str(tmp / "client")], stdout=client_log, stderr=client_log,+ env=dict(os.environ, XDG_RUNTIME_DIR=str(tmp), WAYLAND_DISPLAY=display,+ REDIWM_TEST_LIVE_FILE=str(live)))+ window = wait_for(lambda: next(iter(ipc.get_windows()), None), "window did not map")+ ipc.action("set_camera", {"x": 0, "y": 0})+ ipc.action("move_window_to", {"id": window["id"], "x": 80, "y": 80})+ ipc.move_cursor(20, 20)+ time.sleep(0.4)+ ipc.wait_for_frame()+ window = ipc.get_windows()[0]+ path = tmp / "frame.png"+ ipc.screenshot(path=str(path))+ with Image.open(path) as image:+ return image.convert("RGB"), window, ipc.get_window_debug(window["id"])+ finally:+ if client is not None:+ stop_process(client)+ stop_process(process)+ log.close()+++def frame_parity(scale):+ """A shape changes the corners and the bottom band and nothing else: the+ titlebar, the side borders, the client and the shadow match the legacy frame+ pixel for pixel, at every scale."""+ from PIL import ImageChops+ legacy, lwin, ldbg = frame_screenshot(scale, "legacy")+ owned, owin, odbg = frame_screenshot(scale, "owned")+ assert (lwin["x"], lwin["y"], lwin["width"]) == (owin["x"], owin["y"], owin["width"]), (lwin, owin)+ assert lwin["height"] - owin["height"] == 9, ("the frame is the radius shorter", lwin, owin)+ assert ldbg["client_box"] == odbg["client_box"], (ldbg["client_box"], odbg["client_box"])+ x, y, w, h = owin["x"], owin["y"], owin["width"], owin["height"]+ titlebar = odbg["titlebar_height"]+ arc = math.ceil(10 * scale) + 2+ def device(*box):+ return tuple(round(v * scale) for v in box)+ regions = {+ "titlebar band": (device(x, y, x + w, y + titlebar)[0] + arc, round(y * scale),+ device(x, y, x + w, y + titlebar)[2] - arc, round((y + titlebar) * scale)),+ "left titlebar edge below the arc": (round(x * scale), round(y * scale) + arc, round(x * scale) + 2, round((y + titlebar) * scale)),+ # The legacy border is a snapped rect whose width depends on where the edge falls on+ # the device grid (at 1.25 the right one is two pixels, the left one one); a shape's+ # ring is one uniform max(1, round(border * scale)). They agree on integer scales.+ "left and right side columns": (round(x * scale), round((y + titlebar) * scale),+ round((x + w) * scale) - (0 if scale == int(scale) else math.ceil(scale)),+ round((y + h) * scale) - arc),+ "shadow left of the window": (round((x - 14) * scale), round((y + 20) * scale),+ round(x * scale), round((y + h) * scale) - arc),+ "shadow above the window": (round((x + 20) * scale), round((y - 14) * scale),+ round((x + w - 20) * scale), round(y * scale)),+ }+ for name, box in regions.items():+ diff = ImageChops.difference(legacy.crop(box), owned.crop(box))+ assert diff.getbbox() is None, (name, scale, box, diff.getbbox(), diff.getextrema())+ print(f"PASS scale {scale}: titlebar, sides, client and shadow identical to the legacy frame")++def run(scale, background=(48, 50, 56), chrome_alpha=0.98):with tempfile.TemporaryDirectory(prefix="rediwm-corners-") as directory:tmp = Path(directory)@@ -245,6 +357,23 @@ def run(scale, background=(48, 50, 56), chrome_alpha=0.98):pixel = image.getpixel((column, row))assert all(abs(a - b) <= 2 for a, b in zip(pixel, expected)), ("side border fill", scale, hovered, column, row, pixel, expected)+ if OWNED:+ # One shape clips the client too: its bottom corners are+ # transparent, so the wallpaper shows there (no shadow here),+ # and a click on one reaches what is below. Interior+ # pixels next to the arc keep the client's colour.+ for cx, cy in ((x, y + h - 1), (x + w - 1, y + h - 1)):+ pixel = image.getpixel((round(cx * scale) if cx == x else round((cx + 1) * scale) - 1,+ round((cy + 1) * scale) - 1))+ assert all(abs(a - b) <= 3 for a, b in zip(pixel, background)), (+ "client corner is not transparent", scale, hovered, cx, cy, pixel)+ inward = 1 if cx == x else -1+ pixel = image.getpixel((round((cx + inward * 14) * scale), round((cy - 14) * scale)))+ assert pixel == (16, 18, 21), ("client interior near the corner", scale, pixel)+ hit = ipc.hit_test(cx + inward, cy - 1)+ assert hit["target_type"] == "none", ("click on a clipped corner stayed on the window", scale, hit)+ hit = ipc.hit_test(cx + inward * 30, cy - 30)+ assert hit["target_type"] == "window", ("client interior is not the window's", scale, hit)# Straight borders and the surrounding wallpaper# bound every colour in an antialiased corner. The old# straight-alpha interpolation overshot this by ~40 levels.@@ -276,6 +405,8 @@ def run(scale, background=(48, 50, 56), chrome_alpha=0.98):if __name__ == "__main__":for scale in (1, 1.25, 1.5, 2):+ if OWNED:+ frame_parity(scale)workspace_focus(scale)settings_resize(scale)run(scale)diff --git a/tests/xwayland.py b/tests/xwayland.pyindex 6c9d39a..168f208 100644--- a/tests/xwayland.py+++ b/tests/xwayland.py@@ -528,7 +528,8 @@ def test_native_scaling_managed_window(factor=2):# Surface pixels map back to logical client dimensions.dbg = request(sock, reader, {"version": 1, "command": 'get_window_debug', "params": {"id": wid}})["WindowDebug"]cbox = dbg["client_box"]- assert dbg["titlebar_height"] == 41, dbg+ # Native-scaled X11 chrome is drawn at density 0.75 of the default 46 px titlebar.+ assert dbg["titlebar_height"] == 35, dbg # 46 * 0.75 = 34.5, rounded half upassert cbox["width"] == math.ceil(400 / factor) and cbox["height"] == math.ceil(300 / factor), f"Unexpected client geometry at factor {factor}: {cbox}"# Focus window