blob: 7e0b8928be2da9434f3002d0d7ffda029aa0b4ec [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
reed@google.comac10a2d2010-12-22 21:39:39 +00002/*
epoger@google.comec3ed6a2011-07-28 14:26:00 +00003 * 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.comac10a2d2010-12-22 21:39:39 +00007 */
8
9
epoger@google.comec3ed6a2011-07-28 14:26:00 +000010
bsalomon@google.com50398bf2011-07-26 20:45:30 +000011#include "GrResourceCache.h"
12#include "GrResource.h"
reed@google.comac10a2d2010-12-22 21:39:39 +000013
bsalomon@google.com50398bf2011-07-26 20:45:30 +000014GrResourceEntry::GrResourceEntry(const GrResourceKey& key, GrResource* resource)
15 : fKey(key), fResource(resource) {
reed@google.comac10a2d2010-12-22 21:39:39 +000016 fLockCount = 0;
17 fPrev = fNext = NULL;
18
bsalomon@google.com50398bf2011-07-26 20:45:30 +000019 // we assume ownership of the resource, and will unref it when we die
20 GrAssert(resource);
reed@google.comac10a2d2010-12-22 21:39:39 +000021}
22
bsalomon@google.com50398bf2011-07-26 20:45:30 +000023GrResourceEntry::~GrResourceEntry() {
24 fResource->unref();
reed@google.comac10a2d2010-12-22 21:39:39 +000025}
26
27#if GR_DEBUG
bsalomon@google.com50398bf2011-07-26 20:45:30 +000028void GrResourceEntry::validate() const {
reed@google.comac10a2d2010-12-22 21:39:39 +000029 GrAssert(fLockCount >= 0);
bsalomon@google.com50398bf2011-07-26 20:45:30 +000030 GrAssert(fResource);
robertphillips@google.com1f47f4f2012-08-16 14:49:16 +000031 GrAssert(fResource->getCacheEntry() == this);
bsalomon@google.com50398bf2011-07-26 20:45:30 +000032 fResource->validate();
reed@google.comac10a2d2010-12-22 21:39:39 +000033}
34#endif
35
36///////////////////////////////////////////////////////////////////////////////
37
bsalomon@google.com07fc0d12012-06-22 15:15:59 +000038GrResourceCache::GrResourceCache(int maxCount, size_t maxBytes) :
39 fMaxCount(maxCount),
40 fMaxBytes(maxBytes) {
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +000041#if GR_DEBUG
42 fHighWaterEntryCount = 0;
43 fHighWaterUnlockedEntryCount = 0;
44 fHighWaterEntryBytes = 0;
45 fHighWaterClientDetachedCount = 0;
46 fHighWaterClientDetachedBytes = 0;
47#endif
48
49 fEntryCount = 0;
50 fUnlockedEntryCount = 0;
51 fEntryBytes = 0;
52 fClientDetachedCount = 0;
53 fClientDetachedBytes = 0;
reed@google.comac10a2d2010-12-22 21:39:39 +000054
55 fHead = fTail = NULL;
bsalomon@google.coma5a1da82011-08-05 14:02:41 +000056 fPurging = false;
reed@google.comac10a2d2010-12-22 21:39:39 +000057}
58
bsalomon@google.com50398bf2011-07-26 20:45:30 +000059GrResourceCache::~GrResourceCache() {
60 GrAutoResourceCacheValidate atcv(this);
reed@google.com01804b42011-01-18 21:50:41 +000061
bsalomon@google.com8fe72472011-03-30 21:26:44 +000062 this->removeAll();
reed@google.comac10a2d2010-12-22 21:39:39 +000063}
64
bsalomon@google.com07fc0d12012-06-22 15:15:59 +000065void GrResourceCache::getLimits(int* maxResources, size_t* maxResourceBytes) const{
66 if (maxResources) {
67 *maxResources = fMaxCount;
68 }
69 if (maxResourceBytes) {
70 *maxResourceBytes = fMaxBytes;
71 }
72}
reed@google.com01804b42011-01-18 21:50:41 +000073
bsalomon@google.com07fc0d12012-06-22 15:15:59 +000074void GrResourceCache::setLimits(int maxResources, size_t maxResourceBytes) {
75 bool smaller = (maxResources < fMaxCount) || (maxResourceBytes < fMaxBytes);
76
77 fMaxCount = maxResources;
bsalomon@google.com50398bf2011-07-26 20:45:30 +000078 fMaxBytes = maxResourceBytes;
reed@google.com01804b42011-01-18 21:50:41 +000079
80 if (smaller) {
81 this->purgeAsNeeded();
82 }
83}
84
bsalomon@google.com50398bf2011-07-26 20:45:30 +000085void GrResourceCache::internalDetach(GrResourceEntry* entry,
reed@google.comac10a2d2010-12-22 21:39:39 +000086 bool clientDetach) {
bsalomon@google.com50398bf2011-07-26 20:45:30 +000087 GrResourceEntry* prev = entry->fPrev;
88 GrResourceEntry* next = entry->fNext;
reed@google.comac10a2d2010-12-22 21:39:39 +000089
90 if (prev) {
91 prev->fNext = next;
92 } else {
93 fHead = next;
94 }
95 if (next) {
96 next->fPrev = prev;
97 } else {
98 fTail = prev;
99 }
bsalomon@google.coma5a1da82011-08-05 14:02:41 +0000100 if (!entry->isLocked()) {
101 --fUnlockedEntryCount;
102 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000103
robertphillips@google.com15c0fea2012-06-22 12:41:43 +0000104 entry->fPrev = NULL;
105 entry->fNext = NULL;
106
reed@google.comac10a2d2010-12-22 21:39:39 +0000107 // update our stats
108 if (clientDetach) {
109 fClientDetachedCount += 1;
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000110 fClientDetachedBytes += entry->resource()->sizeInBytes();
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +0000111
112#if GR_DEBUG
113 if (fHighWaterClientDetachedCount < fClientDetachedCount) {
114 fHighWaterClientDetachedCount = fClientDetachedCount;
115 }
116 if (fHighWaterClientDetachedBytes < fClientDetachedBytes) {
117 fHighWaterClientDetachedBytes = fClientDetachedBytes;
118 }
119#endif
120
reed@google.comac10a2d2010-12-22 21:39:39 +0000121 } else {
122 fEntryCount -= 1;
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000123 fEntryBytes -= entry->resource()->sizeInBytes();
reed@google.comac10a2d2010-12-22 21:39:39 +0000124 }
125}
126
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000127void GrResourceCache::attachToHead(GrResourceEntry* entry,
reed@google.comac10a2d2010-12-22 21:39:39 +0000128 bool clientReattach) {
129 entry->fPrev = NULL;
130 entry->fNext = fHead;
131 if (fHead) {
132 fHead->fPrev = entry;
133 }
134 fHead = entry;
135 if (NULL == fTail) {
136 fTail = entry;
137 }
bsalomon@google.coma5a1da82011-08-05 14:02:41 +0000138 if (!entry->isLocked()) {
139 ++fUnlockedEntryCount;
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +0000140#if GR_DEBUG
141 if (fHighWaterUnlockedEntryCount < fUnlockedEntryCount) {
142 fHighWaterUnlockedEntryCount = fUnlockedEntryCount;
143 }
144#endif
bsalomon@google.coma5a1da82011-08-05 14:02:41 +0000145 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000146
147 // update our stats
148 if (clientReattach) {
149 fClientDetachedCount -= 1;
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000150 fClientDetachedBytes -= entry->resource()->sizeInBytes();
reed@google.comac10a2d2010-12-22 21:39:39 +0000151 } else {
152 fEntryCount += 1;
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000153 fEntryBytes += entry->resource()->sizeInBytes();
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +0000154
155#if GR_DEBUG
156 if (fHighWaterEntryCount < fEntryCount) {
157 fHighWaterEntryCount = fEntryCount;
158 }
159 if (fHighWaterEntryBytes < fEntryBytes) {
160 fHighWaterEntryBytes = fEntryBytes;
161 }
162#endif
reed@google.comac10a2d2010-12-22 21:39:39 +0000163 }
164}
165
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000166class GrResourceCache::Key {
167 typedef GrResourceEntry T;
reed@google.comac10a2d2010-12-22 21:39:39 +0000168
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000169 const GrResourceKey& fKey;
reed@google.comac10a2d2010-12-22 21:39:39 +0000170public:
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000171 Key(const GrResourceKey& key) : fKey(key) {}
reed@google.comac10a2d2010-12-22 21:39:39 +0000172
173 uint32_t getHash() const { return fKey.hashIndex(); }
reed@google.com01804b42011-01-18 21:50:41 +0000174
reed@google.comac10a2d2010-12-22 21:39:39 +0000175 static bool LT(const T& entry, const Key& key) {
176 return entry.key() < key.fKey;
177 }
178 static bool EQ(const T& entry, const Key& key) {
179 return entry.key() == key.fKey;
180 }
181#if GR_DEBUG
182 static uint32_t GetHash(const T& entry) {
183 return entry.key().hashIndex();
184 }
185 static bool LT(const T& a, const T& b) {
186 return a.key() < b.key();
187 }
188 static bool EQ(const T& a, const T& b) {
189 return a.key() == b.key();
190 }
191#endif
192};
193
robertphillips@google.com1f47f4f2012-08-16 14:49:16 +0000194GrResource* GrResourceCache::findAndLock(const GrResourceKey& key,
195 LockType type) {
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000196 GrAutoResourceCacheValidate atcv(this);
reed@google.comac10a2d2010-12-22 21:39:39 +0000197
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000198 GrResourceEntry* entry = fCache.find(key);
robertphillips@google.com1f47f4f2012-08-16 14:49:16 +0000199 if (NULL == entry) {
200 return NULL;
reed@google.comac10a2d2010-12-22 21:39:39 +0000201 }
robertphillips@google.com1f47f4f2012-08-16 14:49:16 +0000202
203 this->internalDetach(entry, false);
204 // mark the entry as "busy" so it doesn't get purged
205 // do this between detach and attach for locked count tracking
206 if (kNested_LockType == type || !entry->isLocked()) {
207 entry->lock();
208 }
209 this->attachToHead(entry, false);
210
211 return entry->fResource;
reed@google.comac10a2d2010-12-22 21:39:39 +0000212}
213
bsalomon@google.comfb309512011-11-30 14:13:48 +0000214bool GrResourceCache::hasKey(const GrResourceKey& key) const {
215 return NULL != fCache.find(key);
216}
217
robertphillips@google.com15c0fea2012-06-22 12:41:43 +0000218GrResourceEntry* GrResourceCache::create(const GrResourceKey& key,
219 GrResource* resource,
robertphillips@google.com386319e2012-06-27 14:59:18 +0000220 bool lock,
221 bool clientReattach) {
bsalomon@google.coma5a1da82011-08-05 14:02:41 +0000222 // we don't expect to create new resources during a purge. In theory
223 // this could cause purgeAsNeeded() into an infinite loop (e.g.
224 // each resource destroyed creates and locks 2 resources and
225 // unlocks 1 thereby causing a new purge).
226 GrAssert(!fPurging);
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000227 GrAutoResourceCacheValidate atcv(this);
reed@google.comac10a2d2010-12-22 21:39:39 +0000228
tomhudson@google.comc377baf2012-07-09 20:17:56 +0000229 GrResourceEntry* entry = SkNEW_ARGS(GrResourceEntry, (key, resource));
reed@google.comac10a2d2010-12-22 21:39:39 +0000230
robertphillips@google.com1f47f4f2012-08-16 14:49:16 +0000231 resource->setCacheEntry(entry);
232
robertphillips@google.com15c0fea2012-06-22 12:41:43 +0000233 if (lock) {
234 // mark the entry as "busy" so it doesn't get purged
235 // do this before attach for locked count tracking
236 entry->lock();
237 }
bsalomon@google.coma5a1da82011-08-05 14:02:41 +0000238
robertphillips@google.com386319e2012-06-27 14:59:18 +0000239 this->attachToHead(entry, clientReattach);
reed@google.comac10a2d2010-12-22 21:39:39 +0000240 fCache.insert(key, entry);
241
242#if GR_DUMP_TEXTURE_UPLOAD
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000243 GrPrintf("--- add resource to cache %p, count=%d bytes= %d %d\n",
244 entry, fEntryCount, resource->sizeInBytes(), fEntryBytes);
reed@google.comac10a2d2010-12-22 21:39:39 +0000245#endif
246
reed@google.comac10a2d2010-12-22 21:39:39 +0000247 this->purgeAsNeeded();
248 return entry;
249}
250
robertphillips@google.com1f47f4f2012-08-16 14:49:16 +0000251void GrResourceCache::createAndLock(const GrResourceKey& key,
252 GrResource* resource) {
253 GrAssert(NULL == resource->getCacheEntry());
254 this->create(key, resource, true, false);
robertphillips@google.com15c0fea2012-06-22 12:41:43 +0000255}
256
257void GrResourceCache::attach(const GrResourceKey& key,
258 GrResource* resource) {
robertphillips@google.com1f47f4f2012-08-16 14:49:16 +0000259 GrAssert(NULL == resource->getCacheEntry());
robertphillips@google.com386319e2012-06-27 14:59:18 +0000260 this->create(key, resource, false, true);
robertphillips@google.com15c0fea2012-06-22 12:41:43 +0000261}
262
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000263void GrResourceCache::detach(GrResourceEntry* entry) {
bsalomon@google.come9a98942011-08-22 17:06:16 +0000264 GrAutoResourceCacheValidate atcv(this);
robertphillips@google.com15c0fea2012-06-22 12:41:43 +0000265 this->internalDetach(entry, true);
reed@google.comac10a2d2010-12-22 21:39:39 +0000266 fCache.remove(entry->fKey, entry);
267}
268
robertphillips@google.com15c0fea2012-06-22 12:41:43 +0000269void GrResourceCache::freeEntry(GrResourceEntry* entry) {
270 GrAssert(NULL == entry->fNext && NULL == entry->fPrev);
271 delete entry;
272}
273
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000274void GrResourceCache::reattachAndUnlock(GrResourceEntry* entry) {
bsalomon@google.com60879752011-09-15 20:43:53 +0000275 GrAutoResourceCacheValidate atcv(this);
276 if (entry->resource()->isValid()) {
277 attachToHead(entry, true);
278 fCache.insert(entry->key(), entry);
279 } else {
280 // If the resource went invalid while it was detached then purge it
281 // This can happen when a 3D context was lost,
282 // the client called GrContext::contextDestroyed() to notify Gr,
283 // and then later an SkGpuDevice's destructor releases its backing
284 // texture (which was invalidated at contextDestroyed time).
285 fClientDetachedCount -= 1;
286 fEntryCount -= 1;
287 size_t size = entry->resource()->sizeInBytes();
288 fClientDetachedBytes -= size;
289 fEntryBytes -= size;
290 }
291 this->unlock(entry);
reed@google.comac10a2d2010-12-22 21:39:39 +0000292}
293
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000294void GrResourceCache::unlock(GrResourceEntry* entry) {
295 GrAutoResourceCacheValidate atcv(this);
reed@google.com01804b42011-01-18 21:50:41 +0000296
reed@google.comac10a2d2010-12-22 21:39:39 +0000297 GrAssert(entry);
298 GrAssert(entry->isLocked());
299 GrAssert(fCache.find(entry->key()));
300
301 entry->unlock();
bsalomon@google.coma5a1da82011-08-05 14:02:41 +0000302 if (!entry->isLocked()) {
303 ++fUnlockedEntryCount;
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +0000304#if GR_DEBUG
305 if (fHighWaterUnlockedEntryCount < fUnlockedEntryCount) {
306 fHighWaterUnlockedEntryCount = fUnlockedEntryCount;
307 }
308#endif
bsalomon@google.coma5a1da82011-08-05 14:02:41 +0000309 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000310 this->purgeAsNeeded();
311}
312
bsalomon@google.coma5a1da82011-08-05 14:02:41 +0000313/**
314 * Destroying a resource may potentially trigger the unlock of additional
315 * resources which in turn will trigger a nested purge. We block the nested
316 * purge using the fPurging variable. However, the initial purge will keep
317 * looping until either all resources in the cache are unlocked or we've met
318 * the budget. There is an assertion in createAndLock to check against a
319 * resource's destructor inserting new resources into the cache. If these
320 * new resources were unlocked before purgeAsNeeded completed it could
321 * potentially make purgeAsNeeded loop infinitely.
322 */
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000323void GrResourceCache::purgeAsNeeded() {
bsalomon@google.coma5a1da82011-08-05 14:02:41 +0000324 if (!fPurging) {
325 fPurging = true;
326 bool withinBudget = false;
327 do {
bsalomon@google.coma5a1da82011-08-05 14:02:41 +0000328 GrResourceEntry* entry = fTail;
329 while (entry && fUnlockedEntryCount) {
bsalomon@google.come9a98942011-08-22 17:06:16 +0000330 GrAutoResourceCacheValidate atcv(this);
bsalomon@google.com07fc0d12012-06-22 15:15:59 +0000331 if (fEntryCount <= fMaxCount && fEntryBytes <= fMaxBytes) {
bsalomon@google.coma5a1da82011-08-05 14:02:41 +0000332 withinBudget = true;
333 break;
334 }
reed@google.com01804b42011-01-18 21:50:41 +0000335
bsalomon@google.coma5a1da82011-08-05 14:02:41 +0000336 GrResourceEntry* prev = entry->fPrev;
337 if (!entry->isLocked()) {
338 // remove from our cache
339 fCache.remove(entry->fKey, entry);
reed@google.comac10a2d2010-12-22 21:39:39 +0000340
bsalomon@google.coma5a1da82011-08-05 14:02:41 +0000341 // remove from our llist
342 this->internalDetach(entry, false);
reed@google.com01804b42011-01-18 21:50:41 +0000343
bsalomon@google.coma5a1da82011-08-05 14:02:41 +0000344 #if GR_DUMP_TEXTURE_UPLOAD
345 GrPrintf("--- ~resource from cache %p [%d %d]\n",
346 entry->resource(),
347 entry->resource()->width(),
348 entry->resource()->height());
349 #endif
350 delete entry;
351 }
352 entry = prev;
353 }
354 } while (!withinBudget && fUnlockedEntryCount);
355 fPurging = false;
reed@google.comac10a2d2010-12-22 21:39:39 +0000356 }
357}
358
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000359void GrResourceCache::removeAll() {
bsalomon@google.come9a98942011-08-22 17:06:16 +0000360 GrAutoResourceCacheValidate atcv(this);
reed@google.com01804b42011-01-18 21:50:41 +0000361
bsalomon@google.come9a98942011-08-22 17:06:16 +0000362 // we can have one GrResource holding a lock on another
363 // so we don't want to just do a simple loop kicking each
364 // entry out. Instead change the budget and purge.
reed@google.comac10a2d2010-12-22 21:39:39 +0000365
bsalomon@google.come9a98942011-08-22 17:06:16 +0000366 int savedMaxBytes = fMaxBytes;
bsalomon@google.com07fc0d12012-06-22 15:15:59 +0000367 int savedMaxCount = fMaxCount;
368 fMaxBytes = (size_t) -1;
369 fMaxCount = 0;
bsalomon@google.come9a98942011-08-22 17:06:16 +0000370 this->purgeAsNeeded();
371
twiz@google.com0ec107f2012-02-21 19:15:53 +0000372#if GR_DEBUG
bsalomon@google.come9a98942011-08-22 17:06:16 +0000373 GrAssert(!fUnlockedEntryCount);
twiz@google.com0ec107f2012-02-21 19:15:53 +0000374 if (!fCache.count()) {
375 // Items may have been detached from the cache (such as the backing
376 // texture for an SkGpuDevice). The above purge would not have removed
377 // them.
378 GrAssert(fEntryCount == fClientDetachedCount);
379 GrAssert(fEntryBytes == fClientDetachedBytes);
380 GrAssert(NULL == fHead);
381 GrAssert(NULL == fTail);
382 }
383#endif
bsalomon@google.come9a98942011-08-22 17:06:16 +0000384
385 fMaxBytes = savedMaxBytes;
bsalomon@google.com07fc0d12012-06-22 15:15:59 +0000386 fMaxCount = savedMaxCount;
reed@google.comac10a2d2010-12-22 21:39:39 +0000387}
388
389///////////////////////////////////////////////////////////////////////////////
390
391#if GR_DEBUG
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000392static int countMatches(const GrResourceEntry* head, const GrResourceEntry* target) {
393 const GrResourceEntry* entry = head;
reed@google.comac10a2d2010-12-22 21:39:39 +0000394 int count = 0;
395 while (entry) {
396 if (target == entry) {
397 count += 1;
398 }
399 entry = entry->next();
400 }
401 return count;
402}
403
reed@google.comb89a6432011-02-07 13:20:30 +0000404#if GR_DEBUG
405static bool both_zero_or_nonzero(int count, size_t bytes) {
406 return (count == 0 && bytes == 0) || (count > 0 && bytes > 0);
407}
408#endif
409
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000410void GrResourceCache::validate() const {
reed@google.comac10a2d2010-12-22 21:39:39 +0000411 GrAssert(!fHead == !fTail);
reed@google.comb89a6432011-02-07 13:20:30 +0000412 GrAssert(both_zero_or_nonzero(fEntryCount, fEntryBytes));
413 GrAssert(both_zero_or_nonzero(fClientDetachedCount, fClientDetachedBytes));
reed@google.comac10a2d2010-12-22 21:39:39 +0000414 GrAssert(fClientDetachedBytes <= fEntryBytes);
415 GrAssert(fClientDetachedCount <= fEntryCount);
416 GrAssert((fEntryCount - fClientDetachedCount) == fCache.count());
reed@google.com01804b42011-01-18 21:50:41 +0000417
reed@google.comac10a2d2010-12-22 21:39:39 +0000418 fCache.validate();
419
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000420 GrResourceEntry* entry = fHead;
reed@google.comac10a2d2010-12-22 21:39:39 +0000421 int count = 0;
bsalomon@google.coma5a1da82011-08-05 14:02:41 +0000422 int unlockCount = 0;
reed@google.comac10a2d2010-12-22 21:39:39 +0000423 size_t bytes = 0;
424 while (entry) {
425 entry->validate();
426 GrAssert(fCache.find(entry->key()));
427 count += 1;
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000428 bytes += entry->resource()->sizeInBytes();
bsalomon@google.coma5a1da82011-08-05 14:02:41 +0000429 if (!entry->isLocked()) {
430 unlockCount += 1;
431 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000432 entry = entry->fNext;
433 }
434 GrAssert(count == fEntryCount - fClientDetachedCount);
435 GrAssert(bytes == fEntryBytes - fClientDetachedBytes);
bsalomon@google.coma5a1da82011-08-05 14:02:41 +0000436 GrAssert(unlockCount == fUnlockedEntryCount);
reed@google.comac10a2d2010-12-22 21:39:39 +0000437
438 count = 0;
439 for (entry = fTail; entry; entry = entry->fPrev) {
440 count += 1;
441 }
442 GrAssert(count == fEntryCount - fClientDetachedCount);
443
444 for (int i = 0; i < count; i++) {
445 int matches = countMatches(fHead, fCache.getArray()[i]);
446 GrAssert(1 == matches);
447 }
448}
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +0000449
450void GrResourceCache::printStats() const {
451 SkDebugf("Budget: %d items %d bytes\n", fMaxCount, fMaxBytes);
452 SkDebugf("\t\tEntry Count: current %d high %d\n",
453 fEntryCount, fHighWaterEntryCount);
454 SkDebugf("\t\tUnlocked Entry Count: current %d high %d\n",
455 fUnlockedEntryCount, fHighWaterUnlockedEntryCount);
456 SkDebugf("\t\tEntry Bytes: current %d high %d\n",
457 fEntryBytes, fHighWaterEntryBytes);
458 SkDebugf("\t\tDetached Entry Count: current %d high %d\n",
459 fClientDetachedCount, fHighWaterClientDetachedCount);
460 SkDebugf("\t\tDetached Bytes: current %d high %d\n",
461 fClientDetachedBytes, fHighWaterClientDetachedBytes);
462}
463
reed@google.comac10a2d2010-12-22 21:39:39 +0000464#endif