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

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

Issue 2795683003: [cc]Replace use of SurfaceFactory with CompositorFrameSinkSupport in tests (Closed)
Patch Set: Fix SurfaceManagerRefTest 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 namespace {
13 14
14 class FakeSurfaceFactoryClient : public SurfaceFactoryClient { 15 constexpr bool kIsRoot = true;
15 public: 16 constexpr bool kIsChildRoot = false;
16 explicit FakeSurfaceFactoryClient(const FrameSinkId& frame_sink_id) 17 constexpr bool kHandlesFrameSinkIdInvalidation = false;
17 : source_(nullptr), manager_(nullptr), frame_sink_id_(frame_sink_id) {} 18 constexpr bool kNeedsSyncPoints = true;
19 constexpr FrameSinkId kFrameSinkIdA = FrameSinkId(1, 1);
20 constexpr FrameSinkId kFrameSinkIdB = FrameSinkId(2, 2);
21 constexpr FrameSinkId kFrameSinkIdC = FrameSinkId(3, 3);
18 22
19 FakeSurfaceFactoryClient(const FrameSinkId& frame_sink_id, 23 } // namespace
danakj 2017/04/07 15:52:45 we usually wrap the whole test file in anon namesp
Alex Z. 2017/04/07 20:43:58 Done.
20 SurfaceManager* manager)
21 : source_(nullptr), manager_(nullptr), frame_sink_id_(frame_sink_id) {
22 DCHECK(manager);
23 Register(manager);
24 }
25
26 ~FakeSurfaceFactoryClient() override {
27 if (manager_) {
28 Unregister();
29 }
30 EXPECT_EQ(nullptr, source_);
31 }
32
33 BeginFrameSource* source() { return source_; }
34 const FrameSinkId& frame_sink_id() { return frame_sink_id_; }
35
36 void Register(SurfaceManager* manager) {
37 EXPECT_EQ(nullptr, manager_);
38 manager_ = manager;
39 manager_->RegisterSurfaceFactoryClient(frame_sink_id_, this);
40 }
41
42 void Unregister() {
43 EXPECT_NE(manager_, nullptr);
44 manager_->UnregisterSurfaceFactoryClient(frame_sink_id_);
45 manager_ = nullptr;
46 }
47
48 // SurfaceFactoryClient implementation.
49 void ReturnResources(const ReturnedResourceArray& resources) override {}
50 void SetBeginFrameSource(BeginFrameSource* begin_frame_source) override {
51 DCHECK(!source_ || !begin_frame_source);
52 source_ = begin_frame_source;
53 };
54
55 private:
56 BeginFrameSource* source_;
57 SurfaceManager* manager_;
58 FrameSinkId frame_sink_id_;
59 };
60 24
61 class SurfaceManagerTest : public testing::Test { 25 class SurfaceManagerTest : public testing::Test {
62 public: 26 public:
63 // These tests don't care about namespace registration, so just preregister 27 // 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 28 // a set of namespaces that tests can use freely without worrying if they're
65 // valid or not. 29 // valid or not.
66 enum { MAX_FRAME_SINK = 10 }; 30 enum { MAX_FRAME_SINK = 10 };
67 31
68 SurfaceManagerTest() { 32 SurfaceManagerTest() {
69 for (size_t i = 0; i < MAX_FRAME_SINK; ++i) 33 for (size_t i = 0; i < MAX_FRAME_SINK; ++i)
70 manager_.RegisterFrameSinkId(FrameSinkId(i, i)); 34 manager_.RegisterFrameSinkId(FrameSinkId(i, i));
71 } 35 }
72 36
73 ~SurfaceManagerTest() override { 37 ~SurfaceManagerTest() override {
74 for (size_t i = 0; i < MAX_FRAME_SINK; ++i) 38 for (size_t i = 0; i < MAX_FRAME_SINK; ++i)
75 manager_.InvalidateFrameSinkId(FrameSinkId(i, i)); 39 manager_.InvalidateFrameSinkId(FrameSinkId(i, i));
76 } 40 }
77 41
78 protected: 42 protected:
79 SurfaceManager manager_; 43 SurfaceManager manager_;
80 }; 44 };
81 45
82 TEST_F(SurfaceManagerTest, SingleClients) { 46 TEST_F(SurfaceManagerTest, SingleClients) {
83 FakeSurfaceFactoryClient client(FrameSinkId(1, 1)); 47 CompositorFrameSinkSupport client(
84 FakeSurfaceFactoryClient other_client(FrameSinkId(2, 2)); 48 nullptr, &manager_, FrameSinkId(1, 1), kIsChildRoot,
49 kHandlesFrameSinkIdInvalidation, kNeedsSyncPoints);
50 CompositorFrameSinkSupport other_client(
51 nullptr, &manager_, FrameSinkId(2, 2), kIsChildRoot,
52 kHandlesFrameSinkIdInvalidation, kNeedsSyncPoints);
85 StubBeginFrameSource source; 53 StubBeginFrameSource source;
86 54
87 EXPECT_EQ(nullptr, client.source()); 55 EXPECT_EQ(nullptr, client.BeginFrameSourceForTesting());
danakj 2017/04/07 15:52:45 I don't think you need to add a ForTesting() metho
Alex Z. 2017/04/07 20:43:58 I added a mock class (see the next patchset) but i
danakj 2017/04/07 21:16:17 Does this imply that virtual methods on Compositor
Alex Z. 2017/04/07 21:29:01 MockCompositorFrameSinkSupport is a friend of Com
88 EXPECT_EQ(nullptr, other_client.source()); 56 EXPECT_EQ(nullptr, other_client.BeginFrameSourceForTesting());
89 client.Register(&manager_);
90 other_client.Register(&manager_);
91 EXPECT_EQ(nullptr, client.source());
92 EXPECT_EQ(nullptr, other_client.source());
93 57
94 // Test setting unsetting BFS 58 // Test setting unsetting BFS
95 manager_.RegisterBeginFrameSource(&source, client.frame_sink_id()); 59 manager_.RegisterBeginFrameSource(&source, client.frame_sink_id());
96 EXPECT_EQ(&source, client.source()); 60 EXPECT_EQ(&source, client.BeginFrameSourceForTesting());
97 EXPECT_EQ(nullptr, other_client.source()); 61 EXPECT_EQ(nullptr, other_client.BeginFrameSourceForTesting());
98 manager_.UnregisterBeginFrameSource(&source); 62 manager_.UnregisterBeginFrameSource(&source);
99 EXPECT_EQ(nullptr, client.source()); 63 EXPECT_EQ(nullptr, client.BeginFrameSourceForTesting());
100 EXPECT_EQ(nullptr, other_client.source()); 64 EXPECT_EQ(nullptr, other_client.BeginFrameSourceForTesting());
101 65
102 // Set BFS for other namespace 66 // Set BFS for other namespace
103 manager_.RegisterBeginFrameSource(&source, other_client.frame_sink_id()); 67 manager_.RegisterBeginFrameSource(&source, other_client.frame_sink_id());
104 EXPECT_EQ(&source, other_client.source()); 68 EXPECT_EQ(&source, other_client.BeginFrameSourceForTesting());
105 EXPECT_EQ(nullptr, client.source()); 69 EXPECT_EQ(nullptr, client.BeginFrameSourceForTesting());
106 manager_.UnregisterBeginFrameSource(&source); 70 manager_.UnregisterBeginFrameSource(&source);
107 EXPECT_EQ(nullptr, client.source()); 71 EXPECT_EQ(nullptr, client.BeginFrameSourceForTesting());
108 EXPECT_EQ(nullptr, other_client.source()); 72 EXPECT_EQ(nullptr, other_client.BeginFrameSourceForTesting());
109 73
110 // Re-set BFS for original 74 // Re-set BFS for original
111 manager_.RegisterBeginFrameSource(&source, client.frame_sink_id()); 75 manager_.RegisterBeginFrameSource(&source, client.frame_sink_id());
112 EXPECT_EQ(&source, client.source()); 76 EXPECT_EQ(&source, client.BeginFrameSourceForTesting());
113 manager_.UnregisterBeginFrameSource(&source); 77 manager_.UnregisterBeginFrameSource(&source);
114 EXPECT_EQ(nullptr, client.source()); 78 EXPECT_EQ(nullptr, client.BeginFrameSourceForTesting());
115 } 79 }
116 80
117 TEST_F(SurfaceManagerTest, MultipleDisplays) { 81 TEST_F(SurfaceManagerTest, MultipleDisplays) {
118 StubBeginFrameSource root1_source; 82 StubBeginFrameSource root1_source;
119 StubBeginFrameSource root2_source; 83 StubBeginFrameSource root2_source;
120 84
121 // root1 -> A -> B 85 // root1 -> A -> B
122 // root2 -> C 86 // root2 -> C
123 FakeSurfaceFactoryClient root1(FrameSinkId(1, 1), &manager_); 87 CompositorFrameSinkSupport root1(nullptr, &manager_, FrameSinkId(1, 1),
124 FakeSurfaceFactoryClient root2(FrameSinkId(2, 2), &manager_); 88 kIsRoot, kHandlesFrameSinkIdInvalidation,
125 FakeSurfaceFactoryClient client_a(FrameSinkId(3, 3), &manager_); 89 kNeedsSyncPoints);
126 FakeSurfaceFactoryClient client_b(FrameSinkId(4, 4), &manager_); 90 CompositorFrameSinkSupport root2(nullptr, &manager_, FrameSinkId(2, 2),
127 FakeSurfaceFactoryClient client_c(FrameSinkId(5, 5), &manager_); 91 kIsRoot, kHandlesFrameSinkIdInvalidation,
92 kNeedsSyncPoints);
93 CompositorFrameSinkSupport client_a(
94 nullptr, &manager_, FrameSinkId(3, 3), kIsChildRoot,
95 kHandlesFrameSinkIdInvalidation, kNeedsSyncPoints);
96 CompositorFrameSinkSupport client_b(
97 nullptr, &manager_, FrameSinkId(4, 4), kIsChildRoot,
98 kHandlesFrameSinkIdInvalidation, kNeedsSyncPoints);
99 CompositorFrameSinkSupport client_c(
100 nullptr, &manager_, FrameSinkId(5, 5), kIsChildRoot,
101 kHandlesFrameSinkIdInvalidation, kNeedsSyncPoints);
128 102
129 manager_.RegisterBeginFrameSource(&root1_source, root1.frame_sink_id()); 103 manager_.RegisterBeginFrameSource(&root1_source, root1.frame_sink_id());
130 manager_.RegisterBeginFrameSource(&root2_source, root2.frame_sink_id()); 104 manager_.RegisterBeginFrameSource(&root2_source, root2.frame_sink_id());
131 EXPECT_EQ(root1.source(), &root1_source); 105 EXPECT_EQ(root1.BeginFrameSourceForTesting(), &root1_source);
132 EXPECT_EQ(root2.source(), &root2_source); 106 EXPECT_EQ(root2.BeginFrameSourceForTesting(), &root2_source);
133 107
134 // Set up initial hierarchy. 108 // Set up initial hierarchy.
135 manager_.RegisterFrameSinkHierarchy(root1.frame_sink_id(), 109 manager_.RegisterFrameSinkHierarchy(root1.frame_sink_id(),
136 client_a.frame_sink_id()); 110 client_a.frame_sink_id());
137 EXPECT_EQ(client_a.source(), root1.source()); 111 EXPECT_EQ(client_a.BeginFrameSourceForTesting(),
112 root1.BeginFrameSourceForTesting());
138 manager_.RegisterFrameSinkHierarchy(client_a.frame_sink_id(), 113 manager_.RegisterFrameSinkHierarchy(client_a.frame_sink_id(),
139 client_b.frame_sink_id()); 114 client_b.frame_sink_id());
140 EXPECT_EQ(client_b.source(), root1.source()); 115 EXPECT_EQ(client_b.BeginFrameSourceForTesting(),
116 root1.BeginFrameSourceForTesting());
141 manager_.RegisterFrameSinkHierarchy(root2.frame_sink_id(), 117 manager_.RegisterFrameSinkHierarchy(root2.frame_sink_id(),
142 client_c.frame_sink_id()); 118 client_c.frame_sink_id());
143 EXPECT_EQ(client_c.source(), root2.source()); 119 EXPECT_EQ(client_c.BeginFrameSourceForTesting(),
120 root2.BeginFrameSourceForTesting());
144 121
145 // Attach A into root2's subtree, like a window moving across displays. 122 // Attach A into root2's subtree, like a window moving across displays.
146 // root1 -> A -> B 123 // root1 -> A -> B
147 // root2 -> C -> A -> B 124 // root2 -> C -> A -> B
148 manager_.RegisterFrameSinkHierarchy(client_c.frame_sink_id(), 125 manager_.RegisterFrameSinkHierarchy(client_c.frame_sink_id(),
149 client_a.frame_sink_id()); 126 client_a.frame_sink_id());
150 // With the heuristic of just keeping existing BFS in the face of multiple, 127 // With the heuristic of just keeping existing BFS in the face of multiple,
151 // no client sources should change. 128 // no client sources should change.
152 EXPECT_EQ(client_a.source(), root1.source()); 129 EXPECT_EQ(client_a.BeginFrameSourceForTesting(),
153 EXPECT_EQ(client_b.source(), root1.source()); 130 root1.BeginFrameSourceForTesting());
154 EXPECT_EQ(client_c.source(), root2.source()); 131 EXPECT_EQ(client_b.BeginFrameSourceForTesting(),
132 root1.BeginFrameSourceForTesting());
133 EXPECT_EQ(client_c.BeginFrameSourceForTesting(),
134 root2.BeginFrameSourceForTesting());
155 135
156 // Detach A from root1. A and B should now be updated to root2. 136 // Detach A from root1. A and B should now be updated to root2.
157 manager_.UnregisterFrameSinkHierarchy(root1.frame_sink_id(), 137 manager_.UnregisterFrameSinkHierarchy(root1.frame_sink_id(),
158 client_a.frame_sink_id()); 138 client_a.frame_sink_id());
159 EXPECT_EQ(client_a.source(), root2.source()); 139 EXPECT_EQ(client_a.BeginFrameSourceForTesting(),
160 EXPECT_EQ(client_b.source(), root2.source()); 140 root2.BeginFrameSourceForTesting());
161 EXPECT_EQ(client_c.source(), root2.source()); 141 EXPECT_EQ(client_b.BeginFrameSourceForTesting(),
142 root2.BeginFrameSourceForTesting());
143 EXPECT_EQ(client_c.BeginFrameSourceForTesting(),
144 root2.BeginFrameSourceForTesting());
162 145
163 // Detach root1 from BFS. root1 should now have no source. 146 // Detach root1 from BFS. root1 should now have no source.
164 manager_.UnregisterBeginFrameSource(&root1_source); 147 manager_.UnregisterBeginFrameSource(&root1_source);
165 EXPECT_EQ(nullptr, root1.source()); 148 EXPECT_EQ(nullptr, root1.BeginFrameSourceForTesting());
166 EXPECT_NE(nullptr, root2.source()); 149 EXPECT_NE(nullptr, root2.BeginFrameSourceForTesting());
167 150
168 // Detatch root2 from BFS. 151 // Detatch root2 from BFS.
169 manager_.UnregisterBeginFrameSource(&root2_source); 152 manager_.UnregisterBeginFrameSource(&root2_source);
170 EXPECT_EQ(nullptr, client_a.source()); 153 EXPECT_EQ(nullptr, client_a.BeginFrameSourceForTesting());
171 EXPECT_EQ(nullptr, client_b.source()); 154 EXPECT_EQ(nullptr, client_b.BeginFrameSourceForTesting());
172 EXPECT_EQ(nullptr, client_c.source()); 155 EXPECT_EQ(nullptr, client_c.BeginFrameSourceForTesting());
173 EXPECT_EQ(nullptr, root2.source()); 156 EXPECT_EQ(nullptr, root2.BeginFrameSourceForTesting());
174 157
175 // Cleanup hierarchy. 158 // Cleanup hierarchy.
176 manager_.UnregisterFrameSinkHierarchy(root2.frame_sink_id(), 159 manager_.UnregisterFrameSinkHierarchy(root2.frame_sink_id(),
177 client_c.frame_sink_id()); 160 client_c.frame_sink_id());
178 manager_.UnregisterFrameSinkHierarchy(client_c.frame_sink_id(), 161 manager_.UnregisterFrameSinkHierarchy(client_c.frame_sink_id(),
179 client_a.frame_sink_id()); 162 client_a.frame_sink_id());
180 manager_.UnregisterFrameSinkHierarchy(client_a.frame_sink_id(), 163 manager_.UnregisterFrameSinkHierarchy(client_a.frame_sink_id(),
181 client_b.frame_sink_id()); 164 client_b.frame_sink_id());
182 } 165 }
183 166
184 // This test verifies that a BeginFrameSource path to the root from a 167 // This test verifies that a BeginFrameSource path to the root from a
185 // FrameSinkId is preserved even if that FrameSinkId has no children 168 // FrameSinkId is preserved even if that FrameSinkId has no children
186 // and does not have a corresponding SurfaceFactoryClient. 169 // and does not have a corresponding SurfaceFactoryClient.
187 TEST_F(SurfaceManagerTest, ParentWithoutClientRetained) { 170 TEST_F(SurfaceManagerTest, ParentWithoutClientRetained) {
188 StubBeginFrameSource root_source; 171 StubBeginFrameSource root_source;
189 172
190 constexpr FrameSinkId kFrameSinkIdRoot(1, 1); 173 constexpr FrameSinkId kFrameSinkIdRoot(1, 1);
191 constexpr FrameSinkId kFrameSinkIdA(2, 2); 174 constexpr FrameSinkId kFrameSinkIdA(2, 2);
192 constexpr FrameSinkId kFrameSinkIdB(3, 3); 175 constexpr FrameSinkId kFrameSinkIdB(3, 3);
193 constexpr FrameSinkId kFrameSinkIdC(4, 4); 176 constexpr FrameSinkId kFrameSinkIdC(4, 4);
194 177
195 FakeSurfaceFactoryClient root(kFrameSinkIdRoot, &manager_); 178 CompositorFrameSinkSupport root(nullptr, &manager_, kFrameSinkIdRoot, kIsRoot,
196 FakeSurfaceFactoryClient client_b(kFrameSinkIdB, &manager_); 179 kHandlesFrameSinkIdInvalidation,
197 FakeSurfaceFactoryClient client_c(kFrameSinkIdC, &manager_); 180 kNeedsSyncPoints);
181 CompositorFrameSinkSupport client_b(
182 nullptr, &manager_, kFrameSinkIdB, kIsChildRoot,
183 kHandlesFrameSinkIdInvalidation, kNeedsSyncPoints);
184 CompositorFrameSinkSupport client_c(
185 nullptr, &manager_, kFrameSinkIdC, kIsChildRoot,
186 kHandlesFrameSinkIdInvalidation, kNeedsSyncPoints);
198 187
199 manager_.RegisterBeginFrameSource(&root_source, root.frame_sink_id()); 188 manager_.RegisterBeginFrameSource(&root_source, root.frame_sink_id());
200 EXPECT_EQ(&root_source, root.source()); 189 EXPECT_EQ(&root_source, root.BeginFrameSourceForTesting());
201 190
202 // Set up initial hierarchy: root -> A -> B. 191 // Set up initial hierarchy: root -> A -> B.
203 // Note that A does not have a SurfaceFactoryClient. 192 // Note that A does not have a SurfaceFactoryClient.
204 manager_.RegisterFrameSinkHierarchy(kFrameSinkIdRoot, kFrameSinkIdA); 193 manager_.RegisterFrameSinkHierarchy(kFrameSinkIdRoot, kFrameSinkIdA);
205 manager_.RegisterFrameSinkHierarchy(kFrameSinkIdA, kFrameSinkIdB); 194 manager_.RegisterFrameSinkHierarchy(kFrameSinkIdA, kFrameSinkIdB);
206 // The root's BeginFrameSource should propagate to B. 195 // The root's BeginFrameSource should propagate to B.
207 EXPECT_EQ(root.source(), client_b.source()); 196 EXPECT_EQ(root.BeginFrameSourceForTesting(),
197 client_b.BeginFrameSourceForTesting());
208 198
209 // Unregister B, and attach C to A: root -> A -> C 199 // Unregister B, and attach C to A: root -> A -> C
210 manager_.UnregisterFrameSinkHierarchy(kFrameSinkIdA, kFrameSinkIdB); 200 manager_.UnregisterFrameSinkHierarchy(kFrameSinkIdA, kFrameSinkIdB);
211 EXPECT_EQ(nullptr, client_b.source()); 201 EXPECT_EQ(nullptr, client_b.BeginFrameSourceForTesting());
212 manager_.RegisterFrameSinkHierarchy(kFrameSinkIdA, kFrameSinkIdC); 202 manager_.RegisterFrameSinkHierarchy(kFrameSinkIdA, kFrameSinkIdC);
213 // The root's BeginFrameSource should propagate to C. 203 // The root's BeginFrameSource should propagate to C.
214 EXPECT_EQ(root.source(), client_c.source()); 204 EXPECT_EQ(root.BeginFrameSourceForTesting(),
205 client_c.BeginFrameSourceForTesting());
215 206
216 manager_.UnregisterBeginFrameSource(&root_source); 207 manager_.UnregisterBeginFrameSource(&root_source);
217 EXPECT_EQ(nullptr, root.source()); 208 EXPECT_EQ(nullptr, root.BeginFrameSourceForTesting());
218 EXPECT_EQ(nullptr, client_c.source()); 209 EXPECT_EQ(nullptr, client_c.BeginFrameSourceForTesting());
219 } 210 }
220 211
221 // This test sets up the same hierarchy as ParentWithoutClientRetained. 212 // This test sets up the same hierarchy as ParentWithoutClientRetained.
222 // However, this unit test registers the BeginFrameSource AFTER C 213 // However, this unit test registers the BeginFrameSource AFTER C
223 // has been attached to A. This test verifies that the BeginFrameSource 214 // has been attached to A. This test verifies that the BeginFrameSource
224 // propagates all the way to C. 215 // propagates all the way to C.
225 TEST_F(SurfaceManagerTest, 216 TEST_F(SurfaceManagerTest,
226 ParentWithoutClientRetained_LateBeginFrameRegistration) { 217 ParentWithoutClientRetained_LateBeginFrameRegistration) {
227 StubBeginFrameSource root_source; 218 StubBeginFrameSource root_source;
228 219
229 constexpr FrameSinkId kFrameSinkIdRoot(1, 1); 220 constexpr FrameSinkId kFrameSinkIdRoot(1, 1);
230 constexpr FrameSinkId kFrameSinkIdA(2, 2); 221 constexpr FrameSinkId kFrameSinkIdA(2, 2);
231 constexpr FrameSinkId kFrameSinkIdB(3, 3); 222 constexpr FrameSinkId kFrameSinkIdB(3, 3);
232 constexpr FrameSinkId kFrameSinkIdC(4, 4); 223 constexpr FrameSinkId kFrameSinkIdC(4, 4);
233 224
234 FakeSurfaceFactoryClient root(kFrameSinkIdRoot, &manager_); 225 CompositorFrameSinkSupport root(nullptr, &manager_, kFrameSinkIdRoot, kIsRoot,
235 FakeSurfaceFactoryClient client_b(kFrameSinkIdB, &manager_); 226 kHandlesFrameSinkIdInvalidation,
236 FakeSurfaceFactoryClient client_c(kFrameSinkIdC, &manager_); 227 kNeedsSyncPoints);
228 CompositorFrameSinkSupport client_b(
229 nullptr, &manager_, kFrameSinkIdB, kIsChildRoot,
230 kHandlesFrameSinkIdInvalidation, kNeedsSyncPoints);
231 CompositorFrameSinkSupport client_c(
232 nullptr, &manager_, kFrameSinkIdC, kIsChildRoot,
233 kHandlesFrameSinkIdInvalidation, kNeedsSyncPoints);
237 234
238 // Set up initial hierarchy: root -> A -> B. 235 // Set up initial hierarchy: root -> A -> B.
239 // Note that A does not have a SurfaceFactoryClient. 236 // Note that A does not have a SurfaceFactoryClient.
240 manager_.RegisterFrameSinkHierarchy(kFrameSinkIdRoot, kFrameSinkIdA); 237 manager_.RegisterFrameSinkHierarchy(kFrameSinkIdRoot, kFrameSinkIdA);
241 manager_.RegisterFrameSinkHierarchy(kFrameSinkIdA, kFrameSinkIdB); 238 manager_.RegisterFrameSinkHierarchy(kFrameSinkIdA, kFrameSinkIdB);
242 // The root does not yet have a BeginFrameSource so client B should not have 239 // The root does not yet have a BeginFrameSource so client B should not have
243 // one either. 240 // one either.
244 EXPECT_EQ(nullptr, client_b.source()); 241 EXPECT_EQ(nullptr, client_b.BeginFrameSourceForTesting());
245 242
246 // Unregister B, and attach C to A: root -> A -> C 243 // Unregister B, and attach C to A: root -> A -> C
247 manager_.UnregisterFrameSinkHierarchy(kFrameSinkIdA, kFrameSinkIdB); 244 manager_.UnregisterFrameSinkHierarchy(kFrameSinkIdA, kFrameSinkIdB);
248 manager_.RegisterFrameSinkHierarchy(kFrameSinkIdA, kFrameSinkIdC); 245 manager_.RegisterFrameSinkHierarchy(kFrameSinkIdA, kFrameSinkIdC);
249 246
250 // Registering a BeginFrameSource at the root should propagate it to C. 247 // Registering a BeginFrameSource at the root should propagate it to C.
251 manager_.RegisterBeginFrameSource(&root_source, root.frame_sink_id()); 248 manager_.RegisterBeginFrameSource(&root_source, root.frame_sink_id());
252 // The root's BeginFrameSource should propagate to C. 249 // The root's BeginFrameSource should propagate to C.
253 EXPECT_EQ(&root_source, root.source()); 250 EXPECT_EQ(&root_source, root.BeginFrameSourceForTesting());
254 EXPECT_EQ(root.source(), client_c.source()); 251 EXPECT_EQ(root.BeginFrameSourceForTesting(),
252 client_c.BeginFrameSourceForTesting());
255 253
256 manager_.UnregisterBeginFrameSource(&root_source); 254 manager_.UnregisterBeginFrameSource(&root_source);
257 EXPECT_EQ(nullptr, root.source()); 255 EXPECT_EQ(nullptr, root.BeginFrameSourceForTesting());
258 EXPECT_EQ(nullptr, client_c.source()); 256 EXPECT_EQ(nullptr, client_c.BeginFrameSourceForTesting());
259 } 257 }
260 258
261 // In practice, registering and unregistering both parent/child relationships 259 // In practice, registering and unregistering both parent/child relationships
262 // and SurfaceFactoryClients can happen in any ordering with respect to 260 // and SurfaceFactoryClients can happen in any ordering with respect to
263 // each other. These following tests verify that all the data structures 261 // 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 262 // are properly set up and cleaned up under the four permutations of orderings
265 // of this nesting. 263 // of this nesting.
266 264
267 class SurfaceManagerOrderingTest : public SurfaceManagerTest { 265 class SurfaceManagerOrderingTest : public SurfaceManagerTest {
268 public: 266 public:
269 SurfaceManagerOrderingTest() 267 SurfaceManagerOrderingTest()
270 : client_a_(FrameSinkId(1, 1)), 268 : hierarchy_registered_(false),
271 client_b_(FrameSinkId(2, 2)),
272 client_c_(FrameSinkId(3, 3)),
273 hierarchy_registered_(false),
274 clients_registered_(false), 269 clients_registered_(false),
275 bfs_registered_(false) { 270 bfs_registered_(false) {
276 AssertCorrectBFSState(); 271 AssertCorrectBFSState();
277 } 272 }
278 273
279 ~SurfaceManagerOrderingTest() override { 274 ~SurfaceManagerOrderingTest() override {
280 EXPECT_FALSE(hierarchy_registered_); 275 EXPECT_FALSE(hierarchy_registered_);
281 EXPECT_FALSE(clients_registered_); 276 EXPECT_FALSE(clients_registered_);
282 EXPECT_FALSE(bfs_registered_); 277 EXPECT_FALSE(bfs_registered_);
283 AssertCorrectBFSState(); 278 AssertCorrectBFSState();
284 } 279 }
285 280
286 void RegisterHierarchy() { 281 void RegisterHierarchy() {
287 DCHECK(!hierarchy_registered_); 282 DCHECK(!hierarchy_registered_);
288 hierarchy_registered_ = true; 283 hierarchy_registered_ = true;
289 manager_.RegisterFrameSinkHierarchy(client_a_.frame_sink_id(), 284 manager_.RegisterFrameSinkHierarchy(kFrameSinkIdA, kFrameSinkIdB);
290 client_b_.frame_sink_id()); 285 manager_.RegisterFrameSinkHierarchy(kFrameSinkIdB, kFrameSinkIdC);
291 manager_.RegisterFrameSinkHierarchy(client_b_.frame_sink_id(),
292 client_c_.frame_sink_id());
293 AssertCorrectBFSState(); 286 AssertCorrectBFSState();
294 } 287 }
295 void UnregisterHierarchy() { 288 void UnregisterHierarchy() {
296 DCHECK(hierarchy_registered_); 289 DCHECK(hierarchy_registered_);
297 hierarchy_registered_ = false; 290 hierarchy_registered_ = false;
298 manager_.UnregisterFrameSinkHierarchy(client_a_.frame_sink_id(), 291 manager_.UnregisterFrameSinkHierarchy(kFrameSinkIdA, kFrameSinkIdB);
299 client_b_.frame_sink_id()); 292 manager_.UnregisterFrameSinkHierarchy(kFrameSinkIdB, kFrameSinkIdC);
300 manager_.UnregisterFrameSinkHierarchy(client_b_.frame_sink_id(),
301 client_c_.frame_sink_id());
302 AssertCorrectBFSState(); 293 AssertCorrectBFSState();
303 } 294 }
304 295
305 void RegisterClients() { 296 void RegisterClients() {
306 DCHECK(!clients_registered_); 297 DCHECK(!clients_registered_);
307 clients_registered_ = true; 298 clients_registered_ = true;
308 client_a_.Register(&manager_); 299 client_a_ = base::MakeUnique<CompositorFrameSinkSupport>(
309 client_b_.Register(&manager_); 300 nullptr, &manager_, kFrameSinkIdA, kIsRoot,
310 client_c_.Register(&manager_); 301 kHandlesFrameSinkIdInvalidation, kNeedsSyncPoints);
302 client_b_ = base::MakeUnique<CompositorFrameSinkSupport>(
303 nullptr, &manager_, kFrameSinkIdB, kIsChildRoot,
304 kHandlesFrameSinkIdInvalidation, kNeedsSyncPoints);
305 client_c_ = base::MakeUnique<CompositorFrameSinkSupport>(
306 nullptr, &manager_, kFrameSinkIdC, kIsChildRoot,
307 kHandlesFrameSinkIdInvalidation, kNeedsSyncPoints);
311 AssertCorrectBFSState(); 308 AssertCorrectBFSState();
312 } 309 }
313 310
314 void UnregisterClients() { 311 void UnregisterClients() {
315 DCHECK(clients_registered_); 312 DCHECK(clients_registered_);
316 clients_registered_ = false; 313 clients_registered_ = false;
317 client_a_.Unregister(); 314 client_a_.reset();
318 client_b_.Unregister(); 315 client_b_.reset();
319 client_c_.Unregister(); 316 client_c_.reset();
320 AssertCorrectBFSState(); 317 AssertCorrectBFSState();
321 } 318 }
322 319
323 void RegisterBFS() { 320 void RegisterBFS() {
324 DCHECK(!bfs_registered_); 321 DCHECK(!bfs_registered_);
325 bfs_registered_ = true; 322 bfs_registered_ = true;
326 manager_.RegisterBeginFrameSource(&source_, client_a_.frame_sink_id()); 323 manager_.RegisterBeginFrameSource(&source_, kFrameSinkIdA);
327 AssertCorrectBFSState(); 324 AssertCorrectBFSState();
328 } 325 }
329 void UnregisterBFS() { 326 void UnregisterBFS() {
330 DCHECK(bfs_registered_); 327 DCHECK(bfs_registered_);
331 bfs_registered_ = false; 328 bfs_registered_ = false;
332 manager_.UnregisterBeginFrameSource(&source_); 329 manager_.UnregisterBeginFrameSource(&source_);
333 AssertCorrectBFSState(); 330 AssertCorrectBFSState();
334 } 331 }
335 332
336 void AssertEmptyBFS() { 333 void AssertEmptyBFS() {
337 EXPECT_EQ(nullptr, client_a_.source()); 334 EXPECT_TRUE(!client_a_ || !client_a_->BeginFrameSourceForTesting());
338 EXPECT_EQ(nullptr, client_b_.source()); 335 EXPECT_TRUE(!client_b_ || !client_b_->BeginFrameSourceForTesting());
339 EXPECT_EQ(nullptr, client_c_.source()); 336 EXPECT_TRUE(!client_c_ || !client_c_->BeginFrameSourceForTesting());
340 } 337 }
341 338
342 void AssertAllValidBFS() { 339 void AssertAllValidBFS() {
343 EXPECT_EQ(&source_, client_a_.source()); 340 EXPECT_EQ(&source_, client_a_->BeginFrameSourceForTesting());
344 EXPECT_EQ(&source_, client_b_.source()); 341 EXPECT_EQ(&source_, client_b_->BeginFrameSourceForTesting());
345 EXPECT_EQ(&source_, client_c_.source()); 342 EXPECT_EQ(&source_, client_c_->BeginFrameSourceForTesting());
346 } 343 }
347 344
348 protected: 345 protected:
349 void AssertCorrectBFSState() { 346 void AssertCorrectBFSState() {
350 if (!clients_registered_ || !bfs_registered_) { 347 if (!clients_registered_ || !bfs_registered_) {
351 AssertEmptyBFS(); 348 AssertEmptyBFS();
352 return; 349 return;
353 } 350 }
354 if (!hierarchy_registered_) { 351 if (!hierarchy_registered_) {
355 // A valid but not attached to anything. 352 // A valid but not attached to anything.
356 EXPECT_EQ(&source_, client_a_.source()); 353 EXPECT_EQ(&source_, client_a_->BeginFrameSourceForTesting());
357 EXPECT_EQ(nullptr, client_b_.source()); 354 EXPECT_TRUE(!client_b_ || !client_b_->BeginFrameSourceForTesting());
358 EXPECT_EQ(nullptr, client_c_.source()); 355 EXPECT_TRUE(!client_c_ || !client_c_->BeginFrameSourceForTesting());
359 return; 356 return;
360 } 357 }
361 358
362 AssertAllValidBFS(); 359 AssertAllValidBFS();
363 } 360 }
364 361
365 StubBeginFrameSource source_; 362 StubBeginFrameSource source_;
366 // A -> B -> C hierarchy, with A always having the BFS. 363 // A -> B -> C hierarchy, with A always having the BFS.
367 FakeSurfaceFactoryClient client_a_; 364 std::unique_ptr<CompositorFrameSinkSupport> client_a_;
368 FakeSurfaceFactoryClient client_b_; 365 std::unique_ptr<CompositorFrameSinkSupport> client_b_;
369 FakeSurfaceFactoryClient client_c_; 366 std::unique_ptr<CompositorFrameSinkSupport> client_c_;
370 367
371 bool hierarchy_registered_; 368 bool hierarchy_registered_;
372 bool clients_registered_; 369 bool clients_registered_;
373 bool bfs_registered_; 370 bool bfs_registered_;
374 }; 371 };
375 372
376 enum RegisterOrder { REGISTER_HIERARCHY_FIRST, REGISTER_CLIENTS_FIRST }; 373 enum RegisterOrder { REGISTER_HIERARCHY_FIRST, REGISTER_CLIENTS_FIRST };
377 enum UnregisterOrder { UNREGISTER_HIERARCHY_FIRST, UNREGISTER_CLIENTS_FIRST }; 374 enum UnregisterOrder { UNREGISTER_HIERARCHY_FIRST, UNREGISTER_CLIENTS_FIRST };
378 enum BFSOrder { BFS_FIRST, BFS_SECOND, BFS_THIRD }; 375 enum BFSOrder { BFS_FIRST, BFS_SECOND, BFS_THIRD };
379 376
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 } 440 }
444 441
445 INSTANTIATE_TEST_CASE_P( 442 INSTANTIATE_TEST_CASE_P(
446 SurfaceManagerOrderingParamTestInstantiation, 443 SurfaceManagerOrderingParamTestInstantiation,
447 SurfaceManagerOrderingParamTest, 444 SurfaceManagerOrderingParamTest,
448 ::testing::Combine(::testing::ValuesIn(kRegisterOrderList), 445 ::testing::Combine(::testing::ValuesIn(kRegisterOrderList),
449 ::testing::ValuesIn(kUnregisterOrderList), 446 ::testing::ValuesIn(kUnregisterOrderList),
450 ::testing::ValuesIn(kBFSOrderList))); 447 ::testing::ValuesIn(kBFSOrderList)));
451 448
452 } // namespace cc 449 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698