OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/trees/damage_tracker.h" | 5 #include "cc/trees/damage_tracker.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "cc/base/filter_operation.h" | 9 #include "cc/base/filter_operation.h" |
10 #include "cc/base/filter_operations.h" | 10 #include "cc/base/filter_operations.h" |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 | 182 |
183 EXPECT_EQ(2, GetRenderSurface(root)->num_contributors()); | 183 EXPECT_EQ(2, GetRenderSurface(root)->num_contributors()); |
184 EXPECT_TRUE(root->contributes_to_drawn_render_surface()); | 184 EXPECT_TRUE(root->contributes_to_drawn_render_surface()); |
185 EXPECT_TRUE(child->contributes_to_drawn_render_surface()); | 185 EXPECT_TRUE(child->contributes_to_drawn_render_surface()); |
186 | 186 |
187 gfx::Rect root_damage_rect; | 187 gfx::Rect root_damage_rect; |
188 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 188 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
189 &root_damage_rect)); | 189 &root_damage_rect)); |
190 | 190 |
191 EXPECT_EQ(gfx::Rect(500, 500).ToString(), root_damage_rect.ToString()); | 191 EXPECT_EQ(gfx::Rect(500, 500).ToString(), root_damage_rect.ToString()); |
| 192 EXPECT_TRUE(GetRenderSurface(root) |
| 193 ->damage_tracker() |
| 194 ->has_damage_from_contributing_content()); |
192 } | 195 } |
193 | 196 |
194 TEST_F(DamageTrackerTest, SanityCheckTestTreeWithTwoSurfaces) { | 197 TEST_F(DamageTrackerTest, SanityCheckTestTreeWithTwoSurfaces) { |
195 // Sanity check that the complex test tree will actually produce the expected | 198 // Sanity check that the complex test tree will actually produce the expected |
196 // render surfaces. | 199 // render surfaces. |
197 | 200 |
198 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 201 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
199 | 202 |
200 LayerImpl* child1 = root->test_properties()->children[0]; | 203 LayerImpl* child1 = root->test_properties()->children[0]; |
201 LayerImpl* child2 = root->test_properties()->children[1]; | 204 LayerImpl* child2 = root->test_properties()->children[1]; |
202 | 205 |
203 gfx::Rect child_damage_rect; | 206 gfx::Rect child_damage_rect; |
204 EXPECT_TRUE(GetRenderSurface(child1)->damage_tracker()->GetDamageRectIfValid( | 207 EXPECT_TRUE(GetRenderSurface(child1)->damage_tracker()->GetDamageRectIfValid( |
205 &child_damage_rect)); | 208 &child_damage_rect)); |
206 gfx::Rect root_damage_rect; | 209 gfx::Rect root_damage_rect; |
207 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 210 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
208 &root_damage_rect)); | 211 &root_damage_rect)); |
209 | 212 |
210 EXPECT_NE(GetRenderSurface(child1), GetRenderSurface(root)); | 213 EXPECT_NE(GetRenderSurface(child1), GetRenderSurface(root)); |
211 EXPECT_EQ(GetRenderSurface(child2), GetRenderSurface(root)); | 214 EXPECT_EQ(GetRenderSurface(child2), GetRenderSurface(root)); |
212 EXPECT_EQ(3, GetRenderSurface(root)->num_contributors()); | 215 EXPECT_EQ(3, GetRenderSurface(root)->num_contributors()); |
213 EXPECT_EQ(2, GetRenderSurface(child1)->num_contributors()); | 216 EXPECT_EQ(2, GetRenderSurface(child1)->num_contributors()); |
214 | 217 |
215 // The render surface for child1 only has a content_rect that encloses | 218 // The render surface for child1 only has a content_rect that encloses |
216 // grand_child1 and grand_child2, because child1 does not draw content. | 219 // grand_child1 and grand_child2, because child1 does not draw content. |
217 EXPECT_EQ(gfx::Rect(190, 190, 16, 18).ToString(), | 220 EXPECT_EQ(gfx::Rect(190, 190, 16, 18).ToString(), |
218 child_damage_rect.ToString()); | 221 child_damage_rect.ToString()); |
219 EXPECT_EQ(gfx::Rect(500, 500).ToString(), root_damage_rect.ToString()); | 222 EXPECT_EQ(gfx::Rect(500, 500).ToString(), root_damage_rect.ToString()); |
| 223 |
| 224 EXPECT_TRUE(GetRenderSurface(root) |
| 225 ->damage_tracker() |
| 226 ->has_damage_from_contributing_content()); |
| 227 EXPECT_TRUE(GetRenderSurface(child1) |
| 228 ->damage_tracker() |
| 229 ->has_damage_from_contributing_content()); |
220 } | 230 } |
221 | 231 |
222 TEST_F(DamageTrackerTest, VerifyDamageForUpdateRects) { | 232 TEST_F(DamageTrackerTest, VerifyDamageForUpdateRects) { |
223 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 233 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
224 LayerImpl* child = root->test_properties()->children[0]; | 234 LayerImpl* child = root->test_properties()->children[0]; |
225 | 235 |
226 // CASE 1: Setting the update rect should cause the corresponding damage to | 236 // CASE 1: Setting the update rect should cause the corresponding damage to |
227 // the surface. | 237 // the surface. |
228 ClearDamageForAllSurfaces(root); | 238 ClearDamageForAllSurfaces(root); |
229 child->SetUpdateRect(gfx::Rect(10, 11, 12, 13)); | 239 child->SetUpdateRect(gfx::Rect(10, 11, 12, 13)); |
(...skipping 24 matching lines...) Expand all Loading... |
254 ClearDamageForAllSurfaces(root); | 264 ClearDamageForAllSurfaces(root); |
255 child->SetUpdateRect(gfx::Rect(20, 25, 1, 2)); | 265 child->SetUpdateRect(gfx::Rect(20, 25, 1, 2)); |
256 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 266 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
257 EmulateDrawingOneFrame(root); | 267 EmulateDrawingOneFrame(root); |
258 | 268 |
259 // Damage position on the surface should be: position of update_rect (20, 25) | 269 // Damage position on the surface should be: position of update_rect (20, 25) |
260 // relative to the child (100, 100). | 270 // relative to the child (100, 100). |
261 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 271 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
262 &root_damage_rect)); | 272 &root_damage_rect)); |
263 EXPECT_EQ(gfx::Rect(120, 125, 1, 2).ToString(), root_damage_rect.ToString()); | 273 EXPECT_EQ(gfx::Rect(120, 125, 1, 2).ToString(), root_damage_rect.ToString()); |
| 274 EXPECT_TRUE(GetRenderSurface(root) |
| 275 ->damage_tracker() |
| 276 ->has_damage_from_contributing_content()); |
264 } | 277 } |
265 | 278 |
266 TEST_F(DamageTrackerTest, VerifyDamageForLayerDamageRects) { | 279 TEST_F(DamageTrackerTest, VerifyDamageForLayerDamageRects) { |
267 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 280 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
268 LayerImpl* child = root->test_properties()->children[0]; | 281 LayerImpl* child = root->test_properties()->children[0]; |
269 | 282 |
270 // CASE 1: Adding the layer damage rect should cause the corresponding damage | 283 // CASE 1: Adding the layer damage rect should cause the corresponding damage |
271 // to the surface. | 284 // to the surface. |
272 ClearDamageForAllSurfaces(root); | 285 ClearDamageForAllSurfaces(root); |
273 child->AddDamageRect(gfx::Rect(10, 11, 12, 13)); | 286 child->AddDamageRect(gfx::Rect(10, 11, 12, 13)); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 child->AddDamageRect(gfx::Rect(10, 15, 3, 4)); | 324 child->AddDamageRect(gfx::Rect(10, 15, 3, 4)); |
312 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 325 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
313 EmulateDrawingOneFrame(root); | 326 EmulateDrawingOneFrame(root); |
314 | 327 |
315 // Damage position on the surface should be: position of layer damage_rect | 328 // Damage position on the surface should be: position of layer damage_rect |
316 // (20, 25) relative to the child (100, 100). | 329 // (20, 25) relative to the child (100, 100). |
317 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 330 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
318 &root_damage_rect)); | 331 &root_damage_rect)); |
319 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(120, 125, 1, 2))); | 332 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(120, 125, 1, 2))); |
320 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(110, 115, 3, 4))); | 333 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(110, 115, 3, 4))); |
| 334 EXPECT_TRUE(GetRenderSurface(root) |
| 335 ->damage_tracker() |
| 336 ->has_damage_from_contributing_content()); |
321 } | 337 } |
322 | 338 |
323 TEST_F(DamageTrackerTest, VerifyDamageForLayerUpdateAndDamageRects) { | 339 TEST_F(DamageTrackerTest, VerifyDamageForLayerUpdateAndDamageRects) { |
324 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 340 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
325 LayerImpl* child = root->test_properties()->children[0]; | 341 LayerImpl* child = root->test_properties()->children[0]; |
326 | 342 |
327 // CASE 1: Adding the layer damage rect and update rect should cause the | 343 // CASE 1: Adding the layer damage rect and update rect should cause the |
328 // corresponding damage to the surface. | 344 // corresponding damage to the surface. |
329 ClearDamageForAllSurfaces(root); | 345 ClearDamageForAllSurfaces(root); |
330 child->AddDamageRect(gfx::Rect(5, 6, 12, 13)); | 346 child->AddDamageRect(gfx::Rect(5, 6, 12, 13)); |
(...skipping 26 matching lines...) Expand all Loading... |
357 child->AddDamageRect(gfx::Rect(20, 25, 2, 3)); | 373 child->AddDamageRect(gfx::Rect(20, 25, 2, 3)); |
358 child->SetUpdateRect(gfx::Rect(5, 10, 7, 8)); | 374 child->SetUpdateRect(gfx::Rect(5, 10, 7, 8)); |
359 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 375 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
360 EmulateDrawingOneFrame(root); | 376 EmulateDrawingOneFrame(root); |
361 | 377 |
362 // Damage position on the surface should be: position of unified layer damage | 378 // Damage position on the surface should be: position of unified layer damage |
363 // rect and update rect (5, 10) relative to the child (100, 100). | 379 // rect and update rect (5, 10) relative to the child (100, 100). |
364 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 380 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
365 &root_damage_rect)); | 381 &root_damage_rect)); |
366 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(105, 110, 17, 18))); | 382 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(105, 110, 17, 18))); |
| 383 EXPECT_TRUE(GetRenderSurface(root) |
| 384 ->damage_tracker() |
| 385 ->has_damage_from_contributing_content()); |
367 } | 386 } |
368 | 387 |
369 TEST_F(DamageTrackerTest, VerifyDamageForPropertyChanges) { | 388 TEST_F(DamageTrackerTest, VerifyDamageForPropertyChanges) { |
370 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 389 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
371 LayerImpl* child = root->test_properties()->children[0]; | 390 LayerImpl* child = root->test_properties()->children[0]; |
372 | 391 |
373 // CASE 1: The layer's property changed flag takes priority over update rect. | 392 // CASE 1: The layer's property changed flag takes priority over update rect. |
374 // | 393 // |
375 child->test_properties()->force_render_surface = true; | 394 child->test_properties()->force_render_surface = true; |
376 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 395 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
377 EmulateDrawingOneFrame(root); | 396 EmulateDrawingOneFrame(root); |
378 ClearDamageForAllSurfaces(root); | 397 ClearDamageForAllSurfaces(root); |
379 child->SetUpdateRect(gfx::Rect(10, 11, 12, 13)); | 398 child->SetUpdateRect(gfx::Rect(10, 11, 12, 13)); |
380 root->layer_tree_impl()->SetOpacityMutated(child->element_id(), 0.5f); | 399 root->layer_tree_impl()->SetOpacityMutated(child->element_id(), 0.5f); |
381 EmulateDrawingOneFrame(root); | 400 EmulateDrawingOneFrame(root); |
382 | 401 |
383 ASSERT_EQ(2, GetRenderSurface(root)->num_contributors()); | 402 ASSERT_EQ(2, GetRenderSurface(root)->num_contributors()); |
384 | 403 |
385 // Damage should be the entire child layer in target_surface space. | 404 // Damage should be the entire child layer in target_surface space. |
386 gfx::Rect expected_rect = gfx::Rect(100, 100, 30, 30); | 405 gfx::Rect expected_rect = gfx::Rect(100, 100, 30, 30); |
387 gfx::Rect root_damage_rect; | 406 gfx::Rect root_damage_rect; |
388 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 407 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
389 &root_damage_rect)); | 408 &root_damage_rect)); |
390 EXPECT_EQ(expected_rect.ToString(), root_damage_rect.ToString()); | 409 EXPECT_EQ(expected_rect.ToString(), root_damage_rect.ToString()); |
| 410 EXPECT_TRUE(GetRenderSurface(root) |
| 411 ->damage_tracker() |
| 412 ->has_damage_from_contributing_content()); |
| 413 EXPECT_TRUE(GetRenderSurface(child) |
| 414 ->damage_tracker() |
| 415 ->has_damage_from_contributing_content()); |
391 | 416 |
392 // CASE 2: If a layer moves due to property change, it damages both the new | 417 // CASE 2: If a layer moves due to property change, it damages both the new |
393 // location and the old (exposed) location. The old location is the | 418 // location and the old (exposed) location. The old location is the |
394 // entire old layer, not just the update_rect. | 419 // entire old layer, not just the update_rect. |
395 | 420 |
396 // Cycle one frame of no change, just to sanity check that the next rect is | 421 // Cycle one frame of no change, just to sanity check that the next rect is |
397 // not because of the old damage state. | 422 // not because of the old damage state. |
398 ClearDamageForAllSurfaces(root); | 423 ClearDamageForAllSurfaces(root); |
399 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 424 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
400 EmulateDrawingOneFrame(root); | 425 EmulateDrawingOneFrame(root); |
401 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 426 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
402 &root_damage_rect)); | 427 &root_damage_rect)); |
403 EXPECT_TRUE(root_damage_rect.IsEmpty()); | 428 EXPECT_TRUE(root_damage_rect.IsEmpty()); |
404 | 429 |
405 // Then, test the actual layer movement. | 430 // Then, test the actual layer movement. |
406 ClearDamageForAllSurfaces(root); | 431 ClearDamageForAllSurfaces(root); |
407 gfx::Transform translation; | 432 gfx::Transform translation; |
408 translation.Translate(100.f, 130.f); | 433 translation.Translate(100.f, 130.f); |
409 root->layer_tree_impl()->SetTransformMutated(child->element_id(), | 434 root->layer_tree_impl()->SetTransformMutated(child->element_id(), |
410 translation); | 435 translation); |
411 EmulateDrawingOneFrame(root); | 436 EmulateDrawingOneFrame(root); |
412 | 437 |
413 // Expect damage to be the combination of the previous one and the new one. | 438 // Expect damage to be the combination of the previous one and the new one. |
414 expected_rect.Union(gfx::Rect(200, 230, 30, 30)); | 439 expected_rect.Union(gfx::Rect(200, 230, 30, 30)); |
415 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 440 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
416 &root_damage_rect)); | 441 &root_damage_rect)); |
417 EXPECT_FLOAT_RECT_EQ(expected_rect, root_damage_rect); | 442 EXPECT_FLOAT_RECT_EQ(expected_rect, root_damage_rect); |
| 443 EXPECT_TRUE(GetRenderSurface(root) |
| 444 ->damage_tracker() |
| 445 ->has_damage_from_contributing_content()); |
| 446 // Transform from browser animation should not be considered as damage from |
| 447 // contributing layer since it is applied to the whole layer which has a |
| 448 // render surface. |
| 449 EXPECT_FALSE(GetRenderSurface(child) |
| 450 ->damage_tracker() |
| 451 ->has_damage_from_contributing_content()); |
| 452 } |
| 453 |
| 454 TEST_F(DamageTrackerTest, |
| 455 VerifyDamageForPropertyChangesFromContributingContents) { |
| 456 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
| 457 LayerImpl* child1 = root->test_properties()->children[0]; |
| 458 LayerImpl* child2 = root->test_properties()->children[1]; |
| 459 LayerImpl* grandchild1 = child1->test_properties()->children[0]; |
| 460 |
| 461 // CASE 1: The child1's opacity changed. |
| 462 ClearDamageForAllSurfaces(root); |
| 463 root->layer_tree_impl()->SetOpacityMutated(child1->element_id(), 0.5f); |
| 464 EmulateDrawingOneFrame(root); |
| 465 EXPECT_TRUE(GetRenderSurface(root) |
| 466 ->damage_tracker() |
| 467 ->has_damage_from_contributing_content()); |
| 468 EXPECT_FALSE(GetRenderSurface(child1) |
| 469 ->damage_tracker() |
| 470 ->has_damage_from_contributing_content()); |
| 471 |
| 472 // CASE 2: The layer2's opacity changed. |
| 473 child2->test_properties()->force_render_surface = true; |
| 474 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 475 EmulateDrawingOneFrame(root); |
| 476 ClearDamageForAllSurfaces(root); |
| 477 root->layer_tree_impl()->SetOpacityMutated(child2->element_id(), 0.5f); |
| 478 EmulateDrawingOneFrame(root); |
| 479 EXPECT_TRUE(GetRenderSurface(root) |
| 480 ->damage_tracker() |
| 481 ->has_damage_from_contributing_content()); |
| 482 EXPECT_FALSE(GetRenderSurface(child1) |
| 483 ->damage_tracker() |
| 484 ->has_damage_from_contributing_content()); |
| 485 |
| 486 // CASE 3: The grandchild1's opacity changed. |
| 487 grandchild1->test_properties()->force_render_surface = true; |
| 488 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 489 EmulateDrawingOneFrame(root); |
| 490 ClearDamageForAllSurfaces(root); |
| 491 root->layer_tree_impl()->SetOpacityMutated(grandchild1->element_id(), 0.5f); |
| 492 EmulateDrawingOneFrame(root); |
| 493 EXPECT_TRUE(GetRenderSurface(root) |
| 494 ->damage_tracker() |
| 495 ->has_damage_from_contributing_content()); |
| 496 EXPECT_TRUE(GetRenderSurface(child1) |
| 497 ->damage_tracker() |
| 498 ->has_damage_from_contributing_content()); |
| 499 } |
| 500 |
| 501 TEST_F(DamageTrackerTest, |
| 502 VerifyDamageForUpdateAndDamageRectsFromContributingContents) { |
| 503 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
| 504 LayerImpl* child1 = root->test_properties()->children[0]; |
| 505 LayerImpl* child2 = root->test_properties()->children[1]; |
| 506 LayerImpl* grandchild1 = child1->test_properties()->children[0]; |
| 507 |
| 508 // CASE 1: Adding the layer1's damage rect and update rect should cause the |
| 509 // corresponding damage to the surface. |
| 510 child1->SetDrawsContent(true); |
| 511 ClearDamageForAllSurfaces(root); |
| 512 child1->AddDamageRect(gfx::Rect(105, 106, 12, 15)); |
| 513 child1->SetUpdateRect(gfx::Rect(115, 116, 12, 15)); |
| 514 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
| 515 EmulateDrawingOneFrame(root); |
| 516 EXPECT_TRUE(GetRenderSurface(root) |
| 517 ->damage_tracker() |
| 518 ->has_damage_from_contributing_content()); |
| 519 EXPECT_TRUE(GetRenderSurface(child1) |
| 520 ->damage_tracker() |
| 521 ->has_damage_from_contributing_content()); |
| 522 |
| 523 // CASE 2: Adding the layer2's damage rect and update rect should cause the |
| 524 // corresponding damage to the surface. |
| 525 ClearDamageForAllSurfaces(root); |
| 526 child2->AddDamageRect(gfx::Rect(11, 11, 12, 15)); |
| 527 child2->SetUpdateRect(gfx::Rect(12, 12, 12, 15)); |
| 528 EmulateDrawingOneFrame(root); |
| 529 EXPECT_TRUE(GetRenderSurface(root) |
| 530 ->damage_tracker() |
| 531 ->has_damage_from_contributing_content()); |
| 532 EXPECT_FALSE(GetRenderSurface(child1) |
| 533 ->damage_tracker() |
| 534 ->has_damage_from_contributing_content()); |
| 535 |
| 536 // CASE 3: Adding the grandchild1's damage rect and update rect should cause |
| 537 // the corresponding damage to the surface. |
| 538 ClearDamageForAllSurfaces(root); |
| 539 grandchild1->AddDamageRect(gfx::Rect(1, 0, 2, 5)); |
| 540 grandchild1->SetUpdateRect(gfx::Rect(2, 1, 2, 5)); |
| 541 EmulateDrawingOneFrame(root); |
| 542 EXPECT_TRUE(GetRenderSurface(root) |
| 543 ->damage_tracker() |
| 544 ->has_damage_from_contributing_content()); |
| 545 EXPECT_TRUE(GetRenderSurface(child1) |
| 546 ->damage_tracker() |
| 547 ->has_damage_from_contributing_content()); |
418 } | 548 } |
419 | 549 |
420 TEST_F(DamageTrackerTest, VerifyDamageWhenSurfaceRemoved) { | 550 TEST_F(DamageTrackerTest, VerifyDamageWhenSurfaceRemoved) { |
421 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 551 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
422 LayerImpl* surface = root->test_properties()->children[0]; | 552 LayerImpl* surface = root->test_properties()->children[0]; |
423 LayerImpl* child = surface->test_properties()->children[0]; | 553 LayerImpl* child = surface->test_properties()->children[0]; |
424 child->SetDrawsContent(true); | 554 child->SetDrawsContent(true); |
425 EmulateDrawingOneFrame(root); | 555 EmulateDrawingOneFrame(root); |
426 ClearDamageForAllSurfaces(root); | 556 ClearDamageForAllSurfaces(root); |
427 | 557 |
428 surface->test_properties()->force_render_surface = false; | 558 surface->test_properties()->force_render_surface = false; |
429 child->SetDrawsContent(false); | 559 child->SetDrawsContent(false); |
430 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 560 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
431 EmulateDrawingOneFrame(root); | 561 EmulateDrawingOneFrame(root); |
432 gfx::Rect root_damage_rect; | 562 gfx::Rect root_damage_rect; |
433 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 563 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
434 &root_damage_rect)); | 564 &root_damage_rect)); |
435 EXPECT_EQ(gfx::Rect(290, 290, 16, 18).ToString(), | 565 EXPECT_EQ(gfx::Rect(290, 290, 16, 18).ToString(), |
436 root_damage_rect.ToString()); | 566 root_damage_rect.ToString()); |
| 567 EXPECT_TRUE(GetRenderSurface(root) |
| 568 ->damage_tracker() |
| 569 ->has_damage_from_contributing_content()); |
437 } | 570 } |
438 | 571 |
439 TEST_F(DamageTrackerTest, VerifyDamageForTransformedLayer) { | 572 TEST_F(DamageTrackerTest, VerifyDamageForTransformedLayer) { |
440 // If a layer is transformed, the damage rect should still enclose the entire | 573 // If a layer is transformed, the damage rect should still enclose the entire |
441 // transformed layer. | 574 // transformed layer. |
442 | 575 |
443 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 576 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
444 LayerImpl* child = root->test_properties()->children[0]; | 577 LayerImpl* child = root->test_properties()->children[0]; |
445 child->test_properties()->force_render_surface = true; | 578 child->test_properties()->force_render_surface = true; |
446 | 579 |
447 gfx::Transform rotation; | 580 gfx::Transform rotation; |
448 rotation.Rotate(45.0); | 581 rotation.Rotate(45.0); |
449 | 582 |
450 ClearDamageForAllSurfaces(root); | 583 ClearDamageForAllSurfaces(root); |
451 child->test_properties()->transform_origin = gfx::Point3F( | 584 child->test_properties()->transform_origin = gfx::Point3F( |
452 child->bounds().width() * 0.5f, child->bounds().height() * 0.5f, 0.f); | 585 child->bounds().width() * 0.5f, child->bounds().height() * 0.5f, 0.f); |
453 child->SetPosition(gfx::PointF(85.f, 85.f)); | 586 child->SetPosition(gfx::PointF(85.f, 85.f)); |
454 child->NoteLayerPropertyChanged(); | 587 child->NoteLayerPropertyChanged(); |
455 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 588 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
456 EmulateDrawingOneFrame(root); | 589 EmulateDrawingOneFrame(root); |
457 | 590 |
458 // Sanity check that the layer actually moved to (85, 85), damaging its old | 591 // Sanity check that the layer actually moved to (85, 85), damaging its old |
459 // location and new location. | 592 // location and new location. |
460 gfx::Rect root_damage_rect; | 593 gfx::Rect root_damage_rect; |
461 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 594 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
462 &root_damage_rect)); | 595 &root_damage_rect)); |
463 EXPECT_EQ(gfx::Rect(85, 85, 45, 45).ToString(), root_damage_rect.ToString()); | 596 EXPECT_EQ(gfx::Rect(85, 85, 45, 45).ToString(), root_damage_rect.ToString()); |
| 597 EXPECT_TRUE(GetRenderSurface(root) |
| 598 ->damage_tracker() |
| 599 ->has_damage_from_contributing_content()); |
| 600 // Layer's layer_property_changed_ should be considered as damage to render |
| 601 // surface. |
| 602 EXPECT_TRUE(GetRenderSurface(child) |
| 603 ->damage_tracker() |
| 604 ->has_damage_from_contributing_content()); |
464 | 605 |
465 // With the anchor on the layer's center, now we can test the rotation more | 606 // With the anchor on the layer's center, now we can test the rotation more |
466 // intuitively, since it applies about the layer's anchor. | 607 // intuitively, since it applies about the layer's anchor. |
467 ClearDamageForAllSurfaces(root); | 608 ClearDamageForAllSurfaces(root); |
468 root->layer_tree_impl()->SetTransformMutated(child->element_id(), rotation); | 609 root->layer_tree_impl()->SetTransformMutated(child->element_id(), rotation); |
469 EmulateDrawingOneFrame(root); | 610 EmulateDrawingOneFrame(root); |
470 | 611 |
471 // Since the child layer is square, rotation by 45 degrees about the center | 612 // Since the child layer is square, rotation by 45 degrees about the center |
472 // should increase the size of the expected rect by sqrt(2), centered around | 613 // should increase the size of the expected rect by sqrt(2), centered around |
473 // (100, 100). The old exposed region should be fully contained in the new | 614 // (100, 100). The old exposed region should be fully contained in the new |
474 // region. | 615 // region. |
475 float expected_width = 30.f * sqrt(2.f); | 616 float expected_width = 30.f * sqrt(2.f); |
476 float expected_position = 100.f - 0.5f * expected_width; | 617 float expected_position = 100.f - 0.5f * expected_width; |
477 gfx::Rect expected_rect = gfx::ToEnclosingRect(gfx::RectF( | 618 gfx::Rect expected_rect = gfx::ToEnclosingRect(gfx::RectF( |
478 expected_position, expected_position, expected_width, expected_width)); | 619 expected_position, expected_position, expected_width, expected_width)); |
479 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 620 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
480 &root_damage_rect)); | 621 &root_damage_rect)); |
481 EXPECT_EQ(expected_rect.ToString(), root_damage_rect.ToString()); | 622 EXPECT_EQ(expected_rect.ToString(), root_damage_rect.ToString()); |
| 623 EXPECT_TRUE(GetRenderSurface(root) |
| 624 ->damage_tracker() |
| 625 ->has_damage_from_contributing_content()); |
| 626 // Transform from browser animation should not be considered as damage from |
| 627 // contributing layer since it is applied to the whole layer which has a |
| 628 // render surface. |
| 629 EXPECT_FALSE(GetRenderSurface(child) |
| 630 ->damage_tracker() |
| 631 ->has_damage_from_contributing_content()); |
482 } | 632 } |
483 | 633 |
484 TEST_F(DamageTrackerTest, VerifyDamageForPerspectiveClippedLayer) { | 634 TEST_F(DamageTrackerTest, VerifyDamageForPerspectiveClippedLayer) { |
485 // If a layer has a perspective transform that causes w < 0, then not | 635 // If a layer has a perspective transform that causes w < 0, then not |
486 // clipping the layer can cause an invalid damage rect. This test checks that | 636 // clipping the layer can cause an invalid damage rect. This test checks that |
487 // the w < 0 case is tracked properly. | 637 // the w < 0 case is tracked properly. |
488 // | 638 // |
489 // The transform is constructed so that if w < 0 clipping is not performed, | 639 // The transform is constructed so that if w < 0 clipping is not performed, |
490 // the incorrect rect will be very small, specifically: position (500.972504, | 640 // the incorrect rect will be very small, specifically: position (500.972504, |
491 // 498.544617) and size 0.056610 x 2.910767. Instead, the correctly | 641 // 498.544617) and size 0.056610 x 2.910767. Instead, the correctly |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
526 EmulateDrawingOneFrame(root); | 676 EmulateDrawingOneFrame(root); |
527 | 677 |
528 // The expected damage should cover the entire root surface (500x500), but we | 678 // The expected damage should cover the entire root surface (500x500), but we |
529 // don't care whether the damage rect was clamped or is larger than the | 679 // don't care whether the damage rect was clamped or is larger than the |
530 // surface for this test. | 680 // surface for this test. |
531 gfx::Rect root_damage_rect; | 681 gfx::Rect root_damage_rect; |
532 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 682 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
533 &root_damage_rect)); | 683 &root_damage_rect)); |
534 gfx::Rect damage_we_care_about = gfx::Rect(gfx::Size(500, 500)); | 684 gfx::Rect damage_we_care_about = gfx::Rect(gfx::Size(500, 500)); |
535 EXPECT_TRUE(root_damage_rect.Contains(damage_we_care_about)); | 685 EXPECT_TRUE(root_damage_rect.Contains(damage_we_care_about)); |
| 686 EXPECT_TRUE(GetRenderSurface(root) |
| 687 ->damage_tracker() |
| 688 ->has_damage_from_contributing_content()); |
| 689 EXPECT_FALSE(GetRenderSurface(child) |
| 690 ->damage_tracker() |
| 691 ->has_damage_from_contributing_content()); |
536 } | 692 } |
537 | 693 |
538 TEST_F(DamageTrackerTest, VerifyDamageForBlurredSurface) { | 694 TEST_F(DamageTrackerTest, VerifyDamageForBlurredSurface) { |
539 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 695 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
540 LayerImpl* surface = root->test_properties()->children[0]; | 696 LayerImpl* surface = root->test_properties()->children[0]; |
541 LayerImpl* child = surface->test_properties()->children[0]; | 697 LayerImpl* child = surface->test_properties()->children[0]; |
542 | 698 |
543 FilterOperations filters; | 699 FilterOperations filters; |
544 filters.Append(FilterOperation::CreateBlurFilter(5.f)); | 700 filters.Append(FilterOperation::CreateBlurFilter(5.f)); |
545 | 701 |
546 // Setting the filter will damage the whole surface. | 702 // Setting the filter should not damage the conrresponding render surface. |
547 ClearDamageForAllSurfaces(root); | 703 ClearDamageForAllSurfaces(root); |
548 surface->test_properties()->filters = filters; | 704 surface->test_properties()->filters = filters; |
549 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 705 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
550 EmulateDrawingOneFrame(root); | 706 EmulateDrawingOneFrame(root); |
| 707 EXPECT_FALSE(GetRenderSurface(root) |
| 708 ->damage_tracker() |
| 709 ->has_damage_from_contributing_content()); |
| 710 EXPECT_FALSE(GetRenderSurface(surface) |
| 711 ->damage_tracker() |
| 712 ->has_damage_from_contributing_content()); |
551 | 713 |
552 // Setting the update rect should cause the corresponding damage to the | 714 // Setting the update rect should cause the corresponding damage to the |
553 // surface, blurred based on the size of the blur filter. | 715 // surface, blurred based on the size of the blur filter. |
554 ClearDamageForAllSurfaces(root); | 716 ClearDamageForAllSurfaces(root); |
555 child->SetUpdateRect(gfx::Rect(1, 2, 3, 4)); | 717 child->SetUpdateRect(gfx::Rect(1, 2, 3, 4)); |
556 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 718 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
557 EmulateDrawingOneFrame(root); | 719 EmulateDrawingOneFrame(root); |
558 | 720 |
559 // Damage position on the surface should be: position of update_rect (1, 2) | 721 // Damage position on the surface should be: position of update_rect (1, 2) |
560 // relative to the child (300, 300), but expanded by the blur outsets | 722 // relative to the child (300, 300), but expanded by the blur outsets |
561 // (15, since the blur radius is 5). | 723 // (15, since the blur radius is 5). |
562 gfx::Rect root_damage_rect; | 724 gfx::Rect root_damage_rect; |
563 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 725 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
564 &root_damage_rect)); | 726 &root_damage_rect)); |
565 EXPECT_EQ(gfx::Rect(286, 287, 33, 34), root_damage_rect); | 727 EXPECT_EQ(gfx::Rect(286, 287, 33, 34), root_damage_rect); |
| 728 EXPECT_TRUE(GetRenderSurface(root) |
| 729 ->damage_tracker() |
| 730 ->has_damage_from_contributing_content()); |
| 731 EXPECT_TRUE(GetRenderSurface(surface) |
| 732 ->damage_tracker() |
| 733 ->has_damage_from_contributing_content()); |
566 } | 734 } |
567 | 735 |
568 TEST_F(DamageTrackerTest, VerifyDamageForImageFilter) { | 736 TEST_F(DamageTrackerTest, VerifyDamageForImageFilter) { |
569 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 737 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
570 LayerImpl* child = root->test_properties()->children[0]; | 738 LayerImpl* child = root->test_properties()->children[0]; |
571 gfx::Rect root_damage_rect, child_damage_rect; | 739 gfx::Rect root_damage_rect, child_damage_rect; |
572 | 740 |
573 // Allow us to set damage on child too. | 741 // Allow us to set damage on child too. |
574 child->SetDrawsContent(true); | 742 child->SetDrawsContent(true); |
575 | 743 |
576 FilterOperations filters; | 744 FilterOperations filters; |
577 filters.Append(FilterOperation::CreateReferenceFilter( | 745 filters.Append(FilterOperation::CreateReferenceFilter( |
578 SkBlurImageFilter::Make(2, 2, nullptr))); | 746 SkBlurImageFilter::Make(2, 2, nullptr))); |
579 | 747 |
580 // Setting the filter will damage the whole surface. | 748 // Setting the filter will damage the whole surface. |
581 ClearDamageForAllSurfaces(root); | |
582 child->test_properties()->force_render_surface = true; | 749 child->test_properties()->force_render_surface = true; |
583 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 750 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
584 EmulateDrawingOneFrame(root); | 751 EmulateDrawingOneFrame(root); |
| 752 ClearDamageForAllSurfaces(root); |
585 child->layer_tree_impl()->SetFilterMutated(child->element_id(), filters); | 753 child->layer_tree_impl()->SetFilterMutated(child->element_id(), filters); |
586 EmulateDrawingOneFrame(root); | 754 EmulateDrawingOneFrame(root); |
587 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 755 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
588 &root_damage_rect)); | 756 &root_damage_rect)); |
589 EXPECT_TRUE(GetRenderSurface(child)->damage_tracker()->GetDamageRectIfValid( | 757 EXPECT_TRUE(GetRenderSurface(child)->damage_tracker()->GetDamageRectIfValid( |
590 &child_damage_rect)); | 758 &child_damage_rect)); |
591 | 759 |
592 // gfx::Rect(100, 100, 30, 30), expanded by 6px for the 2px blur filter. | 760 // gfx::Rect(100, 100, 30, 30), expanded by 6px for the 2px blur filter. |
593 EXPECT_EQ(gfx::Rect(94, 94, 42, 42), root_damage_rect); | 761 EXPECT_EQ(gfx::Rect(94, 94, 42, 42), root_damage_rect); |
594 | 762 |
595 // gfx::Rect(0, 0, 30, 30), expanded by 6px for the 2px blur filter. | 763 // gfx::Rect(0, 0, 30, 30), expanded by 6px for the 2px blur filter. |
596 EXPECT_EQ(gfx::Rect(-6, -6, 42, 42), child_damage_rect); | 764 EXPECT_EQ(gfx::Rect(-6, -6, 42, 42), child_damage_rect); |
597 | 765 |
| 766 EXPECT_TRUE(GetRenderSurface(root) |
| 767 ->damage_tracker() |
| 768 ->has_damage_from_contributing_content()); |
| 769 EXPECT_FALSE(GetRenderSurface(child) |
| 770 ->damage_tracker() |
| 771 ->has_damage_from_contributing_content()); |
| 772 |
598 // CASE 1: Setting the update rect should damage the whole surface (for now) | 773 // CASE 1: Setting the update rect should damage the whole surface (for now) |
599 ClearDamageForAllSurfaces(root); | 774 ClearDamageForAllSurfaces(root); |
600 child->SetUpdateRect(gfx::Rect(1, 1)); | 775 child->SetUpdateRect(gfx::Rect(1, 1)); |
601 EmulateDrawingOneFrame(root); | 776 EmulateDrawingOneFrame(root); |
602 | 777 |
603 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 778 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
604 &root_damage_rect)); | 779 &root_damage_rect)); |
605 EXPECT_TRUE(GetRenderSurface(child)->damage_tracker()->GetDamageRectIfValid( | 780 EXPECT_TRUE(GetRenderSurface(child)->damage_tracker()->GetDamageRectIfValid( |
606 &child_damage_rect)); | 781 &child_damage_rect)); |
607 | 782 |
608 // gfx::Rect(100, 100, 1, 1), expanded by 6px for the 2px blur filter. | 783 // gfx::Rect(100, 100, 1, 1), expanded by 6px for the 2px blur filter. |
609 EXPECT_EQ(gfx::Rect(94, 94, 13, 13), root_damage_rect); | 784 EXPECT_EQ(gfx::Rect(94, 94, 13, 13), root_damage_rect); |
610 | 785 |
611 // gfx::Rect(0, 0, 1, 1), expanded by 6px for the 2px blur filter. | 786 // gfx::Rect(0, 0, 1, 1), expanded by 6px for the 2px blur filter. |
612 EXPECT_EQ(gfx::Rect(-6, -6, 13, 13), child_damage_rect); | 787 EXPECT_EQ(gfx::Rect(-6, -6, 13, 13), child_damage_rect); |
613 | 788 |
| 789 EXPECT_TRUE(GetRenderSurface(root) |
| 790 ->damage_tracker() |
| 791 ->has_damage_from_contributing_content()); |
| 792 EXPECT_TRUE(GetRenderSurface(child) |
| 793 ->damage_tracker() |
| 794 ->has_damage_from_contributing_content()); |
| 795 |
614 // CASE 2: No changes, so should not damage the surface. | 796 // CASE 2: No changes, so should not damage the surface. |
615 ClearDamageForAllSurfaces(root); | 797 ClearDamageForAllSurfaces(root); |
616 EmulateDrawingOneFrame(root); | 798 EmulateDrawingOneFrame(root); |
617 | 799 |
618 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 800 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
619 &root_damage_rect)); | 801 &root_damage_rect)); |
620 EXPECT_TRUE(GetRenderSurface(child)->damage_tracker()->GetDamageRectIfValid( | 802 EXPECT_TRUE(GetRenderSurface(child)->damage_tracker()->GetDamageRectIfValid( |
621 &child_damage_rect)); | 803 &child_damage_rect)); |
622 | 804 |
623 // Should not be expanded by the blur filter. | 805 // Should not be expanded by the blur filter. |
624 EXPECT_EQ(gfx::Rect(), root_damage_rect); | 806 EXPECT_EQ(gfx::Rect(), root_damage_rect); |
625 EXPECT_EQ(gfx::Rect(), child_damage_rect); | 807 EXPECT_EQ(gfx::Rect(), child_damage_rect); |
| 808 |
| 809 EXPECT_FALSE(GetRenderSurface(root) |
| 810 ->damage_tracker() |
| 811 ->has_damage_from_contributing_content()); |
| 812 EXPECT_FALSE(GetRenderSurface(child) |
| 813 ->damage_tracker() |
| 814 ->has_damage_from_contributing_content()); |
626 } | 815 } |
627 | 816 |
628 TEST_F(DamageTrackerTest, VerifyDamageForTransformedImageFilter) { | 817 TEST_F(DamageTrackerTest, VerifyDamageForTransformedImageFilter) { |
629 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 818 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
630 LayerImpl* child = root->test_properties()->children[0]; | 819 LayerImpl* child = root->test_properties()->children[0]; |
631 gfx::Rect root_damage_rect, child_damage_rect; | 820 gfx::Rect root_damage_rect, child_damage_rect; |
632 | 821 |
633 // Allow us to set damage on child too. | 822 // Allow us to set damage on child too. |
634 child->SetDrawsContent(true); | 823 child->SetDrawsContent(true); |
635 | 824 |
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
901 EmulateDrawingOneFrame(root); | 1090 EmulateDrawingOneFrame(root); |
902 | 1091 |
903 // Sanity check - all 3 layers should be on the same render surface; render | 1092 // Sanity check - all 3 layers should be on the same render surface; render |
904 // surfaces are tested elsewhere. | 1093 // surfaces are tested elsewhere. |
905 ASSERT_EQ(3, GetRenderSurface(root)->num_contributors()); | 1094 ASSERT_EQ(3, GetRenderSurface(root)->num_contributors()); |
906 | 1095 |
907 gfx::Rect root_damage_rect; | 1096 gfx::Rect root_damage_rect; |
908 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 1097 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
909 &root_damage_rect)); | 1098 &root_damage_rect)); |
910 EXPECT_EQ(gfx::Rect(400, 380, 6, 8).ToString(), root_damage_rect.ToString()); | 1099 EXPECT_EQ(gfx::Rect(400, 380, 6, 8).ToString(), root_damage_rect.ToString()); |
| 1100 EXPECT_TRUE(GetRenderSurface(root) |
| 1101 ->damage_tracker() |
| 1102 ->has_damage_from_contributing_content()); |
911 | 1103 |
912 // CASE 2: If the layer is removed, its entire old layer becomes exposed, not | 1104 // CASE 2: If the layer is removed, its entire old layer becomes exposed, not |
913 // just the last update rect. | 1105 // just the last update rect. |
914 | 1106 |
915 // Advance one frame without damage so that we know the damage rect is not | 1107 // Advance one frame without damage so that we know the damage rect is not |
916 // leftover from the previous case. | 1108 // leftover from the previous case. |
917 ClearDamageForAllSurfaces(root); | 1109 ClearDamageForAllSurfaces(root); |
918 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1110 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
919 EmulateDrawingOneFrame(root); | 1111 EmulateDrawingOneFrame(root); |
920 | 1112 |
921 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 1113 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
922 &root_damage_rect)); | 1114 &root_damage_rect)); |
923 EXPECT_TRUE(root_damage_rect.IsEmpty()); | 1115 EXPECT_TRUE(root_damage_rect.IsEmpty()); |
924 | 1116 |
925 // Then, test removing child1. | 1117 // Then, test removing child1. |
926 root->test_properties()->RemoveChild(child1); | 1118 root->test_properties()->RemoveChild(child1); |
927 child1 = NULL; | 1119 child1 = NULL; |
928 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1120 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
929 EmulateDrawingOneFrame(root); | 1121 EmulateDrawingOneFrame(root); |
930 | 1122 |
931 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 1123 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
932 &root_damage_rect)); | 1124 &root_damage_rect)); |
933 EXPECT_EQ(gfx::Rect(100, 100, 30, 30).ToString(), | 1125 EXPECT_EQ(gfx::Rect(100, 100, 30, 30).ToString(), |
934 root_damage_rect.ToString()); | 1126 root_damage_rect.ToString()); |
| 1127 EXPECT_TRUE(GetRenderSurface(root) |
| 1128 ->damage_tracker() |
| 1129 ->has_damage_from_contributing_content()); |
935 } | 1130 } |
936 | 1131 |
937 TEST_F(DamageTrackerTest, VerifyDamageForNewUnchangedLayer) { | 1132 TEST_F(DamageTrackerTest, VerifyDamageForNewUnchangedLayer) { |
938 // If child2 is added to the layer tree, but it doesn't have any explicit | 1133 // If child2 is added to the layer tree, but it doesn't have any explicit |
939 // damage of its own, it should still indeed damage the target surface. | 1134 // damage of its own, it should still indeed damage the target surface. |
940 | 1135 |
941 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 1136 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
942 | 1137 |
943 ClearDamageForAllSurfaces(root); | 1138 ClearDamageForAllSurfaces(root); |
944 { | 1139 { |
(...skipping 16 matching lines...) Expand all Loading... |
961 EmulateDrawingOneFrame(root); | 1156 EmulateDrawingOneFrame(root); |
962 | 1157 |
963 // Sanity check - all 3 layers should be on the same render surface; render | 1158 // Sanity check - all 3 layers should be on the same render surface; render |
964 // surfaces are tested elsewhere. | 1159 // surfaces are tested elsewhere. |
965 ASSERT_EQ(3, GetRenderSurface(root)->num_contributors()); | 1160 ASSERT_EQ(3, GetRenderSurface(root)->num_contributors()); |
966 | 1161 |
967 gfx::Rect root_damage_rect; | 1162 gfx::Rect root_damage_rect; |
968 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 1163 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
969 &root_damage_rect)); | 1164 &root_damage_rect)); |
970 EXPECT_EQ(gfx::Rect(400, 380, 6, 8).ToString(), root_damage_rect.ToString()); | 1165 EXPECT_EQ(gfx::Rect(400, 380, 6, 8).ToString(), root_damage_rect.ToString()); |
| 1166 EXPECT_TRUE(GetRenderSurface(root) |
| 1167 ->damage_tracker() |
| 1168 ->has_damage_from_contributing_content()); |
971 } | 1169 } |
972 | 1170 |
973 TEST_F(DamageTrackerTest, VerifyDamageForMultipleLayers) { | 1171 TEST_F(DamageTrackerTest, VerifyDamageForMultipleLayers) { |
974 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 1172 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
975 LayerImpl* child1 = root->test_properties()->children[0]; | 1173 LayerImpl* child1 = root->test_properties()->children[0]; |
976 | 1174 |
977 // In this test we don't want the above tree manipulation to be considered | 1175 // In this test we don't want the above tree manipulation to be considered |
978 // part of the same frame. | 1176 // part of the same frame. |
979 ClearDamageForAllSurfaces(root); | 1177 ClearDamageForAllSurfaces(root); |
980 { | 1178 { |
(...skipping 14 matching lines...) Expand all Loading... |
995 ClearDamageForAllSurfaces(root); | 1193 ClearDamageForAllSurfaces(root); |
996 child1->SetUpdateRect(gfx::Rect(1, 2)); | 1194 child1->SetUpdateRect(gfx::Rect(1, 2)); |
997 child2->SetUpdateRect(gfx::Rect(3, 4)); | 1195 child2->SetUpdateRect(gfx::Rect(3, 4)); |
998 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1196 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
999 EmulateDrawingOneFrame(root); | 1197 EmulateDrawingOneFrame(root); |
1000 gfx::Rect root_damage_rect; | 1198 gfx::Rect root_damage_rect; |
1001 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 1199 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
1002 &root_damage_rect)); | 1200 &root_damage_rect)); |
1003 EXPECT_EQ(gfx::Rect(100, 100, 303, 284).ToString(), | 1201 EXPECT_EQ(gfx::Rect(100, 100, 303, 284).ToString(), |
1004 root_damage_rect.ToString()); | 1202 root_damage_rect.ToString()); |
| 1203 EXPECT_TRUE(GetRenderSurface(root) |
| 1204 ->damage_tracker() |
| 1205 ->has_damage_from_contributing_content()); |
1005 } | 1206 } |
1006 | 1207 |
1007 TEST_F(DamageTrackerTest, VerifyDamageForNestedSurfaces) { | 1208 TEST_F(DamageTrackerTest, VerifyDamageForNestedSurfaces) { |
1008 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 1209 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
1009 LayerImpl* child1 = root->test_properties()->children[0]; | 1210 LayerImpl* child1 = root->test_properties()->children[0]; |
1010 LayerImpl* child2 = root->test_properties()->children[1]; | 1211 LayerImpl* child2 = root->test_properties()->children[1]; |
1011 LayerImpl* grand_child1 = | 1212 LayerImpl* grand_child1 = |
1012 root->test_properties()->children[0]->test_properties()->children[0]; | 1213 root->test_properties()->children[0]->test_properties()->children[0]; |
1013 child2->test_properties()->force_render_surface = true; | 1214 child2->test_properties()->force_render_surface = true; |
1014 grand_child1->test_properties()->force_render_surface = true; | 1215 grand_child1->test_properties()->force_render_surface = true; |
1015 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1216 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
1016 EmulateDrawingOneFrame(root); | 1217 EmulateDrawingOneFrame(root); |
1017 gfx::Rect child_damage_rect; | 1218 gfx::Rect child_damage_rect; |
1018 gfx::Rect root_damage_rect; | 1219 gfx::Rect root_damage_rect; |
1019 | 1220 |
1020 // CASE 1: Damage to a descendant surface should propagate properly to | 1221 // CASE 1: Damage to a descendant surface should propagate properly to |
1021 // ancestor surface. | 1222 // ancestor surface. |
1022 ClearDamageForAllSurfaces(root); | 1223 ClearDamageForAllSurfaces(root); |
1023 root->layer_tree_impl()->SetOpacityMutated(grand_child1->element_id(), 0.5f); | 1224 root->layer_tree_impl()->SetOpacityMutated(grand_child1->element_id(), 0.5f); |
1024 EmulateDrawingOneFrame(root); | 1225 EmulateDrawingOneFrame(root); |
1025 EXPECT_TRUE(GetRenderSurface(child1)->damage_tracker()->GetDamageRectIfValid( | 1226 EXPECT_TRUE(GetRenderSurface(child1)->damage_tracker()->GetDamageRectIfValid( |
1026 &child_damage_rect)); | 1227 &child_damage_rect)); |
1027 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 1228 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
1028 &root_damage_rect)); | 1229 &root_damage_rect)); |
1029 EXPECT_EQ(gfx::Rect(200, 200, 6, 8).ToString(), child_damage_rect.ToString()); | 1230 EXPECT_EQ(gfx::Rect(200, 200, 6, 8).ToString(), child_damage_rect.ToString()); |
1030 EXPECT_EQ(gfx::Rect(300, 300, 6, 8).ToString(), root_damage_rect.ToString()); | 1231 EXPECT_EQ(gfx::Rect(300, 300, 6, 8).ToString(), root_damage_rect.ToString()); |
| 1232 EXPECT_TRUE(GetRenderSurface(root) |
| 1233 ->damage_tracker() |
| 1234 ->has_damage_from_contributing_content()); |
| 1235 EXPECT_TRUE(GetRenderSurface(child1) |
| 1236 ->damage_tracker() |
| 1237 ->has_damage_from_contributing_content()); |
| 1238 EXPECT_FALSE(GetRenderSurface(child2) |
| 1239 ->damage_tracker() |
| 1240 ->has_damage_from_contributing_content()); |
| 1241 EXPECT_FALSE(GetRenderSurface(grand_child1) |
| 1242 ->damage_tracker() |
| 1243 ->has_damage_from_contributing_content()); |
1031 | 1244 |
1032 // CASE 2: Same as previous case, but with additional damage elsewhere that | 1245 // CASE 2: Same as previous case, but with additional damage elsewhere that |
1033 // should be properly unioned. | 1246 // should be properly unioned. |
1034 // - child1 surface damage in root surface space: | 1247 // - child1 surface damage in root surface space: |
1035 // gfx::Rect(300, 300, 6, 8); | 1248 // gfx::Rect(300, 300, 6, 8); |
1036 // - child2 damage in root surface space: | 1249 // - child2 damage in root surface space: |
1037 // gfx::Rect(11, 11, 18, 18); | 1250 // gfx::Rect(11, 11, 18, 18); |
1038 ClearDamageForAllSurfaces(root); | 1251 ClearDamageForAllSurfaces(root); |
1039 root->layer_tree_impl()->SetOpacityMutated(grand_child1->element_id(), 0.7f); | 1252 root->layer_tree_impl()->SetOpacityMutated(grand_child1->element_id(), 0.7f); |
1040 root->layer_tree_impl()->SetOpacityMutated(child2->element_id(), 0.7f); | 1253 root->layer_tree_impl()->SetOpacityMutated(child2->element_id(), 0.7f); |
1041 EmulateDrawingOneFrame(root); | 1254 EmulateDrawingOneFrame(root); |
1042 EXPECT_TRUE(GetRenderSurface(child1)->damage_tracker()->GetDamageRectIfValid( | 1255 EXPECT_TRUE(GetRenderSurface(child1)->damage_tracker()->GetDamageRectIfValid( |
1043 &child_damage_rect)); | 1256 &child_damage_rect)); |
1044 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 1257 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
1045 &root_damage_rect)); | 1258 &root_damage_rect)); |
1046 EXPECT_EQ(gfx::Rect(200, 200, 6, 8).ToString(), child_damage_rect.ToString()); | 1259 EXPECT_EQ(gfx::Rect(200, 200, 6, 8).ToString(), child_damage_rect.ToString()); |
1047 EXPECT_EQ(gfx::Rect(11, 11, 295, 297).ToString(), | 1260 EXPECT_EQ(gfx::Rect(11, 11, 295, 297).ToString(), |
1048 root_damage_rect.ToString()); | 1261 root_damage_rect.ToString()); |
| 1262 EXPECT_TRUE(GetRenderSurface(root) |
| 1263 ->damage_tracker() |
| 1264 ->has_damage_from_contributing_content()); |
| 1265 EXPECT_TRUE(GetRenderSurface(child1) |
| 1266 ->damage_tracker() |
| 1267 ->has_damage_from_contributing_content()); |
| 1268 EXPECT_FALSE(GetRenderSurface(child2) |
| 1269 ->damage_tracker() |
| 1270 ->has_damage_from_contributing_content()); |
| 1271 EXPECT_FALSE(GetRenderSurface(grand_child1) |
| 1272 ->damage_tracker() |
| 1273 ->has_damage_from_contributing_content()); |
1049 } | 1274 } |
1050 | 1275 |
1051 TEST_F(DamageTrackerTest, VerifyDamageForSurfaceChangeFromDescendantLayer) { | 1276 TEST_F(DamageTrackerTest, VerifyDamageForSurfaceChangeFromDescendantLayer) { |
1052 // If descendant layer changes and affects the content bounds of the render | 1277 // If descendant layer changes and affects the content bounds of the render |
1053 // surface, then the entire descendant surface should be damaged, and it | 1278 // surface, then the entire descendant surface should be damaged, and it |
1054 // should damage its ancestor surface with the old and new surface regions. | 1279 // should damage its ancestor surface with the old and new surface regions. |
1055 | 1280 |
1056 // This is a tricky case, since only the first grand_child changes, but the | 1281 // This is a tricky case, since only the first grand_child changes, but the |
1057 // entire surface should be marked dirty. | 1282 // entire surface should be marked dirty. |
1058 | 1283 |
(...skipping 16 matching lines...) Expand all Loading... |
1075 // The new surface bounds should be damaged entirely, even though only one of | 1300 // The new surface bounds should be damaged entirely, even though only one of |
1076 // the layers changed. | 1301 // the layers changed. |
1077 EXPECT_EQ(gfx::Rect(190, 190, 11, 23).ToString(), | 1302 EXPECT_EQ(gfx::Rect(190, 190, 11, 23).ToString(), |
1078 child_damage_rect.ToString()); | 1303 child_damage_rect.ToString()); |
1079 | 1304 |
1080 // Damage to the root surface should be the union of child1's *entire* render | 1305 // Damage to the root surface should be the union of child1's *entire* render |
1081 // surface (in target space), and its old exposed area (also in target | 1306 // surface (in target space), and its old exposed area (also in target |
1082 // space). | 1307 // space). |
1083 EXPECT_EQ(gfx::Rect(290, 290, 16, 23).ToString(), | 1308 EXPECT_EQ(gfx::Rect(290, 290, 16, 23).ToString(), |
1084 root_damage_rect.ToString()); | 1309 root_damage_rect.ToString()); |
| 1310 |
| 1311 EXPECT_TRUE(GetRenderSurface(root) |
| 1312 ->damage_tracker() |
| 1313 ->has_damage_from_contributing_content()); |
| 1314 EXPECT_TRUE(GetRenderSurface(child1) |
| 1315 ->damage_tracker() |
| 1316 ->has_damage_from_contributing_content()); |
1085 } | 1317 } |
1086 | 1318 |
1087 TEST_F(DamageTrackerTest, VerifyDamageForSurfaceChangeFromAncestorLayer) { | 1319 TEST_F(DamageTrackerTest, VerifyDamageForSurfaceChangeFromAncestorLayer) { |
1088 // An ancestor/owning layer changes that affects the position/transform of | 1320 // An ancestor/owning layer changes that affects the position/transform of |
1089 // the render surface. Note that in this case, the layer_property_changed flag | 1321 // the render surface. Note that in this case, the layer_property_changed flag |
1090 // already propagates to the subtree (tested in LayerImpltest), which damages | 1322 // already propagates to the subtree (tested in LayerImpltest), which damages |
1091 // the entire child1 surface, but the damage tracker still needs the correct | 1323 // the entire child1 surface, but the damage tracker still needs the correct |
1092 // logic to compute the exposed region on the root surface. | 1324 // logic to compute the exposed region on the root surface. |
1093 | 1325 |
1094 // TODO(shawnsingh): the expectations of this test case should change when we | 1326 // TODO(shawnsingh): the expectations of this test case should change when we |
(...skipping 20 matching lines...) Expand all Loading... |
1115 // The new surface bounds should be damaged entirely. | 1347 // The new surface bounds should be damaged entirely. |
1116 EXPECT_EQ(gfx::Rect(190, 190, 16, 18).ToString(), | 1348 EXPECT_EQ(gfx::Rect(190, 190, 16, 18).ToString(), |
1117 child_damage_rect.ToString()); | 1349 child_damage_rect.ToString()); |
1118 | 1350 |
1119 // The entire child1 surface and the old exposed child1 surface should damage | 1351 // The entire child1 surface and the old exposed child1 surface should damage |
1120 // the root surface. | 1352 // the root surface. |
1121 // - old child1 surface in target space: gfx::Rect(290, 290, 16, 18) | 1353 // - old child1 surface in target space: gfx::Rect(290, 290, 16, 18) |
1122 // - new child1 surface in target space: gfx::Rect(240, 240, 16, 18) | 1354 // - new child1 surface in target space: gfx::Rect(240, 240, 16, 18) |
1123 EXPECT_EQ(gfx::Rect(240, 240, 66, 68).ToString(), | 1355 EXPECT_EQ(gfx::Rect(240, 240, 66, 68).ToString(), |
1124 root_damage_rect.ToString()); | 1356 root_damage_rect.ToString()); |
| 1357 |
| 1358 EXPECT_TRUE(GetRenderSurface(root) |
| 1359 ->damage_tracker() |
| 1360 ->has_damage_from_contributing_content()); |
| 1361 EXPECT_FALSE(GetRenderSurface(child1) |
| 1362 ->damage_tracker() |
| 1363 ->has_damage_from_contributing_content()); |
1125 } | 1364 } |
1126 | 1365 |
1127 TEST_F(DamageTrackerTest, VerifyDamageForAddingAndRemovingRenderSurfaces) { | 1366 TEST_F(DamageTrackerTest, VerifyDamageForAddingAndRemovingRenderSurfaces) { |
1128 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 1367 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
1129 LayerImpl* child1 = root->test_properties()->children[0]; | 1368 LayerImpl* child1 = root->test_properties()->children[0]; |
1130 gfx::Rect child_damage_rect; | 1369 gfx::Rect child_damage_rect; |
1131 gfx::Rect root_damage_rect; | 1370 gfx::Rect root_damage_rect; |
1132 | 1371 |
1133 // CASE 1: If a descendant surface disappears, its entire old area becomes | 1372 // CASE 1: If a descendant surface disappears, its entire old area becomes |
1134 // exposed. | 1373 // exposed. |
1135 ClearDamageForAllSurfaces(root); | 1374 ClearDamageForAllSurfaces(root); |
1136 child1->test_properties()->force_render_surface = false; | 1375 child1->test_properties()->force_render_surface = false; |
1137 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1376 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
1138 EmulateDrawingOneFrame(root); | 1377 EmulateDrawingOneFrame(root); |
1139 | 1378 |
1140 // Sanity check that there is only one surface now. | 1379 // Sanity check that there is only one surface now. |
1141 ASSERT_EQ(GetRenderSurface(child1), GetRenderSurface(root)); | 1380 ASSERT_EQ(GetRenderSurface(child1), GetRenderSurface(root)); |
1142 ASSERT_EQ(4, GetRenderSurface(root)->num_contributors()); | 1381 ASSERT_EQ(4, GetRenderSurface(root)->num_contributors()); |
1143 | 1382 |
1144 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 1383 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
1145 &root_damage_rect)); | 1384 &root_damage_rect)); |
1146 EXPECT_EQ(gfx::Rect(290, 290, 16, 18).ToString(), | 1385 EXPECT_EQ(gfx::Rect(290, 290, 16, 18).ToString(), |
1147 root_damage_rect.ToString()); | 1386 root_damage_rect.ToString()); |
1148 | 1387 |
| 1388 EXPECT_TRUE(GetRenderSurface(root) |
| 1389 ->damage_tracker() |
| 1390 ->has_damage_from_contributing_content()); |
| 1391 |
1149 // CASE 2: If a descendant surface appears, its entire old area becomes | 1392 // CASE 2: If a descendant surface appears, its entire old area becomes |
1150 // exposed. | 1393 // exposed. |
1151 | 1394 |
1152 // Cycle one frame of no change, just to sanity check that the next rect is | 1395 // Cycle one frame of no change, just to sanity check that the next rect is |
1153 // not because of the old damage state. | 1396 // not because of the old damage state. |
1154 ClearDamageForAllSurfaces(root); | 1397 ClearDamageForAllSurfaces(root); |
1155 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1398 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
1156 EmulateDrawingOneFrame(root); | 1399 EmulateDrawingOneFrame(root); |
1157 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 1400 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
1158 &root_damage_rect)); | 1401 &root_damage_rect)); |
(...skipping 12 matching lines...) Expand all Loading... |
1171 EXPECT_EQ(2, GetRenderSurface(child1)->num_contributors()); | 1414 EXPECT_EQ(2, GetRenderSurface(child1)->num_contributors()); |
1172 | 1415 |
1173 EXPECT_TRUE(GetRenderSurface(child1)->damage_tracker()->GetDamageRectIfValid( | 1416 EXPECT_TRUE(GetRenderSurface(child1)->damage_tracker()->GetDamageRectIfValid( |
1174 &child_damage_rect)); | 1417 &child_damage_rect)); |
1175 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 1418 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
1176 &root_damage_rect)); | 1419 &root_damage_rect)); |
1177 EXPECT_EQ(gfx::Rect(190, 190, 16, 18).ToString(), | 1420 EXPECT_EQ(gfx::Rect(190, 190, 16, 18).ToString(), |
1178 child_damage_rect.ToString()); | 1421 child_damage_rect.ToString()); |
1179 EXPECT_EQ(gfx::Rect(290, 290, 16, 18).ToString(), | 1422 EXPECT_EQ(gfx::Rect(290, 290, 16, 18).ToString(), |
1180 root_damage_rect.ToString()); | 1423 root_damage_rect.ToString()); |
| 1424 EXPECT_TRUE(GetRenderSurface(root) |
| 1425 ->damage_tracker() |
| 1426 ->has_damage_from_contributing_content()); |
1181 } | 1427 } |
1182 | 1428 |
1183 TEST_F(DamageTrackerTest, VerifyNoDamageWhenNothingChanged) { | 1429 TEST_F(DamageTrackerTest, VerifyNoDamageWhenNothingChanged) { |
1184 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 1430 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
1185 LayerImpl* child1 = root->test_properties()->children[0]; | 1431 LayerImpl* child1 = root->test_properties()->children[0]; |
1186 gfx::Rect child_damage_rect; | 1432 gfx::Rect child_damage_rect; |
1187 gfx::Rect root_damage_rect; | 1433 gfx::Rect root_damage_rect; |
1188 | 1434 |
1189 // CASE 1: If nothing changes, the damage rect should be empty. | 1435 // CASE 1: If nothing changes, the damage rect should be empty. |
1190 // | 1436 // |
1191 ClearDamageForAllSurfaces(root); | 1437 ClearDamageForAllSurfaces(root); |
1192 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1438 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
1193 EmulateDrawingOneFrame(root); | 1439 EmulateDrawingOneFrame(root); |
1194 EXPECT_TRUE(GetRenderSurface(child1)->damage_tracker()->GetDamageRectIfValid( | 1440 EXPECT_TRUE(GetRenderSurface(child1)->damage_tracker()->GetDamageRectIfValid( |
1195 &child_damage_rect)); | 1441 &child_damage_rect)); |
1196 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 1442 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
1197 &root_damage_rect)); | 1443 &root_damage_rect)); |
1198 EXPECT_TRUE(child_damage_rect.IsEmpty()); | 1444 EXPECT_TRUE(child_damage_rect.IsEmpty()); |
1199 EXPECT_TRUE(root_damage_rect.IsEmpty()); | 1445 EXPECT_TRUE(root_damage_rect.IsEmpty()); |
| 1446 EXPECT_FALSE(GetRenderSurface(root) |
| 1447 ->damage_tracker() |
| 1448 ->has_damage_from_contributing_content()); |
1200 | 1449 |
1201 // CASE 2: If nothing changes twice in a row, the damage rect should still be | 1450 // CASE 2: If nothing changes twice in a row, the damage rect should still be |
1202 // empty. | 1451 // empty. |
1203 // | 1452 // |
1204 ClearDamageForAllSurfaces(root); | 1453 ClearDamageForAllSurfaces(root); |
1205 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1454 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
1206 EmulateDrawingOneFrame(root); | 1455 EmulateDrawingOneFrame(root); |
1207 EXPECT_TRUE(GetRenderSurface(child1)->damage_tracker()->GetDamageRectIfValid( | 1456 EXPECT_TRUE(GetRenderSurface(child1)->damage_tracker()->GetDamageRectIfValid( |
1208 &child_damage_rect)); | 1457 &child_damage_rect)); |
1209 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 1458 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
1210 &root_damage_rect)); | 1459 &root_damage_rect)); |
1211 EXPECT_TRUE(child_damage_rect.IsEmpty()); | 1460 EXPECT_TRUE(child_damage_rect.IsEmpty()); |
1212 EXPECT_TRUE(root_damage_rect.IsEmpty()); | 1461 EXPECT_TRUE(root_damage_rect.IsEmpty()); |
| 1462 EXPECT_FALSE(GetRenderSurface(root) |
| 1463 ->damage_tracker() |
| 1464 ->has_damage_from_contributing_content()); |
1213 } | 1465 } |
1214 | 1466 |
1215 TEST_F(DamageTrackerTest, VerifyNoDamageForUpdateRectThatDoesNotDrawContent) { | 1467 TEST_F(DamageTrackerTest, VerifyNoDamageForUpdateRectThatDoesNotDrawContent) { |
1216 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 1468 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
1217 LayerImpl* child1 = root->test_properties()->children[0]; | 1469 LayerImpl* child1 = root->test_properties()->children[0]; |
1218 gfx::Rect child_damage_rect; | 1470 gfx::Rect child_damage_rect; |
1219 gfx::Rect root_damage_rect; | 1471 gfx::Rect root_damage_rect; |
1220 | 1472 |
1221 // In our specific tree, the update rect of child1 should not cause any | 1473 // In our specific tree, the update rect of child1 should not cause any |
1222 // damage to any surface because it does not actually draw content. | 1474 // damage to any surface because it does not actually draw content. |
1223 ClearDamageForAllSurfaces(root); | 1475 ClearDamageForAllSurfaces(root); |
1224 child1->SetUpdateRect(gfx::Rect(1, 2)); | 1476 child1->SetUpdateRect(gfx::Rect(1, 2)); |
1225 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1477 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
1226 EmulateDrawingOneFrame(root); | 1478 EmulateDrawingOneFrame(root); |
1227 EXPECT_TRUE(GetRenderSurface(child1)->damage_tracker()->GetDamageRectIfValid( | 1479 EXPECT_TRUE(GetRenderSurface(child1)->damage_tracker()->GetDamageRectIfValid( |
1228 &child_damage_rect)); | 1480 &child_damage_rect)); |
1229 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 1481 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
1230 &root_damage_rect)); | 1482 &root_damage_rect)); |
1231 EXPECT_TRUE(child_damage_rect.IsEmpty()); | 1483 EXPECT_TRUE(child_damage_rect.IsEmpty()); |
1232 EXPECT_TRUE(root_damage_rect.IsEmpty()); | 1484 EXPECT_TRUE(root_damage_rect.IsEmpty()); |
| 1485 EXPECT_FALSE(GetRenderSurface(root) |
| 1486 ->damage_tracker() |
| 1487 ->has_damage_from_contributing_content()); |
1233 } | 1488 } |
1234 | 1489 |
1235 TEST_F(DamageTrackerTest, VerifyDamageForMask) { | 1490 TEST_F(DamageTrackerTest, VerifyDamageForMask) { |
1236 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 1491 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
1237 LayerImpl* child = root->test_properties()->children[0]; | 1492 LayerImpl* child = root->test_properties()->children[0]; |
1238 | 1493 |
1239 // In the current implementation of the damage tracker, changes to mask | 1494 // In the current implementation of the damage tracker, changes to mask |
1240 // layers should damage the entire corresponding surface. | 1495 // layers should damage the entire corresponding surface. |
1241 | 1496 |
1242 ClearDamageForAllSurfaces(root); | 1497 ClearDamageForAllSurfaces(root); |
(...skipping 26 matching lines...) Expand all Loading... |
1269 // surface. | 1524 // surface. |
1270 ClearDamageForAllSurfaces(root); | 1525 ClearDamageForAllSurfaces(root); |
1271 mask_layer->SetUpdateRect(gfx::Rect(1, 2, 3, 4)); | 1526 mask_layer->SetUpdateRect(gfx::Rect(1, 2, 3, 4)); |
1272 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1527 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
1273 EmulateDrawingOneFrame(root); | 1528 EmulateDrawingOneFrame(root); |
1274 gfx::Rect child_damage_rect; | 1529 gfx::Rect child_damage_rect; |
1275 EXPECT_TRUE(GetRenderSurface(child)->damage_tracker()->GetDamageRectIfValid( | 1530 EXPECT_TRUE(GetRenderSurface(child)->damage_tracker()->GetDamageRectIfValid( |
1276 &child_damage_rect)); | 1531 &child_damage_rect)); |
1277 EXPECT_EQ(gfx::Rect(30, 30).ToString(), child_damage_rect.ToString()); | 1532 EXPECT_EQ(gfx::Rect(30, 30).ToString(), child_damage_rect.ToString()); |
1278 | 1533 |
| 1534 EXPECT_TRUE(GetRenderSurface(root) |
| 1535 ->damage_tracker() |
| 1536 ->has_damage_from_contributing_content()); |
| 1537 EXPECT_FALSE(GetRenderSurface(child) |
| 1538 ->damage_tracker() |
| 1539 ->has_damage_from_contributing_content()); |
| 1540 |
1279 // CASE 2: a property change on the mask layer should damage the entire | 1541 // CASE 2: a property change on the mask layer should damage the entire |
1280 // target surface. | 1542 // target surface. |
1281 | 1543 |
1282 // Advance one frame without damage so that we know the damage rect is not | 1544 // Advance one frame without damage so that we know the damage rect is not |
1283 // leftover from the previous case. | 1545 // leftover from the previous case. |
1284 ClearDamageForAllSurfaces(root); | 1546 ClearDamageForAllSurfaces(root); |
1285 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1547 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
1286 EmulateDrawingOneFrame(root); | 1548 EmulateDrawingOneFrame(root); |
1287 EXPECT_TRUE(GetRenderSurface(child)->damage_tracker()->GetDamageRectIfValid( | 1549 EXPECT_TRUE(GetRenderSurface(child)->damage_tracker()->GetDamageRectIfValid( |
1288 &child_damage_rect)); | 1550 &child_damage_rect)); |
1289 EXPECT_TRUE(child_damage_rect.IsEmpty()); | 1551 EXPECT_TRUE(child_damage_rect.IsEmpty()); |
1290 | 1552 |
1291 // Then test the property change. | 1553 // Then test the property change. |
1292 ClearDamageForAllSurfaces(root); | 1554 ClearDamageForAllSurfaces(root); |
1293 mask_layer->NoteLayerPropertyChanged(); | 1555 mask_layer->NoteLayerPropertyChanged(); |
1294 | 1556 |
1295 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1557 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
1296 EmulateDrawingOneFrame(root); | 1558 EmulateDrawingOneFrame(root); |
1297 EXPECT_TRUE(GetRenderSurface(child)->damage_tracker()->GetDamageRectIfValid( | 1559 EXPECT_TRUE(GetRenderSurface(child)->damage_tracker()->GetDamageRectIfValid( |
1298 &child_damage_rect)); | 1560 &child_damage_rect)); |
1299 EXPECT_EQ(gfx::Rect(30, 30).ToString(), child_damage_rect.ToString()); | 1561 EXPECT_EQ(gfx::Rect(30, 30).ToString(), child_damage_rect.ToString()); |
1300 | 1562 |
| 1563 EXPECT_TRUE(GetRenderSurface(root) |
| 1564 ->damage_tracker() |
| 1565 ->has_damage_from_contributing_content()); |
| 1566 EXPECT_FALSE(GetRenderSurface(child) |
| 1567 ->damage_tracker() |
| 1568 ->has_damage_from_contributing_content()); |
| 1569 |
1301 // CASE 3: removing the mask also damages the entire target surface. | 1570 // CASE 3: removing the mask also damages the entire target surface. |
1302 // | 1571 // |
1303 | 1572 |
1304 // Advance one frame without damage so that we know the damage rect is not | 1573 // Advance one frame without damage so that we know the damage rect is not |
1305 // leftover from the previous case. | 1574 // leftover from the previous case. |
1306 ClearDamageForAllSurfaces(root); | 1575 ClearDamageForAllSurfaces(root); |
1307 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1576 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
1308 EmulateDrawingOneFrame(root); | 1577 EmulateDrawingOneFrame(root); |
1309 EXPECT_TRUE(GetRenderSurface(child)->damage_tracker()->GetDamageRectIfValid( | 1578 EXPECT_TRUE(GetRenderSurface(child)->damage_tracker()->GetDamageRectIfValid( |
1310 &child_damage_rect)); | 1579 &child_damage_rect)); |
1311 EXPECT_TRUE(child_damage_rect.IsEmpty()); | 1580 EXPECT_TRUE(child_damage_rect.IsEmpty()); |
1312 | 1581 |
1313 // Then test mask removal. | 1582 // Then test mask removal. |
1314 ClearDamageForAllSurfaces(root); | 1583 ClearDamageForAllSurfaces(root); |
1315 child->test_properties()->SetMaskLayer(nullptr); | 1584 child->test_properties()->SetMaskLayer(nullptr); |
1316 child->NoteLayerPropertyChanged(); | 1585 child->NoteLayerPropertyChanged(); |
1317 ASSERT_TRUE(child->LayerPropertyChanged()); | 1586 ASSERT_TRUE(child->LayerPropertyChanged()); |
1318 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1587 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
1319 EmulateDrawingOneFrame(root); | 1588 EmulateDrawingOneFrame(root); |
1320 | 1589 |
1321 // Sanity check that a render surface still exists. | 1590 // Sanity check that a render surface still exists. |
1322 ASSERT_TRUE(GetRenderSurface(child)); | 1591 ASSERT_TRUE(GetRenderSurface(child)); |
1323 | 1592 |
1324 EXPECT_TRUE(GetRenderSurface(child)->damage_tracker()->GetDamageRectIfValid( | 1593 EXPECT_TRUE(GetRenderSurface(child)->damage_tracker()->GetDamageRectIfValid( |
1325 &child_damage_rect)); | 1594 &child_damage_rect)); |
1326 EXPECT_EQ(gfx::Rect(30, 30).ToString(), child_damage_rect.ToString()); | 1595 EXPECT_EQ(gfx::Rect(30, 30).ToString(), child_damage_rect.ToString()); |
| 1596 |
| 1597 EXPECT_TRUE(GetRenderSurface(root) |
| 1598 ->damage_tracker() |
| 1599 ->has_damage_from_contributing_content()); |
1327 } | 1600 } |
1328 | 1601 |
1329 TEST_F(DamageTrackerTest, DamageWhenAddedExternally) { | 1602 TEST_F(DamageTrackerTest, DamageWhenAddedExternally) { |
1330 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 1603 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
1331 LayerImpl* child = root->test_properties()->children[0]; | 1604 LayerImpl* child = root->test_properties()->children[0]; |
1332 | 1605 |
1333 // Case 1: This test ensures that when the tracker is given damage, that | 1606 // Case 1: This test ensures that when the tracker is given damage, that |
1334 // it is included with any other partial damage. | 1607 // it is included with any other partial damage. |
1335 // | 1608 // |
1336 ClearDamageForAllSurfaces(root); | 1609 ClearDamageForAllSurfaces(root); |
1337 child->SetUpdateRect(gfx::Rect(10, 11, 12, 13)); | 1610 child->SetUpdateRect(gfx::Rect(10, 11, 12, 13)); |
1338 GetRenderSurface(root)->damage_tracker()->AddDamageNextUpdate( | 1611 GetRenderSurface(root)->damage_tracker()->AddDamageNextUpdate( |
1339 gfx::Rect(15, 16, 32, 33)); | 1612 gfx::Rect(15, 16, 32, 33)); |
1340 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1613 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
1341 EmulateDrawingOneFrame(root); | 1614 EmulateDrawingOneFrame(root); |
1342 gfx::Rect root_damage_rect; | 1615 gfx::Rect root_damage_rect; |
1343 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 1616 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
1344 &root_damage_rect)); | 1617 &root_damage_rect)); |
1345 EXPECT_EQ(gfx::UnionRects(gfx::Rect(15, 16, 32, 33), | 1618 EXPECT_EQ(gfx::UnionRects(gfx::Rect(15, 16, 32, 33), |
1346 gfx::Rect(100 + 10, 100 + 11, 12, 13)).ToString(), | 1619 gfx::Rect(100 + 10, 100 + 11, 12, 13)).ToString(), |
1347 root_damage_rect.ToString()); | 1620 root_damage_rect.ToString()); |
| 1621 EXPECT_TRUE(GetRenderSurface(root) |
| 1622 ->damage_tracker() |
| 1623 ->has_damage_from_contributing_content()); |
1348 | 1624 |
1349 // Case 2: An additional sanity check that adding damage works even when | 1625 // Case 2: An additional sanity check that adding damage works even when |
1350 // nothing on the layer tree changed. | 1626 // nothing on the layer tree changed. |
1351 // | 1627 // |
1352 ClearDamageForAllSurfaces(root); | 1628 ClearDamageForAllSurfaces(root); |
1353 GetRenderSurface(root)->damage_tracker()->AddDamageNextUpdate( | 1629 GetRenderSurface(root)->damage_tracker()->AddDamageNextUpdate( |
1354 gfx::Rect(30, 31, 14, 15)); | 1630 gfx::Rect(30, 31, 14, 15)); |
1355 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1631 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
1356 EmulateDrawingOneFrame(root); | 1632 EmulateDrawingOneFrame(root); |
1357 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 1633 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
1358 &root_damage_rect)); | 1634 &root_damage_rect)); |
1359 EXPECT_EQ(gfx::Rect(30, 31, 14, 15).ToString(), root_damage_rect.ToString()); | 1635 EXPECT_EQ(gfx::Rect(30, 31, 14, 15).ToString(), root_damage_rect.ToString()); |
| 1636 EXPECT_FALSE(GetRenderSurface(root) |
| 1637 ->damage_tracker() |
| 1638 ->has_damage_from_contributing_content()); |
1360 } | 1639 } |
1361 | 1640 |
1362 TEST_F(DamageTrackerTest, VerifyDamageWithNoContributingLayers) { | 1641 TEST_F(DamageTrackerTest, VerifyDamageWithNoContributingLayers) { |
1363 std::unique_ptr<LayerImpl> root = | 1642 std::unique_ptr<LayerImpl> root = |
1364 LayerImpl::Create(host_impl_.active_tree(), 1); | 1643 LayerImpl::Create(host_impl_.active_tree(), 1); |
1365 root->test_properties()->force_render_surface = true; | 1644 root->test_properties()->force_render_surface = true; |
1366 host_impl_.active_tree()->SetRootLayerForTesting(std::move(root)); | 1645 host_impl_.active_tree()->SetRootLayerForTesting(std::move(root)); |
1367 LayerImpl* root_ptr = host_impl_.active_tree()->root_layer_for_testing(); | 1646 LayerImpl* root_ptr = host_impl_.active_tree()->root_layer_for_testing(); |
1368 root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1647 root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true; |
1369 EmulateDrawingOneFrame(root_ptr); | 1648 EmulateDrawingOneFrame(root_ptr); |
1370 | 1649 |
1371 DCHECK_EQ(GetRenderSurface(root_ptr), root_ptr->render_target()); | 1650 DCHECK_EQ(GetRenderSurface(root_ptr), root_ptr->render_target()); |
1372 RenderSurfaceImpl* target_surface = GetRenderSurface(root_ptr); | 1651 RenderSurfaceImpl* target_surface = GetRenderSurface(root_ptr); |
1373 gfx::Rect damage_rect; | 1652 gfx::Rect damage_rect; |
1374 EXPECT_TRUE( | 1653 EXPECT_TRUE( |
1375 target_surface->damage_tracker()->GetDamageRectIfValid(&damage_rect)); | 1654 target_surface->damage_tracker()->GetDamageRectIfValid(&damage_rect)); |
1376 EXPECT_TRUE(damage_rect.IsEmpty()); | 1655 EXPECT_TRUE(damage_rect.IsEmpty()); |
| 1656 EXPECT_FALSE(GetRenderSurface(root_ptr) |
| 1657 ->damage_tracker() |
| 1658 ->has_damage_from_contributing_content()); |
1377 } | 1659 } |
1378 | 1660 |
1379 TEST_F(DamageTrackerTest, VerifyDamageAccumulatesUntilReset) { | 1661 TEST_F(DamageTrackerTest, VerifyDamageAccumulatesUntilReset) { |
1380 // If damage is not cleared, it should accumulate. | 1662 // If damage is not cleared, it should accumulate. |
1381 | 1663 |
1382 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 1664 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
1383 LayerImpl* child = root->test_properties()->children[0]; | 1665 LayerImpl* child = root->test_properties()->children[0]; |
1384 | 1666 |
1385 ClearDamageForAllSurfaces(root); | 1667 ClearDamageForAllSurfaces(root); |
1386 child->SetUpdateRect(gfx::Rect(10.f, 11.f, 1.f, 2.f)); | 1668 child->SetUpdateRect(gfx::Rect(10.f, 11.f, 1.f, 2.f)); |
1387 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1669 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
1388 EmulateDrawingOneFrame(root); | 1670 EmulateDrawingOneFrame(root); |
1389 | 1671 |
1390 // Sanity check damage after the first frame; this isnt the actual test yet. | 1672 // Sanity check damage after the first frame; this isnt the actual test yet. |
1391 gfx::Rect root_damage_rect; | 1673 gfx::Rect root_damage_rect; |
1392 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 1674 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
1393 &root_damage_rect)); | 1675 &root_damage_rect)); |
1394 EXPECT_EQ(gfx::Rect(110, 111, 1, 2).ToString(), root_damage_rect.ToString()); | 1676 EXPECT_EQ(gfx::Rect(110, 111, 1, 2).ToString(), root_damage_rect.ToString()); |
| 1677 EXPECT_TRUE(GetRenderSurface(root) |
| 1678 ->damage_tracker() |
| 1679 ->has_damage_from_contributing_content()); |
1395 | 1680 |
1396 // New damage, without having cleared the previous damage, should be unioned | 1681 // New damage, without having cleared the previous damage, should be unioned |
1397 // to the previous one. | 1682 // to the previous one. |
1398 child->SetUpdateRect(gfx::Rect(20, 25, 1, 2)); | 1683 child->SetUpdateRect(gfx::Rect(20, 25, 1, 2)); |
1399 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1684 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
1400 EmulateDrawingOneFrame(root); | 1685 EmulateDrawingOneFrame(root); |
1401 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 1686 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
1402 &root_damage_rect)); | 1687 &root_damage_rect)); |
1403 EXPECT_EQ(gfx::Rect(110, 111, 11, 16).ToString(), | 1688 EXPECT_EQ(gfx::Rect(110, 111, 11, 16).ToString(), |
1404 root_damage_rect.ToString()); | 1689 root_damage_rect.ToString()); |
| 1690 EXPECT_TRUE(GetRenderSurface(root) |
| 1691 ->damage_tracker() |
| 1692 ->has_damage_from_contributing_content()); |
1405 | 1693 |
1406 // If we notify the damage tracker that we drew the damaged area, then damage | 1694 // If we notify the damage tracker that we drew the damaged area, then damage |
1407 // should be emptied. | 1695 // should be emptied. |
1408 GetRenderSurface(root)->damage_tracker()->DidDrawDamagedArea(); | 1696 GetRenderSurface(root)->damage_tracker()->DidDrawDamagedArea(); |
1409 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 1697 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
1410 &root_damage_rect)); | 1698 &root_damage_rect)); |
1411 EXPECT_TRUE(root_damage_rect.IsEmpty()); | 1699 EXPECT_TRUE(root_damage_rect.IsEmpty()); |
| 1700 EXPECT_FALSE(GetRenderSurface(root) |
| 1701 ->damage_tracker() |
| 1702 ->has_damage_from_contributing_content()); |
1412 | 1703 |
1413 // Damage should remain empty even after one frame, since there's yet no new | 1704 // Damage should remain empty even after one frame, since there's yet no new |
1414 // damage. | 1705 // damage. |
1415 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1706 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
1416 EmulateDrawingOneFrame(root); | 1707 EmulateDrawingOneFrame(root); |
1417 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 1708 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
1418 &root_damage_rect)); | 1709 &root_damage_rect)); |
1419 EXPECT_TRUE(root_damage_rect.IsEmpty()); | 1710 EXPECT_TRUE(root_damage_rect.IsEmpty()); |
| 1711 EXPECT_FALSE(GetRenderSurface(root) |
| 1712 ->damage_tracker() |
| 1713 ->has_damage_from_contributing_content()); |
1420 } | 1714 } |
1421 | 1715 |
1422 TEST_F(DamageTrackerTest, HugeDamageRect) { | 1716 TEST_F(DamageTrackerTest, HugeDamageRect) { |
1423 // This number is so large that we start losting floating point accuracy. | 1717 // This number is so large that we start losting floating point accuracy. |
1424 const int kBigNumber = 900000000; | 1718 const int kBigNumber = 900000000; |
1425 // Walk over a range to find floating point inaccuracy boundaries that move | 1719 // Walk over a range to find floating point inaccuracy boundaries that move |
1426 // toward the wrong direction. | 1720 // toward the wrong direction. |
1427 const int kRange = 5000; | 1721 const int kRange = 5000; |
1428 | 1722 |
1429 for (int i = 0; i < kRange; ++i) { | 1723 for (int i = 0; i < kRange; ++i) { |
(...skipping 16 matching lines...) Expand all Loading... |
1446 EmulateDrawingOneFrame(root, device_scale_factor); | 1740 EmulateDrawingOneFrame(root, device_scale_factor); |
1447 | 1741 |
1448 // The expected damage should cover the visible part of the child layer, | 1742 // The expected damage should cover the visible part of the child layer, |
1449 // which is (0, 0, i, i) in the viewport. | 1743 // which is (0, 0, i, i) in the viewport. |
1450 gfx::Rect root_damage_rect; | 1744 gfx::Rect root_damage_rect; |
1451 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 1745 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
1452 &root_damage_rect)); | 1746 &root_damage_rect)); |
1453 gfx::Rect damage_we_care_about = gfx::Rect(i, i); | 1747 gfx::Rect damage_we_care_about = gfx::Rect(i, i); |
1454 EXPECT_LE(damage_we_care_about.right(), root_damage_rect.right()); | 1748 EXPECT_LE(damage_we_care_about.right(), root_damage_rect.right()); |
1455 EXPECT_LE(damage_we_care_about.bottom(), root_damage_rect.bottom()); | 1749 EXPECT_LE(damage_we_care_about.bottom(), root_damage_rect.bottom()); |
| 1750 EXPECT_TRUE(GetRenderSurface(root) |
| 1751 ->damage_tracker() |
| 1752 ->has_damage_from_contributing_content()); |
1456 } | 1753 } |
1457 } | 1754 } |
1458 | 1755 |
1459 TEST_F(DamageTrackerTest, DamageRectTooBig) { | 1756 TEST_F(DamageTrackerTest, DamageRectTooBig) { |
1460 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(2); | 1757 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(2); |
1461 LayerImpl* child1 = root->test_properties()->children[0]; | 1758 LayerImpl* child1 = root->test_properties()->children[0]; |
1462 LayerImpl* child2 = root->test_properties()->children[1]; | 1759 LayerImpl* child2 = root->test_properties()->children[1]; |
1463 | 1760 |
1464 // Really far left. | 1761 // Really far left. |
1465 child1->SetPosition(gfx::PointF(std::numeric_limits<int>::min() + 100, 0)); | 1762 child1->SetPosition(gfx::PointF(std::numeric_limits<int>::min() + 100, 0)); |
1466 child1->SetBounds(gfx::Size(1, 1)); | 1763 child1->SetBounds(gfx::Size(1, 1)); |
1467 | 1764 |
1468 // Really far right. | 1765 // Really far right. |
1469 child2->SetPosition(gfx::PointF(std::numeric_limits<int>::max() - 100, 0)); | 1766 child2->SetPosition(gfx::PointF(std::numeric_limits<int>::max() - 100, 0)); |
1470 child2->SetBounds(gfx::Size(1, 1)); | 1767 child2->SetBounds(gfx::Size(1, 1)); |
1471 | 1768 |
1472 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1769 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
1473 float device_scale_factor = 1.f; | 1770 float device_scale_factor = 1.f; |
1474 EmulateDrawingOneFrame(root, device_scale_factor); | 1771 EmulateDrawingOneFrame(root, device_scale_factor); |
1475 | 1772 |
1476 // The expected damage would be too large to store in a gfx::Rect, so we | 1773 // The expected damage would be too large to store in a gfx::Rect, so we |
1477 // should damage everything (ie, we don't have a valid rect). | 1774 // should damage everything (ie, we don't have a valid rect). |
1478 gfx::Rect damage_rect; | 1775 gfx::Rect damage_rect; |
1479 EXPECT_FALSE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 1776 EXPECT_FALSE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
1480 &damage_rect)); | 1777 &damage_rect)); |
1481 EXPECT_EQ(GetRenderSurface(root)->content_rect(), | 1778 EXPECT_EQ(GetRenderSurface(root)->content_rect(), |
1482 GetRenderSurface(root)->GetDamageRect()); | 1779 GetRenderSurface(root)->GetDamageRect()); |
| 1780 EXPECT_TRUE(GetRenderSurface(root) |
| 1781 ->damage_tracker() |
| 1782 ->has_damage_from_contributing_content()); |
1483 } | 1783 } |
1484 | 1784 |
1485 TEST_F(DamageTrackerTest, DamageRectTooBigWithFilter) { | 1785 TEST_F(DamageTrackerTest, DamageRectTooBigWithFilter) { |
1486 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(2); | 1786 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(2); |
1487 LayerImpl* child1 = root->test_properties()->children[0]; | 1787 LayerImpl* child1 = root->test_properties()->children[0]; |
1488 LayerImpl* child2 = root->test_properties()->children[1]; | 1788 LayerImpl* child2 = root->test_properties()->children[1]; |
1489 | 1789 |
1490 FilterOperations filters; | 1790 FilterOperations filters; |
1491 filters.Append(FilterOperation::CreateBlurFilter(5.f)); | 1791 filters.Append(FilterOperation::CreateBlurFilter(5.f)); |
1492 root->SetDrawsContent(true); | 1792 root->SetDrawsContent(true); |
(...skipping 11 matching lines...) Expand all Loading... |
1504 float device_scale_factor = 1.f; | 1804 float device_scale_factor = 1.f; |
1505 EmulateDrawingOneFrame(root, device_scale_factor); | 1805 EmulateDrawingOneFrame(root, device_scale_factor); |
1506 | 1806 |
1507 // The expected damage would be too large to store in a gfx::Rect, so we | 1807 // The expected damage would be too large to store in a gfx::Rect, so we |
1508 // should damage everything (ie, we don't have a valid rect). | 1808 // should damage everything (ie, we don't have a valid rect). |
1509 gfx::Rect damage_rect; | 1809 gfx::Rect damage_rect; |
1510 EXPECT_FALSE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 1810 EXPECT_FALSE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
1511 &damage_rect)); | 1811 &damage_rect)); |
1512 EXPECT_EQ(GetRenderSurface(root)->content_rect(), | 1812 EXPECT_EQ(GetRenderSurface(root)->content_rect(), |
1513 GetRenderSurface(root)->GetDamageRect()); | 1813 GetRenderSurface(root)->GetDamageRect()); |
| 1814 EXPECT_TRUE(GetRenderSurface(root) |
| 1815 ->damage_tracker() |
| 1816 ->has_damage_from_contributing_content()); |
1514 } | 1817 } |
1515 | 1818 |
1516 TEST_F(DamageTrackerTest, DamageRectTooBigInRenderSurface) { | 1819 TEST_F(DamageTrackerTest, DamageRectTooBigInRenderSurface) { |
1517 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 1820 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
1518 LayerImpl* child1 = root->test_properties()->children[0]; | 1821 LayerImpl* child1 = root->test_properties()->children[0]; |
1519 LayerImpl* grandchild1 = child1->test_properties()->children[0]; | 1822 LayerImpl* grandchild1 = child1->test_properties()->children[0]; |
1520 LayerImpl* grandchild2 = child1->test_properties()->children[1]; | 1823 LayerImpl* grandchild2 = child1->test_properties()->children[1]; |
1521 | 1824 |
1522 // Really far left. | 1825 // Really far left. |
1523 grandchild1->SetPosition( | 1826 grandchild1->SetPosition( |
(...skipping 28 matching lines...) Expand all Loading... |
1552 | 1855 |
1553 // However, the root should just use the child1 render surface's content rect | 1856 // However, the root should just use the child1 render surface's content rect |
1554 // as damage. | 1857 // as damage. |
1555 ASSERT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 1858 ASSERT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
1556 &damage_rect)); | 1859 &damage_rect)); |
1557 EXPECT_TRUE(damage_rect.Contains(GetRenderSurface(root)->content_rect())); | 1860 EXPECT_TRUE(damage_rect.Contains(GetRenderSurface(root)->content_rect())); |
1558 EXPECT_TRUE(damage_rect.Contains( | 1861 EXPECT_TRUE(damage_rect.Contains( |
1559 gfx::ToEnclosingRect(GetRenderSurface(child1)->DrawableContentRect()))); | 1862 gfx::ToEnclosingRect(GetRenderSurface(child1)->DrawableContentRect()))); |
1560 EXPECT_EQ(damage_rect, GetRenderSurface(root)->GetDamageRect()); | 1863 EXPECT_EQ(damage_rect, GetRenderSurface(root)->GetDamageRect()); |
1561 | 1864 |
| 1865 EXPECT_TRUE(GetRenderSurface(root) |
| 1866 ->damage_tracker() |
| 1867 ->has_damage_from_contributing_content()); |
| 1868 EXPECT_TRUE(GetRenderSurface(child1) |
| 1869 ->damage_tracker() |
| 1870 ->has_damage_from_contributing_content()); |
| 1871 |
1562 // Add new damage, without changing properties, which goes down a different | 1872 // Add new damage, without changing properties, which goes down a different |
1563 // path in the damage tracker. | 1873 // path in the damage tracker. |
1564 root->layer_tree_impl()->ResetAllChangeTracking(); | 1874 root->layer_tree_impl()->ResetAllChangeTracking(); |
1565 grandchild1->AddDamageRect(gfx::Rect(grandchild1->bounds())); | 1875 grandchild1->AddDamageRect(gfx::Rect(grandchild1->bounds())); |
1566 grandchild2->AddDamageRect(gfx::Rect(grandchild1->bounds())); | 1876 grandchild2->AddDamageRect(gfx::Rect(grandchild1->bounds())); |
1567 | 1877 |
1568 // Recompute all damage / properties. | 1878 // Recompute all damage / properties. |
1569 render_surface_list.clear(); | 1879 render_surface_list.clear(); |
1570 ExecuteCalculateDrawProperties(root, device_scale_factor, | 1880 ExecuteCalculateDrawProperties(root, device_scale_factor, |
1571 &render_surface_list); | 1881 &render_surface_list); |
1572 DamageTracker::UpdateDamageTracking(host_impl_.active_tree(), | 1882 DamageTracker::UpdateDamageTracking(host_impl_.active_tree(), |
1573 render_surface_list); | 1883 render_surface_list); |
1574 | 1884 |
1575 // Child1 should still not have a valid rect, since the union of the damage of | 1885 // Child1 should still not have a valid rect, since the union of the damage of |
1576 // its children is not representable by a single rect. | 1886 // its children is not representable by a single rect. |
1577 EXPECT_FALSE(GetRenderSurface(child1)->damage_tracker()->GetDamageRectIfValid( | 1887 EXPECT_FALSE(GetRenderSurface(child1)->damage_tracker()->GetDamageRectIfValid( |
1578 &damage_rect)); | 1888 &damage_rect)); |
1579 EXPECT_EQ(GetRenderSurface(child1)->content_rect(), | 1889 EXPECT_EQ(GetRenderSurface(child1)->content_rect(), |
1580 GetRenderSurface(child1)->GetDamageRect()); | 1890 GetRenderSurface(child1)->GetDamageRect()); |
1581 | 1891 |
1582 // Root should have valid damage and contain both its content rect and the | 1892 // Root should have valid damage and contain both its content rect and the |
1583 // drawable content rect of child1. | 1893 // drawable content rect of child1. |
1584 ASSERT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 1894 ASSERT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
1585 &damage_rect)); | 1895 &damage_rect)); |
1586 EXPECT_TRUE(damage_rect.Contains(GetRenderSurface(root)->content_rect())); | 1896 EXPECT_TRUE(damage_rect.Contains(GetRenderSurface(root)->content_rect())); |
1587 EXPECT_TRUE(damage_rect.Contains( | 1897 EXPECT_TRUE(damage_rect.Contains( |
1588 gfx::ToEnclosingRect(GetRenderSurface(child1)->DrawableContentRect()))); | 1898 gfx::ToEnclosingRect(GetRenderSurface(child1)->DrawableContentRect()))); |
1589 EXPECT_EQ(damage_rect, GetRenderSurface(root)->GetDamageRect()); | 1899 EXPECT_EQ(damage_rect, GetRenderSurface(root)->GetDamageRect()); |
| 1900 |
| 1901 EXPECT_TRUE(GetRenderSurface(root) |
| 1902 ->damage_tracker() |
| 1903 ->has_damage_from_contributing_content()); |
| 1904 EXPECT_TRUE(GetRenderSurface(child1) |
| 1905 ->damage_tracker() |
| 1906 ->has_damage_from_contributing_content()); |
1590 } | 1907 } |
1591 | 1908 |
1592 TEST_F(DamageTrackerTest, DamageRectTooBigInRenderSurfaceWithFilter) { | 1909 TEST_F(DamageTrackerTest, DamageRectTooBigInRenderSurfaceWithFilter) { |
1593 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 1910 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
1594 LayerImpl* child1 = root->test_properties()->children[0]; | 1911 LayerImpl* child1 = root->test_properties()->children[0]; |
1595 LayerImpl* grandchild1 = child1->test_properties()->children[0]; | 1912 LayerImpl* grandchild1 = child1->test_properties()->children[0]; |
1596 LayerImpl* grandchild2 = child1->test_properties()->children[1]; | 1913 LayerImpl* grandchild2 = child1->test_properties()->children[1]; |
1597 | 1914 |
1598 // Set up a moving pixels filter on the child. | 1915 // Set up a moving pixels filter on the child. |
1599 FilterOperations filters; | 1916 FilterOperations filters; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1634 | 1951 |
1635 // However, the root should just use the child1 render surface's content rect | 1952 // However, the root should just use the child1 render surface's content rect |
1636 // as damage. | 1953 // as damage. |
1637 ASSERT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 1954 ASSERT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
1638 &damage_rect)); | 1955 &damage_rect)); |
1639 EXPECT_TRUE(damage_rect.Contains(GetRenderSurface(root)->content_rect())); | 1956 EXPECT_TRUE(damage_rect.Contains(GetRenderSurface(root)->content_rect())); |
1640 EXPECT_TRUE(damage_rect.Contains( | 1957 EXPECT_TRUE(damage_rect.Contains( |
1641 gfx::ToEnclosingRect(GetRenderSurface(child1)->DrawableContentRect()))); | 1958 gfx::ToEnclosingRect(GetRenderSurface(child1)->DrawableContentRect()))); |
1642 EXPECT_EQ(damage_rect, GetRenderSurface(root)->GetDamageRect()); | 1959 EXPECT_EQ(damage_rect, GetRenderSurface(root)->GetDamageRect()); |
1643 | 1960 |
| 1961 EXPECT_TRUE(GetRenderSurface(root) |
| 1962 ->damage_tracker() |
| 1963 ->has_damage_from_contributing_content()); |
| 1964 EXPECT_TRUE(GetRenderSurface(child1) |
| 1965 ->damage_tracker() |
| 1966 ->has_damage_from_contributing_content()); |
| 1967 |
1644 // Add new damage, without changing properties, which goes down a different | 1968 // Add new damage, without changing properties, which goes down a different |
1645 // path in the damage tracker. | 1969 // path in the damage tracker. |
1646 root->layer_tree_impl()->ResetAllChangeTracking(); | 1970 root->layer_tree_impl()->ResetAllChangeTracking(); |
1647 grandchild1->AddDamageRect(gfx::Rect(grandchild1->bounds())); | 1971 grandchild1->AddDamageRect(gfx::Rect(grandchild1->bounds())); |
1648 grandchild2->AddDamageRect(gfx::Rect(grandchild1->bounds())); | 1972 grandchild2->AddDamageRect(gfx::Rect(grandchild1->bounds())); |
1649 | 1973 |
1650 // Recompute all damage / properties. | 1974 // Recompute all damage / properties. |
1651 render_surface_list.clear(); | 1975 render_surface_list.clear(); |
1652 ExecuteCalculateDrawProperties(root, device_scale_factor, | 1976 ExecuteCalculateDrawProperties(root, device_scale_factor, |
1653 &render_surface_list); | 1977 &render_surface_list); |
1654 DamageTracker::UpdateDamageTracking(host_impl_.active_tree(), | 1978 DamageTracker::UpdateDamageTracking(host_impl_.active_tree(), |
1655 render_surface_list); | 1979 render_surface_list); |
1656 | 1980 |
1657 // Child1 should still not have a valid rect, since the union of the damage of | 1981 // Child1 should still not have a valid rect, since the union of the damage of |
1658 // its children is not representable by a single rect. | 1982 // its children is not representable by a single rect. |
1659 EXPECT_FALSE(GetRenderSurface(child1)->damage_tracker()->GetDamageRectIfValid( | 1983 EXPECT_FALSE(GetRenderSurface(child1)->damage_tracker()->GetDamageRectIfValid( |
1660 &damage_rect)); | 1984 &damage_rect)); |
1661 EXPECT_EQ(GetRenderSurface(child1)->content_rect(), | 1985 EXPECT_EQ(GetRenderSurface(child1)->content_rect(), |
1662 GetRenderSurface(child1)->GetDamageRect()); | 1986 GetRenderSurface(child1)->GetDamageRect()); |
1663 | 1987 |
1664 // Root should have valid damage and contain both its content rect and the | 1988 // Root should have valid damage and contain both its content rect and the |
1665 // drawable content rect of child1. | 1989 // drawable content rect of child1. |
1666 ASSERT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 1990 ASSERT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
1667 &damage_rect)); | 1991 &damage_rect)); |
1668 EXPECT_TRUE(damage_rect.Contains(GetRenderSurface(root)->content_rect())); | 1992 EXPECT_TRUE(damage_rect.Contains(GetRenderSurface(root)->content_rect())); |
1669 EXPECT_TRUE(damage_rect.Contains( | 1993 EXPECT_TRUE(damage_rect.Contains( |
1670 gfx::ToEnclosingRect(GetRenderSurface(child1)->DrawableContentRect()))); | 1994 gfx::ToEnclosingRect(GetRenderSurface(child1)->DrawableContentRect()))); |
1671 EXPECT_EQ(damage_rect, GetRenderSurface(root)->GetDamageRect()); | 1995 EXPECT_EQ(damage_rect, GetRenderSurface(root)->GetDamageRect()); |
| 1996 |
| 1997 EXPECT_TRUE(GetRenderSurface(root) |
| 1998 ->damage_tracker() |
| 1999 ->has_damage_from_contributing_content()); |
| 2000 EXPECT_TRUE(GetRenderSurface(child1) |
| 2001 ->damage_tracker() |
| 2002 ->has_damage_from_contributing_content()); |
1672 } | 2003 } |
1673 | 2004 |
1674 } // namespace | 2005 } // namespace |
1675 } // namespace cc | 2006 } // namespace cc |
OLD | NEW |