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(root_layer(), |
493 root_layer(), base::Bind(&ApplySentScrollDeltasFromAbortedCommitTo)); | 494 [](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 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
684 size_t LayerTreeImpl::NumLayers() { | 687 size_t LayerTreeImpl::NumLayers() { |
685 return layer_id_map_.size(); | 688 return layer_id_map_.size(); |
686 } | 689 } |
687 | 690 |
688 void LayerTreeImpl::PushPersistedState(LayerTreeImpl* pending_tree) { | 691 void LayerTreeImpl::PushPersistedState(LayerTreeImpl* pending_tree) { |
689 pending_tree->SetCurrentlyScrollingLayer( | 692 pending_tree->SetCurrentlyScrollingLayer( |
690 LayerTreeHostCommon::FindLayerInSubtree(pending_tree->root_layer(), | 693 LayerTreeHostCommon::FindLayerInSubtree(pending_tree->root_layer(), |
691 currently_scrolling_layer_ ? currently_scrolling_layer_->id() : 0)); | 694 currently_scrolling_layer_ ? currently_scrolling_layer_->id() : 0)); |
692 } | 695 } |
693 | 696 |
694 static void DidBecomeActiveRecursive(LayerImpl* layer) { | |
695 layer->DidBecomeActive(); | |
696 if (layer->mask_layer()) | |
697 layer->mask_layer()->DidBecomeActive(); | |
698 if (layer->replica_layer() && layer->replica_layer()->mask_layer()) | |
699 layer->replica_layer()->mask_layer()->DidBecomeActive(); | |
700 | |
701 for (size_t i = 0; i < layer->children().size(); ++i) | |
702 DidBecomeActiveRecursive(layer->children()[i]); | |
703 } | |
704 | |
705 void LayerTreeImpl::DidBecomeActive() { | 697 void LayerTreeImpl::DidBecomeActive() { |
706 if (next_activation_forces_redraw_) { | 698 if (next_activation_forces_redraw_) { |
707 layer_tree_host_impl_->SetFullRootLayerDamage(); | 699 layer_tree_host_impl_->SetFullRootLayerDamage(); |
708 next_activation_forces_redraw_ = false; | 700 next_activation_forces_redraw_ = false; |
709 } | 701 } |
710 | 702 |
711 if (scrolling_layer_id_from_previous_tree_) { | 703 if (scrolling_layer_id_from_previous_tree_) { |
712 currently_scrolling_layer_ = LayerTreeHostCommon::FindLayerInSubtree( | 704 currently_scrolling_layer_ = LayerTreeHostCommon::FindLayerInSubtree( |
713 root_layer(), scrolling_layer_id_from_previous_tree_); | 705 root_layer(), scrolling_layer_id_from_previous_tree_); |
714 } | 706 } |
715 | 707 |
716 // Always reset this flag on activation, as we would only have activated | 708 // Always reset this flag on activation, as we would only have activated |
717 // if we were in a good state. | 709 // if we were in a good state. |
718 layer_tree_host_impl_->ResetRequiresHighResToDraw(); | 710 layer_tree_host_impl_->ResetRequiresHighResToDraw(); |
719 | 711 |
720 if (root_layer()) | 712 if (root_layer()) { |
721 DidBecomeActiveRecursive(root_layer()); | 713 LayerTreeHostCommon::CallFunctionForSubtree( |
| 714 root_layer(), [](LayerImpl* layer) { layer->DidBecomeActive(); }); |
| 715 } |
722 | 716 |
723 devtools_instrumentation::DidActivateLayerTree(layer_tree_host_impl_->id(), | 717 devtools_instrumentation::DidActivateLayerTree(layer_tree_host_impl_->id(), |
724 source_frame_number_); | 718 source_frame_number_); |
725 } | 719 } |
726 | 720 |
727 bool LayerTreeImpl::ContentsTexturesPurged() const { | 721 bool LayerTreeImpl::ContentsTexturesPurged() const { |
728 return contents_textures_purged_; | 722 return contents_textures_purged_; |
729 } | 723 } |
730 | 724 |
731 void LayerTreeImpl::SetContentsTexturesPurged() { | 725 void LayerTreeImpl::SetContentsTexturesPurged() { |
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1199 | 1193 |
1200 const std::vector<LayerImpl*>& LayerTreeImpl::LayersWithCopyOutputRequest() | 1194 const std::vector<LayerImpl*>& LayerTreeImpl::LayersWithCopyOutputRequest() |
1201 const { | 1195 const { |
1202 // Only the active tree needs to know about layers with copy requests, as | 1196 // Only the active tree needs to know about layers with copy requests, as |
1203 // they are aborted if not serviced during draw. | 1197 // they are aborted if not serviced during draw. |
1204 DCHECK(IsActiveTree()); | 1198 DCHECK(IsActiveTree()); |
1205 | 1199 |
1206 return layers_with_copy_output_request_; | 1200 return layers_with_copy_output_request_; |
1207 } | 1201 } |
1208 | 1202 |
1209 void LayerTreeImpl::ProcessLayersRecursive(LayerImpl* current, | |
1210 void (LayerImpl::*function)()) { | |
1211 DCHECK(current); | |
1212 (current->*function)(); | |
1213 if (current->mask_layer()) | |
1214 ProcessLayersRecursive(current->mask_layer(), function); | |
1215 if (current->replica_layer()) | |
1216 ProcessLayersRecursive(current->replica_layer(), function); | |
1217 for (size_t i = 0; i < current->children().size(); ++i) | |
1218 ProcessLayersRecursive(current->children()[i], function); | |
1219 } | |
1220 | |
1221 template <typename LayerType> | 1203 template <typename LayerType> |
1222 static inline bool LayerClipsSubtree(LayerType* layer) { | 1204 static inline bool LayerClipsSubtree(LayerType* layer) { |
1223 return layer->masks_to_bounds() || layer->mask_layer(); | 1205 return layer->masks_to_bounds() || layer->mask_layer(); |
1224 } | 1206 } |
1225 | 1207 |
1226 static bool PointHitsRect( | 1208 static bool PointHitsRect( |
1227 const gfx::PointF& screen_space_point, | 1209 const gfx::PointF& screen_space_point, |
1228 const gfx::Transform& local_space_to_screen_space_transform, | 1210 const gfx::Transform& local_space_to_screen_space_transform, |
1229 const gfx::RectF& local_space_rect, | 1211 const gfx::RectF& local_space_rect, |
1230 float* distance_to_camera) { | 1212 float* distance_to_camera) { |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1590 scoped_ptr<PendingPageScaleAnimation> pending_animation) { | 1572 scoped_ptr<PendingPageScaleAnimation> pending_animation) { |
1591 pending_page_scale_animation_ = pending_animation.Pass(); | 1573 pending_page_scale_animation_ = pending_animation.Pass(); |
1592 } | 1574 } |
1593 | 1575 |
1594 scoped_ptr<PendingPageScaleAnimation> | 1576 scoped_ptr<PendingPageScaleAnimation> |
1595 LayerTreeImpl::TakePendingPageScaleAnimation() { | 1577 LayerTreeImpl::TakePendingPageScaleAnimation() { |
1596 return pending_page_scale_animation_.Pass(); | 1578 return pending_page_scale_animation_.Pass(); |
1597 } | 1579 } |
1598 | 1580 |
1599 } // namespace cc | 1581 } // namespace cc |
OLD | NEW |