@geastack/engine 0.1.21 → 0.1.23

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.
@@ -5,6 +5,7 @@
5
5
  #include "canvas_element.h"
6
6
  #include "display.h"
7
7
  #include "display_underlay.h"
8
+ #include <image.h>
8
9
  #include "document.h"
9
10
  #include "internal.h"
10
11
  #include "layout_snapshot.h"
@@ -43,6 +44,42 @@
43
44
  #define GEA_EMBEDDED_DISPLAY_FUSE_INTERLEAVED_REPLAY_FLUSH 0
44
45
  #endif
45
46
 
47
+ // Called just before direct replay repaints `rects` completely. A display that
48
+ // keeps several scanout buffers can bring its back buffer up to date everywhere
49
+ // else and skip those rects: on the CrowPanel 7 a scrolling page otherwise
50
+ // copied the whole viewport between buffers (~1.4 MB of PSRAM traffic a frame)
51
+ // only to redraw it, and that traffic starved the panel's scanout.
52
+ extern "C" __attribute__((weak)) void gea_display_prepare_repaint(const gea::platform::display::DisplayFlushRect *, int) {}
53
+ extern "C" int gea_bulk_replay_stage_rows_for_width(int width);
54
+ extern "C" bool gea_replay_stage_begin(int x0, int y0, int x1, int y1);
55
+ extern "C" void gea_replay_stage_end();
56
+ extern "C" bool gea_replay_stage_active();
57
+ extern "C" void gea_replay_stage_skip_seed(bool skip);
58
+ // Overlaps each strip's copy-back with the next strip's replay (rgb_panel).
59
+ extern "C" void gea_replay_stage_pipeline(bool on);
60
+ // True when every flush presents a whole frame (an RGB panel swapping scanout
61
+ // buffers): interleaving replay with one flush per dirty rect then costs one
62
+ // buffer swap -- and one panel refresh of waiting -- per rect instead of per frame.
63
+ extern "C" __attribute__((weak)) bool gea_display_flush_presents_frame() { return false; }
64
+ // The draw canvas for reading state only (dirty box, scroll region) -- never
65
+ // for pixels. A double-buffered panel readies its back buffer the first time
66
+ // Display::canvas() is asked for, patching every stale pixel; asked this early
67
+ // in the frame, that is before the replay can say which rects it repaints
68
+ // whole, so the patch copies them too. Null: the target has no such split.
69
+ extern "C" __attribute__((weak)) gea::framework::graphics::Canvas *gea_display_state_canvas() { return nullptr; }
70
+ namespace
71
+ {
72
+ }
73
+ namespace
74
+ {
75
+ gea::framework::graphics::Canvas *displayStateCanvas()
76
+ {
77
+ if (auto *canvas = gea_display_state_canvas())
78
+ return canvas;
79
+ return gea::platform::display::Display::canvas();
80
+ }
81
+ }
82
+
46
83
  #ifndef GEA_EMBEDDED_DISPLAY_FUSE_REPLAY_CLEAR_RGB565
47
84
  #define GEA_EMBEDDED_DISPLAY_FUSE_REPLAY_CLEAR_RGB565 -1
48
85
  #endif
@@ -81,6 +118,11 @@
81
118
  #define GEA_EMBEDDED_SUBTREE_REVEAL_CHECK 1
82
119
  #endif
83
120
 
121
+ // A display whose every framebuffer writer goes through the canvas's ring
122
+ // mapping (the ESP32-S3 RGB panel) keeps the scroll region across non-scroll
123
+ // frames; resetting it would re-lay the buffer and repaint the whole region.
124
+ extern "C" __attribute__((weak)) bool gea_display_scroll_region_persists() { return false; }
125
+
84
126
  namespace gea::embedded::ui
85
127
  {
86
128
  namespace
@@ -2051,6 +2093,54 @@ namespace gea::embedded::ui
2051
2093
  }
2052
2094
  return -1;
2053
2095
  }
2096
+
2097
+ bool scopeIsAncestorOrSelf(TreeState &state, int node, int ancestor)
2098
+ {
2099
+ int steps = 0;
2100
+ for (int c = node; c >= 0 && c < state.nodeCount; c = state.nodes[c].parent)
2101
+ {
2102
+ if (c == ancestor)
2103
+ return true;
2104
+ if (!walkParents(state, node, steps))
2105
+ return false;
2106
+ }
2107
+ return false;
2108
+ }
2109
+
2110
+ // One stable scope per geometry-dirty node instead of one around all of
2111
+ // them: a legend ticking in each of three cards otherwise re-lays the
2112
+ // whole card grid (their common ancestor), when each legend row keeps its
2113
+ // size and re-lays alone. Scopes nested in another are dropped -- the outer
2114
+ // pass lays them too. Returns the scope count, or -1 when some dirty node
2115
+ // has no stable ancestor (or there are too many to track): full layout.
2116
+ int stableRelayoutScopes(TreeState &state, int root, int *scopes, int capacity)
2117
+ {
2118
+ int count = 0;
2119
+ for (int i = 0; i < state.nodeCount; i++)
2120
+ {
2121
+ const Node &n = state.nodes[i];
2122
+ if (!n.render.dirty || !n.render.layout_dirty)
2123
+ continue;
2124
+ // A dirty node's own box may change: its scope is a strict ancestor.
2125
+ const int scope = stableScopeAt(state, n.parent, root);
2126
+ if (scope < 0)
2127
+ return -1;
2128
+ bool covered = false;
2129
+ for (int k = 0; k < count && !covered; k++)
2130
+ covered = scopeIsAncestorOrSelf(state, scope, scopes[k]);
2131
+ if (covered)
2132
+ continue;
2133
+ int kept = 0;
2134
+ for (int k = 0; k < count; k++)
2135
+ if (!scopeIsAncestorOrSelf(state, scopes[k], scope))
2136
+ scopes[kept++] = scopes[k];
2137
+ count = kept;
2138
+ if (count >= capacity)
2139
+ return -1;
2140
+ scopes[count++] = scope;
2141
+ }
2142
+ return count;
2143
+ }
2054
2144
  // A transformed parent re-records its whole subtree (its descendants'
2055
2145
  // corners all move). When no descendant paints anything -- the empty slot
2056
2146
  // of `{done ? <img/> : null}` inside a pulsing dot -- there is nothing to
@@ -2071,6 +2161,13 @@ namespace gea::embedded::ui
2071
2161
  }
2072
2162
  } // namespace
2073
2163
 
2164
+ namespace {
2165
+ bool gSoftwareRasterSuppressed = false;
2166
+ bool gSoftwareRasterStale = false; // frames went unrasterized since the last repaint
2167
+ }
2168
+
2169
+ void Tree::setSoftwareRasterSuppressed(bool suppressed) { gSoftwareRasterSuppressed = suppressed; }
2170
+
2074
2171
  void Tree::refresh(int root, int width, int height)
2075
2172
  {
2076
2173
  #if defined(ESP_PLATFORM) && CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS
@@ -2079,6 +2176,9 @@ namespace gea::embedded::ui
2079
2176
  auto &state = treeState();
2080
2177
  if (root < 0 || root >= state.nodeCount)
2081
2178
  return;
2179
+ #if GEA_UI_IMAGE_NODES
2180
+ gea::framework::graphics::ImageStore::instance().releaseIdleDecodes();
2181
+ #endif
2082
2182
  #if GEA_UI_SVG
2083
2183
  svg::validateScenes();
2084
2184
  #endif
@@ -2087,7 +2187,10 @@ namespace gea::embedded::ui
2087
2187
  #endif
2088
2188
  const bool viewportChanged = gLayoutViewportRoot != root ||
2089
2189
  gLayoutViewportWidth != width || gLayoutViewportHeight != height;
2090
- if (viewportChanged) {
2190
+ const bool rasterResumed = gSoftwareRasterStale && !gSoftwareRasterSuppressed;
2191
+ if (rasterResumed)
2192
+ gSoftwareRasterStale = false;
2193
+ if (viewportChanged || rasterResumed) {
2091
2194
  state.displayListDirty = true;
2092
2195
  state.displayListRebuildStructural = true;
2093
2196
  state.nodes[root].render.dirty = true;
@@ -2134,9 +2237,7 @@ namespace gea::embedded::ui
2134
2237
  state.nodes[root].render.dirty = true;
2135
2238
  }
2136
2239
  }
2137
- if (framebufferReadable && !textClipDependencies && state.pendingScrollIntoViewNode < 0 && RootScrollOnlyRefresh::refresh(root, width, height))
2138
- return;
2139
-
2240
+ if (framebufferReadable && !textClipDependencies && state.pendingScrollIntoViewNode < 0 && RootScrollOnlyRefresh::refresh(root, width, height)) return;
2140
2241
  bool scrollFallbackRepaint = false;
2141
2242
  #if GEA_CSS_SCROLLING
2142
2243
  // A rejected scroll blit still moves every descendant's geometry during
@@ -2168,9 +2269,9 @@ namespace gea::embedded::ui
2168
2269
  // them in their unrotated placement.
2169
2270
  #if !defined(GEA_EMBEDDED_DIRECT_CANVAS_CONTEXT) || !GEA_EMBEDDED_DIRECT_CANVAS_CONTEXT
2170
2271
  if (!Document::directCanvasContextUsed()) {
2171
- if (auto *rotCanvas = gea::platform::display::Display::canvas()) {
2272
+ if (auto *rotCanvas = displayStateCanvas()) {
2172
2273
  const int regionH = rotCanvas->scrollRegionH();
2173
- if (regionH > 0) {
2274
+ if (regionH > 0 && !gea_display_scroll_region_persists()) {
2174
2275
  const int regionY = rotCanvas->scrollRegionY();
2175
2276
  gea::platform::display::Display::resetScrollRegion();
2176
2277
  rotCanvas->markDirty(0, regionY, width - 1, regionY + regionH - 1);
@@ -2186,7 +2287,7 @@ namespace gea::embedded::ui
2186
2287
  int framebufferDirtyX1 = -1;
2187
2288
  int framebufferDirtyY1 = -1;
2188
2289
  #if !defined(GEA_EMBEDDED_DIRECT_CANVAS_CONTEXT) || !GEA_EMBEDDED_DIRECT_CANVAS_CONTEXT
2189
- auto *displayCanvas = Document::directCanvasContextUsed() ? nullptr : gea::platform::display::Display::canvas();
2290
+ auto *displayCanvas = Document::directCanvasContextUsed() ? nullptr : displayStateCanvas();
2190
2291
  const bool framebuffer_was_dirty = displayCanvas &&
2191
2292
  displayCanvas->dirty(&framebufferDirtyX0,
2192
2293
  &framebufferDirtyY0,
@@ -2243,23 +2344,39 @@ namespace gea::embedded::ui
2243
2344
  {
2244
2345
  if (!viewportChanged && state.pendingScrollIntoViewNode < 0)
2245
2346
  {
2246
- int scope = scopedRelayoutRoot(state, root);
2247
- if (scope >= 0)
2248
- scope = stableScopeAt(state, scope, root);
2249
- if (scope < 0)
2347
+ constexpr int kMaxScopes = 16;
2348
+ int scopes[kMaxScopes];
2349
+ int scopeCount = stableRelayoutScopes(state, root, scopes, kMaxScopes);
2350
+ if (scopeCount < 0)
2351
+ {
2352
+ // No per-node scope set: one scope around every dirty node.
2353
+ int scope = scopedRelayoutRoot(state, root);
2354
+ if (scope >= 0)
2355
+ scope = stableScopeAt(state, scope, root);
2356
+ scopeCount = scope >= 0 ? 1 : 0;
2357
+ scopes[0] = scope;
2358
+ }
2359
+ if (scopeCount <= 0)
2250
2360
  GEA_REFRESH_PERF(perf.treeScopedRejectReason = 1);
2251
- for (int attempt = 0; scope >= 0 && attempt < 2; attempt++)
2361
+ scoped = scopeCount > 0;
2362
+ for (int k = 0; k < scopeCount && scoped; k++)
2252
2363
  {
2253
- scoped = LayoutEngine::instance().layoutNodeScoped(scope, root);
2254
- if (scoped)
2364
+ int scope = scopes[k];
2365
+ bool laid = false;
2366
+ for (int attempt = 0; scope >= 0 && attempt < 2; attempt++)
2255
2367
  {
2256
- GEA_REFRESH_PERF(perf.treeScopedLayouts++);
2257
- break;
2368
+ laid = LayoutEngine::instance().layoutNodeScoped(scope, root);
2369
+ if (laid)
2370
+ {
2371
+ GEA_REFRESH_PERF(perf.treeScopedLayouts++);
2372
+ break;
2373
+ }
2374
+ // Most rejects mean the scope autosized to the new content —
2375
+ // retry from the next stable ancestor up (each failed attempt's
2376
+ // partial layout is fully redone by the retry / full fallback).
2377
+ scope = stableScopeAt(state, state.nodes[scope].parent, root);
2258
2378
  }
2259
- // Most rejects mean the scope autosized to the new content —
2260
- // retry from the next stable ancestor up (each failed attempt's
2261
- // partial layout is fully redone by the retry / full fallback).
2262
- scope = stableScopeAt(state, state.nodes[scope].parent, root);
2379
+ scoped = laid;
2263
2380
  }
2264
2381
  }
2265
2382
  LayoutEngine::Pass layoutPass(!scoped);
@@ -2634,6 +2751,22 @@ namespace gea::embedded::ui
2634
2751
  if (reprojected)
2635
2752
  GEA_REFRESH_PERF(perf.treeReprojects++);
2636
2753
  GEA_REFRESH_PERF(perf.treeDisplayListUs += refreshPerfNowUs() - displayListStartUs);
2754
+ if (gSoftwareRasterSuppressed)
2755
+ {
2756
+ // The host shows native views, not the framebuffer: finish the frame's
2757
+ // bookkeeping (as the end of a rasterized refresh does) without painting.
2758
+ gSoftwareRasterStale = true;
2759
+ LayoutSnapshot::capture();
2760
+ state.canvases.forEach([](CanvasSurfaceState &surface)
2761
+ {
2762
+ if (auto *canvas = surface.canvas()) canvas->resetDirty(); });
2763
+ CanvasRenderingContext2D::clearRetainedCanvasDamage();
2764
+ #if !defined(GEA_EMBEDDED_DIRECT_CANVAS_CONTEXT) || !GEA_EMBEDDED_DIRECT_CANVAS_CONTEXT
2765
+ if (displayCanvas)
2766
+ displayCanvas->resetDirty();
2767
+ #endif
2768
+ return;
2769
+ }
2637
2770
 
2638
2771
  // Horizontal-pan fast path: when a camera/world wrapper translated the viewport
2639
2772
  // this frame (and nothing structural changed), memcpy-shift the viewport instead
@@ -2697,6 +2830,10 @@ namespace gea::embedded::ui
2697
2830
  int dr_x0 = width, dr_y0 = height, dr_x1 = -1, dr_y1 = -1;
2698
2831
 
2699
2832
  int canvas_x0 = 0, canvas_y0 = 0, canvas_x1 = -1, canvas_y1 = -1;
2833
+ #if GEA_UI_SVG
2834
+ int svgExtra[svg::kExtraDamage][4];
2835
+ #endif
2836
+ int svgExtraCount = 0; // further exact-damage boxes of an svg scene
2700
2837
  const auto *canvas_surface = n->type == NodeType::Canvas ? state.canvases.find(i) : nullptr;
2701
2838
  const auto *canvas = canvas_surface ? canvas_surface->canvas() : nullptr;
2702
2839
  const bool bitmap_canvas_dirty =
@@ -2759,7 +2896,8 @@ namespace gea::embedded::ui
2759
2896
  if (!canvas_dirty && svg::isRoot(*n))
2760
2897
  {
2761
2898
  int sx0, sy0, sx1, sy1;
2762
- const bool svgDamage = svg::damage(i, sx0, sy0, sx1, sy1); // always consume
2899
+ const bool svgDamage = svg::damage(i, sx0, sy0, sx1, sy1, svgExtra, &svgExtraCount); // always consume
2900
+ if (!svgDamage) svgExtraCount = 0;
2763
2901
  if (svgDamage && !n->render.layout_dirty && !n->render.transform_dirty &&
2764
2902
  n->layout.x == n->layout.previous_x && n->layout.y == n->layout.previous_y &&
2765
2903
  n->layout.width == n->layout.previous_width && n->layout.height == n->layout.previous_height &&
@@ -2772,6 +2910,8 @@ namespace gea::embedded::ui
2772
2910
  canvas_x1 = sx1;
2773
2911
  canvas_y1 = sy1;
2774
2912
  }
2913
+ else
2914
+ svgExtraCount = 0;
2775
2915
  }
2776
2916
  #endif
2777
2917
  if (canvas_dirty && !exactCanvasPixelDamage)
@@ -2956,6 +3096,16 @@ namespace gea::embedded::ui
2956
3096
  dr_y0 = n->layout.y + canvas_y0;
2957
3097
  dr_x1 = n->layout.x + canvas_x1;
2958
3098
  dr_y1 = n->layout.y + canvas_y1;
3099
+ #if GEA_UI_SVG
3100
+ for (int k = 0; k < svgExtraCount; ++k)
3101
+ {
3102
+ const DirtyRegions::Rect extraRect{n->layout.x + svgExtra[k][0], n->layout.y + svgExtra[k][1],
3103
+ n->layout.x + svgExtra[k][2], n->layout.y + svgExtra[k][3], i};
3104
+ addDirtyRegion(rects, &rect_count, extraRect, width, height);
3105
+ if (!unifiedRectPath)
3106
+ addDirtyRegion(flush_rects, &flush_rect_count, extraRect, width, height);
3107
+ }
3108
+ #endif
2959
3109
  }
2960
3110
  else if (reprojected && n->render.transform_dirty && n->first_child >= 0 &&
2961
3111
  DisplayList::instance().reprojectDirtyRect(&dr_x0, &dr_y0, &dr_x1, &dr_y1))
@@ -3189,6 +3339,36 @@ namespace gea::embedded::ui
3189
3339
  }
3190
3340
  #endif
3191
3341
  const bool hasFlushOnlyRecolorRegions = preserveFlushOnlyRecolorRegions && flush_rect_count > 0;
3342
+ // Direct replay draws node command ranges, and a scroll container's
3343
+ // scrollbar thumb lies outside them. The direct-replay entry points paint
3344
+ // the thumbs after the nodes, which is right while no later command covers
3345
+ // a thumb; otherwise repaint a thumb's pixels only through the full-list
3346
+ // path. Scrolling moves the thumb every frame, so this keeps scroll frames
3347
+ // on direct replay and the fused flush.
3348
+ if (direct_replay && !DisplayList::instance().scrollbarThumbsPaintLast())
3349
+ {
3350
+ for (int i = 0; i < rect_count && direct_replay; ++i)
3351
+ if (DisplayList::instance().scrollbarOverlapsRegion(rects[i].x0, rects[i].y0, rects[i].x1, rects[i].y1))
3352
+ direct_replay = 0;
3353
+ for (int i = 0; i < flush_rect_count && direct_replay; ++i)
3354
+ if (DisplayList::instance().scrollbarOverlapsRegion(flush_rects[i].x0, flush_rects[i].y0, flush_rects[i].x1, flush_rects[i].y1))
3355
+ direct_replay = 0;
3356
+ }
3357
+ // From here to the flush the tree and display list hold still, so the
3358
+ // simple-replay verdict's region-independent walk runs once, not once per
3359
+ // region the replay below asks about.
3360
+ struct SimpleReplayScope
3361
+ {
3362
+ bool open = true;
3363
+ SimpleReplayScope() { DisplayList::instance().beginSimpleReplayScope(); }
3364
+ void close()
3365
+ {
3366
+ if (open)
3367
+ DisplayList::instance().endSimpleReplayScope();
3368
+ open = false;
3369
+ }
3370
+ ~SimpleReplayScope() { close(); }
3371
+ } simpleReplayScope;
3192
3372
  DisplayReplayRegion simpleTransferRegions[DirtyRegions::kMaxRects];
3193
3373
  for (int i = 0; i < flush_rect_count; ++i)
3194
3374
  {
@@ -3414,9 +3594,32 @@ namespace gea::embedded::ui
3414
3594
  }
3415
3595
  GEA_REFRESH_PERF(perf.treeFlushRectsUs += refreshPerfNowUs() - flushStartUs);
3416
3596
  #else
3597
+ // A panel whose flush presents a whole frame takes one flush after the
3598
+ // last rect: a flush per rect would be a buffer swap -- and a panel
3599
+ // refresh of waiting -- per rect.
3600
+ const bool flushOncePerFrame = gea_display_flush_presents_frame();
3601
+ // One flush presents the frame, so the back buffer is readied once:
3602
+ // hand it every rect this frame repaints, or it copies the stale
3603
+ // pixels under rects 2..n from the front only for them to be painted
3604
+ // over (on a busy screen that copy was the whole repaint area again).
3605
+ gea::platform::display::DisplayFlushRect repaints[DirtyRegions::kMaxRects];
3606
+ int repaintCount = 0;
3607
+ if (flushOncePerFrame && rect_count > 0)
3608
+ {
3609
+ for (int i = 0; i < rect_count && repaintCount < DirtyRegions::kMaxRects; i++)
3610
+ {
3611
+ const DirtyRegions::Rect *r = &rects[i];
3612
+ if (r->x0 <= r->x1 && r->y0 <= r->y1)
3613
+ repaints[repaintCount++] = gea::platform::display::DisplayFlushRect{r->x0, r->y0, r->x1, r->y1};
3614
+ }
3615
+ gea_display_prepare_repaint(repaints, repaintCount);
3616
+ }
3417
3617
  for (int i = 0; i < rect_count; i++)
3418
3618
  {
3419
3619
  DirtyRegions::Rect *r = &rects[i];
3620
+ const gea::platform::display::DisplayFlushRect repaint{r->x0, r->y0, r->x1, r->y1};
3621
+ if (!flushOncePerFrame)
3622
+ gea_display_prepare_repaint(&repaint, 1);
3420
3623
  gea::platform::display::Display::resetClip();
3421
3624
  gea::platform::display::Display::setAlpha(255);
3422
3625
  gea::platform::display::Display::pushClip(r->x0, r->y0, r->x1 - r->x0 + 1, r->y1 - r->y0 + 1);
@@ -3425,10 +3628,24 @@ namespace gea::embedded::ui
3425
3628
  DisplayList::instance().replayDirectDirtyRegions(&region, 1);
3426
3629
  GEA_REFRESH_PERF(perf.treeReplayUs += refreshPerfNowUs() - replayStartUs);
3427
3630
  gea::platform::display::Display::popClip();
3631
+ if (flushOncePerFrame) continue;
3428
3632
  const std::int64_t flushStartUs = refreshPerfNowUs();
3429
3633
  gea::platform::display::Display::flush();
3430
3634
  GEA_REFRESH_PERF(perf.treeFlushRectsUs += refreshPerfNowUs() - flushStartUs);
3431
3635
  }
3636
+ if (flushOncePerFrame)
3637
+ {
3638
+ const std::int64_t flushStartUs = refreshPerfNowUs();
3639
+ // Publish the rects themselves, not the canvas's one dirty box: the
3640
+ // panel copies what it publishes into the other buffer before the
3641
+ // next frame draws there, and the box spans everything between
3642
+ // separate rects (two meters a screen apart).
3643
+ if (repaintCount > 0)
3644
+ gea::platform::display::Display::flushRects(repaints, repaintCount);
3645
+ else
3646
+ gea::platform::display::Display::flush();
3647
+ GEA_REFRESH_PERF(perf.treeFlushRectsUs += refreshPerfNowUs() - flushStartUs);
3648
+ }
3432
3649
  #endif
3433
3650
  }
3434
3651
  else
@@ -3440,26 +3657,74 @@ namespace gea::embedded::ui
3440
3657
  gea::platform::display::Display::resetClip();
3441
3658
  gea::platform::display::Display::setAlpha(255);
3442
3659
  DisplayReplayRegion regions[DirtyRegions::kMaxRects];
3660
+ gea::platform::display::DisplayFlushRect repaints[DirtyRegions::kMaxRects];
3443
3661
  for (int i = 0; i < rect_count; i++)
3444
3662
  {
3445
3663
  DirtyRegions::Rect *r = &rects[i];
3446
3664
  regions[i] = DisplayReplayRegion{r->x0, r->y0, r->x1, r->y1, r->origin};
3665
+ repaints[i] = gea::platform::display::DisplayFlushRect{r->x0, r->y0, r->x1, r->y1};
3447
3666
  }
3667
+ // The direct replay repaints every region completely.
3668
+ gea_display_prepare_repaint(repaints, rect_count);
3448
3669
  DisplayList::instance().replayDirectDirtyRegions(regions, rect_count);
3449
3670
  }
3450
3671
  else
3451
3672
  {
3452
3673
  // Conservative paint path for full display-list replay.
3674
+ // Raster each rect in SRAM strips where the display stages, so the
3675
+ // back-buffer writes cannot starve a PSRAM scanout refill.
3676
+ // An opaque underlay (a gea3d frame) paints every pixel of the rects
3677
+ // it covers before the tree replays over it: those are repainted
3678
+ // whole, so the display need not first restore their old pixels
3679
+ // (on a double-buffered panel, a full-screen copy every frame).
3680
+ {
3681
+ gea::platform::display::DisplayFlushRect covered[DirtyRegions::kMaxRects];
3682
+ int coveredCount = 0;
3683
+ for (int i = 0; i < rect_count; i++)
3684
+ if (gea::framework::display::Underlay::covers(rects[i].x0, rects[i].y0, rects[i].x1, rects[i].y1))
3685
+ covered[coveredCount++] = gea::platform::display::DisplayFlushRect{rects[i].x0, rects[i].y0, rects[i].x1, rects[i].y1};
3686
+ if (coveredCount > 0) gea_display_prepare_repaint(covered, coveredCount);
3687
+ }
3688
+ gea_replay_stage_pipeline(true);
3453
3689
  for (int i = 0; i < rect_count; i++)
3454
3690
  {
3455
3691
  DirtyRegions::Rect *r = &rects[i];
3692
+ const int stageRows = gea_bulk_replay_stage_rows_for_width(r->x1 - r->x0 + 1);
3693
+ const int band = stageRows > 0 && !gea_replay_stage_active() ? stageRows : r->y1 - r->y0 + 1;
3694
+ // One occlusion-cull scan for the whole rect, reused by every strip.
3456
3695
  gea::platform::display::Display::resetClip();
3457
- gea::platform::display::Display::setAlpha(255);
3458
3696
  gea::platform::display::Display::pushClip(r->x0, r->y0, r->x1 - r->x0 + 1, r->y1 - r->y0 + 1);
3459
- gea::framework::display::Underlay::paint(r->x0, r->y0, r->x1, r->y1);
3460
- DisplayList::instance().replay();
3697
+ DisplayList::instance().setReplayCullStart(DisplayList::instance().replayCullStart());
3698
+ // An opaque underlay paints every pixel of the strips it covers
3699
+ // first, so their seed from the back buffer would be overwritten.
3700
+ gea_replay_stage_skip_seed(DisplayList::instance().replayCullCovered() ||
3701
+ gea::framework::display::Underlay::covers(r->x0, r->y0, r->x1, r->y1));
3461
3702
  gea::platform::display::Display::popClip();
3703
+ #ifndef GEA_EMBEDDED_STAGE_GRID_STRIPS
3704
+ #define GEA_EMBEDDED_STAGE_GRID_STRIPS 0
3705
+ #endif
3706
+ // With GEA_EMBEDDED_STAGE_GRID_STRIPS (an app opt-in) staged
3707
+ // strips sit on a fixed grid of the staging height, so a strip's
3708
+ // rows map to one band of an underlay that keeps per-band lists
3709
+ // (gea3d); strips that start wherever the dirty box does straddle
3710
+ // two bands and rescan the whole primitive list.
3711
+ const bool gridStrips = GEA_EMBEDDED_STAGE_GRID_STRIPS && band == stageRows && stageRows > 0;
3712
+ for (int sy0 = r->y0, sy1 = 0; sy0 <= r->y1; sy0 = sy1 + 1)
3713
+ {
3714
+ sy1 = std::min(r->y1, gridStrips ? (sy0 / band + 1) * band - 1 : sy0 + band - 1);
3715
+ gea::platform::display::Display::resetClip();
3716
+ gea::platform::display::Display::setAlpha(255);
3717
+ const bool staged = stageRows > 0 && band == stageRows && gea_replay_stage_begin(r->x0, sy0, r->x1, sy1);
3718
+ gea::platform::display::Display::pushClip(r->x0, sy0, r->x1 - r->x0 + 1, sy1 - sy0 + 1);
3719
+ gea::framework::display::Underlay::paint(r->x0, sy0, r->x1, sy1);
3720
+ DisplayList::instance().replay();
3721
+ gea::platform::display::Display::popClip();
3722
+ if (staged) gea_replay_stage_end();
3723
+ }
3724
+ DisplayList::instance().setReplayCullStart(-1);
3725
+ gea_replay_stage_skip_seed(false);
3462
3726
  }
3727
+ gea_replay_stage_pipeline(false);
3463
3728
  }
3464
3729
  GEA_REFRESH_PERF(perf.treeReplayUs += refreshPerfNowUs() - replayStartUs);
3465
3730
  }
@@ -3496,6 +3761,7 @@ namespace gea::embedded::ui
3496
3761
  #if defined(ESP_PLATFORM) && CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS
3497
3762
  const auto diagnosticReplayEnd = esp_timer_get_time();
3498
3763
  #endif
3764
+ simpleReplayScope.close();
3499
3765
  if (!banded && !simpleUnifiedReplay && !interleavedUnifiedFlush)
3500
3766
  {
3501
3767
  for (int i = 0; i < flush_rect_count; i++)
package/ui/tree_state.h CHANGED
@@ -308,6 +308,9 @@ struct TreeState {
308
308
  uint64_t scrollDirtyNodes[kScrollDirtyWordCount]{};
309
309
  bool scrollDirtyAny = false;
310
310
  int pendingScrollIntoViewNode = -1;
311
+ // The pending scroll keeps the scroller's padding clear of the target
312
+ // (LVGL's scroll-to-view rule; the on-screen keyboard asks for it).
313
+ bool pendingScrollIntoViewKeepsPadding = false;
311
314
  #else
312
315
  static constexpr bool scrollDirtyAny = false;
313
316
  static constexpr int pendingScrollIntoViewNode = -1;
@@ -376,6 +379,12 @@ struct TreeState {
376
379
  int activeInputId = -1;
377
380
  int caretLastFlipMs = 0;
378
381
  bool caretVisible = true;
382
+ // Caret byte index in the active input's value; -1 = at the end.
383
+ int caretPos = -1;
384
+ // A password input shows the characters typed in [pwdRevealFrom,
385
+ // pwdRevealTo) until pwdRevealUntilMs, then bullets (lv_textarea's
386
+ // LV_TEXTAREA_DEF_PWD_SHOW_TIME).
387
+ int pwdRevealFrom = 0, pwdRevealTo = 0, pwdRevealUntilMs = 0;
379
388
  #else
380
389
  static constexpr int activeInputId = -1;
381
390
  static constexpr int caretLastFlipMs = 0;
package/ui/tree_style.cpp CHANGED
@@ -1330,8 +1330,16 @@ void setStyleValue(Tree &tree, int node, Property prop, int value, bool recordIn
1330
1330
  // reflows or reorders → full rebuild.
1331
1331
  const bool absLeafSize = (prop == Property::Width || prop == Property::Height) &&
1332
1332
  style.position == 1 && n->first_child < 0 && n->type != NodeType::Text;
1333
+ // An absolute box WITH children resizing (a progress fill cropping its
1334
+ // artwork) is just as out of flow: re-record the list, but as a content
1335
+ // rebuild that repaints the dirty nodes' old and new boxes instead of the
1336
+ // whole viewport.
1337
+ const bool absBoxSize = (prop == Property::Width || prop == Property::Height) &&
1338
+ style.position == 1 && n->first_child >= 0;
1333
1339
  if (absLeafSize)
1334
1340
  tree.markNodeDisplayCommandsDirty(node);
1341
+ else if (absBoxSize)
1342
+ tree.markDisplayListContentDirty();
1335
1343
  else
1336
1344
  tree.markDisplayListDirty();
1337
1345
  }
package/ui/view.cpp CHANGED
@@ -2640,9 +2640,12 @@ void ViewRenderer::recordScrollbar(const Node &node)
2640
2640
  DisplayCommand *cmd = DisplayList::instance().append();
2641
2641
  if (!cmd) return;
2642
2642
  cmd->type = DisplayCommandType::FillRoundedRect;
2643
- cmd->bx = n->layout.x + n->layout.width - 7;
2643
+ // LVGL's default-theme scrollbar (lv_theme_default.c): a grey (palette
2644
+ // main, #9E9E9E) pill 5 dpx wide, 7 dpx in from the edge, at 40% opacity --
2645
+ // 4 px and 6 px at the 130 dpi this geometry already follows (track pad 6).
2646
+ cmd->bx = n->layout.x + n->layout.width - 6 - 4;
2644
2647
  cmd->by = thumb_y;
2645
- cmd->bw = 3;
2648
+ cmd->bw = 4;
2646
2649
  cmd->bh = thumb_h;
2647
2650
  cmd->fillRoundedRect.x = cmd->bx;
2648
2651
  cmd->fillRoundedRect.y = cmd->by;
@@ -2652,13 +2655,28 @@ void ViewRenderer::recordScrollbar(const Node &node)
2652
2655
  cmd->fillRoundedRect.tr = 2;
2653
2656
  cmd->fillRoundedRect.br = 2;
2654
2657
  cmd->fillRoundedRect.bl = 2;
2655
- // Command colours are panel-order natives, so this has to go through the one
2656
- // authoring conversion (nativeFromRrggbbaa): it applies the panel byte-swap a
2657
- // bare fromRgb565 would leave off on 16-bit panels AND narrows to the board's
2658
- // native_t on the grayscale panels, where native_t is a byte and the RGB565
2659
- // constant would not fit. 0x8C8E94 is the exact RGB888 expansion of the RGB565
2660
- // 0x8C72 this used to spell, so 16-bit panels emit the identical pixel.
2661
- cmd->fillRoundedRect.color = gea::framework::graphics::pixel::nativeFromRrggbbaa(0x8C8E94FFu);
2658
+ // The thumb is replayed on its own (replayScrollbarThumbsInRegion), outside
2659
+ // any alpha scope, so the 40% is blended here against the background the
2660
+ // thumb stands on: the nearest opaque background up the ancestor chain.
2661
+ // Command colours are panel-order natives: build them through the one
2662
+ // authoring conversion (nativeFromRrggbbaa), which applies the panel
2663
+ // byte-swap and narrows to the board's native_t on grayscale panels.
2664
+ using gea::framework::graphics::pixel::nativeFromRrggbbaa;
2665
+ auto under = nativeFromRrggbbaa(0xFFFFFFFFu);
2666
+ {
2667
+ const auto &state = treeState();
2668
+ for (int a = static_cast<int>(n - state.nodes); a >= 0; a = state.nodes[a].parent) {
2669
+ const auto &style = state.nodes[a].computedStyle();
2670
+ if (style.has_bg && style.bg_alpha == 255) { under = style.bg_color; break; }
2671
+ if (state.nodes[a].parent < 0) {
2672
+ const int source = canvasBackgroundSource();
2673
+ if (source >= 0 && state.nodes[source].computedStyle().has_bg && state.nodes[source].computedStyle().bg_alpha == 255)
2674
+ under = state.nodes[source].computedStyle().bg_color;
2675
+ }
2676
+ }
2677
+ }
2678
+ cmd->fillRoundedRect.color = gea::framework::graphics::pixel::blendNative(nativeFromRrggbbaa(0x9E9E9EFFu), under, 102);
2679
+ DisplayList::instance().noteScrollbarBox(static_cast<int>(n - treeState().nodes), cmd->bx, cmd->by, cmd->bw, cmd->bh);
2662
2680
  #else
2663
2681
  (void)node;
2664
2682
  #endif
@@ -4,6 +4,16 @@
4
4
  #include "display.h"
5
5
  #include "internal.h"
6
6
 
7
+ #include <algorithm>
8
+
9
+ // SRAM strip staging (render.cpp defines weak no-op fallbacks; a display that
10
+ // stages overrides them).
11
+ extern "C" int gea_bulk_replay_stage_rows_for_width(int width);
12
+ extern "C" bool gea_replay_stage_begin(int x0, int y0, int x1, int y1);
13
+ extern "C" void gea_replay_stage_end();
14
+ extern "C" bool gea_replay_stage_active();
15
+ extern "C" void gea_replay_stage_skip_seed(bool skip);
16
+
7
17
  namespace gea::embedded::ui {
8
18
 
9
19
  int ViewportRegion::clipRect(int width, int height, int *x, int *y, int *w, int *h)
@@ -25,6 +35,49 @@ int ViewportRegion::clipRect(int width, int height, int *x, int *y, int *w, int
25
35
  return 1;
26
36
  }
27
37
 
38
+ void ViewportRegion::replayDisplayRegionStaged(int x, int y, int w, int h)
39
+ {
40
+ if (w <= 0 || h <= 0) return;
41
+ // A whole-list replay clipped to the region rasters straight into the back
42
+ // buffer. On a panel that scans out of PSRAM, those read-modify-writes
43
+ // compete with the scanout refill for the bus and starve it (a visible tear).
44
+ // Raster the region in SRAM strips instead and copy each back once.
45
+ const int stageRows = gea_bulk_replay_stage_rows_for_width(w);
46
+ if (stageRows > 0 && !gea_replay_stage_active()) {
47
+ // A list the caller filtered for a rect holding this one serves as is
48
+ // (one walk of the display list for a frame's several small regions).
49
+ bool covered = false;
50
+ const bool outer = DisplayList::instance().regionReplayHolds(x, y, w, h, &covered);
51
+ if (!outer) {
52
+ DisplayList::instance().endRegionReplay();
53
+ gea::platform::display::Display::pushClip(x, y, w, h);
54
+ // The strips walk only the commands that can reach this region; failing
55
+ // that, they share one cull start.
56
+ const bool filtered = DisplayList::instance().beginRegionReplay();
57
+ const int cullStart = filtered ? 0 : DisplayList::instance().replayCullStart();
58
+ covered = DisplayList::instance().replayCullCovered();
59
+ gea::platform::display::Display::popClip();
60
+ if (!filtered) DisplayList::instance().setReplayCullStart(cullStart);
61
+ }
62
+ // An opaque fill covers the region: each strip is painted whole, so it
63
+ // need not be seeded from the back buffer.
64
+ gea_replay_stage_skip_seed(covered);
65
+ for (int sy = y; sy < y + h; sy += stageRows) {
66
+ const int sh = std::min(stageRows, y + h - sy);
67
+ const bool staged = gea_replay_stage_begin(x, sy, x + w - 1, sy + sh - 1);
68
+ gea::platform::display::Display::pushClip(x, sy, w, sh);
69
+ DisplayList::instance().replay();
70
+ gea::platform::display::Display::popClip();
71
+ if (staged) gea_replay_stage_end();
72
+ }
73
+ if (!outer) DisplayList::instance().endRegionReplay();
74
+ DisplayList::instance().setReplayCullStart(-1);
75
+ gea_replay_stage_skip_seed(false);
76
+ return;
77
+ }
78
+ replayDisplayRegion(x, y, w, h);
79
+ }
80
+
28
81
  void ViewportRegion::replayDisplayRegion(int x, int y, int w, int h)
29
82
  {
30
83
  if (w <= 0 || h <= 0) return;
@@ -7,6 +7,9 @@ class ViewportRegion {
7
7
  public:
8
8
  static int clipRect(int width, int height, int *x, int *y, int *w, int *h);
9
9
  static void replayDisplayRegion(int x, int y, int w, int h);
10
+ // Same, rastered through the display's SRAM strips where it has them: for
11
+ // the rare large repaints whose raw PSRAM writes would starve the scanout.
12
+ static void replayDisplayRegionStaged(int x, int y, int w, int h);
10
13
  };
11
14
 
12
15
  } // namespace gea::embedded::ui