blob: 2081c1d74739a1ed639dfb61f920b2d2b379529e [file] [log] [blame]
Florin Malita35efaa82018-01-22 12:57:06 -05001/*
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
17class SkCanvas;
18
19namespace sksg {
20
21class RenderNode;
22
23/**
24 * Base class for animators.
25 *
26 */
27class Animator : public SkNoncopyable {
28public:
29 virtual ~Animator();
30
31 void tick(float t);
32
33protected:
34 Animator();
35
36 virtual void onTick(float t) = 0;
37
38private:
39 using INHERITED = SkNoncopyable;
40};
41
Florin Malitacca86f32018-01-29 10:49:49 -050042using AnimatorList = std::vector<std::unique_ptr<Animator>>;
43
44class GroupAnimator : public Animator {
45protected:
46 explicit GroupAnimator(AnimatorList&&);
47
48 void onTick(float t) override;
49
50private:
51 const AnimatorList fAnimators;
52
53 using INHERITED = Animator;
54};
55
Florin Malita35efaa82018-01-22 12:57:06 -050056/**
57 * Holds a scene root and a list of animators.
58 *
59 * Provides high-level mehods for driving rendering and animations.
60 *
61 */
62class Scene final : SkNoncopyable {
63public:
Florin Malita35efaa82018-01-22 12:57:06 -050064 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
72private:
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