#include "gtkgstglwidget.h"
#include "gstgtkutils.h"
+#include <gst/gl/gstglfuncs.h>
#include <gst/video/video.h>
-#if GST_GL_HAVE_WINDOW_X11 && GST_GL_HAVE_PLATFORM_GLX && defined (GDK_WINDOWING_X11)
+#if GST_GL_HAVE_WINDOW_X11 && defined (GDK_WINDOWING_X11)
#include <gdk/gdkx.h>
#include <gst/gl/x11/gstgldisplay_x11.h>
-#include <gst/gl/x11/gstglcontext_glx.h>
#endif
-#if GST_GL_HAVE_WINDOW_WAYLAND && GST_GL_HAVE_PLATFORM_EGL && defined (GDK_WINDOWING_WAYLAND)
+#if GST_GL_HAVE_WINDOW_WAYLAND && defined (GDK_WINDOWING_WAYLAND)
#include <gdk/gdkwayland.h>
#include <gst/gl/wayland/gstgldisplay_wayland.h>
#endif
/**
* SECTION:gtkgstglwidget
+ * @title: GtkGstGlWidget
* @short_description: a #GtkGLArea that renders GStreamer video #GstBuffers
* @see_also: #GtkGLArea, #GstBuffer
*
#define GST_CAT_DEFAULT gtk_gst_gl_widget_debug
GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
-G_DEFINE_TYPE_WITH_CODE (GtkGstGLWidget, gtk_gst_gl_widget, GTK_TYPE_GL_AREA,
- GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "gtkgstglwidget", 0,
- "Gtk Gst GL Widget"););
-
-#define GTK_GST_GL_WIDGET_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), \
- GTK_TYPE_GST_GL_WIDGET, GtkGstGLWidgetPrivate))
-
struct _GtkGstGLWidgetPrivate
{
gboolean initted;
1.0f, -1.0f, 0.0f, 1.0f, 1.0f
};
+G_DEFINE_TYPE_WITH_CODE (GtkGstGLWidget, gtk_gst_gl_widget, GTK_TYPE_GL_AREA,
+ G_ADD_PRIVATE (GtkGstGLWidget)
+ GST_DEBUG_CATEGORY_INIT (GST_CAT_DEFAULT, "gtkgstglwidget", 0,
+ "Gtk Gst GL Widget");
+ );
+
static void
gtk_gst_gl_widget_bind_buffer (GtkGstGLWidget * gst_widget)
{
if (gl->BindVertexArray)
gl->BindVertexArray (priv->vao);
- else
- gtk_gst_gl_widget_bind_buffer (gst_widget);
+ gtk_gst_gl_widget_bind_buffer (gst_widget);
gl->ActiveTexture (GL_TEXTURE0);
gl->BindTexture (GL_TEXTURE_2D, tex);
sync_meta = gst_buffer_get_gl_sync_meta (buffer);
if (sync_meta) {
+ /* XXX: the set_sync() seems to be needed for resizing */
gst_gl_sync_meta_set_sync_point (sync_meta, priv->context);
gst_gl_sync_meta_wait (sync_meta, priv->other_context);
}
GObjectClass *gobject_klass = (GObjectClass *) klass;
GtkGLAreaClass *gl_widget_klass = (GtkGLAreaClass *) klass;
- g_type_class_add_private (klass, sizeof (GtkGstGLWidgetPrivate));
gtk_gst_base_widget_class_init (GTK_GST_BASE_WIDGET_CLASS (klass));
gobject_klass->finalize = gtk_gst_gl_widget_finalize;
gtk_gst_base_widget_init (base_widget);
- gst_widget->priv = priv = GTK_GST_GL_WIDGET_GET_PRIVATE (gst_widget);
+ gst_widget->priv = priv = gtk_gst_gl_widget_get_instance_private (gst_widget);
display = gdk_display_get_default ();
-#if GST_GL_HAVE_WINDOW_X11 && GST_GL_HAVE_PLATFORM_GLX && defined (GDK_WINDOWING_X11)
- if (GDK_IS_X11_DISPLAY (display))
+#if GST_GL_HAVE_WINDOW_X11 && defined (GDK_WINDOWING_X11)
+ if (GDK_IS_X11_DISPLAY (display)) {
priv->display = (GstGLDisplay *)
gst_gl_display_x11_new_with_display (gdk_x11_display_get_xdisplay
(display));
+ }
#endif
-#if GST_GL_HAVE_WINDOW_WAYLAND && GST_GL_HAVE_PLATFORM_EGL && defined (GDK_WINDOWING_WAYLAND)
+#if GST_GL_HAVE_WINDOW_WAYLAND && defined (GDK_WINDOWING_WAYLAND)
if (GDK_IS_WAYLAND_DISPLAY (display)) {
struct wl_display *wayland_display =
gdk_wayland_display_get_wl_display (display);
if (!priv->display)
priv->display = gst_gl_display_new ();
+ GST_INFO ("Created %" GST_PTR_FORMAT, priv->display);
+
gtk_gl_area_set_has_alpha (GTK_GL_AREA (gst_widget),
!base_widget->ignore_alpha);
}
_get_gl_context (GtkGstGLWidget * gst_widget)
{
GtkGstGLWidgetPrivate *priv = gst_widget->priv;
- GstGLPlatform platform;
- GstGLAPI gl_api;
- guintptr gl_handle;
+ GstGLPlatform platform = GST_GL_PLATFORM_NONE;
+ GstGLAPI gl_api = GST_GL_API_NONE;
+ guintptr gl_handle = 0;
gtk_widget_realize (GTK_WIDGET (gst_widget));
+ if (priv->other_context)
+ gst_object_unref (priv->other_context);
+ priv->other_context = NULL;
+
if (priv->gdk_context)
g_object_unref (priv->gdk_context);
+
priv->gdk_context = gtk_gl_area_get_context (GTK_GL_AREA (gst_widget));
if (priv->gdk_context == NULL) {
GError *error = gtk_gl_area_get_error (GTK_GL_AREA (gst_widget));
GST_ERROR_OBJECT (gst_widget, "Error creating GdkGLContext : %s",
error ? error->message : "No error set by Gdk");
g_clear_error (&error);
- g_assert_not_reached ();
return;
}
gdk_gl_context_make_current (priv->gdk_context);
-#if GST_GL_HAVE_WINDOW_X11 && GST_GL_HAVE_PLATFORM_GLX && defined (GDK_WINDOWING_X11)
+#if GST_GL_HAVE_WINDOW_X11 && defined (GDK_WINDOWING_X11)
if (GST_IS_GL_DISPLAY_X11 (priv->display)) {
- platform = GST_GL_PLATFORM_GLX;
- gl_api = gst_gl_context_get_current_gl_api (platform, NULL, NULL);
- gl_handle = gst_gl_context_get_current_gl_context (platform);
- if (gl_handle)
+#if GST_GL_HAVE_PLATFORM_GLX
+ if (!gl_handle) {
+ platform = GST_GL_PLATFORM_GLX;
+ gl_handle = gst_gl_context_get_current_gl_context (platform);
+ }
+#endif
+
+#if GST_GL_HAVE_PLATFORM_EGL
+ if (!gl_handle) {
+ platform = GST_GL_PLATFORM_EGL;
+ gl_handle = gst_gl_context_get_current_gl_context (platform);
+ }
+#endif
+
+ if (gl_handle) {
+ gl_api = gst_gl_context_get_current_gl_api (platform, NULL, NULL);
priv->other_context =
gst_gl_context_new_wrapped (priv->display, gl_handle,
platform, gl_api);
+ }
}
#endif
#if GST_GL_HAVE_WINDOW_WAYLAND && GST_GL_HAVE_PLATFORM_EGL && defined (GDK_WINDOWING_WAYLAND)
if (priv->other_context) {
GError *error = NULL;
+ GST_INFO ("Retrieved Gdk OpenGL context %" GST_PTR_FORMAT,
+ priv->other_context);
gst_gl_context_activate (priv->other_context, TRUE);
if (!gst_gl_context_fill_info (priv->other_context, &error)) {
GST_ERROR ("failed to retrieve gdk context info: %s", error->message);
} else {
gst_gl_context_activate (priv->other_context, FALSE);
}
+ } else {
+ GST_WARNING ("Could not retrieve Gdk OpenGL context");
}
}
GError *error = NULL;
g_return_val_if_fail (GTK_IS_GST_GL_WIDGET (gst_widget), FALSE);
+ g_return_val_if_fail (priv->display != NULL, FALSE);
GTK_GST_BASE_WIDGET_LOCK (gst_widget);
if (priv->display && priv->gdk_context && priv->other_context) {
+ GST_TRACE ("have already initialized contexts");
GTK_GST_BASE_WIDGET_UNLOCK (gst_widget);
return TRUE;
}
}
if (!GST_IS_GL_CONTEXT (priv->other_context)) {
+ GST_FIXME ("Could not retrieve Gdk OpenGL context");
GTK_GST_BASE_WIDGET_UNLOCK (gst_widget);
return FALSE;
}
+ GST_OBJECT_LOCK (priv->display);
if (!gst_gl_display_create_context (priv->display, priv->other_context,
&priv->context, &error)) {
+ GST_WARNING ("Could not create OpenGL context: %s",
+ error ? error->message : "Unknown");
g_clear_error (&error);
+ GST_OBJECT_UNLOCK (priv->display);
GTK_GST_BASE_WIDGET_UNLOCK (gst_widget);
return FALSE;
}
+ gst_gl_display_add_context (priv->display, priv->context);
+ GST_OBJECT_UNLOCK (priv->display);
GTK_GST_BASE_WIDGET_UNLOCK (gst_widget);
return TRUE;