| 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 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 layer->set_visible_layer_rect(visible_rect); | 390 layer->set_visible_layer_rect(visible_rect); |
| 391 } else { | 391 } else { |
| 392 layer->set_visible_layer_rect(gfx::Rect(layer_bounds)); | 392 layer->set_visible_layer_rect(gfx::Rect(layer_bounds)); |
| 393 } | 393 } |
| 394 continue; | 394 continue; |
| 395 } | 395 } |
| 396 | 396 |
| 397 // When both the layer and the target are unclipped, we only have to apply | 397 // When both the layer and the target are unclipped, we only have to apply |
| 398 // the viewport clip. | 398 // the viewport clip. |
| 399 const bool fully_visible = | 399 const bool fully_visible = |
| 400 !clip_node->layers_are_clipped && !clip_node->target_is_clipped; | 400 !clip_node->layers_are_clipped && |
| 401 !effect_tree.Node(clip_node->target_effect_id)->surface_is_clipped; |
| 401 | 402 |
| 402 if (fully_visible) { | 403 if (fully_visible) { |
| 403 if (!transform_node->ancestors_are_invertible) { | 404 if (!transform_node->ancestors_are_invertible) { |
| 404 // An animated singular transform may become non-singular during the | 405 // An animated singular transform may become non-singular during the |
| 405 // animation, so we still need to compute a visible rect. In this | 406 // animation, so we still need to compute a visible rect. In this |
| 406 // situation, we treat the entire layer as visible. | 407 // situation, we treat the entire layer as visible. |
| 407 layer->set_visible_layer_rect(gfx::Rect(layer_bounds)); | 408 layer->set_visible_layer_rect(gfx::Rect(layer_bounds)); |
| 408 } else { | 409 } else { |
| 409 gfx::Transform from_screen; | 410 gfx::Transform from_screen; |
| 410 from_screen.Translate(-layer->offset_to_transform_parent().x(), | 411 from_screen.Translate(-layer->offset_to_transform_parent().x(), |
| (...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 741 clip_node->clip_in_target_space = clip_node->clip; | 742 clip_node->clip_in_target_space = clip_node->clip; |
| 742 clip_node->combined_clip_in_target_space = clip_node->clip; | 743 clip_node->combined_clip_in_target_space = clip_node->clip; |
| 743 continue; | 744 continue; |
| 744 } | 745 } |
| 745 const TransformTree& transform_tree = property_trees->transform_tree; | 746 const TransformTree& transform_tree = property_trees->transform_tree; |
| 746 const EffectTree& effect_tree = property_trees->effect_tree; | 747 const EffectTree& effect_tree = property_trees->effect_tree; |
| 747 const TransformNode* transform_node = | 748 const TransformNode* transform_node = |
| 748 transform_tree.Node(clip_node->transform_id); | 749 transform_tree.Node(clip_node->transform_id); |
| 749 ClipNode* parent_clip_node = clip_tree->parent(clip_node); | 750 ClipNode* parent_clip_node = clip_tree->parent(clip_node); |
| 750 | 751 |
| 752 bool target_is_clipped = |
| 753 effect_tree.Node(clip_node->target_effect_id)->surface_is_clipped; |
| 754 |
| 751 gfx::Transform parent_to_current; | 755 gfx::Transform parent_to_current; |
| 752 const TransformNode* parent_target_transform_node = | 756 const TransformNode* parent_target_transform_node = |
| 753 transform_tree.Node(parent_clip_node->target_transform_id); | 757 transform_tree.Node(parent_clip_node->target_transform_id); |
| 754 bool success = true; | 758 bool success = true; |
| 755 | 759 |
| 756 // Clips must be combined in target space. We cannot, for example, combine | 760 // Clips must be combined in target space. We cannot, for example, combine |
| 757 // clips in the space of the child clip. The reason is non-affine | 761 // clips in the space of the child clip. The reason is non-affine |
| 758 // transforms. Say we have the following tree T->A->B->C, and B clips C, but | 762 // transforms. Say we have the following tree T->A->B->C, and B clips C, but |
| 759 // draw into target T. It may be the case that A applies a perspective | 763 // draw into target T. It may be the case that A applies a perspective |
| 760 // transform, and B and C are at different z positions. When projected into | 764 // transform, and B and C are at different z positions. When projected into |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 800 gfx::Transform to_target; | 804 gfx::Transform to_target; |
| 801 property_trees->GetToTarget(clip_node->transform_id, | 805 property_trees->GetToTarget(clip_node->transform_id, |
| 802 clip_node->target_effect_id, &to_target); | 806 clip_node->target_effect_id, &to_target); |
| 803 clip_node->clip_in_target_space = | 807 clip_node->clip_in_target_space = |
| 804 MathUtil::MapClippedRect(to_target, clip_node->clip); | 808 MathUtil::MapClippedRect(to_target, clip_node->clip); |
| 805 ResetIfHasNanCoordinate(&clip_node->clip_in_target_space); | 809 ResetIfHasNanCoordinate(&clip_node->clip_in_target_space); |
| 806 clip_node->combined_clip_in_target_space = | 810 clip_node->combined_clip_in_target_space = |
| 807 gfx::IntersectRects(clip_node->clip_in_target_space, | 811 gfx::IntersectRects(clip_node->clip_in_target_space, |
| 808 parent_combined_clip_in_target_space); | 812 parent_combined_clip_in_target_space); |
| 809 } else { | 813 } else { |
| 810 DCHECK(!clip_node->target_is_clipped); | 814 DCHECK(!target_is_clipped); |
| 811 DCHECK(!clip_node->layers_are_clipped); | 815 DCHECK(!clip_node->layers_are_clipped); |
| 812 clip_node->combined_clip_in_target_space = | 816 clip_node->combined_clip_in_target_space = |
| 813 parent_combined_clip_in_target_space; | 817 parent_combined_clip_in_target_space; |
| 814 } | 818 } |
| 815 ResetIfHasNanCoordinate(&clip_node->combined_clip_in_target_space); | 819 ResetIfHasNanCoordinate(&clip_node->combined_clip_in_target_space); |
| 816 continue; | 820 continue; |
| 817 } | 821 } |
| 818 bool use_only_parent_clip = | 822 bool use_only_parent_clip = |
| 819 clip_node->clip_type != ClipNode::ClipType::APPLIES_LOCAL_CLIP; | 823 clip_node->clip_type != ClipNode::ClipType::APPLIES_LOCAL_CLIP; |
| 820 if (use_only_parent_clip) { | 824 if (use_only_parent_clip) { |
| 821 clip_node->combined_clip_in_target_space = | 825 clip_node->combined_clip_in_target_space = |
| 822 parent_combined_clip_in_target_space; | 826 parent_combined_clip_in_target_space; |
| 823 if (!non_root_surfaces_enabled) { | 827 if (!non_root_surfaces_enabled) { |
| 824 clip_node->clip_in_target_space = | 828 clip_node->clip_in_target_space = |
| 825 parent_clip_node->clip_in_target_space; | 829 parent_clip_node->clip_in_target_space; |
| 826 } else if (!clip_node->target_is_clipped) { | 830 } else if (!target_is_clipped) { |
| 827 clip_node->clip_in_target_space = parent_clip_in_target_space; | 831 clip_node->clip_in_target_space = parent_clip_in_target_space; |
| 828 } else { | 832 } else { |
| 829 // Render Surface applies clip and the owning layer itself applies | 833 // Render Surface applies clip and the owning layer itself applies |
| 830 // no clip. So, clip_in_target_space is not used and hence we can set | 834 // no clip. So, clip_in_target_space is not used and hence we can set |
| 831 // it to an empty rect. | 835 // it to an empty rect. |
| 832 clip_node->clip_in_target_space = gfx::RectF(); | 836 clip_node->clip_in_target_space = gfx::RectF(); |
| 833 } | 837 } |
| 834 } else { | 838 } else { |
| 835 gfx::Transform source_to_target; | 839 gfx::Transform source_to_target; |
| 836 | 840 |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1183 gfx::Transform render_surface_transform; | 1187 gfx::Transform render_surface_transform; |
| 1184 const EffectNode* target_effect_node = | 1188 const EffectNode* target_effect_node = |
| 1185 effect_tree.Node(effect_node->target_id); | 1189 effect_tree.Node(effect_node->target_id); |
| 1186 property_trees->GetToTarget(transform_node->id, target_effect_node->id, | 1190 property_trees->GetToTarget(transform_node->id, target_effect_node->id, |
| 1187 &render_surface_transform); | 1191 &render_surface_transform); |
| 1188 | 1192 |
| 1189 ConcatInverseSurfaceContentsScale(effect_node, &render_surface_transform); | 1193 ConcatInverseSurfaceContentsScale(effect_node, &render_surface_transform); |
| 1190 render_surface->SetDrawTransform(render_surface_transform); | 1194 render_surface->SetDrawTransform(render_surface_transform); |
| 1191 } | 1195 } |
| 1192 | 1196 |
| 1193 static void SetSurfaceIsClipped(const ClipNode* clip_node, | |
| 1194 RenderSurfaceImpl* render_surface) { | |
| 1195 DCHECK(render_surface->OwningLayerId() == clip_node->owner_id) | |
| 1196 << "we now create clip node for every render surface"; | |
| 1197 | |
| 1198 render_surface->SetIsClipped(clip_node->target_is_clipped); | |
| 1199 } | |
| 1200 | |
| 1201 static void SetSurfaceClipRect(const ClipNode* parent_clip_node, | 1197 static void SetSurfaceClipRect(const ClipNode* parent_clip_node, |
| 1202 const PropertyTrees* property_trees, | 1198 const PropertyTrees* property_trees, |
| 1203 RenderSurfaceImpl* render_surface) { | 1199 RenderSurfaceImpl* render_surface) { |
| 1204 if (!render_surface->is_clipped()) { | 1200 if (!render_surface->is_clipped()) { |
| 1205 render_surface->SetClipRect(gfx::Rect()); | 1201 render_surface->SetClipRect(gfx::Rect()); |
| 1206 return; | 1202 return; |
| 1207 } | 1203 } |
| 1208 | 1204 |
| 1209 const EffectTree& effect_tree = property_trees->effect_tree; | 1205 const EffectTree& effect_tree = property_trees->effect_tree; |
| 1210 const TransformTree& transform_tree = property_trees->transform_tree; | 1206 const TransformTree& transform_tree = property_trees->transform_tree; |
| (...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1338 // properties computed for other layers are not needed. | 1334 // properties computed for other layers are not needed. |
| 1339 mask_layer->draw_properties().screen_space_transform = | 1335 mask_layer->draw_properties().screen_space_transform = |
| 1340 ScreenSpaceTransformInternal(mask_layer, | 1336 ScreenSpaceTransformInternal(mask_layer, |
| 1341 property_trees->transform_tree); | 1337 property_trees->transform_tree); |
| 1342 mask_layer->draw_properties().visible_layer_rect = | 1338 mask_layer->draw_properties().visible_layer_rect = |
| 1343 gfx::Rect(mask_layer->bounds()); | 1339 gfx::Rect(mask_layer->bounds()); |
| 1344 } | 1340 } |
| 1345 | 1341 |
| 1346 void ComputeSurfaceDrawProperties(const PropertyTrees* property_trees, | 1342 void ComputeSurfaceDrawProperties(const PropertyTrees* property_trees, |
| 1347 RenderSurfaceImpl* render_surface) { | 1343 RenderSurfaceImpl* render_surface) { |
| 1348 const ClipNode* clip_node = | 1344 const EffectNode* effect_node = |
| 1349 property_trees->clip_tree.Node(render_surface->ClipTreeIndex()); | 1345 property_trees->effect_tree.Node(render_surface->EffectTreeIndex()); |
| 1350 | 1346 render_surface->SetIsClipped(effect_node->surface_is_clipped); |
| 1351 SetSurfaceIsClipped(clip_node, render_surface); | |
| 1352 SetSurfaceDrawOpacity(property_trees->effect_tree, render_surface); | 1347 SetSurfaceDrawOpacity(property_trees->effect_tree, render_surface); |
| 1353 SetSurfaceDrawTransform(property_trees, render_surface); | 1348 SetSurfaceDrawTransform(property_trees, render_surface); |
| 1354 render_surface->SetScreenSpaceTransform( | 1349 render_surface->SetScreenSpaceTransform( |
| 1355 property_trees->ToScreenSpaceTransformWithoutSurfaceContentsScale( | 1350 property_trees->ToScreenSpaceTransformWithoutSurfaceContentsScale( |
| 1356 render_surface->TransformTreeIndex(), | 1351 render_surface->TransformTreeIndex(), |
| 1357 render_surface->EffectTreeIndex())); | 1352 render_surface->EffectTreeIndex())); |
| 1358 | 1353 |
| 1354 const ClipNode* clip_node = |
| 1355 property_trees->clip_tree.Node(render_surface->ClipTreeIndex()); |
| 1359 SetSurfaceClipRect(property_trees->clip_tree.parent(clip_node), | 1356 SetSurfaceClipRect(property_trees->clip_tree.parent(clip_node), |
| 1360 property_trees, render_surface); | 1357 property_trees, render_surface); |
| 1361 } | 1358 } |
| 1362 | 1359 |
| 1363 #if DCHECK_IS_ON() | 1360 #if DCHECK_IS_ON() |
| 1364 static void ValidatePageScaleLayer(const Layer* page_scale_layer) { | 1361 static void ValidatePageScaleLayer(const Layer* page_scale_layer) { |
| 1365 DCHECK_EQ(page_scale_layer->position().ToString(), gfx::PointF().ToString()); | 1362 DCHECK_EQ(page_scale_layer->position().ToString(), gfx::PointF().ToString()); |
| 1366 DCHECK_EQ(page_scale_layer->transform_origin().ToString(), | 1363 DCHECK_EQ(page_scale_layer->transform_origin().ToString(), |
| 1367 gfx::Point3F().ToString()); | 1364 gfx::Point3F().ToString()); |
| 1368 } | 1365 } |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1456 void UpdateElasticOverscroll(PropertyTrees* property_trees, | 1453 void UpdateElasticOverscroll(PropertyTrees* property_trees, |
| 1457 const Layer* overscroll_elasticity_layer, | 1454 const Layer* overscroll_elasticity_layer, |
| 1458 const gfx::Vector2dF& elastic_overscroll) { | 1455 const gfx::Vector2dF& elastic_overscroll) { |
| 1459 UpdateElasticOverscrollInternal(property_trees, overscroll_elasticity_layer, | 1456 UpdateElasticOverscrollInternal(property_trees, overscroll_elasticity_layer, |
| 1460 elastic_overscroll); | 1457 elastic_overscroll); |
| 1461 } | 1458 } |
| 1462 | 1459 |
| 1463 } // namespace draw_property_utils | 1460 } // namespace draw_property_utils |
| 1464 | 1461 |
| 1465 } // namespace cc | 1462 } // namespace cc |
| OLD | NEW |