| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/trees/draw_property_utils.h" | 5 #include "cc/trees/draw_property_utils.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 target_effect_node->id, &clip_to_target)) { | 70 target_effect_node->id, &clip_to_target)) { |
| 71 const EffectNode* source_node = | 71 const EffectNode* source_node = |
| 72 effect_tree.Node(clip_node->target_effect_id); | 72 effect_tree.Node(clip_node->target_effect_id); |
| 73 ConcatInverseSurfaceContentsScale(source_node, &clip_to_target); | 73 ConcatInverseSurfaceContentsScale(source_node, &clip_to_target); |
| 74 *clip_rect_in_target_space = | 74 *clip_rect_in_target_space = |
| 75 MathUtil::MapClippedRect(clip_to_target, clip_from_clip_node); | 75 MathUtil::MapClippedRect(clip_to_target, clip_from_clip_node); |
| 76 } else { | 76 } else { |
| 77 return false; | 77 return false; |
| 78 } | 78 } |
| 79 } else { | 79 } else { |
| 80 if (property_trees->ComputeTransformFromTarget( | 80 if (property_trees->GetFromTarget( |
| 81 target_node_id, clip_node->target_effect_id, &clip_to_target)) { | 81 target_node_id, clip_node->target_effect_id, &clip_to_target)) { |
| 82 PostConcatSurfaceContentsScale(target_effect_node, &clip_to_target); |
| 82 *clip_rect_in_target_space = | 83 *clip_rect_in_target_space = |
| 83 MathUtil::ProjectClippedRect(clip_to_target, clip_from_clip_node); | 84 MathUtil::ProjectClippedRect(clip_to_target, clip_from_clip_node); |
| 84 } else { | 85 } else { |
| 85 return false; | 86 return false; |
| 86 } | 87 } |
| 87 } | 88 } |
| 88 return true; | 89 return true; |
| 89 } | 90 } |
| 90 | 91 |
| 91 struct ConditionalClip { | 92 struct ConditionalClip { |
| 92 bool is_clipped; | 93 bool is_clipped; |
| 93 gfx::RectF clip_rect; | 94 gfx::RectF clip_rect; |
| 94 }; | 95 }; |
| 95 | 96 |
| 96 static ConditionalClip ComputeTargetRectInLocalSpace( | 97 static ConditionalClip ComputeTargetRectInLocalSpace( |
| 97 gfx::RectF rect, | 98 gfx::RectF rect, |
| 98 const PropertyTrees* property_trees, | 99 const PropertyTrees* property_trees, |
| 99 int target_transform_id, | 100 int target_transform_id, |
| 100 int local_transform_id, | 101 int local_transform_id, |
| 101 const int target_effect_id) { | 102 const int target_effect_id) { |
| 102 const EffectTree& effect_tree = property_trees->effect_tree; | |
| 103 gfx::Transform target_to_local; | 103 gfx::Transform target_to_local; |
| 104 bool success = property_trees->ComputeTransformFromTarget( | 104 bool success = property_trees->GetFromTarget( |
| 105 local_transform_id, target_effect_id, &target_to_local); | 105 local_transform_id, target_effect_id, &target_to_local); |
| 106 if (!success) | 106 if (!success) |
| 107 // If transform is not invertible, cannot apply clip. | 107 // If transform is not invertible, cannot apply clip. |
| 108 return ConditionalClip{false, gfx::RectF()}; | 108 return ConditionalClip{false, gfx::RectF()}; |
| 109 const EffectNode* target_effect_node = effect_tree.Node(target_effect_id); | |
| 110 ConcatInverseSurfaceContentsScale(target_effect_node, &target_to_local); | |
| 111 | 109 |
| 112 if (target_transform_id > local_transform_id) | 110 if (target_transform_id > local_transform_id) |
| 113 return ConditionalClip{true, // is_clipped. | 111 return ConditionalClip{true, // is_clipped. |
| 114 MathUtil::MapClippedRect(target_to_local, rect)}; | 112 MathUtil::MapClippedRect(target_to_local, rect)}; |
| 115 | 113 |
| 116 return ConditionalClip{true, // is_clipped. | 114 return ConditionalClip{true, // is_clipped. |
| 117 MathUtil::ProjectClippedRect(target_to_local, rect)}; | 115 MathUtil::ProjectClippedRect(target_to_local, rect)}; |
| 118 } | 116 } |
| 119 | 117 |
| 120 static ConditionalClip ConvertRectBetweenSurfaceSpaces( | 118 static ConditionalClip ConvertRectBetweenSurfaceSpaces( |
| (...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 } | 534 } |
| 537 | 535 |
| 538 combined_clip_rect_in_target_space.Intersect( | 536 combined_clip_rect_in_target_space.Intersect( |
| 539 layer_content_bounds_in_target_space); | 537 layer_content_bounds_in_target_space); |
| 540 if (combined_clip_rect_in_target_space.IsEmpty()) { | 538 if (combined_clip_rect_in_target_space.IsEmpty()) { |
| 541 layer->set_visible_layer_rect(gfx::Rect()); | 539 layer->set_visible_layer_rect(gfx::Rect()); |
| 542 continue; | 540 continue; |
| 543 } | 541 } |
| 544 | 542 |
| 545 gfx::Transform target_to_layer; | 543 gfx::Transform target_to_layer; |
| 546 if (transform_node->ancestors_are_invertible) { | 544 const EffectNode* target_effect_node = |
| 547 property_trees->GetFromTarget(transform_node->id, | 545 ContentsTargetEffectNode(layer->effect_tree_index(), effect_tree); |
| 548 layer->render_target_effect_tree_index(), | 546 bool success = property_trees->GetFromTarget( |
| 549 &target_to_layer); | 547 transform_node->id, target_effect_node->id, &target_to_layer); |
| 550 } else { | 548 if (!success) { |
| 551 const EffectNode* target_effect_node = | 549 // An animated singular transform may become non-singular during the |
| 552 ContentsTargetEffectNode(layer->effect_tree_index(), effect_tree); | 550 // animation, so we still need to compute a visible rect. In this |
| 553 bool success = property_trees->ComputeTransformFromTarget( | 551 // situation, we treat the entire layer as visible. |
| 554 transform_node->id, target_effect_node->id, &target_to_layer); | 552 layer->set_visible_layer_rect(gfx::Rect(layer_bounds)); |
| 555 if (!success) { | 553 continue; |
| 556 // An animated singular transform may become non-singular during the | |
| 557 // animation, so we still need to compute a visible rect. In this | |
| 558 // situation, we treat the entire layer as visible. | |
| 559 layer->set_visible_layer_rect(gfx::Rect(layer_bounds)); | |
| 560 continue; | |
| 561 } | |
| 562 ConcatInverseSurfaceContentsScale(target_effect_node, &target_to_layer); | |
| 563 } | 554 } |
| 564 gfx::Transform target_to_content; | 555 gfx::Transform target_to_content; |
| 565 target_to_content.Translate(-layer->offset_to_transform_parent().x(), | 556 target_to_content.Translate(-layer->offset_to_transform_parent().x(), |
| 566 -layer->offset_to_transform_parent().y()); | 557 -layer->offset_to_transform_parent().y()); |
| 567 target_to_content.PreconcatTransform(target_to_layer); | 558 target_to_content.PreconcatTransform(target_to_layer); |
| 568 | 559 |
| 569 gfx::Rect visible_rect = gfx::ToEnclosingRect(MathUtil::ProjectClippedRect( | 560 gfx::Rect visible_rect = gfx::ToEnclosingRect(MathUtil::ProjectClippedRect( |
| 570 target_to_content, combined_clip_rect_in_target_space)); | 561 target_to_content, combined_clip_rect_in_target_space)); |
| 571 visible_rect.Intersect(gfx::Rect(layer_bounds)); | 562 visible_rect.Intersect(gfx::Rect(layer_bounds)); |
| 572 layer->set_visible_layer_rect(visible_rect); | 563 layer->set_visible_layer_rect(visible_rect); |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 820 // must combine clips. For each clip node, we save the clip rects in its | 811 // must combine clips. For each clip node, we save the clip rects in its |
| 821 // target space. So, we need to get the ancestor clip rect in the current | 812 // target space. So, we need to get the ancestor clip rect in the current |
| 822 // clip node's target space. | 813 // clip node's target space. |
| 823 gfx::RectF parent_combined_clip_in_target_space = | 814 gfx::RectF parent_combined_clip_in_target_space = |
| 824 parent_clip_node->combined_clip_in_target_space; | 815 parent_clip_node->combined_clip_in_target_space; |
| 825 gfx::RectF parent_clip_in_target_space = | 816 gfx::RectF parent_clip_in_target_space = |
| 826 parent_clip_node->clip_in_target_space; | 817 parent_clip_node->clip_in_target_space; |
| 827 if (parent_target_transform_node && | 818 if (parent_target_transform_node && |
| 828 parent_target_transform_node->id != clip_node->target_transform_id && | 819 parent_target_transform_node->id != clip_node->target_transform_id && |
| 829 non_root_surfaces_enabled) { | 820 non_root_surfaces_enabled) { |
| 830 success &= property_trees->ComputeTransformFromTarget( | 821 success &= property_trees->GetFromTarget( |
| 831 clip_node->target_transform_id, parent_clip_node->target_effect_id, | 822 clip_node->target_transform_id, parent_clip_node->target_effect_id, |
| 832 &parent_to_current); | 823 &parent_to_current); |
| 833 const EffectNode* target_effect_node = | 824 const EffectNode* target_effect_node = |
| 834 effect_tree.Node(clip_node->target_effect_id); | 825 effect_tree.Node(clip_node->target_effect_id); |
| 835 PostConcatSurfaceContentsScale(target_effect_node, &parent_to_current); | 826 PostConcatSurfaceContentsScale(target_effect_node, &parent_to_current); |
| 836 const EffectNode* parent_target_effect_node = | |
| 837 effect_tree.Node(parent_clip_node->target_effect_id); | |
| 838 ConcatInverseSurfaceContentsScale(parent_target_effect_node, | |
| 839 &parent_to_current); | |
| 840 // If we can't compute a transform, it's because we had to use the inverse | 827 // If we can't compute a transform, it's because we had to use the inverse |
| 841 // of a singular transform. We won't draw in this case, so there's no need | 828 // of a singular transform. We won't draw in this case, so there's no need |
| 842 // to compute clips. | 829 // to compute clips. |
| 843 if (!success) | 830 if (!success) |
| 844 continue; | 831 continue; |
| 845 parent_combined_clip_in_target_space = MathUtil::ProjectClippedRect( | 832 parent_combined_clip_in_target_space = MathUtil::ProjectClippedRect( |
| 846 parent_to_current, parent_clip_node->combined_clip_in_target_space); | 833 parent_to_current, parent_clip_node->combined_clip_in_target_space); |
| 847 if (clip_node->clip_type == ClipNode::ClipType::EXPANDS_CLIP) { | 834 if (clip_node->clip_type == ClipNode::ClipType::EXPANDS_CLIP) { |
| 848 parent_combined_clip_in_target_space = | 835 parent_combined_clip_in_target_space = |
| 849 gfx::RectF(clip_node->clip_expander->MapRectReverse( | 836 gfx::RectF(clip_node->clip_expander->MapRectReverse( |
| (...skipping 659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1509 void UpdateElasticOverscroll(PropertyTrees* property_trees, | 1496 void UpdateElasticOverscroll(PropertyTrees* property_trees, |
| 1510 const Layer* overscroll_elasticity_layer, | 1497 const Layer* overscroll_elasticity_layer, |
| 1511 const gfx::Vector2dF& elastic_overscroll) { | 1498 const gfx::Vector2dF& elastic_overscroll) { |
| 1512 UpdateElasticOverscrollInternal(property_trees, overscroll_elasticity_layer, | 1499 UpdateElasticOverscrollInternal(property_trees, overscroll_elasticity_layer, |
| 1513 elastic_overscroll); | 1500 elastic_overscroll); |
| 1514 } | 1501 } |
| 1515 | 1502 |
| 1516 } // namespace draw_property_utils | 1503 } // namespace draw_property_utils |
| 1517 | 1504 |
| 1518 } // namespace cc | 1505 } // namespace cc |
| OLD | NEW |