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"
|
2015-05-20 19:29:50 +00:00
|
|
|
#include "win32_message_source.h"
|
2008-10-22 23:40:52 +00:00
|
|
|
|
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
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0
|
|
|
|
};
|
|
|
|
|
2012-11-15 02:17:59 +00:00
|
|
|
struct _GstGLWindowWin32Private
|
2008-10-22 23:40:52 +00:00
|
|
|
{
|
2015-01-23 03:11:48 +00:00
|
|
|
gint preferred_width;
|
|
|
|
gint preferred_height;
|
2008-10-22 23:40:52 +00:00
|
|
|
};
|
|
|
|
|
2012-11-29 02:06:24 +00:00
|
|
|
#define GST_CAT_DEFAULT gst_gl_window_win32_debug
|
2012-11-15 02:17:59 +00:00
|
|
|
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,
|
2018-06-23 19:33:16 +00:00
|
|
|
GST_TYPE_GL_WINDOW, G_ADD_PRIVATE (GstGLWindowWin32) DEBUG_INIT);
|
2010-01-05 23:13:46 +00:00
|
|
|
|
2013-08-15 07:09:04 +00:00
|
|
|
static void gst_gl_window_win32_set_window_handle (GstGLWindow * window,
|
2012-11-15 02:17:59 +00:00
|
|
|
guintptr handle);
|
2013-08-15 07:09:04 +00:00
|
|
|
static guintptr gst_gl_window_win32_get_display (GstGLWindow * window);
|
2015-01-23 03:11:48 +00:00
|
|
|
static void gst_gl_window_win32_set_preferred_size (GstGLWindow * window,
|
|
|
|
gint width, gint height);
|
2015-01-29 11:25:00 +00:00
|
|
|
static void gst_gl_window_win32_show (GstGLWindow * window);
|
2015-01-23 03:11:48 +00:00
|
|
|
static void gst_gl_window_win32_draw (GstGLWindow * window);
|
2015-05-20 19:29:50 +00:00
|
|
|
gboolean gst_gl_window_win32_open (GstGLWindow * window, GError ** error);
|
|
|
|
void gst_gl_window_win32_close (GstGLWindow * window);
|
2015-05-20 21:09:21 +00:00
|
|
|
static void release_parent_win_id (GstGLWindowWin32 * window_win32);
|
2015-05-20 19:29:50 +00:00
|
|
|
|
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
|
|
|
{
|
2013-03-09 11:53:09 +00:00
|
|
|
GstGLWindowClass *window_class = (GstGLWindowClass *) klass;
|
2008-10-22 23:40:52 +00:00
|
|
|
|
2012-11-15 02:17:59 +00:00
|
|
|
window_class->set_window_handle =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_gl_window_win32_set_window_handle);
|
|
|
|
window_class->draw = GST_DEBUG_FUNCPTR (gst_gl_window_win32_draw);
|
2013-08-15 07:09:04 +00:00
|
|
|
window_class->get_display =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_gl_window_win32_get_display);
|
2015-01-23 03:11:48 +00:00
|
|
|
window_class->set_preferred_size =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_gl_window_win32_set_preferred_size);
|
2015-01-29 11:25:00 +00:00
|
|
|
window_class->show = GST_DEBUG_FUNCPTR (gst_gl_window_win32_show);
|
2015-05-20 19:29:50 +00:00
|
|
|
window_class->open = GST_DEBUG_FUNCPTR (gst_gl_window_win32_open);
|
|
|
|
window_class->close = GST_DEBUG_FUNCPTR (gst_gl_window_win32_close);
|
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
|
|
|
{
|
2018-06-23 19:33:16 +00:00
|
|
|
window->priv = gst_gl_window_win32_get_instance_private (window);
|
2008-10-22 23:40:52 +00:00
|
|
|
}
|
|
|
|
|
2012-11-15 02:17:59 +00:00
|
|
|
GstGLWindowWin32 *
|
2015-07-27 10:00:47 +00:00
|
|
|
gst_gl_window_win32_new (GstGLDisplay * display)
|
2008-10-22 23:40:52 +00:00
|
|
|
{
|
2017-05-15 17:31:31 +00:00
|
|
|
GstGLWindowWin32 *window;
|
|
|
|
|
2015-07-24 07:00:27 +00:00
|
|
|
if ((gst_gl_display_get_handle_type (display) & GST_GL_DISPLAY_TYPE_WIN32) ==
|
|
|
|
0)
|
|
|
|
/* we require an win32 display to create win32 windows */
|
|
|
|
return NULL;
|
2008-10-25 14:18:23 +00:00
|
|
|
|
2017-05-15 17:31:31 +00:00
|
|
|
window = g_object_new (GST_TYPE_GL_WINDOW_WIN32, NULL);
|
|
|
|
gst_object_ref_sink (window);
|
|
|
|
|
|
|
|
return window;
|
2012-11-15 02:17:59 +00:00
|
|
|
}
|
|
|
|
|
2015-05-20 19:29:50 +00:00
|
|
|
static void
|
|
|
|
msg_cb (GstGLWindowWin32 * window_win32, MSG * msg, gpointer user_data)
|
|
|
|
{
|
|
|
|
GST_TRACE ("handle message");
|
|
|
|
TranslateMessage (msg);
|
|
|
|
DispatchMessage (msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gst_gl_window_win32_open (GstGLWindow * window, GError ** error)
|
|
|
|
{
|
|
|
|
GstGLWindowWin32 *window_win32 = GST_GL_WINDOW_WIN32 (window);
|
|
|
|
|
2015-06-04 02:16:35 +00:00
|
|
|
if (!GST_GL_WINDOW_CLASS (parent_class)->open (window, error))
|
|
|
|
return FALSE;
|
|
|
|
|
2015-05-20 19:29:50 +00:00
|
|
|
window_win32->msg_source = win32_message_source_new (window_win32);
|
|
|
|
g_source_set_callback (window_win32->msg_source, (GSourceFunc) msg_cb,
|
|
|
|
NULL, NULL);
|
2016-12-14 13:59:45 +00:00
|
|
|
g_source_attach (window_win32->msg_source, window->main_context);
|
2015-05-20 19:29:50 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
gst_gl_window_win32_close (GstGLWindow * window)
|
|
|
|
{
|
|
|
|
GstGLWindowWin32 *window_win32 = GST_GL_WINDOW_WIN32 (window);
|
|
|
|
|
2015-05-20 21:09:21 +00:00
|
|
|
release_parent_win_id (window_win32);
|
|
|
|
|
|
|
|
if (window_win32->internal_win_id) {
|
|
|
|
RemoveProp (window_win32->internal_win_id, "gl_window");
|
2016-05-16 21:11:53 +00:00
|
|
|
ShowWindow (window_win32->internal_win_id, SW_HIDE);
|
|
|
|
SetParent (window_win32->internal_win_id, NULL);
|
2015-05-20 21:09:21 +00:00
|
|
|
if (!DestroyWindow (window_win32->internal_win_id))
|
|
|
|
GST_WARNING ("failed to destroy window %" G_GUINTPTR_FORMAT
|
|
|
|
", 0x%x", (guintptr) window_win32->internal_win_id,
|
|
|
|
(unsigned int) GetLastError ());
|
|
|
|
}
|
|
|
|
|
2015-05-20 19:29:50 +00:00
|
|
|
g_source_destroy (window_win32->msg_source);
|
|
|
|
g_source_unref (window_win32->msg_source);
|
|
|
|
window_win32->msg_source = NULL;
|
2015-06-04 02:16:35 +00:00
|
|
|
|
|
|
|
GST_GL_WINDOW_CLASS (parent_class)->close (window);
|
2015-05-20 19:29:50 +00:00
|
|
|
}
|
|
|
|
|
2015-05-20 19:30:49 +00:00
|
|
|
static void
|
|
|
|
set_parent_win_id (GstGLWindowWin32 * window_win32)
|
|
|
|
{
|
|
|
|
WNDPROC window_parent_proc;
|
|
|
|
RECT rect;
|
|
|
|
|
|
|
|
if (!window_win32->parent_win_id) {
|
|
|
|
/* no parent so the internal window needs borders and system menu */
|
|
|
|
SetWindowLongPtr (window_win32->internal_win_id, GWL_STYLE,
|
|
|
|
WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_OVERLAPPEDWINDOW);
|
2015-05-21 19:30:34 +00:00
|
|
|
SetParent (window_win32->internal_win_id, NULL);
|
2015-05-20 19:30:49 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
window_parent_proc =
|
|
|
|
(WNDPROC) GetWindowLongPtr (window_win32->parent_win_id, GWLP_WNDPROC);
|
|
|
|
|
|
|
|
GST_DEBUG ("set parent %" G_GUINTPTR_FORMAT,
|
|
|
|
(guintptr) window_win32->parent_win_id);
|
|
|
|
|
|
|
|
SetProp (window_win32->parent_win_id, "gl_window_id",
|
|
|
|
window_win32->internal_win_id);
|
|
|
|
SetProp (window_win32->parent_win_id, "gl_window_parent_proc",
|
|
|
|
(WNDPROC) window_parent_proc);
|
|
|
|
SetWindowLongPtr (window_win32->parent_win_id, GWLP_WNDPROC,
|
|
|
|
(LONG_PTR) sub_class_proc);
|
|
|
|
|
|
|
|
SetWindowLongPtr (window_win32->internal_win_id, GWL_STYLE,
|
|
|
|
WS_CHILD | WS_MAXIMIZE);
|
|
|
|
SetParent (window_win32->internal_win_id, window_win32->parent_win_id);
|
|
|
|
|
|
|
|
/* take changes into account: SWP_FRAMECHANGED */
|
|
|
|
GetClientRect (window_win32->parent_win_id, &rect);
|
|
|
|
SetWindowPos (window_win32->internal_win_id, HWND_TOP, rect.left, rect.top,
|
|
|
|
rect.right, rect.bottom,
|
|
|
|
SWP_ASYNCWINDOWPOS | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER |
|
|
|
|
SWP_FRAMECHANGED | SWP_NOACTIVATE);
|
|
|
|
MoveWindow (window_win32->internal_win_id, rect.left, rect.top, rect.right,
|
|
|
|
rect.bottom, FALSE);
|
|
|
|
}
|
|
|
|
|
2015-05-20 21:09:21 +00:00
|
|
|
static void
|
|
|
|
release_parent_win_id (GstGLWindowWin32 * window_win32)
|
|
|
|
{
|
|
|
|
WNDPROC parent_proc;
|
|
|
|
|
|
|
|
if (!window_win32->parent_win_id)
|
|
|
|
return;
|
|
|
|
|
|
|
|
parent_proc = GetProp (window_win32->parent_win_id, "gl_window_parent_proc");
|
|
|
|
if (!parent_proc)
|
|
|
|
return;
|
|
|
|
|
|
|
|
GST_DEBUG ("release parent %" G_GUINTPTR_FORMAT,
|
|
|
|
(guintptr) window_win32->parent_win_id);
|
|
|
|
|
|
|
|
SetWindowLongPtr (window_win32->parent_win_id, GWLP_WNDPROC,
|
|
|
|
(LONG_PTR) parent_proc);
|
|
|
|
|
|
|
|
RemoveProp (window_win32->parent_win_id, "gl_window_parent_proc");
|
|
|
|
}
|
|
|
|
|
2012-11-15 02:17:59 +00:00
|
|
|
gboolean
|
2013-08-15 07:09:04 +00:00
|
|
|
gst_gl_window_win32_create_window (GstGLWindowWin32 * window_win32,
|
|
|
|
GError ** error)
|
2012-11-15 02:17:59 +00:00
|
|
|
{
|
2013-08-15 07:09:04 +00:00
|
|
|
// GstGLWindowWin32 *window_win32 = GST_GL_WINDOW_WIN32 (window);
|
2013-03-09 11:53:09 +00:00
|
|
|
WNDCLASSEX wc;
|
|
|
|
ATOM atom = 0;
|
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
|
|
|
|
2013-03-09 11:53:09 +00:00
|
|
|
GST_LOG ("Attempting to create a win32 window");
|
|
|
|
|
2008-10-25 00:03:16 +00:00
|
|
|
x += 20;
|
|
|
|
y += 20;
|
2008-10-22 23:40:52 +00:00
|
|
|
|
2013-03-09 11:53:09 +00:00
|
|
|
atom = GetClassInfoEx (hinstance, "GSTGL", &wc);
|
|
|
|
|
|
|
|
if (atom == 0) {
|
|
|
|
ZeroMemory (&wc, sizeof (WNDCLASSEX));
|
|
|
|
|
|
|
|
wc.cbSize = sizeof (WNDCLASSEX);
|
|
|
|
wc.lpfnWndProc = window_proc;
|
|
|
|
wc.cbClsExtra = 0;
|
|
|
|
wc.cbWndExtra = 0;
|
|
|
|
wc.hInstance = hinstance;
|
|
|
|
wc.hIcon = LoadIcon (NULL, IDI_WINLOGO);
|
|
|
|
wc.hIconSm = NULL;
|
|
|
|
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 = RegisterClassEx (&wc);
|
|
|
|
|
|
|
|
if (atom == 0) {
|
2013-08-15 07:09:04 +00:00
|
|
|
g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_FAILED,
|
|
|
|
"Failed to register window class 0x%x\n",
|
|
|
|
(unsigned int) GetLastError ());
|
2013-03-09 11:53:09 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-15 02:17:59 +00:00
|
|
|
window_win32->internal_win_id = 0;
|
|
|
|
window_win32->device = 0;
|
|
|
|
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) {
|
2013-08-15 07:09:04 +00:00
|
|
|
g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_FAILED,
|
|
|
|
"failed to create gl window");
|
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
|
|
|
|
2013-08-15 07:09:04 +00:00
|
|
|
GST_DEBUG ("gl window created: %" G_GUINTPTR_FORMAT,
|
2012-11-15 02:17:59 +00:00
|
|
|
(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) {
|
2013-08-15 07:09:04 +00:00
|
|
|
g_set_error (error, GST_GL_CONTEXT_ERROR, GST_GL_CONTEXT_ERROR_FAILED,
|
|
|
|
"failed to create device");
|
2012-04-13 13:08:00 +00:00
|
|
|
goto failure;
|
|
|
|
}
|
2008-10-22 23:40:52 +00:00
|
|
|
|
|
|
|
ShowCursor (TRUE);
|
|
|
|
|
2013-03-09 11:53:09 +00:00
|
|
|
GST_LOG ("Created a win32 window");
|
2015-05-20 19:30:49 +00:00
|
|
|
|
2016-05-16 19:26:53 +00:00
|
|
|
/* The window has been created as if it had no parent, so there is nothing
|
|
|
|
* else to do in that case. Even if user has already set a window,
|
|
|
|
* parent_win_id could still be 0 at this point, and in that case calling
|
|
|
|
* set_parent_win_id() here would steal focus from the parent window. */
|
|
|
|
if (window_win32->parent_win_id)
|
|
|
|
set_parent_win_id (window_win32);
|
2015-05-20 19:30:49 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-08-15 07:09:04 +00:00
|
|
|
static guintptr
|
|
|
|
gst_gl_window_win32_get_display (GstGLWindow * window)
|
2009-10-22 23:11:27 +00:00
|
|
|
{
|
2012-11-15 02:17:59 +00:00
|
|
|
GstGLWindowWin32 *window_win32;
|
|
|
|
|
|
|
|
window_win32 = GST_GL_WINDOW_WIN32 (window);
|
|
|
|
|
2013-08-15 07:09:04 +00:00
|
|
|
return (guintptr) window_win32->device;
|
2009-10-22 23:11:27 +00:00
|
|
|
}
|
|
|
|
|
2013-08-15 07:09:04 +00:00
|
|
|
static 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;
|
|
|
|
|
|
|
|
window_win32 = GST_GL_WINDOW_WIN32 (window);
|
2009-06-06 12:34:57 +00:00
|
|
|
|
2013-07-11 19:30:53 +00:00
|
|
|
if (!window_win32->internal_win_id) {
|
2013-07-18 18:26:44 +00:00
|
|
|
window_win32->parent_win_id = (HWND) id;
|
2013-07-11 19:30:53 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2015-05-20 21:09:21 +00:00
|
|
|
release_parent_win_id (window_win32);
|
2013-07-18 18:26:44 +00:00
|
|
|
window_win32->parent_win_id = (HWND) id;
|
2015-05-20 19:30:49 +00:00
|
|
|
set_parent_win_id (window_win32);
|
2008-10-22 23:40:52 +00:00
|
|
|
}
|
|
|
|
|
2015-01-23 03:11:48 +00:00
|
|
|
static void
|
2015-01-29 11:25:00 +00:00
|
|
|
gst_gl_window_win32_show (GstGLWindow * window)
|
2008-10-22 23:40:52 +00:00
|
|
|
{
|
2012-11-15 02:17:59 +00:00
|
|
|
GstGLWindowWin32 *window_win32 = GST_GL_WINDOW_WIN32 (window);
|
2015-01-29 12:45:15 +00:00
|
|
|
gint width = window_win32->priv->preferred_width;
|
|
|
|
gint height = window_win32->priv->preferred_height;
|
2008-10-25 14:18:23 +00:00
|
|
|
|
2012-11-15 02:17:59 +00:00
|
|
|
if (!window_win32->visible) {
|
2013-07-18 18:26:44 +00:00
|
|
|
HWND parent_id = window_win32->parent_win_id;
|
2013-07-11 19:30:53 +00:00
|
|
|
|
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
|
|
|
}
|
2009-10-23 18:52:32 +00:00
|
|
|
|
2015-01-29 11:25:00 +00:00
|
|
|
ShowWindowAsync (window_win32->internal_win_id, SW_SHOW);
|
2012-11-15 02:17:59 +00:00
|
|
|
window_win32->visible = TRUE;
|
2008-11-22 15:43:24 +00:00
|
|
|
}
|
2015-01-29 11:25:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_window_win32_set_preferred_size (GstGLWindow * window, gint width,
|
|
|
|
gint height)
|
|
|
|
{
|
|
|
|
GstGLWindowWin32 *window_win32 = GST_GL_WINDOW_WIN32 (window);
|
|
|
|
|
|
|
|
window_win32->priv->preferred_width = width;
|
|
|
|
window_win32->priv->preferred_height = height;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Thread safe */
|
|
|
|
static void
|
|
|
|
gst_gl_window_win32_draw (GstGLWindow * window)
|
|
|
|
{
|
|
|
|
GstGLWindowWin32 *window_win32 = GST_GL_WINDOW_WIN32 (window);
|
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
|
|
|
}
|
|
|
|
|
|
|
|
/* 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;
|
2015-05-20 21:06:42 +00:00
|
|
|
LRESULT ret = 0;
|
|
|
|
|
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);
|
2008-10-22 23:40:52 +00:00
|
|
|
|
2013-08-15 07:09:04 +00:00
|
|
|
GST_TRACE ("WM_CREATE");
|
2012-11-15 02:17:59 +00:00
|
|
|
|
2013-08-15 07:09:04 +00:00
|
|
|
window_win32->device = GetDC (hWnd);
|
|
|
|
/* Do this, otherwise we hang on exit. We can still use it (due to the
|
|
|
|
* CS_OWNDC flag in the WindowClass) after we have Released.
|
|
|
|
*/
|
|
|
|
ReleaseDC (hWnd, window_win32->device);
|
2008-10-22 23:40:52 +00:00
|
|
|
|
2012-11-15 02:17:59 +00:00
|
|
|
SetProp (hWnd, "gl_window", window_win32);
|
2009-02-11 06:39:14 +00:00
|
|
|
} else if (GetProp (hWnd, "gl_window")) {
|
2012-11-15 02:17:59 +00:00
|
|
|
GstGLWindow *window;
|
2013-08-15 07:09:04 +00:00
|
|
|
GstGLContext *context;
|
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 = GST_GL_WINDOW (window_win32);
|
2013-08-15 07:09:04 +00:00
|
|
|
context = gst_gl_window_get_context (window);
|
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
|
|
|
|
2009-02-11 06:39:14 +00:00
|
|
|
switch (uMsg) {
|
2008-10-22 23:40:52 +00:00
|
|
|
case WM_SIZE:
|
2015-09-17 07:06:37 +00:00
|
|
|
gst_gl_window_resize (window, LOWORD (lParam), HIWORD (lParam));
|
2008-10-22 23:40:52 +00:00
|
|
|
break;
|
|
|
|
case WM_PAINT:
|
2008-11-23 15:04:27 +00:00
|
|
|
{
|
2015-09-17 07:06:37 +00:00
|
|
|
if (window->queue_resize) {
|
|
|
|
guint width, height;
|
|
|
|
|
|
|
|
gst_gl_window_get_surface_dimensions (window, &width, &height);
|
|
|
|
gst_gl_window_resize (window, width, height);
|
|
|
|
}
|
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);
|
2017-05-21 10:03:01 +00:00
|
|
|
gst_gl_context_swap_buffers (context);
|
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
|
|
|
|
2013-08-15 07:09:04 +00:00
|
|
|
GST_TRACE ("WM_CLOSE");
|
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;
|
|
|
|
}
|
2008-10-22 23:40:52 +00:00
|
|
|
case WM_CAPTURECHANGED:
|
|
|
|
{
|
2013-08-15 07:09:04 +00:00
|
|
|
GST_DEBUG ("WM_CAPTURECHANGED");
|
2015-09-17 07:06:37 +00:00
|
|
|
if (window->queue_resize) {
|
|
|
|
guint width, height;
|
|
|
|
|
|
|
|
gst_gl_window_get_surface_dimensions (window, &width, &height);
|
|
|
|
gst_gl_window_resize (window, width, height);
|
|
|
|
}
|
2012-11-15 02:17:59 +00:00
|
|
|
if (window->draw)
|
|
|
|
window->draw (window->draw_data);
|
2008-10-22 23:40:52 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-10-25 00:03:16 +00:00
|
|
|
case WM_ERASEBKGND:
|
2015-05-20 21:06:42 +00:00
|
|
|
{
|
|
|
|
ret = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
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) */
|
2013-07-11 19:30:53 +00:00
|
|
|
HWND parent_id = window_win32->parent_win_id;
|
2012-04-11 08:44:23 +00:00
|
|
|
if (parent_id)
|
|
|
|
PostMessage (parent_id, uMsg, wParam, lParam);
|
2015-05-20 21:06:42 +00:00
|
|
|
ret = DefWindowProc (hWnd, uMsg, wParam, lParam);
|
2012-04-11 08:44:23 +00:00
|
|
|
}
|
2008-10-22 23:40:52 +00:00
|
|
|
}
|
|
|
|
|
2013-08-15 07:09:04 +00:00
|
|
|
gst_object_unref (context);
|
|
|
|
} else {
|
2015-05-20 21:06:42 +00:00
|
|
|
ret = DefWindowProc (hWnd, uMsg, wParam, lParam);
|
2013-08-15 07:09:04 +00:00
|
|
|
}
|
2015-05-20 21:06:42 +00:00
|
|
|
|
|
|
|
return ret;
|
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);
|
|
|
|
}
|