glcontext: pass display to implentation's _new()
authorMatthew Waters <matthew@centricular.com>
Fri, 24 Jul 2015 06:11:38 +0000 (16:11 +1000)
committerTim-Philipp Müller <tim@centricular.com>
Sat, 9 Dec 2017 19:32:06 +0000 (19:32 +0000)
This allows the context to fail creation based on incompatible
display type's. e.g. glx context with an wayland display handle.

https://bugzilla.gnome.org/show_bug.cgi?id=752743

gst-libs/gst/gl/cocoa/gstglcontext_cocoa.m
gst-libs/gst/gl/eagl/gstglcontext_eagl.h
gst-libs/gst/gl/eagl/gstglcontext_eagl.m
gst-libs/gst/gl/egl/gstglcontext_egl.c
gst-libs/gst/gl/egl/gstglcontext_egl.h
gst-libs/gst/gl/gstglcontext.c
gst-libs/gst/gl/win32/gstglcontext_wgl.c
gst-libs/gst/gl/x11/gstglcontext_glx.c
gst-libs/gst/gl/x11/gstglcontext_glx.h

index 769395a8600a5f086138d712091c0d64c752d721..bde90f1c6a56cd04a0df0be89d8552f4a45e1716 100644 (file)
@@ -72,11 +72,13 @@ gst_gl_context_cocoa_init (GstGLContextCocoa * context)
 
 /* Must be called in the gl thread */
 GstGLContextCocoa *
-gst_gl_context_cocoa_new (void)
+gst_gl_context_cocoa_new (GstGLDisplay * display)
 {
-  GstGLContextCocoa *context = g_object_new (GST_GL_TYPE_CONTEXT_COCOA, NULL);
+  if ((gst_gl_display_get_handle_type (display) & GST_GL_DISPLAY_TYPE_COCOA) == 0)
+    /* we require an cocoa display to create CGL contexts */
+    return NULL;
 
-  return context;
+  return g_object_new (GST_GL_TYPE_CONTEXT_COCOA, NULL);
 }
 
 struct pixel_attr
index c8997ff0e4d5d7496ff9c9d70e7ea25a2b0ff6bb..bd6cd207214d50cc4f2cea73bc91d3e8dca67f24 100644 (file)
@@ -57,7 +57,7 @@ struct _GstGLContextEaglClass {
 
 GType gst_gl_context_eagl_get_type (void);
 
-GstGLContextEagl * gst_gl_context_eagl_new (void);
+GstGLContextEagl * gst_gl_context_eagl_new (GstGLDisplay * display);
 
 void gst_gl_context_eagl_update_layer (GstGLContext * context);
 void gst_gl_context_eagl_resize (GstGLContextEagl * eagl_context);
index aaabfe256d45a051f096d5eff532c3bbb78167fd..dce81680cb78dbf1135d213a1b56e610f4cbeee6 100644 (file)
@@ -92,11 +92,10 @@ gst_gl_context_eagl_init (GstGLContextEagl * context)
 
 /* Must be called in the gl thread */
 GstGLContextEagl *
-gst_gl_context_eagl_new (void)
+gst_gl_context_eagl_new (GstGLDisplay * display)
 {
-  GstGLContextEagl *context = g_object_new (GST_GL_TYPE_CONTEXT_EAGL, NULL);
-
-  return context;
+  /* there isn't actually a display type for eagl yet? */
+  return g_object_new (GST_GL_TYPE_CONTEXT_EAGL, NULL);
 }
 
 void
index c466a0a68d6eb8997664e0bc37da25ed88db4698..3a4aa356b067ec5c958adc47bbce3c998b5ec928 100644 (file)
@@ -100,11 +100,11 @@ gst_gl_context_egl_init (GstGLContextEGL * context)
 
 /* Must be called in the gl thread */
 GstGLContextEGL *
-gst_gl_context_egl_new (void)
+gst_gl_context_egl_new (GstGLDisplay * display)
 {
-  GstGLContextEGL *window = g_object_new (GST_GL_TYPE_CONTEXT_EGL, NULL);
-
-  return window;
+  /* XXX: display type could theoretically be anything, as long as
+   * eglGetDisplay supports it. */
+  return g_object_new (GST_GL_TYPE_CONTEXT_EGL, NULL);
 }
 
 static const gchar *
index 5af9d606517e7543ec827d251f1f9720e22f5714..88b8bd7739fe3c03be7f8e9f933790c4fb7f8392 100644 (file)
@@ -30,6 +30,7 @@ G_BEGIN_DECLS
 typedef struct _GstGLContextEGL GstGLContextEGL;
 typedef struct _GstGLContextEGLClass GstGLContextEGLClass;
 
+GType gst_gl_context_egl_get_type     (void);
 #define GST_GL_TYPE_CONTEXT_EGL         (gst_gl_context_egl_get_type())
 #define GST_GL_CONTEXT_EGL(o)           (G_TYPE_CHECK_INSTANCE_CAST((o), GST_GL_TYPE_CONTEXT_EGL, GstGLContextEGL))
 #define GST_GL_CONTEXT_EGL_CLASS(k)     (G_TYPE_CHECK_CLASS((k), GST_GL_TYPE_CONTEXT_EGL, GstGLContextEGLClass))
@@ -59,8 +60,7 @@ struct _GstGLContextEGLClass {
   GstGLContextClass parent;
 };
 
-GType gst_gl_context_egl_get_type     (void);
-GstGLContextEGL *   gst_gl_context_egl_new                  (void);
+GstGLContextEGL *   gst_gl_context_egl_new                  (GstGLDisplay * display);
 guintptr            gst_gl_context_egl_get_current_context  (void);
 gpointer            gst_gl_context_egl_get_proc_address     (GstGLAPI gl_api, const gchar * name);
 
index 102abc274c863a1d5ae11128765ff0796259a0f9..9ec30ca430b3a973c4e33f39a83b743fd69f217e 100644 (file)
@@ -311,24 +311,24 @@ gst_gl_context_new (GstGLDisplay * display)
       ", user choice:%s", display, user_choice);
 #if GST_GL_HAVE_PLATFORM_CGL
   if (!context && (!user_choice || g_strstr_len (user_choice, 5, "cgl")))
-    context = GST_GL_CONTEXT (gst_gl_context_cocoa_new ());
+    context = GST_GL_CONTEXT (gst_gl_context_cocoa_new (display));
 #endif
 #if GST_GL_HAVE_PLATFORM_GLX
   if (!context && (!user_choice || g_strstr_len (user_choice, 3, "glx")))
-    context = GST_GL_CONTEXT (gst_gl_context_glx_new ());
+    context = GST_GL_CONTEXT (gst_gl_context_glx_new (display));
 #endif
 #if GST_GL_HAVE_PLATFORM_EGL
   if (!context && (!user_choice || g_strstr_len (user_choice, 7, "egl")))
-    context = GST_GL_CONTEXT (gst_gl_context_egl_new ());
+    context = GST_GL_CONTEXT (gst_gl_context_egl_new (display));
 #endif
 #if GST_GL_HAVE_PLATFORM_WGL
   if (!context && (!user_choice || g_strstr_len (user_choice, 3, "wgl"))) {
-    context = GST_GL_CONTEXT (gst_gl_context_wgl_new ());
+    context = GST_GL_CONTEXT (gst_gl_context_wgl_new (display));
   }
 #endif
 #if GST_GL_HAVE_PLATFORM_EAGL
   if (!context && (!user_choice || g_strstr_len (user_choice, 5, "eagl")))
-    context = GST_GL_CONTEXT (gst_gl_context_eagl_new ());
+    context = GST_GL_CONTEXT (gst_gl_context_eagl_new (display));
 #endif
 
   if (!context) {
index 9fd6e61a820728d4ec1429bb51e82e9cfcca9ce5..59b238c2cc2643cdb6fc6d3a54316cb96c0691e4 100644 (file)
@@ -80,9 +80,12 @@ gst_gl_context_wgl_init (GstGLContextWGL * context_wgl)
 GstGLContextWGL *
 gst_gl_context_wgl_new (void)
 {
-  GstGLContextWGL *context = g_object_new (GST_GL_TYPE_CONTEXT_WGL, NULL);
+  if ((gst_gl_display_get_handle_type (display) & GST_GL_DISPLAY_TYPE_WIN32) ==
+      0)
+    /* we require an win32 display handle to create WGL contexts */
+    return NULL;
 
-  return context;
+  return g_object_new (GST_GL_TYPE_CONTEXT_WGL, NULL);
 }
 
 static gboolean
index 645d5c7499b1746d4d7afe6f57655a58045e3ce0..0e4e67b83d3a33b60000b1842b63b5b7a88fd072 100644 (file)
@@ -37,7 +37,7 @@
 #include <gst/gl/gl.h>
 #include "gstglcontext_glx.h"
 
-#define GST_CAT_DEFAULT gst_gl_window_debug
+#define GST_CAT_DEFAULT gst_gl_context_debug
 
 #define gst_gl_context_glx_parent_class parent_class
 G_DEFINE_TYPE (GstGLContextGLX, gst_gl_context_glx, GST_GL_TYPE_CONTEXT);
@@ -105,11 +105,13 @@ gst_gl_context_glx_init (GstGLContextGLX * context)
 }
 
 GstGLContextGLX *
-gst_gl_context_glx_new (void)
+gst_gl_context_glx_new (GstGLDisplay * display)
 {
-  GstGLContextGLX *context = g_object_new (GST_GL_TYPE_CONTEXT_GLX, NULL);
+  if ((gst_gl_display_get_handle_type (display) & GST_GL_DISPLAY_TYPE_X11) == 0)
+    /* we require an x11 display handle to create GLX contexts */
+    return NULL;
 
-  return context;
+  return g_object_new (GST_GL_TYPE_CONTEXT_GLX, NULL);
 }
 
 static inline void
index cb133fa9d68961e032ee61b8eb29bfdd06d695d5..e015108f72987d53ec79c9c8574d446c873c3520 100644 (file)
@@ -59,7 +59,7 @@ struct _GstGLContextGLXClass {
 
 GType gst_gl_context_glx_get_type     (void);
 
-GstGLContextGLX *   gst_gl_context_glx_new                  (void);
+GstGLContextGLX *   gst_gl_context_glx_new                  (GstGLDisplay * display);
 guintptr            gst_gl_context_glx_get_current_context  (void);
 gpointer            gst_gl_context_glx_get_proc_address     (GstGLAPI gl_api, const gchar * name);