Skip to content

LordOS — a free, fast and secure GNU/Linux distribution based on Debian, with its own desktop environment: display server and Wayland compositor in C, a React UI engine on QuickJS, and private native apps.

Frame pipeline: auto mode lets go after an idle gap, JS frame callbacks once per frame shown; rebase follow-ups

Federico Pereira07ffe79fa7f6
diff --git a/CHANGELOG.md b/CHANGELOG.md
index be0c38b..a5fd008 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -291,7 +291,13 @@ of the matching [GitHub release](https://github.com/lordbasex/LordOS/releases),
drag frame cheaper on the Raspberry Pi). Every frame of `test_drag_exact` keeps its golden hash on the CPU and GPU
paths (VM 116, x86_64) through these steps. The golden hashes were written again twice, each time after a
pixel-by-pixel comparison with the code before: for the approved corner change of step 9 (its own entry below) and
- for the black-corner fix (Fixed). What the steps save was measured on the Pi 5 only all together (the first entry
+ for the black-corner fix (Fixed). A third time, on the GPU path only, when this work was rebased onto the
+ partial-repaint fixes (Fixed, "Partial repaints that left stale areas"): their rule that a blurred surface is
+ repainted with the margin its blur samples (`blur_near`) changed frame 0 of three runs (`neg`, `mix`, `k2mix`),
+ where the first dragged frame's damage reaches the menu bar's or the blurred panel's margin, and nothing else. With
+ that one rule reverted every one of the 2,417 hashes matched the old file; the CPU path's file is unchanged; those
+ three frames differ from a full repaint by at most 2 levels (1,596, 8,778 and 40,180 pixels; 1,532, 8,400 and
+ 38,099 before). What the steps save was measured on the Pi 5 only all together (the first entry
of this section).
- **No clear under the copy of what is below the window:** `paint_root_clear` (`ui/paint.c`) replaces
`canvas_clear` + `paint_root` in `main.c`, `app/appclient.c` and `engine-test`, and skips the clear when the drag
@@ -611,8 +617,11 @@ of the matching [GitHub release](https://github.com/lordbasex/LordOS/releases),
driver paced in software, or with several displays (each frame built and submitted at once there, as before).
- `LORD_PIPELINE`, read once at startup and named in the session log: `0` off (the previous behaviour exactly), `2`
always, unset (the default) on while frames are heavy: after 2 frames in a row whose CPU time passes 60 % of the
- period, off after 60 in a row under 40 % (`fpipe_note`; `-d` logs each change), because when frames already fit
- a prepared frame shows input one vblank later.
+ period, off after 60 in a row under 40 % or at the first frame after more than half a second without one
+ (`FPIPE_IDLE_MS`; an idle desktop gives no frames to count, and without this the pipeline stayed on through it, so
+ the first input after it was shown a vblank later; that frame counts as the first of the two heavy ones that
+ engage it again) (`fpipe_note`; `-d` logs each change), because when frames already fit a prepared frame shows
+ input one vblank later.
- The rules: what changes between a frame's paint and its submission goes into the next frame (the prepared one
is shown as a frame painted at that moment would have been; the cursor and a Linux app's new buffer are still
taken at submission). A prepare that paints nothing tries nothing more until the flip (no busy loop). A
@@ -627,7 +636,18 @@ of the matching [GitHub release](https://github.com/lordbasex/LordOS/releases),
built frame still has GPU drag's catch-up queued (it would run between that prepared frame's paint and its upload).
Direct scanout, the remote desktop's read-back, the protected windows' black, `LORD_GPU_VERIFY` and the -2
path are decided at submission by the same code. The Linux apps' frame callbacks go with a submitted frame,
- never with one only prepared.
+ never with one only prepared. The theme's JS frame callbacks run once per frame shown: a prepare that painted
+ nothing (`FPIPE_EMPTY`) had run them, and when they asked for another frame (an animation callback that changes
+ nothing while an app's frames or the cursor keep the display flipping) the frame built after that flip ran them
+ again, twice per frame shown; that frame now skips them and they run with the next one (`fpipe_hold_callbacks`,
+ `Out.prep_js`). A prepared frame that is undone, or GPU drag's rectangle painted again on the CPU, joins the next
+ frame's damage as a second frame's, so `paint_out` applies the blur rule again (`paint_damage_settle`).
+ Checked on VM 116 after these two fixes (and the rebase onto the partial-repaint fixes): `make -j8` with no
+ warnings; `fpipe-test` 59 checks (new: the idle gap, at and past `FPIPE_IDLE_MS`, re-engaging after it, `2` and
+ `0` ignoring it, a heavy drag then 2 s idle then a click; and a display flipping for an app on the GPU path
+ while an animation callback changes nothing: 600 callbacks for 599 frames shown with the pipeline off, 1,200
+ with it before the fix, 601 after); `engine-test` 6,907 checks, 0 failures; `lordbench-test` 1,217 ok;
+ `make test` 23 passed, 0 failed, 13 skipped. The pipeline itself still has not run on a display.
- LordBench records a prepared frame at its submission: its prepare's paint, its submission's upload, swap and
flip ioctl, both as `renderMs`, and a new `heldMs` (prepared → submitted) with a `prepared` count, in
`frames.phases` and the `drag (scripted):` line (`… prepared ahead N (held for the flip p50/p99)`); such a
diff --git a/docs/BENCHMARK.md b/docs/BENCHMARK.md
index 95735bf..b5da0cc 100644
--- a/docs/BENCHMARK.md
+++ b/docs/BENCHMARK.md
@@ -604,7 +604,8 @@ GPU drag's default is decided after that run: today it is on wherever its self-t
fit with the GPU's part in a 16.7 ms period while the next frame is started only after the flip. Now, while a flip
is pending, the next frame's CPU part (input, JS frame callbacks, layout, paint into the scene) is done ahead, and at
the flip only its upload, the GPU's draw and its flip are left (`docs/GPU.md`, "The frame pipeline"). On by
-default while frames are heavy (more than 60 % of the period, 2 frames in a row; off after 60 frames below 40 %),
+default while frames are heavy (more than 60 % of the period, 2 frames in a row; off after 60 frames below 40 %, or
+at the first frame after more than half a second without one, so an idle desktop answers its next input without it),
`LORD_PIPELINE=0` turns it off and `LORD_PIPELINE=2` keeps it on. Only with one display that has real page flips:
without a monitor, with a driver paced in software or with several displays nothing changes. Expected on the Pi
under the load: the frames shown every vblank instead of every other one as long as the CPU part stays under one
diff --git a/docs/GPU.md b/docs/GPU.md
index 14b2461..a2c5fcd 100644
--- a/docs/GPU.md
+++ b/docs/GPU.md
@@ -294,8 +294,11 @@ GPU and the CPU composition paths use it.
**The switch** `LORD_PIPELINE`, read once at startup (the session log says which): `0` off (exactly the previous
behaviour), `2` always, anything else (and unset, the default) *while frames are heavy*: on after 2 frames in a row
whose CPU time (JS frame callbacks, layout, paint, upload, swap and flip ioctl; for a prepared frame its prepare
-plus its submission) is above 60 % of the refresh period, off after 60 frames in a row below 40 % (`fpipe_note`;
-`-d` logs each change). The auto mode exists because the pipeline costs a frame of latency when frames already
+plus its submission) is above 60 % of the refresh period, off after 60 frames in a row below 40 %, or at the first
+frame after more than half a second without one (`FPIPE_IDLE_MS`: an idle desktop gives no frames to count, so
+before this the pipeline stayed on through it and the first input after it was shown a frame later; the frame that
+ends the gap counts as the first of the two heavy ones that engage it again) (`fpipe_note`; `-d` logs each change).
+The auto mode exists because the pipeline costs a frame of latency when frames already
fit: input that comes after a frame was prepared waits for the next one, shown a vblank later. When frames don't
fit, the latency stays about the same (input waits for at most one flip and is shown two vblanks after it, where
before the flips themselves came every other vblank) and the rate can double.
@@ -334,7 +337,16 @@ before the flips themselves came every other vblank) and the rate can double.
- **-2 (unshown)**, direct scanout of a fullscreen app, the remote desktop's read-back and the protected windows'
black: decided at submission, by the same code as before.
- **Frame callbacks and presentation:** the Linux apps' frame callbacks (`wl_frame_done`) go with a submitted frame,
- never with one only prepared; presentation feedback still follows the main display's flip events.
+ never with one only prepared; presentation feedback still follows the main display's flip events. The theme's JS
+ frame callbacks (`requestAnimationFrame`) run once per frame shown: in the frame's prepare, or in the frame built
+ after the flip. A prepare that painted nothing (`FPIPE_EMPTY`) still ran them; when they asked for another frame
+ (an animation callback that changed nothing, while an app's frames or the cursor kept the display flipping), the
+ frame built after that flip ran them again, so they ran twice per frame shown. That frame now skips them
+ (`fpipe_hold_callbacks`, `Out.prep_js`), and they run with the next one. With the pipeline off nothing is
+ prepared, so nothing changes there.
+- **Damage of two frames:** a prepared frame that is undone, and GPU drag's rectangle painted again on the CPU
+ (`gdrag_stale`, and its join in `paint_out`), join the next frame's damage like a frame gathered while a flip was
+ pending, so `paint_out` applies the blur rule again to them (`paint_damage_settle`, `docs/LAYERS.md`).
**LordBench's phases** (`docs/BENCHMARK.md`, "Frame phases") record a prepared frame at its submission:
`paintMs` is its prepare's, `uploadMs`, `swapMs` and `flipIoctlMs` its submission's, `renderMs` both, the new
diff --git a/docs/WINDOWS.md b/docs/WINDOWS.md
index 5c0072e..f78d5f2 100644
--- a/docs/WINDOWS.md
+++ b/docs/WINDOWS.md
@@ -174,7 +174,13 @@ wm.beginResize(id, edges) // edges as in xdg_toplevel.resize: 1 top, 2 botto
to this path and written again at the corner change above (from 001633b plus that change alone) and at
the black-corner fix (only the dragged window's corner squares and the Dock's and menu bar's backdrop
blur within reach of them changed, compared pixel by pixel first: 498,743 and 445,199 pixels in 2,386
- of 2,417 frames on the CPU path): a faster frame has to give exactly the same pixels. Before that rewrite every frame was compared pixel
+ of 2,417 frames on the CPU path), and once more, on the GPU path only, when `main`'s partial-repaint fixes
+ were merged under this work (0.8.6, `docs/LAYERS.md`: a blurred surface is repainted with the margin its blur
+ samples): frame 0 of three runs (`neg`, `mix`, `k2mix`), where the first dragged frame's damage reaches the
+ menu bar's or the blurred panel's margin, changed and nothing else; with that one rule reverted (`blur_near`)
+ all 2,417 hashes match the old file again, the CPU path's file is unchanged, and those three frames differ
+ from a full repaint by at most 2 levels (in 1,596, 8,778 and 40,180 pixels; 1,532, 8,400 and 38,099 before).
+ A faster frame has to give exactly the same pixels. Before that rewrite every frame was compared pixel
by pixel with the earlier code's: 178,634 pixels in 1,686 of 1,816 frames differed, all by one
level, inside a rounded `overflow: hidden` node's corner squares (`ceil(r) + 1` px) or within the
Dock's and menu bar's backdrop blur reach of one, and none moved away from a full repaint. The hashes
diff --git a/server/Makefile b/server/Makefile
index e04c057..83772ec 100644
--- a/server/Makefile
+++ b/server/Makefile
@@ -414,7 +414,7 @@ build/fpipe-test: tests/fpipe_test.c src/fpipe.c src/fpipe.h
$(CC) $(CPPFLAGS) $(CFLAGS) $(WARN) -std=c11 -o $@ tests/fpipe_test.c src/fpipe.c
./$@ || { rm -f $@; exit 1; }
# test_drag_exact's golden hashes for this architecture: only on the reference code (001633b plus
-# step 9 and the corners' restore on the drag layer), never to make a changed frame pass
+# step 9, the corners' restore on the drag layer and main's blur-margin repaint), never to make a changed frame pass
# (tests/engine_test.c, "The dragged window, pixel for pixel")
drag-golden: tests/engine_test.c $(ENGINE_SRC) src/outputs.c src/bench/lbinput.c build/obj/ui/stb.o $(HDR)
$(CC) $(CPPFLAGS) $(CFLAGS) $(WARN) -std=c11 -o build/engine-golden tests/engine_test.c $(ENGINE_SRC) src/outputs.c src/bench/lbinput.c build/obj/ui/stb.o -lm -lpthread
diff --git a/server/src/fpipe.c b/server/src/fpipe.c
index f4a9924..0b99cd9 100644
--- a/server/src/fpipe.c
+++ b/server/src/fpipe.c
@@ -8,8 +8,11 @@ void fpipe_init(FPipe *p, const char *env) {
p->mode = env && !strcmp(env, "0") ? FPIPE_OFF : env && !strcmp(env, "2") ? FPIPE_ALWAYS : FPIPE_AUTO;
}
-void fpipe_note(FPipe *p, double cpu_ms, double period_ms) {
+void fpipe_note(FPipe *p, double now_ms, double cpu_ms, double period_ms) {
if (p->mode != FPIPE_AUTO || period_ms <= 0) return;
+ int idle = p->last > 0 && now_ms - p->last > FPIPE_IDLE_MS;
+ p->last = now_ms;
+ if (idle) { p->on = 0; p->heavy = p->light = 0; }
if (!p->on) {
p->heavy = cpu_ms > period_ms * 0.6 ? p->heavy + 1 : 0;
if (p->heavy >= 2) { p->on = 1; p->heavy = p->light = 0; }
@@ -30,3 +33,5 @@ int fpipe_step(int eligible, int pending, int prep, int needs, int paint) {
}
int fpipe_blocked(int eligible, int pending, int prep) { return pending && (!eligible || prep != FPIPE_NONE); }
+
+int fpipe_hold_callbacks(int prep, int asked_again) { return prep == FPIPE_EMPTY && asked_again; }
diff --git a/server/src/fpipe.h b/server/src/fpipe.h
index 7d3a002..a5b011c 100644
--- a/server/src/fpipe.h
+++ b/server/src/fpipe.h
@@ -15,13 +15,19 @@ typedef struct {
int mode;
int on; /* auto: engaged */
int heavy, light; /* heavy frames in a row (to engage), light ones (to let go) */
+ double last; /* when the last frame was noted (ms; 0: none yet) */
} FPipe;
+/* A gap this long without a frame is an idle desktop: auto lets go at the next frame (fpipe_note). */
+#define FPIPE_IDLE_MS 500.0
void fpipe_init(FPipe *p, const char *env);
-/* after each frame the main display got: the CPU time it took (input excluded: JS frame callbacks,
- * layout, paint, the upload and the flip's submission) against the refresh period. Auto engages after
- * 2 frames in a row above 60 % of the period (where a frame plus the GPU's part stops fitting before
- * the next vblank) and lets go after 60 in a row below 40 %, like the paint threads (main.c). */
-void fpipe_note(FPipe *p, double cpu_ms, double period_ms);
+/* after each frame the main display got, at now_ms: the CPU time it took (input excluded: JS frame
+ * callbacks, layout, paint, the upload and the flip's submission) against the refresh period. Auto
+ * engages after 2 frames in a row above 60 % of the period (where a frame plus the GPU's part stops
+ * fitting before the next vblank) and lets go after 60 in a row below 40 %, like the paint threads
+ * (main.c), or when this frame came more than FPIPE_IDLE_MS after the last one: an idle desktop gives
+ * no frames to count, and the first change after it (a click, a key) is then shown without a frame of
+ * the pipeline's latency; heavy frames engage it again after 2 (this one counts as the first). */
+void fpipe_note(FPipe *p, double now_ms, double cpu_ms, double period_ms);
int fpipe_engaged(const FPipe *p);
/* A display's prepared frame */
@@ -46,5 +52,12 @@ int fpipe_step(int eligible, int pending, int prep, int needs, int paint);
* frame, and only one is prepared at a time): without the pipeline while its flip is pending, with it
* only once a frame is prepared (or was tried) for that flip. */
int fpipe_blocked(int eligible, int pending, int prep);
+/* The JS frame callbacks run once for each frame: in the frame's prepare when there is one, or in the
+ * frame built after the flip. A prepare that painted nothing (FPIPE_EMPTY) still ran them, and when they
+ * asked for another frame (asked_again: js_wants_frame() right after that prepare) the frame built after
+ * that flip must not run them again: they would run twice for one frame shown (an animation callback
+ * that changes nothing while an app's frames or the cursor keep the display flipping). 1: the render
+ * that follows the flip skips them (they run in the next one). */
+int fpipe_hold_callbacks(int prep, int asked_again);
#endif
diff --git a/server/src/main.c b/server/src/main.c
index 186fd04..861626f 100644
--- a/server/src/main.c
+++ b/server/src/main.c
@@ -171,6 +171,7 @@ typedef struct {
* against, checked before it is submitted (the scene's pixels, the GPU context and output, paint.c's GPU drag
* epoch); its CPU time so far and its phases for LordBench (main display) */
int prep, prep_whole, prep_gpu;
+ int prep_js; /* an FPIPE_EMPTY prepare ran the JS frame callbacks and they asked again (fpipe_hold_callbacks) */
Rect prep_r;
const uint32_t *prep_px;
unsigned prep_gen, prep_epoch;
@@ -228,8 +229,9 @@ static int box_empty(Box b) { return b.x1 <= b.x0 || b.y1 <= b.y0; }
static void gdrag_stale(Out *o) {
float x0, y0, x1, y1;
out_logical_box(&o->v, o->gdragw, &x0, &y0, &x1, &y1);
- if (box_empty(o->pend)) o->pl.n = 0;
+ if (box_empty(o->pend)) { o->pl.n = 0; o->pframes = 0; }
o->pend = box_join(o->pend, (Box){ x0, y0, x1, y1 });
+ o->pframes++; /* another frame's damage joins: paint_out settles the blur rule again */
o->gdrag_on = 0;
}
@@ -244,12 +246,14 @@ static void prep_undo(Out *o) {
else if (r.x1 > r.x0 && r.y1 > r.y0) {
float x0, y0, x1, y1;
out_logical_box(&o->v, r, &x0, &y0, &x1, &y1);
- if (box_empty(o->pend)) o->pl.n = 0;
+ if (box_empty(o->pend)) { o->pl.n = 0; o->pframes = 0; }
o->pend = box_join(o->pend, (Box){ x0, y0, x1, y1 });
+ o->pframes++; /* (as gdrag_stale) */
}
o->gdragtaken = 0;
}
o->prep = FPIPE_NONE;
+ o->prep_js = 0;
}
/* ---- the displays ---- */
@@ -1068,9 +1072,11 @@ static void remote_pinch(int phase, double scale, double rotation) { tp_route_pi
/* Layout and damage of the UI (once per frame, logical px). The damage goes to every display; each
* one paints it when its flip is not pending (paint_out), at its own scale. */
+/* render_frame: paint_ui skips the JS frame callbacks (hold); they ran in this render (ran) */
+static int ui_js_hold, ui_js_ran;
static Box paint_ui(Server *s) {
Box d = { 0, 0, 0, 0 };
- if (js_wants_frame()) js_frame(now_ms());
+ if (!ui_js_hold && js_wants_frame()) { js_frame(now_ms()); ui_js_ran = 1; }
if (!ui.dirty) return d;
ui.dirty = 0;
double t0 = now_ms();
@@ -1168,11 +1174,14 @@ static Rect paint_out(Server *s, Out *o, int index, int feed) {
o->pend = (Box){ 0, 0, 0, 0 };
o->gdragtaken = 0;
if (box_empty(b) || !o->scene.px) return r;
- /* GPU drag: the rectangle the GPU composed last frame is stale in the scene: painted again with this damage */
+ int joined = o->pframes > 1;
+ /* GPU drag: the rectangle the GPU composed last frame is stale in the scene: painted again with this damage
+ * (another frame's rectangle joined: the blur rule is settled again below) */
if (o->gdrag_on && !whole) {
float gx0, gy0, gx1, gy1;
out_logical_box(&o->v, o->gdragw, &gx0, &gy0, &gx1, &gy1);
b = box_join(b, (Box){ gx0, gy0, gx1, gy1 });
+ joined = 1;
}
/* several damaged rectangles (paint.c, "Several damaged rectangles"): each one painted on its
* own; r, what is presented, is the box around them (the scene keeps the pixels in between) */
@@ -1184,7 +1193,7 @@ static Rect paint_out(Server *s, Out *o, int index, int feed) {
else if (!whole) dlist_add(&l, b);
/* several frames' damage (a pending flip): joined rectangles, or an older frame's after a
* blurred node moved, may cut through a blurred node (paint_damage_settle) */
- if (!whole && o->pframes > 1) paint_damage_settle(&l);
+ if (!whole && joined) paint_damage_settle(&l);
if (!whole && l.n) {
b = l.r[0];
for (int k = 1; k < l.n; k++) b = box_join(b, l.r[k]);
@@ -1757,7 +1766,7 @@ static double out_period_ms(const Out *o) { return o->kms.mode.vrefresh ? 1000.0
/* a main display's frame for the pipeline's auto mode (fpipe_note); with -d its changes are logged */
static void pipe_note(const Server *s, double ms, const Out *o) {
int was = fpipe_engaged(&fpipe);
- fpipe_note(&fpipe, ms, out_period_ms(o));
+ fpipe_note(&fpipe, now_ms(), ms, out_period_ms(o));
if (s->debug && was != fpipe_engaged(&fpipe))
fprintf(stderr, "frames: pipeline %s (a frame took %.1f ms of %.1f)\n", was ? "off" : "on", ms, out_period_ms(o));
}
@@ -1770,7 +1779,11 @@ static void out_prepare(Server *s, Out *o, int i, const Out *feed, int is_main,
Rect r = out_paint(s, o, i, feed);
/* nothing painted: the frame is built after the flip as without the pipeline, and nothing more is tried
* before it (input waits for it as before, and a JS frame callback without damage does not spin) */
- if (r.x1 <= r.x0 || r.y1 <= r.y0) { o->prep = FPIPE_EMPTY; return; }
+ if (r.x1 <= r.x0 || r.y1 <= r.y0) {
+ o->prep = FPIPE_EMPTY;
+ o->prep_js = ui_js_ran && js_wants_frame(); /* (fpipe_hold_callbacks) */
+ return;
+ }
o->prep = FPIPE_READY;
o->prep_r = r;
o->prep_whole = whole;
@@ -1790,6 +1803,7 @@ static void out_submit(Server *s, Out *o, int i, const Out *feed, int is_main) {
uint64_t s0 = lbf_recording() ? mono_ns() : 0;
double t0 = now_ms();
o->prep = FPIPE_NONE;
+ o->prep_js = 0;
LbPhase *ph = is_main ? &o->pph : NULL;
out_present(s, o, i, o->prep_r, feed, ph);
if (!is_main) return;
@@ -1842,12 +1856,23 @@ static int render_frame(Server *s) {
}
double ui0 = now_ms();
uint64_t ui0_ns = lbf_recording() ? mono_ns() : 0;
+ /* the JS frame callbacks already ran for the frame built now, in a prepare that painted nothing during
+ * the flip (fpipe_hold_callbacks): not again; the ones they asked for run with the next frame */
+ ui_js_hold = ui_js_ran = 0;
+ if (!prep_only)
+ for (int i = 0; i < OUT_MAX; i++) {
+ Out *o = &s->out[i];
+ if (!o->on || o->kms.flip_pending) continue;
+ if (fpipe_hold_callbacks(o->prep, o->prep_js)) ui_js_hold = 1;
+ o->prep_js = 0;
+ }
paint_ui(s);
s->last_render = now_ms();
cursor_mark(s);
/* (not while every display waits for its flip: stopping the GPU sets the dumb buffer with a modeset, and a
* pending flip's buffer must stay; a frame prepared meanwhile is undone at the flip by cpu_takeover) */
if (!ready && !prep_only && cpu_switch(s)) paint_ui(s);
+ ui_js_hold = 0;
if (s->headless) {
Out *o = &s->out[0];
Rect drawn = paint_out(s, o, 0, 1);
diff --git a/server/tests/drag_golden_gpu.txt b/server/tests/drag_golden_gpu.txt
index efddf64..1589936 100644
--- a/server/tests/drag_golden_gpu.txt
+++ b/server/tests/drag_golden_gpu.txt
@@ -1,7 +1,8 @@
# engine-test test_drag_exact, gpu path: FNV-1a hash of every frame of the dragged window.
# Written by `make drag-golden` from 001633b plus step 9 (2026-10-28: the corners of rounded windows
# below the dragged one, 1 level, towards a full repaint) and the corners' restore on the drag layer
-# (no black squares outside the dragged window's rounded corners); later code must give the same
+# (no black squares outside the dragged window's rounded corners), and main's 0.8.6 blur-margin repaint
+# (blur_near: frame 0 of neg, mix and k2mix, rewritten at the rebase onto it); later code must give the same
# pixels. Lines: architecture, run, frame, hash.
x86_64 drag 0 16b358d6ecdc9df7
x86_64 drag 1 b48adda05df8c08f
@@ -728,7 +729,7 @@ x86_64 edge 57 a671c76ab2f68bbb
x86_64 edge 58 f7541d7022c202b4
x86_64 edge 59 e3db2c5f8a432e85
x86_64 edge 60 6c285a9ccaeb404f
-x86_64 neg 0 200885d230f0183e
+x86_64 neg 0 a61562f0fcc4f072
x86_64 neg 1 c11adafe5265ecd8
x86_64 neg 2 21b18aeaef2a2f54
x86_64 neg 3 90001bf3a5534539
@@ -1696,7 +1697,7 @@ x86_64 zraise 117 a99a86313a15bebe
x86_64 zraise 118 8c111073b4c93682
x86_64 zraise 119 b7dbfcad5f369c08
x86_64 zraise 120 d988d35c13563cc3
-x86_64 mix 0 9e700bfc95d09976
+x86_64 mix 0 e50b8d9ad83fbb64
x86_64 mix 1 2a86b1340ef8ea4a
x86_64 mix 2 b23a07aadd744b7a
x86_64 mix 3 2ea2c7866bcc13be
@@ -1937,7 +1938,7 @@ x86_64 mix 237 8a70ee56dd7a7c68
x86_64 mix 238 60ecf43e14b2825a
x86_64 mix 239 b9d37be1633c6291
x86_64 mix 240 4c4ea00d0f734222
-x86_64 k2mix 0 fd6b1e7771eb1239
+x86_64 k2mix 0 aec9b2b9f6fef494
x86_64 k2mix 1 cddacf466272e432
x86_64 k2mix 2 00b17e62cb42da53
x86_64 k2mix 3 fa73dad29b011126
diff --git a/server/tests/engine_test.c b/server/tests/engine_test.c
index f457b75..9125bb2 100644
--- a/server/tests/engine_test.c
+++ b/server/tests/engine_test.c
@@ -2181,7 +2181,8 @@ static int gold_write(const char *path, const char *variant, const uint64_t *has
fprintf(f, "# engine-test test_drag_exact, %s path: FNV-1a hash of every frame of the dragged window.\n"
"# Written by `make drag-golden` from 001633b plus step 9 (2026-10-28: the corners of rounded windows\n"
"# below the dragged one, 1 level, towards a full repaint) and the corners' restore on the drag layer\n"
- "# (no black squares outside the dragged window's rounded corners); later code must give the same\n"
+ "# (no black squares outside the dragged window's rounded corners), and main's 0.8.6 blur-margin repaint\n"
+ "# (blur_near: GPU path, frame 0 of neg, mix and k2mix); later code must give the same\n"
"# pixels. Lines: architecture, run, frame, hash.\n", variant);
size_t al = strlen(GOLD_ARCH);
for (const char *p = old; p && *p; ) {
diff --git a/server/tests/fpipe_test.c b/server/tests/fpipe_test.c
index a304827..d41f879 100644
--- a/server/tests/fpipe_test.c
+++ b/server/tests/fpipe_test.c
@@ -4,13 +4,17 @@
* - a display driven the way main.c drives it, on a vblank grid: a frame whose CPU part plus the GPU's
* part passes the period is shown every other vblank without the pipeline and at every vblank with
* it; a light frame is shown at every vblank either way; an idle display builds at once; nothing is
- * prepared twice for one flip (no busy loop). */
+ * prepared twice for one flip (no busy loop);
+ * - auto lets go after an idle gap (FPIPE_IDLE_MS without a frame);
+ * - the JS frame callbacks run once per frame shown, also when a prepare painted nothing. */
#include "fpipe.h"
#include <stdio.h>
#include <string.h>
static int fails, checks;
+static double clock_ms = 1000; /* the frames of test_mode/test_auto come one period apart */
+static void note(FPipe *p, double cpu_ms, double period_ms) { clock_ms += 16.67; fpipe_note(p, clock_ms, cpu_ms, period_ms); }
#define CHECK(c) do { checks++; if (!(c)) { fails++; fprintf(stderr, "%s:%d: CHECK(%s) failed\n", __FILE__, __LINE__, #c); } } while (0)
static void test_mode(void) {
@@ -19,12 +23,12 @@ static void test_mode(void) {
CHECK(p.mode == FPIPE_AUTO && !fpipe_engaged(&p));
fpipe_init(&p, "0");
CHECK(p.mode == FPIPE_OFF && !fpipe_engaged(&p));
- fpipe_note(&p, 30, 16.67); /* off stays off, however heavy */
- fpipe_note(&p, 30, 16.67);
+ note(&p, 30, 16.67); /* off stays off, however heavy */
+ note(&p, 30, 16.67);
CHECK(!fpipe_engaged(&p));
fpipe_init(&p, "2");
CHECK(p.mode == FPIPE_ALWAYS && fpipe_engaged(&p));
- fpipe_note(&p, 1, 16.67);
+ note(&p, 1, 16.67);
CHECK(fpipe_engaged(&p));
fpipe_init(&p, "1");
CHECK(p.mode == FPIPE_AUTO);
@@ -35,25 +39,25 @@ static void test_mode(void) {
static void test_auto(void) {
FPipe p;
fpipe_init(&p, NULL);
- fpipe_note(&p, 13, 16.67); /* one heavy frame: not yet */
+ note(&p, 13, 16.67); /* one heavy frame: not yet */
CHECK(!fpipe_engaged(&p));
- fpipe_note(&p, 5, 16.67); /* the run is broken */
- fpipe_note(&p, 13, 16.67);
+ note(&p, 5, 16.67); /* the run is broken */
+ note(&p, 13, 16.67);
CHECK(!fpipe_engaged(&p));
- fpipe_note(&p, 13, 16.67); /* two in a row above 60 % */
+ note(&p, 13, 16.67); /* two in a row above 60 % */
CHECK(fpipe_engaged(&p));
- for (int i = 0; i < 59; i++) fpipe_note(&p, 5, 16.67);
+ for (int i = 0; i < 59; i++) note(&p, 5, 16.67);
CHECK(fpipe_engaged(&p)); /* 59 light ones: still on */
- fpipe_note(&p, 8, 16.67); /* 48 %: neither light nor a reason to stay; the run restarts */
- for (int i = 0; i < 59; i++) fpipe_note(&p, 5, 16.67);
+ note(&p, 8, 16.67); /* 48 %: neither light nor a reason to stay; the run restarts */
+ for (int i = 0; i < 59; i++) note(&p, 5, 16.67);
CHECK(fpipe_engaged(&p));
- fpipe_note(&p, 5, 16.67); /* the 60th light frame in a row */
+ note(&p, 5, 16.67); /* the 60th light frame in a row */
CHECK(!fpipe_engaged(&p));
- fpipe_note(&p, 9, 16.67); /* 54 %: under 60 %, stays off */
- fpipe_note(&p, 9, 16.67);
+ note(&p, 9, 16.67); /* 54 %: under 60 %, stays off */
+ note(&p, 9, 16.67);
CHECK(!fpipe_engaged(&p));
- fpipe_note(&p, 13, 0); /* no period: ignored */
- fpipe_note(&p, 13, 0);
+ note(&p, 13, 0); /* no period: ignored */
+ note(&p, 13, 0);
CHECK(!fpipe_engaged(&p));
}
@@ -110,14 +114,14 @@ static Sim simulate(int mode, long cpu, long sub, long gpu, int animate, long n)
inflight_input = prep_input;
flip_at = ((t + busy + gpu) / P + 1) * P; /* the next vblank after the GPU is done */
pending = 1;
- fpipe_note(&fp, (double)(cpu + sub) / 1000, P / 1000.0);
+ fpipe_note(&fp, (double)t / 1000, (double)(cpu + sub) / 1000, P / 1000.0);
} else if (step == FPIPE_BUILD) {
busy += cpu + sub;
damage = 0;
inflight_input = input_t;
flip_at = ((t + busy + gpu) / P + 1) * P;
pending = 1;
- fpipe_note(&fp, (double)(cpu + sub) / 1000, P / 1000.0);
+ fpipe_note(&fp, (double)t / 1000, (double)(cpu + sub) / 1000, P / 1000.0);
}
/* then, like render_frame, the next frame may be painted ahead */
if (fpipe_step(fpipe_engaged(&fp), pending, prep, 0, damage) == FPIPE_PREPARE) {
@@ -157,11 +161,119 @@ static void test_sim(void) {
CHECK(idle.shown == 1 && idle.prepares == 0);
}
+/* Auto mode after an idle desktop: no frames come, so nothing counted the light ones; the first frame after a gap
+ * longer than FPIPE_IDLE_MS lets go (a heavy one counts as the first of the two that engage it again). */
+static void test_idle(void) {
+ FPipe p;
+ fpipe_init(&p, NULL);
+ fpipe_note(&p, 1000, 13, 16.67);
+ fpipe_note(&p, 1016.7, 13, 16.67);
+ CHECK(fpipe_engaged(&p));
+ fpipe_note(&p, 1416.7, 13, 16.67); /* 400 ms later: not idle */
+ CHECK(fpipe_engaged(&p));
+ fpipe_note(&p, 1916.7, 5, 16.67); /* exactly FPIPE_IDLE_MS later: not yet idle */
+ CHECK(fpipe_engaged(&p));
+ fpipe_note(&p, 2600, 5, 16.67); /* 683 ms without a frame: off at once, not after 60 light frames */
+ CHECK(!fpipe_engaged(&p) && p.light == 0 && p.heavy == 0);
+ fpipe_note(&p, 2616.7, 13, 16.67); /* heavy again: two in a row engage it, as from the start */
+ CHECK(!fpipe_engaged(&p));
+ fpipe_note(&p, 2633.4, 13, 16.67);
+ CHECK(fpipe_engaged(&p));
+ fpipe_note(&p, 5000, 13, 16.67); /* a heavy frame after a gap: off, and it is the first of two */
+ CHECK(!fpipe_engaged(&p) && p.heavy == 1);
+ fpipe_note(&p, 5016.7, 13, 16.67);
+ CHECK(fpipe_engaged(&p));
+ /* the gap restarts the light count too (the light frames before it are not carried over) */
+ for (int i = 0; i < 59; i++) fpipe_note(&p, 5100 + i * 16.67, 5, 16.67);
+ CHECK(fpipe_engaged(&p) && p.light == 59);
+ /* always and off ignore the gap */
+ fpipe_init(&p, "2");
+ fpipe_note(&p, 1000, 5, 16.67);
+ fpipe_note(&p, 9000, 5, 16.67);
+ CHECK(fpipe_engaged(&p));
+ fpipe_init(&p, "0");
+ fpipe_note(&p, 1000, 13, 16.67);
+ fpipe_note(&p, 1016.7, 13, 16.67);
+ fpipe_note(&p, 9000, 13, 16.67);
+ CHECK(!fpipe_engaged(&p));
+ /* a frame-by-frame run: a heavy drag engages it, the desktop goes idle for 2 s, then a light click: the
+ * click's frame lets go, so the next input waits for the flip as without the pipeline */
+ fpipe_init(&p, NULL);
+ double t = 1000;
+ for (int i = 0; i < 100; i++, t += 16.67) fpipe_note(&p, t, 13, 16.67);
+ CHECK(fpipe_engaged(&p));
+ t += 2000;
+ fpipe_note(&p, t, 4, 16.67);
+ CHECK(!fpipe_engaged(&p));
+ CHECK(fpipe_blocked(fpipe_engaged(&p), 1, FPIPE_NONE)); /* input during that frame's flip waits for it */
+}
+
+/* The JS frame callbacks against the frames shown: one display, light frames, an animation callback that never
+ * changes anything and always asks for the next frame, and an app on the GPU path that sends a new frame after each
+ * frame callback (so the display keeps flipping without UI damage). Driven like main.c's loop and render_frame:
+ * a render runs when the display is not waiting for its flip or a frame can be prepared; the callbacks run in it
+ * unless held (hold: fpipe_hold_callbacks; 0 simulates the code before the fix); a frame is built after the flip
+ * for the app; while the flip is pending the callbacks make a prepare, which paints nothing (FPIPE_EMPTY). */
+static void sim_callbacks(int mode, int hold, long n, long *shown, long *cbs) {
+ const long P = 16667, cpu = 2000, gpu = 2000;
+ FPipe fp;
+ fpipe_init(&fp, mode == FPIPE_OFF ? "0" : mode == FPIPE_ALWAYS ? "2" : NULL);
+ long t = 0, flip_at = -1;
+ int prep = FPIPE_NONE, prep_js = 0, app_new = 1;
+ *shown = *cbs = 0;
+ while (t < n * P) {
+ int pending = flip_at >= 0;
+ if (pending && t >= flip_at) { pending = 0; flip_at = -1; (*shown)++; }
+ int eligible = fpipe_engaged(&fp);
+ int ahead = fpipe_step(eligible, pending, prep, 0, 1) == FPIPE_PREPARE;
+ if (pending && !ahead) { t = flip_at; continue; }
+ int prep_only = pending, held = 0, ran = 0;
+ long busy = 0;
+ if (!prep_only) {
+ held = hold && fpipe_hold_callbacks(prep, prep_js);
+ prep_js = 0;
+ }
+ if (!held) { (*cbs)++; ran = 1; } /* the callback runs, changes nothing, asks again */
+ busy += cpu;
+ if (!pending && (fpipe_step(eligible, 0, prep, app_new, 0) == FPIPE_BUILD)) {
+ prep = FPIPE_NONE; /* (prep_undo) */
+ prep_js = 0;
+ flip_at = ((t + busy + gpu) / P + 1) * P;
+ pending = 1;
+ fpipe_note(&fp, (double)t / 1000, (double)busy / 1000, P / 1000.0);
+ }
+ if (fpipe_step(eligible, pending, prep, 0, prep_only) == FPIPE_PREPARE) {
+ prep = FPIPE_EMPTY; /* nothing to paint */
+ prep_js = ran; /* (the callback asked again) */
+ }
+ if (!prep_only) app_new = 1; /* wl_frame_done: the app sends its next frame at once */
+ t += busy;
+ }
+}
+
+static void test_callbacks(void) {
+ long shown, cbs;
+ sim_callbacks(FPIPE_OFF, 1, 600, &shown, &cbs);
+ CHECK(shown >= 598 && cbs >= shown && cbs <= shown + 1); /* once per frame shown */
+ long off_cbs = cbs;
+ sim_callbacks(FPIPE_ALWAYS, 0, 600, &shown, &cbs); /* before the fix: twice per frame */
+ CHECK(shown >= 598 && cbs >= 2 * shown - 1);
+ sim_callbacks(FPIPE_ALWAYS, 1, 600, &shown, &cbs); /* with it: once, as with the pipeline off */
+ CHECK(shown >= 598 && cbs >= shown && cbs <= shown + 2 && cbs <= off_cbs + 1); /* (+1: one prepared at the end) */
+ sim_callbacks(FPIPE_AUTO, 1, 600, &shown, &cbs); /* light frames: auto never engages */
+ CHECK(shown >= 598 && cbs == off_cbs);
+ /* the rule: only after a prepare that painted nothing and whose callbacks asked again */
+ CHECK(fpipe_hold_callbacks(FPIPE_EMPTY, 1));
+ CHECK(!fpipe_hold_callbacks(FPIPE_EMPTY, 0) && !fpipe_hold_callbacks(FPIPE_READY, 1) && !fpipe_hold_callbacks(FPIPE_NONE, 1));
+}
+
int main(void) {
test_mode();
test_auto();
test_step();
test_sim();
+ test_idle();
+ test_callbacks();
printf("fpipe-test: %d checks, %d failed\n", checks, fails);
return fails ? 1 : 0;
}