From c83a0deaa8d4d94450424c4c8eed53e70b25365c Mon Sep 17 00:00:00 2001 From: Florin Malita Date: Thu, 31 May 2018 12:17:55 -0400 Subject: [skottie] Make the resource provider factory argument optional Most of the existing clients don't care about nested resources. Change-Id: Ie7991dd25ebbd679b5b49e5624772c7e19e7ec79 Reviewed-on: https://skia-review.googlesource.com/131141 Reviewed-by: Mike Reed Commit-Queue: Florin Malita --- modules/skottie/fuzz/FuzzSkottieJSON.cpp | 10 +--------- modules/skottie/include/Skottie.h | 2 +- modules/skottie/src/Skottie.cpp | 15 ++++++++++----- 3 files changed, 12 insertions(+), 15 deletions(-) (limited to 'modules') diff --git a/modules/skottie/fuzz/FuzzSkottieJSON.cpp b/modules/skottie/fuzz/FuzzSkottieJSON.cpp index 35135f133f..23c77cebd9 100644 --- a/modules/skottie/fuzz/FuzzSkottieJSON.cpp +++ b/modules/skottie/fuzz/FuzzSkottieJSON.cpp @@ -10,16 +10,8 @@ #include "SkStream.h" void FuzzSkottieJSON(sk_sp bytes) { - // Always returns nullptr to any resource - class EmptyResourceProvider final : public skottie::ResourceProvider { - public: - std::unique_ptr openStream(const char resource[]) const override { - return nullptr; - } - }; SkMemoryStream stream(bytes); - EmptyResourceProvider erp; - auto animation = skottie::Animation::Make(&stream, erp); + auto animation = skottie::Animation::Make(&stream); if (!animation) { return; } diff --git a/modules/skottie/include/Skottie.h b/modules/skottie/include/Skottie.h index 906ea82b68..5114ae4578 100644 --- a/modules/skottie/include/Skottie.h +++ b/modules/skottie/include/Skottie.h @@ -42,7 +42,7 @@ public: fAnimatorCount; }; - static sk_sp Make(SkStream*, const ResourceProvider&, Stats* = nullptr); + static sk_sp Make(SkStream*, const ResourceProvider* = nullptr, Stats* = nullptr); static sk_sp MakeFromFile(const char path[], const ResourceProvider* = nullptr, Stats* = nullptr); diff --git a/modules/skottie/src/Skottie.cpp b/modules/skottie/src/Skottie.cpp index ddea1be18b..250aa2e8d3 100644 --- a/modules/skottie/src/Skottie.cpp +++ b/modules/skottie/src/Skottie.cpp @@ -747,7 +747,7 @@ sk_sp AttachNestedAnimation(const char* path, AttachContext* c return nullptr; } - auto animation = Animation::Make(resStream.get(), ctx->fResources); + auto animation = Animation::Make(resStream.get(), &ctx->fResources); if (!animation) { LOG("!! Could not load nested animation: %s\n", path); return nullptr; @@ -1191,7 +1191,7 @@ sk_sp AttachComposition(const json::ValueRef& comp, AttachCont } // namespace -sk_sp Animation::Make(SkStream* stream, const ResourceProvider& res, Stats* stats) { +sk_sp Animation::Make(SkStream* stream, const ResourceProvider* provider, Stats* stats) { Stats stats_storage; if (!stats) stats = &stats_storage; @@ -1225,8 +1225,13 @@ sk_sp Animation::Make(SkStream* stream, const ResourceProvider& res, return nullptr; } - const auto anim = - sk_sp(new Animation(res, std::move(version), size, fps, json, stats)); + class NullResourceProvider final : public ResourceProvider { + std::unique_ptr openStream(const char[]) const { return nullptr; } + }; + + const NullResourceProvider null_provider; + const auto anim = sk_sp(new Animation(provider ? *provider : null_provider, + std::move(version), size, fps, json, stats)); const auto t2 = SkTime::GetMSecs(); stats->fSceneParseTimeMS = t2 - t1; stats->fTotalLoadTimeMS = t2 - t0; @@ -1258,7 +1263,7 @@ sk_sp Animation::MakeFromFile(const char path[], const ResourceProvid defaultProvider = skstd::make_unique(SkOSPath::Dirname(path)); } - return Make(jsonStream.get(), res ? *res : *defaultProvider, stats); + return Make(jsonStream.get(), res ? res : defaultProvider.get(), stats); } Animation::Animation(const ResourceProvider& resources, -- cgit v1.2.3