@geastack/engine 0.1.5
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/LICENSE +202 -0
- package/README.md +29 -0
- package/bitmap_font.cpp +165 -0
- package/canvas.cpp +4608 -0
- package/components/Button.d.ts +4 -0
- package/components/Button.tsx +32 -0
- package/components/Image.d.ts +3 -0
- package/components/Image.tsx +17 -0
- package/components/Text.d.ts +3 -0
- package/components/Text.tsx +9 -0
- package/components/View.d.ts +3 -0
- package/components/View.tsx +24 -0
- package/components/index.d.ts +8 -0
- package/components/index.ts +4 -0
- package/css/animation.h +252 -0
- package/css/declarative.h +131 -0
- package/css/easing.h +160 -0
- package/css/engine.h +223 -0
- package/css/interpolate.h +38 -0
- package/image_store.cpp +807 -0
- package/package.json +62 -0
- package/rasterized_font.cpp +570 -0
- package/touch_runtime.cpp +513 -0
- package/ui/absolute_leaf_refresh.cpp +279 -0
- package/ui/absolute_leaf_refresh.h +12 -0
- package/ui/canvas_element.cpp +2314 -0
- package/ui/canvas_element.h +353 -0
- package/ui/canvas_store.cpp +188 -0
- package/ui/canvas_store.h +59 -0
- package/ui/core.cpp +135 -0
- package/ui/css_atom.cpp +155 -0
- package/ui/css_atom.h +21 -0
- package/ui/dirty_regions.cpp +66 -0
- package/ui/dirty_regions.h +34 -0
- package/ui/display_invalidation.cpp +101 -0
- package/ui/display_invalidation.h +15 -0
- package/ui/document.cpp +356 -0
- package/ui/document.h +101 -0
- package/ui/image.h +16 -0
- package/ui/image_element.cpp +13 -0
- package/ui/image_node.cpp +165 -0
- package/ui/input.cpp +936 -0
- package/ui/input_render.cpp +213 -0
- package/ui/internal.h +567 -0
- package/ui/layout.cpp +2025 -0
- package/ui/layout_snapshot.cpp +82 -0
- package/ui/layout_snapshot.h +12 -0
- package/ui/mirror.h +25 -0
- package/ui/node.cpp +243 -0
- package/ui/node.h +154 -0
- package/ui/node_lifecycle.cpp +137 -0
- package/ui/node_lifecycle.h +13 -0
- package/ui/node_model.h +597 -0
- package/ui/refresh_perf.h +235 -0
- package/ui/refresh_trace.h +68 -0
- package/ui/render.cpp +12097 -0
- package/ui/root_scroll_refresh.cpp +859 -0
- package/ui/root_scroll_refresh.h +30 -0
- package/ui/state_init.h +21 -0
- package/ui/style.cpp +14994 -0
- package/ui/style.h +727 -0
- package/ui/style_values.h +31 -0
- package/ui/text.cpp +2010 -0
- package/ui/text.h +15 -0
- package/ui/text_element.cpp +15 -0
- package/ui/tree_events.cpp +621 -0
- package/ui/tree_events.h +69 -0
- package/ui/tree_internal.h +191 -0
- package/ui/tree_nodes.cpp +628 -0
- package/ui/tree_render.cpp +3138 -0
- package/ui/tree_scroll_mirror.cpp +101 -0
- package/ui/tree_state.cpp +574 -0
- package/ui/tree_state.h +235 -0
- package/ui/tree_style.cpp +698 -0
- package/ui/ui.h +9 -0
- package/ui/view.cpp +2232 -0
- package/ui/view.h +14 -0
- package/ui/view_element.cpp +13 -0
- package/ui/viewport_region.cpp +36 -0
- package/ui/viewport_region.h +12 -0
- package/ui/virtual_keyboard.cpp +908 -0
- package/ui/virtual_keyboard.h +59 -0
- package/vendor/AnimatedGIF/AnimatedGIF.c +982 -0
- package/vendor/AnimatedGIF/AnimatedGIF.h +216 -0
- package/vendor/stb/stb_image.h +7988 -0
- package/vendor/stb/stb_truetype.h +5079 -0
package/ui/core.cpp
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
#include "internal.h"
|
|
3
|
+
#include "display.h"
|
|
4
|
+
#include "document.h"
|
|
5
|
+
#include "refresh_perf.h"
|
|
6
|
+
#include "tree_state.h"
|
|
7
|
+
|
|
8
|
+
namespace gea::embedded::ui {
|
|
9
|
+
|
|
10
|
+
Tree &Tree::instance()
|
|
11
|
+
{
|
|
12
|
+
static Tree tree;
|
|
13
|
+
return tree;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
void Tree::markDisplayListDirty()
|
|
17
|
+
{
|
|
18
|
+
refreshPerfStatsMutable().treeMarkDisplayListDirtyCalls++;
|
|
19
|
+
auto &state = treeState();
|
|
20
|
+
state.displayListDirty = true;
|
|
21
|
+
// Structural: the pending rebuild may change draw order / which commands
|
|
22
|
+
// exist, so refresh must repaint the whole viewport (see displayListRebuildStructural).
|
|
23
|
+
state.displayListRebuildStructural = true;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
void Tree::markDisplayListContentDirty()
|
|
27
|
+
{
|
|
28
|
+
refreshPerfStatsMutable().treeMarkDisplayListContentDirtyCalls++;
|
|
29
|
+
// Appearance-only rebuild on existing nodes (no draw-order change): request
|
|
30
|
+
// the rebuild but leave displayListRebuildStructural alone, so refresh can
|
|
31
|
+
// replay only the dirty-node regions. A structural change elsewhere in the
|
|
32
|
+
// same frame still sets the flag and forces the full-viewport repaint.
|
|
33
|
+
treeState().displayListDirty = true;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
void Tree::markNodeDisplayCommandsDirty(int node)
|
|
37
|
+
{
|
|
38
|
+
if (node < 0 || node >= kMaxNodes) return;
|
|
39
|
+
refreshPerfStatsMutable().treeMarkNodeCommandDirtyCalls++;
|
|
40
|
+
treeState().nodeCommandDirty[node] = 1;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
void Tree::markScrollDirty(int node)
|
|
44
|
+
{
|
|
45
|
+
auto &state = treeState();
|
|
46
|
+
if (node < 0 || node >= kMaxNodes) return;
|
|
47
|
+
state.nodes[node].render.scroll_dirty = 1;
|
|
48
|
+
state.scrollDirtyNodes[node / 64] |= (1ull << (node % 64));
|
|
49
|
+
state.scrollDirtyAny = true;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
Node *Tree::nodes()
|
|
53
|
+
{
|
|
54
|
+
return treeState().nodes;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const Node *Tree::nodes() const
|
|
58
|
+
{
|
|
59
|
+
return treeState().nodes;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
Node &Tree::node(int id)
|
|
63
|
+
{
|
|
64
|
+
return treeState().nodes[id];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const Node &Tree::node(int id) const
|
|
68
|
+
{
|
|
69
|
+
return treeState().nodes[id];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
int Tree::nodeCount() const { return treeState().nodeCount; }
|
|
73
|
+
int Tree::mountedRoot() const { return treeState().mountedRoot; }
|
|
74
|
+
int Tree::mountedWidth() const { return treeState().mountedWidth; }
|
|
75
|
+
int Tree::mountedHeight() const { return treeState().mountedHeight; }
|
|
76
|
+
|
|
77
|
+
bool Tree::displayListRebuildRequired() const { return treeState().displayListDirty; }
|
|
78
|
+
bool Tree::refreshRequired() const
|
|
79
|
+
{
|
|
80
|
+
const auto &state = treeState();
|
|
81
|
+
int reason = 0;
|
|
82
|
+
if (state.displayListDirty) {
|
|
83
|
+
reason = 1;
|
|
84
|
+
} else if (state.scrollDirtyAny) {
|
|
85
|
+
reason = 2;
|
|
86
|
+
}
|
|
87
|
+
if (!reason) {
|
|
88
|
+
for (int i = 0; i < state.nodeCount; i++) {
|
|
89
|
+
if (state.nodes[i].render.dirty) {
|
|
90
|
+
reason = 4;
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
if (state.nodeCommandDirty[i]) {
|
|
94
|
+
reason = 5;
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
#if !defined(GEA_EMBEDDED_DIRECT_CANVAS_CONTEXT) || !GEA_EMBEDDED_DIRECT_CANVAS_CONTEXT
|
|
100
|
+
if (!reason && !Document::directCanvasContextUsed()) {
|
|
101
|
+
const int root = state.mountedRoot;
|
|
102
|
+
const bool displayBackedCanvasRoot =
|
|
103
|
+
root >= 0 &&
|
|
104
|
+
root < state.nodeCount &&
|
|
105
|
+
state.nodes[root].type == NodeType::Canvas &&
|
|
106
|
+
isDisplayBackedCanvas(root);
|
|
107
|
+
if (!displayBackedCanvasRoot) {
|
|
108
|
+
if (auto *canvas = gea::platform::display::Display::canvas()) {
|
|
109
|
+
if (canvas->dirty(nullptr, nullptr, nullptr, nullptr)) reason = 3;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
#endif
|
|
114
|
+
if (!reason) return false;
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
uint64_t Tree::refreshSerial() const { return treeState().refreshSerial; }
|
|
119
|
+
|
|
120
|
+
void Tree::setDisplayListRebuildRequired(bool required) { treeState().displayListDirty = required; }
|
|
121
|
+
bool Tree::nodeDisplayCommandsDirty(int node) const
|
|
122
|
+
{
|
|
123
|
+
auto &state = treeState();
|
|
124
|
+
return node >= 0 && node < kMaxNodes && state.nodeCommandDirty[node] != 0;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
void Tree::clearNodeDisplayCommandDirty(int node)
|
|
128
|
+
{
|
|
129
|
+
if (node >= 0 && node < kMaxNodes) treeState().nodeCommandDirty[node] = 0;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
int Tree::lastFrameMs() const { return treeState().lastFrameMs; }
|
|
133
|
+
void Tree::setLastFrameMs(int timestampMs) { treeState().lastFrameMs = timestampMs; }
|
|
134
|
+
|
|
135
|
+
} // namespace gea::embedded::ui
|
package/ui/css_atom.cpp
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
#include "css_atom.h"
|
|
3
|
+
|
|
4
|
+
#include <algorithm>
|
|
5
|
+
#include <cstring>
|
|
6
|
+
#include <deque>
|
|
7
|
+
#include <vector>
|
|
8
|
+
|
|
9
|
+
namespace gea::embedded::ui {
|
|
10
|
+
namespace {
|
|
11
|
+
|
|
12
|
+
std::deque<std::string> &atomTable()
|
|
13
|
+
{
|
|
14
|
+
static std::deque<std::string> table = {std::string()};
|
|
15
|
+
return table;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
std::vector<CssAtomId> &atomBuckets()
|
|
19
|
+
{
|
|
20
|
+
static std::vector<CssAtomId> buckets(64, kInvalidCssAtom);
|
|
21
|
+
return buckets;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
std::vector<CssAtomId> &atomNext()
|
|
25
|
+
{
|
|
26
|
+
static std::vector<CssAtomId> next = {kInvalidCssAtom};
|
|
27
|
+
return next;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
std::vector<std::uint32_t> &atomHashes()
|
|
31
|
+
{
|
|
32
|
+
static std::vector<std::uint32_t> hashes = {0};
|
|
33
|
+
return hashes;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
std::uint32_t atomHash(const char *text, std::size_t length)
|
|
37
|
+
{
|
|
38
|
+
const unsigned char *s = reinterpret_cast<const unsigned char *>(text ? text : "");
|
|
39
|
+
std::uint32_t hash = 2166136261u;
|
|
40
|
+
for (std::size_t i = 0; i < length; ++i) {
|
|
41
|
+
hash ^= s[i];
|
|
42
|
+
hash *= 16777619u;
|
|
43
|
+
}
|
|
44
|
+
return hash ? hash : 1u;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
bool atomEquals(const std::string &atom, const char *text, std::size_t length)
|
|
48
|
+
{
|
|
49
|
+
return atom.size() == length && std::memcmp(atom.c_str(), text ? text : "", length) == 0;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
std::size_t nextBucketCount(std::size_t atomCount)
|
|
53
|
+
{
|
|
54
|
+
std::size_t count = 64;
|
|
55
|
+
const std::size_t target = std::max<std::size_t>(atomCount * 2, count);
|
|
56
|
+
while (count < target) count <<= 1u;
|
|
57
|
+
return count;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
void rebuildAtomIndex(std::size_t atomCount)
|
|
61
|
+
{
|
|
62
|
+
auto &table = atomTable();
|
|
63
|
+
auto &buckets = atomBuckets();
|
|
64
|
+
auto &next = atomNext();
|
|
65
|
+
auto &hashes = atomHashes();
|
|
66
|
+
buckets.assign(nextBucketCount(atomCount), kInvalidCssAtom);
|
|
67
|
+
next.assign(table.size(), kInvalidCssAtom);
|
|
68
|
+
hashes.resize(table.size(), 0);
|
|
69
|
+
for (std::size_t i = 1; i < table.size(); ++i) {
|
|
70
|
+
if (hashes[i] == 0) hashes[i] = atomHash(table[i].c_str(), table[i].size());
|
|
71
|
+
const std::size_t bucket = hashes[i] & (buckets.size() - 1);
|
|
72
|
+
next[i] = buckets[bucket];
|
|
73
|
+
buckets[bucket] = static_cast<CssAtomId>(i);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
bool atomIndexNeedsGrow(std::size_t atomCount)
|
|
78
|
+
{
|
|
79
|
+
const auto &buckets = atomBuckets();
|
|
80
|
+
return buckets.empty() || atomCount * 4 >= buckets.size() * 3;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
CssAtomId findCssAtomWithHash(const char *text, std::size_t length, std::uint32_t hash)
|
|
84
|
+
{
|
|
85
|
+
const char *s = text ? text : "";
|
|
86
|
+
auto &table = atomTable();
|
|
87
|
+
auto &buckets = atomBuckets();
|
|
88
|
+
auto &next = atomNext();
|
|
89
|
+
auto &hashes = atomHashes();
|
|
90
|
+
if (buckets.empty()) rebuildAtomIndex(table.size());
|
|
91
|
+
const std::size_t bucket = hash & (buckets.size() - 1);
|
|
92
|
+
for (CssAtomId id = buckets[bucket]; id != kInvalidCssAtom; id = next[id]) {
|
|
93
|
+
if (static_cast<std::size_t>(id) >= table.size()) break;
|
|
94
|
+
if (hashes[id] == hash && atomEquals(table[id], s, length)) return id;
|
|
95
|
+
}
|
|
96
|
+
return kInvalidCssAtom;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
} // namespace
|
|
100
|
+
|
|
101
|
+
CssAtomId findCssAtom(const char *text, std::size_t length)
|
|
102
|
+
{
|
|
103
|
+
const char *s = text ? text : "";
|
|
104
|
+
if (length == 0) return kInvalidCssAtom;
|
|
105
|
+
return findCssAtomWithHash(s, length, atomHash(s, length));
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
CssAtomId findCssAtom(const std::string &text)
|
|
109
|
+
{
|
|
110
|
+
return findCssAtom(text.c_str(), text.size());
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
CssAtomId internCssAtom(const char *text, std::size_t length)
|
|
114
|
+
{
|
|
115
|
+
const char *s = text ? text : "";
|
|
116
|
+
if (length == 0) return kInvalidCssAtom;
|
|
117
|
+
const std::uint32_t hash = atomHash(s, length);
|
|
118
|
+
if (const CssAtomId existing = findCssAtomWithHash(s, length, hash)) return existing;
|
|
119
|
+
auto &table = atomTable();
|
|
120
|
+
if (table.size() >= 0xFFFFu) return kInvalidCssAtom;
|
|
121
|
+
table.emplace_back(s, length);
|
|
122
|
+
auto &next = atomNext();
|
|
123
|
+
auto &hashes = atomHashes();
|
|
124
|
+
next.push_back(kInvalidCssAtom);
|
|
125
|
+
hashes.push_back(hash);
|
|
126
|
+
const CssAtomId id = static_cast<CssAtomId>(table.size() - 1);
|
|
127
|
+
if (atomIndexNeedsGrow(table.size())) {
|
|
128
|
+
rebuildAtomIndex(table.size());
|
|
129
|
+
return id;
|
|
130
|
+
}
|
|
131
|
+
auto &buckets = atomBuckets();
|
|
132
|
+
const std::size_t bucket = hash & (buckets.size() - 1);
|
|
133
|
+
next[id] = buckets[bucket];
|
|
134
|
+
buckets[bucket] = id;
|
|
135
|
+
return id;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
CssAtomId internCssAtom(const char *text)
|
|
139
|
+
{
|
|
140
|
+
return internCssAtom(text, text ? std::strlen(text) : 0);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
CssAtomId internCssAtom(const std::string &text)
|
|
144
|
+
{
|
|
145
|
+
return internCssAtom(text.c_str(), text.size());
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const char *cssAtomText(CssAtomId atom)
|
|
149
|
+
{
|
|
150
|
+
auto &table = atomTable();
|
|
151
|
+
if (atom == kInvalidCssAtom || static_cast<std::size_t>(atom) >= table.size()) return "";
|
|
152
|
+
return table[static_cast<std::size_t>(atom)].c_str();
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
} // namespace gea::embedded::ui
|
package/ui/css_atom.h
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
#pragma once
|
|
3
|
+
|
|
4
|
+
#include <cstddef>
|
|
5
|
+
#include <cstdint>
|
|
6
|
+
#include <string>
|
|
7
|
+
|
|
8
|
+
namespace gea::embedded::ui {
|
|
9
|
+
|
|
10
|
+
using CssAtomId = std::uint16_t;
|
|
11
|
+
|
|
12
|
+
constexpr CssAtomId kInvalidCssAtom = 0;
|
|
13
|
+
|
|
14
|
+
CssAtomId findCssAtom(const char *text, std::size_t length);
|
|
15
|
+
CssAtomId findCssAtom(const std::string &text);
|
|
16
|
+
CssAtomId internCssAtom(const char *text, std::size_t length);
|
|
17
|
+
CssAtomId internCssAtom(const char *text);
|
|
18
|
+
CssAtomId internCssAtom(const std::string &text);
|
|
19
|
+
const char *cssAtomText(CssAtomId atom);
|
|
20
|
+
|
|
21
|
+
} // namespace gea::embedded::ui
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
#include "dirty_regions.h"
|
|
3
|
+
|
|
4
|
+
namespace gea::embedded::ui {
|
|
5
|
+
|
|
6
|
+
int DirtyRegions::area(const Rect *r)
|
|
7
|
+
{
|
|
8
|
+
if (!r || r->x0 > r->x1 || r->y0 > r->y1) return 0;
|
|
9
|
+
return (r->x1 - r->x0 + 1) * (r->y1 - r->y0 + 1);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
DirtyRegions::Rect DirtyRegions::unite(const Rect *a, const Rect *b)
|
|
13
|
+
{
|
|
14
|
+
Rect out = *a;
|
|
15
|
+
if (b->x0 < out.x0) out.x0 = b->x0;
|
|
16
|
+
if (b->y0 < out.y0) out.y0 = b->y0;
|
|
17
|
+
if (b->x1 > out.x1) out.x1 = b->x1;
|
|
18
|
+
if (b->y1 > out.y1) out.y1 = b->y1;
|
|
19
|
+
// Coalesced rects can mix two unrelated node origins. The replay path
|
|
20
|
+
// only short-circuits to the ancestor-chain walk when the origin is
|
|
21
|
+
// definite; mark the rect as multi-source by clearing the origin so
|
|
22
|
+
// the fallback (full drawNodeOrder iteration) runs and stays correct.
|
|
23
|
+
if (a->origin != b->origin) out.origin = -1;
|
|
24
|
+
return out;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
int DirtyRegions::shouldMerge(const Rect *a, const Rect *b)
|
|
28
|
+
{
|
|
29
|
+
if (a->x0 <= b->x1 + 1 && a->x1 + 1 >= b->x0 &&
|
|
30
|
+
a->y0 <= b->y1 + 1 && a->y1 + 1 >= b->y0)
|
|
31
|
+
return 1;
|
|
32
|
+
Rect merged = unite(a, b);
|
|
33
|
+
int merged_area = area(&merged);
|
|
34
|
+
int separate_area = area(a) + area(b);
|
|
35
|
+
return merged_area <= separate_area + 512;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
void DirtyRegions::add(Rect *rects, int *count, int max_count, Rect rect)
|
|
39
|
+
{
|
|
40
|
+
if (!rects || !count || max_count <= 0 || rect.x0 > rect.x1 || rect.y0 > rect.y1) return;
|
|
41
|
+
|
|
42
|
+
for (int i = 0; i < *count; i++) {
|
|
43
|
+
if (!shouldMerge(&rects[i], &rect)) continue;
|
|
44
|
+
rects[i] = unite(&rects[i], &rect);
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (*count < max_count) {
|
|
49
|
+
rects[(*count)++] = rect;
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
int best = 0;
|
|
54
|
+
int best_cost = 0x7fffffff;
|
|
55
|
+
for (int i = 0; i < *count; i++) {
|
|
56
|
+
Rect merged = unite(&rects[i], &rect);
|
|
57
|
+
int cost = area(&merged) - area(&rects[i]);
|
|
58
|
+
if (cost < best_cost) {
|
|
59
|
+
best_cost = cost;
|
|
60
|
+
best = i;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
rects[best] = unite(&rects[best], &rect);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
} // namespace gea::embedded::ui
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
#pragma once
|
|
3
|
+
|
|
4
|
+
namespace gea::embedded::ui {
|
|
5
|
+
|
|
6
|
+
#ifndef GEA_EMBEDDED_DIRTY_REGION_MAX_RECTS
|
|
7
|
+
#define GEA_EMBEDDED_DIRTY_REGION_MAX_RECTS 32
|
|
8
|
+
#endif
|
|
9
|
+
|
|
10
|
+
class DirtyRegions {
|
|
11
|
+
public:
|
|
12
|
+
struct Rect {
|
|
13
|
+
int x0, y0, x1, y1;
|
|
14
|
+
// Originating node id, or -1 for "multi-source / unknown". Set by
|
|
15
|
+
// `add(...)` when a fresh rect is recorded; cleared to -1 when a
|
|
16
|
+
// new rect coalesces with an existing one whose origin differs.
|
|
17
|
+
// The replay path uses this to skip the full `drawNodeOrder`
|
|
18
|
+
// iteration when the rect's only contributing nodes are the
|
|
19
|
+
// origin's ancestor chain (typical for non-overlapping ball-style
|
|
20
|
+
// keyed lists).
|
|
21
|
+
int origin = -1;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
static constexpr int kMaxRects = GEA_EMBEDDED_DIRTY_REGION_MAX_RECTS;
|
|
25
|
+
|
|
26
|
+
static void add(Rect *rects, int *count, int maxCount, Rect rect);
|
|
27
|
+
|
|
28
|
+
private:
|
|
29
|
+
static int area(const Rect *rect);
|
|
30
|
+
static Rect unite(const Rect *a, const Rect *b);
|
|
31
|
+
static int shouldMerge(const Rect *a, const Rect *b);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
} // namespace gea::embedded::ui
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
#include "display_invalidation.h"
|
|
3
|
+
#include "tree_state.h"
|
|
4
|
+
|
|
5
|
+
namespace gea::embedded::ui {
|
|
6
|
+
|
|
7
|
+
bool DisplayInvalidation::retainsDisplayCommands(Property prop)
|
|
8
|
+
{
|
|
9
|
+
switch (prop) {
|
|
10
|
+
case Property::Top:
|
|
11
|
+
case Property::Right:
|
|
12
|
+
case Property::Bottom:
|
|
13
|
+
case Property::Left:
|
|
14
|
+
case Property::TopPercent:
|
|
15
|
+
case Property::RightPercent:
|
|
16
|
+
case Property::BottomPercent:
|
|
17
|
+
case Property::LeftPercent:
|
|
18
|
+
// Position changes are handled by translateNodeCommands (render.cpp)
|
|
19
|
+
// which shifts each command's bbox by (dx, dy) without rebuilding.
|
|
20
|
+
return true;
|
|
21
|
+
default:
|
|
22
|
+
// Opacity is intentionally NOT retained here. render.cpp only emits a
|
|
23
|
+
// SetAlpha command when style.opacity < 255, so a node recorded at
|
|
24
|
+
// opacity=255 has NO SetAlpha command and an in-place "retain" patch
|
|
25
|
+
// can't toggle its visibility. Opacity is instead routed through
|
|
26
|
+
// rebuildsNodeDisplayCommands(): a *leaf* toggling strictly between 0
|
|
27
|
+
// and 255 (e.g. a destroyed brick in tilt-breakout, a hidden
|
|
28
|
+
// button-tetris block) re-records just that node and stays on the
|
|
29
|
+
// direct-replay fast path. Partial opacity or non-leaf nodes fall
|
|
30
|
+
// through to markDisplayListDirty for a correct full rebuild — see the
|
|
31
|
+
// value/leaf gate in tree_style.cpp. (A future patch-SetAlpha-in-place
|
|
32
|
+
// optimization could keep per-frame fade animations on the fast path
|
|
33
|
+
// too.)
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
bool DisplayInvalidation::rebuildsNodeDisplayCommands(Property prop)
|
|
39
|
+
{
|
|
40
|
+
switch (prop) {
|
|
41
|
+
case Property::Display:
|
|
42
|
+
case Property::Opacity:
|
|
43
|
+
case Property::BackgroundColor:
|
|
44
|
+
case Property::ActiveBackgroundColor:
|
|
45
|
+
case Property::Color:
|
|
46
|
+
case Property::BorderColor:
|
|
47
|
+
case Property::BorderTopWidth:
|
|
48
|
+
case Property::BorderRightWidth:
|
|
49
|
+
case Property::BorderBottomWidth:
|
|
50
|
+
case Property::BorderLeftWidth:
|
|
51
|
+
case Property::BorderTopColor:
|
|
52
|
+
case Property::BorderRightColor:
|
|
53
|
+
case Property::BorderBottomColor:
|
|
54
|
+
case Property::BorderLeftColor:
|
|
55
|
+
case Property::BorderRadiusTopLeft:
|
|
56
|
+
case Property::BorderRadiusTopRight:
|
|
57
|
+
case Property::BorderRadiusBottomRight:
|
|
58
|
+
case Property::BorderRadiusBottomLeft:
|
|
59
|
+
case Property::BorderRadiusTopLeftPercent:
|
|
60
|
+
case Property::BorderRadiusTopRightPercent:
|
|
61
|
+
case Property::BorderRadiusBottomRightPercent:
|
|
62
|
+
case Property::BorderRadiusBottomLeftPercent:
|
|
63
|
+
case Property::TransformRotate:
|
|
64
|
+
case Property::TransformRotateX:
|
|
65
|
+
case Property::TransformRotateY:
|
|
66
|
+
case Property::TransformTranslateX:
|
|
67
|
+
case Property::TransformTranslateY:
|
|
68
|
+
case Property::TransformTranslateZ:
|
|
69
|
+
case Property::TransformTranslateXPercent:
|
|
70
|
+
case Property::TransformTranslateYPercent:
|
|
71
|
+
case Property::TransformScaleX:
|
|
72
|
+
case Property::TransformScaleY:
|
|
73
|
+
case Property::TransformOriginX:
|
|
74
|
+
case Property::TransformOriginY:
|
|
75
|
+
case Property::Perspective:
|
|
76
|
+
case Property::PerspectiveOriginX:
|
|
77
|
+
case Property::PerspectiveOriginY:
|
|
78
|
+
case Property::FilterBlur:
|
|
79
|
+
case Property::MaskRightFadeWidth:
|
|
80
|
+
case Property::BoxShadowInset:
|
|
81
|
+
case Property::BoxShadowOffsetX:
|
|
82
|
+
case Property::BoxShadowOffsetY:
|
|
83
|
+
case Property::BoxShadowBlur:
|
|
84
|
+
case Property::BoxShadowSpread:
|
|
85
|
+
case Property::BoxShadowColor:
|
|
86
|
+
case Property::BoxShadowAlpha:
|
|
87
|
+
return true;
|
|
88
|
+
default:
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
bool DisplayInvalidation::nodeDisplayChangeCanStayLocal(int node)
|
|
94
|
+
{
|
|
95
|
+
auto &state = treeState();
|
|
96
|
+
if (node < 0 || node >= state.nodeCount) return false;
|
|
97
|
+
Node *n = &state.nodes[node];
|
|
98
|
+
return n->first_child < 0 && n->type != NodeType::Text;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
} // namespace gea::embedded::ui
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
#pragma once
|
|
3
|
+
|
|
4
|
+
#include "style.h"
|
|
5
|
+
|
|
6
|
+
namespace gea::embedded::ui {
|
|
7
|
+
|
|
8
|
+
class DisplayInvalidation {
|
|
9
|
+
public:
|
|
10
|
+
static bool retainsDisplayCommands(Property prop);
|
|
11
|
+
static bool rebuildsNodeDisplayCommands(Property prop);
|
|
12
|
+
static bool nodeDisplayChangeCanStayLocal(int node);
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
} // namespace gea::embedded::ui
|