| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 764 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 775 DCHECK(IsPropertyChangeAllowed()); | 775 DCHECK(IsPropertyChangeAllowed()); |
| 776 | 776 |
| 777 if (inputs_.scroll_offset == scroll_offset) | 777 if (inputs_.scroll_offset == scroll_offset) |
| 778 return; | 778 return; |
| 779 inputs_.scroll_offset = scroll_offset; | 779 inputs_.scroll_offset = scroll_offset; |
| 780 | 780 |
| 781 if (!layer_tree_host_) | 781 if (!layer_tree_host_) |
| 782 return; | 782 return; |
| 783 | 783 |
| 784 PropertyTrees* property_trees = layer_tree_host_->property_trees(); | 784 PropertyTrees* property_trees = layer_tree_host_->property_trees(); |
| 785 if (scroll_tree_index() != -1 && scrollable()) | 785 if (scroll_tree_index() != -1 && scrollable()) { |
| 786 property_trees->scroll_tree.SetScrollOffset(id(), scroll_offset); | 786 property_trees->scroll_tree.SetScrollOffset(id(), inputs_.scroll_offset, |
| 787 inputs_.overscroll); |
| 788 } |
| 787 | 789 |
| 788 if (property_trees->IsInIdToIndexMap(PropertyTrees::TreeType::TRANSFORM, | 790 if (property_trees->IsInIdToIndexMap(PropertyTrees::TreeType::TRANSFORM, |
| 789 id())) { | 791 id())) { |
| 790 DCHECK_EQ(transform_tree_index(), | 792 DCHECK_EQ(transform_tree_index(), |
| 791 property_trees->transform_id_to_index_map[id()]); | 793 property_trees->transform_id_to_index_map[id()]); |
| 792 TransformNode* transform_node = | 794 TransformNode* transform_node = |
| 793 property_trees->transform_tree.Node(transform_tree_index()); | 795 property_trees->transform_tree.Node(transform_tree_index()); |
| 794 transform_node->scroll_offset = CurrentScrollOffset(); | 796 transform_node->scroll_offset_with_overscroll = |
| 797 inputs_.scroll_offset + inputs_.overscroll; |
| 795 transform_node->needs_local_transform_update = true; | 798 transform_node->needs_local_transform_update = true; |
| 796 property_trees->transform_tree.set_needs_update(true); | 799 property_trees->transform_tree.set_needs_update(true); |
| 797 SetNeedsCommitNoRebuild(); | 800 SetNeedsCommitNoRebuild(); |
| 798 return; | 801 return; |
| 799 } | 802 } |
| 800 | 803 |
| 801 SetNeedsCommit(); | 804 SetNeedsCommit(); |
| 802 } | 805 } |
| 803 | 806 |
| 804 void Layer::SetScrollOffsetFromImplSide( | 807 void Layer::SetScrollOffsetFromImplSide(const gfx::ScrollOffset& scroll_offset, |
| 805 const gfx::ScrollOffset& scroll_offset) { | 808 gfx::Vector2dF* overscroll_delta) { |
| 806 DCHECK(IsPropertyChangeAllowed()); | 809 DCHECK(IsPropertyChangeAllowed()); |
| 807 // This function only gets called during a BeginMainFrame, so there | 810 // This function only gets called during a BeginMainFrame, so there |
| 808 // is no need to call SetNeedsUpdate here. | 811 // is no need to call SetNeedsUpdate here. |
| 809 DCHECK(layer_tree_host_ && layer_tree_host_->CommitRequested()); | 812 DCHECK(layer_tree_host_ && layer_tree_host_->CommitRequested()); |
| 810 if (inputs_.scroll_offset == scroll_offset) | 813 |
| 814 gfx::ScrollOffset overscroll = inputs_.overscroll; |
| 815 if (inputs_.can_overscroll && overscroll_delta) { |
| 816 overscroll = gfx::ScrollOffsetWithDelta(overscroll, *overscroll_delta); |
| 817 *overscroll_delta = gfx::Vector2dF(); |
| 818 } |
| 819 if (inputs_.scroll_offset == scroll_offset && |
| 820 inputs_.overscroll == overscroll) |
| 811 return; | 821 return; |
| 822 |
| 812 inputs_.scroll_offset = scroll_offset; | 823 inputs_.scroll_offset = scroll_offset; |
| 824 inputs_.overscroll = overscroll; |
| 813 SetNeedsPushProperties(); | 825 SetNeedsPushProperties(); |
| 814 | 826 |
| 815 bool needs_rebuild = true; | 827 bool needs_rebuild = true; |
| 816 | 828 |
| 817 PropertyTrees* property_trees = layer_tree_host_->property_trees(); | 829 PropertyTrees* property_trees = layer_tree_host_->property_trees(); |
| 818 if (scroll_tree_index() != -1 && scrollable()) | 830 if (scroll_tree_index() != -1 && scrollable()) { |
| 819 property_trees->scroll_tree.SetScrollOffset(id(), scroll_offset); | 831 property_trees->scroll_tree.SetScrollOffset(id(), inputs_.scroll_offset, |
| 832 inputs_.overscroll); |
| 833 } |
| 820 | 834 |
| 821 if (property_trees->IsInIdToIndexMap(PropertyTrees::TreeType::TRANSFORM, | 835 if (property_trees->IsInIdToIndexMap(PropertyTrees::TreeType::TRANSFORM, |
| 822 id())) { | 836 id())) { |
| 823 DCHECK_EQ(transform_tree_index(), | 837 DCHECK_EQ(transform_tree_index(), |
| 824 property_trees->transform_id_to_index_map[id()]); | 838 property_trees->transform_id_to_index_map[id()]); |
| 825 TransformNode* transform_node = | 839 TransformNode* transform_node = |
| 826 property_trees->transform_tree.Node(transform_tree_index()); | 840 property_trees->transform_tree.Node(transform_tree_index()); |
| 827 transform_node->scroll_offset = CurrentScrollOffset(); | 841 transform_node->scroll_offset_with_overscroll = |
| 842 inputs_.scroll_offset + inputs_.overscroll; |
| 828 transform_node->needs_local_transform_update = true; | 843 transform_node->needs_local_transform_update = true; |
| 829 property_trees->transform_tree.set_needs_update(true); | 844 property_trees->transform_tree.set_needs_update(true); |
| 830 needs_rebuild = false; | 845 needs_rebuild = false; |
| 831 } | 846 } |
| 832 | 847 |
| 833 if (needs_rebuild) | 848 if (needs_rebuild) |
| 834 property_trees->needs_rebuild = true; | 849 property_trees->needs_rebuild = true; |
| 835 | 850 |
| 836 if (!inputs_.did_scroll_callback.is_null()) | 851 if (!inputs_.did_scroll_callback.is_null()) |
| 837 inputs_.did_scroll_callback.Run(); | 852 inputs_.did_scroll_callback.Run(); |
| 838 // The callback could potentially change the layer structure: | 853 // The callback could potentially change the layer structure: |
| 839 // "this" may have been destroyed during the process. | 854 // "this" may have been destroyed during the process. |
| 840 } | 855 } |
| 841 | 856 |
| 842 void Layer::SetScrollClipLayerId(int clip_layer_id) { | 857 void Layer::SetScrollClipAndCanOverscroll(int clip_layer_id, |
| 858 bool can_overscroll) { |
| 843 DCHECK(IsPropertyChangeAllowed()); | 859 DCHECK(IsPropertyChangeAllowed()); |
| 844 if (inputs_.scroll_clip_layer_id == clip_layer_id) | 860 if (inputs_.scroll_clip_layer_id == clip_layer_id && |
| 861 inputs_.can_overscroll == can_overscroll) |
| 845 return; | 862 return; |
| 846 inputs_.scroll_clip_layer_id = clip_layer_id; | 863 inputs_.scroll_clip_layer_id = clip_layer_id; |
| 864 inputs_.can_overscroll = can_overscroll; |
| 847 SetNeedsCommit(); | 865 SetNeedsCommit(); |
| 848 } | 866 } |
| 849 | 867 |
| 850 Layer* Layer::scroll_clip_layer() const { | 868 Layer* Layer::scroll_clip_layer() const { |
| 851 return layer_tree_host()->LayerById(inputs_.scroll_clip_layer_id); | 869 return layer_tree_host()->LayerById(inputs_.scroll_clip_layer_id); |
| 852 } | 870 } |
| 853 | 871 |
| 854 void Layer::SetUserScrollable(bool horizontal, bool vertical) { | 872 void Layer::SetUserScrollable(bool horizontal, bool vertical) { |
| 855 DCHECK(IsPropertyChangeAllowed()); | 873 DCHECK(IsPropertyChangeAllowed()); |
| 856 if (inputs_.user_scrollable_horizontal == horizontal && | 874 if (inputs_.user_scrollable_horizontal == horizontal && |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1156 should_flatten_transform_from_property_tree_); | 1174 should_flatten_transform_from_property_tree_); |
| 1157 layer->set_draw_blend_mode(draw_blend_mode_); | 1175 layer->set_draw_blend_mode(draw_blend_mode_); |
| 1158 layer->SetUseParentBackfaceVisibility(inputs_.use_parent_backface_visibility); | 1176 layer->SetUseParentBackfaceVisibility(inputs_.use_parent_backface_visibility); |
| 1159 layer->SetUseLocalTransformForBackfaceVisibility( | 1177 layer->SetUseLocalTransformForBackfaceVisibility( |
| 1160 use_local_transform_for_backface_visibility_); | 1178 use_local_transform_for_backface_visibility_); |
| 1161 layer->SetShouldCheckBackfaceVisibility(should_check_backface_visibility_); | 1179 layer->SetShouldCheckBackfaceVisibility(should_check_backface_visibility_); |
| 1162 if (!TransformIsAnimating()) | 1180 if (!TransformIsAnimating()) |
| 1163 layer->SetTransform(inputs_.transform); | 1181 layer->SetTransform(inputs_.transform); |
| 1164 layer->Set3dSortingContextId(inputs_.sorting_context_id); | 1182 layer->Set3dSortingContextId(inputs_.sorting_context_id); |
| 1165 | 1183 |
| 1166 layer->SetScrollClipLayer(inputs_.scroll_clip_layer_id); | 1184 layer->SetScrollClipAndCanOverscroll(inputs_.scroll_clip_layer_id, |
| 1185 inputs_.can_overscroll); |
| 1167 layer->set_user_scrollable_horizontal(inputs_.user_scrollable_horizontal); | 1186 layer->set_user_scrollable_horizontal(inputs_.user_scrollable_horizontal); |
| 1168 layer->set_user_scrollable_vertical(inputs_.user_scrollable_vertical); | 1187 layer->set_user_scrollable_vertical(inputs_.user_scrollable_vertical); |
| 1169 layer->SetElementId(inputs_.element_id); | 1188 layer->SetElementId(inputs_.element_id); |
| 1170 layer->SetMutableProperties(inputs_.mutable_properties); | 1189 layer->SetMutableProperties(inputs_.mutable_properties); |
| 1171 | 1190 |
| 1172 // When a scroll offset animation is interrupted the new scroll position on | 1191 // When a scroll offset animation is interrupted the new scroll position on |
| 1173 // the pending tree will clobber any impl-side scrolling occuring on the | 1192 // the pending tree will clobber any impl-side scrolling occuring on the |
| 1174 // active tree. To do so, avoid scrolling the pending tree along with it | 1193 // active tree. To do so, avoid scrolling the pending tree along with it |
| 1175 // instead of trying to undo that scrolling later. | 1194 // instead of trying to undo that scrolling later. |
| 1176 if (ScrollOffsetAnimationWasInterrupted()) | 1195 if (ScrollOffsetAnimationWasInterrupted()) |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1380 base->set_use_parent_backface_visibility( | 1399 base->set_use_parent_backface_visibility( |
| 1381 inputs_.use_parent_backface_visibility); | 1400 inputs_.use_parent_backface_visibility); |
| 1382 TransformToProto(inputs_.transform, base->mutable_transform()); | 1401 TransformToProto(inputs_.transform, base->mutable_transform()); |
| 1383 base->set_sorting_context_id(inputs_.sorting_context_id); | 1402 base->set_sorting_context_id(inputs_.sorting_context_id); |
| 1384 base->set_num_descendants_that_draw_content( | 1403 base->set_num_descendants_that_draw_content( |
| 1385 num_descendants_that_draw_content_); | 1404 num_descendants_that_draw_content_); |
| 1386 | 1405 |
| 1387 base->set_scroll_clip_layer_id(inputs_.scroll_clip_layer_id); | 1406 base->set_scroll_clip_layer_id(inputs_.scroll_clip_layer_id); |
| 1388 base->set_user_scrollable_horizontal(inputs_.user_scrollable_horizontal); | 1407 base->set_user_scrollable_horizontal(inputs_.user_scrollable_horizontal); |
| 1389 base->set_user_scrollable_vertical(inputs_.user_scrollable_vertical); | 1408 base->set_user_scrollable_vertical(inputs_.user_scrollable_vertical); |
| 1409 base->set_can_overscroll(inputs_.can_overscroll); |
| 1390 | 1410 |
| 1391 int scroll_parent_id = | 1411 int scroll_parent_id = |
| 1392 inputs_.scroll_parent ? inputs_.scroll_parent->id() : INVALID_ID; | 1412 inputs_.scroll_parent ? inputs_.scroll_parent->id() : INVALID_ID; |
| 1393 base->set_scroll_parent_id(scroll_parent_id); | 1413 base->set_scroll_parent_id(scroll_parent_id); |
| 1394 | 1414 |
| 1395 if (scroll_children_) { | 1415 if (scroll_children_) { |
| 1396 for (auto* child : *scroll_children_) | 1416 for (auto* child : *scroll_children_) |
| 1397 base->add_scroll_children_ids(child->id()); | 1417 base->add_scroll_children_ids(child->id()); |
| 1398 } | 1418 } |
| 1399 | 1419 |
| 1400 int clip_parent_id = | 1420 int clip_parent_id = |
| 1401 inputs_.clip_parent ? inputs_.clip_parent->id() : INVALID_ID; | 1421 inputs_.clip_parent ? inputs_.clip_parent->id() : INVALID_ID; |
| 1402 base->set_clip_parent_id(clip_parent_id); | 1422 base->set_clip_parent_id(clip_parent_id); |
| 1403 | 1423 |
| 1404 if (clip_children_) { | 1424 if (clip_children_) { |
| 1405 for (auto* child : *clip_children_) | 1425 for (auto* child : *clip_children_) |
| 1406 base->add_clip_children_ids(child->id()); | 1426 base->add_clip_children_ids(child->id()); |
| 1407 } | 1427 } |
| 1408 | 1428 |
| 1409 ScrollOffsetToProto(inputs_.scroll_offset, base->mutable_scroll_offset()); | 1429 ScrollOffsetToProto(inputs_.scroll_offset, base->mutable_scroll_offset()); |
| 1430 ScrollOffsetToProto(inputs_.overscroll, base->mutable_overscroll()); |
| 1410 | 1431 |
| 1411 // TODO(nyquist): Figure out what to do with CopyRequests. | 1432 // TODO(nyquist): Figure out what to do with CopyRequests. |
| 1412 // See crbug.com/570374. | 1433 // See crbug.com/570374. |
| 1413 | 1434 |
| 1414 RectToProto(inputs_.update_rect, base->mutable_update_rect()); | 1435 RectToProto(inputs_.update_rect, base->mutable_update_rect()); |
| 1415 | 1436 |
| 1416 // TODO(nyquist): Figure out what to do with ElementAnimations. | 1437 // TODO(nyquist): Figure out what to do with ElementAnimations. |
| 1417 // See crbug.com/570376. | 1438 // See crbug.com/570376. |
| 1418 | 1439 |
| 1419 inputs_.update_rect = gfx::Rect(); | 1440 inputs_.update_rect = gfx::Rect(); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1464 draw_blend_mode_ = SkXfermodeModeFromProto(base.draw_blend_mode()); | 1485 draw_blend_mode_ = SkXfermodeModeFromProto(base.draw_blend_mode()); |
| 1465 inputs_.use_parent_backface_visibility = | 1486 inputs_.use_parent_backface_visibility = |
| 1466 base.use_parent_backface_visibility(); | 1487 base.use_parent_backface_visibility(); |
| 1467 inputs_.transform = ProtoToTransform(base.transform()); | 1488 inputs_.transform = ProtoToTransform(base.transform()); |
| 1468 inputs_.sorting_context_id = base.sorting_context_id(); | 1489 inputs_.sorting_context_id = base.sorting_context_id(); |
| 1469 num_descendants_that_draw_content_ = base.num_descendants_that_draw_content(); | 1490 num_descendants_that_draw_content_ = base.num_descendants_that_draw_content(); |
| 1470 | 1491 |
| 1471 inputs_.scroll_clip_layer_id = base.scroll_clip_layer_id(); | 1492 inputs_.scroll_clip_layer_id = base.scroll_clip_layer_id(); |
| 1472 inputs_.user_scrollable_horizontal = base.user_scrollable_horizontal(); | 1493 inputs_.user_scrollable_horizontal = base.user_scrollable_horizontal(); |
| 1473 inputs_.user_scrollable_vertical = base.user_scrollable_vertical(); | 1494 inputs_.user_scrollable_vertical = base.user_scrollable_vertical(); |
| 1495 inputs_.can_overscroll = base.can_overscroll(); |
| 1474 | 1496 |
| 1475 inputs_.scroll_parent = | 1497 inputs_.scroll_parent = |
| 1476 base.scroll_parent_id() == INVALID_ID | 1498 base.scroll_parent_id() == INVALID_ID |
| 1477 ? nullptr | 1499 ? nullptr |
| 1478 : layer_tree_host_->LayerById(base.scroll_parent_id()); | 1500 : layer_tree_host_->LayerById(base.scroll_parent_id()); |
| 1479 | 1501 |
| 1480 // If there have been scroll children entries in previous deserializations, | 1502 // If there have been scroll children entries in previous deserializations, |
| 1481 // clear out the set. If there have been none, initialize the set of children. | 1503 // clear out the set. If there have been none, initialize the set of children. |
| 1482 // After this, the set is in the correct state to only add the new children. | 1504 // After this, the set is in the correct state to only add the new children. |
| 1483 // If the set of children has not changed, for now this code still rebuilds | 1505 // If the set of children has not changed, for now this code still rebuilds |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1506 clip_children_->clear(); | 1528 clip_children_->clear(); |
| 1507 else if (base.clip_children_ids_size() > 0) | 1529 else if (base.clip_children_ids_size() > 0) |
| 1508 clip_children_.reset(new std::set<Layer*>); | 1530 clip_children_.reset(new std::set<Layer*>); |
| 1509 for (int i = 0; i < base.clip_children_ids_size(); ++i) { | 1531 for (int i = 0; i < base.clip_children_ids_size(); ++i) { |
| 1510 int child_id = base.clip_children_ids(i); | 1532 int child_id = base.clip_children_ids(i); |
| 1511 scoped_refptr<Layer> child = layer_tree_host_->LayerById(child_id); | 1533 scoped_refptr<Layer> child = layer_tree_host_->LayerById(child_id); |
| 1512 clip_children_->insert(child.get()); | 1534 clip_children_->insert(child.get()); |
| 1513 } | 1535 } |
| 1514 | 1536 |
| 1515 inputs_.scroll_offset = ProtoToScrollOffset(base.scroll_offset()); | 1537 inputs_.scroll_offset = ProtoToScrollOffset(base.scroll_offset()); |
| 1538 inputs_.overscroll = ProtoToScrollOffset(base.overscroll()); |
| 1516 | 1539 |
| 1517 inputs_.update_rect.Union(ProtoToRect(base.update_rect())); | 1540 inputs_.update_rect.Union(ProtoToRect(base.update_rect())); |
| 1518 | 1541 |
| 1519 inputs_.has_will_change_transform_hint = | 1542 inputs_.has_will_change_transform_hint = |
| 1520 base.has_will_change_transform_hint(); | 1543 base.has_will_change_transform_hint(); |
| 1521 } | 1544 } |
| 1522 | 1545 |
| 1523 std::unique_ptr<LayerImpl> Layer::CreateLayerImpl(LayerTreeImpl* tree_impl) { | 1546 std::unique_ptr<LayerImpl> Layer::CreateLayerImpl(LayerTreeImpl* tree_impl) { |
| 1524 return LayerImpl::Create(tree_impl, inputs_.layer_id); | 1547 return LayerImpl::Create(tree_impl, inputs_.layer_id); |
| 1525 } | 1548 } |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1862 ->num_copy_requests_in_subtree; | 1885 ->num_copy_requests_in_subtree; |
| 1863 } | 1886 } |
| 1864 | 1887 |
| 1865 gfx::Transform Layer::screen_space_transform() const { | 1888 gfx::Transform Layer::screen_space_transform() const { |
| 1866 DCHECK_NE(transform_tree_index_, -1); | 1889 DCHECK_NE(transform_tree_index_, -1); |
| 1867 return draw_property_utils::ScreenSpaceTransform( | 1890 return draw_property_utils::ScreenSpaceTransform( |
| 1868 this, layer_tree_host_->property_trees()->transform_tree); | 1891 this, layer_tree_host_->property_trees()->transform_tree); |
| 1869 } | 1892 } |
| 1870 | 1893 |
| 1871 } // namespace cc | 1894 } // namespace cc |
| OLD | NEW |