1/*
2 * Copyright 2020 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#ifndef SkottieAnimator_DEFINED
9#define SkottieAnimator_DEFINED
10
11#include "include/core/SkRefCnt.h"
12
13#include <vector>
14
15namespace skjson {
16
17class ObjectValue;
18
19} // namespace skjson
20
21namespace skottie {
22namespace internal {
23
24class AnimationBuilder;
25class KeyframeAnimatorBuilder;
26
27class Animator : public SkRefCnt {
28public:
29 virtual ~Animator() = default;
30
31 using StateChanged = bool;
32 StateChanged seek(float t) { return this->onSeek(t); }
33
34protected:
35 Animator() = default;
36
37 virtual StateChanged onSeek(float t) = 0;
38
39private:
40 Animator(const Animator&) = delete;
41 Animator& operator=(const Animator&) = delete;
42};
43
44class AnimatablePropertyContainer : public Animator {
45public:
46 // This is the workhorse for property binding: depending on whether the property is animated,
47 // it will either apply immediately or instantiate and attach a keyframe animator, scoped to
48 // this container.
49 template <typename T>
50 bool bind(const AnimationBuilder&, const skjson::ObjectValue*, T*);
51
52 template <typename T>
53 bool bind(const AnimationBuilder& abuilder, const skjson::ObjectValue* jobject, T& v) {
54 return this->bind<T>(abuilder, jobject, &v);
55 }
56
57 bool isStatic() const { return fAnimators.empty(); }
58
59protected:
60 virtual void onSync() = 0;
61
62 void shrink_to_fit();
63
64 void attachDiscardableAdapter(sk_sp<AnimatablePropertyContainer>);
65
66private:
67 StateChanged onSeek(float) final;
68
69 bool bindImpl(const AnimationBuilder&,
70 const skjson::ObjectValue*,
71 KeyframeAnimatorBuilder&,
72 void*);
73
74 std::vector<sk_sp<Animator>> fAnimators;
75 bool fHasSynced = false;
76};
77
78} // namespace internal
79} // namespace skottie
80
81#endif // SkottieAnimator_DEFINED
82