From 9587eb477d9ba51a334ad157a097fec16b430072 Mon Sep 17 00:00:00 2001 From: Matthew Waters Date: Fri, 24 Jul 2015 16:11:38 +1000 Subject: [PATCH] glcontext: pass display to implentation's _new() 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 | 8 +++++--- gst-libs/gst/gl/eagl/gstglcontext_eagl.h | 2 +- gst-libs/gst/gl/eagl/gstglcontext_eagl.m | 7 +++---- gst-libs/gst/gl/egl/gstglcontext_egl.c | 8 ++++---- gst-libs/gst/gl/egl/gstglcontext_egl.h | 4 ++-- gst-libs/gst/gl/gstglcontext.c | 10 +++++----- gst-libs/gst/gl/win32/gstglcontext_wgl.c | 7 +++++-- gst-libs/gst/gl/x11/gstglcontext_glx.c | 10 ++++++---- gst-libs/gst/gl/x11/gstglcontext_glx.h | 2 +- 9 files changed, 32 insertions(+), 26 deletions(-) diff --git a/gst-libs/gst/gl/cocoa/gstglcontext_cocoa.m b/gst-libs/gst/gl/cocoa/gstglcontext_cocoa.m index 769395a860..bde90f1c6a 100644 --- a/gst-libs/gst/gl/cocoa/gstglcontext_cocoa.m +++ b/gst-libs/gst/gl/cocoa/gstglcontext_cocoa.m @@ -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 diff --git a/gst-libs/gst/gl/eagl/gstglcontext_eagl.h b/gst-libs/gst/gl/eagl/gstglcontext_eagl.h index c8997ff0e4..bd6cd20721 100644 --- a/gst-libs/gst/gl/eagl/gstglcontext_eagl.h +++ b/gst-libs/gst/gl/eagl/gstglcontext_eagl.h @@ -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); diff --git a/gst-libs/gst/gl/eagl/gstglcontext_eagl.m b/gst-libs/gst/gl/eagl/gstglcontext_eagl.m index aaabfe256d..dce81680cb 100644 --- a/gst-libs/gst/gl/eagl/gstglcontext_eagl.m +++ b/gst-libs/gst/gl/eagl/gstglcontext_eagl.m @@ -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 diff --git a/gst-libs/gst/gl/egl/gstglcontext_egl.c b/gst-libs/gst/gl/egl/gstglcontext_egl.c index c466a0a68d..3a4aa356b0 100644 --- a/gst-libs/gst/gl/egl/gstglcontext_egl.c +++ b/gst-libs/gst/gl/egl/gstglcontext_egl.c @@ -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 * diff --git a/gst-libs/gst/gl/egl/gstglcontext_egl.h b/gst-libs/gst/gl/egl/gstglcontext_egl.h index 5af9d60651..88b8bd7739 100644 --- a/gst-libs/gst/gl/egl/gstglcontext_egl.h +++ b/gst-libs/gst/gl/egl/gstglcontext_egl.h @@ -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); diff --git a/gst-libs/gst/gl/gstglcontext.c b/gst-libs/gst/gl/gstglcontext.c index 102abc274c..9ec30ca430 100644 --- a/gst-libs/gst/gl/gstglcontext.c +++ b/gst-libs/gst/gl/gstglcontext.c @@ -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) { diff --git a/gst-libs/gst/gl/win32/gstglcontext_wgl.c b/gst-libs/gst/gl/win32/gstglcontext_wgl.c index 9fd6e61a82..59b238c2cc 100644 --- a/gst-libs/gst/gl/win32/gstglcontext_wgl.c +++ b/gst-libs/gst/gl/win32/gstglcontext_wgl.c @@ -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 diff --git a/gst-libs/gst/gl/x11/gstglcontext_glx.c b/gst-libs/gst/gl/x11/gstglcontext_glx.c index 645d5c7499..0e4e67b83d 100644 --- a/gst-libs/gst/gl/x11/gstglcontext_glx.c +++ b/gst-libs/gst/gl/x11/gstglcontext_glx.c @@ -37,7 +37,7 @@ #include #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 diff --git a/gst-libs/gst/gl/x11/gstglcontext_glx.h b/gst-libs/gst/gl/x11/gstglcontext_glx.h index cb133fa9d6..e015108f72 100644 --- a/gst-libs/gst/gl/x11/gstglcontext_glx.h +++ b/gst-libs/gst/gl/x11/gstglcontext_glx.h @@ -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);