@geastack/engine 0.1.20 → 0.1.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/canvas.cpp +150 -27
- package/image_store.cpp +308 -1
- package/package.json +1 -1
- package/ui/CSS_FEATURES.md +51 -0
- package/ui/canvas_element.cpp +12 -16
- package/ui/core.cpp +10 -7
- package/ui/document.cpp +25 -0
- package/ui/input.cpp +341 -11
- package/ui/input_render.cpp +62 -17
- package/ui/input_retirement.h +3 -0
- package/ui/internal.h +38 -1
- package/ui/layout.cpp +68 -16
- package/ui/layout_snapshot.cpp +119 -70
- package/ui/layout_snapshot.h +1 -0
- package/ui/node_features.h +6 -0
- package/ui/node_model.h +23 -2
- package/ui/render.cpp +1154 -64
- package/ui/root_scroll_refresh.cpp +372 -66
- package/ui/root_scroll_refresh.h +4 -0
- package/ui/style.cpp +74 -21
- package/ui/style.h +18 -1
- package/ui/svg_element.h +98 -0
- package/ui/svg_element_impl.h +1589 -0
- package/ui/svg_geometry.h +1767 -0
- package/ui/text.cpp +7 -6
- package/ui/tree_events.cpp +15 -0
- package/ui/tree_internal.h +12 -0
- package/ui/tree_nodes.cpp +37 -2
- package/ui/tree_render.cpp +290 -22
- package/ui/tree_state.h +9 -0
- package/ui/tree_style.cpp +32 -0
- package/ui/view.cpp +27 -9
- package/ui/viewport_region.cpp +53 -0
- package/ui/viewport_region.h +3 -0
- package/ui/virtual_keyboard.cpp +279 -23
- package/ui/virtual_keyboard_icons.h +114 -0
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>
|
|
@@ -25,6 +26,7 @@
|
|
|
25
26
|
#include <cstring>
|
|
26
27
|
#include <deque>
|
|
27
28
|
#include <initializer_list>
|
|
29
|
+
#include <new>
|
|
28
30
|
#include <string>
|
|
29
31
|
#include <unordered_map>
|
|
30
32
|
#include <unordered_set>
|
|
@@ -770,6 +772,13 @@ void markClassRecomputeStyleDiff(int node, const ComputedStyle &beforeStyle, int
|
|
|
770
772
|
Node &target = state.nodes[node];
|
|
771
773
|
if (beforeImageId == target.image_id && styleExactlyEqual(beforeStyle, target.computedStyle()) && !firstLineChanged) return;
|
|
772
774
|
if (!nodeParticipatesInMountedTree(state, node)) return;
|
|
775
|
+
#if GEA_UI_SVG
|
|
776
|
+
// A shape's style only feeds its svg's scene: repaint that svg alone.
|
|
777
|
+
if (svg::isShape(node)) {
|
|
778
|
+
svg::noteNodeChanged(node);
|
|
779
|
+
return;
|
|
780
|
+
}
|
|
781
|
+
#endif
|
|
773
782
|
const bool hadRecolor = target.render.bg_recolor_pending;
|
|
774
783
|
const bool canRecolor = !target.render.dirty || hadRecolor;
|
|
775
784
|
target.render.text_partial_dirty = 0;
|
|
@@ -1245,6 +1254,16 @@ CssDeclarationId classifyDeclaration(const char *property)
|
|
|
1245
1254
|
if (std::strcmp(property, "font-family") == 0) return CssDeclarationId::FontFamily;
|
|
1246
1255
|
if (std::strcmp(property, "font-size") == 0) return CssDeclarationId::FontSize;
|
|
1247
1256
|
if (std::strcmp(property, "font-stretch") == 0) return CssDeclarationId::FontStretch;
|
|
1257
|
+
#if GEA_UI_SVG
|
|
1258
|
+
if (std::strcmp(property, "fill") == 0) return CssDeclarationId::SvgFill;
|
|
1259
|
+
if (std::strcmp(property, "stroke") == 0) return CssDeclarationId::SvgStroke;
|
|
1260
|
+
if (std::strcmp(property, "stroke-width") == 0) return CssDeclarationId::SvgStrokeWidth;
|
|
1261
|
+
if (std::strcmp(property, "fill-opacity") == 0) return CssDeclarationId::SvgFillOpacity;
|
|
1262
|
+
if (std::strcmp(property, "stroke-opacity") == 0) return CssDeclarationId::SvgStrokeOpacity;
|
|
1263
|
+
if (std::strcmp(property, "stroke-linecap") == 0) return CssDeclarationId::SvgStrokeLinecap;
|
|
1264
|
+
if (std::strcmp(property, "stroke-linejoin") == 0) return CssDeclarationId::SvgStrokeLinejoin;
|
|
1265
|
+
if (std::strcmp(property, "fill-rule") == 0) return CssDeclarationId::SvgFillRule;
|
|
1266
|
+
#endif
|
|
1248
1267
|
if (std::strcmp(property, "font-weight") == 0) return CssDeclarationId::FontWeight;
|
|
1249
1268
|
if (std::strcmp(property, "line-height") == 0) return CssDeclarationId::LineHeight;
|
|
1250
1269
|
if (std::strcmp(property, "text-align") == 0) return CssDeclarationId::TextAlign;
|
|
@@ -10075,6 +10094,21 @@ bool applyKnownResolvedPropertyWithSource(NodeHandle node, CssDeclarationId decl
|
|
|
10075
10094
|
case CssDeclarationId::Opacity:
|
|
10076
10095
|
setStyleValue(node, Property::Opacity, parseOpacity(value), source);
|
|
10077
10096
|
return true;
|
|
10097
|
+
case CssDeclarationId::SvgFill:
|
|
10098
|
+
case CssDeclarationId::SvgStroke:
|
|
10099
|
+
case CssDeclarationId::SvgStrokeWidth:
|
|
10100
|
+
case CssDeclarationId::SvgFillOpacity:
|
|
10101
|
+
case CssDeclarationId::SvgStrokeOpacity:
|
|
10102
|
+
case CssDeclarationId::SvgStrokeLinecap:
|
|
10103
|
+
case CssDeclarationId::SvgStrokeLinejoin:
|
|
10104
|
+
case CssDeclarationId::SvgFillRule: {
|
|
10105
|
+
#if GEA_UI_SVG
|
|
10106
|
+
Property property = Property::Count;
|
|
10107
|
+
int encoded = 0;
|
|
10108
|
+
if (svg::cssDeclarationValue(declaration, value.c_str(), property, encoded)) setStyleValue(node, property, encoded, source);
|
|
10109
|
+
#endif
|
|
10110
|
+
return true;
|
|
10111
|
+
}
|
|
10078
10112
|
case CssDeclarationId::BorderColor:
|
|
10079
10113
|
applyBorderColorValue(node, value, source);
|
|
10080
10114
|
return true;
|
|
@@ -13654,42 +13688,49 @@ __attribute__((noinline)) ActiveRulePlanCacheEntry::ActiveRulePlanCacheEntry()
|
|
|
13654
13688
|
}
|
|
13655
13689
|
#endif
|
|
13656
13690
|
|
|
13691
|
+
// Entries past the inline array live in fixed-size chunks allocated with a
|
|
13692
|
+
// nothrow new. A cache must never abort the device: when a chunk cannot be
|
|
13693
|
+
// allocated, tryEmplaceBack returns null and the plan simply goes uncached.
|
|
13694
|
+
// Chunks also avoid the doubling reallocation of a vector, which needed one
|
|
13695
|
+
// contiguous block of up to ~38 KB at boot on boards with fragmented heaps.
|
|
13657
13696
|
class ActiveRulePlanCacheStore {
|
|
13658
13697
|
public:
|
|
13659
|
-
std::size_t
|
|
13698
|
+
static constexpr std::size_t kCapacityLimit = 64;
|
|
13699
|
+
|
|
13700
|
+
std::size_t size() const { return inlineCount_ + spillCount_; }
|
|
13660
13701
|
|
|
13661
13702
|
ActiveRulePlanCacheEntry &operator[](std::size_t index)
|
|
13662
13703
|
{
|
|
13663
|
-
return index < inlineCount_ ? inline_[index] :
|
|
13704
|
+
return index < inlineCount_ ? inline_[index] : spillAt(index - inlineCount_);
|
|
13664
13705
|
}
|
|
13665
13706
|
|
|
13666
13707
|
const ActiveRulePlanCacheEntry &operator[](std::size_t index) const
|
|
13667
13708
|
{
|
|
13668
|
-
return index < inlineCount_ ? inline_[index] :
|
|
13709
|
+
return index < inlineCount_ ? inline_[index] : spillAt(index - inlineCount_);
|
|
13669
13710
|
}
|
|
13670
13711
|
|
|
13671
|
-
ActiveRulePlanCacheEntry
|
|
13712
|
+
ActiveRulePlanCacheEntry *tryEmplaceBack()
|
|
13672
13713
|
{
|
|
13673
13714
|
if (inlineCount_ < kInlineCapacity) {
|
|
13674
13715
|
ActiveRulePlanCacheEntry &entry = inline_[inlineCount_++];
|
|
13675
13716
|
resetActiveRulePlanCacheEntry(entry);
|
|
13676
|
-
return entry;
|
|
13717
|
+
return &entry;
|
|
13677
13718
|
}
|
|
13678
|
-
|
|
13679
|
-
|
|
13719
|
+
const std::size_t chunk = spillCount_ / kChunkEntries;
|
|
13720
|
+
if (chunk >= kMaxChunks) return nullptr;
|
|
13721
|
+
if (!chunks_[chunk]) {
|
|
13722
|
+
chunks_[chunk] = new (std::nothrow) ActiveRulePlanCacheEntry[kChunkEntries];
|
|
13723
|
+
if (!chunks_[chunk]) return nullptr;
|
|
13724
|
+
}
|
|
13725
|
+
ActiveRulePlanCacheEntry &entry = spillAt(spillCount_++);
|
|
13680
13726
|
resetActiveRulePlanCacheEntry(entry);
|
|
13681
|
-
return entry;
|
|
13682
|
-
}
|
|
13683
|
-
|
|
13684
|
-
ActiveRulePlanCacheEntry &back()
|
|
13685
|
-
{
|
|
13686
|
-
return spill_.empty() ? inline_[inlineCount_ - 1] : spill_.back();
|
|
13727
|
+
return &entry;
|
|
13687
13728
|
}
|
|
13688
13729
|
|
|
13689
13730
|
void pop_back()
|
|
13690
13731
|
{
|
|
13691
|
-
if (
|
|
13692
|
-
|
|
13732
|
+
if (spillCount_) {
|
|
13733
|
+
resetActiveRulePlanCacheEntry(spillAt(--spillCount_));
|
|
13693
13734
|
return;
|
|
13694
13735
|
}
|
|
13695
13736
|
if (inlineCount_ == 0) return;
|
|
@@ -13699,16 +13740,25 @@ public:
|
|
|
13699
13740
|
void clear()
|
|
13700
13741
|
{
|
|
13701
13742
|
for (std::size_t i = 0; i < inlineCount_; ++i) resetActiveRulePlanCacheEntry(inline_[i]);
|
|
13743
|
+
for (std::size_t i = 0; i < spillCount_; ++i) resetActiveRulePlanCacheEntry(spillAt(i));
|
|
13702
13744
|
inlineCount_ = 0;
|
|
13703
|
-
|
|
13745
|
+
spillCount_ = 0;
|
|
13704
13746
|
}
|
|
13705
13747
|
|
|
13706
13748
|
private:
|
|
13707
13749
|
static constexpr std::size_t kInlineCapacity =
|
|
13708
13750
|
static_cast<std::size_t>(GEA_CSS_ACTIVE_RULE_PLAN_INLINE_CACHE_ENTRIES);
|
|
13751
|
+
static constexpr std::size_t kChunkEntries = 8;
|
|
13752
|
+
static constexpr std::size_t kMaxChunks =
|
|
13753
|
+
kCapacityLimit > kInlineCapacity ? (kCapacityLimit - kInlineCapacity + kChunkEntries - 1) / kChunkEntries : 0;
|
|
13754
|
+
|
|
13755
|
+
ActiveRulePlanCacheEntry &spillAt(std::size_t i) { return chunks_[i / kChunkEntries][i % kChunkEntries]; }
|
|
13756
|
+
const ActiveRulePlanCacheEntry &spillAt(std::size_t i) const { return chunks_[i / kChunkEntries][i % kChunkEntries]; }
|
|
13757
|
+
|
|
13709
13758
|
std::array<ActiveRulePlanCacheEntry, kInlineCapacity> inline_{};
|
|
13710
|
-
std::
|
|
13759
|
+
std::array<ActiveRulePlanCacheEntry *, (kMaxChunks ? kMaxChunks : 1)> chunks_{};
|
|
13711
13760
|
std::size_t inlineCount_ = 0;
|
|
13761
|
+
std::size_t spillCount_ = 0;
|
|
13712
13762
|
};
|
|
13713
13763
|
|
|
13714
13764
|
ActiveRulePlanCacheStore &activeRulePlanCache()
|
|
@@ -14606,12 +14656,12 @@ std::uint16_t cachedStyleApplyOpForCompiledValue(const CssCompiledValue *compile
|
|
|
14606
14656
|
|
|
14607
14657
|
void storeActiveRulePlanForSignature(const RuleCandidateSignature &signature, const ActiveRulePlan &plan)
|
|
14608
14658
|
{
|
|
14609
|
-
static constexpr std::size_t kActiveRulePlanCacheLimit = 64;
|
|
14610
14659
|
if (!activeRulePlanFitsCache(plan)) return;
|
|
14611
14660
|
auto &cache = activeRulePlanCache();
|
|
14612
|
-
if (cache.size() >=
|
|
14613
|
-
cache.
|
|
14614
|
-
|
|
14661
|
+
if (cache.size() >= ActiveRulePlanCacheStore::kCapacityLimit) return;
|
|
14662
|
+
ActiveRulePlanCacheEntry *slot = cache.tryEmplaceBack();
|
|
14663
|
+
if (!slot) return;
|
|
14664
|
+
ActiveRulePlanCacheEntry &entry = *slot;
|
|
14615
14665
|
activeRulePlanCacheLastHit() = cache.size() - 1;
|
|
14616
14666
|
copyActiveRulePlanSignature(entry, signature);
|
|
14617
14667
|
const auto &ruleList = rules();
|
|
@@ -18792,6 +18842,9 @@ void Tree::setTagName(int node, const char *tagName)
|
|
|
18792
18842
|
const int16_t id = internTag(tagName ? tagName : "");
|
|
18793
18843
|
if (state.nodes[node].tag_id == id) return;
|
|
18794
18844
|
state.nodes[node].tag_id = id;
|
|
18845
|
+
#if GEA_UI_SVG
|
|
18846
|
+
svg::noteTagChanged(node);
|
|
18847
|
+
#endif
|
|
18795
18848
|
recomputeSubtreeClassStyles(node);
|
|
18796
18849
|
}
|
|
18797
18850
|
|
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,98 @@
|
|
|
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. `extra` (up to kExtraDamage rects) gets
|
|
67
|
+
// the further boxes of a rebuild that changed several separate places, and
|
|
68
|
+
// `extraCount` how many; the first box is the returned rect.
|
|
69
|
+
constexpr int kExtraDamage = 3;
|
|
70
|
+
bool damage(int root, int &x0, int &y0, int &x1, int &y1, int (*extra)[4] = nullptr, int *extraCount = nullptr);
|
|
71
|
+
|
|
72
|
+
// Tree hooks.
|
|
73
|
+
void noteTagChanged(int node);
|
|
74
|
+
// Records an attribute on an SVG element (value == nullptr removes it).
|
|
75
|
+
// Returns true when the node is an SVG element.
|
|
76
|
+
bool noteAttribute(int node, const char *name, const char *value);
|
|
77
|
+
// The full attribute value for an SVG element (unbounded, unlike the generic
|
|
78
|
+
// attribute store), or nullptr when the node holds no such SVG attribute.
|
|
79
|
+
const char *attribute(int node, const char *name);
|
|
80
|
+
void noteNodeChanged(int node);
|
|
81
|
+
void releaseNode(int node);
|
|
82
|
+
void clearAll();
|
|
83
|
+
|
|
84
|
+
// Refresh hook: detects changes made by any path (class recompute, :active,
|
|
85
|
+
// structure) by comparing each svg subtree's signature with its last scene.
|
|
86
|
+
void validateScenes();
|
|
87
|
+
|
|
88
|
+
// Rendering.
|
|
89
|
+
void record(const Node &svgNode);
|
|
90
|
+
void paint(const DisplayCommand &command);
|
|
91
|
+
|
|
92
|
+
// Hit test inside an svg root whose box contains (x, y): the topmost shape
|
|
93
|
+
// under the point, or -1 when no shape paints there.
|
|
94
|
+
int hitTest(int rootId, int x, int y);
|
|
95
|
+
|
|
96
|
+
} // namespace gea::embedded::ui::svg
|
|
97
|
+
|
|
98
|
+
#endif // GEA_UI_SVG
|