From e3b5214ac69b130217d0d8f06683bbe27f6e36c2 Mon Sep 17 00:00:00 2001 From: Matthew Waters Date: Tue, 22 Mar 2016 23:10:24 +1100 Subject: [PATCH] gl/examples: fix switchvideooverlay for wayland and call XInitThreads() for X11 --- .../examples/gl/gtk/switchvideooverlay/Makefile.am | 4 +-- tests/examples/gl/gtk/switchvideooverlay/main.cpp | 31 +++++++++++++--------- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/tests/examples/gl/gtk/switchvideooverlay/Makefile.am b/tests/examples/gl/gtk/switchvideooverlay/Makefile.am index dbe007c..e6ebf70 100644 --- a/tests/examples/gl/gtk/switchvideooverlay/Makefile.am +++ b/tests/examples/gl/gtk/switchvideooverlay/Makefile.am @@ -4,8 +4,8 @@ switchvideooverlay_SOURCES = main.cpp switchvideooverlay_CXXFLAGS=-I$(top_srcdir)/gst-libs -I$(top_builddir)/gst-libs \ $(GST_PLUGINS_BASE_CFLAGS) $(GST_CXXFLAGS) \ - $(GL_CFLAGS) $(GTK3_CFLAGS) + $(GL_CFLAGS) $(GTK3_CFLAGS) $(X_CFLAGS) switchvideooverlay_LDADD=../libgstgtkhelper.la \ $(GTK3_LIBS) $(GST_PLUGINS_BASE_LIBS) $(GST_LIBS) \ - $(GL_LIBS) -lgstvideo-$(GST_API_VERSION) + $(GL_LIBS) -lgstvideo-$(GST_API_VERSION) $(X_LIBS) diff --git a/tests/examples/gl/gtk/switchvideooverlay/main.cpp b/tests/examples/gl/gtk/switchvideooverlay/main.cpp index ea53ea1..476478d 100644 --- a/tests/examples/gl/gtk/switchvideooverlay/main.cpp +++ b/tests/examples/gl/gtk/switchvideooverlay/main.cpp @@ -18,12 +18,19 @@ * Boston, MA 02110-1301, USA. */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include #include #include #include "../gstgtk.h" +#ifdef HAVE_X11 +#include +#endif static GstBusSyncReply create_window (GstBus* bus, GstMessage* message, GtkWidget* widget) { @@ -59,7 +66,7 @@ resize_cb (GtkWidget * widget, GdkEvent * event, gpointer sink) gtk_widget_get_allocation (widget, &allocation); gst_video_overlay_set_render_rectangle (GST_VIDEO_OVERLAY (sink), allocation.x, allocation.y, allocation.width, allocation.height); - return G_SOURCE_CONTINUE; + return FALSE; } static void end_stream_cb(GstBus* bus, GstMessage* message, GstElement* pipeline) @@ -104,6 +111,7 @@ static gboolean expose_cb(GtkWidget* widget, cairo_t *cr, GstElement* videosink) static gboolean on_click_drawing_area(GtkWidget* widget, GdkEventButton* event, GstElement* videosink) { GtkAllocation allocation; + GtkWidget *parent = gtk_widget_get_parent (widget); g_print ("switch the drawing area %p\n", widget); gst_video_overlay_set_gtk_window (GST_VIDEO_OVERLAY (videosink), widget); @@ -111,6 +119,11 @@ static gboolean on_click_drawing_area(GtkWidget* widget, GdkEventButton* event, gtk_widget_get_allocation (widget, &allocation); gst_video_overlay_set_render_rectangle (GST_VIDEO_OVERLAY (videosink), allocation.x, allocation.y, allocation.width, allocation.height); + /* XXX: required on wayland as changing the window handle (subsurface) + * requires a wl_surface::commit from the parent */ + if (parent) + gtk_widget_queue_draw (parent); + return FALSE; } @@ -153,16 +166,12 @@ static void button_state_playing_cb(GtkWidget* widget, GstElement* pipeline) g_print ("GST_STATE_PLAYING\n"); } -static void area_realize_cb(GtkWidget* widget, gpointer data) -{ - g_print ("realize %p\n", widget); - if (!gdk_window_ensure_native (gtk_widget_get_window (widget))) - g_error ("Failed to create native window!"); -} - - gint main (gint argc, gchar *argv[]) { +#ifdef HAVE_X11 + XInitThreads(); +#endif + gtk_init (&argc, &argv); gst_init (&argc, &argv); @@ -250,10 +259,6 @@ gint main (gint argc, gchar *argv[]) gtk_widget_set_size_request (area_top_right, 320, 240); gtk_grid_attach (GTK_GRID (table_areas), area_top_right, 1, 0, 1, 1); - //set window id on this event - g_signal_connect(area_top_left, "realize", G_CALLBACK(area_realize_cb), NULL); - g_signal_connect(area_top_right, "realize", G_CALLBACK(area_realize_cb), NULL); - gtk_widget_set_redraw_on_allocate (area_top_left, TRUE); gtk_widget_set_redraw_on_allocate (area_top_right, TRUE); gtk_widget_realize(area_top_left); -- 2.7.4