@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.
@@ -31,7 +31,7 @@ void LayoutSnapshot::capture()
31
31
  // ~1ms/frame on the spinning css-3d-cube (the "snap" phase); spine read these as
32
32
  // direct ComputedStyle fields. (Same regression class as the reproject path.)
33
33
  #if GEA_CSS_TRANSFORMS || GEA_CSS_FILTERS
34
- const RareStyle &rs = rstyle(state.nodes[i].style);
34
+ const RareStyle &rs = rstyle(state.nodes[i].computedStyle());
35
35
  #endif
36
36
  #if GEA_CSS_TRANSFORMS
37
37
  state.nodes[i].render.previous_transformable_box = ViewRenderer::isTransformableBox(state.nodes[i]);
@@ -16,3 +16,21 @@
16
16
  #endif
17
17
  static_assert(GEA_UI_CLASS_INLINE_TOKENS >= 1 && GEA_UI_CLASS_INLINE_TOKENS <= 4,
18
18
  "Class inline capacity must be between one and four tokens");
19
+
20
+ // A separate positive proof covers every class assignment and rules out opaque
21
+ // mutation. Older analyzers and unknown programs retain overflow support.
22
+ #ifndef GEA_UI_CLASS_OVERFLOW
23
+ #define GEA_UI_CLASS_OVERFLOW 1
24
+ #endif
25
+
26
+ // Closed whole-source auxiliary-state proof. Unknown/older programs keep all
27
+ // owners; callers cannot prune these through application manifest switches.
28
+ #ifndef GEA_UI_NODE_LISTENERS
29
+ #define GEA_UI_NODE_LISTENERS 1
30
+ #endif
31
+ #ifndef GEA_UI_NODE_ATTRIBUTES
32
+ #define GEA_UI_NODE_ATTRIBUTES 1
33
+ #endif
34
+ #ifndef GEA_UI_DEFAULT_STYLES
35
+ #define GEA_UI_DEFAULT_STYLES 1
36
+ #endif
@@ -4,6 +4,12 @@
4
4
  #include "pixel.h"
5
5
 
6
6
  #include <cstring>
7
+ #include <cstdlib>
8
+ #include <new>
9
+ #include <utility>
10
+ #if defined(ESP_PLATFORM)
11
+ #include "esp_heap_caps.h"
12
+ #endif
7
13
 
8
14
  namespace gea::embedded::ui {
9
15
 
@@ -14,14 +20,24 @@ constexpr ComputedStyle makeDefaultStyle()
14
20
  {
15
21
  ComputedStyle style{};
16
22
  style.display = kDisplayBlock;
23
+ #if GEA_CSS_DISPLAY_EXPLICIT
17
24
  style.display_explicit = 0;
25
+ #endif
26
+ #if GEA_CSS_FLEX_DIRECTION
18
27
  style.flex_direction = 0;
28
+ #endif
29
+ #if GEA_CSS_FLEX_DIRECTION
19
30
  style.flex_direction_explicit = 0;
31
+ #endif
20
32
  #if GEA_CSS_FLEX_WRAP
21
33
  style.flex_wrap = 0;
22
34
  #endif
35
+ #if GEA_CSS_JUSTIFY_CONTENT
23
36
  style.justify_content = 0;
37
+ #endif
38
+ #if GEA_CSS_ALIGN_ITEMS
24
39
  style.align_items = 0;
40
+ #endif
25
41
  #if GEA_CSS_JUSTIFY_ITEMS
26
42
  style.justify_items = 0;
27
43
  #endif
@@ -31,11 +47,15 @@ constexpr ComputedStyle makeDefaultStyle()
31
47
  #if GEA_CSS_ALIGN_SELF
32
48
  style.align_self = -1;
33
49
  #endif
50
+ #if GEA_CSS_GAP
34
51
  style.gap = 0;
52
+ #endif
35
53
  #if GEA_CSS_ORDER
36
54
  style.order = 0;
37
55
  #endif
56
+ #if GEA_CSS_BOX_SIZING
38
57
  style.box_sizing = 0;
58
+ #endif
39
59
  #if GEA_CSS_FLOATS
40
60
  style.float_side = 0;
41
61
  style.clear_side = 0;
@@ -44,7 +64,9 @@ constexpr ComputedStyle makeDefaultStyle()
44
64
  style.writing_mode = -1;
45
65
  style.direction = -1;
46
66
  #endif
67
+ #if GEA_CSS_MARGIN_AUTO
47
68
  style.margin_auto = 0;
69
+ #endif
48
70
  #if GEA_CSS_AXIS_GAP
49
71
  style.row_gap = style.column_gap = kUnset;
50
72
  #endif
@@ -53,30 +75,48 @@ constexpr ComputedStyle makeDefaultStyle()
53
75
  #endif
54
76
  // Grid tracks moved to RareStyle (default 0 for a node with no rare_style),
55
77
  // so a fresh node needs no explicit reset here.
78
+ #if GEA_CSS_WIDTH_EXPRESSIONS
56
79
  style.width_expression = -1;
80
+ #endif
57
81
  #if GEA_CSS_HEIGHT_EXPRESSIONS
58
82
  style.height_expression = -1;
59
83
  #endif
60
84
  style.width = kUnset;
61
85
  style.height = kUnset;
86
+ #if GEA_CSS_WIDTH_PERCENT
62
87
  style.width_percent = kUnset;
88
+ #endif
89
+ #if GEA_CSS_HEIGHT_PERCENT
63
90
  style.height_percent = kUnset;
91
+ #endif
64
92
  #if GEA_CSS_MIN_WIDTH
65
93
  style.min_width = kUnset;
66
94
  #endif
95
+ #if GEA_CSS_MIN_HEIGHT
67
96
  style.min_height = kUnset;
97
+ #endif
98
+ #if GEA_CSS_MAX_WIDTH
68
99
  style.max_width = kUnset;
100
+ #endif
69
101
  #if GEA_CSS_MAX_HEIGHT
70
102
  style.max_height = kUnset;
71
103
  #endif
104
+ #if GEA_CSS_FLEX_FACTORS
72
105
  style.flex = 0;
106
+ #endif
107
+ #if GEA_CSS_FLEX_FACTORS
73
108
  style.flex_shrink = 1;
109
+ #endif
74
110
  #if GEA_CSS_FLEX_BASIS
75
111
  style.flex_basis = kUnset;
76
112
  #endif
77
113
  for (int i = 0; i < 4; i++) {
114
+ #if GEA_CSS_PADDING
78
115
  style.padding[i] = 0;
116
+ #endif
117
+ #if GEA_CSS_MARGINS
79
118
  style.margin[i] = 0;
119
+ #endif
80
120
  // per-side border width/color/alpha moved to RareStyle (defaults there).
81
121
  style.border_radius[GEA_CSS_RADIUS_INDEX(i)] = 0;
82
122
  #if GEA_CSS_PERCENT_RADIUS
@@ -119,8 +159,12 @@ constexpr ComputedStyle makeDefaultStyle()
119
159
  style.bg_fill = 0;
120
160
  #endif
121
161
  // gradients + background-grid moved to RareStyle (defaults there).
162
+ #if GEA_CSS_ACTIVE_BACKGROUND
122
163
  style.active_bg_color = 0;
164
+ #endif
165
+ #if GEA_CSS_ACTIVE_BACKGROUND
123
166
  style.has_active_bg = 0;
167
+ #endif
124
168
  style.text_color = gea::framework::graphics::pixel::nativeColor(255, 255, 255);
125
169
  #if GEA_CSS_TEXT_ALPHA
126
170
  style.text_alpha = 255;
@@ -133,9 +177,15 @@ constexpr ComputedStyle makeDefaultStyle()
133
177
  style.blink_started_ms = 0;
134
178
  style.blink_visible = 1;
135
179
  #endif
180
+ #if GEA_CSS_BORDER_COLORS
136
181
  style.border_color_flags = 0;
182
+ #endif
183
+ #if GEA_CSS_BORDER_WIDTHS
137
184
  style.border_width = 0;
185
+ #endif
186
+ #if GEA_CSS_BORDER_COLORS
138
187
  style.border_color = gea::framework::graphics::pixel::nativeColor(255, 255, 255);
188
+ #endif
139
189
  #if GEA_CSS_BORDER_ALPHA
140
190
  style.border_alpha = 255;
141
191
  #endif
@@ -143,18 +193,30 @@ constexpr ComputedStyle makeDefaultStyle()
143
193
  // node (rare_style = -1) reads their correct defaults from the zero entry.
144
194
  style.font_id = -1;
145
195
  style.font_size = 0;
196
+ #if GEA_CSS_FONT_WEIGHT
146
197
  style.font_weight = 400;
198
+ #endif
199
+ #if GEA_CSS_LINE_HEIGHT
147
200
  style.line_height = 0;
201
+ #endif
202
+ #if GEA_CSS_LINE_HEIGHT_MULTIPLIER
148
203
  style.line_height_multiplier = -1;
204
+ #endif
205
+ #if GEA_CSS_TEXT_ALIGN
149
206
  style.text_align = 0;
207
+ #endif
150
208
  #if GEA_CSS_TEXT_DECORATION
151
209
  style.text_decoration = 0;
152
210
  #endif
153
211
  #if GEA_CSS_TEXT_TRANSFORM
154
212
  style.text_transform = 0;
155
213
  #endif
214
+ #if GEA_CSS_WHITE_SPACE
156
215
  style.white_space = 0;
216
+ #endif
217
+ #if GEA_CSS_TEXT_OVERFLOW
157
218
  style.text_overflow = 0;
219
+ #endif
158
220
  style.overflow = 0;
159
221
  #if GEA_CSS_OVERFLOW_AXES
160
222
  style.overflow_x = 0;
@@ -188,10 +250,110 @@ void NodeLifecycle::resetStyle(ComputedStyle &style)
188
250
  style = kDefaultStyle;
189
251
  }
190
252
 
253
+ #if GEA_EMBEDDED_SHARED_STYLES
254
+ namespace {
255
+ SharedStyleRecord *g_sharedStyleHead = nullptr;
256
+ std::size_t g_sharedStyleRecords = 0;
257
+ SharedStyleRecord &defaultStyleRecord()
258
+ {
259
+ static SharedStyleRecord record{kDefaultStyle, 0, nullptr};
260
+ return record;
261
+ }
262
+ void retainStyle(SharedStyleRecord *record)
263
+ {
264
+ if (record != &defaultStyleRecord()) ++record->references;
265
+ }
266
+ void releaseStyle(SharedStyleRecord *record)
267
+ {
268
+ if (record == &defaultStyleRecord() || --record->references != 0) return;
269
+ // Reclamation is cold; keep no backward link in every style record.
270
+ // The per-frame read/write path still uses the same direct record pointer.
271
+ auto **link = &g_sharedStyleHead;
272
+ while (*link && *link != record) link = &(*link)->next;
273
+ if (!*link) std::abort();
274
+ *link = record->next;
275
+ record->~SharedStyleRecord();
276
+ #if defined(ESP_PLATFORM)
277
+ heap_caps_free(record);
278
+ #else
279
+ std::free(record);
280
+ #endif
281
+ --g_sharedStyleRecords;
282
+ }
283
+ SharedStyleRecord *copyStyle(const ComputedStyle &value)
284
+ {
285
+ #if defined(ESP_PLATFORM)
286
+ void *storage = heap_caps_malloc(sizeof(SharedStyleRecord), MALLOC_CAP_SPIRAM);
287
+ #else
288
+ void *storage = std::malloc(sizeof(SharedStyleRecord));
289
+ #endif
290
+ if (!storage) std::abort();
291
+ auto *record = new (storage) SharedStyleRecord{value, 1, g_sharedStyleHead};
292
+ g_sharedStyleHead = record;
293
+ ++g_sharedStyleRecords;
294
+ return record;
295
+ }
296
+ }
297
+ NodeStyleStorage::NodeStyleStorage() : record_(&defaultStyleRecord()) {}
298
+ NodeStyleStorage::~NodeStyleStorage() { releaseStyle(record_); }
299
+ NodeStyleStorage::NodeStyleStorage(const NodeStyleStorage &other) : record_(other.record_) { retainStyle(record_); }
300
+ NodeStyleStorage &NodeStyleStorage::operator=(const NodeStyleStorage &other)
301
+ {
302
+ if (this != &other) { retainStyle(other.record_); releaseStyle(record_); record_ = other.record_; }
303
+ return *this;
304
+ }
305
+ NodeStyleStorage::NodeStyleStorage(NodeStyleStorage &&other) noexcept
306
+ : record_(std::exchange(other.record_, &defaultStyleRecord())) {}
307
+ NodeStyleStorage &NodeStyleStorage::operator=(NodeStyleStorage &&other) noexcept
308
+ {
309
+ if (this != &other) { releaseStyle(record_); record_ = std::exchange(other.record_, &defaultStyleRecord()); }
310
+ return *this;
311
+ }
312
+ ComputedStyle &NodeStyleStorage::detach()
313
+ {
314
+ auto *copy = copyStyle(record_->value);
315
+ releaseStyle(record_);
316
+ record_ = copy;
317
+ return record_->value;
318
+ }
319
+ void NodeStyleStorage::reset() { releaseStyle(record_); record_ = &defaultStyleRecord(); }
320
+ void NodeStyleStorage::intern()
321
+ {
322
+ if (record_ == &defaultStyleRecord() || record_->value.rare_style >= 0) return;
323
+ // Called at the end of CSS recomputation, never in the per-frame read path.
324
+ for (auto *other = g_sharedStyleHead; other; other = other->next) {
325
+ if (other == record_ || !(other->value == record_->value)) continue;
326
+ retainStyle(other);
327
+ releaseStyle(record_);
328
+ record_ = other;
329
+ return;
330
+ }
331
+ }
332
+ std::size_t NodeStyleStorage::allocatedBytes() { return g_sharedStyleRecords * sizeof(SharedStyleRecord); }
333
+ std::size_t NodeStyleStorage::allocatedRecords() { return g_sharedStyleRecords; }
334
+ std::size_t NodeStyleStorage::allocatedHeapBytes()
335
+ {
336
+ #if defined(ESP_PLATFORM)
337
+ std::size_t bytes = 0;
338
+ for (auto *record = g_sharedStyleHead; record; record = record->next)
339
+ bytes += heap_caps_get_allocated_size(record);
340
+ return bytes;
341
+ #else
342
+ return allocatedBytes();
343
+ #endif
344
+ }
345
+
346
+ #else
347
+ void Node::resetComputedStyle() { NodeLifecycle::resetStyle(style); }
348
+ #endif
349
+
191
350
  void NodeLifecycle::init(Node *n, NodeType type)
192
351
  {
193
352
  n->type = type;
194
- resetStyle(n->style);
353
+ #if GEA_EMBEDDED_SHARED_STYLES && !GEA_CSS_CUSTOM_PROPERTIES
354
+ n->class_style_tracked = false;
355
+ #endif
356
+ n->resetComputedStyle();
195
357
  n->text.clear();
196
358
  #if GEA_UI_IMAGE_NODES
197
359
  n->image_id = -1;
@@ -207,6 +369,10 @@ void NodeLifecycle::init(Node *n, NodeType type)
207
369
  n->layout.width = 0;
208
370
  n->layout.height = 0;
209
371
  n->layout.inline_indent = 0;
372
+ #if !GEA_EMBEDDED_SHARED_STYLES
373
+ n->layout.memo_avail_w = n->layout.memo_avail_h = 0;
374
+ n->layout.memo_pass = 0;
375
+ #endif
210
376
  #if GEA_CSS_SCROLLING
211
377
  n->layout.scroll_x = 0;
212
378
  n->layout.scroll_y = 0;