| 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 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 534 bool layer_is_drawn; | 534 bool layer_is_drawn; |
| 535 DCHECK_GE(layer->effect_tree_index(), 0); | 535 DCHECK_GE(layer->effect_tree_index(), 0); |
| 536 layer_is_drawn = property_trees->effect_tree.Node(layer->effect_tree_index()) | 536 layer_is_drawn = property_trees->effect_tree.Node(layer->effect_tree_index()) |
| 537 ->data.is_drawn; | 537 ->data.is_drawn; |
| 538 | 538 |
| 539 // The root layer cannot be skipped. | 539 // The root layer cannot be skipped. |
| 540 if (!IsRootLayer(layer) && | 540 if (!IsRootLayer(layer) && |
| 541 draw_property_utils::LayerShouldBeSkipped( | 541 draw_property_utils::LayerShouldBeSkipped( |
| 542 layer, layer_is_drawn, property_trees->transform_tree)) { | 542 layer, layer_is_drawn, property_trees->transform_tree)) { |
| 543 layer->draw_properties().render_target = nullptr; | 543 layer->draw_properties().render_target = nullptr; |
| 544 return; | 544 } else { |
| 545 } | 545 bool render_to_separate_surface = |
| 546 IsRootLayer(layer) || |
| 547 (can_render_to_separate_surface && layer->render_surface()); |
| 546 | 548 |
| 547 bool render_to_separate_surface = | 549 if (render_to_separate_surface) { |
| 548 IsRootLayer(layer) || | 550 DCHECK(layer->render_surface()) << IsRootLayer(layer) |
| 549 (can_render_to_separate_surface && layer->render_surface()); | 551 << can_render_to_separate_surface |
| 552 << layer->has_render_surface(); |
| 553 layer->draw_properties().render_target = layer; |
| 550 | 554 |
| 551 if (render_to_separate_surface) { | 555 if (layer->mask_layer()) |
| 552 DCHECK(layer->render_surface()) << IsRootLayer(layer) | 556 layer->mask_layer()->draw_properties().render_target = layer; |
| 553 << can_render_to_separate_surface | |
| 554 << layer->has_render_surface(); | |
| 555 layer->draw_properties().render_target = layer; | |
| 556 | 557 |
| 557 if (layer->mask_layer()) | 558 if (layer->replica_layer() && layer->replica_layer()->mask_layer()) |
| 558 layer->mask_layer()->draw_properties().render_target = layer; | 559 layer->replica_layer()->mask_layer()->draw_properties().render_target = |
| 560 layer; |
| 559 | 561 |
| 560 if (layer->replica_layer() && layer->replica_layer()->mask_layer()) | 562 } else { |
| 561 layer->replica_layer()->mask_layer()->draw_properties().render_target = | 563 DCHECK(!IsRootLayer(layer)); |
| 562 layer; | 564 layer->draw_properties().render_target = layer->parent()->render_target(); |
| 563 | 565 } |
| 564 } else { | |
| 565 DCHECK(!IsRootLayer(layer)); | |
| 566 layer->draw_properties().render_target = layer->parent()->render_target(); | |
| 567 } | 566 } |
| 568 for (size_t i = 0; i < layer->children().size(); ++i) { | 567 for (size_t i = 0; i < layer->children().size(); ++i) { |
| 569 CalculateRenderTarget( | 568 CalculateRenderTarget( |
| 570 LayerTreeHostCommon::get_layer_as_raw_ptr(layer->children(), i), | 569 LayerTreeHostCommon::get_layer_as_raw_ptr(layer->children(), i), |
| 571 property_trees, layer_is_drawn, can_render_to_separate_surface); | 570 property_trees, layer_is_drawn, can_render_to_separate_surface); |
| 572 } | 571 } |
| 573 } | 572 } |
| 574 | 573 |
| 575 void CalculateRenderSurfaceLayerList( | 574 void CalculateRenderSurfaceLayerList( |
| 576 LayerImpl* layer, | 575 LayerImpl* layer, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 602 layer_is_drawn = property_trees->effect_tree.Node(layer->effect_tree_index()) | 601 layer_is_drawn = property_trees->effect_tree.Node(layer->effect_tree_index()) |
| 603 ->data.is_drawn; | 602 ->data.is_drawn; |
| 604 | 603 |
| 605 // The root layer cannot be skipped. | 604 // The root layer cannot be skipped. |
| 606 if (!IsRootLayer(layer) && | 605 if (!IsRootLayer(layer) && |
| 607 draw_property_utils::LayerShouldBeSkipped( | 606 draw_property_utils::LayerShouldBeSkipped( |
| 608 layer, layer_is_drawn, property_trees->transform_tree)) { | 607 layer, layer_is_drawn, property_trees->transform_tree)) { |
| 609 if (layer->render_surface()) | 608 if (layer->render_surface()) |
| 610 layer->ClearRenderSurfaceLayerList(); | 609 layer->ClearRenderSurfaceLayerList(); |
| 611 layer->draw_properties().render_target = nullptr; | 610 layer->draw_properties().render_target = nullptr; |
| 611 for (auto* child_layer : layer->children()) { |
| 612 CalculateRenderSurfaceLayerList( |
| 613 child_layer, property_trees, render_surface_layer_list, descendants, |
| 614 nearest_occlusion_immune_ancestor, layer_is_drawn, |
| 615 can_render_to_separate_surface, current_render_surface_layer_list_id, |
| 616 max_texture_size); |
| 617 } |
| 612 return; | 618 return; |
| 613 } | 619 } |
| 614 | 620 |
| 615 bool render_to_separate_surface = | 621 bool render_to_separate_surface = |
| 616 IsRootLayer(layer) || | 622 IsRootLayer(layer) || |
| 617 (can_render_to_separate_surface && layer->render_surface()); | 623 (can_render_to_separate_surface && layer->render_surface()); |
| 618 | 624 |
| 619 if (render_to_separate_surface) { | 625 if (render_to_separate_surface) { |
| 620 DCHECK(layer->render_surface()); | 626 DCHECK(layer->render_surface()); |
| 621 draw_property_utils::ComputeSurfaceDrawProperties(property_trees, | 627 draw_property_utils::ComputeSurfaceDrawProperties(property_trees, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 648 } | 654 } |
| 649 layer->render_surface()->SetNearestOcclusionImmuneAncestor( | 655 layer->render_surface()->SetNearestOcclusionImmuneAncestor( |
| 650 nearest_occlusion_immune_ancestor); | 656 nearest_occlusion_immune_ancestor); |
| 651 layer->ClearRenderSurfaceLayerList(); | 657 layer->ClearRenderSurfaceLayerList(); |
| 652 | 658 |
| 653 render_surface_layer_list->push_back(layer); | 659 render_surface_layer_list->push_back(layer); |
| 654 | 660 |
| 655 descendants = &(layer->render_surface()->layer_list()); | 661 descendants = &(layer->render_surface()->layer_list()); |
| 656 } | 662 } |
| 657 | 663 |
| 658 size_t descendants_size = descendants->size(); | |
| 659 | |
| 660 bool layer_should_be_skipped = !draw_property_utils::LayerNeedsUpdate( | 664 bool layer_should_be_skipped = !draw_property_utils::LayerNeedsUpdate( |
| 661 layer, layer_is_drawn, property_trees->transform_tree); | 665 layer, layer_is_drawn, property_trees->transform_tree); |
| 662 if (!layer_should_be_skipped) { | 666 if (!layer_should_be_skipped) { |
| 667 DCHECK(layer->draw_properties().render_target); |
| 663 MarkLayerWithRenderSurfaceLayerListId(layer, | 668 MarkLayerWithRenderSurfaceLayerListId(layer, |
| 664 current_render_surface_layer_list_id); | 669 current_render_surface_layer_list_id); |
| 665 descendants->push_back(layer); | 670 descendants->push_back(layer); |
| 666 } | 671 } |
| 667 | 672 |
| 668 | 673 |
| 669 // Clear the old accumulated content rect of surface. | 674 // Clear the old accumulated content rect of surface. |
| 670 if (render_to_separate_surface) | 675 if (render_to_separate_surface) |
| 671 layer->render_surface()->SetAccumulatedContentRect(gfx::Rect()); | 676 layer->render_surface()->SetAccumulatedContentRect(gfx::Rect()); |
| 672 | 677 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 731 } | 736 } |
| 732 // The RenderSurfaceImpl backing texture cannot exceed the maximum | 737 // The RenderSurfaceImpl backing texture cannot exceed the maximum |
| 733 // supported texture size. | 738 // supported texture size. |
| 734 surface_content_rect.set_width( | 739 surface_content_rect.set_width( |
| 735 std::min(surface_content_rect.width(), max_texture_size)); | 740 std::min(surface_content_rect.width(), max_texture_size)); |
| 736 surface_content_rect.set_height( | 741 surface_content_rect.set_height( |
| 737 std::min(surface_content_rect.height(), max_texture_size)); | 742 std::min(surface_content_rect.height(), max_texture_size)); |
| 738 layer->render_surface()->SetContentRect(surface_content_rect); | 743 layer->render_surface()->SetContentRect(surface_content_rect); |
| 739 } | 744 } |
| 740 const LayerImpl* parent_target = layer->parent()->render_target(); | 745 const LayerImpl* parent_target = layer->parent()->render_target(); |
| 741 if (!IsRootLayer(parent_target)) { | 746 if (parent_target && !IsRootLayer(parent_target)) { |
| 742 gfx::Rect surface_content_rect = | 747 gfx::Rect surface_content_rect = |
| 743 parent_target->render_surface()->accumulated_content_rect(); | 748 parent_target->render_surface()->accumulated_content_rect(); |
| 744 if (render_to_separate_surface) { | 749 if (render_to_separate_surface) { |
| 745 // If the layer owns a surface, then the content rect is in the wrong | 750 // If the layer owns a surface, then the content rect is in the wrong |
| 746 // space. Instead, we will use the surface's DrawableContentRect which | 751 // 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 | 752 // is in target space as required. We also need to clip it with the |
| 748 // target's clip if the target is clipped. | 753 // target's clip if the target is clipped. |
| 749 surface_content_rect.Union(gfx::ToEnclosedRect( | 754 surface_content_rect.Union(gfx::ToEnclosedRect( |
| 750 layer->render_surface()->DrawableContentRect())); | 755 layer->render_surface()->DrawableContentRect())); |
| 751 if (parent_target->is_clipped()) | 756 if (parent_target->is_clipped()) |
| 752 surface_content_rect.Intersect(parent_target->clip_rect()); | 757 surface_content_rect.Intersect(parent_target->clip_rect()); |
| 753 } else if (layer->DrawsContent()) { | 758 } else if (layer->DrawsContent()) { |
| 754 surface_content_rect.Union(layer->drawable_content_rect()); | 759 surface_content_rect.Union(layer->drawable_content_rect()); |
| 755 } | 760 } |
| 756 parent_target->render_surface()->SetAccumulatedContentRect( | 761 parent_target->render_surface()->SetAccumulatedContentRect( |
| 757 surface_content_rect); | 762 surface_content_rect); |
| 758 } | 763 } |
| 759 } else { | 764 } else { |
| 760 // The root layer's surface content rect is always the entire viewport. | 765 // The root layer's surface content rect is always the entire viewport. |
| 761 gfx::Rect viewport = | 766 gfx::Rect viewport = |
| 762 gfx::ToEnclosingRect(property_trees->clip_tree.ViewportClip()); | 767 gfx::ToEnclosingRect(property_trees->clip_tree.ViewportClip()); |
| 763 layer->render_surface()->SetContentRect(viewport); | 768 layer->render_surface()->SetContentRect(viewport); |
| 764 } | 769 } |
| 765 | 770 |
| 766 if (render_to_separate_surface && !IsRootLayer(layer) && | 771 if (render_to_separate_surface && !IsRootLayer(layer) && |
| 767 layer->render_surface()->DrawableContentRect().IsEmpty()) { | 772 layer->render_surface()->DrawableContentRect().IsEmpty()) { |
| 768 RemoveSurfaceForEarlyExit(layer, render_surface_layer_list); | 773 RemoveSurfaceForEarlyExit(layer, render_surface_layer_list); |
| 769 return; | |
| 770 } | |
| 771 | |
| 772 // If neither this layer nor any of its children were added, early out. | |
| 773 if (descendants_size == descendants->size()) { | |
| 774 DCHECK(!render_to_separate_surface || IsRootLayer(layer)); | |
| 775 return; | |
| 776 } | 774 } |
| 777 } | 775 } |
| 778 | 776 |
| 779 static void ComputeMaskLayerDrawProperties(const LayerImpl* layer, | 777 static void ComputeMaskLayerDrawProperties(const LayerImpl* layer, |
| 780 LayerImpl* mask_layer) { | 778 LayerImpl* mask_layer) { |
| 781 DrawProperties& mask_layer_draw_properties = mask_layer->draw_properties(); | 779 DrawProperties& mask_layer_draw_properties = mask_layer->draw_properties(); |
| 782 mask_layer_draw_properties.visible_layer_rect = gfx::Rect(layer->bounds()); | 780 mask_layer_draw_properties.visible_layer_rect = gfx::Rect(layer->bounds()); |
| 783 mask_layer_draw_properties.target_space_transform = | 781 mask_layer_draw_properties.target_space_transform = |
| 784 layer->draw_properties().target_space_transform; | 782 layer->draw_properties().target_space_transform; |
| 785 mask_layer_draw_properties.screen_space_transform = | 783 mask_layer_draw_properties.screen_space_transform = |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 866 } | 864 } |
| 867 | 865 |
| 868 if (should_measure_property_tree_performance) { | 866 if (should_measure_property_tree_performance) { |
| 869 TRACE_EVENT_BEGIN0(TRACE_DISABLED_BY_DEFAULT("cc.debug.cdp-perf"), | 867 TRACE_EVENT_BEGIN0(TRACE_DISABLED_BY_DEFAULT("cc.debug.cdp-perf"), |
| 870 "LayerTreeHostCommon::CalculateDrawProperties"); | 868 "LayerTreeHostCommon::CalculateDrawProperties"); |
| 871 } | 869 } |
| 872 | 870 |
| 873 DCHECK(inputs->can_render_to_separate_surface == | 871 DCHECK(inputs->can_render_to_separate_surface == |
| 874 inputs->property_trees->non_root_surfaces_enabled); | 872 inputs->property_trees->non_root_surfaces_enabled); |
| 875 const bool subtree_visible_from_ancestor = true; | 873 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, | 874 CalculateRenderTarget(inputs->root_layer, inputs->property_trees, |
| 879 subtree_visible_from_ancestor, | 875 subtree_visible_from_ancestor, |
| 880 inputs->can_render_to_separate_surface); | 876 inputs->can_render_to_separate_surface); |
| 881 for (LayerImpl* layer : visible_layer_list) { | 877 for (LayerImpl* layer : visible_layer_list) { |
| 882 draw_property_utils::ComputeLayerDrawProperties( | 878 draw_property_utils::ComputeLayerDrawProperties( |
| 883 layer, inputs->property_trees, inputs->layers_always_allowed_lcd_text, | 879 layer, inputs->property_trees, inputs->layers_always_allowed_lcd_text, |
| 884 inputs->can_use_lcd_text); | 880 inputs->can_use_lcd_text); |
| 885 if (layer->mask_layer()) | 881 if (layer->mask_layer()) |
| 886 ComputeMaskLayerDrawProperties(layer, layer->mask_layer()); | 882 ComputeMaskLayerDrawProperties(layer, layer->mask_layer()); |
| 887 LayerImpl* replica_mask_layer = | 883 LayerImpl* replica_mask_layer = |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 993 | 989 |
| 994 PropertyTrees* GetPropertyTrees(Layer* layer) { | 990 PropertyTrees* GetPropertyTrees(Layer* layer) { |
| 995 return layer->layer_tree_host()->property_trees(); | 991 return layer->layer_tree_host()->property_trees(); |
| 996 } | 992 } |
| 997 | 993 |
| 998 PropertyTrees* GetPropertyTrees(LayerImpl* layer) { | 994 PropertyTrees* GetPropertyTrees(LayerImpl* layer) { |
| 999 return layer->layer_tree_impl()->property_trees(); | 995 return layer->layer_tree_impl()->property_trees(); |
| 1000 } | 996 } |
| 1001 | 997 |
| 1002 } // namespace cc | 998 } // namespace cc |
| OLD | NEW |