From dd22cf96d3bd464b375130786d3cb0b3f44614d3 Mon Sep 17 00:00:00 2001 From: Florin Malita Date: Mon, 29 Jan 2018 15:42:01 +0000 Subject: Revert "[skottie] Cache attached assets" This reverts commit ba3ed69a4ee4125750cd56ca9141c2b78fd65d22. Reason for revert: Looks like asset references can manipulate the timeline (preComps), so we do need distinct instances for each ref. May revisit in the future for cases where all instances share the same timeline. Original change's description: > [skottie] Cache attached assets > > This avoids redundant instantiations for assets referenced multiple > times. > > TBR= > > Change-Id: I8f61f73e695f0d567e55ef077c7d3fb344399f12 > Reviewed-on: https://skia-review.googlesource.com/101002 > Reviewed-by: Florin Malita > Commit-Queue: Florin Malita TBR=fmalita@chromium.org Change-Id: I3e537ace9dfbf69a11f421992db033a0f8ad2aa9 No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://skia-review.googlesource.com/101220 Reviewed-by: Florin Malita Commit-Queue: Florin Malita --- experimental/skottie/Skottie.cpp | 55 ++++++++++++++++++++-------------------- 1 file changed, 27 insertions(+), 28 deletions(-) (limited to 'experimental') diff --git a/experimental/skottie/Skottie.cpp b/experimental/skottie/Skottie.cpp index d0ebb5dbb9..1ec461423d 100644 --- a/experimental/skottie/Skottie.cpp +++ b/experimental/skottie/Skottie.cpp @@ -50,12 +50,7 @@ namespace skottie { namespace { -struct AssetRec { - const Json::Value* fJson; - sk_sp fNode; -}; - -using AssetMap = SkTHashMap; +using AssetMap = SkTHashMap; struct AttachContext { const ResourceProvider& fResources; @@ -681,33 +676,23 @@ sk_sp AttachShape(const Json::Value& jshape, AttachShapeContex return draws.empty() ? nullptr : shape_wrapper; } -sk_sp AttachAsset(const Json::Value& jobject, AttachContext* ctx, - sk_sp(proc)(const Json::Value&, - AttachContext*)) { - SkASSERT(jobject.isObject()); +sk_sp AttachCompLayer(const Json::Value& layer, AttachContext* ctx) { + SkASSERT(layer.isObject()); SkString refId; - if (!Parse(jobject["refId"], &refId) || refId.isEmpty()) { - LOG("!! Missing asset refId\n"); + if (!Parse(layer["refId"], &refId) || refId.isEmpty()) { + LOG("!! Comp layer missing refId\n"); return nullptr; } - auto* rec = ctx->fAssets.find(refId); - if (!rec) { - LOG("!! Asset not found: '%s'\n", refId.c_str()); + const auto* comp = ctx->fAssets.find(refId); + if (!comp) { + LOG("!! Pre-comp not found: '%s'\n", refId.c_str()); return nullptr; } - if (!rec->fNode) { - // TODO: cycle detection - rec->fNode = proc(*rec->fJson, ctx); - } - - return rec->fNode; -} - -sk_sp AttachCompLayer(const Json::Value& jlayer, AttachContext* ctx) { - return AttachAsset(jlayer, ctx, AttachComposition); + // TODO: cycle detection + return AttachComposition(**comp, ctx); } sk_sp AttachSolidLayer(const Json::Value& jlayer, AttachContext*) { @@ -751,8 +736,22 @@ sk_sp AttachImageAsset(const Json::Value& jimage, AttachContex SkImage::MakeFromEncoded(SkData::MakeFromStream(resStream.get(), resStream->getLength()))); } -sk_sp AttachImageLayer(const Json::Value& jlayer, AttachContext* ctx) { - return AttachAsset(jlayer, ctx, AttachImageAsset); +sk_sp AttachImageLayer(const Json::Value& layer, AttachContext* ctx) { + SkASSERT(layer.isObject()); + + SkString refId; + if (!Parse(layer["refId"], &refId) || refId.isEmpty()) { + LOG("!! Image layer missing refId\n"); + return nullptr; + } + + const auto* jimage = ctx->fAssets.find(refId); + if (!jimage) { + LOG("!! Image asset not found: '%s'\n", refId.c_str()); + return nullptr; + } + + return AttachImageAsset(**jimage, ctx); } sk_sp AttachNullLayer(const Json::Value& layer, AttachContext*) { @@ -1089,7 +1088,7 @@ Animation::Animation(const ResourceProvider& resources, continue; } - assets.set(ParseDefault(asset["id"], SkString()), {&asset, nullptr}); + assets.set(ParseDefault(asset["id"], SkString()), &asset); } sksg::Scene::AnimatorList animators; -- cgit v1.2.3