blob: 38378ac77130ffdf45c522ef24ee9474d2aa0bb3 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
bsalomon@google.com50398bf2011-07-26 20:45:30 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * Copyright 2011 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.
bsalomon@google.com50398bf2011-07-26 20:45:30 +00007 */
8
9
epoger@google.comec3ed6a2011-07-28 14:26:00 +000010
bsalomon@google.com50398bf2011-07-26 20:45:30 +000011#ifndef GrResourceCache_DEFINED
12#define GrResourceCache_DEFINED
13
robertphillips@google.com59552022012-08-31 13:07:37 +000014#include "GrConfig.h"
bsalomon@google.com50398bf2011-07-26 20:45:30 +000015#include "GrTypes.h"
mtklein@google.com4c2af742013-10-21 21:04:06 +000016#include "GrTHashTable.h"
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000017#include "GrBinHashKey.h"
commit-bot@chromium.org50a30432013-10-24 17:44:27 +000018#include "SkMessageBus.h"
bsalomon@google.com42619d82012-12-03 14:54:59 +000019#include "SkTInternalLList.h"
bsalomon@google.com50398bf2011-07-26 20:45:30 +000020
21class GrResource;
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000022class GrResourceEntry;
bsalomon@google.com50398bf2011-07-26 20:45:30 +000023
bsalomon@google.com50398bf2011-07-26 20:45:30 +000024class GrResourceKey {
25public:
26 enum {
27 kHashBits = 7,
28 kHashCount = 1 << kHashBits,
29 kHashMask = kHashCount - 1
30 };
31
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000032 static GrCacheID::Domain ScratchDomain() {
33 static const GrCacheID::Domain gDomain = GrCacheID::GenerateDomain();
34 return gDomain;
bsalomon@google.com50398bf2011-07-26 20:45:30 +000035 }
36
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000037 /** Uniquely identifies the GrResource subclass in the key to avoid collisions
38 across resource types. */
39 typedef uint8_t ResourceType;
40
41 /** Flags set by the GrResource subclass. */
42 typedef uint8_t ResourceFlags;
43
44 /** Generate a unique ResourceType */
45 static ResourceType GenerateResourceType();
46
47 /** Creates a key for resource */
48 GrResourceKey(const GrCacheID& id, ResourceType type, ResourceFlags flags) {
49 this->init(id.getDomain(), id.getKey(), type, flags);
50 };
bsalomon@google.com50398bf2011-07-26 20:45:30 +000051
52 GrResourceKey(const GrResourceKey& src) {
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000053 fKey = src.fKey;
54 }
55
56 GrResourceKey() {
57 fKey.fHashedKey.reset();
58 }
59
60 void reset(const GrCacheID& id, ResourceType type, ResourceFlags flags) {
61 this->init(id.getDomain(), id.getKey(), type, flags);
bsalomon@google.com50398bf2011-07-26 20:45:30 +000062 }
63
64 //!< returns hash value [0..kHashMask] for the key
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000065 int getHash() const {
66 return fKey.fHashedKey.getHash() & kHashMask;
bsalomon@google.com50398bf2011-07-26 20:45:30 +000067 }
68
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000069 bool isScratch() const {
70 return ScratchDomain() ==
71 *reinterpret_cast<const GrCacheID::Domain*>(fKey.fHashedKey.getData() +
72 kCacheIDDomainOffset);
bsalomon@google.com50398bf2011-07-26 20:45:30 +000073 }
74
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000075 ResourceType getResourceType() const {
76 return *reinterpret_cast<const ResourceType*>(fKey.fHashedKey.getData() +
77 kResourceTypeOffset);
bsalomon@google.com50398bf2011-07-26 20:45:30 +000078 }
79
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000080 ResourceFlags getResourceFlags() const {
81 return *reinterpret_cast<const ResourceFlags*>(fKey.fHashedKey.getData() +
82 kResourceFlagsOffset);
bsalomon@google.com50398bf2011-07-26 20:45:30 +000083 }
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000084
85 int compare(const GrResourceKey& other) const {
86 return fKey.fHashedKey.compare(other.fKey.fHashedKey);
87 }
88
89 static bool LT(const GrResourceKey& a, const GrResourceKey& b) {
90 return a.compare(b) < 0;
91 }
92
93 static bool EQ(const GrResourceKey& a, const GrResourceKey& b) {
94 return 0 == a.compare(b);
95 }
96
97 inline static bool LT(const GrResourceEntry& entry, const GrResourceKey& key);
98 inline static bool EQ(const GrResourceEntry& entry, const GrResourceKey& key);
99 inline static bool LT(const GrResourceEntry& a, const GrResourceEntry& b);
100 inline static bool EQ(const GrResourceEntry& a, const GrResourceEntry& b);
101
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000102private:
bsalomon@google.com0797c2c2012-12-20 15:13:01 +0000103 enum {
104 kCacheIDKeyOffset = 0,
105 kCacheIDDomainOffset = kCacheIDKeyOffset + sizeof(GrCacheID::Key),
106 kResourceTypeOffset = kCacheIDDomainOffset + sizeof(GrCacheID::Domain),
107 kResourceFlagsOffset = kResourceTypeOffset + sizeof(ResourceType),
108 kPadOffset = kResourceFlagsOffset + sizeof(ResourceFlags),
109 kKeySize = SkAlign4(kPadOffset),
110 kPadSize = kKeySize - kPadOffset
111 };
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000112
bsalomon@google.com0797c2c2012-12-20 15:13:01 +0000113 void init(const GrCacheID::Domain domain,
114 const GrCacheID::Key& key,
115 ResourceType type,
116 ResourceFlags flags) {
117 union {
118 uint8_t fKey8[kKeySize];
119 uint32_t fKey32[kKeySize / 4];
120 } keyData;
skia.committer@gmail.com2859eb72012-12-21 02:01:28 +0000121
bsalomon@google.com0797c2c2012-12-20 15:13:01 +0000122 uint8_t* k = keyData.fKey8;
123 memcpy(k + kCacheIDKeyOffset, key.fData8, sizeof(GrCacheID::Key));
124 memcpy(k + kCacheIDDomainOffset, &domain, sizeof(GrCacheID::Domain));
125 memcpy(k + kResourceTypeOffset, &type, sizeof(ResourceType));
126 memcpy(k + kResourceFlagsOffset, &flags, sizeof(ResourceFlags));
127 memset(k + kPadOffset, 0, kPadSize);
128 fKey.fHashedKey.setKeyData(keyData.fKey32);
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000129 }
130
bsalomon@google.com0797c2c2012-12-20 15:13:01 +0000131 struct Key;
132 typedef GrTBinHashKey<Key, kKeySize> HashedKey;
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000133
bsalomon@google.com0797c2c2012-12-20 15:13:01 +0000134 struct Key {
135 int compare(const HashedKey& hashedKey) const {
sugoi@google.comff57afc2013-02-25 20:42:44 +0000136 return fHashedKey.compare(hashedKey);
bsalomon@google.com0797c2c2012-12-20 15:13:01 +0000137 }
skia.committer@gmail.com2859eb72012-12-21 02:01:28 +0000138
bsalomon@google.com0797c2c2012-12-20 15:13:01 +0000139 HashedKey fHashedKey;
140 };
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000141
bsalomon@google.com0797c2c2012-12-20 15:13:01 +0000142 Key fKey;
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000143};
144
commit-bot@chromium.org50a30432013-10-24 17:44:27 +0000145// The cache listens for these messages to purge junk resources proactively.
146struct GrResourceInvalidatedMessage {
147 GrResourceKey key;
148};
149
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000150///////////////////////////////////////////////////////////////////////////////
151
152class GrResourceEntry {
153public:
154 GrResource* resource() const { return fResource; }
155 const GrResourceKey& key() const { return fKey; }
156
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000157#ifdef SK_DEBUG
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000158 void validate() const;
159#else
160 void validate() const {}
161#endif
162
163private:
164 GrResourceEntry(const GrResourceKey& key, GrResource* resource);
165 ~GrResourceEntry();
166
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000167 GrResourceKey fKey;
168 GrResource* fResource;
169
bsalomon@google.com42619d82012-12-03 14:54:59 +0000170 // we're a linked list
171 SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrResourceEntry);
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000172
173 friend class GrResourceCache;
robertphillips@google.com521eaf82012-08-22 11:03:19 +0000174 friend class GrDLinkedList;
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000175};
176
bsalomon@google.com0797c2c2012-12-20 15:13:01 +0000177bool GrResourceKey::LT(const GrResourceEntry& entry, const GrResourceKey& key) {
178 return LT(entry.key(), key);
179}
180
181bool GrResourceKey::EQ(const GrResourceEntry& entry, const GrResourceKey& key) {
182 return EQ(entry.key(), key);
183}
184
185bool GrResourceKey::LT(const GrResourceEntry& a, const GrResourceEntry& b) {
186 return LT(a.key(), b.key());
187}
188
189bool GrResourceKey::EQ(const GrResourceEntry& a, const GrResourceEntry& b) {
190 return EQ(a.key(), b.key());
191}
192
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000193///////////////////////////////////////////////////////////////////////////////
194
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000195/**
196 * Cache of GrResource objects.
197 *
198 * These have a corresponding GrResourceKey, built from 128bits identifying the
199 * resource.
200 *
201 * The cache stores the entries in a double-linked list, which is its LRU.
202 * When an entry is "locked" (i.e. given to the caller), it is moved to the
203 * head of the list. If/when we must purge some of the entries, we walk the
204 * list backwards from the tail, since those are the least recently used.
205 *
206 * For fast searches, we maintain a sorted array (based on the GrResourceKey)
207 * which we can bsearch. When a new entry is added, it is inserted into this
208 * array.
209 *
210 * For even faster searches, a hash is computed from the Key. If there is
211 * a collision between two keys with the same hash, we fall back on the
212 * bsearch, and update the hash to reflect the most recent Key requested.
bsalomon@google.com76202b82013-05-10 19:08:22 +0000213 *
214 * It is a goal to make the GrResourceCache the central repository and bookkeeper
215 * of all resources. It should replace the linked list of GrResources that
216 * GrGpu uses to call abandon/release.
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000217 */
218class GrResourceCache {
219public:
bsalomon@google.com07fc0d12012-06-22 15:15:59 +0000220 GrResourceCache(int maxCount, size_t maxBytes);
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000221 ~GrResourceCache();
222
223 /**
bsalomon@google.com07fc0d12012-06-22 15:15:59 +0000224 * Return the current resource cache limits.
225 *
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000226 * @param maxResource If non-null, returns maximum number of resources
bsalomon@google.com07fc0d12012-06-22 15:15:59 +0000227 * that can be held in the cache.
228 * @param maxBytes If non-null, returns maximum number of bytes of
robertphillips@google.come4eaea22013-07-19 16:51:46 +0000229 * gpu memory that can be held in the cache.
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000230 */
bsalomon@google.com07fc0d12012-06-22 15:15:59 +0000231 void getLimits(int* maxResources, size_t* maxBytes) const;
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000232
233 /**
bsalomon@google.com07fc0d12012-06-22 15:15:59 +0000234 * Specify the resource cache limits. If the current cache exceeds either
235 * of these, it will be purged (LRU) to keep the cache within these limits.
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000236 *
bsalomon@google.com07fc0d12012-06-22 15:15:59 +0000237 * @param maxResources The maximum number of resources that can be held in
238 * the cache.
239 * @param maxBytes The maximum number of bytes of resource memory that
240 * can be held in the cache.
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000241 */
robertphillips@google.come4eaea22013-07-19 16:51:46 +0000242 void setLimits(int maxResources, size_t maxResourceBytes);
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000243
244 /**
commit-bot@chromium.orgcae27fe2013-07-10 10:14:35 +0000245 * The callback function used by the cache when it is still over budget
skia.committer@gmail.comde2e4e82013-07-11 07:01:01 +0000246 * after a purge. The passed in 'data' is the same 'data' handed to
commit-bot@chromium.orgcae27fe2013-07-10 10:14:35 +0000247 * setOverbudgetCallback. The callback returns true if some resources
248 * have been freed.
249 */
250 typedef bool (*PFOverbudgetCB)(void* data);
251
252 /**
253 * Set the callback the cache should use when it is still over budget
skia.committer@gmail.comde2e4e82013-07-11 07:01:01 +0000254 * after a purge. The 'data' provided here will be passed back to the
skia.committer@gmail.com1f3c7382013-07-20 07:00:58 +0000255 * callback. Note that the cache will attempt to purge any resources newly
robertphillips@google.come4eaea22013-07-19 16:51:46 +0000256 * freed by the callback.
commit-bot@chromium.orgcae27fe2013-07-10 10:14:35 +0000257 */
258 void setOverbudgetCallback(PFOverbudgetCB overbudgetCB, void* data) {
259 fOverbudgetCB = overbudgetCB;
260 fOverbudgetData = data;
261 }
262
263 /**
twiz@google.com05e70242012-01-27 19:12:00 +0000264 * Returns the number of bytes consumed by cached resources.
265 */
266 size_t getCachedResourceBytes() const { return fEntryBytes; }
267
robertphillips@google.com209a1142012-10-31 12:25:21 +0000268 // For a found or added resource to be completely exclusive to the caller
269 // both the kNoOtherOwners and kHide flags need to be specified
270 enum OwnershipFlags {
271 kNoOtherOwners_OwnershipFlag = 0x1, // found/added resource has no other owners
272 kHide_OwnershipFlag = 0x2 // found/added resource is hidden from future 'find's
273 };
274
twiz@google.com05e70242012-01-27 19:12:00 +0000275 /**
robertphillips@google.coma9b06232012-08-30 11:06:31 +0000276 * Search for an entry with the same Key. If found, return it.
277 * If not found, return null.
skia.committer@gmail.comf3dc1992012-11-01 02:01:27 +0000278 * If ownershipFlags includes kNoOtherOwners and a resource is returned
robertphillips@google.com209a1142012-10-31 12:25:21 +0000279 * then that resource has no other refs to it.
280 * If ownershipFlags includes kHide and a resource is returned then that
281 * resource will not be returned from future 'find' calls until it is
282 * 'freed' (and recycled) or makeNonExclusive is called.
283 * For a resource to be completely exclusive to a caller both kNoOtherOwners
284 * and kHide must be specified.
robertphillips@google.coma9b06232012-08-30 11:06:31 +0000285 */
skia.committer@gmail.comf3dc1992012-11-01 02:01:27 +0000286 GrResource* find(const GrResourceKey& key,
robertphillips@google.com209a1142012-10-31 12:25:21 +0000287 uint32_t ownershipFlags = 0);
robertphillips@google.coma9b06232012-08-30 11:06:31 +0000288
289 /**
skia.committer@gmail.comf3dc1992012-11-01 02:01:27 +0000290 * Add the new resource to the cache (by creating a new cache entry based
291 * on the provided key and resource).
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000292 *
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000293 * Ownership of the resource is transferred to the resource cache,
robertphillips@google.com15c0fea2012-06-22 12:41:43 +0000294 * which will unref() it when it is purged or deleted.
robertphillips@google.com209a1142012-10-31 12:25:21 +0000295 *
296 * If ownershipFlags includes kHide, subsequent calls to 'find' will not
skia.committer@gmail.comf3dc1992012-11-01 02:01:27 +0000297 * return 'resource' until it is 'freed' (and recycled) or makeNonExclusive
robertphillips@google.com209a1142012-10-31 12:25:21 +0000298 * is called.
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000299 */
skia.committer@gmail.comf3dc1992012-11-01 02:01:27 +0000300 void addResource(const GrResourceKey& key,
robertphillips@google.com209a1142012-10-31 12:25:21 +0000301 GrResource* resource,
302 uint32_t ownershipFlags = 0);
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000303
304 /**
bsalomon@google.comfb309512011-11-30 14:13:48 +0000305 * Determines if the cache contains an entry matching a key. If a matching
306 * entry exists but was detached then it will not be found.
307 */
robertphillips@google.come4eaea22013-07-19 16:51:46 +0000308 bool hasKey(const GrResourceKey& key) const { return NULL != fCache.find(key); }
bsalomon@google.comfb309512011-11-30 14:13:48 +0000309
310 /**
robertphillips@google.com521eaf82012-08-22 11:03:19 +0000311 * Hide 'entry' so that future searches will not find it. Such
312 * hidden entries will not be purged. The entry still counts against
313 * the cache's budget and should be made non-exclusive when exclusive access
314 * is no longer needed.
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000315 */
robertphillips@google.com521eaf82012-08-22 11:03:19 +0000316 void makeExclusive(GrResourceEntry* entry);
robertphillips@google.com15c0fea2012-06-22 12:41:43 +0000317
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000318 /**
robertphillips@google.com521eaf82012-08-22 11:03:19 +0000319 * Restore 'entry' so that it can be found by future searches. 'entry'
320 * will also be purgeable (provided its lock count is now 0.)
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000321 */
robertphillips@google.com521eaf82012-08-22 11:03:19 +0000322 void makeNonExclusive(GrResourceEntry* entry);
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000323
324 /**
robertphillips@google.come4eaea22013-07-19 16:51:46 +0000325 * Remove a resource from the cache and delete it!
326 */
327 void deleteResource(GrResourceEntry* entry);
328
329 /**
bsalomon@google.coma2921122012-08-28 12:34:17 +0000330 * Removes every resource in the cache that isn't locked.
331 */
332 void purgeAllUnlocked();
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000333
robertphillips@google.com50a035d2012-09-07 19:44:33 +0000334 /**
335 * Allow cache to purge unused resources to obey resource limitations
robertphillips@google.com9fbcad02012-09-09 14:44:15 +0000336 * Note: this entry point will be hidden (again) once totally ref-driven
robertphillips@google.come4eaea22013-07-19 16:51:46 +0000337 * cache maintenance is implemented. Note that the overbudget callback
338 * will be called if the initial purge doesn't get the cache under
339 * its budget.
robertphillips@google.com41d25322013-07-18 17:12:57 +0000340 *
341 * extraCount and extraBytes are added to the current resource allocation
342 * to make sure enough room is available for future additions (e.g,
343 * 10MB across 10 textures is about to be added).
robertphillips@google.com50a035d2012-09-07 19:44:33 +0000344 */
robertphillips@google.com41d25322013-07-18 17:12:57 +0000345 void purgeAsNeeded(int extraCount = 0, size_t extraBytes = 0);
robertphillips@google.com50a035d2012-09-07 19:44:33 +0000346
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000347#ifdef SK_DEBUG
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000348 void validate() const;
349#else
350 void validate() const {}
351#endif
352
robertphillips@google.com59552022012-08-31 13:07:37 +0000353#if GR_CACHE_STATS
robertphillips@google.com9fbcad02012-09-09 14:44:15 +0000354 void printStats();
robertphillips@google.com59552022012-08-31 13:07:37 +0000355#endif
356
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000357private:
robertphillips@google.com209a1142012-10-31 12:25:21 +0000358 enum BudgetBehaviors {
359 kAccountFor_BudgetBehavior,
360 kIgnore_BudgetBehavior
361 };
362
363 void internalDetach(GrResourceEntry*, BudgetBehaviors behavior = kAccountFor_BudgetBehavior);
364 void attachToHead(GrResourceEntry*, BudgetBehaviors behavior = kAccountFor_BudgetBehavior);
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000365
robertphillips@google.com521eaf82012-08-22 11:03:19 +0000366 void removeInvalidResource(GrResourceEntry* entry);
367
bsalomon@google.com0797c2c2012-12-20 15:13:01 +0000368 GrTHashTable<GrResourceEntry, GrResourceKey, 8> fCache;
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000369
bsalomon@google.com42619d82012-12-03 14:54:59 +0000370 // We're an internal doubly linked list
371 typedef SkTInternalLList<GrResourceEntry> EntryList;
robertphillips@google.come4eaea22013-07-19 16:51:46 +0000372 EntryList fList;
robertphillips@google.com521eaf82012-08-22 11:03:19 +0000373
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000374#ifdef SK_DEBUG
robertphillips@google.com521eaf82012-08-22 11:03:19 +0000375 // These objects cannot be returned by a search
robertphillips@google.come4eaea22013-07-19 16:51:46 +0000376 EntryList fExclusiveList;
robertphillips@google.com521eaf82012-08-22 11:03:19 +0000377#endif
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000378
379 // our budget, used in purgeAsNeeded()
robertphillips@google.come4eaea22013-07-19 16:51:46 +0000380 int fMaxCount;
381 size_t fMaxBytes;
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000382
383 // our current stats, related to our budget
robertphillips@google.com59552022012-08-31 13:07:37 +0000384#if GR_CACHE_STATS
robertphillips@google.come4eaea22013-07-19 16:51:46 +0000385 int fHighWaterEntryCount;
386 size_t fHighWaterEntryBytes;
387 int fHighWaterClientDetachedCount;
388 size_t fHighWaterClientDetachedBytes;
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +0000389#endif
390
robertphillips@google.come4eaea22013-07-19 16:51:46 +0000391 int fEntryCount;
392 size_t fEntryBytes;
393 int fClientDetachedCount;
394 size_t fClientDetachedBytes;
robertphillips@google.com386319e2012-06-27 14:59:18 +0000395
bsalomon@google.coma5a1da82011-08-05 14:02:41 +0000396 // prevents recursive purging
commit-bot@chromium.orgcae27fe2013-07-10 10:14:35 +0000397 bool fPurging;
398
399 PFOverbudgetCB fOverbudgetCB;
400 void* fOverbudgetData;
401
robertphillips@google.com41d25322013-07-18 17:12:57 +0000402 void internalPurge(int extraCount, size_t extraBytes);
robertphillips@google.com15c0fea2012-06-22 12:41:43 +0000403
commit-bot@chromium.org50a30432013-10-24 17:44:27 +0000404 // Listen for messages that a resource has been invalidated and purge cached junk proactively.
405 SkMessageBus<GrResourceInvalidatedMessage>::Inbox fInvalidationInbox;
406 void purgeInvalidated();
407
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000408#ifdef SK_DEBUG
bsalomon@google.com42619d82012-12-03 14:54:59 +0000409 static size_t countBytes(const SkTInternalLList<GrResourceEntry>& list);
robertphillips@google.com2ea0a232012-08-23 11:13:48 +0000410#endif
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000411};
412
413///////////////////////////////////////////////////////////////////////////////
414
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000415#ifdef SK_DEBUG
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000416 class GrAutoResourceCacheValidate {
417 public:
418 GrAutoResourceCacheValidate(GrResourceCache* cache) : fCache(cache) {
419 cache->validate();
420 }
421 ~GrAutoResourceCacheValidate() {
422 fCache->validate();
423 }
424 private:
425 GrResourceCache* fCache;
426 };
427#else
428 class GrAutoResourceCacheValidate {
429 public:
430 GrAutoResourceCacheValidate(GrResourceCache*) {}
431 };
432#endif
433
434#endif