@geastack/engine 0.1.14 → 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/canvas.cpp +375 -66
- package/image_store.cpp +15 -0
- package/package.json +2 -2
- package/ui/canvas_element.cpp +334 -261
- package/ui/canvas_element.h +56 -33
- package/ui/layout.cpp +6 -2
- package/ui/render.cpp +372 -31
- package/ui/tree_nodes.cpp +4 -1
- package/ui/tree_render.cpp +20 -1
- package/ui/view.cpp +14 -0
package/ui/canvas_element.h
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
2
|
#pragma once
|
|
3
3
|
|
|
4
|
+
#include <memory>
|
|
5
|
+
|
|
4
6
|
#include "canvas.h"
|
|
5
7
|
#include "node.h"
|
|
6
8
|
|
|
@@ -87,6 +89,45 @@ void canvasPerfStatsReset();
|
|
|
87
89
|
CanvasPerfStats canvasPerfStatsRead();
|
|
88
90
|
void canvasTotalsRead(int *begin, int *end, int *fillRect, int *drawImage, int *nullPixels, int *presentOk);
|
|
89
91
|
|
|
92
|
+
// Everything a 2D context carries between calls: the open batch and its
|
|
93
|
+
// recorded commands, styles, the current path. One per canvas, shared by every
|
|
94
|
+
// CanvasRenderingContext2D for it -- `getContext('2d')` hands back the same
|
|
95
|
+
// object each time, so a context passed to a helper (a by-value copy in
|
|
96
|
+
// generated code) must draw into, and style, the same batch as the original.
|
|
97
|
+
struct CanvasContextState {
|
|
98
|
+
gea::framework::graphics::Canvas *batchCanvas_ = nullptr;
|
|
99
|
+
std::vector<CanvasPresentCommand> presentCommands_;
|
|
100
|
+
std::size_t presentCommandCount_ = 0;
|
|
101
|
+
gea::framework::graphics::pixel::native_t fillStyle_ = gea::framework::graphics::pixel::nativeColor(255, 255, 255);
|
|
102
|
+
gea::framework::graphics::pixel::native_t strokeStyle_ = gea::framework::graphics::pixel::nativeColor(255, 255, 255);
|
|
103
|
+
std::string fillStyleSource_;
|
|
104
|
+
std::string strokeStyleSource_;
|
|
105
|
+
double arcX_ = 0.0;
|
|
106
|
+
double arcY_ = 0.0;
|
|
107
|
+
double arcRadius_ = 0.0;
|
|
108
|
+
std::vector<double> pathX_;
|
|
109
|
+
std::vector<double> pathY_;
|
|
110
|
+
// Start index in pathX_/pathY_ of each subpath (one per moveTo), so a path
|
|
111
|
+
// can hold MULTIPLE rings/contours — required for concave polygons with
|
|
112
|
+
// holes (even-odd fill) and multi-part strokes.
|
|
113
|
+
std::vector<int> pathStarts_;
|
|
114
|
+
double lineWidth_ = 1.0;
|
|
115
|
+
float fontScale_ = 1.0f;
|
|
116
|
+
int fontFamilyId_ = -1;
|
|
117
|
+
int fontSizePx_ = 16;
|
|
118
|
+
// Cache the last CSS font string so setFont can skip the parse + FontRegistry
|
|
119
|
+
// lookups when an app re-sets the same font every frame (e.g. an FPS readout).
|
|
120
|
+
std::string lastFontStr_;
|
|
121
|
+
std::uint8_t globalAlpha_ = 255;
|
|
122
|
+
int batchDepth_ = 0;
|
|
123
|
+
bool fillStyleCached_ = false;
|
|
124
|
+
bool strokeStyleCached_ = false;
|
|
125
|
+
bool hasArc_ = false;
|
|
126
|
+
bool pathClosed_ = false;
|
|
127
|
+
bool presentRecording_ = false;
|
|
128
|
+
bool batchDirty_ = false;
|
|
129
|
+
};
|
|
130
|
+
|
|
90
131
|
class CanvasRenderingContext2D {
|
|
91
132
|
public:
|
|
92
133
|
// A non-explicit default ctor is required so this type can be a by-value
|
|
@@ -95,8 +136,12 @@ public:
|
|
|
95
136
|
// which copy-`{}`-initializes each field — and copy-init cannot select an
|
|
96
137
|
// `explicit` constructor. `explicit` is kept on the int form so a bare
|
|
97
138
|
// `int` still can't implicitly convert to a context.
|
|
98
|
-
CanvasRenderingContext2D() : nodeId_(-1) {}
|
|
99
|
-
explicit CanvasRenderingContext2D(int nodeId) : nodeId_(nodeId) {}
|
|
139
|
+
CanvasRenderingContext2D() : nodeId_(-1), state_(stateFor(-1)) {}
|
|
140
|
+
explicit CanvasRenderingContext2D(int nodeId) : nodeId_(nodeId), state_(stateFor(nodeId)) {}
|
|
141
|
+
// The shared state of canvas `nodeId`; -1 is the direct-canvas display.
|
|
142
|
+
static std::shared_ptr<CanvasContextState> stateFor(int nodeId);
|
|
143
|
+
// Drops canvas `nodeId`'s state, so a node id reused later starts clean.
|
|
144
|
+
static void releaseState(int nodeId);
|
|
100
145
|
|
|
101
146
|
bool valid() const { return nodeId_ >= 0; }
|
|
102
147
|
// The absence state `valid()` already answers, in the spelling a test uses.
|
|
@@ -197,6 +242,14 @@ public:
|
|
|
197
242
|
void fillText(const std::string &text, int x, int y);
|
|
198
243
|
void fillText(const std::string &text, double x, double y);
|
|
199
244
|
void drawImage(int imageId, int dx, int dy);
|
|
245
|
+
// drawImage at full opacity whatever globalAlpha is: putImageData.
|
|
246
|
+
void putImage(int imageId, int dx, int dy);
|
|
247
|
+
// Draws `height` rows of `width` opaque pixels, row r read from
|
|
248
|
+
// `pixels + r * stride`, at (dx, dy). The rows must stay valid until the
|
|
249
|
+
// frame is presented: they are recorded, not copied. This is a sub-rectangle
|
|
250
|
+
// of a larger buffer -- putImageData's dirty rectangle -- without a copy.
|
|
251
|
+
// Like putImageData, it ignores globalAlpha.
|
|
252
|
+
void drawPixelRows(const gea::framework::graphics::pixel::native_t *pixels, int stride, int width, int height, int dx, int dy);
|
|
200
253
|
void drawImage(int imageId, double dx, double dy);
|
|
201
254
|
void drawImage(int imageId, int dx, int dy, int dw, int dh);
|
|
202
255
|
void drawImage(int imageId, double dx, double dy, double dw, double dh);
|
|
@@ -310,37 +363,7 @@ private:
|
|
|
310
363
|
void markDrawDirty();
|
|
311
364
|
|
|
312
365
|
int nodeId_;
|
|
313
|
-
|
|
314
|
-
std::vector<CanvasPresentCommand> presentCommands_;
|
|
315
|
-
std::size_t presentCommandCount_ = 0;
|
|
316
|
-
gea::framework::graphics::pixel::native_t fillStyle_ = gea::framework::graphics::pixel::nativeColor(255, 255, 255);
|
|
317
|
-
gea::framework::graphics::pixel::native_t strokeStyle_ = gea::framework::graphics::pixel::nativeColor(255, 255, 255);
|
|
318
|
-
std::string fillStyleSource_;
|
|
319
|
-
std::string strokeStyleSource_;
|
|
320
|
-
double arcX_ = 0.0;
|
|
321
|
-
double arcY_ = 0.0;
|
|
322
|
-
double arcRadius_ = 0.0;
|
|
323
|
-
std::vector<double> pathX_;
|
|
324
|
-
std::vector<double> pathY_;
|
|
325
|
-
// Start index in pathX_/pathY_ of each subpath (one per moveTo), so a path
|
|
326
|
-
// can hold MULTIPLE rings/contours — required for concave polygons with
|
|
327
|
-
// holes (even-odd fill) and multi-part strokes.
|
|
328
|
-
std::vector<int> pathStarts_;
|
|
329
|
-
double lineWidth_ = 1.0;
|
|
330
|
-
float fontScale_ = 1.0f;
|
|
331
|
-
int fontFamilyId_ = -1;
|
|
332
|
-
int fontSizePx_ = 16;
|
|
333
|
-
// Cache the last CSS font string so setFont can skip the parse + FontRegistry
|
|
334
|
-
// lookups when an app re-sets the same font every frame (e.g. an FPS readout).
|
|
335
|
-
std::string lastFontStr_;
|
|
336
|
-
std::uint8_t globalAlpha_ = 255;
|
|
337
|
-
int batchDepth_ = 0;
|
|
338
|
-
bool fillStyleCached_ = false;
|
|
339
|
-
bool strokeStyleCached_ = false;
|
|
340
|
-
bool hasArc_ = false;
|
|
341
|
-
bool pathClosed_ = false;
|
|
342
|
-
bool presentRecording_ = false;
|
|
343
|
-
bool batchDirty_ = false;
|
|
366
|
+
std::shared_ptr<CanvasContextState> state_;
|
|
344
367
|
};
|
|
345
368
|
|
|
346
369
|
class CanvasElement : public NodeHandle {
|
package/ui/layout.cpp
CHANGED
|
@@ -4293,14 +4293,18 @@ bool LayoutEngine::layoutNodeScoped(int scope, int treeRoot)
|
|
|
4293
4293
|
|
|
4294
4294
|
// Absolute descendants positioned against a containing block OUTSIDE the
|
|
4295
4295
|
// scope mix coordinate spaces (the global containing-block pass runs in
|
|
4296
|
-
// pre-resolve relative space) — those trees must take the full path.
|
|
4296
|
+
// pre-resolve relative space) — those trees must take the full path. The
|
|
4297
|
+
// scope itself is exempt: its own position is restored below, never
|
|
4298
|
+
// recomputed, and a size change is rejected by the dims check. Testing it
|
|
4299
|
+
// here refused every absolutely placed scope (Ember's temperature readout,
|
|
4300
|
+
// then its screen), so each tick of a number fell back to a full relayout.
|
|
4297
4301
|
for (int i = 0; i < nodeCount; ++i) {
|
|
4298
4302
|
const Node &n = nodes[i];
|
|
4303
|
+
if (i == scope) continue;
|
|
4299
4304
|
if (n.parent < 0 || !isOutOfFlowPosition(n.computedStyle().position) || isDisplayNone(n.computedStyle())) continue;
|
|
4300
4305
|
if (!inScope(i)) continue;
|
|
4301
4306
|
const int containing = containingBlockForAbsoluteNode(i, treeRoot, nodes);
|
|
4302
4307
|
if (containing >= 0 && !inScope(containing)) {
|
|
4303
|
-
GEA_REFRESH_PERF(refreshPerfStatsMutable().treeScopedRejectReason = 3);
|
|
4304
4308
|
GEA_REFRESH_PERF(refreshPerfStatsMutable().treeScopedRejectNode = i);
|
|
4305
4309
|
return false;
|
|
4306
4310
|
}
|
package/ui/render.cpp
CHANGED
|
@@ -1588,6 +1588,25 @@ int gLastScrollUiFrame = -1000;
|
|
|
1588
1588
|
out->brRy8 = scaleRadius8(r.brRy8, scaleY);
|
|
1589
1589
|
out->blRx8 = scaleRadius8(r.blRx8, scaleX);
|
|
1590
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);
|
|
1591
1610
|
return true;
|
|
1592
1611
|
}
|
|
1593
1612
|
|
|
@@ -1827,13 +1846,46 @@ int gLastScrollUiFrame = -1000;
|
|
|
1827
1846
|
|
|
1828
1847
|
int fillQuadCoverage(const int *xs, const int *ys, int x, int y, int samples)
|
|
1829
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);
|
|
1830
1882
|
int coverage = 0;
|
|
1831
1883
|
for (int iy = 0; iy < samples; ++iy)
|
|
1832
1884
|
{
|
|
1833
|
-
const float oy = antialiasOffset(iy, samples);
|
|
1885
|
+
const float oy = iy < 16 ? offsets[iy] : antialiasOffset(iy, samples);
|
|
1834
1886
|
for (int ix = 0; ix < samples; ++ix)
|
|
1835
1887
|
{
|
|
1836
|
-
const float ox = antialiasOffset(ix, samples);
|
|
1888
|
+
const float ox = ix < 16 ? offsets[ix] : antialiasOffset(ix, samples);
|
|
1837
1889
|
if (convexQuadContainsFast(xs, ys, static_cast<float>(x) + ox, static_cast<float>(y) + oy))
|
|
1838
1890
|
++coverage;
|
|
1839
1891
|
}
|
|
@@ -1841,6 +1893,87 @@ int gLastScrollUiFrame = -1000;
|
|
|
1841
1893
|
return coverage;
|
|
1842
1894
|
}
|
|
1843
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
|
+
|
|
1844
1977
|
int combinedCoverageAlpha(int alpha, int coverage, int sampleCount)
|
|
1845
1978
|
{
|
|
1846
1979
|
if (coverage <= 0 || alpha <= 0)
|
|
@@ -4218,6 +4351,7 @@ int gLastScrollUiFrame = -1000;
|
|
|
4218
4351
|
const int coverageArea = (drawXMax - drawXMin + 1) * (drawY1 - drawY0 + 1);
|
|
4219
4352
|
const int aaSamples = gea::framework::graphics::Canvas::antialiasSamples();
|
|
4220
4353
|
const int aaSampleCount = aaSamples * aaSamples;
|
|
4354
|
+
const QuadCoverage quadCoverage(xs, ys, aaSamples, drawXMin, drawY0, drawXMax, drawY1);
|
|
4221
4355
|
if (aaSamples >= 2 && drawXMin <= drawXMax && coverageArea > 0 && coverageArea <= kAntialiasFullCoverageAreaLimit)
|
|
4222
4356
|
{
|
|
4223
4357
|
int dirtyX0 = canvas->width();
|
|
@@ -4229,7 +4363,7 @@ int gLastScrollUiFrame = -1000;
|
|
|
4229
4363
|
gea::framework::graphics::pixel::native_t *row = canvas->pixels() + canvas->rowToPhysical(y) * stride;
|
|
4230
4364
|
for (int x = drawXMin; x <= drawXMax; ++x)
|
|
4231
4365
|
{
|
|
4232
|
-
const int coverage =
|
|
4366
|
+
const int coverage = quadCoverage.at(x, y);
|
|
4233
4367
|
if (coverage <= 0)
|
|
4234
4368
|
continue;
|
|
4235
4369
|
paintCoveragePixel(row[x], command.quad.color, alpha, coverage, aaSampleCount);
|
|
@@ -4312,7 +4446,7 @@ int gLastScrollUiFrame = -1000;
|
|
|
4312
4446
|
|
|
4313
4447
|
for (int x = aaLX0; x <= aaLX1; x++)
|
|
4314
4448
|
{
|
|
4315
|
-
const int coverage =
|
|
4449
|
+
const int coverage = quadCoverage.at(x, y);
|
|
4316
4450
|
if (coverage > 0)
|
|
4317
4451
|
paintCoveragePixel(row[x], quadColor, alpha, coverage, aaSampleCount);
|
|
4318
4452
|
}
|
|
@@ -4333,7 +4467,7 @@ int gLastScrollUiFrame = -1000;
|
|
|
4333
4467
|
|
|
4334
4468
|
for (int x = aaRX0; x <= aaRX1; x++)
|
|
4335
4469
|
{
|
|
4336
|
-
const int coverage =
|
|
4470
|
+
const int coverage = quadCoverage.at(x, y);
|
|
4337
4471
|
if (coverage > 0)
|
|
4338
4472
|
paintCoveragePixel(row[x], quadColor, alpha, coverage, aaSampleCount);
|
|
4339
4473
|
}
|
|
@@ -4605,6 +4739,111 @@ int gLastScrollUiFrame = -1000;
|
|
|
4605
4739
|
inner.blRx8 = std::max(0, s.rx8[3] - 8 * s.lineWidth); inner.blRy8 = std::max(0, s.ry8[3] - 8 * s.lineWidth);
|
|
4606
4740
|
}
|
|
4607
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
|
+
|
|
4608
4847
|
int cssRoundedBorderCoverage(const TransformedRoundedRectCommand &outer,
|
|
4609
4848
|
const TransformedRoundedRectCommand &inner,
|
|
4610
4849
|
int x, int y, int samples)
|
|
@@ -4624,6 +4863,11 @@ int gLastScrollUiFrame = -1000;
|
|
|
4624
4863
|
if (!canvas || !canvas->pixels() || s.w <= 0 || s.h <= 0 || s.lineWidth <= 0) return;
|
|
4625
4864
|
TransformedRoundedRectCommand outer{}, inner{};
|
|
4626
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;
|
|
4627
4871
|
int x0, y0, x1, y1;
|
|
4628
4872
|
gea::platform::display::Display::clip(&x0, &y0, &x1, &y1);
|
|
4629
4873
|
x0 = std::max({x0, 0, int(s.x)}); y0 = std::max({y0, 0, int(s.y)});
|
|
@@ -4634,11 +4878,53 @@ int gLastScrollUiFrame = -1000;
|
|
|
4634
4878
|
const int alpha = gea::platform::display::Display::alpha();
|
|
4635
4879
|
if (!alpha) return;
|
|
4636
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;
|
|
4637
4893
|
for (int y = y0; y <= y1; ++y) {
|
|
4638
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
|
+
}
|
|
4639
4902
|
for (int x = x0; x <= x1; ++x) {
|
|
4640
|
-
|
|
4641
|
-
if (
|
|
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);
|
|
4642
4928
|
}
|
|
4643
4929
|
}
|
|
4644
4930
|
canvas->markDirty(x0, y0, x1, y1);
|
|
@@ -8443,17 +8729,23 @@ int gLastScrollUiFrame = -1000;
|
|
|
8443
8729
|
gea::platform::display::Display::fillRect(x0, y0, x1 - x0 + 1, y1 - y0 + 1, base);
|
|
8444
8730
|
}
|
|
8445
8731
|
|
|
8446
|
-
// Painter's-algorithm occlusion cull: the LAST node (in draw order)
|
|
8447
|
-
//
|
|
8448
|
-
// everything drawn before it — the
|
|
8449
|
-
// UI (e-reader page turn) stacks
|
|
8450
|
-
// content; each is a full PSRAM
|
|
8451
|
-
// ones removes ~100 ms/turn on
|
|
8452
|
-
//
|
|
8453
|
-
//
|
|
8454
|
-
//
|
|
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.
|
|
8455
8743
|
static int GEA_RENDER_HOT_SRAM occlusionCullStartIndex(int x0, int y0, int x1, int y1, Node *nodes, int nodeCount)
|
|
8456
8744
|
{
|
|
8745
|
+
constexpr int kMaxCovers = 8;
|
|
8746
|
+
int coverX0[kMaxCovers];
|
|
8747
|
+
int coverX1[kMaxCovers];
|
|
8748
|
+
int coverCount = 0;
|
|
8457
8749
|
for (int oi = state.drawNodeOrderCount - 1; oi > 0; --oi)
|
|
8458
8750
|
{
|
|
8459
8751
|
const int node_id = state.drawNodeOrder[oi];
|
|
@@ -8466,22 +8758,42 @@ int gLastScrollUiFrame = -1000;
|
|
|
8466
8758
|
if (start < 0 || end <= start || end > state.commandCount)
|
|
8467
8759
|
continue;
|
|
8468
8760
|
const DisplayCommand &c = state.commands[start];
|
|
8469
|
-
|
|
8761
|
+
int spanX0 = 0;
|
|
8762
|
+
int spanX1 = -1;
|
|
8470
8763
|
if (c.type == DisplayCommandType::FillRect)
|
|
8471
|
-
|
|
8472
|
-
|
|
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
|
+
}
|
|
8473
8771
|
else if (c.type == DisplayCommandType::BlitImage)
|
|
8474
|
-
|
|
8475
|
-
|
|
8476
|
-
|
|
8477
|
-
|
|
8478
|
-
|
|
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)
|
|
8479
8785
|
continue;
|
|
8480
|
-
// The recorded paint bbox must also cover the
|
|
8786
|
+
// The recorded paint bbox must also cover the span (guards against
|
|
8481
8787
|
// any recording that paints less than the command rect suggests).
|
|
8482
|
-
if (c.
|
|
8788
|
+
if (c.by > y0 || c.by + c.bh - 1 < y1)
|
|
8483
8789
|
continue;
|
|
8484
|
-
|
|
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)
|
|
8795
|
+
continue;
|
|
8796
|
+
// Read node state only for a command that covers part of the region.
|
|
8485
8797
|
Node *n = &nodes[node_id];
|
|
8486
8798
|
if (n->computedStyle().display == 1)
|
|
8487
8799
|
continue;
|
|
@@ -8495,9 +8807,16 @@ int gLastScrollUiFrame = -1000;
|
|
|
8495
8807
|
if (!nodeRecordsOverflowClip(cursor, nodes, nodeCount))
|
|
8496
8808
|
continue;
|
|
8497
8809
|
const Node &clip = nodes[cursor];
|
|
8498
|
-
if (clip.layout.
|
|
8499
|
-
|
|
8500
|
-
|
|
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)
|
|
8501
8820
|
{
|
|
8502
8821
|
clipped = true;
|
|
8503
8822
|
break;
|
|
@@ -8505,7 +8824,29 @@ int gLastScrollUiFrame = -1000;
|
|
|
8505
8824
|
}
|
|
8506
8825
|
if (clipped)
|
|
8507
8826
|
continue;
|
|
8508
|
-
|
|
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;
|
|
8509
8850
|
}
|
|
8510
8851
|
return 0;
|
|
8511
8852
|
}
|
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
|