From 6a61cdce84223376a91fe6690854a76b2cc43349 Mon Sep 17 00:00:00 2001 From: Jeffy Chen Date: Fri, 5 Aug 2022 11:39:00 +0800 Subject: [PATCH 37/41] waylandsink: Support transparent video Tested with transparent png picture. Signed-off-by: Jeffy Chen --- gst-libs/gst/wayland/gstwlwindow.c | 36 +++++++++++++++++++++--------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/gst-libs/gst/wayland/gstwlwindow.c b/gst-libs/gst/wayland/gstwlwindow.c index 21cd476..36afd3f 100644 --- a/gst-libs/gst/wayland/gstwlwindow.c +++ b/gst-libs/gst/wayland/gstwlwindow.c @@ -69,6 +69,9 @@ typedef struct _GstWlWindowPrivate gint crop_x, crop_y, crop_w, crop_h; gboolean crop_dirty; + gboolean video_opaque; + gboolean area_opaque; + enum wl_output_transform buffer_transform; /* when this is not set both the area_surface and the video_surface are not @@ -628,20 +631,23 @@ gst_wl_window_resize_video_surface (GstWlWindow * self, gboolean commit) } static void -gst_wl_window_set_opaque (GstWlWindow * self, const GstVideoInfo * info) +gst_wl_window_set_opaque (GstWlWindow * self) { GstWlWindowPrivate *priv = gst_wl_window_get_instance_private (self); struct wl_compositor *compositor; struct wl_region *region; - /* Set area opaque */ compositor = gst_wl_display_get_compositor (priv->display); - region = wl_compositor_create_region (compositor); - wl_region_add (region, 0, 0, G_MAXINT32, G_MAXINT32); - wl_surface_set_opaque_region (priv->area_surface, region); - wl_region_destroy (region); + + if (priv->area_opaque) { + /* Set area opaque */ + region = wl_compositor_create_region (compositor); + wl_region_add (region, 0, 0, G_MAXINT32, G_MAXINT32); + wl_surface_set_opaque_region (priv->area_surface, region); + wl_region_destroy (region); + } - if (!GST_VIDEO_INFO_HAS_ALPHA (info)) { + if (priv->video_opaque) { /* Set video opaque */ region = wl_compositor_create_region (compositor); wl_region_add (region, 0, 0, G_MAXINT32, G_MAXINT32); @@ -659,10 +665,15 @@ gst_wl_window_render (GstWlWindow * self, GstWlBuffer * buffer, if (G_UNLIKELY (info)) { priv->video_width = info->width; priv->video_height = info->height; + priv->video_opaque = !GST_VIDEO_INFO_HAS_ALPHA (info); + priv->area_opaque = priv->video_opaque; + + if (g_getenv ("WAYLANDSINK_FORCE_OPAQUE")) + priv->area_opaque = priv->video_opaque = TRUE; wl_subsurface_set_sync (priv->video_subsurface); gst_wl_window_resize_video_surface (self, FALSE); - gst_wl_window_set_opaque (self, info); + gst_wl_window_set_opaque (self); } else if (priv->crop_dirty) { gst_wl_window_resize_video_surface (self, FALSE); } @@ -730,8 +741,13 @@ gst_wl_window_update_borders (GstWlWindow * self) height = priv->render_rectangle.h; } - /* we want WL_SHM_FORMAT_XRGB8888 */ - format = GST_VIDEO_FORMAT_BGRx; + if (priv->area_opaque) { + /* we want WL_SHM_FORMAT_XRGB8888 */ + format = GST_VIDEO_FORMAT_BGRx; + } else { + /* we want WL_SHM_FORMAT_ARGB8888 */ + format = GST_VIDEO_FORMAT_BGRA; + } /* draw the area_subsurface */ gst_video_info_set_format (&info, format, width, height); -- 2.20.1