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