Florin Malita | 35efaa8 | 2018-01-22 12:57:06 -0500 | [diff] [blame] | 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 : public SkNoncopyable { |
| 28 | public: |
| 29 | virtual ~Animator(); |
| 30 | |
| 31 | void tick(float t); |
| 32 | |
| 33 | protected: |
| 34 | Animator(); |
| 35 | |
| 36 | virtual void onTick(float t) = 0; |
| 37 | |
| 38 | private: |
| 39 | using INHERITED = SkNoncopyable; |
| 40 | }; |
| 41 | |
Florin Malita | cca86f3 | 2018-01-29 10:49:49 -0500 | [diff] [blame] | 42 | using AnimatorList = std::vector<std::unique_ptr<Animator>>; |
| 43 | |
| 44 | class GroupAnimator : public Animator { |
| 45 | protected: |
| 46 | explicit GroupAnimator(AnimatorList&&); |
| 47 | |
| 48 | void onTick(float t) override; |
| 49 | |
| 50 | private: |
| 51 | const AnimatorList fAnimators; |
| 52 | |
| 53 | using INHERITED = Animator; |
| 54 | }; |
| 55 | |
Florin Malita | 35efaa8 | 2018-01-22 12:57:06 -0500 | [diff] [blame] | 56 | /** |
| 57 | * Holds a scene root and a list of animators. |
| 58 | * |
| 59 | * Provides high-level mehods for driving rendering and animations. |
| 60 | * |
| 61 | */ |
| 62 | class Scene final : SkNoncopyable { |
| 63 | public: |
Florin Malita | 35efaa8 | 2018-01-22 12:57:06 -0500 | [diff] [blame] | 64 | static std::unique_ptr<Scene> Make(sk_sp<RenderNode> root, AnimatorList&& animators); |
| 65 | ~Scene(); |
| 66 | |
| 67 | void render(SkCanvas*) const; |
| 68 | void animate(float t); |
| 69 | |
| 70 | void setShowInval(bool show) { fShowInval = show; } |
| 71 | |
| 72 | private: |
| 73 | Scene(sk_sp<RenderNode> root, AnimatorList&& animators); |
| 74 | |
| 75 | const sk_sp<RenderNode> fRoot; |
| 76 | const AnimatorList fAnimators; |
| 77 | |
| 78 | bool fShowInval = false; |
| 79 | |
| 80 | using INHERITED = SkNoncopyable; |
| 81 | }; |
| 82 | |
| 83 | } // namespace sksg |
| 84 | |
| 85 | #endif // SkSGScene_DEFINED |