Commit 4416dfe8 authored by Eric Petit's avatar Eric Petit

macosx/vout*: also destroy the window and attach/detach the view on the

  main thread (one more step to hopefully fix #45)
 macosx/controls.m: fixed a tiny memleak
parent 3ad73201
......@@ -690,6 +690,7 @@
- (void)dealloc
{
free( psz_name );
[super dealloc];
}
- (char *)name
......
......@@ -30,17 +30,20 @@
@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;
......
......@@ -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];
......
......@@ -48,11 +48,9 @@
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];
......
......@@ -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];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment