epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * 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.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 10 | |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 11 | #ifndef GrResourceCache_DEFINED |
| 12 | #define GrResourceCache_DEFINED |
| 13 | |
robertphillips@google.com | 5955202 | 2012-08-31 13:07:37 +0000 | [diff] [blame] | 14 | #include "GrConfig.h" |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 15 | #include "GrTypes.h" |
| 16 | #include "GrTHashCache.h" |
robertphillips@google.com | 2ea0a23 | 2012-08-23 11:13:48 +0000 | [diff] [blame] | 17 | #include "SkTDLinkedList.h" |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 18 | |
| 19 | class GrResource; |
| 20 | |
| 21 | // return true if a<b, or false if b<a |
| 22 | // |
| 23 | #define RET_IF_LT_OR_GT(a, b) \ |
| 24 | do { \ |
| 25 | if ((a) < (b)) { \ |
| 26 | return true; \ |
| 27 | } \ |
| 28 | if ((b) < (a)) { \ |
| 29 | return false; \ |
| 30 | } \ |
| 31 | } while (0) |
| 32 | |
| 33 | /** |
| 34 | * Helper class for GrResourceCache, the Key is used to identify src data for |
| 35 | * a resource. It is identified by 2 32bit data fields which can hold any |
| 36 | * data (uninterpreted by the cache) and a width/height. |
| 37 | */ |
| 38 | class GrResourceKey { |
| 39 | public: |
| 40 | enum { |
| 41 | kHashBits = 7, |
| 42 | kHashCount = 1 << kHashBits, |
| 43 | kHashMask = kHashCount - 1 |
| 44 | }; |
| 45 | |
| 46 | GrResourceKey(uint32_t p0, uint32_t p1, uint32_t p2, uint32_t p3) { |
| 47 | fP[0] = p0; |
| 48 | fP[1] = p1; |
| 49 | fP[2] = p2; |
| 50 | fP[3] = p3; |
| 51 | this->computeHashIndex(); |
| 52 | } |
| 53 | |
| 54 | GrResourceKey(uint32_t v[4]) { |
| 55 | memcpy(fP, v, 4 * sizeof(uint32_t)); |
| 56 | this->computeHashIndex(); |
| 57 | } |
| 58 | |
| 59 | GrResourceKey(const GrResourceKey& src) { |
| 60 | memcpy(fP, src.fP, 4 * sizeof(uint32_t)); |
| 61 | #if GR_DEBUG |
| 62 | this->computeHashIndex(); |
| 63 | GrAssert(fHashIndex == src.fHashIndex); |
| 64 | #endif |
| 65 | fHashIndex = src.fHashIndex; |
| 66 | } |
| 67 | |
| 68 | //!< returns hash value [0..kHashMask] for the key |
| 69 | int hashIndex() const { return fHashIndex; } |
| 70 | |
| 71 | friend bool operator==(const GrResourceKey& a, const GrResourceKey& b) { |
| 72 | GR_DEBUGASSERT(-1 != a.fHashIndex && -1 != b.fHashIndex); |
| 73 | return 0 == memcmp(a.fP, b.fP, 4 * sizeof(uint32_t)); |
| 74 | } |
| 75 | |
| 76 | friend bool operator!=(const GrResourceKey& a, const GrResourceKey& b) { |
| 77 | GR_DEBUGASSERT(-1 != a.fHashIndex && -1 != b.fHashIndex); |
| 78 | return !(a == b); |
| 79 | } |
| 80 | |
| 81 | friend bool operator<(const GrResourceKey& a, const GrResourceKey& b) { |
| 82 | RET_IF_LT_OR_GT(a.fP[0], b.fP[0]); |
| 83 | RET_IF_LT_OR_GT(a.fP[1], b.fP[1]); |
| 84 | RET_IF_LT_OR_GT(a.fP[2], b.fP[2]); |
| 85 | return a.fP[3] < b.fP[3]; |
| 86 | } |
| 87 | |
| 88 | uint32_t getValue32(int i) const { |
| 89 | GrAssert(i >=0 && i < 4); |
| 90 | return fP[i]; |
| 91 | } |
| 92 | private: |
| 93 | |
| 94 | static uint32_t rol(uint32_t x) { |
| 95 | return (x >> 24) | (x << 8); |
| 96 | } |
| 97 | static uint32_t ror(uint32_t x) { |
| 98 | return (x >> 8) | (x << 24); |
| 99 | } |
| 100 | static uint32_t rohalf(uint32_t x) { |
| 101 | return (x >> 16) | (x << 16); |
| 102 | } |
| 103 | |
| 104 | void computeHashIndex() { |
| 105 | uint32_t hash = fP[0] ^ rol(fP[1]) ^ ror(fP[2]) ^ rohalf(fP[3]); |
| 106 | // this way to mix and reduce hash to its index may have to change |
| 107 | // depending on how many bits we allocate to the index |
| 108 | hash ^= hash >> 16; |
| 109 | hash ^= hash >> 8; |
| 110 | fHashIndex = hash & kHashMask; |
| 111 | } |
| 112 | |
| 113 | uint32_t fP[4]; |
| 114 | |
| 115 | // this is computed from the fP... fields |
| 116 | int fHashIndex; |
| 117 | |
| 118 | friend class GrContext; |
| 119 | }; |
| 120 | |
robertphillips@google.com | a9b0623 | 2012-08-30 11:06:31 +0000 | [diff] [blame] | 121 | |
| 122 | class GrCacheKey { |
| 123 | public: |
| 124 | GrCacheKey(const GrTextureDesc& desc, const GrResourceKey& key) |
| 125 | : fDesc(desc) |
| 126 | , fKey(key) { |
| 127 | } |
| 128 | |
| 129 | void set(const GrTextureDesc& desc, const GrResourceKey& key) { |
| 130 | fDesc = desc; |
| 131 | fKey = key; |
| 132 | } |
| 133 | |
| 134 | const GrTextureDesc& desc() const { return fDesc; } |
| 135 | const GrResourceKey& key() const { return fKey; } |
| 136 | |
| 137 | protected: |
| 138 | GrTextureDesc fDesc; |
| 139 | GrResourceKey fKey; |
| 140 | }; |
| 141 | |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 142 | /////////////////////////////////////////////////////////////////////////////// |
| 143 | |
| 144 | class GrResourceEntry { |
| 145 | public: |
| 146 | GrResource* resource() const { return fResource; } |
| 147 | const GrResourceKey& key() const { return fKey; } |
| 148 | |
| 149 | #if GR_DEBUG |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 150 | void validate() const; |
| 151 | #else |
| 152 | void validate() const {} |
| 153 | #endif |
| 154 | |
| 155 | private: |
| 156 | GrResourceEntry(const GrResourceKey& key, GrResource* resource); |
| 157 | ~GrResourceEntry(); |
| 158 | |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 159 | GrResourceKey fKey; |
| 160 | GrResource* fResource; |
| 161 | |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 162 | // we're a dlinklist |
robertphillips@google.com | 2ea0a23 | 2012-08-23 11:13:48 +0000 | [diff] [blame] | 163 | SK_DEFINE_DLINKEDLIST_INTERFACE(GrResourceEntry); |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 164 | |
| 165 | friend class GrResourceCache; |
robertphillips@google.com | 521eaf8 | 2012-08-22 11:03:19 +0000 | [diff] [blame] | 166 | friend class GrDLinkedList; |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 167 | }; |
| 168 | |
| 169 | /////////////////////////////////////////////////////////////////////////////// |
| 170 | |
| 171 | #include "GrTHashCache.h" |
| 172 | |
| 173 | /** |
| 174 | * Cache of GrResource objects. |
| 175 | * |
| 176 | * These have a corresponding GrResourceKey, built from 128bits identifying the |
| 177 | * resource. |
| 178 | * |
| 179 | * The cache stores the entries in a double-linked list, which is its LRU. |
| 180 | * When an entry is "locked" (i.e. given to the caller), it is moved to the |
| 181 | * head of the list. If/when we must purge some of the entries, we walk the |
| 182 | * list backwards from the tail, since those are the least recently used. |
| 183 | * |
| 184 | * For fast searches, we maintain a sorted array (based on the GrResourceKey) |
| 185 | * which we can bsearch. When a new entry is added, it is inserted into this |
| 186 | * array. |
| 187 | * |
| 188 | * For even faster searches, a hash is computed from the Key. If there is |
| 189 | * a collision between two keys with the same hash, we fall back on the |
| 190 | * bsearch, and update the hash to reflect the most recent Key requested. |
| 191 | */ |
| 192 | class GrResourceCache { |
| 193 | public: |
bsalomon@google.com | 07fc0d1 | 2012-06-22 15:15:59 +0000 | [diff] [blame] | 194 | GrResourceCache(int maxCount, size_t maxBytes); |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 195 | ~GrResourceCache(); |
| 196 | |
| 197 | /** |
bsalomon@google.com | 07fc0d1 | 2012-06-22 15:15:59 +0000 | [diff] [blame] | 198 | * Return the current resource cache limits. |
| 199 | * |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 200 | * @param maxResource If non-null, returns maximum number of resources |
bsalomon@google.com | 07fc0d1 | 2012-06-22 15:15:59 +0000 | [diff] [blame] | 201 | * that can be held in the cache. |
| 202 | * @param maxBytes If non-null, returns maximum number of bytes of |
| 203 | * gpu memory that can be held in the cache. |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 204 | */ |
bsalomon@google.com | 07fc0d1 | 2012-06-22 15:15:59 +0000 | [diff] [blame] | 205 | void getLimits(int* maxResources, size_t* maxBytes) const; |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 206 | |
| 207 | /** |
bsalomon@google.com | 07fc0d1 | 2012-06-22 15:15:59 +0000 | [diff] [blame] | 208 | * Specify the resource cache limits. If the current cache exceeds either |
| 209 | * of these, it will be purged (LRU) to keep the cache within these limits. |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 210 | * |
bsalomon@google.com | 07fc0d1 | 2012-06-22 15:15:59 +0000 | [diff] [blame] | 211 | * @param maxResources The maximum number of resources that can be held in |
| 212 | * the cache. |
| 213 | * @param maxBytes The maximum number of bytes of resource memory that |
| 214 | * can be held in the cache. |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 215 | */ |
bsalomon@google.com | 07fc0d1 | 2012-06-22 15:15:59 +0000 | [diff] [blame] | 216 | void setLimits(int maxResource, size_t maxResourceBytes); |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 217 | |
| 218 | /** |
twiz@google.com | 05e7024 | 2012-01-27 19:12:00 +0000 | [diff] [blame] | 219 | * Returns the number of bytes consumed by cached resources. |
| 220 | */ |
| 221 | size_t getCachedResourceBytes() const { return fEntryBytes; } |
| 222 | |
robertphillips@google.com | 209a114 | 2012-10-31 12:25:21 +0000 | [diff] [blame^] | 223 | // For a found or added resource to be completely exclusive to the caller |
| 224 | // both the kNoOtherOwners and kHide flags need to be specified |
| 225 | enum OwnershipFlags { |
| 226 | kNoOtherOwners_OwnershipFlag = 0x1, // found/added resource has no other owners |
| 227 | kHide_OwnershipFlag = 0x2 // found/added resource is hidden from future 'find's |
| 228 | }; |
| 229 | |
twiz@google.com | 05e7024 | 2012-01-27 19:12:00 +0000 | [diff] [blame] | 230 | /** |
robertphillips@google.com | a9b0623 | 2012-08-30 11:06:31 +0000 | [diff] [blame] | 231 | * Search for an entry with the same Key. If found, return it. |
| 232 | * If not found, return null. |
robertphillips@google.com | 209a114 | 2012-10-31 12:25:21 +0000 | [diff] [blame^] | 233 | * If ownershipFlags includes kNoOtherOwners and a resource is returned |
| 234 | * then that resource has no other refs to it. |
| 235 | * If ownershipFlags includes kHide and a resource is returned then that |
| 236 | * resource will not be returned from future 'find' calls until it is |
| 237 | * 'freed' (and recycled) or makeNonExclusive is called. |
| 238 | * For a resource to be completely exclusive to a caller both kNoOtherOwners |
| 239 | * and kHide must be specified. |
robertphillips@google.com | a9b0623 | 2012-08-30 11:06:31 +0000 | [diff] [blame] | 240 | */ |
robertphillips@google.com | 209a114 | 2012-10-31 12:25:21 +0000 | [diff] [blame^] | 241 | GrResource* find(const GrResourceKey& key, |
| 242 | uint32_t ownershipFlags = 0); |
robertphillips@google.com | a9b0623 | 2012-08-30 11:06:31 +0000 | [diff] [blame] | 243 | |
| 244 | /** |
robertphillips@google.com | 209a114 | 2012-10-31 12:25:21 +0000 | [diff] [blame^] | 245 | * Add the new resource to the cache (by creating a new cache entry based |
| 246 | * on the provided key and resource). |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 247 | * |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 248 | * Ownership of the resource is transferred to the resource cache, |
robertphillips@google.com | 15c0fea | 2012-06-22 12:41:43 +0000 | [diff] [blame] | 249 | * which will unref() it when it is purged or deleted. |
robertphillips@google.com | 209a114 | 2012-10-31 12:25:21 +0000 | [diff] [blame^] | 250 | * |
| 251 | * If ownershipFlags includes kHide, subsequent calls to 'find' will not |
| 252 | * return 'resource' until it is 'freed' (and recycled) or makeNonExclusive |
| 253 | * is called. |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 254 | */ |
robertphillips@google.com | 209a114 | 2012-10-31 12:25:21 +0000 | [diff] [blame^] | 255 | void addResource(const GrResourceKey& key, |
| 256 | GrResource* resource, |
| 257 | uint32_t ownershipFlags = 0); |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 258 | |
| 259 | /** |
bsalomon@google.com | fb30951 | 2011-11-30 14:13:48 +0000 | [diff] [blame] | 260 | * Determines if the cache contains an entry matching a key. If a matching |
| 261 | * entry exists but was detached then it will not be found. |
| 262 | */ |
| 263 | bool hasKey(const GrResourceKey& key) const; |
| 264 | |
| 265 | /** |
robertphillips@google.com | 521eaf8 | 2012-08-22 11:03:19 +0000 | [diff] [blame] | 266 | * Hide 'entry' so that future searches will not find it. Such |
| 267 | * hidden entries will not be purged. The entry still counts against |
| 268 | * the cache's budget and should be made non-exclusive when exclusive access |
| 269 | * is no longer needed. |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 270 | */ |
robertphillips@google.com | 521eaf8 | 2012-08-22 11:03:19 +0000 | [diff] [blame] | 271 | void makeExclusive(GrResourceEntry* entry); |
robertphillips@google.com | 15c0fea | 2012-06-22 12:41:43 +0000 | [diff] [blame] | 272 | |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 273 | /** |
robertphillips@google.com | 521eaf8 | 2012-08-22 11:03:19 +0000 | [diff] [blame] | 274 | * Restore 'entry' so that it can be found by future searches. 'entry' |
| 275 | * will also be purgeable (provided its lock count is now 0.) |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 276 | */ |
robertphillips@google.com | 521eaf8 | 2012-08-22 11:03:19 +0000 | [diff] [blame] | 277 | void makeNonExclusive(GrResourceEntry* entry); |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 278 | |
| 279 | /** |
bsalomon@google.com | a292112 | 2012-08-28 12:34:17 +0000 | [diff] [blame] | 280 | * Removes every resource in the cache that isn't locked. |
| 281 | */ |
| 282 | void purgeAllUnlocked(); |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 283 | |
robertphillips@google.com | 50a035d | 2012-09-07 19:44:33 +0000 | [diff] [blame] | 284 | /** |
| 285 | * Allow cache to purge unused resources to obey resource limitations |
robertphillips@google.com | 9fbcad0 | 2012-09-09 14:44:15 +0000 | [diff] [blame] | 286 | * Note: this entry point will be hidden (again) once totally ref-driven |
| 287 | * cache maintenance is implemented |
robertphillips@google.com | 50a035d | 2012-09-07 19:44:33 +0000 | [diff] [blame] | 288 | */ |
| 289 | void purgeAsNeeded(); |
| 290 | |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 291 | #if GR_DEBUG |
| 292 | void validate() const; |
| 293 | #else |
| 294 | void validate() const {} |
| 295 | #endif |
| 296 | |
robertphillips@google.com | 5955202 | 2012-08-31 13:07:37 +0000 | [diff] [blame] | 297 | #if GR_CACHE_STATS |
robertphillips@google.com | 9fbcad0 | 2012-09-09 14:44:15 +0000 | [diff] [blame] | 298 | void printStats(); |
robertphillips@google.com | 5955202 | 2012-08-31 13:07:37 +0000 | [diff] [blame] | 299 | #endif |
| 300 | |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 301 | private: |
robertphillips@google.com | 209a114 | 2012-10-31 12:25:21 +0000 | [diff] [blame^] | 302 | enum BudgetBehaviors { |
| 303 | kAccountFor_BudgetBehavior, |
| 304 | kIgnore_BudgetBehavior |
| 305 | }; |
| 306 | |
| 307 | void internalDetach(GrResourceEntry*, BudgetBehaviors behavior = kAccountFor_BudgetBehavior); |
| 308 | void attachToHead(GrResourceEntry*, BudgetBehaviors behavior = kAccountFor_BudgetBehavior); |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 309 | |
robertphillips@google.com | 521eaf8 | 2012-08-22 11:03:19 +0000 | [diff] [blame] | 310 | void removeInvalidResource(GrResourceEntry* entry); |
| 311 | |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 312 | class Key; |
| 313 | GrTHashTable<GrResourceEntry, Key, 8> fCache; |
| 314 | |
| 315 | // manage the dlink list |
bsalomon@google.com | a292112 | 2012-08-28 12:34:17 +0000 | [diff] [blame] | 316 | typedef SkTDLinkedList<GrResourceEntry> EntryList; |
| 317 | EntryList fList; |
robertphillips@google.com | 521eaf8 | 2012-08-22 11:03:19 +0000 | [diff] [blame] | 318 | |
| 319 | #if GR_DEBUG |
| 320 | // These objects cannot be returned by a search |
bsalomon@google.com | a292112 | 2012-08-28 12:34:17 +0000 | [diff] [blame] | 321 | EntryList fExclusiveList; |
robertphillips@google.com | 521eaf8 | 2012-08-22 11:03:19 +0000 | [diff] [blame] | 322 | #endif |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 323 | |
| 324 | // our budget, used in purgeAsNeeded() |
bsalomon@google.com | 07fc0d1 | 2012-06-22 15:15:59 +0000 | [diff] [blame] | 325 | int fMaxCount; |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 326 | size_t fMaxBytes; |
| 327 | |
| 328 | // our current stats, related to our budget |
robertphillips@google.com | 5955202 | 2012-08-31 13:07:37 +0000 | [diff] [blame] | 329 | #if GR_CACHE_STATS |
robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 330 | int fHighWaterEntryCount; |
robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 331 | size_t fHighWaterEntryBytes; |
| 332 | int fHighWaterClientDetachedCount; |
| 333 | size_t fHighWaterClientDetachedBytes; |
| 334 | #endif |
| 335 | |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 336 | int fEntryCount; |
| 337 | size_t fEntryBytes; |
| 338 | int fClientDetachedCount; |
| 339 | size_t fClientDetachedBytes; |
robertphillips@google.com | 386319e | 2012-06-27 14:59:18 +0000 | [diff] [blame] | 340 | |
bsalomon@google.com | a5a1da8 | 2011-08-05 14:02:41 +0000 | [diff] [blame] | 341 | // prevents recursive purging |
| 342 | bool fPurging; |
robertphillips@google.com | 15c0fea | 2012-06-22 12:41:43 +0000 | [diff] [blame] | 343 | |
robertphillips@google.com | 2ea0a23 | 2012-08-23 11:13:48 +0000 | [diff] [blame] | 344 | #if GR_DEBUG |
robertphillips@google.com | a5c43a5 | 2012-08-23 11:24:02 +0000 | [diff] [blame] | 345 | static size_t countBytes(const SkTDLinkedList<GrResourceEntry>& list); |
robertphillips@google.com | 2ea0a23 | 2012-08-23 11:13:48 +0000 | [diff] [blame] | 346 | #endif |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 347 | }; |
| 348 | |
| 349 | /////////////////////////////////////////////////////////////////////////////// |
| 350 | |
| 351 | #if GR_DEBUG |
| 352 | class GrAutoResourceCacheValidate { |
| 353 | public: |
| 354 | GrAutoResourceCacheValidate(GrResourceCache* cache) : fCache(cache) { |
| 355 | cache->validate(); |
| 356 | } |
| 357 | ~GrAutoResourceCacheValidate() { |
| 358 | fCache->validate(); |
| 359 | } |
| 360 | private: |
| 361 | GrResourceCache* fCache; |
| 362 | }; |
| 363 | #else |
| 364 | class GrAutoResourceCacheValidate { |
| 365 | public: |
| 366 | GrAutoResourceCacheValidate(GrResourceCache*) {} |
| 367 | }; |
| 368 | #endif |
| 369 | |
| 370 | #endif |