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