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 27 #include "host/libs/wayland/wayland_server_callbacks.h" 28 29 namespace wayland { 30 31 class Surface; 32 33 class 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 44 using FrameCallback = 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_stride_bytes*/, // 49 std::uint8_t* /*frame_bytes*/)>; 50 51 void SetFrameCallback(FrameCallback callback); 52 53 void SetDisplayEventCallback(DisplayEventCallback callback); 54 55 private: 56 friend class Surface; 57 void HandleSurfaceFrame(std::uint32_t display_number, // 58 std::uint32_t frame_width, // 59 std::uint32_t frame_height, // 60 std::uint32_t frame_stride_bytes, // 61 std::uint8_t* frame_bytes); 62 63 void HandleSurfaceCreated(std::uint32_t display_number, 64 std::uint32_t display_width, 65 std::uint32_t display_height); 66 67 void HandleSurfaceDestroyed(std::uint32_t display_number); 68 69 std::mutex callback_mutex_; 70 std::optional<FrameCallback> callback_; 71 std::optional<DisplayEventCallback> event_callback_; 72 }; 73 74 } // namespace wayland 75