@geastack/engine 0.1.20 → 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,12 +5,14 @@
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"
11
12
  #include "refresh_perf.h"
12
13
  #include "root_scroll_refresh.h"
13
14
  #include "tree_state.h"
15
+ #include "svg_element.h"
14
16
 
15
17
  #include <cmath>
16
18
  #include <cstddef>
@@ -42,6 +44,42 @@
42
44
  #define GEA_EMBEDDED_DISPLAY_FUSE_INTERLEAVED_REPLAY_FLUSH 0
43
45
  #endif
44
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
+
45
83
  #ifndef GEA_EMBEDDED_DISPLAY_FUSE_REPLAY_CLEAR_RGB565
46
84
  #define GEA_EMBEDDED_DISPLAY_FUSE_REPLAY_CLEAR_RGB565 -1
47
85
  #endif
@@ -80,6 +118,11 @@
80
118
  #define GEA_EMBEDDED_SUBTREE_REVEAL_CHECK 1
81
119
  #endif
82
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
+
83
126
  namespace gea::embedded::ui
84
127
  {
85
128
  namespace
@@ -2050,6 +2093,54 @@ namespace gea::embedded::ui
2050
2093
  }
2051
2094
  return -1;
2052
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
+ }
2053
2144
  // A transformed parent re-records its whole subtree (its descendants'
2054
2145
  // corners all move). When no descendant paints anything -- the empty slot
2055
2146
  // of `{done ? <img/> : null}` inside a pulsing dot -- there is nothing to
@@ -2078,6 +2169,12 @@ namespace gea::embedded::ui
2078
2169
  auto &state = treeState();
2079
2170
  if (root < 0 || root >= state.nodeCount)
2080
2171
  return;
2172
+ #if GEA_UI_IMAGE_NODES
2173
+ gea::framework::graphics::ImageStore::instance().releaseIdleDecodes();
2174
+ #endif
2175
+ #if GEA_UI_SVG
2176
+ svg::validateScenes();
2177
+ #endif
2081
2178
  #if defined(GEA_NATIVE_DEBUGGER) && GEA_NATIVE_DEBUGGER
2082
2179
  debuggerOverlay.prepare();
2083
2180
  #endif
@@ -2130,9 +2227,7 @@ namespace gea::embedded::ui
2130
2227
  state.nodes[root].render.dirty = true;
2131
2228
  }
2132
2229
  }
2133
- if (framebufferReadable && !textClipDependencies && state.pendingScrollIntoViewNode < 0 && RootScrollOnlyRefresh::refresh(root, width, height))
2134
- return;
2135
-
2230
+ if (framebufferReadable && !textClipDependencies && state.pendingScrollIntoViewNode < 0 && RootScrollOnlyRefresh::refresh(root, width, height)) return;
2136
2231
  bool scrollFallbackRepaint = false;
2137
2232
  #if GEA_CSS_SCROLLING
2138
2233
  // A rejected scroll blit still moves every descendant's geometry during
@@ -2164,9 +2259,9 @@ namespace gea::embedded::ui
2164
2259
  // them in their unrotated placement.
2165
2260
  #if !defined(GEA_EMBEDDED_DIRECT_CANVAS_CONTEXT) || !GEA_EMBEDDED_DIRECT_CANVAS_CONTEXT
2166
2261
  if (!Document::directCanvasContextUsed()) {
2167
- if (auto *rotCanvas = gea::platform::display::Display::canvas()) {
2262
+ if (auto *rotCanvas = displayStateCanvas()) {
2168
2263
  const int regionH = rotCanvas->scrollRegionH();
2169
- if (regionH > 0) {
2264
+ if (regionH > 0 && !gea_display_scroll_region_persists()) {
2170
2265
  const int regionY = rotCanvas->scrollRegionY();
2171
2266
  gea::platform::display::Display::resetScrollRegion();
2172
2267
  rotCanvas->markDirty(0, regionY, width - 1, regionY + regionH - 1);
@@ -2182,7 +2277,7 @@ namespace gea::embedded::ui
2182
2277
  int framebufferDirtyX1 = -1;
2183
2278
  int framebufferDirtyY1 = -1;
2184
2279
  #if !defined(GEA_EMBEDDED_DIRECT_CANVAS_CONTEXT) || !GEA_EMBEDDED_DIRECT_CANVAS_CONTEXT
2185
- auto *displayCanvas = Document::directCanvasContextUsed() ? nullptr : gea::platform::display::Display::canvas();
2280
+ auto *displayCanvas = Document::directCanvasContextUsed() ? nullptr : displayStateCanvas();
2186
2281
  const bool framebuffer_was_dirty = displayCanvas &&
2187
2282
  displayCanvas->dirty(&framebufferDirtyX0,
2188
2283
  &framebufferDirtyY0,
@@ -2239,23 +2334,39 @@ namespace gea::embedded::ui
2239
2334
  {
2240
2335
  if (!viewportChanged && state.pendingScrollIntoViewNode < 0)
2241
2336
  {
2242
- int scope = scopedRelayoutRoot(state, root);
2243
- if (scope >= 0)
2244
- scope = stableScopeAt(state, scope, root);
2245
- 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)
2246
2350
  GEA_REFRESH_PERF(perf.treeScopedRejectReason = 1);
2247
- for (int attempt = 0; scope >= 0 && attempt < 2; attempt++)
2351
+ scoped = scopeCount > 0;
2352
+ for (int k = 0; k < scopeCount && scoped; k++)
2248
2353
  {
2249
- scoped = LayoutEngine::instance().layoutNodeScoped(scope, root);
2250
- if (scoped)
2354
+ int scope = scopes[k];
2355
+ bool laid = false;
2356
+ for (int attempt = 0; scope >= 0 && attempt < 2; attempt++)
2251
2357
  {
2252
- GEA_REFRESH_PERF(perf.treeScopedLayouts++);
2253
- 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);
2254
2368
  }
2255
- // Most rejects mean the scope autosized to the new content —
2256
- // retry from the next stable ancestor up (each failed attempt's
2257
- // partial layout is fully redone by the retry / full fallback).
2258
- scope = stableScopeAt(state, state.nodes[scope].parent, root);
2369
+ scoped = laid;
2259
2370
  }
2260
2371
  }
2261
2372
  LayoutEngine::Pass layoutPass(!scoped);
@@ -2693,6 +2804,10 @@ namespace gea::embedded::ui
2693
2804
  int dr_x0 = width, dr_y0 = height, dr_x1 = -1, dr_y1 = -1;
2694
2805
 
2695
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
2696
2811
  const auto *canvas_surface = n->type == NodeType::Canvas ? state.canvases.find(i) : nullptr;
2697
2812
  const auto *canvas = canvas_surface ? canvas_surface->canvas() : nullptr;
2698
2813
  const bool bitmap_canvas_dirty =
@@ -2749,6 +2864,30 @@ namespace gea::embedded::ui
2749
2864
  canvas_y1 = retained_y1;
2750
2865
  }
2751
2866
  }
2867
+ #if GEA_UI_SVG
2868
+ // An svg whose box is unchanged repaints only the pixels its scene
2869
+ // rebuild touched, through the same exact-damage path as a canvas.
2870
+ if (!canvas_dirty && svg::isRoot(*n))
2871
+ {
2872
+ int sx0, sy0, sx1, sy1;
2873
+ const bool svgDamage = svg::damage(i, sx0, sy0, sx1, sy1, svgExtra, &svgExtraCount); // always consume
2874
+ if (!svgDamage) svgExtraCount = 0;
2875
+ if (svgDamage && !n->render.layout_dirty && !n->render.transform_dirty &&
2876
+ n->layout.x == n->layout.previous_x && n->layout.y == n->layout.previous_y &&
2877
+ n->layout.width == n->layout.previous_width && n->layout.height == n->layout.previous_height &&
2878
+ !ViewRenderer::anyTransformActive())
2879
+ {
2880
+ canvas_dirty = true;
2881
+ exactCanvasPixelDamage = true;
2882
+ canvas_x0 = sx0;
2883
+ canvas_y0 = sy0;
2884
+ canvas_x1 = sx1;
2885
+ canvas_y1 = sy1;
2886
+ }
2887
+ else
2888
+ svgExtraCount = 0;
2889
+ }
2890
+ #endif
2752
2891
  if (canvas_dirty && !exactCanvasPixelDamage)
2753
2892
  {
2754
2893
  // A style/geometry invalidation is not a content-only repaint. Both
@@ -2931,6 +3070,16 @@ namespace gea::embedded::ui
2931
3070
  dr_y0 = n->layout.y + canvas_y0;
2932
3071
  dr_x1 = n->layout.x + canvas_x1;
2933
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
2934
3083
  }
2935
3084
  else if (reprojected && n->render.transform_dirty && n->first_child >= 0 &&
2936
3085
  DisplayList::instance().reprojectDirtyRect(&dr_x0, &dr_y0, &dr_x1, &dr_y1))
@@ -3164,6 +3313,36 @@ namespace gea::embedded::ui
3164
3313
  }
3165
3314
  #endif
3166
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;
3167
3346
  DisplayReplayRegion simpleTransferRegions[DirtyRegions::kMaxRects];
3168
3347
  for (int i = 0; i < flush_rect_count; ++i)
3169
3348
  {
@@ -3389,9 +3568,32 @@ namespace gea::embedded::ui
3389
3568
  }
3390
3569
  GEA_REFRESH_PERF(perf.treeFlushRectsUs += refreshPerfNowUs() - flushStartUs);
3391
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
+ }
3392
3591
  for (int i = 0; i < rect_count; i++)
3393
3592
  {
3394
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);
3395
3597
  gea::platform::display::Display::resetClip();
3396
3598
  gea::platform::display::Display::setAlpha(255);
3397
3599
  gea::platform::display::Display::pushClip(r->x0, r->y0, r->x1 - r->x0 + 1, r->y1 - r->y0 + 1);
@@ -3400,10 +3602,24 @@ namespace gea::embedded::ui
3400
3602
  DisplayList::instance().replayDirectDirtyRegions(&region, 1);
3401
3603
  GEA_REFRESH_PERF(perf.treeReplayUs += refreshPerfNowUs() - replayStartUs);
3402
3604
  gea::platform::display::Display::popClip();
3605
+ if (flushOncePerFrame) continue;
3403
3606
  const std::int64_t flushStartUs = refreshPerfNowUs();
3404
3607
  gea::platform::display::Display::flush();
3405
3608
  GEA_REFRESH_PERF(perf.treeFlushRectsUs += refreshPerfNowUs() - flushStartUs);
3406
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
+ }
3407
3623
  #endif
3408
3624
  }
3409
3625
  else
@@ -3415,26 +3631,74 @@ namespace gea::embedded::ui
3415
3631
  gea::platform::display::Display::resetClip();
3416
3632
  gea::platform::display::Display::setAlpha(255);
3417
3633
  DisplayReplayRegion regions[DirtyRegions::kMaxRects];
3634
+ gea::platform::display::DisplayFlushRect repaints[DirtyRegions::kMaxRects];
3418
3635
  for (int i = 0; i < rect_count; i++)
3419
3636
  {
3420
3637
  DirtyRegions::Rect *r = &rects[i];
3421
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};
3422
3640
  }
3641
+ // The direct replay repaints every region completely.
3642
+ gea_display_prepare_repaint(repaints, rect_count);
3423
3643
  DisplayList::instance().replayDirectDirtyRegions(regions, rect_count);
3424
3644
  }
3425
3645
  else
3426
3646
  {
3427
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);
3428
3663
  for (int i = 0; i < rect_count; i++)
3429
3664
  {
3430
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.
3431
3669
  gea::platform::display::Display::resetClip();
3432
- gea::platform::display::Display::setAlpha(255);
3433
3670
  gea::platform::display::Display::pushClip(r->x0, r->y0, r->x1 - r->x0 + 1, r->y1 - r->y0 + 1);
3434
- gea::framework::display::Underlay::paint(r->x0, r->y0, r->x1, r->y1);
3435
- 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));
3436
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);
3437
3700
  }
3701
+ gea_replay_stage_pipeline(false);
3438
3702
  }
3439
3703
  GEA_REFRESH_PERF(perf.treeReplayUs += refreshPerfNowUs() - replayStartUs);
3440
3704
  }
@@ -3471,6 +3735,7 @@ namespace gea::embedded::ui
3471
3735
  #if defined(ESP_PLATFORM) && CONFIG_FREERTOS_GENERATE_RUN_TIME_STATS
3472
3736
  const auto diagnosticReplayEnd = esp_timer_get_time();
3473
3737
  #endif
3738
+ simpleReplayScope.close();
3474
3739
  if (!banded && !simpleUnifiedReplay && !interleavedUnifiedFlush)
3475
3740
  {
3476
3741
  for (int i = 0; i < flush_rect_count; i++)
@@ -3640,3 +3905,6 @@ namespace gea::embedded::ui
3640
3905
  }
3641
3906
 
3642
3907
  } // namespace gea::embedded::ui
3908
+
3909
+ // Inline SVG lives in this translation unit (see svg_element_impl.h).
3910
+ #include "svg_element_impl.h"
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
@@ -5,6 +5,7 @@
5
5
  #include "node_lifecycle.h"
6
6
  #include "refresh_perf.h"
7
7
  #include "style_values.h"
8
+ #include "svg_element.h"
8
9
  #include "tree_state.h"
9
10
 
10
11
  // Skip the inline-style record for Left/Top (see setStyleValue). Default off: keep the
@@ -1150,6 +1151,21 @@ void setStyleValue(Tree &tree, int node, Property prop, int value, bool recordIn
1150
1151
  if (rstyle(style).box_shadow_alpha != next) { rstyleMut(style).box_shadow_alpha = next; changed = 1; }
1151
1152
  break;
1152
1153
  }
1154
+ #endif
1155
+ #if GEA_UI_SVG
1156
+ #define GEA_SVG_STYLE_FIELD(PROP, FIELD, TYPE) \
1157
+ case Property::PROP: \
1158
+ if (rstyle(style).FIELD != static_cast<TYPE>(value)) { rstyleMut(style).FIELD = static_cast<TYPE>(value); changed = 1; } \
1159
+ break;
1160
+ GEA_SVG_STYLE_FIELD(SvgFill, svg_fill, int32_t)
1161
+ GEA_SVG_STYLE_FIELD(SvgStroke, svg_stroke, int32_t)
1162
+ GEA_SVG_STYLE_FIELD(SvgStrokeWidth, svg_stroke_width, int32_t)
1163
+ GEA_SVG_STYLE_FIELD(SvgFillOpacity, svg_fill_opacity, int16_t)
1164
+ GEA_SVG_STYLE_FIELD(SvgStrokeOpacity, svg_stroke_opacity, int16_t)
1165
+ GEA_SVG_STYLE_FIELD(SvgStrokeLinecap, svg_stroke_linecap, int8_t)
1166
+ GEA_SVG_STYLE_FIELD(SvgStrokeLinejoin, svg_stroke_linejoin, int8_t)
1167
+ GEA_SVG_STYLE_FIELD(SvgFillRule, svg_fill_rule, int8_t)
1168
+ #undef GEA_SVG_STYLE_FIELD
1153
1169
  #endif
1154
1170
  default:
1155
1171
  GEA_REFRESH_PERF(perf.treeSetStyleNoop++);
@@ -1168,6 +1184,14 @@ void setStyleValue(Tree &tree, int node, Property prop, int value, bool recordIn
1168
1184
  GEA_REFRESH_PERF(perf.treeSetStylePaintChanged++);
1169
1185
  if (state.styleInvalidationSuppressionDepth > 0) return;
1170
1186
  if (!nodeParticipatesInMountedTree(state, node)) return;
1187
+ #if GEA_UI_SVG
1188
+ // SVG paint lives in the owning <svg>'s scene, not in this node's commands:
1189
+ // repaint that one svg and nothing else (no layout, no list rebuild).
1190
+ if (svg::isPaintProperty(prop)) {
1191
+ svg::noteNodeChanged(node);
1192
+ return;
1193
+ }
1194
+ #endif
1171
1195
  n->render.canvas_pixels_only_dirty = 0;
1172
1196
  const bool hadRecolor = n->render.bg_recolor_pending;
1173
1197
  const bool canRecolor = !n->render.dirty || hadRecolor;
@@ -1306,8 +1330,16 @@ void setStyleValue(Tree &tree, int node, Property prop, int value, bool recordIn
1306
1330
  // reflows or reorders → full rebuild.
1307
1331
  const bool absLeafSize = (prop == Property::Width || prop == Property::Height) &&
1308
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;
1309
1339
  if (absLeafSize)
1310
1340
  tree.markNodeDisplayCommandsDirty(node);
1341
+ else if (absBoxSize)
1342
+ tree.markDisplayListContentDirty();
1311
1343
  else
1312
1344
  tree.markDisplayListDirty();
1313
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;