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 <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <set> | 9 #include <set> |
10 | 10 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 // the LayerTreeImpl pointer is still valid in the LayerImpl dtor. | 114 // the LayerTreeImpl pointer is still valid in the LayerImpl dtor. |
115 DCHECK(!root_layer_); | 115 DCHECK(!root_layer_); |
116 DCHECK(layers_with_copy_output_request_.empty()); | 116 DCHECK(layers_with_copy_output_request_.empty()); |
117 } | 117 } |
118 | 118 |
119 void LayerTreeImpl::Shutdown() { | 119 void LayerTreeImpl::Shutdown() { |
120 root_layer_ = nullptr; | 120 root_layer_ = nullptr; |
121 } | 121 } |
122 | 122 |
123 void LayerTreeImpl::ReleaseResources() { | 123 void LayerTreeImpl::ReleaseResources() { |
124 if (root_layer_) | 124 if (root_layer_) { |
125 ProcessLayersRecursive(root_layer_.get(), &LayerImpl::ReleaseResources); | 125 LayerTreeHostCommon::CallFunctionForSubtree( |
| 126 root_layer_.get(), [](LayerImpl* layer) { layer->ReleaseResources(); }); |
| 127 } |
126 } | 128 } |
127 | 129 |
128 void LayerTreeImpl::RecreateResources() { | 130 void LayerTreeImpl::RecreateResources() { |
129 if (root_layer_) | 131 if (root_layer_) { |
130 ProcessLayersRecursive(root_layer_.get(), &LayerImpl::RecreateResources); | 132 LayerTreeHostCommon::CallFunctionForSubtree( |
| 133 root_layer_.get(), |
| 134 [](LayerImpl* layer) { layer->RecreateResources(); }); |
| 135 } |
131 } | 136 } |
132 | 137 |
133 void LayerTreeImpl::SetRootLayer(scoped_ptr<LayerImpl> layer) { | 138 void LayerTreeImpl::SetRootLayer(scoped_ptr<LayerImpl> layer) { |
134 if (inner_viewport_scroll_layer_) | 139 if (inner_viewport_scroll_layer_) |
135 inner_viewport_scroll_layer_->SetScrollOffsetDelegate(NULL); | 140 inner_viewport_scroll_layer_->SetScrollOffsetDelegate(NULL); |
136 if (outer_viewport_scroll_layer_) | 141 if (outer_viewport_scroll_layer_) |
137 outer_viewport_scroll_layer_->SetScrollOffsetDelegate(NULL); | 142 outer_viewport_scroll_layer_->SetScrollOffsetDelegate(NULL); |
138 inner_viewport_scroll_delegate_proxy_ = nullptr; | 143 inner_viewport_scroll_delegate_proxy_ = nullptr; |
139 outer_viewport_scroll_delegate_proxy_ = nullptr; | 144 outer_viewport_scroll_delegate_proxy_ = nullptr; |
140 | 145 |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
468 LayerImpl* root_scroll_layer = OuterViewportScrollLayer() | 473 LayerImpl* root_scroll_layer = OuterViewportScrollLayer() |
469 ? OuterViewportScrollLayer() | 474 ? OuterViewportScrollLayer() |
470 : InnerViewportScrollLayer(); | 475 : InnerViewportScrollLayer(); |
471 if (!root_scroll_layer || root_scroll_layer->children().empty()) | 476 if (!root_scroll_layer || root_scroll_layer->children().empty()) |
472 return gfx::Rect(); | 477 return gfx::Rect(); |
473 LayerImpl* layer = root_scroll_layer->children()[0]; | 478 LayerImpl* layer = root_scroll_layer->children()[0]; |
474 return MathUtil::MapEnclosingClippedRect(layer->screen_space_transform(), | 479 return MathUtil::MapEnclosingClippedRect(layer->screen_space_transform(), |
475 gfx::Rect(layer->content_bounds())); | 480 gfx::Rect(layer->content_bounds())); |
476 } | 481 } |
477 | 482 |
478 static void ApplySentScrollDeltasFromAbortedCommitTo(LayerImpl* layer) { | |
479 layer->ApplySentScrollDeltasFromAbortedCommit(); | |
480 } | |
481 | |
482 void LayerTreeImpl::ApplySentScrollAndScaleDeltasFromAbortedCommit() { | 483 void LayerTreeImpl::ApplySentScrollAndScaleDeltasFromAbortedCommit() { |
483 DCHECK(IsActiveTree()); | 484 DCHECK(IsActiveTree()); |
484 | 485 |
485 page_scale_factor()->AbortCommit(); | 486 page_scale_factor()->AbortCommit(); |
486 top_controls_shown_ratio()->AbortCommit(); | 487 top_controls_shown_ratio()->AbortCommit(); |
487 elastic_overscroll()->AbortCommit(); | 488 elastic_overscroll()->AbortCommit(); |
488 | 489 |
489 if (!root_layer()) | 490 if (!root_layer()) |
490 return; | 491 return; |
491 | 492 |
492 LayerTreeHostCommon::CallFunctionForSubtree( | 493 LayerTreeHostCommon::CallFunctionForSubtree( |
493 root_layer(), base::Bind(&ApplySentScrollDeltasFromAbortedCommitTo)); | 494 root_layer(), [](LayerImpl* layer) { |
| 495 layer->ApplySentScrollDeltasFromAbortedCommit(); |
| 496 }); |
494 } | 497 } |
495 | 498 |
496 void LayerTreeImpl::SetViewportLayersFromIds( | 499 void LayerTreeImpl::SetViewportLayersFromIds( |
497 int overscroll_elasticity_layer_id, | 500 int overscroll_elasticity_layer_id, |
498 int page_scale_layer_id, | 501 int page_scale_layer_id, |
499 int inner_viewport_scroll_layer_id, | 502 int inner_viewport_scroll_layer_id, |
500 int outer_viewport_scroll_layer_id) { | 503 int outer_viewport_scroll_layer_id) { |
501 overscroll_elasticity_layer_ = LayerById(overscroll_elasticity_layer_id); | 504 overscroll_elasticity_layer_ = LayerById(overscroll_elasticity_layer_id); |
502 page_scale_layer_ = LayerById(page_scale_layer_id); | 505 page_scale_layer_ = LayerById(page_scale_layer_id); |
503 DCHECK(page_scale_layer_); | 506 DCHECK(page_scale_layer_); |
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
741 size_t LayerTreeImpl::NumLayers() { | 744 size_t LayerTreeImpl::NumLayers() { |
742 return layer_id_map_.size(); | 745 return layer_id_map_.size(); |
743 } | 746 } |
744 | 747 |
745 void LayerTreeImpl::PushPersistedState(LayerTreeImpl* pending_tree) { | 748 void LayerTreeImpl::PushPersistedState(LayerTreeImpl* pending_tree) { |
746 pending_tree->SetCurrentlyScrollingLayer( | 749 pending_tree->SetCurrentlyScrollingLayer( |
747 LayerTreeHostCommon::FindLayerInSubtree(pending_tree->root_layer(), | 750 LayerTreeHostCommon::FindLayerInSubtree(pending_tree->root_layer(), |
748 currently_scrolling_layer_ ? currently_scrolling_layer_->id() : 0)); | 751 currently_scrolling_layer_ ? currently_scrolling_layer_->id() : 0)); |
749 } | 752 } |
750 | 753 |
751 static void DidBecomeActiveRecursive(LayerImpl* layer) { | |
752 layer->DidBecomeActive(); | |
753 if (layer->mask_layer()) | |
754 layer->mask_layer()->DidBecomeActive(); | |
755 if (layer->replica_layer() && layer->replica_layer()->mask_layer()) | |
756 layer->replica_layer()->mask_layer()->DidBecomeActive(); | |
757 | |
758 for (size_t i = 0; i < layer->children().size(); ++i) | |
759 DidBecomeActiveRecursive(layer->children()[i]); | |
760 } | |
761 | |
762 void LayerTreeImpl::DidBecomeActive() { | 754 void LayerTreeImpl::DidBecomeActive() { |
763 if (next_activation_forces_redraw_) { | 755 if (next_activation_forces_redraw_) { |
764 layer_tree_host_impl_->SetFullRootLayerDamage(); | 756 layer_tree_host_impl_->SetFullRootLayerDamage(); |
765 next_activation_forces_redraw_ = false; | 757 next_activation_forces_redraw_ = false; |
766 } | 758 } |
767 | 759 |
768 if (scrolling_layer_id_from_previous_tree_) { | 760 if (scrolling_layer_id_from_previous_tree_) { |
769 currently_scrolling_layer_ = LayerTreeHostCommon::FindLayerInSubtree( | 761 currently_scrolling_layer_ = LayerTreeHostCommon::FindLayerInSubtree( |
770 root_layer(), scrolling_layer_id_from_previous_tree_); | 762 root_layer(), scrolling_layer_id_from_previous_tree_); |
771 } | 763 } |
772 | 764 |
773 // Always reset this flag on activation, as we would only have activated | 765 // Always reset this flag on activation, as we would only have activated |
774 // if we were in a good state. | 766 // if we were in a good state. |
775 layer_tree_host_impl_->ResetRequiresHighResToDraw(); | 767 layer_tree_host_impl_->ResetRequiresHighResToDraw(); |
776 | 768 |
777 if (root_layer()) | 769 if (root_layer()) { |
778 DidBecomeActiveRecursive(root_layer()); | 770 LayerTreeHostCommon::CallFunctionForSubtree( |
| 771 root_layer(), [](LayerImpl* layer) { layer->DidBecomeActive(); }); |
| 772 } |
779 | 773 |
780 devtools_instrumentation::DidActivateLayerTree(layer_tree_host_impl_->id(), | 774 devtools_instrumentation::DidActivateLayerTree(layer_tree_host_impl_->id(), |
781 source_frame_number_); | 775 source_frame_number_); |
782 } | 776 } |
783 | 777 |
784 bool LayerTreeImpl::ContentsTexturesPurged() const { | 778 bool LayerTreeImpl::ContentsTexturesPurged() const { |
785 return contents_textures_purged_; | 779 return contents_textures_purged_; |
786 } | 780 } |
787 | 781 |
788 void LayerTreeImpl::SetContentsTexturesPurged() { | 782 void LayerTreeImpl::SetContentsTexturesPurged() { |
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1260 | 1254 |
1261 const std::vector<LayerImpl*>& LayerTreeImpl::LayersWithCopyOutputRequest() | 1255 const std::vector<LayerImpl*>& LayerTreeImpl::LayersWithCopyOutputRequest() |
1262 const { | 1256 const { |
1263 // Only the active tree needs to know about layers with copy requests, as | 1257 // Only the active tree needs to know about layers with copy requests, as |
1264 // they are aborted if not serviced during draw. | 1258 // they are aborted if not serviced during draw. |
1265 DCHECK(IsActiveTree()); | 1259 DCHECK(IsActiveTree()); |
1266 | 1260 |
1267 return layers_with_copy_output_request_; | 1261 return layers_with_copy_output_request_; |
1268 } | 1262 } |
1269 | 1263 |
1270 void LayerTreeImpl::ProcessLayersRecursive(LayerImpl* current, | |
1271 void (LayerImpl::*function)()) { | |
1272 DCHECK(current); | |
1273 (current->*function)(); | |
1274 if (current->mask_layer()) | |
1275 ProcessLayersRecursive(current->mask_layer(), function); | |
1276 if (current->replica_layer()) | |
1277 ProcessLayersRecursive(current->replica_layer(), function); | |
1278 for (size_t i = 0; i < current->children().size(); ++i) | |
1279 ProcessLayersRecursive(current->children()[i], function); | |
1280 } | |
1281 | |
1282 template <typename LayerType> | 1264 template <typename LayerType> |
1283 static inline bool LayerClipsSubtree(LayerType* layer) { | 1265 static inline bool LayerClipsSubtree(LayerType* layer) { |
1284 return layer->masks_to_bounds() || layer->mask_layer(); | 1266 return layer->masks_to_bounds() || layer->mask_layer(); |
1285 } | 1267 } |
1286 | 1268 |
1287 static bool PointHitsRect( | 1269 static bool PointHitsRect( |
1288 const gfx::PointF& screen_space_point, | 1270 const gfx::PointF& screen_space_point, |
1289 const gfx::Transform& local_space_to_screen_space_transform, | 1271 const gfx::Transform& local_space_to_screen_space_transform, |
1290 const gfx::RectF& local_space_rect, | 1272 const gfx::RectF& local_space_rect, |
1291 float* distance_to_camera) { | 1273 float* distance_to_camera) { |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1654 scoped_ptr<PendingPageScaleAnimation> pending_animation) { | 1636 scoped_ptr<PendingPageScaleAnimation> pending_animation) { |
1655 pending_page_scale_animation_ = pending_animation.Pass(); | 1637 pending_page_scale_animation_ = pending_animation.Pass(); |
1656 } | 1638 } |
1657 | 1639 |
1658 scoped_ptr<PendingPageScaleAnimation> | 1640 scoped_ptr<PendingPageScaleAnimation> |
1659 LayerTreeImpl::TakePendingPageScaleAnimation() { | 1641 LayerTreeImpl::TakePendingPageScaleAnimation() { |
1660 return pending_page_scale_animation_.Pass(); | 1642 return pending_page_scale_animation_.Pass(); |
1661 } | 1643 } |
1662 | 1644 |
1663 } // namespace cc | 1645 } // namespace cc |
OLD | NEW |