Decouple scrolling translation from resize readiness

Track configure-owned presentation dependencies so independent viewport translation can continue while clients resize. Preserve linked reflow waits, native snapshots, handoff deadlines and shared rendering/input coordinates.

Closes #10.
This commit is contained in:
Samuel Onoja authored and GitHub committed 2026-10-04 08:05:44 +01:00
1 parent c1801e1f07
commit d5a829eb16
14 files changed
+1742 -72

No files matched your search

+122
View File
@@ -0,0 +1,122 @@
/* Controlled resize client: acknowledge immediately, attach only on command.
* Sync markers mean the server has processed the preceding ack/commit. */
#define _GNU_SOURCE
#include <poll.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <unistd.h>
#include <wayland-client.h>
#include "xdg-shell-client-protocol.h"
static struct wl_display *display;
static struct wl_compositor *compositor;
static struct wl_shm *shm;
static struct xdg_wm_base *wm;
static struct wl_surface *surface;
static struct xdg_surface *xdg;
static struct wl_buffer *buffer;
static int width = 64, height = 64, holding;
static uint32_t serial;
struct marker { const char *kind; uint32_t serial; int width, height; };
static void done(void *data, struct wl_callback *callback, uint32_t time) {
(void)time;
struct marker *m = data;
printf("%s %u %d %d\n", m->kind, m->serial, m->width, m->height);
fflush(stdout);
wl_callback_destroy(callback);
free(m);
}
static const struct wl_callback_listener sync_listener = {.done = done};
static void mark(const char *kind) {
struct marker *m = malloc(sizeof(*m));
if (!m) exit(3);
*m = (struct marker){kind, serial, width, height};
wl_callback_add_listener(wl_display_sync(display), &sync_listener, m);
}
static void attach(void) {
size_t bytes = (size_t)width * height * 4;
int fd = memfd_create("slow-resize", MFD_CLOEXEC);
if (fd < 0 || ftruncate(fd, bytes)) exit(3);
uint32_t *pixels = mmap(NULL, bytes, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (pixels == MAP_FAILED) exit(4);
for (size_t i = 0; i < bytes / 4; i++) pixels[i] = 0xff3182ce;
struct wl_shm_pool *pool = wl_shm_create_pool(shm, fd, bytes);
struct wl_buffer *next = wl_shm_pool_create_buffer(pool, 0, width, height,
width * 4, WL_SHM_FORMAT_XRGB8888);
wl_shm_pool_destroy(pool);
munmap(pixels, bytes);
close(fd);
if (buffer) wl_buffer_destroy(buffer);
buffer = next;
xdg_surface_set_window_geometry(xdg, 0, 0, width, height);
wl_surface_attach(surface, buffer, 0, 0);
wl_surface_damage(surface, 0, 0, width, height);
wl_surface_commit(surface);
mark("committed");
}
static void configure(void *data, struct xdg_surface *shell, uint32_t value) {
(void)data;
serial = value;
xdg_surface_ack_configure(shell, serial);
if (holding) mark("held"); else attach();
}
static const struct xdg_surface_listener surface_listener = {.configure = configure};
static void size(void *data, struct xdg_toplevel *top, int32_t w, int32_t h, struct wl_array *states) {
(void)data; (void)top; (void)states;
if (w > 0) width = w;
if (h > 0) height = h;
}
static void close_window(void *data, struct xdg_toplevel *top) {
(void)data; (void)top; exit(0);
}
static const struct xdg_toplevel_listener top_listener = {.configure = size, .close = close_window};
static void ping(void *data, struct xdg_wm_base *base, uint32_t value) {
(void)data; xdg_wm_base_pong(base, value);
}
static const struct xdg_wm_base_listener wm_listener = {.ping = ping};
static void global(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version) {
(void)data; (void)version;
if (!strcmp(interface, "wl_compositor")) compositor = wl_registry_bind(registry, name, &wl_compositor_interface, 4);
else if (!strcmp(interface, "wl_shm")) shm = wl_registry_bind(registry, name, &wl_shm_interface, 1);
else if (!strcmp(interface, "xdg_wm_base")) {
wm = wl_registry_bind(registry, name, &xdg_wm_base_interface, 1);
xdg_wm_base_add_listener(wm, &wm_listener, NULL);
}
}
static void removed(void *data, struct wl_registry *registry, uint32_t name) {
(void)data; (void)registry; (void)name;
}
static const struct wl_registry_listener registry_listener = {global, removed};
int main(int argc, char **argv) {
display = wl_display_connect(NULL);
if (!display) return 1;
wl_registry_add_listener(wl_display_get_registry(display), &registry_listener, NULL);
if (wl_display_roundtrip(display) < 0 || !compositor || !shm || !wm) return 2;
surface = wl_compositor_create_surface(compositor);
xdg = xdg_wm_base_get_xdg_surface(wm, surface);
xdg_surface_add_listener(xdg, &surface_listener, NULL);
struct xdg_toplevel *top = xdg_surface_get_toplevel(xdg);
xdg_toplevel_add_listener(top, &top_listener, NULL);
xdg_toplevel_set_app_id(top, argc > 1 ? argv[1] : "ferese.test.slow-resize");
xdg_toplevel_set_title(top, "Controlled slow resize");
wl_surface_commit(surface);
for (;;) {
if (wl_display_dispatch_pending(display) < 0 || wl_display_flush(display) < 0) return 5;
struct pollfd fds[] = {{wl_display_get_fd(display), POLLIN, 0}, {STDIN_FILENO, POLLIN, 0}};
if (poll(fds, 2, -1) < 0) return 6;
if (fds[0].revents && wl_display_dispatch(display) < 0) return 5;
if (fds[1].revents) {
char command;
if (read(STDIN_FILENO, &command, 1) != 1 || command == 'q') break;
if (command == 'h') { holding = 1; mark("holding"); }
if (command == 'c') attach();
}
}
if (buffer) wl_buffer_destroy(buffer);
wl_display_disconnect(display);
return 0;
}
@@ -0,0 +1,158 @@
"""Controlled ack/commit resize test on a disposable nested desktop.
FERESE_TEST_RESIZE=1 FERESE_TEST_BINARY=target/release/ferese \
FERESE_TEST_CTL=target/release/feresectl python3 scripts/tests/test_resize_dependencies_isolated.py
Requires a Wayland host, cc, pkg-config and wayland-scanner. This checks state
before the 300 ms deadline; it does not measure frame pacing or GPU performance.
"""
import json
import os
from pathlib import Path
import select
import subprocess
import tempfile
import time
import unittest
REPO = Path(__file__).resolve().parents[2]
@unittest.skipUnless(os.environ.get("FERESE_TEST_RESIZE") == "1", "opt-in nested test")
class ResizeDependencies(unittest.TestCase):
def test_independent_translation_before_resized_buffer(self):
processes = []
with tempfile.TemporaryDirectory(prefix="ferese-resize-") as directory:
root = Path(directory)
protocols = Path(subprocess.check_output(
["pkg-config", "--variable=pkgdatadir", "wayland-protocols"], text=True).strip())
xml = str(protocols / "stable/xdg-shell/xdg-shell.xml")
for kind, name in [("client-header", "xdg-shell-client-protocol.h"),
("private-code", "xdg-shell-protocol.c")]:
subprocess.run(["wayland-scanner", kind, xml, str(root / name)], check=True)
flags = subprocess.check_output(["pkg-config", "--cflags", "--libs", "wayland-client"], text=True).split()
subprocess.run(["cc", "-Wall", "-Wextra", "-Werror", "-I", str(root),
str(REPO / "scripts/tests/fixtures/slow-resize.c"),
str(root / "xdg-shell-protocol.c"), "-o", str(root / "client"), *flags], check=True)
runtime = root / "runtime"
runtime.mkdir(mode=0o700)
config = root / "config/ferese/config.kdl"
config.parent.mkdir(parents=True)
config.write_text('layout { inner-gap 0; outer-gap 0; }\n'
'theme { geometry { window-radius 0; border-width 0; focus-ring-width 0; }; }\n')
host = Path(os.environ["WAYLAND_DISPLAY"])
if not host.is_absolute():
host = Path(os.environ["XDG_RUNTIME_DIR"]) / host
env = dict(os.environ, XDG_RUNTIME_DIR=str(runtime), XDG_CONFIG_HOME=str(root / "config"),
XDG_STATE_HOME=str(root / "state"), WAYLAND_DISPLAY=str(host))
for key in ["WAYLAND_SOCKET", "FERESE_SOCKET", "FERESE_SHELL_CONTROL_SOCKET"]:
env.pop(key, None)
binary = REPO / os.environ.get("FERESE_TEST_BINARY", "target/debug/ferese")
ctl = REPO / os.environ.get("FERESE_TEST_CTL", "target/debug/feresectl")
with (root / "compositor.log").open("w") as log:
try:
compositor = subprocess.Popen([str(binary), "--backend=nested"], env=env, stdout=log, stderr=log)
processes.append(compositor)
deadline = time.monotonic() + 10
while not (runtime / "ferese/control.sock").exists():
if compositor.poll() is not None or time.monotonic() > deadline:
self.fail((root / "compositor.log").read_text())
time.sleep(.02)
socket = next(p for p in runtime.glob("wayland-*") if not p.name.endswith(".lock"))
client_env = dict(env, WAYLAND_DISPLAY=str(socket))
def call(*args):
return json.loads(subprocess.check_output([str(ctl), *args], env=env, timeout=5))
def action(*args):
subprocess.run([str(ctl), *args], env=env, check=True, capture_output=True, timeout=5)
def client(name):
process = subprocess.Popen([str(root / "client"), name], env=client_env,
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=log, bufsize=0)
processes.append(process)
return process
pending = {}
def marker(process, kind, timeout=5):
deadline = time.monotonic() + timeout
data = pending.pop(process.pid, b"")
while True:
while b"\n" in data:
line, data = data.split(b"\n", 1)
fields = line.decode().split()
if fields[0] == kind:
pending[process.pid] = data
return list(map(int, fields[1:]))
remaining = deadline - time.monotonic()
self.assertGreater(remaining, 0, f"missing {kind} marker")
ready, _, _ = select.select([process.stdout], [], [], remaining)
self.assertTrue(ready, f"missing {kind} marker")
chunk = os.read(process.stdout.fileno(), 4096)
self.assertTrue(chunk, (root / "compositor.log").read_text())
data += chunk
def windows(count):
deadline = time.monotonic() + 5
while time.monotonic() < deadline:
current = call("get-windows")
if len(current) == count and all(w["mapped"] for w in current):
return {w["app_id"]: w for w in current}
time.sleep(.02)
self.fail((root / "compositor.log").read_text())
first = client("ferese.test.first")
marker(first, "committed")
windows(1)
slow = client("ferese.test.slow")
marker(slow, "committed")
windows(2)
# Settle opening/focus motion before isolating one configure.
time.sleep(1)
slow.stdin.write(b"h")
marker(slow, "holding")
before = windows(2)
original = before["ferese.test.slow"]
started = time.monotonic()
action("resize", "right")
configured = marker(slow, "held", timeout=.25)
self.assertGreater(configured[1], original["capture_width"])
# The ack has reached the compositor; no new buffer exists.
action("focus", "left")
action("center-column")
moved = None
while time.monotonic() - started < .25:
current = windows(2)
observed_elapsed = time.monotonic() - started
if observed_elapsed >= .25:
break
a, b = current["ferese.test.first"], current["ferese.test.slow"]
if abs(a["x"] - before["ferese.test.first"]["x"]) >= 2:
moved = current
break
time.sleep(.005)
self.assertIsNotNone(moved, "viewport did not move before the resize deadline")
a, b = moved["ferese.test.first"], moved["ferese.test.slow"]
self.assertEqual(b["capture_width"], original["capture_width"])
self.assertEqual(b["width"], original["width"])
self.assertAlmostEqual(a["x"] - before["ferese.test.first"]["x"],
b["x"] - original["x"], delta=1)
slow.stdin.write(b"c")
committed = marker(slow, "committed")
self.assertEqual(committed[1:], configured[1:])
self.assertEqual(windows(2)["ferese.test.slow"]["capture_width"], configured[1])
print(f"nested: movement observed at {observed_elapsed * 1000:.1f} ms; "
"held raster/size; resized SHM commit (state check, not frame pacing)")
finally:
for process in reversed(processes):
if process.poll() is None:
process.terminate()
process.wait(timeout=5)
for stream in [process.stdin, process.stdout]:
if stream is not None:
stream.close()
if __name__ == "__main__":
unittest.main()