Chromium Code Reviews| 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/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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 80 } | 80 } |
| 81 | 81 |
| 82 root->layer_tree_impl()->ResetAllChangeTracking(); | 82 root->layer_tree_impl()->ResetAllChangeTracking(); |
| 83 } | 83 } |
| 84 | 84 |
| 85 class DamageTrackerTest : public testing::Test { | 85 class DamageTrackerTest : public testing::Test { |
| 86 public: | 86 public: |
| 87 DamageTrackerTest() | 87 DamageTrackerTest() |
| 88 : host_impl_(&task_runner_provider_, &task_graph_runner_) {} | 88 : host_impl_(&task_runner_provider_, &task_graph_runner_) {} |
| 89 | 89 |
| 90 LayerImpl* CreateTestTreeWithOneSurface() { | 90 LayerImpl* CreateTestTreeWithOneSurface(int number_of_children) { |
| 91 host_impl_.active_tree()->DetachLayers(); | 91 host_impl_.active_tree()->DetachLayers(); |
| 92 std::unique_ptr<LayerImpl> root = | 92 std::unique_ptr<LayerImpl> root = |
| 93 LayerImpl::Create(host_impl_.active_tree(), 1); | 93 LayerImpl::Create(host_impl_.active_tree(), 1); |
| 94 std::unique_ptr<LayerImpl> child = | |
| 95 LayerImpl::Create(host_impl_.active_tree(), 2); | |
| 96 | 94 |
| 97 root->SetPosition(gfx::PointF()); | 95 root->SetPosition(gfx::PointF()); |
| 98 root->SetBounds(gfx::Size(500, 500)); | 96 root->SetBounds(gfx::Size(500, 500)); |
| 99 root->SetDrawsContent(true); | 97 root->SetDrawsContent(true); |
| 100 root->test_properties()->force_render_surface = true; | 98 root->test_properties()->force_render_surface = true; |
| 101 | 99 |
| 102 child->SetPosition(gfx::PointF(100.f, 100.f)); | 100 for (int i = 0; i < number_of_children; ++i) { |
| 103 child->SetBounds(gfx::Size(30, 30)); | 101 std::unique_ptr<LayerImpl> child = |
| 104 child->SetDrawsContent(true); | 102 LayerImpl::Create(host_impl_.active_tree(), 2 + i); |
| 105 root->test_properties()->AddChild(std::move(child)); | 103 child->SetPosition(gfx::PointF(100.f, 100.f)); |
| 104 child->SetBounds(gfx::Size(30, 30)); | |
| 105 child->SetDrawsContent(true); | |
| 106 root->test_properties()->AddChild(std::move(child)); | |
| 107 } | |
| 106 host_impl_.active_tree()->SetRootLayerForTesting(std::move(root)); | 108 host_impl_.active_tree()->SetRootLayerForTesting(std::move(root)); |
| 107 | 109 |
| 108 return host_impl_.active_tree()->root_layer_for_testing(); | 110 return host_impl_.active_tree()->root_layer_for_testing(); |
| 109 } | 111 } |
| 110 | 112 |
| 111 LayerImpl* CreateTestTreeWithTwoSurfaces() { | 113 LayerImpl* CreateTestTreeWithTwoSurfaces() { |
| 112 // This test tree has two render surfaces: one for the root, and one for | 114 // This test tree has two render surfaces: one for the root, and one for |
| 113 // child1. Additionally, the root has a second child layer, and child1 has | 115 // child1. Additionally, the root has a second child layer, and child1 has |
| 114 // two children of its own. | 116 // two children of its own. |
| 115 | 117 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 152 | 154 |
| 153 child1->test_properties()->AddChild(std::move(grand_child1)); | 155 child1->test_properties()->AddChild(std::move(grand_child1)); |
| 154 child1->test_properties()->AddChild(std::move(grand_child2)); | 156 child1->test_properties()->AddChild(std::move(grand_child2)); |
| 155 root->test_properties()->AddChild(std::move(child1)); | 157 root->test_properties()->AddChild(std::move(child1)); |
| 156 root->test_properties()->AddChild(std::move(child2)); | 158 root->test_properties()->AddChild(std::move(child2)); |
| 157 host_impl_.active_tree()->SetRootLayerForTesting(std::move(root)); | 159 host_impl_.active_tree()->SetRootLayerForTesting(std::move(root)); |
| 158 | 160 |
| 159 return host_impl_.active_tree()->root_layer_for_testing(); | 161 return host_impl_.active_tree()->root_layer_for_testing(); |
| 160 } | 162 } |
| 161 | 163 |
| 162 LayerImpl* CreateAndSetUpTestTreeWithOneSurface() { | 164 LayerImpl* CreateAndSetUpTestTreeWithOneSurface(int number_of_children = 1) { |
| 163 LayerImpl* root = CreateTestTreeWithOneSurface(); | 165 LayerImpl* root = CreateTestTreeWithOneSurface(number_of_children); |
| 164 | 166 |
| 165 // Setup includes going past the first frame which always damages | 167 // Setup includes going past the first frame which always damages |
| 166 // everything, so that we can actually perform specific tests. | 168 // everything, so that we can actually perform specific tests. |
| 167 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 169 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 168 EmulateDrawingOneFrame(root); | 170 EmulateDrawingOneFrame(root); |
| 169 | 171 |
| 170 return root; | 172 return root; |
| 171 } | 173 } |
| 172 | 174 |
| 173 LayerImpl* CreateAndSetUpTestTreeWithTwoSurfaces() { | 175 LayerImpl* CreateAndSetUpTestTreeWithTwoSurfaces() { |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 190 TEST_F(DamageTrackerTest, SanityCheckTestTreeWithOneSurface) { | 192 TEST_F(DamageTrackerTest, SanityCheckTestTreeWithOneSurface) { |
| 191 // Sanity check that the simple test tree will actually produce the expected | 193 // Sanity check that the simple test tree will actually produce the expected |
| 192 // render surfaces and layer lists. | 194 // render surfaces and layer lists. |
| 193 | 195 |
| 194 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 196 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
| 195 | 197 |
| 196 EXPECT_EQ(2u, root->render_surface()->layer_list().size()); | 198 EXPECT_EQ(2u, root->render_surface()->layer_list().size()); |
| 197 EXPECT_EQ(1, root->render_surface()->layer_list()[0]->id()); | 199 EXPECT_EQ(1, root->render_surface()->layer_list()[0]->id()); |
| 198 EXPECT_EQ(2, root->render_surface()->layer_list()[1]->id()); | 200 EXPECT_EQ(2, root->render_surface()->layer_list()[1]->id()); |
| 199 | 201 |
| 202 EXPECT_FALSE( | |
| 203 root->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 200 gfx::Rect root_damage_rect = | 204 gfx::Rect root_damage_rect = |
| 201 root->render_surface()->damage_tracker()->current_damage_rect(); | 205 root->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 202 | 206 |
| 203 EXPECT_EQ(gfx::Rect(500, 500).ToString(), root_damage_rect.ToString()); | 207 EXPECT_EQ(gfx::Rect(500, 500).ToString(), root_damage_rect.ToString()); |
| 204 } | 208 } |
| 205 | 209 |
| 206 TEST_F(DamageTrackerTest, SanityCheckTestTreeWithTwoSurfaces) { | 210 TEST_F(DamageTrackerTest, SanityCheckTestTreeWithTwoSurfaces) { |
| 207 // Sanity check that the complex test tree will actually produce the expected | 211 // Sanity check that the complex test tree will actually produce the expected |
| 208 // render surfaces and layer lists. | 212 // render surfaces and layer lists. |
| 209 | 213 |
| 210 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 214 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
| 211 | 215 |
| 212 LayerImpl* child1 = root->test_properties()->children[0]; | 216 LayerImpl* child1 = root->test_properties()->children[0]; |
| 213 LayerImpl* child2 = root->test_properties()->children[1]; | 217 LayerImpl* child2 = root->test_properties()->children[1]; |
| 218 | |
| 219 EXPECT_FALSE( | |
| 220 child1->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 221 EXPECT_FALSE( | |
| 222 root->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 214 gfx::Rect child_damage_rect = | 223 gfx::Rect child_damage_rect = |
| 215 child1->render_surface()->damage_tracker()->current_damage_rect(); | 224 child1->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 216 gfx::Rect root_damage_rect = | 225 gfx::Rect root_damage_rect = |
| 217 root->render_surface()->damage_tracker()->current_damage_rect(); | 226 root->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 218 | 227 |
| 219 ASSERT_TRUE(child1->render_surface()); | 228 ASSERT_TRUE(child1->render_surface()); |
| 220 EXPECT_FALSE(child2->render_surface()); | 229 EXPECT_FALSE(child2->render_surface()); |
| 221 EXPECT_EQ(3u, root->render_surface()->layer_list().size()); | 230 EXPECT_EQ(3u, root->render_surface()->layer_list().size()); |
| 222 EXPECT_EQ(2u, child1->render_surface()->layer_list().size()); | 231 EXPECT_EQ(2u, child1->render_surface()->layer_list().size()); |
| 223 | 232 |
| 224 // The render surface for child1 only has a content_rect that encloses | 233 // The render surface for child1 only has a content_rect that encloses |
| 225 // grand_child1 and grand_child2, because child1 does not draw content. | 234 // grand_child1 and grand_child2, because child1 does not draw content. |
| 226 EXPECT_EQ(gfx::Rect(190, 190, 16, 18).ToString(), | 235 EXPECT_EQ(gfx::Rect(190, 190, 16, 18).ToString(), |
| 227 child_damage_rect.ToString()); | 236 child_damage_rect.ToString()); |
| 228 EXPECT_EQ(gfx::Rect(500, 500).ToString(), root_damage_rect.ToString()); | 237 EXPECT_EQ(gfx::Rect(500, 500).ToString(), root_damage_rect.ToString()); |
| 229 } | 238 } |
| 230 | 239 |
| 231 TEST_F(DamageTrackerTest, VerifyDamageForUpdateRects) { | 240 TEST_F(DamageTrackerTest, VerifyDamageForUpdateRects) { |
| 232 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 241 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
| 233 LayerImpl* child = root->test_properties()->children[0]; | 242 LayerImpl* child = root->test_properties()->children[0]; |
| 234 | 243 |
| 235 // CASE 1: Setting the update rect should cause the corresponding damage to | 244 // CASE 1: Setting the update rect should cause the corresponding damage to |
| 236 // the surface. | 245 // the surface. |
| 237 ClearDamageForAllSurfaces(root); | 246 ClearDamageForAllSurfaces(root); |
| 238 child->SetUpdateRect(gfx::Rect(10, 11, 12, 13)); | 247 child->SetUpdateRect(gfx::Rect(10, 11, 12, 13)); |
| 239 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 248 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 240 EmulateDrawingOneFrame(root); | 249 EmulateDrawingOneFrame(root); |
| 241 | 250 |
| 242 // Damage position on the surface should be: position of update_rect (10, 11) | 251 // Damage position on the surface should be: position of update_rect (10, 11) |
| 243 // relative to the child (100, 100). | 252 // relative to the child (100, 100). |
| 253 EXPECT_FALSE( | |
| 254 root->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 244 gfx::Rect root_damage_rect = | 255 gfx::Rect root_damage_rect = |
| 245 root->render_surface()->damage_tracker()->current_damage_rect(); | 256 root->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 246 EXPECT_EQ(gfx::Rect(110, 111, 12, 13).ToString(), | 257 EXPECT_EQ(gfx::Rect(110, 111, 12, 13).ToString(), |
| 247 root_damage_rect.ToString()); | 258 root_damage_rect.ToString()); |
| 248 | 259 |
| 249 // CASE 2: The same update rect twice in a row still produces the same | 260 // CASE 2: The same update rect twice in a row still produces the same |
| 250 // damage. | 261 // damage. |
| 251 ClearDamageForAllSurfaces(root); | 262 ClearDamageForAllSurfaces(root); |
| 252 child->SetUpdateRect(gfx::Rect(10, 11, 12, 13)); | 263 child->SetUpdateRect(gfx::Rect(10, 11, 12, 13)); |
| 253 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 264 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 254 EmulateDrawingOneFrame(root); | 265 EmulateDrawingOneFrame(root); |
| 266 EXPECT_FALSE( | |
| 267 root->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 255 root_damage_rect = | 268 root_damage_rect = |
| 256 root->render_surface()->damage_tracker()->current_damage_rect(); | 269 root->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 257 EXPECT_EQ(gfx::Rect(110, 111, 12, 13).ToString(), | 270 EXPECT_EQ(gfx::Rect(110, 111, 12, 13).ToString(), |
| 258 root_damage_rect.ToString()); | 271 root_damage_rect.ToString()); |
| 259 | 272 |
| 260 // CASE 3: Setting a different update rect should cause damage on the new | 273 // CASE 3: Setting a different update rect should cause damage on the new |
| 261 // update region, but no additional exposed old region. | 274 // update region, but no additional exposed old region. |
| 262 ClearDamageForAllSurfaces(root); | 275 ClearDamageForAllSurfaces(root); |
| 263 child->SetUpdateRect(gfx::Rect(20, 25, 1, 2)); | 276 child->SetUpdateRect(gfx::Rect(20, 25, 1, 2)); |
| 264 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 277 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 265 EmulateDrawingOneFrame(root); | 278 EmulateDrawingOneFrame(root); |
| 266 | 279 |
| 267 // Damage position on the surface should be: position of update_rect (20, 25) | 280 // Damage position on the surface should be: position of update_rect (20, 25) |
| 268 // relative to the child (100, 100). | 281 // relative to the child (100, 100). |
| 282 EXPECT_FALSE( | |
| 283 root->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 269 root_damage_rect = | 284 root_damage_rect = |
| 270 root->render_surface()->damage_tracker()->current_damage_rect(); | 285 root->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 271 EXPECT_EQ(gfx::Rect(120, 125, 1, 2).ToString(), root_damage_rect.ToString()); | 286 EXPECT_EQ(gfx::Rect(120, 125, 1, 2).ToString(), root_damage_rect.ToString()); |
| 272 } | 287 } |
| 273 | 288 |
| 274 TEST_F(DamageTrackerTest, VerifyDamageForLayerDamageRects) { | 289 TEST_F(DamageTrackerTest, VerifyDamageForLayerDamageRects) { |
| 275 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 290 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
| 276 LayerImpl* child = root->test_properties()->children[0]; | 291 LayerImpl* child = root->test_properties()->children[0]; |
| 277 | 292 |
| 278 // CASE 1: Adding the layer damage rect should cause the corresponding damage | 293 // CASE 1: Adding the layer damage rect should cause the corresponding damage |
| 279 // to the surface. | 294 // to the surface. |
| 280 ClearDamageForAllSurfaces(root); | 295 ClearDamageForAllSurfaces(root); |
| 281 child->AddDamageRect(gfx::Rect(10, 11, 12, 13)); | 296 child->AddDamageRect(gfx::Rect(10, 11, 12, 13)); |
| 282 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 297 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 283 EmulateDrawingOneFrame(root); | 298 EmulateDrawingOneFrame(root); |
| 284 | 299 |
| 285 // Damage position on the surface should be: position of layer damage_rect | 300 // Damage position on the surface should be: position of layer damage_rect |
| 286 // (10, 11) relative to the child (100, 100). | 301 // (10, 11) relative to the child (100, 100). |
| 302 EXPECT_FALSE( | |
| 303 root->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 287 gfx::Rect root_damage_rect = | 304 gfx::Rect root_damage_rect = |
| 288 root->render_surface()->damage_tracker()->current_damage_rect(); | 305 root->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 289 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(110, 111, 12, 13))); | 306 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(110, 111, 12, 13))); |
| 290 | 307 |
| 291 // CASE 2: The same layer damage rect twice in a row still produces the same | 308 // CASE 2: The same layer damage rect twice in a row still produces the same |
| 292 // damage. | 309 // damage. |
| 293 ClearDamageForAllSurfaces(root); | 310 ClearDamageForAllSurfaces(root); |
| 294 child->AddDamageRect(gfx::Rect(10, 11, 12, 13)); | 311 child->AddDamageRect(gfx::Rect(10, 11, 12, 13)); |
| 295 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 312 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 296 EmulateDrawingOneFrame(root); | 313 EmulateDrawingOneFrame(root); |
| 314 EXPECT_FALSE( | |
| 315 root->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 297 root_damage_rect = | 316 root_damage_rect = |
| 298 root->render_surface()->damage_tracker()->current_damage_rect(); | 317 root->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 299 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(110, 111, 12, 13))); | 318 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(110, 111, 12, 13))); |
| 300 | 319 |
| 301 // CASE 3: Adding a different layer damage rect should cause damage on the | 320 // CASE 3: Adding a different layer damage rect should cause damage on the |
| 302 // new damaged region, but no additional exposed old region. | 321 // new damaged region, but no additional exposed old region. |
| 303 ClearDamageForAllSurfaces(root); | 322 ClearDamageForAllSurfaces(root); |
| 304 child->AddDamageRect(gfx::Rect(20, 25, 1, 2)); | 323 child->AddDamageRect(gfx::Rect(20, 25, 1, 2)); |
| 305 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 324 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 306 EmulateDrawingOneFrame(root); | 325 EmulateDrawingOneFrame(root); |
| 307 | 326 |
| 308 // Damage position on the surface should be: position of layer damage_rect | 327 // Damage position on the surface should be: position of layer damage_rect |
| 309 // (20, 25) relative to the child (100, 100). | 328 // (20, 25) relative to the child (100, 100). |
| 329 EXPECT_FALSE( | |
| 330 root->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 310 root_damage_rect = | 331 root_damage_rect = |
| 311 root->render_surface()->damage_tracker()->current_damage_rect(); | 332 root->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 312 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(120, 125, 1, 2))); | 333 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(120, 125, 1, 2))); |
| 313 | 334 |
| 314 // CASE 4: Adding multiple layer damage rects should cause a unified | 335 // CASE 4: Adding multiple layer damage rects should cause a unified |
| 315 // damage on root damage rect. | 336 // damage on root damage rect. |
| 316 ClearDamageForAllSurfaces(root); | 337 ClearDamageForAllSurfaces(root); |
| 317 child->AddDamageRect(gfx::Rect(20, 25, 1, 2)); | 338 child->AddDamageRect(gfx::Rect(20, 25, 1, 2)); |
| 318 child->AddDamageRect(gfx::Rect(10, 15, 3, 4)); | 339 child->AddDamageRect(gfx::Rect(10, 15, 3, 4)); |
| 319 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 340 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 320 EmulateDrawingOneFrame(root); | 341 EmulateDrawingOneFrame(root); |
| 321 | 342 |
| 322 // Damage position on the surface should be: position of layer damage_rect | 343 // Damage position on the surface should be: position of layer damage_rect |
| 323 // (20, 25) relative to the child (100, 100). | 344 // (20, 25) relative to the child (100, 100). |
| 345 EXPECT_FALSE( | |
| 346 root->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 324 root_damage_rect = | 347 root_damage_rect = |
| 325 root->render_surface()->damage_tracker()->current_damage_rect(); | 348 root->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 326 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(120, 125, 1, 2))); | 349 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(120, 125, 1, 2))); |
| 327 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(110, 115, 3, 4))); | 350 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(110, 115, 3, 4))); |
| 328 } | 351 } |
| 329 | 352 |
| 330 TEST_F(DamageTrackerTest, VerifyDamageForLayerUpdateAndDamageRects) { | 353 TEST_F(DamageTrackerTest, VerifyDamageForLayerUpdateAndDamageRects) { |
| 331 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 354 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
| 332 LayerImpl* child = root->test_properties()->children[0]; | 355 LayerImpl* child = root->test_properties()->children[0]; |
| 333 | 356 |
| 334 // CASE 1: Adding the layer damage rect and update rect should cause the | 357 // CASE 1: Adding the layer damage rect and update rect should cause the |
| 335 // corresponding damage to the surface. | 358 // corresponding damage to the surface. |
| 336 ClearDamageForAllSurfaces(root); | 359 ClearDamageForAllSurfaces(root); |
| 337 child->AddDamageRect(gfx::Rect(5, 6, 12, 13)); | 360 child->AddDamageRect(gfx::Rect(5, 6, 12, 13)); |
| 338 child->SetUpdateRect(gfx::Rect(15, 16, 14, 10)); | 361 child->SetUpdateRect(gfx::Rect(15, 16, 14, 10)); |
| 339 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 362 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 340 EmulateDrawingOneFrame(root); | 363 EmulateDrawingOneFrame(root); |
| 341 | 364 |
| 342 // Damage position on the surface should be: position of unified layer | 365 // Damage position on the surface should be: position of unified layer |
| 343 // damage_rect and update rect (5, 6) | 366 // damage_rect and update rect (5, 6) |
| 344 // relative to the child (100, 100). | 367 // relative to the child (100, 100). |
| 368 EXPECT_FALSE( | |
| 369 root->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 345 gfx::Rect root_damage_rect = | 370 gfx::Rect root_damage_rect = |
| 346 root->render_surface()->damage_tracker()->current_damage_rect(); | 371 root->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 347 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(105, 106, 24, 20))); | 372 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(105, 106, 24, 20))); |
| 348 | 373 |
| 349 // CASE 2: The same layer damage rect and update rect twice in a row still | 374 // CASE 2: The same layer damage rect and update rect twice in a row still |
| 350 // produces the same damage. | 375 // produces the same damage. |
| 351 ClearDamageForAllSurfaces(root); | 376 ClearDamageForAllSurfaces(root); |
| 352 child->AddDamageRect(gfx::Rect(10, 11, 12, 13)); | 377 child->AddDamageRect(gfx::Rect(10, 11, 12, 13)); |
| 353 child->SetUpdateRect(gfx::Rect(10, 11, 14, 15)); | 378 child->SetUpdateRect(gfx::Rect(10, 11, 14, 15)); |
| 354 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 379 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 355 EmulateDrawingOneFrame(root); | 380 EmulateDrawingOneFrame(root); |
| 381 EXPECT_FALSE( | |
| 382 root->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 356 root_damage_rect = | 383 root_damage_rect = |
| 357 root->render_surface()->damage_tracker()->current_damage_rect(); | 384 root->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 358 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(110, 111, 14, 15))); | 385 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(110, 111, 14, 15))); |
| 359 | 386 |
| 360 // CASE 3: Adding a different layer damage rect and update rect should cause | 387 // CASE 3: Adding a different layer damage rect and update rect should cause |
| 361 // damage on the new damaged region, but no additional exposed old region. | 388 // damage on the new damaged region, but no additional exposed old region. |
| 362 ClearDamageForAllSurfaces(root); | 389 ClearDamageForAllSurfaces(root); |
| 363 child->AddDamageRect(gfx::Rect(20, 25, 2, 3)); | 390 child->AddDamageRect(gfx::Rect(20, 25, 2, 3)); |
| 364 child->SetUpdateRect(gfx::Rect(5, 10, 7, 8)); | 391 child->SetUpdateRect(gfx::Rect(5, 10, 7, 8)); |
| 365 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 392 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 366 EmulateDrawingOneFrame(root); | 393 EmulateDrawingOneFrame(root); |
| 367 | 394 |
| 368 // Damage position on the surface should be: position of unified layer damage | 395 // Damage position on the surface should be: position of unified layer damage |
| 369 // rect and update rect (5, 10) relative to the child (100, 100). | 396 // rect and update rect (5, 10) relative to the child (100, 100). |
| 397 EXPECT_FALSE( | |
| 398 root->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 370 root_damage_rect = | 399 root_damage_rect = |
| 371 root->render_surface()->damage_tracker()->current_damage_rect(); | 400 root->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 372 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(105, 110, 17, 18))); | 401 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(105, 110, 17, 18))); |
| 373 } | 402 } |
| 374 | 403 |
| 375 TEST_F(DamageTrackerTest, VerifyDamageForPropertyChanges) { | 404 TEST_F(DamageTrackerTest, VerifyDamageForPropertyChanges) { |
| 376 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 405 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
| 377 LayerImpl* child = root->test_properties()->children[0]; | 406 LayerImpl* child = root->test_properties()->children[0]; |
| 378 | 407 |
| 379 // CASE 1: The layer's property changed flag takes priority over update rect. | 408 // CASE 1: The layer's property changed flag takes priority over update rect. |
| 380 // | 409 // |
| 381 child->test_properties()->force_render_surface = true; | 410 child->test_properties()->force_render_surface = true; |
| 382 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 411 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 383 EmulateDrawingOneFrame(root); | 412 EmulateDrawingOneFrame(root); |
| 384 ClearDamageForAllSurfaces(root); | 413 ClearDamageForAllSurfaces(root); |
| 385 child->SetUpdateRect(gfx::Rect(10, 11, 12, 13)); | 414 child->SetUpdateRect(gfx::Rect(10, 11, 12, 13)); |
| 386 root->layer_tree_impl()->property_trees()->effect_tree.OnOpacityAnimated( | 415 root->layer_tree_impl()->property_trees()->effect_tree.OnOpacityAnimated( |
| 387 0.5f, child->effect_tree_index(), root->layer_tree_impl()); | 416 0.5f, child->effect_tree_index(), root->layer_tree_impl()); |
| 388 EmulateDrawingOneFrame(root); | 417 EmulateDrawingOneFrame(root); |
| 389 | 418 |
| 390 ASSERT_EQ(2u, root->render_surface()->layer_list().size()); | 419 ASSERT_EQ(2u, root->render_surface()->layer_list().size()); |
| 391 | 420 |
| 392 // Damage should be the entire child layer in target_surface space. | 421 // Damage should be the entire child layer in target_surface space. |
| 393 gfx::Rect expected_rect = gfx::Rect(100, 100, 30, 30); | 422 gfx::Rect expected_rect = gfx::Rect(100, 100, 30, 30); |
| 423 EXPECT_FALSE( | |
| 424 root->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 394 gfx::Rect root_damage_rect = | 425 gfx::Rect root_damage_rect = |
| 395 root->render_surface()->damage_tracker()->current_damage_rect(); | 426 root->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 396 EXPECT_EQ(expected_rect.ToString(), root_damage_rect.ToString()); | 427 EXPECT_EQ(expected_rect.ToString(), root_damage_rect.ToString()); |
| 397 | 428 |
| 398 // CASE 2: If a layer moves due to property change, it damages both the new | 429 // CASE 2: If a layer moves due to property change, it damages both the new |
| 399 // location and the old (exposed) location. The old location is the | 430 // location and the old (exposed) location. The old location is the |
| 400 // entire old layer, not just the update_rect. | 431 // entire old layer, not just the update_rect. |
| 401 | 432 |
| 402 // Cycle one frame of no change, just to sanity check that the next rect is | 433 // Cycle one frame of no change, just to sanity check that the next rect is |
| 403 // not because of the old damage state. | 434 // not because of the old damage state. |
| 404 ClearDamageForAllSurfaces(root); | 435 ClearDamageForAllSurfaces(root); |
| 405 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 436 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 406 EmulateDrawingOneFrame(root); | 437 EmulateDrawingOneFrame(root); |
| 438 EXPECT_FALSE( | |
| 439 root->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 407 root_damage_rect = | 440 root_damage_rect = |
| 408 root->render_surface()->damage_tracker()->current_damage_rect(); | 441 root->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 409 EXPECT_TRUE(root_damage_rect.IsEmpty()); | 442 EXPECT_TRUE(root_damage_rect.IsEmpty()); |
| 410 | 443 |
| 411 // Then, test the actual layer movement. | 444 // Then, test the actual layer movement. |
| 412 ClearDamageForAllSurfaces(root); | 445 ClearDamageForAllSurfaces(root); |
| 413 gfx::Transform translation; | 446 gfx::Transform translation; |
| 414 translation.Translate(100.f, 130.f); | 447 translation.Translate(100.f, 130.f); |
| 415 root->layer_tree_impl()->property_trees()->transform_tree.OnTransformAnimated( | 448 root->layer_tree_impl()->property_trees()->transform_tree.OnTransformAnimated( |
| 416 translation, child->transform_tree_index(), root->layer_tree_impl()); | 449 translation, child->transform_tree_index(), root->layer_tree_impl()); |
| 417 EmulateDrawingOneFrame(root); | 450 EmulateDrawingOneFrame(root); |
| 418 | 451 |
| 419 // Expect damage to be the combination of the previous one and the new one. | 452 // Expect damage to be the combination of the previous one and the new one. |
| 420 expected_rect.Union(gfx::Rect(200, 230, 30, 30)); | 453 expected_rect.Union(gfx::Rect(200, 230, 30, 30)); |
| 454 EXPECT_FALSE( | |
| 455 root->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 421 root_damage_rect = | 456 root_damage_rect = |
| 422 root->render_surface()->damage_tracker()->current_damage_rect(); | 457 root->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 423 EXPECT_FLOAT_RECT_EQ(expected_rect, root_damage_rect); | 458 EXPECT_FLOAT_RECT_EQ(expected_rect, root_damage_rect); |
| 424 } | 459 } |
| 425 | 460 |
| 426 TEST_F(DamageTrackerTest, VerifyDamageWhenSurfaceRemoved) { | 461 TEST_F(DamageTrackerTest, VerifyDamageWhenSurfaceRemoved) { |
| 427 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 462 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
| 428 LayerImpl* surface = root->test_properties()->children[0]; | 463 LayerImpl* surface = root->test_properties()->children[0]; |
| 429 LayerImpl* child = surface->test_properties()->children[0]; | 464 LayerImpl* child = surface->test_properties()->children[0]; |
| 430 child->SetDrawsContent(true); | 465 child->SetDrawsContent(true); |
| 431 EmulateDrawingOneFrame(root); | 466 EmulateDrawingOneFrame(root); |
| 432 ClearDamageForAllSurfaces(root); | 467 ClearDamageForAllSurfaces(root); |
| 433 | 468 |
| 434 surface->test_properties()->force_render_surface = false; | 469 surface->test_properties()->force_render_surface = false; |
| 435 child->SetDrawsContent(false); | 470 child->SetDrawsContent(false); |
| 436 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 471 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 437 EmulateDrawingOneFrame(root); | 472 EmulateDrawingOneFrame(root); |
| 473 EXPECT_FALSE( | |
| 474 root->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 438 gfx::Rect root_damage_rect = | 475 gfx::Rect root_damage_rect = |
| 439 root->render_surface()->damage_tracker()->current_damage_rect(); | 476 root->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 440 EXPECT_EQ(gfx::Rect(290, 290, 16, 18).ToString(), | 477 EXPECT_EQ(gfx::Rect(290, 290, 16, 18).ToString(), |
| 441 root_damage_rect.ToString()); | 478 root_damage_rect.ToString()); |
| 442 } | 479 } |
| 443 | 480 |
| 444 TEST_F(DamageTrackerTest, VerifyDamageForTransformedLayer) { | 481 TEST_F(DamageTrackerTest, VerifyDamageForTransformedLayer) { |
| 445 // If a layer is transformed, the damage rect should still enclose the entire | 482 // If a layer is transformed, the damage rect should still enclose the entire |
| 446 // transformed layer. | 483 // transformed layer. |
| 447 | 484 |
| 448 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 485 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
| 449 LayerImpl* child = root->test_properties()->children[0]; | 486 LayerImpl* child = root->test_properties()->children[0]; |
| 450 child->test_properties()->force_render_surface = true; | 487 child->test_properties()->force_render_surface = true; |
| 451 | 488 |
| 452 gfx::Transform rotation; | 489 gfx::Transform rotation; |
| 453 rotation.Rotate(45.0); | 490 rotation.Rotate(45.0); |
| 454 | 491 |
| 455 ClearDamageForAllSurfaces(root); | 492 ClearDamageForAllSurfaces(root); |
| 456 child->test_properties()->transform_origin = gfx::Point3F( | 493 child->test_properties()->transform_origin = gfx::Point3F( |
| 457 child->bounds().width() * 0.5f, child->bounds().height() * 0.5f, 0.f); | 494 child->bounds().width() * 0.5f, child->bounds().height() * 0.5f, 0.f); |
| 458 child->SetPosition(gfx::PointF(85.f, 85.f)); | 495 child->SetPosition(gfx::PointF(85.f, 85.f)); |
| 459 child->NoteLayerPropertyChanged(); | 496 child->NoteLayerPropertyChanged(); |
| 460 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 497 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 461 EmulateDrawingOneFrame(root); | 498 EmulateDrawingOneFrame(root); |
| 462 | 499 |
| 463 // Sanity check that the layer actually moved to (85, 85), damaging its old | 500 // Sanity check that the layer actually moved to (85, 85), damaging its old |
| 464 // location and new location. | 501 // location and new location. |
| 502 EXPECT_FALSE( | |
| 503 root->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 465 gfx::Rect root_damage_rect = | 504 gfx::Rect root_damage_rect = |
| 466 root->render_surface()->damage_tracker()->current_damage_rect(); | 505 root->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 467 EXPECT_EQ(gfx::Rect(85, 85, 45, 45).ToString(), root_damage_rect.ToString()); | 506 EXPECT_EQ(gfx::Rect(85, 85, 45, 45).ToString(), root_damage_rect.ToString()); |
| 468 | 507 |
| 469 // With the anchor on the layer's center, now we can test the rotation more | 508 // With the anchor on the layer's center, now we can test the rotation more |
| 470 // intuitively, since it applies about the layer's anchor. | 509 // intuitively, since it applies about the layer's anchor. |
| 471 ClearDamageForAllSurfaces(root); | 510 ClearDamageForAllSurfaces(root); |
| 472 root->layer_tree_impl()->property_trees()->transform_tree.OnTransformAnimated( | 511 root->layer_tree_impl()->property_trees()->transform_tree.OnTransformAnimated( |
| 473 rotation, child->transform_tree_index(), root->layer_tree_impl()); | 512 rotation, child->transform_tree_index(), root->layer_tree_impl()); |
| 474 EmulateDrawingOneFrame(root); | 513 EmulateDrawingOneFrame(root); |
| 475 | 514 |
| 476 // Since the child layer is square, rotation by 45 degrees about the center | 515 // Since the child layer is square, rotation by 45 degrees about the center |
| 477 // should increase the size of the expected rect by sqrt(2), centered around | 516 // should increase the size of the expected rect by sqrt(2), centered around |
| 478 // (100, 100). The old exposed region should be fully contained in the new | 517 // (100, 100). The old exposed region should be fully contained in the new |
| 479 // region. | 518 // region. |
| 480 float expected_width = 30.f * sqrt(2.f); | 519 float expected_width = 30.f * sqrt(2.f); |
| 481 float expected_position = 100.f - 0.5f * expected_width; | 520 float expected_position = 100.f - 0.5f * expected_width; |
| 482 gfx::Rect expected_rect = gfx::ToEnclosingRect(gfx::RectF( | 521 gfx::Rect expected_rect = gfx::ToEnclosingRect(gfx::RectF( |
| 483 expected_position, expected_position, expected_width, expected_width)); | 522 expected_position, expected_position, expected_width, expected_width)); |
| 523 EXPECT_FALSE( | |
| 524 root->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 484 root_damage_rect = | 525 root_damage_rect = |
| 485 root->render_surface()->damage_tracker()->current_damage_rect(); | 526 root->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 486 EXPECT_EQ(expected_rect.ToString(), root_damage_rect.ToString()); | 527 EXPECT_EQ(expected_rect.ToString(), root_damage_rect.ToString()); |
| 487 } | 528 } |
| 488 | 529 |
| 489 TEST_F(DamageTrackerTest, VerifyDamageForPerspectiveClippedLayer) { | 530 TEST_F(DamageTrackerTest, VerifyDamageForPerspectiveClippedLayer) { |
| 490 // If a layer has a perspective transform that causes w < 0, then not | 531 // If a layer has a perspective transform that causes w < 0, then not |
| 491 // clipping the layer can cause an invalid damage rect. This test checks that | 532 // clipping the layer can cause an invalid damage rect. This test checks that |
| 492 // the w < 0 case is tracked properly. | 533 // the w < 0 case is tracked properly. |
| 493 // | 534 // |
| 494 // The transform is constructed so that if w < 0 clipping is not performed, | 535 // The transform is constructed so that if w < 0 clipping is not performed, |
| 495 // the incorrect rect will be very small, specifically: position (500.972504, | 536 // the incorrect rect will be very small, specifically: position (500.972504, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 527 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 568 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 528 EmulateDrawingOneFrame(root); | 569 EmulateDrawingOneFrame(root); |
| 529 ClearDamageForAllSurfaces(root); | 570 ClearDamageForAllSurfaces(root); |
| 530 root->layer_tree_impl()->property_trees()->effect_tree.OnOpacityAnimated( | 571 root->layer_tree_impl()->property_trees()->effect_tree.OnOpacityAnimated( |
| 531 0.5f, child->effect_tree_index(), root->layer_tree_impl()); | 572 0.5f, child->effect_tree_index(), root->layer_tree_impl()); |
| 532 EmulateDrawingOneFrame(root); | 573 EmulateDrawingOneFrame(root); |
| 533 | 574 |
| 534 // The expected damage should cover the entire root surface (500x500), but we | 575 // The expected damage should cover the entire root surface (500x500), but we |
| 535 // don't care whether the damage rect was clamped or is larger than the | 576 // don't care whether the damage rect was clamped or is larger than the |
| 536 // surface for this test. | 577 // surface for this test. |
| 578 EXPECT_FALSE( | |
| 579 root->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 537 gfx::Rect root_damage_rect = | 580 gfx::Rect root_damage_rect = |
| 538 root->render_surface()->damage_tracker()->current_damage_rect(); | 581 root->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 539 gfx::Rect damage_we_care_about = gfx::Rect(gfx::Size(500, 500)); | 582 gfx::Rect damage_we_care_about = gfx::Rect(gfx::Size(500, 500)); |
| 540 EXPECT_TRUE(root_damage_rect.Contains(damage_we_care_about)); | 583 EXPECT_TRUE(root_damage_rect.Contains(damage_we_care_about)); |
| 541 } | 584 } |
| 542 | 585 |
| 543 TEST_F(DamageTrackerTest, VerifyDamageForBlurredSurface) { | 586 TEST_F(DamageTrackerTest, VerifyDamageForBlurredSurface) { |
| 544 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 587 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
| 545 LayerImpl* surface = root->test_properties()->children[0]; | 588 LayerImpl* surface = root->test_properties()->children[0]; |
| 546 LayerImpl* child = surface->test_properties()->children[0]; | 589 LayerImpl* child = surface->test_properties()->children[0]; |
| 547 | 590 |
| 548 FilterOperations filters; | 591 FilterOperations filters; |
| 549 filters.Append(FilterOperation::CreateBlurFilter(5.f)); | 592 filters.Append(FilterOperation::CreateBlurFilter(5.f)); |
| 550 | 593 |
| 551 // Setting the filter will damage the whole surface. | 594 // Setting the filter will damage the whole surface. |
| 552 ClearDamageForAllSurfaces(root); | 595 ClearDamageForAllSurfaces(root); |
| 553 surface->test_properties()->filters = filters; | 596 surface->test_properties()->filters = filters; |
| 554 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 597 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 555 EmulateDrawingOneFrame(root); | 598 EmulateDrawingOneFrame(root); |
| 556 | 599 |
| 557 // Setting the update rect should cause the corresponding damage to the | 600 // Setting the update rect should cause the corresponding damage to the |
| 558 // surface, blurred based on the size of the blur filter. | 601 // surface, blurred based on the size of the blur filter. |
| 559 ClearDamageForAllSurfaces(root); | 602 ClearDamageForAllSurfaces(root); |
| 560 child->SetUpdateRect(gfx::Rect(1, 2, 3, 4)); | 603 child->SetUpdateRect(gfx::Rect(1, 2, 3, 4)); |
| 561 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 604 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 562 EmulateDrawingOneFrame(root); | 605 EmulateDrawingOneFrame(root); |
| 563 | 606 |
| 564 // Damage position on the surface should be: position of update_rect (1, 2) | 607 // Damage position on the surface should be: position of update_rect (1, 2) |
| 565 // relative to the child (300, 300), but expanded by the blur outsets | 608 // relative to the child (300, 300), but expanded by the blur outsets |
| 566 // (15, since the blur radius is 5). | 609 // (15, since the blur radius is 5). |
| 610 EXPECT_FALSE( | |
| 611 root->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 567 gfx::Rect root_damage_rect = | 612 gfx::Rect root_damage_rect = |
| 568 root->render_surface()->damage_tracker()->current_damage_rect(); | 613 root->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 569 EXPECT_EQ(gfx::Rect(286, 287, 33, 34), root_damage_rect); | 614 EXPECT_EQ(gfx::Rect(286, 287, 33, 34), root_damage_rect); |
| 570 } | 615 } |
| 571 | 616 |
| 572 TEST_F(DamageTrackerTest, VerifyDamageForImageFilter) { | 617 TEST_F(DamageTrackerTest, VerifyDamageForImageFilter) { |
| 573 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 618 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
| 574 LayerImpl* child = root->test_properties()->children[0]; | 619 LayerImpl* child = root->test_properties()->children[0]; |
| 575 gfx::Rect root_damage_rect, child_damage_rect; | 620 gfx::Rect root_damage_rect, child_damage_rect; |
| 576 | 621 |
| 577 // Allow us to set damage on child too. | 622 // Allow us to set damage on child too. |
| 578 child->SetDrawsContent(true); | 623 child->SetDrawsContent(true); |
| 579 | 624 |
| 580 FilterOperations filters; | 625 FilterOperations filters; |
| 581 filters.Append(FilterOperation::CreateReferenceFilter( | 626 filters.Append(FilterOperation::CreateReferenceFilter( |
| 582 SkBlurImageFilter::Make(2, 2, nullptr))); | 627 SkBlurImageFilter::Make(2, 2, nullptr))); |
| 583 | 628 |
| 584 // Setting the filter will damage the whole surface. | 629 // Setting the filter will damage the whole surface. |
| 585 ClearDamageForAllSurfaces(root); | 630 ClearDamageForAllSurfaces(root); |
| 586 child->test_properties()->force_render_surface = true; | 631 child->test_properties()->force_render_surface = true; |
| 587 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 632 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 588 EmulateDrawingOneFrame(root); | 633 EmulateDrawingOneFrame(root); |
| 589 child->layer_tree_impl()->property_trees()->effect_tree.OnFilterAnimated( | 634 child->layer_tree_impl()->property_trees()->effect_tree.OnFilterAnimated( |
| 590 filters, child->effect_tree_index(), child->layer_tree_impl()); | 635 filters, child->effect_tree_index(), child->layer_tree_impl()); |
| 591 EmulateDrawingOneFrame(root); | 636 EmulateDrawingOneFrame(root); |
| 637 EXPECT_FALSE( | |
| 638 root->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 639 EXPECT_FALSE( | |
| 640 child->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 592 root_damage_rect = | 641 root_damage_rect = |
| 593 root->render_surface()->damage_tracker()->current_damage_rect(); | 642 root->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 594 child_damage_rect = | 643 child_damage_rect = |
| 595 child->render_surface()->damage_tracker()->current_damage_rect(); | 644 child->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 596 | 645 |
| 597 // gfx::Rect(100, 100, 30, 30), expanded by 6px for the 2px blur filter. | 646 // gfx::Rect(100, 100, 30, 30), expanded by 6px for the 2px blur filter. |
| 598 EXPECT_EQ(gfx::Rect(94, 94, 42, 42), root_damage_rect); | 647 EXPECT_EQ(gfx::Rect(94, 94, 42, 42), root_damage_rect); |
| 599 | 648 |
| 600 // gfx::Rect(0, 0, 30, 30), expanded by 6px for the 2px blur filter. | 649 // gfx::Rect(0, 0, 30, 30), expanded by 6px for the 2px blur filter. |
| 601 EXPECT_EQ(gfx::Rect(-6, -6, 42, 42), child_damage_rect); | 650 EXPECT_EQ(gfx::Rect(-6, -6, 42, 42), child_damage_rect); |
| 602 | 651 |
| 603 // CASE 1: Setting the update rect should damage the whole surface (for now) | 652 // CASE 1: Setting the update rect should damage the whole surface (for now) |
| 604 ClearDamageForAllSurfaces(root); | 653 ClearDamageForAllSurfaces(root); |
| 605 child->SetUpdateRect(gfx::Rect(1, 1)); | 654 child->SetUpdateRect(gfx::Rect(1, 1)); |
| 606 EmulateDrawingOneFrame(root); | 655 EmulateDrawingOneFrame(root); |
| 607 | 656 |
| 657 EXPECT_FALSE( | |
| 658 root->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 659 EXPECT_FALSE( | |
| 660 child->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 608 root_damage_rect = | 661 root_damage_rect = |
| 609 root->render_surface()->damage_tracker()->current_damage_rect(); | 662 root->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 610 child_damage_rect = | 663 child_damage_rect = |
| 611 child->render_surface()->damage_tracker()->current_damage_rect(); | 664 child->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 612 | 665 |
| 613 // gfx::Rect(100, 100, 1, 1), expanded by 6px for the 2px blur filter. | 666 // gfx::Rect(100, 100, 1, 1), expanded by 6px for the 2px blur filter. |
| 614 EXPECT_EQ(gfx::Rect(94, 94, 13, 13), root_damage_rect); | 667 EXPECT_EQ(gfx::Rect(94, 94, 13, 13), root_damage_rect); |
| 615 | 668 |
| 616 // gfx::Rect(0, 0, 1, 1), expanded by 6px for the 2px blur filter. | 669 // gfx::Rect(0, 0, 1, 1), expanded by 6px for the 2px blur filter. |
| 617 EXPECT_EQ(gfx::Rect(-6, -6, 13, 13), child_damage_rect); | 670 EXPECT_EQ(gfx::Rect(-6, -6, 13, 13), child_damage_rect); |
| 618 } | 671 } |
| 619 | 672 |
| 620 TEST_F(DamageTrackerTest, VerifyDamageForTransformedImageFilter) { | 673 TEST_F(DamageTrackerTest, VerifyDamageForTransformedImageFilter) { |
| 621 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 674 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 633 gfx::Transform transform; | 686 gfx::Transform transform; |
| 634 transform.RotateAboutYAxis(60); | 687 transform.RotateAboutYAxis(60); |
| 635 ClearDamageForAllSurfaces(root); | 688 ClearDamageForAllSurfaces(root); |
| 636 child->test_properties()->force_render_surface = true; | 689 child->test_properties()->force_render_surface = true; |
| 637 child->test_properties()->transform = transform; | 690 child->test_properties()->transform = transform; |
| 638 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 691 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 639 EmulateDrawingOneFrame(root); | 692 EmulateDrawingOneFrame(root); |
| 640 child->layer_tree_impl()->property_trees()->effect_tree.OnFilterAnimated( | 693 child->layer_tree_impl()->property_trees()->effect_tree.OnFilterAnimated( |
| 641 filters, child->effect_tree_index(), child->layer_tree_impl()); | 694 filters, child->effect_tree_index(), child->layer_tree_impl()); |
| 642 EmulateDrawingOneFrame(root); | 695 EmulateDrawingOneFrame(root); |
| 696 EXPECT_FALSE( | |
| 697 root->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 698 EXPECT_FALSE( | |
| 699 child->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 643 root_damage_rect = | 700 root_damage_rect = |
| 644 root->render_surface()->damage_tracker()->current_damage_rect(); | 701 root->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 645 child_damage_rect = | 702 child_damage_rect = |
| 646 child->render_surface()->damage_tracker()->current_damage_rect(); | 703 child->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 647 | 704 |
| 648 // Blur outset is 6px for a 2px blur. | 705 // Blur outset is 6px for a 2px blur. |
| 649 int blur_outset = 6; | 706 int blur_outset = 6; |
| 650 int rotated_outset_left = blur_outset / 2; | 707 int rotated_outset_left = blur_outset / 2; |
| 651 int expected_rotated_width = (30 + 2 * blur_outset) / 2; | 708 int expected_rotated_width = (30 + 2 * blur_outset) / 2; |
| 652 gfx::Rect expected_root_damage(100 - rotated_outset_left, 100 - blur_outset, | 709 gfx::Rect expected_root_damage(100 - rotated_outset_left, 100 - blur_outset, |
| 653 expected_rotated_width, 30 + 2 * blur_outset); | 710 expected_rotated_width, 30 + 2 * blur_outset); |
| 654 expected_root_damage.Union(gfx::Rect(100, 100, 30, 30)); | 711 expected_root_damage.Union(gfx::Rect(100, 100, 30, 30)); |
| 655 EXPECT_EQ(expected_root_damage, root_damage_rect); | 712 EXPECT_EQ(expected_root_damage, root_damage_rect); |
| 656 EXPECT_EQ(gfx::Rect(-blur_outset, -blur_outset, 30 + 2 * blur_outset, | 713 EXPECT_EQ(gfx::Rect(-blur_outset, -blur_outset, 30 + 2 * blur_outset, |
| 657 30 + 2 * blur_outset), | 714 30 + 2 * blur_outset), |
| 658 child_damage_rect); | 715 child_damage_rect); |
| 659 | 716 |
| 660 // Setting the update rect should damage the whole surface (for now) | 717 // Setting the update rect should damage the whole surface (for now) |
| 661 ClearDamageForAllSurfaces(root); | 718 ClearDamageForAllSurfaces(root); |
| 662 child->SetUpdateRect(gfx::Rect(30, 30)); | 719 child->SetUpdateRect(gfx::Rect(30, 30)); |
| 663 EmulateDrawingOneFrame(root); | 720 EmulateDrawingOneFrame(root); |
| 664 | 721 |
| 722 EXPECT_FALSE( | |
| 723 root->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 724 EXPECT_FALSE( | |
| 725 child->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 665 root_damage_rect = | 726 root_damage_rect = |
| 666 root->render_surface()->damage_tracker()->current_damage_rect(); | 727 root->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 667 child_damage_rect = | 728 child_damage_rect = |
| 668 child->render_surface()->damage_tracker()->current_damage_rect(); | 729 child->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 669 | 730 |
| 670 int expect_width = 30 + 2 * blur_outset; | 731 int expect_width = 30 + 2 * blur_outset; |
| 671 int expect_height = 30 + 2 * blur_outset; | 732 int expect_height = 30 + 2 * blur_outset; |
| 672 EXPECT_EQ(gfx::Rect(100 - blur_outset / 2, 100 - blur_outset, | 733 EXPECT_EQ(gfx::Rect(100 - blur_outset / 2, 100 - blur_outset, |
| 673 expect_width / 2, expect_height), | 734 expect_width / 2, expect_height), |
| 674 root_damage_rect); | 735 root_damage_rect); |
| 675 EXPECT_EQ(gfx::Rect(-blur_outset, -blur_outset, expect_width, expect_height), | 736 EXPECT_EQ(gfx::Rect(-blur_outset, -blur_outset, expect_width, expect_height), |
| 676 child_damage_rect); | 737 child_damage_rect); |
| 677 } | 738 } |
| 678 | 739 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 689 | 750 |
| 690 // Setting the filter will damage the whole surface. | 751 // Setting the filter will damage the whole surface. |
| 691 ClearDamageForAllSurfaces(root); | 752 ClearDamageForAllSurfaces(root); |
| 692 child->test_properties()->force_render_surface = true; | 753 child->test_properties()->force_render_surface = true; |
| 693 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 754 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 694 int device_scale_factor = 2; | 755 int device_scale_factor = 2; |
| 695 EmulateDrawingOneFrame(root, device_scale_factor); | 756 EmulateDrawingOneFrame(root, device_scale_factor); |
| 696 child->layer_tree_impl()->property_trees()->effect_tree.OnFilterAnimated( | 757 child->layer_tree_impl()->property_trees()->effect_tree.OnFilterAnimated( |
| 697 filters, child->effect_tree_index(), child->layer_tree_impl()); | 758 filters, child->effect_tree_index(), child->layer_tree_impl()); |
| 698 EmulateDrawingOneFrame(root, device_scale_factor); | 759 EmulateDrawingOneFrame(root, device_scale_factor); |
| 760 EXPECT_FALSE( | |
| 761 root->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 762 EXPECT_FALSE( | |
| 763 child->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 699 root_damage_rect = | 764 root_damage_rect = |
| 700 root->render_surface()->damage_tracker()->current_damage_rect(); | 765 root->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 701 child_damage_rect = | 766 child_damage_rect = |
| 702 child->render_surface()->damage_tracker()->current_damage_rect(); | 767 child->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 703 | 768 |
| 704 // Blur outset is 9px for a 3px blur, scaled up by DSF. | 769 // Blur outset is 9px for a 3px blur, scaled up by DSF. |
| 705 int blur_outset = 9 * device_scale_factor; | 770 int blur_outset = 9 * device_scale_factor; |
| 706 gfx::Rect original_rect(100, 100, 100, 100); | 771 gfx::Rect original_rect(100, 100, 100, 100); |
| 707 gfx::Rect expected_child_damage_rect(60, 60); | 772 gfx::Rect expected_child_damage_rect(60, 60); |
| 708 expected_child_damage_rect.Inset(-blur_outset, -blur_outset); | 773 expected_child_damage_rect.Inset(-blur_outset, -blur_outset); |
| 709 gfx::Rect expected_root_damage_rect(child_damage_rect); | 774 gfx::Rect expected_root_damage_rect(child_damage_rect); |
| 710 expected_root_damage_rect.Offset(200, 200); | 775 expected_root_damage_rect.Offset(200, 200); |
| 711 gfx::Rect expected_total_damage_rect = expected_root_damage_rect; | 776 gfx::Rect expected_total_damage_rect = expected_root_damage_rect; |
| 712 expected_total_damage_rect.Union(original_rect); | 777 expected_total_damage_rect.Union(original_rect); |
| 713 EXPECT_EQ(expected_total_damage_rect, root_damage_rect); | 778 EXPECT_EQ(expected_total_damage_rect, root_damage_rect); |
| 714 EXPECT_EQ(expected_child_damage_rect, child_damage_rect); | 779 EXPECT_EQ(expected_child_damage_rect, child_damage_rect); |
| 715 | 780 |
| 716 // Setting the update rect should damage only the affected area (original, | 781 // Setting the update rect should damage only the affected area (original, |
| 717 // outset by 3 * blur sigma * DSF). | 782 // outset by 3 * blur sigma * DSF). |
| 718 ClearDamageForAllSurfaces(root); | 783 ClearDamageForAllSurfaces(root); |
| 719 child->SetUpdateRect(gfx::Rect(30, 30)); | 784 child->SetUpdateRect(gfx::Rect(30, 30)); |
| 720 EmulateDrawingOneFrame(root, device_scale_factor); | 785 EmulateDrawingOneFrame(root, device_scale_factor); |
| 721 | 786 |
| 787 EXPECT_FALSE( | |
| 788 root->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 789 EXPECT_FALSE( | |
| 790 child->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 722 root_damage_rect = | 791 root_damage_rect = |
| 723 root->render_surface()->damage_tracker()->current_damage_rect(); | 792 root->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 724 child_damage_rect = | 793 child_damage_rect = |
| 725 child->render_surface()->damage_tracker()->current_damage_rect(); | 794 child->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 726 | 795 |
| 727 EXPECT_EQ(expected_root_damage_rect, root_damage_rect); | 796 EXPECT_EQ(expected_root_damage_rect, root_damage_rect); |
| 728 EXPECT_EQ(expected_child_damage_rect, child_damage_rect); | 797 EXPECT_EQ(expected_child_damage_rect, child_damage_rect); |
| 729 } | 798 } |
| 730 | 799 |
| 731 TEST_F(DamageTrackerTest, VerifyDamageForBackgroundBlurredChild) { | 800 TEST_F(DamageTrackerTest, VerifyDamageForBackgroundBlurredChild) { |
| 732 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 801 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
| 733 LayerImpl* child1 = root->test_properties()->children[0]; | 802 LayerImpl* child1 = root->test_properties()->children[0]; |
| 734 LayerImpl* child2 = root->test_properties()->children[1]; | 803 LayerImpl* child2 = root->test_properties()->children[1]; |
| 735 | 804 |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 748 | 817 |
| 749 // CASE 1: Setting the update rect should cause the corresponding damage to | 818 // CASE 1: Setting the update rect should cause the corresponding damage to |
| 750 // the surface, blurred based on the size of the child's background | 819 // the surface, blurred based on the size of the child's background |
| 751 // blur filter. Note that child1's render surface has a size of | 820 // blur filter. Note that child1's render surface has a size of |
| 752 // 206x208 due to contributions from grand_child1 and grand_child2. | 821 // 206x208 due to contributions from grand_child1 and grand_child2. |
| 753 ClearDamageForAllSurfaces(root); | 822 ClearDamageForAllSurfaces(root); |
| 754 root->SetUpdateRect(gfx::Rect(297, 297, 2, 2)); | 823 root->SetUpdateRect(gfx::Rect(297, 297, 2, 2)); |
| 755 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 824 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 756 EmulateDrawingOneFrame(root); | 825 EmulateDrawingOneFrame(root); |
| 757 | 826 |
| 827 EXPECT_FALSE( | |
| 828 root->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 758 gfx::Rect root_damage_rect = | 829 gfx::Rect root_damage_rect = |
| 759 root->render_surface()->damage_tracker()->current_damage_rect(); | 830 root->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 760 // Damage position on the surface should be a composition of the damage on | 831 // Damage position on the surface should be a composition of the damage on |
| 761 // the root and on child2. Damage on the root should be: position of | 832 // the root and on child2. Damage on the root should be: position of |
| 762 // update_rect (297, 297), but expanded by the blur outsets. | 833 // update_rect (297, 297), but expanded by the blur outsets. |
| 763 gfx::Rect expected_damage_rect = gfx::Rect(297, 297, 2, 2); | 834 gfx::Rect expected_damage_rect = gfx::Rect(297, 297, 2, 2); |
| 764 | 835 |
| 765 // 6px spread for a 2px blur. | 836 // 6px spread for a 2px blur. |
| 766 expected_damage_rect.Inset(-6, -6, -6, -6); | 837 expected_damage_rect.Inset(-6, -6, -6, -6); |
| 767 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString()); | 838 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString()); |
| 768 | 839 |
| 769 // CASE 2: Setting the update rect should cause the corresponding damage to | 840 // CASE 2: Setting the update rect should cause the corresponding damage to |
| 770 // the surface, blurred based on the size of the child's background | 841 // the surface, blurred based on the size of the child's background |
| 771 // blur filter. Since the damage extends to the right/bottom outside | 842 // blur filter. Since the damage extends to the right/bottom outside |
| 772 // of the blurred layer, only the left/top should end up expanded. | 843 // of the blurred layer, only the left/top should end up expanded. |
| 773 ClearDamageForAllSurfaces(root); | 844 ClearDamageForAllSurfaces(root); |
| 774 root->SetUpdateRect(gfx::Rect(297, 297, 30, 30)); | 845 root->SetUpdateRect(gfx::Rect(297, 297, 30, 30)); |
| 775 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 846 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 776 EmulateDrawingOneFrame(root); | 847 EmulateDrawingOneFrame(root); |
| 777 | 848 |
| 849 EXPECT_FALSE( | |
| 850 root->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 778 root_damage_rect = | 851 root_damage_rect = |
| 779 root->render_surface()->damage_tracker()->current_damage_rect(); | 852 root->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 780 // Damage position on the surface should be a composition of the damage on | 853 // Damage position on the surface should be a composition of the damage on |
| 781 // the root and on child2. Damage on the root should be: position of | 854 // the root and on child2. Damage on the root should be: position of |
| 782 // update_rect (297, 297), but expanded on the left/top by the blur outsets. | 855 // update_rect (297, 297), but expanded on the left/top by the blur outsets. |
| 783 expected_damage_rect = gfx::Rect(297, 297, 30, 30); | 856 expected_damage_rect = gfx::Rect(297, 297, 30, 30); |
| 784 | 857 |
| 785 // 6px spread for a 2px blur. | 858 // 6px spread for a 2px blur. |
| 786 expected_damage_rect.Inset(-6, -6, 0, 0); | 859 expected_damage_rect.Inset(-6, -6, 0, 0); |
| 787 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString()); | 860 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString()); |
| 788 | 861 |
| 789 // CASE 3: Setting this update rect outside the blurred content_bounds of the | 862 // CASE 3: Setting this update rect outside the blurred content_bounds of the |
| 790 // blurred child1 will not cause it to be expanded. | 863 // blurred child1 will not cause it to be expanded. |
| 791 ClearDamageForAllSurfaces(root); | 864 ClearDamageForAllSurfaces(root); |
| 792 root->SetUpdateRect(gfx::Rect(30, 30, 2, 2)); | 865 root->SetUpdateRect(gfx::Rect(30, 30, 2, 2)); |
| 793 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 866 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 794 EmulateDrawingOneFrame(root); | 867 EmulateDrawingOneFrame(root); |
| 795 | 868 |
| 869 EXPECT_FALSE( | |
| 870 root->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 796 root_damage_rect = | 871 root_damage_rect = |
| 797 root->render_surface()->damage_tracker()->current_damage_rect(); | 872 root->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 798 // Damage on the root should be: position of update_rect (30, 30), not | 873 // Damage on the root should be: position of update_rect (30, 30), not |
| 799 // expanded. | 874 // expanded. |
| 800 expected_damage_rect = gfx::Rect(30, 30, 2, 2); | 875 expected_damage_rect = gfx::Rect(30, 30, 2, 2); |
| 801 | 876 |
| 802 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString()); | 877 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString()); |
| 803 | 878 |
| 804 // CASE 4: Setting this update rect inside the blurred content_bounds but | 879 // CASE 4: Setting this update rect inside the blurred content_bounds but |
| 805 // outside the original content_bounds of the blurred child1 will | 880 // outside the original content_bounds of the blurred child1 will |
| 806 // cause it to be expanded. | 881 // cause it to be expanded. |
| 807 ClearDamageForAllSurfaces(root); | 882 ClearDamageForAllSurfaces(root); |
| 808 root->SetUpdateRect(gfx::Rect(99, 99, 1, 1)); | 883 root->SetUpdateRect(gfx::Rect(99, 99, 1, 1)); |
| 809 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 884 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 810 EmulateDrawingOneFrame(root); | 885 EmulateDrawingOneFrame(root); |
| 811 | 886 |
| 887 EXPECT_FALSE( | |
| 888 root->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 812 root_damage_rect = | 889 root_damage_rect = |
| 813 root->render_surface()->damage_tracker()->current_damage_rect(); | 890 root->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 814 // Damage on the root should be: the originally damaged rect (99,99 1x1) | 891 // Damage on the root should be: the originally damaged rect (99,99 1x1) |
| 815 // plus the rect that can influence with a 2px blur (93,93 13x13) intersected | 892 // plus the rect that can influence with a 2px blur (93,93 13x13) intersected |
| 816 // with the surface rect (100,100 206x208). So no additional damage occurs | 893 // with the surface rect (100,100 206x208). So no additional damage occurs |
| 817 // above or to the left, but there is additional damage within the blurred | 894 // above or to the left, but there is additional damage within the blurred |
| 818 // area. | 895 // area. |
| 819 expected_damage_rect = gfx::Rect(99, 99, 7, 7); | 896 expected_damage_rect = gfx::Rect(99, 99, 7, 7); |
| 820 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString()); | 897 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString()); |
| 821 | 898 |
| 822 // CASE 5: Setting the update rect on child2, which is above child1, will | 899 // CASE 5: Setting the update rect on child2, which is above child1, will |
| 823 // not get blurred by child1, so it does not need to get expanded. | 900 // not get blurred by child1, so it does not need to get expanded. |
| 824 ClearDamageForAllSurfaces(root); | 901 ClearDamageForAllSurfaces(root); |
| 825 child2->SetUpdateRect(gfx::Rect(1, 1)); | 902 child2->SetUpdateRect(gfx::Rect(1, 1)); |
| 826 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 903 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 827 EmulateDrawingOneFrame(root); | 904 EmulateDrawingOneFrame(root); |
| 828 | 905 |
| 906 EXPECT_FALSE( | |
| 907 root->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 829 root_damage_rect = | 908 root_damage_rect = |
| 830 root->render_surface()->damage_tracker()->current_damage_rect(); | 909 root->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 831 // Damage on child2 should be: position of update_rect offset by the child's | 910 // Damage on child2 should be: position of update_rect offset by the child's |
| 832 // position (11, 11), and not expanded by anything. | 911 // position (11, 11), and not expanded by anything. |
| 833 expected_damage_rect = gfx::Rect(11, 11, 1, 1); | 912 expected_damage_rect = gfx::Rect(11, 11, 1, 1); |
| 834 | 913 |
| 835 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString()); | 914 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString()); |
| 836 | 915 |
| 837 // CASE 6: Setting the update rect on child1 will also blur the damage, so | 916 // CASE 6: Setting the update rect on child1 will also blur the damage, so |
| 838 // that any pixels needed for the blur are redrawn in the current | 917 // that any pixels needed for the blur are redrawn in the current |
| 839 // frame. | 918 // frame. |
| 840 ClearDamageForAllSurfaces(root); | 919 ClearDamageForAllSurfaces(root); |
| 841 child1->SetUpdateRect(gfx::Rect(1, 1)); | 920 child1->SetUpdateRect(gfx::Rect(1, 1)); |
| 842 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 921 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 843 EmulateDrawingOneFrame(root); | 922 EmulateDrawingOneFrame(root); |
| 844 | 923 |
| 924 EXPECT_FALSE( | |
| 925 root->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 845 root_damage_rect = | 926 root_damage_rect = |
| 846 root->render_surface()->damage_tracker()->current_damage_rect(); | 927 root->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 847 // Damage on child1 should be: position of update_rect offset by the child's | 928 // Damage on child1 should be: position of update_rect offset by the child's |
| 848 // position (100, 100), and expanded by the damage. | 929 // position (100, 100), and expanded by the damage. |
| 849 | 930 |
| 850 // Damage should be (0,0 1x1), offset by the 100,100 offset of child1 in | 931 // Damage should be (0,0 1x1), offset by the 100,100 offset of child1 in |
| 851 // root, and expanded 6px for the 2px blur (i.e., 94,94 13x13), but there | 932 // root, and expanded 6px for the 2px blur (i.e., 94,94 13x13), but there |
| 852 // should be no damage outside child1 (i.e. none above or to the left of | 933 // should be no damage outside child1 (i.e. none above or to the left of |
| 853 // 100,100. | 934 // 100,100. |
| 854 expected_damage_rect = gfx::Rect(100, 100, 7, 7); | 935 expected_damage_rect = gfx::Rect(100, 100, 7, 7); |
| 855 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString()); | 936 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString()); |
| 856 } | 937 } |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 870 child2->SetDrawsContent(true); | 951 child2->SetDrawsContent(true); |
| 871 root->test_properties()->AddChild(std::move(child2)); | 952 root->test_properties()->AddChild(std::move(child2)); |
| 872 } | 953 } |
| 873 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 954 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 874 EmulateDrawingOneFrame(root); | 955 EmulateDrawingOneFrame(root); |
| 875 | 956 |
| 876 // Sanity check - all 3 layers should be on the same render surface; render | 957 // Sanity check - all 3 layers should be on the same render surface; render |
| 877 // surfaces are tested elsewhere. | 958 // surfaces are tested elsewhere. |
| 878 ASSERT_EQ(3u, root->render_surface()->layer_list().size()); | 959 ASSERT_EQ(3u, root->render_surface()->layer_list().size()); |
| 879 | 960 |
| 961 EXPECT_FALSE( | |
| 962 root->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 880 gfx::Rect root_damage_rect = | 963 gfx::Rect root_damage_rect = |
| 881 root->render_surface()->damage_tracker()->current_damage_rect(); | 964 root->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 882 EXPECT_EQ(gfx::Rect(400, 380, 6, 8).ToString(), root_damage_rect.ToString()); | 965 EXPECT_EQ(gfx::Rect(400, 380, 6, 8).ToString(), root_damage_rect.ToString()); |
| 883 | 966 |
| 884 // CASE 2: If the layer is removed, its entire old layer becomes exposed, not | 967 // CASE 2: If the layer is removed, its entire old layer becomes exposed, not |
| 885 // just the last update rect. | 968 // just the last update rect. |
| 886 | 969 |
| 887 // Advance one frame without damage so that we know the damage rect is not | 970 // Advance one frame without damage so that we know the damage rect is not |
| 888 // leftover from the previous case. | 971 // leftover from the previous case. |
| 889 ClearDamageForAllSurfaces(root); | 972 ClearDamageForAllSurfaces(root); |
| 890 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 973 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 891 EmulateDrawingOneFrame(root); | 974 EmulateDrawingOneFrame(root); |
| 892 | 975 |
| 976 EXPECT_FALSE( | |
| 977 root->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 893 root_damage_rect = | 978 root_damage_rect = |
| 894 root->render_surface()->damage_tracker()->current_damage_rect(); | 979 root->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 895 EXPECT_TRUE(root_damage_rect.IsEmpty()); | 980 EXPECT_TRUE(root_damage_rect.IsEmpty()); |
| 896 | 981 |
| 897 // Then, test removing child1. | 982 // Then, test removing child1. |
| 898 root->test_properties()->RemoveChild(child1); | 983 root->test_properties()->RemoveChild(child1); |
| 899 child1 = NULL; | 984 child1 = NULL; |
| 900 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 985 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 901 EmulateDrawingOneFrame(root); | 986 EmulateDrawingOneFrame(root); |
| 902 | 987 |
| 988 EXPECT_FALSE( | |
| 989 root->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 903 root_damage_rect = | 990 root_damage_rect = |
| 904 root->render_surface()->damage_tracker()->current_damage_rect(); | 991 root->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 905 EXPECT_EQ(gfx::Rect(100, 100, 30, 30).ToString(), | 992 EXPECT_EQ(gfx::Rect(100, 100, 30, 30).ToString(), |
| 906 root_damage_rect.ToString()); | 993 root_damage_rect.ToString()); |
| 907 } | 994 } |
| 908 | 995 |
| 909 TEST_F(DamageTrackerTest, VerifyDamageForNewUnchangedLayer) { | 996 TEST_F(DamageTrackerTest, VerifyDamageForNewUnchangedLayer) { |
| 910 // If child2 is added to the layer tree, but it doesn't have any explicit | 997 // If child2 is added to the layer tree, but it doesn't have any explicit |
| 911 // damage of its own, it should still indeed damage the target surface. | 998 // damage of its own, it should still indeed damage the target surface. |
| 912 | 999 |
| 913 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 1000 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
| 914 | 1001 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 929 ASSERT_FALSE(child2_ptr->LayerPropertyChanged()); | 1016 ASSERT_FALSE(child2_ptr->LayerPropertyChanged()); |
| 930 ASSERT_TRUE(child2_ptr->update_rect().IsEmpty()); | 1017 ASSERT_TRUE(child2_ptr->update_rect().IsEmpty()); |
| 931 } | 1018 } |
| 932 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1019 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 933 EmulateDrawingOneFrame(root); | 1020 EmulateDrawingOneFrame(root); |
| 934 | 1021 |
| 935 // Sanity check - all 3 layers should be on the same render surface; render | 1022 // Sanity check - all 3 layers should be on the same render surface; render |
| 936 // surfaces are tested elsewhere. | 1023 // surfaces are tested elsewhere. |
| 937 ASSERT_EQ(3u, root->render_surface()->layer_list().size()); | 1024 ASSERT_EQ(3u, root->render_surface()->layer_list().size()); |
| 938 | 1025 |
| 1026 EXPECT_FALSE( | |
| 1027 root->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 939 gfx::Rect root_damage_rect = | 1028 gfx::Rect root_damage_rect = |
| 940 root->render_surface()->damage_tracker()->current_damage_rect(); | 1029 root->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 941 EXPECT_EQ(gfx::Rect(400, 380, 6, 8).ToString(), root_damage_rect.ToString()); | 1030 EXPECT_EQ(gfx::Rect(400, 380, 6, 8).ToString(), root_damage_rect.ToString()); |
| 942 } | 1031 } |
| 943 | 1032 |
| 944 TEST_F(DamageTrackerTest, VerifyDamageForMultipleLayers) { | 1033 TEST_F(DamageTrackerTest, VerifyDamageForMultipleLayers) { |
| 945 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 1034 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
| 946 LayerImpl* child1 = root->test_properties()->children[0]; | 1035 LayerImpl* child1 = root->test_properties()->children[0]; |
| 947 | 1036 |
| 948 // In this test we don't want the above tree manipulation to be considered | 1037 // In this test we don't want the above tree manipulation to be considered |
| 949 // part of the same frame. | 1038 // part of the same frame. |
| 950 ClearDamageForAllSurfaces(root); | 1039 ClearDamageForAllSurfaces(root); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 961 EmulateDrawingOneFrame(root); | 1050 EmulateDrawingOneFrame(root); |
| 962 | 1051 |
| 963 // Damaging two layers simultaneously should cause combined damage. | 1052 // Damaging two layers simultaneously should cause combined damage. |
| 964 // - child1 update rect in surface space: gfx::Rect(100, 100, 1, 2); | 1053 // - child1 update rect in surface space: gfx::Rect(100, 100, 1, 2); |
| 965 // - child2 update rect in surface space: gfx::Rect(400, 380, 3, 4); | 1054 // - child2 update rect in surface space: gfx::Rect(400, 380, 3, 4); |
| 966 ClearDamageForAllSurfaces(root); | 1055 ClearDamageForAllSurfaces(root); |
| 967 child1->SetUpdateRect(gfx::Rect(1, 2)); | 1056 child1->SetUpdateRect(gfx::Rect(1, 2)); |
| 968 child2->SetUpdateRect(gfx::Rect(3, 4)); | 1057 child2->SetUpdateRect(gfx::Rect(3, 4)); |
| 969 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1058 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 970 EmulateDrawingOneFrame(root); | 1059 EmulateDrawingOneFrame(root); |
| 1060 EXPECT_FALSE( | |
| 1061 root->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 971 gfx::Rect root_damage_rect = | 1062 gfx::Rect root_damage_rect = |
| 972 root->render_surface()->damage_tracker()->current_damage_rect(); | 1063 root->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 973 EXPECT_EQ(gfx::Rect(100, 100, 303, 284).ToString(), | 1064 EXPECT_EQ(gfx::Rect(100, 100, 303, 284).ToString(), |
| 974 root_damage_rect.ToString()); | 1065 root_damage_rect.ToString()); |
| 975 } | 1066 } |
| 976 | 1067 |
| 977 TEST_F(DamageTrackerTest, VerifyDamageForNestedSurfaces) { | 1068 TEST_F(DamageTrackerTest, VerifyDamageForNestedSurfaces) { |
| 978 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 1069 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
| 979 LayerImpl* child1 = root->test_properties()->children[0]; | 1070 LayerImpl* child1 = root->test_properties()->children[0]; |
| 980 LayerImpl* child2 = root->test_properties()->children[1]; | 1071 LayerImpl* child2 = root->test_properties()->children[1]; |
| 981 LayerImpl* grand_child1 = | 1072 LayerImpl* grand_child1 = |
| 982 root->test_properties()->children[0]->test_properties()->children[0]; | 1073 root->test_properties()->children[0]->test_properties()->children[0]; |
| 983 child2->test_properties()->force_render_surface = true; | 1074 child2->test_properties()->force_render_surface = true; |
| 984 grand_child1->test_properties()->force_render_surface = true; | 1075 grand_child1->test_properties()->force_render_surface = true; |
| 985 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1076 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 986 EmulateDrawingOneFrame(root); | 1077 EmulateDrawingOneFrame(root); |
| 987 gfx::Rect child_damage_rect; | 1078 gfx::Rect child_damage_rect; |
| 988 gfx::Rect root_damage_rect; | 1079 gfx::Rect root_damage_rect; |
| 989 | 1080 |
| 990 // CASE 1: Damage to a descendant surface should propagate properly to | 1081 // CASE 1: Damage to a descendant surface should propagate properly to |
| 991 // ancestor surface. | 1082 // ancestor surface. |
| 992 ClearDamageForAllSurfaces(root); | 1083 ClearDamageForAllSurfaces(root); |
| 993 root->layer_tree_impl()->property_trees()->effect_tree.OnOpacityAnimated( | 1084 root->layer_tree_impl()->property_trees()->effect_tree.OnOpacityAnimated( |
| 994 0.5f, grand_child1->effect_tree_index(), root->layer_tree_impl()); | 1085 0.5f, grand_child1->effect_tree_index(), root->layer_tree_impl()); |
| 995 EmulateDrawingOneFrame(root); | 1086 EmulateDrawingOneFrame(root); |
| 1087 EXPECT_FALSE( | |
| 1088 child1->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 1089 EXPECT_FALSE( | |
| 1090 root->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 996 child_damage_rect = | 1091 child_damage_rect = |
| 997 child1->render_surface()->damage_tracker()->current_damage_rect(); | 1092 child1->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 998 root_damage_rect = | 1093 root_damage_rect = |
| 999 root->render_surface()->damage_tracker()->current_damage_rect(); | 1094 root->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 1000 EXPECT_EQ(gfx::Rect(200, 200, 6, 8).ToString(), child_damage_rect.ToString()); | 1095 EXPECT_EQ(gfx::Rect(200, 200, 6, 8).ToString(), child_damage_rect.ToString()); |
| 1001 EXPECT_EQ(gfx::Rect(300, 300, 6, 8).ToString(), root_damage_rect.ToString()); | 1096 EXPECT_EQ(gfx::Rect(300, 300, 6, 8).ToString(), root_damage_rect.ToString()); |
| 1002 | 1097 |
| 1003 // CASE 2: Same as previous case, but with additional damage elsewhere that | 1098 // CASE 2: Same as previous case, but with additional damage elsewhere that |
| 1004 // should be properly unioned. | 1099 // should be properly unioned. |
| 1005 // - child1 surface damage in root surface space: | 1100 // - child1 surface damage in root surface space: |
| 1006 // gfx::Rect(300, 300, 6, 8); | 1101 // gfx::Rect(300, 300, 6, 8); |
| 1007 // - child2 damage in root surface space: | 1102 // - child2 damage in root surface space: |
| 1008 // gfx::Rect(11, 11, 18, 18); | 1103 // gfx::Rect(11, 11, 18, 18); |
| 1009 ClearDamageForAllSurfaces(root); | 1104 ClearDamageForAllSurfaces(root); |
| 1010 root->layer_tree_impl()->property_trees()->effect_tree.OnOpacityAnimated( | 1105 root->layer_tree_impl()->property_trees()->effect_tree.OnOpacityAnimated( |
| 1011 0.7f, grand_child1->effect_tree_index(), root->layer_tree_impl()); | 1106 0.7f, grand_child1->effect_tree_index(), root->layer_tree_impl()); |
| 1012 root->layer_tree_impl()->property_trees()->effect_tree.OnOpacityAnimated( | 1107 root->layer_tree_impl()->property_trees()->effect_tree.OnOpacityAnimated( |
| 1013 0.7f, child2->effect_tree_index(), root->layer_tree_impl()); | 1108 0.7f, child2->effect_tree_index(), root->layer_tree_impl()); |
| 1014 EmulateDrawingOneFrame(root); | 1109 EmulateDrawingOneFrame(root); |
| 1110 EXPECT_FALSE( | |
| 1111 child1->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 1112 EXPECT_FALSE( | |
| 1113 root->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 1015 child_damage_rect = | 1114 child_damage_rect = |
| 1016 child1->render_surface()->damage_tracker()->current_damage_rect(); | 1115 child1->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 1017 root_damage_rect = | 1116 root_damage_rect = |
| 1018 root->render_surface()->damage_tracker()->current_damage_rect(); | 1117 root->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 1019 EXPECT_EQ(gfx::Rect(200, 200, 6, 8).ToString(), child_damage_rect.ToString()); | 1118 EXPECT_EQ(gfx::Rect(200, 200, 6, 8).ToString(), child_damage_rect.ToString()); |
| 1020 EXPECT_EQ(gfx::Rect(11, 11, 295, 297).ToString(), | 1119 EXPECT_EQ(gfx::Rect(11, 11, 295, 297).ToString(), |
| 1021 root_damage_rect.ToString()); | 1120 root_damage_rect.ToString()); |
| 1022 } | 1121 } |
| 1023 | 1122 |
| 1024 TEST_F(DamageTrackerTest, VerifyDamageForSurfaceChangeFromDescendantLayer) { | 1123 TEST_F(DamageTrackerTest, VerifyDamageForSurfaceChangeFromDescendantLayer) { |
| 1025 // If descendant layer changes and affects the content bounds of the render | 1124 // If descendant layer changes and affects the content bounds of the render |
| 1026 // surface, then the entire descendant surface should be damaged, and it | 1125 // surface, then the entire descendant surface should be damaged, and it |
| 1027 // should damage its ancestor surface with the old and new surface regions. | 1126 // should damage its ancestor surface with the old and new surface regions. |
| 1028 | 1127 |
| 1029 // This is a tricky case, since only the first grand_child changes, but the | 1128 // This is a tricky case, since only the first grand_child changes, but the |
| 1030 // entire surface should be marked dirty. | 1129 // entire surface should be marked dirty. |
| 1031 | 1130 |
| 1032 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 1131 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
| 1033 LayerImpl* child1 = root->test_properties()->children[0]; | 1132 LayerImpl* child1 = root->test_properties()->children[0]; |
| 1034 LayerImpl* grand_child1 = | 1133 LayerImpl* grand_child1 = |
| 1035 root->test_properties()->children[0]->test_properties()->children[0]; | 1134 root->test_properties()->children[0]->test_properties()->children[0]; |
| 1036 gfx::Rect child_damage_rect; | 1135 gfx::Rect child_damage_rect; |
| 1037 gfx::Rect root_damage_rect; | 1136 gfx::Rect root_damage_rect; |
| 1038 | 1137 |
| 1039 ClearDamageForAllSurfaces(root); | 1138 ClearDamageForAllSurfaces(root); |
| 1040 grand_child1->SetPosition(gfx::PointF(195.f, 205.f)); | 1139 grand_child1->SetPosition(gfx::PointF(195.f, 205.f)); |
| 1041 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1140 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 1042 EmulateDrawingOneFrame(root); | 1141 EmulateDrawingOneFrame(root); |
| 1142 EXPECT_FALSE( | |
| 1143 child1->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 1144 EXPECT_FALSE( | |
| 1145 root->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 1043 child_damage_rect = | 1146 child_damage_rect = |
| 1044 child1->render_surface()->damage_tracker()->current_damage_rect(); | 1147 child1->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 1045 root_damage_rect = | 1148 root_damage_rect = |
| 1046 root->render_surface()->damage_tracker()->current_damage_rect(); | 1149 root->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 1047 | 1150 |
| 1048 // The new surface bounds should be damaged entirely, even though only one of | 1151 // The new surface bounds should be damaged entirely, even though only one of |
| 1049 // the layers changed. | 1152 // the layers changed. |
| 1050 EXPECT_EQ(gfx::Rect(190, 190, 11, 23).ToString(), | 1153 EXPECT_EQ(gfx::Rect(190, 190, 11, 23).ToString(), |
| 1051 child_damage_rect.ToString()); | 1154 child_damage_rect.ToString()); |
| 1052 | 1155 |
| 1053 // Damage to the root surface should be the union of child1's *entire* render | 1156 // Damage to the root surface should be the union of child1's *entire* render |
| 1054 // surface (in target space), and its old exposed area (also in target | 1157 // surface (in target space), and its old exposed area (also in target |
| 1055 // space). | 1158 // space). |
| 1056 EXPECT_EQ(gfx::Rect(290, 290, 16, 23).ToString(), | 1159 EXPECT_EQ(gfx::Rect(290, 290, 16, 23).ToString(), |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 1073 LayerImpl* child1 = root->test_properties()->children[0]; | 1176 LayerImpl* child1 = root->test_properties()->children[0]; |
| 1074 gfx::Rect child_damage_rect; | 1177 gfx::Rect child_damage_rect; |
| 1075 gfx::Rect root_damage_rect; | 1178 gfx::Rect root_damage_rect; |
| 1076 | 1179 |
| 1077 ClearDamageForAllSurfaces(root); | 1180 ClearDamageForAllSurfaces(root); |
| 1078 gfx::Transform translation; | 1181 gfx::Transform translation; |
| 1079 translation.Translate(-50.f, -50.f); | 1182 translation.Translate(-50.f, -50.f); |
| 1080 root->layer_tree_impl()->property_trees()->transform_tree.OnTransformAnimated( | 1183 root->layer_tree_impl()->property_trees()->transform_tree.OnTransformAnimated( |
| 1081 translation, child1->transform_tree_index(), root->layer_tree_impl()); | 1184 translation, child1->transform_tree_index(), root->layer_tree_impl()); |
| 1082 EmulateDrawingOneFrame(root); | 1185 EmulateDrawingOneFrame(root); |
| 1186 EXPECT_FALSE( | |
| 1187 child1->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 1188 EXPECT_FALSE( | |
| 1189 root->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 1083 child_damage_rect = | 1190 child_damage_rect = |
| 1084 child1->render_surface()->damage_tracker()->current_damage_rect(); | 1191 child1->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 1085 root_damage_rect = | 1192 root_damage_rect = |
| 1086 root->render_surface()->damage_tracker()->current_damage_rect(); | 1193 root->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 1087 | 1194 |
| 1088 // The new surface bounds should be damaged entirely. | 1195 // The new surface bounds should be damaged entirely. |
| 1089 EXPECT_EQ(gfx::Rect(190, 190, 16, 18).ToString(), | 1196 EXPECT_EQ(gfx::Rect(190, 190, 16, 18).ToString(), |
| 1090 child_damage_rect.ToString()); | 1197 child_damage_rect.ToString()); |
| 1091 | 1198 |
| 1092 // The entire child1 surface and the old exposed child1 surface should damage | 1199 // The entire child1 surface and the old exposed child1 surface should damage |
| 1093 // the root surface. | 1200 // the root surface. |
| 1094 // - old child1 surface in target space: gfx::Rect(290, 290, 16, 18) | 1201 // - old child1 surface in target space: gfx::Rect(290, 290, 16, 18) |
| 1095 // - new child1 surface in target space: gfx::Rect(240, 240, 16, 18) | 1202 // - new child1 surface in target space: gfx::Rect(240, 240, 16, 18) |
| 1096 EXPECT_EQ(gfx::Rect(240, 240, 66, 68).ToString(), | 1203 EXPECT_EQ(gfx::Rect(240, 240, 66, 68).ToString(), |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 1107 // exposed. | 1214 // exposed. |
| 1108 ClearDamageForAllSurfaces(root); | 1215 ClearDamageForAllSurfaces(root); |
| 1109 child1->test_properties()->force_render_surface = false; | 1216 child1->test_properties()->force_render_surface = false; |
| 1110 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1217 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 1111 EmulateDrawingOneFrame(root); | 1218 EmulateDrawingOneFrame(root); |
| 1112 | 1219 |
| 1113 // Sanity check that there is only one surface now. | 1220 // Sanity check that there is only one surface now. |
| 1114 ASSERT_FALSE(child1->render_surface()); | 1221 ASSERT_FALSE(child1->render_surface()); |
| 1115 ASSERT_EQ(4u, root->render_surface()->layer_list().size()); | 1222 ASSERT_EQ(4u, root->render_surface()->layer_list().size()); |
| 1116 | 1223 |
| 1224 EXPECT_FALSE( | |
| 1225 root->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 1117 root_damage_rect = | 1226 root_damage_rect = |
| 1118 root->render_surface()->damage_tracker()->current_damage_rect(); | 1227 root->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 1119 EXPECT_EQ(gfx::Rect(290, 290, 16, 18).ToString(), | 1228 EXPECT_EQ(gfx::Rect(290, 290, 16, 18).ToString(), |
| 1120 root_damage_rect.ToString()); | 1229 root_damage_rect.ToString()); |
| 1121 | 1230 |
| 1122 // CASE 2: If a descendant surface appears, its entire old area becomes | 1231 // CASE 2: If a descendant surface appears, its entire old area becomes |
| 1123 // exposed. | 1232 // exposed. |
| 1124 | 1233 |
| 1125 // Cycle one frame of no change, just to sanity check that the next rect is | 1234 // Cycle one frame of no change, just to sanity check that the next rect is |
| 1126 // not because of the old damage state. | 1235 // not because of the old damage state. |
| 1127 ClearDamageForAllSurfaces(root); | 1236 ClearDamageForAllSurfaces(root); |
| 1128 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1237 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 1129 EmulateDrawingOneFrame(root); | 1238 EmulateDrawingOneFrame(root); |
| 1239 EXPECT_FALSE( | |
| 1240 root->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 1130 root_damage_rect = | 1241 root_damage_rect = |
| 1131 root->render_surface()->damage_tracker()->current_damage_rect(); | 1242 root->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 1132 EXPECT_TRUE(root_damage_rect.IsEmpty()); | 1243 EXPECT_TRUE(root_damage_rect.IsEmpty()); |
| 1133 | 1244 |
| 1134 // Then change the tree so that the render surface is added back. | 1245 // Then change the tree so that the render surface is added back. |
| 1135 ClearDamageForAllSurfaces(root); | 1246 ClearDamageForAllSurfaces(root); |
| 1136 child1->test_properties()->force_render_surface = true; | 1247 child1->test_properties()->force_render_surface = true; |
| 1137 | 1248 |
| 1138 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1249 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 1139 EmulateDrawingOneFrame(root); | 1250 EmulateDrawingOneFrame(root); |
| 1140 | 1251 |
| 1141 // Sanity check that there is a new surface now. | 1252 // Sanity check that there is a new surface now. |
| 1142 ASSERT_TRUE(child1->render_surface()); | 1253 ASSERT_TRUE(child1->render_surface()); |
| 1143 EXPECT_EQ(3u, root->render_surface()->layer_list().size()); | 1254 EXPECT_EQ(3u, root->render_surface()->layer_list().size()); |
| 1144 EXPECT_EQ(2u, child1->render_surface()->layer_list().size()); | 1255 EXPECT_EQ(2u, child1->render_surface()->layer_list().size()); |
| 1145 | 1256 |
| 1257 EXPECT_FALSE( | |
| 1258 child1->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 1259 EXPECT_FALSE( | |
| 1260 root->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 1146 child_damage_rect = | 1261 child_damage_rect = |
| 1147 child1->render_surface()->damage_tracker()->current_damage_rect(); | 1262 child1->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 1148 root_damage_rect = | 1263 root_damage_rect = |
| 1149 root->render_surface()->damage_tracker()->current_damage_rect(); | 1264 root->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 1150 EXPECT_EQ(gfx::Rect(190, 190, 16, 18).ToString(), | 1265 EXPECT_EQ(gfx::Rect(190, 190, 16, 18).ToString(), |
| 1151 child_damage_rect.ToString()); | 1266 child_damage_rect.ToString()); |
| 1152 EXPECT_EQ(gfx::Rect(290, 290, 16, 18).ToString(), | 1267 EXPECT_EQ(gfx::Rect(290, 290, 16, 18).ToString(), |
| 1153 root_damage_rect.ToString()); | 1268 root_damage_rect.ToString()); |
| 1154 } | 1269 } |
| 1155 | 1270 |
| 1156 TEST_F(DamageTrackerTest, VerifyNoDamageWhenNothingChanged) { | 1271 TEST_F(DamageTrackerTest, VerifyNoDamageWhenNothingChanged) { |
| 1157 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 1272 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
| 1158 LayerImpl* child1 = root->test_properties()->children[0]; | 1273 LayerImpl* child1 = root->test_properties()->children[0]; |
| 1159 gfx::Rect child_damage_rect; | 1274 gfx::Rect child_damage_rect; |
| 1160 gfx::Rect root_damage_rect; | 1275 gfx::Rect root_damage_rect; |
| 1161 | 1276 |
| 1162 // CASE 1: If nothing changes, the damage rect should be empty. | 1277 // CASE 1: If nothing changes, the damage rect should be empty. |
| 1163 // | 1278 // |
| 1164 ClearDamageForAllSurfaces(root); | 1279 ClearDamageForAllSurfaces(root); |
| 1165 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1280 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 1166 EmulateDrawingOneFrame(root); | 1281 EmulateDrawingOneFrame(root); |
| 1282 EXPECT_FALSE( | |
| 1283 child1->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 1284 EXPECT_FALSE( | |
| 1285 root->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 1167 child_damage_rect = | 1286 child_damage_rect = |
| 1168 child1->render_surface()->damage_tracker()->current_damage_rect(); | 1287 child1->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 1169 root_damage_rect = | 1288 root_damage_rect = |
| 1170 root->render_surface()->damage_tracker()->current_damage_rect(); | 1289 root->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 1171 EXPECT_TRUE(child_damage_rect.IsEmpty()); | 1290 EXPECT_TRUE(child_damage_rect.IsEmpty()); |
| 1172 EXPECT_TRUE(root_damage_rect.IsEmpty()); | 1291 EXPECT_TRUE(root_damage_rect.IsEmpty()); |
| 1173 | 1292 |
| 1174 // CASE 2: If nothing changes twice in a row, the damage rect should still be | 1293 // CASE 2: If nothing changes twice in a row, the damage rect should still be |
| 1175 // empty. | 1294 // empty. |
| 1176 // | 1295 // |
| 1177 ClearDamageForAllSurfaces(root); | 1296 ClearDamageForAllSurfaces(root); |
| 1178 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1297 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 1179 EmulateDrawingOneFrame(root); | 1298 EmulateDrawingOneFrame(root); |
| 1299 EXPECT_FALSE( | |
| 1300 child1->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 1301 EXPECT_FALSE( | |
| 1302 root->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 1180 child_damage_rect = | 1303 child_damage_rect = |
| 1181 child1->render_surface()->damage_tracker()->current_damage_rect(); | 1304 child1->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 1182 root_damage_rect = | 1305 root_damage_rect = |
| 1183 root->render_surface()->damage_tracker()->current_damage_rect(); | 1306 root->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 1184 EXPECT_TRUE(child_damage_rect.IsEmpty()); | 1307 EXPECT_TRUE(child_damage_rect.IsEmpty()); |
| 1185 EXPECT_TRUE(root_damage_rect.IsEmpty()); | 1308 EXPECT_TRUE(root_damage_rect.IsEmpty()); |
| 1186 } | 1309 } |
| 1187 | 1310 |
| 1188 TEST_F(DamageTrackerTest, VerifyNoDamageForUpdateRectThatDoesNotDrawContent) { | 1311 TEST_F(DamageTrackerTest, VerifyNoDamageForUpdateRectThatDoesNotDrawContent) { |
| 1189 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 1312 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
| 1190 LayerImpl* child1 = root->test_properties()->children[0]; | 1313 LayerImpl* child1 = root->test_properties()->children[0]; |
| 1191 gfx::Rect child_damage_rect; | 1314 gfx::Rect child_damage_rect; |
| 1192 gfx::Rect root_damage_rect; | 1315 gfx::Rect root_damage_rect; |
| 1193 | 1316 |
| 1194 // In our specific tree, the update rect of child1 should not cause any | 1317 // In our specific tree, the update rect of child1 should not cause any |
| 1195 // damage to any surface because it does not actually draw content. | 1318 // damage to any surface because it does not actually draw content. |
| 1196 ClearDamageForAllSurfaces(root); | 1319 ClearDamageForAllSurfaces(root); |
| 1197 child1->SetUpdateRect(gfx::Rect(1, 2)); | 1320 child1->SetUpdateRect(gfx::Rect(1, 2)); |
| 1198 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1321 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 1199 EmulateDrawingOneFrame(root); | 1322 EmulateDrawingOneFrame(root); |
| 1323 EXPECT_FALSE( | |
| 1324 child1->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 1325 EXPECT_FALSE( | |
| 1326 root->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 1200 child_damage_rect = | 1327 child_damage_rect = |
| 1201 child1->render_surface()->damage_tracker()->current_damage_rect(); | 1328 child1->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 1202 root_damage_rect = | 1329 root_damage_rect = |
| 1203 root->render_surface()->damage_tracker()->current_damage_rect(); | 1330 root->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 1204 EXPECT_TRUE(child_damage_rect.IsEmpty()); | 1331 EXPECT_TRUE(child_damage_rect.IsEmpty()); |
| 1205 EXPECT_TRUE(root_damage_rect.IsEmpty()); | 1332 EXPECT_TRUE(root_damage_rect.IsEmpty()); |
| 1206 } | 1333 } |
| 1207 | 1334 |
| 1208 TEST_F(DamageTrackerTest, VerifyDamageForMask) { | 1335 TEST_F(DamageTrackerTest, VerifyDamageForMask) { |
| 1209 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 1336 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
| 1210 LayerImpl* child = root->test_properties()->children[0]; | 1337 LayerImpl* child = root->test_properties()->children[0]; |
| 1211 | 1338 |
| 1212 // In the current implementation of the damage tracker, changes to mask | 1339 // In the current implementation of the damage tracker, changes to mask |
| 1213 // layers should damage the entire corresponding surface. | 1340 // layers should damage the entire corresponding surface. |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 1237 } | 1364 } |
| 1238 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1365 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 1239 EmulateDrawingOneFrame(root); | 1366 EmulateDrawingOneFrame(root); |
| 1240 | 1367 |
| 1241 // CASE 1: the update_rect on a mask layer should damage the entire target | 1368 // CASE 1: the update_rect on a mask layer should damage the entire target |
| 1242 // surface. | 1369 // surface. |
| 1243 ClearDamageForAllSurfaces(root); | 1370 ClearDamageForAllSurfaces(root); |
| 1244 mask_layer->SetUpdateRect(gfx::Rect(1, 2, 3, 4)); | 1371 mask_layer->SetUpdateRect(gfx::Rect(1, 2, 3, 4)); |
| 1245 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1372 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 1246 EmulateDrawingOneFrame(root); | 1373 EmulateDrawingOneFrame(root); |
| 1374 EXPECT_FALSE( | |
| 1375 child->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 1247 gfx::Rect child_damage_rect = | 1376 gfx::Rect child_damage_rect = |
| 1248 child->render_surface()->damage_tracker()->current_damage_rect(); | 1377 child->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 1249 EXPECT_EQ(gfx::Rect(30, 30).ToString(), child_damage_rect.ToString()); | 1378 EXPECT_EQ(gfx::Rect(30, 30).ToString(), child_damage_rect.ToString()); |
| 1250 | 1379 |
| 1251 // CASE 2: a property change on the mask layer should damage the entire | 1380 // CASE 2: a property change on the mask layer should damage the entire |
| 1252 // target surface. | 1381 // target surface. |
| 1253 | 1382 |
| 1254 // Advance one frame without damage so that we know the damage rect is not | 1383 // Advance one frame without damage so that we know the damage rect is not |
| 1255 // leftover from the previous case. | 1384 // leftover from the previous case. |
| 1256 ClearDamageForAllSurfaces(root); | 1385 ClearDamageForAllSurfaces(root); |
| 1257 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1386 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 1258 EmulateDrawingOneFrame(root); | 1387 EmulateDrawingOneFrame(root); |
| 1388 EXPECT_FALSE( | |
| 1389 child->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 1259 child_damage_rect = | 1390 child_damage_rect = |
| 1260 child->render_surface()->damage_tracker()->current_damage_rect(); | 1391 child->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 1261 EXPECT_TRUE(child_damage_rect.IsEmpty()); | 1392 EXPECT_TRUE(child_damage_rect.IsEmpty()); |
| 1262 | 1393 |
| 1263 // Then test the property change. | 1394 // Then test the property change. |
| 1264 ClearDamageForAllSurfaces(root); | 1395 ClearDamageForAllSurfaces(root); |
| 1265 mask_layer->NoteLayerPropertyChanged(); | 1396 mask_layer->NoteLayerPropertyChanged(); |
| 1266 | 1397 |
| 1267 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1398 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 1268 EmulateDrawingOneFrame(root); | 1399 EmulateDrawingOneFrame(root); |
| 1400 EXPECT_FALSE( | |
| 1401 child->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 1269 child_damage_rect = | 1402 child_damage_rect = |
| 1270 child->render_surface()->damage_tracker()->current_damage_rect(); | 1403 child->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 1271 EXPECT_EQ(gfx::Rect(30, 30).ToString(), child_damage_rect.ToString()); | 1404 EXPECT_EQ(gfx::Rect(30, 30).ToString(), child_damage_rect.ToString()); |
| 1272 | 1405 |
| 1273 // CASE 3: removing the mask also damages the entire target surface. | 1406 // CASE 3: removing the mask also damages the entire target surface. |
| 1274 // | 1407 // |
| 1275 | 1408 |
| 1276 // Advance one frame without damage so that we know the damage rect is not | 1409 // Advance one frame without damage so that we know the damage rect is not |
| 1277 // leftover from the previous case. | 1410 // leftover from the previous case. |
| 1278 ClearDamageForAllSurfaces(root); | 1411 ClearDamageForAllSurfaces(root); |
| 1279 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1412 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 1280 EmulateDrawingOneFrame(root); | 1413 EmulateDrawingOneFrame(root); |
| 1414 EXPECT_FALSE( | |
| 1415 child->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 1281 child_damage_rect = | 1416 child_damage_rect = |
| 1282 child->render_surface()->damage_tracker()->current_damage_rect(); | 1417 child->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 1283 EXPECT_TRUE(child_damage_rect.IsEmpty()); | 1418 EXPECT_TRUE(child_damage_rect.IsEmpty()); |
| 1284 | 1419 |
| 1285 // Then test mask removal. | 1420 // Then test mask removal. |
| 1286 ClearDamageForAllSurfaces(root); | 1421 ClearDamageForAllSurfaces(root); |
| 1287 child->test_properties()->SetMaskLayer(nullptr); | 1422 child->test_properties()->SetMaskLayer(nullptr); |
| 1288 child->NoteLayerPropertyChanged(); | 1423 child->NoteLayerPropertyChanged(); |
| 1289 ASSERT_TRUE(child->LayerPropertyChanged()); | 1424 ASSERT_TRUE(child->LayerPropertyChanged()); |
| 1290 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1425 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 1291 EmulateDrawingOneFrame(root); | 1426 EmulateDrawingOneFrame(root); |
| 1292 | 1427 |
| 1293 // Sanity check that a render surface still exists. | 1428 // Sanity check that a render surface still exists. |
| 1294 ASSERT_TRUE(child->render_surface()); | 1429 ASSERT_TRUE(child->render_surface()); |
| 1295 | 1430 |
| 1431 EXPECT_FALSE( | |
| 1432 child->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 1296 child_damage_rect = | 1433 child_damage_rect = |
| 1297 child->render_surface()->damage_tracker()->current_damage_rect(); | 1434 child->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 1298 EXPECT_EQ(gfx::Rect(30, 30).ToString(), child_damage_rect.ToString()); | 1435 EXPECT_EQ(gfx::Rect(30, 30).ToString(), child_damage_rect.ToString()); |
| 1299 } | 1436 } |
| 1300 | 1437 |
| 1301 TEST_F(DamageTrackerTest, DamageWhenAddedExternally) { | 1438 TEST_F(DamageTrackerTest, DamageWhenAddedExternally) { |
| 1302 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 1439 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
| 1303 LayerImpl* child = root->test_properties()->children[0]; | 1440 LayerImpl* child = root->test_properties()->children[0]; |
| 1304 | 1441 |
| 1305 // Case 1: This test ensures that when the tracker is given damage, that | 1442 // Case 1: This test ensures that when the tracker is given damage, that |
| 1306 // it is included with any other partial damage. | 1443 // it is included with any other partial damage. |
| 1307 // | 1444 // |
| 1308 ClearDamageForAllSurfaces(root); | 1445 ClearDamageForAllSurfaces(root); |
| 1309 child->SetUpdateRect(gfx::Rect(10, 11, 12, 13)); | 1446 child->SetUpdateRect(gfx::Rect(10, 11, 12, 13)); |
| 1310 root->render_surface()->damage_tracker()->AddDamageNextUpdate( | 1447 root->render_surface()->damage_tracker()->AddDamageNextUpdate( |
| 1311 gfx::Rect(15, 16, 32, 33)); | 1448 gfx::Rect(15, 16, 32, 33)); |
| 1312 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1449 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 1313 EmulateDrawingOneFrame(root); | 1450 EmulateDrawingOneFrame(root); |
| 1451 EXPECT_FALSE( | |
| 1452 root->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 1314 gfx::Rect root_damage_rect = | 1453 gfx::Rect root_damage_rect = |
| 1315 root->render_surface()->damage_tracker()->current_damage_rect(); | 1454 root->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 1316 EXPECT_EQ(gfx::UnionRects(gfx::Rect(15, 16, 32, 33), | 1455 EXPECT_EQ(gfx::UnionRects(gfx::Rect(15, 16, 32, 33), |
| 1317 gfx::Rect(100 + 10, 100 + 11, 12, 13)).ToString(), | 1456 gfx::Rect(100 + 10, 100 + 11, 12, 13)).ToString(), |
| 1318 root_damage_rect.ToString()); | 1457 root_damage_rect.ToString()); |
| 1319 | 1458 |
| 1320 // Case 2: An additional sanity check that adding damage works even when | 1459 // Case 2: An additional sanity check that adding damage works even when |
| 1321 // nothing on the layer tree changed. | 1460 // nothing on the layer tree changed. |
| 1322 // | 1461 // |
| 1323 ClearDamageForAllSurfaces(root); | 1462 ClearDamageForAllSurfaces(root); |
| 1324 root->render_surface()->damage_tracker()->AddDamageNextUpdate( | 1463 root->render_surface()->damage_tracker()->AddDamageNextUpdate( |
| 1325 gfx::Rect(30, 31, 14, 15)); | 1464 gfx::Rect(30, 31, 14, 15)); |
| 1326 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1465 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 1327 EmulateDrawingOneFrame(root); | 1466 EmulateDrawingOneFrame(root); |
| 1467 EXPECT_FALSE( | |
| 1468 root->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 1328 root_damage_rect = | 1469 root_damage_rect = |
| 1329 root->render_surface()->damage_tracker()->current_damage_rect(); | 1470 root->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 1330 EXPECT_EQ(gfx::Rect(30, 31, 14, 15).ToString(), root_damage_rect.ToString()); | 1471 EXPECT_EQ(gfx::Rect(30, 31, 14, 15).ToString(), root_damage_rect.ToString()); |
| 1331 } | 1472 } |
| 1332 | 1473 |
| 1333 TEST_F(DamageTrackerTest, VerifyDamageForEmptyLayerList) { | 1474 TEST_F(DamageTrackerTest, VerifyDamageForEmptyLayerList) { |
| 1334 // Though it should never happen, its a good idea to verify that the damage | 1475 // Though it should never happen, its a good idea to verify that the damage |
| 1335 // tracker does not crash when it receives an empty layer_list. | 1476 // tracker does not crash when it receives an empty layer_list. |
| 1336 | 1477 |
| 1337 std::unique_ptr<LayerImpl> root = | 1478 std::unique_ptr<LayerImpl> root = |
| 1338 LayerImpl::Create(host_impl_.active_tree(), 1); | 1479 LayerImpl::Create(host_impl_.active_tree(), 1); |
| 1339 root->test_properties()->force_render_surface = true; | 1480 root->test_properties()->force_render_surface = true; |
| 1340 host_impl_.active_tree()->SetRootLayerForTesting(std::move(root)); | 1481 host_impl_.active_tree()->SetRootLayerForTesting(std::move(root)); |
| 1341 LayerImpl* root_ptr = host_impl_.active_tree()->root_layer_for_testing(); | 1482 LayerImpl* root_ptr = host_impl_.active_tree()->root_layer_for_testing(); |
| 1342 root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1483 root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 1343 EmulateDrawingOneFrame(root_ptr); | 1484 EmulateDrawingOneFrame(root_ptr); |
| 1344 | 1485 |
| 1345 DCHECK_EQ(root_ptr->render_surface(), root_ptr->render_target()); | 1486 DCHECK_EQ(root_ptr->render_surface(), root_ptr->render_target()); |
| 1346 RenderSurfaceImpl* target_surface = root_ptr->render_surface(); | 1487 RenderSurfaceImpl* target_surface = root_ptr->render_surface(); |
| 1347 | 1488 |
| 1348 LayerImplList empty_list; | 1489 LayerImplList empty_list; |
| 1349 target_surface->damage_tracker()->UpdateDamageTrackingState( | 1490 target_surface->damage_tracker()->UpdateDamageTrackingState( |
| 1350 empty_list, target_surface, false, gfx::Rect(), NULL, FilterOperations()); | 1491 empty_list, target_surface, false, gfx::Rect(), NULL, FilterOperations()); |
| 1351 | 1492 |
| 1352 gfx::Rect damage_rect = | 1493 EXPECT_FALSE(target_surface->damage_tracker()->ShouldDamageEverything()); |
| 1353 target_surface->damage_tracker()->current_damage_rect(); | 1494 gfx::Rect damage_rect = target_surface->damage_tracker()->CurrentDamageRect(); |
| 1354 EXPECT_TRUE(damage_rect.IsEmpty()); | 1495 EXPECT_TRUE(damage_rect.IsEmpty()); |
| 1355 } | 1496 } |
| 1356 | 1497 |
| 1357 TEST_F(DamageTrackerTest, VerifyDamageAccumulatesUntilReset) { | 1498 TEST_F(DamageTrackerTest, VerifyDamageAccumulatesUntilReset) { |
| 1358 // If damage is not cleared, it should accumulate. | 1499 // If damage is not cleared, it should accumulate. |
| 1359 | 1500 |
| 1360 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 1501 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
| 1361 LayerImpl* child = root->test_properties()->children[0]; | 1502 LayerImpl* child = root->test_properties()->children[0]; |
| 1362 | 1503 |
| 1363 ClearDamageForAllSurfaces(root); | 1504 ClearDamageForAllSurfaces(root); |
| 1364 child->SetUpdateRect(gfx::Rect(10.f, 11.f, 1.f, 2.f)); | 1505 child->SetUpdateRect(gfx::Rect(10.f, 11.f, 1.f, 2.f)); |
| 1365 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1506 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 1366 EmulateDrawingOneFrame(root); | 1507 EmulateDrawingOneFrame(root); |
| 1367 | 1508 |
| 1368 // Sanity check damage after the first frame; this isnt the actual test yet. | 1509 // Sanity check damage after the first frame; this isnt the actual test yet. |
| 1510 EXPECT_FALSE( | |
| 1511 root->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 1369 gfx::Rect root_damage_rect = | 1512 gfx::Rect root_damage_rect = |
| 1370 root->render_surface()->damage_tracker()->current_damage_rect(); | 1513 root->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 1371 EXPECT_EQ(gfx::Rect(110, 111, 1, 2).ToString(), root_damage_rect.ToString()); | 1514 EXPECT_EQ(gfx::Rect(110, 111, 1, 2).ToString(), root_damage_rect.ToString()); |
| 1372 | 1515 |
| 1373 // New damage, without having cleared the previous damage, should be unioned | 1516 // New damage, without having cleared the previous damage, should be unioned |
| 1374 // to the previous one. | 1517 // to the previous one. |
| 1375 child->SetUpdateRect(gfx::Rect(20, 25, 1, 2)); | 1518 child->SetUpdateRect(gfx::Rect(20, 25, 1, 2)); |
| 1376 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1519 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 1377 EmulateDrawingOneFrame(root); | 1520 EmulateDrawingOneFrame(root); |
| 1521 EXPECT_FALSE( | |
| 1522 root->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 1378 root_damage_rect = | 1523 root_damage_rect = |
| 1379 root->render_surface()->damage_tracker()->current_damage_rect(); | 1524 root->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 1380 EXPECT_EQ(gfx::Rect(110, 111, 11, 16).ToString(), | 1525 EXPECT_EQ(gfx::Rect(110, 111, 11, 16).ToString(), |
| 1381 root_damage_rect.ToString()); | 1526 root_damage_rect.ToString()); |
| 1382 | 1527 |
| 1383 // If we notify the damage tracker that we drew the damaged area, then damage | 1528 // If we notify the damage tracker that we drew the damaged area, then damage |
| 1384 // should be emptied. | 1529 // should be emptied. |
| 1385 root->render_surface()->damage_tracker()->DidDrawDamagedArea(); | 1530 root->render_surface()->damage_tracker()->DidDrawDamagedArea(); |
| 1531 EXPECT_FALSE( | |
| 1532 root->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 1386 root_damage_rect = | 1533 root_damage_rect = |
| 1387 root->render_surface()->damage_tracker()->current_damage_rect(); | 1534 root->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 1388 EXPECT_TRUE(root_damage_rect.IsEmpty()); | 1535 EXPECT_TRUE(root_damage_rect.IsEmpty()); |
| 1389 | 1536 |
| 1390 // Damage should remain empty even after one frame, since there's yet no new | 1537 // Damage should remain empty even after one frame, since there's yet no new |
| 1391 // damage. | 1538 // damage. |
| 1392 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1539 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 1393 EmulateDrawingOneFrame(root); | 1540 EmulateDrawingOneFrame(root); |
| 1541 EXPECT_FALSE( | |
| 1542 root->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 1394 root_damage_rect = | 1543 root_damage_rect = |
| 1395 root->render_surface()->damage_tracker()->current_damage_rect(); | 1544 root->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 1396 EXPECT_TRUE(root_damage_rect.IsEmpty()); | 1545 EXPECT_TRUE(root_damage_rect.IsEmpty()); |
| 1397 } | 1546 } |
| 1398 | 1547 |
| 1399 TEST_F(DamageTrackerTest, HugeDamageRect) { | 1548 TEST_F(DamageTrackerTest, HugeDamageRect) { |
| 1400 // This number is so large that we start losting floating point accuracy. | 1549 // This number is so large that we start losting floating point accuracy. |
| 1401 const int kBigNumber = 900000000; | 1550 const int kBigNumber = 900000000; |
| 1402 // Walk over a range to find floating point inaccuracy boundaries that move | 1551 // Walk over a range to find floating point inaccuracy boundaries that move |
| 1403 // toward the wrong direction. | 1552 // toward the wrong direction. |
| 1404 const int kRange = 5000; | 1553 const int kRange = 5000; |
| 1405 | 1554 |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 1419 float device_scale_factor = 1.f; | 1568 float device_scale_factor = 1.f; |
| 1420 // Visible rects computed from combining clips in target space and root | 1569 // Visible rects computed from combining clips in target space and root |
| 1421 // space don't match because of the loss in floating point accuracy. So, we | 1570 // space don't match because of the loss in floating point accuracy. So, we |
| 1422 // skip verify_clip_tree_calculations. | 1571 // skip verify_clip_tree_calculations. |
| 1423 bool skip_verify_visible_rect_calculations = true; | 1572 bool skip_verify_visible_rect_calculations = true; |
| 1424 EmulateDrawingOneFrame(root, device_scale_factor, | 1573 EmulateDrawingOneFrame(root, device_scale_factor, |
| 1425 skip_verify_visible_rect_calculations); | 1574 skip_verify_visible_rect_calculations); |
| 1426 | 1575 |
| 1427 // The expected damage should cover the visible part of the child layer, | 1576 // The expected damage should cover the visible part of the child layer, |
| 1428 // which is (0, 0, i, i) in the viewport. | 1577 // which is (0, 0, i, i) in the viewport. |
| 1578 EXPECT_FALSE( | |
| 1579 root->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 1429 gfx::Rect root_damage_rect = | 1580 gfx::Rect root_damage_rect = |
| 1430 root->render_surface()->damage_tracker()->current_damage_rect(); | 1581 root->render_surface()->damage_tracker()->CurrentDamageRect(); |
| 1431 gfx::Rect damage_we_care_about = gfx::Rect(i, i); | 1582 gfx::Rect damage_we_care_about = gfx::Rect(i, i); |
| 1432 EXPECT_LE(damage_we_care_about.right(), root_damage_rect.right()); | 1583 EXPECT_LE(damage_we_care_about.right(), root_damage_rect.right()); |
| 1433 EXPECT_LE(damage_we_care_about.bottom(), root_damage_rect.bottom()); | 1584 EXPECT_LE(damage_we_care_about.bottom(), root_damage_rect.bottom()); |
| 1434 } | 1585 } |
| 1435 } | 1586 } |
| 1436 | 1587 |
| 1588 TEST_F(DamageTrackerTest, DamageRectTooBig) { | |
|
enne (OOO)
2017/01/13 22:21:38
wtb DamageRectTooBigInRenderSurface
vmpstr
2017/01/19 23:08:27
Done.
| |
| 1589 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(2); | |
| 1590 LayerImpl* child1 = root->test_properties()->children[0]; | |
| 1591 LayerImpl* child2 = root->test_properties()->children[1]; | |
| 1592 | |
| 1593 // Really far left. | |
| 1594 child1->SetPosition(gfx::PointF(std::numeric_limits<int>::min(), 0)); | |
| 1595 child1->SetBounds(gfx::Size(1, 1)); | |
| 1596 | |
| 1597 // Really far right. | |
| 1598 child2->SetPosition(gfx::PointF(std::numeric_limits<int>::max(), 0)); | |
| 1599 child2->SetBounds(gfx::Size(1, 1)); | |
| 1600 | |
| 1601 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | |
| 1602 float device_scale_factor = 1.f; | |
| 1603 bool skip_verify_visible_rect_calculations = true; | |
| 1604 EmulateDrawingOneFrame(root, device_scale_factor, | |
| 1605 skip_verify_visible_rect_calculations); | |
| 1606 | |
| 1607 // The expected damage would be too large to store in a gfx::Rect, so we | |
| 1608 // should damage everything. | |
| 1609 EXPECT_TRUE( | |
| 1610 root->render_surface()->damage_tracker()->ShouldDamageEverything()); | |
| 1611 } | |
| 1612 | |
| 1437 } // namespace | 1613 } // namespace |
| 1438 } // namespace cc | 1614 } // namespace cc |
| OLD | NEW |