@geastack/engine 0.1.13 → 0.1.14

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geastack/engine",
3
- "version": "0.1.13",
3
+ "version": "0.1.14",
4
4
  "description": "GeaStack rendering engine, intrinsic JSX primitives, and native engine backends.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -57,6 +57,6 @@
57
57
  },
58
58
  "sideEffects": false,
59
59
  "dependencies": {
60
- "@geastack/core": "^0.1.36"
60
+ "@geastack/core": "^0.1.38"
61
61
  }
62
62
  }
package/ui/render.cpp CHANGED
@@ -138,6 +138,16 @@ extern "C" __attribute__((weak)) void *gea_display_command_buffer(int *cap_comma
138
138
  return nullptr;
139
139
  }
140
140
 
141
+ // Banded UI mode (GEA_EMBEDDED_DISPLAY_BANDED_UI) replays into a DMA staging
142
+ // chunk the shared canvas is temporarily bound to; the worker core's canvas
143
+ // still addresses the framebuffer, so no replay/fill may split across cores
144
+ // while a band rasterizes. Constant true everywhere else.
145
+ #if GEA_EMBEDDED_DISPLAY_BANDED_UI
146
+ #define GEA_RENDER_SPLIT_ALLOWED (!gea::embedded::ui::gBandedRasterActive)
147
+ #else
148
+ #define GEA_RENDER_SPLIT_ALLOWED 1
149
+ #endif
150
+
141
151
  // 2nd-core fill offload. The target may provide a worker pinned to the other CPU;
142
152
  // submit() hands it a row band (returns false if there's no worker), wait() joins.
143
153
  // Weak defaults = no worker, so the fill runs entirely on the calling core
@@ -3287,7 +3297,7 @@ int gLastScrollUiFrame = -1000;
3287
3297
  gSplitN = gInlineN = gSplitRows = gInlineRows = gMaxRows = 0;
3288
3298
  }
3289
3299
  };
3290
- if (rows >= kMinRowsToSplit)
3300
+ if (GEA_RENDER_SPLIT_ALLOWED && rows >= kMinRowsToSplit)
3291
3301
  {
3292
3302
  const int mid = (y0 + y1) >> 1;
3293
3303
  struct Trampoline
@@ -7911,7 +7921,7 @@ int gLastScrollUiFrame = -1000;
7911
7921
  constexpr int kMinPixelsToSplitFrame = GEA_EMBEDDED_RENDER_PARALLEL_MIN_PIXELS;
7912
7922
  const int regionW = x1 - x0 + 1;
7913
7923
  const int regionH = y1 - y0 + 1;
7914
- if (GEA_EMBEDDED_RENDER_PARALLEL_DIRTY_REPLAY && allowSplit && regionW > 0 && regionH >= kMinRowsToSplitFrame &&
7924
+ if (GEA_EMBEDDED_RENDER_PARALLEL_DIRTY_REPLAY && GEA_RENDER_SPLIT_ALLOWED && allowSplit && regionW > 0 && regionH >= kMinRowsToSplitFrame &&
7915
7925
  regionW * regionH >= kMinPixelsToSplitFrame)
7916
7926
  {
7917
7927
  int mainRows = (regionH * gea_render_parallel_main_share_permille()) / 1000;
@@ -8285,7 +8295,7 @@ int gLastScrollUiFrame = -1000;
8285
8295
  constexpr int kMinPixelsToSplitFrame = GEA_EMBEDDED_RENDER_PARALLEL_MIN_PIXELS;
8286
8296
  const int regionW = x1 - x0 + 1;
8287
8297
  const int regionH = y1 - y0 + 1;
8288
- if (GEA_EMBEDDED_RENDER_PARALLEL_DIRTY_REPLAY && allowSplit && regionW > 0 && regionH >= kMinRowsToSplitFrame &&
8298
+ if (GEA_EMBEDDED_RENDER_PARALLEL_DIRTY_REPLAY && GEA_RENDER_SPLIT_ALLOWED && allowSplit && regionW > 0 && regionH >= kMinRowsToSplitFrame &&
8289
8299
  regionW * regionH >= kMinPixelsToSplitFrame)
8290
8300
  {
8291
8301
  int mainRows = (regionH * gea_render_parallel_main_share_permille()) / 1000;
@@ -8801,7 +8811,7 @@ int gLastScrollUiFrame = -1000;
8801
8811
  constexpr int kMaxSplitRegions = 32;
8802
8812
  constexpr int kMinRowsToSplitFrame = GEA_EMBEDDED_RENDER_PARALLEL_MIN_ROWS;
8803
8813
  constexpr int kMinPixelsToSplitFrame = GEA_EMBEDDED_RENDER_PARALLEL_MIN_PIXELS;
8804
- if (GEA_EMBEDDED_RENDER_PARALLEL_DIRTY_REPLAY && allowSplit && count <= kMaxSplitRegions)
8814
+ if (GEA_EMBEDDED_RENDER_PARALLEL_DIRTY_REPLAY && GEA_RENDER_SPLIT_ALLOWED && allowSplit && count <= kMaxSplitRegions)
8805
8815
  {
8806
8816
  int minY = 0x7fffffff, maxY = -0x7fffffff;
8807
8817
  int totalArea = 0;
@@ -9,6 +9,14 @@
9
9
  #include <string>
10
10
  #include <string_view>
11
11
 
12
+ // Framebuffer-free retained rendering: each dirty band is rasterized into the
13
+ // display's internal-RAM DMA chunk and streamed to the panel while the next
14
+ // band renders (tree_render.cpp). A board capability, set by the target's
15
+ // CMake; off everywhere else, where it compiles out entirely.
16
+ #ifndef GEA_EMBEDDED_DISPLAY_BANDED_UI
17
+ #define GEA_EMBEDDED_DISPLAY_BANDED_UI 0
18
+ #endif
19
+
12
20
  namespace gea::embedded::ui {
13
21
 
14
22
  class Tree {
@@ -207,4 +215,17 @@ void releaseRareData(int node); // frees the block back to the pool
207
215
  // Caller must hold AppState::lock(). Returns false for canvas/present apps.
208
216
  bool renderRetainedSnapshotRgb565(std::uint16_t *dst, int width, int height);
209
217
 
218
+ #if GEA_EMBEDDED_DISPLAY_BANDED_UI
219
+ // Banded UI mode: the retained tree renders each dirty band straight into the
220
+ // display's DMA staging buffers, so the PSRAM framebuffer does not hold the
221
+ // frame on the panel. True once a banded frame has been presented (until a
222
+ // full repaint into the framebuffer makes it current again) — a screenshot
223
+ // must then re-render instead of copying the framebuffer.
224
+ bool retainedFramebufferStale();
225
+ // Set while a banded raster callback replays into a staging chunk. The 2-core
226
+ // replay split must not engage then: the worker core's canvas is bound to the
227
+ // framebuffer, not to the chunk.
228
+ extern bool gBandedRasterActive;
229
+ #endif
230
+
210
231
  } // namespace gea::embedded::ui
@@ -141,6 +141,119 @@ namespace gea::embedded::ui
141
141
  }
142
142
  #endif
143
143
 
144
+ #if GEA_EMBEDDED_DISPLAY_BANDED_UI
145
+ // Banded (framebuffer-free) retained rendering.
146
+ //
147
+ // Every frame that reaches the panel is rasterized band by band straight into
148
+ // the display's internal-RAM DMA staging chunks: the chunk is cleared, the
149
+ // native underlay (gea3d) paints it, the display list replays clipped to it,
150
+ // and the display streams it while the next chunk renders. The PSRAM
151
+ // framebuffer is neither written nor read back for these frames.
152
+ //
153
+ // Nothing may therefore depend on the framebuffer holding the last frame.
154
+ // The paths that do are bypassed while banded: the root-scroll pixel shift,
155
+ // the horizontal-pan memcpy, the in-place background recolor, and the
156
+ // static-backdrop cache (never baked). Scenes that still need old pixels —
157
+ // filter: blur() captures its backdrop from the framebuffer over the node's
158
+ // whole bounds, and a display-backed <canvas> draws into it directly — fall
159
+ // back to the framebuffer path, after one full repaint that makes the
160
+ // framebuffer current again.
161
+ bool gBandedFramebufferStaleFlag = false;
162
+
163
+ bool bandedUiEligible()
164
+ {
165
+ if (Document::directCanvasContextUsed())
166
+ return false;
167
+ if (!gea::platform::display::Display::canvas())
168
+ return false;
169
+ auto &state = treeState();
170
+ #if GEA_CSS_FILTERS
171
+ for (int i = 0; i < state.nodeCount; i++)
172
+ {
173
+ if (rstyle(state.nodes[i].computedStyle()).filter_blur_radius > 0)
174
+ return false;
175
+ }
176
+ #endif
177
+ bool displayBackedCanvas = false;
178
+ state.canvases.forEach([&](const CanvasSurfaceState &surface)
179
+ { displayBackedCanvas = displayBackedCanvas || surface.displayBacked(); });
180
+ return !displayBackedCanvas;
181
+ }
182
+
183
+ struct BandedRasterCtx
184
+ {
185
+ int screenW;
186
+ int screenH;
187
+ // The frame may use the direct dirty-region replay (same gate as the
188
+ // framebuffer path's direct_replay). Otherwise the conservative full
189
+ // replay runs, clipped to the band.
190
+ bool direct;
191
+ };
192
+
193
+ // Replays [x0,x1] x [y0,y1] into the bound canvas, whose clip is already that
194
+ // region. The underlay is painted first so the tree lands on top of it; the
195
+ // direct replay restores its own clear base, which would paint over an
196
+ // underlay, so a frame with one always takes the full replay.
197
+ void bandedReplayRegion(int x0, int y0, int x1, int y1, bool direct)
198
+ {
199
+ if (direct && !gea::framework::display::Underlay::active())
200
+ {
201
+ const DisplayReplayRegion region{x0, y0, x1, y1, -1};
202
+ DisplayList::instance().replayDirectDirtyRegions(&region, 1);
203
+ return;
204
+ }
205
+ gea::framework::display::Underlay::paint(x0, y0, x1, y1);
206
+ DisplayList::instance().replay();
207
+ }
208
+
209
+ // Display::flushRectsRasterized callback: `pixels` holds rows [oy, oy+height)
210
+ // x columns [ox, ox+width) with stride `width`. The canvas is bound onto it
211
+ // through an offset base pointer so absolute screen coordinates land in the
212
+ // chunk; the clip keeps every write inside it.
213
+ void bandedRaster(gea::framework::graphics::pixel::native_t *pixels, int width, int height, int ox, int oy, void *user)
214
+ {
215
+ auto *ctx = static_cast<BandedRasterCtx *>(user);
216
+ auto *canvas = gea::platform::display::Display::canvas();
217
+ if (!canvas || !ctx)
218
+ return;
219
+ using PixT = gea::framework::graphics::pixel::native_t;
220
+ const std::int64_t replayStartUs = refreshPerfNowUs();
221
+ // The framebuffer path starts from Display::clearNoFlush()'s black; so
222
+ // does every band (a scene that leaves pixels uncovered shows black, never
223
+ // the previous band's bytes).
224
+ std::fill_n(pixels, static_cast<std::size_t>(width) * static_cast<std::size_t>(height),
225
+ gea::framework::graphics::pixel::fromRgb565(0x0000));
226
+ PixT *base = pixels - (static_cast<std::ptrdiff_t>(oy) * width + ox);
227
+ canvas->bindPixels(base, ctx->screenW, ctx->screenH, width);
228
+ gea::platform::display::Display::resetClip();
229
+ gea::platform::display::Display::setAlpha(255);
230
+ gea::platform::display::Display::pushClip(ox, oy, width, height);
231
+ gBandedRasterActive = true;
232
+ bandedReplayRegion(ox, oy, ox + width - 1, oy + height - 1, ctx->direct);
233
+ gBandedRasterActive = false;
234
+ gea::platform::display::Display::popClip();
235
+ GEA_REFRESH_PERF(refreshPerfStatsMutable().treeReplayUs += refreshPerfNowUs() - replayStartUs);
236
+ }
237
+
238
+ void bandedFlush(const gea::platform::display::DisplayFlushRect *rects, int count, int width, int height, bool direct)
239
+ {
240
+ if (!rects || count <= 0)
241
+ return;
242
+ BandedRasterCtx ctx{width, height, direct};
243
+ gea::platform::display::Display::flushRectsRasterized(rects, count, bandedRaster, &ctx, /*allowPerChunkDrain=*/false);
244
+ gea::platform::display::Display::rebindCanvasToFramebuffer();
245
+ gBandedFramebufferStaleFlag = true;
246
+ }
247
+
248
+ void bandedFlushFullScreen(int width, int height, bool direct)
249
+ {
250
+ if (width <= 0 || height <= 0)
251
+ return;
252
+ const gea::platform::display::DisplayFlushRect full{0, 0, width - 1, height - 1};
253
+ bandedFlush(&full, 1, width, height, direct);
254
+ }
255
+ #endif
256
+
144
257
  #if GEA_CSS_SCROLLING
145
258
  struct PreservedScrollOffset
146
259
  {
@@ -1572,10 +1685,46 @@ namespace gea::embedded::ui
1572
1685
  // The caller must hold AppState::lock() so the frame task isn't using the shared canvas
1573
1686
  // or mutating the list. Returns false for non-retained (canvas/present) apps, whose
1574
1687
  // pixels aren't in the retained command list — the caller falls back to the present path.
1688
+ #if GEA_EMBEDDED_DISPLAY_BANDED_UI
1689
+ bool gBandedRasterActive = false;
1690
+
1691
+ bool retainedFramebufferStale()
1692
+ {
1693
+ return gBandedFramebufferStaleFlag;
1694
+ }
1695
+ #endif
1696
+
1575
1697
  bool renderRetainedSnapshotRgb565(std::uint16_t *dst, int width, int height)
1576
1698
  {
1577
1699
  if (!dst || width <= 0 || height <= 0)
1578
1700
  return false;
1701
+ #if GEA_EMBEDDED_DISPLAY_BANDED_UI
1702
+ // A banded frame lives only on the panel: render it again the way the
1703
+ // bands did — black base, the underlay, then the whole display list.
1704
+ if (gBandedFramebufferStaleFlag && DisplayList::instance().commandCount() > 0)
1705
+ {
1706
+ auto *bandCanvas = gea::platform::display::Display::canvas();
1707
+ if (!bandCanvas)
1708
+ return false;
1709
+ using PixT = gea::framework::graphics::pixel::native_t;
1710
+ PixT *base = reinterpret_cast<PixT *>(dst);
1711
+ std::fill_n(base, static_cast<std::size_t>(width) * static_cast<std::size_t>(height),
1712
+ gea::framework::graphics::pixel::fromRgb565(0x0000));
1713
+ bandCanvas->bindPixels(base, width, height, width);
1714
+ gea::platform::display::Display::resetClip();
1715
+ gea::platform::display::Display::setAlpha(255);
1716
+ gea::platform::display::Display::pushClip(0, 0, width, height);
1717
+ gBandedRasterActive = true;
1718
+ bandedReplayRegion(0, 0, width - 1, height - 1, /*direct=*/false);
1719
+ gBandedRasterActive = false;
1720
+ gea::platform::display::Display::popClip();
1721
+ gea::platform::display::Display::rebindCanvasToFramebuffer();
1722
+ const int pixels = width * height;
1723
+ for (int i = 0; i < pixels; i++)
1724
+ dst[i] = gea::framework::graphics::pixel::toRgb565(base[i]);
1725
+ return true;
1726
+ }
1727
+ #endif
1579
1728
  if (DisplayList::instance().commandCount() < 2)
1580
1729
  return false; // canvas/present app: nothing retained to replay
1581
1730
  auto *canvas = gea::platform::display::Display::canvas();
@@ -1676,10 +1825,25 @@ namespace gea::embedded::ui
1676
1825
  DisplayList::instance().clear();
1677
1826
  DisplayList::instance().recordNode(root, 255);
1678
1827
  DisplayList::instance().weldTransformedFaces();
1828
+ #if GEA_EMBEDDED_DISPLAY_BANDED_UI
1829
+ if (!styleMountBatchActive() && bandedUiEligible())
1830
+ {
1831
+ state.displayListDirty = false;
1832
+ state.displayListRebuildStructural = false;
1833
+ bandedFlushFullScreen(width, height, /*direct=*/false);
1834
+ // The framebuffer was cleared above but holds none of this frame.
1835
+ gea::platform::display::Display::canvas()->resetDirty();
1836
+ }
1837
+ else
1838
+ #endif
1839
+ {
1679
1840
  gea::framework::display::Underlay::paint(0, 0, width - 1, height - 1);
1680
1841
  DisplayList::instance().replay();
1681
1842
  state.displayListDirty = false;
1682
1843
  state.displayListRebuildStructural = false; // this path already repainted everything
1844
+ #if GEA_EMBEDDED_DISPLAY_BANDED_UI
1845
+ gBandedFramebufferStaleFlag = false; // the framebuffer holds the whole frame again
1846
+ #endif
1683
1847
 
1684
1848
  // Don't present the very first mount while the initial style batch is still
1685
1849
  // open: per-node class styles haven't been applied yet, so this frame is
@@ -1688,6 +1852,7 @@ namespace gea::embedded::ui
1688
1852
  // avoiding a flash of unstyled content (text + images, no CSS) at boot.
1689
1853
  if (!styleMountBatchActive())
1690
1854
  gea::platform::display::Display::flush();
1855
+ }
1691
1856
  state.canvases.forEach([](CanvasSurfaceState &surface)
1692
1857
  {
1693
1858
  if (auto *canvas = surface.canvas()) canvas->resetDirty(); });
@@ -1876,6 +2041,24 @@ namespace gea::embedded::ui
1876
2041
  GEA_REFRESH_PERF(perf.treeRefreshCalls++);
1877
2042
  DisplayList::instance().clearRetainedBackgroundRecolors();
1878
2043
 
2044
+ #if GEA_EMBEDDED_DISPLAY_BANDED_UI
2045
+ // Banded frames never touch the framebuffer (see bandedUiEligible). A frame
2046
+ // that must take the framebuffer path after banded ones first repaints the
2047
+ // whole viewport into it: a structural rebuild does exactly that.
2048
+ const bool banded = bandedUiEligible();
2049
+ const bool framebufferReadable = !banded && !gBandedFramebufferStaleFlag;
2050
+ if (!banded && gBandedFramebufferStaleFlag)
2051
+ {
2052
+ state.displayListDirty = true;
2053
+ state.displayListRebuildStructural = true;
2054
+ state.nodes[root].render.dirty = true;
2055
+ state.nodes[root].render.layout_dirty = true;
2056
+ gBandedFramebufferStaleFlag = false;
2057
+ }
2058
+ #else
2059
+ constexpr bool banded = false;
2060
+ constexpr bool framebufferReadable = true;
2061
+ #endif
1879
2062
  const bool textClipDependencies = DisplayList::instance().hasTextClippedBackgrounds();
1880
2063
  if (textClipDependencies) {
1881
2064
  bool changed = state.displayListDirty;
@@ -1890,7 +2073,7 @@ namespace gea::embedded::ui
1890
2073
  state.nodes[root].render.dirty = true;
1891
2074
  }
1892
2075
  }
1893
- if (!textClipDependencies && state.pendingScrollIntoViewNode < 0 && RootScrollOnlyRefresh::refresh(root, width, height))
2076
+ if (framebufferReadable && !textClipDependencies && state.pendingScrollIntoViewNode < 0 && RootScrollOnlyRefresh::refresh(root, width, height))
1894
2077
  return;
1895
2078
 
1896
2079
  // This frame is NOT a pure scroll, so the software scroll register's
@@ -2368,7 +2551,7 @@ namespace gea::embedded::ui
2368
2551
  // Horizontal-pan fast path: when a camera/world wrapper translated the viewport
2369
2552
  // this frame (and nothing structural changed), memcpy-shift the viewport instead
2370
2553
  // of re-replaying the whole panned scene. Handles the frame fully when it engages.
2371
- if (tryHorizontalPanRefresh(root, width, height, framebuffer_was_dirty,
2554
+ if (framebufferReadable && tryHorizontalPanRefresh(root, width, height, framebuffer_was_dirty,
2372
2555
  display_list_was_dirty, display_list_was_structural,
2373
2556
  displayListFullRecord))
2374
2557
  {
@@ -2457,7 +2640,8 @@ namespace gea::embedded::ui
2457
2640
  continue;
2458
2641
  }
2459
2642
 
2460
- if (!canvas_dirty &&
2643
+ if (framebufferReadable &&
2644
+ !canvas_dirty &&
2461
2645
  direct_replay &&
2462
2646
  n->render.bg_recolor_pending &&
2463
2647
  n->first_child < 0 &&
@@ -2845,6 +3029,38 @@ namespace gea::embedded::ui
2845
3029
  (int)simpleUnifiedReplay, (int)interleavedUnifiedFlush, (int)hasFlushOnlyRecolorRegions,
2846
3030
  (int)GEA_EMBEDDED_DISPLAY_FUSE_REPLAY_FLUSH);
2847
3031
  }
3032
+ #endif
3033
+ #if GEA_EMBEDDED_DISPLAY_BANDED_UI
3034
+ if (banded)
3035
+ {
3036
+ // Every pixel the panel receives is re-rendered into its band, so the band
3037
+ // set is everything this frame repaints (rects) or transmits (flush_rects).
3038
+ DirtyRegions::Rect bandRegions[DirtyRegions::kMaxRects];
3039
+ int bandRegionCount = 0;
3040
+ for (int i = 0; i < flush_rect_count; i++)
3041
+ addDirtyRegion(bandRegions, &bandRegionCount, flush_rects[i], width, height);
3042
+ for (int i = 0; i < rect_count; i++)
3043
+ addDirtyRegion(bandRegions, &bandRegionCount, rects[i], width, height);
3044
+ coalesceLowCostDirtyRegions(bandRegions, &bandRegionCount);
3045
+ gea::platform::display::DisplayFlushRect bandRects[DirtyRegions::kMaxRects];
3046
+ int bandRectCount = 0;
3047
+ for (int i = 0; i < bandRegionCount; i++)
3048
+ {
3049
+ const DirtyRegions::Rect &r = bandRegions[i];
3050
+ if (r.x0 > r.x1 || r.y0 > r.y1)
3051
+ continue;
3052
+ bandRects[bandRectCount++] = gea::platform::display::DisplayFlushRect{r.x0, r.y0, r.x1, r.y1};
3053
+ }
3054
+ const std::int64_t flushStartUs = refreshPerfNowUs();
3055
+ if (bandRectCount > 0)
3056
+ {
3057
+ if (direct_replay)
3058
+ GEA_REFRESH_PERF(perf.treeDirectReplayCalls++);
3059
+ bandedFlush(bandRects, bandRectCount, width, height, direct_replay != 0);
3060
+ }
3061
+ GEA_REFRESH_PERF(perf.treeFlushRectsUs += refreshPerfNowUs() - flushStartUs);
3062
+ }
3063
+ else
2848
3064
  #endif
2849
3065
  if (simpleUnifiedReplay)
2850
3066
  {
@@ -3086,18 +3302,21 @@ namespace gea::embedded::ui
3086
3302
  display_list_was_structural ? 1 : 0, rect_count, flush_rect_count);
3087
3303
  }
3088
3304
  #endif
3305
+ // Banded: never bake — the cache is a second full-screen PSRAM copy whose
3306
+ // blits are exactly the read-back this mode removes (directReplay=false
3307
+ // keeps it invalid).
3089
3308
  DisplayList::instance().maybeBakeStaticBackdrop(
3090
3309
  width,
3091
3310
  height,
3092
3311
  !display_list_was_structural && staticBackdropStable,
3093
- direct_replay != 0 && !simpleDirtyReplayAvailable && staticBackdropStable,
3312
+ !banded && direct_replay != 0 && !simpleDirtyReplayAvailable && staticBackdropStable,
3094
3313
  staticBackdropEligible);
3095
3314
 
3096
3315
  const std::int64_t flushRectsStartUs = refreshPerfNowUs();
3097
3316
  #if defined(ESP_PLATFORM) && CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS
3098
3317
  const auto diagnosticReplayEnd = esp_timer_get_time();
3099
3318
  #endif
3100
- if (!simpleUnifiedReplay && !interleavedUnifiedFlush)
3319
+ if (!banded && !simpleUnifiedReplay && !interleavedUnifiedFlush)
3101
3320
  {
3102
3321
  for (int i = 0; i < flush_rect_count; i++)
3103
3322
  {