| 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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 } | 90 } |
| 91 } | 91 } |
| 92 return true; | 92 return true; |
| 93 } | 93 } |
| 94 | 94 |
| 95 struct ConditionalClip { | 95 struct ConditionalClip { |
| 96 bool is_clipped; | 96 bool is_clipped; |
| 97 gfx::RectF clip_rect; | 97 gfx::RectF clip_rect; |
| 98 }; | 98 }; |
| 99 | 99 |
| 100 static ConditionalClip ComputeRectInTargetSpace( | 100 static ConditionalClip ComputeTargetRectInLocalSpace( |
| 101 gfx::RectF rect, | 101 gfx::RectF rect, |
| 102 const TransformTree& transform_tree, | 102 const TransformTree& transform_tree, |
| 103 int current_transform_id, | 103 int current_transform_id, |
| 104 int target_transform_id) { |
| 105 gfx::Transform current_to_target; |
| 106 if (!transform_tree.ComputeTransformWithSourceSublayerScale( |
| 107 current_transform_id, target_transform_id, ¤t_to_target)) |
| 108 // If transform is not invertible, cannot apply clip. |
| 109 return ConditionalClip{false, gfx::RectF()}; |
| 110 |
| 111 if (current_transform_id > target_transform_id) |
| 112 return ConditionalClip{true, // is_clipped. |
| 113 MathUtil::MapClippedRect(current_to_target, rect)}; |
| 114 |
| 115 return ConditionalClip{true, // is_clipped. |
| 116 MathUtil::ProjectClippedRect(current_to_target, rect)}; |
| 117 } |
| 118 |
| 119 static ConditionalClip ComputeLocalRectInTargetSpace( |
| 120 gfx::RectF rect, |
| 121 const TransformTree& transform_tree, |
| 122 int current_transform_id, |
| 104 int target_transform_id) { | 123 int target_transform_id) { |
| 105 gfx::Transform current_to_target; | 124 gfx::Transform current_to_target; |
| 106 if (!transform_tree.ComputeTransformWithDestinationSublayerScale( | 125 if (!transform_tree.ComputeTransformWithDestinationSublayerScale( |
| 107 current_transform_id, target_transform_id, ¤t_to_target)) | 126 current_transform_id, target_transform_id, ¤t_to_target)) |
| 108 // If transform is not invertible, cannot apply clip. | 127 // If transform is not invertible, cannot apply clip. |
| 109 return ConditionalClip{false, gfx::RectF()}; | 128 return ConditionalClip{false, gfx::RectF()}; |
| 129 |
| 110 if (current_transform_id > target_transform_id) | 130 if (current_transform_id > target_transform_id) |
| 111 return ConditionalClip{true, // is_clipped. | 131 return ConditionalClip{true, // is_clipped. |
| 112 MathUtil::MapClippedRect(current_to_target, rect)}; | 132 MathUtil::MapClippedRect(current_to_target, rect)}; |
| 113 | 133 |
| 114 return ConditionalClip{true, // is_clipped. | 134 return ConditionalClip{true, // is_clipped. |
| 115 MathUtil::ProjectClippedRect(current_to_target, rect)}; | 135 MathUtil::ProjectClippedRect(current_to_target, rect)}; |
| 116 } | 136 } |
| 117 | 137 |
| 118 static ConditionalClip ComputeCurrentClip(const ClipNode* clip_node, | 138 static ConditionalClip ComputeCurrentClip(const ClipNode* clip_node, |
| 119 const TransformTree& transform_tree, | 139 const TransformTree& transform_tree, |
| 120 int target_transform_id) { | 140 int target_transform_id) { |
| 121 if (clip_node->data.transform_id != target_transform_id) | 141 if (clip_node->data.transform_id != target_transform_id) |
| 122 return ComputeRectInTargetSpace(clip_node->data.clip, transform_tree, | 142 return ComputeLocalRectInTargetSpace(clip_node->data.clip, transform_tree, |
| 123 clip_node->data.transform_id, | 143 clip_node->data.transform_id, |
| 124 target_transform_id); | 144 target_transform_id); |
| 125 | 145 |
| 126 gfx::RectF current_clip = clip_node->data.clip; | 146 gfx::RectF current_clip = clip_node->data.clip; |
| 127 gfx::Vector2dF sublayer_scale = | 147 gfx::Vector2dF sublayer_scale = |
| 128 transform_tree.Node(target_transform_id)->data.sublayer_scale; | 148 transform_tree.Node(target_transform_id)->data.sublayer_scale; |
| 129 if (sublayer_scale.x() > 0 && sublayer_scale.y() > 0) | 149 if (sublayer_scale.x() > 0 && sublayer_scale.y() > 0) |
| 130 current_clip.Scale(sublayer_scale.x(), sublayer_scale.y()); | 150 current_clip.Scale(sublayer_scale.x(), sublayer_scale.y()); |
| 131 return ConditionalClip{true /* is_clipped */, current_clip}; | 151 return ConditionalClip{true /* is_clipped */, current_clip}; |
| 132 } | 152 } |
| 133 | 153 |
| 134 static ConditionalClip ComputeAccumulatedClip( | 154 static ConditionalClip ComputeAccumulatedClip( |
| (...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 if (!accumulated_clip_rect.is_clipped) { | 328 if (!accumulated_clip_rect.is_clipped) { |
| 309 layer->set_visible_layer_rect(gfx::Rect(layer_bounds)); | 329 layer->set_visible_layer_rect(gfx::Rect(layer_bounds)); |
| 310 continue; | 330 continue; |
| 311 } | 331 } |
| 312 | 332 |
| 313 gfx::RectF accumulated_clip_in_copy_request_space = | 333 gfx::RectF accumulated_clip_in_copy_request_space = |
| 314 accumulated_clip_rect.clip_rect; | 334 accumulated_clip_rect.clip_rect; |
| 315 | 335 |
| 316 const EffectNode* copy_request_effect_node = | 336 const EffectNode* copy_request_effect_node = |
| 317 effect_tree.Node(effect_ancestor_with_copy_request); | 337 effect_tree.Node(effect_ancestor_with_copy_request); |
| 318 ConditionalClip clip_in_layer_space = ComputeRectInTargetSpace( | 338 ConditionalClip clip_in_layer_space = ComputeTargetRectInLocalSpace( |
| 319 accumulated_clip_in_copy_request_space, transform_tree, | 339 accumulated_clip_in_copy_request_space, transform_tree, |
| 320 copy_request_effect_node->data.transform_id, | 340 copy_request_effect_node->data.transform_id, |
| 321 layer->transform_tree_index()); | 341 layer->transform_tree_index()); |
| 342 |
| 322 if (clip_in_layer_space.is_clipped) { | 343 if (clip_in_layer_space.is_clipped) { |
| 323 gfx::RectF clip_rect = clip_in_layer_space.clip_rect; | 344 gfx::RectF clip_rect = clip_in_layer_space.clip_rect; |
| 324 clip_rect.Offset(-layer->offset_to_transform_parent()); | 345 clip_rect.Offset(-layer->offset_to_transform_parent()); |
| 325 gfx::Rect visible_rect = gfx::ToEnclosingRect(clip_rect); | 346 gfx::Rect visible_rect = gfx::ToEnclosingRect(clip_rect); |
| 326 visible_rect.Intersect(gfx::Rect(layer_bounds)); | 347 visible_rect.Intersect(gfx::Rect(layer_bounds)); |
| 327 layer->set_visible_layer_rect(visible_rect); | 348 layer->set_visible_layer_rect(visible_rect); |
| 328 } else { | 349 } else { |
| 329 layer->set_visible_layer_rect(gfx::Rect(layer_bounds)); | 350 layer->set_visible_layer_rect(gfx::Rect(layer_bounds)); |
| 330 } | 351 } |
| 331 continue; | 352 continue; |
| (...skipping 1029 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1361 void UpdateElasticOverscroll(PropertyTrees* property_trees, | 1382 void UpdateElasticOverscroll(PropertyTrees* property_trees, |
| 1362 const Layer* overscroll_elasticity_layer, | 1383 const Layer* overscroll_elasticity_layer, |
| 1363 const gfx::Vector2dF& elastic_overscroll) { | 1384 const gfx::Vector2dF& elastic_overscroll) { |
| 1364 UpdateElasticOverscrollInternal(property_trees, overscroll_elasticity_layer, | 1385 UpdateElasticOverscrollInternal(property_trees, overscroll_elasticity_layer, |
| 1365 elastic_overscroll); | 1386 elastic_overscroll); |
| 1366 } | 1387 } |
| 1367 | 1388 |
| 1368 } // namespace draw_property_utils | 1389 } // namespace draw_property_utils |
| 1369 | 1390 |
| 1370 } // namespace cc | 1391 } // namespace cc |
| OLD | NEW |