[canvaskit] Expand SkAnimatedImage
With these things exposed, I think Flutter will not need
CanvasKit to expose the very complex SkCodec API.
Change-Id: Iace1b496d1dcb8842181466e860e8f212aba7b48
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/253542
Reviewed-by: Leon Scroggins <scroggo@google.com>
diff --git a/RELEASE_NOTES.txt b/RELEASE_NOTES.txt
index 0a6a2f8..3387988 100644
--- a/RELEASE_NOTES.txt
+++ b/RELEASE_NOTES.txt
@@ -8,6 +8,9 @@
<Insert new notes here- top is most recent.>
+ * Added dimensions() and getFrameCount() to SkAnimatedImage
+ https://review.skia.org/253542
+
* Removed SkMatrix44 version of toXYZD50 from SkColorSpace. Switched to skcms types in
transferFn, invTrasnferFn, and gamutTransformTo functions.
https://review.skia.org/252596
diff --git a/include/android/SkAnimatedImage.h b/include/android/SkAnimatedImage.h
index 760dabd..a3907a6 100644
--- a/include/android/SkAnimatedImage.h
+++ b/include/android/SkAnimatedImage.h
@@ -110,6 +110,16 @@
return fRepetitionCount;
}
+ /**
+ * Return the total number of frames in the animation.
+ */
+ int getFrameCount() const { return fFrameCount; }
+
+ /**
+ * Return the (possibly scaled) dimensions of the image.
+ */
+ SkISize dimensions() const { return fScaledSize; }
+
protected:
SkRect onGetBounds() override;
void onDraw(SkCanvas*) override;
diff --git a/modules/canvaskit/CHANGELOG.md b/modules/canvaskit/CHANGELOG.md
index 6cc8bd2..0ccc2e1 100644
--- a/modules/canvaskit/CHANGELOG.md
+++ b/modules/canvaskit/CHANGELOG.md
@@ -14,6 +14,7 @@
- `SkCanvas.saveLayer` now takes 3 or 4 params to include up to bounds, paint, SkImageFilter, flags.
- `SkPath.rArcTo`, `SkPath.rConicTo`, `SkPath.rCubicTo`, `SkPath.rLineTo`, `SkPath.rMoveTo`,
`SkPath.rQuadTo`. Like their non-relative siblings, these are chainable.
+ - Add `width()`, `height()`, `reset()`, `getFrameCount()` to SkAnimatedImage.
### Deprecated
- `CanvasKit.MakeBlurMaskFilter` will be renamed/moved soon to `CanvasKit.SkMaskFilter.MakeBlur`.
diff --git a/modules/canvaskit/canvaskit_bindings.cpp b/modules/canvaskit/canvaskit_bindings.cpp
index 6462f7f..25b374e 100644
--- a/modules/canvaskit/canvaskit_bindings.cpp
+++ b/modules/canvaskit/canvaskit_bindings.cpp
@@ -847,14 +847,22 @@
class_<SkAnimatedImage>("SkAnimatedImage")
.smart_ptr<sk_sp<SkAnimatedImage>>("sk_sp<SkAnimatedImage>")
+ .function("decodeNextFrame", &SkAnimatedImage::decodeNextFrame)
+ .function("getFrameCount", &SkAnimatedImage::getFrameCount)
.function("getRepetitionCount", &SkAnimatedImage::getRepetitionCount)
- .function("decodeNextFrame", &SkAnimatedImage::decodeNextFrame);
+ .function("height", optional_override([](SkAnimatedImage& self)->int32_t {
+ return self.dimensions().height();
+ }))
+ .function("reset", &SkAnimatedImage::reset)
+ .function("width", optional_override([](SkAnimatedImage& self)->int32_t {
+ return self.dimensions().width();
+ }));
class_<SkCanvas>("SkCanvas")
.constructor<>()
.function("clear", &SkCanvas::clear)
.function("clipPath", select_overload<void (const SkPath&, SkClipOp, bool)>(&SkCanvas::clipPath))
- .function("clipRRect",optional_override([](SkCanvas& self, const SimpleRRect& r, SkClipOp op, bool doAntiAlias) {
+ .function("clipRRect", optional_override([](SkCanvas& self, const SimpleRRect& r, SkClipOp op, bool doAntiAlias) {
self.clipRRect(toRRect(r), op, doAntiAlias);
}))
.function("clipRect", select_overload<void (const SkRect&, SkClipOp, bool)>(&SkCanvas::clipRect))
diff --git a/modules/canvaskit/externs.js b/modules/canvaskit/externs.js
index a878635..c51278e 100644
--- a/modules/canvaskit/externs.js
+++ b/modules/canvaskit/externs.js
@@ -120,8 +120,12 @@
SkAnimatedImage: {
// public API (from C++ bindings)
- getRepetitionCount: function() {},
decodeNextFrame: function() {},
+ getFrameCount: function() {},
+ getRepetitionCount: function() {},
+ height: function() {},
+ reset: function() {},
+ width: function() {},
},
SkCanvas: {
diff --git a/modules/canvaskit/tests/core.spec.js b/modules/canvaskit/tests/core.spec.js
index 8b9161f..7147c43 100644
--- a/modules/canvaskit/tests/core.spec.js
+++ b/modules/canvaskit/tests/core.spec.js
@@ -157,6 +157,9 @@
let aImg = CanvasKit.MakeAnimatedImageFromEncoded(gifData);
expect(aImg).toBeTruthy();
expect(aImg.getRepetitionCount()).toEqual(-1); // infinite loop
+ expect(aImg.width()).toEqual(320);
+ expect(aImg.height()).toEqual(240);
+ expect(aImg.getFrameCount()).toEqual(60);
const surface = CanvasKit.MakeCanvasSurface('test');
expect(surface).toBeTruthy('Could not make surface')