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