Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Side by Side Diff: cc/trees/layer_tree_host_common_unittest.cc

Issue 1221273003: cc: Convert backface LTHCommon tests from Layer->LayerImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@delete_main_thread_cdp
Patch Set: Swap arg order Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/trees/draw_property_utils.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <algorithm> 7 #include <algorithm>
8 #include <set> 8 #include <set>
9 9
10 #include "cc/animation/layer_animation_controller.h" 10 #include "cc/animation/layer_animation_controller.h"
(...skipping 3600 matching lines...) Expand 10 before | Expand all | Expand 10 after
3611 true, 3611 true,
3612 false); 3612 false);
3613 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(), 3613 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(),
3614 backface_matrix, 3614 backface_matrix,
3615 gfx::Point3F(), 3615 gfx::Point3F(),
3616 gfx::PointF(), 3616 gfx::PointF(),
3617 gfx::Size(100, 100), 3617 gfx::Size(100, 100),
3618 true, 3618 true,
3619 false); 3619 false);
3620 3620
3621 RenderSurfaceLayerList render_surface_layer_list; 3621 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent.get());
3622 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
3623 parent.get(), parent->bounds(), &render_surface_layer_list);
3624 inputs.can_adjust_raster_scales = true;
3625 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
3626 3622
3627 // Verify which render surfaces were created. 3623 // Verify which render surfaces were created.
3628 EXPECT_FALSE(front_facing_child->render_surface()); 3624 EXPECT_FALSE(front_facing_child->render_surface());
3629 EXPECT_FALSE(back_facing_child->render_surface()); 3625 EXPECT_FALSE(back_facing_child->render_surface());
3630 EXPECT_TRUE(front_facing_surface->render_surface()); 3626 EXPECT_TRUE(front_facing_surface->render_surface());
3631 EXPECT_TRUE(back_facing_surface->render_surface()); 3627 EXPECT_TRUE(back_facing_surface->render_surface());
3632 EXPECT_FALSE(front_facing_child_of_front_facing_surface->render_surface()); 3628 EXPECT_FALSE(front_facing_child_of_front_facing_surface->render_surface());
3633 EXPECT_FALSE(back_facing_child_of_front_facing_surface->render_surface()); 3629 EXPECT_FALSE(back_facing_child_of_front_facing_surface->render_surface());
3634 EXPECT_FALSE(front_facing_child_of_back_facing_surface->render_surface()); 3630 EXPECT_FALSE(front_facing_child_of_back_facing_surface->render_surface());
3635 EXPECT_FALSE(back_facing_child_of_back_facing_surface->render_surface()); 3631 EXPECT_FALSE(back_facing_child_of_back_facing_surface->render_surface());
3636 3632
3637 // Verify the render_surface_layer_list. 3633 EXPECT_EQ(4u, update_layer_list().size());
3638 ASSERT_EQ(3u, render_surface_layer_list.size()); 3634 EXPECT_TRUE(UpdateLayerListContains(front_facing_child->id()));
3639 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id()); 3635 EXPECT_TRUE(UpdateLayerListContains(front_facing_surface->id()));
3640 EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id()); 3636 EXPECT_TRUE(UpdateLayerListContains(
3641 // Even though the back facing surface LAYER gets culled, the other 3637 front_facing_child_of_front_facing_surface->id()));
3642 // descendants should still be added, so the SURFACE should not be culled. 3638 EXPECT_TRUE(
3643 EXPECT_EQ(back_facing_surface->id(), render_surface_layer_list.at(2)->id()); 3639 UpdateLayerListContains(front_facing_child_of_back_facing_surface->id()));
3644
3645 // Verify root surface's layer list.
3646 ASSERT_EQ(
3647 3u,
3648 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
3649 EXPECT_EQ(front_facing_child->id(),
3650 render_surface_layer_list.at(0)
3651 ->render_surface()
3652 ->layer_list()
3653 .at(0)
3654 ->id());
3655 EXPECT_EQ(front_facing_surface->id(),
3656 render_surface_layer_list.at(0)
3657 ->render_surface()
3658 ->layer_list()
3659 .at(1)
3660 ->id());
3661 EXPECT_EQ(back_facing_surface->id(),
3662 render_surface_layer_list.at(0)
3663 ->render_surface()
3664 ->layer_list()
3665 .at(2)
3666 ->id());
3667
3668 // Verify front_facing_surface's layer list.
3669 ASSERT_EQ(
3670 2u,
3671 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
3672 EXPECT_EQ(front_facing_surface->id(),
3673 render_surface_layer_list.at(1)
3674 ->render_surface()
3675 ->layer_list()
3676 .at(0)
3677 ->id());
3678 EXPECT_EQ(front_facing_child_of_front_facing_surface->id(),
3679 render_surface_layer_list.at(1)
3680 ->render_surface()
3681 ->layer_list()
3682 .at(1)
3683 ->id());
3684
3685 // Verify back_facing_surface's layer list; its own layer should be culled
3686 // from the surface list.
3687 ASSERT_EQ(
3688 1u,
3689 render_surface_layer_list.at(2)->render_surface()->layer_list().size());
3690 EXPECT_EQ(front_facing_child_of_back_facing_surface->id(),
3691 render_surface_layer_list.at(2)
3692 ->render_surface()
3693 ->layer_list()
3694 .at(0)
3695 ->id());
3696 } 3640 }
3697 3641
3698 TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithPreserves3d) { 3642 TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithPreserves3d) {
3699 // Verify the behavior of back-face culling when preserves-3d transform style 3643 // Verify the behavior of back-face culling when preserves-3d transform style
3700 // is used. 3644 // is used.
3701 3645
3702 const gfx::Transform identity_matrix; 3646 const gfx::Transform identity_matrix;
3703 scoped_refptr<Layer> parent = Layer::Create(layer_settings()); 3647 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
3704 scoped_refptr<LayerWithForcedDrawsContent> front_facing_child = 3648 scoped_refptr<LayerWithForcedDrawsContent> front_facing_child =
3705 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings())); 3649 make_scoped_refptr(new LayerWithForcedDrawsContent(layer_settings()));
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
3822 true, 3766 true,
3823 true); 3767 true);
3824 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(), 3768 SetLayerPropertiesForTesting(back_facing_child_of_back_facing_surface.get(),
3825 backface_matrix, 3769 backface_matrix,
3826 gfx::Point3F(), 3770 gfx::Point3F(),
3827 gfx::PointF(), 3771 gfx::PointF(),
3828 gfx::Size(100, 100), 3772 gfx::Size(100, 100),
3829 true, 3773 true,
3830 true); 3774 true);
3831 3775
3832 RenderSurfaceLayerList render_surface_layer_list; 3776 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent.get());
3833 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
3834 parent.get(), parent->bounds(), &render_surface_layer_list);
3835 inputs.can_adjust_raster_scales = true;
3836 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
3837 3777
3838 // Verify which render surfaces were created and used. 3778 // Verify which render surfaces were created and used.
3839 EXPECT_FALSE(front_facing_child->render_surface()); 3779 EXPECT_FALSE(front_facing_child->render_surface());
3840 EXPECT_FALSE(back_facing_child->render_surface()); 3780 EXPECT_FALSE(back_facing_child->render_surface());
3841 EXPECT_TRUE(front_facing_surface->render_surface()); 3781 EXPECT_TRUE(front_facing_surface->render_surface());
3842 EXPECT_NE(back_facing_surface->render_target(), back_facing_surface); 3782 EXPECT_NE(back_facing_surface->render_target(), back_facing_surface);
3843 // We expect that a render_surface was created but not used. 3783 // We expect that a render_surface was created but not used.
3844 EXPECT_TRUE(back_facing_surface->render_surface()); 3784 EXPECT_TRUE(back_facing_surface->render_surface());
3845 EXPECT_FALSE(front_facing_child_of_front_facing_surface->render_surface()); 3785 EXPECT_FALSE(front_facing_child_of_front_facing_surface->render_surface());
3846 EXPECT_FALSE(back_facing_child_of_front_facing_surface->render_surface()); 3786 EXPECT_FALSE(back_facing_child_of_front_facing_surface->render_surface());
3847 EXPECT_FALSE(front_facing_child_of_back_facing_surface->render_surface()); 3787 EXPECT_FALSE(front_facing_child_of_back_facing_surface->render_surface());
3848 EXPECT_FALSE(back_facing_child_of_back_facing_surface->render_surface()); 3788 EXPECT_FALSE(back_facing_child_of_back_facing_surface->render_surface());
3849 3789
3850 // Verify the render_surface_layer_list. The back-facing surface should be 3790 EXPECT_EQ(3u, update_layer_list().size());
3851 // culled.
3852 ASSERT_EQ(2u, render_surface_layer_list.size());
3853 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
3854 EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id());
3855 3791
3856 // Verify root surface's layer list. 3792 EXPECT_TRUE(UpdateLayerListContains(front_facing_child->id()));
3857 ASSERT_EQ( 3793 EXPECT_TRUE(UpdateLayerListContains(front_facing_surface->id()));
3858 2u, 3794 EXPECT_TRUE(UpdateLayerListContains(
3859 render_surface_layer_list.at(0)->render_surface()->layer_list().size()); 3795 front_facing_child_of_front_facing_surface->id()));
3860 EXPECT_EQ(front_facing_child->id(),
3861 render_surface_layer_list.at(0)
3862 ->render_surface()->layer_list().at(0)->id());
3863 EXPECT_EQ(front_facing_surface->id(),
3864 render_surface_layer_list.at(0)
3865 ->render_surface()->layer_list().at(1)->id());
3866
3867 // Verify front_facing_surface's layer list.
3868 ASSERT_EQ(
3869 2u,
3870 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
3871 EXPECT_EQ(front_facing_surface->id(),
3872 render_surface_layer_list.at(1)
3873 ->render_surface()->layer_list().at(0)->id());
3874 EXPECT_EQ(front_facing_child_of_front_facing_surface->id(),
3875 render_surface_layer_list.at(1)
3876 ->render_surface()->layer_list().at(1)->id());
3877 } 3796 }
3878 3797
3879 TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithAnimatingTransforms) { 3798 TEST_F(LayerTreeHostCommonTest, BackFaceCullingWithAnimatingTransforms) {
3880 // Verify that layers are appropriately culled when their back face is showing 3799 // Verify that layers are appropriately culled when their back face is showing
3881 // and they are not double sided, while animations are going on. 3800 // and they are not double sided, while animations are going on.
3882 // 3801 //
3883 // Layers that are animating do not get culled on the main thread, as their 3802 // Layers that are animating do not get culled on the main thread, as their
3884 // transforms should be treated as "unknown" so we can not be sure that their 3803 // transforms should be treated as "unknown" so we can not be sure that their
3885 // back face is really showing. 3804 // back face is really showing.
3886 const gfx::Transform identity_matrix; 3805 const gfx::Transform identity_matrix;
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
3974 parent.get(), parent->bounds(), &render_surface_layer_list); 3893 parent.get(), parent->bounds(), &render_surface_layer_list);
3975 inputs.can_adjust_raster_scales = true; 3894 inputs.can_adjust_raster_scales = true;
3976 LayerTreeHostCommon::CalculateDrawProperties(&inputs); 3895 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
3977 3896
3978 EXPECT_FALSE(child->render_surface()); 3897 EXPECT_FALSE(child->render_surface());
3979 EXPECT_TRUE(animating_surface->render_surface()); 3898 EXPECT_TRUE(animating_surface->render_surface());
3980 EXPECT_FALSE(child_of_animating_surface->render_surface()); 3899 EXPECT_FALSE(child_of_animating_surface->render_surface());
3981 EXPECT_FALSE(animating_child->render_surface()); 3900 EXPECT_FALSE(animating_child->render_surface());
3982 EXPECT_FALSE(child2->render_surface()); 3901 EXPECT_FALSE(child2->render_surface());
3983 3902
3984 // Verify that the animating_child and child_of_animating_surface were not 3903 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent.get());
3985 // culled, but that child was. 3904
3986 ASSERT_EQ(2u, render_surface_layer_list.size()); 3905 EXPECT_EQ(4u, update_layer_list().size());
3987 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
3988 EXPECT_EQ(animating_surface->id(), render_surface_layer_list.at(1)->id());
3989 3906
3990 // The non-animating child be culled from the layer list for the parent render 3907 // The non-animating child be culled from the layer list for the parent render
3991 // surface. 3908 // surface.
3992 ASSERT_EQ( 3909 EXPECT_TRUE(UpdateLayerListContains(animating_surface->id()));
3993 3u, 3910 EXPECT_TRUE(UpdateLayerListContains(animating_child->id()));
3994 render_surface_layer_list.at(0)->render_surface()->layer_list().size()); 3911 EXPECT_TRUE(UpdateLayerListContains(child2->id()));
3995 EXPECT_EQ(animating_surface->id(), 3912 EXPECT_TRUE(UpdateLayerListContains(child_of_animating_surface->id()));
3996 render_surface_layer_list.at(0)
3997 ->render_surface()->layer_list().at(0)->id());
3998 EXPECT_EQ(animating_child->id(),
3999 render_surface_layer_list.at(0)
4000 ->render_surface()->layer_list().at(1)->id());
4001 EXPECT_EQ(child2->id(),
4002 render_surface_layer_list.at(0)
4003 ->render_surface()->layer_list().at(2)->id());
4004 3913
4005 ASSERT_EQ( 3914 EXPECT_FALSE(child2->visible_rect_from_property_trees().IsEmpty());
4006 2u,
4007 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
4008 EXPECT_EQ(animating_surface->id(),
4009 render_surface_layer_list.at(1)
4010 ->render_surface()->layer_list().at(0)->id());
4011 EXPECT_EQ(child_of_animating_surface->id(),
4012 render_surface_layer_list.at(1)
4013 ->render_surface()->layer_list().at(1)->id());
4014
4015 EXPECT_FALSE(child2->visible_layer_rect().IsEmpty());
4016 3915
4017 // The animating layers should have a visible content rect that represents the 3916 // The animating layers should have a visible content rect that represents the
4018 // area of the front face that is within the viewport. 3917 // area of the front face that is within the viewport.
4019 EXPECT_EQ(animating_child->visible_layer_rect(), 3918 EXPECT_EQ(animating_child->visible_rect_from_property_trees(),
4020 gfx::Rect(animating_child->bounds())); 3919 gfx::Rect(animating_child->bounds()));
4021 EXPECT_EQ(animating_surface->visible_layer_rect(), 3920 EXPECT_EQ(animating_surface->visible_rect_from_property_trees(),
4022 gfx::Rect(animating_surface->bounds())); 3921 gfx::Rect(animating_surface->bounds()));
4023 // And layers in the subtree of the animating layer should have valid visible 3922 // And layers in the subtree of the animating layer should have valid visible
4024 // content rects also. 3923 // content rects also.
4025 EXPECT_EQ(child_of_animating_surface->visible_layer_rect(), 3924 EXPECT_EQ(child_of_animating_surface->visible_rect_from_property_trees(),
4026 gfx::Rect(child_of_animating_surface->bounds())); 3925 gfx::Rect(child_of_animating_surface->bounds()));
4027 } 3926 }
4028 3927
4029 TEST_F(LayerTreeHostCommonTest, 3928 TEST_F(LayerTreeHostCommonTest,
4030 BackFaceCullingWithPreserves3dForFlatteningSurface) { 3929 BackFaceCullingWithPreserves3dForFlatteningSurface) {
4031 // Verify the behavior of back-face culling for a render surface that is 3930 // Verify the behavior of back-face culling for a render surface that is
4032 // created when it flattens its subtree, and its parent has preserves-3d. 3931 // created when it flattens its subtree, and its parent has preserves-3d.
4033 3932
4034 const gfx::Transform identity_matrix; 3933 const gfx::Transform identity_matrix;
4035 scoped_refptr<Layer> parent = Layer::Create(layer_settings()); 3934 scoped_refptr<Layer> parent = Layer::Create(layer_settings());
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
4090 identity_matrix, 3989 identity_matrix,
4091 gfx::Point3F(), 3990 gfx::Point3F(),
4092 gfx::PointF(), 3991 gfx::PointF(),
4093 gfx::Size(100, 100), 3992 gfx::Size(100, 100),
4094 true, 3993 true,
4095 false); 3994 false);
4096 3995
4097 front_facing_surface->Set3dSortingContextId(1); 3996 front_facing_surface->Set3dSortingContextId(1);
4098 back_facing_surface->Set3dSortingContextId(1); 3997 back_facing_surface->Set3dSortingContextId(1);
4099 3998
4100 RenderSurfaceLayerList render_surface_layer_list; 3999 ExecuteCalculateDrawPropertiesWithPropertyTrees(parent.get());
4101 LayerTreeHostCommon::CalcDrawPropsMainInputsForTesting inputs(
4102 parent.get(), parent->bounds(), &render_surface_layer_list);
4103 inputs.can_adjust_raster_scales = true;
4104 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
4105 4000
4106 // Verify which render surfaces were created and used. 4001 // Verify which render surfaces were created and used.
4107 EXPECT_TRUE(front_facing_surface->render_surface()); 4002 EXPECT_TRUE(front_facing_surface->render_surface());
4108 4003
4109 // We expect the render surface to have been created, but remain unused. 4004 // We expect the render surface to have been created, but remain unused.
4110 EXPECT_TRUE(back_facing_surface->render_surface()); 4005 EXPECT_TRUE(back_facing_surface->render_surface());
4111 EXPECT_NE(back_facing_surface->render_target(), 4006 EXPECT_NE(back_facing_surface->render_target(),
4112 back_facing_surface); // because it should be culled 4007 back_facing_surface); // because it should be culled
4113 EXPECT_FALSE(child1->render_surface()); 4008 EXPECT_FALSE(child1->render_surface());
4114 EXPECT_FALSE(child2->render_surface()); 4009 EXPECT_FALSE(child2->render_surface());
4115 4010
4116 // Verify the render_surface_layer_list. The back-facing surface should be 4011 EXPECT_EQ(2u, update_layer_list().size());
4117 // culled. 4012 EXPECT_TRUE(UpdateLayerListContains(front_facing_surface->id()));
4118 ASSERT_EQ(2u, render_surface_layer_list.size()); 4013 EXPECT_TRUE(UpdateLayerListContains(child1->id()));
4119 EXPECT_EQ(parent->id(), render_surface_layer_list.at(0)->id());
4120 EXPECT_EQ(front_facing_surface->id(), render_surface_layer_list.at(1)->id());
4121
4122 // Verify root surface's layer list.
4123 ASSERT_EQ(
4124 1u,
4125 render_surface_layer_list.at(0)->render_surface()->layer_list().size());
4126 EXPECT_EQ(front_facing_surface->id(),
4127 render_surface_layer_list.at(0)
4128 ->render_surface()->layer_list().at(0)->id());
4129
4130 // Verify front_facing_surface's layer list.
4131 ASSERT_EQ(
4132 2u,
4133 render_surface_layer_list.at(1)->render_surface()->layer_list().size());
4134 EXPECT_EQ(front_facing_surface->id(),
4135 render_surface_layer_list.at(1)
4136 ->render_surface()->layer_list().at(0)->id());
4137 EXPECT_EQ(child1->id(),
4138 render_surface_layer_list.at(1)
4139 ->render_surface()->layer_list().at(1)->id());
4140 } 4014 }
4141 4015
4142 TEST_F(LayerTreeHostCommonScalingTest, LayerTransformsInHighDPI) { 4016 TEST_F(LayerTreeHostCommonScalingTest, LayerTransformsInHighDPI) {
4143 // Verify draw and screen space transforms of layers not in a surface. 4017 // Verify draw and screen space transforms of layers not in a surface.
4144 gfx::Transform identity_matrix; 4018 gfx::Transform identity_matrix;
4145 4019
4146 LayerImpl* parent = root_layer(); 4020 LayerImpl* parent = root_layer();
4147 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(), 4021 SetLayerPropertiesForTesting(parent, identity_matrix, gfx::Point3F(),
4148 gfx::PointF(), gfx::Size(100, 100), false, true, 4022 gfx::PointF(), gfx::Size(100, 100), false, true,
4149 true); 4023 true);
(...skipping 4311 matching lines...) Expand 10 before | Expand all | Expand 10 after
8461 EXPECT_FALSE(root->layer_or_descendant_is_drawn()); 8335 EXPECT_FALSE(root->layer_or_descendant_is_drawn());
8462 EXPECT_FALSE(root->visited()); 8336 EXPECT_FALSE(root->visited());
8463 EXPECT_FALSE(root->sorted_for_recursion()); 8337 EXPECT_FALSE(root->sorted_for_recursion());
8464 EXPECT_FALSE(child->layer_or_descendant_is_drawn()); 8338 EXPECT_FALSE(child->layer_or_descendant_is_drawn());
8465 EXPECT_FALSE(child->visited()); 8339 EXPECT_FALSE(child->visited());
8466 EXPECT_FALSE(child->sorted_for_recursion()); 8340 EXPECT_FALSE(child->sorted_for_recursion());
8467 } 8341 }
8468 8342
8469 } // namespace 8343 } // namespace
8470 } // namespace cc 8344 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/draw_property_utils.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698