| 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 global->OnBind(); |
| 281 } | 283 } |
| 282 | 284 |
| 283 // static | 285 // static |
| 284 void Global::OnResourceDestroyed(wl_resource* resource) { | 286 void Global::OnResourceDestroyed(wl_resource* resource) { |
| 285 auto global = static_cast<Global*>(wl_resource_get_user_data(resource)); | 287 auto global = static_cast<Global*>(wl_resource_get_user_data(resource)); |
| 286 if (global->resource_ == resource) | 288 if (global->resource_ == resource) |
| 287 global->resource_ = nullptr; | 289 global->resource_ = nullptr; |
| 288 } | 290 } |
| 289 | 291 |
| 290 MockCompositor::MockCompositor() | 292 MockCompositor::MockCompositor() |
| 291 : Global(&wl_compositor_interface, &compositor_impl, kCompositorVersion) {} | 293 : Global(&wl_compositor_interface, &compositor_impl, kCompositorVersion) {} |
| 292 | 294 |
| 293 MockCompositor::~MockCompositor() {} | 295 MockCompositor::~MockCompositor() {} |
| 294 | 296 |
| 295 void MockCompositor::AddSurface(std::unique_ptr<MockSurface> surface) { | 297 void MockCompositor::AddSurface(std::unique_ptr<MockSurface> surface) { |
| 296 surfaces_.push_back(std::move(surface)); | 298 surfaces_.push_back(std::move(surface)); |
| 297 } | 299 } |
| 298 | 300 |
| 301 MockOutput::MockOutput() |
| 302 : Global(&wl_output_interface, nullptr, kOutputVersion) {} |
| 303 |
| 304 MockOutput::~MockOutput() {} |
| 305 |
| 306 // Notify clients of the change for output position. |
| 307 void MockOutput::OnBind() { |
| 308 const char* kUnknownMake = "unknown"; |
| 309 const char* kUnknownModel = "unknown"; |
| 310 wl_output_send_geometry(resource(), rect_.x(), rect_.y(), 0, 0, 0, |
| 311 kUnknownMake, kUnknownModel, 0); |
| 312 wl_output_send_mode(resource(), WL_OUTPUT_MODE_CURRENT, rect_.width(), |
| 313 rect_.height(), 0); |
| 314 } |
| 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) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 330 int fd[2]; | 347 int fd[2]; |
| 331 if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, fd) < 0) | 348 if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, fd) < 0) |
| 332 return false; | 349 return false; |
| 333 base::ScopedFD server_fd(fd[0]); | 350 base::ScopedFD server_fd(fd[0]); |
| 334 base::ScopedFD client_fd(fd[1]); | 351 base::ScopedFD client_fd(fd[1]); |
| 335 | 352 |
| 336 if (wl_display_init_shm(display_.get()) < 0) | 353 if (wl_display_init_shm(display_.get()) < 0) |
| 337 return false; | 354 return false; |
| 338 if (!compositor_.Initialize(display_.get())) | 355 if (!compositor_.Initialize(display_.get())) |
| 339 return false; | 356 return false; |
| 357 if (!output_.Initialize(display_.get())) |
| 358 return false; |
| 340 if (!seat_.Initialize(display_.get())) | 359 if (!seat_.Initialize(display_.get())) |
| 341 return false; | 360 return false; |
| 342 if (!xdg_shell_.Initialize(display_.get())) | 361 if (!xdg_shell_.Initialize(display_.get())) |
| 343 return false; | 362 return false; |
| 344 | 363 |
| 345 client_ = wl_client_create(display_.get(), server_fd.get()); | 364 client_ = wl_client_create(display_.get(), server_fd.get()); |
| 346 if (!client_) | 365 if (!client_) |
| 347 return false; | 366 return false; |
| 348 (void)server_fd.release(); | 367 (void)server_fd.release(); |
| 349 | 368 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 385 } | 404 } |
| 386 | 405 |
| 387 void FakeServer::OnFileCanReadWithoutBlocking(int fd) { | 406 void FakeServer::OnFileCanReadWithoutBlocking(int fd) { |
| 388 wl_event_loop_dispatch(event_loop_, 0); | 407 wl_event_loop_dispatch(event_loop_, 0); |
| 389 wl_display_flush_clients(display_.get()); | 408 wl_display_flush_clients(display_.get()); |
| 390 } | 409 } |
| 391 | 410 |
| 392 void FakeServer::OnFileCanWriteWithoutBlocking(int fd) {} | 411 void FakeServer::OnFileCanWriteWithoutBlocking(int fd) {} |
| 393 | 412 |
| 394 } // namespace wl | 413 } // namespace wl |
| OLD | NEW |