[totem/wip/hadess/glsink: 74/89] WIP: backend: Port to gtkglsink




commit 81aefae384e6bd56417603d3e784020325ed538b
Author: Bastien Nocera <hadess hadess net>
Date:   Fri Apr 30 17:45:28 2021 +0200

    WIP: backend: Port to gtkglsink

 data/controls.ui                         |   5 ++
 docs/reference/meson.build               |   1 -
 src/backend/bacon-video-controls-actor.c | 126 -------------------------------
 src/backend/bacon-video-controls-actor.h |  59 ---------------
 src/backend/bacon-video-widget.c         | 100 ++++++++++++------------
 src/backend/bacon-video-widget.h         |   9 +--
 src/backend/bvw-test.c                   |   3 +-
 src/backend/meson.build                  |   1 -
 src/meson.build                          |   1 -
 src/totem-object.c                       |  55 ++++++++++----
 src/totem-private.h                      |   5 +-
 11 files changed, 103 insertions(+), 262 deletions(-)
---
diff --git a/data/controls.ui b/data/controls.ui
index a7ebe9468..a9b1b59e4 100644
--- a/data/controls.ui
+++ b/data/controls.ui
@@ -9,6 +9,11 @@
         <property name="visible">True</property>
         <property name="can_focus">False</property>
         <property name="border_width">0</property>
+        <property name="opacity">0.86</property>
+        <style>
+          <class name="osd"/>
+          <class name="bottom"/>
+        </style>
         <child>
           <object class="GtkToolItem" id="controls_toolbutton">
             <property name="visible">True</property>
diff --git a/docs/reference/meson.build b/docs/reference/meson.build
index 6eec8d9d1..021a27119 100644
--- a/docs/reference/meson.build
+++ b/docs/reference/meson.build
@@ -2,7 +2,6 @@ doc_module = meson.project_name()
 
 private_headers = [
   'bacon-time-label.h',
-  'bacon-video-controls-actor.h',
   'bacon-video-spinner-actor.h',
   'bacon-video-widget-gst-missing-plugins.h',
   'bacon-video-widget-properties.h',
diff --git a/src/backend/bacon-video-widget.c b/src/backend/bacon-video-widget.c
index 9cd7dcb8f..e93f19189 100644
--- a/src/backend/bacon-video-widget.c
+++ b/src/backend/bacon-video-widget.c
@@ -83,7 +83,6 @@
 #include "totem-gst-pixbuf-helpers.h"
 #include "bacon-video-widget.h"
 #include "bacon-video-widget-gst-missing-plugins.h"
-#include "bacon-video-controls-actor.h"
 #include "bacon-video-spinner-actor.h"
 #include "bacon-video-widget-enums.h"
 
@@ -110,6 +109,19 @@
 
 #define I_(string) (g_intern_static_string (string))
 
+typedef enum
+{
+  GST_GTK_GL_ROTATE_METHOD_IDENTITY,
+  GST_GTK_GL_ROTATE_METHOD_90R,
+  GST_GTK_GL_ROTATE_METHOD_180,
+  GST_GTK_GL_ROTATE_METHOD_90L,
+  GST_GTK_GL_ROTATE_METHOD_FLIP_HORIZ,
+  GST_GTK_GL_ROTATE_METHOD_FLIP_VERT,
+  GST_GTK_GL_ROTATE_METHOD_FLIP_UL_LR,
+  GST_GTK_GL_ROTATE_METHOD_FLIP_UR_LL,
+  GST_GTK_GL_ROTATE_METHOD_AUTO,
+} GstGtkGLRotateMethod;
+
 static void bacon_video_widget_initable_iface_init (GInitableIface *iface);
 
 /* Signals */
@@ -162,7 +174,7 @@ static const gchar *video_props_str[4] = {
 
 struct _BaconVideoWidget
 {
-  GtkClutterEmbed              parent;
+  GtkOverlay                   parent;
 
   char                        *user_agent;
 
@@ -279,7 +291,7 @@ struct _BaconVideoWidget
   float                        rate;
 };
 
-G_DEFINE_TYPE_WITH_CODE (BaconVideoWidget, bacon_video_widget, GTK_CLUTTER_TYPE_EMBED,
+G_DEFINE_TYPE_WITH_CODE (BaconVideoWidget, bacon_video_widget, GTK_TYPE_OVERLAY,
                         G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE,
                                                bacon_video_widget_initable_iface_init))
 
@@ -770,6 +782,7 @@ set_controls_visibility (BaconVideoWidget *bvw,
                         gboolean          visible,
                         gboolean          animate)
 {
+#if 0
   guint8 opacity = visible ? OVERLAY_OPACITY : 0;
   gint header_controls_height;
   gfloat header_controls_y;
@@ -796,6 +809,7 @@ set_controls_visibility (BaconVideoWidget *bvw,
 
   bvw->reveal_controls = visible;
   g_object_notify (G_OBJECT (bvw), "reveal-controls");
+#endif
 }
 
 static void
@@ -1476,7 +1490,7 @@ bacon_video_widget_init (BaconVideoWidget * bvw)
   g_type_class_ref (BVW_TYPE_DVD_EVENT);
   g_type_class_ref (BVW_TYPE_ROTATION);
 
-  g_object_set (G_OBJECT (bvw), "use-layout-size", TRUE, NULL);
+  //g_object_set (G_OBJECT (bvw), "use-layout-size", TRUE, NULL);
 
   bvw->update_id = 0;
   bvw->tagcache = NULL;
@@ -1543,9 +1557,9 @@ bvw_handle_application_message (BaconVideoWidget *bvw, GstMessage *msg)
     /* This is necessary for the pixel-aspect-ratio of the
      * display to be taken into account. */
     get_media_size (bvw, &w, &h);
-    clutter_actor_set_size (bvw->texture, w, h);
+    //clutter_actor_set_size (bvw->texture, w, h);
 
-    set_current_actor (bvw);
+    //set_current_actor (bvw);
   } else {
     g_debug ("Unhandled application message %s", msg_name);
   }
@@ -2085,7 +2099,7 @@ update_orientation_from_video (BaconVideoWidget *bvw)
   g_free (orientation_str);
 
   angle = rotation * 90.0;
-  totem_aspect_frame_set_rotation (TOTEM_ASPECT_FRAME (bvw->frame), angle);
+  //totem_aspect_frame_set_rotation (TOTEM_ASPECT_FRAME (bvw->frame), angle);
 }
 
 static void
@@ -3813,6 +3827,7 @@ void
 bacon_video_widget_unmark_popup_busy (BaconVideoWidget *bvw,
                                      const char       *reason)
 {
+#if 0
   g_return_if_fail (BACON_IS_VIDEO_WIDGET (bvw));
 
   g_hash_table_remove (bvw->busy_popup_ht, reason);
@@ -3824,40 +3839,7 @@ bacon_video_widget_unmark_popup_busy (BaconVideoWidget *bvw,
     GST_DEBUG ("Will hide popup soon");
     schedule_hiding_popup (bvw);
   }
-}
-
-/**
- * bacon_video_widget_get_controls_object:
- * @bvw: a #BaconVideoWidget
- *
- * Get the widget which displays the video controls.
- *
- * Returns: (transfer none): controls widget
- * Since: 3.12
- */
-GObject *
-bacon_video_widget_get_controls_object (BaconVideoWidget *bvw)
-{
-  g_return_val_if_fail (BACON_IS_VIDEO_WIDGET (bvw), NULL);
-
-  return G_OBJECT (bvw->controls);
-}
-
-/**
- * bacon_video_widget_get_header_controls_object:
- * @bvw: a #BaconVideoWidget
- *
- * Get the widget which displays the video header controls.
- *
- * Returns: (transfer none): header controls widget
- * Since: 3.20
- */
-GObject *
-bacon_video_widget_get_header_controls_object (BaconVideoWidget *bvw)
-{
-  g_return_val_if_fail (BACON_IS_VIDEO_WIDGET (bvw), NULL);
-
-  return G_OBJECT (gtk_clutter_actor_get_widget (GTK_CLUTTER_ACTOR (bvw->header_controls)));
+#endif
 }
 
 /* =========================================== */
@@ -4981,7 +4963,7 @@ bacon_video_widget_set_rotation (BaconVideoWidget *bvw,
   bvw->rotation = rotation;
 
   angle = rotation * 90.0;
-  totem_aspect_frame_set_rotation (TOTEM_ASPECT_FRAME (bvw->frame), angle);
+  //totem_aspect_frame_set_rotation (TOTEM_ASPECT_FRAME (bvw->frame), angle);
 }
 
 /**
@@ -6006,6 +5988,15 @@ element_make_or_warn (const char *plugin,
   return element;
 }
 
+static void
+rotate_method_changed_cb (GObject *video_sink)
+{
+  GstGtkGLRotateMethod method;
+
+  g_object_get (video_sink, "rotate-method", &method, NULL);
+  g_message ("video sink's rotate method %d", method);
+}
+
 static gboolean
 bacon_video_widget_initable_init (GInitable     *initable,
                                  GCancellable  *cancellable,
@@ -6015,8 +6006,9 @@ bacon_video_widget_initable_init (GInitable     *initable,
   GstElement *audio_sink = NULL;
   gchar *version_str;
   GstPlayFlags flags;
+  GtkWidget *area;
   ClutterActor *layout;
-  GstElement *audio_bin;
+  GstElement *glsinkbin, *audio_bin;
   GstPad *audio_pad;
   ClutterAction *action;
   GObject *item;
@@ -6040,7 +6032,9 @@ bacon_video_widget_initable_init (GInitable     *initable,
   /* Instantiate all the fallible plugins */
   bvw->play = element_make_or_warn ("playbin", "play");
   bvw->audio_pitchcontrol = element_make_or_warn ("scaletempo", "scaletempo");
-  bvw->video_sink = GST_ELEMENT (clutter_gst_video_sink_new ());
+  bvw->video_sink = element_make_or_warn ("gtkglsink", "video-sink");
+  glsinkbin = element_make_or_warn ("glsinkbin", "glsinkbin");
+  g_object_set (glsinkbin, "sink", bvw->video_sink, NULL);
   audio_sink = element_make_or_warn ("autoaudiosink", "audio-sink");
 
   if (!bvw->play ||
@@ -6082,6 +6076,17 @@ bacon_video_widget_initable_init (GInitable     *initable,
 
   bvw->cursor_shown = TRUE;
 
+  g_object_get (bvw->video_sink, "widget", &area, NULL);
+  gtk_container_add (GTK_CONTAINER (bvw), area);
+  gtk_widget_show (area);
+  //g_object_unref (area);
+
+  g_object_set (bvw->video_sink,
+                "rotate-method", GST_GTK_GL_ROTATE_METHOD_AUTO,
+                NULL);
+  g_signal_connect (bvw->video_sink, "notify::rotate-method",
+                   G_CALLBACK (rotate_method_changed_cb), NULL);
+#if 0
   bvw->stage = gtk_clutter_embed_get_stage (GTK_CLUTTER_EMBED (bvw));
   clutter_actor_set_text_direction (bvw->stage,
                                    CLUTTER_TEXT_DIRECTION_LTR);
@@ -6178,9 +6183,9 @@ bacon_video_widget_initable_init (GInitable     *initable,
   item = g_object_get_data (G_OBJECT (bvw->controls), "volume_button");
   g_signal_connect (item, "scroll-event",
                    G_CALLBACK (bacon_video_widget_handle_scroll), bvw);
-
+#endif
   /* And tell playbin */
-  g_object_set (bvw->play, "video-sink", bvw->video_sink, NULL);
+  g_object_set (bvw->play, "video-sink", glsinkbin, NULL);
 
   /* Link the audiopitch element */
   bvw->audio_capsfilter =
@@ -6330,7 +6335,8 @@ bacon_video_widget_set_fullscreen (BaconVideoWidget *bvw,
 {
   g_return_if_fail (BACON_IS_VIDEO_WIDGET (bvw));
 
-  g_object_set (bvw->header_controls, "visible", fullscreen, NULL);
+  //FIXME
+  //g_object_set (bvw->header_controls, "visible", fullscreen, NULL);
 }
 
 /*
diff --git a/src/backend/bacon-video-widget.h b/src/backend/bacon-video-widget.h
index 734dbdbe9..183c97338 100644
--- a/src/backend/bacon-video-widget.h
+++ b/src/backend/bacon-video-widget.h
@@ -29,12 +29,8 @@
 
 #include <clutter-gtk/clutter-gtk.h>
 
-#ifndef glib_autoptr_clear_GtkClutterEmbed
-G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkClutterEmbed, g_object_unref)
-#endif
-
 #define BACON_TYPE_VIDEO_WIDGET                     (bacon_video_widget_get_type ())
-G_DECLARE_FINAL_TYPE(BaconVideoWidget, bacon_video_widget, BACON, VIDEO_WIDGET, GtkClutterEmbed)
+G_DECLARE_FINAL_TYPE(BaconVideoWidget, bacon_video_widget, BACON, VIDEO_WIDGET, GtkOverlay)
 #define BVW_ERROR bacon_video_widget_error_quark ()
 
 /**
@@ -422,6 +418,3 @@ void bacon_video_widget_mark_popup_busy           (BaconVideoWidget *bvw,
                                                   const char       *reason);
 void bacon_video_widget_unmark_popup_busy         (BaconVideoWidget *bvw,
                                                   const char       *reason);
-
-GObject * bacon_video_widget_get_controls_object  (BaconVideoWidget *bvw);
-GObject * bacon_video_widget_get_header_controls_object (BaconVideoWidget *bvw);
diff --git a/src/backend/bvw-test.c b/src/backend/bvw-test.c
index 60c173234..1ab0ab2e2 100644
--- a/src/backend/bvw-test.c
+++ b/src/backend/bvw-test.c
@@ -123,6 +123,7 @@ int main
        g_signal_connect (G_OBJECT (bvw), "got-redirect", G_CALLBACK (on_redirect), NULL);
        g_signal_connect (G_OBJECT (bvw), "error", G_CALLBACK (error_cb), NULL);
 
+#if 0
        box = g_object_get_data (bacon_video_widget_get_controls_object (BACON_VIDEO_WIDGET (bvw)), 
"controls_box");
 
        /* Previous */
@@ -150,7 +151,7 @@ int main
        gtk_button_set_image (GTK_BUTTON (item), image);
 
        gtk_widget_show_all (GTK_WIDGET (box));
-
+#endif
        gtk_container_add (GTK_CONTAINER (win),bvw);
 
        gtk_widget_realize (GTK_WIDGET (win));
diff --git a/src/backend/meson.build b/src/backend/meson.build
index 0a47fbd9f..eb8a56e62 100644
--- a/src/backend/meson.build
+++ b/src/backend/meson.build
@@ -34,7 +34,6 @@ endforeach
 
 sources = files(
   'bacon-time-label.c',
-  'bacon-video-controls-actor.c',
   'bacon-video-spinner-actor.c',
   'bacon-video-widget-gst-missing-plugins.c',
   'bacon-video-widget.c',
diff --git a/src/meson.build b/src/meson.build
index 7fed9f1b2..d11ffc96d 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -6,7 +6,6 @@ subdir('backend')
 
 enum_headers = files(
   'backend/bacon-time-label.h',
-  'backend/bacon-video-controls-actor.h',
   'backend/bacon-video-spinner-actor.h',
   'backend/bacon-video-widget-gst-missing-plugins.h',
   'backend/bacon-video-widget.h',
diff --git a/src/totem-object.c b/src/totem-object.c
index 01f05f344..4592d1701 100644
--- a/src/totem-object.c
+++ b/src/totem-object.c
@@ -205,11 +205,23 @@ totem_object_app_activate (GApplication *app)
 
        totem->controls_visibility = TOTEM_CONTROLS_UNDEFINED;
 
-       totem->seek = g_object_get_data (totem->controls, "seek_scale");
+       totem->controls = gtk_builder_new ();
+       const char *objects[] = { "toolbar", NULL };
+       GError *error = NULL;
+        if (gtk_builder_add_objects_from_file (totem->controls, DATADIR "/totem/controls.ui", (gchar **) 
objects, &error) == 0)
+               g_assert_not_reached ();
+       gtk_grid_attach (GTK_GRID (totem->bvw_grid),
+                        GTK_WIDGET (gtk_builder_get_object (totem->controls, "toolbar")),
+                        0, 2, 1, 1);
+       gtk_widget_set_hexpand (GTK_WIDGET (gtk_builder_get_object (totem->controls, "toolbar")), TRUE);
+       gtk_widget_set_vexpand (GTK_WIDGET (gtk_builder_get_object (totem->controls, "toolbar")), TRUE);
+       gtk_widget_set_valign (GTK_WIDGET (gtk_builder_get_object (totem->controls, "toolbar")), 
GTK_ALIGN_END);
+
+       totem->seek = GTK_WIDGET (gtk_builder_get_object (totem->controls, "seek_scale"));
        totem->seekadj = gtk_range_get_adjustment (GTK_RANGE (totem->seek));
-       totem->volume = g_object_get_data (totem->controls, "volume_button");
-       totem->time_label = g_object_get_data (totem->controls, "time_label");
-       totem->time_rem_label = g_object_get_data (totem->controls, "time_rem_label");
+       totem->volume = GTK_WIDGET (gtk_builder_get_object (totem->controls, "volume_button"));
+       totem->time_label = BACON_TIME_LABEL (gtk_builder_get_object (totem->controls, "time_label"));
+       totem->time_rem_label = BACON_TIME_LABEL (gtk_builder_get_object (totem->controls, "time_rem_label"));
        totem->pause_start = optionstate.pause;
 
        totem_callback_connect (totem);
@@ -1631,8 +1643,9 @@ window_state_event_cb (GtkWidget           *window,
                show_controls (totem, TRUE);
        }
 
-       bacon_video_widget_set_fullscreen (totem->bvw,
-                                          totem->controls_visibility == TOTEM_CONTROLS_FULLSCREEN);
+       g_object_set (totem->fullscreen_header,
+                     "visible", totem->controls_visibility == TOTEM_CONTROLS_FULLSCREEN,
+                     NULL);
 
        action = g_action_map_lookup_action (G_ACTION_MAP (totem), "fullscreen");
        g_simple_action_set_state (G_SIMPLE_ACTION (action),
@@ -3809,6 +3822,7 @@ create_control_button (TotemObject *totem,
        gtk_button_set_image (GTK_BUTTON (button), image);
        gtk_widget_set_valign (GTK_WIDGET (button), GTK_ALIGN_CENTER);
        gtk_style_context_add_class (gtk_widget_get_style_context (button), "image-button");
+       g_message ("action_name: %s", action_name);
        if (g_str_equal (action_name, "app.play")) {
                g_object_set (G_OBJECT (image),
                              "margin-start", 16,
@@ -3841,7 +3855,7 @@ totem_callback_connect (TotemObject *totem)
                                   g_variant_new_boolean (totem_playlist_get_repeat (totem->playlist)));
 
        /* Controls */
-       box = g_object_get_data (totem->controls, "controls_box");
+       box = GTK_BOX (gtk_builder_get_object (totem->controls, "controls_box"));
        gtk_widget_insert_action_group (GTK_WIDGET (box), "app", G_ACTION_GROUP (totem));
 
        /* Previous */
@@ -3854,6 +3868,7 @@ totem_callback_connect (TotemObject *totem)
        item = create_control_button (totem, "app.play",
                                      "media-playback-start-symbolic",
                                      _("Play / Pause"));
+       g_assert (item);
        gtk_box_pack_start (box, item, FALSE, FALSE, 0);
 
        /* Next */
@@ -3878,7 +3893,7 @@ totem_callback_connect (TotemObject *totem)
                          G_CALLBACK (volume_button_menu_shown_cb), totem);
 
        /* Go button */
-       item = g_object_get_data (totem->controls, "go_button");
+       item = GTK_WIDGET (gtk_builder_get_object (totem->controls, "go_button"));
        menu = (GMenuModel *) gtk_builder_get_object (totem->xml, "gomenu");
        gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (item), menu);
        popover = gtk_menu_button_get_popover (GTK_MENU_BUTTON (item));
@@ -4027,13 +4042,12 @@ grilo_widget_setup (TotemObject *totem)
 }
 
 static void
-add_fullscreen_toolbar (TotemObject *totem)
+add_fullscreen_toolbar (TotemObject *totem,
+                       GtkWidget   *container)
 {
-       GtkWidget *container, *item;
+       GtkWidget *item;
        GMenuModel *menu;
 
-       container = GTK_WIDGET (bacon_video_widget_get_header_controls_object (totem->bvw));
-
        totem->fullscreen_header = g_object_new (TOTEM_TYPE_MAIN_TOOLBAR,
                                                 "show-search-button", FALSE,
                                                 "show-select-button", FALSE,
@@ -4066,8 +4080,11 @@ add_fullscreen_toolbar (TotemObject *totem)
                          G_CALLBACK (popup_menu_shown_cb), totem);
        totem->fullscreen_gear_button = item;
 
-       gtk_container_add (GTK_CONTAINER (container), totem->fullscreen_header);
+       gtk_grid_attach (GTK_GRID (container), totem->fullscreen_header, 0, 0, 1, 1);
+       gtk_widget_set_halign (totem->fullscreen_header, GTK_ALIGN_FILL);
+       gtk_widget_set_hexpand (totem->fullscreen_header, TRUE);
        gtk_widget_show_all (totem->fullscreen_header);
+       gtk_widget_hide (totem->fullscreen_header);
 }
 
 void
@@ -4090,8 +4107,8 @@ video_widget_create (TotemObject *totem)
        window = gtk_widget_get_window (totem->win);
 
        fullscreen = window && ((gdk_window_get_state (window) & GDK_WINDOW_STATE_FULLSCREEN) != 0);
-       bacon_video_widget_set_fullscreen (totem->bvw, fullscreen);
-       totem->controls = bacon_video_widget_get_controls_object (totem->bvw);
+       //FIXME doesn't exist yet
+       g_object_set (totem->fullscreen_header, "visible", fullscreen, NULL);
 
        g_signal_connect_after (G_OBJECT (totem->bvw),
                        "button-press-event",
@@ -4146,7 +4163,13 @@ video_widget_create (TotemObject *totem)
        gtk_container_add (container,
                        GTK_WIDGET (totem->bvw));
 
-       add_fullscreen_toolbar (totem);
+       //FIXME
+       totem->bvw_grid = gtk_grid_new ();
+       gtk_overlay_add_overlay (GTK_OVERLAY (totem->bvw), totem->bvw_grid);
+       gtk_widget_set_halign (totem->bvw_grid, GTK_ALIGN_FILL);
+       gtk_widget_set_valign (totem->bvw_grid, GTK_ALIGN_FILL);
+       gtk_widget_show (totem->bvw_grid);
+       add_fullscreen_toolbar (totem, totem->bvw_grid);
 
        /* Events for the widget video window as well */
        gtk_widget_add_events (GTK_WIDGET (totem->bvw),
diff --git a/src/totem-private.h b/src/totem-private.h
index de6edb42d..62cd5276f 100644
--- a/src/totem-private.h
+++ b/src/totem-private.h
@@ -46,7 +46,7 @@
                widget = GTK_WIDGET (gtk_builder_get_object (xml, name));       \
                gtk_widget_set_sensitive (widget, state);                       \
        }
-#define totem_controls_set_sensitivity(name, state) gtk_widget_set_sensitive (g_object_get_data 
(totem->controls, name), state)
+#define totem_controls_set_sensitivity(name, state) gtk_widget_set_sensitive (GTK_WIDGET 
(gtk_builder_get_object (totem->controls, name)), state)
 
 #define totem_object_set_sensitivity2(name, state)                                     \
        {                                                                               \
@@ -75,12 +75,13 @@ struct _TotemObject {
        GtkWidget *win;
        GtkWidget *stack;
        BaconVideoWidget *bvw;
+       GtkWidget *bvw_grid;
        GtkWidget *prefs;
        GtkWindow *shortcuts_win;
 
        GtkWidget *grilo;
 
-       GObject *controls;
+       GtkBuilder *controls;
        GtkWidget *play_button;
        BaconTimeLabel *time_label;
        BaconTimeLabel *time_rem_label;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]