2008-06-19 23:38:36 +00:00
|
|
|
/*
|
2008-05-19 16:57:39 +00:00
|
|
|
* GStreamer
|
2008-09-20 13:44:24 +00:00
|
|
|
* Copyright (C) 2007 David A. Schleef <ds@schleef.org>
|
2008-05-19 16:57:39 +00:00
|
|
|
* Copyright (C) 2008 Julien Isorce <julien.isorce@gmail.com>
|
2008-08-11 07:52:16 +00:00
|
|
|
* Copyright (C) 2008 Filippo Argiolas <filippo.argiolas@gmail.com>
|
2013-06-13 07:57:35 +00:00
|
|
|
* Copyright (C) 2013 Matthew Waters <ystreet00@gmail.com>
|
2008-05-19 16:57:39 +00:00
|
|
|
*
|
|
|
|
* 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
|
2012-11-08 11:53:56 +00:00
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
2008-05-19 16:57:39 +00:00
|
|
|
*/
|
|
|
|
|
2013-11-23 11:54:46 +00:00
|
|
|
/**
|
|
|
|
* SECTION:gstgldisplay
|
|
|
|
* @short_description: window system display connection abstraction
|
|
|
|
* @title: GstGLDisplay
|
|
|
|
* @see_also: #GstContext, #GstGLContext, #GstGLWindow
|
|
|
|
*
|
|
|
|
* #GstGLDisplay represents a connection to the underlying windowing system.
|
|
|
|
* Elements are required to make use of #GstContext to share and propogate
|
|
|
|
* a #GstGLDisplay.
|
2014-06-24 13:33:30 +00:00
|
|
|
*
|
2014-08-01 06:41:13 +00:00
|
|
|
* There are a number of environment variables that influence the choice of
|
|
|
|
* platform and window system specific functionality.
|
|
|
|
* - GST_GL_WINDOW influences the window system to use. Common values are
|
|
|
|
* 'x11', 'wayland', 'win32' or 'cocoa'.
|
|
|
|
* - GST_GL_PLATFORM influences the OpenGL platform to use. Common values are
|
|
|
|
* 'egl', 'glx', 'wgl' or 'cgl'.
|
2014-08-01 07:51:08 +00:00
|
|
|
* - GST_GL_API influences the OpenGL API requested by the OpenGL platform.
|
2014-08-01 06:41:13 +00:00
|
|
|
* Common values are 'opengl' and 'gles2'.
|
|
|
|
*
|
2014-06-24 13:33:30 +00:00
|
|
|
* <note>Certain window systems require a special function to be called to
|
|
|
|
* initialize threading support. As this GStreamer GL library does not preclude
|
|
|
|
* concurrent access to the windowing system, it is strongly advised that
|
|
|
|
* applications ensure that threading support has been initialized before any
|
|
|
|
* other toolkit/library functionality is accessed. Failure to do so could
|
|
|
|
* result in sudden application abortion during execution. The most notably
|
|
|
|
* example of such a function is X11's XInitThreads().</note>
|
2013-11-23 11:54:46 +00:00
|
|
|
*/
|
|
|
|
|
2008-05-18 11:12:46 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2013-07-10 15:03:04 +00:00
|
|
|
#include "gl.h"
|
2013-01-16 04:21:44 +00:00
|
|
|
#include "gstgldisplay.h"
|
2009-08-03 15:52:31 +00:00
|
|
|
|
2015-03-11 00:06:55 +00:00
|
|
|
#if GST_GL_HAVE_WINDOW_COCOA
|
|
|
|
#include <gst/gl/cocoa/gstgldisplay_cocoa.h>
|
|
|
|
#endif
|
2013-11-27 06:52:46 +00:00
|
|
|
#if GST_GL_HAVE_WINDOW_X11
|
|
|
|
#include <gst/gl/x11/gstgldisplay_x11.h>
|
|
|
|
#endif
|
2015-05-21 07:48:31 +00:00
|
|
|
#if GST_GL_HAVE_WINDOW_WAYLAND
|
|
|
|
#include <gst/gl/wayland/gstgldisplay_wayland.h>
|
|
|
|
#endif
|
2014-03-17 09:56:39 +00:00
|
|
|
#if GST_GL_HAVE_PLATFORM_EGL
|
|
|
|
#include <gst/gl/egl/gstgldisplay_egl.h>
|
2014-03-22 22:01:49 +00:00
|
|
|
#include <gst/gl/egl/gsteglimagememory.h>
|
2014-03-17 09:56:39 +00:00
|
|
|
#endif
|
2013-11-27 06:52:46 +00:00
|
|
|
|
2013-11-12 23:43:16 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (gst_context);
|
2008-09-13 01:32:04 +00:00
|
|
|
GST_DEBUG_CATEGORY_STATIC (gst_gl_display_debug);
|
|
|
|
#define GST_CAT_DEFAULT gst_gl_display_debug
|
|
|
|
|
2012-05-30 03:46:21 +00:00
|
|
|
#define DEBUG_INIT \
|
2013-11-12 23:43:16 +00:00
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_gl_display_debug, "gldisplay", 0, "opengl display"); \
|
|
|
|
GST_DEBUG_CATEGORY_GET (gst_context, "GST_CONTEXT");
|
2008-09-13 01:32:04 +00:00
|
|
|
|
2014-05-08 05:30:49 +00:00
|
|
|
G_DEFINE_TYPE_WITH_CODE (GstGLDisplay, gst_gl_display, GST_TYPE_OBJECT,
|
2009-02-11 06:39:14 +00:00
|
|
|
DEBUG_INIT);
|
2012-12-06 07:40:26 +00:00
|
|
|
|
|
|
|
#define GST_GL_DISPLAY_GET_PRIVATE(o) \
|
2013-06-13 07:57:35 +00:00
|
|
|
(G_TYPE_INSTANCE_GET_PRIVATE((o), GST_TYPE_GL_DISPLAY, GstGLDisplayPrivate))
|
2012-12-06 07:40:26 +00:00
|
|
|
|
2015-06-15 15:09:54 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
SIGNAL_0,
|
|
|
|
CREATE_CONTEXT,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
static guint gst_gl_display_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
static void gst_gl_display_finalize (GObject * object);
|
2013-11-27 06:52:46 +00:00
|
|
|
static guintptr gst_gl_display_default_get_handle (GstGLDisplay * display);
|
2008-06-29 17:27:43 +00:00
|
|
|
|
2012-12-06 07:40:26 +00:00
|
|
|
struct _GstGLDisplayPrivate
|
|
|
|
{
|
2014-11-27 10:05:45 +00:00
|
|
|
GstGLAPI gl_api;
|
2015-03-03 06:26:47 +00:00
|
|
|
|
|
|
|
GList *contexts;
|
2012-12-06 07:40:26 +00:00
|
|
|
};
|
|
|
|
|
2008-05-18 11:12:46 +00:00
|
|
|
static void
|
|
|
|
gst_gl_display_class_init (GstGLDisplayClass * klass)
|
2008-06-19 23:38:36 +00:00
|
|
|
{
|
2012-12-06 07:40:26 +00:00
|
|
|
g_type_class_add_private (klass, sizeof (GstGLDisplayPrivate));
|
|
|
|
|
2015-06-15 15:09:54 +00:00
|
|
|
/**
|
|
|
|
* GstGLDisplay::create-context:
|
|
|
|
* @object: the #GstGLDisplay
|
|
|
|
* @context: other context to share resources with.
|
|
|
|
*
|
|
|
|
* Overrides the @GstGLContext creation mechanism.
|
|
|
|
* It can be called in any thread and it is emitted with
|
|
|
|
* display's object lock held.
|
|
|
|
*
|
|
|
|
* Returns: the new context.
|
|
|
|
*/
|
|
|
|
gst_gl_display_signals[CREATE_CONTEXT] =
|
|
|
|
g_signal_new ("create-context", G_TYPE_FROM_CLASS (klass),
|
|
|
|
G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_marshal_generic,
|
|
|
|
GST_GL_TYPE_CONTEXT, 1, GST_GL_TYPE_CONTEXT);
|
|
|
|
|
2013-11-27 06:52:46 +00:00
|
|
|
klass->get_handle = gst_gl_display_default_get_handle;
|
|
|
|
|
2008-08-01 09:00:49 +00:00
|
|
|
G_OBJECT_CLASS (klass)->finalize = gst_gl_display_finalize;
|
2008-05-18 11:12:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-05-30 03:46:21 +00:00
|
|
|
gst_gl_display_init (GstGLDisplay * display)
|
2008-05-18 11:12:46 +00:00
|
|
|
{
|
2012-12-06 07:40:26 +00:00
|
|
|
display->priv = GST_GL_DISPLAY_GET_PRIVATE (display);
|
|
|
|
|
2014-01-14 23:21:56 +00:00
|
|
|
display->type = GST_GL_DISPLAY_TYPE_ANY;
|
2014-11-27 10:05:45 +00:00
|
|
|
display->priv->gl_api = GST_GL_API_ANY;
|
2013-06-13 07:57:35 +00:00
|
|
|
|
2013-11-12 23:43:16 +00:00
|
|
|
GST_TRACE ("init %p", display);
|
|
|
|
|
2015-06-10 06:36:15 +00:00
|
|
|
gst_gl_base_buffer_init_once ();
|
2012-09-16 11:23:09 +00:00
|
|
|
gst_gl_memory_init ();
|
2014-03-22 22:01:49 +00:00
|
|
|
|
|
|
|
#if GST_GL_HAVE_PLATFORM_EGL
|
|
|
|
gst_egl_image_memory_init ();
|
|
|
|
#endif
|
2008-05-18 11:12:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2009-02-11 06:39:14 +00:00
|
|
|
gst_gl_display_finalize (GObject * object)
|
2008-05-18 11:12:46 +00:00
|
|
|
{
|
2015-03-03 06:26:47 +00:00
|
|
|
GstGLDisplay *display = GST_GL_DISPLAY (object);
|
|
|
|
GList *l;
|
|
|
|
|
2015-02-12 14:02:31 +00:00
|
|
|
GST_TRACE_OBJECT (object, "finalizing");
|
2013-11-12 23:43:16 +00:00
|
|
|
|
2015-03-03 06:26:47 +00:00
|
|
|
for (l = display->priv->contexts; l; l = l->next) {
|
|
|
|
g_weak_ref_clear ((GWeakRef *) l->data);
|
|
|
|
g_free (l->data);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free (display->priv->contexts);
|
|
|
|
|
2013-06-12 13:17:30 +00:00
|
|
|
G_OBJECT_CLASS (gst_gl_display_parent_class)->finalize (object);
|
2008-06-29 17:27:43 +00:00
|
|
|
}
|
|
|
|
|
2014-01-14 23:21:56 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_display_new:
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): a new #GstGLDisplay
|
2014-10-31 01:30:53 +00:00
|
|
|
*
|
|
|
|
* Since: 1.4
|
2014-01-14 23:21:56 +00:00
|
|
|
*/
|
2013-08-14 00:44:19 +00:00
|
|
|
GstGLDisplay *
|
|
|
|
gst_gl_display_new (void)
|
|
|
|
{
|
2013-11-27 06:52:46 +00:00
|
|
|
GstGLDisplay *display = NULL;
|
2014-05-06 06:31:28 +00:00
|
|
|
const gchar *user_choice, *platform_choice;
|
2013-11-27 06:52:46 +00:00
|
|
|
static volatile gsize _init = 0;
|
|
|
|
|
|
|
|
if (g_once_init_enter (&_init)) {
|
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_gl_display_debug, "gldisplay", 0,
|
|
|
|
"gldisplay element");
|
|
|
|
g_once_init_leave (&_init, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
user_choice = g_getenv ("GST_GL_WINDOW");
|
2014-05-06 06:31:28 +00:00
|
|
|
platform_choice = g_getenv ("GST_GL_PLATFORM");
|
2014-05-08 20:49:33 +00:00
|
|
|
GST_INFO ("creating a display, user choice:%s (platform: %s)",
|
|
|
|
GST_STR_NULL (user_choice), GST_STR_NULL (platform_choice));
|
2013-11-27 06:52:46 +00:00
|
|
|
|
2014-05-06 07:08:18 +00:00
|
|
|
#if GST_GL_HAVE_WINDOW_COCOA
|
2015-03-11 00:06:55 +00:00
|
|
|
if (!display && (!user_choice || g_strstr_len (user_choice, 5, "cocoa"))) {
|
|
|
|
display = GST_GL_DISPLAY (gst_gl_display_cocoa_new ());
|
|
|
|
if (!display)
|
|
|
|
return NULL;
|
|
|
|
}
|
2014-05-06 07:08:18 +00:00
|
|
|
#endif
|
2013-11-27 06:52:46 +00:00
|
|
|
#if GST_GL_HAVE_WINDOW_X11
|
|
|
|
if (!display && (!user_choice || g_strstr_len (user_choice, 3, "x11")))
|
|
|
|
display = GST_GL_DISPLAY (gst_gl_display_x11_new (NULL));
|
2014-03-17 09:56:39 +00:00
|
|
|
#endif
|
2014-06-05 08:43:30 +00:00
|
|
|
#if GST_GL_HAVE_WINDOW_WAYLAND
|
|
|
|
if (!display && (!user_choice || g_strstr_len (user_choice, 7, "wayland")))
|
2015-05-21 07:48:31 +00:00
|
|
|
display = GST_GL_DISPLAY (gst_gl_display_wayland_new (NULL));
|
2014-06-05 08:43:30 +00:00
|
|
|
#endif
|
2014-03-17 09:56:39 +00:00
|
|
|
#if GST_GL_HAVE_PLATFORM_EGL
|
2014-05-06 06:31:28 +00:00
|
|
|
if (!display && (!platform_choice
|
|
|
|
|| g_strstr_len (platform_choice, 3, "egl")))
|
2014-03-17 09:56:39 +00:00
|
|
|
display = GST_GL_DISPLAY (gst_gl_display_egl_new ());
|
2013-11-27 06:52:46 +00:00
|
|
|
#endif
|
|
|
|
if (!display) {
|
|
|
|
/* subclass returned a NULL window */
|
2014-05-08 20:49:33 +00:00
|
|
|
GST_WARNING ("Could not create display. user specified %s "
|
|
|
|
"(platform: %s), creating dummy",
|
|
|
|
GST_STR_NULL (user_choice), GST_STR_NULL (platform_choice));
|
2013-11-27 06:52:46 +00:00
|
|
|
|
|
|
|
return g_object_new (GST_TYPE_GL_DISPLAY, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
return display;
|
2013-08-14 00:44:19 +00:00
|
|
|
}
|
|
|
|
|
2013-11-27 06:52:46 +00:00
|
|
|
guintptr
|
|
|
|
gst_gl_display_get_handle (GstGLDisplay * display)
|
|
|
|
{
|
|
|
|
GstGLDisplayClass *klass;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_GL_DISPLAY (display), 0);
|
|
|
|
klass = GST_GL_DISPLAY_GET_CLASS (display);
|
|
|
|
g_return_val_if_fail (klass->get_handle != NULL, 0);
|
|
|
|
|
|
|
|
return klass->get_handle (display);
|
|
|
|
}
|
|
|
|
|
|
|
|
static guintptr
|
|
|
|
gst_gl_display_default_get_handle (GstGLDisplay * display)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-11-27 10:05:45 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_display_filter_gl_api:
|
|
|
|
* @display: a #GstGLDisplay
|
2015-03-18 17:12:49 +00:00
|
|
|
* @gl_api: a #GstGLAPI to filter with
|
2014-11-27 10:05:45 +00:00
|
|
|
*
|
|
|
|
* limit the use of OpenGL to the requested @gl_api. This is intended to allow
|
|
|
|
* application and elements to request a specific set of OpenGL API's based on
|
|
|
|
* what they support. See gst_gl_context_get_gl_api() for the retreiving the
|
|
|
|
* API supported by a #GstGLContext.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_gl_display_filter_gl_api (GstGLDisplay * display, GstGLAPI gl_api)
|
|
|
|
{
|
|
|
|
gchar *gl_api_s;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_GL_DISPLAY (display));
|
|
|
|
|
|
|
|
gl_api_s = gst_gl_api_to_string (gl_api);
|
|
|
|
GST_TRACE_OBJECT (display, "filtering with api %s", gl_api_s);
|
|
|
|
g_free (gl_api_s);
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (display);
|
|
|
|
display->priv->gl_api &= gl_api;
|
|
|
|
GST_OBJECT_UNLOCK (display);
|
|
|
|
}
|
|
|
|
|
2015-04-21 02:19:46 +00:00
|
|
|
GstGLAPI
|
|
|
|
gst_gl_display_get_gl_api_unlocked (GstGLDisplay * display)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GST_IS_GL_DISPLAY (display), GST_GL_API_NONE);
|
|
|
|
|
|
|
|
return display->priv->gl_api;
|
|
|
|
}
|
|
|
|
|
2014-11-27 10:05:45 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_display_get_gl_api:
|
|
|
|
* @display: a #GstGLDisplay
|
|
|
|
*
|
|
|
|
* see gst_gl_display_filter_gl_api() for what the returned value represents
|
|
|
|
*
|
|
|
|
* Returns: the #GstGLAPI configured for @display
|
|
|
|
*/
|
|
|
|
GstGLAPI
|
|
|
|
gst_gl_display_get_gl_api (GstGLDisplay * display)
|
|
|
|
{
|
|
|
|
GstGLAPI ret;
|
|
|
|
|
2014-11-27 23:03:18 +00:00
|
|
|
g_return_val_if_fail (GST_IS_GL_DISPLAY (display), GST_GL_API_NONE);
|
2014-11-27 10:05:45 +00:00
|
|
|
|
|
|
|
GST_OBJECT_LOCK (display);
|
|
|
|
ret = display->priv->gl_api;
|
|
|
|
GST_OBJECT_UNLOCK (display);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-05-06 07:27:15 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_display_get_handle_type:
|
|
|
|
* @display: a #GstGLDisplay
|
|
|
|
*
|
|
|
|
* Returns: the #GstGLDisplayType of @display
|
2014-10-31 01:30:53 +00:00
|
|
|
*
|
|
|
|
* Since: 1.4
|
2014-05-06 07:27:15 +00:00
|
|
|
*/
|
|
|
|
GstGLDisplayType
|
|
|
|
gst_gl_display_get_handle_type (GstGLDisplay * display)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GST_IS_GL_DISPLAY (display), GST_GL_DISPLAY_TYPE_NONE);
|
|
|
|
|
|
|
|
return display->type;
|
|
|
|
}
|
|
|
|
|
2013-11-23 11:54:46 +00:00
|
|
|
/**
|
|
|
|
* gst_context_set_gl_display:
|
|
|
|
* @context: a #GstContext
|
|
|
|
* @display: resulting #GstGLDisplay
|
|
|
|
*
|
|
|
|
* Sets @display on @context
|
2014-10-31 01:30:53 +00:00
|
|
|
*
|
|
|
|
* Since: 1.4
|
2013-11-23 11:54:46 +00:00
|
|
|
*/
|
2013-06-13 07:57:35 +00:00
|
|
|
void
|
|
|
|
gst_context_set_gl_display (GstContext * context, GstGLDisplay * display)
|
|
|
|
{
|
|
|
|
GstStructure *s;
|
|
|
|
|
2013-11-12 23:43:16 +00:00
|
|
|
g_return_if_fail (context != NULL);
|
|
|
|
|
2015-03-05 18:09:49 +00:00
|
|
|
if (display)
|
|
|
|
GST_CAT_LOG (gst_context,
|
|
|
|
"setting GstGLDisplay(%" GST_PTR_FORMAT ") on context(%" GST_PTR_FORMAT
|
|
|
|
")", display, context);
|
2013-11-12 23:43:16 +00:00
|
|
|
|
2013-06-13 07:57:35 +00:00
|
|
|
s = gst_context_writable_structure (context);
|
|
|
|
gst_structure_set (s, GST_GL_DISPLAY_CONTEXT_TYPE, GST_TYPE_GL_DISPLAY,
|
|
|
|
display, NULL);
|
|
|
|
}
|
|
|
|
|
2013-11-23 11:54:46 +00:00
|
|
|
/**
|
|
|
|
* gst_context_get_gl_display:
|
|
|
|
* @context: a #GstContext
|
|
|
|
* @display: resulting #GstGLDisplay
|
|
|
|
*
|
|
|
|
* Returns: Whether @display was in @context
|
2014-10-31 01:30:53 +00:00
|
|
|
*
|
|
|
|
* Since: 1.4
|
2013-11-23 11:54:46 +00:00
|
|
|
*/
|
2013-06-13 07:57:35 +00:00
|
|
|
gboolean
|
|
|
|
gst_context_get_gl_display (GstContext * context, GstGLDisplay ** display)
|
|
|
|
{
|
|
|
|
const GstStructure *s;
|
2013-11-12 23:43:16 +00:00
|
|
|
gboolean ret;
|
|
|
|
|
|
|
|
g_return_val_if_fail (display != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (context != NULL, FALSE);
|
2013-06-13 07:57:35 +00:00
|
|
|
|
|
|
|
s = gst_context_get_structure (context);
|
2013-11-12 23:43:16 +00:00
|
|
|
ret = gst_structure_get (s, GST_GL_DISPLAY_CONTEXT_TYPE,
|
2013-06-13 07:57:35 +00:00
|
|
|
GST_TYPE_GL_DISPLAY, display, NULL);
|
2013-11-12 23:43:16 +00:00
|
|
|
|
|
|
|
GST_CAT_LOG (gst_context, "got GstGLDisplay(%p) from context(%p)", *display,
|
|
|
|
context);
|
|
|
|
|
|
|
|
return ret;
|
2013-06-12 13:17:30 +00:00
|
|
|
}
|
2015-03-03 06:26:47 +00:00
|
|
|
|
2015-06-15 15:09:54 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_display_create_context:
|
|
|
|
* @display: a #GstGLDisplay
|
|
|
|
* @other_context: other #GstGLContext to share resources with.
|
|
|
|
* @p_context: resulting #GstGLContext
|
|
|
|
* @error: resulting #GError
|
|
|
|
*
|
|
|
|
* It requires the display's object lock to be held.
|
|
|
|
*
|
|
|
|
* Returns: whether a new context could be created.
|
|
|
|
*
|
|
|
|
* Since: 1.6
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_gl_display_create_context (GstGLDisplay * display,
|
|
|
|
GstGLContext * other_context, GstGLContext ** p_context, GError ** error)
|
|
|
|
{
|
|
|
|
GstGLContext *context = NULL;
|
|
|
|
gboolean ret = FALSE;
|
|
|
|
|
|
|
|
g_return_val_if_fail (display != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (p_context != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (error != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (*error == NULL, FALSE);
|
|
|
|
|
|
|
|
g_signal_emit (display, gst_gl_display_signals[CREATE_CONTEXT], 0,
|
|
|
|
other_context, &context);
|
|
|
|
|
|
|
|
if (context) {
|
|
|
|
*p_context = context;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
context = gst_gl_context_new (display);
|
|
|
|
if (!context) {
|
|
|
|
g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_FAILED,
|
|
|
|
"Failed to create GL context");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (display,
|
|
|
|
"creating context %" GST_PTR_FORMAT " from other context %"
|
|
|
|
GST_PTR_FORMAT, context, other_context);
|
|
|
|
|
|
|
|
ret = gst_gl_context_create (context, other_context, error);
|
|
|
|
|
|
|
|
if (ret)
|
|
|
|
*p_context = context;
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-03-03 06:26:47 +00:00
|
|
|
static GstGLContext *
|
|
|
|
_get_gl_context_for_thread_unlocked (GstGLDisplay * display, GThread * thread)
|
|
|
|
{
|
|
|
|
GstGLContext *context = NULL;
|
|
|
|
GList *prev = NULL, *l = display->priv->contexts;
|
|
|
|
|
|
|
|
while (l) {
|
|
|
|
GWeakRef *ref = l->data;
|
|
|
|
GThread *context_thread;
|
|
|
|
|
|
|
|
context = g_weak_ref_get (ref);
|
|
|
|
if (!context) {
|
|
|
|
/* remove dead contexts */
|
|
|
|
g_weak_ref_clear (l->data);
|
|
|
|
display->priv->contexts = g_list_delete_link (display->priv->contexts, l);
|
|
|
|
l = prev ? prev->next : display->priv->contexts;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
context_thread = gst_gl_context_get_thread (context);
|
|
|
|
if (thread != NULL && thread == context_thread) {
|
|
|
|
g_thread_unref (context_thread);
|
|
|
|
gst_object_unref (context);
|
|
|
|
prev = l;
|
|
|
|
l = l->next;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (context_thread)
|
|
|
|
g_thread_unref (context_thread);
|
|
|
|
return context;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_gl_display_get_gl_context_for_thread:
|
|
|
|
* @display: a #GstGLDisplay
|
|
|
|
* @thread: a #GThread
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): the #GstGLContext current on @thread or %NULL
|
|
|
|
*
|
2015-04-21 02:19:46 +00:00
|
|
|
* Must be called with the object lock held.
|
|
|
|
*
|
2015-03-03 06:26:47 +00:00
|
|
|
* Since: 1.6
|
|
|
|
*/
|
|
|
|
GstGLContext *
|
|
|
|
gst_gl_display_get_gl_context_for_thread (GstGLDisplay * display,
|
|
|
|
GThread * thread)
|
|
|
|
{
|
|
|
|
GstGLContext *context;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_GL_DISPLAY (display), NULL);
|
|
|
|
|
|
|
|
context = _get_gl_context_for_thread_unlocked (display, thread);
|
|
|
|
GST_DEBUG_OBJECT (display, "returning context %" GST_PTR_FORMAT " for thread "
|
|
|
|
"%p", context, thread);
|
|
|
|
|
|
|
|
return context;
|
|
|
|
}
|
|
|
|
|
2015-03-15 12:58:26 +00:00
|
|
|
static gboolean
|
|
|
|
_check_collision (GstGLContext * context, GstGLContext * collision)
|
|
|
|
{
|
|
|
|
GThread *thread, *collision_thread;
|
|
|
|
gboolean ret = FALSE;
|
|
|
|
|
|
|
|
if (!context || !collision)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
thread = gst_gl_context_get_thread (context);
|
|
|
|
collision_thread = gst_gl_context_get_thread (collision);
|
|
|
|
|
|
|
|
if (!thread || !collision_thread) {
|
|
|
|
ret = FALSE;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (collision == context) {
|
|
|
|
ret = TRUE;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
if (thread)
|
|
|
|
g_thread_unref (thread);
|
|
|
|
if (collision_thread)
|
|
|
|
g_thread_unref (collision_thread);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-03-03 06:26:47 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_display_add_context:
|
|
|
|
* @display: a #GstGLDisplay
|
|
|
|
* @context: (transfer none): a #GstGLContext
|
|
|
|
*
|
|
|
|
* Returns: whether @context was successfully added. %FALSE may be returned
|
|
|
|
* if there already exists another context for @context's active thread.
|
|
|
|
*
|
2015-04-21 02:19:46 +00:00
|
|
|
* Must be called with the object lock held.
|
|
|
|
*
|
2015-03-03 06:26:47 +00:00
|
|
|
* Since: 1.6
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_gl_display_add_context (GstGLDisplay * display, GstGLContext * context)
|
|
|
|
{
|
2015-03-15 12:58:26 +00:00
|
|
|
GstGLContext *collision = NULL;
|
2015-03-03 06:26:47 +00:00
|
|
|
GstGLDisplay *context_display;
|
|
|
|
gboolean ret = TRUE;
|
|
|
|
GThread *thread;
|
|
|
|
GWeakRef *ref;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_GL_DISPLAY (display), FALSE);
|
2015-10-19 04:15:30 +00:00
|
|
|
g_return_val_if_fail (GST_IS_GL_CONTEXT (context), FALSE);
|
2015-03-03 06:26:47 +00:00
|
|
|
|
|
|
|
context_display = gst_gl_context_get_display (context);
|
|
|
|
g_assert (context_display == display);
|
|
|
|
gst_object_unref (context_display);
|
|
|
|
|
|
|
|
thread = gst_gl_context_get_thread (context);
|
|
|
|
if (thread) {
|
2015-03-15 12:58:26 +00:00
|
|
|
collision = _get_gl_context_for_thread_unlocked (display, thread);
|
2015-03-22 18:03:19 +00:00
|
|
|
g_thread_unref (thread);
|
2015-03-15 12:58:26 +00:00
|
|
|
if (_check_collision (context, collision)) {
|
|
|
|
ret = FALSE;
|
|
|
|
goto out;
|
2015-03-03 06:26:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ref = g_new0 (GWeakRef, 1);
|
|
|
|
g_weak_ref_init (ref, context);
|
|
|
|
|
|
|
|
display->priv->contexts = g_list_prepend (display->priv->contexts, ref);
|
|
|
|
|
|
|
|
out:
|
2015-03-15 12:58:26 +00:00
|
|
|
if (collision)
|
|
|
|
gst_object_unref (collision);
|
|
|
|
|
2015-03-03 06:26:47 +00:00
|
|
|
GST_DEBUG_OBJECT (display, "%ssuccessfully inserted context %" GST_PTR_FORMAT,
|
|
|
|
ret ? "" : "un", context);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|