2008-11-05 01:06:33 +00:00
|
|
|
/*
|
|
|
|
* GStreamer
|
|
|
|
* Copyright (C) 2008 Julien Isorce <julien.isorce@gmail.com>
|
2012-11-14 09:36:16 +00:00
|
|
|
* Copyright (C) 2012 Matthew Waters <ystreet00@gmail.com>
|
2008-11-05 01:06:33 +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-11-05 01:06:33 +00:00
|
|
|
*/
|
|
|
|
|
2012-06-05 09:10:19 +00:00
|
|
|
#define GLIB_DISABLE_DEPRECATION_WARNINGS
|
|
|
|
|
2008-11-05 01:06:33 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
#include <gst/gst.h>
|
2008-11-29 21:16:44 +00:00
|
|
|
#include <locale.h>
|
|
|
|
|
2013-07-02 12:06:03 +00:00
|
|
|
#include "x11_event_source.h"
|
2012-11-13 11:12:20 +00:00
|
|
|
#include "gstglwindow_x11.h"
|
|
|
|
|
2013-01-09 14:13:23 +00:00
|
|
|
#if GST_GL_HAVE_PLATFORM_GLX
|
2012-11-13 11:12:20 +00:00
|
|
|
# include "gstglwindow_x11_glx.h"
|
|
|
|
#endif
|
2013-01-09 14:13:23 +00:00
|
|
|
#if GST_GL_HAVE_PLATFORM_EGL
|
2012-11-13 11:12:20 +00:00
|
|
|
# include "gstglwindow_x11_egl.h"
|
|
|
|
#endif
|
2008-11-05 01:06:33 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
#define GST_GL_WINDOW_X11_GET_PRIVATE(o) \
|
|
|
|
(G_TYPE_INSTANCE_GET_PRIVATE((o), GST_GL_TYPE_WINDOW_X11, GstGLWindowX11Private))
|
2008-11-05 01:06:33 +00:00
|
|
|
|
2012-12-08 22:30:48 +00:00
|
|
|
#define GST_CAT_DEFAULT gst_gl_window_debug
|
2008-11-25 00:01:01 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
#define gst_gl_window_x11_parent_class parent_class
|
2013-02-12 12:48:36 +00:00
|
|
|
G_DEFINE_ABSTRACT_TYPE (GstGLWindowX11, gst_gl_window_x11, GST_GL_TYPE_WINDOW);
|
2008-11-25 00:01:01 +00:00
|
|
|
|
2013-06-03 08:15:45 +00:00
|
|
|
/* X error trap */
|
|
|
|
static int TrappedErrorCode = 0;
|
|
|
|
static int (*old_error_handler) (Display *, XErrorEvent *);
|
|
|
|
|
2008-11-05 01:06:33 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
ARG_0,
|
|
|
|
ARG_DISPLAY
|
|
|
|
};
|
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
struct _GstGLWindowX11Private
|
2008-11-05 01:06:33 +00:00
|
|
|
{
|
2012-11-13 11:12:20 +00:00
|
|
|
gboolean activate;
|
|
|
|
gboolean activate_result;
|
2008-11-05 01:06:33 +00:00
|
|
|
};
|
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
guintptr gst_gl_window_x11_get_gl_context (GstGLWindow * window);
|
|
|
|
gboolean gst_gl_window_x11_activate (GstGLWindow * window, gboolean activate);
|
|
|
|
void gst_gl_window_x11_set_window_handle (GstGLWindow * window,
|
|
|
|
guintptr handle);
|
|
|
|
void gst_gl_window_x11_draw_unlocked (GstGLWindow * window, guint width,
|
|
|
|
guint height);
|
|
|
|
void gst_gl_window_x11_draw (GstGLWindow * window, guint width, guint height);
|
|
|
|
void gst_gl_window_x11_run (GstGLWindow * window);
|
2013-07-15 13:58:04 +00:00
|
|
|
void gst_gl_window_x11_quit (GstGLWindow * window);
|
2012-11-13 11:12:20 +00:00
|
|
|
void gst_gl_window_x11_send_message (GstGLWindow * window,
|
|
|
|
GstGLWindowCB callback, gpointer data);
|
2013-02-12 12:48:36 +00:00
|
|
|
gboolean gst_gl_window_x11_create_context (GstGLWindow * window,
|
|
|
|
GstGLAPI gl_api, guintptr external_gl_context, GError ** error);
|
2013-06-13 06:04:40 +00:00
|
|
|
gboolean gst_gl_window_x11_open (GstGLWindow * window, GError ** error);
|
|
|
|
void gst_gl_window_x11_close (GstGLWindow * window);
|
2012-11-13 11:12:20 +00:00
|
|
|
|
|
|
|
static gboolean gst_gl_window_x11_create_window (GstGLWindowX11 * window_x11);
|
2010-01-05 23:13:46 +00:00
|
|
|
|
2008-11-05 01:06:33 +00:00
|
|
|
static void
|
2012-11-13 11:12:20 +00:00
|
|
|
gst_gl_window_x11_set_property (GObject * object, guint prop_id,
|
2008-11-05 01:06:33 +00:00
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2012-11-13 11:12:20 +00:00
|
|
|
GstGLWindowX11 *window_x11;
|
2008-11-05 01:06:33 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
g_return_if_fail (GST_GL_IS_WINDOW_X11 (object));
|
2008-11-05 01:06:33 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
window_x11 = GST_GL_WINDOW_X11 (object);
|
2008-11-05 01:06:33 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case ARG_DISPLAY:
|
2012-11-13 11:12:20 +00:00
|
|
|
window_x11->display_name = g_strdup (g_value_get_string (value));
|
2008-11-05 01:06:33 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-11-13 11:12:20 +00:00
|
|
|
gst_gl_window_x11_get_property (GObject * object, guint prop_id,
|
2008-11-05 01:06:33 +00:00
|
|
|
GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
2012-11-13 11:12:20 +00:00
|
|
|
GstGLWindowX11 *window_x11;
|
2008-11-05 01:06:33 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
g_return_if_fail (GST_GL_IS_WINDOW_X11 (object));
|
2008-11-05 01:06:33 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
window_x11 = GST_GL_WINDOW_X11 (object);
|
2008-11-05 01:06:33 +00:00
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case ARG_DISPLAY:
|
2012-11-13 11:12:20 +00:00
|
|
|
g_value_set_string (value, window_x11->display_name);
|
2008-11-05 01:06:33 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-11-13 11:12:20 +00:00
|
|
|
gst_gl_window_x11_class_init (GstGLWindowX11Class * klass)
|
2008-11-05 01:06:33 +00:00
|
|
|
{
|
|
|
|
GObjectClass *obj_class = G_OBJECT_CLASS (klass);
|
2012-11-13 11:12:20 +00:00
|
|
|
GstGLWindowClass *window_class = (GstGLWindowClass *) klass;
|
2008-11-05 01:06:33 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
g_type_class_add_private (klass, sizeof (GstGLWindowX11Private));
|
2008-11-05 01:06:33 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
obj_class->set_property = gst_gl_window_x11_set_property;
|
|
|
|
obj_class->get_property = gst_gl_window_x11_get_property;
|
2008-11-05 01:06:33 +00:00
|
|
|
|
|
|
|
g_object_class_install_property (obj_class, ARG_DISPLAY,
|
|
|
|
g_param_spec_string ("display", "Display", "X Display name", NULL,
|
|
|
|
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
|
2012-11-13 11:12:20 +00:00
|
|
|
|
2013-02-12 12:48:36 +00:00
|
|
|
window_class->create_context =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_gl_window_x11_create_context);
|
2012-11-13 11:12:20 +00:00
|
|
|
window_class->get_gl_context =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_gl_window_x11_get_gl_context);
|
|
|
|
window_class->activate = GST_DEBUG_FUNCPTR (gst_gl_window_x11_activate);
|
|
|
|
window_class->set_window_handle =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_gl_window_x11_set_window_handle);
|
|
|
|
window_class->draw_unlocked =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_gl_window_x11_draw_unlocked);
|
|
|
|
window_class->draw = GST_DEBUG_FUNCPTR (gst_gl_window_x11_draw);
|
|
|
|
window_class->run = GST_DEBUG_FUNCPTR (gst_gl_window_x11_run);
|
|
|
|
window_class->quit = GST_DEBUG_FUNCPTR (gst_gl_window_x11_quit);
|
|
|
|
window_class->send_message =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_gl_window_x11_send_message);
|
2013-06-13 06:04:40 +00:00
|
|
|
window_class->open = GST_DEBUG_FUNCPTR (gst_gl_window_x11_open);
|
|
|
|
window_class->close = GST_DEBUG_FUNCPTR (gst_gl_window_x11_close);
|
2008-11-05 01:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-11-13 11:12:20 +00:00
|
|
|
gst_gl_window_x11_init (GstGLWindowX11 * window)
|
2008-11-05 01:06:33 +00:00
|
|
|
{
|
2012-11-13 11:12:20 +00:00
|
|
|
window->priv = GST_GL_WINDOW_X11_GET_PRIVATE (window);
|
2008-11-05 01:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Must be called in the gl thread */
|
2012-11-13 11:12:20 +00:00
|
|
|
GstGLWindowX11 *
|
2013-02-12 12:48:36 +00:00
|
|
|
gst_gl_window_x11_new (void)
|
2008-11-05 01:06:33 +00:00
|
|
|
{
|
2012-11-13 11:12:20 +00:00
|
|
|
GstGLWindowX11 *window = NULL;
|
|
|
|
const gchar *user_choice;
|
|
|
|
|
|
|
|
user_choice = g_getenv ("GST_GL_PLATFORM");
|
|
|
|
|
2013-02-12 12:48:36 +00:00
|
|
|
GST_INFO ("Attempting to create x11 window, user platform choice:%s",
|
|
|
|
user_choice ? user_choice : "(null)");
|
|
|
|
|
2013-01-09 14:13:23 +00:00
|
|
|
#if GST_GL_HAVE_PLATFORM_GLX
|
2012-11-19 11:54:19 +00:00
|
|
|
if (!window && (!user_choice || g_strstr_len (user_choice, 3, "glx") != NULL))
|
2013-02-12 12:48:36 +00:00
|
|
|
window = GST_GL_WINDOW_X11 (gst_gl_window_x11_glx_new ());
|
2013-01-09 14:13:23 +00:00
|
|
|
#endif /* GST_GL_HAVE_PLATFORM_GLX */
|
|
|
|
#ifdef GST_GL_HAVE_PLATFORM_EGL
|
2012-11-19 11:54:19 +00:00
|
|
|
if (!window && (!user_choice || g_strstr_len (user_choice, 3, "egl") != NULL))
|
2013-02-12 12:48:36 +00:00
|
|
|
window = GST_GL_WINDOW_X11 (gst_gl_window_x11_egl_new ());
|
2013-01-09 14:13:23 +00:00
|
|
|
#endif /* GST_GL_HAVE_PLATFORM_EGL */
|
2012-11-13 11:12:20 +00:00
|
|
|
if (!window) {
|
|
|
|
GST_WARNING ("Failed to create x11 window, user_choice:%s",
|
|
|
|
user_choice ? user_choice : "NULL");
|
|
|
|
return NULL;
|
|
|
|
}
|
2008-11-18 23:07:22 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
return window;
|
|
|
|
}
|
2008-11-05 01:06:33 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
gboolean
|
2013-06-13 06:04:40 +00:00
|
|
|
gst_gl_window_x11_open (GstGLWindow * window, GError ** error)
|
2012-11-13 11:12:20 +00:00
|
|
|
{
|
2013-02-12 12:48:36 +00:00
|
|
|
GstGLWindowX11 *window_x11 = GST_GL_WINDOW_X11 (window);
|
2012-11-13 11:12:20 +00:00
|
|
|
|
|
|
|
window_x11->device = XOpenDisplay (window_x11->display_name);
|
|
|
|
if (window_x11->device == NULL) {
|
2012-12-08 22:30:48 +00:00
|
|
|
g_set_error (error, GST_GL_WINDOW_ERROR,
|
|
|
|
GST_GL_WINDOW_ERROR_RESOURCE_UNAVAILABLE,
|
|
|
|
"Failed to connect to X display server");
|
2012-04-13 13:08:00 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
2008-11-11 02:19:51 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
XSynchronize (window_x11->device, FALSE);
|
2008-11-20 00:24:10 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
GST_LOG ("gl device id: %ld", (gulong) window_x11->device);
|
2008-11-11 02:19:51 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
window_x11->disp_send = XOpenDisplay (window_x11->display_name);
|
2008-11-21 18:37:21 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
XSynchronize (window_x11->disp_send, FALSE);
|
2008-11-21 18:37:21 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
GST_LOG ("gl display sender: %ld", (gulong) window_x11->disp_send);
|
2008-11-21 18:37:21 +00:00
|
|
|
|
2013-06-13 06:04:40 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
failure:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gst_gl_window_x11_create_context (GstGLWindow * window,
|
|
|
|
GstGLAPI gl_api, guintptr external_gl_context, GError ** error)
|
|
|
|
{
|
|
|
|
GstGLWindowX11 *window_x11 = GST_GL_WINDOW_X11 (window);
|
|
|
|
GstGLWindowX11Class *window_class = GST_GL_WINDOW_X11_GET_CLASS (window_x11);
|
|
|
|
|
|
|
|
setlocale (LC_NUMERIC, "C");
|
|
|
|
|
2013-07-02 12:06:03 +00:00
|
|
|
gst_gl_window_set_need_lock (GST_GL_WINDOW (window_x11), FALSE);
|
2013-06-13 06:04:40 +00:00
|
|
|
|
|
|
|
window_x11->running = TRUE;
|
|
|
|
window_x11->visible = FALSE;
|
|
|
|
window_x11->allow_extra_expose_events = TRUE;
|
|
|
|
|
|
|
|
g_assert (window_x11->device);
|
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
window_x11->screen = DefaultScreenOfDisplay (window_x11->device);
|
|
|
|
window_x11->screen_num = DefaultScreen (window_x11->device);
|
|
|
|
window_x11->visual =
|
|
|
|
DefaultVisual (window_x11->device, window_x11->screen_num);
|
|
|
|
window_x11->root = DefaultRootWindow (window_x11->device);
|
|
|
|
window_x11->white = XWhitePixel (window_x11->device, window_x11->screen_num);
|
|
|
|
window_x11->black = XBlackPixel (window_x11->device, window_x11->screen_num);
|
|
|
|
window_x11->depth = DefaultDepthOfScreen (window_x11->screen);
|
2008-11-05 01:06:33 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
GST_LOG ("gl root id: %lud", (gulong) window_x11->root);
|
2008-11-15 01:24:07 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
window_x11->device_width =
|
|
|
|
DisplayWidth (window_x11->device, window_x11->screen_num);
|
|
|
|
window_x11->device_height =
|
|
|
|
DisplayHeight (window_x11->device, window_x11->screen_num);
|
2008-11-05 01:06:33 +00:00
|
|
|
|
2013-07-02 12:06:03 +00:00
|
|
|
window_x11->x11_source = x11_event_source_new (window_x11);
|
|
|
|
window_x11->main_context = g_main_context_new ();
|
|
|
|
window_x11->loop = g_main_loop_new (window_x11->main_context, FALSE);
|
|
|
|
|
|
|
|
g_source_attach (window_x11->x11_source, window_x11->main_context);
|
2008-11-05 01:06:33 +00:00
|
|
|
|
2012-12-08 22:30:48 +00:00
|
|
|
if (!window_class->choose_format (window_x11, error)) {
|
2012-04-13 13:08:00 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
2008-11-18 23:07:22 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
gst_gl_window_x11_create_window (window_x11);
|
|
|
|
|
2012-12-08 22:30:48 +00:00
|
|
|
if (!window_class->create_context (window_x11, gl_api, external_gl_context,
|
|
|
|
error)) {
|
2012-11-13 11:12:20 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
2008-11-05 01:06:33 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
if (!window_class->activate (window_x11, TRUE)) {
|
2012-12-08 22:30:48 +00:00
|
|
|
g_set_error (error, GST_GL_WINDOW_ERROR, GST_GL_WINDOW_ERROR_CREATE_CONTEXT,
|
|
|
|
"Failed to make context current");
|
2012-04-13 13:08:00 +00:00
|
|
|
goto failure;
|
2008-12-14 00:36:32 +00:00
|
|
|
}
|
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
failure:
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gst_gl_window_x11_create_window (GstGLWindowX11 * window_x11)
|
|
|
|
{
|
|
|
|
XSetWindowAttributes win_attr;
|
|
|
|
XTextProperty text_property;
|
|
|
|
XWMHints wm_hints;
|
|
|
|
unsigned long mask;
|
|
|
|
const gchar *title = "OpenGL renderer";
|
2013-07-02 12:06:03 +00:00
|
|
|
Atom wm_atoms[1];
|
2013-07-11 19:15:41 +00:00
|
|
|
gint x = 0, y = 0, width = 1, height = 1;
|
2008-11-18 23:07:22 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
if (window_x11->visual_info->visual != window_x11->visual)
|
|
|
|
GST_LOG ("selected visual is different from the default");
|
|
|
|
|
2013-01-08 06:36:18 +00:00
|
|
|
GST_LOG ("visual XID:%d, screen:%d, visualid:%d, depth:%d, class:%d, "
|
|
|
|
"red_mask:%ld, green_mask:%ld, blue_mask:%ld bpp:%d",
|
|
|
|
(gint) XVisualIDFromVisual (window_x11->visual_info->visual),
|
|
|
|
window_x11->visual_info->screen, (gint) window_x11->visual_info->visualid,
|
|
|
|
window_x11->visual_info->depth, window_x11->visual_info->class,
|
|
|
|
window_x11->visual_info->red_mask, window_x11->visual_info->green_mask,
|
|
|
|
window_x11->visual_info->blue_mask,
|
2012-11-13 11:12:20 +00:00
|
|
|
window_x11->visual_info->bits_per_rgb);
|
2008-11-18 23:07:22 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
win_attr.event_mask =
|
|
|
|
StructureNotifyMask | ExposureMask | VisibilityChangeMask;
|
2008-11-21 23:51:30 +00:00
|
|
|
win_attr.do_not_propagate_mask = NoEventMask;
|
2008-11-05 01:06:33 +00:00
|
|
|
|
|
|
|
win_attr.background_pixmap = None;
|
|
|
|
win_attr.background_pixel = 0;
|
|
|
|
win_attr.border_pixel = 0;
|
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
win_attr.colormap =
|
2012-11-13 11:12:20 +00:00
|
|
|
XCreateColormap (window_x11->device, window_x11->root,
|
|
|
|
window_x11->visual_info->visual, AllocNone);
|
2008-11-05 01:06:33 +00:00
|
|
|
|
|
|
|
mask = CWBackPixmap | CWBorderPixel | CWColormap | CWEventMask;
|
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
window_x11->internal_win_id =
|
2013-07-11 19:15:41 +00:00
|
|
|
XCreateWindow (window_x11->device,
|
|
|
|
window_x11->parent_win ? window_x11->parent_win : window_x11->root,
|
|
|
|
x, y, width, height, 0,
|
2012-11-13 11:12:20 +00:00
|
|
|
window_x11->visual_info->depth, InputOutput,
|
|
|
|
window_x11->visual_info->visual, mask, &win_attr);
|
2009-10-23 08:52:39 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
XSync (window_x11->device, FALSE);
|
2008-11-13 00:23:51 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
XSetWindowBackgroundPixmap (window_x11->device, window_x11->internal_win_id,
|
|
|
|
None);
|
2008-11-15 01:24:07 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
GST_LOG ("gl window id: %lud", (gulong) window_x11->internal_win_id);
|
|
|
|
GST_LOG ("gl window props: x:%d y:%d", x, y);
|
2008-12-07 02:25:59 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
wm_atoms[0] = XInternAtom (window_x11->device, "WM_DELETE_WINDOW", True);
|
2008-11-21 00:31:19 +00:00
|
|
|
if (wm_atoms[0] == None)
|
2012-11-13 11:12:20 +00:00
|
|
|
GST_DEBUG ("Cannot create WM_DELETE_WINDOW");
|
2008-11-15 01:24:07 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
XSetWMProtocols (window_x11->device, window_x11->internal_win_id, wm_atoms,
|
2013-07-02 12:06:03 +00:00
|
|
|
1);
|
2008-11-05 01:06:33 +00:00
|
|
|
|
|
|
|
wm_hints.flags = StateHint;
|
|
|
|
wm_hints.initial_state = NormalState;
|
2008-11-15 22:32:04 +00:00
|
|
|
wm_hints.input = False;
|
2008-11-05 01:06:33 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
XStringListToTextProperty ((char **) &title, 1, &text_property);
|
2008-11-05 01:06:33 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
XSetWMProperties (window_x11->device, window_x11->internal_win_id,
|
|
|
|
&text_property, &text_property, 0, 0, NULL, &wm_hints, NULL);
|
2008-11-05 01:06:33 +00:00
|
|
|
|
|
|
|
XFree (text_property.value);
|
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
return TRUE;
|
2008-11-05 01:06:33 +00:00
|
|
|
}
|
|
|
|
|
2013-06-13 06:04:40 +00:00
|
|
|
void
|
|
|
|
gst_gl_window_x11_close (GstGLWindow * window)
|
|
|
|
{
|
|
|
|
GstGLWindowX11 *window_x11 = GST_GL_WINDOW_X11 (window);
|
|
|
|
GstGLWindowX11Class *window_class = GST_GL_WINDOW_X11_GET_CLASS (window_x11);
|
|
|
|
XEvent event;
|
|
|
|
Bool ret = TRUE;
|
|
|
|
|
|
|
|
GST_GL_WINDOW_LOCK (window_x11);
|
|
|
|
|
|
|
|
if (window_x11->device) {
|
|
|
|
if (window_x11->internal_win_id)
|
|
|
|
XUnmapWindow (window_x11->device, window_x11->internal_win_id);
|
|
|
|
|
|
|
|
ret = window_class->activate (window_x11, FALSE);
|
|
|
|
if (!ret)
|
|
|
|
GST_DEBUG ("failed to release opengl context");
|
|
|
|
window_class->destroy_context (window_x11);
|
|
|
|
|
|
|
|
XFree (window_x11->visual_info);
|
|
|
|
|
|
|
|
if (window_x11->internal_win_id) {
|
|
|
|
XReparentWindow (window_x11->device, window_x11->internal_win_id,
|
|
|
|
window_x11->root, 0, 0);
|
|
|
|
XDestroyWindow (window_x11->device, window_x11->internal_win_id);
|
|
|
|
}
|
|
|
|
XSync (window_x11->device, FALSE);
|
|
|
|
|
|
|
|
while (XPending (window_x11->device))
|
|
|
|
XNextEvent (window_x11->device, &event);
|
|
|
|
|
|
|
|
XSetCloseDownMode (window_x11->device, DestroyAll);
|
|
|
|
|
|
|
|
/*XAddToSaveSet (display, w)
|
|
|
|
Display *display;
|
|
|
|
Window w; */
|
|
|
|
|
|
|
|
//FIXME: it seems it causes destroy all created windows, even by other display connection:
|
|
|
|
//This is case in: gst-launch-0.10 videotestsrc ! tee name=t t. ! queue ! glimagesink t. ! queue ! glimagesink
|
|
|
|
//When the first window is closed and so its display is closed by the following line, then the other Window managed by the
|
|
|
|
//other glimagesink, is not useable and so each opengl call causes a segmentation fault.
|
|
|
|
//Maybe the solution is to use: XAddToSaveSet
|
|
|
|
//The following line is commented to avoid the disagreement explained before.
|
|
|
|
//XCloseDisplay (window_x11->device);
|
|
|
|
|
|
|
|
GST_DEBUG ("display receiver closed");
|
|
|
|
XCloseDisplay (window_x11->disp_send);
|
|
|
|
GST_DEBUG ("display sender closed");
|
|
|
|
}
|
|
|
|
|
2013-07-11 18:58:36 +00:00
|
|
|
g_source_destroy (window_x11->x11_source);
|
|
|
|
g_source_unref (window_x11->x11_source);
|
|
|
|
window_x11->x11_source = NULL;
|
|
|
|
g_main_loop_unref (window_x11->loop);
|
|
|
|
window_x11->loop = NULL, g_main_context_unref (window_x11->main_context);
|
|
|
|
window_x11->main_context = NULL;
|
|
|
|
|
|
|
|
window_x11->running = FALSE;
|
|
|
|
|
2013-06-13 06:04:40 +00:00
|
|
|
GST_GL_WINDOW_UNLOCK (window_x11);
|
|
|
|
}
|
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
guintptr
|
|
|
|
gst_gl_window_x11_get_gl_context (GstGLWindow * window)
|
2009-10-23 08:52:39 +00:00
|
|
|
{
|
2012-11-13 11:12:20 +00:00
|
|
|
GstGLWindowX11Class *window_class;
|
2009-10-23 08:52:39 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
window_class = GST_GL_WINDOW_X11_GET_CLASS (window);
|
2009-10-23 08:52:39 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
return window_class->get_gl_context (GST_GL_WINDOW_X11 (window));
|
2009-10-23 08:52:39 +00:00
|
|
|
}
|
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
static void
|
|
|
|
callback_activate (GstGLWindow * window)
|
2008-11-05 01:06:33 +00:00
|
|
|
{
|
2012-11-13 11:12:20 +00:00
|
|
|
GstGLWindowX11Class *window_class;
|
|
|
|
GstGLWindowX11Private *priv;
|
|
|
|
GstGLWindowX11 *window_x11;
|
2008-11-21 19:51:48 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
window_x11 = GST_GL_WINDOW_X11 (window);
|
|
|
|
window_class = GST_GL_WINDOW_X11_GET_CLASS (window_x11);
|
|
|
|
priv = window_x11->priv;
|
2008-11-21 23:51:30 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
priv->activate_result = window_class->activate (window_x11, priv->activate);
|
2008-11-05 01:06:33 +00:00
|
|
|
}
|
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
gboolean
|
|
|
|
gst_gl_window_x11_activate (GstGLWindow * window, gboolean activate)
|
2008-11-05 01:06:33 +00:00
|
|
|
{
|
2012-11-13 11:12:20 +00:00
|
|
|
GstGLWindowX11 *window_x11;
|
|
|
|
GstGLWindowX11Private *priv;
|
2008-11-05 01:06:33 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
window_x11 = GST_GL_WINDOW_X11 (window);
|
|
|
|
priv = window_x11->priv;
|
|
|
|
priv->activate = activate;
|
2008-11-13 00:23:51 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
gst_gl_window_x11_send_message (window, GST_GL_WINDOW_CB (callback_activate),
|
|
|
|
window_x11);
|
2008-11-13 00:23:51 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
return priv->activate_result;
|
2008-11-05 01:06:33 +00:00
|
|
|
}
|
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
/* Not called by the gl thread */
|
2008-11-05 01:06:33 +00:00
|
|
|
void
|
2012-11-13 11:12:20 +00:00
|
|
|
gst_gl_window_x11_set_window_handle (GstGLWindow * window, guintptr id)
|
2008-11-05 01:06:33 +00:00
|
|
|
{
|
2012-11-13 11:12:20 +00:00
|
|
|
GstGLWindowX11 *window_x11;
|
|
|
|
XWindowAttributes attr;
|
2008-11-05 01:06:33 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
window_x11 = GST_GL_WINDOW_X11 (window);
|
2008-11-13 00:23:51 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
window_x11->parent_win = (Window) id;
|
2008-11-13 00:23:51 +00:00
|
|
|
|
2013-07-11 19:15:41 +00:00
|
|
|
if (window_x11->running) {
|
|
|
|
GST_LOG ("set parent window id: %lud", id);
|
2008-11-05 01:06:33 +00:00
|
|
|
|
2013-07-11 19:15:41 +00:00
|
|
|
XGetWindowAttributes (window_x11->disp_send, window_x11->parent_win, &attr);
|
2008-11-05 01:06:33 +00:00
|
|
|
|
2013-07-11 19:15:41 +00:00
|
|
|
XResizeWindow (window_x11->disp_send, window_x11->internal_win_id,
|
|
|
|
attr.width, attr.height);
|
2008-11-13 00:23:51 +00:00
|
|
|
|
2013-07-11 19:15:41 +00:00
|
|
|
XReparentWindow (window_x11->disp_send, window_x11->internal_win_id,
|
|
|
|
window_x11->parent_win, 0, 0);
|
2008-11-13 00:23:51 +00:00
|
|
|
|
2013-07-11 19:15:41 +00:00
|
|
|
XSync (window_x11->disp_send, FALSE);
|
|
|
|
}
|
2008-11-05 01:06:33 +00:00
|
|
|
}
|
|
|
|
|
2008-11-25 00:01:01 +00:00
|
|
|
/* Called in the gl thread */
|
2008-11-23 15:04:27 +00:00
|
|
|
void
|
2012-11-13 11:12:20 +00:00
|
|
|
gst_gl_window_x11_draw_unlocked (GstGLWindow * window, guint width,
|
|
|
|
guint height)
|
2008-11-23 15:04:27 +00:00
|
|
|
{
|
2012-11-13 11:12:20 +00:00
|
|
|
GstGLWindowX11 *window_x11;
|
|
|
|
|
|
|
|
window_x11 = GST_GL_WINDOW_X11 (window);
|
2008-11-23 15:04:27 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
if (window_x11->running && window_x11->allow_extra_expose_events) {
|
2008-11-23 15:04:27 +00:00
|
|
|
XEvent event;
|
|
|
|
XWindowAttributes attr;
|
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
XGetWindowAttributes (window_x11->device, window_x11->internal_win_id,
|
|
|
|
&attr);
|
2008-11-23 15:04:27 +00:00
|
|
|
|
|
|
|
event.xexpose.type = Expose;
|
|
|
|
event.xexpose.send_event = TRUE;
|
2012-11-13 11:12:20 +00:00
|
|
|
event.xexpose.display = window_x11->device;
|
|
|
|
event.xexpose.window = window_x11->internal_win_id;
|
2008-11-23 15:04:27 +00:00
|
|
|
event.xexpose.x = attr.x;
|
|
|
|
event.xexpose.y = attr.y;
|
|
|
|
event.xexpose.width = attr.width;
|
|
|
|
event.xexpose.height = attr.height;
|
|
|
|
event.xexpose.count = 0;
|
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
XSendEvent (window_x11->device, window_x11->internal_win_id, FALSE,
|
|
|
|
ExposureMask, &event);
|
|
|
|
XSync (window_x11->disp_send, FALSE);
|
2008-11-23 15:04:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-25 00:01:01 +00:00
|
|
|
/* Not called by the gl thread */
|
2008-11-05 01:06:33 +00:00
|
|
|
void
|
2012-11-13 11:12:20 +00:00
|
|
|
gst_gl_window_x11_draw (GstGLWindow * window, guint width, guint height)
|
2008-11-05 01:06:33 +00:00
|
|
|
{
|
2012-11-13 11:12:20 +00:00
|
|
|
GstGLWindowX11 *window_x11;
|
2008-11-13 00:23:51 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
window_x11 = GST_GL_WINDOW_X11 (window);
|
2008-11-13 00:23:51 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
if (window_x11->running) {
|
|
|
|
XEvent event;
|
|
|
|
XWindowAttributes attr;
|
2009-10-23 08:52:39 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
XGetWindowAttributes (window_x11->disp_send, window_x11->internal_win_id,
|
|
|
|
&attr);
|
2009-10-23 08:52:39 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
if (!window_x11->visible) {
|
2009-10-23 08:52:39 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
if (!window_x11->parent_win) {
|
|
|
|
attr.width = width;
|
|
|
|
attr.height = height;
|
|
|
|
XResizeWindow (window_x11->disp_send, window_x11->internal_win_id,
|
|
|
|
attr.width, attr.height);
|
|
|
|
XSync (window_x11->disp_send, FALSE);
|
2008-11-17 00:04:32 +00:00
|
|
|
}
|
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
XMapWindow (window_x11->disp_send, window_x11->internal_win_id);
|
|
|
|
window_x11->visible = TRUE;
|
|
|
|
}
|
2008-11-21 23:51:30 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
if (window_x11->parent_win) {
|
|
|
|
XWindowAttributes attr_parent;
|
|
|
|
XGetWindowAttributes (window_x11->disp_send, window_x11->parent_win,
|
|
|
|
&attr_parent);
|
2008-11-21 23:51:30 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
if (attr.width != attr_parent.width || attr.height != attr_parent.height) {
|
|
|
|
XMoveResizeWindow (window_x11->disp_send, window_x11->internal_win_id,
|
|
|
|
0, 0, attr_parent.width, attr_parent.height);
|
|
|
|
XSync (window_x11->disp_send, FALSE);
|
2008-12-07 02:25:59 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
attr.width = attr_parent.width;
|
|
|
|
attr.height = attr_parent.height;
|
2008-11-21 23:51:30 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
GST_LOG ("parent resize: %d, %d",
|
|
|
|
attr_parent.width, attr_parent.height);
|
|
|
|
}
|
2008-11-13 00:23:51 +00:00
|
|
|
}
|
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
event.xexpose.type = Expose;
|
|
|
|
event.xexpose.send_event = TRUE;
|
|
|
|
event.xexpose.display = window_x11->disp_send;
|
|
|
|
event.xexpose.window = window_x11->internal_win_id;
|
|
|
|
event.xexpose.x = attr.x;
|
|
|
|
event.xexpose.y = attr.y;
|
|
|
|
event.xexpose.width = attr.width;
|
|
|
|
event.xexpose.height = attr.height;
|
|
|
|
event.xexpose.count = 0;
|
|
|
|
|
|
|
|
XSendEvent (window_x11->disp_send, window_x11->internal_win_id, FALSE,
|
|
|
|
ExposureMask, &event);
|
|
|
|
XSync (window_x11->disp_send, FALSE);
|
2008-11-13 00:23:51 +00:00
|
|
|
}
|
2008-11-05 01:06:33 +00:00
|
|
|
}
|
|
|
|
|
2013-07-02 12:06:03 +00:00
|
|
|
typedef struct _GstGLMessage
|
|
|
|
{
|
|
|
|
GstGLWindow *window;
|
|
|
|
GMutex lock;
|
|
|
|
GCond cond;
|
|
|
|
gboolean fired;
|
|
|
|
|
|
|
|
GstGLWindowCB callback;
|
|
|
|
gpointer data;
|
|
|
|
} GstGLMessage;
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
_run_message (GstGLMessage * message)
|
|
|
|
{
|
|
|
|
g_mutex_lock (&message->lock);
|
|
|
|
|
|
|
|
if (message->callback)
|
|
|
|
message->callback (message->data);
|
|
|
|
|
|
|
|
message->fired = TRUE;
|
|
|
|
g_cond_signal (&message->cond);
|
|
|
|
g_mutex_unlock (&message->lock);
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2008-11-05 01:06:33 +00:00
|
|
|
void
|
2012-11-13 11:12:20 +00:00
|
|
|
gst_gl_window_x11_run (GstGLWindow * window)
|
2008-11-05 01:06:33 +00:00
|
|
|
{
|
2012-11-13 11:12:20 +00:00
|
|
|
GstGLWindowX11 *window_x11;
|
2008-11-05 01:06:33 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
window_x11 = GST_GL_WINDOW_X11 (window);
|
2008-11-05 01:06:33 +00:00
|
|
|
|
2013-07-02 12:06:03 +00:00
|
|
|
g_main_loop_run (window_x11->loop);
|
|
|
|
}
|
2008-11-13 00:23:51 +00:00
|
|
|
|
2013-07-02 12:06:03 +00:00
|
|
|
void
|
|
|
|
gst_gl_window_x11_handle_event (GstGLWindowX11 * window_x11)
|
|
|
|
{
|
|
|
|
GstGLWindow *window;
|
|
|
|
GstGLWindowX11Class *window_class;
|
2008-11-06 22:41:11 +00:00
|
|
|
|
2013-07-02 12:06:03 +00:00
|
|
|
window = GST_GL_WINDOW (window_x11);
|
|
|
|
window_class = GST_GL_WINDOW_X11_GET_CLASS (window_x11);
|
|
|
|
|
|
|
|
if (window_x11->running && XPending (window_x11->device)) {
|
|
|
|
XEvent event;
|
2008-11-13 00:23:51 +00:00
|
|
|
|
2008-11-15 17:51:44 +00:00
|
|
|
/* XSendEvent (which are called in other threads) are done from another display structure */
|
2012-11-13 11:12:20 +00:00
|
|
|
XNextEvent (window_x11->device, &event);
|
2008-11-14 00:00:33 +00:00
|
|
|
|
2008-11-25 00:01:01 +00:00
|
|
|
// use in generic/cube and other related uses
|
2012-11-13 11:12:20 +00:00
|
|
|
window_x11->allow_extra_expose_events = XPending (window_x11->device) <= 2;
|
2008-11-25 00:01:01 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
switch (event.type) {
|
2008-11-15 17:51:44 +00:00
|
|
|
case ClientMessage:
|
2008-11-13 00:23:51 +00:00
|
|
|
{
|
2012-11-13 11:12:20 +00:00
|
|
|
Atom wm_delete =
|
|
|
|
XInternAtom (window_x11->device, "WM_DELETE_WINDOW", True);
|
2008-11-15 01:24:07 +00:00
|
|
|
|
2008-11-15 17:51:44 +00:00
|
|
|
if (wm_delete == None)
|
2012-11-13 11:12:20 +00:00
|
|
|
GST_DEBUG ("Cannot create WM_DELETE_WINDOW");
|
2008-11-11 02:19:51 +00:00
|
|
|
|
2008-11-25 00:01:01 +00:00
|
|
|
/* User clicked on the cross */
|
2013-07-02 12:06:03 +00:00
|
|
|
if (wm_delete != None && (Atom) event.xclient.data.l[0] == wm_delete) {
|
2012-11-13 11:12:20 +00:00
|
|
|
GST_DEBUG ("Close %lud", (gulong) window_x11->internal_win_id);
|
2008-11-11 02:19:51 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
if (window->close)
|
|
|
|
window->close (window->close_data);
|
2008-11-21 00:31:19 +00:00
|
|
|
}
|
2008-11-15 17:51:44 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-11-06 22:41:11 +00:00
|
|
|
|
2008-11-15 17:51:44 +00:00
|
|
|
case CreateNotify:
|
|
|
|
case ConfigureNotify:
|
|
|
|
{
|
2012-11-13 11:12:20 +00:00
|
|
|
if (window->resize)
|
|
|
|
window->resize (window->resize_data, event.xconfigure.width,
|
2009-02-11 06:39:14 +00:00
|
|
|
event.xconfigure.height);
|
2008-11-15 17:51:44 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case DestroyNotify:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Expose:
|
2012-11-13 11:12:20 +00:00
|
|
|
if (window->draw) {
|
|
|
|
window->draw (window->draw_data);
|
|
|
|
window_class->swap_buffers (window_x11);
|
2008-11-06 00:28:26 +00:00
|
|
|
}
|
2008-11-15 17:51:44 +00:00
|
|
|
break;
|
2008-11-06 22:41:11 +00:00
|
|
|
|
2008-11-15 17:51:44 +00:00
|
|
|
case VisibilityNotify:
|
|
|
|
{
|
2009-02-11 06:39:14 +00:00
|
|
|
switch (event.xvisibility.state) {
|
2008-11-15 17:51:44 +00:00
|
|
|
case VisibilityUnobscured:
|
2012-11-13 11:12:20 +00:00
|
|
|
if (window->draw)
|
|
|
|
window->draw (window->draw_data);
|
2008-11-15 17:51:44 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case VisibilityPartiallyObscured:
|
2012-11-13 11:12:20 +00:00
|
|
|
if (window->draw)
|
|
|
|
window->draw (window->draw_data);
|
2008-11-15 17:51:44 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case VisibilityFullyObscured:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2012-11-13 11:12:20 +00:00
|
|
|
GST_DEBUG ("unknown xvisibility event: %d",
|
2009-02-11 06:39:14 +00:00
|
|
|
event.xvisibility.state);
|
2008-11-15 17:51:44 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2008-11-13 00:23:51 +00:00
|
|
|
|
2008-11-15 17:51:44 +00:00
|
|
|
default:
|
2012-11-13 11:12:20 +00:00
|
|
|
GST_DEBUG ("unknown XEvent type: %ud", event.type);
|
2008-11-15 17:51:44 +00:00
|
|
|
break;
|
2008-11-13 00:23:51 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
} // switch
|
|
|
|
} // while running
|
2008-11-13 00:23:51 +00:00
|
|
|
|
2008-11-05 01:06:33 +00:00
|
|
|
}
|
|
|
|
|
2008-11-25 00:01:01 +00:00
|
|
|
/* Not called by the gl thread */
|
2008-11-05 01:06:33 +00:00
|
|
|
void
|
2013-07-15 13:58:04 +00:00
|
|
|
gst_gl_window_x11_quit (GstGLWindow * window)
|
2008-11-05 01:06:33 +00:00
|
|
|
{
|
2012-11-13 11:12:20 +00:00
|
|
|
GstGLWindowX11 *window_x11;
|
|
|
|
|
|
|
|
window_x11 = GST_GL_WINDOW_X11 (window);
|
2008-11-11 02:19:51 +00:00
|
|
|
|
2013-07-02 12:06:03 +00:00
|
|
|
GST_LOG ("sending quit");
|
2008-11-15 22:32:04 +00:00
|
|
|
|
2013-07-02 12:06:03 +00:00
|
|
|
g_main_loop_quit (window_x11->loop);
|
2008-11-15 22:32:04 +00:00
|
|
|
|
2013-07-02 12:06:03 +00:00
|
|
|
GST_LOG ("quit sent");
|
2008-11-05 01:06:33 +00:00
|
|
|
}
|
|
|
|
|
2008-11-25 00:01:01 +00:00
|
|
|
/* Not called by the gl thread */
|
2008-11-05 01:06:33 +00:00
|
|
|
void
|
2012-11-13 11:12:20 +00:00
|
|
|
gst_gl_window_x11_send_message (GstGLWindow * window, GstGLWindowCB callback,
|
2009-02-11 06:39:14 +00:00
|
|
|
gpointer data)
|
2008-11-05 01:06:33 +00:00
|
|
|
{
|
2012-11-13 11:12:20 +00:00
|
|
|
GstGLWindowX11 *window_x11;
|
2008-11-09 01:44:25 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
window_x11 = GST_GL_WINDOW_X11 (window);
|
2008-11-11 02:19:51 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
if (window_x11->running) {
|
2013-07-02 12:06:03 +00:00
|
|
|
GstGLMessage message;
|
2008-11-09 01:44:25 +00:00
|
|
|
|
2013-07-02 12:06:03 +00:00
|
|
|
message.window = window;
|
|
|
|
message.callback = callback;
|
|
|
|
message.data = data;
|
|
|
|
message.fired = FALSE;
|
|
|
|
g_mutex_init (&message.lock);
|
|
|
|
g_cond_init (&message.cond);
|
2008-11-09 21:14:29 +00:00
|
|
|
|
2013-07-02 12:06:03 +00:00
|
|
|
g_main_context_invoke (window_x11->main_context, (GSourceFunc) _run_message,
|
|
|
|
&message);
|
|
|
|
|
|
|
|
g_mutex_lock (&message.lock);
|
2008-11-11 02:19:51 +00:00
|
|
|
|
2012-11-13 11:12:20 +00:00
|
|
|
/* block until opengl calls have been executed in the gl thread */
|
2013-07-02 12:06:03 +00:00
|
|
|
while (!message.fired)
|
|
|
|
g_cond_wait (&message.cond, &message.lock);
|
|
|
|
g_mutex_unlock (&message.lock);
|
2008-11-05 01:06:33 +00:00
|
|
|
}
|
|
|
|
}
|
2013-06-03 08:15:45 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
error_handler (Display * xdpy, XErrorEvent * error)
|
|
|
|
{
|
|
|
|
TrappedErrorCode = error->error_code;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_gl_window_x11_trap_x_errors:
|
|
|
|
*
|
|
|
|
* Traps every X error until gst_gl_window_x11_untrap_x_errors() is called.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
gst_gl_window_x11_trap_x_errors (void)
|
|
|
|
{
|
|
|
|
TrappedErrorCode = 0;
|
|
|
|
old_error_handler = XSetErrorHandler (error_handler);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gst_gl_window_x11_untrap_x_errors:
|
|
|
|
*
|
|
|
|
* Removes the X error trap and returns the current status.
|
|
|
|
*
|
|
|
|
* Return value: the trapped error code, or 0 for success
|
|
|
|
*/
|
|
|
|
gint
|
|
|
|
gst_gl_window_x11_untrap_x_errors (void)
|
|
|
|
{
|
|
|
|
XSetErrorHandler (old_error_handler);
|
|
|
|
|
|
|
|
return TrappedErrorCode;
|
|
|
|
}
|