@geastack/engine 0.1.13 → 0.1.15

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.
@@ -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(); });
@@ -1849,6 +2014,24 @@ namespace gea::embedded::ui
1849
2014
  }
1850
2015
  return -1;
1851
2016
  }
2017
+ // A transformed parent re-records its whole subtree (its descendants'
2018
+ // corners all move). When no descendant paints anything -- the empty slot
2019
+ // of `{done ? <img/> : null}` inside a pulsing dot -- there is nothing to
2020
+ // move, and the node's own commands re-record in place like a leaf's. A
2021
+ // descendant that starts painting cannot splice into its empty range, so
2022
+ // rerecordNodeCommands refuses and the frame still falls back to a full
2023
+ // record. Ember's flow dot otherwise rebuilt the whole list every frame.
2024
+ bool descendantsPaintNothing(TreeState &state, int node)
2025
+ {
2026
+ for (int child = state.nodes[node].first_child; child >= 0; child = state.nodes[child].next_sibling)
2027
+ {
2028
+ if (DisplayList::instance().nodeCommandCount(child) != 0)
2029
+ return false;
2030
+ if (!descendantsPaintNothing(state, child))
2031
+ return false;
2032
+ }
2033
+ return true;
2034
+ }
1852
2035
  } // namespace
1853
2036
 
1854
2037
  void Tree::refresh(int root, int width, int height)
@@ -1876,6 +2059,24 @@ namespace gea::embedded::ui
1876
2059
  GEA_REFRESH_PERF(perf.treeRefreshCalls++);
1877
2060
  DisplayList::instance().clearRetainedBackgroundRecolors();
1878
2061
 
2062
+ #if GEA_EMBEDDED_DISPLAY_BANDED_UI
2063
+ // Banded frames never touch the framebuffer (see bandedUiEligible). A frame
2064
+ // that must take the framebuffer path after banded ones first repaints the
2065
+ // whole viewport into it: a structural rebuild does exactly that.
2066
+ const bool banded = bandedUiEligible();
2067
+ const bool framebufferReadable = !banded && !gBandedFramebufferStaleFlag;
2068
+ if (!banded && gBandedFramebufferStaleFlag)
2069
+ {
2070
+ state.displayListDirty = true;
2071
+ state.displayListRebuildStructural = true;
2072
+ state.nodes[root].render.dirty = true;
2073
+ state.nodes[root].render.layout_dirty = true;
2074
+ gBandedFramebufferStaleFlag = false;
2075
+ }
2076
+ #else
2077
+ constexpr bool banded = false;
2078
+ constexpr bool framebufferReadable = true;
2079
+ #endif
1879
2080
  const bool textClipDependencies = DisplayList::instance().hasTextClippedBackgrounds();
1880
2081
  if (textClipDependencies) {
1881
2082
  bool changed = state.displayListDirty;
@@ -1890,7 +2091,7 @@ namespace gea::embedded::ui
1890
2091
  state.nodes[root].render.dirty = true;
1891
2092
  }
1892
2093
  }
1893
- if (!textClipDependencies && state.pendingScrollIntoViewNode < 0 && RootScrollOnlyRefresh::refresh(root, width, height))
2094
+ if (framebufferReadable && !textClipDependencies && state.pendingScrollIntoViewNode < 0 && RootScrollOnlyRefresh::refresh(root, width, height))
1894
2095
  return;
1895
2096
 
1896
2097
  // This frame is NOT a pure scroll, so the software scroll register's
@@ -2228,7 +2429,8 @@ namespace gea::embedded::ui
2228
2429
  continue;
2229
2430
  if (layoutSizeChangeNeedsCommandRerecord(*n))
2230
2431
  state.nodeCommandDirty[i] = 1;
2231
- if (state.nodeCommandDirty[i] && n->render.transform_dirty && n->first_child >= 0)
2432
+ if (state.nodeCommandDirty[i] && n->render.transform_dirty && n->first_child >= 0 &&
2433
+ !descendantsPaintNothing(state, i))
2232
2434
  {
2233
2435
  rebuild_for_transform = 1;
2234
2436
  continue;
@@ -2368,7 +2570,7 @@ namespace gea::embedded::ui
2368
2570
  // Horizontal-pan fast path: when a camera/world wrapper translated the viewport
2369
2571
  // this frame (and nothing structural changed), memcpy-shift the viewport instead
2370
2572
  // of re-replaying the whole panned scene. Handles the frame fully when it engages.
2371
- if (tryHorizontalPanRefresh(root, width, height, framebuffer_was_dirty,
2573
+ if (framebufferReadable && tryHorizontalPanRefresh(root, width, height, framebuffer_was_dirty,
2372
2574
  display_list_was_dirty, display_list_was_structural,
2373
2575
  displayListFullRecord))
2374
2576
  {
@@ -2457,7 +2659,8 @@ namespace gea::embedded::ui
2457
2659
  continue;
2458
2660
  }
2459
2661
 
2460
- if (!canvas_dirty &&
2662
+ if (framebufferReadable &&
2663
+ !canvas_dirty &&
2461
2664
  direct_replay &&
2462
2665
  n->render.bg_recolor_pending &&
2463
2666
  n->first_child < 0 &&
@@ -2845,6 +3048,38 @@ namespace gea::embedded::ui
2845
3048
  (int)simpleUnifiedReplay, (int)interleavedUnifiedFlush, (int)hasFlushOnlyRecolorRegions,
2846
3049
  (int)GEA_EMBEDDED_DISPLAY_FUSE_REPLAY_FLUSH);
2847
3050
  }
3051
+ #endif
3052
+ #if GEA_EMBEDDED_DISPLAY_BANDED_UI
3053
+ if (banded)
3054
+ {
3055
+ // Every pixel the panel receives is re-rendered into its band, so the band
3056
+ // set is everything this frame repaints (rects) or transmits (flush_rects).
3057
+ DirtyRegions::Rect bandRegions[DirtyRegions::kMaxRects];
3058
+ int bandRegionCount = 0;
3059
+ for (int i = 0; i < flush_rect_count; i++)
3060
+ addDirtyRegion(bandRegions, &bandRegionCount, flush_rects[i], width, height);
3061
+ for (int i = 0; i < rect_count; i++)
3062
+ addDirtyRegion(bandRegions, &bandRegionCount, rects[i], width, height);
3063
+ coalesceLowCostDirtyRegions(bandRegions, &bandRegionCount);
3064
+ gea::platform::display::DisplayFlushRect bandRects[DirtyRegions::kMaxRects];
3065
+ int bandRectCount = 0;
3066
+ for (int i = 0; i < bandRegionCount; i++)
3067
+ {
3068
+ const DirtyRegions::Rect &r = bandRegions[i];
3069
+ if (r.x0 > r.x1 || r.y0 > r.y1)
3070
+ continue;
3071
+ bandRects[bandRectCount++] = gea::platform::display::DisplayFlushRect{r.x0, r.y0, r.x1, r.y1};
3072
+ }
3073
+ const std::int64_t flushStartUs = refreshPerfNowUs();
3074
+ if (bandRectCount > 0)
3075
+ {
3076
+ if (direct_replay)
3077
+ GEA_REFRESH_PERF(perf.treeDirectReplayCalls++);
3078
+ bandedFlush(bandRects, bandRectCount, width, height, direct_replay != 0);
3079
+ }
3080
+ GEA_REFRESH_PERF(perf.treeFlushRectsUs += refreshPerfNowUs() - flushStartUs);
3081
+ }
3082
+ else
2848
3083
  #endif
2849
3084
  if (simpleUnifiedReplay)
2850
3085
  {
@@ -3086,18 +3321,21 @@ namespace gea::embedded::ui
3086
3321
  display_list_was_structural ? 1 : 0, rect_count, flush_rect_count);
3087
3322
  }
3088
3323
  #endif
3324
+ // Banded: never bake — the cache is a second full-screen PSRAM copy whose
3325
+ // blits are exactly the read-back this mode removes (directReplay=false
3326
+ // keeps it invalid).
3089
3327
  DisplayList::instance().maybeBakeStaticBackdrop(
3090
3328
  width,
3091
3329
  height,
3092
3330
  !display_list_was_structural && staticBackdropStable,
3093
- direct_replay != 0 && !simpleDirtyReplayAvailable && staticBackdropStable,
3331
+ !banded && direct_replay != 0 && !simpleDirtyReplayAvailable && staticBackdropStable,
3094
3332
  staticBackdropEligible);
3095
3333
 
3096
3334
  const std::int64_t flushRectsStartUs = refreshPerfNowUs();
3097
3335
  #if defined(ESP_PLATFORM) && CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS
3098
3336
  const auto diagnosticReplayEnd = esp_timer_get_time();
3099
3337
  #endif
3100
- if (!simpleUnifiedReplay && !interleavedUnifiedFlush)
3338
+ if (!banded && !simpleUnifiedReplay && !interleavedUnifiedFlush)
3101
3339
  {
3102
3340
  for (int i = 0; i < flush_rect_count; i++)
3103
3341
  {
package/ui/view.cpp CHANGED
@@ -1299,6 +1299,20 @@ public:
1299
1299
  long s = std::lroundf(v * 8.0f);
1300
1300
  return (int16_t)(s < -32768 ? -32768 : (s > 32767 ? 32767 : s));
1301
1301
  };
1302
+ // No transform or perspective anywhere up the chain: every ancestor's
1303
+ // coefficients are the identity about its origin, which returns integer
1304
+ // corners exactly. Skip gathering them -- a cache probe and coefficient
1305
+ // fill per ancestor, ~80 us for a 6-deep chain on the ESP32-S31, paid by
1306
+ // every untransformed image and text box re-recorded while anything else
1307
+ // on screen animates a transform.
1308
+ if (!hasTransformChain(node, usePrevious)) {
1309
+ for (int i = 0; i < 4; i++) {
1310
+ xs[i] = (int16_t)std::lroundf(points[i].x);
1311
+ ys[i] = (int16_t)std::lroundf(points[i].y);
1312
+ if (xs8) { xs8[i] = fx8(points[i].x); ys8[i] = fx8(points[i].y); }
1313
+ }
1314
+ return;
1315
+ }
1302
1316
  auto &state = treeState();
1303
1317
  const int perspectiveNode = nearestPerspectiveNode(node, usePrevious);
1304
1318
  const NodeTransformCache *chain[kMaxChainDepth];