hc
2023-05-26 a23f51ed7a39e452c1037343a84d7db1ca2c5bd7
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
From 975430378d792612f14f6b6bf61951eccfceda4d Mon Sep 17 00:00:00 2001
From: Jeffy Chen <jeffy.chen@rock-chips.com>
Date: Tue, 28 Dec 2021 14:06:19 +0800
Subject: [PATCH 28/40] waylandsink: Support window alpha property
 
Tested with:
gst-launch-1.0 videotestsrc ! waylandsink alpha=0.5
 
Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com>
---
 ext/wayland/gstwaylandsink.c | 32 ++++++++++++++++++++++++++++++++
 ext/wayland/gstwaylandsink.h |  1 +
 ext/wayland/wlwindow.c       | 23 ++++++++++++++++-------
 ext/wayland/wlwindow.h       |  1 +
 4 files changed, 50 insertions(+), 7 deletions(-)
 
diff --git a/ext/wayland/gstwaylandsink.c b/ext/wayland/gstwaylandsink.c
index 984aaf3..cec28f2 100644
--- a/ext/wayland/gstwaylandsink.c
+++ b/ext/wayland/gstwaylandsink.c
@@ -65,6 +65,7 @@ enum
   PROP_DISPLAY,
   PROP_FULLSCREEN,
   PROP_LAYER,
+  PROP_ALPHA,
   PROP_LAST
 };
 
@@ -236,6 +237,11 @@ gst_wayland_sink_class_init (GstWaylandSinkClass * klass)
           GST_TYPE_WL_WINDOW_LAYER, GST_WL_WINDOW_LAYER_NORMAL,
           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 
+  g_object_class_install_property (gobject_class, PROP_ALPHA,
+      g_param_spec_double ("alpha", "Window alpha",
+          "Wayland window alpha", 0.0, 1.0, 1.0,
+          G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS));
+
   gst_video_overlay_install_properties (gobject_class, PROP_LAST);
 
   gst_type_mark_as_plugin_api (GST_TYPE_WAYLAND_VIDEO, 0);
@@ -249,6 +255,7 @@ gst_wayland_sink_init (GstWaylandSink * sink)
 
   sink->window_handle = 1;
   sink->layer = GST_WL_WINDOW_LAYER_NORMAL;
+  sink->alpha = 1.0;
 }
 
 static void
@@ -275,6 +282,18 @@ gst_wayland_sink_set_layer (GstWaylandSink * sink, GstWlWindowLayer layer)
   g_mutex_unlock (&sink->render_lock);
 }
 
+static void
+gst_wayland_sink_set_alpha (GstWaylandSink * sink, gdouble alpha)
+{
+  if (alpha == sink->alpha)
+    return;
+
+  g_mutex_lock (&sink->render_lock);
+  sink->alpha = alpha;
+  gst_wl_window_ensure_alpha (sink->window, alpha);
+  g_mutex_unlock (&sink->render_lock);
+}
+
 static void
 gst_wayland_sink_get_property (GObject * object,
     guint prop_id, GValue * value, GParamSpec * pspec)
@@ -297,6 +316,11 @@ gst_wayland_sink_get_property (GObject * object,
       g_value_set_enum (value, sink->layer);
       GST_OBJECT_UNLOCK (sink);
       break;
+    case PROP_ALPHA:
+      GST_OBJECT_LOCK (sink);
+      g_value_set_double (value, sink->alpha);
+      GST_OBJECT_UNLOCK (sink);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -325,6 +349,11 @@ gst_wayland_sink_set_property (GObject * object,
       gst_wayland_sink_set_layer (sink, g_value_get_enum (value));
       GST_OBJECT_UNLOCK (sink);
       break;
+    case PROP_ALPHA:
+      GST_OBJECT_LOCK (sink);
+      gst_wayland_sink_set_alpha (sink, g_value_get_double (value));
+      GST_OBJECT_UNLOCK (sink);
+      break;
     default:
       if (!gst_video_overlay_set_property (object, PROP_LAST, prop_id, value))
         G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -781,6 +810,8 @@ gst_wayland_sink_show_frame (GstVideoSink * vsink, GstBuffer * buffer)
       sink->window = gst_wl_window_new_toplevel (sink->display,
           &sink->video_info, sink->fullscreen, sink->layer,
           &sink->render_lock, &sink->render_rectangle);
+      gst_wl_window_ensure_alpha (sink->window, sink->alpha);
+
       g_signal_connect_object (sink->window, "closed",
           G_CALLBACK (on_window_closed), sink, 0);
     }
@@ -1033,6 +1064,7 @@ gst_wayland_sink_set_window_handle (GstVideoOverlay * overlay, guintptr handle)
       } else {
         sink->window = gst_wl_window_new_in_surface (sink->display, surface,
             &sink->render_lock);
+        gst_wl_window_ensure_alpha (sink->window, sink->alpha);
 
         if (sink->last_buffer) {
           /* Resend video info to force resize video surface */
diff --git a/ext/wayland/gstwaylandsink.h b/ext/wayland/gstwaylandsink.h
index c5fdd50..6fa4de3 100644
--- a/ext/wayland/gstwaylandsink.h
+++ b/ext/wayland/gstwaylandsink.h
@@ -63,6 +63,7 @@ struct _GstWaylandSink
   GstVideoInfo video_info;
   gboolean fullscreen;
   GstWlWindowLayer layer;
+  gdouble alpha;
 
   gchar *display_name;
 
diff --git a/ext/wayland/wlwindow.c b/ext/wayland/wlwindow.c
index 66924a5..7771def 100644
--- a/ext/wayland/wlwindow.c
+++ b/ext/wayland/wlwindow.c
@@ -24,6 +24,7 @@
 #include <config.h>
 #endif
 
+#include <stdio.h>
 #include <stdlib.h>
 
 #include "wlwindow.h"
@@ -237,19 +238,25 @@ gst_wl_window_new_internal (GstWlDisplay * display, GMutex * render_lock)
 }
 
 static void
-gst_wl_window_set_flags (GstWlWindow * window, const char *flags)
+gst_wl_window_set_config (GstWlWindow * window, const char *config)
 {
-  /* HACK: set window flags through title */
-  char s[128] = "flags=";
-  strcat (s, flags);
-
+  /* HACK: set window config through title */
   if (!window)
     return;
 
   if (window->xdg_toplevel)
-    xdg_toplevel_set_title (window->xdg_toplevel, s);
+    xdg_toplevel_set_title (window->xdg_toplevel, config);
   else if (window->wl_shell_surface)
-    wl_shell_surface_set_title (window->wl_shell_surface, s);
+    wl_shell_surface_set_title (window->wl_shell_surface, config);
+}
+
+void
+gst_wl_window_ensure_alpha (GstWlWindow * window, gdouble alpha)
+{
+  char s[128];
+
+  snprintf (s, sizeof (s), "attrs=alpha:%f;", alpha);
+  gst_wl_window_set_config (window, s);
 }
 
 void
@@ -270,6 +277,8 @@ gst_wl_window_ensure_layer (GstWlWindow * window, GstWlWindowLayer layer)
     default:
       return;
   }
+
+  gst_wl_window_set_config (window, s);
 }
 
 void
diff --git a/ext/wayland/wlwindow.h b/ext/wayland/wlwindow.h
index 748f2c6..2fcaa98 100644
--- a/ext/wayland/wlwindow.h
+++ b/ext/wayland/wlwindow.h
@@ -88,6 +88,7 @@ typedef enum
   GST_WL_WINDOW_LAYER_BOTTOM = 2,
 } GstWlWindowLayer;
 
+void gst_wl_window_ensure_alpha (GstWlWindow * window, gdouble alpha);
 void gst_wl_window_ensure_layer (GstWlWindow * window,
         GstWlWindowLayer layer);
 void gst_wl_window_ensure_fullscreen (GstWlWindow * window,
-- 
2.17.1