| 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 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 bool include_viewport_clip = true; | 348 bool include_viewport_clip = true; |
| 349 bool include_expanding_clips = true; | 349 bool include_expanding_clips = true; |
| 350 ConditionalClip accumulated_clip = ComputeAccumulatedClip( | 350 ConditionalClip accumulated_clip = ComputeAccumulatedClip( |
| 351 property_trees, include_viewport_clip, include_expanding_clips, | 351 property_trees, include_viewport_clip, include_expanding_clips, |
| 352 local_clip_id, root_effect_id); | 352 local_clip_id, root_effect_id); |
| 353 DCHECK(accumulated_clip.is_clipped); | 353 DCHECK(accumulated_clip.is_clipped); |
| 354 return accumulated_clip.clip_rect; | 354 return accumulated_clip.clip_rect; |
| 355 } | 355 } |
| 356 | 356 |
| 357 void CalculateClipRects(const std::vector<LayerImpl*>& visible_layer_list, | 357 void CalculateClipRects(const std::vector<LayerImpl*>& visible_layer_list, |
| 358 const PropertyTrees* property_trees, | 358 const PropertyTrees* property_trees) { |
| 359 bool non_root_surfaces_enabled) { | |
| 360 const ClipTree& clip_tree = property_trees->clip_tree; | 359 const ClipTree& clip_tree = property_trees->clip_tree; |
| 361 for (auto* layer : visible_layer_list) { | 360 for (auto* layer : visible_layer_list) { |
| 362 const ClipNode* clip_node = clip_tree.Node(layer->clip_tree_index()); | 361 const ClipNode* clip_node = clip_tree.Node(layer->clip_tree_index()); |
| 363 bool layer_needs_clip_rect = | 362 if (!clip_node->layers_are_clipped) { |
| 364 non_root_surfaces_enabled | |
| 365 ? clip_node->layers_are_clipped | |
| 366 : clip_node->layers_are_clipped_when_surfaces_disabled; | |
| 367 if (!layer_needs_clip_rect) { | |
| 368 layer->set_clip_rect(gfx::Rect()); | 363 layer->set_clip_rect(gfx::Rect()); |
| 369 continue; | 364 continue; |
| 370 } | 365 } |
| 371 if (!non_root_surfaces_enabled) { | |
| 372 layer->set_clip_rect( | |
| 373 gfx::ToEnclosingRect(clip_node->clip_in_target_space)); | |
| 374 continue; | |
| 375 } | |
| 376 | 366 |
| 377 const TransformTree& transform_tree = property_trees->transform_tree; | 367 const TransformTree& transform_tree = property_trees->transform_tree; |
| 378 const TransformNode* transform_node = | 368 const TransformNode* transform_node = |
| 379 transform_tree.Node(layer->transform_tree_index()); | 369 transform_tree.Node(layer->transform_tree_index()); |
| 380 int target_node_id = transform_tree.ContentTargetId(transform_node->id); | 370 int target_node_id = transform_tree.ContentTargetId(transform_node->id); |
| 381 | 371 |
| 382 // The clip node stores clip rect in its target space. | 372 // The clip node stores clip rect in its target space. |
| 383 gfx::RectF clip_rect_in_target_space = clip_node->clip_in_target_space; | 373 gfx::RectF clip_rect_in_target_space = clip_node->clip_in_target_space; |
| 384 | 374 |
| 385 // If required, this clip rect should be mapped to the current layer's | 375 // If required, this clip rect should be mapped to the current layer's |
| (...skipping 16 matching lines...) Expand all Loading... |
| 402 | 392 |
| 403 if (!clip_rect_in_target_space.IsEmpty()) { | 393 if (!clip_rect_in_target_space.IsEmpty()) { |
| 404 layer->set_clip_rect(gfx::ToEnclosingRect(clip_rect_in_target_space)); | 394 layer->set_clip_rect(gfx::ToEnclosingRect(clip_rect_in_target_space)); |
| 405 } else { | 395 } else { |
| 406 layer->set_clip_rect(gfx::Rect()); | 396 layer->set_clip_rect(gfx::Rect()); |
| 407 } | 397 } |
| 408 } | 398 } |
| 409 } | 399 } |
| 410 | 400 |
| 411 void CalculateVisibleRects(const LayerImplList& visible_layer_list, | 401 void CalculateVisibleRects(const LayerImplList& visible_layer_list, |
| 412 const PropertyTrees* property_trees, | 402 const PropertyTrees* property_trees) { |
| 413 bool non_root_surfaces_enabled) { | |
| 414 const EffectTree& effect_tree = property_trees->effect_tree; | 403 const EffectTree& effect_tree = property_trees->effect_tree; |
| 415 const TransformTree& transform_tree = property_trees->transform_tree; | 404 const TransformTree& transform_tree = property_trees->transform_tree; |
| 416 const ClipTree& clip_tree = property_trees->clip_tree; | 405 const ClipTree& clip_tree = property_trees->clip_tree; |
| 417 for (auto* layer : visible_layer_list) { | 406 for (auto* layer : visible_layer_list) { |
| 418 gfx::Size layer_bounds = layer->bounds(); | 407 gfx::Size layer_bounds = layer->bounds(); |
| 419 | 408 |
| 420 int effect_ancestor_with_copy_request = | 409 int effect_ancestor_with_copy_request = |
| 421 effect_tree.ClosestAncestorWithCopyRequest(layer->effect_tree_index()); | 410 effect_tree.ClosestAncestorWithCopyRequest(layer->effect_tree_index()); |
| 422 if (effect_ancestor_with_copy_request > EffectTree::kContentsRootNodeId) { | 411 if (effect_ancestor_with_copy_request > EffectTree::kContentsRootNodeId) { |
| 423 // Non root copy request. | 412 // Non root copy request. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 449 layer->set_visible_layer_rect(visible_rect); | 438 layer->set_visible_layer_rect(visible_rect); |
| 450 } else { | 439 } else { |
| 451 layer->set_visible_layer_rect(gfx::Rect(layer_bounds)); | 440 layer->set_visible_layer_rect(gfx::Rect(layer_bounds)); |
| 452 } | 441 } |
| 453 continue; | 442 continue; |
| 454 } | 443 } |
| 455 | 444 |
| 456 const ClipNode* clip_node = clip_tree.Node(layer->clip_tree_index()); | 445 const ClipNode* clip_node = clip_tree.Node(layer->clip_tree_index()); |
| 457 const TransformNode* transform_node = | 446 const TransformNode* transform_node = |
| 458 transform_tree.Node(layer->transform_tree_index()); | 447 transform_tree.Node(layer->transform_tree_index()); |
| 459 if (!non_root_surfaces_enabled) { | |
| 460 // When we only have a root surface, the clip node and the layer must | |
| 461 // necessarily have the same target (the root). | |
| 462 if (transform_node->ancestors_are_invertible) { | |
| 463 gfx::RectF combined_clip_rect_in_target_space = | |
| 464 clip_node->combined_clip_in_target_space; | |
| 465 gfx::Transform target_to_content; | |
| 466 target_to_content.Translate(-layer->offset_to_transform_parent().x(), | |
| 467 -layer->offset_to_transform_parent().y()); | |
| 468 target_to_content.PreconcatTransform( | |
| 469 transform_tree.FromScreen(transform_node->id)); | |
| 470 | |
| 471 gfx::Rect visible_rect = | |
| 472 gfx::ToEnclosingRect(MathUtil::ProjectClippedRect( | |
| 473 target_to_content, combined_clip_rect_in_target_space)); | |
| 474 visible_rect.Intersect(gfx::Rect(layer_bounds)); | |
| 475 layer->set_visible_layer_rect(visible_rect); | |
| 476 } else { | |
| 477 layer->set_visible_layer_rect(gfx::Rect(layer_bounds)); | |
| 478 } | |
| 479 continue; | |
| 480 } | |
| 481 | 448 |
| 482 // When both the layer and the target are unclipped, we only have to apply | 449 // When both the layer and the target are unclipped, we only have to apply |
| 483 // the viewport clip. | 450 // the viewport clip. |
| 484 const bool fully_visible = | 451 const bool fully_visible = |
| 485 !clip_node->layers_are_clipped && | 452 !clip_node->layers_are_clipped && |
| 486 !effect_tree.Node(clip_node->target_effect_id)->surface_is_clipped; | 453 !effect_tree.Node(clip_node->target_effect_id)->surface_is_clipped; |
| 487 | 454 |
| 488 if (fully_visible) { | 455 if (fully_visible) { |
| 489 if (!transform_node->ancestors_are_invertible) { | 456 if (!transform_node->ancestors_are_invertible) { |
| 490 // An animated singular transform may become non-singular during the | 457 // An animated singular transform may become non-singular during the |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 709 | 676 |
| 710 bool layer_is_drawn = | 677 bool layer_is_drawn = |
| 711 effect_tree.Node(layer_impl->effect_tree_index())->is_drawn; | 678 effect_tree.Node(layer_impl->effect_tree_index())->is_drawn; |
| 712 | 679 |
| 713 if (LayerNeedsUpdate(layer_impl, layer_is_drawn, property_trees)) | 680 if (LayerNeedsUpdate(layer_impl, layer_is_drawn, property_trees)) |
| 714 visible_layer_list->push_back(layer_impl); | 681 visible_layer_list->push_back(layer_impl); |
| 715 } | 682 } |
| 716 } | 683 } |
| 717 | 684 |
| 718 void UpdateRenderSurfaceForLayer(EffectTree* effect_tree, | 685 void UpdateRenderSurfaceForLayer(EffectTree* effect_tree, |
| 719 bool non_root_surfaces_enabled, | |
| 720 LayerImpl* layer) { | 686 LayerImpl* layer) { |
| 721 if (!non_root_surfaces_enabled) { | |
| 722 layer->SetHasRenderSurface(IsRootLayer(layer)); | |
| 723 return; | |
| 724 } | |
| 725 | |
| 726 EffectNode* node = effect_tree->Node(layer->effect_tree_index()); | 687 EffectNode* node = effect_tree->Node(layer->effect_tree_index()); |
| 727 | 688 |
| 728 if (node->owning_layer_id == layer->id() && node->has_render_surface) | 689 if (node->owning_layer_id == layer->id() && node->has_render_surface) |
| 729 layer->SetHasRenderSurface(true); | 690 layer->SetHasRenderSurface(true); |
| 730 else | 691 else |
| 731 layer->SetHasRenderSurface(false); | 692 layer->SetHasRenderSurface(false); |
| 732 } | 693 } |
| 733 } // namespace | 694 } // namespace |
| 734 | 695 |
| 735 template <typename LayerType> | 696 template <typename LayerType> |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 808 | 769 |
| 809 void ConcatInverseSurfaceContentsScale(const EffectNode* effect_node, | 770 void ConcatInverseSurfaceContentsScale(const EffectNode* effect_node, |
| 810 gfx::Transform* transform) { | 771 gfx::Transform* transform) { |
| 811 DCHECK(effect_node->has_render_surface); | 772 DCHECK(effect_node->has_render_surface); |
| 812 if (effect_node->surface_contents_scale.x() != 0.0 && | 773 if (effect_node->surface_contents_scale.x() != 0.0 && |
| 813 effect_node->surface_contents_scale.y() != 0.0) | 774 effect_node->surface_contents_scale.y() != 0.0) |
| 814 transform->Scale(1.0 / effect_node->surface_contents_scale.x(), | 775 transform->Scale(1.0 / effect_node->surface_contents_scale.x(), |
| 815 1.0 / effect_node->surface_contents_scale.y()); | 776 1.0 / effect_node->surface_contents_scale.y()); |
| 816 } | 777 } |
| 817 | 778 |
| 818 void ComputeClips(PropertyTrees* property_trees, | 779 void ComputeClips(PropertyTrees* property_trees) { |
| 819 bool non_root_surfaces_enabled) { | |
| 820 ClipTree* clip_tree = &property_trees->clip_tree; | 780 ClipTree* clip_tree = &property_trees->clip_tree; |
| 821 if (!clip_tree->needs_update()) | 781 if (!clip_tree->needs_update()) |
| 822 return; | 782 return; |
| 823 for (int i = ClipTree::kViewportNodeId; | 783 for (int i = ClipTree::kViewportNodeId; |
| 824 i < static_cast<int>(clip_tree->size()); ++i) { | 784 i < static_cast<int>(clip_tree->size()); ++i) { |
| 825 ClipNode* clip_node = clip_tree->Node(i); | 785 ClipNode* clip_node = clip_tree->Node(i); |
| 826 | 786 |
| 827 if (clip_node->id == ClipTree::kViewportNodeId) { | 787 if (clip_node->id == ClipTree::kViewportNodeId) { |
| 828 ResetIfHasNanCoordinate(&clip_node->clip); | 788 ResetIfHasNanCoordinate(&clip_node->clip); |
| 829 clip_node->clip_in_target_space = clip_node->clip; | 789 clip_node->clip_in_target_space = clip_node->clip; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 852 // target space, the relative sizes and positions of B and C can shift. | 812 // target space, the relative sizes and positions of B and C can shift. |
| 853 // Since it's the relationship in target space that matters, that's where we | 813 // Since it's the relationship in target space that matters, that's where we |
| 854 // must combine clips. For each clip node, we save the clip rects in its | 814 // must combine clips. For each clip node, we save the clip rects in its |
| 855 // target space. So, we need to get the ancestor clip rect in the current | 815 // target space. So, we need to get the ancestor clip rect in the current |
| 856 // clip node's target space. | 816 // clip node's target space. |
| 857 gfx::RectF parent_combined_clip_in_target_space = | 817 gfx::RectF parent_combined_clip_in_target_space = |
| 858 parent_clip_node->combined_clip_in_target_space; | 818 parent_clip_node->combined_clip_in_target_space; |
| 859 gfx::RectF parent_clip_in_target_space = | 819 gfx::RectF parent_clip_in_target_space = |
| 860 parent_clip_node->clip_in_target_space; | 820 parent_clip_node->clip_in_target_space; |
| 861 if (parent_target_transform_node && | 821 if (parent_target_transform_node && |
| 862 parent_target_transform_node->id != clip_node->target_transform_id && | 822 parent_target_transform_node->id != clip_node->target_transform_id) { |
| 863 non_root_surfaces_enabled) { | |
| 864 success &= property_trees->ComputeTransformFromTarget( | 823 success &= property_trees->ComputeTransformFromTarget( |
| 865 clip_node->target_transform_id, parent_clip_node->target_effect_id, | 824 clip_node->target_transform_id, parent_clip_node->target_effect_id, |
| 866 &parent_to_current); | 825 &parent_to_current); |
| 867 const EffectNode* target_effect_node = | 826 const EffectNode* target_effect_node = |
| 868 effect_tree.Node(clip_node->target_effect_id); | 827 effect_tree.Node(clip_node->target_effect_id); |
| 869 PostConcatSurfaceContentsScale(target_effect_node, &parent_to_current); | 828 PostConcatSurfaceContentsScale(target_effect_node, &parent_to_current); |
| 870 const EffectNode* parent_target_effect_node = | 829 const EffectNode* parent_target_effect_node = |
| 871 effect_tree.Node(parent_clip_node->target_effect_id); | 830 effect_tree.Node(parent_clip_node->target_effect_id); |
| 872 ConcatInverseSurfaceContentsScale(parent_target_effect_node, | 831 ConcatInverseSurfaceContentsScale(parent_target_effect_node, |
| 873 &parent_to_current); | 832 &parent_to_current); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 885 property_trees)); | 844 property_trees)); |
| 886 } | 845 } |
| 887 parent_clip_in_target_space = MathUtil::ProjectClippedRect( | 846 parent_clip_in_target_space = MathUtil::ProjectClippedRect( |
| 888 parent_to_current, parent_clip_node->clip_in_target_space); | 847 parent_to_current, parent_clip_node->clip_in_target_space); |
| 889 } | 848 } |
| 890 // Only nodes affected by ancestor clips will have their clip adjusted due | 849 // Only nodes affected by ancestor clips will have their clip adjusted due |
| 891 // to intersecting with an ancestor clip. But, we still need to propagate | 850 // to intersecting with an ancestor clip. But, we still need to propagate |
| 892 // the combined clip to our children because if they are clipped, they may | 851 // the combined clip to our children because if they are clipped, they may |
| 893 // need to clip using our parent clip and if we don't propagate it here, | 852 // need to clip using our parent clip and if we don't propagate it here, |
| 894 // it will be lost. | 853 // it will be lost. |
| 895 if (clip_node->resets_clip && non_root_surfaces_enabled) { | 854 if (clip_node->resets_clip) { |
| 896 if (clip_node->clip_type == ClipNode::ClipType::APPLIES_LOCAL_CLIP) { | 855 if (clip_node->clip_type == ClipNode::ClipType::APPLIES_LOCAL_CLIP) { |
| 897 gfx::Transform to_target; | 856 gfx::Transform to_target; |
| 898 property_trees->GetToTarget(clip_node->transform_id, | 857 property_trees->GetToTarget(clip_node->transform_id, |
| 899 clip_node->target_effect_id, &to_target); | 858 clip_node->target_effect_id, &to_target); |
| 900 clip_node->clip_in_target_space = | 859 clip_node->clip_in_target_space = |
| 901 MathUtil::MapClippedRect(to_target, clip_node->clip); | 860 MathUtil::MapClippedRect(to_target, clip_node->clip); |
| 902 ResetIfHasNanCoordinate(&clip_node->clip_in_target_space); | 861 ResetIfHasNanCoordinate(&clip_node->clip_in_target_space); |
| 903 clip_node->combined_clip_in_target_space = | 862 clip_node->combined_clip_in_target_space = |
| 904 gfx::IntersectRects(clip_node->clip_in_target_space, | 863 gfx::IntersectRects(clip_node->clip_in_target_space, |
| 905 parent_combined_clip_in_target_space); | 864 parent_combined_clip_in_target_space); |
| 906 } else { | 865 } else { |
| 907 DCHECK(!target_is_clipped); | 866 DCHECK(!target_is_clipped); |
| 908 DCHECK(!clip_node->layers_are_clipped); | 867 DCHECK(!clip_node->layers_are_clipped); |
| 909 clip_node->combined_clip_in_target_space = | 868 clip_node->combined_clip_in_target_space = |
| 910 parent_combined_clip_in_target_space; | 869 parent_combined_clip_in_target_space; |
| 911 } | 870 } |
| 912 ResetIfHasNanCoordinate(&clip_node->combined_clip_in_target_space); | 871 ResetIfHasNanCoordinate(&clip_node->combined_clip_in_target_space); |
| 913 continue; | 872 continue; |
| 914 } | 873 } |
| 915 bool use_only_parent_clip = | 874 bool use_only_parent_clip = |
| 916 clip_node->clip_type != ClipNode::ClipType::APPLIES_LOCAL_CLIP; | 875 clip_node->clip_type != ClipNode::ClipType::APPLIES_LOCAL_CLIP; |
| 917 if (use_only_parent_clip) { | 876 if (use_only_parent_clip) { |
| 918 clip_node->combined_clip_in_target_space = | 877 clip_node->combined_clip_in_target_space = |
| 919 parent_combined_clip_in_target_space; | 878 parent_combined_clip_in_target_space; |
| 920 if (!non_root_surfaces_enabled) { | 879 if (!target_is_clipped) { |
| 921 clip_node->clip_in_target_space = | |
| 922 parent_clip_node->clip_in_target_space; | |
| 923 } else if (!target_is_clipped) { | |
| 924 clip_node->clip_in_target_space = parent_clip_in_target_space; | 880 clip_node->clip_in_target_space = parent_clip_in_target_space; |
| 925 } else { | 881 } else { |
| 926 // Render Surface applies clip and the owning layer itself applies | 882 // Render Surface applies clip and the owning layer itself applies |
| 927 // no clip. So, clip_in_target_space is not used and hence we can set | 883 // no clip. So, clip_in_target_space is not used and hence we can set |
| 928 // it to an empty rect. | 884 // it to an empty rect. |
| 929 clip_node->clip_in_target_space = gfx::RectF(); | 885 clip_node->clip_in_target_space = gfx::RectF(); |
| 930 } | 886 } |
| 931 } else { | 887 } else { |
| 932 gfx::Transform source_to_target; | 888 gfx::Transform source_to_target; |
| 933 | 889 |
| 934 if (!non_root_surfaces_enabled) { | 890 if (transform_tree.ContentTargetId(transform_node->id) == |
| 935 source_to_target = transform_tree.ToScreen(clip_node->transform_id); | 891 clip_node->target_transform_id) { |
| 936 } else if (transform_tree.ContentTargetId(transform_node->id) == | |
| 937 clip_node->target_transform_id) { | |
| 938 property_trees->GetToTarget(clip_node->transform_id, | 892 property_trees->GetToTarget(clip_node->transform_id, |
| 939 clip_node->target_effect_id, | 893 clip_node->target_effect_id, |
| 940 &source_to_target); | 894 &source_to_target); |
| 941 } else { | 895 } else { |
| 942 success = property_trees->GetToTarget( | 896 success = property_trees->GetToTarget( |
| 943 transform_node->id, clip_node->target_effect_id, &source_to_target); | 897 transform_node->id, clip_node->target_effect_id, &source_to_target); |
| 944 // source_to_target computation should be successful as target is an | 898 // source_to_target computation should be successful as target is an |
| 945 // ancestor of the transform node. | 899 // ancestor of the transform node. |
| 946 DCHECK(success); | 900 DCHECK(success); |
| 947 } | 901 } |
| 948 | 902 |
| 949 gfx::RectF source_clip_in_target_space = | 903 gfx::RectF source_clip_in_target_space = |
| 950 MathUtil::MapClippedRect(source_to_target, clip_node->clip); | 904 MathUtil::MapClippedRect(source_to_target, clip_node->clip); |
| 951 | 905 |
| 952 // With surfaces disabled, the only case where we use only the local clip | 906 // With surfaces disabled, the only case where we use only the local clip |
| 953 // for layer clipping is the case where no non-viewport ancestor node | 907 // for layer clipping is the case where no non-viewport ancestor node |
| 954 // applies a local clip. | 908 // applies a local clip. |
| 955 bool layer_clipping_uses_only_local_clip = | 909 bool layer_clipping_uses_only_local_clip = |
| 956 non_root_surfaces_enabled | 910 clip_node->layer_clipping_uses_only_local_clip; |
| 957 ? clip_node->layer_clipping_uses_only_local_clip | |
| 958 : !parent_clip_node->layers_are_clipped_when_surfaces_disabled; | |
| 959 if (!layer_clipping_uses_only_local_clip) { | 911 if (!layer_clipping_uses_only_local_clip) { |
| 960 clip_node->clip_in_target_space = gfx::IntersectRects( | 912 clip_node->clip_in_target_space = gfx::IntersectRects( |
| 961 parent_clip_in_target_space, source_clip_in_target_space); | 913 parent_clip_in_target_space, source_clip_in_target_space); |
| 962 } else { | 914 } else { |
| 963 clip_node->clip_in_target_space = source_clip_in_target_space; | 915 clip_node->clip_in_target_space = source_clip_in_target_space; |
| 964 } | 916 } |
| 965 | 917 |
| 966 clip_node->combined_clip_in_target_space = gfx::IntersectRects( | 918 clip_node->combined_clip_in_target_space = gfx::IntersectRects( |
| 967 parent_combined_clip_in_target_space, source_clip_in_target_space); | 919 parent_combined_clip_in_target_space, source_clip_in_target_space); |
| 968 } | 920 } |
| 969 ResetIfHasNanCoordinate(&clip_node->clip_in_target_space); | 921 ResetIfHasNanCoordinate(&clip_node->clip_in_target_space); |
| 970 ResetIfHasNanCoordinate(&clip_node->combined_clip_in_target_space); | 922 ResetIfHasNanCoordinate(&clip_node->combined_clip_in_target_space); |
| 971 } | 923 } |
| 972 clip_tree->set_needs_update(false); | 924 clip_tree->set_needs_update(false); |
| 973 } | 925 } |
| 974 | 926 |
| 975 void ComputeTransforms(TransformTree* transform_tree) { | 927 void ComputeTransforms(TransformTree* transform_tree) { |
| 976 if (!transform_tree->needs_update()) | 928 if (!transform_tree->needs_update()) |
| 977 return; | 929 return; |
| 978 for (int i = TransformTree::kContentsRootNodeId; | 930 for (int i = TransformTree::kContentsRootNodeId; |
| 979 i < static_cast<int>(transform_tree->size()); ++i) | 931 i < static_cast<int>(transform_tree->size()); ++i) |
| 980 transform_tree->UpdateTransforms(i); | 932 transform_tree->UpdateTransforms(i); |
| 981 transform_tree->set_needs_update(false); | 933 transform_tree->set_needs_update(false); |
| 982 } | 934 } |
| 983 | 935 |
| 984 void UpdateRenderTarget(EffectTree* effect_tree, | 936 void UpdateRenderTarget(EffectTree* effect_tree) { |
| 985 bool can_render_to_separate_surface) { | |
| 986 for (int i = EffectTree::kContentsRootNodeId; | 937 for (int i = EffectTree::kContentsRootNodeId; |
| 987 i < static_cast<int>(effect_tree->size()); ++i) { | 938 i < static_cast<int>(effect_tree->size()); ++i) { |
| 988 EffectNode* node = effect_tree->Node(i); | 939 EffectNode* node = effect_tree->Node(i); |
| 989 if (i == EffectTree::kContentsRootNodeId) { | 940 if (i == EffectTree::kContentsRootNodeId) { |
| 990 // Render target of the node corresponding to root is itself. | 941 // Render target of the node corresponding to root is itself. |
| 991 node->target_id = EffectTree::kContentsRootNodeId; | 942 node->target_id = EffectTree::kContentsRootNodeId; |
| 992 } else if (!can_render_to_separate_surface) { | |
| 993 node->target_id = EffectTree::kContentsRootNodeId; | |
| 994 } else if (effect_tree->parent(node)->has_render_surface) { | 943 } else if (effect_tree->parent(node)->has_render_surface) { |
| 995 node->target_id = node->parent_id; | 944 node->target_id = node->parent_id; |
| 996 } else { | 945 } else { |
| 997 node->target_id = effect_tree->parent(node)->target_id; | 946 node->target_id = effect_tree->parent(node)->target_id; |
| 998 } | 947 } |
| 999 } | 948 } |
| 1000 } | 949 } |
| 1001 | 950 |
| 1002 void ComputeEffects(EffectTree* effect_tree) { | 951 void ComputeEffects(EffectTree* effect_tree) { |
| 1003 if (!effect_tree->needs_update()) | 952 if (!effect_tree->needs_update()) |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1045 static void ComputeLayerClipRect(const PropertyTrees* property_trees, | 994 static void ComputeLayerClipRect(const PropertyTrees* property_trees, |
| 1046 const LayerImpl* layer) { | 995 const LayerImpl* layer) { |
| 1047 const EffectTree* effect_tree = &property_trees->effect_tree; | 996 const EffectTree* effect_tree = &property_trees->effect_tree; |
| 1048 const ClipTree* clip_tree = &property_trees->clip_tree; | 997 const ClipTree* clip_tree = &property_trees->clip_tree; |
| 1049 const ClipNode* clip_node = clip_tree->Node(layer->clip_tree_index()); | 998 const ClipNode* clip_node = clip_tree->Node(layer->clip_tree_index()); |
| 1050 const EffectNode* effect_node = effect_tree->Node(layer->effect_tree_index()); | 999 const EffectNode* effect_node = effect_tree->Node(layer->effect_tree_index()); |
| 1051 const EffectNode* target_node = | 1000 const EffectNode* target_node = |
| 1052 effect_node->has_render_surface | 1001 effect_node->has_render_surface |
| 1053 ? effect_node | 1002 ? effect_node |
| 1054 : effect_tree->Node(effect_node->target_id); | 1003 : effect_tree->Node(effect_node->target_id); |
| 1055 // TODO(weiliangc): When effect node has up to date render surface info on | |
| 1056 // compositor thread, no need to check for resourceless draw mode | |
| 1057 if (!property_trees->non_root_surfaces_enabled) { | |
| 1058 target_node = effect_tree->Node(1); | |
| 1059 } | |
| 1060 | |
| 1061 bool include_viewport_clip = false; | 1004 bool include_viewport_clip = false; |
| 1062 bool include_expanding_clips = false; | 1005 bool include_expanding_clips = false; |
| 1063 ConditionalClip accumulated_clip_rect = ComputeAccumulatedClip( | 1006 ConditionalClip accumulated_clip_rect = ComputeAccumulatedClip( |
| 1064 property_trees, include_viewport_clip, include_expanding_clips, | 1007 property_trees, include_viewport_clip, include_expanding_clips, |
| 1065 layer->clip_tree_index(), target_node->id); | 1008 layer->clip_tree_index(), target_node->id); |
| 1066 | 1009 |
| 1067 bool is_clipped_from_clip_tree = | 1010 bool is_clipped_from_clip_tree = clip_node->layers_are_clipped; |
| 1068 property_trees->non_root_surfaces_enabled | |
| 1069 ? clip_node->layers_are_clipped | |
| 1070 : clip_node->layers_are_clipped_when_surfaces_disabled; | |
| 1071 DCHECK_EQ(is_clipped_from_clip_tree, accumulated_clip_rect.is_clipped); | 1011 DCHECK_EQ(is_clipped_from_clip_tree, accumulated_clip_rect.is_clipped); |
| 1072 | 1012 |
| 1073 gfx::RectF accumulated_clip = accumulated_clip_rect.clip_rect; | 1013 gfx::RectF accumulated_clip = accumulated_clip_rect.clip_rect; |
| 1074 | 1014 |
| 1075 DCHECK(layer->clip_rect() == gfx::ToEnclosingRect(accumulated_clip)) | 1015 DCHECK(layer->clip_rect() == gfx::ToEnclosingRect(accumulated_clip)) |
| 1076 << " layer: " << layer->id() << " clip id: " << layer->clip_tree_index() | 1016 << " layer: " << layer->id() << " clip id: " << layer->clip_tree_index() |
| 1077 << " layer clip: " << layer->clip_rect().ToString() << " v.s. " | 1017 << " layer clip: " << layer->clip_rect().ToString() << " v.s. " |
| 1078 << gfx::ToEnclosingRect(accumulated_clip).ToString() | 1018 << gfx::ToEnclosingRect(accumulated_clip).ToString() |
| 1079 << " and clip node clip: " | 1019 << " and clip node clip: " |
| 1080 << gfx::ToEnclosingRect(clip_node->clip_in_target_space).ToString(); | 1020 << gfx::ToEnclosingRect(clip_node->clip_in_target_space).ToString(); |
| 1081 } | 1021 } |
| 1082 | 1022 |
| 1083 static void ComputeVisibleRectsInternal( | 1023 static void ComputeVisibleRectsInternal( |
| 1084 LayerImpl* root_layer, | 1024 LayerImpl* root_layer, |
| 1085 PropertyTrees* property_trees, | 1025 PropertyTrees* property_trees, |
| 1086 bool can_render_to_separate_surface, | |
| 1087 std::vector<LayerImpl*>* visible_layer_list) { | 1026 std::vector<LayerImpl*>* visible_layer_list) { |
| 1088 if (property_trees->non_root_surfaces_enabled != | |
| 1089 can_render_to_separate_surface) { | |
| 1090 property_trees->non_root_surfaces_enabled = can_render_to_separate_surface; | |
| 1091 property_trees->transform_tree.set_needs_update(true); | |
| 1092 } | |
| 1093 if (property_trees->transform_tree.needs_update()) { | 1027 if (property_trees->transform_tree.needs_update()) { |
| 1094 property_trees->clip_tree.set_needs_update(true); | 1028 property_trees->clip_tree.set_needs_update(true); |
| 1095 property_trees->effect_tree.set_needs_update(true); | 1029 property_trees->effect_tree.set_needs_update(true); |
| 1096 } | 1030 } |
| 1097 UpdateRenderTarget(&property_trees->effect_tree, | 1031 UpdateRenderTarget(&property_trees->effect_tree); |
| 1098 property_trees->non_root_surfaces_enabled); | |
| 1099 ComputeTransforms(&property_trees->transform_tree); | 1032 ComputeTransforms(&property_trees->transform_tree); |
| 1100 // Computation of clips uses surface contents scale which is updated while | 1033 // Computation of clips uses surface contents scale which is updated while |
| 1101 // computing effects. So, ComputeEffects should be before ComputeClips. | 1034 // computing effects. So, ComputeEffects should be before ComputeClips. |
| 1102 ComputeEffects(&property_trees->effect_tree); | 1035 ComputeEffects(&property_trees->effect_tree); |
| 1103 ComputeClips(property_trees, can_render_to_separate_surface); | 1036 ComputeClips(property_trees); |
| 1104 | 1037 |
| 1105 FindLayersThatNeedUpdates(root_layer->layer_tree_impl(), property_trees, | 1038 FindLayersThatNeedUpdates(root_layer->layer_tree_impl(), property_trees, |
| 1106 visible_layer_list); | 1039 visible_layer_list); |
| 1107 CalculateClipRects(*visible_layer_list, property_trees, | 1040 CalculateClipRects(*visible_layer_list, property_trees); |
| 1108 can_render_to_separate_surface); | 1041 CalculateVisibleRects(*visible_layer_list, property_trees); |
| 1109 CalculateVisibleRects(*visible_layer_list, property_trees, | |
| 1110 can_render_to_separate_surface); | |
| 1111 } | 1042 } |
| 1112 | 1043 |
| 1113 void UpdatePropertyTrees(PropertyTrees* property_trees, | 1044 void UpdatePropertyTrees(PropertyTrees* property_trees) { |
| 1114 bool can_render_to_separate_surface) { | |
| 1115 if (property_trees->non_root_surfaces_enabled != | |
| 1116 can_render_to_separate_surface) { | |
| 1117 property_trees->non_root_surfaces_enabled = can_render_to_separate_surface; | |
| 1118 property_trees->transform_tree.set_needs_update(true); | |
| 1119 } | |
| 1120 if (property_trees->transform_tree.needs_update()) { | 1045 if (property_trees->transform_tree.needs_update()) { |
| 1121 property_trees->clip_tree.set_needs_update(true); | 1046 property_trees->clip_tree.set_needs_update(true); |
| 1122 property_trees->effect_tree.set_needs_update(true); | 1047 property_trees->effect_tree.set_needs_update(true); |
| 1123 } | 1048 } |
| 1124 ComputeTransforms(&property_trees->transform_tree); | 1049 ComputeTransforms(&property_trees->transform_tree); |
| 1125 // Computation of clips uses surface contents scale which is updated while | 1050 // Computation of clips uses surface contents scale which is updated while |
| 1126 // computing effects. So, ComputeEffects should be before ComputeClips. | 1051 // computing effects. So, ComputeEffects should be before ComputeClips. |
| 1127 ComputeEffects(&property_trees->effect_tree); | 1052 ComputeEffects(&property_trees->effect_tree); |
| 1128 ComputeClips(property_trees, can_render_to_separate_surface); | 1053 ComputeClips(property_trees); |
| 1129 } | 1054 } |
| 1130 | 1055 |
| 1131 void BuildPropertyTreesAndComputeVisibleRects( | 1056 void BuildPropertyTreesAndComputeVisibleRects( |
| 1132 LayerImpl* root_layer, | 1057 LayerImpl* root_layer, |
| 1133 const LayerImpl* page_scale_layer, | 1058 const LayerImpl* page_scale_layer, |
| 1134 const LayerImpl* inner_viewport_scroll_layer, | 1059 const LayerImpl* inner_viewport_scroll_layer, |
| 1135 const LayerImpl* outer_viewport_scroll_layer, | 1060 const LayerImpl* outer_viewport_scroll_layer, |
| 1136 const LayerImpl* overscroll_elasticity_layer, | 1061 const LayerImpl* overscroll_elasticity_layer, |
| 1137 const gfx::Vector2dF& elastic_overscroll, | 1062 const gfx::Vector2dF& elastic_overscroll, |
| 1138 float page_scale_factor, | 1063 float page_scale_factor, |
| 1139 float device_scale_factor, | 1064 float device_scale_factor, |
| 1140 const gfx::Rect& viewport, | 1065 const gfx::Rect& viewport, |
| 1141 const gfx::Transform& device_transform, | 1066 const gfx::Transform& device_transform, |
| 1142 bool can_render_to_separate_surface, | |
| 1143 PropertyTrees* property_trees, | 1067 PropertyTrees* property_trees, |
| 1144 LayerImplList* visible_layer_list) { | 1068 LayerImplList* visible_layer_list) { |
| 1145 PropertyTreeBuilder::BuildPropertyTrees( | 1069 PropertyTreeBuilder::BuildPropertyTrees( |
| 1146 root_layer, page_scale_layer, inner_viewport_scroll_layer, | 1070 root_layer, page_scale_layer, inner_viewport_scroll_layer, |
| 1147 outer_viewport_scroll_layer, overscroll_elasticity_layer, | 1071 outer_viewport_scroll_layer, overscroll_elasticity_layer, |
| 1148 elastic_overscroll, page_scale_factor, device_scale_factor, viewport, | 1072 elastic_overscroll, page_scale_factor, device_scale_factor, viewport, |
| 1149 device_transform, property_trees); | 1073 device_transform, property_trees); |
| 1150 ComputeVisibleRects(root_layer, property_trees, | 1074 ComputeVisibleRects(root_layer, property_trees, visible_layer_list); |
| 1151 can_render_to_separate_surface, visible_layer_list); | |
| 1152 } | 1075 } |
| 1153 | 1076 |
| 1154 void VerifyClipTreeCalculations(const LayerImplList& layer_list, | 1077 void VerifyClipTreeCalculations(const LayerImplList& layer_list, |
| 1155 PropertyTrees* property_trees) { | 1078 PropertyTrees* property_trees) { |
| 1156 if (property_trees->non_root_surfaces_enabled) { | 1079 ComputeClipsWithEffectTree(property_trees); |
| 1157 ComputeClipsWithEffectTree(property_trees); | |
| 1158 } | |
| 1159 for (auto* layer : layer_list) | 1080 for (auto* layer : layer_list) |
| 1160 ComputeLayerClipRect(property_trees, layer); | 1081 ComputeLayerClipRect(property_trees, layer); |
| 1161 } | 1082 } |
| 1162 | 1083 |
| 1163 void ComputeVisibleRects(LayerImpl* root_layer, | 1084 void ComputeVisibleRects(LayerImpl* root_layer, |
| 1164 PropertyTrees* property_trees, | 1085 PropertyTrees* property_trees, |
| 1165 bool can_render_to_separate_surface, | |
| 1166 LayerImplList* visible_layer_list) { | 1086 LayerImplList* visible_layer_list) { |
| 1167 for (auto* layer : *root_layer->layer_tree_impl()) { | 1087 for (auto* layer : *root_layer->layer_tree_impl()) { |
| 1168 UpdateRenderSurfaceForLayer(&property_trees->effect_tree, | 1088 UpdateRenderSurfaceForLayer(&property_trees->effect_tree, layer); |
| 1169 can_render_to_separate_surface, layer); | |
| 1170 EffectNode* node = | 1089 EffectNode* node = |
| 1171 property_trees->effect_tree.Node(layer->effect_tree_index()); | 1090 property_trees->effect_tree.Node(layer->effect_tree_index()); |
| 1172 if (node->owning_layer_id == layer->id()) { | 1091 if (node->owning_layer_id == layer->id()) { |
| 1173 node->render_surface = layer->render_surface(); | 1092 node->render_surface = layer->render_surface(); |
| 1174 if (node->render_surface) | 1093 if (node->render_surface) |
| 1175 node->render_surface->set_effect_tree_index(node->id); | 1094 node->render_surface->set_effect_tree_index(node->id); |
| 1176 } | 1095 } |
| 1177 #if DCHECK_IS_ON() | 1096 #if DCHECK_IS_ON() |
| 1178 if (can_render_to_separate_surface) | 1097 ValidateRenderSurfaceForLayer(layer); |
| 1179 ValidateRenderSurfaceForLayer(layer); | |
| 1180 #endif | 1098 #endif |
| 1181 } | 1099 } |
| 1182 ComputeVisibleRectsInternal(root_layer, property_trees, | 1100 ComputeVisibleRectsInternal(root_layer, property_trees, |
| 1183 can_render_to_separate_surface, | |
| 1184 visible_layer_list); | 1101 visible_layer_list); |
| 1185 } | 1102 } |
| 1186 | 1103 |
| 1187 gfx::Rect ComputeLayerVisibleRectDynamic(const PropertyTrees* property_trees, | 1104 gfx::Rect ComputeLayerVisibleRectDynamic(const PropertyTrees* property_trees, |
| 1188 const LayerImpl* layer) { | 1105 const LayerImpl* layer) { |
| 1189 int effect_ancestor_with_copy_request = | 1106 int effect_ancestor_with_copy_request = |
| 1190 property_trees->effect_tree.ClosestAncestorWithCopyRequest( | 1107 property_trees->effect_tree.ClosestAncestorWithCopyRequest( |
| 1191 layer->effect_tree_index()); | 1108 layer->effect_tree_index()); |
| 1192 bool non_root_copy_request = | 1109 bool non_root_copy_request = |
| 1193 effect_ancestor_with_copy_request > EffectTree::kContentsRootNodeId; | 1110 effect_ancestor_with_copy_request > EffectTree::kContentsRootNodeId; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1252 return LayerNeedsUpdateInternal(layer, layer_is_drawn, property_trees); | 1169 return LayerNeedsUpdateInternal(layer, layer_is_drawn, property_trees); |
| 1253 } | 1170 } |
| 1254 | 1171 |
| 1255 gfx::Transform DrawTransform(const LayerImpl* layer, | 1172 gfx::Transform DrawTransform(const LayerImpl* layer, |
| 1256 const TransformTree& transform_tree, | 1173 const TransformTree& transform_tree, |
| 1257 const EffectTree& effect_tree) { | 1174 const EffectTree& effect_tree) { |
| 1258 // TransformTree::ToTarget computes transform between the layer's transform | 1175 // TransformTree::ToTarget computes transform between the layer's transform |
| 1259 // node and surface's transform node and scales it by the surface's content | 1176 // node and surface's transform node and scales it by the surface's content |
| 1260 // scale. | 1177 // scale. |
| 1261 gfx::Transform xform; | 1178 gfx::Transform xform; |
| 1262 if (transform_tree.property_trees()->non_root_surfaces_enabled) | 1179 transform_tree.property_trees()->GetToTarget( |
| 1263 transform_tree.property_trees()->GetToTarget( | 1180 layer->transform_tree_index(), layer->render_target_effect_tree_index(), |
| 1264 layer->transform_tree_index(), layer->render_target_effect_tree_index(), | 1181 &xform); |
| 1265 &xform); | |
| 1266 else | |
| 1267 xform = transform_tree.ToScreen(layer->transform_tree_index()); | |
| 1268 if (layer->should_flatten_transform_from_property_tree()) | 1182 if (layer->should_flatten_transform_from_property_tree()) |
| 1269 xform.FlattenTo2d(); | 1183 xform.FlattenTo2d(); |
| 1270 xform.Translate(layer->offset_to_transform_parent().x(), | 1184 xform.Translate(layer->offset_to_transform_parent().x(), |
| 1271 layer->offset_to_transform_parent().y()); | 1185 layer->offset_to_transform_parent().y()); |
| 1272 return xform; | 1186 return xform; |
| 1273 } | 1187 } |
| 1274 | 1188 |
| 1275 static void SetSurfaceDrawTransform(const PropertyTrees* property_trees, | 1189 static void SetSurfaceDrawTransform(const PropertyTrees* property_trees, |
| 1276 RenderSurfaceImpl* render_surface) { | 1190 RenderSurfaceImpl* render_surface) { |
| 1277 const TransformTree& transform_tree = property_trees->transform_tree; | 1191 const TransformTree& transform_tree = property_trees->transform_tree; |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1414 | 1328 |
| 1415 layer->draw_properties().screen_space_transform = | 1329 layer->draw_properties().screen_space_transform = |
| 1416 ScreenSpaceTransformInternal(layer, property_trees->transform_tree); | 1330 ScreenSpaceTransformInternal(layer, property_trees->transform_tree); |
| 1417 layer->draw_properties().target_space_transform = DrawTransform( | 1331 layer->draw_properties().target_space_transform = DrawTransform( |
| 1418 layer, property_trees->transform_tree, property_trees->effect_tree); | 1332 layer, property_trees->transform_tree, property_trees->effect_tree); |
| 1419 layer->draw_properties().screen_space_transform_is_animating = | 1333 layer->draw_properties().screen_space_transform_is_animating = |
| 1420 transform_node->to_screen_is_potentially_animated; | 1334 transform_node->to_screen_is_potentially_animated; |
| 1421 | 1335 |
| 1422 layer->draw_properties().opacity = | 1336 layer->draw_properties().opacity = |
| 1423 LayerDrawOpacity(layer, property_trees->effect_tree); | 1337 LayerDrawOpacity(layer, property_trees->effect_tree); |
| 1424 if (property_trees->non_root_surfaces_enabled) { | 1338 layer->draw_properties().is_clipped = clip_node->layers_are_clipped; |
| 1425 layer->draw_properties().is_clipped = clip_node->layers_are_clipped; | |
| 1426 } else { | |
| 1427 layer->draw_properties().is_clipped = | |
| 1428 clip_node->layers_are_clipped_when_surfaces_disabled; | |
| 1429 } | |
| 1430 | 1339 |
| 1431 gfx::Rect bounds_in_target_space = MathUtil::MapEnclosingClippedRect( | 1340 gfx::Rect bounds_in_target_space = MathUtil::MapEnclosingClippedRect( |
| 1432 layer->draw_properties().target_space_transform, | 1341 layer->draw_properties().target_space_transform, |
| 1433 gfx::Rect(layer->bounds())); | 1342 gfx::Rect(layer->bounds())); |
| 1434 layer->draw_properties().drawable_content_rect = LayerDrawableContentRect( | 1343 layer->draw_properties().drawable_content_rect = LayerDrawableContentRect( |
| 1435 layer, bounds_in_target_space, layer->draw_properties().clip_rect); | 1344 layer, bounds_in_target_space, layer->draw_properties().clip_rect); |
| 1436 } | 1345 } |
| 1437 | 1346 |
| 1438 void ComputeMaskDrawProperties(LayerImpl* mask_layer, | 1347 void ComputeMaskDrawProperties(LayerImpl* mask_layer, |
| 1439 const PropertyTrees* property_trees) { | 1348 const PropertyTrees* property_trees) { |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1559 void UpdateElasticOverscroll(PropertyTrees* property_trees, | 1468 void UpdateElasticOverscroll(PropertyTrees* property_trees, |
| 1560 const Layer* overscroll_elasticity_layer, | 1469 const Layer* overscroll_elasticity_layer, |
| 1561 const gfx::Vector2dF& elastic_overscroll) { | 1470 const gfx::Vector2dF& elastic_overscroll) { |
| 1562 UpdateElasticOverscrollInternal(property_trees, overscroll_elasticity_layer, | 1471 UpdateElasticOverscrollInternal(property_trees, overscroll_elasticity_layer, |
| 1563 elastic_overscroll); | 1472 elastic_overscroll); |
| 1564 } | 1473 } |
| 1565 | 1474 |
| 1566 } // namespace draw_property_utils | 1475 } // namespace draw_property_utils |
| 1567 | 1476 |
| 1568 } // namespace cc | 1477 } // namespace cc |
| OLD | NEW |