From 13391dd97209f36c71bc18cc75084f74c2f6af15 Mon Sep 17 00:00:00 2001 From: robertphillips Date: Fri, 30 Oct 2015 05:15:11 -0700 Subject: [PATCH] Minor cleanup of clip mask manager Follow up to https://codereview.chromium.org/1418073005/ (Remove gpu-side clip mask merging from clip mask manager). The path renderer chain is only ever allocated when it is about to be used (so the delayed initialization doesn't buy us anything). We can now reduce the lifetime of the pipelineBuilder in createAlphaClipMask Review URL: https://codereview.chromium.org/1416113006 --- src/gpu/GrClipMaskManager.cpp | 41 +++++++++++++++++--------------- src/gpu/GrDrawingManager.cpp | 6 +++-- src/gpu/GrPathRendererChain.cpp | 42 ++++++++++++--------------------- src/gpu/GrPathRendererChain.h | 17 ++----------- 4 files changed, 43 insertions(+), 63 deletions(-) diff --git a/src/gpu/GrClipMaskManager.cpp b/src/gpu/GrClipMaskManager.cpp index 9617e0dc65..076871ca05 100644 --- a/src/gpu/GrClipMaskManager.cpp +++ b/src/gpu/GrClipMaskManager.cpp @@ -589,12 +589,7 @@ GrTexture* GrClipMaskManager::createAlphaClipMask(int32_t elementsGenID, SkRegion::Op op = element->getOp(); bool invert = element->isInverseFilled(); if (invert || SkRegion::kIntersect_Op == op || SkRegion::kReverseDifference_Op == op) { - GrPipelineBuilder pipelineBuilder; - pipelineBuilder.setClip(clip); - pipelineBuilder.setRenderTarget(texture->asRenderTarget()); - - SkASSERT(pipelineBuilder.getStencil().isDisabled()); GrPathRenderer* pr = GetPathRenderer(this->getContext(), texture, translate, element); if (Element::kRect_Type != element->getType() && !pr) { @@ -605,21 +600,29 @@ GrTexture* GrClipMaskManager::createAlphaClipMask(int32_t elementsGenID, continue; } - // draw directly into the result with the stencil set to make the pixels affected - // by the clip shape be non-zero. - GR_STATIC_CONST_SAME_STENCIL(kStencilInElement, - kReplace_StencilOp, - kReplace_StencilOp, - kAlways_StencilFunc, - 0xffff, - 0xffff, - 0xffff); - pipelineBuilder.setStencil(kStencilInElement); - set_coverage_drawing_xpf(op, invert, &pipelineBuilder); + { + GrPipelineBuilder pipelineBuilder; - if (!this->drawElement(&pipelineBuilder, translate, texture, element, pr)) { - texture->resourcePriv().removeUniqueKey(); - return nullptr; + pipelineBuilder.setClip(clip); + pipelineBuilder.setRenderTarget(texture->asRenderTarget()); + SkASSERT(pipelineBuilder.getStencil().isDisabled()); + + // draw directly into the result with the stencil set to make the pixels affected + // by the clip shape be non-zero. + GR_STATIC_CONST_SAME_STENCIL(kStencilInElement, + kReplace_StencilOp, + kReplace_StencilOp, + kAlways_StencilFunc, + 0xffff, + 0xffff, + 0xffff); + pipelineBuilder.setStencil(kStencilInElement); + set_coverage_drawing_xpf(op, invert, &pipelineBuilder); + + if (!this->drawElement(&pipelineBuilder, translate, texture, element, pr)) { + texture->resourcePriv().removeUniqueKey(); + return nullptr; + } } { diff --git a/src/gpu/GrDrawingManager.cpp b/src/gpu/GrDrawingManager.cpp index 0a487daf41..4483a15934 100644 --- a/src/gpu/GrDrawingManager.cpp +++ b/src/gpu/GrDrawingManager.cpp @@ -31,7 +31,8 @@ void GrDrawingManager::cleanup() { fTextContexts[i][1] = nullptr; } - SkSafeSetNull(fPathRendererChain); + delete fPathRendererChain; + fPathRendererChain = nullptr; SkSafeSetNull(fSoftwarePathRenderer); } @@ -46,7 +47,8 @@ void GrDrawingManager::abandon() { void GrDrawingManager::freeGpuResources() { // a path renderer may be holding onto resources - SkSafeSetNull(fPathRendererChain); + delete fPathRendererChain; + fPathRendererChain = nullptr; SkSafeSetNull(fSoftwarePathRenderer); } diff --git a/src/gpu/GrPathRendererChain.cpp b/src/gpu/GrPathRendererChain.cpp index 63195c6414..e13e6c6584 100644 --- a/src/gpu/GrPathRendererChain.cpp +++ b/src/gpu/GrPathRendererChain.cpp @@ -22,9 +22,21 @@ #include "batches/GrStencilAndCoverPathRenderer.h" #include "batches/GrTessellatingPathRenderer.h" -GrPathRendererChain::GrPathRendererChain(GrContext* context) - : fInit(false) - , fOwner(context) { +GrPathRendererChain::GrPathRendererChain(GrContext* context) { + const GrCaps& caps = *context->caps(); + this->addPathRenderer(new GrDashLinePathRenderer)->unref(); + + if (GrPathRenderer* pr = GrStencilAndCoverPathRenderer::Create(context->resourceProvider(), + caps)) { + this->addPathRenderer(pr)->unref(); + } + this->addPathRenderer(new GrTessellatingPathRenderer)->unref(); + this->addPathRenderer(new GrAAHairLinePathRenderer)->unref(); + this->addPathRenderer(new GrAAConvexPathRenderer)->unref(); + this->addPathRenderer(new GrAALinearizingConvexPathRenderer)->unref(); + this->addPathRenderer(new GrAADistanceFieldPathRenderer)->unref(); + this->addPathRenderer(new GrDefaultPathRenderer(caps.twoSidedStencilSupport(), + caps.stencilWrapOpsSupport()))->unref(); } GrPathRendererChain::~GrPathRendererChain() { @@ -42,10 +54,6 @@ GrPathRenderer* GrPathRendererChain::addPathRenderer(GrPathRenderer* pr) { GrPathRenderer* GrPathRendererChain::getPathRenderer(const GrPathRenderer::CanDrawPathArgs& args, DrawType drawType, GrPathRenderer::StencilSupport* stencilSupport) { - if (!fInit) { - this->init(); - } - GR_STATIC_ASSERT(GrPathRenderer::kNoSupport_StencilSupport < GrPathRenderer::kStencilOnly_StencilSupport); GR_STATIC_ASSERT(GrPathRenderer::kStencilOnly_StencilSupport < @@ -60,7 +68,6 @@ GrPathRenderer* GrPathRendererChain::getPathRenderer(const GrPathRenderer::CanDr minStencilSupport = GrPathRenderer::kNoSupport_StencilSupport; } - for (int i = 0; i < fChain.count(); ++i) { if (fChain[i]->canDrawPath(args)) { if (GrPathRenderer::kNoSupport_StencilSupport != minStencilSupport) { @@ -77,22 +84,3 @@ GrPathRenderer* GrPathRendererChain::getPathRenderer(const GrPathRenderer::CanDr } return nullptr; } - -void GrPathRendererChain::init() { - SkASSERT(!fInit); - const GrCaps& caps = *fOwner->caps(); - this->addPathRenderer(new GrDashLinePathRenderer)->unref(); - - if (GrPathRenderer* pr = GrStencilAndCoverPathRenderer::Create(fOwner->resourceProvider(), - caps)) { - this->addPathRenderer(pr)->unref(); - } - this->addPathRenderer(new GrTessellatingPathRenderer)->unref(); - this->addPathRenderer(new GrAAHairLinePathRenderer)->unref(); - this->addPathRenderer(new GrAAConvexPathRenderer)->unref(); - this->addPathRenderer(new GrAALinearizingConvexPathRenderer)->unref(); - this->addPathRenderer(new GrAADistanceFieldPathRenderer)->unref(); - this->addPathRenderer(new GrDefaultPathRenderer(caps.twoSidedStencilSupport(), - caps.stencilWrapOpsSupport()))->unref(); - fInit = true; -} diff --git a/src/gpu/GrPathRendererChain.h b/src/gpu/GrPathRendererChain.h index e0e7d46f06..ade30551ae 100644 --- a/src/gpu/GrPathRendererChain.h +++ b/src/gpu/GrPathRendererChain.h @@ -10,15 +10,10 @@ #include "GrPathRenderer.h" -#include "SkRefCnt.h" +#include "SkTypes.h" #include "SkTArray.h" class GrContext; -class GrPipelineBuilder; -class GrShaderCaps; -class GrStrokeInfo; -class SkMatrix; -class SkPath; /** * Keeps track of an ordered list of path renderers. When a path needs to be @@ -26,7 +21,7 @@ class SkPath; * path renderer to the list implement the GrPathRenderer::AddPathRenderers * function. */ -class GrPathRendererChain : public SkRefCnt { +class GrPathRendererChain : public SkNoncopyable { public: GrPathRendererChain(GrContext* context); @@ -52,21 +47,13 @@ public: GrPathRenderer::StencilSupport* stencilSupport); private: - GrPathRendererChain(); - // takes a ref and unrefs in destructor GrPathRenderer* addPathRenderer(GrPathRenderer* pr); - void init(); - enum { kPreAllocCount = 8, }; - bool fInit; - GrContext* fOwner; SkSTArray fChain; - - typedef SkRefCnt INHERITED; }; #endif