| 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 SkResourceCache_DEFINED | 8 #ifndef SkResourceCache_DEFINED |
| 9 #define SkResourceCache_DEFINED | 9 #define SkResourceCache_DEFINED |
| 10 | 10 |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 static void Unlock(ID); | 99 static void Unlock(ID); |
| 100 static void Remove(ID); | 100 static void Remove(ID); |
| 101 | 101 |
| 102 static size_t GetTotalBytesUsed(); | 102 static size_t GetTotalBytesUsed(); |
| 103 static size_t GetTotalByteLimit(); | 103 static size_t GetTotalByteLimit(); |
| 104 static size_t SetTotalByteLimit(size_t newLimit); | 104 static size_t SetTotalByteLimit(size_t newLimit); |
| 105 | 105 |
| 106 static size_t SetSingleAllocationByteLimit(size_t); | 106 static size_t SetSingleAllocationByteLimit(size_t); |
| 107 static size_t GetSingleAllocationByteLimit(); | 107 static size_t GetSingleAllocationByteLimit(); |
| 108 | 108 |
| 109 static void PurgeAll(); |
| 110 |
| 109 /** | 111 /** |
| 110 * Use this allocator for bitmaps, so they can use ashmem when available. | 112 * Use this allocator for bitmaps, so they can use ashmem when available. |
| 111 * Returns NULL if the ResourceCache has not been initialized with a Discard
ableFactory. | 113 * Returns NULL if the ResourceCache has not been initialized with a Discard
ableFactory. |
| 112 */ | 114 */ |
| 113 static SkBitmap::Allocator* GetAllocator(); | 115 static SkBitmap::Allocator* GetAllocator(); |
| 114 | 116 |
| 115 /** | 117 /** |
| 116 * Call SkDebugf() with diagnostic information about the state of the cache | 118 * Call SkDebugf() with diagnostic information about the state of the cache |
| 117 */ | 119 */ |
| 118 static void Dump(); | 120 static void Dump(); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 */ | 162 */ |
| 161 size_t setSingleAllocationByteLimit(size_t maximumAllocationSize); | 163 size_t setSingleAllocationByteLimit(size_t maximumAllocationSize); |
| 162 size_t getSingleAllocationByteLimit() const; | 164 size_t getSingleAllocationByteLimit() const; |
| 163 /** | 165 /** |
| 164 * Set the maximum number of bytes available to this cache. If the current | 166 * Set the maximum number of bytes available to this cache. If the current |
| 165 * cache exceeds this new value, it will be purged to try to fit within | 167 * cache exceeds this new value, it will be purged to try to fit within |
| 166 * this new limit. | 168 * this new limit. |
| 167 */ | 169 */ |
| 168 size_t setTotalByteLimit(size_t newLimit); | 170 size_t setTotalByteLimit(size_t newLimit); |
| 169 | 171 |
| 172 void purgeAll() { |
| 173 this->purgeAsNeeded(true); |
| 174 } |
| 175 |
| 170 SkBitmap::Allocator* allocator() const { return fAllocator; }; | 176 SkBitmap::Allocator* allocator() const { return fAllocator; }; |
| 171 | 177 |
| 172 /** | 178 /** |
| 173 * Call SkDebugf() with diagnostic information about the state of the cache | 179 * Call SkDebugf() with diagnostic information about the state of the cache |
| 174 */ | 180 */ |
| 175 void dump() const; | 181 void dump() const; |
| 176 | 182 |
| 177 private: | 183 private: |
| 178 Rec* fHead; | 184 Rec* fHead; |
| 179 Rec* fTail; | 185 Rec* fTail; |
| 180 | 186 |
| 181 class Hash; | 187 class Hash; |
| 182 Hash* fHash; | 188 Hash* fHash; |
| 183 | 189 |
| 184 DiscardableFactory fDiscardableFactory; | 190 DiscardableFactory fDiscardableFactory; |
| 185 // the allocator is NULL or one that matches discardables | 191 // the allocator is NULL or one that matches discardables |
| 186 SkBitmap::Allocator* fAllocator; | 192 SkBitmap::Allocator* fAllocator; |
| 187 | 193 |
| 188 size_t fTotalBytesUsed; | 194 size_t fTotalBytesUsed; |
| 189 size_t fTotalByteLimit; | 195 size_t fTotalByteLimit; |
| 190 size_t fSingleAllocationByteLimit; | 196 size_t fSingleAllocationByteLimit; |
| 191 int fCount; | 197 int fCount; |
| 192 | 198 |
| 193 void purgeAsNeeded(); | 199 void purgeAsNeeded(bool forcePurge = false); |
| 194 | 200 |
| 195 // linklist management | 201 // linklist management |
| 196 void moveToHead(Rec*); | 202 void moveToHead(Rec*); |
| 197 void addToHead(Rec*); | 203 void addToHead(Rec*); |
| 198 void detach(Rec*); | 204 void detach(Rec*); |
| 199 | 205 |
| 200 void init(); // called by constructors | 206 void init(); // called by constructors |
| 201 | 207 |
| 202 #ifdef SK_DEBUG | 208 #ifdef SK_DEBUG |
| 203 void validate() const; | 209 void validate() const; |
| 204 #else | 210 #else |
| 205 void validate() const {} | 211 void validate() const {} |
| 206 #endif | 212 #endif |
| 207 }; | 213 }; |
| 208 #endif | 214 #endif |
| OLD | NEW |