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
This commit is contained in:
robertphillips 2015-10-30 05:15:11 -07:00 committed by Commit bot
parent 8a3760f8b2
commit 13391dd972
4 changed files with 43 additions and 63 deletions

View File

@ -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;
}
}
{

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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<kPreAllocCount, GrPathRenderer*, true> fChain;
typedef SkRefCnt INHERITED;
};
#endif