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 "SkCachedData.h" | |
9 #include "SkChecksum.h" | 8 #include "SkChecksum.h" |
10 #include "SkResourceCache.h" | 9 #include "SkResourceCache.h" |
11 #include "SkMipMap.h" | 10 #include "SkMipMap.h" |
12 #include "SkPixelRef.h" | 11 #include "SkPixelRef.h" |
13 | 12 |
14 // This can be defined by the caller's build system | 13 // This can be defined by the caller's build system |
15 //#define SK_USE_DISCARDABLE_SCALEDIMAGECACHE | 14 //#define SK_USE_DISCARDABLE_SCALEDIMAGECACHE |
16 | 15 |
17 #ifndef SK_DISCARDABLEMEMORY_SCALEDIMAGECACHE_COUNT_LIMIT | 16 #ifndef SK_DISCARDABLEMEMORY_SCALEDIMAGECACHE_COUNT_LIMIT |
18 # define SK_DISCARDABLEMEMORY_SCALEDIMAGECACHE_COUNT_LIMIT 1024 | 17 # define SK_DISCARDABLEMEMORY_SCALEDIMAGECACHE_COUNT_LIMIT 1024 |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 | 256 |
258 size_t SkResourceCache::setTotalByteLimit(size_t newLimit) { | 257 size_t SkResourceCache::setTotalByteLimit(size_t newLimit) { |
259 size_t prevLimit = fTotalByteLimit; | 258 size_t prevLimit = fTotalByteLimit; |
260 fTotalByteLimit = newLimit; | 259 fTotalByteLimit = newLimit; |
261 if (newLimit < prevLimit) { | 260 if (newLimit < prevLimit) { |
262 this->purgeAsNeeded(); | 261 this->purgeAsNeeded(); |
263 } | 262 } |
264 return prevLimit; | 263 return prevLimit; |
265 } | 264 } |
266 | 265 |
267 SkCachedData* SkResourceCache::newCachedData(size_t bytes) { | |
268 if (fDiscardableFactory) { | |
269 SkDiscardableMemory* dm = fDiscardableFactory(bytes); | |
270 return dm ? SkNEW_ARGS(SkCachedData, (bytes, dm)) : NULL; | |
271 } else { | |
272 return SkNEW_ARGS(SkCachedData, (sk_malloc_throw(bytes), bytes)); | |
273 } | |
274 } | |
275 | |
276 /////////////////////////////////////////////////////////////////////////////// | 266 /////////////////////////////////////////////////////////////////////////////// |
277 | 267 |
278 void SkResourceCache::detach(Rec* rec) { | 268 void SkResourceCache::detach(Rec* rec) { |
279 Rec* prev = rec->fPrev; | 269 Rec* prev = rec->fPrev; |
280 Rec* next = rec->fNext; | 270 Rec* next = rec->fNext; |
281 | 271 |
282 if (!prev) { | 272 if (!prev) { |
283 SkASSERT(fHead == rec); | 273 SkASSERT(fHead == rec); |
284 fHead = next; | 274 fHead = next; |
285 } else { | 275 } else { |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 SkResourceCache::DiscardableFactory SkResourceCache::GetDiscardableFactory() { | 435 SkResourceCache::DiscardableFactory SkResourceCache::GetDiscardableFactory() { |
446 SkAutoMutexAcquire am(gMutex); | 436 SkAutoMutexAcquire am(gMutex); |
447 return get_cache()->discardableFactory(); | 437 return get_cache()->discardableFactory(); |
448 } | 438 } |
449 | 439 |
450 SkBitmap::Allocator* SkResourceCache::GetAllocator() { | 440 SkBitmap::Allocator* SkResourceCache::GetAllocator() { |
451 SkAutoMutexAcquire am(gMutex); | 441 SkAutoMutexAcquire am(gMutex); |
452 return get_cache()->allocator(); | 442 return get_cache()->allocator(); |
453 } | 443 } |
454 | 444 |
455 SkCachedData* SkResourceCache::NewCachedData(size_t bytes) { | |
456 SkAutoMutexAcquire am(gMutex); | |
457 return get_cache()->newCachedData(bytes); | |
458 } | |
459 | |
460 void SkResourceCache::Dump() { | 445 void SkResourceCache::Dump() { |
461 SkAutoMutexAcquire am(gMutex); | 446 SkAutoMutexAcquire am(gMutex); |
462 get_cache()->dump(); | 447 get_cache()->dump(); |
463 } | 448 } |
464 | 449 |
465 size_t SkResourceCache::SetSingleAllocationByteLimit(size_t size) { | 450 size_t SkResourceCache::SetSingleAllocationByteLimit(size_t size) { |
466 SkAutoMutexAcquire am(gMutex); | 451 SkAutoMutexAcquire am(gMutex); |
467 return get_cache()->setSingleAllocationByteLimit(size); | 452 return get_cache()->setSingleAllocationByteLimit(size); |
468 } | 453 } |
469 | 454 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
508 } | 493 } |
509 | 494 |
510 size_t SkGraphics::SetResourceCacheSingleAllocationByteLimit(size_t newLimit) { | 495 size_t SkGraphics::SetResourceCacheSingleAllocationByteLimit(size_t newLimit) { |
511 return SkResourceCache::SetSingleAllocationByteLimit(newLimit); | 496 return SkResourceCache::SetSingleAllocationByteLimit(newLimit); |
512 } | 497 } |
513 | 498 |
514 void SkGraphics::PurgeResourceCache() { | 499 void SkGraphics::PurgeResourceCache() { |
515 return SkResourceCache::PurgeAll(); | 500 return SkResourceCache::PurgeAll(); |
516 } | 501 } |
517 | 502 |
OLD | NEW |