@geastack/engine 0.1.7 → 0.1.9

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.
@@ -59,8 +59,10 @@ void applyAudioAttribute(Tree &tree, int node, const char *name, const char *val
59
59
  // setEventListener (on the empty->set transition) and NodeEventListeners::clear()
60
60
  // (which every removal path calls).
61
61
  constexpr int kEventTypeCount = 7;
62
+ #if GEA_UI_NODE_LISTENERS
62
63
  int g_listenerTypeCounts[kEventTypeCount] = {};
63
64
  EventListenerId g_nextEventListenerId = 1;
65
+ #endif
64
66
 
65
67
  int eventTypeIndex(const char *type)
66
68
  {
@@ -165,6 +167,55 @@ std::vector<std::unique_ptr<NodeRareData>> g_rareDataPool;
165
167
  std::vector<int16_t> g_rareDataFreeList;
166
168
  } // namespace
167
169
 
170
+ NodeAuxiliaryStorageUsage nodeAuxiliaryStorageUsage()
171
+ {
172
+ NodeAuxiliaryStorageUsage result;
173
+ result.tree = treeStorageUsage();
174
+ result.text = NodeText::storageUsage();
175
+ result.dependencies = styleDependencyStorageUsage();
176
+ auto &usage = result.rare;
177
+ usage.staticBytes = sizeof(g_rareDataPool) + sizeof(g_rareDataFreeList) + sizeof(g_documentKeyDownListener) + sizeof(g_documentRotaryListener);
178
+ #if GEA_UI_NODE_LISTENERS
179
+ usage.staticBytes += sizeof(g_listenerTypeCounts) + sizeof(g_nextEventListenerId);
180
+ #endif
181
+ if (g_documentKeyDownListener) ++usage.untrackedOwners;
182
+ if (g_documentRotaryListener) ++usage.untrackedOwners;
183
+ usage.addVector(g_rareDataPool);
184
+ usage.addVector(g_rareDataFreeList);
185
+ for (const auto &record : g_rareDataPool) {
186
+ usage.addAllocation(record.get(), sizeof(NodeRareData));
187
+ #if GEA_UI_NODE_LISTENERS
188
+ usage.addVector(record->listeners.entries);
189
+ for (const auto &listener : record->listeners.entries)
190
+ if (listener.listener.use_count()) ++usage.untrackedOwners;
191
+ #endif
192
+ #if GEA_UI_NODE_ATTRIBUTES
193
+ for (auto *entry = record->attributes.values.get(); entry; entry = entry->next.get())
194
+ usage.addAllocation(entry, sizeof(NodeAttributeEntry) + entry->nameBytes + entry->valueCapacity);
195
+ #endif
196
+ #if GEA_CSS_CUSTOM_PROPERTIES
197
+ for (const auto *properties : {&record->customProperties, &record->inlineCustomProperties}) {
198
+ usage.addVector(properties->values);
199
+ for (const auto &property : properties->values)
200
+ if (property.value.use_count()) ++usage.untrackedOwners;
201
+ }
202
+ #endif
203
+ result.overrides += record->defaultStyles.storageUsage();
204
+ result.overrides += record->inlineStyles.storageUsage();
205
+ #if GEA_CSS_GRID
206
+ if (record->gridLayout) {
207
+ usage.addAllocation(record->gridLayout.get(), sizeof(GridTrackLayout));
208
+ usage.addVector(record->gridLayout->columnStart); usage.addVector(record->gridLayout->columnEnd);
209
+ usage.addVector(record->gridLayout->rowStart); usage.addVector(record->gridLayout->rowEnd);
210
+ }
211
+ #endif
212
+ #if GEA_CSS_SCROLLING
213
+ usage.addAllocation(record->virtualList.get(), sizeof(VirtualListNodeState));
214
+ #endif
215
+ }
216
+ return result;
217
+ }
218
+
168
219
  NodeRareData &ensureRareData(int node)
169
220
  {
170
221
  auto &state = treeState();
@@ -218,6 +269,7 @@ NodeAttributePtr NodeAttributeEntry::create(const char *name, const char *value)
218
269
  return NodeAttributePtr(entry);
219
270
  }
220
271
 
272
+ #if GEA_UI_NODE_ATTRIBUTES
221
273
  NodeAttributeStore::NodeAttributeStore(const NodeAttributeStore &other)
222
274
  : pressId(other.pressId), pressValue(other.pressValue), idAtom(other.idAtom), count(other.count)
223
275
  {
@@ -327,16 +379,28 @@ bool NodeAttributeStore::has(const char *name) const
327
379
  return false;
328
380
  }
329
381
 
382
+ #else
383
+ void NodeAttributeStore::set(const char *name, const char *)
384
+ {
385
+ if (name && *name) std::abort(); // A source proof must never discard a live attribute.
386
+ }
387
+ #endif
388
+
330
389
  void NodeEventListeners::clear()
331
390
  {
391
+ #if GEA_UI_NODE_LISTENERS
332
392
  for (int type = 0; type < 7; ++type)
333
393
  if (hasType(type) && g_listenerTypeCounts[type] > 0) --g_listenerTypeCounts[type];
334
394
  entries.clear();
335
395
  types = 0;
396
+ #else
397
+
398
+ #endif
336
399
  }
337
400
 
338
401
  EventListenerId Tree::setEventListener(int node, const char *type, gea::framework::events::EventListener listener)
339
402
  {
403
+ #if GEA_UI_NODE_LISTENERS
340
404
  auto &state = treeState();
341
405
  if (node < 0 || node >= state.nodeCount) return kInvalidEventListenerId;
342
406
  if (!listener) return kInvalidEventListenerId;
@@ -355,10 +419,15 @@ EventListenerId Tree::setEventListener(int node, const char *type, gea::framewor
355
419
  id, static_cast<std::uint8_t>(typeIndex),
356
420
  std::make_shared<gea::framework::events::EventListener>(std::move(listener))});
357
421
  return id;
422
+ #else
423
+ if (node >= 0 && node < treeState().nodeCount && listener && eventTypeIndex(type) >= 0) std::abort();
424
+ return kInvalidEventListenerId;
425
+ #endif
358
426
  }
359
427
 
360
428
  bool Tree::removeEventListener(int node, const char *type, EventListenerId listenerId)
361
429
  {
430
+ #if GEA_UI_NODE_LISTENERS
362
431
  auto &state = treeState();
363
432
  if (node < 0 || node >= state.nodeCount || listenerId == kInvalidEventListenerId) return false;
364
433
  NodeRareData *rd = rareDataFor(node);
@@ -378,6 +447,9 @@ bool Tree::removeEventListener(int node, const char *type, EventListenerId liste
378
447
  return true;
379
448
  }
380
449
  return false;
450
+ #else
451
+ return false;
452
+ #endif
381
453
  }
382
454
 
383
455
  bool Tree::hasEventListener(int node) const
@@ -390,14 +462,19 @@ bool Tree::hasEventListener(int node) const
390
462
 
391
463
  bool Tree::hasListenersForType(const char *type) const
392
464
  {
465
+ #if GEA_UI_NODE_LISTENERS
393
466
  const int index = eventTypeIndex(type);
394
467
  // Unknown/untracked types fall through to dispatch — never silently drop an
395
468
  // event we don't account for.
396
469
  return index < 0 || g_listenerTypeCounts[index] > 0;
470
+ #else
471
+ return false;
472
+ #endif
397
473
  }
398
474
 
399
475
  bool Tree::dispatchEvent(gea::framework::events::PointerEvent &event)
400
476
  {
477
+ #if GEA_UI_NODE_LISTENERS
401
478
  auto &state = treeState();
402
479
  if (event.targetId < 0 || event.targetId >= state.nodeCount) return false;
403
480
 
@@ -450,6 +527,9 @@ bool Tree::dispatchEvent(gea::framework::events::PointerEvent &event)
450
527
  if (event.propagationStopped || !event.bubbles) break;
451
528
  }
452
529
  return dispatched;
530
+ #else
531
+ return false;
532
+ #endif
453
533
  }
454
534
 
455
535
  bool Tree::containsNode(int ancestor, int node) const
@@ -572,8 +652,10 @@ void Tree::removeAttribute(int node, const char *name)
572
652
  if (!rd) return; // no rare-data block → no attributes to remove
573
653
  const bool hadAttribute = rd->attributes.remove(name);
574
654
  if (!hadAttribute) return;
655
+ #if GEA_UI_NODE_ATTRIBUTES
575
656
  if (sameName(name, "data-press-id")) rd->attributes.pressId = -1;
576
657
  if (sameName(name, "data-press-value")) rd->attributes.pressValue = -1;
658
+ #endif
577
659
  if (attributeAffectsRendering(state.nodes[node], name)) {
578
660
  markNodeDisplayCommandsDirty(node);
579
661
  state.displayListDirty = true;
@@ -628,7 +710,9 @@ void Tree::setPressId(int node, int pressId)
628
710
  auto &state = treeState();
629
711
  if (node < 0 || node >= state.nodeCount) return;
630
712
  auto &attrs = ensureRareData(node).attributes;
713
+ #if GEA_UI_NODE_ATTRIBUTES
631
714
  attrs.pressId = static_cast<int16_t>(pressId);
715
+ #endif
632
716
  char value[16];
633
717
  std::snprintf(value, sizeof(value), "%d", pressId);
634
718
  attrs.set("data-press-id", value);
@@ -647,7 +731,9 @@ void Tree::setPressValue(int node, int pressValue)
647
731
  auto &state = treeState();
648
732
  if (node < 0 || node >= state.nodeCount) return;
649
733
  auto &attrs = ensureRareData(node).attributes;
734
+ #if GEA_UI_NODE_ATTRIBUTES
650
735
  attrs.pressValue = static_cast<int16_t>(pressValue);
736
+ #endif
651
737
  char value[16];
652
738
  std::snprintf(value, sizeof(value), "%d", pressValue);
653
739
  attrs.set("data-press-value", value);
package/ui/tree_events.h CHANGED
@@ -5,6 +5,7 @@
5
5
  #include "events.h"
6
6
  #include "node_model.h"
7
7
 
8
+ #include <array>
8
9
  #include <cstdint>
9
10
  #include <memory>
10
11
  #include <vector>
@@ -32,6 +33,7 @@ struct NodeAttributeEntry {
32
33
  };
33
34
 
34
35
  struct NodeAttributeStore {
36
+ #if GEA_UI_NODE_ATTRIBUTES
35
37
  int16_t pressId = -1;
36
38
  int16_t pressValue = -1;
37
39
  CssAtomId idAtom = kInvalidCssAtom;
@@ -51,6 +53,15 @@ struct NodeAttributeStore {
51
53
  bool remove(const char *name);
52
54
  const char *get(const char *name) const;
53
55
  bool has(const char *name) const;
56
+ #else
57
+ static constexpr int16_t pressId = -1, pressValue = -1;
58
+ static constexpr CssAtomId idAtom = kInvalidCssAtom;
59
+ void clear() {}
60
+ void set(const char *name, const char *value);
61
+ bool remove(const char *) { return false; }
62
+ const char *get(const char *) const { return ""; }
63
+ bool has(const char *) const { return false; }
64
+ #endif
54
65
  };
55
66
 
56
67
  using gea::framework::events::EventListenerId;
@@ -63,8 +74,13 @@ struct NodeEventListenerEntry {
63
74
  };
64
75
 
65
76
  struct NodeEventListeners {
77
+ #if GEA_UI_NODE_LISTENERS
66
78
  std::vector<NodeEventListenerEntry> entries;
67
79
  std::uint8_t types = 0;
80
+ #else
81
+ inline static constexpr std::array<NodeEventListenerEntry, 0> entries{};
82
+ static constexpr std::uint8_t types = 0;
83
+ #endif
68
84
 
69
85
  void clear();
70
86
  bool hasType(int type) const { return type >= 0 && (types & (1u << type)); }
package/ui/tree_nodes.cpp CHANGED
@@ -17,16 +17,16 @@ namespace {
17
17
 
18
18
  bool nodeCanDrawWithoutCanvas(const Node &node)
19
19
  {
20
- if (node.style.display == 1) return false;
20
+ if (node.computedStyle().display == 1) return false;
21
21
  if (node.type == NodeType::Canvas) return false;
22
22
  // A <camera> leaf paints itself from the platform preview buffer (or a
23
23
  // native overlay), never via the box renderer — treat it like a canvas.
24
24
  if (node.type == NodeType::Camera) return false;
25
- if (node.style.has_bg || hasAnyBorder(node.style)) return true;
25
+ if (node.computedStyle().has_bg || hasAnyBorder(node.computedStyle())) return true;
26
26
  if (node.type == NodeType::Text && !node.text.empty()) return true;
27
27
  if (node.type == NodeType::Image && node.image_id >= 0) return true;
28
28
  if (node.type == NodeType::VirtualList) return true;
29
- if (isViewLikeNodeType(node.type) && node.style.overflow == 2) return true;
29
+ if (isViewLikeNodeType(node.type) && node.computedStyle().overflow == 2) return true;
30
30
  return false;
31
31
  }
32
32
 
@@ -85,7 +85,7 @@ bool canUseDisplayFramebuffer(TreeState &state, int id, int width, int height)
85
85
  int visibleCanvasCount = 0;
86
86
  for (int i = 0; i < state.nodeCount; i++) {
87
87
  Node &node = state.nodes[i];
88
- if (node.style.display == 1) continue;
88
+ if (node.computedStyle().display == 1) continue;
89
89
  if (node.type == NodeType::Canvas) visibleCanvasCount++;
90
90
  if (i != id && nodeCanDrawWithoutCanvas(node)) return failWhy(5, i);
91
91
  }
@@ -105,7 +105,7 @@ void resetNodeSlot(TreeState &state, int id)
105
105
  if (!state.nodes[id].text.empty()) DisplayList::instance().scrubNodeText(state.nodes[id].text.c_str());
106
106
  releaseRareData(id); // frees the rare-data block: attributes, listeners, custom props, virtual-list
107
107
  #if GEA_CSS_RARE_STYLE
108
- releaseRareStyle(state.nodes[id].style.rare_style); // frees the cold-style block
108
+ releaseRareStyle(state.nodes[id].mutableStyle().rare_style); // frees the cold-style block
109
109
  #endif
110
110
  state.classLists[id].clear();
111
111
  state.canvases.remove(id);
@@ -116,7 +116,8 @@ void resetNodeSlot(TreeState &state, int id)
116
116
  state.nodeInBackdrop[id] = 0;
117
117
  state.nodeActive[id] = 0;
118
118
  NodeLifecycle::init(&state.nodes[id], NodeType::View);
119
- state.nodes[id].style.display = kDisplayNone;
119
+ LayoutEngine::instance().resetNodeLayoutState(id);
120
+ state.nodes[id].mutableStyle().display = kDisplayNone;
120
121
  }
121
122
 
122
123
  void trimInactiveTail(TreeState &state)
@@ -130,14 +131,14 @@ bool localAbsoluteLeafTreeMutation(const TreeState &state, int child)
130
131
  {
131
132
  if (child < 0 || child >= state.nodeCount) return false;
132
133
  const Node &node = state.nodes[child];
133
- if (node.style.display == kDisplayNone) return false;
134
- if (node.style.position != 1) return false;
135
- if (node.style.width == kUnset || node.style.height == kUnset) return false;
134
+ if (node.computedStyle().display == kDisplayNone) return false;
135
+ if (node.computedStyle().position != 1) return false;
136
+ if (node.computedStyle().width == kUnset || node.computedStyle().height == kUnset) return false;
136
137
  if (node.first_child >= 0) return false;
137
138
  if (node.type == NodeType::Text || node.type == NodeType::Canvas || node.type == NodeType::VirtualList) return false;
138
139
  if (!isViewLikeNodeType(node.type) && node.type != NodeType::Image) return false;
139
- if ((GEA_CSS_FILTERS ? rstyle(node.style).filter_blur_radius : 0) > 0 || node.style.mask_right_fade_width > 0) return false;
140
- if ((GEA_CSS_BOX_SHADOW ? rstyle(node.style).box_shadow_alpha : 0) > 0) return false;
140
+ if ((GEA_CSS_FILTERS ? rstyle(node.computedStyle()).filter_blur_radius : 0) > 0 || node.computedStyle().mask_right_fade_width > 0) return false;
141
+ if ((GEA_CSS_BOX_SHADOW ? rstyle(node.computedStyle()).box_shadow_alpha : 0) > 0) return false;
141
142
  return true;
142
143
  }
143
144
 
@@ -145,6 +146,8 @@ bool localAbsoluteLeafTreeMutation(const TreeState &state, int child)
145
146
 
146
147
  void Tree::clear()
147
148
  {
149
+ LayoutEngine::instance().endLayoutPass();
150
+ LayoutEngine::instance().releasePersistentLayoutStorage();
148
151
  auto &state = treeState();
149
152
  state.refreshSerial++;
150
153
  if (state.refreshSerial == 0) state.refreshSerial = 1;
@@ -229,6 +232,7 @@ int Tree::createNode(NodeType type)
229
232
  state.nodeActive[id] = 1;
230
233
  releaseRareData(id); // free any block from a prior occupant before reinit
231
234
  NodeLifecycle::init(&state.nodes[id], type);
235
+ LayoutEngine::instance().resetNodeLayoutState(id);
232
236
  state.classLists[id].clear();
233
237
  if (type == NodeType::VirtualList) VirtualListRenderer::init(id);
234
238
  return id;
@@ -244,12 +248,12 @@ int Tree::cloneNode(int sourceId, bool deep)
244
248
  // is safe; an ACTIVE source slot can never be the one createNode reused.
245
249
  const Node &source = state.nodes[sourceId];
246
250
  Node &clone = state.nodes[id];
247
- clone.style = source.style;
248
- // clone.style copied source's rare_style HANDLE (shared pool entry). Give the
251
+ clone.mutableStyle() = source.computedStyle();
252
+ // clone.computedStyle() copied source's rare_style HANDLE (shared pool entry). Give the
249
253
  // clone its own entry with the same contents, so mutating one never aliases.
250
254
  #if GEA_CSS_RARE_STYLE
251
- clone.style.rare_style = -1;
252
- if (source.style.rare_style >= 0) rstyleMut(clone.style) = rstyle(source.style);
255
+ clone.mutableStyle().rare_style = -1;
256
+ if (source.computedStyle().rare_style >= 0) rstyleMut(clone.mutableStyle()) = rstyle(source.computedStyle());
253
257
  #endif
254
258
  clone.text = source.text;
255
259
  #if GEA_UI_IMAGE_NODES
@@ -314,7 +318,7 @@ int Tree::createCamera() { return createNode(NodeType::Camera); }
314
318
  int Tree::createAudio()
315
319
  {
316
320
  const int id = createNode(NodeType::Audio);
317
- if (id >= 0) treeState().nodes[id].style.display = kDisplayNone;
321
+ if (id >= 0) treeState().nodes[id].mutableStyle().display = kDisplayNone;
318
322
  return id;
319
323
  }
320
324
  int Tree::createVirtualList() { return createNode(NodeType::VirtualList); }
@@ -649,7 +653,7 @@ void Tree::removeNode(int id)
649
653
  }
650
654
  if (n->prev_sibling >= 0) state.nodes[n->prev_sibling].next_sibling = n->next_sibling;
651
655
  if (n->next_sibling >= 0) state.nodes[n->next_sibling].prev_sibling = n->prev_sibling;
652
- n->style.display = 1;
656
+ n->mutableStyle().display = 1;
653
657
  n->parent = -1;
654
658
  n->first_child = -1;
655
659
  n->last_child = -1;