| 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() != ScrollTree::kInvalidNodeId && scrollable()) | 785 if (scroll_tree_index() != ScrollTree::kInvalidNodeId && 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() != ScrollTree::kInvalidNodeId && scrollable()) | 830 if (scroll_tree_index() != ScrollTree::kInvalidNodeId && 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 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1164 should_flatten_transform_from_property_tree_); | 1182 should_flatten_transform_from_property_tree_); |
| 1165 layer->set_draw_blend_mode(draw_blend_mode_); | 1183 layer->set_draw_blend_mode(draw_blend_mode_); |
| 1166 layer->SetUseParentBackfaceVisibility(inputs_.use_parent_backface_visibility); | 1184 layer->SetUseParentBackfaceVisibility(inputs_.use_parent_backface_visibility); |
| 1167 layer->SetUseLocalTransformForBackfaceVisibility( | 1185 layer->SetUseLocalTransformForBackfaceVisibility( |
| 1168 use_local_transform_for_backface_visibility_); | 1186 use_local_transform_for_backface_visibility_); |
| 1169 layer->SetShouldCheckBackfaceVisibility(should_check_backface_visibility_); | 1187 layer->SetShouldCheckBackfaceVisibility(should_check_backface_visibility_); |
| 1170 if (!TransformIsAnimating()) | 1188 if (!TransformIsAnimating()) |
| 1171 layer->SetTransform(inputs_.transform); | 1189 layer->SetTransform(inputs_.transform); |
| 1172 layer->Set3dSortingContextId(inputs_.sorting_context_id); | 1190 layer->Set3dSortingContextId(inputs_.sorting_context_id); |
| 1173 | 1191 |
| 1174 layer->SetScrollClipLayer(inputs_.scroll_clip_layer_id); | 1192 layer->SetScrollClipAndCanOverscroll(inputs_.scroll_clip_layer_id, |
| 1193 inputs_.can_overscroll); |
| 1175 layer->set_user_scrollable_horizontal(inputs_.user_scrollable_horizontal); | 1194 layer->set_user_scrollable_horizontal(inputs_.user_scrollable_horizontal); |
| 1176 layer->set_user_scrollable_vertical(inputs_.user_scrollable_vertical); | 1195 layer->set_user_scrollable_vertical(inputs_.user_scrollable_vertical); |
| 1177 layer->SetElementId(inputs_.element_id); | 1196 layer->SetElementId(inputs_.element_id); |
| 1178 layer->SetMutableProperties(inputs_.mutable_properties); | 1197 layer->SetMutableProperties(inputs_.mutable_properties); |
| 1179 | 1198 |
| 1180 // When a scroll offset animation is interrupted the new scroll position on | 1199 // When a scroll offset animation is interrupted the new scroll position on |
| 1181 // the pending tree will clobber any impl-side scrolling occuring on the | 1200 // the pending tree will clobber any impl-side scrolling occuring on the |
| 1182 // active tree. To do so, avoid scrolling the pending tree along with it | 1201 // active tree. To do so, avoid scrolling the pending tree along with it |
| 1183 // instead of trying to undo that scrolling later. | 1202 // instead of trying to undo that scrolling later. |
| 1184 if (ScrollOffsetAnimationWasInterrupted()) | 1203 if (ScrollOffsetAnimationWasInterrupted()) |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1388 base->set_use_parent_backface_visibility( | 1407 base->set_use_parent_backface_visibility( |
| 1389 inputs_.use_parent_backface_visibility); | 1408 inputs_.use_parent_backface_visibility); |
| 1390 TransformToProto(inputs_.transform, base->mutable_transform()); | 1409 TransformToProto(inputs_.transform, base->mutable_transform()); |
| 1391 base->set_sorting_context_id(inputs_.sorting_context_id); | 1410 base->set_sorting_context_id(inputs_.sorting_context_id); |
| 1392 base->set_num_descendants_that_draw_content( | 1411 base->set_num_descendants_that_draw_content( |
| 1393 num_descendants_that_draw_content_); | 1412 num_descendants_that_draw_content_); |
| 1394 | 1413 |
| 1395 base->set_scroll_clip_layer_id(inputs_.scroll_clip_layer_id); | 1414 base->set_scroll_clip_layer_id(inputs_.scroll_clip_layer_id); |
| 1396 base->set_user_scrollable_horizontal(inputs_.user_scrollable_horizontal); | 1415 base->set_user_scrollable_horizontal(inputs_.user_scrollable_horizontal); |
| 1397 base->set_user_scrollable_vertical(inputs_.user_scrollable_vertical); | 1416 base->set_user_scrollable_vertical(inputs_.user_scrollable_vertical); |
| 1417 base->set_can_overscroll(inputs_.can_overscroll); |
| 1398 | 1418 |
| 1399 int scroll_parent_id = | 1419 int scroll_parent_id = |
| 1400 inputs_.scroll_parent ? inputs_.scroll_parent->id() : INVALID_ID; | 1420 inputs_.scroll_parent ? inputs_.scroll_parent->id() : INVALID_ID; |
| 1401 base->set_scroll_parent_id(scroll_parent_id); | 1421 base->set_scroll_parent_id(scroll_parent_id); |
| 1402 | 1422 |
| 1403 if (scroll_children_) { | 1423 if (scroll_children_) { |
| 1404 for (auto* child : *scroll_children_) | 1424 for (auto* child : *scroll_children_) |
| 1405 base->add_scroll_children_ids(child->id()); | 1425 base->add_scroll_children_ids(child->id()); |
| 1406 } | 1426 } |
| 1407 | 1427 |
| 1408 int clip_parent_id = | 1428 int clip_parent_id = |
| 1409 inputs_.clip_parent ? inputs_.clip_parent->id() : INVALID_ID; | 1429 inputs_.clip_parent ? inputs_.clip_parent->id() : INVALID_ID; |
| 1410 base->set_clip_parent_id(clip_parent_id); | 1430 base->set_clip_parent_id(clip_parent_id); |
| 1411 | 1431 |
| 1412 if (clip_children_) { | 1432 if (clip_children_) { |
| 1413 for (auto* child : *clip_children_) | 1433 for (auto* child : *clip_children_) |
| 1414 base->add_clip_children_ids(child->id()); | 1434 base->add_clip_children_ids(child->id()); |
| 1415 } | 1435 } |
| 1416 | 1436 |
| 1417 ScrollOffsetToProto(inputs_.scroll_offset, base->mutable_scroll_offset()); | 1437 ScrollOffsetToProto(inputs_.scroll_offset, base->mutable_scroll_offset()); |
| 1438 ScrollOffsetToProto(inputs_.overscroll, base->mutable_overscroll()); |
| 1418 | 1439 |
| 1419 // TODO(nyquist): Figure out what to do with CopyRequests. | 1440 // TODO(nyquist): Figure out what to do with CopyRequests. |
| 1420 // See crbug.com/570374. | 1441 // See crbug.com/570374. |
| 1421 | 1442 |
| 1422 RectToProto(inputs_.update_rect, base->mutable_update_rect()); | 1443 RectToProto(inputs_.update_rect, base->mutable_update_rect()); |
| 1423 | 1444 |
| 1424 // TODO(nyquist): Figure out what to do with ElementAnimations. | 1445 // TODO(nyquist): Figure out what to do with ElementAnimations. |
| 1425 // See crbug.com/570376. | 1446 // See crbug.com/570376. |
| 1426 | 1447 |
| 1427 inputs_.update_rect = gfx::Rect(); | 1448 inputs_.update_rect = gfx::Rect(); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1472 draw_blend_mode_ = SkXfermodeModeFromProto(base.draw_blend_mode()); | 1493 draw_blend_mode_ = SkXfermodeModeFromProto(base.draw_blend_mode()); |
| 1473 inputs_.use_parent_backface_visibility = | 1494 inputs_.use_parent_backface_visibility = |
| 1474 base.use_parent_backface_visibility(); | 1495 base.use_parent_backface_visibility(); |
| 1475 inputs_.transform = ProtoToTransform(base.transform()); | 1496 inputs_.transform = ProtoToTransform(base.transform()); |
| 1476 inputs_.sorting_context_id = base.sorting_context_id(); | 1497 inputs_.sorting_context_id = base.sorting_context_id(); |
| 1477 num_descendants_that_draw_content_ = base.num_descendants_that_draw_content(); | 1498 num_descendants_that_draw_content_ = base.num_descendants_that_draw_content(); |
| 1478 | 1499 |
| 1479 inputs_.scroll_clip_layer_id = base.scroll_clip_layer_id(); | 1500 inputs_.scroll_clip_layer_id = base.scroll_clip_layer_id(); |
| 1480 inputs_.user_scrollable_horizontal = base.user_scrollable_horizontal(); | 1501 inputs_.user_scrollable_horizontal = base.user_scrollable_horizontal(); |
| 1481 inputs_.user_scrollable_vertical = base.user_scrollable_vertical(); | 1502 inputs_.user_scrollable_vertical = base.user_scrollable_vertical(); |
| 1503 inputs_.can_overscroll = base.can_overscroll(); |
| 1482 | 1504 |
| 1483 inputs_.scroll_parent = | 1505 inputs_.scroll_parent = |
| 1484 base.scroll_parent_id() == INVALID_ID | 1506 base.scroll_parent_id() == INVALID_ID |
| 1485 ? nullptr | 1507 ? nullptr |
| 1486 : layer_tree_host_->LayerById(base.scroll_parent_id()); | 1508 : layer_tree_host_->LayerById(base.scroll_parent_id()); |
| 1487 | 1509 |
| 1488 // If there have been scroll children entries in previous deserializations, | 1510 // If there have been scroll children entries in previous deserializations, |
| 1489 // clear out the set. If there have been none, initialize the set of children. | 1511 // clear out the set. If there have been none, initialize the set of children. |
| 1490 // After this, the set is in the correct state to only add the new children. | 1512 // After this, the set is in the correct state to only add the new children. |
| 1491 // If the set of children has not changed, for now this code still rebuilds | 1513 // If the set of children has not changed, for now this code still rebuilds |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1514 clip_children_->clear(); | 1536 clip_children_->clear(); |
| 1515 else if (base.clip_children_ids_size() > 0) | 1537 else if (base.clip_children_ids_size() > 0) |
| 1516 clip_children_.reset(new std::set<Layer*>); | 1538 clip_children_.reset(new std::set<Layer*>); |
| 1517 for (int i = 0; i < base.clip_children_ids_size(); ++i) { | 1539 for (int i = 0; i < base.clip_children_ids_size(); ++i) { |
| 1518 int child_id = base.clip_children_ids(i); | 1540 int child_id = base.clip_children_ids(i); |
| 1519 scoped_refptr<Layer> child = layer_tree_host_->LayerById(child_id); | 1541 scoped_refptr<Layer> child = layer_tree_host_->LayerById(child_id); |
| 1520 clip_children_->insert(child.get()); | 1542 clip_children_->insert(child.get()); |
| 1521 } | 1543 } |
| 1522 | 1544 |
| 1523 inputs_.scroll_offset = ProtoToScrollOffset(base.scroll_offset()); | 1545 inputs_.scroll_offset = ProtoToScrollOffset(base.scroll_offset()); |
| 1546 inputs_.overscroll = ProtoToScrollOffset(base.overscroll()); |
| 1524 | 1547 |
| 1525 inputs_.update_rect.Union(ProtoToRect(base.update_rect())); | 1548 inputs_.update_rect.Union(ProtoToRect(base.update_rect())); |
| 1526 | 1549 |
| 1527 inputs_.has_will_change_transform_hint = | 1550 inputs_.has_will_change_transform_hint = |
| 1528 base.has_will_change_transform_hint(); | 1551 base.has_will_change_transform_hint(); |
| 1529 } | 1552 } |
| 1530 | 1553 |
| 1531 std::unique_ptr<LayerImpl> Layer::CreateLayerImpl(LayerTreeImpl* tree_impl) { | 1554 std::unique_ptr<LayerImpl> Layer::CreateLayerImpl(LayerTreeImpl* tree_impl) { |
| 1532 return LayerImpl::Create(tree_impl, inputs_.layer_id); | 1555 return LayerImpl::Create(tree_impl, inputs_.layer_id); |
| 1533 } | 1556 } |
| (...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1870 ->num_copy_requests_in_subtree; | 1893 ->num_copy_requests_in_subtree; |
| 1871 } | 1894 } |
| 1872 | 1895 |
| 1873 gfx::Transform Layer::screen_space_transform() const { | 1896 gfx::Transform Layer::screen_space_transform() const { |
| 1874 DCHECK_NE(transform_tree_index_, TransformTree::kInvalidNodeId); | 1897 DCHECK_NE(transform_tree_index_, TransformTree::kInvalidNodeId); |
| 1875 return draw_property_utils::ScreenSpaceTransform( | 1898 return draw_property_utils::ScreenSpaceTransform( |
| 1876 this, layer_tree_host_->property_trees()->transform_tree); | 1899 this, layer_tree_host_->property_trees()->transform_tree); |
| 1877 } | 1900 } |
| 1878 | 1901 |
| 1879 } // namespace cc | 1902 } // namespace cc |
| OLD | NEW |