blob: a1bfe8c3b474ade27eb22999c951df04ee4383f1 [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001From 5fdbcf3ea4b5f81b4aa7a03ff2bd130a6bb2a022 Mon Sep 17 00:00:00 2001
2From: Jia Rong <jia.rong@mediatek.com>
3Date: Thu, 3 May 2018 09:06:15 +0800
4Subject: [PATCH] weston: add surface overlay assignment interface
5
6add surface overlay assignment interface
7Test: OK
8
9Change-Id: I970797b6c3fe59567590639c2fe1e65784f296aa
10Signed-off-by: Jia Rong <jia.rong@mediatek.com>
11CR-Id: AUTO00016576
12---
13 Makefile.am | 6 +-
14 clients/simple-configure-mtk.c | 17 +++++
15 compositor/main.c | 6 ++
16 libweston/compositor-drm.c | 6 ++
17 libweston/compositor.h | 12 ++++
18 libweston/weston-configure-mtk.c | 126 ++++++++++++++++++++++++++++++++++++++
19 libweston/weston-configure-mtk.h | 54 ++++++++++++++++
20 protocol/weston-configure-mtk.xml | 30 +++++++++
21 8 files changed, 256 insertions(+), 1 deletion(-)
22 create mode 100644 libweston/weston-configure-mtk.c
23 create mode 100644 libweston/weston-configure-mtk.h
24
25diff --git a/Makefile.am b/Makefile.am
26index 576b4a1..cf92198 100644
27--- a/Makefile.am
28+++ b/Makefile.am
29@@ -108,6 +108,8 @@ libweston_@LIBWESTON_MAJOR@_la_SOURCES = \
30 libweston/pixel-formats.c \
31 libweston/pixel-formats.h \
32 libweston/weston-screenshooter-mtk.c \
33+ libweston/weston-configure-mtk.c \
34+ libweston/weston-configure-mtk.h \
35 shared/helpers.h \
36 shared/matrix.c \
37 shared/matrix.h \
38@@ -666,7 +668,9 @@ nodist_weston_simple_configure_mtk_SOURCES = \
39 protocol/fullscreen-shell-unstable-v1-protocol.c \
40 protocol/fullscreen-shell-unstable-v1-client-protocol.h \
41 protocol/linux-dmabuf-unstable-v1-protocol.c \
42- protocol/linux-dmabuf-unstable-v1-client-protocol.h
43+ protocol/linux-dmabuf-unstable-v1-client-protocol.h \
44+ protocol/weston-configure-mtk-protocol.c \
45+ protocol/weston-configure-mtk-client-protocol.h
46 weston_simple_configure_mtk_CFLAGS = $(AM_CFLAGS) $(CLIENT_CFLAGS)
47 weston_simple_configure_mtk_LDADD = $(EGL_LIBS) $(LIBDRM_LIBS) libtoytoolkit.la
48 BUILT_SOURCES += protocol/linux-dmabuf-unstable-v1-client-protocol.h
49diff --git a/clients/simple-configure-mtk.c b/clients/simple-configure-mtk.c
50index f94497e..8b146ff 100644
51--- a/clients/simple-configure-mtk.c
52+++ b/clients/simple-configure-mtk.c
53@@ -24,6 +24,7 @@
54 #include "xdg-shell-unstable-v6-client-protocol.h"
55 #include "linux-dmabuf-unstable-v1-client-protocol.h"
56 #include "fullscreen-shell-unstable-v1-client-protocol.h"
57+#include "weston-configure-mtk-client-protocol.h"
58
59 #include <shared/platform.h>
60
61@@ -55,6 +56,7 @@ struct display {
62 struct wl_cursor *default_cursor;
63 struct wl_surface *cursor_surface;
64 struct window *window;
65+ struct config_switch *config_switch;
66 };
67
68 struct geometry {
69@@ -92,6 +94,7 @@ struct window {
70 int fullscreen, opaque, buffer_size, overlay, format;
71 enum wl_output_transform transform;
72 int drm_card_fd;
73+ struct config_switch_set *switch_set;
74 };
75
76 struct img_texture {
77@@ -591,6 +594,8 @@ create_surface(struct window *window)
78 display->cursor_surface =
79 wl_compositor_create_surface(display->compositor);
80
81+ window->switch_set = config_switch_connect(display->config_switch, window->surface);
82+
83 if (display->shell) {
84 window->xdg_surface =
85 zxdg_shell_v6_get_xdg_surface(display->shell,
86@@ -991,6 +996,10 @@ registry_handle_global(void *data, struct wl_registry *registry,
87 d->dmabuf = wl_registry_bind(registry, name,
88 &zwp_linux_dmabuf_v1_interface, 1);
89 zwp_linux_dmabuf_v1_add_listener(d->dmabuf, &dmabuf_listener, d);
90+ } else if (strcmp(interface, "config_switch") == 0) {
91+ d->config_switch =
92+ wl_registry_bind(registry, name,
93+ &config_switch_interface, 1);
94 }
95 }
96
97@@ -1208,6 +1217,14 @@ main(int argc, char **argv)
98 fprintf(stderr, "error: fail to get drm_card_fd !\n");
99 return -1;
100 }
101+ /*
102+ * setting sprite_switch = 0, indicate not walk overlay
103+ * setting sprite_switch = 1, indicate walk overlay
104+ */
105+ if(window.overlay)
106+ config_switch_set_sprite_switch(window.switch_set, 1);
107+ else
108+ config_switch_set_sprite_switch(window.switch_set, 0);
109
110 sigint.sa_handler = signal_int;
111 sigemptyset(&sigint.sa_mask);
112diff --git a/compositor/main.c b/compositor/main.c
113index 72c3cd1..5a8fd55 100644
114--- a/compositor/main.c
115+++ b/compositor/main.c
116@@ -56,6 +56,7 @@
117 #include "git-version.h"
118 #include "version.h"
119 #include "weston.h"
120+#include "../libweston/weston-configure-mtk.h"
121
122 #include "compositor-drm.h"
123 #include "compositor-headless.h"
124@@ -1879,6 +1880,11 @@ int main(int argc, char *argv[])
125
126 weston_pending_output_coldplug(ec);
127
128+ if (config_switch_global_create(ec) < 0) {
129+ weston_log("fatal: failed to config_switch_global_create\n");
130+ goto out;
131+ }
132+
133 catch_signals();
134 segv_compositor = ec;
135
136diff --git a/libweston/compositor-drm.c b/libweston/compositor-drm.c
137index 064d8c2..b5b103b 100644
138--- a/libweston/compositor-drm.c
139+++ b/libweston/compositor-drm.c
140@@ -2753,6 +2753,12 @@ drm_output_prepare_overlay_view(struct drm_output_state *output_state,
141 uint32_t format;
142 wl_fixed_t sx1, sy1, sx2, sy2;
143
144+ /*
145+ * if switch controlled by client is off, then return.
146+ */
147+ if ((!ev->surface->config_switch)||(!ev->surface->config_switch->sprites_switch))
148+ return NULL;
149+
150 if (b->sprites_are_broken)
151 return NULL;
152
153diff --git a/libweston/compositor.h b/libweston/compositor.h
154index dea88dc..6470173 100644
155--- a/libweston/compositor.h
156+++ b/libweston/compositor.h
157@@ -1141,6 +1141,16 @@ struct weston_surface_state {
158 struct weston_buffer_viewport buffer_viewport;
159 };
160
161+/*
162+ * For setting whether the views on this surface walk
163+ * overlay path; on==>1, off==>0
164+*/
165+struct config_switch{
166+ struct wl_resource *resource;
167+ void *private;
168+ int sprites_switch;
169+};
170+
171 struct weston_surface_activation_data {
172 struct weston_surface *surface;
173 struct weston_seat *seat;
174@@ -1262,6 +1272,8 @@ struct weston_surface {
175
176 /* An list of per seat pointer constraints. */
177 struct wl_list pointer_constraints;
178+
179+ struct config_switch *config_switch;
180 };
181
182 struct weston_subsurface {
183diff --git a/libweston/weston-configure-mtk.c b/libweston/weston-configure-mtk.c
184new file mode 100644
185index 0000000..185f91c
186--- /dev/null
187+++ b/libweston/weston-configure-mtk.c
188@@ -0,0 +1,126 @@
189+#include "config.h"
190+#include <fcntl.h>
191+#include <stdio.h>
192+#include <string.h>
193+#include <stdlib.h>
194+#include <stdint.h>
195+#include <limits.h>
196+#include <stdarg.h>
197+#include <assert.h>
198+#include <sys/ioctl.h>
199+#include <sys/mman.h>
200+#include <sys/wait.h>
201+#include <sys/socket.h>
202+#include <sys/utsname.h>
203+#include <sys/stat.h>
204+#include <unistd.h>
205+#include <math.h>
206+#include <linux/input.h>
207+#include <dlfcn.h>
208+#include <signal.h>
209+#include <setjmp.h>
210+#include <sys/time.h>
211+#include <time.h>
212+#include <errno.h>
213+
214+#include "timeline.h"
215+
216+#include "compositor.h"
217+//#include "scaler-server-protocol.h"
218+#include "shared/helpers.h"
219+#include "shared/os-compatibility.h"
220+#include "shared/timespec-util.h"
221+#include "git-version.h"
222+#include "version.h"
223+
224+#include "weston-configure-mtk.h"
225+#include "weston-configure-mtk-server-protocol.h"
226+
227+static void
228+config_set_sprite_switch(struct wl_client *client,
229+ struct wl_resource *resource,
230+ int32_t spr_switch)
231+{
232+ struct config_switch *configure = wl_resource_get_user_data(resource);
233+
234+ configure->sprites_switch = spr_switch;
235+}
236+
237+static const struct config_switch_set_interface switch_set_interface = {
238+ config_set_sprite_switch,
239+};
240+
241+static struct config_switch *
242+config_interface_create(struct weston_surface *surface)
243+{
244+ struct config_switch *config_switch;
245+
246+ config_switch = zalloc(sizeof *config_switch);
247+ if (config_switch == NULL)
248+ return NULL;
249+
250+ config_switch->private = (void *)surface;
251+ surface->config_switch = config_switch;
252+
253+ return config_switch;
254+}
255+
256+static void
257+config_switch_connect(struct wl_client *client, struct wl_resource *resource,
258+ struct wl_resource *wl_surface, uint32_t id)
259+{
260+ struct config_switch *config_switch = wl_resource_get_user_data(resource);
261+ struct weston_surface *surface = wl_resource_get_user_data(wl_surface);
262+
263+ config_switch = config_interface_create(surface);
264+ if (config_switch == NULL) {
265+ wl_resource_post_no_memory(resource);
266+ return;
267+ }
268+
269+ config_switch->resource =
270+ wl_resource_create(client, &config_switch_set_interface,
271+ wl_resource_get_version(resource), id);
272+ if (config_switch->resource == NULL) {
273+ wl_resource_post_no_memory(resource);
274+ return;
275+ }
276+ wl_resource_set_implementation(config_switch->resource, &switch_set_interface,
277+ config_switch, NULL);
278+}
279+
280+static const struct config_switch_interface switch_interface = {
281+ config_switch_connect,
282+};
283+
284+static void
285+bind_config_switch(struct wl_client *client,
286+ void *data, uint32_t version, uint32_t id)
287+{
288+ struct weston_compositor *compositor = data;
289+ struct wl_resource *resource;
290+
291+ resource = wl_resource_create(client, &config_switch_interface,
292+ MIN(version, 1), id);
293+ if (resource == NULL) {
294+ wl_client_post_no_memory(client);
295+ return;
296+ }
297+
298+ wl_resource_set_implementation(resource, &switch_interface,
299+ compositor, NULL);
300+}
301+
302+WL_EXPORT int
303+config_switch_global_create(struct weston_compositor *ec)
304+{
305+ if(!ec)
306+ return -1;
307+ if (!wl_global_create(ec->wl_display, &config_switch_interface, 1,
308+ ec, bind_config_switch)){
309+ fprintf(stderr, "error: failed to config_switch_global_create: %s\n", dlerror());
310+ return -1;
311+ }
312+ return 0;
313+}
314+
315diff --git a/libweston/weston-configure-mtk.h b/libweston/weston-configure-mtk.h
316new file mode 100644
317index 0000000..0f093fe
318--- /dev/null
319+++ b/libweston/weston-configure-mtk.h
320@@ -0,0 +1,54 @@
321+/*
322+ * Copyright © 2008-2011 Kristian Høgsberg
323+ * Copyright © 2012 Collabora, Ltd.
324+ *
325+ * Permission is hereby granted, free of charge, to any person obtaining
326+ * a copy of this software and associated documentation files (the
327+ * "Software"), to deal in the Software without restriction, including
328+ * without limitation the rights to use, copy, modify, merge, publish,
329+ * distribute, sublicense, and/or sell copies of the Software, and to
330+ * permit persons to whom the Software is furnished to do so, subject to
331+ * the following conditions:
332+ *
333+ * The above copyright notice and this permission notice (including the
334+ * next paragraph) shall be included in all copies or substantial
335+ * portions of the Software.
336+ *
337+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
338+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
339+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
340+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
341+ * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
342+ * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
343+ * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
344+ * SOFTWARE.
345+ */
346+
347+#ifndef _APP_CONFIGURE_EXTENSION_H_
348+#define _APP_CONFIGURE_EXTENSION_H_
349+
350+#ifdef __cplusplus
351+extern "C" {
352+#endif
353+
354+#include <stdbool.h>
355+#include <time.h>
356+#include <pixman.h>
357+#include <xkbcommon/xkbcommon.h>
358+
359+#include <wayland-server.h>
360+
361+#include "version.h"
362+#include "matrix.h"
363+#include "config-parser.h"
364+#include "zalloc.h"
365+#include "timeline-object.h"
366+
367+int config_switch_global_create(struct weston_compositor *ec);
368+
369+#ifdef __cplusplus
370+}
371+#endif
372+
373+#endif
374+
375diff --git a/protocol/weston-configure-mtk.xml b/protocol/weston-configure-mtk.xml
376index e19a2ad..120e904 100644
377--- a/protocol/weston-configure-mtk.xml
378+++ b/protocol/weston-configure-mtk.xml
379@@ -33,5 +33,35 @@
380 </event>
381 </interface>
382
383+ <interface name="config_switch_set" version="1">
384+ <description summary="app interface for setting configure for the surface"/>
385+
386+ <request name="sprite_switch">
387+ <description summary="setting the surface configure">
388+ This set view matched with the surface to show in overlay plane if
389+ overlay planes are available.Otherwise, it walk primary plane to
390+ render, and then send to drm to show.
391+ </description>
392+ <arg name="sprite_switch" type="int"/>
393+ </request>
394+ </interface>
395+
396+ <interface name="config_switch" version="1">
397+ <description summary="create app configure path for setting parameter">
398+ This interface is exposed as a global singleton.
399+ This interface is implemented by server, it mainly provide channel to allow
400+ client to control some properties.
401+ </description>
402+
403+ <request name="connect">
404+ <description summary="connect to server for setting parameter">
405+ This request gives client way to connect server.In fact, parameters set by
406+ app all through wl_surface because this is only way can be transmit by app.
407+ </description>
408+ <arg name="surface" type="object" interface="wl_surface" allow-null="true"/>
409+ <arg name="id" type="new_id" interface="config_switch_set"/>
410+ </request>
411+ </interface>
412+
413 </protocol>
414
415--
4161.9.1
417