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_CONTROLLER_H_ | 5 #ifndef CC_TILES_SOFTWARE_IMAGE_DECODE_CONTROLLER_H_ |
6 #define CC_TILES_SOFTWARE_IMAGE_DECODE_CONTROLLER_H_ | 6 #define CC_TILES_SOFTWARE_IMAGE_DECODE_CONTROLLER_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 #include <unordered_map> | 11 #include <unordered_map> |
12 #include <unordered_set> | 12 #include <unordered_set> |
13 | 13 |
14 #include "base/atomic_sequence_num.h" | 14 #include "base/atomic_sequence_num.h" |
15 #include "base/containers/mru_cache.h" | 15 #include "base/containers/mru_cache.h" |
16 #include "base/hash.h" | 16 #include "base/hash.h" |
17 #include "base/memory/discardable_memory_allocator.h" | 17 #include "base/memory/discardable_memory_allocator.h" |
| 18 #include "base/memory/memory_coordinator_client.h" |
18 #include "base/memory/ref_counted.h" | 19 #include "base/memory/ref_counted.h" |
19 #include "base/numerics/safe_math.h" | 20 #include "base/numerics/safe_math.h" |
20 #include "base/threading/thread_checker.h" | 21 #include "base/threading/thread_checker.h" |
21 #include "base/trace_event/memory_dump_provider.h" | 22 #include "base/trace_event/memory_dump_provider.h" |
22 #include "cc/base/cc_export.h" | 23 #include "cc/base/cc_export.h" |
23 #include "cc/playback/decoded_draw_image.h" | 24 #include "cc/playback/decoded_draw_image.h" |
24 #include "cc/playback/draw_image.h" | 25 #include "cc/playback/draw_image.h" |
25 #include "cc/resources/resource_format.h" | 26 #include "cc/resources/resource_format.h" |
26 #include "cc/tiles/image_decode_controller.h" | 27 #include "cc/tiles/image_decode_controller.h" |
27 #include "third_party/skia/include/core/SkRefCnt.h" | 28 #include "third_party/skia/include/core/SkRefCnt.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 | 96 |
96 // Hash function for the above ImageDecodeControllerKey. | 97 // Hash function for the above ImageDecodeControllerKey. |
97 struct ImageDecodeControllerKeyHash { | 98 struct ImageDecodeControllerKeyHash { |
98 size_t operator()(const ImageDecodeControllerKey& key) const { | 99 size_t operator()(const ImageDecodeControllerKey& key) const { |
99 return key.get_hash(); | 100 return key.get_hash(); |
100 } | 101 } |
101 }; | 102 }; |
102 | 103 |
103 class CC_EXPORT SoftwareImageDecodeController | 104 class CC_EXPORT SoftwareImageDecodeController |
104 : public ImageDecodeController, | 105 : public ImageDecodeController, |
105 public base::trace_event::MemoryDumpProvider { | 106 public base::trace_event::MemoryDumpProvider, |
| 107 public base::MemoryCoordinatorClient { |
106 public: | 108 public: |
107 using ImageKey = ImageDecodeControllerKey; | 109 using ImageKey = ImageDecodeControllerKey; |
108 using ImageKeyHash = ImageDecodeControllerKeyHash; | 110 using ImageKeyHash = ImageDecodeControllerKeyHash; |
109 | 111 |
110 SoftwareImageDecodeController(ResourceFormat format, | 112 SoftwareImageDecodeController(ResourceFormat format, |
111 size_t locked_memory_limit_bytes); | 113 size_t locked_memory_limit_bytes); |
112 ~SoftwareImageDecodeController() override; | 114 ~SoftwareImageDecodeController() override; |
113 | 115 |
114 // ImageDecodeController overrides. | 116 // ImageDecodeController overrides. |
115 bool GetTaskForImageAndRef(const DrawImage& image, | 117 bool GetTaskForImageAndRef(const DrawImage& image, |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
257 void SanityCheckState(int line, bool lock_acquired); | 259 void SanityCheckState(int line, bool lock_acquired); |
258 void RefImage(const ImageKey& key); | 260 void RefImage(const ImageKey& key); |
259 void RefAtRasterImage(const ImageKey& key); | 261 void RefAtRasterImage(const ImageKey& key); |
260 void UnrefAtRasterImage(const ImageKey& key); | 262 void UnrefAtRasterImage(const ImageKey& key); |
261 | 263 |
262 // Helper function which dumps all images in a specific ImageMRUCache. | 264 // Helper function which dumps all images in a specific ImageMRUCache. |
263 void DumpImageMemoryForCache(const ImageMRUCache& cache, | 265 void DumpImageMemoryForCache(const ImageMRUCache& cache, |
264 const char* cache_name, | 266 const char* cache_name, |
265 base::trace_event::ProcessMemoryDump* pmd) const; | 267 base::trace_event::ProcessMemoryDump* pmd) const; |
266 | 268 |
| 269 // Overriden from base::MemoryCoordinatorClient. |
| 270 void OnMemoryStateChange(base::MemoryState state) override; |
| 271 |
267 std::unordered_map<ImageKey, scoped_refptr<TileTask>, ImageKeyHash> | 272 std::unordered_map<ImageKey, scoped_refptr<TileTask>, ImageKeyHash> |
268 pending_image_tasks_; | 273 pending_image_tasks_; |
269 | 274 |
270 // The members below this comment can only be accessed if the lock is held to | 275 // The members below this comment can only be accessed if the lock is held to |
271 // ensure that they are safe to access on multiple threads. | 276 // ensure that they are safe to access on multiple threads. |
272 base::Lock lock_; | 277 base::Lock lock_; |
273 | 278 |
274 // Decoded images and ref counts (predecode path). | 279 // Decoded images and ref counts (predecode path). |
275 ImageMRUCache decoded_images_; | 280 ImageMRUCache decoded_images_; |
276 std::unordered_map<ImageKey, int, ImageKeyHash> decoded_images_ref_counts_; | 281 std::unordered_map<ImageKey, int, ImageKeyHash> decoded_images_ref_counts_; |
277 | 282 |
278 // Decoded image and ref counts (at-raster decode path). | 283 // Decoded image and ref counts (at-raster decode path). |
279 ImageMRUCache at_raster_decoded_images_; | 284 ImageMRUCache at_raster_decoded_images_; |
280 std::unordered_map<ImageKey, int, ImageKeyHash> | 285 std::unordered_map<ImageKey, int, ImageKeyHash> |
281 at_raster_decoded_images_ref_counts_; | 286 at_raster_decoded_images_ref_counts_; |
282 | 287 |
283 MemoryBudget locked_images_budget_; | 288 MemoryBudget locked_images_budget_; |
284 | 289 |
285 ResourceFormat format_; | 290 ResourceFormat format_; |
286 | 291 |
287 // Used to uniquely identify DecodedImages for memory traces. | 292 // Used to uniquely identify DecodedImages for memory traces. |
288 base::AtomicSequenceNumber next_tracing_id_; | 293 base::AtomicSequenceNumber next_tracing_id_; |
289 }; | 294 }; |
290 | 295 |
291 } // namespace cc | 296 } // namespace cc |
292 | 297 |
293 #endif // CC_TILES_SOFTWARE_IMAGE_DECODE_CONTROLLER_H_ | 298 #endif // CC_TILES_SOFTWARE_IMAGE_DECODE_CONTROLLER_H_ |
OLD | NEW |