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