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

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

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

Powered by Google App Engine
This is Rietveld 408576698