1From 2319581d4848e5763abe25059ad43148baa95aaf Mon Sep 17 00:00:00 2001 2From: Jeffy Chen <jeffy.chen@rock-chips.com> 3Date: Tue, 28 Dec 2021 14:06:19 +0800 4Subject: [PATCH 19/33] waylandsink: Support window alpha property 5 6Tested with: 7gst-launch-1.0 videotestsrc ! waylandsink alpha=0.5 8 9Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com> 10--- 11 ext/wayland/gstwaylandsink.c | 32 ++++++++++++++++++++++++++++++++ 12 ext/wayland/gstwaylandsink.h | 1 + 13 ext/wayland/wlwindow.c | 23 ++++++++++++++++------- 14 ext/wayland/wlwindow.h | 1 + 15 4 files changed, 50 insertions(+), 7 deletions(-) 16 17diff --git a/ext/wayland/gstwaylandsink.c b/ext/wayland/gstwaylandsink.c 18index 1bf4511..ff79ddf 100644 19--- a/ext/wayland/gstwaylandsink.c 20+++ b/ext/wayland/gstwaylandsink.c 21@@ -65,6 +65,7 @@ enum 22 PROP_DISPLAY, 23 PROP_FULLSCREEN, 24 PROP_LAYER, 25+ PROP_ALPHA, 26 PROP_LAST 27 }; 28 29@@ -238,6 +239,11 @@ gst_wayland_sink_class_init (GstWaylandSinkClass * klass) 30 GST_TYPE_WL_WINDOW_LAYER, GST_WL_WINDOW_LAYER_NORMAL, 31 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); 32 33+ g_object_class_install_property (gobject_class, PROP_ALPHA, 34+ g_param_spec_double ("alpha", "Window alpha", 35+ "Wayland window alpha", 0.0, 1.0, 1.0, 36+ G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE | G_PARAM_STATIC_STRINGS)); 37+ 38 gst_video_overlay_install_properties (gobject_class, PROP_LAST); 39 40 gst_type_mark_as_plugin_api (GST_TYPE_WAYLAND_VIDEO, 0); 41@@ -251,6 +257,7 @@ gst_wayland_sink_init (GstWaylandSink * sink) 42 43 sink->window_handle = 1; 44 sink->layer = GST_WL_WINDOW_LAYER_NORMAL; 45+ sink->alpha = 1.0; 46 } 47 48 static void 49@@ -277,6 +284,18 @@ gst_wayland_sink_set_layer (GstWaylandSink * sink, GstWlWindowLayer layer) 50 g_mutex_unlock (&sink->render_lock); 51 } 52 53+static void 54+gst_wayland_sink_set_alpha (GstWaylandSink * sink, gdouble alpha) 55+{ 56+ if (alpha == sink->alpha) 57+ return; 58+ 59+ g_mutex_lock (&sink->render_lock); 60+ sink->alpha = alpha; 61+ gst_wl_window_ensure_alpha (sink->window, alpha); 62+ g_mutex_unlock (&sink->render_lock); 63+} 64+ 65 static void 66 gst_wayland_sink_get_property (GObject * object, 67 guint prop_id, GValue * value, GParamSpec * pspec) 68@@ -299,6 +318,11 @@ gst_wayland_sink_get_property (GObject * object, 69 g_value_set_enum (value, sink->layer); 70 GST_OBJECT_UNLOCK (sink); 71 break; 72+ case PROP_ALPHA: 73+ GST_OBJECT_LOCK (sink); 74+ g_value_set_double (value, sink->alpha); 75+ GST_OBJECT_UNLOCK (sink); 76+ break; 77 default: 78 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); 79 break; 80@@ -327,6 +351,11 @@ gst_wayland_sink_set_property (GObject * object, 81 gst_wayland_sink_set_layer (sink, g_value_get_enum (value)); 82 GST_OBJECT_UNLOCK (sink); 83 break; 84+ case PROP_ALPHA: 85+ GST_OBJECT_LOCK (sink); 86+ gst_wayland_sink_set_alpha (sink, g_value_get_double (value)); 87+ GST_OBJECT_UNLOCK (sink); 88+ break; 89 default: 90 if (!gst_video_overlay_set_property (object, PROP_LAST, prop_id, value)) 91 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); 92@@ -783,6 +812,8 @@ gst_wayland_sink_show_frame (GstVideoSink * vsink, GstBuffer * buffer) 93 sink->window = gst_wl_window_new_toplevel (sink->display, 94 &sink->video_info, sink->fullscreen, sink->layer, 95 &sink->render_lock, &sink->render_rectangle); 96+ gst_wl_window_ensure_alpha (sink->window, sink->alpha); 97+ 98 g_signal_connect_object (sink->window, "closed", 99 G_CALLBACK (on_window_closed), sink, 0); 100 } 101@@ -1035,6 +1066,7 @@ gst_wayland_sink_set_window_handle (GstVideoOverlay * overlay, guintptr handle) 102 } else { 103 sink->window = gst_wl_window_new_in_surface (sink->display, surface, 104 &sink->render_lock); 105+ gst_wl_window_ensure_alpha (sink->window, sink->alpha); 106 107 if (sink->last_buffer) { 108 /* Resend video info to force resize video surface */ 109diff --git a/ext/wayland/gstwaylandsink.h b/ext/wayland/gstwaylandsink.h 110index 3adddf2..f798969 100644 111--- a/ext/wayland/gstwaylandsink.h 112+++ b/ext/wayland/gstwaylandsink.h 113@@ -63,6 +63,7 @@ struct _GstWaylandSink 114 GstVideoInfo video_info; 115 gboolean fullscreen; 116 GstWlWindowLayer layer; 117+ gdouble alpha; 118 119 gchar *display_name; 120 121diff --git a/ext/wayland/wlwindow.c b/ext/wayland/wlwindow.c 122index 7f7f3b6..58e65dd 100644 123--- a/ext/wayland/wlwindow.c 124+++ b/ext/wayland/wlwindow.c 125@@ -24,6 +24,7 @@ 126 #include <config.h> 127 #endif 128 129+#include <stdio.h> 130 #include <stdlib.h> 131 132 #include "wlwindow.h" 133@@ -235,19 +236,25 @@ gst_wl_window_new_internal (GstWlDisplay * display, GMutex * render_lock) 134 } 135 136 static void 137-gst_wl_window_set_flags (GstWlWindow * window, const char *flags) 138+gst_wl_window_set_config (GstWlWindow * window, const char *config) 139 { 140- /* HACK: set window flags through title */ 141- char s[128] = "flags="; 142- strcat (s, flags); 143- 144+ /* HACK: set window config through title */ 145 if (!window) 146 return; 147 148 if (window->xdg_toplevel) 149- xdg_toplevel_set_title (window->xdg_toplevel, s); 150+ xdg_toplevel_set_title (window->xdg_toplevel, config); 151 else if (window->wl_shell_surface) 152- wl_shell_surface_set_title (window->wl_shell_surface, s); 153+ wl_shell_surface_set_title (window->wl_shell_surface, config); 154+} 155+ 156+void 157+gst_wl_window_ensure_alpha (GstWlWindow * window, gdouble alpha) 158+{ 159+ char s[128]; 160+ 161+ snprintf (s, sizeof (s), "attrs=alpha:%f;", alpha); 162+ gst_wl_window_set_config (window, s); 163 } 164 165 void 166@@ -268,6 +275,8 @@ gst_wl_window_ensure_layer (GstWlWindow * window, GstWlWindowLayer layer) 167 default: 168 return; 169 } 170+ 171+ gst_wl_window_set_config (window, s); 172 } 173 174 void 175diff --git a/ext/wayland/wlwindow.h b/ext/wayland/wlwindow.h 176index 97ea79e..6fb8285 100644 177--- a/ext/wayland/wlwindow.h 178+++ b/ext/wayland/wlwindow.h 179@@ -87,6 +87,7 @@ typedef enum 180 GST_WL_WINDOW_LAYER_BOTTOM = 2, 181 } GstWlWindowLayer; 182 183+void gst_wl_window_ensure_alpha (GstWlWindow * window, gdouble alpha); 184 void gst_wl_window_ensure_layer (GstWlWindow * window, 185 GstWlWindowLayer layer); 186 void gst_wl_window_ensure_fullscreen (GstWlWindow * window, 187-- 1882.20.1 189 190