display->clientDrawCallback (display->redisplay_texture,
display->redisplay_texture_width, display->redisplay_texture_height);
- if (doRedisplay)
- gst_gl_window_draw (display->gl_window);
+ if (doRedisplay && display->gl_window)
+ gst_gl_window_draw_unlocked (display->gl_window);
}
//default opengl scene
else
void gst_gl_window_set_resize_callback (GstGLWindow *window, GstGLWindowCB2 callback, gpointer data);
void gst_gl_window_set_close_callback (GstGLWindow *window, GstGLWindowCB callback, gpointer data);
+void gst_gl_window_draw_unlocked (GstGLWindow *window);
void gst_gl_window_draw (GstGLWindow *window);
void gst_gl_window_run_loop (GstGLWindow *window);
void gst_gl_window_quit_loop (GstGLWindow *window, GstGLWindowCB callback, gpointer data);
-/*
+/*
* GStreamer
* Copyright (C) 2008 Julien Isorce <julien.isorce@gmail.com>
*
g_debug ("gl window created: %d\n", priv->internal_win_id);
- //device is set in the window_proc
+ //device is set in the window_proc
g_assert (priv->device);
ShowCursor (TRUE);
return g_quark_from_static_string ("gst-gl-window-error");
}
-void
+void
gst_gl_window_set_external_window_id (GstGLWindow *window, guint64 id)
{
GstGLWindowPrivate *priv = window->priv;
SetProp ((HWND)id, "gl_window_id", priv->internal_win_id);
SetProp ((HWND)id, "gl_window_parent_proc", (WNDPROC) window_parent_proc);
SetWindowLongPtr ((HWND)id, GWL_WNDPROC, (DWORD) (guint64) sub_class_proc);
-
+
SetWindowLongPtr (priv->internal_win_id, GWL_STYLE, WS_CHILD | WS_MAXIMIZE);
- SetParent (priv->internal_win_id, (HWND)id);
+ SetParent (priv->internal_win_id, (HWND)id);
//take changes into account: SWP_FRAMECHANGED
GetClientRect ((HWND)id, &rect);
MoveWindow (priv->internal_win_id, rect.left, rect.top, rect.right, rect.bottom, FALSE);
}
-void
+void
gst_gl_window_set_external_gl_context (GstGLWindow *window, guint64 context)
{
g_warning ("gst_gl_window_set_external_gl_context: not implemented\n");
gst_gl_window_set_draw_callback (GstGLWindow *window, GstGLWindowCB callback, gpointer data)
{
GstGLWindowPrivate *priv = window->priv;
-
+
priv->draw_cb = callback;
priv->draw_data = data;
}
priv->close_data = data;
}
+void
+gst_gl_window_draw_unlocked (GstGLWindow *window)
+{
+ gst_gl_window_draw (window);
+}
+
/* Thread safe */
void
gst_gl_window_draw (GstGLWindow *window)
g_debug ("begin loop\n");
while (running && (bRet = GetMessage (&msg, NULL, 0, 0)) != 0)
- {
+ {
if (bRet == -1)
{
g_error ("Failed to get message %x\r\n", GetLastError());
}
else
{
- TranslateMessage (&msg);
- DispatchMessage (&msg);
+ TranslateMessage (&msg);
+ DispatchMessage (&msg);
}
}
pfd.cColorBits = (BYTE) GetDeviceCaps (priv->device, BITSPIXEL);
pixelformat = ChoosePixelFormat (priv->device, &pfd );
-
+
g_assert (pixelformat);
res = SetPixelFormat (priv->device, pixelformat, &pfd);
}
case WM_PAINT:
- {
+ {
if (priv->draw_cb)
{
PAINTSTRUCT ps;
case WM_CLOSE:
{
ShowWindowAsync (priv->internal_win_id, SW_HIDE);
-
+
if (priv->close_cb)
priv->close_cb (priv->close_data);
if (parent_id)
{
WNDPROC parent_proc = GetProp (parent_id, "gl_window_parent_proc");
-
+
g_assert (parent_proc);
SetWindowLongPtr (parent_id, GWL_WNDPROC, (LONG) (guint64) parent_proc);
g_debug ("failed to destroy window %d, %x\r\n", hWnd, GetLastError());
g_debug ("AFTER\n");
}
-
+
PostQuitMessage (0);
break;
}
LRESULT FAR PASCAL sub_class_proc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
WNDPROC window_parent_proc = GetProp (hWnd, "gl_window_parent_proc");
-
+
if (uMsg == WM_SIZE)
{
HWND gl_window_id = GetProp (hWnd, "gl_window_id");
GCond *cond_send_message;
gboolean running;
gboolean visible;
+ gboolean allow_extra_expose_events;
gchar *display_name;
Display *device;
XSetCloseDownMode (priv->device, DestroyAll);
- XCloseDisplay (priv->device);
-
- XCloseDisplay (priv->disp_send);
-
/*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 (priv->device);
+
+ XCloseDisplay (priv->disp_send);
+
g_debug ("display closed\n");
if (priv->cond_send_message)
priv->running = TRUE;
priv->visible = FALSE;
priv->parent = 0;
+ priv->allow_extra_expose_events = TRUE;
g_mutex_lock (priv->x_lock);
g_mutex_unlock (priv->x_lock);
}
+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);
+ }
+}
+
/* Thread safe */
void
gst_gl_window_draw (GstGLWindow *window)
{
GstGLWindowPrivate *priv = window->priv;
-
g_debug ("begin loop\n");
g_mutex_lock (priv->x_lock);
while (priv->running)
{
XEvent event;
+ XEvent pending_event;
g_mutex_unlock (priv->x_lock);
else if (wm_quit_loop != None && event.xclient.message_type == wm_quit_loop)
{
- XEvent pending_event;
GstGLWindowCB destroy_cb = (GstGLWindowCB) event.xclient.data.l[0];
gpointer destroy_data = (gpointer) event.xclient.data.l[1];
}// switch
+ // use in cube example
+ if (XPending (priv->device) > 10)
+ {
+ XEvent extra_expose_event;
+ priv->allow_extra_expose_events = FALSE;
+ while (XCheckTypedWindowEvent (priv->device, priv->internal_win_id, Expose, &extra_expose_event))
+ {
+ if (priv->draw_cb)
+ {
+ if (glXGetCurrentContext () != priv->gl_context)
+ g_warning ("current gl context has changed\n");
+ priv->draw_cb (priv->draw_data);
+ glFlush();
+ glXSwapBuffers (priv->device, priv->internal_win_id);
+ }
+ }
+ priv->allow_extra_expose_events = TRUE;
+ }
+
}// while running
g_mutex_unlock (priv->x_lock);