• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "modules/sksg/include/SkSGScene.h"
12 
13 namespace skjson {
14 
15 class ObjectValue;
16 
17 } // namespace skjson
18 
19 namespace skottie {
20 namespace internal {
21 
22 class AnimationBuilder;
23 
24 class AnimatablePropertyContainer : public sksg::Animator {
25 public:
26     // This is the workhorse for property binding: depending on whether the property is animated,
27     // it will either apply immediately or instantiate and attach a keyframe animator, scoped to
28     // this container.
29     template <typename T>
30     bool bind(const AnimationBuilder&, const skjson::ObjectValue*, T*);
31 
32     template <typename T>
bind(const AnimationBuilder & abuilder,const skjson::ObjectValue * jobject,T & v)33     bool bind(const AnimationBuilder& abuilder, const skjson::ObjectValue* jobject, T& v) {
34         return this->bind<T>(abuilder, jobject, &v);
35     }
36 
isStatic()37     bool isStatic() const { return fAnimators.empty(); }
38 
39 protected:
40     virtual void onSync() = 0;
41 
42     void shrink_to_fit();
43 
44     void attachDiscardableAdapter(sk_sp<AnimatablePropertyContainer>);
45 
46 private:
47     void onTick(float) final;
48 
49     sksg::AnimatorList fAnimators;
50 };
51 
52 } // namespace internal
53 } // namespace skottie
54 
55 #endif // SkottieAnimator_DEFINED
56