/*****************************************************************************
- * voutgl.m: MacOS X OpenGL provider
+ * macosx.m: MacOS X OpenGL provider
*****************************************************************************
- * Copyright (C) 2001-2009 the VideoLAN team
+ * Copyright (C) 2001-2012 the VideoLAN team
* $Id$
*
* Authors: Colin Delacroix <colin@zoy.org>
* Benjamin Pracht <bigben at videolan dot org>
* Damien Fouilleul <damienf at videolan dot org>
* Pierre d'Herbemont <pdherbemont at videolan dot org>
+ * Felix Paul Kühne <fkuehne at videolan dot org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include <vlc_common.h>
#include <vlc_plugin.h>
#include <vlc_vout_display.h>
-#include <vlc_vout_opengl.h>
+#include <vlc_opengl.h>
+#include <vlc_dialog.h>
#include "opengl.h"
+@interface NSWindow (VLCCustomCode)
+- (BOOL)isFullscreen;
+@end
+
/**
* Forward declarations
*/
static void Close(vlc_object_t *);
static picture_pool_t *Pool(vout_display_t *vd, unsigned requested_count);
-static void PictureRender(vout_display_t *vd, picture_t *pic);
-static void PictureDisplay(vout_display_t *vd, picture_t *pic);
+static void PictureRender(vout_display_t *vd, picture_t *pic, subpicture_t *subpicture);
+static void PictureDisplay(vout_display_t *vd, picture_t *pic, subpicture_t *subpicture);
static int Control (vout_display_t *vd, int query, va_list ap);
-static int OpenglLock(vout_opengl_t *gl);
-static void OpenglUnlock(vout_opengl_t *gl);
-static void OpenglSwap(vout_opengl_t *gl);
+static int OpenglLock(vlc_gl_t *gl);
+static void OpenglUnlock(vlc_gl_t *gl);
+static void OpenglSwap(vlc_gl_t *gl);
/**
* Module declaration
BOOL _hasPendingReshape;
}
- (void)setVoutDisplay:(vout_display_t *)vd;
+- (vout_display_t *)voutDisplay;
- (void)setVoutFlushing:(BOOL)flushing;
@end
id<VLCOpenGLVideoViewEmbedding> container;
vout_window_t *embed;
- vout_opengl_t gl;
- vout_display_opengl_t vgl;
+ vlc_gl_t gl;
+ vout_display_opengl_t *vgl;
picture_pool_t *pool;
picture_t *current;
if (!sys)
return VLC_ENOMEM;
+ if( !CGDisplayUsesOpenGLAcceleration( kCGDirectMainDisplay ) )
+ {
+ msg_Err( this, "no OpenGL hardware acceleration found, video output will fail" );
+ dialog_Fatal( this, _("Video output is not supported"), _("Your Mac lacks Quartz Extreme acceleration, which is required for video output.") );
+ return VLC_EGENERIC;
+ }
+ else
+ msg_Dbg( this, "Quartz Extreme acceleration is active" );
+
vd->sys = sys;
sys->pool = NULL;
sys->gl.sys = NULL;
sys->gl.lock = OpenglLock;
sys->gl.unlock = OpenglUnlock;
sys->gl.swap = OpenglSwap;
+ sys->gl.getProcAddress = NULL;
sys->gl.sys = sys;
+ const vlc_fourcc_t *subpicture_chromas;
+ video_format_t fmt = vd->fmt;
- if (vout_display_opengl_Init(&sys->vgl, &vd->fmt, &sys->gl))
+ sys->vgl = vout_display_opengl_New(&vd->fmt, &subpicture_chromas, &sys->gl);
+ if (!sys->vgl)
{
sys->gl.sys = NULL;
goto error;
/* */
vout_display_info_t info = vd->info;
info.has_pictures_invalid = false;
+ info.has_event_thread = true;
+ info.subpicture_chromas = subpicture_chromas;
/* Setup vout_display_t once everything is fine */
vd->info = info;
vout_display_t *vd = (vout_display_t *)this;
vout_display_sys_t *sys = vd->sys;
+ if ([[sys->glView window] level] != NSNormalWindowLevel)
+ [[sys->glView window] setLevel: NSNormalWindowLevel];
+
[sys->glView setVoutDisplay:nil];
var_Destroy(vd, "drawable-nsobject");
[sys->glView release];
if (sys->gl.sys != NULL)
- vout_display_opengl_Clean(&sys->vgl);
+ vout_display_opengl_Delete(sys->vgl);
if (sys->embed)
vout_display_DeleteWindow(vd, sys->embed);
static picture_pool_t *Pool(vout_display_t *vd, unsigned requested_count)
{
vout_display_sys_t *sys = vd->sys;
- VLC_UNUSED(requested_count);
if (!sys->pool)
- sys->pool = vout_display_opengl_GetPool (&sys->vgl);
+ sys->pool = vout_display_opengl_GetPool (sys->vgl, requested_count);
assert(sys->pool);
return sys->pool;
}
-static void PictureRender(vout_display_t *vd, picture_t *pic)
+static void PictureRender(vout_display_t *vd, picture_t *pic, subpicture_t *subpicture)
{
vout_display_sys_t *sys = vd->sys;
- vout_display_opengl_Prepare( &sys->vgl, pic );
+ vout_display_opengl_Prepare( sys->vgl, pic, subpicture );
}
-static void PictureDisplay(vout_display_t *vd, picture_t *pic)
+static void PictureDisplay(vout_display_t *vd, picture_t *pic, subpicture_t *subpicture)
{
vout_display_sys_t *sys = vd->sys;
[sys->glView setVoutFlushing:YES];
- vout_display_opengl_Display(&sys->vgl, &vd->fmt );
+ vout_display_opengl_Display(sys->vgl, &vd->fmt );
[sys->glView setVoutFlushing:NO];
picture_Release (pic);
sys->has_first_frame = true;
+
+ if (subpicture)
+ subpicture_Delete(subpicture);
}
static int Control (vout_display_t *vd, int query, va_list ap)
switch (query)
{
case VOUT_DISPLAY_CHANGE_FULLSCREEN:
+ {
+ NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
+ [[sys->glView window] performSelectorOnMainThread:@selector(fullscreen:) withObject: nil waitUntilDone:NO];
+ [o_pool release];
+ return VLC_SUCCESS;
+ }
case VOUT_DISPLAY_CHANGE_WINDOW_STATE:
- case VOUT_DISPLAY_CHANGE_DISPLAY_SIZE:
+ {
+ NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
+ unsigned state = va_arg (ap, unsigned);
+ [sys->glView performSelectorOnMainThread:@selector(setWindowLevel:) withObject:[NSNumber numberWithUnsignedInt:state] waitUntilDone:NO];
+ [o_pool release];
+ return VLC_SUCCESS;
+ }
case VOUT_DISPLAY_CHANGE_DISPLAY_FILLED:
+ {
+ [[sys->glView window] performSelectorOnMainThread:@selector(performZoom:) withObject: nil waitUntilDone:NO];
+ return VLC_SUCCESS;
+ }
case VOUT_DISPLAY_CHANGE_ZOOM:
case VOUT_DISPLAY_CHANGE_SOURCE_ASPECT:
case VOUT_DISPLAY_CHANGE_SOURCE_CROP:
+ return VLC_SUCCESS;
+ case VOUT_DISPLAY_CHANGE_DISPLAY_SIZE:
{
- /* todo */
- return VLC_EGENERIC;
+ // is needed in the case we do not an actual resize
+ [sys->glView performSelectorOnMainThread:@selector(reshapeView:) withObject:nil waitUntilDone:NO];
+
+ if (!config_GetInt( vd, "macosx-video-autoresize" ))
+ return VLC_SUCCESS;
+
+ NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
+ NSPoint topleftbase;
+ NSPoint topleftscreen;
+ NSRect new_frame;
+ const vout_display_cfg_t *cfg;
+
+ id o_window = [sys->glView window];
+ if (!o_window)
+ return VLC_SUCCESS; // this is okay, since the event will occur again when we have a window
+ NSRect windowFrame = [o_window frame];
+ NSRect glViewFrame = [sys->glView frame];
+ NSSize windowMinSize = [o_window minSize];
+
+ topleftbase.x = 0;
+ topleftbase.y = windowFrame.size.height;
+ topleftscreen = [o_window convertBaseToScreen: topleftbase];
+ cfg = (const vout_display_cfg_t*)va_arg (ap, const vout_display_cfg_t *);
+ int i_width = cfg->display.width;
+ int i_height = cfg->display.height;
+
+ /* Calculate the window's new size, if it is larger than our minimal size */
+ if (i_width < windowMinSize.width)
+ i_width = windowMinSize.width;
+ if (i_height < windowMinSize.height)
+ i_height = windowMinSize.height;
+
+ if( i_height != glViewFrame.size.height || i_width != glViewFrame.size.width )
+ {
+ new_frame.size.width = windowFrame.size.width - glViewFrame.size.width + i_width;
+ new_frame.size.height = windowFrame.size.height - glViewFrame.size.height + i_height;
+
+ new_frame.origin.x = topleftscreen.x;
+ new_frame.origin.y = topleftscreen.y - new_frame.size.height;
+
+ [sys->glView performSelectorOnMainThread:@selector(setWindowFrameWithValue:) withObject:[NSValue valueWithRect:new_frame] waitUntilDone:NO];
+ }
+ [o_pool release];
+ return VLC_SUCCESS;
}
+
case VOUT_DISPLAY_HIDE_MOUSE:
+ {
+ [NSCursor setHiddenUntilMouseMoves: YES];
return VLC_SUCCESS;
+ }
case VOUT_DISPLAY_GET_OPENGL:
{
- vout_opengl_t **gl = va_arg (ap, vout_opengl_t **);
+ vlc_gl_t **gl = va_arg (ap, vlc_gl_t **);
*gl = &sys->gl;
return VLC_SUCCESS;
}
/*****************************************************************************
* vout opengl callbacks
*****************************************************************************/
-static int OpenglLock(vout_opengl_t *gl)
+static int OpenglLock(vlc_gl_t *gl)
{
vout_display_sys_t *sys = (vout_display_sys_t *)gl->sys;
NSOpenGLContext *context = [sys->glView openGLContext];
return 1;
}
-static void OpenglUnlock(vout_opengl_t *gl)
+static void OpenglUnlock(vlc_gl_t *gl)
{
vout_display_sys_t *sys = (vout_display_sys_t *)gl->sys;
CGLUnlockContext([[sys->glView openGLContext] CGLContextObj]);
}
-static void OpenglSwap(vout_opengl_t *gl)
+static void OpenglSwap(vlc_gl_t *gl)
{
vout_display_sys_t *sys = (vout_display_sys_t *)gl->sys;
[[sys->glView openGLContext] flushBuffer];
[self setFrame:[value rectValue]];
}
+/**
+ * Gets called by Control() to make sure that we're performing on the main thread
+ */
+- (void)setWindowFrameWithValue:(NSValue *)value
+{
+ if (![[self window] isFullscreen])
+ {
+ NSRect frame = [value rectValue];
+ if (frame.origin.x <= 0.0 && frame.origin.y <= 0.0)
+ [[self window] center];
+ [[self window] setFrame:frame display:YES animate: YES];
+ }
+}
+
/**
* Gets called by the Close and Open methods.
* (Non main thread).
}
}
+- (vout_display_t *)voutDisplay
+{
+ return vd;
+}
/**
* Gets called when the vout will aquire the lock and flush.
if (hasFirstFrame) {
// This will lock gl.
- vout_display_opengl_Display( &vd->sys->vgl, &vd->source );
+ vout_display_opengl_Display( vd->sys->vgl, &vd->source );
}
else
glClear(GL_COLOR_BUFFER_BIT);
}
+- (void)reshapeView:(id)sender
+{
+ [self reshape];
+}
+
/**
* Method called by Cocoa when the view is resized.
*/
NSWindow *window = [self window];
// Remove flashes with splitter view.
- if ([window respondsToSelector:@selector(disableScreenUpdatesUntilFlush)])
- [window disableScreenUpdatesUntilFlush];
+ if ([window respondsToSelector:@selector(disableScreenUpdatesUntilFlush)])
+ [window disableScreenUpdatesUntilFlush];
[super renewGState];
}
{
return YES;
}
+
+- (void)setWindowLevel:(NSNumber*)state
+{
+ if( [state unsignedIntValue] & VOUT_WINDOW_STATE_ABOVE )
+ [[self window] setLevel: NSStatusWindowLevel];
+ else
+ [[self window] setLevel: NSNormalWindowLevel];
+}
@end