]> git.sesse.net Git - vlc/blobdiff - modules/video_output/macosx.m
Revert "macosx: don't let the video window get larger than the screen it is on (close...
[vlc] / modules / video_output / macosx.m
index 608ddaa4cb268277a13af7031ff15e68424e28cf..1537325f37b2875362eb21b7bfa71087d05cc005 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
- * voutgl.m: MacOS X OpenGL provider
+ * macosx.m: MacOS X OpenGL provider
  *****************************************************************************
- * Copyright (C) 2001-2011 the VideoLAN team
+ * Copyright (C) 2001-2012 the VideoLAN team
  * $Id$
  *
  * Authors: Colin Delacroix <colin@zoy.org>
 #include <vlc_dialog.h>
 #include "opengl.h"
 
+@interface NSWindow (VLCCustomCode)
+- (BOOL)isFullscreen;
+@end
+
 /**
  * Forward declarations
  */
@@ -91,6 +95,7 @@ vlc_module_end ()
     BOOL _hasPendingReshape;
 }
 - (void)setVoutDisplay:(vout_display_t *)vd;
+- (vout_display_t *)voutDisplay;
 - (void)setVoutFlushing:(BOOL)flushing;
 @end
 
@@ -200,9 +205,11 @@ static int Open(vlc_object_t *this)
     sys->gl.swap = OpenglSwap;
     sys->gl.getProcAddress = NULL;
     sys->gl.sys = sys;
+    const vlc_fourcc_t *subpicture_chromas;
+    video_format_t fmt = vd->fmt;
 
-       sys->vgl = vout_display_opengl_New(&vd->fmt, NULL, &sys->gl);
-       if (!sys->vgl)
+    sys->vgl = vout_display_opengl_New(&vd->fmt, &subpicture_chromas, &sys->gl);
+    if (!sys->vgl)
     {
         sys->gl.sys = NULL;
         goto error;
@@ -211,6 +218,8 @@ static int Open(vlc_object_t *this)
     /* */
     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;
@@ -237,6 +246,9 @@ void Close(vlc_object_t *this)
     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");
@@ -289,7 +301,9 @@ static void PictureDisplay(vout_display_t *vd, picture_t *pic, subpicture_t *sub
     [sys->glView setVoutFlushing:NO];
     picture_Release (pic);
     sys->has_first_frame = true;
-       (void)subpicture;
+
+    if (subpicture)
+        subpicture_Delete(subpicture);
 }
 
 static int Control (vout_display_t *vd, int query, va_list ap)
@@ -300,34 +314,45 @@ static int Control (vout_display_t *vd, int query, va_list ap)
     {
         case VOUT_DISPLAY_CHANGE_FULLSCREEN:
         {
-            /* todo */
-            return VLC_EGENERIC;
+            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:
         {
+            NSAutoreleasePool * o_pool = [[NSAutoreleasePool alloc] init];
             unsigned state = va_arg (ap, unsigned);
-            if( (state & VOUT_WINDOW_STATE_ABOVE) != 0)
-                [[sys->glView window] setLevel: NSStatusWindowLevel];
-            else
-                [[sys->glView window] setLevel: NSNormalWindowLevel];
+            [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] performZoom: nil];
+            [[sys->glView window] performSelectorOnMainThread:@selector(performZoom:) withObject: nil waitUntilDone:NO];
             return VLC_SUCCESS;
         }
-        case VOUT_DISPLAY_CHANGE_DISPLAY_SIZE:
         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:
         {
+            // 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];
@@ -353,8 +378,9 @@ static int Control (vout_display_t *vd, int query, va_list ap)
                 new_frame.origin.x = topleftscreen.x;
                 new_frame.origin.y = topleftscreen.y - new_frame.size.height;
 
-                [o_window setFrame:new_frame display:YES animate:YES];
+                [sys->glView performSelectorOnMainThread:@selector(setWindowFrameWithValue:) withObject:[NSValue valueWithRect:new_frame] waitUntilDone:NO];
             }
+            [o_pool release];
             return VLC_SUCCESS;
         }
 
@@ -470,6 +496,20 @@ static void OpenglSwap(vlc_gl_t *gl)
     [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).
@@ -481,6 +521,10 @@ static void OpenglSwap(vlc_gl_t *gl)
     }
 }
 
+- (vout_display_t *)voutDisplay
+{
+    return vd;
+}
 
 /**
  * Gets called when the vout will aquire the lock and flush.
@@ -557,6 +601,11 @@ static void OpenglSwap(vlc_gl_t *gl)
         glClear(GL_COLOR_BUFFER_BIT);
 }
 
+- (void)reshapeView:(id)sender
+{
+    [self reshape];
+}
+
 /**
  * Method called by Cocoa when the view is resized.
  */
@@ -649,8 +698,8 @@ static void OpenglSwap(vlc_gl_t *gl)
     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];
 }
@@ -664,4 +713,12 @@ static void OpenglSwap(vlc_gl_t *gl)
 {
     return YES;
 }
+
+- (void)setWindowLevel:(NSNumber*)state
+{
+    if( [state unsignedIntValue] & VOUT_WINDOW_STATE_ABOVE )
+        [[self window] setLevel: NSStatusWindowLevel];
+    else
+        [[self window] setLevel: NSNormalWindowLevel];
+}
 @end