• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2018 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 SkSGScene_DEFINED
9 #define SkSGScene_DEFINED
10 
11 #include "SkRefCnt.h"
12 #include "SkTypes.h"
13 
14 #include <memory>
15 #include <vector>
16 
17 class SkCanvas;
18 
19 namespace sksg {
20 
21 class RenderNode;
22 
23 /**
24  * Base class for animators.
25  *
26  */
27 class Animator {
28 public:
29     virtual ~Animator();
30     Animator(const Animator&) = delete;
31     Animator& operator=(const Animator&) = delete;
32 
33     void tick(float t);
34 
35 protected:
36     Animator();
37 
38     virtual void onTick(float t) = 0;
39 };
40 
41 using AnimatorList = std::vector<std::unique_ptr<Animator>>;
42 
43 class GroupAnimator : public Animator {
44 protected:
45     explicit GroupAnimator(AnimatorList&&);
46 
47     void onTick(float t) override;
48 
49 private:
50     const AnimatorList fAnimators;
51 
52     using INHERITED = Animator;
53 };
54 
55 /**
56  * Holds a scene root and a list of animators.
57  *
58  * Provides high-level mehods for driving rendering and animations.
59  *
60  */
61 class Scene final {
62 public:
63     static std::unique_ptr<Scene> Make(sk_sp<RenderNode> root, AnimatorList&& animators);
64     ~Scene();
65     Scene(const Scene&) = delete;
66     Scene& operator=(const Scene&) = delete;
67 
68     void render(SkCanvas*) const;
69     void animate(float t);
70 
setShowInval(bool show)71     void setShowInval(bool show) { fShowInval = show; }
72 
73 private:
74     Scene(sk_sp<RenderNode> root, AnimatorList&& animators);
75 
76     const sk_sp<RenderNode> fRoot;
77     const AnimatorList      fAnimators;
78 
79     bool                    fShowInval = false;
80 };
81 
82 } // namespace sksg
83 
84 #endif // SkSGScene_DEFINED
85