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

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

Issue 394003003: Set maximum output size for scaled-image-cache images (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rename, SkGraphics.h Created 6 years, 5 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
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 "SkChecksum.h" 8 #include "SkChecksum.h"
9 #include "SkScaledImageCache.h" 9 #include "SkScaledImageCache.h"
10 #include "SkMipMap.h" 10 #include "SkMipMap.h"
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 void SkScaledImageCache::init() { 135 void SkScaledImageCache::init() {
136 fHead = NULL; 136 fHead = NULL;
137 fTail = NULL; 137 fTail = NULL;
138 #ifdef USE_HASH 138 #ifdef USE_HASH
139 fHash = new Hash; 139 fHash = new Hash;
140 #else 140 #else
141 fHash = NULL; 141 fHash = NULL;
142 #endif 142 #endif
143 fBytesUsed = 0; 143 fBytesUsed = 0;
144 fCount = 0; 144 fCount = 0;
145 fSingleAllocationByteLimit = 0;
145 fAllocator = NULL; 146 fAllocator = NULL;
146 147
147 // One of these should be explicit set by the caller after we return. 148 // One of these should be explicit set by the caller after we return.
148 fByteLimit = 0; 149 fByteLimit = 0;
149 fDiscardableFactory = NULL; 150 fDiscardableFactory = NULL;
150 } 151 }
151 152
152 #include "SkDiscardableMemory.h" 153 #include "SkDiscardableMemory.h"
153 154
154 class SkOneShotDiscardablePixelRef : public SkPixelRef { 155 class SkOneShotDiscardablePixelRef : public SkPixelRef {
(...skipping 476 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 while (rec) { 632 while (rec) {
632 locked += rec->fLockCount > 0; 633 locked += rec->fLockCount > 0;
633 rec = rec->fNext; 634 rec = rec->fNext;
634 } 635 }
635 636
636 SkDebugf("SkScaledImageCache: count=%d bytes=%d locked=%d %s\n", 637 SkDebugf("SkScaledImageCache: count=%d bytes=%d locked=%d %s\n",
637 fCount, fBytesUsed, locked, 638 fCount, fBytesUsed, locked,
638 fDiscardableFactory ? "discardable" : "malloc"); 639 fDiscardableFactory ? "discardable" : "malloc");
639 } 640 }
640 641
642 size_t SkScaledImageCache::setSingleAllocationByteLimit(size_t newLimit) {
643 size_t oldLimit = fSingleAllocationByteLimit;
644 fSingleAllocationByteLimit = newLimit;
645 return oldLimit;
646 }
647
648 size_t SkScaledImageCache::getSingleAllocationByteLimit() const {
649 return fSingleAllocationByteLimit;
650 }
651
641 /////////////////////////////////////////////////////////////////////////////// 652 ///////////////////////////////////////////////////////////////////////////////
642 653
643 #include "SkThread.h" 654 #include "SkThread.h"
644 655
645 SK_DECLARE_STATIC_MUTEX(gMutex); 656 SK_DECLARE_STATIC_MUTEX(gMutex);
646 static SkScaledImageCache* gScaledImageCache = NULL; 657 static SkScaledImageCache* gScaledImageCache = NULL;
647 static void cleanup_gScaledImageCache() { 658 static void cleanup_gScaledImageCache() {
648 // We'll clean this up in our own tests, but disable for clients. 659 // We'll clean this up in our own tests, but disable for clients.
649 // Chrome seems to have funky multi-process things going on in unit tests th at 660 // Chrome seems to have funky multi-process things going on in unit tests th at
650 // makes this unsafe to delete when the main process atexit()s. 661 // makes this unsafe to delete when the main process atexit()s.
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 SkBitmap::Allocator* SkScaledImageCache::GetAllocator() { 753 SkBitmap::Allocator* SkScaledImageCache::GetAllocator() {
743 SkAutoMutexAcquire am(gMutex); 754 SkAutoMutexAcquire am(gMutex);
744 return get_cache()->allocator(); 755 return get_cache()->allocator();
745 } 756 }
746 757
747 void SkScaledImageCache::Dump() { 758 void SkScaledImageCache::Dump() {
748 SkAutoMutexAcquire am(gMutex); 759 SkAutoMutexAcquire am(gMutex);
749 get_cache()->dump(); 760 get_cache()->dump();
750 } 761 }
751 762
763 size_t SkScaledImageCache::SetSingleAllocationByteLimit(size_t size) {
764 SkAutoMutexAcquire am(gMutex);
765 return get_cache()->setSingleAllocationByteLimit(size);
766 }
767
768 size_t SkScaledImageCache::GetSingleAllocationByteLimit() {
769 SkAutoMutexAcquire am(gMutex);
770 return get_cache()->getSingleAllocationByteLimit();
771 }
772
752 /////////////////////////////////////////////////////////////////////////////// 773 ///////////////////////////////////////////////////////////////////////////////
753 774
754 #include "SkGraphics.h" 775 #include "SkGraphics.h"
755 776
756 size_t SkGraphics::GetImageCacheBytesUsed() { 777 size_t SkGraphics::GetImageCacheBytesUsed() {
757 return SkScaledImageCache::GetBytesUsed(); 778 return SkScaledImageCache::GetBytesUsed();
758 } 779 }
759 780
760 size_t SkGraphics::GetImageCacheByteLimit() { 781 size_t SkGraphics::GetImageCacheByteLimit() {
761 return SkScaledImageCache::GetByteLimit(); 782 return SkScaledImageCache::GetByteLimit();
762 } 783 }
763 784
764 size_t SkGraphics::SetImageCacheByteLimit(size_t newLimit) { 785 size_t SkGraphics::SetImageCacheByteLimit(size_t newLimit) {
765 return SkScaledImageCache::SetByteLimit(newLimit); 786 return SkScaledImageCache::SetByteLimit(newLimit);
766 } 787 }
788
789 size_t SkGraphics::GetImageCacheSingleAllocationByteLimit() {
790 return SkScaledImageCache::GetSingleAllocationByteLimit();
791 }
792
793 size_t SkGraphics::SetImageCacheSingleAllocationByteLimit(size_t newLimit) {
794 return SkScaledImageCache::SetSingleAllocationByteLimit(newLimit);
795 }
796
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698