]> git.sesse.net Git - vlc/blobdiff - modules/gui/minimal_macosx/VLCOpenGLVoutView.m
Use var_Inherit* instead of var_CreateGet*.
[vlc] / modules / gui / minimal_macosx / VLCOpenGLVoutView.m
index 4fff7ffc233bfbe48ea93246ad60711843fbb7a6..4fa69c12fa0202e03584b490e844767a1017b6e0 100644 (file)
@@ -1,7 +1,7 @@
 /*****************************************************************************
  * VLCOpenGLVoutView.m: MacOS X OpenGL provider
  *****************************************************************************
- * Copyright (C) 2001-2007 the VideoLAN team
+ * Copyright (C) 2001-2009 the VideoLAN team
  * $Id$
  *
  * Authors: Colin Delacroix <colin@zoy.org>
@@ -49,18 +49,20 @@ int cocoaglvoutviewInit( vout_thread_t * p_vout )
 
     msg_Dbg( p_vout, "Mac OS X Vout is opening" );
 
-    var_Create( p_vout, "drawable", VLC_VAR_DOINHERIT );
-    var_Get( p_vout, "drawable", &value_drawable );
+    var_Create( p_vout, "drawable-nsobject", VLC_VAR_DOINHERIT );
+    var_Get( p_vout, "drawable-nsobject", &value_drawable );
 
     p_vout->p_sys->o_pool = [[NSAutoreleasePool alloc] init];
 
-    o_cocoaglview_container = (id) value_drawable.i_int;
+    /* This will be released in cocoaglvoutviewEnd(), on
+     * main thread, after we are done using it. */
+    o_cocoaglview_container = [(id) value_drawable.p_address retain];
     if (!o_cocoaglview_container)
     {
         msg_Warn( p_vout, "No drawable!, spawing a window" );
     }
 
-    p_vout->p_sys->b_embedded = VLC_FALSE;
+    p_vout->p_sys->b_embedded = false;
 
 
     /* Create the GL view */
@@ -80,8 +82,11 @@ void cocoaglvoutviewEnd( vout_thread_t * p_vout )
 {
     id <VLCOpenGLVoutEmbedding> o_cocoaglview_container;
 
+    if (!p_vout->p_sys->o_glview)
+        return;
+
     msg_Dbg( p_vout, "Mac OS X Vout is closing" );
-    var_Destroy( p_vout, "drawable" );
+    var_Destroy( p_vout, "drawable-nsobject" );
 
     o_cocoaglview_container = [p_vout->p_sys->o_glview container];
 
@@ -89,16 +94,19 @@ void cocoaglvoutviewEnd( vout_thread_t * p_vout )
     [p_vout->p_sys->o_glview detachFromVout];
     msg_Dbg( p_vout, "Mac OS X Vout is closing" );
 
-    /* Let the view go, _without_blocking_ */
-    [p_vout->p_sys->o_glview performSelectorOnMainThread:@selector(removeFromSuperview) withObject:NULL waitUntilDone:NO];
-
     if( [(id)o_cocoaglview_container respondsToSelector:@selector(removeVoutSubview:)] )
-        [o_cocoaglview_container removeVoutSubview: p_vout->p_sys->o_glview];
+        [o_cocoaglview_container performSelectorOnMainThread:@selector(removeVoutSubview:) withObject:p_vout->p_sys->o_glview waitUntilDone:NO];
+
+    /* Let the view go and release it, _without_blocking_ */
+    [p_vout->p_sys->o_glview performSelectorOnMainThread:@selector(removeFromSuperviewAndRelease) withObject:nil waitUntilDone:NO];
+    p_vout->p_sys->o_glview = nil;
 
-    [p_vout->p_sys->o_glview release];
+    /* Release the container now that we don't use it */
+    [o_cocoaglview_container performSelectorOnMainThread:@selector(release) withObject:nil waitUntilDone:NO];
 
     [p_vout->p_sys->o_pool release];
-    
+    p_vout->p_sys->o_pool = nil;
 }
 
 /*****************************************************************************
@@ -142,19 +150,17 @@ int cocoaglvoutviewManage( vout_thread_t * p_vout )
  *****************************************************************************/
 int cocoaglvoutviewControl( vout_thread_t *p_vout, int i_query, va_list args )
 {
-    vlc_bool_t b_arg;
+    bool b_arg;
 
     switch( i_query )
     {
         case VOUT_SET_STAY_ON_TOP:
-            b_arg = va_arg( args, vlc_bool_t );
+            b_arg = (bool) va_arg( args, int );
             [[p_vout->p_sys->o_glview container] setOnTop: b_arg];
             return VLC_SUCCESS;
 
-        case VOUT_CLOSE:
-        case VOUT_REPARENT:
         default:
-            return vout_vaControlDefault( p_vout, i_query, args );
+            return VLC_EGENERIC;
     }
 }
 
@@ -163,7 +169,7 @@ int cocoaglvoutviewControl( vout_thread_t *p_vout, int i_query, va_list args )
  *****************************************************************************/
 void cocoaglvoutviewSwap( vout_thread_t * p_vout )
 {
-    p_vout->p_sys->b_got_frame = VLC_TRUE;
+    p_vout->p_sys->b_got_frame = true;
     [[p_vout->p_sys->o_glview openGLContext] flushBuffer];
 }
 
@@ -217,16 +223,16 @@ void cocoaglvoutviewUnlock( vout_thread_t * p_vout )
 
 - (void)dealloc
 {
-    [objectLock dealloc]; 
+    [objectLock dealloc];
     [super dealloc];
 }
 
-- (void)removeFromSuperview
+- (void)removeFromSuperviewAndRelease
 {
-    [super removeFromSuperview];
+    [self removeFromSuperview];
+    [self release];
 }
 
-
 - (id) initWithVout: (vout_thread_t *) vout container: (id <VLCOpenGLVoutEmbedding>) aContainer
 {
     NSOpenGLPixelFormatAttribute attribs[] =
@@ -264,7 +270,7 @@ void cocoaglvoutviewUnlock( vout_thread_t * p_vout )
         /* Swap buffers only during the vertical retrace of the monitor.
         http://developer.apple.com/documentation/GraphicsImaging/
         Conceptual/OpenGL/chap5/chapter_5_section_44.html */
-        long params[] = { 1 };
+        GLint params[] = { 1 };
         CGLSetParameter( CGLGetCurrentContext(), kCGLCPSwapInterval,
                      params );
     }
@@ -288,9 +294,8 @@ void cocoaglvoutviewUnlock( vout_thread_t * p_vout )
     [objectLock lock];
     if( p_vout )
     {
-        vlc_object_detach( p_vout );
         vlc_object_release( p_vout );
-        vout_Destroy( (vout_thread_t *)p_vout );
+        vlc_object_release( p_vout );
     }
     [objectLock unlock];
 }
@@ -359,6 +364,8 @@ void cocoaglvoutviewUnlock( vout_thread_t * p_vout )
 
 - (void) update
 {
+    if (!p_vout)
+        return;
     if( kCGLNoError != CGLLockContext([[self openGLContext] CGLContextObj]) )
         return;
     [super update];
@@ -367,6 +374,8 @@ void cocoaglvoutviewUnlock( vout_thread_t * p_vout )
 
 - (void) drawRect: (NSRect) rect
 {
+    if (!p_vout)
+        return;
     if( kCGLNoError != CGLLockContext([[self openGLContext] CGLContextObj]) )
         return;
     [[self openGLContext] flushBuffer];