OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 public: | 154 public: |
155 enum CacheType { | 155 enum CacheType { |
156 TypeImage, | 156 TypeImage, |
157 TypeDecoder, | 157 TypeDecoder, |
158 }; | 158 }; |
159 | 159 |
160 CacheEntry(const ImageFrameGenerator* generator, int useCount, bool isDi
scardable) | 160 CacheEntry(const ImageFrameGenerator* generator, int useCount, bool isDi
scardable) |
161 : m_generator(generator) | 161 : m_generator(generator) |
162 , m_useCount(useCount) | 162 , m_useCount(useCount) |
163 , m_isDiscardable(isDiscardable) | 163 , m_isDiscardable(isDiscardable) |
| 164 , m_isAccountingEnabled(true) |
164 , m_prev(0) | 165 , m_prev(0) |
165 , m_next(0) | 166 , m_next(0) |
166 { | 167 { |
167 } | 168 } |
168 | 169 |
169 virtual ~CacheEntry() | 170 virtual ~CacheEntry() |
170 { | 171 { |
171 ASSERT(!m_useCount); | 172 ASSERT(!m_useCount); |
172 } | 173 } |
173 | 174 |
174 const ImageFrameGenerator* generator() const { return m_generator; } | 175 const ImageFrameGenerator* generator() const { return m_generator; } |
175 int useCount() const { return m_useCount; } | 176 int useCount() const { return m_useCount; } |
176 void incrementUseCount() { ++m_useCount; } | 177 void incrementUseCount() { ++m_useCount; } |
177 void decrementUseCount() { --m_useCount; ASSERT(m_useCount >= 0); } | 178 void decrementUseCount() { --m_useCount; ASSERT(m_useCount >= 0); } |
178 bool isDiscardable() const { return m_isDiscardable; } | 179 bool isDiscardable() const { return m_isDiscardable; } |
179 | 180 |
| 181 void disableAccounting() { m_isAccountingEnabled = false; } |
| 182 bool isAccountingEnabled() const { return m_isAccountingEnabled; } |
| 183 |
180 // FIXME: getSafeSize() returns size in bytes truncated to a 32-bits int
eger. | 184 // FIXME: getSafeSize() returns size in bytes truncated to a 32-bits int
eger. |
181 // Find a way to get the size in 64-bits. | 185 // Find a way to get the size in 64-bits. |
182 virtual size_t memoryUsageInBytes() const = 0; | 186 virtual size_t memoryUsageInBytes() const = 0; |
183 virtual CacheType type() const = 0; | 187 virtual CacheType type() const = 0; |
184 | 188 |
185 protected: | 189 protected: |
186 const ImageFrameGenerator* m_generator; | 190 const ImageFrameGenerator* m_generator; |
187 int m_useCount; | 191 int m_useCount; |
188 bool m_isDiscardable; | 192 bool m_isDiscardable; |
| 193 bool m_isAccountingEnabled; |
189 | 194 |
190 private: | 195 private: |
191 CacheEntry* m_prev; | 196 CacheEntry* m_prev; |
192 CacheEntry* m_next; | 197 CacheEntry* m_next; |
193 }; | 198 }; |
194 | 199 |
195 class ImageCacheEntry : public CacheEntry { | 200 class ImageCacheEntry : public CacheEntry { |
196 public: | 201 public: |
197 static PassOwnPtr<ImageCacheEntry> createAndUse(const ImageFrameGenerato
r* generator, PassOwnPtr<ScaledImageFragment> image) | 202 static PassOwnPtr<ImageCacheEntry> createAndUse(const ImageFrameGenerato
r* generator, PassOwnPtr<ScaledImageFragment> image) |
198 { | 203 { |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 typedef HashSet<ImageCacheKey> ImageCacheKeySet; | 314 typedef HashSet<ImageCacheKey> ImageCacheKeySet; |
310 typedef HashMap<const ImageFrameGenerator*, ImageCacheKeySet> ImageCacheKeyM
ap; | 315 typedef HashMap<const ImageFrameGenerator*, ImageCacheKeySet> ImageCacheKeyM
ap; |
311 ImageCacheKeyMap m_imageCacheKeyMap; | 316 ImageCacheKeyMap m_imageCacheKeyMap; |
312 | 317 |
313 // A lookup table to map ImageFrameGenerator to all associated | 318 // A lookup table to map ImageFrameGenerator to all associated |
314 // decoder cache keys. | 319 // decoder cache keys. |
315 typedef HashSet<DecoderCacheKey> DecoderCacheKeySet; | 320 typedef HashSet<DecoderCacheKey> DecoderCacheKeySet; |
316 typedef HashMap<const ImageFrameGenerator*, DecoderCacheKeySet> DecoderCache
KeyMap; | 321 typedef HashMap<const ImageFrameGenerator*, DecoderCacheKeySet> DecoderCache
KeyMap; |
317 DecoderCacheKeyMap m_decoderCacheKeyMap; | 322 DecoderCacheKeyMap m_decoderCacheKeyMap; |
318 | 323 |
| 324 size_t m_discardableEntriesCount; |
319 size_t m_cacheLimitInBytes; | 325 size_t m_cacheLimitInBytes; |
320 size_t m_memoryUsageInBytes; | 326 size_t m_memoryUsageInBytes; |
321 | 327 |
322 // Protect concurrent access to these members: | 328 // Protect concurrent access to these members: |
323 // m_orderedCacheList | 329 // m_orderedCacheList |
324 // m_imageCacheMap, m_decoderCacheMap and all CacheEntrys stored in it | 330 // m_imageCacheMap, m_decoderCacheMap and all CacheEntrys stored in it |
325 // m_imageCacheKeyMap | 331 // m_imageCacheKeyMap |
326 // m_decoderCacheKeyMap | 332 // m_decoderCacheKeyMap |
327 // m_cacheLimitInBytes | 333 // m_cacheLimitInBytes |
328 // m_memoryUsageInBytes | 334 // m_memoryUsageInBytes |
329 // This mutex also protects calls to underlying skBitmap's | 335 // This mutex also protects calls to underlying skBitmap's |
330 // lockPixels()/unlockPixels() as they are not threadsafe. | 336 // lockPixels()/unlockPixels() as they are not threadsafe. |
331 Mutex m_mutex; | 337 Mutex m_mutex; |
332 }; | 338 }; |
333 | 339 |
334 } // namespace WebCore | 340 } // namespace WebCore |
335 | 341 |
336 #endif | 342 #endif |
OLD | NEW |