@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.
package/ui/node_model.h CHANGED
@@ -138,6 +138,7 @@ inline bool isNativeButtonNodeType(NodeType type)
138
138
  // or embedded inline in ComputedStyle when GEA_EMBEDDED_RARE_STYLE_INLINE is set (defined
139
139
  // BEFORE ComputedStyle so it can be a by-value member).
140
140
  struct RareStyle {
141
+ bool operator==(const RareStyle &) const = default;
141
142
  // Logical edges: block-start/end, inline-start/end.
142
143
  #if GEA_CSS_MARGIN_TRIM
143
144
  uint8_t margin_trim = 0;
@@ -475,23 +476,62 @@ inline int composedTranslateYPercent(const RareStyle &s) { return int(s.transfor
475
476
  static_assert(GEA_CSS_RARE_STYLE || std::is_empty<RareStyle>::value, "An unguarded rare field requires a reachability family");
476
477
 
477
478
  struct ComputedStyle {
478
- int8_t display;
479
+ bool operator==(const ComputedStyle &) const = default;
480
+ uint8_t display : 2;
479
481
  // True iff the `display` property was explicitly authored (a CSS rule or
480
482
  // inline style set it), as opposed to the kDisplayBlock default. Lets the
481
483
  // inline-formatting heuristic distinguish an explicit `display:block` on an
482
484
  // inline-level tag (e.g. <span style="display:block">, which is block-level
483
485
  // and stacks) from a span's default inline behaviour. Mirrors
484
486
  // flex_direction_explicit.
485
- int8_t display_explicit;
487
+ #if GEA_CSS_DISPLAY_EXPLICIT
488
+ uint8_t display_explicit : 1;
489
+ #else
490
+ static constexpr uint8_t display_explicit = 0;
491
+ #endif
492
+ #if GEA_CSS_TEXT_ALIGN
493
+ int8_t text_align;
494
+ #else
495
+ static constexpr int8_t text_align = 0;
496
+ #endif
497
+ int8_t overflow : 3;
498
+ uint8_t position : 2;
499
+ uint8_t has_bg : 1;
500
+ #if GEA_CSS_Z_INDEX
501
+ uint8_t z_index_auto : 1;
502
+ #else
503
+ static constexpr int8_t z_index_auto = 1;
504
+ #endif
505
+ // A proven single byte radius fills the leading text-alignment slot when
506
+ // that field is absent. Its read remains one ordinary byte load.
507
+ #if GEA_CSS_U8_RADIUS && GEA_CSS_RADIUS_COUNT == 1 && !GEA_CSS_TEXT_ALIGN
508
+ uint8_t border_radius[1];
509
+ #endif
510
+ #if GEA_CSS_FLEX_DIRECTION
486
511
  int8_t flex_direction;
512
+ #else
513
+ static constexpr int8_t flex_direction = 0;
514
+ #endif
515
+ #if GEA_CSS_FLEX_DIRECTION
487
516
  int8_t flex_direction_explicit;
517
+ #else
518
+ static constexpr int8_t flex_direction_explicit = 0;
519
+ #endif
488
520
  #if GEA_CSS_FLEX_WRAP
489
521
  int8_t flex_wrap;
490
522
  #else
491
523
  static constexpr int8_t flex_wrap = 0;
492
524
  #endif // low bits: 0 nowrap, 1 wrap, 2 wrap-reverse; bit 2: balance
525
+ #if GEA_CSS_JUSTIFY_CONTENT
493
526
  int8_t justify_content;
527
+ #else
528
+ static constexpr int8_t justify_content = 0;
529
+ #endif
530
+ #if GEA_CSS_ALIGN_ITEMS
494
531
  int8_t align_items;
532
+ #else
533
+ static constexpr int8_t align_items = 0;
534
+ #endif
495
535
  #if GEA_CSS_JUSTIFY_ITEMS
496
536
  int8_t justify_items;
497
537
  #else
@@ -507,10 +547,14 @@ struct ComputedStyle {
507
547
  #else
508
548
  static constexpr int8_t align_self = -1;
509
549
  #endif
510
- #if !GEA_CSS_U8_GAP
550
+ #if GEA_CSS_GAP && !GEA_CSS_U8_GAP
511
551
  int16_t gap;
512
552
  #endif
553
+ #if GEA_CSS_BOX_SIZING
513
554
  int8_t box_sizing; // 0: content-box (CSS initial), 1: border-box
555
+ #else
556
+ static constexpr int8_t box_sizing = 0;
557
+ #endif
514
558
  #if GEA_CSS_FLOATS
515
559
  int8_t float_side;
516
560
  #else
@@ -531,7 +575,11 @@ struct ComputedStyle {
531
575
  #else
532
576
  static constexpr int8_t direction = 0;
533
577
  #endif // -1: inherit, 0: ltr, 1: rtl
578
+ #if GEA_CSS_MARGIN_AUTO
534
579
  uint8_t margin_auto; // TRBL bit mask; numeric margins remain zero for auto
580
+ #else
581
+ static constexpr uint8_t margin_auto = 0;
582
+ #endif
535
583
  #if GEA_CSS_AXIS_GAP
536
584
  int16_t row_gap, column_gap; // kUnset falls back to native gap
537
585
  #else
@@ -546,7 +594,7 @@ struct ComputedStyle {
546
594
  // color must not allocate a rare-style record merely for its binding flags.
547
595
  // Bits 0..3: explicit side colors; bit 4: literal common color;
548
596
  // bits 5..8: explicit side currentColor. Unspecified colors use currentColor.
549
- #if !GEA_CSS_U8_BORDER_FLAGS
597
+ #if GEA_CSS_BORDER_COLORS && !GEA_CSS_U8_BORDER_FLAGS
550
598
  uint16_t border_color_flags = 0;
551
599
  #endif
552
600
  #if GEA_CSS_ORDER
@@ -556,29 +604,54 @@ struct ComputedStyle {
556
604
  #endif
557
605
  // Inherited unitless line-height number as IEEE float bits; -1 means length/normal.
558
606
  // Keep this common inherited value out of the much larger rare-style allocation.
607
+ #if GEA_CSS_LINE_HEIGHT_MULTIPLIER
559
608
  int32_t line_height_multiplier;
609
+ #else
610
+ static constexpr int32_t line_height_multiplier = -1;
611
+ #endif
560
612
 
613
+ #if GEA_CSS_WIDTH_EXPRESSIONS
561
614
  int32_t width_expression;
615
+ #else
616
+ static constexpr int32_t width_expression = -1;
617
+ #endif
562
618
  #if GEA_CSS_HEIGHT_EXPRESSIONS
563
619
  int32_t height_expression;
564
620
  #else
565
621
  static constexpr int32_t height_expression = -1;
566
622
  #endif
567
623
  int16_t width, height;
568
- int16_t width_percent, height_percent;
624
+ #if GEA_CSS_WIDTH_PERCENT
625
+ int16_t width_percent;
626
+ #else
627
+ static constexpr int16_t width_percent = kUnset;
628
+ #endif
629
+ #if GEA_CSS_HEIGHT_PERCENT
630
+ int16_t height_percent;
631
+ #else
632
+ static constexpr int16_t height_percent = kUnset;
633
+ #endif
569
634
  #if GEA_CSS_MIN_WIDTH
570
635
  int16_t min_width;
571
636
  #else
572
637
  static constexpr int16_t min_width = kUnset;
573
638
  #endif
639
+ #if GEA_CSS_MIN_HEIGHT
574
640
  int16_t min_height;
641
+ #else
642
+ static constexpr int16_t min_height = kUnset;
643
+ #endif
644
+ #if GEA_CSS_MAX_WIDTH
575
645
  int16_t max_width;
646
+ #else
647
+ static constexpr int16_t max_width = kUnset;
648
+ #endif
576
649
  #if GEA_CSS_MAX_HEIGHT
577
650
  int16_t max_height;
578
651
  #else
579
652
  static constexpr int16_t max_height = kUnset;
580
653
  #endif
581
- #if !GEA_CSS_U8_FLEX
654
+ #if GEA_CSS_FLEX_FACTORS && !GEA_CSS_U8_FLEX
582
655
  int16_t flex;
583
656
  int16_t flex_shrink;
584
657
  #endif
@@ -593,17 +666,15 @@ struct ComputedStyle {
593
666
  static constexpr int16_t flex_basis = kUnset;
594
667
  #endif
595
668
 
596
- #if !GEA_CSS_U8_PADDING
669
+ #if GEA_CSS_PADDING && !GEA_CSS_U8_PADDING
597
670
  int16_t padding[4];
598
671
  #endif
672
+ #if GEA_CSS_MARGINS
599
673
  int16_t margin[4];
600
-
601
- #if GEA_CSS_Z_INDEX
602
- int8_t position;
603
- int8_t z_index_auto;
604
674
  #else
605
- static constexpr int8_t z_index_auto = 1;
675
+ static constexpr int16_t margin[4] = {};
606
676
  #endif
677
+
607
678
  #if GEA_CSS_POSITION_PX_ALL
608
679
  int16_t pos_offsets[4];
609
680
  #else
@@ -660,14 +731,17 @@ struct ComputedStyle {
660
731
 
661
732
  // Group byte-sized paint flags before native colours. Keep natural alignment
662
733
  // without paying padding between each RGB565 colour and its flags.
663
- int8_t has_bg;
664
734
  uint8_t bg_alpha;
665
735
  #if GEA_EMBEDDED_RENDERER_LINEAR_GRADIENTS
666
736
  int8_t bg_fill;
667
737
  #else
668
738
  static constexpr int8_t bg_fill = 0;
669
739
  #endif
740
+ #if GEA_CSS_ACTIVE_BACKGROUND
670
741
  int8_t has_active_bg;
742
+ #else
743
+ static constexpr int8_t has_active_bg = 0;
744
+ #endif
671
745
  #if GEA_CSS_TEXT_ALPHA
672
746
  uint8_t text_alpha;
673
747
  #else
@@ -678,14 +752,16 @@ struct ComputedStyle {
678
752
  #else
679
753
  static constexpr uint8_t border_alpha = 255;
680
754
  #endif
681
- #if !GEA_CSS_Z_INDEX
682
- // Without the paired stacking flag, position fills the paint-byte group
683
- // instead of leaving a hole before the 16-bit offset array.
684
- int8_t position;
755
+ #if GEA_CSS_LINE_HEIGHT && GEA_CSS_U8_LINE_HEIGHT
756
+ uint8_t line_height;
685
757
  #endif
686
758
  style_color_t bg_color;
687
759
  // linear/overlay/radial gradients + background-grid moved to RareStyle (rare).
760
+ #if GEA_CSS_ACTIVE_BACKGROUND
688
761
  style_color_t active_bg_color;
762
+ #else
763
+ static constexpr style_color_t active_bg_color = 0;
764
+ #endif
689
765
  style_color_t text_color;
690
766
  #if GEA_CSS_OPACITY
691
767
  uint8_t opacity;
@@ -702,10 +778,14 @@ struct ComputedStyle {
702
778
  static constexpr uint8_t blink_visible = 1;
703
779
  #endif
704
780
 
705
- #if !GEA_CSS_U8_BORDER
781
+ #if GEA_CSS_BORDER_WIDTHS && !GEA_CSS_U8_BORDER
706
782
  int16_t border_width;
707
783
  #endif
784
+ #if GEA_CSS_BORDER_COLORS
708
785
  style_color_t border_color;
786
+ #else
787
+ static constexpr style_color_t border_color = gea::framework::graphics::pixel::nativeColor(255, 255, 255);
788
+ #endif
709
789
  // per-side border width/color/alpha moved to RareStyle (rare); border_radius
710
790
  // stays here (rounded rects are common).
711
791
  #if !GEA_CSS_U8_RADIUS
@@ -723,12 +803,17 @@ struct ComputedStyle {
723
803
  #if !GEA_CSS_U8_FONT
724
804
  int16_t font_size;
725
805
  #endif
806
+ #if GEA_CSS_FONT_WEIGHT
726
807
  int16_t font_weight;
727
- #if !GEA_CSS_U8_LINE_HEIGHT
808
+ #else
809
+ static constexpr int16_t font_weight = 400;
810
+ #endif
811
+ #if !GEA_CSS_LINE_HEIGHT
812
+ static constexpr int16_t line_height = 0;
813
+ #elif !GEA_CSS_U8_LINE_HEIGHT
728
814
  int16_t line_height;
729
815
  #endif
730
- int8_t text_align;
731
- int8_t overflow;
816
+
732
817
  #if GEA_CSS_OVERFLOW_AXES
733
818
  int8_t overflow_x;
734
819
  int8_t overflow_y;
@@ -775,38 +860,54 @@ struct ComputedStyle {
775
860
  #endif
776
861
  // CSS `white-space`: 0 normal, 1 nowrap, 2 pre, 3 pre-wrap, 4 pre-line,
777
862
  // 5 break-spaces. Inherited; space preservation and soft wrapping differ.
863
+ #if GEA_CSS_WHITE_SPACE
778
864
  int8_t white_space;
865
+ #else
866
+ static constexpr int8_t white_space = 0;
867
+ #endif
779
868
  // CSS `text-overflow` — 0 = clip (default), 1 = ellipsis. Only consulted
780
869
  // when the line cannot wrap (white-space: nowrap): an overflowing single
781
870
  // line is truncated at a glyph boundary and an ASCII "..." is appended so
782
871
  // the visible run fits within the content width. Not inherited.
872
+ #if GEA_CSS_TEXT_OVERFLOW
783
873
  int8_t text_overflow;
874
+ #else
875
+ static constexpr int8_t text_overflow = 0;
876
+ #endif
784
877
  // Compiler-proven unsigned ranges need one byte load, with no unpacking.
785
878
  // Group these bytes so narrowing does not merely create alignment holes.
786
- #if GEA_CSS_U8_BORDER_FLAGS
879
+ #if GEA_CSS_BORDER_COLORS && GEA_CSS_U8_BORDER_FLAGS
787
880
  uint8_t border_color_flags = 0;
881
+ #elif !GEA_CSS_BORDER_COLORS
882
+ static constexpr uint8_t border_color_flags = 0;
788
883
  #endif
789
- #if GEA_CSS_U8_GAP
884
+ #if GEA_CSS_GAP && GEA_CSS_U8_GAP
790
885
  uint8_t gap;
886
+ #elif !GEA_CSS_GAP
887
+ static constexpr int16_t gap = 0;
791
888
  #endif
792
- #if GEA_CSS_U8_FLEX
889
+ #if GEA_CSS_FLEX_FACTORS && GEA_CSS_U8_FLEX
793
890
  uint8_t flex, flex_shrink;
891
+ #elif !GEA_CSS_FLEX_FACTORS
892
+ static constexpr int16_t flex = 0, flex_shrink = 1;
794
893
  #endif
795
- #if GEA_CSS_U8_PADDING
894
+ #if GEA_CSS_PADDING && GEA_CSS_U8_PADDING
796
895
  uint8_t padding[4];
896
+ #elif !GEA_CSS_PADDING
897
+ static constexpr int16_t padding[4] = {};
797
898
  #endif
798
- #if GEA_CSS_U8_BORDER
899
+ #if GEA_CSS_BORDER_WIDTHS && GEA_CSS_U8_BORDER
799
900
  uint8_t border_width;
901
+ #elif !GEA_CSS_BORDER_WIDTHS
902
+ static constexpr int16_t border_width = 0;
800
903
  #endif
801
- #if GEA_CSS_U8_RADIUS
904
+ #if GEA_CSS_U8_RADIUS && (GEA_CSS_RADIUS_COUNT != 1 || GEA_CSS_TEXT_ALIGN)
802
905
  uint8_t border_radius[GEA_CSS_RADIUS_COUNT];
803
906
  #endif
804
907
  #if GEA_CSS_U8_FONT
805
908
  uint8_t font_size;
806
909
  #endif
807
- #if GEA_CSS_U8_LINE_HEIGHT
808
- uint8_t line_height;
809
- #endif
910
+
810
911
 
811
912
  // CSS `pointer-events` — 0 = auto (default), 1 = none. A `none` node is never
812
913
  // the target of a pointer event and its subtree is skipped in hit-testing, so
@@ -959,6 +1060,7 @@ inline int computedBorderWidth(const ComputedStyle &style, int side)
959
1060
 
960
1061
  inline bool setComputedBorderWidth(ComputedStyle &style, int side, int value, const ComputedStyle *parent)
961
1062
  {
1063
+ #if GEA_CSS_BORDER_WIDTHS
962
1064
  #if GEA_CSS_SIDE_BORDERS
963
1065
  int widths[4];
964
1066
  for (int i = 0; i < 4; ++i) {
@@ -992,10 +1094,15 @@ inline bool setComputedBorderWidth(ComputedStyle &style, int side, int value, co
992
1094
  style.border_width = width;
993
1095
  return true;
994
1096
  #endif
1097
+ #else
1098
+ (void)style; (void)side; (void)value; (void)parent;
1099
+ return false;
1100
+ #endif
995
1101
  }
996
1102
 
997
1103
  inline bool setBorderColorBinding(ComputedStyle &style, int side, bool current)
998
1104
  {
1105
+ #if GEA_CSS_BORDER_COLORS
999
1106
  #if GEA_CSS_SIDE_BORDERS
1000
1107
  const unsigned previous = style.border_color_flags;
1001
1108
  unsigned next;
@@ -1015,6 +1122,10 @@ inline bool setBorderColorBinding(ComputedStyle &style, int side, bool current)
1015
1122
  style.border_color_flags = static_cast<uint16_t>(next);
1016
1123
  return true;
1017
1124
  #endif
1125
+ #else
1126
+ (void)style; (void)side; (void)current;
1127
+ return false;
1128
+ #endif
1018
1129
  }
1019
1130
 
1020
1131
  inline bool borderColorIsCurrent(const ComputedStyle &style, int side = -1)
@@ -1225,6 +1336,10 @@ inline bool hasBorderRelief(const ComputedStyle &style)
1225
1336
  return r.border_relief[0] || r.border_relief[1] || r.border_relief[2] || r.border_relief[3];
1226
1337
  }
1227
1338
 
1339
+ #ifndef GEA_EMBEDDED_SHARED_STYLES
1340
+ #define GEA_EMBEDDED_SHARED_STYLES 0
1341
+ #endif
1342
+
1228
1343
  struct LayoutBox {
1229
1344
  int16_t x, y;
1230
1345
  int16_t width, height;
@@ -1240,7 +1355,9 @@ struct LayoutBox {
1240
1355
  // The hypothetical block-start margin edge of an out-of-flow child,
1241
1356
  // relative to its static-position parent. Capture before relative offsets
1242
1357
  // and absolute-coordinate conversion; retained refresh reuses this anchor.
1358
+ #if !GEA_EMBEDDED_SHARED_STYLES
1243
1359
  int16_t static_block_start = 0;
1360
+ #endif
1244
1361
 
1245
1362
  int16_t previous_x, previous_y;
1246
1363
  int16_t previous_width, previous_height;
@@ -1271,24 +1388,18 @@ struct LayoutBox {
1271
1388
  // node already laid out THIS pass with the same available box. Two slots
1272
1389
  // (MRU order) because flex items alternate between the parent's measure
1273
1390
  // avail and their basis/grown avail — a single slot thrashes on exactly
1274
- // that pattern. Scoped to a single pass (serial bumped by beginLayoutPass),
1275
- // so no cross-frame invalidation is needed and the final
1276
- // absolute-coordinate resolve is unaffected.
1277
- // 16-bit pass tags are direct loads, not packed fields. beginLayoutPass()
1278
- // clears every tag before reusing serial 1 after 65,535 passes.
1279
- // Both slots share result_w/h. An older entry can hit only when its result
1280
- // equals the current dimensions, so discard it on a dimension change instead
1281
- // of storing a second result that can never hit. External flex resizing still
1282
- // compares the shared result against live dimensions before either lookup.
1391
+ // that pattern. Both hit-validity bytes live in scratch cleared on every
1392
+ // beginLayoutPass(), so there is no generation counter or rollover scan.
1393
+ // Only the last available box and its validity survive the pass: scoped
1394
+ // relayout and absolute containing blocks need them across frames. The
1395
+ // legacy memo_pass field stores that validity (0 or 1), not a generation.
1396
+ // Result dimensions and the second available box remain pass-local.
1397
+ #if !GEA_EMBEDDED_SHARED_STYLES
1283
1398
  int16_t memo_avail_w;
1284
1399
  int16_t memo_avail_h;
1285
- int16_t memo_result_w;
1286
- int16_t memo_result_h;
1287
1400
  uint16_t memo_pass;
1288
- int16_t memo2_avail_w;
1289
- int16_t memo2_avail_h;
1290
- uint16_t memo2_pass;
1291
1401
  uint8_t static_block_axis = 0; // 0: unavailable, 1: y, 2: x
1402
+ #endif
1292
1403
  };
1293
1404
 
1294
1405
  struct RenderState {
@@ -1354,14 +1465,14 @@ struct RenderState {
1354
1465
  static constexpr int16_t previous_filter_blur_radius = 0;
1355
1466
  #endif
1356
1467
 
1357
- uint8_t dirty;
1468
+ uint8_t dirty : 1;
1358
1469
  #if GEA_CSS_SCROLLING
1359
- uint8_t scroll_dirty;
1470
+ uint8_t scroll_dirty : 1;
1360
1471
  #else
1361
1472
  static constexpr uint8_t scroll_dirty = 0;
1362
1473
  #endif
1363
1474
  #if GEA_CSS_SCROLLING
1364
- uint8_t non_scroll_dirty;
1475
+ uint8_t non_scroll_dirty : 1;
1365
1476
  #else
1366
1477
  static constexpr uint8_t non_scroll_dirty = 0;
1367
1478
  #endif
@@ -1371,20 +1482,20 @@ struct RenderState {
1371
1482
  // the refresh skip the relayout pass entirely and letting the scoped
1372
1483
  // relayout compute its LCA over geometry-relevant nodes only. Cleared with
1373
1484
  // `dirty`.
1374
- uint8_t layout_dirty;
1485
+ uint8_t layout_dirty : 1;
1375
1486
  #if GEA_CSS_TRANSFORMS
1376
- uint8_t transform_dirty;
1487
+ uint8_t transform_dirty : 1;
1377
1488
  #else
1378
1489
  static constexpr uint8_t transform_dirty = 0;
1379
1490
  #endif
1380
- uint8_t bg_recolor_pending;
1491
+ uint8_t bg_recolor_pending : 1;
1381
1492
  // Tree::setText pre-measures incoming text and sets this flag when the
1382
1493
  // update is safe for the retained/direct-replay path: absolute text may
1383
1494
  // update its measured bbox out of flow, while in-flow text must keep the
1384
1495
  // same layout box (e.g. fixed-width temperature readouts). Cleared on
1385
1496
  // LayoutSnapshot::capture() so it's always either freshly set by setText
1386
1497
  // in the current frame or absent.
1387
- uint8_t text_layout_stable;
1498
+ uint8_t text_layout_stable : 1;
1388
1499
  // Glyph-incremental text dirty (set by Tree::setText): when a content-only text
1389
1500
  // change keeps the same layout box and only a middle run of glyphs differs
1390
1501
  // (e.g. a ticking counter "58"->"57", a clock), the dirty collector flushes only
@@ -1392,14 +1503,14 @@ struct RenderState {
1392
1503
  // box. A 26vmin badge re-render then copies just the changed digits (~one glyph)
1393
1504
  // rather than ~the whole panel width, so it fits a TE-locked frame's slack.
1394
1505
  // Cleared with text_layout_stable each frame (LayoutSnapshot::capture).
1395
- uint8_t text_partial_dirty;
1506
+ uint8_t text_partial_dirty : 1;
1396
1507
  // This box SHARES a line box with other inline content, so it was placed on
1397
1508
  // that line's baseline (FlexLayoutPass::placeLineItems). TextRenderer::record
1398
1509
  // then draws the run at its baseline instead of centring the string's ink in
1399
1510
  // the line advance: ink centring shifts by however far that particular string's
1400
1511
  // glyphs reach, so runs of different words — or different fonts — on one line
1401
1512
  // end up at different heights. A run that owns its line keeps the centring.
1402
- uint8_t inline_baseline;
1513
+ uint8_t inline_baseline : 1;
1403
1514
  // Only one paint shortcut may own this scratch space. Mixed changes use
1404
1515
  // the ordinary dirty-region replay. The recolor destination is bg_color.
1405
1516
  union {
@@ -1414,10 +1525,52 @@ inline bool hadIndividualLinearTransform(const RenderState &s)
1414
1525
  s.previous_scale_x != 1000 || s.previous_scale_y != 1000 || s.previous_scale_z != 1000;
1415
1526
  }
1416
1527
 
1528
+ // A/B experiment only; the default keeps the existing native Node.style API.
1529
+ #if GEA_EMBEDDED_SHARED_STYLES
1530
+ struct SharedStyleRecord {
1531
+ ComputedStyle value;
1532
+ uint32_t references;
1533
+ SharedStyleRecord *next;
1534
+ };
1535
+ class NodeStyleStorage {
1536
+ SharedStyleRecord *record_;
1537
+ ComputedStyle &detach();
1538
+ public:
1539
+ NodeStyleStorage();
1540
+ ~NodeStyleStorage();
1541
+ NodeStyleStorage(const NodeStyleStorage &other);
1542
+ NodeStyleStorage &operator=(const NodeStyleStorage &other);
1543
+ NodeStyleStorage(NodeStyleStorage &&other) noexcept;
1544
+ NodeStyleStorage &operator=(NodeStyleStorage &&other) noexcept;
1545
+ const ComputedStyle &read() const { return record_->value; }
1546
+ ComputedStyle &write() {
1547
+ if (record_->references == 1) return record_->value;
1548
+ return detach();
1549
+ }
1550
+ void reset();
1551
+ void intern();
1552
+ static std::size_t allocatedBytes();
1553
+ static std::size_t allocatedRecords();
1554
+ static std::size_t allocatedHeapBytes();
1555
+ };
1556
+ #endif
1557
+
1417
1558
  struct Node {
1418
- // Keep the hot style at offset zero. Reuse only record tail padding;
1419
- // ordinary field reads remain naturally aligned direct loads.
1559
+ #if GEA_EMBEDDED_SHARED_STYLES
1560
+ NodeStyleStorage sharedStyle_;
1561
+ // Group the four-byte ownership handles before the two-byte fields.
1562
+ NodeText text;
1563
+ const ComputedStyle &computedStyle() const { return sharedStyle_.read(); }
1564
+ ComputedStyle &mutableStyle() { return sharedStyle_.write(); }
1565
+ void resetComputedStyle() { sharedStyle_.reset(); }
1566
+ void internComputedStyle() { sharedStyle_.intern(); }
1567
+ #else
1420
1568
  [[no_unique_address]] ComputedStyle style;
1569
+ const ComputedStyle &computedStyle() const { return style; }
1570
+ ComputedStyle &mutableStyle() { return style; }
1571
+ void resetComputedStyle();
1572
+ void internComputedStyle() {}
1573
+ #endif
1421
1574
  // Interned tag id; zero is the empty tag. Fits in style's tail padding
1422
1575
  // when the source proof removes the unused alpha fields.
1423
1576
  int16_t tag_id = 0;
@@ -1429,8 +1582,10 @@ struct Node {
1429
1582
  // Index into the shared pool for optional listeners/attributes/styles.
1430
1583
  // -1 means absent and is restored by Node{} / node reuse.
1431
1584
  int16_t rare_data = -1;
1585
+ #if !GEA_EMBEDDED_SHARED_STYLES
1432
1586
  // Empty structural nodes retain only the four-byte text ownership handle.
1433
1587
  NodeText text;
1588
+ #endif
1434
1589
  #if GEA_UI_IMAGE_NODES
1435
1590
  int16_t image_id;
1436
1591
  #else
@@ -1438,6 +1593,11 @@ struct Node {
1438
1593
  #endif
1439
1594
  [[no_unique_address]] LayoutBox layout;
1440
1595
  NodeType type;
1596
+ #if GEA_EMBEDDED_SHARED_STYLES && !GEA_CSS_CUSTOM_PROPERTIES
1597
+ // Occupies the alignment byte before RenderState, with direct field access.
1598
+ // No separate per-node dependency array is needed when variables are absent.
1599
+ bool class_style_tracked = false;
1600
+ #endif
1441
1601
  RenderState render;
1442
1602
  };
1443
1603
 
@@ -1445,7 +1605,7 @@ struct Node {
1445
1605
  // the positive display coordinate range and remain stationary during replay.
1446
1606
  inline void overflowClipBounds(const Node &node, int &x, int &y, int &w, int &h)
1447
1607
  {
1448
- const auto &s = node.style;
1608
+ const auto &s = node.computedStyle();
1449
1609
  const int left = boxInset(s, 3) - s.padding[3], right = boxInset(s, 1) - s.padding[1];
1450
1610
  const int top = boxInset(s, 0) - s.padding[0], bottom = boxInset(s, 2) - s.padding[2];
1451
1611
  x = overflowX(s) ? node.layout.x + left : 0;
package/ui/node_text.h CHANGED
@@ -1,5 +1,6 @@
1
1
  // SPDX-License-Identifier: Apache-2.0
2
2
  #pragma once
3
+ #include "storage_usage.h"
3
4
  #include <cstdint>
4
5
  #include <string>
5
6
 
@@ -31,6 +32,7 @@ class NodeText
31
32
  // Pool allocation payload (including spare slots/map), excluding string
32
33
  // character buffers and allocator metadata. Useful alongside heap census.
33
34
  static std::size_t storageBytes();
35
+ static StorageUsage storageUsage();
34
36
  void clear();
35
37
  void assign(const char *text);
36
38
  bool empty() const { return handle_ == kEmpty; }
package/ui/refresh_perf.h CHANGED
@@ -112,6 +112,11 @@ struct RefreshPerfStats {
112
112
  int treeScopedRejectNode = -1;
113
113
  int treeLayoutRepositionCalls = 0;
114
114
  std::int64_t treeLayoutTextUs = 0;
115
+ #if GEA_EMBEDDED_UI_REFRESH_PERF
116
+ // Deterministic work budgets for animation regressions; absent with perf off.
117
+ int treeIntegerPositionFastCalls = 0;
118
+ int treeTranslateClipChecks = 0;
119
+ #endif
115
120
  int treeSetStyleCalls = 0;
116
121
  int treeSetStyleChanged = 0;
117
122
  int treeSetStyleNoop = 0;
@@ -125,6 +130,8 @@ struct RefreshPerfStats {
125
130
  int treeMarkDisplayListDirtyCalls = 0;
126
131
  int treeMarkDisplayListContentDirtyCalls = 0;
127
132
  int treeMarkNodeCommandDirtyCalls = 0;
133
+ int treeAbsContainingAreaCalls = 0;
134
+ int treeAbsContainingAreaHits = 0;
128
135
  int treeAbsModeCalls = 0;
129
136
  int treeAbsModeFast = 0;
130
137
  int treeAbsModeFull = 0;
@@ -201,35 +208,30 @@ inline std::int64_t refreshPerfNowUs()
201
208
  #endif
202
209
  }
203
210
 
211
+ // Diagnostic writes must be compiled out, not redirected to a throwaway object:
212
+ // the latter still performs loads/stores in every style update and replay scan.
213
+ // A statement macro preserves surrounding if/else binding and does not evaluate
214
+ // its arguments when profiling is off.
215
+ #define GEA_REFRESH_PERF(...) \
216
+ do { if constexpr (GEA_EMBEDDED_UI_REFRESH_PERF) { __VA_ARGS__; } } while (false)
217
+
204
218
  inline RefreshPerfStats &refreshPerfStatsMutable()
205
219
  {
206
- #if GEA_EMBEDDED_UI_REFRESH_PERF
207
220
  return gRefreshPerfStats;
208
- #else
209
- // Perf off: the timer-derived `… += refreshPerfNowUs() - start` writes already
210
- // fold to `+= 0` (refreshPerfNowUs() returns 0), and the ScopedRefreshStat
211
- // guards optimize away. The few remaining bare counters in tree_render/render
212
- // (`treePanReplayCalls++`, `treePanRepaintArea += …`) are routed to a throwaway
213
- // that nothing reads, so they never touch live state.
214
- #if GEA_EMBEDDED_UI_STATE_DYNAMIC_INIT
215
- // On the heap, not static: the -1 sentinels make the throwaway a .data
216
- // object (see state_init.h).
217
- static RefreshPerfStats &discard = *new RefreshPerfStats();
218
- #else
219
- static RefreshPerfStats discard;
220
- #endif
221
- return discard;
222
- #endif
223
221
  }
224
222
 
225
223
  inline void refreshPerfStatsReset()
226
224
  {
227
- gRefreshPerfStats = {};
225
+ GEA_REFRESH_PERF(gRefreshPerfStats = {});
228
226
  }
229
227
 
230
228
  inline RefreshPerfStats refreshPerfStatsRead()
231
229
  {
230
+ #if GEA_EMBEDDED_UI_REFRESH_PERF
232
231
  return gRefreshPerfStats;
232
+ #else
233
+ return {};
234
+ #endif
233
235
  }
234
236
 
235
237
  } // namespace gea::embedded::ui