Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(393)

Side by Side Diff: src/core/SkScaledImageCache.cpp

Issue 132803005: SkOnce: add option to call another cleanup function once at exit. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add static Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/core/SkPathRef.cpp ('k') | tests/CachedDecodingPixelRefTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 }
OLDNEW
« no previous file with comments | « src/core/SkPathRef.cpp ('k') | tests/CachedDecodingPixelRefTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698