Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
Florin Malita | 54f65c4 | 2018-01-16 17:04:30 -0500 | [diff] [blame] | 8 | #include "Skottie.h" |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 9 | |
| 10 | #include "SkCanvas.h" |
Florin Malita | 54f65c4 | 2018-01-16 17:04:30 -0500 | [diff] [blame] | 11 | #include "SkottieAnimator.h" |
| 12 | #include "SkottiePriv.h" |
| 13 | #include "SkottieProperties.h" |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 14 | #include "SkData.h" |
Florin Malita | 4932807 | 2018-01-08 12:51:12 -0500 | [diff] [blame] | 15 | #include "SkImage.h" |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 16 | #include "SkMakeUnique.h" |
Florin Malita | 4932807 | 2018-01-08 12:51:12 -0500 | [diff] [blame] | 17 | #include "SkOSPath.h" |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 18 | #include "SkPaint.h" |
Florin Malita | 0e66fba | 2018-01-09 17:10:18 -0500 | [diff] [blame] | 19 | #include "SkParse.h" |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 20 | #include "SkPath.h" |
| 21 | #include "SkPoint.h" |
| 22 | #include "SkSGColor.h" |
| 23 | #include "SkSGDraw.h" |
Florin Malita | 6aaee59 | 2018-01-12 12:25:09 -0500 | [diff] [blame] | 24 | #include "SkSGGradient.h" |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 25 | #include "SkSGGroup.h" |
Florin Malita | 4932807 | 2018-01-08 12:51:12 -0500 | [diff] [blame] | 26 | #include "SkSGImage.h" |
| 27 | #include "SkSGInvalidationController.h" |
Florin Malita | 5f9102f | 2018-01-10 13:36:22 -0500 | [diff] [blame] | 28 | #include "SkSGMaskEffect.h" |
Florin Malita | e6345d9 | 2018-01-03 23:37:54 -0500 | [diff] [blame] | 29 | #include "SkSGMerge.h" |
Florin Malita | c003417 | 2018-01-08 16:42:59 -0500 | [diff] [blame] | 30 | #include "SkSGOpacityEffect.h" |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 31 | #include "SkSGPath.h" |
Florin Malita | 2e1d7e2 | 2018-01-02 10:40:00 -0500 | [diff] [blame] | 32 | #include "SkSGRect.h" |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 33 | #include "SkSGTransform.h" |
Florin Malita | 51b8c89 | 2018-01-07 08:54:24 -0500 | [diff] [blame] | 34 | #include "SkSGTrimEffect.h" |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 35 | #include "SkStream.h" |
| 36 | #include "SkTArray.h" |
| 37 | #include "SkTHash.h" |
| 38 | |
| 39 | #include <cmath> |
Florin Malita | 18eafd9 | 2018-01-04 21:11:55 -0500 | [diff] [blame] | 40 | #include <unordered_map> |
Florin Malita | e6345d9 | 2018-01-03 23:37:54 -0500 | [diff] [blame] | 41 | #include <vector> |
| 42 | |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 43 | #include "stdlib.h" |
| 44 | |
Florin Malita | 54f65c4 | 2018-01-16 17:04:30 -0500 | [diff] [blame] | 45 | namespace skottie { |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 46 | |
| 47 | namespace { |
| 48 | |
| 49 | using AssetMap = SkTHashMap<SkString, const Json::Value*>; |
| 50 | |
| 51 | struct AttachContext { |
Florin Malita | 4932807 | 2018-01-08 12:51:12 -0500 | [diff] [blame] | 52 | const ResourceProvider& fResources; |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 53 | const AssetMap& fAssets; |
| 54 | SkTArray<std::unique_ptr<AnimatorBase>>& fAnimators; |
| 55 | }; |
| 56 | |
| 57 | bool LogFail(const Json::Value& json, const char* msg) { |
| 58 | const auto dump = json.toStyledString(); |
| 59 | LOG("!! %s: %s", msg, dump.c_str()); |
| 60 | return false; |
| 61 | } |
| 62 | |
| 63 | // This is the workhorse for binding properties: depending on whether the property is animated, |
| 64 | // it will either apply immediately or instantiate and attach a keyframe animator. |
Florin Malita | f959092 | 2018-01-09 11:56:09 -0500 | [diff] [blame] | 65 | template <typename ValT, typename NodeT> |
| 66 | bool BindProperty(const Json::Value& jprop, AttachContext* ctx, const sk_sp<NodeT>& node, |
| 67 | typename Animator<ValT, NodeT>::ApplyFuncT&& apply) { |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 68 | if (!jprop.isObject()) |
| 69 | return false; |
| 70 | |
Florin Malita | 95448a9 | 2018-01-08 10:15:12 -0500 | [diff] [blame] | 71 | const auto& jpropA = jprop["a"]; |
| 72 | const auto& jpropK = jprop["k"]; |
| 73 | |
| 74 | // Older Json versions don't have an "a" animation marker. |
| 75 | // For those, we attempt to parse both ways. |
| 76 | if (jpropA.isNull() || !ParseBool(jpropA, "false")) { |
Florin Malita | f959092 | 2018-01-09 11:56:09 -0500 | [diff] [blame] | 77 | ValT val; |
| 78 | if (ValueTraits<ValT>::Parse(jpropK, &val)) { |
Florin Malita | 95448a9 | 2018-01-08 10:15:12 -0500 | [diff] [blame] | 79 | // Static property. |
Florin Malita | f959092 | 2018-01-09 11:56:09 -0500 | [diff] [blame] | 80 | apply(node.get(), val); |
Florin Malita | 95448a9 | 2018-01-08 10:15:12 -0500 | [diff] [blame] | 81 | return true; |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 82 | } |
| 83 | |
Florin Malita | 95448a9 | 2018-01-08 10:15:12 -0500 | [diff] [blame] | 84 | if (!jpropA.isNull()) { |
| 85 | return LogFail(jprop, "Could not parse (explicit) static property"); |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 86 | } |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 87 | } |
| 88 | |
Florin Malita | 95448a9 | 2018-01-08 10:15:12 -0500 | [diff] [blame] | 89 | // Keyframe property. |
Florin Malita | f959092 | 2018-01-09 11:56:09 -0500 | [diff] [blame] | 90 | using AnimatorT = Animator<ValT, NodeT>; |
| 91 | auto animator = AnimatorT::Make(ParseFrames<ValT>(jpropK), node, std::move(apply)); |
Florin Malita | 95448a9 | 2018-01-08 10:15:12 -0500 | [diff] [blame] | 92 | |
| 93 | if (!animator) { |
| 94 | return LogFail(jprop, "Could not parse keyframed property"); |
| 95 | } |
| 96 | |
| 97 | ctx->fAnimators.push_back(std::move(animator)); |
| 98 | |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 99 | return true; |
| 100 | } |
| 101 | |
Florin Malita | 18eafd9 | 2018-01-04 21:11:55 -0500 | [diff] [blame] | 102 | sk_sp<sksg::Matrix> AttachMatrix(const Json::Value& t, AttachContext* ctx, |
| 103 | sk_sp<sksg::Matrix> parentMatrix) { |
| 104 | if (!t.isObject()) |
| 105 | return nullptr; |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 106 | |
Florin Malita | 18eafd9 | 2018-01-04 21:11:55 -0500 | [diff] [blame] | 107 | auto matrix = sksg::Matrix::Make(SkMatrix::I(), std::move(parentMatrix)); |
| 108 | auto composite = sk_make_sp<CompositeTransform>(matrix); |
Florin Malita | f959092 | 2018-01-09 11:56:09 -0500 | [diff] [blame] | 109 | auto anchor_attached = BindProperty<VectorValue>(t["a"], ctx, composite, |
| 110 | [](CompositeTransform* node, const VectorValue& a) { |
| 111 | node->setAnchorPoint(ValueTraits<VectorValue>::As<SkPoint>(a)); |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 112 | }); |
Florin Malita | f959092 | 2018-01-09 11:56:09 -0500 | [diff] [blame] | 113 | auto position_attached = BindProperty<VectorValue>(t["p"], ctx, composite, |
| 114 | [](CompositeTransform* node, const VectorValue& p) { |
| 115 | node->setPosition(ValueTraits<VectorValue>::As<SkPoint>(p)); |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 116 | }); |
Florin Malita | f959092 | 2018-01-09 11:56:09 -0500 | [diff] [blame] | 117 | auto scale_attached = BindProperty<VectorValue>(t["s"], ctx, composite, |
| 118 | [](CompositeTransform* node, const VectorValue& s) { |
| 119 | node->setScale(ValueTraits<VectorValue>::As<SkVector>(s)); |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 120 | }); |
Florin Malita | f959092 | 2018-01-09 11:56:09 -0500 | [diff] [blame] | 121 | auto rotation_attached = BindProperty<ScalarValue>(t["r"], ctx, composite, |
| 122 | [](CompositeTransform* node, const ScalarValue& r) { |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 123 | node->setRotation(r); |
| 124 | }); |
Florin Malita | f959092 | 2018-01-09 11:56:09 -0500 | [diff] [blame] | 125 | auto skew_attached = BindProperty<ScalarValue>(t["sk"], ctx, composite, |
| 126 | [](CompositeTransform* node, const ScalarValue& sk) { |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 127 | node->setSkew(sk); |
| 128 | }); |
Florin Malita | f959092 | 2018-01-09 11:56:09 -0500 | [diff] [blame] | 129 | auto skewaxis_attached = BindProperty<ScalarValue>(t["sa"], ctx, composite, |
| 130 | [](CompositeTransform* node, const ScalarValue& sa) { |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 131 | node->setSkewAxis(sa); |
| 132 | }); |
| 133 | |
| 134 | if (!anchor_attached && |
| 135 | !position_attached && |
| 136 | !scale_attached && |
| 137 | !rotation_attached && |
| 138 | !skew_attached && |
| 139 | !skewaxis_attached) { |
| 140 | LogFail(t, "Could not parse transform"); |
Florin Malita | 18eafd9 | 2018-01-04 21:11:55 -0500 | [diff] [blame] | 141 | return nullptr; |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 142 | } |
| 143 | |
Florin Malita | 18eafd9 | 2018-01-04 21:11:55 -0500 | [diff] [blame] | 144 | return matrix; |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 145 | } |
| 146 | |
Florin Malita | c003417 | 2018-01-08 16:42:59 -0500 | [diff] [blame] | 147 | sk_sp<sksg::RenderNode> AttachOpacity(const Json::Value& jtransform, AttachContext* ctx, |
| 148 | sk_sp<sksg::RenderNode> childNode) { |
| 149 | if (!jtransform.isObject() || !childNode) |
| 150 | return childNode; |
| 151 | |
| 152 | // This is more peeky than other attachers, because we want to avoid redundant opacity |
| 153 | // nodes for the extremely common case of static opaciy == 100. |
| 154 | const auto& opacity = jtransform["o"]; |
| 155 | if (opacity.isObject() && |
| 156 | !ParseBool(opacity["a"], true) && |
| 157 | ParseScalar(opacity["k"], -1) == 100) { |
| 158 | // Ignoring static full opacity. |
| 159 | return childNode; |
| 160 | } |
| 161 | |
| 162 | auto opacityNode = sksg::OpacityEffect::Make(childNode); |
Florin Malita | f959092 | 2018-01-09 11:56:09 -0500 | [diff] [blame] | 163 | BindProperty<ScalarValue>(opacity, ctx, opacityNode, |
| 164 | [](sksg::OpacityEffect* node, const ScalarValue& o) { |
Florin Malita | c003417 | 2018-01-08 16:42:59 -0500 | [diff] [blame] | 165 | // BM opacity is [0..100] |
| 166 | node->setOpacity(o * 0.01f); |
| 167 | }); |
| 168 | |
| 169 | return opacityNode; |
| 170 | } |
| 171 | |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 172 | sk_sp<sksg::RenderNode> AttachShape(const Json::Value&, AttachContext* ctx); |
| 173 | sk_sp<sksg::RenderNode> AttachComposition(const Json::Value&, AttachContext* ctx); |
| 174 | |
| 175 | sk_sp<sksg::RenderNode> AttachShapeGroup(const Json::Value& jgroup, AttachContext* ctx) { |
| 176 | SkASSERT(jgroup.isObject()); |
| 177 | |
| 178 | return AttachShape(jgroup["it"], ctx); |
| 179 | } |
| 180 | |
| 181 | sk_sp<sksg::GeometryNode> AttachPathGeometry(const Json::Value& jpath, AttachContext* ctx) { |
| 182 | SkASSERT(jpath.isObject()); |
| 183 | |
| 184 | auto path_node = sksg::Path::Make(); |
Florin Malita | f959092 | 2018-01-09 11:56:09 -0500 | [diff] [blame] | 185 | auto path_attached = BindProperty<ShapeValue>(jpath["ks"], ctx, path_node, |
| 186 | [](sksg::Path* node, const ShapeValue& p) { node->setPath(p); }); |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 187 | |
| 188 | if (path_attached) |
| 189 | LOG("** Attached path geometry - verbs: %d\n", path_node->getPath().countVerbs()); |
| 190 | |
| 191 | return path_attached ? path_node : nullptr; |
| 192 | } |
| 193 | |
Florin Malita | 2e1d7e2 | 2018-01-02 10:40:00 -0500 | [diff] [blame] | 194 | sk_sp<sksg::GeometryNode> AttachRRectGeometry(const Json::Value& jrect, AttachContext* ctx) { |
| 195 | SkASSERT(jrect.isObject()); |
| 196 | |
| 197 | auto rect_node = sksg::RRect::Make(); |
| 198 | auto composite = sk_make_sp<CompositeRRect>(rect_node); |
| 199 | |
Florin Malita | f959092 | 2018-01-09 11:56:09 -0500 | [diff] [blame] | 200 | auto p_attached = BindProperty<VectorValue>(jrect["p"], ctx, composite, |
| 201 | [](CompositeRRect* node, const VectorValue& p) { |
| 202 | node->setPosition(ValueTraits<VectorValue>::As<SkPoint>(p)); |
| 203 | }); |
| 204 | auto s_attached = BindProperty<VectorValue>(jrect["s"], ctx, composite, |
| 205 | [](CompositeRRect* node, const VectorValue& s) { |
| 206 | node->setSize(ValueTraits<VectorValue>::As<SkSize>(s)); |
| 207 | }); |
| 208 | auto r_attached = BindProperty<ScalarValue>(jrect["r"], ctx, composite, |
| 209 | [](CompositeRRect* node, const ScalarValue& r) { |
| 210 | node->setRadius(SkSize::Make(r, r)); |
| 211 | }); |
Florin Malita | 2e1d7e2 | 2018-01-02 10:40:00 -0500 | [diff] [blame] | 212 | |
| 213 | if (!p_attached && !s_attached && !r_attached) { |
| 214 | return nullptr; |
| 215 | } |
| 216 | |
Florin Malita | fbc13f1 | 2018-01-04 10:26:35 -0500 | [diff] [blame] | 217 | LOG("** Attached (r)rect geometry\n"); |
| 218 | |
| 219 | return rect_node; |
| 220 | } |
| 221 | |
| 222 | sk_sp<sksg::GeometryNode> AttachEllipseGeometry(const Json::Value& jellipse, AttachContext* ctx) { |
| 223 | SkASSERT(jellipse.isObject()); |
| 224 | |
| 225 | auto rect_node = sksg::RRect::Make(); |
| 226 | auto composite = sk_make_sp<CompositeRRect>(rect_node); |
| 227 | |
Florin Malita | f959092 | 2018-01-09 11:56:09 -0500 | [diff] [blame] | 228 | auto p_attached = BindProperty<VectorValue>(jellipse["p"], ctx, composite, |
| 229 | [](CompositeRRect* node, const VectorValue& p) { |
| 230 | node->setPosition(ValueTraits<VectorValue>::As<SkPoint>(p)); |
| 231 | }); |
| 232 | auto s_attached = BindProperty<VectorValue>(jellipse["s"], ctx, composite, |
| 233 | [](CompositeRRect* node, const VectorValue& s) { |
| 234 | const auto sz = ValueTraits<VectorValue>::As<SkSize>(s); |
| 235 | node->setSize(sz); |
| 236 | node->setRadius(SkSize::Make(sz.width() / 2, sz.height() / 2)); |
| 237 | }); |
Florin Malita | fbc13f1 | 2018-01-04 10:26:35 -0500 | [diff] [blame] | 238 | |
| 239 | if (!p_attached && !s_attached) { |
| 240 | return nullptr; |
| 241 | } |
| 242 | |
| 243 | LOG("** Attached ellipse geometry\n"); |
| 244 | |
Florin Malita | 2e1d7e2 | 2018-01-02 10:40:00 -0500 | [diff] [blame] | 245 | return rect_node; |
| 246 | } |
| 247 | |
Florin Malita | 02a32b0 | 2018-01-04 11:27:09 -0500 | [diff] [blame] | 248 | sk_sp<sksg::GeometryNode> AttachPolystarGeometry(const Json::Value& jstar, AttachContext* ctx) { |
| 249 | SkASSERT(jstar.isObject()); |
| 250 | |
| 251 | static constexpr CompositePolyStar::Type gTypes[] = { |
| 252 | CompositePolyStar::Type::kStar, // "sy": 1 |
| 253 | CompositePolyStar::Type::kPoly, // "sy": 2 |
| 254 | }; |
| 255 | |
| 256 | const auto type = ParseInt(jstar["sy"], 0) - 1; |
| 257 | if (type < 0 || type >= SkTo<int>(SK_ARRAY_COUNT(gTypes))) { |
| 258 | LogFail(jstar, "Unknown polystar type"); |
| 259 | return nullptr; |
| 260 | } |
| 261 | |
| 262 | auto path_node = sksg::Path::Make(); |
| 263 | auto composite = sk_make_sp<CompositePolyStar>(path_node, gTypes[type]); |
| 264 | |
Florin Malita | f959092 | 2018-01-09 11:56:09 -0500 | [diff] [blame] | 265 | BindProperty<VectorValue>(jstar["p"], ctx, composite, |
| 266 | [](CompositePolyStar* node, const VectorValue& p) { |
| 267 | node->setPosition(ValueTraits<VectorValue>::As<SkPoint>(p)); |
| 268 | }); |
| 269 | BindProperty<ScalarValue>(jstar["pt"], ctx, composite, |
| 270 | [](CompositePolyStar* node, const ScalarValue& pt) { |
| 271 | node->setPointCount(pt); |
| 272 | }); |
| 273 | BindProperty<ScalarValue>(jstar["ir"], ctx, composite, |
| 274 | [](CompositePolyStar* node, const ScalarValue& ir) { |
| 275 | node->setInnerRadius(ir); |
| 276 | }); |
| 277 | BindProperty<ScalarValue>(jstar["or"], ctx, composite, |
| 278 | [](CompositePolyStar* node, const ScalarValue& otr) { |
Florin Malita | 9661b98 | 2018-01-06 14:25:49 -0500 | [diff] [blame] | 279 | node->setOuterRadius(otr); |
| 280 | }); |
Florin Malita | f959092 | 2018-01-09 11:56:09 -0500 | [diff] [blame] | 281 | BindProperty<ScalarValue>(jstar["is"], ctx, composite, |
| 282 | [](CompositePolyStar* node, const ScalarValue& is) { |
Florin Malita | 9661b98 | 2018-01-06 14:25:49 -0500 | [diff] [blame] | 283 | node->setInnerRoundness(is); |
| 284 | }); |
Florin Malita | f959092 | 2018-01-09 11:56:09 -0500 | [diff] [blame] | 285 | BindProperty<ScalarValue>(jstar["os"], ctx, composite, |
| 286 | [](CompositePolyStar* node, const ScalarValue& os) { |
Florin Malita | 9661b98 | 2018-01-06 14:25:49 -0500 | [diff] [blame] | 287 | node->setOuterRoundness(os); |
| 288 | }); |
Florin Malita | f959092 | 2018-01-09 11:56:09 -0500 | [diff] [blame] | 289 | BindProperty<ScalarValue>(jstar["r"], ctx, composite, |
| 290 | [](CompositePolyStar* node, const ScalarValue& r) { |
| 291 | node->setRotation(r); |
| 292 | }); |
Florin Malita | 02a32b0 | 2018-01-04 11:27:09 -0500 | [diff] [blame] | 293 | |
| 294 | return path_node; |
| 295 | } |
| 296 | |
Florin Malita | 6aaee59 | 2018-01-12 12:25:09 -0500 | [diff] [blame] | 297 | sk_sp<sksg::Color> AttachColor(const Json::Value& obj, AttachContext* ctx) { |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 298 | SkASSERT(obj.isObject()); |
| 299 | |
| 300 | auto color_node = sksg::Color::Make(SK_ColorBLACK); |
Florin Malita | 1586d85 | 2018-01-12 14:27:39 -0500 | [diff] [blame] | 301 | auto color_attached = BindProperty<VectorValue>(obj["c"], ctx, color_node, |
| 302 | [](sksg::Color* node, const VectorValue& c) { |
Florin Malita | f959092 | 2018-01-09 11:56:09 -0500 | [diff] [blame] | 303 | node->setColor(ValueTraits<VectorValue>::As<SkColor>(c)); |
| 304 | }); |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 305 | |
Florin Malita | 1586d85 | 2018-01-12 14:27:39 -0500 | [diff] [blame] | 306 | return color_attached ? color_node : nullptr; |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 307 | } |
| 308 | |
Florin Malita | 6aaee59 | 2018-01-12 12:25:09 -0500 | [diff] [blame] | 309 | sk_sp<sksg::Gradient> AttachGradient(const Json::Value& obj, AttachContext* ctx) { |
| 310 | SkASSERT(obj.isObject()); |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 311 | |
Florin Malita | 6aaee59 | 2018-01-12 12:25:09 -0500 | [diff] [blame] | 312 | const auto& stops = obj["g"]; |
| 313 | if (!stops.isObject()) |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 314 | return nullptr; |
| 315 | |
Florin Malita | 6aaee59 | 2018-01-12 12:25:09 -0500 | [diff] [blame] | 316 | const auto stopCount = ParseInt(stops["p"], -1); |
| 317 | if (stopCount < 0) |
| 318 | return nullptr; |
| 319 | |
| 320 | sk_sp<sksg::Gradient> gradient_node; |
| 321 | sk_sp<CompositeGradient> composite; |
| 322 | |
| 323 | if (ParseInt(obj["t"], 1) == 1) { |
| 324 | auto linear_node = sksg::LinearGradient::Make(); |
| 325 | composite = sk_make_sp<CompositeLinearGradient>(linear_node, stopCount); |
| 326 | gradient_node = std::move(linear_node); |
| 327 | } else { |
| 328 | auto radial_node = sksg::RadialGradient::Make(); |
| 329 | composite = sk_make_sp<CompositeRadialGradient>(radial_node, stopCount); |
| 330 | |
| 331 | // TODO: highlight, angle |
| 332 | gradient_node = std::move(radial_node); |
| 333 | } |
| 334 | |
| 335 | BindProperty<VectorValue>(stops["k"], ctx, composite, |
| 336 | [](CompositeGradient* node, const VectorValue& stops) { |
| 337 | node->setColorStops(stops); |
| 338 | }); |
| 339 | BindProperty<VectorValue>(obj["s"], ctx, composite, |
| 340 | [](CompositeGradient* node, const VectorValue& s) { |
| 341 | node->setStartPoint(ValueTraits<VectorValue>::As<SkPoint>(s)); |
| 342 | }); |
| 343 | BindProperty<VectorValue>(obj["e"], ctx, composite, |
| 344 | [](CompositeGradient* node, const VectorValue& e) { |
| 345 | node->setEndPoint(ValueTraits<VectorValue>::As<SkPoint>(e)); |
| 346 | }); |
| 347 | |
| 348 | return gradient_node; |
| 349 | } |
| 350 | |
Florin Malita | 1586d85 | 2018-01-12 14:27:39 -0500 | [diff] [blame] | 351 | sk_sp<sksg::PaintNode> AttachPaint(const Json::Value& jpaint, AttachContext* ctx, |
Florin Malita | 6aaee59 | 2018-01-12 12:25:09 -0500 | [diff] [blame] | 352 | sk_sp<sksg::PaintNode> paint_node) { |
| 353 | if (paint_node) { |
| 354 | paint_node->setAntiAlias(true); |
| 355 | |
Florin Malita | 1586d85 | 2018-01-12 14:27:39 -0500 | [diff] [blame] | 356 | BindProperty<ScalarValue>(jpaint["o"], ctx, paint_node, |
| 357 | [](sksg::PaintNode* node, const ScalarValue& o) { |
| 358 | // BM opacity is [0..100] |
| 359 | node->setOpacity(o * 0.01f); |
| 360 | }); |
Florin Malita | 6aaee59 | 2018-01-12 12:25:09 -0500 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | return paint_node; |
| 364 | } |
| 365 | |
| 366 | sk_sp<sksg::PaintNode> AttachStroke(const Json::Value& jstroke, AttachContext* ctx, |
| 367 | sk_sp<sksg::PaintNode> stroke_node) { |
| 368 | SkASSERT(jstroke.isObject()); |
| 369 | |
| 370 | if (!stroke_node) |
| 371 | return nullptr; |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 372 | |
| 373 | stroke_node->setStyle(SkPaint::kStroke_Style); |
| 374 | |
Florin Malita | f959092 | 2018-01-09 11:56:09 -0500 | [diff] [blame] | 375 | auto width_attached = BindProperty<ScalarValue>(jstroke["w"], ctx, stroke_node, |
Florin Malita | 6aaee59 | 2018-01-12 12:25:09 -0500 | [diff] [blame] | 376 | [](sksg::PaintNode* node, const ScalarValue& w) { |
Florin Malita | f959092 | 2018-01-09 11:56:09 -0500 | [diff] [blame] | 377 | node->setStrokeWidth(w); |
| 378 | }); |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 379 | if (!width_attached) |
| 380 | return nullptr; |
| 381 | |
| 382 | stroke_node->setStrokeMiter(ParseScalar(jstroke["ml"], 4)); |
| 383 | |
| 384 | static constexpr SkPaint::Join gJoins[] = { |
| 385 | SkPaint::kMiter_Join, |
| 386 | SkPaint::kRound_Join, |
| 387 | SkPaint::kBevel_Join, |
| 388 | }; |
| 389 | stroke_node->setStrokeJoin(gJoins[SkTPin<int>(ParseInt(jstroke["lj"], 1) - 1, |
| 390 | 0, SK_ARRAY_COUNT(gJoins) - 1)]); |
| 391 | |
| 392 | static constexpr SkPaint::Cap gCaps[] = { |
| 393 | SkPaint::kButt_Cap, |
| 394 | SkPaint::kRound_Cap, |
| 395 | SkPaint::kSquare_Cap, |
| 396 | }; |
| 397 | stroke_node->setStrokeCap(gCaps[SkTPin<int>(ParseInt(jstroke["lc"], 1) - 1, |
| 398 | 0, SK_ARRAY_COUNT(gCaps) - 1)]); |
| 399 | |
| 400 | return stroke_node; |
| 401 | } |
| 402 | |
Florin Malita | 6aaee59 | 2018-01-12 12:25:09 -0500 | [diff] [blame] | 403 | sk_sp<sksg::PaintNode> AttachColorFill(const Json::Value& jfill, AttachContext* ctx) { |
| 404 | SkASSERT(jfill.isObject()); |
| 405 | |
| 406 | return AttachPaint(jfill, ctx, AttachColor(jfill, ctx)); |
| 407 | } |
| 408 | |
| 409 | sk_sp<sksg::PaintNode> AttachGradientFill(const Json::Value& jfill, AttachContext* ctx) { |
| 410 | SkASSERT(jfill.isObject()); |
| 411 | |
| 412 | return AttachPaint(jfill, ctx, AttachGradient(jfill, ctx)); |
| 413 | } |
| 414 | |
| 415 | sk_sp<sksg::PaintNode> AttachColorStroke(const Json::Value& jstroke, AttachContext* ctx) { |
| 416 | SkASSERT(jstroke.isObject()); |
| 417 | |
| 418 | return AttachStroke(jstroke, ctx, AttachPaint(jstroke, ctx, AttachColor(jstroke, ctx))); |
| 419 | } |
| 420 | |
| 421 | sk_sp<sksg::PaintNode> AttachGradientStroke(const Json::Value& jstroke, AttachContext* ctx) { |
| 422 | SkASSERT(jstroke.isObject()); |
| 423 | |
| 424 | return AttachStroke(jstroke, ctx, AttachPaint(jstroke, ctx, AttachGradient(jstroke, ctx))); |
| 425 | } |
| 426 | |
Florin Malita | e6345d9 | 2018-01-03 23:37:54 -0500 | [diff] [blame] | 427 | std::vector<sk_sp<sksg::GeometryNode>> AttachMergeGeometryEffect( |
| 428 | const Json::Value& jmerge, AttachContext* ctx, std::vector<sk_sp<sksg::GeometryNode>>&& geos) { |
| 429 | std::vector<sk_sp<sksg::GeometryNode>> merged; |
| 430 | |
| 431 | static constexpr sksg::Merge::Mode gModes[] = { |
| 432 | sksg::Merge::Mode::kMerge, // "mm": 1 |
| 433 | sksg::Merge::Mode::kUnion, // "mm": 2 |
| 434 | sksg::Merge::Mode::kDifference, // "mm": 3 |
| 435 | sksg::Merge::Mode::kIntersect, // "mm": 4 |
| 436 | sksg::Merge::Mode::kXOR , // "mm": 5 |
| 437 | }; |
| 438 | |
Florin Malita | 51b8c89 | 2018-01-07 08:54:24 -0500 | [diff] [blame] | 439 | const auto mode = gModes[SkTPin<int>(ParseInt(jmerge["mm"], 1) - 1, |
| 440 | 0, SK_ARRAY_COUNT(gModes) - 1)]; |
Florin Malita | e6345d9 | 2018-01-03 23:37:54 -0500 | [diff] [blame] | 441 | merged.push_back(sksg::Merge::Make(std::move(geos), mode)); |
| 442 | |
| 443 | LOG("** Attached merge path effect, mode: %d\n", mode); |
| 444 | |
| 445 | return merged; |
| 446 | } |
| 447 | |
Florin Malita | 51b8c89 | 2018-01-07 08:54:24 -0500 | [diff] [blame] | 448 | std::vector<sk_sp<sksg::GeometryNode>> AttachTrimGeometryEffect( |
| 449 | const Json::Value& jtrim, AttachContext* ctx, std::vector<sk_sp<sksg::GeometryNode>>&& geos) { |
| 450 | |
| 451 | enum class Mode { |
| 452 | kMerged, // "m": 1 |
| 453 | kSeparate, // "m": 2 |
| 454 | } gModes[] = { Mode::kMerged, Mode::kSeparate }; |
| 455 | |
| 456 | const auto mode = gModes[SkTPin<int>(ParseInt(jtrim["m"], 1) - 1, |
| 457 | 0, SK_ARRAY_COUNT(gModes) - 1)]; |
| 458 | |
| 459 | std::vector<sk_sp<sksg::GeometryNode>> inputs; |
| 460 | if (mode == Mode::kMerged) { |
| 461 | inputs.push_back(sksg::Merge::Make(std::move(geos), sksg::Merge::Mode::kMerge)); |
| 462 | } else { |
| 463 | inputs = std::move(geos); |
| 464 | } |
| 465 | |
| 466 | std::vector<sk_sp<sksg::GeometryNode>> trimmed; |
| 467 | trimmed.reserve(inputs.size()); |
| 468 | for (const auto& i : inputs) { |
| 469 | const auto trim = sksg::TrimEffect::Make(i); |
| 470 | trimmed.push_back(trim); |
Florin Malita | f959092 | 2018-01-09 11:56:09 -0500 | [diff] [blame] | 471 | BindProperty<ScalarValue>(jtrim["s"], ctx, trim, |
| 472 | [](sksg::TrimEffect* node, const ScalarValue& s) { |
Florin Malita | 51b8c89 | 2018-01-07 08:54:24 -0500 | [diff] [blame] | 473 | node->setStart(s * 0.01f); |
| 474 | }); |
Florin Malita | f959092 | 2018-01-09 11:56:09 -0500 | [diff] [blame] | 475 | BindProperty<ScalarValue>(jtrim["e"], ctx, trim, |
| 476 | [](sksg::TrimEffect* node, const ScalarValue& e) { |
Florin Malita | 51b8c89 | 2018-01-07 08:54:24 -0500 | [diff] [blame] | 477 | node->setEnd(e * 0.01f); |
| 478 | }); |
| 479 | // TODO: "offset" doesn't currently work the same as BM - figure out what's going on. |
Florin Malita | f959092 | 2018-01-09 11:56:09 -0500 | [diff] [blame] | 480 | BindProperty<ScalarValue>(jtrim["o"], ctx, trim, |
| 481 | [](sksg::TrimEffect* node, const ScalarValue& o) { |
Florin Malita | 51b8c89 | 2018-01-07 08:54:24 -0500 | [diff] [blame] | 482 | node->setOffset(o * 0.01f); |
| 483 | }); |
| 484 | } |
| 485 | |
| 486 | return trimmed; |
| 487 | } |
| 488 | |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 489 | using GeometryAttacherT = sk_sp<sksg::GeometryNode> (*)(const Json::Value&, AttachContext*); |
| 490 | static constexpr GeometryAttacherT gGeometryAttachers[] = { |
| 491 | AttachPathGeometry, |
Florin Malita | 2e1d7e2 | 2018-01-02 10:40:00 -0500 | [diff] [blame] | 492 | AttachRRectGeometry, |
Florin Malita | fbc13f1 | 2018-01-04 10:26:35 -0500 | [diff] [blame] | 493 | AttachEllipseGeometry, |
Florin Malita | 02a32b0 | 2018-01-04 11:27:09 -0500 | [diff] [blame] | 494 | AttachPolystarGeometry, |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 495 | }; |
| 496 | |
| 497 | using PaintAttacherT = sk_sp<sksg::PaintNode> (*)(const Json::Value&, AttachContext*); |
| 498 | static constexpr PaintAttacherT gPaintAttachers[] = { |
Florin Malita | 6aaee59 | 2018-01-12 12:25:09 -0500 | [diff] [blame] | 499 | AttachColorFill, |
| 500 | AttachColorStroke, |
| 501 | AttachGradientFill, |
| 502 | AttachGradientStroke, |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 503 | }; |
| 504 | |
| 505 | using GroupAttacherT = sk_sp<sksg::RenderNode> (*)(const Json::Value&, AttachContext*); |
| 506 | static constexpr GroupAttacherT gGroupAttachers[] = { |
| 507 | AttachShapeGroup, |
| 508 | }; |
| 509 | |
Florin Malita | e6345d9 | 2018-01-03 23:37:54 -0500 | [diff] [blame] | 510 | using GeometryEffectAttacherT = |
| 511 | std::vector<sk_sp<sksg::GeometryNode>> (*)(const Json::Value&, |
| 512 | AttachContext*, |
| 513 | std::vector<sk_sp<sksg::GeometryNode>>&&); |
| 514 | static constexpr GeometryEffectAttacherT gGeometryEffectAttachers[] = { |
| 515 | AttachMergeGeometryEffect, |
Florin Malita | 51b8c89 | 2018-01-07 08:54:24 -0500 | [diff] [blame] | 516 | AttachTrimGeometryEffect, |
Florin Malita | e6345d9 | 2018-01-03 23:37:54 -0500 | [diff] [blame] | 517 | }; |
| 518 | |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 519 | enum class ShapeType { |
| 520 | kGeometry, |
Florin Malita | e6345d9 | 2018-01-03 23:37:54 -0500 | [diff] [blame] | 521 | kGeometryEffect, |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 522 | kPaint, |
| 523 | kGroup, |
Florin Malita | dacc02b | 2017-12-31 09:12:31 -0500 | [diff] [blame] | 524 | kTransform, |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 525 | }; |
| 526 | |
| 527 | struct ShapeInfo { |
| 528 | const char* fTypeString; |
| 529 | ShapeType fShapeType; |
| 530 | uint32_t fAttacherIndex; // index into respective attacher tables |
| 531 | }; |
| 532 | |
| 533 | const ShapeInfo* FindShapeInfo(const Json::Value& shape) { |
| 534 | static constexpr ShapeInfo gShapeInfo[] = { |
Florin Malita | fbc13f1 | 2018-01-04 10:26:35 -0500 | [diff] [blame] | 535 | { "el", ShapeType::kGeometry , 2 }, // ellipse -> AttachEllipseGeometry |
Florin Malita | 6aaee59 | 2018-01-12 12:25:09 -0500 | [diff] [blame] | 536 | { "fl", ShapeType::kPaint , 0 }, // fill -> AttachColorFill |
| 537 | { "gf", ShapeType::kPaint , 2 }, // gfill -> AttachGradientFill |
Florin Malita | e6345d9 | 2018-01-03 23:37:54 -0500 | [diff] [blame] | 538 | { "gr", ShapeType::kGroup , 0 }, // group -> AttachShapeGroup |
Florin Malita | 6aaee59 | 2018-01-12 12:25:09 -0500 | [diff] [blame] | 539 | { "gs", ShapeType::kPaint , 3 }, // gstroke -> AttachGradientStroke |
Florin Malita | e6345d9 | 2018-01-03 23:37:54 -0500 | [diff] [blame] | 540 | { "mm", ShapeType::kGeometryEffect, 0 }, // merge -> AttachMergeGeometryEffect |
Florin Malita | 02a32b0 | 2018-01-04 11:27:09 -0500 | [diff] [blame] | 541 | { "rc", ShapeType::kGeometry , 1 }, // rrect -> AttachRRectGeometry |
Florin Malita | e6345d9 | 2018-01-03 23:37:54 -0500 | [diff] [blame] | 542 | { "sh", ShapeType::kGeometry , 0 }, // shape -> AttachPathGeometry |
Florin Malita | 02a32b0 | 2018-01-04 11:27:09 -0500 | [diff] [blame] | 543 | { "sr", ShapeType::kGeometry , 3 }, // polystar -> AttachPolyStarGeometry |
Florin Malita | 6aaee59 | 2018-01-12 12:25:09 -0500 | [diff] [blame] | 544 | { "st", ShapeType::kPaint , 1 }, // stroke -> AttachColorStroke |
Florin Malita | 51b8c89 | 2018-01-07 08:54:24 -0500 | [diff] [blame] | 545 | { "tm", ShapeType::kGeometryEffect, 1 }, // trim -> AttachTrimGeometryEffect |
Florin Malita | 18eafd9 | 2018-01-04 21:11:55 -0500 | [diff] [blame] | 546 | { "tr", ShapeType::kTransform , 0 }, // transform -> In-place handler |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 547 | }; |
| 548 | |
| 549 | if (!shape.isObject()) |
| 550 | return nullptr; |
| 551 | |
| 552 | const auto& type = shape["ty"]; |
| 553 | if (!type.isString()) |
| 554 | return nullptr; |
| 555 | |
| 556 | const auto* info = bsearch(type.asCString(), |
| 557 | gShapeInfo, |
| 558 | SK_ARRAY_COUNT(gShapeInfo), |
| 559 | sizeof(ShapeInfo), |
| 560 | [](const void* key, const void* info) { |
| 561 | return strcmp(static_cast<const char*>(key), |
| 562 | static_cast<const ShapeInfo*>(info)->fTypeString); |
| 563 | }); |
| 564 | |
| 565 | return static_cast<const ShapeInfo*>(info); |
| 566 | } |
| 567 | |
| 568 | sk_sp<sksg::RenderNode> AttachShape(const Json::Value& shapeArray, AttachContext* ctx) { |
| 569 | if (!shapeArray.isArray()) |
| 570 | return nullptr; |
| 571 | |
Florin Malita | 2a8275b | 2018-01-02 12:52:43 -0500 | [diff] [blame] | 572 | // (https://helpx.adobe.com/after-effects/using/overview-shape-layers-paths-vector.html#groups_and_render_order_for_shapes_and_shape_attributes) |
| 573 | // |
| 574 | // Render order for shapes within a shape layer |
| 575 | // |
| 576 | // The rules for rendering a shape layer are similar to the rules for rendering a composition |
| 577 | // that contains nested compositions: |
| 578 | // |
| 579 | // * Within a group, the shape at the bottom of the Timeline panel stacking order is rendered |
| 580 | // first. |
| 581 | // |
| 582 | // * All path operations within a group are performed before paint operations. This means, |
| 583 | // for example, that the stroke follows the distortions in the path made by the Wiggle Paths |
| 584 | // path operation. Path operations within a group are performed from top to bottom. |
| 585 | // |
| 586 | // * Paint operations within a group are performed from the bottom to the top in the Timeline |
| 587 | // panel stacking order. This means, for example, that a stroke is rendered on top of |
| 588 | // (in front of) a stroke that appears after it in the Timeline panel. |
| 589 | // |
Florin Malita | dacc02b | 2017-12-31 09:12:31 -0500 | [diff] [blame] | 590 | sk_sp<sksg::Group> shape_group = sksg::Group::Make(); |
| 591 | sk_sp<sksg::RenderNode> xformed_group = shape_group; |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 592 | |
Florin Malita | e6345d9 | 2018-01-03 23:37:54 -0500 | [diff] [blame] | 593 | std::vector<sk_sp<sksg::GeometryNode>> geos; |
| 594 | std::vector<sk_sp<sksg::RenderNode>> draws; |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 595 | |
| 596 | for (const auto& s : shapeArray) { |
| 597 | const auto* info = FindShapeInfo(s); |
| 598 | if (!info) { |
| 599 | LogFail(s.isObject() ? s["ty"] : s, "Unknown shape"); |
| 600 | continue; |
| 601 | } |
| 602 | |
| 603 | switch (info->fShapeType) { |
| 604 | case ShapeType::kGeometry: { |
| 605 | SkASSERT(info->fAttacherIndex < SK_ARRAY_COUNT(gGeometryAttachers)); |
| 606 | if (auto geo = gGeometryAttachers[info->fAttacherIndex](s, ctx)) { |
| 607 | geos.push_back(std::move(geo)); |
| 608 | } |
| 609 | } break; |
Florin Malita | e6345d9 | 2018-01-03 23:37:54 -0500 | [diff] [blame] | 610 | case ShapeType::kGeometryEffect: { |
| 611 | SkASSERT(info->fAttacherIndex < SK_ARRAY_COUNT(gGeometryEffectAttachers)); |
| 612 | geos = gGeometryEffectAttachers[info->fAttacherIndex](s, ctx, std::move(geos)); |
| 613 | } break; |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 614 | case ShapeType::kPaint: { |
| 615 | SkASSERT(info->fAttacherIndex < SK_ARRAY_COUNT(gPaintAttachers)); |
| 616 | if (auto paint = gPaintAttachers[info->fAttacherIndex](s, ctx)) { |
Florin Malita | 2a8275b | 2018-01-02 12:52:43 -0500 | [diff] [blame] | 617 | for (const auto& geo : geos) { |
| 618 | draws.push_back(sksg::Draw::Make(geo, paint)); |
| 619 | } |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 620 | } |
| 621 | } break; |
| 622 | case ShapeType::kGroup: { |
| 623 | SkASSERT(info->fAttacherIndex < SK_ARRAY_COUNT(gGroupAttachers)); |
| 624 | if (auto group = gGroupAttachers[info->fAttacherIndex](s, ctx)) { |
Florin Malita | 2a8275b | 2018-01-02 12:52:43 -0500 | [diff] [blame] | 625 | draws.push_back(std::move(group)); |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 626 | } |
| 627 | } break; |
Florin Malita | dacc02b | 2017-12-31 09:12:31 -0500 | [diff] [blame] | 628 | case ShapeType::kTransform: { |
Florin Malita | 2a8275b | 2018-01-02 12:52:43 -0500 | [diff] [blame] | 629 | // TODO: BM appears to transform the geometry, not the draw op itself. |
Florin Malita | 18eafd9 | 2018-01-04 21:11:55 -0500 | [diff] [blame] | 630 | if (auto matrix = AttachMatrix(s, ctx, nullptr)) { |
| 631 | xformed_group = sksg::Transform::Make(std::move(xformed_group), |
| 632 | std::move(matrix)); |
| 633 | } |
Florin Malita | c003417 | 2018-01-08 16:42:59 -0500 | [diff] [blame] | 634 | xformed_group = AttachOpacity(s, ctx, std::move(xformed_group)); |
Florin Malita | dacc02b | 2017-12-31 09:12:31 -0500 | [diff] [blame] | 635 | } break; |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 636 | } |
| 637 | } |
| 638 | |
Florin Malita | 2a8275b | 2018-01-02 12:52:43 -0500 | [diff] [blame] | 639 | if (draws.empty()) { |
| 640 | return nullptr; |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 641 | } |
| 642 | |
Florin Malita | e6345d9 | 2018-01-03 23:37:54 -0500 | [diff] [blame] | 643 | for (auto draw = draws.rbegin(); draw != draws.rend(); ++draw) { |
| 644 | shape_group->addChild(std::move(*draw)); |
Florin Malita | 2a8275b | 2018-01-02 12:52:43 -0500 | [diff] [blame] | 645 | } |
| 646 | |
Florin Malita | e6345d9 | 2018-01-03 23:37:54 -0500 | [diff] [blame] | 647 | LOG("** Attached shape: %zd draws.\n", draws.size()); |
Florin Malita | dacc02b | 2017-12-31 09:12:31 -0500 | [diff] [blame] | 648 | return xformed_group; |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | sk_sp<sksg::RenderNode> AttachCompLayer(const Json::Value& layer, AttachContext* ctx) { |
| 652 | SkASSERT(layer.isObject()); |
| 653 | |
| 654 | auto refId = ParseString(layer["refId"], ""); |
| 655 | if (refId.isEmpty()) { |
| 656 | LOG("!! Comp layer missing refId\n"); |
| 657 | return nullptr; |
| 658 | } |
| 659 | |
| 660 | const auto* comp = ctx->fAssets.find(refId); |
| 661 | if (!comp) { |
| 662 | LOG("!! Pre-comp not found: '%s'\n", refId.c_str()); |
| 663 | return nullptr; |
| 664 | } |
| 665 | |
| 666 | // TODO: cycle detection |
| 667 | return AttachComposition(**comp, ctx); |
| 668 | } |
| 669 | |
Florin Malita | 0e66fba | 2018-01-09 17:10:18 -0500 | [diff] [blame] | 670 | sk_sp<sksg::RenderNode> AttachSolidLayer(const Json::Value& jlayer, AttachContext*) { |
| 671 | SkASSERT(jlayer.isObject()); |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 672 | |
Florin Malita | 0e66fba | 2018-01-09 17:10:18 -0500 | [diff] [blame] | 673 | const auto size = SkSize::Make(ParseScalar(jlayer["sw"], -1), |
| 674 | ParseScalar(jlayer["sh"], -1)); |
| 675 | const auto hex = ParseString(jlayer["sc"], ""); |
| 676 | uint32_t c; |
| 677 | if (size.isEmpty() || |
| 678 | !hex.startsWith("#") || |
| 679 | !SkParse::FindHex(hex.c_str() + 1, &c)) { |
| 680 | LogFail(jlayer, "Could not parse solid layer"); |
| 681 | return nullptr; |
| 682 | } |
| 683 | |
| 684 | const SkColor color = 0xff000000 | c; |
| 685 | |
| 686 | return sksg::Draw::Make(sksg::Rect::Make(SkRect::MakeSize(size)), |
| 687 | sksg::Color::Make(color)); |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 688 | } |
| 689 | |
Florin Malita | 4932807 | 2018-01-08 12:51:12 -0500 | [diff] [blame] | 690 | sk_sp<sksg::RenderNode> AttachImageAsset(const Json::Value& jimage, AttachContext* ctx) { |
| 691 | SkASSERT(jimage.isObject()); |
| 692 | |
| 693 | const auto name = ParseString(jimage["p"], ""), |
| 694 | path = ParseString(jimage["u"], ""); |
| 695 | if (name.isEmpty()) |
| 696 | return nullptr; |
| 697 | |
| 698 | // TODO: plumb resource paths explicitly to ResourceProvider? |
| 699 | const auto resName = path.isEmpty() ? name : SkOSPath::Join(path.c_str(), name.c_str()); |
| 700 | const auto resStream = ctx->fResources.openStream(resName.c_str()); |
| 701 | if (!resStream || !resStream->hasLength()) { |
| 702 | LOG("!! Could not load image resource: %s\n", resName.c_str()); |
| 703 | return nullptr; |
| 704 | } |
| 705 | |
| 706 | // TODO: non-intrisic image sizing |
| 707 | return sksg::Image::Make( |
| 708 | SkImage::MakeFromEncoded(SkData::MakeFromStream(resStream.get(), resStream->getLength()))); |
| 709 | } |
| 710 | |
| 711 | sk_sp<sksg::RenderNode> AttachImageLayer(const Json::Value& layer, AttachContext* ctx) { |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 712 | SkASSERT(layer.isObject()); |
| 713 | |
Florin Malita | 4932807 | 2018-01-08 12:51:12 -0500 | [diff] [blame] | 714 | auto refId = ParseString(layer["refId"], ""); |
| 715 | if (refId.isEmpty()) { |
| 716 | LOG("!! Image layer missing refId\n"); |
| 717 | return nullptr; |
| 718 | } |
| 719 | |
| 720 | const auto* jimage = ctx->fAssets.find(refId); |
| 721 | if (!jimage) { |
| 722 | LOG("!! Image asset not found: '%s'\n", refId.c_str()); |
| 723 | return nullptr; |
| 724 | } |
| 725 | |
| 726 | return AttachImageAsset(**jimage, ctx); |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 727 | } |
| 728 | |
| 729 | sk_sp<sksg::RenderNode> AttachNullLayer(const Json::Value& layer, AttachContext*) { |
| 730 | SkASSERT(layer.isObject()); |
| 731 | |
Florin Malita | 18eafd9 | 2018-01-04 21:11:55 -0500 | [diff] [blame] | 732 | // Null layers are used solely to drive dependent transforms, |
| 733 | // but we use free-floating sksg::Matrices for that purpose. |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 734 | return nullptr; |
| 735 | } |
| 736 | |
| 737 | sk_sp<sksg::RenderNode> AttachShapeLayer(const Json::Value& layer, AttachContext* ctx) { |
| 738 | SkASSERT(layer.isObject()); |
| 739 | |
| 740 | LOG("** Attaching shape layer ind: %d\n", ParseInt(layer["ind"], 0)); |
| 741 | |
| 742 | return AttachShape(layer["shapes"], ctx); |
| 743 | } |
| 744 | |
| 745 | sk_sp<sksg::RenderNode> AttachTextLayer(const Json::Value& layer, AttachContext*) { |
| 746 | SkASSERT(layer.isObject()); |
| 747 | |
| 748 | LOG("?? Text layer stub\n"); |
| 749 | return nullptr; |
| 750 | } |
| 751 | |
Florin Malita | 18eafd9 | 2018-01-04 21:11:55 -0500 | [diff] [blame] | 752 | struct AttachLayerContext { |
| 753 | AttachLayerContext(const Json::Value& jlayers, AttachContext* ctx) |
| 754 | : fLayerList(jlayers), fCtx(ctx) {} |
| 755 | |
| 756 | const Json::Value& fLayerList; |
| 757 | AttachContext* fCtx; |
| 758 | std::unordered_map<const Json::Value*, sk_sp<sksg::Matrix>> fLayerMatrixCache; |
| 759 | std::unordered_map<int, const Json::Value*> fLayerIndexCache; |
Florin Malita | 5f9102f | 2018-01-10 13:36:22 -0500 | [diff] [blame] | 760 | sk_sp<sksg::RenderNode> fCurrentMatte; |
Florin Malita | 18eafd9 | 2018-01-04 21:11:55 -0500 | [diff] [blame] | 761 | |
| 762 | const Json::Value* findLayer(int index) { |
| 763 | SkASSERT(fLayerList.isArray()); |
| 764 | |
| 765 | if (index < 0) { |
| 766 | return nullptr; |
| 767 | } |
| 768 | |
| 769 | const auto cached = fLayerIndexCache.find(index); |
| 770 | if (cached != fLayerIndexCache.end()) { |
| 771 | return cached->second; |
| 772 | } |
| 773 | |
| 774 | for (const auto& l : fLayerList) { |
| 775 | if (!l.isObject()) { |
| 776 | continue; |
| 777 | } |
| 778 | |
| 779 | if (ParseInt(l["ind"], -1) == index) { |
| 780 | fLayerIndexCache.insert(std::make_pair(index, &l)); |
| 781 | return &l; |
| 782 | } |
| 783 | } |
| 784 | |
| 785 | return nullptr; |
| 786 | } |
| 787 | |
| 788 | sk_sp<sksg::Matrix> AttachLayerMatrix(const Json::Value& jlayer) { |
| 789 | SkASSERT(jlayer.isObject()); |
| 790 | |
| 791 | const auto cached = fLayerMatrixCache.find(&jlayer); |
| 792 | if (cached != fLayerMatrixCache.end()) { |
| 793 | return cached->second; |
| 794 | } |
| 795 | |
| 796 | const auto* parentLayer = this->findLayer(ParseInt(jlayer["parent"], -1)); |
| 797 | |
| 798 | // TODO: cycle detection? |
| 799 | auto parentMatrix = (parentLayer && parentLayer != &jlayer) |
| 800 | ? this->AttachLayerMatrix(*parentLayer) : nullptr; |
| 801 | |
| 802 | auto layerMatrix = AttachMatrix(jlayer["ks"], fCtx, std::move(parentMatrix)); |
| 803 | fLayerMatrixCache.insert(std::make_pair(&jlayer, layerMatrix)); |
| 804 | |
| 805 | return layerMatrix; |
| 806 | } |
| 807 | }; |
| 808 | |
| 809 | sk_sp<sksg::RenderNode> AttachLayer(const Json::Value& jlayer, |
| 810 | AttachLayerContext* layerCtx) { |
| 811 | if (!jlayer.isObject()) |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 812 | return nullptr; |
| 813 | |
| 814 | using LayerAttacher = sk_sp<sksg::RenderNode> (*)(const Json::Value&, AttachContext*); |
| 815 | static constexpr LayerAttacher gLayerAttachers[] = { |
| 816 | AttachCompLayer, // 'ty': 0 |
| 817 | AttachSolidLayer, // 'ty': 1 |
| 818 | AttachImageLayer, // 'ty': 2 |
| 819 | AttachNullLayer, // 'ty': 3 |
| 820 | AttachShapeLayer, // 'ty': 4 |
| 821 | AttachTextLayer, // 'ty': 5 |
| 822 | }; |
| 823 | |
Florin Malita | 18eafd9 | 2018-01-04 21:11:55 -0500 | [diff] [blame] | 824 | int type = ParseInt(jlayer["ty"], -1); |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 825 | if (type < 0 || type >= SkTo<int>(SK_ARRAY_COUNT(gLayerAttachers))) { |
| 826 | return nullptr; |
| 827 | } |
| 828 | |
Florin Malita | 71cba8f | 2018-01-09 08:07:14 -0500 | [diff] [blame] | 829 | // Layer content. |
| 830 | auto layer = gLayerAttachers[type](jlayer, layerCtx->fCtx); |
| 831 | if (auto layerMatrix = layerCtx->AttachLayerMatrix(jlayer)) { |
| 832 | // Optional layer transform. |
| 833 | layer = sksg::Transform::Make(std::move(layer), std::move(layerMatrix)); |
| 834 | } |
| 835 | // Optional layer opacity. |
| 836 | layer = AttachOpacity(jlayer["ks"], layerCtx->fCtx, std::move(layer)); |
Florin Malita | 18eafd9 | 2018-01-04 21:11:55 -0500 | [diff] [blame] | 837 | |
Florin Malita | 71cba8f | 2018-01-09 08:07:14 -0500 | [diff] [blame] | 838 | // TODO: we should also disable related/inactive animators. |
| 839 | class Activator final : public AnimatorBase { |
| 840 | public: |
| 841 | Activator(sk_sp<sksg::OpacityEffect> controlNode, float in, float out) |
| 842 | : fControlNode(std::move(controlNode)) |
| 843 | , fIn(in) |
| 844 | , fOut(out) {} |
| 845 | |
Florin Malita | a6dd752 | 2018-01-09 08:46:52 -0500 | [diff] [blame] | 846 | void tick(float t) override { |
Florin Malita | 71cba8f | 2018-01-09 08:07:14 -0500 | [diff] [blame] | 847 | // Keep the layer fully transparent except for its [in..out] lifespan. |
| 848 | // (note: opacity == 0 disables rendering, while opacity == 1 is a noop) |
| 849 | fControlNode->setOpacity(t >= fIn && t <= fOut ? 1 : 0); |
| 850 | } |
| 851 | |
| 852 | private: |
| 853 | const sk_sp<sksg::OpacityEffect> fControlNode; |
| 854 | const float fIn, |
| 855 | fOut; |
| 856 | }; |
| 857 | |
| 858 | auto layerControl = sksg::OpacityEffect::Make(std::move(layer)); |
| 859 | const auto in = ParseScalar(jlayer["ip"], 0), |
| 860 | out = ParseScalar(jlayer["op"], in); |
| 861 | |
| 862 | if (in >= out || ! layerControl) |
| 863 | return nullptr; |
| 864 | |
| 865 | layerCtx->fCtx->fAnimators.push_back(skstd::make_unique<Activator>(layerControl, in, out)); |
| 866 | |
Florin Malita | 5f9102f | 2018-01-10 13:36:22 -0500 | [diff] [blame] | 867 | if (ParseBool(jlayer["td"], false)) { |
| 868 | // This layer is a matte. We apply it as a mask to the next layer. |
| 869 | layerCtx->fCurrentMatte = std::move(layerControl); |
| 870 | return nullptr; |
| 871 | } |
| 872 | |
| 873 | if (layerCtx->fCurrentMatte) { |
| 874 | // There is a pending matte. Apply and reset. |
| 875 | return sksg::MaskEffect::Make(std::move(layerControl), std::move(layerCtx->fCurrentMatte)); |
| 876 | } |
| 877 | |
Florin Malita | 71cba8f | 2018-01-09 08:07:14 -0500 | [diff] [blame] | 878 | return layerControl; |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 879 | } |
| 880 | |
| 881 | sk_sp<sksg::RenderNode> AttachComposition(const Json::Value& comp, AttachContext* ctx) { |
| 882 | if (!comp.isObject()) |
| 883 | return nullptr; |
| 884 | |
Florin Malita | 18eafd9 | 2018-01-04 21:11:55 -0500 | [diff] [blame] | 885 | const auto& jlayers = comp["layers"]; |
| 886 | if (!jlayers.isArray()) |
| 887 | return nullptr; |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 888 | |
Florin Malita | 18eafd9 | 2018-01-04 21:11:55 -0500 | [diff] [blame] | 889 | SkSTArray<16, sk_sp<sksg::RenderNode>, true> layers; |
| 890 | AttachLayerContext layerCtx(jlayers, ctx); |
| 891 | |
| 892 | for (const auto& l : jlayers) { |
| 893 | if (auto layer_fragment = AttachLayer(l, &layerCtx)) { |
Florin Malita | 2a8275b | 2018-01-02 12:52:43 -0500 | [diff] [blame] | 894 | layers.push_back(std::move(layer_fragment)); |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 895 | } |
| 896 | } |
| 897 | |
Florin Malita | 2a8275b | 2018-01-02 12:52:43 -0500 | [diff] [blame] | 898 | if (layers.empty()) { |
| 899 | return nullptr; |
| 900 | } |
| 901 | |
| 902 | // Layers are painted in bottom->top order. |
| 903 | auto comp_group = sksg::Group::Make(); |
| 904 | for (int i = layers.count() - 1; i >= 0; --i) { |
| 905 | comp_group->addChild(std::move(layers[i])); |
| 906 | } |
| 907 | |
| 908 | LOG("** Attached composition '%s': %d layers.\n", |
| 909 | ParseString(comp["id"], "").c_str(), layers.count()); |
| 910 | |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 911 | return comp_group; |
| 912 | } |
| 913 | |
| 914 | } // namespace |
| 915 | |
Florin Malita | 4932807 | 2018-01-08 12:51:12 -0500 | [diff] [blame] | 916 | std::unique_ptr<Animation> Animation::Make(SkStream* stream, const ResourceProvider& res) { |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 917 | if (!stream->hasLength()) { |
| 918 | // TODO: handle explicit buffering? |
| 919 | LOG("!! cannot parse streaming content\n"); |
| 920 | return nullptr; |
| 921 | } |
| 922 | |
| 923 | Json::Value json; |
| 924 | { |
| 925 | auto data = SkData::MakeFromStream(stream, stream->getLength()); |
| 926 | if (!data) { |
| 927 | LOG("!! could not read stream\n"); |
| 928 | return nullptr; |
| 929 | } |
| 930 | |
| 931 | Json::Reader reader; |
| 932 | |
| 933 | auto dataStart = static_cast<const char*>(data->data()); |
| 934 | if (!reader.parse(dataStart, dataStart + data->size(), json, false) || !json.isObject()) { |
| 935 | LOG("!! failed to parse json: %s\n", reader.getFormattedErrorMessages().c_str()); |
| 936 | return nullptr; |
| 937 | } |
| 938 | } |
| 939 | |
| 940 | const auto version = ParseString(json["v"], ""); |
| 941 | const auto size = SkSize::Make(ParseScalar(json["w"], -1), ParseScalar(json["h"], -1)); |
| 942 | const auto fps = ParseScalar(json["fr"], -1); |
| 943 | |
| 944 | if (size.isEmpty() || version.isEmpty() || fps < 0) { |
| 945 | LOG("!! invalid animation params (version: %s, size: [%f %f], frame rate: %f)", |
| 946 | version.c_str(), size.width(), size.height(), fps); |
| 947 | return nullptr; |
| 948 | } |
| 949 | |
Florin Malita | 4932807 | 2018-01-08 12:51:12 -0500 | [diff] [blame] | 950 | return std::unique_ptr<Animation>(new Animation(res, std::move(version), size, fps, json)); |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 951 | } |
| 952 | |
Florin Malita | 4932807 | 2018-01-08 12:51:12 -0500 | [diff] [blame] | 953 | std::unique_ptr<Animation> Animation::MakeFromFile(const char path[], const ResourceProvider* res) { |
| 954 | class DirectoryResourceProvider final : public ResourceProvider { |
| 955 | public: |
| 956 | explicit DirectoryResourceProvider(SkString dir) : fDir(std::move(dir)) {} |
| 957 | |
| 958 | std::unique_ptr<SkStream> openStream(const char resource[]) const override { |
| 959 | const auto resPath = SkOSPath::Join(fDir.c_str(), resource); |
| 960 | return SkStream::MakeFromFile(resPath.c_str()); |
| 961 | } |
| 962 | |
| 963 | private: |
| 964 | const SkString fDir; |
| 965 | }; |
| 966 | |
| 967 | const auto jsonStream = SkStream::MakeFromFile(path); |
| 968 | if (!jsonStream) |
| 969 | return nullptr; |
| 970 | |
| 971 | std::unique_ptr<ResourceProvider> defaultProvider; |
| 972 | if (!res) { |
| 973 | defaultProvider = skstd::make_unique<DirectoryResourceProvider>(SkOSPath::Dirname(path)); |
| 974 | } |
| 975 | |
| 976 | return Make(jsonStream.get(), res ? *res : *defaultProvider); |
| 977 | } |
| 978 | |
| 979 | Animation::Animation(const ResourceProvider& resources, |
| 980 | SkString version, const SkSize& size, SkScalar fps, const Json::Value& json) |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 981 | : fVersion(std::move(version)) |
| 982 | , fSize(size) |
| 983 | , fFrameRate(fps) |
| 984 | , fInPoint(ParseScalar(json["ip"], 0)) |
| 985 | , fOutPoint(SkTMax(ParseScalar(json["op"], SK_ScalarMax), fInPoint)) { |
| 986 | |
| 987 | AssetMap assets; |
| 988 | for (const auto& asset : json["assets"]) { |
| 989 | if (!asset.isObject()) { |
| 990 | continue; |
| 991 | } |
| 992 | |
| 993 | assets.set(ParseString(asset["id"], ""), &asset); |
| 994 | } |
| 995 | |
Florin Malita | 4932807 | 2018-01-08 12:51:12 -0500 | [diff] [blame] | 996 | AttachContext ctx = { resources, assets, fAnimators }; |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 997 | fDom = AttachComposition(json, &ctx); |
| 998 | |
Florin Malita | db38573 | 2018-01-09 12:19:32 -0500 | [diff] [blame] | 999 | // In case the client calls render before the first tick. |
| 1000 | this->animationTick(0); |
| 1001 | |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 1002 | LOG("** Attached %d animators\n", fAnimators.count()); |
| 1003 | } |
| 1004 | |
| 1005 | Animation::~Animation() = default; |
| 1006 | |
Mike Reed | 2985987 | 2018-01-08 08:25:27 -0500 | [diff] [blame] | 1007 | void Animation::render(SkCanvas* canvas, const SkRect* dstR) const { |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 1008 | if (!fDom) |
| 1009 | return; |
| 1010 | |
| 1011 | sksg::InvalidationController ic; |
| 1012 | fDom->revalidate(&ic, SkMatrix::I()); |
| 1013 | |
| 1014 | // TODO: proper inval |
Mike Reed | 2985987 | 2018-01-08 08:25:27 -0500 | [diff] [blame] | 1015 | SkAutoCanvasRestore restore(canvas, true); |
| 1016 | const SkRect srcR = SkRect::MakeSize(this->size()); |
| 1017 | if (dstR) { |
| 1018 | canvas->concat(SkMatrix::MakeRectToRect(srcR, *dstR, SkMatrix::kCenter_ScaleToFit)); |
| 1019 | } |
| 1020 | canvas->clipRect(srcR); |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 1021 | fDom->render(canvas); |
| 1022 | |
| 1023 | if (!fShowInval) |
| 1024 | return; |
| 1025 | |
| 1026 | SkPaint fill, stroke; |
| 1027 | fill.setAntiAlias(true); |
| 1028 | fill.setColor(0x40ff0000); |
| 1029 | stroke.setAntiAlias(true); |
| 1030 | stroke.setColor(0xffff0000); |
| 1031 | stroke.setStyle(SkPaint::kStroke_Style); |
| 1032 | |
| 1033 | for (const auto& r : ic) { |
| 1034 | canvas->drawRect(r, fill); |
| 1035 | canvas->drawRect(r, stroke); |
| 1036 | } |
| 1037 | } |
| 1038 | |
| 1039 | void Animation::animationTick(SkMSec ms) { |
| 1040 | // 't' in the BM model really means 'frame #' |
| 1041 | auto t = static_cast<float>(ms) * fFrameRate / 1000; |
| 1042 | |
| 1043 | t = fInPoint + std::fmod(t, fOutPoint - fInPoint); |
| 1044 | |
| 1045 | // TODO: this can be optimized quite a bit with some sorting/state tracking. |
| 1046 | for (const auto& a : fAnimators) { |
| 1047 | a->tick(t); |
| 1048 | } |
| 1049 | } |
| 1050 | |
Florin Malita | 54f65c4 | 2018-01-16 17:04:30 -0500 | [diff] [blame] | 1051 | } // namespace skottie |