skia2/experimental/sksg/SkSGScene.cpp
Florin Malita 35efaa8fd7 [sksg] Animator, Scene
Relocate some reusable logic from Skottie

TBR=
Change-Id: I8764e666c9f1127ed895ee1d16cd66d052469ac5
Reviewed-on: https://skia-review.googlesource.com/98160
Reviewed-by: Florin Malita <fmalita@chromium.org>
Commit-Queue: Florin Malita <fmalita@chromium.org>
2018-01-22 18:31:17 +00:00

62 lines
1.4 KiB
C++

/*
* Copyright 2018 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "SkSGScene.h"
#include "SkCanvas.h"
#include "SkMatrix.h"
#include "SkPaint.h"
#include "SkSGInvalidationController.h"
#include "SkSGRenderNode.h"
namespace sksg {
Animator::Animator() = default;
Animator::~Animator() = default;
void Animator::tick(float t) {
this->onTick(t);
}
std::unique_ptr<Scene> Scene::Make(sk_sp<RenderNode> root, AnimatorList&& anims) {
return root ? std::unique_ptr<Scene>(new Scene(std::move(root), std::move(anims))) : nullptr;
}
Scene::Scene(sk_sp<RenderNode> root, AnimatorList&& animators)
: fRoot(std::move(root))
, fAnimators(std::move(animators)) {}
Scene::~Scene() = default;
void Scene::render(SkCanvas* canvas) const {
InvalidationController ic;
fRoot->revalidate(&ic, SkMatrix::I());
fRoot->render(canvas);
if (fShowInval) {
SkPaint fill, stroke;
fill.setAntiAlias(true);
fill.setColor(0x40ff0000);
stroke.setAntiAlias(true);
stroke.setColor(0xffff0000);
stroke.setStyle(SkPaint::kStroke_Style);
for (const auto& r : ic) {
canvas->drawRect(r, fill);
canvas->drawRect(r, stroke);
}
}
}
void Scene::animate(float t) {
for (const auto& anim : fAnimators) {
anim->tick(t);
}
}
} // namespace sksg