Chromium Code Reviews| 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 |
|
enne (OOO)
2013/10/31 18:45:58
It seems a little weird for this to live on Layer.
wjmaclean
2013/11/13 21:01:29
True. I did this primarily so that WebLayerImpl wo
| |
| 635 void Layer::SetMaxScrollOffset(gfx::Vector2d max_scroll_offset) { | 643 gfx::Vector2d Layer::TotalViewportScrollOffset() const { |
| 644 gfx::Vector2d offset = | |
| 645 layer_tree_host()->inner_viewport_scroll_layer()->scroll_offset(); | |
| 646 if (layer_tree_host()->outer_viewport_scroll_layer()) | |
| 647 offset += layer_tree_host()->outer_viewport_scroll_layer()->scroll_offset(); | |
| 648 return offset; | |
| 649 } | |
| 650 | |
| 651 // TODO(wjmaclean) We should template this and put it into LayerTreeHostCommon | |
| 652 // so that both Layer and LayerImpl are using the same code. In order | |
| 653 // to template it we should avoind calling layer_tree_host() by giving | |
| 654 // Layer/LayerImpl local accessors for page_scale_layer() and | |
| 655 // page_scale_factor(). | |
| 656 gfx::Vector2d Layer::MaxScrollOffset() const { | |
| 657 if (!clip_layer_) | |
| 658 return gfx::Vector2d(); | |
| 659 | |
| 660 gfx::Size scaled_scroll_bounds(bounds()); | |
| 661 Layer const* current_layer = this; | |
| 662 Layer const* page_scale_layer = layer_tree_host()->page_scale_layer(); | |
| 663 float scale_factor = 1.f; | |
| 664 do { | |
| 665 if (current_layer == page_scale_layer) { | |
| 666 scale_factor = layer_tree_host()->page_scale_factor(); | |
| 667 scaled_scroll_bounds.SetSize( | |
| 668 scale_factor * scaled_scroll_bounds.width(), | |
| 669 scale_factor * scaled_scroll_bounds.height()); | |
| 670 } | |
| 671 current_layer = current_layer->parent(); | |
| 672 } while (current_layer && current_layer != clip_layer_); | |
| 673 DCHECK(current_layer == clip_layer_); | |
| 674 | |
| 675 gfx::Vector2dF max_offset( | |
| 676 scaled_scroll_bounds.width() - clip_layer_->bounds().width(), | |
| 677 scaled_scroll_bounds.height() - clip_layer_->bounds().height()); | |
| 678 // We need the final scroll offset to be in CSS coords. | |
| 679 max_offset.Scale(1 / scale_factor); | |
| 680 return gfx::Vector2d(max_offset.x(), max_offset.y()); | |
| 681 } | |
| 682 | |
| 683 void Layer::SetScrollable(Layer* clip_layer) { | |
| 636 DCHECK(IsPropertyChangeAllowed()); | 684 DCHECK(IsPropertyChangeAllowed()); |
| 637 if (max_scroll_offset_ == max_scroll_offset) | 685 if (clip_layer_ == clip_layer) |
| 638 return; | 686 return; |
| 639 max_scroll_offset_ = max_scroll_offset; | 687 clip_layer_ = clip_layer; |
| 640 SetNeedsCommit(); | 688 SetNeedsCommit(); |
| 641 } | 689 } |
| 642 | 690 |
| 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) { | 691 void Layer::SetUserScrollable(bool horizontal, bool vertical) { |
| 652 DCHECK(IsPropertyChangeAllowed()); | 692 DCHECK(IsPropertyChangeAllowed()); |
| 653 if (user_scrollable_horizontal_ == horizontal && | 693 if (user_scrollable_horizontal_ == horizontal && |
| 654 user_scrollable_vertical_ == vertical) | 694 user_scrollable_vertical_ == vertical) |
| 655 return; | 695 return; |
| 656 user_scrollable_horizontal_ = horizontal; | 696 user_scrollable_horizontal_ = horizontal; |
| 657 user_scrollable_vertical_ = vertical; | 697 user_scrollable_vertical_ = vertical; |
| 658 SetNeedsCommit(); | 698 SetNeedsCommit(); |
| 659 } | 699 } |
| 660 | 700 |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 837 IsContainerForFixedPositionLayers()); | 877 IsContainerForFixedPositionLayers()); |
| 838 layer->SetFixedContainerSizeDelta(gfx::Vector2dF()); | 878 layer->SetFixedContainerSizeDelta(gfx::Vector2dF()); |
| 839 layer->SetPositionConstraint(position_constraint_); | 879 layer->SetPositionConstraint(position_constraint_); |
| 840 layer->SetPreserves3d(preserves_3d()); | 880 layer->SetPreserves3d(preserves_3d()); |
| 841 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_); | 881 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_); |
| 842 layer->SetSublayerTransform(sublayer_transform_); | 882 layer->SetSublayerTransform(sublayer_transform_); |
| 843 if (!layer->TransformIsAnimatingOnImplOnly() && !TransformIsAnimating()) | 883 if (!layer->TransformIsAnimatingOnImplOnly() && !TransformIsAnimating()) |
| 844 layer->SetTransform(transform_); | 884 layer->SetTransform(transform_); |
| 845 DCHECK(!(TransformIsAnimating() && layer->TransformIsAnimatingOnImplOnly())); | 885 DCHECK(!(TransformIsAnimating() && layer->TransformIsAnimatingOnImplOnly())); |
| 846 | 886 |
| 847 layer->SetScrollable(scrollable_); | 887 layer->SetScrollable(clip_layer_ ? clip_layer_->id() : Layer::INVALID_ID); |
| 848 layer->set_user_scrollable_horizontal(user_scrollable_horizontal_); | 888 layer->set_user_scrollable_horizontal(user_scrollable_horizontal_); |
| 849 layer->set_user_scrollable_vertical(user_scrollable_vertical_); | 889 layer->set_user_scrollable_vertical(user_scrollable_vertical_); |
| 850 layer->SetMaxScrollOffset(max_scroll_offset_); | |
| 851 | 890 |
| 852 LayerImpl* scroll_parent = NULL; | 891 LayerImpl* scroll_parent = NULL; |
| 853 if (scroll_parent_) | 892 if (scroll_parent_) |
| 854 scroll_parent = layer->layer_tree_impl()->LayerById(scroll_parent_->id()); | 893 scroll_parent = layer->layer_tree_impl()->LayerById(scroll_parent_->id()); |
| 855 | 894 |
| 856 layer->SetScrollParent(scroll_parent); | 895 layer->SetScrollParent(scroll_parent); |
| 857 if (scroll_children_) { | 896 if (scroll_children_) { |
| 858 std::set<LayerImpl*>* scroll_children = new std::set<LayerImpl*>; | 897 std::set<LayerImpl*>* scroll_children = new std::set<LayerImpl*>; |
| 859 for (std::set<Layer*>::iterator it = scroll_children_->begin(); | 898 for (std::set<Layer*>::iterator it = scroll_children_->begin(); |
| 860 it != scroll_children_->end(); ++it) | 899 it != scroll_children_->end(); ++it) |
| (...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1093 clip_parent_->RemoveClipChild(this); | 1132 clip_parent_->RemoveClipChild(this); |
| 1094 | 1133 |
| 1095 clip_parent_ = NULL; | 1134 clip_parent_ = NULL; |
| 1096 } | 1135 } |
| 1097 | 1136 |
| 1098 void Layer::RunMicroBenchmark(MicroBenchmark* benchmark) { | 1137 void Layer::RunMicroBenchmark(MicroBenchmark* benchmark) { |
| 1099 benchmark->RunOnLayer(this); | 1138 benchmark->RunOnLayer(this); |
| 1100 } | 1139 } |
| 1101 | 1140 |
| 1102 } // namespace cc | 1141 } // namespace cc |
| OLD | NEW |