1From 347a0ce52357d2f199724b18b571516a95d73029 Mon Sep 17 00:00:00 2001 2From: Jeffy Chen <jeffy.chen@rock-chips.com> 3Date: Fri, 5 Aug 2022 11:39:00 +0800 4Subject: [PATCH 37/41] waylandsink: Support transparent video 5 6Tested with transparent png picture. 7 8Signed-off-by: Jeffy Chen <jeffy.chen@rock-chips.com> 9--- 10 gst-libs/gst/wayland/gstwlwindow.c | 36 +++++++++++++++++++++--------- 11 1 file changed, 26 insertions(+), 10 deletions(-) 12 13diff --git a/gst-libs/gst/wayland/gstwlwindow.c b/gst-libs/gst/wayland/gstwlwindow.c 14index 21cd476..36afd3f 100644 15--- a/gst-libs/gst/wayland/gstwlwindow.c 16+++ b/gst-libs/gst/wayland/gstwlwindow.c 17@@ -69,6 +69,9 @@ typedef struct _GstWlWindowPrivate 18 gint crop_x, crop_y, crop_w, crop_h; 19 gboolean crop_dirty; 20 21+ gboolean video_opaque; 22+ gboolean area_opaque; 23+ 24 enum wl_output_transform buffer_transform; 25 26 /* when this is not set both the area_surface and the video_surface are not 27@@ -628,20 +631,23 @@ gst_wl_window_resize_video_surface (GstWlWindow * self, gboolean commit) 28 } 29 30 static void 31-gst_wl_window_set_opaque (GstWlWindow * self, const GstVideoInfo * info) 32+gst_wl_window_set_opaque (GstWlWindow * self) 33 { 34 GstWlWindowPrivate *priv = gst_wl_window_get_instance_private (self); 35 struct wl_compositor *compositor; 36 struct wl_region *region; 37 38- /* Set area opaque */ 39 compositor = gst_wl_display_get_compositor (priv->display); 40- region = wl_compositor_create_region (compositor); 41- wl_region_add (region, 0, 0, G_MAXINT32, G_MAXINT32); 42- wl_surface_set_opaque_region (priv->area_surface, region); 43- wl_region_destroy (region); 44+ 45+ if (priv->area_opaque) { 46+ /* Set area opaque */ 47+ region = wl_compositor_create_region (compositor); 48+ wl_region_add (region, 0, 0, G_MAXINT32, G_MAXINT32); 49+ wl_surface_set_opaque_region (priv->area_surface, region); 50+ wl_region_destroy (region); 51+ } 52 53- if (!GST_VIDEO_INFO_HAS_ALPHA (info)) { 54+ if (priv->video_opaque) { 55 /* Set video opaque */ 56 region = wl_compositor_create_region (compositor); 57 wl_region_add (region, 0, 0, G_MAXINT32, G_MAXINT32); 58@@ -659,10 +665,15 @@ gst_wl_window_render (GstWlWindow * self, GstWlBuffer * buffer, 59 if (G_UNLIKELY (info)) { 60 priv->video_width = info->width; 61 priv->video_height = info->height; 62+ priv->video_opaque = !GST_VIDEO_INFO_HAS_ALPHA (info); 63+ priv->area_opaque = priv->video_opaque; 64+ 65+ if (g_getenv ("WAYLANDSINK_FORCE_OPAQUE")) 66+ priv->area_opaque = priv->video_opaque = TRUE; 67 68 wl_subsurface_set_sync (priv->video_subsurface); 69 gst_wl_window_resize_video_surface (self, FALSE); 70- gst_wl_window_set_opaque (self, info); 71+ gst_wl_window_set_opaque (self); 72 } else if (priv->crop_dirty) { 73 gst_wl_window_resize_video_surface (self, FALSE); 74 } 75@@ -730,8 +741,13 @@ gst_wl_window_update_borders (GstWlWindow * self) 76 height = priv->render_rectangle.h; 77 } 78 79- /* we want WL_SHM_FORMAT_XRGB8888 */ 80- format = GST_VIDEO_FORMAT_BGRx; 81+ if (priv->area_opaque) { 82+ /* we want WL_SHM_FORMAT_XRGB8888 */ 83+ format = GST_VIDEO_FORMAT_BGRx; 84+ } else { 85+ /* we want WL_SHM_FORMAT_ARGB8888 */ 86+ format = GST_VIDEO_FORMAT_BGRA; 87+ } 88 89 /* draw the area_subsurface */ 90 gst_video_info_set_format (&info, format, width, height); 91-- 922.20.1 93 94