@geastack/engine 0.1.11 → 0.1.13

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/css/easing.h CHANGED
@@ -149,6 +149,13 @@ public:
149
149
  return t;
150
150
  }
151
151
 
152
+ bool operator==(const Easing &other) const
153
+ {
154
+ return kind_ == other.kind_ && bx1_ == other.bx1_ && by1_ == other.by1_ &&
155
+ bx2_ == other.bx2_ && by2_ == other.by2_ && steps_ == other.steps_ &&
156
+ stepPosition_ == other.stepPosition_ && custom_ == other.custom_;
157
+ }
158
+
152
159
  private:
153
160
  EasingKind kind_ = EasingKind::Linear;
154
161
  double bx1_ = 0.0, by1_ = 0.0, bx2_ = 1.0, by2_ = 1.0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geastack/engine",
3
- "version": "0.1.11",
3
+ "version": "0.1.13",
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,6 @@
57
57
  },
58
58
  "sideEffects": false,
59
59
  "dependencies": {
60
- "@geastack/core": "^0.1.35"
60
+ "@geastack/core": "^0.1.36"
61
61
  }
62
62
  }
@@ -250,8 +250,12 @@ void AbsoluteLeafRefresh::refreshPositions()
250
250
  // new extent. Percent-sized nodes keep the already-resolved layout box;
251
251
  // the full layout pass owns recomputing them when their containing block
252
252
  // changes.
253
- if (n->computedStyle().width != kUnset) n->layout.width = n->computedStyle().width;
254
- if (n->computedStyle().height != kUnset) n->layout.height = n->computedStyle().height;
253
+ // The style size is the content box unless box-sizing says otherwise;
254
+ // layout stores the border box, as the full layout pass does.
255
+ if (n->computedStyle().width != kUnset)
256
+ n->layout.width = clampBorderBoxSize(n->computedStyle(), contentSizeToBorderSize(n->computedStyle(), n->computedStyle().width, true), true);
257
+ if (n->computedStyle().height != kUnset)
258
+ n->layout.height = clampBorderBoxSize(n->computedStyle(), contentSizeToBorderSize(n->computedStyle(), n->computedStyle().height, false), false);
255
259
  Node *p = &state.nodes[n->parent];
256
260
  // Absolute siblings share their parent's padding box. The cache lasts
257
261
  // only for this loop: visiting a different parent invalidates it before
package/ui/document.cpp CHANGED
@@ -4,6 +4,7 @@
4
4
  #include "internal.h"
5
5
 
6
6
  #include "display.h"
7
+ #include "display_underlay.h"
7
8
  #include "tree_internal.h"
8
9
 
9
10
  #include <algorithm>
@@ -365,3 +366,47 @@ void Document::addEventListener(const char *type, gea::framework::events::EventL
365
366
  }
366
367
 
367
368
  } // namespace gea::embedded::ui
369
+
370
+ namespace
371
+ {
372
+ gea::framework::display::Underlay::Paint underlayPaint = nullptr;
373
+ void *underlayUser = nullptr;
374
+ int underlayX0 = 0, underlayY0 = 0, underlayX1 = -1, underlayY1 = -1;
375
+ } // namespace
376
+
377
+ bool gea::framework::display::Underlay::composited()
378
+ {
379
+ return !gea::embedded::ui::Document::directCanvasContextUsed() && gea::embedded::ui::Tree::instance().mountedRoot() >= 0;
380
+ }
381
+
382
+ void gea::framework::display::Underlay::set(Paint paint, void *user, int x0, int y0, int x1, int y1)
383
+ {
384
+ underlayPaint = paint;
385
+ underlayUser = user;
386
+ underlayX0 = x0;
387
+ underlayY0 = y0;
388
+ underlayX1 = x1;
389
+ underlayY1 = y1;
390
+ }
391
+
392
+ void gea::framework::display::Underlay::clear()
393
+ {
394
+ underlayPaint = nullptr;
395
+ underlayUser = nullptr;
396
+ }
397
+
398
+ bool gea::framework::display::Underlay::active()
399
+ {
400
+ return underlayPaint != nullptr;
401
+ }
402
+
403
+ void gea::framework::display::Underlay::paint(int x0, int y0, int x1, int y1)
404
+ {
405
+ if (!underlayPaint) return;
406
+ x0 = std::max(x0, underlayX0);
407
+ y0 = std::max(y0, underlayY0);
408
+ x1 = std::min(x1, underlayX1);
409
+ y1 = std::min(y1, underlayY1);
410
+ if (x0 > x1 || y0 > y1) return;
411
+ underlayPaint(x0, y0, x1, y1, underlayUser);
412
+ }
package/ui/layout.cpp CHANGED
@@ -634,9 +634,16 @@ public:
634
634
  if (node_.computedStyle().display == kDisplayFlex) {
635
635
  applyFlexBasis(child);
636
636
  Node &item = Tree::instance().nodes()[child];
637
- const int floor = automaticMinimumMainSize(item);
638
- int16_t &main = isRow_ ? item.layout.width : item.layout.height;
639
- if (main < floor) { main = clampInt16(floor); engine_.repositionChildren(child); }
637
+ // A growing item with a zero flex basis (`flex: 1`) starts from zero; its
638
+ // automatic minimum floors the FINAL flexed size (growFlexChildren), not the
639
+ // basis. Flooring the basis hands content-bearing items a head start over their
640
+ // siblings and unbalances equal-flex rows (a tic-tac-toe cell holding "X" grew
641
+ // wider than its empty neighbours).
642
+ if (!zeroBasisGrowItem(item)) {
643
+ const int floor = automaticMinimumMainSize(item);
644
+ int16_t &main = isRow_ ? item.layout.width : item.layout.height;
645
+ if (main < floor) { main = clampInt16(floor); engine_.repositionChildren(child); }
646
+ }
640
647
  }
641
648
  }
642
649
  }
@@ -1320,7 +1327,11 @@ public:
1320
1327
  Node &childNode = nodes[child];
1321
1328
  if (childNode.computedStyle().flex <= 0) continue;
1322
1329
  const int mainSize = isRow_ ? childNode.layout.width : childNode.layout.height;
1323
- if (mainSize == 0) engine_.repositionChildren(child);
1330
+ if (mainSize == 0) {
1331
+ const int floor = automaticMinimumMainSize(childNode);
1332
+ if (floor > 0) (isRow_ ? childNode.layout.width : childNode.layout.height) = clampInt16(floor);
1333
+ engine_.repositionChildren(child);
1334
+ }
1324
1335
  }
1325
1336
  }
1326
1337
  bool hasRatio = false;
@@ -1525,6 +1536,13 @@ private:
1525
1536
  return -1;
1526
1537
  }
1527
1538
 
1539
+ // True when applyFlexBasis zeroed this item: it grows from nothing.
1540
+ bool zeroBasisGrowItem(const Node &childNode) const
1541
+ {
1542
+ if (hasFlexBasis(childNode) || childNode.computedStyle().flex <= 0) return false;
1543
+ return !(isRow_ ? hasExplicitWidth(childNode) : hasExplicitHeight(childNode));
1544
+ }
1545
+
1528
1546
  void applyFlexBasis(int child)
1529
1547
  {
1530
1548
  Node &childNode = Tree::instance().nodes()[child];
@@ -1718,6 +1736,10 @@ private:
1718
1736
  const int before = isRow_ ? childNode.layout.width : childNode.layout.height;
1719
1737
  int after = before + delta;
1720
1738
  after = clampFlexMainSize(childNode, after);
1739
+ if (delta > 0 && zeroBasisGrowItem(childNode)) {
1740
+ const int autoMin = automaticMinimumMainSize(childNode);
1741
+ if (after < autoMin) after = autoMin;
1742
+ }
1721
1743
  if (delta < 0) {
1722
1744
  // Floor the shrink at the automatic minimum size, and never let that floor
1723
1745
  // GROW an item that was already smaller than its content.
package/ui/render.cpp CHANGED
@@ -5647,11 +5647,11 @@ int gLastScrollUiFrame = -1000;
5647
5647
  #ifndef GEA_EMBEDDED_GRADIENT_LUT_SLOTS
5648
5648
  #define GEA_EMBEDDED_GRADIENT_LUT_SLOTS 1
5649
5649
  #endif
5650
- // GEA_EMBEDDED_LAZY_GRADIENT_LUTS=1 allocates the dither tables on first use
5651
- // instead of as static arrays: the slots above plus the radial table below
5652
- // otherwise sit in .bss whether or not the app ever draws a gradient.
5650
+ // Allocate dither tables on first use by default. An app that never draws a
5651
+ // gradient must not reserve these ~20 KB in internal RAM. The slot count still
5652
+ // controls caching when gradients are actually used.
5653
5653
  #ifndef GEA_EMBEDDED_LAZY_GRADIENT_LUTS
5654
- #define GEA_EMBEDDED_LAZY_GRADIENT_LUTS 0
5654
+ #define GEA_EMBEDDED_LAZY_GRADIENT_LUTS 1
5655
5655
  #endif
5656
5656
  #if GEA_EMBEDDED_RENDERER_LINEAR_GRADIENTS
5657
5657
  struct LutSlot
package/ui/style.cpp CHANGED
@@ -16356,6 +16356,43 @@ struct CssAnimationSpec {
16356
16356
  bool valid = false;
16357
16357
  };
16358
16358
 
16359
+ struct NodeCssAnimation {
16360
+ int node;
16361
+ CssAnimationSpec spec;
16362
+ std::uint32_t startMs = 0;
16363
+ bool started = false;
16364
+ std::vector<int> handles;
16365
+ };
16366
+
16367
+ // Only nodes with animation declarations occupy storage. Style recomputation
16368
+ // enrolls new nodes; the frame clock starts pending tracks once, without a
16369
+ // full-tree scan or restarting existing timelines on unrelated renders.
16370
+ std::vector<NodeCssAnimation> &nodeCssAnimations()
16371
+ {
16372
+ static std::vector<NodeCssAnimation> animations;
16373
+ return animations;
16374
+ }
16375
+
16376
+ std::uint32_t g_cssAnimationNowMs = 0;
16377
+
16378
+ bool sameAnimationSpec(const CssAnimationSpec &a, const CssAnimationSpec &b)
16379
+ {
16380
+ return a.nameAtom == b.nameAtom && a.durationMs == b.durationMs &&
16381
+ a.delayMs == b.delayMs && a.iterations == b.iterations &&
16382
+ a.direction == b.direction && a.fill == b.fill && a.easing == b.easing;
16383
+ }
16384
+
16385
+ void cancelNodeCssAnimation(int node)
16386
+ {
16387
+ auto &animations = nodeCssAnimations();
16388
+ for (auto it = animations.begin(); it != animations.end(); ++it) {
16389
+ if (it->node != node) continue;
16390
+ for (int handle : it->handles) gea::css::AnimationEngine::instance().cancel(handle);
16391
+ animations.erase(it);
16392
+ return;
16393
+ }
16394
+ }
16395
+
16359
16396
  CssAnimationSpec parseAnimationShorthand(const std::string &value)
16360
16397
  {
16361
16398
  CssAnimationSpec spec;
@@ -17062,20 +17099,32 @@ void applyPrimedAnimationValue(const gea::css::Animation &animation, double valu
17062
17099
 
17063
17100
  void primeCssAnimationsForNode(int node, const ActiveRulePlan *activePlan)
17064
17101
  {
17065
- if (activePlan) {
17066
- if (!activePlan->has(kActiveAnimation)) return;
17067
- } else {
17068
- rebuildRuleIndexIfNeeded();
17069
- if (g_ruleIndex.animationRules.empty()) return;
17070
- }
17071
17102
  const CssAnimationSpec spec = activePlan ? animationSpecForNodeFromActivePlan(*activePlan) : animationSpecForNode(node);
17103
+ if (!spec.valid || isDisplayNone(treeState().nodes[node].computedStyle())) {
17104
+ cancelNodeCssAnimation(node);
17105
+ return;
17106
+ }
17107
+ auto &animations = nodeCssAnimations();
17108
+ auto it = std::find_if(animations.begin(), animations.end(), [&](const NodeCssAnimation &entry) {
17109
+ return entry.node == node;
17110
+ });
17111
+ if (it != animations.end() && !sameAnimationSpec(it->spec, spec)) {
17112
+ cancelNodeCssAnimation(node);
17113
+ it = animations.end();
17114
+ }
17115
+ if (it == animations.end()) {
17116
+ animations.push_back({node, spec});
17117
+ it = animations.end() - 1;
17118
+ }
17119
+ const double elapsed = it->started
17120
+ ? static_cast<double>(static_cast<std::int32_t>(g_cssAnimationNowMs - it->startMs)) : 0.0;
17072
17121
  CssAnimationTrackList tracks;
17073
17122
  buildAnimationTracksForNode(node, spec, tracks);
17074
17123
  for (std::size_t i = 0, n = tracks.size(); i < n; ++i) {
17075
17124
  const CssAnimationTrack &track = tracks.at(i);
17076
17125
  if (isRotationAxisTrack(track.property)) continue;
17077
17126
  const gea::css::Animation animation = animationFromTrack(node, spec, track, tracks);
17078
- const gea::css::Progress progress = gea::css::computeProgress(animation, 0.0);
17127
+ const gea::css::Progress progress = gea::css::computeProgress(animation, elapsed);
17079
17128
  if (!progress.active) continue;
17080
17129
  if (!animation.rotationAxes.empty())
17081
17130
  gea::css::applyRotationSample(animation, progress.p, [&](Property property, int value) {
@@ -17085,15 +17134,17 @@ void primeCssAnimationsForNode(int node, const ActiveRulePlan *activePlan)
17085
17134
  }
17086
17135
  }
17087
17136
 
17088
- void startAnimationForNode(int nodeId, const CssAnimationSpec &spec, std::uint32_t nowMs)
17137
+ void startAnimationForNode(NodeCssAnimation &entry, std::uint32_t nowMs)
17089
17138
  {
17090
17139
  CssAnimationTrackList tracks;
17091
- buildAnimationTracksForNode(nodeId, spec, tracks);
17140
+ buildAnimationTracksForNode(entry.node, entry.spec, tracks);
17141
+ entry.startMs = nowMs;
17142
+ entry.started = true;
17092
17143
  for (std::size_t i = 0, n = tracks.size(); i < n; ++i) {
17093
17144
  const CssAnimationTrack &track = tracks.at(i);
17094
17145
  if (isRotationAxisTrack(track.property)) continue;
17095
- gea::css::Animation animation = animationFromTrack(nodeId, spec, track, tracks);
17096
- gea::css::AnimationEngine::instance().start(std::move(animation), nowMs);
17146
+ gea::css::Animation animation = animationFromTrack(entry.node, entry.spec, track, tracks);
17147
+ entry.handles.push_back(gea::css::AnimationEngine::instance().start(std::move(animation), nowMs));
17097
17148
  }
17098
17149
  }
17099
17150
 
@@ -17346,11 +17397,23 @@ void Style::cssScale(double value) const
17346
17397
  set(Property::ScaleX, scale); set(Property::ScaleY, scale); set(Property::ScaleZ, 1000);
17347
17398
  }
17348
17399
 
17400
+ void forgetNodeCssAnimations(int node)
17401
+ {
17402
+ #if GEA_CSS_ANIMATIONS
17403
+ cancelNodeCssAnimation(node);
17404
+ gea::css::AnimationEngine::instance().cancelNode(node);
17405
+ #else
17406
+ (void)node;
17407
+ #endif
17408
+ }
17409
+
17349
17410
  void StyleSheet::clear()
17350
17411
  {
17351
17412
  rules().clear();
17352
17413
  #if GEA_CSS_ANIMATIONS
17353
17414
  keyframeRules().clear();
17415
+ nodeCssAnimations().clear();
17416
+ g_cssAnimationNowMs = 0;
17354
17417
  #endif
17355
17418
  g_ruleRegistrationBatchDepth = 0;
17356
17419
  g_ruleRegistrationRulesChanged = false;
@@ -18024,13 +18087,9 @@ void StyleSheet::recomputeSubtree(int nodeId) const
18024
18087
  void StyleSheet::startCssAnimations(std::uint32_t nowMs) const
18025
18088
  {
18026
18089
  #if GEA_CSS_ANIMATIONS
18027
- rebuildRuleIndexIfNeeded();
18028
- if (g_ruleIndex.animationRules.empty()) return;
18029
- auto &state = treeState();
18030
- for (int node = 0; node < state.nodeCount; ++node) {
18031
- if (isDisplayNone(state.nodes[node].computedStyle())) continue;
18032
- const CssAnimationSpec spec = animationSpecForNode(node);
18033
- startAnimationForNode(node, spec, nowMs);
18090
+ g_cssAnimationNowMs = nowMs;
18091
+ for (auto &entry : nodeCssAnimations()) {
18092
+ if (!entry.started) startAnimationForNode(entry, nowMs);
18034
18093
  }
18035
18094
  #else
18036
18095
  (void)nowMs;
package/ui/style.h CHANGED
@@ -862,4 +862,7 @@ void applyAnimatedStyleValue(int nodeId, Property property, int value);
862
862
  void setSafeAreaInsetBottom(int inset);
863
863
  int safeAreaInsetBottom();
864
864
 
865
+ // Drop animation timelines before a node slot can be reused.
866
+ void forgetNodeCssAnimations(int node);
867
+
865
868
  } // namespace gea::embedded::ui
package/ui/tree_nodes.cpp CHANGED
@@ -98,6 +98,7 @@ bool canUseDisplayFramebuffer(TreeState &state, int id, int width, int height)
98
98
  void resetNodeSlot(TreeState &state, int id)
99
99
  {
100
100
  if (id < 0 || id >= kMaxNodes) return;
101
+ forgetNodeCssAnimations(id);
101
102
  // The node's text buffer dies with the slot; retained display commands hold
102
103
  // a raw pointer into it (see DisplayList::scrubNodeText) — neutralize them
103
104
  // before NodeLifecycle::init frees the string, or a stale-list replay in the
@@ -152,6 +153,7 @@ void Tree::clear()
152
153
  state.refreshSerial++;
153
154
  if (state.refreshSerial == 0) state.refreshSerial = 1;
154
155
  for (int i = 0; i < state.nodeCount; i++) {
156
+ forgetNodeCssAnimations(i);
155
157
  releaseRareData(i); // frees the rare-data block: attributes, listeners, custom props, styles, virtual-list
156
158
  state.classLists[i].clear();
157
159
  }
@@ -2,6 +2,7 @@
2
2
  #include "absolute_leaf_refresh.h"
3
3
  #include "dirty_regions.h"
4
4
  #include "display.h"
5
+ #include "display_underlay.h"
5
6
  #include "document.h"
6
7
  #include "internal.h"
7
8
  #include "layout_snapshot.h"
@@ -1675,6 +1676,7 @@ namespace gea::embedded::ui
1675
1676
  DisplayList::instance().clear();
1676
1677
  DisplayList::instance().recordNode(root, 255);
1677
1678
  DisplayList::instance().weldTransformedFaces();
1679
+ gea::framework::display::Underlay::paint(0, 0, width - 1, height - 1);
1678
1680
  DisplayList::instance().replay();
1679
1681
  state.displayListDirty = false;
1680
1682
  state.displayListRebuildStructural = false; // this path already repainted everything
@@ -3058,6 +3060,7 @@ namespace gea::embedded::ui
3058
3060
  gea::platform::display::Display::resetClip();
3059
3061
  gea::platform::display::Display::setAlpha(255);
3060
3062
  gea::platform::display::Display::pushClip(r->x0, r->y0, r->x1 - r->x0 + 1, r->y1 - r->y0 + 1);
3063
+ gea::framework::display::Underlay::paint(r->x0, r->y0, r->x1, r->y1);
3061
3064
  DisplayList::instance().replay();
3062
3065
  gea::platform::display::Display::popClip();
3063
3066
  }