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 will damage the whole surface, but not conrresponding |
| 703 // render surface. |
547 ClearDamageForAllSurfaces(root); | 704 ClearDamageForAllSurfaces(root); |
548 surface->test_properties()->filters = filters; | 705 surface->test_properties()->filters = filters; |
549 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 706 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
550 EmulateDrawingOneFrame(root); | 707 EmulateDrawingOneFrame(root); |
| 708 EXPECT_TRUE(GetRenderSurface(root) |
| 709 ->damage_tracker() |
| 710 ->has_damage_from_contributing_content()); |
| 711 EXPECT_FALSE(GetRenderSurface(surface) |
| 712 ->damage_tracker() |
| 713 ->has_damage_from_contributing_content()); |
551 | 714 |
552 // Setting the update rect should cause the corresponding damage to the | 715 // Setting the update rect should cause the corresponding damage to the |
553 // surface, blurred based on the size of the blur filter. | 716 // surface, blurred based on the size of the blur filter. |
554 ClearDamageForAllSurfaces(root); | 717 ClearDamageForAllSurfaces(root); |
555 child->SetUpdateRect(gfx::Rect(1, 2, 3, 4)); | 718 child->SetUpdateRect(gfx::Rect(1, 2, 3, 4)); |
556 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 719 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
557 EmulateDrawingOneFrame(root); | 720 EmulateDrawingOneFrame(root); |
558 | 721 |
559 // Damage position on the surface should be: position of update_rect (1, 2) | 722 // 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 | 723 // relative to the child (300, 300), but expanded by the blur outsets |
561 // (15, since the blur radius is 5). | 724 // (15, since the blur radius is 5). |
562 gfx::Rect root_damage_rect; | 725 gfx::Rect root_damage_rect; |
563 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 726 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
564 &root_damage_rect)); | 727 &root_damage_rect)); |
565 EXPECT_EQ(gfx::Rect(286, 287, 33, 34), root_damage_rect); | 728 EXPECT_EQ(gfx::Rect(286, 287, 33, 34), root_damage_rect); |
| 729 EXPECT_TRUE(GetRenderSurface(root) |
| 730 ->damage_tracker() |
| 731 ->has_damage_from_contributing_content()); |
| 732 EXPECT_TRUE(GetRenderSurface(surface) |
| 733 ->damage_tracker() |
| 734 ->has_damage_from_contributing_content()); |
566 } | 735 } |
567 | 736 |
568 TEST_F(DamageTrackerTest, VerifyDamageForImageFilter) { | 737 TEST_F(DamageTrackerTest, VerifyDamageForImageFilter) { |
569 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 738 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
570 LayerImpl* child = root->test_properties()->children[0]; | 739 LayerImpl* child = root->test_properties()->children[0]; |
571 gfx::Rect root_damage_rect, child_damage_rect; | 740 gfx::Rect root_damage_rect, child_damage_rect; |
572 | 741 |
573 // Allow us to set damage on child too. | 742 // Allow us to set damage on child too. |
574 child->SetDrawsContent(true); | 743 child->SetDrawsContent(true); |
575 | 744 |
576 FilterOperations filters; | 745 FilterOperations filters; |
577 filters.Append(FilterOperation::CreateReferenceFilter( | 746 filters.Append(FilterOperation::CreateReferenceFilter( |
578 SkBlurImageFilter::Make(2, 2, nullptr))); | 747 SkBlurImageFilter::Make(2, 2, nullptr))); |
579 | 748 |
580 // Setting the filter will damage the whole surface. | 749 // Setting the filter will damage the whole surface. |
581 ClearDamageForAllSurfaces(root); | |
582 child->test_properties()->force_render_surface = true; | 750 child->test_properties()->force_render_surface = true; |
583 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 751 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
584 EmulateDrawingOneFrame(root); | 752 EmulateDrawingOneFrame(root); |
| 753 ClearDamageForAllSurfaces(root); |
585 child->layer_tree_impl()->SetFilterMutated(child->element_id(), filters); | 754 child->layer_tree_impl()->SetFilterMutated(child->element_id(), filters); |
586 EmulateDrawingOneFrame(root); | 755 EmulateDrawingOneFrame(root); |
587 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 756 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
588 &root_damage_rect)); | 757 &root_damage_rect)); |
589 EXPECT_TRUE(GetRenderSurface(child)->damage_tracker()->GetDamageRectIfValid( | 758 EXPECT_TRUE(GetRenderSurface(child)->damage_tracker()->GetDamageRectIfValid( |
590 &child_damage_rect)); | 759 &child_damage_rect)); |
591 | 760 |
592 // gfx::Rect(100, 100, 30, 30), expanded by 6px for the 2px blur filter. | 761 // 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); | 762 EXPECT_EQ(gfx::Rect(94, 94, 42, 42), root_damage_rect); |
594 | 763 |
595 // gfx::Rect(0, 0, 30, 30), expanded by 6px for the 2px blur filter. | 764 // 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); | 765 EXPECT_EQ(gfx::Rect(-6, -6, 42, 42), child_damage_rect); |
597 | 766 |
| 767 EXPECT_TRUE(GetRenderSurface(root) |
| 768 ->damage_tracker() |
| 769 ->has_damage_from_contributing_content()); |
| 770 EXPECT_FALSE(GetRenderSurface(child) |
| 771 ->damage_tracker() |
| 772 ->has_damage_from_contributing_content()); |
| 773 |
598 // CASE 1: Setting the update rect should damage the whole surface (for now) | 774 // CASE 1: Setting the update rect should damage the whole surface (for now) |
599 ClearDamageForAllSurfaces(root); | 775 ClearDamageForAllSurfaces(root); |
600 child->SetUpdateRect(gfx::Rect(1, 1)); | 776 child->SetUpdateRect(gfx::Rect(1, 1)); |
601 EmulateDrawingOneFrame(root); | 777 EmulateDrawingOneFrame(root); |
602 | 778 |
603 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 779 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
604 &root_damage_rect)); | 780 &root_damage_rect)); |
605 EXPECT_TRUE(GetRenderSurface(child)->damage_tracker()->GetDamageRectIfValid( | 781 EXPECT_TRUE(GetRenderSurface(child)->damage_tracker()->GetDamageRectIfValid( |
606 &child_damage_rect)); | 782 &child_damage_rect)); |
607 | 783 |
608 // gfx::Rect(100, 100, 1, 1), expanded by 6px for the 2px blur filter. | 784 // 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); | 785 EXPECT_EQ(gfx::Rect(94, 94, 13, 13), root_damage_rect); |
610 | 786 |
611 // gfx::Rect(0, 0, 1, 1), expanded by 6px for the 2px blur filter. | 787 // 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); | 788 EXPECT_EQ(gfx::Rect(-6, -6, 13, 13), child_damage_rect); |
| 789 |
| 790 EXPECT_TRUE(GetRenderSurface(root) |
| 791 ->damage_tracker() |
| 792 ->has_damage_from_contributing_content()); |
| 793 EXPECT_TRUE(GetRenderSurface(child) |
| 794 ->damage_tracker() |
| 795 ->has_damage_from_contributing_content()); |
613 } | 796 } |
614 | 797 |
615 TEST_F(DamageTrackerTest, VerifyDamageForTransformedImageFilter) { | 798 TEST_F(DamageTrackerTest, VerifyDamageForTransformedImageFilter) { |
616 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 799 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
617 LayerImpl* child = root->test_properties()->children[0]; | 800 LayerImpl* child = root->test_properties()->children[0]; |
618 gfx::Rect root_damage_rect, child_damage_rect; | 801 gfx::Rect root_damage_rect, child_damage_rect; |
619 | 802 |
620 // Allow us to set damage on child too. | 803 // Allow us to set damage on child too. |
621 child->SetDrawsContent(true); | 804 child->SetDrawsContent(true); |
622 | 805 |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
868 EmulateDrawingOneFrame(root); | 1051 EmulateDrawingOneFrame(root); |
869 | 1052 |
870 // Sanity check - all 3 layers should be on the same render surface; render | 1053 // Sanity check - all 3 layers should be on the same render surface; render |
871 // surfaces are tested elsewhere. | 1054 // surfaces are tested elsewhere. |
872 ASSERT_EQ(3, GetRenderSurface(root)->num_contributors()); | 1055 ASSERT_EQ(3, GetRenderSurface(root)->num_contributors()); |
873 | 1056 |
874 gfx::Rect root_damage_rect; | 1057 gfx::Rect root_damage_rect; |
875 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 1058 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
876 &root_damage_rect)); | 1059 &root_damage_rect)); |
877 EXPECT_EQ(gfx::Rect(400, 380, 6, 8).ToString(), root_damage_rect.ToString()); | 1060 EXPECT_EQ(gfx::Rect(400, 380, 6, 8).ToString(), root_damage_rect.ToString()); |
| 1061 EXPECT_TRUE(GetRenderSurface(root) |
| 1062 ->damage_tracker() |
| 1063 ->has_damage_from_contributing_content()); |
878 | 1064 |
879 // CASE 2: If the layer is removed, its entire old layer becomes exposed, not | 1065 // CASE 2: If the layer is removed, its entire old layer becomes exposed, not |
880 // just the last update rect. | 1066 // just the last update rect. |
881 | 1067 |
882 // Advance one frame without damage so that we know the damage rect is not | 1068 // Advance one frame without damage so that we know the damage rect is not |
883 // leftover from the previous case. | 1069 // leftover from the previous case. |
884 ClearDamageForAllSurfaces(root); | 1070 ClearDamageForAllSurfaces(root); |
885 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1071 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
886 EmulateDrawingOneFrame(root); | 1072 EmulateDrawingOneFrame(root); |
887 | 1073 |
888 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 1074 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
889 &root_damage_rect)); | 1075 &root_damage_rect)); |
890 EXPECT_TRUE(root_damage_rect.IsEmpty()); | 1076 EXPECT_TRUE(root_damage_rect.IsEmpty()); |
891 | 1077 |
892 // Then, test removing child1. | 1078 // Then, test removing child1. |
893 root->test_properties()->RemoveChild(child1); | 1079 root->test_properties()->RemoveChild(child1); |
894 child1 = NULL; | 1080 child1 = NULL; |
895 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1081 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
896 EmulateDrawingOneFrame(root); | 1082 EmulateDrawingOneFrame(root); |
897 | 1083 |
898 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 1084 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
899 &root_damage_rect)); | 1085 &root_damage_rect)); |
900 EXPECT_EQ(gfx::Rect(100, 100, 30, 30).ToString(), | 1086 EXPECT_EQ(gfx::Rect(100, 100, 30, 30).ToString(), |
901 root_damage_rect.ToString()); | 1087 root_damage_rect.ToString()); |
| 1088 EXPECT_TRUE(GetRenderSurface(root) |
| 1089 ->damage_tracker() |
| 1090 ->has_damage_from_contributing_content()); |
902 } | 1091 } |
903 | 1092 |
904 TEST_F(DamageTrackerTest, VerifyDamageForNewUnchangedLayer) { | 1093 TEST_F(DamageTrackerTest, VerifyDamageForNewUnchangedLayer) { |
905 // If child2 is added to the layer tree, but it doesn't have any explicit | 1094 // If child2 is added to the layer tree, but it doesn't have any explicit |
906 // damage of its own, it should still indeed damage the target surface. | 1095 // damage of its own, it should still indeed damage the target surface. |
907 | 1096 |
908 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 1097 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
909 | 1098 |
910 ClearDamageForAllSurfaces(root); | 1099 ClearDamageForAllSurfaces(root); |
911 { | 1100 { |
(...skipping 16 matching lines...) Expand all Loading... |
928 EmulateDrawingOneFrame(root); | 1117 EmulateDrawingOneFrame(root); |
929 | 1118 |
930 // Sanity check - all 3 layers should be on the same render surface; render | 1119 // Sanity check - all 3 layers should be on the same render surface; render |
931 // surfaces are tested elsewhere. | 1120 // surfaces are tested elsewhere. |
932 ASSERT_EQ(3, GetRenderSurface(root)->num_contributors()); | 1121 ASSERT_EQ(3, GetRenderSurface(root)->num_contributors()); |
933 | 1122 |
934 gfx::Rect root_damage_rect; | 1123 gfx::Rect root_damage_rect; |
935 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 1124 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
936 &root_damage_rect)); | 1125 &root_damage_rect)); |
937 EXPECT_EQ(gfx::Rect(400, 380, 6, 8).ToString(), root_damage_rect.ToString()); | 1126 EXPECT_EQ(gfx::Rect(400, 380, 6, 8).ToString(), root_damage_rect.ToString()); |
| 1127 EXPECT_TRUE(GetRenderSurface(root) |
| 1128 ->damage_tracker() |
| 1129 ->has_damage_from_contributing_content()); |
938 } | 1130 } |
939 | 1131 |
940 TEST_F(DamageTrackerTest, VerifyDamageForMultipleLayers) { | 1132 TEST_F(DamageTrackerTest, VerifyDamageForMultipleLayers) { |
941 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 1133 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
942 LayerImpl* child1 = root->test_properties()->children[0]; | 1134 LayerImpl* child1 = root->test_properties()->children[0]; |
943 | 1135 |
944 // In this test we don't want the above tree manipulation to be considered | 1136 // In this test we don't want the above tree manipulation to be considered |
945 // part of the same frame. | 1137 // part of the same frame. |
946 ClearDamageForAllSurfaces(root); | 1138 ClearDamageForAllSurfaces(root); |
947 { | 1139 { |
(...skipping 14 matching lines...) Expand all Loading... |
962 ClearDamageForAllSurfaces(root); | 1154 ClearDamageForAllSurfaces(root); |
963 child1->SetUpdateRect(gfx::Rect(1, 2)); | 1155 child1->SetUpdateRect(gfx::Rect(1, 2)); |
964 child2->SetUpdateRect(gfx::Rect(3, 4)); | 1156 child2->SetUpdateRect(gfx::Rect(3, 4)); |
965 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1157 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
966 EmulateDrawingOneFrame(root); | 1158 EmulateDrawingOneFrame(root); |
967 gfx::Rect root_damage_rect; | 1159 gfx::Rect root_damage_rect; |
968 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 1160 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
969 &root_damage_rect)); | 1161 &root_damage_rect)); |
970 EXPECT_EQ(gfx::Rect(100, 100, 303, 284).ToString(), | 1162 EXPECT_EQ(gfx::Rect(100, 100, 303, 284).ToString(), |
971 root_damage_rect.ToString()); | 1163 root_damage_rect.ToString()); |
| 1164 EXPECT_TRUE(GetRenderSurface(root) |
| 1165 ->damage_tracker() |
| 1166 ->has_damage_from_contributing_content()); |
972 } | 1167 } |
973 | 1168 |
974 TEST_F(DamageTrackerTest, VerifyDamageForNestedSurfaces) { | 1169 TEST_F(DamageTrackerTest, VerifyDamageForNestedSurfaces) { |
975 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 1170 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
976 LayerImpl* child1 = root->test_properties()->children[0]; | 1171 LayerImpl* child1 = root->test_properties()->children[0]; |
977 LayerImpl* child2 = root->test_properties()->children[1]; | 1172 LayerImpl* child2 = root->test_properties()->children[1]; |
978 LayerImpl* grand_child1 = | 1173 LayerImpl* grand_child1 = |
979 root->test_properties()->children[0]->test_properties()->children[0]; | 1174 root->test_properties()->children[0]->test_properties()->children[0]; |
980 child2->test_properties()->force_render_surface = true; | 1175 child2->test_properties()->force_render_surface = true; |
981 grand_child1->test_properties()->force_render_surface = true; | 1176 grand_child1->test_properties()->force_render_surface = true; |
982 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1177 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
983 EmulateDrawingOneFrame(root); | 1178 EmulateDrawingOneFrame(root); |
984 gfx::Rect child_damage_rect; | 1179 gfx::Rect child_damage_rect; |
985 gfx::Rect root_damage_rect; | 1180 gfx::Rect root_damage_rect; |
986 | 1181 |
987 // CASE 1: Damage to a descendant surface should propagate properly to | 1182 // CASE 1: Damage to a descendant surface should propagate properly to |
988 // ancestor surface. | 1183 // ancestor surface. |
989 ClearDamageForAllSurfaces(root); | 1184 ClearDamageForAllSurfaces(root); |
990 root->layer_tree_impl()->SetOpacityMutated(grand_child1->element_id(), 0.5f); | 1185 root->layer_tree_impl()->SetOpacityMutated(grand_child1->element_id(), 0.5f); |
991 EmulateDrawingOneFrame(root); | 1186 EmulateDrawingOneFrame(root); |
992 EXPECT_TRUE(GetRenderSurface(child1)->damage_tracker()->GetDamageRectIfValid( | 1187 EXPECT_TRUE(GetRenderSurface(child1)->damage_tracker()->GetDamageRectIfValid( |
993 &child_damage_rect)); | 1188 &child_damage_rect)); |
994 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 1189 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
995 &root_damage_rect)); | 1190 &root_damage_rect)); |
996 EXPECT_EQ(gfx::Rect(200, 200, 6, 8).ToString(), child_damage_rect.ToString()); | 1191 EXPECT_EQ(gfx::Rect(200, 200, 6, 8).ToString(), child_damage_rect.ToString()); |
997 EXPECT_EQ(gfx::Rect(300, 300, 6, 8).ToString(), root_damage_rect.ToString()); | 1192 EXPECT_EQ(gfx::Rect(300, 300, 6, 8).ToString(), root_damage_rect.ToString()); |
| 1193 EXPECT_TRUE(GetRenderSurface(root) |
| 1194 ->damage_tracker() |
| 1195 ->has_damage_from_contributing_content()); |
| 1196 EXPECT_TRUE(GetRenderSurface(child1) |
| 1197 ->damage_tracker() |
| 1198 ->has_damage_from_contributing_content()); |
| 1199 EXPECT_FALSE(GetRenderSurface(child2) |
| 1200 ->damage_tracker() |
| 1201 ->has_damage_from_contributing_content()); |
| 1202 EXPECT_FALSE(GetRenderSurface(grand_child1) |
| 1203 ->damage_tracker() |
| 1204 ->has_damage_from_contributing_content()); |
998 | 1205 |
999 // CASE 2: Same as previous case, but with additional damage elsewhere that | 1206 // CASE 2: Same as previous case, but with additional damage elsewhere that |
1000 // should be properly unioned. | 1207 // should be properly unioned. |
1001 // - child1 surface damage in root surface space: | 1208 // - child1 surface damage in root surface space: |
1002 // gfx::Rect(300, 300, 6, 8); | 1209 // gfx::Rect(300, 300, 6, 8); |
1003 // - child2 damage in root surface space: | 1210 // - child2 damage in root surface space: |
1004 // gfx::Rect(11, 11, 18, 18); | 1211 // gfx::Rect(11, 11, 18, 18); |
1005 ClearDamageForAllSurfaces(root); | 1212 ClearDamageForAllSurfaces(root); |
1006 root->layer_tree_impl()->SetOpacityMutated(grand_child1->element_id(), 0.7f); | 1213 root->layer_tree_impl()->SetOpacityMutated(grand_child1->element_id(), 0.7f); |
1007 root->layer_tree_impl()->SetOpacityMutated(child2->element_id(), 0.7f); | 1214 root->layer_tree_impl()->SetOpacityMutated(child2->element_id(), 0.7f); |
1008 EmulateDrawingOneFrame(root); | 1215 EmulateDrawingOneFrame(root); |
1009 EXPECT_TRUE(GetRenderSurface(child1)->damage_tracker()->GetDamageRectIfValid( | 1216 EXPECT_TRUE(GetRenderSurface(child1)->damage_tracker()->GetDamageRectIfValid( |
1010 &child_damage_rect)); | 1217 &child_damage_rect)); |
1011 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 1218 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
1012 &root_damage_rect)); | 1219 &root_damage_rect)); |
1013 EXPECT_EQ(gfx::Rect(200, 200, 6, 8).ToString(), child_damage_rect.ToString()); | 1220 EXPECT_EQ(gfx::Rect(200, 200, 6, 8).ToString(), child_damage_rect.ToString()); |
1014 EXPECT_EQ(gfx::Rect(11, 11, 295, 297).ToString(), | 1221 EXPECT_EQ(gfx::Rect(11, 11, 295, 297).ToString(), |
1015 root_damage_rect.ToString()); | 1222 root_damage_rect.ToString()); |
| 1223 EXPECT_TRUE(GetRenderSurface(root) |
| 1224 ->damage_tracker() |
| 1225 ->has_damage_from_contributing_content()); |
| 1226 EXPECT_TRUE(GetRenderSurface(child1) |
| 1227 ->damage_tracker() |
| 1228 ->has_damage_from_contributing_content()); |
| 1229 EXPECT_FALSE(GetRenderSurface(child2) |
| 1230 ->damage_tracker() |
| 1231 ->has_damage_from_contributing_content()); |
| 1232 EXPECT_FALSE(GetRenderSurface(grand_child1) |
| 1233 ->damage_tracker() |
| 1234 ->has_damage_from_contributing_content()); |
1016 } | 1235 } |
1017 | 1236 |
1018 TEST_F(DamageTrackerTest, VerifyDamageForSurfaceChangeFromDescendantLayer) { | 1237 TEST_F(DamageTrackerTest, VerifyDamageForSurfaceChangeFromDescendantLayer) { |
1019 // If descendant layer changes and affects the content bounds of the render | 1238 // If descendant layer changes and affects the content bounds of the render |
1020 // surface, then the entire descendant surface should be damaged, and it | 1239 // surface, then the entire descendant surface should be damaged, and it |
1021 // should damage its ancestor surface with the old and new surface regions. | 1240 // should damage its ancestor surface with the old and new surface regions. |
1022 | 1241 |
1023 // This is a tricky case, since only the first grand_child changes, but the | 1242 // This is a tricky case, since only the first grand_child changes, but the |
1024 // entire surface should be marked dirty. | 1243 // entire surface should be marked dirty. |
1025 | 1244 |
(...skipping 16 matching lines...) Expand all Loading... |
1042 // The new surface bounds should be damaged entirely, even though only one of | 1261 // The new surface bounds should be damaged entirely, even though only one of |
1043 // the layers changed. | 1262 // the layers changed. |
1044 EXPECT_EQ(gfx::Rect(190, 190, 11, 23).ToString(), | 1263 EXPECT_EQ(gfx::Rect(190, 190, 11, 23).ToString(), |
1045 child_damage_rect.ToString()); | 1264 child_damage_rect.ToString()); |
1046 | 1265 |
1047 // Damage to the root surface should be the union of child1's *entire* render | 1266 // Damage to the root surface should be the union of child1's *entire* render |
1048 // surface (in target space), and its old exposed area (also in target | 1267 // surface (in target space), and its old exposed area (also in target |
1049 // space). | 1268 // space). |
1050 EXPECT_EQ(gfx::Rect(290, 290, 16, 23).ToString(), | 1269 EXPECT_EQ(gfx::Rect(290, 290, 16, 23).ToString(), |
1051 root_damage_rect.ToString()); | 1270 root_damage_rect.ToString()); |
| 1271 |
| 1272 EXPECT_TRUE(GetRenderSurface(root) |
| 1273 ->damage_tracker() |
| 1274 ->has_damage_from_contributing_content()); |
| 1275 EXPECT_TRUE(GetRenderSurface(child1) |
| 1276 ->damage_tracker() |
| 1277 ->has_damage_from_contributing_content()); |
1052 } | 1278 } |
1053 | 1279 |
1054 TEST_F(DamageTrackerTest, VerifyDamageForSurfaceChangeFromAncestorLayer) { | 1280 TEST_F(DamageTrackerTest, VerifyDamageForSurfaceChangeFromAncestorLayer) { |
1055 // An ancestor/owning layer changes that affects the position/transform of | 1281 // An ancestor/owning layer changes that affects the position/transform of |
1056 // the render surface. Note that in this case, the layer_property_changed flag | 1282 // the render surface. Note that in this case, the layer_property_changed flag |
1057 // already propagates to the subtree (tested in LayerImpltest), which damages | 1283 // already propagates to the subtree (tested in LayerImpltest), which damages |
1058 // the entire child1 surface, but the damage tracker still needs the correct | 1284 // the entire child1 surface, but the damage tracker still needs the correct |
1059 // logic to compute the exposed region on the root surface. | 1285 // logic to compute the exposed region on the root surface. |
1060 | 1286 |
1061 // TODO(shawnsingh): the expectations of this test case should change when we | 1287 // TODO(shawnsingh): the expectations of this test case should change when we |
(...skipping 20 matching lines...) Expand all Loading... |
1082 // The new surface bounds should be damaged entirely. | 1308 // The new surface bounds should be damaged entirely. |
1083 EXPECT_EQ(gfx::Rect(190, 190, 16, 18).ToString(), | 1309 EXPECT_EQ(gfx::Rect(190, 190, 16, 18).ToString(), |
1084 child_damage_rect.ToString()); | 1310 child_damage_rect.ToString()); |
1085 | 1311 |
1086 // The entire child1 surface and the old exposed child1 surface should damage | 1312 // The entire child1 surface and the old exposed child1 surface should damage |
1087 // the root surface. | 1313 // the root surface. |
1088 // - old child1 surface in target space: gfx::Rect(290, 290, 16, 18) | 1314 // - old child1 surface in target space: gfx::Rect(290, 290, 16, 18) |
1089 // - new child1 surface in target space: gfx::Rect(240, 240, 16, 18) | 1315 // - new child1 surface in target space: gfx::Rect(240, 240, 16, 18) |
1090 EXPECT_EQ(gfx::Rect(240, 240, 66, 68).ToString(), | 1316 EXPECT_EQ(gfx::Rect(240, 240, 66, 68).ToString(), |
1091 root_damage_rect.ToString()); | 1317 root_damage_rect.ToString()); |
| 1318 |
| 1319 EXPECT_TRUE(GetRenderSurface(root) |
| 1320 ->damage_tracker() |
| 1321 ->has_damage_from_contributing_content()); |
| 1322 EXPECT_FALSE(GetRenderSurface(child1) |
| 1323 ->damage_tracker() |
| 1324 ->has_damage_from_contributing_content()); |
1092 } | 1325 } |
1093 | 1326 |
1094 TEST_F(DamageTrackerTest, VerifyDamageForAddingAndRemovingRenderSurfaces) { | 1327 TEST_F(DamageTrackerTest, VerifyDamageForAddingAndRemovingRenderSurfaces) { |
1095 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 1328 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
1096 LayerImpl* child1 = root->test_properties()->children[0]; | 1329 LayerImpl* child1 = root->test_properties()->children[0]; |
1097 gfx::Rect child_damage_rect; | 1330 gfx::Rect child_damage_rect; |
1098 gfx::Rect root_damage_rect; | 1331 gfx::Rect root_damage_rect; |
1099 | 1332 |
1100 // CASE 1: If a descendant surface disappears, its entire old area becomes | 1333 // CASE 1: If a descendant surface disappears, its entire old area becomes |
1101 // exposed. | 1334 // exposed. |
1102 ClearDamageForAllSurfaces(root); | 1335 ClearDamageForAllSurfaces(root); |
1103 child1->test_properties()->force_render_surface = false; | 1336 child1->test_properties()->force_render_surface = false; |
1104 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1337 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
1105 EmulateDrawingOneFrame(root); | 1338 EmulateDrawingOneFrame(root); |
1106 | 1339 |
1107 // Sanity check that there is only one surface now. | 1340 // Sanity check that there is only one surface now. |
1108 ASSERT_EQ(GetRenderSurface(child1), GetRenderSurface(root)); | 1341 ASSERT_EQ(GetRenderSurface(child1), GetRenderSurface(root)); |
1109 ASSERT_EQ(4, GetRenderSurface(root)->num_contributors()); | 1342 ASSERT_EQ(4, GetRenderSurface(root)->num_contributors()); |
1110 | 1343 |
1111 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 1344 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
1112 &root_damage_rect)); | 1345 &root_damage_rect)); |
1113 EXPECT_EQ(gfx::Rect(290, 290, 16, 18).ToString(), | 1346 EXPECT_EQ(gfx::Rect(290, 290, 16, 18).ToString(), |
1114 root_damage_rect.ToString()); | 1347 root_damage_rect.ToString()); |
1115 | 1348 |
| 1349 EXPECT_TRUE(GetRenderSurface(root) |
| 1350 ->damage_tracker() |
| 1351 ->has_damage_from_contributing_content()); |
| 1352 |
1116 // CASE 2: If a descendant surface appears, its entire old area becomes | 1353 // CASE 2: If a descendant surface appears, its entire old area becomes |
1117 // exposed. | 1354 // exposed. |
1118 | 1355 |
1119 // Cycle one frame of no change, just to sanity check that the next rect is | 1356 // Cycle one frame of no change, just to sanity check that the next rect is |
1120 // not because of the old damage state. | 1357 // not because of the old damage state. |
1121 ClearDamageForAllSurfaces(root); | 1358 ClearDamageForAllSurfaces(root); |
1122 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1359 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
1123 EmulateDrawingOneFrame(root); | 1360 EmulateDrawingOneFrame(root); |
1124 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 1361 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
1125 &root_damage_rect)); | 1362 &root_damage_rect)); |
(...skipping 12 matching lines...) Expand all Loading... |
1138 EXPECT_EQ(2, GetRenderSurface(child1)->num_contributors()); | 1375 EXPECT_EQ(2, GetRenderSurface(child1)->num_contributors()); |
1139 | 1376 |
1140 EXPECT_TRUE(GetRenderSurface(child1)->damage_tracker()->GetDamageRectIfValid( | 1377 EXPECT_TRUE(GetRenderSurface(child1)->damage_tracker()->GetDamageRectIfValid( |
1141 &child_damage_rect)); | 1378 &child_damage_rect)); |
1142 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 1379 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
1143 &root_damage_rect)); | 1380 &root_damage_rect)); |
1144 EXPECT_EQ(gfx::Rect(190, 190, 16, 18).ToString(), | 1381 EXPECT_EQ(gfx::Rect(190, 190, 16, 18).ToString(), |
1145 child_damage_rect.ToString()); | 1382 child_damage_rect.ToString()); |
1146 EXPECT_EQ(gfx::Rect(290, 290, 16, 18).ToString(), | 1383 EXPECT_EQ(gfx::Rect(290, 290, 16, 18).ToString(), |
1147 root_damage_rect.ToString()); | 1384 root_damage_rect.ToString()); |
| 1385 EXPECT_TRUE(GetRenderSurface(root) |
| 1386 ->damage_tracker() |
| 1387 ->has_damage_from_contributing_content()); |
1148 } | 1388 } |
1149 | 1389 |
1150 TEST_F(DamageTrackerTest, VerifyNoDamageWhenNothingChanged) { | 1390 TEST_F(DamageTrackerTest, VerifyNoDamageWhenNothingChanged) { |
1151 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 1391 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
1152 LayerImpl* child1 = root->test_properties()->children[0]; | 1392 LayerImpl* child1 = root->test_properties()->children[0]; |
1153 gfx::Rect child_damage_rect; | 1393 gfx::Rect child_damage_rect; |
1154 gfx::Rect root_damage_rect; | 1394 gfx::Rect root_damage_rect; |
1155 | 1395 |
1156 // CASE 1: If nothing changes, the damage rect should be empty. | 1396 // CASE 1: If nothing changes, the damage rect should be empty. |
1157 // | 1397 // |
1158 ClearDamageForAllSurfaces(root); | 1398 ClearDamageForAllSurfaces(root); |
1159 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1399 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
1160 EmulateDrawingOneFrame(root); | 1400 EmulateDrawingOneFrame(root); |
1161 EXPECT_TRUE(GetRenderSurface(child1)->damage_tracker()->GetDamageRectIfValid( | 1401 EXPECT_TRUE(GetRenderSurface(child1)->damage_tracker()->GetDamageRectIfValid( |
1162 &child_damage_rect)); | 1402 &child_damage_rect)); |
1163 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 1403 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
1164 &root_damage_rect)); | 1404 &root_damage_rect)); |
1165 EXPECT_TRUE(child_damage_rect.IsEmpty()); | 1405 EXPECT_TRUE(child_damage_rect.IsEmpty()); |
1166 EXPECT_TRUE(root_damage_rect.IsEmpty()); | 1406 EXPECT_TRUE(root_damage_rect.IsEmpty()); |
| 1407 EXPECT_FALSE(GetRenderSurface(root) |
| 1408 ->damage_tracker() |
| 1409 ->has_damage_from_contributing_content()); |
1167 | 1410 |
1168 // CASE 2: If nothing changes twice in a row, the damage rect should still be | 1411 // CASE 2: If nothing changes twice in a row, the damage rect should still be |
1169 // empty. | 1412 // empty. |
1170 // | 1413 // |
1171 ClearDamageForAllSurfaces(root); | 1414 ClearDamageForAllSurfaces(root); |
1172 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1415 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
1173 EmulateDrawingOneFrame(root); | 1416 EmulateDrawingOneFrame(root); |
1174 EXPECT_TRUE(GetRenderSurface(child1)->damage_tracker()->GetDamageRectIfValid( | 1417 EXPECT_TRUE(GetRenderSurface(child1)->damage_tracker()->GetDamageRectIfValid( |
1175 &child_damage_rect)); | 1418 &child_damage_rect)); |
1176 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 1419 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
1177 &root_damage_rect)); | 1420 &root_damage_rect)); |
1178 EXPECT_TRUE(child_damage_rect.IsEmpty()); | 1421 EXPECT_TRUE(child_damage_rect.IsEmpty()); |
1179 EXPECT_TRUE(root_damage_rect.IsEmpty()); | 1422 EXPECT_TRUE(root_damage_rect.IsEmpty()); |
| 1423 EXPECT_FALSE(GetRenderSurface(root) |
| 1424 ->damage_tracker() |
| 1425 ->has_damage_from_contributing_content()); |
1180 } | 1426 } |
1181 | 1427 |
1182 TEST_F(DamageTrackerTest, VerifyNoDamageForUpdateRectThatDoesNotDrawContent) { | 1428 TEST_F(DamageTrackerTest, VerifyNoDamageForUpdateRectThatDoesNotDrawContent) { |
1183 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 1429 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
1184 LayerImpl* child1 = root->test_properties()->children[0]; | 1430 LayerImpl* child1 = root->test_properties()->children[0]; |
1185 gfx::Rect child_damage_rect; | 1431 gfx::Rect child_damage_rect; |
1186 gfx::Rect root_damage_rect; | 1432 gfx::Rect root_damage_rect; |
1187 | 1433 |
1188 // In our specific tree, the update rect of child1 should not cause any | 1434 // In our specific tree, the update rect of child1 should not cause any |
1189 // damage to any surface because it does not actually draw content. | 1435 // damage to any surface because it does not actually draw content. |
1190 ClearDamageForAllSurfaces(root); | 1436 ClearDamageForAllSurfaces(root); |
1191 child1->SetUpdateRect(gfx::Rect(1, 2)); | 1437 child1->SetUpdateRect(gfx::Rect(1, 2)); |
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 | 1450 |
1202 TEST_F(DamageTrackerTest, VerifyDamageForMask) { | 1451 TEST_F(DamageTrackerTest, VerifyDamageForMask) { |
1203 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 1452 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
1204 LayerImpl* child = root->test_properties()->children[0]; | 1453 LayerImpl* child = root->test_properties()->children[0]; |
1205 | 1454 |
1206 // In the current implementation of the damage tracker, changes to mask | 1455 // In the current implementation of the damage tracker, changes to mask |
1207 // layers should damage the entire corresponding surface. | 1456 // layers should damage the entire corresponding surface. |
1208 | 1457 |
1209 ClearDamageForAllSurfaces(root); | 1458 ClearDamageForAllSurfaces(root); |
(...skipping 26 matching lines...) Expand all Loading... |
1236 // surface. | 1485 // surface. |
1237 ClearDamageForAllSurfaces(root); | 1486 ClearDamageForAllSurfaces(root); |
1238 mask_layer->SetUpdateRect(gfx::Rect(1, 2, 3, 4)); | 1487 mask_layer->SetUpdateRect(gfx::Rect(1, 2, 3, 4)); |
1239 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1488 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
1240 EmulateDrawingOneFrame(root); | 1489 EmulateDrawingOneFrame(root); |
1241 gfx::Rect child_damage_rect; | 1490 gfx::Rect child_damage_rect; |
1242 EXPECT_TRUE(GetRenderSurface(child)->damage_tracker()->GetDamageRectIfValid( | 1491 EXPECT_TRUE(GetRenderSurface(child)->damage_tracker()->GetDamageRectIfValid( |
1243 &child_damage_rect)); | 1492 &child_damage_rect)); |
1244 EXPECT_EQ(gfx::Rect(30, 30).ToString(), child_damage_rect.ToString()); | 1493 EXPECT_EQ(gfx::Rect(30, 30).ToString(), child_damage_rect.ToString()); |
1245 | 1494 |
| 1495 EXPECT_TRUE(GetRenderSurface(root) |
| 1496 ->damage_tracker() |
| 1497 ->has_damage_from_contributing_content()); |
| 1498 EXPECT_FALSE(GetRenderSurface(child) |
| 1499 ->damage_tracker() |
| 1500 ->has_damage_from_contributing_content()); |
| 1501 |
1246 // CASE 2: a property change on the mask layer should damage the entire | 1502 // CASE 2: a property change on the mask layer should damage the entire |
1247 // target surface. | 1503 // target surface. |
1248 | 1504 |
1249 // Advance one frame without damage so that we know the damage rect is not | 1505 // Advance one frame without damage so that we know the damage rect is not |
1250 // leftover from the previous case. | 1506 // leftover from the previous case. |
1251 ClearDamageForAllSurfaces(root); | 1507 ClearDamageForAllSurfaces(root); |
1252 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1508 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
1253 EmulateDrawingOneFrame(root); | 1509 EmulateDrawingOneFrame(root); |
1254 EXPECT_TRUE(GetRenderSurface(child)->damage_tracker()->GetDamageRectIfValid( | 1510 EXPECT_TRUE(GetRenderSurface(child)->damage_tracker()->GetDamageRectIfValid( |
1255 &child_damage_rect)); | 1511 &child_damage_rect)); |
1256 EXPECT_TRUE(child_damage_rect.IsEmpty()); | 1512 EXPECT_TRUE(child_damage_rect.IsEmpty()); |
1257 | 1513 |
1258 // Then test the property change. | 1514 // Then test the property change. |
1259 ClearDamageForAllSurfaces(root); | 1515 ClearDamageForAllSurfaces(root); |
1260 mask_layer->NoteLayerPropertyChanged(); | 1516 mask_layer->NoteLayerPropertyChanged(); |
1261 | 1517 |
1262 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1518 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
1263 EmulateDrawingOneFrame(root); | 1519 EmulateDrawingOneFrame(root); |
1264 EXPECT_TRUE(GetRenderSurface(child)->damage_tracker()->GetDamageRectIfValid( | 1520 EXPECT_TRUE(GetRenderSurface(child)->damage_tracker()->GetDamageRectIfValid( |
1265 &child_damage_rect)); | 1521 &child_damage_rect)); |
1266 EXPECT_EQ(gfx::Rect(30, 30).ToString(), child_damage_rect.ToString()); | 1522 EXPECT_EQ(gfx::Rect(30, 30).ToString(), child_damage_rect.ToString()); |
1267 | 1523 |
| 1524 EXPECT_TRUE(GetRenderSurface(root) |
| 1525 ->damage_tracker() |
| 1526 ->has_damage_from_contributing_content()); |
| 1527 EXPECT_FALSE(GetRenderSurface(child) |
| 1528 ->damage_tracker() |
| 1529 ->has_damage_from_contributing_content()); |
| 1530 |
1268 // CASE 3: removing the mask also damages the entire target surface. | 1531 // CASE 3: removing the mask also damages the entire target surface. |
1269 // | 1532 // |
1270 | 1533 |
1271 // Advance one frame without damage so that we know the damage rect is not | 1534 // Advance one frame without damage so that we know the damage rect is not |
1272 // leftover from the previous case. | 1535 // leftover from the previous case. |
1273 ClearDamageForAllSurfaces(root); | 1536 ClearDamageForAllSurfaces(root); |
1274 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1537 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
1275 EmulateDrawingOneFrame(root); | 1538 EmulateDrawingOneFrame(root); |
1276 EXPECT_TRUE(GetRenderSurface(child)->damage_tracker()->GetDamageRectIfValid( | 1539 EXPECT_TRUE(GetRenderSurface(child)->damage_tracker()->GetDamageRectIfValid( |
1277 &child_damage_rect)); | 1540 &child_damage_rect)); |
1278 EXPECT_TRUE(child_damage_rect.IsEmpty()); | 1541 EXPECT_TRUE(child_damage_rect.IsEmpty()); |
1279 | 1542 |
1280 // Then test mask removal. | 1543 // Then test mask removal. |
1281 ClearDamageForAllSurfaces(root); | 1544 ClearDamageForAllSurfaces(root); |
1282 child->test_properties()->SetMaskLayer(nullptr); | 1545 child->test_properties()->SetMaskLayer(nullptr); |
1283 child->NoteLayerPropertyChanged(); | 1546 child->NoteLayerPropertyChanged(); |
1284 ASSERT_TRUE(child->LayerPropertyChanged()); | 1547 ASSERT_TRUE(child->LayerPropertyChanged()); |
1285 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1548 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
1286 EmulateDrawingOneFrame(root); | 1549 EmulateDrawingOneFrame(root); |
1287 | 1550 |
1288 // Sanity check that a render surface still exists. | 1551 // Sanity check that a render surface still exists. |
1289 ASSERT_TRUE(GetRenderSurface(child)); | 1552 ASSERT_TRUE(GetRenderSurface(child)); |
1290 | 1553 |
1291 EXPECT_TRUE(GetRenderSurface(child)->damage_tracker()->GetDamageRectIfValid( | 1554 EXPECT_TRUE(GetRenderSurface(child)->damage_tracker()->GetDamageRectIfValid( |
1292 &child_damage_rect)); | 1555 &child_damage_rect)); |
1293 EXPECT_EQ(gfx::Rect(30, 30).ToString(), child_damage_rect.ToString()); | 1556 EXPECT_EQ(gfx::Rect(30, 30).ToString(), child_damage_rect.ToString()); |
| 1557 |
| 1558 EXPECT_TRUE(GetRenderSurface(root) |
| 1559 ->damage_tracker() |
| 1560 ->has_damage_from_contributing_content()); |
1294 } | 1561 } |
1295 | 1562 |
1296 TEST_F(DamageTrackerTest, DamageWhenAddedExternally) { | 1563 TEST_F(DamageTrackerTest, DamageWhenAddedExternally) { |
1297 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 1564 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
1298 LayerImpl* child = root->test_properties()->children[0]; | 1565 LayerImpl* child = root->test_properties()->children[0]; |
1299 | 1566 |
1300 // Case 1: This test ensures that when the tracker is given damage, that | 1567 // Case 1: This test ensures that when the tracker is given damage, that |
1301 // it is included with any other partial damage. | 1568 // it is included with any other partial damage. |
1302 // | 1569 // |
1303 ClearDamageForAllSurfaces(root); | 1570 ClearDamageForAllSurfaces(root); |
1304 child->SetUpdateRect(gfx::Rect(10, 11, 12, 13)); | 1571 child->SetUpdateRect(gfx::Rect(10, 11, 12, 13)); |
1305 GetRenderSurface(root)->damage_tracker()->AddDamageNextUpdate( | 1572 GetRenderSurface(root)->damage_tracker()->AddDamageNextUpdate( |
1306 gfx::Rect(15, 16, 32, 33)); | 1573 gfx::Rect(15, 16, 32, 33)); |
1307 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1574 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
1308 EmulateDrawingOneFrame(root); | 1575 EmulateDrawingOneFrame(root); |
1309 gfx::Rect root_damage_rect; | 1576 gfx::Rect root_damage_rect; |
1310 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 1577 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
1311 &root_damage_rect)); | 1578 &root_damage_rect)); |
1312 EXPECT_EQ(gfx::UnionRects(gfx::Rect(15, 16, 32, 33), | 1579 EXPECT_EQ(gfx::UnionRects(gfx::Rect(15, 16, 32, 33), |
1313 gfx::Rect(100 + 10, 100 + 11, 12, 13)).ToString(), | 1580 gfx::Rect(100 + 10, 100 + 11, 12, 13)).ToString(), |
1314 root_damage_rect.ToString()); | 1581 root_damage_rect.ToString()); |
| 1582 EXPECT_TRUE(GetRenderSurface(root) |
| 1583 ->damage_tracker() |
| 1584 ->has_damage_from_contributing_content()); |
1315 | 1585 |
1316 // Case 2: An additional sanity check that adding damage works even when | 1586 // Case 2: An additional sanity check that adding damage works even when |
1317 // nothing on the layer tree changed. | 1587 // nothing on the layer tree changed. |
1318 // | 1588 // |
1319 ClearDamageForAllSurfaces(root); | 1589 ClearDamageForAllSurfaces(root); |
1320 GetRenderSurface(root)->damage_tracker()->AddDamageNextUpdate( | 1590 GetRenderSurface(root)->damage_tracker()->AddDamageNextUpdate( |
1321 gfx::Rect(30, 31, 14, 15)); | 1591 gfx::Rect(30, 31, 14, 15)); |
1322 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1592 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
1323 EmulateDrawingOneFrame(root); | 1593 EmulateDrawingOneFrame(root); |
1324 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 1594 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
1325 &root_damage_rect)); | 1595 &root_damage_rect)); |
1326 EXPECT_EQ(gfx::Rect(30, 31, 14, 15).ToString(), root_damage_rect.ToString()); | 1596 EXPECT_EQ(gfx::Rect(30, 31, 14, 15).ToString(), root_damage_rect.ToString()); |
| 1597 EXPECT_FALSE(GetRenderSurface(root) |
| 1598 ->damage_tracker() |
| 1599 ->has_damage_from_contributing_content()); |
1327 } | 1600 } |
1328 | 1601 |
1329 TEST_F(DamageTrackerTest, VerifyDamageWithNoContributingLayers) { | 1602 TEST_F(DamageTrackerTest, VerifyDamageWithNoContributingLayers) { |
1330 std::unique_ptr<LayerImpl> root = | 1603 std::unique_ptr<LayerImpl> root = |
1331 LayerImpl::Create(host_impl_.active_tree(), 1); | 1604 LayerImpl::Create(host_impl_.active_tree(), 1); |
1332 root->test_properties()->force_render_surface = true; | 1605 root->test_properties()->force_render_surface = true; |
1333 host_impl_.active_tree()->SetRootLayerForTesting(std::move(root)); | 1606 host_impl_.active_tree()->SetRootLayerForTesting(std::move(root)); |
1334 LayerImpl* root_ptr = host_impl_.active_tree()->root_layer_for_testing(); | 1607 LayerImpl* root_ptr = host_impl_.active_tree()->root_layer_for_testing(); |
1335 root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1608 root_ptr->layer_tree_impl()->property_trees()->needs_rebuild = true; |
1336 EmulateDrawingOneFrame(root_ptr); | 1609 EmulateDrawingOneFrame(root_ptr); |
1337 | 1610 |
1338 DCHECK_EQ(GetRenderSurface(root_ptr), root_ptr->render_target()); | 1611 DCHECK_EQ(GetRenderSurface(root_ptr), root_ptr->render_target()); |
1339 RenderSurfaceImpl* target_surface = GetRenderSurface(root_ptr); | 1612 RenderSurfaceImpl* target_surface = GetRenderSurface(root_ptr); |
1340 gfx::Rect damage_rect; | 1613 gfx::Rect damage_rect; |
1341 EXPECT_TRUE( | 1614 EXPECT_TRUE( |
1342 target_surface->damage_tracker()->GetDamageRectIfValid(&damage_rect)); | 1615 target_surface->damage_tracker()->GetDamageRectIfValid(&damage_rect)); |
1343 EXPECT_TRUE(damage_rect.IsEmpty()); | 1616 EXPECT_TRUE(damage_rect.IsEmpty()); |
| 1617 EXPECT_FALSE(GetRenderSurface(root_ptr) |
| 1618 ->damage_tracker() |
| 1619 ->has_damage_from_contributing_content()); |
1344 } | 1620 } |
1345 | 1621 |
1346 TEST_F(DamageTrackerTest, VerifyDamageAccumulatesUntilReset) { | 1622 TEST_F(DamageTrackerTest, VerifyDamageAccumulatesUntilReset) { |
1347 // If damage is not cleared, it should accumulate. | 1623 // If damage is not cleared, it should accumulate. |
1348 | 1624 |
1349 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); | 1625 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); |
1350 LayerImpl* child = root->test_properties()->children[0]; | 1626 LayerImpl* child = root->test_properties()->children[0]; |
1351 | 1627 |
1352 ClearDamageForAllSurfaces(root); | 1628 ClearDamageForAllSurfaces(root); |
1353 child->SetUpdateRect(gfx::Rect(10.f, 11.f, 1.f, 2.f)); | 1629 child->SetUpdateRect(gfx::Rect(10.f, 11.f, 1.f, 2.f)); |
1354 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1630 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
1355 EmulateDrawingOneFrame(root); | 1631 EmulateDrawingOneFrame(root); |
1356 | 1632 |
1357 // Sanity check damage after the first frame; this isnt the actual test yet. | 1633 // Sanity check damage after the first frame; this isnt the actual test yet. |
1358 gfx::Rect root_damage_rect; | 1634 gfx::Rect root_damage_rect; |
1359 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 1635 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
1360 &root_damage_rect)); | 1636 &root_damage_rect)); |
1361 EXPECT_EQ(gfx::Rect(110, 111, 1, 2).ToString(), root_damage_rect.ToString()); | 1637 EXPECT_EQ(gfx::Rect(110, 111, 1, 2).ToString(), root_damage_rect.ToString()); |
| 1638 EXPECT_TRUE(GetRenderSurface(root) |
| 1639 ->damage_tracker() |
| 1640 ->has_damage_from_contributing_content()); |
1362 | 1641 |
1363 // New damage, without having cleared the previous damage, should be unioned | 1642 // New damage, without having cleared the previous damage, should be unioned |
1364 // to the previous one. | 1643 // to the previous one. |
1365 child->SetUpdateRect(gfx::Rect(20, 25, 1, 2)); | 1644 child->SetUpdateRect(gfx::Rect(20, 25, 1, 2)); |
1366 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1645 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
1367 EmulateDrawingOneFrame(root); | 1646 EmulateDrawingOneFrame(root); |
1368 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 1647 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
1369 &root_damage_rect)); | 1648 &root_damage_rect)); |
1370 EXPECT_EQ(gfx::Rect(110, 111, 11, 16).ToString(), | 1649 EXPECT_EQ(gfx::Rect(110, 111, 11, 16).ToString(), |
1371 root_damage_rect.ToString()); | 1650 root_damage_rect.ToString()); |
| 1651 EXPECT_TRUE(GetRenderSurface(root) |
| 1652 ->damage_tracker() |
| 1653 ->has_damage_from_contributing_content()); |
1372 | 1654 |
1373 // If we notify the damage tracker that we drew the damaged area, then damage | 1655 // If we notify the damage tracker that we drew the damaged area, then damage |
1374 // should be emptied. | 1656 // should be emptied. |
1375 GetRenderSurface(root)->damage_tracker()->DidDrawDamagedArea(); | 1657 GetRenderSurface(root)->damage_tracker()->DidDrawDamagedArea(); |
1376 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 1658 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
1377 &root_damage_rect)); | 1659 &root_damage_rect)); |
1378 EXPECT_TRUE(root_damage_rect.IsEmpty()); | 1660 EXPECT_TRUE(root_damage_rect.IsEmpty()); |
| 1661 EXPECT_FALSE(GetRenderSurface(root) |
| 1662 ->damage_tracker() |
| 1663 ->has_damage_from_contributing_content()); |
1379 | 1664 |
1380 // Damage should remain empty even after one frame, since there's yet no new | 1665 // Damage should remain empty even after one frame, since there's yet no new |
1381 // damage. | 1666 // damage. |
1382 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1667 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
1383 EmulateDrawingOneFrame(root); | 1668 EmulateDrawingOneFrame(root); |
1384 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 1669 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
1385 &root_damage_rect)); | 1670 &root_damage_rect)); |
1386 EXPECT_TRUE(root_damage_rect.IsEmpty()); | 1671 EXPECT_TRUE(root_damage_rect.IsEmpty()); |
| 1672 EXPECT_FALSE(GetRenderSurface(root) |
| 1673 ->damage_tracker() |
| 1674 ->has_damage_from_contributing_content()); |
1387 } | 1675 } |
1388 | 1676 |
1389 TEST_F(DamageTrackerTest, HugeDamageRect) { | 1677 TEST_F(DamageTrackerTest, HugeDamageRect) { |
1390 // This number is so large that we start losting floating point accuracy. | 1678 // This number is so large that we start losting floating point accuracy. |
1391 const int kBigNumber = 900000000; | 1679 const int kBigNumber = 900000000; |
1392 // Walk over a range to find floating point inaccuracy boundaries that move | 1680 // Walk over a range to find floating point inaccuracy boundaries that move |
1393 // toward the wrong direction. | 1681 // toward the wrong direction. |
1394 const int kRange = 5000; | 1682 const int kRange = 5000; |
1395 | 1683 |
1396 for (int i = 0; i < kRange; ++i) { | 1684 for (int i = 0; i < kRange; ++i) { |
(...skipping 16 matching lines...) Expand all Loading... |
1413 EmulateDrawingOneFrame(root, device_scale_factor); | 1701 EmulateDrawingOneFrame(root, device_scale_factor); |
1414 | 1702 |
1415 // The expected damage should cover the visible part of the child layer, | 1703 // The expected damage should cover the visible part of the child layer, |
1416 // which is (0, 0, i, i) in the viewport. | 1704 // which is (0, 0, i, i) in the viewport. |
1417 gfx::Rect root_damage_rect; | 1705 gfx::Rect root_damage_rect; |
1418 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 1706 EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
1419 &root_damage_rect)); | 1707 &root_damage_rect)); |
1420 gfx::Rect damage_we_care_about = gfx::Rect(i, i); | 1708 gfx::Rect damage_we_care_about = gfx::Rect(i, i); |
1421 EXPECT_LE(damage_we_care_about.right(), root_damage_rect.right()); | 1709 EXPECT_LE(damage_we_care_about.right(), root_damage_rect.right()); |
1422 EXPECT_LE(damage_we_care_about.bottom(), root_damage_rect.bottom()); | 1710 EXPECT_LE(damage_we_care_about.bottom(), root_damage_rect.bottom()); |
| 1711 EXPECT_TRUE(GetRenderSurface(root) |
| 1712 ->damage_tracker() |
| 1713 ->has_damage_from_contributing_content()); |
1423 } | 1714 } |
1424 } | 1715 } |
1425 | 1716 |
1426 TEST_F(DamageTrackerTest, DamageRectTooBig) { | 1717 TEST_F(DamageTrackerTest, DamageRectTooBig) { |
1427 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(2); | 1718 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(2); |
1428 LayerImpl* child1 = root->test_properties()->children[0]; | 1719 LayerImpl* child1 = root->test_properties()->children[0]; |
1429 LayerImpl* child2 = root->test_properties()->children[1]; | 1720 LayerImpl* child2 = root->test_properties()->children[1]; |
1430 | 1721 |
1431 // Really far left. | 1722 // Really far left. |
1432 child1->SetPosition(gfx::PointF(std::numeric_limits<int>::min() + 100, 0)); | 1723 child1->SetPosition(gfx::PointF(std::numeric_limits<int>::min() + 100, 0)); |
1433 child1->SetBounds(gfx::Size(1, 1)); | 1724 child1->SetBounds(gfx::Size(1, 1)); |
1434 | 1725 |
1435 // Really far right. | 1726 // Really far right. |
1436 child2->SetPosition(gfx::PointF(std::numeric_limits<int>::max() - 100, 0)); | 1727 child2->SetPosition(gfx::PointF(std::numeric_limits<int>::max() - 100, 0)); |
1437 child2->SetBounds(gfx::Size(1, 1)); | 1728 child2->SetBounds(gfx::Size(1, 1)); |
1438 | 1729 |
1439 root->layer_tree_impl()->property_trees()->needs_rebuild = true; | 1730 root->layer_tree_impl()->property_trees()->needs_rebuild = true; |
1440 float device_scale_factor = 1.f; | 1731 float device_scale_factor = 1.f; |
1441 EmulateDrawingOneFrame(root, device_scale_factor); | 1732 EmulateDrawingOneFrame(root, device_scale_factor); |
1442 | 1733 |
1443 // The expected damage would be too large to store in a gfx::Rect, so we | 1734 // The expected damage would be too large to store in a gfx::Rect, so we |
1444 // should damage everything (ie, we don't have a valid rect). | 1735 // should damage everything (ie, we don't have a valid rect). |
1445 gfx::Rect damage_rect; | 1736 gfx::Rect damage_rect; |
1446 EXPECT_FALSE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 1737 EXPECT_FALSE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
1447 &damage_rect)); | 1738 &damage_rect)); |
1448 EXPECT_EQ(GetRenderSurface(root)->content_rect(), | 1739 EXPECT_EQ(GetRenderSurface(root)->content_rect(), |
1449 GetRenderSurface(root)->GetDamageRect()); | 1740 GetRenderSurface(root)->GetDamageRect()); |
| 1741 EXPECT_TRUE(GetRenderSurface(root) |
| 1742 ->damage_tracker() |
| 1743 ->has_damage_from_contributing_content()); |
1450 } | 1744 } |
1451 | 1745 |
1452 TEST_F(DamageTrackerTest, DamageRectTooBigWithFilter) { | 1746 TEST_F(DamageTrackerTest, DamageRectTooBigWithFilter) { |
1453 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(2); | 1747 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(2); |
1454 LayerImpl* child1 = root->test_properties()->children[0]; | 1748 LayerImpl* child1 = root->test_properties()->children[0]; |
1455 LayerImpl* child2 = root->test_properties()->children[1]; | 1749 LayerImpl* child2 = root->test_properties()->children[1]; |
1456 | 1750 |
1457 FilterOperations filters; | 1751 FilterOperations filters; |
1458 filters.Append(FilterOperation::CreateBlurFilter(5.f)); | 1752 filters.Append(FilterOperation::CreateBlurFilter(5.f)); |
1459 root->SetDrawsContent(true); | 1753 root->SetDrawsContent(true); |
(...skipping 11 matching lines...) Expand all Loading... |
1471 float device_scale_factor = 1.f; | 1765 float device_scale_factor = 1.f; |
1472 EmulateDrawingOneFrame(root, device_scale_factor); | 1766 EmulateDrawingOneFrame(root, device_scale_factor); |
1473 | 1767 |
1474 // The expected damage would be too large to store in a gfx::Rect, so we | 1768 // The expected damage would be too large to store in a gfx::Rect, so we |
1475 // should damage everything (ie, we don't have a valid rect). | 1769 // should damage everything (ie, we don't have a valid rect). |
1476 gfx::Rect damage_rect; | 1770 gfx::Rect damage_rect; |
1477 EXPECT_FALSE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 1771 EXPECT_FALSE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
1478 &damage_rect)); | 1772 &damage_rect)); |
1479 EXPECT_EQ(GetRenderSurface(root)->content_rect(), | 1773 EXPECT_EQ(GetRenderSurface(root)->content_rect(), |
1480 GetRenderSurface(root)->GetDamageRect()); | 1774 GetRenderSurface(root)->GetDamageRect()); |
| 1775 EXPECT_TRUE(GetRenderSurface(root) |
| 1776 ->damage_tracker() |
| 1777 ->has_damage_from_contributing_content()); |
1481 } | 1778 } |
1482 | 1779 |
1483 TEST_F(DamageTrackerTest, DamageRectTooBigInRenderSurface) { | 1780 TEST_F(DamageTrackerTest, DamageRectTooBigInRenderSurface) { |
1484 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 1781 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
1485 LayerImpl* child1 = root->test_properties()->children[0]; | 1782 LayerImpl* child1 = root->test_properties()->children[0]; |
1486 LayerImpl* grandchild1 = child1->test_properties()->children[0]; | 1783 LayerImpl* grandchild1 = child1->test_properties()->children[0]; |
1487 LayerImpl* grandchild2 = child1->test_properties()->children[1]; | 1784 LayerImpl* grandchild2 = child1->test_properties()->children[1]; |
1488 | 1785 |
1489 // Really far left. | 1786 // Really far left. |
1490 grandchild1->SetPosition( | 1787 grandchild1->SetPosition( |
(...skipping 28 matching lines...) Expand all Loading... |
1519 | 1816 |
1520 // However, the root should just use the child1 render surface's content rect | 1817 // However, the root should just use the child1 render surface's content rect |
1521 // as damage. | 1818 // as damage. |
1522 ASSERT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 1819 ASSERT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
1523 &damage_rect)); | 1820 &damage_rect)); |
1524 EXPECT_TRUE(damage_rect.Contains(GetRenderSurface(root)->content_rect())); | 1821 EXPECT_TRUE(damage_rect.Contains(GetRenderSurface(root)->content_rect())); |
1525 EXPECT_TRUE(damage_rect.Contains( | 1822 EXPECT_TRUE(damage_rect.Contains( |
1526 gfx::ToEnclosingRect(GetRenderSurface(child1)->DrawableContentRect()))); | 1823 gfx::ToEnclosingRect(GetRenderSurface(child1)->DrawableContentRect()))); |
1527 EXPECT_EQ(damage_rect, GetRenderSurface(root)->GetDamageRect()); | 1824 EXPECT_EQ(damage_rect, GetRenderSurface(root)->GetDamageRect()); |
1528 | 1825 |
| 1826 EXPECT_TRUE(GetRenderSurface(root) |
| 1827 ->damage_tracker() |
| 1828 ->has_damage_from_contributing_content()); |
| 1829 EXPECT_TRUE(GetRenderSurface(child1) |
| 1830 ->damage_tracker() |
| 1831 ->has_damage_from_contributing_content()); |
| 1832 |
1529 // Add new damage, without changing properties, which goes down a different | 1833 // Add new damage, without changing properties, which goes down a different |
1530 // path in the damage tracker. | 1834 // path in the damage tracker. |
1531 root->layer_tree_impl()->ResetAllChangeTracking(); | 1835 root->layer_tree_impl()->ResetAllChangeTracking(); |
1532 grandchild1->AddDamageRect(gfx::Rect(grandchild1->bounds())); | 1836 grandchild1->AddDamageRect(gfx::Rect(grandchild1->bounds())); |
1533 grandchild2->AddDamageRect(gfx::Rect(grandchild1->bounds())); | 1837 grandchild2->AddDamageRect(gfx::Rect(grandchild1->bounds())); |
1534 | 1838 |
1535 // Recompute all damage / properties. | 1839 // Recompute all damage / properties. |
1536 render_surface_list.clear(); | 1840 render_surface_list.clear(); |
1537 ExecuteCalculateDrawProperties(root, device_scale_factor, | 1841 ExecuteCalculateDrawProperties(root, device_scale_factor, |
1538 &render_surface_list); | 1842 &render_surface_list); |
1539 DamageTracker::UpdateDamageTracking(host_impl_.active_tree(), | 1843 DamageTracker::UpdateDamageTracking(host_impl_.active_tree(), |
1540 render_surface_list); | 1844 render_surface_list); |
1541 | 1845 |
1542 // Child1 should still not have a valid rect, since the union of the damage of | 1846 // Child1 should still not have a valid rect, since the union of the damage of |
1543 // its children is not representable by a single rect. | 1847 // its children is not representable by a single rect. |
1544 EXPECT_FALSE(GetRenderSurface(child1)->damage_tracker()->GetDamageRectIfValid( | 1848 EXPECT_FALSE(GetRenderSurface(child1)->damage_tracker()->GetDamageRectIfValid( |
1545 &damage_rect)); | 1849 &damage_rect)); |
1546 EXPECT_EQ(GetRenderSurface(child1)->content_rect(), | 1850 EXPECT_EQ(GetRenderSurface(child1)->content_rect(), |
1547 GetRenderSurface(child1)->GetDamageRect()); | 1851 GetRenderSurface(child1)->GetDamageRect()); |
1548 | 1852 |
1549 // Root should have valid damage and contain both its content rect and the | 1853 // Root should have valid damage and contain both its content rect and the |
1550 // drawable content rect of child1. | 1854 // drawable content rect of child1. |
1551 ASSERT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 1855 ASSERT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
1552 &damage_rect)); | 1856 &damage_rect)); |
1553 EXPECT_TRUE(damage_rect.Contains(GetRenderSurface(root)->content_rect())); | 1857 EXPECT_TRUE(damage_rect.Contains(GetRenderSurface(root)->content_rect())); |
1554 EXPECT_TRUE(damage_rect.Contains( | 1858 EXPECT_TRUE(damage_rect.Contains( |
1555 gfx::ToEnclosingRect(GetRenderSurface(child1)->DrawableContentRect()))); | 1859 gfx::ToEnclosingRect(GetRenderSurface(child1)->DrawableContentRect()))); |
1556 EXPECT_EQ(damage_rect, GetRenderSurface(root)->GetDamageRect()); | 1860 EXPECT_EQ(damage_rect, GetRenderSurface(root)->GetDamageRect()); |
| 1861 |
| 1862 EXPECT_TRUE(GetRenderSurface(root) |
| 1863 ->damage_tracker() |
| 1864 ->has_damage_from_contributing_content()); |
| 1865 EXPECT_TRUE(GetRenderSurface(child1) |
| 1866 ->damage_tracker() |
| 1867 ->has_damage_from_contributing_content()); |
1557 } | 1868 } |
1558 | 1869 |
1559 TEST_F(DamageTrackerTest, DamageRectTooBigInRenderSurfaceWithFilter) { | 1870 TEST_F(DamageTrackerTest, DamageRectTooBigInRenderSurfaceWithFilter) { |
1560 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); | 1871 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); |
1561 LayerImpl* child1 = root->test_properties()->children[0]; | 1872 LayerImpl* child1 = root->test_properties()->children[0]; |
1562 LayerImpl* grandchild1 = child1->test_properties()->children[0]; | 1873 LayerImpl* grandchild1 = child1->test_properties()->children[0]; |
1563 LayerImpl* grandchild2 = child1->test_properties()->children[1]; | 1874 LayerImpl* grandchild2 = child1->test_properties()->children[1]; |
1564 | 1875 |
1565 // Set up a moving pixels filter on the child. | 1876 // Set up a moving pixels filter on the child. |
1566 FilterOperations filters; | 1877 FilterOperations filters; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1601 | 1912 |
1602 // However, the root should just use the child1 render surface's content rect | 1913 // However, the root should just use the child1 render surface's content rect |
1603 // as damage. | 1914 // as damage. |
1604 ASSERT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 1915 ASSERT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
1605 &damage_rect)); | 1916 &damage_rect)); |
1606 EXPECT_TRUE(damage_rect.Contains(GetRenderSurface(root)->content_rect())); | 1917 EXPECT_TRUE(damage_rect.Contains(GetRenderSurface(root)->content_rect())); |
1607 EXPECT_TRUE(damage_rect.Contains( | 1918 EXPECT_TRUE(damage_rect.Contains( |
1608 gfx::ToEnclosingRect(GetRenderSurface(child1)->DrawableContentRect()))); | 1919 gfx::ToEnclosingRect(GetRenderSurface(child1)->DrawableContentRect()))); |
1609 EXPECT_EQ(damage_rect, GetRenderSurface(root)->GetDamageRect()); | 1920 EXPECT_EQ(damage_rect, GetRenderSurface(root)->GetDamageRect()); |
1610 | 1921 |
| 1922 EXPECT_TRUE(GetRenderSurface(root) |
| 1923 ->damage_tracker() |
| 1924 ->has_damage_from_contributing_content()); |
| 1925 EXPECT_TRUE(GetRenderSurface(child1) |
| 1926 ->damage_tracker() |
| 1927 ->has_damage_from_contributing_content()); |
| 1928 |
1611 // Add new damage, without changing properties, which goes down a different | 1929 // Add new damage, without changing properties, which goes down a different |
1612 // path in the damage tracker. | 1930 // path in the damage tracker. |
1613 root->layer_tree_impl()->ResetAllChangeTracking(); | 1931 root->layer_tree_impl()->ResetAllChangeTracking(); |
1614 grandchild1->AddDamageRect(gfx::Rect(grandchild1->bounds())); | 1932 grandchild1->AddDamageRect(gfx::Rect(grandchild1->bounds())); |
1615 grandchild2->AddDamageRect(gfx::Rect(grandchild1->bounds())); | 1933 grandchild2->AddDamageRect(gfx::Rect(grandchild1->bounds())); |
1616 | 1934 |
1617 // Recompute all damage / properties. | 1935 // Recompute all damage / properties. |
1618 render_surface_list.clear(); | 1936 render_surface_list.clear(); |
1619 ExecuteCalculateDrawProperties(root, device_scale_factor, | 1937 ExecuteCalculateDrawProperties(root, device_scale_factor, |
1620 &render_surface_list); | 1938 &render_surface_list); |
1621 DamageTracker::UpdateDamageTracking(host_impl_.active_tree(), | 1939 DamageTracker::UpdateDamageTracking(host_impl_.active_tree(), |
1622 render_surface_list); | 1940 render_surface_list); |
1623 | 1941 |
1624 // Child1 should still not have a valid rect, since the union of the damage of | 1942 // Child1 should still not have a valid rect, since the union of the damage of |
1625 // its children is not representable by a single rect. | 1943 // its children is not representable by a single rect. |
1626 EXPECT_FALSE(GetRenderSurface(child1)->damage_tracker()->GetDamageRectIfValid( | 1944 EXPECT_FALSE(GetRenderSurface(child1)->damage_tracker()->GetDamageRectIfValid( |
1627 &damage_rect)); | 1945 &damage_rect)); |
1628 EXPECT_EQ(GetRenderSurface(child1)->content_rect(), | 1946 EXPECT_EQ(GetRenderSurface(child1)->content_rect(), |
1629 GetRenderSurface(child1)->GetDamageRect()); | 1947 GetRenderSurface(child1)->GetDamageRect()); |
1630 | 1948 |
1631 // Root should have valid damage and contain both its content rect and the | 1949 // Root should have valid damage and contain both its content rect and the |
1632 // drawable content rect of child1. | 1950 // drawable content rect of child1. |
1633 ASSERT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( | 1951 ASSERT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid( |
1634 &damage_rect)); | 1952 &damage_rect)); |
1635 EXPECT_TRUE(damage_rect.Contains(GetRenderSurface(root)->content_rect())); | 1953 EXPECT_TRUE(damage_rect.Contains(GetRenderSurface(root)->content_rect())); |
1636 EXPECT_TRUE(damage_rect.Contains( | 1954 EXPECT_TRUE(damage_rect.Contains( |
1637 gfx::ToEnclosingRect(GetRenderSurface(child1)->DrawableContentRect()))); | 1955 gfx::ToEnclosingRect(GetRenderSurface(child1)->DrawableContentRect()))); |
1638 EXPECT_EQ(damage_rect, GetRenderSurface(root)->GetDamageRect()); | 1956 EXPECT_EQ(damage_rect, GetRenderSurface(root)->GetDamageRect()); |
| 1957 |
| 1958 EXPECT_TRUE(GetRenderSurface(root) |
| 1959 ->damage_tracker() |
| 1960 ->has_damage_from_contributing_content()); |
| 1961 EXPECT_TRUE(GetRenderSurface(child1) |
| 1962 ->damage_tracker() |
| 1963 ->has_damage_from_contributing_content()); |
1639 } | 1964 } |
1640 | 1965 |
1641 } // namespace | 1966 } // namespace |
1642 } // namespace cc | 1967 } // namespace cc |
OLD | NEW |