]> git.sesse.net Git - vlc/commitdiff
macosx/vout*: also destroy the window and attach/detach the view on the
authorEric Petit <titer@videolan.org>
Sat, 4 Jun 2005 15:07:03 +0000 (15:07 +0000)
committerEric Petit <titer@videolan.org>
Sat, 4 Jun 2005 15:07:03 +0000 (15:07 +0000)
  main thread (one more step to hopefully fix #45)
 macosx/controls.m: fixed a tiny memleak

modules/gui/macosx/controls.m
modules/gui/macosx/vout.h
modules/gui/macosx/vout.m
modules/gui/macosx/voutgl.m
modules/gui/macosx/voutqt.m

index ebddcefc1fe8b1739a207366c9fe1946220d5b8d..f4af6f47b1a997b2b5be820973fbc75a8eb145f5 100644 (file)
 - (void)dealloc
 {
     free( psz_name );
+    [super dealloc];
 }
 
 - (char *)name
index e2babf1bf6cc2caa145587ab6a5c9b7a219eea47..ea39ac4fc45b3dce8557604a32fac2956a91b364 100644 (file)
 @interface VLCWindow : NSWindow
 {
     vout_thread_t * p_vout;
-    vout_thread_t * p_real_vout;
+    NSView        * o_view;
+    NSRect        * s_frame;
 
+    vout_thread_t * p_real_vout;
     Ptr             p_fullscreen_state;
     mtime_t         i_time_mouse_last_moved;
-    NSRect        * s_frame;
     vlc_bool_t      b_init_ok;
 }
 
-- (id) initWithVout: (vout_thread_t *) p_vout frame: (NSRect *) s_frame;
+- (id) initWithVout: (vout_thread_t *) p_vout view: (NSView *) view
+                     frame: (NSRect *) s_frame;
 - (id) initReal: (id) sender;
-- (void)close;
+- (void) close;
+- (id)   closeReal: (id) sender;
 - (void)setOnTop:(BOOL)b_on_top;
 
 - (void)hideMouse:(BOOL)b_hide;
index 9bfc0075f6d095f3e22a797e82c22f1fe660bf0d..bc49b8910d49dc528f8e220a4558a488bdb057e3 100644 (file)
@@ -65,20 +65,15 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
  *****************************************************************************/
 @implementation VLCWindow
 
-- (id) initWithVout: (vout_thread_t *) vout frame: (NSRect *) frame
+- (id) initWithVout: (vout_thread_t *) vout view: (NSView *) view
+                     frame: (NSRect *) frame
 {
     p_vout  = vout;
+    o_view  = view;
     s_frame = frame;
 
-    if( MACOS_VERSION >= 10.2 )
-    {
-        [self performSelectorOnMainThread: @selector(initReal:)
-            withObject: NULL waitUntilDone: YES];
-    }
-    else
-    {
-        [self initReal: NULL];
-    }
+    [self performSelectorOnMainThread: @selector(initReal:)
+        withObject: NULL waitUntilDone: YES];
 
     if( !b_init_ok )
     {
@@ -282,6 +277,9 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
     /* We'll catch mouse events */
     [self setAcceptsMouseMovedEvents: YES];
     [self makeFirstResponder: self];
+
+    /* Add the view. It's automatically resized to fit the window */
+    [self setContentView: o_view];
     
     [o_pool release];
 
@@ -289,13 +287,22 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
     return self;
 }
 
-- (void)close
+- (void) close
+{
+    /* XXX waitUntilDone = NO to avoid a possible deadlock when hitting
+       Command-Q */
+    [self performSelectorOnMainThread: @selector(closeReal:)
+        withObject: NULL waitUntilDone: NO];
+}
+
+- (id) closeReal: (id) sender
 {
     [super close];
     if( p_fullscreen_state )
     {
         EndFullScreen( p_fullscreen_state, 0 );
     }
+    return NULL;
 }
 
 - (void)setOnTop:(BOOL)b_on_top
@@ -701,11 +708,9 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
     NSPoint ml;
     NSRect s_rect;
     BOOL b_inside;
-    NSView * o_view;
 
     i_time_mouse_last_moved = mdate();
 
-    o_view = [self contentView];
     s_rect = [o_view bounds];
     ml = [o_view convertPoint: [o_event locationInWindow] fromView: nil];
     b_inside = [o_view mouse: ml inRect: s_rect];
index 365c3cdf0c6e19e6ec46db4f421a83e27ff74e1e..45041634812841ff71d52f3117524f41abc421a3 100644 (file)
     vout_thread_t * p_vout;
 }
 
-- (id)initWithFrame: (NSRect) frame vout: (vout_thread_t*) p_vout;
-
+- (id) initWithVout: (vout_thread_t *) p_vout;
 @end
 
-
 struct vout_sys_t
 {
     NSAutoreleasePool * o_pool;
@@ -99,23 +97,19 @@ int E_(OpenVideoGL)  ( vlc_object_t * p_this )
     p_vout->p_sys->o_pool = [[NSAutoreleasePool alloc] init];
     vlc_mutex_init( p_vout, &p_vout->p_sys->lock );
 
-    /* Spawn window */
+    /* Create the GL view */
+    p_vout->p_sys->o_glview = [[VLCGLView alloc] initWithVout: p_vout];
+    [p_vout->p_sys->o_glview autorelease];
+
+    /* Spawn the window */
     p_vout->p_sys->b_got_frame = VLC_FALSE;
     p_vout->p_sys->o_window = [[VLCWindow alloc] initWithVout: p_vout
-                                                 frame: nil];
+        view: p_vout->p_sys->o_glview frame: nil];
     if( !p_vout->p_sys->o_window )
     {
         return VLC_EGENERIC;
     }
 
-    /* Add OpenGL view */
-#define o_glview p_vout->p_sys->o_glview
-    o_glview = [[VLCGLView alloc] initWithFrame:
-                [p_vout->p_sys->o_window frame] vout: p_vout];
-    [p_vout->p_sys->o_window setContentView: o_glview];
-    [o_glview autorelease];
-#undef o_glview
-
     p_vout->pf_init   = Init;
     p_vout->pf_end    = End;
     p_vout->pf_manage = Manage;
@@ -132,12 +126,6 @@ void E_(CloseVideoGL) ( vlc_object_t * p_this )
     vout_thread_t * p_vout = (vout_thread_t *) p_this;
     NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
 
-    /* Remove the GLView from the window, because we are not sure OS X
-       will actually close the window right away. When it doesn't,
-       VLCGLView's reshape is called while p_vout and p_vout->p_sys
-       aren't valid anymore and crashes. */
-    [p_vout->p_sys->o_window setContentView: NULL];
-
     /* Close the window */
     [p_vout->p_sys->o_window close];
 
@@ -177,23 +165,25 @@ static int Manage( vout_thread_t * p_vout )
 
         p_vout->b_fullscreen = !p_vout->b_fullscreen;
 
+#define o_glview p_vout->p_sys->o_glview
+        o_glview = [[VLCGLView alloc] initWithVout: p_vout];
+        [o_glview autorelease];
+
         if( p_vout->p_sys->b_saved_frame )
         {
             p_vout->p_sys->o_window = [[VLCWindow alloc]
-                initWithVout: p_vout frame: &p_vout->p_sys->s_frame];
+                initWithVout: p_vout view: o_glview
+                frame: &p_vout->p_sys->s_frame];
         }
         else
         {
             p_vout->p_sys->o_window = [[VLCWindow alloc]
-                initWithVout: p_vout frame: nil];
+                initWithVout: p_vout view: o_glview frame: nil];
         }
 
-#define o_glview p_vout->p_sys->o_glview
-        o_glview = [[VLCGLView alloc] initWithFrame: [p_vout->p_sys->o_window frame] vout: p_vout];
-        [p_vout->p_sys->o_window setContentView: o_glview];
-        [o_glview autorelease];
         [[o_glview openGLContext] makeCurrentContext];
 #undef o_glview
+
         [o_pool release];
 
         p_vout->i_changes &= ~VOUT_FULLSCREEN_CHANGE;
@@ -246,9 +236,9 @@ static void Unlock( vout_thread_t * p_vout )
  *****************************************************************************/
 @implementation VLCGLView
 
-- (id) initWithFrame: (NSRect) frame vout: (vout_thread_t*) _p_vout
+- (id) initWithVout: (vout_thread_t *) vout
 {
-    p_vout = _p_vout;
+    p_vout = vout;
 
     NSOpenGLPixelFormatAttribute attribs[] =
     {
@@ -270,7 +260,7 @@ static void Unlock( vout_thread_t * p_vout )
         return nil;
     }
 
-    self = [super initWithFrame:frame pixelFormat: fmt];
+    self = [super initWithFrame: NSMakeRect(0,0,10,10) pixelFormat: fmt];
     [fmt release];
 
     [[self openGLContext] makeCurrentContext];
index 56ecfc0d6dec4a04833756ea82add84568ecf4a3..9208f8524767cda7704f3949921a19f592eee4c9 100644 (file)
@@ -140,25 +140,6 @@ int E_(OpenVideoQT) ( vlc_object_t *p_this )
     else
         p_vout->p_sys->b_embedded = VLC_FALSE;
 
-    if( p_vout->p_sys->b_embedded )
-    {
-        /* Zero the clipping rectangle */
-        p_vout->p_sys->clipping_rect.left = 0;
-        p_vout->p_sys->clipping_rect.right = 0;
-        p_vout->p_sys->clipping_rect.top = 0;
-        p_vout->p_sys->clipping_rect.bottom = 0;
-    }
-    else
-    {
-        /* Spawn window */
-        p_vout->p_sys->o_window =
-            [[VLCWindow alloc] initWithVout: p_vout frame: nil];
-        if( !p_vout->p_sys->o_window )
-        {
-            return VLC_EGENERIC;
-        }
-    }
-
     p_vout->p_sys->b_altivec = p_vout->p_libvlc->i_cpu & CPU_CAPABILITY_ALTIVEC;
     msg_Dbg( p_vout, "We do%s have Altivec", p_vout->p_sys->b_altivec ? "" : "n't" );
     
@@ -221,9 +202,27 @@ int E_(OpenVideoQT) ( vlc_object_t *p_this )
 
 #define o_qtview p_vout->p_sys->o_qtview
     o_qtview = [[VLCQTView alloc] initWithVout: p_vout];
-    [p_vout->p_sys->o_window setContentView: o_qtview];
     [o_qtview autorelease];
 
+    if( p_vout->p_sys->b_embedded )
+    {
+        /* Zero the clipping rectangle */
+        p_vout->p_sys->clipping_rect.left = 0;
+        p_vout->p_sys->clipping_rect.right = 0;
+        p_vout->p_sys->clipping_rect.top = 0;
+        p_vout->p_sys->clipping_rect.bottom = 0;
+    }
+    else
+    {
+        /* Spawn window */
+        p_vout->p_sys->o_window = [[VLCWindow alloc]
+            initWithVout: p_vout view: o_qtview frame: nil];
+        if( !p_vout->p_sys->o_window )
+        {
+            return VLC_EGENERIC;
+        }
+    }
+
     /* Retrieve the QuickDraw port */
     if( p_vout->p_sys->b_embedded )
     {
@@ -498,22 +497,22 @@ static int CoToggleFullscreen( vout_thread_t *p_vout )
 
     p_vout->b_fullscreen = !p_vout->b_fullscreen;
 
+#define o_qtview p_vout->p_sys->o_qtview
+    o_qtview = [[VLCQTView alloc] initWithVout: p_vout];
+    [o_qtview autorelease];
+    
     if( p_vout->p_sys->b_saved_frame )
     {
         p_vout->p_sys->o_window = [[VLCWindow alloc]
-            initWithVout: p_vout frame: &p_vout->p_sys->s_frame];
+            initWithVout: p_vout view: o_qtview
+            frame: &p_vout->p_sys->s_frame];
     }
     else
     {
         p_vout->p_sys->o_window = [[VLCWindow alloc]
-            initWithVout: p_vout frame: nil];
+            initWithVout: p_vout view: o_qtview frame: nil];
     }
 
-#define o_qtview p_vout->p_sys->o_qtview
-    o_qtview = [[VLCQTView alloc] initWithVout: p_vout];
-    [p_vout->p_sys->o_window setContentView: o_qtview];
-    [o_qtview autorelease];
-
     /* Retrieve the QuickDraw port */
     [o_qtview lockFocus];
     p_vout->p_sys->p_qdport = [o_qtview qdPort];