blob: ca30732bbc176fed947b048779022412004fcc94 [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() {
rmistry@google.comd6bab022013-12-02 13:50:38 +000057 fKey.reset();
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000058 }
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 {
rmistry@google.comd6bab022013-12-02 13:50:38 +000066 return fKey.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() ==
rmistry@google.comd6bab022013-12-02 13:50:38 +000071 *reinterpret_cast<const GrCacheID::Domain*>(fKey.getData() +
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000072 kCacheIDDomainOffset);
bsalomon@google.com50398bf2011-07-26 20:45:30 +000073 }
74
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000075 ResourceType getResourceType() const {
rmistry@google.comd6bab022013-12-02 13:50:38 +000076 return *reinterpret_cast<const ResourceType*>(fKey.getData() +
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000077 kResourceTypeOffset);
bsalomon@google.com50398bf2011-07-26 20:45:30 +000078 }
79
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000080 ResourceFlags getResourceFlags() const {
rmistry@google.comd6bab022013-12-02 13:50:38 +000081 return *reinterpret_cast<const ResourceFlags*>(fKey.getData() +
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000082 kResourceFlagsOffset);
bsalomon@google.com50398bf2011-07-26 20:45:30 +000083 }
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000084
rmistry@google.comd6bab022013-12-02 13:50:38 +000085 bool operator==(const GrResourceKey& other) const { return fKey == other.fKey; }
86 bool operator<(const GrResourceKey& other) const { return fKey < other.fKey; }
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000087
rmistry@google.comd6bab022013-12-02 13:50:38 +000088 static bool LessThan(const GrResourceEntry& entry, const GrResourceKey& key);
89 static bool Equals(const GrResourceEntry& entry, const GrResourceKey& key);
90#ifdef SK_DEBUG
91 static bool LessThan(const GrResourceEntry& a, const GrResourceEntry& b);
92 static bool Equals(const GrResourceEntry& a, const GrResourceEntry& b);
93#endif
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000094
bsalomon@google.com50398bf2011-07-26 20:45:30 +000095private:
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000096 enum {
97 kCacheIDKeyOffset = 0,
98 kCacheIDDomainOffset = kCacheIDKeyOffset + sizeof(GrCacheID::Key),
99 kResourceTypeOffset = kCacheIDDomainOffset + sizeof(GrCacheID::Domain),
100 kResourceFlagsOffset = kResourceTypeOffset + sizeof(ResourceType),
101 kPadOffset = kResourceFlagsOffset + sizeof(ResourceFlags),
102 kKeySize = SkAlign4(kPadOffset),
103 kPadSize = kKeySize - kPadOffset
104 };
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000105
bsalomon@google.com0797c2c2012-12-20 15:13:01 +0000106 void init(const GrCacheID::Domain domain,
107 const GrCacheID::Key& key,
108 ResourceType type,
109 ResourceFlags flags) {
110 union {
111 uint8_t fKey8[kKeySize];
112 uint32_t fKey32[kKeySize / 4];
113 } keyData;
skia.committer@gmail.com2859eb72012-12-21 02:01:28 +0000114
bsalomon@google.com0797c2c2012-12-20 15:13:01 +0000115 uint8_t* k = keyData.fKey8;
116 memcpy(k + kCacheIDKeyOffset, key.fData8, sizeof(GrCacheID::Key));
117 memcpy(k + kCacheIDDomainOffset, &domain, sizeof(GrCacheID::Domain));
118 memcpy(k + kResourceTypeOffset, &type, sizeof(ResourceType));
119 memcpy(k + kResourceFlagsOffset, &flags, sizeof(ResourceFlags));
120 memset(k + kPadOffset, 0, kPadSize);
rmistry@google.comd6bab022013-12-02 13:50:38 +0000121 fKey.setKeyData(keyData.fKey32);
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000122 }
rmistry@google.comd6bab022013-12-02 13:50:38 +0000123 GrBinHashKey<kKeySize> fKey;
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000124};
125
commit-bot@chromium.org50a30432013-10-24 17:44:27 +0000126// The cache listens for these messages to purge junk resources proactively.
127struct GrResourceInvalidatedMessage {
128 GrResourceKey key;
129};
130
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000131///////////////////////////////////////////////////////////////////////////////
132
133class GrResourceEntry {
134public:
135 GrResource* resource() const { return fResource; }
136 const GrResourceKey& key() const { return fKey; }
137
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000138#ifdef SK_DEBUG
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000139 void validate() const;
140#else
141 void validate() const {}
142#endif
143
144private:
145 GrResourceEntry(const GrResourceKey& key, GrResource* resource);
146 ~GrResourceEntry();
147
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000148 GrResourceKey fKey;
149 GrResource* fResource;
150
bsalomon@google.com42619d82012-12-03 14:54:59 +0000151 // we're a linked list
152 SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrResourceEntry);
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000153
154 friend class GrResourceCache;
robertphillips@google.com521eaf82012-08-22 11:03:19 +0000155 friend class GrDLinkedList;
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000156};
157
rmistry@google.comd6bab022013-12-02 13:50:38 +0000158inline bool GrResourceKey::LessThan(const GrResourceEntry& entry, const GrResourceKey& key) {
159 return entry.key() < key;
bsalomon@google.com0797c2c2012-12-20 15:13:01 +0000160}
161
rmistry@google.comd6bab022013-12-02 13:50:38 +0000162inline bool GrResourceKey::Equals(const GrResourceEntry& entry, const GrResourceKey& key) {
163 return entry.key() == key;
bsalomon@google.com0797c2c2012-12-20 15:13:01 +0000164}
165
rmistry@google.comd6bab022013-12-02 13:50:38 +0000166#ifdef SK_DEBUG
167inline bool GrResourceKey::LessThan(const GrResourceEntry& a, const GrResourceEntry& b) {
168 return a.key() < b.key();
bsalomon@google.com0797c2c2012-12-20 15:13:01 +0000169}
170
rmistry@google.comd6bab022013-12-02 13:50:38 +0000171inline bool GrResourceKey::Equals(const GrResourceEntry& a, const GrResourceEntry& b) {
172 return a.key() == b.key();
bsalomon@google.com0797c2c2012-12-20 15:13:01 +0000173}
rmistry@google.comd6bab022013-12-02 13:50:38 +0000174#endif
bsalomon@google.com0797c2c2012-12-20 15:13:01 +0000175
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000176///////////////////////////////////////////////////////////////////////////////
177
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000178/**
179 * Cache of GrResource objects.
180 *
181 * These have a corresponding GrResourceKey, built from 128bits identifying the
182 * resource.
183 *
184 * The cache stores the entries in a double-linked list, which is its LRU.
185 * When an entry is "locked" (i.e. given to the caller), it is moved to the
186 * head of the list. If/when we must purge some of the entries, we walk the
187 * list backwards from the tail, since those are the least recently used.
188 *
189 * For fast searches, we maintain a sorted array (based on the GrResourceKey)
190 * which we can bsearch. When a new entry is added, it is inserted into this
191 * array.
192 *
193 * For even faster searches, a hash is computed from the Key. If there is
194 * a collision between two keys with the same hash, we fall back on the
195 * bsearch, and update the hash to reflect the most recent Key requested.
bsalomon@google.com76202b82013-05-10 19:08:22 +0000196 *
197 * It is a goal to make the GrResourceCache the central repository and bookkeeper
198 * of all resources. It should replace the linked list of GrResources that
199 * GrGpu uses to call abandon/release.
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000200 */
201class GrResourceCache {
202public:
bsalomon@google.com07fc0d12012-06-22 15:15:59 +0000203 GrResourceCache(int maxCount, size_t maxBytes);
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000204 ~GrResourceCache();
205
206 /**
bsalomon@google.com07fc0d12012-06-22 15:15:59 +0000207 * Return the current resource cache limits.
208 *
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000209 * @param maxResource If non-null, returns maximum number of resources
bsalomon@google.com07fc0d12012-06-22 15:15:59 +0000210 * that can be held in the cache.
211 * @param maxBytes If non-null, returns maximum number of bytes of
robertphillips@google.come4eaea22013-07-19 16:51:46 +0000212 * gpu memory that can be held in the cache.
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000213 */
bsalomon@google.com07fc0d12012-06-22 15:15:59 +0000214 void getLimits(int* maxResources, size_t* maxBytes) const;
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000215
216 /**
bsalomon@google.com07fc0d12012-06-22 15:15:59 +0000217 * Specify the resource cache limits. If the current cache exceeds either
218 * of these, it will be purged (LRU) to keep the cache within these limits.
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000219 *
bsalomon@google.com07fc0d12012-06-22 15:15:59 +0000220 * @param maxResources The maximum number of resources that can be held in
221 * the cache.
222 * @param maxBytes The maximum number of bytes of resource memory that
223 * can be held in the cache.
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000224 */
robertphillips@google.come4eaea22013-07-19 16:51:46 +0000225 void setLimits(int maxResources, size_t maxResourceBytes);
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000226
227 /**
commit-bot@chromium.orgcae27fe2013-07-10 10:14:35 +0000228 * The callback function used by the cache when it is still over budget
skia.committer@gmail.comde2e4e82013-07-11 07:01:01 +0000229 * after a purge. The passed in 'data' is the same 'data' handed to
commit-bot@chromium.orgcae27fe2013-07-10 10:14:35 +0000230 * setOverbudgetCallback. The callback returns true if some resources
231 * have been freed.
232 */
233 typedef bool (*PFOverbudgetCB)(void* data);
234
235 /**
236 * Set the callback the cache should use when it is still over budget
skia.committer@gmail.comde2e4e82013-07-11 07:01:01 +0000237 * after a purge. The 'data' provided here will be passed back to the
skia.committer@gmail.com1f3c7382013-07-20 07:00:58 +0000238 * callback. Note that the cache will attempt to purge any resources newly
robertphillips@google.come4eaea22013-07-19 16:51:46 +0000239 * freed by the callback.
commit-bot@chromium.orgcae27fe2013-07-10 10:14:35 +0000240 */
241 void setOverbudgetCallback(PFOverbudgetCB overbudgetCB, void* data) {
242 fOverbudgetCB = overbudgetCB;
243 fOverbudgetData = data;
244 }
245
246 /**
twiz@google.com05e70242012-01-27 19:12:00 +0000247 * Returns the number of bytes consumed by cached resources.
248 */
249 size_t getCachedResourceBytes() const { return fEntryBytes; }
250
robertphillips@google.com209a1142012-10-31 12:25:21 +0000251 // For a found or added resource to be completely exclusive to the caller
252 // both the kNoOtherOwners and kHide flags need to be specified
253 enum OwnershipFlags {
254 kNoOtherOwners_OwnershipFlag = 0x1, // found/added resource has no other owners
255 kHide_OwnershipFlag = 0x2 // found/added resource is hidden from future 'find's
256 };
257
twiz@google.com05e70242012-01-27 19:12:00 +0000258 /**
robertphillips@google.coma9b06232012-08-30 11:06:31 +0000259 * Search for an entry with the same Key. If found, return it.
260 * If not found, return null.
skia.committer@gmail.comf3dc1992012-11-01 02:01:27 +0000261 * If ownershipFlags includes kNoOtherOwners and a resource is returned
robertphillips@google.com209a1142012-10-31 12:25:21 +0000262 * then that resource has no other refs to it.
263 * If ownershipFlags includes kHide and a resource is returned then that
264 * resource will not be returned from future 'find' calls until it is
265 * 'freed' (and recycled) or makeNonExclusive is called.
266 * For a resource to be completely exclusive to a caller both kNoOtherOwners
267 * and kHide must be specified.
robertphillips@google.coma9b06232012-08-30 11:06:31 +0000268 */
skia.committer@gmail.comf3dc1992012-11-01 02:01:27 +0000269 GrResource* find(const GrResourceKey& key,
robertphillips@google.com209a1142012-10-31 12:25:21 +0000270 uint32_t ownershipFlags = 0);
robertphillips@google.coma9b06232012-08-30 11:06:31 +0000271
272 /**
skia.committer@gmail.comf3dc1992012-11-01 02:01:27 +0000273 * Add the new resource to the cache (by creating a new cache entry based
274 * on the provided key and resource).
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000275 *
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000276 * Ownership of the resource is transferred to the resource cache,
robertphillips@google.com15c0fea2012-06-22 12:41:43 +0000277 * which will unref() it when it is purged or deleted.
robertphillips@google.com209a1142012-10-31 12:25:21 +0000278 *
279 * If ownershipFlags includes kHide, subsequent calls to 'find' will not
skia.committer@gmail.comf3dc1992012-11-01 02:01:27 +0000280 * return 'resource' until it is 'freed' (and recycled) or makeNonExclusive
robertphillips@google.com209a1142012-10-31 12:25:21 +0000281 * is called.
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000282 */
skia.committer@gmail.comf3dc1992012-11-01 02:01:27 +0000283 void addResource(const GrResourceKey& key,
robertphillips@google.com209a1142012-10-31 12:25:21 +0000284 GrResource* resource,
285 uint32_t ownershipFlags = 0);
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000286
287 /**
bsalomon@google.comfb309512011-11-30 14:13:48 +0000288 * Determines if the cache contains an entry matching a key. If a matching
289 * entry exists but was detached then it will not be found.
290 */
robertphillips@google.come4eaea22013-07-19 16:51:46 +0000291 bool hasKey(const GrResourceKey& key) const { return NULL != fCache.find(key); }
bsalomon@google.comfb309512011-11-30 14:13:48 +0000292
293 /**
robertphillips@google.com521eaf82012-08-22 11:03:19 +0000294 * Hide 'entry' so that future searches will not find it. Such
295 * hidden entries will not be purged. The entry still counts against
296 * the cache's budget and should be made non-exclusive when exclusive access
297 * is no longer needed.
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000298 */
robertphillips@google.com521eaf82012-08-22 11:03:19 +0000299 void makeExclusive(GrResourceEntry* entry);
robertphillips@google.com15c0fea2012-06-22 12:41:43 +0000300
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000301 /**
robertphillips@google.com521eaf82012-08-22 11:03:19 +0000302 * Restore 'entry' so that it can be found by future searches. 'entry'
303 * will also be purgeable (provided its lock count is now 0.)
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000304 */
robertphillips@google.com521eaf82012-08-22 11:03:19 +0000305 void makeNonExclusive(GrResourceEntry* entry);
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000306
307 /**
robertphillips@google.come4eaea22013-07-19 16:51:46 +0000308 * Remove a resource from the cache and delete it!
309 */
310 void deleteResource(GrResourceEntry* entry);
311
312 /**
bsalomon@google.coma2921122012-08-28 12:34:17 +0000313 * Removes every resource in the cache that isn't locked.
314 */
315 void purgeAllUnlocked();
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000316
robertphillips@google.com50a035d2012-09-07 19:44:33 +0000317 /**
318 * Allow cache to purge unused resources to obey resource limitations
robertphillips@google.com9fbcad02012-09-09 14:44:15 +0000319 * Note: this entry point will be hidden (again) once totally ref-driven
robertphillips@google.come4eaea22013-07-19 16:51:46 +0000320 * cache maintenance is implemented. Note that the overbudget callback
321 * will be called if the initial purge doesn't get the cache under
322 * its budget.
robertphillips@google.com41d25322013-07-18 17:12:57 +0000323 *
324 * extraCount and extraBytes are added to the current resource allocation
325 * to make sure enough room is available for future additions (e.g,
326 * 10MB across 10 textures is about to be added).
robertphillips@google.com50a035d2012-09-07 19:44:33 +0000327 */
robertphillips@google.com41d25322013-07-18 17:12:57 +0000328 void purgeAsNeeded(int extraCount = 0, size_t extraBytes = 0);
robertphillips@google.com50a035d2012-09-07 19:44:33 +0000329
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000330#ifdef SK_DEBUG
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000331 void validate() const;
332#else
333 void validate() const {}
334#endif
335
robertphillips@google.com59552022012-08-31 13:07:37 +0000336#if GR_CACHE_STATS
robertphillips@google.com9fbcad02012-09-09 14:44:15 +0000337 void printStats();
robertphillips@google.com59552022012-08-31 13:07:37 +0000338#endif
339
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000340private:
robertphillips@google.com209a1142012-10-31 12:25:21 +0000341 enum BudgetBehaviors {
342 kAccountFor_BudgetBehavior,
343 kIgnore_BudgetBehavior
344 };
345
346 void internalDetach(GrResourceEntry*, BudgetBehaviors behavior = kAccountFor_BudgetBehavior);
347 void attachToHead(GrResourceEntry*, BudgetBehaviors behavior = kAccountFor_BudgetBehavior);
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000348
robertphillips@google.com521eaf82012-08-22 11:03:19 +0000349 void removeInvalidResource(GrResourceEntry* entry);
350
bsalomon@google.com0797c2c2012-12-20 15:13:01 +0000351 GrTHashTable<GrResourceEntry, GrResourceKey, 8> fCache;
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000352
bsalomon@google.com42619d82012-12-03 14:54:59 +0000353 // We're an internal doubly linked list
354 typedef SkTInternalLList<GrResourceEntry> EntryList;
robertphillips@google.come4eaea22013-07-19 16:51:46 +0000355 EntryList fList;
robertphillips@google.com521eaf82012-08-22 11:03:19 +0000356
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000357#ifdef SK_DEBUG
robertphillips@google.com521eaf82012-08-22 11:03:19 +0000358 // These objects cannot be returned by a search
robertphillips@google.come4eaea22013-07-19 16:51:46 +0000359 EntryList fExclusiveList;
robertphillips@google.com521eaf82012-08-22 11:03:19 +0000360#endif
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000361
362 // our budget, used in purgeAsNeeded()
robertphillips@google.come4eaea22013-07-19 16:51:46 +0000363 int fMaxCount;
364 size_t fMaxBytes;
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000365
366 // our current stats, related to our budget
robertphillips@google.com59552022012-08-31 13:07:37 +0000367#if GR_CACHE_STATS
robertphillips@google.come4eaea22013-07-19 16:51:46 +0000368 int fHighWaterEntryCount;
369 size_t fHighWaterEntryBytes;
370 int fHighWaterClientDetachedCount;
371 size_t fHighWaterClientDetachedBytes;
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +0000372#endif
373
robertphillips@google.come4eaea22013-07-19 16:51:46 +0000374 int fEntryCount;
375 size_t fEntryBytes;
376 int fClientDetachedCount;
377 size_t fClientDetachedBytes;
robertphillips@google.com386319e2012-06-27 14:59:18 +0000378
bsalomon@google.coma5a1da82011-08-05 14:02:41 +0000379 // prevents recursive purging
commit-bot@chromium.orgcae27fe2013-07-10 10:14:35 +0000380 bool fPurging;
381
382 PFOverbudgetCB fOverbudgetCB;
383 void* fOverbudgetData;
384
robertphillips@google.com41d25322013-07-18 17:12:57 +0000385 void internalPurge(int extraCount, size_t extraBytes);
robertphillips@google.com15c0fea2012-06-22 12:41:43 +0000386
commit-bot@chromium.org50a30432013-10-24 17:44:27 +0000387 // Listen for messages that a resource has been invalidated and purge cached junk proactively.
388 SkMessageBus<GrResourceInvalidatedMessage>::Inbox fInvalidationInbox;
389 void purgeInvalidated();
390
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000391#ifdef SK_DEBUG
bsalomon@google.com42619d82012-12-03 14:54:59 +0000392 static size_t countBytes(const SkTInternalLList<GrResourceEntry>& list);
robertphillips@google.com2ea0a232012-08-23 11:13:48 +0000393#endif
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000394};
395
396///////////////////////////////////////////////////////////////////////////////
397
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000398#ifdef SK_DEBUG
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000399 class GrAutoResourceCacheValidate {
400 public:
401 GrAutoResourceCacheValidate(GrResourceCache* cache) : fCache(cache) {
402 cache->validate();
403 }
404 ~GrAutoResourceCacheValidate() {
405 fCache->validate();
406 }
407 private:
408 GrResourceCache* fCache;
409 };
410#else
411 class GrAutoResourceCacheValidate {
412 public:
413 GrAutoResourceCacheValidate(GrResourceCache*) {}
414 };
415#endif
416
417#endif