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/raster/tile_task_runner.h" | 25 #include "cc/raster/task.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 "skia/ext/refptr.h" | 28 #include "skia/ext/refptr.h" |
28 | 29 |
29 namespace cc { | 30 namespace cc { |
30 | 31 |
31 // ImageDecodeControllerKey is a class that gets a cache key out of a given draw | 32 // ImageDecodeControllerKey is a class that gets a cache key out of a given draw |
32 // image. That is, this key uniquely identifies an image in the cache. Note that | 33 // image. That is, this key uniquely identifies an image in the cache. Note that |
33 // it's insufficient to use SkImage's unique id, since the same image can appear | 34 // it's insufficient to use SkImage's unique id, since the same image can appear |
34 // in the cache multiple times at different scales and filter qualities. | 35 // in the cache multiple times at different scales and filter qualities. |
35 class CC_EXPORT ImageDecodeControllerKey { | 36 class CC_EXPORT ImageDecodeControllerKey { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 using ImageKey = ImageDecodeControllerKey; | 104 using ImageKey = ImageDecodeControllerKey; |
104 using ImageKeyHash = ImageDecodeControllerKeyHash; | 105 using ImageKeyHash = ImageDecodeControllerKeyHash; |
105 | 106 |
106 explicit SoftwareImageDecodeController(ResourceFormat format); | 107 explicit SoftwareImageDecodeController(ResourceFormat format); |
107 SoftwareImageDecodeController(); | 108 SoftwareImageDecodeController(); |
108 ~SoftwareImageDecodeController() override; | 109 ~SoftwareImageDecodeController() override; |
109 | 110 |
110 // ImageDecodeController overrides. | 111 // ImageDecodeController overrides. |
111 bool GetTaskForImageAndRef(const DrawImage& image, | 112 bool GetTaskForImageAndRef(const DrawImage& image, |
112 uint64_t prepare_tiles_id, | 113 uint64_t prepare_tiles_id, |
113 scoped_refptr<ImageDecodeTask>* task) override; | 114 scoped_refptr<Task>* task) override; |
114 void UnrefImage(const DrawImage& image) override; | 115 void UnrefImage(const DrawImage& image) override; |
115 DecodedDrawImage GetDecodedImageForDraw(const DrawImage& image) override; | 116 DecodedDrawImage GetDecodedImageForDraw(const DrawImage& image) override; |
116 void DrawWithImageFinished(const DrawImage& image, | 117 void DrawWithImageFinished(const DrawImage& image, |
117 const DecodedDrawImage& decoded_image) override; | 118 const DecodedDrawImage& decoded_image) override; |
118 void ReduceCacheUsage() override; | 119 void ReduceCacheUsage() override; |
119 // Software doesn't keep outstanding images pinned, so this is a no-op. | 120 // Software doesn't keep outstanding images pinned, so this is a no-op. |
120 void SetShouldAggressivelyFreeResources( | 121 void SetShouldAggressivelyFreeResources( |
121 bool aggressively_free_resources) override {} | 122 bool aggressively_free_resources) override {} |
122 void ImageDecodeTaskCompleted(Task* task) override; | 123 void ImageDecodeTaskCompleted(Task* task) override; |
123 void ImageUploadTaskCompleted(Task* task) override {} | 124 void ImageUploadTaskCompleted(Task* task) override {} |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
223 // exception of possibly prerolling them). Over time these should return | 224 // exception of possibly prerolling them). Over time these should return |
224 // "false" in less cases, as the ImageDecodeController should start handling | 225 // "false" in less cases, as the ImageDecodeController should start handling |
225 // more of them. | 226 // more of them. |
226 bool CanHandleImage(const ImageKey& key); | 227 bool CanHandleImage(const ImageKey& key); |
227 | 228 |
228 // Helper function which dumps all images in a specific ImageMRUCache. | 229 // Helper function which dumps all images in a specific ImageMRUCache. |
229 void DumpImageMemoryForCache(const ImageMRUCache& cache, | 230 void DumpImageMemoryForCache(const ImageMRUCache& cache, |
230 const char* cache_name, | 231 const char* cache_name, |
231 base::trace_event::ProcessMemoryDump* pmd) const; | 232 base::trace_event::ProcessMemoryDump* pmd) const; |
232 | 233 |
233 std::unordered_map<ImageKey, scoped_refptr<ImageDecodeTask>, ImageKeyHash> | 234 std::unordered_map<ImageKey, scoped_refptr<Task>, ImageKeyHash> |
234 pending_image_tasks_; | 235 pending_image_tasks_; |
235 | 236 |
236 // The members below this comment can only be accessed if the lock is held to | 237 // The members below this comment can only be accessed if the lock is held to |
237 // ensure that they are safe to access on multiple threads. | 238 // ensure that they are safe to access on multiple threads. |
238 base::Lock lock_; | 239 base::Lock lock_; |
239 | 240 |
240 // Decoded images and ref counts (predecode path). | 241 // Decoded images and ref counts (predecode path). |
241 ImageMRUCache decoded_images_; | 242 ImageMRUCache decoded_images_; |
242 std::unordered_map<ImageKey, int, ImageKeyHash> decoded_images_ref_counts_; | 243 std::unordered_map<ImageKey, int, ImageKeyHash> decoded_images_ref_counts_; |
243 | 244 |
(...skipping 11 matching lines...) Expand all Loading... |
255 | 256 |
256 ResourceFormat format_; | 257 ResourceFormat format_; |
257 | 258 |
258 // Used to uniquely identify DecodedImages for memory traces. | 259 // Used to uniquely identify DecodedImages for memory traces. |
259 base::AtomicSequenceNumber next_tracing_id_; | 260 base::AtomicSequenceNumber next_tracing_id_; |
260 }; | 261 }; |
261 | 262 |
262 } // namespace cc | 263 } // namespace cc |
263 | 264 |
264 #endif // CC_TILES_SOFTWARE_IMAGE_DECODE_CONTROLLER_H_ | 265 #endif // CC_TILES_SOFTWARE_IMAGE_DECODE_CONTROLLER_H_ |
OLD | NEW |