blob: 8d7e0b369babe09f7d849b275c53ced4a83add1b [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
Florin Malitacca86f32018-01-29 10:49:49 -050025GroupAnimator::GroupAnimator(AnimatorList&& animators)
26 : fAnimators(std::move(animators)) {}
27
28void GroupAnimator::onTick(float t) {
29 for (const auto& a : fAnimators) {
30 a->tick(t);
31 }
32}
33
Florin Malita35efaa82018-01-22 12:57:06 -050034std::unique_ptr<Scene> Scene::Make(sk_sp<RenderNode> root, AnimatorList&& anims) {
35 return root ? std::unique_ptr<Scene>(new Scene(std::move(root), std::move(anims))) : nullptr;
36}
37
38Scene::Scene(sk_sp<RenderNode> root, AnimatorList&& animators)
39 : fRoot(std::move(root))
40 , fAnimators(std::move(animators)) {}
41
42Scene::~Scene() = default;
43
44void Scene::render(SkCanvas* canvas) const {
45 InvalidationController ic;
46 fRoot->revalidate(&ic, SkMatrix::I());
47 fRoot->render(canvas);
48
49 if (fShowInval) {
50 SkPaint fill, stroke;
51 fill.setAntiAlias(true);
52 fill.setColor(0x40ff0000);
53 stroke.setAntiAlias(true);
54 stroke.setColor(0xffff0000);
55 stroke.setStyle(SkPaint::kStroke_Style);
56
57 for (const auto& r : ic) {
58 canvas->drawRect(r, fill);
59 canvas->drawRect(r, stroke);
60 }
61 }
62}
63
64void Scene::animate(float t) {
65 for (const auto& anim : fAnimators) {
66 anim->tick(t);
67 }
68}
69
70} // namespace sksg