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

Side by Side Diff: cc/layers/layer.cc

Issue 1155553006: Revert of 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, 6 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
« no previous file with comments | « cc/layers/layer.h ('k') | cc/layers/layer_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2010 The Chromium Authors. All rights reserved. 1 // Copyright 2010 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/layers/layer.h" 5 #include "cc/layers/layer.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/atomic_sequence_num.h" 9 #include "base/atomic_sequence_num.h"
10 #include "base/location.h" 10 #include "base/location.h"
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 } 330 }
331 331
332 void Layer::ReplaceChild(Layer* reference, scoped_refptr<Layer> new_layer) { 332 void Layer::ReplaceChild(Layer* reference, scoped_refptr<Layer> new_layer) {
333 DCHECK(reference); 333 DCHECK(reference);
334 DCHECK_EQ(reference->parent(), this); 334 DCHECK_EQ(reference->parent(), this);
335 DCHECK(IsPropertyChangeAllowed()); 335 DCHECK(IsPropertyChangeAllowed());
336 336
337 if (reference == new_layer.get()) 337 if (reference == new_layer.get())
338 return; 338 return;
339 339
340 // Find the index of |reference| in |children_|. 340 int reference_index = IndexOfChild(reference);
341 auto reference_it = 341 if (reference_index == -1) {
342 std::find_if(children_.begin(), children_.end(), 342 NOTREACHED();
343 [reference](const scoped_refptr<Layer>& layer) { 343 return;
344 return layer.get() == reference; 344 }
345 }); 345
346 DCHECK(reference_it != children_.end());
347 size_t reference_index = reference_it - children_.begin();
348 reference->RemoveFromParent(); 346 reference->RemoveFromParent();
349 347
350 if (new_layer.get()) { 348 if (new_layer.get()) {
351 new_layer->RemoveFromParent(); 349 new_layer->RemoveFromParent();
352 InsertChild(new_layer, reference_index); 350 InsertChild(new_layer, reference_index);
353 } 351 }
354 } 352 }
355 353
354 int Layer::IndexOfChild(const Layer* reference) {
355 for (size_t i = 0; i < children_.size(); ++i) {
356 if (children_[i].get() == reference)
357 return i;
358 }
359 return -1;
360 }
361
356 void Layer::SetBounds(const gfx::Size& size) { 362 void Layer::SetBounds(const gfx::Size& size) {
357 DCHECK(IsPropertyChangeAllowed()); 363 DCHECK(IsPropertyChangeAllowed());
358 if (bounds() == size) 364 if (bounds() == size)
359 return; 365 return;
360 bounds_ = size; 366 bounds_ = size;
361 367
362 if (!layer_tree_host_) 368 if (!layer_tree_host_)
363 return; 369 return;
364 370
365 if (ClipNode* clip_node = layer_tree_host_->property_trees()->clip_tree.Node( 371 if (ClipNode* clip_node = layer_tree_host_->property_trees()->clip_tree.Node(
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 for (const Layer* layer = parent(); layer; layer = layer->parent()) { 409 for (const Layer* layer = parent(); layer; layer = layer->parent()) {
404 if (layer == ancestor) 410 if (layer == ancestor)
405 return true; 411 return true;
406 } 412 }
407 return false; 413 return false;
408 } 414 }
409 415
410 void Layer::RequestCopyOfOutput( 416 void Layer::RequestCopyOfOutput(
411 scoped_ptr<CopyOutputRequest> request) { 417 scoped_ptr<CopyOutputRequest> request) {
412 DCHECK(IsPropertyChangeAllowed()); 418 DCHECK(IsPropertyChangeAllowed());
413 bool had_no_copy_requests = copy_requests_.empty(); 419 int size = copy_requests_.size();
414 if (void* source = request->source()) { 420 if (void* source = request->source()) {
415 auto it = std::find_if( 421 auto it = std::find_if(
416 copy_requests_.begin(), copy_requests_.end(), 422 copy_requests_.begin(), copy_requests_.end(),
417 [source](const CopyOutputRequest* x) { return x->source() == source; }); 423 [source](const CopyOutputRequest* x) { return x->source() == source; });
418 if (it != copy_requests_.end()) 424 if (it != copy_requests_.end())
419 copy_requests_.erase(it); 425 copy_requests_.erase(it);
420 } 426 }
421 if (request->IsEmpty()) 427 if (request->IsEmpty())
422 return; 428 return;
423 copy_requests_.push_back(request.Pass()); 429 copy_requests_.push_back(request.Pass());
424 if (had_no_copy_requests) { 430 if (size == 0) {
425 bool copy_request_added = true; 431 bool copy_request_added = true;
426 UpdateNumCopyRequestsForSubtree(copy_request_added); 432 UpdateNumCopyRequestsForSubtree(copy_request_added);
427 } 433 }
428 SetNeedsCommit(); 434 SetNeedsCommit();
429 } 435 }
430 436
431 void Layer::UpdateNumCopyRequestsForSubtree(bool add) { 437 void Layer::UpdateNumCopyRequestsForSubtree(bool add) {
432 int change = add ? 1 : -1; 438 int change = add ? 1 : -1;
433 for (Layer* layer = this; layer; layer = layer->parent()) { 439 for (Layer* layer = this; layer; layer = layer->parent()) {
434 layer->num_layer_or_descendants_with_copy_request_ += change; 440 layer->num_layer_or_descendants_with_copy_request_ += change;
(...skipping 826 matching lines...) Expand 10 before | Expand all | Expand 10 after
1261 // the pending tree will clobber any impl-side scrolling occuring on the 1267 // the pending tree will clobber any impl-side scrolling occuring on the
1262 // active tree. To do so, avoid scrolling the pending tree along with it 1268 // active tree. To do so, avoid scrolling the pending tree along with it
1263 // instead of trying to undo that scrolling later. 1269 // instead of trying to undo that scrolling later.
1264 if (layer_animation_controller_->scroll_offset_animation_was_interrupted()) 1270 if (layer_animation_controller_->scroll_offset_animation_was_interrupted())
1265 layer->PushScrollOffsetFromMainThreadAndClobberActiveValue(scroll_offset_); 1271 layer->PushScrollOffsetFromMainThreadAndClobberActiveValue(scroll_offset_);
1266 else 1272 else
1267 layer->PushScrollOffsetFromMainThread(scroll_offset_); 1273 layer->PushScrollOffsetFromMainThread(scroll_offset_);
1268 layer->SetScrollCompensationAdjustment(ScrollCompensationAdjustment()); 1274 layer->SetScrollCompensationAdjustment(ScrollCompensationAdjustment());
1269 1275
1270 // Wrap the copy_requests_ in a PostTask to the main thread. 1276 // Wrap the copy_requests_ in a PostTask to the main thread.
1271 bool had_copy_requests = !copy_requests_.empty(); 1277 int size = copy_requests_.size();
1272 ScopedPtrVector<CopyOutputRequest> main_thread_copy_requests; 1278 ScopedPtrVector<CopyOutputRequest> main_thread_copy_requests;
1273 for (ScopedPtrVector<CopyOutputRequest>::iterator it = copy_requests_.begin(); 1279 for (ScopedPtrVector<CopyOutputRequest>::iterator it = copy_requests_.begin();
1274 it != copy_requests_.end(); 1280 it != copy_requests_.end();
1275 ++it) { 1281 ++it) {
1276 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner = 1282 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner =
1277 layer_tree_host()->proxy()->MainThreadTaskRunner(); 1283 layer_tree_host()->proxy()->MainThreadTaskRunner();
1278 scoped_ptr<CopyOutputRequest> original_request = copy_requests_.take(it); 1284 scoped_ptr<CopyOutputRequest> original_request = copy_requests_.take(it);
1279 const CopyOutputRequest& original_request_ref = *original_request; 1285 const CopyOutputRequest& original_request_ref = *original_request;
1280 scoped_ptr<CopyOutputRequest> main_thread_request = 1286 scoped_ptr<CopyOutputRequest> main_thread_request =
1281 CopyOutputRequest::CreateRelayRequest( 1287 CopyOutputRequest::CreateRelayRequest(
1282 original_request_ref, 1288 original_request_ref,
1283 base::Bind(&PostCopyCallbackToMainThread, 1289 base::Bind(&PostCopyCallbackToMainThread,
1284 main_thread_task_runner, 1290 main_thread_task_runner,
1285 base::Passed(&original_request))); 1291 base::Passed(&original_request)));
1286 main_thread_copy_requests.push_back(main_thread_request.Pass()); 1292 main_thread_copy_requests.push_back(main_thread_request.Pass());
1287 } 1293 }
1288 if (!copy_requests_.empty() && layer_tree_host_) 1294 if (!copy_requests_.empty() && layer_tree_host_)
1289 layer_tree_host_->property_trees()->needs_rebuild = true; 1295 layer_tree_host_->property_trees()->needs_rebuild = true;
1290 if (had_copy_requests) 1296 if (size != 0)
1291 UpdateNumCopyRequestsForSubtree(false); 1297 UpdateNumCopyRequestsForSubtree(false);
1292 copy_requests_.clear(); 1298 copy_requests_.clear();
1293 layer->PassCopyRequests(&main_thread_copy_requests); 1299 layer->PassCopyRequests(&main_thread_copy_requests);
1294 1300
1295 // If the main thread commits multiple times before the impl thread actually 1301 // If the main thread commits multiple times before the impl thread actually
1296 // draws, then damage tracking will become incorrect if we simply clobber the 1302 // draws, then damage tracking will become incorrect if we simply clobber the
1297 // update_rect here. The LayerImpl's update_rect needs to accumulate (i.e. 1303 // update_rect here. The LayerImpl's update_rect needs to accumulate (i.e.
1298 // union) any update changes that have occurred on the main thread. 1304 // union) any update changes that have occurred on the main thread.
1299 update_rect_.Union(layer->update_rect()); 1305 update_rect_.Union(layer->update_rect());
1300 layer->SetUpdateRect(update_rect_); 1306 layer->SetUpdateRect(update_rect_);
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after
1641 ? layer_tree_host()->meta_information_sequence_number() 1647 ? layer_tree_host()->meta_information_sequence_number()
1642 : 0; 1648 : 0;
1643 } 1649 }
1644 1650
1645 bool Layer::sorted_for_recursion() { 1651 bool Layer::sorted_for_recursion() {
1646 return sorted_for_recursion_tracker_ == 1652 return sorted_for_recursion_tracker_ ==
1647 layer_tree_host()->meta_information_sequence_number(); 1653 layer_tree_host()->meta_information_sequence_number();
1648 } 1654 }
1649 1655
1650 } // namespace cc 1656 } // namespace cc
OLDNEW
« 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