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 #include "host/libs/wayland/wayland_surfaces.h"
18
19 #include <android-base/logging.h>
20 #include <wayland-server-protocol.h>
21
22 #include "host/libs/wayland/wayland_surface.h"
23
24 namespace wayland {
25
SetFrameCallback(FrameCallback callback)26 void Surfaces::SetFrameCallback(FrameCallback callback) {
27 std::unique_lock<std::mutex> lock(callback_mutex_);
28 callback_.emplace(std::move(callback));
29 }
30
SetDisplayEventCallback(DisplayEventCallback callback)31 void Surfaces::SetDisplayEventCallback(DisplayEventCallback callback) {
32 std::unique_lock<std::mutex> lock(callback_mutex_);
33 event_callback_.emplace(std::move(callback));
34 }
35
HandleSurfaceFrame(std::uint32_t display_number,std::uint32_t frame_width,std::uint32_t frame_height,std::uint32_t frame_stride_bytes,std::uint8_t * frame_bytes)36 void Surfaces::HandleSurfaceFrame(std::uint32_t display_number,
37 std::uint32_t frame_width,
38 std::uint32_t frame_height,
39 std::uint32_t frame_stride_bytes,
40 std::uint8_t* frame_bytes) {
41 std::unique_lock<std::mutex> lock(callback_mutex_);
42 if (callback_) {
43 (callback_.value())(display_number, frame_width, frame_height,
44 frame_stride_bytes, frame_bytes);
45 }
46 }
47
HandleSurfaceCreated(std::uint32_t display_number,std::uint32_t display_width,std::uint32_t display_height)48 void Surfaces::HandleSurfaceCreated(std::uint32_t display_number,
49 std::uint32_t display_width,
50 std::uint32_t display_height) {
51 const DisplayEvent event{DisplayCreatedEvent{
52 .display_number = display_number,
53 .display_width = display_width,
54 .display_height = display_height,
55 }};
56
57 std::unique_lock<std::mutex> lock(callback_mutex_);
58 if (event_callback_) {
59 (event_callback_.value())(event);
60 }
61 }
62
HandleSurfaceDestroyed(std::uint32_t display_number)63 void Surfaces::HandleSurfaceDestroyed(std::uint32_t display_number) {
64 const DisplayEvent event{DisplayDestroyedEvent{
65 .display_number = display_number,
66 }};
67
68 std::unique_lock<std::mutex> lock(callback_mutex_);
69 if (event_callback_) {
70 (event_callback_.value())(event);
71 }
72 }
73
74 } // namespace wayland