blob: 85a1b43b1c36d085067471c3b7ce83ca0b175047 [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#include "SkSGScene.h"
9
10#include "SkCanvas.h"
11#include "SkMatrix.h"
12#include "SkPaint.h"
13#include "SkSGInvalidationController.h"
14#include "SkSGRenderNode.h"
15
16namespace sksg {
17
18Animator::Animator() = default;
19Animator::~Animator() = default;
20
21void Animator::tick(float t) {
22 this->onTick(t);
23}
24
25std::unique_ptr<Scene> Scene::Make(sk_sp<RenderNode> root, AnimatorList&& anims) {
26 return root ? std::unique_ptr<Scene>(new Scene(std::move(root), std::move(anims))) : nullptr;
27}
28
29Scene::Scene(sk_sp<RenderNode> root, AnimatorList&& animators)
30 : fRoot(std::move(root))
31 , fAnimators(std::move(animators)) {}
32
33Scene::~Scene() = default;
34
35void Scene::render(SkCanvas* canvas) const {
36 InvalidationController ic;
37 fRoot->revalidate(&ic, SkMatrix::I());
38 fRoot->render(canvas);
39
40 if (fShowInval) {
41 SkPaint fill, stroke;
42 fill.setAntiAlias(true);
43 fill.setColor(0x40ff0000);
44 stroke.setAntiAlias(true);
45 stroke.setColor(0xffff0000);
46 stroke.setStyle(SkPaint::kStroke_Style);
47
48 for (const auto& r : ic) {
49 canvas->drawRect(r, fill);
50 canvas->drawRect(r, stroke);
51 }
52 }
53}
54
55void Scene::animate(float t) {
56 for (const auto& anim : fAnimators) {
57 anim->tick(t);
58 }
59}
60
61} // namespace sksg