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

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

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 #ifndef SkScaledImageCache_DEFINED 8 #ifndef SkScaledImageCache_DEFINED
9 #define SkScaledImageCache_DEFINED 9 #define SkScaledImageCache_DEFINED
10 10
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 static ID* AddAndLock(const SkBitmap& original, SkScalar scaleX, 57 static ID* AddAndLock(const SkBitmap& original, SkScalar scaleX,
58 SkScalar scaleY, const SkBitmap& bitmap); 58 SkScalar scaleY, const SkBitmap& bitmap);
59 static ID* AddAndLockMip(const SkBitmap& original, const SkMipMap* mipMap); 59 static ID* AddAndLockMip(const SkBitmap& original, const SkMipMap* mipMap);
60 60
61 static void Unlock(ID*); 61 static void Unlock(ID*);
62 62
63 static size_t GetBytesUsed(); 63 static size_t GetBytesUsed();
64 static size_t GetByteLimit(); 64 static size_t GetByteLimit();
65 static size_t SetByteLimit(size_t newLimit); 65 static size_t SetByteLimit(size_t newLimit);
66 66
67 static size_t SetSingleAllocationByteLimit(size_t);
68 static size_t GetSingleAllocationByteLimit();
69
67 static SkBitmap::Allocator* GetAllocator(); 70 static SkBitmap::Allocator* GetAllocator();
68 71
69 /** 72 /**
70 * Call SkDebugf() with diagnostic information about the state of the cache 73 * Call SkDebugf() with diagnostic information about the state of the cache
71 */ 74 */
72 static void Dump(); 75 static void Dump();
73 76
74 /////////////////////////////////////////////////////////////////////////// 77 ///////////////////////////////////////////////////////////////////////////
75 78
76 /** 79 /**
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 * this releases the associated resources to be available to be purged 144 * this releases the associated resources to be available to be purged
142 * if needed. After this, the cached bitmap should no longer be 145 * if needed. After this, the cached bitmap should no longer be
143 * referenced by the caller. 146 * referenced by the caller.
144 */ 147 */
145 void unlock(ID*); 148 void unlock(ID*);
146 149
147 size_t getBytesUsed() const { return fBytesUsed; } 150 size_t getBytesUsed() const { return fBytesUsed; }
148 size_t getByteLimit() const { return fByteLimit; } 151 size_t getByteLimit() const { return fByteLimit; }
149 152
150 /** 153 /**
154 * This is respected by SkBitmapProcState::possiblyScaleImage.
155 * 0 is no maximum at all; this is the default.
156 * setSingleAllocationByteLimit() returns the previous value.
157 */
158 size_t setSingleAllocationByteLimit(size_t maximumAllocationSize);
159 size_t getSingleAllocationByteLimit() const;
160 /**
151 * Set the maximum number of bytes available to this cache. If the current 161 * Set the maximum number of bytes available to this cache. If the current
152 * cache exceeds this new value, it will be purged to try to fit within 162 * cache exceeds this new value, it will be purged to try to fit within
153 * this new limit. 163 * this new limit.
154 */ 164 */
155 size_t setByteLimit(size_t newLimit); 165 size_t setByteLimit(size_t newLimit);
156 166
157 SkBitmap::Allocator* allocator() const { return fAllocator; }; 167 SkBitmap::Allocator* allocator() const { return fAllocator; };
158 168
159 /** 169 /**
160 * Call SkDebugf() with diagnostic information about the state of the cache 170 * Call SkDebugf() with diagnostic information about the state of the cache
161 */ 171 */
162 void dump() const; 172 void dump() const;
163 173
164 public: 174 public:
165 struct Rec; 175 struct Rec;
166 struct Key; 176 struct Key;
167 private: 177 private:
168 Rec* fHead; 178 Rec* fHead;
169 Rec* fTail; 179 Rec* fTail;
170 180
171 class Hash; 181 class Hash;
172 Hash* fHash; 182 Hash* fHash;
173 183
174 DiscardableFactory fDiscardableFactory; 184 DiscardableFactory fDiscardableFactory;
175 // the allocator is NULL or one that matches discardables 185 // the allocator is NULL or one that matches discardables
176 SkBitmap::Allocator* fAllocator; 186 SkBitmap::Allocator* fAllocator;
177 187
178 size_t fBytesUsed; 188 size_t fBytesUsed;
179 size_t fByteLimit; 189 size_t fByteLimit;
190 size_t fSingleAllocationByteLimit;
180 int fCount; 191 int fCount;
181 192
182 Rec* findAndLock(uint32_t generationID, SkScalar sx, SkScalar sy, 193 Rec* findAndLock(uint32_t generationID, SkScalar sx, SkScalar sy,
183 const SkIRect& bounds); 194 const SkIRect& bounds);
184 Rec* findAndLock(const Key& key); 195 Rec* findAndLock(const Key& key);
185 ID* addAndLock(Rec* rec); 196 ID* addAndLock(Rec* rec);
186 197
187 void purgeRec(Rec*); 198 void purgeRec(Rec*);
188 void purgeAsNeeded(); 199 void purgeAsNeeded();
189 200
190 // linklist management 201 // linklist management
191 void moveToHead(Rec*); 202 void moveToHead(Rec*);
192 void addToHead(Rec*); 203 void addToHead(Rec*);
193 void detach(Rec*); 204 void detach(Rec*);
194 205
195 void init(); // called by constructors 206 void init(); // called by constructors
196 207
197 #ifdef SK_DEBUG 208 #ifdef SK_DEBUG
198 void validate() const; 209 void validate() const;
199 #else 210 #else
200 void validate() const {} 211 void validate() const {}
201 #endif 212 #endif
202 }; 213 };
203 #endif 214 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698