2008-11-23 15:04:27 +00:00
|
|
|
/*
|
2008-10-22 23:40:52 +00:00
|
|
|
* GStreamer
|
|
|
|
* Copyright (C) 2008 Julien Isorce <julien.isorce@gmail.com>
|
2012-11-15 02:17:59 +00:00
|
|
|
* Copyright (C) 2012 Matthew Waters <ystreet00@gmail.com>
|
2008-10-22 23:40:52 +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-10-22 23:40:52 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2012-11-15 02:17:59 +00:00
|
|
|
#include "gstglwindow_win32.h"
|
2008-10-22 23:40:52 +00:00
|
|
|
|
2012-11-15 02:17:59 +00:00
|
|
|
#include "gstglwindow_win32_wgl.h"
|
2008-10-22 23:40:52 +00:00
|
|
|
|
2008-11-22 15:43:24 +00:00
|
|
|
#define WM_GST_GL_WINDOW_CUSTOM (WM_APP+1)
|
|
|
|
#define WM_GST_GL_WINDOW_QUIT (WM_APP+2)
|
2008-10-22 23:40:52 +00:00
|
|
|
|
2012-11-15 02:17:59 +00:00
|
|
|
void gst_gl_window_set_pixel_format (GstGLWindowWin32 * window);
|
2009-02-11 06:39:14 +00:00
|
|
|
LRESULT CALLBACK window_proc (HWND hWnd, UINT uMsg, WPARAM wParam,
|
|
|
|
LPARAM lParam);
|
|
|
|
LRESULT FAR PASCAL sub_class_proc (HWND hWnd, UINT uMsg, WPARAM wParam,
|
|
|
|
LPARAM lParam);
|
2008-10-22 23:40:52 +00:00
|
|
|
|
2012-11-15 02:17:59 +00:00
|
|
|
#define GST_GL_WINDOW_WIN32_GET_PRIVATE(o) \
|
|
|
|
(G_TYPE_INSTANCE_GET_PRIVATE((o), GST_GL_TYPE_WINDOW_WIN32, GstGLWindowWin32Private))
|
2008-10-22 23:40:52 +00:00
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0
|
|
|
|
};
|
|
|
|
|
2012-11-15 02:17:59 +00:00
|
|
|
struct _GstGLWindowWin32Private
|
2008-10-22 23:40:52 +00:00
|
|
|
{
|
2012-11-15 02:17:59 +00:00
|
|
|
GstGLRendererAPI render_api;
|
|
|
|
guintptr external_gl_context;
|
|
|
|
gboolean activate;
|
|
|
|
gboolean activate_result;
|
2008-10-22 23:40:52 +00:00
|
|
|
};
|
|
|
|
|
2012-11-15 02:17:59 +00:00
|
|
|
#define GST_CAT_DEFAULT gst_gl_window_x11_debug
|
|
|
|
GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
|
2008-10-22 23:40:52 +00:00
|
|
|
|
2012-11-15 02:17:59 +00:00
|
|
|
#define DEBUG_INIT \
|
|
|
|
GST_DEBUG_CATEGORY_GET (GST_CAT_DEFAULT, "glwindow");
|
|
|
|
#define gst_gl_window_win32_parent_class parent_class
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GstGLWindowWin32, gst_gl_window_win32,
|
|
|
|
GST_GL_TYPE_WINDOW, DEBUG_INIT);
|
2010-01-05 23:13:46 +00:00
|
|
|
|
2008-10-27 23:22:27 +00:00
|
|
|
HHOOK hHook;
|
|
|
|
|
2012-11-15 02:17:59 +00:00
|
|
|
guintptr gst_gl_window_win32_get_gl_context (GstGLWindow * window);
|
|
|
|
gboolean gst_gl_window_win32_activate (GstGLWindow * window, gboolean activate);
|
|
|
|
void gst_gl_window_win32_set_window_handle (GstGLWindow * window,
|
|
|
|
guintptr handle);
|
|
|
|
void gst_gl_window_win32_draw_unlocked (GstGLWindow * window, guint width,
|
|
|
|
guint height);
|
|
|
|
void gst_gl_window_win32_draw (GstGLWindow * window, guint width, guint height);
|
|
|
|
void gst_gl_window_win32_run (GstGLWindow * window);
|
|
|
|
void gst_gl_window_win32_quit (GstGLWindow * window, GstGLWindowCB callback,
|
|
|
|
gpointer data);
|
|
|
|
void gst_gl_window_win32_send_message (GstGLWindow * window,
|
|
|
|
GstGLWindowCB callback, gpointer data);
|
2008-10-22 23:40:52 +00:00
|
|
|
|
|
|
|
static void
|
2012-11-15 02:17:59 +00:00
|
|
|
gst_gl_window_win32_class_init (GstGLWindowWin32Class * klass)
|
2008-10-22 23:40:52 +00:00
|
|
|
{
|
2012-11-15 02:17:59 +00:00
|
|
|
GstGLWindowClass *window_class;
|
2008-12-12 23:50:16 +00:00
|
|
|
WNDCLASS wc;
|
|
|
|
ATOM atom = 0;
|
|
|
|
HINSTANCE hinstance = GetModuleHandle (NULL);
|
2008-10-22 23:40:52 +00:00
|
|
|
|
2012-11-15 02:17:59 +00:00
|
|
|
window_class = (GstGLWindowClass *) klass;
|
2008-10-22 23:40:52 +00:00
|
|
|
|
2012-11-15 02:17:59 +00:00
|
|
|
g_type_class_add_private (klass, sizeof (GstGLWindowWin32Private));
|
2008-12-12 23:50:16 +00:00
|
|
|
|
|
|
|
atom = GetClassInfo (hinstance, "GSTGL", &wc);
|
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
if (atom == 0) {
|
|
|
|
ZeroMemory (&wc, sizeof (WNDCLASS));
|
2008-12-12 23:50:16 +00:00
|
|
|
|
|
|
|
wc.lpfnWndProc = window_proc;
|
|
|
|
wc.cbClsExtra = 0;
|
|
|
|
wc.cbWndExtra = 0;
|
|
|
|
wc.hInstance = hinstance;
|
|
|
|
wc.hIcon = LoadIcon (NULL, IDI_WINLOGO);
|
|
|
|
wc.style = CS_OWNDC | CS_HREDRAW | CS_VREDRAW;
|
|
|
|
wc.hCursor = LoadCursor (NULL, IDC_ARROW);
|
|
|
|
wc.hbrBackground = (HBRUSH) GetStockObject (BLACK_BRUSH);
|
|
|
|
wc.lpszMenuName = NULL;
|
|
|
|
wc.lpszClassName = "GSTGL";
|
|
|
|
|
|
|
|
atom = RegisterClass (&wc);
|
|
|
|
|
|
|
|
if (atom == 0)
|
2012-11-15 02:17:59 +00:00
|
|
|
GST_WARNING ("Failed to register window class %lud\n", GetLastError ());
|
2008-12-12 23:50:16 +00:00
|
|
|
}
|
2012-11-15 02:17:59 +00:00
|
|
|
|
|
|
|
window_class->get_gl_context =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_gl_window_win32_get_gl_context);
|
|
|
|
window_class->activate = GST_DEBUG_FUNCPTR (gst_gl_window_win32_activate);
|
|
|
|
window_class->set_window_handle =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_gl_window_win32_set_window_handle);
|
|
|
|
window_class->draw_unlocked = GST_DEBUG_FUNCPTR (gst_gl_window_win32_draw);
|
|
|
|
window_class->draw = GST_DEBUG_FUNCPTR (gst_gl_window_win32_draw);
|
|
|
|
window_class->run = GST_DEBUG_FUNCPTR (gst_gl_window_win32_run);
|
|
|
|
window_class->quit = GST_DEBUG_FUNCPTR (gst_gl_window_win32_quit);
|
|
|
|
window_class->send_message =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_gl_window_win32_send_message);
|
2008-10-22 23:40:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-11-15 02:17:59 +00:00
|
|
|
gst_gl_window_win32_init (GstGLWindowWin32 * window)
|
2008-10-22 23:40:52 +00:00
|
|
|
{
|
2012-11-15 02:17:59 +00:00
|
|
|
window->priv = GST_GL_WINDOW_WIN32_GET_PRIVATE (window);
|
2008-10-22 23:40:52 +00:00
|
|
|
|
2012-11-15 02:17:59 +00:00
|
|
|
gst_gl_window_set_need_lock (GST_GL_WINDOW (window), FALSE);
|
2008-10-22 23:40:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Must be called in the gl thread */
|
2012-11-15 02:17:59 +00:00
|
|
|
GstGLWindowWin32 *
|
|
|
|
gst_gl_window_win32_new (GstGLRendererAPI render_api,
|
|
|
|
guintptr external_gl_context)
|
2008-10-22 23:40:52 +00:00
|
|
|
{
|
2012-11-15 02:17:59 +00:00
|
|
|
GstGLWindowWin32 *window = NULL;
|
|
|
|
|
|
|
|
window =
|
|
|
|
GST_GL_WINDOW_WIN32 (gst_gl_window_win32_wgl_new (render_api,
|
|
|
|
external_gl_context));
|
2008-10-25 14:18:23 +00:00
|
|
|
|
2012-11-15 02:17:59 +00:00
|
|
|
window->priv->render_api = render_api;
|
|
|
|
window->priv->external_gl_context = external_gl_context;
|
|
|
|
|
|
|
|
return window;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gst_gl_window_win32_open_device (GstGLWindowWin32 * window_win32)
|
|
|
|
{
|
2008-10-25 14:18:23 +00:00
|
|
|
HINSTANCE hinstance = GetModuleHandle (NULL);
|
|
|
|
|
2008-10-25 00:03:16 +00:00
|
|
|
static gint x = 0;
|
2008-10-22 23:40:52 +00:00
|
|
|
static gint y = 0;
|
2008-10-25 14:18:23 +00:00
|
|
|
|
2008-10-25 00:03:16 +00:00
|
|
|
x += 20;
|
|
|
|
y += 20;
|
2008-10-22 23:40:52 +00:00
|
|
|
|
2012-11-15 02:17:59 +00:00
|
|
|
window_win32->internal_win_id = 0;
|
|
|
|
window_win32->device = 0;
|
|
|
|
window_win32->is_closed = FALSE;
|
|
|
|
window_win32->visible = FALSE;
|
|
|
|
|
|
|
|
window_win32->internal_win_id = CreateWindowEx (0,
|
2009-02-11 06:39:14 +00:00
|
|
|
"GSTGL",
|
|
|
|
"OpenGL renderer",
|
|
|
|
WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW,
|
2012-11-15 02:17:59 +00:00
|
|
|
x, y, 0, 0, (HWND) NULL, (HMENU) NULL, hinstance, window_win32);
|
2009-02-11 06:39:14 +00:00
|
|
|
|
2012-11-15 02:17:59 +00:00
|
|
|
if (!window_win32->internal_win_id) {
|
|
|
|
GST_DEBUG ("failed to create gl window\n");
|
2012-04-13 13:08:00 +00:00
|
|
|
goto failure;
|
2008-10-25 14:18:23 +00:00
|
|
|
}
|
2008-10-22 23:40:52 +00:00
|
|
|
|
2012-11-15 02:17:59 +00:00
|
|
|
GST_DEBUG ("gl window created: %" G_GUINTPTR_FORMAT "\n",
|
|
|
|
(guintptr) window_win32->internal_win_id);
|
2008-10-23 23:39:00 +00:00
|
|
|
|
2008-11-23 15:04:27 +00:00
|
|
|
//device is set in the window_proc
|
2012-11-15 02:17:59 +00:00
|
|
|
if (!window_win32->device) {
|
|
|
|
GST_DEBUG ("failed to create device\n");
|
2012-04-13 13:08:00 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
2008-10-22 23:40:52 +00:00
|
|
|
|
|
|
|
ShowCursor (TRUE);
|
|
|
|
|
2012-11-15 02:17:59 +00:00
|
|
|
return TRUE;
|
2012-04-13 13:08:00 +00:00
|
|
|
|
|
|
|
failure:
|
2012-11-15 02:17:59 +00:00
|
|
|
return FALSE;
|
2008-10-22 23:40:52 +00:00
|
|
|
}
|
|
|
|
|
2012-05-20 15:45:06 +00:00
|
|
|
guintptr
|
2012-11-15 02:17:59 +00:00
|
|
|
gst_gl_window_win32_get_gl_context (GstGLWindow * window)
|
2009-10-22 23:11:27 +00:00
|
|
|
{
|
2012-11-15 02:17:59 +00:00
|
|
|
GstGLWindowWin32Class *window_class;
|
2009-10-22 23:11:27 +00:00
|
|
|
|
2012-11-15 02:17:59 +00:00
|
|
|
window_class = GST_GL_WINDOW_WIN32_GET_CLASS (window);
|
|
|
|
|
|
|
|
return window_class->get_gl_context (GST_GL_WINDOW_WIN32 (window));
|
2009-10-22 23:11:27 +00:00
|
|
|
}
|
|
|
|
|
2012-11-15 02:17:59 +00:00
|
|
|
static void
|
|
|
|
callback_activate (GstGLWindow * window)
|
2009-10-22 23:11:27 +00:00
|
|
|
{
|
2012-11-15 02:17:59 +00:00
|
|
|
GstGLWindowWin32Class *window_class;
|
|
|
|
GstGLWindowWin32Private *priv;
|
|
|
|
GstGLWindowWin32 *window_win32;
|
|
|
|
|
|
|
|
window_win32 = GST_GL_WINDOW_WIN32 (window);
|
|
|
|
window_class = GST_GL_WINDOW_WIN32_GET_CLASS (window_win32);
|
|
|
|
priv = window_win32->priv;
|
|
|
|
|
|
|
|
priv->activate_result = window_class->activate (window_win32, priv->activate);
|
2009-10-22 23:11:27 +00:00
|
|
|
}
|
|
|
|
|
2012-11-15 02:17:59 +00:00
|
|
|
gboolean
|
|
|
|
gst_gl_window_win32_activate (GstGLWindow * window, gboolean activate)
|
2009-10-22 23:11:27 +00:00
|
|
|
{
|
2012-11-15 02:17:59 +00:00
|
|
|
GstGLWindowWin32 *window_win32;
|
|
|
|
GstGLWindowWin32Private *priv;
|
|
|
|
|
|
|
|
window_win32 = GST_GL_WINDOW_WIN32 (window);
|
|
|
|
priv = window_win32->priv;
|
|
|
|
priv->activate = activate;
|
|
|
|
|
|
|
|
gst_gl_window_win32_send_message (window,
|
|
|
|
GST_GL_WINDOW_CB (callback_activate), window_win32);
|
|
|
|
|
|
|
|
return priv->activate_result;
|
2009-10-22 23:11:27 +00:00
|
|
|
}
|
|
|
|
|
2008-11-23 15:04:27 +00:00
|
|
|
void
|
2012-11-15 02:17:59 +00:00
|
|
|
gst_gl_window_win32_set_window_handle (GstGLWindow * window, guintptr id)
|
2008-10-22 23:40:52 +00:00
|
|
|
{
|
2012-11-15 02:17:59 +00:00
|
|
|
GstGLWindowWin32 *window_win32;
|
|
|
|
HWND parent_id;
|
|
|
|
|
|
|
|
window_win32 = GST_GL_WINDOW_WIN32 (window);
|
2009-06-06 12:34:57 +00:00
|
|
|
|
|
|
|
//retrieve parent if previously set
|
2012-11-15 02:17:59 +00:00
|
|
|
parent_id = GetProp (window_win32->internal_win_id, "gl_window_parent_id");
|
2009-06-06 12:34:57 +00:00
|
|
|
|
2012-11-15 02:17:59 +00:00
|
|
|
if (window_win32->visible) {
|
|
|
|
ShowWindow (window_win32->internal_win_id, SW_HIDE);
|
|
|
|
window_win32->visible = FALSE;
|
2012-04-11 08:44:23 +00:00
|
|
|
}
|
2009-10-23 18:52:32 +00:00
|
|
|
|
2009-06-06 12:34:57 +00:00
|
|
|
if (parent_id) {
|
|
|
|
WNDPROC parent_proc = GetProp (parent_id, "gl_window_parent_proc");
|
|
|
|
|
2012-11-15 02:17:59 +00:00
|
|
|
GST_DEBUG ("release parent %" G_GUINTPTR_FORMAT "\n", (guintptr) parent_id);
|
2009-06-06 12:34:57 +00:00
|
|
|
|
2012-04-11 08:44:23 +00:00
|
|
|
g_return_if_fail (parent_proc);
|
2009-06-06 12:34:57 +00:00
|
|
|
|
2012-05-20 15:45:06 +00:00
|
|
|
SetWindowLongPtr (parent_id, GWLP_WNDPROC, (LONG_PTR) parent_proc);
|
2012-11-15 02:17:59 +00:00
|
|
|
SetParent (window_win32->internal_win_id, NULL);
|
2009-06-06 12:34:57 +00:00
|
|
|
|
|
|
|
RemoveProp (parent_id, "gl_window_parent_proc");
|
2012-11-15 02:17:59 +00:00
|
|
|
RemoveProp (window_win32->internal_win_id, "gl_window_parent_id");
|
2009-06-06 12:34:57 +00:00
|
|
|
}
|
|
|
|
//not 0
|
|
|
|
if (id) {
|
|
|
|
WNDPROC window_parent_proc =
|
2012-05-20 15:45:06 +00:00
|
|
|
(WNDPROC) GetWindowLongPtr ((HWND) id, GWLP_WNDPROC);
|
2009-06-06 12:34:57 +00:00
|
|
|
RECT rect;
|
|
|
|
|
2012-11-15 02:17:59 +00:00
|
|
|
GST_DEBUG ("set parent %" G_GUINTPTR_FORMAT "\n", id);
|
2009-06-06 12:34:57 +00:00
|
|
|
|
2012-11-15 02:17:59 +00:00
|
|
|
SetProp (window_win32->internal_win_id, "gl_window_parent_id", (HWND) id);
|
|
|
|
SetProp ((HWND) id, "gl_window_id", window_win32->internal_win_id);
|
2009-06-06 12:34:57 +00:00
|
|
|
SetProp ((HWND) id, "gl_window_parent_proc", (WNDPROC) window_parent_proc);
|
2012-05-20 15:45:06 +00:00
|
|
|
SetWindowLongPtr ((HWND) id, GWLP_WNDPROC, (LONG_PTR) sub_class_proc);
|
2009-06-06 12:34:57 +00:00
|
|
|
|
2012-11-15 02:17:59 +00:00
|
|
|
SetWindowLongPtr (window_win32->internal_win_id, GWL_STYLE,
|
|
|
|
WS_CHILD | WS_MAXIMIZE);
|
|
|
|
SetParent (window_win32->internal_win_id, (HWND) id);
|
2009-06-06 12:34:57 +00:00
|
|
|
|
|
|
|
//take changes into account: SWP_FRAMECHANGED
|
|
|
|
GetClientRect ((HWND) id, &rect);
|
2012-11-15 02:17:59 +00:00
|
|
|
SetWindowPos (window_win32->internal_win_id, HWND_TOP, rect.left, rect.top,
|
2009-06-06 12:34:57 +00:00
|
|
|
rect.right, rect.bottom,
|
|
|
|
SWP_ASYNCWINDOWPOS | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER |
|
|
|
|
SWP_FRAMECHANGED | SWP_NOACTIVATE);
|
2012-11-15 02:17:59 +00:00
|
|
|
MoveWindow (window_win32->internal_win_id, rect.left, rect.top, rect.right,
|
2009-06-06 12:34:57 +00:00
|
|
|
rect.bottom, FALSE);
|
|
|
|
} else {
|
|
|
|
//no parent so the internal window needs borders and system menu
|
2012-11-15 02:17:59 +00:00
|
|
|
SetWindowLongPtr (window_win32->internal_win_id, GWL_STYLE,
|
2012-04-11 08:44:23 +00:00
|
|
|
WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW);
|
2009-06-06 12:34:57 +00:00
|
|
|
}
|
2008-10-22 23:40:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Thread safe */
|
|
|
|
void
|
2012-11-15 02:17:59 +00:00
|
|
|
gst_gl_window_win32_draw (GstGLWindow * window, guint width, guint height)
|
2008-10-22 23:40:52 +00:00
|
|
|
{
|
2012-11-15 02:17:59 +00:00
|
|
|
GstGLWindowWin32 *window_win32 = GST_GL_WINDOW_WIN32 (window);
|
2008-10-25 14:18:23 +00:00
|
|
|
|
2012-11-15 02:17:59 +00:00
|
|
|
if (!window_win32->visible) {
|
|
|
|
HWND parent_id =
|
|
|
|
GetProp (window_win32->internal_win_id, "gl_window_parent_id");
|
2009-10-22 23:11:27 +00:00
|
|
|
/* if no parent the real size has to be set now because this has not been done
|
|
|
|
* when at window creation */
|
|
|
|
if (!parent_id) {
|
|
|
|
RECT rect;
|
2012-11-15 02:17:59 +00:00
|
|
|
GetClientRect (window_win32->internal_win_id, &rect);
|
2009-10-22 23:11:27 +00:00
|
|
|
width += 2 * GetSystemMetrics (SM_CXSIZEFRAME);
|
2012-04-11 08:44:23 +00:00
|
|
|
height +=
|
|
|
|
2 * GetSystemMetrics (SM_CYSIZEFRAME) +
|
|
|
|
GetSystemMetrics (SM_CYCAPTION);
|
2012-11-15 02:17:59 +00:00
|
|
|
MoveWindow (window_win32->internal_win_id, rect.left, rect.top, width,
|
|
|
|
height, FALSE);
|
2009-10-22 23:11:27 +00:00
|
|
|
}
|
2012-11-15 02:17:59 +00:00
|
|
|
ShowWindowAsync (window_win32->internal_win_id, SW_SHOW);
|
2009-10-23 18:52:32 +00:00
|
|
|
|
2012-11-15 02:17:59 +00:00
|
|
|
window_win32->visible = TRUE;
|
2008-11-22 15:43:24 +00:00
|
|
|
}
|
2008-10-22 23:40:52 +00:00
|
|
|
|
2012-11-15 02:17:59 +00:00
|
|
|
RedrawWindow (window_win32->internal_win_id, NULL, NULL,
|
2009-02-11 06:39:14 +00:00
|
|
|
RDW_NOERASE | RDW_INTERNALPAINT | RDW_INVALIDATE);
|
2008-10-22 23:40:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-11-15 02:17:59 +00:00
|
|
|
gst_gl_window_win32_run (GstGLWindow * window)
|
2008-10-22 23:40:52 +00:00
|
|
|
{
|
2012-11-15 02:17:59 +00:00
|
|
|
gint bRet;
|
2008-10-22 23:40:52 +00:00
|
|
|
MSG msg;
|
|
|
|
|
2012-11-15 02:17:59 +00:00
|
|
|
GST_INFO ("begin message loop\n");
|
2008-10-22 23:40:52 +00:00
|
|
|
|
2012-11-15 02:17:59 +00:00
|
|
|
while (TRUE) {
|
|
|
|
bRet = GetMessage (&msg, NULL, 0, 0);
|
|
|
|
if (bRet == 0)
|
|
|
|
break;
|
|
|
|
else if (bRet == -1) {
|
|
|
|
GST_WARNING ("Failed to get message %lud\n", GetLastError ());
|
|
|
|
break;
|
2009-02-11 06:39:14 +00:00
|
|
|
} else {
|
2012-11-15 02:17:59 +00:00
|
|
|
GST_TRACE ("handle message");
|
2009-02-11 06:39:14 +00:00
|
|
|
TranslateMessage (&msg);
|
|
|
|
DispatchMessage (&msg);
|
|
|
|
}
|
2008-10-22 23:40:52 +00:00
|
|
|
}
|
2008-10-23 23:39:00 +00:00
|
|
|
|
2012-11-15 02:17:59 +00:00
|
|
|
GST_INFO ("end message loop\n");
|
2008-10-22 23:40:52 +00:00
|
|
|
}
|
|
|
|
|
2008-10-23 23:39:00 +00:00
|
|
|
/* Thread safe */
|
2008-10-22 23:40:52 +00:00
|
|
|
void
|
2012-11-15 02:17:59 +00:00
|
|
|
gst_gl_window_win32_quit (GstGLWindow * window, GstGLWindowCB callback,
|
2009-02-11 06:39:14 +00:00
|
|
|
gpointer data)
|
2008-10-22 23:40:52 +00:00
|
|
|
{
|
2012-11-15 02:17:59 +00:00
|
|
|
GstGLWindowWin32 *window_win32;
|
|
|
|
|
|
|
|
window_win32 = GST_GL_WINDOW_WIN32 (window);
|
|
|
|
|
|
|
|
if (window_win32 && window_win32->internal_win_id) {
|
|
|
|
LRESULT res =
|
|
|
|
PostMessage (window_win32->internal_win_id, WM_GST_GL_WINDOW_QUIT,
|
2009-02-11 06:39:14 +00:00
|
|
|
(WPARAM) data, (LPARAM) callback);
|
2012-11-15 02:17:59 +00:00
|
|
|
GST_DEBUG ("end loop requested");
|
2012-04-11 08:44:23 +00:00
|
|
|
g_return_if_fail (SUCCEEDED (res));
|
2008-10-23 23:39:00 +00:00
|
|
|
}
|
2008-10-22 23:40:52 +00:00
|
|
|
}
|
|
|
|
|
2008-10-23 23:39:00 +00:00
|
|
|
/* Thread safe */
|
2008-10-22 23:40:52 +00:00
|
|
|
void
|
2012-11-15 02:17:59 +00:00
|
|
|
gst_gl_window_win32_send_message (GstGLWindow * window, GstGLWindowCB callback,
|
2009-02-11 06:39:14 +00:00
|
|
|
gpointer data)
|
2008-10-22 23:40:52 +00:00
|
|
|
{
|
2012-11-15 02:17:59 +00:00
|
|
|
GstGLWindowWin32 *window_win32;
|
|
|
|
|
|
|
|
window_win32 = GST_GL_WINDOW_WIN32 (window);
|
|
|
|
|
|
|
|
if (window_win32) {
|
|
|
|
LRESULT res =
|
|
|
|
SendMessage (window_win32->internal_win_id, WM_GST_GL_WINDOW_CUSTOM,
|
2009-02-11 06:39:14 +00:00
|
|
|
(WPARAM) data, (LPARAM) callback);
|
2012-04-11 08:44:23 +00:00
|
|
|
g_return_if_fail (SUCCEEDED (res));
|
2008-10-23 23:39:00 +00:00
|
|
|
}
|
2008-10-22 23:40:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* PRIVATE */
|
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
LRESULT CALLBACK
|
|
|
|
window_proc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
2008-10-22 23:40:52 +00:00
|
|
|
{
|
2012-11-15 02:17:59 +00:00
|
|
|
GstGLWindowWin32 *window_win32;
|
|
|
|
GstGLWindowWin32Class *window_class;
|
|
|
|
GstGLWindowWin32Private *priv;
|
|
|
|
|
2008-10-22 23:40:52 +00:00
|
|
|
if (uMsg == WM_CREATE) {
|
2012-11-15 02:17:59 +00:00
|
|
|
window_win32 =
|
|
|
|
GST_GL_WINDOW_WIN32 (((LPCREATESTRUCT) lParam)->lpCreateParams);
|
|
|
|
window_class = GST_GL_WINDOW_WIN32_GET_CLASS (window_win32);
|
2008-10-22 23:40:52 +00:00
|
|
|
|
2012-11-15 02:17:59 +00:00
|
|
|
GST_DEBUG ("WM_CREATE\n");
|
2008-10-22 23:40:52 +00:00
|
|
|
|
2012-11-15 02:17:59 +00:00
|
|
|
{
|
|
|
|
priv = window_win32->priv;
|
|
|
|
window_win32->device = GetDC (hWnd);
|
2008-10-22 23:40:52 +00:00
|
|
|
|
2012-11-15 02:17:59 +00:00
|
|
|
// gst_gl_window_set_pixel_format (window_win32);
|
|
|
|
window_class->choose_format (window_win32);
|
2008-10-22 23:40:52 +00:00
|
|
|
|
2012-11-15 02:17:59 +00:00
|
|
|
window_class->create_context (window_win32, priv->render_api,
|
|
|
|
priv->external_gl_context);
|
|
|
|
|
|
|
|
/* priv->gl_context = wglCreateContext (priv->device);
|
2008-10-25 00:03:16 +00:00
|
|
|
if (priv->gl_context)
|
2012-11-15 02:17:59 +00:00
|
|
|
GST_DEBUG ("gl context created: %" G_GUINTPTR_FORMAT "\n",
|
2012-05-20 15:45:06 +00:00
|
|
|
(guintptr) priv->gl_context);
|
2008-10-25 00:03:16 +00:00
|
|
|
else
|
2012-11-15 02:17:59 +00:00
|
|
|
GST_DEBUG ("failed to create glcontext %" G_GUINTPTR_FORMAT ", %lud\n",
|
2012-05-20 15:45:06 +00:00
|
|
|
(guintptr) hWnd, GetLastError ());
|
2012-11-15 02:17:59 +00:00
|
|
|
g_assert (priv->gl_context);*/
|
|
|
|
ReleaseDC (hWnd, window_win32->device);
|
2009-04-18 11:57:44 +00:00
|
|
|
|
2012-11-15 02:17:59 +00:00
|
|
|
window_class->activate (window_win32, TRUE);
|
|
|
|
|
|
|
|
/* if (!wglMakeCurrent (priv->device, priv->gl_context))
|
|
|
|
GST_DEBUG ("failed to make opengl context current %" G_GUINTPTR_FORMAT
|
|
|
|
", %lud\n", (guintptr) hWnd, GetLastError ());
|
|
|
|
*/
|
|
|
|
if (priv->external_gl_context)
|
|
|
|
window_class->share_context (window_win32, priv->external_gl_context);
|
|
|
|
/*
|
2009-04-18 11:57:44 +00:00
|
|
|
if (priv->external_gl_context) {
|
2010-03-09 00:35:42 +00:00
|
|
|
if (!wglShareLists (priv->external_gl_context, priv->gl_context))
|
2012-11-15 02:17:59 +00:00
|
|
|
GST_DEBUG ("failed to share opengl context %" G_GUINTPTR_FORMAT
|
2012-05-20 15:45:06 +00:00
|
|
|
" with %" G_GUINTPTR_FORMAT "\n", (guintptr) priv->gl_context,
|
|
|
|
(guintptr) priv->external_gl_context);
|
2009-04-18 11:57:44 +00:00
|
|
|
else
|
2012-11-15 02:17:59 +00:00
|
|
|
GST_DEBUG ("share opengl context succeed %" G_GUINTPTR_FORMAT "\n",
|
2012-05-20 15:45:06 +00:00
|
|
|
(guintptr) priv->external_gl_context);
|
2012-11-15 02:17:59 +00:00
|
|
|
}*/
|
2008-10-22 23:40:52 +00:00
|
|
|
}
|
|
|
|
|
2012-11-15 02:17:59 +00:00
|
|
|
SetProp (hWnd, "gl_window", window_win32);
|
2008-10-25 14:18:23 +00:00
|
|
|
|
2008-10-23 23:39:00 +00:00
|
|
|
return 0;
|
2009-02-11 06:39:14 +00:00
|
|
|
} else if (GetProp (hWnd, "gl_window")) {
|
2012-11-15 02:17:59 +00:00
|
|
|
GstGLWindow *window;
|
2008-10-22 23:40:52 +00:00
|
|
|
|
2012-11-15 02:17:59 +00:00
|
|
|
window_win32 = GST_GL_WINDOW_WIN32 (GetProp (hWnd, "gl_window"));
|
|
|
|
window_class = GST_GL_WINDOW_WIN32_GET_CLASS (window_win32);
|
|
|
|
window = GST_GL_WINDOW (window_win32);
|
|
|
|
priv = window_win32->priv;
|
2008-10-22 23:40:52 +00:00
|
|
|
|
2012-11-15 02:17:59 +00:00
|
|
|
g_assert (window_win32->internal_win_id == hWnd);
|
2008-10-22 23:40:52 +00:00
|
|
|
|
2012-11-15 02:17:59 +00:00
|
|
|
/* g_assert (!wglGetCurrentContext ()
|
2012-04-11 08:44:23 +00:00
|
|
|
|| priv->gl_context == wglGetCurrentContext ());
|
2012-11-15 02:17:59 +00:00
|
|
|
*/
|
2009-02-11 06:39:14 +00:00
|
|
|
switch (uMsg) {
|
2008-10-22 23:40:52 +00:00
|
|
|
|
|
|
|
case WM_SIZE:
|
|
|
|
{
|
2012-11-15 02:17:59 +00:00
|
|
|
if (window->resize) {
|
|
|
|
window->resize (window->resize_data, LOWORD (lParam),
|
|
|
|
HIWORD (lParam));
|
2009-10-22 23:11:27 +00:00
|
|
|
}
|
2008-10-22 23:40:52 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_PAINT:
|
2008-11-23 15:04:27 +00:00
|
|
|
{
|
2012-11-15 02:17:59 +00:00
|
|
|
if (window->draw) {
|
2008-10-22 23:40:52 +00:00
|
|
|
PAINTSTRUCT ps;
|
|
|
|
BeginPaint (hWnd, &ps);
|
2012-11-15 02:17:59 +00:00
|
|
|
window->draw (window->draw_data);
|
|
|
|
window_class->swap_buffers (window_win32);
|
|
|
|
// SwapBuffers (priv->device);
|
2008-10-22 23:40:52 +00:00
|
|
|
EndPaint (hWnd, &ps);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_CLOSE:
|
2008-11-22 15:43:24 +00:00
|
|
|
{
|
2012-11-15 02:17:59 +00:00
|
|
|
ShowWindowAsync (window_win32->internal_win_id, SW_HIDE);
|
2008-11-23 15:04:27 +00:00
|
|
|
|
2012-11-15 02:17:59 +00:00
|
|
|
GST_DEBUG ("WM_CLOSE\n");
|
2009-02-11 06:39:14 +00:00
|
|
|
|
2012-11-15 02:17:59 +00:00
|
|
|
if (window->close)
|
|
|
|
window->close (window->close_data);
|
2008-11-22 15:43:24 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_GST_GL_WINDOW_QUIT:
|
2008-10-22 23:40:52 +00:00
|
|
|
{
|
2008-10-28 20:44:09 +00:00
|
|
|
HWND parent_id = 0;
|
2008-11-22 15:43:24 +00:00
|
|
|
GstGLWindowCB destroy_cb = (GstGLWindowCB) lParam;
|
2008-10-28 20:44:09 +00:00
|
|
|
|
2012-11-15 02:17:59 +00:00
|
|
|
GST_DEBUG ("WM_GST_GL_WINDOW_QUIT\n");
|
2008-10-28 20:44:09 +00:00
|
|
|
|
2008-11-22 15:43:24 +00:00
|
|
|
destroy_cb ((gpointer) wParam);
|
|
|
|
|
2008-10-28 20:44:09 +00:00
|
|
|
parent_id = GetProp (hWnd, "gl_window_parent_id");
|
2009-02-11 06:39:14 +00:00
|
|
|
if (parent_id) {
|
2008-10-28 20:44:09 +00:00
|
|
|
WNDPROC parent_proc = GetProp (parent_id, "gl_window_parent_proc");
|
2008-11-23 15:04:27 +00:00
|
|
|
|
2008-10-28 20:44:09 +00:00
|
|
|
g_assert (parent_proc);
|
|
|
|
|
2012-05-20 15:45:06 +00:00
|
|
|
SetWindowLongPtr (parent_id, GWLP_WNDPROC, (LONG_PTR) parent_proc);
|
2008-10-28 20:44:09 +00:00
|
|
|
SetParent (hWnd, NULL);
|
|
|
|
|
|
|
|
RemoveProp (parent_id, "gl_window_parent_proc");
|
|
|
|
RemoveProp (hWnd, "gl_window_parent_id");
|
|
|
|
}
|
|
|
|
|
2012-11-15 02:17:59 +00:00
|
|
|
window_win32->is_closed = TRUE;
|
2008-10-28 20:44:09 +00:00
|
|
|
RemoveProp (hWnd, "gl_window");
|
2008-10-25 14:18:23 +00:00
|
|
|
|
2012-11-15 02:17:59 +00:00
|
|
|
window_class->activate (window_win32, FALSE);
|
|
|
|
|
|
|
|
window_class->destroy_context (window_win32);
|
|
|
|
|
|
|
|
/* if (!wglMakeCurrent (NULL, NULL))
|
|
|
|
GST_DEBUG ("failed to make current %" G_GUINTPTR_FORMAT ", %lud\n",
|
2012-05-20 15:45:06 +00:00
|
|
|
(guintptr) hWnd, GetLastError ());
|
2008-10-22 23:40:52 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
if (priv->gl_context) {
|
2008-10-25 14:18:23 +00:00
|
|
|
if (!wglDeleteContext (priv->gl_context))
|
2012-11-15 02:17:59 +00:00
|
|
|
GST_DEBUG ("failed to destroy context %" G_GUINTPTR_FORMAT ", %lud\n",
|
2012-05-20 15:45:06 +00:00
|
|
|
(guintptr) priv->gl_context, GetLastError ());
|
2008-10-25 14:18:23 +00:00
|
|
|
}
|
2012-11-15 02:17:59 +00:00
|
|
|
*/
|
|
|
|
if (window_win32->internal_win_id) {
|
|
|
|
if (!DestroyWindow (window_win32->internal_win_id))
|
|
|
|
GST_DEBUG ("failed to destroy window %" G_GUINTPTR_FORMAT
|
|
|
|
", %lud\n", (guintptr) hWnd, GetLastError ());
|
2008-10-25 14:18:23 +00:00
|
|
|
}
|
2008-11-23 15:04:27 +00:00
|
|
|
|
2008-10-22 23:40:52 +00:00
|
|
|
PostQuitMessage (0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_CAPTURECHANGED:
|
|
|
|
{
|
2012-11-15 02:17:59 +00:00
|
|
|
GST_DEBUG ("WM_CAPTURECHANGED\n");
|
|
|
|
if (window->draw)
|
|
|
|
window->draw (window->draw_data);
|
2008-10-22 23:40:52 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-11-22 15:43:24 +00:00
|
|
|
case WM_GST_GL_WINDOW_CUSTOM:
|
2008-10-22 23:40:52 +00:00
|
|
|
{
|
2012-11-15 02:17:59 +00:00
|
|
|
if (!window_win32->is_closed) {
|
2008-10-25 14:18:23 +00:00
|
|
|
GstGLWindowCB custom_cb = (GstGLWindowCB) lParam;
|
|
|
|
custom_cb ((gpointer) wParam);
|
|
|
|
}
|
2008-10-22 23:40:52 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2008-10-25 00:03:16 +00:00
|
|
|
case WM_ERASEBKGND:
|
|
|
|
return TRUE;
|
|
|
|
|
2008-10-22 23:40:52 +00:00
|
|
|
default:
|
2012-04-11 08:44:23 +00:00
|
|
|
{
|
|
|
|
/* transmit messages to the parrent (ex: mouse/keyboard input) */
|
|
|
|
HWND parent_id = GetProp (hWnd, "gl_window_parent_id");
|
|
|
|
if (parent_id)
|
|
|
|
PostMessage (parent_id, uMsg, wParam, lParam);
|
|
|
|
return DefWindowProc (hWnd, uMsg, wParam, lParam);
|
|
|
|
}
|
2008-10-22 23:40:52 +00:00
|
|
|
}
|
|
|
|
|
2008-10-23 23:39:00 +00:00
|
|
|
return 0;
|
2009-02-11 06:39:14 +00:00
|
|
|
} else
|
|
|
|
return DefWindowProc (hWnd, uMsg, wParam, lParam);
|
2008-10-22 23:40:52 +00:00
|
|
|
}
|
2008-10-27 23:22:27 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
LRESULT FAR PASCAL
|
|
|
|
sub_class_proc (HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
2008-10-27 23:22:27 +00:00
|
|
|
{
|
|
|
|
WNDPROC window_parent_proc = GetProp (hWnd, "gl_window_parent_proc");
|
2008-11-23 15:04:27 +00:00
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
if (uMsg == WM_SIZE) {
|
2008-10-28 20:44:09 +00:00
|
|
|
HWND gl_window_id = GetProp (hWnd, "gl_window_id");
|
2009-02-11 06:39:14 +00:00
|
|
|
MoveWindow (gl_window_id, 0, 0, LOWORD (lParam), HIWORD (lParam), FALSE);
|
2008-10-27 23:22:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return CallWindowProc (window_parent_proc, hWnd, uMsg, wParam, lParam);
|
|
|
|
}
|