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" | 10 #include "SkOnce.h" |
(...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
676 SkDebugf("SkScaledImageCache: count=%d bytes=%d locked=%d %s\n", | 676 SkDebugf("SkScaledImageCache: count=%d bytes=%d locked=%d %s\n", |
677 fCount, fBytesUsed, locked, | 677 fCount, fBytesUsed, locked, |
678 fDiscardableFactory ? "discardable" : "malloc"); | 678 fDiscardableFactory ? "discardable" : "malloc"); |
679 } | 679 } |
680 | 680 |
681 /////////////////////////////////////////////////////////////////////////////// | 681 /////////////////////////////////////////////////////////////////////////////// |
682 | 682 |
683 #include "SkThread.h" | 683 #include "SkThread.h" |
684 | 684 |
685 SK_DECLARE_STATIC_MUTEX(gMutex); | 685 SK_DECLARE_STATIC_MUTEX(gMutex); |
| 686 static SkScaledImageCache* gScaledImageCache = NULL; |
| 687 static void cleanup_gScaledImageCache() { SkDELETE(gScaledImageCache); } |
686 | 688 |
687 static void create_cache(SkScaledImageCache** cache) { | 689 static void create_cache(int) { |
688 #ifdef SK_USE_DISCARDABLE_SCALEDIMAGECACHE | 690 #ifdef SK_USE_DISCARDABLE_SCALEDIMAGECACHE |
689 *cache = SkNEW_ARGS(SkScaledImageCache, (SkDiscardableMemory::Create)); | 691 gScaledImageCache = SkNEW_ARGS(SkScaledImageCache, (SkDiscardableMemory::Cre
ate)); |
690 #else | 692 #else |
691 *cache = SkNEW_ARGS(SkScaledImageCache, (SK_DEFAULT_IMAGE_CACHE_LIMIT)); | 693 gScaledImageCache = SkNEW_ARGS(SkScaledImageCache, (SK_DEFAULT_IMAGE_CACHE_L
IMIT)); |
692 #endif | 694 #endif |
693 } | 695 } |
694 | 696 |
695 static SkScaledImageCache* get_cache() { | 697 static SkScaledImageCache* get_cache() { |
696 static SkScaledImageCache* gCache(NULL); | 698 SK_DECLARE_STATIC_ONCE(once); |
697 SK_DECLARE_STATIC_ONCE(create_cache_once); | 699 SkOnce(&once, create_cache, 0, cleanup_gScaledImageCache); |
698 SkOnce(&create_cache_once, create_cache, &gCache); | 700 SkASSERT(NULL != gScaledImageCache); |
699 SkASSERT(NULL != gCache); | 701 return gScaledImageCache; |
700 return gCache; | |
701 } | 702 } |
702 | 703 |
703 | 704 |
704 SkScaledImageCache::ID* SkScaledImageCache::FindAndLock( | 705 SkScaledImageCache::ID* SkScaledImageCache::FindAndLock( |
705 uint32_t pixelGenerationID, | 706 uint32_t pixelGenerationID, |
706 int32_t width, | 707 int32_t width, |
707 int32_t height, | 708 int32_t height, |
708 SkBitmap* scaled) { | 709 SkBitmap* scaled) { |
709 SkAutoMutexAcquire am(gMutex); | 710 SkAutoMutexAcquire am(gMutex); |
710 return get_cache()->findAndLock(pixelGenerationID, width, height, scaled); | 711 return get_cache()->findAndLock(pixelGenerationID, width, height, scaled); |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
788 return SkScaledImageCache::GetBytesUsed(); | 789 return SkScaledImageCache::GetBytesUsed(); |
789 } | 790 } |
790 | 791 |
791 size_t SkGraphics::GetImageCacheByteLimit() { | 792 size_t SkGraphics::GetImageCacheByteLimit() { |
792 return SkScaledImageCache::GetByteLimit(); | 793 return SkScaledImageCache::GetByteLimit(); |
793 } | 794 } |
794 | 795 |
795 size_t SkGraphics::SetImageCacheByteLimit(size_t newLimit) { | 796 size_t SkGraphics::SetImageCacheByteLimit(size_t newLimit) { |
796 return SkScaledImageCache::SetByteLimit(newLimit); | 797 return SkScaledImageCache::SetByteLimit(newLimit); |
797 } | 798 } |
OLD | NEW |