| OLD | NEW |
| 1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 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/layer_tree_host_common.h" | 5 #include "cc/trees/layer_tree_host_common.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| (...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 520 } | 520 } |
| 521 } | 521 } |
| 522 return jitter; | 522 return jitter; |
| 523 } | 523 } |
| 524 | 524 |
| 525 enum PropertyTreeOption { | 525 enum PropertyTreeOption { |
| 526 BUILD_PROPERTY_TREES_IF_NEEDED, | 526 BUILD_PROPERTY_TREES_IF_NEEDED, |
| 527 DONT_BUILD_PROPERTY_TREES | 527 DONT_BUILD_PROPERTY_TREES |
| 528 }; | 528 }; |
| 529 | 529 |
| 530 void CalculateRenderTarget(LayerImpl* layer, | |
| 531 PropertyTrees* property_trees, | |
| 532 bool subtree_visible_from_ancestor, | |
| 533 bool can_render_to_separate_surface) { | |
| 534 bool layer_is_drawn; | |
| 535 DCHECK_GE(layer->effect_tree_index(), 0); | |
| 536 layer_is_drawn = property_trees->effect_tree.Node(layer->effect_tree_index()) | |
| 537 ->data.is_drawn; | |
| 538 | |
| 539 // The root layer cannot be skipped. | |
| 540 if (!IsRootLayer(layer) && | |
| 541 draw_property_utils::LayerShouldBeSkipped( | |
| 542 layer, layer_is_drawn, property_trees->transform_tree)) { | |
| 543 layer->draw_properties().render_target = nullptr; | |
| 544 return; | |
| 545 } | |
| 546 | |
| 547 bool render_to_separate_surface = | |
| 548 IsRootLayer(layer) || | |
| 549 (can_render_to_separate_surface && layer->render_surface()); | |
| 550 | |
| 551 if (render_to_separate_surface) { | |
| 552 DCHECK(layer->render_surface()) << IsRootLayer(layer) | |
| 553 << can_render_to_separate_surface | |
| 554 << layer->has_render_surface(); | |
| 555 layer->draw_properties().render_target = layer; | |
| 556 | |
| 557 if (layer->mask_layer()) | |
| 558 layer->mask_layer()->draw_properties().render_target = layer; | |
| 559 | |
| 560 if (layer->replica_layer() && layer->replica_layer()->mask_layer()) | |
| 561 layer->replica_layer()->mask_layer()->draw_properties().render_target = | |
| 562 layer; | |
| 563 | |
| 564 } else { | |
| 565 DCHECK(!IsRootLayer(layer)); | |
| 566 layer->draw_properties().render_target = layer->parent()->render_target(); | |
| 567 } | |
| 568 for (size_t i = 0; i < layer->children().size(); ++i) { | |
| 569 CalculateRenderTarget( | |
| 570 LayerTreeHostCommon::get_layer_as_raw_ptr(layer->children(), i), | |
| 571 property_trees, layer_is_drawn, can_render_to_separate_surface); | |
| 572 } | |
| 573 } | |
| 574 | |
| 575 void CalculateRenderSurfaceLayerList( | 530 void CalculateRenderSurfaceLayerList( |
| 576 LayerImpl* layer, | 531 LayerImpl* layer, |
| 577 PropertyTrees* property_trees, | 532 PropertyTrees* property_trees, |
| 578 LayerImplList* render_surface_layer_list, | 533 LayerImplList* render_surface_layer_list, |
| 579 LayerImplList* descendants, | 534 LayerImplList* descendants, |
| 580 RenderSurfaceImpl* nearest_occlusion_immune_ancestor, | 535 RenderSurfaceImpl* nearest_occlusion_immune_ancestor, |
| 581 bool subtree_visible_from_ancestor, | 536 bool subtree_visible_from_ancestor, |
| 582 const bool can_render_to_separate_surface, | 537 const bool can_render_to_separate_surface, |
| 583 const int current_render_surface_layer_list_id, | 538 const int current_render_surface_layer_list_id, |
| 584 const int max_texture_size) { | 539 const int max_texture_size) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 601 DCHECK_GE(layer->effect_tree_index(), 0); | 556 DCHECK_GE(layer->effect_tree_index(), 0); |
| 602 layer_is_drawn = property_trees->effect_tree.Node(layer->effect_tree_index()) | 557 layer_is_drawn = property_trees->effect_tree.Node(layer->effect_tree_index()) |
| 603 ->data.is_drawn; | 558 ->data.is_drawn; |
| 604 | 559 |
| 605 // The root layer cannot be skipped. | 560 // The root layer cannot be skipped. |
| 606 if (!IsRootLayer(layer) && | 561 if (!IsRootLayer(layer) && |
| 607 draw_property_utils::LayerShouldBeSkipped( | 562 draw_property_utils::LayerShouldBeSkipped( |
| 608 layer, layer_is_drawn, property_trees->transform_tree)) { | 563 layer, layer_is_drawn, property_trees->transform_tree)) { |
| 609 if (layer->render_surface()) | 564 if (layer->render_surface()) |
| 610 layer->ClearRenderSurfaceLayerList(); | 565 layer->ClearRenderSurfaceLayerList(); |
| 611 layer->draw_properties().render_target = nullptr; | |
| 612 return; | 566 return; |
| 613 } | 567 } |
| 614 | 568 |
| 615 bool render_to_separate_surface = | 569 bool render_to_separate_surface = |
| 616 IsRootLayer(layer) || | 570 IsRootLayer(layer) || |
| 617 (can_render_to_separate_surface && layer->render_surface()); | 571 (can_render_to_separate_surface && layer->render_surface()); |
| 618 | 572 |
| 619 if (render_to_separate_surface) { | 573 if (render_to_separate_surface) { |
| 620 DCHECK(layer->render_surface()); | 574 DCHECK(layer->render_surface()); |
| 621 draw_property_utils::ComputeSurfaceDrawProperties(property_trees, | 575 draw_property_utils::ComputeSurfaceDrawProperties(property_trees, |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 661 layer, layer_is_drawn, property_trees->transform_tree); | 615 layer, layer_is_drawn, property_trees->transform_tree); |
| 662 if (!layer_should_be_skipped) { | 616 if (!layer_should_be_skipped) { |
| 663 MarkLayerWithRenderSurfaceLayerListId(layer, | 617 MarkLayerWithRenderSurfaceLayerListId(layer, |
| 664 current_render_surface_layer_list_id); | 618 current_render_surface_layer_list_id); |
| 665 descendants->push_back(layer); | 619 descendants->push_back(layer); |
| 666 } | 620 } |
| 667 | 621 |
| 668 | 622 |
| 669 // Clear the old accumulated content rect of surface. | 623 // Clear the old accumulated content rect of surface. |
| 670 if (render_to_separate_surface) | 624 if (render_to_separate_surface) |
| 671 layer->render_surface()->SetAccumulatedContentRect(gfx::Rect()); | 625 layer->render_surface()->ClearAccumulatedContentRect(); |
| 672 | 626 |
| 673 for (auto* child_layer : layer->children()) { | 627 for (auto* child_layer : layer->children()) { |
| 674 CalculateRenderSurfaceLayerList( | 628 CalculateRenderSurfaceLayerList( |
| 675 child_layer, property_trees, render_surface_layer_list, descendants, | 629 child_layer, property_trees, render_surface_layer_list, descendants, |
| 676 nearest_occlusion_immune_ancestor, layer_is_drawn, | 630 nearest_occlusion_immune_ancestor, layer_is_drawn, |
| 677 can_render_to_separate_surface, current_render_surface_layer_list_id, | 631 can_render_to_separate_surface, current_render_surface_layer_list_id, |
| 678 max_texture_size); | 632 max_texture_size); |
| 679 | 633 |
| 680 // If the child is its own render target, then it has a render surface. | 634 // If the child is its own render target, then it has a render surface. |
| 681 if (child_layer->render_target() == child_layer && | 635 if (child_layer->has_render_surface() && |
| 636 child_layer->render_target() == child_layer->render_surface() && |
| 682 !child_layer->render_surface()->layer_list().empty() && | 637 !child_layer->render_surface()->layer_list().empty() && |
| 683 !child_layer->render_surface()->content_rect().IsEmpty()) { | 638 !child_layer->render_surface()->content_rect().IsEmpty()) { |
| 684 // This child will contribute its render surface, which means | 639 // This child will contribute its render surface, which means |
| 685 // we need to mark just the mask layer (and replica mask layer) | 640 // we need to mark just the mask layer (and replica mask layer) |
| 686 // with the id. | 641 // with the id. |
| 687 MarkMasksWithRenderSurfaceLayerListId( | 642 MarkMasksWithRenderSurfaceLayerListId( |
| 688 child_layer, current_render_surface_layer_list_id); | 643 child_layer, current_render_surface_layer_list_id); |
| 689 descendants->push_back(child_layer); | 644 descendants->push_back(child_layer); |
| 690 } | 645 } |
| 691 | 646 |
| 692 if (child_layer->layer_or_descendant_is_drawn()) { | 647 if (child_layer->layer_or_descendant_is_drawn()) { |
| 693 bool layer_or_descendant_is_drawn = true; | 648 bool layer_or_descendant_is_drawn = true; |
| 694 layer->set_layer_or_descendant_is_drawn(layer_or_descendant_is_drawn); | 649 layer->set_layer_or_descendant_is_drawn(layer_or_descendant_is_drawn); |
| 695 } | 650 } |
| 696 } | 651 } |
| 697 | 652 |
| 698 if (render_to_separate_surface && !IsRootLayer(layer) && | 653 if (render_to_separate_surface && !IsRootLayer(layer) && |
| 699 layer->render_surface()->layer_list().empty()) { | 654 layer->render_surface()->layer_list().empty()) { |
| 700 RemoveSurfaceForEarlyExit(layer, render_surface_layer_list); | 655 RemoveSurfaceForEarlyExit(layer, render_surface_layer_list); |
| 701 return; | 656 return; |
| 702 } | 657 } |
| 703 | 658 |
| 704 // The render surface's content rect is the union of drawable content rects | 659 // The render surface's content rect is the union of drawable content rects |
| 705 // of the layers that draw into the surface. If the render surface is clipped, | 660 // of the layers that draw into the surface. If the render surface is clipped, |
| 706 // it is also intersected with the render's surface clip rect. | 661 // it is also intersected with the render's surface clip rect. |
| 707 if (!IsRootLayer(layer)) { | 662 if (!IsRootLayer(layer)) { |
| 663 // Layer contriubutes its drawable content rect to its render target. |
| 664 if (layer->DrawsContent()) |
| 665 layer->render_target()->AccumulateContentRectFromContributingLayer(layer); |
| 666 |
| 708 if (render_to_separate_surface) { | 667 if (render_to_separate_surface) { |
| 709 gfx::Rect surface_content_rect = | 668 gfx::Rect surface_content_rect = |
| 710 layer->render_surface()->accumulated_content_rect(); | 669 layer->render_surface()->accumulated_content_rect(); |
| 711 // If the owning layer of a render surface draws content, the content | |
| 712 // rect of the render surface is expanded to include the drawable | |
| 713 // content rect of the layer. | |
| 714 if (layer->DrawsContent()) | |
| 715 surface_content_rect.Union(layer->drawable_content_rect()); | |
| 716 | 670 |
| 717 if (!layer->replica_layer() && !layer->HasCopyRequest() && | 671 if (!layer->replica_layer() && !layer->HasCopyRequest() && |
| 718 layer->render_surface()->is_clipped()) { | 672 layer->render_surface()->is_clipped()) { |
| 719 // Here, we clip the render surface's content rect with its clip rect. | 673 // Here, we clip the render surface's content rect with its clip rect. |
| 720 // As the clip rect of render surface is in the surface's target | 674 // As the clip rect of render surface is in the surface's target |
| 721 // space, we first map the content rect into the target space, | 675 // space, we first map the content rect into the target space, |
| 722 // intersect it with clip rect and project back the result to the | 676 // intersect it with clip rect and project back the result to the |
| 723 // surface space. | 677 // surface space. |
| 724 if (!surface_content_rect.IsEmpty()) { | 678 if (!surface_content_rect.IsEmpty()) { |
| 725 gfx::Rect surface_clip_rect = | 679 gfx::Rect surface_clip_rect = |
| 726 LayerTreeHostCommon::CalculateVisibleRect( | 680 LayerTreeHostCommon::CalculateVisibleRect( |
| 727 layer->render_surface()->clip_rect(), surface_content_rect, | 681 layer->render_surface()->clip_rect(), surface_content_rect, |
| 728 layer->render_surface()->draw_transform()); | 682 layer->render_surface()->draw_transform()); |
| 729 surface_content_rect.Intersect(surface_clip_rect); | 683 surface_content_rect.Intersect(surface_clip_rect); |
| 730 } | 684 } |
| 731 } | 685 } |
| 732 // The RenderSurfaceImpl backing texture cannot exceed the maximum | 686 // The RenderSurfaceImpl backing texture cannot exceed the maximum |
| 733 // supported texture size. | 687 // supported texture size. |
| 734 surface_content_rect.set_width( | 688 surface_content_rect.set_width( |
| 735 std::min(surface_content_rect.width(), max_texture_size)); | 689 std::min(surface_content_rect.width(), max_texture_size)); |
| 736 surface_content_rect.set_height( | 690 surface_content_rect.set_height( |
| 737 std::min(surface_content_rect.height(), max_texture_size)); | 691 std::min(surface_content_rect.height(), max_texture_size)); |
| 738 layer->render_surface()->SetContentRect(surface_content_rect); | 692 layer->render_surface()->SetContentRect(surface_content_rect); |
| 739 } | 693 |
| 740 const LayerImpl* parent_target = layer->parent()->render_target(); | 694 // Now the render surface's content rect is calculated correctly, it could |
| 741 if (!IsRootLayer(parent_target)) { | 695 // contribute to its render target. |
| 742 gfx::Rect surface_content_rect = | 696 layer->render_surface() |
| 743 parent_target->render_surface()->accumulated_content_rect(); | 697 ->render_target() |
| 744 if (render_to_separate_surface) { | 698 ->AccumulateContentRectFromContributingRenderSurface( |
| 745 // If the layer owns a surface, then the content rect is in the wrong | 699 layer->render_surface()); |
| 746 // space. Instead, we will use the surface's DrawableContentRect which | |
| 747 // is in target space as required. We also need to clip it with the | |
| 748 // target's clip if the target is clipped. | |
| 749 surface_content_rect.Union(gfx::ToEnclosedRect( | |
| 750 layer->render_surface()->DrawableContentRect())); | |
| 751 if (parent_target->is_clipped()) | |
| 752 surface_content_rect.Intersect(parent_target->clip_rect()); | |
| 753 } else if (layer->DrawsContent()) { | |
| 754 surface_content_rect.Union(layer->drawable_content_rect()); | |
| 755 } | |
| 756 parent_target->render_surface()->SetAccumulatedContentRect( | |
| 757 surface_content_rect); | |
| 758 } | 700 } |
| 759 } else { | 701 } else { |
| 760 // The root layer's surface content rect is always the entire viewport. | 702 // The root layer's surface content rect is always the entire viewport. |
| 761 gfx::Rect viewport = | 703 gfx::Rect viewport = |
| 762 gfx::ToEnclosingRect(property_trees->clip_tree.ViewportClip()); | 704 gfx::ToEnclosingRect(property_trees->clip_tree.ViewportClip()); |
| 763 layer->render_surface()->SetContentRect(viewport); | 705 layer->render_surface()->SetContentRect(viewport); |
| 764 } | 706 } |
| 765 | 707 |
| 766 if (render_to_separate_surface && !IsRootLayer(layer) && | 708 if (render_to_separate_surface && !IsRootLayer(layer) && |
| 767 layer->render_surface()->DrawableContentRect().IsEmpty()) { | 709 layer->render_surface()->DrawableContentRect().IsEmpty()) { |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 866 } | 808 } |
| 867 | 809 |
| 868 if (should_measure_property_tree_performance) { | 810 if (should_measure_property_tree_performance) { |
| 869 TRACE_EVENT_BEGIN0(TRACE_DISABLED_BY_DEFAULT("cc.debug.cdp-perf"), | 811 TRACE_EVENT_BEGIN0(TRACE_DISABLED_BY_DEFAULT("cc.debug.cdp-perf"), |
| 870 "LayerTreeHostCommon::CalculateDrawProperties"); | 812 "LayerTreeHostCommon::CalculateDrawProperties"); |
| 871 } | 813 } |
| 872 | 814 |
| 873 DCHECK(inputs->can_render_to_separate_surface == | 815 DCHECK(inputs->can_render_to_separate_surface == |
| 874 inputs->property_trees->non_root_surfaces_enabled); | 816 inputs->property_trees->non_root_surfaces_enabled); |
| 875 const bool subtree_visible_from_ancestor = true; | 817 const bool subtree_visible_from_ancestor = true; |
| 876 for (auto* layer : *inputs->root_layer->layer_tree_impl()) | |
| 877 layer->draw_properties().render_target = nullptr; | |
| 878 CalculateRenderTarget(inputs->root_layer, inputs->property_trees, | |
| 879 subtree_visible_from_ancestor, | |
| 880 inputs->can_render_to_separate_surface); | |
| 881 for (LayerImpl* layer : visible_layer_list) { | 818 for (LayerImpl* layer : visible_layer_list) { |
| 882 draw_property_utils::ComputeLayerDrawProperties( | 819 draw_property_utils::ComputeLayerDrawProperties( |
| 883 layer, inputs->property_trees, inputs->layers_always_allowed_lcd_text, | 820 layer, inputs->property_trees, inputs->layers_always_allowed_lcd_text, |
| 884 inputs->can_use_lcd_text); | 821 inputs->can_use_lcd_text); |
| 885 if (layer->mask_layer()) | 822 if (layer->mask_layer()) |
| 886 ComputeMaskLayerDrawProperties(layer, layer->mask_layer()); | 823 ComputeMaskLayerDrawProperties(layer, layer->mask_layer()); |
| 887 LayerImpl* replica_mask_layer = | 824 LayerImpl* replica_mask_layer = |
| 888 layer->replica_layer() ? layer->replica_layer()->mask_layer() : nullptr; | 825 layer->replica_layer() ? layer->replica_layer()->mask_layer() : nullptr; |
| 889 if (replica_mask_layer) | 826 if (replica_mask_layer) |
| 890 ComputeMaskLayerDrawProperties(layer, replica_mask_layer); | 827 ComputeMaskLayerDrawProperties(layer, replica_mask_layer); |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 993 | 930 |
| 994 PropertyTrees* GetPropertyTrees(Layer* layer) { | 931 PropertyTrees* GetPropertyTrees(Layer* layer) { |
| 995 return layer->layer_tree_host()->property_trees(); | 932 return layer->layer_tree_host()->property_trees(); |
| 996 } | 933 } |
| 997 | 934 |
| 998 PropertyTrees* GetPropertyTrees(LayerImpl* layer) { | 935 PropertyTrees* GetPropertyTrees(LayerImpl* layer) { |
| 999 return layer->layer_tree_impl()->property_trees(); | 936 return layer->layer_tree_impl()->property_trees(); |
| 1000 } | 937 } |
| 1001 | 938 |
| 1002 } // namespace cc | 939 } // namespace cc |
| OLD | NEW |