| 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 "cc/base/math_util.h" | 7 #include "cc/base/math_util.h" |
| 8 #include "cc/layers/layer_impl.h" | 8 #include "cc/layers/layer_impl.h" |
| 9 #include "cc/output/filter_operation.h" | 9 #include "cc/output/filter_operation.h" |
| 10 #include "cc/output/filter_operations.h" | 10 #include "cc/output/filter_operations.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 root, root->bounds(), render_surface_layer_list); | 37 root, root->bounds(), render_surface_layer_list); |
| 38 LayerTreeHostCommon::CalculateDrawProperties(&inputs); | 38 LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
| 39 } | 39 } |
| 40 | 40 |
| 41 void ClearDamageForAllSurfaces(LayerImpl* layer) { | 41 void ClearDamageForAllSurfaces(LayerImpl* layer) { |
| 42 if (layer->render_surface()) | 42 if (layer->render_surface()) |
| 43 layer->render_surface()->damage_tracker()->DidDrawDamagedArea(); | 43 layer->render_surface()->damage_tracker()->DidDrawDamagedArea(); |
| 44 | 44 |
| 45 // Recursively clear damage for any existing surface. | 45 // Recursively clear damage for any existing surface. |
| 46 for (size_t i = 0; i < layer->children().size(); ++i) | 46 for (size_t i = 0; i < layer->children().size(); ++i) |
| 47 ClearDamageForAllSurfaces(layer->children()[i]); | 47 ClearDamageForAllSurfaces(layer->children()[i].get()); |
| 48 } | 48 } |
| 49 | 49 |
| 50 void EmulateDrawingOneFrame(LayerImpl* root) { | 50 void EmulateDrawingOneFrame(LayerImpl* root) { |
| 51 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 51 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 52 // This emulates only steps that are relevant to testing the damage tracker: | 52 // This emulates only steps that are relevant to testing the damage tracker: |
| 53 // 1. computing the render passes and layerlists | 53 // 1. computing the render passes and layerlists |
| 54 // 2. updating all damage trackers in the correct order | 54 // 2. updating all damage trackers in the correct order |
| 55 // 3. resetting all update_rects and property_changed flags for all layers | 55 // 3. resetting all update_rects and property_changed flags for all layers |
| 56 // and surfaces. | 56 // and surfaces. |
| 57 | 57 |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 | 195 |
| 196 EXPECT_EQ(gfx::Rect(500, 500).ToString(), root_damage_rect.ToString()); | 196 EXPECT_EQ(gfx::Rect(500, 500).ToString(), root_damage_rect.ToString()); |
| 197 } | 197 } |
| 198 | 198 |
| 199 TEST_F(DamageTrackerTest, SanityCheckTestTreeWithTwoSurfaces) { | 199 TEST_F(DamageTrackerTest, SanityCheckTestTreeWithTwoSurfaces) { |
| 200 // Sanity check that the complex test tree will actually produce the expected | 200 // Sanity check that the complex test tree will actually produce the expected |
| 201 // render surfaces and layer lists. | 201 // render surfaces and layer lists. |
| 202 | 202 |
| 203 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 203 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
| 204 | 204 |
| 205 LayerImpl* child1 = root->children()[0]; | 205 LayerImpl* child1 = root->children()[0].get(); |
| 206 LayerImpl* child2 = root->children()[1]; | 206 LayerImpl* child2 = root->children()[1].get(); |
| 207 gfx::Rect child_damage_rect = | 207 gfx::Rect child_damage_rect = |
| 208 child1->render_surface()->damage_tracker()->current_damage_rect(); | 208 child1->render_surface()->damage_tracker()->current_damage_rect(); |
| 209 gfx::Rect root_damage_rect = | 209 gfx::Rect root_damage_rect = |
| 210 root->render_surface()->damage_tracker()->current_damage_rect(); | 210 root->render_surface()->damage_tracker()->current_damage_rect(); |
| 211 | 211 |
| 212 ASSERT_TRUE(child1->render_surface()); | 212 ASSERT_TRUE(child1->render_surface()); |
| 213 EXPECT_FALSE(child2->render_surface()); | 213 EXPECT_FALSE(child2->render_surface()); |
| 214 EXPECT_EQ(3u, root->render_surface()->layer_list().size()); | 214 EXPECT_EQ(3u, root->render_surface()->layer_list().size()); |
| 215 EXPECT_EQ(2u, child1->render_surface()->layer_list().size()); | 215 EXPECT_EQ(2u, child1->render_surface()->layer_list().size()); |
| 216 | 216 |
| 217 // The render surface for child1 only has a content_rect that encloses | 217 // The render surface for child1 only has a content_rect that encloses |
| 218 // grand_child1 and grand_child2, because child1 does not draw content. | 218 // grand_child1 and grand_child2, because child1 does not draw content. |
| 219 EXPECT_EQ(gfx::Rect(190, 190, 16, 18).ToString(), | 219 EXPECT_EQ(gfx::Rect(190, 190, 16, 18).ToString(), |
| 220 child_damage_rect.ToString()); | 220 child_damage_rect.ToString()); |
| 221 EXPECT_EQ(gfx::Rect(500, 500).ToString(), root_damage_rect.ToString()); | 221 EXPECT_EQ(gfx::Rect(500, 500).ToString(), root_damage_rect.ToString()); |
| 222 } | 222 } |
| 223 | 223 |
| 224 TEST_F(DamageTrackerTest, VerifyDamageForUpdateRects) { | 224 TEST_F(DamageTrackerTest, VerifyDamageForUpdateRects) { |
| 225 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithOneSurface(); | 225 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithOneSurface(); |
| 226 LayerImpl* child = root->children()[0]; | 226 LayerImpl* child = root->children()[0].get(); |
| 227 | 227 |
| 228 // CASE 1: Setting the update rect should cause the corresponding damage to | 228 // CASE 1: Setting the update rect should cause the corresponding damage to |
| 229 // the surface. | 229 // the surface. |
| 230 ClearDamageForAllSurfaces(root.get()); | 230 ClearDamageForAllSurfaces(root.get()); |
| 231 child->SetUpdateRect(gfx::Rect(10, 11, 12, 13)); | 231 child->SetUpdateRect(gfx::Rect(10, 11, 12, 13)); |
| 232 EmulateDrawingOneFrame(root.get()); | 232 EmulateDrawingOneFrame(root.get()); |
| 233 | 233 |
| 234 // Damage position on the surface should be: position of update_rect (10, 11) | 234 // Damage position on the surface should be: position of update_rect (10, 11) |
| 235 // relative to the child (100, 100). | 235 // relative to the child (100, 100). |
| 236 gfx::Rect root_damage_rect = | 236 gfx::Rect root_damage_rect = |
| (...skipping 19 matching lines...) Expand all Loading... |
| 256 | 256 |
| 257 // Damage position on the surface should be: position of update_rect (20, 25) | 257 // Damage position on the surface should be: position of update_rect (20, 25) |
| 258 // relative to the child (100, 100). | 258 // relative to the child (100, 100). |
| 259 root_damage_rect = | 259 root_damage_rect = |
| 260 root->render_surface()->damage_tracker()->current_damage_rect(); | 260 root->render_surface()->damage_tracker()->current_damage_rect(); |
| 261 EXPECT_EQ(gfx::Rect(120, 125, 1, 2).ToString(), root_damage_rect.ToString()); | 261 EXPECT_EQ(gfx::Rect(120, 125, 1, 2).ToString(), root_damage_rect.ToString()); |
| 262 } | 262 } |
| 263 | 263 |
| 264 TEST_F(DamageTrackerTest, VerifyDamageForLayerDamageRects) { | 264 TEST_F(DamageTrackerTest, VerifyDamageForLayerDamageRects) { |
| 265 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithOneSurface(); | 265 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithOneSurface(); |
| 266 LayerImpl* child = root->children()[0]; | 266 LayerImpl* child = root->children()[0].get(); |
| 267 | 267 |
| 268 // CASE 1: Adding the layer damage rect should cause the corresponding damage | 268 // CASE 1: Adding the layer damage rect should cause the corresponding damage |
| 269 // to the surface. | 269 // to the surface. |
| 270 ClearDamageForAllSurfaces(root.get()); | 270 ClearDamageForAllSurfaces(root.get()); |
| 271 child->AddDamageRect(gfx::Rect(10, 11, 12, 13)); | 271 child->AddDamageRect(gfx::Rect(10, 11, 12, 13)); |
| 272 EmulateDrawingOneFrame(root.get()); | 272 EmulateDrawingOneFrame(root.get()); |
| 273 | 273 |
| 274 // Damage position on the surface should be: position of layer damage_rect | 274 // Damage position on the surface should be: position of layer damage_rect |
| 275 // (10, 11) relative to the child (100, 100). | 275 // (10, 11) relative to the child (100, 100). |
| 276 gfx::Rect root_damage_rect = | 276 gfx::Rect root_damage_rect = |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 // Damage position on the surface should be: position of layer damage_rect | 308 // Damage position on the surface should be: position of layer damage_rect |
| 309 // (20, 25) relative to the child (100, 100). | 309 // (20, 25) relative to the child (100, 100). |
| 310 root_damage_rect = | 310 root_damage_rect = |
| 311 root->render_surface()->damage_tracker()->current_damage_rect(); | 311 root->render_surface()->damage_tracker()->current_damage_rect(); |
| 312 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(120, 125, 1, 2))); | 312 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(120, 125, 1, 2))); |
| 313 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(110, 115, 3, 4))); | 313 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(110, 115, 3, 4))); |
| 314 } | 314 } |
| 315 | 315 |
| 316 TEST_F(DamageTrackerTest, VerifyDamageForLayerUpdateAndDamageRects) { | 316 TEST_F(DamageTrackerTest, VerifyDamageForLayerUpdateAndDamageRects) { |
| 317 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithOneSurface(); | 317 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithOneSurface(); |
| 318 LayerImpl* child = root->children()[0]; | 318 LayerImpl* child = root->children()[0].get(); |
| 319 | 319 |
| 320 // CASE 1: Adding the layer damage rect and update rect should cause the | 320 // CASE 1: Adding the layer damage rect and update rect should cause the |
| 321 // corresponding damage to the surface. | 321 // corresponding damage to the surface. |
| 322 ClearDamageForAllSurfaces(root.get()); | 322 ClearDamageForAllSurfaces(root.get()); |
| 323 child->AddDamageRect(gfx::Rect(5, 6, 12, 13)); | 323 child->AddDamageRect(gfx::Rect(5, 6, 12, 13)); |
| 324 child->SetUpdateRect(gfx::Rect(15, 16, 14, 10)); | 324 child->SetUpdateRect(gfx::Rect(15, 16, 14, 10)); |
| 325 EmulateDrawingOneFrame(root.get()); | 325 EmulateDrawingOneFrame(root.get()); |
| 326 | 326 |
| 327 // Damage position on the surface should be: position of unified layer | 327 // Damage position on the surface should be: position of unified layer |
| 328 // damage_rect and update rect (5, 6) | 328 // damage_rect and update rect (5, 6) |
| (...skipping 21 matching lines...) Expand all Loading... |
| 350 | 350 |
| 351 // Damage position on the surface should be: position of unified layer damage | 351 // Damage position on the surface should be: position of unified layer damage |
| 352 // rect and update rect (5, 10) relative to the child (100, 100). | 352 // rect and update rect (5, 10) relative to the child (100, 100). |
| 353 root_damage_rect = | 353 root_damage_rect = |
| 354 root->render_surface()->damage_tracker()->current_damage_rect(); | 354 root->render_surface()->damage_tracker()->current_damage_rect(); |
| 355 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(105, 110, 17, 18))); | 355 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(105, 110, 17, 18))); |
| 356 } | 356 } |
| 357 | 357 |
| 358 TEST_F(DamageTrackerTest, VerifyDamageForPropertyChanges) { | 358 TEST_F(DamageTrackerTest, VerifyDamageForPropertyChanges) { |
| 359 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithOneSurface(); | 359 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithOneSurface(); |
| 360 LayerImpl* child = root->children()[0]; | 360 LayerImpl* child = root->children()[0].get(); |
| 361 | 361 |
| 362 // CASE 1: The layer's property changed flag takes priority over update rect. | 362 // CASE 1: The layer's property changed flag takes priority over update rect. |
| 363 // | 363 // |
| 364 ClearDamageForAllSurfaces(root.get()); | 364 ClearDamageForAllSurfaces(root.get()); |
| 365 child->SetUpdateRect(gfx::Rect(10, 11, 12, 13)); | 365 child->SetUpdateRect(gfx::Rect(10, 11, 12, 13)); |
| 366 child->SetOpacity(0.5f); | 366 child->SetOpacity(0.5f); |
| 367 EmulateDrawingOneFrame(root.get()); | 367 EmulateDrawingOneFrame(root.get()); |
| 368 | 368 |
| 369 // Sanity check - we should not have accidentally created a separate render | 369 // Sanity check - we should not have accidentally created a separate render |
| 370 // surface for the translucent layer. | 370 // surface for the translucent layer. |
| (...skipping 28 matching lines...) Expand all Loading... |
| 399 root_damage_rect = | 399 root_damage_rect = |
| 400 root->render_surface()->damage_tracker()->current_damage_rect(); | 400 root->render_surface()->damage_tracker()->current_damage_rect(); |
| 401 EXPECT_FLOAT_RECT_EQ(expected_rect, root_damage_rect); | 401 EXPECT_FLOAT_RECT_EQ(expected_rect, root_damage_rect); |
| 402 } | 402 } |
| 403 | 403 |
| 404 TEST_F(DamageTrackerTest, VerifyDamageForTransformedLayer) { | 404 TEST_F(DamageTrackerTest, VerifyDamageForTransformedLayer) { |
| 405 // If a layer is transformed, the damage rect should still enclose the entire | 405 // If a layer is transformed, the damage rect should still enclose the entire |
| 406 // transformed layer. | 406 // transformed layer. |
| 407 | 407 |
| 408 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithOneSurface(); | 408 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithOneSurface(); |
| 409 LayerImpl* child = root->children()[0]; | 409 LayerImpl* child = root->children()[0].get(); |
| 410 | 410 |
| 411 gfx::Transform rotation; | 411 gfx::Transform rotation; |
| 412 rotation.Rotate(45.0); | 412 rotation.Rotate(45.0); |
| 413 | 413 |
| 414 ClearDamageForAllSurfaces(root.get()); | 414 ClearDamageForAllSurfaces(root.get()); |
| 415 child->SetTransformOrigin(gfx::Point3F( | 415 child->SetTransformOrigin(gfx::Point3F( |
| 416 child->bounds().width() * 0.5f, child->bounds().height() * 0.5f, 0.f)); | 416 child->bounds().width() * 0.5f, child->bounds().height() * 0.5f, 0.f)); |
| 417 child->SetPosition(gfx::PointF(85.f, 85.f)); | 417 child->SetPosition(gfx::PointF(85.f, 85.f)); |
| 418 EmulateDrawingOneFrame(root.get()); | 418 EmulateDrawingOneFrame(root.get()); |
| 419 | 419 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 449 // | 449 // |
| 450 // The transform is constructed so that if w < 0 clipping is not performed, | 450 // The transform is constructed so that if w < 0 clipping is not performed, |
| 451 // the incorrect rect will be very small, specifically: position (500.972504, | 451 // the incorrect rect will be very small, specifically: position (500.972504, |
| 452 // 498.544617) and size 0.056610 x 2.910767. Instead, the correctly | 452 // 498.544617) and size 0.056610 x 2.910767. Instead, the correctly |
| 453 // transformed rect should actually be very huge (i.e. in theory, -infinity | 453 // transformed rect should actually be very huge (i.e. in theory, -infinity |
| 454 // on the left), and positioned so that the right-most bound rect will be | 454 // on the left), and positioned so that the right-most bound rect will be |
| 455 // approximately 501 units in root surface space. | 455 // approximately 501 units in root surface space. |
| 456 // | 456 // |
| 457 | 457 |
| 458 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithOneSurface(); | 458 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithOneSurface(); |
| 459 LayerImpl* child = root->children()[0]; | 459 LayerImpl* child = root->children()[0].get(); |
| 460 | 460 |
| 461 gfx::Transform transform; | 461 gfx::Transform transform; |
| 462 transform.Translate3d(500.0, 500.0, 0.0); | 462 transform.Translate3d(500.0, 500.0, 0.0); |
| 463 transform.ApplyPerspectiveDepth(1.0); | 463 transform.ApplyPerspectiveDepth(1.0); |
| 464 transform.RotateAboutYAxis(45.0); | 464 transform.RotateAboutYAxis(45.0); |
| 465 transform.Translate3d(-50.0, -50.0, 0.0); | 465 transform.Translate3d(-50.0, -50.0, 0.0); |
| 466 | 466 |
| 467 // Set up the child | 467 // Set up the child |
| 468 child->SetPosition(gfx::PointF(0.f, 0.f)); | 468 child->SetPosition(gfx::PointF(0.f, 0.f)); |
| 469 child->SetBounds(gfx::Size(100, 100)); | 469 child->SetBounds(gfx::Size(100, 100)); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 486 // don't care whether the damage rect was clamped or is larger than the | 486 // don't care whether the damage rect was clamped or is larger than the |
| 487 // surface for this test. | 487 // surface for this test. |
| 488 gfx::Rect root_damage_rect = | 488 gfx::Rect root_damage_rect = |
| 489 root->render_surface()->damage_tracker()->current_damage_rect(); | 489 root->render_surface()->damage_tracker()->current_damage_rect(); |
| 490 gfx::Rect damage_we_care_about = gfx::Rect(gfx::Size(500, 500)); | 490 gfx::Rect damage_we_care_about = gfx::Rect(gfx::Size(500, 500)); |
| 491 EXPECT_TRUE(root_damage_rect.Contains(damage_we_care_about)); | 491 EXPECT_TRUE(root_damage_rect.Contains(damage_we_care_about)); |
| 492 } | 492 } |
| 493 | 493 |
| 494 TEST_F(DamageTrackerTest, VerifyDamageForBlurredSurface) { | 494 TEST_F(DamageTrackerTest, VerifyDamageForBlurredSurface) { |
| 495 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 495 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
| 496 LayerImpl* surface = root->children()[0]; | 496 LayerImpl* surface = root->children()[0].get(); |
| 497 LayerImpl* child = surface->children()[0]; | 497 LayerImpl* child = surface->children()[0].get(); |
| 498 | 498 |
| 499 FilterOperations filters; | 499 FilterOperations filters; |
| 500 filters.Append(FilterOperation::CreateBlurFilter(5.f)); | 500 filters.Append(FilterOperation::CreateBlurFilter(5.f)); |
| 501 int outset_top, outset_right, outset_bottom, outset_left; | 501 int outset_top, outset_right, outset_bottom, outset_left; |
| 502 filters.GetOutsets(&outset_top, &outset_right, &outset_bottom, &outset_left); | 502 filters.GetOutsets(&outset_top, &outset_right, &outset_bottom, &outset_left); |
| 503 | 503 |
| 504 // Setting the filter will damage the whole surface. | 504 // Setting the filter will damage the whole surface. |
| 505 ClearDamageForAllSurfaces(root.get()); | 505 ClearDamageForAllSurfaces(root.get()); |
| 506 surface->SetFilters(filters); | 506 surface->SetFilters(filters); |
| 507 EmulateDrawingOneFrame(root.get()); | 507 EmulateDrawingOneFrame(root.get()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 520 | 520 |
| 521 expected_damage_rect.Inset(-outset_left, | 521 expected_damage_rect.Inset(-outset_left, |
| 522 -outset_top, | 522 -outset_top, |
| 523 -outset_right, | 523 -outset_right, |
| 524 -outset_bottom); | 524 -outset_bottom); |
| 525 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString()); | 525 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString()); |
| 526 } | 526 } |
| 527 | 527 |
| 528 TEST_F(DamageTrackerTest, VerifyDamageForImageFilter) { | 528 TEST_F(DamageTrackerTest, VerifyDamageForImageFilter) { |
| 529 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithOneSurface(); | 529 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithOneSurface(); |
| 530 LayerImpl* child = root->children()[0]; | 530 LayerImpl* child = root->children()[0].get(); |
| 531 gfx::Rect root_damage_rect, child_damage_rect; | 531 gfx::Rect root_damage_rect, child_damage_rect; |
| 532 | 532 |
| 533 // Allow us to set damage on child too. | 533 // Allow us to set damage on child too. |
| 534 child->SetDrawsContent(true); | 534 child->SetDrawsContent(true); |
| 535 | 535 |
| 536 skia::RefPtr<SkImageFilter> filter = skia::AdoptRef( | 536 skia::RefPtr<SkImageFilter> filter = skia::AdoptRef( |
| 537 SkBlurImageFilter::Create(SkIntToScalar(2), SkIntToScalar(2))); | 537 SkBlurImageFilter::Create(SkIntToScalar(2), SkIntToScalar(2))); |
| 538 FilterOperations filters; | 538 FilterOperations filters; |
| 539 filters.Append(FilterOperation::CreateReferenceFilter(filter)); | 539 filters.Append(FilterOperation::CreateReferenceFilter(filter)); |
| 540 int outset_top, outset_right, outset_bottom, outset_left; | 540 int outset_top, outset_right, outset_bottom, outset_left; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 expect_height) | 573 expect_height) |
| 574 .ToString(), | 574 .ToString(), |
| 575 root_damage_rect.ToString()); | 575 root_damage_rect.ToString()); |
| 576 EXPECT_EQ(gfx::Rect(-outset_left, -outset_top, expect_width, expect_height) | 576 EXPECT_EQ(gfx::Rect(-outset_left, -outset_top, expect_width, expect_height) |
| 577 .ToString(), | 577 .ToString(), |
| 578 child_damage_rect.ToString()); | 578 child_damage_rect.ToString()); |
| 579 } | 579 } |
| 580 | 580 |
| 581 TEST_F(DamageTrackerTest, VerifyDamageForBackgroundBlurredChild) { | 581 TEST_F(DamageTrackerTest, VerifyDamageForBackgroundBlurredChild) { |
| 582 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 582 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
| 583 LayerImpl* child1 = root->children()[0]; | 583 LayerImpl* child1 = root->children()[0].get(); |
| 584 LayerImpl* child2 = root->children()[1]; | 584 LayerImpl* child2 = root->children()[1].get(); |
| 585 | 585 |
| 586 // Allow us to set damage on child1 too. | 586 // Allow us to set damage on child1 too. |
| 587 child1->SetDrawsContent(true); | 587 child1->SetDrawsContent(true); |
| 588 | 588 |
| 589 FilterOperations filters; | 589 FilterOperations filters; |
| 590 filters.Append(FilterOperation::CreateBlurFilter(2.f)); | 590 filters.Append(FilterOperation::CreateBlurFilter(2.f)); |
| 591 int outset_top, outset_right, outset_bottom, outset_left; | 591 int outset_top, outset_right, outset_bottom, outset_left; |
| 592 filters.GetOutsets(&outset_top, &outset_right, &outset_bottom, &outset_left); | 592 filters.GetOutsets(&outset_top, &outset_right, &outset_bottom, &outset_left); |
| 593 | 593 |
| 594 // Setting the filter will damage the whole surface. | 594 // Setting the filter will damage the whole surface. |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 700 | 700 |
| 701 expected_damage_rect.Inset(-outset_left, | 701 expected_damage_rect.Inset(-outset_left, |
| 702 -outset_top, | 702 -outset_top, |
| 703 -outset_right, | 703 -outset_right, |
| 704 -outset_bottom); | 704 -outset_bottom); |
| 705 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString()); | 705 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString()); |
| 706 } | 706 } |
| 707 | 707 |
| 708 TEST_F(DamageTrackerTest, VerifyDamageForAddingAndRemovingLayer) { | 708 TEST_F(DamageTrackerTest, VerifyDamageForAddingAndRemovingLayer) { |
| 709 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithOneSurface(); | 709 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithOneSurface(); |
| 710 LayerImpl* child1 = root->children()[0]; | 710 LayerImpl* child1 = root->children()[0].get(); |
| 711 | 711 |
| 712 // CASE 1: Adding a new layer should cause the appropriate damage. | 712 // CASE 1: Adding a new layer should cause the appropriate damage. |
| 713 // | 713 // |
| 714 ClearDamageForAllSurfaces(root.get()); | 714 ClearDamageForAllSurfaces(root.get()); |
| 715 { | 715 { |
| 716 scoped_ptr<LayerImpl> child2 = | 716 scoped_ptr<LayerImpl> child2 = |
| 717 LayerImpl::Create(host_impl_.active_tree(), 3); | 717 LayerImpl::Create(host_impl_.active_tree(), 3); |
| 718 child2->SetPosition(gfx::PointF(400.f, 380.f)); | 718 child2->SetPosition(gfx::PointF(400.f, 380.f)); |
| 719 child2->SetBounds(gfx::Size(6, 8)); | 719 child2->SetBounds(gfx::Size(6, 8)); |
| 720 child2->SetDrawsContent(true); | 720 child2->SetDrawsContent(true); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 780 // surfaces are tested elsewhere. | 780 // surfaces are tested elsewhere. |
| 781 ASSERT_EQ(3u, root->render_surface()->layer_list().size()); | 781 ASSERT_EQ(3u, root->render_surface()->layer_list().size()); |
| 782 | 782 |
| 783 gfx::Rect root_damage_rect = | 783 gfx::Rect root_damage_rect = |
| 784 root->render_surface()->damage_tracker()->current_damage_rect(); | 784 root->render_surface()->damage_tracker()->current_damage_rect(); |
| 785 EXPECT_EQ(gfx::Rect(400, 380, 6, 8).ToString(), root_damage_rect.ToString()); | 785 EXPECT_EQ(gfx::Rect(400, 380, 6, 8).ToString(), root_damage_rect.ToString()); |
| 786 } | 786 } |
| 787 | 787 |
| 788 TEST_F(DamageTrackerTest, VerifyDamageForMultipleLayers) { | 788 TEST_F(DamageTrackerTest, VerifyDamageForMultipleLayers) { |
| 789 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithOneSurface(); | 789 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithOneSurface(); |
| 790 LayerImpl* child1 = root->children()[0]; | 790 LayerImpl* child1 = root->children()[0].get(); |
| 791 | 791 |
| 792 // In this test we don't want the above tree manipulation to be considered | 792 // In this test we don't want the above tree manipulation to be considered |
| 793 // part of the same frame. | 793 // part of the same frame. |
| 794 ClearDamageForAllSurfaces(root.get()); | 794 ClearDamageForAllSurfaces(root.get()); |
| 795 { | 795 { |
| 796 scoped_ptr<LayerImpl> child2 = | 796 scoped_ptr<LayerImpl> child2 = |
| 797 LayerImpl::Create(host_impl_.active_tree(), 3); | 797 LayerImpl::Create(host_impl_.active_tree(), 3); |
| 798 child2->SetPosition(gfx::PointF(400.f, 380.f)); | 798 child2->SetPosition(gfx::PointF(400.f, 380.f)); |
| 799 child2->SetBounds(gfx::Size(6, 8)); | 799 child2->SetBounds(gfx::Size(6, 8)); |
| 800 child2->SetDrawsContent(true); | 800 child2->SetDrawsContent(true); |
| 801 root->AddChild(child2.Pass()); | 801 root->AddChild(child2.Pass()); |
| 802 } | 802 } |
| 803 LayerImpl* child2 = root->children()[1]; | 803 LayerImpl* child2 = root->children()[1].get(); |
| 804 EmulateDrawingOneFrame(root.get()); | 804 EmulateDrawingOneFrame(root.get()); |
| 805 | 805 |
| 806 // Damaging two layers simultaneously should cause combined damage. | 806 // Damaging two layers simultaneously should cause combined damage. |
| 807 // - child1 update rect in surface space: gfx::Rect(100, 100, 1, 2); | 807 // - child1 update rect in surface space: gfx::Rect(100, 100, 1, 2); |
| 808 // - child2 update rect in surface space: gfx::Rect(400, 380, 3, 4); | 808 // - child2 update rect in surface space: gfx::Rect(400, 380, 3, 4); |
| 809 ClearDamageForAllSurfaces(root.get()); | 809 ClearDamageForAllSurfaces(root.get()); |
| 810 child1->SetUpdateRect(gfx::Rect(1, 2)); | 810 child1->SetUpdateRect(gfx::Rect(1, 2)); |
| 811 child2->SetUpdateRect(gfx::Rect(3, 4)); | 811 child2->SetUpdateRect(gfx::Rect(3, 4)); |
| 812 EmulateDrawingOneFrame(root.get()); | 812 EmulateDrawingOneFrame(root.get()); |
| 813 gfx::Rect root_damage_rect = | 813 gfx::Rect root_damage_rect = |
| 814 root->render_surface()->damage_tracker()->current_damage_rect(); | 814 root->render_surface()->damage_tracker()->current_damage_rect(); |
| 815 EXPECT_EQ(gfx::Rect(100, 100, 303, 284).ToString(), | 815 EXPECT_EQ(gfx::Rect(100, 100, 303, 284).ToString(), |
| 816 root_damage_rect.ToString()); | 816 root_damage_rect.ToString()); |
| 817 } | 817 } |
| 818 | 818 |
| 819 TEST_F(DamageTrackerTest, VerifyDamageForNestedSurfaces) { | 819 TEST_F(DamageTrackerTest, VerifyDamageForNestedSurfaces) { |
| 820 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 820 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
| 821 LayerImpl* child1 = root->children()[0]; | 821 LayerImpl* child1 = root->children()[0].get(); |
| 822 LayerImpl* child2 = root->children()[1]; | 822 LayerImpl* child2 = root->children()[1].get(); |
| 823 LayerImpl* grand_child1 = root->children()[0]->children()[0]; | 823 LayerImpl* grand_child1 = root->children()[0]->children()[0].get(); |
| 824 gfx::Rect child_damage_rect; | 824 gfx::Rect child_damage_rect; |
| 825 gfx::Rect root_damage_rect; | 825 gfx::Rect root_damage_rect; |
| 826 | 826 |
| 827 // CASE 1: Damage to a descendant surface should propagate properly to | 827 // CASE 1: Damage to a descendant surface should propagate properly to |
| 828 // ancestor surface. | 828 // ancestor surface. |
| 829 ClearDamageForAllSurfaces(root.get()); | 829 ClearDamageForAllSurfaces(root.get()); |
| 830 grand_child1->SetOpacity(0.5f); | 830 grand_child1->SetOpacity(0.5f); |
| 831 EmulateDrawingOneFrame(root.get()); | 831 EmulateDrawingOneFrame(root.get()); |
| 832 child_damage_rect = | 832 child_damage_rect = |
| 833 child1->render_surface()->damage_tracker()->current_damage_rect(); | 833 child1->render_surface()->damage_tracker()->current_damage_rect(); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 857 | 857 |
| 858 TEST_F(DamageTrackerTest, VerifyDamageForSurfaceChangeFromDescendantLayer) { | 858 TEST_F(DamageTrackerTest, VerifyDamageForSurfaceChangeFromDescendantLayer) { |
| 859 // If descendant layer changes and affects the content bounds of the render | 859 // If descendant layer changes and affects the content bounds of the render |
| 860 // surface, then the entire descendant surface should be damaged, and it | 860 // surface, then the entire descendant surface should be damaged, and it |
| 861 // should damage its ancestor surface with the old and new surface regions. | 861 // should damage its ancestor surface with the old and new surface regions. |
| 862 | 862 |
| 863 // This is a tricky case, since only the first grand_child changes, but the | 863 // This is a tricky case, since only the first grand_child changes, but the |
| 864 // entire surface should be marked dirty. | 864 // entire surface should be marked dirty. |
| 865 | 865 |
| 866 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 866 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
| 867 LayerImpl* child1 = root->children()[0]; | 867 LayerImpl* child1 = root->children()[0].get(); |
| 868 LayerImpl* grand_child1 = root->children()[0]->children()[0]; | 868 LayerImpl* grand_child1 = root->children()[0]->children()[0].get(); |
| 869 gfx::Rect child_damage_rect; | 869 gfx::Rect child_damage_rect; |
| 870 gfx::Rect root_damage_rect; | 870 gfx::Rect root_damage_rect; |
| 871 | 871 |
| 872 ClearDamageForAllSurfaces(root.get()); | 872 ClearDamageForAllSurfaces(root.get()); |
| 873 grand_child1->SetPosition(gfx::PointF(195.f, 205.f)); | 873 grand_child1->SetPosition(gfx::PointF(195.f, 205.f)); |
| 874 EmulateDrawingOneFrame(root.get()); | 874 EmulateDrawingOneFrame(root.get()); |
| 875 child_damage_rect = | 875 child_damage_rect = |
| 876 child1->render_surface()->damage_tracker()->current_damage_rect(); | 876 child1->render_surface()->damage_tracker()->current_damage_rect(); |
| 877 root_damage_rect = | 877 root_damage_rect = |
| 878 root->render_surface()->damage_tracker()->current_damage_rect(); | 878 root->render_surface()->damage_tracker()->current_damage_rect(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 895 // already propagates to the subtree (tested in LayerImpltest), which damages | 895 // already propagates to the subtree (tested in LayerImpltest), which damages |
| 896 // the entire child1 surface, but the damage tracker still needs the correct | 896 // the entire child1 surface, but the damage tracker still needs the correct |
| 897 // logic to compute the exposed region on the root surface. | 897 // logic to compute the exposed region on the root surface. |
| 898 | 898 |
| 899 // TODO(shawnsingh): the expectations of this test case should change when we | 899 // TODO(shawnsingh): the expectations of this test case should change when we |
| 900 // add support for a unique scissor_rect per RenderSurface. In that case, the | 900 // add support for a unique scissor_rect per RenderSurface. In that case, the |
| 901 // child1 surface should be completely unchanged, since we are only | 901 // child1 surface should be completely unchanged, since we are only |
| 902 // transforming it, while the root surface would be damaged appropriately. | 902 // transforming it, while the root surface would be damaged appropriately. |
| 903 | 903 |
| 904 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 904 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
| 905 LayerImpl* child1 = root->children()[0]; | 905 LayerImpl* child1 = root->children()[0].get(); |
| 906 gfx::Rect child_damage_rect; | 906 gfx::Rect child_damage_rect; |
| 907 gfx::Rect root_damage_rect; | 907 gfx::Rect root_damage_rect; |
| 908 | 908 |
| 909 ClearDamageForAllSurfaces(root.get()); | 909 ClearDamageForAllSurfaces(root.get()); |
| 910 child1->SetPosition(gfx::PointF(50.f, 50.f)); | 910 child1->SetPosition(gfx::PointF(50.f, 50.f)); |
| 911 EmulateDrawingOneFrame(root.get()); | 911 EmulateDrawingOneFrame(root.get()); |
| 912 child_damage_rect = | 912 child_damage_rect = |
| 913 child1->render_surface()->damage_tracker()->current_damage_rect(); | 913 child1->render_surface()->damage_tracker()->current_damage_rect(); |
| 914 root_damage_rect = | 914 root_damage_rect = |
| 915 root->render_surface()->damage_tracker()->current_damage_rect(); | 915 root->render_surface()->damage_tracker()->current_damage_rect(); |
| 916 | 916 |
| 917 // The new surface bounds should be damaged entirely. | 917 // The new surface bounds should be damaged entirely. |
| 918 EXPECT_EQ(gfx::Rect(190, 190, 16, 18).ToString(), | 918 EXPECT_EQ(gfx::Rect(190, 190, 16, 18).ToString(), |
| 919 child_damage_rect.ToString()); | 919 child_damage_rect.ToString()); |
| 920 | 920 |
| 921 // The entire child1 surface and the old exposed child1 surface should damage | 921 // The entire child1 surface and the old exposed child1 surface should damage |
| 922 // the root surface. | 922 // the root surface. |
| 923 // - old child1 surface in target space: gfx::Rect(290, 290, 16, 18) | 923 // - old child1 surface in target space: gfx::Rect(290, 290, 16, 18) |
| 924 // - new child1 surface in target space: gfx::Rect(240, 240, 16, 18) | 924 // - new child1 surface in target space: gfx::Rect(240, 240, 16, 18) |
| 925 EXPECT_EQ(gfx::Rect(240, 240, 66, 68).ToString(), | 925 EXPECT_EQ(gfx::Rect(240, 240, 66, 68).ToString(), |
| 926 root_damage_rect.ToString()); | 926 root_damage_rect.ToString()); |
| 927 } | 927 } |
| 928 | 928 |
| 929 TEST_F(DamageTrackerTest, VerifyDamageForAddingAndRemovingRenderSurfaces) { | 929 TEST_F(DamageTrackerTest, VerifyDamageForAddingAndRemovingRenderSurfaces) { |
| 930 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 930 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
| 931 LayerImpl* child1 = root->children()[0]; | 931 LayerImpl* child1 = root->children()[0].get(); |
| 932 gfx::Rect child_damage_rect; | 932 gfx::Rect child_damage_rect; |
| 933 gfx::Rect root_damage_rect; | 933 gfx::Rect root_damage_rect; |
| 934 | 934 |
| 935 // CASE 1: If a descendant surface disappears, its entire old area becomes | 935 // CASE 1: If a descendant surface disappears, its entire old area becomes |
| 936 // exposed. | 936 // exposed. |
| 937 ClearDamageForAllSurfaces(root.get()); | 937 ClearDamageForAllSurfaces(root.get()); |
| 938 child1->SetHasRenderSurface(false); | 938 child1->SetHasRenderSurface(false); |
| 939 EmulateDrawingOneFrame(root.get()); | 939 EmulateDrawingOneFrame(root.get()); |
| 940 | 940 |
| 941 // Sanity check that there is only one surface now. | 941 // Sanity check that there is only one surface now. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 974 root_damage_rect = | 974 root_damage_rect = |
| 975 root->render_surface()->damage_tracker()->current_damage_rect(); | 975 root->render_surface()->damage_tracker()->current_damage_rect(); |
| 976 EXPECT_EQ(gfx::Rect(190, 190, 16, 18).ToString(), | 976 EXPECT_EQ(gfx::Rect(190, 190, 16, 18).ToString(), |
| 977 child_damage_rect.ToString()); | 977 child_damage_rect.ToString()); |
| 978 EXPECT_EQ(gfx::Rect(290, 290, 16, 18).ToString(), | 978 EXPECT_EQ(gfx::Rect(290, 290, 16, 18).ToString(), |
| 979 root_damage_rect.ToString()); | 979 root_damage_rect.ToString()); |
| 980 } | 980 } |
| 981 | 981 |
| 982 TEST_F(DamageTrackerTest, VerifyNoDamageWhenNothingChanged) { | 982 TEST_F(DamageTrackerTest, VerifyNoDamageWhenNothingChanged) { |
| 983 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 983 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
| 984 LayerImpl* child1 = root->children()[0]; | 984 LayerImpl* child1 = root->children()[0].get(); |
| 985 gfx::Rect child_damage_rect; | 985 gfx::Rect child_damage_rect; |
| 986 gfx::Rect root_damage_rect; | 986 gfx::Rect root_damage_rect; |
| 987 | 987 |
| 988 // CASE 1: If nothing changes, the damage rect should be empty. | 988 // CASE 1: If nothing changes, the damage rect should be empty. |
| 989 // | 989 // |
| 990 ClearDamageForAllSurfaces(root.get()); | 990 ClearDamageForAllSurfaces(root.get()); |
| 991 EmulateDrawingOneFrame(root.get()); | 991 EmulateDrawingOneFrame(root.get()); |
| 992 child_damage_rect = | 992 child_damage_rect = |
| 993 child1->render_surface()->damage_tracker()->current_damage_rect(); | 993 child1->render_surface()->damage_tracker()->current_damage_rect(); |
| 994 root_damage_rect = | 994 root_damage_rect = |
| 995 root->render_surface()->damage_tracker()->current_damage_rect(); | 995 root->render_surface()->damage_tracker()->current_damage_rect(); |
| 996 EXPECT_TRUE(child_damage_rect.IsEmpty()); | 996 EXPECT_TRUE(child_damage_rect.IsEmpty()); |
| 997 EXPECT_TRUE(root_damage_rect.IsEmpty()); | 997 EXPECT_TRUE(root_damage_rect.IsEmpty()); |
| 998 | 998 |
| 999 // CASE 2: If nothing changes twice in a row, the damage rect should still be | 999 // CASE 2: If nothing changes twice in a row, the damage rect should still be |
| 1000 // empty. | 1000 // empty. |
| 1001 // | 1001 // |
| 1002 ClearDamageForAllSurfaces(root.get()); | 1002 ClearDamageForAllSurfaces(root.get()); |
| 1003 EmulateDrawingOneFrame(root.get()); | 1003 EmulateDrawingOneFrame(root.get()); |
| 1004 child_damage_rect = | 1004 child_damage_rect = |
| 1005 child1->render_surface()->damage_tracker()->current_damage_rect(); | 1005 child1->render_surface()->damage_tracker()->current_damage_rect(); |
| 1006 root_damage_rect = | 1006 root_damage_rect = |
| 1007 root->render_surface()->damage_tracker()->current_damage_rect(); | 1007 root->render_surface()->damage_tracker()->current_damage_rect(); |
| 1008 EXPECT_TRUE(child_damage_rect.IsEmpty()); | 1008 EXPECT_TRUE(child_damage_rect.IsEmpty()); |
| 1009 EXPECT_TRUE(root_damage_rect.IsEmpty()); | 1009 EXPECT_TRUE(root_damage_rect.IsEmpty()); |
| 1010 } | 1010 } |
| 1011 | 1011 |
| 1012 TEST_F(DamageTrackerTest, VerifyNoDamageForUpdateRectThatDoesNotDrawContent) { | 1012 TEST_F(DamageTrackerTest, VerifyNoDamageForUpdateRectThatDoesNotDrawContent) { |
| 1013 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 1013 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
| 1014 LayerImpl* child1 = root->children()[0]; | 1014 LayerImpl* child1 = root->children()[0].get(); |
| 1015 gfx::Rect child_damage_rect; | 1015 gfx::Rect child_damage_rect; |
| 1016 gfx::Rect root_damage_rect; | 1016 gfx::Rect root_damage_rect; |
| 1017 | 1017 |
| 1018 // In our specific tree, the update rect of child1 should not cause any | 1018 // In our specific tree, the update rect of child1 should not cause any |
| 1019 // damage to any surface because it does not actually draw content. | 1019 // damage to any surface because it does not actually draw content. |
| 1020 ClearDamageForAllSurfaces(root.get()); | 1020 ClearDamageForAllSurfaces(root.get()); |
| 1021 child1->SetUpdateRect(gfx::Rect(1, 2)); | 1021 child1->SetUpdateRect(gfx::Rect(1, 2)); |
| 1022 EmulateDrawingOneFrame(root.get()); | 1022 EmulateDrawingOneFrame(root.get()); |
| 1023 child_damage_rect = | 1023 child_damage_rect = |
| 1024 child1->render_surface()->damage_tracker()->current_damage_rect(); | 1024 child1->render_surface()->damage_tracker()->current_damage_rect(); |
| 1025 root_damage_rect = | 1025 root_damage_rect = |
| 1026 root->render_surface()->damage_tracker()->current_damage_rect(); | 1026 root->render_surface()->damage_tracker()->current_damage_rect(); |
| 1027 EXPECT_TRUE(child_damage_rect.IsEmpty()); | 1027 EXPECT_TRUE(child_damage_rect.IsEmpty()); |
| 1028 EXPECT_TRUE(root_damage_rect.IsEmpty()); | 1028 EXPECT_TRUE(root_damage_rect.IsEmpty()); |
| 1029 } | 1029 } |
| 1030 | 1030 |
| 1031 TEST_F(DamageTrackerTest, VerifyDamageForReplica) { | 1031 TEST_F(DamageTrackerTest, VerifyDamageForReplica) { |
| 1032 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 1032 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
| 1033 LayerImpl* child1 = root->children()[0]; | 1033 LayerImpl* child1 = root->children()[0].get(); |
| 1034 LayerImpl* grand_child1 = child1->children()[0]; | 1034 LayerImpl* grand_child1 = child1->children()[0].get(); |
| 1035 LayerImpl* grand_child2 = child1->children()[1]; | 1035 LayerImpl* grand_child2 = child1->children()[1].get(); |
| 1036 | 1036 |
| 1037 // Damage on a surface that has a reflection should cause the target surface | 1037 // Damage on a surface that has a reflection should cause the target surface |
| 1038 // to receive the surface's damage and the surface's reflected damage. | 1038 // to receive the surface's damage and the surface's reflected damage. |
| 1039 | 1039 |
| 1040 // For this test case, we modify grand_child2, and add grand_child3 to extend | 1040 // For this test case, we modify grand_child2, and add grand_child3 to extend |
| 1041 // the bounds of child1's surface. This way, we can test reflection changes | 1041 // the bounds of child1's surface. This way, we can test reflection changes |
| 1042 // without changing content_bounds of the surface. | 1042 // without changing content_bounds of the surface. |
| 1043 grand_child2->SetPosition(gfx::PointF(180.f, 180.f)); | 1043 grand_child2->SetPosition(gfx::PointF(180.f, 180.f)); |
| 1044 { | 1044 { |
| 1045 scoped_ptr<LayerImpl> grand_child3 = | 1045 scoped_ptr<LayerImpl> grand_child3 = |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1127 root_damage_rect = | 1127 root_damage_rect = |
| 1128 root->render_surface()->damage_tracker()->current_damage_rect(); | 1128 root->render_surface()->damage_tracker()->current_damage_rect(); |
| 1129 | 1129 |
| 1130 EXPECT_EQ(gfx::Rect(189, 205, 12, 8).ToString(), | 1130 EXPECT_EQ(gfx::Rect(189, 205, 12, 8).ToString(), |
| 1131 child_damage_rect.ToString()); | 1131 child_damage_rect.ToString()); |
| 1132 EXPECT_EQ(gfx::Rect(289, 305, 12, 8).ToString(), root_damage_rect.ToString()); | 1132 EXPECT_EQ(gfx::Rect(289, 305, 12, 8).ToString(), root_damage_rect.ToString()); |
| 1133 } | 1133 } |
| 1134 | 1134 |
| 1135 TEST_F(DamageTrackerTest, VerifyDamageForMask) { | 1135 TEST_F(DamageTrackerTest, VerifyDamageForMask) { |
| 1136 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithOneSurface(); | 1136 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithOneSurface(); |
| 1137 LayerImpl* child = root->children()[0]; | 1137 LayerImpl* child = root->children()[0].get(); |
| 1138 | 1138 |
| 1139 // In the current implementation of the damage tracker, changes to mask | 1139 // In the current implementation of the damage tracker, changes to mask |
| 1140 // layers should damage the entire corresponding surface. | 1140 // layers should damage the entire corresponding surface. |
| 1141 | 1141 |
| 1142 ClearDamageForAllSurfaces(root.get()); | 1142 ClearDamageForAllSurfaces(root.get()); |
| 1143 | 1143 |
| 1144 // Set up the mask layer. | 1144 // Set up the mask layer. |
| 1145 { | 1145 { |
| 1146 scoped_ptr<LayerImpl> mask_layer = | 1146 scoped_ptr<LayerImpl> mask_layer = |
| 1147 LayerImpl::Create(host_impl_.active_tree(), 3); | 1147 LayerImpl::Create(host_impl_.active_tree(), 3); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1213 // Sanity check that a render surface still exists. | 1213 // Sanity check that a render surface still exists. |
| 1214 ASSERT_TRUE(child->render_surface()); | 1214 ASSERT_TRUE(child->render_surface()); |
| 1215 | 1215 |
| 1216 child_damage_rect = | 1216 child_damage_rect = |
| 1217 child->render_surface()->damage_tracker()->current_damage_rect(); | 1217 child->render_surface()->damage_tracker()->current_damage_rect(); |
| 1218 EXPECT_EQ(gfx::Rect(30, 30).ToString(), child_damage_rect.ToString()); | 1218 EXPECT_EQ(gfx::Rect(30, 30).ToString(), child_damage_rect.ToString()); |
| 1219 } | 1219 } |
| 1220 | 1220 |
| 1221 TEST_F(DamageTrackerTest, VerifyDamageForReplicaMask) { | 1221 TEST_F(DamageTrackerTest, VerifyDamageForReplicaMask) { |
| 1222 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 1222 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
| 1223 LayerImpl* child1 = root->children()[0]; | 1223 LayerImpl* child1 = root->children()[0].get(); |
| 1224 LayerImpl* grand_child1 = child1->children()[0]; | 1224 LayerImpl* grand_child1 = child1->children()[0].get(); |
| 1225 | 1225 |
| 1226 // Changes to a replica's mask should not damage the original surface, | 1226 // Changes to a replica's mask should not damage the original surface, |
| 1227 // because it is not masked. But it does damage the ancestor target surface. | 1227 // because it is not masked. But it does damage the ancestor target surface. |
| 1228 | 1228 |
| 1229 ClearDamageForAllSurfaces(root.get()); | 1229 ClearDamageForAllSurfaces(root.get()); |
| 1230 | 1230 |
| 1231 // Create a reflection about the left edge of grand_child1. | 1231 // Create a reflection about the left edge of grand_child1. |
| 1232 { | 1232 { |
| 1233 scoped_ptr<LayerImpl> grand_child1_replica = | 1233 scoped_ptr<LayerImpl> grand_child1_replica = |
| 1234 LayerImpl::Create(host_impl_.active_tree(), 6); | 1234 LayerImpl::Create(host_impl_.active_tree(), 6); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1282 current_damage_rect(); | 1282 current_damage_rect(); |
| 1283 child_damage_rect = | 1283 child_damage_rect = |
| 1284 child1->render_surface()->damage_tracker()->current_damage_rect(); | 1284 child1->render_surface()->damage_tracker()->current_damage_rect(); |
| 1285 | 1285 |
| 1286 EXPECT_TRUE(grand_child_damage_rect.IsEmpty()); | 1286 EXPECT_TRUE(grand_child_damage_rect.IsEmpty()); |
| 1287 EXPECT_EQ(gfx::Rect(194, 200, 6, 8).ToString(), child_damage_rect.ToString()); | 1287 EXPECT_EQ(gfx::Rect(194, 200, 6, 8).ToString(), child_damage_rect.ToString()); |
| 1288 } | 1288 } |
| 1289 | 1289 |
| 1290 TEST_F(DamageTrackerTest, VerifyDamageForReplicaMaskWithTransformOrigin) { | 1290 TEST_F(DamageTrackerTest, VerifyDamageForReplicaMaskWithTransformOrigin) { |
| 1291 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 1291 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
| 1292 LayerImpl* child1 = root->children()[0]; | 1292 LayerImpl* child1 = root->children()[0].get(); |
| 1293 LayerImpl* grand_child1 = child1->children()[0]; | 1293 LayerImpl* grand_child1 = child1->children()[0].get(); |
| 1294 | 1294 |
| 1295 // Verify that the correct replica_origin_transform is used for the | 1295 // Verify that the correct replica_origin_transform is used for the |
| 1296 // replica_mask. | 1296 // replica_mask. |
| 1297 ClearDamageForAllSurfaces(root.get()); | 1297 ClearDamageForAllSurfaces(root.get()); |
| 1298 | 1298 |
| 1299 // This is not actually the transform origin point being tested, but by | 1299 // This is not actually the transform origin point being tested, but by |
| 1300 // convention its | 1300 // convention its |
| 1301 // expected to be the same as the replica's anchor point. | 1301 // expected to be the same as the replica's anchor point. |
| 1302 grand_child1->SetTransformOrigin( | 1302 grand_child1->SetTransformOrigin( |
| 1303 gfx::Point3F(grand_child1->bounds().width(), 0.f, 0.f)); | 1303 gfx::Point3F(grand_child1->bounds().width(), 0.f, 0.f)); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1341 | 1341 |
| 1342 EmulateDrawingOneFrame(root.get()); | 1342 EmulateDrawingOneFrame(root.get()); |
| 1343 | 1343 |
| 1344 gfx::Rect child_damage_rect = | 1344 gfx::Rect child_damage_rect = |
| 1345 child1->render_surface()->damage_tracker()->current_damage_rect(); | 1345 child1->render_surface()->damage_tracker()->current_damage_rect(); |
| 1346 EXPECT_EQ(gfx::Rect(206, 200, 6, 8).ToString(), child_damage_rect.ToString()); | 1346 EXPECT_EQ(gfx::Rect(206, 200, 6, 8).ToString(), child_damage_rect.ToString()); |
| 1347 } | 1347 } |
| 1348 | 1348 |
| 1349 TEST_F(DamageTrackerTest, DamageWhenAddedExternally) { | 1349 TEST_F(DamageTrackerTest, DamageWhenAddedExternally) { |
| 1350 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithOneSurface(); | 1350 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithOneSurface(); |
| 1351 LayerImpl* child = root->children()[0]; | 1351 LayerImpl* child = root->children()[0].get(); |
| 1352 | 1352 |
| 1353 // Case 1: This test ensures that when the tracker is given damage, that | 1353 // Case 1: This test ensures that when the tracker is given damage, that |
| 1354 // it is included with any other partial damage. | 1354 // it is included with any other partial damage. |
| 1355 // | 1355 // |
| 1356 ClearDamageForAllSurfaces(root.get()); | 1356 ClearDamageForAllSurfaces(root.get()); |
| 1357 child->SetUpdateRect(gfx::Rect(10, 11, 12, 13)); | 1357 child->SetUpdateRect(gfx::Rect(10, 11, 12, 13)); |
| 1358 root->render_surface()->damage_tracker()->AddDamageNextUpdate( | 1358 root->render_surface()->damage_tracker()->AddDamageNextUpdate( |
| 1359 gfx::Rect(15, 16, 32, 33)); | 1359 gfx::Rect(15, 16, 32, 33)); |
| 1360 EmulateDrawingOneFrame(root.get()); | 1360 EmulateDrawingOneFrame(root.get()); |
| 1361 gfx::Rect root_damage_rect = | 1361 gfx::Rect root_damage_rect = |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1398 | 1398 |
| 1399 gfx::Rect damage_rect = | 1399 gfx::Rect damage_rect = |
| 1400 target_surface->damage_tracker()->current_damage_rect(); | 1400 target_surface->damage_tracker()->current_damage_rect(); |
| 1401 EXPECT_TRUE(damage_rect.IsEmpty()); | 1401 EXPECT_TRUE(damage_rect.IsEmpty()); |
| 1402 } | 1402 } |
| 1403 | 1403 |
| 1404 TEST_F(DamageTrackerTest, VerifyDamageAccumulatesUntilReset) { | 1404 TEST_F(DamageTrackerTest, VerifyDamageAccumulatesUntilReset) { |
| 1405 // If damage is not cleared, it should accumulate. | 1405 // If damage is not cleared, it should accumulate. |
| 1406 | 1406 |
| 1407 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithOneSurface(); | 1407 scoped_ptr<LayerImpl> root = CreateAndSetUpTestTreeWithOneSurface(); |
| 1408 LayerImpl* child = root->children()[0]; | 1408 LayerImpl* child = root->children()[0].get(); |
| 1409 | 1409 |
| 1410 ClearDamageForAllSurfaces(root.get()); | 1410 ClearDamageForAllSurfaces(root.get()); |
| 1411 child->SetUpdateRect(gfx::Rect(10.f, 11.f, 1.f, 2.f)); | 1411 child->SetUpdateRect(gfx::Rect(10.f, 11.f, 1.f, 2.f)); |
| 1412 EmulateDrawingOneFrame(root.get()); | 1412 EmulateDrawingOneFrame(root.get()); |
| 1413 | 1413 |
| 1414 // Sanity check damage after the first frame; this isnt the actual test yet. | 1414 // Sanity check damage after the first frame; this isnt the actual test yet. |
| 1415 gfx::Rect root_damage_rect = | 1415 gfx::Rect root_damage_rect = |
| 1416 root->render_surface()->damage_tracker()->current_damage_rect(); | 1416 root->render_surface()->damage_tracker()->current_damage_rect(); |
| 1417 EXPECT_EQ(gfx::Rect(110, 111, 1, 2).ToString(), root_damage_rect.ToString()); | 1417 EXPECT_EQ(gfx::Rect(110, 111, 1, 2).ToString(), root_damage_rect.ToString()); |
| 1418 | 1418 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1442 | 1442 |
| 1443 TEST_F(DamageTrackerTest, HugeDamageRect) { | 1443 TEST_F(DamageTrackerTest, HugeDamageRect) { |
| 1444 // This number is so large that we start losting floating point accuracy. | 1444 // This number is so large that we start losting floating point accuracy. |
| 1445 const int kBigNumber = 900000000; | 1445 const int kBigNumber = 900000000; |
| 1446 // Walk over a range to find floating point inaccuracy boundaries that move | 1446 // Walk over a range to find floating point inaccuracy boundaries that move |
| 1447 // toward the wrong direction. | 1447 // toward the wrong direction. |
| 1448 const int kRange = 5000; | 1448 const int kRange = 5000; |
| 1449 | 1449 |
| 1450 for (int i = 0; i < kRange; ++i) { | 1450 for (int i = 0; i < kRange; ++i) { |
| 1451 scoped_ptr<LayerImpl> root = CreateTestTreeWithOneSurface(); | 1451 scoped_ptr<LayerImpl> root = CreateTestTreeWithOneSurface(); |
| 1452 LayerImpl* child = root->children()[0]; | 1452 LayerImpl* child = root->children()[0].get(); |
| 1453 | 1453 |
| 1454 gfx::Transform transform; | 1454 gfx::Transform transform; |
| 1455 transform.Translate(-kBigNumber, -kBigNumber); | 1455 transform.Translate(-kBigNumber, -kBigNumber); |
| 1456 | 1456 |
| 1457 // The child layer covers (0, 0, i, i) of the viewport, | 1457 // The child layer covers (0, 0, i, i) of the viewport, |
| 1458 // but has a huge negative position. | 1458 // but has a huge negative position. |
| 1459 child->SetPosition(gfx::PointF()); | 1459 child->SetPosition(gfx::PointF()); |
| 1460 child->SetBounds(gfx::Size(kBigNumber + i, kBigNumber + i)); | 1460 child->SetBounds(gfx::Size(kBigNumber + i, kBigNumber + i)); |
| 1461 child->SetTransform(transform); | 1461 child->SetTransform(transform); |
| 1462 EmulateDrawingOneFrame(root.get()); | 1462 EmulateDrawingOneFrame(root.get()); |
| 1463 | 1463 |
| 1464 // The expected damage should cover the visible part of the child layer, | 1464 // The expected damage should cover the visible part of the child layer, |
| 1465 // which is (0, 0, i, i) in the viewport. | 1465 // which is (0, 0, i, i) in the viewport. |
| 1466 gfx::Rect root_damage_rect = | 1466 gfx::Rect root_damage_rect = |
| 1467 root->render_surface()->damage_tracker()->current_damage_rect(); | 1467 root->render_surface()->damage_tracker()->current_damage_rect(); |
| 1468 gfx::Rect damage_we_care_about = gfx::Rect(i, i); | 1468 gfx::Rect damage_we_care_about = gfx::Rect(i, i); |
| 1469 EXPECT_LE(damage_we_care_about.right(), root_damage_rect.right()); | 1469 EXPECT_LE(damage_we_care_about.right(), root_damage_rect.right()); |
| 1470 EXPECT_LE(damage_we_care_about.bottom(), root_damage_rect.bottom()); | 1470 EXPECT_LE(damage_we_care_about.bottom(), root_damage_rect.bottom()); |
| 1471 } | 1471 } |
| 1472 } | 1472 } |
| 1473 | 1473 |
| 1474 } // namespace | 1474 } // namespace |
| 1475 } // namespace cc | 1475 } // namespace cc |
| OLD | NEW |