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

Side by Side Diff: ui/ozone/platform/wayland/fake_server.cc

Issue 1712103002: ozone/platform/wayland: Implement pointer handling (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add second window for WaylandPointerTest.Leave, check for NULL surface in WaylandPointer::{Enter,Le… Created 4 years, 10 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 "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 kSeatVersion = 4;
19 const uint32_t kXdgShellVersion = 1; 20 const uint32_t kXdgShellVersion = 1;
20 21
21 void DestroyResource(wl_client* client, wl_resource* resource) { 22 void DestroyResource(wl_client* client, wl_resource* resource) {
22 wl_resource_destroy(resource); 23 wl_resource_destroy(resource);
23 } 24 }
24 25
25 // wl_compositor 26 // wl_compositor
26 27
27 void CreateSurface(wl_client* client, wl_resource* resource, uint32_t id) { 28 void CreateSurface(wl_client* client, wl_resource* resource, uint32_t id) {
28 auto compositor = 29 auto compositor =
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 } 114 }
114 115
115 const struct xdg_shell_interface xdg_shell_impl = { 116 const struct xdg_shell_interface xdg_shell_impl = {
116 &DestroyResource, // destroy 117 &DestroyResource, // destroy
117 &UseUnstableVersion, // use_unstable_version 118 &UseUnstableVersion, // use_unstable_version
118 &GetXdgSurface, // get_xdg_surface 119 &GetXdgSurface, // get_xdg_surface
119 nullptr, // get_xdg_popup 120 nullptr, // get_xdg_popup
120 &Pong, // pong 121 &Pong, // pong
121 }; 122 };
122 123
124 // wl_seat
125
126 void GetPointer(wl_client* client, wl_resource* resource, uint32_t id) {
127 auto seat = static_cast<MockSeat*>(wl_resource_get_user_data(resource));
128 wl_resource* pointer_resource = wl_resource_create(
129 client, &wl_pointer_interface, wl_resource_get_version(resource), id);
130 if (!pointer_resource) {
131 wl_client_post_no_memory(client);
132 return;
133 }
134 seat->pointer.reset(new MockPointer(pointer_resource));
135 }
136
137 const struct wl_seat_interface seat_impl = {
138 &GetPointer, // get_pointer
139 nullptr, // get_keyboard
140 nullptr, // get_touch,
141 &DestroyResource, // release
142 };
143
144 // wl_pointer
145
146 const struct wl_pointer_interface pointer_impl = {
147 nullptr, // set_cursor
148 &DestroyResource, // release
149 };
150
123 // xdg_surface 151 // xdg_surface
124 152
125 void SetTitle(wl_client* client, wl_resource* resource, const char* title) { 153 void SetTitle(wl_client* client, wl_resource* resource, const char* title) {
126 static_cast<MockXdgSurface*>(wl_resource_get_user_data(resource)) 154 static_cast<MockXdgSurface*>(wl_resource_get_user_data(resource))
127 ->SetTitle(title); 155 ->SetTitle(title);
128 } 156 }
129 157
130 void SetAppId(wl_client* client, wl_resource* resource, const char* app_id) { 158 void SetAppId(wl_client* client, wl_resource* resource, const char* app_id) {
131 static_cast<MockXdgSurface*>(wl_resource_get_user_data(resource)) 159 static_cast<MockXdgSurface*>(wl_resource_get_user_data(resource))
132 ->SetAppId(app_id); 160 ->SetAppId(app_id);
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
200 if (xdg_surface && xdg_surface->resource()) 228 if (xdg_surface && xdg_surface->resource())
201 wl_resource_destroy(xdg_surface->resource()); 229 wl_resource_destroy(xdg_surface->resource());
202 } 230 }
203 231
204 MockSurface* MockSurface::FromResource(wl_resource* resource) { 232 MockSurface* MockSurface::FromResource(wl_resource* resource) {
205 if (!wl_resource_instance_of(resource, &wl_surface_interface, &surface_impl)) 233 if (!wl_resource_instance_of(resource, &wl_surface_interface, &surface_impl))
206 return nullptr; 234 return nullptr;
207 return static_cast<MockSurface*>(wl_resource_get_user_data(resource)); 235 return static_cast<MockSurface*>(wl_resource_get_user_data(resource));
208 } 236 }
209 237
238 MockPointer::MockPointer(wl_resource* resource) : ServerObject(resource) {
239 wl_resource_set_implementation(resource, &pointer_impl, this,
240 &ServerObject::OnResourceDestroyed);
241 }
242
243 MockPointer::~MockPointer() {}
244
210 void GlobalDeleter::operator()(wl_global* global) { 245 void GlobalDeleter::operator()(wl_global* global) {
211 wl_global_destroy(global); 246 wl_global_destroy(global);
212 } 247 }
213 248
214 Global::Global(const wl_interface* interface, 249 Global::Global(const wl_interface* interface,
215 const void* implementation, 250 const void* implementation,
216 uint32_t version) 251 uint32_t version)
217 : interface_(interface), 252 : interface_(interface),
218 implementation_(implementation), 253 implementation_(implementation),
219 version_(version) {} 254 version_(version) {}
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 287
253 MockCompositor::MockCompositor() 288 MockCompositor::MockCompositor()
254 : Global(&wl_compositor_interface, &compositor_impl, kCompositorVersion) {} 289 : Global(&wl_compositor_interface, &compositor_impl, kCompositorVersion) {}
255 290
256 MockCompositor::~MockCompositor() {} 291 MockCompositor::~MockCompositor() {}
257 292
258 void MockCompositor::AddSurface(scoped_ptr<MockSurface> surface) { 293 void MockCompositor::AddSurface(scoped_ptr<MockSurface> surface) {
259 surfaces_.push_back(std::move(surface)); 294 surfaces_.push_back(std::move(surface));
260 } 295 }
261 296
297 MockSeat::MockSeat() : Global(&wl_seat_interface, &seat_impl, kSeatVersion) {}
298
299 MockSeat::~MockSeat() {}
300
262 MockXdgShell::MockXdgShell() 301 MockXdgShell::MockXdgShell()
263 : Global(&xdg_shell_interface, &xdg_shell_impl, kXdgShellVersion) {} 302 : Global(&xdg_shell_interface, &xdg_shell_impl, kXdgShellVersion) {}
264 303
265 MockXdgShell::~MockXdgShell() {} 304 MockXdgShell::~MockXdgShell() {}
266 305
267 void DisplayDeleter::operator()(wl_display* display) { 306 void DisplayDeleter::operator()(wl_display* display) {
268 wl_display_destroy(display); 307 wl_display_destroy(display);
269 } 308 }
270 309
271 FakeServer::FakeServer() 310 FakeServer::FakeServer()
(...skipping 14 matching lines...) Expand all
286 int fd[2]; 325 int fd[2];
287 if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, fd) < 0) 326 if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0, fd) < 0)
288 return false; 327 return false;
289 base::ScopedFD server_fd(fd[0]); 328 base::ScopedFD server_fd(fd[0]);
290 base::ScopedFD client_fd(fd[1]); 329 base::ScopedFD client_fd(fd[1]);
291 330
292 if (wl_display_init_shm(display_.get()) < 0) 331 if (wl_display_init_shm(display_.get()) < 0)
293 return false; 332 return false;
294 if (!compositor_.Initialize(display_.get())) 333 if (!compositor_.Initialize(display_.get()))
295 return false; 334 return false;
335 if (!seat_.Initialize(display_.get()))
336 return false;
296 if (!xdg_shell_.Initialize(display_.get())) 337 if (!xdg_shell_.Initialize(display_.get()))
297 return false; 338 return false;
298 339
299 client_ = wl_client_create(display_.get(), server_fd.get()); 340 client_ = wl_client_create(display_.get(), server_fd.get());
300 if (!client_) 341 if (!client_)
301 return false; 342 return false;
302 (void)server_fd.release(); 343 (void)server_fd.release();
303 344
304 base::Thread::Options options; 345 base::Thread::Options options;
305 options.message_pump_factory = 346 options.message_pump_factory =
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 } 381 }
341 382
342 void FakeServer::OnFileCanReadWithoutBlocking(int fd) { 383 void FakeServer::OnFileCanReadWithoutBlocking(int fd) {
343 wl_event_loop_dispatch(event_loop_, 0); 384 wl_event_loop_dispatch(event_loop_, 0);
344 wl_display_flush_clients(display_.get()); 385 wl_display_flush_clients(display_.get());
345 } 386 }
346 387
347 void FakeServer::OnFileCanWriteWithoutBlocking(int fd) {} 388 void FakeServer::OnFileCanWriteWithoutBlocking(int fd) {}
348 389
349 } // namespace wl 390 } // namespace wl
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698