forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdamage_tracker_unittest.cc
2007 lines (1728 loc) · 84.5 KB
/
damage_tracker_unittest.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "cc/trees/damage_tracker.h"
#include <stddef.h>
#include "cc/base/math_util.h"
#include "cc/layers/layer_impl.h"
#include "cc/paint/filter_operation.h"
#include "cc/paint/filter_operations.h"
#include "cc/test/fake_impl_task_runner_provider.h"
#include "cc/test/fake_layer_tree_host_impl.h"
#include "cc/test/geometry_test_utils.h"
#include "cc/test/layer_test_common.h"
#include "cc/test/test_task_graph_runner.h"
#include "cc/trees/layer_tree_host_common.h"
#include "cc/trees/layer_tree_impl.h"
#include "cc/trees/single_thread_proxy.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/geometry/quad_f.h"
#include "ui/gfx/geometry/rect_conversions.h"
namespace cc {
namespace {
void ExecuteCalculateDrawProperties(LayerImpl* root,
float device_scale_factor,
RenderSurfaceList* render_surface_list) {
// Sanity check: The test itself should create the root layer's render
// surface, so that the surface (and its damage tracker) can
// persist across multiple calls to this function.
ASSERT_FALSE(render_surface_list->size());
LayerTreeHostCommon::CalcDrawPropsImplInputsForTesting inputs(
root, root->bounds(), device_scale_factor, render_surface_list);
LayerTreeHostCommon::CalculateDrawPropertiesForTesting(&inputs);
ASSERT_TRUE(GetRenderSurface(root));
}
void ClearDamageForAllSurfaces(LayerImpl* root) {
for (auto* layer : *root->layer_tree_impl()) {
if (GetRenderSurface(layer))
GetRenderSurface(layer)->damage_tracker()->DidDrawDamagedArea();
}
}
void EmulateDrawingOneFrame(LayerImpl* root, float device_scale_factor = 1.f) {
// This emulates only steps that are relevant to testing the damage tracker:
// 1. computing the render passes and layerlists
// 2. updating all damage trackers in the correct order
// 3. resetting all update_rects and property_changed flags for all layers
// and surfaces.
RenderSurfaceList render_surface_list;
ExecuteCalculateDrawProperties(root, device_scale_factor,
&render_surface_list);
DamageTracker::UpdateDamageTracking(root->layer_tree_impl(),
render_surface_list);
root->layer_tree_impl()->ResetAllChangeTracking();
}
class DamageTrackerTest : public testing::Test {
public:
DamageTrackerTest()
: host_impl_(&task_runner_provider_, &task_graph_runner_) {}
LayerImpl* CreateTestTreeWithOneSurface(int number_of_children) {
host_impl_.active_tree()->DetachLayers();
std::unique_ptr<LayerImpl> root =
LayerImpl::Create(host_impl_.active_tree(), 1);
root->SetPosition(gfx::PointF());
root->SetBounds(gfx::Size(500, 500));
root->SetDrawsContent(true);
root->test_properties()->force_render_surface = true;
for (int i = 0; i < number_of_children; ++i) {
std::unique_ptr<LayerImpl> child =
LayerImpl::Create(host_impl_.active_tree(), 2 + i);
child->SetPosition(gfx::PointF(100.f, 100.f));
child->SetBounds(gfx::Size(30, 30));
child->SetDrawsContent(true);
root->test_properties()->AddChild(std::move(child));
}
host_impl_.active_tree()->SetRootLayerForTesting(std::move(root));
host_impl_.active_tree()->SetElementIdsForTesting();
return host_impl_.active_tree()->root_layer_for_testing();
}
LayerImpl* CreateTestTreeWithTwoSurfaces() {
// This test tree has two render surfaces: one for the root, and one for
// child1. Additionally, the root has a second child layer, and child1 has
// two children of its own.
host_impl_.active_tree()->DetachLayers();
std::unique_ptr<LayerImpl> root =
LayerImpl::Create(host_impl_.active_tree(), 1);
std::unique_ptr<LayerImpl> child1 =
LayerImpl::Create(host_impl_.active_tree(), 2);
std::unique_ptr<LayerImpl> child2 =
LayerImpl::Create(host_impl_.active_tree(), 3);
std::unique_ptr<LayerImpl> grand_child1 =
LayerImpl::Create(host_impl_.active_tree(), 4);
std::unique_ptr<LayerImpl> grand_child2 =
LayerImpl::Create(host_impl_.active_tree(), 5);
root->SetPosition(gfx::PointF());
root->SetBounds(gfx::Size(500, 500));
root->SetDrawsContent(true);
root->test_properties()->force_render_surface = true;
child1->SetPosition(gfx::PointF(100.f, 100.f));
child1->SetBounds(gfx::Size(30, 30));
// With a child that draws_content, opacity will cause the layer to create
// its own RenderSurface. This layer does not draw, but is intended to
// create its own RenderSurface.
child1->SetDrawsContent(false);
child1->test_properties()->force_render_surface = true;
child2->SetPosition(gfx::PointF(11.f, 11.f));
child2->SetBounds(gfx::Size(18, 18));
child2->SetDrawsContent(true);
grand_child1->SetPosition(gfx::PointF(200.f, 200.f));
grand_child1->SetBounds(gfx::Size(6, 8));
grand_child1->SetDrawsContent(true);
grand_child2->SetPosition(gfx::PointF(190.f, 190.f));
grand_child2->SetBounds(gfx::Size(6, 8));
grand_child2->SetDrawsContent(true);
child1->test_properties()->AddChild(std::move(grand_child1));
child1->test_properties()->AddChild(std::move(grand_child2));
root->test_properties()->AddChild(std::move(child1));
root->test_properties()->AddChild(std::move(child2));
host_impl_.active_tree()->SetRootLayerForTesting(std::move(root));
host_impl_.active_tree()->SetElementIdsForTesting();
return host_impl_.active_tree()->root_layer_for_testing();
}
LayerImpl* CreateAndSetUpTestTreeWithOneSurface(int number_of_children = 1) {
LayerImpl* root = CreateTestTreeWithOneSurface(number_of_children);
// Setup includes going past the first frame which always damages
// everything, so that we can actually perform specific tests.
root->layer_tree_impl()->property_trees()->needs_rebuild = true;
EmulateDrawingOneFrame(root);
return root;
}
LayerImpl* CreateAndSetUpTestTreeWithTwoSurfaces() {
LayerImpl* root = CreateTestTreeWithTwoSurfaces();
// Setup includes going past the first frame which always damages
// everything, so that we can actually perform specific tests.
root->layer_tree_impl()->property_trees()->needs_rebuild = true;
EmulateDrawingOneFrame(root);
return root;
}
protected:
FakeImplTaskRunnerProvider task_runner_provider_;
TestTaskGraphRunner task_graph_runner_;
FakeLayerTreeHostImpl host_impl_;
};
TEST_F(DamageTrackerTest, SanityCheckTestTreeWithOneSurface) {
// Sanity check that the simple test tree will actually produce the expected
// render surfaces.
LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface();
LayerImpl* child = root->test_properties()->children[0];
EXPECT_EQ(2, GetRenderSurface(root)->num_contributors());
EXPECT_TRUE(root->contributes_to_drawn_render_surface());
EXPECT_TRUE(child->contributes_to_drawn_render_surface());
gfx::Rect root_damage_rect;
EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
&root_damage_rect));
EXPECT_EQ(gfx::Rect(500, 500).ToString(), root_damage_rect.ToString());
EXPECT_TRUE(GetRenderSurface(root)
->damage_tracker()
->has_damage_from_contributing_content());
}
TEST_F(DamageTrackerTest, SanityCheckTestTreeWithTwoSurfaces) {
// Sanity check that the complex test tree will actually produce the expected
// render surfaces.
LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces();
LayerImpl* child1 = root->test_properties()->children[0];
LayerImpl* child2 = root->test_properties()->children[1];
gfx::Rect child_damage_rect;
EXPECT_TRUE(GetRenderSurface(child1)->damage_tracker()->GetDamageRectIfValid(
&child_damage_rect));
gfx::Rect root_damage_rect;
EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
&root_damage_rect));
EXPECT_NE(GetRenderSurface(child1), GetRenderSurface(root));
EXPECT_EQ(GetRenderSurface(child2), GetRenderSurface(root));
EXPECT_EQ(3, GetRenderSurface(root)->num_contributors());
EXPECT_EQ(2, GetRenderSurface(child1)->num_contributors());
// The render surface for child1 only has a content_rect that encloses
// grand_child1 and grand_child2, because child1 does not draw content.
EXPECT_EQ(gfx::Rect(190, 190, 16, 18).ToString(),
child_damage_rect.ToString());
EXPECT_EQ(gfx::Rect(500, 500).ToString(), root_damage_rect.ToString());
EXPECT_TRUE(GetRenderSurface(root)
->damage_tracker()
->has_damage_from_contributing_content());
EXPECT_TRUE(GetRenderSurface(child1)
->damage_tracker()
->has_damage_from_contributing_content());
}
TEST_F(DamageTrackerTest, VerifyDamageForUpdateRects) {
LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface();
LayerImpl* child = root->test_properties()->children[0];
// CASE 1: Setting the update rect should cause the corresponding damage to
// the surface.
ClearDamageForAllSurfaces(root);
child->SetUpdateRect(gfx::Rect(10, 11, 12, 13));
root->layer_tree_impl()->property_trees()->needs_rebuild = true;
EmulateDrawingOneFrame(root);
// Damage position on the surface should be: position of update_rect (10, 11)
// relative to the child (100, 100).
gfx::Rect root_damage_rect;
EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
&root_damage_rect));
EXPECT_EQ(gfx::Rect(110, 111, 12, 13).ToString(),
root_damage_rect.ToString());
// CASE 2: The same update rect twice in a row still produces the same
// damage.
ClearDamageForAllSurfaces(root);
child->SetUpdateRect(gfx::Rect(10, 11, 12, 13));
root->layer_tree_impl()->property_trees()->needs_rebuild = true;
EmulateDrawingOneFrame(root);
EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
&root_damage_rect));
EXPECT_EQ(gfx::Rect(110, 111, 12, 13).ToString(),
root_damage_rect.ToString());
// CASE 3: Setting a different update rect should cause damage on the new
// update region, but no additional exposed old region.
ClearDamageForAllSurfaces(root);
child->SetUpdateRect(gfx::Rect(20, 25, 1, 2));
root->layer_tree_impl()->property_trees()->needs_rebuild = true;
EmulateDrawingOneFrame(root);
// Damage position on the surface should be: position of update_rect (20, 25)
// relative to the child (100, 100).
EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
&root_damage_rect));
EXPECT_EQ(gfx::Rect(120, 125, 1, 2).ToString(), root_damage_rect.ToString());
EXPECT_TRUE(GetRenderSurface(root)
->damage_tracker()
->has_damage_from_contributing_content());
}
TEST_F(DamageTrackerTest, VerifyDamageForLayerDamageRects) {
LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface();
LayerImpl* child = root->test_properties()->children[0];
// CASE 1: Adding the layer damage rect should cause the corresponding damage
// to the surface.
ClearDamageForAllSurfaces(root);
child->AddDamageRect(gfx::Rect(10, 11, 12, 13));
root->layer_tree_impl()->property_trees()->needs_rebuild = true;
EmulateDrawingOneFrame(root);
// Damage position on the surface should be: position of layer damage_rect
// (10, 11) relative to the child (100, 100).
gfx::Rect root_damage_rect;
EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
&root_damage_rect));
EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(110, 111, 12, 13)));
// CASE 2: The same layer damage rect twice in a row still produces the same
// damage.
ClearDamageForAllSurfaces(root);
child->AddDamageRect(gfx::Rect(10, 11, 12, 13));
root->layer_tree_impl()->property_trees()->needs_rebuild = true;
EmulateDrawingOneFrame(root);
EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
&root_damage_rect));
EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(110, 111, 12, 13)));
// CASE 3: Adding a different layer damage rect should cause damage on the
// new damaged region, but no additional exposed old region.
ClearDamageForAllSurfaces(root);
child->AddDamageRect(gfx::Rect(20, 25, 1, 2));
root->layer_tree_impl()->property_trees()->needs_rebuild = true;
EmulateDrawingOneFrame(root);
// Damage position on the surface should be: position of layer damage_rect
// (20, 25) relative to the child (100, 100).
EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
&root_damage_rect));
EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(120, 125, 1, 2)));
// CASE 4: Adding multiple layer damage rects should cause a unified
// damage on root damage rect.
ClearDamageForAllSurfaces(root);
child->AddDamageRect(gfx::Rect(20, 25, 1, 2));
child->AddDamageRect(gfx::Rect(10, 15, 3, 4));
root->layer_tree_impl()->property_trees()->needs_rebuild = true;
EmulateDrawingOneFrame(root);
// Damage position on the surface should be: position of layer damage_rect
// (20, 25) relative to the child (100, 100).
EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
&root_damage_rect));
EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(120, 125, 1, 2)));
EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(110, 115, 3, 4)));
EXPECT_TRUE(GetRenderSurface(root)
->damage_tracker()
->has_damage_from_contributing_content());
}
TEST_F(DamageTrackerTest, VerifyDamageForLayerUpdateAndDamageRects) {
LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface();
LayerImpl* child = root->test_properties()->children[0];
// CASE 1: Adding the layer damage rect and update rect should cause the
// corresponding damage to the surface.
ClearDamageForAllSurfaces(root);
child->AddDamageRect(gfx::Rect(5, 6, 12, 13));
child->SetUpdateRect(gfx::Rect(15, 16, 14, 10));
root->layer_tree_impl()->property_trees()->needs_rebuild = true;
EmulateDrawingOneFrame(root);
// Damage position on the surface should be: position of unified layer
// damage_rect and update rect (5, 6)
// relative to the child (100, 100).
gfx::Rect root_damage_rect;
EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
&root_damage_rect));
EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(105, 106, 24, 20)));
// CASE 2: The same layer damage rect and update rect twice in a row still
// produces the same damage.
ClearDamageForAllSurfaces(root);
child->AddDamageRect(gfx::Rect(10, 11, 12, 13));
child->SetUpdateRect(gfx::Rect(10, 11, 14, 15));
root->layer_tree_impl()->property_trees()->needs_rebuild = true;
EmulateDrawingOneFrame(root);
EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
&root_damage_rect));
EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(110, 111, 14, 15)));
// CASE 3: Adding a different layer damage rect and update rect should cause
// damage on the new damaged region, but no additional exposed old region.
ClearDamageForAllSurfaces(root);
child->AddDamageRect(gfx::Rect(20, 25, 2, 3));
child->SetUpdateRect(gfx::Rect(5, 10, 7, 8));
root->layer_tree_impl()->property_trees()->needs_rebuild = true;
EmulateDrawingOneFrame(root);
// Damage position on the surface should be: position of unified layer damage
// rect and update rect (5, 10) relative to the child (100, 100).
EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
&root_damage_rect));
EXPECT_EQ(true, root_damage_rect.Contains(gfx::Rect(105, 110, 17, 18)));
EXPECT_TRUE(GetRenderSurface(root)
->damage_tracker()
->has_damage_from_contributing_content());
}
TEST_F(DamageTrackerTest, VerifyDamageForPropertyChanges) {
LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface();
LayerImpl* child = root->test_properties()->children[0];
// CASE 1: The layer's property changed flag takes priority over update rect.
//
child->test_properties()->force_render_surface = true;
root->layer_tree_impl()->property_trees()->needs_rebuild = true;
EmulateDrawingOneFrame(root);
ClearDamageForAllSurfaces(root);
child->SetUpdateRect(gfx::Rect(10, 11, 12, 13));
root->layer_tree_impl()->SetOpacityMutated(child->element_id(), 0.5f);
EmulateDrawingOneFrame(root);
ASSERT_EQ(2, GetRenderSurface(root)->num_contributors());
// Damage should be the entire child layer in target_surface space.
gfx::Rect expected_rect = gfx::Rect(100, 100, 30, 30);
gfx::Rect root_damage_rect;
EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
&root_damage_rect));
EXPECT_EQ(expected_rect.ToString(), root_damage_rect.ToString());
EXPECT_TRUE(GetRenderSurface(root)
->damage_tracker()
->has_damage_from_contributing_content());
EXPECT_TRUE(GetRenderSurface(child)
->damage_tracker()
->has_damage_from_contributing_content());
// CASE 2: If a layer moves due to property change, it damages both the new
// location and the old (exposed) location. The old location is the
// entire old layer, not just the update_rect.
// Cycle one frame of no change, just to sanity check that the next rect is
// not because of the old damage state.
ClearDamageForAllSurfaces(root);
root->layer_tree_impl()->property_trees()->needs_rebuild = true;
EmulateDrawingOneFrame(root);
EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
&root_damage_rect));
EXPECT_TRUE(root_damage_rect.IsEmpty());
// Then, test the actual layer movement.
ClearDamageForAllSurfaces(root);
gfx::Transform translation;
translation.Translate(100.f, 130.f);
root->layer_tree_impl()->SetTransformMutated(child->element_id(),
translation);
EmulateDrawingOneFrame(root);
// Expect damage to be the combination of the previous one and the new one.
expected_rect.Union(gfx::Rect(200, 230, 30, 30));
EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
&root_damage_rect));
EXPECT_FLOAT_RECT_EQ(expected_rect, root_damage_rect);
EXPECT_TRUE(GetRenderSurface(root)
->damage_tracker()
->has_damage_from_contributing_content());
// Transform from browser animation should not be considered as damage from
// contributing layer since it is applied to the whole layer which has a
// render surface.
EXPECT_FALSE(GetRenderSurface(child)
->damage_tracker()
->has_damage_from_contributing_content());
}
TEST_F(DamageTrackerTest,
VerifyDamageForPropertyChangesFromContributingContents) {
LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces();
LayerImpl* child1 = root->test_properties()->children[0];
LayerImpl* child2 = root->test_properties()->children[1];
LayerImpl* grandchild1 = child1->test_properties()->children[0];
// CASE 1: The child1's opacity changed.
ClearDamageForAllSurfaces(root);
root->layer_tree_impl()->SetOpacityMutated(child1->element_id(), 0.5f);
EmulateDrawingOneFrame(root);
EXPECT_TRUE(GetRenderSurface(root)
->damage_tracker()
->has_damage_from_contributing_content());
EXPECT_FALSE(GetRenderSurface(child1)
->damage_tracker()
->has_damage_from_contributing_content());
// CASE 2: The layer2's opacity changed.
child2->test_properties()->force_render_surface = true;
root->layer_tree_impl()->property_trees()->needs_rebuild = true;
EmulateDrawingOneFrame(root);
ClearDamageForAllSurfaces(root);
root->layer_tree_impl()->SetOpacityMutated(child2->element_id(), 0.5f);
EmulateDrawingOneFrame(root);
EXPECT_TRUE(GetRenderSurface(root)
->damage_tracker()
->has_damage_from_contributing_content());
EXPECT_FALSE(GetRenderSurface(child1)
->damage_tracker()
->has_damage_from_contributing_content());
// CASE 3: The grandchild1's opacity changed.
grandchild1->test_properties()->force_render_surface = true;
root->layer_tree_impl()->property_trees()->needs_rebuild = true;
EmulateDrawingOneFrame(root);
ClearDamageForAllSurfaces(root);
root->layer_tree_impl()->SetOpacityMutated(grandchild1->element_id(), 0.5f);
EmulateDrawingOneFrame(root);
EXPECT_TRUE(GetRenderSurface(root)
->damage_tracker()
->has_damage_from_contributing_content());
EXPECT_TRUE(GetRenderSurface(child1)
->damage_tracker()
->has_damage_from_contributing_content());
}
TEST_F(DamageTrackerTest,
VerifyDamageForUpdateAndDamageRectsFromContributingContents) {
LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces();
LayerImpl* child1 = root->test_properties()->children[0];
LayerImpl* child2 = root->test_properties()->children[1];
LayerImpl* grandchild1 = child1->test_properties()->children[0];
// CASE 1: Adding the layer1's damage rect and update rect should cause the
// corresponding damage to the surface.
child1->SetDrawsContent(true);
ClearDamageForAllSurfaces(root);
child1->AddDamageRect(gfx::Rect(105, 106, 12, 15));
child1->SetUpdateRect(gfx::Rect(115, 116, 12, 15));
root->layer_tree_impl()->property_trees()->needs_rebuild = true;
EmulateDrawingOneFrame(root);
EXPECT_TRUE(GetRenderSurface(root)
->damage_tracker()
->has_damage_from_contributing_content());
EXPECT_TRUE(GetRenderSurface(child1)
->damage_tracker()
->has_damage_from_contributing_content());
// CASE 2: Adding the layer2's damage rect and update rect should cause the
// corresponding damage to the surface.
ClearDamageForAllSurfaces(root);
child2->AddDamageRect(gfx::Rect(11, 11, 12, 15));
child2->SetUpdateRect(gfx::Rect(12, 12, 12, 15));
EmulateDrawingOneFrame(root);
EXPECT_TRUE(GetRenderSurface(root)
->damage_tracker()
->has_damage_from_contributing_content());
EXPECT_FALSE(GetRenderSurface(child1)
->damage_tracker()
->has_damage_from_contributing_content());
// CASE 3: Adding the grandchild1's damage rect and update rect should cause
// the corresponding damage to the surface.
ClearDamageForAllSurfaces(root);
grandchild1->AddDamageRect(gfx::Rect(1, 0, 2, 5));
grandchild1->SetUpdateRect(gfx::Rect(2, 1, 2, 5));
EmulateDrawingOneFrame(root);
EXPECT_TRUE(GetRenderSurface(root)
->damage_tracker()
->has_damage_from_contributing_content());
EXPECT_TRUE(GetRenderSurface(child1)
->damage_tracker()
->has_damage_from_contributing_content());
}
TEST_F(DamageTrackerTest, VerifyDamageWhenSurfaceRemoved) {
LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces();
LayerImpl* surface = root->test_properties()->children[0];
LayerImpl* child = surface->test_properties()->children[0];
child->SetDrawsContent(true);
EmulateDrawingOneFrame(root);
ClearDamageForAllSurfaces(root);
surface->test_properties()->force_render_surface = false;
child->SetDrawsContent(false);
root->layer_tree_impl()->property_trees()->needs_rebuild = true;
EmulateDrawingOneFrame(root);
gfx::Rect root_damage_rect;
EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
&root_damage_rect));
EXPECT_EQ(gfx::Rect(290, 290, 16, 18).ToString(),
root_damage_rect.ToString());
EXPECT_TRUE(GetRenderSurface(root)
->damage_tracker()
->has_damage_from_contributing_content());
}
TEST_F(DamageTrackerTest, VerifyDamageForTransformedLayer) {
// If a layer is transformed, the damage rect should still enclose the entire
// transformed layer.
LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface();
LayerImpl* child = root->test_properties()->children[0];
child->test_properties()->force_render_surface = true;
gfx::Transform rotation;
rotation.Rotate(45.0);
ClearDamageForAllSurfaces(root);
child->test_properties()->transform_origin = gfx::Point3F(
child->bounds().width() * 0.5f, child->bounds().height() * 0.5f, 0.f);
child->SetPosition(gfx::PointF(85.f, 85.f));
child->NoteLayerPropertyChanged();
root->layer_tree_impl()->property_trees()->needs_rebuild = true;
EmulateDrawingOneFrame(root);
// Sanity check that the layer actually moved to (85, 85), damaging its old
// location and new location.
gfx::Rect root_damage_rect;
EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
&root_damage_rect));
EXPECT_EQ(gfx::Rect(85, 85, 45, 45).ToString(), root_damage_rect.ToString());
EXPECT_TRUE(GetRenderSurface(root)
->damage_tracker()
->has_damage_from_contributing_content());
// Layer's layer_property_changed_not_from_property_trees_ should be
// considered as damage to render surface.
EXPECT_TRUE(GetRenderSurface(child)
->damage_tracker()
->has_damage_from_contributing_content());
// With the anchor on the layer's center, now we can test the rotation more
// intuitively, since it applies about the layer's anchor.
ClearDamageForAllSurfaces(root);
root->layer_tree_impl()->SetTransformMutated(child->element_id(), rotation);
EmulateDrawingOneFrame(root);
// Since the child layer is square, rotation by 45 degrees about the center
// should increase the size of the expected rect by sqrt(2), centered around
// (100, 100). The old exposed region should be fully contained in the new
// region.
float expected_width = 30.f * sqrt(2.f);
float expected_position = 100.f - 0.5f * expected_width;
gfx::Rect expected_rect = gfx::ToEnclosingRect(gfx::RectF(
expected_position, expected_position, expected_width, expected_width));
EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
&root_damage_rect));
EXPECT_EQ(expected_rect.ToString(), root_damage_rect.ToString());
EXPECT_TRUE(GetRenderSurface(root)
->damage_tracker()
->has_damage_from_contributing_content());
// Transform from browser animation should not be considered as damage from
// contributing layer since it is applied to the whole layer which has a
// render surface.
EXPECT_FALSE(GetRenderSurface(child)
->damage_tracker()
->has_damage_from_contributing_content());
}
TEST_F(DamageTrackerTest, VerifyDamageForPerspectiveClippedLayer) {
// If a layer has a perspective transform that causes w < 0, then not
// clipping the layer can cause an invalid damage rect. This test checks that
// the w < 0 case is tracked properly.
//
// The transform is constructed so that if w < 0 clipping is not performed,
// the incorrect rect will be very small, specifically: position (500.972504,
// 498.544617) and size 0.056610 x 2.910767. Instead, the correctly
// transformed rect should actually be very huge (i.e. in theory, -infinity
// on the left), and positioned so that the right-most bound rect will be
// approximately 501 units in root surface space.
//
LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface();
LayerImpl* child = root->test_properties()->children[0];
gfx::Transform transform;
transform.Translate3d(550.0, 500.0, 0.0);
transform.ApplyPerspectiveDepth(1.0);
transform.RotateAboutYAxis(45.0);
transform.Translate3d(-50.0, -50.0, 0.0);
// Set up the child
child->SetPosition(gfx::PointF(0.f, 0.f));
child->SetBounds(gfx::Size(100, 100));
child->test_properties()->transform = transform;
root->layer_tree_impl()->property_trees()->needs_rebuild = true;
EmulateDrawingOneFrame(root);
// Sanity check that the child layer's bounds would actually get clipped by
// w < 0, otherwise this test is not actually testing the intended scenario.
gfx::RectF test_rect(child->position(), gfx::SizeF(child->bounds()));
bool clipped = false;
MathUtil::MapQuad(transform, gfx::QuadF(test_rect), &clipped);
EXPECT_TRUE(clipped);
// Damage the child without moving it.
child->test_properties()->force_render_surface = true;
root->layer_tree_impl()->property_trees()->needs_rebuild = true;
EmulateDrawingOneFrame(root);
ClearDamageForAllSurfaces(root);
root->layer_tree_impl()->SetOpacityMutated(child->element_id(), 0.5f);
EmulateDrawingOneFrame(root);
// The expected damage should cover the entire root surface (500x500), but we
// don't care whether the damage rect was clamped or is larger than the
// surface for this test.
gfx::Rect root_damage_rect;
EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
&root_damage_rect));
gfx::Rect damage_we_care_about = gfx::Rect(gfx::Size(500, 500));
EXPECT_TRUE(root_damage_rect.Contains(damage_we_care_about));
EXPECT_TRUE(GetRenderSurface(root)
->damage_tracker()
->has_damage_from_contributing_content());
EXPECT_FALSE(GetRenderSurface(child)
->damage_tracker()
->has_damage_from_contributing_content());
}
TEST_F(DamageTrackerTest, VerifyDamageForBlurredSurface) {
LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces();
LayerImpl* surface = root->test_properties()->children[0];
LayerImpl* child = surface->test_properties()->children[0];
FilterOperations filters;
filters.Append(FilterOperation::CreateBlurFilter(5.f));
// Setting the filter should not damage the conrresponding render surface.
ClearDamageForAllSurfaces(root);
surface->test_properties()->filters = filters;
root->layer_tree_impl()->property_trees()->needs_rebuild = true;
EmulateDrawingOneFrame(root);
EXPECT_FALSE(GetRenderSurface(root)
->damage_tracker()
->has_damage_from_contributing_content());
EXPECT_FALSE(GetRenderSurface(surface)
->damage_tracker()
->has_damage_from_contributing_content());
// Setting the update rect should cause the corresponding damage to the
// surface, blurred based on the size of the blur filter.
ClearDamageForAllSurfaces(root);
child->SetUpdateRect(gfx::Rect(1, 2, 3, 4));
root->layer_tree_impl()->property_trees()->needs_rebuild = true;
EmulateDrawingOneFrame(root);
// Damage position on the surface should be: position of update_rect (1, 2)
// relative to the child (300, 300), but expanded by the blur outsets
// (15, since the blur radius is 5).
gfx::Rect root_damage_rect;
EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
&root_damage_rect));
EXPECT_EQ(gfx::Rect(286, 287, 33, 34), root_damage_rect);
EXPECT_TRUE(GetRenderSurface(root)
->damage_tracker()
->has_damage_from_contributing_content());
EXPECT_TRUE(GetRenderSurface(surface)
->damage_tracker()
->has_damage_from_contributing_content());
}
TEST_F(DamageTrackerTest, VerifyDamageForImageFilter) {
LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface();
LayerImpl* child = root->test_properties()->children[0];
gfx::Rect root_damage_rect, child_damage_rect;
// Allow us to set damage on child too.
child->SetDrawsContent(true);
FilterOperations filters;
filters.Append(
FilterOperation::CreateReferenceFilter(sk_make_sp<BlurPaintFilter>(
2, 2, BlurPaintFilter::TileMode::kClampToBlack_TileMode, nullptr)));
// Setting the filter will damage the whole surface.
child->test_properties()->force_render_surface = true;
root->layer_tree_impl()->property_trees()->needs_rebuild = true;
EmulateDrawingOneFrame(root);
ClearDamageForAllSurfaces(root);
child->layer_tree_impl()->SetFilterMutated(child->element_id(), filters);
EmulateDrawingOneFrame(root);
EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
&root_damage_rect));
EXPECT_TRUE(GetRenderSurface(child)->damage_tracker()->GetDamageRectIfValid(
&child_damage_rect));
// gfx::Rect(100, 100, 30, 30), expanded by 6px for the 2px blur filter.
EXPECT_EQ(gfx::Rect(94, 94, 42, 42), root_damage_rect);
// gfx::Rect(0, 0, 30, 30), expanded by 6px for the 2px blur filter.
EXPECT_EQ(gfx::Rect(-6, -6, 42, 42), child_damage_rect);
EXPECT_TRUE(GetRenderSurface(root)
->damage_tracker()
->has_damage_from_contributing_content());
EXPECT_FALSE(GetRenderSurface(child)
->damage_tracker()
->has_damage_from_contributing_content());
// CASE 1: Setting the update rect should damage the whole surface (for now)
ClearDamageForAllSurfaces(root);
child->SetUpdateRect(gfx::Rect(1, 1));
EmulateDrawingOneFrame(root);
EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
&root_damage_rect));
EXPECT_TRUE(GetRenderSurface(child)->damage_tracker()->GetDamageRectIfValid(
&child_damage_rect));
// gfx::Rect(100, 100, 1, 1), expanded by 6px for the 2px blur filter.
EXPECT_EQ(gfx::Rect(94, 94, 13, 13), root_damage_rect);
// gfx::Rect(0, 0, 1, 1), expanded by 6px for the 2px blur filter.
EXPECT_EQ(gfx::Rect(-6, -6, 13, 13), child_damage_rect);
EXPECT_TRUE(GetRenderSurface(root)
->damage_tracker()
->has_damage_from_contributing_content());
EXPECT_TRUE(GetRenderSurface(child)
->damage_tracker()
->has_damage_from_contributing_content());
// CASE 2: No changes, so should not damage the surface.
ClearDamageForAllSurfaces(root);
EmulateDrawingOneFrame(root);
EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
&root_damage_rect));
EXPECT_TRUE(GetRenderSurface(child)->damage_tracker()->GetDamageRectIfValid(
&child_damage_rect));
// Should not be expanded by the blur filter.
EXPECT_EQ(gfx::Rect(), root_damage_rect);
EXPECT_EQ(gfx::Rect(), child_damage_rect);
EXPECT_FALSE(GetRenderSurface(root)
->damage_tracker()
->has_damage_from_contributing_content());
EXPECT_FALSE(GetRenderSurface(child)
->damage_tracker()
->has_damage_from_contributing_content());
}
TEST_F(DamageTrackerTest, VerifyDamageForTransformedImageFilter) {
LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface();
LayerImpl* child = root->test_properties()->children[0];
gfx::Rect root_damage_rect, child_damage_rect;
// Allow us to set damage on child too.
child->SetDrawsContent(true);
FilterOperations filters;
filters.Append(
FilterOperation::CreateReferenceFilter(sk_make_sp<BlurPaintFilter>(
2, 2, BlurPaintFilter::TileMode::kClampToBlack_TileMode, nullptr)));
// Setting the filter will damage the whole surface.
gfx::Transform transform;
transform.RotateAboutYAxis(60);
ClearDamageForAllSurfaces(root);
child->test_properties()->force_render_surface = true;
child->test_properties()->transform = transform;
root->layer_tree_impl()->property_trees()->needs_rebuild = true;
EmulateDrawingOneFrame(root);
child->layer_tree_impl()->SetFilterMutated(child->element_id(), filters);
EmulateDrawingOneFrame(root);
EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
&root_damage_rect));
EXPECT_TRUE(GetRenderSurface(child)->damage_tracker()->GetDamageRectIfValid(
&child_damage_rect));
// Blur outset is 6px for a 2px blur.
int blur_outset = 6;
int rotated_outset_left = blur_outset / 2;
int expected_rotated_width = (30 + 2 * blur_outset) / 2;
gfx::Rect expected_root_damage(100 - rotated_outset_left, 100 - blur_outset,
expected_rotated_width, 30 + 2 * blur_outset);
expected_root_damage.Union(gfx::Rect(100, 100, 30, 30));
EXPECT_EQ(expected_root_damage, root_damage_rect);
EXPECT_EQ(gfx::Rect(-blur_outset, -blur_outset, 30 + 2 * blur_outset,
30 + 2 * blur_outset),
child_damage_rect);
// Setting the update rect should damage the whole surface (for now)
ClearDamageForAllSurfaces(root);
child->SetUpdateRect(gfx::Rect(30, 30));
EmulateDrawingOneFrame(root);
EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
&root_damage_rect));
EXPECT_TRUE(GetRenderSurface(child)->damage_tracker()->GetDamageRectIfValid(
&child_damage_rect));
int expect_width = 30 + 2 * blur_outset;
int expect_height = 30 + 2 * blur_outset;
EXPECT_EQ(gfx::Rect(100 - blur_outset / 2, 100 - blur_outset,
expect_width / 2, expect_height),
root_damage_rect);
EXPECT_EQ(gfx::Rect(-blur_outset, -blur_outset, expect_width, expect_height),
child_damage_rect);
}
TEST_F(DamageTrackerTest, VerifyDamageForHighDPIImageFilter) {
LayerImpl* root = CreateAndSetUpTestTreeWithOneSurface();
LayerImpl* child = root->test_properties()->children[0];
gfx::Rect root_damage_rect, child_damage_rect;
// Allow us to set damage on child too.
child->SetDrawsContent(true);
FilterOperations filters;
filters.Append(FilterOperation::CreateBlurFilter(3.f));
// Setting the filter will damage the whole surface.
ClearDamageForAllSurfaces(root);
child->test_properties()->force_render_surface = true;
root->layer_tree_impl()->property_trees()->needs_rebuild = true;
int device_scale_factor = 2;
EmulateDrawingOneFrame(root, device_scale_factor);
child->layer_tree_impl()->SetFilterMutated(child->element_id(), filters);
EmulateDrawingOneFrame(root, device_scale_factor);
EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
&root_damage_rect));
EXPECT_TRUE(GetRenderSurface(child)->damage_tracker()->GetDamageRectIfValid(
&child_damage_rect));
// Blur outset is 9px for a 3px blur, scaled up by DSF.
int blur_outset = 9 * device_scale_factor;
gfx::Rect original_rect(100, 100, 100, 100);
gfx::Rect expected_child_damage_rect(60, 60);
expected_child_damage_rect.Inset(-blur_outset, -blur_outset);
gfx::Rect expected_root_damage_rect(child_damage_rect);
expected_root_damage_rect.Offset(200, 200);
gfx::Rect expected_total_damage_rect = expected_root_damage_rect;
expected_total_damage_rect.Union(original_rect);
EXPECT_EQ(expected_total_damage_rect, root_damage_rect);
EXPECT_EQ(expected_child_damage_rect, child_damage_rect);
// Setting the update rect should damage only the affected area (original,
// outset by 3 * blur sigma * DSF).
ClearDamageForAllSurfaces(root);
child->SetUpdateRect(gfx::Rect(30, 30));
EmulateDrawingOneFrame(root, device_scale_factor);
EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
&root_damage_rect));
EXPECT_TRUE(GetRenderSurface(child)->damage_tracker()->GetDamageRectIfValid(
&child_damage_rect));
EXPECT_EQ(expected_root_damage_rect, root_damage_rect);
EXPECT_EQ(expected_child_damage_rect, child_damage_rect);
}
TEST_F(DamageTrackerTest, VerifyDamageForBackgroundBlurredChild) {
LayerImpl* root = CreateAndSetUpTestTreeWithTwoSurfaces();
LayerImpl* child1 = root->test_properties()->children[0];
LayerImpl* child2 = root->test_properties()->children[1];
// Allow us to set damage on child1 too.
child1->SetDrawsContent(true);
FilterOperations filters;
filters.Append(FilterOperation::CreateBlurFilter(2.f));
// Setting the filter will damage the whole surface.
ClearDamageForAllSurfaces(root);
child1->test_properties()->background_filters = filters;
child1->NoteLayerPropertyChanged();
root->layer_tree_impl()->property_trees()->needs_rebuild = true;
EmulateDrawingOneFrame(root);
// CASE 1: Setting the update rect should cause the corresponding damage to
// the surface, blurred based on the size of the child's background
// blur filter. Note that child1's render surface has a size of
// 206x208 due to contributions from grand_child1 and grand_child2.
ClearDamageForAllSurfaces(root);
root->SetUpdateRect(gfx::Rect(297, 297, 2, 2));
root->layer_tree_impl()->property_trees()->needs_rebuild = true;
EmulateDrawingOneFrame(root);
gfx::Rect root_damage_rect;
EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
&root_damage_rect));
// Damage position on the surface should be a composition of the damage on
// the root and on child2. Damage on the root should be: position of
// update_rect (297, 297), but expanded by the blur outsets.
gfx::Rect expected_damage_rect = gfx::Rect(297, 297, 2, 2);
// 6px spread for a 2px blur.
expected_damage_rect.Inset(-6, -6, -6, -6);
EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString());
// CASE 2: Setting the update rect should cause the corresponding damage to
// the surface, blurred based on the size of the child's background
// blur filter. Since the damage extends to the right/bottom outside
// of the blurred layer, only the left/top should end up expanded.
ClearDamageForAllSurfaces(root);
root->SetUpdateRect(gfx::Rect(297, 297, 30, 30));
root->layer_tree_impl()->property_trees()->needs_rebuild = true;
EmulateDrawingOneFrame(root);
EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
&root_damage_rect));
// Damage position on the surface should be a composition of the damage on
// the root and on child2. Damage on the root should be: position of
// update_rect (297, 297), but expanded on the left/top by the blur outsets.
expected_damage_rect = gfx::Rect(297, 297, 30, 30);
// 6px spread for a 2px blur.
expected_damage_rect.Inset(-6, -6, 0, 0);
EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString());
// CASE 3: Setting this update rect outside the blurred content_bounds of the
// blurred child1 will not cause it to be expanded.
ClearDamageForAllSurfaces(root);
root->SetUpdateRect(gfx::Rect(30, 30, 2, 2));
root->layer_tree_impl()->property_trees()->needs_rebuild = true;
EmulateDrawingOneFrame(root);
EXPECT_TRUE(GetRenderSurface(root)->damage_tracker()->GetDamageRectIfValid(
&root_damage_rect));
// Damage on the root should be: position of update_rect (30, 30), not
// expanded.
expected_damage_rect = gfx::Rect(30, 30, 2, 2);
EXPECT_EQ(expected_damage_rect.ToString(), root_damage_rect.ToString());