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 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
277 * for incoming resources (e.g., GrContext is about to add 10MB split between | 277 * for incoming resources (e.g., GrContext is about to add 10MB split between |
278 * 10 textures). | 278 * 10 textures). |
279 */ | 279 */ |
280 void GrResourceCache::purgeAsNeeded(int extraCount, size_t extraBytes) { | 280 void GrResourceCache::purgeAsNeeded(int extraCount, size_t extraBytes) { |
281 if (fPurging) { | 281 if (fPurging) { |
282 return; | 282 return; |
283 } | 283 } |
284 | 284 |
285 fPurging = true; | 285 fPurging = true; |
286 | 286 |
287 this->purgeInvalidated(); | |
288 | |
287 this->internalPurge(extraCount, extraBytes); | 289 this->internalPurge(extraCount, extraBytes); |
288 if (((fEntryCount+extraCount) > fMaxCount || | 290 if (((fEntryCount+extraCount) > fMaxCount || |
289 (fEntryBytes+extraBytes) > fMaxBytes) && | 291 (fEntryBytes+extraBytes) > fMaxBytes) && |
290 NULL != fOverbudgetCB) { | 292 NULL != fOverbudgetCB) { |
291 // Despite the purge we're still over budget. See if Ganesh can | 293 // Despite the purge we're still over budget. See if Ganesh can |
292 // release some resources and purge again. | 294 // release some resources and purge again. |
293 if ((*fOverbudgetCB)(fOverbudgetData)) { | 295 if ((*fOverbudgetCB)(fOverbudgetData)) { |
294 this->internalPurge(extraCount, extraBytes); | 296 this->internalPurge(extraCount, extraBytes); |
295 } | 297 } |
296 } | 298 } |
297 | 299 |
298 fPurging = false; | 300 fPurging = false; |
299 } | 301 } |
300 | 302 |
303 void GrResourceCache::purgeInvalidated() { | |
304 SkTDArray<GrResourceInvalidatedMessage> invalidated; | |
305 fInvalidationInbox.poll(&invalidated); | |
306 | |
307 for (int i = 0; i < invalidated.count(); i++) { | |
308 // We're somewhat missing an opportunity here. We could use the | |
309 // default find functor that gives us back resources whether we own | |
310 // them exclusively or not, and when they're not exclusively owned mark | |
311 // them for purging later when they do become exclusively owned. | |
312 // | |
313 // This is complicated and confusing. May try this in the future. For | |
314 // now, these resources are just LRU'd as if we never got the message. | |
315 GrResourceEntry* entry = fCache.find(invalidated[i].key, GrTFindUnreffed Functor()); | |
bsalomon
2013/10/23 13:52:57
Don't we need the unique check somewhere in here?
mtklein
2013/10/23 15:28:10
Yes. That's what GrTFindUnreffedFunctor() does. :
| |
316 if (entry) { | |
317 this->deleteResource(entry); | |
318 } | |
319 } | |
320 } | |
321 | |
301 void GrResourceCache::deleteResource(GrResourceEntry* entry) { | 322 void GrResourceCache::deleteResource(GrResourceEntry* entry) { |
302 SkASSERT(1 == entry->fResource->getRefCnt()); | 323 SkASSERT(1 == entry->fResource->getRefCnt()); |
303 | 324 |
304 // remove from our cache | 325 // remove from our cache |
305 fCache.remove(entry->key(), entry); | 326 fCache.remove(entry->key(), entry); |
306 | 327 |
307 // remove from our llist | 328 // remove from our llist |
308 this->internalDetach(entry); | 329 this->internalDetach(entry); |
309 delete entry; | 330 delete entry; |
310 } | 331 } |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
465 fEntryBytes, fHighWaterEntryBytes); | 486 fEntryBytes, fHighWaterEntryBytes); |
466 SkDebugf("\t\tDetached Entry Count: current %d high %d\n", | 487 SkDebugf("\t\tDetached Entry Count: current %d high %d\n", |
467 fClientDetachedCount, fHighWaterClientDetachedCount); | 488 fClientDetachedCount, fHighWaterClientDetachedCount); |
468 SkDebugf("\t\tDetached Bytes: current %d high %d\n", | 489 SkDebugf("\t\tDetached Bytes: current %d high %d\n", |
469 fClientDetachedBytes, fHighWaterClientDetachedBytes); | 490 fClientDetachedBytes, fHighWaterClientDetachedBytes); |
470 } | 491 } |
471 | 492 |
472 #endif | 493 #endif |
473 | 494 |
474 /////////////////////////////////////////////////////////////////////////////// | 495 /////////////////////////////////////////////////////////////////////////////// |
OLD | NEW |