8#ifndef GrResourceCache_DEFINED
9#define GrResourceCache_DEFINED
73 static std::enable_if_t<std::is_base_of_v<GrGpuResource, T>,
void>
96 return fPurgeableQueue.
count() + fNonpurgeableResources.
size();
144 return fScratchMap.countForKey(scratchKey);
154 this->refAndMakeResourceMRU(resource);
190 bool overBudget()
const {
return fBudgetedBytes > fMaxBytes; }
212 int fNumNonPurgeable;
216 size_t fUnbudgetedSize;
223 fNumNonPurgeable = 0;
242 void getStats(
Stats*)
const;
244#if defined(GR_TEST_UTILS)
247 void dumpStatsKeyValuePairs(
253#if defined(GR_TEST_UTILS)
254 int countUniqueKeysWithTag(
const char* tag)
const;
256 void changeTimestamp(uint32_t newTimestamp);
258 void visitSurfaces(
const std::function<
void(
const GrSurface*,
bool purgeable)>&)
const;
266 fThreadSafeCache = threadSafeCache;
287 : fResource(
std::move(resource)), fRecipient(
recipient) {}
311 void processFreedGpuResources();
315 bool wouldFit(
size_t bytes)
const {
return fBudgetedBytes+bytes <= fMaxBytes; }
317 uint32_t getNextTimestamp();
324 void validate()
const;
326 void validate()
const {}
331 struct ScratchMapTraits {
341 struct UniqueHashTraits {
349 return a->cacheAccess().timestamp() <
b->cacheAccess().timestamp();
366 uint32_t fTimestamp = 0;
367 PurgeableQueue fPurgeableQueue;
368 ResourceArray fNonpurgeableResources;
371 ScratchMap fScratchMap;
373 UniqueHash fUniqueHash;
379 int fHighWaterCount = 0;
380 size_t fHighWaterBytes = 0;
381 int fBudgetedHighWaterCount = 0;
382 size_t fBudgetedHighWaterBytes = 0;
390 int fBudgetedCount = 0;
391 size_t fBudgetedBytes = 0;
392 size_t fPurgeableBytes = 0;
393 int fNumBudgetedResourcesFlushWillMakePurgeable = 0;
395 InvalidUniqueKeyInbox fInvalidUniqueKeyInbox;
416 void insertResource(
GrGpuResource* resource) { fCache->insertResource(resource); }
421 void removeResource(
GrGpuResource* resource) { fCache->removeResource(resource); }
427 void refResource(
GrGpuResource* resource) { fCache->refResource(resource); }
433 enum RefNotificationFlags {
435 kAllCntsReachedZero_RefNotificationFlag = 0x1,
437 kRefCntReachedZero_RefNotificationFlag = 0x2,
445 fCache->notifyARefCntReachedZero(resource, removedRef);
452 fCache->changeUniqueKey(resource, newKey);
458 void removeUniqueKey(
GrGpuResource* resource) { fCache->removeUniqueKey(resource); }
464 fCache->willRemoveScratchKey(resource);
470 void didChangeBudgetStatus(
GrGpuResource* resource) { fCache->didChangeBudgetStatus(resource); }
484 return potentialRecipient == msg.
recipient();
static bool SkShouldPostMessageToBus(const GrResourceCache::UnrefResourceMessage &msg, GrDirectContext::DirectContextID potentialRecipient)
static constexpr bool SkToBool(const T &x)
static constexpr uint32_t SK_InvalidUniqueID
const skgpu::ScratchKey & getScratchKey() const
bool refsWrappedObjects() const
GrBudgetedType budgetedType() const
size_t gpuMemorySize() const
const skgpu::UniqueKey & getUniqueKey() const
CacheAccess cacheAccess()
ResourcePriv resourcePriv()
UnrefResourceMessage & operator=(UnrefResourceMessage &&)=default
GrDirectContext::DirectContextID recipient() const
UnrefResourceMessage(UnrefResourceMessage &&)=default
size_t getResourceBytes() const
void setThreadSafeCache(GrThreadSafeCache *threadSafeCache)
void dumpMemoryStatistics(SkTraceMemoryDump *traceMemoryDump) const
void setLimit(size_t bytes)
int getBudgetedResourceCount() const
GrResourceCache(skgpu::SingleOwner *owner, GrDirectContext::DirectContextID owningContextID, uint32_t familyID)
size_t getPurgeableBytes() const
static std::enable_if_t< std::is_base_of_v< GrGpuResource, T >, void > ReturnResourceFromThread(sk_sp< T > &&resource, GrDirectContext::DirectContextID id)
bool hasUniqueKey(const skgpu::UniqueKey &key) const
int getResourceCount() const
bool requestsFlush() const
ResourceAccess resourceAccess()
size_t getMaxResourceBytes() const
bool purgeToMakeHeadroom(size_t desiredHeadroomBytes)
size_t getBudgetedResourceBytes() const
void setProxyProvider(GrProxyProvider *proxyProvider)
static const size_t kDefaultMaxSize
void purgeResourcesNotUsedSince(skgpu::StdSteadyClock::time_point purgeTime, GrPurgeResourceOptions opts)
void purgeUnlockedResources(GrPurgeResourceOptions opts)
GrGpuResource * findAndRefScratchResource(const skgpu::ScratchKey &scratchKey)
GrGpuResource * findAndRefUniqueResource(const skgpu::UniqueKey &key)
uint32_t contextUniqueID() const
SkDEBUGCODE(int fCount=0;) size_t fBytes=0
static void Post(Message m)
T * find(const Key &key) const