@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,235 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ #pragma once
3
+
4
+ #include <cstdint>
5
+
6
+ #include "gea_perf_config.h" // GEA_EMBEDDED_UI_REFRESH_PERF (+ GEA_EMBEDDED_PERF master)
7
+ #include "state_init.h"
8
+
9
+ #ifdef ESP_PLATFORM
10
+ #include "esp_timer.h"
11
+ #elif defined(GEA_PICO_SDK) && GEA_PICO_SDK
12
+ #include "pico/time.h"
13
+ #else
14
+ #include <chrono>
15
+ #endif
16
+
17
+ namespace gea::embedded::ui {
18
+
19
+ struct RefreshPerfStats {
20
+ std::int64_t rootScrollScanUs = 0;
21
+ std::int64_t rootScrollRebuildUs = 0;
22
+ std::int64_t rootScrollScrollRectUs = 0;
23
+ std::int64_t rootScrollStripReplayUs = 0;
24
+ std::int64_t rootScrollScrollbarReplayUs = 0;
25
+ std::int64_t rootScrollFullReplayUs = 0;
26
+ std::int64_t rootScrollStreamUs = 0;
27
+ std::int64_t rootScrollExtraReplayUs = 0;
28
+ std::int64_t rootScrollFlushUs = 0;
29
+ std::int64_t rootScrollSnapshotUs = 0;
30
+ std::int64_t virtualListRegionFillUs = 0;
31
+ std::int64_t virtualListRegionTextUs = 0;
32
+ std::int64_t virtualListRegionThumbUs = 0;
33
+ std::int64_t treeLayoutModeUs = 0;
34
+ std::int64_t treeLayoutUs = 0;
35
+ std::int64_t treeDisplayListUs = 0;
36
+ std::int64_t treeRecordNodeUs = 0;
37
+ std::int64_t treeSetStyleUs = 0;
38
+ std::int64_t treeSetTextUs = 0;
39
+ std::int64_t treeAbsModeUs = 0;
40
+ std::int64_t treeDirtyCollectUs = 0;
41
+ std::int64_t treeDirtyCoalesceUs = 0;
42
+ std::int64_t treeReplayUs = 0;
43
+ // TEMP replay-split instrumentation (simple clipped dirty replay): attribute
44
+ // the per-region replay total to (1) the ancestor-chain background restore,
45
+ // (2) the dynamic nodes-after-origin replay, and (3) the batched rounded-rect
46
+ // raster flush. Lets us see whether the bouncing-balls replay cost is bg
47
+ // re-fill, overlapping-ball overdraw, or the circle rasterizer.
48
+ std::int64_t treeReplaySplitBgUs = 0;
49
+ std::int64_t treeReplaySplitDynUs = 0;
50
+ std::int64_t treeReplaySplitRasterUs = 0;
51
+ std::int64_t treeReplayBgRestoreUs = 0;
52
+ std::int64_t treeReplayNodeWalkUs = 0;
53
+ std::int64_t treeReplayCommandFilterUs = 0;
54
+ std::int64_t treeReplayCommandClipUs = 0;
55
+ std::int64_t treeFlushRectsUs = 0;
56
+ std::int64_t treeSnapshotUs = 0;
57
+ std::int64_t treeBgRecolorUs = 0;
58
+ std::int64_t treeBgRecolorFillUs = 0;
59
+ std::int64_t treeBgRecolorEdgeUs = 0;
60
+ std::int64_t treeBgRecolorReplayUs = 0;
61
+ static constexpr int kMaxTreeReplayRegionSamples = 8;
62
+ int treeReplayRegions = 0;
63
+ int treeReplayOriginRegions = 0;
64
+ int treeReplayCommandChecks = 0;
65
+ int treeReplayDirectRegionCalls = 0;
66
+ int treeReplayDirectRegionsCalls = 0;
67
+ int treeReplaySimpleRegionCalls = 0;
68
+ int treeReplayParallelAttempts = 0;
69
+ int treeReplayParallelSuccesses = 0;
70
+ int treeReplayCommandFilterCalls = 0;
71
+ int treeReplayCommandClipCalls = 0;
72
+ int treeReplayRegionSampleCount = 0;
73
+ std::int16_t treeReplayRegionX0[kMaxTreeReplayRegionSamples]{};
74
+ std::int16_t treeReplayRegionY0[kMaxTreeReplayRegionSamples]{};
75
+ std::int16_t treeReplayRegionX1[kMaxTreeReplayRegionSamples]{};
76
+ std::int16_t treeReplayRegionY1[kMaxTreeReplayRegionSamples]{};
77
+ std::int16_t treeReplayRegionOrigin[kMaxTreeReplayRegionSamples]{};
78
+ int treeReplayFillRectCommands = 0;
79
+ int treeReplayCircleCommands = 0;
80
+ int treeReplayRoundedRectCommands = 0;
81
+ int treeReplayTransformedRoundedRectCommands = 0;
82
+ int treeReplayTextCommands = 0;
83
+ int treeReplayOtherCommands = 0;
84
+ // Per-command-type microseconds spent in DisplayCommandDrawer::replay, so the
85
+ // SLOW-frame log can attribute the replay total to gradients vs text vs images
86
+ // vs fills vs everything else (rounded rects, lines, clips, alpha, ...).
87
+ std::int64_t treeReplayFillUs = 0;
88
+ std::int64_t treeReplayCircleUs = 0;
89
+ std::int64_t treeReplayTextUs = 0;
90
+ std::int64_t treeReplayGradientUs = 0;
91
+ std::int64_t treeReplayImageUs = 0;
92
+ std::int64_t treeReplayOtherUs = 0;
93
+ int projectedTextCacheCalls = 0;
94
+ int projectedTextCacheHits = 0;
95
+ int projectedTextCacheMisses = 0;
96
+ int projectedTextCacheFallbacks = 0;
97
+ int projectedTextCacheSramUses = 0;
98
+ int projectedTextCachePsramUses = 0;
99
+ int projectedTextCacheBytes = 0;
100
+ int projectedTextCacheSramBytes = 0;
101
+ int projectedTextCacheMaxEntryBytes = 0;
102
+ // Layout instrumentation: layoutNode/repositionChildren call counts (>> node
103
+ // count signals redundant re-layout / O(n^2)) and time spent measuring text
104
+ // (font metrics) during layout — the prime suspect for a slow full re-layout.
105
+ int treeLayoutNodeCalls = 0;
106
+ int treeLayoutMemoHits = 0;
107
+ int treeScopedLayouts = 0;
108
+ // Why the scoped-relayout attempt fell back (last occurrence):
109
+ // 1=no stable scope found, 2=avail unknown, 3=abs containing block escapes,
110
+ // 4=scope dims changed after layout. 0 = no fallback recorded.
111
+ int treeScopedRejectReason = 0;
112
+ int treeScopedRejectNode = -1;
113
+ int treeLayoutRepositionCalls = 0;
114
+ std::int64_t treeLayoutTextUs = 0;
115
+ int treeSetStyleCalls = 0;
116
+ int treeSetStyleChanged = 0;
117
+ int treeSetStyleNoop = 0;
118
+ int treeSetStyleLayoutChanged = 0;
119
+ int treeSetStyleTransformChanged = 0;
120
+ int treeSetStylePaintChanged = 0;
121
+ int treeSetTextCalls = 0;
122
+ int treeSetTextChanged = 0;
123
+ int treeSetTextStable = 0;
124
+ int treeSetTextHidden = 0;
125
+ int treeMarkDisplayListDirtyCalls = 0;
126
+ int treeMarkDisplayListContentDirtyCalls = 0;
127
+ int treeMarkNodeCommandDirtyCalls = 0;
128
+ int treeAbsModeCalls = 0;
129
+ int treeAbsModeFast = 0;
130
+ int treeAbsModeFull = 0;
131
+ int treeAbsModeNoop = 0;
132
+ int treeAbsModeDirtyNodes = 0;
133
+ int treeAbsModeRejectNode = -1;
134
+ int treeAbsModeRejectReason = 0;
135
+ int rootScrollCalls = 0;
136
+ int rootScrollAccepted = 0;
137
+ int rootScrollRejected = 0;
138
+ int rootScrollMovePx = 0;
139
+ int rootScrollViewportPx = 0;
140
+ int rootScrollStripPx = 0;
141
+ int rootScrollExtraDirtyNodes = 0;
142
+ int rootScrollStreamFrames = 0;
143
+ int rootScrollSyncFrames = 0;
144
+ int virtualListRegionCalls = 0;
145
+ int virtualListRegionRows = 0;
146
+ int virtualListRegionTextCalls = 0;
147
+ int treeRefreshCalls = 0;
148
+ int treeDirectReplayCalls = 0;
149
+ int treeBgRecolorCalls = 0;
150
+ int treeBgRecolorPixels = 0;
151
+ int treeBgRecolorFastPixels = 0;
152
+ int treeRecordCalls = 0;
153
+ int treeRecordedNodes = 0;
154
+ int treeRecordedCommands = 0;
155
+ // Display-list rebuild path taken this frame: a full clear()+recordNode()
156
+ // (treeFullRecords) vs the transform-only corner reproject (treeReprojects).
157
+ // A spinning-transform scene should reproject ~every frame; full records
158
+ // showing up mid-animation mark the frames that fell off the fast path.
159
+ int treeFullRecords = 0;
160
+ int treeReprojects = 0;
161
+ // Horizontal-pan fast path: a camera/world wrapper inside an overflow:hidden
162
+ // parent shifted its `left` by dx, so the viewport is memcpy-scrolled and only
163
+ // the revealed strip + independently-moving sprites + smeared non-uniform
164
+ // backdrop are repainted (instead of re-replaying the whole panned viewport).
165
+ int treePanReplayCalls = 0;
166
+ // Total pixel area actually re-replayed by the pan fast path (sum of clipped
167
+ // repaint regions). Far below viewport-area/frame proves the memcpy-shift is
168
+ // avoiding the whole-viewport repaint.
169
+ int treePanRepaintArea = 0;
170
+ };
171
+
172
+ inline RefreshPerfStats gRefreshPerfStats;
173
+
174
+ // Gate for the horizontal-pan fast path. Enabled by default. The fast path is
175
+ // verified pixel-identical to the full-replay reference across full gameplay
176
+ // (walk/fall/collide/collect/die/respawn/hurt-blink) by the per-frame check in
177
+ // test_gea_sky_hop_jsx_main.cpp. The host test flips this to compare on-vs-off.
178
+ inline bool gHorizontalPanFastPathDisabled = false;
179
+
180
+ // Per-operation refresh profiling (the ScopedRefreshStat timers wrapping setStyle,
181
+ // record-node, layout, replay, etc.) reads a hardware timer twice per timed region.
182
+ // On a hot frame (e.g. 128 setStyle calls + dozens of render-op regions) those reads
183
+ // add up, and they are NOT removed by the production log gate — only the log *output*
184
+ // is. Set GEA_EMBEDDED_UI_REFRESH_PERF=0 to compile the clock reads out (the timers
185
+ // then accumulate 0 and optimize away); the frame-level fps/phase timing is separate
186
+ // (esp_timer in the scheduler) and unaffected.
187
+ // GEA_EMBEDDED_UI_REFRESH_PERF (and the GEA_EMBEDDED_PERF master that forces it
188
+ // off) come from gea_perf_config.h, included above.
189
+
190
+ inline std::int64_t refreshPerfNowUs()
191
+ {
192
+ #if !GEA_EMBEDDED_UI_REFRESH_PERF
193
+ return 0;
194
+ #elif defined(ESP_PLATFORM)
195
+ return esp_timer_get_time();
196
+ #elif defined(GEA_PICO_SDK) && GEA_PICO_SDK
197
+ return static_cast<std::int64_t>(time_us_64());
198
+ #else
199
+ using Clock = std::chrono::steady_clock;
200
+ return std::chrono::duration_cast<std::chrono::microseconds>(Clock::now().time_since_epoch()).count();
201
+ #endif
202
+ }
203
+
204
+ inline RefreshPerfStats &refreshPerfStatsMutable()
205
+ {
206
+ #if GEA_EMBEDDED_UI_REFRESH_PERF
207
+ return gRefreshPerfStats;
208
+ #else
209
+ // Perf off: the timer-derived `… += refreshPerfNowUs() - start` writes already
210
+ // fold to `+= 0` (refreshPerfNowUs() returns 0), and the ScopedRefreshStat
211
+ // guards optimize away. The few remaining bare counters in tree_render/render
212
+ // (`treePanReplayCalls++`, `treePanRepaintArea += …`) are routed to a throwaway
213
+ // that nothing reads, so they never touch live state.
214
+ #if GEA_EMBEDDED_UI_STATE_DYNAMIC_INIT
215
+ // On the heap, not static: the -1 sentinels make the throwaway a .data
216
+ // object (see state_init.h).
217
+ static RefreshPerfStats &discard = *new RefreshPerfStats();
218
+ #else
219
+ static RefreshPerfStats discard;
220
+ #endif
221
+ return discard;
222
+ #endif
223
+ }
224
+
225
+ inline void refreshPerfStatsReset()
226
+ {
227
+ gRefreshPerfStats = {};
228
+ }
229
+
230
+ inline RefreshPerfStats refreshPerfStatsRead()
231
+ {
232
+ return gRefreshPerfStats;
233
+ }
234
+
235
+ } // namespace gea::embedded::ui
@@ -0,0 +1,68 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ #pragma once
3
+
4
+ #include <atomic>
5
+
6
+ namespace gea::embedded::ui {
7
+
8
+ enum class RefreshTraceStage : int {
9
+ Idle,
10
+ Begin,
11
+ RootScroll,
12
+ LayoutMode,
13
+ Layout,
14
+ DirectPrepare,
15
+ DisplayListRebuild,
16
+ DirtyCollect,
17
+ DirtyCoalesce,
18
+ RectReplay,
19
+ RectFlush,
20
+ Snapshot,
21
+ CanvasReset,
22
+ };
23
+
24
+ inline std::atomic<int> gRefreshTraceStage{static_cast<int>(RefreshTraceStage::Idle)};
25
+ inline std::atomic<int> gRefreshTraceIndex{0};
26
+
27
+ inline void refreshTraceSet(RefreshTraceStage stage, int index = 0)
28
+ {
29
+ gRefreshTraceIndex.store(index, std::memory_order_relaxed);
30
+ gRefreshTraceStage.store(static_cast<int>(stage), std::memory_order_release);
31
+ }
32
+
33
+ inline RefreshTraceStage refreshTraceStage()
34
+ {
35
+ return static_cast<RefreshTraceStage>(gRefreshTraceStage.load(std::memory_order_acquire));
36
+ }
37
+
38
+ inline int refreshTraceIndex()
39
+ {
40
+ return gRefreshTraceIndex.load(std::memory_order_relaxed);
41
+ }
42
+
43
+ inline const char *refreshTraceStageName(RefreshTraceStage stage)
44
+ {
45
+ switch (stage) {
46
+ case RefreshTraceStage::Begin: return "begin";
47
+ case RefreshTraceStage::RootScroll: return "root_scroll";
48
+ case RefreshTraceStage::LayoutMode: return "layout_mode";
49
+ case RefreshTraceStage::Layout: return "layout";
50
+ case RefreshTraceStage::DirectPrepare: return "direct_prepare";
51
+ case RefreshTraceStage::DisplayListRebuild: return "display_list_rebuild";
52
+ case RefreshTraceStage::DirtyCollect: return "dirty_collect";
53
+ case RefreshTraceStage::DirtyCoalesce: return "dirty_coalesce";
54
+ case RefreshTraceStage::RectReplay: return "rect_replay";
55
+ case RefreshTraceStage::RectFlush: return "rect_flush";
56
+ case RefreshTraceStage::Snapshot: return "snapshot";
57
+ case RefreshTraceStage::CanvasReset: return "canvas_reset";
58
+ case RefreshTraceStage::Idle: return "idle";
59
+ }
60
+ return "idle";
61
+ }
62
+
63
+ inline const char *refreshTraceStageName()
64
+ {
65
+ return refreshTraceStageName(refreshTraceStage());
66
+ }
67
+
68
+ } // namespace gea::embedded::ui