Android-cuttlefish cvd tool
wayland_surfaces.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2020 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 <stdint.h>
20#include <future>
21#include <memory>
22#include <mutex>
23#include <optional>
24#include <thread>
25#include <unordered_map>
26
28
29namespace wayland {
30
31class Surface;
32
33class Surfaces {
34 public:
35 Surfaces() = default;
36 virtual ~Surfaces() = default;
37
38 Surfaces(const Surfaces& rhs) = delete;
39 Surfaces& operator=(const Surfaces& rhs) = delete;
40
41 Surfaces(Surfaces&& rhs) = delete;
42 Surfaces& operator=(Surfaces&& rhs) = delete;
43
45 std::function<void(std::uint32_t /*display_number*/, //
46 std::uint32_t /*frame_width*/, //
47 std::uint32_t /*frame_height*/, //
48 std::uint32_t /*frame_fourcc_format*/, //
49 std::uint32_t /*frame_stride_bytes*/, //
50 std::uint8_t* /*frame_bytes*/)>;
51
52 void SetFrameCallback(FrameCallback callback);
53
55
56 void SetFramesAreRGBA(bool frames_are_rgba);
57
58 private:
59 friend class Surface;
60 void HandleSurfaceFrame(std::uint32_t display_number, //
61 std::uint32_t frame_width, //
62 std::uint32_t frame_height, //
63 std::uint32_t frame_fourcc_format, //
64 std::uint32_t frame_stride_bytes, //
65 std::uint8_t* frame_bytes);
66
67 void HandleSurfaceCreated(std::uint32_t display_number,
68 std::uint32_t display_width,
69 std::uint32_t display_height);
70
71 void HandleSurfaceDestroyed(std::uint32_t display_number);
72
73 std::mutex callback_mutex_;
74 std::optional<FrameCallback> callback_;
75 std::optional<DisplayEventCallback> event_callback_;
76 // If true, report that the received frames are RGBA regardless
77 // of the format reported by the wayland client.
78 bool frames_are_rgba_ = false;
79};
80
81} // namespace wayland
Definition: wayland_surface.h:31
Definition: wayland_surfaces.h:33
Surfaces()=default
std::optional< FrameCallback > callback_
Definition: wayland_surfaces.h:74
void HandleSurfaceDestroyed(std::uint32_t display_number)
Definition: wayland_surfaces.cpp:74
Surfaces(Surfaces &&rhs)=delete
std::function< void(std::uint32_t, std::uint32_t, std::uint32_t, std::uint32_t, std::uint32_t, std::uint8_t *)> FrameCallback
Definition: wayland_surfaces.h:50
void HandleSurfaceCreated(std::uint32_t display_number, std::uint32_t display_width, std::uint32_t display_height)
Definition: wayland_surfaces.cpp:59
void SetFramesAreRGBA(bool frames_are_rgba)
Definition: wayland_surfaces.cpp:37
virtual ~Surfaces()=default
bool frames_are_rgba_
Definition: wayland_surfaces.h:78
void SetDisplayEventCallback(DisplayEventCallback callback)
Definition: wayland_surfaces.cpp:32
void HandleSurfaceFrame(std::uint32_t display_number, std::uint32_t frame_width, std::uint32_t frame_height, std::uint32_t frame_fourcc_format, std::uint32_t frame_stride_bytes, std::uint8_t *frame_bytes)
Definition: wayland_surfaces.cpp:41
std::mutex callback_mutex_
Definition: wayland_surfaces.h:73
Surfaces(const Surfaces &rhs)=delete
void SetFrameCallback(FrameCallback callback)
Definition: wayland_surfaces.cpp:27
Surfaces & operator=(const Surfaces &rhs)=delete
Surfaces & operator=(Surfaces &&rhs)=delete
std::optional< DisplayEventCallback > event_callback_
Definition: wayland_surfaces.h:75
Definition: wayland_compositor.cpp:27
std::function< void(const DisplayEvent &)> DisplayEventCallback
Definition: wayland_server_callbacks.h:34