2009-02-26 00:06:58 +00:00
|
|
|
/*
|
|
|
|
* GStreamer
|
|
|
|
* Copyright (C) 2008 Julien Isorce <julien.isorce@gmail.com>
|
2014-09-26 10:05:27 +00:00
|
|
|
* Copyright (C) 2014 Sebastian Dröge <sebastian@centricular.com>
|
2009-02-26 00:06:58 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
2009-07-17 14:47:41 +00:00
|
|
|
* modify it un der the terms of the GNU Library General Public
|
2009-02-26 00:06:58 +00:00
|
|
|
* 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.
|
2009-02-26 00:06:58 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2012-11-16 06:13:03 +00:00
|
|
|
#include <Cocoa/Cocoa.h>
|
2009-02-26 00:06:58 +00:00
|
|
|
|
2013-08-15 07:09:04 +00:00
|
|
|
#include "gstgl_cocoa_private.h"
|
2009-02-26 00:06:58 +00:00
|
|
|
|
2009-07-17 14:47:41 +00:00
|
|
|
/* =============================================================*/
|
|
|
|
/* */
|
|
|
|
/* GstGLNSWindow declaration */
|
|
|
|
/* */
|
|
|
|
/* =============================================================*/
|
2009-02-26 00:06:58 +00:00
|
|
|
|
2014-10-18 04:26:52 +00:00
|
|
|
@interface GstGLNSWindow: NSWindow <NSApplicationDelegate> {
|
2009-02-26 00:06:58 +00:00
|
|
|
BOOL m_isClosed;
|
2014-09-26 10:05:27 +00:00
|
|
|
GstGLWindowCocoa *window_cocoa;
|
2009-02-26 00:06:58 +00:00
|
|
|
}
|
|
|
|
- (id)initWithContentRect:(NSRect)contentRect
|
2009-07-17 14:47:41 +00:00
|
|
|
styleMask: (unsigned int) styleMask
|
|
|
|
backing: (NSBackingStoreType) bufferingType
|
|
|
|
defer: (BOOL) flag screen: (NSScreen *) aScreen
|
2012-11-16 06:13:03 +00:00
|
|
|
gstWin: (GstGLWindowCocoa *) window;
|
2009-07-24 08:12:07 +00:00
|
|
|
- (void) setClosed;
|
2009-07-17 14:47:41 +00:00
|
|
|
- (BOOL) isClosed;
|
2009-07-24 08:12:07 +00:00
|
|
|
- (BOOL) canBecomeMainWindow;
|
|
|
|
- (BOOL) canBecomeKeyWindow;
|
2009-02-26 00:06:58 +00:00
|
|
|
@end
|
|
|
|
|
2009-07-17 14:47:41 +00:00
|
|
|
/* =============================================================*/
|
|
|
|
/* */
|
|
|
|
/* GstGLWindow */
|
|
|
|
/* */
|
|
|
|
/* =============================================================*/
|
2009-02-26 00:06:58 +00:00
|
|
|
|
2012-11-16 06:13:03 +00:00
|
|
|
#define GST_GL_WINDOW_COCOA_GET_PRIVATE(o) \
|
|
|
|
(G_TYPE_INSTANCE_GET_PRIVATE((o), GST_GL_TYPE_WINDOW_COCOA, GstGLWindowCocoaPrivate))
|
|
|
|
|
|
|
|
#define GST_CAT_DEFAULT gst_gl_window_cocoa_debug
|
|
|
|
GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
|
|
|
|
|
|
|
|
#define DEBUG_INIT \
|
|
|
|
GST_DEBUG_CATEGORY_GET (GST_CAT_DEFAULT, "glwindow");
|
|
|
|
#define gst_gl_window_cocoa_parent_class parent_class
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GstGLWindowCocoa, gst_gl_window_cocoa, GST_GL_TYPE_WINDOW, DEBUG_INIT);
|
|
|
|
|
2014-09-25 13:13:19 +00:00
|
|
|
static gboolean gst_gl_window_cocoa_open (GstGLWindow *window, GError **err);
|
|
|
|
static void gst_gl_window_cocoa_close (GstGLWindow *window);
|
2013-08-15 07:09:04 +00:00
|
|
|
static guintptr gst_gl_window_cocoa_get_window_handle (GstGLWindow * window);
|
|
|
|
static void gst_gl_window_cocoa_set_window_handle (GstGLWindow * window,
|
2012-11-16 06:13:03 +00:00
|
|
|
guintptr handle);
|
2013-08-15 07:09:04 +00:00
|
|
|
static void gst_gl_window_cocoa_draw (GstGLWindow * window, guint width, guint height);
|
|
|
|
static void gst_gl_window_cocoa_run (GstGLWindow * window);
|
|
|
|
static void gst_gl_window_cocoa_quit (GstGLWindow * window);
|
2013-09-25 02:26:57 +00:00
|
|
|
static void gst_gl_window_cocoa_send_message_async (GstGLWindow * window,
|
|
|
|
GstGLWindowCB callback, gpointer data, GDestroyNotify destroy);
|
2012-11-16 06:13:03 +00:00
|
|
|
|
|
|
|
struct _GstGLWindowCocoaPrivate
|
2009-02-26 00:06:58 +00:00
|
|
|
{
|
|
|
|
GstGLNSWindow *internal_win_id;
|
2014-04-24 09:37:00 +00:00
|
|
|
NSView *external_view;
|
2009-02-26 00:06:58 +00:00
|
|
|
gboolean visible;
|
2014-09-25 13:13:19 +00:00
|
|
|
GMainContext *main_context;
|
|
|
|
GMainLoop *loop;
|
2014-09-29 06:33:42 +00:00
|
|
|
|
|
|
|
GLint viewport_dim[4];
|
2009-02-26 00:06:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static void
|
2012-11-16 06:13:03 +00:00
|
|
|
gst_gl_window_cocoa_class_init (GstGLWindowCocoaClass * klass)
|
2009-02-26 00:06:58 +00:00
|
|
|
{
|
2012-11-16 06:13:03 +00:00
|
|
|
GstGLWindowClass *window_class;
|
2009-02-26 00:06:58 +00:00
|
|
|
|
2012-11-16 06:13:03 +00:00
|
|
|
window_class = (GstGLWindowClass *) klass;
|
|
|
|
|
|
|
|
g_type_class_add_private (klass, sizeof (GstGLWindowCocoaPrivate));
|
|
|
|
|
2014-09-25 13:13:19 +00:00
|
|
|
window_class->open = GST_DEBUG_FUNCPTR (gst_gl_window_cocoa_open);
|
|
|
|
window_class->close = GST_DEBUG_FUNCPTR (gst_gl_window_cocoa_close);
|
2013-08-15 07:09:04 +00:00
|
|
|
window_class->get_window_handle =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_gl_window_cocoa_get_window_handle);
|
2012-11-16 06:13:03 +00:00
|
|
|
window_class->set_window_handle =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_gl_window_cocoa_set_window_handle);
|
|
|
|
window_class->draw_unlocked = GST_DEBUG_FUNCPTR (gst_gl_window_cocoa_draw);
|
|
|
|
window_class->draw = GST_DEBUG_FUNCPTR (gst_gl_window_cocoa_draw);
|
|
|
|
window_class->run = GST_DEBUG_FUNCPTR (gst_gl_window_cocoa_run);
|
|
|
|
window_class->quit = GST_DEBUG_FUNCPTR (gst_gl_window_cocoa_quit);
|
2013-09-25 02:26:57 +00:00
|
|
|
window_class->send_message_async =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_gl_window_cocoa_send_message_async);
|
2009-02-26 00:06:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-11-16 06:13:03 +00:00
|
|
|
gst_gl_window_cocoa_init (GstGLWindowCocoa * window)
|
2009-02-26 00:06:58 +00:00
|
|
|
{
|
2012-11-16 06:13:03 +00:00
|
|
|
window->priv = GST_GL_WINDOW_COCOA_GET_PRIVATE (window);
|
2009-02-26 00:06:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Must be called in the gl thread */
|
2012-11-16 06:13:03 +00:00
|
|
|
GstGLWindowCocoa *
|
2013-02-12 12:48:36 +00:00
|
|
|
gst_gl_window_cocoa_new (void)
|
2009-02-26 00:06:58 +00:00
|
|
|
{
|
2012-11-16 06:13:03 +00:00
|
|
|
GstGLWindowCocoa *window = g_object_new (GST_GL_TYPE_WINDOW_COCOA, NULL);
|
2013-02-12 12:48:36 +00:00
|
|
|
|
|
|
|
return window;
|
|
|
|
}
|
|
|
|
|
2014-09-26 11:21:46 +00:00
|
|
|
/* Must be called from the main thread */
|
2013-02-12 12:48:36 +00:00
|
|
|
gboolean
|
2014-09-26 10:05:27 +00:00
|
|
|
gst_gl_window_cocoa_create_window (GstGLWindowCocoa *window_cocoa, NSRect rect)
|
2013-02-12 12:48:36 +00:00
|
|
|
{
|
|
|
|
GstGLWindowCocoaPrivate *priv = window_cocoa->priv;
|
2009-02-26 00:06:58 +00:00
|
|
|
|
2014-09-26 10:05:27 +00:00
|
|
|
priv->internal_win_id = [[GstGLNSWindow alloc] initWithContentRect:rect styleMask:
|
2014-09-26 11:21:46 +00:00
|
|
|
(NSTitledWindowMask | NSClosableWindowMask |
|
|
|
|
NSResizableWindowMask | NSMiniaturizableWindowMask)
|
|
|
|
backing: NSBackingStoreBuffered defer: NO screen: nil gstWin: window_cocoa];
|
2009-02-26 00:06:58 +00:00
|
|
|
|
2014-09-26 11:21:46 +00:00
|
|
|
GST_DEBUG ("NSWindow id: %"G_GUINTPTR_FORMAT, (guintptr) priv->internal_win_id);
|
2013-08-15 07:09:04 +00:00
|
|
|
|
2014-10-18 04:26:52 +00:00
|
|
|
[[NSApplication sharedApplication] setDelegate: priv->internal_win_id];
|
2009-03-07 02:13:38 +00:00
|
|
|
|
2013-02-12 12:48:36 +00:00
|
|
|
return TRUE;
|
2009-02-26 00:06:58 +00:00
|
|
|
}
|
|
|
|
|
2014-09-25 13:13:19 +00:00
|
|
|
static gboolean
|
|
|
|
gst_gl_window_cocoa_open (GstGLWindow *window, GError **err)
|
|
|
|
{
|
|
|
|
GstGLWindowCocoa *window_cocoa;
|
|
|
|
|
|
|
|
window_cocoa = GST_GL_WINDOW_COCOA (window);
|
|
|
|
|
|
|
|
window_cocoa->priv->main_context = g_main_context_new ();
|
|
|
|
window_cocoa->priv->loop =
|
|
|
|
g_main_loop_new (window_cocoa->priv->main_context, FALSE);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gst_gl_window_cocoa_close (GstGLWindow *window)
|
|
|
|
{
|
|
|
|
GstGLWindowCocoa *window_cocoa;
|
|
|
|
|
|
|
|
window_cocoa = GST_GL_WINDOW_COCOA (window);
|
|
|
|
|
|
|
|
g_main_loop_unref (window_cocoa->priv->loop);
|
|
|
|
g_main_context_unref (window_cocoa->priv->main_context);
|
|
|
|
|
|
|
|
[window_cocoa->priv->internal_win_id release];
|
|
|
|
window_cocoa->priv->internal_win_id = nil;
|
|
|
|
}
|
|
|
|
|
2013-08-15 07:09:04 +00:00
|
|
|
static guintptr
|
|
|
|
gst_gl_window_cocoa_get_window_handle (GstGLWindow *window)
|
2009-10-26 10:44:35 +00:00
|
|
|
{
|
2013-08-15 07:09:04 +00:00
|
|
|
return (guintptr) GST_GL_WINDOW_COCOA (window)->priv->internal_win_id;
|
2009-10-26 10:44:35 +00:00
|
|
|
}
|
|
|
|
|
2013-08-15 07:09:04 +00:00
|
|
|
static void
|
2012-11-16 06:13:03 +00:00
|
|
|
gst_gl_window_cocoa_set_window_handle (GstGLWindow * window, guintptr handle)
|
2009-02-26 00:06:58 +00:00
|
|
|
{
|
2012-11-16 06:13:03 +00:00
|
|
|
GstGLWindowCocoa *window_cocoa;
|
|
|
|
GstGLWindowCocoaPrivate *priv;
|
|
|
|
|
|
|
|
window_cocoa = GST_GL_WINDOW_COCOA (window);
|
|
|
|
priv = window_cocoa->priv;
|
2014-09-25 13:13:19 +00:00
|
|
|
|
2013-07-11 19:22:57 +00:00
|
|
|
if (priv->internal_win_id) {
|
2013-11-30 16:38:13 +00:00
|
|
|
if (handle) {
|
2014-04-24 09:37:00 +00:00
|
|
|
priv->external_view = (NSView *) handle;
|
2013-11-30 16:38:13 +00:00
|
|
|
priv->visible = TRUE;
|
|
|
|
} else {
|
|
|
|
/* bring back our internal window */
|
2014-04-24 09:37:00 +00:00
|
|
|
priv->external_view = 0;
|
2013-11-30 16:38:13 +00:00
|
|
|
priv->visible = FALSE;
|
|
|
|
}
|
2013-09-25 02:26:57 +00:00
|
|
|
|
2014-09-25 13:13:19 +00:00
|
|
|
|
2014-09-26 11:21:46 +00:00
|
|
|
dispatch_async (dispatch_get_main_queue (), ^{
|
|
|
|
NSView *view = [window_cocoa->priv->internal_win_id contentView];
|
|
|
|
[window_cocoa->priv->internal_win_id orderOut:window_cocoa->priv->internal_win_id];
|
|
|
|
|
|
|
|
[window_cocoa->priv->external_view addSubview: view];
|
|
|
|
|
|
|
|
[view setFrame: [window_cocoa->priv->external_view bounds]];
|
|
|
|
[view setAutoresizingMask: NSViewWidthSizable|NSViewHeightSizable];
|
|
|
|
});
|
2013-11-30 16:38:13 +00:00
|
|
|
} else {
|
2014-09-25 13:13:19 +00:00
|
|
|
/* no internal window yet so delay it to the next drawing */
|
2014-04-24 09:37:00 +00:00
|
|
|
priv->external_view = (NSView*) handle;
|
2013-11-30 16:38:13 +00:00
|
|
|
priv->visible = FALSE;
|
2009-02-26 00:06:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Thread safe */
|
2014-09-25 13:13:19 +00:00
|
|
|
struct draw
|
2009-02-26 00:06:58 +00:00
|
|
|
{
|
2014-09-25 13:13:19 +00:00
|
|
|
GstGLWindowCocoa *window;
|
|
|
|
guint width, height;
|
|
|
|
};
|
2009-02-26 00:06:58 +00:00
|
|
|
|
2014-09-25 13:13:19 +00:00
|
|
|
static void
|
|
|
|
draw_cb (gpointer data)
|
|
|
|
{
|
|
|
|
struct draw *draw_data = data;
|
|
|
|
GstGLWindowCocoa *window_cocoa = draw_data->window;
|
|
|
|
GstGLWindowCocoaPrivate *priv = window_cocoa->priv;
|
2009-10-26 10:44:35 +00:00
|
|
|
|
2013-11-30 16:38:13 +00:00
|
|
|
/* useful when set_window_handle is called before
|
|
|
|
* the internal NSWindow */
|
2014-04-24 09:37:00 +00:00
|
|
|
if (priv->external_view && !priv->visible) {
|
2014-09-25 13:13:19 +00:00
|
|
|
gst_gl_window_cocoa_set_window_handle (GST_GL_WINDOW (window_cocoa), (guintptr) priv->external_view);
|
2013-11-30 16:38:13 +00:00
|
|
|
priv->visible = TRUE;
|
|
|
|
}
|
|
|
|
|
2014-04-24 09:37:00 +00:00
|
|
|
if (!priv->external_view && !priv->visible) {
|
2014-09-26 11:21:46 +00:00
|
|
|
dispatch_sync (dispatch_get_main_queue (), ^{
|
|
|
|
NSRect mainRect = [[NSScreen mainScreen] visibleFrame];
|
|
|
|
NSRect windowRect = [priv->internal_win_id frame];
|
|
|
|
gint x = 0;
|
|
|
|
gint y = 0;
|
2013-09-25 02:26:57 +00:00
|
|
|
|
2014-09-26 11:21:46 +00:00
|
|
|
GST_DEBUG ("main screen rect: %d %d %d %d\n", (int) mainRect.origin.x,
|
|
|
|
(int) mainRect.origin.y, (int) mainRect.size.width,
|
|
|
|
(int) mainRect.size.height);
|
2014-09-25 13:13:19 +00:00
|
|
|
|
2014-09-26 11:21:46 +00:00
|
|
|
windowRect.origin.x += x;
|
|
|
|
windowRect.origin.y += mainRect.size.height > y ? (mainRect.size.height - y) * 0.5 : y;
|
|
|
|
windowRect.size.width = draw_data->width;
|
|
|
|
windowRect.size.height = draw_data->height;
|
2009-10-26 10:44:35 +00:00
|
|
|
|
2014-09-26 11:21:46 +00:00
|
|
|
GST_DEBUG ("window rect: %d %d %d %d\n", (int) windowRect.origin.x,
|
|
|
|
(int) windowRect.origin.y, (int) windowRect.size.width,
|
|
|
|
(int) windowRect.size.height);
|
2009-10-26 10:44:35 +00:00
|
|
|
|
2014-09-26 11:21:46 +00:00
|
|
|
x += 20;
|
|
|
|
y += 20;
|
2009-10-26 10:44:35 +00:00
|
|
|
|
2010-01-05 23:13:46 +00:00
|
|
|
#ifndef GNUSTEP
|
2014-09-26 11:21:46 +00:00
|
|
|
[priv->internal_win_id setFrame:windowRect display:NO];
|
|
|
|
GST_DEBUG ("make the window available\n");
|
|
|
|
[priv->internal_win_id makeMainWindow];
|
2010-01-05 23:13:46 +00:00
|
|
|
#endif
|
2014-09-25 13:13:19 +00:00
|
|
|
|
2014-09-26 11:21:46 +00:00
|
|
|
[priv->internal_win_id orderFrontRegardless];
|
2012-11-16 06:13:03 +00:00
|
|
|
|
2014-09-26 11:21:46 +00:00
|
|
|
[priv->internal_win_id setViewsNeedDisplay:YES];
|
|
|
|
});
|
2013-09-25 02:26:57 +00:00
|
|
|
priv->visible = TRUE;
|
2009-02-26 00:06:58 +00:00
|
|
|
}
|
2013-09-25 02:26:57 +00:00
|
|
|
|
2014-09-25 13:13:19 +00:00
|
|
|
if (g_main_loop_is_running (priv->loop)) {
|
|
|
|
if (![priv->internal_win_id isClosed]) {
|
2014-09-26 10:05:27 +00:00
|
|
|
GstGLContext *context = gst_gl_window_get_context (GST_GL_WINDOW (window_cocoa));
|
|
|
|
NSOpenGLContext * glContext = (NSOpenGLContext *) gst_gl_context_get_gl_context (context);
|
|
|
|
|
2014-09-25 13:13:19 +00:00
|
|
|
/* draw opengl scene in the back buffer */
|
|
|
|
GST_GL_WINDOW (window_cocoa)->draw (GST_GL_WINDOW (window_cocoa)->draw_data);
|
2014-04-24 08:03:32 +00:00
|
|
|
|
2014-09-25 13:13:19 +00:00
|
|
|
/* Copy the back buffer to the front buffer */
|
2014-09-26 10:05:27 +00:00
|
|
|
[glContext flushBuffer];
|
|
|
|
|
|
|
|
gst_object_unref (context);
|
2014-09-25 13:13:19 +00:00
|
|
|
}
|
|
|
|
}
|
2009-02-26 00:06:58 +00:00
|
|
|
}
|
|
|
|
|
2013-08-15 07:09:04 +00:00
|
|
|
static void
|
2014-09-25 13:13:19 +00:00
|
|
|
gst_gl_window_cocoa_draw (GstGLWindow * window, guint width, guint height)
|
2009-02-26 00:06:58 +00:00
|
|
|
{
|
2014-09-25 13:13:19 +00:00
|
|
|
struct draw draw_data;
|
2013-09-25 02:26:57 +00:00
|
|
|
|
2014-09-25 13:13:19 +00:00
|
|
|
draw_data.window = GST_GL_WINDOW_COCOA (window);
|
|
|
|
draw_data.width = width;
|
|
|
|
draw_data.height = height;
|
2013-09-25 02:26:57 +00:00
|
|
|
|
2014-09-25 13:13:19 +00:00
|
|
|
gst_gl_window_send_message (window, (GstGLWindowCB) draw_cb, &draw_data);
|
|
|
|
}
|
2012-11-16 06:13:03 +00:00
|
|
|
|
2014-09-25 13:13:19 +00:00
|
|
|
static void
|
|
|
|
gst_gl_window_cocoa_run (GstGLWindow * window)
|
|
|
|
{
|
|
|
|
GstGLWindowCocoa *window_cocoa;
|
2009-02-26 00:06:58 +00:00
|
|
|
|
2014-09-25 13:13:19 +00:00
|
|
|
window_cocoa = GST_GL_WINDOW_COCOA (window);
|
2009-02-26 00:06:58 +00:00
|
|
|
|
2014-09-25 13:13:19 +00:00
|
|
|
GST_LOG ("starting main loop");
|
|
|
|
g_main_loop_run (window_cocoa->priv->loop);
|
|
|
|
GST_LOG ("exiting main loop");
|
2009-02-26 00:06:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Thread safe */
|
2013-08-15 07:09:04 +00:00
|
|
|
static void
|
2013-07-15 13:58:04 +00:00
|
|
|
gst_gl_window_cocoa_quit (GstGLWindow * window)
|
2009-02-26 00:06:58 +00:00
|
|
|
{
|
2012-11-16 06:13:03 +00:00
|
|
|
GstGLWindowCocoa *window_cocoa;
|
|
|
|
|
|
|
|
window_cocoa = GST_GL_WINDOW_COCOA (window);
|
|
|
|
|
2014-09-25 13:13:19 +00:00
|
|
|
g_main_loop_quit (window_cocoa->priv->loop);
|
|
|
|
}
|
2009-02-26 00:06:58 +00:00
|
|
|
|
2014-09-25 13:13:19 +00:00
|
|
|
/* Thread safe */
|
|
|
|
typedef struct _GstGLMessage
|
|
|
|
{
|
|
|
|
GstGLWindowCB callback;
|
|
|
|
gpointer data;
|
|
|
|
GDestroyNotify destroy;
|
|
|
|
} GstGLMessage;
|
2009-02-26 00:06:58 +00:00
|
|
|
|
2014-09-25 13:13:19 +00:00
|
|
|
static gboolean
|
|
|
|
_run_message (GstGLMessage * message)
|
|
|
|
{
|
|
|
|
if (message->callback)
|
|
|
|
message->callback (message->data);
|
|
|
|
|
|
|
|
if (message->destroy)
|
|
|
|
message->destroy (message->data);
|
|
|
|
|
|
|
|
g_slice_free (GstGLMessage, message);
|
|
|
|
|
|
|
|
return FALSE;
|
2009-02-26 00:06:58 +00:00
|
|
|
}
|
|
|
|
|
2013-08-15 07:09:04 +00:00
|
|
|
static void
|
2013-09-25 02:26:57 +00:00
|
|
|
gst_gl_window_cocoa_send_message_async (GstGLWindow * window,
|
|
|
|
GstGLWindowCB callback, gpointer data, GDestroyNotify destroy)
|
2009-02-26 00:06:58 +00:00
|
|
|
{
|
2012-11-16 06:13:03 +00:00
|
|
|
GstGLWindowCocoa *window_cocoa;
|
2014-09-25 13:13:19 +00:00
|
|
|
GstGLMessage *message;
|
2012-11-16 06:13:03 +00:00
|
|
|
|
|
|
|
window_cocoa = GST_GL_WINDOW_COCOA (window);
|
2014-09-25 13:13:19 +00:00
|
|
|
message = g_slice_new (GstGLMessage);
|
2012-11-16 06:13:03 +00:00
|
|
|
|
2014-09-25 13:13:19 +00:00
|
|
|
message->callback = callback;
|
|
|
|
message->data = data;
|
|
|
|
message->destroy = destroy;
|
2013-09-25 02:26:57 +00:00
|
|
|
|
2014-09-25 13:13:19 +00:00
|
|
|
g_main_context_invoke (window_cocoa->priv->main_context,
|
|
|
|
(GSourceFunc) _run_message, message);
|
2009-02-26 00:06:58 +00:00
|
|
|
}
|
|
|
|
|
2009-07-17 14:47:41 +00:00
|
|
|
/* =============================================================*/
|
|
|
|
/* */
|
|
|
|
/* GstGLNSWindow implementation */
|
|
|
|
/* */
|
|
|
|
/* =============================================================*/
|
2009-02-26 00:06:58 +00:00
|
|
|
|
2014-09-26 11:21:46 +00:00
|
|
|
/* Must be called from the main thread */
|
2009-02-26 00:06:58 +00:00
|
|
|
@implementation GstGLNSWindow
|
|
|
|
|
|
|
|
- (id) initWithContentRect: (NSRect) contentRect
|
2009-07-17 14:47:41 +00:00
|
|
|
styleMask: (unsigned int) styleMask
|
2009-02-26 00:06:58 +00:00
|
|
|
backing: (NSBackingStoreType) bufferingType
|
|
|
|
defer: (BOOL) flag screen: (NSScreen *) aScreen
|
2012-11-16 06:13:03 +00:00
|
|
|
gstWin: (GstGLWindowCocoa *) cocoa {
|
2009-02-26 00:06:58 +00:00
|
|
|
|
2009-04-13 05:24:06 +00:00
|
|
|
m_isClosed = NO;
|
2014-09-26 10:05:27 +00:00
|
|
|
window_cocoa = cocoa;
|
2009-04-13 05:24:06 +00:00
|
|
|
|
2009-02-26 00:06:58 +00:00
|
|
|
self = [super initWithContentRect: contentRect
|
2009-07-17 14:47:41 +00:00
|
|
|
styleMask: styleMask backing: bufferingType
|
|
|
|
defer: flag screen:aScreen];
|
2009-02-26 00:06:58 +00:00
|
|
|
|
|
|
|
[self setReleasedWhenClosed:NO];
|
|
|
|
|
2012-11-16 06:13:03 +00:00
|
|
|
GST_DEBUG ("initializing GstGLNSWindow\n");
|
2009-02-26 00:06:58 +00:00
|
|
|
|
|
|
|
[self setTitle:@"OpenGL renderer"];
|
2013-09-25 02:26:57 +00:00
|
|
|
|
2009-07-17 14:47:41 +00:00
|
|
|
[self setBackgroundColor:[NSColor clearColor]];
|
2013-09-25 02:26:57 +00:00
|
|
|
|
2014-09-26 10:05:27 +00:00
|
|
|
[self orderOut:window_cocoa->priv->internal_win_id];
|
2009-02-26 00:06:58 +00:00
|
|
|
|
2014-09-26 10:05:27 +00:00
|
|
|
if (window_cocoa->priv->external_view) {
|
2014-04-24 09:37:00 +00:00
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
2014-09-26 10:05:27 +00:00
|
|
|
NSView *view = [window_cocoa->priv->internal_win_id contentView];
|
2014-04-24 09:37:00 +00:00
|
|
|
|
2014-09-26 10:05:27 +00:00
|
|
|
[window_cocoa->priv->external_view addSubview: view];
|
|
|
|
[view setFrame: [window_cocoa->priv->external_view bounds]];
|
2014-04-24 09:37:00 +00:00
|
|
|
[view setAutoresizingMask: NSViewWidthSizable|NSViewHeightSizable];
|
|
|
|
|
|
|
|
[pool release];
|
2013-07-11 19:22:57 +00:00
|
|
|
}
|
|
|
|
|
2009-02-26 00:06:58 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2009-07-24 08:12:07 +00:00
|
|
|
- (void) setClosed {
|
|
|
|
m_isClosed = YES;
|
|
|
|
}
|
|
|
|
|
2009-02-26 00:06:58 +00:00
|
|
|
- (BOOL) isClosed {
|
|
|
|
return m_isClosed;
|
|
|
|
}
|
|
|
|
|
2009-07-24 08:12:07 +00:00
|
|
|
- (BOOL) canBecomeMainWindow {
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) canBecomeKeyWindow {
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2014-09-25 13:13:19 +00:00
|
|
|
static void
|
|
|
|
close_window_cb (gpointer data)
|
|
|
|
{
|
|
|
|
GstGLWindowCocoa *window_cocoa = data;
|
|
|
|
GstGLWindow *window;
|
|
|
|
|
|
|
|
window = GST_GL_WINDOW (window_cocoa);
|
|
|
|
|
|
|
|
if (window->close) {
|
|
|
|
window->close (window->close_data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-24 08:12:07 +00:00
|
|
|
/* Called in the main thread which is never the gl thread */
|
2009-02-26 00:06:58 +00:00
|
|
|
- (BOOL) windowShouldClose:(id)sender {
|
2014-09-25 13:13:19 +00:00
|
|
|
|
2012-11-16 06:13:03 +00:00
|
|
|
GST_DEBUG ("user clicked the close button\n");
|
2014-09-26 11:21:46 +00:00
|
|
|
[window_cocoa->priv->internal_win_id setClosed];
|
|
|
|
gst_gl_window_send_message_async (GST_GL_WINDOW (window_cocoa), (GstGLWindowCB) close_window_cb, gst_object_ref (window_cocoa), (GDestroyNotify) gst_object_unref);
|
2009-02-26 00:06:58 +00:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) applicationDidFinishLaunching: (NSNotification *) not {
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) applicationWillFinishLaunching: (NSNotification *) not {
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)app {
|
|
|
|
/* the application is manually stopped by calling stopApp on the AppThreadPerformer */
|
|
|
|
return NO;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) applicationWillTerminate:(NSNotification *)aNotification {
|
2012-11-17 14:16:44 +00:00
|
|
|
#ifdef GNUSTEP
|
|
|
|
/* fixes segfault with gst-launch-1.0 -e ... and sending SIGINT (Ctrl-C)
|
|
|
|
* which causes GNUstep to run a signal handler in the main thread.
|
|
|
|
* However that thread has never been 'registered' with GNUstep so
|
|
|
|
* the autorelease magic of objective-c causes a segfault from accessing
|
|
|
|
* a null NSThread object somewhere deep in GNUstep.
|
|
|
|
*
|
|
|
|
* I put it here because this is the first time we can register the thread.
|
|
|
|
*/
|
|
|
|
GSRegisterCurrentThread();
|
|
|
|
#endif
|
2009-02-26 00:06:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
2009-07-17 14:47:41 +00:00
|
|
|
/* =============================================================*/
|
|
|
|
/* */
|
2014-09-26 10:05:27 +00:00
|
|
|
/* GstGLNSView implementation */
|
2009-07-17 14:47:41 +00:00
|
|
|
/* */
|
|
|
|
/* =============================================================*/
|
|
|
|
|
2014-09-26 10:05:27 +00:00
|
|
|
@implementation GstGLNSView
|
2009-07-17 14:47:41 +00:00
|
|
|
|
2014-09-26 11:21:46 +00:00
|
|
|
/* Must be called from the application main thread */
|
2014-09-26 10:05:27 +00:00
|
|
|
- (id)initWithFrame:(GstGLWindowCocoa *)window rect:(NSRect)contentRect {
|
2013-08-15 07:09:04 +00:00
|
|
|
|
2014-09-26 10:05:27 +00:00
|
|
|
self = [super initWithFrame: contentRect];
|
2013-08-15 07:09:04 +00:00
|
|
|
|
2014-09-26 10:05:27 +00:00
|
|
|
window_cocoa = window;
|
2013-08-15 07:09:04 +00:00
|
|
|
|
2010-01-05 23:13:46 +00:00
|
|
|
#ifndef GNUSTEP
|
2009-08-03 08:13:02 +00:00
|
|
|
[self setWantsLayer:NO];
|
2010-01-05 23:13:46 +00:00
|
|
|
#endif
|
2013-08-15 07:09:04 +00:00
|
|
|
|
2014-09-26 10:05:27 +00:00
|
|
|
/* Get notified about changes */
|
2014-11-03 23:07:34 +00:00
|
|
|
[self setPostsFrameChangedNotifications:YES];
|
2014-11-03 23:02:17 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] addObserver: self selector:@selector(reshape:) name: NSViewFrameDidChangeNotification object: self];
|
2014-10-09 07:54:35 +00:00
|
|
|
[self setWantsBestResolutionOpenGLSurface:YES];
|
2014-09-26 10:05:27 +00:00
|
|
|
|
2013-08-15 07:09:04 +00:00
|
|
|
return self;
|
2009-07-17 14:47:41 +00:00
|
|
|
}
|
|
|
|
|
2014-09-26 10:05:27 +00:00
|
|
|
- (void) dealloc {
|
|
|
|
[[NSNotificationCenter defaultCenter] removeObserver: self];
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2014-09-25 13:13:19 +00:00
|
|
|
struct resize
|
|
|
|
{
|
|
|
|
GstGLWindowCocoa * window;
|
2014-09-26 10:05:27 +00:00
|
|
|
NSRect bounds, visibleRect;
|
2014-09-25 13:13:19 +00:00
|
|
|
};
|
2009-02-26 00:06:58 +00:00
|
|
|
|
2014-09-25 13:13:19 +00:00
|
|
|
static void
|
|
|
|
resize_cb (gpointer data)
|
|
|
|
{
|
|
|
|
struct resize *resize_data = data;
|
|
|
|
GstGLWindowCocoa *window_cocoa = resize_data->window;
|
|
|
|
GstGLWindow *window = GST_GL_WINDOW (window_cocoa);
|
2014-09-26 10:05:27 +00:00
|
|
|
GstGLContext *context = gst_gl_window_get_context (window);
|
|
|
|
NSOpenGLContext * glContext = (NSOpenGLContext *) gst_gl_context_get_gl_context (context);
|
2009-02-26 00:06:58 +00:00
|
|
|
|
2014-09-25 13:13:19 +00:00
|
|
|
if (g_main_loop_is_running (window_cocoa->priv->loop) && ![window_cocoa->priv->internal_win_id isClosed]) {
|
2014-09-29 06:33:42 +00:00
|
|
|
const GstGLFuncs *gl;
|
2009-02-26 00:06:58 +00:00
|
|
|
|
2014-09-26 10:05:27 +00:00
|
|
|
[glContext update];
|
2014-09-29 06:33:42 +00:00
|
|
|
|
2014-10-01 13:04:36 +00:00
|
|
|
gl = context->gl_vtable;
|
2014-09-29 06:33:42 +00:00
|
|
|
|
2014-10-01 13:04:36 +00:00
|
|
|
if (window->resize) {
|
|
|
|
window->resize (window->resize_data, resize_data->bounds.size.width, resize_data->bounds.size.height);
|
|
|
|
gl->GetIntegerv (GL_VIEWPORT, window_cocoa->priv->viewport_dim);
|
2014-09-29 06:33:42 +00:00
|
|
|
}
|
|
|
|
|
2014-10-01 13:04:36 +00:00
|
|
|
gl->Viewport (window_cocoa->priv->viewport_dim[0] - resize_data->visibleRect.origin.x,
|
|
|
|
window_cocoa->priv->viewport_dim[1] - resize_data->visibleRect.origin.y,
|
|
|
|
window_cocoa->priv->viewport_dim[2], window_cocoa->priv->viewport_dim[3]);
|
|
|
|
|
2014-09-26 10:05:27 +00:00
|
|
|
GST_GL_WINDOW (window_cocoa)->draw (GST_GL_WINDOW (window_cocoa)->draw_data);
|
|
|
|
[glContext flushBuffer];
|
2009-07-24 08:12:07 +00:00
|
|
|
}
|
2014-09-26 10:05:27 +00:00
|
|
|
gst_object_unref (context);
|
2009-02-26 00:06:58 +00:00
|
|
|
}
|
|
|
|
|
2014-10-01 08:55:13 +00:00
|
|
|
- (void)renewGState {
|
|
|
|
/* Don't update the screen until we redraw, this
|
|
|
|
* prevents flickering during scrolling, clipping,
|
|
|
|
* resizing, etc
|
|
|
|
*/
|
|
|
|
[[self window] disableScreenUpdatesUntilFlush];
|
|
|
|
|
|
|
|
[super renewGState];
|
|
|
|
}
|
|
|
|
|
2014-10-21 14:21:08 +00:00
|
|
|
- (void)reshape: (NSNotification*)notification {
|
2012-11-16 06:13:03 +00:00
|
|
|
GstGLWindow *window;
|
|
|
|
|
2014-09-26 10:05:27 +00:00
|
|
|
window = GST_GL_WINDOW (window_cocoa);
|
2012-11-16 06:13:03 +00:00
|
|
|
|
2014-09-25 13:13:19 +00:00
|
|
|
if (window->resize) {
|
|
|
|
NSRect bounds = [self bounds];
|
2014-09-26 10:05:27 +00:00
|
|
|
NSRect visibleRect = [self visibleRect];
|
2014-09-26 11:21:46 +00:00
|
|
|
struct resize *resize_data = g_new (struct resize, 1);
|
2014-09-25 13:13:19 +00:00
|
|
|
|
2014-10-09 07:54:35 +00:00
|
|
|
bounds = [self convertRectToBacking:bounds];
|
|
|
|
visibleRect = [self convertRectToBacking:visibleRect];
|
|
|
|
|
2014-09-29 06:33:42 +00:00
|
|
|
GST_DEBUG_OBJECT (window, "Window resized: bounds %lf %lf %lf %lf "
|
|
|
|
"visibleRect %lf %lf %lf %lf",
|
2014-09-26 10:05:27 +00:00
|
|
|
bounds.origin.x, bounds.origin.y,
|
|
|
|
bounds.size.width, bounds.size.height,
|
|
|
|
visibleRect.origin.x, visibleRect.origin.y,
|
2014-09-29 06:33:42 +00:00
|
|
|
visibleRect.size.width, visibleRect.size.height);
|
2014-09-26 10:05:27 +00:00
|
|
|
|
2014-09-26 11:21:46 +00:00
|
|
|
resize_data->window = window_cocoa;
|
|
|
|
resize_data->bounds = bounds;
|
|
|
|
resize_data->visibleRect = visibleRect;
|
2014-09-25 13:13:19 +00:00
|
|
|
|
2014-09-26 11:21:46 +00:00
|
|
|
gst_gl_window_send_message_async (GST_GL_WINDOW (window_cocoa), (GstGLWindowCB) resize_cb, resize_data, (GDestroyNotify) g_free);
|
2009-07-24 08:12:07 +00:00
|
|
|
}
|
2012-11-16 06:13:03 +00:00
|
|
|
}
|
|
|
|
|
2014-11-03 22:59:41 +00:00
|
|
|
- (void)drawRect: (NSRect)dirtyRect {
|
|
|
|
[self reshape:nil];
|
|
|
|
}
|
|
|
|
|
2014-09-26 10:05:27 +00:00
|
|
|
- (BOOL) isOpaque {
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL) isFlipped {
|
2014-09-29 06:33:42 +00:00
|
|
|
return NO;
|
2009-07-17 14:47:41 +00:00
|
|
|
}
|
|
|
|
|
2009-02-26 00:06:58 +00:00
|
|
|
@end
|
2014-09-25 13:13:19 +00:00
|
|
|
|