blob: ae9a4e7ee7e3bae513b5503083209b96e1d8fb74 [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 */
bsalomon8718aaf2015-02-19 07:24:21 -0800140 GrGpuResource* findAndRefUniqueResource(const GrUniqueKey& key) {
141 GrGpuResource* resource = fUniqueHash.find(key);
bsalomon71cb0c22014-11-14 12:10:14 -0800142 if (resource) {
bsalomon9f2d1572015-02-17 11:47:40 -0800143 this->refAndMakeResourceMRU(resource);
bsalomon71cb0c22014-11-14 12:10:14 -0800144 }
145 return resource;
bsalomon8b79d232014-11-10 10:19:06 -0800146 }
147
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. */
bsalomon3f324322015-04-08 11:01:54 -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. */
164 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
bsalomonddf30e62015-02-19 11:38:44 -0800214 // This function is for unit testing and is only defined in test tools.
215 void changeTimestamp(uint32_t newTimestamp);
216
ericrk0a5fa482015-09-15 14:16:10 -0700217 // Enumerates all cached resources and dumps their details to traceMemoryDump.
218 void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const;
219
bsalomonc8dc1f72014-08-21 13:02:13 -0700220private:
bsalomon71cb0c22014-11-14 12:10:14 -0800221 ///////////////////////////////////////////////////////////////////////////
222 /// @name Methods accessible via ResourceAccess
223 ////
224 void insertResource(GrGpuResource*);
225 void removeResource(GrGpuResource*);
bsalomon3f324322015-04-08 11:01:54 -0700226 void notifyCntReachedZero(GrGpuResource*, uint32_t flags);
bsalomon71cb0c22014-11-14 12:10:14 -0800227 void didChangeGpuMemorySize(const GrGpuResource*, size_t oldSize);
bsalomonf99e9612015-02-19 08:24:16 -0800228 void changeUniqueKey(GrGpuResource*, const GrUniqueKey&);
229 void removeUniqueKey(GrGpuResource*);
bsalomon10e23ca2014-11-25 05:52:06 -0800230 void willRemoveScratchKey(const GrGpuResource*);
bsalomon84c8e622014-11-17 09:33:27 -0800231 void didChangeBudgetStatus(GrGpuResource*);
bsalomon9f2d1572015-02-17 11:47:40 -0800232 void refAndMakeResourceMRU(GrGpuResource*);
bsalomon71cb0c22014-11-14 12:10:14 -0800233 /// @}
234
bsalomon8718aaf2015-02-19 07:24:21 -0800235 void processInvalidUniqueKeys(const SkTArray<GrUniqueKeyInvalidatedMessage>&);
bsalomonf320e042015-02-17 15:09:34 -0800236 void addToNonpurgeableArray(GrGpuResource*);
237 void removeFromNonpurgeableArray(GrGpuResource*);
238 bool overBudget() const { return fBudgetedBytes > fMaxBytes || fBudgetedCount > fMaxCount; }
bsalomon71cb0c22014-11-14 12:10:14 -0800239
robertphillips6e83ac72015-08-13 05:19:14 -0700240 bool wouldFit(size_t bytes) {
halcanary9d524f22016-03-29 09:03:52 -0700241 return fBudgetedBytes+bytes <= fMaxBytes && fBudgetedCount+1 <= fMaxCount;
robertphillips6e83ac72015-08-13 05:19:14 -0700242 }
243
bsalomonddf30e62015-02-19 11:38:44 -0800244 uint32_t getNextTimestamp();
245
bsalomon16961262014-08-26 14:01:07 -0700246#ifdef SK_DEBUG
bsalomonf320e042015-02-17 15:09:34 -0800247 bool isInCache(const GrGpuResource* r) const;
bsalomon71cb0c22014-11-14 12:10:14 -0800248 void validate() const;
249#else
250 void validate() const {}
bsalomon16961262014-08-26 14:01:07 -0700251#endif
252
bsalomon71cb0c22014-11-14 12:10:14 -0800253 class AutoValidate;
254
bsalomonbcf0a522014-10-08 08:40:09 -0700255 class AvailableForScratchUse;
bsalomon744998e2014-08-28 09:54:34 -0700256
bsalomon744998e2014-08-28 09:54:34 -0700257 struct ScratchMapTraits {
bsalomon7775c852014-12-30 12:50:52 -0800258 static const GrScratchKey& GetKey(const GrGpuResource& r) {
bsalomon3582d3e2015-02-13 14:20:05 -0800259 return r.resourcePriv().getScratchKey();
bsalomon744998e2014-08-28 09:54:34 -0700260 }
261
bsalomon7775c852014-12-30 12:50:52 -0800262 static uint32_t Hash(const GrScratchKey& key) { return key.hash(); }
bsalomon744998e2014-08-28 09:54:34 -0700263 };
bsalomon7775c852014-12-30 12:50:52 -0800264 typedef SkTMultiMap<GrGpuResource, GrScratchKey, ScratchMapTraits> ScratchMap;
bsalomon744998e2014-08-28 09:54:34 -0700265
bsalomon8718aaf2015-02-19 07:24:21 -0800266 struct UniqueHashTraits {
267 static const GrUniqueKey& GetKey(const GrGpuResource& r) { return r.getUniqueKey(); }
bsalomon8b79d232014-11-10 10:19:06 -0800268
bsalomon8718aaf2015-02-19 07:24:21 -0800269 static uint32_t Hash(const GrUniqueKey& key) { return key.hash(); }
bsalomon8b79d232014-11-10 10:19:06 -0800270 };
bsalomon8718aaf2015-02-19 07:24:21 -0800271 typedef SkTDynamicHash<GrGpuResource, GrUniqueKey, UniqueHashTraits> UniqueHash;
bsalomon8b79d232014-11-10 10:19:06 -0800272
bsalomon9f2d1572015-02-17 11:47:40 -0800273 static bool CompareTimestamp(GrGpuResource* const& a, GrGpuResource* const& b) {
274 return a->cacheAccess().timestamp() < b->cacheAccess().timestamp();
275 }
bsalomon23e619c2015-02-06 11:54:28 -0800276
bsalomon9f2d1572015-02-17 11:47:40 -0800277 static int* AccessResourceIndex(GrGpuResource* const& res) {
278 return res->cacheAccess().accessCacheIndex();
279 }
280
bsalomon8718aaf2015-02-19 07:24:21 -0800281 typedef SkMessageBus<GrUniqueKeyInvalidatedMessage>::Inbox InvalidUniqueKeyInbox;
bsalomon9f2d1572015-02-17 11:47:40 -0800282 typedef SkTDPQueue<GrGpuResource*, CompareTimestamp, AccessResourceIndex> PurgeableQueue;
bsalomonf320e042015-02-17 15:09:34 -0800283 typedef SkTDArray<GrGpuResource*> ResourceArray;
bsalomon9f2d1572015-02-17 11:47:40 -0800284
285 // Whenever a resource is added to the cache or the result of a cache lookup, fTimestamp is
286 // assigned as the resource's timestamp and then incremented. fPurgeableQueue orders the
287 // purgeable resources by this value, and thus is used to purge resources in LRU order.
288 uint32_t fTimestamp;
289 PurgeableQueue fPurgeableQueue;
bsalomonf320e042015-02-17 15:09:34 -0800290 ResourceArray fNonpurgeableResources;
bsalomon9f2d1572015-02-17 11:47:40 -0800291
bsalomon744998e2014-08-28 09:54:34 -0700292 // This map holds all resources that can be used as scratch resources.
bsalomon8b79d232014-11-10 10:19:06 -0800293 ScratchMap fScratchMap;
bsalomon8718aaf2015-02-19 07:24:21 -0800294 // This holds all resources that have unique keys.
295 UniqueHash fUniqueHash;
bsalomon71cb0c22014-11-14 12:10:14 -0800296
297 // our budget, used in purgeAsNeeded()
298 int fMaxCount;
299 size_t fMaxBytes;
bsalomon3f324322015-04-08 11:01:54 -0700300 int fMaxUnusedFlushes;
bsalomon71cb0c22014-11-14 12:10:14 -0800301
302#if GR_CACHE_STATS
303 int fHighWaterCount;
304 size_t fHighWaterBytes;
bsalomondace19e2014-11-17 07:34:06 -0800305 int fBudgetedHighWaterCount;
306 size_t fBudgetedHighWaterBytes;
bsalomon71cb0c22014-11-14 12:10:14 -0800307#endif
308
bsalomondace19e2014-11-17 07:34:06 -0800309 // our current stats for all resources
bsalomonf320e042015-02-17 15:09:34 -0800310 SkDEBUGCODE(int fCount;)
bsalomon71cb0c22014-11-14 12:10:14 -0800311 size_t fBytes;
312
bsalomondace19e2014-11-17 07:34:06 -0800313 // our current stats for resources that count against the budget
314 int fBudgetedCount;
315 size_t fBudgetedBytes;
316
bsalomonb77a9072016-09-07 10:02:04 -0700317 bool fRequestFlush;
bsalomone2e87f32016-09-22 12:42:11 -0700318 uint32_t fExternalFlushCnt;
bsalomon3f324322015-04-08 11:01:54 -0700319
bsalomon8718aaf2015-02-19 07:24:21 -0800320 InvalidUniqueKeyInbox fInvalidUniqueKeyInbox;
bsalomon3f324322015-04-08 11:01:54 -0700321
322 // This resource is allowed to be in the nonpurgeable array for the sake of validate() because
323 // we're in the midst of converting it to purgeable status.
324 SkDEBUGCODE(GrGpuResource* fNewlyPurgeableResourceForValidation;)
robertphillips63926682015-08-20 09:39:02 -0700325
326 bool fPreferVRAMUseOverFlushes;
bsalomonc8dc1f72014-08-21 13:02:13 -0700327};
328
bsalomon0ea80f42015-02-11 10:49:59 -0800329class GrResourceCache::ResourceAccess {
bsalomon71cb0c22014-11-14 12:10:14 -0800330private:
bsalomon0ea80f42015-02-11 10:49:59 -0800331 ResourceAccess(GrResourceCache* cache) : fCache(cache) { }
bsalomon71cb0c22014-11-14 12:10:14 -0800332 ResourceAccess(const ResourceAccess& that) : fCache(that.fCache) { }
333 ResourceAccess& operator=(const ResourceAccess&); // unimpl
334
335 /**
336 * Insert a resource into the cache.
337 */
338 void insertResource(GrGpuResource* resource) { fCache->insertResource(resource); }
339
340 /**
341 * Removes a resource from the cache.
342 */
343 void removeResource(GrGpuResource* resource) { fCache->removeResource(resource); }
344
345 /**
bsalomon3f324322015-04-08 11:01:54 -0700346 * Notifications that should be sent to the cache when the ref/io cnt status of resources
347 * changes.
bsalomon71cb0c22014-11-14 12:10:14 -0800348 */
bsalomon3f324322015-04-08 11:01:54 -0700349 enum RefNotificationFlags {
350 /** All types of refs on the resource have reached zero. */
351 kAllCntsReachedZero_RefNotificationFlag = 0x1,
352 /** The normal (not pending IO type) ref cnt has reached zero. */
353 kRefCntReachedZero_RefNotificationFlag = 0x2,
354 };
355 /**
356 * Called by GrGpuResources when they detect that their ref/io cnts have reached zero. When the
357 * normal ref cnt reaches zero the flags that are set should be:
358 * a) kRefCntReachedZero if a pending IO cnt is still non-zero.
359 * b) (kRefCntReachedZero | kAllCntsReachedZero) when all pending IO cnts are also zero.
360 * kAllCntsReachedZero is set by itself if a pending IO cnt is decremented to zero and all the
361 * the other cnts are already zero.
362 */
363 void notifyCntReachedZero(GrGpuResource* resource, uint32_t flags) {
364 fCache->notifyCntReachedZero(resource, flags);
365 }
bsalomon71cb0c22014-11-14 12:10:14 -0800366
367 /**
368 * Called by GrGpuResources when their sizes change.
369 */
370 void didChangeGpuMemorySize(const GrGpuResource* resource, size_t oldSize) {
371 fCache->didChangeGpuMemorySize(resource, oldSize);
372 }
373
374 /**
bsalomonf99e9612015-02-19 08:24:16 -0800375 * Called by GrGpuResources to change their unique keys.
bsalomon71cb0c22014-11-14 12:10:14 -0800376 */
bsalomonf99e9612015-02-19 08:24:16 -0800377 void changeUniqueKey(GrGpuResource* resource, const GrUniqueKey& newKey) {
378 fCache->changeUniqueKey(resource, newKey);
379 }
bsalomon71cb0c22014-11-14 12:10:14 -0800380
bsalomon10e23ca2014-11-25 05:52:06 -0800381 /**
bsalomonf99e9612015-02-19 08:24:16 -0800382 * Called by a GrGpuResource to remove its unique key.
bsalomon23e619c2015-02-06 11:54:28 -0800383 */
bsalomonf99e9612015-02-19 08:24:16 -0800384 void removeUniqueKey(GrGpuResource* resource) { fCache->removeUniqueKey(resource); }
bsalomon23e619c2015-02-06 11:54:28 -0800385
386 /**
387 * Called by a GrGpuResource when it removes its scratch key.
bsalomon10e23ca2014-11-25 05:52:06 -0800388 */
389 void willRemoveScratchKey(const GrGpuResource* resource) {
390 fCache->willRemoveScratchKey(resource);
391 }
bsalomon84c8e622014-11-17 09:33:27 -0800392
393 /**
394 * Called by GrGpuResources when they change from budgeted to unbudgeted or vice versa.
395 */
396 void didChangeBudgetStatus(GrGpuResource* resource) { fCache->didChangeBudgetStatus(resource); }
397
bsalomon71cb0c22014-11-14 12:10:14 -0800398 // No taking addresses of this type.
399 const ResourceAccess* operator&() const;
400 ResourceAccess* operator&();
401
bsalomon0ea80f42015-02-11 10:49:59 -0800402 GrResourceCache* fCache;
bsalomon71cb0c22014-11-14 12:10:14 -0800403
404 friend class GrGpuResource; // To access all the proxy inline methods.
bsalomon0ea80f42015-02-11 10:49:59 -0800405 friend class GrResourceCache; // To create this type.
bsalomon71cb0c22014-11-14 12:10:14 -0800406};
407
bsalomon0ea80f42015-02-11 10:49:59 -0800408inline GrResourceCache::ResourceAccess GrResourceCache::resourceAccess() {
bsalomon71cb0c22014-11-14 12:10:14 -0800409 return ResourceAccess(this);
410}
411
bsalomonc8dc1f72014-08-21 13:02:13 -0700412#endif