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