Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: cc/layers/layer.cc

Issue 146713002: Revert of Pinch/Zoom Infrastructure & Plumbing CL (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « cc/layers/layer.h ('k') | cc/layers/layer_impl.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
20 #include "cc/output/copy_output_request.h" 19 #include "cc/output/copy_output_request.h"
21 #include "cc/output/copy_output_result.h" 20 #include "cc/output/copy_output_result.h"
22 #include "cc/trees/layer_tree_host.h" 21 #include "cc/trees/layer_tree_host.h"
23 #include "cc/trees/layer_tree_impl.h" 22 #include "cc/trees/layer_tree_impl.h"
24 #include "third_party/skia/include/core/SkImageFilter.h" 23 #include "third_party/skia/include/core/SkImageFilter.h"
25 #include "ui/gfx/geometry/vector2d_conversions.h"
26 #include "ui/gfx/rect_conversions.h" 24 #include "ui/gfx/rect_conversions.h"
27 25
28 namespace cc { 26 namespace cc {
29 27
30 static int s_next_layer_id = 1; 28 static int s_next_layer_id = 1;
31 29
32 scoped_refptr<Layer> Layer::Create() { 30 scoped_refptr<Layer> Layer::Create() {
33 return make_scoped_refptr(new Layer()); 31 return make_scoped_refptr(new Layer());
34 } 32 }
35 33
36 Layer::Layer() 34 Layer::Layer()
37 : needs_push_properties_(false), 35 : needs_push_properties_(false),
38 num_dependents_need_push_properties_(false), 36 num_dependents_need_push_properties_(false),
39 stacking_order_changed_(false), 37 stacking_order_changed_(false),
40 layer_id_(s_next_layer_id++), 38 layer_id_(s_next_layer_id++),
41 ignore_set_needs_commit_(false), 39 ignore_set_needs_commit_(false),
42 parent_(NULL), 40 parent_(NULL),
43 layer_tree_host_(NULL), 41 layer_tree_host_(NULL),
44 scroll_clip_layer_(NULL), 42 scrollable_(false),
45 should_scroll_on_main_thread_(false), 43 should_scroll_on_main_thread_(false),
46 have_wheel_event_handlers_(false), 44 have_wheel_event_handlers_(false),
47 user_scrollable_horizontal_(true), 45 user_scrollable_horizontal_(true),
48 user_scrollable_vertical_(true), 46 user_scrollable_vertical_(true),
49 is_root_for_isolated_group_(false), 47 is_root_for_isolated_group_(false),
50 is_container_for_fixed_position_layers_(false), 48 is_container_for_fixed_position_layers_(false),
51 is_drawable_(false), 49 is_drawable_(false),
52 hide_layer_and_subtree_(false), 50 hide_layer_and_subtree_(false),
53 masks_to_bounds_(false), 51 masks_to_bounds_(false),
54 contents_opaque_(false), 52 contents_opaque_(false),
(...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 672
675 void Layer::RemoveClipChild(Layer* child) { 673 void Layer::RemoveClipChild(Layer* child) {
676 clip_children_->erase(child); 674 clip_children_->erase(child);
677 if (clip_children_->empty()) 675 if (clip_children_->empty())
678 clip_children_.reset(); 676 clip_children_.reset();
679 SetNeedsCommit(); 677 SetNeedsCommit();
680 } 678 }
681 679
682 void Layer::SetScrollOffset(gfx::Vector2d scroll_offset) { 680 void Layer::SetScrollOffset(gfx::Vector2d scroll_offset) {
683 DCHECK(IsPropertyChangeAllowed()); 681 DCHECK(IsPropertyChangeAllowed());
684
685 if (layer_tree_host()) {
686 scroll_offset = layer_tree_host()->DistributeScrollOffsetToViewports(
687 scroll_offset, this);
688 }
689
690 if (scroll_offset_ == scroll_offset) 682 if (scroll_offset_ == scroll_offset)
691 return; 683 return;
692 scroll_offset_ = scroll_offset; 684 scroll_offset_ = scroll_offset;
693 SetNeedsCommit(); 685 SetNeedsCommit();
694 } 686 }
695 687
696 void Layer::SetScrollOffsetFromImplSide(gfx::Vector2d scroll_offset) { 688 void Layer::SetScrollOffsetFromImplSide(gfx::Vector2d scroll_offset) {
697 DCHECK(IsPropertyChangeAllowed()); 689 DCHECK(IsPropertyChangeAllowed());
698 // This function only gets called during a BeginMainFrame, so there 690 // This function only gets called during a BeginMainFrame, so there
699 // is no need to call SetNeedsUpdate here. 691 // is no need to call SetNeedsUpdate here.
700 DCHECK(layer_tree_host_ && layer_tree_host_->CommitRequested()); 692 DCHECK(layer_tree_host_ && layer_tree_host_->CommitRequested());
701 if (scroll_offset_ == scroll_offset) 693 if (scroll_offset_ == scroll_offset)
702 return; 694 return;
703 scroll_offset_ = scroll_offset; 695 scroll_offset_ = scroll_offset;
704 SetNeedsPushProperties(); 696 SetNeedsPushProperties();
705 if (!did_scroll_callback_.is_null()) 697 if (!did_scroll_callback_.is_null())
706 did_scroll_callback_.Run(); 698 did_scroll_callback_.Run();
707 // The callback could potentially change the layer structure: 699 // The callback could potentially change the layer structure:
708 // "this" may have been destroyed during the process. 700 // "this" may have been destroyed during the process.
709 } 701 }
710 702
711 // TODO(wjmaclean) We should template this and put it into LayerTreeHostCommon 703 void Layer::SetMaxScrollOffset(gfx::Vector2d max_scroll_offset) {
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.f / scale_factor);
740 max_offset.SetToMax(gfx::Vector2dF());
741 return gfx::ToFlooredVector2d(max_offset);
742 }
743
744 void Layer::SetScrollClipLayer(Layer* clip_layer) {
745 DCHECK(IsPropertyChangeAllowed()); 704 DCHECK(IsPropertyChangeAllowed());
746 if (scroll_clip_layer_ == clip_layer) 705 if (max_scroll_offset_ == max_scroll_offset)
747 return; 706 return;
748 scroll_clip_layer_ = clip_layer; 707 max_scroll_offset_ = max_scroll_offset;
749 SetNeedsCommit(); 708 SetNeedsCommit();
750 } 709 }
751 710
711 void Layer::SetScrollable(bool scrollable) {
712 DCHECK(IsPropertyChangeAllowed());
713 if (scrollable_ == scrollable)
714 return;
715 scrollable_ = scrollable;
716 SetNeedsCommit();
717 }
718
752 void Layer::SetUserScrollable(bool horizontal, bool vertical) { 719 void Layer::SetUserScrollable(bool horizontal, bool vertical) {
753 DCHECK(IsPropertyChangeAllowed()); 720 DCHECK(IsPropertyChangeAllowed());
754 if (user_scrollable_horizontal_ == horizontal && 721 if (user_scrollable_horizontal_ == horizontal &&
755 user_scrollable_vertical_ == vertical) 722 user_scrollable_vertical_ == vertical)
756 return; 723 return;
757 user_scrollable_horizontal_ = horizontal; 724 user_scrollable_horizontal_ = horizontal;
758 user_scrollable_vertical_ = vertical; 725 user_scrollable_vertical_ = vertical;
759 SetNeedsCommit(); 726 SetNeedsCommit();
760 } 727 }
761 728
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
937 IsContainerForFixedPositionLayers()); 904 IsContainerForFixedPositionLayers());
938 layer->SetFixedContainerSizeDelta(gfx::Vector2dF()); 905 layer->SetFixedContainerSizeDelta(gfx::Vector2dF());
939 layer->SetPositionConstraint(position_constraint_); 906 layer->SetPositionConstraint(position_constraint_);
940 layer->SetPreserves3d(preserves_3d()); 907 layer->SetPreserves3d(preserves_3d());
941 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_); 908 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_);
942 layer->SetSublayerTransform(sublayer_transform_); 909 layer->SetSublayerTransform(sublayer_transform_);
943 if (!layer->TransformIsAnimatingOnImplOnly() && !TransformIsAnimating()) 910 if (!layer->TransformIsAnimatingOnImplOnly() && !TransformIsAnimating())
944 layer->SetTransform(transform_); 911 layer->SetTransform(transform_);
945 DCHECK(!(TransformIsAnimating() && layer->TransformIsAnimatingOnImplOnly())); 912 DCHECK(!(TransformIsAnimating() && layer->TransformIsAnimatingOnImplOnly()));
946 913
947 layer->SetScrollClipLayer(scroll_clip_layer_ ? scroll_clip_layer_->id() 914 layer->SetScrollable(scrollable_);
948 : Layer::INVALID_ID);
949 layer->set_user_scrollable_horizontal(user_scrollable_horizontal_); 915 layer->set_user_scrollable_horizontal(user_scrollable_horizontal_);
950 layer->set_user_scrollable_vertical(user_scrollable_vertical_); 916 layer->set_user_scrollable_vertical(user_scrollable_vertical_);
917 layer->SetMaxScrollOffset(max_scroll_offset_);
951 918
952 LayerImpl* scroll_parent = NULL; 919 LayerImpl* scroll_parent = NULL;
953 if (scroll_parent_) 920 if (scroll_parent_)
954 scroll_parent = layer->layer_tree_impl()->LayerById(scroll_parent_->id()); 921 scroll_parent = layer->layer_tree_impl()->LayerById(scroll_parent_->id());
955 922
956 layer->SetScrollParent(scroll_parent); 923 layer->SetScrollParent(scroll_parent);
957 if (scroll_children_) { 924 if (scroll_children_) {
958 std::set<LayerImpl*>* scroll_children = new std::set<LayerImpl*>; 925 std::set<LayerImpl*>* scroll_children = new std::set<LayerImpl*>;
959 for (std::set<Layer*>::iterator it = scroll_children_->begin(); 926 for (std::set<Layer*>::iterator it = scroll_children_->begin();
960 it != scroll_children_->end(); ++it) 927 it != scroll_children_->end(); ++it)
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
1199 clip_parent_->RemoveClipChild(this); 1166 clip_parent_->RemoveClipChild(this);
1200 1167
1201 clip_parent_ = NULL; 1168 clip_parent_ = NULL;
1202 } 1169 }
1203 1170
1204 void Layer::RunMicroBenchmark(MicroBenchmark* benchmark) { 1171 void Layer::RunMicroBenchmark(MicroBenchmark* benchmark) {
1205 benchmark->RunOnLayer(this); 1172 benchmark->RunOnLayer(this);
1206 } 1173 }
1207 1174
1208 } // namespace cc 1175 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/layer.h ('k') | cc/layers/layer_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698