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

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

Issue 2084233002: cc: Move LayerImpl::AddChild and RemoveChild to LayerImplTestProperties (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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/tiles/tile_manager_unittest.cc ('k') | cc/trees/layer_tree_host_common_unittest.cc » ('j') | 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/damage_tracker.h" 5 #include "cc/trees/damage_tracker.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "cc/base/math_util.h" 9 #include "cc/base/math_util.h"
10 #include "cc/layers/layer_impl.h" 10 #include "cc/layers/layer_impl.h"
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 LayerImpl::Create(host_impl_.active_tree(), 2); 90 LayerImpl::Create(host_impl_.active_tree(), 2);
91 91
92 root->SetPosition(gfx::PointF()); 92 root->SetPosition(gfx::PointF());
93 root->SetBounds(gfx::Size(500, 500)); 93 root->SetBounds(gfx::Size(500, 500));
94 root->SetDrawsContent(true); 94 root->SetDrawsContent(true);
95 root->test_properties()->force_render_surface = true; 95 root->test_properties()->force_render_surface = true;
96 96
97 child->SetPosition(gfx::PointF(100.f, 100.f)); 97 child->SetPosition(gfx::PointF(100.f, 100.f));
98 child->SetBounds(gfx::Size(30, 30)); 98 child->SetBounds(gfx::Size(30, 30));
99 child->SetDrawsContent(true); 99 child->SetDrawsContent(true);
100 root->AddChild(std::move(child)); 100 root->test_properties()->AddChild(std::move(child));
101 host_impl_.active_tree()->SetRootLayer(std::move(root)); 101 host_impl_.active_tree()->SetRootLayer(std::move(root));
102 102
103 return host_impl_.active_tree()->root_layer(); 103 return host_impl_.active_tree()->root_layer();
104 } 104 }
105 105
106 LayerImpl* CreateTestTreeWithTwoSurfaces() { 106 LayerImpl* CreateTestTreeWithTwoSurfaces() {
107 // This test tree has two render surfaces: one for the root, and one for 107 // This test tree has two render surfaces: one for the root, and one for
108 // child1. Additionally, the root has a second child layer, and child1 has 108 // child1. Additionally, the root has a second child layer, and child1 has
109 // two children of its own. 109 // two children of its own.
110 110
(...skipping 27 matching lines...) Expand all
138 child2->SetDrawsContent(true); 138 child2->SetDrawsContent(true);
139 139
140 grand_child1->SetPosition(gfx::PointF(200.f, 200.f)); 140 grand_child1->SetPosition(gfx::PointF(200.f, 200.f));
141 grand_child1->SetBounds(gfx::Size(6, 8)); 141 grand_child1->SetBounds(gfx::Size(6, 8));
142 grand_child1->SetDrawsContent(true); 142 grand_child1->SetDrawsContent(true);
143 143
144 grand_child2->SetPosition(gfx::PointF(190.f, 190.f)); 144 grand_child2->SetPosition(gfx::PointF(190.f, 190.f));
145 grand_child2->SetBounds(gfx::Size(6, 8)); 145 grand_child2->SetBounds(gfx::Size(6, 8));
146 grand_child2->SetDrawsContent(true); 146 grand_child2->SetDrawsContent(true);
147 147
148 child1->AddChild(std::move(grand_child1)); 148 child1->test_properties()->AddChild(std::move(grand_child1));
149 child1->AddChild(std::move(grand_child2)); 149 child1->test_properties()->AddChild(std::move(grand_child2));
150 root->AddChild(std::move(child1)); 150 root->test_properties()->AddChild(std::move(child1));
151 root->AddChild(std::move(child2)); 151 root->test_properties()->AddChild(std::move(child2));
152 host_impl_.active_tree()->SetRootLayer(std::move(root)); 152 host_impl_.active_tree()->SetRootLayer(std::move(root));
153 153
154 return host_impl_.active_tree()->root_layer(); 154 return host_impl_.active_tree()->root_layer();
155 } 155 }
156 156
157 LayerImpl* CreateAndSetUpTestTreeWithOneSurface() { 157 LayerImpl* CreateAndSetUpTestTreeWithOneSurface() {
158 LayerImpl* root = CreateTestTreeWithOneSurface(); 158 LayerImpl* root = CreateTestTreeWithOneSurface();
159 159
160 // Setup includes going past the first frame which always damages 160 // Setup includes going past the first frame which always damages
161 // everything, so that we can actually perform specific tests. 161 // everything, so that we can actually perform specific tests.
(...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after
820 820
821 // CASE 1: Adding a new layer should cause the appropriate damage. 821 // CASE 1: Adding a new layer should cause the appropriate damage.
822 // 822 //
823 ClearDamageForAllSurfaces(root); 823 ClearDamageForAllSurfaces(root);
824 { 824 {
825 std::unique_ptr<LayerImpl> child2 = 825 std::unique_ptr<LayerImpl> child2 =
826 LayerImpl::Create(host_impl_.active_tree(), 3); 826 LayerImpl::Create(host_impl_.active_tree(), 3);
827 child2->SetPosition(gfx::PointF(400.f, 380.f)); 827 child2->SetPosition(gfx::PointF(400.f, 380.f));
828 child2->SetBounds(gfx::Size(6, 8)); 828 child2->SetBounds(gfx::Size(6, 8));
829 child2->SetDrawsContent(true); 829 child2->SetDrawsContent(true);
830 root->AddChild(std::move(child2)); 830 root->test_properties()->AddChild(std::move(child2));
831 } 831 }
832 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 832 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
833 EmulateDrawingOneFrame(root); 833 EmulateDrawingOneFrame(root);
834 834
835 // Sanity check - all 3 layers should be on the same render surface; render 835 // Sanity check - all 3 layers should be on the same render surface; render
836 // surfaces are tested elsewhere. 836 // surfaces are tested elsewhere.
837 ASSERT_EQ(3u, root->render_surface()->layer_list().size()); 837 ASSERT_EQ(3u, root->render_surface()->layer_list().size());
838 838
839 gfx::Rect root_damage_rect = 839 gfx::Rect root_damage_rect =
840 root->render_surface()->damage_tracker()->current_damage_rect(); 840 root->render_surface()->damage_tracker()->current_damage_rect();
841 EXPECT_EQ(gfx::Rect(400, 380, 6, 8).ToString(), root_damage_rect.ToString()); 841 EXPECT_EQ(gfx::Rect(400, 380, 6, 8).ToString(), root_damage_rect.ToString());
842 842
843 // CASE 2: If the layer is removed, its entire old layer becomes exposed, not 843 // CASE 2: If the layer is removed, its entire old layer becomes exposed, not
844 // just the last update rect. 844 // just the last update rect.
845 845
846 // Advance one frame without damage so that we know the damage rect is not 846 // Advance one frame without damage so that we know the damage rect is not
847 // leftover from the previous case. 847 // leftover from the previous case.
848 ClearDamageForAllSurfaces(root); 848 ClearDamageForAllSurfaces(root);
849 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 849 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
850 EmulateDrawingOneFrame(root); 850 EmulateDrawingOneFrame(root);
851 851
852 root_damage_rect = 852 root_damage_rect =
853 root->render_surface()->damage_tracker()->current_damage_rect(); 853 root->render_surface()->damage_tracker()->current_damage_rect();
854 EXPECT_TRUE(root_damage_rect.IsEmpty()); 854 EXPECT_TRUE(root_damage_rect.IsEmpty());
855 855
856 // Then, test removing child1. 856 // Then, test removing child1.
857 root->RemoveChildForTesting(child1); 857 root->test_properties()->RemoveChild(child1);
858 child1 = NULL; 858 child1 = NULL;
859 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 859 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
860 EmulateDrawingOneFrame(root); 860 EmulateDrawingOneFrame(root);
861 861
862 root_damage_rect = 862 root_damage_rect =
863 root->render_surface()->damage_tracker()->current_damage_rect(); 863 root->render_surface()->damage_tracker()->current_damage_rect();
864 EXPECT_EQ(gfx::Rect(100, 100, 30, 30).ToString(), 864 EXPECT_EQ(gfx::Rect(100, 100, 30, 30).ToString(),
865 root_damage_rect.ToString()); 865 root_damage_rect.ToString());
866 } 866 }
867 867
868 TEST_F(DamageTrackerTest, VerifyDamageForNewUnchangedLayer) { 868 TEST_F(DamageTrackerTest, VerifyDamageForNewUnchangedLayer) {
869 // If child2 is added to the layer tree, but it doesn't have any explicit 869 // If child2 is added to the layer tree, but it doesn't have any explicit
870 // damage of its own, it should still indeed damage the target surface. 870 // damage of its own, it should still indeed damage the target surface.
871 871
872 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); 872 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface();
873 873
874 ClearDamageForAllSurfaces(root); 874 ClearDamageForAllSurfaces(root);
875 { 875 {
876 std::unique_ptr<LayerImpl> child2 = 876 std::unique_ptr<LayerImpl> child2 =
877 LayerImpl::Create(host_impl_.active_tree(), 3); 877 LayerImpl::Create(host_impl_.active_tree(), 3);
878 child2->SetPosition(gfx::PointF(400.f, 380.f)); 878 child2->SetPosition(gfx::PointF(400.f, 380.f));
879 child2->SetBounds(gfx::Size(6, 8)); 879 child2->SetBounds(gfx::Size(6, 8));
880 child2->SetDrawsContent(true); 880 child2->SetDrawsContent(true);
881 root->AddChild(std::move(child2)); 881 root->test_properties()->AddChild(std::move(child2));
882 root->layer_tree_impl()->BuildLayerListForTesting(); 882 root->layer_tree_impl()->BuildLayerListForTesting();
883 host_impl_.active_tree()->ResetAllChangeTracking(); 883 host_impl_.active_tree()->ResetAllChangeTracking();
884 LayerImpl* child2_ptr = host_impl_.active_tree()->LayerById(3); 884 LayerImpl* child2_ptr = host_impl_.active_tree()->LayerById(3);
885 // Sanity check the initial conditions of the test, if these asserts 885 // Sanity check the initial conditions of the test, if these asserts
886 // trigger, it means the test no longer actually covers the intended 886 // trigger, it means the test no longer actually covers the intended
887 // scenario. 887 // scenario.
888 ASSERT_FALSE(child2_ptr->LayerPropertyChanged()); 888 ASSERT_FALSE(child2_ptr->LayerPropertyChanged());
889 ASSERT_TRUE(child2_ptr->update_rect().IsEmpty()); 889 ASSERT_TRUE(child2_ptr->update_rect().IsEmpty());
890 } 890 }
891 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 891 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
(...skipping 14 matching lines...) Expand all
906 906
907 // In this test we don't want the above tree manipulation to be considered 907 // In this test we don't want the above tree manipulation to be considered
908 // part of the same frame. 908 // part of the same frame.
909 ClearDamageForAllSurfaces(root); 909 ClearDamageForAllSurfaces(root);
910 { 910 {
911 std::unique_ptr<LayerImpl> child2 = 911 std::unique_ptr<LayerImpl> child2 =
912 LayerImpl::Create(host_impl_.active_tree(), 3); 912 LayerImpl::Create(host_impl_.active_tree(), 3);
913 child2->SetPosition(gfx::PointF(400.f, 380.f)); 913 child2->SetPosition(gfx::PointF(400.f, 380.f));
914 child2->SetBounds(gfx::Size(6, 8)); 914 child2->SetBounds(gfx::Size(6, 8));
915 child2->SetDrawsContent(true); 915 child2->SetDrawsContent(true);
916 root->AddChild(std::move(child2)); 916 root->test_properties()->AddChild(std::move(child2));
917 } 917 }
918 LayerImpl* child2 = root->test_properties()->children[1]; 918 LayerImpl* child2 = root->test_properties()->children[1];
919 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 919 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
920 EmulateDrawingOneFrame(root); 920 EmulateDrawingOneFrame(root);
921 921
922 // Damaging two layers simultaneously should cause combined damage. 922 // Damaging two layers simultaneously should cause combined damage.
923 // - child1 update rect in surface space: gfx::Rect(100, 100, 1, 2); 923 // - child1 update rect in surface space: gfx::Rect(100, 100, 1, 2);
924 // - child2 update rect in surface space: gfx::Rect(400, 380, 3, 4); 924 // - child2 update rect in surface space: gfx::Rect(400, 380, 3, 4);
925 ClearDamageForAllSurfaces(root); 925 ClearDamageForAllSurfaces(root);
926 child1->SetUpdateRect(gfx::Rect(1, 2)); 926 child1->SetUpdateRect(gfx::Rect(1, 2));
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
1176 // For this test case, we modify grand_child2, and add grand_child3 to extend 1176 // For this test case, we modify grand_child2, and add grand_child3 to extend
1177 // the bounds of child1's surface. This way, we can test reflection changes 1177 // the bounds of child1's surface. This way, we can test reflection changes
1178 // without changing content_bounds of the surface. 1178 // without changing content_bounds of the surface.
1179 grand_child2->SetPosition(gfx::PointF(180.f, 180.f)); 1179 grand_child2->SetPosition(gfx::PointF(180.f, 180.f));
1180 { 1180 {
1181 std::unique_ptr<LayerImpl> grand_child3 = 1181 std::unique_ptr<LayerImpl> grand_child3 =
1182 LayerImpl::Create(host_impl_.active_tree(), 6); 1182 LayerImpl::Create(host_impl_.active_tree(), 6);
1183 grand_child3->SetPosition(gfx::PointF(240.f, 240.f)); 1183 grand_child3->SetPosition(gfx::PointF(240.f, 240.f));
1184 grand_child3->SetBounds(gfx::Size(10, 10)); 1184 grand_child3->SetBounds(gfx::Size(10, 10));
1185 grand_child3->SetDrawsContent(true); 1185 grand_child3->SetDrawsContent(true);
1186 child1->AddChild(std::move(grand_child3)); 1186 child1->test_properties()->AddChild(std::move(grand_child3));
1187 } 1187 }
1188 child1->test_properties()->opacity = 0.5f; 1188 child1->test_properties()->opacity = 0.5f;
1189 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 1189 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
1190 EmulateDrawingOneFrame(root); 1190 EmulateDrawingOneFrame(root);
1191 1191
1192 // CASE 1: adding a reflection about the left edge of grand_child1. 1192 // CASE 1: adding a reflection about the left edge of grand_child1.
1193 // 1193 //
1194 ClearDamageForAllSurfaces(root); 1194 ClearDamageForAllSurfaces(root);
1195 { 1195 {
1196 std::unique_ptr<LayerImpl> grand_child1_replica = 1196 std::unique_ptr<LayerImpl> grand_child1_replica =
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1297 LayerImpl* mask_layer = child->test_properties()->mask_layer; 1297 LayerImpl* mask_layer = child->test_properties()->mask_layer;
1298 1298
1299 // Add opacity and a grand_child so that the render surface persists even 1299 // Add opacity and a grand_child so that the render surface persists even
1300 // after we remove the mask. 1300 // after we remove the mask.
1301 { 1301 {
1302 std::unique_ptr<LayerImpl> grand_child = 1302 std::unique_ptr<LayerImpl> grand_child =
1303 LayerImpl::Create(host_impl_.active_tree(), 4); 1303 LayerImpl::Create(host_impl_.active_tree(), 4);
1304 grand_child->SetPosition(gfx::PointF(2.f, 2.f)); 1304 grand_child->SetPosition(gfx::PointF(2.f, 2.f));
1305 grand_child->SetBounds(gfx::Size(2, 2)); 1305 grand_child->SetBounds(gfx::Size(2, 2));
1306 grand_child->SetDrawsContent(true); 1306 grand_child->SetDrawsContent(true);
1307 child->AddChild(std::move(grand_child)); 1307 child->test_properties()->AddChild(std::move(grand_child));
1308 } 1308 }
1309 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 1309 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
1310 EmulateDrawingOneFrame(root); 1310 EmulateDrawingOneFrame(root);
1311 1311
1312 // CASE 1: the update_rect on a mask layer should damage the entire target 1312 // CASE 1: the update_rect on a mask layer should damage the entire target
1313 // surface. 1313 // surface.
1314 ClearDamageForAllSurfaces(root); 1314 ClearDamageForAllSurfaces(root);
1315 mask_layer->SetUpdateRect(gfx::Rect(1, 2, 3, 4)); 1315 mask_layer->SetUpdateRect(gfx::Rect(1, 2, 3, 4));
1316 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 1316 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
1317 EmulateDrawingOneFrame(root); 1317 EmulateDrawingOneFrame(root);
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after
1637 gfx::Rect root_damage_rect = 1637 gfx::Rect root_damage_rect =
1638 root->render_surface()->damage_tracker()->current_damage_rect(); 1638 root->render_surface()->damage_tracker()->current_damage_rect();
1639 gfx::Rect damage_we_care_about = gfx::Rect(i, i); 1639 gfx::Rect damage_we_care_about = gfx::Rect(i, i);
1640 EXPECT_LE(damage_we_care_about.right(), root_damage_rect.right()); 1640 EXPECT_LE(damage_we_care_about.right(), root_damage_rect.right());
1641 EXPECT_LE(damage_we_care_about.bottom(), root_damage_rect.bottom()); 1641 EXPECT_LE(damage_we_care_about.bottom(), root_damage_rect.bottom());
1642 } 1642 }
1643 } 1643 }
1644 1644
1645 } // namespace 1645 } // namespace
1646 } // namespace cc 1646 } // namespace cc
OLDNEW
« no previous file with comments | « cc/tiles/tile_manager_unittest.cc ('k') | cc/trees/layer_tree_host_common_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698