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
|
|
|
|
*
|
2017-03-08 18:01:13 +00:00
|
|
|
* #GstGLDisplay represents a connection to the underlying windowing system.
|
2019-08-29 17:42:39 +00:00
|
|
|
* Elements are required to make use of #GstContext to share and propagate
|
2013-11-23 11:54:46 +00:00
|
|
|
* 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
|
2023-10-19 12:10:16 +00:00
|
|
|
* 'x11', 'wayland', 'surfaceless', 'win32' or 'cocoa'.
|
2014-08-01 06:41:13 +00:00
|
|
|
* - 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.
|
2017-12-02 20:25:16 +00:00
|
|
|
* Common values are 'opengl', 'opengl3' and 'gles2'.
|
2014-08-01 06:41:13 +00:00
|
|
|
*
|
2017-03-08 18:01:13 +00:00
|
|
|
* > 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\().
|
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>
|
2019-04-04 08:41:13 +00:00
|
|
|
#include <gst/gl/egl/gstgldisplay_egl_device.h>
|
2016-05-04 02:17:59 +00:00
|
|
|
#include <gst/gl/egl/gsteglimage.h>
|
2016-01-21 13:18:17 +00:00
|
|
|
#include <gst/gl/egl/gstglmemoryegl.h>
|
2014-03-17 09:56:39 +00:00
|
|
|
#endif
|
2017-02-17 10:24:58 +00:00
|
|
|
#if GST_GL_HAVE_WINDOW_VIV_FB
|
|
|
|
#include <gst/gl/viv-fb/gstgldisplay_viv_fb.h>
|
|
|
|
#endif
|
2018-02-23 18:59:45 +00:00
|
|
|
#if GST_GL_HAVE_WINDOW_GBM
|
|
|
|
#include <gst/gl/gbm/gstgldisplay_gbm.h>
|
|
|
|
#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
|
|
|
|
|
2015-06-15 15:09:54 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
SIGNAL_0,
|
|
|
|
CREATE_CONTEXT,
|
|
|
|
LAST_SIGNAL
|
|
|
|
};
|
|
|
|
|
|
|
|
static guint gst_gl_display_signals[LAST_SIGNAL] = { 0 };
|
|
|
|
|
2016-06-30 13:04:16 +00:00
|
|
|
|
|
|
|
static void gst_gl_display_dispose (GObject * object);
|
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);
|
2016-06-30 13:12:33 +00:00
|
|
|
static GstGLWindow *gst_gl_display_default_create_window (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;
|
2016-06-30 13:04:16 +00:00
|
|
|
|
|
|
|
GThread *event_thread;
|
|
|
|
|
|
|
|
GMutex thread_lock;
|
|
|
|
GCond thread_cond;
|
2019-11-02 13:46:49 +00:00
|
|
|
|
|
|
|
GMutex window_lock;
|
2012-12-06 07:40:26 +00:00
|
|
|
};
|
|
|
|
|
2018-06-23 19:33:16 +00:00
|
|
|
#define DEBUG_INIT \
|
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_gl_display_debug, "gldisplay", 0, "opengl display"); \
|
|
|
|
GST_DEBUG_CATEGORY_GET (gst_context, "GST_CONTEXT");
|
|
|
|
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GstGLDisplay, gst_gl_display, GST_TYPE_OBJECT,
|
|
|
|
G_ADD_PRIVATE (GstGLDisplay)
|
|
|
|
DEBUG_INIT);
|
|
|
|
|
2016-06-30 13:04:16 +00:00
|
|
|
static gboolean
|
|
|
|
_unlock_main_thread (GstGLDisplay * display)
|
|
|
|
{
|
|
|
|
g_mutex_unlock (&display->priv->thread_lock);
|
|
|
|
|
|
|
|
return G_SOURCE_REMOVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gpointer
|
|
|
|
_event_thread_main (GstGLDisplay * display)
|
|
|
|
{
|
|
|
|
g_mutex_lock (&display->priv->thread_lock);
|
|
|
|
|
|
|
|
display->main_context = g_main_context_new ();
|
|
|
|
display->main_loop = g_main_loop_new (display->main_context, FALSE);
|
|
|
|
|
|
|
|
g_main_context_invoke (display->main_context,
|
|
|
|
(GSourceFunc) _unlock_main_thread, display);
|
|
|
|
|
|
|
|
g_cond_broadcast (&display->priv->thread_cond);
|
|
|
|
|
|
|
|
g_main_loop_run (display->main_loop);
|
|
|
|
|
|
|
|
g_mutex_lock (&display->priv->thread_lock);
|
|
|
|
g_main_loop_unref (display->main_loop);
|
|
|
|
g_main_context_unref (display->main_context);
|
|
|
|
|
|
|
|
display->main_loop = NULL;
|
|
|
|
display->main_context = NULL;
|
|
|
|
|
|
|
|
g_cond_broadcast (&display->priv->thread_cond);
|
|
|
|
g_mutex_unlock (&display->priv->thread_lock);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
{
|
2015-06-15 15:09:54 +00:00
|
|
|
/**
|
|
|
|
* GstGLDisplay::create-context:
|
|
|
|
* @object: the #GstGLDisplay
|
2016-11-03 05:14:37 +00:00
|
|
|
* @context: (transfer none): other context to share resources with.
|
2015-06-15 15:09:54 +00:00
|
|
|
*
|
|
|
|
* Overrides the @GstGLContext creation mechanism.
|
|
|
|
* It can be called in any thread and it is emitted with
|
|
|
|
* display's object lock held.
|
|
|
|
*
|
2022-10-15 09:16:01 +00:00
|
|
|
* Returns: (transfer full) (nullable): the new context.
|
2015-06-15 15:09:54 +00:00
|
|
|
*/
|
|
|
|
gst_gl_display_signals[CREATE_CONTEXT] =
|
|
|
|
g_signal_new ("create-context", G_TYPE_FROM_CLASS (klass),
|
2019-08-26 05:54:48 +00:00
|
|
|
G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, GST_TYPE_GL_CONTEXT, 1,
|
|
|
|
GST_TYPE_GL_CONTEXT);
|
2015-06-15 15:09:54 +00:00
|
|
|
|
2013-11-27 06:52:46 +00:00
|
|
|
klass->get_handle = gst_gl_display_default_get_handle;
|
2016-06-30 13:12:33 +00:00
|
|
|
klass->create_window = gst_gl_display_default_create_window;
|
2013-11-27 06:52:46 +00:00
|
|
|
|
2008-08-01 09:00:49 +00:00
|
|
|
G_OBJECT_CLASS (klass)->finalize = gst_gl_display_finalize;
|
2016-06-30 13:04:16 +00:00
|
|
|
G_OBJECT_CLASS (klass)->dispose = gst_gl_display_dispose;
|
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
|
|
|
{
|
2018-06-23 19:33:16 +00:00
|
|
|
display->priv = gst_gl_display_get_instance_private (display);
|
2012-12-06 07:40:26 +00:00
|
|
|
|
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
|
|
|
|
2016-06-30 13:04:16 +00:00
|
|
|
g_mutex_init (&display->priv->thread_lock);
|
|
|
|
g_cond_init (&display->priv->thread_cond);
|
|
|
|
|
2019-11-02 13:46:49 +00:00
|
|
|
g_mutex_init (&display->priv->window_lock);
|
|
|
|
|
2016-06-30 13:04:16 +00:00
|
|
|
display->priv->event_thread = g_thread_new ("gldisplay-event",
|
|
|
|
(GThreadFunc) _event_thread_main, display);
|
|
|
|
|
|
|
|
g_mutex_lock (&display->priv->thread_lock);
|
|
|
|
while (!display->main_loop)
|
|
|
|
g_cond_wait (&display->priv->thread_cond, &display->priv->thread_lock);
|
|
|
|
g_mutex_unlock (&display->priv->thread_lock);
|
|
|
|
|
2013-11-12 23:43:16 +00:00
|
|
|
GST_TRACE ("init %p", display);
|
|
|
|
|
2015-12-14 02:08:10 +00:00
|
|
|
gst_gl_buffer_init_once ();
|
2015-12-14 02:43:59 +00:00
|
|
|
gst_gl_memory_pbo_init_once ();
|
2016-07-11 12:31:04 +00:00
|
|
|
gst_gl_renderbuffer_init_once ();
|
2014-03-22 22:01:49 +00:00
|
|
|
|
|
|
|
#if GST_GL_HAVE_PLATFORM_EGL
|
2016-01-21 13:18:17 +00:00
|
|
|
gst_gl_memory_egl_init_once ();
|
2014-03-22 22:01:49 +00:00
|
|
|
#endif
|
2008-05-18 11:12:46 +00:00
|
|
|
}
|
|
|
|
|
2016-06-30 13:04:16 +00:00
|
|
|
static void
|
|
|
|
gst_gl_display_dispose (GObject * object)
|
|
|
|
{
|
|
|
|
GstGLDisplay *display = GST_GL_DISPLAY (object);
|
|
|
|
|
|
|
|
if (display->main_loop)
|
|
|
|
g_main_loop_quit (display->main_loop);
|
|
|
|
|
|
|
|
if (display->priv->event_thread) {
|
|
|
|
/* can't use g_thread_join() as we could lose the last ref from a user
|
|
|
|
* function */
|
|
|
|
g_mutex_lock (&display->priv->thread_lock);
|
|
|
|
while (display->main_loop)
|
|
|
|
g_cond_wait (&display->priv->thread_cond, &display->priv->thread_lock);
|
|
|
|
g_mutex_unlock (&display->priv->thread_lock);
|
|
|
|
g_thread_unref (display->priv->event_thread);
|
|
|
|
}
|
|
|
|
display->priv->event_thread = NULL;
|
|
|
|
|
|
|
|
if (display->event_source) {
|
|
|
|
g_source_destroy (display->event_source);
|
|
|
|
g_source_unref (display->event_source);
|
|
|
|
}
|
|
|
|
display->event_source = NULL;
|
|
|
|
|
|
|
|
G_OBJECT_CLASS (gst_gl_display_parent_class)->dispose (object);
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2017-04-07 09:24:19 +00:00
|
|
|
g_list_free (display->windows);
|
2015-03-03 06:26:47 +00:00
|
|
|
g_list_free (display->priv->contexts);
|
|
|
|
|
2016-06-30 13:04:16 +00:00
|
|
|
g_cond_clear (&display->priv->thread_cond);
|
|
|
|
g_mutex_clear (&display->priv->thread_lock);
|
2019-11-02 13:46:49 +00:00
|
|
|
g_mutex_clear (&display->priv->window_lock);
|
2016-06-30 13:04:16 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-05-18 09:56:13 +00:00
|
|
|
static void
|
|
|
|
init_debug (void)
|
2013-08-14 00:44:19 +00:00
|
|
|
{
|
2021-03-18 08:18:36 +00:00
|
|
|
static gsize _init = 0;
|
2013-11-27 06:52:46 +00:00
|
|
|
|
|
|
|
if (g_once_init_enter (&_init)) {
|
|
|
|
GST_DEBUG_CATEGORY_INIT (gst_gl_display_debug, "gldisplay", 0,
|
|
|
|
"gldisplay element");
|
|
|
|
g_once_init_leave (&_init, 1);
|
|
|
|
}
|
2021-05-18 09:56:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstGLDisplayType
|
|
|
|
gst_gl_display_type_from_environment (void)
|
|
|
|
{
|
|
|
|
const char *env = g_getenv ("GST_GL_WINDOW");
|
|
|
|
|
2023-02-27 07:23:38 +00:00
|
|
|
if (!env)
|
2021-05-18 09:56:13 +00:00
|
|
|
return GST_GL_DISPLAY_TYPE_ANY;
|
|
|
|
|
|
|
|
if (env) {
|
|
|
|
if (g_strstr_len (env, 3, "x11")) {
|
|
|
|
return GST_GL_DISPLAY_TYPE_X11;
|
|
|
|
} else if (g_strstr_len (env, 7, "wayland")) {
|
|
|
|
return GST_GL_DISPLAY_TYPE_WAYLAND;
|
|
|
|
} else if (g_strstr_len (env, 5, "cocoa")) {
|
|
|
|
return GST_GL_DISPLAY_TYPE_COCOA;
|
|
|
|
} else if (g_strstr_len (env, 5, "win32")) {
|
|
|
|
return GST_GL_DISPLAY_TYPE_WIN32;
|
|
|
|
} else if (g_strstr_len (env, 8, "dispmanx")) {
|
|
|
|
return GST_GL_DISPLAY_TYPE_DISPMANX;
|
2022-03-04 13:21:13 +00:00
|
|
|
} else if (g_strstr_len (env, 10, "egl-device")) {
|
|
|
|
return GST_GL_DISPLAY_TYPE_EGL_DEVICE;
|
2021-05-18 09:56:13 +00:00
|
|
|
} else if (g_strstr_len (env, 3, "egl")) {
|
|
|
|
return GST_GL_DISPLAY_TYPE_EGL;
|
|
|
|
} else if (g_strstr_len (env, 6, "viv-fb")) {
|
|
|
|
return GST_GL_DISPLAY_TYPE_VIV_FB;
|
|
|
|
} else if (g_strstr_len (env, 3, "gbm")) {
|
|
|
|
return GST_GL_DISPLAY_TYPE_GBM;
|
|
|
|
} else if (g_strstr_len (env, 4, "eagl")) {
|
|
|
|
return GST_GL_DISPLAY_TYPE_EAGL;
|
|
|
|
} else if (g_strstr_len (env, 7, "android")) {
|
|
|
|
return GST_GL_DISPLAY_TYPE_EGL;
|
2023-10-19 16:45:29 +00:00
|
|
|
} else if (g_strstr_len (env, 5, "winrt")) {
|
2021-05-18 09:56:13 +00:00
|
|
|
return GST_GL_DISPLAY_TYPE_EGL;
|
2023-10-19 12:10:16 +00:00
|
|
|
} else if (g_strstr_len (env, 11, "surfaceless")) {
|
|
|
|
return GST_GL_DISPLAY_TYPE_EGL_SURFACELESS;
|
2021-05-22 05:42:17 +00:00
|
|
|
} else {
|
|
|
|
return GST_GL_DISPLAY_TYPE_NONE;
|
2021-05-18 09:56:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-22 05:42:17 +00:00
|
|
|
return GST_GL_DISPLAY_TYPE_ANY;
|
2021-05-18 09:56:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GstGLDisplay *
|
|
|
|
create_dummy_display (void)
|
|
|
|
{
|
|
|
|
GstGLDisplay *display = g_object_new (GST_TYPE_GL_DISPLAY, NULL);
|
|
|
|
return gst_object_ref_sink (display);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_gl_display_new_with_type:
|
|
|
|
* @type: #GstGLDisplayType
|
|
|
|
*
|
|
|
|
* Will always return a #GstGLDisplay of a single type. This differs from
|
|
|
|
* gst_gl_display_new() and the seemingly equivalent call
|
|
|
|
* gst_gl_display_new_with_type (GST_GL_DISPLAY_TYPE_ANY) in that the latter
|
|
|
|
* may return NULL.
|
|
|
|
*
|
|
|
|
* Returns: (transfer full) (nullable): a new #GstGLDisplay or %NULL if @type is
|
|
|
|
* not supported
|
|
|
|
*
|
|
|
|
* Since: 1.20
|
|
|
|
*/
|
|
|
|
GstGLDisplay *
|
|
|
|
gst_gl_display_new_with_type (GstGLDisplayType type)
|
|
|
|
{
|
|
|
|
GstGLDisplay *display = NULL;
|
|
|
|
GstGLDisplayType custom_new_types = 0;
|
|
|
|
|
|
|
|
init_debug ();
|
2013-11-27 06:52:46 +00:00
|
|
|
|
2014-05-06 07:08:18 +00:00
|
|
|
#if GST_GL_HAVE_WINDOW_COCOA
|
2021-05-18 09:56:13 +00:00
|
|
|
if (!display && (type & GST_GL_DISPLAY_TYPE_COCOA)) {
|
2015-03-11 00:06:55 +00:00
|
|
|
display = GST_GL_DISPLAY (gst_gl_display_cocoa_new ());
|
|
|
|
if (!display)
|
|
|
|
return NULL;
|
|
|
|
}
|
2014-05-06 07:08:18 +00:00
|
|
|
#endif
|
2021-05-18 09:56:13 +00:00
|
|
|
custom_new_types |= GST_GL_DISPLAY_TYPE_COCOA;
|
2014-06-05 08:43:30 +00:00
|
|
|
#if GST_GL_HAVE_WINDOW_WAYLAND
|
2021-05-18 09:56:13 +00:00
|
|
|
if (!display && (type & GST_GL_DISPLAY_TYPE_WAYLAND))
|
2015-05-21 07:48:31 +00:00
|
|
|
display = GST_GL_DISPLAY (gst_gl_display_wayland_new (NULL));
|
2017-12-02 20:25:38 +00:00
|
|
|
#endif
|
2021-05-18 09:56:13 +00:00
|
|
|
custom_new_types |= GST_GL_DISPLAY_TYPE_WAYLAND;
|
2017-12-02 20:25:38 +00:00
|
|
|
#if GST_GL_HAVE_WINDOW_X11
|
2021-05-18 09:56:13 +00:00
|
|
|
if (!display && (type & GST_GL_DISPLAY_TYPE_X11))
|
2017-12-02 20:25:38 +00:00
|
|
|
display = GST_GL_DISPLAY (gst_gl_display_x11_new (NULL));
|
2014-06-05 08:43:30 +00:00
|
|
|
#endif
|
2021-05-18 09:56:13 +00:00
|
|
|
custom_new_types |= GST_GL_DISPLAY_TYPE_X11;
|
2017-02-17 10:24:58 +00:00
|
|
|
#if GST_GL_HAVE_WINDOW_VIV_FB
|
2024-01-12 02:55:01 +00:00
|
|
|
if (!display && (type & GST_GL_DISPLAY_TYPE_VIV_FB)) {
|
2017-02-17 10:24:58 +00:00
|
|
|
const gchar *disp_idx_str = NULL;
|
|
|
|
gint disp_idx = 0;
|
|
|
|
disp_idx_str = g_getenv ("GST_GL_VIV_FB");
|
|
|
|
if (disp_idx_str) {
|
|
|
|
gint64 v = g_ascii_strtoll (disp_idx_str, NULL, 10);
|
|
|
|
if (v >= G_MININT && v <= G_MAXINT)
|
|
|
|
disp_idx = v;
|
|
|
|
}
|
|
|
|
display = GST_GL_DISPLAY (gst_gl_display_viv_fb_new (disp_idx));
|
|
|
|
}
|
|
|
|
#endif
|
2021-05-18 09:56:13 +00:00
|
|
|
custom_new_types |= GST_GL_DISPLAY_TYPE_VIV_FB;
|
2018-02-23 18:59:45 +00:00
|
|
|
#if GST_GL_HAVE_WINDOW_GBM
|
2021-05-18 09:56:13 +00:00
|
|
|
if (!display && (type & GST_GL_DISPLAY_TYPE_GBM)) {
|
2018-02-23 18:59:45 +00:00
|
|
|
display = GST_GL_DISPLAY (gst_gl_display_gbm_new ());
|
|
|
|
}
|
|
|
|
#endif
|
2021-05-18 09:56:13 +00:00
|
|
|
custom_new_types |= GST_GL_DISPLAY_TYPE_GBM;
|
2014-03-17 09:56:39 +00:00
|
|
|
#if GST_GL_HAVE_PLATFORM_EGL
|
2021-05-18 09:56:13 +00:00
|
|
|
if (!display && (type == GST_GL_DISPLAY_TYPE_EGL_DEVICE)) {
|
2019-04-04 08:41:13 +00:00
|
|
|
display = GST_GL_DISPLAY (gst_gl_display_egl_device_new (0));
|
|
|
|
}
|
|
|
|
|
2021-05-18 09:56:13 +00:00
|
|
|
if (!display && (type & GST_GL_DISPLAY_TYPE_EGL)) {
|
2014-03-17 09:56:39 +00:00
|
|
|
display = GST_GL_DISPLAY (gst_gl_display_egl_new ());
|
2019-04-04 08:41:13 +00:00
|
|
|
}
|
2023-10-19 12:10:16 +00:00
|
|
|
|
|
|
|
if (!display && (type & GST_GL_DISPLAY_TYPE_EGL_SURFACELESS)) {
|
|
|
|
display = GST_GL_DISPLAY (gst_gl_display_egl_new_surfaceless ());
|
|
|
|
}
|
2013-11-27 06:52:46 +00:00
|
|
|
#endif
|
2021-05-18 09:56:13 +00:00
|
|
|
custom_new_types |= GST_GL_DISPLAY_TYPE_EGL_DEVICE;
|
|
|
|
custom_new_types |= GST_GL_DISPLAY_TYPE_EGL;
|
2023-10-19 12:10:16 +00:00
|
|
|
custom_new_types |= GST_GL_DISPLAY_TYPE_EGL_SURFACELESS;
|
2021-05-18 09:56:13 +00:00
|
|
|
custom_new_types |= GST_GL_DISPLAY_TYPE_DISPMANX;
|
|
|
|
custom_new_types |= GST_GL_DISPLAY_TYPE_WINRT;
|
|
|
|
custom_new_types |= GST_GL_DISPLAY_TYPE_ANDROID;
|
|
|
|
#if GST_GL_HAVE_WINDOW_WIN32 || GST_GL_HAVE_WINDOW_EAGL
|
2013-11-27 06:52:46 +00:00
|
|
|
if (!display) {
|
2021-05-18 09:56:13 +00:00
|
|
|
GstGLDisplayType create_type = 0;
|
2021-10-19 08:46:48 +00:00
|
|
|
#if GST_GL_HAVE_WINDOW_WIN32
|
2021-05-18 09:56:13 +00:00
|
|
|
if (type & GST_GL_DISPLAY_TYPE_WIN32)
|
|
|
|
create_type = GST_GL_DISPLAY_TYPE_WIN32;
|
2021-10-19 08:46:48 +00:00
|
|
|
#endif
|
|
|
|
#if GST_GL_HAVE_WINDOW_EAGL
|
|
|
|
if (type & GST_GL_DISPLAY_TYPE_EAGL)
|
2021-05-18 09:56:13 +00:00
|
|
|
create_type = GST_GL_DISPLAY_TYPE_EAGL;
|
2021-10-19 08:46:48 +00:00
|
|
|
#endif
|
2021-05-18 09:56:13 +00:00
|
|
|
if (create_type) {
|
2021-10-19 08:46:48 +00:00
|
|
|
GST_INFO ("Creating display with type %u(0x%x)",
|
2021-05-18 09:56:13 +00:00
|
|
|
create_type, create_type);
|
|
|
|
display = create_dummy_display ();
|
|
|
|
display->type = create_type;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
custom_new_types |= GST_GL_DISPLAY_TYPE_WIN32;
|
|
|
|
custom_new_types |= GST_GL_DISPLAY_TYPE_EAGL;
|
|
|
|
|
|
|
|
if (!display && type != GST_GL_DISPLAY_TYPE_ANY
|
|
|
|
&& type != GST_GL_DISPLAY_TYPE_NONE) {
|
|
|
|
/* remove all the display types that we know about */
|
|
|
|
type &= ~custom_new_types;
|
|
|
|
if (type && (type & (type - 1)) == 0) {
|
|
|
|
/* only create a dummy display if we only have a single type */
|
|
|
|
GST_INFO_OBJECT (display, "Creating dummy display with type %u(0x%x)",
|
|
|
|
type, type);
|
|
|
|
display = create_dummy_display ();
|
|
|
|
display->type = type;
|
|
|
|
}
|
|
|
|
}
|
2013-11-27 06:52:46 +00:00
|
|
|
|
2021-05-18 09:56:13 +00:00
|
|
|
return display;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_gl_display_new:
|
|
|
|
*
|
|
|
|
* Returns: (transfer full): a new #GstGLDisplay
|
|
|
|
*
|
|
|
|
* Since: 1.4
|
|
|
|
*/
|
|
|
|
GstGLDisplay *
|
|
|
|
gst_gl_display_new (void)
|
|
|
|
{
|
|
|
|
GstGLDisplayType env_choice = gst_gl_display_type_from_environment ();
|
|
|
|
GstGLDisplay *display = gst_gl_display_new_with_type (env_choice);
|
|
|
|
|
|
|
|
if (!display) {
|
2017-05-15 17:31:31 +00:00
|
|
|
display = g_object_new (GST_TYPE_GL_DISPLAY, NULL);
|
2021-05-18 09:56:13 +00:00
|
|
|
GST_INFO_OBJECT (display, "Creating dummy display");
|
2017-05-15 17:31:31 +00:00
|
|
|
gst_object_ref_sink (display);
|
2013-11-27 06:52:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return display;
|
2013-08-14 00:44:19 +00:00
|
|
|
}
|
|
|
|
|
2016-11-03 01:03:24 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_display_get_handle:
|
|
|
|
* @display: a #GstGLDisplay
|
|
|
|
*
|
|
|
|
* Returns: the native handle for the display
|
|
|
|
*
|
|
|
|
* Since: 1.4
|
|
|
|
*/
|
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
|
2019-08-29 17:42:39 +00:00
|
|
|
* what they support. See gst_gl_context_get_gl_api() for the retrieving the
|
2014-11-27 10:05:45 +00:00
|
|
|
* 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
|
2022-10-15 09:16:01 +00:00
|
|
|
* @display: (transfer none) (nullable): resulting #GstGLDisplay
|
2013-11-23 11:54:46 +00:00
|
|
|
*
|
|
|
|
* 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
|
2022-10-15 09:16:01 +00:00
|
|
|
* @display: (out) (optional) (nullable) (transfer full): resulting #GstGLDisplay
|
2013-11-23 11:54:46 +00:00
|
|
|
*
|
|
|
|
* 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
|
2023-01-27 14:22:06 +00:00
|
|
|
* @other_context: (transfer none) (nullable): other #GstGLContext to share resources with.
|
2016-11-03 05:14:37 +00:00
|
|
|
* @p_context: (transfer full) (out): resulting #GstGLContext
|
2022-10-25 06:39:07 +00:00
|
|
|
* @error: resulting #GError
|
2015-06-15 15:09:54 +00:00
|
|
|
*
|
|
|
|
* 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);
|
2016-11-03 07:19:58 +00:00
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
2015-06-15 15:09:54 +00:00
|
|
|
|
|
|
|
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;
|
2020-04-08 07:26:23 +00:00
|
|
|
else
|
|
|
|
gst_object_unref (context);
|
2015-06-15 15:09:54 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2016-06-30 13:12:33 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_display_create_window:
|
|
|
|
* @display: a #GstGLDisplay
|
|
|
|
*
|
2022-10-15 09:16:01 +00:00
|
|
|
* Returns: (transfer full) (nullable): a new #GstGLWindow for @display or %NULL.
|
2016-06-30 13:12:33 +00:00
|
|
|
*/
|
2019-11-02 13:46:49 +00:00
|
|
|
/* XXX: previous versions had documentation requiring the OBJECT lock to be
|
|
|
|
* held when this fuction is called so that needs to always work. */
|
2016-06-30 13:12:33 +00:00
|
|
|
GstGLWindow *
|
|
|
|
gst_gl_display_create_window (GstGLDisplay * display)
|
|
|
|
{
|
|
|
|
GstGLDisplayClass *klass;
|
|
|
|
GstGLWindow *window;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_GL_DISPLAY (display), NULL);
|
|
|
|
klass = GST_GL_DISPLAY_GET_CLASS (display);
|
|
|
|
g_return_val_if_fail (klass->create_window != NULL, NULL);
|
|
|
|
|
2019-11-02 13:46:49 +00:00
|
|
|
g_mutex_lock (&display->priv->window_lock);
|
2016-06-30 13:12:33 +00:00
|
|
|
window = klass->create_window (display);
|
|
|
|
|
2019-03-08 06:40:52 +00:00
|
|
|
if (window) {
|
2016-06-30 13:12:33 +00:00
|
|
|
display->windows = g_list_prepend (display->windows, window);
|
2019-03-08 06:40:52 +00:00
|
|
|
}
|
2019-11-02 13:46:49 +00:00
|
|
|
g_mutex_unlock (&display->priv->window_lock);
|
2019-03-08 06:40:52 +00:00
|
|
|
GST_DEBUG_OBJECT (display, "Adding window %" GST_PTR_FORMAT
|
|
|
|
" (%p) to internal list", window, window);
|
2016-06-30 13:12:33 +00:00
|
|
|
|
|
|
|
return window;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GstGLWindow *
|
|
|
|
gst_gl_display_default_create_window (GstGLDisplay * display)
|
|
|
|
{
|
|
|
|
return gst_gl_window_new (display);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_gl_display_remove_window:
|
|
|
|
* @display: a #GstGLDisplay
|
|
|
|
* @window: a #GstGLWindow to remove
|
|
|
|
*
|
|
|
|
* Returns: if @window could be removed from @display
|
|
|
|
*
|
|
|
|
* Since: 1.12
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_gl_display_remove_window (GstGLDisplay * display, GstGLWindow * window)
|
|
|
|
{
|
|
|
|
gboolean ret = FALSE;
|
|
|
|
GList *l;
|
|
|
|
|
2019-11-02 13:46:49 +00:00
|
|
|
g_mutex_lock (&display->priv->window_lock);
|
2016-06-30 13:12:33 +00:00
|
|
|
l = g_list_find (display->windows, window);
|
|
|
|
if (l) {
|
|
|
|
display->windows = g_list_delete_link (display->windows, l);
|
|
|
|
ret = TRUE;
|
|
|
|
}
|
2019-03-08 06:40:52 +00:00
|
|
|
GST_DEBUG_OBJECT (display, "Removing window %" GST_PTR_FORMAT
|
|
|
|
" (%p) from internal list", window, window);
|
2019-11-02 13:46:49 +00:00
|
|
|
g_mutex_unlock (&display->priv->window_lock);
|
2016-06-30 13:12:33 +00:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2022-02-21 13:12:04 +00:00
|
|
|
#ifndef GST_REMOVE_DEPRECATED
|
2016-06-30 13:12:33 +00:00
|
|
|
/**
|
|
|
|
* gst_gl_display_find_window:
|
|
|
|
* @display: a #GstGLDisplay
|
2024-10-24 07:17:54 +00:00
|
|
|
* @data: some data to pass to @compare_func
|
|
|
|
* @compare_func: (scope call) (closure data): a comparison function to run
|
2016-06-30 13:12:33 +00:00
|
|
|
*
|
|
|
|
* Execute @compare_func over the list of windows stored by @display. The
|
2019-08-29 17:42:39 +00:00
|
|
|
* first argument to @compare_func is the #GstGLWindow being checked and the
|
2016-06-30 13:12:33 +00:00
|
|
|
* second argument is @data.
|
|
|
|
*
|
2022-10-15 09:16:01 +00:00
|
|
|
* Returns: (transfer none) (nullable): The first #GstGLWindow that causes a match
|
2017-01-10 04:35:52 +00:00
|
|
|
* from @compare_func
|
2016-06-30 13:12:33 +00:00
|
|
|
*
|
|
|
|
* Since: 1.12
|
2022-02-21 13:08:44 +00:00
|
|
|
* Deprecated: 1.18: Use gst_gl_display_retrieve_window() instead.
|
2016-06-30 13:12:33 +00:00
|
|
|
*/
|
|
|
|
GstGLWindow *
|
|
|
|
gst_gl_display_find_window (GstGLDisplay * display, gpointer data,
|
|
|
|
GCompareFunc compare_func)
|
2019-11-02 11:58:42 +00:00
|
|
|
{
|
|
|
|
GstGLWindow *ret;
|
|
|
|
|
|
|
|
ret = gst_gl_display_retrieve_window (display, data, compare_func);
|
|
|
|
if (ret)
|
|
|
|
gst_object_unref (ret);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2022-02-21 13:12:04 +00:00
|
|
|
#endif
|
2019-11-02 11:58:42 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_gl_display_retrieve_window:
|
|
|
|
* @display: a #GstGLDisplay
|
2024-10-24 07:17:54 +00:00
|
|
|
* @data: some data to pass to @compare_func
|
|
|
|
* @compare_func: (scope call) (closure data): a comparison function to run
|
2019-11-02 11:58:42 +00:00
|
|
|
*
|
|
|
|
* Execute @compare_func over the list of windows stored by @display. The
|
|
|
|
* first argument to @compare_func is the #GstGLWindow being checked and the
|
|
|
|
* second argument is @data.
|
|
|
|
*
|
2022-10-15 09:16:01 +00:00
|
|
|
* Returns: (transfer full) (nullable): The first #GstGLWindow that causes a match
|
2019-11-02 11:58:42 +00:00
|
|
|
* from @compare_func
|
|
|
|
*
|
|
|
|
* Since: 1.18
|
|
|
|
*/
|
|
|
|
GstGLWindow *
|
|
|
|
gst_gl_display_retrieve_window (GstGLDisplay * display, gpointer data,
|
|
|
|
GCompareFunc compare_func)
|
2016-06-30 13:12:33 +00:00
|
|
|
{
|
|
|
|
GstGLWindow *ret = NULL;
|
|
|
|
GList *l;
|
|
|
|
|
2019-11-02 13:46:49 +00:00
|
|
|
g_mutex_lock (&display->priv->window_lock);
|
2016-06-30 13:12:33 +00:00
|
|
|
l = g_list_find_custom (display->windows, data, compare_func);
|
|
|
|
if (l)
|
2019-11-02 11:58:42 +00:00
|
|
|
ret = gst_object_ref (l->data);
|
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (display, "Found window %" GST_PTR_FORMAT
|
|
|
|
" (%p) in internal list", ret, ret);
|
2019-11-02 13:46:49 +00:00
|
|
|
g_mutex_unlock (&display->priv->window_lock);
|
2016-06-30 13:12:33 +00:00
|
|
|
|
|
|
|
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);
|
2016-09-22 08:19:36 +00:00
|
|
|
g_free (l->data);
|
2015-03-03 06:26:47 +00:00
|
|
|
display->priv->contexts = g_list_delete_link (display->priv->contexts, l);
|
|
|
|
l = prev ? prev->next : display->priv->contexts;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2016-05-24 13:38:22 +00:00
|
|
|
if (thread == NULL) {
|
|
|
|
GST_DEBUG_OBJECT (display, "Returning GL context %" GST_PTR_FORMAT " for "
|
|
|
|
"NULL thread", context);
|
2016-03-05 16:16:24 +00:00
|
|
|
return context;
|
2016-05-24 13:38:22 +00:00
|
|
|
}
|
2016-03-05 16:16:24 +00:00
|
|
|
|
2015-03-03 06:26:47 +00:00
|
|
|
context_thread = gst_gl_context_get_thread (context);
|
2016-03-05 16:16:24 +00:00
|
|
|
if (thread != context_thread) {
|
2015-03-03 06:26:47 +00:00
|
|
|
g_thread_unref (context_thread);
|
|
|
|
gst_object_unref (context);
|
|
|
|
prev = l;
|
|
|
|
l = l->next;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (context_thread)
|
|
|
|
g_thread_unref (context_thread);
|
2016-05-24 13:38:22 +00:00
|
|
|
|
|
|
|
GST_DEBUG_OBJECT (display, "Returning GL context %" GST_PTR_FORMAT " for "
|
|
|
|
"thread %p", context, thread);
|
2015-03-03 06:26:47 +00:00
|
|
|
return context;
|
|
|
|
}
|
|
|
|
|
2016-05-24 13:38:22 +00:00
|
|
|
GST_DEBUG_OBJECT (display, "No GL context for thread %p", thread);
|
2015-03-03 06:26:47 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_gl_display_get_gl_context_for_thread:
|
|
|
|
* @display: a #GstGLDisplay
|
|
|
|
* @thread: a #GThread
|
|
|
|
*
|
2022-10-15 09:16:01 +00:00
|
|
|
* Returns: (transfer full) (nullable): the #GstGLContext current on @thread or %NULL
|
2015-03-03 06:26:47 +00:00
|
|
|
*
|
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;
|
|
|
|
}
|
|
|
|
|
2016-03-07 13:35:22 +00:00
|
|
|
if (thread == collision_thread) {
|
2015-03-15 12:58:26 +00:00
|
|
|
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);
|
2016-03-07 13:35:22 +00:00
|
|
|
|
|
|
|
/* adding the same context is a no-op */
|
|
|
|
if (context == collision) {
|
2016-05-24 13:38:22 +00:00
|
|
|
GST_LOG_OBJECT (display, "Attempting to add the same GL context %"
|
|
|
|
GST_PTR_FORMAT ". Ignoring", context);
|
2016-03-07 13:35:22 +00:00
|
|
|
ret = TRUE;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2015-03-15 12:58:26 +00:00
|
|
|
if (_check_collision (context, collision)) {
|
2016-05-24 13:38:22 +00:00
|
|
|
GST_DEBUG_OBJECT (display, "Collision detected adding GL context "
|
|
|
|
"%" GST_PTR_FORMAT, context);
|
2015-03-15 12:58:26 +00:00
|
|
|
ret = FALSE;
|
|
|
|
goto out;
|
2015-03-03 06:26:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ref = g_new0 (GWeakRef, 1);
|
|
|
|
g_weak_ref_init (ref, context);
|
|
|
|
|
2016-05-24 13:38:22 +00:00
|
|
|
GST_DEBUG_OBJECT (display, "Adding GL context %" GST_PTR_FORMAT, context);
|
2015-03-03 06:26:47 +00:00
|
|
|
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;
|
|
|
|
}
|
2020-02-04 03:04:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_gl_display_remove_context:
|
|
|
|
* @display: a #GstGLDisplay
|
|
|
|
* @context: (transfer none): the #GstGLContext to remove
|
|
|
|
*
|
|
|
|
* Must be called with the object lock held.
|
|
|
|
*
|
|
|
|
* Since: 1.18
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_gl_display_remove_context (GstGLDisplay * display, GstGLContext * needle)
|
|
|
|
{
|
|
|
|
GstGLContext *context;
|
|
|
|
GList *prev = NULL, *l;
|
|
|
|
|
|
|
|
g_return_if_fail (GST_IS_GL_DISPLAY (display));
|
|
|
|
g_return_if_fail (GST_IS_GL_CONTEXT (needle));
|
|
|
|
|
|
|
|
l = display->priv->contexts;
|
|
|
|
|
|
|
|
while (l) {
|
|
|
|
GWeakRef *ref = l->data;
|
|
|
|
|
|
|
|
context = g_weak_ref_get (ref);
|
|
|
|
if (!context || context == needle) {
|
|
|
|
/* remove dead contexts */
|
|
|
|
g_weak_ref_clear (l->data);
|
|
|
|
g_free (l->data);
|
|
|
|
display->priv->contexts = g_list_delete_link (display->priv->contexts, l);
|
|
|
|
if (context) {
|
|
|
|
GST_INFO_OBJECT (display, "removed context %" GST_PTR_FORMAT
|
|
|
|
" from internal list", context);
|
2020-05-06 13:13:11 +00:00
|
|
|
gst_object_unref (context);
|
2020-02-04 03:04:21 +00:00
|
|
|
return;
|
2020-05-06 07:26:35 +00:00
|
|
|
}
|
2020-05-06 13:13:11 +00:00
|
|
|
l = prev ? prev->next : display->priv->contexts;
|
2020-05-06 07:26:35 +00:00
|
|
|
continue;
|
2020-02-04 03:04:21 +00:00
|
|
|
}
|
2020-05-06 07:26:35 +00:00
|
|
|
prev = l;
|
|
|
|
l = l->next;
|
2020-02-04 03:04:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GST_WARNING_OBJECT (display, "%" GST_PTR_FORMAT " was not found in this "
|
|
|
|
"display", needle);
|
|
|
|
}
|
2023-02-06 15:14:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_gl_display_ensure_context:
|
|
|
|
* @display: a #GstGLDisplay
|
|
|
|
* @other_context: (transfer none)(nullable): other #GstGLContext to share resources with.
|
|
|
|
* @context: (inout)(transfer full)(nullable): the resulting #GstGLContext
|
|
|
|
* @error: (out)(transfer full)(nullable): possible error
|
|
|
|
*
|
|
|
|
* Ensures that the display has a valid GL context for the current thread. If
|
|
|
|
* @context already contains a valid context, this does nothing.
|
|
|
|
*
|
|
|
|
* Returns: wether @context contains a valid context.
|
|
|
|
*
|
|
|
|
* Since: 1.24
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gst_gl_display_ensure_context (GstGLDisplay * display,
|
|
|
|
GstGLContext * other_context, GstGLContext ** context, GError ** error)
|
|
|
|
{
|
|
|
|
gboolean ret = FALSE;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GST_IS_GL_DISPLAY (display), FALSE);
|
|
|
|
g_return_val_if_fail (other_context == NULL
|
|
|
|
|| GST_IS_GL_CONTEXT (other_context), FALSE);
|
|
|
|
g_return_val_if_fail (context != NULL, FALSE);
|
|
|
|
g_return_val_if_fail (*context == NULL
|
|
|
|
|| GST_IS_GL_CONTEXT (*context), FALSE);
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
|
|
|
|
|
|
|
if (*context && (*context)->display == display) {
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
GST_OBJECT_LOCK (display);
|
|
|
|
do {
|
|
|
|
if (*context) {
|
|
|
|
gst_object_unref (*context);
|
|
|
|
*context = NULL;
|
|
|
|
}
|
|
|
|
/* just get a GL context. we don't care */
|
|
|
|
*context = gst_gl_display_get_gl_context_for_thread (display, NULL);
|
|
|
|
if (!*context) {
|
|
|
|
if (!gst_gl_display_create_context (display, other_context, &*context,
|
|
|
|
error)) {
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (!gst_gl_display_add_context (display, *context));
|
|
|
|
ret = TRUE;
|
|
|
|
out:
|
|
|
|
GST_OBJECT_UNLOCK (display);
|
|
|
|
return ret;
|
|
|
|
}
|