2013-08-14 00:44:19 +00:00
|
|
|
/*
|
|
|
|
* GStreamer
|
|
|
|
* Copyright (C) 2013 Matthew Waters <ystreet00@gmail.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
2013-11-23 11:53:48 +00:00
|
|
|
/**
|
|
|
|
* SECTION:gstglcontext
|
|
|
|
* @short_description: OpenGL context abstraction
|
|
|
|
* @title: GstGLContext
|
|
|
|
* @see_also: #GstGLDisplay, #GstGLWindow
|
|
|
|
*
|
|
|
|
* #GstGLContext wraps an OpenGL context object in a uniform API. As a result
|
|
|
|
* of the limitation on OpenGL context, this object is not thread safe unless
|
|
|
|
* specified and must only be activated in a single thread.
|
|
|
|
*/
|
|
|
|
|
2013-08-14 00:44:19 +00:00
|
|
|
#if HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2013-10-01 13:47:54 +00:00
|
|
|
#if defined(ANDROID) || defined(__ANDROID__)
|
|
|
|
/* Avoid a linker error with _isoc99_sscanf() when building a shared library
|
|
|
|
* for android
|
|
|
|
*/
|
|
|
|
#define _GNU_SOURCE
|
|
|
|
#endif
|
|
|
|
|
2014-03-16 14:34:11 +00:00
|
|
|
#ifndef GL_NUM_EXTENSIONS
|
|
|
|
#define GL_NUM_EXTENSIONS 0x0000821d
|
|
|
|
#endif
|
|
|
|
|
2013-08-14 00:44:19 +00:00
|
|
|
#include <gmodule.h>
|
|
|
|
|
|
|
|
#include "gl.h"
|
|
|
|
#include "gstglcontext.h"
|
|
|
|
|
2013-08-15 07:09:04 +00:00
|
|
|
#if GST_GL_HAVE_PLATFORM_GLX
|
|
|
|
#include "x11/gstglcontext_glx.h"
|
|
|
|
#endif
|
|
|
|
#if GST_GL_HAVE_PLATFORM_EGL
|
2013-08-21 04:05:56 +00:00
|
|
|
#include "egl/gstglcontext_egl.h"
|
2013-08-15 07:09:04 +00:00
|
|
|
#endif
|
2014-05-27 07:46:16 +00:00
|
|
|
#if GST_GL_HAVE_PLATFORM_CGL
|
2013-08-15 07:09:04 +00:00
|
|
|
#include "cocoa/gstglcontext_cocoa.h"
|
|
|
|
#endif
|
|
|
|
#if GST_GL_HAVE_PLATFORM_WGL
|
|
|
|
#include "win32/gstglcontext_wgl.h"
|
|
|
|
#endif
|
2014-04-12 19:43:50 +00:00
|
|
|
#if GST_GL_HAVE_PLATFORM_EAGL
|
|
|
|
#include "eagl/gstglcontext_eagl.h"
|
|
|
|
#endif
|
2013-08-15 07:09:04 +00:00
|
|
|
|
2014-05-01 12:36:54 +00:00
|
|
|
static GModule *module_self;
|
|
|
|
|
|
|
|
#if GST_GL_HAVE_OPENGL
|
|
|
|
static GOnce module_opengl_gonce = G_ONCE_INIT;
|
|
|
|
static GModule *module_opengl;
|
|
|
|
|
|
|
|
static gpointer
|
|
|
|
load_opengl_module (gpointer user_data)
|
|
|
|
{
|
|
|
|
#ifdef GST_GL_LIBGL_MODULE_NAME
|
|
|
|
module_opengl = g_module_open (GST_GL_LIBGL_MODULE_NAME, G_MODULE_BIND_LAZY);
|
|
|
|
#else
|
|
|
|
/* This automatically handles the suffix and even .la files */
|
|
|
|
module_opengl = g_module_open ("libGL", G_MODULE_BIND_LAZY);
|
|
|
|
|
|
|
|
/* On Linux the .so is only in -dev packages, try with a real soname
|
|
|
|
* Proper compilers will optimize away the strcmp */
|
|
|
|
if (!module_opengl && strcmp (G_MODULE_SUFFIX, "so") == 0)
|
|
|
|
module_opengl = g_module_open ("libGL.so.1", G_MODULE_BIND_LAZY);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if GST_GL_HAVE_GLES2
|
|
|
|
static GOnce module_gles2_gonce = G_ONCE_INIT;
|
|
|
|
static GModule *module_gles2;
|
|
|
|
|
|
|
|
static gpointer
|
|
|
|
load_gles2_module (gpointer user_data)
|
|
|
|
{
|
|
|
|
#ifdef GST_GL_LIBGLESV2_MODULE_NAME
|
|
|
|
module_gles2 =
|
|
|
|
g_module_open (GST_GL_LIBGLESV2_MODULE_NAME, G_MODULE_BIND_LAZY);
|
|
|
|
#else
|
|
|
|
/* This automatically handles the suffix and even .la files */
|
|
|
|
module_gles2 = g_module_open ("libGLESv2", G_MODULE_BIND_LAZY);
|
|
|
|
|
|
|
|
/* On Linux the .so is only in -dev packages, try with a real soname
|
|
|
|
* Proper compilers will optimize away the strcmp */
|
|
|
|
if (!module_gles2 && strcmp (G_MODULE_SUFFIX, "so") == 0)
|
|
|
|
module_gles2 = g_module_open ("libGLESv2.so.2", G_MODULE_BIND_LAZY);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if GST_GL_HAVE_GLES3
|
|
|
|
#error "Add module loading support for GLES3"
|
|
|
|
#endif
|
|
|
|
|
2013-08-14 00:44:19 +00:00
|
|
|
#define GST_CAT_DEFAULT gst_gl_context_debug
|
|
|
|
GST_DEBUG_CATEGORY (GST_CAT_DEFAULT);
|
|
|
|
|
|
|
|
#define gst_gl_context_parent_class parent_class
|
2014-05-08 05:30:49 +00:00
|
|
|
G_DEFINE_ABSTRACT_TYPE (GstGLContext, gst_gl_context, GST_TYPE_OBJECT);
|
2013-08-14 00:44:19 +00:00
|
|
|
|
|
|
|
#define GST_GL_CONTEXT_GET_PRIVATE(o) \
|
|
|
|
(G_TYPE_INSTANCE_GET_PRIVATE((o), GST_GL_TYPE_CONTEXT, GstGLContextPrivate))
|
|
|
|
|
|
|
|
static gpointer gst_gl_context_create_thread (GstGLContext * context);
|
|
|
|
static void gst_gl_context_finalize (GObject * object);
|
|
|
|
|
|
|
|
struct _GstGLContextPrivate
|
|
|
|
{
|
|
|
|
GstGLDisplay *display;
|
|
|
|
|
|
|
|
GThread *gl_thread;
|
|
|
|
|
|
|
|
/* conditions */
|
|
|
|
GMutex render_lock;
|
|
|
|
GCond create_cond;
|
|
|
|
GCond destroy_cond;
|
|
|
|
|
|
|
|
gboolean created;
|
|
|
|
gboolean alive;
|
|
|
|
|
2013-08-29 10:10:42 +00:00
|
|
|
GstGLContext *other_context;
|
2013-08-14 00:44:19 +00:00
|
|
|
GError **error;
|
2014-04-13 03:39:14 +00:00
|
|
|
|
|
|
|
gint gl_major;
|
|
|
|
gint gl_minor;
|
2014-05-21 11:44:40 +00:00
|
|
|
|
|
|
|
gchar *gl_exts;
|
2013-08-14 00:44:19 +00:00
|
|
|
};
|
|
|
|
|
2014-02-10 21:57:29 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GstGLContext parent;
|
|
|
|
|
|
|
|
guintptr handle;
|
|
|
|
GstGLPlatform platform;
|
|
|
|
GstGLAPI available_apis;
|
|
|
|
} GstGLWrappedContext;
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GstGLContextClass parent;
|
|
|
|
} GstGLWrappedContextClass;
|
|
|
|
|
|
|
|
#define GST_GL_TYPE_WRAPPED_CONTEXT (gst_gl_wrapped_context_get_type())
|
|
|
|
GType gst_gl_wrapped_context_get_type (void);
|
|
|
|
G_DEFINE_TYPE (GstGLWrappedContext, gst_gl_wrapped_context,
|
|
|
|
GST_GL_TYPE_CONTEXT);
|
|
|
|
|
|
|
|
#define GST_GL_WRAPPED_CONTEXT(o) (G_TYPE_CHECK_INSTANCE_CAST((o), GST_GL_TYPE_WRAPPED_CONTEXT, GstGLWrappedContext))
|
|
|
|
#define GST_GL_WRAPPED_CONTEXT_CLASS(k) (G_TYPE_CHECK_CLASS((k), GST_GL_TYPE_CONTEXT, GstGLContextClass))
|
|
|
|
#define GST_GL_IS_WRAPPED_CONTEXT(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), GST_GL_TYPE_WRAPPED_CONTEXT))
|
|
|
|
#define GST_GL_IS_WRAPPED_CONTEXT_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE((k), GST_GL_TYPE_WRAPPED_CONTEXT))
|
|
|
|
#define GST_GL_WRAPPED_CONTEXT_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS((o), GST_GL_TYPE_WRAPPED_CONTEXT, GstGLWrappedContextClass))
|
|
|
|
|
2013-08-14 00:44:19 +00:00
|
|
|
GQuark
|
|
|
|
gst_gl_context_error_quark (void)
|
|
|
|
{
|
|
|
|
return g_quark_from_static_string ("gst-gl-context-error-quark");
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_ensure_window (GstGLContext * context)
|
|
|
|
{
|
|
|
|
GstGLWindow *window;
|
|
|
|
|
|
|
|
if (context->window)
|
|
|
|
return;
|
|
|
|
|
|
|
|
window = gst_gl_window_new (context->priv->display);
|
|
|
|
|
|
|
|
gst_gl_context_set_window (context, window);
|
2013-09-20 01:55:36 +00:00
|
|
|
|
|
|
|
gst_object_unref (window);
|
2013-08-14 00:44:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_context_init (GstGLContext * context)
|
|
|
|
{
|
|
|
|
context->priv = GST_GL_CONTEXT_GET_PRIVATE (context);
|
|
|
|
|
2013-11-06 22:12:02 +00:00
|
|
|
context->window = NULL;
|
2013-09-15 04:23:43 +00:00
|
|
|
context->gl_vtable = g_slice_alloc0 (sizeof (GstGLFuncs));
|
|
|
|
|
2013-08-14 00:44:19 +00:00
|
|
|
g_mutex_init (&context->priv->render_lock);
|
|
|
|
|
|
|
|
g_cond_init (&context->priv->create_cond);
|
|
|
|
g_cond_init (&context->priv->destroy_cond);
|
|
|
|
context->priv->created = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_context_class_init (GstGLContextClass * klass)
|
|
|
|
{
|
|
|
|
g_type_class_add_private (klass, sizeof (GstGLContextPrivate));
|
|
|
|
|
2014-05-01 12:36:54 +00:00
|
|
|
module_self = g_module_open (NULL, G_MODULE_BIND_LAZY);
|
|
|
|
|
2013-08-14 00:44:19 +00:00
|
|
|
klass->get_proc_address =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_gl_context_default_get_proc_address);
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (klass)->finalize = gst_gl_context_finalize;
|
|
|
|
}
|
|
|
|
|
2014-02-10 21:57:29 +00:00
|
|
|
static void
|
|
|
|
_init_debug (void)
|
|
|
|
{
|
|
|
|
static volatile gsize _init = 0;
|
|
|
|
|
|
|
|
if (g_once_init_enter (&_init)) {
|
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_gl_context_debug, "glcontext", 0,
|
|
|
|
"glcontext element");
|
|
|
|
g_once_init_leave (&_init, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-23 11:53:48 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_context_new:
|
|
|
|
* @display: a #GstGLDisplay
|
|
|
|
*
|
|
|
|
* Create a new #GstGLContext with the specified @display
|
|
|
|
*
|
|
|
|
* Returns: a new #GstGLContext
|
|
|
|
*/
|
2013-08-14 00:44:19 +00:00
|
|
|
GstGLContext *
|
|
|
|
gst_gl_context_new (GstGLDisplay * display)
|
|
|
|
{
|
|
|
|
GstGLContext *context = NULL;
|
|
|
|
const gchar *user_choice;
|
|
|
|
|
2014-02-10 21:57:29 +00:00
|
|
|
_init_debug ();
|
2013-08-14 00:44:19 +00:00
|
|
|
|
|
|
|
user_choice = g_getenv ("GST_GL_PLATFORM");
|
|
|
|
GST_INFO ("creating a context, user choice:%s", user_choice);
|
|
|
|
#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 ());
|
|
|
|
#endif
|
2014-05-27 07:46:16 +00:00
|
|
|
#if GST_GL_HAVE_PLATFORM_CGL
|
|
|
|
if (!context && (!user_choice || g_strstr_len (user_choice, 5, "cgl")))
|
2013-11-30 09:51:49 +00:00
|
|
|
context = GST_GL_CONTEXT (gst_gl_context_cocoa_new ());
|
|
|
|
#endif
|
2013-08-14 00:44:19 +00:00
|
|
|
#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 ());
|
|
|
|
#endif
|
2013-08-15 07:09:04 +00:00
|
|
|
#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 ());
|
|
|
|
}
|
|
|
|
#endif
|
2014-04-12 19:43:50 +00:00
|
|
|
#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 ());
|
|
|
|
#endif
|
2013-08-15 07:09:04 +00:00
|
|
|
|
2013-08-14 00:44:19 +00:00
|
|
|
if (!context) {
|
|
|
|
/* subclass returned a NULL context */
|
|
|
|
GST_WARNING ("Could not create context. user specified %s",
|
|
|
|
user_choice ? user_choice : "(null)");
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2013-10-22 10:48:00 +00:00
|
|
|
context->priv->display = gst_object_ref (display);
|
2013-08-14 00:44:19 +00:00
|
|
|
|
|
|
|
return context;
|
|
|
|
}
|
|
|
|
|
2014-02-10 21:57:29 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_context_new_wrapped:
|
|
|
|
* @display: a #GstGLDisplay
|
|
|
|
* @handle: the OpenGL context to wrap
|
|
|
|
* @context_type: a #GstGLPlatform specifying the type of context in @handle
|
|
|
|
* @available_apis: a #GstGLAPI containing the available OpenGL apis in @handle
|
|
|
|
*
|
|
|
|
* Wraps an existing OpenGL context into a #GstGLContext.
|
|
|
|
*
|
|
|
|
* Returns: a #GstGLContext wrapping @handle
|
|
|
|
*/
|
|
|
|
GstGLContext *
|
|
|
|
gst_gl_context_new_wrapped (GstGLDisplay * display, guintptr handle,
|
|
|
|
GstGLPlatform context_type, GstGLAPI available_apis)
|
|
|
|
{
|
|
|
|
GstGLContext *context;
|
|
|
|
GstGLWrappedContext *context_wrap = NULL;
|
|
|
|
|
|
|
|
_init_debug ();
|
|
|
|
|
|
|
|
context_wrap = g_object_new (GST_GL_TYPE_WRAPPED_CONTEXT, NULL);
|
|
|
|
|
|
|
|
if (!context_wrap) {
|
|
|
|
/* subclass returned a NULL context */
|
|
|
|
GST_ERROR ("Could not wrap existing context");
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
context = (GstGLContext *) context_wrap;
|
|
|
|
|
|
|
|
context->priv->display = gst_object_ref (display);
|
|
|
|
context_wrap->handle = handle;
|
|
|
|
context_wrap->platform = context_type;
|
|
|
|
context_wrap->available_apis = available_apis;
|
|
|
|
|
|
|
|
return context;
|
|
|
|
}
|
|
|
|
|
2013-08-14 00:44:19 +00:00
|
|
|
static void
|
|
|
|
gst_gl_context_finalize (GObject * object)
|
|
|
|
{
|
|
|
|
GstGLContext *context = GST_GL_CONTEXT (object);
|
|
|
|
|
2014-02-10 21:57:29 +00:00
|
|
|
if (context->window) {
|
|
|
|
gst_gl_window_set_resize_callback (context->window, NULL, NULL, NULL);
|
|
|
|
gst_gl_window_set_draw_callback (context->window, NULL, NULL, NULL);
|
|
|
|
|
|
|
|
if (context->priv->alive) {
|
|
|
|
g_mutex_lock (&context->priv->render_lock);
|
|
|
|
GST_INFO ("send quit gl window loop");
|
|
|
|
gst_gl_window_quit (context->window);
|
|
|
|
while (context->priv->alive) {
|
|
|
|
g_cond_wait (&context->priv->destroy_cond, &context->priv->render_lock);
|
|
|
|
}
|
|
|
|
g_mutex_unlock (&context->priv->render_lock);
|
2013-08-15 07:09:04 +00:00
|
|
|
}
|
2013-08-14 00:44:19 +00:00
|
|
|
|
2014-02-10 21:57:29 +00:00
|
|
|
gst_gl_window_set_close_callback (context->window, NULL, NULL, NULL);
|
|
|
|
|
|
|
|
if (context->priv->gl_thread) {
|
|
|
|
gpointer ret = g_thread_join (context->priv->gl_thread);
|
|
|
|
GST_INFO ("gl thread joined");
|
|
|
|
if (ret != NULL)
|
|
|
|
GST_ERROR ("gl thread returned a non-null pointer");
|
|
|
|
context->priv->gl_thread = NULL;
|
|
|
|
}
|
2013-08-14 00:44:19 +00:00
|
|
|
|
2014-02-10 21:57:29 +00:00
|
|
|
gst_object_unref (context->window);
|
2013-08-14 00:44:19 +00:00
|
|
|
}
|
|
|
|
|
2013-10-22 10:48:00 +00:00
|
|
|
gst_object_unref (context->priv->display);
|
2013-08-14 00:44:19 +00:00
|
|
|
|
2013-09-15 04:23:43 +00:00
|
|
|
if (context->gl_vtable) {
|
|
|
|
g_slice_free (GstGLFuncs, context->gl_vtable);
|
|
|
|
context->gl_vtable = NULL;
|
|
|
|
}
|
|
|
|
|
2013-08-14 00:44:19 +00:00
|
|
|
g_mutex_clear (&context->priv->render_lock);
|
|
|
|
|
|
|
|
g_cond_clear (&context->priv->destroy_cond);
|
|
|
|
g_cond_clear (&context->priv->create_cond);
|
|
|
|
|
2014-05-21 11:44:40 +00:00
|
|
|
g_free (context->priv->gl_exts);
|
|
|
|
|
2013-08-14 00:44:19 +00:00
|
|
|
G_OBJECT_CLASS (gst_gl_context_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
2013-11-23 11:53:48 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_context_activate:
|
|
|
|
* @context: a #GstGLContext
|
|
|
|
* @activate: %TRUE to activate, %FALSE to deactivate
|
|
|
|
*
|
|
|
|
* (De)activate the OpenGL context represented by this @context.
|
|
|
|
*
|
|
|
|
* In OpenGL terms, calls eglMakeCurrent or similar with this context and the
|
|
|
|
* currently set window. See gst_gl_context_set_window() for details.
|
|
|
|
*
|
|
|
|
* Returns: Whether the activation succeeded
|
|
|
|
*/
|
2013-08-14 00:44:19 +00:00
|
|
|
gboolean
|
|
|
|
gst_gl_context_activate (GstGLContext * context, gboolean activate)
|
|
|
|
{
|
2013-08-15 07:09:04 +00:00
|
|
|
GstGLContextClass *context_class;
|
2013-08-14 00:44:19 +00:00
|
|
|
gboolean result;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_GL_IS_CONTEXT (context), FALSE);
|
2013-08-15 07:09:04 +00:00
|
|
|
context_class = GST_GL_CONTEXT_GET_CLASS (context);
|
|
|
|
g_return_val_if_fail (context_class->activate != NULL, FALSE);
|
2013-08-14 00:44:19 +00:00
|
|
|
|
2013-08-15 07:09:04 +00:00
|
|
|
result = context_class->activate (context, activate);
|
2013-08-14 00:44:19 +00:00
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-11-23 11:53:48 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_context_get_gl_api:
|
|
|
|
* @context: a #GstGLContext
|
|
|
|
*
|
|
|
|
* Get the currently enabled OpenGL api.
|
|
|
|
*
|
|
|
|
* The currently available API may be limited by the #GstGLDisplay in use and/or
|
|
|
|
* the #GstGLWindow chosen.
|
|
|
|
*
|
|
|
|
* Returns: the currently available OpenGL api
|
|
|
|
*/
|
2013-08-14 00:44:19 +00:00
|
|
|
GstGLAPI
|
|
|
|
gst_gl_context_get_gl_api (GstGLContext * context)
|
|
|
|
{
|
2013-08-15 07:09:04 +00:00
|
|
|
GstGLContextClass *context_class;
|
2013-08-14 00:44:19 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GST_GL_IS_CONTEXT (context), GST_GL_API_NONE);
|
2013-08-15 07:09:04 +00:00
|
|
|
context_class = GST_GL_CONTEXT_GET_CLASS (context);
|
|
|
|
g_return_val_if_fail (context_class->get_gl_api != NULL, GST_GL_API_NONE);
|
2013-08-14 00:44:19 +00:00
|
|
|
|
2013-08-15 07:09:04 +00:00
|
|
|
return context_class->get_gl_api (context);
|
2013-08-14 00:44:19 +00:00
|
|
|
}
|
|
|
|
|
2013-11-23 11:53:48 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_context_get_proc_address:
|
|
|
|
* @context: a #GstGLContext
|
|
|
|
* @name: an opengl function name
|
|
|
|
*
|
|
|
|
* Get a function pointer to a specified opengl function, @name. If the the
|
|
|
|
* specific function does not exist, NULL is returned instead.
|
|
|
|
*
|
|
|
|
* Platform specfic functions (names starting 'egl', 'glX', 'wgl', etc) can also
|
|
|
|
* be retreived using this method.
|
|
|
|
*
|
|
|
|
* Returns: a function pointer or NULL
|
|
|
|
*/
|
2013-08-14 00:44:19 +00:00
|
|
|
gpointer
|
|
|
|
gst_gl_context_get_proc_address (GstGLContext * context, const gchar * name)
|
|
|
|
{
|
|
|
|
gpointer ret;
|
2013-08-15 07:09:04 +00:00
|
|
|
GstGLContextClass *context_class;
|
2013-08-14 00:44:19 +00:00
|
|
|
|
|
|
|
g_return_val_if_fail (GST_GL_IS_CONTEXT (context), NULL);
|
2014-02-10 21:57:29 +00:00
|
|
|
g_return_val_if_fail (!GST_GL_IS_WRAPPED_CONTEXT (context), NULL);
|
2013-08-15 07:09:04 +00:00
|
|
|
context_class = GST_GL_CONTEXT_GET_CLASS (context);
|
|
|
|
g_return_val_if_fail (context_class->get_proc_address != NULL, NULL);
|
2013-08-14 00:44:19 +00:00
|
|
|
|
2013-08-15 07:09:04 +00:00
|
|
|
ret = context_class->get_proc_address (context, name);
|
2013-08-14 00:44:19 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
gpointer
|
|
|
|
gst_gl_context_default_get_proc_address (GstGLContext * context,
|
|
|
|
const gchar * name)
|
|
|
|
{
|
|
|
|
gpointer ret = NULL;
|
2014-05-01 12:36:54 +00:00
|
|
|
GstGLAPI gl_api = gst_gl_context_get_gl_api (context);
|
2013-08-30 13:12:37 +00:00
|
|
|
|
2014-05-01 12:36:54 +00:00
|
|
|
/* First try to load symbol from the selected GL API for this context */
|
2014-04-30 17:37:27 +00:00
|
|
|
#if GST_GL_HAVE_GLES2
|
2014-05-01 12:36:54 +00:00
|
|
|
if (!ret && (gl_api & GST_GL_API_GLES2)) {
|
|
|
|
g_once (&module_gles2_gonce, load_gles2_module, NULL);
|
|
|
|
if (module_gles2)
|
|
|
|
g_module_symbol (module_gles2, name, &ret);
|
|
|
|
}
|
2014-04-30 17:37:27 +00:00
|
|
|
#endif
|
2013-08-30 13:12:37 +00:00
|
|
|
|
2014-05-01 12:36:54 +00:00
|
|
|
#if GST_GL_HAVE_OPENGL
|
|
|
|
if (!ret && (gl_api & (GST_GL_API_OPENGL | GST_GL_API_OPENGL3))) {
|
|
|
|
g_once (&module_opengl_gonce, load_opengl_module, NULL);
|
|
|
|
if (module_opengl)
|
|
|
|
g_module_symbol (module_opengl, name, &ret);
|
2013-08-30 13:12:37 +00:00
|
|
|
}
|
2014-05-01 12:36:54 +00:00
|
|
|
#endif
|
2013-08-14 00:44:19 +00:00
|
|
|
|
2014-05-01 12:36:54 +00:00
|
|
|
/* Otherwise fall back to the current module */
|
|
|
|
if (!ret)
|
|
|
|
g_module_symbol (module_self, name, &ret);
|
2013-08-14 00:44:19 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-11-23 11:53:48 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_context_set_window:
|
|
|
|
* @context: a #GstGLContext
|
|
|
|
* @window: (transfer full): a #GstGLWindow
|
|
|
|
*
|
|
|
|
* Set's the current window on @context to @window. The window can only be
|
|
|
|
* changed before gst_gl_context_create() has been called and the @window is not
|
|
|
|
* already running.
|
|
|
|
*
|
|
|
|
* Returns: Whether the window was successfully updated
|
|
|
|
*/
|
2013-08-14 00:44:19 +00:00
|
|
|
gboolean
|
|
|
|
gst_gl_context_set_window (GstGLContext * context, GstGLWindow * window)
|
|
|
|
{
|
2014-02-23 00:44:51 +00:00
|
|
|
g_return_val_if_fail (!GST_GL_IS_WRAPPED_CONTEXT (context), FALSE);
|
2014-02-10 21:57:29 +00:00
|
|
|
|
2013-08-14 00:44:19 +00:00
|
|
|
/* we can't change the window while we are running */
|
|
|
|
if (context->priv->alive)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (window) {
|
|
|
|
if (gst_gl_window_is_running (window))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
g_weak_ref_set (&window->context_ref, context);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (context->window)
|
|
|
|
gst_object_unref (context->window);
|
|
|
|
|
|
|
|
context->window = window ? gst_object_ref (window) : NULL;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-11-23 11:53:48 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_context_get_window:
|
|
|
|
* @context: a #GstGLContext
|
|
|
|
*
|
|
|
|
* Returns: the currently set window
|
|
|
|
*/
|
2013-08-14 00:44:19 +00:00
|
|
|
GstGLWindow *
|
|
|
|
gst_gl_context_get_window (GstGLContext * context)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GST_GL_IS_CONTEXT (context), NULL);
|
|
|
|
|
2014-02-10 21:57:29 +00:00
|
|
|
if (GST_GL_IS_WRAPPED_CONTEXT (context))
|
|
|
|
return NULL;
|
|
|
|
|
2013-08-14 00:44:19 +00:00
|
|
|
_ensure_window (context);
|
|
|
|
|
|
|
|
return gst_object_ref (context->window);
|
|
|
|
}
|
|
|
|
|
2013-11-23 11:53:48 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_context_create:
|
|
|
|
* @context: a #GstGLContext:
|
|
|
|
* @other_context: (allow-none): a #GstGLContext to share OpenGL objects with
|
|
|
|
* @error: (allow-none): a #GError
|
|
|
|
*
|
|
|
|
* Creates an OpenGL context in the current thread with the specified
|
|
|
|
* @other_context as a context to share shareable OpenGL objects with. See the
|
|
|
|
* OpenGL specification for what is shared between contexts.
|
|
|
|
*
|
|
|
|
* If an error occurs, and @error is not %NULL, then error will contain details
|
|
|
|
* of the error and %FALSE will be returned.
|
|
|
|
*
|
|
|
|
* Should only be called once.
|
|
|
|
*
|
|
|
|
* Returns: whether the context could successfully be created
|
|
|
|
*/
|
2013-08-14 00:44:19 +00:00
|
|
|
gboolean
|
|
|
|
gst_gl_context_create (GstGLContext * context,
|
2013-08-29 10:10:42 +00:00
|
|
|
GstGLContext * other_context, GError ** error)
|
2013-08-14 00:44:19 +00:00
|
|
|
{
|
|
|
|
gboolean alive = FALSE;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_GL_IS_CONTEXT (context), FALSE);
|
2014-02-10 21:57:29 +00:00
|
|
|
g_return_val_if_fail (!GST_GL_IS_WRAPPED_CONTEXT (context), FALSE);
|
2013-08-14 00:44:19 +00:00
|
|
|
_ensure_window (context);
|
|
|
|
|
|
|
|
g_mutex_lock (&context->priv->render_lock);
|
|
|
|
|
|
|
|
if (!context->priv->created) {
|
2013-08-29 10:10:42 +00:00
|
|
|
context->priv->other_context = other_context;
|
2013-08-14 00:44:19 +00:00
|
|
|
context->priv->error = error;
|
|
|
|
|
|
|
|
context->priv->gl_thread = g_thread_new ("gstglcontext",
|
|
|
|
(GThreadFunc) gst_gl_context_create_thread, context);
|
|
|
|
|
|
|
|
g_cond_wait (&context->priv->create_cond, &context->priv->render_lock);
|
|
|
|
|
|
|
|
context->priv->created = TRUE;
|
|
|
|
|
|
|
|
GST_INFO ("gl thread created");
|
|
|
|
}
|
|
|
|
|
|
|
|
alive = context->priv->alive;
|
|
|
|
|
|
|
|
g_mutex_unlock (&context->priv->render_lock);
|
|
|
|
|
|
|
|
return alive;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
_create_context_gles2 (GstGLContext * context, gint * gl_major, gint * gl_minor,
|
|
|
|
GError ** error)
|
|
|
|
{
|
|
|
|
const GstGLFuncs *gl;
|
|
|
|
GLenum gl_err = GL_NO_ERROR;
|
|
|
|
|
2013-09-15 04:23:43 +00:00
|
|
|
gl = context->gl_vtable;
|
2013-08-14 00:44:19 +00:00
|
|
|
|
|
|
|
GST_INFO ("GL_VERSION: %s", gl->GetString (GL_VERSION));
|
|
|
|
GST_INFO ("GL_SHADING_LANGUAGE_VERSION: %s",
|
|
|
|
gl->GetString (GL_SHADING_LANGUAGE_VERSION));
|
|
|
|
GST_INFO ("GL_VENDOR: %s", gl->GetString (GL_VENDOR));
|
|
|
|
GST_INFO ("GL_RENDERER: %s", gl->GetString (GL_RENDERER));
|
|
|
|
|
|
|
|
gl_err = gl->GetError ();
|
|
|
|
if (gl_err != GL_NO_ERROR) {
|
|
|
|
g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_FAILED,
|
|
|
|
"glGetString error: 0x%x", gl_err);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
#if GST_GL_HAVE_GLES2
|
|
|
|
if (!GL_ES_VERSION_2_0) {
|
|
|
|
g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_OLD_LIBS,
|
|
|
|
"OpenGL|ES >= 2.0 is required");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (gl_major)
|
|
|
|
*gl_major = 2;
|
|
|
|
if (gl_minor)
|
|
|
|
*gl_minor = 0;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-03-16 14:06:37 +00:00
|
|
|
static gboolean
|
2013-08-14 00:44:19 +00:00
|
|
|
_create_context_opengl (GstGLContext * context, gint * gl_major,
|
|
|
|
gint * gl_minor, GError ** error)
|
|
|
|
{
|
|
|
|
const GstGLFuncs *gl;
|
|
|
|
guint maj, min;
|
|
|
|
GLenum gl_err = GL_NO_ERROR;
|
|
|
|
GString *opengl_version = NULL;
|
|
|
|
|
2013-09-15 04:23:43 +00:00
|
|
|
gl = context->gl_vtable;
|
2013-08-14 00:44:19 +00:00
|
|
|
|
|
|
|
GST_INFO ("GL_VERSION: %s", gl->GetString (GL_VERSION));
|
|
|
|
GST_INFO ("GL_SHADING_LANGUAGE_VERSION: %s",
|
|
|
|
gl->GetString (GL_SHADING_LANGUAGE_VERSION));
|
|
|
|
GST_INFO ("GL_VENDOR: %s", gl->GetString (GL_VENDOR));
|
|
|
|
GST_INFO ("GL_RENDERER: %s", gl->GetString (GL_RENDERER));
|
|
|
|
|
|
|
|
gl_err = gl->GetError ();
|
|
|
|
if (gl_err != GL_NO_ERROR) {
|
|
|
|
g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_FAILED,
|
|
|
|
"glGetString error: 0x%x", gl_err);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
opengl_version =
|
|
|
|
g_string_truncate (g_string_new ((gchar *) gl->GetString (GL_VERSION)),
|
|
|
|
3);
|
|
|
|
|
|
|
|
sscanf (opengl_version->str, "%d.%d", &maj, &min);
|
|
|
|
|
|
|
|
g_string_free (opengl_version, TRUE);
|
|
|
|
|
|
|
|
/* OpenGL > 1.2.0 */
|
|
|
|
if ((maj < 1) || (maj < 2 && maj >= 1 && min < 2)) {
|
|
|
|
g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_OLD_LIBS,
|
|
|
|
"OpenGL >= 1.2.0 required, found %u.%u", maj, min);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gl_major)
|
|
|
|
*gl_major = maj;
|
|
|
|
if (gl_minor)
|
|
|
|
*gl_minor = min;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-03-16 14:06:37 +00:00
|
|
|
static GstGLAPI
|
2013-08-14 00:44:19 +00:00
|
|
|
_compiled_api (void)
|
|
|
|
{
|
|
|
|
GstGLAPI ret = GST_GL_API_NONE;
|
|
|
|
|
|
|
|
#if GST_GL_HAVE_OPENGL
|
|
|
|
ret |= GST_GL_API_OPENGL | GST_GL_API_OPENGL3;
|
|
|
|
#endif
|
|
|
|
#if GST_GL_HAVE_GLES2
|
|
|
|
ret |= GST_GL_API_GLES2;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-09-25 02:26:57 +00:00
|
|
|
static void
|
|
|
|
_unlock_create_thread (GstGLContext * context)
|
|
|
|
{
|
|
|
|
g_mutex_unlock (&context->priv->render_lock);
|
|
|
|
}
|
|
|
|
|
2014-03-23 11:02:08 +00:00
|
|
|
static GString *
|
2014-03-15 10:25:43 +00:00
|
|
|
_build_extension_string (GstGLContext * context)
|
|
|
|
{
|
|
|
|
const GstGLFuncs *gl = context->gl_vtable;
|
2014-03-23 11:02:08 +00:00
|
|
|
GString *ext_g_str = g_string_sized_new (1024);
|
|
|
|
const gchar *ext_const_c_str = NULL;
|
2014-03-15 10:25:43 +00:00
|
|
|
int i, n;
|
|
|
|
|
|
|
|
gl->GetIntegerv (GL_NUM_EXTENSIONS, &n);
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++) {
|
2014-03-23 11:02:08 +00:00
|
|
|
ext_const_c_str = (const gchar *) gl->GetStringi (GL_EXTENSIONS, i);
|
|
|
|
if (ext_const_c_str)
|
|
|
|
g_string_append_printf (ext_g_str, "%s ", ext_const_c_str);
|
2014-03-15 10:25:43 +00:00
|
|
|
}
|
|
|
|
|
2014-03-23 11:02:08 +00:00
|
|
|
return ext_g_str;
|
2014-03-15 10:25:43 +00:00
|
|
|
}
|
|
|
|
|
2013-08-14 00:44:19 +00:00
|
|
|
//gboolean
|
2013-08-29 10:10:42 +00:00
|
|
|
//gst_gl_context_create (GstGLContext * context, GstGLContext * other_context, GError ** error)
|
2013-08-14 00:44:19 +00:00
|
|
|
static gpointer
|
|
|
|
gst_gl_context_create_thread (GstGLContext * context)
|
|
|
|
{
|
2013-08-15 07:09:04 +00:00
|
|
|
GstGLContextClass *context_class;
|
2013-08-14 00:44:19 +00:00
|
|
|
GstGLWindowClass *window_class;
|
|
|
|
GstGLFuncs *gl;
|
|
|
|
gboolean ret = FALSE;
|
2014-05-06 06:39:06 +00:00
|
|
|
GstGLAPI compiled_api, user_api, gl_api;
|
2013-08-14 00:44:19 +00:00
|
|
|
gchar *api_string;
|
|
|
|
gchar *compiled_api_s;
|
|
|
|
gchar *user_api_string;
|
2014-03-23 11:02:08 +00:00
|
|
|
const gchar *user_choice;
|
2013-08-14 00:44:19 +00:00
|
|
|
GError **error;
|
2013-08-29 10:10:42 +00:00
|
|
|
GstGLContext *other_context;
|
2014-03-23 11:02:08 +00:00
|
|
|
GString *ext_g_str = NULL;
|
|
|
|
const gchar *ext_const_c_str = NULL;
|
2013-08-14 00:44:19 +00:00
|
|
|
|
2013-08-15 07:09:04 +00:00
|
|
|
g_mutex_lock (&context->priv->render_lock);
|
|
|
|
|
2013-08-14 00:44:19 +00:00
|
|
|
error = context->priv->error;
|
2013-08-29 10:10:42 +00:00
|
|
|
other_context = context->priv->other_context;
|
2013-08-14 00:44:19 +00:00
|
|
|
|
2013-08-15 07:09:04 +00:00
|
|
|
context_class = GST_GL_CONTEXT_GET_CLASS (context);
|
2013-08-14 00:44:19 +00:00
|
|
|
window_class = GST_GL_WINDOW_GET_CLASS (context->window);
|
|
|
|
|
|
|
|
if (window_class->open) {
|
2014-05-19 10:21:13 +00:00
|
|
|
if (!window_class->open (context->window, error)) {
|
|
|
|
g_assert (error == NULL || *error != NULL);
|
2013-08-14 00:44:19 +00:00
|
|
|
goto failure;
|
2014-05-19 10:21:13 +00:00
|
|
|
}
|
2013-08-14 00:44:19 +00:00
|
|
|
}
|
|
|
|
|
2013-09-15 04:23:43 +00:00
|
|
|
gl = context->gl_vtable;
|
2013-08-14 00:44:19 +00:00
|
|
|
compiled_api = _compiled_api ();
|
|
|
|
|
|
|
|
user_choice = g_getenv ("GST_GL_API");
|
|
|
|
|
2014-02-10 21:23:39 +00:00
|
|
|
user_api = gst_gl_api_from_string (user_choice);
|
|
|
|
user_api_string = gst_gl_api_to_string (user_api);
|
2013-08-14 00:44:19 +00:00
|
|
|
|
2014-02-10 21:23:39 +00:00
|
|
|
compiled_api_s = gst_gl_api_to_string (compiled_api);
|
2013-08-14 00:44:19 +00:00
|
|
|
|
|
|
|
if ((user_api & compiled_api) == GST_GL_API_NONE) {
|
|
|
|
g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_WRONG_API,
|
|
|
|
"Cannot create context with the user requested api (%s). "
|
|
|
|
"We have support for (%s)", user_api_string, compiled_api_s);
|
|
|
|
g_free (user_api_string);
|
|
|
|
g_free (compiled_api_s);
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
2013-08-15 07:09:04 +00:00
|
|
|
if (context_class->choose_format &&
|
|
|
|
!context_class->choose_format (context, error)) {
|
|
|
|
g_assert (error == NULL || *error != NULL);
|
|
|
|
g_free (compiled_api_s);
|
|
|
|
g_free (user_api_string);
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
2013-08-14 00:44:19 +00:00
|
|
|
GST_INFO ("Attempting to create opengl context. user chosen api(s) (%s), "
|
|
|
|
"compiled api support (%s)", user_api_string, compiled_api_s);
|
|
|
|
|
2013-08-15 07:09:04 +00:00
|
|
|
if (!context_class->create_context (context, compiled_api & user_api,
|
2013-08-29 10:10:42 +00:00
|
|
|
other_context, error)) {
|
2013-08-14 00:44:19 +00:00
|
|
|
g_assert (error == NULL || *error != NULL);
|
|
|
|
g_free (compiled_api_s);
|
|
|
|
g_free (user_api_string);
|
|
|
|
goto failure;
|
|
|
|
}
|
2013-08-15 07:09:04 +00:00
|
|
|
GST_INFO ("created context");
|
|
|
|
|
|
|
|
if (!context_class->activate (context, TRUE)) {
|
|
|
|
g_set_error (error, GST_GL_CONTEXT_ERROR,
|
|
|
|
GST_GL_CONTEXT_ERROR_RESOURCE_UNAVAILABLE,
|
|
|
|
"Failed to activate the GL Context");
|
|
|
|
g_free (compiled_api_s);
|
|
|
|
g_free (user_api_string);
|
|
|
|
goto failure;
|
|
|
|
}
|
2013-08-14 00:44:19 +00:00
|
|
|
|
2014-05-06 06:39:06 +00:00
|
|
|
gl_api = gst_gl_context_get_gl_api (context);
|
|
|
|
g_assert (gl_api != GST_GL_API_NONE && gl_api != GST_GL_API_ANY);
|
2013-08-14 00:44:19 +00:00
|
|
|
|
2014-05-06 06:39:06 +00:00
|
|
|
api_string = gst_gl_api_to_string (gl_api);
|
2013-08-14 00:44:19 +00:00
|
|
|
GST_INFO ("available GL APIs: %s", api_string);
|
|
|
|
|
2014-05-06 06:39:06 +00:00
|
|
|
if (((compiled_api & gl_api) & user_api) == GST_GL_API_NONE) {
|
2013-08-14 00:44:19 +00:00
|
|
|
g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_WRONG_API,
|
|
|
|
"failed to create context, context "
|
|
|
|
"could not provide correct api. user (%s), compiled (%s), context (%s)",
|
|
|
|
user_api_string, compiled_api_s, api_string);
|
|
|
|
g_free (api_string);
|
|
|
|
g_free (compiled_api_s);
|
|
|
|
g_free (user_api_string);
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (api_string);
|
|
|
|
g_free (compiled_api_s);
|
|
|
|
g_free (user_api_string);
|
|
|
|
|
|
|
|
gl->GetError = gst_gl_context_get_proc_address (context, "glGetError");
|
|
|
|
gl->GetString = gst_gl_context_get_proc_address (context, "glGetString");
|
2014-03-15 10:25:43 +00:00
|
|
|
gl->GetStringi = gst_gl_context_get_proc_address (context, "glGetStringi");
|
|
|
|
gl->GetIntegerv = gst_gl_context_get_proc_address (context, "glGetIntegerv");
|
2013-08-14 00:44:19 +00:00
|
|
|
|
|
|
|
if (!gl->GetError || !gl->GetString) {
|
|
|
|
g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_FAILED,
|
|
|
|
"could not GetProcAddress core opengl functions");
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* gl api specific code */
|
2014-05-06 06:39:06 +00:00
|
|
|
if (!ret && gl_api & GST_GL_API_OPENGL)
|
2014-04-13 03:39:14 +00:00
|
|
|
ret = _create_context_opengl (context, &context->priv->gl_major,
|
|
|
|
&context->priv->gl_minor, error);
|
2014-05-06 06:39:06 +00:00
|
|
|
if (!ret && gl_api & GST_GL_API_GLES2)
|
2014-04-13 03:39:14 +00:00
|
|
|
ret =
|
|
|
|
_create_context_gles2 (context, &context->priv->gl_major,
|
|
|
|
&context->priv->gl_minor, error);
|
2013-08-14 00:44:19 +00:00
|
|
|
|
2014-05-19 10:21:13 +00:00
|
|
|
if (!ret) {
|
|
|
|
g_assert (error == NULL || *error != NULL);
|
2013-08-14 00:44:19 +00:00
|
|
|
goto failure;
|
2014-05-19 10:21:13 +00:00
|
|
|
}
|
2013-08-14 00:44:19 +00:00
|
|
|
|
2014-03-15 10:25:43 +00:00
|
|
|
/* GL core contexts and GLES3 */
|
2014-04-13 03:39:14 +00:00
|
|
|
if (gl->GetIntegerv && gl->GetStringi && context->priv->gl_major >= 3)
|
2014-03-23 11:02:08 +00:00
|
|
|
ext_g_str = _build_extension_string (context);
|
|
|
|
|
2014-03-24 12:04:08 +00:00
|
|
|
if (ext_g_str && ext_g_str->len) {
|
2014-04-13 03:49:22 +00:00
|
|
|
GST_DEBUG_OBJECT (context, "GL_EXTENSIONS: %s", ext_g_str->str);
|
2014-04-13 03:39:14 +00:00
|
|
|
_gst_gl_feature_check_ext_functions (context, context->priv->gl_major,
|
|
|
|
context->priv->gl_minor, ext_g_str->str);
|
2014-05-21 11:44:40 +00:00
|
|
|
|
|
|
|
context->priv->gl_exts = g_string_free (ext_g_str, FALSE);
|
2014-03-15 10:25:43 +00:00
|
|
|
} else {
|
2014-03-23 11:02:08 +00:00
|
|
|
ext_const_c_str = (const gchar *) gl->GetString (GL_EXTENSIONS);
|
|
|
|
if (!ext_const_c_str)
|
|
|
|
ext_const_c_str = "";
|
2014-05-21 11:44:40 +00:00
|
|
|
|
2014-04-13 03:49:22 +00:00
|
|
|
GST_DEBUG_OBJECT (context, "GL_EXTENSIONS: %s", ext_const_c_str);
|
2014-04-13 03:39:14 +00:00
|
|
|
_gst_gl_feature_check_ext_functions (context, context->priv->gl_major,
|
|
|
|
context->priv->gl_minor, ext_const_c_str);
|
2014-03-15 10:25:43 +00:00
|
|
|
|
2014-05-21 11:44:40 +00:00
|
|
|
context->priv->gl_exts = g_strdup (ext_const_c_str);
|
|
|
|
}
|
2014-02-10 21:57:29 +00:00
|
|
|
|
2013-08-14 00:44:19 +00:00
|
|
|
context->priv->alive = TRUE;
|
|
|
|
|
|
|
|
g_cond_signal (&context->priv->create_cond);
|
2013-09-25 02:26:57 +00:00
|
|
|
|
|
|
|
// g_mutex_unlock (&context->priv->render_lock);
|
|
|
|
gst_gl_window_send_message_async (context->window,
|
|
|
|
(GstGLWindowCB) _unlock_create_thread, context, NULL);
|
2013-08-14 00:44:19 +00:00
|
|
|
|
|
|
|
gst_gl_window_run (context->window);
|
|
|
|
|
|
|
|
GST_INFO ("loop exited\n");
|
|
|
|
|
|
|
|
g_mutex_lock (&context->priv->render_lock);
|
|
|
|
|
|
|
|
context->priv->alive = FALSE;
|
|
|
|
|
|
|
|
context_class->activate (context, FALSE);
|
|
|
|
|
|
|
|
context_class->destroy_context (context);
|
|
|
|
|
2014-02-28 06:42:51 +00:00
|
|
|
/* User supplied callback */
|
2013-08-14 00:44:19 +00:00
|
|
|
if (context->window->close)
|
|
|
|
context->window->close (context->window->close_data);
|
|
|
|
|
2014-02-28 06:42:51 +00:00
|
|
|
/* window specific shutdown */
|
|
|
|
if (window_class->close) {
|
|
|
|
window_class->close (context->window);
|
|
|
|
}
|
|
|
|
|
2013-08-14 00:44:19 +00:00
|
|
|
g_cond_signal (&context->priv->destroy_cond);
|
|
|
|
|
|
|
|
g_mutex_unlock (&context->priv->render_lock);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
failure:
|
|
|
|
{
|
|
|
|
g_cond_signal (&context->priv->create_cond);
|
|
|
|
g_mutex_unlock (&context->priv->render_lock);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-23 11:53:48 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_context_get_gl_context:
|
|
|
|
* @context: a #GstGLContext:
|
|
|
|
*
|
|
|
|
* Gets the backing OpenGL context used by @context.
|
|
|
|
*
|
|
|
|
* Returns: The platform specific backing OpenGL context
|
|
|
|
*/
|
2013-08-14 00:44:19 +00:00
|
|
|
guintptr
|
|
|
|
gst_gl_context_get_gl_context (GstGLContext * context)
|
|
|
|
{
|
|
|
|
GstGLContextClass *context_class;
|
|
|
|
guintptr result;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_GL_IS_CONTEXT (context), 0);
|
|
|
|
context_class = GST_GL_CONTEXT_GET_CLASS (context);
|
|
|
|
g_return_val_if_fail (context_class->get_gl_context != NULL, 0);
|
|
|
|
|
|
|
|
result = context_class->get_gl_context (context);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
2013-09-15 04:23:43 +00:00
|
|
|
|
2014-02-10 21:57:29 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_context_get_gl_platform:
|
|
|
|
* @context: a #GstGLContext:
|
|
|
|
*
|
|
|
|
* Gets the OpenGL platform that used by @context.
|
|
|
|
*
|
|
|
|
* Returns: The platform specific backing OpenGL context
|
|
|
|
*/
|
|
|
|
GstGLPlatform
|
|
|
|
gst_gl_context_get_gl_platform (GstGLContext * context)
|
|
|
|
{
|
|
|
|
GstGLContextClass *context_class;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_GL_IS_CONTEXT (context), 0);
|
|
|
|
context_class = GST_GL_CONTEXT_GET_CLASS (context);
|
|
|
|
g_return_val_if_fail (context_class->get_gl_platform != NULL, 0);
|
|
|
|
|
|
|
|
return context_class->get_gl_platform (context);
|
|
|
|
}
|
|
|
|
|
2013-11-23 11:53:48 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_context_get_display:
|
|
|
|
* @context: a #GstGLContext:
|
|
|
|
*
|
|
|
|
* Returns: the #GstGLDisplay associated with this @context
|
|
|
|
*/
|
2013-09-15 04:23:43 +00:00
|
|
|
GstGLDisplay *
|
|
|
|
gst_gl_context_get_display (GstGLContext * context)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GST_GL_IS_CONTEXT (context), NULL);
|
|
|
|
|
|
|
|
return gst_object_ref (context->priv->display);
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GstGLContext *context;
|
|
|
|
GstGLContextThreadFunc func;
|
|
|
|
gpointer data;
|
|
|
|
} RunGenericData;
|
|
|
|
|
|
|
|
static void
|
|
|
|
_gst_gl_context_thread_run_generic (RunGenericData * data)
|
|
|
|
{
|
|
|
|
GST_TRACE ("running function:%p data:%p", data->func, data->data);
|
|
|
|
|
|
|
|
data->func (data->context, data->data);
|
|
|
|
}
|
|
|
|
|
2013-11-23 11:53:48 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_context_thread_add:
|
|
|
|
* @context: a #GstGLContext
|
|
|
|
* @func: a #GstGLContextThreadFunc
|
|
|
|
* @data: (closure): user data to call @func with
|
|
|
|
*
|
|
|
|
* Execute @func in the OpenGL thread of @context with @data
|
|
|
|
*
|
|
|
|
* MT-safe
|
|
|
|
*/
|
2013-09-15 04:23:43 +00:00
|
|
|
void
|
|
|
|
gst_gl_context_thread_add (GstGLContext * context,
|
|
|
|
GstGLContextThreadFunc func, gpointer data)
|
|
|
|
{
|
|
|
|
GstGLWindow *window;
|
|
|
|
RunGenericData rdata;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_GL_IS_CONTEXT (context));
|
|
|
|
g_return_if_fail (func != NULL);
|
2014-02-10 21:57:29 +00:00
|
|
|
g_return_if_fail (!GST_GL_IS_WRAPPED_CONTEXT (context));
|
2013-09-15 04:23:43 +00:00
|
|
|
|
|
|
|
rdata.context = context;
|
|
|
|
rdata.data = data;
|
|
|
|
rdata.func = func;
|
|
|
|
|
|
|
|
window = gst_gl_context_get_window (context);
|
|
|
|
|
|
|
|
gst_gl_window_send_message (window,
|
|
|
|
GST_GL_WINDOW_CB (_gst_gl_context_thread_run_generic), &rdata);
|
|
|
|
|
|
|
|
gst_object_unref (window);
|
|
|
|
}
|
2014-02-10 21:57:29 +00:00
|
|
|
|
2014-04-13 03:39:14 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_context_get_gl_version:
|
|
|
|
* @context: a #GstGLContext
|
|
|
|
* @maj: (out): resulting major version
|
|
|
|
* @min: (out): resulting minor version
|
|
|
|
*
|
|
|
|
* Returns the OpenGL version implemented by @context. See
|
|
|
|
* gst_gl_context_get_gl_api() for retreiving the OpenGL api implemented by
|
|
|
|
* @context.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_gl_context_get_gl_version (GstGLContext * context, gint * maj, gint * min)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GST_GL_IS_CONTEXT (context));
|
|
|
|
g_return_if_fail (maj == NULL && min == NULL);
|
|
|
|
|
|
|
|
if (maj)
|
|
|
|
*maj = context->priv->gl_major;
|
|
|
|
|
|
|
|
if (min)
|
|
|
|
*min = context->priv->gl_minor;
|
|
|
|
}
|
2014-02-10 21:57:29 +00:00
|
|
|
|
2014-05-14 07:33:21 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_context_check_feature:
|
|
|
|
* @context: a #GstGLContext
|
|
|
|
* @feature: a platform specific feature
|
|
|
|
*
|
|
|
|
* Some features require that the context be created before it is possible to
|
|
|
|
* determine their existence and so will fail if that is not the case.
|
|
|
|
*
|
|
|
|
* Returns: Whether @feature is supported by @context
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_gl_context_check_feature (GstGLContext * context, const gchar * feature)
|
|
|
|
{
|
|
|
|
GstGLContextClass *context_class;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_GL_IS_CONTEXT (context), FALSE);
|
|
|
|
g_return_val_if_fail (feature != NULL, FALSE);
|
|
|
|
|
|
|
|
context_class = GST_GL_CONTEXT_GET_CLASS (context);
|
2014-05-21 11:44:40 +00:00
|
|
|
|
|
|
|
if (g_strstr_len (feature, 3, "GL_"))
|
|
|
|
return gst_gl_check_extension (feature, context->priv->gl_exts);
|
|
|
|
|
2014-05-14 07:33:21 +00:00
|
|
|
if (!context_class->check_feature)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return context_class->check_feature (context, feature);
|
|
|
|
}
|
|
|
|
|
2014-02-10 21:57:29 +00:00
|
|
|
static GstGLAPI
|
|
|
|
gst_gl_wrapped_context_get_gl_api (GstGLContext * context)
|
|
|
|
{
|
|
|
|
GstGLWrappedContext *context_wrap = GST_GL_WRAPPED_CONTEXT (context);
|
|
|
|
|
|
|
|
return context_wrap->available_apis;
|
|
|
|
}
|
|
|
|
|
|
|
|
static guintptr
|
|
|
|
gst_gl_wrapped_context_get_gl_context (GstGLContext * context)
|
|
|
|
{
|
|
|
|
GstGLWrappedContext *context_wrap = GST_GL_WRAPPED_CONTEXT (context);
|
|
|
|
|
|
|
|
return context_wrap->handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstGLPlatform
|
|
|
|
gst_gl_wrapped_context_get_gl_platform (GstGLContext * context)
|
|
|
|
{
|
|
|
|
GstGLWrappedContext *context_wrap = GST_GL_WRAPPED_CONTEXT (context);
|
|
|
|
|
|
|
|
return context_wrap->platform;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_gl_wrapped_context_activate (GstGLContext * context, gboolean activate)
|
|
|
|
{
|
|
|
|
g_assert_not_reached ();
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_wrapped_context_class_init (GstGLWrappedContextClass * klass)
|
|
|
|
{
|
|
|
|
GstGLContextClass *context_class = (GstGLContextClass *) klass;
|
|
|
|
|
|
|
|
context_class->get_gl_context =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_gl_wrapped_context_get_gl_context);
|
|
|
|
context_class->get_gl_api =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_gl_wrapped_context_get_gl_api);
|
|
|
|
context_class->get_gl_platform =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_gl_wrapped_context_get_gl_platform);
|
|
|
|
context_class->activate = GST_DEBUG_FUNCPTR (gst_gl_wrapped_context_activate);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_wrapped_context_init (GstGLWrappedContext * context)
|
|
|
|
{
|
|
|
|
}
|