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

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

Issue 2668873002: cc: Add checker-imaging support to TileManager. (Closed)
Patch Set: rebase Created 3 years, 10 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "cc/tiles/checker_image_tracker.h"
6
7 #include "base/bind.h"
8 #include "base/trace_event/trace_event.h"
9
10 namespace cc {
11 namespace {
12 // The minimum size of an image that we should consider checkering.
13 size_t kMinImageSizeToCheckerBytes = 512 * 1024;
14 } // namespace
15
16 CheckerImageTracker::CheckerImageTracker(ImageController* image_controller,
17 CheckerImageTrackerClient* client,
18 bool enable_checker_imaging)
19 : image_controller_(image_controller),
20 client_(client),
21 enable_checker_imaging_(enable_checker_imaging),
22 weak_factory_(this) {}
23
24 CheckerImageTracker::~CheckerImageTracker() {
25 // Unlock all images pending decode requests.
26 for (auto it : image_id_to_decode_request_id_)
27 image_controller_->UnlockImageDecode(it.second);
28 }
29
30 void CheckerImageTracker::FilterImagesForCheckeringForTile(
31 std::vector<DrawImage>* images,
32 ImageIdFlatSet* checkered_images,
33 WhichTree tree) {
34 DCHECK(checkered_images->empty());
35
36 for (std::vector<DrawImage>::iterator it = images->begin();
37 it != images->end();) {
38 const sk_sp<const SkImage>& image = it->image();
39 DCHECK(image->isLazyGenerated());
40 if (ShouldCheckerImage(image, tree)) {
41 ScheduleImageDecodeIfNecessary(image);
42 checkered_images->insert(image->uniqueID());
43 it = images->erase(it);
enne (OOO) 2017/02/16 21:41:32 std::vector::erase <_< How about: swap with last
Khushal 2017/02/17 19:05:38 Done. And with a suggestion from vmpstr@ on how to
44 } else {
45 ++it;
46 }
47 }
48 }
49
50 const std::unordered_set<ImageId>&
51 CheckerImageTracker::TakeImagesToInvalidateOnSyncTree() {
52 DCHECK(invalidated_images_on_current_sync_tree_.empty())
vmpstr 2017/02/16 20:59:14 nit: Can you make this DCHECK_EQ(0u, ....size()),
Khushal 2017/02/17 19:05:38 Done.
53 << "Sync tree can not be invalidated more than once";
54
55 invalidated_images_on_current_sync_tree_.swap(images_pending_invalidation_);
56 images_pending_invalidation_.clear();
57 return invalidated_images_on_current_sync_tree_;
58 }
59
60 void CheckerImageTracker::DidActivateSyncTree() {
61 for (auto image_id : invalidated_images_on_current_sync_tree_) {
62 auto it = image_id_to_decode_request_id_.find(image_id);
63 image_controller_->UnlockImageDecode(it->second);
64 image_id_to_decode_request_id_.erase(it);
65 }
66
67 invalidated_images_on_current_sync_tree_.clear();
68 }
69
70 void CheckerImageTracker::DidFinishImageDecode(
vmpstr 2017/02/16 20:59:13 Can you add a unittest where we queue some request
71 ImageId image_id,
72 ImageController::ImageDecodeRequestId request_id) {
73 TRACE_EVENT_ASYNC_END0("cc", "CheckerImageTracker::DeferImageDecode",
74 image_id);
75
76 DCHECK_NE(pending_image_decodes_.count(image_id), 0u);
77 pending_image_decodes_.erase(image_id);
78
79 images_decoded_once_.insert(image_id);
80 images_pending_invalidation_.insert(image_id);
81 client_->NeedsInvalidationForCheckerImagedTiles();
82 }
83
84 bool CheckerImageTracker::ShouldCheckerImage(const sk_sp<const SkImage>& image,
85 WhichTree tree) const {
86 TRACE_EVENT1("cc", "CheckerImageTracker::ShouldCheckerImage", "image_id",
87 image->uniqueID());
88
89 if (!enable_checker_imaging_)
90 return false;
91
92 // If the image was invalidated on the current sync tree and the tile is
93 // for the active tree, continue checkering it on the active tree to ensure
94 // the image update is atomic for the frame.
95 if (invalidated_images_on_current_sync_tree_.count(image->uniqueID()) != 0 &&
96 tree == WhichTree::ACTIVE_TREE) {
97 return true;
98 }
99
100 // If a decode request is pending for this image, continue checkering it.
101 if (pending_image_decodes_.find(image->uniqueID()) !=
102 pending_image_decodes_.end()) {
103 return true;
104 }
105
106 // If the image is pending invalidation, continue checkering it. All tiles
107 // for these images will be invalidated on the next pending tree.
108 if (images_pending_invalidation_.find(image->uniqueID()) !=
109 images_pending_invalidation_.end()) {
110 return true;
111 }
112
113 // If the image has been decoded once before, don't checker it again.
114 if (images_decoded_once_.find(image->uniqueID()) !=
115 images_decoded_once_.end()) {
116 return false;
117 }
118
119 base::CheckedNumeric<size_t> checked_size = 4;
enne (OOO) 2017/02/16 21:41:32 This is a very popular dance. Maybe we need a ski
vmpstr 2017/02/16 22:01:27 +1000
Khushal 2017/02/17 19:05:38 On popular demand. Done.
120 checked_size *= image->width();
121 checked_size *= image->height();
122 size_t image_size =
123 checked_size.ValueOrDefault(std::numeric_limits<size_t>::max());
124
125 return image_size >= kMinImageSizeToCheckerBytes;
126 }
127
128 void CheckerImageTracker::ScheduleImageDecodeIfNecessary(
129 const sk_sp<const SkImage>& image) {
130 ImageId image_id = image->uniqueID();
131
132 // If the image has already been decoded, or a decode request is pending, we
133 // don't need to schedule another decode.
134 if (images_decoded_once_.count(image_id) != 0 ||
135 pending_image_decodes_.count(image_id) != 0) {
136 return;
137 }
138
139 TRACE_EVENT_ASYNC_BEGIN0("cc", "CheckerImageTracker::DeferImageDecode",
140 image_id);
141 DCHECK_EQ(image_id_to_decode_request_id_.count(image_id), 0U);
142
143 image_id_to_decode_request_id_[image_id] =
144 image_controller_->QueueImageDecode(
145 image, base::Bind(&CheckerImageTracker::DidFinishImageDecode,
146 weak_factory_.GetWeakPtr(), image_id));
147 pending_image_decodes_.insert(image_id);
148 }
149
150 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698