8#ifndef skgpu_graphite_ResourceCache_DEFINED
9#define skgpu_graphite_ResourceCache_DEFINED
20#if defined(GRAPHITE_TEST_UTILS)
33class GraphiteResourceKey;
37#if defined(GRAPHITE_TEST_UTILS)
53 return fPurgeableQueue.
count() + fNonpurgeableResources.
size();
87#if defined(GRAPHITE_TEST_UTILS)
88 void forceProcessReturnedResources() { this->processReturnedResources(); }
90 void forcePurgeAsNeeded() { this->purgeAsNeeded(); }
94 int numFindableResources()
const;
98 void setMaxBudget(
size_t bytes);
100 Resource* topOfPurgeableQueue();
102 bool testingInPurgeableQueue(Resource*
resource) {
return this->inPurgeableQueue(
resource); }
104 void visitTextures(
const std::function<
void(
const Texture*,
bool purgeable)>&)
const;
114 void refAndMakeResourceMRU(
Resource*);
120 bool processReturnedResources();
123 uint32_t getNextTimestamp();
124 void setResourceTimestamp(
Resource*, uint32_t timestamp);
126 bool inPurgeableQueue(
Resource*)
const;
128 bool overbudget()
const {
return fBudgetedBytes > fMaxBytes; }
129 void purgeAsNeeded();
130 void purgeResource(Resource*);
135 bool isInCache(
const Resource* r)
const;
136 void validate()
const;
138 void validate()
const {}
142 static const GraphiteResourceKey& GetKey(
const Resource& r);
144 static uint32_t
Hash(
const GraphiteResourceKey&
key);
145 static void OnFree(Resource*) {}
149 static bool CompareTimestamp(Resource*
const&
a, Resource*
const&
b);
150 static int* AccessResourceIndex(Resource*
const& res);
161 uint32_t fTimestamp = 0;
162 static const uint32_t kMaxTimestamp = 0xFFFFFFFF;
164 PurgeableQueue fPurgeableQueue;
165 ResourceArray fNonpurgeableResources;
166 std::unique_ptr<ProxyCache> fProxyCache;
168 SkDEBUGCODE(
int fCount = 0;)
170 ResourceMap fResourceMap;
174 size_t fBudgetedBytes = 0;
176 SingleOwner* fSingleOwner =
nullptr;
178 bool fIsShutdown =
false;
180 SkMutex fReturnMutex;
181 using ReturnQueue = std::vector<std::pair<Resource*, LastRemovedRef>>;
182 ReturnQueue fReturnQueue SK_GUARDED_BY(fReturnMutex);
static SkString resource(SkPDFResourceType type, int index)
bool returnResource(Resource *, LastRemovedRef)
~ResourceCache() override
ResourceCache(const ResourceCache &)=delete
size_t currentBudgetedBytes() const
ResourceCache & operator=(ResourceCache &&)=delete
void purgeResourcesNotUsedSince(StdSteadyClock::time_point purgeTime)
static sk_sp< ResourceCache > Make(SingleOwner *, uint32_t recorderID, size_t maxBytes)
void dumpMemoryStatistics(SkTraceMemoryDump *traceMemoryDump) const
int getResourceCount() const
ResourceCache(ResourceCache &&)=delete
void insertResource(Resource *)
ProxyCache * proxyCache()
Resource * findAndRefResource(const GraphiteResourceKey &key, skgpu::Budgeted)
ResourceCache & operator=(const ResourceCache &)=delete
size_t getMaxBudget() const
Dart_NativeFunction function
static uint32_t Hash(uint32_t key)