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 const Layer* scroll_clip_layer = | |
718 layer_tree_host()->LayerById(scroll_clip_layer_id_); | |
enne (OOO)
2014/01/29 21:25:30
Inside of MaxScrollOffset seems like an unfortunat
| |
719 if (!scroll_clip_layer) | |
720 return gfx::Vector2d(); | |
721 | |
722 gfx::Size scaled_scroll_bounds(bounds()); | |
723 Layer const* current_layer = this; | |
724 Layer const* page_scale_layer = layer_tree_host()->page_scale_layer(); | |
725 float scale_factor = 1.f; | |
726 do { | |
727 if (current_layer == page_scale_layer) { | |
728 scale_factor = layer_tree_host()->page_scale_factor(); | |
729 scaled_scroll_bounds.SetSize( | |
730 scale_factor * scaled_scroll_bounds.width(), | |
731 scale_factor * scaled_scroll_bounds.height()); | |
732 } | |
733 current_layer = current_layer->parent(); | |
734 } while (current_layer && current_layer != scroll_clip_layer); | |
735 DCHECK(current_layer == scroll_clip_layer); | |
736 | |
737 gfx::Vector2dF max_offset( | |
738 scaled_scroll_bounds.width() - scroll_clip_layer->bounds().width(), | |
739 scaled_scroll_bounds.height() - scroll_clip_layer->bounds().height()); | |
740 // We need the final scroll offset to be in CSS coords. | |
741 max_offset.Scale(1.f / scale_factor); | |
742 max_offset.SetToMax(gfx::Vector2dF()); | |
743 return gfx::ToFlooredVector2d(max_offset); | |
744 } | |
745 | |
746 void Layer::SetScrollClipLayerId(int clip_layer_id) { | |
704 DCHECK(IsPropertyChangeAllowed()); | 747 DCHECK(IsPropertyChangeAllowed()); |
705 if (max_scroll_offset_ == max_scroll_offset) | 748 if (scroll_clip_layer_id_ == clip_layer_id) |
706 return; | 749 return; |
707 max_scroll_offset_ = max_scroll_offset; | 750 scroll_clip_layer_id_ = clip_layer_id; |
708 SetNeedsCommit(); | 751 SetNeedsCommit(); |
709 } | 752 } |
710 | 753 |
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) { | 754 void Layer::SetUserScrollable(bool horizontal, bool vertical) { |
720 DCHECK(IsPropertyChangeAllowed()); | 755 DCHECK(IsPropertyChangeAllowed()); |
721 if (user_scrollable_horizontal_ == horizontal && | 756 if (user_scrollable_horizontal_ == horizontal && |
722 user_scrollable_vertical_ == vertical) | 757 user_scrollable_vertical_ == vertical) |
723 return; | 758 return; |
724 user_scrollable_horizontal_ = horizontal; | 759 user_scrollable_horizontal_ = horizontal; |
725 user_scrollable_vertical_ = vertical; | 760 user_scrollable_vertical_ = vertical; |
726 SetNeedsCommit(); | 761 SetNeedsCommit(); |
727 } | 762 } |
728 | 763 |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
904 IsContainerForFixedPositionLayers()); | 939 IsContainerForFixedPositionLayers()); |
905 layer->SetFixedContainerSizeDelta(gfx::Vector2dF()); | 940 layer->SetFixedContainerSizeDelta(gfx::Vector2dF()); |
906 layer->SetPositionConstraint(position_constraint_); | 941 layer->SetPositionConstraint(position_constraint_); |
907 layer->SetPreserves3d(preserves_3d()); | 942 layer->SetPreserves3d(preserves_3d()); |
908 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_); | 943 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_); |
909 layer->SetSublayerTransform(sublayer_transform_); | 944 layer->SetSublayerTransform(sublayer_transform_); |
910 if (!layer->TransformIsAnimatingOnImplOnly() && !TransformIsAnimating()) | 945 if (!layer->TransformIsAnimatingOnImplOnly() && !TransformIsAnimating()) |
911 layer->SetTransform(transform_); | 946 layer->SetTransform(transform_); |
912 DCHECK(!(TransformIsAnimating() && layer->TransformIsAnimatingOnImplOnly())); | 947 DCHECK(!(TransformIsAnimating() && layer->TransformIsAnimatingOnImplOnly())); |
913 | 948 |
914 layer->SetScrollable(scrollable_); | 949 layer->SetScrollClipLayer(scroll_clip_layer_id_); |
915 layer->set_user_scrollable_horizontal(user_scrollable_horizontal_); | 950 layer->set_user_scrollable_horizontal(user_scrollable_horizontal_); |
916 layer->set_user_scrollable_vertical(user_scrollable_vertical_); | 951 layer->set_user_scrollable_vertical(user_scrollable_vertical_); |
917 layer->SetMaxScrollOffset(max_scroll_offset_); | |
918 | 952 |
919 LayerImpl* scroll_parent = NULL; | 953 LayerImpl* scroll_parent = NULL; |
920 if (scroll_parent_) | 954 if (scroll_parent_) |
921 scroll_parent = layer->layer_tree_impl()->LayerById(scroll_parent_->id()); | 955 scroll_parent = layer->layer_tree_impl()->LayerById(scroll_parent_->id()); |
922 | 956 |
923 layer->SetScrollParent(scroll_parent); | 957 layer->SetScrollParent(scroll_parent); |
924 if (scroll_children_) { | 958 if (scroll_children_) { |
925 std::set<LayerImpl*>* scroll_children = new std::set<LayerImpl*>; | 959 std::set<LayerImpl*>* scroll_children = new std::set<LayerImpl*>; |
926 for (std::set<Layer*>::iterator it = scroll_children_->begin(); | 960 for (std::set<Layer*>::iterator it = scroll_children_->begin(); |
927 it != scroll_children_->end(); ++it) | 961 it != scroll_children_->end(); ++it) |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1166 clip_parent_->RemoveClipChild(this); | 1200 clip_parent_->RemoveClipChild(this); |
1167 | 1201 |
1168 clip_parent_ = NULL; | 1202 clip_parent_ = NULL; |
1169 } | 1203 } |
1170 | 1204 |
1171 void Layer::RunMicroBenchmark(MicroBenchmark* benchmark) { | 1205 void Layer::RunMicroBenchmark(MicroBenchmark* benchmark) { |
1172 benchmark->RunOnLayer(this); | 1206 benchmark->RunOnLayer(this); |
1173 } | 1207 } |
1174 | 1208 |
1175 } // namespace cc | 1209 } // namespace cc |
OLD | NEW |