@geastack/engine 0.1.11 → 0.1.12

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/css/easing.h CHANGED
@@ -149,6 +149,13 @@ public:
149
149
  return t;
150
150
  }
151
151
 
152
+ bool operator==(const Easing &other) const
153
+ {
154
+ return kind_ == other.kind_ && bx1_ == other.bx1_ && by1_ == other.by1_ &&
155
+ bx2_ == other.bx2_ && by2_ == other.by2_ && steps_ == other.steps_ &&
156
+ stepPosition_ == other.stepPosition_ && custom_ == other.custom_;
157
+ }
158
+
152
159
  private:
153
160
  EasingKind kind_ = EasingKind::Linear;
154
161
  double bx1_ = 0.0, by1_ = 0.0, bx2_ = 1.0, by2_ = 1.0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geastack/engine",
3
- "version": "0.1.11",
3
+ "version": "0.1.12",
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.35"
60
+ "@geastack/core": "^0.1.36"
61
61
  }
62
62
  }
@@ -250,8 +250,12 @@ void AbsoluteLeafRefresh::refreshPositions()
250
250
  // new extent. Percent-sized nodes keep the already-resolved layout box;
251
251
  // the full layout pass owns recomputing them when their containing block
252
252
  // changes.
253
- if (n->computedStyle().width != kUnset) n->layout.width = n->computedStyle().width;
254
- if (n->computedStyle().height != kUnset) n->layout.height = n->computedStyle().height;
253
+ // The style size is the content box unless box-sizing says otherwise;
254
+ // layout stores the border box, as the full layout pass does.
255
+ if (n->computedStyle().width != kUnset)
256
+ n->layout.width = clampBorderBoxSize(n->computedStyle(), contentSizeToBorderSize(n->computedStyle(), n->computedStyle().width, true), true);
257
+ if (n->computedStyle().height != kUnset)
258
+ n->layout.height = clampBorderBoxSize(n->computedStyle(), contentSizeToBorderSize(n->computedStyle(), n->computedStyle().height, false), false);
255
259
  Node *p = &state.nodes[n->parent];
256
260
  // Absolute siblings share their parent's padding box. The cache lasts
257
261
  // only for this loop: visiting a different parent invalidates it before
package/ui/document.cpp CHANGED
@@ -4,6 +4,7 @@
4
4
  #include "internal.h"
5
5
 
6
6
  #include "display.h"
7
+ #include "display_underlay.h"
7
8
  #include "tree_internal.h"
8
9
 
9
10
  #include <algorithm>
@@ -365,3 +366,47 @@ void Document::addEventListener(const char *type, gea::framework::events::EventL
365
366
  }
366
367
 
367
368
  } // namespace gea::embedded::ui
369
+
370
+ namespace
371
+ {
372
+ gea::framework::display::Underlay::Paint underlayPaint = nullptr;
373
+ void *underlayUser = nullptr;
374
+ int underlayX0 = 0, underlayY0 = 0, underlayX1 = -1, underlayY1 = -1;
375
+ } // namespace
376
+
377
+ bool gea::framework::display::Underlay::composited()
378
+ {
379
+ return !gea::embedded::ui::Document::directCanvasContextUsed() && gea::embedded::ui::Tree::instance().mountedRoot() >= 0;
380
+ }
381
+
382
+ void gea::framework::display::Underlay::set(Paint paint, void *user, int x0, int y0, int x1, int y1)
383
+ {
384
+ underlayPaint = paint;
385
+ underlayUser = user;
386
+ underlayX0 = x0;
387
+ underlayY0 = y0;
388
+ underlayX1 = x1;
389
+ underlayY1 = y1;
390
+ }
391
+
392
+ void gea::framework::display::Underlay::clear()
393
+ {
394
+ underlayPaint = nullptr;
395
+ underlayUser = nullptr;
396
+ }
397
+
398
+ bool gea::framework::display::Underlay::active()
399
+ {
400
+ return underlayPaint != nullptr;
401
+ }
402
+
403
+ void gea::framework::display::Underlay::paint(int x0, int y0, int x1, int y1)
404
+ {
405
+ if (!underlayPaint) return;
406
+ x0 = std::max(x0, underlayX0);
407
+ y0 = std::max(y0, underlayY0);
408
+ x1 = std::min(x1, underlayX1);
409
+ y1 = std::min(y1, underlayY1);
410
+ if (x0 > x1 || y0 > y1) return;
411
+ underlayPaint(x0, y0, x1, y1, underlayUser);
412
+ }
package/ui/layout.cpp CHANGED
@@ -634,9 +634,16 @@ public:
634
634
  if (node_.computedStyle().display == kDisplayFlex) {
635
635
  applyFlexBasis(child);
636
636
  Node &item = Tree::instance().nodes()[child];
637
- const int floor = automaticMinimumMainSize(item);
638
- int16_t &main = isRow_ ? item.layout.width : item.layout.height;
639
- if (main < floor) { main = clampInt16(floor); engine_.repositionChildren(child); }
637
+ // A growing item with a zero flex basis (`flex: 1`) starts from zero; its
638
+ // automatic minimum floors the FINAL flexed size (growFlexChildren), not the
639
+ // basis. Flooring the basis hands content-bearing items a head start over their
640
+ // siblings and unbalances equal-flex rows (a tic-tac-toe cell holding "X" grew
641
+ // wider than its empty neighbours).
642
+ if (!zeroBasisGrowItem(item)) {
643
+ const int floor = automaticMinimumMainSize(item);
644
+ int16_t &main = isRow_ ? item.layout.width : item.layout.height;
645
+ if (main < floor) { main = clampInt16(floor); engine_.repositionChildren(child); }
646
+ }
640
647
  }
641
648
  }
642
649
  }
@@ -1320,7 +1327,11 @@ public:
1320
1327
  Node &childNode = nodes[child];
1321
1328
  if (childNode.computedStyle().flex <= 0) continue;
1322
1329
  const int mainSize = isRow_ ? childNode.layout.width : childNode.layout.height;
1323
- if (mainSize == 0) engine_.repositionChildren(child);
1330
+ if (mainSize == 0) {
1331
+ const int floor = automaticMinimumMainSize(childNode);
1332
+ if (floor > 0) (isRow_ ? childNode.layout.width : childNode.layout.height) = clampInt16(floor);
1333
+ engine_.repositionChildren(child);
1334
+ }
1324
1335
  }
1325
1336
  }
1326
1337
  bool hasRatio = false;
@@ -1525,6 +1536,13 @@ private:
1525
1536
  return -1;
1526
1537
  }
1527
1538
 
1539
+ // True when applyFlexBasis zeroed this item: it grows from nothing.
1540
+ bool zeroBasisGrowItem(const Node &childNode) const
1541
+ {
1542
+ if (hasFlexBasis(childNode) || childNode.computedStyle().flex <= 0) return false;
1543
+ return !(isRow_ ? hasExplicitWidth(childNode) : hasExplicitHeight(childNode));
1544
+ }
1545
+
1528
1546
  void applyFlexBasis(int child)
1529
1547
  {
1530
1548
  Node &childNode = Tree::instance().nodes()[child];
@@ -1718,6 +1736,10 @@ private:
1718
1736
  const int before = isRow_ ? childNode.layout.width : childNode.layout.height;
1719
1737
  int after = before + delta;
1720
1738
  after = clampFlexMainSize(childNode, after);
1739
+ if (delta > 0 && zeroBasisGrowItem(childNode)) {
1740
+ const int autoMin = automaticMinimumMainSize(childNode);
1741
+ if (after < autoMin) after = autoMin;
1742
+ }
1721
1743
  if (delta < 0) {
1722
1744
  // Floor the shrink at the automatic minimum size, and never let that floor
1723
1745
  // GROW an item that was already smaller than its content.
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
@@ -5647,11 +5657,11 @@ int gLastScrollUiFrame = -1000;
5647
5657
  #ifndef GEA_EMBEDDED_GRADIENT_LUT_SLOTS
5648
5658
  #define GEA_EMBEDDED_GRADIENT_LUT_SLOTS 1
5649
5659
  #endif
5650
- // GEA_EMBEDDED_LAZY_GRADIENT_LUTS=1 allocates the dither tables on first use
5651
- // instead of as static arrays: the slots above plus the radial table below
5652
- // otherwise sit in .bss whether or not the app ever draws a gradient.
5660
+ // Allocate dither tables on first use by default. An app that never draws a
5661
+ // gradient must not reserve these ~20 KB in internal RAM. The slot count still
5662
+ // controls caching when gradients are actually used.
5653
5663
  #ifndef GEA_EMBEDDED_LAZY_GRADIENT_LUTS
5654
- #define GEA_EMBEDDED_LAZY_GRADIENT_LUTS 0
5664
+ #define GEA_EMBEDDED_LAZY_GRADIENT_LUTS 1
5655
5665
  #endif
5656
5666
  #if GEA_EMBEDDED_RENDERER_LINEAR_GRADIENTS
5657
5667
  struct LutSlot
@@ -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;
package/ui/style.cpp CHANGED
@@ -16356,6 +16356,43 @@ struct CssAnimationSpec {
16356
16356
  bool valid = false;
16357
16357
  };
16358
16358
 
16359
+ struct NodeCssAnimation {
16360
+ int node;
16361
+ CssAnimationSpec spec;
16362
+ std::uint32_t startMs = 0;
16363
+ bool started = false;
16364
+ std::vector<int> handles;
16365
+ };
16366
+
16367
+ // Only nodes with animation declarations occupy storage. Style recomputation
16368
+ // enrolls new nodes; the frame clock starts pending tracks once, without a
16369
+ // full-tree scan or restarting existing timelines on unrelated renders.
16370
+ std::vector<NodeCssAnimation> &nodeCssAnimations()
16371
+ {
16372
+ static std::vector<NodeCssAnimation> animations;
16373
+ return animations;
16374
+ }
16375
+
16376
+ std::uint32_t g_cssAnimationNowMs = 0;
16377
+
16378
+ bool sameAnimationSpec(const CssAnimationSpec &a, const CssAnimationSpec &b)
16379
+ {
16380
+ return a.nameAtom == b.nameAtom && a.durationMs == b.durationMs &&
16381
+ a.delayMs == b.delayMs && a.iterations == b.iterations &&
16382
+ a.direction == b.direction && a.fill == b.fill && a.easing == b.easing;
16383
+ }
16384
+
16385
+ void cancelNodeCssAnimation(int node)
16386
+ {
16387
+ auto &animations = nodeCssAnimations();
16388
+ for (auto it = animations.begin(); it != animations.end(); ++it) {
16389
+ if (it->node != node) continue;
16390
+ for (int handle : it->handles) gea::css::AnimationEngine::instance().cancel(handle);
16391
+ animations.erase(it);
16392
+ return;
16393
+ }
16394
+ }
16395
+
16359
16396
  CssAnimationSpec parseAnimationShorthand(const std::string &value)
16360
16397
  {
16361
16398
  CssAnimationSpec spec;
@@ -17062,20 +17099,32 @@ void applyPrimedAnimationValue(const gea::css::Animation &animation, double valu
17062
17099
 
17063
17100
  void primeCssAnimationsForNode(int node, const ActiveRulePlan *activePlan)
17064
17101
  {
17065
- if (activePlan) {
17066
- if (!activePlan->has(kActiveAnimation)) return;
17067
- } else {
17068
- rebuildRuleIndexIfNeeded();
17069
- if (g_ruleIndex.animationRules.empty()) return;
17070
- }
17071
17102
  const CssAnimationSpec spec = activePlan ? animationSpecForNodeFromActivePlan(*activePlan) : animationSpecForNode(node);
17103
+ if (!spec.valid || isDisplayNone(treeState().nodes[node].computedStyle())) {
17104
+ cancelNodeCssAnimation(node);
17105
+ return;
17106
+ }
17107
+ auto &animations = nodeCssAnimations();
17108
+ auto it = std::find_if(animations.begin(), animations.end(), [&](const NodeCssAnimation &entry) {
17109
+ return entry.node == node;
17110
+ });
17111
+ if (it != animations.end() && !sameAnimationSpec(it->spec, spec)) {
17112
+ cancelNodeCssAnimation(node);
17113
+ it = animations.end();
17114
+ }
17115
+ if (it == animations.end()) {
17116
+ animations.push_back({node, spec});
17117
+ it = animations.end() - 1;
17118
+ }
17119
+ const double elapsed = it->started
17120
+ ? static_cast<double>(static_cast<std::int32_t>(g_cssAnimationNowMs - it->startMs)) : 0.0;
17072
17121
  CssAnimationTrackList tracks;
17073
17122
  buildAnimationTracksForNode(node, spec, tracks);
17074
17123
  for (std::size_t i = 0, n = tracks.size(); i < n; ++i) {
17075
17124
  const CssAnimationTrack &track = tracks.at(i);
17076
17125
  if (isRotationAxisTrack(track.property)) continue;
17077
17126
  const gea::css::Animation animation = animationFromTrack(node, spec, track, tracks);
17078
- const gea::css::Progress progress = gea::css::computeProgress(animation, 0.0);
17127
+ const gea::css::Progress progress = gea::css::computeProgress(animation, elapsed);
17079
17128
  if (!progress.active) continue;
17080
17129
  if (!animation.rotationAxes.empty())
17081
17130
  gea::css::applyRotationSample(animation, progress.p, [&](Property property, int value) {
@@ -17085,15 +17134,17 @@ void primeCssAnimationsForNode(int node, const ActiveRulePlan *activePlan)
17085
17134
  }
17086
17135
  }
17087
17136
 
17088
- void startAnimationForNode(int nodeId, const CssAnimationSpec &spec, std::uint32_t nowMs)
17137
+ void startAnimationForNode(NodeCssAnimation &entry, std::uint32_t nowMs)
17089
17138
  {
17090
17139
  CssAnimationTrackList tracks;
17091
- buildAnimationTracksForNode(nodeId, spec, tracks);
17140
+ buildAnimationTracksForNode(entry.node, entry.spec, tracks);
17141
+ entry.startMs = nowMs;
17142
+ entry.started = true;
17092
17143
  for (std::size_t i = 0, n = tracks.size(); i < n; ++i) {
17093
17144
  const CssAnimationTrack &track = tracks.at(i);
17094
17145
  if (isRotationAxisTrack(track.property)) continue;
17095
- gea::css::Animation animation = animationFromTrack(nodeId, spec, track, tracks);
17096
- gea::css::AnimationEngine::instance().start(std::move(animation), nowMs);
17146
+ gea::css::Animation animation = animationFromTrack(entry.node, entry.spec, track, tracks);
17147
+ entry.handles.push_back(gea::css::AnimationEngine::instance().start(std::move(animation), nowMs));
17097
17148
  }
17098
17149
  }
17099
17150
 
@@ -17346,11 +17397,23 @@ void Style::cssScale(double value) const
17346
17397
  set(Property::ScaleX, scale); set(Property::ScaleY, scale); set(Property::ScaleZ, 1000);
17347
17398
  }
17348
17399
 
17400
+ void forgetNodeCssAnimations(int node)
17401
+ {
17402
+ #if GEA_CSS_ANIMATIONS
17403
+ cancelNodeCssAnimation(node);
17404
+ gea::css::AnimationEngine::instance().cancelNode(node);
17405
+ #else
17406
+ (void)node;
17407
+ #endif
17408
+ }
17409
+
17349
17410
  void StyleSheet::clear()
17350
17411
  {
17351
17412
  rules().clear();
17352
17413
  #if GEA_CSS_ANIMATIONS
17353
17414
  keyframeRules().clear();
17415
+ nodeCssAnimations().clear();
17416
+ g_cssAnimationNowMs = 0;
17354
17417
  #endif
17355
17418
  g_ruleRegistrationBatchDepth = 0;
17356
17419
  g_ruleRegistrationRulesChanged = false;
@@ -18024,13 +18087,9 @@ void StyleSheet::recomputeSubtree(int nodeId) const
18024
18087
  void StyleSheet::startCssAnimations(std::uint32_t nowMs) const
18025
18088
  {
18026
18089
  #if GEA_CSS_ANIMATIONS
18027
- rebuildRuleIndexIfNeeded();
18028
- if (g_ruleIndex.animationRules.empty()) return;
18029
- auto &state = treeState();
18030
- for (int node = 0; node < state.nodeCount; ++node) {
18031
- if (isDisplayNone(state.nodes[node].computedStyle())) continue;
18032
- const CssAnimationSpec spec = animationSpecForNode(node);
18033
- startAnimationForNode(node, spec, nowMs);
18090
+ g_cssAnimationNowMs = nowMs;
18091
+ for (auto &entry : nodeCssAnimations()) {
18092
+ if (!entry.started) startAnimationForNode(entry, nowMs);
18034
18093
  }
18035
18094
  #else
18036
18095
  (void)nowMs;
package/ui/style.h CHANGED
@@ -862,4 +862,7 @@ void applyAnimatedStyleValue(int nodeId, Property property, int value);
862
862
  void setSafeAreaInsetBottom(int inset);
863
863
  int safeAreaInsetBottom();
864
864
 
865
+ // Drop animation timelines before a node slot can be reused.
866
+ void forgetNodeCssAnimations(int node);
867
+
865
868
  } // namespace gea::embedded::ui
@@ -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
package/ui/tree_nodes.cpp CHANGED
@@ -98,6 +98,7 @@ bool canUseDisplayFramebuffer(TreeState &state, int id, int width, int height)
98
98
  void resetNodeSlot(TreeState &state, int id)
99
99
  {
100
100
  if (id < 0 || id >= kMaxNodes) return;
101
+ forgetNodeCssAnimations(id);
101
102
  // The node's text buffer dies with the slot; retained display commands hold
102
103
  // a raw pointer into it (see DisplayList::scrubNodeText) — neutralize them
103
104
  // before NodeLifecycle::init frees the string, or a stale-list replay in the
@@ -152,6 +153,7 @@ void Tree::clear()
152
153
  state.refreshSerial++;
153
154
  if (state.refreshSerial == 0) state.refreshSerial = 1;
154
155
  for (int i = 0; i < state.nodeCount; i++) {
156
+ forgetNodeCssAnimations(i);
155
157
  releaseRareData(i); // frees the rare-data block: attributes, listeners, custom props, styles, virtual-list
156
158
  state.classLists[i].clear();
157
159
  }
@@ -2,6 +2,7 @@
2
2
  #include "absolute_leaf_refresh.h"
3
3
  #include "dirty_regions.h"
4
4
  #include "display.h"
5
+ #include "display_underlay.h"
5
6
  #include "document.h"
6
7
  #include "internal.h"
7
8
  #include "layout_snapshot.h"
@@ -140,6 +141,119 @@ namespace gea::embedded::ui
140
141
  }
141
142
  #endif
142
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
+
143
257
  #if GEA_CSS_SCROLLING
144
258
  struct PreservedScrollOffset
145
259
  {
@@ -1571,10 +1685,46 @@ namespace gea::embedded::ui
1571
1685
  // The caller must hold AppState::lock() so the frame task isn't using the shared canvas
1572
1686
  // or mutating the list. Returns false for non-retained (canvas/present) apps, whose
1573
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
+
1574
1697
  bool renderRetainedSnapshotRgb565(std::uint16_t *dst, int width, int height)
1575
1698
  {
1576
1699
  if (!dst || width <= 0 || height <= 0)
1577
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
1578
1728
  if (DisplayList::instance().commandCount() < 2)
1579
1729
  return false; // canvas/present app: nothing retained to replay
1580
1730
  auto *canvas = gea::platform::display::Display::canvas();
@@ -1675,9 +1825,25 @@ namespace gea::embedded::ui
1675
1825
  DisplayList::instance().clear();
1676
1826
  DisplayList::instance().recordNode(root, 255);
1677
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
+ {
1840
+ gea::framework::display::Underlay::paint(0, 0, width - 1, height - 1);
1678
1841
  DisplayList::instance().replay();
1679
1842
  state.displayListDirty = false;
1680
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
1681
1847
 
1682
1848
  // Don't present the very first mount while the initial style batch is still
1683
1849
  // open: per-node class styles haven't been applied yet, so this frame is
@@ -1686,6 +1852,7 @@ namespace gea::embedded::ui
1686
1852
  // avoiding a flash of unstyled content (text + images, no CSS) at boot.
1687
1853
  if (!styleMountBatchActive())
1688
1854
  gea::platform::display::Display::flush();
1855
+ }
1689
1856
  state.canvases.forEach([](CanvasSurfaceState &surface)
1690
1857
  {
1691
1858
  if (auto *canvas = surface.canvas()) canvas->resetDirty(); });
@@ -1874,6 +2041,24 @@ namespace gea::embedded::ui
1874
2041
  GEA_REFRESH_PERF(perf.treeRefreshCalls++);
1875
2042
  DisplayList::instance().clearRetainedBackgroundRecolors();
1876
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
1877
2062
  const bool textClipDependencies = DisplayList::instance().hasTextClippedBackgrounds();
1878
2063
  if (textClipDependencies) {
1879
2064
  bool changed = state.displayListDirty;
@@ -1888,7 +2073,7 @@ namespace gea::embedded::ui
1888
2073
  state.nodes[root].render.dirty = true;
1889
2074
  }
1890
2075
  }
1891
- if (!textClipDependencies && state.pendingScrollIntoViewNode < 0 && RootScrollOnlyRefresh::refresh(root, width, height))
2076
+ if (framebufferReadable && !textClipDependencies && state.pendingScrollIntoViewNode < 0 && RootScrollOnlyRefresh::refresh(root, width, height))
1892
2077
  return;
1893
2078
 
1894
2079
  // This frame is NOT a pure scroll, so the software scroll register's
@@ -2366,7 +2551,7 @@ namespace gea::embedded::ui
2366
2551
  // Horizontal-pan fast path: when a camera/world wrapper translated the viewport
2367
2552
  // this frame (and nothing structural changed), memcpy-shift the viewport instead
2368
2553
  // of re-replaying the whole panned scene. Handles the frame fully when it engages.
2369
- if (tryHorizontalPanRefresh(root, width, height, framebuffer_was_dirty,
2554
+ if (framebufferReadable && tryHorizontalPanRefresh(root, width, height, framebuffer_was_dirty,
2370
2555
  display_list_was_dirty, display_list_was_structural,
2371
2556
  displayListFullRecord))
2372
2557
  {
@@ -2455,7 +2640,8 @@ namespace gea::embedded::ui
2455
2640
  continue;
2456
2641
  }
2457
2642
 
2458
- if (!canvas_dirty &&
2643
+ if (framebufferReadable &&
2644
+ !canvas_dirty &&
2459
2645
  direct_replay &&
2460
2646
  n->render.bg_recolor_pending &&
2461
2647
  n->first_child < 0 &&
@@ -2843,6 +3029,38 @@ namespace gea::embedded::ui
2843
3029
  (int)simpleUnifiedReplay, (int)interleavedUnifiedFlush, (int)hasFlushOnlyRecolorRegions,
2844
3030
  (int)GEA_EMBEDDED_DISPLAY_FUSE_REPLAY_FLUSH);
2845
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
2846
3064
  #endif
2847
3065
  if (simpleUnifiedReplay)
2848
3066
  {
@@ -3058,6 +3276,7 @@ namespace gea::embedded::ui
3058
3276
  gea::platform::display::Display::resetClip();
3059
3277
  gea::platform::display::Display::setAlpha(255);
3060
3278
  gea::platform::display::Display::pushClip(r->x0, r->y0, r->x1 - r->x0 + 1, r->y1 - r->y0 + 1);
3279
+ gea::framework::display::Underlay::paint(r->x0, r->y0, r->x1, r->y1);
3061
3280
  DisplayList::instance().replay();
3062
3281
  gea::platform::display::Display::popClip();
3063
3282
  }
@@ -3083,18 +3302,21 @@ namespace gea::embedded::ui
3083
3302
  display_list_was_structural ? 1 : 0, rect_count, flush_rect_count);
3084
3303
  }
3085
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).
3086
3308
  DisplayList::instance().maybeBakeStaticBackdrop(
3087
3309
  width,
3088
3310
  height,
3089
3311
  !display_list_was_structural && staticBackdropStable,
3090
- direct_replay != 0 && !simpleDirtyReplayAvailable && staticBackdropStable,
3312
+ !banded && direct_replay != 0 && !simpleDirtyReplayAvailable && staticBackdropStable,
3091
3313
  staticBackdropEligible);
3092
3314
 
3093
3315
  const std::int64_t flushRectsStartUs = refreshPerfNowUs();
3094
3316
  #if defined(ESP_PLATFORM) && CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS
3095
3317
  const auto diagnosticReplayEnd = esp_timer_get_time();
3096
3318
  #endif
3097
- if (!simpleUnifiedReplay && !interleavedUnifiedFlush)
3319
+ if (!banded && !simpleUnifiedReplay && !interleavedUnifiedFlush)
3098
3320
  {
3099
3321
  for (int i = 0; i < flush_rect_count; i++)
3100
3322
  {