| 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 |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 360 return false; | 360 return false; |
| 361 if (!xdg_shell_.Initialize(display_.get())) | 361 if (!xdg_shell_.Initialize(display_.get())) |
| 362 return false; | 362 return false; |
| 363 | 363 |
| 364 client_ = wl_client_create(display_.get(), server_fd.get()); | 364 client_ = wl_client_create(display_.get(), server_fd.get()); |
| 365 if (!client_) | 365 if (!client_) |
| 366 return false; | 366 return false; |
| 367 (void)server_fd.release(); | 367 (void)server_fd.release(); |
| 368 | 368 |
| 369 base::Thread::Options options; | 369 base::Thread::Options options; |
| 370 options.message_pump_factory = | 370 options.message_loop_type = MessageLoop::TYPE_IO; |
| 371 base::Bind(&FakeServer::CreateMessagePump, base::Unretained(this)); | |
| 372 if (!base::Thread::StartWithOptions(options)) | 371 if (!base::Thread::StartWithOptions(options)) |
| 373 return false; | 372 return false; |
| 373 task_runner()->PostTask(FROM_HERE, |
| 374 base::Bind(&FakeServer::StartWatchingFileDescriptor, |
| 375 base::Unretained(this))); |
| 374 | 376 |
| 375 setenv("WAYLAND_SOCKET", base::UintToString(client_fd.release()).c_str(), 1); | 377 setenv("WAYLAND_SOCKET", base::UintToString(client_fd.release()).c_str(), 1); |
| 376 | 378 |
| 377 return true; | 379 return true; |
| 378 } | 380 } |
| 379 | 381 |
| 380 void FakeServer::Pause() { | 382 void FakeServer::Pause() { |
| 381 task_runner()->PostTask( | 383 task_runner()->PostTask( |
| 382 FROM_HERE, base::Bind(&FakeServer::DoPause, base::Unretained(this))); | 384 FROM_HERE, base::Bind(&FakeServer::DoPause, base::Unretained(this))); |
| 383 pause_event_.Wait(); | 385 pause_event_.Wait(); |
| 384 } | 386 } |
| 385 | 387 |
| 386 void FakeServer::Resume() { | 388 void FakeServer::Resume() { |
| 387 if (display_) | 389 if (display_) |
| 388 wl_display_flush_clients(display_.get()); | 390 wl_display_flush_clients(display_.get()); |
| 389 resume_event_.Signal(); | 391 resume_event_.Signal(); |
| 390 } | 392 } |
| 391 | 393 |
| 392 void FakeServer::DoPause() { | 394 void FakeServer::DoPause() { |
| 393 base::RunLoop().RunUntilIdle(); | 395 base::RunLoop().RunUntilIdle(); |
| 394 pause_event_.Signal(); | 396 pause_event_.Signal(); |
| 395 resume_event_.Wait(); | 397 resume_event_.Wait(); |
| 396 } | 398 } |
| 397 | 399 |
| 398 std::unique_ptr<base::MessagePump> FakeServer::CreateMessagePump() { | 400 void FakeServer::StartWatchingFileDescriptor() { |
| 399 auto pump = base::WrapUnique(new base::MessagePumpLibevent); | 401 controller_ = base::FileDescriptorWatcher::WatchReadable( |
| 400 pump->WatchFileDescriptor(wl_event_loop_get_fd(event_loop_), true, | 402 wl_event_loop_get_fd(event_loop_), |
| 401 base::MessagePumpLibevent::WATCH_READ, &controller_, | 403 base::Bind(&FakeServer::OnFileCanReadWithoutBlocking, |
| 402 this); | 404 base::Unretained(this))); |
| 403 return std::move(pump); | |
| 404 } | 405 } |
| 405 | 406 |
| 406 void FakeServer::OnFileCanReadWithoutBlocking(int fd) { | 407 void FakeServer::OnFileCanReadWithoutBlocking() { |
| 407 wl_event_loop_dispatch(event_loop_, 0); | 408 wl_event_loop_dispatch(event_loop_, 0); |
| 408 wl_display_flush_clients(display_.get()); | 409 wl_display_flush_clients(display_.get()); |
| 409 } | 410 } |
| 410 | 411 |
| 411 void FakeServer::OnFileCanWriteWithoutBlocking(int fd) {} | |
| 412 | 412 |
| 413 } // namespace wl | 413 } // namespace wl |
| OLD | NEW |