| OLD | NEW |
| 1 // Copyright 2010 The Chromium Authors. All rights reserved. | 1 // Copyright 2010 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.h" | 5 #include "cc/layers/layer.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/debug/trace_event.h" | 9 #include "base/debug/trace_event.h" |
| 10 #include "base/location.h" | 10 #include "base/location.h" |
| 11 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
| 12 #include "base/single_thread_task_runner.h" | 12 #include "base/single_thread_task_runner.h" |
| 13 #include "cc/animation/animation.h" | 13 #include "cc/animation/animation.h" |
| 14 #include "cc/animation/animation_events.h" | 14 #include "cc/animation/animation_events.h" |
| 15 #include "cc/animation/keyframed_animation_curve.h" | 15 #include "cc/animation/keyframed_animation_curve.h" |
| 16 #include "cc/animation/layer_animation_controller.h" | 16 #include "cc/animation/layer_animation_controller.h" |
| 17 #include "cc/layers/layer_client.h" | 17 #include "cc/layers/layer_client.h" |
| 18 #include "cc/layers/layer_impl.h" | 18 #include "cc/layers/layer_impl.h" |
| 19 #include "cc/layers/scrollbar_layer_interface.h" |
| 19 #include "cc/output/copy_output_request.h" | 20 #include "cc/output/copy_output_request.h" |
| 20 #include "cc/output/copy_output_result.h" | 21 #include "cc/output/copy_output_result.h" |
| 21 #include "cc/trees/layer_tree_host.h" | 22 #include "cc/trees/layer_tree_host.h" |
| 22 #include "cc/trees/layer_tree_impl.h" | 23 #include "cc/trees/layer_tree_impl.h" |
| 23 #include "third_party/skia/include/core/SkImageFilter.h" | 24 #include "third_party/skia/include/core/SkImageFilter.h" |
| 25 #include "ui/gfx/geometry/vector2d_conversions.h" |
| 24 #include "ui/gfx/rect_conversions.h" | 26 #include "ui/gfx/rect_conversions.h" |
| 25 | 27 |
| 26 namespace cc { | 28 namespace cc { |
| 27 | 29 |
| 28 static int s_next_layer_id = 1; | 30 static int s_next_layer_id = 1; |
| 29 | 31 |
| 30 scoped_refptr<Layer> Layer::Create() { | 32 scoped_refptr<Layer> Layer::Create() { |
| 31 return make_scoped_refptr(new Layer()); | 33 return make_scoped_refptr(new Layer()); |
| 32 } | 34 } |
| 33 | 35 |
| 34 Layer::Layer() | 36 Layer::Layer() |
| 35 : needs_push_properties_(false), | 37 : needs_push_properties_(false), |
| 36 num_dependents_need_push_properties_(false), | 38 num_dependents_need_push_properties_(false), |
| 37 stacking_order_changed_(false), | 39 stacking_order_changed_(false), |
| 38 layer_id_(s_next_layer_id++), | 40 layer_id_(s_next_layer_id++), |
| 39 ignore_set_needs_commit_(false), | 41 ignore_set_needs_commit_(false), |
| 40 parent_(NULL), | 42 parent_(NULL), |
| 41 layer_tree_host_(NULL), | 43 layer_tree_host_(NULL), |
| 42 scrollable_(false), | 44 scroll_clip_layer_id_(INVALID_ID), |
| 43 should_scroll_on_main_thread_(false), | 45 should_scroll_on_main_thread_(false), |
| 44 have_wheel_event_handlers_(false), | 46 have_wheel_event_handlers_(false), |
| 45 user_scrollable_horizontal_(true), | 47 user_scrollable_horizontal_(true), |
| 46 user_scrollable_vertical_(true), | 48 user_scrollable_vertical_(true), |
| 47 is_root_for_isolated_group_(false), | 49 is_root_for_isolated_group_(false), |
| 48 is_container_for_fixed_position_layers_(false), | 50 is_container_for_fixed_position_layers_(false), |
| 49 is_drawable_(false), | 51 is_drawable_(false), |
| 50 hide_layer_and_subtree_(false), | 52 hide_layer_and_subtree_(false), |
| 51 masks_to_bounds_(false), | 53 masks_to_bounds_(false), |
| 52 contents_opaque_(false), | 54 contents_opaque_(false), |
| (...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 | 674 |
| 673 void Layer::RemoveClipChild(Layer* child) { | 675 void Layer::RemoveClipChild(Layer* child) { |
| 674 clip_children_->erase(child); | 676 clip_children_->erase(child); |
| 675 if (clip_children_->empty()) | 677 if (clip_children_->empty()) |
| 676 clip_children_.reset(); | 678 clip_children_.reset(); |
| 677 SetNeedsCommit(); | 679 SetNeedsCommit(); |
| 678 } | 680 } |
| 679 | 681 |
| 680 void Layer::SetScrollOffset(gfx::Vector2d scroll_offset) { | 682 void Layer::SetScrollOffset(gfx::Vector2d scroll_offset) { |
| 681 DCHECK(IsPropertyChangeAllowed()); | 683 DCHECK(IsPropertyChangeAllowed()); |
| 684 |
| 685 if (layer_tree_host()) { |
| 686 scroll_offset = layer_tree_host()->DistributeScrollOffsetToViewports( |
| 687 scroll_offset, this); |
| 688 } |
| 689 |
| 682 if (scroll_offset_ == scroll_offset) | 690 if (scroll_offset_ == scroll_offset) |
| 683 return; | 691 return; |
| 684 scroll_offset_ = scroll_offset; | 692 scroll_offset_ = scroll_offset; |
| 685 SetNeedsCommit(); | 693 SetNeedsCommit(); |
| 686 } | 694 } |
| 687 | 695 |
| 688 void Layer::SetScrollOffsetFromImplSide(gfx::Vector2d scroll_offset) { | 696 void Layer::SetScrollOffsetFromImplSide(gfx::Vector2d scroll_offset) { |
| 689 DCHECK(IsPropertyChangeAllowed()); | 697 DCHECK(IsPropertyChangeAllowed()); |
| 690 // This function only gets called during a BeginMainFrame, so there | 698 // This function only gets called during a BeginMainFrame, so there |
| 691 // is no need to call SetNeedsUpdate here. | 699 // is no need to call SetNeedsUpdate here. |
| 692 DCHECK(layer_tree_host_ && layer_tree_host_->CommitRequested()); | 700 DCHECK(layer_tree_host_ && layer_tree_host_->CommitRequested()); |
| 693 if (scroll_offset_ == scroll_offset) | 701 if (scroll_offset_ == scroll_offset) |
| 694 return; | 702 return; |
| 695 scroll_offset_ = scroll_offset; | 703 scroll_offset_ = scroll_offset; |
| 696 SetNeedsPushProperties(); | 704 SetNeedsPushProperties(); |
| 697 if (!did_scroll_callback_.is_null()) | 705 if (!did_scroll_callback_.is_null()) |
| 698 did_scroll_callback_.Run(); | 706 did_scroll_callback_.Run(); |
| 699 // The callback could potentially change the layer structure: | 707 // The callback could potentially change the layer structure: |
| 700 // "this" may have been destroyed during the process. | 708 // "this" may have been destroyed during the process. |
| 701 } | 709 } |
| 702 | 710 |
| 703 void Layer::SetMaxScrollOffset(gfx::Vector2d max_scroll_offset) { | 711 // TODO(wjmaclean) We should template this and put it into LayerTreeHostCommon |
| 712 // so that both Layer and LayerImpl are using the same code. In order |
| 713 // to template it we should avoid calling layer_tree_host() by giving |
| 714 // Layer/LayerImpl local accessors for page_scale_layer() and |
| 715 // page_scale_factor(). |
| 716 gfx::Vector2d Layer::MaxScrollOffset() const { |
| 717 if (scroll_clip_layer_id_ == INVALID_ID) |
| 718 return gfx::Vector2d(); |
| 719 |
| 720 gfx::Size scaled_scroll_bounds(bounds()); |
| 721 Layer const* current_layer = this; |
| 722 Layer const* page_scale_layer = layer_tree_host()->page_scale_layer(); |
| 723 float scale_factor = 1.f; |
| 724 do { |
| 725 if (current_layer == page_scale_layer) { |
| 726 scale_factor = layer_tree_host()->page_scale_factor(); |
| 727 scaled_scroll_bounds.SetSize( |
| 728 scale_factor * scaled_scroll_bounds.width(), |
| 729 scale_factor * scaled_scroll_bounds.height()); |
| 730 } |
| 731 current_layer = current_layer->parent(); |
| 732 } while (current_layer && current_layer->id() != scroll_clip_layer_id_); |
| 733 DCHECK(current_layer); |
| 734 DCHECK(current_layer->id() == scroll_clip_layer_id_); |
| 735 |
| 736 gfx::Vector2dF max_offset( |
| 737 scaled_scroll_bounds.width() - current_layer->bounds().width(), |
| 738 scaled_scroll_bounds.height() - current_layer->bounds().height()); |
| 739 // We need the final scroll offset to be in CSS coords. |
| 740 max_offset.Scale(1.f / scale_factor); |
| 741 max_offset.SetToMax(gfx::Vector2dF()); |
| 742 return gfx::ToFlooredVector2d(max_offset); |
| 743 } |
| 744 |
| 745 void Layer::SetScrollClipLayerId(int clip_layer_id) { |
| 704 DCHECK(IsPropertyChangeAllowed()); | 746 DCHECK(IsPropertyChangeAllowed()); |
| 705 if (max_scroll_offset_ == max_scroll_offset) | 747 if (scroll_clip_layer_id_ == clip_layer_id) |
| 706 return; | 748 return; |
| 707 max_scroll_offset_ = max_scroll_offset; | 749 scroll_clip_layer_id_ = clip_layer_id; |
| 708 SetNeedsCommit(); | 750 SetNeedsCommit(); |
| 709 } | 751 } |
| 710 | 752 |
| 711 void Layer::SetScrollable(bool scrollable) { | |
| 712 DCHECK(IsPropertyChangeAllowed()); | |
| 713 if (scrollable_ == scrollable) | |
| 714 return; | |
| 715 scrollable_ = scrollable; | |
| 716 SetNeedsCommit(); | |
| 717 } | |
| 718 | |
| 719 void Layer::SetUserScrollable(bool horizontal, bool vertical) { | 753 void Layer::SetUserScrollable(bool horizontal, bool vertical) { |
| 720 DCHECK(IsPropertyChangeAllowed()); | 754 DCHECK(IsPropertyChangeAllowed()); |
| 721 if (user_scrollable_horizontal_ == horizontal && | 755 if (user_scrollable_horizontal_ == horizontal && |
| 722 user_scrollable_vertical_ == vertical) | 756 user_scrollable_vertical_ == vertical) |
| 723 return; | 757 return; |
| 724 user_scrollable_horizontal_ = horizontal; | 758 user_scrollable_horizontal_ = horizontal; |
| 725 user_scrollable_vertical_ = vertical; | 759 user_scrollable_vertical_ = vertical; |
| 726 SetNeedsCommit(); | 760 SetNeedsCommit(); |
| 727 } | 761 } |
| 728 | 762 |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 904 IsContainerForFixedPositionLayers()); | 938 IsContainerForFixedPositionLayers()); |
| 905 layer->SetFixedContainerSizeDelta(gfx::Vector2dF()); | 939 layer->SetFixedContainerSizeDelta(gfx::Vector2dF()); |
| 906 layer->SetPositionConstraint(position_constraint_); | 940 layer->SetPositionConstraint(position_constraint_); |
| 907 layer->SetPreserves3d(preserves_3d()); | 941 layer->SetPreserves3d(preserves_3d()); |
| 908 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_); | 942 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_); |
| 909 layer->SetSublayerTransform(sublayer_transform_); | 943 layer->SetSublayerTransform(sublayer_transform_); |
| 910 if (!layer->TransformIsAnimatingOnImplOnly() && !TransformIsAnimating()) | 944 if (!layer->TransformIsAnimatingOnImplOnly() && !TransformIsAnimating()) |
| 911 layer->SetTransform(transform_); | 945 layer->SetTransform(transform_); |
| 912 DCHECK(!(TransformIsAnimating() && layer->TransformIsAnimatingOnImplOnly())); | 946 DCHECK(!(TransformIsAnimating() && layer->TransformIsAnimatingOnImplOnly())); |
| 913 | 947 |
| 914 layer->SetScrollable(scrollable_); | 948 layer->SetScrollClipLayer(scroll_clip_layer_id_); |
| 915 layer->set_user_scrollable_horizontal(user_scrollable_horizontal_); | 949 layer->set_user_scrollable_horizontal(user_scrollable_horizontal_); |
| 916 layer->set_user_scrollable_vertical(user_scrollable_vertical_); | 950 layer->set_user_scrollable_vertical(user_scrollable_vertical_); |
| 917 layer->SetMaxScrollOffset(max_scroll_offset_); | |
| 918 | 951 |
| 919 LayerImpl* scroll_parent = NULL; | 952 LayerImpl* scroll_parent = NULL; |
| 920 if (scroll_parent_) | 953 if (scroll_parent_) |
| 921 scroll_parent = layer->layer_tree_impl()->LayerById(scroll_parent_->id()); | 954 scroll_parent = layer->layer_tree_impl()->LayerById(scroll_parent_->id()); |
| 922 | 955 |
| 923 layer->SetScrollParent(scroll_parent); | 956 layer->SetScrollParent(scroll_parent); |
| 924 if (scroll_children_) { | 957 if (scroll_children_) { |
| 925 std::set<LayerImpl*>* scroll_children = new std::set<LayerImpl*>; | 958 std::set<LayerImpl*>* scroll_children = new std::set<LayerImpl*>; |
| 926 for (std::set<Layer*>::iterator it = scroll_children_->begin(); | 959 for (std::set<Layer*>::iterator it = scroll_children_->begin(); |
| 927 it != scroll_children_->end(); ++it) | 960 it != scroll_children_->end(); ++it) |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1166 clip_parent_->RemoveClipChild(this); | 1199 clip_parent_->RemoveClipChild(this); |
| 1167 | 1200 |
| 1168 clip_parent_ = NULL; | 1201 clip_parent_ = NULL; |
| 1169 } | 1202 } |
| 1170 | 1203 |
| 1171 void Layer::RunMicroBenchmark(MicroBenchmark* benchmark) { | 1204 void Layer::RunMicroBenchmark(MicroBenchmark* benchmark) { |
| 1172 benchmark->RunOnLayer(this); | 1205 benchmark->RunOnLayer(this); |
| 1173 } | 1206 } |
| 1174 | 1207 |
| 1175 } // namespace cc | 1208 } // namespace cc |
| OLD | NEW |