Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
|
vmpstr
2017/02/03 23:42:32
2017
Khushal
2017/02/07 00:25:32
Done.
| |
| 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 "cc/playback/raster_source.h" | |
| 9 #include "cc/tiles/picture_layer_tiling.h" | |
| 10 #include "cc/tiles/prioritized_tile.h" | |
| 11 #include "cc/tiles/tile.h" | |
| 12 #include "cc/trees/layer_tree_impl.h" | |
| 13 | |
| 14 namespace cc { | |
| 15 namespace { | |
| 16 // The minimum size of an image that we should consider checkering. | |
| 17 size_t kMinImageSizeToCheckerBytes = 512 * 1024; | |
| 18 } // namespace | |
| 19 | |
| 20 CheckerImageTracker::CheckerImageTracker(ImageController* image_controller, | |
| 21 CheckerImageTrackerClient* client, | |
| 22 bool enable_checker_imaging) | |
| 23 : image_controller_(image_controller), | |
| 24 client_(client), | |
| 25 enable_checker_imaging_(enable_checker_imaging), | |
| 26 weak_factory_(this) {} | |
| 27 | |
| 28 CheckerImageTracker::~CheckerImageTracker() { | |
| 29 // Unlock all images pending decode requests. | |
| 30 for (auto it : image_id_to_decode_request_id_) { | |
|
vmpstr
2017/02/03 23:42:32
nit: no braces
Khushal
2017/02/07 00:25:32
Done.
| |
| 31 image_controller_->UnlockImageDecode(it.second); | |
| 32 } | |
| 33 } | |
| 34 | |
| 35 void CheckerImageTracker::FilterImagesForCheckeringForTile( | |
| 36 const PrioritizedTile& prioritized_tile, | |
|
vmpstr
2017/02/03 23:42:32
I'd prefer if we don't expose prioritized tile her
Khushal
2017/02/07 00:25:32
Awesome suggestion, eliminating all of these makes
| |
| 37 std::vector<DrawImage>* images, | |
| 38 std::unordered_set<ImageId>* checkered_images) { | |
| 39 DCHECK(images->empty()); | |
| 40 DCHECK(checkered_images->empty()); | |
| 41 | |
| 42 Tile* tile = prioritized_tile.tile(); | |
| 43 prioritized_tile.raster_source()->GetDiscardableImagesInRect( | |
| 44 tile->enclosing_layer_rect(), tile->contents_scale(), images); | |
| 45 WhichTree tree = tile->tiling()->tree(); | |
| 46 | |
| 47 for (std::vector<DrawImage>::iterator it = images->begin(); | |
| 48 it != images->end();) { | |
| 49 const sk_sp<const SkImage> image = it->image(); | |
| 50 if (AnalyzeImageForCheckeringAndScheduleDecodeIfNecessary(image, tree)) { | |
| 51 checkered_images->insert(image->uniqueID()); | |
| 52 it = images->erase(it); | |
| 53 } else { | |
| 54 ++it; | |
| 55 } | |
| 56 } | |
| 57 } | |
| 58 | |
| 59 void CheckerImageTracker::AddInvalidationForCheckerImages( | |
|
vmpstr
2017/02/03 23:42:32
I think this should be something like
Region Take
Khushal
2017/02/07 00:25:32
Great suggestion. Can't return the region since on
| |
| 60 LayerTreeImpl* sync_tree) { | |
| 61 DCHECK(images_invalidated_on_current_sync_tree_.empty()) | |
| 62 << "Can not invalidate again on the sync tree"; | |
| 63 | |
| 64 sync_tree->InvalidateRegionForImages(images_pending_invalidation_); | |
| 65 images_invalidated_on_current_sync_tree_.swap(images_pending_invalidation_); | |
|
vmpstr
2017/02/03 23:42:32
Should images_pending_invalidation_ be cleared her
Khushal
2017/02/07 00:25:32
Hmmm, there is a DCHECK above to assert that |imag
| |
| 66 } | |
| 67 | |
| 68 void CheckerImageTracker::DidActivateSyncTree() { | |
| 69 for (auto image_id : images_invalidated_on_current_sync_tree_) { | |
| 70 auto it = image_id_to_decode_request_id_.find(image_id); | |
| 71 image_controller_->UnlockImageDecode(it->second); | |
| 72 image_id_to_decode_request_id_.erase(it); | |
| 73 } | |
| 74 | |
| 75 images_invalidated_on_current_sync_tree_.clear(); | |
| 76 } | |
| 77 | |
| 78 void CheckerImageTracker::DidFinishImageDecode( | |
| 79 ImageId image_id, | |
| 80 ImageController::ImageDecodeRequestId request_id) { | |
| 81 TRACE_EVENT_ASYNC_END0("cc", "CheckerImageTracker::DeferImageDecode", | |
| 82 image_id); | |
| 83 | |
| 84 auto it = pending_image_decodes_.find(image_id); | |
| 85 DCHECK(it != pending_image_decodes_.end()); | |
| 86 pending_image_decodes_.erase(it); | |
|
vmpstr
2017/02/03 23:42:32
We typically write this type of pattern as:
DCHEC
Khushal
2017/02/07 00:25:32
Done.
| |
| 87 | |
| 88 images_decoded_once_.insert(image_id); | |
| 89 images_pending_invalidation_.insert(image_id); | |
| 90 client_->NeedsInvalidationForCheckerImagedTiles(); | |
| 91 } | |
| 92 | |
| 93 bool CheckerImageTracker::AnalyzeImageForCheckeringAndScheduleDecodeIfNecessary( | |
|
vmpstr
2017/02/03 23:42:32
I think this name makes it clear that this should
Khushal
2017/02/07 00:25:32
Done.
| |
| 94 const sk_sp<const SkImage> image, | |
| 95 WhichTree tree) { | |
| 96 TRACE_EVENT1("cc", "CheckerImageTracker::AnalyzeImageForCheckering", | |
| 97 "image_id", image->uniqueID()); | |
| 98 if (!enable_checker_imaging_) { | |
|
vmpstr
2017/02/03 23:42:32
nit (here and elsewhere), remove braces from singl
Khushal
2017/02/07 00:25:32
Done.
| |
| 99 return false; | |
| 100 } | |
| 101 | |
| 102 // If the image doesn't need to be decoded. | |
| 103 if (!image->isLazyGenerated()) { | |
|
vmpstr
2017/02/03 23:42:32
If this is coming from discardable image map, then
Khushal
2017/02/07 00:25:32
Done.
| |
| 104 return false; | |
| 105 } | |
| 106 | |
| 107 // If a decode request is pending for this image, continue checkering it. | |
| 108 if (pending_image_decodes_.find(image->uniqueID()) != | |
| 109 pending_image_decodes_.end()) { | |
| 110 return true; | |
| 111 } | |
| 112 | |
| 113 // If the image is pending invalidation, continue checkering it. All tiles | |
| 114 // for these images will be invalidated on the next pending tree. | |
| 115 if (images_pending_invalidation_.find(image->uniqueID()) != | |
| 116 images_pending_invalidation_.end()) { | |
| 117 return true; | |
| 118 } | |
| 119 | |
| 120 // If the image was invalidated on the current sync tree and the tile is | |
| 121 // for the active tree, continue checkering it on the active tree to ensure | |
| 122 // the image update is atomic for the frame. | |
| 123 if (images_invalidated_on_current_sync_tree_.count(image->uniqueID()) != 0 && | |
| 124 tree == WhichTree::ACTIVE_TREE) { | |
|
vmpstr
2017/02/03 23:42:32
Check the tree first, since it's much quicker.
Khushal
2017/02/07 00:25:32
Done.
| |
| 125 return true; | |
| 126 } | |
| 127 | |
| 128 // If the image has been decoded once before, don't checker it again. | |
| 129 if (images_decoded_once_.find(image->uniqueID()) != | |
| 130 images_decoded_once_.end()) { | |
| 131 return false; | |
| 132 } | |
| 133 | |
| 134 base::CheckedNumeric<size_t> checked_size = 4; | |
| 135 checked_size *= image->width(); | |
| 136 checked_size *= image->height(); | |
| 137 size_t image_size = | |
| 138 checked_size.ValueOrDefault(std::numeric_limits<size_t>::max()); | |
| 139 bool defer_image_decode = image_size >= kMinImageSizeToCheckerBytes; | |
| 140 | |
| 141 if (defer_image_decode) { | |
|
vmpstr
2017/02/03 23:42:32
if (!defer_image_decode)
return false;
...
Khushal
2017/02/07 00:25:32
Simpler now?
| |
| 142 ImageId image_id = image->uniqueID(); | |
| 143 TRACE_EVENT_ASYNC_BEGIN0("cc", "CheckerImageTracker::DeferImageDecode", | |
| 144 image_id); | |
| 145 DCHECK_EQ(image_id_to_decode_request_id_.count(image_id), 0U); | |
| 146 | |
| 147 image_id_to_decode_request_id_[image_id] = | |
| 148 image_controller_->QueueImageDecode( | |
| 149 image, base::Bind(&CheckerImageTracker::DidFinishImageDecode, | |
| 150 weak_factory_.GetWeakPtr(), image_id)); | |
| 151 pending_image_decodes_.insert(image_id); | |
| 152 } | |
| 153 | |
| 154 return defer_image_decode; | |
| 155 } | |
| 156 | |
| 157 } // namespace cc | |
| OLD | NEW |