@geastack/engine 0.1.6 → 0.1.8

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.
@@ -34,7 +34,7 @@ bool hasTransformState(const Node &node)
34
34
  // runs before those bumps) doesn't trigger the scan-then-invalidate that regressed
35
35
  // fps before. A transform ADD routes through setStyle → clears the durable cache.
36
36
  if (!ViewRenderer::anyTransformActive()) return false;
37
- const RareStyle &rs = rstyle(node.style); // one pool lookup, not 11
37
+ const RareStyle &rs = rstyle(node.computedStyle()); // one pool lookup, not 11
38
38
  return hasIndividualLinearTransform(rs) || hadIndividualLinearTransform(node.render) ||
39
39
  rs.transform_rotate != 0 ||
40
40
  node.render.previous_transform_rotate != 0 ||
@@ -62,17 +62,11 @@ bool hasTransformState(const Node &node)
62
62
  node.render.previous_perspective > 0;
63
63
  }
64
64
 
65
- int alignedAbsoluteOffset(const Node &parent, const Node &child, bool horizontal)
65
+ template <int side>
66
+ int resolvedPositionOffset(const Node &child, int basis)
66
67
  {
67
- int x, y, width, height;
68
- LayoutEngine::absoluteContainingArea(parent, child, x, y, width, height);
69
- return LayoutEngine::alignedAbsoluteOffset(parent, child, horizontal, &parent, horizontal ? x : y, horizontal ? width : height);
70
- }
71
-
72
- int resolvedPositionOffset(const Node &child, int side, int basis)
73
- {
74
- int offset = child.style.pos_offsets[side] != kUnset ? child.style.pos_offsets[side] : 0;
75
- const int percent = child.style.pos_offset_percent[side];
68
+ int offset = GEA_CSS_POSITION_PX(child.computedStyle(), side) != kUnset ? GEA_CSS_POSITION_PX(child.computedStyle(), side) : 0;
69
+ const int percent = GEA_CSS_POSITION_PERCENT(child.computedStyle(), side);
76
70
  if (percent != kUnset) {
77
71
  const int numerator = basis * percent;
78
72
  offset += (numerator + (numerator >= 0 ? 500 : -500)) / 1000;
@@ -80,47 +74,48 @@ int resolvedPositionOffset(const Node &child, int side, int basis)
80
74
  return offset;
81
75
  }
82
76
 
83
- bool hasPositionOffset(const Node &node, int side)
77
+ template <int side>
78
+ bool hasPositionOffset(const Node &node)
84
79
  {
85
- return node.style.pos_offsets[side] != kUnset || node.style.pos_offset_percent[side] != kUnset;
80
+ return GEA_CSS_POSITION_PX(node.computedStyle(), side) != kUnset || GEA_CSS_POSITION_PERCENT(node.computedStyle(), side) != kUnset;
86
81
  }
87
82
 
88
83
  bool hasExplicitWidth(const Node &node)
89
84
  {
90
- return node.style.width != kUnset || node.style.width_percent != kUnset;
85
+ return node.computedStyle().width != kUnset || node.computedStyle().width_percent != kUnset;
91
86
  }
92
87
 
93
88
  bool hasExplicitHeight(const Node &node)
94
89
  {
95
- return node.style.height != kUnset || node.style.height_percent != kUnset;
90
+ return node.computedStyle().height != kUnset || node.computedStyle().height_percent != kUnset;
96
91
  }
97
92
 
98
93
  bool retainableAbsoluteLayoutNode(const Node &node)
99
94
  {
100
- if ((!isViewLikeNodeType(node.type) && node.type != NodeType::Image) || node.style.position != 1) return false;
95
+ if ((!isViewLikeNodeType(node.type) && node.type != NodeType::Image) || node.computedStyle().position != 1) return false;
101
96
  if (node.parent < 0) return false;
102
97
  const Node &parent = Tree::instance().nodes()[node.parent];
103
98
  // A static wrapper cannot supply the offsets for a more distant containing
104
99
  // block. Let the full positioning pass resolve that ancestor instead.
105
- if (parent.parent >= 0 && parent.style.position == 0) return false;
100
+ if (parent.parent >= 0 && parent.computedStyle().position == 0) return false;
106
101
  // Grid area geometry and its percentage bases belong to the grid pass.
107
- if (isDisplayGrid(Tree::instance().nodes()[node.parent].style)) return false;
102
+ if (isDisplayGrid(parent.computedStyle())) return false;
108
103
  if (!hasExplicitWidth(node) || !hasExplicitHeight(node)) return false;
109
104
  if (node.first_child >= 0) {
110
- if (node.style.width != kUnset && node.style.width != node.layout.width) return false;
111
- if (node.style.height != kUnset && node.style.height != node.layout.height) return false;
105
+ if (node.computedStyle().width != kUnset && node.computedStyle().width != node.layout.width) return false;
106
+ if (node.computedStyle().height != kUnset && node.computedStyle().height != node.layout.height) return false;
112
107
  if (node.layout.width != node.layout.previous_width || node.layout.height != node.layout.previous_height) return false;
113
108
  }
114
- if (node.style.min_width != 0 ||
115
- node.style.min_height != 0 ||
116
- node.style.max_width != kUnset ||
117
- node.style.max_height != kUnset) return false;
118
- if (node.style.flex != 0 ||
119
- node.style.padding[0] ||
120
- node.style.padding[1] ||
121
- node.style.padding[2] ||
122
- node.style.padding[3]) return false;
123
- if (node.style.margin[0] || node.style.margin[1] || node.style.margin[2] || node.style.margin[3]) return false;
109
+ if ((node.computedStyle().min_width != kUnset && node.computedStyle().min_width != 0) ||
110
+ (node.computedStyle().min_height != kUnset && node.computedStyle().min_height != 0) ||
111
+ node.computedStyle().max_width != kUnset ||
112
+ node.computedStyle().max_height != kUnset) return false;
113
+ if (node.computedStyle().flex != 0 ||
114
+ node.computedStyle().padding[0] ||
115
+ node.computedStyle().padding[1] ||
116
+ node.computedStyle().padding[2] ||
117
+ node.computedStyle().padding[3]) return false;
118
+ if (node.computedStyle().margin[0] || node.computedStyle().margin[1] || node.computedStyle().margin[2] || node.computedStyle().margin[3]) return false;
124
119
  return true;
125
120
  }
126
121
 
@@ -128,14 +123,14 @@ bool retainableAbsoluteNode(const Node &node)
128
123
  {
129
124
  if (!retainableAbsoluteLayoutNode(node)) return false;
130
125
  if (hasTransformState(node)) return false;
131
- if (rstyle(node.style).transform_origin_x != node.render.previous_transform_origin_x ||
132
- rstyle(node.style).transform_origin_y != node.render.previous_transform_origin_y) return false;
126
+ if (rstyle(node.computedStyle()).transform_origin_x != node.render.previous_transform_origin_x ||
127
+ rstyle(node.computedStyle()).transform_origin_y != node.render.previous_transform_origin_y) return false;
133
128
  return true;
134
129
  }
135
130
 
136
131
  bool retainableStaticTransformedPaintNode(const Node &node)
137
132
  {
138
- if (!isViewLikeNodeType(node.type) || node.style.position != 1) return false;
133
+ if (!isViewLikeNodeType(node.type) || node.computedStyle().position != 1) return false;
139
134
  if (node.parent < 0) return false;
140
135
  if (!hasTransformState(node) || node.render.transform_dirty) return false;
141
136
  if (node.layout.x != node.layout.previous_x ||
@@ -143,8 +138,8 @@ bool retainableStaticTransformedPaintNode(const Node &node)
143
138
  node.layout.width != node.layout.previous_width ||
144
139
  node.layout.height != node.layout.previous_height)
145
140
  return false;
146
- if (rstyle(node.style).transform_origin_x != node.render.previous_transform_origin_x ||
147
- rstyle(node.style).transform_origin_y != node.render.previous_transform_origin_y)
141
+ if (rstyle(node.computedStyle()).transform_origin_x != node.render.previous_transform_origin_x ||
142
+ rstyle(node.computedStyle()).transform_origin_y != node.render.previous_transform_origin_y)
148
143
  return false;
149
144
  return true;
150
145
  }
@@ -166,23 +161,27 @@ int AbsoluteLeafRefresh::mode()
166
161
  auto &state = treeState();
167
162
  auto &perf = refreshPerfStatsMutable();
168
163
  ScopedRefreshStat timer(perf.treeAbsModeUs);
169
- perf.treeAbsModeCalls++;
164
+ GEA_REFRESH_PERF(perf.treeAbsModeCalls++);
170
165
  int dirtyNodes = 0;
171
166
  for (int i = 0; i < state.nodeCount; i++) {
172
167
  if (state.nodes[i].render.dirty)
173
168
  dirtyNodes++;
174
169
  }
175
- perf.treeAbsModeDirtyNodes += dirtyNodes;
170
+ GEA_REFRESH_PERF(perf.treeAbsModeDirtyNodes += dirtyNodes);
176
171
  if (dirtyNodes == 0) {
177
- perf.treeAbsModeNoop++;
172
+ GEA_REFRESH_PERF(perf.treeAbsModeNoop++);
178
173
  return -1;
179
174
  }
180
175
  auto reject = [&](int node, int reason) {
181
- perf.treeAbsModeFull++;
182
- perf.treeAbsModeRejectNode = node;
183
- perf.treeAbsModeRejectReason = reason;
176
+ GEA_REFRESH_PERF(perf.treeAbsModeFull++);
177
+ GEA_REFRESH_PERF(perf.treeAbsModeRejectNode = node);
178
+ GEA_REFRESH_PERF(perf.treeAbsModeRejectReason = reason);
184
179
  return 0;
185
180
  };
181
+ // A structural rebuild can carry sizing changes that the position-only
182
+ // path cannot resolve (percentage dimensions, class recomputation, etc.).
183
+ // Honor that invalidation before deciding individual nodes are retainable.
184
+ if (state.displayListRebuildStructural) return reject(-1, 10);
186
185
  for (int i = 0; i < state.nodeCount; i++) {
187
186
  Node *n = &state.nodes[i];
188
187
  if (!n->render.dirty) continue;
@@ -209,9 +208,9 @@ int AbsoluteLeafRefresh::mode()
209
208
  if (n->type == NodeType::Text && n->render.text_layout_stable &&
210
209
  n->parent >= 0 && n->first_child < 0) {
211
210
  if (hasTransformState(*n)) return reject(i, 3);
212
- if (rstyle(n->style).transform_origin_x != n->render.previous_transform_origin_x ||
213
- rstyle(n->style).transform_origin_y != n->render.previous_transform_origin_y) return reject(i, 4);
214
- if (n->style.position != 1 &&
211
+ if (rstyle(n->computedStyle()).transform_origin_x != n->render.previous_transform_origin_x ||
212
+ rstyle(n->computedStyle()).transform_origin_y != n->render.previous_transform_origin_y) return reject(i, 4);
213
+ if (n->computedStyle().position != 1 &&
215
214
  (n->layout.x != n->layout.previous_x ||
216
215
  n->layout.y != n->layout.previous_y ||
217
216
  n->layout.width != n->layout.previous_width ||
@@ -232,47 +231,63 @@ int AbsoluteLeafRefresh::mode()
232
231
  // style with no tree-wide relayout. Non-leaf nodes must keep stable size
233
232
  // so their descendants can be translated instead of reflowed.
234
233
  }
235
- perf.treeAbsModeFast++;
234
+ GEA_REFRESH_PERF(perf.treeAbsModeFast++);
236
235
  return 1;
237
236
  }
238
237
 
239
238
  void AbsoluteLeafRefresh::refreshPositions()
240
239
  {
241
240
  auto &state = treeState();
241
+ int cachedParent = -1;
242
+ int areaX = 0, areaY = 0, areaWidth = 0, areaHeight = 0;
242
243
  for (int i = 0; i < state.nodeCount; i++) {
243
244
  Node *n = &state.nodes[i];
244
245
  if (!n->render.dirty) continue;
245
246
  if (n->render.transform_dirty && !retainableAbsoluteLayoutNode(*n)) continue;
246
- if (n->type == NodeType::Text && n->render.text_layout_stable && n->style.position != 1) continue;
247
+ if (n->type == NodeType::Text && n->render.text_layout_stable && n->computedStyle().position != 1) continue;
247
248
  // Reconcile size from style for resized absolute leaves (mode() allowed
248
249
  // the change). Before position so right/bottom-anchored offsets use the
249
250
  // new extent. Percent-sized nodes keep the already-resolved layout box;
250
251
  // the full layout pass owns recomputing them when their containing block
251
252
  // changes.
252
- if (n->style.width != kUnset) n->layout.width = n->style.width;
253
- if (n->style.height != kUnset) n->layout.height = n->style.height;
253
+ if (n->computedStyle().width != kUnset) n->layout.width = n->computedStyle().width;
254
+ if (n->computedStyle().height != kUnset) n->layout.height = n->computedStyle().height;
254
255
  Node *p = &state.nodes[n->parent];
255
- int areaX, areaY, areaWidth, areaHeight;
256
- LayoutEngine::absoluteContainingArea(*p, *n, areaX, areaY, areaWidth, areaHeight);
256
+ // Absolute siblings share their parent's padding box. The cache lasts
257
+ // only for this loop: visiting a different parent invalidates it before
258
+ // any parent/ancestor movement can affect the next sibling group.
259
+ // Grid areas depend on the child, and fixed boxes have separate rules.
260
+ const bool shareArea = n->computedStyle().position == 1 && !isDisplayGrid(p->computedStyle());
261
+ if (!shareArea || cachedParent != n->parent) {
262
+ LayoutEngine::absoluteContainingArea(*p, *n, areaX, areaY, areaWidth, areaHeight);
263
+ cachedParent = shareArea ? n->parent : -1;
264
+ #if GEA_EMBEDDED_UI_REFRESH_PERF
265
+ GEA_REFRESH_PERF(refreshPerfStatsMutable().treeAbsContainingAreaCalls++);
266
+ #endif
267
+ } else {
268
+ #if GEA_EMBEDDED_UI_REFRESH_PERF
269
+ GEA_REFRESH_PERF(refreshPerfStatsMutable().treeAbsContainingAreaHits++);
270
+ #endif
271
+ }
257
272
  const int before_x = n->layout.x;
258
273
  const int before_y = n->layout.y;
259
274
  int parent_x = p->layout.x;
260
- if (p->style.overflow == 2 && scrollsOverflowX(p->style)) parent_x -= p->layout.scroll_x;
261
- if (hasPositionOffset(*n, 3))
262
- n->layout.x = parent_x + areaX + resolvedPositionOffset(*n, 3, areaWidth);
263
- else if (hasPositionOffset(*n, 1))
264
- n->layout.x = parent_x + areaX + areaWidth - n->layout.width - resolvedPositionOffset(*n, 1, areaWidth);
275
+ if (p->computedStyle().overflow == 2 && scrollsOverflowX(p->computedStyle())) parent_x -= p->layout.scroll_x;
276
+ if (hasPositionOffset<3>(*n))
277
+ n->layout.x = parent_x + areaX + resolvedPositionOffset<3>(*n, areaWidth);
278
+ else if (hasPositionOffset<1>(*n))
279
+ n->layout.x = parent_x + areaX + areaWidth - n->layout.width - resolvedPositionOffset<1>(*n, areaWidth);
265
280
  else
266
- n->layout.x = parent_x + alignedAbsoluteOffset(*p, *n, true);
281
+ n->layout.x = parent_x + LayoutEngine::alignedAbsoluteOffset(*p, *n, true, p, areaX, areaWidth);
267
282
 
268
283
  int parent_y = p->layout.y;
269
- if (p->style.overflow == 2 && scrollsOverflowY(p->style)) parent_y -= p->layout.scroll_y;
270
- if (hasPositionOffset(*n, 0))
271
- n->layout.y = parent_y + areaY + resolvedPositionOffset(*n, 0, areaHeight);
272
- else if (hasPositionOffset(*n, 2))
273
- n->layout.y = parent_y + areaY + areaHeight - n->layout.height - resolvedPositionOffset(*n, 2, areaHeight);
284
+ if (p->computedStyle().overflow == 2 && scrollsOverflowY(p->computedStyle())) parent_y -= p->layout.scroll_y;
285
+ if (hasPositionOffset<0>(*n))
286
+ n->layout.y = parent_y + areaY + resolvedPositionOffset<0>(*n, areaHeight);
287
+ else if (hasPositionOffset<2>(*n))
288
+ n->layout.y = parent_y + areaY + areaHeight - n->layout.height - resolvedPositionOffset<2>(*n, areaHeight);
274
289
  else
275
- n->layout.y = parent_y + alignedAbsoluteOffset(*p, *n, false);
290
+ n->layout.y = parent_y + LayoutEngine::alignedAbsoluteOffset(*p, *n, false, p, areaY, areaHeight);
276
291
  translateDescendantLayouts(state, i, n->layout.x - before_x, n->layout.y - before_y);
277
292
  }
278
293
  }
package/ui/core.cpp CHANGED
@@ -4,6 +4,7 @@
4
4
  #include "document.h"
5
5
  #include "refresh_perf.h"
6
6
  #include "tree_state.h"
7
+ #include "tree_inspection.h"
7
8
 
8
9
  namespace gea::embedded::ui {
9
10
 
@@ -15,7 +16,7 @@ Tree &Tree::instance()
15
16
 
16
17
  void Tree::markDisplayListDirty()
17
18
  {
18
- refreshPerfStatsMutable().treeMarkDisplayListDirtyCalls++;
19
+ GEA_REFRESH_PERF(refreshPerfStatsMutable().treeMarkDisplayListDirtyCalls++);
19
20
  auto &state = treeState();
20
21
  state.displayListDirty = true;
21
22
  // Structural: the pending rebuild may change draw order / which commands
@@ -25,7 +26,7 @@ void Tree::markDisplayListDirty()
25
26
 
26
27
  void Tree::markDisplayListContentDirty()
27
28
  {
28
- refreshPerfStatsMutable().treeMarkDisplayListContentDirtyCalls++;
29
+ GEA_REFRESH_PERF(refreshPerfStatsMutable().treeMarkDisplayListContentDirtyCalls++);
29
30
  // Appearance-only rebuild on existing nodes (no draw-order change): request
30
31
  // the rebuild but leave displayListRebuildStructural alone, so refresh can
31
32
  // replay only the dirty-node regions. A structural change elsewhere in the
@@ -36,7 +37,7 @@ void Tree::markDisplayListContentDirty()
36
37
  void Tree::markNodeDisplayCommandsDirty(int node)
37
38
  {
38
39
  if (node < 0 || node >= kMaxNodes) return;
39
- refreshPerfStatsMutable().treeMarkNodeCommandDirtyCalls++;
40
+ GEA_REFRESH_PERF(refreshPerfStatsMutable().treeMarkNodeCommandDirtyCalls++);
40
41
  auto &state = treeState();
41
42
  state.nodeCommandDirty[node] = 1;
42
43
  const int root = state.mountedRoot;
@@ -50,11 +51,15 @@ void Tree::markNodeDisplayCommandsDirty(int node)
50
51
 
51
52
  void Tree::markScrollDirty(int node)
52
53
  {
54
+ #if GEA_CSS_SCROLLING
53
55
  auto &state = treeState();
54
56
  if (node < 0 || node >= kMaxNodes) return;
55
57
  state.nodes[node].render.scroll_dirty = 1;
56
58
  state.scrollDirtyNodes[node / 64] |= (1ull << (node % 64));
57
59
  state.scrollDirtyAny = true;
60
+ #else
61
+ (void)node;
62
+ #endif
58
63
  }
59
64
 
60
65
  Node *Tree::nodes()
@@ -82,6 +87,24 @@ int Tree::mountedRoot() const { return treeState().mountedRoot; }
82
87
  int Tree::mountedWidth() const { return treeState().mountedWidth; }
83
88
  int Tree::mountedHeight() const { return treeState().mountedHeight; }
84
89
 
90
+ int TreeInspection::nodeCount() { return Tree::instance().nodeCount(); }
91
+ int TreeInspection::mountedWidth() { return Tree::instance().mountedWidth(); }
92
+ bool TreeInspection::hasMountedText(const char *text)
93
+ {
94
+ if (!text) return false;
95
+ const auto &tree = Tree::instance();
96
+ for (int i = 0; i < tree.nodeCount(); ++i) {
97
+ if (tree.node(i).text != text) continue;
98
+ int node = i;
99
+ for (int depth = 0; node >= 0 && node < tree.nodeCount() && depth < tree.nodeCount(); ++depth) {
100
+ if (isDisplayNone(tree.node(node).computedStyle())) break;
101
+ if (node == tree.mountedRoot()) return true;
102
+ node = tree.node(node).parent;
103
+ }
104
+ }
105
+ return false;
106
+ }
107
+
85
108
  bool Tree::displayListRebuildRequired() const { return treeState().displayListDirty; }
86
109
  bool Tree::refreshRequired() const
87
110
  {
package/ui/css_atom.cpp CHANGED
@@ -145,6 +145,12 @@ CssAtomId internCssAtom(const std::string &text)
145
145
  return internCssAtom(text.c_str(), text.size());
146
146
  }
147
147
 
148
+ const std::string &cssAtomString(CssAtomId atom)
149
+ {
150
+ auto &table = atomTable();
151
+ return table[static_cast<std::size_t>(atom) < table.size() ? atom : kInvalidCssAtom];
152
+ }
153
+
148
154
  const char *cssAtomText(CssAtomId atom)
149
155
  {
150
156
  auto &table = atomTable();
package/ui/css_atom.h CHANGED
@@ -16,6 +16,8 @@ CssAtomId findCssAtom(const std::string &text);
16
16
  CssAtomId internCssAtom(const char *text, std::size_t length);
17
17
  CssAtomId internCssAtom(const char *text);
18
18
  CssAtomId internCssAtom(const std::string &text);
19
+ // References remain valid for the process lifetime, including table growth.
20
+ const std::string &cssAtomString(CssAtomId atom);
19
21
  const char *cssAtomText(CssAtomId atom);
20
22
 
21
23
  } // namespace gea::embedded::ui