Commit 3c5c523f authored by Eric Petit's avatar Eric Petit

macosx/vout* : don't forget to exit fullscreen mode at EOF,

                fixed a segfault
parent c97ac86a
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* vout.h: MacOS X interface module * vout.h: MacOS X interface module
***************************************************************************** *****************************************************************************
* Copyright (C) 2001-2003 VideoLAN * Copyright (C) 2001-2003 VideoLAN
* $Id: vout.h,v 1.24 2004/02/25 19:27:23 titer Exp $ * $Id: vout.h,v 1.25 2004/02/28 13:53:35 titer Exp $
* *
* Authors: Colin Delacroix <colin@zoy.org> * Authors: Colin Delacroix <colin@zoy.org>
* Florian G. Pflug <fgp@phlo.org> * Florian G. Pflug <fgp@phlo.org>
...@@ -61,10 +61,11 @@ ...@@ -61,10 +61,11 @@
{ {
vout_thread_t * p_vout; vout_thread_t * p_vout;
int i_effect; int i_effect;
int b_init_done;
unsigned long i_texture; unsigned long i_texture;
float f_x; float f_x;
float f_y; float f_y;
int initDone;
int isFullScreen;
NSOpenGLContext * fullScreenContext; NSOpenGLContext * fullScreenContext;
NSOpenGLContext * currentContext; NSOpenGLContext * currentContext;
} }
...@@ -74,6 +75,7 @@ ...@@ -74,6 +75,7 @@
- (void) reloadTexture; - (void) reloadTexture;
- (void) goFullScreen; - (void) goFullScreen;
- (void) exitFullScreen; - (void) exitFullScreen;
- (void) cleanUp;
@end @end
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* vout.m: MacOS X video output module * vout.m: MacOS X video output module
***************************************************************************** *****************************************************************************
* Copyright (C) 2001-2003 VideoLAN * Copyright (C) 2001-2003 VideoLAN
* $Id: vout.m,v 1.84 2004/02/26 13:24:55 hartman Exp $ * $Id: vout.m,v 1.85 2004/02/28 13:53:35 titer Exp $
* *
* Authors: Colin Delacroix <colin@zoy.org> * Authors: Colin Delacroix <colin@zoy.org>
* Florian G. Pflug <fgp@phlo.org> * Florian G. Pflug <fgp@phlo.org>
...@@ -328,9 +328,9 @@ static int vout_Init( vout_thread_t *p_vout ) ...@@ -328,9 +328,9 @@ static int vout_Init( vout_thread_t *p_vout )
{ {
/* Nothing special to do, we just need a basic allocated /* Nothing special to do, we just need a basic allocated
picture_t */ picture_t */
vout_AllocatePicture( p_vout, p_pic, p_vout->output.i_chroma, vout_AllocatePicture( VLC_OBJECT( p_vout ), p_pic,
p_vout->output.i_width, p_vout->output.i_height, p_vout->output.i_chroma, p_vout->output.i_width,
p_vout->output.i_aspect ); p_vout->output.i_height, p_vout->output.i_aspect );
} }
p_pic->i_status = DESTROYED_PICTURE; p_pic->i_status = DESTROYED_PICTURE;
...@@ -345,6 +345,7 @@ static int vout_Init( vout_thread_t *p_vout ) ...@@ -345,6 +345,7 @@ static int vout_Init( vout_thread_t *p_vout )
{ {
[p_vout->p_sys->o_glview lockFocus]; [p_vout->p_sys->o_glview lockFocus];
[p_vout->p_sys->o_glview initTextures]; [p_vout->p_sys->o_glview initTextures];
[p_vout->p_sys->o_glview reshape];
[p_vout->p_sys->o_glview unlockFocus]; [p_vout->p_sys->o_glview unlockFocus];
} }
...@@ -362,6 +363,10 @@ static void vout_End( vout_thread_t *p_vout ) ...@@ -362,6 +363,10 @@ static void vout_End( vout_thread_t *p_vout )
{ {
QTDestroySequence( p_vout ); QTDestroySequence( p_vout );
} }
else
{
[p_vout->p_sys->o_glview cleanUp];
}
/* Free the direct buffers we allocated */ /* Free the direct buffers we allocated */
for( i_index = I_OUTPUTPICTURES; i_index; ) for( i_index = I_OUTPUTPICTURES; i_index; )
...@@ -1365,17 +1370,23 @@ static void QTFreePicture( vout_thread_t *p_vout, picture_t *p_pic ) ...@@ -1365,17 +1370,23 @@ static void QTFreePicture( vout_thread_t *p_vout, picture_t *p_pic )
glTranslatef( 0.0, 0.0, - 5.0 ); glTranslatef( 0.0, 0.0, - 5.0 );
} }
b_init_done = 0; i_texture = 0;
initDone = 0;
isFullScreen = 0;
return self; return self;
} }
- (void) reshape - (void) reshape
{ {
if( !initDone )
{
return;
}
[currentContext makeCurrentContext]; [currentContext makeCurrentContext];
NSRect bounds = [self bounds]; NSRect bounds = [self bounds];
glViewport( 0, 0, (GLint) bounds.size.width, glViewport( 0, 0, (GLint) bounds.size.width,
(GLint) bounds.size.height ); (GLint) bounds.size.height );
...@@ -1385,10 +1396,10 @@ static void QTFreePicture( vout_thread_t *p_vout, picture_t *p_pic ) ...@@ -1385,10 +1396,10 @@ static void QTFreePicture( vout_thread_t *p_vout, picture_t *p_pic )
f_x = 1.0; f_x = 1.0;
f_y = 1.0; f_y = 1.0;
} }
else if( bounds.size.height * p_vout->render.i_aspect < else if( bounds.size.height * p_vout->output.i_aspect <
bounds.size.width * VOUT_ASPECT_FACTOR ) bounds.size.width * VOUT_ASPECT_FACTOR )
{ {
f_x = bounds.size.height * p_vout->render.i_aspect / f_x = bounds.size.height * p_vout->output.i_aspect /
VOUT_ASPECT_FACTOR / bounds.size.width; VOUT_ASPECT_FACTOR / bounds.size.width;
f_y = 1.0; f_y = 1.0;
} }
...@@ -1396,7 +1407,7 @@ static void QTFreePicture( vout_thread_t *p_vout, picture_t *p_pic ) ...@@ -1396,7 +1407,7 @@ static void QTFreePicture( vout_thread_t *p_vout, picture_t *p_pic )
{ {
f_x = 1.0; f_x = 1.0;
f_y = bounds.size.width * VOUT_ASPECT_FACTOR / f_y = bounds.size.width * VOUT_ASPECT_FACTOR /
p_vout->render.i_aspect / bounds.size.height; p_vout->output.i_aspect / bounds.size.height;
} }
} }
...@@ -1404,6 +1415,12 @@ static void QTFreePicture( vout_thread_t *p_vout, picture_t *p_pic ) ...@@ -1404,6 +1415,12 @@ static void QTFreePicture( vout_thread_t *p_vout, picture_t *p_pic )
{ {
[currentContext makeCurrentContext]; [currentContext makeCurrentContext];
/* Free previous texture if any */
if( i_texture )
{
glDeleteTextures( 1, &i_texture );
}
/* Create textures */ /* Create textures */
glGenTextures( 1, &i_texture ); glGenTextures( 1, &i_texture );
...@@ -1439,11 +1456,16 @@ static void QTFreePicture( vout_thread_t *p_vout, picture_t *p_pic ) ...@@ -1439,11 +1456,16 @@ static void QTFreePicture( vout_thread_t *p_vout, picture_t *p_pic )
GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_APPLE, GL_YCBCR_422_APPLE, GL_UNSIGNED_SHORT_8_8_APPLE,
PP_OUTPUTPICTURE[0]->p_data ); PP_OUTPUTPICTURE[0]->p_data );
b_init_done = 1; initDone = 1;
} }
- (void) reloadTexture - (void) reloadTexture
{ {
if( !initDone )
{
return;
}
[currentContext makeCurrentContext]; [currentContext makeCurrentContext];
glBindTexture( GL_TEXTURE_RECTANGLE_EXT, i_texture ); glBindTexture( GL_TEXTURE_RECTANGLE_EXT, i_texture );
...@@ -1459,6 +1481,7 @@ static void QTFreePicture( vout_thread_t *p_vout, picture_t *p_pic ) ...@@ -1459,6 +1481,7 @@ static void QTFreePicture( vout_thread_t *p_vout, picture_t *p_pic )
- (void) goFullScreen - (void) goFullScreen
{ {
/* Create the new pixel format */
NSOpenGLPixelFormatAttribute attribs[] = NSOpenGLPixelFormatAttribute attribs[] =
{ {
NSOpenGLPFAAccelerated, NSOpenGLPFAAccelerated,
...@@ -1469,47 +1492,47 @@ static void QTFreePicture( vout_thread_t *p_vout, picture_t *p_pic ) ...@@ -1469,47 +1492,47 @@ static void QTFreePicture( vout_thread_t *p_vout, picture_t *p_pic )
NSOpenGLPFADepthSize, 24, NSOpenGLPFADepthSize, 24,
NSOpenGLPFAFullScreen, NSOpenGLPFAFullScreen,
NSOpenGLPFAScreenMask, NSOpenGLPFAScreenMask,
/* TODO handle macosxx-vdev */
CGDisplayIDToOpenGLDisplayMask( kCGDirectMainDisplay ), CGDisplayIDToOpenGLDisplayMask( kCGDirectMainDisplay ),
0 0
}; };
NSOpenGLPixelFormat * fmt = [[NSOpenGLPixelFormat alloc] NSOpenGLPixelFormat * fmt = [[NSOpenGLPixelFormat alloc]
initWithAttributes: attribs]; initWithAttributes: attribs];
if( !fmt ) if( !fmt )
{ {
msg_Warn( p_vout, "Cannot create NSOpenGLPixelFormat" ); msg_Warn( p_vout, "Cannot create NSOpenGLPixelFormat" );
return; return;
} }
/* Create the new OpenGL context */
fullScreenContext = [[NSOpenGLContext alloc] fullScreenContext = [[NSOpenGLContext alloc]
initWithFormat: fmt shareContext: [self openGLContext]]; initWithFormat: fmt shareContext: nil];
if( !fullScreenContext ) if( !fullScreenContext )
{ {
msg_Warn( p_vout, "Failed to create new NSOpenGLContext" ); msg_Warn( p_vout, "Failed to create new NSOpenGLContext" );
return; return;
} }
currentContext = fullScreenContext; currentContext = fullScreenContext;
/* Capture display, switch to fullscreen */
if( CGCaptureAllDisplays() != CGDisplayNoErr ) if( CGCaptureAllDisplays() != CGDisplayNoErr )
{ {
msg_Warn( p_vout, "CGCaptureAllDisplays() failed" ); msg_Warn( p_vout, "CGCaptureAllDisplays() failed" );
return; return;
} }
[fullScreenContext setFullScreen]; [fullScreenContext setFullScreen];
[fullScreenContext makeCurrentContext]; [fullScreenContext makeCurrentContext];
/* Fix ratio */
unsigned width = CGDisplayPixelsWide( kCGDirectMainDisplay ); unsigned width = CGDisplayPixelsWide( kCGDirectMainDisplay );
unsigned height = CGDisplayPixelsHigh( kCGDirectMainDisplay ); unsigned height = CGDisplayPixelsHigh( kCGDirectMainDisplay );
if( config_GetInt( p_vout, "macosx-stretch" ) ) if( config_GetInt( p_vout, "macosx-stretch" ) )
{ {
f_x = 1.0; f_x = 1.0;
f_y = 1.0; f_y = 1.0;
} }
else if( height * p_vout->output.i_aspect < width * VOUT_ASPECT_FACTOR ) else if( height * p_vout->output.i_aspect <
width * VOUT_ASPECT_FACTOR )
{ {
f_x = (float) height * p_vout->output.i_aspect / f_x = (float) height * p_vout->output.i_aspect /
width / VOUT_ASPECT_FACTOR; width / VOUT_ASPECT_FACTOR;
...@@ -1521,18 +1544,42 @@ static void QTFreePicture( vout_thread_t *p_vout, picture_t *p_pic ) ...@@ -1521,18 +1544,42 @@ static void QTFreePicture( vout_thread_t *p_vout, picture_t *p_pic )
f_y = (float) width * VOUT_ASPECT_FACTOR / f_y = (float) width * VOUT_ASPECT_FACTOR /
p_vout->output.i_aspect / height; p_vout->output.i_aspect / height;
} }
/* Update viewport, re-init textures */
glViewport( 0, 0, width, height ); glViewport( 0, 0, width, height );
[self initTextures]; [self initTextures];
/* Redraw the last picture */
[self setNeedsDisplay: YES];
isFullScreen = 1;
} }
- (void) exitFullScreen - (void) exitFullScreen
{ {
/* Free current OpenGL context */
[NSOpenGLContext clearCurrentContext]; [NSOpenGLContext clearCurrentContext];
[fullScreenContext clearDrawable]; [fullScreenContext clearDrawable];
[fullScreenContext release]; [fullScreenContext release];
CGReleaseAllDisplays(); CGReleaseAllDisplays();
currentContext = [self openGLContext]; currentContext = [self openGLContext];
[self initTextures];
[self reshape]; [self reshape];
/* Redraw the last picture */
[self setNeedsDisplay: YES];
isFullScreen = 0;
}
- (void) cleanUp
{
if( isFullScreen )
{
[self exitFullScreen];
}
initDone = 0;
} }
- (void) drawQuad - (void) drawQuad
...@@ -1639,7 +1686,7 @@ static void QTFreePicture( vout_thread_t *p_vout, picture_t *p_pic ) ...@@ -1639,7 +1686,7 @@ static void QTFreePicture( vout_thread_t *p_vout, picture_t *p_pic )
/* Black background */ /* Black background */
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
if( !b_init_done ) if( !initDone )
{ {
[currentContext flushBuffer]; [currentContext flushBuffer];
return; return;
......
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