2008-11-05 01:06:33 +00:00
|
|
|
/*
|
|
|
|
* GStreamer
|
|
|
|
* Copyright (C) 2008 Julien Isorce <julien.isorce@gmail.com>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "gstglwindow.h"
|
|
|
|
|
2008-11-29 21:16:44 +00:00
|
|
|
#include <locale.h>
|
|
|
|
|
2008-11-05 01:06:33 +00:00
|
|
|
#include <GL/glx.h>
|
|
|
|
|
|
|
|
#define GST_GL_WINDOW_GET_PRIVATE(o) \
|
|
|
|
(G_TYPE_INSTANCE_GET_PRIVATE((o), GST_GL_TYPE_WINDOW, GstGLWindowPrivate))
|
|
|
|
|
2008-11-25 00:01:01 +00:00
|
|
|
|
|
|
|
/* A gl window is created and deleted in a thread dedicated to opengl calls
|
|
|
|
The name contains "window" because an opengl context is used in cooperation
|
|
|
|
with a window */
|
|
|
|
|
2008-11-05 01:06:33 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
ARG_0,
|
|
|
|
ARG_DISPLAY
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _GstGLWindowPrivate
|
|
|
|
{
|
2008-11-25 00:01:01 +00:00
|
|
|
/* X is not thread safe */
|
2008-11-13 00:23:51 +00:00
|
|
|
GMutex *x_lock;
|
|
|
|
GCond *cond_send_message;
|
|
|
|
gboolean running;
|
2008-11-17 00:04:32 +00:00
|
|
|
gboolean visible;
|
2008-11-23 15:04:27 +00:00
|
|
|
gboolean allow_extra_expose_events;
|
2008-11-13 00:23:51 +00:00
|
|
|
|
2008-11-25 00:01:01 +00:00
|
|
|
/* opengl context */
|
2008-11-05 01:06:33 +00:00
|
|
|
gchar *display_name;
|
|
|
|
Display *device;
|
2008-11-15 01:24:07 +00:00
|
|
|
Screen *screen;
|
|
|
|
gint screen_num;
|
|
|
|
Visual *visual;
|
2008-11-05 01:06:33 +00:00
|
|
|
Window root;
|
2008-11-15 01:24:07 +00:00
|
|
|
gulong white;
|
|
|
|
gulong black;
|
|
|
|
gint depth;
|
2008-11-05 01:06:33 +00:00
|
|
|
gint device_width;
|
|
|
|
gint device_height;
|
|
|
|
gint connection;
|
|
|
|
XVisualInfo *visual_info;
|
2008-11-21 23:51:30 +00:00
|
|
|
Window parent;
|
2008-11-05 01:06:33 +00:00
|
|
|
|
2008-11-25 00:01:01 +00:00
|
|
|
/* We use a specific connection to send events */
|
2008-11-21 18:37:21 +00:00
|
|
|
Display *disp_send;
|
|
|
|
|
2008-11-25 00:01:01 +00:00
|
|
|
/* X window */
|
2008-11-05 01:06:33 +00:00
|
|
|
Window internal_win_id;
|
|
|
|
GLXContext gl_context;
|
|
|
|
|
2008-11-25 00:01:01 +00:00
|
|
|
/* frozen callbacks */
|
2008-11-05 01:06:33 +00:00
|
|
|
GstGLWindowCB draw_cb;
|
|
|
|
gpointer draw_data;
|
|
|
|
GstGLWindowCB2 resize_cb;
|
|
|
|
gpointer resize_data;
|
|
|
|
GstGLWindowCB close_cb;
|
|
|
|
gpointer close_data;
|
|
|
|
};
|
|
|
|
|
|
|
|
G_DEFINE_TYPE (GstGLWindow, gst_gl_window, G_TYPE_OBJECT);
|
|
|
|
|
|
|
|
#undef G_LOG_DOMAIN
|
|
|
|
#define G_LOG_DOMAIN "GstGLWindow"
|
|
|
|
|
|
|
|
gboolean _gst_gl_window_debug = FALSE;
|
|
|
|
|
|
|
|
/* Must be called in the gl thread */
|
|
|
|
static void
|
|
|
|
gst_gl_window_finalize (GObject * object)
|
|
|
|
{
|
2008-11-06 22:41:11 +00:00
|
|
|
GstGLWindow *window = GST_GL_WINDOW (object);
|
|
|
|
GstGLWindowPrivate *priv = window->priv;
|
2008-11-11 02:19:51 +00:00
|
|
|
XEvent event;
|
2008-11-20 00:24:10 +00:00
|
|
|
Bool ret = TRUE;
|
2008-11-11 02:19:51 +00:00
|
|
|
|
2008-11-13 00:23:51 +00:00
|
|
|
g_mutex_lock (priv->x_lock);
|
|
|
|
|
2008-11-21 23:51:30 +00:00
|
|
|
priv->parent = 0;
|
|
|
|
|
2008-11-06 22:41:11 +00:00
|
|
|
XUnmapWindow (priv->device, priv->internal_win_id);
|
|
|
|
|
2008-11-20 00:24:10 +00:00
|
|
|
ret = glXMakeCurrent (priv->device, None, NULL);
|
|
|
|
if (!ret)
|
|
|
|
g_debug ("failed to release opengl context\n");
|
2008-11-06 22:41:11 +00:00
|
|
|
|
|
|
|
glXDestroyContext (priv->device, priv->gl_context);
|
|
|
|
|
2008-11-18 23:07:22 +00:00
|
|
|
XFree (priv->visual_info);
|
|
|
|
|
2008-11-20 00:24:10 +00:00
|
|
|
XReparentWindow (priv->device, priv->internal_win_id, priv->root, 0, 0);
|
|
|
|
|
2008-11-06 22:41:11 +00:00
|
|
|
XDestroyWindow (priv->device, priv->internal_win_id);
|
|
|
|
|
2008-11-15 01:24:07 +00:00
|
|
|
XSync (priv->device, FALSE);
|
|
|
|
|
2008-11-11 02:19:51 +00:00
|
|
|
while(XPending (priv->device))
|
|
|
|
XNextEvent (priv->device, &event);
|
2008-11-06 22:41:11 +00:00
|
|
|
|
2008-11-11 02:19:51 +00:00
|
|
|
XSetCloseDownMode (priv->device, DestroyAll);
|
2008-11-09 21:14:29 +00:00
|
|
|
|
2008-11-21 23:51:30 +00:00
|
|
|
/*XAddToSaveSet (display, w)
|
|
|
|
Display *display;
|
|
|
|
Window w;*/
|
|
|
|
|
2008-11-23 15:04:27 +00:00
|
|
|
//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 (priv->device);
|
|
|
|
|
2008-11-25 00:01:01 +00:00
|
|
|
g_debug ("display receiver closed\n");
|
|
|
|
|
2008-11-23 15:04:27 +00:00
|
|
|
XCloseDisplay (priv->disp_send);
|
|
|
|
|
2008-11-25 00:01:01 +00:00
|
|
|
g_debug ("display sender closed\n");
|
2008-11-09 21:14:29 +00:00
|
|
|
|
2008-11-09 01:44:25 +00:00
|
|
|
if (priv->cond_send_message)
|
2008-11-14 00:00:33 +00:00
|
|
|
{
|
2008-11-09 01:44:25 +00:00
|
|
|
g_cond_free (priv->cond_send_message);
|
2008-11-14 00:00:33 +00:00
|
|
|
priv->cond_send_message = NULL;
|
|
|
|
}
|
2008-11-09 01:44:25 +00:00
|
|
|
|
2008-11-15 22:32:04 +00:00
|
|
|
g_mutex_unlock (priv->x_lock);
|
|
|
|
|
2008-11-13 00:23:51 +00:00
|
|
|
if (priv->x_lock)
|
2008-11-14 00:00:33 +00:00
|
|
|
{
|
2008-11-13 00:23:51 +00:00
|
|
|
g_mutex_free (priv->x_lock);
|
2008-11-14 00:00:33 +00:00
|
|
|
priv->x_lock = NULL;
|
|
|
|
}
|
|
|
|
|
2008-11-05 01:06:33 +00:00
|
|
|
G_OBJECT_CLASS (gst_gl_window_parent_class)->finalize (object);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_window_set_property (GObject * object, guint prop_id,
|
|
|
|
const GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstGLWindow *window;
|
2008-11-06 22:41:11 +00:00
|
|
|
GstGLWindowPrivate *priv;
|
2008-11-05 01:06:33 +00:00
|
|
|
|
|
|
|
g_return_if_fail (GST_GL_IS_WINDOW (object));
|
|
|
|
|
|
|
|
window = GST_GL_WINDOW (object);
|
|
|
|
|
|
|
|
priv = window->priv;
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case ARG_DISPLAY:
|
|
|
|
priv->display_name = g_strdup (g_value_get_string (value));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_window_get_property (GObject * object, guint prop_id,
|
|
|
|
GValue * value, GParamSpec * pspec)
|
|
|
|
{
|
|
|
|
GstGLWindow *window;
|
2008-11-06 22:41:11 +00:00
|
|
|
GstGLWindowPrivate *priv;
|
2008-11-05 01:06:33 +00:00
|
|
|
|
|
|
|
g_return_if_fail (GST_GL_IS_WINDOW (object));
|
|
|
|
|
|
|
|
window = GST_GL_WINDOW (object);
|
|
|
|
|
|
|
|
priv = window->priv;
|
|
|
|
|
|
|
|
switch (prop_id) {
|
|
|
|
case ARG_DISPLAY:
|
|
|
|
g_value_set_string (value, priv->display_name);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_window_log_handler (const gchar *domain, GLogLevelFlags flags,
|
|
|
|
const gchar *message, gpointer user_data)
|
|
|
|
{
|
|
|
|
if (_gst_gl_window_debug) {
|
|
|
|
g_log_default_handler (domain, flags, message, user_data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_window_class_init (GstGLWindowClass * klass)
|
|
|
|
{
|
|
|
|
GObjectClass *obj_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
|
|
|
g_type_class_add_private (klass, sizeof (GstGLWindowPrivate));
|
|
|
|
|
|
|
|
obj_class->finalize = gst_gl_window_finalize;
|
|
|
|
obj_class->set_property = gst_gl_window_set_property;
|
|
|
|
obj_class->get_property = gst_gl_window_get_property;
|
|
|
|
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_window_init (GstGLWindow *window)
|
|
|
|
{
|
|
|
|
window->priv = GST_GL_WINDOW_GET_PRIVATE (window);
|
|
|
|
|
|
|
|
if (g_getenv ("GST_GL_WINDOW_DEBUG") != NULL)
|
|
|
|
_gst_gl_window_debug = TRUE;
|
|
|
|
|
|
|
|
g_log_set_handler ("GstGLWindow", G_LOG_LEVEL_DEBUG,
|
|
|
|
gst_gl_window_log_handler, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Must be called in the gl thread */
|
|
|
|
GstGLWindow *
|
|
|
|
gst_gl_window_new (gint width, gint height)
|
|
|
|
{
|
|
|
|
GstGLWindow *window = g_object_new (GST_GL_TYPE_WINDOW, NULL);
|
|
|
|
GstGLWindowPrivate *priv = window->priv;
|
|
|
|
|
|
|
|
gint attrib[] = {
|
|
|
|
GLX_RGBA,
|
2008-12-14 00:36:32 +00:00
|
|
|
GLX_RED_SIZE, 1, GLX_GREEN_SIZE, 1, GLX_BLUE_SIZE, 1,
|
2008-11-05 01:06:33 +00:00
|
|
|
GLX_DOUBLEBUFFER,
|
|
|
|
None
|
|
|
|
};
|
|
|
|
|
2008-11-11 02:19:51 +00:00
|
|
|
Bool ret = FALSE;
|
2008-11-18 23:07:22 +00:00
|
|
|
gint error_base;
|
|
|
|
gint event_base;
|
|
|
|
|
2008-11-05 01:06:33 +00:00
|
|
|
XSetWindowAttributes win_attr;
|
|
|
|
XTextProperty text_property;
|
|
|
|
XWMHints wm_hints;
|
|
|
|
unsigned long mask;
|
|
|
|
const gchar *title = "OpenGL renderer";
|
2008-11-21 00:31:19 +00:00
|
|
|
Atom wm_atoms[3];
|
2008-11-05 01:06:33 +00:00
|
|
|
|
|
|
|
static gint x = 0;
|
|
|
|
static gint y = 0;
|
|
|
|
|
2008-11-29 21:16:44 +00:00
|
|
|
setlocale(LC_NUMERIC, "C");
|
|
|
|
|
2008-11-13 00:23:51 +00:00
|
|
|
priv->x_lock = g_mutex_new ();
|
|
|
|
priv->cond_send_message = g_cond_new ();
|
|
|
|
priv->running = TRUE;
|
2008-11-17 00:04:32 +00:00
|
|
|
priv->visible = FALSE;
|
2008-11-21 23:51:30 +00:00
|
|
|
priv->parent = 0;
|
2008-11-23 15:04:27 +00:00
|
|
|
priv->allow_extra_expose_events = TRUE;
|
2008-11-13 00:23:51 +00:00
|
|
|
|
|
|
|
g_mutex_lock (priv->x_lock);
|
|
|
|
|
2008-11-05 01:06:33 +00:00
|
|
|
priv->device = XOpenDisplay (priv->display_name);
|
2008-11-11 02:19:51 +00:00
|
|
|
|
2008-11-20 00:24:10 +00:00
|
|
|
XSynchronize (priv->device, FALSE);
|
|
|
|
|
2008-11-11 02:19:51 +00:00
|
|
|
g_debug ("gl device id: %ld\n", (gulong) priv->device);
|
|
|
|
|
2008-11-21 18:37:21 +00:00
|
|
|
priv->disp_send = XOpenDisplay (priv->display_name);
|
|
|
|
|
|
|
|
XSynchronize (priv->disp_send, FALSE);
|
|
|
|
|
|
|
|
g_debug ("gl display sender: %ld\n", (gulong) priv->disp_send);
|
|
|
|
|
2008-11-15 01:24:07 +00:00
|
|
|
priv->screen = DefaultScreenOfDisplay (priv->device);
|
|
|
|
priv->screen_num = DefaultScreen (priv->device);
|
|
|
|
priv->visual = DefaultVisual (priv->device, priv->screen_num);
|
|
|
|
priv->root = DefaultRootWindow (priv->device);
|
|
|
|
priv->white = XWhitePixel (priv->device, priv->screen_num);
|
|
|
|
priv->black = XBlackPixel (priv->device, priv->screen_num);
|
|
|
|
priv->depth = DefaultDepthOfScreen (priv->screen);
|
2008-11-05 01:06:33 +00:00
|
|
|
|
2008-11-17 00:04:32 +00:00
|
|
|
g_debug ("gl root id: %lld\n", (guint64) priv->root);
|
2008-11-15 01:24:07 +00:00
|
|
|
|
|
|
|
priv->device_width = DisplayWidth (priv->device, priv->screen_num);
|
|
|
|
priv->device_height = DisplayHeight (priv->device, priv->screen_num);
|
2008-11-05 01:06:33 +00:00
|
|
|
|
|
|
|
priv->connection = ConnectionNumber (priv->device);
|
|
|
|
|
2008-11-18 23:07:22 +00:00
|
|
|
ret = glXQueryExtension (priv->device, &error_base, &event_base);
|
|
|
|
if (!ret)
|
|
|
|
g_debug ("No GLX extension");
|
|
|
|
|
2008-11-15 01:24:07 +00:00
|
|
|
priv->visual_info = glXChooseVisual (priv->device, priv->screen_num, attrib);
|
2008-11-05 01:06:33 +00:00
|
|
|
|
2008-12-14 00:36:32 +00:00
|
|
|
if (!priv->visual_info)
|
|
|
|
{
|
|
|
|
g_warning ("glx visual is null (bad attributes)\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-11-18 23:07:22 +00:00
|
|
|
if (priv->visual_info->visual != priv->visual)
|
|
|
|
g_debug ("selected visual is different from the default\n");
|
|
|
|
|
|
|
|
if (priv->visual_info->class == TrueColor)
|
|
|
|
g_debug ("visual is using TrueColor\n");
|
|
|
|
|
|
|
|
g_debug ("visual ID: %d\n", (gint)XVisualIDFromVisual(priv->visual_info->visual));
|
|
|
|
g_debug ("visual info screen: %d\n", priv->visual_info->screen);
|
|
|
|
g_debug ("visual info visualid: %d\n", (gint) priv->visual_info->visualid);
|
|
|
|
g_debug ("visual info depth: %d\n", priv->visual_info->depth);
|
|
|
|
g_debug ("visual info class: %d\n", priv->visual_info->class);
|
|
|
|
g_debug ("visual info red_mask: %ld\n", priv->visual_info->red_mask);
|
|
|
|
g_debug ("visual info green_mask: %ld\n", priv->visual_info->green_mask);
|
|
|
|
g_debug ("visual info blue_mask: %ld\n", priv->visual_info->blue_mask);
|
|
|
|
g_debug ("visual info bits_per_rgb: %d\n", priv->visual_info->bits_per_rgb);
|
|
|
|
|
2008-11-15 01:24:07 +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;
|
|
|
|
|
|
|
|
win_attr.colormap = XCreateColormap(priv->device, priv->root, priv->visual_info->visual, AllocNone);
|
|
|
|
|
|
|
|
mask = CWBackPixmap | CWBorderPixel | CWColormap | CWEventMask;
|
|
|
|
|
|
|
|
priv->internal_win_id = XCreateWindow (priv->device, priv->root, x, y,
|
|
|
|
width, height, 0, priv->visual_info->depth, InputOutput,
|
|
|
|
priv->visual_info->visual, mask, &win_attr);
|
|
|
|
|
2008-11-17 00:04:32 +00:00
|
|
|
x += 20;
|
|
|
|
y += 20;
|
|
|
|
|
2008-11-13 00:23:51 +00:00
|
|
|
XSync (priv->device, FALSE);
|
|
|
|
|
2008-11-15 01:24:07 +00:00
|
|
|
XSetWindowBackgroundPixmap (priv->device, priv->internal_win_id, None);
|
|
|
|
|
2008-11-09 21:14:29 +00:00
|
|
|
g_debug ("gl window id: %lld\n", (guint64) priv->internal_win_id);
|
|
|
|
|
2008-12-07 02:25:59 +00:00
|
|
|
g_debug ("gl window props: x:%d y:%d w:%d h:%d\n", x, y, width, height);
|
|
|
|
|
2008-11-21 00:31:19 +00:00
|
|
|
wm_atoms[0] = XInternAtom (priv->device, "WM_DELETE_WINDOW", True);
|
|
|
|
if (wm_atoms[0] == None)
|
2008-11-15 01:24:07 +00:00
|
|
|
g_debug ("Cannot create WM_DELETE_WINDOW\n");
|
|
|
|
|
2008-11-21 00:31:19 +00:00
|
|
|
wm_atoms[1] = XInternAtom (priv->device, "WM_GL_WINDOW", False);
|
|
|
|
if (wm_atoms[1] == None)
|
2008-11-15 01:24:07 +00:00
|
|
|
g_debug ("Cannot create WM_GL_WINDOW\n");
|
|
|
|
|
2008-11-21 00:31:19 +00:00
|
|
|
wm_atoms[2] = XInternAtom (priv->device, "WM_QUIT_LOOP", False);
|
|
|
|
if (wm_atoms[2] == None)
|
|
|
|
g_debug ("Cannot create WM_QUIT_LOOP\n");
|
|
|
|
|
|
|
|
XSetWMProtocols (priv->device, priv->internal_win_id, wm_atoms, 2);
|
2008-11-15 01:24:07 +00:00
|
|
|
|
2008-11-05 01:06:33 +00:00
|
|
|
priv->gl_context = glXCreateContext (priv->device, priv->visual_info, NULL, TRUE);
|
|
|
|
|
2008-11-09 21:14:29 +00:00
|
|
|
g_debug ("gl context id: %ld\n", (gulong) priv->gl_context);
|
|
|
|
|
2008-11-05 01:06:33 +00:00
|
|
|
if (!glXIsDirect(priv->device, priv->gl_context))
|
|
|
|
g_debug ("direct rendering failed\n");
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
XStringListToTextProperty ((char**)&title, 1, &text_property);
|
|
|
|
|
|
|
|
XSetWMProperties (priv->device, priv->internal_win_id, &text_property, &text_property, 0, 0,
|
2008-11-17 00:04:32 +00:00
|
|
|
NULL, &wm_hints, NULL);
|
2008-11-05 01:06:33 +00:00
|
|
|
|
|
|
|
XFree (text_property.value);
|
|
|
|
|
2008-11-09 21:14:29 +00:00
|
|
|
ret = glXMakeCurrent (priv->device, priv->internal_win_id, priv->gl_context);
|
|
|
|
|
|
|
|
if (!ret)
|
|
|
|
g_debug ("failed to make opengl context current\n");
|
2008-11-05 01:06:33 +00:00
|
|
|
|
2008-11-20 00:24:10 +00:00
|
|
|
if (glXIsDirect (priv->device, priv->gl_context))
|
|
|
|
g_debug ("Direct Rendering: yes\n");
|
|
|
|
else
|
|
|
|
g_debug ("Direct Rendering: no\n");
|
|
|
|
|
2008-11-13 00:23:51 +00:00
|
|
|
g_mutex_unlock (priv->x_lock);
|
|
|
|
|
2008-11-05 01:06:33 +00:00
|
|
|
return window;
|
|
|
|
}
|
|
|
|
|
|
|
|
GQuark
|
|
|
|
gst_gl_window_error_quark (void)
|
|
|
|
{
|
|
|
|
return g_quark_from_static_string ("gst-gl-window-error");
|
|
|
|
}
|
|
|
|
|
2008-11-25 00:01:01 +00:00
|
|
|
/* Not called by the gl thread */
|
2008-11-05 01:06:33 +00:00
|
|
|
void
|
|
|
|
gst_gl_window_set_external_window_id (GstGLWindow *window, guint64 id)
|
|
|
|
{
|
2008-11-21 19:51:48 +00:00
|
|
|
if (window)
|
|
|
|
{
|
|
|
|
GstGLWindowPrivate *priv = window->priv;
|
|
|
|
XWindowAttributes attr;
|
|
|
|
|
|
|
|
g_mutex_lock (priv->x_lock);
|
|
|
|
|
2008-11-21 23:51:30 +00:00
|
|
|
priv->parent = (Window) id;
|
|
|
|
|
2008-12-07 02:25:59 +00:00
|
|
|
g_debug ("set parent window id: %lld\n", id);
|
|
|
|
|
2008-11-21 23:51:30 +00:00
|
|
|
XGetWindowAttributes (priv->disp_send, priv->parent, &attr);
|
2008-11-21 19:51:48 +00:00
|
|
|
|
|
|
|
XResizeWindow (priv->disp_send, priv->internal_win_id, attr.width, attr.height);
|
|
|
|
|
2008-11-21 23:51:30 +00:00
|
|
|
XReparentWindow (priv->disp_send, priv->internal_win_id, priv->parent, attr.x, attr.y);
|
2008-11-21 19:51:48 +00:00
|
|
|
|
|
|
|
XSync (priv->disp_send, FALSE);
|
|
|
|
|
|
|
|
g_mutex_unlock (priv->x_lock);
|
|
|
|
}
|
2008-11-05 01:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gst_gl_window_set_external_gl_context (GstGLWindow *window, guint64 context)
|
|
|
|
{
|
|
|
|
g_warning ("gst_gl_window_set_external_gl_context: not implemented\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gst_gl_window_set_draw_callback (GstGLWindow *window, GstGLWindowCB callback, gpointer data)
|
|
|
|
{
|
|
|
|
GstGLWindowPrivate *priv = window->priv;
|
|
|
|
|
2008-11-15 17:51:44 +00:00
|
|
|
g_mutex_lock (priv->x_lock);
|
2008-11-13 00:23:51 +00:00
|
|
|
|
2008-11-05 01:06:33 +00:00
|
|
|
priv->draw_cb = callback;
|
|
|
|
priv->draw_data = data;
|
2008-11-13 00:23:51 +00:00
|
|
|
|
2008-11-15 17:51:44 +00:00
|
|
|
g_mutex_unlock (priv->x_lock);
|
2008-11-05 01:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gst_gl_window_set_resize_callback (GstGLWindow *window, GstGLWindowCB2 callback , gpointer data)
|
|
|
|
{
|
|
|
|
GstGLWindowPrivate *priv = window->priv;
|
|
|
|
|
2008-11-15 17:51:44 +00:00
|
|
|
g_mutex_lock (priv->x_lock);
|
2008-11-13 00:23:51 +00:00
|
|
|
|
2008-11-05 01:06:33 +00:00
|
|
|
priv->resize_cb = callback;
|
|
|
|
priv->resize_data = data;
|
2008-11-13 00:23:51 +00:00
|
|
|
|
2008-11-15 17:51:44 +00:00
|
|
|
g_mutex_unlock (priv->x_lock);
|
2008-11-05 01:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gst_gl_window_set_close_callback (GstGLWindow *window, GstGLWindowCB callback, gpointer data)
|
|
|
|
{
|
|
|
|
GstGLWindowPrivate *priv = window->priv;
|
|
|
|
|
2008-11-15 17:51:44 +00:00
|
|
|
g_mutex_lock (priv->x_lock);
|
2008-11-13 00:23:51 +00:00
|
|
|
|
2008-11-05 01:06:33 +00:00
|
|
|
priv->close_cb = callback;
|
|
|
|
priv->close_data = data;
|
2008-11-13 00:23:51 +00:00
|
|
|
|
2008-11-15 17:51:44 +00:00
|
|
|
g_mutex_unlock (priv->x_lock);
|
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
|
|
|
|
gst_gl_window_draw_unlocked (GstGLWindow *window)
|
|
|
|
{
|
|
|
|
GstGLWindowPrivate *priv = window->priv;
|
|
|
|
|
|
|
|
if (priv->running && priv->allow_extra_expose_events)
|
|
|
|
{
|
|
|
|
XEvent event;
|
|
|
|
XWindowAttributes attr;
|
|
|
|
|
|
|
|
XGetWindowAttributes (priv->device, priv->internal_win_id, &attr);
|
|
|
|
|
|
|
|
event.xexpose.type = Expose;
|
|
|
|
event.xexpose.send_event = TRUE;
|
|
|
|
event.xexpose.display = priv->device;
|
|
|
|
event.xexpose.window = priv->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 (priv->device, priv->internal_win_id, FALSE, ExposureMask, &event);
|
|
|
|
XSync (priv->disp_send, FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-25 00:01:01 +00:00
|
|
|
/* Not called by the gl thread */
|
2008-11-05 01:06:33 +00:00
|
|
|
void
|
|
|
|
gst_gl_window_draw (GstGLWindow *window)
|
|
|
|
{
|
2008-11-13 00:23:51 +00:00
|
|
|
if (window)
|
|
|
|
{
|
|
|
|
GstGLWindowPrivate *priv = window->priv;
|
|
|
|
|
2008-11-15 17:51:44 +00:00
|
|
|
g_mutex_lock (priv->x_lock);
|
2008-11-13 00:23:51 +00:00
|
|
|
|
|
|
|
if (priv->running)
|
|
|
|
{
|
|
|
|
XEvent event;
|
|
|
|
XWindowAttributes attr;
|
|
|
|
|
2008-11-22 15:43:24 +00:00
|
|
|
if (!priv->visible)
|
2008-11-17 00:04:32 +00:00
|
|
|
{
|
2008-11-21 18:37:21 +00:00
|
|
|
XMapWindow (priv->disp_send, priv->internal_win_id);
|
2008-11-22 15:43:24 +00:00
|
|
|
priv->visible = TRUE;
|
2008-11-17 00:04:32 +00:00
|
|
|
}
|
|
|
|
|
2008-11-21 18:37:21 +00:00
|
|
|
XGetWindowAttributes (priv->disp_send, priv->internal_win_id, &attr);
|
2008-11-13 00:23:51 +00:00
|
|
|
|
2008-11-21 23:51:30 +00:00
|
|
|
if (priv->parent)
|
|
|
|
{
|
|
|
|
XWindowAttributes attr_parent;
|
|
|
|
XGetWindowAttributes (priv->disp_send, priv->parent, &attr_parent);
|
|
|
|
|
2008-12-07 02:25:59 +00:00
|
|
|
if (attr.x != attr_parent.x || attr.y != attr_parent.y ||
|
|
|
|
attr.width != attr_parent.width || attr.height != attr_parent.height)
|
2008-11-21 23:51:30 +00:00
|
|
|
{
|
2008-12-07 02:25:59 +00:00
|
|
|
XMoveResizeWindow (priv->disp_send, priv->internal_win_id, attr_parent.x, attr_parent.y,
|
|
|
|
attr_parent.width, attr_parent.height);
|
2008-11-21 23:51:30 +00:00
|
|
|
XSync (priv->disp_send, FALSE);
|
|
|
|
|
2008-12-07 02:25:59 +00:00
|
|
|
attr.x = attr_parent.x;
|
|
|
|
attr.y = attr_parent.y;
|
|
|
|
|
2008-11-21 23:51:30 +00:00
|
|
|
attr.width = attr_parent.width;
|
|
|
|
attr.height = attr_parent.height;
|
2008-12-07 02:25:59 +00:00
|
|
|
|
|
|
|
g_debug ("parent resize: %d, %d, %d, %d\n", attr_parent.x, attr_parent.y,
|
|
|
|
attr_parent.width, attr_parent.height);
|
2008-11-21 23:51:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-13 00:23:51 +00:00
|
|
|
event.xexpose.type = Expose;
|
|
|
|
event.xexpose.send_event = TRUE;
|
2008-11-21 18:37:21 +00:00
|
|
|
event.xexpose.display = priv->disp_send;
|
2008-11-13 00:23:51 +00:00
|
|
|
event.xexpose.window = priv->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;
|
|
|
|
|
2008-11-21 18:37:21 +00:00
|
|
|
XSendEvent (priv->disp_send, priv->internal_win_id, FALSE, ExposureMask, &event);
|
|
|
|
XSync (priv->disp_send, FALSE);
|
2008-11-13 00:23:51 +00:00
|
|
|
}
|
|
|
|
|
2008-11-15 17:51:44 +00:00
|
|
|
g_mutex_unlock (priv->x_lock);
|
2008-11-13 00:23:51 +00:00
|
|
|
}
|
2008-11-05 01:06:33 +00:00
|
|
|
}
|
|
|
|
|
2008-11-25 00:01:01 +00:00
|
|
|
/* Called in the gl thread */
|
2008-11-05 01:06:33 +00:00
|
|
|
void
|
|
|
|
gst_gl_window_run_loop (GstGLWindow *window)
|
|
|
|
{
|
2008-11-06 00:28:26 +00:00
|
|
|
GstGLWindowPrivate *priv = window->priv;
|
2008-11-05 01:06:33 +00:00
|
|
|
|
|
|
|
g_debug ("begin loop\n");
|
|
|
|
|
2008-11-15 17:51:44 +00:00
|
|
|
g_mutex_lock (priv->x_lock);
|
2008-11-13 00:23:51 +00:00
|
|
|
|
|
|
|
while (priv->running)
|
2008-11-05 01:06:33 +00:00
|
|
|
{
|
2008-11-15 17:51:44 +00:00
|
|
|
XEvent event;
|
2008-11-23 15:04:27 +00:00
|
|
|
XEvent pending_event;
|
2008-11-06 22:41:11 +00:00
|
|
|
|
2008-11-15 17:51:44 +00:00
|
|
|
g_mutex_unlock (priv->x_lock);
|
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 */
|
|
|
|
XNextEvent(priv->device, &event);
|
2008-11-14 00:00:33 +00:00
|
|
|
|
2008-11-15 17:51:44 +00:00
|
|
|
g_mutex_lock (priv->x_lock);
|
2008-11-13 00:23:51 +00:00
|
|
|
|
2008-11-25 00:01:01 +00:00
|
|
|
// use in generic/cube and other related uses
|
|
|
|
priv->allow_extra_expose_events = XPending (priv->device) <= 2;
|
|
|
|
|
2008-11-15 17:51:44 +00:00
|
|
|
switch (event.type)
|
|
|
|
{
|
|
|
|
case ClientMessage:
|
2008-11-13 00:23:51 +00:00
|
|
|
{
|
2008-11-06 00:28:26 +00:00
|
|
|
|
2008-11-15 17:51:44 +00:00
|
|
|
Atom wm_delete = XInternAtom (priv->device, "WM_DELETE_WINDOW", True);
|
|
|
|
Atom wm_gl = XInternAtom (priv->device, "WM_GL_WINDOW", True);
|
2008-11-21 00:31:19 +00:00
|
|
|
Atom wm_quit_loop = XInternAtom (priv->device, "WM_QUIT_LOOP", True);
|
2008-11-15 01:24:07 +00:00
|
|
|
|
2008-11-15 17:51:44 +00:00
|
|
|
if (wm_delete == None)
|
|
|
|
g_debug ("Cannot create WM_DELETE_WINDOW\n");
|
|
|
|
if (wm_gl == None)
|
|
|
|
g_debug ("Cannot create WM_GL_WINDOW\n");
|
2008-11-21 00:31:19 +00:00
|
|
|
if (wm_quit_loop == None)
|
|
|
|
g_debug ("Cannot create WM_QUIT_LOOP\n");
|
2008-11-15 01:24:07 +00:00
|
|
|
|
2008-11-25 00:01:01 +00:00
|
|
|
/* Message sent with gst_gl_window_send_message */
|
2008-11-15 17:51:44 +00:00
|
|
|
if (wm_gl != None && event.xclient.message_type == wm_gl)
|
|
|
|
{
|
2008-11-16 15:57:00 +00:00
|
|
|
if (priv->running)
|
2008-11-06 00:28:26 +00:00
|
|
|
{
|
2008-11-15 17:51:44 +00:00
|
|
|
GstGLWindowCB custom_cb = (GstGLWindowCB) event.xclient.data.l[0];
|
|
|
|
gpointer custom_data = (gpointer) event.xclient.data.l[1];
|
2008-11-15 01:24:07 +00:00
|
|
|
|
2008-11-15 17:51:44 +00:00
|
|
|
if (!custom_cb || !custom_data)
|
|
|
|
g_debug ("custom cb not initialized\n");
|
2008-11-11 02:19:51 +00:00
|
|
|
|
2008-11-15 17:51:44 +00:00
|
|
|
custom_cb (custom_data);
|
2008-11-13 00:23:51 +00:00
|
|
|
}
|
2008-11-11 02:19:51 +00:00
|
|
|
|
2008-11-15 17:51:44 +00:00
|
|
|
g_cond_signal (priv->cond_send_message);
|
|
|
|
}
|
2008-11-11 02:19:51 +00:00
|
|
|
|
2008-11-25 00:01:01 +00:00
|
|
|
/* User clicked on the cross */
|
2008-11-15 17:51:44 +00:00
|
|
|
else if (wm_delete != None && (Atom) event.xclient.data.l[0] == wm_delete)
|
|
|
|
{
|
2008-11-17 00:04:32 +00:00
|
|
|
g_debug ("Close %lld\n", (guint64) priv->internal_win_id);
|
2008-11-11 02:19:51 +00:00
|
|
|
|
2008-11-15 17:51:44 +00:00
|
|
|
if (priv->close_cb)
|
|
|
|
priv->close_cb (priv->close_data);
|
|
|
|
|
2008-11-16 15:57:00 +00:00
|
|
|
priv->draw_cb = NULL;
|
|
|
|
priv->draw_data = NULL;
|
|
|
|
priv->resize_cb = NULL;
|
|
|
|
priv->resize_data = NULL;
|
|
|
|
priv->close_cb = NULL;
|
|
|
|
priv->close_data = NULL;
|
2008-11-21 00:31:19 +00:00
|
|
|
}
|
|
|
|
|
2008-11-25 00:01:01 +00:00
|
|
|
/* message sent with gst_gl_window_quit_loop */
|
2008-11-21 00:31:19 +00:00
|
|
|
else if (wm_quit_loop != None && event.xclient.message_type == wm_quit_loop)
|
|
|
|
{
|
2008-11-21 18:11:11 +00:00
|
|
|
GstGLWindowCB destroy_cb = (GstGLWindowCB) event.xclient.data.l[0];
|
|
|
|
gpointer destroy_data = (gpointer) event.xclient.data.l[1];
|
2008-11-21 00:31:19 +00:00
|
|
|
|
|
|
|
g_debug ("Quit loop message %lld\n", (guint64) priv->internal_win_id);
|
|
|
|
|
2008-11-25 00:01:01 +00:00
|
|
|
/* exit loop */
|
2008-11-21 00:31:19 +00:00
|
|
|
priv->running = FALSE;
|
2008-11-16 15:57:00 +00:00
|
|
|
|
2008-11-25 00:01:01 +00:00
|
|
|
/* make sure last pendings send message calls are executed */
|
2008-11-15 17:51:44 +00:00
|
|
|
XFlush (priv->device);
|
2008-11-21 18:11:11 +00:00
|
|
|
while (XCheckTypedEvent (priv->device, ClientMessage, &pending_event))
|
2008-11-15 01:24:07 +00:00
|
|
|
{
|
2008-11-21 18:11:11 +00:00
|
|
|
GstGLWindowCB custom_cb = (GstGLWindowCB) pending_event.xclient.data.l[0];
|
|
|
|
gpointer custom_data = (gpointer) pending_event.xclient.data.l[1];
|
2008-11-20 00:24:10 +00:00
|
|
|
|
2008-11-21 18:11:11 +00:00
|
|
|
g_debug ("execute last pending custom x events\n");
|
2008-11-20 00:24:10 +00:00
|
|
|
|
|
|
|
if (!custom_cb || !custom_data)
|
|
|
|
g_debug ("custom cb not initialized\n");
|
|
|
|
|
|
|
|
custom_cb (custom_data);
|
|
|
|
|
2008-11-15 17:51:44 +00:00
|
|
|
g_cond_signal (priv->cond_send_message);
|
2008-11-15 01:24:07 +00:00
|
|
|
}
|
2008-11-21 18:11:11 +00:00
|
|
|
|
2008-11-25 00:01:01 +00:00
|
|
|
/* Finally we can destroy opengl ressources (texture/shaders/fbo) */
|
2008-11-21 18:11:11 +00:00
|
|
|
if (!destroy_cb || !destroy_data)
|
2008-11-25 00:01:01 +00:00
|
|
|
g_debug ("destroy cb not correclty set\n");
|
2008-11-21 18:11:11 +00:00
|
|
|
|
|
|
|
destroy_cb (destroy_data);
|
|
|
|
|
2008-11-06 22:41:11 +00:00
|
|
|
}
|
2008-11-15 17:51:44 +00:00
|
|
|
else
|
2008-11-25 00:01:01 +00:00
|
|
|
g_debug("client message not reconized \n");
|
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:
|
|
|
|
{
|
|
|
|
if (priv->resize_cb)
|
2008-11-16 15:57:00 +00:00
|
|
|
priv->resize_cb (priv->resize_data, event.xconfigure.width, event.xconfigure.height);
|
2008-11-15 17:51:44 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case DestroyNotify:
|
|
|
|
g_debug ("DestroyNotify\n");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Expose:
|
|
|
|
if (priv->draw_cb)
|
2008-11-06 22:41:11 +00:00
|
|
|
{
|
2008-11-15 17:51:44 +00:00
|
|
|
priv->draw_cb (priv->draw_data);
|
2008-11-17 00:04:32 +00:00
|
|
|
glFlush();
|
2008-11-15 17:51:44 +00:00
|
|
|
glXSwapBuffers (priv->device, priv->internal_win_id);
|
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:
|
|
|
|
{
|
|
|
|
switch (event.xvisibility.state)
|
|
|
|
{
|
|
|
|
case VisibilityUnobscured:
|
|
|
|
if (priv->draw_cb)
|
|
|
|
priv->draw_cb (priv->draw_data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VisibilityPartiallyObscured:
|
|
|
|
if (priv->draw_cb)
|
|
|
|
priv->draw_cb (priv->draw_data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VisibilityFullyObscured:
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_debug("unknown xvisibility event: %d\n", event.xvisibility.state);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2008-11-13 00:23:51 +00:00
|
|
|
|
2008-11-15 17:51:44 +00:00
|
|
|
default:
|
2008-11-25 00:01:01 +00:00
|
|
|
g_debug ("unknow\n");
|
2008-11-15 17:51:44 +00:00
|
|
|
break;
|
2008-11-13 00:23:51 +00:00
|
|
|
|
2008-11-15 17:51:44 +00:00
|
|
|
}// switch
|
2008-11-13 00:23:51 +00:00
|
|
|
|
|
|
|
}// while running
|
|
|
|
|
2008-11-15 17:51:44 +00:00
|
|
|
g_mutex_unlock (priv->x_lock);
|
2008-11-05 01:06:33 +00:00
|
|
|
|
2008-11-06 00:28:26 +00:00
|
|
|
g_debug ("end loop\n");
|
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
|
2008-11-21 18:11:11 +00:00
|
|
|
gst_gl_window_quit_loop (GstGLWindow *window, GstGLWindowCB callback, gpointer data)
|
2008-11-05 01:06:33 +00:00
|
|
|
{
|
2008-11-09 21:14:29 +00:00
|
|
|
if (window)
|
2008-11-05 01:06:33 +00:00
|
|
|
{
|
|
|
|
GstGLWindowPrivate *priv = window->priv;
|
2008-11-11 02:19:51 +00:00
|
|
|
|
2008-11-15 17:51:44 +00:00
|
|
|
g_mutex_lock (priv->x_lock);
|
2008-11-11 02:19:51 +00:00
|
|
|
|
2008-11-15 17:51:44 +00:00
|
|
|
if (priv->running)
|
2008-11-15 22:32:04 +00:00
|
|
|
{
|
|
|
|
XEvent event;
|
|
|
|
|
|
|
|
event.xclient.type = ClientMessage;
|
|
|
|
event.xclient.send_event = TRUE;
|
2008-11-21 18:37:21 +00:00
|
|
|
event.xclient.display = priv->disp_send;
|
2008-11-15 22:32:04 +00:00
|
|
|
event.xclient.window = priv->internal_win_id;
|
2008-11-21 18:37:21 +00:00
|
|
|
event.xclient.message_type = XInternAtom (priv->disp_send, "WM_QUIT_LOOP", True);;
|
2008-11-15 22:32:04 +00:00
|
|
|
event.xclient.format = 32;
|
2008-11-21 18:11:11 +00:00
|
|
|
event.xclient.data.l[0] = (long) callback;
|
|
|
|
event.xclient.data.l[1] = (long) data;
|
2008-11-15 22:32:04 +00:00
|
|
|
|
2008-11-21 18:37:21 +00:00
|
|
|
XSendEvent (priv->disp_send, priv->internal_win_id, FALSE, NoEventMask, &event);
|
|
|
|
XSync (priv->disp_send, FALSE);
|
2008-11-15 22:32:04 +00:00
|
|
|
}
|
2008-11-14 00:00:33 +00:00
|
|
|
|
2008-11-15 17:51:44 +00:00
|
|
|
g_mutex_unlock (priv->x_lock);
|
2008-11-09 21:14:29 +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
|
|
|
|
gst_gl_window_send_message (GstGLWindow *window, GstGLWindowCB callback, gpointer data)
|
|
|
|
{
|
2008-11-06 22:41:11 +00:00
|
|
|
if (window)
|
2008-11-05 01:06:33 +00:00
|
|
|
{
|
2008-11-06 22:41:11 +00:00
|
|
|
GstGLWindowPrivate *priv = window->priv;
|
2008-11-09 01:44:25 +00:00
|
|
|
|
2008-11-15 17:51:44 +00:00
|
|
|
g_mutex_lock (priv->x_lock);
|
2008-11-11 02:19:51 +00:00
|
|
|
|
2008-11-13 00:23:51 +00:00
|
|
|
if (priv->running)
|
2008-11-09 21:14:29 +00:00
|
|
|
{
|
|
|
|
XEvent event;
|
2008-11-09 01:44:25 +00:00
|
|
|
|
2008-11-09 21:14:29 +00:00
|
|
|
event.xclient.type = ClientMessage;
|
|
|
|
event.xclient.send_event = TRUE;
|
2008-11-21 18:37:21 +00:00
|
|
|
event.xclient.display = priv->disp_send;
|
2008-11-09 21:14:29 +00:00
|
|
|
event.xclient.window = priv->internal_win_id;
|
2008-11-21 18:37:21 +00:00
|
|
|
event.xclient.message_type = XInternAtom (priv->disp_send, "WM_GL_WINDOW", True);
|
2008-11-09 21:14:29 +00:00
|
|
|
event.xclient.format = 32;
|
|
|
|
event.xclient.data.l[0] = (long) callback;
|
|
|
|
event.xclient.data.l[1] = (long) data;
|
|
|
|
|
2008-11-21 18:37:21 +00:00
|
|
|
XSendEvent (priv->disp_send, priv->internal_win_id, FALSE, NoEventMask, &event);
|
|
|
|
XSync (priv->disp_send, FALSE);
|
2008-11-14 00:00:33 +00:00
|
|
|
|
2008-11-25 00:01:01 +00:00
|
|
|
/* block until opengl calls have been executed in the gl thread */
|
2008-11-15 17:51:44 +00:00
|
|
|
g_cond_wait (priv->cond_send_message, priv->x_lock);
|
2008-11-09 21:14:29 +00:00
|
|
|
}
|
2008-11-11 02:19:51 +00:00
|
|
|
|
2008-11-15 17:51:44 +00:00
|
|
|
g_mutex_unlock (priv->x_lock);
|
2008-11-05 01:06:33 +00:00
|
|
|
}
|
|
|
|
}
|