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" |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 12 | #include "GrCacheable.h" |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 13 | |
commit-bot@chromium.org | c665804 | 2014-01-15 23:09:01 +0000 | [diff] [blame] | 14 | DECLARE_SKMESSAGEBUS_MESSAGE(GrResourceInvalidatedMessage); |
bsalomon@google.com | 0797c2c | 2012-12-20 15:13:01 +0000 | [diff] [blame] | 15 | |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 16 | /////////////////////////////////////////////////////////////////////////////// |
| 17 | |
| 18 | void GrCacheable::didChangeGpuMemorySize() const { |
| 19 | if (this->isInCache()) { |
| 20 | fCacheEntry->didChangeResourceSize(); |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | /////////////////////////////////////////////////////////////////////////////// |
| 25 | |
bsalomon@google.com | 0797c2c | 2012-12-20 15:13:01 +0000 | [diff] [blame] | 26 | GrResourceKey::ResourceType GrResourceKey::GenerateResourceType() { |
| 27 | static int32_t gNextType = 0; |
| 28 | |
| 29 | int32_t type = sk_atomic_inc(&gNextType); |
| 30 | if (type >= (1 << 8 * sizeof(ResourceType))) { |
commit-bot@chromium.org | 88cb22b | 2014-04-30 14:17:00 +0000 | [diff] [blame] | 31 | SkFAIL("Too many Resource Types"); |
bsalomon@google.com | 0797c2c | 2012-12-20 15:13:01 +0000 | [diff] [blame] | 32 | } |
| 33 | |
| 34 | return static_cast<ResourceType>(type); |
| 35 | } |
| 36 | |
| 37 | /////////////////////////////////////////////////////////////////////////////// |
| 38 | |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 39 | GrResourceCacheEntry::GrResourceCacheEntry(GrResourceCache* resourceCache, |
| 40 | const GrResourceKey& key, |
| 41 | GrCacheable* resource) |
| 42 | : fResourceCache(resourceCache), |
| 43 | fKey(key), |
| 44 | fResource(resource), |
| 45 | fCachedSize(resource->gpuMemorySize()), |
| 46 | fIsExclusive(false) { |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 47 | // we assume ownership of the resource, and will unref it when we die |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 48 | SkASSERT(resource); |
skia.committer@gmail.com | 6c77816 | 2012-09-06 02:01:13 +0000 | [diff] [blame] | 49 | resource->ref(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 50 | } |
| 51 | |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 52 | GrResourceCacheEntry::~GrResourceCacheEntry() { |
robertphillips@google.com | 521eaf8 | 2012-08-22 11:03:19 +0000 | [diff] [blame] | 53 | fResource->setCacheEntry(NULL); |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 54 | fResource->unref(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 55 | } |
| 56 | |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 57 | #ifdef SK_DEBUG |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 58 | void GrResourceCacheEntry::validate() const { |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 59 | SkASSERT(fResourceCache); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 60 | SkASSERT(fResource); |
| 61 | SkASSERT(fResource->getCacheEntry() == this); |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 62 | SkASSERT(fResource->gpuMemorySize() == fCachedSize); |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 63 | fResource->validate(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 64 | } |
| 65 | #endif |
| 66 | |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 67 | void GrResourceCacheEntry::didChangeResourceSize() { |
| 68 | size_t oldSize = fCachedSize; |
| 69 | fCachedSize = fResource->gpuMemorySize(); |
| 70 | if (fCachedSize > oldSize) { |
| 71 | fResourceCache->didIncreaseResourceSize(this, fCachedSize - oldSize); |
| 72 | } else if (fCachedSize < oldSize) { |
| 73 | fResourceCache->didDecreaseResourceSize(this, oldSize - fCachedSize); |
| 74 | } |
| 75 | } |
| 76 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 77 | /////////////////////////////////////////////////////////////////////////////// |
| 78 | |
bsalomon@google.com | 07fc0d1 | 2012-06-22 15:15:59 +0000 | [diff] [blame] | 79 | GrResourceCache::GrResourceCache(int maxCount, size_t maxBytes) : |
| 80 | fMaxCount(maxCount), |
| 81 | fMaxBytes(maxBytes) { |
robertphillips@google.com | 5955202 | 2012-08-31 13:07:37 +0000 | [diff] [blame] | 82 | #if GR_CACHE_STATS |
robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 83 | fHighWaterEntryCount = 0; |
robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 84 | fHighWaterEntryBytes = 0; |
| 85 | fHighWaterClientDetachedCount = 0; |
| 86 | fHighWaterClientDetachedBytes = 0; |
| 87 | #endif |
| 88 | |
| 89 | fEntryCount = 0; |
robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 90 | fEntryBytes = 0; |
| 91 | fClientDetachedCount = 0; |
| 92 | fClientDetachedBytes = 0; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 93 | |
commit-bot@chromium.org | cae27fe | 2013-07-10 10:14:35 +0000 | [diff] [blame] | 94 | fPurging = false; |
| 95 | |
| 96 | fOverbudgetCB = NULL; |
| 97 | fOverbudgetData = NULL; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 98 | } |
| 99 | |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 100 | GrResourceCache::~GrResourceCache() { |
| 101 | GrAutoResourceCacheValidate atcv(this); |
reed@google.com | 01804b4 | 2011-01-18 21:50:41 +0000 | [diff] [blame] | 102 | |
bsalomon@google.com | a292112 | 2012-08-28 12:34:17 +0000 | [diff] [blame] | 103 | EntryList::Iter iter; |
| 104 | |
| 105 | // Unlike the removeAll, here we really remove everything, including locked resources. |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 106 | while (GrResourceCacheEntry* entry = fList.head()) { |
bsalomon@google.com | a292112 | 2012-08-28 12:34:17 +0000 | [diff] [blame] | 107 | GrAutoResourceCacheValidate atcv(this); |
| 108 | |
| 109 | // remove from our cache |
| 110 | fCache.remove(entry->fKey, entry); |
| 111 | |
| 112 | // remove from our llist |
robertphillips@google.com | 209a114 | 2012-10-31 12:25:21 +0000 | [diff] [blame] | 113 | this->internalDetach(entry); |
bsalomon@google.com | a292112 | 2012-08-28 12:34:17 +0000 | [diff] [blame] | 114 | |
| 115 | delete entry; |
| 116 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 117 | } |
| 118 | |
bsalomon@google.com | 07fc0d1 | 2012-06-22 15:15:59 +0000 | [diff] [blame] | 119 | void GrResourceCache::getLimits(int* maxResources, size_t* maxResourceBytes) const{ |
robertphillips@google.com | e4eaea2 | 2013-07-19 16:51:46 +0000 | [diff] [blame] | 120 | if (NULL != maxResources) { |
bsalomon@google.com | 07fc0d1 | 2012-06-22 15:15:59 +0000 | [diff] [blame] | 121 | *maxResources = fMaxCount; |
| 122 | } |
robertphillips@google.com | e4eaea2 | 2013-07-19 16:51:46 +0000 | [diff] [blame] | 123 | if (NULL != maxResourceBytes) { |
bsalomon@google.com | 07fc0d1 | 2012-06-22 15:15:59 +0000 | [diff] [blame] | 124 | *maxResourceBytes = fMaxBytes; |
| 125 | } |
| 126 | } |
reed@google.com | 01804b4 | 2011-01-18 21:50:41 +0000 | [diff] [blame] | 127 | |
bsalomon@google.com | 07fc0d1 | 2012-06-22 15:15:59 +0000 | [diff] [blame] | 128 | void GrResourceCache::setLimits(int maxResources, size_t maxResourceBytes) { |
| 129 | bool smaller = (maxResources < fMaxCount) || (maxResourceBytes < fMaxBytes); |
| 130 | |
| 131 | fMaxCount = maxResources; |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 132 | fMaxBytes = maxResourceBytes; |
reed@google.com | 01804b4 | 2011-01-18 21:50:41 +0000 | [diff] [blame] | 133 | |
| 134 | if (smaller) { |
| 135 | this->purgeAsNeeded(); |
| 136 | } |
| 137 | } |
| 138 | |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 139 | void GrResourceCache::internalDetach(GrResourceCacheEntry* entry, |
robertphillips@google.com | 209a114 | 2012-10-31 12:25:21 +0000 | [diff] [blame] | 140 | BudgetBehaviors behavior) { |
robertphillips@google.com | 521eaf8 | 2012-08-22 11:03:19 +0000 | [diff] [blame] | 141 | fList.remove(entry); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 142 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 143 | // update our stats |
robertphillips@google.com | 209a114 | 2012-10-31 12:25:21 +0000 | [diff] [blame] | 144 | if (kIgnore_BudgetBehavior == behavior) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 145 | fClientDetachedCount += 1; |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 146 | fClientDetachedBytes += entry->fCachedSize; |
robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 147 | |
robertphillips@google.com | 5955202 | 2012-08-31 13:07:37 +0000 | [diff] [blame] | 148 | #if GR_CACHE_STATS |
robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 149 | if (fHighWaterClientDetachedCount < fClientDetachedCount) { |
| 150 | fHighWaterClientDetachedCount = fClientDetachedCount; |
| 151 | } |
| 152 | if (fHighWaterClientDetachedBytes < fClientDetachedBytes) { |
| 153 | fHighWaterClientDetachedBytes = fClientDetachedBytes; |
| 154 | } |
| 155 | #endif |
| 156 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 157 | } else { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 158 | SkASSERT(kAccountFor_BudgetBehavior == behavior); |
robertphillips@google.com | 209a114 | 2012-10-31 12:25:21 +0000 | [diff] [blame] | 159 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 160 | fEntryCount -= 1; |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 161 | fEntryBytes -= entry->fCachedSize; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 162 | } |
| 163 | } |
| 164 | |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 165 | void GrResourceCache::attachToHead(GrResourceCacheEntry* entry, |
robertphillips@google.com | 209a114 | 2012-10-31 12:25:21 +0000 | [diff] [blame] | 166 | BudgetBehaviors behavior) { |
robertphillips@google.com | 521eaf8 | 2012-08-22 11:03:19 +0000 | [diff] [blame] | 167 | fList.addToHead(entry); |
| 168 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 169 | // update our stats |
robertphillips@google.com | 209a114 | 2012-10-31 12:25:21 +0000 | [diff] [blame] | 170 | if (kIgnore_BudgetBehavior == behavior) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 171 | fClientDetachedCount -= 1; |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 172 | fClientDetachedBytes -= entry->fCachedSize; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 173 | } else { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 174 | SkASSERT(kAccountFor_BudgetBehavior == behavior); |
robertphillips@google.com | 209a114 | 2012-10-31 12:25:21 +0000 | [diff] [blame] | 175 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 176 | fEntryCount += 1; |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 177 | fEntryBytes += entry->fCachedSize; |
robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 178 | |
robertphillips@google.com | 5955202 | 2012-08-31 13:07:37 +0000 | [diff] [blame] | 179 | #if GR_CACHE_STATS |
robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 180 | if (fHighWaterEntryCount < fEntryCount) { |
| 181 | fHighWaterEntryCount = fEntryCount; |
| 182 | } |
| 183 | if (fHighWaterEntryBytes < fEntryBytes) { |
| 184 | fHighWaterEntryBytes = fEntryBytes; |
| 185 | } |
| 186 | #endif |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 187 | } |
| 188 | } |
| 189 | |
robertphillips@google.com | 209a114 | 2012-10-31 12:25:21 +0000 | [diff] [blame] | 190 | // This functor just searches for an entry with only a single ref (from |
| 191 | // the texture cache itself). Presumably in this situation no one else |
| 192 | // is relying on the texture. |
| 193 | class GrTFindUnreffedFunctor { |
| 194 | public: |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 195 | bool operator()(const GrResourceCacheEntry* entry) const { |
bungeman@google.com | f64c684 | 2013-07-19 23:18:52 +0000 | [diff] [blame] | 196 | return entry->resource()->unique(); |
robertphillips@google.com | 209a114 | 2012-10-31 12:25:21 +0000 | [diff] [blame] | 197 | } |
| 198 | }; |
| 199 | |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 200 | GrCacheable* GrResourceCache::find(const GrResourceKey& key, uint32_t ownershipFlags) { |
robertphillips@google.com | a9b0623 | 2012-08-30 11:06:31 +0000 | [diff] [blame] | 201 | GrAutoResourceCacheValidate atcv(this); |
| 202 | |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 203 | GrResourceCacheEntry* entry = NULL; |
robertphillips@google.com | 209a114 | 2012-10-31 12:25:21 +0000 | [diff] [blame] | 204 | |
| 205 | if (ownershipFlags & kNoOtherOwners_OwnershipFlag) { |
| 206 | GrTFindUnreffedFunctor functor; |
| 207 | |
| 208 | entry = fCache.find<GrTFindUnreffedFunctor>(key, functor); |
| 209 | } else { |
| 210 | entry = fCache.find(key); |
| 211 | } |
| 212 | |
robertphillips@google.com | a9b0623 | 2012-08-30 11:06:31 +0000 | [diff] [blame] | 213 | if (NULL == entry) { |
| 214 | return NULL; |
| 215 | } |
| 216 | |
robertphillips@google.com | 209a114 | 2012-10-31 12:25:21 +0000 | [diff] [blame] | 217 | if (ownershipFlags & kHide_OwnershipFlag) { |
| 218 | this->makeExclusive(entry); |
| 219 | } else { |
| 220 | // Make this resource MRU |
| 221 | this->internalDetach(entry); |
| 222 | this->attachToHead(entry); |
| 223 | } |
robertphillips@google.com | 1f47f4f | 2012-08-16 14:49:16 +0000 | [diff] [blame] | 224 | |
| 225 | return entry->fResource; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 226 | } |
| 227 | |
skia.committer@gmail.com | f3dc199 | 2012-11-01 02:01:27 +0000 | [diff] [blame] | 228 | void GrResourceCache::addResource(const GrResourceKey& key, |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 229 | GrCacheable* resource, |
robertphillips@google.com | 209a114 | 2012-10-31 12:25:21 +0000 | [diff] [blame] | 230 | uint32_t ownershipFlags) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 231 | SkASSERT(NULL == resource->getCacheEntry()); |
bsalomon@google.com | a5a1da8 | 2011-08-05 14:02:41 +0000 | [diff] [blame] | 232 | // we don't expect to create new resources during a purge. In theory |
| 233 | // this could cause purgeAsNeeded() into an infinite loop (e.g. |
| 234 | // each resource destroyed creates and locks 2 resources and |
| 235 | // unlocks 1 thereby causing a new purge). |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 236 | SkASSERT(!fPurging); |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 237 | GrAutoResourceCacheValidate atcv(this); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 238 | |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 239 | GrResourceCacheEntry* entry = SkNEW_ARGS(GrResourceCacheEntry, (this, key, resource)); |
robertphillips@google.com | 1f47f4f | 2012-08-16 14:49:16 +0000 | [diff] [blame] | 240 | resource->setCacheEntry(entry); |
| 241 | |
robertphillips@google.com | 209a114 | 2012-10-31 12:25:21 +0000 | [diff] [blame] | 242 | this->attachToHead(entry); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 243 | fCache.insert(key, entry); |
| 244 | |
robertphillips@google.com | 209a114 | 2012-10-31 12:25:21 +0000 | [diff] [blame] | 245 | if (ownershipFlags & kHide_OwnershipFlag) { |
| 246 | this->makeExclusive(entry); |
| 247 | } |
| 248 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 249 | } |
| 250 | |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 251 | void GrResourceCache::makeExclusive(GrResourceCacheEntry* entry) { |
bsalomon@google.com | e9a9894 | 2011-08-22 17:06:16 +0000 | [diff] [blame] | 252 | GrAutoResourceCacheValidate atcv(this); |
robertphillips@google.com | 521eaf8 | 2012-08-22 11:03:19 +0000 | [diff] [blame] | 253 | |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 254 | SkASSERT(!entry->fIsExclusive); |
| 255 | entry->fIsExclusive = true; |
| 256 | |
robertphillips@google.com | 209a114 | 2012-10-31 12:25:21 +0000 | [diff] [blame] | 257 | // When scratch textures are detached (to hide them from future finds) they |
| 258 | // still count against the resource budget |
| 259 | this->internalDetach(entry, kIgnore_BudgetBehavior); |
robertphillips@google.com | a9b0623 | 2012-08-30 11:06:31 +0000 | [diff] [blame] | 260 | fCache.remove(entry->key(), entry); |
robertphillips@google.com | 521eaf8 | 2012-08-22 11:03:19 +0000 | [diff] [blame] | 261 | |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 262 | #ifdef SK_DEBUG |
robertphillips@google.com | 521eaf8 | 2012-08-22 11:03:19 +0000 | [diff] [blame] | 263 | fExclusiveList.addToHead(entry); |
| 264 | #endif |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 265 | } |
| 266 | |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 267 | void GrResourceCache::removeInvalidResource(GrResourceCacheEntry* entry) { |
robertphillips@google.com | 521eaf8 | 2012-08-22 11:03:19 +0000 | [diff] [blame] | 268 | // If the resource went invalid while it was detached then purge it |
| 269 | // This can happen when a 3D context was lost, |
| 270 | // the client called GrContext::contextDestroyed() to notify Gr, |
| 271 | // and then later an SkGpuDevice's destructor releases its backing |
| 272 | // texture (which was invalidated at contextDestroyed time). |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 273 | // TODO: Safely delete the GrResourceCacheEntry as well. |
robertphillips@google.com | 521eaf8 | 2012-08-22 11:03:19 +0000 | [diff] [blame] | 274 | fClientDetachedCount -= 1; |
| 275 | fEntryCount -= 1; |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 276 | fClientDetachedBytes -= entry->fCachedSize; |
| 277 | fEntryBytes -= entry->fCachedSize; |
| 278 | entry->fCachedSize = 0; |
robertphillips@google.com | 15c0fea | 2012-06-22 12:41:43 +0000 | [diff] [blame] | 279 | } |
| 280 | |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 281 | void GrResourceCache::makeNonExclusive(GrResourceCacheEntry* entry) { |
bsalomon@google.com | 6087975 | 2011-09-15 20:43:53 +0000 | [diff] [blame] | 282 | GrAutoResourceCacheValidate atcv(this); |
robertphillips@google.com | 521eaf8 | 2012-08-22 11:03:19 +0000 | [diff] [blame] | 283 | |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 284 | #ifdef SK_DEBUG |
robertphillips@google.com | 521eaf8 | 2012-08-22 11:03:19 +0000 | [diff] [blame] | 285 | fExclusiveList.remove(entry); |
| 286 | #endif |
| 287 | |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 288 | if (entry->resource()->isValidOnGpu()) { |
skia.committer@gmail.com | f3dc199 | 2012-11-01 02:01:27 +0000 | [diff] [blame] | 289 | // Since scratch textures still count against the cache budget even |
| 290 | // when they have been removed from the cache, re-adding them doesn't |
robertphillips@google.com | 209a114 | 2012-10-31 12:25:21 +0000 | [diff] [blame] | 291 | // alter the budget information. |
| 292 | attachToHead(entry, kIgnore_BudgetBehavior); |
bsalomon@google.com | 6087975 | 2011-09-15 20:43:53 +0000 | [diff] [blame] | 293 | fCache.insert(entry->key(), entry); |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 294 | |
| 295 | SkASSERT(entry->fIsExclusive); |
| 296 | entry->fIsExclusive = false; |
bsalomon@google.com | 6087975 | 2011-09-15 20:43:53 +0000 | [diff] [blame] | 297 | } else { |
robertphillips@google.com | 521eaf8 | 2012-08-22 11:03:19 +0000 | [diff] [blame] | 298 | this->removeInvalidResource(entry); |
bsalomon@google.com | 6087975 | 2011-09-15 20:43:53 +0000 | [diff] [blame] | 299 | } |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 300 | } |
| 301 | |
commit-bot@chromium.org | 11c6b39 | 2014-05-05 19:09:13 +0000 | [diff] [blame] | 302 | void GrResourceCache::didIncreaseResourceSize(const GrResourceCacheEntry* entry, size_t amountInc) { |
| 303 | fEntryBytes += amountInc; |
| 304 | if (entry->fIsExclusive) { |
| 305 | fClientDetachedBytes += amountInc; |
| 306 | } |
| 307 | this->purgeAsNeeded(); |
| 308 | } |
| 309 | |
| 310 | void GrResourceCache::didDecreaseResourceSize(const GrResourceCacheEntry* entry, size_t amountDec) { |
| 311 | fEntryBytes -= amountDec; |
| 312 | if (entry->fIsExclusive) { |
| 313 | fClientDetachedBytes -= amountDec; |
| 314 | } |
| 315 | #ifdef SK_DEBUG |
| 316 | this->validate(); |
| 317 | #endif |
| 318 | } |
| 319 | |
bsalomon@google.com | a5a1da8 | 2011-08-05 14:02:41 +0000 | [diff] [blame] | 320 | /** |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 321 | * Destroying a resource may potentially trigger the unlock of additional |
bsalomon@google.com | a5a1da8 | 2011-08-05 14:02:41 +0000 | [diff] [blame] | 322 | * resources which in turn will trigger a nested purge. We block the nested |
| 323 | * purge using the fPurging variable. However, the initial purge will keep |
| 324 | * looping until either all resources in the cache are unlocked or we've met |
| 325 | * the budget. There is an assertion in createAndLock to check against a |
| 326 | * resource's destructor inserting new resources into the cache. If these |
| 327 | * new resources were unlocked before purgeAsNeeded completed it could |
| 328 | * potentially make purgeAsNeeded loop infinitely. |
robertphillips@google.com | 41d2532 | 2013-07-18 17:12:57 +0000 | [diff] [blame] | 329 | * |
| 330 | * extraCount and extraBytes are added to the current resource totals to account |
| 331 | * for incoming resources (e.g., GrContext is about to add 10MB split between |
| 332 | * 10 textures). |
bsalomon@google.com | a5a1da8 | 2011-08-05 14:02:41 +0000 | [diff] [blame] | 333 | */ |
robertphillips@google.com | 41d2532 | 2013-07-18 17:12:57 +0000 | [diff] [blame] | 334 | void GrResourceCache::purgeAsNeeded(int extraCount, size_t extraBytes) { |
commit-bot@chromium.org | cae27fe | 2013-07-10 10:14:35 +0000 | [diff] [blame] | 335 | if (fPurging) { |
| 336 | return; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 337 | } |
commit-bot@chromium.org | cae27fe | 2013-07-10 10:14:35 +0000 | [diff] [blame] | 338 | |
| 339 | fPurging = true; |
| 340 | |
commit-bot@chromium.org | 50a3043 | 2013-10-24 17:44:27 +0000 | [diff] [blame] | 341 | this->purgeInvalidated(); |
| 342 | |
robertphillips@google.com | 41d2532 | 2013-07-18 17:12:57 +0000 | [diff] [blame] | 343 | this->internalPurge(extraCount, extraBytes); |
skia.committer@gmail.com | a799198 | 2013-07-19 07:00:57 +0000 | [diff] [blame] | 344 | if (((fEntryCount+extraCount) > fMaxCount || |
robertphillips@google.com | 41d2532 | 2013-07-18 17:12:57 +0000 | [diff] [blame] | 345 | (fEntryBytes+extraBytes) > fMaxBytes) && |
commit-bot@chromium.org | cae27fe | 2013-07-10 10:14:35 +0000 | [diff] [blame] | 346 | NULL != fOverbudgetCB) { |
| 347 | // Despite the purge we're still over budget. See if Ganesh can |
| 348 | // release some resources and purge again. |
| 349 | if ((*fOverbudgetCB)(fOverbudgetData)) { |
robertphillips@google.com | 41d2532 | 2013-07-18 17:12:57 +0000 | [diff] [blame] | 350 | this->internalPurge(extraCount, extraBytes); |
commit-bot@chromium.org | cae27fe | 2013-07-10 10:14:35 +0000 | [diff] [blame] | 351 | } |
| 352 | } |
| 353 | |
| 354 | fPurging = false; |
| 355 | } |
| 356 | |
commit-bot@chromium.org | 50a3043 | 2013-10-24 17:44:27 +0000 | [diff] [blame] | 357 | void GrResourceCache::purgeInvalidated() { |
| 358 | SkTDArray<GrResourceInvalidatedMessage> invalidated; |
| 359 | fInvalidationInbox.poll(&invalidated); |
| 360 | |
| 361 | for (int i = 0; i < invalidated.count(); i++) { |
| 362 | // We're somewhat missing an opportunity here. We could use the |
| 363 | // default find functor that gives us back resources whether we own |
| 364 | // them exclusively or not, and when they're not exclusively owned mark |
| 365 | // them for purging later when they do become exclusively owned. |
| 366 | // |
| 367 | // This is complicated and confusing. May try this in the future. For |
| 368 | // now, these resources are just LRU'd as if we never got the message. |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 369 | while (GrResourceCacheEntry* entry = fCache.find(invalidated[i].key, GrTFindUnreffedFunctor())) { |
commit-bot@chromium.org | 50a3043 | 2013-10-24 17:44:27 +0000 | [diff] [blame] | 370 | this->deleteResource(entry); |
| 371 | } |
| 372 | } |
| 373 | } |
| 374 | |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 375 | void GrResourceCache::deleteResource(GrResourceCacheEntry* entry) { |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 376 | SkASSERT(1 == entry->fResource->getRefCnt()); |
robertphillips@google.com | e4eaea2 | 2013-07-19 16:51:46 +0000 | [diff] [blame] | 377 | |
| 378 | // remove from our cache |
| 379 | fCache.remove(entry->key(), entry); |
| 380 | |
| 381 | // remove from our llist |
| 382 | this->internalDetach(entry); |
| 383 | delete entry; |
| 384 | } |
| 385 | |
robertphillips@google.com | 41d2532 | 2013-07-18 17:12:57 +0000 | [diff] [blame] | 386 | void GrResourceCache::internalPurge(int extraCount, size_t extraBytes) { |
commit-bot@chromium.org | cae27fe | 2013-07-10 10:14:35 +0000 | [diff] [blame] | 387 | SkASSERT(fPurging); |
| 388 | |
| 389 | bool withinBudget = false; |
| 390 | bool changed = false; |
| 391 | |
| 392 | // The purging process is repeated several times since one pass |
| 393 | // may free up other resources |
| 394 | do { |
| 395 | EntryList::Iter iter; |
| 396 | |
| 397 | changed = false; |
| 398 | |
| 399 | // Note: the following code relies on the fact that the |
| 400 | // doubly linked list doesn't invalidate its data/pointers |
| 401 | // outside of the specific area where a deletion occurs (e.g., |
| 402 | // in internalDetach) |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 403 | GrResourceCacheEntry* entry = iter.init(fList, EntryList::Iter::kTail_IterStart); |
commit-bot@chromium.org | cae27fe | 2013-07-10 10:14:35 +0000 | [diff] [blame] | 404 | |
| 405 | while (NULL != entry) { |
| 406 | GrAutoResourceCacheValidate atcv(this); |
| 407 | |
skia.committer@gmail.com | a799198 | 2013-07-19 07:00:57 +0000 | [diff] [blame] | 408 | if ((fEntryCount+extraCount) <= fMaxCount && |
robertphillips@google.com | 41d2532 | 2013-07-18 17:12:57 +0000 | [diff] [blame] | 409 | (fEntryBytes+extraBytes) <= fMaxBytes) { |
commit-bot@chromium.org | cae27fe | 2013-07-10 10:14:35 +0000 | [diff] [blame] | 410 | withinBudget = true; |
| 411 | break; |
| 412 | } |
| 413 | |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 414 | GrResourceCacheEntry* prev = iter.prev(); |
bungeman@google.com | f64c684 | 2013-07-19 23:18:52 +0000 | [diff] [blame] | 415 | if (entry->fResource->unique()) { |
commit-bot@chromium.org | cae27fe | 2013-07-10 10:14:35 +0000 | [diff] [blame] | 416 | changed = true; |
robertphillips@google.com | e4eaea2 | 2013-07-19 16:51:46 +0000 | [diff] [blame] | 417 | this->deleteResource(entry); |
commit-bot@chromium.org | cae27fe | 2013-07-10 10:14:35 +0000 | [diff] [blame] | 418 | } |
| 419 | entry = prev; |
| 420 | } |
| 421 | } while (!withinBudget && changed); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 422 | } |
| 423 | |
bsalomon@google.com | a292112 | 2012-08-28 12:34:17 +0000 | [diff] [blame] | 424 | void GrResourceCache::purgeAllUnlocked() { |
bsalomon@google.com | e9a9894 | 2011-08-22 17:06:16 +0000 | [diff] [blame] | 425 | GrAutoResourceCacheValidate atcv(this); |
reed@google.com | 01804b4 | 2011-01-18 21:50:41 +0000 | [diff] [blame] | 426 | |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 427 | // we can have one GrCacheable holding a lock on another |
bsalomon@google.com | e9a9894 | 2011-08-22 17:06:16 +0000 | [diff] [blame] | 428 | // so we don't want to just do a simple loop kicking each |
| 429 | // entry out. Instead change the budget and purge. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 430 | |
robertphillips@google.com | adacc70 | 2013-10-14 21:53:24 +0000 | [diff] [blame] | 431 | size_t savedMaxBytes = fMaxBytes; |
bsalomon@google.com | 07fc0d1 | 2012-06-22 15:15:59 +0000 | [diff] [blame] | 432 | int savedMaxCount = fMaxCount; |
| 433 | fMaxBytes = (size_t) -1; |
| 434 | fMaxCount = 0; |
bsalomon@google.com | e9a9894 | 2011-08-22 17:06:16 +0000 | [diff] [blame] | 435 | this->purgeAsNeeded(); |
| 436 | |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 437 | #ifdef SK_DEBUG |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 438 | SkASSERT(fExclusiveList.countEntries() == fClientDetachedCount); |
| 439 | SkASSERT(countBytes(fExclusiveList) == fClientDetachedBytes); |
twiz@google.com | 0ec107f | 2012-02-21 19:15:53 +0000 | [diff] [blame] | 440 | if (!fCache.count()) { |
| 441 | // Items may have been detached from the cache (such as the backing |
| 442 | // texture for an SkGpuDevice). The above purge would not have removed |
| 443 | // them. |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 444 | SkASSERT(fEntryCount == fClientDetachedCount); |
| 445 | SkASSERT(fEntryBytes == fClientDetachedBytes); |
| 446 | SkASSERT(fList.isEmpty()); |
twiz@google.com | 0ec107f | 2012-02-21 19:15:53 +0000 | [diff] [blame] | 447 | } |
| 448 | #endif |
bsalomon@google.com | e9a9894 | 2011-08-22 17:06:16 +0000 | [diff] [blame] | 449 | |
| 450 | fMaxBytes = savedMaxBytes; |
bsalomon@google.com | 07fc0d1 | 2012-06-22 15:15:59 +0000 | [diff] [blame] | 451 | fMaxCount = savedMaxCount; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | /////////////////////////////////////////////////////////////////////////////// |
| 455 | |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 456 | #ifdef SK_DEBUG |
bsalomon@google.com | a292112 | 2012-08-28 12:34:17 +0000 | [diff] [blame] | 457 | size_t GrResourceCache::countBytes(const EntryList& list) { |
robertphillips@google.com | 2ea0a23 | 2012-08-23 11:13:48 +0000 | [diff] [blame] | 458 | size_t bytes = 0; |
| 459 | |
bsalomon@google.com | a292112 | 2012-08-28 12:34:17 +0000 | [diff] [blame] | 460 | EntryList::Iter iter; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 461 | |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 462 | const GrResourceCacheEntry* entry = iter.init(const_cast<EntryList&>(list), |
| 463 | EntryList::Iter::kTail_IterStart); |
robertphillips@google.com | 2ea0a23 | 2012-08-23 11:13:48 +0000 | [diff] [blame] | 464 | |
| 465 | for ( ; NULL != entry; entry = iter.prev()) { |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 466 | bytes += entry->resource()->gpuMemorySize(); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 467 | } |
robertphillips@google.com | 2ea0a23 | 2012-08-23 11:13:48 +0000 | [diff] [blame] | 468 | return bytes; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 469 | } |
| 470 | |
reed@google.com | b89a643 | 2011-02-07 13:20:30 +0000 | [diff] [blame] | 471 | static bool both_zero_or_nonzero(int count, size_t bytes) { |
| 472 | return (count == 0 && bytes == 0) || (count > 0 && bytes > 0); |
| 473 | } |
reed@google.com | b89a643 | 2011-02-07 13:20:30 +0000 | [diff] [blame] | 474 | |
bsalomon@google.com | 50398bf | 2011-07-26 20:45:30 +0000 | [diff] [blame] | 475 | void GrResourceCache::validate() const { |
robertphillips@google.com | 2ea0a23 | 2012-08-23 11:13:48 +0000 | [diff] [blame] | 476 | fList.validate(); |
| 477 | fExclusiveList.validate(); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 478 | SkASSERT(both_zero_or_nonzero(fEntryCount, fEntryBytes)); |
| 479 | SkASSERT(both_zero_or_nonzero(fClientDetachedCount, fClientDetachedBytes)); |
| 480 | SkASSERT(fClientDetachedBytes <= fEntryBytes); |
| 481 | SkASSERT(fClientDetachedCount <= fEntryCount); |
| 482 | SkASSERT((fEntryCount - fClientDetachedCount) == fCache.count()); |
reed@google.com | 01804b4 | 2011-01-18 21:50:41 +0000 | [diff] [blame] | 483 | |
bsalomon@google.com | a292112 | 2012-08-28 12:34:17 +0000 | [diff] [blame] | 484 | EntryList::Iter iter; |
rmistry@google.com | fbfcd56 | 2012-08-23 18:09:54 +0000 | [diff] [blame] | 485 | |
robertphillips@google.com | 9fbcad0 | 2012-09-09 14:44:15 +0000 | [diff] [blame] | 486 | // check that the exclusively held entries are okay |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 487 | const GrResourceCacheEntry* entry = iter.init(const_cast<EntryList&>(fExclusiveList), |
| 488 | EntryList::Iter::kHead_IterStart); |
robertphillips@google.com | 2ea0a23 | 2012-08-23 11:13:48 +0000 | [diff] [blame] | 489 | |
| 490 | for ( ; NULL != entry; entry = iter.next()) { |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 491 | entry->validate(); |
robertphillips@google.com | d07cb0c | 2012-08-30 19:22:29 +0000 | [diff] [blame] | 492 | } |
| 493 | |
robertphillips@google.com | 9fbcad0 | 2012-09-09 14:44:15 +0000 | [diff] [blame] | 494 | // check that the shareable entries are okay |
robertphillips@google.com | d07cb0c | 2012-08-30 19:22:29 +0000 | [diff] [blame] | 495 | entry = iter.init(const_cast<EntryList&>(fList), EntryList::Iter::kHead_IterStart); |
| 496 | |
| 497 | int count = 0; |
robertphillips@google.com | d07cb0c | 2012-08-30 19:22:29 +0000 | [diff] [blame] | 498 | for ( ; NULL != entry; entry = iter.next()) { |
| 499 | entry->validate(); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 500 | SkASSERT(fCache.find(entry->key())); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 501 | count += 1; |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 502 | } |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 503 | SkASSERT(count == fEntryCount - fClientDetachedCount); |
robertphillips@google.com | 521eaf8 | 2012-08-22 11:03:19 +0000 | [diff] [blame] | 504 | |
robertphillips@google.com | 2ea0a23 | 2012-08-23 11:13:48 +0000 | [diff] [blame] | 505 | size_t bytes = countBytes(fList); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 506 | SkASSERT(bytes == fEntryBytes - fClientDetachedBytes); |
robertphillips@google.com | 521eaf8 | 2012-08-22 11:03:19 +0000 | [diff] [blame] | 507 | |
robertphillips@google.com | 2ea0a23 | 2012-08-23 11:13:48 +0000 | [diff] [blame] | 508 | bytes = countBytes(fExclusiveList); |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 509 | SkASSERT(bytes == fClientDetachedBytes); |
robertphillips@google.com | 521eaf8 | 2012-08-22 11:03:19 +0000 | [diff] [blame] | 510 | |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 511 | SkASSERT(fList.countEntries() == fEntryCount - fClientDetachedCount); |
robertphillips@google.com | 521eaf8 | 2012-08-22 11:03:19 +0000 | [diff] [blame] | 512 | |
tfarina@chromium.org | f6de475 | 2013-08-17 00:02:59 +0000 | [diff] [blame] | 513 | SkASSERT(fExclusiveList.countEntries() == fClientDetachedCount); |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 514 | } |
commit-bot@chromium.org | 515dcd3 | 2013-08-28 14:17:03 +0000 | [diff] [blame] | 515 | #endif // SK_DEBUG |
robertphillips@google.com | 5955202 | 2012-08-31 13:07:37 +0000 | [diff] [blame] | 516 | |
| 517 | #if GR_CACHE_STATS |
robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 518 | |
robertphillips@google.com | 9fbcad0 | 2012-09-09 14:44:15 +0000 | [diff] [blame] | 519 | void GrResourceCache::printStats() { |
| 520 | int locked = 0; |
| 521 | |
| 522 | EntryList::Iter iter; |
| 523 | |
commit-bot@chromium.org | 089a780 | 2014-05-02 21:38:22 +0000 | [diff] [blame] | 524 | GrResourceCacheEntry* entry = iter.init(fList, EntryList::Iter::kTail_IterStart); |
robertphillips@google.com | 9fbcad0 | 2012-09-09 14:44:15 +0000 | [diff] [blame] | 525 | |
| 526 | for ( ; NULL != entry; entry = iter.prev()) { |
| 527 | if (entry->fResource->getRefCnt() > 1) { |
| 528 | ++locked; |
| 529 | } |
| 530 | } |
| 531 | |
robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 532 | SkDebugf("Budget: %d items %d bytes\n", fMaxCount, fMaxBytes); |
robertphillips@google.com | 9fbcad0 | 2012-09-09 14:44:15 +0000 | [diff] [blame] | 533 | SkDebugf("\t\tEntry Count: current %d (%d locked) high %d\n", |
| 534 | fEntryCount, locked, fHighWaterEntryCount); |
robertphillips@google.com | 5f9f2f5 | 2012-08-22 10:57:05 +0000 | [diff] [blame] | 535 | SkDebugf("\t\tEntry Bytes: current %d high %d\n", |
| 536 | fEntryBytes, fHighWaterEntryBytes); |
| 537 | SkDebugf("\t\tDetached Entry Count: current %d high %d\n", |
| 538 | fClientDetachedCount, fHighWaterClientDetachedCount); |
| 539 | SkDebugf("\t\tDetached Bytes: current %d high %d\n", |
| 540 | fClientDetachedBytes, fHighWaterClientDetachedBytes); |
| 541 | } |
| 542 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 543 | #endif |
robertphillips@google.com | 521eaf8 | 2012-08-22 11:03:19 +0000 | [diff] [blame] | 544 | |
| 545 | /////////////////////////////////////////////////////////////////////////////// |