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

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

Issue 2731743002: Decouple FrameSink Hierarchy registration from SurfaceFactoryClient registration (Closed)
Patch Set: Fixed Created 3 years, 9 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
« no previous file with comments | « cc/surfaces/surface_manager.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/surface_factory_client.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 SurfaceFactoryClient {
15 public: 15 public:
16 explicit FakeSurfaceFactoryClient(const FrameSinkId& frame_sink_id) 16 explicit FakeSurfaceFactoryClient(const FrameSinkId& frame_sink_id)
17 : source_(nullptr), manager_(nullptr), frame_sink_id_(frame_sink_id) {} 17 : source_(nullptr), manager_(nullptr), frame_sink_id_(frame_sink_id) {}
18 18
19 FakeSurfaceFactoryClient(const FrameSinkId& frame_sink_id, 19 FakeSurfaceFactoryClient(const FrameSinkId& frame_sink_id,
20 SurfaceManager* manager) 20 SurfaceManager* manager)
21 : source_(nullptr), manager_(nullptr), frame_sink_id_(frame_sink_id) { 21 : source_(nullptr), manager_(nullptr), frame_sink_id_(frame_sink_id) {
22 DCHECK(manager); 22 DCHECK(manager);
23 Register(manager); 23 Register(manager);
24 } 24 }
25 25
26 ~FakeSurfaceFactoryClient() override { 26 ~FakeSurfaceFactoryClient() override {
27 if (manager_) { 27 if (manager_) {
28 Unregister(); 28 Unregister();
29 } 29 }
30 EXPECT_EQ(source_, nullptr); 30 EXPECT_EQ(nullptr, source_);
31 } 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(manager_, nullptr); 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
42 void Unregister() { 42 void Unregister() {
43 EXPECT_NE(manager_, nullptr); 43 EXPECT_NE(manager_, nullptr);
44 manager_->UnregisterSurfaceFactoryClient(frame_sink_id_); 44 manager_->UnregisterSurfaceFactoryClient(frame_sink_id_);
45 manager_ = nullptr; 45 manager_ = nullptr;
46 } 46 }
47 47
(...skipping 29 matching lines...) Expand all
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));
84 FakeSurfaceFactoryClient other_client(FrameSinkId(2, 2)); 84 FakeSurfaceFactoryClient other_client(FrameSinkId(2, 2));
85 StubBeginFrameSource source; 85 StubBeginFrameSource source;
86 86
87 EXPECT_EQ(client.source(), nullptr); 87 EXPECT_EQ(nullptr, client.source());
88 EXPECT_EQ(other_client.source(), nullptr); 88 EXPECT_EQ(nullptr, other_client.source());
89 client.Register(&manager_); 89 client.Register(&manager_);
90 other_client.Register(&manager_); 90 other_client.Register(&manager_);
91 EXPECT_EQ(client.source(), nullptr); 91 EXPECT_EQ(nullptr, client.source());
92 EXPECT_EQ(other_client.source(), nullptr); 92 EXPECT_EQ(nullptr, other_client.source());
93 93
94 // Test setting unsetting BFS 94 // Test setting unsetting BFS
95 manager_.RegisterBeginFrameSource(&source, client.frame_sink_id()); 95 manager_.RegisterBeginFrameSource(&source, client.frame_sink_id());
96 EXPECT_EQ(client.source(), &source); 96 EXPECT_EQ(&source, client.source());
97 EXPECT_EQ(other_client.source(), nullptr); 97 EXPECT_EQ(nullptr, other_client.source());
98 manager_.UnregisterBeginFrameSource(&source); 98 manager_.UnregisterBeginFrameSource(&source);
99 EXPECT_EQ(client.source(), nullptr); 99 EXPECT_EQ(nullptr, client.source());
100 EXPECT_EQ(other_client.source(), nullptr); 100 EXPECT_EQ(nullptr, other_client.source());
101 101
102 // Set BFS for other namespace 102 // Set BFS for other namespace
103 manager_.RegisterBeginFrameSource(&source, other_client.frame_sink_id()); 103 manager_.RegisterBeginFrameSource(&source, other_client.frame_sink_id());
104 EXPECT_EQ(other_client.source(), &source); 104 EXPECT_EQ(&source, other_client.source());
105 EXPECT_EQ(client.source(), nullptr); 105 EXPECT_EQ(nullptr, client.source());
106 manager_.UnregisterBeginFrameSource(&source); 106 manager_.UnregisterBeginFrameSource(&source);
107 EXPECT_EQ(client.source(), nullptr); 107 EXPECT_EQ(nullptr, client.source());
108 EXPECT_EQ(other_client.source(), nullptr); 108 EXPECT_EQ(nullptr, other_client.source());
109 109
110 // Re-set BFS for original 110 // Re-set BFS for original
111 manager_.RegisterBeginFrameSource(&source, client.frame_sink_id()); 111 manager_.RegisterBeginFrameSource(&source, client.frame_sink_id());
112 EXPECT_EQ(client.source(), &source); 112 EXPECT_EQ(&source, client.source());
113 manager_.UnregisterBeginFrameSource(&source); 113 manager_.UnregisterBeginFrameSource(&source);
114 EXPECT_EQ(client.source(), nullptr); 114 EXPECT_EQ(nullptr, client.source());
115 } 115 }
116 116
117 TEST_F(SurfaceManagerTest, MultipleDisplays) { 117 TEST_F(SurfaceManagerTest, MultipleDisplays) {
118 StubBeginFrameSource root1_source; 118 StubBeginFrameSource root1_source;
119 StubBeginFrameSource root2_source; 119 StubBeginFrameSource root2_source;
120 120
121 // root1 -> A -> B 121 // root1 -> A -> B
122 // root2 -> C 122 // root2 -> C
123 FakeSurfaceFactoryClient root1(FrameSinkId(1, 1), &manager_); 123 FakeSurfaceFactoryClient root1(FrameSinkId(1, 1), &manager_);
124 FakeSurfaceFactoryClient root2(FrameSinkId(2, 2), &manager_); 124 FakeSurfaceFactoryClient root2(FrameSinkId(2, 2), &manager_);
(...skipping 30 matching lines...) Expand all
155 155
156 // Detach A from root1. A and B should now be updated to root2. 156 // Detach A from root1. A and B should now be updated to root2.
157 manager_.UnregisterFrameSinkHierarchy(root1.frame_sink_id(), 157 manager_.UnregisterFrameSinkHierarchy(root1.frame_sink_id(),
158 client_a.frame_sink_id()); 158 client_a.frame_sink_id());
159 EXPECT_EQ(client_a.source(), root2.source()); 159 EXPECT_EQ(client_a.source(), root2.source());
160 EXPECT_EQ(client_b.source(), root2.source()); 160 EXPECT_EQ(client_b.source(), root2.source());
161 EXPECT_EQ(client_c.source(), root2.source()); 161 EXPECT_EQ(client_c.source(), root2.source());
162 162
163 // Detach root1 from BFS. root1 should now have no source. 163 // Detach root1 from BFS. root1 should now have no source.
164 manager_.UnregisterBeginFrameSource(&root1_source); 164 manager_.UnregisterBeginFrameSource(&root1_source);
165 EXPECT_EQ(root1.source(), nullptr); 165 EXPECT_EQ(nullptr, root1.source());
166 EXPECT_NE(root2.source(), nullptr); 166 EXPECT_NE(nullptr, root2.source());
167 167
168 // Detatch root2 from BFS. 168 // Detatch root2 from BFS.
169 manager_.UnregisterBeginFrameSource(&root2_source); 169 manager_.UnregisterBeginFrameSource(&root2_source);
170 EXPECT_EQ(client_a.source(), nullptr); 170 EXPECT_EQ(nullptr, client_a.source());
171 EXPECT_EQ(client_b.source(), nullptr); 171 EXPECT_EQ(nullptr, client_b.source());
172 EXPECT_EQ(client_c.source(), nullptr); 172 EXPECT_EQ(nullptr, client_c.source());
173 EXPECT_EQ(root2.source(), nullptr); 173 EXPECT_EQ(nullptr, root2.source());
174 174
175 // Cleanup hierarchy. 175 // Cleanup hierarchy.
176 manager_.UnregisterFrameSinkHierarchy(root2.frame_sink_id(), 176 manager_.UnregisterFrameSinkHierarchy(root2.frame_sink_id(),
177 client_c.frame_sink_id()); 177 client_c.frame_sink_id());
178 manager_.UnregisterFrameSinkHierarchy(client_c.frame_sink_id(), 178 manager_.UnregisterFrameSinkHierarchy(client_c.frame_sink_id(),
179 client_a.frame_sink_id()); 179 client_a.frame_sink_id());
180 manager_.UnregisterFrameSinkHierarchy(client_a.frame_sink_id(), 180 manager_.UnregisterFrameSinkHierarchy(client_a.frame_sink_id(),
181 client_b.frame_sink_id()); 181 client_b.frame_sink_id());
182 } 182 }
183 183
184 // In practice, registering and unregistering both parent/child relationships 184 // In practice, registering and unregistering both parent/child relationships
185 // and SurfaceFactoryClients can happen in any ordering with respect to 185 // and SurfaceFactoryClients can happen in any ordering with respect to
186 // each other. These following tests verify that all the data structures 186 // each other. These following tests verify that all the data structures
187 // are properly set up and cleaned up under the four permutations of orderings 187 // are properly set up and cleaned up under the four permutations of orderings
188 // of this nesting. 188 // of this nesting.
189 189
190 class SurfaceManagerOrderingTest : public SurfaceManagerTest { 190 class SurfaceManagerOrderingTest : public SurfaceManagerTest {
191 public: 191 public:
192 SurfaceManagerOrderingTest() 192 SurfaceManagerOrderingTest()
193 : client_a_(FrameSinkId(1, 1)), 193 : client_a_(FrameSinkId(1, 1)),
194 client_b_(FrameSinkId(2, 2)), 194 client_b_(FrameSinkId(2, 2)),
195 client_c_(FrameSinkId(3, 3)), 195 client_c_(FrameSinkId(3, 3)),
196 hierarchy_registered_(false), 196 hierarchy_registered_(false),
197 clients_registered_(false), 197 clients_registered_(false),
198 bfs_registered_(false) { 198 bfs_registered_(false) {
199 AssertCorrectBFSState(); 199 AssertCorrectBFSState();
200 } 200 }
201 201
202 ~SurfaceManagerOrderingTest() override { 202 ~SurfaceManagerOrderingTest() override {
203 EXPECT_EQ(hierarchy_registered_, false); 203 EXPECT_FALSE(hierarchy_registered_);
204 EXPECT_EQ(clients_registered_, false); 204 EXPECT_FALSE(clients_registered_);
205 EXPECT_EQ(bfs_registered_, false); 205 EXPECT_FALSE(bfs_registered_);
206 AssertCorrectBFSState(); 206 AssertCorrectBFSState();
207 } 207 }
208 208
209 void RegisterHierarchy() { 209 void RegisterHierarchy() {
210 DCHECK(!hierarchy_registered_); 210 DCHECK(!hierarchy_registered_);
211 hierarchy_registered_ = true; 211 hierarchy_registered_ = true;
212 manager_.RegisterFrameSinkHierarchy(client_a_.frame_sink_id(), 212 manager_.RegisterFrameSinkHierarchy(client_a_.frame_sink_id(),
213 client_b_.frame_sink_id()); 213 client_b_.frame_sink_id());
214 manager_.RegisterFrameSinkHierarchy(client_b_.frame_sink_id(), 214 manager_.RegisterFrameSinkHierarchy(client_b_.frame_sink_id(),
215 client_c_.frame_sink_id()); 215 client_c_.frame_sink_id());
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 AssertCorrectBFSState(); 250 AssertCorrectBFSState();
251 } 251 }
252 void UnregisterBFS() { 252 void UnregisterBFS() {
253 DCHECK(bfs_registered_); 253 DCHECK(bfs_registered_);
254 bfs_registered_ = false; 254 bfs_registered_ = false;
255 manager_.UnregisterBeginFrameSource(&source_); 255 manager_.UnregisterBeginFrameSource(&source_);
256 AssertCorrectBFSState(); 256 AssertCorrectBFSState();
257 } 257 }
258 258
259 void AssertEmptyBFS() { 259 void AssertEmptyBFS() {
260 EXPECT_EQ(client_a_.source(), nullptr); 260 EXPECT_EQ(nullptr, client_a_.source());
261 EXPECT_EQ(client_b_.source(), nullptr); 261 EXPECT_EQ(nullptr, client_b_.source());
262 EXPECT_EQ(client_c_.source(), nullptr); 262 EXPECT_EQ(nullptr, client_c_.source());
263 } 263 }
264 264
265 void AssertAllValidBFS() { 265 void AssertAllValidBFS() {
266 EXPECT_EQ(client_a_.source(), &source_); 266 EXPECT_EQ(&source_, client_a_.source());
267 EXPECT_EQ(client_b_.source(), &source_); 267 EXPECT_EQ(&source_, client_b_.source());
268 EXPECT_EQ(client_c_.source(), &source_); 268 EXPECT_EQ(&source_, client_c_.source());
269 } 269 }
270 270
271 protected: 271 protected:
272 void AssertCorrectBFSState() { 272 void AssertCorrectBFSState() {
273 if (!clients_registered_ || !bfs_registered_) { 273 if (!clients_registered_ || !bfs_registered_) {
274 AssertEmptyBFS(); 274 AssertEmptyBFS();
275 return; 275 return;
276 } 276 }
277 if (!hierarchy_registered_) { 277 if (!hierarchy_registered_) {
278 // A valid but not attached to anything. 278 // A valid but not attached to anything.
279 EXPECT_EQ(client_a_.source(), &source_); 279 EXPECT_EQ(&source_, client_a_.source());
280 EXPECT_EQ(client_b_.source(), nullptr); 280 EXPECT_EQ(nullptr, client_b_.source());
281 EXPECT_EQ(client_c_.source(), nullptr); 281 EXPECT_EQ(nullptr, client_c_.source());
282 return; 282 return;
283 } 283 }
284 284
285 AssertAllValidBFS(); 285 AssertAllValidBFS();
286 } 286 }
287 287
288 StubBeginFrameSource source_; 288 StubBeginFrameSource source_;
289 // A -> B -> C hierarchy, with A always having the BFS. 289 // A -> B -> C hierarchy, with A always having the BFS.
290 FakeSurfaceFactoryClient client_a_; 290 FakeSurfaceFactoryClient client_a_;
291 FakeSurfaceFactoryClient client_b_; 291 FakeSurfaceFactoryClient client_b_;
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 } 366 }
367 367
368 INSTANTIATE_TEST_CASE_P( 368 INSTANTIATE_TEST_CASE_P(
369 SurfaceManagerOrderingParamTestInstantiation, 369 SurfaceManagerOrderingParamTestInstantiation,
370 SurfaceManagerOrderingParamTest, 370 SurfaceManagerOrderingParamTest,
371 ::testing::Combine(::testing::ValuesIn(kRegisterOrderList), 371 ::testing::Combine(::testing::ValuesIn(kRegisterOrderList),
372 ::testing::ValuesIn(kUnregisterOrderList), 372 ::testing::ValuesIn(kUnregisterOrderList),
373 ::testing::ValuesIn(kBFSOrderList))); 373 ::testing::ValuesIn(kBFSOrderList)));
374 374
375 } // namespace cc 375 } // namespace cc
OLDNEW
« no previous file with comments | « cc/surfaces/surface_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698