From e1efd38cf0c05ebb8a06a19e15800eee53ce1e0a Mon Sep 17 00:00:00 2001 From: Robert Phillips Date: Wed, 21 Aug 2019 10:07:10 -0400 Subject: [PATCH] Remove GrPendingIOResource AFAICT these three remaining uses of GrPendingIOResource were just real-ref placeholders (i.e., they just added 1 pending read and then held on to the GrPendingIOResource until object destruction). Change-Id: Iba6bb199477d846d079999f09794422e240c675a Reviewed-on: https://skia-review.googlesource.com/c/skia/+/235458 Reviewed-by: Greg Daniel Commit-Queue: Robert Phillips --- gn/gpu.gni | 1 - src/gpu/GrMesh.h | 1 - src/gpu/GrPathRendering_none.cpp | 3 +- src/gpu/GrPendingIOResource.h | 82 ------------------- src/gpu/GrPipeline.h | 1 - src/gpu/GrRenderTargetContext.cpp | 5 +- src/gpu/GrRenderTargetContextPriv.h | 2 +- src/gpu/GrResourceCache.cpp | 3 + src/gpu/ops/GrDrawPathOp.cpp | 4 +- src/gpu/ops/GrDrawPathOp.h | 10 +-- src/gpu/ops/GrStencilAndCoverPathRenderer.cpp | 7 +- src/gpu/ops/GrStencilPathOp.cpp | 9 +- src/gpu/ops/GrStencilPathOp.h | 22 ++--- src/gpu/vk/GrVkGpuCommandBuffer.cpp | 23 +++--- src/gpu/vk/GrVkGpuCommandBuffer.h | 3 +- tests/ProxyRefTest.cpp | 1 - 16 files changed, 45 insertions(+), 132 deletions(-) delete mode 100644 src/gpu/GrPendingIOResource.h diff --git a/gn/gpu.gni b/gn/gpu.gni index 16bb7b96be..29e9491395 100644 --- a/gn/gpu.gni +++ b/gn/gpu.gni @@ -127,7 +127,6 @@ skia_gpu_sources = [ "$_src/gpu/GrPathRendererChain.h", "$_src/gpu/GrPathRenderer.cpp", "$_src/gpu/GrPathRenderer.h", - "$_src/gpu/GrPendingIOResource.h", "$_src/gpu/GrOnFlushResourceProvider.cpp", "$_src/gpu/GrOnFlushResourceProvider.h", "$_src/gpu/GrPipeline.cpp", diff --git a/src/gpu/GrMesh.h b/src/gpu/GrMesh.h index e968bd4b6a..08daf0e32b 100644 --- a/src/gpu/GrMesh.h +++ b/src/gpu/GrMesh.h @@ -10,7 +10,6 @@ #include "src/gpu/GrBuffer.h" #include "src/gpu/GrGpuBuffer.h" -#include "src/gpu/GrPendingIOResource.h" class GrPrimitiveProcessor; diff --git a/src/gpu/GrPathRendering_none.cpp b/src/gpu/GrPathRendering_none.cpp index c526a23ba4..3cee3958c9 100644 --- a/src/gpu/GrPathRendering_none.cpp +++ b/src/gpu/GrPathRendering_none.cpp @@ -54,9 +54,8 @@ void GrGLPathRendering::onStencilPath(const StencilPathArgs&, const GrPath*) {} std::unique_ptr GrStencilPathOp::Make(GrRecordingContext*, const SkMatrix&, bool, - GrPathRendering::FillType, bool, const GrScissorState&, - const GrPath*) { return nullptr; } + sk_sp) { return nullptr; } void GrPath::ComputeKey(const GrShape&, GrUniqueKey*, bool*) {} diff --git a/src/gpu/GrPendingIOResource.h b/src/gpu/GrPendingIOResource.h deleted file mode 100644 index 17bec297ea..0000000000 --- a/src/gpu/GrPendingIOResource.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright 2014 Google Inc. - * - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#ifndef GrPendingIOResource_DEFINED -#define GrPendingIOResource_DEFINED - -#include "include/core/SkRefCnt.h" -#include "include/gpu/GrGpuResource.h" -#include "include/private/SkNoncopyable.h" -#include "src/gpu/GrSurfaceProxy.h" - -/** - * Helper for owning a pending read, write, read-write on a GrGpuResource. It never owns a regular - * ref. - */ -template -class GrPendingIOResource : SkNoncopyable { -public: - GrPendingIOResource() = default; - GrPendingIOResource(T* resource) { this->reset(resource); } - GrPendingIOResource(sk_sp resource) { *this = std::move(resource); } - GrPendingIOResource(const GrPendingIOResource& that) : GrPendingIOResource(that.get()) {} - ~GrPendingIOResource() { this->release(); } - - GrPendingIOResource& operator=(sk_sp resource) { - this->reset(resource.get()); - return *this; - } - - void reset(T* resource = nullptr) { - if (resource) { - switch (IO_TYPE) { - case kRead_GrIOType: - resource->addPendingRead(); - break; - case kWrite_GrIOType: - resource->addPendingWrite(); - break; - case kRW_GrIOType: - resource->addPendingRead(); - resource->addPendingWrite(); - break; - } - } - this->release(); - fResource = resource; - } - - explicit operator bool() const { return SkToBool(fResource); } - - bool operator==(const GrPendingIOResource& other) const { return fResource == other.fResource; } - - T* get() const { return fResource; } - T* operator*() const { return *fResource; } - T* operator->() const { return fResource; } - -private: - void release() { - if (fResource) { - switch (IO_TYPE) { - case kRead_GrIOType: - fResource->completedRead(); - break; - case kWrite_GrIOType: - fResource->completedWrite(); - break; - case kRW_GrIOType: - fResource->completedRead(); - fResource->completedWrite(); - break; - } - } - } - - T* fResource = nullptr; -}; - -#endif diff --git a/src/gpu/GrPipeline.h b/src/gpu/GrPipeline.h index cacf02034c..b57e66d200 100644 --- a/src/gpu/GrPipeline.h +++ b/src/gpu/GrPipeline.h @@ -13,7 +13,6 @@ #include "src/gpu/GrColor.h" #include "src/gpu/GrFragmentProcessor.h" #include "src/gpu/GrNonAtomicRef.h" -#include "src/gpu/GrPendingIOResource.h" #include "src/gpu/GrProcessorSet.h" #include "src/gpu/GrProgramDesc.h" #include "src/gpu/GrScissorState.h" diff --git a/src/gpu/GrRenderTargetContext.cpp b/src/gpu/GrRenderTargetContext.cpp index 8dda26775d..df423b585b 100644 --- a/src/gpu/GrRenderTargetContext.cpp +++ b/src/gpu/GrRenderTargetContext.cpp @@ -875,7 +875,7 @@ void GrRenderTargetContext::internalStencilClear(const GrFixedClip& clip, bool i void GrRenderTargetContextPriv::stencilPath(const GrHardClip& clip, GrAA doStencilMSAA, const SkMatrix& viewMatrix, - const GrPath* path) { + sk_sp path) { ASSERT_SINGLE_OWNER_PRIV RETURN_IF_ABANDONED_PRIV SkDEBUGCODE(fRenderTargetContext->validate();) @@ -900,10 +900,9 @@ void GrRenderTargetContextPriv::stencilPath(const GrHardClip& clip, std::unique_ptr op = GrStencilPathOp::Make(fRenderTargetContext->fContext, viewMatrix, GrAA::kYes == doStencilMSAA, - path->getFillType(), appliedClip.hasStencilClip(), appliedClip.scissorState(), - path); + std::move(path)); if (!op) { return; } diff --git a/src/gpu/GrRenderTargetContextPriv.h b/src/gpu/GrRenderTargetContextPriv.h index ef60655f8a..f816ea77fc 100644 --- a/src/gpu/GrRenderTargetContextPriv.h +++ b/src/gpu/GrRenderTargetContextPriv.h @@ -78,7 +78,7 @@ public: } void stencilPath( - const GrHardClip&, GrAA doStencilMSAA, const SkMatrix& viewMatrix, const GrPath*); + const GrHardClip&, GrAA doStencilMSAA, const SkMatrix& viewMatrix, sk_sp); /** * Draws a path, either AA or not, and touches the stencil buffer with the user stencil settings diff --git a/src/gpu/GrResourceCache.cpp b/src/gpu/GrResourceCache.cpp index 4dd0481daa..0f7deb3fbf 100644 --- a/src/gpu/GrResourceCache.cpp +++ b/src/gpu/GrResourceCache.cpp @@ -862,6 +862,9 @@ void GrResourceCache::validate() const { void update(GrGpuResource* resource) { fBytes += resource->gpuMemorySize(); + // No resource should ever have pendingIO any more + SkASSERT(!resource->internalHasPendingIO()); + if (!resource->resourcePriv().isPurgeable()) { ++fLocked; } diff --git a/src/gpu/ops/GrDrawPathOp.cpp b/src/gpu/ops/GrDrawPathOp.cpp index 43885242fe..5d93e45cae 100644 --- a/src/gpu/ops/GrDrawPathOp.cpp +++ b/src/gpu/ops/GrDrawPathOp.cpp @@ -79,10 +79,10 @@ std::unique_ptr GrDrawPathOp::Make(GrRecordingContext* context, const SkMatrix& viewMatrix, GrPaint&& paint, GrAA aa, - GrPath* path) { + sk_sp path) { GrOpMemoryPool* pool = context->priv().opMemoryPool(); - return pool->allocate(viewMatrix, std::move(paint), aa, path); + return pool->allocate(viewMatrix, std::move(paint), aa, std::move(path)); } void GrDrawPathOp::onExecute(GrOpFlushState* state, const SkRect& chainBounds) { diff --git a/src/gpu/ops/GrDrawPathOp.h b/src/gpu/ops/GrDrawPathOp.h index cd4ecc30c9..fd9631b761 100644 --- a/src/gpu/ops/GrDrawPathOp.h +++ b/src/gpu/ops/GrDrawPathOp.h @@ -71,7 +71,7 @@ public: DEFINE_OP_CLASS_ID static std::unique_ptr Make( - GrRecordingContext*, const SkMatrix& viewMatrix, GrPaint&&, GrAA, GrPath*); + GrRecordingContext*, const SkMatrix& viewMatrix, GrPaint&&, GrAA, sk_sp); const char* name() const override { return "DrawPath"; } @@ -82,16 +82,16 @@ public: private: friend class GrOpMemoryPool; // for ctor - GrDrawPathOp(const SkMatrix& viewMatrix, GrPaint&& paint, GrAA aa, const GrPath* path) + GrDrawPathOp(const SkMatrix& viewMatrix, GrPaint&& paint, GrAA aa, sk_sp path) : GrDrawPathOpBase( ClassID(), viewMatrix, std::move(paint), path->getFillType(), aa) - , fPath(path) { - this->setTransformedBounds(path->getBounds(), viewMatrix, HasAABloat::kNo, IsZeroArea::kNo); + , fPath(std::move(path)) { + this->setTransformedBounds(fPath->getBounds(), viewMatrix, HasAABloat::kNo, IsZeroArea::kNo); } void onExecute(GrOpFlushState*, const SkRect& chainBounds) override; - GrPendingIOResource fPath; + sk_sp fPath; typedef GrDrawPathOpBase INHERITED; }; diff --git a/src/gpu/ops/GrStencilAndCoverPathRenderer.cpp b/src/gpu/ops/GrStencilAndCoverPathRenderer.cpp index b2a41051cd..c05b955d8e 100644 --- a/src/gpu/ops/GrStencilAndCoverPathRenderer.cpp +++ b/src/gpu/ops/GrStencilAndCoverPathRenderer.cpp @@ -79,7 +79,7 @@ void GrStencilAndCoverPathRenderer::onStencilPath(const StencilPathArgs& args) { "GrStencilAndCoverPathRenderer::onStencilPath"); sk_sp p(get_gr_path(fResourceProvider, *args.fShape)); args.fRenderTargetContext->priv().stencilPath( - *args.fClip, args.fDoStencilMSAA, *args.fViewMatrix, p.get()); + *args.fClip, args.fDoStencilMSAA, *args.fViewMatrix, std::move(p)); } bool GrStencilAndCoverPathRenderer::onDrawPath(const DrawPathArgs& args) { @@ -120,7 +120,7 @@ bool GrStencilAndCoverPathRenderer::onDrawPath(const DrawPathArgs& args) { // Just ignore the analytic FPs (if any) during the stencil pass. They will still clip the // final draw and it is meaningless to multiply by coverage when drawing to stencil. args.fRenderTargetContext->priv().stencilPath( - stencilClip, GrAA(doStencilMSAA), viewMatrix, path.get()); + stencilClip, GrAA(doStencilMSAA), viewMatrix, std::move(path)); { static constexpr GrUserStencilSettings kInvertedCoverPass( @@ -162,7 +162,8 @@ bool GrStencilAndCoverPathRenderer::onDrawPath(const DrawPathArgs& args) { } } else { std::unique_ptr op = GrDrawPathOp::Make( - args.fContext, viewMatrix, std::move(args.fPaint), GrAA(doStencilMSAA), path.get()); + args.fContext, viewMatrix, std::move(args.fPaint), GrAA(doStencilMSAA), + std::move(path)); args.fRenderTargetContext->addDrawOp(*args.fClip, std::move(op)); } diff --git a/src/gpu/ops/GrStencilPathOp.cpp b/src/gpu/ops/GrStencilPathOp.cpp index f0b9f5a5e1..0707678f56 100644 --- a/src/gpu/ops/GrStencilPathOp.cpp +++ b/src/gpu/ops/GrStencilPathOp.cpp @@ -17,14 +17,13 @@ std::unique_ptr GrStencilPathOp::Make(GrRecordingContext* context, const SkMatrix& viewMatrix, bool useHWAA, - GrPathRendering::FillType fillType, bool hasStencilClip, const GrScissorState& scissor, - const GrPath* path) { + sk_sp path) { GrOpMemoryPool* pool = context->priv().opMemoryPool(); - return pool->allocate(viewMatrix, useHWAA, fillType, - hasStencilClip, scissor, path); + return pool->allocate(viewMatrix, useHWAA, + hasStencilClip, scissor, std::move(path)); } void GrStencilPathOp::onExecute(GrOpFlushState* state, const SkRect& chainBounds) { @@ -32,7 +31,7 @@ void GrStencilPathOp::onExecute(GrOpFlushState* state, const SkRect& chainBounds SkASSERT(rt); int numStencilBits = rt->renderTargetPriv().numStencilBits(); - GrStencilSettings stencil(GrPathRendering::GetStencilPassSettings(fFillType), + GrStencilSettings stencil(GrPathRendering::GetStencilPassSettings(fPath->getFillType()), fHasStencilClip, numStencilBits); GrPathRendering::StencilPathArgs args(fUseHWAA, state->drawOpArgs().fProxy, diff --git a/src/gpu/ops/GrStencilPathOp.h b/src/gpu/ops/GrStencilPathOp.h index f78356bc8c..958c5c06de 100644 --- a/src/gpu/ops/GrStencilPathOp.h +++ b/src/gpu/ops/GrStencilPathOp.h @@ -23,10 +23,9 @@ public: static std::unique_ptr Make(GrRecordingContext* context, const SkMatrix& viewMatrix, bool useHWAA, - GrPathRendering::FillType fillType, bool hasStencilClip, const GrScissorState& scissor, - const GrPath* path); + sk_sp path); const char* name() const override { return "StencilPathOp"; } @@ -44,30 +43,27 @@ private: GrStencilPathOp(const SkMatrix& viewMatrix, bool useHWAA, - GrPathRendering::FillType fillType, bool hasStencilClip, const GrScissorState& scissor, - const GrPath* path) + sk_sp path) : INHERITED(ClassID()) , fViewMatrix(viewMatrix) , fUseHWAA(useHWAA) - , fFillType(fillType) , fHasStencilClip(hasStencilClip) , fScissor(scissor) - , fPath(path) { - this->setBounds(path->getBounds(), HasAABloat::kNo, IsZeroArea::kNo); + , fPath(std::move(path)) { + this->setBounds(fPath->getBounds(), HasAABloat::kNo, IsZeroArea::kNo); } void onPrepare(GrOpFlushState*) override {} void onExecute(GrOpFlushState*, const SkRect& chainBounds) override; - SkMatrix fViewMatrix; - bool fUseHWAA; - GrPathRendering::FillType fFillType; - bool fHasStencilClip; - GrScissorState fScissor; - GrPendingIOResource fPath; + SkMatrix fViewMatrix; + bool fUseHWAA; + bool fHasStencilClip; + GrScissorState fScissor; + sk_sp fPath; typedef GrOp INHERITED; }; diff --git a/src/gpu/vk/GrVkGpuCommandBuffer.cpp b/src/gpu/vk/GrVkGpuCommandBuffer.cpp index 0376a0f821..331728a19d 100644 --- a/src/gpu/vk/GrVkGpuCommandBuffer.cpp +++ b/src/gpu/vk/GrVkGpuCommandBuffer.cpp @@ -46,8 +46,9 @@ private: class Copy : public GrVkPrimaryCommandBufferTask { public: - Copy(GrSurface* src, const SkIRect& srcRect, const SkIPoint& dstPoint, bool shouldDiscardDst) - : fSrc(src) + Copy(sk_sp src, const SkIRect& srcRect, const SkIPoint& dstPoint, + bool shouldDiscardDst) + : fSrc(std::move(src)) , fSrcRect(srcRect) , fDstPoint(dstPoint) , fShouldDiscardDst(shouldDiscardDst) {} @@ -57,11 +58,10 @@ public: } private: - using Src = GrPendingIOResource; - Src fSrc; - SkIRect fSrcRect; - SkIPoint fDstPoint; - bool fShouldDiscardDst; + sk_sp fSrc; + SkIRect fSrcRect; + SkIPoint fDstPoint; + bool fShouldDiscardDst; }; } // anonymous namespace @@ -71,7 +71,7 @@ private: void GrVkGpuTextureCommandBuffer::copy(GrSurface* src, const SkIRect& srcRect, const SkIPoint& dstPoint) { SkASSERT(!src->isProtected() || (fTexture->isProtected() && fGpu->protectedContext())); - fTasks.emplace(src, srcRect, dstPoint, false); + fTasks.emplace(sk_ref_sp(src), srcRect, dstPoint, false); } void GrVkGpuTextureCommandBuffer::insertEventMarker(const char* msg) { @@ -549,7 +549,8 @@ void GrVkGpuRTCommandBuffer::copy(GrSurface* src, const SkIRect& srcRect, } fPreCommandBufferTasks.emplace( - src, srcRect, dstPoint, LoadStoreState::kStartsWithDiscard == cbInfo.fLoadStoreState); + sk_ref_sp(src), srcRect, dstPoint, + LoadStoreState::kStartsWithDiscard == cbInfo.fLoadStoreState); ++fCommandBufferInfos[fCurrentCmdInfo].fNumPreCmds; if (LoadStoreState::kLoadAndStore != cbInfo.fLoadStoreState) { @@ -792,7 +793,9 @@ void GrVkGpuRTCommandBuffer::onDraw(const GrPrimitiveProcessor& primProc, void GrVkGpuRTCommandBuffer::appendSampledTexture(GrTexture* tex) { SkASSERT(!tex->isProtected() || (fRenderTarget->isProtected() && fGpu->protectedContext())); - fCommandBufferInfos[fCurrentCmdInfo].fSampledTextures.push_back(static_cast(tex)); + GrVkTexture* vkTex = static_cast(tex); + + fCommandBufferInfos[fCurrentCmdInfo].fSampledTextures.push_back(sk_ref_sp(vkTex)); } void GrVkGpuRTCommandBuffer::sendInstancedMeshToGpu(GrPrimitiveType, diff --git a/src/gpu/vk/GrVkGpuCommandBuffer.h b/src/gpu/vk/GrVkGpuCommandBuffer.h index 8666591f78..a9283f4ff1 100644 --- a/src/gpu/vk/GrVkGpuCommandBuffer.h +++ b/src/gpu/vk/GrVkGpuCommandBuffer.h @@ -188,7 +188,6 @@ private: }; struct CommandBufferInfo { - using SampledTexture = GrPendingIOResource; const GrVkRenderPass* fRenderPass; std::unique_ptr fCommandBuffer; int fNumPreCmds = 0; @@ -199,7 +198,7 @@ private: // Array of images that will be sampled and thus need to be transferred to sampled layout // before submitting the secondary command buffers. This must happen after we do any predraw // uploads or copies. - SkTArray fSampledTextures; + SkTArray> fSampledTextures; GrVkSecondaryCommandBuffer* currentCmdBuf() { return fCommandBuffer.get(); diff --git a/tests/ProxyRefTest.cpp b/tests/ProxyRefTest.cpp index b82ab91d82..4629557dd8 100644 --- a/tests/ProxyRefTest.cpp +++ b/tests/ProxyRefTest.cpp @@ -11,7 +11,6 @@ #include "include/gpu/GrTexture.h" #include "src/gpu/GrContextPriv.h" -#include "src/gpu/GrPendingIOResource.h" #include "src/gpu/GrProxyProvider.h" #include "src/gpu/GrRenderTargetProxy.h" #include "src/gpu/GrResourceProvider.h"