hc
2023-12-09 b22da3d8526a935aa31e086e63f60ff3246cb61c
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 66d219e1cd5b48cac839b2351782e799b5cac8d7 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 19/31] 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 1bf4511..ff79ddf 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
 };
 
@@ -238,6 +239,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);
@@ -251,6 +257,7 @@ gst_wayland_sink_init (GstWaylandSink * sink)
 
   sink->window_handle = 1;
   sink->layer = GST_WL_WINDOW_LAYER_NORMAL;
+  sink->alpha = 1.0;
 }
 
 static void
@@ -277,6 +284,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)
@@ -299,6 +318,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;
@@ -327,6 +351,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);
@@ -783,6 +812,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);
     }
@@ -1035,6 +1066,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 3adddf2..f798969 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 7f7f3b6..58e65dd 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"
@@ -235,19 +236,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
@@ -268,6 +275,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 97ea79e..6fb8285 100644
--- a/ext/wayland/wlwindow.h
+++ b/ext/wayland/wlwindow.h
@@ -87,6 +87,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.20.1