RediWM is a Wayland compositor written in Zig (OpenGL ES) that includes everything in one process
stage 4e: GLES2-only fixes the pixman test default hid
oxydizera35f78be758a
diff --git a/AGENTS.md b/AGENTS.mdindex 0581fcd..2936948 100644--- a/AGENTS.md+++ b/AGENTS.md@@ -22,30 +22,23 @@ 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 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). The shadow is analytic (`setTreeShadow` on `shadow_tree`,- drawn by the pass with the CPU shadow's smoothstep); its leaf, `shadow_fallback`- without a buffer, carries footprint, opacity and input only, and the projection- damages that footprint itself, since wlroots damages nothing for a bufferless view. 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 buffer- row; shm is premultiplied). Resample only on damage to that row or a- mapping change; pointer reuse proves nothing. `readFormat` stays memoized- per texture (it binds GL).+* **Window frames are shapes** (`docs/plans/scene-graph-stage4.md`).+ `Toplevel.applyShape` gives `frame_tree` one rounded clip carrying the ring+ colour (× window opacity); the pass composites the ring over the body, so+ something must be drawn under every ring pixel: the titlebar `ChromeBuffer`+ (a plain band) on top and the three `frame_fills` rects beside and below the+ client. The footer is `frame_border`. `shadow_tree`, the resize-grab tree and+ every xdg popup carry `setTreeUnclipped` (a new node that hangs outside the+ window needs it too). The shadow is analytic (`setTreeShadow` on+ `shadow_tree`, the CPU formula's smoothstep); its leaf `shadow_node` has no+ buffer and carries footprint, opacity and input only, so the projection+ damages that footprint itself. CSD windows have no shape and keep the+ `border_rects` 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))`.+ Without the shaped programs (`chrome.shapes` false) windows are square, with+ no ring or shadow.* **Buffer size ≠ scene size** at fractional scale (`round(len*s)` vs`round((off+len)*s)-round(off*s)`). Chrome/panel buffers filter bilinearly:never re-raster per device-grid phase (`ChromeBuffer.create` costs 2–8 ms).@@ -53,7 +46,7 @@ the one for the directory you work in: `src/files`, `src/editor`,`REDIWM_SCALE=1`, and debug visuals with IPC screenshots/buffer dumps, nothost `grim`. Brief vanishing after a startup scale mismatch is not a bug.* **GLES can NULL `wlr_scene_buffer.buffer`** after upload (the texture- stays): persist raster sizes; test with `REDIWM_TEST_RENDERER=gles2`.+ stays): persist raster sizes.* **Glass** samples `wlr_client_buffer_get(buffer)->texture` and trackssource-surface damage per effect. Empty commits and buffer rotation keep theblur. Drags may hold titlebar blur at ≥ 0.98 opacity (the default theme is@@ -71,11 +64,11 @@ the one for the directory you work in: `src/files`, `src/editor`,`wlr_output_commit_state`. `commitIsRedundant` skips commits with no damage,colour change, attach-render lock or cursor change; register anything newthere. Skipped frames get callbacks from `vblank_timer`, never immediately.- Build output state through `Server.buildOutputState`, including capture: it- selects the legacy or owned presenter and keeps one swapchain damage history.- The temporary `[compositor] scene_renderer = "owned"` requires GLES2 and a- restart. The owned pass reads graph geometry; scene nodes remain resource and- feedback transports until stage 6 (`docs/plans/scene-graph-stage3.md`).+ Build output state through `Server.buildOutputState`, including capture: the+ owned GLES2 pass is the only presenter (the session requires GLES2) and keeps+ one swapchain damage history. It reads graph geometry; scene nodes remain+ resource and feedback transports until stage 6+ (`docs/plans/scene-graph-stage3.md`).* **Shapes in the owned pass** (`scene_pass.h`): a window's rounded clip, ringand shadow are `rediwm_scene_pass_add_*_shaped` calls, device pixels, snapped bythe caller. The programs cost the driver about 430 KiB (a GL program costs@@ -143,7 +136,7 @@ the one for the directory you work in: `src/files`, `src/editor`,changes wait for a restart once X11 surfaces exist.* Units: `clientSurfaceGeometry()` X units; `clientGeometry()`,`requestSize()`, `commitPosition()` world units (`ceil(surface/N)`);- `applySizeClip()`, `probeClientEdge()` surface units; `surfaceScale()` = N.+ `applySizeClip()` surface units; `surfaceScale()` = N.Content trees use `rediwm_projection_set_tree_scale(1/N)`; X11 chromedensity is 0.75.* Clamp stale off-screen geometry of new X11 windows in@@ -155,7 +148,7 @@ the one for the directory you work in: `src/files`, `src/editor`,## Security, lock and login* **Greeter** (`rediwm --greeter`) never unlocks (only `rediwm-dm` decides),- writes nothing under `$HOME`, and runs no Xwayland, autostart, IPC,+ writes nothing under `$HOME` (it disables the GLES2 shader cache), and runs no Xwayland, autostart, IPC,notifications, tray, portal, polkit, services, audio, desktop orexternal-tool globals: skip anything new that owns a bus name, spawns orwrites (`tests/greeter.py`). Secrets stay in mlocked, wiped buffers.diff --git a/TESTING.md b/TESTING.mdindex 3e7d0fd..fea1e99 100644--- a/TESTING.md+++ b/TESTING.md@@ -41,39 +41,25 @@ compiler, `wayland-scanner` and wayland-protocols; D-Bus suites need PyGObject,Files-launching suite sets `REDIWM_FILES_DEVICES=0`. Do the same in new ones.- Files records opened files in shared recent history; set a scratch`XDG_DATA_HOME` in suites that open files so they never update the host's history.-- `REDIWM_TEST_RENDERER=gles2`: GPU rendering (needs a render node; pick one- with `WLR_RENDER_DRM_DEVICE=/dev/dri/renderD128` on multi-GPU machines).- GLES2 frees CPU scene buffers after upload, so `DumpBuffer` checks run on- pixman and GLES2 runs compare output screenshots instead.+- The compositor requires GLES2 (the owned output pass, stage 4e of+ `docs/plans/scene-graph-stage4.md`), so every suite runs on a render node:+ `ipc_client.py` sets `WLR_RENDER_DRM_DEVICE=/dev/dri/renderD128` when it is+ unset; suites that start the compositor without it need it in the environment+ on multi-GPU machines. Without a GPU use Mesa's llvmpipe+ (`WLR_RENDERER_ALLOW_SOFTWARE=1`). GLES2 frees CPU scene buffers after+ upload, so `DumpBuffer` reads only what the compositor still holds; compare+ output screenshots for pixels.- `REDIWM_TEST_SCALE=1.5` (or a `1.5` / `--scale 1.5` argument, per script):fractional scale. `REDIWM_TEST_OUTPUTS=2`: two outputs.-- `REDIWM_TEST_SCENE_RENDERER=owned` with `REDIWM_TEST_RENDERER=gles2`: select- 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`. 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 of- and under glass. Records instructions per committed frame, frame timers, RSS- and power conditions. Use a ReleaseSafe build and a render node; keep other- builds/tests stopped. Both counters and timers are enabled, so compare these- runs with each other, not the harness's `clean` mode. Read the saved results- with `--report /tmp/scene-cost.json`.-- `python3 tests/scene_ab.py --binary <measurement build>`: the stage 3 cost- gate. One compositor alternates the legacy and owned output presenters every- 32 frames, so both share clocks and thermal state; it reports legacy → owned- build CPU, build + commit and GPU time per scale and repaint and exits 1 if any- cell exceeds the tolerance (`--tolerance`, default +5 %). Needs a build with- `tests/scene_ab.patch` applied to a throwaway copy of the tree (the hook must- never ship); the docstring has the exact steps. Use it instead of the paired- mode for differences under about 10 %. Keep AC power and stop other work.+- `python3 tests/scene_baseline.py --out /tmp/scene-cost.json`: clean and stats+ sessions per scale (`--configs`), instructions, frame timers, RSS and power+ conditions; compare with `--report new.json --against old.json`. Use a+ ReleaseSafe build and a render node, keep other builds/tests stopped and AC+ power on. `--report` still reads the stages 3 and 4 "paired" results.- `REDIWM_*_PREVIEW=/tmp/...` (lock, greeter, OSD, settings, switcher, tray,notification): keep the compositor's own screenshots.- GLES2 at a fractional scale can differ by one level depending on render- history. Compare pixman or integer scales exactly, or allow one level.+ history. Compare integer scales exactly, or allow one level.## The IPC socket is the test harness@@ -110,12 +96,9 @@ 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; under-`REDIWM_TEST_SCENE_RENDERER=owned` it also runs `frame_parity` (titlebar, sides,-client bit-identical to the legacy frame at scales 1 to 2, the rightmost column-excepted on fractional scales; the analytic shadow, corners included, within 2-levels of the CPU one, apart from the legacy 9-slice's gap under the bottom arcs) and checks transparent client-corners and that a click on a clipped corner reaches the window below), `switcher.py`,+decorations, mode transitions, fullscreen and default/explicit gaps, 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/floatingdiff --git a/src/ipc/handlers.zig b/src/ipc/handlers.zigindex 55d23b0..c4e83a6 100644--- a/src/ipc/handlers.zig+++ b/src/ipc/handlers.zig@@ -1180,11 +1180,10 @@ fn handleAction(const buf = target_buf orelse return .{ .err = "BufferNotAttached" };var data_ptr: *anyopaque = undefined;var format: u32 = 0;- var stride: usize = 0;- if (!buf.beginDataPtrAccess(0, &data_ptr, &format, &stride)) {- return .{ .err = "BufferAccessDenied" };- }- buf.endDataPtrAccess();+ // A panel presented through its texture (`presentOwned`) is a client+ // buffer with no CPU mapping on GLES2; its raster is packed ARGB8888.+ var stride: usize = @as(usize, @intCast(buf.width)) * @sizeOf(u32);+ if (buf.beginDataPtrAccess(0, &data_ptr, &format, &stride)) buf.endDataPtrAccess();return .{ .ok = .{ .dump_buffer = .{.target = p.target,@@ -1223,6 +1222,9 @@ fn handleAction(.src_box = .{ .x = p.x, .y = p.y, .width = @intCast(p.width), .height = @intCast(p.height) },});if (!ok) return .{ .err = "ReadPixelsFailed" };+ // The reply is packed 0xAARRGGBB whatever the renderer prefers to read+ // (GLES2 reads ABGR8888, bytes R, G, B, A).+ for (pixels) |*pixel| pixel.* = packedArgb(format, pixel.*) orelse return .{ .err = "ReadPixelsFailed: unsupported read format" };return .{ .ok = .{ .sample_pixels = .{.output = std.mem.span(target_out.wlr_output.name),@@ -1848,6 +1850,30 @@ pub const PanelRegistryEntry = struct {resolve: *const fn (*Output) ?PanelRoot,};+/// One pixel read in a little-endian 32-bit DRM `format`, as 0xAARRGGBB.+fn packedArgb(format: u32, pixel: u32) ?u32 {+ const argb8888: u32 = 0x34325241;+ const xrgb8888: u32 = 0x34325258;+ const abgr8888: u32 = 0x34324241;+ const xbgr8888: u32 = 0x34324258;+ const swapped = (pixel & 0xff00ff00) | ((pixel & 0xff) << 16) | ((pixel >> 16) & 0xff);+ return switch (format) {+ argb8888 => pixel,+ xrgb8888 => pixel | 0xff000000,+ abgr8888 => swapped,+ xbgr8888 => swapped | 0xff000000,+ else => null,+ };+}++test "sampled pixels are reported as 0xAARRGGBB from every 8-bit read format" {+ try std.testing.expectEqual(@as(?u32, 0x80112233), packedArgb(0x34325241, 0x80112233));+ try std.testing.expectEqual(@as(?u32, 0xff112233), packedArgb(0x34325258, 0x00112233));+ try std.testing.expectEqual(@as(?u32, 0x80112233), packedArgb(0x34324241, 0x80332211));+ try std.testing.expectEqual(@as(?u32, 0xff112233), packedArgb(0x34324258, 0x00332211));+ try std.testing.expectEqual(@as(?u32, null), packedArgb(0, 0));+}+/// `dump_buffer` targets; the panel tags double as `Output` field names.const DumpTarget = enum {titlebar,diff --git a/src/main.zig b/src/main.zigindex 14ad7e5..8c7b9f8 100644--- a/src/main.zig+++ b/src/main.zig@@ -71,6 +71,8 @@ pub fn main(init: std.process.Init) void {}}+extern "c" fn setenv(name: [*:0]const u8, value: [*:0]const u8, overwrite: c_int) c_int;+fn start(init: std.process.Init) !bool {@import("startup.zig").initOrigin(init.minimal.environ);const theme_path = ui_theme.resolvePath(init.minimal.environ);@@ -78,6 +80,9 @@ fn start(init: std.process.Init) !bool {// `rediwm --greeter` is rediwm-dm's greeter: no IPC, no autostart, no// command, and the lock screen stays up until rediwm-dm starts a session.const greeter = argv.len >= 2 and std.mem.eql(u8, std.mem.span(argv[1]), "--greeter");+ // The greeter writes nothing under $HOME, and GLES2 drivers keep a shader+ // cache in ~/.cache. Compiling a handful of shaders per start costs little.+ if (greeter and setenv("MESA_SHADER_CACHE_DISABLE", "true", 0) != 0) return error.OutOfMemory;var server: Server = undefined;try server.init(