| 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 <algorithm> | 10 #include <algorithm> |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 user_scrollable_vertical_(true), | 59 user_scrollable_vertical_(true), |
| 60 should_flatten_transform_from_property_tree_(false), | 60 should_flatten_transform_from_property_tree_(false), |
| 61 layer_property_changed_(false), | 61 layer_property_changed_(false), |
| 62 masks_to_bounds_(false), | 62 masks_to_bounds_(false), |
| 63 contents_opaque_(false), | 63 contents_opaque_(false), |
| 64 use_parent_backface_visibility_(false), | 64 use_parent_backface_visibility_(false), |
| 65 use_local_transform_for_backface_visibility_(false), | 65 use_local_transform_for_backface_visibility_(false), |
| 66 should_check_backface_visibility_(false), | 66 should_check_backface_visibility_(false), |
| 67 draws_content_(false), | 67 draws_content_(false), |
| 68 is_drawn_render_surface_layer_list_member_(false), | 68 is_drawn_render_surface_layer_list_member_(false), |
| 69 hide_layer_and_subtree_(false), | |
| 70 is_affected_by_page_scale_(true), | 69 is_affected_by_page_scale_(true), |
| 71 was_ever_ready_since_last_transform_animation_(true), | 70 was_ever_ready_since_last_transform_animation_(true), |
| 72 background_color_(0), | 71 background_color_(0), |
| 73 safe_opaque_background_color_(0), | 72 safe_opaque_background_color_(0), |
| 74 opacity_(1.0), | 73 opacity_(1.0), |
| 75 blend_mode_(SkXfermode::kSrcOver_Mode), | 74 blend_mode_(SkXfermode::kSrcOver_Mode), |
| 76 draw_blend_mode_(SkXfermode::kSrcOver_Mode), | 75 draw_blend_mode_(SkXfermode::kSrcOver_Mode), |
| 77 transform_tree_index_(-1), | 76 transform_tree_index_(-1), |
| 78 effect_tree_index_(-1), | 77 effect_tree_index_(-1), |
| 79 clip_tree_index_(-1), | 78 clip_tree_index_(-1), |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 } | 433 } |
| 435 | 434 |
| 436 main_thread_scrolling_reasons_ = main_thread_scrolling_reasons; | 435 main_thread_scrolling_reasons_ = main_thread_scrolling_reasons; |
| 437 } | 436 } |
| 438 | 437 |
| 439 void LayerImpl::PushPropertiesTo(LayerImpl* layer) { | 438 void LayerImpl::PushPropertiesTo(LayerImpl* layer) { |
| 440 layer->SetBackgroundColor(background_color_); | 439 layer->SetBackgroundColor(background_color_); |
| 441 layer->SetSafeOpaqueBackgroundColor(safe_opaque_background_color_); | 440 layer->SetSafeOpaqueBackgroundColor(safe_opaque_background_color_); |
| 442 layer->SetBounds(bounds_); | 441 layer->SetBounds(bounds_); |
| 443 layer->SetDrawsContent(DrawsContent()); | 442 layer->SetDrawsContent(DrawsContent()); |
| 444 layer->SetHideLayerAndSubtree(hide_layer_and_subtree_); | |
| 445 // If whether layer has render surface changes, we need to update draw | 443 // If whether layer has render surface changes, we need to update draw |
| 446 // properties. | 444 // properties. |
| 447 // TODO(weiliangc): Should be safely removed after impl side is able to | 445 // TODO(weiliangc): Should be safely removed after impl side is able to |
| 448 // update render surfaces without rebuilding property trees. | 446 // update render surfaces without rebuilding property trees. |
| 449 if (layer->has_render_surface() != has_render_surface()) | 447 if (layer->has_render_surface() != has_render_surface()) |
| 450 layer->layer_tree_impl()->set_needs_update_draw_properties(); | 448 layer->layer_tree_impl()->set_needs_update_draw_properties(); |
| 451 layer->SetFilters(filters()); | 449 layer->SetFilters(filters()); |
| 452 layer->SetBackgroundFilters(background_filters()); | 450 layer->SetBackgroundFilters(background_filters()); |
| 453 layer->SetMasksToBounds(masks_to_bounds_); | 451 layer->SetMasksToBounds(masks_to_bounds_); |
| 454 layer->set_main_thread_scrolling_reasons(main_thread_scrolling_reasons_); | 452 layer->set_main_thread_scrolling_reasons(main_thread_scrolling_reasons_); |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 703 if (effect_tree_index_ != -1) { | 701 if (effect_tree_index_ != -1) { |
| 704 EffectTree& effect_tree = layer_tree_impl()->property_trees()->effect_tree; | 702 EffectTree& effect_tree = layer_tree_impl()->property_trees()->effect_tree; |
| 705 if (effect_tree_index_ >= static_cast<int>(effect_tree.size())) | 703 if (effect_tree_index_ >= static_cast<int>(effect_tree.size())) |
| 706 return; | 704 return; |
| 707 EffectNode* node = effect_tree.Node(effect_tree_index_); | 705 EffectNode* node = effect_tree.Node(effect_tree_index_); |
| 708 // A LayerImpl's own current state is insufficient for determining whether | 706 // A LayerImpl's own current state is insufficient for determining whether |
| 709 // it owns an OpacityNode, since this depends on the state of the | 707 // it owns an OpacityNode, since this depends on the state of the |
| 710 // corresponding Layer at the time of the last commit. For example, an | 708 // corresponding Layer at the time of the last commit. For example, an |
| 711 // opacity animation might have been in progress at the time the last commit | 709 // opacity animation might have been in progress at the time the last commit |
| 712 // started, but might have finished since then on the compositor thread. | 710 // started, but might have finished since then on the compositor thread. |
| 713 float effective_opacity = EffectiveOpacity(); | 711 if (node->owner_id != id() || node->data.opacity == opacity_) |
| 714 if (node->owner_id != id() || node->data.opacity == effective_opacity) | |
| 715 return; | 712 return; |
| 716 node->data.opacity = effective_opacity; | 713 node->data.opacity = opacity_; |
| 717 node->data.effect_changed = true; | 714 node->data.effect_changed = true; |
| 718 layer_tree_impl()->property_trees()->changed = true; | 715 layer_tree_impl()->property_trees()->changed = true; |
| 719 effect_tree.set_needs_update(true); | 716 effect_tree.set_needs_update(true); |
| 720 } | 717 } |
| 721 } | 718 } |
| 722 | 719 |
| 723 void LayerImpl::UpdatePropertyTreeForScrollingAndAnimationIfNeeded() { | 720 void LayerImpl::UpdatePropertyTreeForScrollingAndAnimationIfNeeded() { |
| 724 if (scrollable()) | 721 if (scrollable()) |
| 725 UpdatePropertyTreeScrollOffset(); | 722 UpdatePropertyTreeScrollOffset(); |
| 726 | 723 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 747 EffectNode* node = effect_tree.Node(effect_tree_index_); | 744 EffectNode* node = effect_tree.Node(effect_tree_index_); |
| 748 DCHECK_EQ(node->owner_id, id()); | 745 DCHECK_EQ(node->owner_id, id()); |
| 749 node->data.effect_changed = true; | 746 node->data.effect_changed = true; |
| 750 layer_tree_impl()->property_trees()->changed = true; | 747 layer_tree_impl()->property_trees()->changed = true; |
| 751 effect_tree.set_needs_update(true); | 748 effect_tree.set_needs_update(true); |
| 752 } | 749 } |
| 753 } | 750 } |
| 754 | 751 |
| 755 void LayerImpl::OnOpacityAnimated(float opacity) { | 752 void LayerImpl::OnOpacityAnimated(float opacity) { |
| 756 SetOpacity(opacity); | 753 SetOpacity(opacity); |
| 757 // When hide_layer_and_subtree is true, the effective opacity is zero and we | 754 UpdatePropertyTreeOpacity(); |
| 758 // need not update the opacity on property trees. | 755 SetNeedsPushProperties(); |
| 759 if (!hide_layer_and_subtree_) { | 756 layer_tree_impl()->set_needs_update_draw_properties(); |
| 760 UpdatePropertyTreeOpacity(); | |
| 761 SetNeedsPushProperties(); | |
| 762 layer_tree_impl()->set_needs_update_draw_properties(); | |
| 763 } | |
| 764 } | 757 } |
| 765 | 758 |
| 766 void LayerImpl::OnTransformAnimated(const gfx::Transform& transform) { | 759 void LayerImpl::OnTransformAnimated(const gfx::Transform& transform) { |
| 767 gfx::Transform old_transform = transform_; | 760 gfx::Transform old_transform = transform_; |
| 768 SetTransform(transform); | 761 SetTransform(transform); |
| 769 UpdatePropertyTreeTransform(); | 762 UpdatePropertyTreeTransform(); |
| 770 was_ever_ready_since_last_transform_animation_ = false; | 763 was_ever_ready_since_last_transform_animation_ = false; |
| 771 if (old_transform != transform) { | 764 if (old_transform != transform) { |
| 772 SetNeedsPushProperties(); | 765 SetNeedsPushProperties(); |
| 773 layer_tree_impl()->set_needs_update_draw_properties(); | 766 layer_tree_impl()->set_needs_update_draw_properties(); |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 911 } | 904 } |
| 912 | 905 |
| 913 void LayerImpl::SetDrawsContent(bool draws_content) { | 906 void LayerImpl::SetDrawsContent(bool draws_content) { |
| 914 if (draws_content_ == draws_content) | 907 if (draws_content_ == draws_content) |
| 915 return; | 908 return; |
| 916 | 909 |
| 917 draws_content_ = draws_content; | 910 draws_content_ = draws_content; |
| 918 NoteLayerPropertyChanged(); | 911 NoteLayerPropertyChanged(); |
| 919 } | 912 } |
| 920 | 913 |
| 921 void LayerImpl::SetHideLayerAndSubtree(bool hide) { | |
| 922 if (hide_layer_and_subtree_ == hide) | |
| 923 return; | |
| 924 | |
| 925 hide_layer_and_subtree_ = hide; | |
| 926 } | |
| 927 | |
| 928 void LayerImpl::SetBackgroundColor(SkColor background_color) { | 914 void LayerImpl::SetBackgroundColor(SkColor background_color) { |
| 929 if (background_color_ == background_color) | 915 if (background_color_ == background_color) |
| 930 return; | 916 return; |
| 931 | 917 |
| 932 background_color_ = background_color; | 918 background_color_ = background_color; |
| 933 NoteLayerPropertyChanged(); | 919 NoteLayerPropertyChanged(); |
| 934 } | 920 } |
| 935 | 921 |
| 936 void LayerImpl::SetSafeOpaqueBackgroundColor(SkColor background_color) { | 922 void LayerImpl::SetSafeOpaqueBackgroundColor(SkColor background_color) { |
| 937 if (background_color == safe_opaque_background_color_) | 923 if (background_color == safe_opaque_background_color_) |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 992 contents_opaque_ = opaque; | 978 contents_opaque_ = opaque; |
| 993 } | 979 } |
| 994 | 980 |
| 995 void LayerImpl::SetOpacity(float opacity) { | 981 void LayerImpl::SetOpacity(float opacity) { |
| 996 if (opacity_ == opacity) | 982 if (opacity_ == opacity) |
| 997 return; | 983 return; |
| 998 | 984 |
| 999 opacity_ = opacity; | 985 opacity_ = opacity; |
| 1000 } | 986 } |
| 1001 | 987 |
| 1002 float LayerImpl::EffectiveOpacity() const { | |
| 1003 return hide_layer_and_subtree_ ? 0.f : opacity_; | |
| 1004 } | |
| 1005 | |
| 1006 bool LayerImpl::OpacityIsAnimating() const { | 988 bool LayerImpl::OpacityIsAnimating() const { |
| 1007 return layer_tree_impl_->IsAnimatingOpacityProperty(this); | 989 return layer_tree_impl_->IsAnimatingOpacityProperty(this); |
| 1008 } | 990 } |
| 1009 | 991 |
| 1010 bool LayerImpl::HasPotentiallyRunningOpacityAnimation() const { | 992 bool LayerImpl::HasPotentiallyRunningOpacityAnimation() const { |
| 1011 return layer_tree_impl_->HasPotentiallyRunningOpacityAnimation(this); | 993 return layer_tree_impl_->HasPotentiallyRunningOpacityAnimation(this); |
| 1012 } | 994 } |
| 1013 | 995 |
| 1014 bool LayerImpl::OpacityIsAnimatingOnImplOnly() const { | 996 bool LayerImpl::OpacityIsAnimatingOnImplOnly() const { |
| 1015 return layer_tree_impl_->OpacityIsAnimatingOnImplOnly(this); | 997 return layer_tree_impl_->OpacityIsAnimatingOnImplOnly(this); |
| (...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1410 .layer_transforms_should_scale_layer_contents) { | 1392 .layer_transforms_should_scale_layer_contents) { |
| 1411 return default_scale; | 1393 return default_scale; |
| 1412 } | 1394 } |
| 1413 | 1395 |
| 1414 gfx::Vector2dF transform_scales = MathUtil::ComputeTransform2dScaleComponents( | 1396 gfx::Vector2dF transform_scales = MathUtil::ComputeTransform2dScaleComponents( |
| 1415 DrawTransform(), default_scale); | 1397 DrawTransform(), default_scale); |
| 1416 return std::max(transform_scales.x(), transform_scales.y()); | 1398 return std::max(transform_scales.x(), transform_scales.y()); |
| 1417 } | 1399 } |
| 1418 | 1400 |
| 1419 } // namespace cc | 1401 } // namespace cc |
| OLD | NEW |