diff options
author | Florin Malita <fmalita@chromium.org> | 2017-10-11 14:11:16 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-10-11 18:32:37 +0000 |
commit | b36be14c254b61510c13844311d6885775c96e8a (patch) | |
tree | 97c5f78e7650f227a73f007be3f72192a688b880 /experimental/svg/model | |
parent | 6a69c053ff244a11ae41002bfc09b54a5dc9ec68 (diff) |
[SVGDom] Avoid some unneeded canvas save()s
The canvas only needs to be saved once, per local SkSVGRenderContext.
Add a helper (saveOnce) to implement this optimization.
Change-Id: I0c21fa78ad9fd5d3d11de0a29f8441620488d676
Reviewed-on: https://skia-review.googlesource.com/58340
Commit-Queue: Florin Malita <fmalita@chromium.org>
Reviewed-by: Robert Phillips <robertphillips@google.com>
Diffstat (limited to 'experimental/svg/model')
-rw-r--r-- | experimental/svg/model/SkSVGRenderContext.cpp | 14 | ||||
-rw-r--r-- | experimental/svg/model/SkSVGRenderContext.h | 1 | ||||
-rw-r--r-- | experimental/svg/model/SkSVGSVG.cpp | 2 | ||||
-rw-r--r-- | experimental/svg/model/SkSVGTransformableNode.cpp | 2 | ||||
-rw-r--r-- | experimental/svg/model/SkSVGUse.cpp | 2 |
5 files changed, 14 insertions, 7 deletions
diff --git a/experimental/svg/model/SkSVGRenderContext.cpp b/experimental/svg/model/SkSVGRenderContext.cpp index d8c269a56f..7fa61d48a3 100644 --- a/experimental/svg/model/SkSVGRenderContext.cpp +++ b/experimental/svg/model/SkSVGRenderContext.cpp @@ -333,6 +333,15 @@ void SkSVGRenderContext::applyOpacity(SkScalar opacity, uint32_t flags) { } } +void SkSVGRenderContext::saveOnce() { + // The canvas only needs to be saved once, per local SkSVGRenderContext. + if (fCanvas->getSaveCount() == fCanvasSaveCount) { + fCanvas->save(); + } + + SkASSERT(fCanvas->getSaveCount() > fCanvasSaveCount); +} + void SkSVGRenderContext::applyClip(const SkSVGClip& clip) { if (clip.type() != SkSVGClip::Type::kIRI) { return; @@ -352,10 +361,7 @@ void SkSVGRenderContext::applyClip(const SkSVGClip& clip) { // // TODO: the two uses are exclusive, avoid canvas churn when non needed. - // Only save if needed - if (fCanvas->getSaveCount() == fCanvasSaveCount) { - fCanvas->save(); - } + this->saveOnce(); fCanvas->clipPath(clipPath, true); fClipPath.set(clipPath); diff --git a/experimental/svg/model/SkSVGRenderContext.h b/experimental/svg/model/SkSVGRenderContext.h index 3cd38cbd7f..b5d8720ab3 100644 --- a/experimental/svg/model/SkSVGRenderContext.h +++ b/experimental/svg/model/SkSVGRenderContext.h @@ -69,6 +69,7 @@ public: const SkSVGPresentationContext& presentationContext() const { return *fPresentationContext; } SkCanvas* canvas() const { return fCanvas; } + void saveOnce(); enum ApplyFlags { kLeaf = 1 << 0, // the target node doesn't have descendants diff --git a/experimental/svg/model/SkSVGSVG.cpp b/experimental/svg/model/SkSVGSVG.cpp index 592992760a..ef919a8ec1 100644 --- a/experimental/svg/model/SkSVGSVG.cpp +++ b/experimental/svg/model/SkSVGSVG.cpp @@ -33,7 +33,7 @@ bool SkSVGSVG::onPrepareToRender(SkSVGRenderContext* ctx) const { } if (!contentMatrix.isIdentity()) { - ctx->canvas()->save(); + ctx->saveOnce(); ctx->canvas()->concat(contentMatrix); } diff --git a/experimental/svg/model/SkSVGTransformableNode.cpp b/experimental/svg/model/SkSVGTransformableNode.cpp index aa2a814f58..e8713c03c4 100644 --- a/experimental/svg/model/SkSVGTransformableNode.cpp +++ b/experimental/svg/model/SkSVGTransformableNode.cpp @@ -17,7 +17,7 @@ SkSVGTransformableNode::SkSVGTransformableNode(SkSVGTag tag) bool SkSVGTransformableNode::onPrepareToRender(SkSVGRenderContext* ctx) const { if (!fTransform.value().isIdentity()) { - ctx->canvas()->save(); + ctx->saveOnce(); ctx->canvas()->concat(fTransform); } diff --git a/experimental/svg/model/SkSVGUse.cpp b/experimental/svg/model/SkSVGUse.cpp index b98909f8b4..b0d6f93b77 100644 --- a/experimental/svg/model/SkSVGUse.cpp +++ b/experimental/svg/model/SkSVGUse.cpp @@ -58,7 +58,7 @@ bool SkSVGUse::onPrepareToRender(SkSVGRenderContext* ctx) const { if (fX.value() || fY.value()) { // Restored when the local SkSVGRenderContext leaves scope. - ctx->canvas()->save(); + ctx->saveOnce(); ctx->canvas()->translate(fX.value(), fY.value()); } |