[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>
This commit is contained in:
Kevin Lubick 2019-11-08 06:55:15 -08:00
parent f6a9d20e95
commit 47bd9f1b73
6 changed files with 32 additions and 3 deletions

View File

@ -8,6 +8,9 @@ Milestone 80
<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

View File

@ -110,6 +110,16 @@ public:
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;

View File

@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `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`.

View File

@ -847,14 +847,22 @@ EMSCRIPTEN_BINDINGS(Skia) {
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))

View File

@ -120,8 +120,12 @@ var CanvasKit = {
SkAnimatedImage: {
// public API (from C++ bindings)
getRepetitionCount: function() {},
decodeNextFrame: function() {},
getFrameCount: function() {},
getRepetitionCount: function() {},
height: function() {},
reset: function() {},
width: function() {},
},
SkCanvas: {

View File

@ -157,6 +157,9 @@ describe('Core canvas behavior', function() {
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')