From 65048139bd26c8edbc6796f220e79b6c848151d7 Mon Sep 17 00:00:00 2001 From: Robert Phillips Date: Thu, 10 Aug 2017 08:44:49 -0400 Subject: Remove accessRenderTarget calls in service of binding stencil buffer Change-Id: Ifca6e21c619a0433ecf0b8699d92661f8c3068a8 Reviewed-on: https://skia-review.googlesource.com/31243 Commit-Queue: Robert Phillips Reviewed-by: Brian Salomon --- src/gpu/GrClipStackClip.cpp | 11 +--------- src/gpu/GrRenderTargetContext.cpp | 23 ++------------------ src/gpu/GrRenderTargetContext.h | 2 ++ src/gpu/GrRenderTargetProxy.cpp | 8 ++++--- src/gpu/GrSurfaceProxy.cpp | 38 +++++++++++++++++++++++++++------- src/gpu/GrTextureProxy.cpp | 8 ++++--- src/gpu/GrTextureRenderTargetProxy.cpp | 8 +++---- src/gpu/ops/GrStencilPathOp.cpp | 10 ++++++++- src/gpu/ops/GrStencilPathOp.h | 12 +++++------ 9 files changed, 64 insertions(+), 56 deletions(-) (limited to 'src/gpu') diff --git a/src/gpu/GrClipStackClip.cpp b/src/gpu/GrClipStackClip.cpp index 0a63e40076..49d56351b6 100644 --- a/src/gpu/GrClipStackClip.cpp +++ b/src/gpu/GrClipStackClip.cpp @@ -338,16 +338,7 @@ bool GrClipStackClip::apply(GrContext* context, GrRenderTargetContext* renderTar } } - GrRenderTarget* rt = renderTargetContext->accessRenderTarget(); - if (!rt) { - return true; - } - - // use the stencil clip if we can't represent the clip as a rectangle. - if (!context->resourceProvider()->attachStencilAttachment(rt)) { - SkDebugf("WARNING: failed to attach stencil buffer for clip mask. Clip will be ignored.\n"); - return true; - } + renderTargetContext->setNeedsStencil(); // This relies on the property that a reduced sub-rect of the last clip will contain all the // relevant window rectangles that were in the last clip. This subtle requirement will go away diff --git a/src/gpu/GrRenderTargetContext.cpp b/src/gpu/GrRenderTargetContext.cpp index e76b5ff26e..10f21e8ed2 100644 --- a/src/gpu/GrRenderTargetContext.cpp +++ b/src/gpu/GrRenderTargetContext.cpp @@ -648,22 +648,12 @@ void GrRenderTargetContextPriv::stencilPath(const GrClip& clip, // attempt this in a situation that would require coverage AA. SkASSERT(!appliedClip.clipCoverageFragmentProcessor()); - GrRenderTarget* rt = fRenderTargetContext->accessRenderTarget(); - if (!rt) { - return; - } - GrStencilAttachment* stencilAttachment = - fRenderTargetContext->fContext->resourceProvider()->attachStencilAttachment(rt); - if (!stencilAttachment) { - SkDebugf("ERROR creating stencil attachment. Draw skipped.\n"); - return; - } + fRenderTargetContext->setNeedsStencil(); std::unique_ptr op = GrStencilPathOp::Make(viewMatrix, useHWAA, path->getFillType(), appliedClip.hasStencilClip(), - stencilAttachment->bits(), appliedClip.scissorState(), path); if (!op) { @@ -1763,16 +1753,7 @@ uint32_t GrRenderTargetContext::addDrawOp(const GrClip& clip, std::unique_ptrgetOpList()->setRequiresStencil(); - // This forces instantiation of the render target. - GrRenderTarget* rt = this->accessRenderTarget(); - if (!rt) { - return SK_InvalidUniqueID; - } - - if (!fContext->resourceProvider()->attachStencilAttachment(rt)) { - SkDebugf("ERROR creating stencil attachment. Draw skipped.\n"); - return SK_InvalidUniqueID; - } + this->setNeedsStencil(); } GrXferProcessor::DstProxy dstProxy; diff --git a/src/gpu/GrRenderTargetContext.h b/src/gpu/GrRenderTargetContext.h index f012ebb2cf..2b9308a544 100644 --- a/src/gpu/GrRenderTargetContext.h +++ b/src/gpu/GrRenderTargetContext.h @@ -328,6 +328,8 @@ public: bool wasAbandoned() const; + void setNeedsStencil() { fRenderTargetProxy->setNeedsStencil(); } + GrRenderTarget* accessRenderTarget() { // TODO: usage of this entry point needs to be reduced and potentially eliminated // since it ends the deferral of the GrRenderTarget's allocation diff --git a/src/gpu/GrRenderTargetProxy.cpp b/src/gpu/GrRenderTargetProxy.cpp index 83809114ff..fff3d0bcea 100644 --- a/src/gpu/GrRenderTargetProxy.cpp +++ b/src/gpu/GrRenderTargetProxy.cpp @@ -22,6 +22,7 @@ GrRenderTargetProxy::GrRenderTargetProxy(const GrCaps& caps, const GrSurfaceDesc SkBackingFit fit, SkBudgeted budgeted, uint32_t flags) : INHERITED(desc, fit, budgeted, flags) , fSampleCnt(desc.fSampleCnt) + , fNeedsStencil(false) , fRenderTargetFlags(GrRenderTargetFlags::kNone) { // Since we know the newly created render target will be internal, we are able to precompute // what the flags will ultimately end up being. @@ -37,6 +38,7 @@ GrRenderTargetProxy::GrRenderTargetProxy(const GrCaps& caps, const GrSurfaceDesc GrRenderTargetProxy::GrRenderTargetProxy(sk_sp surf, GrSurfaceOrigin origin) : INHERITED(std::move(surf), origin, SkBackingFit::kExact) , fSampleCnt(fTarget->asRenderTarget()->numStencilSamples()) + , fNeedsStencil(false) , fRenderTargetFlags(fTarget->asRenderTarget()->renderTargetPriv().flags()) { } @@ -49,7 +51,7 @@ int GrRenderTargetProxy::maxWindowRectangles(const GrCaps& caps) const { bool GrRenderTargetProxy::instantiate(GrResourceProvider* resourceProvider) { static constexpr GrSurfaceFlags kFlags = kRenderTarget_GrSurfaceFlag; - if (!this->instantiateImpl(resourceProvider, fSampleCnt, kFlags, + if (!this->instantiateImpl(resourceProvider, fSampleCnt, fNeedsStencil, kFlags, /* isMipped = */ false, SkDestinationSurfaceColorMode::kLegacy)) { return false; @@ -64,8 +66,8 @@ bool GrRenderTargetProxy::instantiate(GrResourceProvider* resourceProvider) { sk_sp GrRenderTargetProxy::createSurface(GrResourceProvider* resourceProvider) const { static constexpr GrSurfaceFlags kFlags = kRenderTarget_GrSurfaceFlag; - sk_sp surface = this->createSurfaceImpl(resourceProvider, fSampleCnt, kFlags, - /* isMipped = */ false, + sk_sp surface = this->createSurfaceImpl(resourceProvider, fSampleCnt, fNeedsStencil, + kFlags, /* isMipped = */ false, SkDestinationSurfaceColorMode::kLegacy); if (!surface) { return nullptr; diff --git a/src/gpu/GrSurfaceProxy.cpp b/src/gpu/GrSurfaceProxy.cpp index f8639406d6..6a55270b34 100644 --- a/src/gpu/GrSurfaceProxy.cpp +++ b/src/gpu/GrSurfaceProxy.cpp @@ -43,8 +43,26 @@ GrSurfaceProxy::~GrSurfaceProxy() { SkASSERT(!fLastOpList); } +static bool attach_stencil_if_needed(GrResourceProvider* resourceProvider, + GrSurface* surface, bool needsStencil) { + if (needsStencil) { + GrRenderTarget* rt = surface->asRenderTarget(); + if (!rt) { + SkASSERT(0); + return false; + } + + if (!resourceProvider->attachStencilAttachment(rt)) { + return false; + } + } + + return true; +} + sk_sp GrSurfaceProxy::createSurfaceImpl( - GrResourceProvider* resourceProvider, int sampleCnt, + GrResourceProvider* resourceProvider, + int sampleCnt, bool needsStencil, GrSurfaceFlags flags, bool isMipMapped, SkDestinationSurfaceColorMode mipColorMode) const { GrSurfaceDesc desc; @@ -65,8 +83,14 @@ sk_sp GrSurfaceProxy::createSurfaceImpl( } else { surface.reset(resourceProvider->createTexture(desc, fBudgeted, fFlags).release()); } - if (surface) { - surface->asTexture()->texturePriv().setMipColorMode(mipColorMode); + if (!surface) { + return nullptr; + } + + surface->asTexture()->texturePriv().setMipColorMode(mipColorMode); + + if (!attach_stencil_if_needed(resourceProvider, surface.get(), needsStencil)) { + return nullptr; } return surface; @@ -85,14 +109,14 @@ void GrSurfaceProxy::assign(sk_sp surface) { } bool GrSurfaceProxy::instantiateImpl(GrResourceProvider* resourceProvider, int sampleCnt, - GrSurfaceFlags flags, bool isMipMapped, + bool needsStencil, GrSurfaceFlags flags, bool isMipMapped, SkDestinationSurfaceColorMode mipColorMode) { if (fTarget) { - return true; + return attach_stencil_if_needed(resourceProvider, fTarget, needsStencil); } - sk_sp surface = this->createSurfaceImpl(resourceProvider, sampleCnt, flags, - isMipMapped, mipColorMode); + sk_sp surface = this->createSurfaceImpl(resourceProvider, sampleCnt, needsStencil, + flags, isMipMapped, mipColorMode); if (!surface) { return false; } diff --git a/src/gpu/GrTextureProxy.cpp b/src/gpu/GrTextureProxy.cpp index 21533df0ee..5bacc977e8 100644 --- a/src/gpu/GrTextureProxy.cpp +++ b/src/gpu/GrTextureProxy.cpp @@ -24,8 +24,8 @@ GrTextureProxy::GrTextureProxy(sk_sp surf, GrSurfaceOrigin origin) } bool GrTextureProxy::instantiate(GrResourceProvider* resourceProvider) { - if (!this->instantiateImpl(resourceProvider, 0, kNone_GrSurfaceFlags, fIsMipMapped, - fMipColorMode)) { + if (!this->instantiateImpl(resourceProvider, 0, /* needsStencil = */ false, + kNone_GrSurfaceFlags, fIsMipMapped, fMipColorMode)) { return false; } @@ -34,7 +34,9 @@ bool GrTextureProxy::instantiate(GrResourceProvider* resourceProvider) { } sk_sp GrTextureProxy::createSurface(GrResourceProvider* resourceProvider) const { - sk_sp surface= this->createSurfaceImpl(resourceProvider, 0, kNone_GrSurfaceFlags, + sk_sp surface= this->createSurfaceImpl(resourceProvider, 0, + /* needsStencil = */ false, + kNone_GrSurfaceFlags, fIsMipMapped, fMipColorMode); if (!surface) { return nullptr; diff --git a/src/gpu/GrTextureRenderTargetProxy.cpp b/src/gpu/GrTextureRenderTargetProxy.cpp index 1bb0e239fd..4a4d79c531 100644 --- a/src/gpu/GrTextureRenderTargetProxy.cpp +++ b/src/gpu/GrTextureRenderTargetProxy.cpp @@ -48,8 +48,8 @@ size_t GrTextureRenderTargetProxy::onUninstantiatedGpuMemorySize() const { bool GrTextureRenderTargetProxy::instantiate(GrResourceProvider* resourceProvider) { static constexpr GrSurfaceFlags kFlags = kRenderTarget_GrSurfaceFlag; - if (!this->instantiateImpl(resourceProvider, this->numStencilSamples(), kFlags, - this->isMipMapped(), this->mipColorMode())) { + if (!this->instantiateImpl(resourceProvider, this->numStencilSamples(), this->needsStencil(), + kFlags, this->isMipMapped(), this->mipColorMode())) { return false; } SkASSERT(fTarget->asRenderTarget()); @@ -63,8 +63,8 @@ sk_sp GrTextureRenderTargetProxy::createSurface( static constexpr GrSurfaceFlags kFlags = kRenderTarget_GrSurfaceFlag; sk_sp surface = this->createSurfaceImpl(resourceProvider, this->numStencilSamples(), - kFlags, this->isMipMapped(), - this->mipColorMode()); + this->needsStencil(), kFlags, + this->isMipMapped(), this->mipColorMode()); if (!surface) { return nullptr; } diff --git a/src/gpu/ops/GrStencilPathOp.cpp b/src/gpu/ops/GrStencilPathOp.cpp index 53a55cc979..4c89ec0b05 100644 --- a/src/gpu/ops/GrStencilPathOp.cpp +++ b/src/gpu/ops/GrStencilPathOp.cpp @@ -9,10 +9,18 @@ #include "GrGpu.h" #include "GrOpFlushState.h" +#include "GrRenderTargetPriv.h" void GrStencilPathOp::onExecute(GrOpFlushState* state) { + GrRenderTarget* rt = state->drawOpArgs().renderTarget(); + SkASSERT(rt); + + int numStencilBits = rt->renderTargetPriv().numStencilBits(); + GrStencilSettings stencil(GrPathRendering::GetStencilPassSettings(fFillType), + fHasStencilClip, numStencilBits); + GrPathRendering::StencilPathArgs args(fUseHWAA, state->drawOpArgs().fProxy, - &fViewMatrix, &fScissor, &fStencil); + &fViewMatrix, &fScissor, &stencil); state->gpu()->pathRendering()->stencilPath(args, fPath.get()); } diff --git a/src/gpu/ops/GrStencilPathOp.h b/src/gpu/ops/GrStencilPathOp.h index 45240be4fd..64df726536 100644 --- a/src/gpu/ops/GrStencilPathOp.h +++ b/src/gpu/ops/GrStencilPathOp.h @@ -23,13 +23,11 @@ public: bool useHWAA, GrPathRendering::FillType fillType, bool hasStencilClip, - int numStencilBits, const GrScissorState& scissor, const GrPath* path) { return std::unique_ptr(new GrStencilPathOp(viewMatrix, useHWAA, fillType, - hasStencilClip, numStencilBits, scissor, - path)); + hasStencilClip, scissor, path)); } const char* name() const override { return "StencilPathOp"; } @@ -46,14 +44,13 @@ private: bool useHWAA, GrPathRendering::FillType fillType, bool hasStencilClip, - int numStencilBits, const GrScissorState& scissor, const GrPath* path) : INHERITED(ClassID()) , fViewMatrix(viewMatrix) , fUseHWAA(useHWAA) - , fStencil(GrPathRendering::GetStencilPassSettings(fillType), hasStencilClip, - numStencilBits) + , fFillType(fillType) + , fHasStencilClip(hasStencilClip) , fScissor(scissor) , fPath(path) { this->setBounds(path->getBounds(), HasAABloat::kNo, IsZeroArea::kNo); @@ -67,7 +64,8 @@ private: SkMatrix fViewMatrix; bool fUseHWAA; - GrStencilSettings fStencil; + GrPathRendering::FillType fFillType; + bool fHasStencilClip; GrScissorState fScissor; GrPendingIOResource fPath; -- cgit v1.2.3