OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2010 Google Inc. | 3 * Copyright 2010 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 | 10 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 GrResourceCache::~GrResourceCache() { | 71 GrResourceCache::~GrResourceCache() { |
72 GrAutoResourceCacheValidate atcv(this); | 72 GrAutoResourceCacheValidate atcv(this); |
73 | 73 |
74 EntryList::Iter iter; | 74 EntryList::Iter iter; |
75 | 75 |
76 // Unlike the removeAll, here we really remove everything, including locked
resources. | 76 // Unlike the removeAll, here we really remove everything, including locked
resources. |
77 while (GrResourceEntry* entry = fList.head()) { | 77 while (GrResourceEntry* entry = fList.head()) { |
78 GrAutoResourceCacheValidate atcv(this); | 78 GrAutoResourceCacheValidate atcv(this); |
79 | 79 |
80 // remove from our cache | 80 // remove from our cache |
81 fCache.remove(entry->fKey, entry); | 81 fCache.remove(entry); |
82 | 82 |
83 // remove from our llist | 83 // remove from our llist |
84 this->internalDetach(entry); | 84 this->internalDetach(entry); |
85 | 85 |
86 delete entry; | 86 delete entry; |
87 } | 87 } |
88 } | 88 } |
89 | 89 |
90 void GrResourceCache::getLimits(int* maxResources, size_t* maxResourceBytes) con
st{ | 90 void GrResourceCache::getLimits(int* maxResources, size_t* maxResourceBytes) con
st{ |
91 if (NULL != maxResources) { | 91 if (NULL != maxResources) { |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 SkASSERT(NULL == resource->getCacheEntry()); | 202 SkASSERT(NULL == resource->getCacheEntry()); |
203 // we don't expect to create new resources during a purge. In theory | 203 // we don't expect to create new resources during a purge. In theory |
204 // this could cause purgeAsNeeded() into an infinite loop (e.g. | 204 // this could cause purgeAsNeeded() into an infinite loop (e.g. |
205 // each resource destroyed creates and locks 2 resources and | 205 // each resource destroyed creates and locks 2 resources and |
206 // unlocks 1 thereby causing a new purge). | 206 // unlocks 1 thereby causing a new purge). |
207 SkASSERT(!fPurging); | 207 SkASSERT(!fPurging); |
208 GrAutoResourceCacheValidate atcv(this); | 208 GrAutoResourceCacheValidate atcv(this); |
209 | 209 |
210 GrResourceEntry* entry = SkNEW_ARGS(GrResourceEntry, (key, resource)); | 210 GrResourceEntry* entry = SkNEW_ARGS(GrResourceEntry, (key, resource)); |
211 resource->setCacheEntry(entry); | 211 resource->setCacheEntry(entry); |
212 | |
213 this->attachToHead(entry); | 212 this->attachToHead(entry); |
214 fCache.insert(key, entry); | 213 fCache.add(entry); |
215 | 214 |
216 if (ownershipFlags & kHide_OwnershipFlag) { | 215 if (ownershipFlags & kHide_OwnershipFlag) { |
217 this->makeExclusive(entry); | 216 this->makeExclusive(entry); |
218 } | 217 } |
219 | 218 |
220 } | 219 } |
221 | 220 |
222 void GrResourceCache::makeExclusive(GrResourceEntry* entry) { | 221 void GrResourceCache::makeExclusive(GrResourceEntry* entry) { |
223 GrAutoResourceCacheValidate atcv(this); | 222 GrAutoResourceCacheValidate atcv(this); |
224 | |
225 // When scratch textures are detached (to hide them from future finds) they | 223 // When scratch textures are detached (to hide them from future finds) they |
226 // still count against the resource budget | 224 // still count against the resource budget |
227 this->internalDetach(entry, kIgnore_BudgetBehavior); | 225 this->internalDetach(entry, kIgnore_BudgetBehavior); |
228 fCache.remove(entry->key(), entry); | 226 fCache.remove(entry); |
229 | 227 |
230 #ifdef SK_DEBUG | 228 #ifdef SK_DEBUG |
231 fExclusiveList.addToHead(entry); | 229 fExclusiveList.addToHead(entry); |
232 #endif | 230 #endif |
233 } | 231 } |
234 | 232 |
235 void GrResourceCache::removeInvalidResource(GrResourceEntry* entry) { | 233 void GrResourceCache::removeInvalidResource(GrResourceEntry* entry) { |
236 // If the resource went invalid while it was detached then purge it | 234 // If the resource went invalid while it was detached then purge it |
237 // This can happen when a 3D context was lost, | 235 // This can happen when a 3D context was lost, |
238 // the client called GrContext::contextDestroyed() to notify Gr, | 236 // the client called GrContext::contextDestroyed() to notify Gr, |
(...skipping 11 matching lines...) Expand all Loading... |
250 | 248 |
251 #ifdef SK_DEBUG | 249 #ifdef SK_DEBUG |
252 fExclusiveList.remove(entry); | 250 fExclusiveList.remove(entry); |
253 #endif | 251 #endif |
254 | 252 |
255 if (entry->resource()->isValid()) { | 253 if (entry->resource()->isValid()) { |
256 // Since scratch textures still count against the cache budget even | 254 // Since scratch textures still count against the cache budget even |
257 // when they have been removed from the cache, re-adding them doesn't | 255 // when they have been removed from the cache, re-adding them doesn't |
258 // alter the budget information. | 256 // alter the budget information. |
259 attachToHead(entry, kIgnore_BudgetBehavior); | 257 attachToHead(entry, kIgnore_BudgetBehavior); |
260 fCache.insert(entry->key(), entry); | 258 fCache.add(entry); |
261 } else { | 259 } else { |
262 this->removeInvalidResource(entry); | 260 this->removeInvalidResource(entry); |
263 } | 261 } |
264 } | 262 } |
265 | 263 |
266 /** | 264 /** |
267 * Destroying a resource may potentially trigger the unlock of additional | 265 * Destroying a resource may potentially trigger the unlock of additional |
268 * resources which in turn will trigger a nested purge. We block the nested | 266 * resources which in turn will trigger a nested purge. We block the nested |
269 * purge using the fPurging variable. However, the initial purge will keep | 267 * purge using the fPurging variable. However, the initial purge will keep |
270 * looping until either all resources in the cache are unlocked or we've met | 268 * looping until either all resources in the cache are unlocked or we've met |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 // now, these resources are just LRU'd as if we never got the message. | 312 // now, these resources are just LRU'd as if we never got the message. |
315 GrResourceEntry* entry = fCache.find(invalidated[i].key, GrTFindUnreffed
Functor()); | 313 GrResourceEntry* entry = fCache.find(invalidated[i].key, GrTFindUnreffed
Functor()); |
316 if (entry) { | 314 if (entry) { |
317 this->deleteResource(entry); | 315 this->deleteResource(entry); |
318 } | 316 } |
319 } | 317 } |
320 } | 318 } |
321 | 319 |
322 void GrResourceCache::deleteResource(GrResourceEntry* entry) { | 320 void GrResourceCache::deleteResource(GrResourceEntry* entry) { |
323 SkASSERT(1 == entry->fResource->getRefCnt()); | 321 SkASSERT(1 == entry->fResource->getRefCnt()); |
324 | |
325 // remove from our cache | 322 // remove from our cache |
326 fCache.remove(entry->key(), entry); | 323 fCache.remove(entry); |
327 | 324 |
328 // remove from our llist | 325 // remove from our llist |
329 this->internalDetach(entry); | 326 this->internalDetach(entry); |
330 delete entry; | 327 delete entry; |
331 } | 328 } |
332 | 329 |
333 void GrResourceCache::internalPurge(int extraCount, size_t extraBytes) { | 330 void GrResourceCache::internalPurge(int extraCount, size_t extraBytes) { |
334 SkASSERT(fPurging); | 331 SkASSERT(fPurging); |
335 | 332 |
336 bool withinBudget = false; | 333 bool withinBudget = false; |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
421 | 418 |
422 void GrResourceCache::validate() const { | 419 void GrResourceCache::validate() const { |
423 fList.validate(); | 420 fList.validate(); |
424 fExclusiveList.validate(); | 421 fExclusiveList.validate(); |
425 SkASSERT(both_zero_or_nonzero(fEntryCount, fEntryBytes)); | 422 SkASSERT(both_zero_or_nonzero(fEntryCount, fEntryBytes)); |
426 SkASSERT(both_zero_or_nonzero(fClientDetachedCount, fClientDetachedBytes)); | 423 SkASSERT(both_zero_or_nonzero(fClientDetachedCount, fClientDetachedBytes)); |
427 SkASSERT(fClientDetachedBytes <= fEntryBytes); | 424 SkASSERT(fClientDetachedBytes <= fEntryBytes); |
428 SkASSERT(fClientDetachedCount <= fEntryCount); | 425 SkASSERT(fClientDetachedCount <= fEntryCount); |
429 SkASSERT((fEntryCount - fClientDetachedCount) == fCache.count()); | 426 SkASSERT((fEntryCount - fClientDetachedCount) == fCache.count()); |
430 | 427 |
431 fCache.validate(); | |
432 | |
433 | |
434 EntryList::Iter iter; | 428 EntryList::Iter iter; |
435 | 429 |
436 // check that the exclusively held entries are okay | 430 // check that the exclusively held entries are okay |
437 const GrResourceEntry* entry = iter.init(const_cast<EntryList&>(fExclusiveLi
st), | 431 const GrResourceEntry* entry = iter.init(const_cast<EntryList&>(fExclusiveLi
st), |
438 EntryList::Iter::kHead_IterStart); | 432 EntryList::Iter::kHead_IterStart); |
439 | 433 |
440 for ( ; NULL != entry; entry = iter.next()) { | 434 for ( ; NULL != entry; entry = iter.next()) { |
441 entry->validate(); | 435 entry->validate(); |
442 } | 436 } |
443 | 437 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
486 fEntryBytes, fHighWaterEntryBytes); | 480 fEntryBytes, fHighWaterEntryBytes); |
487 SkDebugf("\t\tDetached Entry Count: current %d high %d\n", | 481 SkDebugf("\t\tDetached Entry Count: current %d high %d\n", |
488 fClientDetachedCount, fHighWaterClientDetachedCount); | 482 fClientDetachedCount, fHighWaterClientDetachedCount); |
489 SkDebugf("\t\tDetached Bytes: current %d high %d\n", | 483 SkDebugf("\t\tDetached Bytes: current %d high %d\n", |
490 fClientDetachedBytes, fHighWaterClientDetachedBytes); | 484 fClientDetachedBytes, fHighWaterClientDetachedBytes); |
491 } | 485 } |
492 | 486 |
493 #endif | 487 #endif |
494 | 488 |
495 /////////////////////////////////////////////////////////////////////////////// | 489 /////////////////////////////////////////////////////////////////////////////// |
OLD | NEW |