| 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 ImageId image_id, | 85 ImageId image_id, |
| 86 ImageController::ImageDecodeRequestId request_id, | 86 ImageController::ImageDecodeRequestId request_id, |
| 87 ImageController::ImageDecodeResult result) { | 87 ImageController::ImageDecodeResult result) { |
| 88 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | 88 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
| 89 "CheckerImageTracker::DidFinishImageDecode"); | 89 "CheckerImageTracker::DidFinishImageDecode"); |
| 90 TRACE_EVENT_ASYNC_END0("cc", "CheckerImageTracker::DeferImageDecode", | 90 TRACE_EVENT_ASYNC_END0("cc", "CheckerImageTracker::DeferImageDecode", |
| 91 image_id); | 91 image_id); |
| 92 | 92 |
| 93 DCHECK_NE(result, ImageController::ImageDecodeResult::DECODE_NOT_REQUIRED); | 93 DCHECK_NE(result, ImageController::ImageDecodeResult::DECODE_NOT_REQUIRED); |
| 94 DCHECK_NE(pending_image_decodes_.count(image_id), 0u); | 94 DCHECK_NE(pending_image_decodes_.count(image_id), 0u); |
| 95 DCHECK_NE(image_async_decode_state_.count(image_id), 0u); |
| 96 |
| 95 pending_image_decodes_.erase(image_id); | 97 pending_image_decodes_.erase(image_id); |
| 96 | 98 |
| 97 images_decoded_once_.insert(image_id); | 99 image_async_decode_state_[image_id] = DecodePolicy::SYNC_DECODED_ONCE; |
| 98 images_pending_invalidation_.insert(image_id); | 100 images_pending_invalidation_.insert(image_id); |
| 99 client_->NeedsInvalidationForCheckerImagedTiles(); | 101 client_->NeedsInvalidationForCheckerImagedTiles(); |
| 100 } | 102 } |
| 101 | 103 |
| 102 bool CheckerImageTracker::ShouldCheckerImage(const sk_sp<const SkImage>& image, | 104 bool CheckerImageTracker::ShouldCheckerImage(const sk_sp<const SkImage>& image, |
| 103 WhichTree tree) const { | 105 WhichTree tree) { |
| 104 TRACE_EVENT1("cc", "CheckerImageTracker::ShouldCheckerImage", "image_id", | 106 TRACE_EVENT1("cc", "CheckerImageTracker::ShouldCheckerImage", "image_id", |
| 105 image->uniqueID()); | 107 image->uniqueID()); |
| 106 | 108 |
| 107 if (!enable_checker_imaging_) | 109 if (!enable_checker_imaging_) |
| 108 return false; | 110 return false; |
| 109 | 111 |
| 110 // If the image was invalidated on the current sync tree and the tile is | 112 // If the image was invalidated on the current sync tree and the tile is |
| 111 // for the active tree, continue checkering it on the active tree to ensure | 113 // for the active tree, continue checkering it on the active tree to ensure |
| 112 // the image update is atomic for the frame. | 114 // the image update is atomic for the frame. |
| 113 if (invalidated_images_on_current_sync_tree_.count(image->uniqueID()) != 0 && | 115 if (invalidated_images_on_current_sync_tree_.count(image->uniqueID()) != 0 && |
| 114 tree == WhichTree::ACTIVE_TREE) { | 116 tree == WhichTree::ACTIVE_TREE) { |
| 115 return true; | 117 return true; |
| 116 } | 118 } |
| 117 | 119 |
| 118 // If a decode request is pending for this image, continue checkering it. | |
| 119 if (pending_image_decodes_.find(image->uniqueID()) != | |
| 120 pending_image_decodes_.end()) { | |
| 121 return true; | |
| 122 } | |
| 123 | |
| 124 // If the image is pending invalidation, continue checkering it. All tiles | 120 // If the image is pending invalidation, continue checkering it. All tiles |
| 125 // for these images will be invalidated on the next pending tree. | 121 // for these images will be invalidated on the next pending tree. |
| 126 if (images_pending_invalidation_.find(image->uniqueID()) != | 122 if (images_pending_invalidation_.find(image->uniqueID()) != |
| 127 images_pending_invalidation_.end()) { | 123 images_pending_invalidation_.end()) { |
| 128 return true; | 124 return true; |
| 129 } | 125 } |
| 130 | 126 |
| 131 // If the image has been decoded once before, don't checker it again. | 127 ImageId image_id = image->uniqueID(); |
| 132 if (images_decoded_once_.find(image->uniqueID()) != | 128 auto insert_result = image_async_decode_state_.insert( |
| 133 images_decoded_once_.end()) { | 129 std::pair<ImageId, DecodePolicy>(image_id, DecodePolicy::ASYNC)); |
| 134 return false; | 130 auto it = insert_result.first; |
| 131 if (insert_result.second) { |
| 132 it->second = SafeSizeOfImage(image.get()) >= kMinImageSizeToCheckerBytes |
| 133 ? DecodePolicy::ASYNC |
| 134 : DecodePolicy::SYNC_PERMANENT; |
| 135 } | 135 } |
| 136 | 136 |
| 137 return SafeSizeOfImage(image.get()) >= kMinImageSizeToCheckerBytes; | 137 return it->second == DecodePolicy::ASYNC; |
| 138 } | 138 } |
| 139 | 139 |
| 140 void CheckerImageTracker::ScheduleImageDecodeIfNecessary( | 140 void CheckerImageTracker::ScheduleImageDecodeIfNecessary( |
| 141 const sk_sp<const SkImage>& image) { | 141 const sk_sp<const SkImage>& image) { |
| 142 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), | 142 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
| 143 "CheckerImageTracker::ScheduleImageDecodeIfNecessary"); | 143 "CheckerImageTracker::ScheduleImageDecodeIfNecessary"); |
| 144 ImageId image_id = image->uniqueID(); | 144 ImageId image_id = image->uniqueID(); |
| 145 | 145 |
| 146 // If the image has already been decoded, or a decode request is pending, we | 146 // Once an image has been decoded, they can still be present in the decode |
| 147 // don't need to schedule another decode. | 147 // queue (duplicate entries), or while an image is still being skipped on the |
| 148 if (images_decoded_once_.count(image_id) != 0 || | 148 // active tree. Check if the image is still ASYNC to see if a decode is |
| 149 pending_image_decodes_.count(image_id) != 0) { | 149 // needed. |
| 150 auto it = image_async_decode_state_.find(image_id); |
| 151 DCHECK(it != image_async_decode_state_.end()); |
| 152 if (it->second != DecodePolicy::ASYNC) |
| 153 return; |
| 154 |
| 155 // If a decode request is pending, we don't need to schedule another decode. |
| 156 if (pending_image_decodes_.count(image_id) != 0) { |
| 150 return; | 157 return; |
| 151 } | 158 } |
| 152 | 159 |
| 153 TRACE_EVENT_ASYNC_BEGIN0("cc", "CheckerImageTracker::DeferImageDecode", | 160 TRACE_EVENT_ASYNC_BEGIN0("cc", "CheckerImageTracker::DeferImageDecode", |
| 154 image_id); | 161 image_id); |
| 155 DCHECK_EQ(image_id_to_decode_request_id_.count(image_id), 0U); | 162 DCHECK_EQ(image_id_to_decode_request_id_.count(image_id), 0U); |
| 156 | 163 |
| 157 image_id_to_decode_request_id_[image_id] = | 164 image_id_to_decode_request_id_[image_id] = |
| 158 image_controller_->QueueImageDecode( | 165 image_controller_->QueueImageDecode( |
| 159 image, base::Bind(&CheckerImageTracker::DidFinishImageDecode, | 166 image, base::Bind(&CheckerImageTracker::DidFinishImageDecode, |
| 160 weak_factory_.GetWeakPtr(), image_id)); | 167 weak_factory_.GetWeakPtr(), image_id)); |
| 161 pending_image_decodes_.insert(image_id); | 168 pending_image_decodes_.insert(image_id); |
| 162 } | 169 } |
| 163 | 170 |
| 164 } // namespace cc | 171 } // namespace cc |
| OLD | NEW |