aboutsummaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorFlorin Malita <fmalita@chromium.org>2018-09-10 11:25:35 -0400
committerSkia Commit-Bot <skia-commit-bot@chromium.org>2018-09-10 15:44:42 +0000
commita61f0f73dcc504fac52a556a5745ea9dd8624fb8 (patch)
treea89df2bf7839d6af5c54390fb616cfe0ec48c7bc /modules
parent57d2beabc714e1ca0d01125e456c81297f9eb4eb (diff)
downloadskqp-a61f0f73dcc504fac52a556a5745ea9dd8624fb8.tar.gz
[skottie] Add support for explicit image asset sizing
TBR= Change-Id: Ie1c8a30ebc6a7c647265f05fe39b39b53758f016 Reviewed-on: https://skia-review.googlesource.com/153004 Reviewed-by: Florin Malita <fmalita@chromium.org> Commit-Queue: Florin Malita <fmalita@chromium.org>
Diffstat (limited to 'modules')
-rw-r--r--modules/skottie/src/SkottieLayer.cpp18
1 files changed, 16 insertions, 2 deletions
diff --git a/modules/skottie/src/SkottieLayer.cpp b/modules/skottie/src/SkottieLayer.cpp
index b3a88ea41c..b01acbac55 100644
--- a/modules/skottie/src/SkottieLayer.cpp
+++ b/modules/skottie/src/SkottieLayer.cpp
@@ -311,8 +311,22 @@ sk_sp<sksg::RenderNode> AnimationBuilder::attachImageAsset(const skjson::ObjectV
return nullptr;
}
- // TODO: non-intrisic image sizing
- return *fAssetCache.set(res_id, sksg::Image::Make(SkImage::MakeFromEncoded(data)));
+ auto image = SkImage::MakeFromEncoded(data);
+ if (!image) {
+ return nullptr;
+ }
+
+ const auto width = ParseDefault<int>(jimage["w"], image->width()),
+ height = ParseDefault<int>(jimage["h"], image->height());
+
+ sk_sp<sksg::RenderNode> image_node = sksg::Image::Make(image);
+ if (width != image->width() || height != image->height()) {
+ image_node = sksg::Transform::Make(std::move(image_node),
+ SkMatrix::MakeScale(static_cast<float>(width) / image->width(),
+ static_cast<float>(height) / image->height()));
+ }
+
+ return *fAssetCache.set(res_id, std::move(image_node));
}
sk_sp<sksg::RenderNode> AnimationBuilder::attachImageLayer(const skjson::ObjectValue& jlayer,