Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(327)

Side by Side Diff: cc/trees/damage_tracker_unittest.cc

Issue 1801853002: Transfer LayerImpl ownership to LayerTreeImpl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: more asan. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/trees/damage_tracker.h ('k') | cc/trees/draw_property_utils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 The Chromium Authors. All rights reserved. 1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/trees/damage_tracker.h" 5 #include "cc/trees/damage_tracker.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include "cc/base/math_util.h" 9 #include "cc/base/math_util.h"
10 #include "cc/layers/layer_impl.h" 10 #include "cc/layers/layer_impl.h"
(...skipping 30 matching lines...) Expand all
41 LayerTreeHostCommon::CalculateDrawProperties(&inputs); 41 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
42 ASSERT_TRUE(root->render_surface()); 42 ASSERT_TRUE(root->render_surface());
43 } 43 }
44 44
45 void ClearDamageForAllSurfaces(LayerImpl* layer) { 45 void ClearDamageForAllSurfaces(LayerImpl* layer) {
46 if (layer->render_surface()) 46 if (layer->render_surface())
47 layer->render_surface()->damage_tracker()->DidDrawDamagedArea(); 47 layer->render_surface()->damage_tracker()->DidDrawDamagedArea();
48 48
49 // Recursively clear damage for any existing surface. 49 // Recursively clear damage for any existing surface.
50 for (size_t i = 0; i < layer->children().size(); ++i) 50 for (size_t i = 0; i < layer->children().size(); ++i)
51 ClearDamageForAllSurfaces(layer->children()[i].get()); 51 ClearDamageForAllSurfaces(layer->children()[i]);
52 } 52 }
53 53
54 void EmulateDrawingOneFrame(LayerImpl* root) { 54 void EmulateDrawingOneFrame(LayerImpl* root) {
55 // This emulates only steps that are relevant to testing the damage tracker: 55 // This emulates only steps that are relevant to testing the damage tracker:
56 // 1. computing the render passes and layerlists 56 // 1. computing the render passes and layerlists
57 // 2. updating all damage trackers in the correct order 57 // 2. updating all damage trackers in the correct order
58 // 3. resetting all update_rects and property_changed flags for all layers 58 // 3. resetting all update_rects and property_changed flags for all layers
59 // and surfaces. 59 // and surfaces.
60 60
61 LayerImplList render_surface_layer_list; 61 LayerImplList render_surface_layer_list;
(...skipping 19 matching lines...) Expand all
81 } 81 }
82 82
83 class DamageTrackerTest : public testing::Test { 83 class DamageTrackerTest : public testing::Test {
84 public: 84 public:
85 DamageTrackerTest() 85 DamageTrackerTest()
86 : host_impl_(&task_runner_provider_, 86 : host_impl_(&task_runner_provider_,
87 &shared_bitmap_manager_, 87 &shared_bitmap_manager_,
88 &task_graph_runner_) {} 88 &task_graph_runner_) {}
89 89
90 LayerImpl* CreateTestTreeWithOneSurface() { 90 LayerImpl* CreateTestTreeWithOneSurface() {
91 host_impl_.active_tree()->DetachLayerTree(); 91 host_impl_.active_tree()->ClearLayers();
92 scoped_ptr<LayerImpl> root = 92 scoped_ptr<LayerImpl> root =
93 LayerImpl::Create(host_impl_.active_tree(), 1); 93 LayerImpl::Create(host_impl_.active_tree(), 1);
94 scoped_ptr<LayerImpl> child = 94 scoped_ptr<LayerImpl> child =
95 LayerImpl::Create(host_impl_.active_tree(), 2); 95 LayerImpl::Create(host_impl_.active_tree(), 2);
96 96
97 root->SetPosition(gfx::PointF()); 97 root->SetPosition(gfx::PointF());
98 root->SetBounds(gfx::Size(500, 500)); 98 root->SetBounds(gfx::Size(500, 500));
99 root->SetDrawsContent(true); 99 root->SetDrawsContent(true);
100 root->SetForceRenderSurface(true); 100 root->SetForceRenderSurface(true);
101 101
102 child->SetPosition(gfx::PointF(100.f, 100.f)); 102 child->SetPosition(gfx::PointF(100.f, 100.f));
103 child->SetBounds(gfx::Size(30, 30)); 103 child->SetBounds(gfx::Size(30, 30));
104 child->SetDrawsContent(true); 104 child->SetDrawsContent(true);
105 root->AddChild(std::move(child)); 105 root->AddChild(std::move(child));
106 host_impl_.active_tree()->SetRootLayer(std::move(root)); 106 host_impl_.active_tree()->SetRootLayer(std::move(root));
107 107
108 return host_impl_.active_tree()->root_layer(); 108 return host_impl_.active_tree()->root_layer();
109 } 109 }
110 110
111 LayerImpl* CreateTestTreeWithTwoSurfaces() { 111 LayerImpl* CreateTestTreeWithTwoSurfaces() {
112 // This test tree has two render surfaces: one for the root, and one for 112 // This test tree has two render surfaces: one for the root, and one for
113 // child1. Additionally, the root has a second child layer, and child1 has 113 // child1. Additionally, the root has a second child layer, and child1 has
114 // two children of its own. 114 // two children of its own.
115 115
116 host_impl_.active_tree()->DetachLayerTree(); 116 host_impl_.active_tree()->ClearLayers();
117 scoped_ptr<LayerImpl> root = 117 scoped_ptr<LayerImpl> root =
118 LayerImpl::Create(host_impl_.active_tree(), 1); 118 LayerImpl::Create(host_impl_.active_tree(), 1);
119 scoped_ptr<LayerImpl> child1 = 119 scoped_ptr<LayerImpl> child1 =
120 LayerImpl::Create(host_impl_.active_tree(), 2); 120 LayerImpl::Create(host_impl_.active_tree(), 2);
121 scoped_ptr<LayerImpl> child2 = 121 scoped_ptr<LayerImpl> child2 =
122 LayerImpl::Create(host_impl_.active_tree(), 3); 122 LayerImpl::Create(host_impl_.active_tree(), 3);
123 scoped_ptr<LayerImpl> grand_child1 = 123 scoped_ptr<LayerImpl> grand_child1 =
124 LayerImpl::Create(host_impl_.active_tree(), 4); 124 LayerImpl::Create(host_impl_.active_tree(), 4);
125 scoped_ptr<LayerImpl> grand_child2 = 125 scoped_ptr<LayerImpl> grand_child2 =
126 LayerImpl::Create(host_impl_.active_tree(), 5); 126 LayerImpl::Create(host_impl_.active_tree(), 5);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 203
204 EXPECT_EQ(gfx::Rect(500, 500).ToString(), root_damage_rect.ToString()); 204 EXPECT_EQ(gfx::Rect(500, 500).ToString(), root_damage_rect.ToString());
205 } 205 }
206 206
207 TEST_F(DamageTrackerTest, SanityCheckTestTreeWithTwoSurfaces) { 207 TEST_F(DamageTrackerTest, SanityCheckTestTreeWithTwoSurfaces) {
208 // Sanity check that the complex test tree will actually produce the expected 208 // Sanity check that the complex test tree will actually produce the expected
209 // render surfaces and layer lists. 209 // render surfaces and layer lists.
210 210
211 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); 211 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces();
212 212
213 LayerImpl* child1 = root->children()[0].get(); 213 LayerImpl* child1 = root->children()[0];
214 LayerImpl* child2 = root->children()[1].get(); 214 LayerImpl* child2 = root->children()[1];
215 gfx::Rect child_damage_rect = 215 gfx::Rect child_damage_rect =
216 child1->render_surface()->damage_tracker()->current_damage_rect(); 216 child1->render_surface()->damage_tracker()->current_damage_rect();
217 gfx::Rect root_damage_rect = 217 gfx::Rect root_damage_rect =
218 root->render_surface()->damage_tracker()->current_damage_rect(); 218 root->render_surface()->damage_tracker()->current_damage_rect();
219 219
220 ASSERT_TRUE(child1->render_surface()); 220 ASSERT_TRUE(child1->render_surface());
221 EXPECT_FALSE(child2->render_surface()); 221 EXPECT_FALSE(child2->render_surface());
222 EXPECT_EQ(3u, root->render_surface()->layer_list().size()); 222 EXPECT_EQ(3u, root->render_surface()->layer_list().size());
223 EXPECT_EQ(2u, child1->render_surface()->layer_list().size()); 223 EXPECT_EQ(2u, child1->render_surface()->layer_list().size());
224 224
225 // The render surface for child1 only has a content_rect that encloses 225 // The render surface for child1 only has a content_rect that encloses
226 // grand_child1 and grand_child2, because child1 does not draw content. 226 // grand_child1 and grand_child2, because child1 does not draw content.
227 EXPECT_EQ(gfx::Rect(190, 190, 16, 18).ToString(), 227 EXPECT_EQ(gfx::Rect(190, 190, 16, 18).ToString(),
228 child_damage_rect.ToString()); 228 child_damage_rect.ToString());
229 EXPECT_EQ(gfx::Rect(500, 500).ToString(), root_damage_rect.ToString()); 229 EXPECT_EQ(gfx::Rect(500, 500).ToString(), root_damage_rect.ToString());
230 } 230 }
231 231
232 TEST_F(DamageTrackerTest, VerifyDamageForUpdateRects) { 232 TEST_F(DamageTrackerTest, VerifyDamageForUpdateRects) {
233 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); 233 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface();
234 LayerImpl* child = root->children()[0].get(); 234 LayerImpl* child = root->children()[0];
235 235
236 // 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
237 // the surface. 237 // the surface.
238 ClearDamageForAllSurfaces(root); 238 ClearDamageForAllSurfaces(root);
239 child->SetUpdateRect(gfx::Rect(10, 11, 12, 13)); 239 child->SetUpdateRect(gfx::Rect(10, 11, 12, 13));
240 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 240 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
241 EmulateDrawingOneFrame(root); 241 EmulateDrawingOneFrame(root);
242 242
243 // Damage position on the surface should be: position of update_rect (10, 11) 243 // Damage position on the surface should be: position of update_rect (10, 11)
244 // relative to the child (100, 100). 244 // relative to the child (100, 100).
(...skipping 22 matching lines...) Expand all
267 267
268 // Damage position on the surface should be: position of update_rect (20, 25) 268 // Damage position on the surface should be: position of update_rect (20, 25)
269 // relative to the child (100, 100). 269 // relative to the child (100, 100).
270 root_damage_rect = 270 root_damage_rect =
271 root->render_surface()->damage_tracker()->current_damage_rect(); 271 root->render_surface()->damage_tracker()->current_damage_rect();
272 EXPECT_EQ(gfx::Rect(120, 125, 1, 2).ToString(), root_damage_rect.ToString()); 272 EXPECT_EQ(gfx::Rect(120, 125, 1, 2).ToString(), root_damage_rect.ToString());
273 } 273 }
274 274
275 TEST_F(DamageTrackerTest, VerifyDamageForLayerDamageRects) { 275 TEST_F(DamageTrackerTest, VerifyDamageForLayerDamageRects) {
276 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); 276 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface();
277 LayerImpl* child = root->children()[0].get(); 277 LayerImpl* child = root->children()[0];
278 278
279 // CASE 1: Adding the layer damage rect should cause the corresponding damage 279 // CASE 1: Adding the layer damage rect should cause the corresponding damage
280 // to the surface. 280 // to the surface.
281 ClearDamageForAllSurfaces(root); 281 ClearDamageForAllSurfaces(root);
282 child->AddDamageRect(gfx::Rect(10, 11, 12, 13)); 282 child->AddDamageRect(gfx::Rect(10, 11, 12, 13));
283 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 283 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
284 EmulateDrawingOneFrame(root); 284 EmulateDrawingOneFrame(root);
285 285
286 // Damage position on the surface should be: position of layer damage_rect 286 // Damage position on the surface should be: position of layer damage_rect
287 // (10, 11) relative to the child (100, 100). 287 // (10, 11) relative to the child (100, 100).
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 // Damage position on the surface should be: position of layer damage_rect 323 // Damage position on the surface should be: position of layer damage_rect
324 // (20, 25) relative to the child (100, 100). 324 // (20, 25) relative to the child (100, 100).
325 root_damage_rect = 325 root_damage_rect =
326 root->render_surface()->damage_tracker()->current_damage_rect(); 326 root->render_surface()->damage_tracker()->current_damage_rect();
327 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(120, 125, 1, 2))); 327 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(120, 125, 1, 2)));
328 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(110, 115, 3, 4))); 328 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(110, 115, 3, 4)));
329 } 329 }
330 330
331 TEST_F(DamageTrackerTest, VerifyDamageForLayerUpdateAndDamageRects) { 331 TEST_F(DamageTrackerTest, VerifyDamageForLayerUpdateAndDamageRects) {
332 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); 332 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface();
333 LayerImpl* child = root->children()[0].get(); 333 LayerImpl* child = root->children()[0];
334 334
335 // CASE 1: Adding the layer damage rect and update rect should cause the 335 // CASE 1: Adding the layer damage rect and update rect should cause the
336 // corresponding damage to the surface. 336 // corresponding damage to the surface.
337 ClearDamageForAllSurfaces(root); 337 ClearDamageForAllSurfaces(root);
338 child->AddDamageRect(gfx::Rect(5, 6, 12, 13)); 338 child->AddDamageRect(gfx::Rect(5, 6, 12, 13));
339 child->SetUpdateRect(gfx::Rect(15, 16, 14, 10)); 339 child->SetUpdateRect(gfx::Rect(15, 16, 14, 10));
340 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 340 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
341 EmulateDrawingOneFrame(root); 341 EmulateDrawingOneFrame(root);
342 342
343 // Damage position on the surface should be: position of unified layer 343 // Damage position on the surface should be: position of unified layer
(...skipping 24 matching lines...) Expand all
368 368
369 // Damage position on the surface should be: position of unified layer damage 369 // Damage position on the surface should be: position of unified layer damage
370 // rect and update rect (5, 10) relative to the child (100, 100). 370 // rect and update rect (5, 10) relative to the child (100, 100).
371 root_damage_rect = 371 root_damage_rect =
372 root->render_surface()->damage_tracker()->current_damage_rect(); 372 root->render_surface()->damage_tracker()->current_damage_rect();
373 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(105, 110, 17, 18))); 373 EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(105, 110, 17, 18)));
374 } 374 }
375 375
376 TEST_F(DamageTrackerTest, VerifyDamageForPropertyChanges) { 376 TEST_F(DamageTrackerTest, VerifyDamageForPropertyChanges) {
377 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); 377 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface();
378 LayerImpl* child = root->children()[0].get(); 378 LayerImpl* child = root->children()[0];
379 379
380 // CASE 1: The layer's property changed flag takes priority over update rect. 380 // CASE 1: The layer's property changed flag takes priority over update rect.
381 // 381 //
382 child->SetForceRenderSurface(true); 382 child->SetForceRenderSurface(true);
383 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 383 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
384 EmulateDrawingOneFrame(root); 384 EmulateDrawingOneFrame(root);
385 ClearDamageForAllSurfaces(root); 385 ClearDamageForAllSurfaces(root);
386 child->SetUpdateRect(gfx::Rect(10, 11, 12, 13)); 386 child->SetUpdateRect(gfx::Rect(10, 11, 12, 13));
387 child->OnOpacityAnimated(0.5f); 387 child->OnOpacityAnimated(0.5f);
388 EmulateDrawingOneFrame(root); 388 EmulateDrawingOneFrame(root);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 root_damage_rect = 420 root_damage_rect =
421 root->render_surface()->damage_tracker()->current_damage_rect(); 421 root->render_surface()->damage_tracker()->current_damage_rect();
422 EXPECT_FLOAT_RECT_EQ(expected_rect, root_damage_rect); 422 EXPECT_FLOAT_RECT_EQ(expected_rect, root_damage_rect);
423 } 423 }
424 424
425 TEST_F(DamageTrackerTest, VerifyDamageForTransformedLayer) { 425 TEST_F(DamageTrackerTest, VerifyDamageForTransformedLayer) {
426 // If a layer is transformed, the damage rect should still enclose the entire 426 // If a layer is transformed, the damage rect should still enclose the entire
427 // transformed layer. 427 // transformed layer.
428 428
429 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); 429 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface();
430 LayerImpl* child = root->children()[0].get(); 430 LayerImpl* child = root->children()[0];
431 child->SetForceRenderSurface(true); 431 child->SetForceRenderSurface(true);
432 432
433 gfx::Transform rotation; 433 gfx::Transform rotation;
434 rotation.Rotate(45.0); 434 rotation.Rotate(45.0);
435 435
436 ClearDamageForAllSurfaces(root); 436 ClearDamageForAllSurfaces(root);
437 child->SetTransformOrigin(gfx::Point3F( 437 child->SetTransformOrigin(gfx::Point3F(
438 child->bounds().width() * 0.5f, child->bounds().height() * 0.5f, 0.f)); 438 child->bounds().width() * 0.5f, child->bounds().height() * 0.5f, 0.f));
439 child->SetPosition(gfx::PointF(85.f, 85.f)); 439 child->SetPosition(gfx::PointF(85.f, 85.f));
440 child->NoteLayerPropertyChanged(); 440 child->NoteLayerPropertyChanged();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 // 473 //
474 // The transform is constructed so that if w < 0 clipping is not performed, 474 // The transform is constructed so that if w < 0 clipping is not performed,
475 // the incorrect rect will be very small, specifically: position (500.972504, 475 // the incorrect rect will be very small, specifically: position (500.972504,
476 // 498.544617) and size 0.056610 x 2.910767. Instead, the correctly 476 // 498.544617) and size 0.056610 x 2.910767. Instead, the correctly
477 // transformed rect should actually be very huge (i.e. in theory, -infinity 477 // transformed rect should actually be very huge (i.e. in theory, -infinity
478 // on the left), and positioned so that the right-most bound rect will be 478 // on the left), and positioned so that the right-most bound rect will be
479 // approximately 501 units in root surface space. 479 // approximately 501 units in root surface space.
480 // 480 //
481 481
482 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); 482 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface();
483 LayerImpl* child = root->children()[0].get(); 483 LayerImpl* child = root->children()[0];
484 484
485 gfx::Transform transform; 485 gfx::Transform transform;
486 transform.Translate3d(500.0, 500.0, 0.0); 486 transform.Translate3d(500.0, 500.0, 0.0);
487 transform.ApplyPerspectiveDepth(1.0); 487 transform.ApplyPerspectiveDepth(1.0);
488 transform.RotateAboutYAxis(45.0); 488 transform.RotateAboutYAxis(45.0);
489 transform.Translate3d(-50.0, -50.0, 0.0); 489 transform.Translate3d(-50.0, -50.0, 0.0);
490 490
491 // Set up the child 491 // Set up the child
492 child->SetPosition(gfx::PointF(0.f, 0.f)); 492 child->SetPosition(gfx::PointF(0.f, 0.f));
493 child->SetBounds(gfx::Size(100, 100)); 493 child->SetBounds(gfx::Size(100, 100));
(...skipping 20 matching lines...) Expand all
514 // don't care whether the damage rect was clamped or is larger than the 514 // don't care whether the damage rect was clamped or is larger than the
515 // surface for this test. 515 // surface for this test.
516 gfx::Rect root_damage_rect = 516 gfx::Rect root_damage_rect =
517 root->render_surface()->damage_tracker()->current_damage_rect(); 517 root->render_surface()->damage_tracker()->current_damage_rect();
518 gfx::Rect damage_we_care_about = gfx::Rect(gfx::Size(500, 500)); 518 gfx::Rect damage_we_care_about = gfx::Rect(gfx::Size(500, 500));
519 EXPECT_TRUE(root_damage_rect.Contains(damage_we_care_about)); 519 EXPECT_TRUE(root_damage_rect.Contains(damage_we_care_about));
520 } 520 }
521 521
522 TEST_F(DamageTrackerTest, VerifyDamageForBlurredSurface) { 522 TEST_F(DamageTrackerTest, VerifyDamageForBlurredSurface) {
523 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); 523 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces();
524 LayerImpl* surface = root->children()[0].get(); 524 LayerImpl* surface = root->children()[0];
525 LayerImpl* child = surface->children()[0].get(); 525 LayerImpl* child = surface->children()[0];
526 526
527 FilterOperations filters; 527 FilterOperations filters;
528 filters.Append(FilterOperation::CreateBlurFilter(5.f)); 528 filters.Append(FilterOperation::CreateBlurFilter(5.f));
529 int outset_top, outset_right, outset_bottom, outset_left; 529 int outset_top, outset_right, outset_bottom, outset_left;
530 filters.GetOutsets(&outset_top, &outset_right, &outset_bottom, &outset_left); 530 filters.GetOutsets(&outset_top, &outset_right, &outset_bottom, &outset_left);
531 531
532 // Setting the filter will damage the whole surface. 532 // Setting the filter will damage the whole surface.
533 ClearDamageForAllSurfaces(root); 533 ClearDamageForAllSurfaces(root);
534 surface->SetFilters(filters); 534 surface->SetFilters(filters);
535 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 535 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
(...skipping 14 matching lines...) Expand all
550 550
551 expected_damage_rect.Inset(-outset_left, 551 expected_damage_rect.Inset(-outset_left,
552 -outset_top, 552 -outset_top,
553 -outset_right, 553 -outset_right,
554 -outset_bottom); 554 -outset_bottom);
555 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString()); 555 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString());
556 } 556 }
557 557
558 TEST_F(DamageTrackerTest, VerifyDamageForImageFilter) { 558 TEST_F(DamageTrackerTest, VerifyDamageForImageFilter) {
559 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); 559 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface();
560 LayerImpl* child = root->children()[0].get(); 560 LayerImpl* child = root->children()[0];
561 gfx::Rect root_damage_rect, child_damage_rect; 561 gfx::Rect root_damage_rect, child_damage_rect;
562 562
563 // Allow us to set damage on child too. 563 // Allow us to set damage on child too.
564 child->SetDrawsContent(true); 564 child->SetDrawsContent(true);
565 565
566 skia::RefPtr<SkImageFilter> filter = skia::AdoptRef( 566 skia::RefPtr<SkImageFilter> filter = skia::AdoptRef(
567 SkBlurImageFilter::Create(SkIntToScalar(2), SkIntToScalar(2))); 567 SkBlurImageFilter::Create(SkIntToScalar(2), SkIntToScalar(2)));
568 FilterOperations filters; 568 FilterOperations filters;
569 filters.Append(FilterOperation::CreateReferenceFilter(filter)); 569 filters.Append(FilterOperation::CreateReferenceFilter(filter));
570 int outset_top, outset_right, outset_bottom, outset_left; 570 int outset_top, outset_right, outset_bottom, outset_left;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
605 expect_height) 605 expect_height)
606 .ToString(), 606 .ToString(),
607 root_damage_rect.ToString()); 607 root_damage_rect.ToString());
608 EXPECT_EQ(gfx::Rect(-outset_left, -outset_top, expect_width, expect_height) 608 EXPECT_EQ(gfx::Rect(-outset_left, -outset_top, expect_width, expect_height)
609 .ToString(), 609 .ToString(),
610 child_damage_rect.ToString()); 610 child_damage_rect.ToString());
611 } 611 }
612 612
613 TEST_F(DamageTrackerTest, VerifyDamageForBackgroundBlurredChild) { 613 TEST_F(DamageTrackerTest, VerifyDamageForBackgroundBlurredChild) {
614 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); 614 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces();
615 LayerImpl* child1 = root->children()[0].get(); 615 LayerImpl* child1 = root->children()[0];
616 LayerImpl* child2 = root->children()[1].get(); 616 LayerImpl* child2 = root->children()[1];
617 617
618 // Allow us to set damage on child1 too. 618 // Allow us to set damage on child1 too.
619 child1->SetDrawsContent(true); 619 child1->SetDrawsContent(true);
620 620
621 FilterOperations filters; 621 FilterOperations filters;
622 filters.Append(FilterOperation::CreateBlurFilter(2.f)); 622 filters.Append(FilterOperation::CreateBlurFilter(2.f));
623 int outset_top, outset_right, outset_bottom, outset_left; 623 int outset_top, outset_right, outset_bottom, outset_left;
624 filters.GetOutsets(&outset_top, &outset_right, &outset_bottom, &outset_left); 624 filters.GetOutsets(&outset_top, &outset_right, &outset_bottom, &outset_left);
625 625
626 // Setting the filter will damage the whole surface. 626 // Setting the filter will damage the whole surface.
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
739 739
740 expected_damage_rect.Inset(-outset_left, 740 expected_damage_rect.Inset(-outset_left,
741 -outset_top, 741 -outset_top,
742 -outset_right, 742 -outset_right,
743 -outset_bottom); 743 -outset_bottom);
744 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString()); 744 EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString());
745 } 745 }
746 746
747 TEST_F(DamageTrackerTest, VerifyDamageForAddingAndRemovingLayer) { 747 TEST_F(DamageTrackerTest, VerifyDamageForAddingAndRemovingLayer) {
748 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); 748 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface();
749 LayerImpl* child1 = root->children()[0].get(); 749 LayerImpl* child1 = root->children()[0];
750 750
751 // CASE 1: Adding a new layer should cause the appropriate damage. 751 // CASE 1: Adding a new layer should cause the appropriate damage.
752 // 752 //
753 ClearDamageForAllSurfaces(root); 753 ClearDamageForAllSurfaces(root);
754 { 754 {
755 scoped_ptr<LayerImpl> child2 = 755 scoped_ptr<LayerImpl> child2 =
756 LayerImpl::Create(host_impl_.active_tree(), 3); 756 LayerImpl::Create(host_impl_.active_tree(), 3);
757 child2->SetPosition(gfx::PointF(400.f, 380.f)); 757 child2->SetPosition(gfx::PointF(400.f, 380.f));
758 child2->SetBounds(gfx::Size(6, 8)); 758 child2->SetBounds(gfx::Size(6, 8));
759 child2->SetDrawsContent(true); 759 child2->SetDrawsContent(true);
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
825 // surfaces are tested elsewhere. 825 // surfaces are tested elsewhere.
826 ASSERT_EQ(3u, root->render_surface()->layer_list().size()); 826 ASSERT_EQ(3u, root->render_surface()->layer_list().size());
827 827
828 gfx::Rect root_damage_rect = 828 gfx::Rect root_damage_rect =
829 root->render_surface()->damage_tracker()->current_damage_rect(); 829 root->render_surface()->damage_tracker()->current_damage_rect();
830 EXPECT_EQ(gfx::Rect(400, 380, 6, 8).ToString(), root_damage_rect.ToString()); 830 EXPECT_EQ(gfx::Rect(400, 380, 6, 8).ToString(), root_damage_rect.ToString());
831 } 831 }
832 832
833 TEST_F(DamageTrackerTest, VerifyDamageForMultipleLayers) { 833 TEST_F(DamageTrackerTest, VerifyDamageForMultipleLayers) {
834 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); 834 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface();
835 LayerImpl* child1 = root->children()[0].get(); 835 LayerImpl* child1 = root->children()[0];
836 836
837 // In this test we don't want the above tree manipulation to be considered 837 // In this test we don't want the above tree manipulation to be considered
838 // part of the same frame. 838 // part of the same frame.
839 ClearDamageForAllSurfaces(root); 839 ClearDamageForAllSurfaces(root);
840 { 840 {
841 scoped_ptr<LayerImpl> child2 = 841 scoped_ptr<LayerImpl> child2 =
842 LayerImpl::Create(host_impl_.active_tree(), 3); 842 LayerImpl::Create(host_impl_.active_tree(), 3);
843 child2->SetPosition(gfx::PointF(400.f, 380.f)); 843 child2->SetPosition(gfx::PointF(400.f, 380.f));
844 child2->SetBounds(gfx::Size(6, 8)); 844 child2->SetBounds(gfx::Size(6, 8));
845 child2->SetDrawsContent(true); 845 child2->SetDrawsContent(true);
846 root->AddChild(std::move(child2)); 846 root->AddChild(std::move(child2));
847 } 847 }
848 LayerImpl* child2 = root->children()[1].get(); 848 LayerImpl* child2 = root->children()[1];
849 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 849 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
850 EmulateDrawingOneFrame(root); 850 EmulateDrawingOneFrame(root);
851 851
852 // Damaging two layers simultaneously should cause combined damage. 852 // Damaging two layers simultaneously should cause combined damage.
853 // - child1 update rect in surface space: gfx::Rect(100, 100, 1, 2); 853 // - child1 update rect in surface space: gfx::Rect(100, 100, 1, 2);
854 // - child2 update rect in surface space: gfx::Rect(400, 380, 3, 4); 854 // - child2 update rect in surface space: gfx::Rect(400, 380, 3, 4);
855 ClearDamageForAllSurfaces(root); 855 ClearDamageForAllSurfaces(root);
856 child1->SetUpdateRect(gfx::Rect(1, 2)); 856 child1->SetUpdateRect(gfx::Rect(1, 2));
857 child2->SetUpdateRect(gfx::Rect(3, 4)); 857 child2->SetUpdateRect(gfx::Rect(3, 4));
858 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 858 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
859 EmulateDrawingOneFrame(root); 859 EmulateDrawingOneFrame(root);
860 gfx::Rect root_damage_rect = 860 gfx::Rect root_damage_rect =
861 root->render_surface()->damage_tracker()->current_damage_rect(); 861 root->render_surface()->damage_tracker()->current_damage_rect();
862 EXPECT_EQ(gfx::Rect(100, 100, 303, 284).ToString(), 862 EXPECT_EQ(gfx::Rect(100, 100, 303, 284).ToString(),
863 root_damage_rect.ToString()); 863 root_damage_rect.ToString());
864 } 864 }
865 865
866 TEST_F(DamageTrackerTest, VerifyDamageForNestedSurfaces) { 866 TEST_F(DamageTrackerTest, VerifyDamageForNestedSurfaces) {
867 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); 867 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces();
868 LayerImpl* child1 = root->children()[0].get(); 868 LayerImpl* child1 = root->children()[0];
869 LayerImpl* child2 = root->children()[1].get(); 869 LayerImpl* child2 = root->children()[1];
870 LayerImpl* grand_child1 = root->children()[0]->children()[0].get(); 870 LayerImpl* grand_child1 = root->children()[0]->children()[0];
871 child2->SetForceRenderSurface(true); 871 child2->SetForceRenderSurface(true);
872 grand_child1->SetForceRenderSurface(true); 872 grand_child1->SetForceRenderSurface(true);
873 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 873 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
874 EmulateDrawingOneFrame(root); 874 EmulateDrawingOneFrame(root);
875 gfx::Rect child_damage_rect; 875 gfx::Rect child_damage_rect;
876 gfx::Rect root_damage_rect; 876 gfx::Rect root_damage_rect;
877 877
878 // CASE 1: Damage to a descendant surface should propagate properly to 878 // CASE 1: Damage to a descendant surface should propagate properly to
879 // ancestor surface. 879 // ancestor surface.
880 ClearDamageForAllSurfaces(root); 880 ClearDamageForAllSurfaces(root);
(...skipping 27 matching lines...) Expand all
908 908
909 TEST_F(DamageTrackerTest, VerifyDamageForSurfaceChangeFromDescendantLayer) { 909 TEST_F(DamageTrackerTest, VerifyDamageForSurfaceChangeFromDescendantLayer) {
910 // If descendant layer changes and affects the content bounds of the render 910 // If descendant layer changes and affects the content bounds of the render
911 // surface, then the entire descendant surface should be damaged, and it 911 // surface, then the entire descendant surface should be damaged, and it
912 // should damage its ancestor surface with the old and new surface regions. 912 // should damage its ancestor surface with the old and new surface regions.
913 913
914 // This is a tricky case, since only the first grand_child changes, but the 914 // This is a tricky case, since only the first grand_child changes, but the
915 // entire surface should be marked dirty. 915 // entire surface should be marked dirty.
916 916
917 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); 917 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces();
918 LayerImpl* child1 = root->children()[0].get(); 918 LayerImpl* child1 = root->children()[0];
919 LayerImpl* grand_child1 = root->children()[0]->children()[0].get(); 919 LayerImpl* grand_child1 = root->children()[0]->children()[0];
920 gfx::Rect child_damage_rect; 920 gfx::Rect child_damage_rect;
921 gfx::Rect root_damage_rect; 921 gfx::Rect root_damage_rect;
922 922
923 ClearDamageForAllSurfaces(root); 923 ClearDamageForAllSurfaces(root);
924 grand_child1->SetPosition(gfx::PointF(195.f, 205.f)); 924 grand_child1->SetPosition(gfx::PointF(195.f, 205.f));
925 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 925 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
926 EmulateDrawingOneFrame(root); 926 EmulateDrawingOneFrame(root);
927 child_damage_rect = 927 child_damage_rect =
928 child1->render_surface()->damage_tracker()->current_damage_rect(); 928 child1->render_surface()->damage_tracker()->current_damage_rect();
929 root_damage_rect = 929 root_damage_rect =
(...skipping 17 matching lines...) Expand all
947 // already propagates to the subtree (tested in LayerImpltest), which damages 947 // already propagates to the subtree (tested in LayerImpltest), which damages
948 // the entire child1 surface, but the damage tracker still needs the correct 948 // the entire child1 surface, but the damage tracker still needs the correct
949 // logic to compute the exposed region on the root surface. 949 // logic to compute the exposed region on the root surface.
950 950
951 // TODO(shawnsingh): the expectations of this test case should change when we 951 // TODO(shawnsingh): the expectations of this test case should change when we
952 // add support for a unique scissor_rect per RenderSurface. In that case, the 952 // add support for a unique scissor_rect per RenderSurface. In that case, the
953 // child1 surface should be completely unchanged, since we are only 953 // child1 surface should be completely unchanged, since we are only
954 // transforming it, while the root surface would be damaged appropriately. 954 // transforming it, while the root surface would be damaged appropriately.
955 955
956 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); 956 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces();
957 LayerImpl* child1 = root->children()[0].get(); 957 LayerImpl* child1 = root->children()[0];
958 LayerImpl* grand_child1 = child1->children()[0].get(); 958 LayerImpl* grand_child1 = child1->children()[0];
959 LayerImpl* grand_child2 = child1->children()[1].get(); 959 LayerImpl* grand_child2 = child1->children()[1];
960 gfx::Rect child_damage_rect; 960 gfx::Rect child_damage_rect;
961 gfx::Rect root_damage_rect; 961 gfx::Rect root_damage_rect;
962 962
963 ClearDamageForAllSurfaces(root); 963 ClearDamageForAllSurfaces(root);
964 child1->SetPosition(gfx::PointF(50.f, 50.f)); 964 child1->SetPosition(gfx::PointF(50.f, 50.f));
965 child1->NoteLayerPropertyChanged(); 965 child1->NoteLayerPropertyChanged();
966 grand_child1->NoteLayerPropertyChanged(); 966 grand_child1->NoteLayerPropertyChanged();
967 grand_child2->NoteLayerPropertyChanged(); 967 grand_child2->NoteLayerPropertyChanged();
968 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 968 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
969 EmulateDrawingOneFrame(root); 969 EmulateDrawingOneFrame(root);
970 child_damage_rect = 970 child_damage_rect =
971 child1->render_surface()->damage_tracker()->current_damage_rect(); 971 child1->render_surface()->damage_tracker()->current_damage_rect();
972 root_damage_rect = 972 root_damage_rect =
973 root->render_surface()->damage_tracker()->current_damage_rect(); 973 root->render_surface()->damage_tracker()->current_damage_rect();
974 974
975 // The new surface bounds should be damaged entirely. 975 // The new surface bounds should be damaged entirely.
976 EXPECT_EQ(gfx::Rect(190, 190, 16, 18).ToString(), 976 EXPECT_EQ(gfx::Rect(190, 190, 16, 18).ToString(),
977 child_damage_rect.ToString()); 977 child_damage_rect.ToString());
978 978
979 // The entire child1 surface and the old exposed child1 surface should damage 979 // The entire child1 surface and the old exposed child1 surface should damage
980 // the root surface. 980 // the root surface.
981 // - old child1 surface in target space: gfx::Rect(290, 290, 16, 18) 981 // - old child1 surface in target space: gfx::Rect(290, 290, 16, 18)
982 // - new child1 surface in target space: gfx::Rect(240, 240, 16, 18) 982 // - new child1 surface in target space: gfx::Rect(240, 240, 16, 18)
983 EXPECT_EQ(gfx::Rect(240, 240, 66, 68).ToString(), 983 EXPECT_EQ(gfx::Rect(240, 240, 66, 68).ToString(),
984 root_damage_rect.ToString()); 984 root_damage_rect.ToString());
985 } 985 }
986 986
987 TEST_F(DamageTrackerTest, VerifyDamageForAddingAndRemovingRenderSurfaces) { 987 TEST_F(DamageTrackerTest, VerifyDamageForAddingAndRemovingRenderSurfaces) {
988 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); 988 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces();
989 LayerImpl* child1 = root->children()[0].get(); 989 LayerImpl* child1 = root->children()[0];
990 gfx::Rect child_damage_rect; 990 gfx::Rect child_damage_rect;
991 gfx::Rect root_damage_rect; 991 gfx::Rect root_damage_rect;
992 992
993 // CASE 1: If a descendant surface disappears, its entire old area becomes 993 // CASE 1: If a descendant surface disappears, its entire old area becomes
994 // exposed. 994 // exposed.
995 ClearDamageForAllSurfaces(root); 995 ClearDamageForAllSurfaces(root);
996 child1->SetForceRenderSurface(false); 996 child1->SetForceRenderSurface(false);
997 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 997 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
998 EmulateDrawingOneFrame(root); 998 EmulateDrawingOneFrame(root);
999 999
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1035 root_damage_rect = 1035 root_damage_rect =
1036 root->render_surface()->damage_tracker()->current_damage_rect(); 1036 root->render_surface()->damage_tracker()->current_damage_rect();
1037 EXPECT_EQ(gfx::Rect(190, 190, 16, 18).ToString(), 1037 EXPECT_EQ(gfx::Rect(190, 190, 16, 18).ToString(),
1038 child_damage_rect.ToString()); 1038 child_damage_rect.ToString());
1039 EXPECT_EQ(gfx::Rect(290, 290, 16, 18).ToString(), 1039 EXPECT_EQ(gfx::Rect(290, 290, 16, 18).ToString(),
1040 root_damage_rect.ToString()); 1040 root_damage_rect.ToString());
1041 } 1041 }
1042 1042
1043 TEST_F(DamageTrackerTest, VerifyNoDamageWhenNothingChanged) { 1043 TEST_F(DamageTrackerTest, VerifyNoDamageWhenNothingChanged) {
1044 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); 1044 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces();
1045 LayerImpl* child1 = root->children()[0].get(); 1045 LayerImpl* child1 = root->children()[0];
1046 gfx::Rect child_damage_rect; 1046 gfx::Rect child_damage_rect;
1047 gfx::Rect root_damage_rect; 1047 gfx::Rect root_damage_rect;
1048 1048
1049 // CASE 1: If nothing changes, the damage rect should be empty. 1049 // CASE 1: If nothing changes, the damage rect should be empty.
1050 // 1050 //
1051 ClearDamageForAllSurfaces(root); 1051 ClearDamageForAllSurfaces(root);
1052 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 1052 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
1053 EmulateDrawingOneFrame(root); 1053 EmulateDrawingOneFrame(root);
1054 child_damage_rect = 1054 child_damage_rect =
1055 child1->render_surface()->damage_tracker()->current_damage_rect(); 1055 child1->render_surface()->damage_tracker()->current_damage_rect();
(...skipping 11 matching lines...) Expand all
1067 child_damage_rect = 1067 child_damage_rect =
1068 child1->render_surface()->damage_tracker()->current_damage_rect(); 1068 child1->render_surface()->damage_tracker()->current_damage_rect();
1069 root_damage_rect = 1069 root_damage_rect =
1070 root->render_surface()->damage_tracker()->current_damage_rect(); 1070 root->render_surface()->damage_tracker()->current_damage_rect();
1071 EXPECT_TRUE(child_damage_rect.IsEmpty()); 1071 EXPECT_TRUE(child_damage_rect.IsEmpty());
1072 EXPECT_TRUE(root_damage_rect.IsEmpty()); 1072 EXPECT_TRUE(root_damage_rect.IsEmpty());
1073 } 1073 }
1074 1074
1075 TEST_F(DamageTrackerTest, VerifyNoDamageForUpdateRectThatDoesNotDrawContent) { 1075 TEST_F(DamageTrackerTest, VerifyNoDamageForUpdateRectThatDoesNotDrawContent) {
1076 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); 1076 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces();
1077 LayerImpl* child1 = root->children()[0].get(); 1077 LayerImpl* child1 = root->children()[0];
1078 gfx::Rect child_damage_rect; 1078 gfx::Rect child_damage_rect;
1079 gfx::Rect root_damage_rect; 1079 gfx::Rect root_damage_rect;
1080 1080
1081 // In our specific tree, the update rect of child1 should not cause any 1081 // In our specific tree, the update rect of child1 should not cause any
1082 // damage to any surface because it does not actually draw content. 1082 // damage to any surface because it does not actually draw content.
1083 ClearDamageForAllSurfaces(root); 1083 ClearDamageForAllSurfaces(root);
1084 child1->SetUpdateRect(gfx::Rect(1, 2)); 1084 child1->SetUpdateRect(gfx::Rect(1, 2));
1085 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 1085 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
1086 EmulateDrawingOneFrame(root); 1086 EmulateDrawingOneFrame(root);
1087 child_damage_rect = 1087 child_damage_rect =
1088 child1->render_surface()->damage_tracker()->current_damage_rect(); 1088 child1->render_surface()->damage_tracker()->current_damage_rect();
1089 root_damage_rect = 1089 root_damage_rect =
1090 root->render_surface()->damage_tracker()->current_damage_rect(); 1090 root->render_surface()->damage_tracker()->current_damage_rect();
1091 EXPECT_TRUE(child_damage_rect.IsEmpty()); 1091 EXPECT_TRUE(child_damage_rect.IsEmpty());
1092 EXPECT_TRUE(root_damage_rect.IsEmpty()); 1092 EXPECT_TRUE(root_damage_rect.IsEmpty());
1093 } 1093 }
1094 1094
1095 TEST_F(DamageTrackerTest, VerifyDamageForReplica) { 1095 TEST_F(DamageTrackerTest, VerifyDamageForReplica) {
1096 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); 1096 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces();
1097 LayerImpl* child1 = root->children()[0].get(); 1097 LayerImpl* child1 = root->children()[0];
1098 LayerImpl* grand_child1 = child1->children()[0].get(); 1098 LayerImpl* grand_child1 = child1->children()[0];
1099 LayerImpl* grand_child2 = child1->children()[1].get(); 1099 LayerImpl* grand_child2 = child1->children()[1];
1100 1100
1101 // Damage on a surface that has a reflection should cause the target surface 1101 // Damage on a surface that has a reflection should cause the target surface
1102 // to receive the surface's damage and the surface's reflected damage. 1102 // to receive the surface's damage and the surface's reflected damage.
1103 1103
1104 // For this test case, we modify grand_child2, and add grand_child3 to extend 1104 // For this test case, we modify grand_child2, and add grand_child3 to extend
1105 // the bounds of child1's surface. This way, we can test reflection changes 1105 // the bounds of child1's surface. This way, we can test reflection changes
1106 // without changing content_bounds of the surface. 1106 // without changing content_bounds of the surface.
1107 grand_child2->SetPosition(gfx::PointF(180.f, 180.f)); 1107 grand_child2->SetPosition(gfx::PointF(180.f, 180.f));
1108 { 1108 {
1109 scoped_ptr<LayerImpl> grand_child3 = 1109 scoped_ptr<LayerImpl> grand_child3 =
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
1196 root_damage_rect = 1196 root_damage_rect =
1197 root->render_surface()->damage_tracker()->current_damage_rect(); 1197 root->render_surface()->damage_tracker()->current_damage_rect();
1198 1198
1199 EXPECT_EQ(gfx::Rect(189, 205, 12, 8).ToString(), 1199 EXPECT_EQ(gfx::Rect(189, 205, 12, 8).ToString(),
1200 child_damage_rect.ToString()); 1200 child_damage_rect.ToString());
1201 EXPECT_EQ(gfx::Rect(289, 305, 12, 8).ToString(), root_damage_rect.ToString()); 1201 EXPECT_EQ(gfx::Rect(289, 305, 12, 8).ToString(), root_damage_rect.ToString());
1202 } 1202 }
1203 1203
1204 TEST_F(DamageTrackerTest, VerifyDamageForMask) { 1204 TEST_F(DamageTrackerTest, VerifyDamageForMask) {
1205 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); 1205 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface();
1206 LayerImpl* child = root->children()[0].get(); 1206 LayerImpl* child = root->children()[0];
1207 1207
1208 // In the current implementation of the damage tracker, changes to mask 1208 // In the current implementation of the damage tracker, changes to mask
1209 // layers should damage the entire corresponding surface. 1209 // layers should damage the entire corresponding surface.
1210 1210
1211 ClearDamageForAllSurfaces(root); 1211 ClearDamageForAllSurfaces(root);
1212 1212
1213 // Set up the mask layer. 1213 // Set up the mask layer.
1214 { 1214 {
1215 scoped_ptr<LayerImpl> mask_layer = 1215 scoped_ptr<LayerImpl> mask_layer =
1216 LayerImpl::Create(host_impl_.active_tree(), 3); 1216 LayerImpl::Create(host_impl_.active_tree(), 3);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1289 // Sanity check that a render surface still exists. 1289 // Sanity check that a render surface still exists.
1290 ASSERT_TRUE(child->render_surface()); 1290 ASSERT_TRUE(child->render_surface());
1291 1291
1292 child_damage_rect = 1292 child_damage_rect =
1293 child->render_surface()->damage_tracker()->current_damage_rect(); 1293 child->render_surface()->damage_tracker()->current_damage_rect();
1294 EXPECT_EQ(gfx::Rect(30, 30).ToString(), child_damage_rect.ToString()); 1294 EXPECT_EQ(gfx::Rect(30, 30).ToString(), child_damage_rect.ToString());
1295 } 1295 }
1296 1296
1297 TEST_F(DamageTrackerTest, VerifyDamageForReplicaMask) { 1297 TEST_F(DamageTrackerTest, VerifyDamageForReplicaMask) {
1298 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); 1298 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces();
1299 LayerImpl* child1 = root->children()[0].get(); 1299 LayerImpl* child1 = root->children()[0];
1300 LayerImpl* grand_child1 = child1->children()[0].get(); 1300 LayerImpl* grand_child1 = child1->children()[0];
1301 1301
1302 // Changes to a replica's mask should not damage the original surface, 1302 // Changes to a replica's mask should not damage the original surface,
1303 // because it is not masked. But it does damage the ancestor target surface. 1303 // because it is not masked. But it does damage the ancestor target surface.
1304 1304
1305 ClearDamageForAllSurfaces(root); 1305 ClearDamageForAllSurfaces(root);
1306 1306
1307 // Create a reflection about the left edge of grand_child1. 1307 // Create a reflection about the left edge of grand_child1.
1308 { 1308 {
1309 scoped_ptr<LayerImpl> grand_child1_replica = 1309 scoped_ptr<LayerImpl> grand_child1_replica =
1310 LayerImpl::Create(host_impl_.active_tree(), 6); 1310 LayerImpl::Create(host_impl_.active_tree(), 6);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1361 current_damage_rect(); 1361 current_damage_rect();
1362 child_damage_rect = 1362 child_damage_rect =
1363 child1->render_surface()->damage_tracker()->current_damage_rect(); 1363 child1->render_surface()->damage_tracker()->current_damage_rect();
1364 1364
1365 EXPECT_TRUE(grand_child_damage_rect.IsEmpty()); 1365 EXPECT_TRUE(grand_child_damage_rect.IsEmpty());
1366 EXPECT_EQ(gfx::Rect(194, 200, 6, 8).ToString(), child_damage_rect.ToString()); 1366 EXPECT_EQ(gfx::Rect(194, 200, 6, 8).ToString(), child_damage_rect.ToString());
1367 } 1367 }
1368 1368
1369 TEST_F(DamageTrackerTest, VerifyDamageForReplicaMaskWithTransformOrigin) { 1369 TEST_F(DamageTrackerTest, VerifyDamageForReplicaMaskWithTransformOrigin) {
1370 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces(); 1370 LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces();
1371 LayerImpl* child1 = root->children()[0].get(); 1371 LayerImpl* child1 = root->children()[0];
1372 LayerImpl* grand_child1 = child1->children()[0].get(); 1372 LayerImpl* grand_child1 = child1->children()[0];
1373 1373
1374 // Verify that the correct replica_origin_transform is used for the 1374 // Verify that the correct replica_origin_transform is used for the
1375 // replica_mask. 1375 // replica_mask.
1376 ClearDamageForAllSurfaces(root); 1376 ClearDamageForAllSurfaces(root);
1377 1377
1378 // This is not actually the transform origin point being tested, but by 1378 // This is not actually the transform origin point being tested, but by
1379 // convention its 1379 // convention its
1380 // expected to be the same as the replica's anchor point. 1380 // expected to be the same as the replica's anchor point.
1381 grand_child1->SetTransformOrigin( 1381 grand_child1->SetTransformOrigin(
1382 gfx::Point3F(grand_child1->bounds().width(), 0.f, 0.f)); 1382 gfx::Point3F(grand_child1->bounds().width(), 0.f, 0.f));
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1422 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 1422 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
1423 EmulateDrawingOneFrame(root); 1423 EmulateDrawingOneFrame(root);
1424 1424
1425 gfx::Rect child_damage_rect = 1425 gfx::Rect child_damage_rect =
1426 child1->render_surface()->damage_tracker()->current_damage_rect(); 1426 child1->render_surface()->damage_tracker()->current_damage_rect();
1427 EXPECT_EQ(gfx::Rect(206, 200, 6, 8).ToString(), child_damage_rect.ToString()); 1427 EXPECT_EQ(gfx::Rect(206, 200, 6, 8).ToString(), child_damage_rect.ToString());
1428 } 1428 }
1429 1429
1430 TEST_F(DamageTrackerTest, DamageWhenAddedExternally) { 1430 TEST_F(DamageTrackerTest, DamageWhenAddedExternally) {
1431 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); 1431 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface();
1432 LayerImpl* child = root->children()[0].get(); 1432 LayerImpl* child = root->children()[0];
1433 1433
1434 // Case 1: This test ensures that when the tracker is given damage, that 1434 // Case 1: This test ensures that when the tracker is given damage, that
1435 // it is included with any other partial damage. 1435 // it is included with any other partial damage.
1436 // 1436 //
1437 ClearDamageForAllSurfaces(root); 1437 ClearDamageForAllSurfaces(root);
1438 child->SetUpdateRect(gfx::Rect(10, 11, 12, 13)); 1438 child->SetUpdateRect(gfx::Rect(10, 11, 12, 13));
1439 root->render_surface()->damage_tracker()->AddDamageNextUpdate( 1439 root->render_surface()->damage_tracker()->AddDamageNextUpdate(
1440 gfx::Rect(15, 16, 32, 33)); 1440 gfx::Rect(15, 16, 32, 33));
1441 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 1441 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
1442 EmulateDrawingOneFrame(root); 1442 EmulateDrawingOneFrame(root);
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1483 1483
1484 gfx::Rect damage_rect = 1484 gfx::Rect damage_rect =
1485 target_surface->damage_tracker()->current_damage_rect(); 1485 target_surface->damage_tracker()->current_damage_rect();
1486 EXPECT_TRUE(damage_rect.IsEmpty()); 1486 EXPECT_TRUE(damage_rect.IsEmpty());
1487 } 1487 }
1488 1488
1489 TEST_F(DamageTrackerTest, VerifyDamageAccumulatesUntilReset) { 1489 TEST_F(DamageTrackerTest, VerifyDamageAccumulatesUntilReset) {
1490 // If damage is not cleared, it should accumulate. 1490 // If damage is not cleared, it should accumulate.
1491 1491
1492 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface(); 1492 LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface();
1493 LayerImpl* child = root->children()[0].get(); 1493 LayerImpl* child = root->children()[0];
1494 1494
1495 ClearDamageForAllSurfaces(root); 1495 ClearDamageForAllSurfaces(root);
1496 child->SetUpdateRect(gfx::Rect(10.f, 11.f, 1.f, 2.f)); 1496 child->SetUpdateRect(gfx::Rect(10.f, 11.f, 1.f, 2.f));
1497 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 1497 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
1498 EmulateDrawingOneFrame(root); 1498 EmulateDrawingOneFrame(root);
1499 1499
1500 // Sanity check damage after the first frame; this isnt the actual test yet. 1500 // Sanity check damage after the first frame; this isnt the actual test yet.
1501 gfx::Rect root_damage_rect = 1501 gfx::Rect root_damage_rect =
1502 root->render_surface()->damage_tracker()->current_damage_rect(); 1502 root->render_surface()->damage_tracker()->current_damage_rect();
1503 EXPECT_EQ(gfx::Rect(110, 111, 1, 2).ToString(), root_damage_rect.ToString()); 1503 EXPECT_EQ(gfx::Rect(110, 111, 1, 2).ToString(), root_damage_rect.ToString());
(...skipping 26 matching lines...) Expand all
1530 1530
1531 TEST_F(DamageTrackerTest, HugeDamageRect) { 1531 TEST_F(DamageTrackerTest, HugeDamageRect) {
1532 // This number is so large that we start losting floating point accuracy. 1532 // This number is so large that we start losting floating point accuracy.
1533 const int kBigNumber = 900000000; 1533 const int kBigNumber = 900000000;
1534 // Walk over a range to find floating point inaccuracy boundaries that move 1534 // Walk over a range to find floating point inaccuracy boundaries that move
1535 // toward the wrong direction. 1535 // toward the wrong direction.
1536 const int kRange = 5000; 1536 const int kRange = 5000;
1537 1537
1538 for (int i = 0; i < kRange; ++i) { 1538 for (int i = 0; i < kRange; ++i) {
1539 LayerImpl* root = CreateTestTreeWithOneSurface(); 1539 LayerImpl* root = CreateTestTreeWithOneSurface();
1540 LayerImpl* child = root->children()[0].get(); 1540 LayerImpl* child = root->children()[0];
1541 1541
1542 gfx::Transform transform; 1542 gfx::Transform transform;
1543 transform.Translate(-kBigNumber, -kBigNumber); 1543 transform.Translate(-kBigNumber, -kBigNumber);
1544 1544
1545 // The child layer covers (0, 0, i, i) of the viewport, 1545 // The child layer covers (0, 0, i, i) of the viewport,
1546 // but has a huge negative position. 1546 // but has a huge negative position.
1547 child->SetPosition(gfx::PointF()); 1547 child->SetPosition(gfx::PointF());
1548 child->SetBounds(gfx::Size(kBigNumber + i, kBigNumber + i)); 1548 child->SetBounds(gfx::Size(kBigNumber + i, kBigNumber + i));
1549 child->SetTransform(transform); 1549 child->SetTransform(transform);
1550 root->layer_tree_impl()->property_trees()->needs_rebuild = true; 1550 root->layer_tree_impl()->property_trees()->needs_rebuild = true;
1551 EmulateDrawingOneFrame(root); 1551 EmulateDrawingOneFrame(root);
1552 1552
1553 // The expected damage should cover the visible part of the child layer, 1553 // The expected damage should cover the visible part of the child layer,
1554 // which is (0, 0, i, i) in the viewport. 1554 // which is (0, 0, i, i) in the viewport.
1555 gfx::Rect root_damage_rect = 1555 gfx::Rect root_damage_rect =
1556 root->render_surface()->damage_tracker()->current_damage_rect(); 1556 root->render_surface()->damage_tracker()->current_damage_rect();
1557 gfx::Rect damage_we_care_about = gfx::Rect(i, i); 1557 gfx::Rect damage_we_care_about = gfx::Rect(i, i);
1558 EXPECT_LE(damage_we_care_about.right(), root_damage_rect.right()); 1558 EXPECT_LE(damage_we_care_about.right(), root_damage_rect.right());
1559 EXPECT_LE(damage_we_care_about.bottom(), root_damage_rect.bottom()); 1559 EXPECT_LE(damage_we_care_about.bottom(), root_damage_rect.bottom());
1560 } 1560 }
1561 } 1561 }
1562 1562
1563 } // namespace 1563 } // namespace
1564 } // namespace cc 1564 } // namespace cc
OLDNEW
« no previous file with comments | « cc/trees/damage_tracker.h ('k') | cc/trees/draw_property_utils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698