| 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/ref_counted.h" | 18 #include "base/memory/ref_counted.h" |
| 19 #include "base/numerics/safe_math.h" | 19 #include "base/numerics/safe_math.h" |
| 20 #include "base/threading/thread_checker.h" | 20 #include "base/threading/thread_checker.h" |
| 21 #include "base/trace_event/memory_dump_provider.h" | 21 #include "base/trace_event/memory_dump_provider.h" |
| 22 #include "cc/base/cc_export.h" | 22 #include "cc/base/cc_export.h" |
| 23 #include "cc/playback/decoded_draw_image.h" | 23 #include "cc/playback/decoded_draw_image.h" |
| 24 #include "cc/playback/draw_image.h" | 24 #include "cc/playback/draw_image.h" |
| 25 #include "cc/resources/resource_format.h" | 25 #include "cc/resources/resource_format.h" |
| 26 #include "cc/tiles/image_decode_controller.h" | 26 #include "cc/tiles/image_decode_controller.h" |
| 27 #include "components/memory_coordinator/common/memory_coordinator_client.h" |
| 27 #include "third_party/skia/include/core/SkRefCnt.h" | 28 #include "third_party/skia/include/core/SkRefCnt.h" |
| 28 #include "ui/gfx/geometry/rect.h" | 29 #include "ui/gfx/geometry/rect.h" |
| 29 | 30 |
| 30 namespace cc { | 31 namespace cc { |
| 31 | 32 |
| 32 // ImageDecodeControllerKey is a class that gets a cache key out of a given draw | 33 // ImageDecodeControllerKey is a class that gets a cache key out of a given draw |
| 33 // image. That is, this key uniquely identifies an image in the cache. Note that | 34 // image. That is, this key uniquely identifies an image in the cache. Note that |
| 34 // it's insufficient to use SkImage's unique id, since the same image can appear | 35 // it's insufficient to use SkImage's unique id, since the same image can appear |
| 35 // in the cache multiple times at different scales and filter qualities. | 36 // in the cache multiple times at different scales and filter qualities. |
| 36 class CC_EXPORT ImageDecodeControllerKey { | 37 class CC_EXPORT ImageDecodeControllerKey { |
| (...skipping 58 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 memory_coordinator::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 memory_coordinator::MemoryCoordinatorClient. |
| 270 void OnMemoryStateChange( |
| 271 memory_coordinator::mojom::MemoryState state) override; |
| 272 |
| 267 std::unordered_map<ImageKey, scoped_refptr<TileTask>, ImageKeyHash> | 273 std::unordered_map<ImageKey, scoped_refptr<TileTask>, ImageKeyHash> |
| 268 pending_image_tasks_; | 274 pending_image_tasks_; |
| 269 | 275 |
| 270 // The members below this comment can only be accessed if the lock is held to | 276 // 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. | 277 // ensure that they are safe to access on multiple threads. |
| 272 base::Lock lock_; | 278 base::Lock lock_; |
| 273 | 279 |
| 274 // Decoded images and ref counts (predecode path). | 280 // Decoded images and ref counts (predecode path). |
| 275 ImageMRUCache decoded_images_; | 281 ImageMRUCache decoded_images_; |
| 276 std::unordered_map<ImageKey, int, ImageKeyHash> decoded_images_ref_counts_; | 282 std::unordered_map<ImageKey, int, ImageKeyHash> decoded_images_ref_counts_; |
| 277 | 283 |
| 278 // Decoded image and ref counts (at-raster decode path). | 284 // Decoded image and ref counts (at-raster decode path). |
| 279 ImageMRUCache at_raster_decoded_images_; | 285 ImageMRUCache at_raster_decoded_images_; |
| 280 std::unordered_map<ImageKey, int, ImageKeyHash> | 286 std::unordered_map<ImageKey, int, ImageKeyHash> |
| 281 at_raster_decoded_images_ref_counts_; | 287 at_raster_decoded_images_ref_counts_; |
| 282 | 288 |
| 283 MemoryBudget locked_images_budget_; | 289 MemoryBudget locked_images_budget_; |
| 284 | 290 |
| 285 ResourceFormat format_; | 291 ResourceFormat format_; |
| 286 | 292 |
| 287 // Used to uniquely identify DecodedImages for memory traces. | 293 // Used to uniquely identify DecodedImages for memory traces. |
| 288 base::AtomicSequenceNumber next_tracing_id_; | 294 base::AtomicSequenceNumber next_tracing_id_; |
| 289 }; | 295 }; |
| 290 | 296 |
| 291 } // namespace cc | 297 } // namespace cc |
| 292 | 298 |
| 293 #endif // CC_TILES_SOFTWARE_IMAGE_DECODE_CONTROLLER_H_ | 299 #endif // CC_TILES_SOFTWARE_IMAGE_DECODE_CONTROLLER_H_ |
| OLD | NEW |