blob: 41c6b516b97a476dd4c5b43281eae1d392d605f4 [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"
commit-bot@chromium.orgbd58feb2014-01-17 17:56:21 +000016#include "GrTMultiMap.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:
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000026 static GrCacheID::Domain ScratchDomain() {
27 static const GrCacheID::Domain gDomain = GrCacheID::GenerateDomain();
28 return gDomain;
bsalomon@google.com50398bf2011-07-26 20:45:30 +000029 }
30
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000031 /** Uniquely identifies the GrResource subclass in the key to avoid collisions
32 across resource types. */
33 typedef uint8_t ResourceType;
34
35 /** Flags set by the GrResource subclass. */
36 typedef uint8_t ResourceFlags;
37
38 /** Generate a unique ResourceType */
39 static ResourceType GenerateResourceType();
40
41 /** Creates a key for resource */
42 GrResourceKey(const GrCacheID& id, ResourceType type, ResourceFlags flags) {
43 this->init(id.getDomain(), id.getKey(), type, flags);
44 };
bsalomon@google.com50398bf2011-07-26 20:45:30 +000045
46 GrResourceKey(const GrResourceKey& src) {
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000047 fKey = src.fKey;
48 }
49
50 GrResourceKey() {
rmistry@google.comd6bab022013-12-02 13:50:38 +000051 fKey.reset();
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000052 }
53
54 void reset(const GrCacheID& id, ResourceType type, ResourceFlags flags) {
55 this->init(id.getDomain(), id.getKey(), type, flags);
bsalomon@google.com50398bf2011-07-26 20:45:30 +000056 }
57
commit-bot@chromium.orgbd58feb2014-01-17 17:56:21 +000058 uint32_t getHash() const {
59 return fKey.getHash();
bsalomon@google.com50398bf2011-07-26 20:45:30 +000060 }
61
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000062 bool isScratch() const {
63 return ScratchDomain() ==
rmistry@google.comd6bab022013-12-02 13:50:38 +000064 *reinterpret_cast<const GrCacheID::Domain*>(fKey.getData() +
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000065 kCacheIDDomainOffset);
bsalomon@google.com50398bf2011-07-26 20:45:30 +000066 }
67
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000068 ResourceType getResourceType() const {
rmistry@google.comd6bab022013-12-02 13:50:38 +000069 return *reinterpret_cast<const ResourceType*>(fKey.getData() +
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000070 kResourceTypeOffset);
bsalomon@google.com50398bf2011-07-26 20:45:30 +000071 }
72
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000073 ResourceFlags getResourceFlags() const {
rmistry@google.comd6bab022013-12-02 13:50:38 +000074 return *reinterpret_cast<const ResourceFlags*>(fKey.getData() +
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000075 kResourceFlagsOffset);
bsalomon@google.com50398bf2011-07-26 20:45:30 +000076 }
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000077
rmistry@google.comd6bab022013-12-02 13:50:38 +000078 bool operator==(const GrResourceKey& other) const { return fKey == other.fKey; }
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000079
bsalomon@google.com50398bf2011-07-26 20:45:30 +000080private:
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000081 enum {
82 kCacheIDKeyOffset = 0,
83 kCacheIDDomainOffset = kCacheIDKeyOffset + sizeof(GrCacheID::Key),
84 kResourceTypeOffset = kCacheIDDomainOffset + sizeof(GrCacheID::Domain),
85 kResourceFlagsOffset = kResourceTypeOffset + sizeof(ResourceType),
86 kPadOffset = kResourceFlagsOffset + sizeof(ResourceFlags),
87 kKeySize = SkAlign4(kPadOffset),
88 kPadSize = kKeySize - kPadOffset
89 };
bsalomon@google.com50398bf2011-07-26 20:45:30 +000090
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000091 void init(const GrCacheID::Domain domain,
92 const GrCacheID::Key& key,
93 ResourceType type,
94 ResourceFlags flags) {
95 union {
96 uint8_t fKey8[kKeySize];
97 uint32_t fKey32[kKeySize / 4];
98 } keyData;
skia.committer@gmail.com2859eb72012-12-21 02:01:28 +000099
bsalomon@google.com0797c2c2012-12-20 15:13:01 +0000100 uint8_t* k = keyData.fKey8;
101 memcpy(k + kCacheIDKeyOffset, key.fData8, sizeof(GrCacheID::Key));
102 memcpy(k + kCacheIDDomainOffset, &domain, sizeof(GrCacheID::Domain));
103 memcpy(k + kResourceTypeOffset, &type, sizeof(ResourceType));
104 memcpy(k + kResourceFlagsOffset, &flags, sizeof(ResourceFlags));
105 memset(k + kPadOffset, 0, kPadSize);
rmistry@google.comd6bab022013-12-02 13:50:38 +0000106 fKey.setKeyData(keyData.fKey32);
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000107 }
rmistry@google.comd6bab022013-12-02 13:50:38 +0000108 GrBinHashKey<kKeySize> fKey;
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000109};
110
commit-bot@chromium.org50a30432013-10-24 17:44:27 +0000111// The cache listens for these messages to purge junk resources proactively.
112struct GrResourceInvalidatedMessage {
113 GrResourceKey key;
114};
115
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000116///////////////////////////////////////////////////////////////////////////////
117
118class GrResourceEntry {
119public:
120 GrResource* resource() const { return fResource; }
121 const GrResourceKey& key() const { return fKey; }
122
commit-bot@chromium.orgbd58feb2014-01-17 17:56:21 +0000123 static const GrResourceKey& GetKey(const GrResourceEntry& e) { return e.key(); }
124 static uint32_t Hash(const GrResourceKey& key) { return key.getHash(); }
125 static bool Equal(const GrResourceEntry& a, const GrResourceKey& b) {
126 return a.key() == b;
127 }
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000128#ifdef SK_DEBUG
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000129 void validate() const;
130#else
131 void validate() const {}
132#endif
133
134private:
135 GrResourceEntry(const GrResourceKey& key, GrResource* resource);
136 ~GrResourceEntry();
137
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000138 GrResourceKey fKey;
139 GrResource* fResource;
140
commit-bot@chromium.orgbd58feb2014-01-17 17:56:21 +0000141 // Linked list for the LRU ordering.
bsalomon@google.com42619d82012-12-03 14:54:59 +0000142 SK_DECLARE_INTERNAL_LLIST_INTERFACE(GrResourceEntry);
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000143
144 friend class GrResourceCache;
145};
146
147///////////////////////////////////////////////////////////////////////////////
148
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000149/**
150 * Cache of GrResource objects.
151 *
152 * These have a corresponding GrResourceKey, built from 128bits identifying the
commit-bot@chromium.orgbd58feb2014-01-17 17:56:21 +0000153 * resource. Multiple resources can map to same GrResourceKey.
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000154 *
155 * The cache stores the entries in a double-linked list, which is its LRU.
156 * When an entry is "locked" (i.e. given to the caller), it is moved to the
157 * head of the list. If/when we must purge some of the entries, we walk the
158 * list backwards from the tail, since those are the least recently used.
159 *
commit-bot@chromium.orgbd58feb2014-01-17 17:56:21 +0000160 * For fast searches, we maintain a hash map based on the GrResourceKey.
bsalomon@google.com76202b82013-05-10 19:08:22 +0000161 *
162 * It is a goal to make the GrResourceCache the central repository and bookkeeper
163 * of all resources. It should replace the linked list of GrResources that
164 * GrGpu uses to call abandon/release.
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000165 */
166class GrResourceCache {
167public:
bsalomon@google.com07fc0d12012-06-22 15:15:59 +0000168 GrResourceCache(int maxCount, size_t maxBytes);
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000169 ~GrResourceCache();
170
171 /**
bsalomon@google.com07fc0d12012-06-22 15:15:59 +0000172 * Return the current resource cache limits.
173 *
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000174 * @param maxResource If non-null, returns maximum number of resources
bsalomon@google.com07fc0d12012-06-22 15:15:59 +0000175 * that can be held in the cache.
176 * @param maxBytes If non-null, returns maximum number of bytes of
robertphillips@google.come4eaea22013-07-19 16:51:46 +0000177 * gpu memory that can be held in the cache.
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000178 */
bsalomon@google.com07fc0d12012-06-22 15:15:59 +0000179 void getLimits(int* maxResources, size_t* maxBytes) const;
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000180
181 /**
bsalomon@google.com07fc0d12012-06-22 15:15:59 +0000182 * Specify the resource cache limits. If the current cache exceeds either
183 * of these, it will be purged (LRU) to keep the cache within these limits.
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000184 *
bsalomon@google.com07fc0d12012-06-22 15:15:59 +0000185 * @param maxResources The maximum number of resources that can be held in
186 * the cache.
187 * @param maxBytes The maximum number of bytes of resource memory that
188 * can be held in the cache.
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000189 */
robertphillips@google.come4eaea22013-07-19 16:51:46 +0000190 void setLimits(int maxResources, size_t maxResourceBytes);
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000191
192 /**
commit-bot@chromium.orgcae27fe2013-07-10 10:14:35 +0000193 * The callback function used by the cache when it is still over budget
skia.committer@gmail.comde2e4e82013-07-11 07:01:01 +0000194 * after a purge. The passed in 'data' is the same 'data' handed to
commit-bot@chromium.orgcae27fe2013-07-10 10:14:35 +0000195 * setOverbudgetCallback. The callback returns true if some resources
196 * have been freed.
197 */
198 typedef bool (*PFOverbudgetCB)(void* data);
199
200 /**
201 * Set the callback the cache should use when it is still over budget
skia.committer@gmail.comde2e4e82013-07-11 07:01:01 +0000202 * after a purge. The 'data' provided here will be passed back to the
skia.committer@gmail.com1f3c7382013-07-20 07:00:58 +0000203 * callback. Note that the cache will attempt to purge any resources newly
robertphillips@google.come4eaea22013-07-19 16:51:46 +0000204 * freed by the callback.
commit-bot@chromium.orgcae27fe2013-07-10 10:14:35 +0000205 */
206 void setOverbudgetCallback(PFOverbudgetCB overbudgetCB, void* data) {
207 fOverbudgetCB = overbudgetCB;
208 fOverbudgetData = data;
209 }
210
211 /**
twiz@google.com05e70242012-01-27 19:12:00 +0000212 * Returns the number of bytes consumed by cached resources.
213 */
214 size_t getCachedResourceBytes() const { return fEntryBytes; }
215
robertphillips@google.com209a1142012-10-31 12:25:21 +0000216 // For a found or added resource to be completely exclusive to the caller
217 // both the kNoOtherOwners and kHide flags need to be specified
218 enum OwnershipFlags {
219 kNoOtherOwners_OwnershipFlag = 0x1, // found/added resource has no other owners
220 kHide_OwnershipFlag = 0x2 // found/added resource is hidden from future 'find's
221 };
222
twiz@google.com05e70242012-01-27 19:12:00 +0000223 /**
robertphillips@google.coma9b06232012-08-30 11:06:31 +0000224 * Search for an entry with the same Key. If found, return it.
225 * If not found, return null.
skia.committer@gmail.comf3dc1992012-11-01 02:01:27 +0000226 * If ownershipFlags includes kNoOtherOwners and a resource is returned
robertphillips@google.com209a1142012-10-31 12:25:21 +0000227 * then that resource has no other refs to it.
228 * If ownershipFlags includes kHide and a resource is returned then that
229 * resource will not be returned from future 'find' calls until it is
230 * 'freed' (and recycled) or makeNonExclusive is called.
231 * For a resource to be completely exclusive to a caller both kNoOtherOwners
232 * and kHide must be specified.
robertphillips@google.coma9b06232012-08-30 11:06:31 +0000233 */
skia.committer@gmail.comf3dc1992012-11-01 02:01:27 +0000234 GrResource* find(const GrResourceKey& key,
robertphillips@google.com209a1142012-10-31 12:25:21 +0000235 uint32_t ownershipFlags = 0);
robertphillips@google.coma9b06232012-08-30 11:06:31 +0000236
237 /**
skia.committer@gmail.comf3dc1992012-11-01 02:01:27 +0000238 * Add the new resource to the cache (by creating a new cache entry based
239 * on the provided key and resource).
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000240 *
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000241 * Ownership of the resource is transferred to the resource cache,
robertphillips@google.com15c0fea2012-06-22 12:41:43 +0000242 * which will unref() it when it is purged or deleted.
robertphillips@google.com209a1142012-10-31 12:25:21 +0000243 *
244 * If ownershipFlags includes kHide, subsequent calls to 'find' will not
skia.committer@gmail.comf3dc1992012-11-01 02:01:27 +0000245 * return 'resource' until it is 'freed' (and recycled) or makeNonExclusive
robertphillips@google.com209a1142012-10-31 12:25:21 +0000246 * is called.
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000247 */
skia.committer@gmail.comf3dc1992012-11-01 02:01:27 +0000248 void addResource(const GrResourceKey& key,
robertphillips@google.com209a1142012-10-31 12:25:21 +0000249 GrResource* resource,
250 uint32_t ownershipFlags = 0);
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000251
252 /**
bsalomon@google.comfb309512011-11-30 14:13:48 +0000253 * Determines if the cache contains an entry matching a key. If a matching
254 * entry exists but was detached then it will not be found.
255 */
robertphillips@google.come4eaea22013-07-19 16:51:46 +0000256 bool hasKey(const GrResourceKey& key) const { return NULL != fCache.find(key); }
bsalomon@google.comfb309512011-11-30 14:13:48 +0000257
258 /**
robertphillips@google.com521eaf82012-08-22 11:03:19 +0000259 * Hide 'entry' so that future searches will not find it. Such
260 * hidden entries will not be purged. The entry still counts against
261 * the cache's budget and should be made non-exclusive when exclusive access
262 * is no longer needed.
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000263 */
robertphillips@google.com521eaf82012-08-22 11:03:19 +0000264 void makeExclusive(GrResourceEntry* entry);
robertphillips@google.com15c0fea2012-06-22 12:41:43 +0000265
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000266 /**
robertphillips@google.com521eaf82012-08-22 11:03:19 +0000267 * Restore 'entry' so that it can be found by future searches. 'entry'
268 * will also be purgeable (provided its lock count is now 0.)
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000269 */
robertphillips@google.com521eaf82012-08-22 11:03:19 +0000270 void makeNonExclusive(GrResourceEntry* entry);
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000271
272 /**
robertphillips@google.come4eaea22013-07-19 16:51:46 +0000273 * Remove a resource from the cache and delete it!
274 */
275 void deleteResource(GrResourceEntry* entry);
276
277 /**
bsalomon@google.coma2921122012-08-28 12:34:17 +0000278 * Removes every resource in the cache that isn't locked.
279 */
280 void purgeAllUnlocked();
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000281
robertphillips@google.com50a035d2012-09-07 19:44:33 +0000282 /**
283 * Allow cache to purge unused resources to obey resource limitations
robertphillips@google.com9fbcad02012-09-09 14:44:15 +0000284 * Note: this entry point will be hidden (again) once totally ref-driven
robertphillips@google.come4eaea22013-07-19 16:51:46 +0000285 * cache maintenance is implemented. Note that the overbudget callback
286 * will be called if the initial purge doesn't get the cache under
287 * its budget.
robertphillips@google.com41d25322013-07-18 17:12:57 +0000288 *
289 * extraCount and extraBytes are added to the current resource allocation
290 * to make sure enough room is available for future additions (e.g,
291 * 10MB across 10 textures is about to be added).
robertphillips@google.com50a035d2012-09-07 19:44:33 +0000292 */
robertphillips@google.com41d25322013-07-18 17:12:57 +0000293 void purgeAsNeeded(int extraCount = 0, size_t extraBytes = 0);
robertphillips@google.com50a035d2012-09-07 19:44:33 +0000294
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000295#ifdef SK_DEBUG
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000296 void validate() const;
297#else
298 void validate() const {}
299#endif
300
robertphillips@google.com59552022012-08-31 13:07:37 +0000301#if GR_CACHE_STATS
robertphillips@google.com9fbcad02012-09-09 14:44:15 +0000302 void printStats();
robertphillips@google.com59552022012-08-31 13:07:37 +0000303#endif
304
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000305private:
robertphillips@google.com209a1142012-10-31 12:25:21 +0000306 enum BudgetBehaviors {
307 kAccountFor_BudgetBehavior,
308 kIgnore_BudgetBehavior
309 };
310
311 void internalDetach(GrResourceEntry*, BudgetBehaviors behavior = kAccountFor_BudgetBehavior);
312 void attachToHead(GrResourceEntry*, BudgetBehaviors behavior = kAccountFor_BudgetBehavior);
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000313
robertphillips@google.com521eaf82012-08-22 11:03:19 +0000314 void removeInvalidResource(GrResourceEntry* entry);
315
commit-bot@chromium.orgbd58feb2014-01-17 17:56:21 +0000316 GrTMultiMap<GrResourceEntry,
317 GrResourceKey,
318 GrResourceEntry::GetKey,
319 GrResourceEntry::Hash,
320 GrResourceEntry::Equal> fCache;
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000321
bsalomon@google.com42619d82012-12-03 14:54:59 +0000322 // We're an internal doubly linked list
323 typedef SkTInternalLList<GrResourceEntry> EntryList;
robertphillips@google.come4eaea22013-07-19 16:51:46 +0000324 EntryList fList;
robertphillips@google.com521eaf82012-08-22 11:03:19 +0000325
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000326#ifdef SK_DEBUG
robertphillips@google.com521eaf82012-08-22 11:03:19 +0000327 // These objects cannot be returned by a search
robertphillips@google.come4eaea22013-07-19 16:51:46 +0000328 EntryList fExclusiveList;
robertphillips@google.com521eaf82012-08-22 11:03:19 +0000329#endif
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000330
331 // our budget, used in purgeAsNeeded()
robertphillips@google.come4eaea22013-07-19 16:51:46 +0000332 int fMaxCount;
333 size_t fMaxBytes;
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000334
335 // our current stats, related to our budget
robertphillips@google.com59552022012-08-31 13:07:37 +0000336#if GR_CACHE_STATS
robertphillips@google.come4eaea22013-07-19 16:51:46 +0000337 int fHighWaterEntryCount;
338 size_t fHighWaterEntryBytes;
339 int fHighWaterClientDetachedCount;
340 size_t fHighWaterClientDetachedBytes;
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +0000341#endif
342
robertphillips@google.come4eaea22013-07-19 16:51:46 +0000343 int fEntryCount;
344 size_t fEntryBytes;
345 int fClientDetachedCount;
346 size_t fClientDetachedBytes;
robertphillips@google.com386319e2012-06-27 14:59:18 +0000347
bsalomon@google.coma5a1da82011-08-05 14:02:41 +0000348 // prevents recursive purging
commit-bot@chromium.orgcae27fe2013-07-10 10:14:35 +0000349 bool fPurging;
350
351 PFOverbudgetCB fOverbudgetCB;
352 void* fOverbudgetData;
353
robertphillips@google.com41d25322013-07-18 17:12:57 +0000354 void internalPurge(int extraCount, size_t extraBytes);
robertphillips@google.com15c0fea2012-06-22 12:41:43 +0000355
commit-bot@chromium.org50a30432013-10-24 17:44:27 +0000356 // Listen for messages that a resource has been invalidated and purge cached junk proactively.
357 SkMessageBus<GrResourceInvalidatedMessage>::Inbox fInvalidationInbox;
358 void purgeInvalidated();
359
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000360#ifdef SK_DEBUG
bsalomon@google.com42619d82012-12-03 14:54:59 +0000361 static size_t countBytes(const SkTInternalLList<GrResourceEntry>& list);
robertphillips@google.com2ea0a232012-08-23 11:13:48 +0000362#endif
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000363};
364
365///////////////////////////////////////////////////////////////////////////////
366
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000367#ifdef SK_DEBUG
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000368 class GrAutoResourceCacheValidate {
369 public:
370 GrAutoResourceCacheValidate(GrResourceCache* cache) : fCache(cache) {
371 cache->validate();
372 }
373 ~GrAutoResourceCacheValidate() {
374 fCache->validate();
375 }
376 private:
377 GrResourceCache* fCache;
378 };
379#else
380 class GrAutoResourceCacheValidate {
381 public:
382 GrAutoResourceCacheValidate(GrResourceCache*) {}
383 };
384#endif
385
386#endif