aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools
diff options
context:
space:
mode:
authorGravatar Florin Malita <fmalita@chromium.org>2018-01-31 18:35:05 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-02-01 00:28:32 +0000
commit22c528dccef2716d04bb2ee8906cb5ac17c5b09e (patch)
tree12d03cb99a5d9894c4609733869ef4a56828f96e /tools
parente2b300adcc1589e7008ab93c361f1d6b9409c411 (diff)
[skottie] Convert SkottieSlide2 to SkSceneGraph animators.
Instead of dispatching ticks explicitly, bind Animations to the Scene using ForwardingAnimator adaptors. TBR= Change-Id: I9faffed5c96157c781cc96729395b52d3f841e2b Reviewed-on: https://skia-review.googlesource.com/102500 Reviewed-by: Florin Malita <fmalita@chromium.org> Commit-Queue: Florin Malita <fmalita@chromium.org>
Diffstat (limited to 'tools')
-rw-r--r--tools/viewer/SkottieSlide.h4
-rw-r--r--tools/viewer/SkottieSlide2.cpp43
2 files changed, 33 insertions, 14 deletions
diff --git a/tools/viewer/SkottieSlide.h b/tools/viewer/SkottieSlide.h
index 44929d7be5..cbb70b2183 100644
--- a/tools/viewer/SkottieSlide.h
+++ b/tools/viewer/SkottieSlide.h
@@ -56,7 +56,6 @@ private:
struct Rec {
sk_sp<AnimationWrapper> fWrapper;
- SkMSec fTimeBase = 0;
bool fShowAnimationInval = false;
explicit Rec(sk_sp<AnimationWrapper>);
@@ -69,7 +68,8 @@ private:
SkTArray<Rec> fAnims;
std::unique_ptr<sksg::Scene> fScene;
- int fTrackingCell = -1;
+ SkMSec fTimeBase = 0;
+ int fTrackingCell = -1;
typedef Slide INHERITED;
};
diff --git a/tools/viewer/SkottieSlide2.cpp b/tools/viewer/SkottieSlide2.cpp
index 7b2c7c25a1..3eb723a0f4 100644
--- a/tools/viewer/SkottieSlide2.cpp
+++ b/tools/viewer/SkottieSlide2.cpp
@@ -9,6 +9,7 @@
#include "SkAnimTimer.h"
#include "SkCanvas.h"
+#include "SkMakeUnique.h"
#include "Skottie.h"
#include "SkOSFile.h"
#include "SkOSPath.h"
@@ -45,6 +46,22 @@ public:
void setShowInval(bool show) { fAnimation->setShowInval(show); }
+ // Trivial sksg::Animator -> skottie::Animation tick adapter
+ class ForwardingAnimator final : public sksg::Animator {
+ public:
+ ForwardingAnimator(sk_sp<AnimationWrapper> wrapper) : fWrapper(std::move(wrapper)) {}
+
+ protected:
+ void onTick(float t) override {
+ fWrapper->tick(SkScalarRoundToInt(t));
+ }
+
+ private:
+ sk_sp<AnimationWrapper> fWrapper;
+
+ using INHERITED = sksg::Animator;
+ };
+
protected:
SkRect onRevalidate(sksg::InvalidationController* ic, const SkMatrix& ctm) override {
return SkRect::MakeSize(fAnimation->size());
@@ -109,6 +126,7 @@ void SkottieSlide2::load(SkScalar, SkScalar) {
int x = 0, y = 0;
auto scene_root = sksg::Group::Make();
+ sksg::AnimatorList scene_animators;
while (iter.next(&name)) {
SkString path = SkOSPath::Join(fPath.c_str(), name.c_str());
@@ -117,16 +135,17 @@ void SkottieSlide2::load(SkScalar, SkScalar) {
dst = SkRect::MakeXYWH(MARGIN + x * (CELL_WIDTH + SPACER_X),
MARGIN + y * (CELL_HEIGHT + SPACER_Y),
CELL_WIDTH, CELL_HEIGHT);
- const auto m = SkMatrix::MakeRectToRect(src, dst, SkMatrix::kCenter_ScaleToFit);
-
- auto wrapper = sk_make_sp<AnimationWrapper>(std::move(anim));
+ const auto m = SkMatrix::MakeRectToRect(src, dst, SkMatrix::kCenter_ScaleToFit);
+ auto wrapper = sk_make_sp<AnimationWrapper>(std::move(anim));
+ auto group = sksg::Group::Make();
- auto group = sksg::Group::Make();
group->addChild(wrapper);
group->addChild(MakeLabel(name, src, m));
- auto xform = sksg::Transform::Make(std::move(group), m);
+ auto xform = sksg::Transform::Make(std::move(group), m);
+ scene_animators.push_back(
+ skstd::make_unique<AnimationWrapper::ForwardingAnimator>(wrapper));
scene_root->addChild(xform);
fAnims.emplace_back(std::move(wrapper));
@@ -137,12 +156,13 @@ void SkottieSlide2::load(SkScalar, SkScalar) {
}
}
- fScene = sksg::Scene::Make(std::move(scene_root), sksg::AnimatorList());
+ fScene = sksg::Scene::Make(std::move(scene_root), std::move(scene_animators));
}
void SkottieSlide2::unload() {
fAnims.reset();
fScene.reset();
+ fTimeBase = 0;
}
SkISize SkottieSlide2::getDimensions() const {
@@ -158,13 +178,12 @@ void SkottieSlide2::draw(SkCanvas* canvas) {
}
bool SkottieSlide2::animate(const SkAnimTimer& timer) {
- for (auto& rec : fAnims) {
- if (rec.fTimeBase == 0) {
- // Reset the animation time.
- rec.fTimeBase = timer.msec();
- }
- rec.fWrapper->tick(timer.msec() - rec.fTimeBase);
+ if (fTimeBase == 0) {
+ // Reset the animation time.
+ fTimeBase = timer.msec();
}
+ fScene->animate(timer.msec() - fTimeBase);
+
return true;
}