@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
package/ui/internal.h ADDED
@@ -0,0 +1,567 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ #pragma once
3
+
4
+ #include "tree_internal.h"
5
+
6
+ #include <cstdint>
7
+
8
+ #ifdef quad
9
+ #undef quad
10
+ #endif
11
+
12
+ namespace gea::embedded::ui
13
+ {
14
+
15
+ // True while the root-scroll fast path repaints its exposed strips / moved
16
+ // slots. On packed e-paper targets the image blits skip while this is set —
17
+ // a fling shows paper where covers would raster (the moved pixels themselves
18
+ // scrollRect along and stay visible). Cuts the per-frame strip cost to
19
+ // text+fills; rootScrollImageHoldTick() repaints once with images on settle.
20
+ extern bool gScrollStripReplayActive;
21
+ // Set by the root-scroll fast path on every frame it actually scrolls.
22
+ extern bool gScrollRanThisFrame;
23
+ // Frame counter (ticked once per refresh pass) + the frame of the last scroll:
24
+ // the image hold applies only to CONSECUTIVE scroll frames (a live drag or
25
+ // fling), never to a one-shot jump like a row-snap commit — that single frame
26
+ // paints its images inline and needs no deferred repaint.
27
+ extern int gUiFrameCounter;
28
+ extern int gLastScrollUiFrame;
29
+ // Set when a blit was skipped under the hold; consumed by the settle tick.
30
+ extern bool gScrollImageHoldPending;
31
+ // Frame-entry tick: the first frame WITHOUT scroll activity after skipped
32
+ // blits marks the tree dirty for one normal full refresh (images included).
33
+ void rootScrollImageHoldTick();
34
+
35
+ class CameraSurfaceProvider;
36
+
37
+ // Max children collected per node in one recordNode level. The record scratch
38
+ // is kScratchDepth * kMaxChildren ints; at 256 that is a 16 KB per-record heap
39
+ // allocation, which FAILS on a PSRAM-less, heap-fragmented part (ESP32-C3
40
+ // Xteink X3, largest free block ~16 KB) — childrenForDepth() then returns
41
+ // nullptr and recordNode() never recurses past the root, so nothing renders.
42
+ // Overridable so such boards can shrink it to a value whose scratch fits.
43
+ #ifndef GEA_EMBEDDED_MAX_CHILDREN
44
+ #define GEA_EMBEDDED_MAX_CHILDREN 256
45
+ #endif
46
+ inline constexpr int kMaxChildren = GEA_EMBEDDED_MAX_CHILDREN;
47
+ inline constexpr int kMaxFlexLines = 32;
48
+
49
+ enum class DisplayCommandType : uint8_t
50
+ {
51
+ PushClip,
52
+ PopClip,
53
+ SetAlpha,
54
+ FillRect,
55
+ FillCircle,
56
+ FillRoundedRect,
57
+ FillQuad,
58
+ FillLinearGradient,
59
+ FillRadialGradient,
60
+ DrawLine,
61
+ StrokeRect,
62
+ StrokeRoundedRect,
63
+ DrawProjectedText,
64
+ DrawText,
65
+ BlitImage,
66
+ BlitImageScaled,
67
+ BeginFilterBlur,
68
+ ApplyFilterBlur,
69
+ FillTransformedLinearGradient,
70
+ FillTransformedRoundedRect
71
+ };
72
+
73
+ struct DisplayCommand
74
+ {
75
+ DisplayCommandType type;
76
+ int16_t bx, by, bw, bh;
77
+ union
78
+ {
79
+ struct
80
+ {
81
+ int16_t x, y, w, h;
82
+ // Clip scopes are recorded outside the owning node's paint-command
83
+ // range. Keep the owner so retained subtree translations can move the
84
+ // scope with the node (and undo the scroll viewport's own movement).
85
+ int16_t nodeId;
86
+ } clip;
87
+ struct
88
+ {
89
+ uint8_t alpha;
90
+ // OPEN SetAlpha of an opacity scope is tagged with its node so a
91
+ // partial→partial fade can patch the value in place
92
+ // (DisplayList::patchNodeAlpha): nodeId = owning node (-1 on the CLOSE
93
+ // command), recordParentAlpha = parent alpha at record time so the
94
+ // patch recomputes alpha = recordParentAlpha * opacity / 255.
95
+ uint8_t recordParentAlpha;
96
+ int16_t nodeId;
97
+ } alpha;
98
+ struct
99
+ {
100
+ int16_t x, y, w, h;
101
+ gea::framework::graphics::pixel::native_t color;
102
+ } fill;
103
+ struct
104
+ {
105
+ int16_t cx, cy, r;
106
+ gea::framework::graphics::pixel::native_t color;
107
+ } fillCircle;
108
+ struct
109
+ {
110
+ int16_t x, y, w, h;
111
+ int16_t tl, tr, br, bl;
112
+ gea::framework::graphics::pixel::native_t color;
113
+ } fillRoundedRect;
114
+ struct
115
+ {
116
+ int16_t x0, y0, x1, y1, x2, y2, x3, y3;
117
+ // Transform-reproject payload. mode 1: lx/ly/lw/lh are a local rect.
118
+ // mode 2: lx/ly/lw/lh are local segment endpoints in 1/8 px; aux is
119
+ // stroke width in 1/8 screen px.
120
+ int16_t lx, ly, lw, lh, aux;
121
+ gea::framework::graphics::pixel::native_t color;
122
+ uint8_t reprojectMode;
123
+ } quad;
124
+ struct
125
+ {
126
+ int16_t x, y, w, h;
127
+ int16_t tl, tr, br, bl;
128
+ gea::framework::graphics::pixel::native_t fromColor;
129
+ gea::framework::graphics::pixel::native_t midColor;
130
+ gea::framework::graphics::pixel::native_t toColor;
131
+ uint16_t midStop;
132
+ int16_t angle;
133
+ uint8_t fromAlpha;
134
+ uint8_t midAlpha;
135
+ uint8_t toAlpha;
136
+ uint16_t toStop;
137
+ uint8_t hasMid;
138
+ } gradient;
139
+ struct
140
+ {
141
+ int16_t x, y, w, h;
142
+ int16_t tl, tr, br, bl;
143
+ int16_t cxPermille, cyPermille;
144
+ int16_t rxPermille, ryPermille;
145
+ gea::framework::graphics::pixel::native_t fromColor;
146
+ gea::framework::graphics::pixel::native_t toColor;
147
+ uint16_t stopPermille;
148
+ uint8_t fromAlpha;
149
+ uint8_t toAlpha;
150
+ } radialGradient;
151
+ struct
152
+ {
153
+ int16_t x0, y0, x1, y1;
154
+ gea::framework::graphics::pixel::native_t color;
155
+ } line;
156
+ struct
157
+ {
158
+ int16_t x, y, w, h;
159
+ gea::framework::graphics::pixel::native_t color;
160
+ } stroke;
161
+ struct
162
+ {
163
+ int16_t x, y, w, h;
164
+ int16_t tl, tr, br, bl;
165
+ int16_t lineWidth;
166
+ gea::framework::graphics::pixel::native_t color;
167
+ } strokeRoundedRect;
168
+ struct
169
+ {
170
+ const char *text;
171
+ int16_t x, y, maxWidth;
172
+ gea::framework::graphics::pixel::native_t color;
173
+ float scale;
174
+ int8_t align;
175
+ int8_t textTransform;
176
+ int16_t lineHeight;
177
+ int16_t containerWidth;
178
+ int16_t fontId;
179
+ // CSS white-space / text-overflow, carried so the deferred draw
180
+ // can reproduce single-line truncation. whiteSpace==1 => nowrap
181
+ // (no width-based wrapping); textOverflow==1 => ellipsis ("...").
182
+ int8_t whiteSpace;
183
+ int8_t textOverflow;
184
+ // Content-box height. With ellipsis on WRAPPED text this caps the
185
+ // line budget (height / line advance) and the last line ellipsizes
186
+ // — the multi-line clamp. 0 = unlimited (draw every line).
187
+ int16_t maxHeight;
188
+ // Inline continuation offset for the run's FIRST line only (see
189
+ // LayoutBox::inline_indent). 0 for every run that starts its own line.
190
+ int16_t firstLineIndent;
191
+ } text;
192
+ struct
193
+ {
194
+ const char *text;
195
+ int16_t srcX, srcY, srcW, srcH;
196
+ int16_t x0, y0, x1, y1, x2, y2, x3, y3;
197
+ int16_t fontId, fontSize;
198
+ gea::framework::graphics::pixel::native_t color;
199
+ uint8_t alpha;
200
+ int8_t textTransform;
201
+ // CSS backface-visibility:hidden — drop this projected label when its winding
202
+ // points away from the viewer, matching its (culled) back-facing parent face.
203
+ uint8_t backfaceHidden;
204
+ } projectedText;
205
+ // A 3D/perspective-transformed linear-gradient face, shaded per pixel via
206
+ // inverse homography (screen->local) + gradient LUT — replaces the old
207
+ // ~72-strips-per-face approximation (one quad command, exact gradient).
208
+ struct
209
+ {
210
+ int16_t x0, y0, x1, y1, x2, y2, x3, y3; // screen corners (TL,TR,BR,BL)
211
+ // Same corners in 1/8-px fixed point. The int16 corners above round each
212
+ // face's projected vertices independently, so two faces meeting at a shared
213
+ // 3D edge can land ~1px apart at round-to-nearest straddles, leaving a
214
+ // shimmering backdrop crack. The rasterizer uses these sub-pixel corners so
215
+ // adjacent faces' shared edges coincide and tile watertight (no bloat, no AA).
216
+ int16_t fx0, fy0, fx1, fy1, fx2, fy2, fx3, fy3;
217
+ int16_t lx, ly, lw, lh; // local (untransformed) rect
218
+ gea::framework::graphics::pixel::native_t fromColor, midColor, toColor; // native pixel stops
219
+ uint16_t midStop, toStop; // permille
220
+ int16_t angle; // gradient angle, tenths of degree
221
+ uint8_t fromAlpha, midAlpha, toAlpha, hasMid;
222
+ // CSS backface-visibility:hidden — drop this face when its projected winding
223
+ // points away from the viewer (a closed opaque solid occludes its back faces
224
+ // anyway, so culling them removes the wasted overdraw). 0 => always drawn.
225
+ uint8_t backfaceHidden;
226
+ // CSS border on the transformed face, drawn by the span rasterizer as an
227
+ // edge frame (the first/last edgeWidth px of every span + the quad's
228
+ // top/bottom rows trace the full outline). Folded into this command so
229
+ // borders don't emit projected stroke quads — those would disarm the
230
+ // transform-reproject fast path every frame. edgeWidth 0 => no border.
231
+ gea::framework::graphics::pixel::native_t edgeColor;
232
+ uint8_t edgeAlpha;
233
+ uint8_t edgeWidth;
234
+ } transformedGradient;
235
+ struct
236
+ {
237
+ int16_t x0, y0, x1, y1, x2, y2, x3, y3; // screen corners (TL,TR,BR,BL)
238
+ int16_t lx, ly, lw, lh; // local (untransformed) rect
239
+ int16_t tlRx8, tlRy8;
240
+ int16_t trRx8, trRy8;
241
+ int16_t brRx8, brRy8;
242
+ int16_t blRx8, blRy8;
243
+ gea::framework::graphics::pixel::native_t color;
244
+ uint8_t backfaceHidden;
245
+ } transformedRoundedRect;
246
+ struct
247
+ {
248
+ const gea::framework::graphics::pixel::native_t *pixels;
249
+ const uint8_t *alpha;
250
+ int16_t sourceWidth, sourceHeight, dx, dy;
251
+ // Packed grayscale targets only: the source is a sub-byte-packed canvas
252
+ // surface (2 px/byte on GRAY4, 4 px/byte on GRAY2) rather than an
253
+ // unpacked decoded image, so the blit must unpack it.
254
+ uint8_t sourcePacked;
255
+ } blit;
256
+ struct
257
+ {
258
+ const gea::framework::graphics::pixel::native_t *pixels;
259
+ const uint8_t *alpha;
260
+ int16_t sourceWidth, sourceHeight, dx, dy, dw, dh;
261
+ int16_t tl, tr, br, bl;
262
+ } scaledBlit;
263
+ struct
264
+ {
265
+ int16_t nodeId;
266
+ int16_t radius;
267
+ int16_t radiusX;
268
+ int16_t radiusY;
269
+ int16_t sourceAlphaCap;
270
+ } filterBlur;
271
+ };
272
+ };
273
+
274
+ struct DisplayReplayRegion
275
+ {
276
+ int x0;
277
+ int y0;
278
+ int x1;
279
+ int y1;
280
+ int origin;
281
+ };
282
+
283
+ class DisplayList
284
+ {
285
+ public:
286
+ static DisplayList &instance();
287
+
288
+ DisplayCommand *append();
289
+ void clear();
290
+ void resetStorage();
291
+ // allowSkipStatic: caller guarantees this frame will use the direct
292
+ // (backdrop-blit) replay path, so recordNode may skip re-recording fully-static
293
+ // subtrees when the backdrop is baked. Must be false on the full-replay path.
294
+ void recordNode(int id, uint8_t parentAlpha, bool allowSkipStatic = false);
295
+ void recordNodeWithExpandedClip(int id, uint8_t parentAlpha, int clipNode,
296
+ int clipX0, int clipY0, int clipX1, int clipY1);
297
+ void replay();
298
+ bool canReplayDirectDirtyRegions(int width, int height) const;
299
+ void translateNodeCommands(int node, int dx, int dy);
300
+ void translateSubtreeCommands(int node, int dx, int dy);
301
+ // After translating a subtree in place, content that was fully outside the
302
+ // record-time clip (culled: no commands recorded) may now overlap the
303
+ // viewport. The retained list is then incomplete — replay would paint stale
304
+ // background where that content entered — so the caller must fall back to a
305
+ // full record. Returns true when such a reveal exists.
306
+ bool subtreeRevealsUnrecordedContent(int node, int width, int height) const;
307
+ bool rerecordNodeCommands(int node);
308
+ // A pixel buffer referenced by retained blit commands is about to be freed
309
+ // (canvas surface mode flip / resize / removal). The owning node is only
310
+ // *marked* dirty — its re-record happens later — so any replay in the gap
311
+ // would read freed memory. Neutralize every retained command still pointing
312
+ // at the buffer.
313
+ void scrubBlitPixels(const gea::framework::graphics::pixel::native_t *pixels);
314
+ // A node's text buffer is about to be freed (node destruction) or has just
315
+ // been reallocated (setText growing past capacity). Retained DrawText /
316
+ // DrawProjectedText commands hold a raw c_str() pointer into that buffer,
317
+ // and a stale-list replay (partial refresh, backdrop restore) in the gap
318
+ // before the next record would read freed memory — on device this crashed
319
+ // (LoadStoreError) replaying the reader after the TOC unmounted its rows.
320
+ // Neutralize every retained text command still pointing at the buffer.
321
+ void scrubNodeText(const char *data);
322
+ // Patch a node's opacity-scope alpha in place (partial→partial fade) without a
323
+ // rebuild. Returns false if the node has no SetAlpha scope in the current list.
324
+ bool patchNodeAlpha(int node, uint8_t opacity);
325
+ // Bumped by clear(): lets a caller detect that its recorded coverage (e.g. the
326
+ // root-scroll translate window) was replaced by someone else's record.
327
+ std::uint32_t recordSerial() const;
328
+ // True when an append() was dropped since the last clear() — the recorded
329
+ // list is truncated and must not be treated as complete coverage.
330
+ bool commandOverflow() const;
331
+ // Move a scroll node's recorded scrollbar thumb (the single FillRoundedRect
332
+ // recordScrollbar emits, which lives OUTSIDE the node's draw range) from its
333
+ // previous_scroll_y position to the current scroll_y position, in place.
334
+ // Returns false when the thumb command isn't found — caller must full-record.
335
+ bool patchScrollbarThumb(int node);
336
+ bool recolorRetainedSolidBackground(int node, gea::framework::graphics::pixel::native_t oldColor, gea::framework::graphics::pixel::native_t newColor, int *x0, int *y0, int *x1, int *y1);
337
+ // A retained-background recolor rewrites the background pixels in place; the
338
+ // span replace only touches pixels that match the OLD colour exactly. Every
339
+ // antialiased edge of a node drawn OVER that background is a blend of the old
340
+ // colour with the foreground colour, so it matches nothing and is left stale —
341
+ // the tick marks and labels on a recoloured dial keep a halo of the previous
342
+ // background. Report the paint bounds of the later-drawn nodes that overlap the
343
+ // recoloured area so the caller can add them as ordinary dirty replay regions:
344
+ // a scoped direct replay of those rects redraws background + foreground exactly
345
+ // as a full replay would, with no per-command-type special casing (glyph runs
346
+ // have no coverage function to re-blend against).
347
+ // Writes x0,y0,x1,y1 quadruples; returns the rect count (never more than
348
+ // maxRects — the overflow is unioned into the last slot).
349
+ int collectRecolorForegroundRepairRects(int node, int x0, int y0, int x1, int y1,
350
+ int *outRects, int maxRects) const;
351
+ void replayDirectDirtyRegion(int x0, int y0, int x1, int y1, int origin = -1);
352
+ void replayDirectDirtyRegions(const DisplayReplayRegion *regions, int count);
353
+ bool canReplaySimpleDirtyRegions(int width, int height) const;
354
+ void replaySimpleClippedDirtyRegion(int x0, int y0, int x1, int y1, int origin = -1);
355
+ // Static-backdrop cache: bake every non-dirty (static) node into the bg cache
356
+ // buffer once it's stable, so the dirty-region replay can blit that backdrop and
357
+ // replay only the dynamic subtree (the spinning cube) on top — making the static
358
+ // stage free per frame. invalidate clears it on a structural change.
359
+ // stableThisFrame: nothing happened that could stale baked pixels (quiet
360
+ // pause/ticker frames included) — false drops the cache. bakeEligibleThisFrame:
361
+ // a dynamic root is actively dirty, so a bake taken now can exclude it — quiet
362
+ // frames keep the cache but must not bake (the paused subtree would be baked in).
363
+ void maybeBakeStaticBackdrop(int width, int height, bool stableThisFrame, bool directReplay,
364
+ bool bakeEligibleThisFrame = true);
365
+ void invalidateStaticBackdrop();
366
+ bool staticBackdropActive() const;
367
+ // True once after each bake: caller must repaint the full viewport from the
368
+ // cache that frame so the framebuffer/panel become exactly the baked backdrop.
369
+ bool consumeBackdropFullSyncRequest();
370
+ // Transform-only fast path: re-project every recorded command's corners in place
371
+ // (from its stored local rect through the node's current transform) instead of
372
+ // clear()+recordNode(). Returns false — caller must full-record — when not armed
373
+ // (structure may have changed) or a command type isn't re-projectable. Produces
374
+ // byte-identical geometry to a full record.
375
+ bool tryReprojectTransformed();
376
+ // Watertight vertex weld over the recorded transformed-gradient faces: snaps
377
+ // tight clusters of projected corners (shared 3D vertices projected through
378
+ // independent transform chains) to their centroid so adjacent faces tile
379
+ // without backdrop cracks. Must run after ANY path that (re)creates face
380
+ // commands — tryReprojectTransformed calls it internally; every full record
381
+ // needs an explicit call or shared edges crack for that one frame. Non-null
382
+ // dirty pointers are extended to cover the welded geometry.
383
+ void weldTransformedFaces(int *dirtyX0 = nullptr, int *dirtyY0 = nullptr, int *dirtyX1 = nullptr, int *dirtyY1 = nullptr);
384
+ // Arm/disarm the reproject path after a record. Eligible records keep enough
385
+ // local geometry in their transformed commands for later transform-only frames
386
+ // to patch projected corners in place; if a backdrop cache is active, static
387
+ // subtrees may also have been skipped from the recorded list.
388
+ void armTransformReproject(bool eligible);
389
+ // The (prev ∪ cur) screen bbox the last tryReprojectTransformed() patched — the
390
+ // spinning subtree's dirty rect, free to reuse instead of re-projecting it in the
391
+ // dirty pass. Returns false if empty. Only meaningful on a reprojected frame.
392
+ bool reprojectDirtyRect(int *x0, int *y0, int *x1, int *y1) const;
393
+ void filterBlurCacheStats(int *hits, int *misses) const;
394
+ int commandCount() const;
395
+ int nodeCommandCount(int node) const;
396
+ const DisplayCommand *nodeCommandAt(int node, int index) const;
397
+ bool nodeCommandBounds(int node, int *x0, int *y0, int *x1, int *y1) const;
398
+ void clearRetainedBackgroundRecolors();
399
+ };
400
+
401
+ class LayoutEngine
402
+ {
403
+ public:
404
+ static LayoutEngine &instance();
405
+
406
+ int clampSize(int size, int minSize, int maxSize) const;
407
+ int collectChildren(int parent, int *out, int max, bool skipAbsolute) const;
408
+ // Starts a new layout pass: invalidates the intra-pass layoutNode memo
409
+ // (LayoutBox::memo_pass). Must be called before each root layoutNode()
410
+ // so memo hits never leak across passes/frames.
411
+ void beginLayoutPass();
412
+ void layoutNode(int id, int availableWidth, int availableHeight);
413
+ // Scoped relayout: re-lays ONLY `scope`'s subtree using the available box
414
+ // remembered from its last layout, then resolves the subtree's absolute
415
+ // coords from the scope's (unchanged) position. Returns false — caller
416
+ // must full-relayout — when the scope's remembered avail is unknown, an
417
+ // absolute descendant's containing block escapes the scope, or the
418
+ // scope's own dims changed as a result (its content no longer fits the
419
+ // same box, so ancestors need reflow after all).
420
+ bool layoutNodeScoped(int scope, int treeRoot);
421
+ void repositionChildren(int id);
422
+ void resolveAbsoluteCoords(int id, int parentX, int parentY);
423
+ // True when `n` is an inline-level box (a span/text/image without an
424
+ // explicit block-level display) — the inline-formatting input that makes a
425
+ // plain block flow its children as a row (LayoutNodePass::
426
+ // resolveRowDirection). Exposed for refresh fast paths that mirror that
427
+ // flow decision without running a layout pass.
428
+ static bool isInlineLevelNode(const Node &n);
429
+ };
430
+
431
+ class ViewRenderer
432
+ {
433
+ public:
434
+ static bool recordClipBegin(const Node &node);
435
+ static void recordClipEnd(const Node &node);
436
+ static void recordBox(const Node &node, uint8_t parentAlpha = 255);
437
+ static void recordScrollbar(const Node &node);
438
+ static int scrollMaxX(const Node &node);
439
+ static int scrollMaxY(const Node &node);
440
+ static void transformedBounds(const Node &node, bool usePrevious, int *x0, int *y0, int *x1, int *y1);
441
+ static void transformedPoint(const Node &node, bool usePrevious, float x, float y, float z, int16_t *outX, int16_t *outY);
442
+ static void transformedCorners(const Node &node, bool usePrevious, int16_t *xs, int16_t *ys);
443
+ static void transformedRectCorners(const Node &node, bool usePrevious, int x, int y, int w, int h, int16_t *xs, int16_t *ys,
444
+ int16_t *xs8 = nullptr, int16_t *ys8 = nullptr);
445
+ static int transformedDepth(const Node &node, bool usePrevious);
446
+ // True iff any node in the tree carries a transform/perspective this frame
447
+ // or last (cached once per refresh). Lets paint-order sorting skip the 3D
448
+ // depth walk entirely for all-2D trees.
449
+ static bool anyTransformActive();
450
+ };
451
+
452
+ // How one text run fragments across the line boxes of an inline formatting
453
+ // context, given that its first line starts part-way along a line box.
454
+ // `lineCount == 0` means the run could not be fragmented (see
455
+ // TextRenderer::canFragmentInlineRuns) and must be flowed as one atomic box.
456
+ struct InlineFlowMeasure {
457
+ int lineCount = 0;
458
+ int firstLineWidth = 0;
459
+ int lastLineWidth = 0;
460
+ int maxLineWidth = 0;
461
+ int lineAdvance = 0;
462
+ // Shift applied to the run's FIRST line, negative by exactly the width of
463
+ // the leading collapsible whitespace CSS drops at the start of a line box.
464
+ // Spaces carry no ink, so drawing the line that much further left renders
465
+ // identically to deleting them — and keeps the run a single unmodified
466
+ // string for the display list.
467
+ int firstLineIndentAdjust = 0;
468
+ // True when the first line could only be filled by cutting a word open —
469
+ // the run does not fit the space left on the line box it was offered, so an
470
+ // inline formatting context starts it on the next one instead.
471
+ bool firstLineForcedSplit = false;
472
+ };
473
+
474
+ class TextRenderer
475
+ {
476
+ public:
477
+ static void layout(int id, int availableWidth);
478
+ // True when a run's line breaking is reproducible from per-glyph advances,
479
+ // i.e. the same wrapper the draw path uses. A host that measures whole
480
+ // strings for us (CoreText on Apple targets) does its own breaking, which
481
+ // this engine cannot subdivide — such targets keep flowing runs whole.
482
+ static bool canFragmentInlineRuns(const Node &node);
483
+ // Wraps `node`'s text with `firstAvail` px available on its first line and
484
+ // `contentWidth` on every line after it — the measurement an inline
485
+ // formatting context needs to continue a run after the box that precedes
486
+ // it on the same line box. Leading collapsible whitespace is dropped when
487
+ // `atLineStart`, as CSS does when a line box begins.
488
+ static InlineFlowMeasure measureInlineFlow(const Node &node, int firstAvail, int contentWidth, bool atLineStart);
489
+ static void record(const Node &node, uint8_t parentAlpha = 255);
490
+ static void drawWrapped(const char *text, int x, int y, int maxWidth, gea::framework::graphics::pixel::native_t color, float scale, int textAlign,
491
+ int containerWidth, int fontId, int textTransform = 0, int lineHeight = 0, int whiteSpace = 0, int textOverflow = 0, int maxHeight = 0,
492
+ int firstLineIndent = 0);
493
+ // Single-line width measure for places that don't go through layout()
494
+ // — used by InputRenderer to position the caret at the end of the value.
495
+ static int measureWidth(const char *text, int fontId, int fontSize, int textTransform = 0);
496
+ static int measureHeight(const char *text, int fontId, int fontSize, int textTransform = 0, int lineHeight = 0);
497
+ // In-place box re-measure for a rebound text node on refresh paths that
498
+ // skip the layout pass (root-scroll fast path): record() wraps and clips
499
+ // by layout.width/height, so a longer string in a stale box truncates.
500
+ // Returns true when the box changed. Anchoring is left to the caller.
501
+ // keepBoxWidth re-wraps within the current layout.width (a cross-
502
+ // stretched block's box) and only updates the height.
503
+ static bool remeasureContentBox(int id, bool keepBoxWidth = false);
504
+ };
505
+
506
+ // Materializes `<input>` JSX elements. They emit View nodes (tag_name=="input")
507
+ // with no Text child — the user-visible text lives in the `value` attribute
508
+ // (or `placeholder` when `value` is empty). This renderer paints that text on
509
+ // top of the View box recorded by ViewRenderer. Pixel-only targets can pair
510
+ // this with the framework-owned on-screen keyboard; native text targets use
511
+ // platform controls instead.
512
+ class InputRenderer
513
+ {
514
+ public:
515
+ static void layout(int id, int availableWidth);
516
+ static void record(int id);
517
+ };
518
+
519
+ class ImageRenderer
520
+ {
521
+ public:
522
+ static void layout(int id);
523
+ static void record(const Node &node);
524
+ };
525
+
526
+ class CanvasRenderer
527
+ {
528
+ public:
529
+ static void record(const Node &node);
530
+ };
531
+
532
+ // Presents a <camera> leaf's live preview each frame: framebuffer-mode
533
+ // backends fill an owned RGB565 buffer that's blitted into the node's computed
534
+ // rect (CSS clip / z-order honoured); native-overlay backends (iOS) get their
535
+ // preview layer repositioned over the rect. Implemented in camera_element.cpp.
536
+ class CameraRenderer
537
+ {
538
+ public:
539
+ static void record(const Node &node);
540
+ static void positionNativeOverlay(const Node &node, CameraSurfaceProvider *provider);
541
+ };
542
+
543
+ // A <virtual-list> windows a small pool of real child slot nodes over a
544
+ // virtual content height of itemCount * rowHeight. It carries no app-specific
545
+ // row content — rows are ordinary child nodes drawn by the generic render
546
+ // path. These helpers only track the item count and proxy the element's scroll
547
+ // position onto the standard layout.scroll_y so the generic overflow:scroll
548
+ // machinery (scrollbar, scrollRect fast path, clipping) drives the list.
549
+ class VirtualListRenderer
550
+ {
551
+ public:
552
+ static void init(int node);
553
+ static void configureAttribute(int node, const char *name, const char *value);
554
+ static int itemCount(int node);
555
+ static int virtualContentHeight(int node, int rowHeight);
556
+ // Last measured row height (first slot child's rendered CSS layout height),
557
+ // cached by virtualContentHeight(). Surfaced to the app as the element's
558
+ // `rowHeight` property so it positions slots from one source of truth.
559
+ static int rowHeight(int node);
560
+ static int scrollTop(int node);
561
+ static int previousScrollTop(int node);
562
+ static int scrollMaxY(int node);
563
+ static bool setScrollTop(int node, int scrollTop);
564
+ static void captureSnapshot(int node);
565
+ };
566
+
567
+ } // namespace gea::embedded::ui