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 19 matching lines...) Expand all Loading... | |
30 std::ostringstream str; | 30 std::ostringstream str; |
31 str << "paint_image_id[" << paint_image_id << "] sk_image_id[" << sk_image_id | 31 str << "paint_image_id[" << paint_image_id << "] sk_image_id[" << sk_image_id |
32 << "] complete[" << complete << "] static[" << static_image | 32 << "] complete[" << complete << "] static[" << static_image |
33 << "], fits_size_constraints[" << fits_size_constraints << "], size[" | 33 << "], fits_size_constraints[" << fits_size_constraints << "], size[" |
34 << size << "]"; | 34 << size << "]"; |
35 return str.str(); | 35 return str.str(); |
36 } | 36 } |
37 | 37 |
38 } // namespace | 38 } // namespace |
39 | 39 |
40 CheckerImageTracker::ImageDecodeRequest::ImageDecodeRequest( | |
41 PaintImage paint_image, | |
42 DecodeType type) | |
43 : paint_image(std::move(paint_image)), type(type) {} | |
44 | |
40 CheckerImageTracker::CheckerImageTracker(ImageController* image_controller, | 45 CheckerImageTracker::CheckerImageTracker(ImageController* image_controller, |
41 CheckerImageTrackerClient* client, | 46 CheckerImageTrackerClient* client, |
42 bool enable_checker_imaging) | 47 bool enable_checker_imaging) |
43 : image_controller_(image_controller), | 48 : image_controller_(image_controller), |
44 client_(client), | 49 client_(client), |
45 enable_checker_imaging_(enable_checker_imaging), | 50 enable_checker_imaging_(enable_checker_imaging), |
46 weak_factory_(this) {} | 51 weak_factory_(this) {} |
47 | 52 |
48 CheckerImageTracker::~CheckerImageTracker() = default; | 53 CheckerImageTracker::~CheckerImageTracker() = default; |
49 | 54 |
55 void CheckerImageTracker::SetCanSchedulePredecodeImages( | |
56 bool can_schedule_predecode_images) { | |
57 if (can_schedule_predecode_images_ == can_schedule_predecode_images) | |
58 return; | |
59 can_schedule_predecode_images_ = can_schedule_predecode_images; | |
60 | |
61 // If scheduling for the pre-decode queue was disabled, then we will stop | |
62 // queueing more work once a decode currently in flight is completed. If it | |
63 // was enabled, then kick off the next decode task. | |
64 if (can_schedule_predecode_images_) | |
65 ScheduleNextImageDecode(); | |
66 } | |
67 | |
50 void CheckerImageTracker::ScheduleImageDecodeQueue( | 68 void CheckerImageTracker::ScheduleImageDecodeQueue( |
51 ImageDecodeQueue image_decode_queue) { | 69 ImageDecodeQueue image_decode_queue) { |
52 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | 70 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
53 "CheckerImageTracker::ScheduleImageDecodeQueue"); | 71 "CheckerImageTracker::ScheduleImageDecodeQueue"); |
54 // Only checker-imaged (async updated) images are decoded using the image | 72 // Only checker-imaged (async updated) images are decoded using the image |
55 // decode service. If |enable_checker_imaging_| is false, no image should | 73 // decode service. If |enable_checker_imaging_| is false, no image should |
56 // be checkered. | 74 // be checkered. |
57 DCHECK(image_decode_queue.empty() || enable_checker_imaging_); | 75 DCHECK(image_decode_queue.empty() || enable_checker_imaging_); |
58 | 76 |
59 image_decode_queue_ = std::move(image_decode_queue); | 77 image_decode_queue_ = std::move(image_decode_queue); |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
228 } | 246 } |
229 | 247 |
230 void CheckerImageTracker::ScheduleNextImageDecode() { | 248 void CheckerImageTracker::ScheduleNextImageDecode() { |
231 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | 249 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
232 "CheckerImageTracker::ScheduleNextImageDecode"); | 250 "CheckerImageTracker::ScheduleNextImageDecode"); |
233 // We can have only one outstanding decode pending completion with the decode | 251 // We can have only one outstanding decode pending completion with the decode |
234 // service. We'll come back here when it is completed. | 252 // service. We'll come back here when it is completed. |
235 if (outstanding_image_decode_.has_value()) | 253 if (outstanding_image_decode_.has_value()) |
236 return; | 254 return; |
237 | 255 |
256 // If scheduling pre-decodes was disabled and we have reached the pre-decode | |
257 // images in the queue, don't run them now. We will come back here when | |
258 // these decodes are enabled. | |
259 if (!image_decode_queue_.empty() && | |
vmpstr
2017/06/12 21:45:30
Can you break this up a bit. Like, check if empty
Khushal
2017/06/14 00:29:19
Done.
| |
260 image_decode_queue_.front().type == DecodeType::kPreDecode && | |
261 !can_schedule_predecode_images_) { | |
262 return; | |
263 } | |
264 | |
238 DrawImage draw_image; | 265 DrawImage draw_image; |
239 while (!image_decode_queue_.empty()) { | 266 while (!image_decode_queue_.empty()) { |
240 auto candidate = std::move(image_decode_queue_.front()); | 267 auto candidate = std::move(image_decode_queue_.front().paint_image); |
241 image_decode_queue_.erase(image_decode_queue_.begin()); | 268 image_decode_queue_.erase(image_decode_queue_.begin()); |
242 | 269 |
243 // Once an image has been decoded, it can still be present in the decode | 270 // Once an image has been decoded, it can still be present in the decode |
244 // queue (duplicate entries), or while an image is still being skipped on | 271 // queue (duplicate entries), or while an image is still being skipped on |
245 // the active tree. Check if the image is still ASYNC to see if a decode is | 272 // the active tree. Check if the image is still ASYNC to see if a decode is |
246 // needed. | 273 // needed. |
247 PaintImage::Id image_id = candidate.stable_id(); | 274 PaintImage::Id image_id = candidate.stable_id(); |
248 auto it = image_async_decode_state_.find(image_id); | 275 auto it = image_async_decode_state_.find(image_id); |
249 DCHECK(it != image_async_decode_state_.end()); | 276 DCHECK(it != image_async_decode_state_.end()); |
250 if (it->second.policy != DecodePolicy::ASYNC) | 277 if (it->second.policy != DecodePolicy::ASYNC) |
(...skipping 22 matching lines...) Expand all Loading... | |
273 ImageController::ImageDecodeRequestId request_id = | 300 ImageController::ImageDecodeRequestId request_id = |
274 image_controller_->QueueImageDecode( | 301 image_controller_->QueueImageDecode( |
275 draw_image, base::Bind(&CheckerImageTracker::DidFinishImageDecode, | 302 draw_image, base::Bind(&CheckerImageTracker::DidFinishImageDecode, |
276 weak_factory_.GetWeakPtr(), image_id)); | 303 weak_factory_.GetWeakPtr(), image_id)); |
277 | 304 |
278 image_id_to_decode_.emplace(image_id, base::MakeUnique<ScopedDecodeHolder>( | 305 image_id_to_decode_.emplace(image_id, base::MakeUnique<ScopedDecodeHolder>( |
279 image_controller_, request_id)); | 306 image_controller_, request_id)); |
280 } | 307 } |
281 | 308 |
282 } // namespace cc | 309 } // namespace cc |
OLD | NEW |