[669/906] window: seperate object creation and context creation

This commit is contained in:
Matthew Waters 2013-02-12 23:48:36 +11:00 committed by Tim-Philipp Müller
parent 63a5d9e981
commit 7d4d1f50d4
14 changed files with 163 additions and 178 deletions

View file

@ -58,9 +58,7 @@ struct _GstGLWindowCocoaClass {
GType gst_gl_window_cocoa_get_type (void); GType gst_gl_window_cocoa_get_type (void);
GstGLWindowCocoa * gst_gl_window_cocoa_new (GstGLAPI gl_api, GstGLWindowCocoa * gst_gl_window_cocoa_new (void);
guintptr external_gl_context,
GError ** error);
G_END_DECLS G_END_DECLS

View file

@ -111,6 +111,8 @@ GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
#define gst_gl_window_cocoa_parent_class parent_class #define gst_gl_window_cocoa_parent_class parent_class
G_DEFINE_TYPE_WITH_CODE (GstGLWindowCocoa, gst_gl_window_cocoa, GST_GL_TYPE_WINDOW, DEBUG_INIT); G_DEFINE_TYPE_WITH_CODE (GstGLWindowCocoa, gst_gl_window_cocoa, GST_GL_TYPE_WINDOW, DEBUG_INIT);
gboolean gst_gl_window_cocoa_create_context (GstGLWindow *window, GstGLAPI gl_api,
guintptr external_opengl_context, GError **error);
guintptr gst_gl_window_cocoa_get_gl_context (GstGLWindow * window); guintptr gst_gl_window_cocoa_get_gl_context (GstGLWindow * window);
gboolean gst_gl_window_cocoa_activate (GstGLWindow * window, gboolean activate); gboolean gst_gl_window_cocoa_activate (GstGLWindow * window, gboolean activate);
void gst_gl_window_cocoa_set_window_handle (GstGLWindow * window, void gst_gl_window_cocoa_set_window_handle (GstGLWindow * window,
@ -167,6 +169,8 @@ gst_gl_window_cocoa_class_init (GstGLWindowCocoaClass * klass)
g_type_class_add_private (klass, sizeof (GstGLWindowCocoaPrivate)); g_type_class_add_private (klass, sizeof (GstGLWindowCocoaPrivate));
window_class->create_context =
GST_DEBUG_FUNCPTR (gst_gl_window_cocoa_create_context);
window_class->get_gl_context = window_class->get_gl_context =
GST_DEBUG_FUNCPTR (gst_gl_window_cocoa_get_gl_context); GST_DEBUG_FUNCPTR (gst_gl_window_cocoa_get_gl_context);
window_class->activate = GST_DEBUG_FUNCPTR (gst_gl_window_cocoa_activate); window_class->activate = GST_DEBUG_FUNCPTR (gst_gl_window_cocoa_activate);
@ -193,14 +197,25 @@ static void
gst_gl_window_cocoa_init (GstGLWindowCocoa * window) gst_gl_window_cocoa_init (GstGLWindowCocoa * window)
{ {
window->priv = GST_GL_WINDOW_COCOA_GET_PRIVATE (window); window->priv = GST_GL_WINDOW_COCOA_GET_PRIVATE (window);
gst_gl_window_set_need_lock (GST_GL_WINDOW (window), FALSE);
} }
/* Must be called in the gl thread */ /* Must be called in the gl thread */
GstGLWindowCocoa * GstGLWindowCocoa *
gst_gl_window_cocoa_new (GstGLAPI gl_api, guintptr external_gl_context, GError ** error) gst_gl_window_cocoa_new (void)
{ {
GstGLWindowCocoa *window = g_object_new (GST_GL_TYPE_WINDOW_COCOA, NULL); GstGLWindowCocoa *window = g_object_new (GST_GL_TYPE_WINDOW_COCOA, NULL);
GstGLWindowCocoaPrivate *priv = window->priv;
return window;
}
gboolean
gst_gl_window_cocoa_create_context (GstGLWindow *window, GstGLAPI gl_api,
guintptr external_gl_context, GError **error)
{
GstGLWindowCocoa *window_cocoa = GST_GL_WINDOW_COCOA (window);
GstGLWindowCocoaPrivate *priv = window_cocoa->priv;
NSRect rect; NSRect rect;
NSAutoreleasePool *pool; NSAutoreleasePool *pool;
@ -212,8 +227,6 @@ gst_gl_window_cocoa_new (GstGLAPI gl_api, guintptr external_gl_context, GError *
priv->thread = nil; priv->thread = nil;
priv->running = TRUE; priv->running = TRUE;
gst_gl_window_set_need_lock (GST_GL_WINDOW (window), FALSE);
GSRegisterCurrentThread(); GSRegisterCurrentThread();
pool = [[NSAutoreleasePool alloc] init]; pool = [[NSAutoreleasePool alloc] init];
@ -230,7 +243,7 @@ gst_gl_window_cocoa_new (GstGLAPI gl_api, guintptr external_gl_context, GError *
priv->internal_win_id =[[GstGLNSWindow alloc] initWithContentRect:rect styleMask: priv->internal_win_id =[[GstGLNSWindow alloc] initWithContentRect:rect styleMask:
(NSTitledWindowMask | NSClosableWindowMask | (NSTitledWindowMask | NSClosableWindowMask |
NSResizableWindowMask | NSMiniaturizableWindowMask) NSResizableWindowMask | NSMiniaturizableWindowMask)
backing: NSBackingStoreBuffered defer: NO screen: nil gstWin: window]; backing: NSBackingStoreBuffered defer: NO screen: nil gstWin: window_cocoa];
GST_DEBUG ("NSWindow id: %lud\n", (gulong) priv->internal_win_id); GST_DEBUG ("NSWindow id: %lud\n", (gulong) priv->internal_win_id);
@ -244,7 +257,7 @@ gst_gl_window_cocoa_new (GstGLAPI gl_api, guintptr external_gl_context, GError *
priv->source_id = g_timeout_add_seconds (1, gst_gl_window_cocoa_nsapp_iteration, NULL); priv->source_id = g_timeout_add_seconds (1, gst_gl_window_cocoa_nsapp_iteration, NULL);
#endif #endif
return window; return TRUE;
} }
guintptr guintptr

View file

@ -221,6 +221,8 @@ gst_gl_display_init (GstGLDisplay * display)
display->gl_vtable = g_slice_alloc0 (sizeof (GstGLFuncs)); display->gl_vtable = g_slice_alloc0 (sizeof (GstGLFuncs));
display->gl_window = gst_gl_window_new ();
gst_gl_memory_init (); gst_gl_memory_init ();
} }
@ -237,15 +239,16 @@ gst_gl_display_finalize (GObject * object)
gst_gl_window_set_draw_callback (display->gl_window, NULL, NULL); gst_gl_window_set_draw_callback (display->gl_window, NULL, NULL);
gst_gl_window_set_close_callback (display->gl_window, NULL, NULL); gst_gl_window_set_close_callback (display->gl_window, NULL, NULL);
GST_INFO ("send quit gl window loop"); if (display->context_created) {
GST_INFO ("send quit gl window loop");
gst_gl_window_quit (display->gl_window,
GST_GL_WINDOW_CB (gst_gl_display_thread_destroy_context), display);
gst_gl_window_quit (display->gl_window, GST_INFO ("quit sent to gl window loop");
GST_GL_WINDOW_CB (gst_gl_display_thread_destroy_context), display);
GST_INFO ("quit sent to gl window loop"); g_cond_wait (display->priv->cond_destroy_context, display->mutex);
GST_INFO ("quit received from gl window");
g_cond_wait (display->priv->cond_destroy_context, display->mutex); }
GST_INFO ("quit received from gl window");
gst_gl_display_unlock (display); gst_gl_display_unlock (display);
} }
@ -438,19 +441,20 @@ gst_gl_display_thread_create_context (GstGLDisplay * display)
gst_gl_display_lock (display); gst_gl_display_lock (display);
gl = display->gl_vtable; gl = display->gl_vtable;
compiled_api = _compiled_api (); compiled_api = _compiled_api ();
display->gl_window = if (!display->gl_window) {
gst_gl_window_new (compiled_api, display->external_gl_context, &error); gst_gl_display_set_error (display, "Failed to create opengl window");
goto failure;
}
if (!display->gl_window || error) { if (!gst_gl_window_create_context (display->gl_window, compiled_api,
display->external_gl_context, &error)) {
gst_gl_display_set_error (display, gst_gl_display_set_error (display,
error ? error->message : "Failed to create gl window"); error ? error->message : "Failed to create gl window");
goto failure; goto failure;
} }
GST_INFO ("window created context");
GST_INFO ("gl window created");
display->gl_api = gst_gl_window_get_gl_api (display->gl_window); display->gl_api = gst_gl_window_get_gl_api (display->gl_window);
g_assert (display->gl_api != GST_GL_API_NONE g_assert (display->gl_api != GST_GL_API_NONE
@ -490,6 +494,7 @@ gst_gl_display_thread_create_context (GstGLDisplay * display)
ret = _create_context_gles2 (display, &gl_major, NULL); ret = _create_context_gles2 (display, &gl_major, NULL);
if (!ret || !gl_major) { if (!ret || !gl_major) {
GST_WARNING ("GL api specific initialization failed");
goto failure; goto failure;
} }
@ -1213,7 +1218,7 @@ gst_gl_display_create_context (GstGLDisplay * display,
gst_gl_display_lock (display); gst_gl_display_lock (display);
if (!display->gl_window) { if (!display->context_created) {
display->external_gl_context = external_gl_context; display->external_gl_context = external_gl_context;
display->gl_thread = g_thread_create ( display->gl_thread = g_thread_create (

View file

@ -144,6 +144,7 @@ struct _GstGLDisplay
GThread *gl_thread; GThread *gl_thread;
GstGLWindow *gl_window; GstGLWindow *gl_window;
gboolean isAlive; gboolean isAlive;
gboolean context_created;
/* gl API we are using */ /* gl API we are using */
GstGLAPI gl_api; GstGLAPI gl_api;

View file

@ -66,14 +66,12 @@ gst_gl_window_class_init (GstGLWindowClass * klass)
} }
GstGLWindow * GstGLWindow *
gst_gl_window_new (GstGLAPI api, guintptr external_gl_context, GError ** error) gst_gl_window_new (void)
{ {
GstGLWindow *window = NULL; GstGLWindow *window = NULL;
const gchar *user_choice; const gchar *user_choice;
static volatile gsize _init = 0; static volatile gsize _init = 0;
g_return_val_if_fail (error == NULL || *error == NULL, NULL);
if (g_once_init_enter (&_init)) { if (g_once_init_enter (&_init)) {
GST_DEBUG_CATEGORY_INIT (gst_gl_window_debug, "glwindow", 0, GST_DEBUG_CATEGORY_INIT (gst_gl_window_debug, "glwindow", 0,
"glwindow element"); "glwindow element");
@ -85,44 +83,29 @@ gst_gl_window_new (GstGLAPI api, guintptr external_gl_context, GError ** error)
#if GST_GL_HAVE_WINDOW_X11 #if GST_GL_HAVE_WINDOW_X11
if (!window && (!user_choice || g_strstr_len (user_choice, 3, "x11"))) if (!window && (!user_choice || g_strstr_len (user_choice, 3, "x11")))
window = window = GST_GL_WINDOW (gst_gl_window_x11_new ());
GST_GL_WINDOW (gst_gl_window_x11_new (api, external_gl_context, error));
#endif #endif
#if GST_GL_HAVE_WINDOW_WIN32 #if GST_GL_HAVE_WINDOW_WIN32
if (!window && (!user_choice || g_strstr_len (user_choice, 5, "win32"))) if (!window && (!user_choice || g_strstr_len (user_choice, 5, "win32")))
window = window = GST_GL_WINDOW (gst_gl_window_win32_new ());
GST_GL_WINDOW (gst_gl_window_win32_new (api, external_gl_context,
error));
#endif #endif
#if GST_GL_HAVE_WINDOW_COCOA #if GST_GL_HAVE_WINDOW_COCOA
if (!window && (!user_choice || g_strstr_len (user_choice, 5, "cocoa"))) if (!window && (!user_choice || g_strstr_len (user_choice, 5, "cocoa"))) {
window = window = GST_GL_WINDOW (gst_gl_window_cocoa_new ());
GST_GL_WINDOW (gst_gl_window_cocoa_new (api, external_gl_context, }
error));
#endif #endif
#if GST_GL_HAVE_WINDOW_WAYLAND #if GST_GL_HAVE_WINDOW_WAYLAND
if (!window && (!user_choice || g_strstr_len (user_choice, 7, "wayland"))) if (!window && (!user_choice || g_strstr_len (user_choice, 7, "wayland")))
window = window = GST_GL_WINDOW (gst_gl_window_wayland_egl_new ());
GST_GL_WINDOW (gst_gl_window_wayland_egl_new (api,
external_gl_context, error));
#endif #endif
if (!window) { if (!window) {
if (error && !*error) { /* subclass returned a NULL window */
if (user_choice) { GST_WARNING ("Could not create window. user specified %s",
g_set_error (error, GST_GL_WINDOW_ERROR, GST_GL_WINDOW_ERROR_FAILED, user_choice ? user_choice : "(null)");
"Could not create %s window", user_choice);
} else {
/* subclass did not set an error yet returned a NULL window */
g_set_error (error, GST_GL_WINDOW_ERROR, GST_GL_WINDOW_ERROR_FAILED,
"Could not create %s window, Unknown Error",
user_choice ? user_choice : "");
}
}
return NULL; return NULL;
} }
window->external_gl_context = external_gl_context;
return window; return window;
} }
@ -346,6 +329,28 @@ gst_gl_window_get_proc_address (GstGLWindow * window, const gchar * name)
return ret; return ret;
} }
gboolean
gst_gl_window_create_context (GstGLWindow * window, GstGLAPI gl_api,
guintptr external_gl_context, GError ** error)
{
gboolean ret;
GstGLWindowClass *window_class;
g_return_val_if_fail (GST_GL_IS_WINDOW (window), FALSE);
window_class = GST_GL_WINDOW_GET_CLASS (window);
g_return_val_if_fail (window_class->create_context != NULL, FALSE);
GST_GL_WINDOW_LOCK (window);
ret =
window_class->create_context (window, gl_api, external_gl_context, error);
GST_GL_WINDOW_UNLOCK (window);
return ret;
}
gpointer gpointer
gst_gl_window_default_get_proc_address (GstGLWindow * window, gst_gl_window_default_get_proc_address (GstGLWindow * window,
const gchar * name) const gchar * name)

View file

@ -101,6 +101,8 @@ struct _GstGLWindowClass {
gpointer (*get_proc_address) (GstGLWindow *window, const gchar *name); gpointer (*get_proc_address) (GstGLWindow *window, const gchar *name);
gboolean (*activate) (GstGLWindow *window, gboolean activate); gboolean (*activate) (GstGLWindow *window, gboolean activate);
void (*set_window_handle) (GstGLWindow *window, guintptr id); void (*set_window_handle) (GstGLWindow *window, guintptr id);
gboolean (*create_context) (GstGLWindow *window, GstGLAPI gl_api,
guintptr external_gl_context, GError ** error);
gboolean (*share_context) (GstGLWindow *window, guintptr external_gl_context); gboolean (*share_context) (GstGLWindow *window, guintptr external_gl_context);
void (*draw_unlocked) (GstGLWindow *window, guint width, guint height); void (*draw_unlocked) (GstGLWindow *window, guint width, guint height);
void (*draw) (GstGLWindow *window, guint width, guint height); void (*draw) (GstGLWindow *window, guint width, guint height);
@ -117,7 +119,7 @@ struct _GstGLWindowClass {
GQuark gst_gl_window_error_quark (void); GQuark gst_gl_window_error_quark (void);
GType gst_gl_window_get_type (void); GType gst_gl_window_get_type (void);
GstGLWindow * gst_gl_window_new (GstGLAPI gl_api, guintptr external_gl_context, GError ** error); GstGLWindow * gst_gl_window_new (void);
void gst_gl_window_set_draw_callback (GstGLWindow *window, GstGLWindowCB callback, gpointer data); void gst_gl_window_set_draw_callback (GstGLWindow *window, GstGLWindowCB callback, gpointer data);
void gst_gl_window_set_resize_callback (GstGLWindow *window, GstGLWindowResizeCB callback, gpointer data); void gst_gl_window_set_resize_callback (GstGLWindow *window, GstGLWindowResizeCB callback, gpointer data);
@ -138,6 +140,9 @@ gpointer gst_gl_window_get_proc_address (GstGLWindow *window, const gchar *
GstGLPlatform gst_gl_window_get_platform (GstGLWindow *window); GstGLPlatform gst_gl_window_get_platform (GstGLWindow *window);
GstGLAPI gst_gl_window_get_gl_api (GstGLWindow *window); GstGLAPI gst_gl_window_get_gl_api (GstGLWindow *window);
gboolean gst_gl_window_create_context (GstGLWindow *window, GstGLAPI gl_api,
guintptr external_gl_context, GError ** error);
gpointer gst_gl_window_default_get_proc_address (GstGLWindow *window, const gchar *name); gpointer gst_gl_window_default_get_proc_address (GstGLWindow *window, const gchar *name);
GST_DEBUG_CATEGORY_EXTERN (gst_gl_window_debug); GST_DEBUG_CATEGORY_EXTERN (gst_gl_window_debug);

View file

@ -51,9 +51,8 @@ static void gst_gl_window_wayland_egl_send_message (GstGLWindow * window,
GstGLWindowCB callback, gpointer data); GstGLWindowCB callback, gpointer data);
static void gst_gl_window_wayland_egl_destroy_context (GstGLWindowWaylandEGL * static void gst_gl_window_wayland_egl_destroy_context (GstGLWindowWaylandEGL *
window_egl); window_egl);
static gboolean gst_gl_window_wayland_egl_create_context (GstGLWindowWaylandEGL static gboolean gst_gl_window_wayland_egl_create_context (GstGLWindow
* window_egl, GstGLAPI gl_api, guintptr external_gl_context, * window, GstGLAPI gl_api, guintptr external_gl_context, GError ** error);
GError ** error);
static GstGLAPI gst_gl_window_wayland_egl_get_gl_api (GstGLWindow * window); static GstGLAPI gst_gl_window_wayland_egl_get_gl_api (GstGLWindow * window);
static gpointer gst_gl_window_wayland_egl_get_proc_address (GstGLWindow * static gpointer gst_gl_window_wayland_egl_get_proc_address (GstGLWindow *
window, const gchar * name); window, const gchar * name);
@ -260,6 +259,8 @@ gst_gl_window_wayland_egl_class_init (GstGLWindowWaylandEGLClass * klass)
GObjectClass *object_class = (GObjectClass *) klass; GObjectClass *object_class = (GObjectClass *) klass;
GstGLWindowClass *window_class = (GstGLWindowClass *) klass; GstGLWindowClass *window_class = (GstGLWindowClass *) klass;
window_class->create_context =
GST_DEBUG_FUNCPTR (gst_gl_window_wayland_egl_create_context);
window_class->get_gl_context = window_class->get_gl_context =
GST_DEBUG_FUNCPTR (gst_gl_window_wayland_egl_get_gl_context); GST_DEBUG_FUNCPTR (gst_gl_window_wayland_egl_get_gl_context);
window_class->activate = window_class->activate =
@ -288,8 +289,7 @@ gst_gl_window_wayland_egl_init (GstGLWindowWaylandEGL * window)
/* Must be called in the gl thread */ /* Must be called in the gl thread */
GstGLWindowWaylandEGL * GstGLWindowWaylandEGL *
gst_gl_window_wayland_egl_new (GstGLAPI gl_api, guintptr external_gl_context, gst_gl_window_wayland_egl_new (void)
GError ** error)
{ {
GstGLWindowWaylandEGL *window; GstGLWindowWaylandEGL *window;
@ -299,42 +299,7 @@ gst_gl_window_wayland_egl_new (GstGLAPI gl_api, guintptr external_gl_context,
gst_gl_window_set_need_lock (GST_GL_WINDOW (window), FALSE); gst_gl_window_set_need_lock (GST_GL_WINDOW (window), FALSE);
window->display.display = wl_display_connect (NULL);
if (!window->display.display) {
g_set_error (error, GST_GL_WINDOW_ERROR,
GST_GL_WINDOW_ERROR_RESOURCE_UNAVAILABLE,
"Failed to connect to Wayland display server");
goto error;
}
window->display.registry = wl_display_get_registry (window->display.display);
wl_registry_add_listener (window->display.registry, &registry_listener,
&window->display);
wl_display_dispatch (window->display.display);
create_surface (window);
window->display.cursor_surface =
wl_compositor_create_surface (window->display.compositor);
window->wl_source = wayland_event_source_new (window->display.display);
window->main_context = g_main_context_new ();
window->loop = g_main_loop_new (window->main_context, FALSE);
g_source_attach (window->wl_source, window->main_context);
gst_gl_window_wayland_egl_create_context (window, gl_api,
external_gl_context, error);
return window; return window;
error:
{
if (window)
g_object_unref (window);
return NULL;
}
} }
static void static void
@ -367,9 +332,47 @@ gst_gl_window_wayland_egl_finalize (GObject * object)
} }
static gboolean static gboolean
gst_gl_window_wayland_egl_create_context (GstGLWindowWaylandEGL * window_egl, _setup_wayland (GstGLWindowWaylandEGL * window_egl, GError ** error)
{
window_egl->display.display = wl_display_connect (NULL);
if (!window_egl->display.display) {
g_set_error (error, GST_GL_WINDOW_ERROR,
GST_GL_WINDOW_ERROR_RESOURCE_UNAVAILABLE,
"Failed to connect to Wayland display server");
goto error;
}
window_egl->display.registry =
wl_display_get_registry (window_egl->display.display);
wl_registry_add_listener (window_egl->display.registry, &registry_listener,
&window_egl->display);
wl_display_dispatch (window_egl->display.display);
create_surface (window_egl);
window_egl->display.cursor_surface =
wl_compositor_create_surface (window_egl->display.compositor);
window_egl->wl_source =
wayland_event_source_new (window_egl->display.display);
window_egl->main_context = g_main_context_new ();
window_egl->loop = g_main_loop_new (window_egl->main_context, FALSE);
g_source_attach (window_egl->wl_source, window_egl->main_context);
return TRUE;
error:
return FALSE;
}
gboolean
gst_gl_window_wayland_egl_create_context (GstGLWindow * window,
GstGLAPI gl_api, guintptr external_gl_context, GError ** error) GstGLAPI gl_api, guintptr external_gl_context, GError ** error)
{ {
GstGLWindowWaylandEGL *window_egl = GST_GL_WINDOW_WAYLAND_EGL (window);
EGLint config_attrib[] = { EGLint config_attrib[] = {
EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_RED_SIZE, 1, EGL_RED_SIZE, 1,
@ -390,6 +393,9 @@ gst_gl_window_wayland_egl_create_context (GstGLWindowWaylandEGL * window_egl,
EGLint minorVersion; EGLint minorVersion;
EGLint numConfigs; EGLint numConfigs;
if (!_setup_wayland (window_egl, error))
return FALSE;
window_egl->egl_display = window_egl->egl_display =
eglGetDisplay ((EGLNativeDisplayType) window_egl->display.display); eglGetDisplay ((EGLNativeDisplayType) window_egl->display.display);

View file

@ -99,9 +99,7 @@ struct _GstGLWindowWaylandEGLClass {
GType gst_gl_window_wayland_egl_get_type (void); GType gst_gl_window_wayland_egl_get_type (void);
GstGLWindowWaylandEGL * gst_gl_window_wayland_egl_new (GstGLAPI gl_api, GstGLWindowWaylandEGL * gst_gl_window_wayland_egl_new (void);
guintptr external_gl_context,
GError ** error);
G_END_DECLS G_END_DECLS

View file

@ -43,7 +43,7 @@
#define GST_CAT_DEFAULT gst_gl_window_debug #define GST_CAT_DEFAULT gst_gl_window_debug
#define gst_gl_window_x11_parent_class parent_class #define gst_gl_window_x11_parent_class parent_class
G_DEFINE_TYPE (GstGLWindowX11, gst_gl_window_x11, GST_GL_TYPE_WINDOW); G_DEFINE_ABSTRACT_TYPE (GstGLWindowX11, gst_gl_window_x11, GST_GL_TYPE_WINDOW);
enum enum
{ {
@ -69,6 +69,8 @@ void gst_gl_window_x11_quit (GstGLWindow * window, GstGLWindowCB callback,
gpointer data); gpointer data);
void gst_gl_window_x11_send_message (GstGLWindow * window, void gst_gl_window_x11_send_message (GstGLWindow * window,
GstGLWindowCB callback, gpointer data); GstGLWindowCB callback, gpointer data);
gboolean gst_gl_window_x11_create_context (GstGLWindow * window,
GstGLAPI gl_api, guintptr external_gl_context, GError ** error);
static gboolean gst_gl_window_x11_create_window (GstGLWindowX11 * window_x11); static gboolean gst_gl_window_x11_create_window (GstGLWindowX11 * window_x11);
@ -187,6 +189,8 @@ gst_gl_window_x11_class_init (GstGLWindowX11Class * klass)
g_param_spec_string ("display", "Display", "X Display name", NULL, g_param_spec_string ("display", "Display", "X Display name", NULL,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
window_class->create_context =
GST_DEBUG_FUNCPTR (gst_gl_window_x11_create_context);
window_class->get_gl_context = window_class->get_gl_context =
GST_DEBUG_FUNCPTR (gst_gl_window_x11_get_gl_context); GST_DEBUG_FUNCPTR (gst_gl_window_x11_get_gl_context);
window_class->activate = GST_DEBUG_FUNCPTR (gst_gl_window_x11_activate); window_class->activate = GST_DEBUG_FUNCPTR (gst_gl_window_x11_activate);
@ -209,51 +213,23 @@ gst_gl_window_x11_init (GstGLWindowX11 * window)
/* Must be called in the gl thread */ /* Must be called in the gl thread */
GstGLWindowX11 * GstGLWindowX11 *
gst_gl_window_x11_new (GstGLAPI gl_api, guintptr external_gl_context, gst_gl_window_x11_new (void)
GError ** error)
{ {
GstGLWindowX11 *window = NULL; GstGLWindowX11 *window = NULL;
const gchar *user_choice; const gchar *user_choice;
user_choice = g_getenv ("GST_GL_PLATFORM"); user_choice = g_getenv ("GST_GL_PLATFORM");
GST_INFO ("Attempting to create x11 window, user platform choice:%s",
user_choice ? user_choice : "(null)");
#if GST_GL_HAVE_PLATFORM_GLX #if GST_GL_HAVE_PLATFORM_GLX
#if GST_GL_HAVE_PLATFORM_EGL
/* try GLX first for Desktop OpenGL */
if (gl_api & GST_GL_API_OPENGL || gl_api & GST_GL_API_OPENGL3) {
if (!window && (!user_choice
|| g_strstr_len (user_choice, 3, "glx") != NULL))
window =
GST_GL_WINDOW_X11 (gst_gl_window_x11_glx_new (gl_api,
external_gl_context, error));
if (!window && (!user_choice
|| g_strstr_len (user_choice, 3, "egl") != NULL))
window =
GST_GL_WINDOW_X11 (gst_gl_window_x11_egl_new (gl_api,
external_gl_context, error));
} else { /* try EGL first for OpenGL|ES */
if (!window && (!user_choice
|| g_strstr_len (user_choice, 3, "egl") != NULL))
window =
GST_GL_WINDOW_X11 (gst_gl_window_x11_egl_new (gl_api,
external_gl_context, error));
if (!window && (!user_choice
|| g_strstr_len (user_choice, 3, "glx") != NULL))
window =
GST_GL_WINDOW_X11 (gst_gl_window_x11_glx_new (gl_api,
external_gl_context, error));
}
#endif /* GST_GL_HAVE_PLATFORM_EGL */
if (!window && (!user_choice || g_strstr_len (user_choice, 3, "glx") != NULL)) if (!window && (!user_choice || g_strstr_len (user_choice, 3, "glx") != NULL))
window = window = GST_GL_WINDOW_X11 (gst_gl_window_x11_glx_new ());
GST_GL_WINDOW_X11 (gst_gl_window_x11_glx_new (gl_api,
external_gl_context, error));
#endif /* GST_GL_HAVE_PLATFORM_GLX */ #endif /* GST_GL_HAVE_PLATFORM_GLX */
#ifdef GST_GL_HAVE_PLATFORM_EGL #ifdef GST_GL_HAVE_PLATFORM_EGL
if (!window && (!user_choice || g_strstr_len (user_choice, 3, "egl") != NULL)) if (!window && (!user_choice || g_strstr_len (user_choice, 3, "egl") != NULL))
window = window = GST_GL_WINDOW_X11 (gst_gl_window_x11_egl_new ());
GST_GL_WINDOW_X11 (gst_gl_window_x11_egl_new (gl_api,
external_gl_context, error));
#endif /* GST_GL_HAVE_PLATFORM_EGL */ #endif /* GST_GL_HAVE_PLATFORM_EGL */
if (!window) { if (!window) {
GST_WARNING ("Failed to create x11 window, user_choice:%s", GST_WARNING ("Failed to create x11 window, user_choice:%s",
@ -265,17 +241,16 @@ gst_gl_window_x11_new (GstGLAPI gl_api, guintptr external_gl_context,
} }
gboolean gboolean
gst_gl_window_x11_open_device (GstGLWindowX11 * window_x11, gst_gl_window_x11_create_context (GstGLWindow * window,
GstGLAPI gl_api, guintptr external_gl_context, GError ** error) GstGLAPI gl_api, guintptr external_gl_context, GError ** error)
{ {
GstGLWindowX11 *window_x11 = GST_GL_WINDOW_X11 (window);
GstGLWindowX11Class *window_class = GST_GL_WINDOW_X11_GET_CLASS (window_x11); GstGLWindowX11Class *window_class = GST_GL_WINDOW_X11_GET_CLASS (window_x11);
setlocale (LC_NUMERIC, "C"); setlocale (LC_NUMERIC, "C");
gst_gl_window_set_need_lock (GST_GL_WINDOW (window_x11), TRUE); gst_gl_window_set_need_lock (GST_GL_WINDOW (window_x11), TRUE);
GST_GL_WINDOW_LOCK (window_x11);
g_cond_init (&window_x11->cond_send_message); g_cond_init (&window_x11->cond_send_message);
window_x11->running = TRUE; window_x11->running = TRUE;
window_x11->visible = FALSE; window_x11->visible = FALSE;
@ -335,12 +310,9 @@ gst_gl_window_x11_open_device (GstGLWindowX11 * window_x11,
goto failure; goto failure;
} }
GST_GL_WINDOW_UNLOCK (window_x11);
return TRUE; return TRUE;
failure: failure:
GST_GL_WINDOW_UNLOCK (window_x11);
return FALSE; return FALSE;
} }
@ -635,13 +607,13 @@ gst_gl_window_x11_run (GstGLWindow * window)
if (window_x11->running) { if (window_x11->running) {
#if SIZEOF_VOID_P == 8 #if SIZEOF_VOID_P == 8
GstGLWindowCB custom_cb = GstGLWindowCB custom_cb =
(GstGLWindowCB) (((event.xclient. (GstGLWindowCB) (((event.xclient.data.
data.l[0] & 0xffffffff) << 32) | (event.xclient. l[0] & 0xffffffff) << 32) | (event.xclient.data.
data.l[1] & 0xffffffff)); l[1] & 0xffffffff));
gpointer custom_data = gpointer custom_data =
(gpointer) (((event.xclient. (gpointer) (((event.xclient.data.
data.l[2] & 0xffffffff) << 32) | (event.xclient. l[2] & 0xffffffff) << 32) | (event.xclient.data.
data.l[3] & 0xffffffff)); l[3] & 0xffffffff));
#else #else
GstGLWindowCB custom_cb = (GstGLWindowCB) event.xclient.data.l[0]; GstGLWindowCB custom_cb = (GstGLWindowCB) event.xclient.data.l[0];
gpointer custom_data = (gpointer) event.xclient.data.l[1]; gpointer custom_data = (gpointer) event.xclient.data.l[1];
@ -670,13 +642,13 @@ gst_gl_window_x11_run (GstGLWindow * window)
&& event.xclient.message_type == wm_quit_loop) { && event.xclient.message_type == wm_quit_loop) {
#if SIZEOF_VOID_P == 8 #if SIZEOF_VOID_P == 8
GstGLWindowCB destroy_cb = GstGLWindowCB destroy_cb =
(GstGLWindowCB) (((event.xclient. (GstGLWindowCB) (((event.xclient.data.
data.l[0] & 0xffffffff) << 32) | (event.xclient. l[0] & 0xffffffff) << 32) | (event.xclient.data.
data.l[1] & 0xffffffff)); l[1] & 0xffffffff));
gpointer destroy_data = gpointer destroy_data =
(gpointer) (((event.xclient. (gpointer) (((event.xclient.data.
data.l[2] & 0xffffffff) << 32) | (event.xclient. l[2] & 0xffffffff) << 32) | (event.xclient.data.
data.l[3] & 0xffffffff)); l[3] & 0xffffffff));
#else #else
GstGLWindowCB destroy_cb = (GstGLWindowCB) event.xclient.data.l[0]; GstGLWindowCB destroy_cb = (GstGLWindowCB) event.xclient.data.l[0];
gpointer destroy_data = (gpointer) event.xclient.data.l[1]; gpointer destroy_data = (gpointer) event.xclient.data.l[1];
@ -694,13 +666,13 @@ gst_gl_window_x11_run (GstGLWindow * window)
&pending_event)) { &pending_event)) {
#if SIZEOF_VOID_P == 8 #if SIZEOF_VOID_P == 8
GstGLWindowCB custom_cb = GstGLWindowCB custom_cb =
(GstGLWindowCB) (((event.xclient. (GstGLWindowCB) (((event.xclient.data.
data.l[0] & 0xffffffff) << 32) | (event.xclient. l[0] & 0xffffffff) << 32) | (event.xclient.data.
data.l[1] & 0xffffffff)); l[1] & 0xffffffff));
gpointer custom_data = gpointer custom_data =
(gpointer) (((event.xclient. (gpointer) (((event.xclient.data.
data.l[2] & 0xffffffff) << 32) | (event.xclient. l[2] & 0xffffffff) << 32) | (event.xclient.data.
data.l[3] & 0xffffffff)); l[3] & 0xffffffff));
#else #else
GstGLWindowCB custom_cb = (GstGLWindowCB) event.xclient.data.l[0]; GstGLWindowCB custom_cb = (GstGLWindowCB) event.xclient.data.l[0];
gpointer custom_data = (gpointer) event.xclient.data.l[1]; gpointer custom_data = (gpointer) event.xclient.data.l[1];

View file

@ -95,13 +95,7 @@ struct _GstGLWindowX11Class {
GType gst_gl_window_x11_get_type (void); GType gst_gl_window_x11_get_type (void);
GstGLWindowX11 * gst_gl_window_x11_new (GstGLAPI gl_api, GstGLWindowX11 * gst_gl_window_x11_new (void);
guintptr external_gl_context,
GError ** error);
gboolean gst_gl_window_x11_open_device (GstGLWindowX11 *window_x11,
GstGLAPI gl_api,
guintptr external_gl_context,
GError ** error);
G_END_DECLS G_END_DECLS

View file

@ -81,14 +81,10 @@ gst_gl_window_x11_egl_init (GstGLWindowX11EGL * window)
/* Must be called in the gl thread */ /* Must be called in the gl thread */
GstGLWindowX11EGL * GstGLWindowX11EGL *
gst_gl_window_x11_egl_new (GstGLAPI gl_api, guintptr external_gl_context, gst_gl_window_x11_egl_new (void)
GError ** error)
{ {
GstGLWindowX11EGL *window = g_object_new (GST_GL_TYPE_WINDOW_X11_EGL, NULL); GstGLWindowX11EGL *window = g_object_new (GST_GL_TYPE_WINDOW_X11_EGL, NULL);
gst_gl_window_x11_open_device (GST_GL_WINDOW_X11 (window), gl_api,
external_gl_context, error);
return window; return window;
} }

View file

@ -61,9 +61,7 @@ struct _GstGLWindowX11EGLClass {
GType gst_gl_window_x11_egl_get_type (void); GType gst_gl_window_x11_egl_get_type (void);
GstGLWindowX11EGL * gst_gl_window_x11_egl_new (GstGLAPI gl_api, GstGLWindowX11EGL * gst_gl_window_x11_egl_new (void);
guintptr external_gl_context,
GError ** error);
G_END_DECLS G_END_DECLS

View file

@ -81,14 +81,10 @@ gst_gl_window_x11_glx_init (GstGLWindowX11GLX * window)
/* Must be called in the gl thread */ /* Must be called in the gl thread */
GstGLWindowX11GLX * GstGLWindowX11GLX *
gst_gl_window_x11_glx_new (GstGLAPI gl_api, guintptr external_gl_context, gst_gl_window_x11_glx_new (void)
GError ** error)
{ {
GstGLWindowX11GLX *window = g_object_new (GST_GL_TYPE_WINDOW_X11_GLX, NULL); GstGLWindowX11GLX *window = g_object_new (GST_GL_TYPE_WINDOW_X11_GLX, NULL);
gst_gl_window_x11_open_device (GST_GL_WINDOW_X11 (window), gl_api,
external_gl_context, error);
return window; return window;
} }

View file

@ -56,9 +56,7 @@ struct _GstGLWindowX11GLXClass {
GType gst_gl_window_x11_glx_get_type (void); GType gst_gl_window_x11_glx_get_type (void);
GstGLWindowX11GLX * gst_gl_window_x11_glx_new (GstGLAPI gl_api, GstGLWindowX11GLX * gst_gl_window_x11_glx_new (void);
guintptr external_gl_context,
GError ** error);
G_END_DECLS G_END_DECLS