blob: 5f08a51aa05b594e6ca36cf00d936e65c55003fd [file] [log] [blame]
bsalomonc8dc1f72014-08-21 13:02:13 -07001/*
2 * Copyright 2014 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
bsalomon0ea80f42015-02-11 10:49:59 -08008#ifndef GrResourceCache_DEFINED
9#define GrResourceCache_DEFINED
bsalomonc8dc1f72014-08-21 13:02:13 -070010
bsalomon744998e2014-08-28 09:54:34 -070011#include "GrGpuResource.h"
bsalomon9f2d1572015-02-17 11:47:40 -080012#include "GrGpuResourceCacheAccess.h"
bsalomon3582d3e2015-02-13 14:20:05 -080013#include "GrGpuResourcePriv.h"
bsalomonb77a9072016-09-07 10:02:04 -070014#include "GrResourceCache.h"
bsalomon744998e2014-08-28 09:54:34 -070015#include "GrResourceKey.h"
bsalomon23e619c2015-02-06 11:54:28 -080016#include "SkMessageBus.h"
bsalomon8b79d232014-11-10 10:19:06 -080017#include "SkRefCnt.h"
bsalomon23e619c2015-02-06 11:54:28 -080018#include "SkTArray.h"
bsalomon9f2d1572015-02-17 11:47:40 -080019#include "SkTDPQueue.h"
bsalomonc8dc1f72014-08-21 13:02:13 -070020#include "SkTInternalLList.h"
bsalomon744998e2014-08-28 09:54:34 -070021#include "SkTMultiMap.h"
bsalomonc8dc1f72014-08-21 13:02:13 -070022
robertphillips63926682015-08-20 09:39:02 -070023class GrCaps;
mtkleinb9eb4ac2015-02-02 18:26:03 -080024class SkString;
ericrk0a5fa482015-09-15 14:16:10 -070025class SkTraceMemoryDump;
mtkleinb9eb4ac2015-02-02 18:26:03 -080026
bsalomonc8dc1f72014-08-21 13:02:13 -070027/**
bsalomon71cb0c22014-11-14 12:10:14 -080028 * Manages the lifetime of all GrGpuResource instances.
29 *
30 * Resources may have optionally have two types of keys:
31 * 1) A scratch key. This is for resources whose allocations are cached but not their contents.
32 * Multiple resources can share the same scratch key. This is so a caller can have two
bsalomon84c8e622014-11-17 09:33:27 -080033 * resource instances with the same properties (e.g. multipass rendering that ping-pongs
bsalomon8718aaf2015-02-19 07:24:21 -080034 * between two temporary surfaces). The scratch key is set at resource creation time and
bsalomon71cb0c22014-11-14 12:10:14 -080035 * should never change. Resources need not have a scratch key.
bsalomon8718aaf2015-02-19 07:24:21 -080036 * 2) A unique key. This key's meaning is specific to the domain that created the key. Only one
bsalomonf99e9612015-02-19 08:24:16 -080037 * resource may have a given unique key. The unique key can be set, cleared, or changed
38 * anytime after resource creation.
39 *
bsalomon8718aaf2015-02-19 07:24:21 -080040 * A unique key always takes precedence over a scratch key when a resource has both types of keys.
bsalomon71cb0c22014-11-14 12:10:14 -080041 * If a resource has neither key type then it will be deleted as soon as the last reference to it
bsalomon8718aaf2015-02-19 07:24:21 -080042 * is dropped.
bsalomonc8dc1f72014-08-21 13:02:13 -070043 */
bsalomon0ea80f42015-02-11 10:49:59 -080044class GrResourceCache {
bsalomonc8dc1f72014-08-21 13:02:13 -070045public:
robertphillips63926682015-08-20 09:39:02 -070046 GrResourceCache(const GrCaps* caps);
bsalomon0ea80f42015-02-11 10:49:59 -080047 ~GrResourceCache();
bsalomonc8dc1f72014-08-21 13:02:13 -070048
bsalomon3f324322015-04-08 11:01:54 -070049 // Default maximum number of budgeted resources in the cache.
50 static const int kDefaultMaxCount = 2 * (1 << 12);
51 // Default maximum number of bytes of gpu memory of budgeted resources in the cache.
52 static const size_t kDefaultMaxSize = 96 * (1 << 20);
bsalomone2e87f32016-09-22 12:42:11 -070053 // Default number of external flushes a budgeted resources can go unused in the cache before it
54 // is purged. Using a value <= 0 disables this feature.
55 static const int kDefaultMaxUnusedFlushes =
56 1 * /* flushes per frame */
57 60 * /* fps */
58 30; /* seconds */
bsalomon3f324322015-04-08 11:01:54 -070059
bsalomon71cb0c22014-11-14 12:10:14 -080060 /** Used to access functionality needed by GrGpuResource for lifetime management. */
61 class ResourceAccess;
62 ResourceAccess resourceAccess();
bsalomonc8dc1f72014-08-21 13:02:13 -070063
bsalomon71cb0c22014-11-14 12:10:14 -080064 /**
bsalomon3f324322015-04-08 11:01:54 -070065 * Sets the cache limits in terms of number of resources, max gpu memory byte size, and number
bsalomone2e87f32016-09-22 12:42:11 -070066 * of external GrContext flushes that a resource can be unused before it is evicted. The latter
67 * value is a suggestion and there is no promise that a resource will be purged immediately
68 * after it hasn't been used in maxUnusedFlushes flushes.
bsalomon71cb0c22014-11-14 12:10:14 -080069 */
bsalomon3f324322015-04-08 11:01:54 -070070 void setLimits(int count, size_t bytes, int maxUnusedFlushes = kDefaultMaxUnusedFlushes);
bsalomonc8dc1f72014-08-21 13:02:13 -070071
bsalomon71cb0c22014-11-14 12:10:14 -080072 /**
bsalomondace19e2014-11-17 07:34:06 -080073 * Returns the number of resources.
bsalomon71cb0c22014-11-14 12:10:14 -080074 */
bsalomonf320e042015-02-17 15:09:34 -080075 int getResourceCount() const {
76 return fPurgeableQueue.count() + fNonpurgeableResources.count();
77 }
bsalomon8b79d232014-11-10 10:19:06 -080078
bsalomon71cb0c22014-11-14 12:10:14 -080079 /**
bsalomondace19e2014-11-17 07:34:06 -080080 * Returns the number of resources that count against the budget.
81 */
82 int getBudgetedResourceCount() const { return fBudgetedCount; }
83
84 /**
85 * Returns the number of bytes consumed by resources.
bsalomon71cb0c22014-11-14 12:10:14 -080086 */
87 size_t getResourceBytes() const { return fBytes; }
88
89 /**
bsalomondace19e2014-11-17 07:34:06 -080090 * Returns the number of bytes consumed by budgeted resources.
91 */
92 size_t getBudgetedResourceBytes() const { return fBudgetedBytes; }
93
94 /**
bsalomon71cb0c22014-11-14 12:10:14 -080095 * Returns the cached resources count budget.
96 */
97 int getMaxResourceCount() const { return fMaxCount; }
98
99 /**
100 * Returns the number of bytes consumed by cached resources.
101 */
102 size_t getMaxResourceBytes() const { return fMaxBytes; }
103
104 /**
105 * Abandons the backend API resources owned by all GrGpuResource objects and removes them from
106 * the cache.
107 */
bsalomonc8dc1f72014-08-21 13:02:13 -0700108 void abandonAll();
109
bsalomon71cb0c22014-11-14 12:10:14 -0800110 /**
111 * Releases the backend API resources owned by all GrGpuResource objects and removes them from
112 * the cache.
113 */
bsalomonc8dc1f72014-08-21 13:02:13 -0700114 void releaseAll();
115
bsalomon000f8292014-10-15 19:04:14 -0700116 enum {
117 /** Preferentially returns scratch resources with no pending IO. */
118 kPreferNoPendingIO_ScratchFlag = 0x1,
119 /** Will not return any resources that match but have pending IO. */
120 kRequireNoPendingIO_ScratchFlag = 0x2,
121 };
bsalomon71cb0c22014-11-14 12:10:14 -0800122
123 /**
124 * Find a resource that matches a scratch key.
125 */
robertphillips6e83ac72015-08-13 05:19:14 -0700126 GrGpuResource* findAndRefScratchResource(const GrScratchKey& scratchKey,
127 size_t resourceSize,
128 uint32_t flags);
halcanary9d524f22016-03-29 09:03:52 -0700129
bsalomon8b79d232014-11-10 10:19:06 -0800130#ifdef SK_DEBUG
131 // This is not particularly fast and only used for validation, so debug only.
bsalomon7775c852014-12-30 12:50:52 -0800132 int countScratchEntriesForKey(const GrScratchKey& scratchKey) const {
bsalomon8b79d232014-11-10 10:19:06 -0800133 return fScratchMap.countForKey(scratchKey);
134 }
135#endif
136
bsalomon71cb0c22014-11-14 12:10:14 -0800137 /**
bsalomon8718aaf2015-02-19 07:24:21 -0800138 * Find a resource that matches a unique key.
bsalomon71cb0c22014-11-14 12:10:14 -0800139 */
robertphillipsee843b22016-10-04 05:30:20 -0700140 GrGpuResource* findAndRefUniqueResource(const GrUniqueKey& key) {
141 GrGpuResource* resource = fUniqueHash.find(key);
142 if (resource) {
143 this->refAndMakeResourceMRU(resource);
144 }
145 return resource;
146 }
bsalomon8b79d232014-11-10 10:19:06 -0800147
bsalomon71cb0c22014-11-14 12:10:14 -0800148 /**
bsalomon8718aaf2015-02-19 07:24:21 -0800149 * Query whether a unique key exists in the cache.
bsalomon71cb0c22014-11-14 12:10:14 -0800150 */
bsalomon8718aaf2015-02-19 07:24:21 -0800151 bool hasUniqueKey(const GrUniqueKey& key) const {
152 return SkToBool(fUniqueHash.find(key));
bsalomon8b79d232014-11-10 10:19:06 -0800153 }
bsalomonbcf0a522014-10-08 08:40:09 -0700154
bsalomon8718aaf2015-02-19 07:24:21 -0800155 /** Purges resources to become under budget and processes resources with invalidated unique
bsalomon23e619c2015-02-06 11:54:28 -0800156 keys. */
robertphillipsee843b22016-10-04 05:30:20 -0700157 void purgeAsNeeded();
bsalomon23e619c2015-02-06 11:54:28 -0800158
bsalomon71cb0c22014-11-14 12:10:14 -0800159 /** Purges all resources that don't have external owners. */
160 void purgeAllUnlocked();
161
bsalomonb77a9072016-09-07 10:02:04 -0700162 /** Returns true if the cache would like a flush to occur in order to make more resources
163 purgeable. */
robertphillipsee843b22016-10-04 05:30:20 -0700164 bool requestsFlush() const { return fRequestFlush; }
bsalomon71cb0c22014-11-14 12:10:14 -0800165
bsalomonb77a9072016-09-07 10:02:04 -0700166 enum FlushType {
167 kExternal,
168 kImmediateMode,
169 kCacheRequested,
170 };
171 void notifyFlushOccurred(FlushType);
bsalomon71cb0c22014-11-14 12:10:14 -0800172
robertphillips60029a52015-11-09 13:51:06 -0800173#if GR_CACHE_STATS
174 struct Stats {
175 int fTotal;
176 int fNumPurgeable;
177 int fNumNonPurgeable;
178
179 int fScratch;
kkinnunen2e6055b2016-04-22 01:48:29 -0700180 int fWrapped;
robertphillips60029a52015-11-09 13:51:06 -0800181 size_t fUnbudgetedSize;
182
183 Stats() { this->reset(); }
184
185 void reset() {
186 fTotal = 0;
187 fNumPurgeable = 0;
188 fNumNonPurgeable = 0;
189 fScratch = 0;
kkinnunen2e6055b2016-04-22 01:48:29 -0700190 fWrapped = 0;
robertphillips60029a52015-11-09 13:51:06 -0800191 fUnbudgetedSize = 0;
192 }
193
194 void update(GrGpuResource* resource) {
195 if (resource->cacheAccess().isScratch()) {
196 ++fScratch;
197 }
kkinnunen2e6055b2016-04-22 01:48:29 -0700198 if (resource->resourcePriv().refsWrappedObjects()) {
199 ++fWrapped;
robertphillips60029a52015-11-09 13:51:06 -0800200 }
bsalomon5ec26ae2016-02-25 08:33:02 -0800201 if (SkBudgeted::kNo == resource->resourcePriv().isBudgeted()) {
robertphillips60029a52015-11-09 13:51:06 -0800202 fUnbudgetedSize += resource->gpuMemorySize();
203 }
204 }
205 };
206
207 void getStats(Stats*) const;
208
mtkleinb9eb4ac2015-02-02 18:26:03 -0800209 void dumpStats(SkString*) const;
joshualittdc5685a2015-12-02 14:08:25 -0800210
211 void dumpStatsKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* value) const;
bsalomon71cb0c22014-11-14 12:10:14 -0800212#endif
213
Brian Salomon1090da62017-01-06 12:04:19 -0500214#ifdef SK_DEBUG
215 int countUniqueKeysWithTag(const char* tag) const;
216#endif
217
bsalomonddf30e62015-02-19 11:38:44 -0800218 // This function is for unit testing and is only defined in test tools.
219 void changeTimestamp(uint32_t newTimestamp);
220
ericrk0a5fa482015-09-15 14:16:10 -0700221 // Enumerates all cached resources and dumps their details to traceMemoryDump.
222 void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const;
223
bsalomonc8dc1f72014-08-21 13:02:13 -0700224private:
bsalomon71cb0c22014-11-14 12:10:14 -0800225 ///////////////////////////////////////////////////////////////////////////
226 /// @name Methods accessible via ResourceAccess
227 ////
228 void insertResource(GrGpuResource*);
229 void removeResource(GrGpuResource*);
bsalomon3f324322015-04-08 11:01:54 -0700230 void notifyCntReachedZero(GrGpuResource*, uint32_t flags);
bsalomon71cb0c22014-11-14 12:10:14 -0800231 void didChangeGpuMemorySize(const GrGpuResource*, size_t oldSize);
bsalomonf99e9612015-02-19 08:24:16 -0800232 void changeUniqueKey(GrGpuResource*, const GrUniqueKey&);
233 void removeUniqueKey(GrGpuResource*);
bsalomon10e23ca2014-11-25 05:52:06 -0800234 void willRemoveScratchKey(const GrGpuResource*);
bsalomon84c8e622014-11-17 09:33:27 -0800235 void didChangeBudgetStatus(GrGpuResource*);
bsalomon9f2d1572015-02-17 11:47:40 -0800236 void refAndMakeResourceMRU(GrGpuResource*);
bsalomon71cb0c22014-11-14 12:10:14 -0800237 /// @}
238
bsalomon8718aaf2015-02-19 07:24:21 -0800239 void processInvalidUniqueKeys(const SkTArray<GrUniqueKeyInvalidatedMessage>&);
bsalomonf320e042015-02-17 15:09:34 -0800240 void addToNonpurgeableArray(GrGpuResource*);
241 void removeFromNonpurgeableArray(GrGpuResource*);
242 bool overBudget() const { return fBudgetedBytes > fMaxBytes || fBudgetedCount > fMaxCount; }
bsalomon71cb0c22014-11-14 12:10:14 -0800243
robertphillips6e83ac72015-08-13 05:19:14 -0700244 bool wouldFit(size_t bytes) {
halcanary9d524f22016-03-29 09:03:52 -0700245 return fBudgetedBytes+bytes <= fMaxBytes && fBudgetedCount+1 <= fMaxCount;
robertphillips6e83ac72015-08-13 05:19:14 -0700246 }
247
bsalomonddf30e62015-02-19 11:38:44 -0800248 uint32_t getNextTimestamp();
249
bsalomon16961262014-08-26 14:01:07 -0700250#ifdef SK_DEBUG
bsalomonf320e042015-02-17 15:09:34 -0800251 bool isInCache(const GrGpuResource* r) const;
bsalomon71cb0c22014-11-14 12:10:14 -0800252 void validate() const;
253#else
254 void validate() const {}
bsalomon16961262014-08-26 14:01:07 -0700255#endif
256
bsalomon71cb0c22014-11-14 12:10:14 -0800257 class AutoValidate;
258
bsalomonbcf0a522014-10-08 08:40:09 -0700259 class AvailableForScratchUse;
bsalomon744998e2014-08-28 09:54:34 -0700260
robertphillipsee843b22016-10-04 05:30:20 -0700261 struct ScratchMapTraits {
bsalomon7775c852014-12-30 12:50:52 -0800262 static const GrScratchKey& GetKey(const GrGpuResource& r) {
bsalomon3582d3e2015-02-13 14:20:05 -0800263 return r.resourcePriv().getScratchKey();
bsalomon744998e2014-08-28 09:54:34 -0700264 }
robertphillipsee843b22016-10-04 05:30:20 -0700265
266 static uint32_t Hash(const GrScratchKey& key) { return key.hash(); }
bsalomon744998e2014-08-28 09:54:34 -0700267 };
bsalomon7775c852014-12-30 12:50:52 -0800268 typedef SkTMultiMap<GrGpuResource, GrScratchKey, ScratchMapTraits> ScratchMap;
bsalomon744998e2014-08-28 09:54:34 -0700269
robertphillipsee843b22016-10-04 05:30:20 -0700270 struct UniqueHashTraits {
bsalomon8718aaf2015-02-19 07:24:21 -0800271 static const GrUniqueKey& GetKey(const GrGpuResource& r) { return r.getUniqueKey(); }
robertphillipsee843b22016-10-04 05:30:20 -0700272
273 static uint32_t Hash(const GrUniqueKey& key) { return key.hash(); }
bsalomon8b79d232014-11-10 10:19:06 -0800274 };
bsalomon8718aaf2015-02-19 07:24:21 -0800275 typedef SkTDynamicHash<GrGpuResource, GrUniqueKey, UniqueHashTraits> UniqueHash;
bsalomon8b79d232014-11-10 10:19:06 -0800276
bsalomon9f2d1572015-02-17 11:47:40 -0800277 static bool CompareTimestamp(GrGpuResource* const& a, GrGpuResource* const& b) {
278 return a->cacheAccess().timestamp() < b->cacheAccess().timestamp();
279 }
bsalomon23e619c2015-02-06 11:54:28 -0800280
bsalomon9f2d1572015-02-17 11:47:40 -0800281 static int* AccessResourceIndex(GrGpuResource* const& res) {
282 return res->cacheAccess().accessCacheIndex();
283 }
284
bsalomon8718aaf2015-02-19 07:24:21 -0800285 typedef SkMessageBus<GrUniqueKeyInvalidatedMessage>::Inbox InvalidUniqueKeyInbox;
bsalomon9f2d1572015-02-17 11:47:40 -0800286 typedef SkTDPQueue<GrGpuResource*, CompareTimestamp, AccessResourceIndex> PurgeableQueue;
bsalomonf320e042015-02-17 15:09:34 -0800287 typedef SkTDArray<GrGpuResource*> ResourceArray;
bsalomon9f2d1572015-02-17 11:47:40 -0800288
289 // Whenever a resource is added to the cache or the result of a cache lookup, fTimestamp is
290 // assigned as the resource's timestamp and then incremented. fPurgeableQueue orders the
291 // purgeable resources by this value, and thus is used to purge resources in LRU order.
292 uint32_t fTimestamp;
293 PurgeableQueue fPurgeableQueue;
bsalomonf320e042015-02-17 15:09:34 -0800294 ResourceArray fNonpurgeableResources;
bsalomon9f2d1572015-02-17 11:47:40 -0800295
bsalomon744998e2014-08-28 09:54:34 -0700296 // This map holds all resources that can be used as scratch resources.
bsalomon8b79d232014-11-10 10:19:06 -0800297 ScratchMap fScratchMap;
bsalomon8718aaf2015-02-19 07:24:21 -0800298 // This holds all resources that have unique keys.
299 UniqueHash fUniqueHash;
bsalomon71cb0c22014-11-14 12:10:14 -0800300
301 // our budget, used in purgeAsNeeded()
302 int fMaxCount;
303 size_t fMaxBytes;
bsalomon3f324322015-04-08 11:01:54 -0700304 int fMaxUnusedFlushes;
bsalomon71cb0c22014-11-14 12:10:14 -0800305
306#if GR_CACHE_STATS
307 int fHighWaterCount;
308 size_t fHighWaterBytes;
bsalomondace19e2014-11-17 07:34:06 -0800309 int fBudgetedHighWaterCount;
310 size_t fBudgetedHighWaterBytes;
bsalomon71cb0c22014-11-14 12:10:14 -0800311#endif
312
bsalomondace19e2014-11-17 07:34:06 -0800313 // our current stats for all resources
bsalomonf320e042015-02-17 15:09:34 -0800314 SkDEBUGCODE(int fCount;)
bsalomon71cb0c22014-11-14 12:10:14 -0800315 size_t fBytes;
316
bsalomondace19e2014-11-17 07:34:06 -0800317 // our current stats for resources that count against the budget
318 int fBudgetedCount;
319 size_t fBudgetedBytes;
320
robertphillipsee843b22016-10-04 05:30:20 -0700321 bool fRequestFlush;
bsalomone2e87f32016-09-22 12:42:11 -0700322 uint32_t fExternalFlushCnt;
bsalomon3f324322015-04-08 11:01:54 -0700323
bsalomon8718aaf2015-02-19 07:24:21 -0800324 InvalidUniqueKeyInbox fInvalidUniqueKeyInbox;
bsalomon3f324322015-04-08 11:01:54 -0700325
326 // This resource is allowed to be in the nonpurgeable array for the sake of validate() because
327 // we're in the midst of converting it to purgeable status.
328 SkDEBUGCODE(GrGpuResource* fNewlyPurgeableResourceForValidation;)
robertphillips63926682015-08-20 09:39:02 -0700329
330 bool fPreferVRAMUseOverFlushes;
bsalomonc8dc1f72014-08-21 13:02:13 -0700331};
332
bsalomon0ea80f42015-02-11 10:49:59 -0800333class GrResourceCache::ResourceAccess {
bsalomon71cb0c22014-11-14 12:10:14 -0800334private:
bsalomon0ea80f42015-02-11 10:49:59 -0800335 ResourceAccess(GrResourceCache* cache) : fCache(cache) { }
bsalomon71cb0c22014-11-14 12:10:14 -0800336 ResourceAccess(const ResourceAccess& that) : fCache(that.fCache) { }
337 ResourceAccess& operator=(const ResourceAccess&); // unimpl
338
339 /**
340 * Insert a resource into the cache.
341 */
342 void insertResource(GrGpuResource* resource) { fCache->insertResource(resource); }
343
344 /**
345 * Removes a resource from the cache.
346 */
347 void removeResource(GrGpuResource* resource) { fCache->removeResource(resource); }
348
349 /**
bsalomon3f324322015-04-08 11:01:54 -0700350 * Notifications that should be sent to the cache when the ref/io cnt status of resources
351 * changes.
bsalomon71cb0c22014-11-14 12:10:14 -0800352 */
bsalomon3f324322015-04-08 11:01:54 -0700353 enum RefNotificationFlags {
354 /** All types of refs on the resource have reached zero. */
355 kAllCntsReachedZero_RefNotificationFlag = 0x1,
356 /** The normal (not pending IO type) ref cnt has reached zero. */
357 kRefCntReachedZero_RefNotificationFlag = 0x2,
358 };
359 /**
360 * Called by GrGpuResources when they detect that their ref/io cnts have reached zero. When the
361 * normal ref cnt reaches zero the flags that are set should be:
362 * a) kRefCntReachedZero if a pending IO cnt is still non-zero.
363 * b) (kRefCntReachedZero | kAllCntsReachedZero) when all pending IO cnts are also zero.
364 * kAllCntsReachedZero is set by itself if a pending IO cnt is decremented to zero and all the
365 * the other cnts are already zero.
366 */
367 void notifyCntReachedZero(GrGpuResource* resource, uint32_t flags) {
368 fCache->notifyCntReachedZero(resource, flags);
369 }
bsalomon71cb0c22014-11-14 12:10:14 -0800370
371 /**
372 * Called by GrGpuResources when their sizes change.
373 */
374 void didChangeGpuMemorySize(const GrGpuResource* resource, size_t oldSize) {
375 fCache->didChangeGpuMemorySize(resource, oldSize);
376 }
377
378 /**
bsalomonf99e9612015-02-19 08:24:16 -0800379 * Called by GrGpuResources to change their unique keys.
bsalomon71cb0c22014-11-14 12:10:14 -0800380 */
bsalomonf99e9612015-02-19 08:24:16 -0800381 void changeUniqueKey(GrGpuResource* resource, const GrUniqueKey& newKey) {
382 fCache->changeUniqueKey(resource, newKey);
383 }
bsalomon71cb0c22014-11-14 12:10:14 -0800384
bsalomon10e23ca2014-11-25 05:52:06 -0800385 /**
bsalomonf99e9612015-02-19 08:24:16 -0800386 * Called by a GrGpuResource to remove its unique key.
bsalomon23e619c2015-02-06 11:54:28 -0800387 */
bsalomonf99e9612015-02-19 08:24:16 -0800388 void removeUniqueKey(GrGpuResource* resource) { fCache->removeUniqueKey(resource); }
bsalomon23e619c2015-02-06 11:54:28 -0800389
390 /**
391 * Called by a GrGpuResource when it removes its scratch key.
bsalomon10e23ca2014-11-25 05:52:06 -0800392 */
393 void willRemoveScratchKey(const GrGpuResource* resource) {
394 fCache->willRemoveScratchKey(resource);
395 }
bsalomon84c8e622014-11-17 09:33:27 -0800396
397 /**
398 * Called by GrGpuResources when they change from budgeted to unbudgeted or vice versa.
399 */
400 void didChangeBudgetStatus(GrGpuResource* resource) { fCache->didChangeBudgetStatus(resource); }
401
bsalomon71cb0c22014-11-14 12:10:14 -0800402 // No taking addresses of this type.
403 const ResourceAccess* operator&() const;
404 ResourceAccess* operator&();
405
bsalomon0ea80f42015-02-11 10:49:59 -0800406 GrResourceCache* fCache;
bsalomon71cb0c22014-11-14 12:10:14 -0800407
408 friend class GrGpuResource; // To access all the proxy inline methods.
bsalomon0ea80f42015-02-11 10:49:59 -0800409 friend class GrResourceCache; // To create this type.
bsalomon71cb0c22014-11-14 12:10:14 -0800410};
411
bsalomon0ea80f42015-02-11 10:49:59 -0800412inline GrResourceCache::ResourceAccess GrResourceCache::resourceAccess() {
bsalomon71cb0c22014-11-14 12:10:14 -0800413 return ResourceAccess(this);
414}
415
bsalomonc8dc1f72014-08-21 13:02:13 -0700416#endif