8 #ifndef GrGpuResource_DEFINED
9 #define GrGpuResource_DEFINED
11 #include "GrResourceKey.h"
12 #include "GrTypesPriv.h"
16 class GrResourceCache;
46 template <
typename DERIVED>
class GrIORef :
public SkNoncopyable {
61 if (!static_cast<const DERIVED*>(
this)->notifyRefCountIsZero()) {
66 this->didRemoveRefOrPendingIO(kRef_CntType);
69 void validate()
const {
71 SkASSERT(fRefCnt >= 0);
72 SkASSERT(fPendingReads >= 0);
73 SkASSERT(fPendingWrites >= 0);
74 SkASSERT(fRefCnt + fPendingReads + fPendingWrites >= 0);
79 GrIORef() : fRefCnt(1), fPendingReads(0), fPendingWrites(0) { }
84 kPendingWrite_CntType,
87 bool isPurgeable()
const {
return !this->internalHasRef() && !this->internalHasPendingIO(); }
89 bool internalHasPendingRead()
const {
return SkToBool(fPendingReads); }
90 bool internalHasPendingWrite()
const {
return SkToBool(fPendingWrites); }
91 bool internalHasPendingIO()
const {
return SkToBool(fPendingWrites | fPendingReads); }
93 bool internalHasRef()
const {
return SkToBool(fRefCnt); }
96 friend class GrIORefProxy;
99 friend void testingOnly_getIORefCnts(
const T*,
int* refCnt,
int* readCnt,
int* writeCnt);
101 void addPendingRead()
const {
106 void completedRead()
const {
109 this->didRemoveRefOrPendingIO(kPendingRead_CntType);
112 void addPendingWrite()
const {
117 void completedWrite()
const {
120 this->didRemoveRefOrPendingIO(kPendingWrite_CntType);
124 void didRemoveRefOrPendingIO(CntType cntTypeRemoved)
const {
125 if (0 == fPendingReads && 0 == fPendingWrites && 0 == fRefCnt) {
126 static_cast<const DERIVED*
>(
this)->notifyAllCntsAreZero(cntTypeRemoved);
130 mutable int32_t fRefCnt;
131 mutable int32_t fPendingReads;
132 mutable int32_t fPendingWrites;
135 friend class GrGpuResourceRef;
136 friend class GrResourceCache;
138 template <
typename, GrIOType>
friend class GrPendingIOResource;
176 if (kInvalidGpuMemorySize == fGpuMemorySize) {
177 fGpuMemorySize = this->onGpuMemorySize();
178 SkASSERT(kInvalidGpuMemorySize != fGpuMemorySize);
180 return fGpuMemorySize;
191 explicit UniqueID(uint32_t
id) : fID(
id) {}
193 uint32_t asUInt()
const {
return fID; }
195 bool operator==(
const UniqueID& other)
const {
196 return fID == other.fID;
198 bool operator!=(
const UniqueID& other)
const {
199 return !(*
this == other);
224 inline CacheAccess cacheAccess();
225 inline const CacheAccess cacheAccess()
const;
231 inline ResourcePriv resourcePriv();
232 inline const ResourcePriv resourcePriv()
const;
251 static uint32_t CreateUniqueID();
256 void registerWithCache(SkBudgeted);
261 void registerWithCacheWrapped();
266 GrGpu* getGpu()
const {
return fGpu; }
279 void didChangeGpuMemorySize()
const;
301 virtual size_t onGpuMemorySize()
const = 0;
305 void removeUniqueKey();
306 void notifyAllCntsAreZero(CntType)
const;
307 bool notifyRefCountIsZero()
const;
308 void removeScratchKey();
310 void makeUnbudgeted();
318 int fCacheArrayIndex;
322 uint32_t fExternalFlushCntWhenBecamePurgeable;
323 GrStdSteadyClock::time_point fTimeWhenBecamePurgeable;
325 static const size_t kInvalidGpuMemorySize = ~static_cast<
size_t>(0);
332 mutable size_t fGpuMemorySize;
334 SkBudgeted fBudgeted;
335 bool fRefsWrappedObjects;
336 const UniqueID fUniqueID;
Base class for objects that can be kept in the GrResourceCache.
Definition: GrGpuResource.h:144
Definition: GrGpuResource.h:183
virtual void onAbandon()
Overridden to abandon any internal handles, ptrs, etc to backend API resources.
Definition: GrGpuResource.h:273
#define SK_InvalidUniqueID
The unique IDs in Skia reserve 0 has an invalid marker.
Definition: SkTypes.h:323
const GrUniqueKey & getUniqueKey() const
Returns the current unique key for the resource.
Definition: GrGpuResource.h:218
A key that allows for exclusive use of a resource for a use case (AKA "domain").
Definition: GrResourceKey.h:222
virtual void onRelease()
Overridden to free GPU resources in the backend API.
Definition: GrGpuResource.h:269
bool wasDestroyed() const
Tests whether a object has been abandoned or released.
Definition: GrGpuResource.h:157
UniqueID uniqueID() const
Gets an id that is unique for this GrGpuResource object.
Definition: GrGpuResource.h:214
Base class for GrGpuResource.
Definition: GrGpuResource.h:46
#define SkToBool(cond)
Returns 0 or 1 based on the condition.
Definition: SkTypes.h:227
virtual void setMemoryBacking(SkTraceMemoryDump *, const SkString &) const
Allows subclasses to add additional backing information to the SkTraceMemoryDump. ...
Definition: GrGpuResource.h:285
size_t gpuMemorySize() const
Retrieves the amount of GPU memory used by this resource in bytes.
Definition: GrGpuResource.h:175
Definition: GrContext.h:47
A key used for scratch resources.
Definition: GrResourceKey.h:168
Interface for memory tracing.
Definition: SkTraceMemoryDump.h:20
virtual void computeScratchKey(GrScratchKey *) const
Called by the registerWithCache if the resource is available to be used as scratch.
Definition: GrGpuResource.h:294
Light weight class for managing strings.
Definition: SkString.h:121