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