@geastack/engine 0.1.6 → 0.1.7

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.
@@ -13,20 +13,27 @@ void LayoutSnapshot::capture()
13
13
  // !anyTransformActive), and anyTransformActive checks both current and previous
14
14
  // transforms — so for a tree with no transforms (e.g. bouncing-balls) these reads
15
15
  // are pure per-frame waste and the stale previous_* values are never observed. Skip
16
- // them. The filter snapshot is independent (no transform), so it always runs.
16
+ // them. The filter snapshot is independent and retained when filters are reachable.
17
+ #if GEA_CSS_TRANSFORMS
17
18
  const bool captureTransforms = ViewRenderer::anyTransformActive();
19
+ #endif
18
20
  for (int i = 0; i < state.nodeCount; i++) {
19
21
  state.nodes[i].layout.previous_x = state.nodes[i].layout.x;
20
22
  state.nodes[i].layout.previous_y = state.nodes[i].layout.y;
21
23
  state.nodes[i].layout.previous_width = state.nodes[i].layout.width;
22
24
  state.nodes[i].layout.previous_height = state.nodes[i].layout.height;
25
+ #if GEA_CSS_SCROLLING
23
26
  state.nodes[i].layout.previous_scroll_x = state.nodes[i].layout.scroll_x;
24
27
  state.nodes[i].layout.previous_scroll_y = state.nodes[i].layout.scroll_y;
28
+ #endif
25
29
  // ONE RareStyle pool lookup per node, not ~16 — rstyle() is an out-of-line
26
30
  // deque index (separate cache line from the node). Per-field lookups here cost
27
31
  // ~1ms/frame on the spinning css-3d-cube (the "snap" phase); spine read these as
28
32
  // direct ComputedStyle fields. (Same regression class as the reproject path.)
33
+ #if GEA_CSS_TRANSFORMS || GEA_CSS_FILTERS
29
34
  const RareStyle &rs = rstyle(state.nodes[i].style);
35
+ #endif
36
+ #if GEA_CSS_TRANSFORMS
30
37
  state.nodes[i].render.previous_transformable_box = ViewRenderer::isTransformableBox(state.nodes[i]);
31
38
  if (captureTransforms) {
32
39
  state.nodes[i].render.previous_rotate_angle = rs.rotate_angle;
@@ -60,12 +67,21 @@ void LayoutSnapshot::capture()
60
67
  state.nodes[i].render.previous_perspective_origin_x = rs.perspective_origin_x;
61
68
  state.nodes[i].render.previous_perspective_origin_y = rs.perspective_origin_y;
62
69
  }
70
+ #endif
71
+ #if GEA_CSS_FILTERS
63
72
  state.nodes[i].render.previous_filter_blur_radius = rs.filter_blur_radius;
73
+ #endif
64
74
  state.nodes[i].render.dirty = 0;
65
75
  state.nodes[i].render.layout_dirty = 0;
76
+ #if GEA_CSS_SCROLLING
66
77
  state.nodes[i].render.scroll_dirty = 0;
78
+ #endif
79
+ #if GEA_CSS_SCROLLING
67
80
  state.nodes[i].render.non_scroll_dirty = 0;
81
+ #endif
82
+ #if GEA_CSS_TRANSFORMS
68
83
  state.nodes[i].render.transform_dirty = 0;
84
+ #endif
69
85
  state.nodes[i].render.bg_recolor_pending = 0;
70
86
  state.nodes[i].render.text_layout_stable = 0;
71
87
  state.nodes[i].render.text_partial_dirty = 0;
@@ -74,9 +90,18 @@ void LayoutSnapshot::capture()
74
90
  state.nodeCommandDirtyCanOverpaint[i] = 0;
75
91
  if (state.nodes[i].type == NodeType::VirtualList) VirtualListRenderer::captureSnapshot(i);
76
92
  }
93
+ #if GEA_CSS_SCROLLING
77
94
  for (int i = 0; i < kScrollDirtyWordCount; i++)
78
95
  state.scrollDirtyNodes[i] = 0;
79
96
  state.scrollDirtyAny = false;
97
+ #endif
98
+ // Previous-frame transforms just changed. Geometry cached while collecting
99
+ // dirty bounds refers to the old snapshot; callers after capture must observe
100
+ // the new one, just as the uncached path does. The refresh serial is the
101
+ // geometry cache's authority for both current and previous transforms.
102
+ #if GEA_CSS_TRANSFORMS
103
+ if (captureTransforms && ++state.refreshSerial == 0) state.refreshSerial = 1;
104
+ #endif
80
105
  }
81
106
 
82
107
  void LayoutSnapshot::markChangesDirty()
@@ -90,7 +115,9 @@ void LayoutSnapshot::markChangesDirty()
90
115
  n->layout.height != n->layout.previous_height) {
91
116
  n->render.dirty = 1;
92
117
  n->render.layout_dirty = 1;
118
+ #if GEA_CSS_SCROLLING
93
119
  n->render.non_scroll_dirty = 1;
120
+ #endif
94
121
  }
95
122
  }
96
123
  }
@@ -0,0 +1,18 @@
1
+ // SPDX-License-Identifier: Apache-2.0
2
+ #pragma once
3
+ // Positive whole-program node reachability facts. Older or opaque builds
4
+ // retain every native node kind; applications do not opt into compact storage.
5
+ #ifndef GEA_UI_IMAGE_NODES
6
+ #define GEA_UI_IMAGE_NODES 1
7
+ #endif
8
+ #ifndef GEA_UI_INPUT_NODES
9
+ #define GEA_UI_INPUT_NODES 1
10
+ #endif
11
+
12
+ // Generated from the whole-source class-token bound. Unknown programs retain
13
+ // four inline entries. Overflow support is independent of this capacity.
14
+ #ifndef GEA_UI_CLASS_INLINE_TOKENS
15
+ #define GEA_UI_CLASS_INLINE_TOKENS 4
16
+ #endif
17
+ static_assert(GEA_UI_CLASS_INLINE_TOKENS >= 1 && GEA_UI_CLASS_INLINE_TOKENS <= 4,
18
+ "Class inline capacity must be between one and four tokens");
@@ -7,102 +7,196 @@
7
7
 
8
8
  namespace gea::embedded::ui {
9
9
 
10
- void NodeLifecycle::init(Node *n, NodeType type)
10
+ namespace {
11
+ // One immutable default image. Resetting CSS must not construct/destroy a whole
12
+ // Node, touch its text ownership, or initialize layout/render state on the stack.
13
+ constexpr ComputedStyle makeDefaultStyle()
11
14
  {
12
- // Node contains a `std::string text` member — it is NOT a trivially-
13
- // copyable struct, so `std::memset(n, 0, sizeof(*n))` is undefined
14
- // behavior (it would zero the string's internal _M_dataplus._M_p,
15
- // and the subsequent .clear() would null-deref writing the NUL
16
- // terminator to address 0). Every Node field is explicitly assigned
17
- // below, so the memset was a redundant belt-and-suspenders zero —
18
- // dropping it both fixes the crash and is no-loss because the next
19
- // ~80 lines reassign every member.
20
- n->type = type;
21
- n->style.display = kDisplayBlock;
22
- n->style.display_explicit = 0;
23
- n->style.flex_direction = 0;
24
- n->style.flex_direction_explicit = 0;
25
- n->style.flex_wrap = 0;
26
- n->style.justify_content = 0;
27
- n->style.align_items = 0;
28
- n->style.justify_items = 0;
29
- n->style.align_content = 0;
30
- n->style.align_self = -1;
31
- n->style.gap = 0;
32
- n->style.order = 0;
33
- n->style.box_sizing = 0;
34
- n->style.float_side = 0;
35
- n->style.clear_side = 0;
36
- n->style.writing_mode = -1;
37
- n->style.direction = -1;
38
- n->style.margin_auto = 0;
39
- n->style.row_gap = n->style.column_gap = kUnset;
40
- n->style.row_gap_percent = n->style.column_gap_percent = kUnset;
15
+ ComputedStyle style{};
16
+ style.display = kDisplayBlock;
17
+ style.display_explicit = 0;
18
+ style.flex_direction = 0;
19
+ style.flex_direction_explicit = 0;
20
+ #if GEA_CSS_FLEX_WRAP
21
+ style.flex_wrap = 0;
22
+ #endif
23
+ style.justify_content = 0;
24
+ style.align_items = 0;
25
+ #if GEA_CSS_JUSTIFY_ITEMS
26
+ style.justify_items = 0;
27
+ #endif
28
+ #if GEA_CSS_ALIGN_CONTENT
29
+ style.align_content = 0;
30
+ #endif
31
+ #if GEA_CSS_ALIGN_SELF
32
+ style.align_self = -1;
33
+ #endif
34
+ style.gap = 0;
35
+ #if GEA_CSS_ORDER
36
+ style.order = 0;
37
+ #endif
38
+ style.box_sizing = 0;
39
+ #if GEA_CSS_FLOATS
40
+ style.float_side = 0;
41
+ style.clear_side = 0;
42
+ #endif
43
+ #if GEA_CSS_WRITING_MODE
44
+ style.writing_mode = -1;
45
+ style.direction = -1;
46
+ #endif
47
+ style.margin_auto = 0;
48
+ #if GEA_CSS_AXIS_GAP
49
+ style.row_gap = style.column_gap = kUnset;
50
+ #endif
51
+ #if GEA_CSS_PERCENT_GAP
52
+ style.row_gap_percent = style.column_gap_percent = kUnset;
53
+ #endif
41
54
  // Grid tracks moved to RareStyle (default 0 for a node with no rare_style),
42
55
  // so a fresh node needs no explicit reset here.
43
- n->style.width_expression = n->style.height_expression = -1;
44
- n->style.width = kUnset;
45
- n->style.height = kUnset;
46
- n->style.width_percent = kUnset;
47
- n->style.height_percent = kUnset;
48
- n->style.min_width = kUnset;
49
- n->style.min_height = kUnset;
50
- n->style.max_width = kUnset;
51
- n->style.max_height = kUnset;
52
- n->style.flex = 0;
53
- n->style.flex_shrink = 1;
54
- n->style.flex_basis = kUnset;
56
+ style.width_expression = -1;
57
+ #if GEA_CSS_HEIGHT_EXPRESSIONS
58
+ style.height_expression = -1;
59
+ #endif
60
+ style.width = kUnset;
61
+ style.height = kUnset;
62
+ style.width_percent = kUnset;
63
+ style.height_percent = kUnset;
64
+ #if GEA_CSS_MIN_WIDTH
65
+ style.min_width = kUnset;
66
+ #endif
67
+ style.min_height = kUnset;
68
+ style.max_width = kUnset;
69
+ #if GEA_CSS_MAX_HEIGHT
70
+ style.max_height = kUnset;
71
+ #endif
72
+ style.flex = 0;
73
+ style.flex_shrink = 1;
74
+ #if GEA_CSS_FLEX_BASIS
75
+ style.flex_basis = kUnset;
76
+ #endif
55
77
  for (int i = 0; i < 4; i++) {
56
- n->style.padding[i] = 0;
57
- n->style.margin[i] = 0;
58
- n->style.pos_offsets[i] = kUnset;
59
- n->style.pos_offset_percent[i] = kUnset;
78
+ style.padding[i] = 0;
79
+ style.margin[i] = 0;
60
80
  // per-side border width/color/alpha moved to RareStyle (defaults there).
61
- n->style.border_radius[i] = 0;
62
- n->style.border_radius_percent[i] = kUnset;
81
+ style.border_radius[GEA_CSS_RADIUS_INDEX(i)] = 0;
82
+ #if GEA_CSS_PERCENT_RADIUS
83
+ style.border_radius_percent[GEA_CSS_RADIUS_INDEX(i)] = kUnset;
84
+ #endif
63
85
  }
64
- n->style.position = 0;
65
- n->style.z_index = 0;
66
- n->style.z_index_auto = 1;
67
- n->style.bg_color = 0;
68
- n->style.has_bg = 0;
69
- n->style.bg_alpha = 0;
70
- n->style.bg_fill = 0;
86
+ #if GEA_CSS_POSITION_TOP
87
+ GEA_CSS_POSITION_PX_0(style) = kUnset;
88
+ #endif
89
+ #if GEA_CSS_POSITION_TOP_PERCENT
90
+ GEA_CSS_POSITION_PERCENT_0(style) = kUnset;
91
+ #endif
92
+ #if GEA_CSS_POSITION_RIGHT
93
+ GEA_CSS_POSITION_PX_1(style) = kUnset;
94
+ #endif
95
+ #if GEA_CSS_POSITION_RIGHT_PERCENT
96
+ GEA_CSS_POSITION_PERCENT_1(style) = kUnset;
97
+ #endif
98
+ #if GEA_CSS_POSITION_BOTTOM
99
+ GEA_CSS_POSITION_PX_2(style) = kUnset;
100
+ #endif
101
+ #if GEA_CSS_POSITION_BOTTOM_PERCENT
102
+ GEA_CSS_POSITION_PERCENT_2(style) = kUnset;
103
+ #endif
104
+ #if GEA_CSS_POSITION_LEFT
105
+ GEA_CSS_POSITION_PX_3(style) = kUnset;
106
+ #endif
107
+ #if GEA_CSS_POSITION_LEFT_PERCENT
108
+ GEA_CSS_POSITION_PERCENT_3(style) = kUnset;
109
+ #endif
110
+ style.position = 0;
111
+ #if GEA_CSS_Z_INDEX
112
+ style.z_index = 0;
113
+ style.z_index_auto = 1;
114
+ #endif
115
+ style.bg_color = 0;
116
+ style.has_bg = 0;
117
+ style.bg_alpha = 0;
118
+ #if GEA_EMBEDDED_RENDERER_LINEAR_GRADIENTS
119
+ style.bg_fill = 0;
120
+ #endif
71
121
  // gradients + background-grid moved to RareStyle (defaults there).
72
- n->style.active_bg_color = 0;
73
- n->style.has_active_bg = 0;
74
- n->style.text_color = gea::framework::graphics::pixel::nativeColor(255, 255, 255);
75
- n->style.text_alpha = 255;
76
- n->style.opacity = 255;
77
- n->style.blink_interval_ms = 0;
78
- n->style.blink_started_ms = 0;
79
- n->style.blink_visible = 1;
80
- n->style.border_width = 0;
81
- n->style.border_color = gea::framework::graphics::pixel::nativeColor(255, 255, 255);
82
- n->style.border_alpha = 255;
122
+ style.active_bg_color = 0;
123
+ style.has_active_bg = 0;
124
+ style.text_color = gea::framework::graphics::pixel::nativeColor(255, 255, 255);
125
+ #if GEA_CSS_TEXT_ALPHA
126
+ style.text_alpha = 255;
127
+ #endif
128
+ #if GEA_CSS_OPACITY
129
+ style.opacity = 255;
130
+ #endif
131
+ #if GEA_CSS_BLINK
132
+ style.blink_interval_ms = 0;
133
+ style.blink_started_ms = 0;
134
+ style.blink_visible = 1;
135
+ #endif
136
+ style.border_color_flags = 0;
137
+ style.border_width = 0;
138
+ style.border_color = gea::framework::graphics::pixel::nativeColor(255, 255, 255);
139
+ #if GEA_CSS_BORDER_ALPHA
140
+ style.border_alpha = 255;
141
+ #endif
83
142
  // transform / perspective / filter / box-shadow moved to RareStyle; a fresh
84
143
  // node (rare_style = -1) reads their correct defaults from the zero entry.
85
- n->style.font_id = -1;
86
- n->style.font_size = 0;
87
- n->style.font_weight = 400;
88
- n->style.line_height = 0;
89
- n->style.line_height_multiplier = -1;
90
- n->style.text_align = 0;
91
- n->style.text_decoration = 0;
92
- n->style.text_transform = 0;
93
- n->style.white_space = 0;
94
- n->style.text_overflow = 0;
95
- n->style.overflow = 0;
96
- n->style.overflow_x = 0;
97
- n->style.overflow_y = 0;
98
- n->style.mask_right_fade_width = 0;
144
+ style.font_id = -1;
145
+ style.font_size = 0;
146
+ style.font_weight = 400;
147
+ style.line_height = 0;
148
+ style.line_height_multiplier = -1;
149
+ style.text_align = 0;
150
+ #if GEA_CSS_TEXT_DECORATION
151
+ style.text_decoration = 0;
152
+ #endif
153
+ #if GEA_CSS_TEXT_TRANSFORM
154
+ style.text_transform = 0;
155
+ #endif
156
+ style.white_space = 0;
157
+ style.text_overflow = 0;
158
+ style.overflow = 0;
159
+ #if GEA_CSS_OVERFLOW_AXES
160
+ style.overflow_x = 0;
161
+ #endif
162
+ #if GEA_CSS_OVERFLOW_AXES
163
+ style.overflow_y = 0;
164
+ #endif
165
+ #if GEA_CSS_MASK
166
+ style.mask_right_fade_width = 0;
167
+ #endif
168
+ #if GEA_CSS_IMAGE_FIT
169
+ style.image_fit = 0;
170
+ #endif
171
+ #if GEA_CSS_TRANSFORMS
172
+ style.backface_hidden = 0;
173
+ #endif
174
+ #if GEA_CSS_VISIBILITY
175
+ style.visibility = 0;
176
+ #endif
177
+ #if GEA_CSS_POINTER_EVENTS
178
+ style.pointer_events = 0;
179
+ #endif
180
+ return style;
181
+ }
182
+ constexpr ComputedStyle kDefaultStyle = makeDefaultStyle();
183
+ } // namespace
184
+
185
+ void NodeLifecycle::resetStyle(ComputedStyle &style)
186
+ {
187
+ // Member assignment preserves adjacent state when Node reuses tail padding.
188
+ style = kDefaultStyle;
189
+ }
190
+
191
+ void NodeLifecycle::init(Node *n, NodeType type)
192
+ {
193
+ n->type = type;
194
+ resetStyle(n->style);
99
195
  n->text.clear();
196
+ #if GEA_UI_IMAGE_NODES
100
197
  n->image_id = -1;
198
+ #endif
101
199
  n->tag_id = 0; // 0 = empty tag (interned tag table index 0)
102
- n->style.image_fit = 0;
103
- n->style.backface_hidden = 0;
104
- n->style.visibility = 0;
105
- n->style.pointer_events = 0;
106
200
  n->parent = -1;
107
201
  n->first_child = -1;
108
202
  n->last_child = -1;
@@ -113,16 +207,21 @@ void NodeLifecycle::init(Node *n, NodeType type)
113
207
  n->layout.width = 0;
114
208
  n->layout.height = 0;
115
209
  n->layout.inline_indent = 0;
210
+ #if GEA_CSS_SCROLLING
116
211
  n->layout.scroll_x = 0;
117
212
  n->layout.scroll_y = 0;
118
213
  n->layout.scroll_content_width = 0;
119
214
  n->layout.scroll_content_height = 0;
215
+ #endif
120
216
  n->layout.previous_x = 0;
121
217
  n->layout.previous_y = 0;
122
218
  n->layout.previous_width = 0;
123
219
  n->layout.previous_height = 0;
220
+ #if GEA_CSS_SCROLLING
124
221
  n->layout.previous_scroll_x = 0;
125
222
  n->layout.previous_scroll_y = 0;
223
+ #endif
224
+ #if GEA_CSS_TRANSFORMS
126
225
  n->render.previous_rotate_angle = 0;
127
226
  n->render.previous_rotate_axis_x = 0;
128
227
  n->render.previous_rotate_axis_y = 0;
@@ -150,12 +249,21 @@ void NodeLifecycle::init(Node *n, NodeType type)
150
249
  n->render.previous_perspective_origin_x = 500;
151
250
  n->render.previous_perspective_origin_y = 500;
152
251
  n->render.previous_transformable_box = 0;
252
+ #endif
253
+ #if GEA_CSS_FILTERS
153
254
  n->render.previous_filter_blur_radius = 0;
255
+ #endif
154
256
  n->render.inline_baseline = 0;
155
257
  n->render.dirty = 0;
258
+ #if GEA_CSS_SCROLLING
156
259
  n->render.scroll_dirty = 0;
260
+ #endif
261
+ #if GEA_CSS_SCROLLING
157
262
  n->render.non_scroll_dirty = 0;
263
+ #endif
264
+ #if GEA_CSS_TRANSFORMS
158
265
  n->render.transform_dirty = 0;
266
+ #endif
159
267
  n->render.text_layout_stable = 0;
160
268
  }
161
269
 
@@ -8,6 +8,7 @@ namespace gea::embedded::ui {
8
8
  class NodeLifecycle {
9
9
  public:
10
10
  static void init(Node *node, NodeType type);
11
+ static void resetStyle(ComputedStyle &style);
11
12
  };
12
13
 
13
14
  } // namespace gea::embedded::ui