@geastack/engine 0.1.20 → 0.1.21
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 +126 -27
- package/package.json +1 -1
- package/ui/CSS_FEATURES.md +51 -0
- package/ui/input.cpp +9 -0
- package/ui/internal.h +4 -1
- package/ui/node_features.h +6 -0
- package/ui/node_model.h +17 -1
- package/ui/render.cpp +28 -0
- package/ui/style.cpp +36 -0
- package/ui/style.h +18 -1
- package/ui/svg_element.h +95 -0
- package/ui/svg_element_impl.h +1150 -0
- package/ui/svg_geometry.h +1702 -0
- package/ui/tree_events.cpp +15 -0
- package/ui/tree_nodes.cpp +36 -2
- package/ui/tree_render.cpp +28 -0
- package/ui/tree_style.cpp +24 -0
package/canvas.cpp
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
|
|
9
9
|
#include <algorithm>
|
|
10
10
|
#include <atomic>
|
|
11
|
+
#include <climits>
|
|
11
12
|
#include <cmath>
|
|
12
13
|
#include <cstdio>
|
|
13
14
|
#include <cstdlib>
|
|
@@ -1347,6 +1348,87 @@ void Canvas::writePixelAlpha(int x, int y, pixel::native_t fg, std::uint8_t alph
|
|
|
1347
1348
|
writePixelNativeAlpha(x, y, fg, alpha);
|
|
1348
1349
|
}
|
|
1349
1350
|
|
|
1351
|
+
void Canvas::blendCoverageRow(int y, int x0, int count, const std::uint8_t *coverage, pixel::native_t color,
|
|
1352
|
+
bool markRowDirty)
|
|
1353
|
+
{
|
|
1354
|
+
if (!pixels_ || !coverage || count <= 0 || globalAlpha_ == 0) return;
|
|
1355
|
+
const ClipRect &clip = clipStack_[clipDepth_];
|
|
1356
|
+
if (y < 0 || y >= height_ || y < clip.y0 || y > clip.y1) return;
|
|
1357
|
+
int begin = std::max({x0, clip.x0, 0});
|
|
1358
|
+
int end = std::min({x0 + count - 1, clip.x1, width_ - 1});
|
|
1359
|
+
while (begin <= end && coverage[begin - x0] == 0) ++begin;
|
|
1360
|
+
while (end >= begin && coverage[end - x0] == 0) --end;
|
|
1361
|
+
if (begin > end) return;
|
|
1362
|
+
const int phys = rowToPhysical(y);
|
|
1363
|
+
for (int x = begin; x <= end;) {
|
|
1364
|
+
// Runs of equal coverage: a shape's interior is one long run, its edges
|
|
1365
|
+
// short ones. Full runs are span fills; partial runs blend one colour at
|
|
1366
|
+
// one alpha, so the result for a given destination pixel repeats -- and
|
|
1367
|
+
// under a chart the destination is mostly one background colour.
|
|
1368
|
+
const std::uint8_t c = coverage[x - x0];
|
|
1369
|
+
int run = x + 1;
|
|
1370
|
+
while (run <= end && coverage[run - x0] == c) ++run;
|
|
1371
|
+
const int n = run - x;
|
|
1372
|
+
if (c == 255) {
|
|
1373
|
+
fillSpanGlobalAlpha(phys, x, n, color);
|
|
1374
|
+
} else if (c != 0) {
|
|
1375
|
+
const int a = globalAlpha_ == 255 ? c : (c * globalAlpha_) / 255;
|
|
1376
|
+
if (a > 0) blendSpanAlpha(y, phys, x, n, color, a);
|
|
1377
|
+
}
|
|
1378
|
+
x = run;
|
|
1379
|
+
}
|
|
1380
|
+
if (markRowDirty) markDirty(begin, y, end, y);
|
|
1381
|
+
}
|
|
1382
|
+
|
|
1383
|
+
void Canvas::blendCoverageSpan(int y, int x0, int count, std::uint8_t coverage, pixel::native_t color,
|
|
1384
|
+
bool markRowDirty)
|
|
1385
|
+
{
|
|
1386
|
+
if (!pixels_ || count <= 0 || coverage == 0 || globalAlpha_ == 0) return;
|
|
1387
|
+
const ClipRect &clip = clipStack_[clipDepth_];
|
|
1388
|
+
if (y < 0 || y >= height_ || y < clip.y0 || y > clip.y1) return;
|
|
1389
|
+
const int begin = std::max({x0, clip.x0, 0});
|
|
1390
|
+
const int end = std::min({x0 + count - 1, clip.x1, width_ - 1});
|
|
1391
|
+
if (begin > end) return;
|
|
1392
|
+
const int phys = rowToPhysical(y);
|
|
1393
|
+
if (coverage == 255) {
|
|
1394
|
+
fillSpanGlobalAlpha(phys, begin, end - begin + 1, color);
|
|
1395
|
+
} else {
|
|
1396
|
+
const int a = globalAlpha_ == 255 ? coverage : (coverage * globalAlpha_) / 255;
|
|
1397
|
+
if (a <= 0) return;
|
|
1398
|
+
blendSpanAlpha(y, phys, begin, end - begin + 1, color, a);
|
|
1399
|
+
}
|
|
1400
|
+
if (markRowDirty) markDirty(begin, y, end, y);
|
|
1401
|
+
}
|
|
1402
|
+
|
|
1403
|
+
// A run blends one colour at one alpha, so the result for a given destination
|
|
1404
|
+
// pixel repeats -- and under a chart the destination is mostly one colour.
|
|
1405
|
+
void Canvas::blendSpanAlpha(int y, int phys, int x, int n, pixel::native_t color, int a)
|
|
1406
|
+
{
|
|
1407
|
+
#if GEA_EMBEDDED_DISPLAY_ROTATE_LANDSCAPE
|
|
1408
|
+
if (landscapeRot_) {
|
|
1409
|
+
for (int i = 0; i < n; ++i) rotBlend(x + i, y, color, a);
|
|
1410
|
+
return;
|
|
1411
|
+
}
|
|
1412
|
+
#endif
|
|
1413
|
+
(void)y;
|
|
1414
|
+
#if GEA_PIXEL_STORAGE_PACKED
|
|
1415
|
+
for (int i = 0; i < n; ++i) pixel::packed::blendPixel(packedRow(phys), x + i, color, a);
|
|
1416
|
+
#else
|
|
1417
|
+
pixel::native_t *p = &pixels_[phys * stride_ + x];
|
|
1418
|
+
pixel::native_t lastBg = p[0];
|
|
1419
|
+
pixel::native_t lastOut = pixel::blendNative(color, lastBg, a);
|
|
1420
|
+
p[0] = lastOut;
|
|
1421
|
+
for (int i = 1; i < n; ++i) {
|
|
1422
|
+
const pixel::native_t bg = p[i];
|
|
1423
|
+
if (bg != lastBg) {
|
|
1424
|
+
lastBg = bg;
|
|
1425
|
+
lastOut = pixel::blendNative(color, bg, a);
|
|
1426
|
+
}
|
|
1427
|
+
p[i] = lastOut;
|
|
1428
|
+
}
|
|
1429
|
+
#endif
|
|
1430
|
+
}
|
|
1431
|
+
|
|
1350
1432
|
// Fill a horizontal span at physical row `phys` with a colour (converted once
|
|
1351
1433
|
// to the native pixel). Native fill — no per-pixel conversion, no branch.
|
|
1352
1434
|
void Canvas::fillSpanColor(int phys, int x0, int count, pixel::native_t color)
|
|
@@ -1860,19 +1942,23 @@ void Canvas::fillRect(int x, int y, int w, int h, pixel::native_t color)
|
|
|
1860
1942
|
runStart = -1; // keep the shared tail below a no-op
|
|
1861
1943
|
}
|
|
1862
1944
|
#else
|
|
1863
|
-
|
|
1864
|
-
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1945
|
+
// Trim the already-correct pixels off both ends and fill what is
|
|
1946
|
+
// left as one span. Pixels inside the span that already match are
|
|
1947
|
+
// rewritten with the same value, so the pixels are exactly those of
|
|
1948
|
+
// a per-run fill; the dirty rect is the row's differing extent, a
|
|
1949
|
+
// superset of the per-run rects. Per-run marking cost a dirty-list
|
|
1950
|
+
// walk per run: a fill over freshly reused staging memory (the
|
|
1951
|
+
// fused flush's strip buffer) differs in scattered runs, and it
|
|
1952
|
+
// measured 15.8 cycles/px on an ESP32-S3.
|
|
1953
|
+
const pixel::native_t *dst = &pixels_[rowToPhysical(row) * stride_ + x0];
|
|
1954
|
+
const int runStart = -1;
|
|
1955
|
+
int a = 0;
|
|
1956
|
+
while (a < count && dst[a] == c) ++a;
|
|
1957
|
+
if (a == count) continue;
|
|
1958
|
+
int b = count - 1;
|
|
1959
|
+
while (dst[b] == c) --b;
|
|
1960
|
+
fillSpanColor(rowToPhysical(row), x0 + a, b - a + 1, c);
|
|
1961
|
+
markDirty(x0 + a, row, x0 + b, row);
|
|
1876
1962
|
#endif
|
|
1877
1963
|
if (runStart >= 0) markDirty(x0 + runStart, row, x1, row);
|
|
1878
1964
|
}
|
|
@@ -3983,8 +4069,14 @@ void Canvas::fillRoundedRect(int x, int y, int w, int h, int tl, int tr, int br,
|
|
|
3983
4069
|
for (int sy = row0; sy <= row1; sy++) {
|
|
3984
4070
|
int sx0 = width_;
|
|
3985
4071
|
int sx1 = -1;
|
|
4072
|
+
// The row's span before clipping: the antialiased edge band is measured
|
|
4073
|
+
// from the shape's own edges, not from where a clip happens to cut it.
|
|
4074
|
+
int ux0 = INT_MAX;
|
|
4075
|
+
int ux1 = INT_MIN;
|
|
3986
4076
|
auto addSpan = [&](int left, int right) {
|
|
3987
4077
|
if (left > right) return;
|
|
4078
|
+
if (left < ux0) ux0 = left;
|
|
4079
|
+
if (right > ux1) ux1 = right;
|
|
3988
4080
|
if (left < clip->x0) left = clip->x0;
|
|
3989
4081
|
if (right > clip->x1) right = clip->x1;
|
|
3990
4082
|
if (left < 0) left = 0;
|
|
@@ -4036,10 +4128,12 @@ void Canvas::fillRoundedRect(int x, int y, int w, int h, int tl, int tr, int br,
|
|
|
4036
4128
|
anyX0 = width_;
|
|
4037
4129
|
anyX1 = -1;
|
|
4038
4130
|
roundedRectAnyCoverageSpan(x, y, w, h, tl, tr, br, bl, sy, aaSamples, kernelWidth, &anyX0, &anyX1);
|
|
4039
|
-
if (anyX0 < clip->x0) anyX0 = clip->x0;
|
|
4040
|
-
if (anyX1 > clip->x1) anyX1 = clip->x1;
|
|
4041
4131
|
if (anyX0 < x) anyX0 = x;
|
|
4042
4132
|
if (anyX1 > x + w - 1) anyX1 = x + w - 1;
|
|
4133
|
+
if (ux0 < anyX0) ux0 = anyX0;
|
|
4134
|
+
if (ux1 > anyX1) ux1 = anyX1;
|
|
4135
|
+
if (anyX0 < clip->x0) anyX0 = clip->x0;
|
|
4136
|
+
if (anyX1 > clip->x1) anyX1 = clip->x1;
|
|
4043
4137
|
if (anyX0 < 0) anyX0 = 0;
|
|
4044
4138
|
if (anyX1 >= width_) anyX1 = width_ - 1;
|
|
4045
4139
|
if (sx0 < anyX0) sx0 = anyX0;
|
|
@@ -4116,18 +4210,23 @@ void Canvas::fillRoundedRect(int x, int y, int w, int h, int tl, int tr, int br,
|
|
|
4116
4210
|
for (int px = inX1 + 1; px <= anyX1; ++px) paintCoverageEdge(px);
|
|
4117
4211
|
continue;
|
|
4118
4212
|
} else if (useAntialias) {
|
|
4119
|
-
|
|
4120
|
-
|
|
4121
|
-
|
|
4122
|
-
|
|
4123
|
-
|
|
4124
|
-
|
|
4125
|
-
|
|
4126
|
-
|
|
4127
|
-
|
|
4128
|
-
} else {
|
|
4213
|
+
// Coverage-test only the pixels within edgePad of the shape's edges;
|
|
4214
|
+
// the solid interior below takes the rest. Measuring the band from
|
|
4215
|
+
// the clipped span instead sampled coverage at both clip borders of
|
|
4216
|
+
// every row, though the shape covers those pixels fully: a card
|
|
4217
|
+
// background repainted under a dirty region inside it spent most
|
|
4218
|
+
// of its time there.
|
|
4219
|
+
const int solidX0 = ux0 + edgePad + 1;
|
|
4220
|
+
const int solidX1 = ux1 - edgePad - 1;
|
|
4221
|
+
if (sx0 > sx1 || solidX0 > solidX1) {
|
|
4129
4222
|
for (int px = anyX0; px <= anyX1; ++px) paintCoverageEdge(px);
|
|
4223
|
+
} else {
|
|
4224
|
+
const int leftEdgeEnd = std::min(anyX1, solidX0 - 1);
|
|
4225
|
+
const int rightEdgeStart = std::max(anyX0, solidX1 + 1);
|
|
4226
|
+
for (int px = anyX0; px <= leftEdgeEnd; ++px) paintCoverageEdge(px);
|
|
4227
|
+
for (int px = rightEdgeStart; px <= anyX1; ++px) paintCoverageEdge(px);
|
|
4130
4228
|
}
|
|
4229
|
+
if (sx0 > sx1) continue; // no solid span (and ux0/ux1 may be unset)
|
|
4131
4230
|
} else if (sx0 > sx1) {
|
|
4132
4231
|
continue;
|
|
4133
4232
|
}
|
|
@@ -4136,8 +4235,8 @@ void Canvas::fillRoundedRect(int x, int y, int w, int h, int tl, int tr, int br,
|
|
|
4136
4235
|
// full opaque shape — fill it directly, with no per-pixel edge coverage
|
|
4137
4236
|
// (roundedRectSampleContains). AA on carves the antialiased edge band (edgePad)
|
|
4138
4237
|
// out of the solid fill and leaves those edges to the coverage passes above.
|
|
4139
|
-
int fillX0 = useAntialias ?
|
|
4140
|
-
int fillX1 = useAntialias ?
|
|
4238
|
+
int fillX0 = useAntialias ? ux0 + edgePad + 1 : sx0;
|
|
4239
|
+
int fillX1 = useAntialias ? ux1 - edgePad - 1 : sx1;
|
|
4141
4240
|
if (fillX0 < clip->x0) fillX0 = clip->x0;
|
|
4142
4241
|
if (fillX1 > clip->x1) fillX1 = clip->x1;
|
|
4143
4242
|
if (fillX0 < 0) fillX0 = 0;
|
package/package.json
CHANGED
package/ui/CSS_FEATURES.md
CHANGED
|
@@ -259,3 +259,54 @@ with the preceding 164-byte candidate, this saves 648 B in TreeState and
|
|
|
259
259
|
11,664 B of firmware. The 49-node host allocation fixture is unchanged because
|
|
260
260
|
of allocator rounding; these record reductions are not a host heap saving.
|
|
261
261
|
This remains a development checkpoint, not a 50-byte node or a 60 fps guarantee.
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
## Inline SVG
|
|
265
|
+
|
|
266
|
+
`<svg>` and its shapes are ordinary nodes (`svg_element.h`): they take classes,
|
|
267
|
+
inline style, listeners and `:active`, and `getAttribute` returns full path
|
|
268
|
+
data. The `<svg>` box lays out like a view (its `width`/`height` attributes are
|
|
269
|
+
its default size; CSS wins) and records one `DrawSvg` display command. That
|
|
270
|
+
command rasterizes the svg's cached scene into the framebuffer with exact-area
|
|
271
|
+
anti-aliasing, honouring clip and opacity. Shapes are out of flow and zero-size.
|
|
272
|
+
The scene rebuilds once, on the next frame after anything in the subtree changes
|
|
273
|
+
(attribute, class, style, structure), and only the svg's box repaints.
|
|
274
|
+
|
|
275
|
+
Supported:
|
|
276
|
+
|
|
277
|
+
- Elements: `svg`, `g`, `path`, `polyline`, `polygon`, `line`, `circle`,
|
|
278
|
+
`ellipse` and `rect` (with `rx`/`ry`). `defs`, `title`, `desc` and `text`
|
|
279
|
+
are accepted and not painted.
|
|
280
|
+
- `viewBox` with `preserveAspectRatio` (all align values, `meet`/`slice`,
|
|
281
|
+
`none`).
|
|
282
|
+
- Path data: `M L H V C S Q T A Z`, absolute and relative, with implicit
|
|
283
|
+
repeats and compact arc flags. Parsing stops at the first error and keeps
|
|
284
|
+
what came before it, as browsers do.
|
|
285
|
+
- `transform` on shapes and groups: `matrix`, `translate`, `scale`,
|
|
286
|
+
`rotate(a [cx cy])`, `skewX` and `skewY`.
|
|
287
|
+
- Paint: `fill`, `stroke`, `stroke-width`, `stroke-linecap` (butt, round,
|
|
288
|
+
square), `stroke-linejoin` (miter, round, bevel), `stroke-miterlimit`,
|
|
289
|
+
`fill-rule`, `opacity`, `fill-opacity`, `stroke-opacity`, `color` with
|
|
290
|
+
`currentColor`, `visibility`, `display` and `pointer-events`. Colours are
|
|
291
|
+
hex (3, 4, 6 or 8 digits), `rgb[a]()`, `hsl[a]()`, named colours and
|
|
292
|
+
`transparent`.
|
|
293
|
+
- The same paint properties as CSS (`.slice { fill: #38bdf8; stroke-width: 3px }`,
|
|
294
|
+
`style={{ fill: color }}`). CSS beats presentation attributes, and the
|
|
295
|
+
inheritable ones inherit through `g`. Group `opacity` multiplies into each
|
|
296
|
+
shape; it is not composited as a layer.
|
|
297
|
+
- Touch: the hit test descends into the svg by geometry, either the fill's
|
|
298
|
+
winding or the stroke within 3px of slop. The topmost shape receives the
|
|
299
|
+
event, which bubbles through `g` and `svg`. `pointer-events: none` shapes
|
|
300
|
+
are transparent to touch.
|
|
301
|
+
|
|
302
|
+
Not supported: `<text>`, `<use>`, gradients and patterns, `clipPath`/`mask`,
|
|
303
|
+
markers, dashes (`stroke-dasharray`), filters, and units other than px.
|
|
304
|
+
`var()` in paint values is not supported either. A CSS `transform` on the
|
|
305
|
+
`<svg>` element itself moves its box, but the scene is not reprojected into the
|
|
306
|
+
transformed space.
|
|
307
|
+
|
|
308
|
+
Cost: the svg paint fields live in the pooled `RareStyle`, allocated only for
|
|
309
|
+
nodes that set a rare field. Ordinary nodes carry nothing new. The plugin
|
|
310
|
+
reports `node-svg` when the source can create an svg element (JSX `<svg>`,
|
|
311
|
+
`createElement('svg')`, `SVG*Element`, opaque markup). The CLI turns that into
|
|
312
|
+
`GEA_UI_SVG`, which compiles the whole feature out of apps that have no svg.
|
package/ui/input.cpp
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
#include "pixel.h"
|
|
5
5
|
#include "tree_state.h"
|
|
6
|
+
#include "svg_element.h"
|
|
6
7
|
#include "control_commit.h"
|
|
7
8
|
#include "input_retirement.h"
|
|
8
9
|
|
|
@@ -517,6 +518,14 @@ private:
|
|
|
517
518
|
if (result >= 0) return result;
|
|
518
519
|
}
|
|
519
520
|
|
|
521
|
+
#if GEA_UI_SVG
|
|
522
|
+
// Inside an <svg>, the target is the topmost shape under the point, by
|
|
523
|
+
// its painted geometry; the svg itself when none is.
|
|
524
|
+
if (inside && !clipped && svg::isRoot(node)) {
|
|
525
|
+
const int shape = svg::hitTest(id, x, y);
|
|
526
|
+
if (shape >= 0) return shape;
|
|
527
|
+
}
|
|
528
|
+
#endif
|
|
520
529
|
if (!inside || clipped || node.computedStyle().visibility != 0) return -1;
|
|
521
530
|
return id;
|
|
522
531
|
}
|
package/ui/internal.h
CHANGED
|
@@ -73,7 +73,9 @@ void rootScrollImageHoldTick();
|
|
|
73
73
|
BeginFilterBlur,
|
|
74
74
|
ApplyFilterBlur,
|
|
75
75
|
FillTransformedLinearGradient,
|
|
76
|
-
FillTransformedRoundedRect
|
|
76
|
+
FillTransformedRoundedRect,
|
|
77
|
+
// Inline <svg>: rasterizes the svg node's cached scene (svg_element.h).
|
|
78
|
+
DrawSvg
|
|
77
79
|
};
|
|
78
80
|
|
|
79
81
|
struct DisplayCommand
|
|
@@ -111,6 +113,7 @@ void rootScrollImageHoldTick();
|
|
|
111
113
|
gea::framework::graphics::pixel::native_t color;
|
|
112
114
|
} fill;
|
|
113
115
|
struct { int16_t nodeId, x, y, width, height; std::uint32_t identity; } canvasBatch;
|
|
116
|
+
struct { int16_t nodeId, x, y, w, h; } svg;
|
|
114
117
|
struct
|
|
115
118
|
{
|
|
116
119
|
int16_t cx, cy, r;
|
package/ui/node_features.h
CHANGED
|
@@ -29,6 +29,12 @@ static_assert(GEA_UI_CLASS_INLINE_TOKENS >= 1 && GEA_UI_CLASS_INLINE_TOKENS <= 4
|
|
|
29
29
|
|
|
30
30
|
// Closed whole-source auxiliary-state proof. Unknown/older programs keep all
|
|
31
31
|
// owners; callers cannot prune these through application manifest switches.
|
|
32
|
+
// Inline <svg>: the element, its scene cache and the SVG paint properties in
|
|
33
|
+
// RareStyle. The plugin proves absence (node-svg); unknown programs keep it.
|
|
34
|
+
#ifndef GEA_UI_SVG
|
|
35
|
+
#define GEA_UI_SVG 1
|
|
36
|
+
#endif
|
|
37
|
+
|
|
32
38
|
#ifndef GEA_UI_NODE_LISTENERS
|
|
33
39
|
#define GEA_UI_NODE_LISTENERS 1
|
|
34
40
|
#endif
|
package/ui/node_model.h
CHANGED
|
@@ -161,6 +161,22 @@ inline bool isNativeButtonNodeType(NodeType type)
|
|
|
161
161
|
// BEFORE ComputedStyle so it can be a by-value member).
|
|
162
162
|
struct RareStyle {
|
|
163
163
|
bool operator==(const RareStyle &) const = default;
|
|
164
|
+
#if GEA_UI_SVG
|
|
165
|
+
// SVG paint. Unset (0 / -1) means "inherit from the SVG parent"; the scene
|
|
166
|
+
// resolver walks the svg subtree, so no inheritance machinery runs for them.
|
|
167
|
+
int32_t svg_fill = 0; // svg::encodePaint
|
|
168
|
+
int32_t svg_stroke = 0; // svg::encodePaint
|
|
169
|
+
int32_t svg_stroke_width = -1; // px * 100
|
|
170
|
+
int16_t svg_fill_opacity = -1; // 0..1000
|
|
171
|
+
int16_t svg_stroke_opacity = -1; // 0..1000
|
|
172
|
+
int8_t svg_stroke_linecap = -1; // svg::LineCap
|
|
173
|
+
int8_t svg_stroke_linejoin = -1; // svg::LineJoin
|
|
174
|
+
int8_t svg_fill_rule = -1; // 0 nonzero, 1 evenodd
|
|
175
|
+
#else
|
|
176
|
+
static constexpr int32_t svg_fill = 0, svg_stroke = 0, svg_stroke_width = -1;
|
|
177
|
+
static constexpr int16_t svg_fill_opacity = -1, svg_stroke_opacity = -1;
|
|
178
|
+
static constexpr int8_t svg_stroke_linecap = -1, svg_stroke_linejoin = -1, svg_fill_rule = -1;
|
|
179
|
+
#endif
|
|
164
180
|
// Logical edges: block-start/end, inline-start/end.
|
|
165
181
|
#if GEA_CSS_MARGIN_TRIM
|
|
166
182
|
uint8_t margin_trim = 0;
|
|
@@ -494,7 +510,7 @@ inline int composedTranslateZ(const RareStyle &s) { return int(s.transform_trans
|
|
|
494
510
|
inline int composedTranslateXPercent(const RareStyle &s) { return int(s.transform_translate_x_percent) + s.translate_x_percent; }
|
|
495
511
|
inline int composedTranslateYPercent(const RareStyle &s) { return int(s.transform_translate_y_percent) + s.translate_y_percent; }
|
|
496
512
|
|
|
497
|
-
#define GEA_CSS_RARE_STYLE (GEA_CSS_ASPECT_RATIO || GEA_CSS_BACKGROUND_LAYERS || GEA_CSS_BORDER_RELIEF || GEA_CSS_BOX_EXPRESSIONS || GEA_CSS_BOX_SHADOW || GEA_CSS_CONTAINMENT || GEA_CSS_FILTERS || GEA_CSS_FLEX_BASIS_EXPRESSIONS || GEA_CSS_FLEX_LINE_COUNT || GEA_CSS_GRID || GEA_CSS_JUSTIFY_SELF || GEA_CSS_LINE_HEIGHT_EXPRESSIONS || GEA_CSS_MARGIN_TRIM || GEA_CSS_SIDE_BORDERS || GEA_CSS_TRANSFORMS || GEA_EMBEDDED_RENDERER_LINEAR_GRADIENTS || GEA_EMBEDDED_RENDERER_RADIAL_GRADIENTS)
|
|
513
|
+
#define GEA_CSS_RARE_STYLE (GEA_CSS_ASPECT_RATIO || GEA_CSS_BACKGROUND_LAYERS || GEA_CSS_BORDER_RELIEF || GEA_CSS_BOX_EXPRESSIONS || GEA_CSS_BOX_SHADOW || GEA_CSS_CONTAINMENT || GEA_CSS_FILTERS || GEA_CSS_FLEX_BASIS_EXPRESSIONS || GEA_CSS_FLEX_LINE_COUNT || GEA_CSS_GRID || GEA_CSS_JUSTIFY_SELF || GEA_CSS_LINE_HEIGHT_EXPRESSIONS || GEA_CSS_MARGIN_TRIM || GEA_CSS_SIDE_BORDERS || GEA_CSS_TRANSFORMS || GEA_EMBEDDED_RENDERER_LINEAR_GRADIENTS || GEA_EMBEDDED_RENDERER_RADIAL_GRADIENTS || GEA_UI_SVG)
|
|
498
514
|
static_assert(GEA_CSS_RARE_STYLE || std::is_empty<RareStyle>::value, "An unguarded rare field requires a reachability family");
|
|
499
515
|
|
|
500
516
|
struct ComputedStyle {
|
package/ui/render.cpp
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
#include "state_init.h"
|
|
11
11
|
#include "style_values.h"
|
|
12
12
|
#include "tree_state.h"
|
|
13
|
+
#include "svg_element.h"
|
|
13
14
|
#include <pixel.h>
|
|
14
15
|
|
|
15
16
|
#include <algorithm>
|
|
@@ -335,6 +336,8 @@ int gLastScrollUiFrame = -1000;
|
|
|
335
336
|
return "BlitImageProjected";
|
|
336
337
|
case DisplayCommandType::ReplayCanvasBatch:
|
|
337
338
|
return "ReplayCanvasBatch";
|
|
339
|
+
case DisplayCommandType::DrawSvg:
|
|
340
|
+
return "DrawSvg";
|
|
338
341
|
case DisplayCommandType::BeginFilterBlur:
|
|
339
342
|
return "BeginFilterBlur";
|
|
340
343
|
case DisplayCommandType::ApplyFilterBlur:
|
|
@@ -5538,6 +5541,10 @@ int gLastScrollUiFrame = -1000;
|
|
|
5538
5541
|
c->canvasBatch.x += dx;
|
|
5539
5542
|
c->canvasBatch.y += dy;
|
|
5540
5543
|
break;
|
|
5544
|
+
case DisplayCommandType::DrawSvg:
|
|
5545
|
+
c->svg.x += dx;
|
|
5546
|
+
c->svg.y += dy;
|
|
5547
|
+
break;
|
|
5541
5548
|
case DisplayCommandType::BlitImageProjected:
|
|
5542
5549
|
c->projectedBlit.x += dx;
|
|
5543
5550
|
c->projectedBlit.y += dy;
|
|
@@ -6946,6 +6953,11 @@ int gLastScrollUiFrame = -1000;
|
|
|
6946
6953
|
CanvasRenderingContext2D::replayRetainedCanvas(c.canvasBatch.nodeId, c.canvasBatch.identity,
|
|
6947
6954
|
c.canvasBatch.x, c.canvasBatch.y, c.canvasBatch.width, c.canvasBatch.height);
|
|
6948
6955
|
break;
|
|
6956
|
+
case DisplayCommandType::DrawSvg:
|
|
6957
|
+
#if GEA_UI_SVG
|
|
6958
|
+
svg::paint(c);
|
|
6959
|
+
#endif
|
|
6960
|
+
break;
|
|
6949
6961
|
case DisplayCommandType::BlitImageProjected:
|
|
6950
6962
|
drawProjectedImage(c);
|
|
6951
6963
|
break;
|
|
@@ -7041,6 +7053,7 @@ int gLastScrollUiFrame = -1000;
|
|
|
7041
7053
|
break;
|
|
7042
7054
|
case DisplayCommandType::BlitImage:
|
|
7043
7055
|
case DisplayCommandType::ReplayCanvasBatch:
|
|
7056
|
+
case DisplayCommandType::DrawSvg:
|
|
7044
7057
|
case DisplayCommandType::BlitImageProjected:
|
|
7045
7058
|
case DisplayCommandType::BlitImageScaled:
|
|
7046
7059
|
GEA_REFRESH_PERF(__perf.treeReplayImageUs += __replayDt);
|
|
@@ -7334,6 +7347,12 @@ int gLastScrollUiFrame = -1000;
|
|
|
7334
7347
|
{
|
|
7335
7348
|
CanvasRenderer::record(*n);
|
|
7336
7349
|
}
|
|
7350
|
+
#if GEA_UI_SVG
|
|
7351
|
+
else if (paintsOwnBox && svg::isRoot(*n))
|
|
7352
|
+
{
|
|
7353
|
+
svg::record(*n);
|
|
7354
|
+
}
|
|
7355
|
+
#endif
|
|
7337
7356
|
else if (paintsOwnBox && n->type == NodeType::Camera)
|
|
7338
7357
|
{
|
|
7339
7358
|
CameraRenderer::record(*n);
|
|
@@ -9738,6 +9757,10 @@ int gLastScrollUiFrame = -1000;
|
|
|
9738
9757
|
// the enclosing real context. Ordinary block/inline wrappers contribute
|
|
9739
9758
|
// separate entries so block backgrounds remain below floats and text.
|
|
9740
9759
|
auto walk = [&](auto &&self, int parent, bool withinGroup) -> void {
|
|
9760
|
+
#if GEA_UI_SVG
|
|
9761
|
+
// An svg's children are its scene, painted by its DrawSvg command.
|
|
9762
|
+
if (svg::isRoot(nodes[parent])) return;
|
|
9763
|
+
#endif
|
|
9741
9764
|
std::vector<int> children;
|
|
9742
9765
|
for (int child = nodes[parent].first_child; child >= 0; child = nodes[child].next_sibling)
|
|
9743
9766
|
if (!isStructuralNodeType(nodes[child].type) && !isDisplayNone(nodes[child].computedStyle())) children.push_back(child);
|
|
@@ -11788,6 +11811,7 @@ int gLastScrollUiFrame = -1000;
|
|
|
11788
11811
|
case DisplayCommandType::DrawText:
|
|
11789
11812
|
case DisplayCommandType::BlitImage:
|
|
11790
11813
|
case DisplayCommandType::ReplayCanvasBatch:
|
|
11814
|
+
case DisplayCommandType::DrawSvg:
|
|
11791
11815
|
case DisplayCommandType::BlitImageProjected:
|
|
11792
11816
|
case DisplayCommandType::BlitImageScaled:
|
|
11793
11817
|
case DisplayCommandType::FillTransformedLinearGradient:
|
|
@@ -13034,6 +13058,10 @@ int gLastScrollUiFrame = -1000;
|
|
|
13034
13058
|
CanvasRenderer::record(*n);
|
|
13035
13059
|
else if (n->type == NodeType::Camera)
|
|
13036
13060
|
CameraRenderer::record(*n);
|
|
13061
|
+
#if GEA_UI_SVG
|
|
13062
|
+
else if (svg::isRoot(*n))
|
|
13063
|
+
svg::record(*n);
|
|
13064
|
+
#endif
|
|
13037
13065
|
}
|
|
13038
13066
|
|
|
13039
13067
|
state.appendOverride = prev_override;
|
package/ui/style.cpp
CHANGED
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
#include <image.h>
|
|
14
14
|
#include "css/engine.h"
|
|
15
15
|
#include "refresh_perf.h"
|
|
16
|
+
#include "svg_element.h"
|
|
16
17
|
|
|
17
18
|
#include <algorithm>
|
|
18
19
|
#include <array>
|
|
@@ -770,6 +771,13 @@ void markClassRecomputeStyleDiff(int node, const ComputedStyle &beforeStyle, int
|
|
|
770
771
|
Node &target = state.nodes[node];
|
|
771
772
|
if (beforeImageId == target.image_id && styleExactlyEqual(beforeStyle, target.computedStyle()) && !firstLineChanged) return;
|
|
772
773
|
if (!nodeParticipatesInMountedTree(state, node)) return;
|
|
774
|
+
#if GEA_UI_SVG
|
|
775
|
+
// A shape's style only feeds its svg's scene: repaint that svg alone.
|
|
776
|
+
if (svg::isShape(node)) {
|
|
777
|
+
svg::noteNodeChanged(node);
|
|
778
|
+
return;
|
|
779
|
+
}
|
|
780
|
+
#endif
|
|
773
781
|
const bool hadRecolor = target.render.bg_recolor_pending;
|
|
774
782
|
const bool canRecolor = !target.render.dirty || hadRecolor;
|
|
775
783
|
target.render.text_partial_dirty = 0;
|
|
@@ -1245,6 +1253,16 @@ CssDeclarationId classifyDeclaration(const char *property)
|
|
|
1245
1253
|
if (std::strcmp(property, "font-family") == 0) return CssDeclarationId::FontFamily;
|
|
1246
1254
|
if (std::strcmp(property, "font-size") == 0) return CssDeclarationId::FontSize;
|
|
1247
1255
|
if (std::strcmp(property, "font-stretch") == 0) return CssDeclarationId::FontStretch;
|
|
1256
|
+
#if GEA_UI_SVG
|
|
1257
|
+
if (std::strcmp(property, "fill") == 0) return CssDeclarationId::SvgFill;
|
|
1258
|
+
if (std::strcmp(property, "stroke") == 0) return CssDeclarationId::SvgStroke;
|
|
1259
|
+
if (std::strcmp(property, "stroke-width") == 0) return CssDeclarationId::SvgStrokeWidth;
|
|
1260
|
+
if (std::strcmp(property, "fill-opacity") == 0) return CssDeclarationId::SvgFillOpacity;
|
|
1261
|
+
if (std::strcmp(property, "stroke-opacity") == 0) return CssDeclarationId::SvgStrokeOpacity;
|
|
1262
|
+
if (std::strcmp(property, "stroke-linecap") == 0) return CssDeclarationId::SvgStrokeLinecap;
|
|
1263
|
+
if (std::strcmp(property, "stroke-linejoin") == 0) return CssDeclarationId::SvgStrokeLinejoin;
|
|
1264
|
+
if (std::strcmp(property, "fill-rule") == 0) return CssDeclarationId::SvgFillRule;
|
|
1265
|
+
#endif
|
|
1248
1266
|
if (std::strcmp(property, "font-weight") == 0) return CssDeclarationId::FontWeight;
|
|
1249
1267
|
if (std::strcmp(property, "line-height") == 0) return CssDeclarationId::LineHeight;
|
|
1250
1268
|
if (std::strcmp(property, "text-align") == 0) return CssDeclarationId::TextAlign;
|
|
@@ -10075,6 +10093,21 @@ bool applyKnownResolvedPropertyWithSource(NodeHandle node, CssDeclarationId decl
|
|
|
10075
10093
|
case CssDeclarationId::Opacity:
|
|
10076
10094
|
setStyleValue(node, Property::Opacity, parseOpacity(value), source);
|
|
10077
10095
|
return true;
|
|
10096
|
+
case CssDeclarationId::SvgFill:
|
|
10097
|
+
case CssDeclarationId::SvgStroke:
|
|
10098
|
+
case CssDeclarationId::SvgStrokeWidth:
|
|
10099
|
+
case CssDeclarationId::SvgFillOpacity:
|
|
10100
|
+
case CssDeclarationId::SvgStrokeOpacity:
|
|
10101
|
+
case CssDeclarationId::SvgStrokeLinecap:
|
|
10102
|
+
case CssDeclarationId::SvgStrokeLinejoin:
|
|
10103
|
+
case CssDeclarationId::SvgFillRule: {
|
|
10104
|
+
#if GEA_UI_SVG
|
|
10105
|
+
Property property = Property::Count;
|
|
10106
|
+
int encoded = 0;
|
|
10107
|
+
if (svg::cssDeclarationValue(declaration, value.c_str(), property, encoded)) setStyleValue(node, property, encoded, source);
|
|
10108
|
+
#endif
|
|
10109
|
+
return true;
|
|
10110
|
+
}
|
|
10078
10111
|
case CssDeclarationId::BorderColor:
|
|
10079
10112
|
applyBorderColorValue(node, value, source);
|
|
10080
10113
|
return true;
|
|
@@ -18792,6 +18825,9 @@ void Tree::setTagName(int node, const char *tagName)
|
|
|
18792
18825
|
const int16_t id = internTag(tagName ? tagName : "");
|
|
18793
18826
|
if (state.nodes[node].tag_id == id) return;
|
|
18794
18827
|
state.nodes[node].tag_id = id;
|
|
18828
|
+
#if GEA_UI_SVG
|
|
18829
|
+
svg::noteTagChanged(node);
|
|
18830
|
+
#endif
|
|
18795
18831
|
recomputeSubtreeClassStyles(node);
|
|
18796
18832
|
}
|
|
18797
18833
|
|
package/ui/style.h
CHANGED
|
@@ -214,6 +214,15 @@ enum class Property : int {
|
|
|
214
214
|
BorderLeftRelief,
|
|
215
215
|
BorderRelief,
|
|
216
216
|
FontStretch,
|
|
217
|
+
// SVG paint (RareStyle, GEA_UI_SVG). Encodings in svg_element.h.
|
|
218
|
+
SvgFill,
|
|
219
|
+
SvgStroke,
|
|
220
|
+
SvgStrokeWidth,
|
|
221
|
+
SvgFillOpacity,
|
|
222
|
+
SvgStrokeOpacity,
|
|
223
|
+
SvgStrokeLinecap,
|
|
224
|
+
SvgStrokeLinejoin,
|
|
225
|
+
SvgFillRule,
|
|
217
226
|
Count
|
|
218
227
|
};
|
|
219
228
|
|
|
@@ -349,7 +358,15 @@ enum class StyleDeclaration : std::uint8_t {
|
|
|
349
358
|
MarginTrim,
|
|
350
359
|
Transition,
|
|
351
360
|
AnimationPlayState,
|
|
352
|
-
FontStretch
|
|
361
|
+
FontStretch,
|
|
362
|
+
SvgFill,
|
|
363
|
+
SvgStroke,
|
|
364
|
+
SvgStrokeWidth,
|
|
365
|
+
SvgFillOpacity,
|
|
366
|
+
SvgStrokeOpacity,
|
|
367
|
+
SvgStrokeLinecap,
|
|
368
|
+
SvgStrokeLinejoin,
|
|
369
|
+
SvgFillRule
|
|
353
370
|
};
|
|
354
371
|
|
|
355
372
|
class Style {
|
package/ui/svg_element.h
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
#pragma once
|
|
3
|
+
|
|
4
|
+
// Inline <svg> in the node tree.
|
|
5
|
+
//
|
|
6
|
+
// Every SVG element is an ordinary node: it has the NodeHandle interface,
|
|
7
|
+
// classes, inline style, listeners and :active/:hover state. What differs is
|
|
8
|
+
// how it paints:
|
|
9
|
+
//
|
|
10
|
+
// - <svg> is a view (its CSS box, background and border paint as usual) that
|
|
11
|
+
// records ONE DrawSvg display command. That command rasterizes the svg's
|
|
12
|
+
// cached scene, anti-aliased, straight into the framebuffer at replay.
|
|
13
|
+
// - Shapes and groups (path polyline polygon line circle ellipse rect g) are
|
|
14
|
+
// out-of-flow, zero-size nodes that never paint a box of their own; they
|
|
15
|
+
// are the scene's source. The hit test descends into them by geometry, so
|
|
16
|
+
// a tap on a <circle> targets that circle and bubbles through <g> and <svg>.
|
|
17
|
+
//
|
|
18
|
+
// Paint comes from presentation attributes and from CSS (fill, stroke,
|
|
19
|
+
// stroke-width, fill-opacity, stroke-opacity, stroke-linecap,
|
|
20
|
+
// stroke-linejoin, fill-rule, opacity, color/currentColor, visibility,
|
|
21
|
+
// display, pointer-events); CSS wins over attributes, and the inheritable
|
|
22
|
+
// properties inherit through the svg subtree.
|
|
23
|
+
//
|
|
24
|
+
// A change anywhere in an svg subtree (attribute, style, class, structure)
|
|
25
|
+
// marks that svg's scene dirty; it rebuilds once, when the svg next records,
|
|
26
|
+
// and repaints only the svg's box. Everything here compiles out with
|
|
27
|
+
// GEA_UI_SVG=0, which the plugin proves for apps without <svg>.
|
|
28
|
+
|
|
29
|
+
#include "node_features.h"
|
|
30
|
+
|
|
31
|
+
#if GEA_UI_SVG
|
|
32
|
+
|
|
33
|
+
#include "style.h"
|
|
34
|
+
|
|
35
|
+
#include <cstdint>
|
|
36
|
+
|
|
37
|
+
namespace gea::embedded::ui {
|
|
38
|
+
struct Node;
|
|
39
|
+
struct DisplayCommand;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
namespace gea::embedded::ui::svg {
|
|
43
|
+
|
|
44
|
+
// True for the SVG paint properties (stored in RareStyle).
|
|
45
|
+
inline bool isPaintProperty(Property p)
|
|
46
|
+
{
|
|
47
|
+
return p >= Property::SvgFill && p <= Property::SvgFillRule;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Parses a CSS declaration value for one of the SVG paint declarations into
|
|
51
|
+
// its style property and encoded value. False leaves the property untouched.
|
|
52
|
+
bool cssDeclarationValue(StyleDeclaration declaration, const char *value, Property &property, int &encoded);
|
|
53
|
+
|
|
54
|
+
// The <svg> root test: one int compare against the interned "svg" tag id.
|
|
55
|
+
bool isRoot(const Node &node);
|
|
56
|
+
|
|
57
|
+
// True for an SVG shape, group or metadata element (anything in an svg
|
|
58
|
+
// subtree except the <svg> root). Such nodes paint nothing themselves, so
|
|
59
|
+
// inserting, removing or restyling one only repaints its svg's scene.
|
|
60
|
+
bool isShape(int node);
|
|
61
|
+
|
|
62
|
+
// The pixels (relative to the svg's box) that its last scene rebuild changed,
|
|
63
|
+
// consumed once per rebuild. False means "repaint the whole box": no rebuild
|
|
64
|
+
// since the last call, a first build or resize, a z-order change, or a change
|
|
65
|
+
// to the svg box's own style or position. An empty rect (x1 < x0) means the
|
|
66
|
+
// rebuild changed nothing on screen.
|
|
67
|
+
bool damage(int root, int &x0, int &y0, int &x1, int &y1);
|
|
68
|
+
|
|
69
|
+
// Tree hooks.
|
|
70
|
+
void noteTagChanged(int node);
|
|
71
|
+
// Records an attribute on an SVG element (value == nullptr removes it).
|
|
72
|
+
// Returns true when the node is an SVG element.
|
|
73
|
+
bool noteAttribute(int node, const char *name, const char *value);
|
|
74
|
+
// The full attribute value for an SVG element (unbounded, unlike the generic
|
|
75
|
+
// attribute store), or nullptr when the node holds no such SVG attribute.
|
|
76
|
+
const char *attribute(int node, const char *name);
|
|
77
|
+
void noteNodeChanged(int node);
|
|
78
|
+
void releaseNode(int node);
|
|
79
|
+
void clearAll();
|
|
80
|
+
|
|
81
|
+
// Refresh hook: detects changes made by any path (class recompute, :active,
|
|
82
|
+
// structure) by comparing each svg subtree's signature with its last scene.
|
|
83
|
+
void validateScenes();
|
|
84
|
+
|
|
85
|
+
// Rendering.
|
|
86
|
+
void record(const Node &svgNode);
|
|
87
|
+
void paint(const DisplayCommand &command);
|
|
88
|
+
|
|
89
|
+
// Hit test inside an svg root whose box contains (x, y): the topmost shape
|
|
90
|
+
// under the point, or -1 when no shape paints there.
|
|
91
|
+
int hitTest(int rootId, int x, int y);
|
|
92
|
+
|
|
93
|
+
} // namespace gea::embedded::ui::svg
|
|
94
|
+
|
|
95
|
+
#endif // GEA_UI_SVG
|