MMFMWK-7954 waylandsink: implement alpha blending for surface

upstream status: imx specific
diff --git a/ext/wayland/Makefile.am b/ext/wayland/Makefile.am
index 387f84f..ecdb957 100644
--- a/ext/wayland/Makefile.am
+++ b/ext/wayland/Makefile.am
@@ -4,7 +4,9 @@
 	viewporter-protocol.c \
 	viewporter-client-protocol.h \
 	linux-dmabuf-unstable-v1-protocol.c \
-	linux-dmabuf-unstable-v1-client-protocol.h
+	linux-dmabuf-unstable-v1-client-protocol.h \
+	alpha-compositing-unstable-v1-protocol.c \
+	alpha-compositing-unstable-v1-client-protocol.h
 
 libgstwaylandsink_la_SOURCES =  \
 	gstwaylandsink.c \
@@ -17,7 +19,8 @@
 
 nodist_libgstwaylandsink_la_SOURCES = \
 	viewporter-protocol.c \
-	linux-dmabuf-unstable-v1-protocol.c
+	linux-dmabuf-unstable-v1-protocol.c \
+	alpha-compositing-unstable-v1-protocol.c
 
 libgstwaylandsink_la_CFLAGS = \
 	$(GST_PLUGINS_BAD_CFLAGS) \
diff --git a/ext/wayland/gstwaylandsink.c b/ext/wayland/gstwaylandsink.c
index bc56bf4..e9be60e 100644
--- a/ext/wayland/gstwaylandsink.c
+++ b/ext/wayland/gstwaylandsink.c
@@ -67,7 +67,8 @@
 enum
 {
   PROP_0,
-  PROP_DISPLAY
+  PROP_DISPLAY,
+  PROP_ALPHA
 };
 
 GST_DEBUG_CATEGORY (gstwayland_debug);
@@ -208,11 +209,17 @@
       g_param_spec_string ("display", "Wayland Display name", "Wayland "
           "display name to connect to, if not supplied via the GstContext",
           NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
+  
+  g_object_class_install_property (gobject_class, PROP_ALPHA,
+      g_param_spec_float ("alpha", "Wayland surface alpha", "Wayland "
+          "surface alpha value, apply custom alpha value to wayland surface",
+          0.0f, 1.0f, 0.0f, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
 }
 
 static void
 gst_wayland_sink_init (GstWaylandSink * sink)
 {
+  sink->alpha = 0.0f;
   g_mutex_init (&sink->display_lock);
   g_mutex_init (&sink->render_lock);
   g_cond_init (&sink->redraw_wait);
@@ -232,6 +239,9 @@
       g_value_set_string (value, sink->display_name);
       GST_OBJECT_UNLOCK (sink);
       break;
+    case PROP_ALPHA:
+      g_value_set_float (value, sink->alpha);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -250,6 +260,9 @@
       sink->display_name = g_value_dup_string (value);
       GST_OBJECT_UNLOCK (sink);
       break;
+    case PROP_ALPHA:
+      sink->alpha = g_value_get_float (value);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -688,6 +701,7 @@
       sink->window = gst_wl_window_new_toplevel (sink->display,
           &sink->video_info, &sink->render_lock);
     }
+    gst_wl_window_set_alpha (sink->window, sink->alpha);
   }
 
   while (sink->redraw_pending)
diff --git a/ext/wayland/gstwaylandsink.h b/ext/wayland/gstwaylandsink.h
index ff396e4..dd6bcec 100644
--- a/ext/wayland/gstwaylandsink.h
+++ b/ext/wayland/gstwaylandsink.h
@@ -58,6 +58,9 @@
   GstBufferPool *pool;
   gboolean use_dmabuf;
 
+  /* alpha compositing */
+  gfloat alpha;
+
   gboolean video_info_changed;
   GstVideoInfo video_info;
 
diff --git a/ext/wayland/wldisplay.c b/ext/wayland/wldisplay.c
index 39782bc..7ce632d 100644
--- a/ext/wayland/wldisplay.c
+++ b/ext/wayland/wldisplay.c
@@ -87,6 +87,9 @@
   if (self->dmabuf)
     zwp_linux_dmabuf_v1_destroy (self->dmabuf);
 
+  if (self->alpha_compositing)
+    zwp_alpha_compositing_v1_destroy(self->alpha_compositing);
+
   if (self->shell)
     wl_shell_destroy (self->shell);
 
@@ -175,6 +178,9 @@
   GArray *formats;
   guint i;
 
+  if (format == GST_VIDEO_FORMAT_NV12_10LE)
+    return TRUE;
+
   shm_fmt = gst_video_format_to_wl_shm_format (format);
   if (shm_fmt == (enum wl_shm_format) -1)
     return FALSE;
@@ -235,6 +241,13 @@
     self->dmabuf =
         wl_registry_bind (registry, id, &zwp_linux_dmabuf_v1_interface, 1);
     zwp_linux_dmabuf_v1_add_listener (self->dmabuf, &dmabuf_listener, self);
+  } else if (g_strcmp0 (interface, "zwp_alpha_compositing_v1") == 0) {
+    self->alpha_compositing =
+        wl_registry_bind (registry, id, &zwp_alpha_compositing_v1_interface, 1);
+  } else if (g_strcmp0 (interface, "zwp_hdr10_metadata_v1") == 0) {
+    self->hdr10_metadata =
+        wl_registry_bind (registry, id, &zwp_hdr10_metadata_v1_interface, 1);
+    g_print ("got hdr10 support\n");
   }
 }
 
diff --git a/ext/wayland/wldisplay.h b/ext/wayland/wldisplay.h
index 7c89212..2a815a7 100644
--- a/ext/wayland/wldisplay.h
+++ b/ext/wayland/wldisplay.h
@@ -26,6 +26,7 @@
 #include <wayland-client.h>
 #include "viewporter-client-protocol.h"
 #include "linux-dmabuf-unstable-v1-client-protocol.h"
+#include "alpha-compositing-unstable-v1-client-protocol.h"
 
 G_BEGIN_DECLS
 
@@ -55,6 +56,7 @@
   struct wl_shm *shm;
   struct wp_viewporter *viewporter;
   struct zwp_linux_dmabuf_v1 *dmabuf;
+  struct zwp_alpha_compositing_v1 *alpha_compositing;
   GArray *shm_formats;
   GArray *dmabuf_formats;
 
diff --git a/ext/wayland/wlwindow.c b/ext/wayland/wlwindow.c
index 6e63ab7..d417148 100644
--- a/ext/wayland/wlwindow.c
+++ b/ext/wayland/wlwindow.c
@@ -96,6 +96,9 @@
   if (self->video_viewport)
     wp_viewport_destroy (self->video_viewport);
 
+  if (self->blend_func)
+    zwp_blending_v1_destroy (self->blend_func);
+
   wl_subsurface_destroy (self->video_subsurface);
   wl_surface_destroy (self->video_surface);
 
@@ -142,6 +145,10 @@
         window->video_surface);
   }
 
+  if (display->alpha_compositing)
+    window->blend_func = zwp_alpha_compositing_v1_get_blending(
+        display->alpha_compositing, window->area_surface);
+
   /* do not accept input */
   region = wl_compositor_create_region (display->compositor);
   wl_surface_set_input_region (window->area_surface, region);
@@ -433,3 +440,12 @@
     window->src_width = -1;
   }
 }
+
+void
+gst_wl_window_set_alpha (GstWlWindow * window, gfloat alpha)
+{
+  if (window->blend_func) {
+    zwp_blending_v1_set_alpha(window->blend_func, wl_fixed_from_double(alpha));
+    zwp_blending_v1_set_blending(window->blend_func, ZWP_BLENDING_V1_BLENDING_EQUATION_FROMSOURCE);
+  }
+}
diff --git a/ext/wayland/wlwindow.h b/ext/wayland/wlwindow.h
index 2c176a1..0927594 100644
--- a/ext/wayland/wlwindow.h
+++ b/ext/wayland/wlwindow.h
@@ -51,6 +51,7 @@
   struct wl_subsurface *video_subsurface;
   struct wp_viewport *video_viewport;
   struct wl_shell_surface *shell_surface;
+  struct zwp_blending_v1 *blend_func;
 
   /* the size and position of the area_(sub)surface */
   GstVideoRectangle render_rectangle;
@@ -91,6 +92,7 @@
 void gst_wl_window_set_render_rectangle (GstWlWindow * window, gint x, gint y,
         gint w, gint h);
 void gst_wl_window_set_source_crop (GstWlWindow * window, GstBuffer * buffer);
+void gst_wl_window_set_alpha (GstWlWindow * window, gfloat alpha);
 
 G_END_DECLS