@geastack/engine 0.1.7 → 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.
@@ -52,8 +52,8 @@ bool Mirror::nodeIsScrollable(int node) const
52
52
  if (node < 0 || node >= state.nodeCount) return false;
53
53
  Node *n = &state.nodes[node];
54
54
  return isViewLikeNodeType(n->type) &&
55
- ((n->type != NodeType::VirtualList && scrollsOverflowX(n->style) && ViewRenderer::scrollMaxX(*n) > 0) ||
56
- ((n->type == NodeType::VirtualList || scrollsOverflowY(n->style)) && ViewRenderer::scrollMaxY(*n) > 0));
55
+ ((n->type != NodeType::VirtualList && scrollsOverflowX(n->computedStyle()) && ViewRenderer::scrollMaxX(*n) > 0) ||
56
+ ((n->type == NodeType::VirtualList || scrollsOverflowY(n->computedStyle())) && ViewRenderer::scrollMaxY(*n) > 0));
57
57
  #else
58
58
  (void)node; return false;
59
59
  #endif
@@ -72,7 +72,7 @@ void Mirror::setScrollX(int node, int scroll_x) const
72
72
  auto &state = treeState();
73
73
  if (node < 0 || node >= state.nodeCount) return;
74
74
  Node *n = &state.nodes[node];
75
- if (!isViewLikeNodeType(n->type) || !scrollsOverflowX(n->style) || n->type == NodeType::VirtualList) return;
75
+ if (!isViewLikeNodeType(n->type) || !scrollsOverflowX(n->computedStyle()) || n->type == NodeType::VirtualList) return;
76
76
 
77
77
  int max_x = ViewRenderer::scrollMaxX(*n);
78
78
  if (scroll_x < 0) scroll_x = 0;
@@ -106,7 +106,7 @@ void Mirror::setScrollY(int node, int scroll_y) const
106
106
  auto &state = treeState();
107
107
  if (node < 0 || node >= state.nodeCount) return;
108
108
  Node *n = &state.nodes[node];
109
- if (!isViewLikeNodeType(n->type) || (n->type != NodeType::VirtualList && !scrollsOverflowY(n->style))) return;
109
+ if (!isViewLikeNodeType(n->type) || (n->type != NodeType::VirtualList && !scrollsOverflowY(n->computedStyle()))) return;
110
110
 
111
111
  int max_y = ViewRenderer::scrollMaxY(*n);
112
112
  if (scroll_y < 0) scroll_y = 0;
package/ui/tree_state.cpp CHANGED
@@ -4,6 +4,7 @@
4
4
  #include <algorithm>
5
5
  #include <cstddef>
6
6
  #include <cstring>
7
+ #include <cstdlib>
7
8
  #include <deque>
8
9
  #include <new>
9
10
  #include <memory>
@@ -115,6 +116,28 @@ std::size_t NodeText::storageBytes()
115
116
  return g_nodeTextStorageBytes;
116
117
  }
117
118
 
119
+ StorageUsage NodeText::storageUsage()
120
+ {
121
+ StorageUsage usage;
122
+ usage.staticBytes = sizeof(g_nodeTextStorageBytes) + sizeof(g_nodeTextPool) + sizeof(g_emptyNodeText);
123
+ usage.addString(g_emptyNodeText);
124
+ if (!g_nodeTextPool) return usage;
125
+ const auto &pool = *g_nodeTextPool;
126
+ usage.addAllocation(g_nodeTextPool, sizeof(NodeTextPool));
127
+ usage.addVector(pool.pages);
128
+ for (const auto *page : pool.pages)
129
+ usage.addAllocation(page, NodeTextPool::kPageEntries * sizeof(NodeTextEntry));
130
+ for (std::size_t index = 0; index < pool.size; ++index) {
131
+ bool free = false;
132
+ // Census only: walking the free chain avoids allocating a temporary
133
+ // live bitmap, and never reads a destroyed union member as a string.
134
+ for (auto handle = pool.freeHead; handle != UINT32_MAX; handle = g_nodeTextPool->at(handle).nextFree)
135
+ if (handle == index) { free = true; break; }
136
+ if (!free) usage.addString(g_nodeTextPool->at(index).text);
137
+ }
138
+ return usage;
139
+ }
140
+
118
141
  NodeText::NodeText(const NodeText &other)
119
142
  {
120
143
  if (!other.empty())
@@ -198,6 +221,7 @@ bool validToken(const std::string &token)
198
221
  return true;
199
222
  }
200
223
 
224
+ #if GEA_UI_CLASS_OVERFLOW
201
225
  std::deque<std::vector<CssAtomId>> &classListOverflowLists()
202
226
  {
203
227
  static std::deque<std::vector<CssAtomId>> lists;
@@ -249,6 +273,9 @@ void releaseClassListOverflow(NodeClassList &list)
249
273
  classListOverflowFreeList().push_back(list.overflowHandle);
250
274
  list.overflowHandle = NodeClassList::kNoOverflow;
251
275
  }
276
+ #else
277
+ void releaseClassListOverflow(NodeClassList &) {}
278
+ #endif
252
279
 
253
280
  bool appendClassAtom(NodeClassList &list, CssAtomId atom)
254
281
  {
@@ -257,11 +284,16 @@ bool appendClassAtom(NodeClassList &list, CssAtomId atom)
257
284
  list.inlineTokens[list.count++] = atom;
258
285
  return true;
259
286
  }
287
+ #if GEA_UI_CLASS_OVERFLOW
260
288
  auto *overflow = ensureClassListOverflow(list);
261
289
  if (!overflow || list.overflowHandle == NodeClassList::kNoOverflow) return false;
262
290
  overflow->push_back(atom);
263
291
  ++list.count;
264
292
  return true;
293
+ #else
294
+ // A violated source proof must fail visibly, never truncate a class list.
295
+ std::abort();
296
+ #endif
265
297
  }
266
298
 
267
299
  void eraseClassAtomAt(NodeClassList &list, std::size_t index)
@@ -271,6 +303,7 @@ void eraseClassAtomAt(NodeClassList &list, std::size_t index)
271
303
  const std::size_t inlineEnd = std::min<std::size_t>(list.count, NodeClassList::kInlineTokenCount);
272
304
  for (std::size_t i = index + 1; i < inlineEnd; ++i)
273
305
  list.inlineTokens[i - 1] = list.inlineTokens[i];
306
+ #if GEA_UI_CLASS_OVERFLOW
274
307
  if (list.count > NodeClassList::kInlineTokenCount) {
275
308
  auto *overflow = classListOverflow(list.overflowHandle);
276
309
  if (overflow && !overflow->empty()) {
@@ -278,12 +311,15 @@ void eraseClassAtomAt(NodeClassList &list, std::size_t index)
278
311
  overflow->erase(overflow->begin());
279
312
  if (overflow->empty()) releaseClassListOverflow(list);
280
313
  }
281
- } else if (list.count > 0) {
314
+ } else
315
+ #endif
316
+ if (list.count > 0) {
282
317
  list.inlineTokens[list.count - 1] = kInvalidCssAtom;
283
318
  }
284
319
  --list.count;
285
320
  return;
286
321
  }
322
+ #if GEA_UI_CLASS_OVERFLOW
287
323
  auto *overflow = classListOverflow(list.overflowHandle);
288
324
  if (!overflow) return;
289
325
  const std::size_t overflowIndex = index - NodeClassList::kInlineTokenCount;
@@ -291,6 +327,7 @@ void eraseClassAtomAt(NodeClassList &list, std::size_t index)
291
327
  overflow->erase(overflow->begin() + static_cast<std::ptrdiff_t>(overflowIndex));
292
328
  --list.count;
293
329
  if (overflow->empty()) releaseClassListOverflow(list);
330
+ #endif
294
331
  }
295
332
 
296
333
  bool classListsEqual(const NodeClassList &a, const NodeClassList &b)
@@ -346,9 +383,11 @@ NodeClassList::NodeClassList(NodeClassList &&other) noexcept
346
383
  {
347
384
  for (std::uint8_t i = 0; i < kInlineTokenCount; ++i)
348
385
  inlineTokens[i] = other.inlineTokens[i];
386
+ #if GEA_UI_CLASS_OVERFLOW
349
387
  overflowHandle = other.overflowHandle;
350
- count = other.count;
351
388
  other.overflowHandle = kNoOverflow;
389
+ #endif
390
+ count = other.count;
352
391
  other.count = 0;
353
392
  for (std::uint8_t i = 0; i < kInlineTokenCount; ++i)
354
393
  other.inlineTokens[i] = kInvalidCssAtom;
@@ -360,9 +399,11 @@ NodeClassList &NodeClassList::operator=(NodeClassList &&other) noexcept
360
399
  clear();
361
400
  for (std::uint8_t i = 0; i < kInlineTokenCount; ++i)
362
401
  inlineTokens[i] = other.inlineTokens[i];
402
+ #if GEA_UI_CLASS_OVERFLOW
363
403
  overflowHandle = other.overflowHandle;
364
- count = other.count;
365
404
  other.overflowHandle = kNoOverflow;
405
+ #endif
406
+ count = other.count;
366
407
  other.count = 0;
367
408
  for (std::uint8_t i = 0; i < kInlineTokenCount; ++i)
368
409
  other.inlineTokens[i] = kInvalidCssAtom;
@@ -449,11 +490,15 @@ CssAtomId NodeClassList::at(std::size_t index) const
449
490
  {
450
491
  if (index >= count) return kInvalidCssAtom;
451
492
  if (index < kInlineTokenCount) return inlineTokens[index];
493
+ #if GEA_UI_CLASS_OVERFLOW
452
494
  const auto *overflow = classListOverflowConst(overflowHandle);
453
495
  if (!overflow) return kInvalidCssAtom;
454
496
  const std::size_t overflowIndex = index - kInlineTokenCount;
455
497
  if (overflowIndex >= overflow->size()) return kInvalidCssAtom;
456
498
  return (*overflow)[overflowIndex];
499
+ #else
500
+ return kInvalidCssAtom;
501
+ #endif
457
502
  }
458
503
 
459
504
  std::string NodeClassList::value() const
@@ -470,7 +515,9 @@ std::string NodeClassList::value() const
470
515
  // Empty override stores own nothing. One allocation contains both metadata
471
516
  // and values; computed styles remain ordinary aligned fields in Node.
472
517
  struct NodeStyleOverrideStore::Block {
473
- std::size_t count = 0, capacity = 0;
518
+ // Entries are unique by Property; geometric growth fits this bound.
519
+ static_assert(static_cast<unsigned>(Property::Count) <= 32768);
520
+ std::uint16_t count = 0, capacity = 0;
474
521
  // Only CSS px overrides allocate unit metadata. Raw numeric styles keep
475
522
  // their compact entries and do not lose precision by reverse-scaling ints.
476
523
  std::unique_ptr<std::vector<std::pair<Property, float>>> cssPixels;
@@ -482,9 +529,11 @@ void appendStyleOverride(NodeStyleOverrideStore &store, NodeStyleOverride entry)
482
529
  {
483
530
  auto *old = store.block;
484
531
  if (!old || old->count == old->capacity) {
485
- const std::size_t capacity = old ? old->capacity * 2 : 2;
532
+ // Small inline styles commonly have three entries. Grow 2 -> 3 -> 4
533
+ // before doubling, so they do not retain an unused fourth entry.
534
+ const std::size_t capacity = old ? (old->capacity < 4 ? old->capacity + 1 : old->capacity * 2) : 2;
486
535
  auto *next = new (::operator new(sizeof(NodeStyleOverrideStore::Block) + capacity * sizeof(NodeStyleOverride))) NodeStyleOverrideStore::Block;
487
- next->capacity = capacity;
536
+ next->capacity = static_cast<std::uint16_t>(capacity);
488
537
  if (old) {
489
538
  next->count = old->count;
490
539
  next->cssPixels = std::move(old->cssPixels);
@@ -533,6 +582,18 @@ void NodeStyleOverrideStore::clear()
533
582
  block = nullptr;
534
583
  }
535
584
  std::size_t NodeStyleOverrideStore::size() const { return block ? block->count : 0; }
585
+ StorageUsage NodeStyleOverrideStore::storageUsage() const
586
+ {
587
+ StorageUsage usage;
588
+ if (!block) return usage;
589
+ usage.addAllocation(block, sizeof(Block) + block->capacity * sizeof(NodeStyleOverride));
590
+ if (block->cssPixels) {
591
+ usage.addAllocation(block->cssPixels.get(), sizeof(*block->cssPixels));
592
+ usage.addVector(*block->cssPixels);
593
+ }
594
+ return usage;
595
+ }
596
+
536
597
  void NodeStyleOverrideStore::set(Property property, int value)
537
598
  {
538
599
  for (std::size_t i = 0; i < size(); ++i) {
@@ -580,6 +641,7 @@ bool NodeStyleOverrideStore::remove(Property property)
580
641
  }
581
642
  const NodeStyleOverride &NodeStyleOverrideStore::at(std::size_t index) const { return block->values()[index]; }
582
643
 
644
+ #if GEA_CSS_CUSTOM_PROPERTIES
583
645
  void NodeCustomPropertyStore::clear()
584
646
  {
585
647
  values.clear();
@@ -693,6 +755,8 @@ const NodeCustomProperty *NodeCustomPropertyStore::getEntry(CssAtomId nameId) co
693
755
  return nullptr;
694
756
  }
695
757
 
758
+ #endif
759
+
696
760
  // File-scope lazy pointer rather than a function-local static. On this Xtensa
697
761
  // toolchain the static-local guard is NOT inlined, so a Meyers singleton pays a
698
762
  // __cxa_guard_acquire CALL on every access — and treeState() sits on the hottest
@@ -700,6 +764,14 @@ const NodeCustomProperty *NodeCustomPropertyStore::getEntry(CssAtomId nameId) co
700
764
  // (the mount task and the frame task never run concurrently), so the guard is
701
765
  // unnecessary; a zero-initialized pointer + null check is one load and a branch.
702
766
  static TreeState *g_treeState = nullptr;
767
+ StorageUsage treeStorageUsage()
768
+ {
769
+ StorageUsage usage;
770
+ usage.staticBytes = sizeof(g_treeState);
771
+ usage.addAllocation(g_treeState, sizeof(TreeState));
772
+ return usage;
773
+ }
774
+
703
775
 
704
776
  TreeState &treeState()
705
777
  {
package/ui/tree_state.h CHANGED
@@ -7,8 +7,10 @@
7
7
  #include "style.h"
8
8
  #include "tree_events.h"
9
9
 
10
+ #include <array>
10
11
  #include <cstddef>
11
12
  #include <cstdint>
13
+ #include <cstdlib>
12
14
  #include <string>
13
15
  #include <memory>
14
16
  #include <vector>
@@ -20,7 +22,11 @@ struct NodeClassList {
20
22
  static constexpr std::uint16_t kNoOverflow = 0xFFFFu;
21
23
 
22
24
  CssAtomId inlineTokens[kInlineTokenCount]{};
25
+ #if GEA_UI_CLASS_OVERFLOW
23
26
  std::uint16_t overflowHandle = kNoOverflow;
27
+ #else
28
+ static constexpr std::uint16_t overflowHandle = kNoOverflow;
29
+ #endif
24
30
  std::uint8_t count = 0;
25
31
 
26
32
  NodeClassList() = default;
@@ -69,6 +75,17 @@ struct NodeStyleOverrideStore {
69
75
  std::size_t size() const;
70
76
  bool empty() const { return size() == 0; }
71
77
  const NodeStyleOverride &at(std::size_t index) const;
78
+ StorageUsage storageUsage() const;
79
+ };
80
+
81
+ // This empty owner is selected only by a complete source/native reachability
82
+ // proof. A violated mutation contract fails loudly instead of dropping styles.
83
+ struct EmptyNodeStyleOverrideStore {
84
+ void clear() {}
85
+ void set(Property, int) { std::abort(); }
86
+ std::size_t size() const { return 0; }
87
+ const NodeStyleOverride &at(std::size_t) const { std::abort(); }
88
+ StorageUsage storageUsage() const { return {}; }
72
89
  };
73
90
 
74
91
  // CSS ::first-line painting is uncommon and line fragments are useful only
@@ -129,8 +146,15 @@ struct NodeCustomProperty {
129
146
  };
130
147
 
131
148
  struct NodeCustomPropertyStore {
132
- std::vector<NodeCustomProperty> values;
149
+ #if GEA_CSS_CUSTOM_PROPERTIES
150
+ using Values = std::vector<NodeCustomProperty>;
151
+ Values values;
152
+ #else
153
+ using Values = std::array<NodeCustomProperty, 0>;
154
+ inline static constexpr Values values{};
155
+ #endif
133
156
 
157
+ #if GEA_CSS_CUSTOM_PROPERTIES
134
158
  void clear();
135
159
  void set(const std::string &name, const std::string &value);
136
160
  void set(CssAtomId nameId, const std::string &value);
@@ -146,6 +170,16 @@ struct NodeCustomPropertyStore {
146
170
  const std::string *get(const std::string &name) const;
147
171
  const std::string *get(CssAtomId nameId) const;
148
172
  const NodeCustomProperty *getEntry(CssAtomId nameId) const;
173
+ #else
174
+ void clear() {}
175
+ void set(const std::string &, const std::string &) {}
176
+ void set(CssAtomId, const std::string &) {}
177
+ void setColor(CssAtomId, const std::string &, std::int32_t, std::int32_t, std::uint8_t) {}
178
+ void setLength(CssAtomId, const std::string &, float, std::uint8_t) {}
179
+ const std::string *get(const std::string &) const { return nullptr; }
180
+ const std::string *get(CssAtomId) const { return nullptr; }
181
+ const NodeCustomProperty *getEntry(CssAtomId) const { return nullptr; }
182
+ #endif
149
183
  };
150
184
 
151
185
  // Generic windowing state for a <virtual-list>. The element renders a small
@@ -176,11 +210,15 @@ struct NodeRareData {
176
210
  // Both members remain ordinary embedded fields with fixed-offset access.
177
211
  [[no_unique_address]] NodeEventListeners listeners;
178
212
  InlineStaticPosition inlineStaticPosition;
179
- NodeAttributeStore attributes;
180
- NodeCustomPropertyStore customProperties;
213
+ [[no_unique_address]] NodeAttributeStore attributes;
214
+ [[no_unique_address]] NodeCustomPropertyStore customProperties;
181
215
  // Authored inline values survive rebuilding the computed custom-property map.
182
- NodeCustomPropertyStore inlineCustomProperties;
216
+ [[no_unique_address]] NodeCustomPropertyStore inlineCustomProperties;
217
+ #if GEA_UI_DEFAULT_STYLES
183
218
  NodeStyleOverrideStore defaultStyles;
219
+ #else
220
+ [[no_unique_address]] EmptyNodeStyleOverrideStore defaultStyles;
221
+ #endif
184
222
  NodeStyleOverrideStore inlineStyles;
185
223
  #if GEA_CSS_GRID
186
224
  CssAtomId inlineGridTemplates[2] = {kInvalidCssAtom, kInvalidCssAtom};
@@ -229,6 +267,13 @@ struct NodeRareData {
229
267
  }
230
268
  };
231
269
 
270
+ struct NodeAuxiliaryStorageUsage {
271
+ StorageUsage tree, text, rare, overrides, dependencies;
272
+ };
273
+ StorageUsage treeStorageUsage();
274
+ StorageUsage styleDependencyStorageUsage();
275
+ NodeAuxiliaryStorageUsage nodeAuxiliaryStorageUsage();
276
+
232
277
  struct TreeState {
233
278
  Node nodes[kMaxNodes];
234
279
  // Attributes and event listeners are no longer dense per-node arrays — they