blob: d77f6c5787981ce76c10c00037fdbf3c881fb799 [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#include <cstring>
17#include "wstclient_wayland.h"
fei.dengb9a1a572023-09-13 01:33:57 +000018#include "ErrorCode.h"
fei.dengf7a0cd32023-08-29 09:36:37 +000019#include "Logger.h"
fei.dengb9a1a572023-09-13 01:33:57 +000020#include "wstclient_plugin.h"
fei.dengf7a0cd32023-08-29 09:36:37 +000021
22#ifndef MAX
23# define MAX(a,b) ((a) > (b)? (a) : (b))
24# define MIN(a,b) ((a) < (b)? (a) : (b))
25#endif
26
27#define WESTEROS_UNUSED(x) ((void)(x))
28
fei.dengb9a1a572023-09-13 01:33:57 +000029#define TAG "rlib:wstclient_wayland"
30
fei.dengf7a0cd32023-08-29 09:36:37 +000031#define DEFAULT_WINDOW_X (0)
32#define DEFAULT_WINDOW_Y (0)
33#define DEFAULT_WINDOW_WIDTH (1920)
34#define DEFAULT_WINDOW_HEIGHT (1080)
35//discuss with display team,outpu resolution is a fixed value(1920x1080)
36#define DEFAULT_OUTPUT_WIDTH (1920)
37#define DEFAULT_OUTPUT_HEIGHT (1080)
38
39#define AV_SYNC_SESSION_V_MONO 64
40
41enum
42{
43 ZOOM_NONE,
44 ZOOM_DIRECT,
45 ZOOM_NORMAL,
46 ZOOM_16_9_STRETCH,
47 ZOOM_4_3_PILLARBOX,
48 ZOOM_ZOOM,
49 ZOOM_GLOBAL
50};
51
52#define needBounds() (mForceAspectRatio || (mZoomMode != ZOOM_NONE))
53
54void WstClientWayland::shellSurfaceId(void *data,
55 struct wl_simple_shell *wl_simple_shell,
56 struct wl_surface *surface,
57 uint32_t surfaceId)
58{
59 WstClientWayland *self = static_cast<WstClientWayland *>(data);
60 self->mWlShellSurfaceId = surfaceId;
61 char name[32];
62 wl_fixed_t z, op;
63 WESTEROS_UNUSED(wl_simple_shell);
64 WESTEROS_UNUSED(surface);
65
66 sprintf( name, "westeros-surface-%x", surfaceId );
67 wl_simple_shell_set_name(self->mWlShell, surfaceId, name);
68 if ( (self->mWindowWidth == 0) || (self->mWindowHeight == 0) )
69 {
70 wl_simple_shell_set_visible(self->mWlShell, self->mWlShellSurfaceId, false);
71 }
72 else
73 {
74 wl_simple_shell_set_visible(self->mWlShell, self->mWlShellSurfaceId, true);
75 if (!self->mWlVpc)
76 {
77 wl_simple_shell_set_geometry(self->mWlShell, self->mWlShellSurfaceId, self->mWindowX, self->mWindowY, self->mWindowWidth, self->mWindowHeight );
78 }
79 }
80
81 z = wl_fixed_from_double(self->mZorder);
82 wl_simple_shell_set_zorder(self->mWlShell, self->mWlShellSurfaceId, z);
83 op = wl_fixed_from_double(self->mOpacity);
84 wl_simple_shell_set_opacity(self->mWlShell, self->mWlShellSurfaceId, op);
85 wl_simple_shell_get_status(self->mWlShell, self->mWlShellSurfaceId);
86
87 wl_display_flush(self->mWlDisplay);
88}
89
90void WstClientWayland::shellSurfaceCreated(void *data,
91 struct wl_simple_shell *wl_simple_shell,
92 uint32_t surfaceId,
93 const char *name)
94{
95 WESTEROS_UNUSED(data);
96 WESTEROS_UNUSED(wl_simple_shell);
97 WESTEROS_UNUSED(surfaceId);
98 WESTEROS_UNUSED(name);
99}
100
101void WstClientWayland::shellSurfaceDestroyed(void *data,
102 struct wl_simple_shell *wl_simple_shell,
103 uint32_t surfaceId,
104 const char *name)
105{
106 WESTEROS_UNUSED(data);
107 WESTEROS_UNUSED(wl_simple_shell);
108 WESTEROS_UNUSED(surfaceId);
109 WESTEROS_UNUSED(name);
110}
111
112void WstClientWayland::shellSurfaceStatus(void *data,
113 struct wl_simple_shell *wl_simple_shell,
114 uint32_t surfaceId,
115 const char *name,
116 uint32_t visible,
117 int32_t x,
118 int32_t y,
119 int32_t width,
120 int32_t height,
121 wl_fixed_t opacity,
122 wl_fixed_t zorder)
123{
124 WstClientWayland *self = static_cast<WstClientWayland *>(data);
125 WESTEROS_UNUSED(wl_simple_shell);
126 WESTEROS_UNUSED(surfaceId);
127 WESTEROS_UNUSED(name);
128 WESTEROS_UNUSED(x);
129 WESTEROS_UNUSED(y);
130 WESTEROS_UNUSED(width);
131 WESTEROS_UNUSED(height);
132
fei.dengb9a1a572023-09-13 01:33:57 +0000133 INFO(self->mLogCategory,"opacity: %d,zorder:%d", opacity,zorder);
fei.dengf7a0cd32023-08-29 09:36:37 +0000134 self->mWindowChange = true;
135 self->mOpacity = opacity;
136 self->mZorder = zorder;
137}
138
139void WstClientWayland::shellGetSurfacesDone(void *data, struct wl_simple_shell *wl_simple_shell)
140{
141 WESTEROS_UNUSED(data);
142 WESTEROS_UNUSED(wl_simple_shell);
143}
144
145static const struct wl_simple_shell_listener shellListener =
146{
147 WstClientWayland::shellSurfaceId,
148 WstClientWayland::shellSurfaceCreated,
149 WstClientWayland::shellSurfaceDestroyed,
150 WstClientWayland::shellSurfaceStatus,
151 WstClientWayland::shellGetSurfacesDone
152};
153
154void WstClientWayland::vpcVideoPathChange(void *data,
155 struct wl_vpc_surface *wl_vpc_surface,
156 uint32_t new_pathway )
157{
158 WESTEROS_UNUSED(wl_vpc_surface);
159 WstClientWayland *self = static_cast<WstClientWayland *>(data);
160
sheng.liua7baed72024-01-24 07:31:24 +0000161 INFO(self->mLogCategory,"new pathway: %d", new_pathway);
fei.dengf7a0cd32023-08-29 09:36:37 +0000162 self->setVideoPath(new_pathway == WL_VPC_SURFACE_PATHWAY_GRAPHICS);
163}
164
165void WstClientWayland::vpcVideoXformChange(void *data,
166 struct wl_vpc_surface *wl_vpc_surface,
167 int32_t x_translation,
168 int32_t y_translation,
169 uint32_t x_scale_num,
170 uint32_t x_scale_denom,
171 uint32_t y_scale_num,
172 uint32_t y_scale_denom,
173 uint32_t output_width,
174 uint32_t output_height)
175{
176 WESTEROS_UNUSED(wl_vpc_surface);
177 WstClientWayland *self = static_cast<WstClientWayland *>(data);
178
fei.dengb9a1a572023-09-13 01:33:57 +0000179 TRACE(self->mLogCategory,"x_trans:%d,y_trans:%d,x_scale_num:%d,x_scale_denom:%d,y_scale_num:%d,y_scale_denom:%d",\
fei.dengf7a0cd32023-08-29 09:36:37 +0000180 x_translation,y_translation,x_scale_num,x_scale_denom,y_scale_num,y_scale_denom);
fei.dengb9a1a572023-09-13 01:33:57 +0000181 TRACE(self->mLogCategory,"output_width:%d,output_height:%d",output_width,output_height);
fei.dengf7a0cd32023-08-29 09:36:37 +0000182 self->mTransX= x_translation;
183 self->mTransY= y_translation;
184 if ( x_scale_denom )
185 {
186 self->mScaleXNum= x_scale_num;
187 self->mScaleXDenom= x_scale_denom;
188 }
189 if ( y_scale_denom )
190 {
191 self->mScaleYNum = y_scale_num;
192 self->mScaleYDenom = y_scale_denom;
193 }
194 self->mOutputWidth= (int)output_width;
195 self->mOutputHeight= (int)output_height;
196
fei.dengb9a1a572023-09-13 01:33:57 +0000197 Tls::Mutex::Autolock _l(self->mMutex);
fei.dengf7a0cd32023-08-29 09:36:37 +0000198 self->updateVideoPosition();
199}
200
201static const struct wl_vpc_surface_listener vpcListener= {
202 WstClientWayland::vpcVideoPathChange,
203 WstClientWayland::vpcVideoXformChange
204};
205
206void WstClientWayland::outputHandleGeometry( void *data,
207 struct wl_output *output,
208 int x,
209 int y,
210 int mmWidth,
211 int mmHeight,
212 int subPixel,
213 const char *make,
214 const char *model,
215 int transform )
216{
217 WESTEROS_UNUSED(data);
218 WESTEROS_UNUSED(output);
219 WESTEROS_UNUSED(x);
220 WESTEROS_UNUSED(y);
221 WESTEROS_UNUSED(mmWidth);
222 WESTEROS_UNUSED(mmHeight);
223 WESTEROS_UNUSED(subPixel);
224 WESTEROS_UNUSED(make);
225 WESTEROS_UNUSED(model);
226 WESTEROS_UNUSED(transform);
227}
228
229void WstClientWayland::outputHandleMode( void *data,
230 struct wl_output *output,
231 uint32_t flags,
232 int width,
233 int height,
234 int refreshRate )
235{
236 WstClientWayland *self = static_cast<WstClientWayland *>(data);
237
238 if ( flags & WL_OUTPUT_MODE_CURRENT )
239 {
240 //output resolution is a fixed value(1920x1080)
241 width = DEFAULT_OUTPUT_WIDTH;
242 height = DEFAULT_OUTPUT_HEIGHT;
fei.dengb9a1a572023-09-13 01:33:57 +0000243 Tls::Mutex::Autolock _l(self->mMutex);
fei.dengf7a0cd32023-08-29 09:36:37 +0000244 self->mDisplayWidth = width;
245 self->mDisplayHeight = height;
sheng.liua7baed72024-01-24 07:31:24 +0000246 DEBUG(self->mLogCategory,"compositor sets window to (%dx%d)", width, height);
fei.dengf7a0cd32023-08-29 09:36:37 +0000247 if (!self->mWindowSet)
248 {
249 self->mWindowWidth = width;
250 self->mWindowHeight = height;
251 if (self->mWlVpcSurface)
252 {
fei.dengb9a1a572023-09-13 01:33:57 +0000253 TRACE(self->mLogCategory,"set window geometry:x:%d,y:%d,w:%d,h:%d",self->mWindowX,self->mWindowY,self->mWindowWidth,self->mWindowHeight);
fei.dengf7a0cd32023-08-29 09:36:37 +0000254 wl_vpc_surface_set_geometry(self->mWlVpcSurface, self->mWindowX, self->mWindowY, self->mWindowWidth, self->mWindowHeight);
255 }
256 }
257 }
258}
259
260void WstClientWayland::outputHandleDone( void *data,
261 struct wl_output *output )
262{
263 WESTEROS_UNUSED(data);
264 WESTEROS_UNUSED(output);
265}
266
267void WstClientWayland::outputHandleScale( void *data,
268 struct wl_output *output,
269 int32_t scale )
270{
271 WESTEROS_UNUSED(data);
272 WESTEROS_UNUSED(output);
273 WESTEROS_UNUSED(scale);
274}
275
276static const struct wl_output_listener outputListener = {
277 WstClientWayland::outputHandleGeometry,
278 WstClientWayland::outputHandleMode,
279 WstClientWayland::outputHandleDone,
280 WstClientWayland::outputHandleScale
281};
282
283void WstClientWayland::sbFormat(void *data, struct wl_sb *wl_sb, uint32_t format)
284{
285 WstClientWayland *self = static_cast<WstClientWayland *>(data);
286 WESTEROS_UNUSED(wl_sb);
287 WESTEROS_UNUSED(data);
sheng.liua7baed72024-01-24 07:31:24 +0000288 TRACE(self->mLogCategory,"registry: sbFormat: %X", format);
fei.dengf7a0cd32023-08-29 09:36:37 +0000289}
290
291static const struct wl_sb_listener sbListener = {
292 WstClientWayland::sbFormat
293};
294
295void
296WstClientWayland::registryHandleGlobal (void *data, struct wl_registry *registry,
297 uint32_t id, const char *interface, uint32_t version)
298{
299 WstClientWayland *self = static_cast<WstClientWayland *>(data);
fei.dengb9a1a572023-09-13 01:33:57 +0000300 TRACE(self->mLogCategory,"registryHandleGlobal,interface:%s,version:%d",interface,version);
fei.dengf7a0cd32023-08-29 09:36:37 +0000301
302 if (strcmp (interface, "wl_compositor") == 0) {
303 self->mWlCompositor = (struct wl_compositor *)wl_registry_bind (registry, id, &wl_compositor_interface, 1/*MIN (version, 3)*/);
304 wl_proxy_set_queue((struct wl_proxy*)self->mWlCompositor, self->mWlQueue);
fei.dengb9a1a572023-09-13 01:33:57 +0000305 TRACE(self->mLogCategory,"registry: compositor %p\n", (void*)self->mWlCompositor);
fei.dengf7a0cd32023-08-29 09:36:37 +0000306 } else if (strcmp (interface, "wl_simple_shell") == 0) {
307 self->mWlShell = (struct wl_simple_shell*)wl_registry_bind(registry, id, &wl_simple_shell_interface, 1);
308 wl_proxy_set_queue((struct wl_proxy*)self->mWlShell, self->mWlQueue);
309 wl_simple_shell_add_listener(self->mWlShell, &shellListener, (void *)self);
fei.dengb9a1a572023-09-13 01:33:57 +0000310 TRACE(self->mLogCategory,"registry: simple shell %p\n", (void*)self->mWlShell);
fei.dengf7a0cd32023-08-29 09:36:37 +0000311 } else if (strcmp (interface, "wl_vpc") == 0) {
312 self->mWlVpc = (struct wl_vpc*)wl_registry_bind(registry, id, &wl_vpc_interface, 1);
313 wl_proxy_set_queue((struct wl_proxy*)self->mWlVpc, self->mWlQueue);
fei.dengb9a1a572023-09-13 01:33:57 +0000314 TRACE(self->mLogCategory,"registry: vpc %p\n", (void*)self->mWlVpc);
fei.dengf7a0cd32023-08-29 09:36:37 +0000315 } else if (strcmp (interface, "wl_output") == 0) {
316 self->mWlOutput = (struct wl_output*)wl_registry_bind(registry, id, &wl_output_interface, 2);
317 wl_proxy_set_queue((struct wl_proxy*)self->mWlOutput, self->mWlQueue);
318 wl_output_add_listener(self->mWlOutput, &outputListener, (void *)self);
fei.dengb9a1a572023-09-13 01:33:57 +0000319 TRACE(self->mLogCategory,"registry: output %p\n", (void*)self->mWlOutput);
fei.dengf7a0cd32023-08-29 09:36:37 +0000320 } else if (strcmp (interface, "wl_sb") == 0) {
321 self->mWlSb = (struct wl_sb*)wl_registry_bind(registry, id, &wl_sb_interface, version);
322 wl_proxy_set_queue((struct wl_proxy*)self->mWlSb, self->mWlQueue);
323 wl_sb_add_listener(self->mWlSb, &sbListener, (void *)self);
fei.dengb9a1a572023-09-13 01:33:57 +0000324 TRACE(self->mLogCategory,"registry: sb %p\n", (void*)self->mWlSb);
fei.dengf7a0cd32023-08-29 09:36:37 +0000325 }
326}
327
328void
329WstClientWayland::registryHandleGlobalRemove (void *data, struct wl_registry *registry, uint32_t name)
330{
331 WstClientWayland *self = static_cast<WstClientWayland *>(data);
332 /* temporarily do nothing */
fei.dengb9a1a572023-09-13 01:33:57 +0000333 DEBUG(self->mLogCategory,"wayland display remove registry handle global");
fei.dengf7a0cd32023-08-29 09:36:37 +0000334}
335
336static const struct wl_registry_listener registry_listener = {
337 WstClientWayland::registryHandleGlobal,
338 WstClientWayland::registryHandleGlobalRemove
339};
340
fei.dengb9a1a572023-09-13 01:33:57 +0000341WstClientWayland::WstClientWayland(WstClientPlugin *plugin, int logCategory)
342 :mMutex("bufferMutex"),
343 mPlugin(plugin),
344 mLogCategory(logCategory)
fei.dengf7a0cd32023-08-29 09:36:37 +0000345{
fei.dengb9a1a572023-09-13 01:33:57 +0000346 TRACE(mLogCategory,"construct WstClientWayland");
fei.dengf7a0cd32023-08-29 09:36:37 +0000347 mWlDisplay = NULL;
348 mWlQueue = NULL;
349 mWlRegistry = NULL;
350 mWlCompositor = NULL;
351 mWlSurface = NULL;
352 mWlVpc = NULL;
353 mWlVpcSurface = NULL;
354 mWlOutput = NULL;
355 mWlShell = NULL;
356 mWlSb = NULL;
357 mDisplayWidth = DEFAULT_OUTPUT_WIDTH;
358 mDisplayHeight = DEFAULT_OUTPUT_HEIGHT;
359 mWindowX = DEFAULT_WINDOW_X;
360 mWindowY = DEFAULT_WINDOW_Y;
361 mWindowWidth = DEFAULT_WINDOW_WIDTH;
362 mWindowHeight = DEFAULT_WINDOW_HEIGHT;
363 mVideoX = mWindowX;
364 mVideoY = mWindowY;
365 mVideoWidth = mWindowWidth;
366 mVideoHeight = mWindowHeight;
367 mWlShellSurfaceId = 0;
368 mWindowChange = false;
369 mWindowSet = false;
370 mWindowSizeOverride = false;
371 mZoomMode = ZOOM_NONE;
372 mZoomModeGlobal = false;
373 mAllow4kZoom = false;
374 mFrameWidth = 0;
375 mFrameHeight = 0;
376 mForceAspectRatio = false;
377 mPixelAspectRatio = 1.0;
378 mScaleXDenom = 0;
379 mScaleYDenom = 0;
380 mForceFullScreen = false;
sheng.liua7baed72024-01-24 07:31:24 +0000381 mVideoPaused = false;
fei.dengb9a1a572023-09-13 01:33:57 +0000382 mPoll = new Tls::Poll(true);
fei.dengf7a0cd32023-08-29 09:36:37 +0000383}
384
385WstClientWayland::~WstClientWayland()
386{
fei.dengb9a1a572023-09-13 01:33:57 +0000387 TRACE(mLogCategory,"deconstruct WstClientWayland");
388 if (mPoll) {
389 delete mPoll;
390 mPoll = NULL;
391 }
fei.dengf7a0cd32023-08-29 09:36:37 +0000392}
393
394int WstClientWayland::connectToWayland()
395{
396 const char *xdgEnv = NULL;
397 const char *displayEnv = NULL;
398 const char *displayName = "rlib-display";
399 const char *fullScreenEnV = NULL;
fei.dengb9a1a572023-09-13 01:33:57 +0000400 DEBUG(mLogCategory,"in");
fei.dengf7a0cd32023-08-29 09:36:37 +0000401 xdgEnv = getenv("XDG_RUNTIME_DIR");
fei.dengb9a1a572023-09-13 01:33:57 +0000402 INFO(mLogCategory,"XDG_RUNTIME_DIR:%s",xdgEnv != NULL?xdgEnv:"NULL");
fei.dengf7a0cd32023-08-29 09:36:37 +0000403 if (!xdgEnv) {
404 xdgEnv = "/run";
fei.dengb9a1a572023-09-13 01:33:57 +0000405 ERROR(mLogCategory,"XDG_RUNTIME_DIR is not set,set default %s",xdgEnv);
fei.dengf7a0cd32023-08-29 09:36:37 +0000406 }
407 displayEnv= getenv("WAYLAND_DISPLAY");
fei.dengb9a1a572023-09-13 01:33:57 +0000408 INFO(mLogCategory,"WAYLAND_DISPLAY:%s",displayEnv != NULL?displayEnv:"NULL");
fei.dengf7a0cd32023-08-29 09:36:37 +0000409
410 fullScreenEnV= getenv("VIDEO_RENDER_FORCE_FULLSCREEN");
fei.dengb9a1a572023-09-13 01:33:57 +0000411 INFO(mLogCategory,"VIDEO_RENDER_FORCE_FULLSCREEN:%s",fullScreenEnV != NULL?fullScreenEnV:"NULL");
fei.dengf7a0cd32023-08-29 09:36:37 +0000412 if (fullScreenEnV) {
413 int force = atoi(fullScreenEnV);
414 mForceFullScreen = force != 0? true: false;
fei.dengb9a1a572023-09-13 01:33:57 +0000415 INFO(mLogCategory,"VIDEO_RENDER_FORCE_FULLSCREEN:%d",mForceFullScreen);
fei.dengf7a0cd32023-08-29 09:36:37 +0000416 }
417
418 mWlDisplay = wl_display_connect(NULL);
419 if (!mWlDisplay) {
420 char waylandDisplay[64];
fei.dengb9a1a572023-09-13 01:33:57 +0000421 ERROR(mLogCategory,"Failed connect to default wayland display");
fei.dengf7a0cd32023-08-29 09:36:37 +0000422 memset(waylandDisplay, 0, 64);
423 strcpy(waylandDisplay, xdgEnv);
424 strcat(waylandDisplay, "/" );
425 strcat(waylandDisplay, displayName);
fei.dengb9a1a572023-09-13 01:33:57 +0000426 INFO(mLogCategory,"detect rlib wayland display %s",waylandDisplay);
fei.dengf7a0cd32023-08-29 09:36:37 +0000427 if (access(waylandDisplay,F_OK) == 0) {
fei.dengb9a1a572023-09-13 01:33:57 +0000428 INFO(mLogCategory,"try to connect to %s",waylandDisplay);
fei.dengf7a0cd32023-08-29 09:36:37 +0000429 mWlDisplay = wl_display_connect(displayName);
430 }
431 /*try to create wayland display my self*/
432 if (!mWlDisplay && xdgEnv) {
fei.dengb9a1a572023-09-13 01:33:57 +0000433 WARNING(mLogCategory,"try to create and connect rlib-display display");
fei.dengf7a0cd32023-08-29 09:36:37 +0000434 std::string cmdCreateDisplay = R"(curl 'http://127.0.0.1:9998/jsonrpc' -d '{"jsonrpc": "2.0","id": 4,"method":
435 "org.rdk.RDKShell.1.createDisplay","params": { "client": "rlib-display", "displayName": "rlib-display" }}';echo)";
436 std::string cmdMoveDisplay = R"(curl 'http://127.0.0.1:9998/jsonrpc' -d '{"jsonrpc": "2.0","id": 4,"method":
437 "org.rdk.RDKShell.1.moveToBack", "params": { "client": "rlib-display" }}';echo)";
438
439 executeCmd(cmdCreateDisplay.c_str());
440 executeCmd(cmdMoveDisplay.c_str());
441 //try to connect again
442 mWlDisplay = wl_display_connect(displayName);
443 }
444
445 if (!mWlDisplay) {
fei.dengb9a1a572023-09-13 01:33:57 +0000446 ERROR(mLogCategory, "wayland connect rlib-display fail");
447 return ERROR_OPEN_FAIL;
fei.dengf7a0cd32023-08-29 09:36:37 +0000448 }
fei.denga8f4b902024-02-22 03:49:07 +0000449 setenv("XDG_RUNTIME_DIR",xdgEnv,0);
450 setenv("WAYLAND_DISPLAY",displayName,0);
fei.dengb9a1a572023-09-13 01:33:57 +0000451 INFO(mLogCategory,"wayland connected to rlib-display");
fei.dengf7a0cd32023-08-29 09:36:37 +0000452 }
453
454 mWlQueue = wl_display_create_queue (mWlDisplay);
455 wl_proxy_set_queue ((struct wl_proxy *)mWlDisplay, mWlQueue);
456
457 mWlRegistry = wl_display_get_registry (mWlDisplay);
458 wl_registry_add_listener (mWlRegistry, &registry_listener, (void *)this);
459
460 /* we need exactly 2 roundtrips to discover global objects and their state */
461 for (int i = 0; i < 2; i++) {
462 if (wl_display_roundtrip_queue (mWlDisplay, mWlQueue) < 0) {
fei.dengb9a1a572023-09-13 01:33:57 +0000463 ERROR(mLogCategory,"Error communicating with the wayland display");
464 return ERROR_OPEN_FAIL;
fei.dengf7a0cd32023-08-29 09:36:37 +0000465 }
466 }
467
468 //create surface from compositor
469 if (mWlCompositor) {
470 mWlSurface = wl_compositor_create_surface(mWlCompositor);
471 wl_proxy_set_queue((struct wl_proxy*)mWlSurface, mWlQueue);
472 wl_display_flush( mWlDisplay );
473 }
474
475 if (mWlVpc && mWlSurface) {
476 mWlVpcSurface = wl_vpc_get_vpc_surface( mWlVpc, mWlSurface );
477 if (mWlVpcSurface) {
478 wl_vpc_surface_add_listener( mWlVpcSurface, &vpcListener, (void *)this);
479 wl_proxy_set_queue((struct wl_proxy*)mWlVpcSurface, mWlQueue);
480 wl_vpc_surface_set_geometry( mWlVpcSurface, mWindowX, mWindowY, mWindowWidth, mWindowHeight);
481 wl_display_flush(mWlDisplay);
482 }
483 }
484
fei.dengb9a1a572023-09-13 01:33:57 +0000485 INFO(mLogCategory,"out");
486 return NO_ERROR;
fei.dengf7a0cd32023-08-29 09:36:37 +0000487}
488
489void WstClientWayland::disconnectFromWayland()
490{
fei.dengb9a1a572023-09-13 01:33:57 +0000491 INFO(mLogCategory,"in");
fei.dengf7a0cd32023-08-29 09:36:37 +0000492
493 if (isRunning()) {
fei.dengb9a1a572023-09-13 01:33:57 +0000494 TRACE(mLogCategory,"try stop dispatch thread");
495 if (mPoll) {
496 mPoll->setFlushing(true);
497 }
fei.dengf7a0cd32023-08-29 09:36:37 +0000498 requestExitAndWait();
499 }
500
501 if (mWlShell) {
502 wl_simple_shell_destroy(mWlShell);
503 mWlShell = NULL;
504 }
505
506 if (mWlVpcSurface) {
507 wl_vpc_surface_destroy(mWlVpcSurface);
508 mWlVpcSurface = NULL;
509 }
510
511 if (mWlVpc) {
512 wl_vpc_destroy(mWlVpc);
513 mWlVpc = NULL;
514 }
515
516 if (mWlSurface) {
517 wl_surface_destroy(mWlSurface);
518 mWlSurface = NULL;
519 }
520
521 if (mWlOutput) {
522 wl_output_destroy(mWlOutput);
523 mWlOutput = NULL;
524 }
525
526 if (mWlSb) {
527 wl_sb_destroy(mWlSb);
528 mWlSb = NULL;
529 }
530
531 if (mWlCompositor) {
532 wl_compositor_destroy (mWlCompositor);
533 mWlCompositor = NULL;
534 }
535
536 if (mWlRegistry) {
537 wl_registry_destroy (mWlRegistry);
538 mWlRegistry= NULL;
539 }
540
541 if (mWlQueue) {
542 wl_event_queue_destroy (mWlQueue);
543 mWlQueue = NULL;
544 }
545
546 if (mWlDisplay) {
547 wl_display_flush (mWlDisplay);
548 wl_display_disconnect (mWlDisplay);
fei.dengb9a1a572023-09-13 01:33:57 +0000549 INFO(mLogCategory,"wl display disconnect");
fei.dengf7a0cd32023-08-29 09:36:37 +0000550 mWlDisplay = NULL;
551 }
552
fei.dengb9a1a572023-09-13 01:33:57 +0000553 INFO(mLogCategory,"out");
fei.dengf7a0cd32023-08-29 09:36:37 +0000554}
555
556void WstClientWayland::setWindowSize(int x, int y, int w, int h)
557{
558 if (x == 0 && y == 0 && w == 0 && h == 0) {
fei.dengb9a1a572023-09-13 01:33:57 +0000559 WARNING(mLogCategory, "set full screen? %dx%dx%dx%d",x,y,w,h);
fei.dengf7a0cd32023-08-29 09:36:37 +0000560 return;
561 }
562 mWindowX = x;
563 mWindowY = y;
564 mWindowWidth = w;
565 mWindowHeight = h;
566 mWindowChange = true;
567 mWindowSet = true;
568 mWindowSizeOverride = true;
fei.dengb9a1a572023-09-13 01:33:57 +0000569 DEBUG(mLogCategory,"set window size:x:%d,y:%d,w:%d,h:%d",x,y,w,h);
sheng.liua7baed72024-01-24 07:31:24 +0000570
fei.dengf7a0cd32023-08-29 09:36:37 +0000571 if (mWlVpcSurface) {
fei.dengb9a1a572023-09-13 01:33:57 +0000572 DEBUG(mLogCategory, "wl_vpc_surface_set_geometry(%d,%d,%d,%d)",mWindowX,mWindowY,mWindowWidth,mWindowHeight);
fei.dengf7a0cd32023-08-29 09:36:37 +0000573 wl_vpc_surface_set_geometry(mWlVpcSurface, mWindowX, mWindowY, mWindowWidth, mWindowHeight);
574 }
575 //if window size is updated, update video position
sheng.liua7baed72024-01-24 07:31:24 +0000576 if (mVideoPaused && mWlVpcSurface && mWindowChange && mScaleXDenom != 0 && mScaleYDenom != 0) {
fei.dengf7a0cd32023-08-29 09:36:37 +0000577 mWindowChange = false;
578 updateVideoPosition();
579 }
sheng.liua7baed72024-01-24 07:31:24 +0000580
581 if (mWlDisplay) {
582 wl_display_flush( mWlDisplay );
583 }
fei.dengf7a0cd32023-08-29 09:36:37 +0000584}
585
586void WstClientWayland::setFrameSize(int frameWidth, int frameHeight) {
587 mFrameWidth = frameWidth;
588 mFrameHeight = frameHeight;
fei.dengb9a1a572023-09-13 01:33:57 +0000589 DEBUG(mLogCategory, "set frame size:%dx%d",mFrameWidth, mFrameHeight);
fei.dengf7a0cd32023-08-29 09:36:37 +0000590}
591
592void WstClientWayland::setZoomMode(int zoomMode, bool globalZoomActive, bool allow4kZoom) {
fei.dengb9a1a572023-09-13 01:33:57 +0000593 DEBUG(mLogCategory, "zoomMode:%d, globalZoomActive:%d, allow4kZoom:%d",zoomMode,globalZoomActive,allow4kZoom);
fei.dengf7a0cd32023-08-29 09:36:37 +0000594 mZoomModeGlobal = globalZoomActive;
595 if ( !globalZoomActive )
596 {
597 mZoomMode = ZOOM_NONE;
598 }
599 mAllow4kZoom= allow4kZoom;
600 if ( mZoomModeGlobal == true )
601 {
602 if ( (zoomMode >= ZOOM_NONE) && (zoomMode <= ZOOM_ZOOM) )
603 {
604 mZoomMode = zoomMode;
605 mPixelAspectRatioChanged = true;
606 }
607 } else {
fei.dengb9a1a572023-09-13 01:33:57 +0000608 DEBUG(mLogCategory, "global zoom disabled: ignore server value");
fei.dengf7a0cd32023-08-29 09:36:37 +0000609 }
610}
611
612void WstClientWayland::getVideoBounds(int *x, int *y, int *w, int *h)
613{
614 int vx, vy, vw, vh;
615 int frameWidth, frameHeight;
616 int zoomMode;
617 double contentWidth, contentHeight;
618 double roix, roiy, roiw, roih;
619 double arf, ard;
620 double hfactor= 1.0, vfactor= 1.0;
621
622 //if wayland open fail,use the default window size
623 if (!mWlDisplay) {
624 *x = mWindowX;
625 *y = mWindowY;
626 *w = mWindowWidth;
627 *h = mWindowHeight;
fei.dengb9a1a572023-09-13 01:33:57 +0000628 TRACE(mLogCategory, "no wldisplay, %d,%d,%d,%d",mVideoX,mVideoY,mVideoWidth,mVideoHeight);
fei.dengf7a0cd32023-08-29 09:36:37 +0000629 return;
630 }
631
632 //if window size is updated, update video position
633 if (mWlVpcSurface && mWindowChange) {
634 mWindowChange = false;
635 updateVideoPosition();
636 }
637
638 vx = mVideoX;
639 vy = mVideoY;
640 vw = mVideoWidth;
641 vh = mVideoHeight;
642
fei.dengb9a1a572023-09-13 01:33:57 +0000643 TRACE(mLogCategory, "videoX:%d,videoY:%d,videoW:%d,videoH:%d",mVideoX,mVideoY,mVideoWidth,mVideoHeight);
fei.dengf7a0cd32023-08-29 09:36:37 +0000644 //if the window size is smaller than display size,we scall video to map window size
645 if (mWindowWidth != mDisplayWidth || mWindowHeight != mDisplayHeight) {
646 *x= vx;
647 *y= vy;
648 *w= vw;
649 *h= vh;
fei.dengb9a1a572023-09-13 01:33:57 +0000650 TRACE(mLogCategory, "small window vrect %d, %d, %d, %d", vx, vy, vw, vh);
fei.dengf7a0cd32023-08-29 09:36:37 +0000651 return;
652 }
653 if (mForceFullScreen) {
654 *x= vx;
655 *y= vy;
656 *w= vw;
657 *h= vh;
fei.dengb9a1a572023-09-13 01:33:57 +0000658 TRACE(mLogCategory, "force window vrect %d, %d, %d, %d", vx, vy, vw, vh);
fei.dengf7a0cd32023-08-29 09:36:37 +0000659 return;
660 }
661
662 frameWidth = mFrameWidth;
663 frameHeight = mFrameHeight;
664 contentWidth = frameWidth * mPixelAspectRatio;
665 contentHeight = frameHeight;
666
667 if (mPixelAspectRatioChanged)
fei.dengb9a1a572023-09-13 01:33:57 +0000668 DEBUG(mLogCategory,"pixelAspectRatio: %f zoom-mode %d", mPixelAspectRatio, mZoomMode);
fei.dengf7a0cd32023-08-29 09:36:37 +0000669
670 ard = (double)mVideoWidth/(double)mVideoHeight;
671 arf = (double)contentWidth/(double)contentHeight;
672
fei.dengb9a1a572023-09-13 01:33:57 +0000673 TRACE(mLogCategory, "frameWidth:%d,frameHeight:%d,contentWidth:%f,contentHeight:%f",frameWidth,frameHeight,contentWidth,contentHeight);
fei.dengf7a0cd32023-08-29 09:36:37 +0000674
675 /* Establish region of interest */
676 roix = 0;
677 roiy = 0;
678 roiw = contentWidth;
679 roih = contentHeight;
680
681 zoomMode = mZoomMode;
682 if ((mFrameWidth > 1920) || (mFrameHeight > 1080))
683 {
684 zoomMode= ZOOM_NORMAL;
685 }
686 //if (mPixelAspectRatioChanged )
fei.dengb9a1a572023-09-13 01:33:57 +0000687 TRACE(mLogCategory, "ard %f arf %f", ard, arf);
fei.dengf7a0cd32023-08-29 09:36:37 +0000688 switch ( zoomMode )
689 {
690 case ZOOM_NORMAL:
691 {
692 if ( arf >= ard )
693 {
694 vw = mVideoWidth * (1.0);
695 vh = (roih * vw) / roiw;
696 vx = vx+(mVideoWidth-vw)/2;
697 vy = vy+(mVideoHeight-vh)/2;
698 }
699 else
700 {
701 vh = mVideoHeight * (1.0);
702 vw = (roiw * vh) / roih;
703 vx = vx+(mVideoWidth-vw)/2;
704 vy = vy+(mVideoHeight-vh)/2;
705 }
706 }
707 break;
708 case ZOOM_NONE:
709 case ZOOM_DIRECT:
710 {
711 if ( arf >= ard )
712 {
713 vh = (contentHeight * mVideoWidth) / contentWidth;
714 vy = vy+(mVideoHeight-vh)/2;
715 }
716 else
717 {
718 vw = (contentWidth * mVideoHeight) / contentHeight;
719 vx = vx+(mVideoWidth-vw)/2;
720 }
721 }
722 break;
723 case ZOOM_16_9_STRETCH:
724 {
725 if ( approxEqual(arf, ard) && approxEqual(arf, 1.777) )
726 {
727 /* For 16:9 content on a 16:9 display, stretch as though 4:3 */
728 hfactor= 4.0/3.0;
729 if (mPixelAspectRatioChanged )
fei.dengb9a1a572023-09-13 01:33:57 +0000730 DEBUG(mLogCategory, "stretch apply vfactor %f hfactor %f", vfactor, hfactor);
fei.dengf7a0cd32023-08-29 09:36:37 +0000731 }
732 vh = mVideoHeight * (1.0);
733 vw = vh*hfactor*16/9;
734 vx = vx+(mVideoWidth-vw)/2;
735 vy = vy+(mVideoHeight-vh)/2;
736 }
737 break;
738 case ZOOM_4_3_PILLARBOX:
739 {
740 vh = mVideoHeight * (1.0);
741 vw = vh*4/3;
742 vx = vx+(mVideoWidth-vw)/2;
743 vy = vy+(mVideoHeight-vh)/2;
744 }
745 break;
746 case ZOOM_ZOOM:
747 {
748 if ( arf >= ard )
749 {
750 if (approxEqual(arf, ard) && approxEqual( arf, 1.777) )
751 {
752 /* For 16:9 content on a 16:9 display, enlarge as though 4:3 */
753 vfactor= 4.0/3.0;
754 hfactor= 1.0;
755 if (mPixelAspectRatioChanged )
fei.dengb9a1a572023-09-13 01:33:57 +0000756 DEBUG(mLogCategory, "zoom apply vfactor %f hfactor %f", vfactor, hfactor);
fei.dengf7a0cd32023-08-29 09:36:37 +0000757 }
758 vh = mVideoHeight * vfactor * (1.0);
759 vw = (roiw * vh) * hfactor / roih;
760 vx = vx+(mVideoWidth-vw)/2;
761 vy = vy+(mVideoHeight-vh)/2;
762 }
763 else
764 {
765 vw = mVideoWidth * (1.0);
766 vh = (roih * vw) / roiw;
767 vx = vx+(mVideoWidth-vw)/2;
768 vy = vy+(mVideoHeight-vh)/2;
769 }
770 }
771 break;
772 }
fei.dengb9a1a572023-09-13 01:33:57 +0000773 if (mPixelAspectRatioChanged) DEBUG(mLogCategory, "vrect %d, %d, %d, %d", vx, vy, vw, vh);
fei.dengf7a0cd32023-08-29 09:36:37 +0000774 if (mPixelAspectRatioChanged)
775 {
776 if (mWlDisplay && mWlVpcSurface )
777 {
778 wl_vpc_surface_set_geometry(mWlVpcSurface, mWindowX, mWindowY, mWindowWidth, mWindowHeight);
779 wl_display_flush(mWlDisplay);
780 }
781 }
782 mPixelAspectRatioChanged = false;
783 *x= vx;
784 *y= vy;
785 *w= vw;
786 *h= vh;
fei.dengb9a1a572023-09-13 01:33:57 +0000787 TRACE(mLogCategory, "vrect %d, %d, %d, %d", vx, vy, vw, vh);
fei.dengf7a0cd32023-08-29 09:36:37 +0000788}
789
790void WstClientWayland::setTextureCrop(int vx, int vy, int vw, int vh)
791{
fei.dengb9a1a572023-09-13 01:33:57 +0000792 DEBUG(mLogCategory, "vx %d vy %d vw %d vh %d window(%d, %d, %d, %d) display(%dx%d)", \
fei.dengf7a0cd32023-08-29 09:36:37 +0000793 vx, vy, vw, vh, mWindowX, mWindowY, mWindowWidth, mWindowHeight, mDisplayWidth, mDisplayHeight);
794 if ( (mDisplayWidth != -1) && (mDisplayHeight != -1) &&
795 ( (vx < 0) || (vx+vw > mDisplayWidth) ||
796 (vy < 0) || (vy+vh > mDisplayHeight) ) )
797 {
798 int cropx, cropy, cropw, croph;
799 int wx1, wx2, wy1, wy2;
800 cropx= 0;
801 cropw= mWindowWidth;
802 cropy= 0;
803 croph= mWindowHeight;
804 if ( (vx < mWindowX) || (vx+vw > mWindowX+mWindowWidth) )
805 {
806 cropx= (mWindowX-vx)*mWindowWidth/vw;
807 cropw= (mWindowX+mWindowWidth-vx)*mWindowWidth/vw - cropx;
808 }
809 else if ( vx < 0 )
810 {
811 cropx= -vx*mWindowWidth/vw;
812 cropw= (vw+vx)*mWindowWidth/vw;
813 }
814 else if ( vx+vw > mWindowWidth )
815 {
816 cropx= 0;
817 cropw= (mWindowWidth-vx)*mWindowWidth/vw;
818 }
819
820 if ( (vy < mWindowY) || (vy+vh > mWindowY+mWindowHeight) )
821 {
822 cropy= (mWindowY-vy)*mWindowHeight/vh;
823 croph= (mWindowY+mWindowHeight-vy)*mWindowHeight/vh - cropy;
824 }
825 else if ( vy < 0 )
826 {
827 cropy= -vy*mWindowHeight/vh;
828 croph= (vh+vy)*mWindowHeight/vh;
829 }
830 else if ( vy+vh > mWindowHeight )
831 {
832 cropy= 0;
833 croph= (mWindowHeight-vy)*mWindowHeight/vh;
834 }
835
836 wx1 = vx;
837 wx2 = vx+vw;
838 wy1 = vy;
839 wy2 = vy+vh;
840 vx = mWindowX;
841 vy = mWindowY;
842 vw = mWindowWidth;
843 vh = mWindowHeight;
844 if ( (wx1 > vx) && (wx1 > 0) )
845 {
846 vx= wx1;
847 }
848 else if ( (wx1 >= vx) && (wx1 < 0) )
849 {
850 vw += wx1;
851 vx= 0;
852 }
853 else if ( wx2 < vx+vw )
854 {
855 vw= wx2-vx;
856 }
857 if ( (wx1 >= 0) && (wx2 > vw) )
858 {
859 vw= vw-wx1;
860 }
861 else if ( wx2 < vx+vw )
862 {
863 vw= wx2-vx;
864 }
865
866 if ( (wy1 > vy) && (wy1 > 0) )
867 {
868 vy= wy1;
869 }
870 else if ( (wy1 >= vy) && (wy1 < 0) )
871 {
872 vy= 0;
873 }
874 else if ( (wy1 < vy) && (wy1 > 0) )
875 {
876 vh -= wy1;
877 }
878 if ( (wy1 >= 0) && (wy2 > vh) )
879 {
880 vh= vh-wy1;
881 }
882 else if ( wy2 < vy+vh )
883 {
884 vh= wy2-vy;
885 }
886 if ( vw < 0 ) vw= 0;
887 if ( vh < 0 ) vh= 0;
888 cropx= (cropx*WL_VPC_SURFACE_CROP_DENOM)/mWindowWidth;
889 cropy= (cropy*WL_VPC_SURFACE_CROP_DENOM)/mWindowHeight;
890 cropw= (cropw*WL_VPC_SURFACE_CROP_DENOM)/mWindowWidth;
891 croph= (croph*WL_VPC_SURFACE_CROP_DENOM)/mWindowHeight;
fei.dengb9a1a572023-09-13 01:33:57 +0000892 DEBUG(mLogCategory,"%d, %d, %d, %d - %d, %d, %d, %d", vx, vy, vw, vh, cropx, cropy, cropw, croph);
fei.dengf7a0cd32023-08-29 09:36:37 +0000893 if (mWlVpcSurface) {
894 wl_vpc_surface_set_geometry_with_crop(mWlVpcSurface, vx, vy, vw, vh, cropx, cropy, cropw, croph );
895 }
896 }
897 else
898 {
899 if (mWlVpcSurface) {
900 wl_vpc_surface_set_geometry(mWlVpcSurface, mWindowX, mWindowY, mWindowWidth, mWindowHeight);
901 }
902 }
903}
904
905void WstClientWayland::setForceAspectRatio(bool force)
906{
fei.dengb9a1a572023-09-13 01:33:57 +0000907 DEBUG(mLogCategory, "force aspect ratio:%d",force);
fei.dengf7a0cd32023-08-29 09:36:37 +0000908 mForceAspectRatio = force;
909}
910
911void WstClientWayland::setPixelAspectRatio(double ratio)
912{
913 mPixelAspectRatio = ratio;
914 mPixelAspectRatioChanged = true;
fei.dengb9a1a572023-09-13 01:33:57 +0000915 INFO(mLogCategory, "set aspect ratio:%f",ratio);
fei.dengf7a0cd32023-08-29 09:36:37 +0000916}
917
918void WstClientWayland::updateVideoPosition()
919{
920 bool needUpdate= true;
921 int vx, vy, vw, vh;
922 vx= mVideoX;
923 vy= mVideoY;
924 vw= mVideoWidth;
925 vh= mVideoHeight;
926
927 if (mWindowSizeOverride)
928 {
929 mVideoX= ((mWindowX*mScaleXNum)/mScaleXDenom) + mTransX;
930 mVideoY= ((mWindowY*mScaleYNum)/mScaleYDenom) + mTransY;
931 mVideoWidth= (mWindowWidth*mScaleXNum)/mScaleXDenom;
932 mVideoHeight= (mWindowHeight*mScaleYNum)/mScaleYDenom;
fei.dengb9a1a572023-09-13 01:33:57 +0000933 DEBUG(mLogCategory, "window override video rectangle(%d,%d,%d,%d)",mVideoX,mVideoY,mVideoWidth,mVideoHeight);
fei.dengf7a0cd32023-08-29 09:36:37 +0000934 }
935 else
936 {
937 mVideoX = mTransX;
938 mVideoY = mTransY;
939 mVideoWidth = (mOutputWidth*mScaleXNum)/mScaleXDenom;
940 mVideoHeight = (mOutputHeight*mScaleYNum)/mScaleYDenom;
fei.dengb9a1a572023-09-13 01:33:57 +0000941 DEBUG(mLogCategory, "video rectangle(%d,%d,%d,%d)",mVideoX,mVideoY,mVideoWidth,mVideoHeight);
fei.dengf7a0cd32023-08-29 09:36:37 +0000942 }
943
944 if (vx == mVideoX && vy == mVideoY && vw == mVideoWidth && vh == mVideoHeight) {
945 needUpdate = false;
946 }
947
948 if (needUpdate) {
949 /* Send a buffer to compositor to update hole punch geometry */
950 if (mWlSb)
951 {
952 struct wl_buffer *buff;
953
954 buff = wl_sb_create_buffer( mWlSb,
955 0,
956 mWindowWidth,
957 mWindowHeight,
958 mWindowWidth*4,
959 WL_SB_FORMAT_ARGB8888 );
960 wl_surface_attach(mWlSurface, buff, mWindowX, mWindowY);
961 wl_surface_damage(mWlSurface, 0, 0, mWindowWidth, mWindowHeight);
962 wl_surface_commit(mWlSurface);
963 }
sheng.liua7baed72024-01-24 07:31:24 +0000964 }
965 if (mPlugin)
966 {
967 mPlugin->setVideoRect(mVideoX, mVideoY, mVideoWidth, mVideoHeight);
fei.dengf7a0cd32023-08-29 09:36:37 +0000968 }
969}
970
971void WstClientWayland::setVideoPath(bool useGfxPath )
972{
fei.dengb9a1a572023-09-13 01:33:57 +0000973 INFO(mLogCategory,"useGfxPath:%d",useGfxPath);
fei.dengf7a0cd32023-08-29 09:36:37 +0000974 if ( needBounds() && mWlVpcSurface )
975 {
976 /* Use nominal display size provided to us by
977 * the compositor to calculate the video bounds
978 * we should use when we transition to graphics path.
979 * Save and restore current HW video rectangle. */
980 int vx, vy, vw, vh;
981 int tx, ty, tw, th;
982 tx = mVideoX;
983 ty = mVideoY;
984 tw = mVideoWidth;
985 th = mVideoHeight;
986 mVideoX = mWindowX;
987 mVideoY = mWindowY;
988 mVideoWidth = mWindowWidth;
989 mVideoHeight = mWindowHeight;
990
fei.dengb9a1a572023-09-13 01:33:57 +0000991 DEBUG(mLogCategory, "video rect (%d,%d,%d,%d)",mVideoX,mVideoY,mVideoWidth,mVideoHeight);
fei.dengf7a0cd32023-08-29 09:36:37 +0000992
993 if (mFrameWidth > 0 && mFrameHeight > 0) {
994 getVideoBounds(&vx, &vy, &vw, &vh);
995 setTextureCrop(vx, vy, vw, vh);
996 }
997
998 mVideoX = tx;
999 mVideoY = ty;
1000 mVideoWidth = tw;
1001 mVideoHeight = th;
1002 }
1003}
1004
1005bool WstClientWayland::approxEqual( double v1, double v2 )
1006{
1007 bool result= false;
1008 if ( v1 >= v2 )
1009 {
1010 if ( (v1-v2) < 0.001 )
1011 {
1012 result= true;
1013 }
1014 }
1015 else
1016 {
1017 if ( (v2-v1) < 0.001 )
1018 {
1019 result= true;
1020 }
1021 }
1022 return result;
1023}
1024
1025void WstClientWayland::readyToRun()
1026{
1027 mFd = wl_display_get_fd (mWlDisplay);
fei.dengb9a1a572023-09-13 01:33:57 +00001028 if (mPoll) {
1029 mPoll->addFd(mFd);
1030 mPoll->setFdReadable(mFd, true);
1031 }
fei.dengf7a0cd32023-08-29 09:36:37 +00001032}
1033
1034bool WstClientWayland::threadLoop()
1035{
1036 struct pollfd pfd;
1037 int ret;
1038
1039 while (wl_display_prepare_read_queue (mWlDisplay, mWlQueue) != 0) {
1040 wl_display_dispatch_queue_pending (mWlDisplay, mWlQueue);
1041 }
1042
fei.dengf7a0cd32023-08-29 09:36:37 +00001043 wl_display_flush (mWlDisplay);
1044
fei.dengb9a1a572023-09-13 01:33:57 +00001045 /*poll timeout value must > 300 ms,otherwise zwp_linux_dmabuf will create failed,
1046 so do use -1 to wait for ever*/
1047 ret = mPoll->wait(-1); //wait for ever
fei.dengf7a0cd32023-08-29 09:36:37 +00001048 if (ret < 0) { //poll error
fei.dengb9a1a572023-09-13 01:33:57 +00001049 WARNING(mLogCategory,"poll error");
fei.dengf7a0cd32023-08-29 09:36:37 +00001050 wl_display_cancel_read(mWlDisplay);
1051 return false;
1052 } else if (ret == 0) { //poll time out
1053 return true; //run loop
1054 }
1055
1056 if (wl_display_read_events (mWlDisplay) == -1) {
1057 goto tag_error;
1058 }
1059
1060 wl_display_dispatch_queue_pending (mWlDisplay, mWlQueue);
1061 return true;
1062tag_error:
fei.dengb9a1a572023-09-13 01:33:57 +00001063 ERROR(mLogCategory,"Error communicating with the wayland server");
fei.dengf7a0cd32023-08-29 09:36:37 +00001064 return false;
1065}
1066
1067void WstClientWayland::executeCmd(const char *cmd) {
fei.dengb9a1a572023-09-13 01:33:57 +00001068 INFO(mLogCategory,"%s", cmd);
fei.dengf7a0cd32023-08-29 09:36:37 +00001069 FILE* pFile = popen(cmd, "r");
fei.denga8f4b902024-02-22 03:49:07 +00001070 if (pFile) {
1071 char buf[128];
1072 char* retStr = fgets(buf, sizeof(buf), pFile);
1073 INFO(mLogCategory,"ret= %s", retStr);
1074 pclose(pFile);
1075 }
fei.dengf7a0cd32023-08-29 09:36:37 +00001076}