1 /* 2 * Copyright (C) 2019 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #pragma once 18 19 #include <atomic> 20 #include <cstdint> 21 #include <functional> 22 #include <future> 23 #include <memory> 24 #include <string> 25 #include <thread> 26 27 #include "host/libs/wayland/wayland_surfaces.h" 28 29 namespace wayland { 30 31 namespace internal { 32 struct WaylandServerState; 33 } // namespace internal 34 35 // A Wayland compositing server that provides an interface for receiving frame 36 // updates from a connected client. 37 class WaylandServer { 38 public: 39 // Creates a Wayland compositing server. If specified, uses the given 40 // socket file descriptor to connect with clients. If provided, this 41 // server will close the file descriptor upon exit. 42 WaylandServer(int wayland_socket_fd = -1); 43 virtual ~WaylandServer(); 44 45 WaylandServer(const WaylandServer& rhs) = delete; 46 WaylandServer& operator=(const WaylandServer& rhs) = delete; 47 48 WaylandServer(WaylandServer&& rhs) = delete; 49 WaylandServer& operator=(WaylandServer&& rhs) = delete; 50 51 // Blocks until the given callback is run on the next frame available. 52 void OnNextFrame(const Surfaces::FrameCallback& callback); 53 54 private: 55 void ServerLoop(int wayland_socket_fd); 56 57 bool server_ready_ = false; 58 std::mutex server_ready_mutex_; 59 std::condition_variable server_ready_cv_; 60 61 std::thread server_thread_; 62 std::unique_ptr<internal::WaylandServerState> server_state_; 63 }; 64 65 } // namespace wayland