Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(963)

Side by Side Diff: cc/tiles/checker_image_tracker.cc

Issue 2726343004: cc: Optimize decode scheduling for checker-images. (Closed)
Patch Set: addressed comments Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 18 matching lines...) Expand all
29 client_(client), 29 client_(client),
30 enable_checker_imaging_(enable_checker_imaging), 30 enable_checker_imaging_(enable_checker_imaging),
31 weak_factory_(this) {} 31 weak_factory_(this) {}
32 32
33 CheckerImageTracker::~CheckerImageTracker() { 33 CheckerImageTracker::~CheckerImageTracker() {
34 // Unlock all images pending decode requests. 34 // Unlock all images pending decode requests.
35 for (auto it : image_id_to_decode_request_id_) 35 for (auto it : image_id_to_decode_request_id_)
36 image_controller_->UnlockImageDecode(it.second); 36 image_controller_->UnlockImageDecode(it.second);
37 } 37 }
38 38
39 void CheckerImageTracker::FilterImagesForCheckeringForTile( 39 void CheckerImageTracker::ScheduleImageDecodeQueue(
40 std::vector<DrawImage>* images, 40 ImageDecodeQueue image_decode_queue) {
41 ImageIdFlatSet* checkered_images, 41 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"),
42 WhichTree tree) { 42 "CheckerImageTracker::ScheduleImageDecodeQueue");
43 TRACE_EVENT1(TRACE_DISABLED_BY_DEFAULT("cc.debug"), 43 DCHECK(image_decode_queue.empty() || enable_checker_imaging_);
44 "CheckerImageTracker::FilterImagesForCheckeringForTile", "tree",
45 tree);
46 DCHECK(checkered_images->empty());
47 44
48 base::EraseIf(*images, 45 image_decode_queue_ = std::move(image_decode_queue);
49 [this, tree, &checkered_images](const DrawImage& draw_image) { 46 ScheduleNextImageDecode();
50 const sk_sp<const SkImage>& image = draw_image.image();
51 DCHECK(image->isLazyGenerated());
52 if (ShouldCheckerImage(image, tree)) {
53 ScheduleImageDecodeIfNecessary(image);
54 checkered_images->insert(image->uniqueID());
55 return true;
56 }
57 return false;
58 });
59 } 47 }
60 48
61 const ImageIdFlatSet& CheckerImageTracker::TakeImagesToInvalidateOnSyncTree() { 49 const ImageIdFlatSet& CheckerImageTracker::TakeImagesToInvalidateOnSyncTree() {
62 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), 50 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"),
63 "CheckerImageTracker::TakeImagesToInvalidateOnSyncTree"); 51 "CheckerImageTracker::TakeImagesToInvalidateOnSyncTree");
64 DCHECK_EQ(invalidated_images_on_current_sync_tree_.size(), 0u) 52 DCHECK_EQ(invalidated_images_on_current_sync_tree_.size(), 0u)
65 << "Sync tree can not be invalidated more than once"; 53 << "Sync tree can not be invalidated more than once";
66 54
67 invalidated_images_on_current_sync_tree_.swap(images_pending_invalidation_); 55 invalidated_images_on_current_sync_tree_.swap(images_pending_invalidation_);
68 images_pending_invalidation_.clear(); 56 images_pending_invalidation_.clear();
(...skipping 14 matching lines...) Expand all
83 71
84 void CheckerImageTracker::DidFinishImageDecode( 72 void CheckerImageTracker::DidFinishImageDecode(
85 ImageId image_id, 73 ImageId image_id,
86 ImageController::ImageDecodeRequestId request_id, 74 ImageController::ImageDecodeRequestId request_id,
87 ImageController::ImageDecodeResult result) { 75 ImageController::ImageDecodeResult result) {
88 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), 76 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"),
89 "CheckerImageTracker::DidFinishImageDecode"); 77 "CheckerImageTracker::DidFinishImageDecode");
90 TRACE_EVENT_ASYNC_END0("cc", "CheckerImageTracker::DeferImageDecode", 78 TRACE_EVENT_ASYNC_END0("cc", "CheckerImageTracker::DeferImageDecode",
91 image_id); 79 image_id);
92 80
93 DCHECK_NE(result, ImageController::ImageDecodeResult::DECODE_NOT_REQUIRED); 81 DCHECK_NE(ImageController::ImageDecodeResult::DECODE_NOT_REQUIRED, result);
94 DCHECK_NE(pending_image_decodes_.count(image_id), 0u); 82 DCHECK_EQ(outstanding_image_decode_->uniqueID(), image_id);
95 pending_image_decodes_.erase(image_id); 83 outstanding_image_decode_ = nullptr;
96
97 images_decoded_once_.insert(image_id); 84 images_decoded_once_.insert(image_id);
98 images_pending_invalidation_.insert(image_id); 85 images_pending_invalidation_.insert(image_id);
86
87 ScheduleNextImageDecode();
99 client_->NeedsInvalidationForCheckerImagedTiles(); 88 client_->NeedsInvalidationForCheckerImagedTiles();
100 } 89 }
101 90
102 bool CheckerImageTracker::ShouldCheckerImage(const sk_sp<const SkImage>& image, 91 bool CheckerImageTracker::ShouldCheckerImage(const sk_sp<const SkImage>& image,
103 WhichTree tree) const { 92 WhichTree tree) const {
104 TRACE_EVENT1("cc", "CheckerImageTracker::ShouldCheckerImage", "image_id", 93 TRACE_EVENT1("cc", "CheckerImageTracker::ShouldCheckerImage", "image_id",
105 image->uniqueID()); 94 image->uniqueID());
106 95
107 if (!enable_checker_imaging_) 96 if (!enable_checker_imaging_)
108 return false; 97 return false;
109 98
110 // If the image was invalidated on the current sync tree and the tile is 99 // 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 100 // for the active tree, continue checkering it on the active tree to ensure
112 // the image update is atomic for the frame. 101 // the image update is atomic for the frame.
113 if (invalidated_images_on_current_sync_tree_.count(image->uniqueID()) != 0 && 102 if (invalidated_images_on_current_sync_tree_.count(image->uniqueID()) != 0 &&
114 tree == WhichTree::ACTIVE_TREE) { 103 tree == WhichTree::ACTIVE_TREE) {
115 return true; 104 return true;
116 } 105 }
117 106
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 107 // If the image is pending invalidation, continue checkering it. All tiles
125 // for these images will be invalidated on the next pending tree. 108 // for these images will be invalidated on the next pending tree.
126 if (images_pending_invalidation_.find(image->uniqueID()) != 109 if (images_pending_invalidation_.find(image->uniqueID()) !=
127 images_pending_invalidation_.end()) { 110 images_pending_invalidation_.end()) {
128 return true; 111 return true;
129 } 112 }
130 113
131 // If the image has been decoded once before, don't checker it again. 114 // If the image has been decoded once before, don't checker it again.
132 if (images_decoded_once_.find(image->uniqueID()) != 115 if (images_decoded_once_.find(image->uniqueID()) !=
133 images_decoded_once_.end()) { 116 images_decoded_once_.end()) {
134 return false; 117 return false;
135 } 118 }
136 119
137 return SafeSizeOfImage(image.get()) >= kMinImageSizeToCheckerBytes; 120 return SafeSizeOfImage(image.get()) >= kMinImageSizeToCheckerBytes;
138 } 121 }
139 122
140 void CheckerImageTracker::ScheduleImageDecodeIfNecessary( 123 void CheckerImageTracker::ScheduleNextImageDecode() {
141 const sk_sp<const SkImage>& image) {
142 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"), 124 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("cc.debug"),
143 "CheckerImageTracker::ScheduleImageDecodeIfNecessary"); 125 "CheckerImageTracker::ScheduleNextImageDecode");
144 ImageId image_id = image->uniqueID(); 126 // We can have only one outsanding decode pending completion with the decode
127 // service. We'll come back here when it is completed.
128 if (outstanding_image_decode_)
129 return;
145 130
146 // If the image has already been decoded, or a decode request is pending, we 131 while (!image_decode_queue_.empty()) {
147 // don't need to schedule another decode. 132 auto candidate = image_decode_queue_.front();
148 if (images_decoded_once_.count(image_id) != 0 || 133 image_decode_queue_.erase(image_decode_queue_.begin());
149 pending_image_decodes_.count(image_id) != 0) { 134
135 // Schedule decode for this image if it has not already been decoded,
136 // otherwise try the next image in the queue.
137 ImageId image_id = candidate->uniqueID();
138 if (images_decoded_once_.count(image_id) != 0)
139 continue;
140
141 outstanding_image_decode_ = std::move(candidate);
142 break;
143 }
144
145 // We either found an image to decode or we reached the end of the queue. If
146 // we couldn't find an image, we're done.
147 if (!outstanding_image_decode_) {
148 DCHECK(image_decode_queue_.empty());
150 return; 149 return;
151 } 150 }
152 151
152 ImageId image_id = outstanding_image_decode_->uniqueID();
153 DCHECK_EQ(image_id_to_decode_request_id_.count(image_id), 0u);
153 TRACE_EVENT_ASYNC_BEGIN0("cc", "CheckerImageTracker::DeferImageDecode", 154 TRACE_EVENT_ASYNC_BEGIN0("cc", "CheckerImageTracker::DeferImageDecode",
154 image_id); 155 image_id);
155 DCHECK_EQ(image_id_to_decode_request_id_.count(image_id), 0U);
156
157 image_id_to_decode_request_id_[image_id] = 156 image_id_to_decode_request_id_[image_id] =
158 image_controller_->QueueImageDecode( 157 image_controller_->QueueImageDecode(
159 image, base::Bind(&CheckerImageTracker::DidFinishImageDecode, 158 outstanding_image_decode_,
160 weak_factory_.GetWeakPtr(), image_id)); 159 base::Bind(&CheckerImageTracker::DidFinishImageDecode,
161 pending_image_decodes_.insert(image_id); 160 weak_factory_.GetWeakPtr(), image_id));
162 } 161 }
163 162
164 } // namespace cc 163 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698