Commit 6a39fbbf authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Backport [22107] and [25067] MIT-SHM fixes.

parent fdbd6574
...@@ -107,7 +107,7 @@ static IMAGE_TYPE *CreateImage ( vout_thread_t *, ...@@ -107,7 +107,7 @@ static IMAGE_TYPE *CreateImage ( vout_thread_t *,
#ifdef HAVE_SYS_SHM_H #ifdef HAVE_SYS_SHM_H
static IMAGE_TYPE *CreateShmImage ( vout_thread_t *, static IMAGE_TYPE *CreateShmImage ( vout_thread_t *,
Display *, EXTRA_ARGS_SHM, int, int ); Display *, EXTRA_ARGS_SHM, int, int );
static vlc_bool_t b_shm = VLC_TRUE; static int i_shm_major = 0;
#endif #endif
static void ToggleFullScreen ( vout_thread_t * ); static void ToggleFullScreen ( vout_thread_t * );
...@@ -507,7 +507,7 @@ static void DisplayVideo( vout_thread_t *p_vout, picture_t *p_pic ) ...@@ -507,7 +507,7 @@ static void DisplayVideo( vout_thread_t *p_vout, picture_t *p_pic )
vlc_mutex_lock( &p_vout->p_sys->lock ); vlc_mutex_lock( &p_vout->p_sys->lock );
#ifdef HAVE_SYS_SHM_H #ifdef HAVE_SYS_SHM_H
if( p_vout->p_sys->b_shm ) if( p_vout->p_sys->i_shm_opcode )
{ {
/* Display rendered image using shared memory extension */ /* Display rendered image using shared memory extension */
# ifdef MODULE_NAME_IS_xvideo # ifdef MODULE_NAME_IS_xvideo
...@@ -1322,7 +1322,7 @@ static int NewPicture( vout_thread_t *p_vout, picture_t *p_pic ) ...@@ -1322,7 +1322,7 @@ static int NewPicture( vout_thread_t *p_vout, picture_t *p_pic )
p_vout->output.i_aspect ); p_vout->output.i_aspect );
#ifdef HAVE_SYS_SHM_H #ifdef HAVE_SYS_SHM_H
if( p_vout->p_sys->b_shm ) if( p_vout->p_sys->i_shm_opcode )
{ {
/* Create image using XShm extension */ /* Create image using XShm extension */
p_pic->p_sys->p_image = p_pic->p_sys->p_image =
...@@ -1338,7 +1338,7 @@ static int NewPicture( vout_thread_t *p_vout, picture_t *p_pic ) ...@@ -1338,7 +1338,7 @@ static int NewPicture( vout_thread_t *p_vout, picture_t *p_pic )
p_vout->output.i_width, p_vout->output.i_height ); p_vout->output.i_width, p_vout->output.i_height );
} }
if( !p_vout->p_sys->b_shm || !p_pic->p_sys->p_image ) if( !p_vout->p_sys->i_shm_opcode || !p_pic->p_sys->p_image )
#endif /* HAVE_SYS_SHM_H */ #endif /* HAVE_SYS_SHM_H */
{ {
/* Create image without XShm extension */ /* Create image without XShm extension */
...@@ -1356,10 +1356,10 @@ static int NewPicture( vout_thread_t *p_vout, picture_t *p_pic ) ...@@ -1356,10 +1356,10 @@ static int NewPicture( vout_thread_t *p_vout, picture_t *p_pic )
p_vout->output.i_width, p_vout->output.i_height ); p_vout->output.i_width, p_vout->output.i_height );
#ifdef HAVE_SYS_SHM_H #ifdef HAVE_SYS_SHM_H
if( p_pic->p_sys->p_image && p_vout->p_sys->b_shm ) if( p_pic->p_sys->p_image && p_vout->p_sys->i_shm_opcode )
{ {
msg_Warn( p_vout, "couldn't create SHM image, disabling SHM" ); msg_Warn( p_vout, "couldn't create SHM image, disabling SHM" );
p_vout->p_sys->b_shm = VLC_FALSE; p_vout->p_sys->i_shm_opcode = 0;
} }
#endif /* HAVE_SYS_SHM_H */ #endif /* HAVE_SYS_SHM_H */
} }
...@@ -1449,7 +1449,7 @@ static void FreePicture( vout_thread_t *p_vout, picture_t *p_pic ) ...@@ -1449,7 +1449,7 @@ static void FreePicture( vout_thread_t *p_vout, picture_t *p_pic )
{ {
/* The order of operations is correct */ /* The order of operations is correct */
#ifdef HAVE_SYS_SHM_H #ifdef HAVE_SYS_SHM_H
if( p_vout->p_sys->b_shm ) if( p_vout->p_sys->i_shm_opcode )
{ {
XShmDetach( p_vout->p_sys->p_display, &p_pic->p_sys->shminfo ); XShmDetach( p_vout->p_sys->p_display, &p_pic->p_sys->shminfo );
IMAGE_FREE( p_pic->p_sys->p_image ); IMAGE_FREE( p_pic->p_sys->p_image );
...@@ -2032,18 +2032,36 @@ static int InitDisplay( vout_thread_t *p_vout ) ...@@ -2032,18 +2032,36 @@ static int InitDisplay( vout_thread_t *p_vout )
#endif #endif
#ifdef HAVE_SYS_SHM_H #ifdef HAVE_SYS_SHM_H
p_vout->p_sys->b_shm = 0; p_vout->p_sys->i_shm_opcode = 0;
if( config_GetInt( p_vout, MODULE_STRING "-shm" ) ) if( config_GetInt( p_vout, MODULE_STRING "-shm" ) )
{ {
# ifdef __APPLE__ # ifdef __APPLE__
/* FIXME: As of 2001-03-16, XFree4 for MacOS X does not support Xshm */ /* FIXME: As of 2001-03-16, XFree4 for MacOS X does not support Xshm */
# else # else
p_vout->p_sys->b_shm = int major, evt, err;
( XShmQueryExtension( p_vout->p_sys->p_display ) == True );
if( XQueryExtension( p_vout->p_sys->p_display, "MIT-SHM", &major,
&evt, &err )
&& XShmQueryExtension( p_vout->p_sys->p_display ) )
p_vout->p_sys->i_shm_opcode = major;
if( p_vout->p_sys->i_shm_opcode )
{
int major, minor;
Bool pixmaps;
XShmQueryVersion( p_vout->p_sys->p_display, &major, &minor,
&pixmaps );
msg_Dbg( p_vout, "XShm video extension v%d.%d "
"(with%s pixmaps, opcode: %d)",
major, minor, pixmaps ? "" : "out",
p_vout->p_sys->i_shm_opcode );
}
# endif # endif
if( !p_vout->p_sys->b_shm ) if( !p_vout->p_sys->i_shm_opcode )
{ {
msg_Warn( p_vout, "XShm video extension is unavailable" ); msg_Warn( p_vout, "XShm video extension is unavailable" );
} }
...@@ -2222,9 +2240,9 @@ static IMAGE_TYPE * CreateShmImage( vout_thread_t *p_vout, ...@@ -2222,9 +2240,9 @@ static IMAGE_TYPE * CreateShmImage( vout_thread_t *p_vout,
/* Attach shared memory segment to X server */ /* Attach shared memory segment to X server */
XSynchronize( p_display, True ); XSynchronize( p_display, True );
b_shm = VLC_TRUE; i_shm_major = p_vout->p_sys->i_shm_opcode;
result = XShmAttach( p_display, p_shm ); result = XShmAttach( p_display, p_shm );
if( result == False || !b_shm ) if( result == False || !i_shm_major )
{ {
msg_Err( p_vout, "cannot attach shared memory to X server" ); msg_Err( p_vout, "cannot attach shared memory to X server" );
IMAGE_FREE( p_image ); IMAGE_FREE( p_image );
...@@ -2329,17 +2347,11 @@ static int X11ErrorHandler( Display * display, XErrorEvent * event ) ...@@ -2329,17 +2347,11 @@ static int X11ErrorHandler( Display * display, XErrorEvent * event )
/* Ingnore errors on XSetInputFocus() /* Ingnore errors on XSetInputFocus()
* (they happen when a window is not yet mapped) */ * (they happen when a window is not yet mapped) */
return 0; return 0;
case 150: /* MIT-SHM */
case 146: /* MIT-SHM too, what gives? */
if( event->minor_code == X_ShmAttach )
{
b_shm = VLC_FALSE;
return 0;
}
break;
} }
if( event->request_code == i_shm_major ) /* MIT-SHM */
return i_shm_major = 0;
XSetErrorHandler(NULL); XSetErrorHandler(NULL);
return (XSetErrorHandler(X11ErrorHandler))( display, event ); return (XSetErrorHandler(X11ErrorHandler))( display, event );
} }
......
...@@ -103,7 +103,7 @@ struct vout_sys_t ...@@ -103,7 +103,7 @@ struct vout_sys_t
/* X11 generic properties */ /* X11 generic properties */
vlc_bool_t b_altfullscreen; /* which fullscreen method */ vlc_bool_t b_altfullscreen; /* which fullscreen method */
#ifdef HAVE_SYS_SHM_H #ifdef HAVE_SYS_SHM_H
vlc_bool_t b_shm; /* shared memory extension flag */ int i_shm_opcode; /* shared memory extension opcode */
#endif #endif
#ifdef MODULE_NAME_IS_xvideo #ifdef MODULE_NAME_IS_xvideo
......
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