OLD | NEW |
---|---|
(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 std::unordered_set<ImageId>* 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(); | |
vmpstr
2017/02/10 19:25:42
&
Khushal
2017/02/10 22:09:19
Done.
| |
39 DCHECK(image->isLazyGenerated()); | |
40 if (ShouldCheckerImage(image, tree)) { | |
41 ScheduleImageDecodeIfNecessary(image); | |
42 checkered_images->insert(image->uniqueID()); | |
43 it = images->erase(it); | |
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()) | |
53 << "Sync tree can not be invalidated more than once"; | |
54 | |
55 invalidated_images_on_current_sync_tree_.swap(images_pending_invalidation_); | |
vmpstr
2017/02/10 19:25:42
I think this should be
std::unordered_set<ImageId
Khushal
2017/02/10 22:09:19
But doesn't this unnecessarily create a copy?
| |
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( | |
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, | |
vmpstr
2017/02/10 19:25:42
&
Khushal
2017/02/10 22:09:19
Done.
| |
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; | |
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 bool should_checker_image = image_size >= kMinImageSizeToCheckerBytes; | |
vmpstr
2017/02/10 19:25:42
just return image_size >= kMinImageSizeToCheckerBy
Khushal
2017/02/10 22:09:19
Done.
| |
126 return should_checker_image; | |
127 } | |
128 | |
129 void CheckerImageTracker::ScheduleImageDecodeIfNecessary( | |
130 const sk_sp<const SkImage> image) { | |
131 ImageId image_id = image->uniqueID(); | |
132 | |
133 // If the image has already been decoded, or a decode request is pending, we | |
134 // don't need to schedule another decode. | |
135 if (images_decoded_once_.count(image_id) != 0 || | |
136 pending_image_decodes_.count(image_id) != 0) | |
vmpstr
2017/02/10 19:25:42
braces pls
Khushal
2017/02/10 22:09:19
Done.
| |
137 return; | |
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 | |
OLD | NEW |