OLD | NEW |
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 "services/ui/surfaces/display_compositor.h" | 5 #include "services/ui/surfaces/display_compositor.h" |
6 | 6 |
7 #include <inttypes.h> | 7 #include <inttypes.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 events_ += ";"; | 65 events_ += ";"; |
66 events_ += text; | 66 events_ += text; |
67 } | 67 } |
68 | 68 |
69 // cc::mojom::DisplayCompositorClient: | 69 // cc::mojom::DisplayCompositorClient: |
70 void OnDisplayCompositorCreated( | 70 void OnDisplayCompositorCreated( |
71 const cc::SurfaceId& root_surface_id) override { | 71 const cc::SurfaceId& root_surface_id) override { |
72 got_root_surface_id_ = true; | 72 got_root_surface_id_ = true; |
73 } | 73 } |
74 | 74 |
75 void OnSurfaceCreated(const cc::SurfaceId& surface_id, | 75 void OnSurfaceCreated(const cc::SurfaceInfo& surface_info) override { |
76 const gfx::Size& frame_size, | |
77 float device_scale_factor) override { | |
78 EXPECT_TRUE(got_root_surface_id_); | 76 EXPECT_TRUE(got_root_surface_id_); |
79 AddEvent(base::StringPrintf("OnSurfaceCreated(%s)", | 77 AddEvent(base::StringPrintf("OnSurfaceCreated(%s)", |
80 SurfaceIdString(surface_id).c_str())); | 78 SurfaceIdString(surface_info.id()).c_str())); |
81 } | 79 } |
82 | 80 |
83 mojo::Binding<cc::mojom::DisplayCompositorClient> binding_; | 81 mojo::Binding<cc::mojom::DisplayCompositorClient> binding_; |
84 std::string events_; | 82 std::string events_; |
85 bool got_root_surface_id_ = false; | 83 bool got_root_surface_id_ = false; |
86 | 84 |
87 DISALLOW_COPY_AND_ASSIGN(TestDisplayCompositorClient); | 85 DISALLOW_COPY_AND_ASSIGN(TestDisplayCompositorClient); |
88 }; | 86 }; |
89 | 87 |
90 // Test SurfaceReferenceManager that records AddSurfaceReference() and | 88 // Test SurfaceReferenceManager that records AddSurfaceReference() and |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 TestSurfaceReferenceManager reference_manager_; | 184 TestSurfaceReferenceManager reference_manager_; |
187 std::unique_ptr<DisplayCompositor> display_compositor_; | 185 std::unique_ptr<DisplayCompositor> display_compositor_; |
188 | 186 |
189 private: | 187 private: |
190 DISALLOW_COPY_AND_ASSIGN(DisplayCompositorTest); | 188 DISALLOW_COPY_AND_ASSIGN(DisplayCompositorTest); |
191 }; | 189 }; |
192 | 190 |
193 TEST_F(DisplayCompositorTest, AddSurfaceThenReference) { | 191 TEST_F(DisplayCompositorTest, AddSurfaceThenReference) { |
194 const cc::SurfaceId parent_id = MakeSurfaceId(1, 1, 1); | 192 const cc::SurfaceId parent_id = MakeSurfaceId(1, 1, 1); |
195 const cc::SurfaceId surface_id = MakeSurfaceId(2, 1, 1); | 193 const cc::SurfaceId surface_id = MakeSurfaceId(2, 1, 1); |
196 surface_observer()->OnSurfaceCreated(surface_id, gfx::Size(1, 1), 1.0f); | 194 surface_observer()->OnSurfaceCreated( |
| 195 cc::SurfaceInfo(surface_id, 1.0f, gfx::Size(1, 1))); |
197 RunUntilIdle(); | 196 RunUntilIdle(); |
198 | 197 |
199 // Client should get OnSurfaceCreated call and temporary reference added. | 198 // Client should get OnSurfaceCreated call and temporary reference added. |
200 EXPECT_EQ("OnSurfaceCreated(2:1:1)", client_.events()); | 199 EXPECT_EQ("OnSurfaceCreated(2:1:1)", client_.events()); |
201 EXPECT_EQ("Add(0:0:0-2:1:1)", reference_manager_.events()); | 200 EXPECT_EQ("Add(0:0:0-2:1:1)", reference_manager_.events()); |
202 EXPECT_EQ(1u, CountTempReferences()); | 201 EXPECT_EQ(1u, CountTempReferences()); |
203 | 202 |
204 AddSurfaceReference(parent_id, surface_id); | 203 AddSurfaceReference(parent_id, surface_id); |
205 RunUntilIdle(); | 204 RunUntilIdle(); |
206 | 205 |
207 // Real reference is added then temporary reference removed. | 206 // Real reference is added then temporary reference removed. |
208 EXPECT_EQ("Add(1:1:1-2:1:1);Remove(0:0:0-2:1:1)", | 207 EXPECT_EQ("Add(1:1:1-2:1:1);Remove(0:0:0-2:1:1)", |
209 reference_manager_.events()); | 208 reference_manager_.events()); |
210 EXPECT_EQ(0u, CountTempReferences()); | 209 EXPECT_EQ(0u, CountTempReferences()); |
211 } | 210 } |
212 | 211 |
213 TEST_F(DisplayCompositorTest, AddSurfaceThenRootReference) { | 212 TEST_F(DisplayCompositorTest, AddSurfaceThenRootReference) { |
214 const cc::SurfaceId surface_id = MakeSurfaceId(1, 1, 1); | 213 const cc::SurfaceId surface_id = MakeSurfaceId(1, 1, 1); |
215 surface_observer()->OnSurfaceCreated(surface_id, gfx::Size(1, 1), 1.0f); | 214 surface_observer()->OnSurfaceCreated( |
| 215 cc::SurfaceInfo(surface_id, 1.0f, gfx::Size(1, 1))); |
216 RunUntilIdle(); | 216 RunUntilIdle(); |
217 | 217 |
218 // Temporary reference should be added. | 218 // Temporary reference should be added. |
219 EXPECT_EQ("Add(0:0:0-1:1:1)", reference_manager_.events()); | 219 EXPECT_EQ("Add(0:0:0-1:1:1)", reference_manager_.events()); |
220 EXPECT_EQ(1u, CountTempReferences()); | 220 EXPECT_EQ(1u, CountTempReferences()); |
221 | 221 |
222 AddSurfaceReference(GetRootSurfaceId(), surface_id); | 222 AddSurfaceReference(GetRootSurfaceId(), surface_id); |
223 RunUntilIdle(); | 223 RunUntilIdle(); |
224 | 224 |
225 // Adding real reference doesn't need to change anything in | 225 // Adding real reference doesn't need to change anything in |
226 // SurfaceReferenceManager does remove the temporary reference marker. | 226 // SurfaceReferenceManager does remove the temporary reference marker. |
227 EXPECT_EQ("", reference_manager_.events()); | 227 EXPECT_EQ("", reference_manager_.events()); |
228 EXPECT_EQ(0u, CountTempReferences()); | 228 EXPECT_EQ(0u, CountTempReferences()); |
229 } | 229 } |
230 | 230 |
231 TEST_F(DisplayCompositorTest, AddTwoSurfacesThenOneReference) { | 231 TEST_F(DisplayCompositorTest, AddTwoSurfacesThenOneReference) { |
232 const cc::SurfaceId parent_id = MakeSurfaceId(1, 1, 1); | 232 const cc::SurfaceId parent_id = MakeSurfaceId(1, 1, 1); |
233 const cc::SurfaceId surface_id1 = MakeSurfaceId(2, 1, 1); | 233 const cc::SurfaceId surface_id1 = MakeSurfaceId(2, 1, 1); |
234 const cc::SurfaceId surface_id2 = MakeSurfaceId(3, 1, 1); | 234 const cc::SurfaceId surface_id2 = MakeSurfaceId(3, 1, 1); |
235 | 235 |
236 // Add two surfaces with different FrameSinkIds. | 236 // Add two surfaces with different FrameSinkIds. |
237 surface_observer()->OnSurfaceCreated(surface_id1, gfx::Size(1, 1), 1.0f); | 237 surface_observer()->OnSurfaceCreated( |
238 surface_observer()->OnSurfaceCreated(surface_id2, gfx::Size(1, 1), 1.0f); | 238 cc::SurfaceInfo(surface_id1, 1.0f, gfx::Size(1, 1))); |
| 239 surface_observer()->OnSurfaceCreated( |
| 240 cc::SurfaceInfo(surface_id2, 1.0f, gfx::Size(1, 1))); |
239 RunUntilIdle(); | 241 RunUntilIdle(); |
240 | 242 |
241 // Temporary reference should be added for both surfaces. | 243 // Temporary reference should be added for both surfaces. |
242 EXPECT_EQ("Add(0:0:0-2:1:1);Add(0:0:0-3:1:1)", reference_manager_.events()); | 244 EXPECT_EQ("Add(0:0:0-2:1:1);Add(0:0:0-3:1:1)", reference_manager_.events()); |
243 EXPECT_EQ(2u, CountTempReferences()); | 245 EXPECT_EQ(2u, CountTempReferences()); |
244 | 246 |
245 AddSurfaceReference(parent_id, surface_id1); | 247 AddSurfaceReference(parent_id, surface_id1); |
246 RunUntilIdle(); | 248 RunUntilIdle(); |
247 | 249 |
248 // Real reference is added then temporary reference removed for 2:1:1. There | 250 // Real reference is added then temporary reference removed for 2:1:1. There |
249 // should still be a temporary reference left to 3:1:1 | 251 // should still be a temporary reference left to 3:1:1 |
250 EXPECT_EQ("Add(1:1:1-2:1:1);Remove(0:0:0-2:1:1)", | 252 EXPECT_EQ("Add(1:1:1-2:1:1);Remove(0:0:0-2:1:1)", |
251 reference_manager_.events()); | 253 reference_manager_.events()); |
252 EXPECT_EQ(1u, CountTempReferences()); | 254 EXPECT_EQ(1u, CountTempReferences()); |
253 } | 255 } |
254 | 256 |
255 TEST_F(DisplayCompositorTest, AddSurfacesSkipReference) { | 257 TEST_F(DisplayCompositorTest, AddSurfacesSkipReference) { |
256 const cc::SurfaceId parent_id = MakeSurfaceId(1, 1, 1); | 258 const cc::SurfaceId parent_id = MakeSurfaceId(1, 1, 1); |
257 const cc::SurfaceId surface_id1 = MakeSurfaceId(2, 1, 1); | 259 const cc::SurfaceId surface_id1 = MakeSurfaceId(2, 1, 1); |
258 const cc::SurfaceId surface_id2 = MakeSurfaceId(2, 1, 2); | 260 const cc::SurfaceId surface_id2 = MakeSurfaceId(2, 1, 2); |
259 | 261 |
260 // Add two surfaces that have the same FrameSinkId. This would happen when a | 262 // Add two surfaces that have the same FrameSinkId. This would happen when a |
261 // client submits two CFs before parent submits a new CF. | 263 // client submits two CFs before parent submits a new CF. |
262 surface_observer()->OnSurfaceCreated(surface_id1, gfx::Size(1, 1), 1.0f); | 264 surface_observer()->OnSurfaceCreated( |
263 surface_observer()->OnSurfaceCreated(surface_id2, gfx::Size(1, 1), 1.0f); | 265 cc::SurfaceInfo(surface_id1, 1.0f, gfx::Size(1, 1))); |
| 266 surface_observer()->OnSurfaceCreated( |
| 267 cc::SurfaceInfo(surface_id2, 1.0f, gfx::Size(1, 1))); |
264 RunUntilIdle(); | 268 RunUntilIdle(); |
265 | 269 |
266 // Client should get OnSurfaceCreated call and temporary reference added for | 270 // Client should get OnSurfaceCreated call and temporary reference added for |
267 // both surfaces. | 271 // both surfaces. |
268 EXPECT_EQ("OnSurfaceCreated(2:1:1);OnSurfaceCreated(2:1:2)", | 272 EXPECT_EQ("OnSurfaceCreated(2:1:1);OnSurfaceCreated(2:1:2)", |
269 client_.events()); | 273 client_.events()); |
270 EXPECT_EQ("Add(0:0:0-2:1:1);Add(0:0:0-2:1:2)", reference_manager_.events()); | 274 EXPECT_EQ("Add(0:0:0-2:1:1);Add(0:0:0-2:1:2)", reference_manager_.events()); |
271 EXPECT_EQ(2u, CountTempReferences()); | 275 EXPECT_EQ(2u, CountTempReferences()); |
272 | 276 |
273 // Add a reference to the surface with the later LocalFrameId. | 277 // Add a reference to the surface with the later LocalFrameId. |
274 AddSurfaceReference(parent_id, surface_id2); | 278 AddSurfaceReference(parent_id, surface_id2); |
275 RunUntilIdle(); | 279 RunUntilIdle(); |
276 | 280 |
277 // The real reference should be added for 2:1:2 and both temporary references | 281 // The real reference should be added for 2:1:2 and both temporary references |
278 // should be removed. | 282 // should be removed. |
279 EXPECT_EQ("Add(1:1:1-2:1:2);Remove(0:0:0-2:1:2);Remove(0:0:0-2:1:1)", | 283 EXPECT_EQ("Add(1:1:1-2:1:2);Remove(0:0:0-2:1:2);Remove(0:0:0-2:1:1)", |
280 reference_manager_.events()); | 284 reference_manager_.events()); |
281 EXPECT_EQ(0u, CountTempReferences()); | 285 EXPECT_EQ(0u, CountTempReferences()); |
282 } | 286 } |
283 | 287 |
284 } // namespace test | 288 } // namespace test |
285 } // namespace ui | 289 } // namespace ui |
OLD | NEW |