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 #ifndef SkScaledImageCache_DEFINED | 8 #ifndef SkScaledImageCache_DEFINED |
9 #define SkScaledImageCache_DEFINED | 9 #define SkScaledImageCache_DEFINED |
10 | 10 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 SkBitmap::Allocator* GetAllocator(); | 67 static SkBitmap::Allocator* GetAllocator(); |
68 | 68 |
| 69 /** |
| 70 * Call SkDebugf() with diagnostic information about the state of the cache |
| 71 */ |
| 72 static void Dump(); |
| 73 |
69 /////////////////////////////////////////////////////////////////////////// | 74 /////////////////////////////////////////////////////////////////////////// |
70 | 75 |
71 /** | 76 /** |
72 * Construct the cache to call DiscardableFactory when it | 77 * Construct the cache to call DiscardableFactory when it |
73 * allocates memory for the pixels. In this mode, the cache has | 78 * allocates memory for the pixels. In this mode, the cache has |
74 * not explicit budget, and so methods like getBytesUsed() and | 79 * not explicit budget, and so methods like getBytesUsed() and |
75 * getByteLimit() will return 0, and setByteLimit will ignore its argument | 80 * getByteLimit() will return 0, and setByteLimit will ignore its argument |
76 * and return 0. | 81 * and return 0. |
77 */ | 82 */ |
78 SkScaledImageCache(DiscardableFactory); | 83 SkScaledImageCache(DiscardableFactory); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
144 | 149 |
145 /** | 150 /** |
146 * Set the maximum number of bytes available to this cache. If the current | 151 * Set the maximum number of bytes available to this cache. If the current |
147 * cache exceeds this new value, it will be purged to try to fit within | 152 * cache exceeds this new value, it will be purged to try to fit within |
148 * this new limit. | 153 * this new limit. |
149 */ | 154 */ |
150 size_t setByteLimit(size_t newLimit); | 155 size_t setByteLimit(size_t newLimit); |
151 | 156 |
152 SkBitmap::Allocator* allocator() const { return fAllocator; }; | 157 SkBitmap::Allocator* allocator() const { return fAllocator; }; |
153 | 158 |
| 159 /** |
| 160 * Call SkDebugf() with diagnostic information about the state of the cache |
| 161 */ |
| 162 void dump() const; |
| 163 |
154 public: | 164 public: |
155 struct Rec; | 165 struct Rec; |
156 struct Key; | 166 struct Key; |
157 private: | 167 private: |
158 Rec* fHead; | 168 Rec* fHead; |
159 Rec* fTail; | 169 Rec* fTail; |
160 | 170 |
161 class Hash; | 171 class Hash; |
162 Hash* fHash; | 172 Hash* fHash; |
163 | 173 |
164 DiscardableFactory fDiscardableFactory; | 174 DiscardableFactory fDiscardableFactory; |
165 // the allocator is NULL or one that matches discardables | 175 // the allocator is NULL or one that matches discardables |
166 SkBitmap::Allocator* fAllocator; | 176 SkBitmap::Allocator* fAllocator; |
167 | 177 |
168 size_t fBytesUsed; | 178 size_t fBytesUsed; |
169 size_t fByteLimit; | 179 size_t fByteLimit; |
170 int fCount; | 180 int fCount; |
171 | 181 |
172 Rec* findAndLock(uint32_t generationID, SkScalar sx, SkScalar sy, | 182 Rec* findAndLock(uint32_t generationID, SkScalar sx, SkScalar sy, |
173 const SkIRect& bounds); | 183 const SkIRect& bounds); |
174 Rec* findAndLock(const Key& key); | 184 Rec* findAndLock(const Key& key); |
175 ID* addAndLock(Rec* rec); | 185 ID* addAndLock(Rec* rec); |
176 | 186 |
| 187 void purgeRec(Rec*); |
177 void purgeAsNeeded(); | 188 void purgeAsNeeded(); |
178 | 189 |
179 // linklist management | 190 // linklist management |
180 void moveToHead(Rec*); | 191 void moveToHead(Rec*); |
181 void addToHead(Rec*); | 192 void addToHead(Rec*); |
182 void detach(Rec*); | 193 void detach(Rec*); |
183 | 194 |
184 void init(); // called by constructors | 195 void init(); // called by constructors |
185 | 196 |
186 #ifdef SK_DEBUG | 197 #ifdef SK_DEBUG |
187 void validate() const; | 198 void validate() const; |
188 #else | 199 #else |
189 void validate() const {} | 200 void validate() const {} |
190 #endif | 201 #endif |
191 }; | 202 }; |
192 #endif | 203 #endif |
OLD | NEW |