OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CC_TILES_SOFTWARE_IMAGE_DECODE_CACHE_H_ | 5 #ifndef CC_TILES_SOFTWARE_IMAGE_DECODE_CACHE_H_ |
6 #define CC_TILES_SOFTWARE_IMAGE_DECODE_CACHE_H_ | 6 #define CC_TILES_SOFTWARE_IMAGE_DECODE_CACHE_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
133 scoped_refptr<TileTask>* task) override; | 133 scoped_refptr<TileTask>* task) override; |
134 void UnrefImage(const DrawImage& image) override; | 134 void UnrefImage(const DrawImage& image) override; |
135 DecodedDrawImage GetDecodedImageForDraw(const DrawImage& image) override; | 135 DecodedDrawImage GetDecodedImageForDraw(const DrawImage& image) override; |
136 void DrawWithImageFinished(const DrawImage& image, | 136 void DrawWithImageFinished(const DrawImage& image, |
137 const DecodedDrawImage& decoded_image) override; | 137 const DecodedDrawImage& decoded_image) override; |
138 void ReduceCacheUsage() override; | 138 void ReduceCacheUsage() override; |
139 // Software doesn't keep outstanding images pinned, so this is a no-op. | 139 // Software doesn't keep outstanding images pinned, so this is a no-op. |
140 void SetShouldAggressivelyFreeResources( | 140 void SetShouldAggressivelyFreeResources( |
141 bool aggressively_free_resources) override {} | 141 bool aggressively_free_resources) override {} |
142 void ClearCache() override; | 142 void ClearCache() override; |
143 size_t GetMaximumMemoryLimit() const override; | |
143 | 144 |
144 // Decode the given image and store it in the cache. This is only called by an | 145 // Decode the given image and store it in the cache. This is only called by an |
145 // image decode task from a worker thread. | 146 // image decode task from a worker thread. |
146 void DecodeImage(const ImageKey& key, | 147 void DecodeImage(const ImageKey& key, |
147 const DrawImage& image, | 148 const DrawImage& image, |
148 DecodeTaskType task_type); | 149 DecodeTaskType task_type); |
149 | 150 |
150 void RemovePendingTask(const ImageKey& key, DecodeTaskType task_type); | 151 void RemovePendingTask(const ImageKey& key, DecodeTaskType task_type); |
151 | 152 |
152 // MemoryDumpProvider overrides. | 153 // MemoryDumpProvider overrides. |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
213 explicit MemoryBudget(size_t limit_bytes); | 214 explicit MemoryBudget(size_t limit_bytes); |
214 | 215 |
215 size_t AvailableMemoryBytes() const; | 216 size_t AvailableMemoryBytes() const; |
216 void AddUsage(size_t usage); | 217 void AddUsage(size_t usage); |
217 void SubtractUsage(size_t usage); | 218 void SubtractUsage(size_t usage); |
218 void ResetUsage(); | 219 void ResetUsage(); |
219 size_t total_limit_bytes() const { return limit_bytes_; } | 220 size_t total_limit_bytes() const { return limit_bytes_; } |
220 size_t GetCurrentUsageSafe() const; | 221 size_t GetCurrentUsageSafe() const; |
221 | 222 |
222 private: | 223 private: |
223 size_t limit_bytes_; | 224 const size_t limit_bytes_; |
224 base::CheckedNumeric<size_t> current_usage_bytes_; | 225 base::CheckedNumeric<size_t> current_usage_bytes_; |
225 }; | 226 }; |
226 | 227 |
227 using ImageMRUCache = base:: | 228 using ImageMRUCache = base:: |
228 HashingMRUCache<ImageKey, std::unique_ptr<DecodedImage>, ImageKeyHash>; | 229 HashingMRUCache<ImageKey, std::unique_ptr<DecodedImage>, ImageKeyHash>; |
229 | 230 |
230 // Looks for the key in the cache and returns true if it was found and was | 231 // Looks for the key in the cache and returns true if it was found and was |
231 // successfully locked (or if it was already locked). Note that if this | 232 // successfully locked (or if it was already locked). Note that if this |
232 // function returns true, then a ref count is increased for the image. | 233 // function returns true, then a ref count is increased for the image. |
233 bool LockDecodedImageIfPossibleAndRef(const ImageKey& key); | 234 bool LockDecodedImageIfPossibleAndRef(const ImageKey& key); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
299 DecodeTaskType type, | 300 DecodeTaskType type, |
300 scoped_refptr<TileTask>* task); | 301 scoped_refptr<TileTask>* task); |
301 | 302 |
302 std::unordered_map<ImageKey, scoped_refptr<TileTask>, ImageKeyHash> | 303 std::unordered_map<ImageKey, scoped_refptr<TileTask>, ImageKeyHash> |
303 pending_in_raster_image_tasks_; | 304 pending_in_raster_image_tasks_; |
304 std::unordered_map<ImageKey, scoped_refptr<TileTask>, ImageKeyHash> | 305 std::unordered_map<ImageKey, scoped_refptr<TileTask>, ImageKeyHash> |
305 pending_out_of_raster_image_tasks_; | 306 pending_out_of_raster_image_tasks_; |
306 | 307 |
307 // The members below this comment can only be accessed if the lock is held to | 308 // The members below this comment can only be accessed if the lock is held to |
308 // ensure that they are safe to access on multiple threads. | 309 // ensure that they are safe to access on multiple threads. |
310 // The exception is accessing |locked_images_budget_.total_limit_bytes()|, | |
311 // which is const and thread safe. | |
Khushal
2017/04/28 00:12:53
nit: Can you make |limit_bytes_| in MemoryBudget c
Khushal
2017/04/28 00:18:46
Note to self: Look for colors other than green.
vmpstr
2017/04/28 17:18:30
Acknowledged.
| |
309 base::Lock lock_; | 312 base::Lock lock_; |
310 | 313 |
311 // Decoded images and ref counts (predecode path). | 314 // Decoded images and ref counts (predecode path). |
312 ImageMRUCache decoded_images_; | 315 ImageMRUCache decoded_images_; |
313 std::unordered_map<ImageKey, int, ImageKeyHash> decoded_images_ref_counts_; | 316 std::unordered_map<ImageKey, int, ImageKeyHash> decoded_images_ref_counts_; |
314 | 317 |
315 // Decoded image and ref counts (at-raster decode path). | 318 // Decoded image and ref counts (at-raster decode path). |
316 ImageMRUCache at_raster_decoded_images_; | 319 ImageMRUCache at_raster_decoded_images_; |
317 std::unordered_map<ImageKey, int, ImageKeyHash> | 320 std::unordered_map<ImageKey, int, ImageKeyHash> |
318 at_raster_decoded_images_ref_counts_; | 321 at_raster_decoded_images_ref_counts_; |
319 | 322 |
320 MemoryBudget locked_images_budget_; | 323 MemoryBudget locked_images_budget_; |
321 | 324 |
322 ResourceFormat format_; | 325 ResourceFormat format_; |
323 size_t max_items_in_cache_; | 326 size_t max_items_in_cache_; |
324 | 327 |
325 // Used to uniquely identify DecodedImages for memory traces. | 328 // Used to uniquely identify DecodedImages for memory traces. |
326 base::AtomicSequenceNumber next_tracing_id_; | 329 base::AtomicSequenceNumber next_tracing_id_; |
327 }; | 330 }; |
328 | 331 |
329 } // namespace cc | 332 } // namespace cc |
330 | 333 |
331 #endif // CC_TILES_SOFTWARE_IMAGE_DECODE_CACHE_H_ | 334 #endif // CC_TILES_SOFTWARE_IMAGE_DECODE_CACHE_H_ |
OLD | NEW |