aboutsummaryrefslogtreecommitdiffhomepage
path: root/experimental
diff options
context:
space:
mode:
authorGravatar Florin Malita <fmalita@chromium.org>2018-04-30 10:32:18 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-04-30 15:19:03 +0000
commit6eb85a1cf1b0829a16859f0e4b5b3f2064f38120 (patch)
tree17dd1c8b3e5467fe900697075d107e6d3e204459 /experimental
parentba36572d1c681c50066be6a19542b12cb434c59b (diff)
[skottie] Show load stats in SkottieSlide
TBR= Change-Id: Ie3a1036d9a90cb16d2795134c453759aeff06e3c Reviewed-on: https://skia-review.googlesource.com/124461 Reviewed-by: Florin Malita <fmalita@chromium.org> Commit-Queue: Florin Malita <fmalita@chromium.org>
Diffstat (limited to 'experimental')
-rw-r--r--experimental/skottie/Skottie.cpp32
-rw-r--r--experimental/skottie/Skottie.h15
2 files changed, 38 insertions, 9 deletions
diff --git a/experimental/skottie/Skottie.cpp b/experimental/skottie/Skottie.cpp
index a3b6d46b93..bb98ad75f0 100644
--- a/experimental/skottie/Skottie.cpp
+++ b/experimental/skottie/Skottie.cpp
@@ -38,6 +38,7 @@
#include "SkSGTrimEffect.h"
#include "SkStream.h"
#include "SkTArray.h"
+#include "SkTime.h"
#include "SkTHash.h"
#include <cmath>
@@ -1170,13 +1171,20 @@ sk_sp<sksg::RenderNode> AttachComposition(const Json::Value& comp, AttachContext
} // namespace
-sk_sp<Animation> Animation::Make(SkStream* stream, const ResourceProvider& res) {
+sk_sp<Animation> Animation::Make(SkStream* stream, const ResourceProvider& res, Stats* stats) {
+ Stats stats_storage;
+ if (!stats)
+ stats = &stats_storage;
+ memset(stats, 0, sizeof(struct Stats));
+
if (!stream->hasLength()) {
// TODO: handle explicit buffering?
LOG("!! cannot parse streaming content\n");
return nullptr;
}
+ const auto t0 = SkTime::GetMSecs();
+
Json::Value json;
{
auto data = SkData::MakeFromStream(stream, stream->getLength());
@@ -1184,6 +1192,7 @@ sk_sp<Animation> Animation::Make(SkStream* stream, const ResourceProvider& res)
LOG("!! could not read stream\n");
return nullptr;
}
+ stats->fJsonSize = data->size();
Json::Reader reader;
@@ -1194,6 +1203,9 @@ sk_sp<Animation> Animation::Make(SkStream* stream, const ResourceProvider& res)
}
}
+ const auto t1 = SkTime::GetMSecs();
+ stats->fJsonParseTimeMS = t1 - t0;
+
const auto version = ParseDefault(json["v"], SkString());
const auto size = SkSize::Make(ParseDefault(json["w"], 0.0f),
ParseDefault(json["h"], 0.0f));
@@ -1205,10 +1217,17 @@ sk_sp<Animation> Animation::Make(SkStream* stream, const ResourceProvider& res)
return nullptr;
}
- return sk_sp<Animation>(new Animation(res, std::move(version), size, fps, json));
+ const auto anim =
+ sk_sp<Animation>(new Animation(res, std::move(version), size, fps, json, stats));
+ const auto t2 = SkTime::GetMSecs();
+ stats->fSceneParseTimeMS = t2 - t1;
+ stats->fTotalLoadTimeMS = t2 - t0;
+
+ return anim;
}
-sk_sp<Animation> Animation::MakeFromFile(const char path[], const ResourceProvider* res) {
+sk_sp<Animation> Animation::MakeFromFile(const char path[], const ResourceProvider* res,
+ Stats* stats) {
class DirectoryResourceProvider final : public ResourceProvider {
public:
explicit DirectoryResourceProvider(SkString dir) : fDir(std::move(dir)) {}
@@ -1231,11 +1250,12 @@ sk_sp<Animation> Animation::MakeFromFile(const char path[], const ResourceProvid
defaultProvider = skstd::make_unique<DirectoryResourceProvider>(SkOSPath::Dirname(path));
}
- return Make(jsonStream.get(), res ? *res : *defaultProvider);
+ return Make(jsonStream.get(), res ? *res : *defaultProvider, stats);
}
Animation::Animation(const ResourceProvider& resources,
- SkString version, const SkSize& size, SkScalar fps, const Json::Value& json)
+ SkString version, const SkSize& size, SkScalar fps, const Json::Value& json,
+ Stats* stats)
: fVersion(std::move(version))
, fSize(size)
, fFrameRate(fps)
@@ -1255,7 +1275,7 @@ Animation::Animation(const ResourceProvider& resources,
AttachContext ctx = { resources, assets, fFrameRate, animators };
auto root = AttachComposition(json, &ctx);
- LOG("** Attached %d animators\n", animators.size());
+ stats->fAnimatorCount = animators.size();
fScene = sksg::Scene::Make(std::move(root), std::move(animators));
diff --git a/experimental/skottie/Skottie.h b/experimental/skottie/Skottie.h
index f14c4dc42b..44541fd81b 100644
--- a/experimental/skottie/Skottie.h
+++ b/experimental/skottie/Skottie.h
@@ -36,8 +36,17 @@ public:
class Animation : public SkRefCnt {
public:
- static sk_sp<Animation> Make(SkStream*, const ResourceProvider&);
- static sk_sp<Animation> MakeFromFile(const char path[], const ResourceProvider* = nullptr);
+ struct Stats {
+ float fTotalLoadTimeMS,
+ fJsonParseTimeMS,
+ fSceneParseTimeMS;
+ size_t fJsonSize,
+ fAnimatorCount;
+ };
+
+ static sk_sp<Animation> Make(SkStream*, const ResourceProvider&, Stats* = nullptr);
+ static sk_sp<Animation> MakeFromFile(const char path[], const ResourceProvider* = nullptr,
+ Stats* = nullptr);
~Animation() override;
@@ -56,7 +65,7 @@ public:
private:
Animation(const ResourceProvider&,
SkString ver, const SkSize& size, SkScalar fps,
- const Json::Value&);
+ const Json::Value&, Stats*);
SkString fVersion;
SkSize fSize;