From 2074da0710a9f9b17836a95bf92d1f4b4cf1813b Mon Sep 17 00:00:00 2001
From: Fabrice Bellet <fabrice@bellet.info>
Date: Fri, 18 Nov 2016 14:57:29 +0100
Subject: [PATCH] call: fix the video preview

The port to clutter-gst 3.0 broke the video preview window.
The rounded texture effect is now provided by a ClutterEffect
sub-class, and the horizontal flip of the preview is done
directly with a cogl transformation. This last modification
using cogl_push_matrix()/cogl_pop_matrix(), the deprecation
warning of cogl has been lowered from 1.14 to 1.8.

https://bugzilla.gnome.org/show_bug.cgi?id=751185
---
 configure.ac                  |  4 ++--
 src/empathy-call-window.c     | 10 +++++-----
 src/empathy-rounded-texture.c | 28 +++++++++++++++++-----------
 src/empathy-rounded-texture.h |  6 +++---
 4 files changed, 27 insertions(+), 21 deletions(-)

diff --git a/configure.ac b/configure.ac
index ce1ae4e..2867329 100644
--- a/configure.ac
+++ b/configure.ac
@@ -58,8 +58,8 @@ AC_DEFINE(TP_SEAL_ENABLE, 1, [Prevent to use sealed variables])
 AC_DEFINE(TP_DISABLE_SINGLE_INCLUDE, 1, [Disable single include header])
 
 COGL_REQUIRED=1.14
-AC_DEFINE(COGL_VERSION_MIN_REQUIRED, COGL_VERSION_1_14, [Ignore post 1.14 deprecations])
-AC_DEFINE(COGL_VERSION_MAX_ALLOWED, COGL_VERSION_1_14, [Ignore post 1.14 deprecations])
+AC_DEFINE(COGL_VERSION_MIN_REQUIRED, COGL_VERSION_1_8, [Ignore post 1.8 deprecations])
+AC_DEFINE(COGL_VERSION_MAX_ALLOWED, COGL_VERSION_1_14, [Prevent post 1.14 APIs])
 
 GSTREAMER_REQUIRED=0.10.32
 TP_FS_REQUIRED=0.6.0
diff --git a/src/empathy-call-window.c b/src/empathy-call-window.c
index f6de5e7..3a7c756 100644
--- a/src/empathy-call-window.c
+++ b/src/empathy-call-window.c
@@ -1072,9 +1072,10 @@ create_video_preview (EmpathyCallWindow *self)
 
   pos = g_settings_get_enum (priv->settings, "camera-position");
 
-  preview = empathy_rounded_texture_new ();
+  preview = clutter_actor_new ();
   clutter_actor_set_size (preview,
       SELF_VIDEO_SECTION_WIDTH, SELF_VIDEO_SECTION_HEIGHT);
+  clutter_actor_add_effect (preview, empathy_rounded_texture_new ());
 
   priv->video_preview_sink = GST_ELEMENT (clutter_gst_video_sink_new ());
   g_object_add_weak_pointer (G_OBJECT (priv->video_preview_sink), (gpointer) &priv->video_preview_sink);
@@ -1086,10 +1087,9 @@ create_video_preview (EmpathyCallWindow *self)
   clutter_actor_set_size (priv->video_preview,
       SELF_VIDEO_SECTION_WIDTH + 2 * SELF_VIDEO_SECTION_MARGIN,
       SELF_VIDEO_SECTION_HEIGHT + 2 * SELF_VIDEO_SECTION_MARGIN);
-  clutter_actor_set_content (priv->video_preview,
-      g_object_new (CLUTTER_GST_TYPE_ASPECTRATIO,
-                    "sink", priv->video_preview,
-                    NULL));
+  clutter_actor_set_content (preview,
+      clutter_gst_content_new_with_sink (
+          CLUTTER_GST_VIDEO_SINK (priv->video_preview_sink)));
 
   /* Spinner for when changing the camera device */
   priv->preview_spinner_widget = gtk_spinner_new ();
diff --git a/src/empathy-rounded-texture.c b/src/empathy-rounded-texture.c
index 46c0b21..4f3a3aa 100644
--- a/src/empathy-rounded-texture.c
+++ b/src/empathy-rounded-texture.c
@@ -23,15 +23,19 @@
 
 G_DEFINE_TYPE (EmpathyRoundedTexture,
     empathy_rounded_texture,
-    CLUTTER_TYPE_TEXTURE)
+    CLUTTER_TYPE_EFFECT)
 
 static void
-empathy_rounded_texture_paint (ClutterActor *texture)
+empathy_rounded_texture_paint (ClutterEffect *effect,
+    ClutterEffectPaintFlags flags)
 {
+  EmpathyRoundedTexture *self = EMPATHY_ROUNDED_TEXTURE (effect);
+  ClutterActor *actor;
   ClutterActorBox allocation = { 0, };
   gfloat width, height;
 
-  clutter_actor_get_allocation_box (texture, &allocation);
+  actor = clutter_actor_meta_get_actor (CLUTTER_ACTOR_META (self));
+  clutter_actor_get_allocation_box (actor, &allocation);
   clutter_actor_box_get_size (&allocation, &width, &height);
 
   cogl_path_new ();
@@ -41,12 +45,14 @@ empathy_rounded_texture_paint (ClutterActor *texture)
 
   cogl_clip_push_from_path ();
 
-  CLUTTER_ACTOR_CLASS (empathy_rounded_texture_parent_class)->paint (texture);
-
   /* Flip */
-  cogl_rectangle_with_texture_coords (0, 0, width, height,
-      1., 0., 0., 1.);
+  cogl_push_matrix ();
+  cogl_translate (width, 0, 0);
+  cogl_scale (-1, 1, 1);
+
+  clutter_actor_continue_paint (actor);
 
+  cogl_pop_matrix ();
   cogl_clip_pop ();
 }
 
@@ -58,14 +64,14 @@ empathy_rounded_texture_init (EmpathyRoundedTexture *self)
 static void
 empathy_rounded_texture_class_init (EmpathyRoundedTextureClass *klass)
 {
-  ClutterActorClass *actor_class = CLUTTER_ACTOR_CLASS (klass);
+  ClutterEffectClass *effect_class = CLUTTER_EFFECT_CLASS (klass);
 
-  actor_class->paint = empathy_rounded_texture_paint;
+  effect_class->paint = empathy_rounded_texture_paint;
 }
 
-ClutterActor *
+ClutterEffect *
 empathy_rounded_texture_new (void)
 {
-  return CLUTTER_ACTOR (
+  return CLUTTER_EFFECT (
     g_object_new (EMPATHY_TYPE_ROUNDED_TEXTURE, NULL));
 }
diff --git a/src/empathy-rounded-texture.h b/src/empathy-rounded-texture.h
index c5d870d..4891f6d 100644
--- a/src/empathy-rounded-texture.h
+++ b/src/empathy-rounded-texture.h
@@ -29,11 +29,11 @@ typedef struct _EmpathyRoundedTexture EmpathyRoundedTexture;
 typedef struct _EmpathyRoundedTextureClass EmpathyRoundedTextureClass;
 
 struct _EmpathyRoundedTextureClass {
-    ClutterTextureClass parent_class;
+    ClutterEffectClass parent_class;
 };
 
 struct _EmpathyRoundedTexture {
-    ClutterTexture parent;
+    ClutterEffect parent;
 };
 
 GType empathy_rounded_texture_get_type (void);
@@ -55,7 +55,7 @@ GType empathy_rounded_texture_get_type (void);
   (G_TYPE_INSTANCE_GET_CLASS ((obj), EMPATHY_TYPE_ROUNDED_TEXTURE, \
     EmpathyRoundedTextureClass))
 
-ClutterActor *empathy_rounded_texture_new (void);
+ClutterEffect *empathy_rounded_texture_new (void);
 
 G_END_DECLS
 
-- 
2.7.4

