OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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_CHECKER_IMAGE_TRACKER_H_ | 5 #ifndef CC_TILES_CHECKER_IMAGE_TRACKER_H_ |
6 #define CC_TILES_CHECKER_IMAGE_TRACKER_H_ | 6 #define CC_TILES_CHECKER_IMAGE_TRACKER_H_ |
7 | 7 |
8 #include <unordered_map> | 8 #include <unordered_map> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 15 matching lines...) Expand all Loading... |
26 // CheckerImageTracker is used to track the set of images in a frame which are | 26 // CheckerImageTracker is used to track the set of images in a frame which are |
27 // decoded asynchronously, using the ImageDecodeService, from the rasterization | 27 // decoded asynchronously, using the ImageDecodeService, from the rasterization |
28 // of tiles which depend on them. Once decoded, these images are stored for | 28 // of tiles which depend on them. Once decoded, these images are stored for |
29 // invalidation on the next sync tree. TakeImagesToInvalidateOnSyncTree will | 29 // invalidation on the next sync tree. TakeImagesToInvalidateOnSyncTree will |
30 // return this set and maintain a copy to keeps these images locked until the | 30 // return this set and maintain a copy to keeps these images locked until the |
31 // sync tree is activated. | 31 // sync tree is activated. |
32 // Note: It is illegal to call TakeImagesToInvalidateOnSyncTree for the next | 32 // Note: It is illegal to call TakeImagesToInvalidateOnSyncTree for the next |
33 // sync tree until the previous tree is activated. | 33 // sync tree until the previous tree is activated. |
34 class CC_EXPORT CheckerImageTracker { | 34 class CC_EXPORT CheckerImageTracker { |
35 public: | 35 public: |
| 36 // The priority type for a decode. Note we use int to specify a decreasing |
| 37 // order of priority with higher values. |
| 38 enum DecodeType : int { |
| 39 // Priority for images on tiles being rasterized (visible or pre-paint). |
| 40 kRaster = 0, |
| 41 // Lowest priority for images on tiles in pre-decode region. These are tiles |
| 42 // which are beyond the pre-paint region, but have their images decoded. |
| 43 kPreDecode = 1, |
| 44 |
| 45 kLast = kPreDecode |
| 46 }; |
| 47 |
| 48 struct CC_EXPORT ImageDecodeRequest { |
| 49 ImageDecodeRequest(PaintImage paint_image, DecodeType type); |
| 50 PaintImage paint_image; |
| 51 DecodeType type; |
| 52 }; |
| 53 |
36 CheckerImageTracker(ImageController* image_controller, | 54 CheckerImageTracker(ImageController* image_controller, |
37 CheckerImageTrackerClient* client, | 55 CheckerImageTrackerClient* client, |
38 bool enable_checker_imaging); | 56 bool enable_checker_imaging); |
39 ~CheckerImageTracker(); | 57 ~CheckerImageTracker(); |
40 | 58 |
41 // Returns true if the decode for |image| will be deferred to the image decode | 59 // Returns true if the decode for |image| will be deferred to the image decode |
42 // service and it should be be skipped during raster. | 60 // service and it should be be skipped during raster. |
43 bool ShouldCheckerImage(const DrawImage& image, WhichTree tree); | 61 bool ShouldCheckerImage(const DrawImage& image, WhichTree tree); |
44 | 62 |
45 using ImageDecodeQueue = std::vector<PaintImage>; | 63 // Provides a prioritized queue of images to decode. |
| 64 using ImageDecodeQueue = std::vector<ImageDecodeRequest>; |
46 void ScheduleImageDecodeQueue(ImageDecodeQueue image_decode_queue); | 65 void ScheduleImageDecodeQueue(ImageDecodeQueue image_decode_queue); |
47 | 66 |
| 67 // Disables scheduling any decode work by the tracker. |
| 68 void SetNoDecodesAllowed(); |
| 69 |
| 70 // The max decode priority type that is allowed to run. |
| 71 void SetMaxDecodePriorityAllowed(DecodeType decode_type); |
| 72 |
48 // Returns the set of images to invalidate on the sync tree. | 73 // Returns the set of images to invalidate on the sync tree. |
49 const PaintImageIdFlatSet& TakeImagesToInvalidateOnSyncTree(); | 74 const PaintImageIdFlatSet& TakeImagesToInvalidateOnSyncTree(); |
50 | 75 |
51 // Called when the sync tree is activated. Each call to | 76 // Called when the sync tree is activated. Each call to |
52 // TakeImagesToInvalidateOnSyncTree() must be followed by this when the | 77 // TakeImagesToInvalidateOnSyncTree() must be followed by this when the |
53 // invalidated sync tree is activated. | 78 // invalidated sync tree is activated. |
54 void DidActivateSyncTree(); | 79 void DidActivateSyncTree(); |
55 | 80 |
56 // Called to reset the tracker state on navigation. This will release all | 81 // Called to reset the tracker state on navigation. This will release all |
57 // cached images. Setting |can_clear_decode_policy_tracking| will also result | 82 // cached images. Setting |can_clear_decode_policy_tracking| will also result |
58 // in re-checkering any images already decoded by the tracker. | 83 // in re-checkering any images already decoded by the tracker. |
59 void ClearTracker(bool can_clear_decode_policy_tracking); | 84 void ClearTracker(bool can_clear_decode_policy_tracking); |
60 | 85 |
61 // Informs the tracker to not checker the given image. This can be used to opt | 86 // Informs the tracker to not checker the given image. This can be used to opt |
62 // out of the checkering behavior for certain images, such as ones that were | 87 // out of the checkering behavior for certain images, such as ones that were |
63 // decoded using the img.decode api. | 88 // decoded using the img.decode api. |
64 // Note that if the image is already being checkered, then it will continue to | 89 // Note that if the image is already being checkered, then it will continue to |
65 // do so. This call is meant to be issued prior to the image appearing during | 90 // do so. This call is meant to be issued prior to the image appearing during |
66 // raster. | 91 // raster. |
67 void DisallowCheckeringForImage(const PaintImage& image); | 92 void DisallowCheckeringForImage(const PaintImage& image); |
68 | 93 |
69 bool has_locked_decodes_for_testing() const { | 94 bool has_locked_decodes_for_testing() const { |
70 return !image_id_to_decode_.empty(); | 95 return !image_id_to_decode_.empty(); |
71 } | 96 } |
72 | 97 |
| 98 int decode_priority_allowed_for_testing() const { |
| 99 return decode_priority_allowed_; |
| 100 } |
| 101 bool no_decodes_allowed_for_testing() const { |
| 102 return decode_priority_allowed_ == kNoDecodeAllowedPriority; |
| 103 } |
| 104 |
73 private: | 105 private: |
| 106 static const int kNoDecodeAllowedPriority; |
| 107 |
74 enum class DecodePolicy { | 108 enum class DecodePolicy { |
75 // The image can be decoded asynchronously from raster. When set, the image | 109 // The image can be decoded asynchronously from raster. When set, the image |
76 // is always skipped during rasterization of content that includes this | 110 // is always skipped during rasterization of content that includes this |
77 // image until it has been decoded using the decode service. | 111 // image until it has been decoded using the decode service. |
78 ASYNC, | 112 ASYNC, |
79 // The image has been decoded asynchronously once and should now be | 113 // The image has been decoded asynchronously once and should now be |
80 // synchronously rasterized with the content or the image has been | 114 // synchronously rasterized with the content or the image has been |
81 // permanently vetoed from being decoded async. | 115 // permanently vetoed from being decoded async. |
82 SYNC | 116 SYNC |
83 }; | 117 }; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
127 PaintImageIdFlatSet images_pending_invalidation_; | 161 PaintImageIdFlatSet images_pending_invalidation_; |
128 | 162 |
129 // A set of images which were invalidated on the current sync tree. | 163 // A set of images which were invalidated on the current sync tree. |
130 PaintImageIdFlatSet invalidated_images_on_current_sync_tree_; | 164 PaintImageIdFlatSet invalidated_images_on_current_sync_tree_; |
131 | 165 |
132 // The queue of images pending decode. We maintain a queue to ensure that the | 166 // The queue of images pending decode. We maintain a queue to ensure that the |
133 // order in which images are decoded is aligned with the priority of the tiles | 167 // order in which images are decoded is aligned with the priority of the tiles |
134 // dependent on these images. | 168 // dependent on these images. |
135 ImageDecodeQueue image_decode_queue_; | 169 ImageDecodeQueue image_decode_queue_; |
136 | 170 |
| 171 // The max decode type that is allowed to run, if decodes are allowed to run. |
| 172 int decode_priority_allowed_ = kNoDecodeAllowedPriority; |
| 173 |
137 // The currently outstanding image decode that has been scheduled with the | 174 // The currently outstanding image decode that has been scheduled with the |
138 // decode service. There can be only one outstanding decode at a time. | 175 // decode service. There can be only one outstanding decode at a time. |
139 base::Optional<PaintImage> outstanding_image_decode_; | 176 base::Optional<PaintImage> outstanding_image_decode_; |
140 | 177 |
141 // A map of ImageId to its DecodePolicy. | 178 // A map of ImageId to its DecodePolicy. |
142 std::unordered_map<PaintImage::Id, DecodeState> image_async_decode_state_; | 179 std::unordered_map<PaintImage::Id, DecodeState> image_async_decode_state_; |
143 | 180 |
144 // A map of image id to image decode request id for images to be unlocked. | 181 // A map of image id to image decode request id for images to be unlocked. |
145 std::unordered_map<PaintImage::Id, std::unique_ptr<ScopedDecodeHolder>> | 182 std::unordered_map<PaintImage::Id, std::unique_ptr<ScopedDecodeHolder>> |
146 image_id_to_decode_; | 183 image_id_to_decode_; |
147 | 184 |
148 base::WeakPtrFactory<CheckerImageTracker> weak_factory_; | 185 base::WeakPtrFactory<CheckerImageTracker> weak_factory_; |
149 | 186 |
150 DISALLOW_COPY_AND_ASSIGN(CheckerImageTracker); | 187 DISALLOW_COPY_AND_ASSIGN(CheckerImageTracker); |
151 }; | 188 }; |
152 | 189 |
153 } // namespace cc | 190 } // namespace cc |
154 | 191 |
155 #endif // CC_TILES_CHECKER_IMAGE_TRACKER_H_ | 192 #endif // CC_TILES_CHECKER_IMAGE_TRACKER_H_ |
OLD | NEW |