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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 }; | 102 }; |
103 | 103 |
104 class CC_EXPORT SoftwareImageDecodeCache | 104 class CC_EXPORT SoftwareImageDecodeCache |
105 : public ImageDecodeCache, | 105 : public ImageDecodeCache, |
106 public base::trace_event::MemoryDumpProvider, | 106 public base::trace_event::MemoryDumpProvider, |
107 public base::MemoryCoordinatorClient { | 107 public base::MemoryCoordinatorClient { |
108 public: | 108 public: |
109 using ImageKey = ImageDecodeCacheKey; | 109 using ImageKey = ImageDecodeCacheKey; |
110 using ImageKeyHash = ImageDecodeCacheKeyHash; | 110 using ImageKeyHash = ImageDecodeCacheKeyHash; |
111 | 111 |
112 enum class DecodeTaskType { USE_IN_RASTER_TASKS, USE_OUT_OF_RASTER_TASKS }; | |
113 | |
114 SoftwareImageDecodeCache(ResourceFormat format, | 112 SoftwareImageDecodeCache(ResourceFormat format, |
115 size_t locked_memory_limit_bytes); | 113 size_t locked_memory_limit_bytes); |
116 ~SoftwareImageDecodeCache() override; | 114 ~SoftwareImageDecodeCache() override; |
117 | 115 |
118 // ImageDecodeCache overrides. | 116 // ImageDecodeCache overrides. |
119 bool GetTaskForImageAndRef(const DrawImage& image, | 117 bool GetTaskForImageAndRef(const DrawImage& image, |
120 const TracingInfo& tracing_info, | 118 const TracingInfo& tracing_info, |
121 scoped_refptr<TileTask>* task) override; | 119 scoped_refptr<TileTask>* task) override; |
122 bool GetOutOfRasterDecodeTaskForImageAndRef( | |
123 const DrawImage& image, | |
124 scoped_refptr<TileTask>* task) override; | |
125 void UnrefImage(const DrawImage& image) override; | 120 void UnrefImage(const DrawImage& image) override; |
126 DecodedDrawImage GetDecodedImageForDraw(const DrawImage& image) override; | 121 DecodedDrawImage GetDecodedImageForDraw(const DrawImage& image) override; |
127 void DrawWithImageFinished(const DrawImage& image, | 122 void DrawWithImageFinished(const DrawImage& image, |
128 const DecodedDrawImage& decoded_image) override; | 123 const DecodedDrawImage& decoded_image) override; |
129 void ReduceCacheUsage() override; | 124 void ReduceCacheUsage() override; |
130 // Software doesn't keep outstanding images pinned, so this is a no-op. | 125 // Software doesn't keep outstanding images pinned, so this is a no-op. |
131 void SetShouldAggressivelyFreeResources( | 126 void SetShouldAggressivelyFreeResources( |
132 bool aggressively_free_resources) override {} | 127 bool aggressively_free_resources) override {} |
133 | 128 |
134 // Decode the given image and store it in the cache. This is only called by an | 129 // Decode the given image and store it in the cache. This is only called by an |
135 // image decode task from a worker thread. | 130 // image decode task from a worker thread. |
136 void DecodeImage(const ImageKey& key, | 131 void DecodeImage(const ImageKey& key, const DrawImage& image); |
137 const DrawImage& image, | |
138 DecodeTaskType task_type); | |
139 | 132 |
140 void RemovePendingTask(const ImageKey& key, DecodeTaskType task_type); | 133 void RemovePendingTask(const ImageKey& key); |
141 | 134 |
142 // MemoryDumpProvider overrides. | 135 // MemoryDumpProvider overrides. |
143 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, | 136 bool OnMemoryDump(const base::trace_event::MemoryDumpArgs& args, |
144 base::trace_event::ProcessMemoryDump* pmd) override; | 137 base::trace_event::ProcessMemoryDump* pmd) override; |
145 | 138 |
146 private: | 139 private: |
147 // DecodedImage is a convenience storage for discardable memory. It can also | 140 // DecodedImage is a convenience storage for discardable memory. It can also |
148 // construct an image out of SkImageInfo and stored discardable memory. | 141 // construct an image out of SkImageInfo and stored discardable memory. |
149 class DecodedImage { | 142 class DecodedImage { |
150 public: | 143 public: |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 void UnrefAtRasterImage(const ImageKey& key); | 260 void UnrefAtRasterImage(const ImageKey& key); |
268 | 261 |
269 // Helper function which dumps all images in a specific ImageMRUCache. | 262 // Helper function which dumps all images in a specific ImageMRUCache. |
270 void DumpImageMemoryForCache(const ImageMRUCache& cache, | 263 void DumpImageMemoryForCache(const ImageMRUCache& cache, |
271 const char* cache_name, | 264 const char* cache_name, |
272 base::trace_event::ProcessMemoryDump* pmd) const; | 265 base::trace_event::ProcessMemoryDump* pmd) const; |
273 | 266 |
274 // Overriden from base::MemoryCoordinatorClient. | 267 // Overriden from base::MemoryCoordinatorClient. |
275 void OnMemoryStateChange(base::MemoryState state) override; | 268 void OnMemoryStateChange(base::MemoryState state) override; |
276 | 269 |
277 // Helper method to get the different tasks. Note that this should be used as | |
278 // if it was public (ie, all of the locks need to be properly acquired). | |
279 bool GetTaskForImageAndRefInternal(const DrawImage& image, | |
280 const TracingInfo& tracing_info, | |
281 DecodeTaskType type, | |
282 scoped_refptr<TileTask>* task); | |
283 | |
284 std::unordered_map<ImageKey, scoped_refptr<TileTask>, ImageKeyHash> | 270 std::unordered_map<ImageKey, scoped_refptr<TileTask>, ImageKeyHash> |
285 pending_in_raster_image_tasks_; | 271 pending_image_tasks_; |
286 std::unordered_map<ImageKey, scoped_refptr<TileTask>, ImageKeyHash> | |
287 pending_out_of_raster_image_tasks_; | |
288 | 272 |
289 // The members below this comment can only be accessed if the lock is held to | 273 // The members below this comment can only be accessed if the lock is held to |
290 // ensure that they are safe to access on multiple threads. | 274 // ensure that they are safe to access on multiple threads. |
291 base::Lock lock_; | 275 base::Lock lock_; |
292 | 276 |
293 // Decoded images and ref counts (predecode path). | 277 // Decoded images and ref counts (predecode path). |
294 ImageMRUCache decoded_images_; | 278 ImageMRUCache decoded_images_; |
295 std::unordered_map<ImageKey, int, ImageKeyHash> decoded_images_ref_counts_; | 279 std::unordered_map<ImageKey, int, ImageKeyHash> decoded_images_ref_counts_; |
296 | 280 |
297 // Decoded image and ref counts (at-raster decode path). | 281 // Decoded image and ref counts (at-raster decode path). |
298 ImageMRUCache at_raster_decoded_images_; | 282 ImageMRUCache at_raster_decoded_images_; |
299 std::unordered_map<ImageKey, int, ImageKeyHash> | 283 std::unordered_map<ImageKey, int, ImageKeyHash> |
300 at_raster_decoded_images_ref_counts_; | 284 at_raster_decoded_images_ref_counts_; |
301 | 285 |
302 MemoryBudget locked_images_budget_; | 286 MemoryBudget locked_images_budget_; |
303 | 287 |
304 ResourceFormat format_; | 288 ResourceFormat format_; |
305 size_t max_items_in_cache_; | 289 size_t max_items_in_cache_; |
306 | 290 |
307 // Used to uniquely identify DecodedImages for memory traces. | 291 // Used to uniquely identify DecodedImages for memory traces. |
308 base::AtomicSequenceNumber next_tracing_id_; | 292 base::AtomicSequenceNumber next_tracing_id_; |
309 }; | 293 }; |
310 | 294 |
311 } // namespace cc | 295 } // namespace cc |
312 | 296 |
313 #endif // CC_TILES_SOFTWARE_IMAGE_DECODE_CACHE_H_ | 297 #endif // CC_TILES_SOFTWARE_IMAGE_DECODE_CACHE_H_ |
OLD | NEW |