mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-04-26 06:54:49 +00:00
[261/906] implement quit x message loop
This commit is contained in:
parent
baedf3a65b
commit
5ec4972d3d
1 changed files with 50 additions and 36 deletions
|
@ -88,6 +88,9 @@ gst_gl_window_finalize (GObject * object)
|
||||||
|
|
||||||
XCloseDisplay (priv->device);
|
XCloseDisplay (priv->device);
|
||||||
|
|
||||||
|
|
||||||
|
g_cond_signal (priv->cond_send_message);
|
||||||
|
|
||||||
if (priv->cond_send_message)
|
if (priv->cond_send_message)
|
||||||
g_cond_free (priv->cond_send_message);
|
g_cond_free (priv->cond_send_message);
|
||||||
|
|
||||||
|
@ -202,6 +205,8 @@ gst_gl_window_new (gint width, gint height)
|
||||||
unsigned long mask;
|
unsigned long mask;
|
||||||
const gchar *title = "OpenGL renderer";
|
const gchar *title = "OpenGL renderer";
|
||||||
|
|
||||||
|
Bool ret = FALSE;
|
||||||
|
|
||||||
static gint x = 0;
|
static gint x = 0;
|
||||||
static gint y = 0;
|
static gint y = 0;
|
||||||
|
|
||||||
|
@ -239,8 +244,12 @@ gst_gl_window_new (gint width, gint height)
|
||||||
width, height, 0, priv->visual_info->depth, InputOutput,
|
width, height, 0, priv->visual_info->depth, InputOutput,
|
||||||
priv->visual_info->visual, mask, &win_attr);
|
priv->visual_info->visual, mask, &win_attr);
|
||||||
|
|
||||||
|
g_debug ("gl window id: %lld\n", (guint64) priv->internal_win_id);
|
||||||
|
|
||||||
priv->gl_context = glXCreateContext (priv->device, priv->visual_info, NULL, TRUE);
|
priv->gl_context = glXCreateContext (priv->device, priv->visual_info, NULL, TRUE);
|
||||||
|
|
||||||
|
g_debug ("gl context id: %ld\n", (gulong) priv->gl_context);
|
||||||
|
|
||||||
if (!glXIsDirect(priv->device, priv->gl_context))
|
if (!glXIsDirect(priv->device, priv->gl_context))
|
||||||
g_debug ("direct rendering failed\n");
|
g_debug ("direct rendering failed\n");
|
||||||
|
|
||||||
|
@ -262,12 +271,17 @@ gst_gl_window_new (gint width, gint height)
|
||||||
|
|
||||||
XSetWMProtocols (priv->device, priv->internal_win_id, &priv->atom_delete_window, 1);
|
XSetWMProtocols (priv->device, priv->internal_win_id, &priv->atom_delete_window, 1);
|
||||||
|
|
||||||
glXMakeCurrent (priv->device, priv->internal_win_id, priv->gl_context);
|
ret = glXMakeCurrent (priv->device, priv->internal_win_id, priv->gl_context);
|
||||||
|
|
||||||
|
if (!ret)
|
||||||
|
g_debug ("failed to make opengl context current\n");
|
||||||
|
|
||||||
priv->mutex = g_mutex_new ();
|
priv->mutex = g_mutex_new ();
|
||||||
priv->cond_send_message = g_cond_new ();
|
priv->cond_send_message = g_cond_new ();
|
||||||
priv->is_closed = FALSE;
|
priv->is_closed = FALSE;
|
||||||
|
|
||||||
|
XResizeWindow (priv->device, priv->internal_win_id, width, height);
|
||||||
|
|
||||||
return window;
|
return window;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -359,8 +373,6 @@ gst_gl_window_draw (GstGLWindow *window)
|
||||||
XEvent event;
|
XEvent event;
|
||||||
XWindowAttributes attr;
|
XWindowAttributes attr;
|
||||||
|
|
||||||
g_debug ("DRAW\n");
|
|
||||||
|
|
||||||
XGetWindowAttributes (priv->device, priv->internal_win_id, &attr);
|
XGetWindowAttributes (priv->device, priv->internal_win_id, &attr);
|
||||||
|
|
||||||
event.xexpose.type = Expose;
|
event.xexpose.type = Expose;
|
||||||
|
@ -373,8 +385,6 @@ gst_gl_window_draw (GstGLWindow *window)
|
||||||
event.xexpose.height = attr.height;
|
event.xexpose.height = attr.height;
|
||||||
event.xexpose.count = 0;
|
event.xexpose.count = 0;
|
||||||
XSendEvent (priv->device, priv->internal_win_id, FALSE, NoEventMask, &event);
|
XSendEvent (priv->device, priv->internal_win_id, FALSE, NoEventMask, &event);
|
||||||
|
|
||||||
g_debug ("AFTER DRAW\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -390,17 +400,13 @@ gst_gl_window_run_loop (GstGLWindow *window)
|
||||||
{
|
{
|
||||||
XNextEvent(priv->device, &event);
|
XNextEvent(priv->device, &event);
|
||||||
|
|
||||||
g_debug ("Next\n");
|
|
||||||
|
|
||||||
switch (event.type)
|
switch (event.type)
|
||||||
{
|
{
|
||||||
case ClientMessage:
|
case ClientMessage:
|
||||||
{
|
{
|
||||||
|
|
||||||
g_debug ("Client Message\n");
|
|
||||||
if (event.xclient.message_type == priv->atom_custom)
|
if (event.xclient.message_type == priv->atom_custom)
|
||||||
{
|
{
|
||||||
g_debug ("Custom message\n");
|
|
||||||
|
|
||||||
if (priv->is_closed && priv->close_cb)
|
if (priv->is_closed && priv->close_cb)
|
||||||
{
|
{
|
||||||
|
@ -414,9 +420,7 @@ gst_gl_window_run_loop (GstGLWindow *window)
|
||||||
custom_cb (custom_data);
|
custom_cb (custom_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_mutex_lock (priv->mutex);
|
|
||||||
g_cond_signal (priv->cond_send_message);
|
g_cond_signal (priv->cond_send_message);
|
||||||
g_mutex_unlock (priv->mutex);
|
|
||||||
}
|
}
|
||||||
else if ( (Atom) event.xclient.data.l[0] == priv->atom_delete_window)
|
else if ( (Atom) event.xclient.data.l[0] == priv->atom_delete_window)
|
||||||
{
|
{
|
||||||
|
@ -430,7 +434,6 @@ gst_gl_window_run_loop (GstGLWindow *window)
|
||||||
case CreateNotify:
|
case CreateNotify:
|
||||||
case ConfigureNotify:
|
case ConfigureNotify:
|
||||||
{
|
{
|
||||||
g_debug ("CreateNotify or ConfigureNotify\n");
|
|
||||||
gint width = event.xconfigure.width;
|
gint width = event.xconfigure.width;
|
||||||
gint height = event.xconfigure.height;
|
gint height = event.xconfigure.height;
|
||||||
if (priv->resize_cb)
|
if (priv->resize_cb)
|
||||||
|
@ -443,15 +446,12 @@ gst_gl_window_run_loop (GstGLWindow *window)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Expose:
|
case Expose:
|
||||||
g_debug ("Expose\n");
|
|
||||||
if (priv->draw_cb)
|
if (priv->draw_cb)
|
||||||
priv->draw_cb (priv->draw_data);
|
priv->draw_cb (priv->draw_data);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VisibilityNotify:
|
case VisibilityNotify:
|
||||||
{
|
{
|
||||||
g_debug ("VisibilityNotify\n");
|
|
||||||
|
|
||||||
switch (event.xvisibility.state)
|
switch (event.xvisibility.state)
|
||||||
{
|
{
|
||||||
case VisibilityUnobscured:
|
case VisibilityUnobscured:
|
||||||
|
@ -487,13 +487,22 @@ gst_gl_window_run_loop (GstGLWindow *window)
|
||||||
void
|
void
|
||||||
gst_gl_window_quit_loop (GstGLWindow *window)
|
gst_gl_window_quit_loop (GstGLWindow *window)
|
||||||
{
|
{
|
||||||
/*if (window)
|
if (window)
|
||||||
{
|
{
|
||||||
GstGLWindowPrivate *priv = window->priv;
|
GstGLWindowPrivate *priv = window->priv;
|
||||||
LRESULT res = PostMessage(priv->internal_win_id, WM_CLOSE, 0, 0);
|
XEvent event;
|
||||||
g_assert (SUCCEEDED (res));
|
|
||||||
g_debug ("end loop requested\n");
|
event.xclient.type = ClientMessage;
|
||||||
}*/
|
event.xclient.send_event = TRUE;
|
||||||
|
event.xclient.display = priv->device;
|
||||||
|
event.xclient.window = priv->internal_win_id;
|
||||||
|
event.xclient.message_type = 0;
|
||||||
|
event.xclient.format = 32;
|
||||||
|
event.xclient.data.l[0] = priv->atom_delete_window;
|
||||||
|
|
||||||
|
XSendEvent (priv->device, priv->internal_win_id, FALSE, NoEventMask, &event);
|
||||||
|
XFlush (priv->device);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Thread safe */
|
/* Thread safe */
|
||||||
|
@ -504,23 +513,28 @@ gst_gl_window_send_message (GstGLWindow *window, GstGLWindowCB callback, gpointe
|
||||||
{
|
{
|
||||||
|
|
||||||
GstGLWindowPrivate *priv = window->priv;
|
GstGLWindowPrivate *priv = window->priv;
|
||||||
XEvent event;
|
|
||||||
|
|
||||||
g_mutex_lock (priv->mutex);
|
if (!priv->is_closed)
|
||||||
|
{
|
||||||
|
XEvent event;
|
||||||
|
|
||||||
g_debug ("CUSTOM\n");
|
g_mutex_lock (priv->mutex);
|
||||||
event.xclient.type = ClientMessage;
|
|
||||||
event.xclient.send_event = FALSE;
|
event.xclient.type = ClientMessage;
|
||||||
event.xclient.display = priv->device;
|
event.xclient.send_event = TRUE;
|
||||||
event.xclient.window = priv->internal_win_id;
|
event.xclient.display = priv->device;
|
||||||
event.xclient.message_type = priv->atom_custom;
|
event.xclient.window = priv->internal_win_id;
|
||||||
event.xclient.format = 32;
|
event.xclient.message_type = priv->atom_custom;
|
||||||
event.xclient.data.l[0] = (long) callback;
|
event.xclient.format = 32;
|
||||||
event.xclient.data.l[1] = (long) data;
|
event.xclient.data.l[0] = (long) callback;
|
||||||
XSendEvent (priv->device, priv->internal_win_id, FALSE, NoEventMask, &event);
|
event.xclient.data.l[1] = (long) data;
|
||||||
g_debug ("CUSTOM sent\n");
|
|
||||||
g_cond_wait (priv->cond_send_message, priv->mutex);
|
XSendEvent (priv->device, priv->internal_win_id, FALSE, NoEventMask, &event);
|
||||||
g_debug ("AFTER CUSTOM\n");
|
XFlush (priv->device);
|
||||||
g_mutex_unlock (priv->mutex);
|
|
||||||
|
g_cond_wait (priv->cond_send_message, priv->mutex);
|
||||||
|
|
||||||
|
g_mutex_unlock (priv->mutex);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue