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

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

Issue 2795683003: [cc]Replace use of SurfaceFactory with CompositorFrameSinkSupport in tests (Closed)
Patch Set: Created 3 years, 8 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 <stddef.h> 5 #include <stddef.h>
6 6
7 #include "cc/scheduler/begin_frame_source.h" 7 #include "cc/scheduler/begin_frame_source.h"
8 #include "cc/surfaces/surface_factory_client.h" 8 #include "cc/surfaces/compositor_frame_sink_support.h"
9 #include "cc/surfaces/surface_manager.h" 9 #include "cc/surfaces/surface_manager.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 11
12 namespace cc { 12 namespace cc {
13 13
14 class FakeSurfaceFactoryClient : public SurfaceFactoryClient { 14 class FakeSurfaceFactoryClient : public CompositorFrameSinkSupport {
Fady Samuel 2017/04/03 22:33:25 Can we get rid of this entirely?
Alex Z. 2017/04/04 14:10:33 Done.
15 public: 15 public:
16 explicit FakeSurfaceFactoryClient(const FrameSinkId& frame_sink_id)
17 : source_(nullptr), manager_(nullptr), frame_sink_id_(frame_sink_id) {}
18
19 FakeSurfaceFactoryClient(const FrameSinkId& frame_sink_id, 16 FakeSurfaceFactoryClient(const FrameSinkId& frame_sink_id,
20 SurfaceManager* manager) 17 SurfaceManager* manager)
21 : source_(nullptr), manager_(nullptr), frame_sink_id_(frame_sink_id) { 18 : CompositorFrameSinkSupport(nullptr,
19 manager,
20 frame_sink_id,
21 false /* is_root */,
22 false /* handles_frame_sink_id_validation */,
23 true /* needs_sync_points */),
24 source_(nullptr),
25 manager_(nullptr),
26 frame_sink_id_(frame_sink_id) {
22 DCHECK(manager); 27 DCHECK(manager);
23 Register(manager); 28 Register(manager);
24 } 29 }
25 30
26 ~FakeSurfaceFactoryClient() override { 31 ~FakeSurfaceFactoryClient() override {}
27 if (manager_) {
28 Unregister();
29 }
30 EXPECT_EQ(nullptr, source_);
31 }
32 32
33 BeginFrameSource* source() { return source_; } 33 BeginFrameSource* source() { return source_; }
34 const FrameSinkId& frame_sink_id() { return frame_sink_id_; } 34 const FrameSinkId& frame_sink_id() { return frame_sink_id_; }
35 35
36 void Register(SurfaceManager* manager) { 36 void Register(SurfaceManager* manager) {
37 EXPECT_EQ(nullptr, manager_); 37 EXPECT_EQ(nullptr, manager_);
38 manager_ = manager; 38 manager_ = manager;
39 manager_->RegisterSurfaceFactoryClient(frame_sink_id_, this); 39 manager_->RegisterSurfaceFactoryClient(frame_sink_id_, this);
40 } 40 }
41 41
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 ~SurfaceManagerTest() override { 73 ~SurfaceManagerTest() override {
74 for (size_t i = 0; i < MAX_FRAME_SINK; ++i) 74 for (size_t i = 0; i < MAX_FRAME_SINK; ++i)
75 manager_.InvalidateFrameSinkId(FrameSinkId(i, i)); 75 manager_.InvalidateFrameSinkId(FrameSinkId(i, i));
76 } 76 }
77 77
78 protected: 78 protected:
79 SurfaceManager manager_; 79 SurfaceManager manager_;
80 }; 80 };
81 81
82 TEST_F(SurfaceManagerTest, SingleClients) { 82 TEST_F(SurfaceManagerTest, SingleClients) {
83 FakeSurfaceFactoryClient client(FrameSinkId(1, 1)); 83 FakeSurfaceFactoryClient client(FrameSinkId(1, 1), &manager_);
84 FakeSurfaceFactoryClient other_client(FrameSinkId(2, 2)); 84 FakeSurfaceFactoryClient other_client(FrameSinkId(2, 2), &manager_);
85 StubBeginFrameSource source; 85 StubBeginFrameSource source;
86 86
87 EXPECT_EQ(nullptr, client.source()); 87 EXPECT_EQ(nullptr, client.source());
88 EXPECT_EQ(nullptr, other_client.source()); 88 EXPECT_EQ(nullptr, other_client.source());
89 client.Register(&manager_);
90 other_client.Register(&manager_);
91 EXPECT_EQ(nullptr, client.source());
92 EXPECT_EQ(nullptr, other_client.source());
93 89
94 // Test setting unsetting BFS 90 // Test setting unsetting BFS
95 manager_.RegisterBeginFrameSource(&source, client.frame_sink_id()); 91 manager_.RegisterBeginFrameSource(&source, client.frame_sink_id());
96 EXPECT_EQ(&source, client.source()); 92 EXPECT_EQ(&source, client.source());
97 EXPECT_EQ(nullptr, other_client.source()); 93 EXPECT_EQ(nullptr, other_client.source());
98 manager_.UnregisterBeginFrameSource(&source); 94 manager_.UnregisterBeginFrameSource(&source);
99 EXPECT_EQ(nullptr, client.source()); 95 EXPECT_EQ(nullptr, client.source());
100 EXPECT_EQ(nullptr, other_client.source()); 96 EXPECT_EQ(nullptr, other_client.source());
101 97
102 // Set BFS for other namespace 98 // Set BFS for other namespace
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 256
261 // In practice, registering and unregistering both parent/child relationships 257 // In practice, registering and unregistering both parent/child relationships
262 // and SurfaceFactoryClients can happen in any ordering with respect to 258 // and SurfaceFactoryClients can happen in any ordering with respect to
263 // each other. These following tests verify that all the data structures 259 // each other. These following tests verify that all the data structures
264 // are properly set up and cleaned up under the four permutations of orderings 260 // are properly set up and cleaned up under the four permutations of orderings
265 // of this nesting. 261 // of this nesting.
266 262
267 class SurfaceManagerOrderingTest : public SurfaceManagerTest { 263 class SurfaceManagerOrderingTest : public SurfaceManagerTest {
268 public: 264 public:
269 SurfaceManagerOrderingTest() 265 SurfaceManagerOrderingTest()
270 : client_a_(FrameSinkId(1, 1)), 266 : hierarchy_registered_(false),
271 client_b_(FrameSinkId(2, 2)),
272 client_c_(FrameSinkId(3, 3)),
273 hierarchy_registered_(false),
274 clients_registered_(false), 267 clients_registered_(false),
275 bfs_registered_(false) { 268 bfs_registered_(false) {
276 AssertCorrectBFSState(); 269 AssertCorrectBFSState();
277 } 270 }
278 271
279 ~SurfaceManagerOrderingTest() override { 272 ~SurfaceManagerOrderingTest() override {
280 EXPECT_FALSE(hierarchy_registered_); 273 EXPECT_FALSE(hierarchy_registered_);
281 EXPECT_FALSE(clients_registered_); 274 EXPECT_FALSE(clients_registered_);
282 EXPECT_FALSE(bfs_registered_); 275 EXPECT_FALSE(bfs_registered_);
283 AssertCorrectBFSState(); 276 AssertCorrectBFSState();
284 } 277 }
285 278
286 void RegisterHierarchy() { 279 void RegisterHierarchy() {
287 DCHECK(!hierarchy_registered_); 280 DCHECK(!hierarchy_registered_);
288 hierarchy_registered_ = true; 281 hierarchy_registered_ = true;
289 manager_.RegisterFrameSinkHierarchy(client_a_.frame_sink_id(), 282 manager_.RegisterFrameSinkHierarchy(frame_sink_id_a_, frame_sink_id_b_);
290 client_b_.frame_sink_id()); 283 manager_.RegisterFrameSinkHierarchy(frame_sink_id_b_, frame_sink_id_c_);
291 manager_.RegisterFrameSinkHierarchy(client_b_.frame_sink_id(),
292 client_c_.frame_sink_id());
293 AssertCorrectBFSState(); 284 AssertCorrectBFSState();
294 } 285 }
295 void UnregisterHierarchy() { 286 void UnregisterHierarchy() {
296 DCHECK(hierarchy_registered_); 287 DCHECK(hierarchy_registered_);
297 hierarchy_registered_ = false; 288 hierarchy_registered_ = false;
298 manager_.UnregisterFrameSinkHierarchy(client_a_.frame_sink_id(), 289 manager_.UnregisterFrameSinkHierarchy(frame_sink_id_a_, frame_sink_id_b_);
299 client_b_.frame_sink_id()); 290 manager_.UnregisterFrameSinkHierarchy(frame_sink_id_b_, frame_sink_id_c_);
300 manager_.UnregisterFrameSinkHierarchy(client_b_.frame_sink_id(),
301 client_c_.frame_sink_id());
302 AssertCorrectBFSState(); 291 AssertCorrectBFSState();
303 } 292 }
304 293
305 void RegisterClients() { 294 void RegisterClients() {
306 DCHECK(!clients_registered_); 295 DCHECK(!clients_registered_);
307 clients_registered_ = true; 296 clients_registered_ = true;
308 client_a_.Register(&manager_); 297 client_a_ =
309 client_b_.Register(&manager_); 298 base::MakeUnique<FakeSurfaceFactoryClient>(frame_sink_id_a_, &manager_);
310 client_c_.Register(&manager_); 299 client_b_ =
300 base::MakeUnique<FakeSurfaceFactoryClient>(frame_sink_id_b_, &manager_);
301 client_c_ =
302 base::MakeUnique<FakeSurfaceFactoryClient>(frame_sink_id_c_, &manager_);
311 AssertCorrectBFSState(); 303 AssertCorrectBFSState();
312 } 304 }
313 305
314 void UnregisterClients() { 306 void UnregisterClients() {
315 DCHECK(clients_registered_); 307 DCHECK(clients_registered_);
316 clients_registered_ = false; 308 clients_registered_ = false;
317 client_a_.Unregister(); 309 client_a_.reset();
318 client_b_.Unregister(); 310 client_b_.reset();
319 client_c_.Unregister(); 311 client_c_.reset();
320 AssertCorrectBFSState(); 312 AssertCorrectBFSState();
321 } 313 }
322 314
323 void RegisterBFS() { 315 void RegisterBFS() {
324 DCHECK(!bfs_registered_); 316 DCHECK(!bfs_registered_);
325 bfs_registered_ = true; 317 bfs_registered_ = true;
326 manager_.RegisterBeginFrameSource(&source_, client_a_.frame_sink_id()); 318 manager_.RegisterBeginFrameSource(&source_, frame_sink_id_a_);
327 AssertCorrectBFSState(); 319 AssertCorrectBFSState();
328 } 320 }
329 void UnregisterBFS() { 321 void UnregisterBFS() {
330 DCHECK(bfs_registered_); 322 DCHECK(bfs_registered_);
331 bfs_registered_ = false; 323 bfs_registered_ = false;
332 manager_.UnregisterBeginFrameSource(&source_); 324 manager_.UnregisterBeginFrameSource(&source_);
333 AssertCorrectBFSState(); 325 AssertCorrectBFSState();
334 } 326 }
335 327
336 void AssertEmptyBFS() { 328 void AssertEmptyBFS() {
337 EXPECT_EQ(nullptr, client_a_.source()); 329 EXPECT_TRUE(client_a_.get() == nullptr || client_a_->source() == nullptr);
338 EXPECT_EQ(nullptr, client_b_.source()); 330 EXPECT_TRUE(client_b_.get() == nullptr || client_b_->source() == nullptr);
339 EXPECT_EQ(nullptr, client_c_.source()); 331 EXPECT_TRUE(client_c_.get() == nullptr || client_c_->source() == nullptr);
340 } 332 }
341 333
342 void AssertAllValidBFS() { 334 void AssertAllValidBFS() {
343 EXPECT_EQ(&source_, client_a_.source()); 335 EXPECT_EQ(&source_, client_a_->source());
344 EXPECT_EQ(&source_, client_b_.source()); 336 EXPECT_EQ(&source_, client_b_->source());
345 EXPECT_EQ(&source_, client_c_.source()); 337 EXPECT_EQ(&source_, client_c_->source());
346 } 338 }
347 339
348 protected: 340 protected:
349 void AssertCorrectBFSState() { 341 void AssertCorrectBFSState() {
350 if (!clients_registered_ || !bfs_registered_) { 342 if (!clients_registered_ || !bfs_registered_) {
351 AssertEmptyBFS(); 343 AssertEmptyBFS();
352 return; 344 return;
353 } 345 }
354 if (!hierarchy_registered_) { 346 if (!hierarchy_registered_) {
355 // A valid but not attached to anything. 347 // A valid but not attached to anything.
356 EXPECT_EQ(&source_, client_a_.source()); 348 EXPECT_EQ(&source_, client_a_->source());
357 EXPECT_EQ(nullptr, client_b_.source()); 349 EXPECT_TRUE(client_b_.get() == nullptr || client_b_->source() == nullptr);
358 EXPECT_EQ(nullptr, client_c_.source()); 350 EXPECT_TRUE(client_c_.get() == nullptr || client_c_->source() == nullptr);
359 return; 351 return;
360 } 352 }
361 353
362 AssertAllValidBFS(); 354 AssertAllValidBFS();
363 } 355 }
364 356
365 StubBeginFrameSource source_; 357 StubBeginFrameSource source_;
366 // A -> B -> C hierarchy, with A always having the BFS. 358 // A -> B -> C hierarchy, with A always having the BFS.
367 FakeSurfaceFactoryClient client_a_; 359 std::unique_ptr<FakeSurfaceFactoryClient> client_a_;
368 FakeSurfaceFactoryClient client_b_; 360 std::unique_ptr<FakeSurfaceFactoryClient> client_b_;
369 FakeSurfaceFactoryClient client_c_; 361 std::unique_ptr<FakeSurfaceFactoryClient> client_c_;
362
363 const FrameSinkId frame_sink_id_a_ = FrameSinkId(1, 1);
364 const FrameSinkId frame_sink_id_b_ = FrameSinkId(2, 2);
365 const FrameSinkId frame_sink_id_c_ = FrameSinkId(3, 3);
370 366
371 bool hierarchy_registered_; 367 bool hierarchy_registered_;
372 bool clients_registered_; 368 bool clients_registered_;
373 bool bfs_registered_; 369 bool bfs_registered_;
374 }; 370 };
375 371
376 enum RegisterOrder { REGISTER_HIERARCHY_FIRST, REGISTER_CLIENTS_FIRST }; 372 enum RegisterOrder { REGISTER_HIERARCHY_FIRST, REGISTER_CLIENTS_FIRST };
377 enum UnregisterOrder { UNREGISTER_HIERARCHY_FIRST, UNREGISTER_CLIENTS_FIRST }; 373 enum UnregisterOrder { UNREGISTER_HIERARCHY_FIRST, UNREGISTER_CLIENTS_FIRST };
378 enum BFSOrder { BFS_FIRST, BFS_SECOND, BFS_THIRD }; 374 enum BFSOrder { BFS_FIRST, BFS_SECOND, BFS_THIRD };
379 375
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 } 439 }
444 440
445 INSTANTIATE_TEST_CASE_P( 441 INSTANTIATE_TEST_CASE_P(
446 SurfaceManagerOrderingParamTestInstantiation, 442 SurfaceManagerOrderingParamTestInstantiation,
447 SurfaceManagerOrderingParamTest, 443 SurfaceManagerOrderingParamTest,
448 ::testing::Combine(::testing::ValuesIn(kRegisterOrderList), 444 ::testing::Combine(::testing::ValuesIn(kRegisterOrderList),
449 ::testing::ValuesIn(kUnregisterOrderList), 445 ::testing::ValuesIn(kUnregisterOrderList),
450 ::testing::ValuesIn(kBFSOrderList))); 446 ::testing::ValuesIn(kBFSOrderList)));
451 447
452 } // namespace cc 448 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698