HYL_OK3568_LINUX/buildroot/package/gstreamer1/gst1-plugins-bad/0020-waylandsink-Support-window-alpha-property.patch

165 lines
5.2 KiB
Diff
Raw Normal View History

2025-05-10 21:49:39 +08:00
From 094b728bb0ab22c917928d334358b4491b04b163 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 20/41] 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 | 31 ++++++++++++++++++++++++++++++
ext/wayland/gstwaylandsink.h | 1 +
gst-libs/gst/wayland/gstwlwindow.c | 10 ++++++++++
gst-libs/gst/wayland/gstwlwindow.h | 3 +++
4 files changed, 45 insertions(+)
diff --git a/ext/wayland/gstwaylandsink.c b/ext/wayland/gstwaylandsink.c
index 56a6849..008c774 100644
--- a/ext/wayland/gstwaylandsink.c
+++ b/ext/wayland/gstwaylandsink.c
@@ -62,6 +62,7 @@ enum
PROP_FULLSCREEN,
PROP_ROTATE_METHOD,
PROP_LAYER,
+ PROP_ALPHA,
PROP_LAST
};
@@ -202,6 +203,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));
+
/**
* waylandsink:render-rectangle:
*
@@ -221,6 +227,7 @@ gst_wayland_sink_init (GstWaylandSink * self)
self->window_handle = 1;
self->layer = GST_WL_WINDOW_LAYER_NORMAL;
+ self->alpha = 1.0;
}
static void
@@ -284,6 +291,18 @@ gst_wayland_sink_set_layer (GstWaylandSink * self, GstWlWindowLayer layer)
g_mutex_unlock (&self->render_lock);
}
+static void
+gst_wayland_sink_set_alpha (GstWaylandSink * self, gdouble alpha)
+{
+ if (alpha == self->alpha)
+ return;
+
+ g_mutex_lock (&self->render_lock);
+ self->alpha = alpha;
+ gst_wl_window_ensure_alpha (self->window, alpha);
+ g_mutex_unlock (&self->render_lock);
+}
+
static void
gst_wayland_sink_get_property (GObject * object,
guint prop_id, GValue * value, GParamSpec * pspec)
@@ -311,6 +330,11 @@ gst_wayland_sink_get_property (GObject * object,
g_value_set_enum (value, self->layer);
GST_OBJECT_UNLOCK (self);
break;
+ case PROP_ALPHA:
+ GST_OBJECT_LOCK (self);
+ g_value_set_double (value, self->alpha);
+ GST_OBJECT_UNLOCK (self);
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -343,6 +367,11 @@ gst_wayland_sink_set_property (GObject * object,
gst_wayland_sink_set_layer (self, g_value_get_enum (value));
GST_OBJECT_UNLOCK (self);
break;
+ case PROP_ALPHA:
+ GST_OBJECT_LOCK (self);
+ gst_wayland_sink_set_alpha (self, g_value_get_double (value));
+ GST_OBJECT_UNLOCK (self);
+ break;
default:
if (!gst_video_overlay_set_property (object, PROP_LAST, prop_id, value))
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -827,6 +856,7 @@ gst_wayland_sink_show_frame (GstVideoSink * vsink, GstBuffer * buffer)
G_CALLBACK (on_window_closed), self, 0);
gst_wl_window_set_rotate_method (self->window,
self->current_rotate_method);
+ gst_wl_window_ensure_alpha (self->window, self->alpha);
}
}
@@ -1085,6 +1115,7 @@ gst_wayland_sink_set_window_handle (GstVideoOverlay * overlay, guintptr handle)
&self->render_lock);
gst_wl_window_set_rotate_method (self->window,
self->current_rotate_method);
+ gst_wl_window_ensure_alpha (self->window, self->alpha);
if (self->last_buffer) {
/* Resend video info to force resize video surface */
diff --git a/ext/wayland/gstwaylandsink.h b/ext/wayland/gstwaylandsink.h
index a417788..0339ef7 100644
--- a/ext/wayland/gstwaylandsink.h
+++ b/ext/wayland/gstwaylandsink.h
@@ -58,6 +58,7 @@ struct _GstWaylandSink
GstVideoInfo video_info;
gboolean fullscreen;
GstWlWindowLayer layer;
+ gdouble alpha;
gchar *display_name;
diff --git a/gst-libs/gst/wayland/gstwlwindow.c b/gst-libs/gst/wayland/gstwlwindow.c
index fed1c97..f470338 100644
--- a/gst-libs/gst/wayland/gstwlwindow.c
+++ b/gst-libs/gst/wayland/gstwlwindow.c
@@ -24,6 +24,7 @@
#include <config.h>
#endif
+#include <stdio.h>
#include <stdlib.h>
#include "gstwlwindow.h"
@@ -267,6 +268,15 @@ gst_wl_window_set_config (GstWlWindow * self, const char *config)
xdg_toplevel_set_title (priv->xdg_toplevel, 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
gst_wl_window_ensure_layer (GstWlWindow * self, GstWlWindowLayer layer)
{
diff --git a/gst-libs/gst/wayland/gstwlwindow.h b/gst-libs/gst/wayland/gstwlwindow.h
index a0b05c3..2672e0f 100644
--- a/gst-libs/gst/wayland/gstwlwindow.h
+++ b/gst-libs/gst/wayland/gstwlwindow.h
@@ -40,6 +40,9 @@ struct _GstWlWindow
GObject parent_instance;
};
+GST_WL_API
+void gst_wl_window_ensure_alpha (GstWlWindow * self, gdouble alpha);
+
GST_WL_API
void gst_wl_window_ensure_layer (GstWlWindow * self,
GstWlWindowLayer layer);
--
2.20.1