@geastack/engine 0.1.13 → 0.1.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/ui/render.cpp CHANGED
@@ -138,6 +138,16 @@ extern "C" __attribute__((weak)) void *gea_display_command_buffer(int *cap_comma
138
138
  return nullptr;
139
139
  }
140
140
 
141
+ // Banded UI mode (GEA_EMBEDDED_DISPLAY_BANDED_UI) replays into a DMA staging
142
+ // chunk the shared canvas is temporarily bound to; the worker core's canvas
143
+ // still addresses the framebuffer, so no replay/fill may split across cores
144
+ // while a band rasterizes. Constant true everywhere else.
145
+ #if GEA_EMBEDDED_DISPLAY_BANDED_UI
146
+ #define GEA_RENDER_SPLIT_ALLOWED (!gea::embedded::ui::gBandedRasterActive)
147
+ #else
148
+ #define GEA_RENDER_SPLIT_ALLOWED 1
149
+ #endif
150
+
141
151
  // 2nd-core fill offload. The target may provide a worker pinned to the other CPU;
142
152
  // submit() hands it a row band (returns false if there's no worker), wait() joins.
143
153
  // Weak defaults = no worker, so the fill runs entirely on the calling core
@@ -1578,6 +1588,25 @@ int gLastScrollUiFrame = -1000;
1578
1588
  out->brRy8 = scaleRadius8(r.brRy8, scaleY);
1579
1589
  out->blRx8 = scaleRadius8(r.blRx8, scaleX);
1580
1590
  out->blRy8 = scaleRadius8(r.blRy8, scaleY);
1591
+ // A scaled circle's box rounds to whole pixels independently of its
1592
+ // radii; rounding the box down leaves each radius up to a pixel past
1593
+ // half the box, and the Canvas primitive refused it -- about half the
1594
+ // frames of any scale animation then took the per-pixel shader. CSS
1595
+ // clamps such a radius to the box anyway; clamp the rounding slack.
1596
+ const int maxRx8 = std::min(out->w, out->h) * 4;
1597
+ const int maxRy8 = maxRx8;
1598
+ auto clampSlack = [](int &radius8, int max8) {
1599
+ if (radius8 > max8 && radius8 - max8 <= 8)
1600
+ radius8 = max8;
1601
+ };
1602
+ clampSlack(out->tlRx8, maxRx8);
1603
+ clampSlack(out->trRx8, maxRx8);
1604
+ clampSlack(out->brRx8, maxRx8);
1605
+ clampSlack(out->blRx8, maxRx8);
1606
+ clampSlack(out->tlRy8, maxRy8);
1607
+ clampSlack(out->trRy8, maxRy8);
1608
+ clampSlack(out->brRy8, maxRy8);
1609
+ clampSlack(out->blRy8, maxRy8);
1581
1610
  return true;
1582
1611
  }
1583
1612
 
@@ -1817,13 +1846,46 @@ int gLastScrollUiFrame = -1000;
1817
1846
 
1818
1847
  int fillQuadCoverage(const int *xs, const int *ys, int x, int y, int samples)
1819
1848
  {
1849
+ // Every sample lies within half a pixel of the pixel centre, so a pixel
1850
+ // whose centre clears each edge by that half-pixel reach (plus a bound on
1851
+ // the float rounding of the per-sample test) classifies all of its samples
1852
+ // at once. Exact integer math in half-pixel units; only the pixels an edge
1853
+ // actually crosses pay for the per-sample test, which is unchanged. Small
1854
+ // quads were ~7 us per pixel on the S31 doing every sample.
1855
+ int positive = 0, negative = 0;
1856
+ for (int i = 0; i < 4; ++i)
1857
+ {
1858
+ const int j = (i + 1) & 3;
1859
+ const std::int64_t dx = static_cast<std::int64_t>(xs[j]) - xs[i];
1860
+ const std::int64_t dy = static_cast<std::int64_t>(ys[j]) - ys[i];
1861
+ const std::int64_t ry = 2 * static_cast<std::int64_t>(y) + 1 - 2 * static_cast<std::int64_t>(ys[i]);
1862
+ const std::int64_t rx = 2 * static_cast<std::int64_t>(x) + 1 - 2 * static_cast<std::int64_t>(xs[i]);
1863
+ const std::int64_t adx = dx < 0 ? -dx : dx;
1864
+ const std::int64_t ady = dy < 0 ? -dy : dy;
1865
+ const std::int64_t centre = dx * ry - dy * rx;
1866
+ const std::int64_t reach = adx + ady;
1867
+ const std::int64_t rounding = ((adx * ((ry < 0 ? -ry : ry) + 1) + ady * ((rx < 0 ? -rx : rx) + 1)) >> 20) + 1;
1868
+ const std::int64_t margin = reach + rounding;
1869
+ if (centre > margin)
1870
+ positive |= 1 << i;
1871
+ else if (centre < -margin)
1872
+ negative |= 1 << i;
1873
+ }
1874
+ if (positive && negative)
1875
+ return 0;
1876
+ if (positive == 0xf || negative == 0xf)
1877
+ return samples * samples;
1878
+ float offsets[16];
1879
+ const int n = std::min(samples, 16);
1880
+ for (int i = 0; i < n; ++i)
1881
+ offsets[i] = antialiasOffset(i, samples);
1820
1882
  int coverage = 0;
1821
1883
  for (int iy = 0; iy < samples; ++iy)
1822
1884
  {
1823
- const float oy = antialiasOffset(iy, samples);
1885
+ const float oy = iy < 16 ? offsets[iy] : antialiasOffset(iy, samples);
1824
1886
  for (int ix = 0; ix < samples; ++ix)
1825
1887
  {
1826
- const float ox = antialiasOffset(ix, samples);
1888
+ const float ox = ix < 16 ? offsets[ix] : antialiasOffset(ix, samples);
1827
1889
  if (convexQuadContainsFast(xs, ys, static_cast<float>(x) + ox, static_cast<float>(y) + oy))
1828
1890
  ++coverage;
1829
1891
  }
@@ -1831,6 +1893,87 @@ int gLastScrollUiFrame = -1000;
1831
1893
  return coverage;
1832
1894
  }
1833
1895
 
1896
+ // Per-command preparation for fillQuadCoverage. With 2x2 or 4x4 sampling the
1897
+ // sample offsets are exact binary fractions, and while every edge's cross
1898
+ // product stays below 2^21 the float test in convexQuadContainsFast never
1899
+ // rounds — so the same signs come out of exact integers in 1/(2n) pixel
1900
+ // units. Each edge is then a linear function stepped across the sample grid:
1901
+ // a pixel it clears entirely costs two compares, and only the edges that
1902
+ // cross the pixel fill in per-sample sign bits. Thin rotated quads (dial
1903
+ // ticks) are almost all edge pixels; they were ~3 us per pixel on the S31.
1904
+ struct QuadCoverage
1905
+ {
1906
+ const int *xs;
1907
+ const int *ys;
1908
+ int samples;
1909
+ bool exact;
1910
+ int a[4], b[4];
1911
+ unsigned full;
1912
+
1913
+ QuadCoverage(const int *qx, const int *qy, int n, int x0, int y0, int x1, int y1)
1914
+ : xs(qx), ys(qy), samples(n), exact(false), full(0)
1915
+ {
1916
+ if (n != 2 && n != 4)
1917
+ return;
1918
+ std::int64_t worst = 0;
1919
+ for (int i = 0; i < 4; ++i)
1920
+ {
1921
+ const int j = (i + 1) & 3;
1922
+ const std::int64_t dx = static_cast<std::int64_t>(qx[j]) - qx[i];
1923
+ const std::int64_t dy = static_cast<std::int64_t>(qy[j]) - qy[i];
1924
+ const std::int64_t spanX = std::max(std::llabs(static_cast<std::int64_t>(x0) - qx[i]), std::llabs(static_cast<std::int64_t>(x1) - qx[i])) + 1;
1925
+ const std::int64_t spanY = std::max(std::llabs(static_cast<std::int64_t>(y0) - qy[i]), std::llabs(static_cast<std::int64_t>(y1) - qy[i])) + 1;
1926
+ worst = std::max(worst, std::llabs(dx) * spanY + std::llabs(dy) * spanX);
1927
+ a[i] = static_cast<int>(-dy);
1928
+ b[i] = static_cast<int>(dx);
1929
+ }
1930
+ if (worst >= (std::int64_t(1) << 20))
1931
+ return;
1932
+ exact = true;
1933
+ full = (1u << (n * n)) - 1u;
1934
+ }
1935
+
1936
+ int at(int x, int y) const
1937
+ {
1938
+ if (!exact)
1939
+ return fillQuadCoverage(xs, ys, x, y, samples);
1940
+ const int n = samples;
1941
+ const int unit = 2 * n;
1942
+ unsigned anyPositive = 0, anyNegative = 0;
1943
+ for (int i = 0; i < 4; ++i)
1944
+ {
1945
+ const int stepX = 2 * a[i], stepY = 2 * b[i];
1946
+ const int base = b[i] * (unit * (y - ys[i]) + 1) + a[i] * (unit * (x - xs[i]) + 1);
1947
+ const int reachX = stepX * (n - 1), reachY = stepY * (n - 1);
1948
+ const int lo = base + std::min(0, reachX) + std::min(0, reachY);
1949
+ const int hi = base + std::max(0, reachX) + std::max(0, reachY);
1950
+ if (lo > 0)
1951
+ anyPositive = full;
1952
+ else if (hi < 0)
1953
+ anyNegative = full;
1954
+ else if (lo != 0 || hi != 0)
1955
+ {
1956
+ unsigned bit = 1;
1957
+ int row = base;
1958
+ for (int iy = 0; iy < n; ++iy, row += stepY)
1959
+ {
1960
+ int v = row;
1961
+ for (int ix = 0; ix < n; ++ix, v += stepX, bit <<= 1)
1962
+ {
1963
+ if (v > 0)
1964
+ anyPositive |= bit;
1965
+ else if (v < 0)
1966
+ anyNegative |= bit;
1967
+ }
1968
+ }
1969
+ }
1970
+ if ((anyPositive & anyNegative) == full)
1971
+ return 0;
1972
+ }
1973
+ return __builtin_popcount(full & ~(anyPositive & anyNegative));
1974
+ }
1975
+ };
1976
+
1834
1977
  int combinedCoverageAlpha(int alpha, int coverage, int sampleCount)
1835
1978
  {
1836
1979
  if (coverage <= 0 || alpha <= 0)
@@ -3287,7 +3430,7 @@ int gLastScrollUiFrame = -1000;
3287
3430
  gSplitN = gInlineN = gSplitRows = gInlineRows = gMaxRows = 0;
3288
3431
  }
3289
3432
  };
3290
- if (rows >= kMinRowsToSplit)
3433
+ if (GEA_RENDER_SPLIT_ALLOWED && rows >= kMinRowsToSplit)
3291
3434
  {
3292
3435
  const int mid = (y0 + y1) >> 1;
3293
3436
  struct Trampoline
@@ -4208,6 +4351,7 @@ int gLastScrollUiFrame = -1000;
4208
4351
  const int coverageArea = (drawXMax - drawXMin + 1) * (drawY1 - drawY0 + 1);
4209
4352
  const int aaSamples = gea::framework::graphics::Canvas::antialiasSamples();
4210
4353
  const int aaSampleCount = aaSamples * aaSamples;
4354
+ const QuadCoverage quadCoverage(xs, ys, aaSamples, drawXMin, drawY0, drawXMax, drawY1);
4211
4355
  if (aaSamples >= 2 && drawXMin <= drawXMax && coverageArea > 0 && coverageArea <= kAntialiasFullCoverageAreaLimit)
4212
4356
  {
4213
4357
  int dirtyX0 = canvas->width();
@@ -4219,7 +4363,7 @@ int gLastScrollUiFrame = -1000;
4219
4363
  gea::framework::graphics::pixel::native_t *row = canvas->pixels() + canvas->rowToPhysical(y) * stride;
4220
4364
  for (int x = drawXMin; x <= drawXMax; ++x)
4221
4365
  {
4222
- const int coverage = fillQuadCoverage(xs, ys, x, y, aaSamples);
4366
+ const int coverage = quadCoverage.at(x, y);
4223
4367
  if (coverage <= 0)
4224
4368
  continue;
4225
4369
  paintCoveragePixel(row[x], command.quad.color, alpha, coverage, aaSampleCount);
@@ -4302,7 +4446,7 @@ int gLastScrollUiFrame = -1000;
4302
4446
 
4303
4447
  for (int x = aaLX0; x <= aaLX1; x++)
4304
4448
  {
4305
- const int coverage = fillQuadCoverage(xs, ys, x, y, aaSamples);
4449
+ const int coverage = quadCoverage.at(x, y);
4306
4450
  if (coverage > 0)
4307
4451
  paintCoveragePixel(row[x], quadColor, alpha, coverage, aaSampleCount);
4308
4452
  }
@@ -4323,7 +4467,7 @@ int gLastScrollUiFrame = -1000;
4323
4467
 
4324
4468
  for (int x = aaRX0; x <= aaRX1; x++)
4325
4469
  {
4326
- const int coverage = fillQuadCoverage(xs, ys, x, y, aaSamples);
4470
+ const int coverage = quadCoverage.at(x, y);
4327
4471
  if (coverage > 0)
4328
4472
  paintCoveragePixel(row[x], quadColor, alpha, coverage, aaSampleCount);
4329
4473
  }
@@ -4595,6 +4739,111 @@ int gLastScrollUiFrame = -1000;
4595
4739
  inner.blRx8 = std::max(0, s.rx8[3] - 8 * s.lineWidth); inner.blRy8 = std::max(0, s.ry8[3] - 8 * s.lineWidth);
4596
4740
  }
4597
4741
 
4742
+ // Whole-pixel answers for roundedRectContainsFast over a pixel's sample box.
4743
+ // Valid only while no two corner radii overlap along a side: the contained
4744
+ // set is then the convex rounded rect, so four inside corners mean every
4745
+ // sample is inside, and a box wholly in one corner's quadrant whose nearest
4746
+ // point lies outside that ellipse has every sample outside. The margins
4747
+ // dwarf the float rounding of the per-sample test; anything closer than
4748
+ // that is left to it.
4749
+ struct RoundedRectPixelClassifier
4750
+ {
4751
+ bool valid = false;
4752
+ bool empty = false;
4753
+ float left = 0, top = 0, right = 0, bottom = 0;
4754
+ float cx[4]{}, cy[4]{}, irx[4]{}, iry[4]{};
4755
+ bool rounded[4]{};
4756
+
4757
+ explicit RoundedRectPixelClassifier(const TransformedRoundedRectCommand &r)
4758
+ {
4759
+ if (r.lw <= 0 || r.lh <= 0)
4760
+ {
4761
+ valid = true;
4762
+ empty = true;
4763
+ return;
4764
+ }
4765
+ left = static_cast<float>(r.lx);
4766
+ top = static_cast<float>(r.ly);
4767
+ right = left + static_cast<float>(r.lw);
4768
+ bottom = top + static_cast<float>(r.lh);
4769
+ const int rx8[4] = {std::max(0, int(r.tlRx8)), std::max(0, int(r.trRx8)), std::max(0, int(r.brRx8)), std::max(0, int(r.blRx8))};
4770
+ const int ry8[4] = {std::max(0, int(r.tlRy8)), std::max(0, int(r.trRy8)), std::max(0, int(r.brRy8)), std::max(0, int(r.blRy8))};
4771
+ if (rx8[0] + rx8[1] > 8 * r.lw || rx8[3] + rx8[2] > 8 * r.lw ||
4772
+ ry8[0] + ry8[3] > 8 * r.lh || ry8[1] + ry8[2] > 8 * r.lh)
4773
+ return;
4774
+ for (int k = 0; k < 4; ++k)
4775
+ {
4776
+ rounded[k] = rx8[k] > 0 && ry8[k] > 0;
4777
+ if (!rounded[k])
4778
+ continue;
4779
+ // Below 2px the normalized margins shrink toward float error.
4780
+ if (rx8[k] < 16 || ry8[k] < 16)
4781
+ return;
4782
+ const float rx = rx8[k] * 0.125f, ry = ry8[k] * 0.125f;
4783
+ cx[k] = (k == 0 || k == 3) ? left + rx : right - rx;
4784
+ cy[k] = (k == 0 || k == 1) ? top + ry : bottom - ry;
4785
+ irx[k] = 1.0f / rx;
4786
+ iry[k] = 1.0f / ry;
4787
+ }
4788
+ valid = true;
4789
+ }
4790
+
4791
+ // The corner quadrant a point lies in: the region where the per-sample
4792
+ // test consults that ellipse.
4793
+ bool inQuadrant(int k, float px, float py, float m) const
4794
+ {
4795
+ const bool xSide = (k == 0 || k == 3) ? px < cx[k] - m : px > cx[k] + m;
4796
+ const bool ySide = (k == 0 || k == 1) ? py < cy[k] - m : py > cy[k] + m;
4797
+ return xSide && ySide;
4798
+ }
4799
+
4800
+ bool pointSurelyInside(float px, float py) const
4801
+ {
4802
+ const float m = 1e-3f;
4803
+ if (px < left + m || py < top + m || px >= right - m || py >= bottom - m)
4804
+ return false;
4805
+ for (int k = 0; k < 4; ++k)
4806
+ {
4807
+ if (!rounded[k])
4808
+ continue;
4809
+ const bool nearX = (k == 0 || k == 3) ? px < cx[k] + m : px > cx[k] - m;
4810
+ const bool nearY = (k == 0 || k == 1) ? py < cy[k] + m : py > cy[k] - m;
4811
+ if (!nearX || !nearY)
4812
+ continue;
4813
+ const float dx = (px - cx[k]) * irx[k], dy = (py - cy[k]) * iry[k];
4814
+ if (dx * dx + dy * dy > 1.0f - 1e-3f)
4815
+ return false;
4816
+ }
4817
+ return true;
4818
+ }
4819
+
4820
+ // 1: every sample inside, -1: every sample outside, 0: undecided.
4821
+ int box(float x0, float y0, float x1, float y1) const
4822
+ {
4823
+ if (empty)
4824
+ return -1;
4825
+ const float m = 1e-3f;
4826
+ if (x1 < left - m || y1 < top - m || x0 >= right + m || y0 >= bottom + m)
4827
+ return -1;
4828
+ for (int k = 0; k < 4; ++k)
4829
+ {
4830
+ if (!rounded[k])
4831
+ continue;
4832
+ const float nx = (k == 0 || k == 3) ? x1 : x0;
4833
+ const float ny = (k == 0 || k == 1) ? y1 : y0;
4834
+ if (!inQuadrant(k, nx, ny, m))
4835
+ continue;
4836
+ const float dx = (nx - cx[k]) * irx[k], dy = (ny - cy[k]) * iry[k];
4837
+ if (dx * dx + dy * dy > 1.0f + 1e-3f)
4838
+ return -1;
4839
+ }
4840
+ if (pointSurelyInside(x0, y0) && pointSurelyInside(x1, y0) &&
4841
+ pointSurelyInside(x0, y1) && pointSurelyInside(x1, y1))
4842
+ return 1;
4843
+ return 0;
4844
+ }
4845
+ };
4846
+
4598
4847
  int cssRoundedBorderCoverage(const TransformedRoundedRectCommand &outer,
4599
4848
  const TransformedRoundedRectCommand &inner,
4600
4849
  int x, int y, int samples)
@@ -4614,6 +4863,11 @@ int gLastScrollUiFrame = -1000;
4614
4863
  if (!canvas || !canvas->pixels() || s.w <= 0 || s.h <= 0 || s.lineWidth <= 0) return;
4615
4864
  TransformedRoundedRectCommand outer{}, inner{};
4616
4865
  cssRoundedBorderContours(s, outer, inner);
4866
+ // A circular 2px ring is all corner box: every pixel ran 2 x 16
4867
+ // containment tests (3.5 ms for an 88px ring on the S31). Settle whole
4868
+ // pixels first; only the ones a contour crosses are sampled.
4869
+ const RoundedRectPixelClassifier outerClass(outer), innerClass(inner);
4870
+ const bool classify = outerClass.valid && innerClass.valid;
4617
4871
  int x0, y0, x1, y1;
4618
4872
  gea::platform::display::Display::clip(&x0, &y0, &x1, &y1);
4619
4873
  x0 = std::max({x0, 0, int(s.x)}); y0 = std::max({y0, 0, int(s.y)});
@@ -4624,11 +4878,53 @@ int gLastScrollUiFrame = -1000;
4624
4878
  const int alpha = gea::platform::display::Display::alpha();
4625
4879
  if (!alpha) return;
4626
4880
  const int stride = canvas->strideBytes() / sizeof(gea::framework::graphics::pixel::native_t);
4881
+ const int full = samples * samples;
4882
+ // Only the corner boxes need sampling. Outside them both contours are
4883
+ // plain rectangles (the inner corners lie inside the outer corner
4884
+ // boxes), so a pixel is fully covered when it is outside the inner
4885
+ // rectangle and uncovered inside it -- exactly what sampling would
4886
+ // give. Rows between the corners only touch the two side bands.
4887
+ const int radiusX = (std::max({s.rx8[0], s.rx8[1], s.rx8[2], s.rx8[3]}) + 7) / 8;
4888
+ const int radiusY = (std::max({s.ry8[0], s.ry8[1], s.ry8[2], s.ry8[3]}) + 7) / 8;
4889
+ const int cornerX0 = s.x + radiusX, cornerX1 = s.x + s.w - radiusX;
4890
+ const int cornerY0 = s.y + radiusY, cornerY1 = s.y + s.h - radiusY;
4891
+ const int innerX0 = s.x + s.lineWidth, innerX1 = s.x + s.w - s.lineWidth;
4892
+ const int innerY0 = s.y + s.lineWidth, innerY1 = s.y + s.h - s.lineWidth;
4627
4893
  for (int y = y0; y <= y1; ++y) {
4628
4894
  auto *row = canvas->pixels() + canvas->rowToPhysical(y) * stride;
4895
+ const bool cornerRow = y < cornerY0 || y >= cornerY1;
4896
+ const bool innerRow = y >= innerY0 && y < innerY1;
4897
+ if (!cornerRow && innerRow) {
4898
+ for (int x = x0; x <= std::min(x1, innerX0 - 1); ++x) paintCoveragePixel(row[x], s.color, alpha, full, full);
4899
+ for (int x = std::max(x0, innerX1); x <= x1; ++x) paintCoveragePixel(row[x], s.color, alpha, full, full);
4900
+ continue;
4901
+ }
4629
4902
  for (int x = x0; x <= x1; ++x) {
4630
- const int coverage = cssRoundedBorderCoverage(outer, inner, x, y, samples);
4631
- if (coverage) paintCoveragePixel(row[x], s.color, alpha, coverage, samples * samples);
4903
+ int coverage;
4904
+ if (cornerRow && (x < cornerX0 || x >= cornerX1))
4905
+ {
4906
+ int decided = -1;
4907
+ if (classify)
4908
+ {
4909
+ const float o0 = 0.5f / samples, o1 = 1.0f - o0;
4910
+ const float bx0 = x + o0, by0 = y + o0, bx1 = x + o1, by1 = y + o1;
4911
+ const int out = outerClass.box(bx0, by0, bx1, by1);
4912
+ if (out < 0)
4913
+ decided = 0;
4914
+ else
4915
+ {
4916
+ const int in = innerClass.box(bx0, by0, bx1, by1);
4917
+ if (in > 0)
4918
+ decided = 0;
4919
+ else if (out > 0 && in < 0)
4920
+ decided = full;
4921
+ }
4922
+ }
4923
+ coverage = decided >= 0 ? decided : cssRoundedBorderCoverage(outer, inner, x, y, samples);
4924
+ }
4925
+ else
4926
+ coverage = innerRow && x >= innerX0 && x < innerX1 ? 0 : full;
4927
+ if (coverage) paintCoveragePixel(row[x], s.color, alpha, coverage, full);
4632
4928
  }
4633
4929
  }
4634
4930
  canvas->markDirty(x0, y0, x1, y1);
@@ -7911,7 +8207,7 @@ int gLastScrollUiFrame = -1000;
7911
8207
  constexpr int kMinPixelsToSplitFrame = GEA_EMBEDDED_RENDER_PARALLEL_MIN_PIXELS;
7912
8208
  const int regionW = x1 - x0 + 1;
7913
8209
  const int regionH = y1 - y0 + 1;
7914
- if (GEA_EMBEDDED_RENDER_PARALLEL_DIRTY_REPLAY && allowSplit && regionW > 0 && regionH >= kMinRowsToSplitFrame &&
8210
+ if (GEA_EMBEDDED_RENDER_PARALLEL_DIRTY_REPLAY && GEA_RENDER_SPLIT_ALLOWED && allowSplit && regionW > 0 && regionH >= kMinRowsToSplitFrame &&
7915
8211
  regionW * regionH >= kMinPixelsToSplitFrame)
7916
8212
  {
7917
8213
  int mainRows = (regionH * gea_render_parallel_main_share_permille()) / 1000;
@@ -8285,7 +8581,7 @@ int gLastScrollUiFrame = -1000;
8285
8581
  constexpr int kMinPixelsToSplitFrame = GEA_EMBEDDED_RENDER_PARALLEL_MIN_PIXELS;
8286
8582
  const int regionW = x1 - x0 + 1;
8287
8583
  const int regionH = y1 - y0 + 1;
8288
- if (GEA_EMBEDDED_RENDER_PARALLEL_DIRTY_REPLAY && allowSplit && regionW > 0 && regionH >= kMinRowsToSplitFrame &&
8584
+ if (GEA_EMBEDDED_RENDER_PARALLEL_DIRTY_REPLAY && GEA_RENDER_SPLIT_ALLOWED && allowSplit && regionW > 0 && regionH >= kMinRowsToSplitFrame &&
8289
8585
  regionW * regionH >= kMinPixelsToSplitFrame)
8290
8586
  {
8291
8587
  int mainRows = (regionH * gea_render_parallel_main_share_permille()) / 1000;
@@ -8433,17 +8729,23 @@ int gLastScrollUiFrame = -1000;
8433
8729
  gea::platform::display::Display::fillRect(x0, y0, x1 - x0 + 1, y1 - y0 + 1, base);
8434
8730
  }
8435
8731
 
8436
- // Painter's-algorithm occlusion cull: the LAST node (in draw order) whose
8437
- // first command is an opaque fill or image covering the region occludes
8438
- // everything drawn before it — the replay walk can start there. A page-sized
8439
- // UI (e-reader page turn) stacks several full-bleed paper fills under the
8440
- // content; each is a full PSRAM write of the region, so skipping the covered
8441
- // ones removes ~100 ms/turn on a 540×960 GRAY4 panel. Conservative: the
8442
- // cover must be untransformed, at full effective alpha,
8443
- // its node's first command, never blinking, and not shrunk by any ancestor
8444
- // overflow clip smaller than the region.
8732
+ // Painter's-algorithm occlusion cull: the LAST node (in draw order) from
8733
+ // which the opaque fills or images that open the nodes drawn from there on
8734
+ // cover the region together occludes everything drawn before it — the
8735
+ // replay walk can start there. A page-sized UI (e-reader page turn) stacks
8736
+ // several full-bleed paper fills under the content; each is a full PSRAM
8737
+ // write of the region, so skipping the covered ones removes ~100 ms/turn on
8738
+ // a 540×960 GRAY4 panel. A carousel mid-slide shows two side-by-side
8739
+ // full-height images over a page background that neither covers alone but
8740
+ // both do together. Conservative: a cover must span the region's full
8741
+ // height, be untransformed, at full effective alpha, its node's first
8742
+ // command, never blinking, and is narrowed to every ancestor overflow clip.
8445
8743
  static int GEA_RENDER_HOT_SRAM occlusionCullStartIndex(int x0, int y0, int x1, int y1, Node *nodes, int nodeCount)
8446
8744
  {
8745
+ constexpr int kMaxCovers = 8;
8746
+ int coverX0[kMaxCovers];
8747
+ int coverX1[kMaxCovers];
8748
+ int coverCount = 0;
8447
8749
  for (int oi = state.drawNodeOrderCount - 1; oi > 0; --oi)
8448
8750
  {
8449
8751
  const int node_id = state.drawNodeOrder[oi];
@@ -8456,22 +8758,42 @@ int gLastScrollUiFrame = -1000;
8456
8758
  if (start < 0 || end <= start || end > state.commandCount)
8457
8759
  continue;
8458
8760
  const DisplayCommand &c = state.commands[start];
8459
- bool covers = false;
8761
+ int spanX0 = 0;
8762
+ int spanX1 = -1;
8460
8763
  if (c.type == DisplayCommandType::FillRect)
8461
- covers = c.fill.x <= x0 && c.fill.y <= y0 &&
8462
- c.fill.x + c.fill.w - 1 >= x1 && c.fill.y + c.fill.h - 1 >= y1;
8764
+ {
8765
+ if (c.fill.y <= y0 && c.fill.y + c.fill.h - 1 >= y1)
8766
+ {
8767
+ spanX0 = c.fill.x;
8768
+ spanX1 = c.fill.x + c.fill.w - 1;
8769
+ }
8770
+ }
8463
8771
  else if (c.type == DisplayCommandType::BlitImage)
8464
- covers = c.blit.pixels && !c.blit.alpha &&
8465
- c.blit.dx <= x0 && c.blit.dy <= y0 &&
8466
- c.blit.dx + c.blit.sourceWidth - 1 >= x1 &&
8467
- c.blit.dy + c.blit.sourceHeight - 1 >= y1;
8468
- if (!covers || c.textClipOwner >= 0)
8772
+ {
8773
+ if (c.blit.pixels && !c.blit.alpha && c.blit.dy <= y0 &&
8774
+ c.blit.dy + c.blit.sourceHeight - 1 >= y1)
8775
+ {
8776
+ spanX0 = c.blit.dx;
8777
+ spanX1 = c.blit.dx + c.blit.sourceWidth - 1;
8778
+ }
8779
+ }
8780
+ if (spanX0 < x0)
8781
+ spanX0 = x0;
8782
+ if (spanX1 > x1)
8783
+ spanX1 = x1;
8784
+ if (spanX0 > spanX1 || c.textClipOwner >= 0)
8469
8785
  continue;
8470
- // The recorded paint bbox must also cover the region (guards against
8786
+ // The recorded paint bbox must also cover the span (guards against
8471
8787
  // any recording that paints less than the command rect suggests).
8472
- if (c.bx > x0 || c.by > y0 || c.bx + c.bw - 1 < x1 || c.by + c.bh - 1 < y1)
8788
+ if (c.by > y0 || c.by + c.bh - 1 < y1)
8789
+ continue;
8790
+ if (spanX0 < c.bx)
8791
+ spanX0 = c.bx;
8792
+ if (spanX1 > c.bx + c.bw - 1)
8793
+ spanX1 = c.bx + c.bw - 1;
8794
+ if (spanX0 > spanX1)
8473
8795
  continue;
8474
- // Read node state only for a command large enough to cover the region.
8796
+ // Read node state only for a command that covers part of the region.
8475
8797
  Node *n = &nodes[node_id];
8476
8798
  if (n->computedStyle().display == 1)
8477
8799
  continue;
@@ -8485,9 +8807,16 @@ int gLastScrollUiFrame = -1000;
8485
8807
  if (!nodeRecordsOverflowClip(cursor, nodes, nodeCount))
8486
8808
  continue;
8487
8809
  const Node &clip = nodes[cursor];
8488
- if (clip.layout.x > x0 || clip.layout.y > y0 ||
8489
- clip.layout.x + clip.layout.width - 1 < x1 ||
8490
- clip.layout.y + clip.layout.height - 1 < y1)
8810
+ if (clip.layout.y > y0 || clip.layout.y + clip.layout.height - 1 < y1)
8811
+ {
8812
+ clipped = true;
8813
+ break;
8814
+ }
8815
+ if (spanX0 < clip.layout.x)
8816
+ spanX0 = clip.layout.x;
8817
+ if (spanX1 > clip.layout.x + clip.layout.width - 1)
8818
+ spanX1 = clip.layout.x + clip.layout.width - 1;
8819
+ if (spanX0 > spanX1)
8491
8820
  {
8492
8821
  clipped = true;
8493
8822
  break;
@@ -8495,7 +8824,29 @@ int gLastScrollUiFrame = -1000;
8495
8824
  }
8496
8825
  if (clipped)
8497
8826
  continue;
8498
- return oi;
8827
+ if (spanX0 == x0 && spanX1 == x1)
8828
+ return oi;
8829
+ if (coverCount == kMaxCovers)
8830
+ return 0;
8831
+ coverX0[coverCount] = spanX0;
8832
+ coverX1[coverCount] = spanX1;
8833
+ ++coverCount;
8834
+ // Covered when [x0, x1] can be walked left to right through the spans.
8835
+ int reach = x0;
8836
+ for (bool advanced = true; advanced && reach <= x1;)
8837
+ {
8838
+ advanced = false;
8839
+ for (int i = 0; i < coverCount; ++i)
8840
+ {
8841
+ if (coverX0[i] <= reach && coverX1[i] >= reach)
8842
+ {
8843
+ reach = coverX1[i] + 1;
8844
+ advanced = true;
8845
+ }
8846
+ }
8847
+ }
8848
+ if (reach > x1)
8849
+ return oi;
8499
8850
  }
8500
8851
  return 0;
8501
8852
  }
@@ -8801,7 +9152,7 @@ int gLastScrollUiFrame = -1000;
8801
9152
  constexpr int kMaxSplitRegions = 32;
8802
9153
  constexpr int kMinRowsToSplitFrame = GEA_EMBEDDED_RENDER_PARALLEL_MIN_ROWS;
8803
9154
  constexpr int kMinPixelsToSplitFrame = GEA_EMBEDDED_RENDER_PARALLEL_MIN_PIXELS;
8804
- if (GEA_EMBEDDED_RENDER_PARALLEL_DIRTY_REPLAY && allowSplit && count <= kMaxSplitRegions)
9155
+ if (GEA_EMBEDDED_RENDER_PARALLEL_DIRTY_REPLAY && GEA_RENDER_SPLIT_ALLOWED && allowSplit && count <= kMaxSplitRegions)
8805
9156
  {
8806
9157
  int minY = 0x7fffffff, maxY = -0x7fffffff;
8807
9158
  int totalArea = 0;
@@ -9,6 +9,14 @@
9
9
  #include <string>
10
10
  #include <string_view>
11
11
 
12
+ // Framebuffer-free retained rendering: each dirty band is rasterized into the
13
+ // display's internal-RAM DMA chunk and streamed to the panel while the next
14
+ // band renders (tree_render.cpp). A board capability, set by the target's
15
+ // CMake; off everywhere else, where it compiles out entirely.
16
+ #ifndef GEA_EMBEDDED_DISPLAY_BANDED_UI
17
+ #define GEA_EMBEDDED_DISPLAY_BANDED_UI 0
18
+ #endif
19
+
12
20
  namespace gea::embedded::ui {
13
21
 
14
22
  class Tree {
@@ -207,4 +215,17 @@ void releaseRareData(int node); // frees the block back to the pool
207
215
  // Caller must hold AppState::lock(). Returns false for canvas/present apps.
208
216
  bool renderRetainedSnapshotRgb565(std::uint16_t *dst, int width, int height);
209
217
 
218
+ #if GEA_EMBEDDED_DISPLAY_BANDED_UI
219
+ // Banded UI mode: the retained tree renders each dirty band straight into the
220
+ // display's DMA staging buffers, so the PSRAM framebuffer does not hold the
221
+ // frame on the panel. True once a banded frame has been presented (until a
222
+ // full repaint into the framebuffer makes it current again) — a screenshot
223
+ // must then re-render instead of copying the framebuffer.
224
+ bool retainedFramebufferStale();
225
+ // Set while a banded raster callback replays into a staging chunk. The 2-core
226
+ // replay split must not engage then: the worker core's canvas is bound to the
227
+ // framebuffer, not to the chunk.
228
+ extern bool gBandedRasterActive;
229
+ #endif
230
+
210
231
  } // namespace gea::embedded::ui
package/ui/tree_nodes.cpp CHANGED
@@ -480,8 +480,11 @@ void Tree::markCanvasDirty(int id)
480
480
  if (id < 0 || id >= state.nodeCount) return;
481
481
  const auto *surface = state.canvases.find(id);
482
482
  if (surface && surface->displayBacked()) return;
483
+ // Pixels only: drawing never changes the element's box, so no layout_dirty.
484
+ // It used to be set here, and a canvas redrawn every frame (Ember's heat
485
+ // arc) then cost a full relayout of the whole screen per frame (~5.5 ms of
486
+ // 163 layout calls on the S31) for a box that never moved.
483
487
  state.nodes[id].render.dirty = 1;
484
- state.nodes[id].render.layout_dirty = 1;
485
488
  #if GEA_CSS_SCROLLING
486
489
  state.nodes[id].render.non_scroll_dirty = 1;
487
490
  #endif