Commit 40792ebd authored by Pierre d'Herbemont's avatar Pierre d'Herbemont

Mac OS X gui: Comply to "Cocoa Thread Safety" guideline, that is, make...

Mac OS X gui: Comply to "Cocoa Thread Safety" guideline, that is, make creating, resizing, closing, the NSView on main thread.
parent ddb469c7
...@@ -757,13 +757,13 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable, ...@@ -757,13 +757,13 @@ int DeviceCallback( vlc_object_t *p_this, const char *psz_variable,
- (void)enterFullscreen - (void)enterFullscreen
{ {
[[o_view class] resetVout: p_vout]; [[o_view class] performSelectorOnMainThread:@selector(resetVout:) withObject:[NSValue valueWithPointer:p_vout] waitUntilDone:YES];
[[[[VLCMain sharedInstance] getControls] getFSPanel] setActive: nil]; [[[[VLCMain sharedInstance] getControls] getFSPanel] setActive: nil];
} }
- (void)leaveFullscreen - (void)leaveFullscreen
{ {
[[o_view class] resetVout: p_vout]; [[o_view class] performSelectorOnMainThread:@selector(resetVout:) withObject:[NSValue valueWithPointer:p_vout] waitUntilDone:YES];
[[[[VLCMain sharedInstance] getControls] getFSPanel] setNonActive: nil]; [[[[VLCMain sharedInstance] getControls] getFSPanel] setNonActive: nil];
} }
......
...@@ -171,19 +171,15 @@ int E_(OpenVideoGL) ( vlc_object_t * p_this ) ...@@ -171,19 +171,15 @@ int E_(OpenVideoGL) ( vlc_object_t * p_this )
{ {
p_vout->p_sys->b_embedded = VLC_FALSE; p_vout->p_sys->b_embedded = VLC_FALSE;
p_vout->p_sys->o_pool = [[NSAutoreleasePool alloc] init]; [VLCGLView performSelectorOnMainThread:@selector(initVout:) withObject:[NSValue valueWithPointer:p_vout] waitUntilDone:YES];
/* Create the GL view */ /* Check to see if fillVoutWithNewView: was successfull */
p_vout->p_sys->o_glview = [[VLCGLView alloc] initWithVout: p_vout];
[p_vout->p_sys->o_glview autorelease];
/* Spawn the window */ if( !p_vout->p_sys->o_vout_view )
if( !(p_vout->p_sys->o_vout_view = [VLCVoutView getVoutView: p_vout
subView: p_vout->p_sys->o_glview frame: nil]) )
{ {
return VLC_EGENERIC; return VLC_EGENERIC;
} }
p_vout->pf_init = Init; p_vout->pf_init = Init;
p_vout->pf_end = End; p_vout->pf_end = End;
p_vout->pf_manage = Manage; p_vout->pf_manage = Manage;
...@@ -209,7 +205,7 @@ void E_(CloseVideoGL) ( vlc_object_t * p_this ) ...@@ -209,7 +205,7 @@ void E_(CloseVideoGL) ( vlc_object_t * p_this )
NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init]; NSAutoreleasePool *o_pool = [[NSAutoreleasePool alloc] init];
/* Close the window */ /* Close the window */
[p_vout->p_sys->o_vout_view closeVout]; [p_vout->p_sys->o_vout_view performSelectorOnMainThread:@selector(closeVout) withObject:NULL waitUntilDone:YES];
[o_pool release]; [o_pool release];
} }
...@@ -307,10 +303,24 @@ static void Unlock( vout_thread_t * p_vout ) ...@@ -307,10 +303,24 @@ static void Unlock( vout_thread_t * p_vout )
* VLCGLView implementation * VLCGLView implementation
*****************************************************************************/ *****************************************************************************/
@implementation VLCGLView @implementation VLCGLView
+ (void)initVout:(NSValue *)arg
{
vout_thread_t * p_vout = [arg pointerValue];
/* 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->o_vout_view = [VLCVoutView getVoutView: p_vout
subView: p_vout->p_sys->o_glview frame: nil];
}
/* This function will reset the o_vout_view. It's useful to go fullscreen. */ /* This function will reset the o_vout_view. It's useful to go fullscreen. */
+ (void)resetVout: (vout_thread_t *)p_vout + (void)resetVout:(NSData *)arg
{ {
vout_thread_t * p_vout = [arg pointerValue];
if( p_vout->b_fullscreen ) if( p_vout->b_fullscreen )
{ {
/* Save window size and position */ /* Save window size and position */
...@@ -344,6 +354,13 @@ static void Unlock( vout_thread_t * p_vout ) ...@@ -344,6 +354,13 @@ static void Unlock( vout_thread_t * p_vout )
- (id) initWithVout: (vout_thread_t *) vout - (id) initWithVout: (vout_thread_t *) vout
{ {
/* Must be called from main thread:
* "The NSView class is generally thread-safe, with a few exceptions. You
* should create, destroy, resize, move, and perform other operations on NSView
* objects only from the main thread of an application. Drawing from secondary
* threads is thread-safe as long as you bracket drawing calls with calls to
* lockFocusIfCanDraw and unlockFocus." Cocoa Thread Safety */
p_vout = vout; p_vout = vout;
NSOpenGLPixelFormatAttribute attribs[] = NSOpenGLPixelFormatAttribute attribs[] =
...@@ -418,6 +435,8 @@ static void Unlock( vout_thread_t * p_vout ) ...@@ -418,6 +435,8 @@ static void Unlock( vout_thread_t * p_vout )
glViewport( ( bounds.size.width - x ) / 2, glViewport( ( bounds.size.width - x ) / 2,
( bounds.size.height - y ) / 2, x, y ); ( bounds.size.height - y ) / 2, x, y );
[super reshape];
if( p_vout->p_sys->b_got_frame ) if( p_vout->p_sys->b_got_frame )
{ {
/* Ask the opengl module to redraw */ /* Ask the opengl module to redraw */
...@@ -434,7 +453,6 @@ static void Unlock( vout_thread_t * p_vout ) ...@@ -434,7 +453,6 @@ static void Unlock( vout_thread_t * p_vout )
glClear( GL_COLOR_BUFFER_BIT ); glClear( GL_COLOR_BUFFER_BIT );
Unlock( p_vout ); Unlock( p_vout );
} }
[super reshape];
} }
- (void) update - (void) update
......
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