@geastack/engine 0.1.21 → 0.1.22

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
@@ -2079,6 +2169,9 @@ namespace gea::embedded::ui
2079
2169
  auto &state = treeState();
2080
2170
  if (root < 0 || root >= state.nodeCount)
2081
2171
  return;
2172
+ #if GEA_UI_IMAGE_NODES
2173
+ gea::framework::graphics::ImageStore::instance().releaseIdleDecodes();
2174
+ #endif
2082
2175
  #if GEA_UI_SVG
2083
2176
  svg::validateScenes();
2084
2177
  #endif
@@ -2134,9 +2227,7 @@ namespace gea::embedded::ui
2134
2227
  state.nodes[root].render.dirty = true;
2135
2228
  }
2136
2229
  }
2137
- if (framebufferReadable && !textClipDependencies && state.pendingScrollIntoViewNode < 0 && RootScrollOnlyRefresh::refresh(root, width, height))
2138
- return;
2139
-
2230
+ if (framebufferReadable && !textClipDependencies && state.pendingScrollIntoViewNode < 0 && RootScrollOnlyRefresh::refresh(root, width, height)) return;
2140
2231
  bool scrollFallbackRepaint = false;
2141
2232
  #if GEA_CSS_SCROLLING
2142
2233
  // A rejected scroll blit still moves every descendant's geometry during
@@ -2168,9 +2259,9 @@ namespace gea::embedded::ui
2168
2259
  // them in their unrotated placement.
2169
2260
  #if !defined(GEA_EMBEDDED_DIRECT_CANVAS_CONTEXT) || !GEA_EMBEDDED_DIRECT_CANVAS_CONTEXT
2170
2261
  if (!Document::directCanvasContextUsed()) {
2171
- if (auto *rotCanvas = gea::platform::display::Display::canvas()) {
2262
+ if (auto *rotCanvas = displayStateCanvas()) {
2172
2263
  const int regionH = rotCanvas->scrollRegionH();
2173
- if (regionH > 0) {
2264
+ if (regionH > 0 && !gea_display_scroll_region_persists()) {
2174
2265
  const int regionY = rotCanvas->scrollRegionY();
2175
2266
  gea::platform::display::Display::resetScrollRegion();
2176
2267
  rotCanvas->markDirty(0, regionY, width - 1, regionY + regionH - 1);
@@ -2186,7 +2277,7 @@ namespace gea::embedded::ui
2186
2277
  int framebufferDirtyX1 = -1;
2187
2278
  int framebufferDirtyY1 = -1;
2188
2279
  #if !defined(GEA_EMBEDDED_DIRECT_CANVAS_CONTEXT) || !GEA_EMBEDDED_DIRECT_CANVAS_CONTEXT
2189
- auto *displayCanvas = Document::directCanvasContextUsed() ? nullptr : gea::platform::display::Display::canvas();
2280
+ auto *displayCanvas = Document::directCanvasContextUsed() ? nullptr : displayStateCanvas();
2190
2281
  const bool framebuffer_was_dirty = displayCanvas &&
2191
2282
  displayCanvas->dirty(&framebufferDirtyX0,
2192
2283
  &framebufferDirtyY0,
@@ -2243,23 +2334,39 @@ namespace gea::embedded::ui
2243
2334
  {
2244
2335
  if (!viewportChanged && state.pendingScrollIntoViewNode < 0)
2245
2336
  {
2246
- int scope = scopedRelayoutRoot(state, root);
2247
- if (scope >= 0)
2248
- scope = stableScopeAt(state, scope, root);
2249
- if (scope < 0)
2337
+ constexpr int kMaxScopes = 16;
2338
+ int scopes[kMaxScopes];
2339
+ int scopeCount = stableRelayoutScopes(state, root, scopes, kMaxScopes);
2340
+ if (scopeCount < 0)
2341
+ {
2342
+ // No per-node scope set: one scope around every dirty node.
2343
+ int scope = scopedRelayoutRoot(state, root);
2344
+ if (scope >= 0)
2345
+ scope = stableScopeAt(state, scope, root);
2346
+ scopeCount = scope >= 0 ? 1 : 0;
2347
+ scopes[0] = scope;
2348
+ }
2349
+ if (scopeCount <= 0)
2250
2350
  GEA_REFRESH_PERF(perf.treeScopedRejectReason = 1);
2251
- for (int attempt = 0; scope >= 0 && attempt < 2; attempt++)
2351
+ scoped = scopeCount > 0;
2352
+ for (int k = 0; k < scopeCount && scoped; k++)
2252
2353
  {
2253
- scoped = LayoutEngine::instance().layoutNodeScoped(scope, root);
2254
- if (scoped)
2354
+ int scope = scopes[k];
2355
+ bool laid = false;
2356
+ for (int attempt = 0; scope >= 0 && attempt < 2; attempt++)
2255
2357
  {
2256
- GEA_REFRESH_PERF(perf.treeScopedLayouts++);
2257
- break;
2358
+ laid = LayoutEngine::instance().layoutNodeScoped(scope, root);
2359
+ if (laid)
2360
+ {
2361
+ GEA_REFRESH_PERF(perf.treeScopedLayouts++);
2362
+ break;
2363
+ }
2364
+ // Most rejects mean the scope autosized to the new content —
2365
+ // retry from the next stable ancestor up (each failed attempt's
2366
+ // partial layout is fully redone by the retry / full fallback).
2367
+ scope = stableScopeAt(state, state.nodes[scope].parent, root);
2258
2368
  }
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);
2369
+ scoped = laid;
2263
2370
  }
2264
2371
  }
2265
2372
  LayoutEngine::Pass layoutPass(!scoped);
@@ -2697,6 +2804,10 @@ namespace gea::embedded::ui
2697
2804
  int dr_x0 = width, dr_y0 = height, dr_x1 = -1, dr_y1 = -1;
2698
2805
 
2699
2806
  int canvas_x0 = 0, canvas_y0 = 0, canvas_x1 = -1, canvas_y1 = -1;
2807
+ #if GEA_UI_SVG
2808
+ int svgExtra[svg::kExtraDamage][4];
2809
+ #endif
2810
+ int svgExtraCount = 0; // further exact-damage boxes of an svg scene
2700
2811
  const auto *canvas_surface = n->type == NodeType::Canvas ? state.canvases.find(i) : nullptr;
2701
2812
  const auto *canvas = canvas_surface ? canvas_surface->canvas() : nullptr;
2702
2813
  const bool bitmap_canvas_dirty =
@@ -2759,7 +2870,8 @@ namespace gea::embedded::ui
2759
2870
  if (!canvas_dirty && svg::isRoot(*n))
2760
2871
  {
2761
2872
  int sx0, sy0, sx1, sy1;
2762
- const bool svgDamage = svg::damage(i, sx0, sy0, sx1, sy1); // always consume
2873
+ const bool svgDamage = svg::damage(i, sx0, sy0, sx1, sy1, svgExtra, &svgExtraCount); // always consume
2874
+ if (!svgDamage) svgExtraCount = 0;
2763
2875
  if (svgDamage && !n->render.layout_dirty && !n->render.transform_dirty &&
2764
2876
  n->layout.x == n->layout.previous_x && n->layout.y == n->layout.previous_y &&
2765
2877
  n->layout.width == n->layout.previous_width && n->layout.height == n->layout.previous_height &&
@@ -2772,6 +2884,8 @@ namespace gea::embedded::ui
2772
2884
  canvas_x1 = sx1;
2773
2885
  canvas_y1 = sy1;
2774
2886
  }
2887
+ else
2888
+ svgExtraCount = 0;
2775
2889
  }
2776
2890
  #endif
2777
2891
  if (canvas_dirty && !exactCanvasPixelDamage)
@@ -2956,6 +3070,16 @@ namespace gea::embedded::ui
2956
3070
  dr_y0 = n->layout.y + canvas_y0;
2957
3071
  dr_x1 = n->layout.x + canvas_x1;
2958
3072
  dr_y1 = n->layout.y + canvas_y1;
3073
+ #if GEA_UI_SVG
3074
+ for (int k = 0; k < svgExtraCount; ++k)
3075
+ {
3076
+ const DirtyRegions::Rect extraRect{n->layout.x + svgExtra[k][0], n->layout.y + svgExtra[k][1],
3077
+ n->layout.x + svgExtra[k][2], n->layout.y + svgExtra[k][3], i};
3078
+ addDirtyRegion(rects, &rect_count, extraRect, width, height);
3079
+ if (!unifiedRectPath)
3080
+ addDirtyRegion(flush_rects, &flush_rect_count, extraRect, width, height);
3081
+ }
3082
+ #endif
2959
3083
  }
2960
3084
  else if (reprojected && n->render.transform_dirty && n->first_child >= 0 &&
2961
3085
  DisplayList::instance().reprojectDirtyRect(&dr_x0, &dr_y0, &dr_x1, &dr_y1))
@@ -3189,6 +3313,36 @@ namespace gea::embedded::ui
3189
3313
  }
3190
3314
  #endif
3191
3315
  const bool hasFlushOnlyRecolorRegions = preserveFlushOnlyRecolorRegions && flush_rect_count > 0;
3316
+ // Direct replay draws node command ranges, and a scroll container's
3317
+ // scrollbar thumb lies outside them. The direct-replay entry points paint
3318
+ // the thumbs after the nodes, which is right while no later command covers
3319
+ // a thumb; otherwise repaint a thumb's pixels only through the full-list
3320
+ // path. Scrolling moves the thumb every frame, so this keeps scroll frames
3321
+ // on direct replay and the fused flush.
3322
+ if (direct_replay && !DisplayList::instance().scrollbarThumbsPaintLast())
3323
+ {
3324
+ for (int i = 0; i < rect_count && direct_replay; ++i)
3325
+ if (DisplayList::instance().scrollbarOverlapsRegion(rects[i].x0, rects[i].y0, rects[i].x1, rects[i].y1))
3326
+ direct_replay = 0;
3327
+ for (int i = 0; i < flush_rect_count && direct_replay; ++i)
3328
+ if (DisplayList::instance().scrollbarOverlapsRegion(flush_rects[i].x0, flush_rects[i].y0, flush_rects[i].x1, flush_rects[i].y1))
3329
+ direct_replay = 0;
3330
+ }
3331
+ // From here to the flush the tree and display list hold still, so the
3332
+ // simple-replay verdict's region-independent walk runs once, not once per
3333
+ // region the replay below asks about.
3334
+ struct SimpleReplayScope
3335
+ {
3336
+ bool open = true;
3337
+ SimpleReplayScope() { DisplayList::instance().beginSimpleReplayScope(); }
3338
+ void close()
3339
+ {
3340
+ if (open)
3341
+ DisplayList::instance().endSimpleReplayScope();
3342
+ open = false;
3343
+ }
3344
+ ~SimpleReplayScope() { close(); }
3345
+ } simpleReplayScope;
3192
3346
  DisplayReplayRegion simpleTransferRegions[DirtyRegions::kMaxRects];
3193
3347
  for (int i = 0; i < flush_rect_count; ++i)
3194
3348
  {
@@ -3414,9 +3568,32 @@ namespace gea::embedded::ui
3414
3568
  }
3415
3569
  GEA_REFRESH_PERF(perf.treeFlushRectsUs += refreshPerfNowUs() - flushStartUs);
3416
3570
  #else
3571
+ // A panel whose flush presents a whole frame takes one flush after the
3572
+ // last rect: a flush per rect would be a buffer swap -- and a panel
3573
+ // refresh of waiting -- per rect.
3574
+ const bool flushOncePerFrame = gea_display_flush_presents_frame();
3575
+ // One flush presents the frame, so the back buffer is readied once:
3576
+ // hand it every rect this frame repaints, or it copies the stale
3577
+ // pixels under rects 2..n from the front only for them to be painted
3578
+ // over (on a busy screen that copy was the whole repaint area again).
3579
+ gea::platform::display::DisplayFlushRect repaints[DirtyRegions::kMaxRects];
3580
+ int repaintCount = 0;
3581
+ if (flushOncePerFrame && rect_count > 0)
3582
+ {
3583
+ for (int i = 0; i < rect_count && repaintCount < DirtyRegions::kMaxRects; i++)
3584
+ {
3585
+ const DirtyRegions::Rect *r = &rects[i];
3586
+ if (r->x0 <= r->x1 && r->y0 <= r->y1)
3587
+ repaints[repaintCount++] = gea::platform::display::DisplayFlushRect{r->x0, r->y0, r->x1, r->y1};
3588
+ }
3589
+ gea_display_prepare_repaint(repaints, repaintCount);
3590
+ }
3417
3591
  for (int i = 0; i < rect_count; i++)
3418
3592
  {
3419
3593
  DirtyRegions::Rect *r = &rects[i];
3594
+ const gea::platform::display::DisplayFlushRect repaint{r->x0, r->y0, r->x1, r->y1};
3595
+ if (!flushOncePerFrame)
3596
+ gea_display_prepare_repaint(&repaint, 1);
3420
3597
  gea::platform::display::Display::resetClip();
3421
3598
  gea::platform::display::Display::setAlpha(255);
3422
3599
  gea::platform::display::Display::pushClip(r->x0, r->y0, r->x1 - r->x0 + 1, r->y1 - r->y0 + 1);
@@ -3425,10 +3602,24 @@ namespace gea::embedded::ui
3425
3602
  DisplayList::instance().replayDirectDirtyRegions(&region, 1);
3426
3603
  GEA_REFRESH_PERF(perf.treeReplayUs += refreshPerfNowUs() - replayStartUs);
3427
3604
  gea::platform::display::Display::popClip();
3605
+ if (flushOncePerFrame) continue;
3428
3606
  const std::int64_t flushStartUs = refreshPerfNowUs();
3429
3607
  gea::platform::display::Display::flush();
3430
3608
  GEA_REFRESH_PERF(perf.treeFlushRectsUs += refreshPerfNowUs() - flushStartUs);
3431
3609
  }
3610
+ if (flushOncePerFrame)
3611
+ {
3612
+ const std::int64_t flushStartUs = refreshPerfNowUs();
3613
+ // Publish the rects themselves, not the canvas's one dirty box: the
3614
+ // panel copies what it publishes into the other buffer before the
3615
+ // next frame draws there, and the box spans everything between
3616
+ // separate rects (two meters a screen apart).
3617
+ if (repaintCount > 0)
3618
+ gea::platform::display::Display::flushRects(repaints, repaintCount);
3619
+ else
3620
+ gea::platform::display::Display::flush();
3621
+ GEA_REFRESH_PERF(perf.treeFlushRectsUs += refreshPerfNowUs() - flushStartUs);
3622
+ }
3432
3623
  #endif
3433
3624
  }
3434
3625
  else
@@ -3440,26 +3631,74 @@ namespace gea::embedded::ui
3440
3631
  gea::platform::display::Display::resetClip();
3441
3632
  gea::platform::display::Display::setAlpha(255);
3442
3633
  DisplayReplayRegion regions[DirtyRegions::kMaxRects];
3634
+ gea::platform::display::DisplayFlushRect repaints[DirtyRegions::kMaxRects];
3443
3635
  for (int i = 0; i < rect_count; i++)
3444
3636
  {
3445
3637
  DirtyRegions::Rect *r = &rects[i];
3446
3638
  regions[i] = DisplayReplayRegion{r->x0, r->y0, r->x1, r->y1, r->origin};
3639
+ repaints[i] = gea::platform::display::DisplayFlushRect{r->x0, r->y0, r->x1, r->y1};
3447
3640
  }
3641
+ // The direct replay repaints every region completely.
3642
+ gea_display_prepare_repaint(repaints, rect_count);
3448
3643
  DisplayList::instance().replayDirectDirtyRegions(regions, rect_count);
3449
3644
  }
3450
3645
  else
3451
3646
  {
3452
3647
  // Conservative paint path for full display-list replay.
3648
+ // Raster each rect in SRAM strips where the display stages, so the
3649
+ // back-buffer writes cannot starve a PSRAM scanout refill.
3650
+ // An opaque underlay (a gea3d frame) paints every pixel of the rects
3651
+ // it covers before the tree replays over it: those are repainted
3652
+ // whole, so the display need not first restore their old pixels
3653
+ // (on a double-buffered panel, a full-screen copy every frame).
3654
+ {
3655
+ gea::platform::display::DisplayFlushRect covered[DirtyRegions::kMaxRects];
3656
+ int coveredCount = 0;
3657
+ for (int i = 0; i < rect_count; i++)
3658
+ if (gea::framework::display::Underlay::covers(rects[i].x0, rects[i].y0, rects[i].x1, rects[i].y1))
3659
+ covered[coveredCount++] = gea::platform::display::DisplayFlushRect{rects[i].x0, rects[i].y0, rects[i].x1, rects[i].y1};
3660
+ if (coveredCount > 0) gea_display_prepare_repaint(covered, coveredCount);
3661
+ }
3662
+ gea_replay_stage_pipeline(true);
3453
3663
  for (int i = 0; i < rect_count; i++)
3454
3664
  {
3455
3665
  DirtyRegions::Rect *r = &rects[i];
3666
+ const int stageRows = gea_bulk_replay_stage_rows_for_width(r->x1 - r->x0 + 1);
3667
+ const int band = stageRows > 0 && !gea_replay_stage_active() ? stageRows : r->y1 - r->y0 + 1;
3668
+ // One occlusion-cull scan for the whole rect, reused by every strip.
3456
3669
  gea::platform::display::Display::resetClip();
3457
- gea::platform::display::Display::setAlpha(255);
3458
3670
  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();
3671
+ DisplayList::instance().setReplayCullStart(DisplayList::instance().replayCullStart());
3672
+ // An opaque underlay paints every pixel of the strips it covers
3673
+ // first, so their seed from the back buffer would be overwritten.
3674
+ gea_replay_stage_skip_seed(DisplayList::instance().replayCullCovered() ||
3675
+ gea::framework::display::Underlay::covers(r->x0, r->y0, r->x1, r->y1));
3461
3676
  gea::platform::display::Display::popClip();
3677
+ #ifndef GEA_EMBEDDED_STAGE_GRID_STRIPS
3678
+ #define GEA_EMBEDDED_STAGE_GRID_STRIPS 0
3679
+ #endif
3680
+ // With GEA_EMBEDDED_STAGE_GRID_STRIPS (an app opt-in) staged
3681
+ // strips sit on a fixed grid of the staging height, so a strip's
3682
+ // rows map to one band of an underlay that keeps per-band lists
3683
+ // (gea3d); strips that start wherever the dirty box does straddle
3684
+ // two bands and rescan the whole primitive list.
3685
+ const bool gridStrips = GEA_EMBEDDED_STAGE_GRID_STRIPS && band == stageRows && stageRows > 0;
3686
+ for (int sy0 = r->y0, sy1 = 0; sy0 <= r->y1; sy0 = sy1 + 1)
3687
+ {
3688
+ sy1 = std::min(r->y1, gridStrips ? (sy0 / band + 1) * band - 1 : sy0 + band - 1);
3689
+ gea::platform::display::Display::resetClip();
3690
+ gea::platform::display::Display::setAlpha(255);
3691
+ const bool staged = stageRows > 0 && band == stageRows && gea_replay_stage_begin(r->x0, sy0, r->x1, sy1);
3692
+ gea::platform::display::Display::pushClip(r->x0, sy0, r->x1 - r->x0 + 1, sy1 - sy0 + 1);
3693
+ gea::framework::display::Underlay::paint(r->x0, sy0, r->x1, sy1);
3694
+ DisplayList::instance().replay();
3695
+ gea::platform::display::Display::popClip();
3696
+ if (staged) gea_replay_stage_end();
3697
+ }
3698
+ DisplayList::instance().setReplayCullStart(-1);
3699
+ gea_replay_stage_skip_seed(false);
3462
3700
  }
3701
+ gea_replay_stage_pipeline(false);
3463
3702
  }
3464
3703
  GEA_REFRESH_PERF(perf.treeReplayUs += refreshPerfNowUs() - replayStartUs);
3465
3704
  }
@@ -3496,6 +3735,7 @@ namespace gea::embedded::ui
3496
3735
  #if defined(ESP_PLATFORM) && CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS
3497
3736
  const auto diagnosticReplayEnd = esp_timer_get_time();
3498
3737
  #endif
3738
+ simpleReplayScope.close();
3499
3739
  if (!banded && !simpleUnifiedReplay && !interleavedUnifiedFlush)
3500
3740
  {
3501
3741
  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