Commit e0ff9af8 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont
Browse files

Really fix XShm detection with remote X11 (cf [19346]):

Get correct major opcode for MIT-SHM instead of an hard-coded one that
works with some X servers (not including mine).
parent 965b82cc
......@@ -116,7 +116,7 @@ static IMAGE_TYPE *CreateImage ( vout_thread_t *,
#ifdef HAVE_SYS_SHM_H
static IMAGE_TYPE *CreateShmImage ( vout_thread_t *,
Display *, EXTRA_ARGS_SHM, int, int );
static vlc_bool_t b_shm = VLC_TRUE;
static int i_shm_major = 0;
#endif
static void ToggleFullScreen ( vout_thread_t * );
......@@ -1065,7 +1065,7 @@ static void DisplayVideo( vout_thread_t *p_vout, picture_t *p_pic )
#endif
#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 */
# if defined(MODULE_NAME_IS_xvideo) || defined(MODULE_NAME_IS_xvmc)
......@@ -1885,7 +1885,7 @@ static int NewPicture( vout_thread_t *p_vout, picture_t *p_pic )
p_vout->output.i_aspect );
#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 */
p_pic->p_sys->p_image =
......@@ -1901,7 +1901,7 @@ static int NewPicture( vout_thread_t *p_vout, picture_t *p_pic )
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 */
{
/* Create image without XShm extension */
......@@ -1919,10 +1919,10 @@ static int NewPicture( vout_thread_t *p_vout, picture_t *p_pic )
p_vout->output.i_width, p_vout->output.i_height );
#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" );
p_vout->p_sys->b_shm = VLC_FALSE;
p_vout->p_sys->i_shm_opcode = 0;
}
#endif /* HAVE_SYS_SHM_H */
}
......@@ -2012,7 +2012,7 @@ static void FreePicture( vout_thread_t *p_vout, picture_t *p_pic )
{
/* The order of operations is correct */
#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 );
IMAGE_FREE( p_pic->p_sys->p_image );
......@@ -2613,29 +2613,36 @@ static int InitDisplay( vout_thread_t *p_vout )
#endif
#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" ) )
{
# ifdef __APPLE__
/* FIXME: As of 2001-03-16, XFree4 for MacOS X does not support Xshm */
# else
p_vout->p_sys->b_shm =
( XShmQueryExtension( p_vout->p_sys->p_display ) == True );
if( p_vout->p_sys->b_shm )
int major, evt, err;
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)",
major, minor, pixmaps ? "" : "out" );
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
if( !p_vout->p_sys->b_shm )
if( !p_vout->p_sys->i_shm_opcode )
{
msg_Warn( p_vout, "XShm video extension is unavailable" );
}
......@@ -2817,9 +2824,9 @@ static IMAGE_TYPE * CreateShmImage( vout_thread_t *p_vout,
/* Attach shared memory segment to X server */
XSynchronize( p_display, True );
b_shm = VLC_TRUE;
i_shm_major = p_vout->p_sys->i_shm_opcode;
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" );
IMAGE_FREE( p_image );
......@@ -2932,17 +2939,11 @@ static int X11ErrorHandler( Display * display, XErrorEvent * event )
/* Ignore errors on XSetInputFocus()
* (they happen when a window is not yet mapped) */
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);
return (XSetErrorHandler(X11ErrorHandler))( display, event );
}
......
......@@ -107,7 +107,7 @@ struct vout_sys_t
/* X11 generic properties */
vlc_bool_t b_altfullscreen; /* which fullscreen method */
#ifdef HAVE_SYS_SHM_H
vlc_bool_t b_shm; /* shared memory extension flag */
vlc_bool_t i_shm_opcode; /* shared memory extension opcode */
#endif
#if defined(MODULE_NAME_IS_xvideo) || defined(MODULE_NAME_IS_xvmc)
......
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