2009-02-26 00:06:58 +00:00
|
|
|
/*
|
|
|
|
* GStreamer
|
|
|
|
* Copyright (C) 2008 Julien Isorce <julien.isorce@gmail.com>
|
|
|
|
*
|
|
|
|
* 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-07-10 14:47:23 +00:00
|
|
|
#include "gstglwindow_cocoa.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
|
|
|
|
|
|
|
@interface GstGLNSWindow: NSWindow {
|
|
|
|
BOOL m_isClosed;
|
2012-11-16 06:13:03 +00:00
|
|
|
GstGLWindowCocoa *m_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
|
|
|
/* =============================================================*/
|
|
|
|
/* */
|
|
|
|
/* GstGLNSOpenGLView declaration */
|
|
|
|
/* */
|
|
|
|
/* =============================================================*/
|
|
|
|
|
|
|
|
@interface GstGLNSOpenGLView: NSOpenGLView {
|
2012-11-16 06:13:03 +00:00
|
|
|
GstGLWindowCocoa *m_cocoa;
|
2009-08-03 08:13:02 +00:00
|
|
|
gint m_resizeCount;
|
2009-07-17 14:47:41 +00:00
|
|
|
}
|
2012-11-16 06:13:03 +00:00
|
|
|
- (id) initWithFrame:(GstGLWindowCocoa *)window rect:(NSRect)contentRect
|
|
|
|
pixelFormat:(NSOpenGLPixelFormat *)fmt;
|
2009-07-17 14:47:41 +00:00
|
|
|
@end
|
2009-02-26 00:06:58 +00:00
|
|
|
|
2009-07-17 14:47:41 +00:00
|
|
|
|
|
|
|
/* =============================================================*/
|
|
|
|
/* */
|
|
|
|
/* AppThreadPerformer declaration */
|
|
|
|
/* */
|
|
|
|
/* =============================================================*/
|
2009-02-26 00:06:58 +00:00
|
|
|
|
|
|
|
/* Perform actions in the Application thread */
|
|
|
|
@interface AppThreadPerformer : NSObject {
|
2012-11-16 06:13:03 +00:00
|
|
|
GstGLWindowCocoa *m_cocoa;
|
2009-02-26 00:06:58 +00:00
|
|
|
GstGLWindowCB m_callback;
|
2012-11-16 06:13:03 +00:00
|
|
|
GstGLWindowResizeCB m_callback2;
|
2009-02-26 00:06:58 +00:00
|
|
|
gpointer m_data;
|
2009-07-17 14:47:41 +00:00
|
|
|
gint m_width;
|
|
|
|
gint m_height;
|
2009-02-26 00:06:58 +00:00
|
|
|
}
|
2012-11-16 06:13:03 +00:00
|
|
|
- (id) init: (GstGLWindowCocoa *)window;
|
|
|
|
- (id) initWithCallback:(GstGLWindowCocoa *)window callback:(GstGLWindowCB)callback userData:(gpointer) data;
|
|
|
|
- (id) initWithSize: (GstGLWindowCocoa *)window callback:(GstGLWindowResizeCB)callback userData:(gpointer)data toSize:(NSSize)size;
|
|
|
|
- (id) initWithAll: (GstGLWindowCocoa *)window callback:(GstGLWindowCB)callback userData:(gpointer) data;
|
2009-02-26 00:06:58 +00:00
|
|
|
- (void) updateWindow;
|
|
|
|
- (void) sendToApp;
|
2009-07-17 14:47:41 +00:00
|
|
|
- (void) setWindow;
|
2009-02-26 00:06:58 +00:00
|
|
|
- (void) stopApp;
|
2009-07-24 08:12:07 +00:00
|
|
|
- (void) closeWindow;
|
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
|
|
|
|
|
|
|
#ifndef GNUSTEP
|
2009-04-13 05:24:06 +00:00
|
|
|
static BOOL GSRegisterCurrentThread(void) { return TRUE; };
|
|
|
|
static void GSUnregisterCurrentThread(void) {};
|
2009-02-26 00:06:58 +00:00
|
|
|
#endif
|
|
|
|
|
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);
|
|
|
|
|
2013-02-12 12:48:36 +00:00
|
|
|
gboolean gst_gl_window_cocoa_create_context (GstGLWindow *window, GstGLAPI gl_api,
|
|
|
|
guintptr external_opengl_context, GError **error);
|
2012-11-16 06:13:03 +00:00
|
|
|
guintptr gst_gl_window_cocoa_get_gl_context (GstGLWindow * window);
|
|
|
|
gboolean gst_gl_window_cocoa_activate (GstGLWindow * window, gboolean activate);
|
|
|
|
void gst_gl_window_cocoa_set_window_handle (GstGLWindow * window,
|
|
|
|
guintptr handle);
|
|
|
|
void gst_gl_window_cocoa_draw_unlocked (GstGLWindow * window, guint width,
|
|
|
|
guint height);
|
|
|
|
void gst_gl_window_cocoa_draw (GstGLWindow * window, guint width, guint height);
|
|
|
|
void gst_gl_window_cocoa_run (GstGLWindow * window);
|
|
|
|
void gst_gl_window_cocoa_quit (GstGLWindow * window, GstGLWindowCB callback,
|
|
|
|
gpointer data);
|
|
|
|
void gst_gl_window_cocoa_send_message (GstGLWindow * window,
|
|
|
|
GstGLWindowCB callback, gpointer data);
|
2012-12-03 04:04:49 +00:00
|
|
|
GstGLAPI gst_gl_window_cocoa_get_gl_api (GstGLWindow * window);
|
2012-11-16 06:13:03 +00:00
|
|
|
|
|
|
|
struct _GstGLWindowCocoaPrivate
|
2009-02-26 00:06:58 +00:00
|
|
|
{
|
|
|
|
GstGLNSWindow *internal_win_id;
|
2009-10-26 10:44:35 +00:00
|
|
|
NSOpenGLContext *gl_context;
|
2009-07-17 14:47:41 +00:00
|
|
|
NSOpenGLContext *external_gl_context;
|
2009-02-26 00:06:58 +00:00
|
|
|
gboolean visible;
|
|
|
|
NSWindow *parent;
|
2009-07-17 14:47:41 +00:00
|
|
|
NSThread *thread;
|
|
|
|
gboolean running;
|
2009-07-27 07:58:20 +00:00
|
|
|
guint source_id;
|
2009-02-26 00:06:58 +00:00
|
|
|
};
|
|
|
|
|
2009-07-27 07:58:20 +00:00
|
|
|
gboolean
|
2012-11-16 06:13:03 +00:00
|
|
|
gst_gl_window_cocoa_nsapp_iteration (gpointer data)
|
2010-01-05 23:13:46 +00:00
|
|
|
{
|
2009-07-27 07:58:20 +00:00
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
|
|
|
|
2010-01-05 23:13:46 +00:00
|
|
|
NSEvent *event = nil;
|
|
|
|
|
2009-07-27 07:58:20 +00:00
|
|
|
if ([NSThread isMainThread]) {
|
|
|
|
|
2009-08-03 08:13:02 +00:00
|
|
|
while ((event = ([NSApp nextEventMatchingMask:NSAnyEventMask
|
|
|
|
untilDate:[NSDate dateWithTimeIntervalSinceNow:0.5]
|
2009-07-27 07:58:20 +00:00
|
|
|
inMode:NSDefaultRunLoopMode dequeue:YES])) != nil)
|
2009-08-03 08:13:02 +00:00
|
|
|
|
|
|
|
[NSApp sendEvent:event];
|
2009-07-27 07:58:20 +00:00
|
|
|
}
|
|
|
|
|
2010-01-05 23:13:46 +00:00
|
|
|
[pool release];
|
|
|
|
|
2009-07-27 07:58:20 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
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;
|
2013-07-10 14:47:23 +00:00
|
|
|
|
|
|
|
#ifndef GNUSTEP
|
|
|
|
NSAutoreleasePool* pool = nil;
|
|
|
|
#endif
|
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));
|
|
|
|
|
2013-02-12 12:48:36 +00:00
|
|
|
window_class->create_context =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_gl_window_cocoa_create_context);
|
2012-11-16 06:13:03 +00:00
|
|
|
window_class->get_gl_context =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_gl_window_cocoa_get_gl_context);
|
|
|
|
window_class->activate = GST_DEBUG_FUNCPTR (gst_gl_window_cocoa_activate);
|
|
|
|
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);
|
|
|
|
window_class->send_message =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_gl_window_cocoa_send_message);
|
2012-12-03 04:04:49 +00:00
|
|
|
window_class->get_gl_api =
|
|
|
|
GST_DEBUG_FUNCPTR (gst_gl_window_cocoa_get_gl_api);
|
2012-11-16 06:13:03 +00:00
|
|
|
|
|
|
|
#ifndef GNUSTEP
|
2013-07-10 14:47:23 +00:00
|
|
|
pool = [[NSAutoreleasePool alloc] init];
|
2012-11-16 06:13:03 +00:00
|
|
|
[NSApplication sharedApplication];
|
2013-07-10 14:47:23 +00:00
|
|
|
|
2012-11-16 06:13:03 +00:00
|
|
|
[pool release];
|
|
|
|
#endif
|
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);
|
2013-02-12 12:48:36 +00:00
|
|
|
|
|
|
|
gst_gl_window_set_need_lock (GST_GL_WINDOW (window), FALSE);
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
gst_gl_window_cocoa_create_context (GstGLWindow *window, GstGLAPI gl_api,
|
|
|
|
guintptr external_gl_context, GError **error)
|
|
|
|
{
|
|
|
|
GstGLWindowCocoa *window_cocoa = GST_GL_WINDOW_COCOA (window);
|
|
|
|
GstGLWindowCocoaPrivate *priv = window_cocoa->priv;
|
2009-02-26 00:06:58 +00:00
|
|
|
NSRect rect;
|
2012-11-16 06:13:03 +00:00
|
|
|
NSAutoreleasePool *pool;
|
2009-02-26 00:06:58 +00:00
|
|
|
|
|
|
|
priv->internal_win_id = nil;
|
2009-10-26 10:44:35 +00:00
|
|
|
priv->gl_context = nil;
|
2009-07-17 14:47:41 +00:00
|
|
|
priv->external_gl_context = (NSOpenGLContext *) external_gl_context;
|
2009-02-26 00:06:58 +00:00
|
|
|
priv->visible = FALSE;
|
|
|
|
priv->parent = nil;
|
2009-07-17 14:47:41 +00:00
|
|
|
priv->thread = nil;
|
|
|
|
priv->running = TRUE;
|
2009-02-26 00:06:58 +00:00
|
|
|
|
|
|
|
GSRegisterCurrentThread();
|
2009-07-17 14:47:41 +00:00
|
|
|
|
2009-02-26 00:06:58 +00:00
|
|
|
pool = [[NSAutoreleasePool alloc] init];
|
2010-01-05 23:13:46 +00:00
|
|
|
|
|
|
|
#ifdef GNUSTEP
|
|
|
|
[NSApplication sharedApplication];
|
|
|
|
#endif
|
2009-02-26 00:06:58 +00:00
|
|
|
|
2009-03-07 02:13:38 +00:00
|
|
|
rect.origin.x = 0;
|
|
|
|
rect.origin.y = 0;
|
2010-01-05 23:13:46 +00:00
|
|
|
rect.size.width = 320;
|
|
|
|
rect.size.height = 240;
|
2009-02-26 00:06:58 +00:00
|
|
|
|
2009-07-17 14:47:41 +00:00
|
|
|
priv->internal_win_id =[[GstGLNSWindow alloc] initWithContentRect:rect styleMask:
|
|
|
|
(NSTitledWindowMask | NSClosableWindowMask |
|
2009-07-24 08:12:07 +00:00
|
|
|
NSResizableWindowMask | NSMiniaturizableWindowMask)
|
2013-02-12 12:48:36 +00:00
|
|
|
backing: NSBackingStoreBuffered defer: NO screen: nil gstWin: window_cocoa];
|
2009-02-26 00:06:58 +00:00
|
|
|
|
2012-11-16 06:13:03 +00:00
|
|
|
GST_DEBUG ("NSWindow id: %lud\n", (gulong) priv->internal_win_id);
|
2009-03-07 02:13:38 +00:00
|
|
|
|
2009-07-17 14:47:41 +00:00
|
|
|
priv->thread = [NSThread currentThread];
|
2012-11-16 06:13:03 +00:00
|
|
|
|
2009-07-17 14:47:41 +00:00
|
|
|
[NSApp setDelegate: priv->internal_win_id];
|
2009-03-07 02:13:38 +00:00
|
|
|
|
2009-02-26 00:06:58 +00:00
|
|
|
[pool release];
|
2009-07-27 07:58:20 +00:00
|
|
|
|
2010-01-05 23:13:46 +00:00
|
|
|
#ifndef GNUSTEP
|
2012-11-16 06:13:03 +00:00
|
|
|
priv->source_id = g_timeout_add_seconds (1, gst_gl_window_cocoa_nsapp_iteration, NULL);
|
2010-01-05 23:13:46 +00:00
|
|
|
#endif
|
2009-02-26 00:06:58 +00:00
|
|
|
|
2013-02-12 12:48:36 +00:00
|
|
|
return TRUE;
|
2009-02-26 00:06:58 +00:00
|
|
|
}
|
|
|
|
|
2012-08-27 14:08:16 +00:00
|
|
|
guintptr
|
2012-11-16 06:13:03 +00:00
|
|
|
gst_gl_window_cocoa_get_gl_context (GstGLWindow * window)
|
2009-10-26 10:44:35 +00:00
|
|
|
{
|
2012-11-16 06:13:03 +00:00
|
|
|
return (guintptr) GST_GL_WINDOW_COCOA (window)->priv->gl_context;
|
2009-10-26 10:44:35 +00:00
|
|
|
}
|
|
|
|
|
2012-11-16 06:13:03 +00:00
|
|
|
gboolean
|
|
|
|
gst_gl_window_cocoa_activate (GstGLWindow * window, gboolean activate)
|
2009-10-26 10:44:35 +00:00
|
|
|
{
|
2012-11-16 06:13:03 +00:00
|
|
|
GstGLWindowCocoa *window_cocoa;
|
|
|
|
GstGLWindowCocoaPrivate *priv;
|
2009-10-26 10:44:35 +00:00
|
|
|
|
2012-11-16 06:13:03 +00:00
|
|
|
window_cocoa = GST_GL_WINDOW_COCOA (window);
|
|
|
|
priv = window_cocoa->priv;
|
2009-10-26 10:44:35 +00:00
|
|
|
|
|
|
|
if (activate)
|
2012-11-16 06:13:03 +00:00
|
|
|
[priv->gl_context makeCurrentContext];
|
|
|
|
#if 0
|
2009-10-26 10:44:35 +00:00
|
|
|
else
|
2012-11-16 06:13:03 +00:00
|
|
|
/* FIXME */
|
|
|
|
[priv->gl_context clearCurrentContext];
|
|
|
|
#endif
|
|
|
|
return TRUE;
|
2009-10-26 10:44:35 +00:00
|
|
|
}
|
|
|
|
|
2009-02-26 00:06:58 +00:00
|
|
|
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;
|
|
|
|
|
2009-07-27 07:58:20 +00:00
|
|
|
g_source_remove (priv->source_id);
|
2009-02-26 00:06:58 +00:00
|
|
|
|
|
|
|
if (GSRegisterCurrentThread()) {
|
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
|
|
|
|
2012-11-16 06:13:03 +00:00
|
|
|
AppThreadPerformer* app_thread_performer = [[AppThreadPerformer alloc] init:window_cocoa];
|
|
|
|
priv->parent = (NSWindow*) handle;
|
2009-07-17 14:47:41 +00:00
|
|
|
[app_thread_performer performSelectorOnMainThread:@selector(setWindow)
|
2010-01-05 23:13:46 +00:00
|
|
|
withObject:0 waitUntilDone:YES];
|
2009-02-26 00:06:58 +00:00
|
|
|
|
|
|
|
[pool release];
|
|
|
|
|
|
|
|
GSUnregisterCurrentThread();
|
|
|
|
}
|
|
|
|
else
|
2012-11-16 06:13:03 +00:00
|
|
|
GST_DEBUG ("failed to register current thread, cannot set external window id\n");
|
2009-02-26 00:06:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Thread safe */
|
|
|
|
void
|
2012-11-16 06:13:03 +00:00
|
|
|
gst_gl_window_cocoa_draw (GstGLWindow * window, guint width, guint height)
|
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;
|
2009-02-26 00:06:58 +00:00
|
|
|
|
|
|
|
if (GSRegisterCurrentThread()) {
|
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
|
|
|
|
2012-11-16 06:13:03 +00:00
|
|
|
AppThreadPerformer* app_thread_performer = [[AppThreadPerformer alloc] init:window_cocoa];
|
2009-07-17 14:47:41 +00:00
|
|
|
[app_thread_performer performSelector:@selector(updateWindow)
|
|
|
|
onThread:priv->thread withObject:nil waitUntilDone:YES];
|
2009-07-24 08:12:07 +00:00
|
|
|
|
|
|
|
if (!priv->parent && !priv->visible) {
|
2009-10-26 10:44:35 +00:00
|
|
|
static gint x = 0;
|
|
|
|
static gint y = 0;
|
|
|
|
|
|
|
|
NSRect mainRect = [[NSScreen mainScreen] visibleFrame];
|
|
|
|
NSRect windowRect = [priv->internal_win_id frame];
|
|
|
|
|
2012-11-16 06:13:03 +00:00
|
|
|
GST_DEBUG ("main screen rect: %d %d %d %d\n", (int) mainRect.origin.x, (int) mainRect.origin.y,
|
2009-10-26 10:44:35 +00:00
|
|
|
(int) mainRect.size.width, (int) mainRect.size.height);
|
|
|
|
|
|
|
|
windowRect.origin.x += x;
|
|
|
|
windowRect.origin.y += mainRect.size.height > y ? (mainRect.size.height - y) * 0.5 : y;
|
|
|
|
windowRect.size.width = width;
|
|
|
|
windowRect.size.height = height;
|
|
|
|
|
2012-11-16 06:13:03 +00:00
|
|
|
GST_DEBUG ("window rect: %d %d %d %d\n", (int) windowRect.origin.x, (int) windowRect.origin.y,
|
2009-10-26 10:44:35 +00:00
|
|
|
(int) windowRect.size.width, (int) windowRect.size.height);
|
|
|
|
|
|
|
|
x += 20;
|
|
|
|
y += 20;
|
|
|
|
|
2010-01-05 23:13:46 +00:00
|
|
|
#ifndef GNUSTEP
|
2012-11-16 06:13:03 +00:00
|
|
|
[priv->internal_win_id setFrame:windowRect display:NO];
|
|
|
|
GST_DEBUG ("make the window available\n");
|
2009-07-24 08:12:07 +00:00
|
|
|
[priv->internal_win_id makeMainWindow];
|
2010-01-05 23:13:46 +00:00
|
|
|
#endif
|
2012-11-16 06:13:03 +00:00
|
|
|
[app_thread_performer performSelector:@selector(orderFront)
|
|
|
|
onThread:priv->thread withObject:nil waitUntilDone:YES];
|
|
|
|
|
|
|
|
/*[priv->internal_win_id setViewsNeedDisplay:YES]; */
|
2009-07-24 08:12:07 +00:00
|
|
|
priv->visible = TRUE;
|
2009-08-03 08:13:02 +00:00
|
|
|
}
|
2009-02-26 00:06:58 +00:00
|
|
|
|
|
|
|
[pool release];
|
|
|
|
|
|
|
|
GSUnregisterCurrentThread();
|
|
|
|
}
|
|
|
|
else
|
2012-11-16 06:13:03 +00:00
|
|
|
GST_DEBUG ("failed to register current thread, cannot draw\n");
|
2009-02-26 00:06:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-11-16 06:13:03 +00:00
|
|
|
gst_gl_window_cocoa_run (GstGLWindow * window)
|
2009-02-26 00:06:58 +00:00
|
|
|
{
|
2012-11-16 06:13:03 +00:00
|
|
|
GstGLWindowCocoa *window_cocoa;
|
|
|
|
GstGLWindowCocoaPrivate *priv;
|
2009-02-26 00:06:58 +00:00
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
2010-01-05 23:13:46 +00:00
|
|
|
#ifndef GNUSTEP
|
2009-07-17 14:47:41 +00:00
|
|
|
NSRunLoop *run_loop = [NSRunLoop currentRunLoop];
|
2010-01-05 23:13:46 +00:00
|
|
|
#endif
|
|
|
|
|
2012-11-16 06:13:03 +00:00
|
|
|
window_cocoa = GST_GL_WINDOW_COCOA (window);
|
|
|
|
priv = window_cocoa->priv;
|
|
|
|
|
|
|
|
GST_DEBUG ("begin loop\n");
|
2009-07-27 07:58:20 +00:00
|
|
|
|
2009-02-26 00:06:58 +00:00
|
|
|
if (priv->internal_win_id != nil) {
|
2010-01-05 23:13:46 +00:00
|
|
|
#ifndef GNUSTEP
|
|
|
|
while (priv->running)
|
2009-08-03 08:13:02 +00:00
|
|
|
[run_loop runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
|
2010-01-05 23:13:46 +00:00
|
|
|
#else
|
|
|
|
[NSApp run];
|
|
|
|
#endif
|
2012-11-16 06:13:03 +00:00
|
|
|
|
2009-02-26 00:06:58 +00:00
|
|
|
[priv->internal_win_id release];
|
2009-07-17 14:47:41 +00:00
|
|
|
priv->internal_win_id = nil;
|
2009-02-26 00:06:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[pool release];
|
|
|
|
|
2012-11-16 06:13:03 +00:00
|
|
|
GST_DEBUG ("end loop\n");
|
2009-02-26 00:06:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Thread safe */
|
|
|
|
void
|
2012-11-16 06:13:03 +00:00
|
|
|
gst_gl_window_cocoa_quit (GstGLWindow * window, GstGLWindowCB callback,
|
2009-02-26 00:06:58 +00:00
|
|
|
gpointer data)
|
|
|
|
{
|
2012-11-16 06:13:03 +00:00
|
|
|
GstGLWindowCocoa *window_cocoa;
|
|
|
|
GstGLWindowCocoaPrivate *priv;
|
|
|
|
|
|
|
|
window_cocoa = GST_GL_WINDOW_COCOA (window);
|
|
|
|
priv = window_cocoa->priv;
|
|
|
|
|
2009-02-26 00:06:58 +00:00
|
|
|
if (window) {
|
2010-01-05 23:13:46 +00:00
|
|
|
if (GSRegisterCurrentThread() || 1) {
|
2009-02-26 00:06:58 +00:00
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
2009-07-17 14:47:41 +00:00
|
|
|
|
2012-11-16 06:13:03 +00:00
|
|
|
AppThreadPerformer* app_thread_performer = [[AppThreadPerformer alloc]
|
|
|
|
initWithAll:window_cocoa callback:callback userData:data];
|
2009-07-17 14:47:41 +00:00
|
|
|
|
|
|
|
[app_thread_performer performSelector:@selector(stopApp) onThread:priv->thread
|
|
|
|
withObject:nil waitUntilDone:YES];
|
2009-02-26 00:06:58 +00:00
|
|
|
|
|
|
|
[pool release];
|
|
|
|
|
|
|
|
GSUnregisterCurrentThread();
|
|
|
|
}
|
|
|
|
else
|
2012-11-16 06:13:03 +00:00
|
|
|
GST_DEBUG ("failed to register current thread, application thread is lost\n");
|
2009-02-26 00:06:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Thread safe */
|
|
|
|
void
|
2012-11-16 06:13:03 +00:00
|
|
|
gst_gl_window_cocoa_send_message (GstGLWindow * window, GstGLWindowCB callback,
|
2009-02-26 00:06:58 +00:00
|
|
|
gpointer data)
|
|
|
|
{
|
2012-11-16 06:13:03 +00:00
|
|
|
GstGLWindowCocoa *window_cocoa;
|
|
|
|
GstGLWindowCocoaPrivate *priv;
|
|
|
|
|
|
|
|
window_cocoa = GST_GL_WINDOW_COCOA (window);
|
|
|
|
priv = window_cocoa->priv;
|
|
|
|
|
2009-02-26 00:06:58 +00:00
|
|
|
if (window) {
|
|
|
|
if (GSRegisterCurrentThread()) {
|
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
|
|
|
|
2012-11-16 06:13:03 +00:00
|
|
|
AppThreadPerformer* app_thread_performer = [[AppThreadPerformer alloc]
|
|
|
|
initWithAll:window_cocoa callback:callback userData:data];
|
2009-07-17 14:47:41 +00:00
|
|
|
|
|
|
|
[app_thread_performer performSelector:@selector(sendToApp) onThread:priv->thread
|
|
|
|
withObject:nil waitUntilDone:YES];
|
2009-02-26 00:06:58 +00:00
|
|
|
|
|
|
|
[pool release];
|
|
|
|
|
|
|
|
GSUnregisterCurrentThread();
|
|
|
|
}
|
|
|
|
else
|
2012-11-16 06:13:03 +00:00
|
|
|
GST_DEBUG ("failed to register current thread, cannot send message\n");
|
2009-02-26 00:06:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-03 04:04:49 +00:00
|
|
|
GstGLAPI
|
|
|
|
gst_gl_window_cocoa_get_gl_api (GstGLWindow * window)
|
|
|
|
{
|
|
|
|
return GST_GL_API_OPENGL;
|
|
|
|
}
|
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
|
|
|
|
|
|
|
@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-07-17 14:47:41 +00:00
|
|
|
GstGLNSOpenGLView *glView = nil;
|
2009-02-26 00:06:58 +00:00
|
|
|
NSOpenGLPixelFormat *fmt = nil;
|
|
|
|
NSOpenGLContext *glContext = nil;
|
|
|
|
NSOpenGLPixelFormatAttribute attribs[] = {
|
|
|
|
NSOpenGLPFADoubleBuffer,
|
2012-11-16 06:13:03 +00:00
|
|
|
NSOpenGLPFAAccumSize, 32,
|
2009-02-26 00:06:58 +00:00
|
|
|
0
|
|
|
|
};
|
|
|
|
|
2009-04-13 05:24:06 +00:00
|
|
|
m_isClosed = NO;
|
2012-11-16 06:13:03 +00:00
|
|
|
m_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
|
|
|
|
2009-07-17 14:47:41 +00:00
|
|
|
glView = [GstGLNSOpenGLView alloc];
|
2009-02-26 00:06:58 +00:00
|
|
|
|
|
|
|
fmt = [[NSOpenGLPixelFormat alloc] initWithAttributes:attribs];
|
|
|
|
|
|
|
|
if (!fmt) {
|
2012-11-16 06:13:03 +00:00
|
|
|
GST_WARNING ("cannot create NSOpenGLPixelFormat");
|
2009-02-26 00:06:58 +00:00
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2012-11-16 06:13:03 +00:00
|
|
|
glView = [glView initWithFrame:m_cocoa rect:contentRect pixelFormat:fmt];
|
2009-07-17 14:47:41 +00:00
|
|
|
|
|
|
|
[self setContentView:glView];
|
|
|
|
|
2010-01-05 23:13:46 +00:00
|
|
|
#ifndef GNUSTEP
|
2009-07-17 14:47:41 +00:00
|
|
|
glContext = [[NSOpenGLContext alloc] initWithFormat:fmt
|
2012-11-16 06:13:03 +00:00
|
|
|
shareContext:m_cocoa->priv->external_gl_context];
|
2009-10-26 10:44:35 +00:00
|
|
|
|
2012-11-16 06:13:03 +00:00
|
|
|
GST_DEBUG ("NSOpenGL context created: %lud\n", (gulong) glContext);
|
2009-10-26 10:44:35 +00:00
|
|
|
|
2013-07-10 14:47:23 +00:00
|
|
|
m_cocoa->priv->gl_context = glContext;
|
2009-07-17 14:47:41 +00:00
|
|
|
|
|
|
|
[glView setOpenGLContext:glContext];
|
2010-01-05 23:13:46 +00:00
|
|
|
#else
|
|
|
|
glContext = [glView openGLContext];
|
|
|
|
#endif
|
2009-02-26 00:06:58 +00:00
|
|
|
|
|
|
|
/* OpenGL context is made current only one time threre.
|
|
|
|
* Indeed, all OpenGL calls are made in only one thread,
|
|
|
|
* the Application thread */
|
|
|
|
[glContext makeCurrentContext];
|
|
|
|
|
|
|
|
[glContext update];
|
|
|
|
|
|
|
|
/* Back and front buffers are swapped only during the vertical retrace of the monitor.
|
|
|
|
* Discarded if you configured your driver to Never-use-V-Sync.
|
|
|
|
*/
|
|
|
|
NS_DURING {
|
|
|
|
if (glContext) {
|
2010-01-05 23:13:46 +00:00
|
|
|
#ifdef GNUSTEP
|
|
|
|
const long swapInterval = 1;
|
|
|
|
#else
|
|
|
|
const GLint swapInterval = 1;
|
|
|
|
#endif
|
|
|
|
[[glView openGLContext] setValues:&swapInterval forParameter:NSOpenGLCPSwapInterval];
|
2009-02-26 00:06:58 +00:00
|
|
|
}
|
|
|
|
} NS_HANDLER {
|
2012-11-16 06:13:03 +00:00
|
|
|
GST_DEBUG ("your back-end does not implement NSOpenglContext::setValues\n");
|
2009-02-26 00:06:58 +00:00
|
|
|
}
|
|
|
|
NS_ENDHANDLER
|
|
|
|
|
2012-11-16 06:13:03 +00:00
|
|
|
GST_DEBUG ("opengl GstGLNSWindow initialized: %d x %d\n",
|
2009-07-17 14:47:41 +00:00
|
|
|
(gint) contentRect.size.width, (gint) contentRect.size.height);
|
2009-02-26 00:06:58 +00:00
|
|
|
|
|
|
|
[self setTitle:@"OpenGL renderer"];
|
2009-07-17 14:47:41 +00:00
|
|
|
|
|
|
|
[self setBackgroundColor:[NSColor clearColor]];
|
2009-07-24 08:12:07 +00:00
|
|
|
|
2012-11-16 06:13:03 +00:00
|
|
|
[self orderOut:m_cocoa->priv->internal_win_id];
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Called in the main thread which is never the gl thread */
|
2009-02-26 00:06:58 +00:00
|
|
|
- (BOOL) windowShouldClose:(id)sender {
|
2009-07-24 08:12:07 +00:00
|
|
|
|
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
|
|
|
AppThreadPerformer* app_thread_performer = [[AppThreadPerformer alloc]
|
2012-11-16 06:13:03 +00:00
|
|
|
init:m_cocoa];
|
2010-01-05 23:13:46 +00:00
|
|
|
|
2012-11-16 06:13:03 +00:00
|
|
|
GST_DEBUG ("user clicked the close button\n");
|
2009-07-24 08:12:07 +00:00
|
|
|
|
2012-11-16 06:13:03 +00:00
|
|
|
[app_thread_performer performSelector:@selector(closeWindow) onThread:m_cocoa->priv->thread
|
2009-07-24 08:12:07 +00:00
|
|
|
withObject:nil waitUntilDone:YES];
|
|
|
|
|
|
|
|
[pool release];
|
|
|
|
|
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
|
|
|
/* =============================================================*/
|
|
|
|
/* */
|
|
|
|
/* GstGLNSOpenGLView implementation */
|
|
|
|
/* */
|
|
|
|
/* =============================================================*/
|
|
|
|
|
|
|
|
@implementation GstGLNSOpenGLView
|
|
|
|
|
2012-11-16 06:13:03 +00:00
|
|
|
- (id)initWithFrame:(GstGLWindowCocoa *)window rect:(NSRect)contentRect pixelFormat:(NSOpenGLPixelFormat *)fmt {
|
2009-07-17 14:47:41 +00:00
|
|
|
|
|
|
|
self = [super initWithFrame: contentRect pixelFormat: fmt];
|
|
|
|
|
2012-11-16 06:13:03 +00:00
|
|
|
m_cocoa = window;
|
2009-08-03 08:13:02 +00:00
|
|
|
m_resizeCount = 0;
|
|
|
|
|
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
|
2009-07-17 14:47:41 +00:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)reshape {
|
2012-11-16 06:13:03 +00:00
|
|
|
GstGLWindow *window;
|
|
|
|
|
|
|
|
window = GST_GL_WINDOW (m_cocoa);
|
2010-01-05 23:13:46 +00:00
|
|
|
|
2009-08-03 08:13:02 +00:00
|
|
|
if (m_resizeCount % 5 == 0) {
|
|
|
|
m_resizeCount = 0;
|
2012-11-16 06:13:03 +00:00
|
|
|
if (window->resize) {
|
2009-07-17 14:47:41 +00:00
|
|
|
|
2009-08-03 08:13:02 +00:00
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
|
|
|
NSRect bounds = [self bounds];
|
|
|
|
AppThreadPerformer* app_thread_performer = [[AppThreadPerformer alloc]
|
2012-11-16 06:13:03 +00:00
|
|
|
initWithSize:m_cocoa callback:window->resize userData:window->resize_data
|
|
|
|
toSize:bounds.size];
|
|
|
|
|
|
|
|
[app_thread_performer performSelector:@selector(resizeWindow) onThread:m_cocoa->priv->thread
|
2009-08-03 08:13:02 +00:00
|
|
|
withObject:nil waitUntilDone:YES];
|
2009-07-17 14:47:41 +00:00
|
|
|
|
2009-08-03 08:13:02 +00:00
|
|
|
[pool release];
|
|
|
|
}
|
2009-07-17 14:47:41 +00:00
|
|
|
}
|
2009-08-03 08:13:02 +00:00
|
|
|
m_resizeCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) update {
|
2009-07-17 14:47:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
/* =============================================================*/
|
|
|
|
/* */
|
|
|
|
/* AppThreadPerformer implementation */
|
|
|
|
/* */
|
|
|
|
/* =============================================================*/
|
2009-02-26 00:06:58 +00:00
|
|
|
|
|
|
|
@implementation AppThreadPerformer
|
|
|
|
|
2012-11-16 06:13:03 +00:00
|
|
|
- (id) init: (GstGLWindowCocoa *) window {
|
|
|
|
m_cocoa = window;
|
2009-02-26 00:06:58 +00:00
|
|
|
m_callback = NULL;
|
2009-07-17 14:47:41 +00:00
|
|
|
m_callback2 = NULL;
|
2009-02-26 00:06:58 +00:00
|
|
|
m_data = NULL;
|
2009-07-17 14:47:41 +00:00
|
|
|
m_width = 0;
|
|
|
|
m_height = 0;
|
2009-02-26 00:06:58 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2012-11-16 06:13:03 +00:00
|
|
|
- (id) initWithCallback:(GstGLWindowCocoa *)window callback:(GstGLWindowCB)callback userData:(gpointer)data {
|
|
|
|
m_cocoa = window;
|
2009-02-26 00:06:58 +00:00
|
|
|
m_callback = callback;
|
2009-07-17 14:47:41 +00:00
|
|
|
m_callback2 = NULL;
|
|
|
|
m_data = data;
|
|
|
|
m_width = 0;
|
|
|
|
m_height = 0;
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2012-11-16 06:13:03 +00:00
|
|
|
- (id) initWithSize: (GstGLWindowCocoa *) window
|
|
|
|
callback:(GstGLWindowResizeCB)callback userData:(gpointer)data
|
|
|
|
toSize:(NSSize)size {
|
|
|
|
m_cocoa = window;
|
2009-07-17 14:47:41 +00:00
|
|
|
m_callback = NULL;
|
|
|
|
m_callback2 = callback;
|
2009-02-26 00:06:58 +00:00
|
|
|
m_data = data;
|
2009-07-17 14:47:41 +00:00
|
|
|
m_width = size.width;
|
|
|
|
m_height = size.height;
|
2009-02-26 00:06:58 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2012-11-16 06:13:03 +00:00
|
|
|
- (id) initWithAll: (GstGLWindowCocoa *) window
|
|
|
|
callback:(GstGLWindowCB) callback userData: (gpointer) data {
|
|
|
|
m_cocoa = window;
|
2009-02-26 00:06:58 +00:00
|
|
|
m_callback = callback;
|
2009-07-17 14:47:41 +00:00
|
|
|
m_callback2 = NULL;
|
2009-02-26 00:06:58 +00:00
|
|
|
m_data = data;
|
2009-07-17 14:47:41 +00:00
|
|
|
m_width = 0;
|
|
|
|
m_height = 0;
|
2009-02-26 00:06:58 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) updateWindow {
|
2012-11-16 06:13:03 +00:00
|
|
|
if (m_cocoa->priv->running) {
|
2009-02-26 00:06:58 +00:00
|
|
|
|
2012-11-16 06:13:03 +00:00
|
|
|
if (![m_cocoa->priv->internal_win_id isClosed]) {
|
2009-02-26 00:06:58 +00:00
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
|
|
|
|
2009-08-03 08:13:02 +00:00
|
|
|
/* draw opengl scene in the back buffer */
|
2012-11-16 06:13:03 +00:00
|
|
|
GST_GL_WINDOW (m_cocoa)->draw (GST_GL_WINDOW (m_cocoa)->draw_data);
|
2009-08-03 08:13:02 +00:00
|
|
|
/* Copy the back buffer to the front buffer */
|
2012-11-16 06:13:03 +00:00
|
|
|
[[[m_cocoa->priv->internal_win_id contentView] openGLContext] flushBuffer];
|
2009-02-26 00:06:58 +00:00
|
|
|
|
|
|
|
[pool release];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-17 14:47:41 +00:00
|
|
|
- (void) resizeWindow {
|
2012-11-16 06:13:03 +00:00
|
|
|
if (m_cocoa->priv->running && ![m_cocoa->priv->internal_win_id isClosed]) {
|
2009-07-17 14:47:41 +00:00
|
|
|
m_callback2 (m_data, m_width, m_height);
|
2012-11-16 06:13:03 +00:00
|
|
|
[[[m_cocoa->priv->internal_win_id contentView] openGLContext] update];
|
|
|
|
GST_GL_WINDOW (m_cocoa)->draw (GST_GL_WINDOW (m_cocoa)->draw_data);
|
|
|
|
[[[m_cocoa->priv->internal_win_id contentView] openGLContext] flushBuffer];
|
2009-07-24 08:12:07 +00:00
|
|
|
}
|
2009-02-26 00:06:58 +00:00
|
|
|
}
|
|
|
|
|
2009-07-17 14:47:41 +00:00
|
|
|
- (void) sendToApp {
|
2012-11-16 06:13:03 +00:00
|
|
|
if (m_cocoa->priv->running && ![m_cocoa->priv->internal_win_id isClosed])
|
2009-07-17 14:47:41 +00:00
|
|
|
m_callback (m_data);
|
2009-02-26 00:06:58 +00:00
|
|
|
}
|
|
|
|
|
2009-07-17 14:47:41 +00:00
|
|
|
- (void) setWindow {
|
2009-02-26 00:06:58 +00:00
|
|
|
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
|
2012-11-16 06:13:03 +00:00
|
|
|
NSWindow *window = m_cocoa->priv->parent;
|
2009-07-17 14:47:41 +00:00
|
|
|
|
2012-11-16 06:13:03 +00:00
|
|
|
[m_cocoa->priv->internal_win_id orderOut:m_cocoa->priv->internal_win_id];
|
2009-07-17 14:47:41 +00:00
|
|
|
|
2012-11-16 06:13:03 +00:00
|
|
|
[window setContentView: [m_cocoa->priv->internal_win_id contentView]];
|
2009-07-24 08:12:07 +00:00
|
|
|
|
2009-02-26 00:06:58 +00:00
|
|
|
[pool release];
|
|
|
|
}
|
|
|
|
|
2009-07-17 14:47:41 +00:00
|
|
|
- (void) stopApp {
|
2013-07-10 14:47:23 +00:00
|
|
|
#ifdef GNUSTEP
|
|
|
|
NSAutoreleasePool *pool = nil;
|
|
|
|
#endif
|
2012-11-16 06:13:03 +00:00
|
|
|
|
|
|
|
m_cocoa->priv->running = FALSE;
|
2013-07-02 12:45:08 +00:00
|
|
|
if (m_callback)
|
|
|
|
m_callback (m_data);
|
|
|
|
|
2012-11-16 06:13:03 +00:00
|
|
|
#ifdef GNUSTEP
|
|
|
|
pool = [[NSAutoreleasePool alloc] init];
|
2010-01-05 23:13:46 +00:00
|
|
|
if ([NSApp isRunning])
|
|
|
|
[NSApp stop:self];
|
|
|
|
[pool release];
|
|
|
|
#endif
|
2009-07-24 08:12:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) closeWindow {
|
2012-11-16 06:13:03 +00:00
|
|
|
GstGLWindow *window;
|
|
|
|
|
|
|
|
window = GST_GL_WINDOW (m_cocoa);
|
|
|
|
|
|
|
|
[m_cocoa->priv->internal_win_id setClosed];
|
|
|
|
if (window->close) {
|
|
|
|
window->close (window->close_data);
|
2009-07-24 08:12:07 +00:00
|
|
|
}
|
2012-11-16 06:13:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) orderFront {
|
|
|
|
[m_cocoa->priv->internal_win_id orderFront:m_cocoa->priv->internal_win_id];
|
2009-07-17 14:47:41 +00:00
|
|
|
}
|
|
|
|
|
2009-02-26 00:06:58 +00:00
|
|
|
@end
|