[skottie] Add frame time histogram to SkottieSlide UI

Ignoring GPU flush for now...

Change-Id: Ie28718ee528ac3f708c0237472845b3cca47f97d
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/259160
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Florin Malita <fmalita@chromium.org>
This commit is contained in:
Florin Malita 2019-12-10 14:23:32 -05:00 committed by Skia Commit-Bot
parent c5313e6b2a
commit 15ee970d79
2 changed files with 20 additions and 3 deletions

View File

@ -11,6 +11,7 @@
#include "include/core/SkCanvas.h" #include "include/core/SkCanvas.h"
#include "include/core/SkFont.h" #include "include/core/SkFont.h"
#include "include/core/SkTime.h"
#include "modules/skottie/include/Skottie.h" #include "modules/skottie/include/Skottie.h"
#include "modules/skresources/include/SkResources.h" #include "modules/skresources/include/SkResources.h"
#include "src/utils/SkOSPath.h" #include "src/utils/SkOSPath.h"
@ -110,6 +111,7 @@ void SkottieSlide::load(SkScalar w, SkScalar h) {
if (fAnimation) { if (fAnimation) {
fAnimation->seek(0); fAnimation->seek(0);
fFrameTimes.resize(SkScalarCeilToInt(fAnimation->duration() * fAnimation->fps()));
SkDebugf("Loaded Bodymovin animation v: %s, size: [%f %f]\n", SkDebugf("Loaded Bodymovin animation v: %s, size: [%f %f]\n",
fAnimation->version().c_str(), fAnimation->version().c_str(),
fAnimation->size().width(), fAnimation->size().width(),
@ -137,7 +139,15 @@ void SkottieSlide::draw(SkCanvas* canvas) {
if (fAnimation) { if (fAnimation) {
SkAutoCanvasRestore acr(canvas, true); SkAutoCanvasRestore acr(canvas, true);
const auto dstR = SkRect::MakeSize(fWinSize); const auto dstR = SkRect::MakeSize(fWinSize);
fAnimation->render(canvas, &dstR);
{
const auto t0 = SkTime::GetNSecs();
fAnimation->render(canvas, &dstR);
// TODO: this does not capture GPU flush time!
const auto frame_index = SkToSizeT(SkScalarRoundToInt(fCurrentFrame));
fFrameTimes[frame_index] = static_cast<float>((SkTime::GetNSecs() - t0) * 1e-6);
}
if (fShowAnimationStats) { if (fShowAnimationStats) {
draw_stats_box(canvas, fAnimationStats); draw_stats_box(canvas, fAnimationStats);
@ -226,7 +236,8 @@ SkRect SkottieSlide::UIArea() const {
} }
void SkottieSlide::renderUI() { void SkottieSlide::renderUI() {
static constexpr auto kUI_opacity = 0.35f; static constexpr auto kUI_opacity = 0.35f,
kUI_hist_height = 50.0f;
ImGui::SetNextWindowBgAlpha(kUI_opacity); ImGui::SetNextWindowBgAlpha(kUI_opacity);
if (ImGui::Begin("Skottie Controls", nullptr, ImGuiWindowFlags_NoDecoration | if (ImGui::Begin("Skottie Controls", nullptr, ImGuiWindowFlags_NoDecoration |
@ -240,7 +251,10 @@ void SkottieSlide::renderUI() {
ImGui::SetWindowSize(ImVec2(ui_area.width(), ui_area.height())); ImGui::SetWindowSize(ImVec2(ui_area.width(), ui_area.height()));
ImGui::PushItemWidth(-1); ImGui::PushItemWidth(-1);
ImGui::SliderFloat("", &fCurrentFrame, 0, fAnimation->duration() * fAnimation->fps());
ImGui::PlotHistogram("", fFrameTimes.data(), fFrameTimes.size(),
0, nullptr, FLT_MAX, FLT_MAX, ImVec2(0, kUI_hist_height));
ImGui::SliderFloat("", &fCurrentFrame, 0, fAnimation->duration() * fAnimation->fps() - 1);
fDraggingProgress = ImGui::IsItemActive(); fDraggingProgress = ImGui::IsItemActive();
ImGui::PopItemWidth(); ImGui::PopItemWidth();

View File

@ -14,6 +14,8 @@
#include "modules/skottie/include/Skottie.h" #include "modules/skottie/include/Skottie.h"
#include "modules/sksg/include/SkSGInvalidationController.h" #include "modules/sksg/include/SkSGInvalidationController.h"
#include <vector>
namespace sksg { class Scene; } namespace sksg { class Scene; }
class SkottieSlide : public Slide { class SkottieSlide : public Slide {
@ -42,6 +44,7 @@ private:
sk_sp<skottie::Animation> fAnimation; sk_sp<skottie::Animation> fAnimation;
skottie::Animation::Builder::Stats fAnimationStats; skottie::Animation::Builder::Stats fAnimationStats;
sksg::InvalidationController fInvalController; sksg::InvalidationController fInvalController;
std::vector<float> fFrameTimes;
SkSize fWinSize = SkSize::MakeEmpty(); SkSize fWinSize = SkSize::MakeEmpty();
SkMSec fTimeBase = 0; SkMSec fTimeBase = 0;
float fCurrentFrame = 0; float fCurrentFrame = 0;