blob: 20b82eceae5e707e84163740394985b5ec0d6f8e [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
bsalomon@google.com50398bf2011-07-26 20:45:30 +00009#include "GrResourceCache.h"
bsalomon6d3fe022014-07-25 08:35:45 -070010#include "GrGpuResource.h"
bsalomonbcf0a522014-10-08 08:40:09 -070011#include "GrTexturePriv.h"
12
commit-bot@chromium.orgc6658042014-01-15 23:09:01 +000013DECLARE_SKMESSAGEBUS_MESSAGE(GrResourceInvalidatedMessage);
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000014
commit-bot@chromium.org11c6b392014-05-05 19:09:13 +000015///////////////////////////////////////////////////////////////////////////////
16
bsalomon6d3fe022014-07-25 08:35:45 -070017void GrGpuResource::didChangeGpuMemorySize() const {
commit-bot@chromium.org11c6b392014-05-05 19:09:13 +000018 if (this->isInCache()) {
19 fCacheEntry->didChangeResourceSize();
20 }
21}
22
23///////////////////////////////////////////////////////////////////////////////
24
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000025GrResourceKey::ResourceType GrResourceKey::GenerateResourceType() {
26 static int32_t gNextType = 0;
27
28 int32_t type = sk_atomic_inc(&gNextType);
29 if (type >= (1 << 8 * sizeof(ResourceType))) {
commit-bot@chromium.org88cb22b2014-04-30 14:17:00 +000030 SkFAIL("Too many Resource Types");
bsalomon@google.com0797c2c2012-12-20 15:13:01 +000031 }
32
33 return static_cast<ResourceType>(type);
34}
35
36///////////////////////////////////////////////////////////////////////////////
37
bsalomon6d4488c2014-11-11 07:27:16 -080038GrResourceCacheEntry::GrResourceCacheEntry(GrResourceCache* resourceCache, GrGpuResource* resource)
commit-bot@chromium.org11c6b392014-05-05 19:09:13 +000039 : fResourceCache(resourceCache),
commit-bot@chromium.org11c6b392014-05-05 19:09:13 +000040 fResource(resource),
bsalomon6d4488c2014-11-11 07:27:16 -080041 fCachedSize(resource->gpuMemorySize()) {
bsalomon@google.com50398bf2011-07-26 20:45:30 +000042 // we assume ownership of the resource, and will unref it when we die
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000043 SkASSERT(resource);
skia.committer@gmail.com6c778162012-09-06 02:01:13 +000044 resource->ref();
reed@google.comac10a2d2010-12-22 21:39:39 +000045}
46
commit-bot@chromium.org089a7802014-05-02 21:38:22 +000047GrResourceCacheEntry::~GrResourceCacheEntry() {
bsalomon8b79d232014-11-10 10:19:06 -080048 // We're relying on having the cache entry to remove this from GrResourceCache2's content hash.
49 // fResource->setCacheEntry(NULL);
bsalomon@google.com50398bf2011-07-26 20:45:30 +000050 fResource->unref();
reed@google.comac10a2d2010-12-22 21:39:39 +000051}
52
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +000053#ifdef SK_DEBUG
commit-bot@chromium.org089a7802014-05-02 21:38:22 +000054void GrResourceCacheEntry::validate() const {
commit-bot@chromium.org11c6b392014-05-05 19:09:13 +000055 SkASSERT(fResourceCache);
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +000056 SkASSERT(fResource);
57 SkASSERT(fResource->getCacheEntry() == this);
commit-bot@chromium.org11c6b392014-05-05 19:09:13 +000058 SkASSERT(fResource->gpuMemorySize() == fCachedSize);
bsalomon@google.com50398bf2011-07-26 20:45:30 +000059 fResource->validate();
reed@google.comac10a2d2010-12-22 21:39:39 +000060}
61#endif
62
commit-bot@chromium.org11c6b392014-05-05 19:09:13 +000063void GrResourceCacheEntry::didChangeResourceSize() {
64 size_t oldSize = fCachedSize;
65 fCachedSize = fResource->gpuMemorySize();
66 if (fCachedSize > oldSize) {
67 fResourceCache->didIncreaseResourceSize(this, fCachedSize - oldSize);
68 } else if (fCachedSize < oldSize) {
69 fResourceCache->didDecreaseResourceSize(this, oldSize - fCachedSize);
70 }
71}
72
reed@google.comac10a2d2010-12-22 21:39:39 +000073///////////////////////////////////////////////////////////////////////////////
74
bsalomonbcf0a522014-10-08 08:40:09 -070075GrResourceCache::GrResourceCache(const GrDrawTargetCaps* caps, int maxCount, size_t maxBytes)
76 : fMaxCount(maxCount)
77 , fMaxBytes(maxBytes)
78 , fCaps(SkRef(caps)) {
robertphillips@google.com59552022012-08-31 13:07:37 +000079#if GR_CACHE_STATS
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +000080 fHighWaterEntryCount = 0;
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +000081 fHighWaterEntryBytes = 0;
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +000082#endif
83
84 fEntryCount = 0;
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +000085 fEntryBytes = 0;
reed@google.comac10a2d2010-12-22 21:39:39 +000086
commit-bot@chromium.orgcae27fe2013-07-10 10:14:35 +000087 fPurging = false;
88
89 fOverbudgetCB = NULL;
90 fOverbudgetData = NULL;
reed@google.comac10a2d2010-12-22 21:39:39 +000091}
92
bsalomon@google.com50398bf2011-07-26 20:45:30 +000093GrResourceCache::~GrResourceCache() {
94 GrAutoResourceCacheValidate atcv(this);
reed@google.com01804b42011-01-18 21:50:41 +000095
bsalomon@google.coma2921122012-08-28 12:34:17 +000096 EntryList::Iter iter;
97
98 // Unlike the removeAll, here we really remove everything, including locked resources.
commit-bot@chromium.org089a7802014-05-02 21:38:22 +000099 while (GrResourceCacheEntry* entry = fList.head()) {
bsalomon@google.coma2921122012-08-28 12:34:17 +0000100 GrAutoResourceCacheValidate atcv(this);
101
bsalomon@google.coma2921122012-08-28 12:34:17 +0000102 // remove from our llist
robertphillips@google.com209a1142012-10-31 12:25:21 +0000103 this->internalDetach(entry);
bsalomon@google.coma2921122012-08-28 12:34:17 +0000104
105 delete entry;
106 }
reed@google.comac10a2d2010-12-22 21:39:39 +0000107}
108
bsalomon@google.com07fc0d12012-06-22 15:15:59 +0000109void GrResourceCache::getLimits(int* maxResources, size_t* maxResourceBytes) const{
bsalomon49f085d2014-09-05 13:34:00 -0700110 if (maxResources) {
bsalomon@google.com07fc0d12012-06-22 15:15:59 +0000111 *maxResources = fMaxCount;
112 }
bsalomon49f085d2014-09-05 13:34:00 -0700113 if (maxResourceBytes) {
bsalomon@google.com07fc0d12012-06-22 15:15:59 +0000114 *maxResourceBytes = fMaxBytes;
115 }
116}
reed@google.com01804b42011-01-18 21:50:41 +0000117
bsalomon@google.com07fc0d12012-06-22 15:15:59 +0000118void GrResourceCache::setLimits(int maxResources, size_t maxResourceBytes) {
119 bool smaller = (maxResources < fMaxCount) || (maxResourceBytes < fMaxBytes);
120
121 fMaxCount = maxResources;
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000122 fMaxBytes = maxResourceBytes;
reed@google.com01804b42011-01-18 21:50:41 +0000123
124 if (smaller) {
125 this->purgeAsNeeded();
126 }
127}
128
bsalomonbcf0a522014-10-08 08:40:09 -0700129void GrResourceCache::internalDetach(GrResourceCacheEntry* entry) {
robertphillips@google.com521eaf82012-08-22 11:03:19 +0000130 fList.remove(entry);
bsalomonbcf0a522014-10-08 08:40:09 -0700131 fEntryCount -= 1;
132 fEntryBytes -= entry->fCachedSize;
Brian Salomon9323b8b2014-10-07 15:07:38 -0400133}
134
bsalomonbcf0a522014-10-08 08:40:09 -0700135void GrResourceCache::attachToHead(GrResourceCacheEntry* entry) {
Brian Salomon9323b8b2014-10-07 15:07:38 -0400136 fList.addToHead(entry);
137
bsalomonbcf0a522014-10-08 08:40:09 -0700138 fEntryCount += 1;
139 fEntryBytes += entry->fCachedSize;
Brian Salomon9323b8b2014-10-07 15:07:38 -0400140
141#if GR_CACHE_STATS
bsalomonbcf0a522014-10-08 08:40:09 -0700142 if (fHighWaterEntryCount < fEntryCount) {
143 fHighWaterEntryCount = fEntryCount;
Brian Salomon9323b8b2014-10-07 15:07:38 -0400144 }
bsalomonbcf0a522014-10-08 08:40:09 -0700145 if (fHighWaterEntryBytes < fEntryBytes) {
146 fHighWaterEntryBytes = fEntryBytes;
147 }
148#endif
reed@google.comac10a2d2010-12-22 21:39:39 +0000149}
150
bsalomonbcf0a522014-10-08 08:40:09 -0700151
152void GrResourceCache::makeResourceMRU(GrGpuResource* resource) {
153 GrResourceCacheEntry* entry = resource->getCacheEntry();
154 if (entry) {
155 this->internalDetach(entry);
156 this->attachToHead(entry);
157 }
158}
159
160void GrResourceCache::notifyPurgable(const GrGpuResource* resource) {
161 // Remove scratch textures from the cache the moment they become purgeable if
162 // scratch texture reuse is turned off.
163 SkASSERT(resource->getCacheEntry());
bsalomon6d4488c2014-11-11 07:27:16 -0800164 if (resource->isScratch()) {
165 const GrResourceKey& key = resource->getScratchKey();
166 if (key.getResourceType() == GrTexturePriv::ResourceType() &&
167 !fCaps->reuseScratchTextures() &&
168 !(static_cast<const GrSurface*>(resource)->desc().fFlags & kRenderTarget_GrSurfaceFlag)) {
169 this->deleteResource(resource->getCacheEntry());
170 }
bsalomonbcf0a522014-10-08 08:40:09 -0700171 }
172}
173
bsalomon8b79d232014-11-10 10:19:06 -0800174bool GrResourceCache::addResource(const GrResourceKey& key, GrGpuResource* resource) {
175 if (NULL != resource->getCacheEntry()) {
176 return false;
robertphillips@google.coma9b06232012-08-30 11:06:31 +0000177 }
bsalomon6d4488c2014-11-11 07:27:16 -0800178
179 if (key.isScratch()) {
180 SkASSERT(resource->isScratch() && key == resource->getScratchKey());
181 } else {
182 if (!resource->setContentKey(key)) {
183 return false;
184 }
185 }
robertphillips@google.coma9b06232012-08-30 11:06:31 +0000186
bsalomon@google.coma5a1da82011-08-05 14:02:41 +0000187 // we don't expect to create new resources during a purge. In theory
188 // this could cause purgeAsNeeded() into an infinite loop (e.g.
189 // each resource destroyed creates and locks 2 resources and
190 // unlocks 1 thereby causing a new purge).
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000191 SkASSERT(!fPurging);
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000192 GrAutoResourceCacheValidate atcv(this);
reed@google.comac10a2d2010-12-22 21:39:39 +0000193
bsalomon6d4488c2014-11-11 07:27:16 -0800194 GrResourceCacheEntry* entry = SkNEW_ARGS(GrResourceCacheEntry, (this, resource));
195 resource->setCacheEntry(entry);
robertphillips@google.com1f47f4f2012-08-16 14:49:16 +0000196
robertphillips@google.com209a1142012-10-31 12:25:21 +0000197 this->attachToHead(entry);
bsalomonbcf0a522014-10-08 08:40:09 -0700198 this->purgeAsNeeded();
bsalomon8b79d232014-11-10 10:19:06 -0800199 return true;
reed@google.comac10a2d2010-12-22 21:39:39 +0000200}
201
commit-bot@chromium.org11c6b392014-05-05 19:09:13 +0000202void GrResourceCache::didIncreaseResourceSize(const GrResourceCacheEntry* entry, size_t amountInc) {
203 fEntryBytes += amountInc;
commit-bot@chromium.org11c6b392014-05-05 19:09:13 +0000204 this->purgeAsNeeded();
205}
206
207void GrResourceCache::didDecreaseResourceSize(const GrResourceCacheEntry* entry, size_t amountDec) {
208 fEntryBytes -= amountDec;
commit-bot@chromium.org11c6b392014-05-05 19:09:13 +0000209#ifdef SK_DEBUG
210 this->validate();
211#endif
212}
213
bsalomon@google.coma5a1da82011-08-05 14:02:41 +0000214/**
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000215 * Destroying a resource may potentially trigger the unlock of additional
bsalomon@google.coma5a1da82011-08-05 14:02:41 +0000216 * resources which in turn will trigger a nested purge. We block the nested
217 * purge using the fPurging variable. However, the initial purge will keep
218 * looping until either all resources in the cache are unlocked or we've met
219 * the budget. There is an assertion in createAndLock to check against a
220 * resource's destructor inserting new resources into the cache. If these
221 * new resources were unlocked before purgeAsNeeded completed it could
222 * potentially make purgeAsNeeded loop infinitely.
robertphillips@google.com41d25322013-07-18 17:12:57 +0000223 *
224 * extraCount and extraBytes are added to the current resource totals to account
225 * for incoming resources (e.g., GrContext is about to add 10MB split between
226 * 10 textures).
bsalomon@google.coma5a1da82011-08-05 14:02:41 +0000227 */
robertphillips@google.com41d25322013-07-18 17:12:57 +0000228void GrResourceCache::purgeAsNeeded(int extraCount, size_t extraBytes) {
commit-bot@chromium.orgcae27fe2013-07-10 10:14:35 +0000229 if (fPurging) {
230 return;
reed@google.comac10a2d2010-12-22 21:39:39 +0000231 }
commit-bot@chromium.orgcae27fe2013-07-10 10:14:35 +0000232
233 fPurging = true;
234
robertphillips@google.com41d25322013-07-18 17:12:57 +0000235 this->internalPurge(extraCount, extraBytes);
skia.committer@gmail.coma7991982013-07-19 07:00:57 +0000236 if (((fEntryCount+extraCount) > fMaxCount ||
robertphillips@google.com41d25322013-07-18 17:12:57 +0000237 (fEntryBytes+extraBytes) > fMaxBytes) &&
bsalomon49f085d2014-09-05 13:34:00 -0700238 fOverbudgetCB) {
commit-bot@chromium.orgcae27fe2013-07-10 10:14:35 +0000239 // Despite the purge we're still over budget. See if Ganesh can
240 // release some resources and purge again.
241 if ((*fOverbudgetCB)(fOverbudgetData)) {
robertphillips@google.com41d25322013-07-18 17:12:57 +0000242 this->internalPurge(extraCount, extraBytes);
commit-bot@chromium.orgcae27fe2013-07-10 10:14:35 +0000243 }
244 }
245
246 fPurging = false;
247}
248
commit-bot@chromium.org50a30432013-10-24 17:44:27 +0000249void GrResourceCache::purgeInvalidated() {
bsalomon6d4488c2014-11-11 07:27:16 -0800250 // TODO: Implement this in GrResourceCache2.
commit-bot@chromium.org50a30432013-10-24 17:44:27 +0000251}
252
commit-bot@chromium.org089a7802014-05-02 21:38:22 +0000253void GrResourceCache::deleteResource(GrResourceCacheEntry* entry) {
bsalomonbcf0a522014-10-08 08:40:09 -0700254 SkASSERT(entry->fResource->isPurgable());
robertphillips@google.come4eaea22013-07-19 16:51:46 +0000255 // remove from our llist
256 this->internalDetach(entry);
257 delete entry;
258}
259
robertphillips@google.com41d25322013-07-18 17:12:57 +0000260void GrResourceCache::internalPurge(int extraCount, size_t extraBytes) {
commit-bot@chromium.orgcae27fe2013-07-10 10:14:35 +0000261 SkASSERT(fPurging);
262
263 bool withinBudget = false;
264 bool changed = false;
265
266 // The purging process is repeated several times since one pass
267 // may free up other resources
268 do {
269 EntryList::Iter iter;
270
271 changed = false;
272
273 // Note: the following code relies on the fact that the
274 // doubly linked list doesn't invalidate its data/pointers
275 // outside of the specific area where a deletion occurs (e.g.,
276 // in internalDetach)
commit-bot@chromium.org089a7802014-05-02 21:38:22 +0000277 GrResourceCacheEntry* entry = iter.init(fList, EntryList::Iter::kTail_IterStart);
commit-bot@chromium.orgcae27fe2013-07-10 10:14:35 +0000278
bsalomon49f085d2014-09-05 13:34:00 -0700279 while (entry) {
commit-bot@chromium.orgcae27fe2013-07-10 10:14:35 +0000280 GrAutoResourceCacheValidate atcv(this);
281
skia.committer@gmail.coma7991982013-07-19 07:00:57 +0000282 if ((fEntryCount+extraCount) <= fMaxCount &&
robertphillips@google.com41d25322013-07-18 17:12:57 +0000283 (fEntryBytes+extraBytes) <= fMaxBytes) {
commit-bot@chromium.orgcae27fe2013-07-10 10:14:35 +0000284 withinBudget = true;
285 break;
286 }
287
commit-bot@chromium.org089a7802014-05-02 21:38:22 +0000288 GrResourceCacheEntry* prev = iter.prev();
bsalomonbcf0a522014-10-08 08:40:09 -0700289 if (entry->fResource->isPurgable()) {
commit-bot@chromium.orgcae27fe2013-07-10 10:14:35 +0000290 changed = true;
robertphillips@google.come4eaea22013-07-19 16:51:46 +0000291 this->deleteResource(entry);
commit-bot@chromium.orgcae27fe2013-07-10 10:14:35 +0000292 }
293 entry = prev;
294 }
295 } while (!withinBudget && changed);
reed@google.comac10a2d2010-12-22 21:39:39 +0000296}
297
bsalomon@google.coma2921122012-08-28 12:34:17 +0000298void GrResourceCache::purgeAllUnlocked() {
bsalomon@google.come9a98942011-08-22 17:06:16 +0000299 GrAutoResourceCacheValidate atcv(this);
reed@google.com01804b42011-01-18 21:50:41 +0000300
commit-bot@chromium.org089a7802014-05-02 21:38:22 +0000301 // we can have one GrCacheable holding a lock on another
bsalomon@google.come9a98942011-08-22 17:06:16 +0000302 // so we don't want to just do a simple loop kicking each
303 // entry out. Instead change the budget and purge.
reed@google.comac10a2d2010-12-22 21:39:39 +0000304
robertphillips@google.comadacc702013-10-14 21:53:24 +0000305 size_t savedMaxBytes = fMaxBytes;
bsalomon@google.com07fc0d12012-06-22 15:15:59 +0000306 int savedMaxCount = fMaxCount;
307 fMaxBytes = (size_t) -1;
308 fMaxCount = 0;
bsalomon@google.come9a98942011-08-22 17:06:16 +0000309 this->purgeAsNeeded();
310
bsalomon@google.come9a98942011-08-22 17:06:16 +0000311 fMaxBytes = savedMaxBytes;
bsalomon@google.com07fc0d12012-06-22 15:15:59 +0000312 fMaxCount = savedMaxCount;
reed@google.comac10a2d2010-12-22 21:39:39 +0000313}
314
315///////////////////////////////////////////////////////////////////////////////
316
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000317#ifdef SK_DEBUG
bsalomon@google.coma2921122012-08-28 12:34:17 +0000318size_t GrResourceCache::countBytes(const EntryList& list) {
robertphillips@google.com2ea0a232012-08-23 11:13:48 +0000319 size_t bytes = 0;
320
bsalomon@google.coma2921122012-08-28 12:34:17 +0000321 EntryList::Iter iter;
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000322
commit-bot@chromium.org089a7802014-05-02 21:38:22 +0000323 const GrResourceCacheEntry* entry = iter.init(const_cast<EntryList&>(list),
324 EntryList::Iter::kTail_IterStart);
robertphillips@google.com2ea0a232012-08-23 11:13:48 +0000325
bsalomon49f085d2014-09-05 13:34:00 -0700326 for ( ; entry; entry = iter.prev()) {
commit-bot@chromium.org089a7802014-05-02 21:38:22 +0000327 bytes += entry->resource()->gpuMemorySize();
reed@google.comac10a2d2010-12-22 21:39:39 +0000328 }
robertphillips@google.com2ea0a232012-08-23 11:13:48 +0000329 return bytes;
reed@google.comac10a2d2010-12-22 21:39:39 +0000330}
331
reed@google.comb89a6432011-02-07 13:20:30 +0000332static bool both_zero_or_nonzero(int count, size_t bytes) {
333 return (count == 0 && bytes == 0) || (count > 0 && bytes > 0);
334}
reed@google.comb89a6432011-02-07 13:20:30 +0000335
bsalomon@google.com50398bf2011-07-26 20:45:30 +0000336void GrResourceCache::validate() const {
robertphillips@google.com2ea0a232012-08-23 11:13:48 +0000337 fList.validate();
tfarina@chromium.orgf6de4752013-08-17 00:02:59 +0000338 SkASSERT(both_zero_or_nonzero(fEntryCount, fEntryBytes));
reed@google.com01804b42011-01-18 21:50:41 +0000339
bsalomon@google.coma2921122012-08-28 12:34:17 +0000340 EntryList::Iter iter;
rmistry@google.comfbfcd562012-08-23 18:09:54 +0000341
Brian Salomon9323b8b2014-10-07 15:07:38 -0400342 // check that the shareable entries are okay
bsalomonbcf0a522014-10-08 08:40:09 -0700343 const GrResourceCacheEntry* entry = iter.init(const_cast<EntryList&>(fList),
344 EntryList::Iter::kHead_IterStart);
Brian Salomon9323b8b2014-10-07 15:07:38 -0400345
robertphillips@google.comd07cb0c2012-08-30 19:22:29 +0000346 int count = 0;
bsalomon49f085d2014-09-05 13:34:00 -0700347 for ( ; entry; entry = iter.next()) {
robertphillips@google.comd07cb0c2012-08-30 19:22:29 +0000348 entry->validate();
reed@google.comac10a2d2010-12-22 21:39:39 +0000349 count += 1;
reed@google.comac10a2d2010-12-22 21:39:39 +0000350 }
bsalomonbcf0a522014-10-08 08:40:09 -0700351 SkASSERT(count == fEntryCount);
robertphillips@google.com521eaf82012-08-22 11:03:19 +0000352
bsalomonbcf0a522014-10-08 08:40:09 -0700353 size_t bytes = this->countBytes(fList);
354 SkASSERT(bytes == fEntryBytes);
355 SkASSERT(fList.countEntries() == fEntryCount);
reed@google.comac10a2d2010-12-22 21:39:39 +0000356}
commit-bot@chromium.org515dcd32013-08-28 14:17:03 +0000357#endif // SK_DEBUG
robertphillips@google.com59552022012-08-31 13:07:37 +0000358
359#if GR_CACHE_STATS
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +0000360
robertphillips@google.com9fbcad02012-09-09 14:44:15 +0000361void GrResourceCache::printStats() {
362 int locked = 0;
bsalomon24234fe2014-10-24 09:34:41 -0700363 int scratch = 0;
robertphillips@google.com9fbcad02012-09-09 14:44:15 +0000364
365 EntryList::Iter iter;
366
commit-bot@chromium.org089a7802014-05-02 21:38:22 +0000367 GrResourceCacheEntry* entry = iter.init(fList, EntryList::Iter::kTail_IterStart);
robertphillips@google.com9fbcad02012-09-09 14:44:15 +0000368
bsalomon49f085d2014-09-05 13:34:00 -0700369 for ( ; entry; entry = iter.prev()) {
bsalomon24234fe2014-10-24 09:34:41 -0700370 if (!entry->fResource->isPurgable()) {
robertphillips@google.com9fbcad02012-09-09 14:44:15 +0000371 ++locked;
372 }
bsalomon24234fe2014-10-24 09:34:41 -0700373 if (entry->fResource->isScratch()) {
374 ++scratch;
375 }
robertphillips@google.com9fbcad02012-09-09 14:44:15 +0000376 }
377
bsalomon24234fe2014-10-24 09:34:41 -0700378 float countUtilization = (100.f * fEntryCount) / fMaxCount;
379 float byteUtilization = (100.f * fEntryBytes) / fMaxBytes;
380
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +0000381 SkDebugf("Budget: %d items %d bytes\n", fMaxCount, fMaxBytes);
bsalomon24234fe2014-10-24 09:34:41 -0700382 SkDebugf("\t\tEntry Count: current %d (%d locked, %d scratch %.2g%% full), high %d\n",
383 fEntryCount, locked, scratch, countUtilization, fHighWaterEntryCount);
384 SkDebugf("\t\tEntry Bytes: current %d (%.2g%% full) high %d\n",
385 fEntryBytes, byteUtilization, fHighWaterEntryBytes);
robertphillips@google.com5f9f2f52012-08-22 10:57:05 +0000386}
387
reed@google.comac10a2d2010-12-22 21:39:39 +0000388#endif
robertphillips@google.com521eaf82012-08-22 11:03:19 +0000389
390///////////////////////////////////////////////////////////////////////////////