[skottie] Preserve image aspect ratio
When the intrinsic image dimensions don't match the declared asset size,
use an aspect-preserving matrix for scaling.
Bug: skia:
TBR=
Change-Id: Ie361f464fdbc2c32cb898c9f97103521162b46a7
Reviewed-on: https://skia-review.googlesource.com/c/168274
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Florin Malita <fmalita@chromium.org>
Auto-Submit: Florin Malita <fmalita@chromium.org>
diff --git a/modules/skottie/src/SkottieLayer.cpp b/modules/skottie/src/SkottieLayer.cpp
index 98ea02c..2786ed5 100644
--- a/modules/skottie/src/SkottieLayer.cpp
+++ b/modules/skottie/src/SkottieLayer.cpp
@@ -373,8 +373,9 @@
}
return sksg::Transform::Make(std::move(image_node),
- SkMatrix::MakeScale(static_cast<float>(asset_size.width()) / image->width(),
- static_cast<float>(asset_size.height()) / image->height()));
+ SkMatrix::MakeRectToRect(SkRect::Make(image->bounds()),
+ SkRect::Make(asset_size),
+ SkMatrix::kCenter_ScaleToFit));
}
sk_sp<sksg::RenderNode> AnimationBuilder::attachImageLayer(const skjson::ObjectValue& jlayer,