aboutsummaryrefslogtreecommitdiffhomepage
path: root/experimental
diff options
context:
space:
mode:
authorGravatar Florin Malita <fmalita@chromium.org>2018-01-08 10:15:12 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-01-08 15:44:29 +0000
commit95448a90c1e168f5d36abab40dc762b2602ba75a (patch)
tree30e9d96f04d2ae59985f397d881d2b2a99358756 /experimental
parent7c2192b33635d3e72bb455aeddeac71267ee63df (diff)
[skotty] More flexible property parsing
Older Json versions don't tag properties wih an "a" animation marker, but appear to instead rely on a try-and-see-what-sticks approach. TBR= Change-Id: I8a3a7e43576c590aa5ac168891574ceb4811ad49 Reviewed-on: https://skia-review.googlesource.com/91861 Reviewed-by: Florin Malita <fmalita@chromium.org> Commit-Queue: Florin Malita <fmalita@chromium.org>
Diffstat (limited to 'experimental')
-rw-r--r--experimental/skotty/Skotty.cpp34
1 files changed, 21 insertions, 13 deletions
diff --git a/experimental/skotty/Skotty.cpp b/experimental/skotty/Skotty.cpp
index 84cc08051f..b331547316 100644
--- a/experimental/skotty/Skotty.cpp
+++ b/experimental/skotty/Skotty.cpp
@@ -60,26 +60,34 @@ bool AttachProperty(const Json::Value& jprop, AttachContext* ctx, const sk_sp<No
if (!jprop.isObject())
return false;
- if (!ParseBool(jprop["a"], false)) {
- // Static property.
+ const auto& jpropA = jprop["a"];
+ const auto& jpropK = jprop["k"];
+
+ // Older Json versions don't have an "a" animation marker.
+ // For those, we attempt to parse both ways.
+ if (jpropA.isNull() || !ParseBool(jpropA, "false")) {
ValueT val;
- if (!ValueT::Parse(jprop["k"], &val)) {
- return LogFail(jprop, "Could not parse static property");
+ if (ValueT::Parse(jpropK, &val)) {
+ // Static property.
+ apply(node, val.template as<AttrT>());
+ return true;
}
- apply(node, val.template as<AttrT>());
- } else {
- // Keyframe property.
- using AnimatorT = Animator<ValueT, AttrT, NodeT>;
- auto animator = AnimatorT::Make(jprop["k"], node, std::move(apply));
-
- if (!animator) {
- return LogFail(jprop, "Could not instantiate keyframe animator");
+ if (!jpropA.isNull()) {
+ return LogFail(jprop, "Could not parse (explicit) static property");
}
+ }
+
+ // Keyframe property.
+ using AnimatorT = Animator<ValueT, AttrT, NodeT>;
+ auto animator = AnimatorT::Make(jpropK, node, std::move(apply));
- ctx->fAnimators.push_back(std::move(animator));
+ if (!animator) {
+ return LogFail(jprop, "Could not parse keyframed property");
}
+ ctx->fAnimators.push_back(std::move(animator));
+
return true;
}