summaryrefslogtreecommitdiffstats
path: root/meta-uhmi/meta-rvgpu/recipes-graphics/remote-virtio-gpu/remote-virtio-gpu/0002-Add-agl-shell-desktop-and-xdg-shell-support.patch
blob: db5a69228610a60d04be5071a3ff677cb00109fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
From b60e0a361d29723643fe81b47bff8f86d5200258 Mon Sep 17 00:00:00 2001
From: Kenta <murakami.kenta002@jp.panasonic.com>
Date: Wed, 6 Sep 2023 18:44:22 +0900
Subject: [PATCH] Add agl-shell-desktop and xdg-shell supports

---
 CMakeLists.txt                              |  25 +++
 include/rvgpu-renderer/renderer/rvgpu-egl.h |   9 +-
 src/rvgpu-renderer/CMakeLists.txt           |   3 +
 src/rvgpu-renderer/backend/rvgpu-gbm.c      |   2 +
 src/rvgpu-renderer/backend/rvgpu-wayland.c  | 192 +++++++++++++++++---
 src/rvgpu-renderer/renderer/rvgpu-egl.c     |   3 +
 src/rvgpu-renderer/rvgpu-renderer.c         |  11 +-
 7 files changed, 220 insertions(+), 25 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt
index f569ca2..85c875a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -20,6 +20,31 @@ cmake_minimum_required(VERSION 3.2)
 project(rvgpu C)
 set(CMAKE_C_STANDARD 11)
 
+find_program(WAYLAND_SCANNER_EXECUTABLE wayland-scanner)
+
+message("generating agl-shell-desktop client files from: agl-shell-desktop.xml")
+
+execute_process ( COMMAND mkdir ${CMAKE_BINARY_DIR}/protocol)
+
+execute_process ( COMMAND ${WAYLAND_SCANNER_EXECUTABLE} private-code
+  ${CMAKE_SYSROOT}/usr/share/agl-compositor/protocols/agl-shell-desktop.xml
+	${CMAKE_BINARY_DIR}/protocol/agl-shell-desktop-protocol.c)
+
+execute_process ( COMMAND ${WAYLAND_SCANNER_EXECUTABLE} client-header
+  ${CMAKE_SYSROOT}/usr/share/agl-compositor/protocols/agl-shell-desktop.xml
+	${CMAKE_BINARY_DIR}/protocol/agl-shell-desktop-protocol.h)
+
+message("generating agl-shell-desktop client files from: xdg-shell.xml")
+
+execute_process ( COMMAND ${WAYLAND_SCANNER_EXECUTABLE} private-code
+  ${CMAKE_SYSROOT}/usr/share/wayland-protocols/stable/xdg-shell/xdg-shell.xml
+	${CMAKE_BINARY_DIR}/protocol/xdg-shell-protocol.c)
+
+execute_process ( COMMAND ${WAYLAND_SCANNER_EXECUTABLE} client-header
+  ${CMAKE_SYSROOT}/usr/share/wayland-protocols/stable/xdg-shell/xdg-shell.xml
+	${CMAKE_BINARY_DIR}/protocol/xdg-shell-protocol.h)
+
+
 if (CMAKE_SYSROOT AND NOT ENV{PKG_CONFIG_LIBDIR})
 	set(ENV{PKG_CONFIG_DIR} "")
 	set(ENV{PKG_CONFIG_LIBDIR} "${CMAKE_SYSROOT}/usr/lib/pkgconfig:${CMAKE_SYSROOT}/usr/share/pkgconfig")
diff --git a/include/rvgpu-renderer/renderer/rvgpu-egl.h b/include/rvgpu-renderer/renderer/rvgpu-egl.h
index ebd2bd2..dcff36a 100644
--- a/include/rvgpu-renderer/renderer/rvgpu-egl.h
+++ b/include/rvgpu-renderer/renderer/rvgpu-egl.h
@@ -59,6 +59,9 @@ struct rvgpu_scanout_params {
 	uint32_t id; /**< ID for scanout window (i.e. IVI id)*/
 	bool enabled; /**< enable/disable scanout */
 	bool boxed; /**< box is set by user */
+  struct rvgpu_box agl_win; /** Window position & limit on AGL */
+	bool agl_win_set;
+
 };
 
 struct rvgpu_scanout {
@@ -118,6 +121,8 @@ struct rvgpu_egl_state {
 	bool spawn_support;
 
 	bool use_scissors;
+
+  bool user_specified_scanouts;
 };
 
 /** Initialize main context */
@@ -150,11 +155,11 @@ void rvgpu_egl_destroy_scanout(struct rvgpu_egl_state *e,
 
 /** Draw Virgl output on the surface */
 void rvgpu_egl_draw(struct rvgpu_egl_state *e, struct rvgpu_scanout *s,
-		    bool vsync);
+           bool vsync);
 
 /** Redraw all scanouts with given resource id */
 void rvgpu_egl_drawall(struct rvgpu_egl_state *e, unsigned int res_id,
-		       bool vsync);
+           bool vsync);
 
 /* Async event handling */
 /** Call before polling */
diff --git a/src/rvgpu-renderer/CMakeLists.txt b/src/rvgpu-renderer/CMakeLists.txt
index dc5f5b0..c8a8c34 100644
--- a/src/rvgpu-renderer/CMakeLists.txt
+++ b/src/rvgpu-renderer/CMakeLists.txt
@@ -17,6 +17,8 @@
 
 
 add_executable(rvgpu-renderer
+  ${CMAKE_BINARY_DIR}/protocol/agl-shell-desktop-protocol.c
+	${CMAKE_BINARY_DIR}/protocol/xdg-shell-protocol.c
 	backend/rvgpu-wayland.c
 	backend/rvgpu-gbm.c
 	renderer/rvgpu-egl.c
@@ -28,6 +30,7 @@ add_executable(rvgpu-renderer
 target_include_directories(rvgpu-renderer
 	PRIVATE
 		${PROJECT_SOURCE_DIR}/include
+    ${CMAKE_BINARY_DIR}/protocol
 		${extlibs_INCLUDE_DIRS}
 	)
 target_compile_definitions(rvgpu-renderer PRIVATE _GNU_SOURCE)
diff --git a/src/rvgpu-renderer/backend/rvgpu-gbm.c b/src/rvgpu-renderer/backend/rvgpu-gbm.c
index 4194b0d..b2b3ed3 100644
--- a/src/rvgpu-renderer/backend/rvgpu-gbm.c
+++ b/src/rvgpu-renderer/backend/rvgpu-gbm.c
@@ -259,6 +259,8 @@ static void rvgpu_gbm_create_scanout(struct rvgpu_egl_state *e,
 
 	eglMakeCurrent(e->dpy, s->surface, s->surface, e->context);
 	glGenFramebuffers(1, &s->fb);
+
+  rvgpu_egl_draw(e, s, false);
 }
 
 static void rvgpu_gbm_page_flip_handler(int fd, unsigned int sequence,
diff --git a/src/rvgpu-renderer/backend/rvgpu-wayland.c b/src/rvgpu-renderer/backend/rvgpu-wayland.c
index 0aaeaa7..c00ff00 100644
--- a/src/rvgpu-renderer/backend/rvgpu-wayland.c
+++ b/src/rvgpu-renderer/backend/rvgpu-wayland.c
@@ -39,12 +39,18 @@
 #include <rvgpu-renderer/renderer/rvgpu-egl.h>
 #include <rvgpu-renderer/renderer/rvgpu-input.h>
 
+#include "agl-shell-desktop-protocol.h"
+#include "xdg-shell-protocol.h"
+
 struct rvgpu_native {
 	/* Window structures */
 	struct wl_surface *surface;
 	struct wl_shell_surface *shell_surface;
 	struct wl_egl_window *egl_window;
 	struct ivi_surface *ivi_surface;
+  struct xdg_surface *xdg_surface;
+	struct xdg_toplevel *xdg_toplevel;
+	bool wait_for_configure;
 };
 
 struct rvgpu_wl_state {
@@ -58,6 +64,9 @@ struct rvgpu_wl_state {
 	struct wl_keyboard *keyboard;
 	struct wl_shell *shell;
 	struct ivi_application *ivi_app;
+  struct xdg_wm_base *wm_base;
+	struct agl_shell_desktop *agl_shell_desktop;
+	struct wl_output *output;
 
 	/* EGL structures */
 	struct rvgpu_egl_state egl;
@@ -78,6 +87,16 @@ static inline struct rvgpu_wl_state *to_wl(struct rvgpu_egl_state *e)
 	return rvgpu_container_of(e, struct rvgpu_wl_state, egl);
 }
 
+static void xdg_wm_base_ping(void *data, struct xdg_wm_base *shell,
+				uint32_t serial)
+{
+        xdg_wm_base_pong(shell, serial);
+}
+
+static const struct xdg_wm_base_listener xdg_wm_base_listener = {
+        xdg_wm_base_ping,
+};
+
 static struct wl_seat_listener seat_listener;
 
 static void registry_add_object(void *data, struct wl_registry *registry,
@@ -98,8 +117,17 @@ static void registry_add_object(void *data, struct wl_registry *registry,
 			wl_registry_bind(registry, name, &wl_seat_interface, 1);
 		wl_seat_add_listener(r->seat, &seat_listener, r);
 	} else if (!strcmp(interface, "ivi_application")) {
-		r->ivi_app = wl_registry_bind(registry, name,
-					      &ivi_application_interface, 1);
+		r->ivi_app = wl_registry_bind(registry, name, &ivi_application_interface, 1);
+	} else if (strcmp(interface, "xdg_wm_base") == 0) {
+		r->wm_base = wl_registry_bind(registry, name,
+                        &xdg_wm_base_interface, 1);
+		xdg_wm_base_add_listener(r->wm_base, &xdg_wm_base_listener, r);
+	} else if (strcmp(interface, "agl_shell_desktop") == 0) {
+		r->agl_shell_desktop = wl_registry_bind(registry, name,
+                        &agl_shell_desktop_interface, 1);
+	} else if (strcmp(interface, "wl_output") == 0) {
+		r->output = wl_registry_bind(registry, name,
+                        &wl_output_interface, 1);
 	}
 }
 
@@ -157,6 +185,57 @@ static const struct ivi_surface_listener ivi_surface_listener = {
 	handle_ivi_surface_configure,
 };
 
+static void handle_xdg_toplevel_configure(void *data,
+				struct xdg_toplevel *xdg_toplevel,
+				int32_t width, int32_t height, struct wl_array *states)
+{
+	(void)xdg_toplevel;
+	struct rvgpu_scanout *s = data;
+
+	s->window.w = (unsigned int)width;
+	s->window.h = (unsigned int)height;
+
+	wl_egl_window_resize(s->native->egl_window, width, height, 0, 0);
+}
+
+static const struct xdg_toplevel_listener xdg_toplevel_listener = {
+	handle_xdg_toplevel_configure,
+};
+
+static struct config_param {
+    struct rvgpu_egl_state *egl_state;
+    struct rvgpu_scanout *scanout;
+};
+
+static void handle_xdg_surface_configure(void *data,
+		struct xdg_surface *surface, uint32_t serial)
+{
+    struct config_param *cp = data;
+	  struct rvgpu_scanout *s = cp->scanout;
+	  struct rvgpu_egl_state *egl = cp->egl_state;
+
+    if (surface == NULL)
+        return;
+
+	xdg_surface_ack_configure(surface, serial);
+	if (s->native->wait_for_configure) {
+		if (egl->user_specified_scanouts){
+			for (unsigned int i = 0; i < VIRTIO_GPU_MAX_SCANOUTS; i++) {
+				if (egl->scanouts[i].params.enabled) {
+					rvgpu_egl_draw(egl, &egl->scanouts[i], false);
+				}
+			}
+		} else {
+			rvgpu_egl_draw(egl, &egl->scanouts[0], false);
+		}
+		s->native->wait_for_configure = false;
+	}
+}
+
+static const struct xdg_surface_listener xdg_surface_listener = {
+	handle_xdg_surface_configure,
+};
+
 static void pointer_handle_enter(void *data, struct wl_pointer *pointer,
 				 uint32_t serial, struct wl_surface *surface,
 				 wl_fixed_t sx, wl_fixed_t sy)
@@ -493,6 +572,12 @@ static void rvgpu_wl_destroy_scanout(struct rvgpu_egl_state *e,
 	if (s->native->ivi_surface)
 		ivi_surface_destroy(s->native->ivi_surface);
 
+  if (s->native->xdg_toplevel)
+		xdg_toplevel_destroy(s->native->xdg_toplevel);
+
+	if (s->native->xdg_surface)
+		xdg_surface_destroy(s->native->xdg_surface);
+
 	wl_surface_destroy(s->native->surface);
 	free(s->native);
 }
@@ -510,6 +595,12 @@ static void rvgpu_wl_free(struct rvgpu_egl_state *e)
 	if (r->shell)
 		wl_shell_destroy(r->shell);
 
+  if (r->wm_base)
+		xdg_wm_base_destroy(r->wm_base);
+
+	if (r->agl_shell_desktop)
+		agl_shell_desktop_destroy(r->agl_shell_desktop);
+
 	wl_seat_destroy(r->seat);
 	if (r->pointer)
 		wl_pointer_destroy(r->pointer);
@@ -564,6 +655,21 @@ static void rvgpu_wl_process_events(struct rvgpu_egl_state *e, const void *ev,
 	}
 }
 
+static void create_opaque_region(struct rvgpu_egl_state *e,
+				 struct rvgpu_scanout *s)
+{
+	struct rvgpu_wl_state *r = to_wl(e);
+	struct wl_region *region =
+		wl_compositor_create_region(r->comp);
+	assert(region);
+	wl_region_add(region, 0, 0, (int)s->window.w,
+				(int)s->window.h);
+	wl_surface_set_opaque_region(s->native->surface,
+						region);
+	wl_region_destroy(region);
+}
+
+
 static void rvgpu_wl_set_scanout(struct rvgpu_egl_state *e,
 				 struct rvgpu_scanout *s)
 {
@@ -572,15 +678,9 @@ static void rvgpu_wl_set_scanout(struct rvgpu_egl_state *e,
 	if (!r->fullscreen) {
 		s->window = s->virgl.box;
 		if (s->native) {
-			if (!r->translucent) {
-				struct wl_region *region =
-					wl_compositor_create_region(r->comp);
-				wl_region_add(region, 0, 0, (int)s->window.w,
-					      (int)s->window.h);
-				wl_surface_set_opaque_region(s->native->surface,
-							     region);
-				wl_region_destroy(region);
-			}
+      if (!r->translucent)
+				create_opaque_region(e, s);
+
 			wl_egl_window_resize(s->native->egl_window,
 					     (int)s->window.w, (int)s->window.h,
 					     0, 0);
@@ -629,6 +729,59 @@ static void rvgpu_wl_create_scanout(struct rvgpu_egl_state *e,
 		assert(n->ivi_surface);
 		ivi_surface_add_listener(n->ivi_surface, &ivi_surface_listener,
 					 s);
+
+  } else if (r->wm_base) {
+    if (r->agl_shell_desktop){
+			/* Default create window at the center of the AGL homescreen */
+			unsigned int agl_x = 0;
+			unsigned int agl_y = 215;
+			unsigned int agl_w = 1080;
+			unsigned int agl_h = 1500;
+			if (sp && sp->agl_win_set) {
+				agl_x = sp->agl_win.x;
+				agl_y = sp->agl_win.y;
+			}
+
+     	/*
+			* Because we can not resize the surface automatically, window size
+			* have to be fit to the size of renderer box.
+			*/
+			if (sp && sp->boxed) {
+				agl_w = s->window.w;
+				agl_h = s->window.h;
+			}
+
+      agl_shell_desktop_set_app_property(r->agl_shell_desktop,
+					"rvgpu-renderer",
+					AGL_SHELL_DESKTOP_APP_ROLE_POPUP,
+					agl_x, agl_y,
+					0, 0, agl_w, agl_h,
+					r->output);
+		}
+      
+		n->xdg_surface =
+			xdg_wm_base_get_xdg_surface(r->wm_base, n->surface);
+		assert(n->xdg_surface);
+
+    struct config_param *cp = malloc(sizeof(*cp));
+		assert(cp);
+
+		cp->egl_state = e;
+		cp->scanout = s;
+
+		xdg_surface_add_listener(n->xdg_surface,
+					 &xdg_surface_listener, cp);
+		n->xdg_toplevel = xdg_surface_get_toplevel(n->xdg_surface);
+		assert(n->xdg_toplevel);
+
+		xdg_toplevel_add_listener(n->xdg_toplevel,
+					  &xdg_toplevel_listener, s);
+
+		xdg_toplevel_set_app_id(n->xdg_toplevel, "rvgpu-renderer");
+		wl_surface_commit(n->surface);
+		n->wait_for_configure = true;
+		create_opaque_region(e, s);
+
 	} else if (r->shell) {
 		char title[32];
 
@@ -654,16 +807,9 @@ static void rvgpu_wl_create_scanout(struct rvgpu_egl_state *e,
 				NULL);
 		} else {
 			wl_shell_surface_set_toplevel(n->shell_surface);
-			if (!r->translucent) {
-				struct wl_region *region =
-					wl_compositor_create_region(r->comp);
-				assert(region);
-				wl_region_add(region, 0, 0, (int)s->window.w,
-					      (int)s->window.h);
-				wl_surface_set_opaque_region(n->surface,
-							     region);
-				wl_region_destroy(region);
-			}
+      if (!r->translucent)
+				create_opaque_region(e, s);
+
 		}
 	}
 
@@ -677,6 +823,10 @@ static void rvgpu_wl_create_scanout(struct rvgpu_egl_state *e,
 	eglMakeCurrent(e->dpy, s->surface, s->surface, e->context);
 
 	glGenFramebuffers(1, &s->fb);
+
+  if(!r->wm_base){
+		rvgpu_egl_draw(e, s, false);
+	}
 }
 
 static const struct rvgpu_egl_callbacks wl_callbacks = {
diff --git a/src/rvgpu-renderer/renderer/rvgpu-egl.c b/src/rvgpu-renderer/renderer/rvgpu-egl.c
index a9dd398..6918843 100644
--- a/src/rvgpu-renderer/renderer/rvgpu-egl.c
+++ b/src/rvgpu-renderer/renderer/rvgpu-egl.c
@@ -21,6 +21,7 @@
 #include <assert.h>
 #include <err.h>
 #include <stdlib.h>
+#include <stdio.h>
 
 #include <rvgpu-renderer/renderer/rvgpu-egl.h>
 
@@ -146,6 +147,7 @@ void rvgpu_egl_free(struct rvgpu_egl_state *e)
 		e->cb->free(e);
 }
 
+
 void rvgpu_egl_draw(struct rvgpu_egl_state *e, struct rvgpu_scanout *s,
 		    bool vsync)
 {
@@ -191,6 +193,7 @@ void rvgpu_egl_draw(struct rvgpu_egl_state *e, struct rvgpu_scanout *s,
 				  (int)s->window.w, (int)s->window.h,
 				  GL_COLOR_BUFFER_BIT, GL_NEAREST);
 	}
+
 	if (e->cb->draw)
 		e->cb->draw(e, s, vsync);
 	else
diff --git a/src/rvgpu-renderer/rvgpu-renderer.c b/src/rvgpu-renderer/rvgpu-renderer.c
index 3e74289..40b78d4 100644
--- a/src/rvgpu-renderer/rvgpu-renderer.c
+++ b/src/rvgpu-renderer/rvgpu-renderer.c
@@ -52,6 +52,7 @@ static void usage(void)
 	info("\t-f\t\tRun in fullscreen mode\n");
 	info("\t-p port\t\tport for listening (default: %u)\n",
 	     RVGPU_DEFAULT_PORT);
+  info("\t-w\t\tSet AGL window position\n");
 	info("\t-h\t\tShow this message\n");
 
 	info("\nNote:\n");
@@ -189,7 +190,7 @@ int main(int argc, char **argv)
 
 	memset(sp, 0, sizeof(sp));
 
-	while ((opt = getopt(argc, argv, "afhi:c:s:S:b:B:p:g:")) != -1) {
+	while ((opt = getopt(argc, argv, "afhi:c:s:S:b:w:B:p:g:")) != -1) {
 		switch (opt) {
 		case 'a':
 			translucent = true;
@@ -240,6 +241,13 @@ int main(int argc, char **argv)
 			}
 			cp->boxed = true;
 			break;
+    case 'w':
+      if (sscanf(optarg, "%u,%u",
+        &cp->agl_win.x, &cp->agl_win.y) != 2) {
+        errx(1, "invalid AGL popup application window%s", optarg);
+      }
+      cp->agl_win_set = true;
+      break;
 		case 'i':
 			cp->id = (uint32_t)sanity_strtonum(
 				optarg, 1, UINT32_MAX, &errstr);
@@ -300,7 +308,6 @@ int main(int argc, char **argv)
 		s->params = sp[i];
 		if (sp[i].enabled) {
 			rvgpu_egl_create_scanout(egl, &egl->scanouts[i]);
-			rvgpu_egl_draw(egl, &egl->scanouts[i], false);
 		}
 	}
 
-- 
2.25.1