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

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

Issue 2189583004: [not for review - epic CL] Adding Elastic+Momentum+Layered scrolling to views::ScrollView Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 2 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
« 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 <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <algorithm> 10 #include <algorithm>
(...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after
764 DCHECK(IsPropertyChangeAllowed()); 764 DCHECK(IsPropertyChangeAllowed());
765 765
766 if (inputs_.scroll_offset == scroll_offset) 766 if (inputs_.scroll_offset == scroll_offset)
767 return; 767 return;
768 inputs_.scroll_offset = scroll_offset; 768 inputs_.scroll_offset = scroll_offset;
769 769
770 if (!layer_tree_host_) 770 if (!layer_tree_host_)
771 return; 771 return;
772 772
773 PropertyTrees* property_trees = layer_tree_->property_trees(); 773 PropertyTrees* property_trees = layer_tree_->property_trees();
774 if (scroll_tree_index() != ScrollTree::kInvalidNodeId && scrollable()) 774 if (scroll_tree_index() != ScrollTree::kInvalidNodeId && scrollable()) {
775 property_trees->scroll_tree.SetScrollOffset(id(), scroll_offset); 775 property_trees->scroll_tree.SetScrollOffset(id(), inputs_.scroll_offset,
776 inputs_.overscroll);
777 }
776 778
777 if (property_trees->IsInIdToIndexMap(PropertyTrees::TreeType::TRANSFORM, 779 if (property_trees->IsInIdToIndexMap(PropertyTrees::TreeType::TRANSFORM,
778 id())) { 780 id())) {
779 DCHECK_EQ(transform_tree_index(), 781 DCHECK_EQ(transform_tree_index(),
780 property_trees->transform_id_to_index_map[id()]); 782 property_trees->transform_id_to_index_map[id()]);
781 TransformNode* transform_node = 783 TransformNode* transform_node =
782 property_trees->transform_tree.Node(transform_tree_index()); 784 property_trees->transform_tree.Node(transform_tree_index());
783 transform_node->scroll_offset = CurrentScrollOffset(); 785 transform_node->scroll_offset_with_overscroll =
786 inputs_.scroll_offset + inputs_.overscroll;
784 transform_node->needs_local_transform_update = true; 787 transform_node->needs_local_transform_update = true;
785 property_trees->transform_tree.set_needs_update(true); 788 property_trees->transform_tree.set_needs_update(true);
786 SetNeedsCommitNoRebuild(); 789 SetNeedsCommitNoRebuild();
787 return; 790 return;
788 } 791 }
789 792
790 SetNeedsCommit(); 793 SetNeedsCommit();
791 } 794 }
792 795
793 void Layer::SetScrollOffsetFromImplSide( 796 void Layer::SetScrollOffsetFromImplSide(const gfx::ScrollOffset& scroll_offset,
794 const gfx::ScrollOffset& scroll_offset) { 797 gfx::Vector2dF* overscroll_delta) {
795 DCHECK(IsPropertyChangeAllowed()); 798 DCHECK(IsPropertyChangeAllowed());
796 // This function only gets called during a BeginMainFrame, so there 799 // This function only gets called during a BeginMainFrame, so there
797 // is no need to call SetNeedsUpdate here. 800 // is no need to call SetNeedsUpdate here.
798 DCHECK(layer_tree_host_ && layer_tree_host_->CommitRequested()); 801 DCHECK(layer_tree_host_ && layer_tree_host_->CommitRequested());
799 if (inputs_.scroll_offset == scroll_offset) 802
803 gfx::ScrollOffset overscroll = inputs_.overscroll;
804 if (inputs_.can_overscroll && overscroll_delta) {
805 overscroll = gfx::ScrollOffsetWithDelta(overscroll, *overscroll_delta);
806 *overscroll_delta = gfx::Vector2dF();
807 }
808 if (inputs_.scroll_offset == scroll_offset &&
809 inputs_.overscroll == overscroll)
800 return; 810 return;
811
801 inputs_.scroll_offset = scroll_offset; 812 inputs_.scroll_offset = scroll_offset;
813 inputs_.overscroll = overscroll;
802 SetNeedsPushProperties(); 814 SetNeedsPushProperties();
803 815
804 bool needs_rebuild = true; 816 bool needs_rebuild = true;
805 817
806 PropertyTrees* property_trees = layer_tree_->property_trees(); 818 PropertyTrees* property_trees = layer_tree_->property_trees();
807 if (scroll_tree_index() != ScrollTree::kInvalidNodeId && scrollable()) 819 if (scroll_tree_index() != ScrollTree::kInvalidNodeId && scrollable()) {
808 property_trees->scroll_tree.SetScrollOffset(id(), scroll_offset); 820 property_trees->scroll_tree.SetScrollOffset(id(), inputs_.scroll_offset,
821 inputs_.overscroll);
822 }
809 823
810 if (property_trees->IsInIdToIndexMap(PropertyTrees::TreeType::TRANSFORM, 824 if (property_trees->IsInIdToIndexMap(PropertyTrees::TreeType::TRANSFORM,
811 id())) { 825 id())) {
812 DCHECK_EQ(transform_tree_index(), 826 DCHECK_EQ(transform_tree_index(),
813 property_trees->transform_id_to_index_map[id()]); 827 property_trees->transform_id_to_index_map[id()]);
814 TransformNode* transform_node = 828 TransformNode* transform_node =
815 property_trees->transform_tree.Node(transform_tree_index()); 829 property_trees->transform_tree.Node(transform_tree_index());
816 transform_node->scroll_offset = CurrentScrollOffset(); 830 transform_node->scroll_offset_with_overscroll =
831 inputs_.scroll_offset + inputs_.overscroll;
817 transform_node->needs_local_transform_update = true; 832 transform_node->needs_local_transform_update = true;
818 property_trees->transform_tree.set_needs_update(true); 833 property_trees->transform_tree.set_needs_update(true);
819 needs_rebuild = false; 834 needs_rebuild = false;
820 } 835 }
821 836
822 if (needs_rebuild) 837 if (needs_rebuild)
823 property_trees->needs_rebuild = true; 838 property_trees->needs_rebuild = true;
824 839
825 if (!inputs_.did_scroll_callback.is_null()) 840 if (!inputs_.did_scroll_callback.is_null())
826 inputs_.did_scroll_callback.Run(); 841 inputs_.did_scroll_callback.Run();
827 // The callback could potentially change the layer structure: 842 // The callback could potentially change the layer structure:
828 // "this" may have been destroyed during the process. 843 // "this" may have been destroyed during the process.
829 } 844 }
830 845
831 void Layer::SetScrollClipLayerId(int clip_layer_id) { 846 void Layer::SetScrollClipAndCanOverscroll(int clip_layer_id,
847 bool can_overscroll) {
832 DCHECK(IsPropertyChangeAllowed()); 848 DCHECK(IsPropertyChangeAllowed());
833 if (inputs_.scroll_clip_layer_id == clip_layer_id) 849 if (inputs_.scroll_clip_layer_id == clip_layer_id &&
850 inputs_.can_overscroll == can_overscroll)
834 return; 851 return;
835 inputs_.scroll_clip_layer_id = clip_layer_id; 852 inputs_.scroll_clip_layer_id = clip_layer_id;
853 inputs_.can_overscroll = can_overscroll;
836 SetNeedsCommit(); 854 SetNeedsCommit();
837 } 855 }
838 856
839 Layer* Layer::scroll_clip_layer() const { 857 Layer* Layer::scroll_clip_layer() const {
840 DCHECK(layer_tree_); 858 DCHECK(layer_tree_);
841 return layer_tree_->LayerById(inputs_.scroll_clip_layer_id); 859 return layer_tree_->LayerById(inputs_.scroll_clip_layer_id);
842 } 860 }
843 861
844 void Layer::SetUserScrollable(bool horizontal, bool vertical) { 862 void Layer::SetUserScrollable(bool horizontal, bool vertical) {
845 DCHECK(IsPropertyChangeAllowed()); 863 DCHECK(IsPropertyChangeAllowed());
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
1153 layer->SetPosition(inputs_.position); 1171 layer->SetPosition(inputs_.position);
1154 layer->set_should_flatten_transform_from_property_tree( 1172 layer->set_should_flatten_transform_from_property_tree(
1155 should_flatten_transform_from_property_tree_); 1173 should_flatten_transform_from_property_tree_);
1156 layer->set_draw_blend_mode(draw_blend_mode_); 1174 layer->set_draw_blend_mode(draw_blend_mode_);
1157 layer->SetUseParentBackfaceVisibility(inputs_.use_parent_backface_visibility); 1175 layer->SetUseParentBackfaceVisibility(inputs_.use_parent_backface_visibility);
1158 layer->SetUseLocalTransformForBackfaceVisibility( 1176 layer->SetUseLocalTransformForBackfaceVisibility(
1159 use_local_transform_for_backface_visibility_); 1177 use_local_transform_for_backface_visibility_);
1160 layer->SetShouldCheckBackfaceVisibility(should_check_backface_visibility_); 1178 layer->SetShouldCheckBackfaceVisibility(should_check_backface_visibility_);
1161 layer->Set3dSortingContextId(inputs_.sorting_context_id); 1179 layer->Set3dSortingContextId(inputs_.sorting_context_id);
1162 1180
1163 layer->SetScrollClipLayer(inputs_.scroll_clip_layer_id); 1181 layer->SetScrollClipAndCanOverscroll(inputs_.scroll_clip_layer_id,
1182 inputs_.can_overscroll);
1164 layer->set_user_scrollable_horizontal(inputs_.user_scrollable_horizontal); 1183 layer->set_user_scrollable_horizontal(inputs_.user_scrollable_horizontal);
1165 layer->set_user_scrollable_vertical(inputs_.user_scrollable_vertical); 1184 layer->set_user_scrollable_vertical(inputs_.user_scrollable_vertical);
1166 layer->SetElementId(inputs_.element_id); 1185 layer->SetElementId(inputs_.element_id);
1167 layer->SetMutableProperties(inputs_.mutable_properties); 1186 layer->SetMutableProperties(inputs_.mutable_properties);
1168 1187
1169 // When a scroll offset animation is interrupted the new scroll position on 1188 // When a scroll offset animation is interrupted the new scroll position on
1170 // the pending tree will clobber any impl-side scrolling occuring on the 1189 // the pending tree will clobber any impl-side scrolling occuring on the
1171 // active tree. To do so, avoid scrolling the pending tree along with it 1190 // active tree. To do so, avoid scrolling the pending tree along with it
1172 // instead of trying to undo that scrolling later. 1191 // instead of trying to undo that scrolling later.
1173 if (ScrollOffsetAnimationWasInterrupted()) 1192 if (ScrollOffsetAnimationWasInterrupted())
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
1336 base->set_double_sided(inputs_.double_sided); 1355 base->set_double_sided(inputs_.double_sided);
1337 base->set_should_flatten_transform(inputs_.should_flatten_transform); 1356 base->set_should_flatten_transform(inputs_.should_flatten_transform);
1338 base->set_sorting_context_id(inputs_.sorting_context_id); 1357 base->set_sorting_context_id(inputs_.sorting_context_id);
1339 base->set_use_parent_backface_visibility( 1358 base->set_use_parent_backface_visibility(
1340 inputs_.use_parent_backface_visibility); 1359 inputs_.use_parent_backface_visibility);
1341 base->set_background_color(inputs_.background_color); 1360 base->set_background_color(inputs_.background_color);
1342 ScrollOffsetToProto(inputs_.scroll_offset, base->mutable_scroll_offset()); 1361 ScrollOffsetToProto(inputs_.scroll_offset, base->mutable_scroll_offset());
1343 base->set_scroll_clip_layer_id(inputs_.scroll_clip_layer_id); 1362 base->set_scroll_clip_layer_id(inputs_.scroll_clip_layer_id);
1344 base->set_user_scrollable_horizontal(inputs_.user_scrollable_horizontal); 1363 base->set_user_scrollable_horizontal(inputs_.user_scrollable_horizontal);
1345 base->set_user_scrollable_vertical(inputs_.user_scrollable_vertical); 1364 base->set_user_scrollable_vertical(inputs_.user_scrollable_vertical);
1365 base->set_can_overscroll(inputs_.can_overscroll);
1346 base->set_main_thread_scrolling_reasons( 1366 base->set_main_thread_scrolling_reasons(
1347 inputs_.main_thread_scrolling_reasons); 1367 inputs_.main_thread_scrolling_reasons);
1348 RegionToProto(inputs_.non_fast_scrollable_region, 1368 RegionToProto(inputs_.non_fast_scrollable_region,
1349 base->mutable_non_fast_scrollable_region()); 1369 base->mutable_non_fast_scrollable_region());
1350 RegionToProto(inputs_.touch_event_handler_region, 1370 RegionToProto(inputs_.touch_event_handler_region,
1351 base->mutable_touch_event_handler_region()); 1371 base->mutable_touch_event_handler_region());
1352 base->set_is_container_for_fixed_position_layers( 1372 base->set_is_container_for_fixed_position_layers(
1353 inputs_.is_container_for_fixed_position_layers); 1373 inputs_.is_container_for_fixed_position_layers);
1354 inputs_.position_constraint.ToProtobuf(base->mutable_position_constraint()); 1374 inputs_.position_constraint.ToProtobuf(base->mutable_position_constraint());
1355 inputs_.sticky_position_constraint.ToProtobuf( 1375 inputs_.sticky_position_constraint.ToProtobuf(
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
1471 draw_blend_mode_ = SkXfermodeModeFromProto(base.draw_blend_mode()); 1491 draw_blend_mode_ = SkXfermodeModeFromProto(base.draw_blend_mode());
1472 inputs_.use_parent_backface_visibility = 1492 inputs_.use_parent_backface_visibility =
1473 base.use_parent_backface_visibility(); 1493 base.use_parent_backface_visibility();
1474 inputs_.transform = ProtoToTransform(base.transform()); 1494 inputs_.transform = ProtoToTransform(base.transform());
1475 inputs_.sorting_context_id = base.sorting_context_id(); 1495 inputs_.sorting_context_id = base.sorting_context_id();
1476 num_descendants_that_draw_content_ = base.num_descendants_that_draw_content(); 1496 num_descendants_that_draw_content_ = base.num_descendants_that_draw_content();
1477 1497
1478 inputs_.scroll_clip_layer_id = base.scroll_clip_layer_id(); 1498 inputs_.scroll_clip_layer_id = base.scroll_clip_layer_id();
1479 inputs_.user_scrollable_horizontal = base.user_scrollable_horizontal(); 1499 inputs_.user_scrollable_horizontal = base.user_scrollable_horizontal();
1480 inputs_.user_scrollable_vertical = base.user_scrollable_vertical(); 1500 inputs_.user_scrollable_vertical = base.user_scrollable_vertical();
1501 inputs_.can_overscroll = base.can_overscroll();
1481 1502
1482 inputs_.scroll_parent = base.scroll_parent_id() == INVALID_ID 1503 inputs_.scroll_parent = base.scroll_parent_id() == INVALID_ID
1483 ? nullptr 1504 ? nullptr
1484 : layer_tree_->LayerById(base.scroll_parent_id()); 1505 : layer_tree_->LayerById(base.scroll_parent_id());
1485 1506
1486 // If there have been scroll children entries in previous deserializations, 1507 // If there have been scroll children entries in previous deserializations,
1487 // clear out the set. If there have been none, initialize the set of children. 1508 // clear out the set. If there have been none, initialize the set of children.
1488 // After this, the set is in the correct state to only add the new children. 1509 // After this, the set is in the correct state to only add the new children.
1489 // If the set of children has not changed, for now this code still rebuilds 1510 // If the set of children has not changed, for now this code still rebuilds
1490 // the set. 1511 // the set.
(...skipping 20 matching lines...) Expand all
1511 clip_children_->clear(); 1532 clip_children_->clear();
1512 else if (base.clip_children_ids_size() > 0) 1533 else if (base.clip_children_ids_size() > 0)
1513 clip_children_.reset(new std::set<Layer*>); 1534 clip_children_.reset(new std::set<Layer*>);
1514 for (int i = 0; i < base.clip_children_ids_size(); ++i) { 1535 for (int i = 0; i < base.clip_children_ids_size(); ++i) {
1515 int child_id = base.clip_children_ids(i); 1536 int child_id = base.clip_children_ids(i);
1516 scoped_refptr<Layer> child = layer_tree_->LayerById(child_id); 1537 scoped_refptr<Layer> child = layer_tree_->LayerById(child_id);
1517 clip_children_->insert(child.get()); 1538 clip_children_->insert(child.get());
1518 } 1539 }
1519 1540
1520 inputs_.scroll_offset = ProtoToScrollOffset(base.scroll_offset()); 1541 inputs_.scroll_offset = ProtoToScrollOffset(base.scroll_offset());
1542 inputs_.overscroll = ProtoToScrollOffset(base.overscroll());
1521 1543
1522 inputs_.update_rect.Union(ProtoToRect(base.update_rect())); 1544 inputs_.update_rect.Union(ProtoToRect(base.update_rect()));
1523 1545
1524 inputs_.has_will_change_transform_hint = 1546 inputs_.has_will_change_transform_hint =
1525 base.has_will_change_transform_hint(); 1547 base.has_will_change_transform_hint();
1526 } 1548 }
1527 1549
1528 std::unique_ptr<LayerImpl> Layer::CreateLayerImpl(LayerTreeImpl* tree_impl) { 1550 std::unique_ptr<LayerImpl> Layer::CreateLayerImpl(LayerTreeImpl* tree_impl) {
1529 return LayerImpl::Create(tree_impl, inputs_.layer_id); 1551 return LayerImpl::Create(tree_impl, inputs_.layer_id);
1530 } 1552 }
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
1862 1884
1863 LayerTree* Layer::GetLayerTree() const { 1885 LayerTree* Layer::GetLayerTree() const {
1864 return layer_tree_; 1886 return layer_tree_;
1865 } 1887 }
1866 1888
1867 void Layer::SetLayerIdForTesting(int id) { 1889 void Layer::SetLayerIdForTesting(int id) {
1868 inputs_.layer_id = id; 1890 inputs_.layer_id = id;
1869 } 1891 }
1870 1892
1871 } // namespace cc 1893 } // 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