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 #include "cc/tiles/checker_image_tracker.h" | 5 #include "cc/tiles/checker_image_tracker.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 #include "base/trace_event/trace_event.h" | 9 #include "base/trace_event/trace_event.h" |
10 | 10 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 void CheckerImageTracker::DidFinishImageDecode( | 75 void CheckerImageTracker::DidFinishImageDecode( |
76 ImageId image_id, | 76 ImageId image_id, |
77 ImageController::ImageDecodeRequestId request_id, | 77 ImageController::ImageDecodeRequestId request_id, |
78 ImageController::ImageDecodeResult result) { | 78 ImageController::ImageDecodeResult result) { |
79 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | 79 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
80 "CheckerImageTracker::DidFinishImageDecode"); | 80 "CheckerImageTracker::DidFinishImageDecode"); |
81 TRACE_EVENT_ASYNC_END0("cc", "CheckerImageTracker::DeferImageDecode", | 81 TRACE_EVENT_ASYNC_END0("cc", "CheckerImageTracker::DeferImageDecode", |
82 image_id); | 82 image_id); |
83 | 83 |
84 DCHECK_NE(ImageController::ImageDecodeResult::DECODE_NOT_REQUIRED, result); | 84 DCHECK_NE(ImageController::ImageDecodeResult::DECODE_NOT_REQUIRED, result); |
85 DCHECK_EQ(outstanding_image_decode_->uniqueID(), image_id); | 85 DCHECK_EQ(outstanding_image_decode_.value().stable_id(), image_id); |
86 | 86 |
87 outstanding_image_decode_ = nullptr; | 87 outstanding_image_decode_.reset(); |
88 image_async_decode_state_[image_id] = DecodePolicy::SYNC_DECODED_ONCE; | 88 image_async_decode_state_[image_id] = DecodePolicy::SYNC_DECODED_ONCE; |
89 images_pending_invalidation_.insert(image_id); | 89 images_pending_invalidation_.insert(image_id); |
90 | 90 |
91 ScheduleNextImageDecode(); | 91 ScheduleNextImageDecode(); |
92 client_->NeedsInvalidationForCheckerImagedTiles(); | 92 client_->NeedsInvalidationForCheckerImagedTiles(); |
93 } | 93 } |
94 | 94 |
95 bool CheckerImageTracker::ShouldCheckerImage(const sk_sp<const SkImage>& image, | 95 bool CheckerImageTracker::ShouldCheckerImage(const PaintImage& image, |
96 WhichTree tree) { | 96 WhichTree tree) { |
97 TRACE_EVENT1("cc", "CheckerImageTracker::ShouldCheckerImage", "image_id", | 97 TRACE_EVENT1("cc", "CheckerImageTracker::ShouldCheckerImage", "image_id", |
98 image->uniqueID()); | 98 image.stable_id()); |
99 | 99 |
100 if (!enable_checker_imaging_) | 100 if (!enable_checker_imaging_) |
101 return false; | 101 return false; |
102 | 102 |
| 103 ImageId image_id = image.stable_id(); |
| 104 |
103 // If the image was invalidated on the current sync tree and the tile is | 105 // If the image was invalidated on the current sync tree and the tile is |
104 // for the active tree, continue checkering it on the active tree to ensure | 106 // for the active tree, continue checkering it on the active tree to ensure |
105 // the image update is atomic for the frame. | 107 // the image update is atomic for the frame. |
106 if (invalidated_images_on_current_sync_tree_.count(image->uniqueID()) != 0 && | 108 if (invalidated_images_on_current_sync_tree_.count(image_id) != 0 && |
107 tree == WhichTree::ACTIVE_TREE) { | 109 tree == WhichTree::ACTIVE_TREE) { |
108 return true; | 110 return true; |
109 } | 111 } |
110 | 112 |
111 // If the image is pending invalidation, continue checkering it. All tiles | 113 // If the image is pending invalidation, continue checkering it. All tiles |
112 // for these images will be invalidated on the next pending tree. | 114 // for these images will be invalidated on the next pending tree. |
113 if (images_pending_invalidation_.find(image->uniqueID()) != | 115 if (images_pending_invalidation_.find(image_id) != |
114 images_pending_invalidation_.end()) { | 116 images_pending_invalidation_.end()) { |
115 return true; | 117 return true; |
116 } | 118 } |
117 | 119 |
118 ImageId image_id = image->uniqueID(); | |
119 auto insert_result = image_async_decode_state_.insert( | 120 auto insert_result = image_async_decode_state_.insert( |
120 std::pair<ImageId, DecodePolicy>(image_id, DecodePolicy::ASYNC)); | 121 std::pair<ImageId, DecodePolicy>(image_id, DecodePolicy::SYNC_PERMANENT)); |
121 auto it = insert_result.first; | 122 auto it = insert_result.first; |
122 if (insert_result.second) { | 123 if (insert_result.second) { |
123 size_t size = SafeSizeOfImage(image.get()); | 124 bool can_checker_image = |
124 it->second = (size >= kMinImageSizeToCheckerBytes && | 125 image.animation_type() == PaintImage::AnimationType::STATIC && |
125 size <= image_controller_->image_cache_max_limit_bytes()) | 126 image.completion_state() == PaintImage::CompletionState::DONE; |
126 ? DecodePolicy::ASYNC | 127 if (can_checker_image) { |
127 : DecodePolicy::SYNC_PERMANENT; | 128 size_t size = SafeSizeOfImage(image.sk_image().get()); |
| 129 it->second = (size >= kMinImageSizeToCheckerBytes && |
| 130 size <= image_controller_->image_cache_max_limit_bytes()) |
| 131 ? DecodePolicy::ASYNC |
| 132 : DecodePolicy::SYNC_PERMANENT; |
| 133 } |
128 } | 134 } |
129 | 135 |
130 return it->second == DecodePolicy::ASYNC; | 136 return it->second == DecodePolicy::ASYNC; |
131 } | 137 } |
132 | 138 |
133 void CheckerImageTracker::ScheduleNextImageDecode() { | 139 void CheckerImageTracker::ScheduleNextImageDecode() { |
134 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | 140 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
135 "CheckerImageTracker::ScheduleNextImageDecode"); | 141 "CheckerImageTracker::ScheduleNextImageDecode"); |
136 // We can have only one outsanding decode pending completion with the decode | 142 // We can have only one outsanding decode pending completion with the decode |
137 // service. We'll come back here when it is completed. | 143 // service. We'll come back here when it is completed. |
138 if (outstanding_image_decode_) | 144 if (outstanding_image_decode_.has_value()) |
139 return; | 145 return; |
140 | 146 |
141 while (!image_decode_queue_.empty()) { | 147 while (!image_decode_queue_.empty()) { |
142 auto candidate = std::move(image_decode_queue_.front()); | 148 auto candidate = std::move(image_decode_queue_.front()); |
143 image_decode_queue_.erase(image_decode_queue_.begin()); | 149 image_decode_queue_.erase(image_decode_queue_.begin()); |
144 | 150 |
145 // Once an image has been decoded, it can still be present in the decode | 151 // Once an image has been decoded, it can still be present in the decode |
146 // queue (duplicate entries), or while an image is still being skipped on | 152 // queue (duplicate entries), or while an image is still being skipped on |
147 // the active tree. Check if the image is still ASYNC to see if a decode is | 153 // the active tree. Check if the image is still ASYNC to see if a decode is |
148 // needed. | 154 // needed. |
149 ImageId image_id = candidate->uniqueID(); | 155 ImageId image_id = candidate.stable_id(); |
150 auto it = image_async_decode_state_.find(image_id); | 156 auto it = image_async_decode_state_.find(image_id); |
151 DCHECK(it != image_async_decode_state_.end()); | 157 DCHECK(it != image_async_decode_state_.end()); |
152 if (it->second != DecodePolicy::ASYNC) | 158 if (it->second != DecodePolicy::ASYNC) |
153 continue; | 159 continue; |
154 | 160 |
155 outstanding_image_decode_ = std::move(candidate); | 161 outstanding_image_decode_.emplace(candidate); |
156 break; | 162 break; |
157 } | 163 } |
158 | 164 |
159 // We either found an image to decode or we reached the end of the queue. If | 165 // We either found an image to decode or we reached the end of the queue. If |
160 // we couldn't find an image, we're done. | 166 // we couldn't find an image, we're done. |
161 if (!outstanding_image_decode_) { | 167 if (!outstanding_image_decode_.has_value()) { |
162 DCHECK(image_decode_queue_.empty()); | 168 DCHECK(image_decode_queue_.empty()); |
163 return; | 169 return; |
164 } | 170 } |
165 | 171 |
166 ImageId image_id = outstanding_image_decode_->uniqueID(); | 172 ImageId image_id = outstanding_image_decode_.value().stable_id(); |
167 DCHECK_EQ(image_id_to_decode_request_id_.count(image_id), 0u); | 173 DCHECK_EQ(image_id_to_decode_request_id_.count(image_id), 0u); |
168 TRACE_EVENT_ASYNC_BEGIN0("cc", "CheckerImageTracker::DeferImageDecode", | 174 TRACE_EVENT_ASYNC_BEGIN0("cc", "CheckerImageTracker::DeferImageDecode", |
169 image_id); | 175 image_id); |
170 image_id_to_decode_request_id_[image_id] = | 176 image_id_to_decode_request_id_[image_id] = |
171 image_controller_->QueueImageDecode( | 177 image_controller_->QueueImageDecode( |
172 outstanding_image_decode_, | 178 outstanding_image_decode_.value().sk_image(), |
173 base::Bind(&CheckerImageTracker::DidFinishImageDecode, | 179 base::Bind(&CheckerImageTracker::DidFinishImageDecode, |
174 weak_factory_.GetWeakPtr(), image_id)); | 180 weak_factory_.GetWeakPtr(), image_id)); |
175 } | 181 } |
176 | 182 |
177 } // namespace cc | 183 } // namespace cc |
OLD | NEW |