OLD | NEW |
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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_impl.h" | 5 #include "cc/layers/layer_impl.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <utility> | 10 #include <utility> |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 num_dependents_need_push_properties_(0), | 93 num_dependents_need_push_properties_(0), |
94 sorting_context_id_(0), | 94 sorting_context_id_(0), |
95 current_draw_mode_(DRAW_MODE_NONE), | 95 current_draw_mode_(DRAW_MODE_NONE), |
96 element_id_(0), | 96 element_id_(0), |
97 mutable_properties_(MutableProperty::kNone), | 97 mutable_properties_(MutableProperty::kNone), |
98 force_render_surface_(false), | 98 force_render_surface_(false), |
99 frame_timing_requests_dirty_(false), | 99 frame_timing_requests_dirty_(false), |
100 visited_(false), | 100 visited_(false), |
101 layer_or_descendant_is_drawn_(false), | 101 layer_or_descendant_is_drawn_(false), |
102 layer_or_descendant_has_input_handler_(false), | 102 layer_or_descendant_has_input_handler_(false), |
103 sorted_for_recursion_(false), | 103 sorted_for_recursion_(false) { |
104 is_hidden_from_property_trees_(false) { | |
105 DCHECK_GT(layer_id_, 0); | 104 DCHECK_GT(layer_id_, 0); |
106 DCHECK(layer_tree_impl_); | 105 DCHECK(layer_tree_impl_); |
107 layer_tree_impl_->RegisterLayer(this); | 106 layer_tree_impl_->RegisterLayer(this); |
108 | 107 |
109 if (!layer_tree_impl_->settings().use_compositor_animation_timelines) { | 108 if (!layer_tree_impl_->settings().use_compositor_animation_timelines) { |
110 AnimationRegistrar* registrar = layer_tree_impl_->GetAnimationRegistrar(); | 109 AnimationRegistrar* registrar = layer_tree_impl_->GetAnimationRegistrar(); |
111 layer_animation_controller_ = | 110 layer_animation_controller_ = |
112 registrar->GetAnimationControllerForId(layer_id_); | 111 registrar->GetAnimationControllerForId(layer_id_); |
113 layer_animation_controller_->AddValueObserver(this); | 112 layer_animation_controller_->AddValueObserver(this); |
114 if (IsActive()) { | 113 if (IsActive()) { |
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
652 | 651 |
653 layer->PushScrollOffset(nullptr); | 652 layer->PushScrollOffset(nullptr); |
654 | 653 |
655 layer->Set3dSortingContextId(sorting_context_id_); | 654 layer->Set3dSortingContextId(sorting_context_id_); |
656 layer->SetNumDescendantsThatDrawContent(num_descendants_that_draw_content_); | 655 layer->SetNumDescendantsThatDrawContent(num_descendants_that_draw_content_); |
657 | 656 |
658 layer->SetTransformTreeIndex(transform_tree_index_); | 657 layer->SetTransformTreeIndex(transform_tree_index_); |
659 layer->SetClipTreeIndex(clip_tree_index_); | 658 layer->SetClipTreeIndex(clip_tree_index_); |
660 layer->SetEffectTreeIndex(effect_tree_index_); | 659 layer->SetEffectTreeIndex(effect_tree_index_); |
661 layer->set_offset_to_transform_parent(offset_to_transform_parent_); | 660 layer->set_offset_to_transform_parent(offset_to_transform_parent_); |
662 layer->set_is_hidden_from_property_trees(is_hidden_from_property_trees_); | |
663 | 661 |
664 LayerImpl* scroll_parent = nullptr; | 662 LayerImpl* scroll_parent = nullptr; |
665 if (scroll_parent_) { | 663 if (scroll_parent_) { |
666 scroll_parent = layer->layer_tree_impl()->LayerById(scroll_parent_->id()); | 664 scroll_parent = layer->layer_tree_impl()->LayerById(scroll_parent_->id()); |
667 DCHECK(scroll_parent); | 665 DCHECK(scroll_parent); |
668 } | 666 } |
669 | 667 |
670 layer->SetScrollParent(scroll_parent); | 668 layer->SetScrollParent(scroll_parent); |
671 if (scroll_children_) { | 669 if (scroll_children_) { |
672 std::set<LayerImpl*>* scroll_children = new std::set<LayerImpl*>; | 670 std::set<LayerImpl*>* scroll_children = new std::set<LayerImpl*>; |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
955 if (effect_tree_index_ >= static_cast<int>(effect_tree.size())) | 953 if (effect_tree_index_ >= static_cast<int>(effect_tree.size())) |
956 return; | 954 return; |
957 EffectNode* node = effect_tree.Node(effect_tree_index_); | 955 EffectNode* node = effect_tree.Node(effect_tree_index_); |
958 // A LayerImpl's own current state is insufficient for determining whether | 956 // A LayerImpl's own current state is insufficient for determining whether |
959 // it owns an OpacityNode, since this depends on the state of the | 957 // it owns an OpacityNode, since this depends on the state of the |
960 // corresponding Layer at the time of the last commit. For example, an | 958 // corresponding Layer at the time of the last commit. For example, an |
961 // opacity animation might have been in progress at the time the last commit | 959 // opacity animation might have been in progress at the time the last commit |
962 // started, but might have finished since then on the compositor thread. | 960 // started, but might have finished since then on the compositor thread. |
963 if (node->owner_id != id()) | 961 if (node->owner_id != id()) |
964 return; | 962 return; |
965 node->data.opacity = opacity_; | 963 node->data.opacity = EffectiveOpacity(); |
966 effect_tree.set_needs_update(true); | 964 effect_tree.set_needs_update(true); |
967 } | 965 } |
968 } | 966 } |
969 | 967 |
970 void LayerImpl::UpdatePropertyTreeForScrollingAndAnimationIfNeeded() { | 968 void LayerImpl::UpdatePropertyTreeForScrollingAndAnimationIfNeeded() { |
971 if (scrollable()) | 969 if (scrollable()) |
972 UpdatePropertyTreeScrollOffset(); | 970 UpdatePropertyTreeScrollOffset(); |
973 | 971 |
974 if (HasAnyAnimationTargetingProperty(Animation::OPACITY)) | 972 if (HasAnyAnimationTargetingProperty(Animation::OPACITY)) |
975 UpdatePropertyTreeOpacity(); | 973 UpdatePropertyTreeOpacity(); |
976 | 974 |
977 if (HasAnyAnimationTargetingProperty(Animation::TRANSFORM)) { | 975 if (HasAnyAnimationTargetingProperty(Animation::TRANSFORM)) { |
978 UpdatePropertyTreeTransform(); | 976 UpdatePropertyTreeTransform(); |
979 UpdatePropertyTreeTransformIsAnimated( | 977 UpdatePropertyTreeTransformIsAnimated( |
980 HasPotentiallyRunningTransformAnimation()); | 978 HasPotentiallyRunningTransformAnimation()); |
981 } | 979 } |
982 } | 980 } |
983 | 981 |
984 gfx::ScrollOffset LayerImpl::ScrollOffsetForAnimation() const { | 982 gfx::ScrollOffset LayerImpl::ScrollOffsetForAnimation() const { |
985 return CurrentScrollOffset(); | 983 return CurrentScrollOffset(); |
986 } | 984 } |
987 | 985 |
988 void LayerImpl::OnFilterAnimated(const FilterOperations& filters) { | 986 void LayerImpl::OnFilterAnimated(const FilterOperations& filters) { |
989 SetFilters(filters); | 987 SetFilters(filters); |
990 } | 988 } |
991 | 989 |
992 void LayerImpl::OnOpacityAnimated(float opacity) { | 990 void LayerImpl::OnOpacityAnimated(float opacity) { |
993 SetOpacity(opacity); | 991 SetOpacity(opacity); |
994 UpdatePropertyTreeOpacity(); | 992 // When hide_layer_and_subtree is true, the effective opacity is zero and we |
| 993 // need not update the opacity on property trees. |
| 994 if (!hide_layer_and_subtree_) |
| 995 UpdatePropertyTreeOpacity(); |
995 } | 996 } |
996 | 997 |
997 void LayerImpl::OnTransformAnimated(const gfx::Transform& transform) { | 998 void LayerImpl::OnTransformAnimated(const gfx::Transform& transform) { |
998 SetTransform(transform); | 999 SetTransform(transform); |
999 UpdatePropertyTreeTransform(); | 1000 UpdatePropertyTreeTransform(); |
1000 was_ever_ready_since_last_transform_animation_ = false; | 1001 was_ever_ready_since_last_transform_animation_ = false; |
1001 } | 1002 } |
1002 | 1003 |
1003 void LayerImpl::OnScrollOffsetAnimated(const gfx::ScrollOffset& scroll_offset) { | 1004 void LayerImpl::OnScrollOffsetAnimated(const gfx::ScrollOffset& scroll_offset) { |
1004 // Only layers in the active tree should need to do anything here, since | 1005 // Only layers in the active tree should need to do anything here, since |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1241 } | 1242 } |
1242 | 1243 |
1243 void LayerImpl::SetOpacity(float opacity) { | 1244 void LayerImpl::SetOpacity(float opacity) { |
1244 if (opacity_ == opacity) | 1245 if (opacity_ == opacity) |
1245 return; | 1246 return; |
1246 | 1247 |
1247 opacity_ = opacity; | 1248 opacity_ = opacity; |
1248 NoteLayerPropertyChangedForSubtree(); | 1249 NoteLayerPropertyChangedForSubtree(); |
1249 } | 1250 } |
1250 | 1251 |
| 1252 float LayerImpl::EffectiveOpacity() const { |
| 1253 return hide_layer_and_subtree_ ? 0.f : opacity_; |
| 1254 } |
| 1255 |
1251 bool LayerImpl::OpacityIsAnimating() const { | 1256 bool LayerImpl::OpacityIsAnimating() const { |
1252 LayerAnimationController::ObserverType observer_type = | 1257 LayerAnimationController::ObserverType observer_type = |
1253 IsActive() ? LayerAnimationController::ObserverType::ACTIVE | 1258 IsActive() ? LayerAnimationController::ObserverType::ACTIVE |
1254 : LayerAnimationController::ObserverType::PENDING; | 1259 : LayerAnimationController::ObserverType::PENDING; |
1255 return layer_animation_controller_ | 1260 return layer_animation_controller_ |
1256 ? layer_animation_controller_->IsCurrentlyAnimatingProperty( | 1261 ? layer_animation_controller_->IsCurrentlyAnimatingProperty( |
1257 Animation::OPACITY, observer_type) | 1262 Animation::OPACITY, observer_type) |
1258 : layer_tree_impl_->IsAnimatingOpacityProperty(this); | 1263 : layer_tree_impl_->IsAnimatingOpacityProperty(this); |
1259 } | 1264 } |
1260 | 1265 |
(...skipping 655 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1916 } | 1921 } |
1917 | 1922 |
1918 gfx::Rect LayerImpl::GetScaledEnclosingRectInTargetSpace(float scale) const { | 1923 gfx::Rect LayerImpl::GetScaledEnclosingRectInTargetSpace(float scale) const { |
1919 gfx::Transform scaled_draw_transform = DrawTransform(); | 1924 gfx::Transform scaled_draw_transform = DrawTransform(); |
1920 scaled_draw_transform.Scale(SK_MScalar1 / scale, SK_MScalar1 / scale); | 1925 scaled_draw_transform.Scale(SK_MScalar1 / scale, SK_MScalar1 / scale); |
1921 gfx::Size scaled_bounds = gfx::ScaleToCeiledSize(bounds(), scale); | 1926 gfx::Size scaled_bounds = gfx::ScaleToCeiledSize(bounds(), scale); |
1922 return MathUtil::MapEnclosingClippedRect(scaled_draw_transform, | 1927 return MathUtil::MapEnclosingClippedRect(scaled_draw_transform, |
1923 gfx::Rect(scaled_bounds)); | 1928 gfx::Rect(scaled_bounds)); |
1924 } | 1929 } |
1925 | 1930 |
1926 bool LayerImpl::LayerIsHidden() const { | 1931 bool LayerImpl::IsHidden() const { |
1927 if (layer_tree_impl()->settings().use_property_trees) { | 1932 if (layer_tree_impl()->settings().use_property_trees) { |
1928 return is_hidden_from_property_trees_; | 1933 EffectTree& effect_tree = layer_tree_impl_->property_trees()->effect_tree; |
| 1934 EffectNode* node = effect_tree.Node(effect_tree_index_); |
| 1935 return node->data.screen_space_opacity == 0.f; |
1929 } else { | 1936 } else { |
1930 return hide_layer_and_subtree_ || (parent() && parent()->LayerIsHidden()); | 1937 return EffectiveOpacity() == 0.f || (parent() && parent()->IsHidden()); |
1931 } | 1938 } |
1932 } | 1939 } |
1933 | 1940 |
1934 float LayerImpl::GetIdealContentsScale() const { | 1941 float LayerImpl::GetIdealContentsScale() const { |
1935 float page_scale = IsAffectedByPageScale() | 1942 float page_scale = IsAffectedByPageScale() |
1936 ? layer_tree_impl()->current_page_scale_factor() | 1943 ? layer_tree_impl()->current_page_scale_factor() |
1937 : 1.f; | 1944 : 1.f; |
1938 float device_scale = layer_tree_impl()->device_scale_factor(); | 1945 float device_scale = layer_tree_impl()->device_scale_factor(); |
1939 | 1946 |
1940 float default_scale = page_scale * device_scale; | 1947 float default_scale = page_scale * device_scale; |
1941 if (!layer_tree_impl() | 1948 if (!layer_tree_impl() |
1942 ->settings() | 1949 ->settings() |
1943 .layer_transforms_should_scale_layer_contents) { | 1950 .layer_transforms_should_scale_layer_contents) { |
1944 return default_scale; | 1951 return default_scale; |
1945 } | 1952 } |
1946 | 1953 |
1947 gfx::Vector2dF transform_scales = MathUtil::ComputeTransform2dScaleComponents( | 1954 gfx::Vector2dF transform_scales = MathUtil::ComputeTransform2dScaleComponents( |
1948 DrawTransform(), default_scale); | 1955 DrawTransform(), default_scale); |
1949 return std::max(transform_scales.x(), transform_scales.y()); | 1956 return std::max(transform_scales.x(), transform_scales.y()); |
1950 } | 1957 } |
1951 | 1958 |
1952 } // namespace cc | 1959 } // namespace cc |
OLD | NEW |