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

Side by Side Diff: cc/surfaces/surface_synchronization_unittest.cc

Issue 2802023002: Remove SurfaceFactory And SurfaceFactoryClient (Closed)
Patch Set: Change Ref/UnrefResources to public Created 3 years, 7 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
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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/surfaces/compositor_frame_sink_support.h" 5 #include "cc/surfaces/compositor_frame_sink_support.h"
6
7 #include "base/macros.h"
8 #include "cc/output/compositor_frame.h"
9 #include "cc/surfaces/compositor_frame_sink_support_client.h"
10 #include "cc/surfaces/frame_sink_id.h"
11 #include "cc/surfaces/surface_id.h" 6 #include "cc/surfaces/surface_id.h"
12 #include "cc/surfaces/surface_manager.h" 7 #include "cc/surfaces/surface_manager.h"
8 #include "cc/surfaces/surface_observer.h"
13 #include "cc/test/begin_frame_args_test.h" 9 #include "cc/test/begin_frame_args_test.h"
14 #include "cc/test/fake_external_begin_frame_source.h" 10 #include "cc/test/fake_external_begin_frame_source.h"
11 #include "cc/test/mock_compositor_frame_sink_support_client.h"
15 #include "testing/gmock/include/gmock/gmock.h" 12 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
17 14
15 using testing::Eq;
16 using testing::IsEmpty;
18 using testing::UnorderedElementsAre; 17 using testing::UnorderedElementsAre;
19 using testing::IsEmpty;
20 using testing::SizeIs;
21 using testing::Invoke;
22 using testing::_;
23 using testing::Eq;
24 18
25 namespace cc { 19 namespace cc {
26 namespace test { 20 namespace test {
27 namespace { 21 namespace {
28 22
23 constexpr bool kIsRoot = true;
24 constexpr bool kIsChildRoot = false;
25 constexpr bool kHandlesFrameSinkIdInvalidation = true;
26 constexpr bool kNeedsSyncPoints = true;
29 constexpr FrameSinkId kDisplayFrameSink(2, 0); 27 constexpr FrameSinkId kDisplayFrameSink(2, 0);
30 constexpr FrameSinkId kParentFrameSink(3, 0); 28 constexpr FrameSinkId kParentFrameSink(3, 0);
31 constexpr FrameSinkId kChildFrameSink1(65563, 0); 29 constexpr FrameSinkId kChildFrameSink1(65563, 0);
32 constexpr FrameSinkId kChildFrameSink2(65564, 0); 30 constexpr FrameSinkId kChildFrameSink2(65564, 0);
33 constexpr FrameSinkId kArbitraryFrameSink(1337, 7331); 31 constexpr FrameSinkId kArbitraryFrameSink(1337, 7331);
34 32
35 class MockCompositorFrameSinkSupportClient
36 : public CompositorFrameSinkSupportClient {
37 public:
38 MockCompositorFrameSinkSupportClient() {
39 ON_CALL(*this, ReclaimResources(_))
40 .WillByDefault(Invoke(
41 this,
42 &MockCompositorFrameSinkSupportClient::ReclaimResourcesInternal));
43 ON_CALL(*this, DidReceiveCompositorFrameAck(_))
44 .WillByDefault(Invoke(
45 this,
46 &MockCompositorFrameSinkSupportClient::ReclaimResourcesInternal));
47 }
48
49 ReturnedResourceArray& last_returned_resources() {
50 return last_returned_resources_;
51 }
52
53 // CompositorFrameSinkSupportClient implementation.
54 MOCK_METHOD1(DidReceiveCompositorFrameAck,
55 void(const ReturnedResourceArray&));
56 MOCK_METHOD1(OnBeginFrame, void(const BeginFrameArgs&));
57 MOCK_METHOD1(ReclaimResources, void(const ReturnedResourceArray&));
58 MOCK_METHOD2(WillDrawSurface, void(const LocalSurfaceId&, const gfx::Rect&));
59
60 private:
61 void ReclaimResourcesInternal(const ReturnedResourceArray& resources) {
62 last_returned_resources_ = resources;
63 }
64
65 ReturnedResourceArray last_returned_resources_;
66 };
67
68 std::vector<SurfaceId> empty_surface_ids() { 33 std::vector<SurfaceId> empty_surface_ids() {
69 return std::vector<SurfaceId>(); 34 return std::vector<SurfaceId>();
70 } 35 }
71 36
72 SurfaceId MakeSurfaceId(const FrameSinkId& frame_sink_id, uint32_t local_id) { 37 SurfaceId MakeSurfaceId(const FrameSinkId& frame_sink_id, uint32_t local_id) {
73 return SurfaceId( 38 return SurfaceId(
74 frame_sink_id, 39 frame_sink_id,
75 LocalSurfaceId(local_id, base::UnguessableToken::Deserialize(0, 1u))); 40 LocalSurfaceId(local_id, base::UnguessableToken::Deserialize(0, 1u)));
76 } 41 }
77 42
78 CompositorFrame MakeCompositorFrame(std::vector<SurfaceId> embedded_surfaces,
79 std::vector<SurfaceId> referenced_surfaces,
80 TransferableResourceArray resource_list) {
81 CompositorFrame compositor_frame;
82 compositor_frame.metadata.begin_frame_ack = BeginFrameAck(0, 1, 1, true);
83 compositor_frame.metadata.embedded_surfaces = std::move(embedded_surfaces);
84 compositor_frame.metadata.referenced_surfaces =
85 std::move(referenced_surfaces);
86 compositor_frame.resource_list = std::move(resource_list);
87 return compositor_frame;
88 }
89
90 CompositorFrame MakeCompositorFrame() {
91 return MakeCompositorFrame(empty_surface_ids(), empty_surface_ids(),
92 TransferableResourceArray());
93 }
94
95 CompositorFrame MakeCompositorFrame(std::vector<SurfaceId> embedded_surfaces) {
96 return MakeCompositorFrame(embedded_surfaces, embedded_surfaces,
97 TransferableResourceArray());
98 }
99
100 CompositorFrame MakeCompositorFrame(
101 std::vector<SurfaceId> embedded_surfaces,
102 std::vector<SurfaceId> referenced_surfaces) {
103 return MakeCompositorFrame(std::move(embedded_surfaces),
104 std::move(referenced_surfaces),
105 TransferableResourceArray());
106 }
107
108 CompositorFrame MakeCompositorFrameWithResources(
109 std::vector<SurfaceId> embedded_surfaces,
110 TransferableResourceArray resource_list) {
111 return MakeCompositorFrame(embedded_surfaces, embedded_surfaces,
112 std::move(resource_list));
113 }
114
115 TransferableResource MakeResource(ResourceId id,
116 ResourceFormat format,
117 uint32_t filter,
118 const gfx::Size& size) {
119 TransferableResource resource;
120 resource.id = id;
121 resource.format = format;
122 resource.filter = filter;
123 resource.size = size;
124 return resource;
125 }
126
127 } // namespace 43 } // namespace
128 44
129 class CompositorFrameSinkSupportTest : public testing::Test, 45 class SurfaceSynchronizationTest : public testing::Test,
130 public SurfaceObserver { 46 public SurfaceObserver {
131 public: 47 public:
132 CompositorFrameSinkSupportTest() 48 SurfaceSynchronizationTest()
133 : surface_manager_(SurfaceManager::LifetimeType::REFERENCES) {} 49 : support_client_(false /* create_surface_during_eviction */),
134 ~CompositorFrameSinkSupportTest() override {} 50 surface_manager_(SurfaceManager::LifetimeType::REFERENCES) {}
51 ~SurfaceSynchronizationTest() override {}
135 52
136 CompositorFrameSinkSupport& display_support() { return *supports_[0]; } 53 CompositorFrameSinkSupport& display_support() { return *supports_[0]; }
137 Surface* display_surface() { 54 Surface* display_surface() {
138 return display_support().current_surface_for_testing(); 55 return display_support().current_surface_for_testing();
139 } 56 }
140 57
141 CompositorFrameSinkSupport& parent_support() { return *supports_[1]; } 58 CompositorFrameSinkSupport& parent_support() { return *supports_[1]; }
142 Surface* parent_surface() { 59 Surface* parent_surface() {
143 return parent_support().current_surface_for_testing(); 60 return parent_support().current_surface_for_testing();
144 } 61 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 return *surface_manager_.dependency_tracker(); 95 return *surface_manager_.dependency_tracker();
179 } 96 }
180 97
181 FakeExternalBeginFrameSource* begin_frame_source() { 98 FakeExternalBeginFrameSource* begin_frame_source() {
182 return begin_frame_source_.get(); 99 return begin_frame_source_.get();
183 } 100 }
184 101
185 // testing::Test: 102 // testing::Test:
186 void SetUp() override { 103 void SetUp() override {
187 testing::Test::SetUp(); 104 testing::Test::SetUp();
188 constexpr bool is_root = true; 105
189 constexpr bool is_child_root = false;
190 constexpr bool handles_frame_sink_id_invalidation = true;
191 constexpr bool needs_sync_points = true;
192 begin_frame_source_ = 106 begin_frame_source_ =
193 base::MakeUnique<FakeExternalBeginFrameSource>(0.f, false); 107 base::MakeUnique<FakeExternalBeginFrameSource>(0.f, false);
194 surface_manager_.SetDependencyTracker( 108 surface_manager_.SetDependencyTracker(
195 base::MakeUnique<SurfaceDependencyTracker>(&surface_manager_, 109 base::MakeUnique<SurfaceDependencyTracker>(&surface_manager_,
196 begin_frame_source_.get())); 110 begin_frame_source_.get()));
197 surface_manager_.AddObserver(this); 111 surface_manager_.AddObserver(this);
198 supports_.push_back(CompositorFrameSinkSupport::Create( 112 supports_.push_back(CompositorFrameSinkSupport::Create(
199 &support_client_, &surface_manager_, kDisplayFrameSink, is_root, 113 &support_client_, &surface_manager_, kDisplayFrameSink, kIsRoot,
200 handles_frame_sink_id_invalidation, needs_sync_points)); 114 kHandlesFrameSinkIdInvalidation, kNeedsSyncPoints));
201 supports_.push_back(CompositorFrameSinkSupport::Create( 115 supports_.push_back(CompositorFrameSinkSupport::Create(
202 &support_client_, &surface_manager_, kParentFrameSink, is_child_root, 116 &support_client_, &surface_manager_, kParentFrameSink, kIsChildRoot,
203 handles_frame_sink_id_invalidation, needs_sync_points)); 117 kHandlesFrameSinkIdInvalidation, kNeedsSyncPoints));
204 supports_.push_back(CompositorFrameSinkSupport::Create( 118 supports_.push_back(CompositorFrameSinkSupport::Create(
205 &support_client_, &surface_manager_, kChildFrameSink1, is_child_root, 119 &support_client_, &surface_manager_, kChildFrameSink1, kIsChildRoot,
206 handles_frame_sink_id_invalidation, needs_sync_points)); 120 kHandlesFrameSinkIdInvalidation, kNeedsSyncPoints));
207 supports_.push_back(CompositorFrameSinkSupport::Create( 121 supports_.push_back(CompositorFrameSinkSupport::Create(
208 &support_client_, &surface_manager_, kChildFrameSink2, is_child_root, 122 &support_client_, &surface_manager_, kChildFrameSink2, kIsChildRoot,
209 handles_frame_sink_id_invalidation, needs_sync_points)); 123 kHandlesFrameSinkIdInvalidation, kNeedsSyncPoints));
210 124
211 // Normally, the BeginFrameSource would be registered by the Display. We 125 // Normally, the BeginFrameSource would be registered by the Display. We
212 // register it here so that BeginFrames are received by the display support, 126 // register it here so that BeginFrames are received by the display support,
213 // for use in the PassesOnBeginFrameAcks test. Other supports do not receive 127 // for use in the PassesOnBeginFrameAcks test. Other supports do not receive
214 // BeginFrames, since the frame sink hierarchy is not set up in this test. 128 // BeginFrames, since the frame sink hierarchy is not set up in this test.
215 surface_manager_.RegisterBeginFrameSource(begin_frame_source_.get(), 129 surface_manager_.RegisterBeginFrameSource(begin_frame_source_.get(),
216 kDisplayFrameSink); 130 kDisplayFrameSink);
217 } 131 }
218 132
219 void TearDown() override { 133 void TearDown() override {
(...skipping 22 matching lines...) Expand all
242 156
243 protected: 157 protected:
244 testing::NiceMock<MockCompositorFrameSinkSupportClient> support_client_; 158 testing::NiceMock<MockCompositorFrameSinkSupportClient> support_client_;
245 159
246 private: 160 private:
247 base::flat_set<SurfaceId> damaged_surfaces_; 161 base::flat_set<SurfaceId> damaged_surfaces_;
248 SurfaceManager surface_manager_; 162 SurfaceManager surface_manager_;
249 std::unique_ptr<FakeExternalBeginFrameSource> begin_frame_source_; 163 std::unique_ptr<FakeExternalBeginFrameSource> begin_frame_source_;
250 std::vector<std::unique_ptr<CompositorFrameSinkSupport>> supports_; 164 std::vector<std::unique_ptr<CompositorFrameSinkSupport>> supports_;
251 165
252 DISALLOW_COPY_AND_ASSIGN(CompositorFrameSinkSupportTest); 166 DISALLOW_COPY_AND_ASSIGN(SurfaceSynchronizationTest);
253 }; 167 };
254 168
255 // The display root surface should have a surface reference from the top-level 169 // The display root surface should have a surface reference from the top-level
256 // root added/removed when a CompositorFrame is submitted with a new SurfaceId. 170 // root added/removed when a CompositorFrame is submitted with a new SurfaceId.
257 TEST_F(CompositorFrameSinkSupportTest, RootSurfaceReceivesReferences) { 171 TEST_F(SurfaceSynchronizationTest, RootSurfaceReceivesReferences) {
258 const SurfaceId display_id_first = MakeSurfaceId(kDisplayFrameSink, 1); 172 const SurfaceId display_id_first = MakeSurfaceId(kDisplayFrameSink, 1);
259 const SurfaceId display_id_second = MakeSurfaceId(kDisplayFrameSink, 2); 173 const SurfaceId display_id_second = MakeSurfaceId(kDisplayFrameSink, 2);
260 174
261 // Submit a CompositorFrame for the first display root surface. 175 // Submit a CompositorFrame for the first display root surface.
262 display_support().SubmitCompositorFrame(display_id_first.local_surface_id(), 176 display_support().SubmitCompositorFrame(display_id_first.local_surface_id(),
263 MakeCompositorFrame()); 177 MakeCompositorFrame());
264 178
265 // A surface reference from the top-level root is added and there shouldn't be 179 // A surface reference from the top-level root is added and there shouldn't be
266 // a temporary reference. 180 // a temporary reference.
267 EXPECT_FALSE(HasTemporaryReference(display_id_first)); 181 EXPECT_FALSE(HasTemporaryReference(display_id_first));
268 EXPECT_THAT(GetChildReferences(surface_manager().GetRootSurfaceId()), 182 EXPECT_THAT(GetChildReferences(surface_manager().GetRootSurfaceId()),
269 UnorderedElementsAre(display_id_first)); 183 UnorderedElementsAre(display_id_first));
270 184
271 // Submit a CompositorFrame for the second display root surface. 185 // Submit a CompositorFrame for the second display root surface.
272 display_support().SubmitCompositorFrame(display_id_second.local_surface_id(), 186 display_support().SubmitCompositorFrame(display_id_second.local_surface_id(),
273 MakeCompositorFrame()); 187 MakeCompositorFrame());
274 188
275 // A surface reference from the top-level root to |display_id_second| should 189 // A surface reference from the top-level root to |display_id_second| should
276 // be added and the reference to |display_root_first| removed. 190 // be added and the reference to |display_root_first| removed.
277 EXPECT_FALSE(HasTemporaryReference(display_id_second)); 191 EXPECT_FALSE(HasTemporaryReference(display_id_second));
278 EXPECT_THAT(GetChildReferences(surface_manager().GetRootSurfaceId()), 192 EXPECT_THAT(GetChildReferences(surface_manager().GetRootSurfaceId()),
279 UnorderedElementsAre(display_id_second)); 193 UnorderedElementsAre(display_id_second));
280 194
281 // Surface |display_id_first| is unreachable and should get deleted. 195 // Surface |display_id_first| is unreachable and should get deleted.
282 EXPECT_EQ(nullptr, surface_manager().GetSurfaceForId(display_id_first)); 196 EXPECT_EQ(nullptr, surface_manager().GetSurfaceForId(display_id_first));
283 } 197 }
284 198
285 // The parent Surface is blocked on |child_id1| and |child_id2|. 199 // The parent Surface is blocked on |child_id1| and |child_id2|.
286 TEST_F(CompositorFrameSinkSupportTest, DisplayCompositorLockingBlockedOnTwo) { 200 TEST_F(SurfaceSynchronizationTest, BlockedOnTwo) {
287 const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1); 201 const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1);
288 const SurfaceId child_id1 = MakeSurfaceId(kChildFrameSink1, 1); 202 const SurfaceId child_id1 = MakeSurfaceId(kChildFrameSink1, 1);
289 const SurfaceId child_id2 = MakeSurfaceId(kChildFrameSink2, 1); 203 const SurfaceId child_id2 = MakeSurfaceId(kChildFrameSink2, 1);
290 204
291 parent_support().SubmitCompositorFrame( 205 parent_support().SubmitCompositorFrame(
292 parent_id.local_surface_id(), 206 parent_id.local_surface_id(),
293 MakeCompositorFrame({child_id1, child_id2})); 207 MakeCompositorFrame({child_id1, child_id2}));
294 208
295 // parent_support is blocked on |child_id1| and |child_id2|. 209 // parent_support is blocked on |child_id1| and |child_id2|.
296 EXPECT_TRUE(dependency_tracker().has_deadline()); 210 EXPECT_TRUE(dependency_tracker().has_deadline());
(...skipping 18 matching lines...) Expand all
315 child_support2().SubmitCompositorFrame( 229 child_support2().SubmitCompositorFrame(
316 child_id2.local_surface_id(), MakeCompositorFrame(empty_surface_ids())); 230 child_id2.local_surface_id(), MakeCompositorFrame(empty_surface_ids()));
317 231
318 EXPECT_FALSE(dependency_tracker().has_deadline()); 232 EXPECT_FALSE(dependency_tracker().has_deadline());
319 EXPECT_TRUE(parent_surface()->HasActiveFrame()); 233 EXPECT_TRUE(parent_surface()->HasActiveFrame());
320 EXPECT_FALSE(parent_surface()->HasPendingFrame()); 234 EXPECT_FALSE(parent_surface()->HasPendingFrame());
321 EXPECT_THAT(parent_surface()->blocking_surfaces(), IsEmpty()); 235 EXPECT_THAT(parent_surface()->blocking_surfaces(), IsEmpty());
322 } 236 }
323 237
324 // The parent Surface is blocked on |child_id2| which is blocked on |child_id3|. 238 // The parent Surface is blocked on |child_id2| which is blocked on |child_id3|.
325 TEST_F(CompositorFrameSinkSupportTest, DisplayCompositorLockingBlockedChain) { 239 TEST_F(SurfaceSynchronizationTest, BlockedChain) {
326 const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1); 240 const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1);
327 const SurfaceId child_id1 = MakeSurfaceId(kChildFrameSink1, 1); 241 const SurfaceId child_id1 = MakeSurfaceId(kChildFrameSink1, 1);
328 const SurfaceId child_id2 = MakeSurfaceId(kChildFrameSink2, 1); 242 const SurfaceId child_id2 = MakeSurfaceId(kChildFrameSink2, 1);
329 243
330 parent_support().SubmitCompositorFrame(parent_id.local_surface_id(), 244 parent_support().SubmitCompositorFrame(parent_id.local_surface_id(),
331 MakeCompositorFrame({child_id1})); 245 MakeCompositorFrame({child_id1}));
332 246
333 // parent_support is blocked on |child_id1|. 247 // parent_support is blocked on |child_id1|.
334 EXPECT_TRUE(dependency_tracker().has_deadline()); 248 EXPECT_TRUE(dependency_tracker().has_deadline());
335 EXPECT_FALSE(parent_surface()->HasActiveFrame()); 249 EXPECT_FALSE(parent_surface()->HasActiveFrame());
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 EXPECT_THAT(parent_surface()->blocking_surfaces(), IsEmpty()); 288 EXPECT_THAT(parent_surface()->blocking_surfaces(), IsEmpty());
375 289
376 // All three surfaces |parent_id|, |child_id1|, and |child_id2| should 290 // All three surfaces |parent_id|, |child_id1|, and |child_id2| should
377 // now report damage. This would trigger a new display frame. 291 // now report damage. This would trigger a new display frame.
378 EXPECT_TRUE(IsSurfaceDamaged(parent_id)); 292 EXPECT_TRUE(IsSurfaceDamaged(parent_id));
379 EXPECT_TRUE(IsSurfaceDamaged(child_id1)); 293 EXPECT_TRUE(IsSurfaceDamaged(child_id1));
380 EXPECT_TRUE(IsSurfaceDamaged(child_id2)); 294 EXPECT_TRUE(IsSurfaceDamaged(child_id2));
381 } 295 }
382 296
383 // parent_surface and child_surface1 are blocked on |child_id2|. 297 // parent_surface and child_surface1 are blocked on |child_id2|.
384 TEST_F(CompositorFrameSinkSupportTest, 298 TEST_F(SurfaceSynchronizationTest, TwoBlockedOnOne) {
385 DisplayCompositorLockingTwoBlockedOnOne) {
386 const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1); 299 const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1);
387 const SurfaceId child_id1 = MakeSurfaceId(kChildFrameSink1, 1); 300 const SurfaceId child_id1 = MakeSurfaceId(kChildFrameSink1, 1);
388 const SurfaceId child_id2 = MakeSurfaceId(kChildFrameSink2, 1); 301 const SurfaceId child_id2 = MakeSurfaceId(kChildFrameSink2, 1);
389 302
390 parent_support().SubmitCompositorFrame(parent_id.local_surface_id(), 303 parent_support().SubmitCompositorFrame(parent_id.local_surface_id(),
391 MakeCompositorFrame({child_id2})); 304 MakeCompositorFrame({child_id2}));
392 305
393 // parent_support is blocked on |child_id2|. 306 // parent_support is blocked on |child_id2|.
394 EXPECT_TRUE(dependency_tracker().has_deadline()); 307 EXPECT_TRUE(dependency_tracker().has_deadline());
395 EXPECT_FALSE(parent_surface()->HasActiveFrame()); 308 EXPECT_FALSE(parent_surface()->HasActiveFrame());
(...skipping 28 matching lines...) Expand all
424 EXPECT_THAT(child_surface1()->blocking_surfaces(), IsEmpty()); 337 EXPECT_THAT(child_surface1()->blocking_surfaces(), IsEmpty());
425 338
426 // parent_surface should now be active. 339 // parent_surface should now be active.
427 EXPECT_TRUE(parent_surface()->HasActiveFrame()); 340 EXPECT_TRUE(parent_surface()->HasActiveFrame());
428 EXPECT_FALSE(parent_surface()->HasPendingFrame()); 341 EXPECT_FALSE(parent_surface()->HasPendingFrame());
429 EXPECT_THAT(parent_surface()->blocking_surfaces(), IsEmpty()); 342 EXPECT_THAT(parent_surface()->blocking_surfaces(), IsEmpty());
430 } 343 }
431 344
432 // parent_surface is blocked on |child_id1|, and child_surface2 is blocked on 345 // parent_surface is blocked on |child_id1|, and child_surface2 is blocked on
433 // |child_id2| until the deadline hits. 346 // |child_id2| until the deadline hits.
434 TEST_F(CompositorFrameSinkSupportTest, DisplayCompositorLockingDeadlineHits) { 347 TEST_F(SurfaceSynchronizationTest, DeadlineHits) {
435 const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1); 348 const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1);
436 const SurfaceId child_id1 = MakeSurfaceId(kChildFrameSink1, 1); 349 const SurfaceId child_id1 = MakeSurfaceId(kChildFrameSink1, 1);
437 const SurfaceId child_id2 = MakeSurfaceId(kChildFrameSink2, 1); 350 const SurfaceId child_id2 = MakeSurfaceId(kChildFrameSink2, 1);
438 351
439 parent_support().SubmitCompositorFrame(parent_id.local_surface_id(), 352 parent_support().SubmitCompositorFrame(parent_id.local_surface_id(),
440 MakeCompositorFrame({child_id1})); 353 MakeCompositorFrame({child_id1}));
441 354
442 // parent_support is blocked on |child_id1|. 355 // parent_support is blocked on |child_id1|.
443 EXPECT_TRUE(dependency_tracker().has_deadline()); 356 EXPECT_TRUE(dependency_tracker().has_deadline());
444 EXPECT_FALSE(parent_surface()->HasActiveFrame()); 357 EXPECT_FALSE(parent_surface()->HasActiveFrame());
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 EXPECT_THAT(parent_surface()->blocking_surfaces(), IsEmpty()); 405 EXPECT_THAT(parent_surface()->blocking_surfaces(), IsEmpty());
493 406
494 // child_surface1 has been activated. 407 // child_surface1 has been activated.
495 EXPECT_TRUE(child_surface1()->HasActiveFrame()); 408 EXPECT_TRUE(child_surface1()->HasActiveFrame());
496 EXPECT_FALSE(child_surface1()->HasPendingFrame()); 409 EXPECT_FALSE(child_surface1()->HasPendingFrame());
497 EXPECT_THAT(child_surface1()->blocking_surfaces(), IsEmpty()); 410 EXPECT_THAT(child_surface1()->blocking_surfaces(), IsEmpty());
498 } 411 }
499 412
500 // Verifies that the deadline does not reset if we submit CompositorFrames 413 // Verifies that the deadline does not reset if we submit CompositorFrames
501 // to new Surfaces with unresolved dependencies. 414 // to new Surfaces with unresolved dependencies.
502 TEST_F(CompositorFrameSinkSupportTest, 415 TEST_F(SurfaceSynchronizationTest, FramesSubmittedAfterDeadlineSet) {
503 DisplayCompositorLockingFramesSubmittedAfterDeadlineSet) {
504 const SurfaceId arbitrary_id = MakeSurfaceId(kArbitraryFrameSink, 1); 416 const SurfaceId arbitrary_id = MakeSurfaceId(kArbitraryFrameSink, 1);
505 BeginFrameArgs args = 417 BeginFrameArgs args =
506 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 0, 1); 418 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 0, 1);
507 for (int i = 0; i < 3; ++i) { 419 for (int i = 0; i < 3; ++i) {
508 LocalSurfaceId local_surface_id(1, base::UnguessableToken::Create()); 420 LocalSurfaceId local_surface_id(1, base::UnguessableToken::Create());
509 support(i).SubmitCompositorFrame(local_surface_id, 421 support(i).SubmitCompositorFrame(local_surface_id,
510 MakeCompositorFrame({arbitrary_id})); 422 MakeCompositorFrame({arbitrary_id}));
511 // The deadline has been set. 423 // The deadline has been set.
512 EXPECT_TRUE(dependency_tracker().has_deadline()); 424 EXPECT_TRUE(dependency_tracker().has_deadline());
513 425
(...skipping 11 matching lines...) Expand all
525 begin_frame_source()->TestOnBeginFrame(args); 437 begin_frame_source()->TestOnBeginFrame(args);
526 for (int i = 0; i < 3; ++i) { 438 for (int i = 0; i < 3; ++i) {
527 EXPECT_TRUE(surface(i)->HasActiveFrame()); 439 EXPECT_TRUE(surface(i)->HasActiveFrame());
528 EXPECT_FALSE(surface(i)->HasPendingFrame()); 440 EXPECT_FALSE(surface(i)->HasPendingFrame());
529 EXPECT_THAT(surface(i)->blocking_surfaces(), IsEmpty()); 441 EXPECT_THAT(surface(i)->blocking_surfaces(), IsEmpty());
530 } 442 }
531 } 443 }
532 444
533 // This test verifies at the Surface activates once a CompositorFrame is 445 // This test verifies at the Surface activates once a CompositorFrame is
534 // submitted that has no unresolved dependencies. 446 // submitted that has no unresolved dependencies.
535 TEST_F(CompositorFrameSinkSupportTest, 447 TEST_F(SurfaceSynchronizationTest, NewFrameOverridesOldDependencies) {
536 DisplayCompositorLockingNewFrameOverridesOldDependencies) {
537 const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1); 448 const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1);
538 const SurfaceId arbitrary_id = MakeSurfaceId(kArbitraryFrameSink, 1); 449 const SurfaceId arbitrary_id = MakeSurfaceId(kArbitraryFrameSink, 1);
539 450
540 // Submit a CompositorFrame that depends on |arbitrary_id|. 451 // Submit a CompositorFrame that depends on |arbitrary_id|.
541 parent_support().SubmitCompositorFrame(parent_id.local_surface_id(), 452 parent_support().SubmitCompositorFrame(parent_id.local_surface_id(),
542 MakeCompositorFrame({arbitrary_id})); 453 MakeCompositorFrame({arbitrary_id}));
543 454
544 // Verify that the CompositorFrame is blocked on |arbitrary_id|. 455 // Verify that the CompositorFrame is blocked on |arbitrary_id|.
545 EXPECT_FALSE(parent_surface()->HasActiveFrame()); 456 EXPECT_FALSE(parent_surface()->HasActiveFrame());
546 EXPECT_TRUE(parent_surface()->HasPendingFrame()); 457 EXPECT_TRUE(parent_surface()->HasPendingFrame());
547 EXPECT_THAT(parent_surface()->blocking_surfaces(), 458 EXPECT_THAT(parent_surface()->blocking_surfaces(),
548 UnorderedElementsAre(arbitrary_id)); 459 UnorderedElementsAre(arbitrary_id));
549 460
550 // Submit a CompositorFrame that has no dependencies. 461 // Submit a CompositorFrame that has no dependencies.
551 parent_support().SubmitCompositorFrame( 462 parent_support().SubmitCompositorFrame(
552 parent_id.local_surface_id(), MakeCompositorFrame(empty_surface_ids())); 463 parent_id.local_surface_id(), MakeCompositorFrame(empty_surface_ids()));
553 464
554 // Verify that the CompositorFrame has been activated. 465 // Verify that the CompositorFrame has been activated.
555 EXPECT_TRUE(parent_surface()->HasActiveFrame()); 466 EXPECT_TRUE(parent_surface()->HasActiveFrame());
556 EXPECT_FALSE(parent_surface()->HasPendingFrame()); 467 EXPECT_FALSE(parent_surface()->HasPendingFrame());
557 EXPECT_THAT(parent_surface()->blocking_surfaces(), IsEmpty()); 468 EXPECT_THAT(parent_surface()->blocking_surfaces(), IsEmpty());
558 } 469 }
559 470
560 // This test verifies that a pending CompositorFrame does not affect surface 471 // This test verifies that a pending CompositorFrame does not affect surface
561 // references. A new surface from a child will continue to exist as a temporary 472 // references. A new surface from a child will continue to exist as a temporary
562 // reference until the parent's frame activates. 473 // reference until the parent's frame activates.
563 TEST_F(CompositorFrameSinkSupportTest, 474 TEST_F(SurfaceSynchronizationTest, OnlyActiveFramesAffectSurfaceReferences) {
564 OnlyActiveFramesAffectSurfaceReferences) {
565 const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1); 475 const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1);
566 const SurfaceId child_id1 = MakeSurfaceId(kChildFrameSink1, 1); 476 const SurfaceId child_id1 = MakeSurfaceId(kChildFrameSink1, 1);
567 const SurfaceId child_id2 = MakeSurfaceId(kChildFrameSink2, 1); 477 const SurfaceId child_id2 = MakeSurfaceId(kChildFrameSink2, 1);
568 478
569 // child_support1 submits a CompositorFrame without any dependencies. 479 // child_support1 submits a CompositorFrame without any dependencies.
570 // DidReceiveCompositorFrameAck should call on immediate activation. 480 // DidReceiveCompositorFrameAck should call on immediate activation.
571 EXPECT_CALL(support_client_, DidReceiveCompositorFrameAck(_)).Times(1); 481 EXPECT_CALL(support_client_, DidReceiveCompositorFrameAck(_)).Times(1);
572 child_support1().SubmitCompositorFrame(child_id1.local_surface_id(), 482 child_support1().SubmitCompositorFrame(child_id1.local_surface_id(),
573 MakeCompositorFrame()); 483 MakeCompositorFrame());
574 testing::Mock::VerifyAndClearExpectations(&support_client_); 484 testing::Mock::VerifyAndClearExpectations(&support_client_);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 EXPECT_FALSE(parent_surface()->HasPendingFrame()); 530 EXPECT_FALSE(parent_surface()->HasPendingFrame());
621 EXPECT_THAT(parent_surface()->blocking_surfaces(), IsEmpty()); 531 EXPECT_THAT(parent_surface()->blocking_surfaces(), IsEmpty());
622 EXPECT_FALSE(HasTemporaryReference(child_id1)); 532 EXPECT_FALSE(HasTemporaryReference(child_id1));
623 EXPECT_THAT(GetChildReferences(parent_id), 533 EXPECT_THAT(GetChildReferences(parent_id),
624 UnorderedElementsAre(child_id1, child_id2)); 534 UnorderedElementsAre(child_id1, child_id2));
625 } 535 }
626 536
627 // This test verifies that we do not double count returned resources when a 537 // This test verifies that we do not double count returned resources when a
628 // CompositorFrame starts out as pending, then becomes active, and then is 538 // CompositorFrame starts out as pending, then becomes active, and then is
629 // replaced with another active CompositorFrame. 539 // replaced with another active CompositorFrame.
630 TEST_F(CompositorFrameSinkSupportTest, 540 TEST_F(SurfaceSynchronizationTest, ResourcesOnlyReturnedOnce) {
631 DisplayCompositorLockingResourcesOnlyReturnedOnce) {
632 const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1); 541 const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1);
633 const SurfaceId child_id = MakeSurfaceId(kChildFrameSink1, 1); 542 const SurfaceId child_id = MakeSurfaceId(kChildFrameSink1, 1);
634 543
635 // The parent submits a CompositorFrame that depends on |child_id| before the 544 // The parent submits a CompositorFrame that depends on |child_id| before the
636 // child submits a CompositorFrame. The CompositorFrame also has resources in 545 // child submits a CompositorFrame. The CompositorFrame also has resources in
637 // its resource list. 546 // its resource list.
638 TransferableResource resource = 547 TransferableResource resource =
639 MakeResource(1337 /* id */, ALPHA_8 /* format */, 1234 /* filter */, 548 MakeResource(1337 /* id */, ALPHA_8 /* format */, 1234 /* filter */,
danakj 2017/05/03 16:08:39 This is exactly 1 caller of MakeResource.. can you
Alex Z. 2017/05/03 18:07:37 Done.
640 gfx::Size(1234, 5678)); 549 gfx::Size(1234, 5678));
641 TransferableResourceArray resource_list = {resource}; 550 TransferableResourceArray resource_list = {resource};
642 parent_support().SubmitCompositorFrame( 551 parent_support().SubmitCompositorFrame(
643 parent_id.local_surface_id(), 552 parent_id.local_surface_id(),
644 MakeCompositorFrameWithResources({child_id}, resource_list)); 553 MakeCompositorFrameWithResources({child_id}, resource_list));
645 554
646 // Verify that the CompositorFrame is blocked on |child_id|. 555 // Verify that the CompositorFrame is blocked on |child_id|.
647 EXPECT_FALSE(parent_surface()->HasActiveFrame()); 556 EXPECT_FALSE(parent_surface()->HasActiveFrame());
648 EXPECT_TRUE(parent_surface()->HasPendingFrame()); 557 EXPECT_TRUE(parent_surface()->HasPendingFrame());
649 EXPECT_THAT(parent_surface()->blocking_surfaces(), 558 EXPECT_THAT(parent_surface()->blocking_surfaces(),
(...skipping 21 matching lines...) Expand all
671 EXPECT_FALSE(parent_surface()->HasPendingFrame()); 580 EXPECT_FALSE(parent_surface()->HasPendingFrame());
672 EXPECT_THAT(parent_surface()->blocking_surfaces(), IsEmpty()); 581 EXPECT_THAT(parent_surface()->blocking_surfaces(), IsEmpty());
673 ReturnedResource returned_resource = resource.ToReturnedResource(); 582 ReturnedResource returned_resource = resource.ToReturnedResource();
674 EXPECT_THAT(support_client_.last_returned_resources(), 583 EXPECT_THAT(support_client_.last_returned_resources(),
675 UnorderedElementsAre(returned_resource)); 584 UnorderedElementsAre(returned_resource));
676 } 585 }
677 586
678 // The parent Surface is blocked on |child_id2| which is blocked on |child_id3|. 587 // The parent Surface is blocked on |child_id2| which is blocked on |child_id3|.
679 // child_support1 evicts its blocked Surface. The parent surface should 588 // child_support1 evicts its blocked Surface. The parent surface should
680 // activate. 589 // activate.
681 TEST_F(CompositorFrameSinkSupportTest, EvictSurfaceWithPendingFrame) { 590 TEST_F(SurfaceSynchronizationTest, EvictSurfaceWithPendingFrame) {
682 const SurfaceId parent_id1 = MakeSurfaceId(kParentFrameSink, 1); 591 const SurfaceId parent_id1 = MakeSurfaceId(kParentFrameSink, 1);
683 const SurfaceId child_id1 = MakeSurfaceId(kChildFrameSink1, 1); 592 const SurfaceId child_id1 = MakeSurfaceId(kChildFrameSink1, 1);
684 const SurfaceId child_id2 = MakeSurfaceId(kChildFrameSink2, 1); 593 const SurfaceId child_id2 = MakeSurfaceId(kChildFrameSink2, 1);
685 594
686 // Submit a CompositorFrame that depends on |child_id1|. 595 // Submit a CompositorFrame that depends on |child_id1|.
687 parent_support().SubmitCompositorFrame(parent_id1.local_surface_id(), 596 parent_support().SubmitCompositorFrame(parent_id1.local_surface_id(),
688 MakeCompositorFrame({child_id1})); 597 MakeCompositorFrame({child_id1}));
689 598
690 // Verify that the CompositorFrame is blocked on |child_id1|. 599 // Verify that the CompositorFrame is blocked on |child_id1|.
691 EXPECT_FALSE(parent_surface()->HasActiveFrame()); 600 EXPECT_FALSE(parent_surface()->HasActiveFrame());
(...skipping 20 matching lines...) Expand all
712 EXPECT_FALSE(parent_surface()->HasPendingFrame()); 621 EXPECT_FALSE(parent_surface()->HasPendingFrame());
713 EXPECT_THAT(parent_surface()->blocking_surfaces(), IsEmpty()); 622 EXPECT_THAT(parent_surface()->blocking_surfaces(), IsEmpty());
714 EXPECT_FALSE(dependency_tracker().has_deadline()); 623 EXPECT_FALSE(dependency_tracker().has_deadline());
715 } 624 }
716 625
717 // This test verifies that if a surface has both a pending and active 626 // This test verifies that if a surface has both a pending and active
718 // CompositorFrame and the pending CompositorFrame activates, replacing the 627 // CompositorFrame and the pending CompositorFrame activates, replacing the
719 // existing active CompositorFrame, then the surface reference hierarchy will be 628 // existing active CompositorFrame, then the surface reference hierarchy will be
720 // updated allowing garbage collection of surfaces that are no longer 629 // updated allowing garbage collection of surfaces that are no longer
721 // referenced. 630 // referenced.
722 TEST_F(CompositorFrameSinkSupportTest, DropStaleReferencesAfterActivation) { 631 TEST_F(SurfaceSynchronizationTest, DropStaleReferencesAfterActivation) {
723 const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1); 632 const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1);
724 const SurfaceId child_id1 = MakeSurfaceId(kChildFrameSink1, 1); 633 const SurfaceId child_id1 = MakeSurfaceId(kChildFrameSink1, 1);
725 const SurfaceId child_id2 = MakeSurfaceId(kChildFrameSink2, 1); 634 const SurfaceId child_id2 = MakeSurfaceId(kChildFrameSink2, 1);
726 635
727 // The parent submits a CompositorFrame that depends on |child_id1| before the 636 // The parent submits a CompositorFrame that depends on |child_id1| before the
728 // child submits a CompositorFrame. 637 // child submits a CompositorFrame.
729 EXPECT_CALL(support_client_, DidReceiveCompositorFrameAck(_)).Times(0); 638 EXPECT_CALL(support_client_, DidReceiveCompositorFrameAck(_)).Times(0);
730 parent_support().SubmitCompositorFrame(parent_id.local_surface_id(), 639 parent_support().SubmitCompositorFrame(parent_id.local_surface_id(),
731 MakeCompositorFrame({child_id1})); 640 MakeCompositorFrame({child_id1}));
732 641
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
785 // CompositorFrame. Also verify that |child_id1| is no longer a child 694 // CompositorFrame. Also verify that |child_id1| is no longer a child
786 // reference of |parent_id|. 695 // reference of |parent_id|.
787 EXPECT_TRUE(parent_surface()->HasActiveFrame()); 696 EXPECT_TRUE(parent_surface()->HasActiveFrame());
788 EXPECT_FALSE(parent_surface()->HasPendingFrame()); 697 EXPECT_FALSE(parent_surface()->HasPendingFrame());
789 EXPECT_THAT(parent_surface()->blocking_surfaces(), IsEmpty()); 698 EXPECT_THAT(parent_surface()->blocking_surfaces(), IsEmpty());
790 EXPECT_THAT(GetChildReferences(parent_id), UnorderedElementsAre(child_id2)); 699 EXPECT_THAT(GetChildReferences(parent_id), UnorderedElementsAre(child_id2));
791 } 700 }
792 701
793 // Checks whether the latency info are moved to the new surface from the old 702 // Checks whether the latency info are moved to the new surface from the old
794 // one when LocalSurfaceId changes. No frame has unresolved dependencies. 703 // one when LocalSurfaceId changes. No frame has unresolved dependencies.
795 TEST_F(CompositorFrameSinkSupportTest, 704 TEST_F(SurfaceSynchronizationTest,
796 LatencyInfoCarriedOverOnResize_NoUnresolvedDependencies) { 705 LatencyInfoCarriedOverOnResize_NoUnresolvedDependencies) {
797 const SurfaceId parent_id1 = MakeSurfaceId(kParentFrameSink, 1); 706 const SurfaceId parent_id1 = MakeSurfaceId(kParentFrameSink, 1);
798 const SurfaceId parent_id2 = MakeSurfaceId(kParentFrameSink, 2); 707 const SurfaceId parent_id2 = MakeSurfaceId(kParentFrameSink, 2);
799 const ui::LatencyComponentType latency_type1 = 708 const ui::LatencyComponentType latency_type1 =
800 ui::BROWSER_SNAPSHOT_FRAME_NUMBER_COMPONENT; 709 ui::BROWSER_SNAPSHOT_FRAME_NUMBER_COMPONENT;
801 const int64_t latency_id1 = 234; 710 const int64_t latency_id1 = 234;
802 const int64_t latency_sequence_number1 = 5645432; 711 const int64_t latency_sequence_number1 = 5645432;
803 const ui::LatencyComponentType latency_type2 = ui::TAB_SHOW_COMPONENT; 712 const ui::LatencyComponentType latency_type2 = ui::TAB_SHOW_COMPONENT;
804 const int64_t latency_id2 = 31434351; 713 const int64_t latency_id2 = 31434351;
805 const int64_t latency_sequence_number2 = 663788; 714 const int64_t latency_sequence_number2 = 663788;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
855 aggregated_latency_info.FindLatency(latency_type1, latency_id1, &comp1)); 764 aggregated_latency_info.FindLatency(latency_type1, latency_id1, &comp1));
856 EXPECT_EQ(latency_sequence_number1, comp1.sequence_number); 765 EXPECT_EQ(latency_sequence_number1, comp1.sequence_number);
857 EXPECT_TRUE( 766 EXPECT_TRUE(
858 aggregated_latency_info.FindLatency(latency_type2, latency_id2, nullptr)); 767 aggregated_latency_info.FindLatency(latency_type2, latency_id2, nullptr));
859 EXPECT_TRUE(aggregated_latency_info.FindLatency( 768 EXPECT_TRUE(aggregated_latency_info.FindLatency(
860 ui::DISPLAY_COMPOSITOR_RECEIVED_FRAME_COMPONENT, nullptr)); 769 ui::DISPLAY_COMPOSITOR_RECEIVED_FRAME_COMPONENT, nullptr));
861 } 770 }
862 771
863 // Checks whether the latency info are moved to the new surface from the old 772 // Checks whether the latency info are moved to the new surface from the old
864 // one when LocalSurfaceId changes. Old surface has unresolved dependencies. 773 // one when LocalSurfaceId changes. Old surface has unresolved dependencies.
865 TEST_F(CompositorFrameSinkSupportTest, 774 TEST_F(SurfaceSynchronizationTest,
866 LatencyInfoCarriedOverOnResize_OldSurfaceHasPendingAndActiveFrame) { 775 LatencyInfoCarriedOverOnResize_OldSurfaceHasPendingAndActiveFrame) {
867 const SurfaceId parent_id1 = MakeSurfaceId(kParentFrameSink, 1); 776 const SurfaceId parent_id1 = MakeSurfaceId(kParentFrameSink, 1);
868 const SurfaceId parent_id2 = MakeSurfaceId(kParentFrameSink, 2); 777 const SurfaceId parent_id2 = MakeSurfaceId(kParentFrameSink, 2);
869 const SurfaceId child_id = MakeSurfaceId(kChildFrameSink1, 1); 778 const SurfaceId child_id = MakeSurfaceId(kChildFrameSink1, 1);
870 779
871 const ui::LatencyComponentType latency_type1 = 780 const ui::LatencyComponentType latency_type1 =
872 ui::BROWSER_SNAPSHOT_FRAME_NUMBER_COMPONENT; 781 ui::BROWSER_SNAPSHOT_FRAME_NUMBER_COMPONENT;
873 const int64_t latency_id1 = 234; 782 const int64_t latency_id1 = 234;
874 const int64_t latency_sequence_number1 = 5645432; 783 const int64_t latency_sequence_number1 = 5645432;
875 const ui::LatencyComponentType latency_type2 = ui::TAB_SHOW_COMPONENT; 784 const ui::LatencyComponentType latency_type2 = ui::TAB_SHOW_COMPONENT;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
931 aggregated_latency_info.FindLatency(latency_type1, latency_id1, &comp1)); 840 aggregated_latency_info.FindLatency(latency_type1, latency_id1, &comp1));
932 EXPECT_EQ(latency_sequence_number1, comp1.sequence_number); 841 EXPECT_EQ(latency_sequence_number1, comp1.sequence_number);
933 EXPECT_TRUE( 842 EXPECT_TRUE(
934 aggregated_latency_info.FindLatency(latency_type2, latency_id2, nullptr)); 843 aggregated_latency_info.FindLatency(latency_type2, latency_id2, nullptr));
935 EXPECT_TRUE(aggregated_latency_info.FindLatency( 844 EXPECT_TRUE(aggregated_latency_info.FindLatency(
936 ui::DISPLAY_COMPOSITOR_RECEIVED_FRAME_COMPONENT, nullptr)); 845 ui::DISPLAY_COMPOSITOR_RECEIVED_FRAME_COMPONENT, nullptr));
937 } 846 }
938 847
939 // Checks whether the latency info are moved to the new surface from the old 848 // Checks whether the latency info are moved to the new surface from the old
940 // one when LocalSurfaceId changes. The new surface has unresolved dependencies. 849 // one when LocalSurfaceId changes. The new surface has unresolved dependencies.
941 TEST_F(CompositorFrameSinkSupportTest, 850 TEST_F(SurfaceSynchronizationTest,
942 LatencyInfoCarriedOverOnResize_NewSurfaceHasPendingFrame) { 851 LatencyInfoCarriedOverOnResize_NewSurfaceHasPendingFrame) {
943 const SurfaceId parent_id1 = MakeSurfaceId(kParentFrameSink, 1); 852 const SurfaceId parent_id1 = MakeSurfaceId(kParentFrameSink, 1);
944 const SurfaceId parent_id2 = MakeSurfaceId(kParentFrameSink, 2); 853 const SurfaceId parent_id2 = MakeSurfaceId(kParentFrameSink, 2);
945 const SurfaceId child_id = MakeSurfaceId(kChildFrameSink1, 1); 854 const SurfaceId child_id = MakeSurfaceId(kChildFrameSink1, 1);
946 855
947 const ui::LatencyComponentType latency_type1 = 856 const ui::LatencyComponentType latency_type1 =
948 ui::BROWSER_SNAPSHOT_FRAME_NUMBER_COMPONENT; 857 ui::BROWSER_SNAPSHOT_FRAME_NUMBER_COMPONENT;
949 const int64_t latency_id1 = 234; 858 const int64_t latency_id1 = 234;
950 const int64_t latency_sequence_number1 = 5645432; 859 const int64_t latency_sequence_number1 = 5645432;
951 const ui::LatencyComponentType latency_type2 = ui::TAB_SHOW_COMPONENT; 860 const ui::LatencyComponentType latency_type2 = ui::TAB_SHOW_COMPONENT;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1008 ui::LatencyInfo::LatencyComponent comp1; 917 ui::LatencyInfo::LatencyComponent comp1;
1009 EXPECT_TRUE( 918 EXPECT_TRUE(
1010 aggregated_latency_info.FindLatency(latency_type1, latency_id1, &comp1)); 919 aggregated_latency_info.FindLatency(latency_type1, latency_id1, &comp1));
1011 EXPECT_EQ(latency_sequence_number1, comp1.sequence_number); 920 EXPECT_EQ(latency_sequence_number1, comp1.sequence_number);
1012 EXPECT_TRUE( 921 EXPECT_TRUE(
1013 aggregated_latency_info.FindLatency(latency_type2, latency_id2, nullptr)); 922 aggregated_latency_info.FindLatency(latency_type2, latency_id2, nullptr));
1014 EXPECT_TRUE(aggregated_latency_info.FindLatency( 923 EXPECT_TRUE(aggregated_latency_info.FindLatency(
1015 ui::DISPLAY_COMPOSITOR_RECEIVED_FRAME_COMPONENT, nullptr)); 924 ui::DISPLAY_COMPOSITOR_RECEIVED_FRAME_COMPONENT, nullptr));
1016 } 925 }
1017 926
1018 TEST_F(CompositorFrameSinkSupportTest, PassesOnBeginFrameAcks) { 927 TEST_F(SurfaceSynchronizationTest, PassesOnBeginFrameAcks) {
1019 const SurfaceId display_id = MakeSurfaceId(kDisplayFrameSink, 1); 928 const SurfaceId display_id = MakeSurfaceId(kDisplayFrameSink, 1);
1020 929
1021 // Request BeginFrames. 930 // Request BeginFrames.
1022 display_support().SetNeedsBeginFrame(true); 931 display_support().SetNeedsBeginFrame(true);
1023 932
1024 // Issue a BeginFrame. 933 // Issue a BeginFrame.
1025 BeginFrameArgs args = 934 BeginFrameArgs args =
1026 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 0, 1); 935 CreateBeginFrameArgsForTesting(BEGINFRAME_FROM_HERE, 0, 1);
1027 begin_frame_source()->TestOnBeginFrame(args); 936 begin_frame_source()->TestOnBeginFrame(args);
1028 937
(...skipping 11 matching lines...) Expand all
1040 // to a CompositorFrame to the BeginFrameSource. 949 // to a CompositorFrame to the BeginFrameSource.
1041 BeginFrameAck ack2(0, 2, 2, true); 950 BeginFrameAck ack2(0, 2, 2, true);
1042 CompositorFrame frame = MakeCompositorFrame(); 951 CompositorFrame frame = MakeCompositorFrame();
1043 frame.metadata.begin_frame_ack = ack2; 952 frame.metadata.begin_frame_ack = ack2;
1044 display_support().SubmitCompositorFrame(display_id.local_surface_id(), 953 display_support().SubmitCompositorFrame(display_id.local_surface_id(),
1045 std::move(frame)); 954 std::move(frame));
1046 EXPECT_EQ(ack2, begin_frame_source()->LastAckForObserver(&display_support())); 955 EXPECT_EQ(ack2, begin_frame_source()->LastAckForObserver(&display_support()));
1047 } 956 }
1048 957
1049 // Checks that resources and ack are sent together if possible. 958 // Checks that resources and ack are sent together if possible.
1050 TEST_F(CompositorFrameSinkSupportTest, ReturnResourcesWithAck) { 959 TEST_F(SurfaceSynchronizationTest, ReturnResourcesWithAck) {
1051 const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1); 960 const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1);
1052 TransferableResource resource; 961 TransferableResource resource;
1053 resource.id = 1234; 962 resource.id = 1234;
1054 parent_support().SubmitCompositorFrame( 963 parent_support().SubmitCompositorFrame(
1055 parent_id.local_surface_id(), 964 parent_id.local_surface_id(),
1056 MakeCompositorFrameWithResources(empty_surface_ids(), {resource})); 965 MakeCompositorFrameWithResources(empty_surface_ids(), {resource}));
1057 ReturnedResourceArray returned_resources; 966 ReturnedResourceArray returned_resources;
1058 TransferableResource::ReturnResources({resource}, &returned_resources); 967 TransferableResource::ReturnResources({resource}, &returned_resources);
1059 EXPECT_CALL(support_client_, ReclaimResources(_)).Times(0); 968 EXPECT_CALL(support_client_, ReclaimResources(_)).Times(0);
1060 EXPECT_CALL(support_client_, 969 EXPECT_CALL(support_client_,
1061 DidReceiveCompositorFrameAck(Eq(returned_resources))); 970 DidReceiveCompositorFrameAck(Eq(returned_resources)));
1062 parent_support().SubmitCompositorFrame(parent_id.local_surface_id(), 971 parent_support().SubmitCompositorFrame(parent_id.local_surface_id(),
1063 MakeCompositorFrame()); 972 MakeCompositorFrame());
1064 } 973 }
1065 974
1066 // Verifies that if a surface is marked destroyed and a new frame arrives for 975 // Verifies that if a surface is marked destroyed and a new frame arrives for
1067 // it, it will be recovered. 976 // it, it will be recovered.
1068 TEST_F(CompositorFrameSinkSupportTest, SurfaceResurrection) { 977 TEST_F(SurfaceSynchronizationTest, SurfaceResurrection) {
1069 const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1); 978 const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1);
1070 const SurfaceId child_id = MakeSurfaceId(kChildFrameSink1, 3); 979 const SurfaceId child_id = MakeSurfaceId(kChildFrameSink1, 3);
1071 980
1072 // Add a reference from the parent to the child. 981 // Add a reference from the parent to the child.
1073 parent_support().SubmitCompositorFrame(parent_id.local_surface_id(), 982 parent_support().SubmitCompositorFrame(parent_id.local_surface_id(),
1074 MakeCompositorFrame({child_id})); 983 MakeCompositorFrame({child_id}));
1075 984
1076 // Create the child surface by submitting a frame to it. 985 // Create the child surface by submitting a frame to it.
1077 EXPECT_EQ(nullptr, surface_manager().GetSurfaceForId(child_id)); 986 EXPECT_EQ(nullptr, surface_manager().GetSurfaceForId(child_id));
1078 child_support1().SubmitCompositorFrame(child_id.local_surface_id(), 987 child_support1().SubmitCompositorFrame(child_id.local_surface_id(),
(...skipping 17 matching lines...) Expand all
1096 1005
1097 // Verify that the surface that was marked destroyed is recovered and is being 1006 // Verify that the surface that was marked destroyed is recovered and is being
1098 // used again. 1007 // used again.
1099 Surface* surface2 = surface_manager().GetSurfaceForId(child_id); 1008 Surface* surface2 = surface_manager().GetSurfaceForId(child_id);
1100 EXPECT_EQ(surface, surface2); 1009 EXPECT_EQ(surface, surface2);
1101 EXPECT_FALSE(surface2->destroyed()); 1010 EXPECT_FALSE(surface2->destroyed());
1102 } 1011 }
1103 1012
1104 // Verifies that if a LocalSurfaceId belonged to a surface that doesn't exist 1013 // Verifies that if a LocalSurfaceId belonged to a surface that doesn't exist
1105 // anymore, it can still be reused for new surfaces. 1014 // anymore, it can still be reused for new surfaces.
1106 TEST_F(CompositorFrameSinkSupportTest, LocalSurfaceIdIsReusable) { 1015 TEST_F(SurfaceSynchronizationTest, LocalSurfaceIdIsReusable) {
1107 const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1); 1016 const SurfaceId parent_id = MakeSurfaceId(kParentFrameSink, 1);
1108 const SurfaceId child_id = MakeSurfaceId(kChildFrameSink1, 3); 1017 const SurfaceId child_id = MakeSurfaceId(kChildFrameSink1, 3);
1109 1018
1110 // Add a reference from parent. 1019 // Add a reference from parent.
1111 parent_support().SubmitCompositorFrame(parent_id.local_surface_id(), 1020 parent_support().SubmitCompositorFrame(parent_id.local_surface_id(),
1112 MakeCompositorFrame({child_id})); 1021 MakeCompositorFrame({child_id}));
1113 1022
1114 // Submit the first frame. Creates the surface. 1023 // Submit the first frame. Creates the surface.
1115 child_support1().SubmitCompositorFrame(child_id.local_surface_id(), 1024 child_support1().SubmitCompositorFrame(child_id.local_surface_id(),
1116 MakeCompositorFrame()); 1025 MakeCompositorFrame());
(...skipping 14 matching lines...) Expand all
1131 EXPECT_NE(nullptr, surface_manager().GetSurfaceForId(child_id)); 1040 EXPECT_NE(nullptr, surface_manager().GetSurfaceForId(child_id));
1132 } 1041 }
1133 1042
1134 // This test verifies that a crash does not occur if garbage collection is 1043 // This test verifies that a crash does not occur if garbage collection is
1135 // triggered during surface dependency resolution. This test triggers garbage 1044 // triggered during surface dependency resolution. This test triggers garbage
1136 // collection during surface resolution, by causing an activation to remove 1045 // collection during surface resolution, by causing an activation to remove
1137 // a surface subtree from the root. Both the old subtree and the new 1046 // a surface subtree from the root. Both the old subtree and the new
1138 // activated subtree refer to the same dependency. The old subtree was activated 1047 // activated subtree refer to the same dependency. The old subtree was activated
1139 // by deadline, and the new subtree was activated by a dependency finally 1048 // by deadline, and the new subtree was activated by a dependency finally
1140 // resolving. 1049 // resolving.
1141 TEST_F(CompositorFrameSinkSupportTest, DependencyTrackingGarbageCollection) { 1050 TEST_F(SurfaceSynchronizationTest, DependencyTrackingGarbageCollection) {
1142 const SurfaceId display_id = MakeSurfaceId(kDisplayFrameSink, 1); 1051 const SurfaceId display_id = MakeSurfaceId(kDisplayFrameSink, 1);
1143 const SurfaceId parent_id1 = MakeSurfaceId(kParentFrameSink, 1); 1052 const SurfaceId parent_id1 = MakeSurfaceId(kParentFrameSink, 1);
1144 const SurfaceId parent_id2 = MakeSurfaceId(kParentFrameSink, 2); 1053 const SurfaceId parent_id2 = MakeSurfaceId(kParentFrameSink, 2);
1145 const SurfaceId child_id = MakeSurfaceId(kChildFrameSink1, 1); 1054 const SurfaceId child_id = MakeSurfaceId(kChildFrameSink1, 1);
1146 1055
1147 parent_support().SubmitCompositorFrame(parent_id1.local_surface_id(), 1056 parent_support().SubmitCompositorFrame(parent_id1.local_surface_id(),
1148 MakeCompositorFrame({child_id})); 1057 MakeCompositorFrame({child_id}));
1149 display_support().SubmitCompositorFrame(display_id.local_surface_id(), 1058 display_support().SubmitCompositorFrame(display_id.local_surface_id(),
1150 MakeCompositorFrame({parent_id1})); 1059 MakeCompositorFrame({parent_id1}));
1151 1060
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1185 } 1094 }
1186 1095
1187 // This test verifies that a crash does not occur if garbage collection is 1096 // This test verifies that a crash does not occur if garbage collection is
1188 // triggered when a deadline forces frame activation. This test triggers garbage 1097 // triggered when a deadline forces frame activation. This test triggers garbage
1189 // collection during deadline activation by causing the activation of a display 1098 // collection during deadline activation by causing the activation of a display
1190 // frame to replace a previously activated display frame that was referring to 1099 // frame to replace a previously activated display frame that was referring to
1191 // a now-unreachable surface subtree. That subtree gets garbage collected during 1100 // a now-unreachable surface subtree. That subtree gets garbage collected during
1192 // deadline activation. SurfaceDependencyTracker is also tracking a surface 1101 // deadline activation. SurfaceDependencyTracker is also tracking a surface
1193 // from that subtree due to an unresolved dependency. This test verifies that 1102 // from that subtree due to an unresolved dependency. This test verifies that
1194 // this dependency resolution does not crash. 1103 // this dependency resolution does not crash.
1195 TEST_F(CompositorFrameSinkSupportTest, GarbageCollectionOnDeadline) { 1104 TEST_F(SurfaceSynchronizationTest, GarbageCollectionOnDeadline) {
1196 const SurfaceId display_id = MakeSurfaceId(kDisplayFrameSink, 1); 1105 const SurfaceId display_id = MakeSurfaceId(kDisplayFrameSink, 1);
1197 const SurfaceId parent_id1 = MakeSurfaceId(kParentFrameSink, 1); 1106 const SurfaceId parent_id1 = MakeSurfaceId(kParentFrameSink, 1);
1198 const SurfaceId parent_id2 = MakeSurfaceId(kParentFrameSink, 2); 1107 const SurfaceId parent_id2 = MakeSurfaceId(kParentFrameSink, 2);
1199 const SurfaceId child_id = MakeSurfaceId(kChildFrameSink1, 1); 1108 const SurfaceId child_id = MakeSurfaceId(kChildFrameSink1, 1);
1200 1109
1201 display_support().SubmitCompositorFrame(display_id.local_surface_id(), 1110 display_support().SubmitCompositorFrame(display_id.local_surface_id(),
1202 MakeCompositorFrame({parent_id1})); 1111 MakeCompositorFrame({parent_id1}));
1203 1112
1204 EXPECT_TRUE(display_surface()->HasPendingFrame()); 1113 EXPECT_TRUE(display_surface()->HasPendingFrame());
1205 EXPECT_TRUE(dependency_tracker().has_deadline()); 1114 EXPECT_TRUE(dependency_tracker().has_deadline());
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1242 for (int i = 0; i < 3; ++i) { 1151 for (int i = 0; i < 3; ++i) {
1243 begin_frame_source()->TestOnBeginFrame(args); 1152 begin_frame_source()->TestOnBeginFrame(args);
1244 EXPECT_TRUE(dependency_tracker().has_deadline()); 1153 EXPECT_TRUE(dependency_tracker().has_deadline());
1245 } 1154 }
1246 begin_frame_source()->TestOnBeginFrame(args); 1155 begin_frame_source()->TestOnBeginFrame(args);
1247 EXPECT_FALSE(dependency_tracker().has_deadline()); 1156 EXPECT_FALSE(dependency_tracker().has_deadline());
1248 } 1157 }
1249 1158
1250 // This test verifies that a CompositorFrame will only blocked on embedded 1159 // This test verifies that a CompositorFrame will only blocked on embedded
1251 // surfaces but not on other retained surface IDs in the CompositorFrame. 1160 // surfaces but not on other retained surface IDs in the CompositorFrame.
1252 TEST_F(CompositorFrameSinkSupportTest, OnlyBlockOnEmbeddedSurfaces) { 1161 TEST_F(SurfaceSynchronizationTest, OnlyBlockOnEmbeddedSurfaces) {
1253 const SurfaceId display_id = MakeSurfaceId(kDisplayFrameSink, 1); 1162 const SurfaceId display_id = MakeSurfaceId(kDisplayFrameSink, 1);
1254 const SurfaceId parent_id1 = MakeSurfaceId(kParentFrameSink, 1); 1163 const SurfaceId parent_id1 = MakeSurfaceId(kParentFrameSink, 1);
1255 const SurfaceId parent_id2 = MakeSurfaceId(kParentFrameSink, 2); 1164 const SurfaceId parent_id2 = MakeSurfaceId(kParentFrameSink, 2);
1256 1165
1257 display_support().SubmitCompositorFrame( 1166 display_support().SubmitCompositorFrame(
1258 display_id.local_surface_id(), 1167 display_id.local_surface_id(),
1259 MakeCompositorFrame({parent_id1}, {parent_id1, parent_id2})); 1168 MakeCompositorFrame({parent_id1}, {parent_id1, parent_id2}));
1260 1169
1261 EXPECT_TRUE(display_surface()->HasPendingFrame()); 1170 EXPECT_TRUE(display_surface()->HasPendingFrame());
1262 EXPECT_FALSE(display_surface()->HasActiveFrame()); 1171 EXPECT_FALSE(display_surface()->HasActiveFrame());
(...skipping 17 matching lines...) Expand all
1280 EXPECT_TRUE(display_surface()->HasActiveFrame()); 1189 EXPECT_TRUE(display_surface()->HasActiveFrame());
1281 EXPECT_THAT(display_surface()->blocking_surfaces(), IsEmpty()); 1190 EXPECT_THAT(display_surface()->blocking_surfaces(), IsEmpty());
1282 1191
1283 // Only a reference to |parent_id1| is added because |parent_id2| does not 1192 // Only a reference to |parent_id1| is added because |parent_id2| does not
1284 // exist. 1193 // exist.
1285 EXPECT_THAT(GetChildReferences(display_id), UnorderedElementsAre(parent_id1)); 1194 EXPECT_THAT(GetChildReferences(display_id), UnorderedElementsAre(parent_id1));
1286 } 1195 }
1287 1196
1288 // This test verifies that a late arriving CompositorFrame activates immediately 1197 // This test verifies that a late arriving CompositorFrame activates immediately
1289 // and does not trigger a new deadline. 1198 // and does not trigger a new deadline.
1290 TEST_F(CompositorFrameSinkSupportTest, LateArrivingDependency) { 1199 TEST_F(SurfaceSynchronizationTest, LateArrivingDependency) {
1291 const SurfaceId display_id = MakeSurfaceId(kDisplayFrameSink, 1); 1200 const SurfaceId display_id = MakeSurfaceId(kDisplayFrameSink, 1);
1292 const SurfaceId parent_id1 = MakeSurfaceId(kParentFrameSink, 1); 1201 const SurfaceId parent_id1 = MakeSurfaceId(kParentFrameSink, 1);
1293 const SurfaceId child_id1 = MakeSurfaceId(kChildFrameSink1, 1); 1202 const SurfaceId child_id1 = MakeSurfaceId(kChildFrameSink1, 1);
1294 1203
1295 display_support().SubmitCompositorFrame(display_id.local_surface_id(), 1204 display_support().SubmitCompositorFrame(display_id.local_surface_id(),
1296 MakeCompositorFrame({parent_id1})); 1205 MakeCompositorFrame({parent_id1}));
1297 1206
1298 EXPECT_TRUE(display_surface()->HasPendingFrame()); 1207 EXPECT_TRUE(display_surface()->HasPendingFrame());
1299 EXPECT_FALSE(display_surface()->HasActiveFrame()); 1208 EXPECT_FALSE(display_surface()->HasActiveFrame());
1300 EXPECT_TRUE(dependency_tracker().has_deadline()); 1209 EXPECT_TRUE(dependency_tracker().has_deadline());
(...skipping 15 matching lines...) Expand all
1316 // scheduling a deadline and without waiting for dependencies to resolve. 1225 // scheduling a deadline and without waiting for dependencies to resolve.
1317 parent_support().SubmitCompositorFrame(parent_id1.local_surface_id(), 1226 parent_support().SubmitCompositorFrame(parent_id1.local_surface_id(),
1318 MakeCompositorFrame({child_id1})); 1227 MakeCompositorFrame({child_id1}));
1319 EXPECT_FALSE(dependency_tracker().has_deadline()); 1228 EXPECT_FALSE(dependency_tracker().has_deadline());
1320 EXPECT_FALSE(parent_surface()->HasPendingFrame()); 1229 EXPECT_FALSE(parent_surface()->HasPendingFrame());
1321 EXPECT_TRUE(parent_surface()->HasActiveFrame()); 1230 EXPECT_TRUE(parent_surface()->HasActiveFrame());
1322 } 1231 }
1323 1232
1324 } // namespace test 1233 } // namespace test
1325 } // namespace cc 1234 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698