• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "modules/sksg/include/SkSGScene.h"
9 
10 #include "include/core/SkCanvas.h"
11 #include "include/core/SkMatrix.h"
12 #include "include/core/SkPaint.h"
13 #include "modules/sksg/include/SkSGInvalidationController.h"
14 #include "modules/sksg/include/SkSGRenderNode.h"
15 
16 namespace sksg {
17 
18 Animator::Animator()  = default;
19 Animator::~Animator() = default;
20 
tick(float t)21 void Animator::tick(float t) {
22     this->onTick(t);
23 }
24 
GroupAnimator(AnimatorList && animators)25 GroupAnimator::GroupAnimator(AnimatorList&& animators)
26     : fAnimators(std::move(animators)) {}
27 
onTick(float t)28 void GroupAnimator::onTick(float t) {
29     for (const auto& a : fAnimators) {
30         a->tick(t);
31     }
32 }
33 
Make(sk_sp<RenderNode> root,AnimatorList && anims)34 std::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 
Scene(sk_sp<RenderNode> root,AnimatorList && animators)38 Scene::Scene(sk_sp<RenderNode> root, AnimatorList&& animators)
39     : fRoot(std::move(root))
40     , fAnimators(std::move(animators)) {}
41 
42 Scene::~Scene() = default;
43 
render(SkCanvas * canvas) const44 void Scene::render(SkCanvas* canvas) const {
45     // Ensure the SG is revalidated.
46     // Note: this is a no-op if the scene has already been revalidated - e.g. in animate().
47     fRoot->revalidate(nullptr, SkMatrix::I());
48     fRoot->render(canvas);
49 }
50 
animate(float t,InvalidationController * ic)51 void Scene::animate(float t, InvalidationController* ic) {
52     for (const auto& anim : fAnimators) {
53         anim->tick(t);
54     }
55 
56     fRoot->revalidate(ic, SkMatrix::I());
57 }
58 
nodeAt(const SkPoint & p) const59 const RenderNode* Scene::nodeAt(const SkPoint& p) const {
60     return fRoot->nodeAt(p);
61 }
62 
63 } // namespace sksg
64