fei.deng | f7a0cd3 | 2023-08-29 09:36:37 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2021 Amlogic Corporation. |
| 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 | #ifndef __WST_CLIENT_WAYLAND_H__ |
| 17 | #define __WST_CLIENT_WAYLAND_H__ |
| 18 | #include <stdint.h> |
| 19 | #include <stdlib.h> |
| 20 | #include <pthread.h> |
| 21 | #include <poll.h> |
fei.deng | f7a0cd3 | 2023-08-29 09:36:37 +0000 | [diff] [blame] | 22 | #include <list> |
| 23 | #include <wayland-client.h> |
| 24 | #include "xdg-shell-client-protocol.h" |
| 25 | #include "fullscreen-shell-unstable-v1-client-protocol.h" |
| 26 | #include "linux-dmabuf-unstable-v1-client-protocol.h" |
| 27 | #include "linux-explicit-synchronization-unstable-v1-client-protocol.h" |
| 28 | #include "viewporter-client-protocol.h" |
| 29 | #include "simpleshell-client-protocol.h" |
| 30 | #include "vpc-client-protocol.h" |
| 31 | #include "simplebuffer-client-protocol.h" |
| 32 | #include "Thread.h" |
fei.deng | b9a1a57 | 2023-09-13 01:33:57 +0000 | [diff] [blame] | 33 | #include "Poll.h" |
fei.deng | f7a0cd3 | 2023-08-29 09:36:37 +0000 | [diff] [blame] | 34 | #include "render_common.h" |
| 35 | #include "wstclient_socket.h" |
| 36 | |
| 37 | using namespace std; |
| 38 | |
| 39 | class WstClientPlugin; |
| 40 | |
| 41 | class WstClientWayland : public Tls::Thread{ |
| 42 | public: |
fei.deng | b9a1a57 | 2023-09-13 01:33:57 +0000 | [diff] [blame] | 43 | WstClientWayland(WstClientPlugin *plugin, int logCategory); |
fei.deng | f7a0cd3 | 2023-08-29 09:36:37 +0000 | [diff] [blame] | 44 | virtual ~WstClientWayland(); |
| 45 | /** |
| 46 | * @brief connet client to compositor server |
| 47 | * and acquire a display from compositor |
| 48 | * |
| 49 | * @return int 0 success,other fail |
| 50 | */ |
| 51 | int connectToWayland(); |
| 52 | /** |
| 53 | * @brief release display that acquired from compositor |
| 54 | * |
| 55 | */ |
| 56 | void disconnectFromWayland(); |
| 57 | |
| 58 | //thread func |
| 59 | void readyToRun(); |
| 60 | virtual bool threadLoop(); |
| 61 | |
| 62 | void getVideoBounds(int *x, int *y, int *w, int *h); |
| 63 | |
| 64 | void setTextureCrop(int vx, int vy, int vw, int vh); |
| 65 | |
| 66 | void setForceAspectRatio(bool force); |
| 67 | |
| 68 | void setPixelAspectRatio(double ratio); |
| 69 | |
| 70 | struct wl_display *getWlDisplay() { |
| 71 | return mWlDisplay; |
| 72 | }; |
| 73 | struct wl_compositor * getWlCompositor() |
| 74 | { |
| 75 | return mWlCompositor; |
| 76 | }; |
| 77 | struct wl_event_queue *getWlEventQueue() { |
| 78 | return mWlQueue; |
| 79 | }; |
| 80 | |
| 81 | void setWindowSize(int x, int y, int w, int h); |
| 82 | |
| 83 | void getWindowSize(int *x, int *y, int *w, int *h) { |
| 84 | *x = mWindowX; |
| 85 | *y = mWindowY; |
| 86 | *w = mWindowWidth; |
| 87 | *h = mWindowHeight; |
| 88 | }; |
| 89 | void setFrameSize(int frameWidth, int frameHeight); |
| 90 | |
| 91 | void getFrameSize(int *w, int *h) { |
| 92 | *w = mFrameWidth; |
| 93 | *h = mFrameHeight; |
| 94 | }; |
sheng.liu | a7baed7 | 2024-01-24 07:31:24 +0000 | [diff] [blame^] | 95 | void setPause(bool paused) |
| 96 | { |
| 97 | mVideoPaused = paused; |
| 98 | }; |
fei.deng | f7a0cd3 | 2023-08-29 09:36:37 +0000 | [diff] [blame] | 99 | |
| 100 | void setZoomMode(int zoomMode, bool globalZoomActive, bool allow4kZoom); |
| 101 | |
| 102 | /**callback functions**/ |
| 103 | static void shellSurfaceId(void *data, |
| 104 | struct wl_simple_shell *wl_simple_shell, |
| 105 | struct wl_surface *surface, |
| 106 | uint32_t surfaceId); |
| 107 | static void shellSurfaceCreated(void *data, |
| 108 | struct wl_simple_shell *wl_simple_shell, |
| 109 | uint32_t surfaceId, |
| 110 | const char *name); |
| 111 | static void shellSurfaceDestroyed(void *data, |
| 112 | struct wl_simple_shell *wl_simple_shell, |
| 113 | uint32_t surfaceId, |
| 114 | const char *name); |
| 115 | static void shellSurfaceStatus(void *data, |
| 116 | struct wl_simple_shell *wl_simple_shell, |
| 117 | uint32_t surfaceId, |
| 118 | const char *name, |
| 119 | uint32_t visible, |
| 120 | int32_t x, |
| 121 | int32_t y, |
| 122 | int32_t width, |
| 123 | int32_t height, |
| 124 | wl_fixed_t opacity, |
| 125 | wl_fixed_t zorder); |
| 126 | static void shellGetSurfacesDone(void *data, struct wl_simple_shell *wl_simple_shell); |
| 127 | static void vpcVideoPathChange(void *data, |
| 128 | struct wl_vpc_surface *wl_vpc_surface, |
| 129 | uint32_t new_pathway ); |
| 130 | static void vpcVideoXformChange(void *data, |
| 131 | struct wl_vpc_surface *wl_vpc_surface, |
| 132 | int32_t x_translation, |
| 133 | int32_t y_translation, |
| 134 | uint32_t x_scale_num, |
| 135 | uint32_t x_scale_denom, |
| 136 | uint32_t y_scale_num, |
| 137 | uint32_t y_scale_denom, |
| 138 | uint32_t output_width, |
| 139 | uint32_t output_height); |
| 140 | static void outputHandleGeometry( void *data, |
| 141 | struct wl_output *output, |
| 142 | int x, |
| 143 | int y, |
| 144 | int mmWidth, |
| 145 | int mmHeight, |
| 146 | int subPixel, |
| 147 | const char *make, |
| 148 | const char *model, |
| 149 | int transform ); |
| 150 | static void outputHandleMode( void *data, |
| 151 | struct wl_output *output, |
| 152 | uint32_t flags, |
| 153 | int width, |
| 154 | int height, |
| 155 | int refreshRate ); |
| 156 | static void outputHandleDone( void *data, |
| 157 | struct wl_output *output ); |
| 158 | static void outputHandleScale( void *data, |
| 159 | struct wl_output *output, |
| 160 | int32_t scale ); |
| 161 | static void sbFormat(void *data, struct wl_sb *wl_sb, uint32_t format); |
| 162 | static void registryHandleGlobal (void *data, struct wl_registry *registry, |
| 163 | uint32_t id, const char *interface, uint32_t version); |
| 164 | static void registryHandleGlobalRemove (void *data, struct wl_registry *registry, uint32_t name); |
| 165 | private: |
| 166 | void updateVideoPosition(); |
| 167 | void setVideoPath(bool useGfxPath); |
| 168 | bool approxEqual( double v1, double v2); |
| 169 | void executeCmd(const char *cmd); |
| 170 | WstClientPlugin *mPlugin; |
| 171 | struct wl_display *mWlDisplay; |
| 172 | struct wl_event_queue *mWlQueue; |
| 173 | struct wl_surface *mWlSurface; |
| 174 | struct wl_vpc *mWlVpc; |
| 175 | struct wl_vpc_surface *mWlVpcSurface; |
| 176 | struct wl_output *mWlOutput; |
| 177 | struct wl_simple_shell *mWlShell; |
| 178 | uint32_t mWlShellSurfaceId; |
| 179 | struct wl_sb *mWlSb; |
| 180 | struct wl_registry *mWlRegistry; |
| 181 | struct wl_compositor *mWlCompositor; |
| 182 | |
fei.deng | b9a1a57 | 2023-09-13 01:33:57 +0000 | [diff] [blame] | 183 | int mLogCategory; |
| 184 | |
fei.deng | f7a0cd3 | 2023-08-29 09:36:37 +0000 | [diff] [blame] | 185 | int mTransX; |
| 186 | int mTransY; |
| 187 | int mScaleXNum; |
| 188 | int mScaleXDenom; |
| 189 | int mScaleYNum; |
| 190 | int mScaleYDenom; |
| 191 | int mOutputWidth; |
| 192 | int mOutputHeight; |
| 193 | |
| 194 | int mDisplayWidth; //the terminal display width |
| 195 | int mDisplayHeight; //the terminal display width |
| 196 | int mWindowX; |
| 197 | int mWindowY; |
| 198 | int mWindowWidth; //the window width set |
| 199 | int mWindowHeight; //the window height set |
| 200 | |
| 201 | int mVideoX; |
| 202 | int mVideoY; |
| 203 | int mVideoWidth; |
| 204 | int mVideoHeight; |
| 205 | |
| 206 | bool mVideoPaused; |
| 207 | |
| 208 | bool mWindowSet; //the window size set flag |
| 209 | bool mWindowSizeOverride; //the window size override |
| 210 | bool mWindowChange; |
| 211 | |
| 212 | int mFrameWidth; |
| 213 | int mFrameHeight; |
| 214 | |
| 215 | bool mForceAspectRatio; |
| 216 | double mPixelAspectRatio; |
| 217 | bool mPixelAspectRatioChanged; |
| 218 | float mOpacity; |
| 219 | float mZorder; |
| 220 | |
| 221 | int mZoomMode; |
| 222 | bool mZoomModeGlobal; |
| 223 | bool mAllow4kZoom; |
| 224 | |
fei.deng | b9a1a57 | 2023-09-13 01:33:57 +0000 | [diff] [blame] | 225 | mutable Tls::Mutex mMutex; |
fei.deng | f7a0cd3 | 2023-08-29 09:36:37 +0000 | [diff] [blame] | 226 | int mFd; |
fei.deng | b9a1a57 | 2023-09-13 01:33:57 +0000 | [diff] [blame] | 227 | Tls::Poll *mPoll; |
fei.deng | f7a0cd3 | 2023-08-29 09:36:37 +0000 | [diff] [blame] | 228 | |
| 229 | bool mForceFullScreen; |
| 230 | }; |
| 231 | |
| 232 | #endif /*__WST_CLIENT_WAYLAND_H__*/ |