8 #ifndef GrGpuResource_DEFINED
9 #define GrGpuResource_DEFINED
11 #include "GrResourceKey.h"
12 #include "GrTypesPriv.h"
17 class GrResourceCache;
47 template <
typename DERIVED>
class GrIORef :
public SkNoncopyable {
62 if (!static_cast<const DERIVED*>(
this)->notifyRefCountIsZero()) {
67 this->didRemoveRefOrPendingIO(kRef_CntType);
70 void validate()
const {
72 SkASSERT(fRefCnt >= 0);
73 SkASSERT(fPendingReads >= 0);
74 SkASSERT(fPendingWrites >= 0);
75 SkASSERT(fRefCnt + fPendingReads + fPendingWrites >= 0);
80 GrIORef() : fRefCnt(1), fPendingReads(0), fPendingWrites(0) { }
85 kPendingWrite_CntType,
88 bool isPurgeable()
const {
return !this->internalHasRef() && !this->internalHasPendingIO(); }
90 bool internalHasPendingRead()
const {
return SkToBool(fPendingReads); }
91 bool internalHasPendingWrite()
const {
return SkToBool(fPendingWrites); }
92 bool internalHasPendingIO()
const {
return SkToBool(fPendingWrites | fPendingReads); }
94 bool internalHasRef()
const {
return SkToBool(fRefCnt); }
97 void addPendingRead()
const {
102 void completedRead()
const {
105 this->didRemoveRefOrPendingIO(kPendingRead_CntType);
108 void addPendingWrite()
const {
113 void completedWrite()
const {
116 this->didRemoveRefOrPendingIO(kPendingWrite_CntType);
120 void didRemoveRefOrPendingIO(CntType cntTypeRemoved)
const {
121 if (0 == fPendingReads && 0 == fPendingWrites && 0 == fRefCnt) {
122 static_cast<const DERIVED*
>(
this)->notifyAllCntsAreZero(cntTypeRemoved);
126 mutable int32_t fRefCnt;
127 mutable int32_t fPendingReads;
128 mutable int32_t fPendingWrites;
132 friend class GrResourceCache;
172 if (kInvalidGpuMemorySize == fGpuMemorySize) {
173 fGpuMemorySize = this->onGpuMemorySize();
174 SkASSERT(kInvalidGpuMemorySize != fGpuMemorySize);
176 return fGpuMemorySize;
208 inline CacheAccess cacheAccess();
209 inline const CacheAccess cacheAccess()
const;
215 inline ResourcePriv resourcePriv();
216 inline const ResourcePriv resourcePriv()
const;
238 void registerWithCache(SkBudgeted);
243 void registerWithCacheWrapped();
248 GrGpu* getGpu()
const {
return fGpu; }
261 void didChangeGpuMemorySize()
const;
283 virtual size_t onGpuMemorySize()
const = 0;
287 void removeUniqueKey();
288 void notifyAllCntsAreZero(CntType)
const;
289 bool notifyRefCountIsZero()
const;
290 void removeScratchKey();
292 void makeUnbudgeted();
298 static uint32_t CreateUniqueID();
302 int fCacheArrayIndex;
307 static const size_t kInvalidGpuMemorySize = ~static_cast<
size_t>(0);
314 mutable size_t fGpuMemorySize;
316 SkBudgeted fBudgeted;
317 bool fRefsWrappedObjects;
318 const uint32_t fUniqueID;
Base class for objects that can be kept in the GrResourceCache.
Definition: GrGpuResource.h:140
virtual void onAbandon()
Overridden to abandon any internal handles, ptrs, etc to backend API resources.
Definition: GrGpuResource.h:255
uint32_t getUniqueID() const
Gets an id that is unique for this GrGpuResource object.
Definition: GrGpuResource.h:184
const GrUniqueKey & getUniqueKey() const
Returns the current unique key for the resource.
Definition: GrGpuResource.h:188
A key that allows for exclusive use of a resource for a use case (AKA "domain").
Definition: GrResourceKey.h:220
const SkData * getCustomData() const
Returns the custom data object that was attached to this resource by calling setCustomData.
Definition: GrGpuResource.h:202
This is similar to GrTGpuResourceRef but can only be in the pending IO state.
Definition: GrGpuResourceRef.h:156
virtual void onRelease()
Overridden to free GPU resources in the backend API.
Definition: GrGpuResource.h:251
bool wasDestroyed() const
Tests whether a object has been abandoned or released.
Definition: GrGpuResource.h:153
Base class for GrGpuResource.
Definition: GrGpuResource.h:47
SkData holds an immutable data buffer.
Definition: SkData.h:22
#define SkToBool(cond)
Returns 0 or 1 based on the condition.
Definition: SkTypes.h:287
This class is intended only for internal use in core Gr code.
Definition: GrGpuResourceRef.h:37
virtual void setMemoryBacking(SkTraceMemoryDump *, const SkString &) const
Allows subclasses to add additional backing information to the SkTraceMemoryDump. ...
Definition: GrGpuResource.h:267
size_t gpuMemorySize() const
Retrieves the amount of GPU memory used by this resource in bytes.
Definition: GrGpuResource.h:171
Definition: GrContext.h:48
A key used for scratch resources.
Definition: GrResourceKey.h:166
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:276
Light weight class for managing strings.
Definition: SkString.h:121