blob: adbfb7919ffd25b024d6f70f527e29b18d988ed2 [file] [log] [blame]
bsalomonc8dc1f72014-08-21 13:02:13 -07001
2/*
3 * Copyright 2014 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
8
bsalomon0ea80f42015-02-11 10:49:59 -08009#ifndef GrResourceCache_DEFINED
10#define GrResourceCache_DEFINED
bsalomonc8dc1f72014-08-21 13:02:13 -070011
bsalomon744998e2014-08-28 09:54:34 -070012#include "GrGpuResource.h"
bsalomon9f2d1572015-02-17 11:47:40 -080013#include "GrGpuResourceCacheAccess.h"
bsalomon3582d3e2015-02-13 14:20:05 -080014#include "GrGpuResourcePriv.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.
bsalomon3f324322015-04-08 11:01:54 -070043 *
44 * When proactive purging is enabled, on every flush, the timestamp of that flush is stored in a
45 * n-sized ring buffer. When purging occurs each purgeable resource's timestamp is compared to the
46 * timestamp of the n-th prior flush. If the resource's last use timestamp is older than the old
47 * flush then the resource is proactively purged even when the cache is under budget. By default
48 * this feature is disabled, though it can be enabled by calling GrResourceCache::setLimits.
bsalomonc8dc1f72014-08-21 13:02:13 -070049 */
bsalomon0ea80f42015-02-11 10:49:59 -080050class GrResourceCache {
bsalomonc8dc1f72014-08-21 13:02:13 -070051public:
robertphillips63926682015-08-20 09:39:02 -070052 GrResourceCache(const GrCaps* caps);
bsalomon0ea80f42015-02-11 10:49:59 -080053 ~GrResourceCache();
bsalomonc8dc1f72014-08-21 13:02:13 -070054
bsalomon3f324322015-04-08 11:01:54 -070055 // Default maximum number of budgeted resources in the cache.
56 static const int kDefaultMaxCount = 2 * (1 << 12);
57 // Default maximum number of bytes of gpu memory of budgeted resources in the cache.
58 static const size_t kDefaultMaxSize = 96 * (1 << 20);
59 // Default number of flushes a budgeted resources can go unused in the cache before it is
60 // purged. Large values disable the feature (as the ring buffer of flush timestamps would be
bsalomonc03bdfa2015-11-03 11:48:43 -080061 // large). This is currently the default until we decide to enable this feature
62 // of the cache by default.
bsalomon9f0337e2015-12-09 06:27:59 -080063 static const int kDefaultMaxUnusedFlushes = 64;
bsalomon3f324322015-04-08 11:01:54 -070064
bsalomon71cb0c22014-11-14 12:10:14 -080065 /** Used to access functionality needed by GrGpuResource for lifetime management. */
66 class ResourceAccess;
67 ResourceAccess resourceAccess();
bsalomonc8dc1f72014-08-21 13:02:13 -070068
bsalomon71cb0c22014-11-14 12:10:14 -080069 /**
bsalomon3f324322015-04-08 11:01:54 -070070 * Sets the cache limits in terms of number of resources, max gpu memory byte size, and number
71 * of GrContext flushes that a resource can be unused before it is evicted. The latter value is
72 * a suggestion and there is no promise that a resource will be purged immediately after it
73 * hasn't been used in maxUnusedFlushes flushes.
bsalomon71cb0c22014-11-14 12:10:14 -080074 */
bsalomon3f324322015-04-08 11:01:54 -070075 void setLimits(int count, size_t bytes, int maxUnusedFlushes = kDefaultMaxUnusedFlushes);
bsalomonc8dc1f72014-08-21 13:02:13 -070076
bsalomon71cb0c22014-11-14 12:10:14 -080077 /**
bsalomondace19e2014-11-17 07:34:06 -080078 * Returns the number of resources.
bsalomon71cb0c22014-11-14 12:10:14 -080079 */
bsalomonf320e042015-02-17 15:09:34 -080080 int getResourceCount() const {
81 return fPurgeableQueue.count() + fNonpurgeableResources.count();
82 }
bsalomon8b79d232014-11-10 10:19:06 -080083
bsalomon71cb0c22014-11-14 12:10:14 -080084 /**
bsalomondace19e2014-11-17 07:34:06 -080085 * Returns the number of resources that count against the budget.
86 */
87 int getBudgetedResourceCount() const { return fBudgetedCount; }
88
89 /**
90 * Returns the number of bytes consumed by resources.
bsalomon71cb0c22014-11-14 12:10:14 -080091 */
92 size_t getResourceBytes() const { return fBytes; }
93
94 /**
bsalomondace19e2014-11-17 07:34:06 -080095 * Returns the number of bytes consumed by budgeted resources.
96 */
97 size_t getBudgetedResourceBytes() const { return fBudgetedBytes; }
98
99 /**
bsalomon71cb0c22014-11-14 12:10:14 -0800100 * Returns the cached resources count budget.
101 */
102 int getMaxResourceCount() const { return fMaxCount; }
103
104 /**
105 * Returns the number of bytes consumed by cached resources.
106 */
107 size_t getMaxResourceBytes() const { return fMaxBytes; }
108
109 /**
110 * Abandons the backend API resources owned by all GrGpuResource objects and removes them from
111 * the cache.
112 */
bsalomonc8dc1f72014-08-21 13:02:13 -0700113 void abandonAll();
114
bsalomon71cb0c22014-11-14 12:10:14 -0800115 /**
116 * Releases the backend API resources owned by all GrGpuResource objects and removes them from
117 * the cache.
118 */
bsalomonc8dc1f72014-08-21 13:02:13 -0700119 void releaseAll();
120
bsalomon000f8292014-10-15 19:04:14 -0700121 enum {
122 /** Preferentially returns scratch resources with no pending IO. */
123 kPreferNoPendingIO_ScratchFlag = 0x1,
124 /** Will not return any resources that match but have pending IO. */
125 kRequireNoPendingIO_ScratchFlag = 0x2,
126 };
bsalomon71cb0c22014-11-14 12:10:14 -0800127
128 /**
129 * Find a resource that matches a scratch key.
130 */
robertphillips6e83ac72015-08-13 05:19:14 -0700131 GrGpuResource* findAndRefScratchResource(const GrScratchKey& scratchKey,
132 size_t resourceSize,
133 uint32_t flags);
bsalomon8b79d232014-11-10 10:19:06 -0800134
135#ifdef SK_DEBUG
136 // This is not particularly fast and only used for validation, so debug only.
bsalomon7775c852014-12-30 12:50:52 -0800137 int countScratchEntriesForKey(const GrScratchKey& scratchKey) const {
bsalomon8b79d232014-11-10 10:19:06 -0800138 return fScratchMap.countForKey(scratchKey);
139 }
140#endif
141
bsalomon71cb0c22014-11-14 12:10:14 -0800142 /**
bsalomon8718aaf2015-02-19 07:24:21 -0800143 * Find a resource that matches a unique key.
bsalomon71cb0c22014-11-14 12:10:14 -0800144 */
bsalomon8718aaf2015-02-19 07:24:21 -0800145 GrGpuResource* findAndRefUniqueResource(const GrUniqueKey& key) {
146 GrGpuResource* resource = fUniqueHash.find(key);
bsalomon71cb0c22014-11-14 12:10:14 -0800147 if (resource) {
bsalomon9f2d1572015-02-17 11:47:40 -0800148 this->refAndMakeResourceMRU(resource);
bsalomon71cb0c22014-11-14 12:10:14 -0800149 }
150 return resource;
bsalomon8b79d232014-11-10 10:19:06 -0800151 }
152
bsalomon71cb0c22014-11-14 12:10:14 -0800153 /**
bsalomon8718aaf2015-02-19 07:24:21 -0800154 * Query whether a unique key exists in the cache.
bsalomon71cb0c22014-11-14 12:10:14 -0800155 */
bsalomon8718aaf2015-02-19 07:24:21 -0800156 bool hasUniqueKey(const GrUniqueKey& key) const {
157 return SkToBool(fUniqueHash.find(key));
bsalomon8b79d232014-11-10 10:19:06 -0800158 }
bsalomonbcf0a522014-10-08 08:40:09 -0700159
bsalomon8718aaf2015-02-19 07:24:21 -0800160 /** Purges resources to become under budget and processes resources with invalidated unique
bsalomon23e619c2015-02-06 11:54:28 -0800161 keys. */
bsalomon3f324322015-04-08 11:01:54 -0700162 void purgeAsNeeded();
bsalomon23e619c2015-02-06 11:54:28 -0800163
bsalomon71cb0c22014-11-14 12:10:14 -0800164 /** Purges all resources that don't have external owners. */
165 void purgeAllUnlocked();
166
167 /**
168 * The callback function used by the cache when it is still over budget after a purge. The
169 * passed in 'data' is the same 'data' handed to setOverbudgetCallback.
170 */
171 typedef void (*PFOverBudgetCB)(void* data);
172
173 /**
174 * Set the callback the cache should use when it is still over budget after a purge. The 'data'
175 * provided here will be passed back to the callback. Note that the cache will attempt to purge
176 * any resources newly freed by the callback.
177 */
178 void setOverBudgetCallback(PFOverBudgetCB overBudgetCB, void* data) {
179 fOverBudgetCB = overBudgetCB;
180 fOverBudgetData = data;
181 }
ericrk0a5fa482015-09-15 14:16:10 -0700182
bsalomon3f324322015-04-08 11:01:54 -0700183 void notifyFlushOccurred();
bsalomon71cb0c22014-11-14 12:10:14 -0800184
robertphillips60029a52015-11-09 13:51:06 -0800185#if GR_CACHE_STATS
186 struct Stats {
187 int fTotal;
188 int fNumPurgeable;
189 int fNumNonPurgeable;
190
191 int fScratch;
192 int fExternal;
193 int fBorrowed;
194 int fAdopted;
195 size_t fUnbudgetedSize;
196
197 Stats() { this->reset(); }
198
199 void reset() {
200 fTotal = 0;
201 fNumPurgeable = 0;
202 fNumNonPurgeable = 0;
203 fScratch = 0;
204 fExternal = 0;
205 fBorrowed = 0;
206 fAdopted = 0;
207 fUnbudgetedSize = 0;
208 }
209
210 void update(GrGpuResource* resource) {
211 if (resource->cacheAccess().isScratch()) {
212 ++fScratch;
213 }
214 if (resource->cacheAccess().isExternal()) {
215 ++fExternal;
216 }
217 if (resource->cacheAccess().isBorrowed()) {
218 ++fBorrowed;
219 }
220 if (resource->cacheAccess().isAdopted()) {
221 ++fAdopted;
222 }
223 if (!resource->resourcePriv().isBudgeted()) {
224 fUnbudgetedSize += resource->gpuMemorySize();
225 }
226 }
227 };
228
229 void getStats(Stats*) const;
230
mtkleinb9eb4ac2015-02-02 18:26:03 -0800231 void dumpStats(SkString*) const;
joshualittdc5685a2015-12-02 14:08:25 -0800232
233 void dumpStatsKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* value) const;
bsalomon71cb0c22014-11-14 12:10:14 -0800234#endif
235
bsalomonddf30e62015-02-19 11:38:44 -0800236 // This function is for unit testing and is only defined in test tools.
237 void changeTimestamp(uint32_t newTimestamp);
238
ericrk0a5fa482015-09-15 14:16:10 -0700239 // Enumerates all cached resources and dumps their details to traceMemoryDump.
240 void dumpMemoryStatistics(SkTraceMemoryDump* traceMemoryDump) const;
241
bsalomonc8dc1f72014-08-21 13:02:13 -0700242private:
bsalomon71cb0c22014-11-14 12:10:14 -0800243 ///////////////////////////////////////////////////////////////////////////
244 /// @name Methods accessible via ResourceAccess
245 ////
246 void insertResource(GrGpuResource*);
247 void removeResource(GrGpuResource*);
bsalomon3f324322015-04-08 11:01:54 -0700248 void notifyCntReachedZero(GrGpuResource*, uint32_t flags);
bsalomon71cb0c22014-11-14 12:10:14 -0800249 void didChangeGpuMemorySize(const GrGpuResource*, size_t oldSize);
bsalomonf99e9612015-02-19 08:24:16 -0800250 void changeUniqueKey(GrGpuResource*, const GrUniqueKey&);
251 void removeUniqueKey(GrGpuResource*);
bsalomon10e23ca2014-11-25 05:52:06 -0800252 void willRemoveScratchKey(const GrGpuResource*);
bsalomon84c8e622014-11-17 09:33:27 -0800253 void didChangeBudgetStatus(GrGpuResource*);
bsalomon9f2d1572015-02-17 11:47:40 -0800254 void refAndMakeResourceMRU(GrGpuResource*);
bsalomon71cb0c22014-11-14 12:10:14 -0800255 /// @}
256
bsalomon3f324322015-04-08 11:01:54 -0700257 void resetFlushTimestamps();
bsalomon8718aaf2015-02-19 07:24:21 -0800258 void processInvalidUniqueKeys(const SkTArray<GrUniqueKeyInvalidatedMessage>&);
bsalomonf320e042015-02-17 15:09:34 -0800259 void addToNonpurgeableArray(GrGpuResource*);
260 void removeFromNonpurgeableArray(GrGpuResource*);
261 bool overBudget() const { return fBudgetedBytes > fMaxBytes || fBudgetedCount > fMaxCount; }
bsalomon71cb0c22014-11-14 12:10:14 -0800262
robertphillips6e83ac72015-08-13 05:19:14 -0700263 bool wouldFit(size_t bytes) {
264 return fBudgetedBytes+bytes <= fMaxBytes && fBudgetedCount+1 <= fMaxCount;
265 }
266
bsalomonddf30e62015-02-19 11:38:44 -0800267 uint32_t getNextTimestamp();
268
bsalomon16961262014-08-26 14:01:07 -0700269#ifdef SK_DEBUG
bsalomonf320e042015-02-17 15:09:34 -0800270 bool isInCache(const GrGpuResource* r) const;
bsalomon71cb0c22014-11-14 12:10:14 -0800271 void validate() const;
272#else
273 void validate() const {}
bsalomon16961262014-08-26 14:01:07 -0700274#endif
275
bsalomon71cb0c22014-11-14 12:10:14 -0800276 class AutoValidate;
277
bsalomonbcf0a522014-10-08 08:40:09 -0700278 class AvailableForScratchUse;
bsalomon744998e2014-08-28 09:54:34 -0700279
bsalomon744998e2014-08-28 09:54:34 -0700280 struct ScratchMapTraits {
bsalomon7775c852014-12-30 12:50:52 -0800281 static const GrScratchKey& GetKey(const GrGpuResource& r) {
bsalomon3582d3e2015-02-13 14:20:05 -0800282 return r.resourcePriv().getScratchKey();
bsalomon744998e2014-08-28 09:54:34 -0700283 }
284
bsalomon7775c852014-12-30 12:50:52 -0800285 static uint32_t Hash(const GrScratchKey& key) { return key.hash(); }
bsalomon744998e2014-08-28 09:54:34 -0700286 };
bsalomon7775c852014-12-30 12:50:52 -0800287 typedef SkTMultiMap<GrGpuResource, GrScratchKey, ScratchMapTraits> ScratchMap;
bsalomon744998e2014-08-28 09:54:34 -0700288
bsalomon8718aaf2015-02-19 07:24:21 -0800289 struct UniqueHashTraits {
290 static const GrUniqueKey& GetKey(const GrGpuResource& r) { return r.getUniqueKey(); }
bsalomon8b79d232014-11-10 10:19:06 -0800291
bsalomon8718aaf2015-02-19 07:24:21 -0800292 static uint32_t Hash(const GrUniqueKey& key) { return key.hash(); }
bsalomon8b79d232014-11-10 10:19:06 -0800293 };
bsalomon8718aaf2015-02-19 07:24:21 -0800294 typedef SkTDynamicHash<GrGpuResource, GrUniqueKey, UniqueHashTraits> UniqueHash;
bsalomon8b79d232014-11-10 10:19:06 -0800295
bsalomon9f2d1572015-02-17 11:47:40 -0800296 static bool CompareTimestamp(GrGpuResource* const& a, GrGpuResource* const& b) {
297 return a->cacheAccess().timestamp() < b->cacheAccess().timestamp();
298 }
bsalomon23e619c2015-02-06 11:54:28 -0800299
bsalomon9f2d1572015-02-17 11:47:40 -0800300 static int* AccessResourceIndex(GrGpuResource* const& res) {
301 return res->cacheAccess().accessCacheIndex();
302 }
303
bsalomon8718aaf2015-02-19 07:24:21 -0800304 typedef SkMessageBus<GrUniqueKeyInvalidatedMessage>::Inbox InvalidUniqueKeyInbox;
bsalomon9f2d1572015-02-17 11:47:40 -0800305 typedef SkTDPQueue<GrGpuResource*, CompareTimestamp, AccessResourceIndex> PurgeableQueue;
bsalomonf320e042015-02-17 15:09:34 -0800306 typedef SkTDArray<GrGpuResource*> ResourceArray;
bsalomon9f2d1572015-02-17 11:47:40 -0800307
308 // Whenever a resource is added to the cache or the result of a cache lookup, fTimestamp is
309 // assigned as the resource's timestamp and then incremented. fPurgeableQueue orders the
310 // purgeable resources by this value, and thus is used to purge resources in LRU order.
311 uint32_t fTimestamp;
312 PurgeableQueue fPurgeableQueue;
bsalomonf320e042015-02-17 15:09:34 -0800313 ResourceArray fNonpurgeableResources;
bsalomon9f2d1572015-02-17 11:47:40 -0800314
bsalomon744998e2014-08-28 09:54:34 -0700315 // This map holds all resources that can be used as scratch resources.
bsalomon8b79d232014-11-10 10:19:06 -0800316 ScratchMap fScratchMap;
bsalomon8718aaf2015-02-19 07:24:21 -0800317 // This holds all resources that have unique keys.
318 UniqueHash fUniqueHash;
bsalomon71cb0c22014-11-14 12:10:14 -0800319
320 // our budget, used in purgeAsNeeded()
321 int fMaxCount;
322 size_t fMaxBytes;
bsalomon3f324322015-04-08 11:01:54 -0700323 int fMaxUnusedFlushes;
bsalomon71cb0c22014-11-14 12:10:14 -0800324
325#if GR_CACHE_STATS
326 int fHighWaterCount;
327 size_t fHighWaterBytes;
bsalomondace19e2014-11-17 07:34:06 -0800328 int fBudgetedHighWaterCount;
329 size_t fBudgetedHighWaterBytes;
bsalomon71cb0c22014-11-14 12:10:14 -0800330#endif
331
bsalomondace19e2014-11-17 07:34:06 -0800332 // our current stats for all resources
bsalomonf320e042015-02-17 15:09:34 -0800333 SkDEBUGCODE(int fCount;)
bsalomon71cb0c22014-11-14 12:10:14 -0800334 size_t fBytes;
335
bsalomondace19e2014-11-17 07:34:06 -0800336 // our current stats for resources that count against the budget
337 int fBudgetedCount;
338 size_t fBudgetedBytes;
339
bsalomon71cb0c22014-11-14 12:10:14 -0800340 PFOverBudgetCB fOverBudgetCB;
341 void* fOverBudgetData;
342
bsalomon3f324322015-04-08 11:01:54 -0700343 // We keep track of the "timestamps" of the last n flushes. If a resource hasn't been used in
344 // that time then we well preemptively purge it to reduce memory usage.
345 uint32_t* fFlushTimestamps;
346 int fLastFlushTimestampIndex;
347
bsalomon8718aaf2015-02-19 07:24:21 -0800348 InvalidUniqueKeyInbox fInvalidUniqueKeyInbox;
bsalomon3f324322015-04-08 11:01:54 -0700349
350 // This resource is allowed to be in the nonpurgeable array for the sake of validate() because
351 // we're in the midst of converting it to purgeable status.
352 SkDEBUGCODE(GrGpuResource* fNewlyPurgeableResourceForValidation;)
robertphillips63926682015-08-20 09:39:02 -0700353
354 bool fPreferVRAMUseOverFlushes;
bsalomonc8dc1f72014-08-21 13:02:13 -0700355};
356
bsalomon0ea80f42015-02-11 10:49:59 -0800357class GrResourceCache::ResourceAccess {
bsalomon71cb0c22014-11-14 12:10:14 -0800358private:
bsalomon0ea80f42015-02-11 10:49:59 -0800359 ResourceAccess(GrResourceCache* cache) : fCache(cache) { }
bsalomon71cb0c22014-11-14 12:10:14 -0800360 ResourceAccess(const ResourceAccess& that) : fCache(that.fCache) { }
361 ResourceAccess& operator=(const ResourceAccess&); // unimpl
362
363 /**
364 * Insert a resource into the cache.
365 */
366 void insertResource(GrGpuResource* resource) { fCache->insertResource(resource); }
367
368 /**
369 * Removes a resource from the cache.
370 */
371 void removeResource(GrGpuResource* resource) { fCache->removeResource(resource); }
372
373 /**
bsalomon3f324322015-04-08 11:01:54 -0700374 * Notifications that should be sent to the cache when the ref/io cnt status of resources
375 * changes.
bsalomon71cb0c22014-11-14 12:10:14 -0800376 */
bsalomon3f324322015-04-08 11:01:54 -0700377 enum RefNotificationFlags {
378 /** All types of refs on the resource have reached zero. */
379 kAllCntsReachedZero_RefNotificationFlag = 0x1,
380 /** The normal (not pending IO type) ref cnt has reached zero. */
381 kRefCntReachedZero_RefNotificationFlag = 0x2,
382 };
383 /**
384 * Called by GrGpuResources when they detect that their ref/io cnts have reached zero. When the
385 * normal ref cnt reaches zero the flags that are set should be:
386 * a) kRefCntReachedZero if a pending IO cnt is still non-zero.
387 * b) (kRefCntReachedZero | kAllCntsReachedZero) when all pending IO cnts are also zero.
388 * kAllCntsReachedZero is set by itself if a pending IO cnt is decremented to zero and all the
389 * the other cnts are already zero.
390 */
391 void notifyCntReachedZero(GrGpuResource* resource, uint32_t flags) {
392 fCache->notifyCntReachedZero(resource, flags);
393 }
bsalomon71cb0c22014-11-14 12:10:14 -0800394
395 /**
396 * Called by GrGpuResources when their sizes change.
397 */
398 void didChangeGpuMemorySize(const GrGpuResource* resource, size_t oldSize) {
399 fCache->didChangeGpuMemorySize(resource, oldSize);
400 }
401
402 /**
bsalomonf99e9612015-02-19 08:24:16 -0800403 * Called by GrGpuResources to change their unique keys.
bsalomon71cb0c22014-11-14 12:10:14 -0800404 */
bsalomonf99e9612015-02-19 08:24:16 -0800405 void changeUniqueKey(GrGpuResource* resource, const GrUniqueKey& newKey) {
406 fCache->changeUniqueKey(resource, newKey);
407 }
bsalomon71cb0c22014-11-14 12:10:14 -0800408
bsalomon10e23ca2014-11-25 05:52:06 -0800409 /**
bsalomonf99e9612015-02-19 08:24:16 -0800410 * Called by a GrGpuResource to remove its unique key.
bsalomon23e619c2015-02-06 11:54:28 -0800411 */
bsalomonf99e9612015-02-19 08:24:16 -0800412 void removeUniqueKey(GrGpuResource* resource) { fCache->removeUniqueKey(resource); }
bsalomon23e619c2015-02-06 11:54:28 -0800413
414 /**
415 * Called by a GrGpuResource when it removes its scratch key.
bsalomon10e23ca2014-11-25 05:52:06 -0800416 */
417 void willRemoveScratchKey(const GrGpuResource* resource) {
418 fCache->willRemoveScratchKey(resource);
419 }
bsalomon84c8e622014-11-17 09:33:27 -0800420
421 /**
422 * Called by GrGpuResources when they change from budgeted to unbudgeted or vice versa.
423 */
424 void didChangeBudgetStatus(GrGpuResource* resource) { fCache->didChangeBudgetStatus(resource); }
425
bsalomon71cb0c22014-11-14 12:10:14 -0800426 // No taking addresses of this type.
427 const ResourceAccess* operator&() const;
428 ResourceAccess* operator&();
429
bsalomon0ea80f42015-02-11 10:49:59 -0800430 GrResourceCache* fCache;
bsalomon71cb0c22014-11-14 12:10:14 -0800431
432 friend class GrGpuResource; // To access all the proxy inline methods.
bsalomon0ea80f42015-02-11 10:49:59 -0800433 friend class GrResourceCache; // To create this type.
bsalomon71cb0c22014-11-14 12:10:14 -0800434};
435
bsalomon0ea80f42015-02-11 10:49:59 -0800436inline GrResourceCache::ResourceAccess GrResourceCache::resourceAccess() {
bsalomon71cb0c22014-11-14 12:10:14 -0800437 return ResourceAccess(this);
438}
439
bsalomonc8dc1f72014-08-21 13:02:13 -0700440#endif