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.

Partial-repaint fixes found by a randomized full-repaint comparison (test_damage_fuzz, test_damage_pipeline): ancestor borders over an opaque cover child, transformed-subtree raster cache invalidation (Node.gen, nested signatures), a raster grid fixed to the node, raster kind changes damage the subtree, blur sampling margin repainted, damage gathered over several frames re-settled for blur; several damaged rectangles stay off by default; CHANGELOG, MONITOR, LAYERS

Federico Pereiraf083478db53e
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f4edaf8..6c1e008 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -221,6 +221,44 @@ of the matching [GitHub release](https://github.com/lordbasex/LordOS/releases),
older Pi 4 and Pi 5 kernel with `get_throttled` set, clear and "now"; both sources; a malformed value and a second
line; a Pi with neither; a machine that isn't a Pi with both files; 790 checks) and
`tests/sysinfo_model_test.mjs` (`piStatus`, 68 checks). `build/lordbench-test` still passes (1,198 checks).
+- **Partial repaints that left stale areas on screen** (the search for the 0.8.2 "grey rectangle", which keeps
+ several damaged rectangles off by default; `docs/MONITOR.md`, "0.8.6: the search for the grey rectangle"). Two new
+ `build/engine-test` suites compare every painted frame with a full repaint that bypasses the raster cache of
+ transformed subtrees (`paint_tf_nocache`, tests only): `test_damage_pipeline` runs the reported scene (Monitor's
+ moving map, a translucent, blurred Terminal minimized into the blurred Dock, the blurred menu bar, menus, the cursor)
+ through a copy of `main.c`'s whole bookkeeping (damage gathered while a page flip is pending, `paint_out`'s parts,
+ `present_cpu`'s per-buffer lists and copy, the cursor) with 0, 30 and 60 % of the flips pending, and checks every
+ presented buffer against the scene; `test_damage_fuzz` does the same with random trees and random changes (clipping,
+ rounded, shadows, translucent, blurred, scaled, rotated, faded, zIndex, hidden, moved, resized, re-parented,
+ destroyed). The double-buffer and cursor bookkeeping was right in every frame. The fuzz found seven bugs in the
+ paint engine, all with one box per frame **and** with several rectangles, each able to leave a wrong area until
+ something repainted it (before the fixes 11 of 12 seeds failed; now 1 of 48 in each mode, a single
+ 1-pixel row of 17 pixels, plus a few levels on antialiased edges in a second rare case, both described in the
+ test; the 12 seeds `make test` runs pass):
+ - a node's border is drawn over its children; when a partial repaint started from an opaque child (the opaque-cover
+ shortcut), the parent's border was skipped, so a child overflowing its parent lost the parent's border line where
+ a small rectangle fell (`paint_node`);
+ - a transformed subtree's cached raster stayed valid after a change made while the subtree was hidden or had scale 1,
+ and came back with the old content (each node now has a generation counter, `Node.gen`, bumped by
+ `node_invalidate`, in the subtree's signature, and the node's own style is compared every time);
+ - a transform inside another transform: changes inside the inner subtree never reached the outer raster's
+ signature, so the outer raster stayed cached with old content;
+ - the raster's pixel grid moved with the subtree's extent, so a child moving inside an unclipped scaled subtree
+ resampled every edge of it outside the damage (the grid is now fixed to the node);
+ - when a blur, a terminal or an app window came into or left a transformed subtree, its raster changed resolution or
+ kind and every pixel of it changed, but only the node that came or went was damaged (the whole subtree is now);
+ - a blurred surface repainted with only its own box read, outside the repainted area, the last frame's final
+ pixels, including whatever is painted above it (a sibling's shadow, a menu, a window's border), while a full
+ repaint blurs only what lies below: its edges kept the difference. The margin its blur samples (twice the radius)
+ is now repainted with it (`blur_near`, in `blur_walk` and the several-rectangles rule); in `test_multi_damage`
+ this raises the pixels repainted per frame from 24,078 to 27,363;
+ - a display whose flip was pending gathers several frames' rectangles and `dlist_add` joins the ones that overlap;
+ a join, or an older frame's rectangle after a blurred node moved, could cut through a blurred node, whose blur
+ then depended on where the cut fell. `paint_out` now applies the blur rule again to damage gathered over more than
+ one frame, on the tree as it is painted (`paint_damage_settle`).
+ Which of these was the 0.8.2 report is not proven (the reported scene itself never failed), so several rectangles
+ stay **off by default** (`LORD_DAMAGE=multi`); before turning them on, the 0.8.2 integration test is to be repeated
+ on a VM and the blur margin's cost measured. Built with `make -j8` (no warnings) and `make test` on VM 116.
- **The desktop under load** (found by LordBench's desktop test; `docs/BENCHMARK.md`, "The desktop under load"): the
compositor's cgroup (`server`) had the same `cpu.weight` as every app scope, and nice values don't count between
cgroups, so an app keeping every core busy took half of the compositor's CPU even at nice 19. On a Raspberry Pi 5
diff --git a/docs/LAYERS.md b/docs/LAYERS.md
index 1821be6..80f0c9e 100644
--- a/docs/LAYERS.md
+++ b/docs/LAYERS.md
@@ -108,6 +108,16 @@ touches a blurred surface or its margin grows to the whole surface, and every ot
touching that margin joins it, so a blur never reads a neighbour rectangle half painted
(`test_multi_damage` in `build/engine-test`, against a full repaint).
+Since 0.8.6 the margin is repainted together with the surface (`blur_near` in `paint.c`, used by
+`blur_walk` and by the several-rectangles rule). Outside the repainted area the screen holds the
+last frame's *final* pixels, so whatever is painted above the blurred surface and reaches into its
+margin (a sibling's shadow, a menu, the window's own border over a translucent Terminal) was
+blurred into the surface's edges, while a full repaint blurs only what lies below it; the
+difference stayed until the next full repaint. `test_damage_fuzz` in `build/engine-test` found it
+(random trees through lord-server's whole damage pipeline, every painted frame compared with a full
+repaint). The cost: a repaint that touches the Dock or the menu bar also repaints the band of twice
+the blur radius around it (about 41 px for a 20 px blur; the screen edges cut it).
+
| | |
|---|---|
| ![before](menubar-band-before.png) | ![after](menubar-band-after.png) |
diff --git a/docs/MONITOR.md b/docs/MONITOR.md
index a46fd75..c635812 100644
--- a/docs/MONITOR.md
+++ b/docs/MONITOR.md
@@ -832,6 +832,29 @@ path described here (with the clipped-subtree skip and the per-rectangle present
same switch). The measurements below are with it on. The 9×9 dot images and the map frame's opaque
color (below, "The Monitor's side") stay on.
+**0.8.6: the search for the grey rectangle (still off by default).** Two new `build/engine-test`
+suites compare every frame with a full repaint that bypasses the transformed subtrees' raster cache
+(`paint_tf_nocache`): `test_damage_pipeline` runs the reported scene (Monitor's moving map, a
+translucent, blurred Terminal minimized into a blurred Dock with the default theme's frame and
+`fxStyle` transform, a blurred menu bar, menus, title changes, the cursor) through a copy of
+`main.c`'s bookkeeping (each frame's rectangles gathered while a flip is pending, `paint_out`'s
+parts, `present_cpu`'s per-buffer lists and copy, the cursor), with 0, 30 and 60 % of the flips
+pending; it also checks every presented buffer against the scene. `test_damage_fuzz` does the same
+with random trees and random changes. The pipeline's double-buffer and cursor bookkeeping was
+right in every frame. The fuzz found seven engine bugs, all in **both** damage modes (one box or
+several), each able to leave a stale area until something repainted it, and all are fixed
+(CHANGELOG, 0.8.6): a parent's border lost where an opaque child started a partial repaint; cached
+rasters of transformed subtrees kept after a change made while hidden, unscaled or inside a nested
+transform; a raster grid that moved with the subtree's extent; a raster changing kind (a blur
+coming in) outside the damage; blurs taking in what is painted above them from outside the
+repainted area; and several frames' rectangles cutting through a blurred node. Which one the 0.8.2
+report was is not proven (the reported scene itself never failed), so `LORD_DAMAGE=multi` is still
+needed to turn the several-rectangles path on. Before turning it on by default: repeat the 0.8.2
+integration test on a VM with `LORD_DAMAGE=multi` (minimize a Terminal over the animating map at
+least 20 times, screenshots after each), and measure the cost of the blur fix (the margin of a
+blurred surface is now repainted with it: in `test_multi_damage` the pixels repainted per frame
+went from 24,078 to 27,363).
+
VM 119: 4 vCPU Xeon Silver 4108 at 1.8 GHz, `virtio` GPU without 3D, CPU compositing, 1280×800.
Network tab in front, ten slow downloads to mirrors in ten countries (arcs to 8–11 countries, about
20 moving dots). `lord-server` (whole process, % of one core), 5 × 30 s each, the same session
diff --git a/server/src/main.c b/server/src/main.c
index e9bd249..2e1afcc 100644
--- a/server/src/main.c
+++ b/server/src/main.c
@@ -109,6 +109,7 @@ typedef struct {
uint32_t *frame; /* rotated displays and the capture view: scene + fullscreen + cursor */
Box pend; /* logical damage not painted on it yet (its flip was pending) */
DamageList pl; /* the same as separate rectangles (paint_damage_rects); pend is their box */
+ int pframes; /* how many frames' damage pend holds (more than one: a flip was pending) */
int full; /* paint all of it next time */
int cdirty, cur_on; /* the cursor moved since it was presented; it was drawn on it */
/* CPU path: each KMS buffer only gets what changed since it was last drawn into (what was
@@ -1000,9 +1001,10 @@ static Box paint_ui(Server *s) {
for (int i = 0; i <= OUT_MAX; i++) {
Out *o = i < OUT_MAX ? &s->out[i] : &s->cap;
if (i < OUT_MAX && !o->on) continue;
- if (box_empty(o->pend)) o->pl.n = 0;
+ if (box_empty(o->pend)) { o->pl.n = 0; o->pframes = 0; }
for (int k = 0; k < nr; k++) dlist_add(&o->pl, rs[k]);
o->pend = box_join(o->pend, d);
+ o->pframes++;
}
}
ui.layout_ms = t1 - t0;
@@ -1026,11 +1028,23 @@ static Rect paint_out(Server *s, Out *o, int index, int feed) {
Box lb = o->pl.n ? o->pl.r[0] : (Box){ 0, 0, 0, 0 };
for (int k = 1; k < o->pl.n; k++) lb = box_join(lb, o->pl.r[k]);
int multi = !whole && o->pl.n > 1 && !gpu_active() && lb.x0 == b.x0 && lb.y0 == b.y0 && lb.x1 == b.x1 && lb.y1 == b.y1;
- int nparts = multi ? o->pl.n : 1;
+ DamageList l = { .n = 0 };
+ if (multi) l = o->pl;
+ 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 && l.n) {
+ b = l.r[0];
+ for (int k = 1; k < l.n; k++) b = box_join(b, l.r[k]);
+ }
+ multi = !whole && !gpu_active() && l.n > 1;
+ int nparts = multi ? l.n : 1;
Box parts[DAMAGE_MAX];
- if (multi) memcpy(parts, o->pl.r, sizeof(Box) * (size_t)nparts);
+ if (multi) memcpy(parts, l.r, sizeof(Box) * (size_t)nparts);
else parts[0] = b;
o->pl.n = 0;
+ o->pframes = 0;
double t0 = now_ms(), px = 0;
view_of(o, index);
for (int k = 0; k < nparts; k++) {
diff --git a/server/src/ui/node.c b/server/src/ui/node.c
index 8caf002..8c37f70 100644
--- a/server/src/ui/node.c
+++ b/server/src/ui/node.c
@@ -120,6 +120,7 @@ void node_moved(Node *n) {
void node_invalidate(Node *n) {
n->paint_dirty = 1;
+ n->gen++;
if (n->s.ext) n->s.ext->r.ok = 0;
if (n->type == NODE_RAW && n->parent) n->parent->paint_dirty = 1;
invalidate_measure(n);
diff --git a/server/src/ui/paint.c b/server/src/ui/paint.c
index ab37e45..c54470b 100644
--- a/server/src/ui/paint.c
+++ b/server/src/ui/paint.c
@@ -45,6 +45,7 @@ static int paint_cull; /* paint_node may skip clipped subtrees
static int layer_paint(Canvas *c, Node *n, float opacity);
static int tf_paint(Canvas *c, Node *n, float opacity);
static int tf_self, tf_unit; /* the transformed node being rasterized; the one painted at opacity 1 */
+int paint_tf_nocache; /* tests: transformed subtrees rasterized again, the cache untouched */
static float max4(const float r[4]) { return fmaxf(fmaxf(r[0], r[1]), fmaxf(r[2], r[3])); }
@@ -159,6 +160,12 @@ children:;
for (int i = 0; i < k; i++) paint_node(c, kids[i], op);
}
canvas_set_clip(c, old_clip);
+ /* The border goes over the children. A partial repaint that starts from a node inside this
+ * subtree (the opaque cover, a video) reached it among the children: the border is above it,
+ * so it is painted (before 0.8.6 it was skipped, and a child that overflows its parent lost
+ * the parent's border line where a small damaged rectangle fell; engine-test
+ * test_damage_fuzz). */
+ if (!own && skip_until && skip_reached) own = 1;
if (own && plain && bw > 0 && (s->border_color >> 24))
PROF(5, canvas_rrect_stroke(c, x, y, w, h, rad, bw * k, with_opacity(s->border_color, op)));
@@ -296,18 +303,30 @@ static int tf_paint(Canvas *c, Node *n, float opacity) {
if (!n->s.overflow_hidden) b = sub;
float kr = live ? paint_view.k : paint_view.k * tf_step(sc);
const int pad = 1; /* a transparent edge: antialiased borders */
+ /* The raster's pixel grid is fixed to the node (whole raster pixels from its corner), not to the
+ * bounds: a child that moves changes the bounds, and a grid that moved with them resampled every
+ * edge of the subtree a fraction of a pixel away, outside the damage of the child that moved
+ * (0.8.6, engine-test test_damage_fuzz). */
int w, h;
+ float gx0, gy0;
for (;;) {
- w = (int)ceilf((b.x1 - b.x0) * kr) + 2 * pad;
- h = (int)ceilf((b.y1 - b.y0) * kr) + 2 * pad;
+ gx0 = floorf((b.x0 - n->ax) * kr);
+ gy0 = floorf((b.y0 - n->ay) * kr);
+ w = (int)(ceilf((b.x1 - n->ax) * kr) - gx0) + 2 * pad;
+ h = (int)(ceilf((b.y1 - n->ay) * kr) - gy0) + 2 * pad;
if (w <= 0 || h <= 0) return 1;
if ((size_t)w * h <= TF_MAX_PX || kr < 0.05f) break;
kr *= 0.7f;
}
if ((size_t)w * h > TF_MAX_PX) return 0;
- TfLayer *e = tf_slot(n->id, kr);
+ /* paint_tf_nocache (tests): a raster of its own per nesting level, the cache untouched */
+ static TfLayer scratch[8];
+ static int depth;
+ if (paint_tf_nocache && depth >= 8) return 0;
+ TfLayer *e = paint_tf_nocache ? &scratch[depth] : tf_slot(n->id, kr);
+ if (paint_tf_nocache) e->valid = 0;
e->used = ++tf_tick;
- float ox = b.x0 - n->ax - pad / kr, oy = b.y0 - n->ay - pad / kr;
+ float ox = (gx0 - pad) / kr, oy = (gy0 - pad) / kr;
if (!e->valid || live || e->w != w || e->h != h || fabsf(e->ox - ox) > 0.01f || fabsf(e->oy - oy) > 0.01f) {
if ((size_t)w * h > e->cap) {
uint32_t *px = realloc(e->px, (size_t)w * h * 4);
@@ -324,7 +343,9 @@ static int tf_paint(Canvas *c, Node *n, float opacity) {
int ks = skip_until, kr_self = tf_self, ku = tf_unit;
skip_until = 0;
tf_self = tf_unit = n->id;
+ depth++;
paint_node(&rc, n, 1);
+ depth--;
skip_until = ks; tf_self = kr_self; tf_unit = ku;
paint_view = keep;
tf_norm(&n->s, &e->st, &e->xst);
@@ -351,8 +372,19 @@ void paint_tf_stats(long *renders, long *composites) {
}
/* damage_walk: the geometry of a transformed subtree (each node's box relative to its parent) and
- * whether a style or text changed in it; the node's own transform and opacity don't count. */
-typedef struct { uint64_t h; int dirty; } TfSig;
+ * whether a style or text changed in it; the node's own transform and opacity don't count.
+ * A change is seen by the walk only once (paint_dirty is cleared), and the walk only checks a
+ * subtree while it is visible and transformed: a change made while it was hidden, or while its
+ * scale was 1, left a raster cached for that node valid, and it came back with the old content
+ * when the subtree was shown or scaled again (0.8.6, engine-test test_damage_fuzz). So the
+ * signature also holds every descendant's generation (Node.gen, bumped by node_invalidate and
+ * never cleared), and the node's own style is compared every time. */
+typedef struct {
+ uint64_t h;
+ int dirty;
+ int live; /* what tf_bounds decides the raster by: 1 live (blur, terminal, app window), 2 not rasterized (video) */
+ Box area; /* the subtree on screen (the nodes' visible boxes) */
+} TfSig;
static TfSig *walk_sig;
static void sig_mix(TfSig *g, const void *p, size_t len) {
@@ -364,6 +396,7 @@ static void sig_node(TfSig *g, const Node *n, int self) {
float f[6] = { self ? 0 : n->x, self ? 0 : n->y, n->w, n->h, self ? 0 : n->s.translate_x, self ? 0 : n->s.translate_y };
sig_mix(g, f, sizeof f);
sig_mix(g, &n->id, sizeof n->id);
+ if (!self) sig_mix(g, &n->gen, sizeof n->gen); /* its own: compared as a style (tf_check) */
if (!self && n->own_tf) {
float t[3] = { n->s.ext->scale_x, n->s.ext->scale_y, n->s.ext->rotate };
sig_mix(g, t, sizeof t);
@@ -376,7 +409,7 @@ static void tf_check(Node *n, const TfSig *g) {
TfLayer *e = &tfl[i];
if (e->node != n->id) continue;
int changed = g->dirty || e->sig != g->h;
- if (!changed && n->paint_dirty) {
+ if (!changed) {
Style st;
StyleExt xst;
tf_norm(&n->s, &st, &xst);
@@ -683,8 +716,18 @@ static Box box_and(Box a, Box b) {
return r.x1 > r.x0 && r.y1 > r.y0 ? r : (Box){0, 0, 0, 0};
}
+static Box box_or(Box a, Box b) {
+ if (a.x1 <= a.x0 || a.y1 <= a.y0) return b;
+ if (b.x1 <= b.x0 || b.y1 <= b.y0) return a;
+ return (Box){ fminf(a.x0, b.x0), fminf(a.y0, b.y0), fmaxf(a.x1, b.x1), fmaxf(a.y1, b.y1) };
+}
+
static void damage_walk(Node *n, int parent_dirty, int visible, int in_layer, Box clip) {
- if (n->type == NODE_RAW) { n->paint_dirty = 0; return; }
+ if (n->type == NODE_RAW) {
+ if (walk_sig && visible) sig_mix(walk_sig, &n->gen, sizeof n->gen); /* the text, for a cached raster */
+ n->paint_dirty = 0;
+ return;
+ }
int vis = visible && !n->s.display_none;
int dirty = parent_dirty || n->paint_dirty;
Box cur = vis ? box_and(screen_box(n), clip) : (Box){0, 0, 0, 0};
@@ -692,9 +735,13 @@ static void damage_walk(Node *n, int parent_dirty, int visible, int in_layer, Bo
if (walk_sig && vis) {
sig_node(walk_sig, n, 0);
if (n->paint_dirty) walk_sig->dirty = 1;
+ /* as tf_bounds */
+ if (n->s.backdrop_blur >= 1 || n->type == NODE_TERM || (n->type == NODE_SURFACE && !gpu_active())) walk_sig->live |= 1;
+ if (n->type == NODE_MEDIA || (n->type == NODE_SURFACE && gpu_active())) walk_sig->live |= 2;
+ walk_sig->area = box_or(walk_sig->area, cur);
}
if (vis && n->own_tf) {
- sig = (TfSig){ 1469598103934665603ull, 0 };
+ sig = (TfSig){ 1469598103934665603ull, 0, 0, cur };
sig_node(&sig, n, 1);
walk_sig = &sig;
}
@@ -722,7 +769,28 @@ static void damage_walk(Node *n, int parent_dirty, int visible, int in_layer, Bo
inner = box_and(clip, own_box);
}
for (Node *c = n->first; c; c = c->next) damage_walk(c, dirty, vis, in_layer, inner);
- if (walk_sig == &sig) { tf_check(n, &sig); walk_sig = outer_sig; }
+ if (walk_sig == &sig) {
+ tf_check(n, &sig);
+ /* The raster's kind changed (a blur, a terminal or an app window came into the subtree or
+ * left it): it is now drawn at another resolution, or untransformed, so every pixel of the
+ * subtree changes, not only the node that came or went (0.8.6, engine-test
+ * test_damage_fuzz: a blurred node moved into a scaled, unclipped subtree changed the
+ * text next to it, outside the damage). */
+ if (n->tf->live_known && n->tf->live != sig.live) damage_add(sig.area);
+ n->tf->live = (uint8_t)sig.live;
+ n->tf->live_known = 1;
+ walk_sig = outer_sig;
+ /* a transformed subtree inside another one: the outer raster holds the inner one's pixels,
+ * so whatever changes the inner raster changes the outer one (before 0.8.6 only the inner
+ * node's own box reached the outer signature, and the outer raster stayed cached with old
+ * content of the inner subtree; engine-test test_damage_fuzz with nested transforms) */
+ if (walk_sig) {
+ sig_mix(walk_sig, &sig.h, sizeof sig.h);
+ walk_sig->dirty |= sig.dirty;
+ walk_sig->live |= sig.live;
+ walk_sig->area = box_or(walk_sig->area, sig.area);
+ }
+ }
}
static int box_inside(Box a, Box b) { return a.x0 >= b.x0 && a.y0 >= b.y0 && a.x1 <= b.x1 && a.y1 <= b.y1; }
@@ -733,14 +801,28 @@ static int box_meets(Box a, Box b) { return a.x0 < b.x1 && b.x0 < a.x1 && a.y0 <
* this node's own tint already on it. Blurring that in made the repainted part lighter: the band
* left in the menu bar where a menu or the Control Center had just closed (0.8.1, docs/LAYERS.md).
* So a damage that touches a blurred node, or the margin it samples, repaints the whole node: what
- * it blurs is then this frame's, as in a full repaint. Same on the GPU path (same CPU canvas). */
+ * it blurs is then this frame's, as in a full repaint. Same on the GPU path (same CPU canvas).
+ * (0.8.6) The margin is repainted too: outside the region the canvas holds the last frame's final
+ * pixels, with whatever is painted above the blurred node (a sibling's shadow, a menu) already in
+ * it, while a full repaint blurs only what lies below it. The node's edges took those in, and the
+ * difference stayed until the next full repaint (engine-test test_damage_fuzz). */
+static Box blur_near(const Node *n) {
+ Box b = n->prev_box;
+ float m = ceilf(n->s.backdrop_blur * 2) + 1;
+ Box near = { floorf(b.x0 - m), floorf(b.y0 - m), ceilf(b.x1 + m), ceilf(b.y1 + m) };
+ if (ui.width > 0 && ui.height > 0) { /* the canvas ends there: so does what it samples */
+ near.x0 = fmaxf(near.x0, 0); near.y0 = fmaxf(near.y0, 0);
+ near.x1 = fminf(near.x1, ui.width); near.y1 = fminf(near.y1, ui.height);
+ }
+ return near;
+}
+
static void blur_walk(Node *n, int *grew) {
if (n->type == NODE_RAW || n->s.display_none) return;
Box b = n->prev_box;
if (n->s.backdrop_blur >= 1 && b.x1 > b.x0 && b.y1 > b.y0) {
- float m = ceilf(n->s.backdrop_blur * 2) + 1;
- Box near = { b.x0 - m, b.y0 - m, b.x1 + m, b.y1 + m };
- if (box_meets(ui.damage, near) && !box_inside(b, ui.damage)) { damage_add(b); *grew = 1; }
+ Box near = blur_near(n);
+ if (box_meets(ui.damage, near) && !box_inside(near, ui.damage)) { damage_add(near); *grew = 1; }
}
for (Node *c = n->first; c; c = c->next) blur_walk(c, grew);
}
@@ -764,7 +846,16 @@ static void blur_walk(Node *n, int *grew) {
* and the cause was not found (engine-test test_minimize_damage, a full-repaint comparison of that
* scene, passes). Correctness first: one box, exactly as in 0.8.1, unless lord-server runs with
* LORD_DAMAGE=multi (main.c). The clipped-subtree skip (paint_cull) and the copy of only the
- * painted rectangles (present_cpu) follow the same switch. */
+ * painted rectangles (present_cpu) follow the same switch.
+ * (0.8.6) engine-test test_damage_pipeline (that scene through a copy of main.c's whole
+ * bookkeeping: pending flips, both KMS buffers, the cursor) and test_damage_fuzz (random trees)
+ * found and fixed here: a parent's border lost where an opaque child started a partial repaint,
+ * cached rasters kept after changes made while hidden or unscaled or inside a nested transform, a
+ * raster grid that moved with the subtree's extent, a raster changing kind outside the damage,
+ * blurs taking in what is painted above them from outside the repainted area, and several frames'
+ * rectangles cutting through a blurred node (paint_damage_settle). Each one could leave a stale
+ * area until something repainted it, with one box or several; which one the 0.8.2 report was is
+ * not proven, so the switch stays off until it is tried again on the VM. */
int paint_multi_damage = 0;
static Box drects[DAMAGE_MAX];
static int ndrects;
@@ -782,14 +873,63 @@ static Box dl_bbox(const DamageList *l) {
return b;
}
-static void blur_collect(Node *n, Box *bb, float *bm, int *k) {
+static void blur_collect(Node *n, Box *bb, int *k) {
if (n->type == NODE_RAW || n->s.display_none) return;
Box b = n->prev_box;
if (n->s.backdrop_blur >= 1 && b.x1 > b.x0 && b.y1 > b.y0) {
- if (*k < BLUR_MAX) { bb[*k] = b; bm[*k] = ceilf(n->s.backdrop_blur * 2) + 1; } /* as blur_walk */
+ if (*k < BLUR_MAX) bb[*k] = blur_near(n); /* the node and the margin it samples, as blur_walk */
(*k)++;
}
- for (Node *c = n->first; c; c = c->next) blur_collect(c, bb, bm, k);
+ for (Node *c = n->first; c; c = c->next) blur_collect(c, bb, k);
+}
+
+/* The blur rule on a list of rectangles: every rectangle that touches a blurred node's margin joins
+ * the rectangle holding that node and its whole margin. 1 if it did not settle in 8 passes. */
+static int blur_rule(DamageList *l, const Box *bb, int nb) {
+ int changed = 1;
+ for (int pass = 0; changed && pass < 8; pass++) {
+ changed = 0;
+ for (int k = 0; k < nb; k++) {
+ Box near = bb[k];
+ int hits = 0, inside = 0;
+ Box u = near;
+ for (int i = 0; i < l->n; i++) {
+ if (!box_meets(l->r[i], near)) continue;
+ hits++;
+ if (box_inside(near, l->r[i])) inside = 1;
+ u = (Box){ fminf(u.x0, l->r[i].x0), fminf(u.y0, l->r[i].y0), fmaxf(u.x1, l->r[i].x1), fmaxf(u.y1, l->r[i].y1) };
+ }
+ if (!hits || (hits == 1 && inside)) continue;
+ for (int i = 0; i < l->n; i++) if (box_meets(l->r[i], near)) l->r[i--] = l->r[--l->n];
+ dlist_add(l, (Box){ floorf(u.x0), floorf(u.y0), ceilf(u.x1), ceilf(u.y1) });
+ changed = 1;
+ }
+ }
+ return changed;
+}
+
+/* Damage gathered over several frames (main.c: a display whose page flip was pending keeps adding
+ * each frame's rectangles to its list, and dlist_add joins the ones that overlap): each frame's
+ * rectangles kept the blur rule, but a join of two of them, or a rectangle of an older frame after
+ * a blurred node moved, can cut through a blurred node, whose blur then depends on where the cut
+ * falls (0.8.6, engine-test test_damage_pipeline/test_damage_fuzz). The rule again, on the tree as
+ * it is painted now; if it doesn't settle, one box grown to every margin it touches. */
+void paint_damage_settle(DamageList *l) {
+ if (!ui.root || l->n < 1) return;
+ Box bb[BLUR_MAX];
+ int nb = 0;
+ blur_collect(ui.root, bb, &nb);
+ if (!nb) return;
+ if (nb <= BLUR_MAX && !blur_rule(l, bb, nb)) return;
+ Box all = dl_bbox(l);
+ if (nb > BLUR_MAX) nb = BLUR_MAX; /* (more than 48 blurred nodes: the first ones) */
+ for (int pass = 0, grew = 1; grew && pass < 8; pass++) {
+ grew = 0;
+ for (int k = 0; k < nb; k++)
+ if (box_meets(all, bb[k]) && !box_inside(bb[k], all)) { all = box_or(all, bb[k]); grew = 1; }
+ }
+ l->n = 0;
+ dlist_add(l, (Box){ floorf(all.x0), floorf(all.y0), ceilf(all.x1), ceilf(all.y1) });
}
/* The list for this frame, or 0 if it has to be one box. */
@@ -821,29 +961,10 @@ static int multi_rects(Node *root) {
}
/* blurred surfaces: see above */
Box bb[BLUR_MAX];
- float bm[BLUR_MAX];
int nb = 0;
- blur_collect(root, bb, bm, &nb);
+ blur_collect(root, bb, &nb);
if (nb > BLUR_MAX) return 0;
- int changed = 1;
- for (int pass = 0; changed && pass < 8; pass++) {
- changed = 0;
- for (int k = 0; k < nb; k++) {
- Box b = bb[k], near = { b.x0 - bm[k], b.y0 - bm[k], b.x1 + bm[k], b.y1 + bm[k] };
- int hits = 0, inside = 0;
- Box u = b;
- for (int i = 0; i < l.n; i++) {
- if (!box_meets(l.r[i], near)) continue;
- hits++;
- if (box_inside(b, l.r[i])) inside = 1;
- u = (Box){ fminf(u.x0, l.r[i].x0), fminf(u.y0, l.r[i].y0), fmaxf(u.x1, l.r[i].x1), fmaxf(u.y1, l.r[i].y1) };
- }
- if (!hits || (hits == 1 && inside)) continue;
- for (int i = 0; i < l.n; i++) if (box_meets(l.r[i], near)) l.r[i--] = l.r[--l.n];
- dlist_add(&l, (Box){ floorf(u.x0), floorf(u.y0), ceilf(u.x1), ceilf(u.y1) });
- changed = 1;
- }
- }
+ int changed = blur_rule(&l, bb, nb);
if (changed || l.n < 2) return 0;
Box all = dl_bbox(&l);
float sum = 0;
diff --git a/server/src/ui/ui.h b/server/src/ui/ui.h
index 75ab265..a3526f6 100644
--- a/server/src/ui/ui.h
+++ b/server/src/ui/ui.h
@@ -91,6 +91,7 @@ typedef struct { float x0, y0, x1, y1; } Box;
typedef struct {
Affine own, world, inv;
uint64_t sig; /* paint.c: geometry of its subtree in the last damage pass (own_tf) */
+ uint8_t live, live_known; /* paint.c: what decided its raster's kind in the last damage pass */
} NodeTf;
typedef struct Node {
@@ -109,6 +110,8 @@ typedef struct Node {
int measure_valid;
float measure_maxw, measure_w, measure_h;
uint8_t paint_dirty; /* its style or text changed */
+ unsigned gen; /* bumped with paint_dirty and never cleared: a transformed subtree's
+ * cached raster compares it (paint.c tf_check) */
Box prev_box; /* what it occupied on screen in the last frame */
NodeTf *tf;
} Node;
@@ -282,7 +285,12 @@ int paint_damage(Node *root); /* computes ui.damage; 0 if there is nothing
/* after paint_damage: the rectangles to repaint (1 = just ui.damage), each inside ui.damage;
* see "Several damaged rectangles" in paint.c */
int paint_damage_rects(Box *out, int max);
+/* damage gathered over several frames (a display whose flip was pending): the blur rule again,
+ * on the tree as it is now (paint.c, main.c paint_out) */
+void paint_damage_settle(DamageList *l);
extern int paint_multi_damage; /* 1: several rectangles (LORD_DAMAGE=multi, tests); 0 by default */
+extern int paint_tf_nocache; /* tests: a reference paint that neither reads nor fills the
+ * transformed subtrees' raster cache (engine-test) */
void paint_root(Canvas *c, Node *root);
Node *hit_test(Node *root, float x, float y);
/* Capture mode (media/capture.c): protected nodes are painted black and app windows
diff --git a/server/tests/engine_test.c b/server/tests/engine_test.c
index 886db83..0af964e 100644
--- a/server/tests/engine_test.c
+++ b/server/tests/engine_test.c
@@ -677,6 +677,560 @@ static void test_minimize_damage(void) {
paint_multi_damage = 0;
}
+/* ---- lord-server's whole CPU damage pipeline (main.c), modelled ----
+ * The tests above paint each frame's rectangles straight into one canvas. lord-server does more:
+ * paint_ui adds each frame's rectangles to the display's pending list (o->pl, o->pend) and a display
+ * whose page flip is still pending keeps gathering them; paint_out paints the gathered list into
+ * the scene; present_cpu copies into the KMS back buffer what that buffer is missing (what the
+ * other buffer got since, as a box and as rectangles), draws the cursor and flips. This copy of
+ * that bookkeeping (kept in step with main.c: paint_ui, paint_out, present_cpu) checks every
+ * painted scene against a full repaint and every presented buffer against the scene. */
+enum { SW = 1280, SH = 800 };
+typedef struct {
+ Box pend;
+ DamageList pl;
+ int full, pframes;
+ uint32_t *scene;
+ Canvas sc;
+ uint32_t *buf[2];
+ int front, flip_pending;
+ Rect stale[2], curs[2];
+ DamageList pstale[2];
+ Box painted[DAMAGE_MAX];
+ int npainted, full_copy;
+} SimOut;
+
+static Rect sim_rjoin(Rect a, Rect b) {
+ if (a.x1 <= a.x0 || a.y1 <= a.y0) return b;
+ if (b.x1 <= b.x0 || b.y1 <= b.y0) return a;
+ return (Rect){ a.x0 < b.x0 ? a.x0 : b.x0, a.y0 < b.y0 ? a.y0 : b.y0, a.x1 > b.x1 ? a.x1 : b.x1, a.y1 > b.y1 ? a.y1 : b.y1 };
+}
+static Box sim_bjoin(Box a, Box b) {
+ if (a.x1 <= a.x0 || a.y1 <= a.y0) return b;
+ if (b.x1 <= b.x0 || b.y1 <= b.y0) return a;
+ return (Box){ fminf(a.x0, b.x0), fminf(a.y0, b.y0), fmaxf(a.x1, b.x1), fmaxf(a.y1, b.y1) };
+}
+static int sim_bempty(Box b) { return b.x1 <= b.x0 || b.y1 <= b.y0; }
+
+static void sim_init(SimOut *o) {
+ memset(o, 0, sizeof *o);
+ o->scene = calloc((size_t)SW * SH, 4);
+ o->buf[0] = calloc((size_t)SW * SH, 4);
+ o->buf[1] = calloc((size_t)SW * SH, 4);
+ canvas_init(&o->sc, o->scene, SW, SH, SW);
+ o->full = 1;
+ o->full_copy = 2;
+}
+static void sim_free(SimOut *o) { free(o->scene); free(o->buf[0]); free(o->buf[1]); }
+
+/* main.c paint_ui: layout, damage, and the damage goes to the display's pending list */
+static void sim_paint_ui(SimOut *o, Node *root) {
+ layout_root(root, SW, SH);
+ Box d = { 0, 0, 0, 0 };
+ if (paint_damage(root)) d = ui.damage;
+ ui.damage = (Box){ 0, 0, 0, 0 };
+ if (sim_bempty(d)) return;
+ Box rs[DAMAGE_MAX];
+ int nr = paint_damage_rects(rs, DAMAGE_MAX);
+ if (sim_bempty(o->pend)) { o->pl.n = 0; o->pframes = 0; }
+ for (int k = 0; k < nr; k++) dlist_add(&o->pl, rs[k]);
+ o->pend = sim_bjoin(o->pend, d);
+ o->pframes++;
+}
+
+/* main.c paint_out at scale 1 */
+static Rect sim_paint_out(SimOut *o, Node *root, int *nparts_out) {
+ Rect r = { 0, 0, 0, 0 };
+ Box b = o->pend;
+ o->npainted = 0;
+ *nparts_out = 0;
+ if (o->full) b = (Box){ 0, 0, SW, SH };
+ int whole = o->full;
+ o->full = 0;
+ o->pend = (Box){ 0, 0, 0, 0 };
+ if (sim_bempty(b)) return r;
+ Box lb = o->pl.n ? o->pl.r[0] : (Box){ 0, 0, 0, 0 };
+ for (int k = 1; k < o->pl.n; k++) lb = sim_bjoin(lb, o->pl.r[k]);
+ int multi = !whole && o->pl.n > 1 && lb.x0 == b.x0 && lb.y0 == b.y0 && lb.x1 == b.x1 && lb.y1 == b.y1;
+ DamageList l = { .n = 0 };
+ if (multi) l = o->pl;
+ else if (!whole) dlist_add(&l, b);
+ if (!whole && o->pframes > 1 && !getenv("SIM_NO_SETTLE")) paint_damage_settle(&l);
+ if (!whole && l.n) {
+ b = l.r[0];
+ for (int k = 1; k < l.n; k++) b = sim_bjoin(b, l.r[k]);
+ }
+ multi = !whole && l.n > 1;
+ int nparts = multi ? l.n : 1;
+ Box parts[DAMAGE_MAX];
+ if (multi) memcpy(parts, l.r, sizeof(Box) * (size_t)nparts);
+ else parts[0] = b;
+ o->pl.n = 0;
+ o->pframes = 0;
+ for (int k = 0; k < nparts; k++) {
+ Box q = parts[k];
+ Rect pr = { (int)floorf(fmaxf(q.x0, 0)), (int)floorf(fmaxf(q.y0, 0)), (int)ceilf(fminf(q.x1, SW)), (int)ceilf(fminf(q.y1, SH)) };
+ if (whole) pr = (Rect){ 0, 0, SW, SH };
+ if (pr.x1 <= pr.x0 || pr.y1 <= pr.y0) continue;
+ ui.damage = (Box){ (float)pr.x0, (float)pr.y0, (float)pr.x1, (float)pr.y1 };
+ canvas_set_clip(&o->sc, pr);
+ canvas_clear(&o->sc, 0x000000);
+ paint_root(&o->sc, root);
+ r = sim_rjoin(r, pr);
+ o->painted[o->npainted++] = (Box){ (float)pr.x0, (float)pr.y0, (float)pr.x1, (float)pr.y1 };
+ }
+ *nparts_out = nparts;
+ canvas_set_clip(&o->sc, (Rect){ 0, 0, SW, SH });
+ ui.damage = (Box){ 0, 0, 0, 0 };
+ return r;
+}
+
+/* main.c present_cpu (no rotation, no Night Light): returns the back buffer it drew */
+static int sim_present(SimOut *o, Rect r, Rect cur) {
+ int bi = o->front ^ 1;
+ uint32_t *out = o->buf[bi];
+ if (o->full_copy > 0) {
+ memcpy(out, o->scene, (size_t)SW * SH * 4);
+ o->full_copy--;
+ } else {
+ Rect need = sim_rjoin(sim_rjoin(o->stale[bi], r), o->curs[bi]);
+ if (need.x0 < 0) need.x0 = 0;
+ if (need.y0 < 0) need.y0 = 0;
+ if (need.x1 > SW) need.x1 = SW;
+ if (need.y1 > SH) need.y1 = SH;
+ DamageList cp = o->pstale[bi];
+ for (int i = 0; i < o->npainted; i++) dlist_add(&cp, o->painted[i]);
+ Rect cu = o->curs[bi];
+ if (cu.x1 > cu.x0 && cu.y1 > cu.y0) dlist_add(&cp, (Box){ (float)cu.x0, (float)cu.y0, (float)cu.x1, (float)cu.y1 });
+ Box cb = cp.n ? cp.r[0] : (Box){ 0, 0, 0, 0 };
+ for (int i = 1; i < cp.n; i++) cb = sim_bjoin(cb, cp.r[i]);
+ Rect cbr = { (int)cb.x0, (int)cb.y0, (int)cb.x1, (int)cb.y1 };
+ Rect nj = sim_rjoin(sim_rjoin(o->stale[bi], r), o->curs[bi]);
+ if (paint_multi_damage && cp.n > 1 && cbr.x0 == nj.x0 && cbr.y0 == nj.y0 && cbr.x1 == nj.x1 && cbr.y1 == nj.y1) {
+ for (int i = 0; i < cp.n; i++) {
+ Rect q = { (int)cp.r[i].x0, (int)cp.r[i].y0, (int)cp.r[i].x1, (int)cp.r[i].y1 };
+ if (q.x0 < 0) q.x0 = 0;
+ if (q.y0 < 0) q.y0 = 0;
+ if (q.x1 > SW) q.x1 = SW;
+ if (q.y1 > SH) q.y1 = SH;
+ for (int y = q.y0; y < q.y1; y++) memcpy(out + (size_t)y * SW + q.x0, o->scene + (size_t)y * SW + q.x0, (size_t)(q.x1 - q.x0) * 4);
+ }
+ } else
+ for (int y = need.y0; y < need.y1; y++) memcpy(out + (size_t)y * SW + need.x0, o->scene + (size_t)y * SW + need.x0, (size_t)(need.x1 - need.x0) * 4);
+ }
+ o->stale[bi] = (Rect){ 0, 0, 0, 0 };
+ o->stale[bi ^ 1] = sim_rjoin(o->stale[bi ^ 1], r);
+ o->pstale[bi].n = 0;
+ for (int i = 0; i < o->npainted; i++) dlist_add(&o->pstale[bi ^ 1], o->painted[i]);
+ o->curs[bi] = (Rect){ 0, 0, 0, 0 };
+ if (cur.x1 > cur.x0) { /* the arrow: an opaque square */
+ for (int y = cur.y0; y < cur.y1; y++) for (int x = cur.x0; x < cur.x1; x++) out[(size_t)y * SW + x] = 0xffff00ff;
+ o->curs[bi] = cur;
+ }
+ return bi;
+}
+
+static uint32_t *sim_ref;
+static int sim_bad_px; /* pixels off by more than 24 levels in the last comparison */
+/* a full repaint of the tree as it is now; worst channel difference from px, and where */
+static int sim_full_differs(Node *root, const uint32_t *px, int *where) {
+ if (!sim_ref) sim_ref = calloc((size_t)SW * SH, 4);
+ if (!sim_ref) return 999;
+ Canvas rc;
+ canvas_init(&rc, sim_ref, SW, SH, SW);
+ ui.damage = (Box){ 0, 0, SW, SH };
+ canvas_clear(&rc, 0);
+ paint_tf_nocache = 1; /* the truth: no raster from the cache, and the cache untouched */
+ paint_root(&rc, root);
+ paint_tf_nocache = 0;
+ ui.damage = (Box){ 0, 0, 0, 0 };
+ int worst = 0;
+ sim_bad_px = 0;
+ for (int i = 0; i < SW * SH; i++) {
+ uint32_t a = sim_ref[i], b = px[i];
+ if (a == b) continue;
+ int big = 0;
+ for (int sh = 0; sh < 24; sh += 8) {
+ int dv = abs((int)((a >> sh) & 255) - (int)((b >> sh) & 255));
+ if (dv > worst) { worst = dv; *where = i; }
+ if (dv > 24) big = 1;
+ }
+ sim_bad_px += big;
+ }
+ return worst;
+}
+
+/* The desktop of the 0.8.2 report: Monitor's moving map, a translucent, blurred Terminal in front of
+ * it, minimized into a blurred Dock (the default theme: WindowShell's frame, fxStyle's transform),
+ * under a blurred menu bar. */
+typedef struct { Node *shell, *inner, *title; } SimWin;
+static SimWin sim_window(Node *parent, float x, float y, float w, float h, int terminal, int with_title) {
+ SimWin sw;
+ const float m = 6; /* WINDOW_EDGE: the invisible resize borders */
+ sw.shell = box_in(parent, x - m, y - m, w + 2 * m, h + 2 * m, 0);
+ sw.inner = box_in(sw.shell, m, m, w, h, terminal ? 0 : 0xff1e1e20);
+ ss(sw.inner, "overflow", "hidden");
+ sn(sw.inner, "borderRadius", 12);
+ sn(sw.inner, "borderWidth", 1);
+ sn(sw.inner, "borderColor", terminal ? 0xff3a3a3d : 0x33ffffff);
+ sn(sw.inner, "shadowColor", 0x8c000000);
+ sn(sw.inner, "shadowBlur", 56);
+ sn(sw.inner, "shadowOffsetY", 24);
+ Node *bar = box_in(sw.inner, 0, 0, w, 40, 0xff2c2c2f);
+ sw.title = with_title ? text(bar, terminal ? "lord@lordos: ~" : "Monitor", 13) : NULL;
+ if (sw.title) { sn(sw.title, "color", 0xffe0e0e0); ss(sw.title, "position", "absolute"); sn(sw.title, "left", w / 2 - 50); sn(sw.title, "top", 12); }
+ static const uint32_t lights[3] = { 0xffff5f57, 0xfffebc2e, 0xff28c840 };
+ for (int i = 0; i < 3; i++) { Node *l = box_in(bar, 14 + i * 21, 13, 13, 13, lights[i]); sn(l, "borderRadius", 7); }
+ box_in(sw.inner, 0, 40, w, 1, terminal ? 0xff3a3a3d : 0x22ffffff);
+ if (terminal) {
+ Node *pane = box_in(sw.inner, 0, 41, w, h - 41, 0xc81e1e1e); /* translucent profile, with blur */
+ ss(pane, "overflow", "hidden");
+ sn(pane, "backdropBlur", 14);
+ for (int i = 0; i < 4; i++) { Node *t = text(pane, "lord@lordos:~$ ls -la /usr/share", 13); sn(t, "color", 0xffd0d0d0); ss(t, "position", "absolute"); sn(t, "left", 8); sn(t, "top", 6 + i * 18); }
+ }
+ return sw;
+}
+
+typedef struct { int pend_pct, seed, frames; } SimPlan;
+
+/* Returns the number of frames that differed. */
+static int sim_run(const SimPlan *pl, int *painted_frames, int *multi_frames) {
+ enum { DOTS = 30 };
+ rng_state = (uint32_t)pl->seed * 2654435761u + 7;
+ ui_reset();
+ Node *root = view(NULL);
+ ui.root = root;
+ sn(root, "backgroundColor", 0xff35507a);
+ box_in(root, 0, 0, SW, SH, 0xff35507a); /* the wallpaper image */
+ for (int i = 0; i < 12; i++) box_in(root, (float)(i * 110), 0, 40, SH, 0xff2a4466);
+ SimWin mon = sim_window(root, 70, 60, 960, 620, 0, 1);
+ Node *map = box_in(mon.inner, 16, 56, 928, 548, 0xff26282c);
+ ss(map, "overflow", "hidden");
+ sn(map, "borderRadius", 8);
+ for (int i = 0; i < 9; i++) box_in(map, (float)(40 + (i % 5) * 170), (float)(60 + (i / 5) * 220), 120, 140, 0xff3b4f3b);
+ Node *dots[DOTS];
+ float dx[DOTS], dy[DOTS];
+ for (int i = 0; i < DOTS; i++) {
+ dx[i] = (float)(rnd() % 900);
+ dy[i] = (float)(rnd() % 520);
+ dots[i] = box_in(map, dx[i], dy[i], 9, 9, i % 2 ? 0xd8ff9f0a : 0xd830d158);
+ sn(dots[i], "borderRadius", 4.5);
+ }
+ Node *pill = box_in(map, 300, 200, 90, 18, 0xe01c1d21);
+ sn(pill, "borderRadius", 9);
+ float tx = 260 + (float)(rnd() % 300), ty = 140 + (float)(rnd() % 200), tw = 640, th = 400;
+ SimWin term = sim_window(root, tx, ty, tw, th, 1, 1);
+ Node *bar = box_in(layer_node(root, 20, SW, SH), 0, 0, SW, 28, 0x80202024);
+ sn(bar, "backdropBlur", 20);
+ text(bar, "Terminal File Edit View", 13);
+ Node *dockl = layer_node(root, 10, SW, SH);
+ Node *dock = box_in(dockl, SW / 2 - 300, SH - 70, 600, 62, 0x90303034);
+ sn(dock, "backdropBlur", 20);
+ sn(dock, "borderRadius", 16);
+ for (int i = 0; i < 10; i++) { Node *ic = box_in(dock, 8 + i * 58, 7, 48, 48, 0xff5080c0 + (uint32_t)i * 0x101010); sn(ic, "borderRadius", 11); }
+ Node *popl = layer_node(root, 50, SW, SH), *menu = NULL;
+ SimOut o;
+ sim_init(&o);
+ int bad = 0, cx = 600, cy = 400;
+ int state = 0, t0 = 0, steps = 0; /* 0 shown, 1 gone one frame, 2 shrinking, 3 minimized */
+ *painted_frames = *multi_frames = 0;
+ for (int f = 0; f < pl->frames; f++) {
+ /* the moving dots (12 fps in Monitor, here every frame) */
+ for (int i = 0; i < DOTS; i++) {
+ if (rnd() % 4 == 0) continue;
+ dx[i] += (float)((int)(rnd() % 9) - 4);
+ dy[i] += (float)((int)(rnd() % 7) - 3);
+ if (dx[i] < -9 || dx[i] > 930) dx[i] = (float)(rnd() % 900);
+ if (dy[i] < -9 || dy[i] > 550) dy[i] = (float)(rnd() % 520);
+ sn(dots[i], "left", dx[i]);
+ sn(dots[i], "top", dy[i]);
+ }
+ if (rnd() % 6 == 0) { sn(pill, "left", (float)(rnd() % 800)); sn(pill, "top", (float)(rnd() % 500)); }
+ /* the Terminal: minimize (wm.minimize, then useMinimizing's remount with fxStyle), restore */
+ if (state == 0 && rnd() % 25 == 0) {
+ node_destroy(term.shell);
+ state = 1;
+ } else if (state == 1) {
+ term = sim_window(root, tx, ty, tw, th, 1, 1);
+ state = 2;
+ t0 = f;
+ steps = 6 + (int)(rnd() % 14);
+ }
+ if (state == 2) {
+ float p = fminf(1, (float)(f - t0 + 1) / (float)steps), e = p * p;
+ float fx = SW / 2.0f, fy = SH - 36.0f;
+ sn(term.inner, "translateX", (fx - (tx + tw / 2)) * e);
+ sn(term.inner, "translateY", (fy - (ty + th / 2)) * e);
+ sn(term.inner, "scaleX", 1 - 0.9f * e);
+ sn(term.inner, "scaleY", 1 - 0.9f * e);
+ sn(term.inner, "opacity", 1 - 0.7f * e);
+ if (f - t0 >= steps) { node_destroy(term.shell); state = 3; t0 = f; }
+ } else if (state == 3 && f - t0 > 8 && rnd() % 10 == 0) {
+ tx = 200 + (float)(rnd() % 400);
+ ty = 100 + (float)(rnd() % 250);
+ term = sim_window(root, tx, ty, tw, th, 1, 1);
+ state = 0;
+ }
+ if (state == 0 && term.title && rnd() % 9 == 0) node_set_text(term.title->first, rnd() % 2 ? "lord@lordos: ~/src" : "lord@lordos: ~");
+ if (rnd() % 20 == 0) { /* a menu opens or closes */
+ if (menu) { node_destroy(menu); menu = NULL; }
+ else { menu = box_in(popl, (float)(rnd() % 1000), 24, 220, 260, 0xf0303034); sn(menu, "borderRadius", 8); sn(menu, "shadowColor", 0x60000000); sn(menu, "shadowBlur", 20); }
+ }
+ if (rnd() % 3 == 0) { cx = (int)(rnd() % (SW - 16)); cy = (int)(rnd() % (SH - 16)); }
+ /* the frame: damage always; painted and presented only when the flip is not pending */
+ sim_paint_ui(&o, root);
+ if (o.flip_pending) {
+ if ((int)(rnd() % 100) < 50) { o.flip_pending = 0; o.front ^= 1; }
+ else continue;
+ }
+ int nparts = 0;
+ Rect r = sim_paint_out(&o, root, &nparts);
+ if (r.x1 > r.x0) { (*painted_frames)++; if (nparts > 1) (*multi_frames)++; }
+ int where = 0, worst = sim_full_differs(root, o.scene, &where);
+ if (worst > 2) {
+ if (bad < 4) printf(" pipeline seed %d frame %d (state %d, %d parts): scene differs from a full repaint by %d at %d,%d\n",
+ pl->seed, f, state, nparts, worst, where % SW, where / SW);
+ bad++;
+ }
+ Rect cur = { cx, cy, cx + 12, cy + 18 };
+ int bi = sim_present(&o, r, cur);
+ int off = 0, at = -1;
+ for (int y = 0; y < SH && at < 0; y++)
+ for (int x = 0; x < SW; x++) {
+ int in = x >= cur.x0 && x < cur.x1 && y >= cur.y0 && y < cur.y1;
+ uint32_t want = in ? 0xffff00ff : o.scene[(size_t)y * SW + x];
+ if (o.buf[bi][(size_t)y * SW + x] != want) { off++; at = y * SW + x; break; }
+ }
+ if (off) {
+ if (bad < 4) printf(" pipeline seed %d frame %d: the presented buffer %d differs from the scene at %d,%d\n", pl->seed, f, bi, at % SW, at / SW);
+ bad++;
+ }
+ if ((int)(rnd() % 100) < pl->pend_pct) o.flip_pending = 1;
+ else o.front = bi;
+ }
+ sim_free(&o);
+ return bad;
+}
+
+static void test_damage_pipeline(void) {
+ int total_bad = 0, painted = 0, multi = 0;
+ for (int mode = 1; mode >= 0; mode--)
+ for (int seed = 0; seed < 6; seed++) {
+ paint_multi_damage = mode;
+ SimPlan pl = { (int[]){ 0, 30, 60 }[seed % 3], seed + 100 * mode, 120 };
+ int p = 0, m = 0, bad = sim_run(&pl, &p, &m);
+ CHECK(!bad, "pipeline (multi %d, seed %d, %d%% of flips pending): %d frames differ", mode, seed, pl.pend_pct, bad);
+ total_bad += bad;
+ if (mode) { painted += p; multi += m; }
+ }
+ printf("pipeline: %d frames painted with several rectangles on, %d of them in several parts\n", painted, multi);
+ paint_multi_damage = 0;
+ (void)total_bad;
+}
+
+/* Random trees and random changes through the same pipeline (0.8.6): boxes that clip or not,
+ * rounded, with shadows, translucent, blurred, scaled or rotated, faded, raised with zIndex, hidden,
+ * moved, resized, re-parented, destroyed; small changes far apart, so most frames are several
+ * rectangles, and 40 % of the flips pending in half the seeds. Every painted frame is compared with
+ * a full repaint that doesn't use the transformed subtrees' raster cache (paint_tf_nocache), and
+ * every presented buffer with the scene. It found, in both damage modes: a parent's border lost
+ * where its opaque child was the start of a partial repaint; cached rasters kept after a change
+ * made while hidden or unscaled; a raster grid that moved with the subtree's extent; blurs that
+ * took in what is painted above them from outside the repainted area; a raster that changed kind
+ * (a blur coming in) outside the damage; several frames' rectangles that cut through a blurred
+ * node; a transform inside another one whose changes never reached the outer raster's cache.
+ * What is left (FZ_STRICT=1, 24 seeds: one seed in each mode, the same with one box or several):
+ * a 1-pixel row of a rotated subtree moved into another transformed subtree (up to 63 levels,
+ * 17 px), and the antialiased edge of a blurred node inside a scaled subtree without
+ * overflow: hidden, which moves by up to ~13 levels when the subtree's extent changes; both stay
+ * until something repaints them. The 12 seeds run by default hit neither (a frame fails here with
+ * a pixel off by more than 24 levels).
+ * Environment: FUZZ_SEEDS, FZ_ONLY=seed, FZ_MULTI=0|1, FZ_NO, FZ_INIT=nodes, FZ_STRICT, FZ_AREA,
+ * FZ_LOG (the changes), FZ_DEBUG (fz_explain). */
+#define FZ_MAX 160
+static Node *fz_nodes[FZ_MAX];
+static int fz_n;
+
+static float frand(float a, float b) { return a + (b - a) * (float)(rnd() % 10001) / 10000.0f; }
+/* FZ_NO=blur,shadow,scale,rotate,nest leaves those out (nest: a transform inside another one) */
+static int fz_no(const char *what) { const char *e = getenv("FZ_NO"); return e && strstr(e, what) != NULL; }
+
+static int fz_has_tf(const Node *n) { return n->s.ext && (n->s.ext->scale_x != 1 || n->s.ext->scale_y != 1 || n->s.ext->rotate != 0); }
+static int fz_sub_tf(const Node *n) { if (fz_has_tf(n)) return 1; for (const Node *c = n->first; c; c = c->next) if (fz_sub_tf(c)) return 1; return 0; }
+/* FZ_NO=nest: a transform only where no ancestor or descendant has one */
+static int fz_nest_ok(const Node *n) {
+ if (!fz_no("nest")) return 1;
+ for (const Node *p = n->parent; p; p = p->parent) if (fz_has_tf(p)) return 0;
+ for (const Node *c = n->first; c; c = c->next) if (fz_sub_tf(c)) return 0;
+ return 1;
+}
+
+static void fz_style(Node *b) {
+ int r = (int)(rnd() % 100);
+ if (r < 35) ss(b, "overflow", "hidden");
+ if (rnd() % 3 == 0) sn(b, "borderRadius", frand(0, 20));
+ if (rnd() % 5 == 0 && !fz_no("shadow")) { sn(b, "shadowColor", 0x70000000); sn(b, "shadowBlur", frand(2, 40)); sn(b, "shadowOffsetY", frand(-6, 16)); }
+ if (rnd() % 7 == 0 && !fz_no("blur")) sn(b, "backdropBlur", frand(2, 24));
+ if (rnd() % 6 == 0) sn(b, "opacity", frand(0.2f, 1));
+ if (rnd() % 6 == 0 && !fz_no("scale") && fz_nest_ok(b)) { float s = frand(0.1f, 1.3f); sn(b, "scaleX", s); sn(b, "scaleY", s); }
+ if (rnd() % 14 == 0 && !fz_no("rotate") && fz_nest_ok(b)) sn(b, "rotate", frand(-30, 30));
+ if (rnd() % 8 == 0) sn(b, "zIndex", (float)(rnd() % 5));
+ if (rnd() % 6 == 0) { sn(b, "borderWidth", 1); sn(b, "borderColor", 0x40ffffff); }
+}
+
+static void fz_forget(Node *n) {
+ for (int i = 0; i < fz_n; i++) if (fz_nodes[i] == n) { fz_nodes[i] = fz_nodes[--fz_n]; i--; }
+ for (Node *c = n->first; c; c = c->next) fz_forget(c);
+}
+
+static Node *fz_add(Node *root) {
+ if (fz_n >= FZ_MAX) return NULL;
+ Node *p = fz_n && rnd() % 3 ? fz_nodes[rnd() % (unsigned)fz_n] : root;
+ if (p->type == NODE_TEXT) p = root;
+ uint32_t a = rnd() % 3 == 0 ? 0xff000000u : (uint32_t)(0x60 + rnd() % 0x9f) << 24;
+ Node *b = box_in(p, frand(-20, p == root ? SW - 40 : p->w), frand(-20, p == root ? SH - 40 : p->h), frand(4, 300), frand(4, 220),
+ a | (rnd() & 0xffffff));
+ fz_style(b);
+ if (rnd() % 6 == 0) { Node *t = text(b, rnd() % 2 ? "Quarterly report" : "\xd8\xaa\xd9\x82\xd8\xb1\xd9\x8a\xd8\xb1 abc", 13); sn(t, "color", 0xffffffff); }
+ else fz_nodes[fz_n++] = b;
+ return b;
+}
+
+static void fz_step(Node *root) {
+ int ops = 1 + (int)(rnd() % 4);
+ for (int k = 0; k < ops; k++) {
+ int op = (int)(rnd() % 100);
+ if (!fz_n || op < 12) { fz_add(root); continue; }
+ Node *n = fz_nodes[rnd() % (unsigned)fz_n];
+ if (getenv("FZ_LOG")) printf(" op %d on node %d (parent %d)\n", op, n->id, n->parent ? n->parent->id : 0);
+ if (op < 22) { fz_forget(n); node_destroy(n); }
+ else if (op < 50) { sn(n, "left", n->x + frand(-12, 12)); sn(n, "top", n->y + frand(-12, 12)); }
+ else if (op < 58) { sn(n, "width", frand(4, 300)); sn(n, "height", frand(4, 220)); }
+ else if (op < 66) { float s = frand(0.1f, 1.3f); if (!fz_no("scale") && fz_nest_ok(n)) { sn(n, "scaleX", s); sn(n, "scaleY", s); } sn(n, "translateX", frand(-40, 40)); }
+ else if (op < 72) sn(n, "opacity", frand(0, 1));
+ else if (op < 78) ss(n, "display", n->s.display_none ? "flex" : "none");
+ else if (op < 84) sn(n, "backgroundColor", (uint32_t)(0x60 + rnd() % 0xa0) << 24 | (rnd() & 0xffffff));
+ else if (op < 88) sn(n, "zIndex", (float)(rnd() % 5));
+ else if (op < 92 && fz_n > 1) { /* re-parented (React moving a node) */
+ Node *p = fz_nodes[rnd() % (unsigned)fz_n];
+ int cycle = 0;
+ for (Node *q = p; q; q = q->parent) if (q == n) cycle = 1;
+ if (fz_no("nest") && fz_sub_tf(n)) for (Node *q = p; q; q = q->parent) if (fz_has_tf(q)) cycle = 1;
+ if (!cycle && p->type != NODE_TEXT) node_append(p, n);
+ } else if (op < 96) { float v = frand(0, 40); if (!fz_no("shadow")) sn(n, "shadowBlur", v); }
+ else { float v = rnd() % 2 ? 0 : frand(2, 20); if (!fz_no("blur")) sn(n, "backdropBlur", v); }
+ }
+}
+
+/* FZ_DEBUG: what the first differing pixel of a seed is made of (the damage, the nodes over it,
+ * which ones the reference depends on, and the partial paint replayed three ways). */
+static void fz_explain(Node *root, SimOut *op, const uint32_t *before, DamageList keep, Box keepb, int where) {
+ SimOut o = *op;
+ int px = where % SW, py = where / SW;
+ printf(" pend %.0f,%.0f %.0f,%.0f; parts:", keepb.x0, keepb.y0, keepb.x1, keepb.y1);
+ for (int i = 0; i < keep.n; i++) printf(" [%.0f,%.0f %.0f,%.0f]", keep.r[i].x0, keep.r[i].y0, keep.r[i].x1, keep.r[i].y1);
+ printf("\n scene %08x ref %08x\n", o.scene[where], sim_ref[where]);
+ uint32_t want = sim_ref[where];
+ { int outside = 0, first = -1; for (int i = 0; i < SW * SH; i++) { int x = i % SW, y = i / SW, in = 0; for (int k = 0; k < o.npainted; k++) if (x >= o.painted[k].x0 && x < o.painted[k].x1 && y >= o.painted[k].y0 && y < o.painted[k].y1) in = 1; if (!in && before[i] != sim_ref[i]) { outside++; if (first < 0) first = i; } }
+ printf(" outside the parts, the scene before this frame differs from the reference in %d px (first %d,%d)\n", outside, first % SW, first / SW); }
+ { static uint32_t *t; if (!t) t = malloc((size_t)SW * SH * 4); Canvas tc; canvas_init(&tc, t, SW, SH, SW); Rect pr = { (int)o.painted[0].x0, (int)o.painted[0].y0, (int)o.painted[0].x1, (int)o.painted[0].y1 };
+ memcpy(t, before, (size_t)SW * SH * 4); ui.damage = o.painted[0]; canvas_set_clip(&tc, pr); canvas_clear(&tc, 0); paint_tf_nocache = 1; paint_root(&tc, root); printf(" replay part (damage part, clip part): %08x\n", t[where]);
+ memcpy(t, before, (size_t)SW * SH * 4); ui.damage = (Box){ 0, 0, SW, SH }; canvas_set_clip(&tc, pr); canvas_clear(&tc, 0); paint_root(&tc, root); printf(" replay part (damage full, clip part): %08x\n", t[where]);
+ memcpy(t, before, (size_t)SW * SH * 4); ui.damage = o.painted[0]; canvas_set_clip(&tc, (Rect){0,0,SW,SH}); canvas_clear(&tc, 0); paint_root(&tc, root); printf(" replay (damage part, clip full): %08x\n", t[where]);
+ paint_tf_nocache = 0; ui.damage = (Box){0,0,0,0}; }
+ { int keepm = paint_multi_damage, w3 = 0; paint_multi_damage = 0; sim_full_differs(root, o.scene, &w3); printf(" reference without cull: %08x\n", sim_ref[where]); paint_multi_damage = keepm; sim_full_differs(root, o.scene, &w3); }
+ for (int dy2 = -3; dy2 <= 3; dy2++) { printf(" row %d:", dy2); for (int dx2 = -3; dx2 <= 3; dx2++) printf(" %06x/%06x", sim_ref[where + dy2 * SW + dx2] & 0xffffff, o.scene[where + dy2 * SW + dx2] & 0xffffff); printf("\n"); }
+ for (int i = 2; i < ui.cap; i++) {
+ Node *n = ui.nodes[i];
+ if (!n || n->type == NODE_RAW || n->s.display_none) continue;
+ n->s.display_none = 1;
+ int w2 = 0;
+ sim_full_differs(root, o.scene, &w2);
+ if (sim_ref[where] != want) printf(" hiding node %d changes the reference pixel to %08x\n", i, sim_ref[where]);
+ n->s.display_none = 0;
+ }
+ sim_full_differs(root, o.scene, &where);
+ for (int i = 0; i < ui.cap; i++) {
+ Node *n = ui.nodes[i];
+ if (!n || n->type == NODE_RAW) continue;
+ Box b = n->prev_box;
+ int inl = px >= n->ax && px < n->ax + n->w && py >= n->ay && py < n->ay + n->h;
+ if ((px < b.x0 || px >= b.x1 || py < b.y0 || py >= b.y1) && !inl) continue;
+ printf(" chain:");
+ for (Node *q = n->parent; q; q = q->parent) printf(" %d%s%s[op %.2f bg %08x at %.1f,%.1f %.1fx%.1f r %.1f]", q->id, q->s.overflow_hidden ? "(ovf)" : "", q->s.display_none ? "(none)" : "",
+ q->s.opacity, q->s.bg, q->ax, q->ay, q->w, q->h, q->s.radius);
+ printf(" kids:");
+ for (Node *q = n->first; q; q = q->next) printf(" %d", q->id);
+ printf("\n");
+ printf(" node %d parent %d at %.1f,%.1f %.1fx%.1f prev %.0f,%.0f %.0f,%.0f ovf %d rad %.1f bg %08x op %.2f z %d tf %d/%d blur %.1f\n", n->id, n->parent ? n->parent->id : 0,
+ n->ax, n->ay, n->w, n->h, b.x0, b.y0, b.x1, b.y1, n->s.overflow_hidden, n->s.radius, n->s.bg, n->s.opacity, (int)n->s.z_index, n->own_tf, n->has_tf, n->s.backdrop_blur);
+ }
+}
+
+static int fz_run(int seed, int frames, int pend_pct, int *multi_frames) {
+ rng_state = (uint32_t)seed * 2246822519u + 3;
+ ui_reset();
+ fz_n = 0;
+ Node *root = view(NULL);
+ ui.root = root;
+ sn(root, "backgroundColor", 0xff203040);
+ int init = getenv("FZ_INIT") ? atoi(getenv("FZ_INIT")) : 40;
+ for (int i = 0; i < init; i++) fz_add(root);
+ SimOut o;
+ sim_init(&o);
+ int bad = 0;
+ *multi_frames = 0;
+ for (int f = 0; f < frames; f++) {
+ if (getenv("FZ_LOG")) printf(" frame %d\n", f);
+ fz_step(root);
+ sim_paint_ui(&o, root);
+ if (o.flip_pending) {
+ if ((int)(rnd() % 100) < 50) { o.flip_pending = 0; o.front ^= 1; }
+ else continue;
+ }
+ int nparts = 0;
+ static uint32_t *before;
+ if (getenv("FZ_DEBUG")) { if (!before) before = malloc((size_t)SW * SH * 4); memcpy(before, o.scene, (size_t)SW * SH * 4); }
+ DamageList keep = o.pl;
+ Box keepb = o.pend;
+ Rect r = sim_paint_out(&o, root, &nparts);
+ if (nparts > 1) (*multi_frames)++;
+ int where = 0, worst = sim_full_differs(root, o.scene, &where);
+ /* a frame fails with a pixel off by more than 24 levels (FZ_STRICT: by more than 2; FZ_AREA=n:
+ * with n such pixels); the antialiased edges of a blurred node inside a scaled, unclipped
+ * subtree move a few levels with the subtree's extent (its raster's edge), test_damage_fuzz */
+ if (getenv("FZ_AREA") ? sim_bad_px < atoi(getenv("FZ_AREA")) : !getenv("FZ_STRICT") && !sim_bad_px) worst = 0;
+ if (worst > 2 && getenv("FZ_DEBUG") && !bad) fz_explain(root, &o, before, keep, keepb, where);
+ if (worst > 2) {
+ if (bad < 3) printf(" fuzz seed %d frame %d (%d parts): differs from a full repaint by %d at %d,%d (%d px off by more than 24)\n", seed, f, nparts, worst, where % SW, where / SW, sim_bad_px);
+ bad++;
+ }
+ int bi = sim_present(&o, r, (Rect){ 0, 0, 0, 0 });
+ if (memcmp(o.buf[bi], o.scene, (size_t)SW * SH * 4)) {
+ if (bad < 3) printf(" fuzz seed %d frame %d: the presented buffer differs from the scene\n", seed, f);
+ bad++;
+ }
+ if ((int)(rnd() % 100) < pend_pct) o.flip_pending = 1;
+ else o.front = bi;
+ }
+ sim_free(&o);
+ return bad;
+}
+
+static void test_damage_fuzz(void) {
+ int seeds = getenv("FUZZ_SEEDS") ? atoi(getenv("FUZZ_SEEDS")) : 12, multi = 0, failed = 0;
+ for (int seed = 0; seed < seeds; seed++) {
+ if (getenv("FZ_ONLY") && atoi(getenv("FZ_ONLY")) != seed) continue;
+ paint_multi_damage = getenv("FZ_MULTI") ? atoi(getenv("FZ_MULTI")) : seed % 4 != 3;
+ int m = 0, bad = fz_run(seed, 60, (int[]){ 0, 40 }[seed % 2], &m);
+ multi += m;
+ failed += bad != 0;
+ CHECK(!bad, "damage fuzz seed %d (multi %d): %d frames differ", seed, paint_multi_damage, bad);
+ }
+ printf("damage fuzz: %d seeds, %d frames in several parts, %d seeds failed\n", seeds, multi, failed);
+ paint_multi_damage = 0;
+}
+
/* A row with a fixed child and one that grows (a list item: bullet + text): the growing child's
* wrapped height is measured at the width it gets, not the whole row's (0.8.2: the last line of a
@@ -1070,6 +1624,8 @@ int main(int argc, char **argv) {
test_backdrop_band();
test_multi_damage();
test_minimize_damage();
+ test_damage_pipeline();
+ test_damage_fuzz();
test_grow_wrap_height();
test_overlay_scrollbar();
printf("engine-test: %d checks, %d failures\n", checks, fails);