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

Unified Diff: cc/layers/layer.cc

Issue 1158433010: Reland: cc: Fix size_t to int truncations in layers/ output/ playback/ quads/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cc/layers/layer.h ('k') | cc/layers/layer_impl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/layers/layer.cc
diff --git a/cc/layers/layer.cc b/cc/layers/layer.cc
index d795670192770cf273875a4bf29e67db9a660aa0..9a3908490f8b0d688f231702578486997db828ee 100644
--- a/cc/layers/layer.cc
+++ b/cc/layers/layer.cc
@@ -337,12 +337,18 @@ void Layer::ReplaceChild(Layer* reference, scoped_refptr<Layer> new_layer) {
if (reference == new_layer.get())
return;
- int reference_index = IndexOfChild(reference);
- if (reference_index == -1) {
+ // Find the index of reference, aborting if it doesn't exist.
+ auto reference_it =
+ std::find_if(children_.begin(), children_.end(),
+ [reference](const scoped_refptr<Layer>& layer) {
+ return layer.get() == reference;
+ });
+ if (reference_it == children_.end()) {
NOTREACHED();
danakj 2015/06/02 00:06:27 Oh, yuck. Can you just DCHECK(reference_it != end)
vmpstr 2015/06/02 00:21:10 Done.
return;
}
+ size_t reference_index = reference_it - children_.begin();
reference->RemoveFromParent();
if (new_layer.get()) {
@@ -351,14 +357,6 @@ void Layer::ReplaceChild(Layer* reference, scoped_refptr<Layer> new_layer) {
}
}
-int Layer::IndexOfChild(const Layer* reference) {
- for (size_t i = 0; i < children_.size(); ++i) {
- if (children_[i].get() == reference)
- return i;
- }
- return -1;
-}
-
void Layer::SetBounds(const gfx::Size& size) {
DCHECK(IsPropertyChangeAllowed());
if (bounds() == size)
@@ -416,7 +414,7 @@ bool Layer::HasAncestor(const Layer* ancestor) const {
void Layer::RequestCopyOfOutput(
scoped_ptr<CopyOutputRequest> request) {
DCHECK(IsPropertyChangeAllowed());
- int size = copy_requests_.size();
+ bool had_no_copy_requests = copy_requests_.empty();
if (void* source = request->source()) {
auto it = std::find_if(
copy_requests_.begin(), copy_requests_.end(),
@@ -427,7 +425,7 @@ void Layer::RequestCopyOfOutput(
if (request->IsEmpty())
return;
copy_requests_.push_back(request.Pass());
- if (size == 0) {
+ if (had_no_copy_requests) {
bool copy_request_added = true;
UpdateNumCopyRequestsForSubtree(copy_request_added);
}
@@ -1274,7 +1272,7 @@ void Layer::PushPropertiesTo(LayerImpl* layer) {
layer->SetScrollCompensationAdjustment(ScrollCompensationAdjustment());
// Wrap the copy_requests_ in a PostTask to the main thread.
- int size = copy_requests_.size();
+ bool had_copy_requests = !copy_requests_.empty();
ScopedPtrVector<CopyOutputRequest> main_thread_copy_requests;
for (ScopedPtrVector<CopyOutputRequest>::iterator it = copy_requests_.begin();
it != copy_requests_.end();
@@ -1293,7 +1291,7 @@ void Layer::PushPropertiesTo(LayerImpl* layer) {
}
if (!copy_requests_.empty() && layer_tree_host_)
layer_tree_host_->property_trees()->needs_rebuild = true;
- if (size != 0)
+ if (had_copy_requests)
UpdateNumCopyRequestsForSubtree(false);
copy_requests_.clear();
layer->PassCopyRequests(&main_thread_copy_requests);
« no previous file with comments | « cc/layers/layer.h ('k') | cc/layers/layer_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698