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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 Rec() {} | 72 Rec() {} |
73 virtual ~Rec() {} | 73 virtual ~Rec() {} |
74 | 74 |
75 uint32_t getHash() const { return this->getKey().hash(); } | 75 uint32_t getHash() const { return this->getKey().hash(); } |
76 | 76 |
77 virtual const Key& getKey() const = 0; | 77 virtual const Key& getKey() const = 0; |
78 virtual size_t bytesUsed() const = 0; | 78 virtual size_t bytesUsed() const = 0; |
79 | 79 |
80 // for memory usage diagnostics | 80 // for memory usage diagnostics |
81 virtual const char* getCategory() const = 0; | 81 virtual const char* getCategory() const = 0; |
82 virtual SkDiscardableMemory* diagnostic_only_getDiscardable() const { re
turn NULL; } | 82 virtual SkDiscardableMemory* diagnostic_only_getDiscardable() const { re
turn nullptr; } |
83 | 83 |
84 // for SkTDynamicHash::Traits | 84 // for SkTDynamicHash::Traits |
85 static uint32_t Hash(const Key& key) { return key.hash(); } | 85 static uint32_t Hash(const Key& key) { return key.hash(); } |
86 static const Key& GetKey(const Rec& rec) { return rec.getKey(); } | 86 static const Key& GetKey(const Rec& rec) { return rec.getKey(); } |
87 | 87 |
88 private: | 88 private: |
89 Rec* fNext; | 89 Rec* fNext; |
90 Rec* fPrev; | 90 Rec* fPrev; |
91 | 91 |
92 friend class SkResourceCache; | 92 friend class SkResourceCache; |
(...skipping 15 matching lines...) Expand all Loading... |
108 * (casting context to whatever it really is). | 108 * (casting context to whatever it really is). |
109 * | 109 * |
110 * The return value determines what the cache will do with the Rec. If the
function returns | 110 * The return value determines what the cache will do with the Rec. If the
function returns |
111 * true, then the Rec is considered "valid". If false is returned, the Rec
will be considered | 111 * true, then the Rec is considered "valid". If false is returned, the Rec
will be considered |
112 * "stale" and will be purged from the cache. | 112 * "stale" and will be purged from the cache. |
113 */ | 113 */ |
114 typedef bool (*FindVisitor)(const Rec&, void* context); | 114 typedef bool (*FindVisitor)(const Rec&, void* context); |
115 | 115 |
116 /** | 116 /** |
117 * Returns a locked/pinned SkDiscardableMemory instance for the specified | 117 * Returns a locked/pinned SkDiscardableMemory instance for the specified |
118 * number of bytes, or NULL on failure. | 118 * number of bytes, or nullptr on failure. |
119 */ | 119 */ |
120 typedef SkDiscardableMemory* (*DiscardableFactory)(size_t bytes); | 120 typedef SkDiscardableMemory* (*DiscardableFactory)(size_t bytes); |
121 | 121 |
122 /* | 122 /* |
123 * The following static methods are thread-safe wrappers around a global | 123 * The following static methods are thread-safe wrappers around a global |
124 * instance of this cache. | 124 * instance of this cache. |
125 */ | 125 */ |
126 | 126 |
127 /** | 127 /** |
128 * Returns true if the visitor was called on a matching Key, and the visito
r returned true. | 128 * Returns true if the visitor was called on a matching Key, and the visito
r returned true. |
(...skipping 17 matching lines...) Expand all Loading... |
146 | 146 |
147 static size_t SetSingleAllocationByteLimit(size_t); | 147 static size_t SetSingleAllocationByteLimit(size_t); |
148 static size_t GetSingleAllocationByteLimit(); | 148 static size_t GetSingleAllocationByteLimit(); |
149 static size_t GetEffectiveSingleAllocationByteLimit(); | 149 static size_t GetEffectiveSingleAllocationByteLimit(); |
150 | 150 |
151 static void PurgeAll(); | 151 static void PurgeAll(); |
152 | 152 |
153 static void TestDumpMemoryStatistics(); | 153 static void TestDumpMemoryStatistics(); |
154 | 154 |
155 /** | 155 /** |
156 * Returns the DiscardableFactory used by the global cache, or NULL. | 156 * Returns the DiscardableFactory used by the global cache, or nullptr. |
157 */ | 157 */ |
158 static DiscardableFactory GetDiscardableFactory(); | 158 static DiscardableFactory GetDiscardableFactory(); |
159 | 159 |
160 /** | 160 /** |
161 * Use this allocator for bitmaps, so they can use ashmem when available. | 161 * Use this allocator for bitmaps, so they can use ashmem when available. |
162 * Returns NULL if the ResourceCache has not been initialized with a Discard
ableFactory. | 162 * Returns nullptr if the ResourceCache has not been initialized with a Disc
ardableFactory. |
163 */ | 163 */ |
164 static SkBitmap::Allocator* GetAllocator(); | 164 static SkBitmap::Allocator* GetAllocator(); |
165 | 165 |
166 static SkCachedData* NewCachedData(size_t bytes); | 166 static SkCachedData* NewCachedData(size_t bytes); |
167 | 167 |
168 static void PostPurgeSharedID(uint64_t sharedID); | 168 static void PostPurgeSharedID(uint64_t sharedID); |
169 | 169 |
170 /** | 170 /** |
171 * Call SkDebugf() with diagnostic information about the state of the cache | 171 * Call SkDebugf() with diagnostic information about the state of the cache |
172 */ | 172 */ |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 void dump() const; | 243 void dump() const; |
244 | 244 |
245 private: | 245 private: |
246 Rec* fHead; | 246 Rec* fHead; |
247 Rec* fTail; | 247 Rec* fTail; |
248 | 248 |
249 class Hash; | 249 class Hash; |
250 Hash* fHash; | 250 Hash* fHash; |
251 | 251 |
252 DiscardableFactory fDiscardableFactory; | 252 DiscardableFactory fDiscardableFactory; |
253 // the allocator is NULL or one that matches discardables | 253 // the allocator is nullptr or one that matches discardables |
254 SkBitmap::Allocator* fAllocator; | 254 SkBitmap::Allocator* fAllocator; |
255 | 255 |
256 size_t fTotalBytesUsed; | 256 size_t fTotalBytesUsed; |
257 size_t fTotalByteLimit; | 257 size_t fTotalByteLimit; |
258 size_t fSingleAllocationByteLimit; | 258 size_t fSingleAllocationByteLimit; |
259 int fCount; | 259 int fCount; |
260 | 260 |
261 SkMessageBus<PurgeSharedIDMessage>::Inbox fPurgeSharedIDInbox; | 261 SkMessageBus<PurgeSharedIDMessage>::Inbox fPurgeSharedIDInbox; |
262 | 262 |
263 void checkMessages(); | 263 void checkMessages(); |
264 void purgeAsNeeded(bool forcePurge = false); | 264 void purgeAsNeeded(bool forcePurge = false); |
265 | 265 |
266 // linklist management | 266 // linklist management |
267 void moveToHead(Rec*); | 267 void moveToHead(Rec*); |
268 void addToHead(Rec*); | 268 void addToHead(Rec*); |
269 void detach(Rec*); | 269 void detach(Rec*); |
270 void remove(Rec*); | 270 void remove(Rec*); |
271 | 271 |
272 void init(); // called by constructors | 272 void init(); // called by constructors |
273 | 273 |
274 #ifdef SK_DEBUG | 274 #ifdef SK_DEBUG |
275 void validate() const; | 275 void validate() const; |
276 #else | 276 #else |
277 void validate() const {} | 277 void validate() const {} |
278 #endif | 278 #endif |
279 }; | 279 }; |
280 #endif | 280 #endif |
OLD | NEW |