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 19 matching lines...) Expand all Loading... |
30 // we assume ownership of the resource, and will unref it when we die | 30 // we assume ownership of the resource, and will unref it when we die |
31 SkASSERT(resource); | 31 SkASSERT(resource); |
32 resource->ref(); | 32 resource->ref(); |
33 } | 33 } |
34 | 34 |
35 GrResourceEntry::~GrResourceEntry() { | 35 GrResourceEntry::~GrResourceEntry() { |
36 fResource->setCacheEntry(NULL); | 36 fResource->setCacheEntry(NULL); |
37 fResource->unref(); | 37 fResource->unref(); |
38 } | 38 } |
39 | 39 |
40 #if GR_DEBUG | 40 #if SK_DEBUG |
41 void GrResourceEntry::validate() const { | 41 void GrResourceEntry::validate() const { |
42 SkASSERT(fResource); | 42 SkASSERT(fResource); |
43 SkASSERT(fResource->getCacheEntry() == this); | 43 SkASSERT(fResource->getCacheEntry() == this); |
44 fResource->validate(); | 44 fResource->validate(); |
45 } | 45 } |
46 #endif | 46 #endif |
47 | 47 |
48 /////////////////////////////////////////////////////////////////////////////// | 48 /////////////////////////////////////////////////////////////////////////////// |
49 | 49 |
50 GrResourceCache::GrResourceCache(int maxCount, size_t maxBytes) : | 50 GrResourceCache::GrResourceCache(int maxCount, size_t maxBytes) : |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 } | 220 } |
221 | 221 |
222 void GrResourceCache::makeExclusive(GrResourceEntry* entry) { | 222 void GrResourceCache::makeExclusive(GrResourceEntry* entry) { |
223 GrAutoResourceCacheValidate atcv(this); | 223 GrAutoResourceCacheValidate atcv(this); |
224 | 224 |
225 // When scratch textures are detached (to hide them from future finds) they | 225 // When scratch textures are detached (to hide them from future finds) they |
226 // still count against the resource budget | 226 // still count against the resource budget |
227 this->internalDetach(entry, kIgnore_BudgetBehavior); | 227 this->internalDetach(entry, kIgnore_BudgetBehavior); |
228 fCache.remove(entry->key(), entry); | 228 fCache.remove(entry->key(), entry); |
229 | 229 |
230 #if GR_DEBUG | 230 #if SK_DEBUG |
231 fExclusiveList.addToHead(entry); | 231 fExclusiveList.addToHead(entry); |
232 #endif | 232 #endif |
233 } | 233 } |
234 | 234 |
235 void GrResourceCache::removeInvalidResource(GrResourceEntry* entry) { | 235 void GrResourceCache::removeInvalidResource(GrResourceEntry* entry) { |
236 // If the resource went invalid while it was detached then purge it | 236 // If the resource went invalid while it was detached then purge it |
237 // This can happen when a 3D context was lost, | 237 // This can happen when a 3D context was lost, |
238 // the client called GrContext::contextDestroyed() to notify Gr, | 238 // the client called GrContext::contextDestroyed() to notify Gr, |
239 // and then later an SkGpuDevice's destructor releases its backing | 239 // and then later an SkGpuDevice's destructor releases its backing |
240 // texture (which was invalidated at contextDestroyed time). | 240 // texture (which was invalidated at contextDestroyed time). |
241 fClientDetachedCount -= 1; | 241 fClientDetachedCount -= 1; |
242 fEntryCount -= 1; | 242 fEntryCount -= 1; |
243 size_t size = entry->resource()->sizeInBytes(); | 243 size_t size = entry->resource()->sizeInBytes(); |
244 fClientDetachedBytes -= size; | 244 fClientDetachedBytes -= size; |
245 fEntryBytes -= size; | 245 fEntryBytes -= size; |
246 } | 246 } |
247 | 247 |
248 void GrResourceCache::makeNonExclusive(GrResourceEntry* entry) { | 248 void GrResourceCache::makeNonExclusive(GrResourceEntry* entry) { |
249 GrAutoResourceCacheValidate atcv(this); | 249 GrAutoResourceCacheValidate atcv(this); |
250 | 250 |
251 #if GR_DEBUG | 251 #if SK_DEBUG |
252 fExclusiveList.remove(entry); | 252 fExclusiveList.remove(entry); |
253 #endif | 253 #endif |
254 | 254 |
255 if (entry->resource()->isValid()) { | 255 if (entry->resource()->isValid()) { |
256 // Since scratch textures still count against the cache budget even | 256 // Since scratch textures still count against the cache budget even |
257 // when they have been removed from the cache, re-adding them doesn't | 257 // when they have been removed from the cache, re-adding them doesn't |
258 // alter the budget information. | 258 // alter the budget information. |
259 attachToHead(entry, kIgnore_BudgetBehavior); | 259 attachToHead(entry, kIgnore_BudgetBehavior); |
260 fCache.insert(entry->key(), entry); | 260 fCache.insert(entry->key(), entry); |
261 } else { | 261 } else { |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 // we can have one GrResource holding a lock on another | 353 // we can have one GrResource holding a lock on another |
354 // so we don't want to just do a simple loop kicking each | 354 // so we don't want to just do a simple loop kicking each |
355 // entry out. Instead change the budget and purge. | 355 // entry out. Instead change the budget and purge. |
356 | 356 |
357 int savedMaxBytes = fMaxBytes; | 357 int savedMaxBytes = fMaxBytes; |
358 int savedMaxCount = fMaxCount; | 358 int savedMaxCount = fMaxCount; |
359 fMaxBytes = (size_t) -1; | 359 fMaxBytes = (size_t) -1; |
360 fMaxCount = 0; | 360 fMaxCount = 0; |
361 this->purgeAsNeeded(); | 361 this->purgeAsNeeded(); |
362 | 362 |
363 #if GR_DEBUG | 363 #if SK_DEBUG |
364 SkASSERT(fExclusiveList.countEntries() == fClientDetachedCount); | 364 SkASSERT(fExclusiveList.countEntries() == fClientDetachedCount); |
365 SkASSERT(countBytes(fExclusiveList) == fClientDetachedBytes); | 365 SkASSERT(countBytes(fExclusiveList) == fClientDetachedBytes); |
366 if (!fCache.count()) { | 366 if (!fCache.count()) { |
367 // Items may have been detached from the cache (such as the backing | 367 // Items may have been detached from the cache (such as the backing |
368 // texture for an SkGpuDevice). The above purge would not have removed | 368 // texture for an SkGpuDevice). The above purge would not have removed |
369 // them. | 369 // them. |
370 SkASSERT(fEntryCount == fClientDetachedCount); | 370 SkASSERT(fEntryCount == fClientDetachedCount); |
371 SkASSERT(fEntryBytes == fClientDetachedBytes); | 371 SkASSERT(fEntryBytes == fClientDetachedBytes); |
372 SkASSERT(fList.isEmpty()); | 372 SkASSERT(fList.isEmpty()); |
373 } | 373 } |
374 #endif | 374 #endif |
375 | 375 |
376 fMaxBytes = savedMaxBytes; | 376 fMaxBytes = savedMaxBytes; |
377 fMaxCount = savedMaxCount; | 377 fMaxCount = savedMaxCount; |
378 } | 378 } |
379 | 379 |
380 /////////////////////////////////////////////////////////////////////////////// | 380 /////////////////////////////////////////////////////////////////////////////// |
381 | 381 |
382 #if GR_DEBUG | 382 #if SK_DEBUG |
383 size_t GrResourceCache::countBytes(const EntryList& list) { | 383 size_t GrResourceCache::countBytes(const EntryList& list) { |
384 size_t bytes = 0; | 384 size_t bytes = 0; |
385 | 385 |
386 EntryList::Iter iter; | 386 EntryList::Iter iter; |
387 | 387 |
388 const GrResourceEntry* entry = iter.init(const_cast<EntryList&>(list), | 388 const GrResourceEntry* entry = iter.init(const_cast<EntryList&>(list), |
389 EntryList::Iter::kTail_IterStart); | 389 EntryList::Iter::kTail_IterStart); |
390 | 390 |
391 for ( ; NULL != entry; entry = iter.prev()) { | 391 for ( ; NULL != entry; entry = iter.prev()) { |
392 bytes += entry->resource()->sizeInBytes(); | 392 bytes += entry->resource()->sizeInBytes(); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 size_t bytes = countBytes(fList); | 434 size_t bytes = countBytes(fList); |
435 SkASSERT(bytes == fEntryBytes - fClientDetachedBytes); | 435 SkASSERT(bytes == fEntryBytes - fClientDetachedBytes); |
436 | 436 |
437 bytes = countBytes(fExclusiveList); | 437 bytes = countBytes(fExclusiveList); |
438 SkASSERT(bytes == fClientDetachedBytes); | 438 SkASSERT(bytes == fClientDetachedBytes); |
439 | 439 |
440 SkASSERT(fList.countEntries() == fEntryCount - fClientDetachedCount); | 440 SkASSERT(fList.countEntries() == fEntryCount - fClientDetachedCount); |
441 | 441 |
442 SkASSERT(fExclusiveList.countEntries() == fClientDetachedCount); | 442 SkASSERT(fExclusiveList.countEntries() == fClientDetachedCount); |
443 } | 443 } |
444 #endif // GR_DEBUG | 444 #endif // SK_DEBUG |
445 | 445 |
446 #if GR_CACHE_STATS | 446 #if GR_CACHE_STATS |
447 | 447 |
448 void GrResourceCache::printStats() { | 448 void GrResourceCache::printStats() { |
449 int locked = 0; | 449 int locked = 0; |
450 | 450 |
451 EntryList::Iter iter; | 451 EntryList::Iter iter; |
452 | 452 |
453 GrResourceEntry* entry = iter.init(fList, EntryList::Iter::kTail_IterStart); | 453 GrResourceEntry* entry = iter.init(fList, EntryList::Iter::kTail_IterStart); |
454 | 454 |
(...skipping 10 matching lines...) Expand all Loading... |
465 fEntryBytes, fHighWaterEntryBytes); | 465 fEntryBytes, fHighWaterEntryBytes); |
466 SkDebugf("\t\tDetached Entry Count: current %d high %d\n", | 466 SkDebugf("\t\tDetached Entry Count: current %d high %d\n", |
467 fClientDetachedCount, fHighWaterClientDetachedCount); | 467 fClientDetachedCount, fHighWaterClientDetachedCount); |
468 SkDebugf("\t\tDetached Bytes: current %d high %d\n", | 468 SkDebugf("\t\tDetached Bytes: current %d high %d\n", |
469 fClientDetachedBytes, fHighWaterClientDetachedBytes); | 469 fClientDetachedBytes, fHighWaterClientDetachedBytes); |
470 } | 470 } |
471 | 471 |
472 #endif | 472 #endif |
473 | 473 |
474 /////////////////////////////////////////////////////////////////////////////// | 474 /////////////////////////////////////////////////////////////////////////////// |
OLD | NEW |