@geastack/engine 0.1.14 → 0.1.16

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/engine.h CHANGED
@@ -46,6 +46,22 @@ public:
46
46
  {
47
47
  running_.eraseIf([&](const Running &r) { return r.handle == handle; });
48
48
  }
49
+ bool contains(int handle) const
50
+ {
51
+ for (std::size_t i = 0; i < running_.size(); ++i)
52
+ if (running_[i].handle == handle) return true;
53
+ return false;
54
+ }
55
+ void setPaused(int handle, bool paused, uint32_t nowMs)
56
+ {
57
+ for (std::size_t i = 0; i < running_.size(); ++i) {
58
+ Running &r = running_[i];
59
+ if (r.handle != handle || r.paused == paused) continue;
60
+ if (paused) r.pauseMs = nowMs;
61
+ else r.startMs += nowMs - r.pauseMs;
62
+ r.paused = paused;
63
+ }
64
+ }
49
65
  void cancelNode(int nodeId) // cancel all animations targeting a node
50
66
  {
51
67
  running_.eraseIf([&](const Running &r) { return r.anim.nodeId == nodeId; });
@@ -65,7 +81,7 @@ public:
65
81
  const Progress pr = computeProgress(first.anim, elapsed);
66
82
  std::size_t groupEnd = i + 1;
67
83
  while (groupEnd < running_.size() && sameTimeline(first, running_[groupEnd])) ++groupEnd;
68
- if (pr.active) {
84
+ if (pr.active && !first.paused) {
69
85
  for (std::size_t j = i; j < groupEnd; ++j) {
70
86
  const auto &a = running_[j].anim;
71
87
  if (!a.rotationAxes.empty())
@@ -75,7 +91,7 @@ public:
75
91
  else applyValue(a, sampleTrack(a, pr.p));
76
92
  }
77
93
  }
78
- if (pr.done)
94
+ if (pr.done && !first.paused)
79
95
  running_.erase(i, groupEnd);
80
96
  else
81
97
  i = groupEnd;
@@ -89,6 +105,8 @@ private:
89
105
  Animation anim;
90
106
  uint32_t startMs;
91
107
  int handle;
108
+ bool paused = false;
109
+ uint32_t pauseMs = 0;
92
110
  };
93
111
 
94
112
  class RunningList {
@@ -195,7 +213,7 @@ private:
195
213
 
196
214
  static bool sameTimeline(const Running &a, const Running &b)
197
215
  {
198
- return a.startMs == b.startMs && a.anim.durationMs == b.anim.durationMs &&
216
+ return a.paused == b.paused && a.startMs == b.startMs && a.anim.durationMs == b.anim.durationMs &&
199
217
  a.anim.delayMs == b.anim.delayMs && a.anim.iterations == b.anim.iterations &&
200
218
  a.anim.direction == b.anim.direction && a.anim.fill == b.anim.fill;
201
219
  }
@@ -237,6 +255,8 @@ public:
237
255
  static AnimationEngine &instance() { static AnimationEngine engine; return engine; }
238
256
  int start(Animation, uint32_t) = delete;
239
257
  void cancel(int) {}
258
+ bool contains(int) const { return false; }
259
+ void setPaused(int, bool, uint32_t) {}
240
260
  void cancelNode(int) {}
241
261
  void clear() {}
242
262
  bool active() const { return false; }
package/image_store.cpp CHANGED
@@ -781,6 +781,20 @@ bool ImageStore::isAnimated(int id) const { const ImageSlot *image = slot(id); r
781
781
  ImageFormat ImageStore::format(int id) const { const ImageSlot *image = slot(id); return image ? image->format : ImageFormat::Unknown; }
782
782
  bool ImageStore::playing(int id) const { const ImageSlot *image = slot(id); return image && image->playing; }
783
783
  int ImageStore::currentFrame(int id) const { const ImageSlot *image = slot(id); return image ? image->currentFrame : 0; }
784
+ bool ImageStore::pixelsMayChange(const pixel::native_t *pixels) const
785
+ {
786
+ if (!pixels) return false;
787
+ for (int i = 0; i < kImageMax; i++) {
788
+ // Anywhere inside the buffer: a dirty-rect putImageData draws rows that
789
+ // start part-way into it (CanvasRenderingContext2D::drawPixelRows).
790
+ const ImageSlot &image = images_[i];
791
+ if (!used_[i] || !image.mutablePixels || !image.pixels) continue;
792
+ const std::size_t count = static_cast<std::size_t>(image.width) * static_cast<std::size_t>(image.height);
793
+ if (pixels >= image.pixels && pixels < image.pixels + count) return true;
794
+ }
795
+ return false;
796
+ }
797
+
784
798
  const pixel::native_t *ImageStore::currentPixels(int id) const { materializeDeferred(id); const ImageSlot *image = slot(id); return image ? image->pixels : nullptr; }
785
799
  const std::uint8_t *ImageStore::currentAlpha(int id) const { materializeDeferred(id); const ImageSlot *image = slot(id); return image ? image->alpha : nullptr; }
786
800
 
@@ -855,10 +869,38 @@ bool ImageStore::rotate90(int id)
855
869
  return true;
856
870
  }
857
871
 
872
+ bool ImageStore::retain(int id)
873
+ {
874
+ if (id < 0 || id >= kImageMax) return false;
875
+ ImageStoreLock lock(slotMutex_);
876
+ if (!slot(id)) return false;
877
+ ++references_[id];
878
+ return true;
879
+ }
880
+
881
+ void ImageStore::release(int id)
882
+ {
883
+ if (id < 0 || id >= kImageMax) return;
884
+ ImageStoreLock lock(slotMutex_);
885
+ if (!slot(id) || references_[id] == 0) return;
886
+ if (--references_[id] == 0 && retired_[id]) disposeLocked(id);
887
+ }
888
+
889
+ int ImageStore::idForPixels(const pixel::native_t *pixels) const
890
+ {
891
+ if (!pixels) return -1;
892
+ ImageStoreLock lock(slotMutex_);
893
+ for (int id = 0; id < kImageMax; ++id)
894
+ if (used_[id] && images_[id].pixels == pixels) return id;
895
+ return -1;
896
+ }
897
+
858
898
  void ImageStore::dispose(int id)
859
899
  {
860
900
  ImageStoreLock lock(slotMutex_);
861
- disposeLocked(id);
901
+ if (!slot(id)) return;
902
+ retired_[id] = true;
903
+ if (references_[id] == 0) disposeLocked(id);
862
904
  }
863
905
 
864
906
  void ImageStore::disposeLocked(int id)
@@ -875,13 +917,18 @@ void ImageStore::disposeLocked(int id)
875
917
  ImageMemory::release(image->alpha);
876
918
  *image = ImageSlot{};
877
919
  used_[id] = false;
920
+ references_[id] = 0;
921
+ retired_[id] = false;
878
922
  }
879
923
 
880
924
  void ImageStore::disposeAll()
881
925
  {
882
926
  ImageStoreLock lock(slotMutex_);
883
927
  for (int i = 0; i < kImageMax; i++) {
884
- if (used_[i]) disposeLocked(i);
928
+ if (used_[i]) {
929
+ retired_[i] = true;
930
+ if (references_[i] == 0) disposeLocked(i);
931
+ }
885
932
  }
886
933
  }
887
934
 
@@ -901,6 +948,7 @@ int ImageStore::registerBuffer(pixel::native_t *pixels, int width, int height, i
901
948
  image.frameCount = 1;
902
949
  image.pixels = pixels;
903
950
  image.ownsPixels = takeOwnership;
951
+ image.mutablePixels = true;
904
952
  image.loopCount = 0;
905
953
  image.playing = false;
906
954
  used_[id] = true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@geastack/engine",
3
- "version": "0.1.14",
3
+ "version": "0.1.16",
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.38"
60
+ "@geastack/core": "^0.1.40"
61
61
  }
62
62
  }
@@ -64,6 +64,15 @@ public:
64
64
  for (int i = 0; i < font->glyphCount; i++) {
65
65
  if (font->glyphs[i].codepoint == codepoint) return &font->glyphs[i];
66
66
  }
67
+ if (font->strictGlyphLookup)
68
+ {
69
+ for (int i = 0; i < font->glyphCount; i++)
70
+ {
71
+ if (font->glyphs[i].codepoint == font->fallbackCodepoint)
72
+ return &font->glyphs[i];
73
+ }
74
+ return nullptr;
75
+ }
67
76
  if (font->glyphCount > 0 && codepoint != '?') {
68
77
  for (int i = 0; i < font->glyphCount; i++) {
69
78
  if (font->glyphs[i].codepoint == '?') return &font->glyphs[i];
@@ -352,7 +361,8 @@ void ensureRuntimeGlyphMetrics(const RasterizedFontData *data, int codepoint)
352
361
  slot->atlasRowHeight = std::max(slot->atlasRowHeight, glyph.height);
353
362
  slot->atlasCursorX += glyph.width + kRuntimeAtlasPadding;
354
363
  if (metricTraceCount <= 48) {
355
- runtimeTtfTrace("glyph.metrics.ready family=%d size=%d cp=%d adv=%d box=%dx%d bearing=%d,%d src=%d,%d",
364
+ runtimeTtfTrace("glyph.metrics.ready family=%d size=%d cp=%d adv=%d "
365
+ "box=%dx%d bearing=%d,%d src=%d,%d",
356
366
  slot->familyId,
357
367
  slot->data.sizePx,
358
368
  codepoint,
@@ -464,6 +474,35 @@ bool RasterizedFont::glyph(int codepoint, Glyph *out) const
464
474
  return true;
465
475
  }
466
476
 
477
+ int RasterizedFont::advance(int codepoint, int nextCodepoint) const
478
+ {
479
+ Glyph value{};
480
+ if (!glyph(codepoint, &value))
481
+ return data_ && data_->strictGlyphLookup ? 0 : sizePx() / 2;
482
+ if (value.advance16 < 0)
483
+ return value.advance;
484
+ int adjustment = 0;
485
+ int first = 0;
486
+ int last = data_->kerningCount;
487
+ while (first < last)
488
+ {
489
+ const int middle = first + (last - first) / 2;
490
+ const FontKerningPair &pair = data_->kerning[middle];
491
+ if (pair.left < codepoint ||
492
+ (pair.left == codepoint && pair.right < nextCodepoint))
493
+ first = middle + 1;
494
+ else
495
+ last = middle;
496
+ }
497
+ if (first < data_->kerningCount)
498
+ {
499
+ const FontKerningPair &pair = data_->kerning[first];
500
+ if (pair.left == codepoint && pair.right == nextCodepoint)
501
+ adjustment = pair.adjustment16;
502
+ }
503
+ return (value.advance16 + adjustment + 8) >> 4;
504
+ }
505
+
467
506
  std::uint8_t RasterizedFont::coverage(const Glyph &glyph, int row, int col) const
468
507
  {
469
508
  if (!data_ || !data_->atlas) return 0;
@@ -487,7 +526,8 @@ std::uint8_t RasterizedFont::coverage(const Glyph &glyph, int row, int col) cons
487
526
  if (data_->atlasBits == 2) {
488
527
  const int stride = (data_->atlasWidth + 3) >> 2;
489
528
  const int level = (data_->atlas[y * stride + (x >> 2)] >> ((3 - (x & 3)) * 2)) & 0x3;
490
- #if defined(GEA_EMBEDDED_FONT_COVERAGE_PAPERS3) && GEA_EMBEDDED_FONT_COVERAGE_PAPERS3
529
+ #if defined(GEA_EMBEDDED_FONT_COVERAGE_PAPERS3) && \
530
+ GEA_EMBEDDED_FONT_COVERAGE_PAPERS3
491
531
  static constexpr std::uint8_t kCoverage[4] = {0, 144, 176, 255};
492
532
  return kCoverage[level];
493
533
  #else