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

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

Issue 2824053003: Split SurfaceFactoryClient Into Four Interfaces (Closed)
Patch Set: Cleanup 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/frame_sink_manager_client.h"
9 #include "cc/surfaces/surface_aggregator_client.h"
8 #include "cc/surfaces/surface_factory_client.h" 10 #include "cc/surfaces/surface_factory_client.h"
9 #include "cc/surfaces/surface_manager.h" 11 #include "cc/surfaces/surface_manager.h"
12 #include "cc/surfaces/surface_resource_holder_client.h"
10 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
11 14
12 namespace cc { 15 namespace cc {
13 16
14 class FakeSurfaceFactoryClient : public SurfaceFactoryClient { 17 class FakeFrameSinkManagerClient : public FrameSinkManagerClient {
15 public: 18 public:
16 explicit FakeSurfaceFactoryClient(const FrameSinkId& frame_sink_id) 19 explicit FakeFrameSinkManagerClient(const FrameSinkId& frame_sink_id)
17 : source_(nullptr), manager_(nullptr), frame_sink_id_(frame_sink_id) {} 20 : source_(nullptr), manager_(nullptr), frame_sink_id_(frame_sink_id) {}
18 21
19 FakeSurfaceFactoryClient(const FrameSinkId& frame_sink_id, 22 FakeFrameSinkManagerClient(const FrameSinkId& frame_sink_id,
20 SurfaceManager* manager) 23 SurfaceManager* manager)
21 : source_(nullptr), manager_(nullptr), frame_sink_id_(frame_sink_id) { 24 : source_(nullptr), manager_(nullptr), frame_sink_id_(frame_sink_id) {
22 DCHECK(manager); 25 DCHECK(manager);
23 Register(manager); 26 Register(manager);
24 } 27 }
25 28
26 ~FakeSurfaceFactoryClient() override { 29 ~FakeFrameSinkManagerClient() override {
27 if (manager_) { 30 if (manager_) {
28 Unregister(); 31 Unregister();
29 } 32 }
30 EXPECT_EQ(nullptr, source_); 33 EXPECT_EQ(nullptr, source_);
31 } 34 }
32 35
33 BeginFrameSource* source() { return source_; } 36 BeginFrameSource* source() { return source_; }
34 const FrameSinkId& frame_sink_id() { return frame_sink_id_; } 37 const FrameSinkId& frame_sink_id() { return frame_sink_id_; }
35 38
36 void Register(SurfaceManager* manager) { 39 void Register(SurfaceManager* manager) {
37 EXPECT_EQ(nullptr, manager_); 40 EXPECT_EQ(nullptr, manager_);
38 manager_ = manager; 41 manager_ = manager;
39 manager_->RegisterSurfaceFactoryClient(frame_sink_id_, this); 42 manager_->RegisterFrameSinkManagerClient(frame_sink_id_, this);
40 } 43 }
41 44
42 void Unregister() { 45 void Unregister() {
43 EXPECT_NE(manager_, nullptr); 46 EXPECT_NE(manager_, nullptr);
44 manager_->UnregisterSurfaceFactoryClient(frame_sink_id_); 47 manager_->UnregisterFrameSinkManagerClient(frame_sink_id_);
45 manager_ = nullptr; 48 manager_ = nullptr;
46 } 49 }
47 50
48 // SurfaceFactoryClient implementation. 51 // FrameSinkManagerClient implementation.
49 void ReturnResources(const ReturnedResourceArray& resources) override {}
50 void SetBeginFrameSource(BeginFrameSource* begin_frame_source) override { 52 void SetBeginFrameSource(BeginFrameSource* begin_frame_source) override {
51 DCHECK(!source_ || !begin_frame_source); 53 DCHECK(!source_ || !begin_frame_source);
52 source_ = begin_frame_source; 54 source_ = begin_frame_source;
53 }; 55 }
54 56
55 private: 57 private:
56 BeginFrameSource* source_; 58 BeginFrameSource* source_;
57 SurfaceManager* manager_; 59 SurfaceManager* manager_;
58 FrameSinkId frame_sink_id_; 60 FrameSinkId frame_sink_id_;
59 }; 61 };
60 62
61 class SurfaceManagerTest : public testing::Test { 63 class SurfaceManagerTest : public testing::Test {
62 public: 64 public:
63 // These tests don't care about namespace registration, so just preregister 65 // These tests don't care about namespace registration, so just preregister
64 // a set of namespaces that tests can use freely without worrying if they're 66 // a set of namespaces that tests can use freely without worrying if they're
65 // valid or not. 67 // valid or not.
66 enum { MAX_FRAME_SINK = 10 }; 68 enum { MAX_FRAME_SINK = 10 };
67 69
68 SurfaceManagerTest() { 70 SurfaceManagerTest() {
69 for (size_t i = 0; i < MAX_FRAME_SINK; ++i) 71 for (size_t i = 0; i < MAX_FRAME_SINK; ++i)
70 manager_.RegisterFrameSinkId(FrameSinkId(i, i)); 72 manager_.RegisterFrameSinkId(FrameSinkId(i, i));
71 } 73 }
72 74
73 ~SurfaceManagerTest() override { 75 ~SurfaceManagerTest() override {
74 for (size_t i = 0; i < MAX_FRAME_SINK; ++i) 76 for (size_t i = 0; i < MAX_FRAME_SINK; ++i)
75 manager_.InvalidateFrameSinkId(FrameSinkId(i, i)); 77 manager_.InvalidateFrameSinkId(FrameSinkId(i, i));
76 } 78 }
77 79
78 protected: 80 protected:
79 SurfaceManager manager_; 81 SurfaceManager manager_;
80 }; 82 };
81 83
82 TEST_F(SurfaceManagerTest, SingleClients) { 84 TEST_F(SurfaceManagerTest, SingleClients) {
83 FakeSurfaceFactoryClient client(FrameSinkId(1, 1)); 85 FakeFrameSinkManagerClient client(FrameSinkId(1, 1));
84 FakeSurfaceFactoryClient other_client(FrameSinkId(2, 2)); 86 FakeFrameSinkManagerClient other_client(FrameSinkId(2, 2));
85 StubBeginFrameSource source; 87 StubBeginFrameSource source;
86 88
87 EXPECT_EQ(nullptr, client.source()); 89 EXPECT_EQ(nullptr, client.source());
88 EXPECT_EQ(nullptr, other_client.source()); 90 EXPECT_EQ(nullptr, other_client.source());
89 client.Register(&manager_); 91 client.Register(&manager_);
90 other_client.Register(&manager_); 92 other_client.Register(&manager_);
91 EXPECT_EQ(nullptr, client.source()); 93 EXPECT_EQ(nullptr, client.source());
92 EXPECT_EQ(nullptr, other_client.source()); 94 EXPECT_EQ(nullptr, other_client.source());
93 95
94 // Test setting unsetting BFS 96 // Test setting unsetting BFS
(...skipping 18 matching lines...) Expand all
113 manager_.UnregisterBeginFrameSource(&source); 115 manager_.UnregisterBeginFrameSource(&source);
114 EXPECT_EQ(nullptr, client.source()); 116 EXPECT_EQ(nullptr, client.source());
115 } 117 }
116 118
117 TEST_F(SurfaceManagerTest, MultipleDisplays) { 119 TEST_F(SurfaceManagerTest, MultipleDisplays) {
118 StubBeginFrameSource root1_source; 120 StubBeginFrameSource root1_source;
119 StubBeginFrameSource root2_source; 121 StubBeginFrameSource root2_source;
120 122
121 // root1 -> A -> B 123 // root1 -> A -> B
122 // root2 -> C 124 // root2 -> C
123 FakeSurfaceFactoryClient root1(FrameSinkId(1, 1), &manager_); 125 FakeFrameSinkManagerClient root1(FrameSinkId(1, 1), &manager_);
124 FakeSurfaceFactoryClient root2(FrameSinkId(2, 2), &manager_); 126 FakeFrameSinkManagerClient root2(FrameSinkId(2, 2), &manager_);
125 FakeSurfaceFactoryClient client_a(FrameSinkId(3, 3), &manager_); 127 FakeFrameSinkManagerClient client_a(FrameSinkId(3, 3), &manager_);
126 FakeSurfaceFactoryClient client_b(FrameSinkId(4, 4), &manager_); 128 FakeFrameSinkManagerClient client_b(FrameSinkId(4, 4), &manager_);
127 FakeSurfaceFactoryClient client_c(FrameSinkId(5, 5), &manager_); 129 FakeFrameSinkManagerClient client_c(FrameSinkId(5, 5), &manager_);
128 130
129 manager_.RegisterBeginFrameSource(&root1_source, root1.frame_sink_id()); 131 manager_.RegisterBeginFrameSource(&root1_source, root1.frame_sink_id());
130 manager_.RegisterBeginFrameSource(&root2_source, root2.frame_sink_id()); 132 manager_.RegisterBeginFrameSource(&root2_source, root2.frame_sink_id());
131 EXPECT_EQ(root1.source(), &root1_source); 133 EXPECT_EQ(root1.source(), &root1_source);
132 EXPECT_EQ(root2.source(), &root2_source); 134 EXPECT_EQ(root2.source(), &root2_source);
133 135
134 // Set up initial hierarchy. 136 // Set up initial hierarchy.
135 manager_.RegisterFrameSinkHierarchy(root1.frame_sink_id(), 137 manager_.RegisterFrameSinkHierarchy(root1.frame_sink_id(),
136 client_a.frame_sink_id()); 138 client_a.frame_sink_id());
137 EXPECT_EQ(client_a.source(), root1.source()); 139 EXPECT_EQ(client_a.source(), root1.source());
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 // FrameSinkId is preserved even if that FrameSinkId has no children 187 // FrameSinkId is preserved even if that FrameSinkId has no children
186 // and does not have a corresponding SurfaceFactoryClient. 188 // and does not have a corresponding SurfaceFactoryClient.
187 TEST_F(SurfaceManagerTest, ParentWithoutClientRetained) { 189 TEST_F(SurfaceManagerTest, ParentWithoutClientRetained) {
188 StubBeginFrameSource root_source; 190 StubBeginFrameSource root_source;
189 191
190 constexpr FrameSinkId kFrameSinkIdRoot(1, 1); 192 constexpr FrameSinkId kFrameSinkIdRoot(1, 1);
191 constexpr FrameSinkId kFrameSinkIdA(2, 2); 193 constexpr FrameSinkId kFrameSinkIdA(2, 2);
192 constexpr FrameSinkId kFrameSinkIdB(3, 3); 194 constexpr FrameSinkId kFrameSinkIdB(3, 3);
193 constexpr FrameSinkId kFrameSinkIdC(4, 4); 195 constexpr FrameSinkId kFrameSinkIdC(4, 4);
194 196
195 FakeSurfaceFactoryClient root(kFrameSinkIdRoot, &manager_); 197 FakeFrameSinkManagerClient root(kFrameSinkIdRoot, &manager_);
196 FakeSurfaceFactoryClient client_b(kFrameSinkIdB, &manager_); 198 FakeFrameSinkManagerClient client_b(kFrameSinkIdB, &manager_);
197 FakeSurfaceFactoryClient client_c(kFrameSinkIdC, &manager_); 199 FakeFrameSinkManagerClient client_c(kFrameSinkIdC, &manager_);
198 200
199 manager_.RegisterBeginFrameSource(&root_source, root.frame_sink_id()); 201 manager_.RegisterBeginFrameSource(&root_source, root.frame_sink_id());
200 EXPECT_EQ(&root_source, root.source()); 202 EXPECT_EQ(&root_source, root.source());
201 203
202 // Set up initial hierarchy: root -> A -> B. 204 // Set up initial hierarchy: root -> A -> B.
203 // Note that A does not have a SurfaceFactoryClient. 205 // Note that A does not have a SurfaceFactoryClient.
204 manager_.RegisterFrameSinkHierarchy(kFrameSinkIdRoot, kFrameSinkIdA); 206 manager_.RegisterFrameSinkHierarchy(kFrameSinkIdRoot, kFrameSinkIdA);
205 manager_.RegisterFrameSinkHierarchy(kFrameSinkIdA, kFrameSinkIdB); 207 manager_.RegisterFrameSinkHierarchy(kFrameSinkIdA, kFrameSinkIdB);
206 // The root's BeginFrameSource should propagate to B. 208 // The root's BeginFrameSource should propagate to B.
207 EXPECT_EQ(root.source(), client_b.source()); 209 EXPECT_EQ(root.source(), client_b.source());
(...skipping 16 matching lines...) Expand all
224 // propagates all the way to C. 226 // propagates all the way to C.
225 TEST_F(SurfaceManagerTest, 227 TEST_F(SurfaceManagerTest,
226 ParentWithoutClientRetained_LateBeginFrameRegistration) { 228 ParentWithoutClientRetained_LateBeginFrameRegistration) {
227 StubBeginFrameSource root_source; 229 StubBeginFrameSource root_source;
228 230
229 constexpr FrameSinkId kFrameSinkIdRoot(1, 1); 231 constexpr FrameSinkId kFrameSinkIdRoot(1, 1);
230 constexpr FrameSinkId kFrameSinkIdA(2, 2); 232 constexpr FrameSinkId kFrameSinkIdA(2, 2);
231 constexpr FrameSinkId kFrameSinkIdB(3, 3); 233 constexpr FrameSinkId kFrameSinkIdB(3, 3);
232 constexpr FrameSinkId kFrameSinkIdC(4, 4); 234 constexpr FrameSinkId kFrameSinkIdC(4, 4);
233 235
234 FakeSurfaceFactoryClient root(kFrameSinkIdRoot, &manager_); 236 FakeFrameSinkManagerClient root(kFrameSinkIdRoot, &manager_);
235 FakeSurfaceFactoryClient client_b(kFrameSinkIdB, &manager_); 237 FakeFrameSinkManagerClient client_b(kFrameSinkIdB, &manager_);
236 FakeSurfaceFactoryClient client_c(kFrameSinkIdC, &manager_); 238 FakeFrameSinkManagerClient client_c(kFrameSinkIdC, &manager_);
237 239
238 // Set up initial hierarchy: root -> A -> B. 240 // Set up initial hierarchy: root -> A -> B.
239 // Note that A does not have a SurfaceFactoryClient. 241 // Note that A does not have a SurfaceFactoryClient.
240 manager_.RegisterFrameSinkHierarchy(kFrameSinkIdRoot, kFrameSinkIdA); 242 manager_.RegisterFrameSinkHierarchy(kFrameSinkIdRoot, kFrameSinkIdA);
241 manager_.RegisterFrameSinkHierarchy(kFrameSinkIdA, kFrameSinkIdB); 243 manager_.RegisterFrameSinkHierarchy(kFrameSinkIdA, kFrameSinkIdB);
242 // The root does not yet have a BeginFrameSource so client B should not have 244 // The root does not yet have a BeginFrameSource so client B should not have
243 // one either. 245 // one either.
244 EXPECT_EQ(nullptr, client_b.source()); 246 EXPECT_EQ(nullptr, client_b.source());
245 247
246 // Unregister B, and attach C to A: root -> A -> C 248 // Unregister B, and attach C to A: root -> A -> C
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
357 EXPECT_EQ(nullptr, client_b_.source()); 359 EXPECT_EQ(nullptr, client_b_.source());
358 EXPECT_EQ(nullptr, client_c_.source()); 360 EXPECT_EQ(nullptr, client_c_.source());
359 return; 361 return;
360 } 362 }
361 363
362 AssertAllValidBFS(); 364 AssertAllValidBFS();
363 } 365 }
364 366
365 StubBeginFrameSource source_; 367 StubBeginFrameSource source_;
366 // A -> B -> C hierarchy, with A always having the BFS. 368 // A -> B -> C hierarchy, with A always having the BFS.
367 FakeSurfaceFactoryClient client_a_; 369 FakeFrameSinkManagerClient client_a_;
368 FakeSurfaceFactoryClient client_b_; 370 FakeFrameSinkManagerClient client_b_;
369 FakeSurfaceFactoryClient client_c_; 371 FakeFrameSinkManagerClient client_c_;
370 372
371 bool hierarchy_registered_; 373 bool hierarchy_registered_;
372 bool clients_registered_; 374 bool clients_registered_;
373 bool bfs_registered_; 375 bool bfs_registered_;
374 }; 376 };
375 377
376 enum RegisterOrder { REGISTER_HIERARCHY_FIRST, REGISTER_CLIENTS_FIRST }; 378 enum RegisterOrder { REGISTER_HIERARCHY_FIRST, REGISTER_CLIENTS_FIRST };
377 enum UnregisterOrder { UNREGISTER_HIERARCHY_FIRST, UNREGISTER_CLIENTS_FIRST }; 379 enum UnregisterOrder { UNREGISTER_HIERARCHY_FIRST, UNREGISTER_CLIENTS_FIRST };
378 enum BFSOrder { BFS_FIRST, BFS_SECOND, BFS_THIRD }; 380 enum BFSOrder { BFS_FIRST, BFS_SECOND, BFS_THIRD };
379 381
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 } 445 }
444 446
445 INSTANTIATE_TEST_CASE_P( 447 INSTANTIATE_TEST_CASE_P(
446 SurfaceManagerOrderingParamTestInstantiation, 448 SurfaceManagerOrderingParamTestInstantiation,
447 SurfaceManagerOrderingParamTest, 449 SurfaceManagerOrderingParamTest,
448 ::testing::Combine(::testing::ValuesIn(kRegisterOrderList), 450 ::testing::Combine(::testing::ValuesIn(kRegisterOrderList),
449 ::testing::ValuesIn(kUnregisterOrderList), 451 ::testing::ValuesIn(kUnregisterOrderList),
450 ::testing::ValuesIn(kBFSOrderList))); 452 ::testing::ValuesIn(kBFSOrderList)));
451 453
452 } // namespace cc 454 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698