| 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 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 if (!accumulated_clip_rect.is_clipped) { | 321 if (!accumulated_clip_rect.is_clipped) { |
| 302 layer->set_visible_layer_rect(gfx::Rect(layer_bounds)); | 322 layer->set_visible_layer_rect(gfx::Rect(layer_bounds)); |
| 303 continue; | 323 continue; |
| 304 } | 324 } |
| 305 | 325 |
| 306 gfx::RectF accumulated_clip_in_copy_request_space = | 326 gfx::RectF accumulated_clip_in_copy_request_space = |
| 307 accumulated_clip_rect.clip_rect; | 327 accumulated_clip_rect.clip_rect; |
| 308 | 328 |
| 309 const EffectNode* copy_request_effect_node = | 329 const EffectNode* copy_request_effect_node = |
| 310 effect_tree.Node(effect_ancestor_with_copy_request); | 330 effect_tree.Node(effect_ancestor_with_copy_request); |
| 311 ConditionalClip clip_in_layer_space = ComputeRectInTargetSpace( | 331 ConditionalClip clip_in_layer_space = ComputeTargetRectInLocalSpace( |
| 312 accumulated_clip_in_copy_request_space, transform_tree, | 332 accumulated_clip_in_copy_request_space, transform_tree, |
| 313 copy_request_effect_node->data.transform_id, | 333 copy_request_effect_node->data.transform_id, |
| 314 layer->transform_tree_index()); | 334 layer->transform_tree_index()); |
| 335 |
| 315 if (clip_in_layer_space.is_clipped) { | 336 if (clip_in_layer_space.is_clipped) { |
| 316 gfx::RectF clip_rect = clip_in_layer_space.clip_rect; | 337 gfx::RectF clip_rect = clip_in_layer_space.clip_rect; |
| 317 clip_rect.Offset(-layer->offset_to_transform_parent()); | 338 clip_rect.Offset(-layer->offset_to_transform_parent()); |
| 318 gfx::Rect visible_rect = gfx::ToEnclosingRect(clip_rect); | 339 gfx::Rect visible_rect = gfx::ToEnclosingRect(clip_rect); |
| 319 visible_rect.Intersect(gfx::Rect(layer_bounds)); | 340 visible_rect.Intersect(gfx::Rect(layer_bounds)); |
| 320 layer->set_visible_layer_rect(visible_rect); | 341 layer->set_visible_layer_rect(visible_rect); |
| 321 } else { | 342 } else { |
| 322 layer->set_visible_layer_rect(gfx::Rect(layer_bounds)); | 343 layer->set_visible_layer_rect(gfx::Rect(layer_bounds)); |
| 323 } | 344 } |
| 324 continue; | 345 continue; |
| (...skipping 1040 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1365 void UpdateElasticOverscroll(PropertyTrees* property_trees, | 1386 void UpdateElasticOverscroll(PropertyTrees* property_trees, |
| 1366 const Layer* overscroll_elasticity_layer, | 1387 const Layer* overscroll_elasticity_layer, |
| 1367 const gfx::Vector2dF& elastic_overscroll) { | 1388 const gfx::Vector2dF& elastic_overscroll) { |
| 1368 UpdateElasticOverscrollInternal(property_trees, overscroll_elasticity_layer, | 1389 UpdateElasticOverscrollInternal(property_trees, overscroll_elasticity_layer, |
| 1369 elastic_overscroll); | 1390 elastic_overscroll); |
| 1370 } | 1391 } |
| 1371 | 1392 |
| 1372 } // namespace draw_property_utils | 1393 } // namespace draw_property_utils |
| 1373 | 1394 |
| 1374 } // namespace cc | 1395 } // namespace cc |
| OLD | NEW |