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 | |
| 8 | #include "Skotty.h" |
| 9 | |
| 10 | #include "SkCanvas.h" |
| 11 | #include "SkottyAnimator.h" |
| 12 | #include "SkottyPriv.h" |
| 13 | #include "SkottyProperties.h" |
| 14 | #include "SkData.h" |
| 15 | #include "SkMakeUnique.h" |
| 16 | #include "SkPaint.h" |
| 17 | #include "SkPath.h" |
| 18 | #include "SkPoint.h" |
| 19 | #include "SkSGColor.h" |
| 20 | #include "SkSGDraw.h" |
| 21 | #include "SkSGInvalidationController.h" |
| 22 | #include "SkSGGroup.h" |
Florin Malita | e6345d9 | 2018-01-03 23:37:54 -0500 | [diff] [blame] | 23 | #include "SkSGMerge.h" |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 24 | #include "SkSGPath.h" |
Florin Malita | 2e1d7e2 | 2018-01-02 10:40:00 -0500 | [diff] [blame] | 25 | #include "SkSGRect.h" |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 26 | #include "SkSGTransform.h" |
| 27 | #include "SkStream.h" |
| 28 | #include "SkTArray.h" |
| 29 | #include "SkTHash.h" |
| 30 | |
| 31 | #include <cmath> |
Florin Malita | 18eafd9 | 2018-01-04 21:11:55 -0500 | [diff] [blame] | 32 | #include <unordered_map> |
Florin Malita | e6345d9 | 2018-01-03 23:37:54 -0500 | [diff] [blame] | 33 | #include <vector> |
| 34 | |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 35 | #include "stdlib.h" |
| 36 | |
| 37 | namespace skotty { |
| 38 | |
| 39 | namespace { |
| 40 | |
| 41 | using AssetMap = SkTHashMap<SkString, const Json::Value*>; |
| 42 | |
| 43 | struct AttachContext { |
| 44 | const AssetMap& fAssets; |
| 45 | SkTArray<std::unique_ptr<AnimatorBase>>& fAnimators; |
| 46 | }; |
| 47 | |
| 48 | bool LogFail(const Json::Value& json, const char* msg) { |
| 49 | const auto dump = json.toStyledString(); |
| 50 | LOG("!! %s: %s", msg, dump.c_str()); |
| 51 | return false; |
| 52 | } |
| 53 | |
| 54 | // This is the workhorse for binding properties: depending on whether the property is animated, |
| 55 | // it will either apply immediately or instantiate and attach a keyframe animator. |
Florin Malita | 9661b98 | 2018-01-06 14:25:49 -0500 | [diff] [blame^] | 56 | template <typename ValueT, typename AttrT, typename NodeT> |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 57 | bool AttachProperty(const Json::Value& jprop, AttachContext* ctx, const sk_sp<NodeT>& node, |
Florin Malita | 9661b98 | 2018-01-06 14:25:49 -0500 | [diff] [blame^] | 58 | typename Animator<ValueT, AttrT, NodeT>::ApplyFuncT&& apply) { |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 59 | if (!jprop.isObject()) |
| 60 | return false; |
| 61 | |
| 62 | if (!ParseBool(jprop["a"], false)) { |
| 63 | // Static property. |
| 64 | ValueT val; |
| 65 | if (!ValueT::Parse(jprop["k"], &val)) { |
| 66 | return LogFail(jprop, "Could not parse static property"); |
| 67 | } |
| 68 | |
| 69 | apply(node, val.template as<AttrT>()); |
| 70 | } else { |
| 71 | // Keyframe property. |
| 72 | using AnimatorT = Animator<ValueT, AttrT, NodeT>; |
| 73 | auto animator = AnimatorT::Make(jprop["k"], node, std::move(apply)); |
| 74 | |
| 75 | if (!animator) { |
| 76 | return LogFail(jprop, "Could not instantiate keyframe animator"); |
| 77 | } |
| 78 | |
| 79 | ctx->fAnimators.push_back(std::move(animator)); |
| 80 | } |
| 81 | |
| 82 | return true; |
| 83 | } |
| 84 | |
Florin Malita | 18eafd9 | 2018-01-04 21:11:55 -0500 | [diff] [blame] | 85 | sk_sp<sksg::Matrix> AttachMatrix(const Json::Value& t, AttachContext* ctx, |
| 86 | sk_sp<sksg::Matrix> parentMatrix) { |
| 87 | if (!t.isObject()) |
| 88 | return nullptr; |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 89 | |
Florin Malita | 18eafd9 | 2018-01-04 21:11:55 -0500 | [diff] [blame] | 90 | auto matrix = sksg::Matrix::Make(SkMatrix::I(), std::move(parentMatrix)); |
| 91 | auto composite = sk_make_sp<CompositeTransform>(matrix); |
| 92 | auto anchor_attached = AttachProperty<VectorValue, SkPoint>(t["a"], ctx, composite, |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 93 | [](const sk_sp<CompositeTransform>& node, const SkPoint& a) { |
| 94 | node->setAnchorPoint(a); |
| 95 | }); |
Florin Malita | 18eafd9 | 2018-01-04 21:11:55 -0500 | [diff] [blame] | 96 | auto position_attached = AttachProperty<VectorValue, SkPoint>(t["p"], ctx, composite, |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 97 | [](const sk_sp<CompositeTransform>& node, const SkPoint& p) { |
| 98 | node->setPosition(p); |
| 99 | }); |
Florin Malita | 18eafd9 | 2018-01-04 21:11:55 -0500 | [diff] [blame] | 100 | auto scale_attached = AttachProperty<VectorValue, SkVector>(t["s"], ctx, composite, |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 101 | [](const sk_sp<CompositeTransform>& node, const SkVector& s) { |
| 102 | node->setScale(s); |
| 103 | }); |
Florin Malita | 18eafd9 | 2018-01-04 21:11:55 -0500 | [diff] [blame] | 104 | auto rotation_attached = AttachProperty<ScalarValue, SkScalar>(t["r"], ctx, composite, |
Florin Malita | 9661b98 | 2018-01-06 14:25:49 -0500 | [diff] [blame^] | 105 | [](const sk_sp<CompositeTransform>& node, const SkScalar& r) { |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 106 | node->setRotation(r); |
| 107 | }); |
Florin Malita | 18eafd9 | 2018-01-04 21:11:55 -0500 | [diff] [blame] | 108 | auto skew_attached = AttachProperty<ScalarValue, SkScalar>(t["sk"], ctx, composite, |
Florin Malita | 9661b98 | 2018-01-06 14:25:49 -0500 | [diff] [blame^] | 109 | [](const sk_sp<CompositeTransform>& node, const SkScalar& sk) { |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 110 | node->setSkew(sk); |
| 111 | }); |
Florin Malita | 18eafd9 | 2018-01-04 21:11:55 -0500 | [diff] [blame] | 112 | auto skewaxis_attached = AttachProperty<ScalarValue, SkScalar>(t["sa"], ctx, composite, |
Florin Malita | 9661b98 | 2018-01-06 14:25:49 -0500 | [diff] [blame^] | 113 | [](const sk_sp<CompositeTransform>& node, const SkScalar& sa) { |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 114 | node->setSkewAxis(sa); |
| 115 | }); |
| 116 | |
| 117 | if (!anchor_attached && |
| 118 | !position_attached && |
| 119 | !scale_attached && |
| 120 | !rotation_attached && |
| 121 | !skew_attached && |
| 122 | !skewaxis_attached) { |
| 123 | LogFail(t, "Could not parse transform"); |
Florin Malita | 18eafd9 | 2018-01-04 21:11:55 -0500 | [diff] [blame] | 124 | return nullptr; |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 125 | } |
| 126 | |
Florin Malita | 18eafd9 | 2018-01-04 21:11:55 -0500 | [diff] [blame] | 127 | return matrix; |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | sk_sp<sksg::RenderNode> AttachShape(const Json::Value&, AttachContext* ctx); |
| 131 | sk_sp<sksg::RenderNode> AttachComposition(const Json::Value&, AttachContext* ctx); |
| 132 | |
| 133 | sk_sp<sksg::RenderNode> AttachShapeGroup(const Json::Value& jgroup, AttachContext* ctx) { |
| 134 | SkASSERT(jgroup.isObject()); |
| 135 | |
| 136 | return AttachShape(jgroup["it"], ctx); |
| 137 | } |
| 138 | |
| 139 | sk_sp<sksg::GeometryNode> AttachPathGeometry(const Json::Value& jpath, AttachContext* ctx) { |
| 140 | SkASSERT(jpath.isObject()); |
| 141 | |
| 142 | auto path_node = sksg::Path::Make(); |
| 143 | auto path_attached = AttachProperty<ShapeValue, SkPath>(jpath["ks"], ctx, path_node, |
| 144 | [](const sk_sp<sksg::Path>& node, const SkPath& p) { node->setPath(p); }); |
| 145 | |
| 146 | if (path_attached) |
| 147 | LOG("** Attached path geometry - verbs: %d\n", path_node->getPath().countVerbs()); |
| 148 | |
| 149 | return path_attached ? path_node : nullptr; |
| 150 | } |
| 151 | |
Florin Malita | 2e1d7e2 | 2018-01-02 10:40:00 -0500 | [diff] [blame] | 152 | sk_sp<sksg::GeometryNode> AttachRRectGeometry(const Json::Value& jrect, AttachContext* ctx) { |
| 153 | SkASSERT(jrect.isObject()); |
| 154 | |
| 155 | auto rect_node = sksg::RRect::Make(); |
| 156 | auto composite = sk_make_sp<CompositeRRect>(rect_node); |
| 157 | |
| 158 | auto p_attached = AttachProperty<VectorValue, SkPoint>(jrect["p"], ctx, composite, |
| 159 | [](const sk_sp<CompositeRRect>& node, const SkPoint& pos) { node->setPosition(pos); }); |
| 160 | auto s_attached = AttachProperty<VectorValue, SkSize>(jrect["s"], ctx, composite, |
| 161 | [](const sk_sp<CompositeRRect>& node, const SkSize& sz) { node->setSize(sz); }); |
| 162 | auto r_attached = AttachProperty<ScalarValue, SkScalar>(jrect["r"], ctx, composite, |
Florin Malita | 9661b98 | 2018-01-06 14:25:49 -0500 | [diff] [blame^] | 163 | [](const sk_sp<CompositeRRect>& node, const SkScalar& radius) { |
Florin Malita | fbc13f1 | 2018-01-04 10:26:35 -0500 | [diff] [blame] | 164 | node->setRadius(SkSize::Make(radius, radius)); |
| 165 | }); |
Florin Malita | 2e1d7e2 | 2018-01-02 10:40:00 -0500 | [diff] [blame] | 166 | |
| 167 | if (!p_attached && !s_attached && !r_attached) { |
| 168 | return nullptr; |
| 169 | } |
| 170 | |
Florin Malita | fbc13f1 | 2018-01-04 10:26:35 -0500 | [diff] [blame] | 171 | LOG("** Attached (r)rect geometry\n"); |
| 172 | |
| 173 | return rect_node; |
| 174 | } |
| 175 | |
| 176 | sk_sp<sksg::GeometryNode> AttachEllipseGeometry(const Json::Value& jellipse, AttachContext* ctx) { |
| 177 | SkASSERT(jellipse.isObject()); |
| 178 | |
| 179 | auto rect_node = sksg::RRect::Make(); |
| 180 | auto composite = sk_make_sp<CompositeRRect>(rect_node); |
| 181 | |
| 182 | auto p_attached = AttachProperty<VectorValue, SkPoint>(jellipse["p"], ctx, composite, |
| 183 | [](const sk_sp<CompositeRRect>& node, const SkPoint& pos) { node->setPosition(pos); }); |
| 184 | auto s_attached = AttachProperty<VectorValue, SkSize>(jellipse["s"], ctx, composite, |
| 185 | [](const sk_sp<CompositeRRect>& node, const SkSize& sz) { |
| 186 | node->setSize(sz); |
| 187 | node->setRadius(SkSize::Make(sz.width() / 2, sz.height() / 2)); |
| 188 | }); |
| 189 | |
| 190 | if (!p_attached && !s_attached) { |
| 191 | return nullptr; |
| 192 | } |
| 193 | |
| 194 | LOG("** Attached ellipse geometry\n"); |
| 195 | |
Florin Malita | 2e1d7e2 | 2018-01-02 10:40:00 -0500 | [diff] [blame] | 196 | return rect_node; |
| 197 | } |
| 198 | |
Florin Malita | 02a32b0 | 2018-01-04 11:27:09 -0500 | [diff] [blame] | 199 | sk_sp<sksg::GeometryNode> AttachPolystarGeometry(const Json::Value& jstar, AttachContext* ctx) { |
| 200 | SkASSERT(jstar.isObject()); |
| 201 | |
| 202 | static constexpr CompositePolyStar::Type gTypes[] = { |
| 203 | CompositePolyStar::Type::kStar, // "sy": 1 |
| 204 | CompositePolyStar::Type::kPoly, // "sy": 2 |
| 205 | }; |
| 206 | |
| 207 | const auto type = ParseInt(jstar["sy"], 0) - 1; |
| 208 | if (type < 0 || type >= SkTo<int>(SK_ARRAY_COUNT(gTypes))) { |
| 209 | LogFail(jstar, "Unknown polystar type"); |
| 210 | return nullptr; |
| 211 | } |
| 212 | |
| 213 | auto path_node = sksg::Path::Make(); |
| 214 | auto composite = sk_make_sp<CompositePolyStar>(path_node, gTypes[type]); |
| 215 | |
| 216 | AttachProperty<VectorValue, SkPoint>(jstar["p"], ctx, composite, |
| 217 | [](const sk_sp<CompositePolyStar>& node, const SkPoint& p) { node->setPosition(p); }); |
| 218 | AttachProperty<ScalarValue, SkScalar>(jstar["pt"], ctx, composite, |
Florin Malita | 9661b98 | 2018-01-06 14:25:49 -0500 | [diff] [blame^] | 219 | [](const sk_sp<CompositePolyStar>& node, const SkScalar& pt) { node->setPointCount(pt); }); |
Florin Malita | 02a32b0 | 2018-01-04 11:27:09 -0500 | [diff] [blame] | 220 | AttachProperty<ScalarValue, SkScalar>(jstar["ir"], ctx, composite, |
Florin Malita | 9661b98 | 2018-01-06 14:25:49 -0500 | [diff] [blame^] | 221 | [](const sk_sp<CompositePolyStar>& node, const SkScalar& ir) { node->setInnerRadius(ir); }); |
Florin Malita | 02a32b0 | 2018-01-04 11:27:09 -0500 | [diff] [blame] | 222 | AttachProperty<ScalarValue, SkScalar>(jstar["or"], ctx, composite, |
Florin Malita | 9661b98 | 2018-01-06 14:25:49 -0500 | [diff] [blame^] | 223 | [](const sk_sp<CompositePolyStar>& node, const SkScalar& otr) { |
| 224 | node->setOuterRadius(otr); |
| 225 | }); |
Florin Malita | 02a32b0 | 2018-01-04 11:27:09 -0500 | [diff] [blame] | 226 | AttachProperty<ScalarValue, SkScalar>(jstar["is"], ctx, composite, |
Florin Malita | 9661b98 | 2018-01-06 14:25:49 -0500 | [diff] [blame^] | 227 | [](const sk_sp<CompositePolyStar>& node, const SkScalar& is) { |
| 228 | node->setInnerRoundness(is); |
| 229 | }); |
Florin Malita | 02a32b0 | 2018-01-04 11:27:09 -0500 | [diff] [blame] | 230 | AttachProperty<ScalarValue, SkScalar>(jstar["os"], ctx, composite, |
Florin Malita | 9661b98 | 2018-01-06 14:25:49 -0500 | [diff] [blame^] | 231 | [](const sk_sp<CompositePolyStar>& node, const SkScalar& os) { |
| 232 | node->setOuterRoundness(os); |
| 233 | }); |
Florin Malita | 02a32b0 | 2018-01-04 11:27:09 -0500 | [diff] [blame] | 234 | AttachProperty<ScalarValue, SkScalar>(jstar["r"], ctx, composite, |
Florin Malita | 9661b98 | 2018-01-06 14:25:49 -0500 | [diff] [blame^] | 235 | [](const sk_sp<CompositePolyStar>& node, const SkScalar& r) { node->setRotation(r); }); |
Florin Malita | 02a32b0 | 2018-01-04 11:27:09 -0500 | [diff] [blame] | 236 | |
| 237 | return path_node; |
| 238 | } |
| 239 | |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 240 | sk_sp<sksg::Color> AttachColorPaint(const Json::Value& obj, AttachContext* ctx) { |
| 241 | SkASSERT(obj.isObject()); |
| 242 | |
| 243 | auto color_node = sksg::Color::Make(SK_ColorBLACK); |
| 244 | color_node->setAntiAlias(true); |
| 245 | |
| 246 | auto color_attached = AttachProperty<VectorValue, SkColor>(obj["c"], ctx, color_node, |
Florin Malita | 9661b98 | 2018-01-06 14:25:49 -0500 | [diff] [blame^] | 247 | [](const sk_sp<sksg::Color>& node, const SkColor& c) { node->setColor(c); }); |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 248 | |
| 249 | return color_attached ? color_node : nullptr; |
| 250 | } |
| 251 | |
| 252 | sk_sp<sksg::PaintNode> AttachFillPaint(const Json::Value& jfill, AttachContext* ctx) { |
| 253 | SkASSERT(jfill.isObject()); |
| 254 | |
| 255 | auto color = AttachColorPaint(jfill, ctx); |
| 256 | if (color) { |
| 257 | LOG("** Attached color fill: 0x%x\n", color->getColor()); |
| 258 | } |
| 259 | return color; |
| 260 | } |
| 261 | |
| 262 | sk_sp<sksg::PaintNode> AttachStrokePaint(const Json::Value& jstroke, AttachContext* ctx) { |
| 263 | SkASSERT(jstroke.isObject()); |
| 264 | |
| 265 | auto stroke_node = AttachColorPaint(jstroke, ctx); |
| 266 | if (!stroke_node) |
| 267 | return nullptr; |
| 268 | |
| 269 | LOG("** Attached color stroke: 0x%x\n", stroke_node->getColor()); |
| 270 | |
| 271 | stroke_node->setStyle(SkPaint::kStroke_Style); |
| 272 | |
| 273 | auto width_attached = AttachProperty<ScalarValue, SkScalar>(jstroke["w"], ctx, stroke_node, |
Florin Malita | 9661b98 | 2018-01-06 14:25:49 -0500 | [diff] [blame^] | 274 | [](const sk_sp<sksg::Color>& node, const SkScalar& width) { node->setStrokeWidth(width); }); |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 275 | if (!width_attached) |
| 276 | return nullptr; |
| 277 | |
| 278 | stroke_node->setStrokeMiter(ParseScalar(jstroke["ml"], 4)); |
| 279 | |
| 280 | static constexpr SkPaint::Join gJoins[] = { |
| 281 | SkPaint::kMiter_Join, |
| 282 | SkPaint::kRound_Join, |
| 283 | SkPaint::kBevel_Join, |
| 284 | }; |
| 285 | stroke_node->setStrokeJoin(gJoins[SkTPin<int>(ParseInt(jstroke["lj"], 1) - 1, |
| 286 | 0, SK_ARRAY_COUNT(gJoins) - 1)]); |
| 287 | |
| 288 | static constexpr SkPaint::Cap gCaps[] = { |
| 289 | SkPaint::kButt_Cap, |
| 290 | SkPaint::kRound_Cap, |
| 291 | SkPaint::kSquare_Cap, |
| 292 | }; |
| 293 | stroke_node->setStrokeCap(gCaps[SkTPin<int>(ParseInt(jstroke["lc"], 1) - 1, |
| 294 | 0, SK_ARRAY_COUNT(gCaps) - 1)]); |
| 295 | |
| 296 | return stroke_node; |
| 297 | } |
| 298 | |
Florin Malita | e6345d9 | 2018-01-03 23:37:54 -0500 | [diff] [blame] | 299 | std::vector<sk_sp<sksg::GeometryNode>> AttachMergeGeometryEffect( |
| 300 | const Json::Value& jmerge, AttachContext* ctx, std::vector<sk_sp<sksg::GeometryNode>>&& geos) { |
| 301 | std::vector<sk_sp<sksg::GeometryNode>> merged; |
| 302 | |
| 303 | static constexpr sksg::Merge::Mode gModes[] = { |
| 304 | sksg::Merge::Mode::kMerge, // "mm": 1 |
| 305 | sksg::Merge::Mode::kUnion, // "mm": 2 |
| 306 | sksg::Merge::Mode::kDifference, // "mm": 3 |
| 307 | sksg::Merge::Mode::kIntersect, // "mm": 4 |
| 308 | sksg::Merge::Mode::kXOR , // "mm": 5 |
| 309 | }; |
| 310 | |
| 311 | const auto mode = gModes[SkTPin<int>(ParseInt(jmerge["mm"], 1) - 1, 0, SK_ARRAY_COUNT(gModes))]; |
| 312 | merged.push_back(sksg::Merge::Make(std::move(geos), mode)); |
| 313 | |
| 314 | LOG("** Attached merge path effect, mode: %d\n", mode); |
| 315 | |
| 316 | return merged; |
| 317 | } |
| 318 | |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 319 | using GeometryAttacherT = sk_sp<sksg::GeometryNode> (*)(const Json::Value&, AttachContext*); |
| 320 | static constexpr GeometryAttacherT gGeometryAttachers[] = { |
| 321 | AttachPathGeometry, |
Florin Malita | 2e1d7e2 | 2018-01-02 10:40:00 -0500 | [diff] [blame] | 322 | AttachRRectGeometry, |
Florin Malita | fbc13f1 | 2018-01-04 10:26:35 -0500 | [diff] [blame] | 323 | AttachEllipseGeometry, |
Florin Malita | 02a32b0 | 2018-01-04 11:27:09 -0500 | [diff] [blame] | 324 | AttachPolystarGeometry, |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 325 | }; |
| 326 | |
| 327 | using PaintAttacherT = sk_sp<sksg::PaintNode> (*)(const Json::Value&, AttachContext*); |
| 328 | static constexpr PaintAttacherT gPaintAttachers[] = { |
| 329 | AttachFillPaint, |
| 330 | AttachStrokePaint, |
| 331 | }; |
| 332 | |
| 333 | using GroupAttacherT = sk_sp<sksg::RenderNode> (*)(const Json::Value&, AttachContext*); |
| 334 | static constexpr GroupAttacherT gGroupAttachers[] = { |
| 335 | AttachShapeGroup, |
| 336 | }; |
| 337 | |
Florin Malita | e6345d9 | 2018-01-03 23:37:54 -0500 | [diff] [blame] | 338 | using GeometryEffectAttacherT = |
| 339 | std::vector<sk_sp<sksg::GeometryNode>> (*)(const Json::Value&, |
| 340 | AttachContext*, |
| 341 | std::vector<sk_sp<sksg::GeometryNode>>&&); |
| 342 | static constexpr GeometryEffectAttacherT gGeometryEffectAttachers[] = { |
| 343 | AttachMergeGeometryEffect, |
| 344 | }; |
| 345 | |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 346 | enum class ShapeType { |
| 347 | kGeometry, |
Florin Malita | e6345d9 | 2018-01-03 23:37:54 -0500 | [diff] [blame] | 348 | kGeometryEffect, |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 349 | kPaint, |
| 350 | kGroup, |
Florin Malita | dacc02b | 2017-12-31 09:12:31 -0500 | [diff] [blame] | 351 | kTransform, |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 352 | }; |
| 353 | |
| 354 | struct ShapeInfo { |
| 355 | const char* fTypeString; |
| 356 | ShapeType fShapeType; |
| 357 | uint32_t fAttacherIndex; // index into respective attacher tables |
| 358 | }; |
| 359 | |
| 360 | const ShapeInfo* FindShapeInfo(const Json::Value& shape) { |
| 361 | static constexpr ShapeInfo gShapeInfo[] = { |
Florin Malita | fbc13f1 | 2018-01-04 10:26:35 -0500 | [diff] [blame] | 362 | { "el", ShapeType::kGeometry , 2 }, // ellipse -> AttachEllipseGeometry |
Florin Malita | e6345d9 | 2018-01-03 23:37:54 -0500 | [diff] [blame] | 363 | { "fl", ShapeType::kPaint , 0 }, // fill -> AttachFillPaint |
| 364 | { "gr", ShapeType::kGroup , 0 }, // group -> AttachShapeGroup |
| 365 | { "mm", ShapeType::kGeometryEffect, 0 }, // merge -> AttachMergeGeometryEffect |
Florin Malita | 02a32b0 | 2018-01-04 11:27:09 -0500 | [diff] [blame] | 366 | { "rc", ShapeType::kGeometry , 1 }, // rrect -> AttachRRectGeometry |
Florin Malita | e6345d9 | 2018-01-03 23:37:54 -0500 | [diff] [blame] | 367 | { "sh", ShapeType::kGeometry , 0 }, // shape -> AttachPathGeometry |
Florin Malita | 02a32b0 | 2018-01-04 11:27:09 -0500 | [diff] [blame] | 368 | { "sr", ShapeType::kGeometry , 3 }, // polystar -> AttachPolyStarGeometry |
Florin Malita | e6345d9 | 2018-01-03 23:37:54 -0500 | [diff] [blame] | 369 | { "st", ShapeType::kPaint , 1 }, // stroke -> AttachStrokePaint |
Florin Malita | 18eafd9 | 2018-01-04 21:11:55 -0500 | [diff] [blame] | 370 | { "tr", ShapeType::kTransform , 0 }, // transform -> In-place handler |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 371 | }; |
| 372 | |
| 373 | if (!shape.isObject()) |
| 374 | return nullptr; |
| 375 | |
| 376 | const auto& type = shape["ty"]; |
| 377 | if (!type.isString()) |
| 378 | return nullptr; |
| 379 | |
| 380 | const auto* info = bsearch(type.asCString(), |
| 381 | gShapeInfo, |
| 382 | SK_ARRAY_COUNT(gShapeInfo), |
| 383 | sizeof(ShapeInfo), |
| 384 | [](const void* key, const void* info) { |
| 385 | return strcmp(static_cast<const char*>(key), |
| 386 | static_cast<const ShapeInfo*>(info)->fTypeString); |
| 387 | }); |
| 388 | |
| 389 | return static_cast<const ShapeInfo*>(info); |
| 390 | } |
| 391 | |
| 392 | sk_sp<sksg::RenderNode> AttachShape(const Json::Value& shapeArray, AttachContext* ctx) { |
| 393 | if (!shapeArray.isArray()) |
| 394 | return nullptr; |
| 395 | |
Florin Malita | 2a8275b | 2018-01-02 12:52:43 -0500 | [diff] [blame] | 396 | // (https://helpx.adobe.com/after-effects/using/overview-shape-layers-paths-vector.html#groups_and_render_order_for_shapes_and_shape_attributes) |
| 397 | // |
| 398 | // Render order for shapes within a shape layer |
| 399 | // |
| 400 | // The rules for rendering a shape layer are similar to the rules for rendering a composition |
| 401 | // that contains nested compositions: |
| 402 | // |
| 403 | // * Within a group, the shape at the bottom of the Timeline panel stacking order is rendered |
| 404 | // first. |
| 405 | // |
| 406 | // * All path operations within a group are performed before paint operations. This means, |
| 407 | // for example, that the stroke follows the distortions in the path made by the Wiggle Paths |
| 408 | // path operation. Path operations within a group are performed from top to bottom. |
| 409 | // |
| 410 | // * Paint operations within a group are performed from the bottom to the top in the Timeline |
| 411 | // panel stacking order. This means, for example, that a stroke is rendered on top of |
| 412 | // (in front of) a stroke that appears after it in the Timeline panel. |
| 413 | // |
Florin Malita | dacc02b | 2017-12-31 09:12:31 -0500 | [diff] [blame] | 414 | sk_sp<sksg::Group> shape_group = sksg::Group::Make(); |
| 415 | sk_sp<sksg::RenderNode> xformed_group = shape_group; |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 416 | |
Florin Malita | e6345d9 | 2018-01-03 23:37:54 -0500 | [diff] [blame] | 417 | std::vector<sk_sp<sksg::GeometryNode>> geos; |
| 418 | std::vector<sk_sp<sksg::RenderNode>> draws; |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 419 | |
| 420 | for (const auto& s : shapeArray) { |
| 421 | const auto* info = FindShapeInfo(s); |
| 422 | if (!info) { |
| 423 | LogFail(s.isObject() ? s["ty"] : s, "Unknown shape"); |
| 424 | continue; |
| 425 | } |
| 426 | |
| 427 | switch (info->fShapeType) { |
| 428 | case ShapeType::kGeometry: { |
| 429 | SkASSERT(info->fAttacherIndex < SK_ARRAY_COUNT(gGeometryAttachers)); |
| 430 | if (auto geo = gGeometryAttachers[info->fAttacherIndex](s, ctx)) { |
| 431 | geos.push_back(std::move(geo)); |
| 432 | } |
| 433 | } break; |
Florin Malita | e6345d9 | 2018-01-03 23:37:54 -0500 | [diff] [blame] | 434 | case ShapeType::kGeometryEffect: { |
| 435 | SkASSERT(info->fAttacherIndex < SK_ARRAY_COUNT(gGeometryEffectAttachers)); |
| 436 | geos = gGeometryEffectAttachers[info->fAttacherIndex](s, ctx, std::move(geos)); |
| 437 | } break; |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 438 | case ShapeType::kPaint: { |
| 439 | SkASSERT(info->fAttacherIndex < SK_ARRAY_COUNT(gPaintAttachers)); |
| 440 | if (auto paint = gPaintAttachers[info->fAttacherIndex](s, ctx)) { |
Florin Malita | 2a8275b | 2018-01-02 12:52:43 -0500 | [diff] [blame] | 441 | for (const auto& geo : geos) { |
| 442 | draws.push_back(sksg::Draw::Make(geo, paint)); |
| 443 | } |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 444 | } |
| 445 | } break; |
| 446 | case ShapeType::kGroup: { |
| 447 | SkASSERT(info->fAttacherIndex < SK_ARRAY_COUNT(gGroupAttachers)); |
| 448 | if (auto group = gGroupAttachers[info->fAttacherIndex](s, ctx)) { |
Florin Malita | 2a8275b | 2018-01-02 12:52:43 -0500 | [diff] [blame] | 449 | draws.push_back(std::move(group)); |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 450 | } |
| 451 | } break; |
Florin Malita | dacc02b | 2017-12-31 09:12:31 -0500 | [diff] [blame] | 452 | case ShapeType::kTransform: { |
Florin Malita | 2a8275b | 2018-01-02 12:52:43 -0500 | [diff] [blame] | 453 | // TODO: BM appears to transform the geometry, not the draw op itself. |
Florin Malita | 18eafd9 | 2018-01-04 21:11:55 -0500 | [diff] [blame] | 454 | if (auto matrix = AttachMatrix(s, ctx, nullptr)) { |
| 455 | xformed_group = sksg::Transform::Make(std::move(xformed_group), |
| 456 | std::move(matrix)); |
| 457 | } |
Florin Malita | dacc02b | 2017-12-31 09:12:31 -0500 | [diff] [blame] | 458 | } break; |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 459 | } |
| 460 | } |
| 461 | |
Florin Malita | 2a8275b | 2018-01-02 12:52:43 -0500 | [diff] [blame] | 462 | if (draws.empty()) { |
| 463 | return nullptr; |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 464 | } |
| 465 | |
Florin Malita | e6345d9 | 2018-01-03 23:37:54 -0500 | [diff] [blame] | 466 | for (auto draw = draws.rbegin(); draw != draws.rend(); ++draw) { |
| 467 | shape_group->addChild(std::move(*draw)); |
Florin Malita | 2a8275b | 2018-01-02 12:52:43 -0500 | [diff] [blame] | 468 | } |
| 469 | |
Florin Malita | e6345d9 | 2018-01-03 23:37:54 -0500 | [diff] [blame] | 470 | LOG("** Attached shape: %zd draws.\n", draws.size()); |
Florin Malita | dacc02b | 2017-12-31 09:12:31 -0500 | [diff] [blame] | 471 | return xformed_group; |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | sk_sp<sksg::RenderNode> AttachCompLayer(const Json::Value& layer, AttachContext* ctx) { |
| 475 | SkASSERT(layer.isObject()); |
| 476 | |
| 477 | auto refId = ParseString(layer["refId"], ""); |
| 478 | if (refId.isEmpty()) { |
| 479 | LOG("!! Comp layer missing refId\n"); |
| 480 | return nullptr; |
| 481 | } |
| 482 | |
| 483 | const auto* comp = ctx->fAssets.find(refId); |
| 484 | if (!comp) { |
| 485 | LOG("!! Pre-comp not found: '%s'\n", refId.c_str()); |
| 486 | return nullptr; |
| 487 | } |
| 488 | |
| 489 | // TODO: cycle detection |
| 490 | return AttachComposition(**comp, ctx); |
| 491 | } |
| 492 | |
| 493 | sk_sp<sksg::RenderNode> AttachSolidLayer(const Json::Value& layer, AttachContext*) { |
| 494 | SkASSERT(layer.isObject()); |
| 495 | |
| 496 | LOG("?? Solid layer stub\n"); |
| 497 | return nullptr; |
| 498 | } |
| 499 | |
| 500 | sk_sp<sksg::RenderNode> AttachImageLayer(const Json::Value& layer, AttachContext*) { |
| 501 | SkASSERT(layer.isObject()); |
| 502 | |
| 503 | LOG("?? Image layer stub\n"); |
| 504 | return nullptr; |
| 505 | } |
| 506 | |
| 507 | sk_sp<sksg::RenderNode> AttachNullLayer(const Json::Value& layer, AttachContext*) { |
| 508 | SkASSERT(layer.isObject()); |
| 509 | |
Florin Malita | 18eafd9 | 2018-01-04 21:11:55 -0500 | [diff] [blame] | 510 | // Null layers are used solely to drive dependent transforms, |
| 511 | // but we use free-floating sksg::Matrices for that purpose. |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 512 | return nullptr; |
| 513 | } |
| 514 | |
| 515 | sk_sp<sksg::RenderNode> AttachShapeLayer(const Json::Value& layer, AttachContext* ctx) { |
| 516 | SkASSERT(layer.isObject()); |
| 517 | |
| 518 | LOG("** Attaching shape layer ind: %d\n", ParseInt(layer["ind"], 0)); |
| 519 | |
| 520 | return AttachShape(layer["shapes"], ctx); |
| 521 | } |
| 522 | |
| 523 | sk_sp<sksg::RenderNode> AttachTextLayer(const Json::Value& layer, AttachContext*) { |
| 524 | SkASSERT(layer.isObject()); |
| 525 | |
| 526 | LOG("?? Text layer stub\n"); |
| 527 | return nullptr; |
| 528 | } |
| 529 | |
Florin Malita | 18eafd9 | 2018-01-04 21:11:55 -0500 | [diff] [blame] | 530 | struct AttachLayerContext { |
| 531 | AttachLayerContext(const Json::Value& jlayers, AttachContext* ctx) |
| 532 | : fLayerList(jlayers), fCtx(ctx) {} |
| 533 | |
| 534 | const Json::Value& fLayerList; |
| 535 | AttachContext* fCtx; |
| 536 | std::unordered_map<const Json::Value*, sk_sp<sksg::Matrix>> fLayerMatrixCache; |
| 537 | std::unordered_map<int, const Json::Value*> fLayerIndexCache; |
| 538 | |
| 539 | const Json::Value* findLayer(int index) { |
| 540 | SkASSERT(fLayerList.isArray()); |
| 541 | |
| 542 | if (index < 0) { |
| 543 | return nullptr; |
| 544 | } |
| 545 | |
| 546 | const auto cached = fLayerIndexCache.find(index); |
| 547 | if (cached != fLayerIndexCache.end()) { |
| 548 | return cached->second; |
| 549 | } |
| 550 | |
| 551 | for (const auto& l : fLayerList) { |
| 552 | if (!l.isObject()) { |
| 553 | continue; |
| 554 | } |
| 555 | |
| 556 | if (ParseInt(l["ind"], -1) == index) { |
| 557 | fLayerIndexCache.insert(std::make_pair(index, &l)); |
| 558 | return &l; |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | return nullptr; |
| 563 | } |
| 564 | |
| 565 | sk_sp<sksg::Matrix> AttachLayerMatrix(const Json::Value& jlayer) { |
| 566 | SkASSERT(jlayer.isObject()); |
| 567 | |
| 568 | const auto cached = fLayerMatrixCache.find(&jlayer); |
| 569 | if (cached != fLayerMatrixCache.end()) { |
| 570 | return cached->second; |
| 571 | } |
| 572 | |
| 573 | const auto* parentLayer = this->findLayer(ParseInt(jlayer["parent"], -1)); |
| 574 | |
| 575 | // TODO: cycle detection? |
| 576 | auto parentMatrix = (parentLayer && parentLayer != &jlayer) |
| 577 | ? this->AttachLayerMatrix(*parentLayer) : nullptr; |
| 578 | |
| 579 | auto layerMatrix = AttachMatrix(jlayer["ks"], fCtx, std::move(parentMatrix)); |
| 580 | fLayerMatrixCache.insert(std::make_pair(&jlayer, layerMatrix)); |
| 581 | |
| 582 | return layerMatrix; |
| 583 | } |
| 584 | }; |
| 585 | |
| 586 | sk_sp<sksg::RenderNode> AttachLayer(const Json::Value& jlayer, |
| 587 | AttachLayerContext* layerCtx) { |
| 588 | if (!jlayer.isObject()) |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 589 | return nullptr; |
| 590 | |
| 591 | using LayerAttacher = sk_sp<sksg::RenderNode> (*)(const Json::Value&, AttachContext*); |
| 592 | static constexpr LayerAttacher gLayerAttachers[] = { |
| 593 | AttachCompLayer, // 'ty': 0 |
| 594 | AttachSolidLayer, // 'ty': 1 |
| 595 | AttachImageLayer, // 'ty': 2 |
| 596 | AttachNullLayer, // 'ty': 3 |
| 597 | AttachShapeLayer, // 'ty': 4 |
| 598 | AttachTextLayer, // 'ty': 5 |
| 599 | }; |
| 600 | |
Florin Malita | 18eafd9 | 2018-01-04 21:11:55 -0500 | [diff] [blame] | 601 | int type = ParseInt(jlayer["ty"], -1); |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 602 | if (type < 0 || type >= SkTo<int>(SK_ARRAY_COUNT(gLayerAttachers))) { |
| 603 | return nullptr; |
| 604 | } |
| 605 | |
Florin Malita | 18eafd9 | 2018-01-04 21:11:55 -0500 | [diff] [blame] | 606 | auto layer = gLayerAttachers[type](jlayer, layerCtx->fCtx); |
| 607 | auto layerMatrix = layerCtx->AttachLayerMatrix(jlayer); |
| 608 | |
| 609 | return layerMatrix |
| 610 | ? sksg::Transform::Make(std::move(layer), std::move(layerMatrix)) |
| 611 | : layer; |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 612 | } |
| 613 | |
| 614 | sk_sp<sksg::RenderNode> AttachComposition(const Json::Value& comp, AttachContext* ctx) { |
| 615 | if (!comp.isObject()) |
| 616 | return nullptr; |
| 617 | |
Florin Malita | 18eafd9 | 2018-01-04 21:11:55 -0500 | [diff] [blame] | 618 | const auto& jlayers = comp["layers"]; |
| 619 | if (!jlayers.isArray()) |
| 620 | return nullptr; |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 621 | |
Florin Malita | 18eafd9 | 2018-01-04 21:11:55 -0500 | [diff] [blame] | 622 | SkSTArray<16, sk_sp<sksg::RenderNode>, true> layers; |
| 623 | AttachLayerContext layerCtx(jlayers, ctx); |
| 624 | |
| 625 | for (const auto& l : jlayers) { |
| 626 | if (auto layer_fragment = AttachLayer(l, &layerCtx)) { |
Florin Malita | 2a8275b | 2018-01-02 12:52:43 -0500 | [diff] [blame] | 627 | layers.push_back(std::move(layer_fragment)); |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 628 | } |
| 629 | } |
| 630 | |
Florin Malita | 2a8275b | 2018-01-02 12:52:43 -0500 | [diff] [blame] | 631 | if (layers.empty()) { |
| 632 | return nullptr; |
| 633 | } |
| 634 | |
| 635 | // Layers are painted in bottom->top order. |
| 636 | auto comp_group = sksg::Group::Make(); |
| 637 | for (int i = layers.count() - 1; i >= 0; --i) { |
| 638 | comp_group->addChild(std::move(layers[i])); |
| 639 | } |
| 640 | |
| 641 | LOG("** Attached composition '%s': %d layers.\n", |
| 642 | ParseString(comp["id"], "").c_str(), layers.count()); |
| 643 | |
Florin Malita | 094ccde | 2017-12-30 12:27:00 -0500 | [diff] [blame] | 644 | return comp_group; |
| 645 | } |
| 646 | |
| 647 | } // namespace |
| 648 | |
| 649 | std::unique_ptr<Animation> Animation::Make(SkStream* stream) { |
| 650 | if (!stream->hasLength()) { |
| 651 | // TODO: handle explicit buffering? |
| 652 | LOG("!! cannot parse streaming content\n"); |
| 653 | return nullptr; |
| 654 | } |
| 655 | |
| 656 | Json::Value json; |
| 657 | { |
| 658 | auto data = SkData::MakeFromStream(stream, stream->getLength()); |
| 659 | if (!data) { |
| 660 | LOG("!! could not read stream\n"); |
| 661 | return nullptr; |
| 662 | } |
| 663 | |
| 664 | Json::Reader reader; |
| 665 | |
| 666 | auto dataStart = static_cast<const char*>(data->data()); |
| 667 | if (!reader.parse(dataStart, dataStart + data->size(), json, false) || !json.isObject()) { |
| 668 | LOG("!! failed to parse json: %s\n", reader.getFormattedErrorMessages().c_str()); |
| 669 | return nullptr; |
| 670 | } |
| 671 | } |
| 672 | |
| 673 | const auto version = ParseString(json["v"], ""); |
| 674 | const auto size = SkSize::Make(ParseScalar(json["w"], -1), ParseScalar(json["h"], -1)); |
| 675 | const auto fps = ParseScalar(json["fr"], -1); |
| 676 | |
| 677 | if (size.isEmpty() || version.isEmpty() || fps < 0) { |
| 678 | LOG("!! invalid animation params (version: %s, size: [%f %f], frame rate: %f)", |
| 679 | version.c_str(), size.width(), size.height(), fps); |
| 680 | return nullptr; |
| 681 | } |
| 682 | |
| 683 | return std::unique_ptr<Animation>(new Animation(std::move(version), size, fps, json)); |
| 684 | } |
| 685 | |
| 686 | Animation::Animation(SkString version, const SkSize& size, SkScalar fps, const Json::Value& json) |
| 687 | : fVersion(std::move(version)) |
| 688 | , fSize(size) |
| 689 | , fFrameRate(fps) |
| 690 | , fInPoint(ParseScalar(json["ip"], 0)) |
| 691 | , fOutPoint(SkTMax(ParseScalar(json["op"], SK_ScalarMax), fInPoint)) { |
| 692 | |
| 693 | AssetMap assets; |
| 694 | for (const auto& asset : json["assets"]) { |
| 695 | if (!asset.isObject()) { |
| 696 | continue; |
| 697 | } |
| 698 | |
| 699 | assets.set(ParseString(asset["id"], ""), &asset); |
| 700 | } |
| 701 | |
| 702 | AttachContext ctx = { assets, fAnimators }; |
| 703 | fDom = AttachComposition(json, &ctx); |
| 704 | |
| 705 | LOG("** Attached %d animators\n", fAnimators.count()); |
| 706 | } |
| 707 | |
| 708 | Animation::~Animation() = default; |
| 709 | |
| 710 | void Animation::render(SkCanvas* canvas) const { |
| 711 | if (!fDom) |
| 712 | return; |
| 713 | |
| 714 | sksg::InvalidationController ic; |
| 715 | fDom->revalidate(&ic, SkMatrix::I()); |
| 716 | |
| 717 | // TODO: proper inval |
| 718 | fDom->render(canvas); |
| 719 | |
| 720 | if (!fShowInval) |
| 721 | return; |
| 722 | |
| 723 | SkPaint fill, stroke; |
| 724 | fill.setAntiAlias(true); |
| 725 | fill.setColor(0x40ff0000); |
| 726 | stroke.setAntiAlias(true); |
| 727 | stroke.setColor(0xffff0000); |
| 728 | stroke.setStyle(SkPaint::kStroke_Style); |
| 729 | |
| 730 | for (const auto& r : ic) { |
| 731 | canvas->drawRect(r, fill); |
| 732 | canvas->drawRect(r, stroke); |
| 733 | } |
| 734 | } |
| 735 | |
| 736 | void Animation::animationTick(SkMSec ms) { |
| 737 | // 't' in the BM model really means 'frame #' |
| 738 | auto t = static_cast<float>(ms) * fFrameRate / 1000; |
| 739 | |
| 740 | t = fInPoint + std::fmod(t, fOutPoint - fInPoint); |
| 741 | |
| 742 | // TODO: this can be optimized quite a bit with some sorting/state tracking. |
| 743 | for (const auto& a : fAnimators) { |
| 744 | a->tick(t); |
| 745 | } |
| 746 | } |
| 747 | |
| 748 | } // namespace skotty |