From 3be2e10ce534a9bf8eb008d3704be26b2ba04437 Mon Sep 17 00:00:00 2001 From: Florin Malita Date: Tue, 10 Jul 2018 10:20:36 -0400 Subject: [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 Commit-Queue: Florin Malita --- modules/skottie/src/Skottie.cpp | 40 +++++++++++++++-------------------- modules/skottie/src/SkottieAnimator.h | 10 ++++++++- 2 files changed, 26 insertions(+), 24 deletions(-) (limited to 'modules') 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 AttachMatrix(const skjson::ObjectValue& t, AttachContext* ctx, sk_sp 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(matrix); - auto anchor_attached = BindProperty(t["a"], &ctx->fAnimators, + + auto bound = BindProperty(t["a"], &ctx->fAnimators, [adapter](const VectorValue& a) { adapter->setAnchorPoint(ValueTraits::As(a)); - }); - auto position_attached = BindProperty(t["p"], &ctx->fAnimators, + }, g_default_vec_0); + bound |= BindProperty(t["p"], &ctx->fAnimators, [adapter](const VectorValue& p) { adapter->setPosition(ValueTraits::As(p)); - }); - auto scale_attached = BindProperty(t["s"], &ctx->fAnimators, + }, g_default_vec_0); + bound |= BindProperty(t["s"], &ctx->fAnimators, [adapter](const VectorValue& s) { adapter->setScale(ValueTraits::As(s)); - }); + }, g_default_vec_100); const auto* jrotation = &t["r"]; if (jrotation->is()) { @@ -98,30 +102,20 @@ sk_sp AttachMatrix(const skjson::ObjectValue& t, AttachContext* ct // we can still make use of rz. jrotation = &t["rz"]; } - auto rotation_attached = BindProperty(*jrotation, &ctx->fAnimators, + bound |= BindProperty(*jrotation, &ctx->fAnimators, [adapter](const ScalarValue& r) { adapter->setRotation(r); - }); - auto skew_attached = BindProperty(t["sk"], &ctx->fAnimators, + }, 0.0f); + bound |= BindProperty(t["sk"], &ctx->fAnimators, [adapter](const ScalarValue& sk) { adapter->setSkew(sk); - }); - auto skewaxis_attached = BindProperty(t["sa"], &ctx->fAnimators, + }, 0.0f); + bound |= BindProperty(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 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 bool BindProperty(const skjson::Value&, sksg::AnimatorList*, std::function&&, - const T* noop = nullptr); + const T* default_igore = nullptr); + +template +bool BindProperty(const skjson::Value& jv, + sksg::AnimatorList* animators, + std::function&& apply, + const T& default_ignore) { + return BindProperty(jv, animators, std::move(apply), &default_ignore); +} } // namespace skottie -- cgit v1.2.3