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.
|
|
|
|
*/
|
|
|
|
|
2017-12-19 16:51:24 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2013-08-14 00:44:19 +00:00
|
|
|
# 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
|
|
|
|
|
2017-07-07 15:15:12 +00:00
|
|
|
#include "gstglcontext.h"
|
2017-08-28 02:56:34 +00:00
|
|
|
#include <gst/gl/gl.h>
|
2017-07-07 15:15:12 +00:00
|
|
|
|
2013-08-14 00:44:19 +00:00
|
|
|
#include <gmodule.h>
|
2015-10-20 17:44:50 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
2013-08-14 00:44:19 +00:00
|
|
|
|
2017-08-14 08:33:38 +00:00
|
|
|
#include "gstglcontext_private.h"
|
2017-07-07 15:15:12 +00:00
|
|
|
#include "gstglfeature.h"
|
2016-10-27 05:19:04 +00:00
|
|
|
#include "gstglfeature_private.h"
|
2017-07-07 15:15:12 +00:00
|
|
|
#include "gstglfuncs.h"
|
2013-08-14 00:44:19 +00:00
|
|
|
|
2015-07-05 23:45:45 +00:00
|
|
|
#ifndef GL_NUM_EXTENSIONS
|
|
|
|
#define GL_NUM_EXTENSIONS 0x0000821d
|
|
|
|
#endif
|
|
|
|
|
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
|
2020-02-18 10:33:18 +00:00
|
|
|
#include "wgl/gstglcontext_wgl.h"
|
2013-08-15 07:09:04 +00:00
|
|
|
#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
|
|
|
|
2016-02-16 02:58:42 +00:00
|
|
|
extern void _gst_gl_debug_enable (GstGLContext * context);
|
2015-10-01 15:01:42 +00:00
|
|
|
|
2015-02-27 13:30:38 +00:00
|
|
|
static GPrivate current_context_key;
|
|
|
|
|
2014-05-01 12:36:54 +00:00
|
|
|
static GModule *module_self;
|
2014-10-28 06:31:37 +00:00
|
|
|
static GOnce module_self_gonce = G_ONCE_INIT;
|
2014-05-01 12:36:54 +00:00
|
|
|
|
|
|
|
#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
|
|
|
|
/* On Linux the .so is only in -dev packages, try with a real soname
|
|
|
|
* Proper compilers will optimize away the strcmp */
|
2015-10-20 17:44:50 +00:00
|
|
|
if (g_strcmp0 (G_MODULE_SUFFIX, "so") == 0)
|
2014-05-01 12:36:54 +00:00
|
|
|
module_opengl = g_module_open ("libGL.so.1", G_MODULE_BIND_LAZY);
|
2014-05-29 14:59:28 +00:00
|
|
|
|
|
|
|
/* This automatically handles the suffix and even .la files */
|
|
|
|
if (!module_opengl)
|
|
|
|
module_opengl = g_module_open ("libGL", G_MODULE_BIND_LAZY);
|
2014-05-01 12:36:54 +00:00
|
|
|
#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
|
|
|
|
/* On Linux the .so is only in -dev packages, try with a real soname
|
|
|
|
* Proper compilers will optimize away the strcmp */
|
2015-10-20 17:44:50 +00:00
|
|
|
if (g_strcmp0 (G_MODULE_SUFFIX, "so") == 0)
|
2014-05-01 12:36:54 +00:00
|
|
|
module_gles2 = g_module_open ("libGLESv2.so.2", G_MODULE_BIND_LAZY);
|
2014-05-29 14:59:28 +00:00
|
|
|
|
|
|
|
/* This automatically handles the suffix and even .la files */
|
|
|
|
if (!module_gles2)
|
|
|
|
module_gles2 = g_module_open ("libGLESv2", G_MODULE_BIND_LAZY);
|
|
|
|
|
2014-05-01 12:36:54 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-10-28 06:31:37 +00:00
|
|
|
static gpointer
|
|
|
|
load_self_module (gpointer user_data)
|
|
|
|
{
|
|
|
|
module_self = g_module_open (NULL, G_MODULE_BIND_LAZY);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2016-01-07 03:02:52 +00:00
|
|
|
/* Context sharedness is tracked by a refcounted pointer stored in each context
|
|
|
|
* object to track complex creation/deletion scenarios. As a result,
|
|
|
|
* sharedness can only be successfully validated between two GstGLContext's
|
|
|
|
* where one is not a wrapped context.
|
2015-07-15 14:37:58 +00:00
|
|
|
*
|
|
|
|
* As there is no API at the winsys level to tell whether two OpenGL contexts
|
|
|
|
* can share GL resources, this is the next best thing.
|
2016-01-07 03:02:52 +00:00
|
|
|
*
|
|
|
|
* XXX: we may need a way to associate two wrapped GstGLContext's as being
|
2019-08-29 17:42:39 +00:00
|
|
|
* shared however I have not come across a use case that requires this yet.
|
2015-07-15 14:37:58 +00:00
|
|
|
*/
|
2016-01-07 03:02:52 +00:00
|
|
|
struct ContextShareGroup
|
|
|
|
{
|
2021-03-18 08:18:36 +00:00
|
|
|
int refcount;
|
2016-01-07 03:02:52 +00:00
|
|
|
};
|
2015-07-15 14:37:58 +00:00
|
|
|
|
2016-01-07 03:02:52 +00:00
|
|
|
static struct ContextShareGroup *
|
|
|
|
_context_share_group_new (void)
|
2015-07-15 14:37:58 +00:00
|
|
|
{
|
2016-01-07 03:02:52 +00:00
|
|
|
struct ContextShareGroup *ret = g_new0 (struct ContextShareGroup, 1);
|
2015-07-15 14:37:58 +00:00
|
|
|
|
2016-01-07 03:02:52 +00:00
|
|
|
ret->refcount = 1;
|
2015-07-15 14:37:58 +00:00
|
|
|
|
2016-01-07 03:02:52 +00:00
|
|
|
return ret;
|
|
|
|
}
|
2015-07-15 14:37:58 +00:00
|
|
|
|
2016-01-07 03:02:52 +00:00
|
|
|
static struct ContextShareGroup *
|
|
|
|
_context_share_group_ref (struct ContextShareGroup *share)
|
|
|
|
{
|
|
|
|
g_atomic_int_inc (&share->refcount);
|
|
|
|
return share;
|
|
|
|
}
|
2015-07-15 14:37:58 +00:00
|
|
|
|
2016-01-07 03:02:52 +00:00
|
|
|
static void
|
|
|
|
_context_share_group_unref (struct ContextShareGroup *share)
|
|
|
|
{
|
|
|
|
if (g_atomic_int_dec_and_test (&share->refcount))
|
|
|
|
g_free (share);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
_context_share_group_is_shared (struct ContextShareGroup *share)
|
|
|
|
{
|
|
|
|
return g_atomic_int_get (&share->refcount) > 1;
|
2015-07-15 14:37:58 +00:00
|
|
|
}
|
|
|
|
|
2013-08-14 00:44:19 +00:00
|
|
|
#define GST_CAT_DEFAULT gst_gl_context_debug
|
|
|
|
GST_DEBUG_CATEGORY (GST_CAT_DEFAULT);
|
2016-02-16 02:58:42 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (gst_gl_debug);
|
2013-08-14 00:44:19 +00:00
|
|
|
|
2015-05-27 10:07:38 +00:00
|
|
|
static void _init_debug (void);
|
|
|
|
|
2013-08-14 00:44:19 +00:00
|
|
|
static gpointer gst_gl_context_create_thread (GstGLContext * context);
|
|
|
|
static void gst_gl_context_finalize (GObject * object);
|
2016-11-16 14:45:38 +00:00
|
|
|
static void gst_gl_context_default_get_gl_platform_version (GstGLContext *
|
|
|
|
context, gint * major, gint * minor);
|
2013-08-14 00:44:19 +00:00
|
|
|
|
|
|
|
struct _GstGLContextPrivate
|
|
|
|
{
|
|
|
|
GThread *gl_thread;
|
2014-09-21 11:30:58 +00:00
|
|
|
GThread *active_thread;
|
2013-08-14 00:44:19 +00:00
|
|
|
|
|
|
|
/* conditions */
|
|
|
|
GMutex render_lock;
|
|
|
|
GCond create_cond;
|
2016-11-28 03:19:18 +00:00
|
|
|
GCond destroy_cond;
|
2013-08-14 00:44:19 +00:00
|
|
|
|
|
|
|
gboolean created;
|
|
|
|
gboolean alive;
|
|
|
|
|
2014-09-23 02:01:04 +00:00
|
|
|
GWeakRef other_context_ref;
|
2016-01-07 03:02:52 +00:00
|
|
|
struct ContextShareGroup *sharegroup;
|
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;
|
|
|
|
|
2018-06-23 19:33:16 +00:00
|
|
|
#define gst_gl_context_parent_class parent_class
|
|
|
|
G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (GstGLContext, gst_gl_context,
|
|
|
|
GST_TYPE_OBJECT);
|
|
|
|
|
2016-10-05 01:19:12 +00:00
|
|
|
#define GST_TYPE_GL_WRAPPED_CONTEXT (gst_gl_wrapped_context_get_type())
|
2017-08-11 17:38:41 +00:00
|
|
|
static GType gst_gl_wrapped_context_get_type (void);
|
2014-02-10 21:57:29 +00:00
|
|
|
G_DEFINE_TYPE (GstGLWrappedContext, gst_gl_wrapped_context,
|
2016-10-05 01:19:12 +00:00
|
|
|
GST_TYPE_GL_CONTEXT);
|
2014-02-10 21:57:29 +00:00
|
|
|
|
2016-10-05 01:19:12 +00:00
|
|
|
#define GST_GL_WRAPPED_CONTEXT(o) (G_TYPE_CHECK_INSTANCE_CAST((o), GST_TYPE_GL_WRAPPED_CONTEXT, GstGLWrappedContext))
|
|
|
|
#define GST_GL_WRAPPED_CONTEXT_CLASS(k) (G_TYPE_CHECK_CLASS((k), GST_TYPE_GL_CONTEXT, GstGLContextClass))
|
|
|
|
#define GST_IS_GL_WRAPPED_CONTEXT(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), GST_TYPE_GL_WRAPPED_CONTEXT))
|
|
|
|
#define GST_IS_GL_WRAPPED_CONTEXT_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE((k), GST_TYPE_GL_WRAPPED_CONTEXT))
|
|
|
|
#define GST_GL_WRAPPED_CONTEXT_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS((o), GST_TYPE_GL_WRAPPED_CONTEXT, GstGLWrappedContextClass))
|
2014-02-10 21:57:29 +00:00
|
|
|
|
2019-05-20 01:14:27 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_context_error_quark:
|
|
|
|
*
|
|
|
|
* Returns: the quark used for #GstGLContext in #GError's
|
|
|
|
*/
|
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;
|
|
|
|
|
2016-06-30 13:12:33 +00:00
|
|
|
window = gst_gl_display_create_window (context->display);
|
2013-08-14 00:44:19 +00:00
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2018-06-23 19:33:16 +00:00
|
|
|
context->priv = gst_gl_context_get_instance_private (context);
|
2013-08-14 00:44:19 +00:00
|
|
|
|
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);
|
2016-11-28 03:19:18 +00:00
|
|
|
g_cond_init (&context->priv->destroy_cond);
|
2013-08-14 00:44:19 +00:00
|
|
|
context->priv->created = FALSE;
|
2014-09-23 02:01:04 +00:00
|
|
|
|
|
|
|
g_weak_ref_init (&context->priv->other_context_ref, NULL);
|
2013-08-14 00:44:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_context_class_init (GstGLContextClass * klass)
|
|
|
|
{
|
2015-07-18 07:08:36 +00:00
|
|
|
klass->get_proc_address =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_gl_context_default_get_proc_address);
|
2016-11-16 14:45:38 +00:00
|
|
|
klass->get_gl_platform_version =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_gl_context_default_get_gl_platform_version);
|
2013-08-14 00:44:19 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (klass)->finalize = gst_gl_context_finalize;
|
2015-05-27 10:07:38 +00:00
|
|
|
|
|
|
|
_init_debug ();
|
2013-08-14 00:44:19 +00:00
|
|
|
}
|
|
|
|
|
2014-02-10 21:57:29 +00:00
|
|
|
static void
|
|
|
|
_init_debug (void)
|
|
|
|
{
|
2021-03-18 08:18:36 +00:00
|
|
|
static gsize _init = 0;
|
2014-02-10 21:57:29 +00:00
|
|
|
|
|
|
|
if (g_once_init_enter (&_init)) {
|
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_gl_context_debug, "glcontext", 0,
|
|
|
|
"glcontext element");
|
2016-02-16 02:58:42 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_gl_debug, "gldebug", 0, "OpenGL Debugging");
|
2014-02-10 21:57:29 +00:00
|
|
|
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
|
2014-10-31 01:30:53 +00:00
|
|
|
*
|
|
|
|
* Since: 1.4
|
2013-11-23 11:53:48 +00:00
|
|
|
*/
|
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");
|
2015-02-12 14:02:31 +00:00
|
|
|
GST_INFO ("creating a context for display %" GST_PTR_FORMAT
|
|
|
|
", user choice:%s", display, user_choice);
|
2014-12-03 08:02:58 +00:00
|
|
|
#if GST_GL_HAVE_PLATFORM_CGL
|
2015-09-30 05:17:38 +00:00
|
|
|
if (!context && (!user_choice || g_strstr_len (user_choice, 3, "cgl")))
|
2015-07-24 06:11:38 +00:00
|
|
|
context = GST_GL_CONTEXT (gst_gl_context_cocoa_new (display));
|
2014-12-03 08:02:58 +00:00
|
|
|
#endif
|
2014-05-29 15:09:26 +00:00
|
|
|
#if GST_GL_HAVE_PLATFORM_GLX
|
|
|
|
if (!context && (!user_choice || g_strstr_len (user_choice, 3, "glx")))
|
2015-07-24 06:11:38 +00:00
|
|
|
context = GST_GL_CONTEXT (gst_gl_context_glx_new (display));
|
2014-05-29 15:09:26 +00:00
|
|
|
#endif
|
2013-08-14 00:44:19 +00:00
|
|
|
#if GST_GL_HAVE_PLATFORM_EGL
|
2015-09-30 05:17:38 +00:00
|
|
|
if (!context && (!user_choice || g_strstr_len (user_choice, 3, "egl")))
|
2015-07-24 06:11:38 +00:00
|
|
|
context = GST_GL_CONTEXT (gst_gl_context_egl_new (display));
|
2013-08-14 00:44:19 +00:00
|
|
|
#endif
|
2013-08-15 07:09:04 +00:00
|
|
|
#if GST_GL_HAVE_PLATFORM_WGL
|
2015-09-30 05:17:38 +00:00
|
|
|
if (!context && (!user_choice || g_strstr_len (user_choice, 3, "wgl")))
|
2015-07-24 06:11:38 +00:00
|
|
|
context = GST_GL_CONTEXT (gst_gl_context_wgl_new (display));
|
2013-08-15 07:09:04 +00:00
|
|
|
#endif
|
2014-04-12 19:43:50 +00:00
|
|
|
#if GST_GL_HAVE_PLATFORM_EAGL
|
2015-09-30 05:17:38 +00:00
|
|
|
if (!context && (!user_choice || g_strstr_len (user_choice, 4, "eagl")))
|
2015-07-24 06:11:38 +00:00
|
|
|
context = GST_GL_CONTEXT (gst_gl_context_eagl_new (display));
|
2014-04-12 19:43:50 +00:00
|
|
|
#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;
|
|
|
|
}
|
|
|
|
|
2015-06-15 15:36:26 +00:00
|
|
|
context->display = gst_object_ref (display);
|
2013-08-14 00:44:19 +00:00
|
|
|
|
2015-02-12 14:02:31 +00:00
|
|
|
GST_DEBUG_OBJECT (context,
|
|
|
|
"Done creating context for display %" GST_PTR_FORMAT " (user_choice:%s)",
|
|
|
|
display, user_choice);
|
|
|
|
|
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
|
|
|
|
*
|
2017-03-08 18:01:13 +00:00
|
|
|
* Wraps an existing OpenGL context into a #GstGLContext.
|
2014-02-10 21:57:29 +00:00
|
|
|
*
|
2016-11-03 01:03:24 +00:00
|
|
|
* Note: The caller is responsible for ensuring that the OpenGL context
|
|
|
|
* represented by @handle stays alive while the returned #GstGLContext is
|
|
|
|
* active.
|
|
|
|
*
|
2019-06-13 05:36:56 +00:00
|
|
|
* @context_type must not be %GST_GL_PLATFORM_NONE or %GST_GL_PLATFORM_ANY
|
|
|
|
*
|
|
|
|
* @available_apis must not be %GST_GL_API_NONE or %GST_GL_API_ANY
|
|
|
|
*
|
2017-05-15 17:31:31 +00:00
|
|
|
* Returns: (transfer full): a #GstGLContext wrapping @handle
|
2014-10-31 01:30:53 +00:00
|
|
|
*
|
|
|
|
* Since: 1.4
|
2014-02-10 21:57:29 +00:00
|
|
|
*/
|
|
|
|
GstGLContext *
|
|
|
|
gst_gl_context_new_wrapped (GstGLDisplay * display, guintptr handle,
|
|
|
|
GstGLPlatform context_type, GstGLAPI available_apis)
|
|
|
|
{
|
|
|
|
GstGLContext *context;
|
|
|
|
GstGLWrappedContext *context_wrap = NULL;
|
2014-10-30 05:48:00 +00:00
|
|
|
GstGLContextClass *context_class;
|
2014-11-27 10:05:45 +00:00
|
|
|
GstGLAPI display_api;
|
2014-02-10 21:57:29 +00:00
|
|
|
|
|
|
|
_init_debug ();
|
|
|
|
|
2019-06-13 05:36:56 +00:00
|
|
|
g_return_val_if_fail (GST_IS_GL_DISPLAY (display), NULL);
|
|
|
|
g_return_val_if_fail (handle != 0, NULL);
|
|
|
|
g_return_val_if_fail (available_apis != GST_GL_API_ANY, NULL);
|
|
|
|
g_return_val_if_fail (available_apis != GST_GL_API_NONE, NULL);
|
|
|
|
g_return_val_if_fail (context_type != GST_GL_PLATFORM_NONE, NULL);
|
|
|
|
g_return_val_if_fail (context_type != GST_GL_PLATFORM_ANY, NULL);
|
|
|
|
|
2014-11-27 10:05:45 +00:00
|
|
|
display_api = gst_gl_display_get_gl_api (display);
|
|
|
|
g_return_val_if_fail ((display_api & available_apis) != GST_GL_API_NONE,
|
|
|
|
NULL);
|
|
|
|
|
2016-10-05 01:19:12 +00:00
|
|
|
context_wrap = g_object_new (GST_TYPE_GL_WRAPPED_CONTEXT, NULL);
|
2017-05-15 17:31:31 +00:00
|
|
|
gst_object_ref_sink (context_wrap);
|
2014-02-10 21:57:29 +00:00
|
|
|
|
|
|
|
if (!context_wrap) {
|
|
|
|
/* subclass returned a NULL context */
|
|
|
|
GST_ERROR ("Could not wrap existing context");
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
context = (GstGLContext *) context_wrap;
|
|
|
|
|
2015-06-15 15:36:26 +00:00
|
|
|
context->display = gst_object_ref (display);
|
2016-01-07 03:02:52 +00:00
|
|
|
context->priv->sharegroup = _context_share_group_new ();
|
2014-02-10 21:57:29 +00:00
|
|
|
context_wrap->handle = handle;
|
|
|
|
context_wrap->platform = context_type;
|
|
|
|
context_wrap->available_apis = available_apis;
|
|
|
|
|
2014-10-30 05:48:00 +00:00
|
|
|
context_class = GST_GL_CONTEXT_GET_CLASS (context);
|
|
|
|
|
|
|
|
#if GST_GL_HAVE_PLATFORM_GLX
|
|
|
|
if (context_type == GST_GL_PLATFORM_GLX) {
|
|
|
|
context_class->get_current_context = gst_gl_context_glx_get_current_context;
|
|
|
|
context_class->get_proc_address = gst_gl_context_glx_get_proc_address;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if GST_GL_HAVE_PLATFORM_EGL
|
|
|
|
if (context_type == GST_GL_PLATFORM_EGL) {
|
|
|
|
context_class->get_current_context = gst_gl_context_egl_get_current_context;
|
|
|
|
context_class->get_proc_address = gst_gl_context_egl_get_proc_address;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if GST_GL_HAVE_PLATFORM_CGL
|
|
|
|
if (context_type == GST_GL_PLATFORM_CGL) {
|
|
|
|
context_class->get_current_context =
|
|
|
|
gst_gl_context_cocoa_get_current_context;
|
2015-07-18 07:19:18 +00:00
|
|
|
context_class->get_proc_address = gst_gl_context_default_get_proc_address;
|
2014-10-30 05:48:00 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if GST_GL_HAVE_PLATFORM_WGL
|
|
|
|
if (context_type == GST_GL_PLATFORM_WGL) {
|
|
|
|
context_class->get_current_context = gst_gl_context_wgl_get_current_context;
|
|
|
|
context_class->get_proc_address = gst_gl_context_wgl_get_proc_address;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if GST_GL_HAVE_PLATFORM_EAGL
|
|
|
|
if (context_type == GST_GL_PLATFORM_EAGL) {
|
|
|
|
context_class->get_current_context =
|
|
|
|
gst_gl_context_eagl_get_current_context;
|
2015-07-18 07:19:18 +00:00
|
|
|
context_class->get_proc_address = gst_gl_context_default_get_proc_address;
|
2014-10-30 05:48:00 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-12-31 06:45:53 +00:00
|
|
|
if (!context_class->get_current_context) {
|
|
|
|
/* we don't have API support */
|
|
|
|
gst_object_unref (context);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2014-02-10 21:57:29 +00:00
|
|
|
return context;
|
|
|
|
}
|
|
|
|
|
2014-10-28 06:31:37 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_context_get_current_gl_context:
|
2015-06-05 12:35:39 +00:00
|
|
|
* @context_type: a #GstGLPlatform specifying the type of context to retrieve
|
2014-10-28 06:31:37 +00:00
|
|
|
*
|
|
|
|
* Returns: The OpenGL context handle current in the calling thread or %NULL
|
2014-10-31 01:30:53 +00:00
|
|
|
*
|
|
|
|
* Since: 1.6
|
2014-10-28 06:31:37 +00:00
|
|
|
*/
|
|
|
|
guintptr
|
|
|
|
gst_gl_context_get_current_gl_context (GstGLPlatform context_type)
|
|
|
|
{
|
|
|
|
guintptr handle = 0;
|
|
|
|
|
|
|
|
_init_debug ();
|
|
|
|
|
|
|
|
#if GST_GL_HAVE_PLATFORM_GLX
|
|
|
|
if (!handle && (context_type & GST_GL_PLATFORM_GLX) != 0)
|
|
|
|
handle = gst_gl_context_glx_get_current_context ();
|
|
|
|
#endif
|
|
|
|
#if GST_GL_HAVE_PLATFORM_EGL
|
|
|
|
if (!handle && (context_type & GST_GL_PLATFORM_EGL) != 0)
|
|
|
|
handle = gst_gl_context_egl_get_current_context ();
|
|
|
|
#endif
|
|
|
|
#if GST_GL_HAVE_PLATFORM_CGL
|
|
|
|
if (!handle && (context_type & GST_GL_PLATFORM_CGL) != 0)
|
|
|
|
handle = gst_gl_context_cocoa_get_current_context ();
|
|
|
|
#endif
|
|
|
|
#if GST_GL_HAVE_PLATFORM_WGL
|
|
|
|
if (!handle && (context_type & GST_GL_PLATFORM_WGL) != 0)
|
|
|
|
handle = gst_gl_context_wgl_get_current_context ();
|
|
|
|
#endif
|
|
|
|
#if GST_GL_HAVE_PLATFORM_EAGL
|
|
|
|
if (!handle && (context_type & GST_GL_PLATFORM_EAGL) != 0)
|
|
|
|
handle = gst_gl_context_eagl_get_current_context ();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (!handle)
|
2015-06-05 12:35:39 +00:00
|
|
|
GST_WARNING ("Could not retrieve current context");
|
2014-10-28 06:31:37 +00:00
|
|
|
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
|
2016-11-03 01:03:24 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_context_get_proc_address_with_platform:
|
|
|
|
* @context_type: a #GstGLPlatform
|
|
|
|
* @gl_api: a #GstGLAPI
|
|
|
|
* @name: the name of the function to retrieve
|
|
|
|
*
|
|
|
|
* Attempts to use the @context_type specific GetProcAddress implementations
|
2019-08-29 17:42:39 +00:00
|
|
|
* to retrieve @name.
|
2016-11-03 01:03:24 +00:00
|
|
|
*
|
|
|
|
* See also gst_gl_context_get_proc_address().
|
|
|
|
*
|
|
|
|
* Returns: a function pointer for @name, or %NULL
|
|
|
|
*
|
|
|
|
* Since: 1.6
|
|
|
|
*/
|
2015-07-18 07:08:36 +00:00
|
|
|
gpointer
|
|
|
|
gst_gl_context_get_proc_address_with_platform (GstGLPlatform context_type,
|
|
|
|
GstGLAPI gl_api, const gchar * name)
|
|
|
|
{
|
|
|
|
gpointer ret = NULL;
|
|
|
|
|
|
|
|
#if GST_GL_HAVE_PLATFORM_GLX
|
|
|
|
if (!ret && (context_type & GST_GL_PLATFORM_GLX) != 0)
|
|
|
|
ret = gst_gl_context_glx_get_proc_address (gl_api, name);
|
|
|
|
#endif
|
|
|
|
#if GST_GL_HAVE_PLATFORM_EGL
|
|
|
|
if (!ret && (context_type & GST_GL_PLATFORM_EGL) != 0)
|
|
|
|
ret = gst_gl_context_egl_get_proc_address (gl_api, name);
|
|
|
|
#endif
|
|
|
|
#if GST_GL_HAVE_PLATFORM_WGL
|
|
|
|
if (!ret && (context_type & GST_GL_PLATFORM_WGL) != 0)
|
|
|
|
ret = gst_gl_context_wgl_get_proc_address (gl_api, name);
|
|
|
|
#endif
|
|
|
|
/* CGL and EAGL rely on the default impl */
|
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
ret = gst_gl_context_default_get_proc_address (gl_api, name);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-10-28 06:31:37 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_context_get_current_gl_api:
|
2015-08-31 17:06:31 +00:00
|
|
|
* @platform: the #GstGLPlatform to retrieve the API for
|
2016-11-03 01:03:24 +00:00
|
|
|
* @major: (out) (allow-none): the major version
|
|
|
|
* @minor: (out) (allow-none): the minor version
|
2014-10-28 06:31:37 +00:00
|
|
|
*
|
2016-11-03 01:03:24 +00:00
|
|
|
* If an error occurs, @major and @minor are not modified and %GST_GL_API_NONE is
|
2014-10-28 06:31:37 +00:00
|
|
|
* returned.
|
|
|
|
*
|
|
|
|
* Returns: The version supported by the OpenGL context current in the calling
|
|
|
|
* thread or %GST_GL_API_NONE
|
2014-10-31 01:30:53 +00:00
|
|
|
*
|
|
|
|
* Since: 1.6
|
2014-10-28 06:31:37 +00:00
|
|
|
*/
|
|
|
|
GstGLAPI
|
2015-07-18 07:19:18 +00:00
|
|
|
gst_gl_context_get_current_gl_api (GstGLPlatform platform, guint * major,
|
|
|
|
guint * minor)
|
2014-10-28 06:31:37 +00:00
|
|
|
{
|
2016-06-28 03:02:32 +00:00
|
|
|
const GLubyte *(GSTGLAPI * GetString) (GLenum name);
|
2014-11-17 04:06:52 +00:00
|
|
|
#if GST_GL_HAVE_OPENGL
|
2016-06-28 03:02:32 +00:00
|
|
|
void (GSTGLAPI * GetIntegerv) (GLenum name, GLuint * n);
|
2014-11-17 04:06:52 +00:00
|
|
|
#endif
|
2014-10-28 06:31:37 +00:00
|
|
|
const gchar *version;
|
|
|
|
gint maj, min, n;
|
2017-11-20 16:06:07 +00:00
|
|
|
GstGLAPI ret = (1U << 31);
|
2014-10-28 06:31:37 +00:00
|
|
|
|
|
|
|
_init_debug ();
|
|
|
|
|
|
|
|
while (ret != GST_GL_API_NONE) {
|
|
|
|
/* FIXME: attempt to delve into the platform specific GetProcAddress */
|
2015-07-18 07:19:18 +00:00
|
|
|
GetString =
|
|
|
|
gst_gl_context_get_proc_address_with_platform (platform, ret,
|
|
|
|
"glGetString");
|
2014-11-17 04:06:52 +00:00
|
|
|
#if GST_GL_HAVE_OPENGL
|
2014-10-28 06:31:37 +00:00
|
|
|
GetIntegerv =
|
2015-07-18 07:19:18 +00:00
|
|
|
gst_gl_context_get_proc_address_with_platform (platform, ret,
|
|
|
|
"glGetIntegerv");
|
2014-11-17 04:06:52 +00:00
|
|
|
#endif
|
2014-10-28 06:31:37 +00:00
|
|
|
if (!GetString) {
|
|
|
|
goto next;
|
|
|
|
}
|
|
|
|
|
|
|
|
version = (const gchar *) GetString (GL_VERSION);
|
|
|
|
if (!version)
|
|
|
|
goto next;
|
|
|
|
|
|
|
|
/* strlen (x.x) == 3 */
|
|
|
|
n = strlen (version);
|
|
|
|
if (n < 3)
|
|
|
|
goto next;
|
|
|
|
|
|
|
|
if (g_strstr_len (version, 9, "OpenGL ES")) {
|
|
|
|
/* strlen (OpenGL ES x.x) == 13 */
|
|
|
|
if (n < 13)
|
|
|
|
goto next;
|
|
|
|
|
|
|
|
sscanf (&version[10], "%d.%d", &maj, &min);
|
|
|
|
|
|
|
|
if (maj <= 0 || min < 0)
|
|
|
|
goto next;
|
|
|
|
|
|
|
|
if (maj == 1) {
|
|
|
|
ret = GST_GL_API_GLES1;
|
|
|
|
break;
|
|
|
|
} else if (maj == 2 || maj == 3) {
|
|
|
|
ret = GST_GL_API_GLES2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
goto next;
|
|
|
|
} else {
|
|
|
|
sscanf (version, "%d.%d", &maj, &min);
|
|
|
|
|
|
|
|
if (maj <= 0 || min < 0)
|
|
|
|
goto next;
|
|
|
|
|
|
|
|
#if GST_GL_HAVE_OPENGL
|
|
|
|
if (GetIntegerv && (maj > 3 || (maj == 3 && min > 1))) {
|
2014-11-24 13:10:53 +00:00
|
|
|
GLuint context_flags = 0;
|
|
|
|
|
2014-10-28 06:31:37 +00:00
|
|
|
ret = GST_GL_API_NONE;
|
|
|
|
GetIntegerv (GL_CONTEXT_PROFILE_MASK, &context_flags);
|
|
|
|
if (context_flags & GL_CONTEXT_CORE_PROFILE_BIT)
|
|
|
|
ret |= GST_GL_API_OPENGL3;
|
|
|
|
if (context_flags & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT)
|
|
|
|
ret |= GST_GL_API_OPENGL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
ret = GST_GL_API_OPENGL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
next:
|
|
|
|
/* iterate through the apis */
|
|
|
|
ret >>= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ret == GST_GL_API_NONE)
|
|
|
|
return GST_GL_API_NONE;
|
|
|
|
|
|
|
|
if (major)
|
|
|
|
*major = maj;
|
|
|
|
if (minor)
|
|
|
|
*minor = min;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
2016-11-28 03:19:18 +00:00
|
|
|
g_mutex_lock (&context->priv->render_lock);
|
2014-02-10 21:57:29 +00:00
|
|
|
if (context->priv->alive) {
|
2015-02-12 14:02:31 +00:00
|
|
|
GST_INFO_OBJECT (context, "send quit gl window loop");
|
2014-02-10 21:57:29 +00:00
|
|
|
gst_gl_window_quit (context->window);
|
|
|
|
|
2015-12-21 11:13:15 +00:00
|
|
|
GST_INFO_OBJECT (context, "joining gl thread");
|
2016-11-28 03:19:18 +00:00
|
|
|
while (context->priv->alive)
|
|
|
|
g_cond_wait (&context->priv->destroy_cond, &context->priv->render_lock);
|
2015-02-12 14:02:31 +00:00
|
|
|
GST_INFO_OBJECT (context, "gl thread joined");
|
2016-11-28 03:19:18 +00:00
|
|
|
|
2017-02-23 23:42:08 +00:00
|
|
|
if (context->priv->gl_thread) {
|
|
|
|
g_thread_unref (context->priv->gl_thread);
|
|
|
|
context->priv->gl_thread = NULL;
|
|
|
|
}
|
2014-02-10 21:57:29 +00:00
|
|
|
}
|
2016-11-28 03:19:18 +00:00
|
|
|
g_mutex_unlock (&context->priv->render_lock);
|
2013-08-14 00:44:19 +00:00
|
|
|
|
2015-12-21 11:13:15 +00:00
|
|
|
gst_gl_window_set_close_callback (context->window, NULL, NULL, NULL);
|
2014-02-10 21:57:29 +00:00
|
|
|
gst_object_unref (context->window);
|
2017-02-23 23:42:08 +00:00
|
|
|
context->window = NULL;
|
2013-08-14 00:44:19 +00:00
|
|
|
}
|
|
|
|
|
2017-02-23 23:42:08 +00:00
|
|
|
if (context->priv->active_thread) {
|
|
|
|
g_thread_unref (context->priv->active_thread);
|
|
|
|
context->priv->active_thread = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (context->priv->gl_thread) {
|
|
|
|
g_thread_unref (context->priv->gl_thread);
|
|
|
|
context->priv->gl_thread = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (context->priv->sharegroup) {
|
2016-01-07 03:02:52 +00:00
|
|
|
_context_share_group_unref (context->priv->sharegroup);
|
2017-02-23 23:42:08 +00:00
|
|
|
context->priv->sharegroup = NULL;
|
|
|
|
}
|
2016-01-07 03:02:52 +00:00
|
|
|
|
2017-02-23 23:42:08 +00:00
|
|
|
if (context->display) {
|
|
|
|
gst_object_unref (context->display);
|
|
|
|
context->display = NULL;
|
|
|
|
}
|
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->create_cond);
|
2016-11-28 03:19:18 +00:00
|
|
|
g_cond_clear (&context->priv->destroy_cond);
|
2013-08-14 00:44:19 +00:00
|
|
|
|
2014-05-21 11:44:40 +00:00
|
|
|
g_free (context->priv->gl_exts);
|
2014-09-23 02:01:04 +00:00
|
|
|
g_weak_ref_clear (&context->priv->other_context_ref);
|
2014-05-21 11:44:40 +00:00
|
|
|
|
2015-02-12 14:02:31 +00:00
|
|
|
GST_DEBUG_OBJECT (context, "End of finalize");
|
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
|
2014-10-31 01:30:53 +00:00
|
|
|
*
|
|
|
|
* Since: 1.4
|
2013-11-23 11:53:48 +00:00
|
|
|
*/
|
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;
|
|
|
|
|
2015-10-19 04:15:30 +00:00
|
|
|
g_return_val_if_fail (GST_IS_GL_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
|
|
|
|
2015-02-12 14:02:31 +00:00
|
|
|
GST_DEBUG_OBJECT (context, "activate:%d", activate);
|
|
|
|
|
2014-09-21 11:30:58 +00:00
|
|
|
GST_OBJECT_LOCK (context);
|
2013-08-15 07:09:04 +00:00
|
|
|
result = context_class->activate (context, activate);
|
2013-08-14 00:44:19 +00:00
|
|
|
|
2015-02-27 13:30:38 +00:00
|
|
|
if (result && activate) {
|
2017-02-23 23:42:08 +00:00
|
|
|
GThread *old_thread = context->priv->active_thread;
|
|
|
|
context->priv->active_thread = g_thread_ref (g_thread_self ());
|
|
|
|
if (old_thread) {
|
|
|
|
g_thread_unref (old_thread);
|
|
|
|
}
|
|
|
|
|
2015-02-27 13:30:38 +00:00
|
|
|
g_private_set (¤t_context_key, context);
|
|
|
|
} else {
|
2017-02-23 23:42:08 +00:00
|
|
|
if (context->priv->active_thread) {
|
|
|
|
g_thread_unref (context->priv->active_thread);
|
|
|
|
context->priv->active_thread = NULL;
|
|
|
|
}
|
2015-02-27 13:30:38 +00:00
|
|
|
g_private_set (¤t_context_key, NULL);
|
|
|
|
}
|
2014-09-21 11:30:58 +00:00
|
|
|
GST_OBJECT_UNLOCK (context);
|
|
|
|
|
2013-08-14 00:44:19 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-09-21 11:30:58 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_context_get_thread:
|
|
|
|
* @context: a #GstGLContext
|
|
|
|
*
|
2014-09-22 07:08:17 +00:00
|
|
|
* Returns: (transfer full): The #GThread, @context is current in or NULL
|
2014-09-21 12:32:29 +00:00
|
|
|
*
|
|
|
|
* Since: 1.6
|
2014-09-21 11:30:58 +00:00
|
|
|
*/
|
|
|
|
GThread *
|
|
|
|
gst_gl_context_get_thread (GstGLContext * context)
|
|
|
|
{
|
|
|
|
GThread *ret;
|
|
|
|
|
2020-03-26 02:50:52 +00:00
|
|
|
g_return_val_if_fail (GST_IS_GL_CONTEXT (context), NULL);
|
|
|
|
|
2014-09-21 11:30:58 +00:00
|
|
|
GST_OBJECT_LOCK (context);
|
|
|
|
ret = context->priv->active_thread;
|
2014-09-22 07:08:17 +00:00
|
|
|
if (ret)
|
|
|
|
g_thread_ref (ret);
|
2014-09-21 11:30:58 +00:00
|
|
|
GST_OBJECT_UNLOCK (context);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
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.
|
|
|
|
*
|
2014-10-31 01:30:53 +00:00
|
|
|
* Returns: the available OpenGL api
|
|
|
|
*
|
|
|
|
* Since: 1.4
|
2013-11-23 11:53:48 +00:00
|
|
|
*/
|
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
|
|
|
|
2015-10-19 04:15:30 +00:00
|
|
|
g_return_val_if_fail (GST_IS_GL_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.
|
|
|
|
*
|
2019-08-29 17:42:39 +00:00
|
|
|
* Platform specific functions (names starting 'egl', 'glX', 'wgl', etc) can also
|
2015-06-05 12:35:39 +00:00
|
|
|
* be retrieved using this method.
|
2013-11-23 11:53:48 +00:00
|
|
|
*
|
2016-11-03 01:03:24 +00:00
|
|
|
* Note: This function may return valid function pointers that may not be valid
|
|
|
|
* to call in @context. The caller is responsible for ensuring that the
|
|
|
|
* returned function is a valid function to call in @context by either checking
|
|
|
|
* the OpenGL API and version or for an appropriate OpenGL extension.
|
|
|
|
*
|
|
|
|
* Note: On success, you need to cast the returned function pointer to the
|
|
|
|
* correct type to be able to call it correctly. On 32-bit Windows, this will
|
2019-05-20 01:14:27 +00:00
|
|
|
* include the `GSTGLAPI` identifier to use the correct calling convention.
|
2017-07-28 10:00:12 +00:00
|
|
|
* e.g.
|
|
|
|
*
|
|
|
|
* |[<!-- language="C" -->
|
|
|
|
* void (GSTGLAPI *PFN_glGetIntegerv) (GLenum name, GLint * ret)
|
|
|
|
* ]|
|
2016-11-03 01:03:24 +00:00
|
|
|
*
|
|
|
|
* Returns: a function pointer or %NULL
|
2014-10-31 01:30:53 +00:00
|
|
|
*
|
|
|
|
* Since: 1.4
|
2013-11-23 11:53:48 +00:00
|
|
|
*/
|
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;
|
2015-07-18 07:08:36 +00:00
|
|
|
GstGLAPI gl_api;
|
2013-08-14 00:44:19 +00:00
|
|
|
|
2015-10-19 04:15:30 +00:00
|
|
|
g_return_val_if_fail (GST_IS_GL_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
|
|
|
|
2015-07-18 07:08:36 +00:00
|
|
|
gl_api = gst_gl_context_get_gl_api (context);
|
|
|
|
ret = context_class->get_proc_address (gl_api, name);
|
2013-08-14 00:44:19 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-11-03 01:03:24 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_context_default_get_proc_address:
|
|
|
|
* @gl_api: a #GstGLAPI
|
|
|
|
* @name: then function to get the address of
|
|
|
|
*
|
|
|
|
* A default implementation of the various GetProcAddress functions that looks
|
|
|
|
* for @name in the OpenGL shared libraries or in the current process.
|
|
|
|
*
|
|
|
|
* See also: gst_gl_context_get_proc_address()
|
|
|
|
*
|
|
|
|
* Returns: an address pointing to @name or %NULL
|
|
|
|
*
|
|
|
|
* Since: 1.4
|
|
|
|
*/
|
2013-08-14 00:44:19 +00:00
|
|
|
gpointer
|
2014-10-28 06:31:37 +00:00
|
|
|
gst_gl_context_default_get_proc_address (GstGLAPI gl_api, const gchar * name)
|
2013-08-14 00:44:19 +00:00
|
|
|
{
|
|
|
|
gpointer ret = NULL;
|
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 */
|
2014-10-28 06:31:37 +00:00
|
|
|
g_once (&module_self_gonce, load_self_module, NULL);
|
2014-05-01 12:36:54 +00:00
|
|
|
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
|
2014-10-31 01:30:53 +00:00
|
|
|
*
|
|
|
|
* Since: 1.4
|
2013-11-23 11:53:48 +00:00
|
|
|
*/
|
2013-08-14 00:44:19 +00:00
|
|
|
gboolean
|
|
|
|
gst_gl_context_set_window (GstGLContext * context, GstGLWindow * window)
|
|
|
|
{
|
2015-10-19 04:15:30 +00:00
|
|
|
g_return_val_if_fail (!GST_IS_GL_WRAPPED_CONTEXT (context), FALSE);
|
2014-02-10 21:57:29 +00:00
|
|
|
|
2015-02-12 14:02:31 +00:00
|
|
|
GST_DEBUG_OBJECT (context, "window:%" GST_PTR_FORMAT, window);
|
|
|
|
|
2013-08-14 00:44:19 +00:00
|
|
|
/* we can't change the window while we are running */
|
|
|
|
if (context->priv->alive)
|
|
|
|
return FALSE;
|
|
|
|
|
2016-10-26 05:30:43 +00:00
|
|
|
if (window)
|
2013-08-14 00:44:19 +00:00
|
|
|
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
|
|
|
|
*
|
2016-11-03 05:14:37 +00:00
|
|
|
* Returns: (transfer full) (nullable): the currently set window
|
2014-10-31 01:30:53 +00:00
|
|
|
*
|
|
|
|
* Since: 1.4
|
2013-11-23 11:53:48 +00:00
|
|
|
*/
|
2013-08-14 00:44:19 +00:00
|
|
|
GstGLWindow *
|
|
|
|
gst_gl_context_get_window (GstGLContext * context)
|
|
|
|
{
|
2015-10-19 04:15:30 +00:00
|
|
|
g_return_val_if_fail (GST_IS_GL_CONTEXT (context), NULL);
|
2013-08-14 00:44:19 +00:00
|
|
|
|
2015-10-19 04:15:30 +00:00
|
|
|
if (GST_IS_GL_WRAPPED_CONTEXT (context)) {
|
2015-02-12 14:02:31 +00:00
|
|
|
GST_WARNING_OBJECT (context, "context is not toplevel, returning NULL");
|
2014-02-10 21:57:29 +00:00
|
|
|
return NULL;
|
2015-02-12 14:02:31 +00:00
|
|
|
}
|
2014-02-10 21:57:29 +00:00
|
|
|
|
2013-08-14 00:44:19 +00:00
|
|
|
_ensure_window (context);
|
|
|
|
|
|
|
|
return gst_object_ref (context->window);
|
|
|
|
}
|
|
|
|
|
2014-09-23 02:01:04 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_context_can_share:
|
|
|
|
* @context: a #GstGLContext
|
|
|
|
* @other_context: another #GstGLContext
|
|
|
|
*
|
2015-07-15 14:37:58 +00:00
|
|
|
* Note: This will always fail for two wrapped #GstGLContext's
|
|
|
|
*
|
2014-09-23 02:01:04 +00:00
|
|
|
* Returns: whether @context and @other_context are able to share OpenGL
|
|
|
|
* resources.
|
|
|
|
*
|
|
|
|
* Since: 1.6
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_gl_context_can_share (GstGLContext * context, GstGLContext * other_context)
|
|
|
|
{
|
2015-10-19 04:15:30 +00:00
|
|
|
g_return_val_if_fail (GST_IS_GL_CONTEXT (context), FALSE);
|
|
|
|
g_return_val_if_fail (GST_IS_GL_CONTEXT (other_context), FALSE);
|
2014-09-23 02:01:04 +00:00
|
|
|
|
2014-09-28 14:24:28 +00:00
|
|
|
/* check if the contexts are descendants or the root nodes are the same */
|
2016-01-07 03:02:52 +00:00
|
|
|
return context->priv->sharegroup != NULL
|
|
|
|
&& context->priv->sharegroup == other_context->priv->sharegroup;
|
2014-09-23 02:01:04 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
*
|
2016-11-03 01:03:24 +00:00
|
|
|
* Creates an OpenGL context with the specified @other_context as a context
|
|
|
|
* to share shareable OpenGL objects with. See the OpenGL specification for
|
|
|
|
* what is shared between OpenGL contexts.
|
2013-11-23 11:53:48 +00:00
|
|
|
*
|
|
|
|
* 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
|
2014-10-31 01:30:53 +00:00
|
|
|
*
|
|
|
|
* Since: 1.4
|
2013-11-23 11:53:48 +00:00
|
|
|
*/
|
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;
|
|
|
|
|
2015-10-19 04:15:30 +00:00
|
|
|
g_return_val_if_fail (GST_IS_GL_CONTEXT (context), FALSE);
|
|
|
|
g_return_val_if_fail (!GST_IS_GL_WRAPPED_CONTEXT (context), FALSE);
|
2015-02-12 14:02:31 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (context, " other_context:%" GST_PTR_FORMAT, other_context);
|
|
|
|
|
2013-08-14 00:44:19 +00:00
|
|
|
_ensure_window (context);
|
|
|
|
|
|
|
|
g_mutex_lock (&context->priv->render_lock);
|
|
|
|
|
|
|
|
if (!context->priv->created) {
|
2014-09-23 02:01:04 +00:00
|
|
|
g_weak_ref_set (&context->priv->other_context_ref, other_context);
|
2013-08-14 00:44:19 +00:00
|
|
|
context->priv->error = error;
|
2015-07-15 14:37:58 +00:00
|
|
|
if (other_context == NULL)
|
2016-01-07 03:02:52 +00:00
|
|
|
context->priv->sharegroup = _context_share_group_new ();
|
2015-07-15 14:37:58 +00:00
|
|
|
else
|
2016-01-07 03:02:52 +00:00
|
|
|
context->priv->sharegroup =
|
|
|
|
_context_share_group_ref (other_context->priv->sharegroup);
|
2013-08-14 00:44:19 +00:00
|
|
|
|
|
|
|
context->priv->gl_thread = g_thread_new ("gstglcontext",
|
|
|
|
(GThreadFunc) gst_gl_context_create_thread, context);
|
|
|
|
|
2015-12-21 11:13:15 +00:00
|
|
|
while (!context->priv->created)
|
|
|
|
g_cond_wait (&context->priv->create_cond, &context->priv->render_lock);
|
2013-08-14 00:44:19 +00:00
|
|
|
|
2015-02-12 14:02:31 +00:00
|
|
|
GST_INFO_OBJECT (context, "gl thread created");
|
2013-08-14 00:44:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
alive = context->priv->alive;
|
|
|
|
|
|
|
|
g_mutex_unlock (&context->priv->render_lock);
|
|
|
|
|
|
|
|
return alive;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2014-05-30 00:25:18 +00:00
|
|
|
_create_context_info (GstGLContext * context, GstGLAPI gl_api, gint * gl_major,
|
2013-08-14 00:44:19 +00:00
|
|
|
gint * gl_minor, GError ** error)
|
|
|
|
{
|
|
|
|
const GstGLFuncs *gl;
|
2014-06-02 07:23:39 +00:00
|
|
|
guint maj = 0, min = 0;
|
2013-08-14 00:44:19 +00:00
|
|
|
GLenum gl_err = GL_NO_ERROR;
|
2014-06-02 07:23:39 +00:00
|
|
|
const gchar *opengl_version = NULL;
|
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
|
|
|
|
2015-08-21 05:07:32 +00:00
|
|
|
if (!gl->GetString || !gl->GetString (GL_VERSION)) {
|
2014-11-06 07:37:23 +00:00
|
|
|
g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_FAILED,
|
|
|
|
"glGetString not defined or returned invalid value");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2015-08-21 05:07:32 +00:00
|
|
|
if (!gl->GetString (GL_SHADING_LANGUAGE_VERSION)) {
|
|
|
|
g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_FAILED,
|
|
|
|
"No GL shader support available");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2015-02-12 14:02:31 +00:00
|
|
|
GST_INFO_OBJECT (context, "GL_VERSION: %s",
|
2014-06-02 07:23:39 +00:00
|
|
|
GST_STR_NULL ((const gchar *) gl->GetString (GL_VERSION)));
|
2015-02-12 14:02:31 +00:00
|
|
|
GST_INFO_OBJECT (context, "GL_SHADING_LANGUAGE_VERSION: %s",
|
|
|
|
GST_STR_NULL ((const gchar *)
|
2014-06-02 07:23:39 +00:00
|
|
|
gl->GetString (GL_SHADING_LANGUAGE_VERSION)));
|
2015-02-12 14:02:31 +00:00
|
|
|
GST_INFO_OBJECT (context, "GL_VENDOR: %s",
|
2014-06-02 07:23:39 +00:00
|
|
|
GST_STR_NULL ((const gchar *) gl->GetString (GL_VENDOR)));
|
2015-02-12 14:02:31 +00:00
|
|
|
GST_INFO_OBJECT (context, "GL_RENDERER: %s",
|
2014-06-02 07:23:39 +00:00
|
|
|
GST_STR_NULL ((const gchar *) gl->GetString (GL_RENDERER)));
|
2013-08-14 00:44:19 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2014-06-02 07:23:39 +00:00
|
|
|
opengl_version = (const gchar *) gl->GetString (GL_VERSION);
|
2019-06-12 15:20:10 +00:00
|
|
|
if (opengl_version && g_str_has_prefix (opengl_version, "OpenGL ES "))
|
2014-05-30 00:25:18 +00:00
|
|
|
opengl_version = &opengl_version[10];
|
2013-08-14 00:44:19 +00:00
|
|
|
|
2014-06-02 07:23:39 +00:00
|
|
|
if (opengl_version)
|
|
|
|
sscanf (opengl_version, "%d.%d", &maj, &min);
|
2013-08-14 00:44:19 +00:00
|
|
|
|
|
|
|
/* OpenGL > 1.2.0 */
|
2014-05-30 00:25:18 +00:00
|
|
|
if (gl_api & GST_GL_API_OPENGL || gl_api & GST_GL_API_OPENGL3) {
|
|
|
|
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;
|
|
|
|
}
|
2013-08-14 00:44:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2015-12-21 11:13:15 +00:00
|
|
|
context->priv->created = TRUE;
|
2015-12-28 12:41:59 +00:00
|
|
|
GST_INFO_OBJECT (context, "gl thread running");
|
2015-12-21 11:13:15 +00:00
|
|
|
g_cond_signal (&context->priv->create_cond);
|
2013-09-25 02:26:57 +00:00
|
|
|
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;
|
2015-07-02 09:26:18 +00:00
|
|
|
GLint i = 0;
|
|
|
|
GLint n = 0;
|
2014-03-15 10:25:43 +00:00
|
|
|
|
|
|
|
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;
|
2014-11-27 10:05:45 +00:00
|
|
|
GstGLAPI compiled_api, user_api, gl_api, display_api;
|
2013-08-14 00:44:19 +00:00
|
|
|
gchar *api_string;
|
|
|
|
gchar *compiled_api_s;
|
2014-11-27 10:05:45 +00:00
|
|
|
gchar *user_api_s;
|
|
|
|
gchar *display_api_s;
|
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;
|
2013-08-14 00:44:19 +00:00
|
|
|
|
2013-08-15 07:09:04 +00:00
|
|
|
g_mutex_lock (&context->priv->render_lock);
|
|
|
|
|
2015-02-12 14:02:31 +00:00
|
|
|
GST_DEBUG_OBJECT (context, "Creating thread");
|
|
|
|
|
2013-08-14 00:44:19 +00:00
|
|
|
error = context->priv->error;
|
2014-09-23 02:01:04 +00:00
|
|
|
other_context = g_weak_ref_get (&context->priv->other_context_ref);
|
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);
|
|
|
|
|
2015-06-15 15:36:26 +00:00
|
|
|
display_api = gst_gl_display_get_gl_api_unlocked (context->display);
|
2014-11-27 10:05:45 +00:00
|
|
|
if (display_api == GST_GL_API_NONE) {
|
|
|
|
g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_WRONG_API,
|
|
|
|
"Cannot create context with satisfying requested apis "
|
|
|
|
"(display has no GL api!)");
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
2013-08-14 00:44:19 +00:00
|
|
|
if (window_class->open) {
|
2014-05-19 10:21:13 +00:00
|
|
|
if (!window_class->open (context->window, error)) {
|
2015-02-12 14:02:31 +00:00
|
|
|
GST_WARNING_OBJECT (context, "Failed to open window");
|
2014-05-19 10:21:13 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
compiled_api = _compiled_api ();
|
2014-11-27 10:05:45 +00:00
|
|
|
compiled_api_s = gst_gl_api_to_string (compiled_api);
|
2013-08-14 00:44:19 +00:00
|
|
|
|
|
|
|
user_choice = g_getenv ("GST_GL_API");
|
2014-02-10 21:23:39 +00:00
|
|
|
user_api = gst_gl_api_from_string (user_choice);
|
2014-11-27 10:05:45 +00:00
|
|
|
user_api_s = gst_gl_api_to_string (user_api);
|
2013-08-14 00:44:19 +00:00
|
|
|
|
2014-11-27 10:05:45 +00:00
|
|
|
display_api_s = gst_gl_api_to_string (display_api);
|
2013-08-14 00:44:19 +00:00
|
|
|
|
2014-11-27 10:05:45 +00:00
|
|
|
if ((user_api & compiled_api & display_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,
|
|
|
|
"Cannot create context with the user requested api (%s). "
|
2014-11-27 10:05:45 +00:00
|
|
|
"We have support for (%s), display api (%s)", user_api_s,
|
|
|
|
compiled_api_s, display_api_s);
|
|
|
|
g_free (user_api_s);
|
2013-08-14 00:44:19 +00:00
|
|
|
g_free (compiled_api_s);
|
2014-11-27 10:05:45 +00:00
|
|
|
g_free (display_api_s);
|
2013-08-14 00:44:19 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
2013-08-15 07:09:04 +00:00
|
|
|
if (context_class->choose_format &&
|
|
|
|
!context_class->choose_format (context, error)) {
|
2015-07-15 14:33:17 +00:00
|
|
|
GST_WARNING_OBJECT (context, "Failed to choose format");
|
2013-08-15 07:09:04 +00:00
|
|
|
g_assert (error == NULL || *error != NULL);
|
|
|
|
g_free (compiled_api_s);
|
2014-11-27 10:05:45 +00:00
|
|
|
g_free (user_api_s);
|
|
|
|
g_free (display_api_s);
|
2013-08-15 07:09:04 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
2015-02-12 14:02:31 +00:00
|
|
|
GST_INFO_OBJECT (context,
|
|
|
|
"Attempting to create opengl context. user chosen api(s) (%s), "
|
|
|
|
"compiled api support (%s) display api (%s)", user_api_s, compiled_api_s,
|
|
|
|
display_api_s);
|
2013-08-14 00:44:19 +00:00
|
|
|
|
2014-11-27 10:05:45 +00:00
|
|
|
if (!context_class->create_context (context,
|
|
|
|
compiled_api & user_api & display_api, other_context, error)) {
|
2015-02-12 14:02:31 +00:00
|
|
|
GST_WARNING_OBJECT (context, "Failed to create context");
|
2013-08-14 00:44:19 +00:00
|
|
|
g_assert (error == NULL || *error != NULL);
|
|
|
|
g_free (compiled_api_s);
|
2014-11-27 10:05:45 +00:00
|
|
|
g_free (user_api_s);
|
|
|
|
g_free (display_api_s);
|
2013-08-14 00:44:19 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
2015-02-12 14:02:31 +00:00
|
|
|
GST_INFO_OBJECT (context, "created context");
|
2013-08-15 07:09:04 +00:00
|
|
|
|
2014-12-31 06:45:53 +00:00
|
|
|
if (!gst_gl_context_activate (context, TRUE)) {
|
2013-08-15 07:09:04 +00:00
|
|
|
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);
|
2014-11-27 10:05:45 +00:00
|
|
|
g_free (user_api_s);
|
|
|
|
g_free (display_api_s);
|
2013-08-15 07:09:04 +00:00
|
|
|
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);
|
2015-02-12 14:02:31 +00:00
|
|
|
GST_INFO_OBJECT (context, "available GL APIs: %s", api_string);
|
2013-08-14 00:44:19 +00:00
|
|
|
|
2014-11-27 10:05:45 +00:00
|
|
|
if (((compiled_api & gl_api & display_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)",
|
2014-11-27 10:05:45 +00:00
|
|
|
user_api_s, compiled_api_s, api_string);
|
2013-08-14 00:44:19 +00:00
|
|
|
g_free (api_string);
|
|
|
|
g_free (compiled_api_s);
|
2014-11-27 10:05:45 +00:00
|
|
|
g_free (user_api_s);
|
|
|
|
g_free (display_api_s);
|
2013-08-14 00:44:19 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (api_string);
|
|
|
|
g_free (compiled_api_s);
|
2014-11-27 10:05:45 +00:00
|
|
|
g_free (user_api_s);
|
|
|
|
g_free (display_api_s);
|
2013-08-14 00:44:19 +00:00
|
|
|
|
2015-02-12 14:02:31 +00:00
|
|
|
GST_DEBUG_OBJECT (context, "Filling info");
|
2015-05-13 13:55:28 +00:00
|
|
|
if (!gst_gl_context_fill_info (context, error)) {
|
|
|
|
g_assert (error == NULL || *error != NULL);
|
|
|
|
goto failure;
|
|
|
|
}
|
2014-11-29 13:42:17 +00:00
|
|
|
|
2013-08-14 00:44:19 +00:00
|
|
|
context->priv->alive = TRUE;
|
|
|
|
|
2014-08-20 13:24:12 +00:00
|
|
|
#if !defined(GST_DISABLE_GST_DEBUG)
|
2016-02-16 02:58:42 +00:00
|
|
|
_gst_gl_debug_enable (context);
|
2014-08-20 13:24:12 +00:00
|
|
|
#endif
|
|
|
|
|
2015-02-12 14:02:31 +00:00
|
|
|
if (other_context) {
|
|
|
|
GST_DEBUG_OBJECT (context, "Unreffing other_context %" GST_PTR_FORMAT,
|
|
|
|
other_context);
|
2014-09-23 02:01:04 +00:00
|
|
|
gst_object_unref (other_context);
|
2015-02-12 14:02:31 +00:00
|
|
|
}
|
2014-09-23 02:01:04 +00:00
|
|
|
|
2015-12-21 11:13:15 +00:00
|
|
|
/* unlocking of the render_lock happens when the
|
|
|
|
* context's loop is running from inside that loop */
|
2013-09-25 02:26:57 +00:00
|
|
|
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);
|
|
|
|
|
2015-02-12 14:02:31 +00:00
|
|
|
GST_INFO_OBJECT (context, "loop exited");
|
2013-08-14 00:44:19 +00:00
|
|
|
|
|
|
|
g_mutex_lock (&context->priv->render_lock);
|
|
|
|
context->priv->alive = FALSE;
|
|
|
|
|
2014-12-31 06:45:53 +00:00
|
|
|
gst_gl_context_activate (context, FALSE);
|
2013-08-14 00:44:19 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2015-12-21 11:13:15 +00:00
|
|
|
context->priv->created = FALSE;
|
2016-11-28 03:19:18 +00:00
|
|
|
g_cond_signal (&context->priv->destroy_cond);
|
2013-08-14 00:44:19 +00:00
|
|
|
g_mutex_unlock (&context->priv->render_lock);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
failure:
|
|
|
|
{
|
2014-09-23 02:01:04 +00:00
|
|
|
if (other_context)
|
|
|
|
gst_object_unref (other_context);
|
|
|
|
|
2015-12-21 11:13:15 +00:00
|
|
|
/* A context that fails to be created is considered created but not alive
|
|
|
|
* and will never be able to be alive as creation can't happen */
|
|
|
|
context->priv->created = TRUE;
|
2013-08-14 00:44:19 +00:00
|
|
|
g_cond_signal (&context->priv->create_cond);
|
|
|
|
g_mutex_unlock (&context->priv->render_lock);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-07-31 08:46:33 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_context_destroy:
|
|
|
|
* @context: a #GstGLContext:
|
|
|
|
*
|
|
|
|
* Destroys an OpenGL context.
|
|
|
|
*
|
|
|
|
* Should only be called after gst_gl_context_create() has been successfully
|
|
|
|
* called for this context.
|
2014-10-31 01:30:53 +00:00
|
|
|
*
|
|
|
|
* Since: 1.6
|
2014-07-31 08:46:33 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_gl_context_destroy (GstGLContext * context)
|
|
|
|
{
|
|
|
|
GstGLContextClass *context_class;
|
|
|
|
|
2015-10-19 04:15:30 +00:00
|
|
|
g_return_if_fail (GST_IS_GL_CONTEXT (context));
|
2014-07-31 08:46:33 +00:00
|
|
|
context_class = GST_GL_CONTEXT_GET_CLASS (context);
|
|
|
|
g_return_if_fail (context_class->destroy_context != NULL);
|
|
|
|
|
|
|
|
context_class->destroy_context (context);
|
|
|
|
}
|
|
|
|
|
2014-12-31 06:45:53 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_context_fill_info:
|
|
|
|
* @context: a #GstGLContext:
|
2016-11-03 01:03:24 +00:00
|
|
|
* @error: (allow-none): a #GError to fill on failure
|
2014-12-31 06:45:53 +00:00
|
|
|
*
|
|
|
|
* Fills @context's info (version, extensions, vtable, etc) from the GL
|
|
|
|
* context in the current thread. Typically used with wrapped contexts to
|
|
|
|
* allow wrapped contexts to be used as regular #GstGLContext's.
|
|
|
|
*
|
|
|
|
* Since: 1.6
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_gl_context_fill_info (GstGLContext * context, GError ** error)
|
|
|
|
{
|
|
|
|
GstGLFuncs *gl;
|
|
|
|
GString *ext_g_str = NULL;
|
|
|
|
const gchar *ext_const_c_str = NULL;
|
|
|
|
GstGLAPI gl_api;
|
|
|
|
gboolean ret;
|
|
|
|
|
2015-10-19 04:15:30 +00:00
|
|
|
g_return_val_if_fail (GST_IS_GL_CONTEXT (context), FALSE);
|
2014-12-31 06:45:53 +00:00
|
|
|
g_return_val_if_fail (context->priv->active_thread == g_thread_self (),
|
|
|
|
FALSE);
|
|
|
|
|
|
|
|
gl = context->gl_vtable;
|
|
|
|
gl_api = gst_gl_context_get_gl_api (context);
|
|
|
|
|
|
|
|
gl->GetError = gst_gl_context_get_proc_address (context, "glGetError");
|
|
|
|
gl->GetString = gst_gl_context_get_proc_address (context, "glGetString");
|
|
|
|
gl->GetStringi = gst_gl_context_get_proc_address (context, "glGetStringi");
|
|
|
|
gl->GetIntegerv = gst_gl_context_get_proc_address (context, "glGetIntegerv");
|
|
|
|
|
|
|
|
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 */
|
|
|
|
ret = _create_context_info (context, gl_api, &context->priv->gl_major,
|
|
|
|
&context->priv->gl_minor, error);
|
|
|
|
|
|
|
|
if (!ret) {
|
|
|
|
g_assert (error == NULL || *error != NULL);
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* GL core contexts and GLES3 */
|
|
|
|
if (gl->GetIntegerv && gl->GetStringi && context->priv->gl_major >= 3)
|
|
|
|
ext_g_str = _build_extension_string (context);
|
|
|
|
|
|
|
|
if (ext_g_str && ext_g_str->len) {
|
|
|
|
GST_DEBUG_OBJECT (context, "GL_EXTENSIONS: %s", ext_g_str->str);
|
|
|
|
_gst_gl_feature_check_ext_functions (context, context->priv->gl_major,
|
|
|
|
context->priv->gl_minor, ext_g_str->str);
|
|
|
|
|
|
|
|
context->priv->gl_exts = g_string_free (ext_g_str, FALSE);
|
|
|
|
} else {
|
|
|
|
ext_const_c_str = (const gchar *) gl->GetString (GL_EXTENSIONS);
|
|
|
|
if (!ext_const_c_str)
|
|
|
|
ext_const_c_str = "";
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (context, "GL_EXTENSIONS: %s", ext_const_c_str);
|
|
|
|
_gst_gl_feature_check_ext_functions (context, context->priv->gl_major,
|
|
|
|
context->priv->gl_minor, ext_const_c_str);
|
|
|
|
|
|
|
|
context->priv->gl_exts = g_strdup (ext_const_c_str);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gl_api & GST_GL_API_OPENGL3
|
|
|
|
&& !gst_gl_context_check_gl_version (context, GST_GL_API_OPENGL3, 4, 1)
|
|
|
|
&& !gst_gl_check_extension ("GL_ARB_ES2_compatibility",
|
|
|
|
context->priv->gl_exts)) {
|
|
|
|
g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_FAILED,
|
|
|
|
"An opengl3 context created but the required ES2 compatibility was not found");
|
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
|
2015-06-10 09:42:06 +00:00
|
|
|
/* Does not implement OES_vertex_array_object properly, see
|
|
|
|
* https://bugzilla.gnome.org/show_bug.cgi?id=750185 */
|
|
|
|
if (g_strcmp0 ((const gchar *) gl->GetString (GL_VENDOR),
|
|
|
|
"Imagination Technologies") == 0
|
|
|
|
&& g_strcmp0 ((const gchar *) gl->GetString (GL_RENDERER),
|
|
|
|
"PowerVR SGX 544MP") == 0) {
|
|
|
|
gl->GenVertexArrays = NULL;
|
|
|
|
gl->DeleteVertexArrays = NULL;
|
|
|
|
gl->BindVertexArray = NULL;
|
|
|
|
gl->IsVertexArray = NULL;
|
|
|
|
}
|
|
|
|
|
2014-12-31 06:45:53 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
failure:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
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
|
2014-10-31 01:30:53 +00:00
|
|
|
*
|
|
|
|
* Since: 1.4
|
2013-11-23 11:53:48 +00:00
|
|
|
*/
|
2013-08-14 00:44:19 +00:00
|
|
|
guintptr
|
|
|
|
gst_gl_context_get_gl_context (GstGLContext * context)
|
|
|
|
{
|
|
|
|
GstGLContextClass *context_class;
|
|
|
|
guintptr result;
|
|
|
|
|
2015-10-19 04:15:30 +00:00
|
|
|
g_return_val_if_fail (GST_IS_GL_CONTEXT (context), 0);
|
2013-08-14 00:44:19 +00:00
|
|
|
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
|
2014-10-31 01:30:53 +00:00
|
|
|
*
|
|
|
|
* Since: 1.4
|
2014-02-10 21:57:29 +00:00
|
|
|
*/
|
|
|
|
GstGLPlatform
|
|
|
|
gst_gl_context_get_gl_platform (GstGLContext * context)
|
|
|
|
{
|
|
|
|
GstGLContextClass *context_class;
|
|
|
|
|
2015-10-19 04:15:30 +00:00
|
|
|
g_return_val_if_fail (GST_IS_GL_CONTEXT (context), 0);
|
2014-02-10 21:57:29 +00:00
|
|
|
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:
|
|
|
|
*
|
2016-11-03 01:03:24 +00:00
|
|
|
* Returns: (transfer full): the #GstGLDisplay associated with this @context
|
2014-10-31 01:30:53 +00:00
|
|
|
*
|
|
|
|
* Since: 1.4
|
2013-11-23 11:53:48 +00:00
|
|
|
*/
|
2013-09-15 04:23:43 +00:00
|
|
|
GstGLDisplay *
|
|
|
|
gst_gl_context_get_display (GstGLContext * context)
|
|
|
|
{
|
2015-10-19 04:15:30 +00:00
|
|
|
g_return_val_if_fail (GST_IS_GL_CONTEXT (context), NULL);
|
2013-09-15 04:23:43 +00:00
|
|
|
|
2015-06-15 15:36:26 +00:00
|
|
|
return gst_object_ref (context->display);
|
2013-09-15 04:23:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GstGLContext *context;
|
|
|
|
GstGLContextThreadFunc func;
|
|
|
|
gpointer data;
|
|
|
|
} RunGenericData;
|
|
|
|
|
|
|
|
static void
|
|
|
|
_gst_gl_context_thread_run_generic (RunGenericData * data)
|
|
|
|
{
|
2015-07-15 14:33:17 +00:00
|
|
|
GST_TRACE_OBJECT (data->context, "running function:%p data:%p", data->func,
|
|
|
|
data->data);
|
2013-09-15 04:23:43 +00:00
|
|
|
|
|
|
|
data->func (data->context, data->data);
|
|
|
|
}
|
|
|
|
|
2013-11-23 11:53:48 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_context_thread_add:
|
|
|
|
* @context: a #GstGLContext
|
2016-11-03 05:14:37 +00:00
|
|
|
* @func: (scope call): a #GstGLContextThreadFunc
|
2013-11-23 11:53:48 +00:00
|
|
|
* @data: (closure): user data to call @func with
|
|
|
|
*
|
|
|
|
* Execute @func in the OpenGL thread of @context with @data
|
|
|
|
*
|
|
|
|
* MT-safe
|
2014-10-31 01:30:53 +00:00
|
|
|
*
|
|
|
|
* Since: 1.4
|
2013-11-23 11:53:48 +00:00
|
|
|
*/
|
2013-09-15 04:23:43 +00:00
|
|
|
void
|
|
|
|
gst_gl_context_thread_add (GstGLContext * context,
|
|
|
|
GstGLContextThreadFunc func, gpointer data)
|
|
|
|
{
|
|
|
|
GstGLWindow *window;
|
|
|
|
RunGenericData rdata;
|
|
|
|
|
2015-10-19 04:15:30 +00:00
|
|
|
g_return_if_fail (GST_IS_GL_CONTEXT (context));
|
2013-09-15 04:23:43 +00:00
|
|
|
g_return_if_fail (func != NULL);
|
2014-12-31 06:45:53 +00:00
|
|
|
|
2016-02-10 02:08:43 +00:00
|
|
|
if (GST_IS_GL_WRAPPED_CONTEXT (context))
|
2014-12-31 06:45:53 +00:00
|
|
|
g_return_if_fail (context->priv->active_thread == g_thread_self ());
|
2016-02-10 02:08:43 +00:00
|
|
|
|
|
|
|
if (context->priv->active_thread == g_thread_self ()) {
|
2014-12-31 06:45:53 +00:00
|
|
|
func (context, data);
|
|
|
|
return;
|
|
|
|
}
|
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
|
2019-08-29 17:42:39 +00:00
|
|
|
* gst_gl_context_get_gl_api() for retrieving the OpenGL api implemented by
|
2014-04-13 03:39:14 +00:00
|
|
|
* @context.
|
2014-10-31 01:30:53 +00:00
|
|
|
*
|
|
|
|
* Since: 1.4
|
2014-04-13 03:39:14 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_gl_context_get_gl_version (GstGLContext * context, gint * maj, gint * min)
|
|
|
|
{
|
2015-10-19 04:15:30 +00:00
|
|
|
g_return_if_fail (GST_IS_GL_CONTEXT (context));
|
2016-06-28 03:02:32 +00:00
|
|
|
g_return_if_fail (!(maj == NULL && min == NULL));
|
2014-04-13 03:39:14 +00:00
|
|
|
|
|
|
|
if (maj)
|
|
|
|
*maj = context->priv->gl_major;
|
|
|
|
|
|
|
|
if (min)
|
|
|
|
*min = context->priv->gl_minor;
|
|
|
|
}
|
2014-02-10 21:57:29 +00:00
|
|
|
|
2014-05-29 10:35:48 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_context_check_gl_version:
|
|
|
|
* @context: a #GstGLContext
|
|
|
|
* @api: api type required
|
|
|
|
* @maj: major version required
|
|
|
|
* @min: minor version required
|
|
|
|
*
|
|
|
|
* Returns: whether OpenGL context implements the required api and specified
|
|
|
|
* version.
|
2014-10-31 01:30:53 +00:00
|
|
|
*
|
|
|
|
* Since: 1.4
|
2014-05-29 10:35:48 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_gl_context_check_gl_version (GstGLContext * context, GstGLAPI api,
|
|
|
|
gint maj, gint min)
|
|
|
|
{
|
2015-10-19 04:15:30 +00:00
|
|
|
g_return_val_if_fail (GST_IS_GL_CONTEXT (context), FALSE);
|
2014-05-29 10:35:48 +00:00
|
|
|
|
|
|
|
if (maj > context->priv->gl_major)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if ((gst_gl_context_get_gl_api (context) & api) == GST_GL_API_NONE)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (maj < context->priv->gl_major)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
if (min > context->priv->gl_minor)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-05-14 07:33:21 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_context_check_feature:
|
|
|
|
* @context: a #GstGLContext
|
|
|
|
* @feature: a platform specific feature
|
|
|
|
*
|
2016-11-03 01:03:24 +00:00
|
|
|
* Check for an OpenGL @feature being supported.
|
|
|
|
*
|
|
|
|
* Note: Most 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.
|
2014-05-14 07:33:21 +00:00
|
|
|
*
|
|
|
|
* Returns: Whether @feature is supported by @context
|
2014-10-31 01:30:53 +00:00
|
|
|
*
|
|
|
|
* Since: 1.4
|
2014-05-14 07:33:21 +00:00
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_gl_context_check_feature (GstGLContext * context, const gchar * feature)
|
|
|
|
{
|
|
|
|
GstGLContextClass *context_class;
|
|
|
|
|
2015-10-19 04:15:30 +00:00
|
|
|
g_return_val_if_fail (GST_IS_GL_CONTEXT (context), FALSE);
|
2014-05-14 07:33:21 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2015-02-27 13:30:38 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_context_get_current:
|
|
|
|
*
|
|
|
|
* See also gst_gl_context_activate().
|
|
|
|
*
|
2016-11-03 05:14:37 +00:00
|
|
|
* Returns: (transfer none): the #GstGLContext active in the current thread or %NULL
|
2015-02-27 13:30:38 +00:00
|
|
|
*
|
|
|
|
* Since: 1.6
|
|
|
|
*/
|
|
|
|
GstGLContext *
|
|
|
|
gst_gl_context_get_current (void)
|
|
|
|
{
|
|
|
|
return g_private_get (¤t_context_key);
|
|
|
|
}
|
|
|
|
|
2016-01-07 03:02:52 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_context_is_shared:
|
|
|
|
* @context: a #GstGLContext
|
|
|
|
*
|
|
|
|
* Returns: Whether the #GstGLContext has been shared with another #GstGLContext
|
|
|
|
*
|
|
|
|
* Since: 1.8
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_gl_context_is_shared (GstGLContext * context)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GST_IS_GL_CONTEXT (context), FALSE);
|
2016-11-30 09:22:17 +00:00
|
|
|
|
|
|
|
if (!context->priv->sharegroup)
|
|
|
|
return FALSE;
|
|
|
|
|
2016-02-25 21:34:11 +00:00
|
|
|
if (GST_IS_GL_WRAPPED_CONTEXT (context))
|
|
|
|
g_return_val_if_fail (context->priv->active_thread, FALSE);
|
|
|
|
else
|
|
|
|
g_return_val_if_fail (context->priv->alive, FALSE);
|
2016-01-07 03:02:52 +00:00
|
|
|
|
|
|
|
return _context_share_group_is_shared (context->priv->sharegroup);
|
|
|
|
}
|
|
|
|
|
2016-02-25 21:34:11 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_context_set_shared_with:
|
|
|
|
* @context: a wrapped #GstGLContext
|
|
|
|
* @share: another #GstGLContext
|
|
|
|
*
|
|
|
|
* Will internally set @context as shared with @share
|
|
|
|
*
|
|
|
|
* Since: 1.8
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_gl_context_set_shared_with (GstGLContext * context, GstGLContext * share)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GST_IS_GL_CONTEXT (context));
|
|
|
|
g_return_if_fail (GST_IS_GL_CONTEXT (share));
|
|
|
|
g_return_if_fail (!gst_gl_context_is_shared (context));
|
|
|
|
/* XXX: may be a little too strict */
|
|
|
|
g_return_if_fail (GST_IS_GL_WRAPPED_CONTEXT (context));
|
|
|
|
|
|
|
|
if (context->priv->sharegroup)
|
|
|
|
_context_share_group_unref (context->priv->sharegroup);
|
|
|
|
context->priv->sharegroup =
|
|
|
|
_context_share_group_ref (share->priv->sharegroup);
|
|
|
|
}
|
|
|
|
|
2016-11-16 14:45:38 +00:00
|
|
|
static void
|
|
|
|
gst_gl_context_default_get_gl_platform_version (GstGLContext * context,
|
|
|
|
gint * major, gint * minor)
|
|
|
|
{
|
|
|
|
if (major)
|
|
|
|
*major = 0;
|
|
|
|
if (minor)
|
|
|
|
*minor = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_gl_context_get_gl_platform_version:
|
|
|
|
* @context: a #GstGLContext
|
|
|
|
* @major: (out): return for the major version
|
|
|
|
* @minor: (out): return for the minor version
|
|
|
|
*
|
|
|
|
* Get the version of the OpenGL platform (GLX, EGL, etc) used. Only valid
|
2018-04-02 06:34:58 +00:00
|
|
|
* after a call to gst_gl_context_create().
|
2016-11-16 14:45:38 +00:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_gl_context_get_gl_platform_version (GstGLContext * context, gint * major,
|
|
|
|
gint * minor)
|
|
|
|
{
|
|
|
|
GstGLContextClass *context_class;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_GL_CONTEXT (context));
|
|
|
|
g_return_if_fail (major != NULL);
|
|
|
|
g_return_if_fail (minor != NULL);
|
|
|
|
context_class = GST_GL_CONTEXT_GET_CLASS (context);
|
|
|
|
g_return_if_fail (context_class->get_gl_platform_version != NULL);
|
|
|
|
|
|
|
|
context_class->get_gl_platform_version (context, major, minor);
|
|
|
|
}
|
|
|
|
|
2017-05-21 10:03:01 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_context_swap_buffers:
|
|
|
|
* @context: a #GstGLContext
|
|
|
|
*
|
|
|
|
* Swap the front and back buffers on the window attached to @context.
|
|
|
|
* This will display the frame on the next refresh cycle.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_gl_context_swap_buffers (GstGLContext * context)
|
|
|
|
{
|
|
|
|
GstGLContextClass *context_class;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_GL_CONTEXT (context));
|
|
|
|
context_class = GST_GL_CONTEXT_GET_CLASS (context);
|
|
|
|
g_return_if_fail (context_class->swap_buffers != NULL);
|
|
|
|
|
|
|
|
context_class->swap_buffers (context);
|
|
|
|
}
|
|
|
|
|
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)
|
|
|
|
{
|
2017-02-23 23:42:08 +00:00
|
|
|
if (activate) {
|
|
|
|
GThread *old_thread = context->priv->gl_thread;
|
|
|
|
context->priv->gl_thread = g_thread_ref (g_thread_self ());
|
|
|
|
if (old_thread) {
|
|
|
|
g_thread_unref (old_thread);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (context->priv->gl_thread) {
|
|
|
|
g_thread_unref (context->priv->gl_thread);
|
|
|
|
context->priv->gl_thread = NULL;
|
|
|
|
}
|
|
|
|
}
|
2014-02-10 21:57:29 +00:00
|
|
|
|
2014-12-31 06:45:53 +00:00
|
|
|
return TRUE;
|
2014-02-10 21:57:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
}
|
2019-02-28 09:31:40 +00:00
|
|
|
|
|
|
|
G_GNUC_INTERNAL gboolean
|
|
|
|
_gst_gl_context_debug_is_enabled (GstGLContext * context)
|
|
|
|
{
|
|
|
|
#if !defined(GST_DISABLE_GST_DEBUG)
|
|
|
|
GstDebugLevel level;
|
|
|
|
|
|
|
|
level = gst_debug_category_get_threshold (gst_gl_debug);
|
|
|
|
|
|
|
|
if (level < GST_LEVEL_WARNING) {
|
|
|
|
GST_CAT_INFO_OBJECT (gst_gl_context_debug, context, "Disabling GL context "
|
|
|
|
"debugging (gldebug category debug level < warning)");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
#else
|
|
|
|
return FALSE;
|
|
|
|
#endif
|
|
|
|
}
|