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" |
24 #include "ui/gfx/rect_conversions.h" | 25 #include "ui/gfx/rect_conversions.h" |
25 | 26 |
26 namespace cc { | 27 namespace cc { |
27 | 28 |
28 static int s_next_layer_id = 1; | 29 static int s_next_layer_id = 1; |
29 | 30 |
30 scoped_refptr<Layer> Layer::Create() { | 31 scoped_refptr<Layer> Layer::Create() { |
31 return make_scoped_refptr(new Layer()); | 32 return make_scoped_refptr(new Layer()); |
32 } | 33 } |
33 | 34 |
34 Layer::Layer() | 35 Layer::Layer() |
35 : needs_push_properties_(false), | 36 : needs_push_properties_(false), |
36 num_dependents_need_push_properties_(false), | 37 num_dependents_need_push_properties_(false), |
37 stacking_order_changed_(false), | 38 stacking_order_changed_(false), |
38 layer_id_(s_next_layer_id++), | 39 layer_id_(s_next_layer_id++), |
39 ignore_set_needs_commit_(false), | 40 ignore_set_needs_commit_(false), |
40 parent_(NULL), | 41 parent_(NULL), |
41 layer_tree_host_(NULL), | 42 layer_tree_host_(NULL), |
42 scrollable_(false), | 43 scroll_clip_layer_(NULL), |
43 should_scroll_on_main_thread_(false), | 44 should_scroll_on_main_thread_(false), |
44 have_wheel_event_handlers_(false), | 45 have_wheel_event_handlers_(false), |
45 user_scrollable_horizontal_(true), | 46 user_scrollable_horizontal_(true), |
46 user_scrollable_vertical_(true), | 47 user_scrollable_vertical_(true), |
47 is_root_for_isolated_group_(false), | 48 is_root_for_isolated_group_(false), |
48 is_container_for_fixed_position_layers_(false), | 49 is_container_for_fixed_position_layers_(false), |
49 is_drawable_(false), | 50 is_drawable_(false), |
50 hide_layer_and_subtree_(false), | 51 hide_layer_and_subtree_(false), |
51 masks_to_bounds_(false), | 52 masks_to_bounds_(false), |
52 contents_opaque_(false), | 53 contents_opaque_(false), |
(...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
672 | 673 |
673 void Layer::RemoveClipChild(Layer* child) { | 674 void Layer::RemoveClipChild(Layer* child) { |
674 clip_children_->erase(child); | 675 clip_children_->erase(child); |
675 if (clip_children_->empty()) | 676 if (clip_children_->empty()) |
676 clip_children_.reset(); | 677 clip_children_.reset(); |
677 SetNeedsCommit(); | 678 SetNeedsCommit(); |
678 } | 679 } |
679 | 680 |
680 void Layer::SetScrollOffset(gfx::Vector2d scroll_offset) { | 681 void Layer::SetScrollOffset(gfx::Vector2d scroll_offset) { |
681 DCHECK(IsPropertyChangeAllowed()); | 682 DCHECK(IsPropertyChangeAllowed()); |
683 | |
684 if (layer_tree_host()) { | |
685 scroll_offset = layer_tree_host()->DistributeScrollOffsetToViewports( | |
aelias_OOO_until_Jul13
2014/01/16 03:44:04
Instead of doing this, I think we should make Blin
wjmaclean
2014/01/16 15:07:32
Hmm, but the design doc specifies (and I have alwa
enne (OOO)
2014/01/16 19:35:53
I disagree. I don't think Javascript is ever goin
aelias_OOO_until_Jul13
2014/01/16 19:49:26
For the purpose of this comment I am including Web
| |
686 scroll_offset, this); | |
687 } | |
688 | |
682 if (scroll_offset_ == scroll_offset) | 689 if (scroll_offset_ == scroll_offset) |
683 return; | 690 return; |
684 scroll_offset_ = scroll_offset; | 691 scroll_offset_ = scroll_offset; |
692 | |
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 |
aelias_OOO_until_Jul13
2014/01/16 03:44:04
I don't believe main-thread Layers need to know ab
wjmaclean
2014/01/16 15:07:32
Main thread layers need to know in order to deal w
| |
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_) | |
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 != scroll_clip_layer_); | |
733 DCHECK(current_layer == scroll_clip_layer_); | |
734 | |
735 gfx::Vector2dF max_offset( | |
736 scaled_scroll_bounds.width() - scroll_clip_layer_->bounds().width(), | |
737 scaled_scroll_bounds.height() - scroll_clip_layer_->bounds().height()); | |
738 // We need the final scroll offset to be in CSS coords. | |
739 max_offset.Scale(1 / scale_factor); | |
740 return gfx::Vector2d(max_offset.x(), max_offset.y()); | |
741 } | |
742 | |
743 void Layer::SetScrollClipLayer(Layer* clip_layer) { | |
704 DCHECK(IsPropertyChangeAllowed()); | 744 DCHECK(IsPropertyChangeAllowed()); |
705 if (max_scroll_offset_ == max_scroll_offset) | 745 if (scroll_clip_layer_ == clip_layer) |
706 return; | 746 return; |
707 max_scroll_offset_ = max_scroll_offset; | 747 scroll_clip_layer_ = clip_layer; |
708 SetNeedsCommit(); | 748 SetNeedsCommit(); |
709 } | 749 } |
710 | 750 |
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) { | 751 void Layer::SetUserScrollable(bool horizontal, bool vertical) { |
720 DCHECK(IsPropertyChangeAllowed()); | 752 DCHECK(IsPropertyChangeAllowed()); |
721 if (user_scrollable_horizontal_ == horizontal && | 753 if (user_scrollable_horizontal_ == horizontal && |
722 user_scrollable_vertical_ == vertical) | 754 user_scrollable_vertical_ == vertical) |
723 return; | 755 return; |
724 user_scrollable_horizontal_ = horizontal; | 756 user_scrollable_horizontal_ = horizontal; |
725 user_scrollable_vertical_ = vertical; | 757 user_scrollable_vertical_ = vertical; |
726 SetNeedsCommit(); | 758 SetNeedsCommit(); |
727 } | 759 } |
728 | 760 |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
908 IsContainerForFixedPositionLayers()); | 940 IsContainerForFixedPositionLayers()); |
909 layer->SetFixedContainerSizeDelta(gfx::Vector2dF()); | 941 layer->SetFixedContainerSizeDelta(gfx::Vector2dF()); |
910 layer->SetPositionConstraint(position_constraint_); | 942 layer->SetPositionConstraint(position_constraint_); |
911 layer->SetPreserves3d(preserves_3d()); | 943 layer->SetPreserves3d(preserves_3d()); |
912 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_); | 944 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_); |
913 layer->SetSublayerTransform(sublayer_transform_); | 945 layer->SetSublayerTransform(sublayer_transform_); |
914 if (!layer->TransformIsAnimatingOnImplOnly() && !TransformIsAnimating()) | 946 if (!layer->TransformIsAnimatingOnImplOnly() && !TransformIsAnimating()) |
915 layer->SetTransform(transform_); | 947 layer->SetTransform(transform_); |
916 DCHECK(!(TransformIsAnimating() && layer->TransformIsAnimatingOnImplOnly())); | 948 DCHECK(!(TransformIsAnimating() && layer->TransformIsAnimatingOnImplOnly())); |
917 | 949 |
918 layer->SetScrollable(scrollable_); | 950 layer->SetScrollClipLayer(scroll_clip_layer_ ? scroll_clip_layer_->id() |
951 : Layer::INVALID_ID); | |
919 layer->set_user_scrollable_horizontal(user_scrollable_horizontal_); | 952 layer->set_user_scrollable_horizontal(user_scrollable_horizontal_); |
920 layer->set_user_scrollable_vertical(user_scrollable_vertical_); | 953 layer->set_user_scrollable_vertical(user_scrollable_vertical_); |
921 layer->SetMaxScrollOffset(max_scroll_offset_); | |
922 | 954 |
923 LayerImpl* scroll_parent = NULL; | 955 LayerImpl* scroll_parent = NULL; |
924 if (scroll_parent_) | 956 if (scroll_parent_) |
925 scroll_parent = layer->layer_tree_impl()->LayerById(scroll_parent_->id()); | 957 scroll_parent = layer->layer_tree_impl()->LayerById(scroll_parent_->id()); |
926 | 958 |
927 layer->SetScrollParent(scroll_parent); | 959 layer->SetScrollParent(scroll_parent); |
928 if (scroll_children_) { | 960 if (scroll_children_) { |
929 std::set<LayerImpl*>* scroll_children = new std::set<LayerImpl*>; | 961 std::set<LayerImpl*>* scroll_children = new std::set<LayerImpl*>; |
930 for (std::set<Layer*>::iterator it = scroll_children_->begin(); | 962 for (std::set<Layer*>::iterator it = scroll_children_->begin(); |
931 it != scroll_children_->end(); ++it) | 963 it != scroll_children_->end(); ++it) |
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1174 clip_parent_->RemoveClipChild(this); | 1206 clip_parent_->RemoveClipChild(this); |
1175 | 1207 |
1176 clip_parent_ = NULL; | 1208 clip_parent_ = NULL; |
1177 } | 1209 } |
1178 | 1210 |
1179 void Layer::RunMicroBenchmark(MicroBenchmark* benchmark) { | 1211 void Layer::RunMicroBenchmark(MicroBenchmark* benchmark) { |
1180 benchmark->RunOnLayer(this); | 1212 benchmark->RunOnLayer(this); |
1181 } | 1213 } |
1182 | 1214 |
1183 } // namespace cc | 1215 } // namespace cc |
OLD | NEW |