|
Packit |
971217 |
/*
|
|
Packit |
971217 |
* GStreamer
|
|
Packit |
971217 |
* Copyright (C) 2008 Julien Isorce <julien.isorce@gmail.com>
|
|
Packit |
971217 |
* Copyright (C) 2012 Matthew Waters <ystreet00@gmail.com>
|
|
Packit |
971217 |
*
|
|
Packit |
971217 |
* This library is free software; you can redistribute it and/or
|
|
Packit |
971217 |
* modify it under the terms of the GNU Library General Public
|
|
Packit |
971217 |
* License as published by the Free Software Foundation; either
|
|
Packit |
971217 |
* version 2 of the License, or (at your option) any later version.
|
|
Packit |
971217 |
*
|
|
Packit |
971217 |
* This library is distributed in the hope that it will be useful,
|
|
Packit |
971217 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
971217 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
971217 |
* Library General Public License for more details.
|
|
Packit |
971217 |
*
|
|
Packit |
971217 |
* You should have received a copy of the GNU Library General Public
|
|
Packit |
971217 |
* License along with this library; if not, write to the
|
|
Packit |
971217 |
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
Packit |
971217 |
* Boston, MA 02110-1301, USA.
|
|
Packit |
971217 |
*/
|
|
Packit |
971217 |
|
|
Packit |
971217 |
#define GLIB_DISABLE_DEPRECATION_WARNINGS
|
|
Packit |
971217 |
|
|
Packit |
971217 |
#ifdef HAVE_CONFIG_H
|
|
Packit |
971217 |
#include "config.h"
|
|
Packit |
971217 |
#endif
|
|
Packit |
971217 |
|
|
Packit |
971217 |
/* FIXME: Sharing contexts requires the Display to be the same.
|
|
Packit |
971217 |
* May need to box it
|
|
Packit |
971217 |
*/
|
|
Packit |
971217 |
|
|
Packit |
971217 |
#include <gst/gst.h>
|
|
Packit |
971217 |
|
|
Packit |
971217 |
#include "../gstgl_fwd.h"
|
|
Packit |
971217 |
#include <gst/gl/gstglcontext.h>
|
|
Packit |
971217 |
|
|
Packit |
971217 |
#include <gst/gl/gl.h>
|
|
Packit |
971217 |
#include "gstglcontext_glx.h"
|
|
Packit |
971217 |
#include "../utils/opengl_versions.h"
|
|
Packit |
971217 |
#include "../gstglcontext_private.h"
|
|
Packit |
971217 |
|
|
Packit |
971217 |
#define GST_CAT_DEFAULT gst_gl_context_debug
|
|
Packit |
971217 |
|
|
Packit |
971217 |
#define gst_gl_context_glx_parent_class parent_class
|
|
Packit |
971217 |
G_DEFINE_TYPE (GstGLContextGLX, gst_gl_context_glx, GST_TYPE_GL_CONTEXT);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
#define GST_GL_CONTEXT_GLX_GET_PRIVATE(o) \
|
|
Packit |
971217 |
(G_TYPE_INSTANCE_GET_PRIVATE((o), GST_TYPE_GL_CONTEXT_GLX, GstGLContextGLXPrivate))
|
|
Packit |
971217 |
|
|
Packit |
971217 |
static guintptr gst_gl_context_glx_get_gl_context (GstGLContext * context);
|
|
Packit |
971217 |
static void gst_gl_context_glx_swap_buffers (GstGLContext * context);
|
|
Packit |
971217 |
static gboolean gst_gl_context_glx_activate (GstGLContext * context,
|
|
Packit |
971217 |
gboolean activate);
|
|
Packit |
971217 |
static gboolean gst_gl_context_glx_create_context (GstGLContext *
|
|
Packit |
971217 |
context, GstGLAPI gl_api, GstGLContext * other_context, GError ** error);
|
|
Packit |
971217 |
static void gst_gl_context_glx_destroy_context (GstGLContext * context);
|
|
Packit |
971217 |
static gboolean gst_gl_context_glx_choose_format (GstGLContext *
|
|
Packit |
971217 |
context, GError ** error);
|
|
Packit |
971217 |
static GstGLAPI gst_gl_context_glx_get_gl_api (GstGLContext * context);
|
|
Packit |
971217 |
static GstGLPlatform gst_gl_context_glx_get_gl_platform (GstGLContext *
|
|
Packit |
971217 |
context);
|
|
Packit |
971217 |
static void gst_gl_context_glx_get_gl_platform_version (GstGLContext * context,
|
|
Packit |
971217 |
gint * major, gint * minor);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
struct _GstGLContextGLXPrivate
|
|
Packit |
971217 |
{
|
|
Packit |
971217 |
int glx_major;
|
|
Packit |
971217 |
int glx_minor;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
GstGLAPI context_api;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
GLXFBConfig *fbconfigs;
|
|
Packit |
971217 |
GLXContext (*glXCreateContextAttribsARB) (Display *, GLXFBConfig,
|
|
Packit |
971217 |
GLXContext, Bool, const int *);
|
|
Packit |
971217 |
};
|
|
Packit |
971217 |
|
|
Packit |
971217 |
static void
|
|
Packit |
971217 |
gst_gl_context_glx_class_init (GstGLContextGLXClass * klass)
|
|
Packit |
971217 |
{
|
|
Packit |
971217 |
GstGLContextClass *context_class = (GstGLContextClass *) klass;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
g_type_class_add_private (klass, sizeof (GstGLContextGLXPrivate));
|
|
Packit |
971217 |
|
|
Packit |
971217 |
context_class->get_gl_context =
|
|
Packit |
971217 |
GST_DEBUG_FUNCPTR (gst_gl_context_glx_get_gl_context);
|
|
Packit |
971217 |
context_class->activate = GST_DEBUG_FUNCPTR (gst_gl_context_glx_activate);
|
|
Packit |
971217 |
context_class->create_context =
|
|
Packit |
971217 |
GST_DEBUG_FUNCPTR (gst_gl_context_glx_create_context);
|
|
Packit |
971217 |
context_class->destroy_context =
|
|
Packit |
971217 |
GST_DEBUG_FUNCPTR (gst_gl_context_glx_destroy_context);
|
|
Packit |
971217 |
context_class->choose_format =
|
|
Packit |
971217 |
GST_DEBUG_FUNCPTR (gst_gl_context_glx_choose_format);
|
|
Packit |
971217 |
context_class->swap_buffers =
|
|
Packit |
971217 |
GST_DEBUG_FUNCPTR (gst_gl_context_glx_swap_buffers);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
context_class->get_gl_api = GST_DEBUG_FUNCPTR (gst_gl_context_glx_get_gl_api);
|
|
Packit |
971217 |
context_class->get_gl_platform =
|
|
Packit |
971217 |
GST_DEBUG_FUNCPTR (gst_gl_context_glx_get_gl_platform);
|
|
Packit |
971217 |
context_class->get_proc_address =
|
|
Packit |
971217 |
GST_DEBUG_FUNCPTR (gst_gl_context_glx_get_proc_address);
|
|
Packit |
971217 |
context_class->get_current_context =
|
|
Packit |
971217 |
GST_DEBUG_FUNCPTR (gst_gl_context_glx_get_current_context);
|
|
Packit |
971217 |
context_class->get_gl_platform_version =
|
|
Packit |
971217 |
GST_DEBUG_FUNCPTR (gst_gl_context_glx_get_gl_platform_version);
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
static void
|
|
Packit |
971217 |
gst_gl_context_glx_init (GstGLContextGLX * context)
|
|
Packit |
971217 |
{
|
|
Packit |
971217 |
context->priv = GST_GL_CONTEXT_GLX_GET_PRIVATE (context);
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
GstGLContextGLX *
|
|
Packit |
971217 |
gst_gl_context_glx_new (GstGLDisplay * display)
|
|
Packit |
971217 |
{
|
|
Packit |
971217 |
GstGLContextGLX *context;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
if ((gst_gl_display_get_handle_type (display) & GST_GL_DISPLAY_TYPE_X11) == 0)
|
|
Packit |
971217 |
/* we require an x11 display handle to create GLX contexts */
|
|
Packit |
971217 |
return NULL;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
context = g_object_new (GST_TYPE_GL_CONTEXT_GLX, NULL);
|
|
Packit |
971217 |
gst_object_ref_sink (context);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
return context;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
static inline void
|
|
Packit |
971217 |
_describe_fbconfig (Display * display, GLXFBConfig config)
|
|
Packit |
971217 |
{
|
|
Packit |
971217 |
int val;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
glXGetFBConfigAttrib (display, config, GLX_FBCONFIG_ID, &val;;
|
|
Packit |
971217 |
GST_DEBUG ("ID: %d", val);
|
|
Packit |
971217 |
glXGetFBConfigAttrib (display, config, GLX_DOUBLEBUFFER, &val;;
|
|
Packit |
971217 |
GST_DEBUG ("double buffering: %d", val);
|
|
Packit |
971217 |
glXGetFBConfigAttrib (display, config, GLX_RED_SIZE, &val;;
|
|
Packit |
971217 |
GST_DEBUG ("red: %d", val);
|
|
Packit |
971217 |
glXGetFBConfigAttrib (display, config, GLX_GREEN_SIZE, &val;;
|
|
Packit |
971217 |
GST_DEBUG ("green: %d", val);
|
|
Packit |
971217 |
glXGetFBConfigAttrib (display, config, GLX_BLUE_SIZE, &val;;
|
|
Packit |
971217 |
GST_DEBUG ("blue: %d", val);
|
|
Packit |
971217 |
glXGetFBConfigAttrib (display, config, GLX_ALPHA_SIZE, &val;;
|
|
Packit |
971217 |
GST_DEBUG ("alpha: %d", val);
|
|
Packit |
971217 |
glXGetFBConfigAttrib (display, config, GLX_DEPTH_SIZE, &val;;
|
|
Packit |
971217 |
GST_DEBUG ("depth: %d", val);
|
|
Packit |
971217 |
glXGetFBConfigAttrib (display, config, GLX_STENCIL_SIZE, &val;;
|
|
Packit |
971217 |
GST_DEBUG ("stencil: %d", val);
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
static GLXContext
|
|
Packit |
971217 |
_create_context_with_flags (GstGLContextGLX * context_glx, Display * dpy,
|
|
Packit |
971217 |
GLXFBConfig fbconfig, GLXContext share_context, gint major, gint minor,
|
|
Packit |
971217 |
gint contextFlags, gint profileMask)
|
|
Packit |
971217 |
{
|
|
Packit |
971217 |
GLXContext ret;
|
|
Packit |
971217 |
#define N_ATTRIBS 20
|
|
Packit |
971217 |
gint attribs[N_ATTRIBS];
|
|
Packit |
971217 |
int x_error = 0;
|
|
Packit |
971217 |
gint n = 0;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
if (major) {
|
|
Packit |
971217 |
attribs[n++] = GLX_CONTEXT_MAJOR_VERSION_ARB;
|
|
Packit |
971217 |
attribs[n++] = major;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
if (minor) {
|
|
Packit |
971217 |
attribs[n++] = GLX_CONTEXT_MINOR_VERSION_ARB;
|
|
Packit |
971217 |
attribs[n++] = minor;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
if (contextFlags) {
|
|
Packit |
971217 |
attribs[n++] = GLX_CONTEXT_FLAGS_ARB;
|
|
Packit |
971217 |
attribs[n++] = contextFlags;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
#ifdef GLX_ARB_create_context_profile
|
|
Packit |
971217 |
if (profileMask) {
|
|
Packit |
971217 |
attribs[n++] = GLX_CONTEXT_PROFILE_MASK_ARB;
|
|
Packit |
971217 |
attribs[n++] = profileMask;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
#endif
|
|
Packit |
971217 |
attribs[n++] = None;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
g_assert (n < N_ATTRIBS);
|
|
Packit |
971217 |
#undef N_ATTRIBS
|
|
Packit |
971217 |
|
|
Packit |
971217 |
gst_gl_window_x11_trap_x_errors ();
|
|
Packit |
971217 |
ret = context_glx->priv->glXCreateContextAttribsARB (dpy, fbconfig,
|
|
Packit |
971217 |
share_context, True, attribs);
|
|
Packit |
971217 |
x_error = gst_gl_window_x11_untrap_x_errors ();
|
|
Packit |
971217 |
|
|
Packit |
971217 |
if (x_error)
|
|
Packit |
971217 |
ret = 0;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
return ret;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
static gboolean
|
|
Packit |
971217 |
gst_gl_context_glx_create_context (GstGLContext * context,
|
|
Packit |
971217 |
GstGLAPI gl_api, GstGLContext * other_context, GError ** error)
|
|
Packit |
971217 |
{
|
|
Packit |
971217 |
GstGLContextGLX *context_glx;
|
|
Packit |
971217 |
GstGLWindow *window;
|
|
Packit |
971217 |
GstGLWindowX11 *window_x11;
|
|
Packit |
971217 |
GstGLDisplay *display = NULL;
|
|
Packit |
971217 |
gboolean create_context;
|
|
Packit |
971217 |
const char *glx_exts;
|
|
Packit |
971217 |
Display *device;
|
|
Packit |
971217 |
guintptr external_gl_context = 0;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
context_glx = GST_GL_CONTEXT_GLX (context);
|
|
Packit |
971217 |
window = gst_gl_context_get_window (context);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
if (!GST_IS_GL_WINDOW_X11 (window)) {
|
|
Packit |
971217 |
g_set_error (error, GST_GL_CONTEXT_ERROR,
|
|
Packit |
971217 |
GST_GL_CONTEXT_ERROR_WRONG_CONFIG,
|
|
Packit |
971217 |
"Cannot create an GLX context from a non-X11 window");
|
|
Packit |
971217 |
goto failure;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
window_x11 = GST_GL_WINDOW_X11 (window);
|
|
Packit |
971217 |
display = gst_gl_context_get_display (context);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
if (other_context) {
|
|
Packit |
971217 |
if (gst_gl_context_get_gl_platform (other_context) != GST_GL_PLATFORM_GLX) {
|
|
Packit |
971217 |
g_set_error (error, GST_GL_CONTEXT_ERROR,
|
|
Packit |
971217 |
GST_GL_CONTEXT_ERROR_WRONG_CONFIG,
|
|
Packit |
971217 |
"Cannot share context with non-GLX context");
|
|
Packit |
971217 |
goto failure;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
external_gl_context = gst_gl_context_get_gl_context (other_context);
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
device = (Display *) gst_gl_display_get_handle (display);
|
|
Packit |
971217 |
if (!device) {
|
|
Packit |
971217 |
g_set_error (error, GST_GL_CONTEXT_ERROR,
|
|
Packit |
971217 |
GST_GL_CONTEXT_ERROR_RESOURCE_UNAVAILABLE, "Invalid Display handle");
|
|
Packit |
971217 |
goto failure;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
glx_exts = glXQueryExtensionsString (device, DefaultScreen (device));
|
|
Packit |
971217 |
|
|
Packit |
971217 |
create_context = gst_gl_check_extension ("GLX_ARB_create_context", glx_exts);
|
|
Packit |
971217 |
context_glx->priv->glXCreateContextAttribsARB =
|
|
Packit |
971217 |
(gpointer) glXGetProcAddressARB ((const GLubyte *)
|
|
Packit |
971217 |
"glXCreateContextAttribsARB");
|
|
Packit |
971217 |
|
|
Packit |
971217 |
if (!context_glx->glx_context && gl_api & GST_GL_API_OPENGL3 && create_context
|
|
Packit |
971217 |
&& context_glx->priv->glXCreateContextAttribsARB) {
|
|
Packit |
971217 |
gint i;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
for (i = 0; i < G_N_ELEMENTS (opengl_versions); i++) {
|
|
Packit |
971217 |
gint profileMask = 0;
|
|
Packit |
971217 |
gint contextFlags = 0;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
if ((opengl_versions[i].major > 3
|
|
Packit |
971217 |
|| (opengl_versions[i].major == 3
|
|
Packit |
971217 |
&& opengl_versions[i].minor >= 2))) {
|
|
Packit |
971217 |
profileMask |= GLX_CONTEXT_CORE_PROFILE_BIT_ARB;
|
|
Packit |
971217 |
contextFlags |= GLX_CONTEXT_DEBUG_BIT_ARB;
|
|
Packit |
971217 |
} else {
|
|
Packit |
971217 |
break;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
GST_DEBUG_OBJECT (context, "trying to create a GL %d.%d context",
|
|
Packit |
971217 |
opengl_versions[i].major, opengl_versions[i].minor);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
context_glx->glx_context = _create_context_with_flags (context_glx,
|
|
Packit |
971217 |
device, context_glx->priv->fbconfigs[0],
|
|
Packit |
971217 |
(GLXContext) external_gl_context, opengl_versions[i].major,
|
|
Packit |
971217 |
opengl_versions[i].minor, contextFlags, profileMask);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
if (context_glx->glx_context) {
|
|
Packit |
971217 |
context_glx->priv->context_api = GST_GL_API_OPENGL3;
|
|
Packit |
971217 |
break;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
if (!context_glx->glx_context && gl_api & GST_GL_API_OPENGL) {
|
|
Packit |
971217 |
context_glx->glx_context =
|
|
Packit |
971217 |
glXCreateContext (device, window_x11->visual_info,
|
|
Packit |
971217 |
(GLXContext) external_gl_context, TRUE);
|
|
Packit |
971217 |
context_glx->priv->context_api = GST_GL_API_OPENGL;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
if (context_glx->priv->fbconfigs)
|
|
Packit |
971217 |
XFree (context_glx->priv->fbconfigs);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
if (!context_glx->glx_context) {
|
|
Packit |
971217 |
g_set_error (error, GST_GL_CONTEXT_ERROR,
|
|
Packit |
971217 |
GST_GL_CONTEXT_ERROR_CREATE_CONTEXT, "Failed to create opengl context");
|
|
Packit |
971217 |
goto failure;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
GST_LOG ("gl context id: %ld", (gulong) context_glx->glx_context);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
gst_object_unref (window);
|
|
Packit |
971217 |
gst_object_unref (display);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
return TRUE;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
failure:
|
|
Packit |
971217 |
if (window)
|
|
Packit |
971217 |
gst_object_unref (window);
|
|
Packit |
971217 |
if (display)
|
|
Packit |
971217 |
gst_object_unref (display);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
return FALSE;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
static void
|
|
Packit |
971217 |
gst_gl_context_glx_destroy_context (GstGLContext * context)
|
|
Packit |
971217 |
{
|
|
Packit |
971217 |
GstGLWindow *window;
|
|
Packit |
971217 |
GstGLContextGLX *context_glx;
|
|
Packit |
971217 |
Display *device;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
context_glx = GST_GL_CONTEXT_GLX (context);
|
|
Packit |
971217 |
window = gst_gl_context_get_window (context);
|
|
Packit |
971217 |
device = (Display *) gst_gl_display_get_handle (window->display);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
glXDestroyContext (device, context_glx->glx_context);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
context_glx->glx_context = 0;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
gst_object_unref (window);
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
static gboolean
|
|
Packit |
971217 |
gst_gl_context_glx_choose_format (GstGLContext * context, GError ** error)
|
|
Packit |
971217 |
{
|
|
Packit |
971217 |
GstGLContextGLX *context_glx;
|
|
Packit |
971217 |
GstGLWindow *window;
|
|
Packit |
971217 |
GstGLWindowX11 *window_x11;
|
|
Packit |
971217 |
gint error_base;
|
|
Packit |
971217 |
gint event_base;
|
|
Packit |
971217 |
Display *device;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
context_glx = GST_GL_CONTEXT_GLX (context);
|
|
Packit |
971217 |
window = gst_gl_context_get_window (context);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
if (!GST_IS_GL_WINDOW_X11 (window)) {
|
|
Packit |
971217 |
g_set_error (error, GST_GL_CONTEXT_ERROR,
|
|
Packit |
971217 |
GST_GL_CONTEXT_ERROR_WRONG_CONFIG,
|
|
Packit |
971217 |
"Cannot create an GLX context from a non-X11 window");
|
|
Packit |
971217 |
goto failure;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
window_x11 = GST_GL_WINDOW_X11 (window);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
device = (Display *) gst_gl_display_get_handle (window->display);
|
|
Packit |
971217 |
if (!device) {
|
|
Packit |
971217 |
g_set_error (error, GST_GL_CONTEXT_ERROR,
|
|
Packit |
971217 |
GST_GL_CONTEXT_ERROR_RESOURCE_UNAVAILABLE, "Invalid Display handle");
|
|
Packit |
971217 |
goto failure;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
if (!glXQueryExtension (device, &error_base, &event_base)) {
|
|
Packit |
971217 |
g_set_error (error, GST_GL_CONTEXT_ERROR,
|
|
Packit |
971217 |
GST_GL_CONTEXT_ERROR_RESOURCE_UNAVAILABLE, "No GLX extension");
|
|
Packit |
971217 |
goto failure;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
if (!glXQueryVersion (device, &context_glx->priv->glx_major,
|
|
Packit |
971217 |
&context_glx->priv->glx_minor)) {
|
|
Packit |
971217 |
g_set_error (error, GST_GL_CONTEXT_ERROR,
|
|
Packit |
971217 |
GST_GL_CONTEXT_ERROR_CREATE_CONTEXT,
|
|
Packit |
971217 |
"Failed to query GLX version (glXQueryVersion failed)");
|
|
Packit |
971217 |
goto failure;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
GST_INFO ("GLX Version: %d.%d", context_glx->priv->glx_major,
|
|
Packit |
971217 |
context_glx->priv->glx_minor);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
/* legacy case */
|
|
Packit |
971217 |
if (context_glx->priv->glx_major < 1 || (context_glx->priv->glx_major == 1
|
|
Packit |
971217 |
&& context_glx->priv->glx_minor < 3)) {
|
|
Packit |
971217 |
gint attribs[] = {
|
|
Packit |
971217 |
GLX_RGBA,
|
|
Packit |
971217 |
GLX_RED_SIZE, 1,
|
|
Packit |
971217 |
GLX_GREEN_SIZE, 1,
|
|
Packit |
971217 |
GLX_BLUE_SIZE, 1,
|
|
Packit |
971217 |
GLX_DEPTH_SIZE, 16,
|
|
Packit |
971217 |
GLX_DOUBLEBUFFER,
|
|
Packit |
971217 |
None
|
|
Packit |
971217 |
};
|
|
Packit |
971217 |
|
|
Packit |
971217 |
window_x11->visual_info = glXChooseVisual (device,
|
|
Packit |
971217 |
window_x11->screen_num, attribs);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
if (!window_x11->visual_info) {
|
|
Packit |
971217 |
g_set_error (error, GST_GL_CONTEXT_ERROR,
|
|
Packit |
971217 |
GST_GL_CONTEXT_ERROR_WRONG_CONFIG,
|
|
Packit |
971217 |
"Bad attributes in glXChooseVisual");
|
|
Packit |
971217 |
goto failure;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
} else {
|
|
Packit |
971217 |
gint attribs[] = {
|
|
Packit |
971217 |
GLX_RENDER_TYPE, GLX_RGBA_BIT,
|
|
Packit |
971217 |
GLX_RED_SIZE, 1,
|
|
Packit |
971217 |
GLX_GREEN_SIZE, 1,
|
|
Packit |
971217 |
GLX_BLUE_SIZE, 1,
|
|
Packit |
971217 |
GLX_DEPTH_SIZE, 16,
|
|
Packit |
971217 |
GLX_DOUBLEBUFFER, True,
|
|
Packit |
971217 |
None
|
|
Packit |
971217 |
};
|
|
Packit |
971217 |
int fbcount;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
context_glx->priv->fbconfigs = glXChooseFBConfig (device,
|
|
Packit |
971217 |
DefaultScreen (device), attribs, &fbcount);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
if (!context_glx->priv->fbconfigs) {
|
|
Packit |
971217 |
g_set_error (error, GST_GL_CONTEXT_ERROR,
|
|
Packit |
971217 |
GST_GL_CONTEXT_ERROR_WRONG_CONFIG,
|
|
Packit |
971217 |
"Could not find any FBConfig's to use (check attributes?)");
|
|
Packit |
971217 |
goto failure;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
_describe_fbconfig (device, context_glx->priv->fbconfigs[0]);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
window_x11->visual_info = glXGetVisualFromFBConfig (device,
|
|
Packit |
971217 |
context_glx->priv->fbconfigs[0]);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
if (!window_x11->visual_info) {
|
|
Packit |
971217 |
g_set_error (error, GST_GL_CONTEXT_ERROR,
|
|
Packit |
971217 |
GST_GL_CONTEXT_ERROR_WRONG_CONFIG, "Bad attributes in FBConfig");
|
|
Packit |
971217 |
goto failure;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
gst_gl_window_x11_create_window ((GstGLWindowX11 *) window);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
gst_object_unref (window);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
return TRUE;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
failure:
|
|
Packit |
971217 |
if (window)
|
|
Packit |
971217 |
gst_object_unref (window);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
return FALSE;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
static void
|
|
Packit |
971217 |
gst_gl_context_glx_swap_buffers (GstGLContext * context)
|
|
Packit |
971217 |
{
|
|
Packit |
971217 |
GstGLWindow *window = gst_gl_context_get_window (context);
|
|
Packit |
971217 |
Display *device = (Display *) gst_gl_display_get_handle (window->display);
|
|
Packit |
971217 |
Window window_handle = (Window) gst_gl_window_get_window_handle (window);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
glXSwapBuffers (device, window_handle);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
gst_object_unref (window);
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
static guintptr
|
|
Packit |
971217 |
gst_gl_context_glx_get_gl_context (GstGLContext * context)
|
|
Packit |
971217 |
{
|
|
Packit |
971217 |
return (guintptr) GST_GL_CONTEXT_GLX (context)->glx_context;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
static gboolean
|
|
Packit |
971217 |
gst_gl_context_glx_activate (GstGLContext * context, gboolean activate)
|
|
Packit |
971217 |
{
|
|
Packit |
971217 |
GstGLWindow *window = gst_gl_context_get_window (context);
|
|
Packit |
971217 |
Display *device = (Display *) gst_gl_display_get_handle (window->display);
|
|
Packit |
971217 |
Window window_handle = (Window) gst_gl_window_get_window_handle (window);
|
|
Packit |
971217 |
gboolean result;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
if (activate) {
|
|
Packit |
971217 |
result = glXMakeCurrent (device, window_handle,
|
|
Packit |
971217 |
GST_GL_CONTEXT_GLX (context)->glx_context);
|
|
Packit |
971217 |
} else {
|
|
Packit |
971217 |
result = glXMakeCurrent (device, None, NULL);
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
gst_object_unref (window);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
return result;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
GstGLAPI
|
|
Packit |
971217 |
gst_gl_context_glx_get_gl_api (GstGLContext * context)
|
|
Packit |
971217 |
{
|
|
Packit |
971217 |
GstGLContextGLX *context_glx;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
context_glx = GST_GL_CONTEXT_GLX (context);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
return context_glx->priv->context_api;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
static GstGLPlatform
|
|
Packit |
971217 |
gst_gl_context_glx_get_gl_platform (GstGLContext * context)
|
|
Packit |
971217 |
{
|
|
Packit |
971217 |
return GST_GL_PLATFORM_GLX;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
gpointer
|
|
Packit |
971217 |
gst_gl_context_glx_get_proc_address (GstGLAPI gl_api, const gchar * name)
|
|
Packit |
971217 |
{
|
|
Packit |
971217 |
gpointer result;
|
|
Packit |
971217 |
|
|
Packit |
971217 |
if (!(result = gst_gl_context_default_get_proc_address (gl_api, name))) {
|
|
Packit |
971217 |
result = glXGetProcAddressARB ((const GLubyte *) name);
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
return result;
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
guintptr
|
|
Packit |
971217 |
gst_gl_context_glx_get_current_context (void)
|
|
Packit |
971217 |
{
|
|
Packit |
971217 |
return (guintptr) glXGetCurrentContext ();
|
|
Packit |
971217 |
}
|
|
Packit |
971217 |
|
|
Packit |
971217 |
static void
|
|
Packit |
971217 |
gst_gl_context_glx_get_gl_platform_version (GstGLContext * context,
|
|
Packit |
971217 |
gint * major, gint * minor)
|
|
Packit |
971217 |
{
|
|
Packit |
971217 |
GstGLContextGLX *context_glx = GST_GL_CONTEXT_GLX (context);
|
|
Packit |
971217 |
|
|
Packit |
971217 |
*major = context_glx->priv->glx_major;
|
|
Packit |
971217 |
*minor = context_glx->priv->glx_minor;
|
|
Packit |
971217 |
}
|