aboutsummaryrefslogtreecommitdiffhomepage
path: root/experimental
diff options
context:
space:
mode:
authorGravatar Florin Malita <fmalita@chromium.org>2018-01-06 14:25:49 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-01-07 13:43:08 +0000
commit9661b98221146b379189da015103f692a5902c36 (patch)
treeff75bd4335d0a2a43244225270cf99e769b880cd /experimental
parentca3dcd5b8de33bb78314be6b7403d0d7632f9cc3 (diff)
[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 <fmalita@chromium.org> Commit-Queue: Florin Malita <fmalita@chromium.org>
Diffstat (limited to 'experimental')
-rw-r--r--experimental/skotty/Skotty.cpp34
-rw-r--r--experimental/skotty/SkottyAnimator.h12
2 files changed, 26 insertions, 20 deletions
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 <typename ValueT, typename AttrT, typename NodeT, typename ApplyFuncT>
+template <typename ValueT, typename AttrT, typename NodeT>
bool AttachProperty(const Json::Value& jprop, AttachContext* ctx, const sk_sp<NodeT>& node,
- ApplyFuncT&& apply) {
+ typename Animator<ValueT, AttrT, NodeT>::ApplyFuncT&& apply) {
if (!jprop.isObject())
return false;
@@ -102,15 +102,15 @@ sk_sp<sksg::Matrix> AttachMatrix(const Json::Value& t, AttachContext* ctx,
node->setScale(s);
});
auto rotation_attached = AttachProperty<ScalarValue, SkScalar>(t["r"], ctx, composite,
- [](const sk_sp<CompositeTransform>& node, SkScalar r) {
+ [](const sk_sp<CompositeTransform>& node, const SkScalar& r) {
node->setRotation(r);
});
auto skew_attached = AttachProperty<ScalarValue, SkScalar>(t["sk"], ctx, composite,
- [](const sk_sp<CompositeTransform>& node, SkScalar sk) {
+ [](const sk_sp<CompositeTransform>& node, const SkScalar& sk) {
node->setSkew(sk);
});
auto skewaxis_attached = AttachProperty<ScalarValue, SkScalar>(t["sa"], ctx, composite,
- [](const sk_sp<CompositeTransform>& node, SkScalar sa) {
+ [](const sk_sp<CompositeTransform>& node, const SkScalar& sa) {
node->setSkewAxis(sa);
});
@@ -160,7 +160,7 @@ sk_sp<sksg::GeometryNode> AttachRRectGeometry(const Json::Value& jrect, AttachCo
auto s_attached = AttachProperty<VectorValue, SkSize>(jrect["s"], ctx, composite,
[](const sk_sp<CompositeRRect>& node, const SkSize& sz) { node->setSize(sz); });
auto r_attached = AttachProperty<ScalarValue, SkScalar>(jrect["r"], ctx, composite,
- [](const sk_sp<CompositeRRect>& node, SkScalar radius) {
+ [](const sk_sp<CompositeRRect>& node, const SkScalar& radius) {
node->setRadius(SkSize::Make(radius, radius));
});
@@ -216,17 +216,23 @@ sk_sp<sksg::GeometryNode> AttachPolystarGeometry(const Json::Value& jstar, Attac
AttachProperty<VectorValue, SkPoint>(jstar["p"], ctx, composite,
[](const sk_sp<CompositePolyStar>& node, const SkPoint& p) { node->setPosition(p); });
AttachProperty<ScalarValue, SkScalar>(jstar["pt"], ctx, composite,
- [](const sk_sp<CompositePolyStar>& node, SkScalar pt) { node->setPointCount(pt); });
+ [](const sk_sp<CompositePolyStar>& node, const SkScalar& pt) { node->setPointCount(pt); });
AttachProperty<ScalarValue, SkScalar>(jstar["ir"], ctx, composite,
- [](const sk_sp<CompositePolyStar>& node, SkScalar ir) { node->setInnerRadius(ir); });
+ [](const sk_sp<CompositePolyStar>& node, const SkScalar& ir) { node->setInnerRadius(ir); });
AttachProperty<ScalarValue, SkScalar>(jstar["or"], ctx, composite,
- [](const sk_sp<CompositePolyStar>& node, SkScalar otr) { node->setOuterRadius(otr); });
+ [](const sk_sp<CompositePolyStar>& node, const SkScalar& otr) {
+ node->setOuterRadius(otr);
+ });
AttachProperty<ScalarValue, SkScalar>(jstar["is"], ctx, composite,
- [](const sk_sp<CompositePolyStar>& node, SkScalar is) { node->setInnerRoundness(is); });
+ [](const sk_sp<CompositePolyStar>& node, const SkScalar& is) {
+ node->setInnerRoundness(is);
+ });
AttachProperty<ScalarValue, SkScalar>(jstar["os"], ctx, composite,
- [](const sk_sp<CompositePolyStar>& node, SkScalar os) { node->setOuterRoundness(os); });
+ [](const sk_sp<CompositePolyStar>& node, const SkScalar& os) {
+ node->setOuterRoundness(os);
+ });
AttachProperty<ScalarValue, SkScalar>(jstar["r"], ctx, composite,
- [](const sk_sp<CompositePolyStar>& node, SkScalar r) { node->setRotation(r); });
+ [](const sk_sp<CompositePolyStar>& node, const SkScalar& r) { node->setRotation(r); });
return path_node;
}
@@ -238,7 +244,7 @@ sk_sp<sksg::Color> AttachColorPaint(const Json::Value& obj, AttachContext* ctx)
color_node->setAntiAlias(true);
auto color_attached = AttachProperty<VectorValue, SkColor>(obj["c"], ctx, color_node,
- [](const sk_sp<sksg::Color>& node, SkColor c) { node->setColor(c); });
+ [](const sk_sp<sksg::Color>& node, const SkColor& c) { node->setColor(c); });
return color_attached ? color_node : nullptr;
}
@@ -265,7 +271,7 @@ sk_sp<sksg::PaintNode> AttachStrokePaint(const Json::Value& jstroke, AttachConte
stroke_node->setStyle(SkPaint::kStroke_Style);
auto width_attached = AttachProperty<ScalarValue, SkScalar>(jstroke["w"], ctx, stroke_node,
- [](const sk_sp<sksg::Color>& node, SkScalar width) { node->setStrokeWidth(width); });
+ [](const sk_sp<sksg::Color>& 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 <functional>
#include <memory>
namespace skotty {
@@ -97,8 +96,9 @@ struct KeyframeInterval {
template <typename ValT, typename AttrT, typename NodeT>
class Animator : public AnimatorBase {
public:
+ using ApplyFuncT = void(*)(const sk_sp<NodeT>&, const AttrT&);
static std::unique_ptr<Animator> Make(const Json::Value& frames, sk_sp<NodeT> node,
- std::function<void(const sk_sp<NodeT>&, const AttrT&)> applyFunc);
+ ApplyFuncT&& applyFunc);
void tick(SkMSec t) override {
const auto& frame = this->findInterval(t);
@@ -111,7 +111,7 @@ public:
private:
Animator(SkTArray<KeyframeInterval<ValT>>&& intervals, sk_sp<NodeT> node,
- std::function<void(const sk_sp<NodeT>&, const AttrT&)> applyFunc)
+ ApplyFuncT&& applyFunc)
: fIntervals(std::move(intervals))
, fTarget(std::move(node))
, fFunc(std::move(applyFunc)) {}
@@ -120,13 +120,13 @@ private:
const SkTArray<KeyframeInterval<ValT>> fIntervals;
sk_sp<NodeT> fTarget;
- std::function<void(const sk_sp<NodeT>&, const AttrT&)> fFunc;
+ ApplyFuncT fFunc;
};
template <typename ValT, typename AttrT, typename NodeT>
std::unique_ptr<Animator<ValT, AttrT, NodeT>>
-Animator<ValT, AttrT, NodeT>::Make(const Json::Value& frames,
- sk_sp<NodeT> node, std::function<void(const sk_sp<NodeT>&, const AttrT&)> applyFunc) {
+Animator<ValT, AttrT, NodeT>::Make(const Json::Value& frames, sk_sp<NodeT> node,
+ ApplyFuncT&& applyFunc) {
if (!frames.isArray())
return nullptr;