gboolean _gst_gl_window_debug = FALSE;
+void gst_gl_window_init_platform ()
+{
+#ifndef GNUSTEP
+ NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
+ [NSApplication sharedApplication];
+
+ [pool release];
+#endif
+}
+
/* Must be called in the gl thread */
static void
gst_gl_window_finalize (GObject * object)
}
gboolean
-gst_gl_window_nsapp_init (GCond *nsapp_init_cond)
-{
- NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
- [NSApplication sharedApplication];
-
- [pool release];
-
- g_cond_signal (nsapp_init_cond);
-
- return FALSE;
-}
-
-gboolean
gst_gl_window_nsapp_iteration (gpointer data)
-{
- NSEvent *event = nil;
-
+{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ NSEvent *event = nil;
+
if ([NSThread isMainThread]) {
while ((event = ([NSApp nextEventMatchingMask:NSAnyEventMask
inMode:NSDefaultRunLoopMode dequeue:YES])) != nil)
[NSApp sendEvent:event];
-
- [pool release];
-
}
+ [pool release];
+
return TRUE;
}
-
static void
gst_gl_window_class_init (GstGLWindowClass * klass)
{
GObjectClass *obj_class = G_OBJECT_CLASS (klass);
- GMutex *nsapp_init_mutex = g_mutex_new ();
- GCond *nsapp_init_cond = g_cond_new ();
-
- g_mutex_lock (nsapp_init_mutex);
-
- g_idle_add ((GSourceFunc) gst_gl_window_nsapp_init, nsapp_init_cond);
-
- g_cond_wait (nsapp_init_cond, nsapp_init_mutex);
- g_mutex_unlock (nsapp_init_mutex);
-
- g_mutex_free (nsapp_init_mutex);
- g_cond_free (nsapp_init_cond);
-
g_type_class_add_private (klass, sizeof (GstGLWindowPrivate));
obj_class->finalize = gst_gl_window_finalize;
gst_gl_window_log_handler, NULL);
}
-
/* Must be called in the gl thread */
GstGLWindow *
-gst_gl_window_new (gint width, gint height, gulong external_gl_context)
+gst_gl_window_new (gulong external_gl_context)
{
GstGLWindow *window = g_object_new (GST_GL_TYPE_WINDOW, NULL);
GstGLWindowPrivate *priv = window->priv;
GSRegisterCurrentThread();
pool = [[NSAutoreleasePool alloc] init];
+
+#ifdef GNUSTEP
+ [NSApplication sharedApplication];
+#endif
rect.origin.x = 0;
rect.origin.y = 0;
- rect.size.width = 1;
- rect.size.height = 1;
+ rect.size.width = 320;
+ rect.size.height = 240;
priv->internal_win_id =[[GstGLNSWindow alloc] initWithContentRect:rect styleMask:
(NSTitledWindowMask | NSClosableWindowMask |
[pool release];
- priv->source_id = g_timeout_add_seconds (1, gst_gl_window_nsapp_iteration, priv->internal_win_id);
+#ifndef GNUSTEP
+ priv->source_id = g_timeout_add_seconds (1, gst_gl_window_nsapp_iteration, NULL);
+#endif
return window;
}
void
callback_inactivate_gl_context (GstGLWindowPrivate * priv)
{
- [priv->gl_context clearCurrentContext];
+ //FIXME: [priv->gl_context clearCurrentContext];
}
void
AppThreadPerformer* app_thread_performer = [[AppThreadPerformer alloc] initWithPrivate:priv];
priv->parent = (NSWindow*) id;
[app_thread_performer performSelectorOnMainThread:@selector(setWindow)
- withObject:nil waitUntilDone:YES];
+ withObject:0 waitUntilDone:YES];
[pool release];
GSUnregisterCurrentThread();
}
else
- g_debug ("failed to register current thread, cannot set external window id");
+ g_debug ("failed to register current thread, cannot set external window id\n");
}
/* Must be called in the gl thread */
x += 20;
y += 20;
- g_debug ("make the window available");
+#ifndef GNUSTEP
+ g_debug ("make the window available\n");
[priv->internal_win_id makeMainWindow];
+#endif
[priv->internal_win_id orderFront:priv->internal_win_id];
+ //[priv->internal_win_id setViewsNeedDisplay:YES];
priv->visible = TRUE;
}
GSUnregisterCurrentThread();
}
else
- g_debug ("failed to register current thread, cannot draw");
+ g_debug ("failed to register current thread, cannot draw\n");
}
void
{
GstGLWindowPrivate *priv = window->priv;
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+#ifndef GNUSTEP
NSRunLoop *run_loop = [NSRunLoop currentRunLoop];
-
- g_debug ("begin loop: %lud\n", (gulong) run_loop);
+#endif
+
+ g_debug ("begin loop\n");
if (priv->internal_win_id != nil) {
- while(priv->running)
+#ifndef GNUSTEP
+ while (priv->running)
[run_loop runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
-
+#else
+ [NSApp run];
+#endif
+
[priv->internal_win_id release];
priv->internal_win_id = nil;
}
{
if (window) {
- if (GSRegisterCurrentThread()) {
+ if (GSRegisterCurrentThread() || 1) {
GstGLWindowPrivate *priv = window->priv;
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
GSUnregisterCurrentThread();
}
else
- g_debug ("failed to register current thread, application thread is lost");
+ g_debug ("failed to register current thread, application thread is lost\n");
}
}
GSUnregisterCurrentThread();
}
else
- g_debug ("failed to register current thread, cannot send message");
+ g_debug ("failed to register current thread, cannot send message\n");
}
}
[self setReleasedWhenClosed:NO];
- g_debug ("initializing GstGLNSWindow");
+ g_debug ("initializing GstGLNSWindow\n");
glView = [GstGLNSOpenGLView alloc];
[self setContentView:glView];
+#ifndef GNUSTEP
glContext = [[NSOpenGLContext alloc] initWithFormat:fmt
shareContext:m_priv->external_gl_context];
priv->gl_context = glContext;
[glView setOpenGLContext:glContext];
+#else
+ glContext = [glView openGLContext];
+#endif
/* OpenGL context is made current only one time threre.
* Indeed, all OpenGL calls are made in only one thread,
*/
NS_DURING {
if (glContext) {
- long swapInterval = 1;
- [[glView openGLContext] setValues:(const GLint *)&swapInterval forParameter:NSOpenGLCPSwapInterval];
+#ifdef GNUSTEP
+ const long swapInterval = 1;
+#else
+ const GLint swapInterval = 1;
+#endif
+ [[glView openGLContext] setValues:&swapInterval forParameter:NSOpenGLCPSwapInterval];
}
} NS_HANDLER {
- g_debug ("your back-end does not implement NSOpenglContext::setValues");
+ g_debug ("your back-end does not implement NSOpenglContext::setValues\n");
}
NS_ENDHANDLER
- g_debug ("opengl GstGLNSWindow initialized: %d x %d",
+ g_debug ("opengl GstGLNSWindow initialized: %d x %d\n",
(gint) contentRect.size.width, (gint) contentRect.size.height);
[self setTitle:@"OpenGL renderer"];
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
AppThreadPerformer* app_thread_performer = [[AppThreadPerformer alloc]
initWithPrivate:m_priv];
+
+ g_debug ("user clicked the close button\n");
[app_thread_performer performSelector:@selector(closeWindow) onThread:m_priv->thread
withObject:nil waitUntilDone:YES];
m_priv = priv;
m_resizeCount = 0;
+#ifndef GNUSTEP
[self setWantsLayer:NO];
+#endif
return self;
}
-
- (void)reshape {
-
-
+
if (m_resizeCount % 5 == 0) {
m_resizeCount = 0;
if (m_priv->resize_cb) {
- (void) stopApp {
m_priv->running = FALSE;
m_callback (m_data);
+
+ #ifdef GNUSTEP
+ NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
+ if ([NSApp isRunning])
+ [NSApp stop:self];
+ [pool release];
+#endif
}
- (void) closeWindow {