| 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/strings/string_number_conversions.h" | 13 #include "base/strings/string_number_conversions.h" |
| 14 | 14 |
| 15 namespace wl { | 15 namespace wl { |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 const uint32_t kCompositorVersion = 4; | 18 const uint32_t kCompositorVersion = 4; |
| 19 const uint32_t kSurfaceVersion = 4; | |
| 20 const uint32_t kXdgShellVersion = 1; | 19 const uint32_t kXdgShellVersion = 1; |
| 21 const uint32_t kXdgSurfaceVersion = 1; | |
| 22 | 20 |
| 23 void DestroyResource(wl_client* client, wl_resource* resource) { | 21 void DestroyResource(wl_client* client, wl_resource* resource) { |
| 24 wl_resource_destroy(resource); | 22 wl_resource_destroy(resource); |
| 25 } | 23 } |
| 26 | 24 |
| 27 // wl_compositor | 25 // wl_compositor |
| 28 | 26 |
| 29 void CreateSurface(wl_client* client, wl_resource* resource, uint32_t id) { | 27 void CreateSurface(wl_client* client, wl_resource* resource, uint32_t id) { |
| 30 auto compositor = | 28 auto compositor = |
| 31 static_cast<MockCompositor*>(wl_resource_get_user_data(resource)); | 29 static_cast<MockCompositor*>(wl_resource_get_user_data(resource)); |
| 32 wl_resource* surface_resource = | 30 wl_resource* surface_resource = wl_resource_create( |
| 33 wl_resource_create(client, &wl_surface_interface, kSurfaceVersion, id); | 31 client, &wl_surface_interface, wl_resource_get_version(resource), id); |
| 34 if (!surface_resource) { | 32 if (!surface_resource) { |
| 35 wl_client_post_no_memory(client); | 33 wl_client_post_no_memory(client); |
| 36 return; | 34 return; |
| 37 } | 35 } |
| 38 compositor->AddSurface(make_scoped_ptr(new MockSurface(surface_resource))); | 36 compositor->AddSurface(make_scoped_ptr(new MockSurface(surface_resource))); |
| 39 } | 37 } |
| 40 | 38 |
| 41 const struct wl_compositor_interface compositor_impl = { | 39 const struct wl_compositor_interface compositor_impl = { |
| 42 &CreateSurface, // create_surface | 40 &CreateSurface, // create_surface |
| 43 nullptr, // create_region | 41 nullptr, // create_region |
| (...skipping 27 matching lines...) Expand all Loading... |
| 71 const struct wl_surface_interface surface_impl = { | 69 const struct wl_surface_interface surface_impl = { |
| 72 &DestroyResource, // destroy | 70 &DestroyResource, // destroy |
| 73 &Attach, // attach | 71 &Attach, // attach |
| 74 &Damage, // damage | 72 &Damage, // damage |
| 75 nullptr, // frame | 73 nullptr, // frame |
| 76 nullptr, // set_opaque_region | 74 nullptr, // set_opaque_region |
| 77 nullptr, // set_input_region | 75 nullptr, // set_input_region |
| 78 &Commit, // commit | 76 &Commit, // commit |
| 79 nullptr, // set_buffer_transform | 77 nullptr, // set_buffer_transform |
| 80 nullptr, // set_buffer_scale | 78 nullptr, // set_buffer_scale |
| 79 nullptr, // damage_buffer |
| 81 }; | 80 }; |
| 82 | 81 |
| 83 // xdg_shell | 82 // xdg_shell |
| 84 | 83 |
| 85 void UseUnstableVersion(wl_client* client, | 84 void UseUnstableVersion(wl_client* client, |
| 86 wl_resource* resource, | 85 wl_resource* resource, |
| 87 int32_t version) { | 86 int32_t version) { |
| 88 static_cast<MockXdgShell*>(wl_resource_get_user_data(resource)) | 87 static_cast<MockXdgShell*>(wl_resource_get_user_data(resource)) |
| 89 ->UseUnstableVersion(version); | 88 ->UseUnstableVersion(version); |
| 90 } | 89 } |
| 91 | 90 |
| 92 void GetXdgSurface(wl_client* client, | 91 void GetXdgSurface(wl_client* client, |
| 93 wl_resource* resource, | 92 wl_resource* resource, |
| 94 uint32_t id, | 93 uint32_t id, |
| 95 wl_resource* surface_resource) { | 94 wl_resource* surface_resource) { |
| 96 auto surface = | 95 auto surface = |
| 97 static_cast<MockSurface*>(wl_resource_get_user_data(surface_resource)); | 96 static_cast<MockSurface*>(wl_resource_get_user_data(surface_resource)); |
| 98 if (surface->xdg_surface) { | 97 if (surface->xdg_surface) { |
| 99 wl_resource_post_error(resource, XDG_SHELL_ERROR_ROLE, | 98 wl_resource_post_error(resource, XDG_SHELL_ERROR_ROLE, |
| 100 "surface already has a role"); | 99 "surface already has a role"); |
| 101 return; | 100 return; |
| 102 } | 101 } |
| 103 wl_resource* xdg_surface_resource = wl_resource_create( | 102 wl_resource* xdg_surface_resource = wl_resource_create( |
| 104 client, &xdg_surface_interface, kXdgSurfaceVersion, id); | 103 client, &xdg_surface_interface, wl_resource_get_version(resource), id); |
| 105 if (!xdg_surface_resource) { | 104 if (!xdg_surface_resource) { |
| 106 wl_client_post_no_memory(client); | 105 wl_client_post_no_memory(client); |
| 107 return; | 106 return; |
| 108 } | 107 } |
| 109 surface->xdg_surface.reset(new MockXdgSurface(xdg_surface_resource)); | 108 surface->xdg_surface.reset(new MockXdgSurface(xdg_surface_resource)); |
| 110 } | 109 } |
| 111 | 110 |
| 112 void Pong(wl_client* client, wl_resource* resource, uint32_t serial) { | 111 void Pong(wl_client* client, wl_resource* resource, uint32_t serial) { |
| 113 static_cast<MockXdgShell*>(wl_resource_get_user_data(resource))->Pong(serial); | 112 static_cast<MockXdgShell*>(wl_resource_get_user_data(resource))->Pong(serial); |
| 114 } | 113 } |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 global_.reset(wl_global_create(display, interface_, version_, this, &Bind)); | 224 global_.reset(wl_global_create(display, interface_, version_, this, &Bind)); |
| 226 return global_; | 225 return global_; |
| 227 } | 226 } |
| 228 | 227 |
| 229 // static | 228 // static |
| 230 void Global::Bind(wl_client* client, | 229 void Global::Bind(wl_client* client, |
| 231 void* data, | 230 void* data, |
| 232 uint32_t version, | 231 uint32_t version, |
| 233 uint32_t id) { | 232 uint32_t id) { |
| 234 auto global = static_cast<Global*>(data); | 233 auto global = static_cast<Global*>(data); |
| 235 wl_resource* resource = | 234 wl_resource* resource = wl_resource_create( |
| 236 wl_resource_create(client, global->interface_, global->version_, id); | 235 client, global->interface_, std::min(version, global->version_), id); |
| 237 if (!resource) { | 236 if (!resource) { |
| 238 wl_client_post_no_memory(client); | 237 wl_client_post_no_memory(client); |
| 239 return; | 238 return; |
| 240 } | 239 } |
| 241 if (!global->resource_) | 240 if (!global->resource_) |
| 242 global->resource_ = resource; | 241 global->resource_ = resource; |
| 243 wl_resource_set_implementation(resource, global->implementation_, global, | 242 wl_resource_set_implementation(resource, global->implementation_, global, |
| 244 &Global::OnResourceDestroyed); | 243 &Global::OnResourceDestroyed); |
| 245 } | 244 } |
| 246 | 245 |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 341 } | 340 } |
| 342 | 341 |
| 343 void FakeServer::OnFileCanReadWithoutBlocking(int fd) { | 342 void FakeServer::OnFileCanReadWithoutBlocking(int fd) { |
| 344 wl_event_loop_dispatch(event_loop_, 0); | 343 wl_event_loop_dispatch(event_loop_, 0); |
| 345 wl_display_flush_clients(display_.get()); | 344 wl_display_flush_clients(display_.get()); |
| 346 } | 345 } |
| 347 | 346 |
| 348 void FakeServer::OnFileCanWriteWithoutBlocking(int fd) {} | 347 void FakeServer::OnFileCanWriteWithoutBlocking(int fd) {} |
| 349 | 348 |
| 350 } // namespace wl | 349 } // namespace wl |
| OLD | NEW |