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 "ui/ozone/platform/wayland/fake_server.h" | 5 #include "ui/ozone/platform/wayland/fake_server.h" |
6 | 6 |
7 #include <sys/socket.h> | 7 #include <sys/socket.h> |
8 #include <wayland-server.h> | 8 #include <wayland-server.h> |
9 #include <xdg-shell-unstable-v5-server-protocol.h> | 9 #include <xdg-shell-unstable-v5-server-protocol.h> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/files/scoped_file.h" | 12 #include "base/files/scoped_file.h" |
13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
15 #include "base/strings/string_number_conversions.h" | 15 #include "base/strings/string_number_conversions.h" |
16 | 16 |
17 namespace wl { | 17 namespace wl { |
18 namespace { | 18 namespace { |
19 | 19 |
20 const uint32_t kCompositorVersion = 4; | 20 const uint32_t kCompositorVersion = 4; |
21 const uint32_t kOutputVersion = 2; | |
21 const uint32_t kSeatVersion = 4; | 22 const uint32_t kSeatVersion = 4; |
22 const uint32_t kXdgShellVersion = 1; | 23 const uint32_t kXdgShellVersion = 1; |
23 | 24 |
24 void DestroyResource(wl_client* client, wl_resource* resource) { | 25 void DestroyResource(wl_client* client, wl_resource* resource) { |
25 wl_resource_destroy(resource); | 26 wl_resource_destroy(resource); |
26 } | 27 } |
27 | 28 |
28 // wl_compositor | 29 // wl_compositor |
29 | 30 |
30 void CreateSurface(wl_client* client, wl_resource* resource, uint32_t id) { | 31 void CreateSurface(wl_client* client, wl_resource* resource, uint32_t id) { |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
271 wl_resource* resource = wl_resource_create( | 272 wl_resource* resource = wl_resource_create( |
272 client, global->interface_, std::min(version, global->version_), id); | 273 client, global->interface_, std::min(version, global->version_), id); |
273 if (!resource) { | 274 if (!resource) { |
274 wl_client_post_no_memory(client); | 275 wl_client_post_no_memory(client); |
275 return; | 276 return; |
276 } | 277 } |
277 if (!global->resource_) | 278 if (!global->resource_) |
278 global->resource_ = resource; | 279 global->resource_ = resource; |
279 wl_resource_set_implementation(resource, global->implementation_, global, | 280 wl_resource_set_implementation(resource, global->implementation_, global, |
280 &Global::OnResourceDestroyed); | 281 &Global::OnResourceDestroyed); |
282 | |
283 if (global->interface_ == &wl_output_interface) { | |
284 auto output = static_cast<MockOutput*>(data); | |
285 gfx::Rect bounds = output->Display().bounds(); | |
286 const char* kUnknownMake = "unknown"; | |
287 const char* kUnknownModel = "unknown"; | |
288 wl_output_send_geometry(resource, bounds.x(), bounds.y(), 0, 0, 0, | |
289 kUnknownMake, kUnknownModel, 0); | |
290 wl_output_send_mode(resource, WL_OUTPUT_MODE_CURRENT, bounds.width(), | |
291 bounds.height(), 0); | |
292 } | |
Michael Forney
2016/06/14 00:55:18
Maybe instead you could add a virtual method to Gl
joone
2016/06/14 22:10:28
Done.
| |
281 } | 293 } |
282 | 294 |
283 // static | 295 // static |
284 void Global::OnResourceDestroyed(wl_resource* resource) { | 296 void Global::OnResourceDestroyed(wl_resource* resource) { |
285 auto global = static_cast<Global*>(wl_resource_get_user_data(resource)); | 297 auto global = static_cast<Global*>(wl_resource_get_user_data(resource)); |
286 if (global->resource_ == resource) | 298 if (global->resource_ == resource) |
287 global->resource_ = nullptr; | 299 global->resource_ = nullptr; |
288 } | 300 } |
289 | 301 |
290 MockCompositor::MockCompositor() | 302 MockCompositor::MockCompositor() |
291 : Global(&wl_compositor_interface, &compositor_impl, kCompositorVersion) {} | 303 : Global(&wl_compositor_interface, &compositor_impl, kCompositorVersion) {} |
292 | 304 |
293 MockCompositor::~MockCompositor() {} | 305 MockCompositor::~MockCompositor() {} |
294 | 306 |
295 void MockCompositor::AddSurface(std::unique_ptr<MockSurface> surface) { | 307 void MockCompositor::AddSurface(std::unique_ptr<MockSurface> surface) { |
296 surfaces_.push_back(std::move(surface)); | 308 surfaces_.push_back(std::move(surface)); |
297 } | 309 } |
298 | 310 |
311 MockOutput::MockOutput() | |
312 : Global(&wl_output_interface, nullptr, kOutputVersion) {} | |
313 | |
314 MockOutput::~MockOutput() {} | |
315 | |
299 MockSeat::MockSeat() : Global(&wl_seat_interface, &seat_impl, kSeatVersion) {} | 316 MockSeat::MockSeat() : Global(&wl_seat_interface, &seat_impl, kSeatVersion) {} |
300 | 317 |
301 MockSeat::~MockSeat() {} | 318 MockSeat::~MockSeat() {} |
302 | 319 |
303 MockXdgShell::MockXdgShell() | 320 MockXdgShell::MockXdgShell() |
304 : Global(&xdg_shell_interface, &xdg_shell_impl, kXdgShellVersion) {} | 321 : Global(&xdg_shell_interface, &xdg_shell_impl, kXdgShellVersion) {} |
305 | 322 |
306 MockXdgShell::~MockXdgShell() {} | 323 MockXdgShell::~MockXdgShell() {} |
307 | 324 |
308 void DisplayDeleter::operator()(wl_display* display) { | 325 void DisplayDeleter::operator()(wl_display* display) { |
309 wl_display_destroy(display); | 326 wl_display_destroy(display); |
310 } | 327 } |
311 | 328 |
312 FakeServer::FakeServer() | 329 FakeServer::FakeServer() |
313 : Thread("fake_wayland_server"), | 330 : Thread("fake_wayland_server"), |
314 pause_event_(false, false), | 331 pause_event_(false, false), |
315 resume_event_(false, false) {} | 332 resume_event_(false, false) {} |
316 | 333 |
317 FakeServer::~FakeServer() { | 334 FakeServer::~FakeServer() { |
318 Resume(); | 335 Resume(); |
319 Stop(); | 336 Stop(); |
320 } | 337 } |
321 | 338 |
339 void FakeServer::AddDisplay(const display::Display& fake_display) { | |
340 output_.SetDisplay(fake_display); | |
341 } | |
342 | |
322 bool FakeServer::Start() { | 343 bool FakeServer::Start() { |
323 display_.reset(wl_display_create()); | 344 display_.reset(wl_display_create()); |
324 if (!display_) | 345 if (!display_) |
325 return false; | 346 return false; |
326 event_loop_ = wl_display_get_event_loop(display_.get()); | 347 event_loop_ = wl_display_get_event_loop(display_.get()); |
327 | 348 |
328 int fd[2]; | 349 int fd[2]; |
329 if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, fd) < 0) | 350 if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, fd) < 0) |
330 return false; | 351 return false; |
331 base::ScopedFD server_fd(fd[0]); | 352 base::ScopedFD server_fd(fd[0]); |
332 base::ScopedFD client_fd(fd[1]); | 353 base::ScopedFD client_fd(fd[1]); |
333 | 354 |
334 if (wl_display_init_shm(display_.get()) < 0) | 355 if (wl_display_init_shm(display_.get()) < 0) |
335 return false; | 356 return false; |
336 if (!compositor_.Initialize(display_.get())) | 357 if (!compositor_.Initialize(display_.get())) |
337 return false; | 358 return false; |
359 if (!output_.Initialize(display_.get())) | |
360 return false; | |
338 if (!seat_.Initialize(display_.get())) | 361 if (!seat_.Initialize(display_.get())) |
339 return false; | 362 return false; |
340 if (!xdg_shell_.Initialize(display_.get())) | 363 if (!xdg_shell_.Initialize(display_.get())) |
341 return false; | 364 return false; |
342 | 365 |
343 client_ = wl_client_create(display_.get(), server_fd.get()); | 366 client_ = wl_client_create(display_.get(), server_fd.get()); |
344 if (!client_) | 367 if (!client_) |
345 return false; | 368 return false; |
346 (void)server_fd.release(); | 369 (void)server_fd.release(); |
347 | 370 |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
383 } | 406 } |
384 | 407 |
385 void FakeServer::OnFileCanReadWithoutBlocking(int fd) { | 408 void FakeServer::OnFileCanReadWithoutBlocking(int fd) { |
386 wl_event_loop_dispatch(event_loop_, 0); | 409 wl_event_loop_dispatch(event_loop_, 0); |
387 wl_display_flush_clients(display_.get()); | 410 wl_display_flush_clients(display_.get()); |
388 } | 411 } |
389 | 412 |
390 void FakeServer::OnFileCanWriteWithoutBlocking(int fd) {} | 413 void FakeServer::OnFileCanWriteWithoutBlocking(int fd) {} |
391 | 414 |
392 } // namespace wl | 415 } // namespace wl |
OLD | NEW |