aboutsummaryrefslogtreecommitdiffhomepage
path: root/modules
diff options
context:
space:
mode:
authorGravatar Florin Malita <fmalita@chromium.org>2018-07-10 10:20:36 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-07-10 15:07:04 +0000
commit3be2e10ce534a9bf8eb008d3704be26b2ba04437 (patch)
tree57a362b83d922631f3f0b04637235bcf6bd57e89 /modules
parentc100d48e4241ecc7be0fd7fd79eae13e13f255c0 (diff)
[skottie] Ignore identity transforms
Some tranform properties are not optional, but many of them are static identity. Detect these cases and don't attach SG nodes for them. Reduces the number of sksg::Matrix nodes by ~18%. TBR= Change-Id: Ia51c865d6928e8c48c73b30f6d45541caf334880 Reviewed-on: https://skia-review.googlesource.com/140186 Reviewed-by: Florin Malita <fmalita@chromium.org> Commit-Queue: Florin Malita <fmalita@chromium.org>
Diffstat (limited to 'modules')
-rw-r--r--modules/skottie/src/Skottie.cpp40
-rw-r--r--modules/skottie/src/SkottieAnimator.h10
2 files changed, 26 insertions, 24 deletions
diff --git a/modules/skottie/src/Skottie.cpp b/modules/skottie/src/Skottie.cpp
index 60009b9bc0..e59ace86ac 100644
--- a/modules/skottie/src/Skottie.cpp
+++ b/modules/skottie/src/Skottie.cpp
@@ -77,20 +77,24 @@ bool LogFail(const skjson::Value& json, const char* msg) {
sk_sp<sksg::Matrix> AttachMatrix(const skjson::ObjectValue& t, AttachContext* ctx,
sk_sp<sksg::Matrix> parentMatrix) {
+ static const VectorValue g_default_vec_0 = { 0, 0},
+ g_default_vec_100 = {100, 100};
+
auto matrix = sksg::Matrix::Make(SkMatrix::I(), std::move(parentMatrix));
auto adapter = sk_make_sp<TransformAdapter>(matrix);
- auto anchor_attached = BindProperty<VectorValue>(t["a"], &ctx->fAnimators,
+
+ auto bound = BindProperty<VectorValue>(t["a"], &ctx->fAnimators,
[adapter](const VectorValue& a) {
adapter->setAnchorPoint(ValueTraits<VectorValue>::As<SkPoint>(a));
- });
- auto position_attached = BindProperty<VectorValue>(t["p"], &ctx->fAnimators,
+ }, g_default_vec_0);
+ bound |= BindProperty<VectorValue>(t["p"], &ctx->fAnimators,
[adapter](const VectorValue& p) {
adapter->setPosition(ValueTraits<VectorValue>::As<SkPoint>(p));
- });
- auto scale_attached = BindProperty<VectorValue>(t["s"], &ctx->fAnimators,
+ }, g_default_vec_0);
+ bound |= BindProperty<VectorValue>(t["s"], &ctx->fAnimators,
[adapter](const VectorValue& s) {
adapter->setScale(ValueTraits<VectorValue>::As<SkVector>(s));
- });
+ }, g_default_vec_100);
const auto* jrotation = &t["r"];
if (jrotation->is<skjson::NullValue>()) {
@@ -98,30 +102,20 @@ sk_sp<sksg::Matrix> AttachMatrix(const skjson::ObjectValue& t, AttachContext* ct
// we can still make use of rz.
jrotation = &t["rz"];
}
- auto rotation_attached = BindProperty<ScalarValue>(*jrotation, &ctx->fAnimators,
+ bound |= BindProperty<ScalarValue>(*jrotation, &ctx->fAnimators,
[adapter](const ScalarValue& r) {
adapter->setRotation(r);
- });
- auto skew_attached = BindProperty<ScalarValue>(t["sk"], &ctx->fAnimators,
+ }, 0.0f);
+ bound |= BindProperty<ScalarValue>(t["sk"], &ctx->fAnimators,
[adapter](const ScalarValue& sk) {
adapter->setSkew(sk);
- });
- auto skewaxis_attached = BindProperty<ScalarValue>(t["sa"], &ctx->fAnimators,
+ }, 0.0f);
+ bound |= BindProperty<ScalarValue>(t["sa"], &ctx->fAnimators,
[adapter](const ScalarValue& sa) {
adapter->setSkewAxis(sa);
- });
-
- if (!anchor_attached &&
- !position_attached &&
- !scale_attached &&
- !rotation_attached &&
- !skew_attached &&
- !skewaxis_attached) {
- LogFail(t, "Could not parse transform");
- return nullptr;
- }
+ }, 0.0f);
- return matrix;
+ return bound ? matrix : nullptr;
}
sk_sp<sksg::RenderNode> AttachOpacity(const skjson::ObjectValue& jtransform, AttachContext* ctx,
diff --git a/modules/skottie/src/SkottieAnimator.h b/modules/skottie/src/SkottieAnimator.h
index c4464e3138..23bd9aa500 100644
--- a/modules/skottie/src/SkottieAnimator.h
+++ b/modules/skottie/src/SkottieAnimator.h
@@ -22,7 +22,15 @@ template <typename T>
bool BindProperty(const skjson::Value&,
sksg::AnimatorList*,
std::function<void(const T&)>&&,
- const T* noop = nullptr);
+ const T* default_igore = nullptr);
+
+template <typename T>
+bool BindProperty(const skjson::Value& jv,
+ sksg::AnimatorList* animators,
+ std::function<void(const T&)>&& apply,
+ const T& default_ignore) {
+ return BindProperty(jv, animators, std::move(apply), &default_ignore);
+}
} // namespace skottie