@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.
package/canvas.cpp CHANGED
@@ -6,10 +6,12 @@
6
6
  #include "pixel.h"
7
7
 
8
8
  #include <algorithm>
9
+ #include <atomic>
9
10
  #include <cmath>
10
11
  #include <cstdio>
11
12
  #include <cstdlib>
12
13
  #include <cstring>
14
+ #include <type_traits>
13
15
  #include <vector>
14
16
 
15
17
  // For the compile-gated GEA_EMBEDDED_TEXT_SPRITE_DIAG counters (see the diag
@@ -49,6 +51,7 @@
49
51
  namespace gea::framework::graphics {
50
52
 
51
53
  namespace {
54
+ #if GEA_EMBEDDED_RENDERER_TRIANGLE_OCCLUSION
52
55
  // Per-scanline coverage bitmask for fillTrianglesOpaqueOccluded. Bit x set = a
53
56
  // nearer triangle already owns pixel x on that chunk-local row. Two banks so two
54
57
  // Canvases on different cores can occlude concurrently (cross-core band raster).
@@ -69,6 +72,7 @@ inline int occlCoreBank()
69
72
  return 0;
70
73
  #endif
71
74
  }
75
+ #endif
72
76
  } // namespace
73
77
 
74
78
  constexpr int kBitmapFontWidth = BitmapFont8x16::kWidth;
@@ -240,14 +244,18 @@ void adoptHotTextSprite(const TextSprite &s)
240
244
  }
241
245
  #endif // GEA_EMBEDDED_TEXT_SPRITE_HOT_STAGE_BYTES > 0
242
246
 
243
- std::uint32_t hashTextContent(const char *s)
247
+ TextSprite &textSpriteFor(const char *text, const RasterizedFont &font)
244
248
  {
245
- std::uint32_t h = 2166136261u; // FNV-1a
246
- for (; *s; ++s) {
247
- h ^= static_cast<std::uint8_t>(*s);
248
- h *= 16777619u;
249
+ // Search all four slots: a direct-mapped hash makes alternating labels
250
+ // such as "FPS: 59" and "FPS: 60" evict each other. Hits stay read-only;
251
+ // a four-byte replacement cursor advances only for a new cache key.
252
+ for (TextSprite &candidate : gTextSprites) {
253
+ if (candidate.fontData == font.data() && candidate.sizePx == font.sizePx() &&
254
+ std::strcmp(candidate.text, text) == 0)
255
+ return candidate;
249
256
  }
250
- return h;
257
+ static std::atomic<unsigned> nextSlot{0};
258
+ return gTextSprites[nextSlot.fetch_add(1, std::memory_order_relaxed) % kTextSpriteSlots];
251
259
  }
252
260
 
253
261
  // Rasterize `text` into `sprite`'s coverage buffer in text-relative coordinates
@@ -845,16 +853,31 @@ public:
845
853
  #define GEA_EMBEDDED_CANVAS_CIRCLE_BOX_SPAN_SLOTS 16
846
854
  #endif
847
855
 
848
- static constexpr int kCircleSpanMax = 32;
856
+ #ifndef GEA_EMBEDDED_CANVAS_CIRCLE_SPAN_MAX
857
+ #define GEA_EMBEDDED_CANVAS_CIRCLE_SPAN_MAX 32
858
+ #endif
859
+ static constexpr int kCircleSpanMax = GEA_EMBEDDED_CANVAS_CIRCLE_SPAN_MAX;
849
860
  static constexpr int kCircleSpanSlotCount = (kCircleSpanMax / 2) + 1;
850
861
  static constexpr int kCircleRadiusMax = GEA_EMBEDDED_CANVAS_CIRCLE_RADIUS_MAX;
851
- static constexpr int kCircleRadiusSpanRows = (kCircleRadiusMax * 2) + 1;
862
+ // Tables are concatenated at their actual heights, not at the maximum
863
+ // height for every radius. Even-size slot s uses 2*s rows; radius r uses
864
+ // 2*r+1 rows. Their starts are s*(s-1) and r*r respectively.
865
+ static constexpr int kCircleSpanRows = kCircleSpanSlotCount * (kCircleSpanSlotCount - 1);
866
+ static constexpr int kCircleRadiusRows = (kCircleRadiusMax + 1) * (kCircleRadiusMax + 1);
852
867
  static constexpr int kCircleBoxSpanMax = GEA_EMBEDDED_CANVAS_CIRCLE_BOX_SPAN_MAX;
853
868
  static constexpr int kCircleBoxSpanSlots = GEA_EMBEDDED_CANVAS_CIRCLE_BOX_SPAN_SLOTS;
869
+ static_assert(kCircleSpanMax > 0 && kCircleSpanMax <= 32 && (kCircleSpanMax % 2) == 0);
854
870
  static_assert(kCircleRadiusMax > 0 && kCircleRadiusMax < 64);
855
871
  static_assert(kCircleBoxSpanMax > 0 && kCircleBoxSpanMax <= 255);
856
872
  static_assert(kCircleBoxSpanSlots > 0);
857
873
 
874
+ using CircleSpanReady = std::conditional_t<(kCircleSpanSlotCount <= 8), std::uint8_t,
875
+ std::conditional_t<(kCircleSpanSlotCount <= 16), std::uint16_t, std::uint32_t>>;
876
+ using CircleRadiusReady = std::conditional_t<(kCircleRadiusMax < 8), std::uint8_t,
877
+ std::conditional_t<(kCircleRadiusMax < 16), std::uint16_t,
878
+ std::conditional_t<(kCircleRadiusMax < 32), std::uint32_t, std::uint64_t>>>;
879
+ using CircleBoxSlot = std::conditional_t<(kCircleBoxSpanSlots <= 256), std::uint8_t, std::uint32_t>;
880
+
858
881
  #endif
859
882
  static int min(int a, int b) { return a < b ? a : b; }
860
883
 
@@ -874,19 +897,20 @@ public:
874
897
  {
875
898
  #if GEA_EMBEDDED_RENDERER_CIRCLES
876
899
  if (size <= 0 || size > kCircleSpanMax || (size & 1)) return nullptr;
877
- int slot = size / 2;
878
- std::uint32_t bit = 1u << slot;
900
+ const int slot = size / 2;
901
+ auto *spans = instance().circleSpanCache_ + slot * (slot - 1);
902
+ const CircleSpanReady bit = static_cast<CircleSpanReady>(CircleSpanReady{1} << slot);
879
903
  if (!(instance().circleSpanCacheReady_ & bit)) {
880
904
  int radius2 = size * size;
881
905
  for (int row = 0; row < size; row++) {
882
906
  int dy2 = row * 2 + 1 - size;
883
907
  int dx2 = integerSqrt(radius2 - dy2 * dy2);
884
- instance().circleSpanCache_[slot][row][0] = (std::uint8_t)((size - dx2) / 2);
885
- instance().circleSpanCache_[slot][row][1] = (std::uint8_t)((size + dx2 - 1) / 2);
908
+ spans[row][0] = (std::uint8_t)((size - dx2) / 2);
909
+ spans[row][1] = (std::uint8_t)((size + dx2 - 1) / 2);
886
910
  }
887
911
  instance().circleSpanCacheReady_ |= bit;
888
912
  }
889
- return instance().circleSpanCache_[slot];
913
+ return spans;
890
914
  #else
891
915
  (void)size;
892
916
  return nullptr;
@@ -928,19 +952,20 @@ public:
928
952
  {
929
953
  #if GEA_EMBEDDED_RENDERER_CIRCLES
930
954
  if (radius <= 0 || radius > kCircleRadiusMax) return nullptr;
931
- std::uint64_t bit = 1ull << radius;
955
+ const int rr = radius * radius;
956
+ auto *spans = instance().circleRadiusSpanCache_ + rr;
957
+ const CircleRadiusReady bit = static_cast<CircleRadiusReady>(CircleRadiusReady{1} << radius);
932
958
  if (!(instance().circleRadiusSpanCacheReady_ & bit)) {
933
959
  const int diameter = radius * 2 + 1;
934
- const int rr = radius * radius;
935
960
  for (int row = 0; row < diameter; row++) {
936
961
  const int dy = row - radius;
937
962
  const int dx = integerSqrt(rr - dy * dy);
938
- instance().circleRadiusSpanCache_[radius][row][0] = (std::uint8_t)(radius - dx);
939
- instance().circleRadiusSpanCache_[radius][row][1] = (std::uint8_t)(radius + dx);
963
+ spans[row][0] = (std::uint8_t)(radius - dx);
964
+ spans[row][1] = (std::uint8_t)(radius + dx);
940
965
  }
941
966
  instance().circleRadiusSpanCacheReady_ |= bit;
942
967
  }
943
- return instance().circleRadiusSpanCache_[radius];
968
+ return spans;
944
969
  #else
945
970
  (void)radius;
946
971
  return nullptr;
@@ -955,13 +980,13 @@ public:
955
980
  }
956
981
 
957
982
  private:
958
- std::uint8_t circleSpanCache_[kCircleSpanSlotCount][kCircleSpanMax][2]{};
959
- std::uint32_t circleSpanCacheReady_ = 0;
960
- std::uint8_t circleRadiusSpanCache_[kCircleRadiusMax + 1][kCircleRadiusSpanRows][2]{};
961
- std::uint64_t circleRadiusSpanCacheReady_ = 0;
983
+ std::uint8_t circleSpanCache_[kCircleSpanRows][2]{};
984
+ CircleSpanReady circleSpanCacheReady_ = 0;
985
+ std::uint8_t circleRadiusSpanCache_[kCircleRadiusRows][2]{};
986
+ CircleRadiusReady circleRadiusSpanCacheReady_ = 0;
962
987
  std::uint8_t circleBoxSpanCache_[kCircleBoxSpanSlots][kCircleBoxSpanMax][2]{};
963
988
  std::uint8_t circleBoxSpanSize_[kCircleBoxSpanSlots]{};
964
- int circleBoxSpanNext_ = 0;
989
+ CircleBoxSlot circleBoxSpanNext_ = 0;
965
990
  #endif
966
991
  };
967
992
 
@@ -2120,6 +2145,15 @@ void Canvas::fillTriangleOpaque(int x0, int y0, int x1, int y1, int x2, int y2,
2120
2145
  void Canvas::fillTrianglesOpaqueOccluded(const TriangleEntry *tris, int count, int ox, int oy)
2121
2146
  {
2122
2147
  if (!pixels_ || count <= 0) return;
2148
+ #if !GEA_EMBEDDED_RENDERER_TRIANGLE_OCCLUSION
2149
+ // Same painter's-order fallback used for chunks larger than the scratch.
2150
+ // Unused optimizations reserve no storage, but native commands still draw.
2151
+ for (int i = 0; i < count; ++i) {
2152
+ const TriangleEntry &t = tris[i];
2153
+ fillTriangleOpaque(t.x0 - ox, t.y0 - oy, t.x1 - ox, t.y1 - oy,
2154
+ t.x2 - ox, t.y2 - oy, t.color);
2155
+ }
2156
+ #else
2123
2157
  const int rows = height_;
2124
2158
  // Fall back to painter's back-to-front when the chunk exceeds the coverage
2125
2159
  // scratch (only gea3d's small half-res chunks take the occluded path).
@@ -2232,6 +2266,7 @@ void Canvas::fillTrianglesOpaqueOccluded(const TriangleEntry *tris, int count, i
2232
2266
  }
2233
2267
  }
2234
2268
  if (dirty_x1 >= dirty_x0 && dirty_y1 >= dirty_y0) markDirty(dirty_x0, dirty_y0, dirty_x1, dirty_y1);
2269
+ #endif
2235
2270
  }
2236
2271
 
2237
2272
  void Canvas::drawText(const char *text, int x, int y, pixel::native_t color, float scale)
@@ -2636,7 +2671,7 @@ void Canvas::drawRasterizedText(const char *text, int x, int y, pixel::native_t
2636
2671
  if (len == 0 || len > static_cast<std::size_t>(kTextSpriteMaxLen)) gTsDiag.tooLong++;
2637
2672
  #endif
2638
2673
  if (len > 0 && len <= static_cast<std::size_t>(kTextSpriteMaxLen)) {
2639
- TextSprite &slot = gTextSprites[hashTextContent(text) % kTextSpriteSlots];
2674
+ TextSprite &slot = textSpriteFor(text, font);
2640
2675
  const bool idMatch = slot.fontData == font.data() &&
2641
2676
  slot.sizePx == font.sizePx() &&
2642
2677
  std::strcmp(slot.text, text) == 0;
package/css/engine.h CHANGED
@@ -16,6 +16,7 @@
16
16
  #include <utility>
17
17
  #include <vector>
18
18
 
19
+ #include "../ui/css_features.h"
19
20
  #include "../ui/style.h"
20
21
  #include "animation.h"
21
22
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geastack/engine",
3
- "version": "0.1.7",
3
+ "version": "0.1.8",
4
4
  "description": "GeaStack rendering engine, intrinsic JSX primitives, and native engine backends.",
5
5
  "license": "Apache-2.0",
6
6
  "repository": {
@@ -57,6 +57,7 @@
57
57
  },
58
58
  "sideEffects": false,
59
59
  "dependencies": {
60
- "@geastack/core": "^0.1.27"
61
- }
60
+ "@geastack/core": "^0.1.30"
61
+ },
62
+ "gitHead": "e375eddd8f725d7cc5de3fd46baca63e35936027"
62
63
  }
@@ -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,18 +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)
66
- {
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
65
  template <int side>
73
66
  int resolvedPositionOffset(const Node &child, int basis)
74
67
  {
75
- int offset = GEA_CSS_POSITION_PX(child.style, side) != kUnset ? GEA_CSS_POSITION_PX(child.style, side) : 0;
76
- const int percent = GEA_CSS_POSITION_PERCENT(child.style, 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);
77
70
  if (percent != kUnset) {
78
71
  const int numerator = basis * percent;
79
72
  offset += (numerator + (numerator >= 0 ? 500 : -500)) / 1000;
@@ -84,45 +77,45 @@ int resolvedPositionOffset(const Node &child, int basis)
84
77
  template <int side>
85
78
  bool hasPositionOffset(const Node &node)
86
79
  {
87
- return GEA_CSS_POSITION_PX(node.style, side) != kUnset || GEA_CSS_POSITION_PERCENT(node.style, side) != kUnset;
80
+ return GEA_CSS_POSITION_PX(node.computedStyle(), side) != kUnset || GEA_CSS_POSITION_PERCENT(node.computedStyle(), side) != kUnset;
88
81
  }
89
82
 
90
83
  bool hasExplicitWidth(const Node &node)
91
84
  {
92
- return node.style.width != kUnset || node.style.width_percent != kUnset;
85
+ return node.computedStyle().width != kUnset || node.computedStyle().width_percent != kUnset;
93
86
  }
94
87
 
95
88
  bool hasExplicitHeight(const Node &node)
96
89
  {
97
- return node.style.height != kUnset || node.style.height_percent != kUnset;
90
+ return node.computedStyle().height != kUnset || node.computedStyle().height_percent != kUnset;
98
91
  }
99
92
 
100
93
  bool retainableAbsoluteLayoutNode(const Node &node)
101
94
  {
102
- 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;
103
96
  if (node.parent < 0) return false;
104
97
  const Node &parent = Tree::instance().nodes()[node.parent];
105
98
  // A static wrapper cannot supply the offsets for a more distant containing
106
99
  // block. Let the full positioning pass resolve that ancestor instead.
107
- if (parent.parent >= 0 && parent.style.position == 0) return false;
100
+ if (parent.parent >= 0 && parent.computedStyle().position == 0) return false;
108
101
  // Grid area geometry and its percentage bases belong to the grid pass.
109
- if (isDisplayGrid(Tree::instance().nodes()[node.parent].style)) return false;
102
+ if (isDisplayGrid(parent.computedStyle())) return false;
110
103
  if (!hasExplicitWidth(node) || !hasExplicitHeight(node)) return false;
111
104
  if (node.first_child >= 0) {
112
- if (node.style.width != kUnset && node.style.width != node.layout.width) return false;
113
- 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;
114
107
  if (node.layout.width != node.layout.previous_width || node.layout.height != node.layout.previous_height) return false;
115
108
  }
116
- if (node.style.min_width != 0 ||
117
- node.style.min_height != 0 ||
118
- node.style.max_width != kUnset ||
119
- node.style.max_height != kUnset) return false;
120
- if (node.style.flex != 0 ||
121
- node.style.padding[0] ||
122
- node.style.padding[1] ||
123
- node.style.padding[2] ||
124
- node.style.padding[3]) return false;
125
- 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;
126
119
  return true;
127
120
  }
128
121
 
@@ -130,14 +123,14 @@ bool retainableAbsoluteNode(const Node &node)
130
123
  {
131
124
  if (!retainableAbsoluteLayoutNode(node)) return false;
132
125
  if (hasTransformState(node)) return false;
133
- if (rstyle(node.style).transform_origin_x != node.render.previous_transform_origin_x ||
134
- 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;
135
128
  return true;
136
129
  }
137
130
 
138
131
  bool retainableStaticTransformedPaintNode(const Node &node)
139
132
  {
140
- if (!isViewLikeNodeType(node.type) || node.style.position != 1) return false;
133
+ if (!isViewLikeNodeType(node.type) || node.computedStyle().position != 1) return false;
141
134
  if (node.parent < 0) return false;
142
135
  if (!hasTransformState(node) || node.render.transform_dirty) return false;
143
136
  if (node.layout.x != node.layout.previous_x ||
@@ -145,8 +138,8 @@ bool retainableStaticTransformedPaintNode(const Node &node)
145
138
  node.layout.width != node.layout.previous_width ||
146
139
  node.layout.height != node.layout.previous_height)
147
140
  return false;
148
- if (rstyle(node.style).transform_origin_x != node.render.previous_transform_origin_x ||
149
- 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)
150
143
  return false;
151
144
  return true;
152
145
  }
@@ -168,23 +161,27 @@ int AbsoluteLeafRefresh::mode()
168
161
  auto &state = treeState();
169
162
  auto &perf = refreshPerfStatsMutable();
170
163
  ScopedRefreshStat timer(perf.treeAbsModeUs);
171
- perf.treeAbsModeCalls++;
164
+ GEA_REFRESH_PERF(perf.treeAbsModeCalls++);
172
165
  int dirtyNodes = 0;
173
166
  for (int i = 0; i < state.nodeCount; i++) {
174
167
  if (state.nodes[i].render.dirty)
175
168
  dirtyNodes++;
176
169
  }
177
- perf.treeAbsModeDirtyNodes += dirtyNodes;
170
+ GEA_REFRESH_PERF(perf.treeAbsModeDirtyNodes += dirtyNodes);
178
171
  if (dirtyNodes == 0) {
179
- perf.treeAbsModeNoop++;
172
+ GEA_REFRESH_PERF(perf.treeAbsModeNoop++);
180
173
  return -1;
181
174
  }
182
175
  auto reject = [&](int node, int reason) {
183
- perf.treeAbsModeFull++;
184
- perf.treeAbsModeRejectNode = node;
185
- perf.treeAbsModeRejectReason = reason;
176
+ GEA_REFRESH_PERF(perf.treeAbsModeFull++);
177
+ GEA_REFRESH_PERF(perf.treeAbsModeRejectNode = node);
178
+ GEA_REFRESH_PERF(perf.treeAbsModeRejectReason = reason);
186
179
  return 0;
187
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);
188
185
  for (int i = 0; i < state.nodeCount; i++) {
189
186
  Node *n = &state.nodes[i];
190
187
  if (!n->render.dirty) continue;
@@ -211,9 +208,9 @@ int AbsoluteLeafRefresh::mode()
211
208
  if (n->type == NodeType::Text && n->render.text_layout_stable &&
212
209
  n->parent >= 0 && n->first_child < 0) {
213
210
  if (hasTransformState(*n)) return reject(i, 3);
214
- if (rstyle(n->style).transform_origin_x != n->render.previous_transform_origin_x ||
215
- rstyle(n->style).transform_origin_y != n->render.previous_transform_origin_y) return reject(i, 4);
216
- 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 &&
217
214
  (n->layout.x != n->layout.previous_x ||
218
215
  n->layout.y != n->layout.previous_y ||
219
216
  n->layout.width != n->layout.previous_width ||
@@ -234,47 +231,63 @@ int AbsoluteLeafRefresh::mode()
234
231
  // style with no tree-wide relayout. Non-leaf nodes must keep stable size
235
232
  // so their descendants can be translated instead of reflowed.
236
233
  }
237
- perf.treeAbsModeFast++;
234
+ GEA_REFRESH_PERF(perf.treeAbsModeFast++);
238
235
  return 1;
239
236
  }
240
237
 
241
238
  void AbsoluteLeafRefresh::refreshPositions()
242
239
  {
243
240
  auto &state = treeState();
241
+ int cachedParent = -1;
242
+ int areaX = 0, areaY = 0, areaWidth = 0, areaHeight = 0;
244
243
  for (int i = 0; i < state.nodeCount; i++) {
245
244
  Node *n = &state.nodes[i];
246
245
  if (!n->render.dirty) continue;
247
246
  if (n->render.transform_dirty && !retainableAbsoluteLayoutNode(*n)) continue;
248
- 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;
249
248
  // Reconcile size from style for resized absolute leaves (mode() allowed
250
249
  // the change). Before position so right/bottom-anchored offsets use the
251
250
  // new extent. Percent-sized nodes keep the already-resolved layout box;
252
251
  // the full layout pass owns recomputing them when their containing block
253
252
  // changes.
254
- if (n->style.width != kUnset) n->layout.width = n->style.width;
255
- 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;
256
255
  Node *p = &state.nodes[n->parent];
257
- int areaX, areaY, areaWidth, areaHeight;
258
- 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
+ }
259
272
  const int before_x = n->layout.x;
260
273
  const int before_y = n->layout.y;
261
274
  int parent_x = p->layout.x;
262
- if (p->style.overflow == 2 && scrollsOverflowX(p->style)) parent_x -= p->layout.scroll_x;
275
+ if (p->computedStyle().overflow == 2 && scrollsOverflowX(p->computedStyle())) parent_x -= p->layout.scroll_x;
263
276
  if (hasPositionOffset<3>(*n))
264
277
  n->layout.x = parent_x + areaX + resolvedPositionOffset<3>(*n, areaWidth);
265
278
  else if (hasPositionOffset<1>(*n))
266
279
  n->layout.x = parent_x + areaX + areaWidth - n->layout.width - resolvedPositionOffset<1>(*n, areaWidth);
267
280
  else
268
- n->layout.x = parent_x + alignedAbsoluteOffset(*p, *n, true);
281
+ n->layout.x = parent_x + LayoutEngine::alignedAbsoluteOffset(*p, *n, true, p, areaX, areaWidth);
269
282
 
270
283
  int parent_y = p->layout.y;
271
- if (p->style.overflow == 2 && scrollsOverflowY(p->style)) parent_y -= p->layout.scroll_y;
284
+ if (p->computedStyle().overflow == 2 && scrollsOverflowY(p->computedStyle())) parent_y -= p->layout.scroll_y;
272
285
  if (hasPositionOffset<0>(*n))
273
286
  n->layout.y = parent_y + areaY + resolvedPositionOffset<0>(*n, areaHeight);
274
287
  else if (hasPositionOffset<2>(*n))
275
288
  n->layout.y = parent_y + areaY + areaHeight - n->layout.height - resolvedPositionOffset<2>(*n, areaHeight);
276
289
  else
277
- n->layout.y = parent_y + alignedAbsoluteOffset(*p, *n, false);
290
+ n->layout.y = parent_y + LayoutEngine::alignedAbsoluteOffset(*p, *n, false, p, areaY, areaHeight);
278
291
  translateDescendantLayouts(state, i, n->layout.x - before_x, n->layout.y - before_y);
279
292
  }
280
293
  }
package/ui/core.cpp CHANGED
@@ -16,7 +16,7 @@ Tree &Tree::instance()
16
16
 
17
17
  void Tree::markDisplayListDirty()
18
18
  {
19
- refreshPerfStatsMutable().treeMarkDisplayListDirtyCalls++;
19
+ GEA_REFRESH_PERF(refreshPerfStatsMutable().treeMarkDisplayListDirtyCalls++);
20
20
  auto &state = treeState();
21
21
  state.displayListDirty = true;
22
22
  // Structural: the pending rebuild may change draw order / which commands
@@ -26,7 +26,7 @@ void Tree::markDisplayListDirty()
26
26
 
27
27
  void Tree::markDisplayListContentDirty()
28
28
  {
29
- refreshPerfStatsMutable().treeMarkDisplayListContentDirtyCalls++;
29
+ GEA_REFRESH_PERF(refreshPerfStatsMutable().treeMarkDisplayListContentDirtyCalls++);
30
30
  // Appearance-only rebuild on existing nodes (no draw-order change): request
31
31
  // the rebuild but leave displayListRebuildStructural alone, so refresh can
32
32
  // replay only the dirty-node regions. A structural change elsewhere in the
@@ -37,7 +37,7 @@ void Tree::markDisplayListContentDirty()
37
37
  void Tree::markNodeDisplayCommandsDirty(int node)
38
38
  {
39
39
  if (node < 0 || node >= kMaxNodes) return;
40
- refreshPerfStatsMutable().treeMarkNodeCommandDirtyCalls++;
40
+ GEA_REFRESH_PERF(refreshPerfStatsMutable().treeMarkNodeCommandDirtyCalls++);
41
41
  auto &state = treeState();
42
42
  state.nodeCommandDirty[node] = 1;
43
43
  const int root = state.mountedRoot;
@@ -97,7 +97,7 @@ bool TreeInspection::hasMountedText(const char *text)
97
97
  if (tree.node(i).text != text) continue;
98
98
  int node = i;
99
99
  for (int depth = 0; node >= 0 && node < tree.nodeCount() && depth < tree.nodeCount(); ++depth) {
100
- if (isDisplayNone(tree.node(node).style)) break;
100
+ if (isDisplayNone(tree.node(node).computedStyle())) break;
101
101
  if (node == tree.mountedRoot()) return true;
102
102
  node = tree.node(node).parent;
103
103
  }
package/ui/css_features.h CHANGED
@@ -1,6 +1,84 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  #pragma once
3
3
 
4
+ // Custom-property containers and dependency caches need whole-source proof.
5
+ #ifndef GEA_CSS_CUSTOM_PROPERTIES
6
+ #define GEA_CSS_CUSTOM_PROPERTIES 1
7
+ #endif
8
+
9
+ // v17 default-field reachability facts; only a whole-source proof disables them.
10
+ #ifndef GEA_CSS_MARGINS
11
+ #define GEA_CSS_MARGINS 1
12
+ #endif
13
+ #ifndef GEA_CSS_PADDING
14
+ #define GEA_CSS_PADDING 1
15
+ #endif
16
+ #ifndef GEA_CSS_FLEX_FACTORS
17
+ #define GEA_CSS_FLEX_FACTORS 1
18
+ #endif
19
+ #ifndef GEA_CSS_GAP
20
+ #define GEA_CSS_GAP 1
21
+ #endif
22
+ #ifndef GEA_CSS_BORDER_WIDTHS
23
+ #define GEA_CSS_BORDER_WIDTHS 1
24
+ #endif
25
+ #ifndef GEA_CSS_BORDER_COLORS
26
+ #define GEA_CSS_BORDER_COLORS 1
27
+ #endif
28
+ #ifndef GEA_CSS_FONT_WEIGHT
29
+ #define GEA_CSS_FONT_WEIGHT 1
30
+ #endif
31
+ #ifndef GEA_CSS_TEXT_ALIGN
32
+ #define GEA_CSS_TEXT_ALIGN 1
33
+ #endif
34
+ #ifndef GEA_CSS_WHITE_SPACE
35
+ #define GEA_CSS_WHITE_SPACE 1
36
+ #endif
37
+ #ifndef GEA_CSS_TEXT_OVERFLOW
38
+ #define GEA_CSS_TEXT_OVERFLOW 1
39
+ #endif
40
+
41
+ // v16 common-style reachability facts. Unknown builds keep native defaults.
42
+ #ifndef GEA_CSS_FLEX_DIRECTION
43
+ #define GEA_CSS_FLEX_DIRECTION 1
44
+ #endif
45
+ #ifndef GEA_CSS_JUSTIFY_CONTENT
46
+ #define GEA_CSS_JUSTIFY_CONTENT 1
47
+ #endif
48
+ #ifndef GEA_CSS_ALIGN_ITEMS
49
+ #define GEA_CSS_ALIGN_ITEMS 1
50
+ #endif
51
+ #ifndef GEA_CSS_BOX_SIZING
52
+ #define GEA_CSS_BOX_SIZING 1
53
+ #endif
54
+ #ifndef GEA_CSS_MARGIN_AUTO
55
+ #define GEA_CSS_MARGIN_AUTO 1
56
+ #endif
57
+ #ifndef GEA_CSS_LINE_HEIGHT_MULTIPLIER
58
+ #define GEA_CSS_LINE_HEIGHT_MULTIPLIER 1
59
+ #endif
60
+ // Automatic whole-source percentage reachability. Older builds retain fields.
61
+ #ifndef GEA_CSS_WIDTH_PERCENT
62
+ #define GEA_CSS_WIDTH_PERCENT 1
63
+ #endif
64
+ #ifndef GEA_CSS_HEIGHT_PERCENT
65
+ #define GEA_CSS_HEIGHT_PERCENT 1
66
+ #endif
67
+
68
+ #ifndef GEA_CSS_WIDTH_EXPRESSIONS
69
+ #define GEA_CSS_WIDTH_EXPRESSIONS 1
70
+ #endif
71
+ #ifndef GEA_CSS_MIN_HEIGHT
72
+ #define GEA_CSS_MIN_HEIGHT 1
73
+ #endif
74
+ #ifndef GEA_CSS_MAX_WIDTH
75
+ #define GEA_CSS_MAX_WIDTH 1
76
+ #endif
77
+ #ifndef GEA_CSS_ACTIVE_BACKGROUND
78
+ #define GEA_CSS_ACTIVE_BACKGROUND 1
79
+ #endif
80
+
81
+
4
82
  #ifndef GEA_CSS_PSEUDO_ELEMENTS
5
83
  #define GEA_CSS_PSEUDO_ELEMENTS 1
6
84
  #endif
@@ -280,3 +358,12 @@
280
358
  (std::integral_constant<int, (side)>::value == 0 ? GEA_CSS_POSITION_PERCENT_0(style) : \
281
359
  std::integral_constant<int, (side)>::value == 1 ? GEA_CSS_POSITION_PERCENT_1(style) : \
282
360
  std::integral_constant<int, (side)>::value == 2 ? GEA_CSS_POSITION_PERCENT_2(style) : GEA_CSS_POSITION_PERCENT_3(style))
361
+
362
+ // Optional default-valued fields: only a complete compact-style source proof
363
+ // can omit them. Layout uses these constants directly in a pruned application.
364
+ #ifndef GEA_CSS_LINE_HEIGHT
365
+ #define GEA_CSS_LINE_HEIGHT 1
366
+ #endif
367
+ #ifndef GEA_CSS_DISPLAY_EXPLICIT
368
+ #define GEA_CSS_DISPLAY_EXPLICIT 1
369
+ #endif
package/ui/document.cpp CHANGED
@@ -8,6 +8,7 @@
8
8
 
9
9
  #include <algorithm>
10
10
  #include <cctype>
11
+ #include <cstdlib>
11
12
  #include <cstring>
12
13
  #include <utility>
13
14
  #include <vector>
@@ -268,7 +269,15 @@ int Document::preferredMountHeight() { return g_preferred_mount_h; }
268
269
  ViewElement Document::ensureAppRoot(const char *id) const
269
270
  {
270
271
  const char *rootId = (id && id[0] != '\0') ? id : "app";
272
+ #if GEA_UI_NODE_ATTRIBUTES
271
273
  NodeHandle existing = findElementById(Tree::instance(), rootId);
274
+ #else
275
+ // With no authored attributes or ID selectors, the framework's implicit
276
+ // #app is just the mounted root. Its built-in identity needs no per-node
277
+ // attribute owner. Authored DOM lookups retain the ordinary path above.
278
+ if (std::strcmp(rootId, "app") != 0) std::abort();
279
+ NodeHandle existing(Tree::instance().mountedRoot());
280
+ #endif
272
281
  ViewElement root = existing ? ViewElement(existing.id()) : createView();
273
282
  Tree &tree = Tree::instance();
274
283
  const int rootW = g_preferred_mount_w > 0 ? g_preferred_mount_w
@@ -278,7 +287,9 @@ ViewElement Document::ensureAppRoot(const char *id) const
278
287
  : tree.mountedHeight() > 0 ? tree.mountedHeight()
279
288
  : gea::platform::display::kHeight;
280
289
  if (!existing) {
290
+ #if GEA_UI_NODE_ATTRIBUTES
281
291
  root.setAttribute("id", rootId);
292
+ #endif
282
293
  root.style().width(rootW);
283
294
  root.style().height(rootH);
284
295
  }