[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>
This commit is contained in:
Florin Malita 2018-07-10 10:20:36 -04:00 committed by Skia Commit-Bot
parent c100d48e42
commit 3be2e10ce5
2 changed files with 26 additions and 24 deletions

View File

@ -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);
});
}, 0.0f);
if (!anchor_attached &&
!position_attached &&
!scale_attached &&
!rotation_attached &&
!skew_attached &&
!skewaxis_attached) {
LogFail(t, "Could not parse transform");
return nullptr;
}
return matrix;
return bound ? matrix : nullptr;
}
sk_sp<sksg::RenderNode> AttachOpacity(const skjson::ObjectValue& jtransform, AttachContext* ctx,

View File

@ -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