| 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/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/filter_operation.h" | 9 #include "cc/base/filter_operation.h" |
| 10 #include "cc/base/filter_operations.h" | 10 #include "cc/base/filter_operations.h" |
| 11 #include "cc/base/math_util.h" | 11 #include "cc/base/math_util.h" |
| 12 #include "cc/layers/layer_impl.h" | 12 #include "cc/layers/layer_impl.h" |
| 13 #include "cc/test/fake_impl_task_runner_provider.h" | 13 #include "cc/test/fake_impl_task_runner_provider.h" |
| 14 #include "cc/test/fake_layer_tree_host_impl.h" | 14 #include "cc/test/fake_layer_tree_host_impl.h" |
| 15 #include "cc/test/geometry_test_utils.h" | 15 #include "cc/test/geometry_test_utils.h" |
| 16 #include "cc/test/test_task_graph_runner.h" | 16 #include "cc/test/test_task_graph_runner.h" |
| 17 #include "cc/trees/layer_tree_host_common.h" | 17 #include "cc/trees/layer_tree_host_common.h" |
| 18 #include "cc/trees/layer_tree_impl.h" | 18 #include "cc/trees/layer_tree_impl.h" |
| 19 #include "cc/trees/single_thread_proxy.h" | 19 #include "cc/trees/single_thread_proxy.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 21 #include "third_party/skia/include/effects/SkBlurImageFilter.h" | 21 #include "third_party/skia/include/effects/SkBlurImageFilter.h" |
| 22 #include "ui/gfx/geometry/quad_f.h" | 22 #include "ui/gfx/geometry/quad_f.h" |
| 23 #include "ui/gfx/geometry/rect_conversions.h" | 23 #include "ui/gfx/geometry/rect_conversions.h" |
| 24 | 24 |
| 25 namespace cc { | 25 namespace cc { |
| 26 namespace { | 26 namespace { |
| 27 | 27 |
| 28 void ExecuteCalculateDrawProperties(LayerImpl* root, | 28 void ExecuteCalculateDrawProperties(LayerImpl* root, |
| 29 float device_scale_factor, | 29 float device_scale_factor, |
| 30 LayerImplList* render_surface_layer_list) { | 30 RenderSurfaceList* render_surface_list) { |
| 31 // Sanity check: The test itself should create the root layer's render | 31 // Sanity check: The test itself should create the root layer's render |
| 32 // surface, so that the surface (and its damage tracker) can | 32 // surface, so that the surface (and its damage tracker) can |
| 33 // persist across multiple calls to this function. | 33 // persist across multiple calls to this function. |
| 34 ASSERT_FALSE(render_surface_layer_list->size()); | 34 ASSERT_FALSE(render_surface_list->size()); |
| 35 | 35 |
| 36 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( | 36 LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs( |
| 37 root, root->bounds(), device_scale_factor, render_surface_layer_list); | 37 root, root->bounds(), device_scale_factor, render_surface_list); |
| 38 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); | 38 LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs); |
| 39 ASSERT_TRUE(root->GetRenderSurface()); | 39 ASSERT_TRUE(root->GetRenderSurface()); |
| 40 } | 40 } |
| 41 | 41 |
| 42 void ClearDamageForAllSurfaces(LayerImpl* root) { | 42 void ClearDamageForAllSurfaces(LayerImpl* root) { |
| 43 for (auto* layer : *root->layer_tree_impl()) { | 43 for (auto* layer : *root->layer_tree_impl()) { |
| 44 if (layer->GetRenderSurface()) | 44 if (layer->GetRenderSurface()) |
| 45 layer->GetRenderSurface()->damage_tracker()->DidDrawDamagedArea(); | 45 layer->GetRenderSurface()->damage_tracker()->DidDrawDamagedArea(); |
| 46 } | 46 } |
| 47 } | 47 } |
| 48 | 48 |
| 49 void EmulateDrawingOneFrame(LayerImpl* root, float device_scale_factor = 1.f) { | 49 void EmulateDrawingOneFrame(LayerImpl* root, float device_scale_factor = 1.f) { |
| 50 // This emulates only steps that are relevant to testing the damage tracker: | 50 // This emulates only steps that are relevant to testing the damage tracker: |
| 51 // 1. computing the render passes and layerlists | 51 // 1. computing the render passes and layerlists |
| 52 // 2. updating all damage trackers in the correct order | 52 // 2. updating all damage trackers in the correct order |
| 53 // 3. resetting all update_rects and property_changed flags for all layers | 53 // 3. resetting all update_rects and property_changed flags for all layers |
| 54 // and surfaces. | 54 // and surfaces. |
| 55 | 55 |
| 56 LayerImplList render_surface_layer_list; | 56 RenderSurfaceList render_surface_list; |
| 57 ExecuteCalculateDrawProperties(root, device_scale_factor, | 57 ExecuteCalculateDrawProperties(root, device_scale_factor, |
| 58 &render_surface_layer_list); | 58 &render_surface_list); |
| 59 | 59 |
| 60 DamageTracker::UpdateDamageTracking(root->layer_tree_impl(), | 60 DamageTracker::UpdateDamageTracking(root->layer_tree_impl(), |
| 61 render_surface_layer_list); | 61 render_surface_list); |
| 62 | 62 |
| 63 root->layer_tree_impl()->ResetAllChangeTracking(); | 63 root->layer_tree_impl()->ResetAllChangeTracking(); |
| 64 } | 64 } |
| 65 | 65 |
| 66 class DamageTrackerTest : public testing::Test { | 66 class DamageTrackerTest : public testing::Test { |
| 67 public: | 67 public: |
| 68 DamageTrackerTest() | 68 DamageTrackerTest() |
| 69 : host_impl_(&task_runner_provider_, &task_graph_runner_) {} | 69 : host_impl_(&task_runner_provider_, &task_graph_runner_) {} |
| 70 | 70 |
| 71 LayerImpl* CreateTestTreeWithOneSurface(int number_of_children) { | 71 LayerImpl* CreateTestTreeWithOneSurface(int number_of_children) { |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 } | 167 } |
| 168 | 168 |
| 169 protected: | 169 protected: |
| 170 FakeImplTaskRunnerProvider task_runner_provider_; | 170 FakeImplTaskRunnerProvider task_runner_provider_; |
| 171 TestTaskGraphRunner task_graph_runner_; | 171 TestTaskGraphRunner task_graph_runner_; |
| 172 FakeLayerTreeHostImpl host_impl_; | 172 FakeLayerTreeHostImpl host_impl_; |
| 173 }; | 173 }; |
| 174 | 174 |
| 175 TEST_F(DamageTrackerTest, SanityCheckTestTreeWithOneSurface) { | 175 TEST_F(DamageTrackerTest, SanityCheckTestTreeWithOneSurface) { |
| 176 // Sanity check that the simple test tree will actually produce the expected | 176 // Sanity check that the simple test tree will actually produce the expected |
| 177 // render surfaces and layer lists. | 177 // render surfaces. |
| 178 | 178 |
| 179 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 179 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
| 180 LayerImpl* child = root->test_properties()->children[0]; |
| 180 | 181 |
| 181 EXPECT_EQ(2u, root->GetRenderSurface()->layer_list().size()); | 182 EXPECT_EQ(2, root->GetRenderSurface()->num_contributors()); |
| 182 EXPECT_EQ(1, root->GetRenderSurface()->layer_list()[0]->id()); | 183 EXPECT_TRUE(root->is_drawn_render_surface_layer_list_member()); |
| 183 EXPECT_EQ(2, root->GetRenderSurface()->layer_list()[1]->id()); | 184 EXPECT_TRUE(child->is_drawn_render_surface_layer_list_member()); |
| 184 | 185 |
| 185 gfx::Rect root_damage_rect; | 186 gfx::Rect root_damage_rect; |
| 186 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( | 187 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 187 &root_damage_rect)); | 188 &root_damage_rect)); |
| 188 | 189 |
| 189 EXPECT_EQ(gfx::Rect(500, 500).ToString(), root_damage_rect.ToString()); | 190 EXPECT_EQ(gfx::Rect(500, 500).ToString(), root_damage_rect.ToString()); |
| 190 } | 191 } |
| 191 | 192 |
| 192 TEST_F(DamageTrackerTest, SanityCheckTestTreeWithTwoSurfaces) { | 193 TEST_F(DamageTrackerTest, SanityCheckTestTreeWithTwoSurfaces) { |
| 193 // Sanity check that the complex test tree will actually produce the expected | 194 // Sanity check that the complex test tree will actually produce the expected |
| 194 // render surfaces and layer lists. | 195 // render surfaces. |
| 195 | 196 |
| 196 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 197 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
| 197 | 198 |
| 198 LayerImpl* child1 = root->test_properties()->children[0]; | 199 LayerImpl* child1 = root->test_properties()->children[0]; |
| 199 LayerImpl* child2 = root->test_properties()->children[1]; | 200 LayerImpl* child2 = root->test_properties()->children[1]; |
| 200 | 201 |
| 201 gfx::Rect child_damage_rect; | 202 gfx::Rect child_damage_rect; |
| 202 EXPECT_TRUE( | 203 EXPECT_TRUE( |
| 203 child1->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( | 204 child1->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 204 &child_damage_rect)); | 205 &child_damage_rect)); |
| 205 gfx::Rect root_damage_rect; | 206 gfx::Rect root_damage_rect; |
| 206 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( | 207 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 207 &root_damage_rect)); | 208 &root_damage_rect)); |
| 208 | 209 |
| 209 ASSERT_TRUE(child1->GetRenderSurface()); | 210 ASSERT_TRUE(child1->GetRenderSurface()); |
| 210 EXPECT_FALSE(child2->GetRenderSurface()); | 211 EXPECT_FALSE(child2->GetRenderSurface()); |
| 211 EXPECT_EQ(3u, root->GetRenderSurface()->layer_list().size()); | 212 EXPECT_EQ(3, root->GetRenderSurface()->num_contributors()); |
| 212 EXPECT_EQ(2u, child1->GetRenderSurface()->layer_list().size()); | 213 EXPECT_EQ(2, child1->GetRenderSurface()->num_contributors()); |
| 213 | 214 |
| 214 // The render surface for child1 only has a content_rect that encloses | 215 // The render surface for child1 only has a content_rect that encloses |
| 215 // grand_child1 and grand_child2, because child1 does not draw content. | 216 // grand_child1 and grand_child2, because child1 does not draw content. |
| 216 EXPECT_EQ(gfx::Rect(190, 190, 16, 18).ToString(), | 217 EXPECT_EQ(gfx::Rect(190, 190, 16, 18).ToString(), |
| 217 child_damage_rect.ToString()); | 218 child_damage_rect.ToString()); |
| 218 EXPECT_EQ(gfx::Rect(500, 500).ToString(), root_damage_rect.ToString()); | 219 EXPECT_EQ(gfx::Rect(500, 500).ToString(), root_damage_rect.ToString()); |
| 219 } | 220 } |
| 220 | 221 |
| 221 TEST_F(DamageTrackerTest, VerifyDamageForUpdateRects) { | 222 TEST_F(DamageTrackerTest, VerifyDamageForUpdateRects) { |
| 222 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 223 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 // CASE 1: The layer's property changed flag takes priority over update rect. | 373 // CASE 1: The layer's property changed flag takes priority over update rect. |
| 373 // | 374 // |
| 374 child->test_properties()->force_render_surface = true; | 375 child->test_properties()->force_render_surface = true; |
| 375 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 376 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 376 EmulateDrawingOneFrame(root); | 377 EmulateDrawingOneFrame(root); |
| 377 ClearDamageForAllSurfaces(root); | 378 ClearDamageForAllSurfaces(root); |
| 378 child->SetUpdateRect(gfx::Rect(10, 11, 12, 13)); | 379 child->SetUpdateRect(gfx::Rect(10, 11, 12, 13)); |
| 379 root->layer_tree_impl()->SetOpacityMutated(child->element_id(), 0.5f); | 380 root->layer_tree_impl()->SetOpacityMutated(child->element_id(), 0.5f); |
| 380 EmulateDrawingOneFrame(root); | 381 EmulateDrawingOneFrame(root); |
| 381 | 382 |
| 382 ASSERT_EQ(2u, root->GetRenderSurface()->layer_list().size()); | 383 ASSERT_EQ(2, root->GetRenderSurface()->num_contributors()); |
| 383 | 384 |
| 384 // Damage should be the entire child layer in target_surface space. | 385 // Damage should be the entire child layer in target_surface space. |
| 385 gfx::Rect expected_rect = gfx::Rect(100, 100, 30, 30); | 386 gfx::Rect expected_rect = gfx::Rect(100, 100, 30, 30); |
| 386 gfx::Rect root_damage_rect; | 387 gfx::Rect root_damage_rect; |
| 387 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( | 388 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 388 &root_damage_rect)); | 389 &root_damage_rect)); |
| 389 EXPECT_EQ(expected_rect.ToString(), root_damage_rect.ToString()); | 390 EXPECT_EQ(expected_rect.ToString(), root_damage_rect.ToString()); |
| 390 | 391 |
| 391 // CASE 2: If a layer moves due to property change, it damages both the new | 392 // CASE 2: If a layer moves due to property change, it damages both the new |
| 392 // location and the old (exposed) location. The old location is the | 393 // location and the old (exposed) location. The old location is the |
| (...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 861 child2->SetPosition(gfx::PointF(400.f, 380.f)); | 862 child2->SetPosition(gfx::PointF(400.f, 380.f)); |
| 862 child2->SetBounds(gfx::Size(6, 8)); | 863 child2->SetBounds(gfx::Size(6, 8)); |
| 863 child2->SetDrawsContent(true); | 864 child2->SetDrawsContent(true); |
| 864 root->test_properties()->AddChild(std::move(child2)); | 865 root->test_properties()->AddChild(std::move(child2)); |
| 865 } | 866 } |
| 866 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 867 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 867 EmulateDrawingOneFrame(root); | 868 EmulateDrawingOneFrame(root); |
| 868 | 869 |
| 869 // Sanity check - all 3 layers should be on the same render surface; render | 870 // Sanity check - all 3 layers should be on the same render surface; render |
| 870 // surfaces are tested elsewhere. | 871 // surfaces are tested elsewhere. |
| 871 ASSERT_EQ(3u, root->GetRenderSurface()->layer_list().size()); | 872 ASSERT_EQ(3, root->GetRenderSurface()->num_contributors()); |
| 872 | 873 |
| 873 gfx::Rect root_damage_rect; | 874 gfx::Rect root_damage_rect; |
| 874 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( | 875 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 875 &root_damage_rect)); | 876 &root_damage_rect)); |
| 876 EXPECT_EQ(gfx::Rect(400, 380, 6, 8).ToString(), root_damage_rect.ToString()); | 877 EXPECT_EQ(gfx::Rect(400, 380, 6, 8).ToString(), root_damage_rect.ToString()); |
| 877 | 878 |
| 878 // CASE 2: If the layer is removed, its entire old layer becomes exposed, not | 879 // CASE 2: If the layer is removed, its entire old layer becomes exposed, not |
| 879 // just the last update rect. | 880 // just the last update rect. |
| 880 | 881 |
| 881 // Advance one frame without damage so that we know the damage rect is not | 882 // Advance one frame without damage so that we know the damage rect is not |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 921 // trigger, it means the test no longer actually covers the intended | 922 // trigger, it means the test no longer actually covers the intended |
| 922 // scenario. | 923 // scenario. |
| 923 ASSERT_FALSE(child2_ptr->LayerPropertyChanged()); | 924 ASSERT_FALSE(child2_ptr->LayerPropertyChanged()); |
| 924 ASSERT_TRUE(child2_ptr->update_rect().IsEmpty()); | 925 ASSERT_TRUE(child2_ptr->update_rect().IsEmpty()); |
| 925 } | 926 } |
| 926 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 927 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 927 EmulateDrawingOneFrame(root); | 928 EmulateDrawingOneFrame(root); |
| 928 | 929 |
| 929 // Sanity check - all 3 layers should be on the same render surface; render | 930 // Sanity check - all 3 layers should be on the same render surface; render |
| 930 // surfaces are tested elsewhere. | 931 // surfaces are tested elsewhere. |
| 931 ASSERT_EQ(3u, root->GetRenderSurface()->layer_list().size()); | 932 ASSERT_EQ(3, root->GetRenderSurface()->num_contributors()); |
| 932 | 933 |
| 933 gfx::Rect root_damage_rect; | 934 gfx::Rect root_damage_rect; |
| 934 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( | 935 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 935 &root_damage_rect)); | 936 &root_damage_rect)); |
| 936 EXPECT_EQ(gfx::Rect(400, 380, 6, 8).ToString(), root_damage_rect.ToString()); | 937 EXPECT_EQ(gfx::Rect(400, 380, 6, 8).ToString(), root_damage_rect.ToString()); |
| 937 } | 938 } |
| 938 | 939 |
| 939 TEST_F(DamageTrackerTest, VerifyDamageForMultipleLayers) { | 940 TEST_F(DamageTrackerTest, VerifyDamageForMultipleLayers) { |
| 940 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 941 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
| 941 LayerImpl* child1 = root->test_properties()->children[0]; | 942 LayerImpl* child1 = root->test_properties()->children[0]; |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1102 | 1103 |
| 1103 // CASE 1: If a descendant surface disappears, its entire old area becomes | 1104 // CASE 1: If a descendant surface disappears, its entire old area becomes |
| 1104 // exposed. | 1105 // exposed. |
| 1105 ClearDamageForAllSurfaces(root); | 1106 ClearDamageForAllSurfaces(root); |
| 1106 child1->test_properties()->force_render_surface = false; | 1107 child1->test_properties()->force_render_surface = false; |
| 1107 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1108 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 1108 EmulateDrawingOneFrame(root); | 1109 EmulateDrawingOneFrame(root); |
| 1109 | 1110 |
| 1110 // Sanity check that there is only one surface now. | 1111 // Sanity check that there is only one surface now. |
| 1111 ASSERT_FALSE(child1->GetRenderSurface()); | 1112 ASSERT_FALSE(child1->GetRenderSurface()); |
| 1112 ASSERT_EQ(4u, root->GetRenderSurface()->layer_list().size()); | 1113 ASSERT_EQ(4, root->GetRenderSurface()->num_contributors()); |
| 1113 | 1114 |
| 1114 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( | 1115 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 1115 &root_damage_rect)); | 1116 &root_damage_rect)); |
| 1116 EXPECT_EQ(gfx::Rect(290, 290, 16, 18).ToString(), | 1117 EXPECT_EQ(gfx::Rect(290, 290, 16, 18).ToString(), |
| 1117 root_damage_rect.ToString()); | 1118 root_damage_rect.ToString()); |
| 1118 | 1119 |
| 1119 // CASE 2: If a descendant surface appears, its entire old area becomes | 1120 // CASE 2: If a descendant surface appears, its entire old area becomes |
| 1120 // exposed. | 1121 // exposed. |
| 1121 | 1122 |
| 1122 // Cycle one frame of no change, just to sanity check that the next rect is | 1123 // Cycle one frame of no change, just to sanity check that the next rect is |
| 1123 // not because of the old damage state. | 1124 // not because of the old damage state. |
| 1124 ClearDamageForAllSurfaces(root); | 1125 ClearDamageForAllSurfaces(root); |
| 1125 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1126 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 1126 EmulateDrawingOneFrame(root); | 1127 EmulateDrawingOneFrame(root); |
| 1127 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( | 1128 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 1128 &root_damage_rect)); | 1129 &root_damage_rect)); |
| 1129 EXPECT_TRUE(root_damage_rect.IsEmpty()); | 1130 EXPECT_TRUE(root_damage_rect.IsEmpty()); |
| 1130 | 1131 |
| 1131 // Then change the tree so that the render surface is added back. | 1132 // Then change the tree so that the render surface is added back. |
| 1132 ClearDamageForAllSurfaces(root); | 1133 ClearDamageForAllSurfaces(root); |
| 1133 child1->test_properties()->force_render_surface = true; | 1134 child1->test_properties()->force_render_surface = true; |
| 1134 | 1135 |
| 1135 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1136 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 1136 EmulateDrawingOneFrame(root); | 1137 EmulateDrawingOneFrame(root); |
| 1137 | 1138 |
| 1138 // Sanity check that there is a new surface now. | 1139 // Sanity check that there is a new surface now. |
| 1139 ASSERT_TRUE(child1->GetRenderSurface()); | 1140 ASSERT_TRUE(child1->GetRenderSurface()); |
| 1140 EXPECT_EQ(3u, root->GetRenderSurface()->layer_list().size()); | 1141 EXPECT_EQ(3, root->GetRenderSurface()->num_contributors()); |
| 1141 EXPECT_EQ(2u, child1->GetRenderSurface()->layer_list().size()); | 1142 EXPECT_EQ(2, child1->GetRenderSurface()->num_contributors()); |
| 1142 | 1143 |
| 1143 EXPECT_TRUE( | 1144 EXPECT_TRUE( |
| 1144 child1->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( | 1145 child1->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 1145 &child_damage_rect)); | 1146 &child_damage_rect)); |
| 1146 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( | 1147 EXPECT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 1147 &root_damage_rect)); | 1148 &root_damage_rect)); |
| 1148 EXPECT_EQ(gfx::Rect(190, 190, 16, 18).ToString(), | 1149 EXPECT_EQ(gfx::Rect(190, 190, 16, 18).ToString(), |
| 1149 child_damage_rect.ToString()); | 1150 child_damage_rect.ToString()); |
| 1150 EXPECT_EQ(gfx::Rect(290, 290, 16, 18).ToString(), | 1151 EXPECT_EQ(gfx::Rect(290, 290, 16, 18).ToString(), |
| 1151 root_damage_rect.ToString()); | 1152 root_damage_rect.ToString()); |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1501 grandchild1->SetDrawsContent(true); | 1502 grandchild1->SetDrawsContent(true); |
| 1502 | 1503 |
| 1503 // Really far right. | 1504 // Really far right. |
| 1504 grandchild2->SetPosition( | 1505 grandchild2->SetPosition( |
| 1505 gfx::PointF(std::numeric_limits<int>::max() - 500, 0)); | 1506 gfx::PointF(std::numeric_limits<int>::max() - 500, 0)); |
| 1506 grandchild2->SetBounds(gfx::Size(1, 1)); | 1507 grandchild2->SetBounds(gfx::Size(1, 1)); |
| 1507 grandchild2->SetDrawsContent(true); | 1508 grandchild2->SetDrawsContent(true); |
| 1508 | 1509 |
| 1509 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1510 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 1510 float device_scale_factor = 1.f; | 1511 float device_scale_factor = 1.f; |
| 1511 LayerImplList render_surface_layer_list; | 1512 RenderSurfaceList render_surface_list; |
| 1512 ExecuteCalculateDrawProperties(root, device_scale_factor, | 1513 ExecuteCalculateDrawProperties(root, device_scale_factor, |
| 1513 &render_surface_layer_list); | 1514 &render_surface_list); |
| 1514 // Avoid the descendant-only property change path that skips unioning damage | 1515 // Avoid the descendant-only property change path that skips unioning damage |
| 1515 // from descendant layers. | 1516 // from descendant layers. |
| 1516 child1->GetRenderSurface()->NoteAncestorPropertyChanged(); | 1517 child1->GetRenderSurface()->NoteAncestorPropertyChanged(); |
| 1517 DamageTracker::UpdateDamageTracking(host_impl_.active_tree(), | 1518 DamageTracker::UpdateDamageTracking(host_impl_.active_tree(), |
| 1518 render_surface_layer_list); | 1519 render_surface_list); |
| 1519 | 1520 |
| 1520 // The expected damage would be too large to store in a gfx::Rect, so we | 1521 // The expected damage would be too large to store in a gfx::Rect, so we |
| 1521 // should damage everything on child1. | 1522 // should damage everything on child1. |
| 1522 gfx::Rect damage_rect; | 1523 gfx::Rect damage_rect; |
| 1523 EXPECT_FALSE( | 1524 EXPECT_FALSE( |
| 1524 child1->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( | 1525 child1->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 1525 &damage_rect)); | 1526 &damage_rect)); |
| 1526 EXPECT_EQ(child1->GetRenderSurface()->content_rect(), | 1527 EXPECT_EQ(child1->GetRenderSurface()->content_rect(), |
| 1527 child1->GetRenderSurface()->GetDamageRect()); | 1528 child1->GetRenderSurface()->GetDamageRect()); |
| 1528 | 1529 |
| 1529 // However, the root should just use the child1 render surface's content rect | 1530 // However, the root should just use the child1 render surface's content rect |
| 1530 // as damage. | 1531 // as damage. |
| 1531 ASSERT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( | 1532 ASSERT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 1532 &damage_rect)); | 1533 &damage_rect)); |
| 1533 EXPECT_TRUE(damage_rect.Contains(root->GetRenderSurface()->content_rect())); | 1534 EXPECT_TRUE(damage_rect.Contains(root->GetRenderSurface()->content_rect())); |
| 1534 EXPECT_TRUE(damage_rect.Contains( | 1535 EXPECT_TRUE(damage_rect.Contains( |
| 1535 gfx::ToEnclosingRect(child1->GetRenderSurface()->DrawableContentRect()))); | 1536 gfx::ToEnclosingRect(child1->GetRenderSurface()->DrawableContentRect()))); |
| 1536 EXPECT_EQ(damage_rect, root->GetRenderSurface()->GetDamageRect()); | 1537 EXPECT_EQ(damage_rect, root->GetRenderSurface()->GetDamageRect()); |
| 1537 | 1538 |
| 1538 // Add new damage, without changing properties, which goes down a different | 1539 // Add new damage, without changing properties, which goes down a different |
| 1539 // path in the damage tracker. | 1540 // path in the damage tracker. |
| 1540 root->layer_tree_impl()->ResetAllChangeTracking(); | 1541 root->layer_tree_impl()->ResetAllChangeTracking(); |
| 1541 grandchild1->AddDamageRect(gfx::Rect(grandchild1->bounds())); | 1542 grandchild1->AddDamageRect(gfx::Rect(grandchild1->bounds())); |
| 1542 grandchild2->AddDamageRect(gfx::Rect(grandchild1->bounds())); | 1543 grandchild2->AddDamageRect(gfx::Rect(grandchild1->bounds())); |
| 1543 | 1544 |
| 1544 // Recompute all damage / properties. | 1545 // Recompute all damage / properties. |
| 1545 render_surface_layer_list.clear(); | 1546 render_surface_list.clear(); |
| 1546 ExecuteCalculateDrawProperties(root, device_scale_factor, | 1547 ExecuteCalculateDrawProperties(root, device_scale_factor, |
| 1547 &render_surface_layer_list); | 1548 &render_surface_list); |
| 1548 DamageTracker::UpdateDamageTracking(host_impl_.active_tree(), | 1549 DamageTracker::UpdateDamageTracking(host_impl_.active_tree(), |
| 1549 render_surface_layer_list); | 1550 render_surface_list); |
| 1550 | 1551 |
| 1551 // Child1 should still not have a valid rect, since the union of the damage of | 1552 // Child1 should still not have a valid rect, since the union of the damage of |
| 1552 // its children is not representable by a single rect. | 1553 // its children is not representable by a single rect. |
| 1553 EXPECT_FALSE( | 1554 EXPECT_FALSE( |
| 1554 child1->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( | 1555 child1->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 1555 &damage_rect)); | 1556 &damage_rect)); |
| 1556 EXPECT_EQ(child1->GetRenderSurface()->content_rect(), | 1557 EXPECT_EQ(child1->GetRenderSurface()->content_rect(), |
| 1557 child1->GetRenderSurface()->GetDamageRect()); | 1558 child1->GetRenderSurface()->GetDamageRect()); |
| 1558 | 1559 |
| 1559 // Root should have valid damage and contain both its content rect and the | 1560 // Root should have valid damage and contain both its content rect and the |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1585 grandchild1->SetDrawsContent(true); | 1586 grandchild1->SetDrawsContent(true); |
| 1586 | 1587 |
| 1587 // Really far right. | 1588 // Really far right. |
| 1588 grandchild2->SetPosition( | 1589 grandchild2->SetPosition( |
| 1589 gfx::PointF(std::numeric_limits<int>::max() - 500, 0)); | 1590 gfx::PointF(std::numeric_limits<int>::max() - 500, 0)); |
| 1590 grandchild2->SetBounds(gfx::Size(1, 1)); | 1591 grandchild2->SetBounds(gfx::Size(1, 1)); |
| 1591 grandchild2->SetDrawsContent(true); | 1592 grandchild2->SetDrawsContent(true); |
| 1592 | 1593 |
| 1593 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1594 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 1594 float device_scale_factor = 1.f; | 1595 float device_scale_factor = 1.f; |
| 1595 LayerImplList render_surface_layer_list; | 1596 RenderSurfaceList render_surface_list; |
| 1596 ExecuteCalculateDrawProperties(root, device_scale_factor, | 1597 ExecuteCalculateDrawProperties(root, device_scale_factor, |
| 1597 &render_surface_layer_list); | 1598 &render_surface_list); |
| 1598 // Avoid the descendant-only property change path that skips unioning damage | 1599 // Avoid the descendant-only property change path that skips unioning damage |
| 1599 // from descendant layers. | 1600 // from descendant layers. |
| 1600 child1->GetRenderSurface()->NoteAncestorPropertyChanged(); | 1601 child1->GetRenderSurface()->NoteAncestorPropertyChanged(); |
| 1601 DamageTracker::UpdateDamageTracking(host_impl_.active_tree(), | 1602 DamageTracker::UpdateDamageTracking(host_impl_.active_tree(), |
| 1602 render_surface_layer_list); | 1603 render_surface_list); |
| 1603 | 1604 |
| 1604 // The expected damage would be too large to store in a gfx::Rect, so we | 1605 // The expected damage would be too large to store in a gfx::Rect, so we |
| 1605 // should damage everything on child1. | 1606 // should damage everything on child1. |
| 1606 gfx::Rect damage_rect; | 1607 gfx::Rect damage_rect; |
| 1607 EXPECT_FALSE( | 1608 EXPECT_FALSE( |
| 1608 child1->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( | 1609 child1->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 1609 &damage_rect)); | 1610 &damage_rect)); |
| 1610 EXPECT_EQ(child1->GetRenderSurface()->content_rect(), | 1611 EXPECT_EQ(child1->GetRenderSurface()->content_rect(), |
| 1611 child1->GetRenderSurface()->GetDamageRect()); | 1612 child1->GetRenderSurface()->GetDamageRect()); |
| 1612 | 1613 |
| 1613 // However, the root should just use the child1 render surface's content rect | 1614 // However, the root should just use the child1 render surface's content rect |
| 1614 // as damage. | 1615 // as damage. |
| 1615 ASSERT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( | 1616 ASSERT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 1616 &damage_rect)); | 1617 &damage_rect)); |
| 1617 EXPECT_TRUE(damage_rect.Contains(root->GetRenderSurface()->content_rect())); | 1618 EXPECT_TRUE(damage_rect.Contains(root->GetRenderSurface()->content_rect())); |
| 1618 EXPECT_TRUE(damage_rect.Contains( | 1619 EXPECT_TRUE(damage_rect.Contains( |
| 1619 gfx::ToEnclosingRect(child1->GetRenderSurface()->DrawableContentRect()))); | 1620 gfx::ToEnclosingRect(child1->GetRenderSurface()->DrawableContentRect()))); |
| 1620 EXPECT_EQ(damage_rect, root->GetRenderSurface()->GetDamageRect()); | 1621 EXPECT_EQ(damage_rect, root->GetRenderSurface()->GetDamageRect()); |
| 1621 | 1622 |
| 1622 // Add new damage, without changing properties, which goes down a different | 1623 // Add new damage, without changing properties, which goes down a different |
| 1623 // path in the damage tracker. | 1624 // path in the damage tracker. |
| 1624 root->layer_tree_impl()->ResetAllChangeTracking(); | 1625 root->layer_tree_impl()->ResetAllChangeTracking(); |
| 1625 grandchild1->AddDamageRect(gfx::Rect(grandchild1->bounds())); | 1626 grandchild1->AddDamageRect(gfx::Rect(grandchild1->bounds())); |
| 1626 grandchild2->AddDamageRect(gfx::Rect(grandchild1->bounds())); | 1627 grandchild2->AddDamageRect(gfx::Rect(grandchild1->bounds())); |
| 1627 | 1628 |
| 1628 // Recompute all damage / properties. | 1629 // Recompute all damage / properties. |
| 1629 render_surface_layer_list.clear(); | 1630 render_surface_list.clear(); |
| 1630 ExecuteCalculateDrawProperties(root, device_scale_factor, | 1631 ExecuteCalculateDrawProperties(root, device_scale_factor, |
| 1631 &render_surface_layer_list); | 1632 &render_surface_list); |
| 1632 DamageTracker::UpdateDamageTracking(host_impl_.active_tree(), | 1633 DamageTracker::UpdateDamageTracking(host_impl_.active_tree(), |
| 1633 render_surface_layer_list); | 1634 render_surface_list); |
| 1634 | 1635 |
| 1635 // Child1 should still not have a valid rect, since the union of the damage of | 1636 // Child1 should still not have a valid rect, since the union of the damage of |
| 1636 // its children is not representable by a single rect. | 1637 // its children is not representable by a single rect. |
| 1637 EXPECT_FALSE( | 1638 EXPECT_FALSE( |
| 1638 child1->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( | 1639 child1->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 1639 &damage_rect)); | 1640 &damage_rect)); |
| 1640 EXPECT_EQ(child1->GetRenderSurface()->content_rect(), | 1641 EXPECT_EQ(child1->GetRenderSurface()->content_rect(), |
| 1641 child1->GetRenderSurface()->GetDamageRect()); | 1642 child1->GetRenderSurface()->GetDamageRect()); |
| 1642 | 1643 |
| 1643 // Root should have valid damage and contain both its content rect and the | 1644 // Root should have valid damage and contain both its content rect and the |
| 1644 // drawable content rect of child1. | 1645 // drawable content rect of child1. |
| 1645 ASSERT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( | 1646 ASSERT_TRUE(root->GetRenderSurface()->damage_tracker()->GetDamageRectIfValid( |
| 1646 &damage_rect)); | 1647 &damage_rect)); |
| 1647 EXPECT_TRUE(damage_rect.Contains(root->GetRenderSurface()->content_rect())); | 1648 EXPECT_TRUE(damage_rect.Contains(root->GetRenderSurface()->content_rect())); |
| 1648 EXPECT_TRUE(damage_rect.Contains( | 1649 EXPECT_TRUE(damage_rect.Contains( |
| 1649 gfx::ToEnclosingRect(child1->GetRenderSurface()->DrawableContentRect()))); | 1650 gfx::ToEnclosingRect(child1->GetRenderSurface()->DrawableContentRect()))); |
| 1650 EXPECT_EQ(damage_rect, root->GetRenderSurface()->GetDamageRect()); | 1651 EXPECT_EQ(damage_rect, root->GetRenderSurface()->GetDamageRect()); |
| 1651 } | 1652 } |
| 1652 | 1653 |
| 1653 } // namespace | 1654 } // namespace |
| 1654 } // namespace cc | 1655 } // namespace cc |
| OLD | NEW |