forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsurface_synchronization_unittest.cc
1351 lines (1132 loc) · 59 KB
/
surface_synchronization_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 2017 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 "base/containers/flat_set.h"
#include "cc/surfaces/compositor_frame_sink_support.h"
#include "cc/surfaces/surface_id.h"
#include "cc/surfaces/surface_manager.h"
#include "cc/test/begin_frame_args_test.h"
#include "cc/test/compositor_frame_helpers.h"
#include "cc/test/fake_external_begin_frame_source.h"
#include "cc/test/fake_surface_observer.h"
#include "cc/test/mock_compositor_frame_sink_support_client.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
using testing::_;
using testing::Eq;
using testing::IsEmpty;
using testing::UnorderedElementsAre;
namespace cc {
namespace test {
namespace {
constexpr bool kIsRoot = true;
constexpr bool kIsChildRoot = false;
constexpr bool kHandlesFrameSinkIdInvalidation = true;
constexpr bool kNeedsSyncPoints = true;
constexpr FrameSinkId kDisplayFrameSink(2, 0);
constexpr FrameSinkId kParentFrameSink(3, 0);
constexpr FrameSinkId kChildFrameSink1(65563, 0);
constexpr FrameSinkId kChildFrameSink2(65564, 0);
constexpr FrameSinkId kArbitraryFrameSink(1337, 7331);
std::vector<SurfaceId> empty_surface_ids() {
return std::vector<SurfaceId>();
}
SurfaceId MakeSurfaceId(const FrameSinkId& frame_sink_id, uint32_t local_id) {
return SurfaceId(
frame_sink_id,
LocalSurfaceId(local_id, base::UnguessableToken::Deserialize(0, 1u)));
}
} // namespace
class SurfaceSynchronizationTest : public testing::Test {
public:
SurfaceSynchronizationTest()
: surface_manager_(SurfaceManager::LifetimeType::REFERENCES),
surface_observer_(false) {}
~SurfaceSynchronizationTest() override {}
CompositorFrameSinkSupport& display_support() { return *supports_[0]; }
Surface* display_surface() {
return display_support().current_surface_for_testing();
}
CompositorFrameSinkSupport& parent_support() { return *supports_[1]; }
Surface* parent_surface() {
return parent_support().current_surface_for_testing();
}
CompositorFrameSinkSupport& child_support1() { return *supports_[2]; }
Surface* child_surface1() {
return child_support1().current_surface_for_testing();
}
CompositorFrameSinkSupport& child_support2() { return *supports_[3]; }
Surface* child_surface2() {
return child_support2().current_surface_for_testing();
}
CompositorFrameSinkSupport& support(int index) { return *supports_[index]; }
Surface* surface(int index) {
return support(index).current_surface_for_testing();
}
SurfaceManager& surface_manager() { return surface_manager_; }
// Returns all the references where |surface_id| is the parent.
const base::flat_set<SurfaceId>& GetChildReferences(
const SurfaceId& surface_id) {
return surface_manager().GetSurfacesReferencedByParent(surface_id);
}
// Returns true if there is a temporary reference for |surface_id|.
bool HasTemporaryReference(const SurfaceId& surface_id) {
return surface_manager().HasTemporaryReference(surface_id);
}
SurfaceDependencyTracker& dependency_tracker() {
return *surface_manager_.dependency_tracker();
}
FakeExternalBeginFrameSource* begin_frame_source() {
return begin_frame_source_.get();
}
FakeSurfaceObserver& surface_observer() { return surface_observer_; }
// testing::Test:
void SetUp() override {
testing::Test::SetUp();
begin_frame_source_ =
base::MakeUnique<FakeExternalBeginFrameSource>(0.f, false);
dependency_tracker_ = base::MakeUnique<SurfaceDependencyTracker>(
&surface_manager_, begin_frame_source_.get());
surface_manager_.SetDependencyTracker(dependency_tracker_.get());
surface_manager_.AddObserver(&surface_observer_);
supports_.push_back(CompositorFrameSinkSupport::Create(
&support_client_, &surface_manager_, kDisplayFrameSink, kIsRoot,
kHandlesFrameSinkIdInvalidation, kNeedsSyncPoints));
supports_.push_back(CompositorFrameSinkSupport::Create(
&support_client_, &surface_manager_, kParentFrameSink, kIsChildRoot,
kHandlesFrameSinkIdInvalidation, kNeedsSyncPoints));
supports_.push_back(CompositorFrameSinkSupport::Create(
&support_client_, &surface_manager_, kChildFrameSink1, kIsChildRoot,
kHandlesFrameSinkIdInvalidation, kNeedsSyncPoints));
supports_.push_back(CompositorFrameSinkSupport::Create(
&support_client_, &surface_manager_, kChildFrameSink2, kIsChildRoot,
kHandlesFrameSinkIdInvalidation, kNeedsSyncPoints));
// Normally, the BeginFrameSource would be registered by the Display. We
// register it here so that BeginFrames are received by the display support,
// for use in the PassesOnBeginFrameAcks test. Other supports do not receive
// BeginFrames, since the frame sink hierarchy is not set up in this test.
surface_manager_.RegisterBeginFrameSource(begin_frame_source_.get(),
kDisplayFrameSink);
}
void TearDown() override {
surface_manager_.RemoveObserver(&surface_observer_);
surface_manager_.SetDependencyTracker(nullptr);
surface_manager_.UnregisterBeginFrameSource(begin_frame_source_.get());
dependency_tracker_.reset();
// SurfaceDependencyTracker depends on this BeginFrameSource and so it must
// be destroyed AFTER the dependency tracker is destroyed.
begin_frame_source_.reset();
supports_.clear();
surface_observer_.Reset();
}
protected:
testing::NiceMock<MockCompositorFrameSinkSupportClient> support_client_;
private:
SurfaceManager surface_manager_;
FakeSurfaceObserver surface_observer_;
std::unique_ptr<FakeExternalBeginFrameSource> begin_frame_source_;
std::unique_ptr<SurfaceDependencyTracker> dependency_tracker_;
std::vector<std::unique_ptr<CompositorFrameSinkSupport>> supports_;
DISALLOW_COPY_AND_ASSIGN(SurfaceSynchronizationTest);
};
// The display root surface should have a surface reference from the top-level
// root added/removed when a CompositorFrame is submitted with a new SurfaceId.
TEST_F(SurfaceSynchronizationTest, RootSurfaceReceivesReferences) {
const SurfaceId display_id_first = MakeSurfaceId(kDisplayFrameSink, 1);
const SurfaceId display_id_second = MakeSurfaceId(kDisplayFrameSink, 2);
// Submit a CompositorFrame for the first display root surface.
display_support().SubmitCompositorFrame(display_id_first.local_surface_id(),
MakeCompositorFrame());
// A surface reference from the top-level root is added and there shouldn't be
// a temporary reference.
EXPECT_FALSE(HasTemporaryReference(display_id_first));
EXPECT_THAT(GetChildReferences(surface_manager().GetRootSurfaceId()),
UnorderedElementsAre(display_id_first));
// Submit a CompositorFrame for the second display root surface.
display_support().SubmitCompositorFrame(display_id_second.local_surface_id(),
MakeCompositorFrame());
// A surface reference from the top-level root to |display_id_second| should
// be added and the reference to |display_root_first| removed.
EXPECT_FALSE(HasTemporaryReference(display_id_second));
EXPECT_THAT(GetChildReferences(surface_manager().GetRootSurfaceId()),
UnorderedElementsAre(display_id_second));
// Surface |display_id_first| is unreachable and should get deleted.
EXPECT_EQ(nullptr, surface_manager().GetSurfaceForId(display_id_first));
}
// The parent Surface is blocked on |child_id1| and |child_id2|.
TEST_F(SurfaceSynchronizationTest, BlockedOnTwo) {
const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1);
const SurfaceId child_id1 = MakeSurfaceId(kChildFrameSink1, 1);
const SurfaceId child_id2 = MakeSurfaceId(kChildFrameSink2, 1);
parent_support().SubmitCompositorFrame(
parent_id.local_surface_id(),
MakeCompositorFrame({child_id1, child_id2}, empty_surface_ids(),
TransferableResourceArray()));
// parent_support is blocked on |child_id1| and |child_id2|.
EXPECT_TRUE(dependency_tracker().has_deadline());
EXPECT_FALSE(parent_surface()->HasActiveFrame());
EXPECT_TRUE(parent_surface()->HasPendingFrame());
EXPECT_THAT(parent_surface()->blocking_surfaces(),
UnorderedElementsAre(child_id1, child_id2));
// Submit a CompositorFrame without any dependencies to |child_id1|.
// parent_support should now only be blocked on |child_id2|.
child_support1().SubmitCompositorFrame(child_id1.local_surface_id(),
MakeCompositorFrame());
EXPECT_TRUE(dependency_tracker().has_deadline());
EXPECT_FALSE(parent_surface()->HasActiveFrame());
EXPECT_TRUE(parent_surface()->HasPendingFrame());
EXPECT_THAT(parent_surface()->blocking_surfaces(),
UnorderedElementsAre(child_id2));
// Submit a CompositorFrame without any dependencies to |child_id2|.
// parent_support should be activated.
child_support2().SubmitCompositorFrame(child_id2.local_surface_id(),
MakeCompositorFrame());
EXPECT_FALSE(dependency_tracker().has_deadline());
EXPECT_TRUE(parent_surface()->HasActiveFrame());
EXPECT_FALSE(parent_surface()->HasPendingFrame());
EXPECT_THAT(parent_surface()->blocking_surfaces(), IsEmpty());
}
// The parent Surface is blocked on |child_id2| which is blocked on |child_id3|.
TEST_F(SurfaceSynchronizationTest, BlockedChain) {
const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1);
const SurfaceId child_id1 = MakeSurfaceId(kChildFrameSink1, 1);
const SurfaceId child_id2 = MakeSurfaceId(kChildFrameSink2, 1);
parent_support().SubmitCompositorFrame(
parent_id.local_surface_id(),
MakeCompositorFrame({child_id1}, empty_surface_ids(),
TransferableResourceArray()));
// parent_support is blocked on |child_id1|.
EXPECT_TRUE(dependency_tracker().has_deadline());
EXPECT_FALSE(parent_surface()->HasActiveFrame());
EXPECT_TRUE(parent_surface()->HasPendingFrame());
EXPECT_THAT(parent_surface()->blocking_surfaces(),
UnorderedElementsAre(child_id1));
// The parent should not report damage until it activates.
EXPECT_FALSE(surface_observer().IsSurfaceDamaged(parent_id));
child_support1().SubmitCompositorFrame(
child_id1.local_surface_id(),
MakeCompositorFrame({child_id2}, empty_surface_ids(),
TransferableResourceArray()));
// child_support1 should now be blocked on |child_id2|.
EXPECT_TRUE(dependency_tracker().has_deadline());
EXPECT_FALSE(child_surface1()->HasActiveFrame());
EXPECT_TRUE(child_surface1()->HasPendingFrame());
EXPECT_THAT(child_surface1()->blocking_surfaces(),
UnorderedElementsAre(child_id2));
// The parent and child should not report damage until they activate.
EXPECT_FALSE(surface_observer().IsSurfaceDamaged(parent_id));
EXPECT_FALSE(surface_observer().IsSurfaceDamaged(child_id1));
// The parent should still be blocked on |child_id1| because it's pending.
EXPECT_THAT(parent_surface()->blocking_surfaces(),
UnorderedElementsAre(child_id1));
// Submit a CompositorFrame without any dependencies to |child_id2|.
// parent_support should be activated.
child_support2().SubmitCompositorFrame(
child_id2.local_surface_id(),
MakeCompositorFrame(empty_surface_ids(), empty_surface_ids(),
TransferableResourceArray()));
EXPECT_FALSE(dependency_tracker().has_deadline());
// child_surface1 should now be active.
EXPECT_TRUE(child_surface1()->HasActiveFrame());
EXPECT_FALSE(child_surface1()->HasPendingFrame());
EXPECT_THAT(child_surface1()->blocking_surfaces(), IsEmpty());
// parent_surface should now be active.
EXPECT_TRUE(parent_surface()->HasActiveFrame());
EXPECT_FALSE(parent_surface()->HasPendingFrame());
EXPECT_THAT(parent_surface()->blocking_surfaces(), IsEmpty());
// All three surfaces |parent_id|, |child_id1|, and |child_id2| should
// now report damage. This would trigger a new display frame.
EXPECT_TRUE(surface_observer().IsSurfaceDamaged(parent_id));
EXPECT_TRUE(surface_observer().IsSurfaceDamaged(child_id1));
EXPECT_TRUE(surface_observer().IsSurfaceDamaged(child_id2));
}
// parent_surface and child_surface1 are blocked on |child_id2|.
TEST_F(SurfaceSynchronizationTest, TwoBlockedOnOne) {
const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1);
const SurfaceId child_id1 = MakeSurfaceId(kChildFrameSink1, 1);
const SurfaceId child_id2 = MakeSurfaceId(kChildFrameSink2, 1);
parent_support().SubmitCompositorFrame(
parent_id.local_surface_id(),
MakeCompositorFrame({child_id2}, empty_surface_ids(),
TransferableResourceArray()));
// parent_support is blocked on |child_id2|.
EXPECT_TRUE(dependency_tracker().has_deadline());
EXPECT_FALSE(parent_surface()->HasActiveFrame());
EXPECT_TRUE(parent_surface()->HasPendingFrame());
EXPECT_THAT(parent_surface()->blocking_surfaces(),
UnorderedElementsAre(child_id2));
// child_support1 should now be blocked on |child_id2|.
child_support1().SubmitCompositorFrame(
child_id1.local_surface_id(),
MakeCompositorFrame({child_id2}, empty_surface_ids(),
TransferableResourceArray()));
EXPECT_TRUE(dependency_tracker().has_deadline());
EXPECT_FALSE(child_surface1()->HasActiveFrame());
EXPECT_TRUE(child_surface1()->HasPendingFrame());
EXPECT_THAT(child_surface1()->blocking_surfaces(),
UnorderedElementsAre(child_id2));
// The parent should still be blocked on |child_id2|.
EXPECT_THAT(parent_surface()->blocking_surfaces(),
UnorderedElementsAre(child_id2));
// Submit a CompositorFrame without any dependencies to |child_id2|.
// parent_support should be activated.
child_support2().SubmitCompositorFrame(child_id2.local_surface_id(),
MakeCompositorFrame());
EXPECT_FALSE(dependency_tracker().has_deadline());
// child_surface1 should now be active.
EXPECT_TRUE(child_surface1()->HasActiveFrame());
EXPECT_FALSE(child_surface1()->HasPendingFrame());
EXPECT_THAT(child_surface1()->blocking_surfaces(), IsEmpty());
// parent_surface should now be active.
EXPECT_TRUE(parent_surface()->HasActiveFrame());
EXPECT_FALSE(parent_surface()->HasPendingFrame());
EXPECT_THAT(parent_surface()->blocking_surfaces(), IsEmpty());
}
// parent_surface is blocked on |child_id1|, and child_surface2 is blocked on
// |child_id2| until the deadline hits.
TEST_F(SurfaceSynchronizationTest, DeadlineHits) {
const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1);
const SurfaceId child_id1 = MakeSurfaceId(kChildFrameSink1, 1);
const SurfaceId child_id2 = MakeSurfaceId(kChildFrameSink2, 1);
parent_support().SubmitCompositorFrame(
parent_id.local_surface_id(),
MakeCompositorFrame({child_id1}, empty_surface_ids(),
TransferableResourceArray()));
// parent_support is blocked on |child_id1|.
EXPECT_TRUE(dependency_tracker().has_deadline());
EXPECT_FALSE(parent_surface()->HasActiveFrame());
EXPECT_TRUE(parent_surface()->HasPendingFrame());
EXPECT_THAT(parent_surface()->blocking_surfaces(),
UnorderedElementsAre(child_id1));
child_support1().SubmitCompositorFrame(
child_id1.local_surface_id(),
MakeCompositorFrame({child_id2}, empty_surface_ids(),
TransferableResourceArray()));
// child_support1 should now be blocked on |child_id2|.
EXPECT_TRUE(dependency_tracker().has_deadline());
EXPECT_FALSE(child_surface1()->HasActiveFrame());
EXPECT_TRUE(child_surface1()->HasPendingFrame());
EXPECT_THAT(child_surface1()->blocking_surfaces(),
UnorderedElementsAre(child_id2));
// The parent should still be blocked on |child_id1| because it's pending.
EXPECT_THAT(parent_surface()->blocking_surfaces(),
UnorderedElementsAre(child_id1));
BeginFrameArgs args =
CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 0, 1);
for (int i = 0; i < 3; ++i) {
begin_frame_source()->TestOnBeginFrame(args);
// There is still a looming deadline! Eeek!
EXPECT_TRUE(dependency_tracker().has_deadline());
// parent_support is still blocked on |child_id1|.
EXPECT_FALSE(parent_surface()->HasActiveFrame());
EXPECT_TRUE(parent_surface()->HasPendingFrame());
EXPECT_THAT(parent_surface()->blocking_surfaces(),
UnorderedElementsAre(child_id1));
// child_support1 is still blocked on |child_id2|.
EXPECT_FALSE(child_surface1()->HasActiveFrame());
EXPECT_TRUE(child_surface1()->HasPendingFrame());
EXPECT_THAT(child_surface1()->blocking_surfaces(),
UnorderedElementsAre(child_id2));
}
begin_frame_source()->TestOnBeginFrame(args);
// The deadline has passed.
EXPECT_FALSE(dependency_tracker().has_deadline());
// parent_surface has been activated.
EXPECT_TRUE(parent_surface()->HasActiveFrame());
EXPECT_FALSE(parent_surface()->HasPendingFrame());
EXPECT_THAT(parent_surface()->blocking_surfaces(), IsEmpty());
// child_surface1 has been activated.
EXPECT_TRUE(child_surface1()->HasActiveFrame());
EXPECT_FALSE(child_surface1()->HasPendingFrame());
EXPECT_THAT(child_surface1()->blocking_surfaces(), IsEmpty());
}
// Verifies that the deadline does not reset if we submit CompositorFrames
// to new Surfaces with unresolved dependencies.
TEST_F(SurfaceSynchronizationTest, FramesSubmittedAfterDeadlineSet) {
const SurfaceId arbitrary_id = MakeSurfaceId(kArbitraryFrameSink, 1);
BeginFrameArgs args =
CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 0, 1);
for (int i = 0; i < 3; ++i) {
LocalSurfaceId local_surface_id(1, base::UnguessableToken::Create());
support(i).SubmitCompositorFrame(
local_surface_id,
MakeCompositorFrame({arbitrary_id}, empty_surface_ids(),
TransferableResourceArray()));
// The deadline has been set.
EXPECT_TRUE(dependency_tracker().has_deadline());
// support(i) should be blocked on arbitrary_id.
EXPECT_FALSE(surface(i)->HasActiveFrame());
EXPECT_TRUE(surface(i)->HasPendingFrame());
EXPECT_THAT(surface(i)->blocking_surfaces(),
UnorderedElementsAre(arbitrary_id));
// Issue a BeginFrame to get closer to the deadline.
begin_frame_source()->TestOnBeginFrame(args);
}
// The deadline hits and all the Surfaces should activate.
begin_frame_source()->TestOnBeginFrame(args);
for (int i = 0; i < 3; ++i) {
EXPECT_TRUE(surface(i)->HasActiveFrame());
EXPECT_FALSE(surface(i)->HasPendingFrame());
EXPECT_THAT(surface(i)->blocking_surfaces(), IsEmpty());
}
}
// This test verifies at the Surface activates once a CompositorFrame is
// submitted that has no unresolved dependencies.
TEST_F(SurfaceSynchronizationTest, NewFrameOverridesOldDependencies) {
const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1);
const SurfaceId arbitrary_id = MakeSurfaceId(kArbitraryFrameSink, 1);
// Submit a CompositorFrame that depends on |arbitrary_id|.
parent_support().SubmitCompositorFrame(
parent_id.local_surface_id(),
MakeCompositorFrame({arbitrary_id}, empty_surface_ids(),
TransferableResourceArray()));
// Verify that the CompositorFrame is blocked on |arbitrary_id|.
EXPECT_FALSE(parent_surface()->HasActiveFrame());
EXPECT_TRUE(parent_surface()->HasPendingFrame());
EXPECT_THAT(parent_surface()->blocking_surfaces(),
UnorderedElementsAre(arbitrary_id));
// Submit a CompositorFrame that has no dependencies.
parent_support().SubmitCompositorFrame(parent_id.local_surface_id(),
MakeCompositorFrame());
// Verify that the CompositorFrame has been activated.
EXPECT_TRUE(parent_surface()->HasActiveFrame());
EXPECT_FALSE(parent_surface()->HasPendingFrame());
EXPECT_THAT(parent_surface()->blocking_surfaces(), IsEmpty());
}
// This test verifies that a pending CompositorFrame does not affect surface
// references. A new surface from a child will continue to exist as a temporary
// reference until the parent's frame activates.
TEST_F(SurfaceSynchronizationTest, OnlyActiveFramesAffectSurfaceReferences) {
const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1);
const SurfaceId child_id1 = MakeSurfaceId(kChildFrameSink1, 1);
const SurfaceId child_id2 = MakeSurfaceId(kChildFrameSink2, 1);
// child_support1 submits a CompositorFrame without any dependencies.
// DidReceiveCompositorFrameAck should call on immediate activation.
EXPECT_CALL(support_client_, DidReceiveCompositorFrameAck(_)).Times(1);
child_support1().SubmitCompositorFrame(child_id1.local_surface_id(),
MakeCompositorFrame());
testing::Mock::VerifyAndClearExpectations(&support_client_);
// Verify that the child surface is not blocked.
EXPECT_TRUE(child_surface1()->HasActiveFrame());
EXPECT_FALSE(child_surface1()->HasPendingFrame());
EXPECT_THAT(child_surface1()->blocking_surfaces(), IsEmpty());
// Verify that there's a temporary reference for |child_id1|.
EXPECT_TRUE(HasTemporaryReference(child_id1));
// parent_support submits a CompositorFrame that depends on |child_id1|
// (which is already active) and |child_id2|. Thus, the parent should not
// activate immediately. DidReceiveCompositorFrameAck should not be called
// immediately because the parent CompositorFrame is also blocked on
// |child_id2|.
EXPECT_CALL(support_client_, DidReceiveCompositorFrameAck(_)).Times(0);
parent_support().SubmitCompositorFrame(
parent_id.local_surface_id(),
MakeCompositorFrame({child_id2}, {child_id1},
TransferableResourceArray()));
EXPECT_FALSE(parent_surface()->HasActiveFrame());
EXPECT_TRUE(parent_surface()->HasPendingFrame());
EXPECT_THAT(parent_surface()->blocking_surfaces(),
UnorderedElementsAre(child_id2));
EXPECT_THAT(GetChildReferences(parent_id), IsEmpty());
testing::Mock::VerifyAndClearExpectations(&support_client_);
// Verify that there's a temporary reference for |child_id1| that still
// exists.
EXPECT_TRUE(HasTemporaryReference(child_id1));
// child_support2 submits a CompositorFrame without any dependencies.
// Both the child and the parent should immediately ACK CompositorFrames
// on activation.
EXPECT_CALL(support_client_, DidReceiveCompositorFrameAck(_)).Times(2);
child_support2().SubmitCompositorFrame(child_id2.local_surface_id(),
MakeCompositorFrame());
testing::Mock::VerifyAndClearExpectations(&support_client_);
// Verify that the child surface is not blocked.
EXPECT_TRUE(child_surface1()->HasActiveFrame());
EXPECT_FALSE(child_surface1()->HasPendingFrame());
EXPECT_THAT(child_surface1()->blocking_surfaces(), IsEmpty());
// Verify that the parent surface's CompositorFrame has activated and that the
// temporary reference has been replaced by a permanent one.
EXPECT_TRUE(parent_surface()->HasActiveFrame());
EXPECT_FALSE(parent_surface()->HasPendingFrame());
EXPECT_THAT(parent_surface()->blocking_surfaces(), IsEmpty());
EXPECT_FALSE(HasTemporaryReference(child_id1));
EXPECT_THAT(GetChildReferences(parent_id), UnorderedElementsAre(child_id1));
}
// This test verifies that we do not double count returned resources when a
// CompositorFrame starts out as pending, then becomes active, and then is
// replaced with another active CompositorFrame.
TEST_F(SurfaceSynchronizationTest, ResourcesOnlyReturnedOnce) {
const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1);
const SurfaceId child_id = MakeSurfaceId(kChildFrameSink1, 1);
// The parent submits a CompositorFrame that depends on |child_id| before the
// child submits a CompositorFrame. The CompositorFrame also has resources in
// its resource list.
TransferableResource resource;
resource.id = 1337;
resource.format = ALPHA_8;
resource.filter = 1234;
resource.size = gfx::Size(1234, 5678);
TransferableResourceArray resource_list = {resource};
parent_support().SubmitCompositorFrame(
parent_id.local_surface_id(),
MakeCompositorFrame({child_id}, empty_surface_ids(), resource_list));
// Verify that the CompositorFrame is blocked on |child_id|.
EXPECT_FALSE(parent_surface()->HasActiveFrame());
EXPECT_TRUE(parent_surface()->HasPendingFrame());
EXPECT_THAT(parent_surface()->blocking_surfaces(),
UnorderedElementsAre(child_id));
child_support1().SubmitCompositorFrame(
child_id.local_surface_id(),
MakeCompositorFrame(empty_surface_ids(), empty_surface_ids(),
TransferableResourceArray()));
// Verify that the child CompositorFrame activates immediately.
EXPECT_TRUE(child_surface1()->HasActiveFrame());
EXPECT_FALSE(child_surface1()->HasPendingFrame());
EXPECT_THAT(child_surface1()->blocking_surfaces(), IsEmpty());
// Verify that the parent has activated.
EXPECT_TRUE(parent_surface()->HasActiveFrame());
EXPECT_FALSE(parent_surface()->HasPendingFrame());
EXPECT_THAT(parent_surface()->blocking_surfaces(), IsEmpty());
ReturnedResourceArray returned_resources = {resource.ToReturnedResource()};
EXPECT_CALL(support_client_,
DidReceiveCompositorFrameAck(returned_resources));
// The parent submits a CompositorFrame without any dependencies. That frame
// should activate immediately, replacing the earlier frame. The resource from
// the earlier frame should be returned to the client.
parent_support().SubmitCompositorFrame(
parent_id.local_surface_id(),
MakeCompositorFrame({empty_surface_ids()}, {empty_surface_ids()},
TransferableResourceArray()));
EXPECT_TRUE(parent_surface()->HasActiveFrame());
EXPECT_FALSE(parent_surface()->HasPendingFrame());
EXPECT_THAT(parent_surface()->blocking_surfaces(), IsEmpty());
}
// The parent Surface is blocked on |child_id2| which is blocked on |child_id3|.
// child_support1 evicts its blocked Surface. The parent surface should
// activate.
TEST_F(SurfaceSynchronizationTest, EvictSurfaceWithPendingFrame) {
const SurfaceId parent_id1 = MakeSurfaceId(kParentFrameSink, 1);
const SurfaceId child_id1 = MakeSurfaceId(kChildFrameSink1, 1);
const SurfaceId child_id2 = MakeSurfaceId(kChildFrameSink2, 1);
// Submit a CompositorFrame that depends on |child_id1|.
parent_support().SubmitCompositorFrame(
parent_id1.local_surface_id(),
MakeCompositorFrame({child_id1}, empty_surface_ids(),
TransferableResourceArray()));
// Verify that the CompositorFrame is blocked on |child_id1|.
EXPECT_FALSE(parent_surface()->HasActiveFrame());
EXPECT_TRUE(parent_surface()->HasPendingFrame());
EXPECT_THAT(parent_surface()->blocking_surfaces(),
UnorderedElementsAre(child_id1));
// Submit a CompositorFrame that depends on |child_id2|.
child_support1().SubmitCompositorFrame(
child_id1.local_surface_id(),
MakeCompositorFrame({child_id2}, empty_surface_ids(),
TransferableResourceArray()));
// Verify that the CompositorFrame is blocked on |child_id2|.
EXPECT_FALSE(child_surface1()->HasActiveFrame());
EXPECT_TRUE(child_surface1()->HasPendingFrame());
EXPECT_THAT(child_surface1()->blocking_surfaces(),
UnorderedElementsAre(child_id2));
// Evict child_support1's current Surface.
// TODO(fsamuel): EvictCurrentSurface => EvictCurrentSurface.
child_support1().EvictCurrentSurface();
// The parent Surface should immediately activate.
EXPECT_TRUE(parent_surface()->HasActiveFrame());
EXPECT_FALSE(parent_surface()->HasPendingFrame());
EXPECT_THAT(parent_surface()->blocking_surfaces(), IsEmpty());
EXPECT_FALSE(dependency_tracker().has_deadline());
}
// This test verifies that if a surface has both a pending and active
// CompositorFrame and the pending CompositorFrame activates, replacing the
// existing active CompositorFrame, then the surface reference hierarchy will be
// updated allowing garbage collection of surfaces that are no longer
// referenced.
TEST_F(SurfaceSynchronizationTest, DropStaleReferencesAfterActivation) {
const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1);
const SurfaceId child_id1 = MakeSurfaceId(kChildFrameSink1, 1);
const SurfaceId child_id2 = MakeSurfaceId(kChildFrameSink2, 1);
// The parent submits a CompositorFrame that depends on |child_id1| before the
// child submits a CompositorFrame.
EXPECT_CALL(support_client_, DidReceiveCompositorFrameAck(_)).Times(0);
parent_support().SubmitCompositorFrame(
parent_id.local_surface_id(),
MakeCompositorFrame({child_id1}, empty_surface_ids(),
TransferableResourceArray()));
// Verify that the CompositorFrame is blocked on |child_id|.
EXPECT_FALSE(parent_surface()->HasActiveFrame());
EXPECT_TRUE(parent_surface()->HasPendingFrame());
EXPECT_THAT(parent_surface()->blocking_surfaces(),
UnorderedElementsAre(child_id1));
testing::Mock::VerifyAndClearExpectations(&support_client_);
// Verify that no references are added while the CompositorFrame is pending.
EXPECT_THAT(GetChildReferences(parent_id), IsEmpty());
// DidReceiveCompositorFrameAck should get called twice: once for the child
// and once for the now active parent CompositorFrame.
EXPECT_CALL(support_client_, DidReceiveCompositorFrameAck(_)).Times(2);
child_support1().SubmitCompositorFrame(child_id1.local_surface_id(),
MakeCompositorFrame());
testing::Mock::VerifyAndClearExpectations(&support_client_);
// Verify that the child CompositorFrame activates immediately.
EXPECT_TRUE(child_surface1()->HasActiveFrame());
EXPECT_FALSE(child_surface1()->HasPendingFrame());
EXPECT_THAT(child_surface1()->blocking_surfaces(), IsEmpty());
// Verify that the parent Surface has activated.
EXPECT_TRUE(parent_surface()->HasActiveFrame());
EXPECT_FALSE(parent_surface()->HasPendingFrame());
EXPECT_THAT(parent_surface()->blocking_surfaces(), IsEmpty());
// Submit a new parent CompositorFrame to add a reference.
parent_support().SubmitCompositorFrame(
parent_id.local_surface_id(),
MakeCompositorFrame(empty_surface_ids(), {child_id1},
TransferableResourceArray()));
// Verify that the parent Surface has activated.
EXPECT_TRUE(parent_surface()->HasActiveFrame());
EXPECT_FALSE(parent_surface()->HasPendingFrame());
EXPECT_THAT(parent_surface()->blocking_surfaces(), IsEmpty());
// Verify that there is no temporary reference for the child and that
// the reference from the parent to the child still exists.
EXPECT_FALSE(HasTemporaryReference(child_id1));
EXPECT_THAT(GetChildReferences(parent_id), UnorderedElementsAre(child_id1));
// The parent submits another CompositorFrame that depends on |child_id2|.
// Submitting a pending CompositorFrame will not trigger a CompositorFrameAck.
EXPECT_CALL(support_client_, DidReceiveCompositorFrameAck(_)).Times(0);
parent_support().SubmitCompositorFrame(
parent_id.local_surface_id(),
MakeCompositorFrame({child_id2}, empty_surface_ids(),
TransferableResourceArray()));
testing::Mock::VerifyAndClearExpectations(&support_client_);
// The parent surface should now have both a pending and activate
// CompositorFrame. Verify that the set of child references from
// |parent_id| are only from the active CompositorFrame.
EXPECT_TRUE(parent_surface()->HasActiveFrame());
EXPECT_TRUE(parent_surface()->HasPendingFrame());
EXPECT_THAT(parent_surface()->blocking_surfaces(),
UnorderedElementsAre(child_id2));
EXPECT_THAT(GetChildReferences(parent_id), UnorderedElementsAre(child_id1));
child_support2().SubmitCompositorFrame(child_id2.local_surface_id(),
MakeCompositorFrame());
// Verify that the parent Surface has activated and no longer has a pending
// CompositorFrame. Also verify that |child_id1| is no longer a child
// reference of |parent_id|.
EXPECT_TRUE(parent_surface()->HasActiveFrame());
EXPECT_FALSE(parent_surface()->HasPendingFrame());
EXPECT_THAT(parent_surface()->blocking_surfaces(), IsEmpty());
// The parent will not immediately refer to the child until it submits a new
// CompositorFrame with the reference.
EXPECT_THAT(GetChildReferences(parent_id), IsEmpty());
}
// Checks whether the latency info are moved to the new surface from the old
// one when LocalSurfaceId changes. No frame has unresolved dependencies.
TEST_F(SurfaceSynchronizationTest,
LatencyInfoCarriedOverOnResize_NoUnresolvedDependencies) {
const SurfaceId parent_id1 = MakeSurfaceId(kParentFrameSink, 1);
const SurfaceId parent_id2 = MakeSurfaceId(kParentFrameSink, 2);
const ui::LatencyComponentType latency_type1 =
ui::BROWSER_SNAPSHOT_FRAME_NUMBER_COMPONENT;
const int64_t latency_id1 = 234;
const int64_t latency_sequence_number1 = 5645432;
const ui::LatencyComponentType latency_type2 = ui::TAB_SHOW_COMPONENT;
const int64_t latency_id2 = 31434351;
const int64_t latency_sequence_number2 = 663788;
// Submit a frame with latency info
ui::LatencyInfo info;
info.AddLatencyNumber(latency_type1, latency_id1, latency_sequence_number1);
CompositorFrame frame = MakeCompositorFrame();
frame.metadata.latency_info.push_back(info);
parent_support().SubmitCompositorFrame(parent_id1.local_surface_id(),
std::move(frame));
// Verify that the old surface has an active frame and no pending frame.
Surface* old_surface = surface_manager().GetSurfaceForId(parent_id1);
ASSERT_NE(nullptr, old_surface);
EXPECT_TRUE(old_surface->HasActiveFrame());
EXPECT_FALSE(old_surface->HasPendingFrame());
// Submit another frame with some other latency info and a different
// LocalSurfaceId.
ui::LatencyInfo info2;
info2.AddLatencyNumber(latency_type2, latency_id2, latency_sequence_number2);
CompositorFrame frame2 = MakeCompositorFrame();
frame2.metadata.latency_info.push_back(info2);
parent_support().SubmitCompositorFrame(parent_id2.local_surface_id(),
std::move(frame2));
// Verify that the new surface has an active frame and no pending frames.
Surface* surface = surface_manager().GetSurfaceForId(parent_id2);
ASSERT_NE(nullptr, surface);
EXPECT_TRUE(surface->HasActiveFrame());
EXPECT_FALSE(surface->HasPendingFrame());
// Verify that the new surface has both latency info elements.
std::vector<ui::LatencyInfo> info_list;
surface->TakeLatencyInfo(&info_list);
EXPECT_EQ(2u, info_list.size());
ui::LatencyInfo aggregated_latency_info = info_list[0];
aggregated_latency_info.AddNewLatencyFrom(info_list[1]);
// Two components are the original ones, and the third one is
// DISPLAY_COMPOSITOR_RECEIVED_FRAME_COMPONENT, logged on compositor frame
// submit.
EXPECT_EQ(3u, aggregated_latency_info.latency_components().size());
ui::LatencyInfo::LatencyComponent comp1;
EXPECT_TRUE(
aggregated_latency_info.FindLatency(latency_type1, latency_id1, &comp1));
EXPECT_EQ(latency_sequence_number1, comp1.sequence_number);
EXPECT_TRUE(
aggregated_latency_info.FindLatency(latency_type2, latency_id2, nullptr));
EXPECT_TRUE(aggregated_latency_info.FindLatency(
ui::DISPLAY_COMPOSITOR_RECEIVED_FRAME_COMPONENT, nullptr));
}
// Checks whether the latency info are moved to the new surface from the old
// one when LocalSurfaceId changes. Old surface has unresolved dependencies.
TEST_F(SurfaceSynchronizationTest,
LatencyInfoCarriedOverOnResize_OldSurfaceHasPendingAndActiveFrame) {
const SurfaceId parent_id1 = MakeSurfaceId(kParentFrameSink, 1);
const SurfaceId parent_id2 = MakeSurfaceId(kParentFrameSink, 2);
const SurfaceId child_id = MakeSurfaceId(kChildFrameSink1, 1);
const ui::LatencyComponentType latency_type1 =
ui::BROWSER_SNAPSHOT_FRAME_NUMBER_COMPONENT;
const int64_t latency_id1 = 234;
const int64_t latency_sequence_number1 = 5645432;
const ui::LatencyComponentType latency_type2 = ui::TAB_SHOW_COMPONENT;
const int64_t latency_id2 = 31434351;
const int64_t latency_sequence_number2 = 663788;
// Submit a frame with no unresolved dependecy.
ui::LatencyInfo info;
info.AddLatencyNumber(latency_type1, latency_id1, latency_sequence_number1);
CompositorFrame frame = MakeCompositorFrame();
frame.metadata.latency_info.push_back(info);
parent_support().SubmitCompositorFrame(parent_id1.local_surface_id(),
std::move(frame));
// Submit a frame with unresolved dependencies.
ui::LatencyInfo info2;
info2.AddLatencyNumber(latency_type2, latency_id2, latency_sequence_number2);
CompositorFrame frame2 = MakeCompositorFrame({child_id}, empty_surface_ids(),
TransferableResourceArray());
frame2.metadata.latency_info.push_back(info2);
parent_support().SubmitCompositorFrame(parent_id1.local_surface_id(),
std::move(frame2));
// Verify that the old surface has both an active and a pending frame.
Surface* old_surface = surface_manager().GetSurfaceForId(parent_id1);
ASSERT_NE(nullptr, old_surface);
EXPECT_TRUE(old_surface->HasActiveFrame());
EXPECT_TRUE(old_surface->HasPendingFrame());
// Submit a frame with a new local surface id.
parent_support().SubmitCompositorFrame(parent_id2.local_surface_id(),
MakeCompositorFrame());
// Verify that the new surface has an active frame only.
Surface* surface = surface_manager().GetSurfaceForId(parent_id2);
ASSERT_NE(nullptr, surface);
EXPECT_TRUE(surface->HasActiveFrame());
EXPECT_FALSE(surface->HasPendingFrame());
// Verify that the new surface has latency info from both active and pending
// frame of the old surface.
std::vector<ui::LatencyInfo> info_list;
surface->TakeLatencyInfo(&info_list);
EXPECT_EQ(2u, info_list.size());
ui::LatencyInfo aggregated_latency_info = info_list[0];
aggregated_latency_info.AddNewLatencyFrom(info_list[1]);
// Two components are the original ones, and the third one is
// DISPLAY_COMPOSITOR_RECEIVED_FRAME_COMPONENT, logged on compositor frame
// submit.
EXPECT_EQ(3u, aggregated_latency_info.latency_components().size());
ui::LatencyInfo::LatencyComponent comp1;
EXPECT_TRUE(
aggregated_latency_info.FindLatency(latency_type1, latency_id1, &comp1));
EXPECT_EQ(latency_sequence_number1, comp1.sequence_number);
EXPECT_TRUE(
aggregated_latency_info.FindLatency(latency_type2, latency_id2, nullptr));
EXPECT_TRUE(aggregated_latency_info.FindLatency(
ui::DISPLAY_COMPOSITOR_RECEIVED_FRAME_COMPONENT, nullptr));
}
// Checks whether the latency info are moved to the new surface from the old
// one when LocalSurfaceId changes. The new surface has unresolved dependencies.
TEST_F(SurfaceSynchronizationTest,
LatencyInfoCarriedOverOnResize_NewSurfaceHasPendingFrame) {
const SurfaceId parent_id1 = MakeSurfaceId(kParentFrameSink, 1);
const SurfaceId parent_id2 = MakeSurfaceId(kParentFrameSink, 2);
const SurfaceId child_id = MakeSurfaceId(kChildFrameSink1, 1);
const ui::LatencyComponentType latency_type1 =
ui::BROWSER_SNAPSHOT_FRAME_NUMBER_COMPONENT;
const int64_t latency_id1 = 234;
const int64_t latency_sequence_number1 = 5645432;
const ui::LatencyComponentType latency_type2 = ui::TAB_SHOW_COMPONENT;
const int64_t latency_id2 = 31434351;
const int64_t latency_sequence_number2 = 663788;
// Submit a frame with no unresolved dependencies.
ui::LatencyInfo info;
info.AddLatencyNumber(latency_type1, latency_id1, latency_sequence_number1);
CompositorFrame frame = MakeCompositorFrame();
frame.metadata.latency_info.push_back(info);
parent_support().SubmitCompositorFrame(parent_id1.local_surface_id(),
std::move(frame));
// Verify that the old surface has an active frame only.
Surface* old_surface = surface_manager().GetSurfaceForId(parent_id1);
ASSERT_NE(nullptr, old_surface);
EXPECT_TRUE(old_surface->HasActiveFrame());
EXPECT_FALSE(old_surface->HasPendingFrame());
// Submit a frame with a new local surface id and with unresolved
// dependencies.
ui::LatencyInfo info2;
info2.AddLatencyNumber(latency_type2, latency_id2, latency_sequence_number2);
CompositorFrame frame2 = MakeCompositorFrame({child_id}, empty_surface_ids(),
TransferableResourceArray());
frame2.metadata.latency_info.push_back(info2);
parent_support().SubmitCompositorFrame(parent_id2.local_surface_id(),
std::move(frame2));
// Verify that the new surface has a pending frame and no active frame.
Surface* surface = surface_manager().GetSurfaceForId(parent_id2);
ASSERT_NE(nullptr, surface);
EXPECT_TRUE(surface->HasPendingFrame());
EXPECT_FALSE(surface->HasActiveFrame());
// Resolve the dependencies. The frame in parent's surface must become active.
child_support1().SubmitCompositorFrame(child_id.local_surface_id(),
MakeCompositorFrame());
EXPECT_FALSE(surface->HasPendingFrame());
EXPECT_TRUE(surface->HasActiveFrame());
// Both latency info elements must exist in the now-activated frame of the
// new surface.
std::vector<ui::LatencyInfo> info_list;
surface->TakeLatencyInfo(&info_list);
EXPECT_EQ(2u, info_list.size());
ui::LatencyInfo aggregated_latency_info = info_list[0];
aggregated_latency_info.AddNewLatencyFrom(info_list[1]);
// Two components are the original ones, and the third one is
// DISPLAY_COMPOSITOR_RECEIVED_FRAME_COMPONENT, logged on compositor frame
// submit.
EXPECT_EQ(3u, aggregated_latency_info.latency_components().size());
ui::LatencyInfo::LatencyComponent comp1;
EXPECT_TRUE(
aggregated_latency_info.FindLatency(latency_type1, latency_id1, &comp1));
EXPECT_EQ(latency_sequence_number1, comp1.sequence_number);
EXPECT_TRUE(
aggregated_latency_info.FindLatency(latency_type2, latency_id2, nullptr));
EXPECT_TRUE(aggregated_latency_info.FindLatency(
ui::DISPLAY_COMPOSITOR_RECEIVED_FRAME_COMPONENT, nullptr));
}
// Checks that resources and ack are sent together if possible.
TEST_F(SurfaceSynchronizationTest, ReturnResourcesWithAck) {
const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1);
TransferableResource resource;
resource.id = 1234;
parent_support().SubmitCompositorFrame(
parent_id.local_surface_id(),
MakeCompositorFrame(empty_surface_ids(), empty_surface_ids(),
{resource}));
ReturnedResourceArray returned_resources;
TransferableResource::ReturnResources({resource}, &returned_resources);
EXPECT_CALL(support_client_, ReclaimResources(_)).Times(0);
EXPECT_CALL(support_client_,
DidReceiveCompositorFrameAck(Eq(returned_resources)));
parent_support().SubmitCompositorFrame(parent_id.local_surface_id(),
MakeCompositorFrame());
}
// Verifies that if a surface is marked destroyed and a new frame arrives for
// it, it will be recovered.
TEST_F(SurfaceSynchronizationTest, SurfaceResurrection) {
const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1);
const SurfaceId child_id = MakeSurfaceId(kChildFrameSink1, 3);
// Create the child surface by submitting a frame to it.
EXPECT_EQ(nullptr, surface_manager().GetSurfaceForId(child_id));
child_support1().SubmitCompositorFrame(child_id.local_surface_id(),
MakeCompositorFrame());
// Verify that the child surface is created.
Surface* surface = surface_manager().GetSurfaceForId(child_id);