| 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 | 91 |
| 92 /* | 92 /* |
| 93 * The following static methods are thread-safe wrappers around a global | 93 * The following static methods are thread-safe wrappers around a global |
| 94 * instance of this cache. | 94 * instance of this cache. |
| 95 */ | 95 */ |
| 96 | 96 |
| 97 static const Rec* FindAndLock(const Key& key); | 97 static const Rec* FindAndLock(const Key& key); |
| 98 static const Rec* AddAndLock(Rec*); | 98 static const Rec* AddAndLock(Rec*); |
| 99 static void Add(Rec*); | 99 static void Add(Rec*); |
| 100 static void Unlock(ID); | 100 static void Unlock(ID); |
| 101 static void Remove(ID); |
| 101 | 102 |
| 102 static size_t GetTotalBytesUsed(); | 103 static size_t GetTotalBytesUsed(); |
| 103 static size_t GetTotalByteLimit(); | 104 static size_t GetTotalByteLimit(); |
| 104 static size_t SetTotalByteLimit(size_t newLimit); | 105 static size_t SetTotalByteLimit(size_t newLimit); |
| 105 | 106 |
| 106 static size_t SetSingleAllocationByteLimit(size_t); | 107 static size_t SetSingleAllocationByteLimit(size_t); |
| 107 static size_t GetSingleAllocationByteLimit(); | 108 static size_t GetSingleAllocationByteLimit(); |
| 108 | 109 |
| 109 /** | 110 /** |
| 110 * Use this allocator for bitmaps, so they can use ashmem when available. | 111 * Use this allocator for bitmaps, so they can use ashmem when available. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 133 * byteLimit, purging automatically when a new image is added to the cache | 134 * byteLimit, purging automatically when a new image is added to the cache |
| 134 * that pushes the total bytesUsed over the limit. Note: The limit can be | 135 * that pushes the total bytesUsed over the limit. Note: The limit can be |
| 135 * changed at runtime with setTotalByteLimit. | 136 * changed at runtime with setTotalByteLimit. |
| 136 */ | 137 */ |
| 137 explicit SkResourceCache(size_t byteLimit); | 138 explicit SkResourceCache(size_t byteLimit); |
| 138 ~SkResourceCache(); | 139 ~SkResourceCache(); |
| 139 | 140 |
| 140 const Rec* findAndLock(const Key& key); | 141 const Rec* findAndLock(const Key& key); |
| 141 const Rec* addAndLock(Rec*); | 142 const Rec* addAndLock(Rec*); |
| 142 void add(Rec*); | 143 void add(Rec*); |
| 144 void remove(Rec*); |
| 143 | 145 |
| 144 /** | 146 /** |
| 145 * Given a non-null ID ptr returned by either findAndLock or addAndLock, | 147 * Given a non-null ID ptr returned by either findAndLock or addAndLock, |
| 146 * this releases the associated resources to be available to be purged | 148 * this releases the associated resources to be available to be purged |
| 147 * if needed. After this, the cached bitmap should no longer be | 149 * if needed. After this, the cached bitmap should no longer be |
| 148 * referenced by the caller. | 150 * referenced by the caller. |
| 149 */ | 151 */ |
| 150 void unlock(ID); | 152 void unlock(ID); |
| 151 | 153 |
| 152 size_t getTotalBytesUsed() const { return fTotalBytesUsed; } | 154 size_t getTotalBytesUsed() const { return fTotalBytesUsed; } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 182 | 184 |
| 183 DiscardableFactory fDiscardableFactory; | 185 DiscardableFactory fDiscardableFactory; |
| 184 // the allocator is NULL or one that matches discardables | 186 // the allocator is NULL or one that matches discardables |
| 185 SkBitmap::Allocator* fAllocator; | 187 SkBitmap::Allocator* fAllocator; |
| 186 | 188 |
| 187 size_t fTotalBytesUsed; | 189 size_t fTotalBytesUsed; |
| 188 size_t fTotalByteLimit; | 190 size_t fTotalByteLimit; |
| 189 size_t fSingleAllocationByteLimit; | 191 size_t fSingleAllocationByteLimit; |
| 190 int fCount; | 192 int fCount; |
| 191 | 193 |
| 192 void purgeRec(Rec*); | |
| 193 void purgeAsNeeded(); | 194 void purgeAsNeeded(); |
| 194 | 195 |
| 195 // linklist management | 196 // linklist management |
| 196 void moveToHead(Rec*); | 197 void moveToHead(Rec*); |
| 197 void addToHead(Rec*); | 198 void addToHead(Rec*); |
| 198 void detach(Rec*); | 199 void detach(Rec*); |
| 199 | 200 |
| 200 void init(); // called by constructors | 201 void init(); // called by constructors |
| 201 | 202 |
| 202 #ifdef SK_DEBUG | 203 #ifdef SK_DEBUG |
| 203 void validate() const; | 204 void validate() const; |
| 204 #else | 205 #else |
| 205 void validate() const {} | 206 void validate() const {} |
| 206 #endif | 207 #endif |
| 207 }; | 208 }; |
| 208 #endif | 209 #endif |
| OLD | NEW |