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 #include "host/libs/screen_connector/wayland_screen_connector.h"
18
19 #include <unistd.h>
20 #include <fcntl.h>
21
22 #include <future>
23
24 #include <android-base/logging.h>
25
26 #include "host/libs/wayland/wayland_server.h"
27
28 namespace cuttlefish {
29
WaylandScreenConnector(int frames_fd)30 WaylandScreenConnector::WaylandScreenConnector(int frames_fd) {
31 int wayland_fd = fcntl(frames_fd, F_DUPFD_CLOEXEC, 3);
32 CHECK(wayland_fd != -1) << "Unable to dup server, errno " << errno;
33 close(frames_fd);
34
35 server_.reset(new wayland::WaylandServer(wayland_fd));
36 }
37
OnFrameAfter(std::uint32_t frame_number,const FrameCallback & frame_callback)38 bool WaylandScreenConnector::OnFrameAfter(
39 std::uint32_t frame_number, const FrameCallback& frame_callback) {
40 std::future<void> frame_callback_completed_future =
41 server_->OnFrameAfter(frame_number, frame_callback);
42
43 frame_callback_completed_future.get();
44
45 return true;
46 }
47
48 } // namespace cuttlefish