epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 2 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 3 | * Copyright 2010 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. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +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 | #include "GrResourceCache.h" |
| 12 | #include "GrResource.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 13 | |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 14 | GrResourceEntry::GrResourceEntry(const GrResourceKey& key, GrResource* resource) |
| 15 | : fKey(key), fResource(resource) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 16 | fLockCount = 0; |
| 17 | fPrev = fNext = NULL; |
| 18 | |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 19 | // we assume ownership of the resource, and will unref it when we die |
| 20 | GrAssert(resource); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 21 | } |
| 22 | |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 23 | GrResourceEntry::~GrResourceEntry() { |
| 24 | fResource->unref(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 25 | } |
| 26 | |
| 27 | #if GR_DEBUG |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 28 | void GrResourceEntry::validate() const { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 29 | GrAssert(fLockCount >= 0); |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 30 | GrAssert(fResource); |
| 31 | fResource->validate(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 32 | } |
| 33 | #endif |
| 34 | |
| 35 | /////////////////////////////////////////////////////////////////////////////// |
| 36 | |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 37 | GrResourceCache::GrResourceCache(int maxCount, size_t maxBytes) : |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 38 | fMaxCount(maxCount), |
| 39 | fMaxBytes(maxBytes) { |
| 40 | fEntryCount = 0; |
bsalomon@google.com | a5a1da8 | 2011-08-05 14:02:41 +0000 | [diff] [blame^] | 41 | fUnlockedEntryCount = 0; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 42 | fEntryBytes = 0; |
| 43 | fClientDetachedCount = 0; |
| 44 | fClientDetachedBytes = 0; |
| 45 | |
| 46 | fHead = fTail = NULL; |
bsalomon@google.com | a5a1da8 | 2011-08-05 14:02:41 +0000 | [diff] [blame^] | 47 | fPurging = false; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 48 | } |
| 49 | |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 50 | GrResourceCache::~GrResourceCache() { |
| 51 | GrAutoResourceCacheValidate atcv(this); |
reed@google.com | 01804b4 | 2011-01-18 21:50:41 +0000 | [diff] [blame] | 52 | |
bsalomon@google.com | 8fe7247 | 2011-03-30 21:26:44 +0000 | [diff] [blame] | 53 | this->removeAll(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 54 | } |
| 55 | |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 56 | void GrResourceCache::getLimits(int* maxResources, size_t* maxResourceBytes) const{ |
| 57 | if (maxResources) { |
| 58 | *maxResources = fMaxCount; |
reed@google.com | 01804b4 | 2011-01-18 21:50:41 +0000 | [diff] [blame] | 59 | } |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 60 | if (maxResourceBytes) { |
| 61 | *maxResourceBytes = fMaxBytes; |
reed@google.com | 01804b4 | 2011-01-18 21:50:41 +0000 | [diff] [blame] | 62 | } |
| 63 | } |
| 64 | |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 65 | void GrResourceCache::setLimits(int maxResources, size_t maxResourceBytes) { |
| 66 | bool smaller = (maxResources < fMaxCount) || (maxResourceBytes < fMaxBytes); |
reed@google.com | 01804b4 | 2011-01-18 21:50:41 +0000 | [diff] [blame] | 67 | |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 68 | fMaxCount = maxResources; |
| 69 | fMaxBytes = maxResourceBytes; |
reed@google.com | 01804b4 | 2011-01-18 21:50:41 +0000 | [diff] [blame] | 70 | |
| 71 | if (smaller) { |
| 72 | this->purgeAsNeeded(); |
| 73 | } |
| 74 | } |
| 75 | |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 76 | void GrResourceCache::internalDetach(GrResourceEntry* entry, |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 77 | bool clientDetach) { |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 78 | GrResourceEntry* prev = entry->fPrev; |
| 79 | GrResourceEntry* next = entry->fNext; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 80 | |
| 81 | if (prev) { |
| 82 | prev->fNext = next; |
| 83 | } else { |
| 84 | fHead = next; |
| 85 | } |
| 86 | if (next) { |
| 87 | next->fPrev = prev; |
| 88 | } else { |
| 89 | fTail = prev; |
| 90 | } |
bsalomon@google.com | a5a1da8 | 2011-08-05 14:02:41 +0000 | [diff] [blame^] | 91 | if (!entry->isLocked()) { |
| 92 | --fUnlockedEntryCount; |
| 93 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 94 | |
| 95 | // update our stats |
| 96 | if (clientDetach) { |
| 97 | fClientDetachedCount += 1; |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 98 | fClientDetachedBytes += entry->resource()->sizeInBytes(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 99 | } else { |
| 100 | fEntryCount -= 1; |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 101 | fEntryBytes -= entry->resource()->sizeInBytes(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 102 | } |
| 103 | } |
| 104 | |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 105 | void GrResourceCache::attachToHead(GrResourceEntry* entry, |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 106 | bool clientReattach) { |
| 107 | entry->fPrev = NULL; |
| 108 | entry->fNext = fHead; |
| 109 | if (fHead) { |
| 110 | fHead->fPrev = entry; |
| 111 | } |
| 112 | fHead = entry; |
| 113 | if (NULL == fTail) { |
| 114 | fTail = entry; |
| 115 | } |
bsalomon@google.com | a5a1da8 | 2011-08-05 14:02:41 +0000 | [diff] [blame^] | 116 | if (!entry->isLocked()) { |
| 117 | ++fUnlockedEntryCount; |
| 118 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 119 | |
| 120 | // update our stats |
| 121 | if (clientReattach) { |
| 122 | fClientDetachedCount -= 1; |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 123 | fClientDetachedBytes -= entry->resource()->sizeInBytes(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 124 | } else { |
| 125 | fEntryCount += 1; |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 126 | fEntryBytes += entry->resource()->sizeInBytes(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 127 | } |
| 128 | } |
| 129 | |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 130 | class GrResourceCache::Key { |
| 131 | typedef GrResourceEntry T; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 132 | |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 133 | const GrResourceKey& fKey; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 134 | public: |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 135 | Key(const GrResourceKey& key) : fKey(key) {} |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 136 | |
| 137 | uint32_t getHash() const { return fKey.hashIndex(); } |
reed@google.com | 01804b4 | 2011-01-18 21:50:41 +0000 | [diff] [blame] | 138 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 139 | static bool LT(const T& entry, const Key& key) { |
| 140 | return entry.key() < key.fKey; |
| 141 | } |
| 142 | static bool EQ(const T& entry, const Key& key) { |
| 143 | return entry.key() == key.fKey; |
| 144 | } |
| 145 | #if GR_DEBUG |
| 146 | static uint32_t GetHash(const T& entry) { |
| 147 | return entry.key().hashIndex(); |
| 148 | } |
| 149 | static bool LT(const T& a, const T& b) { |
| 150 | return a.key() < b.key(); |
| 151 | } |
| 152 | static bool EQ(const T& a, const T& b) { |
| 153 | return a.key() == b.key(); |
| 154 | } |
| 155 | #endif |
| 156 | }; |
| 157 | |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 158 | GrResourceEntry* GrResourceCache::findAndLock(const GrResourceKey& key) { |
| 159 | GrAutoResourceCacheValidate atcv(this); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 160 | |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 161 | GrResourceEntry* entry = fCache.find(key); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 162 | if (entry) { |
| 163 | this->internalDetach(entry, false); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 164 | // mark the entry as "busy" so it doesn't get purged |
bsalomon@google.com | a5a1da8 | 2011-08-05 14:02:41 +0000 | [diff] [blame^] | 165 | // do this between detach and attach for locked count tracking |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 166 | entry->lock(); |
bsalomon@google.com | a5a1da8 | 2011-08-05 14:02:41 +0000 | [diff] [blame^] | 167 | this->attachToHead(entry, false); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 168 | } |
| 169 | return entry; |
| 170 | } |
| 171 | |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 172 | GrResourceEntry* GrResourceCache::createAndLock(const GrResourceKey& key, |
| 173 | GrResource* resource) { |
bsalomon@google.com | a5a1da8 | 2011-08-05 14:02:41 +0000 | [diff] [blame^] | 174 | // we don't expect to create new resources during a purge. In theory |
| 175 | // this could cause purgeAsNeeded() into an infinite loop (e.g. |
| 176 | // each resource destroyed creates and locks 2 resources and |
| 177 | // unlocks 1 thereby causing a new purge). |
| 178 | GrAssert(!fPurging); |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 179 | GrAutoResourceCacheValidate atcv(this); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 180 | |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 181 | GrResourceEntry* entry = new GrResourceEntry(key, resource); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 182 | |
bsalomon@google.com | a5a1da8 | 2011-08-05 14:02:41 +0000 | [diff] [blame^] | 183 | // mark the entry as "busy" so it doesn't get purged |
| 184 | // do this before attach for locked count tracking |
| 185 | entry->lock(); |
| 186 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 187 | this->attachToHead(entry, false); |
| 188 | fCache.insert(key, entry); |
| 189 | |
| 190 | #if GR_DUMP_TEXTURE_UPLOAD |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 191 | GrPrintf("--- add resource to cache %p, count=%d bytes= %d %d\n", |
| 192 | entry, fEntryCount, resource->sizeInBytes(), fEntryBytes); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 193 | #endif |
| 194 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 195 | this->purgeAsNeeded(); |
| 196 | return entry; |
| 197 | } |
| 198 | |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 199 | void GrResourceCache::detach(GrResourceEntry* entry) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 200 | internalDetach(entry, true); |
| 201 | fCache.remove(entry->fKey, entry); |
| 202 | } |
| 203 | |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 204 | void GrResourceCache::reattachAndUnlock(GrResourceEntry* entry) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 205 | attachToHead(entry, true); |
| 206 | fCache.insert(entry->key(), entry); |
| 207 | unlock(entry); |
| 208 | } |
| 209 | |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 210 | void GrResourceCache::unlock(GrResourceEntry* entry) { |
| 211 | GrAutoResourceCacheValidate atcv(this); |
reed@google.com | 01804b4 | 2011-01-18 21:50:41 +0000 | [diff] [blame] | 212 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 213 | GrAssert(entry); |
| 214 | GrAssert(entry->isLocked()); |
| 215 | GrAssert(fCache.find(entry->key())); |
| 216 | |
| 217 | entry->unlock(); |
bsalomon@google.com | a5a1da8 | 2011-08-05 14:02:41 +0000 | [diff] [blame^] | 218 | if (!entry->isLocked()) { |
| 219 | ++fUnlockedEntryCount; |
| 220 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 221 | this->purgeAsNeeded(); |
| 222 | } |
| 223 | |
bsalomon@google.com | a5a1da8 | 2011-08-05 14:02:41 +0000 | [diff] [blame^] | 224 | /** |
| 225 | * Destroying a resource may potentially trigger the unlock of additional |
| 226 | * resources which in turn will trigger a nested purge. We block the nested |
| 227 | * purge using the fPurging variable. However, the initial purge will keep |
| 228 | * looping until either all resources in the cache are unlocked or we've met |
| 229 | * the budget. There is an assertion in createAndLock to check against a |
| 230 | * resource's destructor inserting new resources into the cache. If these |
| 231 | * new resources were unlocked before purgeAsNeeded completed it could |
| 232 | * potentially make purgeAsNeeded loop infinitely. |
| 233 | */ |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 234 | void GrResourceCache::purgeAsNeeded() { |
bsalomon@google.com | a5a1da8 | 2011-08-05 14:02:41 +0000 | [diff] [blame^] | 235 | if (!fPurging) { |
| 236 | fPurging = true; |
| 237 | bool withinBudget = false; |
| 238 | do { |
| 239 | GrAutoResourceCacheValidate atcv(this); |
| 240 | GrResourceEntry* entry = fTail; |
| 241 | while (entry && fUnlockedEntryCount) { |
| 242 | if (fEntryCount <= fMaxCount && fEntryBytes <= fMaxBytes) { |
| 243 | withinBudget = true; |
| 244 | break; |
| 245 | } |
reed@google.com | 01804b4 | 2011-01-18 21:50:41 +0000 | [diff] [blame] | 246 | |
bsalomon@google.com | a5a1da8 | 2011-08-05 14:02:41 +0000 | [diff] [blame^] | 247 | GrResourceEntry* prev = entry->fPrev; |
| 248 | if (!entry->isLocked()) { |
| 249 | // remove from our cache |
| 250 | fCache.remove(entry->fKey, entry); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 251 | |
bsalomon@google.com | a5a1da8 | 2011-08-05 14:02:41 +0000 | [diff] [blame^] | 252 | // remove from our llist |
| 253 | this->internalDetach(entry, false); |
reed@google.com | 01804b4 | 2011-01-18 21:50:41 +0000 | [diff] [blame] | 254 | |
bsalomon@google.com | a5a1da8 | 2011-08-05 14:02:41 +0000 | [diff] [blame^] | 255 | #if GR_DUMP_TEXTURE_UPLOAD |
| 256 | GrPrintf("--- ~resource from cache %p [%d %d]\n", |
| 257 | entry->resource(), |
| 258 | entry->resource()->width(), |
| 259 | entry->resource()->height()); |
| 260 | #endif |
| 261 | delete entry; |
| 262 | } |
| 263 | entry = prev; |
| 264 | } |
| 265 | } while (!withinBudget && fUnlockedEntryCount); |
| 266 | fPurging = false; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 267 | } |
| 268 | } |
| 269 | |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 270 | void GrResourceCache::removeAll() { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 271 | GrAssert(!fClientDetachedCount); |
| 272 | GrAssert(!fClientDetachedBytes); |
reed@google.com | 01804b4 | 2011-01-18 21:50:41 +0000 | [diff] [blame] | 273 | |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 274 | GrResourceEntry* entry = fHead; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 275 | while (entry) { |
| 276 | GrAssert(!entry->isLocked()); |
| 277 | |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 278 | GrResourceEntry* next = entry->fNext; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 279 | delete entry; |
| 280 | entry = next; |
| 281 | } |
| 282 | |
| 283 | fCache.removeAll(); |
| 284 | fHead = fTail = NULL; |
| 285 | fEntryCount = 0; |
| 286 | fEntryBytes = 0; |
bsalomon@google.com | a5a1da8 | 2011-08-05 14:02:41 +0000 | [diff] [blame^] | 287 | fUnlockedEntryCount = 0; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | /////////////////////////////////////////////////////////////////////////////// |
| 291 | |
| 292 | #if GR_DEBUG |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 293 | static int countMatches(const GrResourceEntry* head, const GrResourceEntry* target) { |
| 294 | const GrResourceEntry* entry = head; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 295 | int count = 0; |
| 296 | while (entry) { |
| 297 | if (target == entry) { |
| 298 | count += 1; |
| 299 | } |
| 300 | entry = entry->next(); |
| 301 | } |
| 302 | return count; |
| 303 | } |
| 304 | |
reed@google.com | b89a643 | 2011-02-07 13:20:30 +0000 | [diff] [blame] | 305 | #if GR_DEBUG |
| 306 | static bool both_zero_or_nonzero(int count, size_t bytes) { |
| 307 | return (count == 0 && bytes == 0) || (count > 0 && bytes > 0); |
| 308 | } |
| 309 | #endif |
| 310 | |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 311 | void GrResourceCache::validate() const { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 312 | GrAssert(!fHead == !fTail); |
reed@google.com | b89a643 | 2011-02-07 13:20:30 +0000 | [diff] [blame] | 313 | GrAssert(both_zero_or_nonzero(fEntryCount, fEntryBytes)); |
| 314 | GrAssert(both_zero_or_nonzero(fClientDetachedCount, fClientDetachedBytes)); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 315 | GrAssert(fClientDetachedBytes <= fEntryBytes); |
| 316 | GrAssert(fClientDetachedCount <= fEntryCount); |
| 317 | GrAssert((fEntryCount - fClientDetachedCount) == fCache.count()); |
reed@google.com | 01804b4 | 2011-01-18 21:50:41 +0000 | [diff] [blame] | 318 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 319 | fCache.validate(); |
| 320 | |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 321 | GrResourceEntry* entry = fHead; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 322 | int count = 0; |
bsalomon@google.com | a5a1da8 | 2011-08-05 14:02:41 +0000 | [diff] [blame^] | 323 | int unlockCount = 0; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 324 | size_t bytes = 0; |
| 325 | while (entry) { |
| 326 | entry->validate(); |
| 327 | GrAssert(fCache.find(entry->key())); |
| 328 | count += 1; |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 329 | bytes += entry->resource()->sizeInBytes(); |
bsalomon@google.com | a5a1da8 | 2011-08-05 14:02:41 +0000 | [diff] [blame^] | 330 | if (!entry->isLocked()) { |
| 331 | unlockCount += 1; |
| 332 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 333 | entry = entry->fNext; |
| 334 | } |
| 335 | GrAssert(count == fEntryCount - fClientDetachedCount); |
| 336 | GrAssert(bytes == fEntryBytes - fClientDetachedBytes); |
bsalomon@google.com | a5a1da8 | 2011-08-05 14:02:41 +0000 | [diff] [blame^] | 337 | GrAssert(unlockCount == fUnlockedEntryCount); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 338 | |
| 339 | count = 0; |
| 340 | for (entry = fTail; entry; entry = entry->fPrev) { |
| 341 | count += 1; |
| 342 | } |
| 343 | GrAssert(count == fEntryCount - fClientDetachedCount); |
| 344 | |
| 345 | for (int i = 0; i < count; i++) { |
| 346 | int matches = countMatches(fHead, fCache.getArray()[i]); |
| 347 | GrAssert(1 == matches); |
| 348 | } |
| 349 | } |
| 350 | #endif |
| 351 | |
| 352 | |