From 2919b610f4bba18b80f303da9862498bcb1ffe4b Mon Sep 17 00:00:00 2001 From: Florin Malita Date: Thu, 10 May 2018 12:44:07 -0400 Subject: [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 Reviewed-by: Florin Malita --- experimental/skottie/Skottie.cpp | 47 +++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 22 deletions(-) (limited to 'experimental') 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 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> fLayerMatrixMap; sk_sp fCurrentMatte; - sk_sp AttachParentLayerMatrix(const json::ValueRef& jlayer) { + sk_sp AttachLayerMatrix(const json::ValueRef& jlayer) { + SkASSERT(jlayer.isObject()); + + const auto layer_index = jlayer["ind"].toDefault(-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 AttachParentLayerMatrix(const json::ValueRef& jlayer, int layer_index) { SkASSERT(jlayer.isObject()); - SkASSERT(fLayerList.isArray()); const auto parent_index = jlayer["parent"].toDefault(-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 matrix; for (const json::ValueRef l : fLayerList) { if (l["ind"].toDefault(-1) == parent_index) { - matrix = this->AttachLayerMatrix(l); - break; + return this->AttachLayerMatrixImpl(l, parent_index); } } return nullptr; } - sk_sp AttachLayerMatrix(const json::ValueRef& jlayer) { - SkASSERT(jlayer.isObject()); - - const auto layer_index = jlayer["ind"].toDefault(-1); - if (layer_index < 0) - return nullptr; - - if (auto* m = fLayerMatrixMap.find(layer_index)) - return *m; + sk_sp 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)); } }; -- cgit v1.2.3