totem r5015 - in trunk: . src/backend



Author: hadess
Date: Fri Jan 11 10:35:38 2008
New Revision: 5015
URL: http://svn.gnome.org/viewvc/totem?rev=5015&view=rev

Log:
2008-01-11  Bastien Nocera  <hadess hadess net>

	* src/backend/bacon-resize.c: 
	* src/backend/bacon-resize.h:
	Patch from Philip Withnall <pwithnall svn gnome org> to turn
	the bacon-resize code into an object

	* src/backend/bacon-video-widget-gst-0.10.c:
	(bacon_video_widget_unrealize),
	(bacon_video_widget_set_fullscreen),
	(bacon_video_widget_new):
	* src/backend/bacon-video-widget-xine.c:
	(bacon_video_widget_realize),
	(bacon_video_widget_unrealize), 
	(bacon_video_widget_set_fullscreen):
	Port to the new API (Closes: #370099)



Modified:
   trunk/ChangeLog
   trunk/src/backend/bacon-resize.c
   trunk/src/backend/bacon-resize.h
   trunk/src/backend/bacon-video-widget-gst-0.10.c
   trunk/src/backend/bacon-video-widget-xine.c

Modified: trunk/src/backend/bacon-resize.c
==============================================================================
--- trunk/src/backend/bacon-resize.c	(original)
+++ trunk/src/backend/bacon-resize.c	Fri Jan 11 10:35:38 2008
@@ -19,9 +19,9 @@
 
 #include "config.h"
 #include "bacon-resize.h"
+#include <glib.h>
 
 #ifdef HAVE_XVIDMODE
-#include <glib.h>
 #include <gdk/gdkx.h>
 #include <gdk/gdk.h>
 #include <X11/X.h>
@@ -31,49 +31,187 @@
 #include <X11/extensions/xf86vmode.h>
 #include <X11/extensions/Xrandr.h>
 #include <X11/extensions/Xrender.h>
+#endif
+
+static void bacon_resize_class_init	(BaconResizeClass *klass);
+static void bacon_resize_init		(BaconResize *ggo);
+static void bacon_resize_set_property	(GObject *object,
+					 guint property_id,
+					 const GValue *value,
+					 GParamSpec *pspec);
+static void bacon_resize_get_property	(GObject *object,
+					 guint property_id,
+					 GValue *value,
+					 GParamSpec *pspec);
+#ifdef HAVE_XVIDMODE
+static void bacon_resize_finalize	(GObject *object);
+#endif /* HAVE_XVIDMODE */
 
-/* XRandR */
-XRRScreenConfiguration *xr_screen_conf;
-XRRScreenSize *xr_sizes;
-Rotation xr_current_rotation;
-SizeID xr_original_size;
+static void set_video_widget		(BaconResize *resize,
+					 GtkWidget *video_widget);
+static void screen_changed_cb		(GtkWidget *video_widget,
+					 GdkScreen *previous_screen,
+					 BaconResize *resize);
+
+struct BaconResizePrivate {
+	gboolean have_xvidmode;
+	gboolean resized;
+	GtkWidget *video_widget;
+#ifdef HAVE_XVIDMODE
+	/* XRandR */
+	XRRScreenConfiguration *xr_screen_conf;
+	XRRScreenSize *xr_sizes;
+	Rotation xr_current_rotation;
+	SizeID xr_original_size;
 #endif
+};
+
+enum {
+	PROP_HAVE_XVIDMODE = 1,
+	PROP_VIDEO_WIDGET
+};
 
-gboolean
-bacon_resize_init (void)
+G_DEFINE_TYPE (BaconResize, bacon_resize, G_TYPE_OBJECT)
+
+static void
+bacon_resize_class_init (BaconResizeClass *klass)
 {
+	GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+	g_type_class_add_private (klass, sizeof (BaconResizePrivate));
+
+	object_class->set_property = bacon_resize_set_property;
+	object_class->get_property = bacon_resize_get_property;
 #ifdef HAVE_XVIDMODE
+	object_class->finalize = bacon_resize_finalize;
+#endif /* HAVE_XVIDMODE */
+
+	g_object_class_install_property (object_class, PROP_HAVE_XVIDMODE,
+					 g_param_spec_boolean ("have-xvidmode", NULL, NULL,
+							       FALSE, G_PARAM_READABLE));
+
+	g_object_class_install_property (object_class, PROP_VIDEO_WIDGET,
+					 g_param_spec_object ("video-widget", "video-widget",
+						 	      "The related video widget",
+							      GTK_TYPE_WIDGET,
+							      G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY));
+}
+
+static void
+bacon_resize_init (BaconResize *resize)
+{
+	resize->priv = G_TYPE_INSTANCE_GET_PRIVATE (resize, BACON_TYPE_RESIZE, BaconResizePrivate);
+
+	resize->priv->have_xvidmode = FALSE;
+	resize->priv->resized = FALSE;
+}
+
+BaconResize *
+bacon_resize_new (GtkWidget *video_widget)
+{
+	return BACON_RESIZE (g_object_new (BACON_TYPE_RESIZE, "video-widget", video_widget, NULL));
+}
+
+#ifdef HAVE_XVIDMODE
+static void
+bacon_resize_finalize (GObject *object)
+{
+	BaconResize *self = BACON_RESIZE (object);
+
+	g_signal_handlers_disconnect_by_func (self->priv->video_widget, screen_changed_cb, self);
+
+	G_OBJECT_CLASS (bacon_resize_parent_class)->finalize (object);
+}
+#endif /* HAVE_XVIDMODE */
+
+static void
+bacon_resize_set_property (GObject *object,
+			   guint property_id,
+			   const GValue *value,
+			   GParamSpec *pspec)
+{
+	switch (property_id)
+	{
+	case PROP_VIDEO_WIDGET:
+		set_video_widget (BACON_RESIZE (object), GTK_WIDGET (g_value_get_object (value)));
+		break;
+	default:
+		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+	}
+}
+
+static void
+bacon_resize_get_property (GObject *object,
+			   guint property_id,
+			   GValue *value,
+			   GParamSpec *pspec)
+{
+	switch (property_id)
+	{
+	case PROP_HAVE_XVIDMODE:
+		g_value_set_boolean (value, BACON_RESIZE (object)->priv->have_xvidmode);
+		break;
+	default:
+		G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
+	}
+}
+
+static void
+set_video_widget (BaconResize *resize, GtkWidget *video_widget)
+{
+#ifdef HAVE_XVIDMODE
+	GdkDisplay *display;
+	GdkScreen *screen;
 	int event_basep, error_basep;
+	XRRScreenConfiguration *xr_screen_conf;
+#endif
+	g_return_if_fail (GTK_WIDGET_REALIZED (video_widget));
+
+	resize->priv->video_widget = video_widget;
+
+#ifdef HAVE_XVIDMODE
+	display = gtk_widget_get_display (video_widget);
+	screen = gtk_widget_get_screen (video_widget);
+
+	g_signal_connect (G_OBJECT (video_widget),
+			  "screen-changed", G_CALLBACK (screen_changed_cb), resize);
 
-	XLockDisplay (GDK_DISPLAY());
+	XLockDisplay (GDK_DISPLAY_XDISPLAY (display));
 
-	if (!XF86VidModeQueryExtension (GDK_DISPLAY(), &event_basep, &error_basep))
+	if (!XF86VidModeQueryExtension (GDK_DISPLAY_XDISPLAY (display), &event_basep, &error_basep))
 		goto bail;
 
-	if (!XRRQueryExtension (GDK_DISPLAY(), &event_basep, &error_basep))
+	if (!XRRQueryExtension (GDK_DISPLAY_XDISPLAY (display), &event_basep, &error_basep))
 		goto bail;
 
 	/* We don't use the output here, checking whether XRRGetScreenInfo works */
-	xr_screen_conf = XRRGetScreenInfo (GDK_DISPLAY(), GDK_ROOT_WINDOW());
+	xr_screen_conf = XRRGetScreenInfo (GDK_DISPLAY_XDISPLAY (display), GDK_WINDOW_XWINDOW (gdk_screen_get_root_window (screen)));
 	if (xr_screen_conf == NULL)
 		goto bail;
-
+ 
 	XRRFreeScreenConfigInfo (xr_screen_conf);
-	xr_screen_conf = NULL;
-	XUnlockDisplay (GDK_DISPLAY());
-
-	return TRUE;
+	XUnlockDisplay (GDK_DISPLAY_XDISPLAY (display));
+	resize->priv->have_xvidmode = TRUE;
+	return;
 
 bail:
-	XUnlockDisplay (GDK_DISPLAY());
-	return FALSE;
+	XUnlockDisplay (GDK_DISPLAY_XDISPLAY (display));
+	resize->priv->have_xvidmode = FALSE;
+#endif /* HAVE_XVIDMODE */
+}
 
+static void screen_changed_cb (GtkWidget *video_widget, GdkScreen *previous_screen, BaconResize *resize)
+{
+#ifdef HAVE_XVIDMODE
+	if (resize->priv->resized == TRUE)
+		bacon_resize_resize (resize);
+	else
+		bacon_resize_restore (resize);
 #endif /* HAVE_XVIDMODE */
-	return FALSE;
 }
 
 void
-bacon_resize (GtkWidget *widget)
+bacon_resize_resize (BaconResize *resize)
 {
 #ifdef HAVE_XVIDMODE
 	int width, height, i, xr_nsize, res, dotclock;
@@ -84,77 +222,74 @@
 	GdkScreen *screen;
 	Display *Display;
 
-	Display = GDK_DRAWABLE_XDISPLAY (widget->window);
+	g_return_if_fail (GTK_IS_WIDGET (resize->priv->video_widget));
+	g_return_if_fail (GTK_WIDGET_REALIZED (resize->priv->video_widget));
+
+	Display = GDK_DRAWABLE_XDISPLAY (resize->priv->video_widget->window);
 	if (Display == NULL)
 		return;
 
 	XLockDisplay (Display);
 
-	screen = gtk_widget_get_screen (widget);
+	screen = gtk_widget_get_screen (resize->priv->video_widget);
 	root = gdk_screen_get_root_window (screen);
 
 	/* XF86VidModeGetModeLine just doesn't work nicely with multiple monitors */
-	if (gdk_screen_get_n_monitors (screen) > 1) {
-		XUnlockDisplay (Display);
-		return;
-	}
+	if (gdk_screen_get_n_monitors (screen) > 1)
+		goto bail;
 
 	res = XF86VidModeGetModeLine (Display, GDK_SCREEN_XNUMBER (screen), &dotclock, &modeline);
-	if (!res) {
-		XUnlockDisplay (Display);
-		return;
-	}
+	if (!res)
+		goto bail;
 
 	/* Check if there's a viewport */
 	width = gdk_screen_get_width (screen);
 	height = gdk_screen_get_height (screen);
 
-	if (width <= modeline.hdisplay && height <= modeline.vdisplay) {
-		XUnlockDisplay (Display);
-		return;
-	}
+	if (width <= modeline.hdisplay && height <= modeline.vdisplay)
+		goto bail;
 
 	gdk_error_trap_push ();
-	/* Find the xrandr mode that corresponds to the real size */
-	xr_screen_conf = XRRGetScreenInfo (Display, GDK_WINDOW_XWINDOW (root));
-	xr_sizes = XRRConfigSizes (xr_screen_conf, &xr_nsize);
-	xr_original_size = XRRConfigCurrentConfiguration
-		(xr_screen_conf, &xr_current_rotation);
+
+	/* Find the XRandR mode that corresponds to the real size */
+	resize->priv->xr_screen_conf = XRRGetScreenInfo (Display, GDK_WINDOW_XWINDOW (root));
+	xr_sizes = XRRConfigSizes (resize->priv->xr_screen_conf, &xr_nsize);
+	resize->priv->xr_original_size = XRRConfigCurrentConfiguration (resize->priv->xr_screen_conf, &(resize->priv->xr_current_rotation));
 	if (gdk_error_trap_pop ()) {
 		g_warning ("XRRConfigSizes or XRRConfigCurrentConfiguration failed");
-		XUnlockDisplay (Display);
-		return;
+		goto bail;
 	}
 
 	for (i = 0; i < xr_nsize; i++) {
-		if (modeline.hdisplay == xr_sizes[i].width
-		    && modeline.vdisplay == xr_sizes[i].height) {
+		if (modeline.hdisplay == xr_sizes[i].width && modeline.vdisplay == xr_sizes[i].height) {
 			found = TRUE;
 			break;
 		}
 	}
 
-	if (!found) {
-		XUnlockDisplay (Display);
-		return;
-	}
+	if (!found)
+		goto bail;
+
 	gdk_error_trap_push ();
 	XRRSetScreenConfig (Display,
-			    xr_screen_conf,
-			    GDK_WINDOW_XWINDOW (root),
-			    (SizeID) i,
-			    xr_current_rotation,
-			    CurrentTime);
+			resize->priv->xr_screen_conf,
+			GDK_WINDOW_XWINDOW (root),
+			(SizeID) i,
+			resize->priv->xr_current_rotation,
+			CurrentTime);
 	gdk_flush ();
 	if (gdk_error_trap_pop ())
 		g_warning ("XRRSetScreenConfig failed");
+	else
+		resize->priv->resized = TRUE;
 
+bail:
 	XUnlockDisplay (Display);
 #endif /* HAVE_XVIDMODE */
 }
 
 void
-bacon_restore (GtkWidget *widget)
+bacon_resize_restore (BaconResize *resize)
 {
 #ifdef HAVE_XVIDMODE
 	int width, height, res, dotclock;
@@ -163,47 +298,50 @@
 	GdkScreen *screen;
 	Display *Display;
 
-	/* We haven't called bacon_resize before, or it exited
-	 * as we didn't need a resize */
-	if (xr_screen_conf == NULL)
+	g_return_if_fail (GTK_IS_WIDGET (resize->priv->video_widget));
+	g_return_if_fail (GTK_WIDGET_REALIZED (resize->priv->video_widget));
+
+	/* We haven't called bacon_resize_resize before, or it exited
+	 * as we didn't need a resize. */
+	if (resize->priv->xr_screen_conf == NULL)
 		return;
 
-	Display = GDK_DRAWABLE_XDISPLAY (widget->window);
+	Display = GDK_DRAWABLE_XDISPLAY (resize->priv->video_widget->window);
 	if (Display == NULL)
 		return;
 
 	XLockDisplay (Display);
 
-	screen = gtk_widget_get_screen (widget);
+	screen = gtk_widget_get_screen (resize->priv->video_widget);
 	root = gdk_screen_get_root_window (screen);
 	res = XF86VidModeGetModeLine (Display, GDK_SCREEN_XNUMBER (screen), &dotclock, &modeline);
-	if (!res) {
-		XUnlockDisplay (Display);
-		return;
-	}
+	if (!res)
+		goto bail;
 
 	/* Check if there's a viewport */
 	width = gdk_screen_get_width (screen);
 	height = gdk_screen_get_height (screen);
 
-	if (width > modeline.hdisplay && height > modeline.vdisplay) {
-		XUnlockDisplay (Display);
-		return;
-	}
+	if (width > modeline.hdisplay && height > modeline.vdisplay)
+		goto bail;
+
 	gdk_error_trap_push ();
 	XRRSetScreenConfig (Display,
-			    xr_screen_conf,
-			    GDK_WINDOW_XWINDOW (root),
-			    xr_original_size,
-			    xr_current_rotation,
-			    CurrentTime);
+			resize->priv->xr_screen_conf,
+			GDK_WINDOW_XWINDOW (root),
+			resize->priv->xr_original_size,
+			resize->priv->xr_current_rotation,
+			CurrentTime);
 	gdk_flush ();
 	if (gdk_error_trap_pop ())
 		g_warning ("XRRSetScreenConfig failed");
+	else
+		resize->priv->resized = FALSE;
 
-	XRRFreeScreenConfigInfo (xr_screen_conf);
-	xr_screen_conf = NULL;
+	XRRFreeScreenConfigInfo (resize->priv->xr_screen_conf);
+	resize->priv->xr_screen_conf = NULL;
 
+bail:
 	XUnlockDisplay (Display);
 #endif
 }

Modified: trunk/src/backend/bacon-resize.h
==============================================================================
--- trunk/src/backend/bacon-resize.h	(original)
+++ trunk/src/backend/bacon-resize.h	Fri Jan 11 10:35:38 2008
@@ -17,9 +17,39 @@
  * Foundation, Inc., 59 Temple Place - Suite 330, Cambridge, MA 02139, USA.
  */
 
-#include <gtk/gtk.h>
+#ifndef BACON_RESIZE_H
+#define BACON_RESIZE_H
 
-gboolean bacon_resize_init (void);
-void bacon_resize (GtkWidget *widget);
-void bacon_restore (GtkWidget *widget);
+#include <glib.h>
+#include <glib-object.h>
+#include <gtk/gtkwidget.h>
 
+G_BEGIN_DECLS
+
+#define BACON_TYPE_RESIZE		(bacon_resize_get_type ())
+#define BACON_RESIZE(obj)		(G_TYPE_CHECK_INSTANCE_CAST ((obj), BACON_TYPE_RESIZE, BaconResize))
+#define BACON_RESIZE_CLASS(klass)	(G_TYPE_CHECK_CLASS_CAST ((klass), BACON_TYPE_RESIZE, BaconResizeClass))
+#define BACON_IS_RESIZE(obj)		(G_TYPE_CHECK_INSTANCE_TYPE ((obj), BACON_TYPE_RESIZE))
+#define BACON_IS_RESIZE_CLASS(klass)	(G_TYPE_CHECK_CLASS_TYPE ((klass), BACON_TYPE_RESIZE))
+
+typedef struct BaconResize		BaconResize;
+typedef struct BaconResizeClass		BaconResizeClass;
+typedef struct BaconResizePrivate	BaconResizePrivate;
+
+struct BaconResize {
+	GObject parent;
+	BaconResizePrivate *priv;
+};
+
+struct BaconResizeClass {
+	GObjectClass parent_class;
+};
+
+GType bacon_resize_get_type	(void);
+BaconResize *bacon_resize_new	(GtkWidget *video_widget);
+void bacon_resize_resize	(BaconResize *resize);
+void bacon_resize_restore	(BaconResize *resize);
+
+G_END_DECLS
+
+#endif /* BACON_RESIZE_H */

Modified: trunk/src/backend/bacon-video-widget-gst-0.10.c
==============================================================================
--- trunk/src/backend/bacon-video-widget-gst-0.10.c	(original)
+++ trunk/src/backend/bacon-video-widget-gst-0.10.c	Fri Jan 11 10:35:38 2008
@@ -163,7 +163,6 @@
   gboolean                     cursor_shown;
   gboolean                     fullscreen_mode;
   gboolean                     auto_resize;
-  gboolean                     have_xvidmode;
   gboolean                     uses_fakesink;
   
   gint                         video_width; /* Movie width */
@@ -203,6 +202,9 @@
   /* for easy codec installation */
   GList                       *missing_plugins;   /* GList of GstMessages */
   gboolean                     plugin_install_in_progress;
+
+  /* Bacon resize */
+  BaconResize                 *bacon_resize;
 };
 
 static void bacon_video_widget_set_property (GObject * object,
@@ -552,7 +554,7 @@
   } 
 #endif
 
-  bvw->priv->have_xvidmode = bacon_resize_init ();
+  bvw->priv->bacon_resize = bacon_resize_new (widget);
 }
 
 static void
@@ -565,6 +567,7 @@
   nvtv_simple_exit();
 #endif
 
+  g_object_unref (bvw->priv->bacon_resize);
   gdk_window_set_user_data (bvw->priv->video_window, NULL);
   gdk_window_destroy (bvw->priv->video_window);
   bvw->priv->video_window = NULL;
@@ -3193,10 +3196,16 @@
 bacon_video_widget_set_fullscreen (BaconVideoWidget * bvw,
                                    gboolean fullscreen)
 {
+  gboolean have_xvidmode;
+
   g_return_if_fail (bvw != NULL);
   g_return_if_fail (BACON_IS_VIDEO_WIDGET (bvw));
 
-  if (bvw->priv->have_xvidmode == FALSE &&
+  g_object_get (G_OBJECT (bvw->priv->bacon_resize),
+        "have-xvidmode", &have_xvidmode,
+        NULL);
+
+  if (have_xvidmode == FALSE &&
       bvw->priv->tv_out_type != TV_OUT_NVTV_NTSC &&
       bvw->priv->tv_out_type != TV_OUT_NVTV_PAL)
     return;
@@ -3213,7 +3222,7 @@
     /* Else if just auto resize is used */
     } else if (bvw->priv->auto_resize != FALSE) {
 #endif
-      bacon_restore (GTK_WIDGET (bvw));
+      bacon_resize_restore (bvw->priv->bacon_resize);
 #ifdef HAVE_NVTV
     }
   /* Turn fullscreen on with NVTV if that option is on */
@@ -3224,8 +3233,8 @@
                        bvw->priv->video_height);
 #endif
     /* Turn fullscreen on when we have xvidmode */
-  } else if (bvw->priv->have_xvidmode != FALSE) {
-    bacon_resize (GTK_WIDGET (bvw));
+  } else if (have_xvidmode != FALSE) {
+    bacon_resize_resize (bvw->priv->bacon_resize);
   }
 }
 

Modified: trunk/src/backend/bacon-video-widget-xine.c
==============================================================================
--- trunk/src/backend/bacon-video-widget-xine.c	(original)
+++ trunk/src/backend/bacon-video-widget-xine.c	Fri Jan 11 10:35:38 2008
@@ -193,6 +193,9 @@
 	/* fullscreen stuff */
 	int screenid;
 
+	/* Bacon resize */
+	BaconResize *bacon_resize;
+
 	guint ao_driver_none : 1;
 	guint show_vfx : 1;
 	guint using_vfx : 1;
@@ -200,7 +203,6 @@
 	guint can_dvd : 1;
 	guint can_vcd : 1;
 	guint can_dvb : 1;
-	guint have_xvidmode : 1;
 	guint auto_resize : 1;
 	guint is_live : 1;
 	guint got_redirect : 1;
@@ -1241,7 +1243,7 @@
 		bvw->priv->vis_name = NULL;
 	}
 
-	bvw->priv->have_xvidmode = bacon_resize_init ();
+	bvw->priv->bacon_resize = bacon_resize_new (widget);
 	bvw->priv->stream = xine_stream_new (bvw->priv->xine,
 			bvw->priv->ao_driver, bvw->priv->vo_driver);
 	setup_config_stream (bvw);
@@ -1657,6 +1659,8 @@
 			XINE_GUI_SEND_WILL_DESTROY_DRAWABLE,
 			(void*)widget->window);
 
+	g_object_unref (bvw->priv->bacon_resize);
+
 	/* Hide all windows */
 	if (GTK_WIDGET_MAPPED (widget))
 		gtk_widget_unmap (widget);
@@ -3024,10 +3028,16 @@
 void
 bacon_video_widget_set_fullscreen (BaconVideoWidget *bvw, gboolean fullscreen)
 {
+	gboolean have_xvidmode;
+
 	g_return_if_fail (bvw != NULL);
 	g_return_if_fail (BACON_IS_VIDEO_WIDGET (bvw));
 
-	if (bvw->priv->have_xvidmode == FALSE &&
+	g_object_get (G_OBJECT (bvw->priv->bacon_resize),
+				"have-xvidmode", &have_xvidmode,
+				NULL);
+
+	if (have_xvidmode == FALSE &&
 			bvw->priv->tvout != TV_OUT_NVTV_NTSC &&
 			bvw->priv->tvout != TV_OUT_NVTV_PAL)
 		return;
@@ -3044,7 +3054,7 @@
 			/* Else if just auto resize is used */
 		} else if (bvw->priv->auto_resize != FALSE) {
 #endif
-			bacon_restore (GTK_WIDGET (bvw));
+			bacon_resize_restore (bvw->priv->bacon_resize);
 #ifdef HAVE_NVTV
 		}
 		/* Turn fullscreen on with NVTV if that option is on */
@@ -3055,8 +3065,8 @@
 				bvw->priv->video_height);
 #endif
 		/* Turn fullscreen on when we have xvidmode */
-	} else if (bvw->priv->have_xvidmode != FALSE) {
-		bacon_resize (GTK_WIDGET (bvw));
+	} else if (have_xvidmode != FALSE) {
+		bacon_resize_resize (bvw->priv->bacon_resize);
 	}
 }
 



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