| 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 |
| 11 #include "SkBitmap.h" | 11 #include "SkBitmap.h" |
| 12 | 12 |
| 13 class SkCachedData; |
| 13 class SkDiscardableMemory; | 14 class SkDiscardableMemory; |
| 14 class SkMipMap; | 15 class SkMipMap; |
| 15 | 16 |
| 16 /** | 17 /** |
| 17 * Cache object for bitmaps (with possible scale in X Y as part of the key). | 18 * Cache object for bitmaps (with possible scale in X Y as part of the key). |
| 18 * | 19 * |
| 19 * Multiple caches can be instantiated, but each instance is not implicitly | 20 * Multiple caches can be instantiated, but each instance is not implicitly |
| 20 * thread-safe, so if a given instance is to be shared across threads, the | 21 * thread-safe, so if a given instance is to be shared across threads, the |
| 21 * caller must manage the access itself (e.g. via a mutex). | 22 * caller must manage the access itself (e.g. via a mutex). |
| 22 * | 23 * |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 * Returns the DiscardableFactory used by the global cache, or NULL. | 130 * Returns the DiscardableFactory used by the global cache, or NULL. |
| 130 */ | 131 */ |
| 131 static DiscardableFactory GetDiscardableFactory(); | 132 static DiscardableFactory GetDiscardableFactory(); |
| 132 | 133 |
| 133 /** | 134 /** |
| 134 * Use this allocator for bitmaps, so they can use ashmem when available. | 135 * Use this allocator for bitmaps, so they can use ashmem when available. |
| 135 * Returns NULL if the ResourceCache has not been initialized with a Discard
ableFactory. | 136 * Returns NULL if the ResourceCache has not been initialized with a Discard
ableFactory. |
| 136 */ | 137 */ |
| 137 static SkBitmap::Allocator* GetAllocator(); | 138 static SkBitmap::Allocator* GetAllocator(); |
| 138 | 139 |
| 140 static SkCachedData* NewCachedData(size_t bytes); |
| 141 |
| 139 /** | 142 /** |
| 140 * Call SkDebugf() with diagnostic information about the state of the cache | 143 * Call SkDebugf() with diagnostic information about the state of the cache |
| 141 */ | 144 */ |
| 142 static void Dump(); | 145 static void Dump(); |
| 143 | 146 |
| 144 /////////////////////////////////////////////////////////////////////////// | 147 /////////////////////////////////////////////////////////////////////////// |
| 145 | 148 |
| 146 /** | 149 /** |
| 147 * Construct the cache to call DiscardableFactory when it | 150 * Construct the cache to call DiscardableFactory when it |
| 148 * allocates memory for the pixels. In this mode, the cache has | 151 * allocates memory for the pixels. In this mode, the cache has |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 */ | 193 */ |
| 191 size_t setTotalByteLimit(size_t newLimit); | 194 size_t setTotalByteLimit(size_t newLimit); |
| 192 | 195 |
| 193 void purgeAll() { | 196 void purgeAll() { |
| 194 this->purgeAsNeeded(true); | 197 this->purgeAsNeeded(true); |
| 195 } | 198 } |
| 196 | 199 |
| 197 DiscardableFactory discardableFactory() const { return fDiscardableFactory;
} | 200 DiscardableFactory discardableFactory() const { return fDiscardableFactory;
} |
| 198 SkBitmap::Allocator* allocator() const { return fAllocator; }; | 201 SkBitmap::Allocator* allocator() const { return fAllocator; }; |
| 199 | 202 |
| 203 SkCachedData* newCachedData(size_t bytes); |
| 204 |
| 200 /** | 205 /** |
| 201 * Call SkDebugf() with diagnostic information about the state of the cache | 206 * Call SkDebugf() with diagnostic information about the state of the cache |
| 202 */ | 207 */ |
| 203 void dump() const; | 208 void dump() const; |
| 204 | 209 |
| 205 private: | 210 private: |
| 206 Rec* fHead; | 211 Rec* fHead; |
| 207 Rec* fTail; | 212 Rec* fTail; |
| 208 | 213 |
| 209 class Hash; | 214 class Hash; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 228 | 233 |
| 229 void init(); // called by constructors | 234 void init(); // called by constructors |
| 230 | 235 |
| 231 #ifdef SK_DEBUG | 236 #ifdef SK_DEBUG |
| 232 void validate() const; | 237 void validate() const; |
| 233 #else | 238 #else |
| 234 void validate() const {} | 239 void validate() const {} |
| 235 #endif | 240 #endif |
| 236 }; | 241 }; |
| 237 #endif | 242 #endif |
| OLD | NEW |