From 9661b98221146b379189da015103f692a5902c36 Mon Sep 17 00:00:00 2001 From: Florin Malita Date: Sat, 6 Jan 2018 14:25:49 -0500 Subject: [skotty] De-templatize the Animator apply function We can use a raw function pointer. TBR= Change-Id: I66d19ed563171dc314c862b35c3c98d462337f18 Reviewed-on: https://skia-review.googlesource.com/91461 Reviewed-by: Florin Malita Commit-Queue: Florin Malita --- experimental/skotty/Skotty.cpp | 34 ++++++++++++++++++++-------------- experimental/skotty/SkottyAnimator.h | 12 ++++++------ 2 files changed, 26 insertions(+), 20 deletions(-) (limited to 'experimental') diff --git a/experimental/skotty/Skotty.cpp b/experimental/skotty/Skotty.cpp index 3635c2c83b..8c48d1f871 100644 --- a/experimental/skotty/Skotty.cpp +++ b/experimental/skotty/Skotty.cpp @@ -53,9 +53,9 @@ bool LogFail(const Json::Value& json, const char* msg) { // This is the workhorse for binding properties: depending on whether the property is animated, // it will either apply immediately or instantiate and attach a keyframe animator. -template +template bool AttachProperty(const Json::Value& jprop, AttachContext* ctx, const sk_sp& node, - ApplyFuncT&& apply) { + typename Animator::ApplyFuncT&& apply) { if (!jprop.isObject()) return false; @@ -102,15 +102,15 @@ sk_sp AttachMatrix(const Json::Value& t, AttachContext* ctx, node->setScale(s); }); auto rotation_attached = AttachProperty(t["r"], ctx, composite, - [](const sk_sp& node, SkScalar r) { + [](const sk_sp& node, const SkScalar& r) { node->setRotation(r); }); auto skew_attached = AttachProperty(t["sk"], ctx, composite, - [](const sk_sp& node, SkScalar sk) { + [](const sk_sp& node, const SkScalar& sk) { node->setSkew(sk); }); auto skewaxis_attached = AttachProperty(t["sa"], ctx, composite, - [](const sk_sp& node, SkScalar sa) { + [](const sk_sp& node, const SkScalar& sa) { node->setSkewAxis(sa); }); @@ -160,7 +160,7 @@ sk_sp AttachRRectGeometry(const Json::Value& jrect, AttachCo auto s_attached = AttachProperty(jrect["s"], ctx, composite, [](const sk_sp& node, const SkSize& sz) { node->setSize(sz); }); auto r_attached = AttachProperty(jrect["r"], ctx, composite, - [](const sk_sp& node, SkScalar radius) { + [](const sk_sp& node, const SkScalar& radius) { node->setRadius(SkSize::Make(radius, radius)); }); @@ -216,17 +216,23 @@ sk_sp AttachPolystarGeometry(const Json::Value& jstar, Attac AttachProperty(jstar["p"], ctx, composite, [](const sk_sp& node, const SkPoint& p) { node->setPosition(p); }); AttachProperty(jstar["pt"], ctx, composite, - [](const sk_sp& node, SkScalar pt) { node->setPointCount(pt); }); + [](const sk_sp& node, const SkScalar& pt) { node->setPointCount(pt); }); AttachProperty(jstar["ir"], ctx, composite, - [](const sk_sp& node, SkScalar ir) { node->setInnerRadius(ir); }); + [](const sk_sp& node, const SkScalar& ir) { node->setInnerRadius(ir); }); AttachProperty(jstar["or"], ctx, composite, - [](const sk_sp& node, SkScalar otr) { node->setOuterRadius(otr); }); + [](const sk_sp& node, const SkScalar& otr) { + node->setOuterRadius(otr); + }); AttachProperty(jstar["is"], ctx, composite, - [](const sk_sp& node, SkScalar is) { node->setInnerRoundness(is); }); + [](const sk_sp& node, const SkScalar& is) { + node->setInnerRoundness(is); + }); AttachProperty(jstar["os"], ctx, composite, - [](const sk_sp& node, SkScalar os) { node->setOuterRoundness(os); }); + [](const sk_sp& node, const SkScalar& os) { + node->setOuterRoundness(os); + }); AttachProperty(jstar["r"], ctx, composite, - [](const sk_sp& node, SkScalar r) { node->setRotation(r); }); + [](const sk_sp& node, const SkScalar& r) { node->setRotation(r); }); return path_node; } @@ -238,7 +244,7 @@ sk_sp AttachColorPaint(const Json::Value& obj, AttachContext* ctx) color_node->setAntiAlias(true); auto color_attached = AttachProperty(obj["c"], ctx, color_node, - [](const sk_sp& node, SkColor c) { node->setColor(c); }); + [](const sk_sp& node, const SkColor& c) { node->setColor(c); }); return color_attached ? color_node : nullptr; } @@ -265,7 +271,7 @@ sk_sp AttachStrokePaint(const Json::Value& jstroke, AttachConte stroke_node->setStyle(SkPaint::kStroke_Style); auto width_attached = AttachProperty(jstroke["w"], ctx, stroke_node, - [](const sk_sp& node, SkScalar width) { node->setStrokeWidth(width); }); + [](const sk_sp& node, const SkScalar& width) { node->setStrokeWidth(width); }); if (!width_attached) return nullptr; diff --git a/experimental/skotty/SkottyAnimator.h b/experimental/skotty/SkottyAnimator.h index 1b519c9aa6..0e5929334e 100644 --- a/experimental/skotty/SkottyAnimator.h +++ b/experimental/skotty/SkottyAnimator.h @@ -15,7 +15,6 @@ #include "SkTArray.h" #include "SkTypes.h" -#include #include namespace skotty { @@ -97,8 +96,9 @@ struct KeyframeInterval { template class Animator : public AnimatorBase { public: + using ApplyFuncT = void(*)(const sk_sp&, const AttrT&); static std::unique_ptr Make(const Json::Value& frames, sk_sp node, - std::function&, const AttrT&)> applyFunc); + ApplyFuncT&& applyFunc); void tick(SkMSec t) override { const auto& frame = this->findInterval(t); @@ -111,7 +111,7 @@ public: private: Animator(SkTArray>&& intervals, sk_sp node, - std::function&, const AttrT&)> applyFunc) + ApplyFuncT&& applyFunc) : fIntervals(std::move(intervals)) , fTarget(std::move(node)) , fFunc(std::move(applyFunc)) {} @@ -120,13 +120,13 @@ private: const SkTArray> fIntervals; sk_sp fTarget; - std::function&, const AttrT&)> fFunc; + ApplyFuncT fFunc; }; template std::unique_ptr> -Animator::Make(const Json::Value& frames, - sk_sp node, std::function&, const AttrT&)> applyFunc) { +Animator::Make(const Json::Value& frames, sk_sp node, + ApplyFuncT&& applyFunc) { if (!frames.isArray()) return nullptr; -- cgit v1.2.3