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 <egdaniel@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
diff --git a/src/gpu/GrMesh.h b/src/gpu/GrMesh.h
index e968bd4..08daf0e 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 c526a23..3cee395 100644
--- a/src/gpu/GrPathRendering_none.cpp
+++ b/src/gpu/GrPathRendering_none.cpp
@@ -54,9 +54,8 @@
std::unique_ptr<GrOp> GrStencilPathOp::Make(GrRecordingContext*,
const SkMatrix&,
bool,
- GrPathRendering::FillType,
bool,
const GrScissorState&,
- const GrPath*) { return nullptr; }
+ sk_sp<const GrPath>) { 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 17bec29..0000000
--- 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 <typename T, GrIOType IO_TYPE>
-class GrPendingIOResource : SkNoncopyable {
-public:
- GrPendingIOResource() = default;
- GrPendingIOResource(T* resource) { this->reset(resource); }
- GrPendingIOResource(sk_sp<T> resource) { *this = std::move(resource); }
- GrPendingIOResource(const GrPendingIOResource& that) : GrPendingIOResource(that.get()) {}
- ~GrPendingIOResource() { this->release(); }
-
- GrPendingIOResource& operator=(sk_sp<T> 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 cacf020..b57e66d 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 8dda267..df423b5 100644
--- a/src/gpu/GrRenderTargetContext.cpp
+++ b/src/gpu/GrRenderTargetContext.cpp
@@ -875,7 +875,7 @@
void GrRenderTargetContextPriv::stencilPath(const GrHardClip& clip,
GrAA doStencilMSAA,
const SkMatrix& viewMatrix,
- const GrPath* path) {
+ sk_sp<const GrPath> path) {
ASSERT_SINGLE_OWNER_PRIV
RETURN_IF_ABANDONED_PRIV
SkDEBUGCODE(fRenderTargetContext->validate();)
@@ -900,10 +900,9 @@
std::unique_ptr<GrOp> 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 ef60655..f816ea7 100644
--- a/src/gpu/GrRenderTargetContextPriv.h
+++ b/src/gpu/GrRenderTargetContextPriv.h
@@ -78,7 +78,7 @@
}
void stencilPath(
- const GrHardClip&, GrAA doStencilMSAA, const SkMatrix& viewMatrix, const GrPath*);
+ const GrHardClip&, GrAA doStencilMSAA, const SkMatrix& viewMatrix, sk_sp<const GrPath>);
/**
* 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 4dd0481..0f7deb3 100644
--- a/src/gpu/GrResourceCache.cpp
+++ b/src/gpu/GrResourceCache.cpp
@@ -862,6 +862,9 @@
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 4388524..5d93e45 100644
--- a/src/gpu/ops/GrDrawPathOp.cpp
+++ b/src/gpu/ops/GrDrawPathOp.cpp
@@ -79,10 +79,10 @@
const SkMatrix& viewMatrix,
GrPaint&& paint,
GrAA aa,
- GrPath* path) {
+ sk_sp<const GrPath> path) {
GrOpMemoryPool* pool = context->priv().opMemoryPool();
- return pool->allocate<GrDrawPathOp>(viewMatrix, std::move(paint), aa, path);
+ return pool->allocate<GrDrawPathOp>(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 cd4ecc30..fd9631b 100644
--- a/src/gpu/ops/GrDrawPathOp.h
+++ b/src/gpu/ops/GrDrawPathOp.h
@@ -71,7 +71,7 @@
DEFINE_OP_CLASS_ID
static std::unique_ptr<GrDrawOp> Make(
- GrRecordingContext*, const SkMatrix& viewMatrix, GrPaint&&, GrAA, GrPath*);
+ GrRecordingContext*, const SkMatrix& viewMatrix, GrPaint&&, GrAA, sk_sp<const GrPath>);
const char* name() const override { return "DrawPath"; }
@@ -82,16 +82,16 @@
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<const GrPath> 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<const GrPath, kRead_GrIOType> fPath;
+ sk_sp<const GrPath> fPath;
typedef GrDrawPathOpBase INHERITED;
};
diff --git a/src/gpu/ops/GrStencilAndCoverPathRenderer.cpp b/src/gpu/ops/GrStencilAndCoverPathRenderer.cpp
index b2a4105..c05b955 100644
--- a/src/gpu/ops/GrStencilAndCoverPathRenderer.cpp
+++ b/src/gpu/ops/GrStencilAndCoverPathRenderer.cpp
@@ -79,7 +79,7 @@
"GrStencilAndCoverPathRenderer::onStencilPath");
sk_sp<GrPath> 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 @@
// 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 @@
}
} else {
std::unique_ptr<GrDrawOp> 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 f0b9f5a..0707678 100644
--- a/src/gpu/ops/GrStencilPathOp.cpp
+++ b/src/gpu/ops/GrStencilPathOp.cpp
@@ -17,14 +17,13 @@
std::unique_ptr<GrOp> GrStencilPathOp::Make(GrRecordingContext* context,
const SkMatrix& viewMatrix,
bool useHWAA,
- GrPathRendering::FillType fillType,
bool hasStencilClip,
const GrScissorState& scissor,
- const GrPath* path) {
+ sk_sp<const GrPath> path) {
GrOpMemoryPool* pool = context->priv().opMemoryPool();
- return pool->allocate<GrStencilPathOp>(viewMatrix, useHWAA, fillType,
- hasStencilClip, scissor, path);
+ return pool->allocate<GrStencilPathOp>(viewMatrix, useHWAA,
+ hasStencilClip, scissor, std::move(path));
}
void GrStencilPathOp::onExecute(GrOpFlushState* state, const SkRect& chainBounds) {
@@ -32,7 +31,7 @@
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 f78356b..958c5c0 100644
--- a/src/gpu/ops/GrStencilPathOp.h
+++ b/src/gpu/ops/GrStencilPathOp.h
@@ -23,10 +23,9 @@
static std::unique_ptr<GrOp> Make(GrRecordingContext* context,
const SkMatrix& viewMatrix,
bool useHWAA,
- GrPathRendering::FillType fillType,
bool hasStencilClip,
const GrScissorState& scissor,
- const GrPath* path);
+ sk_sp<const GrPath> path);
const char* name() const override { return "StencilPathOp"; }
@@ -44,30 +43,27 @@
GrStencilPathOp(const SkMatrix& viewMatrix,
bool useHWAA,
- GrPathRendering::FillType fillType,
bool hasStencilClip,
const GrScissorState& scissor,
- const GrPath* path)
+ sk_sp<const GrPath> 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<const GrPath, kRead_GrIOType> fPath;
+ SkMatrix fViewMatrix;
+ bool fUseHWAA;
+ bool fHasStencilClip;
+ GrScissorState fScissor;
+ sk_sp<const GrPath> fPath;
typedef GrOp INHERITED;
};
diff --git a/src/gpu/vk/GrVkGpuCommandBuffer.cpp b/src/gpu/vk/GrVkGpuCommandBuffer.cpp
index 0376a0f..331728a 100644
--- a/src/gpu/vk/GrVkGpuCommandBuffer.cpp
+++ b/src/gpu/vk/GrVkGpuCommandBuffer.cpp
@@ -46,8 +46,9 @@
class Copy : public GrVkPrimaryCommandBufferTask {
public:
- Copy(GrSurface* src, const SkIRect& srcRect, const SkIPoint& dstPoint, bool shouldDiscardDst)
- : fSrc(src)
+ Copy(sk_sp<GrSurface> src, const SkIRect& srcRect, const SkIPoint& dstPoint,
+ bool shouldDiscardDst)
+ : fSrc(std::move(src))
, fSrcRect(srcRect)
, fDstPoint(dstPoint)
, fShouldDiscardDst(shouldDiscardDst) {}
@@ -57,11 +58,10 @@
}
private:
- using Src = GrPendingIOResource<GrSurface, kRead_GrIOType>;
- Src fSrc;
- SkIRect fSrcRect;
- SkIPoint fDstPoint;
- bool fShouldDiscardDst;
+ sk_sp<GrSurface> fSrc;
+ SkIRect fSrcRect;
+ SkIPoint fDstPoint;
+ bool fShouldDiscardDst;
};
} // anonymous namespace
@@ -71,7 +71,7 @@
void GrVkGpuTextureCommandBuffer::copy(GrSurface* src, const SkIRect& srcRect,
const SkIPoint& dstPoint) {
SkASSERT(!src->isProtected() || (fTexture->isProtected() && fGpu->protectedContext()));
- fTasks.emplace<Copy>(src, srcRect, dstPoint, false);
+ fTasks.emplace<Copy>(sk_ref_sp(src), srcRect, dstPoint, false);
}
void GrVkGpuTextureCommandBuffer::insertEventMarker(const char* msg) {
@@ -549,7 +549,8 @@
}
fPreCommandBufferTasks.emplace<Copy>(
- 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::appendSampledTexture(GrTexture* tex) {
SkASSERT(!tex->isProtected() || (fRenderTarget->isProtected() && fGpu->protectedContext()));
- fCommandBufferInfos[fCurrentCmdInfo].fSampledTextures.push_back(static_cast<GrVkTexture*>(tex));
+ GrVkTexture* vkTex = static_cast<GrVkTexture*>(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 8666591..a9283f4 100644
--- a/src/gpu/vk/GrVkGpuCommandBuffer.h
+++ b/src/gpu/vk/GrVkGpuCommandBuffer.h
@@ -188,7 +188,6 @@
};
struct CommandBufferInfo {
- using SampledTexture = GrPendingIOResource<GrVkTexture, kRead_GrIOType>;
const GrVkRenderPass* fRenderPass;
std::unique_ptr<GrVkSecondaryCommandBuffer> fCommandBuffer;
int fNumPreCmds = 0;
@@ -199,7 +198,7 @@
// 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<SampledTexture> fSampledTextures;
+ SkTArray<sk_sp<GrVkTexture>> fSampledTextures;
GrVkSecondaryCommandBuffer* currentCmdBuf() {
return fCommandBuffer.get();