@geastack/engine 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +29 -0
  3. package/bitmap_font.cpp +165 -0
  4. package/canvas.cpp +4608 -0
  5. package/components/Button.d.ts +4 -0
  6. package/components/Button.tsx +32 -0
  7. package/components/Image.d.ts +3 -0
  8. package/components/Image.tsx +17 -0
  9. package/components/Text.d.ts +3 -0
  10. package/components/Text.tsx +9 -0
  11. package/components/View.d.ts +3 -0
  12. package/components/View.tsx +24 -0
  13. package/components/index.d.ts +8 -0
  14. package/components/index.ts +4 -0
  15. package/css/animation.h +252 -0
  16. package/css/declarative.h +131 -0
  17. package/css/easing.h +160 -0
  18. package/css/engine.h +223 -0
  19. package/css/interpolate.h +38 -0
  20. package/image_store.cpp +807 -0
  21. package/package.json +62 -0
  22. package/rasterized_font.cpp +570 -0
  23. package/touch_runtime.cpp +513 -0
  24. package/ui/absolute_leaf_refresh.cpp +279 -0
  25. package/ui/absolute_leaf_refresh.h +12 -0
  26. package/ui/canvas_element.cpp +2314 -0
  27. package/ui/canvas_element.h +353 -0
  28. package/ui/canvas_store.cpp +188 -0
  29. package/ui/canvas_store.h +59 -0
  30. package/ui/core.cpp +135 -0
  31. package/ui/css_atom.cpp +155 -0
  32. package/ui/css_atom.h +21 -0
  33. package/ui/dirty_regions.cpp +66 -0
  34. package/ui/dirty_regions.h +34 -0
  35. package/ui/display_invalidation.cpp +101 -0
  36. package/ui/display_invalidation.h +15 -0
  37. package/ui/document.cpp +356 -0
  38. package/ui/document.h +101 -0
  39. package/ui/image.h +16 -0
  40. package/ui/image_element.cpp +13 -0
  41. package/ui/image_node.cpp +165 -0
  42. package/ui/input.cpp +936 -0
  43. package/ui/input_render.cpp +213 -0
  44. package/ui/internal.h +567 -0
  45. package/ui/layout.cpp +2025 -0
  46. package/ui/layout_snapshot.cpp +82 -0
  47. package/ui/layout_snapshot.h +12 -0
  48. package/ui/mirror.h +25 -0
  49. package/ui/node.cpp +243 -0
  50. package/ui/node.h +154 -0
  51. package/ui/node_lifecycle.cpp +137 -0
  52. package/ui/node_lifecycle.h +13 -0
  53. package/ui/node_model.h +597 -0
  54. package/ui/refresh_perf.h +235 -0
  55. package/ui/refresh_trace.h +68 -0
  56. package/ui/render.cpp +12097 -0
  57. package/ui/root_scroll_refresh.cpp +859 -0
  58. package/ui/root_scroll_refresh.h +30 -0
  59. package/ui/state_init.h +21 -0
  60. package/ui/style.cpp +14994 -0
  61. package/ui/style.h +727 -0
  62. package/ui/style_values.h +31 -0
  63. package/ui/text.cpp +2010 -0
  64. package/ui/text.h +15 -0
  65. package/ui/text_element.cpp +15 -0
  66. package/ui/tree_events.cpp +621 -0
  67. package/ui/tree_events.h +69 -0
  68. package/ui/tree_internal.h +191 -0
  69. package/ui/tree_nodes.cpp +628 -0
  70. package/ui/tree_render.cpp +3138 -0
  71. package/ui/tree_scroll_mirror.cpp +101 -0
  72. package/ui/tree_state.cpp +574 -0
  73. package/ui/tree_state.h +235 -0
  74. package/ui/tree_style.cpp +698 -0
  75. package/ui/ui.h +9 -0
  76. package/ui/view.cpp +2232 -0
  77. package/ui/view.h +14 -0
  78. package/ui/view_element.cpp +13 -0
  79. package/ui/viewport_region.cpp +36 -0
  80. package/ui/viewport_region.h +12 -0
  81. package/ui/virtual_keyboard.cpp +908 -0
  82. package/ui/virtual_keyboard.h +59 -0
  83. package/vendor/AnimatedGIF/AnimatedGIF.c +982 -0
  84. package/vendor/AnimatedGIF/AnimatedGIF.h +216 -0
  85. package/vendor/stb/stb_image.h +7988 -0
  86. package/vendor/stb/stb_truetype.h +5079 -0
@@ -0,0 +1,859 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ #include "root_scroll_refresh.h"
3
+
4
+ #include "display.h"
5
+ #include "internal.h"
6
+ #include "layout_snapshot.h"
7
+ #include "refresh_perf.h"
8
+ #include "tree_state.h"
9
+ #include "viewport_region.h"
10
+
11
+ #include <algorithm>
12
+ #include <cstdlib>
13
+
14
+ // When the platform's Display::scrollRect needs no framebuffer flush of the
15
+ // scrolled region itself (e.g. rp2350 driving the panel's hardware vertical
16
+ // scroll register), the final flush only needs the replayed damage rects —
17
+ // strip, scrollbar, slots, extras — instead of the canvas dirty bounding box
18
+ // that the region-wide scroll would otherwise inflate to.
19
+ #ifndef GEA_EMBEDDED_DISPLAY_SCROLLRECT_SELF_FLUSHING
20
+ #define GEA_EMBEDDED_DISPLAY_SCROLLRECT_SELF_FLUSHING 0
21
+ #endif
22
+
23
+ // Translate-only display-list maintenance for pure vertical scroll frames
24
+ // (skips the per-frame clear()+recordNode()). On by default; a build can set
25
+ // this to 0 to A/B against the full-rebuild reference.
26
+ #ifndef GEA_EMBEDDED_ROOT_SCROLL_TRANSLATE
27
+ #define GEA_EMBEDDED_ROOT_SCROLL_TRANSLATE 1
28
+ #endif
29
+
30
+ namespace gea::embedded::ui {
31
+
32
+ namespace {
33
+
34
+ bool hasTransformState(const Node &node)
35
+ {
36
+ return rstyle(node.style).transform_rotate != 0 ||
37
+ node.render.previous_transform_rotate != 0 ||
38
+ rstyle(node.style).transform_rotate_x != 0 ||
39
+ node.render.previous_transform_rotate_x != 0 ||
40
+ rstyle(node.style).transform_rotate_y != 0 ||
41
+ node.render.previous_transform_rotate_y != 0 ||
42
+ rstyle(node.style).transform_translate_x != 0 ||
43
+ node.render.previous_transform_translate_x != 0 ||
44
+ rstyle(node.style).transform_translate_y != 0 ||
45
+ node.render.previous_transform_translate_y != 0 ||
46
+ rstyle(node.style).transform_translate_z != 0 ||
47
+ node.render.previous_transform_translate_z != 0 ||
48
+ rstyle(node.style).transform_translate_x_percent != 0 ||
49
+ node.render.previous_transform_translate_x_percent != 0 ||
50
+ rstyle(node.style).transform_translate_y_percent != 0 ||
51
+ node.render.previous_transform_translate_y_percent != 0 ||
52
+ rstyle(node.style).transform_scale_x != 1000 ||
53
+ node.render.previous_transform_scale_x != 1000 ||
54
+ rstyle(node.style).transform_scale_y != 1000 ||
55
+ node.render.previous_transform_scale_y != 1000 ||
56
+ rstyle(node.style).perspective > 0 ||
57
+ node.render.previous_perspective > 0;
58
+ }
59
+
60
+ constexpr int kMaxExtraDirtyNodes = 8;
61
+ // One full recycled-slot pool: a fast fling can rewindow every slot of a
62
+ // <virtual-list> in a single tick.
63
+ constexpr int kMaxSlotRepositionNodes = 24;
64
+
65
+ bool layoutUnchanged(const Node &n)
66
+ {
67
+ return n.layout.x == n.layout.previous_x && n.layout.y == n.layout.previous_y &&
68
+ n.layout.width == n.layout.previous_width && n.layout.height == n.layout.previous_height;
69
+ }
70
+
71
+ bool isDescendantOf(const TreeState &state, int node, int ancestor)
72
+ {
73
+ for (int cursor = state.nodes[node].parent; cursor >= 0; cursor = state.nodes[cursor].parent) {
74
+ if (cursor == ancestor) return true;
75
+ }
76
+ return false;
77
+ }
78
+
79
+ bool hasRightFadeMask(const TreeState &state, int node)
80
+ {
81
+ for (int cursor = node; cursor >= 0; cursor = state.nodes[cursor].parent) {
82
+ if (state.nodes[cursor].style.mask_right_fade_width > 0) return true;
83
+ }
84
+ return false;
85
+ }
86
+
87
+ // A <virtual-list> windows a pool of absolutely-positioned slot children whose
88
+ // `top` the app rebinds as the scroll advances. Those style writes only land in
89
+ // layout via a layout pass — which this fast path skips — so without native
90
+ // reconciliation the rebuilt display list records recycled slots at their STALE
91
+ // positions and the revealed strip replays blank rows. Detect them here and let
92
+ // refresh() reposition them in place (mirroring the layout engine's
93
+ // absolute-child math), keeping the blit + strip replay path valid for every
94
+ // momentum tick instead of falling back to a full relayout + repaint.
95
+ bool isSlotRepositionCandidate(const TreeState &state, int node, int scrollNode)
96
+ {
97
+ const Node &n = state.nodes[node];
98
+ if (n.parent != scrollNode) return false;
99
+ if (state.nodes[scrollNode].type != NodeType::VirtualList) return false;
100
+ // The list is the slot's containing block only when it is itself positioned
101
+ // (matches containingBlockForAbsoluteNode in the layout engine).
102
+ const auto parentPosition = state.nodes[scrollNode].style.position;
103
+ if (parentPosition != 1 && parentPosition != 2) return false;
104
+ if (n.style.position != 1) return false;
105
+ // Anchored via top/bottom (the windowed axis); refresh() recomputes y from
106
+ // these offsets directly.
107
+ if (n.style.pos_offsets[0] == kUnset && n.style.pos_offset_percent[0] == kUnset &&
108
+ n.style.pos_offsets[2] == kUnset && n.style.pos_offset_percent[2] == kUnset)
109
+ return false;
110
+ if (hasTransformState(n)) return false;
111
+ // The reconcile translates the slot box; a pending size change needs layout.
112
+ if (n.layout.width != n.layout.previous_width || n.layout.height != n.layout.previous_height)
113
+ return false;
114
+ return true;
115
+ }
116
+
117
+ int resolvedSlotOffset(const Node &slot, int side, int basis)
118
+ {
119
+ int offset = slot.style.pos_offsets[side] != kUnset ? slot.style.pos_offsets[side] : 0;
120
+ const int percent = slot.style.pos_offset_percent[side];
121
+ if (percent != kUnset) {
122
+ const int numerator = basis * percent;
123
+ offset += (numerator + (numerator >= 0 ? 500 : -500)) / 1000;
124
+ }
125
+ return offset;
126
+ }
127
+
128
+ void translateSlotDescendants(TreeState &state, int node, int dx, int dy)
129
+ {
130
+ if (dx == 0 && dy == 0) return;
131
+ for (int child = state.nodes[node].first_child; child >= 0; child = state.nodes[child].next_sibling) {
132
+ state.nodes[child].layout.x += dx;
133
+ state.nodes[child].layout.y += dy;
134
+ translateSlotDescendants(state, child, dx, dy);
135
+ }
136
+ }
137
+
138
+ // Mirror of ViewRenderer::recordScrollbar's thumb math (view.cpp:209-243),
139
+ // exposed so the root-scroll refresh can compute old and new thumb bounds
140
+ // for a non-virtual-list scroll node and damage only the diff between them.
141
+ // Returns false when no scrollbar would be drawn for this node.
142
+ bool nonVirtualListScrollbarThumbBounds(const Node &n, int scrollTop, int *thumbY, int *thumbH)
143
+ {
144
+ if (n.layout.height <= 0) return false;
145
+ if (n.layout.scroll_content_height <= n.layout.height) return false;
146
+ const int track_h = n.layout.height - 12;
147
+ if (track_h < 24) return false;
148
+ int thumb_h = (n.layout.height * track_h) / n.layout.scroll_content_height;
149
+ if (thumb_h < 24) thumb_h = 24;
150
+ if (thumb_h > track_h) thumb_h = track_h;
151
+ const int max_scroll = n.layout.scroll_content_height - n.layout.height;
152
+ int y = n.layout.y + 6;
153
+ if (max_scroll > 0)
154
+ y += (scrollTop * (track_h - thumb_h)) / max_scroll;
155
+ if (thumbY) *thumbY = y;
156
+ if (thumbH) *thumbH = thumb_h;
157
+ return true;
158
+ }
159
+
160
+ // Mirror of LayoutNodePass::resolveRowDirection (layout.cpp): an explicit
161
+ // flex-direction or display:flex wins; otherwise a plain block flows its
162
+ // children as a row exactly when every in-flow child is inline-level (CSS
163
+ // inline formatting), and stacks them as a column otherwise.
164
+ bool flowsChildrenAsRow(const TreeState &state, const Node &p)
165
+ {
166
+ if (usesRowLayout(p.style)) return true;
167
+ if (p.style.flex_direction_explicit || p.style.display != kDisplayBlock) return false;
168
+ bool anyInFlow = false;
169
+ for (int c = p.first_child; c >= 0; c = state.nodes[c].next_sibling) {
170
+ const Node &child = state.nodes[c];
171
+ if (child.style.display == kDisplayNone || child.style.position == 1) continue;
172
+ if (!LayoutEngine::isInlineLevelNode(child)) return false;
173
+ anyInFlow = true;
174
+ }
175
+ return anyInFlow;
176
+ }
177
+
178
+ // A left-anchored re-measure moves where the layout engine would place every
179
+ // later sibling on the line: positionLineChildren advances its main-axis
180
+ // cursor by each child's box. The fast path runs no layout, so a recycled
181
+ // row's trailing spans (the pixel-value rail after the "#1234" index label)
182
+ // otherwise keep the PREVIOUS binding's offsets for the whole fling and only
183
+ // snap over at the settle relayout. Mirror the cursor in place: shift the
184
+ // following in-flow siblings by the main-axis delta. Only shapes the cursor
185
+ // math fully determines are mirrored — a single non-wrapping flex-start line
186
+ // with no flex-grow children (wrap re-lines, justify redistributes, flex
187
+ // resizes) — anything else keeps the stale-until-settle behaviour. The caller
188
+ // guarantees the moved siblings' pixels are replayed (a dirty slot's old/new
189
+ // rects cover its whole row).
190
+ void shiftSiblingsForRemeasuredText(TreeState &state, int id, int oldWidth, int oldHeight)
191
+ {
192
+ const Node &n = state.nodes[id];
193
+ const Node &p = state.nodes[n.parent];
194
+ if (p.style.flex_wrap || p.style.justify_content != 0) return;
195
+ const bool row = flowsChildrenAsRow(state, p);
196
+ const int delta = row ? n.layout.width - oldWidth : n.layout.height - oldHeight;
197
+ if (delta == 0) return;
198
+ int totalFlex = 0;
199
+ for (int c = p.first_child; c >= 0; c = state.nodes[c].next_sibling) {
200
+ const Node &child = state.nodes[c];
201
+ if (child.style.display == kDisplayNone || child.style.position == 1) continue;
202
+ totalFlex += child.style.flex;
203
+ }
204
+ if (totalFlex > 0) return;
205
+ for (int c = n.next_sibling; c >= 0; c = state.nodes[c].next_sibling) {
206
+ Node &sib = state.nodes[c];
207
+ if (sib.style.display == kDisplayNone || sib.style.position == 1) continue;
208
+ if (row) sib.layout.x += delta;
209
+ else sib.layout.y += delta;
210
+ translateSlotDescendants(state, c, row ? delta : 0, row ? 0 : delta);
211
+ }
212
+ }
213
+
214
+ // Re-measure a rebound text node in place. The fast path runs no layout, but
215
+ // the display-list rebuild records text wrapped/clipped by layout.width — so a
216
+ // string that grew past its stale box truncates ("#111" drawing as "#11") for
217
+ // the whole fling, snapping right only at the settle frame's full relayout.
218
+ // Fresh string, fresh box instead. Right-flush text (a space-between flex
219
+ // row's trailing column, e.g. HUD value rails) keeps its right edge so the
220
+ // grown box stays inside the parent; everything else keeps its left anchor —
221
+ // and, when the caller's replay rects cover the parent's pixels
222
+ // (siblingsCoveredByReplay), the following in-flow siblings shift with the
223
+ // new width so they don't sit at the previous binding's offsets mid-fling.
224
+ // text_layout_stable stays 0, so the settle frame still runs the full layout
225
+ // that reflows siblings and exact flex alignment.
226
+ void remeasureDirtyTextInPlace(TreeState &state, int id, bool siblingsCoveredByReplay)
227
+ {
228
+ Node &n = state.nodes[id];
229
+ if (n.type != NodeType::Text || n.render.text_layout_stable || n.first_child >= 0) return;
230
+ if (hasTransformState(n)) return;
231
+ const int oldWidth = n.layout.width;
232
+ const int oldHeight = n.layout.height;
233
+ if (n.parent < 0) {
234
+ TextRenderer::remeasureContentBox(id);
235
+ return;
236
+ }
237
+ const Node &p = state.nodes[n.parent];
238
+ if (!flowsChildrenAsRow(state, p)) {
239
+ // Column flow (block-level text stacking). The default align stretch
240
+ // gives the box the parent's full content width, so its right edge
241
+ // ALWAYS touches the parent's — the row path's right-flush heuristic
242
+ // below would misread that as a right-flush rail and throw the rebound
243
+ // glyphs to the right edge for the whole fling (settle relayout then
244
+ // snaps them back left). The box geometry is independent of the string
245
+ // here: keep the stretched box, re-wrap the new text within it, and
246
+ // shift the following stacked siblings by any height delta. Hugged
247
+ // (non-stretch / explicit-width) boxes re-measure naturally and keep
248
+ // their left anchor — the cross axis never right-flushes by default.
249
+ const int align = n.style.align_self >= 0 ? n.style.align_self : p.style.align_items;
250
+ const bool stretched = align == 0 && n.style.width == kUnset && n.style.width_percent == kUnset;
251
+ if (!TextRenderer::remeasureContentBox(id, stretched)) return;
252
+ if (siblingsCoveredByReplay) shiftSiblingsForRemeasuredText(state, id, oldWidth, oldHeight);
253
+ return;
254
+ }
255
+ if (!TextRenderer::remeasureContentBox(id)) return;
256
+ const int oldRight = n.layout.x + oldWidth + n.style.margin[1];
257
+ const int parentRight = p.layout.x + p.layout.width - p.style.padding[1];
258
+ if (oldRight == parentRight) {
259
+ n.layout.x += oldWidth - n.layout.width;
260
+ return;
261
+ }
262
+ if (siblingsCoveredByReplay) shiftSiblingsForRemeasuredText(state, id, oldWidth, oldHeight);
263
+ }
264
+
265
+ bool dirtyBounds(const Node &n, int width, int height, RootScrollOnlyRefresh::DirtyNode *out)
266
+ {
267
+ int x0 = width, y0 = height, x1 = -1, y1 = -1;
268
+ if (n.layout.previous_width > 0 && n.layout.previous_height > 0) {
269
+ ViewRenderer::transformedBounds(n, true, &x0, &y0, &x1, &y1);
270
+ }
271
+ if (n.layout.width > 0 && n.layout.height > 0) {
272
+ int nx0, ny0, nx1, ny1;
273
+ ViewRenderer::transformedBounds(n, false, &nx0, &ny0, &nx1, &ny1);
274
+ if (nx0 < x0) x0 = nx0;
275
+ if (ny0 < y0) y0 = ny0;
276
+ if (nx1 > x1) x1 = nx1;
277
+ if (ny1 > y1) y1 = ny1;
278
+ }
279
+ if (x0 > x1 || y0 > y1) return false;
280
+ if (x0 < 0) x0 = 0;
281
+ if (y0 < 0) y0 = 0;
282
+ if (x1 >= width) x1 = width - 1;
283
+ if (y1 >= height) y1 = height - 1;
284
+ if (x0 > x1 || y0 > y1) return false;
285
+ out->x0 = x0;
286
+ out->y0 = y0;
287
+ out->x1 = x1;
288
+ out->y1 = y1;
289
+ return true;
290
+ }
291
+
292
+ } // namespace
293
+
294
+ int RootScrollOnlyRefresh::refreshNode(int root,
295
+ DirtyNode *extraDirtyNodes,
296
+ int *extraDirtyCount,
297
+ int *slotNodes,
298
+ int *slotCount,
299
+ int width,
300
+ int height)
301
+ {
302
+ (void)root;
303
+ auto &state = treeState();
304
+ int foundNode = -1;
305
+ *extraDirtyCount = 0;
306
+ *slotCount = 0;
307
+
308
+ // Pass 1: exactly one pure-scroll node.
309
+ for (int i = 0; i < state.nodeCount; i++) {
310
+ Node *n = &state.nodes[i];
311
+ if (!n->render.dirty) continue;
312
+
313
+ if (n->render.scroll_dirty && !n->render.non_scroll_dirty) {
314
+ if (foundNode >= 0) return -1;
315
+ if (!isViewLikeNodeType(n->type) || n->style.display == 1) return -1;
316
+ // Accept a pure scroll on exactly one axis the node overflows. The
317
+ // horizontal case mirrors the vertical fast path (see refresh()): a
318
+ // virtual-list is vertical-only. Rejecting a both-axes change keeps the
319
+ // single-axis scrollRect blit unambiguous.
320
+ const bool changedY = n->layout.scroll_y != n->layout.previous_scroll_y;
321
+ const bool changedX = n->layout.scroll_x != n->layout.previous_scroll_x;
322
+ const bool canScrollYAxis = n->type == NodeType::VirtualList || scrollsOverflowY(n->style);
323
+ const bool canScrollXAxis = n->type != NodeType::VirtualList && scrollsOverflowX(n->style);
324
+ const bool vertical = changedY && !changedX && canScrollYAxis;
325
+ const bool horizontal = changedX && !changedY && canScrollXAxis;
326
+ if (!vertical && !horizontal) return -1;
327
+ if (!layoutUnchanged(*n)) return -1;
328
+ if (hasTransformState(*n)) return -1;
329
+ if (n->style.opacity != 255 || hasAnyBorder(n->style)) return -1;
330
+ for (int r = 0; r < 4; r++) {
331
+ if (n->style.border_radius[r] != 0 || n->style.border_radius_percent[r] != kUnset) return -1;
332
+ }
333
+ foundNode = i;
334
+ continue;
335
+ }
336
+
337
+ if (n->render.scroll_dirty) return -1;
338
+ }
339
+ if (foundNode < 0) return -1;
340
+
341
+ // Overlay guard: scrollRect shifts EVERY framebuffer pixel in the scroll
342
+ // viewport, so it is only valid when those pixels belong to the scroll
343
+ // subtree. A node outside the subtree that overlaps the viewport would be
344
+ // dragged with the content. Right-fade masks already disable scrollRect and
345
+ // re-rasterize the complete viewport from the rebuilt root display list; in
346
+ // that branch overlapping siblings are composited afresh, so rejecting them
347
+ // would unnecessarily force a full-tree refresh (the weather city rail has
348
+ // exactly this shape because its negative margin overlaps the hero).
349
+ if (!hasRightFadeMask(state, foundNode)) {
350
+ const Node &sn = state.nodes[foundNode];
351
+ const int svx0 = sn.layout.x, svy0 = sn.layout.y;
352
+ const int svx1 = sn.layout.x + sn.layout.width - 1;
353
+ const int svy1 = sn.layout.y + sn.layout.height - 1;
354
+ for (int i = 0; i < state.nodeCount; i++) {
355
+ if (i == foundNode) continue;
356
+ const Node &o = state.nodes[i];
357
+ if (o.style.display == 1 || o.style.opacity == 0) continue;
358
+ if (o.layout.width <= 0 || o.layout.height <= 0) continue;
359
+ // Skip the scroll node's own subtree and its ancestor chain — and any
360
+ // node inside a display:none subtree: a hidden ancestor removes the
361
+ // whole branch from painting even though the descendants' own display
362
+ // stays 0, so they can never contribute viewport pixels the scrollRect
363
+ // shift would drag. (A reader page hidden under a full-screen Contents
364
+ // panel otherwise rejected every scroll frame through its children.)
365
+ bool related = false;
366
+ bool hidden = false;
367
+ for (int a = i; a >= 0; a = state.nodes[a].parent) {
368
+ if (a == foundNode) { related = true; break; }
369
+ if (state.nodes[a].style.display == 1) { hidden = true; break; }
370
+ }
371
+ if (related || hidden) continue;
372
+ for (int a = foundNode; a >= 0; a = state.nodes[a].parent) {
373
+ if (a == i) { related = true; break; }
374
+ }
375
+ if (related) continue;
376
+ if (o.layout.x > svx1 || o.layout.x + o.layout.width - 1 < svx0 ||
377
+ o.layout.y > svy1 || o.layout.y + o.layout.height - 1 < svy0)
378
+ continue;
379
+ return -1;
380
+ }
381
+ }
382
+
383
+ // Pass 2: classify every other dirty node. Recycled slot children of a
384
+ // scrolling <virtual-list> get repositioned natively by refresh(); their
385
+ // dirty descendants (rebound label text, recolored row content) are covered
386
+ // by the slot's old/new-rect replays over the rebuilt display list, so they
387
+ // are skipped here — including ones whose pre-measured text box changed,
388
+ // which would otherwise reject the whole frame back to the full-relayout
389
+ // path on every fling tick.
390
+ for (int i = 0; i < state.nodeCount; i++) {
391
+ Node *n = &state.nodes[i];
392
+ if (!n->render.dirty || i == foundNode) continue;
393
+
394
+ if (isSlotRepositionCandidate(state, i, foundNode)) {
395
+ if (*slotCount >= kMaxSlotRepositionNodes) return -1;
396
+ slotNodes[(*slotCount)++] = i;
397
+ continue;
398
+ }
399
+
400
+ // Skipping is only safe when the ancestor slot is itself dirty: only then
401
+ // does refresh() replay its old/new rects. A clean slot with a dirty
402
+ // child keeps the regular extra-dirty handling below.
403
+ bool insideSlot = false;
404
+ for (int cursor = n->parent; cursor >= 0; cursor = state.nodes[cursor].parent) {
405
+ if (cursor == foundNode) break;
406
+ if (state.nodes[cursor].render.dirty && isSlotRepositionCandidate(state, cursor, foundNode)) {
407
+ insideSlot = true;
408
+ break;
409
+ }
410
+ }
411
+ if (insideSlot) {
412
+ // Rebound slot text draws from the rebuilt display list, which wraps
413
+ // and clips by the node's measured box — refresh the box so the new
414
+ // label isn't truncated to the old one's width. The slot's old/new
415
+ // rect replays already cover the pixels, including the in-flow
416
+ // siblings the remeasure shifts along the line.
417
+ remeasureDirtyTextInPlace(state, i, true);
418
+ continue;
419
+ }
420
+
421
+ // No replay rect covers this node's siblings (only its own dirtyBounds
422
+ // below), so the remeasure must not move them.
423
+ remeasureDirtyTextInPlace(state, i, false);
424
+ // `layoutUnchanged` compares the LAST LAID-OUT box against the PREVIOUS
425
+ // laid-out box, so a node whose style geometry just changed but which has
426
+ // not been laid out since reads "unchanged" and is admitted as paint-only.
427
+ // The pending relayout is then lost for good: this path clears the dirt
428
+ // and returns, and no later refresh recovers it. That is how dismissing
429
+ // the virtual keyboard left `.todo-app` at its shrunken height --
430
+ // `restoreAppResize` writes Height/Flex/Overflow/Position in the same
431
+ // frame the list is still scroll-dirty, and this path claimed the frame.
432
+ // Consult the pending flag, not just the two laid-out boxes; the sibling
433
+ // fast path already screens on exactly this pair (`absolute_leaf_refresh.cpp`).
434
+ if (n->render.layout_dirty &&
435
+ ((n->style.height != kUnset && n->style.height != n->layout.height) ||
436
+ (n->style.width != kUnset && n->style.width != n->layout.width))) {
437
+ return -1;
438
+ }
439
+ if (!layoutUnchanged(*n)) {
440
+ // A re-measured text box is the one layout change this path accepts:
441
+ // dirtyBounds below unions the old and new boxes so the replay covers
442
+ // both, and the anchor stayed put. Anything else still rejects to the
443
+ // full-relayout path.
444
+ const bool remeasuredTextBox = n->type == NodeType::Text &&
445
+ !n->render.text_layout_stable &&
446
+ n->layout.y == n->layout.previous_y;
447
+ if (!remeasuredTextBox) return -1;
448
+ }
449
+ if (*extraDirtyCount >= kMaxExtraDirtyNodes) return -1;
450
+ DirtyNode dirty{};
451
+ dirty.id = i;
452
+ if (dirtyBounds(*n, width, height, &dirty))
453
+ extraDirtyNodes[(*extraDirtyCount)++] = dirty;
454
+ }
455
+ return foundNode;
456
+ }
457
+
458
+ void RootScrollOnlyRefresh::shiftDescendantLayoutY(int id, int dy)
459
+ {
460
+ if (dy == 0) return;
461
+ auto &state = treeState();
462
+ for (int c = state.nodes[id].first_child; c >= 0; c = state.nodes[c].next_sibling) {
463
+ state.nodes[c].layout.y += dy;
464
+ shiftDescendantLayoutY(c, dy);
465
+ }
466
+ }
467
+
468
+ void RootScrollOnlyRefresh::shiftDescendantLayoutX(int id, int dx)
469
+ {
470
+ if (dx == 0) return;
471
+ auto &state = treeState();
472
+ for (int c = state.nodes[id].first_child; c >= 0; c = state.nodes[c].next_sibling) {
473
+ state.nodes[c].layout.x += dx;
474
+ shiftDescendantLayoutX(c, dx);
475
+ }
476
+ }
477
+
478
+ int RootScrollOnlyRefresh::refresh(int root, int width, int height)
479
+ {
480
+ auto &state = treeState();
481
+ auto &perf = refreshPerfStatsMutable();
482
+ perf.rootScrollCalls++;
483
+ DirtyNode extraDirtyNodes[kMaxExtraDirtyNodes];
484
+ int extraDirtyCount = 0;
485
+ int slotNodes[kMaxSlotRepositionNodes];
486
+ int slotCount = 0;
487
+ const std::int64_t scanStartUs = refreshPerfNowUs();
488
+ int scroll_node = refreshNode(root, extraDirtyNodes, &extraDirtyCount, slotNodes, &slotCount, width, height);
489
+ perf.rootScrollScanUs += refreshPerfNowUs() - scanStartUs;
490
+ if (scroll_node < 0) {
491
+ perf.rootScrollRejected++;
492
+ return 0;
493
+ }
494
+ perf.rootScrollAccepted++;
495
+ perf.rootScrollExtraDirtyNodes += extraDirtyCount;
496
+
497
+ Node *n = &state.nodes[scroll_node];
498
+ // refreshNode accepted a pure single-axis scroll; derive which axis moved.
499
+ const bool horizontal = n->layout.scroll_x != n->layout.previous_scroll_x;
500
+ const int scroll_delta = horizontal ? (n->layout.scroll_x - n->layout.previous_scroll_x)
501
+ : (n->layout.scroll_y - n->layout.previous_scroll_y);
502
+ const int move = -scroll_delta;
503
+ const int abs_move = move < 0 ? -move : move;
504
+
505
+ // Children's resolved coords already encode the previous scroll (layout applies
506
+ // `x -= scroll_x` / `y -= scroll_y`); skipping layout, we apply only this
507
+ // frame's delta along the scrolled axis to keep them in sync.
508
+ if (horizontal) shiftDescendantLayoutX(scroll_node, move);
509
+ else shiftDescendantLayoutY(scroll_node, move);
510
+
511
+ // Reconcile repositioned <virtual-list> slots natively (mirrors the layout
512
+ // engine's absolute-child resolution: the positioned list is the containing
513
+ // block, so y = list.y - scroll_y + top). This runs after the scroll shift
514
+ // and before the display-list rebuild, so recycled slots record at their
515
+ // fresh positions without a layout pass; their old and new rects are
516
+ // replayed after the strip below. Width/height stay as laid out — a slot
517
+ // rebind only moves the box.
518
+ struct SlotDamage {
519
+ int oldX0, oldY0, oldX1, oldY1;
520
+ int newX0, newY0, newX1, newY1;
521
+ bool moved;
522
+ };
523
+ SlotDamage slotDamage[kMaxSlotRepositionNodes];
524
+ for (int s = 0; s < slotCount; s++) {
525
+ Node &slot = state.nodes[slotNodes[s]];
526
+ SlotDamage &damage = slotDamage[s];
527
+ damage.oldX0 = slot.layout.x;
528
+ damage.oldY0 = slot.layout.y;
529
+ damage.oldX1 = slot.layout.x + slot.layout.width - 1;
530
+ damage.oldY1 = slot.layout.y + slot.layout.height - 1;
531
+ damage.moved = false;
532
+ if (slot.style.display == 1) continue; // display:none — erase old rect only
533
+
534
+ int newX = slot.layout.x;
535
+ if (slot.style.pos_offsets[3] != kUnset || slot.style.pos_offset_percent[3] != kUnset)
536
+ newX = n->layout.x + resolvedSlotOffset(slot, 3, n->layout.width);
537
+ else if (slot.style.pos_offsets[1] != kUnset || slot.style.pos_offset_percent[1] != kUnset)
538
+ newX = n->layout.x + n->layout.width - slot.layout.width -
539
+ resolvedSlotOffset(slot, 1, n->layout.width);
540
+
541
+ int newY = slot.layout.y;
542
+ if (slot.style.pos_offsets[0] != kUnset || slot.style.pos_offset_percent[0] != kUnset)
543
+ newY = n->layout.y - n->layout.scroll_y + resolvedSlotOffset(slot, 0, n->layout.height);
544
+ else if (slot.style.pos_offsets[2] != kUnset || slot.style.pos_offset_percent[2] != kUnset)
545
+ newY = n->layout.y - n->layout.scroll_y + n->layout.height - slot.layout.height -
546
+ resolvedSlotOffset(slot, 2, n->layout.height);
547
+
548
+ const int dx = newX - slot.layout.x;
549
+ const int dy = newY - slot.layout.y;
550
+ slot.layout.x = newX;
551
+ slot.layout.y = newY;
552
+ translateSlotDescendants(state, slotNodes[s], dx, dy);
553
+ damage.newX0 = newX;
554
+ damage.newY0 = newY;
555
+ damage.newX1 = newX + slot.layout.width - 1;
556
+ damage.newY1 = newY + slot.layout.height - 1;
557
+ damage.moved = dx != 0 || dy != 0;
558
+ }
559
+
560
+ int vx = n->layout.x;
561
+ int vy = n->layout.y;
562
+ int vw = n->layout.width;
563
+ int vh = n->layout.height;
564
+ if (!ViewportRegion::clipRect(width, height, &vx, &vy, &vw, &vh)) {
565
+ const std::int64_t snapshotStartUs = refreshPerfNowUs();
566
+ LayoutSnapshot::capture();
567
+ perf.rootScrollSnapshotUs += refreshPerfNowUs() - snapshotStartUs;
568
+ return 1;
569
+ }
570
+
571
+ // The scroll replay needs a display list whose commands match the
572
+ // post-shift layout, and recordNode drops commands for nodes outside the
573
+ // record clip — so off-viewport content has no commands until it scrolls
574
+ // in. Historically that forced a full clear()+recordNode() every scroll
575
+ // frame (~2ms). The translate-only path below skips it, mirroring the
576
+ // horizontal-pan fast path: record ONCE with the record clip expanded
577
+ // vertically by kScrollRecordPadding around the viewport (coverage), then
578
+ // per scroll frame just translate the scroll subtree's recorded commands
579
+ // in place (they follow shiftDescendantLayoutY), un-translate the scroll
580
+ // node's own viewport-fixed box, and patch the scrollbar thumb. Coverage
581
+ // is re-recorded when the accumulated scroll leaves the padded window or
582
+ // any other record replaced the list (recordSerial). Frames that change
583
+ // content (extra dirty nodes, virtual-list slot rebinds, horizontal
584
+ // scrolls) keep the plain full rebuild — a translate can't express them.
585
+ // (An earlier hybrid that recorded/cleared subtrees incrementally failed
586
+ // because DisplayList::replay() walks state.commands[] linearly and
587
+ // orphaned ranges kept replaying; wholesale translate avoids that
588
+ // entirely: no command is added or removed.)
589
+ {
590
+ static std::uint32_t coverageSerial = 0;
591
+ static int coverageRoot = -1;
592
+ static int coverageNode = -1;
593
+ static int coverageScrollY = 0;
594
+ static int coveragePadTop = 0;
595
+ static int coveragePadBottom = 0;
596
+ // Window fallback for content too tall to pre-record in one pass
597
+ // (command coords are int16, and the command buffer is finite).
598
+ constexpr int kScrollRecordFallbackPadding = 512;
599
+ constexpr int kMaxFullContentHeight = 16000;
600
+
601
+ auto &list = DisplayList::instance();
602
+ const int scrollYNow = n->layout.scroll_y;
603
+ const bool translateEligible = GEA_EMBEDDED_ROOT_SCROLL_TRANSLATE != 0 &&
604
+ !horizontal &&
605
+ n->type != NodeType::VirtualList &&
606
+ slotCount == 0 &&
607
+ extraDirtyCount == 0;
608
+ const int coverageDelta = scrollYNow - coverageScrollY;
609
+ const bool coverageValid = translateEligible &&
610
+ coverageRoot == root &&
611
+ coverageNode == scroll_node &&
612
+ coverageSerial == list.recordSerial() &&
613
+ coverageDelta >= -coveragePadTop &&
614
+ coverageDelta <= coveragePadBottom;
615
+
616
+ const std::int64_t rebuildStartUs = refreshPerfNowUs();
617
+ bool listReady = false;
618
+ if (coverageValid) {
619
+ list.translateSubtreeCommands(scroll_node, 0, move);
620
+ // translateSubtreeCommands includes the scroll node's own box
621
+ // commands (background/border), which are viewport-fixed — undo.
622
+ list.translateNodeCommands(scroll_node, 0, -move);
623
+ listReady = list.patchScrollbarThumb(scroll_node);
624
+ }
625
+ if (!listReady && translateEligible) {
626
+ // Pre-record the WHOLE scroll content when it fits: one record,
627
+ // replayed (translated) forever — scrolling never re-records. For
628
+ // very tall content, fall back to a padded window around the
629
+ // viewport; a truncated record (command-buffer overflow) also
630
+ // falls back so coverage is never silently incomplete.
631
+ int padTop = scrollYNow;
632
+ int padBottom = n->layout.scroll_content_height - scrollYNow - n->layout.height;
633
+ if (padBottom < 0) padBottom = 0;
634
+ if (n->layout.scroll_content_height > kMaxFullContentHeight) {
635
+ padTop = padTop < kScrollRecordFallbackPadding ? padTop : kScrollRecordFallbackPadding;
636
+ padBottom = padBottom < kScrollRecordFallbackPadding ? padBottom : kScrollRecordFallbackPadding;
637
+ }
638
+ for (int attempt = 0; attempt < 2 && !listReady; attempt++) {
639
+ list.clear();
640
+ list.recordNodeWithExpandedClip(root,
641
+ 255,
642
+ scroll_node,
643
+ vx,
644
+ vy - padTop,
645
+ vx + vw - 1,
646
+ vy + vh - 1 + padBottom);
647
+ list.weldTransformedFaces();
648
+ if (!list.commandOverflow()) {
649
+ listReady = true;
650
+ coverageSerial = list.recordSerial();
651
+ coverageRoot = root;
652
+ coverageNode = scroll_node;
653
+ coverageScrollY = scrollYNow;
654
+ coveragePadTop = padTop;
655
+ coveragePadBottom = padBottom;
656
+ break;
657
+ }
658
+ // Overflowed: retry once with the small window.
659
+ padTop = padTop < kScrollRecordFallbackPadding ? padTop : kScrollRecordFallbackPadding;
660
+ padBottom = padBottom < kScrollRecordFallbackPadding ? padBottom : kScrollRecordFallbackPadding;
661
+ }
662
+ if (listReady) state.displayListDirty = false;
663
+ }
664
+ if (!listReady) {
665
+ list.clear();
666
+ list.recordNode(root, 255);
667
+ state.displayListDirty = false;
668
+ coverageRoot = -1;
669
+ }
670
+ perf.rootScrollRebuildUs += refreshPerfNowUs() - rebuildStartUs;
671
+ }
672
+ perf.rootScrollMovePx += abs_move;
673
+ perf.rootScrollViewportPx += vw * vh;
674
+ perf.rootScrollStripPx += horizontal ? (vh * (abs_move < vw ? abs_move : vw))
675
+ : (vw * (abs_move < vh ? abs_move : vh));
676
+
677
+ gea::platform::display::Display::resetClip();
678
+ gea::platform::display::Display::setAlpha(255);
679
+ constexpr bool kSelfFlushingScroll = GEA_EMBEDDED_DISPLAY_SCROLLRECT_SELF_FLUSHING != 0;
680
+ constexpr int kMaxDamageRects = 24;
681
+ gea::platform::display::DisplayFlushRect damageRects[kMaxDamageRects];
682
+ int damageCount = 0;
683
+ bool damageOverflow = false;
684
+ auto noteDamage = [&](int rx, int ry, int rw, int rh) {
685
+ if (!kSelfFlushingScroll) return;
686
+ if (damageCount >= kMaxDamageRects) {
687
+ damageOverflow = true;
688
+ return;
689
+ }
690
+ damageRects[damageCount++] = {rx, ry, rx + rw - 1, ry + rh - 1};
691
+ };
692
+ gScrollRanThisFrame = true;
693
+ // Hold image blits only when scroll frames are CONSECUTIVE (live drag /
694
+ // fling); an isolated jump (row-snap commit) paints images inline.
695
+ const bool holdImages = gUiFrameCounter - gLastScrollUiFrame <= 3;
696
+ gLastScrollUiFrame = gUiFrameCounter;
697
+ auto replayScrollNodeRegion = [&](int rx, int ry, int rw, int rh) {
698
+ noteDamage(rx, ry, rw, rh);
699
+ gScrollStripReplayActive = holdImages;
700
+ ViewportRegion::replayDisplayRegion(rx, ry, rw, rh);
701
+ gScrollStripReplayActive = false;
702
+ };
703
+
704
+ // A right-edge fade mask (`mask-image: linear-gradient(..., transparent)`) makes
705
+ // each child's alpha depend on its X relative to the container's *fixed* right
706
+ // edge — it is NOT translation-invariant. The scrollRect blit below shifts the
707
+ // already-faded framebuffer pixels and only repaints the freshly-revealed edge
708
+ // strip, which drags the faded band along with the content (the gradient
709
+ // "scrolls like content" instead of staying pinned to the edge). recordNode
710
+ // above already rebuilt the display list with the per-child fade recomputed at
711
+ // the post-shift positions, so for a masked scroller we skip the blit and
712
+ // re-rasterize the whole viewport from that list — the fade stays anchored.
713
+ const bool contentHasRightFadeMask = hasRightFadeMask(state, scroll_node);
714
+
715
+ const int viewportExtent = horizontal ? vw : vh;
716
+ if (!contentHasRightFadeMask && abs_move > 0 && abs_move < viewportExtent) {
717
+ const std::int64_t scrollRectStartUs = refreshPerfNowUs();
718
+ gea::platform::display::Display::scrollRect(vx, vy, vw, vh, horizontal ? move : 0, horizontal ? 0 : move);
719
+ perf.rootScrollScrollRectUs += refreshPerfNowUs() - scrollRectStartUs;
720
+
721
+ const std::int64_t stripReplayStartUs = refreshPerfNowUs();
722
+ if (horizontal) {
723
+ // Repaint the newly-revealed vertical edge strip.
724
+ if (move < 0) replayScrollNodeRegion(vx + vw - abs_move, vy, abs_move, vh);
725
+ else replayScrollNodeRegion(vx, vy, abs_move, vh);
726
+ } else if (move < 0) {
727
+ replayScrollNodeRegion(vx, vy + vh - abs_move, vw, abs_move);
728
+ } else {
729
+ replayScrollNodeRegion(vx, vy, vw, abs_move);
730
+ }
731
+ perf.rootScrollStripReplayUs += refreshPerfNowUs() - stripReplayStartUs;
732
+
733
+ // Scrollbar damage is vertical-only: the horizontal forecast/rail rows use
734
+ // scrollbar-width:none and draw no thumb, so a horizontal scroll skips it.
735
+ if (!horizontal) {
736
+ const int move_y = move;
737
+ const std::int64_t scrollbarReplayStartUs = refreshPerfNowUs();
738
+ auto replayScrollbarDamage = [&](int damagedY, int damagedH) {
739
+ int sx = n->layout.x + n->layout.width - 10;
740
+ int sy = damagedY;
741
+ int sw = 10;
742
+ int sh = damagedH;
743
+ if (ViewportRegion::clipRect(width, height, &sx, &sy, &sw, &sh))
744
+ replayScrollNodeRegion(sx, sy, sw, sh);
745
+ };
746
+ int oldThumbY = 0, oldThumbH = 0;
747
+ int newThumbY = 0, newThumbH = 0;
748
+ const bool hasOldThumb = nonVirtualListScrollbarThumbBounds(
749
+ *n, n->layout.previous_scroll_y, &oldThumbY, &oldThumbH);
750
+ const bool hasNewThumb = nonVirtualListScrollbarThumbBounds(
751
+ *n, n->layout.scroll_y, &newThumbY, &newThumbH);
752
+ if (hasOldThumb && hasNewThumb) {
753
+ const int shiftedOldY = oldThumbY + move_y;
754
+ const int shiftedOldBottom = shiftedOldY + oldThumbH - 1;
755
+ const int newThumbBottom = newThumbY + newThumbH - 1;
756
+ if (shiftedOldBottom + 1 >= newThumbY && newThumbBottom + 1 >= shiftedOldY) {
757
+ const int damageY = shiftedOldY < newThumbY ? shiftedOldY : newThumbY;
758
+ const int damageBottom = shiftedOldBottom > newThumbBottom ? shiftedOldBottom : newThumbBottom;
759
+ replayScrollbarDamage(damageY, damageBottom - damageY + 1);
760
+ } else {
761
+ replayScrollbarDamage(shiftedOldY, oldThumbH);
762
+ replayScrollbarDamage(newThumbY, newThumbH);
763
+ }
764
+ } else {
765
+ replayScrollbarDamage(n->layout.y, n->layout.height);
766
+ }
767
+ perf.rootScrollScrollbarReplayUs += refreshPerfNowUs() - scrollbarReplayStartUs;
768
+ }
769
+ } else {
770
+ const std::int64_t fullReplayStartUs = refreshPerfNowUs();
771
+ replayScrollNodeRegion(vx, vy, vw, vh);
772
+ perf.rootScrollFullReplayUs += refreshPerfNowUs() - fullReplayStartUs;
773
+ }
774
+
775
+ // Repaint repositioned slots: the vacated box (now showing whatever sits
776
+ // beneath) and the destination box (the slot at its fresh position). Both
777
+ // replay the rebuilt display list clipped to the list viewport — slot pixels
778
+ // outside it are clipped by the list at record time anyway.
779
+ const std::int64_t slotReplayStartUs = refreshPerfNowUs();
780
+ auto replaySlotRect = [&](int x0, int y0, int x1, int y1) {
781
+ if (x0 < vx) x0 = vx;
782
+ if (y0 < vy) y0 = vy;
783
+ if (x1 > vx + vw - 1) x1 = vx + vw - 1;
784
+ if (y1 > vy + vh - 1) y1 = vy + vh - 1;
785
+ if (x0 > x1 || y0 > y1) return;
786
+ replayScrollNodeRegion(x0, y0, x1 - x0 + 1, y1 - y0 + 1);
787
+ };
788
+ // When abs_move >= viewportExtent the branch above already replayed the
789
+ // whole viewport from the fresh display list — per-slot rects would only
790
+ // repaint subsets of it.
791
+ if (abs_move < viewportExtent) {
792
+ for (int s = 0; s < slotCount; s++) {
793
+ const SlotDamage &damage = slotDamage[s];
794
+ replaySlotRect(damage.oldX0, damage.oldY0, damage.oldX1, damage.oldY1);
795
+ if (damage.moved)
796
+ replaySlotRect(damage.newX0, damage.newY0, damage.newX1, damage.newY1);
797
+ }
798
+ }
799
+ perf.rootScrollStripReplayUs += refreshPerfNowUs() - slotReplayStartUs;
800
+
801
+ const std::int64_t extraReplayStartUs = refreshPerfNowUs();
802
+ for (int i = 0; i < extraDirtyCount; i++) {
803
+ DirtyNode dirty = extraDirtyNodes[i];
804
+ // Bounds were computed before the scroll shift; content inside the
805
+ // scrolled container has since moved by `move` along the scrolled axis.
806
+ // Cover both the stale and shifted positions.
807
+ if (isDescendantOf(state, dirty.id, scroll_node)) {
808
+ if (horizontal) {
809
+ if (move < 0) dirty.x0 += move; else dirty.x1 += move;
810
+ } else {
811
+ if (move < 0) dirty.y0 += move; else dirty.y1 += move;
812
+ }
813
+ }
814
+ gea::platform::display::Display::resetClip();
815
+ gea::platform::display::Display::setAlpha(255);
816
+ gea::platform::display::Display::pushClip(dirty.x0, dirty.y0, dirty.x1 - dirty.x0 + 1, dirty.y1 - dirty.y0 + 1);
817
+ noteDamage(dirty.x0, dirty.y0, dirty.x1 - dirty.x0 + 1, dirty.y1 - dirty.y0 + 1);
818
+ DisplayList::instance().replay();
819
+ gea::platform::display::Display::popClip();
820
+ }
821
+ perf.rootScrollExtraReplayUs += refreshPerfNowUs() - extraReplayStartUs;
822
+
823
+ const std::int64_t flushStartUs = refreshPerfNowUs();
824
+ if (kSelfFlushingScroll && !damageOverflow) {
825
+ if (damageCount > 0)
826
+ gea::platform::display::Display::flushRects(damageRects, damageCount);
827
+ } else {
828
+ gea::platform::display::Display::flush();
829
+ }
830
+ perf.rootScrollFlushUs += refreshPerfNowUs() - flushStartUs;
831
+
832
+ const std::int64_t snapshotStartUs = refreshPerfNowUs();
833
+ LayoutSnapshot::capture();
834
+ perf.rootScrollSnapshotUs += refreshPerfNowUs() - snapshotStartUs;
835
+
836
+ return 1;
837
+ }
838
+
839
+
840
+ void rootScrollImageHoldTick()
841
+ {
842
+ gUiFrameCounter++;
843
+ // Runs at frame entry, before any scroll work. A frame that scrolled last
844
+ // tick re-arms below; the first quiet frame after held (skipped) image
845
+ // blits schedules one normal full refresh so covers repaint.
846
+ if (gScrollRanThisFrame) {
847
+ gScrollRanThisFrame = false;
848
+ return;
849
+ }
850
+ if (!gScrollImageHoldPending) return;
851
+ gScrollImageHoldPending = false;
852
+ auto &state = treeState();
853
+ if (state.mountedRoot < 0) return;
854
+ Tree::instance().markDisplayListDirty();
855
+ state.nodes[state.mountedRoot].render.dirty = 1;
856
+ state.nodes[state.mountedRoot].render.non_scroll_dirty = 1;
857
+ }
858
+
859
+ } // namespace gea::embedded::ui