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/layer_animation_controller.h" | 15 #include "cc/animation/layer_animation_controller.h" |
16 #include "cc/layers/layer_client.h" | 16 #include "cc/layers/layer_client.h" |
17 #include "cc/layers/layer_impl.h" | 17 #include "cc/layers/layer_impl.h" |
18 #include "cc/layers/scrollbar_layer_interface.h" | |
18 #include "cc/output/copy_output_request.h" | 19 #include "cc/output/copy_output_request.h" |
19 #include "cc/output/copy_output_result.h" | 20 #include "cc/output/copy_output_result.h" |
20 #include "cc/trees/layer_tree_host.h" | 21 #include "cc/trees/layer_tree_host.h" |
21 #include "cc/trees/layer_tree_impl.h" | 22 #include "cc/trees/layer_tree_impl.h" |
22 #include "third_party/skia/include/core/SkImageFilter.h" | 23 #include "third_party/skia/include/core/SkImageFilter.h" |
23 #include "ui/gfx/rect_conversions.h" | 24 #include "ui/gfx/rect_conversions.h" |
24 | 25 |
25 namespace cc { | 26 namespace cc { |
26 | 27 |
27 static int s_next_layer_id = 1; | 28 static int s_next_layer_id = 1; |
28 | 29 |
29 scoped_refptr<Layer> Layer::Create() { | 30 scoped_refptr<Layer> Layer::Create() { |
30 return make_scoped_refptr(new Layer()); | 31 return make_scoped_refptr(new Layer()); |
31 } | 32 } |
32 | 33 |
33 Layer::Layer() | 34 Layer::Layer() |
34 : needs_push_properties_(false), | 35 : needs_push_properties_(false), |
35 num_dependents_need_push_properties_(false), | 36 num_dependents_need_push_properties_(false), |
36 stacking_order_changed_(false), | 37 stacking_order_changed_(false), |
37 layer_id_(s_next_layer_id++), | 38 layer_id_(s_next_layer_id++), |
38 ignore_set_needs_commit_(false), | 39 ignore_set_needs_commit_(false), |
39 parent_(NULL), | 40 parent_(NULL), |
40 layer_tree_host_(NULL), | 41 layer_tree_host_(NULL), |
41 scrollable_(false), | 42 clip_layer_(NULL), |
42 should_scroll_on_main_thread_(false), | 43 should_scroll_on_main_thread_(false), |
43 have_wheel_event_handlers_(false), | 44 have_wheel_event_handlers_(false), |
44 user_scrollable_horizontal_(true), | 45 user_scrollable_horizontal_(true), |
45 user_scrollable_vertical_(true), | 46 user_scrollable_vertical_(true), |
46 anchor_point_(0.5f, 0.5f), | 47 anchor_point_(0.5f, 0.5f), |
47 background_color_(0), | 48 background_color_(0), |
48 compositing_reasons_(kCompositingReasonUnknown), | 49 compositing_reasons_(kCompositingReasonUnknown), |
49 opacity_(1.f), | 50 opacity_(1.f), |
50 anchor_point_z_(0.f), | 51 anchor_point_z_(0.f), |
51 is_container_for_fixed_position_layers_(false), | 52 is_container_for_fixed_position_layers_(false), |
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
604 | 605 |
605 void Layer::RemoveClipChild(Layer* child) { | 606 void Layer::RemoveClipChild(Layer* child) { |
606 clip_children_->erase(child); | 607 clip_children_->erase(child); |
607 if (clip_children_->empty()) | 608 if (clip_children_->empty()) |
608 clip_children_.reset(); | 609 clip_children_.reset(); |
609 SetNeedsCommit(); | 610 SetNeedsCommit(); |
610 } | 611 } |
611 | 612 |
612 void Layer::SetScrollOffset(gfx::Vector2d scroll_offset) { | 613 void Layer::SetScrollOffset(gfx::Vector2d scroll_offset) { |
613 DCHECK(IsPropertyChangeAllowed()); | 614 DCHECK(IsPropertyChangeAllowed()); |
615 | |
616 if (layer_tree_host()) { | |
617 scroll_offset = layer_tree_host()->DistributeScrollOffsetToViewports( | |
618 scroll_offset, this); | |
619 } | |
620 | |
614 if (scroll_offset_ == scroll_offset) | 621 if (scroll_offset_ == scroll_offset) |
615 return; | 622 return; |
616 scroll_offset_ = scroll_offset; | 623 scroll_offset_ = scroll_offset; |
624 | |
617 SetNeedsCommit(); | 625 SetNeedsCommit(); |
618 } | 626 } |
619 | 627 |
620 void Layer::SetScrollOffsetFromImplSide(gfx::Vector2d scroll_offset) { | 628 void Layer::SetScrollOffsetFromImplSide(gfx::Vector2d scroll_offset) { |
621 DCHECK(IsPropertyChangeAllowed()); | 629 DCHECK(IsPropertyChangeAllowed()); |
622 // This function only gets called during a BeginMainFrame, so there | 630 // This function only gets called during a BeginMainFrame, so there |
623 // is no need to call SetNeedsUpdate here. | 631 // is no need to call SetNeedsUpdate here. |
624 DCHECK(layer_tree_host_ && layer_tree_host_->CommitRequested()); | 632 DCHECK(layer_tree_host_ && layer_tree_host_->CommitRequested()); |
625 if (scroll_offset_ == scroll_offset) | 633 if (scroll_offset_ == scroll_offset) |
626 return; | 634 return; |
627 scroll_offset_ = scroll_offset; | 635 scroll_offset_ = scroll_offset; |
628 SetNeedsPushProperties(); | 636 SetNeedsPushProperties(); |
629 if (!did_scroll_callback_.is_null()) | 637 if (!did_scroll_callback_.is_null()) |
630 did_scroll_callback_.Run(); | 638 did_scroll_callback_.Run(); |
631 // The callback could potentially change the layer structure: | 639 // The callback could potentially change the layer structure: |
632 // "this" may have been destroyed during the process. | 640 // "this" may have been destroyed during the process. |
633 } | 641 } |
634 | 642 |
635 void Layer::SetMaxScrollOffset(gfx::Vector2d max_scroll_offset) { | 643 gfx::Vector2d Layer::TotalViewportScrollOffset() const { |
enne (OOO)
2013/11/14 22:59:01
This seems like a LayerTreeHost function and not a
wjmaclean
2013/12/24 21:03:49
Done.
| |
644 if (!layer_tree_host() || | |
645 (this != layer_tree_host()->inner_viewport_scroll_layer() && | |
646 this != layer_tree_host()->outer_viewport_scroll_layer())) | |
647 return scroll_offset(); | |
648 | |
649 gfx::Vector2d offset = | |
650 layer_tree_host()->inner_viewport_scroll_layer()->scroll_offset(); | |
651 if (layer_tree_host()->outer_viewport_scroll_layer()) | |
652 offset += layer_tree_host()->outer_viewport_scroll_layer()->scroll_offset(); | |
653 return offset; | |
654 } | |
655 | |
656 // TODO(wjmaclean) We should template this and put it into LayerTreeHostCommon | |
657 // so that both Layer and LayerImpl are using the same code. In order | |
658 // to template it we should avoid calling layer_tree_host() by giving | |
659 // Layer/LayerImpl local accessors for page_scale_layer() and | |
660 // page_scale_factor(). | |
661 gfx::Vector2d Layer::MaxScrollOffset() const { | |
662 if (!clip_layer_) | |
663 return gfx::Vector2d(); | |
664 | |
665 gfx::Size scaled_scroll_bounds(bounds()); | |
666 Layer const* current_layer = this; | |
667 Layer const* page_scale_layer = layer_tree_host()->page_scale_layer(); | |
668 float scale_factor = 1.f; | |
669 do { | |
670 if (current_layer == page_scale_layer) { | |
671 scale_factor = layer_tree_host()->page_scale_factor(); | |
672 scaled_scroll_bounds.SetSize( | |
673 scale_factor * scaled_scroll_bounds.width(), | |
674 scale_factor * scaled_scroll_bounds.height()); | |
675 } | |
676 current_layer = current_layer->parent(); | |
677 } while (current_layer && current_layer != clip_layer_); | |
678 DCHECK(current_layer == clip_layer_); | |
679 | |
680 gfx::Vector2dF max_offset( | |
681 scaled_scroll_bounds.width() - clip_layer_->bounds().width(), | |
682 scaled_scroll_bounds.height() - clip_layer_->bounds().height()); | |
683 // We need the final scroll offset to be in CSS coords. | |
684 max_offset.Scale(1 / scale_factor); | |
685 return gfx::Vector2d(max_offset.x(), max_offset.y()); | |
686 } | |
687 | |
688 void Layer::SetScrollable(Layer* clip_layer) { | |
636 DCHECK(IsPropertyChangeAllowed()); | 689 DCHECK(IsPropertyChangeAllowed()); |
637 if (max_scroll_offset_ == max_scroll_offset) | 690 if (clip_layer_ == clip_layer) |
638 return; | 691 return; |
639 max_scroll_offset_ = max_scroll_offset; | 692 clip_layer_ = clip_layer; |
640 SetNeedsCommit(); | 693 SetNeedsCommit(); |
641 } | 694 } |
642 | 695 |
643 void Layer::SetScrollable(bool scrollable) { | |
644 DCHECK(IsPropertyChangeAllowed()); | |
645 if (scrollable_ == scrollable) | |
646 return; | |
647 scrollable_ = scrollable; | |
648 SetNeedsCommit(); | |
649 } | |
650 | |
651 void Layer::SetUserScrollable(bool horizontal, bool vertical) { | 696 void Layer::SetUserScrollable(bool horizontal, bool vertical) { |
652 DCHECK(IsPropertyChangeAllowed()); | 697 DCHECK(IsPropertyChangeAllowed()); |
653 if (user_scrollable_horizontal_ == horizontal && | 698 if (user_scrollable_horizontal_ == horizontal && |
654 user_scrollable_vertical_ == vertical) | 699 user_scrollable_vertical_ == vertical) |
655 return; | 700 return; |
656 user_scrollable_horizontal_ = horizontal; | 701 user_scrollable_horizontal_ = horizontal; |
657 user_scrollable_vertical_ = vertical; | 702 user_scrollable_vertical_ = vertical; |
658 SetNeedsCommit(); | 703 SetNeedsCommit(); |
659 } | 704 } |
660 | 705 |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
837 IsContainerForFixedPositionLayers()); | 882 IsContainerForFixedPositionLayers()); |
838 layer->SetFixedContainerSizeDelta(gfx::Vector2dF()); | 883 layer->SetFixedContainerSizeDelta(gfx::Vector2dF()); |
839 layer->SetPositionConstraint(position_constraint_); | 884 layer->SetPositionConstraint(position_constraint_); |
840 layer->SetPreserves3d(preserves_3d()); | 885 layer->SetPreserves3d(preserves_3d()); |
841 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_); | 886 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_); |
842 layer->SetSublayerTransform(sublayer_transform_); | 887 layer->SetSublayerTransform(sublayer_transform_); |
843 if (!layer->TransformIsAnimatingOnImplOnly() && !TransformIsAnimating()) | 888 if (!layer->TransformIsAnimatingOnImplOnly() && !TransformIsAnimating()) |
844 layer->SetTransform(transform_); | 889 layer->SetTransform(transform_); |
845 DCHECK(!(TransformIsAnimating() && layer->TransformIsAnimatingOnImplOnly())); | 890 DCHECK(!(TransformIsAnimating() && layer->TransformIsAnimatingOnImplOnly())); |
846 | 891 |
847 layer->SetScrollable(scrollable_); | 892 layer->SetScrollable(clip_layer_ ? clip_layer_->id() : Layer::INVALID_ID); |
848 layer->set_user_scrollable_horizontal(user_scrollable_horizontal_); | 893 layer->set_user_scrollable_horizontal(user_scrollable_horizontal_); |
849 layer->set_user_scrollable_vertical(user_scrollable_vertical_); | 894 layer->set_user_scrollable_vertical(user_scrollable_vertical_); |
850 layer->SetMaxScrollOffset(max_scroll_offset_); | |
851 | 895 |
852 LayerImpl* scroll_parent = NULL; | 896 LayerImpl* scroll_parent = NULL; |
853 if (scroll_parent_) | 897 if (scroll_parent_) |
854 scroll_parent = layer->layer_tree_impl()->LayerById(scroll_parent_->id()); | 898 scroll_parent = layer->layer_tree_impl()->LayerById(scroll_parent_->id()); |
855 | 899 |
856 layer->SetScrollParent(scroll_parent); | 900 layer->SetScrollParent(scroll_parent); |
857 if (scroll_children_) { | 901 if (scroll_children_) { |
858 std::set<LayerImpl*>* scroll_children = new std::set<LayerImpl*>; | 902 std::set<LayerImpl*>* scroll_children = new std::set<LayerImpl*>; |
859 for (std::set<Layer*>::iterator it = scroll_children_->begin(); | 903 for (std::set<Layer*>::iterator it = scroll_children_->begin(); |
860 it != scroll_children_->end(); ++it) | 904 it != scroll_children_->end(); ++it) |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1088 clip_parent_->RemoveClipChild(this); | 1132 clip_parent_->RemoveClipChild(this); |
1089 | 1133 |
1090 clip_parent_ = NULL; | 1134 clip_parent_ = NULL; |
1091 } | 1135 } |
1092 | 1136 |
1093 void Layer::RunMicroBenchmark(MicroBenchmark* benchmark) { | 1137 void Layer::RunMicroBenchmark(MicroBenchmark* benchmark) { |
1094 benchmark->RunOnLayer(this); | 1138 benchmark->RunOnLayer(this); |
1095 } | 1139 } |
1096 | 1140 |
1097 } // namespace cc | 1141 } // namespace cc |
OLD | NEW |