From ae5f9534b11915c6b927df2a681d2782d83a1b2f Mon Sep 17 00:00:00 2001 From: Brian Salomon Date: Tue, 31 Jul 2018 11:03:40 -0400 Subject: Remove unused GrGpuResourceRef and GrTGpuResourceRef Change-Id: I8b4b323549f51e4601ccb6612f65d354e163e93c Reviewed-on: https://skia-review.googlesource.com/144504 Auto-Submit: Brian Salomon Commit-Queue: Robert Phillips Reviewed-by: Robert Phillips --- gn/gpu.gni | 3 +- include/gpu/GrGpuResource.h | 2 - src/gpu/GrGpuResourceRef.cpp | 127 ------------------------------ src/gpu/GrGpuResourceRef.h | 179 ------------------------------------------ src/gpu/GrMesh.h | 4 +- src/gpu/GrPendingIOResource.h | 74 +++++++++++++++++ src/gpu/GrPipeline.h | 2 +- src/gpu/GrProcessor.h | 1 - tests/ProxyRefTest.cpp | 2 +- 9 files changed, 78 insertions(+), 316 deletions(-) delete mode 100644 src/gpu/GrGpuResourceRef.cpp delete mode 100644 src/gpu/GrGpuResourceRef.h create mode 100644 src/gpu/GrPendingIOResource.h diff --git a/gn/gpu.gni b/gn/gpu.gni index ca86484d58..f4877a51b9 100644 --- a/gn/gpu.gni +++ b/gn/gpu.gni @@ -101,8 +101,6 @@ skia_gpu_sources = [ "$_src/gpu/GrGpuCommandBuffer.h", "$_src/gpu/GrGpuResourcePriv.h", "$_src/gpu/GrGpuResource.cpp", - "$_src/gpu/GrGpuResourceRef.cpp", - "$_src/gpu/GrGpuResourceRef.h", "$_src/gpu/GrImageTextureMaker.cpp", "$_src/gpu/GrImageTextureMaker.h", "$_src/gpu/GrMemoryPool.cpp", @@ -126,6 +124,7 @@ skia_gpu_sources = [ "$_src/gpu/GrPathRendering.h", "$_src/gpu/GrPathUtils.cpp", "$_src/gpu/GrPathUtils.h", + "$_src/gpu/GrPendingIOResource.h", "$_src/gpu/GrPendingProgramElement.h", "$_src/gpu/GrOnFlushResourceProvider.cpp", "$_src/gpu/GrOnFlushResourceProvider.h", diff --git a/include/gpu/GrGpuResource.h b/include/gpu/GrGpuResource.h index 57e52b4e78..3ecf6e759c 100644 --- a/include/gpu/GrGpuResource.h +++ b/include/gpu/GrGpuResource.h @@ -133,8 +133,6 @@ private: mutable int32_t fPendingReads; mutable int32_t fPendingWrites; - // This class is used to manage conversion of refs to pending reads/writes. - friend class GrGpuResourceRef; friend class GrResourceCache; // to check IO ref counts. template friend class GrPendingIOResource; diff --git a/src/gpu/GrGpuResourceRef.cpp b/src/gpu/GrGpuResourceRef.cpp deleted file mode 100644 index 532e0655d8..0000000000 --- a/src/gpu/GrGpuResourceRef.cpp +++ /dev/null @@ -1,127 +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. - */ - -#include "GrGpuResourceRef.h" - -GrGpuResourceRef::GrGpuResourceRef() { - fResource = nullptr; - fOwnRef = false; - fPendingIO = false; -} - -GrGpuResourceRef::GrGpuResourceRef(GrGpuResource* resource, GrIOType ioType) { - fResource = nullptr; - fOwnRef = false; - fPendingIO = false; - this->setResource(resource, ioType); -} - -GrGpuResourceRef::~GrGpuResourceRef() { - if (fOwnRef) { - SkASSERT(fResource); - fResource->unref(); - } - if (fPendingIO) { - switch (fIOType) { - case kRead_GrIOType: - fResource->completedRead(); - break; - case kWrite_GrIOType: - fResource->completedWrite(); - break; - case kRW_GrIOType: - fResource->completedRead(); - fResource->completedWrite(); - break; - } - } -} - -void GrGpuResourceRef::reset() { - SkASSERT(!fPendingIO); - SkASSERT(SkToBool(fResource) == fOwnRef); - if (fOwnRef) { - fResource->unref(); - fOwnRef = false; - fResource = nullptr; - } -} - -void GrGpuResourceRef::setResource(GrGpuResource* resource, GrIOType ioType) { - SkASSERT(!fPendingIO); - SkASSERT(SkToBool(fResource) == fOwnRef); - SkSafeUnref(fResource); - if (nullptr == resource) { - fResource = nullptr; - fOwnRef = false; - } else { - fResource = resource; - fOwnRef = true; - fIOType = ioType; - } -} - -void GrGpuResourceRef::markPendingIO() const { - if (!fResource) { - return; - } - - // This should only be called when the owning GrProgramElement gets its first - // pendingExecution ref. - SkASSERT(!fPendingIO); - fPendingIO = true; - switch (fIOType) { - case kRead_GrIOType: - fResource->addPendingRead(); - break; - case kWrite_GrIOType: - fResource->addPendingWrite(); - break; - case kRW_GrIOType: - fResource->addPendingRead(); - fResource->addPendingWrite(); - break; - } -} - -void GrGpuResourceRef::pendingIOComplete() const { - if (!fResource) { - return; - } - - // This should only be called when the owner's pending executions have ocurred but it is still - // reffed. - SkASSERT(fOwnRef); - SkASSERT(fPendingIO); - switch (fIOType) { - case kRead_GrIOType: - fResource->completedRead(); - break; - case kWrite_GrIOType: - fResource->completedWrite(); - break; - case kRW_GrIOType: - fResource->completedRead(); - fResource->completedWrite(); - break; - - } - fPendingIO = false; -} - -void GrGpuResourceRef::removeRef() const { - if (!fResource) { - return; - } - - // This should only be called once, when the owners last ref goes away and - // there is a pending execution. - SkASSERT(fOwnRef); - SkASSERT(fPendingIO); - fResource->unref(); - fOwnRef = false; -} diff --git a/src/gpu/GrGpuResourceRef.h b/src/gpu/GrGpuResourceRef.h deleted file mode 100644 index 672865329b..0000000000 --- a/src/gpu/GrGpuResourceRef.h +++ /dev/null @@ -1,179 +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 GrGpuResourceRef_DEFINED -#define GrGpuResourceRef_DEFINED - -#include "GrGpuResource.h" -#include "SkNoncopyable.h" -#include "SkRefCnt.h" - -/** - * This class is intended only for internal use in core Gr code. - * - * Class that wraps a resource referenced by a GrProgramElement or GrDrawState. It manages - * converting refs to pending IO operations. It allows a resource ownership to be in three - * states: - * 1. Owns a single ref - * 2. Owns a single ref and a pending IO operation (read, write, or read-write) - * 3. Owns a single pending IO operation. - * - * It is legal to destroy the GrGpuResourceRef in any of these states. It starts in state - * 1. Calling markPendingIO() converts it from state 1 to state 2. Calling removeRef() goes from - * state 2 to state 3. Calling pendingIOComplete() moves from state 2 to state 1. There is no - * valid way of going from state 3 back to 2 or 1. - * - * Like sk_sp, its constructor and setter adopt a ref from their caller. - * - * TODO: Once GrDODrawState no longer exists and therefore GrDrawState and GrOptDrawState no - * longer share an instance of this class, attempt to make the resource owned by GrGpuResourceRef - * only settable via the constructor. - */ -class GrGpuResourceRef : SkNoncopyable { -public: - ~GrGpuResourceRef(); - - GrGpuResource* getResource() const { return fResource; } - - /** Does this object own a pending read or write on the resource it is wrapping. */ - bool ownsPendingIO() const { return fPendingIO; } - - /** What type of IO does this represent? This is independent of whether a normal ref or a - pending IO is currently held. */ - GrIOType ioType() const { return fIOType; } - - /** Shortcut for calling setResource() with NULL. It cannot be called after markingPendingIO - is called. */ - void reset(); - -protected: - GrGpuResourceRef(); - - /** Adopts a ref from the caller. ioType expresses what type of IO operations will be marked as - pending on the resource when markPendingIO is called. */ - GrGpuResourceRef(GrGpuResource*, GrIOType); - - /** Adopts a ref from the caller. ioType expresses what type of IO operations will be marked as - pending on the resource when markPendingIO is called. */ - void setResource(GrGpuResource*, GrIOType); - -private: - /** Called by owning GrProgramElement when the program element is first scheduled for - execution. It can only be called once. */ - void markPendingIO() const; - - /** Called when the program element/draw state is no longer owned by GrOpList-client code. - This lets the cache know that the drawing code will no longer schedule additional reads or - writes to the resource using the program element or draw state. It can only be called once. - */ - void removeRef() const; - - /** Called to indicate that the previous pending IO is complete. Useful when the owning object - still has refs, so it is not about to destroy this GrGpuResourceRef, but its previously - pending executions have been complete. Can only be called if removeRef() was not previously - called. */ - void pendingIOComplete() const; - - friend class GrResourceIOProcessor; - - GrGpuResource* fResource; - mutable bool fOwnRef; - mutable bool fPendingIO; - GrIOType fIOType; - - typedef SkNoncopyable INHERITED; -}; - -/** - * Templated version of GrGpuResourceRef to enforce type safety. - */ -template class GrTGpuResourceRef : public GrGpuResourceRef { -public: - GrTGpuResourceRef() {} - - /** Adopts a ref from the caller. ioType expresses what type of IO operations will be marked as - pending on the resource when markPendingIO is called. */ - GrTGpuResourceRef(T* resource, GrIOType ioType) : INHERITED(resource, ioType) {} - GrTGpuResourceRef(sk_sp resource, GrIOType ioType) : INHERITED(resource, ioType) {} - - T* get() const { return static_cast(this->getResource()); } - - /** Adopts a ref from the caller. ioType expresses what type of IO operations will be marked as - pending on the resource when markPendingIO is called. */ - void set(T* resource, GrIOType ioType) { this->setResource(resource, ioType); } - -private: - typedef GrGpuResourceRef INHERITED; -}; - -/** - * This is similar to GrTGpuResourceRef but can only be in the pending IO state. It never owns a - * ref. - */ -template class GrPendingIOResource : SkNoncopyable { -public: - GrPendingIOResource(T* resource = nullptr) : fResource(nullptr) { - this->reset(resource); - } - - GrPendingIOResource(const GrPendingIOResource& that) - : GrPendingIOResource(that.get()) { - } - - 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; - } - - ~GrPendingIOResource() { - this->release(); - } - - explicit operator bool() const { return SkToBool(fResource); } - - bool operator==(const GrPendingIOResource& other) const { - return fResource == other.fResource; - } - - T* get() 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; -}; - -#endif diff --git a/src/gpu/GrMesh.h b/src/gpu/GrMesh.h index 1c9fac4425..fb7b52516a 100644 --- a/src/gpu/GrMesh.h +++ b/src/gpu/GrMesh.h @@ -9,7 +9,7 @@ #define GrMesh_DEFINED #include "GrBuffer.h" -#include "GrGpuResourceRef.h" +#include "GrPendingIOResource.h" class GrPrimitiveProcessor; @@ -75,8 +75,6 @@ public: void sendToGpu(SendToGpuImpl*) const; - struct PatternBatch; - private: using PendingBuffer = GrPendingIOResource; diff --git a/src/gpu/GrPendingIOResource.h b/src/gpu/GrPendingIOResource.h new file mode 100644 index 0000000000..9aeb65a2d3 --- /dev/null +++ b/src/gpu/GrPendingIOResource.h @@ -0,0 +1,74 @@ +/* + * 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 "GrGpuResource.h" +#include "SkNoncopyable.h" +#include "SkRefCnt.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(T* resource = nullptr) : fResource(nullptr) { this->reset(resource); } + + GrPendingIOResource(const GrPendingIOResource& that) : GrPendingIOResource(that.get()) {} + + 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; + } + + ~GrPendingIOResource() { this->release(); } + + explicit operator bool() const { return SkToBool(fResource); } + + bool operator==(const GrPendingIOResource& other) const { return fResource == other.fResource; } + + T* get() 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; +}; + +#endif diff --git a/src/gpu/GrPipeline.h b/src/gpu/GrPipeline.h index 3e5b64310f..cb741ae445 100644 --- a/src/gpu/GrPipeline.h +++ b/src/gpu/GrPipeline.h @@ -11,6 +11,7 @@ #include "GrColor.h" #include "GrFragmentProcessor.h" #include "GrNonAtomicRef.h" +#include "GrPendingIOResource.h" #include "GrPendingProgramElement.h" #include "GrProcessorSet.h" #include "GrProgramDesc.h" @@ -27,7 +28,6 @@ #include "effects/GrSimpleTextureEffect.h" class GrAppliedClip; -class GrDeviceCoordTexture; class GrOp; class GrRenderTargetContext; diff --git a/src/gpu/GrProcessor.h b/src/gpu/GrProcessor.h index beac0e5c5a..f4a1e1682b 100644 --- a/src/gpu/GrProcessor.h +++ b/src/gpu/GrProcessor.h @@ -11,7 +11,6 @@ #include "../private/SkAtomics.h" #include "GrBuffer.h" #include "GrColor.h" -#include "GrGpuResourceRef.h" #include "GrProcessorUnitTest.h" #include "GrProgramElement.h" #include "GrSamplerState.h" diff --git a/tests/ProxyRefTest.cpp b/tests/ProxyRefTest.cpp index 8161827c2d..914bf283e4 100644 --- a/tests/ProxyRefTest.cpp +++ b/tests/ProxyRefTest.cpp @@ -10,7 +10,7 @@ #include "Test.h" #include "GrContextPriv.h" -#include "GrGpuResourceRef.h" +#include "GrPendingIOResource.h" #include "GrProxyProvider.h" #include "GrRenderTargetProxy.h" #include "GrResourceProvider.h" -- cgit v1.2.3