/* * Copyright (C) 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include #include #include #include #include #include #include #include "host/libs/wayland/wayland_surfaces.h" namespace wayland { namespace internal { struct WaylandServerState; } // namespace internal // A Wayland compositing server that provides an interface for receiving frame // updates from a connected client. class WaylandServer { public: // Creates a Wayland compositing server. If specified, uses the given // socket file descriptor to connect with clients. If provided, this // server will close the file descriptor upon exit. WaylandServer(int wayland_socket_fd = -1); virtual ~WaylandServer(); WaylandServer(const WaylandServer& rhs) = delete; WaylandServer& operator=(const WaylandServer& rhs) = delete; WaylandServer(WaylandServer&& rhs) = delete; WaylandServer& operator=(WaylandServer&& rhs) = delete; // Blocks until the given callback is run on the next frame available. void OnNextFrame(const Surfaces::FrameCallback& callback); private: void ServerLoop(int wayland_socket_fd); bool server_ready_ = false; std::mutex server_ready_mutex_; std::condition_variable server_ready_cv_; std::thread server_thread_; std::unique_ptr server_state_; }; } // namespace wayland