| 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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 | 198 |
| 199 EXPECT_EQ(gfx::Rect(500, 500).ToString(), root_damage_rect.ToString()); | 199 EXPECT_EQ(gfx::Rect(500, 500).ToString(), root_damage_rect.ToString()); |
| 200 } | 200 } |
| 201 | 201 |
| 202 TEST_F(DamageTrackerTest, SanityCheckTestTreeWithTwoSurfaces) { | 202 TEST_F(DamageTrackerTest, SanityCheckTestTreeWithTwoSurfaces) { |
| 203 // Sanity check that the complex test tree will actually produce the expected | 203 // Sanity check that the complex test tree will actually produce the expected |
| 204 // render surfaces and layer lists. | 204 // render surfaces and layer lists. |
| 205 | 205 |
| 206 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 206 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
| 207 | 207 |
| 208 LayerImpl* child1 = root->children()[0]; | 208 LayerImpl* child1 = root->test_properties()->children[0]; |
| 209 LayerImpl* child2 = root->children()[1]; | 209 LayerImpl* child2 = root->test_properties()->children[1]; |
| 210 gfx::Rect child_damage_rect = | 210 gfx::Rect child_damage_rect = |
| 211 child1->render_surface()->damage_tracker()->current_damage_rect(); | 211 child1->render_surface()->damage_tracker()->current_damage_rect(); |
| 212 gfx::Rect root_damage_rect = | 212 gfx::Rect root_damage_rect = |
| 213 root->render_surface()->damage_tracker()->current_damage_rect(); | 213 root->render_surface()->damage_tracker()->current_damage_rect(); |
| 214 | 214 |
| 215 ASSERT_TRUE(child1->render_surface()); | 215 ASSERT_TRUE(child1->render_surface()); |
| 216 EXPECT_FALSE(child2->render_surface()); | 216 EXPECT_FALSE(child2->render_surface()); |
| 217 EXPECT_EQ(3u, root->render_surface()->layer_list().size()); | 217 EXPECT_EQ(3u, root->render_surface()->layer_list().size()); |
| 218 EXPECT_EQ(2u, child1->render_surface()->layer_list().size()); | 218 EXPECT_EQ(2u, child1->render_surface()->layer_list().size()); |
| 219 | 219 |
| 220 // The render surface for child1 only has a content_rect that encloses | 220 // The render surface for child1 only has a content_rect that encloses |
| 221 // grand_child1 and grand_child2, because child1 does not draw content. | 221 // grand_child1 and grand_child2, because child1 does not draw content. |
| 222 EXPECT_EQ(gfx::Rect(190, 190, 16, 18).ToString(), | 222 EXPECT_EQ(gfx::Rect(190, 190, 16, 18).ToString(), |
| 223 child_damage_rect.ToString()); | 223 child_damage_rect.ToString()); |
| 224 EXPECT_EQ(gfx::Rect(500, 500).ToString(), root_damage_rect.ToString()); | 224 EXPECT_EQ(gfx::Rect(500, 500).ToString(), root_damage_rect.ToString()); |
| 225 } | 225 } |
| 226 | 226 |
| 227 TEST_F(DamageTrackerTest, VerifyDamageForUpdateRects) { | 227 TEST_F(DamageTrackerTest, VerifyDamageForUpdateRects) { |
| 228 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 228 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
| 229 LayerImpl* child = root->children()[0]; | 229 LayerImpl* child = root->test_properties()->children[0]; |
| 230 | 230 |
| 231 // CASE 1: Setting the update rect should cause the corresponding damage to | 231 // CASE 1: Setting the update rect should cause the corresponding damage to |
| 232 // the surface. | 232 // the surface. |
| 233 ClearDamageForAllSurfaces(root); | 233 ClearDamageForAllSurfaces(root); |
| 234 child->SetUpdateRect(gfx::Rect(10, 11, 12, 13)); | 234 child->SetUpdateRect(gfx::Rect(10, 11, 12, 13)); |
| 235 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 235 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 236 EmulateDrawingOneFrame(root); | 236 EmulateDrawingOneFrame(root); |
| 237 | 237 |
| 238 // Damage position on the surface should be: position of update_rect (10, 11) | 238 // Damage position on the surface should be: position of update_rect (10, 11) |
| 239 // relative to the child (100, 100). | 239 // relative to the child (100, 100). |
| (...skipping 22 matching lines...) Expand all Loading... |
| 262 | 262 |
| 263 // Damage position on the surface should be: position of update_rect (20, 25) | 263 // Damage position on the surface should be: position of update_rect (20, 25) |
| 264 // relative to the child (100, 100). | 264 // relative to the child (100, 100). |
| 265 root_damage_rect = | 265 root_damage_rect = |
| 266 root->render_surface()->damage_tracker()->current_damage_rect(); | 266 root->render_surface()->damage_tracker()->current_damage_rect(); |
| 267 EXPECT_EQ(gfx::Rect(120, 125, 1, 2).ToString(), root_damage_rect.ToString()); | 267 EXPECT_EQ(gfx::Rect(120, 125, 1, 2).ToString(), root_damage_rect.ToString()); |
| 268 } | 268 } |
| 269 | 269 |
| 270 TEST_F(DamageTrackerTest, VerifyDamageForLayerDamageRects) { | 270 TEST_F(DamageTrackerTest, VerifyDamageForLayerDamageRects) { |
| 271 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 271 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
| 272 LayerImpl* child = root->children()[0]; | 272 LayerImpl* child = root->test_properties()->children[0]; |
| 273 | 273 |
| 274 // CASE 1: Adding the layer damage rect should cause the corresponding damage | 274 // CASE 1: Adding the layer damage rect should cause the corresponding damage |
| 275 // to the surface. | 275 // to the surface. |
| 276 ClearDamageForAllSurfaces(root); | 276 ClearDamageForAllSurfaces(root); |
| 277 child->AddDamageRect(gfx::Rect(10, 11, 12, 13)); | 277 child->AddDamageRect(gfx::Rect(10, 11, 12, 13)); |
| 278 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 278 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 279 EmulateDrawingOneFrame(root); | 279 EmulateDrawingOneFrame(root); |
| 280 | 280 |
| 281 // Damage position on the surface should be: position of layer damage_rect | 281 // Damage position on the surface should be: position of layer damage_rect |
| 282 // (10, 11) relative to the child (100, 100). | 282 // (10, 11) relative to the child (100, 100). |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 // Damage position on the surface should be: position of layer damage_rect | 318 // Damage position on the surface should be: position of layer damage_rect |
| 319 // (20, 25) relative to the child (100, 100). | 319 // (20, 25) relative to the child (100, 100). |
| 320 root_damage_rect = | 320 root_damage_rect = |
| 321 root->render_surface()->damage_tracker()->current_damage_rect(); | 321 root->render_surface()->damage_tracker()->current_damage_rect(); |
| 322 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(120, 125, 1, 2))); | 322 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(120, 125, 1, 2))); |
| 323 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(110, 115, 3, 4))); | 323 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(110, 115, 3, 4))); |
| 324 } | 324 } |
| 325 | 325 |
| 326 TEST_F(DamageTrackerTest, VerifyDamageForLayerUpdateAndDamageRects) { | 326 TEST_F(DamageTrackerTest, VerifyDamageForLayerUpdateAndDamageRects) { |
| 327 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 327 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
| 328 LayerImpl* child = root->children()[0]; | 328 LayerImpl* child = root->test_properties()->children[0]; |
| 329 | 329 |
| 330 // CASE 1: Adding the layer damage rect and update rect should cause the | 330 // CASE 1: Adding the layer damage rect and update rect should cause the |
| 331 // corresponding damage to the surface. | 331 // corresponding damage to the surface. |
| 332 ClearDamageForAllSurfaces(root); | 332 ClearDamageForAllSurfaces(root); |
| 333 child->AddDamageRect(gfx::Rect(5, 6, 12, 13)); | 333 child->AddDamageRect(gfx::Rect(5, 6, 12, 13)); |
| 334 child->SetUpdateRect(gfx::Rect(15, 16, 14, 10)); | 334 child->SetUpdateRect(gfx::Rect(15, 16, 14, 10)); |
| 335 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 335 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 336 EmulateDrawingOneFrame(root); | 336 EmulateDrawingOneFrame(root); |
| 337 | 337 |
| 338 // Damage position on the surface should be: position of unified layer | 338 // Damage position on the surface should be: position of unified layer |
| (...skipping 24 matching lines...) Expand all Loading... |
| 363 | 363 |
| 364 // Damage position on the surface should be: position of unified layer damage | 364 // Damage position on the surface should be: position of unified layer damage |
| 365 // rect and update rect (5, 10) relative to the child (100, 100). | 365 // rect and update rect (5, 10) relative to the child (100, 100). |
| 366 root_damage_rect = | 366 root_damage_rect = |
| 367 root->render_surface()->damage_tracker()->current_damage_rect(); | 367 root->render_surface()->damage_tracker()->current_damage_rect(); |
| 368 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(105, 110, 17, 18))); | 368 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(105, 110, 17, 18))); |
| 369 } | 369 } |
| 370 | 370 |
| 371 TEST_F(DamageTrackerTest, VerifyDamageForPropertyChanges) { | 371 TEST_F(DamageTrackerTest, VerifyDamageForPropertyChanges) { |
| 372 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 372 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
| 373 LayerImpl* child = root->children()[0]; | 373 LayerImpl* child = root->test_properties()->children[0]; |
| 374 | 374 |
| 375 // CASE 1: The layer's property changed flag takes priority over update rect. | 375 // CASE 1: The layer's property changed flag takes priority over update rect. |
| 376 // | 376 // |
| 377 child->test_properties()->force_render_surface = true; | 377 child->test_properties()->force_render_surface = true; |
| 378 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 378 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 379 EmulateDrawingOneFrame(root); | 379 EmulateDrawingOneFrame(root); |
| 380 ClearDamageForAllSurfaces(root); | 380 ClearDamageForAllSurfaces(root); |
| 381 child->SetUpdateRect(gfx::Rect(10, 11, 12, 13)); | 381 child->SetUpdateRect(gfx::Rect(10, 11, 12, 13)); |
| 382 child->OnOpacityAnimated(0.5f); | 382 child->OnOpacityAnimated(0.5f); |
| 383 EmulateDrawingOneFrame(root); | 383 EmulateDrawingOneFrame(root); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 412 | 412 |
| 413 // Expect damage to be the combination of the previous one and the new one. | 413 // Expect damage to be the combination of the previous one and the new one. |
| 414 expected_rect.Union(gfx::Rect(200, 230, 30, 30)); | 414 expected_rect.Union(gfx::Rect(200, 230, 30, 30)); |
| 415 root_damage_rect = | 415 root_damage_rect = |
| 416 root->render_surface()->damage_tracker()->current_damage_rect(); | 416 root->render_surface()->damage_tracker()->current_damage_rect(); |
| 417 EXPECT_FLOAT_RECT_EQ(expected_rect, root_damage_rect); | 417 EXPECT_FLOAT_RECT_EQ(expected_rect, root_damage_rect); |
| 418 } | 418 } |
| 419 | 419 |
| 420 TEST_F(DamageTrackerTest, VerifyDamageWhenSurfaceRemoved) { | 420 TEST_F(DamageTrackerTest, VerifyDamageWhenSurfaceRemoved) { |
| 421 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 421 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
| 422 LayerImpl* surface = root->children()[0]; | 422 LayerImpl* surface = root->test_properties()->children[0]; |
| 423 LayerImpl* child = surface->children()[0]; | 423 LayerImpl* child = surface->test_properties()->children[0]; |
| 424 child->SetDrawsContent(true); | 424 child->SetDrawsContent(true); |
| 425 EmulateDrawingOneFrame(root); | 425 EmulateDrawingOneFrame(root); |
| 426 ClearDamageForAllSurfaces(root); | 426 ClearDamageForAllSurfaces(root); |
| 427 | 427 |
| 428 surface->test_properties()->force_render_surface = false; | 428 surface->test_properties()->force_render_surface = false; |
| 429 child->SetDrawsContent(false); | 429 child->SetDrawsContent(false); |
| 430 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 430 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 431 EmulateDrawingOneFrame(root); | 431 EmulateDrawingOneFrame(root); |
| 432 gfx::Rect root_damage_rect = | 432 gfx::Rect root_damage_rect = |
| 433 root->render_surface()->damage_tracker()->current_damage_rect(); | 433 root->render_surface()->damage_tracker()->current_damage_rect(); |
| 434 EXPECT_EQ(gfx::Rect(290, 290, 16, 18).ToString(), | 434 EXPECT_EQ(gfx::Rect(290, 290, 16, 18).ToString(), |
| 435 root_damage_rect.ToString()); | 435 root_damage_rect.ToString()); |
| 436 } | 436 } |
| 437 | 437 |
| 438 TEST_F(DamageTrackerTest, VerifyDamageForTransformedLayer) { | 438 TEST_F(DamageTrackerTest, VerifyDamageForTransformedLayer) { |
| 439 // If a layer is transformed, the damage rect should still enclose the entire | 439 // If a layer is transformed, the damage rect should still enclose the entire |
| 440 // transformed layer. | 440 // transformed layer. |
| 441 | 441 |
| 442 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 442 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
| 443 LayerImpl* child = root->children()[0]; | 443 LayerImpl* child = root->test_properties()->children[0]; |
| 444 child->test_properties()->force_render_surface = true; | 444 child->test_properties()->force_render_surface = true; |
| 445 | 445 |
| 446 gfx::Transform rotation; | 446 gfx::Transform rotation; |
| 447 rotation.Rotate(45.0); | 447 rotation.Rotate(45.0); |
| 448 | 448 |
| 449 ClearDamageForAllSurfaces(root); | 449 ClearDamageForAllSurfaces(root); |
| 450 child->test_properties()->transform_origin = gfx::Point3F( | 450 child->test_properties()->transform_origin = gfx::Point3F( |
| 451 child->bounds().width() * 0.5f, child->bounds().height() * 0.5f, 0.f); | 451 child->bounds().width() * 0.5f, child->bounds().height() * 0.5f, 0.f); |
| 452 child->SetPosition(gfx::PointF(85.f, 85.f)); | 452 child->SetPosition(gfx::PointF(85.f, 85.f)); |
| 453 child->NoteLayerPropertyChanged(); | 453 child->NoteLayerPropertyChanged(); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 // | 486 // |
| 487 // The transform is constructed so that if w < 0 clipping is not performed, | 487 // The transform is constructed so that if w < 0 clipping is not performed, |
| 488 // the incorrect rect will be very small, specifically: position (500.972504, | 488 // the incorrect rect will be very small, specifically: position (500.972504, |
| 489 // 498.544617) and size 0.056610 x 2.910767. Instead, the correctly | 489 // 498.544617) and size 0.056610 x 2.910767. Instead, the correctly |
| 490 // transformed rect should actually be very huge (i.e. in theory, -infinity | 490 // transformed rect should actually be very huge (i.e. in theory, -infinity |
| 491 // on the left), and positioned so that the right-most bound rect will be | 491 // on the left), and positioned so that the right-most bound rect will be |
| 492 // approximately 501 units in root surface space. | 492 // approximately 501 units in root surface space. |
| 493 // | 493 // |
| 494 | 494 |
| 495 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 495 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
| 496 LayerImpl* child = root->children()[0]; | 496 LayerImpl* child = root->test_properties()->children[0]; |
| 497 | 497 |
| 498 gfx::Transform transform; | 498 gfx::Transform transform; |
| 499 transform.Translate3d(500.0, 500.0, 0.0); | 499 transform.Translate3d(500.0, 500.0, 0.0); |
| 500 transform.ApplyPerspectiveDepth(1.0); | 500 transform.ApplyPerspectiveDepth(1.0); |
| 501 transform.RotateAboutYAxis(45.0); | 501 transform.RotateAboutYAxis(45.0); |
| 502 transform.Translate3d(-50.0, -50.0, 0.0); | 502 transform.Translate3d(-50.0, -50.0, 0.0); |
| 503 | 503 |
| 504 // Set up the child | 504 // Set up the child |
| 505 child->SetPosition(gfx::PointF(0.f, 0.f)); | 505 child->SetPosition(gfx::PointF(0.f, 0.f)); |
| 506 child->SetBounds(gfx::Size(100, 100)); | 506 child->SetBounds(gfx::Size(100, 100)); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 527 // don't care whether the damage rect was clamped or is larger than the | 527 // don't care whether the damage rect was clamped or is larger than the |
| 528 // surface for this test. | 528 // surface for this test. |
| 529 gfx::Rect root_damage_rect = | 529 gfx::Rect root_damage_rect = |
| 530 root->render_surface()->damage_tracker()->current_damage_rect(); | 530 root->render_surface()->damage_tracker()->current_damage_rect(); |
| 531 gfx::Rect damage_we_care_about = gfx::Rect(gfx::Size(500, 500)); | 531 gfx::Rect damage_we_care_about = gfx::Rect(gfx::Size(500, 500)); |
| 532 EXPECT_TRUE(root_damage_rect.Contains(damage_we_care_about)); | 532 EXPECT_TRUE(root_damage_rect.Contains(damage_we_care_about)); |
| 533 } | 533 } |
| 534 | 534 |
| 535 TEST_F(DamageTrackerTest, VerifyDamageForBlurredSurface) { | 535 TEST_F(DamageTrackerTest, VerifyDamageForBlurredSurface) { |
| 536 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 536 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
| 537 LayerImpl* surface = root->children()[0]; | 537 LayerImpl* surface = root->test_properties()->children[0]; |
| 538 LayerImpl* child = surface->children()[0]; | 538 LayerImpl* child = surface->test_properties()->children[0]; |
| 539 | 539 |
| 540 FilterOperations filters; | 540 FilterOperations filters; |
| 541 filters.Append(FilterOperation::CreateBlurFilter(5.f)); | 541 filters.Append(FilterOperation::CreateBlurFilter(5.f)); |
| 542 int outset_top, outset_right, outset_bottom, outset_left; | 542 int outset_top, outset_right, outset_bottom, outset_left; |
| 543 filters.GetOutsets(&outset_top, &outset_right, &outset_bottom, &outset_left); | 543 filters.GetOutsets(&outset_top, &outset_right, &outset_bottom, &outset_left); |
| 544 | 544 |
| 545 // Setting the filter will damage the whole surface. | 545 // Setting the filter will damage the whole surface. |
| 546 ClearDamageForAllSurfaces(root); | 546 ClearDamageForAllSurfaces(root); |
| 547 surface->SetFilters(filters); | 547 surface->SetFilters(filters); |
| 548 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 548 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 563 | 563 |
| 564 expected_damage_rect.Inset(-outset_left, | 564 expected_damage_rect.Inset(-outset_left, |
| 565 -outset_top, | 565 -outset_top, |
| 566 -outset_right, | 566 -outset_right, |
| 567 -outset_bottom); | 567 -outset_bottom); |
| 568 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString()); | 568 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString()); |
| 569 } | 569 } |
| 570 | 570 |
| 571 TEST_F(DamageTrackerTest, VerifyDamageForImageFilter) { | 571 TEST_F(DamageTrackerTest, VerifyDamageForImageFilter) { |
| 572 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 572 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
| 573 LayerImpl* child = root->children()[0]; | 573 LayerImpl* child = root->test_properties()->children[0]; |
| 574 gfx::Rect root_damage_rect, child_damage_rect; | 574 gfx::Rect root_damage_rect, child_damage_rect; |
| 575 | 575 |
| 576 // Allow us to set damage on child too. | 576 // Allow us to set damage on child too. |
| 577 child->SetDrawsContent(true); | 577 child->SetDrawsContent(true); |
| 578 | 578 |
| 579 FilterOperations filters; | 579 FilterOperations filters; |
| 580 filters.Append(FilterOperation::CreateReferenceFilter( | 580 filters.Append(FilterOperation::CreateReferenceFilter( |
| 581 SkBlurImageFilter::Make(2, 2, nullptr))); | 581 SkBlurImageFilter::Make(2, 2, nullptr))); |
| 582 int outset_top, outset_right, outset_bottom, outset_left; | 582 int outset_top, outset_right, outset_bottom, outset_left; |
| 583 filters.GetOutsets(&outset_top, &outset_right, &outset_bottom, &outset_left); | 583 filters.GetOutsets(&outset_top, &outset_right, &outset_bottom, &outset_left); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 617 int expect_height = 1 + outset_top + outset_bottom; | 617 int expect_height = 1 + outset_top + outset_bottom; |
| 618 EXPECT_EQ(gfx::Rect(100 - outset_left, 100 - outset_top, expect_width, | 618 EXPECT_EQ(gfx::Rect(100 - outset_left, 100 - outset_top, expect_width, |
| 619 expect_height), | 619 expect_height), |
| 620 root_damage_rect); | 620 root_damage_rect); |
| 621 EXPECT_EQ(gfx::Rect(-outset_left, -outset_top, expect_width, expect_height), | 621 EXPECT_EQ(gfx::Rect(-outset_left, -outset_top, expect_width, expect_height), |
| 622 child_damage_rect); | 622 child_damage_rect); |
| 623 } | 623 } |
| 624 | 624 |
| 625 TEST_F(DamageTrackerTest, VerifyDamageForTransformedImageFilter) { | 625 TEST_F(DamageTrackerTest, VerifyDamageForTransformedImageFilter) { |
| 626 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 626 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
| 627 LayerImpl* child = root->children()[0]; | 627 LayerImpl* child = root->test_properties()->children[0]; |
| 628 gfx::Rect root_damage_rect, child_damage_rect; | 628 gfx::Rect root_damage_rect, child_damage_rect; |
| 629 | 629 |
| 630 // Allow us to set damage on child too. | 630 // Allow us to set damage on child too. |
| 631 child->SetDrawsContent(true); | 631 child->SetDrawsContent(true); |
| 632 | 632 |
| 633 FilterOperations filters; | 633 FilterOperations filters; |
| 634 filters.Append(FilterOperation::CreateReferenceFilter( | 634 filters.Append(FilterOperation::CreateReferenceFilter( |
| 635 SkBlurImageFilter::Make(2, 2, nullptr))); | 635 SkBlurImageFilter::Make(2, 2, nullptr))); |
| 636 int outset_top, outset_right, outset_bottom, outset_left; | 636 int outset_top, outset_right, outset_bottom, outset_left; |
| 637 filters.GetOutsets(&outset_top, &outset_right, &outset_bottom, &outset_left); | 637 filters.GetOutsets(&outset_top, &outset_right, &outset_bottom, &outset_left); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 677 int expect_height = 30 + outset_top + outset_bottom; | 677 int expect_height = 30 + outset_top + outset_bottom; |
| 678 EXPECT_EQ(gfx::Rect(100 - outset_left / 2, 100 - outset_top, expect_width / 2, | 678 EXPECT_EQ(gfx::Rect(100 - outset_left / 2, 100 - outset_top, expect_width / 2, |
| 679 expect_height), | 679 expect_height), |
| 680 root_damage_rect); | 680 root_damage_rect); |
| 681 EXPECT_EQ(gfx::Rect(-outset_left, -outset_top, expect_width, expect_height), | 681 EXPECT_EQ(gfx::Rect(-outset_left, -outset_top, expect_width, expect_height), |
| 682 child_damage_rect); | 682 child_damage_rect); |
| 683 } | 683 } |
| 684 | 684 |
| 685 TEST_F(DamageTrackerTest, VerifyDamageForBackgroundBlurredChild) { | 685 TEST_F(DamageTrackerTest, VerifyDamageForBackgroundBlurredChild) { |
| 686 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 686 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
| 687 LayerImpl* child1 = root->children()[0]; | 687 LayerImpl* child1 = root->test_properties()->children[0]; |
| 688 LayerImpl* child2 = root->children()[1]; | 688 LayerImpl* child2 = root->test_properties()->children[1]; |
| 689 | 689 |
| 690 // Allow us to set damage on child1 too. | 690 // Allow us to set damage on child1 too. |
| 691 child1->SetDrawsContent(true); | 691 child1->SetDrawsContent(true); |
| 692 | 692 |
| 693 FilterOperations filters; | 693 FilterOperations filters; |
| 694 filters.Append(FilterOperation::CreateBlurFilter(2.f)); | 694 filters.Append(FilterOperation::CreateBlurFilter(2.f)); |
| 695 int outset_top, outset_right, outset_bottom, outset_left; | 695 int outset_top, outset_right, outset_bottom, outset_left; |
| 696 filters.GetOutsets(&outset_top, &outset_right, &outset_bottom, &outset_left); | 696 filters.GetOutsets(&outset_top, &outset_right, &outset_bottom, &outset_left); |
| 697 | 697 |
| 698 // Setting the filter will damage the whole surface. | 698 // Setting the filter will damage the whole surface. |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 809 // Damage should be (0,0 1x1), offset by the 100,100 offset of child1 in | 809 // Damage should be (0,0 1x1), offset by the 100,100 offset of child1 in |
| 810 // root, and expanded 6px for the 2px blur (i.e., 94,94 13x13), but there | 810 // root, and expanded 6px for the 2px blur (i.e., 94,94 13x13), but there |
| 811 // should be no damage outside child1 (i.e. none above or to the left of | 811 // should be no damage outside child1 (i.e. none above or to the left of |
| 812 // 100,100. | 812 // 100,100. |
| 813 expected_damage_rect = gfx::Rect(100, 100, 7, 7); | 813 expected_damage_rect = gfx::Rect(100, 100, 7, 7); |
| 814 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString()); | 814 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString()); |
| 815 } | 815 } |
| 816 | 816 |
| 817 TEST_F(DamageTrackerTest, VerifyDamageForAddingAndRemovingLayer) { | 817 TEST_F(DamageTrackerTest, VerifyDamageForAddingAndRemovingLayer) { |
| 818 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 818 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
| 819 LayerImpl* child1 = root->children()[0]; | 819 LayerImpl* child1 = root->test_properties()->children[0]; |
| 820 | 820 |
| 821 // CASE 1: Adding a new layer should cause the appropriate damage. | 821 // CASE 1: Adding a new layer should cause the appropriate damage. |
| 822 // | 822 // |
| 823 ClearDamageForAllSurfaces(root); | 823 ClearDamageForAllSurfaces(root); |
| 824 { | 824 { |
| 825 std::unique_ptr<LayerImpl> child2 = | 825 std::unique_ptr<LayerImpl> child2 = |
| 826 LayerImpl::Create(host_impl_.active_tree(), 3); | 826 LayerImpl::Create(host_impl_.active_tree(), 3); |
| 827 child2->SetPosition(gfx::PointF(400.f, 380.f)); | 827 child2->SetPosition(gfx::PointF(400.f, 380.f)); |
| 828 child2->SetBounds(gfx::Size(6, 8)); | 828 child2->SetBounds(gfx::Size(6, 8)); |
| 829 child2->SetDrawsContent(true); | 829 child2->SetDrawsContent(true); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 895 // surfaces are tested elsewhere. | 895 // surfaces are tested elsewhere. |
| 896 ASSERT_EQ(3u, root->render_surface()->layer_list().size()); | 896 ASSERT_EQ(3u, root->render_surface()->layer_list().size()); |
| 897 | 897 |
| 898 gfx::Rect root_damage_rect = | 898 gfx::Rect root_damage_rect = |
| 899 root->render_surface()->damage_tracker()->current_damage_rect(); | 899 root->render_surface()->damage_tracker()->current_damage_rect(); |
| 900 EXPECT_EQ(gfx::Rect(400, 380, 6, 8).ToString(), root_damage_rect.ToString()); | 900 EXPECT_EQ(gfx::Rect(400, 380, 6, 8).ToString(), root_damage_rect.ToString()); |
| 901 } | 901 } |
| 902 | 902 |
| 903 TEST_F(DamageTrackerTest, VerifyDamageForMultipleLayers) { | 903 TEST_F(DamageTrackerTest, VerifyDamageForMultipleLayers) { |
| 904 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 904 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
| 905 LayerImpl* child1 = root->children()[0]; | 905 LayerImpl* child1 = root->test_properties()->children[0]; |
| 906 | 906 |
| 907 // In this test we don't want the above tree manipulation to be considered | 907 // In this test we don't want the above tree manipulation to be considered |
| 908 // part of the same frame. | 908 // part of the same frame. |
| 909 ClearDamageForAllSurfaces(root); | 909 ClearDamageForAllSurfaces(root); |
| 910 { | 910 { |
| 911 std::unique_ptr<LayerImpl> child2 = | 911 std::unique_ptr<LayerImpl> child2 = |
| 912 LayerImpl::Create(host_impl_.active_tree(), 3); | 912 LayerImpl::Create(host_impl_.active_tree(), 3); |
| 913 child2->SetPosition(gfx::PointF(400.f, 380.f)); | 913 child2->SetPosition(gfx::PointF(400.f, 380.f)); |
| 914 child2->SetBounds(gfx::Size(6, 8)); | 914 child2->SetBounds(gfx::Size(6, 8)); |
| 915 child2->SetDrawsContent(true); | 915 child2->SetDrawsContent(true); |
| 916 root->AddChild(std::move(child2)); | 916 root->AddChild(std::move(child2)); |
| 917 } | 917 } |
| 918 LayerImpl* child2 = root->children()[1]; | 918 LayerImpl* child2 = root->test_properties()->children[1]; |
| 919 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 919 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 920 EmulateDrawingOneFrame(root); | 920 EmulateDrawingOneFrame(root); |
| 921 | 921 |
| 922 // Damaging two layers simultaneously should cause combined damage. | 922 // Damaging two layers simultaneously should cause combined damage. |
| 923 // - child1 update rect in surface space: gfx::Rect(100, 100, 1, 2); | 923 // - child1 update rect in surface space: gfx::Rect(100, 100, 1, 2); |
| 924 // - child2 update rect in surface space: gfx::Rect(400, 380, 3, 4); | 924 // - child2 update rect in surface space: gfx::Rect(400, 380, 3, 4); |
| 925 ClearDamageForAllSurfaces(root); | 925 ClearDamageForAllSurfaces(root); |
| 926 child1->SetUpdateRect(gfx::Rect(1, 2)); | 926 child1->SetUpdateRect(gfx::Rect(1, 2)); |
| 927 child2->SetUpdateRect(gfx::Rect(3, 4)); | 927 child2->SetUpdateRect(gfx::Rect(3, 4)); |
| 928 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 928 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 929 EmulateDrawingOneFrame(root); | 929 EmulateDrawingOneFrame(root); |
| 930 gfx::Rect root_damage_rect = | 930 gfx::Rect root_damage_rect = |
| 931 root->render_surface()->damage_tracker()->current_damage_rect(); | 931 root->render_surface()->damage_tracker()->current_damage_rect(); |
| 932 EXPECT_EQ(gfx::Rect(100, 100, 303, 284).ToString(), | 932 EXPECT_EQ(gfx::Rect(100, 100, 303, 284).ToString(), |
| 933 root_damage_rect.ToString()); | 933 root_damage_rect.ToString()); |
| 934 } | 934 } |
| 935 | 935 |
| 936 TEST_F(DamageTrackerTest, VerifyDamageForNestedSurfaces) { | 936 TEST_F(DamageTrackerTest, VerifyDamageForNestedSurfaces) { |
| 937 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 937 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
| 938 LayerImpl* child1 = root->children()[0]; | 938 LayerImpl* child1 = root->test_properties()->children[0]; |
| 939 LayerImpl* child2 = root->children()[1]; | 939 LayerImpl* child2 = root->test_properties()->children[1]; |
| 940 LayerImpl* grand_child1 = root->children()[0]->children()[0]; | 940 LayerImpl* grand_child1 = |
| 941 root->test_properties()->children[0]->test_properties()->children[0]; |
| 941 child2->test_properties()->force_render_surface = true; | 942 child2->test_properties()->force_render_surface = true; |
| 942 grand_child1->test_properties()->force_render_surface = true; | 943 grand_child1->test_properties()->force_render_surface = true; |
| 943 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 944 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 944 EmulateDrawingOneFrame(root); | 945 EmulateDrawingOneFrame(root); |
| 945 gfx::Rect child_damage_rect; | 946 gfx::Rect child_damage_rect; |
| 946 gfx::Rect root_damage_rect; | 947 gfx::Rect root_damage_rect; |
| 947 | 948 |
| 948 // CASE 1: Damage to a descendant surface should propagate properly to | 949 // CASE 1: Damage to a descendant surface should propagate properly to |
| 949 // ancestor surface. | 950 // ancestor surface. |
| 950 ClearDamageForAllSurfaces(root); | 951 ClearDamageForAllSurfaces(root); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 978 | 979 |
| 979 TEST_F(DamageTrackerTest, VerifyDamageForSurfaceChangeFromDescendantLayer) { | 980 TEST_F(DamageTrackerTest, VerifyDamageForSurfaceChangeFromDescendantLayer) { |
| 980 // If descendant layer changes and affects the content bounds of the render | 981 // If descendant layer changes and affects the content bounds of the render |
| 981 // surface, then the entire descendant surface should be damaged, and it | 982 // surface, then the entire descendant surface should be damaged, and it |
| 982 // should damage its ancestor surface with the old and new surface regions. | 983 // should damage its ancestor surface with the old and new surface regions. |
| 983 | 984 |
| 984 // This is a tricky case, since only the first grand_child changes, but the | 985 // This is a tricky case, since only the first grand_child changes, but the |
| 985 // entire surface should be marked dirty. | 986 // entire surface should be marked dirty. |
| 986 | 987 |
| 987 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 988 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
| 988 LayerImpl* child1 = root->children()[0]; | 989 LayerImpl* child1 = root->test_properties()->children[0]; |
| 989 LayerImpl* grand_child1 = root->children()[0]->children()[0]; | 990 LayerImpl* grand_child1 = |
| 991 root->test_properties()->children[0]->test_properties()->children[0]; |
| 990 gfx::Rect child_damage_rect; | 992 gfx::Rect child_damage_rect; |
| 991 gfx::Rect root_damage_rect; | 993 gfx::Rect root_damage_rect; |
| 992 | 994 |
| 993 ClearDamageForAllSurfaces(root); | 995 ClearDamageForAllSurfaces(root); |
| 994 grand_child1->SetPosition(gfx::PointF(195.f, 205.f)); | 996 grand_child1->SetPosition(gfx::PointF(195.f, 205.f)); |
| 995 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 997 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 996 EmulateDrawingOneFrame(root); | 998 EmulateDrawingOneFrame(root); |
| 997 child_damage_rect = | 999 child_damage_rect = |
| 998 child1->render_surface()->damage_tracker()->current_damage_rect(); | 1000 child1->render_surface()->damage_tracker()->current_damage_rect(); |
| 999 root_damage_rect = | 1001 root_damage_rect = |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1017 // already propagates to the subtree (tested in LayerImpltest), which damages | 1019 // already propagates to the subtree (tested in LayerImpltest), which damages |
| 1018 // the entire child1 surface, but the damage tracker still needs the correct | 1020 // the entire child1 surface, but the damage tracker still needs the correct |
| 1019 // logic to compute the exposed region on the root surface. | 1021 // logic to compute the exposed region on the root surface. |
| 1020 | 1022 |
| 1021 // TODO(shawnsingh): the expectations of this test case should change when we | 1023 // TODO(shawnsingh): the expectations of this test case should change when we |
| 1022 // add support for a unique scissor_rect per RenderSurface. In that case, the | 1024 // add support for a unique scissor_rect per RenderSurface. In that case, the |
| 1023 // child1 surface should be completely unchanged, since we are only | 1025 // child1 surface should be completely unchanged, since we are only |
| 1024 // transforming it, while the root surface would be damaged appropriately. | 1026 // transforming it, while the root surface would be damaged appropriately. |
| 1025 | 1027 |
| 1026 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 1028 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
| 1027 LayerImpl* child1 = root->children()[0]; | 1029 LayerImpl* child1 = root->test_properties()->children[0]; |
| 1028 LayerImpl* grand_child1 = child1->children()[0]; | 1030 LayerImpl* grand_child1 = child1->test_properties()->children[0]; |
| 1029 LayerImpl* grand_child2 = child1->children()[1]; | 1031 LayerImpl* grand_child2 = child1->test_properties()->children[1]; |
| 1030 gfx::Rect child_damage_rect; | 1032 gfx::Rect child_damage_rect; |
| 1031 gfx::Rect root_damage_rect; | 1033 gfx::Rect root_damage_rect; |
| 1032 | 1034 |
| 1033 ClearDamageForAllSurfaces(root); | 1035 ClearDamageForAllSurfaces(root); |
| 1034 child1->SetPosition(gfx::PointF(50.f, 50.f)); | 1036 child1->SetPosition(gfx::PointF(50.f, 50.f)); |
| 1035 child1->NoteLayerPropertyChanged(); | 1037 child1->NoteLayerPropertyChanged(); |
| 1036 grand_child1->NoteLayerPropertyChanged(); | 1038 grand_child1->NoteLayerPropertyChanged(); |
| 1037 grand_child2->NoteLayerPropertyChanged(); | 1039 grand_child2->NoteLayerPropertyChanged(); |
| 1038 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1040 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 1039 EmulateDrawingOneFrame(root); | 1041 EmulateDrawingOneFrame(root); |
| 1040 child_damage_rect = | 1042 child_damage_rect = |
| 1041 child1->render_surface()->damage_tracker()->current_damage_rect(); | 1043 child1->render_surface()->damage_tracker()->current_damage_rect(); |
| 1042 root_damage_rect = | 1044 root_damage_rect = |
| 1043 root->render_surface()->damage_tracker()->current_damage_rect(); | 1045 root->render_surface()->damage_tracker()->current_damage_rect(); |
| 1044 | 1046 |
| 1045 // The new surface bounds should be damaged entirely. | 1047 // The new surface bounds should be damaged entirely. |
| 1046 EXPECT_EQ(gfx::Rect(190, 190, 16, 18).ToString(), | 1048 EXPECT_EQ(gfx::Rect(190, 190, 16, 18).ToString(), |
| 1047 child_damage_rect.ToString()); | 1049 child_damage_rect.ToString()); |
| 1048 | 1050 |
| 1049 // The entire child1 surface and the old exposed child1 surface should damage | 1051 // The entire child1 surface and the old exposed child1 surface should damage |
| 1050 // the root surface. | 1052 // the root surface. |
| 1051 // - old child1 surface in target space: gfx::Rect(290, 290, 16, 18) | 1053 // - old child1 surface in target space: gfx::Rect(290, 290, 16, 18) |
| 1052 // - new child1 surface in target space: gfx::Rect(240, 240, 16, 18) | 1054 // - new child1 surface in target space: gfx::Rect(240, 240, 16, 18) |
| 1053 EXPECT_EQ(gfx::Rect(240, 240, 66, 68).ToString(), | 1055 EXPECT_EQ(gfx::Rect(240, 240, 66, 68).ToString(), |
| 1054 root_damage_rect.ToString()); | 1056 root_damage_rect.ToString()); |
| 1055 } | 1057 } |
| 1056 | 1058 |
| 1057 TEST_F(DamageTrackerTest, VerifyDamageForAddingAndRemovingRenderSurfaces) { | 1059 TEST_F(DamageTrackerTest, VerifyDamageForAddingAndRemovingRenderSurfaces) { |
| 1058 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 1060 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
| 1059 LayerImpl* child1 = root->children()[0]; | 1061 LayerImpl* child1 = root->test_properties()->children[0]; |
| 1060 gfx::Rect child_damage_rect; | 1062 gfx::Rect child_damage_rect; |
| 1061 gfx::Rect root_damage_rect; | 1063 gfx::Rect root_damage_rect; |
| 1062 | 1064 |
| 1063 // CASE 1: If a descendant surface disappears, its entire old area becomes | 1065 // CASE 1: If a descendant surface disappears, its entire old area becomes |
| 1064 // exposed. | 1066 // exposed. |
| 1065 ClearDamageForAllSurfaces(root); | 1067 ClearDamageForAllSurfaces(root); |
| 1066 child1->test_properties()->force_render_surface = false; | 1068 child1->test_properties()->force_render_surface = false; |
| 1067 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1069 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 1068 EmulateDrawingOneFrame(root); | 1070 EmulateDrawingOneFrame(root); |
| 1069 | 1071 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1105 root_damage_rect = | 1107 root_damage_rect = |
| 1106 root->render_surface()->damage_tracker()->current_damage_rect(); | 1108 root->render_surface()->damage_tracker()->current_damage_rect(); |
| 1107 EXPECT_EQ(gfx::Rect(190, 190, 16, 18).ToString(), | 1109 EXPECT_EQ(gfx::Rect(190, 190, 16, 18).ToString(), |
| 1108 child_damage_rect.ToString()); | 1110 child_damage_rect.ToString()); |
| 1109 EXPECT_EQ(gfx::Rect(290, 290, 16, 18).ToString(), | 1111 EXPECT_EQ(gfx::Rect(290, 290, 16, 18).ToString(), |
| 1110 root_damage_rect.ToString()); | 1112 root_damage_rect.ToString()); |
| 1111 } | 1113 } |
| 1112 | 1114 |
| 1113 TEST_F(DamageTrackerTest, VerifyNoDamageWhenNothingChanged) { | 1115 TEST_F(DamageTrackerTest, VerifyNoDamageWhenNothingChanged) { |
| 1114 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 1116 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
| 1115 LayerImpl* child1 = root->children()[0]; | 1117 LayerImpl* child1 = root->test_properties()->children[0]; |
| 1116 gfx::Rect child_damage_rect; | 1118 gfx::Rect child_damage_rect; |
| 1117 gfx::Rect root_damage_rect; | 1119 gfx::Rect root_damage_rect; |
| 1118 | 1120 |
| 1119 // CASE 1: If nothing changes, the damage rect should be empty. | 1121 // CASE 1: If nothing changes, the damage rect should be empty. |
| 1120 // | 1122 // |
| 1121 ClearDamageForAllSurfaces(root); | 1123 ClearDamageForAllSurfaces(root); |
| 1122 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1124 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 1123 EmulateDrawingOneFrame(root); | 1125 EmulateDrawingOneFrame(root); |
| 1124 child_damage_rect = | 1126 child_damage_rect = |
| 1125 child1->render_surface()->damage_tracker()->current_damage_rect(); | 1127 child1->render_surface()->damage_tracker()->current_damage_rect(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1137 child_damage_rect = | 1139 child_damage_rect = |
| 1138 child1->render_surface()->damage_tracker()->current_damage_rect(); | 1140 child1->render_surface()->damage_tracker()->current_damage_rect(); |
| 1139 root_damage_rect = | 1141 root_damage_rect = |
| 1140 root->render_surface()->damage_tracker()->current_damage_rect(); | 1142 root->render_surface()->damage_tracker()->current_damage_rect(); |
| 1141 EXPECT_TRUE(child_damage_rect.IsEmpty()); | 1143 EXPECT_TRUE(child_damage_rect.IsEmpty()); |
| 1142 EXPECT_TRUE(root_damage_rect.IsEmpty()); | 1144 EXPECT_TRUE(root_damage_rect.IsEmpty()); |
| 1143 } | 1145 } |
| 1144 | 1146 |
| 1145 TEST_F(DamageTrackerTest, VerifyNoDamageForUpdateRectThatDoesNotDrawContent) { | 1147 TEST_F(DamageTrackerTest, VerifyNoDamageForUpdateRectThatDoesNotDrawContent) { |
| 1146 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 1148 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
| 1147 LayerImpl* child1 = root->children()[0]; | 1149 LayerImpl* child1 = root->test_properties()->children[0]; |
| 1148 gfx::Rect child_damage_rect; | 1150 gfx::Rect child_damage_rect; |
| 1149 gfx::Rect root_damage_rect; | 1151 gfx::Rect root_damage_rect; |
| 1150 | 1152 |
| 1151 // In our specific tree, the update rect of child1 should not cause any | 1153 // In our specific tree, the update rect of child1 should not cause any |
| 1152 // damage to any surface because it does not actually draw content. | 1154 // damage to any surface because it does not actually draw content. |
| 1153 ClearDamageForAllSurfaces(root); | 1155 ClearDamageForAllSurfaces(root); |
| 1154 child1->SetUpdateRect(gfx::Rect(1, 2)); | 1156 child1->SetUpdateRect(gfx::Rect(1, 2)); |
| 1155 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1157 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 1156 EmulateDrawingOneFrame(root); | 1158 EmulateDrawingOneFrame(root); |
| 1157 child_damage_rect = | 1159 child_damage_rect = |
| 1158 child1->render_surface()->damage_tracker()->current_damage_rect(); | 1160 child1->render_surface()->damage_tracker()->current_damage_rect(); |
| 1159 root_damage_rect = | 1161 root_damage_rect = |
| 1160 root->render_surface()->damage_tracker()->current_damage_rect(); | 1162 root->render_surface()->damage_tracker()->current_damage_rect(); |
| 1161 EXPECT_TRUE(child_damage_rect.IsEmpty()); | 1163 EXPECT_TRUE(child_damage_rect.IsEmpty()); |
| 1162 EXPECT_TRUE(root_damage_rect.IsEmpty()); | 1164 EXPECT_TRUE(root_damage_rect.IsEmpty()); |
| 1163 } | 1165 } |
| 1164 | 1166 |
| 1165 TEST_F(DamageTrackerTest, VerifyDamageForReplica) { | 1167 TEST_F(DamageTrackerTest, VerifyDamageForReplica) { |
| 1166 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 1168 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
| 1167 LayerImpl* child1 = root->children()[0]; | 1169 LayerImpl* child1 = root->test_properties()->children[0]; |
| 1168 LayerImpl* grand_child1 = child1->children()[0]; | 1170 LayerImpl* grand_child1 = child1->test_properties()->children[0]; |
| 1169 LayerImpl* grand_child2 = child1->children()[1]; | 1171 LayerImpl* grand_child2 = child1->test_properties()->children[1]; |
| 1170 | 1172 |
| 1171 // Damage on a surface that has a reflection should cause the target surface | 1173 // Damage on a surface that has a reflection should cause the target surface |
| 1172 // to receive the surface's damage and the surface's reflected damage. | 1174 // to receive the surface's damage and the surface's reflected damage. |
| 1173 | 1175 |
| 1174 // For this test case, we modify grand_child2, and add grand_child3 to extend | 1176 // For this test case, we modify grand_child2, and add grand_child3 to extend |
| 1175 // the bounds of child1's surface. This way, we can test reflection changes | 1177 // the bounds of child1's surface. This way, we can test reflection changes |
| 1176 // without changing content_bounds of the surface. | 1178 // without changing content_bounds of the surface. |
| 1177 grand_child2->SetPosition(gfx::PointF(180.f, 180.f)); | 1179 grand_child2->SetPosition(gfx::PointF(180.f, 180.f)); |
| 1178 { | 1180 { |
| 1179 std::unique_ptr<LayerImpl> grand_child3 = | 1181 std::unique_ptr<LayerImpl> grand_child3 = |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1268 root_damage_rect = | 1270 root_damage_rect = |
| 1269 root->render_surface()->damage_tracker()->current_damage_rect(); | 1271 root->render_surface()->damage_tracker()->current_damage_rect(); |
| 1270 | 1272 |
| 1271 EXPECT_EQ(gfx::Rect(189, 205, 12, 8).ToString(), | 1273 EXPECT_EQ(gfx::Rect(189, 205, 12, 8).ToString(), |
| 1272 child_damage_rect.ToString()); | 1274 child_damage_rect.ToString()); |
| 1273 EXPECT_EQ(gfx::Rect(289, 305, 12, 8).ToString(), root_damage_rect.ToString()); | 1275 EXPECT_EQ(gfx::Rect(289, 305, 12, 8).ToString(), root_damage_rect.ToString()); |
| 1274 } | 1276 } |
| 1275 | 1277 |
| 1276 TEST_F(DamageTrackerTest, VerifyDamageForMask) { | 1278 TEST_F(DamageTrackerTest, VerifyDamageForMask) { |
| 1277 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 1279 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
| 1278 LayerImpl* child = root->children()[0]; | 1280 LayerImpl* child = root->test_properties()->children[0]; |
| 1279 | 1281 |
| 1280 // In the current implementation of the damage tracker, changes to mask | 1282 // In the current implementation of the damage tracker, changes to mask |
| 1281 // layers should damage the entire corresponding surface. | 1283 // layers should damage the entire corresponding surface. |
| 1282 | 1284 |
| 1283 ClearDamageForAllSurfaces(root); | 1285 ClearDamageForAllSurfaces(root); |
| 1284 | 1286 |
| 1285 // Set up the mask layer. | 1287 // Set up the mask layer. |
| 1286 { | 1288 { |
| 1287 std::unique_ptr<LayerImpl> mask_layer = | 1289 std::unique_ptr<LayerImpl> mask_layer = |
| 1288 LayerImpl::Create(host_impl_.active_tree(), 3); | 1290 LayerImpl::Create(host_impl_.active_tree(), 3); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1361 // Sanity check that a render surface still exists. | 1363 // Sanity check that a render surface still exists. |
| 1362 ASSERT_TRUE(child->render_surface()); | 1364 ASSERT_TRUE(child->render_surface()); |
| 1363 | 1365 |
| 1364 child_damage_rect = | 1366 child_damage_rect = |
| 1365 child->render_surface()->damage_tracker()->current_damage_rect(); | 1367 child->render_surface()->damage_tracker()->current_damage_rect(); |
| 1366 EXPECT_EQ(gfx::Rect(30, 30).ToString(), child_damage_rect.ToString()); | 1368 EXPECT_EQ(gfx::Rect(30, 30).ToString(), child_damage_rect.ToString()); |
| 1367 } | 1369 } |
| 1368 | 1370 |
| 1369 TEST_F(DamageTrackerTest, VerifyDamageForReplicaMask) { | 1371 TEST_F(DamageTrackerTest, VerifyDamageForReplicaMask) { |
| 1370 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 1372 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
| 1371 LayerImpl* child1 = root->children()[0]; | 1373 LayerImpl* child1 = root->test_properties()->children[0]; |
| 1372 LayerImpl* grand_child1 = child1->children()[0]; | 1374 LayerImpl* grand_child1 = child1->test_properties()->children[0]; |
| 1373 | 1375 |
| 1374 // Changes to a replica's mask should not damage the original surface, | 1376 // Changes to a replica's mask should not damage the original surface, |
| 1375 // because it is not masked. But it does damage the ancestor target surface. | 1377 // because it is not masked. But it does damage the ancestor target surface. |
| 1376 | 1378 |
| 1377 ClearDamageForAllSurfaces(root); | 1379 ClearDamageForAllSurfaces(root); |
| 1378 | 1380 |
| 1379 // Create a reflection about the left edge of grand_child1. | 1381 // Create a reflection about the left edge of grand_child1. |
| 1380 { | 1382 { |
| 1381 std::unique_ptr<LayerImpl> grand_child1_replica = | 1383 std::unique_ptr<LayerImpl> grand_child1_replica = |
| 1382 LayerImpl::Create(host_impl_.active_tree(), 6); | 1384 LayerImpl::Create(host_impl_.active_tree(), 6); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1433 current_damage_rect(); | 1435 current_damage_rect(); |
| 1434 child_damage_rect = | 1436 child_damage_rect = |
| 1435 child1->render_surface()->damage_tracker()->current_damage_rect(); | 1437 child1->render_surface()->damage_tracker()->current_damage_rect(); |
| 1436 | 1438 |
| 1437 EXPECT_TRUE(grand_child_damage_rect.IsEmpty()); | 1439 EXPECT_TRUE(grand_child_damage_rect.IsEmpty()); |
| 1438 EXPECT_EQ(gfx::Rect(194, 200, 6, 8).ToString(), child_damage_rect.ToString()); | 1440 EXPECT_EQ(gfx::Rect(194, 200, 6, 8).ToString(), child_damage_rect.ToString()); |
| 1439 } | 1441 } |
| 1440 | 1442 |
| 1441 TEST_F(DamageTrackerTest, VerifyDamageForReplicaMaskWithTransformOrigin) { | 1443 TEST_F(DamageTrackerTest, VerifyDamageForReplicaMaskWithTransformOrigin) { |
| 1442 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 1444 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
| 1443 LayerImpl* child1 = root->children()[0]; | 1445 LayerImpl* child1 = root->test_properties()->children[0]; |
| 1444 LayerImpl* grand_child1 = child1->children()[0]; | 1446 LayerImpl* grand_child1 = child1->test_properties()->children[0]; |
| 1445 | 1447 |
| 1446 // Verify that the correct replica_origin_transform is used for the | 1448 // Verify that the correct replica_origin_transform is used for the |
| 1447 // replica_mask. | 1449 // replica_mask. |
| 1448 ClearDamageForAllSurfaces(root); | 1450 ClearDamageForAllSurfaces(root); |
| 1449 | 1451 |
| 1450 // This is not actually the transform origin point being tested, but by | 1452 // This is not actually the transform origin point being tested, but by |
| 1451 // convention its | 1453 // convention its |
| 1452 // expected to be the same as the replica's anchor point. | 1454 // expected to be the same as the replica's anchor point. |
| 1453 grand_child1->test_properties()->transform_origin = | 1455 grand_child1->test_properties()->transform_origin = |
| 1454 gfx::Point3F(grand_child1->bounds().width(), 0.f, 0.f); | 1456 gfx::Point3F(grand_child1->bounds().width(), 0.f, 0.f); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1496 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1498 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 1497 EmulateDrawingOneFrame(root); | 1499 EmulateDrawingOneFrame(root); |
| 1498 | 1500 |
| 1499 gfx::Rect child_damage_rect = | 1501 gfx::Rect child_damage_rect = |
| 1500 child1->render_surface()->damage_tracker()->current_damage_rect(); | 1502 child1->render_surface()->damage_tracker()->current_damage_rect(); |
| 1501 EXPECT_EQ(gfx::Rect(206, 200, 6, 8).ToString(), child_damage_rect.ToString()); | 1503 EXPECT_EQ(gfx::Rect(206, 200, 6, 8).ToString(), child_damage_rect.ToString()); |
| 1502 } | 1504 } |
| 1503 | 1505 |
| 1504 TEST_F(DamageTrackerTest, DamageWhenAddedExternally) { | 1506 TEST_F(DamageTrackerTest, DamageWhenAddedExternally) { |
| 1505 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 1507 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
| 1506 LayerImpl* child = root->children()[0]; | 1508 LayerImpl* child = root->test_properties()->children[0]; |
| 1507 | 1509 |
| 1508 // Case 1: This test ensures that when the tracker is given damage, that | 1510 // Case 1: This test ensures that when the tracker is given damage, that |
| 1509 // it is included with any other partial damage. | 1511 // it is included with any other partial damage. |
| 1510 // | 1512 // |
| 1511 ClearDamageForAllSurfaces(root); | 1513 ClearDamageForAllSurfaces(root); |
| 1512 child->SetUpdateRect(gfx::Rect(10, 11, 12, 13)); | 1514 child->SetUpdateRect(gfx::Rect(10, 11, 12, 13)); |
| 1513 root->render_surface()->damage_tracker()->AddDamageNextUpdate( | 1515 root->render_surface()->damage_tracker()->AddDamageNextUpdate( |
| 1514 gfx::Rect(15, 16, 32, 33)); | 1516 gfx::Rect(15, 16, 32, 33)); |
| 1515 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1517 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 1516 EmulateDrawingOneFrame(root); | 1518 EmulateDrawingOneFrame(root); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1554 | 1556 |
| 1555 gfx::Rect damage_rect = | 1557 gfx::Rect damage_rect = |
| 1556 target_surface->damage_tracker()->current_damage_rect(); | 1558 target_surface->damage_tracker()->current_damage_rect(); |
| 1557 EXPECT_TRUE(damage_rect.IsEmpty()); | 1559 EXPECT_TRUE(damage_rect.IsEmpty()); |
| 1558 } | 1560 } |
| 1559 | 1561 |
| 1560 TEST_F(DamageTrackerTest, VerifyDamageAccumulatesUntilReset) { | 1562 TEST_F(DamageTrackerTest, VerifyDamageAccumulatesUntilReset) { |
| 1561 // If damage is not cleared, it should accumulate. | 1563 // If damage is not cleared, it should accumulate. |
| 1562 | 1564 |
| 1563 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 1565 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
| 1564 LayerImpl* child = root->children()[0]; | 1566 LayerImpl* child = root->test_properties()->children[0]; |
| 1565 | 1567 |
| 1566 ClearDamageForAllSurfaces(root); | 1568 ClearDamageForAllSurfaces(root); |
| 1567 child->SetUpdateRect(gfx::Rect(10.f, 11.f, 1.f, 2.f)); | 1569 child->SetUpdateRect(gfx::Rect(10.f, 11.f, 1.f, 2.f)); |
| 1568 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1570 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 1569 EmulateDrawingOneFrame(root); | 1571 EmulateDrawingOneFrame(root); |
| 1570 | 1572 |
| 1571 // Sanity check damage after the first frame; this isnt the actual test yet. | 1573 // Sanity check damage after the first frame; this isnt the actual test yet. |
| 1572 gfx::Rect root_damage_rect = | 1574 gfx::Rect root_damage_rect = |
| 1573 root->render_surface()->damage_tracker()->current_damage_rect(); | 1575 root->render_surface()->damage_tracker()->current_damage_rect(); |
| 1574 EXPECT_EQ(gfx::Rect(110, 111, 1, 2).ToString(), root_damage_rect.ToString()); | 1576 EXPECT_EQ(gfx::Rect(110, 111, 1, 2).ToString(), root_damage_rect.ToString()); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1601 | 1603 |
| 1602 TEST_F(DamageTrackerTest, HugeDamageRect) { | 1604 TEST_F(DamageTrackerTest, HugeDamageRect) { |
| 1603 // This number is so large that we start losting floating point accuracy. | 1605 // This number is so large that we start losting floating point accuracy. |
| 1604 const int kBigNumber = 900000000; | 1606 const int kBigNumber = 900000000; |
| 1605 // Walk over a range to find floating point inaccuracy boundaries that move | 1607 // Walk over a range to find floating point inaccuracy boundaries that move |
| 1606 // toward the wrong direction. | 1608 // toward the wrong direction. |
| 1607 const int kRange = 5000; | 1609 const int kRange = 5000; |
| 1608 | 1610 |
| 1609 for (int i = 0; i < kRange; ++i) { | 1611 for (int i = 0; i < kRange; ++i) { |
| 1610 LayerImpl* root = CreateTestTreeWithOneSurface(); | 1612 LayerImpl* root = CreateTestTreeWithOneSurface(); |
| 1611 LayerImpl* child = root->children()[0]; | 1613 LayerImpl* child = root->test_properties()->children[0]; |
| 1612 | 1614 |
| 1613 gfx::Transform transform; | 1615 gfx::Transform transform; |
| 1614 transform.Translate(-kBigNumber, -kBigNumber); | 1616 transform.Translate(-kBigNumber, -kBigNumber); |
| 1615 | 1617 |
| 1616 // The child layer covers (0, 0, i, i) of the viewport, | 1618 // The child layer covers (0, 0, i, i) of the viewport, |
| 1617 // but has a huge negative position. | 1619 // but has a huge negative position. |
| 1618 child->SetPosition(gfx::PointF()); | 1620 child->SetPosition(gfx::PointF()); |
| 1619 child->SetBounds(gfx::Size(kBigNumber + i, kBigNumber + i)); | 1621 child->SetBounds(gfx::Size(kBigNumber + i, kBigNumber + i)); |
| 1620 child->SetTransform(transform); | 1622 child->SetTransform(transform); |
| 1621 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1623 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 1622 EmulateDrawingOneFrame(root); | 1624 EmulateDrawingOneFrame(root); |
| 1623 | 1625 |
| 1624 // The expected damage should cover the visible part of the child layer, | 1626 // The expected damage should cover the visible part of the child layer, |
| 1625 // which is (0, 0, i, i) in the viewport. | 1627 // which is (0, 0, i, i) in the viewport. |
| 1626 gfx::Rect root_damage_rect = | 1628 gfx::Rect root_damage_rect = |
| 1627 root->render_surface()->damage_tracker()->current_damage_rect(); | 1629 root->render_surface()->damage_tracker()->current_damage_rect(); |
| 1628 gfx::Rect damage_we_care_about = gfx::Rect(i, i); | 1630 gfx::Rect damage_we_care_about = gfx::Rect(i, i); |
| 1629 EXPECT_LE(damage_we_care_about.right(), root_damage_rect.right()); | 1631 EXPECT_LE(damage_we_care_about.right(), root_damage_rect.right()); |
| 1630 EXPECT_LE(damage_we_care_about.bottom(), root_damage_rect.bottom()); | 1632 EXPECT_LE(damage_we_care_about.bottom(), root_damage_rect.bottom()); |
| 1631 } | 1633 } |
| 1632 } | 1634 } |
| 1633 | 1635 |
| 1634 } // namespace | 1636 } // namespace |
| 1635 } // namespace cc | 1637 } // namespace cc |
| OLD | NEW |