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 "SkScaledImageCache.h" | 8 #include "SkScaledImageCache.h" |
9 #include "SkMipMap.h" | 9 #include "SkMipMap.h" |
10 #include "SkOnce.h" | |
11 #include "SkPixelRef.h" | 10 #include "SkPixelRef.h" |
12 #include "SkRect.h" | 11 #include "SkRect.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 |
19 #endif | 18 #endif |
20 | 19 |
(...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
666 } | 665 } |
667 | 666 |
668 /////////////////////////////////////////////////////////////////////////////// | 667 /////////////////////////////////////////////////////////////////////////////// |
669 | 668 |
670 #include "SkThread.h" | 669 #include "SkThread.h" |
671 | 670 |
672 SK_DECLARE_STATIC_MUTEX(gMutex); | 671 SK_DECLARE_STATIC_MUTEX(gMutex); |
673 static SkScaledImageCache* gScaledImageCache = NULL; | 672 static SkScaledImageCache* gScaledImageCache = NULL; |
674 static void cleanup_gScaledImageCache() { SkDELETE(gScaledImageCache); } | 673 static void cleanup_gScaledImageCache() { SkDELETE(gScaledImageCache); } |
675 | 674 |
676 static void create_cache(int) { | 675 /** Must hold gMutex when calling. */ |
| 676 static SkScaledImageCache* get_cache() { |
| 677 // gMutex is always held when this is called, so we don't need to be fancy i
n here. |
| 678 if (NULL == gScaledImageCache) { |
677 #ifdef SK_USE_DISCARDABLE_SCALEDIMAGECACHE | 679 #ifdef SK_USE_DISCARDABLE_SCALEDIMAGECACHE |
678 gScaledImageCache = SkNEW_ARGS(SkScaledImageCache, (SkDiscardableMemory::Cre
ate)); | 680 gScaledImageCache = SkNEW_ARGS(SkScaledImageCache, (SkDiscardableMemory:
:Create)); |
679 #else | 681 #else |
680 gScaledImageCache = SkNEW_ARGS(SkScaledImageCache, (SK_DEFAULT_IMAGE_CACHE_L
IMIT)); | 682 gScaledImageCache = SkNEW_ARGS(SkScaledImageCache, (SK_DEFAULT_IMAGE_CAC
HE_LIMIT)); |
681 #endif | 683 #endif |
682 } | 684 atexit(cleanup_gScaledImageCache); |
683 | 685 } |
684 static SkScaledImageCache* get_cache() { | |
685 SK_DECLARE_STATIC_ONCE(once); | |
686 SkOnce(&once, create_cache, 0, cleanup_gScaledImageCache); | |
687 SkASSERT(NULL != gScaledImageCache); | |
688 return gScaledImageCache; | 686 return gScaledImageCache; |
689 } | 687 } |
690 | 688 |
691 | 689 |
692 SkScaledImageCache::ID* SkScaledImageCache::FindAndLock( | 690 SkScaledImageCache::ID* SkScaledImageCache::FindAndLock( |
693 uint32_t pixelGenerationID, | 691 uint32_t pixelGenerationID, |
694 int32_t width, | 692 int32_t width, |
695 int32_t height, | 693 int32_t height, |
696 SkBitmap* scaled) { | 694 SkBitmap* scaled) { |
697 SkAutoMutexAcquire am(gMutex); | 695 SkAutoMutexAcquire am(gMutex); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
776 return SkScaledImageCache::GetBytesUsed(); | 774 return SkScaledImageCache::GetBytesUsed(); |
777 } | 775 } |
778 | 776 |
779 size_t SkGraphics::GetImageCacheByteLimit() { | 777 size_t SkGraphics::GetImageCacheByteLimit() { |
780 return SkScaledImageCache::GetByteLimit(); | 778 return SkScaledImageCache::GetByteLimit(); |
781 } | 779 } |
782 | 780 |
783 size_t SkGraphics::SetImageCacheByteLimit(size_t newLimit) { | 781 size_t SkGraphics::SetImageCacheByteLimit(size_t newLimit) { |
784 return SkScaledImageCache::SetByteLimit(newLimit); | 782 return SkScaledImageCache::SetByteLimit(newLimit); |
785 } | 783 } |
OLD | NEW |