• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_server_callbacks.h"
28 #include "host/libs/wayland/wayland_surfaces.h"
29 
30 namespace wayland {
31 
32 namespace internal {
33 struct WaylandServerState;
34 }  // namespace internal
35 
36 // A Wayland compositing server that provides an interface for receiving frame
37 // updates from a connected client.
38 class WaylandServer {
39   public:
40     // Creates a Wayland compositing server. If specified, uses the given
41     // socket file descriptor to connect with clients. If provided, this
42     // server will close the file descriptor upon exit.
43     WaylandServer(int wayland_socket_fd = -1);
44     virtual ~WaylandServer();
45 
46     WaylandServer(const WaylandServer& rhs) = delete;
47     WaylandServer& operator=(const WaylandServer& rhs) = delete;
48 
49     WaylandServer(WaylandServer&& rhs) = delete;
50     WaylandServer& operator=(WaylandServer&& rhs) = delete;
51 
52     // Registers the callback that will be run whenever a new frame is
53     // available.
54     void SetFrameCallback(Surfaces::FrameCallback callback);
55 
56     void SetDisplayEventCallback(DisplayEventCallback callback);
57 
58    private:
59     void ServerLoop(int wayland_socket_fd);
60 
61     bool server_ready_ = false;
62     std::mutex server_ready_mutex_;
63     std::condition_variable server_ready_cv_;
64 
65     std::thread server_thread_;
66     std::unique_ptr<internal::WaylandServerState> server_state_;
67 };
68 
69 }  // namespace wayland