aboutsummaryrefslogtreecommitdiffhomepage
path: root/experimental/skottie/Skottie.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'experimental/skottie/Skottie.cpp')
-rw-r--r--experimental/skottie/Skottie.cpp55
1 files changed, 27 insertions, 28 deletions
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<sksg::RenderNode> fNode;
-};
-
-using AssetMap = SkTHashMap<SkString, AssetRec>;
+using AssetMap = SkTHashMap<SkString, const Json::Value*>;
struct AttachContext {
const ResourceProvider& fResources;
@@ -681,33 +676,23 @@ sk_sp<sksg::RenderNode> AttachShape(const Json::Value& jshape, AttachShapeContex
return draws.empty() ? nullptr : shape_wrapper;
}
-sk_sp<sksg::RenderNode> AttachAsset(const Json::Value& jobject, AttachContext* ctx,
- sk_sp<sksg::RenderNode>(proc)(const Json::Value&,
- AttachContext*)) {
- SkASSERT(jobject.isObject());
+sk_sp<sksg::RenderNode> 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<sksg::RenderNode> AttachCompLayer(const Json::Value& jlayer, AttachContext* ctx) {
- return AttachAsset(jlayer, ctx, AttachComposition);
+ // TODO: cycle detection
+ return AttachComposition(**comp, ctx);
}
sk_sp<sksg::RenderNode> AttachSolidLayer(const Json::Value& jlayer, AttachContext*) {
@@ -751,8 +736,22 @@ sk_sp<sksg::RenderNode> AttachImageAsset(const Json::Value& jimage, AttachContex
SkImage::MakeFromEncoded(SkData::MakeFromStream(resStream.get(), resStream->getLength())));
}
-sk_sp<sksg::RenderNode> AttachImageLayer(const Json::Value& jlayer, AttachContext* ctx) {
- return AttachAsset(jlayer, ctx, AttachImageAsset);
+sk_sp<sksg::RenderNode> 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<sksg::RenderNode> 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;