| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkChecksum.h" | 8 #include "SkChecksum.h" |
| 9 #include "SkResourceCache.h" | 9 #include "SkResourceCache.h" |
| 10 #include "SkMipMap.h" | 10 #include "SkMipMap.h" |
| (...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 size_t SkResourceCache::setSingleAllocationByteLimit(size_t newLimit) { | 428 size_t SkResourceCache::setSingleAllocationByteLimit(size_t newLimit) { |
| 429 size_t oldLimit = fSingleAllocationByteLimit; | 429 size_t oldLimit = fSingleAllocationByteLimit; |
| 430 fSingleAllocationByteLimit = newLimit; | 430 fSingleAllocationByteLimit = newLimit; |
| 431 return oldLimit; | 431 return oldLimit; |
| 432 } | 432 } |
| 433 | 433 |
| 434 size_t SkResourceCache::getSingleAllocationByteLimit() const { | 434 size_t SkResourceCache::getSingleAllocationByteLimit() const { |
| 435 return fSingleAllocationByteLimit; | 435 return fSingleAllocationByteLimit; |
| 436 } | 436 } |
| 437 | 437 |
| 438 size_t SkResourceCache::getEffectiveSingleAllocationByteLimit() const { |
| 439 // fSingleAllocationByteLimit == 0 means the caller is asking for our defaul
t |
| 440 size_t limit = fSingleAllocationByteLimit; |
| 441 |
| 442 // if we're not discardable (i.e. we are fixed-budget) then cap the single-l
imit |
| 443 // to our budget. |
| 444 if (NULL == fDiscardableFactory) { |
| 445 if (0 == limit) { |
| 446 limit = fTotalByteLimit; |
| 447 } else { |
| 448 limit = SkTMin(limit, fTotalByteLimit); |
| 449 } |
| 450 } |
| 451 return limit; |
| 452 } |
| 453 |
| 438 /////////////////////////////////////////////////////////////////////////////// | 454 /////////////////////////////////////////////////////////////////////////////// |
| 439 | 455 |
| 440 #include "SkThread.h" | 456 #include "SkThread.h" |
| 441 | 457 |
| 442 SK_DECLARE_STATIC_MUTEX(gMutex); | 458 SK_DECLARE_STATIC_MUTEX(gMutex); |
| 443 static SkResourceCache* gResourceCache = NULL; | 459 static SkResourceCache* gResourceCache = NULL; |
| 444 static void cleanup_gResourceCache() { | 460 static void cleanup_gResourceCache() { |
| 445 // We'll clean this up in our own tests, but disable for clients. | 461 // We'll clean this up in our own tests, but disable for clients. |
| 446 // Chrome seems to have funky multi-process things going on in unit tests th
at | 462 // Chrome seems to have funky multi-process things going on in unit tests th
at |
| 447 // makes this unsafe to delete when the main process atexit()s. | 463 // makes this unsafe to delete when the main process atexit()s. |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 size_t SkResourceCache::SetSingleAllocationByteLimit(size_t size) { | 520 size_t SkResourceCache::SetSingleAllocationByteLimit(size_t size) { |
| 505 SkAutoMutexAcquire am(gMutex); | 521 SkAutoMutexAcquire am(gMutex); |
| 506 return get_cache()->setSingleAllocationByteLimit(size); | 522 return get_cache()->setSingleAllocationByteLimit(size); |
| 507 } | 523 } |
| 508 | 524 |
| 509 size_t SkResourceCache::GetSingleAllocationByteLimit() { | 525 size_t SkResourceCache::GetSingleAllocationByteLimit() { |
| 510 SkAutoMutexAcquire am(gMutex); | 526 SkAutoMutexAcquire am(gMutex); |
| 511 return get_cache()->getSingleAllocationByteLimit(); | 527 return get_cache()->getSingleAllocationByteLimit(); |
| 512 } | 528 } |
| 513 | 529 |
| 530 size_t SkResourceCache::GetEffectiveSingleAllocationByteLimit() { |
| 531 SkAutoMutexAcquire am(gMutex); |
| 532 return get_cache()->getEffectiveSingleAllocationByteLimit(); |
| 533 } |
| 534 |
| 514 void SkResourceCache::PurgeAll() { | 535 void SkResourceCache::PurgeAll() { |
| 515 SkAutoMutexAcquire am(gMutex); | 536 SkAutoMutexAcquire am(gMutex); |
| 516 return get_cache()->purgeAll(); | 537 return get_cache()->purgeAll(); |
| 517 } | 538 } |
| 518 | 539 |
| 519 bool SkResourceCache::Find(const Key& key, VisitorProc visitor, void* context) { | 540 bool SkResourceCache::Find(const Key& key, VisitorProc visitor, void* context) { |
| 520 SkAutoMutexAcquire am(gMutex); | 541 SkAutoMutexAcquire am(gMutex); |
| 521 return get_cache()->find(key, visitor, context); | 542 return get_cache()->find(key, visitor, context); |
| 522 } | 543 } |
| 523 | 544 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 547 } | 568 } |
| 548 | 569 |
| 549 size_t SkGraphics::SetResourceCacheSingleAllocationByteLimit(size_t newLimit) { | 570 size_t SkGraphics::SetResourceCacheSingleAllocationByteLimit(size_t newLimit) { |
| 550 return SkResourceCache::SetSingleAllocationByteLimit(newLimit); | 571 return SkResourceCache::SetSingleAllocationByteLimit(newLimit); |
| 551 } | 572 } |
| 552 | 573 |
| 553 void SkGraphics::PurgeResourceCache() { | 574 void SkGraphics::PurgeResourceCache() { |
| 554 return SkResourceCache::PurgeAll(); | 575 return SkResourceCache::PurgeAll(); |
| 555 } | 576 } |
| 556 | 577 |
| OLD | NEW |