blob: 679780aa48572ef357e8adc0c2a0802075498fd0 [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"
16#include "GrTHashCache.h"
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000017#include "GrBinHashKey.h"
bsalomon@google.com42619d82012-12-03 14:54:59 +000018#include "SkTInternalLList.h"
bsalomon@google.com50398bf2011-07-26 20:45:30 +000019
20class GrResource;
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000021class GrResourceEntry;
bsalomon@google.com50398bf2011-07-26 20:45:30 +000022
bsalomon@google.com50398bf2011-07-26 20:45:30 +000023class GrResourceKey {
24public:
25 enum {
26 kHashBits = 7,
27 kHashCount = 1 << kHashBits,
28 kHashMask = kHashCount - 1
29 };
30
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000031 static GrCacheID::Domain ScratchDomain() {
32 static const GrCacheID::Domain gDomain = GrCacheID::GenerateDomain();
33 return gDomain;
bsalomon@google.com50398bf2011-07-26 20:45:30 +000034 }
35
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000036 /** Uniquely identifies the GrResource subclass in the key to avoid collisions
37 across resource types. */
38 typedef uint8_t ResourceType;
39
40 /** Flags set by the GrResource subclass. */
41 typedef uint8_t ResourceFlags;
42
43 /** Generate a unique ResourceType */
44 static ResourceType GenerateResourceType();
45
46 /** Creates a key for resource */
47 GrResourceKey(const GrCacheID& id, ResourceType type, ResourceFlags flags) {
48 this->init(id.getDomain(), id.getKey(), type, flags);
49 };
bsalomon@google.com50398bf2011-07-26 20:45:30 +000050
51 GrResourceKey(const GrResourceKey& src) {
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000052 fKey = src.fKey;
53 }
54
55 GrResourceKey() {
56 fKey.fHashedKey.reset();
57 }
58
59 void reset(const GrCacheID& id, ResourceType type, ResourceFlags flags) {
60 this->init(id.getDomain(), id.getKey(), type, flags);
bsalomon@google.com50398bf2011-07-26 20:45:30 +000061 }
62
63 //!< returns hash value [0..kHashMask] for the key
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000064 int getHash() const {
65 return fKey.fHashedKey.getHash() & kHashMask;
bsalomon@google.com50398bf2011-07-26 20:45:30 +000066 }
67
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000068 bool isScratch() const {
69 return ScratchDomain() ==
70 *reinterpret_cast<const GrCacheID::Domain*>(fKey.fHashedKey.getData() +
71 kCacheIDDomainOffset);
bsalomon@google.com50398bf2011-07-26 20:45:30 +000072 }
73
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000074 ResourceType getResourceType() const {
75 return *reinterpret_cast<const ResourceType*>(fKey.fHashedKey.getData() +
76 kResourceTypeOffset);
bsalomon@google.com50398bf2011-07-26 20:45:30 +000077 }
78
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000079 ResourceFlags getResourceFlags() const {
80 return *reinterpret_cast<const ResourceFlags*>(fKey.fHashedKey.getData() +
81 kResourceFlagsOffset);
bsalomon@google.com50398bf2011-07-26 20:45:30 +000082 }
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000083
84 int compare(const GrResourceKey& other) const {
85 return fKey.fHashedKey.compare(other.fKey.fHashedKey);
86 }
87
88 static bool LT(const GrResourceKey& a, const GrResourceKey& b) {
89 return a.compare(b) < 0;
90 }
91
92 static bool EQ(const GrResourceKey& a, const GrResourceKey& b) {
93 return 0 == a.compare(b);
94 }
95
96 inline static bool LT(const GrResourceEntry& entry, const GrResourceKey& key);
97 inline static bool EQ(const GrResourceEntry& entry, const GrResourceKey& key);
98 inline static bool LT(const GrResourceEntry& a, const GrResourceEntry& b);
99 inline static bool EQ(const GrResourceEntry& a, const GrResourceEntry& b);
100
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000101private:
bsalomon@google.com0797c2c2012-12-20 15:13:01 +0000102 enum {
103 kCacheIDKeyOffset = 0,
104 kCacheIDDomainOffset = kCacheIDKeyOffset + sizeof(GrCacheID::Key),
105 kResourceTypeOffset = kCacheIDDomainOffset + sizeof(GrCacheID::Domain),
106 kResourceFlagsOffset = kResourceTypeOffset + sizeof(ResourceType),
107 kPadOffset = kResourceFlagsOffset + sizeof(ResourceFlags),
108 kKeySize = SkAlign4(kPadOffset),
109 kPadSize = kKeySize - kPadOffset
110 };
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000111
bsalomon@google.com0797c2c2012-12-20 15:13:01 +0000112 void init(const GrCacheID::Domain domain,
113 const GrCacheID::Key& key,
114 ResourceType type,
115 ResourceFlags flags) {
116 union {
117 uint8_t fKey8[kKeySize];
118 uint32_t fKey32[kKeySize / 4];
119 } keyData;
skia.committer@gmail.com2859eb72012-12-21 02:01:28 +0000120
bsalomon@google.com0797c2c2012-12-20 15:13:01 +0000121 uint8_t* k = keyData.fKey8;
122 memcpy(k + kCacheIDKeyOffset, key.fData8, sizeof(GrCacheID::Key));
123 memcpy(k + kCacheIDDomainOffset, &domain, sizeof(GrCacheID::Domain));
124 memcpy(k + kResourceTypeOffset, &type, sizeof(ResourceType));
125 memcpy(k + kResourceFlagsOffset, &flags, sizeof(ResourceFlags));
126 memset(k + kPadOffset, 0, kPadSize);
127 fKey.fHashedKey.setKeyData(keyData.fKey32);
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000128 }
129
bsalomon@google.com0797c2c2012-12-20 15:13:01 +0000130 struct Key;
131 typedef GrTBinHashKey<Key, kKeySize> HashedKey;
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000132
bsalomon@google.com0797c2c2012-12-20 15:13:01 +0000133 struct Key {
134 int compare(const HashedKey& hashedKey) const {
sugoi@google.comff57afc2013-02-25 20:42:44 +0000135 return fHashedKey.compare(hashedKey);
bsalomon@google.com0797c2c2012-12-20 15:13:01 +0000136 }
skia.committer@gmail.com2859eb72012-12-21 02:01:28 +0000137
bsalomon@google.com0797c2c2012-12-20 15:13:01 +0000138 HashedKey fHashedKey;
139 };
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000140
bsalomon@google.com0797c2c2012-12-20 15:13:01 +0000141 Key fKey;
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000142};
143
144///////////////////////////////////////////////////////////////////////////////
145
146class GrResourceEntry {
147public:
148 GrResource* resource() const { return fResource; }
149 const GrResourceKey& key() const { return fKey; }
150
151#if GR_DEBUG
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000152 void validate() const;
153#else
154 void validate() const {}
155#endif
156
157private:
158 GrResourceEntry(const GrResourceKey& key, GrResource* resource);
159 ~GrResourceEntry();
160
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000161 GrResourceKey fKey;
162 GrResource* fResource;
163
bsalomon@google.com42619d82012-12-03 14:54:59 +0000164 // we're a linked list
165 SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrResourceEntry);
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000166
167 friend class GrResourceCache;
robertphillips@google.com521eaf82012-08-22 11:03:19 +0000168 friend class GrDLinkedList;
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000169};
170
bsalomon@google.com0797c2c2012-12-20 15:13:01 +0000171bool GrResourceKey::LT(const GrResourceEntry& entry, const GrResourceKey& key) {
172 return LT(entry.key(), key);
173}
174
175bool GrResourceKey::EQ(const GrResourceEntry& entry, const GrResourceKey& key) {
176 return EQ(entry.key(), key);
177}
178
179bool GrResourceKey::LT(const GrResourceEntry& a, const GrResourceEntry& b) {
180 return LT(a.key(), b.key());
181}
182
183bool GrResourceKey::EQ(const GrResourceEntry& a, const GrResourceEntry& b) {
184 return EQ(a.key(), b.key());
185}
186
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000187///////////////////////////////////////////////////////////////////////////////
188
189#include "GrTHashCache.h"
190
191/**
192 * Cache of GrResource objects.
193 *
194 * These have a corresponding GrResourceKey, built from 128bits identifying the
195 * resource.
196 *
197 * The cache stores the entries in a double-linked list, which is its LRU.
198 * When an entry is "locked" (i.e. given to the caller), it is moved to the
199 * head of the list. If/when we must purge some of the entries, we walk the
200 * list backwards from the tail, since those are the least recently used.
201 *
202 * For fast searches, we maintain a sorted array (based on the GrResourceKey)
203 * which we can bsearch. When a new entry is added, it is inserted into this
204 * array.
205 *
206 * For even faster searches, a hash is computed from the Key. If there is
207 * a collision between two keys with the same hash, we fall back on the
208 * bsearch, and update the hash to reflect the most recent Key requested.
bsalomon@google.com76202b82013-05-10 19:08:22 +0000209 *
210 * It is a goal to make the GrResourceCache the central repository and bookkeeper
211 * of all resources. It should replace the linked list of GrResources that
212 * GrGpu uses to call abandon/release.
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000213 */
214class GrResourceCache {
215public:
bsalomon@google.com07fc0d12012-06-22 15:15:59 +0000216 GrResourceCache(int maxCount, size_t maxBytes);
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000217 ~GrResourceCache();
218
219 /**
bsalomon@google.com07fc0d12012-06-22 15:15:59 +0000220 * Return the current resource cache limits.
221 *
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000222 * @param maxResource If non-null, returns maximum number of resources
bsalomon@google.com07fc0d12012-06-22 15:15:59 +0000223 * that can be held in the cache.
224 * @param maxBytes If non-null, returns maximum number of bytes of
robertphillips@google.come4eaea22013-07-19 16:51:46 +0000225 * gpu memory that can be held in the cache.
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000226 */
bsalomon@google.com07fc0d12012-06-22 15:15:59 +0000227 void getLimits(int* maxResources, size_t* maxBytes) const;
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000228
229 /**
bsalomon@google.com07fc0d12012-06-22 15:15:59 +0000230 * Specify the resource cache limits. If the current cache exceeds either
231 * of these, it will be purged (LRU) to keep the cache within these limits.
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000232 *
bsalomon@google.com07fc0d12012-06-22 15:15:59 +0000233 * @param maxResources The maximum number of resources that can be held in
234 * the cache.
235 * @param maxBytes The maximum number of bytes of resource memory that
236 * can be held in the cache.
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000237 */
robertphillips@google.come4eaea22013-07-19 16:51:46 +0000238 void setLimits(int maxResources, size_t maxResourceBytes);
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000239
240 /**
commit-bot@chromium.orgcae27fe2013-07-10 10:14:35 +0000241 * The callback function used by the cache when it is still over budget
skia.committer@gmail.comde2e4e82013-07-11 07:01:01 +0000242 * after a purge. The passed in 'data' is the same 'data' handed to
commit-bot@chromium.orgcae27fe2013-07-10 10:14:35 +0000243 * setOverbudgetCallback. The callback returns true if some resources
244 * have been freed.
245 */
246 typedef bool (*PFOverbudgetCB)(void* data);
247
248 /**
249 * Set the callback the cache should use when it is still over budget
skia.committer@gmail.comde2e4e82013-07-11 07:01:01 +0000250 * after a purge. The 'data' provided here will be passed back to the
robertphillips@google.come4eaea22013-07-19 16:51:46 +0000251 * callback. Note that the cache will attempt to purge any resources newly
252 * freed by the callback.
commit-bot@chromium.orgcae27fe2013-07-10 10:14:35 +0000253 */
254 void setOverbudgetCallback(PFOverbudgetCB overbudgetCB, void* data) {
255 fOverbudgetCB = overbudgetCB;
256 fOverbudgetData = data;
257 }
258
259 /**
twiz@google.com05e70242012-01-27 19:12:00 +0000260 * Returns the number of bytes consumed by cached resources.
261 */
262 size_t getCachedResourceBytes() const { return fEntryBytes; }
263
robertphillips@google.com209a1142012-10-31 12:25:21 +0000264 // For a found or added resource to be completely exclusive to the caller
265 // both the kNoOtherOwners and kHide flags need to be specified
266 enum OwnershipFlags {
267 kNoOtherOwners_OwnershipFlag = 0x1, // found/added resource has no other owners
268 kHide_OwnershipFlag = 0x2 // found/added resource is hidden from future 'find's
269 };
270
twiz@google.com05e70242012-01-27 19:12:00 +0000271 /**
robertphillips@google.coma9b06232012-08-30 11:06:31 +0000272 * Search for an entry with the same Key. If found, return it.
273 * If not found, return null.
skia.committer@gmail.comf3dc1992012-11-01 02:01:27 +0000274 * If ownershipFlags includes kNoOtherOwners and a resource is returned
robertphillips@google.com209a1142012-10-31 12:25:21 +0000275 * then that resource has no other refs to it.
276 * If ownershipFlags includes kHide and a resource is returned then that
277 * resource will not be returned from future 'find' calls until it is
278 * 'freed' (and recycled) or makeNonExclusive is called.
279 * For a resource to be completely exclusive to a caller both kNoOtherOwners
280 * and kHide must be specified.
robertphillips@google.coma9b06232012-08-30 11:06:31 +0000281 */
skia.committer@gmail.comf3dc1992012-11-01 02:01:27 +0000282 GrResource* find(const GrResourceKey& key,
robertphillips@google.com209a1142012-10-31 12:25:21 +0000283 uint32_t ownershipFlags = 0);
robertphillips@google.coma9b06232012-08-30 11:06:31 +0000284
285 /**
skia.committer@gmail.comf3dc1992012-11-01 02:01:27 +0000286 * Add the new resource to the cache (by creating a new cache entry based
287 * on the provided key and resource).
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000288 *
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000289 * Ownership of the resource is transferred to the resource cache,
robertphillips@google.com15c0fea2012-06-22 12:41:43 +0000290 * which will unref() it when it is purged or deleted.
robertphillips@google.com209a1142012-10-31 12:25:21 +0000291 *
292 * If ownershipFlags includes kHide, subsequent calls to 'find' will not
skia.committer@gmail.comf3dc1992012-11-01 02:01:27 +0000293 * return 'resource' until it is 'freed' (and recycled) or makeNonExclusive
robertphillips@google.com209a1142012-10-31 12:25:21 +0000294 * is called.
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000295 */
skia.committer@gmail.comf3dc1992012-11-01 02:01:27 +0000296 void addResource(const GrResourceKey& key,
robertphillips@google.com209a1142012-10-31 12:25:21 +0000297 GrResource* resource,
298 uint32_t ownershipFlags = 0);
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000299
300 /**
bsalomon@google.comfb309512011-11-30 14:13:48 +0000301 * Determines if the cache contains an entry matching a key. If a matching
302 * entry exists but was detached then it will not be found.
303 */
robertphillips@google.come4eaea22013-07-19 16:51:46 +0000304 bool hasKey(const GrResourceKey& key) const { return NULL != fCache.find(key); }
bsalomon@google.comfb309512011-11-30 14:13:48 +0000305
306 /**
robertphillips@google.com521eaf82012-08-22 11:03:19 +0000307 * Hide 'entry' so that future searches will not find it. Such
308 * hidden entries will not be purged. The entry still counts against
309 * the cache's budget and should be made non-exclusive when exclusive access
310 * is no longer needed.
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000311 */
robertphillips@google.com521eaf82012-08-22 11:03:19 +0000312 void makeExclusive(GrResourceEntry* entry);
robertphillips@google.com15c0fea2012-06-22 12:41:43 +0000313
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000314 /**
robertphillips@google.com521eaf82012-08-22 11:03:19 +0000315 * Restore 'entry' so that it can be found by future searches. 'entry'
316 * will also be purgeable (provided its lock count is now 0.)
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000317 */
robertphillips@google.com521eaf82012-08-22 11:03:19 +0000318 void makeNonExclusive(GrResourceEntry* entry);
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000319
320 /**
robertphillips@google.come4eaea22013-07-19 16:51:46 +0000321 * Remove a resource from the cache and delete it!
322 */
323 void deleteResource(GrResourceEntry* entry);
324
325 /**
bsalomon@google.coma2921122012-08-28 12:34:17 +0000326 * Removes every resource in the cache that isn't locked.
327 */
328 void purgeAllUnlocked();
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000329
robertphillips@google.com50a035d2012-09-07 19:44:33 +0000330 /**
331 * Allow cache to purge unused resources to obey resource limitations
robertphillips@google.com9fbcad02012-09-09 14:44:15 +0000332 * Note: this entry point will be hidden (again) once totally ref-driven
robertphillips@google.come4eaea22013-07-19 16:51:46 +0000333 * cache maintenance is implemented. Note that the overbudget callback
334 * will be called if the initial purge doesn't get the cache under
335 * its budget.
robertphillips@google.com41d25322013-07-18 17:12:57 +0000336 *
337 * extraCount and extraBytes are added to the current resource allocation
338 * to make sure enough room is available for future additions (e.g,
339 * 10MB across 10 textures is about to be added).
robertphillips@google.com50a035d2012-09-07 19:44:33 +0000340 */
robertphillips@google.com41d25322013-07-18 17:12:57 +0000341 void purgeAsNeeded(int extraCount = 0, size_t extraBytes = 0);
robertphillips@google.com50a035d2012-09-07 19:44:33 +0000342
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000343#if GR_DEBUG
344 void validate() const;
345#else
346 void validate() const {}
347#endif
348
robertphillips@google.com59552022012-08-31 13:07:37 +0000349#if GR_CACHE_STATS
robertphillips@google.com9fbcad02012-09-09 14:44:15 +0000350 void printStats();
robertphillips@google.com59552022012-08-31 13:07:37 +0000351#endif
352
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000353private:
robertphillips@google.com209a1142012-10-31 12:25:21 +0000354 enum BudgetBehaviors {
355 kAccountFor_BudgetBehavior,
356 kIgnore_BudgetBehavior
357 };
358
359 void internalDetach(GrResourceEntry*, BudgetBehaviors behavior = kAccountFor_BudgetBehavior);
360 void attachToHead(GrResourceEntry*, BudgetBehaviors behavior = kAccountFor_BudgetBehavior);
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000361
robertphillips@google.com521eaf82012-08-22 11:03:19 +0000362 void removeInvalidResource(GrResourceEntry* entry);
363
bsalomon@google.com0797c2c2012-12-20 15:13:01 +0000364 GrTHashTable<GrResourceEntry, GrResourceKey, 8> fCache;
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000365
bsalomon@google.com42619d82012-12-03 14:54:59 +0000366 // We're an internal doubly linked list
367 typedef SkTInternalLList<GrResourceEntry> EntryList;
robertphillips@google.come4eaea22013-07-19 16:51:46 +0000368 EntryList fList;
robertphillips@google.com521eaf82012-08-22 11:03:19 +0000369
370#if GR_DEBUG
371 // These objects cannot be returned by a search
robertphillips@google.come4eaea22013-07-19 16:51:46 +0000372 EntryList fExclusiveList;
robertphillips@google.com521eaf82012-08-22 11:03:19 +0000373#endif
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000374
375 // our budget, used in purgeAsNeeded()
robertphillips@google.come4eaea22013-07-19 16:51:46 +0000376 int fMaxCount;
377 size_t fMaxBytes;
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000378
379 // our current stats, related to our budget
robertphillips@google.com59552022012-08-31 13:07:37 +0000380#if GR_CACHE_STATS
robertphillips@google.come4eaea22013-07-19 16:51:46 +0000381 int fHighWaterEntryCount;
382 size_t fHighWaterEntryBytes;
383 int fHighWaterClientDetachedCount;
384 size_t fHighWaterClientDetachedBytes;
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +0000385#endif
386
robertphillips@google.come4eaea22013-07-19 16:51:46 +0000387 int fEntryCount;
388 size_t fEntryBytes;
389 int fClientDetachedCount;
390 size_t fClientDetachedBytes;
robertphillips@google.com386319e2012-06-27 14:59:18 +0000391
bsalomon@google.coma5a1da82011-08-05 14:02:41 +0000392 // prevents recursive purging
commit-bot@chromium.orgcae27fe2013-07-10 10:14:35 +0000393 bool fPurging;
394
395 PFOverbudgetCB fOverbudgetCB;
396 void* fOverbudgetData;
397
robertphillips@google.com41d25322013-07-18 17:12:57 +0000398 void internalPurge(int extraCount, size_t extraBytes);
robertphillips@google.com15c0fea2012-06-22 12:41:43 +0000399
robertphillips@google.com2ea0a232012-08-23 11:13:48 +0000400#if GR_DEBUG
bsalomon@google.com42619d82012-12-03 14:54:59 +0000401 static size_t countBytes(const SkTInternalLList<GrResourceEntry>& list);
robertphillips@google.com2ea0a232012-08-23 11:13:48 +0000402#endif
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000403};
404
405///////////////////////////////////////////////////////////////////////////////
406
407#if GR_DEBUG
408 class GrAutoResourceCacheValidate {
409 public:
410 GrAutoResourceCacheValidate(GrResourceCache* cache) : fCache(cache) {
411 cache->validate();
412 }
413 ~GrAutoResourceCacheValidate() {
414 fCache->validate();
415 }
416 private:
417 GrResourceCache* fCache;
418 };
419#else
420 class GrAutoResourceCacheValidate {
421 public:
422 GrAutoResourceCacheValidate(GrResourceCache*) {}
423 };
424#endif
425
426#endif