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/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
81 // they should be accompanied with an invalidation during paint. | 81 // they should be accompanied with an invalidation during paint. |
82 image_id_to_decode_.clear(); | 82 image_id_to_decode_.clear(); |
83 | 83 |
84 if (can_clear_decode_policy_tracking) { | 84 if (can_clear_decode_policy_tracking) { |
85 image_async_decode_state_.clear(); | 85 image_async_decode_state_.clear(); |
86 } else { | 86 } else { |
87 // If we can't clear the decode policy, we need to make sure we still | 87 // If we can't clear the decode policy, we need to make sure we still |
88 // re-decode and checker images that were pending invalidation. | 88 // re-decode and checker images that were pending invalidation. |
89 for (auto image_id : images_pending_invalidation_) { | 89 for (auto image_id : images_pending_invalidation_) { |
90 auto it = image_async_decode_state_.find(image_id); | 90 auto it = image_async_decode_state_.find(image_id); |
91 | |
92 DCHECK(it != image_async_decode_state_.end()); | 91 DCHECK(it != image_async_decode_state_.end()); |
93 DCHECK_EQ(it->second, DecodePolicy::SYNC_DECODED_ONCE); | 92 DCHECK_EQ(it->second, DecodePolicy::SYNC); |
94 | |
95 it->second = DecodePolicy::ASYNC; | 93 it->second = DecodePolicy::ASYNC; |
96 } | 94 } |
97 } | 95 } |
98 images_pending_invalidation_.clear(); | 96 images_pending_invalidation_.clear(); |
99 } | 97 } |
100 | 98 |
| 99 void CheckerImageTracker::DisallowCheckeringForImage(const PaintImage& image) { |
| 100 image_async_decode_state_.insert( |
| 101 std::make_pair(image.stable_id(), DecodePolicy::SYNC)); |
| 102 } |
| 103 |
101 void CheckerImageTracker::DidFinishImageDecode( | 104 void CheckerImageTracker::DidFinishImageDecode( |
102 PaintImage::Id image_id, | 105 PaintImage::Id image_id, |
103 ImageController::ImageDecodeRequestId request_id, | 106 ImageController::ImageDecodeRequestId request_id, |
104 ImageController::ImageDecodeResult result) { | 107 ImageController::ImageDecodeResult result) { |
105 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | 108 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
106 "CheckerImageTracker::DidFinishImageDecode"); | 109 "CheckerImageTracker::DidFinishImageDecode"); |
107 TRACE_EVENT_ASYNC_END0("cc", "CheckerImageTracker::DeferImageDecode", | 110 TRACE_EVENT_ASYNC_END0("cc", "CheckerImageTracker::DeferImageDecode", |
108 image_id); | 111 image_id); |
109 | 112 |
110 DCHECK_NE(ImageController::ImageDecodeResult::DECODE_NOT_REQUIRED, result); | 113 DCHECK_NE(ImageController::ImageDecodeResult::DECODE_NOT_REQUIRED, result); |
111 DCHECK_EQ(outstanding_image_decode_.value().stable_id(), image_id); | 114 DCHECK_EQ(outstanding_image_decode_.value().stable_id(), image_id); |
112 outstanding_image_decode_.reset(); | 115 outstanding_image_decode_.reset(); |
113 | 116 |
114 // The async decode state may have been cleared if the tracker was cleared | 117 // The async decode state may have been cleared if the tracker was cleared |
115 // before this decode could be finished. | 118 // before this decode could be finished. |
116 auto it = image_async_decode_state_.find(image_id); | 119 auto it = image_async_decode_state_.find(image_id); |
117 if (it == image_async_decode_state_.end()) { | 120 if (it == image_async_decode_state_.end()) { |
118 DCHECK_EQ(image_id_to_decode_.count(image_id), 0u); | 121 DCHECK_EQ(image_id_to_decode_.count(image_id), 0u); |
119 return; | 122 return; |
120 } | 123 } |
121 | 124 |
122 it->second = DecodePolicy::SYNC_DECODED_ONCE; | 125 it->second = DecodePolicy::SYNC; |
123 images_pending_invalidation_.insert(image_id); | 126 images_pending_invalidation_.insert(image_id); |
124 ScheduleNextImageDecode(); | 127 ScheduleNextImageDecode(); |
125 client_->NeedsInvalidationForCheckerImagedTiles(); | 128 client_->NeedsInvalidationForCheckerImagedTiles(); |
126 } | 129 } |
127 | 130 |
128 bool CheckerImageTracker::ShouldCheckerImage(const PaintImage& image, | 131 bool CheckerImageTracker::ShouldCheckerImage(const PaintImage& image, |
129 WhichTree tree) { | 132 WhichTree tree) { |
130 TRACE_EVENT1("cc", "CheckerImageTracker::ShouldCheckerImage", "image_id", | 133 TRACE_EVENT1("cc", "CheckerImageTracker::ShouldCheckerImage", "image_id", |
131 image.stable_id()); | 134 image.stable_id()); |
132 | 135 |
(...skipping 10 matching lines...) Expand all Loading... |
143 return true; | 146 return true; |
144 } | 147 } |
145 | 148 |
146 // If the image is pending invalidation, continue checkering it. All tiles | 149 // If the image is pending invalidation, continue checkering it. All tiles |
147 // for these images will be invalidated on the next pending tree. | 150 // for these images will be invalidated on the next pending tree. |
148 if (images_pending_invalidation_.find(image_id) != | 151 if (images_pending_invalidation_.find(image_id) != |
149 images_pending_invalidation_.end()) { | 152 images_pending_invalidation_.end()) { |
150 return true; | 153 return true; |
151 } | 154 } |
152 | 155 |
153 auto insert_result = | 156 auto insert_result = image_async_decode_state_.insert( |
154 image_async_decode_state_.insert(std::pair<PaintImage::Id, DecodePolicy>( | 157 std::pair<PaintImage::Id, DecodePolicy>(image_id, DecodePolicy::SYNC)); |
155 image_id, DecodePolicy::SYNC_PERMANENT)); | |
156 auto it = insert_result.first; | 158 auto it = insert_result.first; |
157 if (insert_result.second) { | 159 if (insert_result.second) { |
158 bool can_checker_image = | 160 bool can_checker_image = |
159 image.animation_type() == PaintImage::AnimationType::STATIC && | 161 image.animation_type() == PaintImage::AnimationType::STATIC && |
160 image.completion_state() == PaintImage::CompletionState::DONE; | 162 image.completion_state() == PaintImage::CompletionState::DONE; |
161 if (can_checker_image) { | 163 if (can_checker_image) { |
162 size_t size = SafeSizeOfImage(image.sk_image().get()); | 164 size_t size = SafeSizeOfImage(image.sk_image().get()); |
163 it->second = (size >= kMinImageSizeToCheckerBytes && | 165 it->second = (size >= kMinImageSizeToCheckerBytes && |
164 size <= image_controller_->image_cache_max_limit_bytes()) | 166 size <= image_controller_->image_cache_max_limit_bytes()) |
165 ? DecodePolicy::ASYNC | 167 ? DecodePolicy::ASYNC |
166 : DecodePolicy::SYNC_PERMANENT; | 168 : DecodePolicy::SYNC; |
167 } | 169 } |
168 } | 170 } |
169 | 171 |
170 return it->second == DecodePolicy::ASYNC; | 172 return it->second == DecodePolicy::ASYNC; |
171 } | 173 } |
172 | 174 |
173 void CheckerImageTracker::ScheduleNextImageDecode() { | 175 void CheckerImageTracker::ScheduleNextImageDecode() { |
174 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | 176 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
175 "CheckerImageTracker::ScheduleNextImageDecode"); | 177 "CheckerImageTracker::ScheduleNextImageDecode"); |
176 // We can have only one outsanding decode pending completion with the decode | 178 // We can have only one outsanding decode pending completion with the decode |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 image_controller_->QueueImageDecode( | 213 image_controller_->QueueImageDecode( |
212 outstanding_image_decode_.value().sk_image(), | 214 outstanding_image_decode_.value().sk_image(), |
213 base::Bind(&CheckerImageTracker::DidFinishImageDecode, | 215 base::Bind(&CheckerImageTracker::DidFinishImageDecode, |
214 weak_factory_.GetWeakPtr(), image_id)); | 216 weak_factory_.GetWeakPtr(), image_id)); |
215 | 217 |
216 image_id_to_decode_.emplace(image_id, base::MakeUnique<ScopedDecodeHolder>( | 218 image_id_to_decode_.emplace(image_id, base::MakeUnique<ScopedDecodeHolder>( |
217 image_controller_, request_id)); | 219 image_controller_, request_id)); |
218 } | 220 } |
219 | 221 |
220 } // namespace cc | 222 } // namespace cc |
OLD | NEW |