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