@geastack/engine 0.1.5 → 0.1.7
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/README.md +70 -0
- package/canvas.cpp +86 -30
- package/css/animation.h +64 -0
- package/css/declarative.h +6 -0
- package/css/engine.h +25 -1
- package/image_store.cpp +136 -33
- package/package.json +2 -2
- package/ui/CSS_FEATURES.md +261 -0
- package/ui/absolute_leaf_refresh.cpp +42 -39
- package/ui/core.cpp +32 -1
- package/ui/css_atom.cpp +6 -0
- package/ui/css_atom.h +2 -0
- package/ui/css_features.h +282 -0
- package/ui/display_invalidation.cpp +29 -0
- package/ui/flex_balance.h +73 -0
- package/ui/image_node.cpp +33 -28
- package/ui/input.cpp +88 -38
- package/ui/input_render.cpp +17 -13
- package/ui/internal.h +51 -5
- package/ui/layout.cpp +2601 -441
- package/ui/layout_snapshot.cpp +49 -6
- package/ui/node_features.h +18 -0
- package/ui/node_lifecycle.cpp +204 -71
- package/ui/node_lifecycle.h +1 -0
- package/ui/node_model.h +930 -70
- package/ui/node_text.h +82 -0
- package/ui/render.cpp +793 -352
- package/ui/renderer_features.h +19 -0
- package/ui/root_scroll_refresh.cpp +46 -24
- package/ui/style.cpp +4155 -1073
- package/ui/style.h +143 -6
- package/ui/style_values.h +16 -0
- package/ui/text.cpp +401 -106
- package/ui/tree_events.cpp +138 -95
- package/ui/tree_events.h +28 -19
- package/ui/tree_inspection.h +15 -0
- package/ui/tree_internal.h +19 -0
- package/ui/tree_nodes.cpp +38 -4
- package/ui/tree_render.cpp +119 -40
- package/ui/tree_scroll_mirror.cpp +26 -0
- package/ui/tree_state.cpp +261 -114
- package/ui/tree_state.h +121 -16
- package/ui/tree_style.cpp +609 -82
- package/ui/view.cpp +720 -299
- package/ui/virtual_keyboard.cpp +10 -3
package/README.md
CHANGED
|
@@ -24,6 +24,76 @@ The component prop types live in `@geastack/core`. The C++ sources are
|
|
|
24
24
|
compiled into a target through `@geastack/core`'s source manifest. Vendored
|
|
25
25
|
third-party code is listed in the repository's `THIRD_PARTY.md`.
|
|
26
26
|
|
|
27
|
+
## Renderer cache reachability
|
|
28
|
+
|
|
29
|
+
ESP32 app builds derive renderer cache storage from the Gea compiler plugin's
|
|
30
|
+
source analysis. Circle operations, CSS transforms, linear gradients and radial
|
|
31
|
+
gradients each retain their own caches only when used. A video canvas that calls
|
|
32
|
+
`clearRect` and `drawImage`, for example, does not reserve circle tables. Ordinary
|
|
33
|
+
rounded corners continue to render without them.
|
|
34
|
+
|
|
35
|
+
The analysis follows source imports, imported CSS and CSS `@import`, JSX style
|
|
36
|
+
objects, style assignments and DOM style setters. Unknown styles or opaque
|
|
37
|
+
imports conservatively retain the corresponding features. The CLI passes the
|
|
38
|
+
result to both the app and the shared engine; no per-app switches are needed.
|
|
39
|
+
Position storage is selected independently for each physical edge and for
|
|
40
|
+
pixel versus percentage offsets. Unknown/logical insets retain every possible
|
|
41
|
+
edge. Native inputs and lists retain the edges they can mutate. The selected
|
|
42
|
+
fields remain embedded, aligned members; selection happens at compile time,
|
|
43
|
+
with no runtime accessor or extra pointer load. Cached style operations also
|
|
44
|
+
omit transform payloads when transforms are absent.
|
|
45
|
+
|
|
46
|
+
Text and border alpha bytes are omitted only when the complete source graph
|
|
47
|
+
proves every reachable color opaque. Literal CSS, custom-color definitions,
|
|
48
|
+
immutable local bindings and bounded palette/getter values participate in that
|
|
49
|
+
build-time proof. Unknown receivers, writes, escaping objects, palette mutation,
|
|
50
|
+
reflection, and native controls retain storage. Background alpha is independent.
|
|
51
|
+
The retained values stay inline; omitted fields read as the constant 255.
|
|
52
|
+
Node records reuse tail padding while preserving member assignment and reset
|
|
53
|
+
semantics, without a pointer lookup or packed-field decoding.
|
|
54
|
+
|
|
55
|
+
CSS animation support is likewise derived from whole-source reachability.
|
|
56
|
+
Animation/transition declarations, keyframes, `data-anim`, imperative animation
|
|
57
|
+
APIs and opaque styles/native UI calls retain it. Animation-free apps omit the
|
|
58
|
+
compiled animation handle in each CSS rule, active-list storage, priming and
|
|
59
|
+
per-frame animation polling. `requestAnimationFrame` is independent and remains
|
|
60
|
+
available. Older analysis versions retain the full animation engine; application
|
|
61
|
+
defines cannot override the proof. Enabled animation and frame-scheduling tests
|
|
62
|
+
run alongside the pruned geometry/pixel checks.
|
|
63
|
+
|
|
64
|
+
Generated `::before`/`::after` node support is also automatic. Literal selectors,
|
|
65
|
+
`content` writes and opaque CSS/native mutation retain it; older analyzers keep
|
|
66
|
+
support by default. First-line and animation buckets remain independent. Absent
|
|
67
|
+
families reserve no rule-plan buckets or cached bucket counters. CSS resets copy
|
|
68
|
+
an immutable default style directly, without constructing a temporary Node or
|
|
69
|
+
initializing unrelated text, links, layout and render state.
|
|
70
|
+
|
|
71
|
+
Cache-size definitions affect only retained features. Older analyzers and native
|
|
72
|
+
builds without feature analysis keep the full engine defaults.
|
|
73
|
+
|
|
74
|
+
Pruned caches have no persistent storage. The engine retains uncached rendering
|
|
75
|
+
paths for native or dynamically supplied instructions, preserving pixels and hit
|
|
76
|
+
testing even when such instructions are absent from the source analysis.
|
|
77
|
+
`packages/core/test/run-renderer-features.sh` compares enabled/pruned rendering
|
|
78
|
+
and verifies that pruned cache storage symbols are absent from the binary.
|
|
79
|
+
|
|
80
|
+
## Native JPEG decoding
|
|
81
|
+
|
|
82
|
+
ESP targets that link Espressif's `esp_new_jpeg` component automatically use it
|
|
83
|
+
when its `esp_jpeg_dec.h` header is visible and the target stores RGB565 pixels.
|
|
84
|
+
The decoder writes directly to the aligned image buffer in the target's byte
|
|
85
|
+
order, preserving source dimensions. It does not allocate an intermediate RGBA
|
|
86
|
+
frame. Unsupported images fall back to the ESP32-S3 ROM decoder, then stb.
|
|
87
|
+
Targets without the component retain their existing decoder fallback.
|
|
88
|
+
|
|
89
|
+
The S3 ROM path also preserves full colour and source dimensions, converting
|
|
90
|
+
individual RGB888 MCU blocks into the final native image with an 8 KiB workspace.
|
|
91
|
+
`packages/core/test/run-native-jpeg.sh` checks the backend API contracts, native
|
|
92
|
+
pixels, byte order, cleanup and fallback using host mocks. Actual codec speed
|
|
93
|
+
and output must be checked on hardware. With `GEA_EMBEDDED_PERF=1`, the optional
|
|
94
|
+
Espressif backend reports its result and duration on the first and every tenth
|
|
95
|
+
decode.
|
|
96
|
+
|
|
27
97
|
## License
|
|
28
98
|
|
|
29
99
|
Apache-2.0. See `LICENSE`.
|
package/canvas.cpp
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
#include "ui/renderer_features.h"
|
|
2
3
|
#include "canvas.h"
|
|
3
4
|
#include "display.h"
|
|
4
5
|
#include "graphics/font.h"
|
|
@@ -833,6 +834,7 @@ SolidGlyphCacheEntry *solidGlyphCacheEntry(const RasterizedFont &font,
|
|
|
833
834
|
|
|
834
835
|
class CanvasMath {
|
|
835
836
|
public:
|
|
837
|
+
#if GEA_EMBEDDED_RENDERER_CIRCLES
|
|
836
838
|
#ifndef GEA_EMBEDDED_CANVAS_CIRCLE_RADIUS_MAX
|
|
837
839
|
#define GEA_EMBEDDED_CANVAS_CIRCLE_RADIUS_MAX 63
|
|
838
840
|
#endif
|
|
@@ -853,6 +855,7 @@ public:
|
|
|
853
855
|
static_assert(kCircleBoxSpanMax > 0 && kCircleBoxSpanMax <= 255);
|
|
854
856
|
static_assert(kCircleBoxSpanSlots > 0);
|
|
855
857
|
|
|
858
|
+
#endif
|
|
856
859
|
static int min(int a, int b) { return a < b ? a : b; }
|
|
857
860
|
|
|
858
861
|
static int integerSqrt(int n)
|
|
@@ -867,33 +870,39 @@ public:
|
|
|
867
870
|
return x;
|
|
868
871
|
}
|
|
869
872
|
|
|
870
|
-
const std::uint8_t (*circleSpans(int size))[2]
|
|
873
|
+
static const std::uint8_t (*circleSpans(int size))[2]
|
|
871
874
|
{
|
|
875
|
+
#if GEA_EMBEDDED_RENDERER_CIRCLES
|
|
872
876
|
if (size <= 0 || size > kCircleSpanMax || (size & 1)) return nullptr;
|
|
873
877
|
int slot = size / 2;
|
|
874
878
|
std::uint32_t bit = 1u << slot;
|
|
875
|
-
if (!(circleSpanCacheReady_ & bit)) {
|
|
879
|
+
if (!(instance().circleSpanCacheReady_ & bit)) {
|
|
876
880
|
int radius2 = size * size;
|
|
877
881
|
for (int row = 0; row < size; row++) {
|
|
878
882
|
int dy2 = row * 2 + 1 - size;
|
|
879
883
|
int dx2 = integerSqrt(radius2 - dy2 * dy2);
|
|
880
|
-
circleSpanCache_[slot][row][0] = (std::uint8_t)((size - dx2) / 2);
|
|
881
|
-
circleSpanCache_[slot][row][1] = (std::uint8_t)((size + dx2 - 1) / 2);
|
|
884
|
+
instance().circleSpanCache_[slot][row][0] = (std::uint8_t)((size - dx2) / 2);
|
|
885
|
+
instance().circleSpanCache_[slot][row][1] = (std::uint8_t)((size + dx2 - 1) / 2);
|
|
882
886
|
}
|
|
883
|
-
circleSpanCacheReady_ |= bit;
|
|
887
|
+
instance().circleSpanCacheReady_ |= bit;
|
|
884
888
|
}
|
|
885
|
-
return circleSpanCache_[slot];
|
|
889
|
+
return instance().circleSpanCache_[slot];
|
|
890
|
+
#else
|
|
891
|
+
(void)size;
|
|
892
|
+
return nullptr;
|
|
893
|
+
#endif
|
|
886
894
|
}
|
|
887
895
|
|
|
888
|
-
const std::uint8_t (*circleBoxSpans(int size))[2]
|
|
896
|
+
static const std::uint8_t (*circleBoxSpans(int size))[2]
|
|
889
897
|
{
|
|
898
|
+
#if GEA_EMBEDDED_RENDERER_CIRCLES
|
|
890
899
|
if (size <= 0 || size > kCircleBoxSpanMax) return nullptr;
|
|
891
900
|
for (int slot = 0; slot < kCircleBoxSpanSlots; ++slot) {
|
|
892
|
-
if (circleBoxSpanSize_[slot] == size)
|
|
893
|
-
return circleBoxSpanCache_[slot];
|
|
901
|
+
if (instance().circleBoxSpanSize_[slot] == size)
|
|
902
|
+
return instance().circleBoxSpanCache_[slot];
|
|
894
903
|
}
|
|
895
|
-
const int slot = circleBoxSpanNext_;
|
|
896
|
-
circleBoxSpanNext_ = (circleBoxSpanNext_ + 1) % kCircleBoxSpanSlots;
|
|
904
|
+
const int slot = instance().circleBoxSpanNext_;
|
|
905
|
+
instance().circleBoxSpanNext_ = (instance().circleBoxSpanNext_ + 1) % kCircleBoxSpanSlots;
|
|
897
906
|
const long long ss = static_cast<long long>(size) * static_cast<long long>(size);
|
|
898
907
|
for (int row = 0; row < size; row++) {
|
|
899
908
|
const long long dy2 = static_cast<long long>(row * 2 + 1 - size);
|
|
@@ -904,31 +913,41 @@ public:
|
|
|
904
913
|
int sx1 = (size + dx2 - 1) / 2;
|
|
905
914
|
if (sx0 < 0) sx0 = 0;
|
|
906
915
|
if (sx1 >= size) sx1 = size - 1;
|
|
907
|
-
circleBoxSpanCache_[slot][row][0] = static_cast<std::uint8_t>(sx0);
|
|
908
|
-
circleBoxSpanCache_[slot][row][1] = static_cast<std::uint8_t>(sx1);
|
|
916
|
+
instance().circleBoxSpanCache_[slot][row][0] = static_cast<std::uint8_t>(sx0);
|
|
917
|
+
instance().circleBoxSpanCache_[slot][row][1] = static_cast<std::uint8_t>(sx1);
|
|
909
918
|
}
|
|
910
|
-
circleBoxSpanSize_[slot] = size;
|
|
911
|
-
return circleBoxSpanCache_[slot];
|
|
919
|
+
instance().circleBoxSpanSize_[slot] = size;
|
|
920
|
+
return instance().circleBoxSpanCache_[slot];
|
|
921
|
+
#else
|
|
922
|
+
(void)size;
|
|
923
|
+
return nullptr;
|
|
924
|
+
#endif
|
|
912
925
|
}
|
|
913
926
|
|
|
914
|
-
const std::uint8_t (*circleRadiusSpans(int radius))[2]
|
|
927
|
+
static const std::uint8_t (*circleRadiusSpans(int radius))[2]
|
|
915
928
|
{
|
|
929
|
+
#if GEA_EMBEDDED_RENDERER_CIRCLES
|
|
916
930
|
if (radius <= 0 || radius > kCircleRadiusMax) return nullptr;
|
|
917
931
|
std::uint64_t bit = 1ull << radius;
|
|
918
|
-
if (!(circleRadiusSpanCacheReady_ & bit)) {
|
|
932
|
+
if (!(instance().circleRadiusSpanCacheReady_ & bit)) {
|
|
919
933
|
const int diameter = radius * 2 + 1;
|
|
920
934
|
const int rr = radius * radius;
|
|
921
935
|
for (int row = 0; row < diameter; row++) {
|
|
922
936
|
const int dy = row - radius;
|
|
923
937
|
const int dx = integerSqrt(rr - dy * dy);
|
|
924
|
-
circleRadiusSpanCache_[radius][row][0] = (std::uint8_t)(radius - dx);
|
|
925
|
-
circleRadiusSpanCache_[radius][row][1] = (std::uint8_t)(radius + dx);
|
|
938
|
+
instance().circleRadiusSpanCache_[radius][row][0] = (std::uint8_t)(radius - dx);
|
|
939
|
+
instance().circleRadiusSpanCache_[radius][row][1] = (std::uint8_t)(radius + dx);
|
|
926
940
|
}
|
|
927
|
-
circleRadiusSpanCacheReady_ |= bit;
|
|
941
|
+
instance().circleRadiusSpanCacheReady_ |= bit;
|
|
928
942
|
}
|
|
929
|
-
return circleRadiusSpanCache_[radius];
|
|
943
|
+
return instance().circleRadiusSpanCache_[radius];
|
|
944
|
+
#else
|
|
945
|
+
(void)radius;
|
|
946
|
+
return nullptr;
|
|
947
|
+
#endif
|
|
930
948
|
}
|
|
931
949
|
|
|
950
|
+
#if GEA_EMBEDDED_RENDERER_CIRCLES
|
|
932
951
|
static CanvasMath &instance()
|
|
933
952
|
{
|
|
934
953
|
static CanvasMath math;
|
|
@@ -943,8 +962,43 @@ private:
|
|
|
943
962
|
std::uint8_t circleBoxSpanCache_[kCircleBoxSpanSlots][kCircleBoxSpanMax][2]{};
|
|
944
963
|
std::uint8_t circleBoxSpanSize_[kCircleBoxSpanSlots]{};
|
|
945
964
|
int circleBoxSpanNext_ = 0;
|
|
965
|
+
#endif
|
|
946
966
|
};
|
|
947
967
|
|
|
968
|
+
pixel::native_t Canvas::readPixelNative(int x, int y) const
|
|
969
|
+
{
|
|
970
|
+
if (!pixels_ || x < 0 || x >= width_ || y < 0 || y >= height_) return 0;
|
|
971
|
+
#if GEA_EMBEDDED_DISPLAY_ROTATE_LANDSCAPE
|
|
972
|
+
if (landscapeRot_) return rotGet(x, y);
|
|
973
|
+
#endif
|
|
974
|
+
#if GEA_PIXEL_STORAGE_PACKED
|
|
975
|
+
return pixel::packed::get(packedRow(rowToPhysical(y)), x);
|
|
976
|
+
#else
|
|
977
|
+
return pixels_[rowToPhysical(y) * stride_ + x];
|
|
978
|
+
#endif
|
|
979
|
+
}
|
|
980
|
+
|
|
981
|
+
void Canvas::writePixelNativeExact(int x, int y, pixel::native_t value)
|
|
982
|
+
{
|
|
983
|
+
if (!pixels_ || x < 0 || x >= width_ || y < 0 || y >= height_) return;
|
|
984
|
+
if (x < clipStack_[clipDepth_].x0 || x > clipStack_[clipDepth_].x1 ||
|
|
985
|
+
y < clipStack_[clipDepth_].y0 || y > clipStack_[clipDepth_].y1)
|
|
986
|
+
return;
|
|
987
|
+
#if GEA_EMBEDDED_DISPLAY_ROTATE_LANDSCAPE
|
|
988
|
+
if (landscapeRot_) {
|
|
989
|
+
rotSet(x, y, value);
|
|
990
|
+
markDirty(x, y, x, y);
|
|
991
|
+
return;
|
|
992
|
+
}
|
|
993
|
+
#endif
|
|
994
|
+
#if GEA_PIXEL_STORAGE_PACKED
|
|
995
|
+
pixel::packed::set(packedRow(rowToPhysical(y)), x, value);
|
|
996
|
+
#else
|
|
997
|
+
pixels_[rowToPhysical(y) * stride_ + x] = value;
|
|
998
|
+
#endif
|
|
999
|
+
markDirty(x, y, x, y);
|
|
1000
|
+
}
|
|
1001
|
+
|
|
948
1002
|
void Canvas::writePixelNative(int x, int y, pixel::native_t c)
|
|
949
1003
|
{
|
|
950
1004
|
if (!pixels_) return;
|
|
@@ -1624,7 +1678,7 @@ bool Canvas::fillCircleNoDirty(int cx, int cy, int r, pixel::native_t color)
|
|
|
1624
1678
|
const ClipRect *clip = &clipStack_[clipDepth_];
|
|
1625
1679
|
if (cx + r < clip->x0 || cx - r > clip->x1 || cy + r < clip->y0 || cy - r > clip->y1) return false;
|
|
1626
1680
|
|
|
1627
|
-
const std::uint8_t (*spans)[2] = CanvasMath::
|
|
1681
|
+
const std::uint8_t (*spans)[2] = CanvasMath::circleRadiusSpans(r);
|
|
1628
1682
|
if (!spans) {
|
|
1629
1683
|
const int rr = r * r;
|
|
1630
1684
|
int dy0 = -r;
|
|
@@ -1773,7 +1827,7 @@ void Canvas::fillCirclesRgb565WorldYSorted(const CircleEntry *circles,
|
|
|
1773
1827
|
int yOffset)
|
|
1774
1828
|
{
|
|
1775
1829
|
if (!pixels_ || !circles || count <= 0 || r <= 0) return;
|
|
1776
|
-
const std::uint8_t (*spans)[2] = CanvasMath::
|
|
1830
|
+
const std::uint8_t (*spans)[2] = CanvasMath::circleRadiusSpans(r);
|
|
1777
1831
|
const int diameter = r * 2 + 1;
|
|
1778
1832
|
const int w = width_;
|
|
1779
1833
|
const int h = height_;
|
|
@@ -3192,8 +3246,8 @@ void Canvas::fillQuarterCircle(int cx, int cy, int r, int quadrant, pixel::nativ
|
|
|
3192
3246
|
void Canvas::fillCircleBox(int x, int y, int size, pixel::native_t color)
|
|
3193
3247
|
{
|
|
3194
3248
|
if (!pixels_) return;
|
|
3195
|
-
const std::uint8_t (*spans)[2] = CanvasMath::
|
|
3196
|
-
if (
|
|
3249
|
+
const std::uint8_t (*spans)[2] = CanvasMath::circleSpans(size);
|
|
3250
|
+
if (size <= 0 || size > 32 || (size & 1)) return;
|
|
3197
3251
|
const ClipRect *clip = &clipStack_[clipDepth_];
|
|
3198
3252
|
|
|
3199
3253
|
if (x > clip->x1 || y > clip->y1 || x + size - 1 < clip->x0 || y + size - 1 < clip->y0) return;
|
|
@@ -3208,8 +3262,10 @@ void Canvas::fillCircleBox(int x, int y, int size, pixel::native_t color)
|
|
|
3208
3262
|
for (int row = row0; row <= row1; row++) {
|
|
3209
3263
|
int sy = y + row;
|
|
3210
3264
|
|
|
3211
|
-
int
|
|
3212
|
-
int
|
|
3265
|
+
const int dy2 = row * 2 + 1 - size;
|
|
3266
|
+
const int dx2 = spans ? 0 : CanvasMath::integerSqrt(size * size - dy2 * dy2);
|
|
3267
|
+
int sx0 = x + (spans ? spans[row][0] : (size - dx2) / 2);
|
|
3268
|
+
int sx1 = x + (spans ? spans[row][1] : (size + dx2 - 1) / 2);
|
|
3213
3269
|
if (sx0 < clip->x0) sx0 = clip->x0;
|
|
3214
3270
|
if (sx1 > clip->x1) sx1 = clip->x1;
|
|
3215
3271
|
if (sx0 < 0) sx0 = 0;
|
|
@@ -3241,7 +3297,7 @@ void Canvas::fillRoundedRectBoxesRgb565(const std::int16_t *xs,
|
|
|
3241
3297
|
// four-corner rounded-rect raster.
|
|
3242
3298
|
if (Canvas::antialiasSamples() < 2 && roundedRectIsCircleLike(w, h, tl, tr, br, bl) && h <= 256) {
|
|
3243
3299
|
const std::uint8_t (*cachedSpans)[2] =
|
|
3244
|
-
(w == h) ? CanvasMath::
|
|
3300
|
+
(w == h) ? CanvasMath::circleBoxSpans(w) : nullptr;
|
|
3245
3301
|
std::uint16_t spanX0[256];
|
|
3246
3302
|
std::uint16_t spanX1[256];
|
|
3247
3303
|
if (!cachedSpans) {
|
|
@@ -3334,7 +3390,7 @@ void Canvas::fillRoundedRect(int x, int y, int w, int h, int tl, int tr, int br,
|
|
|
3334
3390
|
// 62fps circle path (its poles are marginally rounder than the integer scanline).
|
|
3335
3391
|
if (Canvas::antialiasSamples() < 2 && w == h &&
|
|
3336
3392
|
tl == w / 2 && tr == w / 2 && br == w / 2 && bl == w / 2 &&
|
|
3337
|
-
|
|
3393
|
+
w > 0 && w <= 32 && !(w & 1)) {
|
|
3338
3394
|
fillCircleBox(x, y, w, color);
|
|
3339
3395
|
return;
|
|
3340
3396
|
}
|
|
@@ -4344,7 +4400,7 @@ void Canvas::drawImageRounded(
|
|
|
4344
4400
|
// lookup per row instead of an integer sqrt, and repeat draws of the
|
|
4345
4401
|
// same radius (every full-size icon, every chunk that touches it) pay
|
|
4346
4402
|
// nothing at all.
|
|
4347
|
-
const std::uint8_t (*spans)[2] = CanvasMath::
|
|
4403
|
+
const std::uint8_t (*spans)[2] = CanvasMath::circleRadiusSpans(rr);
|
|
4348
4404
|
for (int py = y0; py <= y1; py++) {
|
|
4349
4405
|
const int ly = py - dy;
|
|
4350
4406
|
int lo, hi;
|
package/css/animation.h
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
// (inline). Part of the gea CSS animation engine. See docs/geaos-grand-vision.md (M1).
|
|
8
8
|
|
|
9
9
|
#include <cmath>
|
|
10
|
+
#include <algorithm>
|
|
10
11
|
#include <cstdint>
|
|
11
12
|
#include <initializer_list>
|
|
12
13
|
#include <vector>
|
|
@@ -30,6 +31,7 @@ inline ValueKind kindOf(Property p)
|
|
|
30
31
|
case Property::Color:
|
|
31
32
|
case Property::BorderColor:
|
|
32
33
|
return ValueKind::Color;
|
|
34
|
+
case Property::RotateAngle:
|
|
33
35
|
case Property::TransformRotate:
|
|
34
36
|
case Property::TransformRotateX:
|
|
35
37
|
case Property::TransformRotateY:
|
|
@@ -119,11 +121,17 @@ private:
|
|
|
119
121
|
|
|
120
122
|
// One animated property on one node. A 2-keyframe track is a CSS transition; an
|
|
121
123
|
// N-keyframe track is a @keyframes rule. Easing applies per segment (CSS default).
|
|
124
|
+
struct RotationAxis { double x = 0, y = 0, z = 1; };
|
|
125
|
+
struct RotationValue { double angle; RotationAxis axis; };
|
|
126
|
+
|
|
122
127
|
struct Animation {
|
|
123
128
|
int nodeId = -1;
|
|
124
129
|
Property property = Property::Opacity;
|
|
125
130
|
ValueKind kind = ValueKind::Scalar;
|
|
126
131
|
KeyframeList keyframes; // >= 2, sorted by offset
|
|
132
|
+
// Only an individual rotate track owns axes. Keep its angle and axis coupled
|
|
133
|
+
// during interpolation; independent scalar axis tracks produce wrong turns.
|
|
134
|
+
std::vector<RotationAxis> rotationAxes;
|
|
127
135
|
Easing easing = Easing::ease();
|
|
128
136
|
uint32_t durationMs = 300;
|
|
129
137
|
uint32_t delayMs = 0;
|
|
@@ -147,6 +155,62 @@ struct Animation {
|
|
|
147
155
|
}
|
|
148
156
|
};
|
|
149
157
|
|
|
158
|
+
inline RotationValue sampleRotation(const Animation &a, double p)
|
|
159
|
+
{
|
|
160
|
+
const auto &kf = a.keyframes;
|
|
161
|
+
std::size_t i = 0;
|
|
162
|
+
while (i + 1 < kf.size() && kf[i + 1].offset <= p) ++i;
|
|
163
|
+
if (i + 1 == kf.size() || p <= kf.front().offset)
|
|
164
|
+
return {kf[i].value, a.rotationAxes[i]};
|
|
165
|
+
const double span = kf[i + 1].offset - kf[i].offset;
|
|
166
|
+
const double t = span > 0 ? (p - kf[i].offset) / span : 0;
|
|
167
|
+
const double u = a.easing.kind() == EasingKind::Linear ? t : a.easing(t);
|
|
168
|
+
RotationValue from{kf[i].value, a.rotationAxes[i]}, to{kf[i + 1].value, a.rotationAxes[i + 1]};
|
|
169
|
+
auto normalize = [](RotationValue &r) {
|
|
170
|
+
const double length = std::sqrt(r.axis.x*r.axis.x + r.axis.y*r.axis.y + r.axis.z*r.axis.z);
|
|
171
|
+
if (length == 0) { r.angle = 0; r.axis = {}; }
|
|
172
|
+
else { r.axis.x /= length; r.axis.y /= length; r.axis.z /= length; }
|
|
173
|
+
};
|
|
174
|
+
normalize(from); normalize(to);
|
|
175
|
+
const bool sameAxis = std::abs(from.axis.x-to.axis.x) < 1e-9 &&
|
|
176
|
+
std::abs(from.axis.y-to.axis.y) < 1e-9 && std::abs(from.axis.z-to.axis.z) < 1e-9;
|
|
177
|
+
// Preserve full turns about a common axis. An identity endpoint adopts the
|
|
178
|
+
// other endpoint's axis (CSS Transforms 2, interpolation of rotate3d).
|
|
179
|
+
if (sameAxis || from.angle == 0 || to.angle == 0)
|
|
180
|
+
return {lerp(from.angle, to.angle, u), from.angle != 0 ? from.axis : to.axis};
|
|
181
|
+
constexpr double radians = 3.14159265358979323846 / 180;
|
|
182
|
+
const double s0 = std::sin(from.angle*radians/2), s1 = std::sin(to.angle*radians/2);
|
|
183
|
+
double q0[4] = {from.axis.x*s0, from.axis.y*s0, from.axis.z*s0, std::cos(from.angle*radians/2)};
|
|
184
|
+
double q1[4] = {to.axis.x*s1, to.axis.y*s1, to.axis.z*s1, std::cos(to.angle*radians/2)};
|
|
185
|
+
double dot = 0;
|
|
186
|
+
for (int k = 0; k < 4; ++k) dot += q0[k]*q1[k];
|
|
187
|
+
if (dot < 0) { for (double &v : q1) v = -v; dot = -dot; }
|
|
188
|
+
dot = std::clamp(dot, 0.0, 1.0);
|
|
189
|
+
double w0 = 1-u, w1 = u;
|
|
190
|
+
if (dot < 0.999999) {
|
|
191
|
+
const double theta = std::acos(dot), divisor = std::sin(theta);
|
|
192
|
+
w0 = std::sin((1-u)*theta)/divisor; w1 = std::sin(u*theta)/divisor;
|
|
193
|
+
}
|
|
194
|
+
double q[4], norm = 0;
|
|
195
|
+
for (int k = 0; k < 4; ++k) { q[k] = w0*q0[k] + w1*q1[k]; norm += q[k]*q[k]; }
|
|
196
|
+
norm = std::sqrt(norm);
|
|
197
|
+
if (norm == 0) return {0, {}};
|
|
198
|
+
for (double &v : q) v /= norm;
|
|
199
|
+
const double axisLength = std::sqrt(q[0]*q[0]+q[1]*q[1]+q[2]*q[2]);
|
|
200
|
+
if (axisLength < 1e-12) return {0, {}};
|
|
201
|
+
return {2*std::atan2(axisLength, q[3])/radians, {q[0]/axisLength,q[1]/axisLength,q[2]/axisLength}};
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
template <typename Apply>
|
|
205
|
+
inline void applyRotationSample(const Animation &a, double p, Apply apply)
|
|
206
|
+
{
|
|
207
|
+
const auto r = sampleRotation(a, p);
|
|
208
|
+
apply(Property::RotateAngle, static_cast<int>(std::llround(r.angle*10)));
|
|
209
|
+
apply(Property::RotateAxisX, static_cast<int>(std::llround(r.axis.x*1000000)));
|
|
210
|
+
apply(Property::RotateAxisY, static_cast<int>(std::llround(r.axis.y*1000000)));
|
|
211
|
+
apply(Property::RotateAxisZ, static_cast<int>(std::llround(r.axis.z*1000000)));
|
|
212
|
+
}
|
|
213
|
+
|
|
150
214
|
inline double sampleSegment(const Animation &a, const Keyframe &k0, const Keyframe &k1, double p)
|
|
151
215
|
{
|
|
152
216
|
const double span = k1.offset - k0.offset;
|
package/css/declarative.h
CHANGED
|
@@ -34,6 +34,7 @@ public:
|
|
|
34
34
|
// Call once after an app mounts; nowMs is the current frame clock.
|
|
35
35
|
static void scanAndStart(uint32_t nowMs)
|
|
36
36
|
{
|
|
37
|
+
#if GEA_CSS_ANIMATIONS
|
|
37
38
|
gea::embedded::ui::Tree &tree = gea::embedded::ui::Tree::instance();
|
|
38
39
|
const int count = tree.nodeCount();
|
|
39
40
|
for (int id = 0; id < count; ++id) {
|
|
@@ -41,9 +42,13 @@ public:
|
|
|
41
42
|
if (!kind || kind[0] == '\0') continue;
|
|
42
43
|
startForNode(tree, id, kind, nowMs);
|
|
43
44
|
}
|
|
45
|
+
#else
|
|
46
|
+
(void)nowMs;
|
|
47
|
+
#endif
|
|
44
48
|
}
|
|
45
49
|
|
|
46
50
|
private:
|
|
51
|
+
#if GEA_CSS_ANIMATIONS
|
|
47
52
|
static int attrInt(gea::embedded::ui::Tree &tree, int id, const char *name, int def)
|
|
48
53
|
{
|
|
49
54
|
const char *v = tree.getAttribute(id, name);
|
|
@@ -126,6 +131,7 @@ private:
|
|
|
126
131
|
startOne(Property::Height, from, to);
|
|
127
132
|
}
|
|
128
133
|
}
|
|
134
|
+
#endif
|
|
129
135
|
};
|
|
130
136
|
|
|
131
137
|
} // namespace gea::css
|
package/css/engine.h
CHANGED
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
|
|
26
26
|
namespace gea::css {
|
|
27
27
|
|
|
28
|
+
#if GEA_CSS_ANIMATIONS
|
|
28
29
|
class AnimationEngine {
|
|
29
30
|
public:
|
|
30
31
|
static AnimationEngine &instance()
|
|
@@ -65,7 +66,12 @@ public:
|
|
|
65
66
|
while (groupEnd < running_.size() && sameTimeline(first, running_[groupEnd])) ++groupEnd;
|
|
66
67
|
if (pr.active) {
|
|
67
68
|
for (std::size_t j = i; j < groupEnd; ++j) {
|
|
68
|
-
|
|
69
|
+
const auto &a = running_[j].anim;
|
|
70
|
+
if (!a.rotationAxes.empty())
|
|
71
|
+
applyRotationSample(a, pr.p, [&](Property property, int value) {
|
|
72
|
+
gea::embedded::ui::applyAnimatedStyleValue(a.nodeId, property, value);
|
|
73
|
+
});
|
|
74
|
+
else applyValue(a, sampleTrack(a, pr.p));
|
|
69
75
|
}
|
|
70
76
|
}
|
|
71
77
|
if (pr.done)
|
|
@@ -220,4 +226,22 @@ private:
|
|
|
220
226
|
int nextHandle_ = 1;
|
|
221
227
|
};
|
|
222
228
|
|
|
229
|
+
#else
|
|
230
|
+
// The shared runtime still calls tick/clear in an animation-free app. These
|
|
231
|
+
// compile away without allocating an active-list singleton. A native producer
|
|
232
|
+
// must retain support; accidental use fails at compile time rather than dropping
|
|
233
|
+
// an animation silently.
|
|
234
|
+
class AnimationEngine {
|
|
235
|
+
public:
|
|
236
|
+
static AnimationEngine &instance() { static AnimationEngine engine; return engine; }
|
|
237
|
+
int start(Animation, uint32_t) = delete;
|
|
238
|
+
void cancel(int) {}
|
|
239
|
+
void cancelNode(int) {}
|
|
240
|
+
void clear() {}
|
|
241
|
+
bool active() const { return false; }
|
|
242
|
+
std::size_t count() const { return 0; }
|
|
243
|
+
void tick(uint32_t) {}
|
|
244
|
+
};
|
|
245
|
+
#endif
|
|
246
|
+
|
|
223
247
|
} // namespace gea::css
|