8#ifndef skgpu_graphite_Resource_DEFINED
9#define skgpu_graphite_Resource_DEFINED
30#if defined(GRAPHITE_TEST_UTILS)
49 (void)fUsageRefCnt.fetch_add(+1, std::memory_order_relaxed);
54 bool shouldFree =
false;
59 if (1 == fUsageRefCnt.fetch_add(-1, std::memory_order_acq_rel)) {
65 mutableThis->internalDispose();
71 if (fCommandBufferRefsAsUsageRefs) {
75 (void)fCommandBufferRefCnt.fetch_add(+1, std::memory_order_relaxed);
80 if (fCommandBufferRefsAsUsageRefs) {
83 bool shouldFree =
false;
86 SkASSERT(this->hasCommandBufferRef());
88 if (1 == fCommandBufferRefCnt.fetch_add(-1, std::memory_order_acq_rel)) {
94 mutableThis->internalDispose();
139 if (!fLabel.empty()) {
140 const std::string fullLabel =
"Skia_" + fLabel;
175#if defined(GRAPHITE_TEST_UTILS)
176 bool testingShouldDeleteASAP()
const {
return fDeleteASAP == DeleteASAP::kYes; }
178 virtual const Texture* asTexture()
const {
return nullptr; }
186 bool commandBufferRefsAsUsageRefs =
false);
193 const char* dumpName)
const {}
196 bool debugHasCommandBufferRef()
const {
197 return hasCommandBufferRef();
213 enum class DeleteASAP :
bool {
218 DeleteASAP shouldDeleteASAP()
const {
return fDeleteASAP; }
222 void updateAccessTime() {
223 fLastAccess = skgpu::StdSteadyClock::now();
225 skgpu::StdSteadyClock::time_point lastAccessTime()
const {
242 void initialUsageRef()
const {
246 (void)fUsageRefCnt.fetch_add(+1, std::memory_order_relaxed);
249 bool isPurgeable()
const;
250 int* accessReturnIndex()
const {
return &fReturnIndex; }
251 int* accessCacheIndex()
const {
return &fCacheArrayIndex; }
253 uint32_t timestamp()
const {
return fTimestamp; }
254 void setTimestamp(uint32_t ts) { fTimestamp = ts; }
261 void refCache()
const {
263 (void)fCacheRefCnt.fetch_add(+1, std::memory_order_relaxed);
268 void unrefCache()
const {
269 bool shouldFree =
false;
274 if (1 == fCacheRefCnt.fetch_add(-1, std::memory_order_acq_rel)) {
280 mutableThis->internalDispose();
285 bool isUsableAsScratch()
const {
293 bool hasUsageRef()
const {
294 if (0 == fUsageRefCnt.load(std::memory_order_acquire)) {
303 bool hasCommandBufferRef()
const {
306 if (0 == fCommandBufferRefCnt.load(std::memory_order_acquire)) {
312 SkASSERT(!fCommandBufferRefsAsUsageRefs);
316 bool hasCacheRef()
const {
317 if (0 == fCacheRefCnt.load(std::memory_order_acquire)) {
326 bool hasAnyRefs()
const {
327 return this->hasUsageRef() || this->hasCommandBufferRef() || this->hasCacheRef();
333 void internalDispose();
338 mutable SkMutex fUnrefMutex;
340 SkDEBUGCODE(
mutable bool fCalledRemovedFromCache =
false;)
344 const SharedContext* fSharedContext;
346 mutable std::atomic<int32_t> fUsageRefCnt;
347 mutable std::atomic<int32_t> fCommandBufferRefCnt;
348 mutable std::atomic<int32_t> fCacheRefCnt;
350 const bool fCommandBufferRefsAsUsageRefs =
false;
352 GraphiteResourceKey fKey;
357 mutable int fReturnIndex = -1;
361 static const size_t kInvalidGpuMemorySize = ~static_cast<size_t>(0);
362 mutable size_t fGpuMemorySize = kInvalidGpuMemorySize;
375 DeleteASAP fDeleteASAP = DeleteASAP::kNo;
379 mutable int fCacheArrayIndex = -1;
383 skgpu::StdSteadyClock::time_point fLastAccess;
385 const UniqueID fUniqueID;
394 SkDEBUGCODE(
mutable bool fNonShareableInCache =
false;)
@ kYes
Do pre-clip the geometry before applying the (perspective) matrix.
@ kNo
Don't pre-clip the geometry before applying the (perspective) matrix.
SkDEBUGCODE(SK_SPI) SkThreadID SkGetThreadID()
static constexpr uint32_t SK_InvalidUniqueID
Shareable shareable() const
bool operator!=(const UniqueID &other) const
bool operator==(const UniqueID &other) const
bool wasDestroyed() const
skgpu::Budgeted budgeted() const
virtual void prepareForReturnToCache(const std::function< void()> &takeRef)
const GraphiteResourceKey & key() const
virtual void invokeReleaseProc()
void refCommandBuffer() const
Resource(const Resource &)=delete
virtual void onDumpMemoryStatistics(SkTraceMemoryDump *traceMemoryDump, const char *dumpName) const
void unrefCommandBuffer() const
size_t gpuMemorySize() const
Resource & operator=(const Resource &)=delete
UniqueID uniqueID() const
const SharedContext * sharedContext() const
virtual void setBackendLabel(char const *label)
void setKey(const GraphiteResourceKey &key)
void setLabel(std::string_view label)
std::string getLabel() const
Resource(Resource &&)=delete
Ownership ownership() const
Resource & operator=(Resource &&)=delete
virtual const char * getResourceType() const =0
virtual void freeGpuData()=0
void dumpMemoryStatistics(SkTraceMemoryDump *traceMemoryDump) const
Dart_NativeFunction function