Chromium Code Reviews| 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 static SkScaledImageCache* get_cache() { |
| 676 // gMutex is always held when this is called, so we don't need to be fancy i n here. | |
|
bungeman-skia
2014/05/27 16:21:21
We do have places where we have this requirement (
mtklein
2014/05/27 16:23:10
Done.
| |
| 677 if (NULL == gScaledImageCache) { | |
| 677 #ifdef SK_USE_DISCARDABLE_SCALEDIMAGECACHE | 678 #ifdef SK_USE_DISCARDABLE_SCALEDIMAGECACHE |
| 678 gScaledImageCache = SkNEW_ARGS(SkScaledImageCache, (SkDiscardableMemory::Cre ate)); | 679 gScaledImageCache = SkNEW_ARGS(SkScaledImageCache, (SkDiscardableMemory: :Create)); |
| 679 #else | 680 #else |
| 680 gScaledImageCache = SkNEW_ARGS(SkScaledImageCache, (SK_DEFAULT_IMAGE_CACHE_L IMIT)); | 681 gScaledImageCache = SkNEW_ARGS(SkScaledImageCache, (SK_DEFAULT_IMAGE_CAC HE_LIMIT)); |
| 681 #endif | 682 #endif |
| 682 } | 683 atexit(cleanup_gScaledImageCache); |
| 683 | 684 } |
| 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; | 685 return gScaledImageCache; |
| 689 } | 686 } |
| 690 | 687 |
| 691 | 688 |
| 692 SkScaledImageCache::ID* SkScaledImageCache::FindAndLock( | 689 SkScaledImageCache::ID* SkScaledImageCache::FindAndLock( |
| 693 uint32_t pixelGenerationID, | 690 uint32_t pixelGenerationID, |
| 694 int32_t width, | 691 int32_t width, |
| 695 int32_t height, | 692 int32_t height, |
| 696 SkBitmap* scaled) { | 693 SkBitmap* scaled) { |
| 697 SkAutoMutexAcquire am(gMutex); | 694 SkAutoMutexAcquire am(gMutex); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 776 return SkScaledImageCache::GetBytesUsed(); | 773 return SkScaledImageCache::GetBytesUsed(); |
| 777 } | 774 } |
| 778 | 775 |
| 779 size_t SkGraphics::GetImageCacheByteLimit() { | 776 size_t SkGraphics::GetImageCacheByteLimit() { |
| 780 return SkScaledImageCache::GetByteLimit(); | 777 return SkScaledImageCache::GetByteLimit(); |
| 781 } | 778 } |
| 782 | 779 |
| 783 size_t SkGraphics::SetImageCacheByteLimit(size_t newLimit) { | 780 size_t SkGraphics::SetImageCacheByteLimit(size_t newLimit) { |
| 784 return SkScaledImageCache::SetByteLimit(newLimit); | 781 return SkScaledImageCache::SetByteLimit(newLimit); |
| 785 } | 782 } |
| OLD | NEW |