| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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/trees/layer_tree_impl.h" | 5 #include "cc/trees/layer_tree_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 property_trees()->is_main_thread = false; | 86 property_trees()->is_main_thread = false; |
| 87 } | 87 } |
| 88 | 88 |
| 89 LayerTreeImpl::~LayerTreeImpl() { | 89 LayerTreeImpl::~LayerTreeImpl() { |
| 90 BreakSwapPromises(IsActiveTree() ? SwapPromise::SWAP_FAILS | 90 BreakSwapPromises(IsActiveTree() ? SwapPromise::SWAP_FAILS |
| 91 : SwapPromise::ACTIVATION_FAILS); | 91 : SwapPromise::ACTIVATION_FAILS); |
| 92 | 92 |
| 93 // Need to explicitly clear the tree prior to destroying this so that | 93 // Need to explicitly clear the tree prior to destroying this so that |
| 94 // the LayerTreeImpl pointer is still valid in the LayerImpl dtor. | 94 // the LayerTreeImpl pointer is still valid in the LayerImpl dtor. |
| 95 DCHECK(!root_layer_); | 95 DCHECK(!root_layer_); |
| 96 DCHECK(layers_with_copy_output_request_.empty()); | |
| 97 } | 96 } |
| 98 | 97 |
| 99 void LayerTreeImpl::Shutdown() { | 98 void LayerTreeImpl::Shutdown() { |
| 100 if (root_layer_) | 99 if (root_layer_) |
| 101 RemoveLayer(root_layer_->id()); | 100 RemoveLayer(root_layer_->id()); |
| 102 root_layer_ = nullptr; | 101 root_layer_ = nullptr; |
| 103 } | 102 } |
| 104 | 103 |
| 105 void LayerTreeImpl::ReleaseResources() { | 104 void LayerTreeImpl::ReleaseResources() { |
| 106 if (root_layer_) { | 105 if (root_layer_) { |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 DCHECK_EQ(layer->id(), clip_node->owner_id); | 322 DCHECK_EQ(layer->id(), clip_node->owner_id); |
| 324 gfx::SizeF bounds = gfx::SizeF(layer->bounds()); | 323 gfx::SizeF bounds = gfx::SizeF(layer->bounds()); |
| 325 if (clip_node->data.clip.size() != bounds) { | 324 if (clip_node->data.clip.size() != bounds) { |
| 326 clip_node->data.clip.set_size(bounds); | 325 clip_node->data.clip.set_size(bounds); |
| 327 clip_tree->set_needs_update(true); | 326 clip_tree->set_needs_update(true); |
| 328 } | 327 } |
| 329 } | 328 } |
| 330 } | 329 } |
| 331 } | 330 } |
| 332 | 331 |
| 332 void LayerTreeImpl::SetPropertyTrees(PropertyTrees* property_trees) { |
| 333 property_trees_ = *property_trees; |
| 334 property_trees->effect_tree.PushCopyRequestsTo(&property_trees_.effect_tree); |
| 335 property_trees_.is_main_thread = false; |
| 336 property_trees_.is_active = IsActiveTree(); |
| 337 property_trees_.transform_tree.set_source_to_parent_updates_allowed(false); |
| 338 // The value of some effect node properties (like is_drawn) depends on |
| 339 // whether we are on the active tree or not. So, we need to update the |
| 340 // effect tree. |
| 341 if (IsActiveTree()) |
| 342 property_trees_.effect_tree.set_needs_update(true); |
| 343 } |
| 344 |
| 333 void LayerTreeImpl::UpdatePropertyTreesForBoundsDelta() { | 345 void LayerTreeImpl::UpdatePropertyTreesForBoundsDelta() { |
| 334 DCHECK(IsActiveTree()); | 346 DCHECK(IsActiveTree()); |
| 335 LayerImpl* inner_container = InnerViewportContainerLayer(); | 347 LayerImpl* inner_container = InnerViewportContainerLayer(); |
| 336 LayerImpl* outer_container = OuterViewportContainerLayer(); | 348 LayerImpl* outer_container = OuterViewportContainerLayer(); |
| 337 LayerImpl* inner_scroll = InnerViewportScrollLayer(); | 349 LayerImpl* inner_scroll = InnerViewportScrollLayer(); |
| 338 | 350 |
| 339 UpdateClipTreeForBoundsDeltaOnLayer(inner_container, | 351 UpdateClipTreeForBoundsDeltaOnLayer(inner_container, |
| 340 &property_trees_.clip_tree); | 352 &property_trees_.clip_tree); |
| 341 UpdateClipTreeForBoundsDeltaOnLayer(InnerViewportScrollLayer(), | 353 UpdateClipTreeForBoundsDeltaOnLayer(InnerViewportScrollLayer(), |
| 342 &property_trees_.clip_tree); | 354 &property_trees_.clip_tree); |
| 343 UpdateClipTreeForBoundsDeltaOnLayer(outer_container, | 355 UpdateClipTreeForBoundsDeltaOnLayer(outer_container, |
| 344 &property_trees_.clip_tree); | 356 &property_trees_.clip_tree); |
| 345 | 357 |
| 346 if (inner_container) | 358 if (inner_container) |
| 347 property_trees_.SetInnerViewportContainerBoundsDelta( | 359 property_trees_.SetInnerViewportContainerBoundsDelta( |
| 348 inner_container->bounds_delta()); | 360 inner_container->bounds_delta()); |
| 349 if (outer_container) | 361 if (outer_container) |
| 350 property_trees_.SetOuterViewportContainerBoundsDelta( | 362 property_trees_.SetOuterViewportContainerBoundsDelta( |
| 351 outer_container->bounds_delta()); | 363 outer_container->bounds_delta()); |
| 352 if (inner_scroll) | 364 if (inner_scroll) |
| 353 property_trees_.SetInnerViewportScrollBoundsDelta( | 365 property_trees_.SetInnerViewportScrollBoundsDelta( |
| 354 inner_scroll->bounds_delta()); | 366 inner_scroll->bounds_delta()); |
| 355 } | 367 } |
| 356 | 368 |
| 357 void LayerTreeImpl::PushPropertiesTo(LayerTreeImpl* target_tree) { | 369 void LayerTreeImpl::PushPropertiesTo(LayerTreeImpl* target_tree) { |
| 358 // The request queue should have been processed and does not require a push. | 370 // The request queue should have been processed and does not require a push. |
| 359 DCHECK_EQ(ui_resource_request_queue_.size(), 0u); | 371 DCHECK_EQ(ui_resource_request_queue_.size(), 0u); |
| 360 | 372 |
| 361 LayerImpl* layer = target_tree->CurrentlyScrollingLayer(); | 373 LayerImpl* layer = target_tree->CurrentlyScrollingLayer(); |
| 362 target_tree->SetPropertyTrees(property_trees_); | 374 target_tree->SetPropertyTrees(&property_trees_); |
| 363 target_tree->SetCurrentlyScrollingLayer(layer); | 375 target_tree->SetCurrentlyScrollingLayer(layer); |
| 364 target_tree->UpdatePropertyTreeScrollOffset(&property_trees_); | 376 target_tree->UpdatePropertyTreeScrollOffset(&property_trees_); |
| 365 | 377 |
| 366 if (next_activation_forces_redraw_) { | 378 if (next_activation_forces_redraw_) { |
| 367 target_tree->ForceRedrawNextActivation(); | 379 target_tree->ForceRedrawNextActivation(); |
| 368 next_activation_forces_redraw_ = false; | 380 next_activation_forces_redraw_ = false; |
| 369 } | 381 } |
| 370 | 382 |
| 371 target_tree->PassSwapPromises(&swap_promise_list_); | 383 target_tree->PassSwapPromises(&swap_promise_list_); |
| 372 | 384 |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 770 outer_viewport_scroll_layer_id_ = outer_viewport_scroll_layer_id; | 782 outer_viewport_scroll_layer_id_ = outer_viewport_scroll_layer_id; |
| 771 } | 783 } |
| 772 | 784 |
| 773 void LayerTreeImpl::ClearViewportLayers() { | 785 void LayerTreeImpl::ClearViewportLayers() { |
| 774 overscroll_elasticity_layer_id_ = Layer::INVALID_ID; | 786 overscroll_elasticity_layer_id_ = Layer::INVALID_ID; |
| 775 page_scale_layer_id_ = Layer::INVALID_ID; | 787 page_scale_layer_id_ = Layer::INVALID_ID; |
| 776 inner_viewport_scroll_layer_id_ = Layer::INVALID_ID; | 788 inner_viewport_scroll_layer_id_ = Layer::INVALID_ID; |
| 777 outer_viewport_scroll_layer_id_ = Layer::INVALID_ID; | 789 outer_viewport_scroll_layer_id_ = Layer::INVALID_ID; |
| 778 } | 790 } |
| 779 | 791 |
| 780 #if DCHECK_IS_ON() | |
| 781 void SanityCheckCopyRequestCounts(LayerTreeImpl* layer_tree_impl) { | |
| 782 EffectTree& effect_tree = layer_tree_impl->property_trees()->effect_tree; | |
| 783 const int effect_tree_size = static_cast<int>(effect_tree.size()); | |
| 784 std::vector<int> copy_requests_count_in_effect_tree(effect_tree_size); | |
| 785 for (auto* layer : *layer_tree_impl) { | |
| 786 if (layer->HasCopyRequest()) { | |
| 787 copy_requests_count_in_effect_tree[layer->effect_tree_index()]++; | |
| 788 } | |
| 789 } | |
| 790 for (int i = effect_tree_size - 1; i >= 0; i--) { | |
| 791 EffectNode* node = effect_tree.Node(i); | |
| 792 DCHECK_EQ(node->data.num_copy_requests_in_subtree, | |
| 793 copy_requests_count_in_effect_tree[i]); | |
| 794 if (node->parent_id >= 0) | |
| 795 copy_requests_count_in_effect_tree[node->parent_id] += | |
| 796 copy_requests_count_in_effect_tree[i]; | |
| 797 } | |
| 798 } | |
| 799 #endif | |
| 800 | |
| 801 bool LayerTreeImpl::UpdateDrawProperties(bool update_lcd_text) { | 792 bool LayerTreeImpl::UpdateDrawProperties(bool update_lcd_text) { |
| 802 #if DCHECK_IS_ON() | |
| 803 if (root_layer()) | |
| 804 SanityCheckCopyRequestCounts(root_layer()->layer_tree_impl()); | |
| 805 #endif | |
| 806 | |
| 807 if (!needs_update_draw_properties_) | 793 if (!needs_update_draw_properties_) |
| 808 return true; | 794 return true; |
| 809 | 795 |
| 810 // Calling UpdateDrawProperties must clear this flag, so there can be no | 796 // Calling UpdateDrawProperties must clear this flag, so there can be no |
| 811 // early outs before this. | 797 // early outs before this. |
| 812 needs_update_draw_properties_ = false; | 798 needs_update_draw_properties_ = false; |
| 813 | 799 |
| 814 // For max_texture_size. When the renderer is re-created in | 800 // For max_texture_size. When the renderer is re-created in |
| 815 // CreateAndSetRenderer, the needs update draw properties flag is set | 801 // CreateAndSetRenderer, the needs update draw properties flag is set |
| 816 // again. | 802 // again. |
| (...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1481 DidUpdateScrollState(layer->id()); | 1467 DidUpdateScrollState(layer->id()); |
| 1482 } | 1468 } |
| 1483 | 1469 |
| 1484 void LayerTreeImpl::UnregisterScrollLayer(LayerImpl* layer) { | 1470 void LayerTreeImpl::UnregisterScrollLayer(LayerImpl* layer) { |
| 1485 if (layer->scroll_clip_layer_id() == Layer::INVALID_ID) | 1471 if (layer->scroll_clip_layer_id() == Layer::INVALID_ID) |
| 1486 return; | 1472 return; |
| 1487 | 1473 |
| 1488 clip_scroll_map_.erase(layer->scroll_clip_layer_id()); | 1474 clip_scroll_map_.erase(layer->scroll_clip_layer_id()); |
| 1489 } | 1475 } |
| 1490 | 1476 |
| 1491 void LayerTreeImpl::AddLayerWithCopyOutputRequest(LayerImpl* layer) { | |
| 1492 // Only the active tree needs to know about layers with copy requests, as | |
| 1493 // they are aborted if not serviced during draw. | |
| 1494 DCHECK(IsActiveTree()); | |
| 1495 | |
| 1496 // DCHECK(std::find(layers_with_copy_output_request_.begin(), | |
| 1497 // layers_with_copy_output_request_.end(), | |
| 1498 // layer) == layers_with_copy_output_request_.end()); | |
| 1499 // TODO(danakj): Remove this once crash is found crbug.com/309777 | |
| 1500 for (size_t i = 0; i < layers_with_copy_output_request_.size(); ++i) { | |
| 1501 CHECK(layers_with_copy_output_request_[i] != layer) | |
| 1502 << i << " of " << layers_with_copy_output_request_.size(); | |
| 1503 } | |
| 1504 layers_with_copy_output_request_.push_back(layer); | |
| 1505 } | |
| 1506 | |
| 1507 void LayerTreeImpl::RemoveLayerWithCopyOutputRequest(LayerImpl* layer) { | |
| 1508 // Only the active tree needs to know about layers with copy requests, as | |
| 1509 // they are aborted if not serviced during draw. | |
| 1510 DCHECK(IsActiveTree()); | |
| 1511 | |
| 1512 std::vector<LayerImpl*>::iterator it = | |
| 1513 std::find(layers_with_copy_output_request_.begin(), | |
| 1514 layers_with_copy_output_request_.end(), layer); | |
| 1515 DCHECK(it != layers_with_copy_output_request_.end()); | |
| 1516 layers_with_copy_output_request_.erase(it); | |
| 1517 | |
| 1518 // TODO(danakj): Remove this once crash is found crbug.com/309777 | |
| 1519 for (size_t i = 0; i < layers_with_copy_output_request_.size(); ++i) { | |
| 1520 CHECK(layers_with_copy_output_request_[i] != layer) | |
| 1521 << i << " of " << layers_with_copy_output_request_.size(); | |
| 1522 } | |
| 1523 } | |
| 1524 | |
| 1525 void LayerTreeImpl::AddSurfaceLayer(LayerImpl* layer) { | 1477 void LayerTreeImpl::AddSurfaceLayer(LayerImpl* layer) { |
| 1526 DCHECK(std::find(surface_layers_.begin(), surface_layers_.end(), layer) == | 1478 DCHECK(std::find(surface_layers_.begin(), surface_layers_.end(), layer) == |
| 1527 surface_layers_.end()); | 1479 surface_layers_.end()); |
| 1528 surface_layers_.push_back(layer); | 1480 surface_layers_.push_back(layer); |
| 1529 } | 1481 } |
| 1530 | 1482 |
| 1531 void LayerTreeImpl::RemoveSurfaceLayer(LayerImpl* layer) { | 1483 void LayerTreeImpl::RemoveSurfaceLayer(LayerImpl* layer) { |
| 1532 std::vector<LayerImpl*>::iterator it = | 1484 std::vector<LayerImpl*>::iterator it = |
| 1533 std::find(surface_layers_.begin(), surface_layers_.end(), layer); | 1485 std::find(surface_layers_.begin(), surface_layers_.end(), layer); |
| 1534 DCHECK(it != surface_layers_.end()); | 1486 DCHECK(it != surface_layers_.end()); |
| 1535 surface_layers_.erase(it); | 1487 surface_layers_.erase(it); |
| 1536 } | 1488 } |
| 1537 | 1489 |
| 1538 const std::vector<LayerImpl*>& LayerTreeImpl::LayersWithCopyOutputRequest() | |
| 1539 const { | |
| 1540 // Only the active tree needs to know about layers with copy requests, as | |
| 1541 // they are aborted if not serviced during draw. | |
| 1542 DCHECK(IsActiveTree()); | |
| 1543 | |
| 1544 return layers_with_copy_output_request_; | |
| 1545 } | |
| 1546 | |
| 1547 template <typename LayerType> | 1490 template <typename LayerType> |
| 1548 static inline bool LayerClipsSubtree(LayerType* layer) { | 1491 static inline bool LayerClipsSubtree(LayerType* layer) { |
| 1549 return layer->masks_to_bounds() || layer->mask_layer(); | 1492 return layer->masks_to_bounds() || layer->mask_layer(); |
| 1550 } | 1493 } |
| 1551 | 1494 |
| 1552 static bool PointHitsRect( | 1495 static bool PointHitsRect( |
| 1553 const gfx::PointF& screen_space_point, | 1496 const gfx::PointF& screen_space_point, |
| 1554 const gfx::Transform& local_space_to_screen_space_transform, | 1497 const gfx::Transform& local_space_to_screen_space_transform, |
| 1555 const gfx::Rect& local_space_rect, | 1498 const gfx::Rect& local_space_rect, |
| 1556 float* distance_to_camera) { | 1499 float* distance_to_camera) { |
| (...skipping 531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2088 } | 2031 } |
| 2089 | 2032 |
| 2090 void LayerTreeImpl::ResetAllChangeTracking() { | 2033 void LayerTreeImpl::ResetAllChangeTracking() { |
| 2091 layers_that_should_push_properties_.clear(); | 2034 layers_that_should_push_properties_.clear(); |
| 2092 for (auto* layer : *this) | 2035 for (auto* layer : *this) |
| 2093 layer->ResetChangeTracking(); | 2036 layer->ResetChangeTracking(); |
| 2094 property_trees_.ResetAllChangeTracking(); | 2037 property_trees_.ResetAllChangeTracking(); |
| 2095 } | 2038 } |
| 2096 | 2039 |
| 2097 } // namespace cc | 2040 } // namespace cc |
| OLD | NEW |