blob: a831c5e850c4ca46ba901bbdc223f7b1977a9a66 [file] [log] [blame]
fei.dengf7a0cd32023-08-29 09:36:37 +00001/*
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.dengf7a0cd32023-08-29 09:36:37 +000022#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.dengb9a1a572023-09-13 01:33:57 +000033#include "Poll.h"
fei.dengf7a0cd32023-08-29 09:36:37 +000034#include "render_common.h"
35#include "wstclient_socket.h"
36
37using namespace std;
38
39class WstClientPlugin;
40
41class WstClientWayland : public Tls::Thread{
42 public:
fei.dengb9a1a572023-09-13 01:33:57 +000043 WstClientWayland(WstClientPlugin *plugin, int logCategory);
fei.dengf7a0cd32023-08-29 09:36:37 +000044 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 };
95
96 void setZoomMode(int zoomMode, bool globalZoomActive, bool allow4kZoom);
97
98 /**callback functions**/
99 static void shellSurfaceId(void *data,
100 struct wl_simple_shell *wl_simple_shell,
101 struct wl_surface *surface,
102 uint32_t surfaceId);
103 static void shellSurfaceCreated(void *data,
104 struct wl_simple_shell *wl_simple_shell,
105 uint32_t surfaceId,
106 const char *name);
107 static void shellSurfaceDestroyed(void *data,
108 struct wl_simple_shell *wl_simple_shell,
109 uint32_t surfaceId,
110 const char *name);
111 static void shellSurfaceStatus(void *data,
112 struct wl_simple_shell *wl_simple_shell,
113 uint32_t surfaceId,
114 const char *name,
115 uint32_t visible,
116 int32_t x,
117 int32_t y,
118 int32_t width,
119 int32_t height,
120 wl_fixed_t opacity,
121 wl_fixed_t zorder);
122 static void shellGetSurfacesDone(void *data, struct wl_simple_shell *wl_simple_shell);
123 static void vpcVideoPathChange(void *data,
124 struct wl_vpc_surface *wl_vpc_surface,
125 uint32_t new_pathway );
126 static void vpcVideoXformChange(void *data,
127 struct wl_vpc_surface *wl_vpc_surface,
128 int32_t x_translation,
129 int32_t y_translation,
130 uint32_t x_scale_num,
131 uint32_t x_scale_denom,
132 uint32_t y_scale_num,
133 uint32_t y_scale_denom,
134 uint32_t output_width,
135 uint32_t output_height);
136 static void outputHandleGeometry( void *data,
137 struct wl_output *output,
138 int x,
139 int y,
140 int mmWidth,
141 int mmHeight,
142 int subPixel,
143 const char *make,
144 const char *model,
145 int transform );
146 static void outputHandleMode( void *data,
147 struct wl_output *output,
148 uint32_t flags,
149 int width,
150 int height,
151 int refreshRate );
152 static void outputHandleDone( void *data,
153 struct wl_output *output );
154 static void outputHandleScale( void *data,
155 struct wl_output *output,
156 int32_t scale );
157 static void sbFormat(void *data, struct wl_sb *wl_sb, uint32_t format);
158 static void registryHandleGlobal (void *data, struct wl_registry *registry,
159 uint32_t id, const char *interface, uint32_t version);
160 static void registryHandleGlobalRemove (void *data, struct wl_registry *registry, uint32_t name);
161 private:
162 void updateVideoPosition();
163 void setVideoPath(bool useGfxPath);
164 bool approxEqual( double v1, double v2);
165 void executeCmd(const char *cmd);
166 WstClientPlugin *mPlugin;
167 struct wl_display *mWlDisplay;
168 struct wl_event_queue *mWlQueue;
169 struct wl_surface *mWlSurface;
170 struct wl_vpc *mWlVpc;
171 struct wl_vpc_surface *mWlVpcSurface;
172 struct wl_output *mWlOutput;
173 struct wl_simple_shell *mWlShell;
174 uint32_t mWlShellSurfaceId;
175 struct wl_sb *mWlSb;
176 struct wl_registry *mWlRegistry;
177 struct wl_compositor *mWlCompositor;
178
fei.dengb9a1a572023-09-13 01:33:57 +0000179 int mLogCategory;
180
fei.dengf7a0cd32023-08-29 09:36:37 +0000181 int mTransX;
182 int mTransY;
183 int mScaleXNum;
184 int mScaleXDenom;
185 int mScaleYNum;
186 int mScaleYDenom;
187 int mOutputWidth;
188 int mOutputHeight;
189
190 int mDisplayWidth; //the terminal display width
191 int mDisplayHeight; //the terminal display width
192 int mWindowX;
193 int mWindowY;
194 int mWindowWidth; //the window width set
195 int mWindowHeight; //the window height set
196
197 int mVideoX;
198 int mVideoY;
199 int mVideoWidth;
200 int mVideoHeight;
201
202 bool mVideoPaused;
203
204 bool mWindowSet; //the window size set flag
205 bool mWindowSizeOverride; //the window size override
206 bool mWindowChange;
207
208 int mFrameWidth;
209 int mFrameHeight;
210
211 bool mForceAspectRatio;
212 double mPixelAspectRatio;
213 bool mPixelAspectRatioChanged;
214 float mOpacity;
215 float mZorder;
216
217 int mZoomMode;
218 bool mZoomModeGlobal;
219 bool mAllow4kZoom;
220
fei.dengb9a1a572023-09-13 01:33:57 +0000221 mutable Tls::Mutex mMutex;
fei.dengf7a0cd32023-08-29 09:36:37 +0000222 int mFd;
fei.dengb9a1a572023-09-13 01:33:57 +0000223 Tls::Poll *mPoll;
fei.dengf7a0cd32023-08-29 09:36:37 +0000224
225 bool mForceFullScreen;
226};
227
228#endif /*__WST_CLIENT_WAYLAND_H__*/