diff options
author | Florin Malita <fmalita@chromium.org> | 2018-05-10 12:44:07 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-05-10 17:20:16 +0000 |
commit | 2919b610f4bba18b80f303da9862498bcb1ffe4b (patch) | |
tree | 8f0e333f899c940c74dbf74098fba9f233577d52 /experimental | |
parent | 8aa0dca395d49b136ab59f6e96c4446342c9ebd2 (diff) |
[skottie] Clean up AttachLayerContext
Avoid double "ind" lookups, avoid repeated AttachParentLayerMatrix
calls, hide private functions.
TBR=
Change-Id: I78f11593ffe241de3cdfabf7b3a88e8f4e62aa0c
Reviewed-on: https://skia-review.googlesource.com/127327
Commit-Queue: Florin Malita <fmalita@chromium.org>
Reviewed-by: Florin Malita <fmalita@chromium.org>
Diffstat (limited to 'experimental')
-rw-r--r-- | experimental/skottie/Skottie.cpp | 47 |
1 files changed, 25 insertions, 22 deletions
diff --git a/experimental/skottie/Skottie.cpp b/experimental/skottie/Skottie.cpp index 03429e7228..18c8c193c0 100644 --- a/experimental/skottie/Skottie.cpp +++ b/experimental/skottie/Skottie.cpp @@ -886,54 +886,57 @@ sk_sp<sksg::RenderNode> AttachTextLayer(const json::ValueRef& layer, AttachConte struct AttachLayerContext { AttachLayerContext(const json::ValueRef& jlayers, AttachContext* ctx) - : fLayerList(jlayers), fCtx(ctx) {} + : fLayerList(jlayers), fCtx(ctx) { + SkASSERT(fLayerList.isArray()); + } - const json::ValueRef fLayerList; + const json::ValueRef fLayerList; AttachContext* fCtx; SkTHashMap<int, sk_sp<sksg::Matrix>> fLayerMatrixMap; sk_sp<sksg::RenderNode> fCurrentMatte; - sk_sp<sksg::Matrix> AttachParentLayerMatrix(const json::ValueRef& jlayer) { + sk_sp<sksg::Matrix> AttachLayerMatrix(const json::ValueRef& jlayer) { + SkASSERT(jlayer.isObject()); + + const auto layer_index = jlayer["ind"].toDefault<int>(-1); + if (layer_index < 0) + return nullptr; + + if (auto* m = fLayerMatrixMap.find(layer_index)) + return *m; + + return this->AttachLayerMatrixImpl(jlayer, layer_index); + } + +private: + sk_sp<sksg::Matrix> AttachParentLayerMatrix(const json::ValueRef& jlayer, int layer_index) { SkASSERT(jlayer.isObject()); - SkASSERT(fLayerList.isArray()); const auto parent_index = jlayer["parent"].toDefault<int>(-1); - if (parent_index < 0) + if (parent_index < 0 || parent_index == layer_index) return nullptr; if (auto* m = fLayerMatrixMap.find(parent_index)) return *m; - sk_sp<sksg::Matrix> matrix; for (const json::ValueRef l : fLayerList) { if (l["ind"].toDefault<int>(-1) == parent_index) { - matrix = this->AttachLayerMatrix(l); - break; + return this->AttachLayerMatrixImpl(l, parent_index); } } return nullptr; } - sk_sp<sksg::Matrix> AttachLayerMatrix(const json::ValueRef& jlayer) { - SkASSERT(jlayer.isObject()); - - const auto layer_index = jlayer["ind"].toDefault<int>(-1); - if (layer_index < 0) - return nullptr; - - if (auto* m = fLayerMatrixMap.find(layer_index)) - return *m; + sk_sp<sksg::Matrix> AttachLayerMatrixImpl(const json::ValueRef& jlayer, int layer_index) { + SkASSERT(!fLayerMatrixMap.find(layer_index)); // Add a stub entry to break recursion cycles. fLayerMatrixMap.set(layer_index, nullptr); - auto parent_matrix = this->AttachParentLayerMatrix(jlayer); + auto parent_matrix = this->AttachParentLayerMatrix(jlayer, layer_index); - return *fLayerMatrixMap.set(layer_index, - AttachMatrix(jlayer["ks"], - fCtx, - this->AttachParentLayerMatrix(jlayer))); + return *fLayerMatrixMap.set(layer_index, AttachMatrix(jlayer["ks"], fCtx, parent_matrix)); } }; |