1 /*****************************************************************************
2 * xcommon.c: Functions common to the X11 and XVideo plugins
3 *****************************************************************************
4 * Copyright (C) 1998-2001 VideoLAN
5 * $Id: xcommon.c,v 1.14 2002/01/25 17:18:37 sam Exp $
7 * Authors: Vincent Seguin <seguin@via.ecp.fr>
8 * Samuel Hocevar <sam@zoy.org>
9 * David Kennedy <dkennedy@tinytoad.com>
10 * Gildas Bazin <gbazin@netcourrier.com>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
25 *****************************************************************************/
27 /*****************************************************************************
29 *****************************************************************************/
30 #include <errno.h> /* ENOMEM */
31 #include <stdlib.h> /* free() */
32 #include <string.h> /* strerror() */
34 #include <videolan/vlc.h>
36 #ifdef HAVE_MACHINE_PARAM_H
38 #include <machine/param.h>
39 #include <sys/types.h> /* typedef ushort */
44 #include <netinet/in.h> /* BSD: struct in_addr */
47 #include <sys/shm.h> /* shmget(), shmctl() */
49 #include <X11/Xutil.h>
50 #include <X11/keysym.h>
51 #include <X11/extensions/XShm.h>
52 #ifdef DPMSINFO_IN_DPMS_H
53 # include <X11/extensions/dpms.h>
56 #ifdef MODULE_NAME_IS_xvideo
57 # include <X11/extensions/Xv.h>
58 # include <X11/extensions/Xvlib.h>
62 #include "video_output.h"
65 #include "interface.h"
66 #include "netutils.h" /* network_ChannelJoin */
68 #include "stream_control.h" /* needed by input_ext-intf.h... */
69 #include "input_ext-intf.h"
71 #ifdef MODULE_NAME_IS_xvideo
72 # define IMAGE_TYPE XvImage
73 # define EXTRA_ARGS int i_xvport, int i_chroma
74 # define EXTRA_ARGS_SHM int i_xvport, int i_chroma, XShmSegmentInfo *p_shm
75 # define DATA_SIZE(p) (p)->data_size
76 # define IMAGE_FREE XFree /* There is nothing like XvDestroyImage */
78 # define IMAGE_TYPE XImage
79 # define EXTRA_ARGS Visual *p_visual, int i_depth, int i_bytes_per_pixel
80 # define EXTRA_ARGS_SHM Visual *p_visual, int i_depth, XShmSegmentInfo *p_shm
81 # define DATA_SIZE(p) ((p)->bytes_per_line * (p)->height)
82 # define IMAGE_FREE XDestroyImage
85 /*****************************************************************************
87 *****************************************************************************/
88 static int vout_Probe ( probedata_t * );
89 static int vout_Create ( vout_thread_t * );
90 static void vout_Destroy ( vout_thread_t * );
91 static void vout_Render ( vout_thread_t *, picture_t * );
92 static void vout_Display ( vout_thread_t *, picture_t * );
93 static int vout_Manage ( vout_thread_t * );
94 static int vout_Init ( vout_thread_t * );
95 static void vout_End ( vout_thread_t * );
97 static int InitDisplay ( vout_thread_t * );
99 static int CreateWindow ( vout_thread_t * );
100 static void DestroyWindow ( vout_thread_t * );
102 static int NewPicture ( vout_thread_t *, picture_t * );
103 static void FreePicture ( vout_thread_t *, picture_t * );
105 static IMAGE_TYPE *CreateImage ( Display *, EXTRA_ARGS, int, int );
106 static IMAGE_TYPE *CreateShmImage ( Display *, EXTRA_ARGS_SHM, int, int );
108 static void ToggleFullScreen ( vout_thread_t * );
110 static void EnableXScreenSaver ( vout_thread_t * );
111 static void DisableXScreenSaver ( vout_thread_t * );
113 static void CreateCursor ( vout_thread_t * );
114 static void DestroyCursor ( vout_thread_t * );
115 static void ToggleCursor ( vout_thread_t * );
117 #ifdef MODULE_NAME_IS_xvideo
118 static int XVideoGetPort ( Display *, u32, u32 * );
119 static void XVideoReleasePort ( Display *, int );
122 /*****************************************************************************
123 * vout_sys_t: video output method descriptor
124 *****************************************************************************
125 * This structure is part of the video output thread descriptor.
126 * It describes the X11 and XVideo specific properties of an output thread.
127 *****************************************************************************/
128 typedef struct vout_sys_s
130 /* Internal settings and properties */
131 Display * p_display; /* display pointer */
133 Visual * p_visual; /* visual pointer */
134 int i_screen; /* screen number */
135 Window window; /* root window */
136 GC gc; /* graphic context instance handler */
138 boolean_t b_shm; /* shared memory extension flag */
140 #ifdef MODULE_NAME_IS_xvideo
141 Window yuv_window; /* sub-window for displaying yuv video
145 Colormap colormap; /* colormap used (8bpp only) */
148 int i_bytes_per_pixel;
149 int i_bytes_per_line;
155 /* X11 generic properties */
157 Atom wm_delete_window;
159 int i_width; /* width of main window */
160 int i_height; /* height of main window */
162 /* Backup of window position and size before fullscreen switch */
167 int i_width_backup_2;
168 int i_height_backup_2;
172 /* Screen saver properties */
173 int i_ss_timeout; /* timeout */
174 int i_ss_interval; /* interval between changes */
175 int i_ss_blanking; /* blanking mode */
176 int i_ss_exposure; /* exposure mode */
177 #ifdef DPMSINFO_IN_DPMS_H
178 BOOL b_ss_dpms; /* DPMS mode */
181 /* Mouse pointer properties */
182 boolean_t b_mouse_pointer_visible;
183 mtime_t i_time_mouse_last_moved; /* used to auto-hide pointer*/
184 Cursor blank_cursor; /* the hidden cursor */
185 Pixmap cursor_pixmap;
189 /*****************************************************************************
190 * picture_sys_t: direct buffer method descriptor
191 *****************************************************************************
192 * This structure is part of the picture descriptor, it describes the
193 * XVideo specific properties of a direct buffer.
194 *****************************************************************************/
195 typedef struct picture_sys_s
197 IMAGE_TYPE * p_image;
199 XShmSegmentInfo shminfo; /* shared memory zone information */
203 /*****************************************************************************
204 * mwmhints_t: window manager hints
205 *****************************************************************************
206 * Fullscreen needs to be able to hide the wm decorations so we provide
207 * this structure to make it easier.
208 *****************************************************************************/
209 #define MWM_HINTS_DECORATIONS (1L << 1)
210 #define PROP_MWM_HINTS_ELEMENTS 5
211 typedef struct mwmhints_s
220 /*****************************************************************************
222 *****************************************************************************/
223 #ifdef MODULE_NAME_IS_xvideo
224 # define MAX_DIRECTBUFFERS 10
226 # define MAX_DIRECTBUFFERS 2
229 /*****************************************************************************
230 * Seeking function TODO: put this in a generic location !
231 *****************************************************************************/
232 static __inline__ void vout_Seek( off_t i_seek )
236 vlc_mutex_lock( &p_input_bank->lock );
237 if( p_input_bank->pp_input[0] != NULL )
239 #define S p_input_bank->pp_input[0]->stream
240 i_tell = S.p_selected_area->i_tell + i_seek * (off_t)50 * S.i_mux_rate;
242 i_tell = ( i_tell <= 0 /*S.p_selected_area->i_start*/ )
243 ? 0 /*S.p_selected_area->i_start*/
244 : ( i_tell >= S.p_selected_area->i_size )
245 ? S.p_selected_area->i_size
248 input_Seek( p_input_bank->pp_input[0], i_tell );
251 vlc_mutex_unlock( &p_input_bank->lock );
254 /*****************************************************************************
255 * Functions exported as capabilities. They are declared as static so that
256 * we don't pollute the namespace too much.
257 *****************************************************************************/
258 void _M( vout_getfunctions )( function_list_t * p_function_list )
260 p_function_list->pf_probe = vout_Probe;
261 p_function_list->functions.vout.pf_create = vout_Create;
262 p_function_list->functions.vout.pf_init = vout_Init;
263 p_function_list->functions.vout.pf_end = vout_End;
264 p_function_list->functions.vout.pf_destroy = vout_Destroy;
265 p_function_list->functions.vout.pf_manage = vout_Manage;
266 p_function_list->functions.vout.pf_render = vout_Render;
267 p_function_list->functions.vout.pf_display = vout_Display;
270 /*****************************************************************************
271 * vout_Probe: probe the video driver and return a score
272 *****************************************************************************
273 * This function tries to initialize SDL and returns a score to the
274 * plugin manager so that it can select the best plugin.
275 *****************************************************************************/
276 static int vout_Probe( probedata_t *p_data )
278 Display *p_display; /* display pointer */
280 #ifdef MODULE_NAME_IS_xvideo
281 int i_xvport, i_dummy;
284 /* Open display, unsing 'vlc_display' or DISPLAY environment variable */
285 psz_display = XDisplayName( main_GetPszVariable(VOUT_DISPLAY_VAR, NULL) );
286 p_display = XOpenDisplay( psz_display );
287 if( p_display == NULL ) /* error */
289 intf_WarnMsg( 3, "vout: cannot open display %s", psz_display );
293 #ifdef MODULE_NAME_IS_xvideo
294 /* Check that there is an available XVideo port for this format */
295 i_xvport = XVideoGetPort( p_display, p_data->vout.i_chroma, &i_dummy );
298 /* It failed, but it's not completely lost ! We try to open an
299 * XVideo port for a YUY2 picture */
300 i_xvport = XVideoGetPort( p_display, FOURCC_YUY2, &i_dummy );
303 /* It failed, but it's not completely lost ! We try to open an
304 * XVideo port for a simple 16bpp RGB picture */
305 i_xvport = XVideoGetPort( p_display, FOURCC_RV16, &i_dummy );
308 XCloseDisplay( p_display );
313 XVideoReleasePort( p_display, i_xvport );
316 /* Clean-up everyting */
317 XCloseDisplay( p_display );
319 #ifdef MODULE_NAME_IS_xvideo
326 /*****************************************************************************
327 * vout_Create: allocate X11 video thread output method
328 *****************************************************************************
329 * This function allocate and initialize a X11 vout method. It uses some of the
330 * vout properties to choose the window size, and change them according to the
331 * actual properties of the display.
332 *****************************************************************************/
333 static int vout_Create( vout_thread_t *p_vout )
337 /* Allocate structure */
338 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
339 if( p_vout->p_sys == NULL )
341 intf_ErrMsg( "vout error: %s", strerror(ENOMEM) );
345 /* Open display, unsing 'vlc_display' or DISPLAY environment variable */
346 psz_display = XDisplayName( main_GetPszVariable( VOUT_DISPLAY_VAR, NULL ) );
347 p_vout->p_sys->p_display = XOpenDisplay( psz_display );
349 if( p_vout->p_sys->p_display == NULL ) /* error */
351 intf_ErrMsg( "vout error: cannot open display %s", psz_display );
352 free( p_vout->p_sys );
355 p_vout->p_sys->i_screen = DefaultScreen( p_vout->p_sys->p_display );
357 #ifdef MODULE_NAME_IS_xvideo
358 /* Check that we have access to an XVideo port providing this chroma */
359 p_vout->p_sys->i_xvport = XVideoGetPort( p_vout->p_sys->p_display,
360 p_vout->render.i_chroma,
361 &p_vout->output.i_chroma );
362 if( p_vout->p_sys->i_xvport < 0 )
364 /* It failed, but it's not completely lost ! We try to open an
365 * XVideo port for an YUY2 picture. We'll need to do an YUV
366 * conversion, but at least it has got scaling. */
367 p_vout->p_sys->i_xvport = XVideoGetPort( p_vout->p_sys->p_display,
369 &p_vout->output.i_chroma );
370 if( p_vout->p_sys->i_xvport < 0 )
372 /* It failed, but it's not completely lost ! We try to open an
373 * XVideo port for a simple 16bpp RGB picture. We'll need to do
374 * an YUV conversion, but at least it has got scaling. */
375 p_vout->p_sys->i_xvport = XVideoGetPort( p_vout->p_sys->p_display,
377 &p_vout->output.i_chroma );
378 if( p_vout->p_sys->i_xvport < 0 )
380 XCloseDisplay( p_vout->p_sys->p_display );
381 free( p_vout->p_sys );
388 /* Create blank cursor (for mouse cursor autohiding) */
389 p_vout->p_sys->b_mouse_pointer_visible = 1;
390 CreateCursor( p_vout );
392 /* Spawn base window - this window will include the video output window,
393 * but also command buttons, subtitles and other indicators */
394 if( CreateWindow( p_vout ) )
396 intf_ErrMsg( "vout error: cannot create X11 window" );
397 DestroyCursor( p_vout );
398 XCloseDisplay( p_vout->p_sys->p_display );
399 free( p_vout->p_sys );
403 /* Open and initialize device. */
404 if( InitDisplay( p_vout ) )
406 intf_ErrMsg( "vout error: cannot initialize X11 display" );
407 DestroyCursor( p_vout );
408 DestroyWindow( p_vout );
409 XCloseDisplay( p_vout->p_sys->p_display );
410 free( p_vout->p_sys );
414 /* Disable screen saver and return */
415 DisableXScreenSaver( p_vout );
420 /*****************************************************************************
421 * vout_Destroy: destroy X11 video thread output method
422 *****************************************************************************
423 * Terminate an output method created by vout_CreateOutputMethod
424 *****************************************************************************/
425 static void vout_Destroy( vout_thread_t *p_vout )
427 /* Restore cursor if it was blanked */
428 if( !p_vout->p_sys->b_mouse_pointer_visible )
430 ToggleCursor( p_vout );
433 #ifdef MODULE_NAME_IS_xvideo
434 XVideoReleasePort( p_vout->p_sys->p_display, p_vout->p_sys->i_xvport );
437 /* Destroy colormap */
438 if( p_vout->p_sys->i_screen_depth == 8 )
440 XFreeColormap( p_vout->p_sys->p_display, p_vout->p_sys->colormap );
445 DestroyCursor( p_vout );
446 EnableXScreenSaver( p_vout );
447 DestroyWindow( p_vout );
449 XCloseDisplay( p_vout->p_sys->p_display );
451 /* Destroy structure */
452 free( p_vout->p_sys );
455 /*****************************************************************************
456 * vout_Init: initialize X11 video thread output method
457 *****************************************************************************
458 * This function create the XImages needed by the output thread. It is called
459 * at the beginning of the thread, but also each time the window is resized.
460 *****************************************************************************/
461 static int vout_Init( vout_thread_t *p_vout )
466 I_OUTPUTPICTURES = 0;
468 #ifdef MODULE_NAME_IS_xvideo
469 /* Initialize the output structure; we already found an XVideo port,
470 * and the corresponding chroma we will be using. Since we can
471 * arbitrary scale, stick to the coordinates and aspect. */
472 p_vout->output.i_width = p_vout->render.i_width;
473 p_vout->output.i_height = p_vout->render.i_height;
474 p_vout->output.i_aspect = p_vout->render.i_aspect;
477 /* Initialize the output structure: RGB with square pixels, whatever
478 * the input format is, since it's the only format we know */
479 switch( p_vout->p_sys->i_screen_depth )
481 case 8: /* FIXME: set the palette */
482 p_vout->output.i_chroma = FOURCC_BI_RGB; break;
484 p_vout->output.i_chroma = FOURCC_RV15; break;
486 p_vout->output.i_chroma = FOURCC_RV16; break;
488 p_vout->output.i_chroma = FOURCC_BI_BITFIELDS; break;
490 p_vout->output.i_chroma = FOURCC_BI_BITFIELDS; break;
492 intf_ErrMsg( "vout error: unknown screen depth" );
496 p_vout->output.i_width = p_vout->p_sys->i_width;
497 p_vout->output.i_height = p_vout->p_sys->i_height;
499 /* Assume we have square pixels */
500 p_vout->output.i_aspect = p_vout->p_sys->i_width
501 * VOUT_ASPECT_FACTOR / p_vout->p_sys->i_height;
504 /* Try to initialize up to MAX_DIRECTBUFFERS direct buffers */
505 while( I_OUTPUTPICTURES < MAX_DIRECTBUFFERS )
509 /* Find an empty picture slot */
510 for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
512 if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
514 p_pic = p_vout->p_picture + i_index;
519 /* Allocate the picture */
520 if( p_pic == NULL || NewPicture( p_vout, p_pic ) )
525 p_pic->i_status = DESTROYED_PICTURE;
526 p_pic->i_type = DIRECT_PICTURE;
528 PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
536 /*****************************************************************************
537 * vout_Render: render previously calculated output
538 *****************************************************************************/
539 static void vout_Render( vout_thread_t *p_vout, picture_t *p_pic )
544 /*****************************************************************************
545 * vout_Display: displays previously rendered output
546 *****************************************************************************
547 * This function sends the currently rendered image to X11 server.
548 * (The Xv extension takes care of "double-buffering".)
549 *****************************************************************************/
550 static void vout_Display( vout_thread_t *p_vout, picture_t *p_pic )
552 int i_width, i_height, i_x, i_y;
554 vout_PlacePicture( p_vout, p_vout->p_sys->i_width, p_vout->p_sys->i_height,
555 &i_x, &i_y, &i_width, &i_height );
557 if( p_vout->p_sys->b_shm )
559 /* Display rendered image using shared memory extension */
560 #ifdef MODULE_NAME_IS_xvideo
561 XvShmPutImage( p_vout->p_sys->p_display, p_vout->p_sys->i_xvport,
562 p_vout->p_sys->yuv_window, p_vout->p_sys->gc,
563 p_pic->p_sys->p_image, 0 /*src_x*/, 0 /*src_y*/,
564 p_vout->output.i_width, p_vout->output.i_height,
565 0 /*dest_x*/, 0 /*dest_y*/, i_width, i_height,
566 False /* Don't put True here or you'll waste your CPU */ );
568 XShmPutImage( p_vout->p_sys->p_display, p_vout->p_sys->window,
569 p_vout->p_sys->gc, p_pic->p_sys->p_image,
570 0 /*src_x*/, 0 /*src_y*/, 0 /*dest_x*/, 0 /*dest_y*/,
571 p_vout->output.i_width, p_vout->output.i_height,
572 False /* Don't put True here ! */ );
577 /* Use standard XPutImage -- this is gonna be slow ! */
578 #ifdef MODULE_NAME_IS_xvideo
579 XvPutImage( p_vout->p_sys->p_display, p_vout->p_sys->i_xvport,
580 p_vout->p_sys->yuv_window, p_vout->p_sys->gc,
581 p_pic->p_sys->p_image, 0 /*src_x*/, 0 /*src_y*/,
582 p_vout->output.i_width, p_vout->output.i_height,
583 0 /*dest_x*/, 0 /*dest_y*/, i_width, i_height );
585 XPutImage( p_vout->p_sys->p_display, p_vout->p_sys->window,
586 p_vout->p_sys->gc, p_pic->p_sys->p_image,
587 0 /*src_x*/, 0 /*src_y*/, 0 /*dest_x*/, 0 /*dest_y*/,
588 p_vout->output.i_width, p_vout->output.i_height );
592 /* Make sure the command is sent now - do NOT use XFlush !*/
593 XSync( p_vout->p_sys->p_display, False );
596 /*****************************************************************************
597 * vout_Manage: handle X11 events
598 *****************************************************************************
599 * This function should be called regularly by video output thread. It manages
600 * X11 events and allows window resizing. It returns a non null value on
602 *****************************************************************************/
603 static int vout_Manage( vout_thread_t *p_vout )
605 XEvent xevent; /* X11 event */
606 boolean_t b_resized; /* window has been resized */
607 char i_key; /* ISO Latin-1 key */
610 /* Handle X11 events: ConfigureNotify events are parsed to know if the
611 * output window's size changed, MapNotify and UnmapNotify to know if the
612 * window is mapped (and if the display is useful), and ClientMessages
613 * to intercept window destruction requests */
616 while( XCheckWindowEvent( p_vout->p_sys->p_display, p_vout->p_sys->window,
617 StructureNotifyMask | KeyPressMask |
618 ButtonPressMask | ButtonReleaseMask |
619 PointerMotionMask | Button1MotionMask , &xevent )
622 /* ConfigureNotify event: prepare */
623 if( xevent.type == ConfigureNotify )
625 if( (xevent.xconfigure.width != p_vout->p_sys->i_width)
626 || (xevent.xconfigure.height != p_vout->p_sys->i_height) )
628 /* Update dimensions */
630 p_vout->i_changes |= VOUT_SIZE_CHANGE;
631 p_vout->p_sys->i_width = xevent.xconfigure.width;
632 p_vout->p_sys->i_height = xevent.xconfigure.height;
635 /* MapNotify event: change window status and disable screen saver */
636 else if( xevent.type == MapNotify)
638 if( (p_vout != NULL) && !p_vout->b_active )
640 DisableXScreenSaver( p_vout );
641 p_vout->b_active = 1;
644 /* UnmapNotify event: change window status and enable screen saver */
645 else if( xevent.type == UnmapNotify )
647 if( (p_vout != NULL) && p_vout->b_active )
649 EnableXScreenSaver( p_vout );
650 p_vout->b_active = 0;
654 else if( xevent.type == KeyPress )
656 /* We may have keys like F1 trough F12, ESC ... */
657 x_key_symbol = XKeycodeToKeysym( p_vout->p_sys->p_display,
658 xevent.xkey.keycode, 0 );
659 switch( x_key_symbol )
662 p_main->p_intf->b_die = 1;
665 p_main->p_intf->b_menu_change = 1;
680 input_Seek( p_input_bank->pp_input[0],
681 p_input_bank->pp_input[0]->stream.p_selected_area->i_start );
684 input_Seek( p_input_bank->pp_input[0],
685 p_input_bank->pp_input[0]->stream.p_selected_area->i_size );
694 input_SetStatus( p_input_bank->pp_input[0],
695 INPUT_STATUS_PAUSE );
700 * The reason why I use this instead of XK_0 is that
701 * with XLookupString, we don't have to care about
704 if( XLookupString( &xevent.xkey, &i_key, 1, NULL, NULL ) )
706 /* FIXME: handle stuff here */
711 p_main->p_intf->b_die = 1;
715 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
718 case '0': network_ChannelJoin( 0 ); break;
719 case '1': network_ChannelJoin( 1 ); break;
720 case '2': network_ChannelJoin( 2 ); break;
721 case '3': network_ChannelJoin( 3 ); break;
722 case '4': network_ChannelJoin( 4 ); break;
723 case '5': network_ChannelJoin( 5 ); break;
724 case '6': network_ChannelJoin( 6 ); break;
725 case '7': network_ChannelJoin( 7 ); break;
726 case '8': network_ChannelJoin( 8 ); break;
727 case '9': network_ChannelJoin( 9 ); break;
730 intf_DbgMsg( "vout: unhandled key '%c' (%i)",
731 (char)i_key, i_key );
739 else if( xevent.type == ButtonPress )
741 switch( ((XButtonEvent *)&xevent)->button )
744 /* In this part we will eventually manage
745 * clicks for DVD navigation for instance. For the
746 * moment just pause the stream. */
747 input_SetStatus( p_input_bank->pp_input[0],
748 INPUT_STATUS_PAUSE );
761 else if( xevent.type == ButtonRelease )
763 switch( ((XButtonEvent *)&xevent)->button )
766 /* FIXME: need locking ! */
767 p_main->p_intf->b_menu_change = 1;
772 else if( xevent.type == MotionNotify )
774 p_vout->p_sys->i_time_mouse_last_moved = mdate();
775 if( ! p_vout->p_sys->b_mouse_pointer_visible )
777 ToggleCursor( p_vout );
780 /* Reparent move -- XXX: why are we getting this ? */
781 else if( xevent.type == ReparentNotify )
788 intf_WarnMsg( 3, "vout: unhandled event %d received", xevent.type );
792 #ifdef MODULE_NAME_IS_xvideo
793 /* Handle events for YUV video output sub-window */
794 while( XCheckWindowEvent( p_vout->p_sys->p_display,
795 p_vout->p_sys->yuv_window,
796 ExposureMask, &xevent ) == True )
798 /* Window exposed (only handled if stream playback is paused) */
799 if( xevent.type == Expose )
801 if( ((XExposeEvent *)&xevent)->count == 0 )
803 /* (if this is the last a collection of expose events...) */
804 if( p_input_bank->pp_input[0] != NULL )
807 p_input_bank->pp_input[0]->stream.control.i_status )
809 /* XVideoDisplay( p_vout )*/;
817 /* ClientMessage event - only WM_PROTOCOLS with WM_DELETE_WINDOW data
818 * are handled - according to the man pages, the format is always 32
820 while( XCheckTypedEvent( p_vout->p_sys->p_display,
821 ClientMessage, &xevent ) )
823 if( (xevent.xclient.message_type == p_vout->p_sys->wm_protocols)
824 && (xevent.xclient.data.l[0] == p_vout->p_sys->wm_delete_window ) )
826 p_main->p_intf->b_die = 1;
830 intf_DbgMsg( "vout: unhandled ClientMessage received" );
837 if ( p_vout->i_changes & VOUT_FULLSCREEN_CHANGE )
839 ToggleFullScreen( p_vout );
840 p_vout->i_changes &= ~VOUT_FULLSCREEN_CHANGE;
845 #ifdef MODULE_NAME_IS_x11
847 * Handle vout window resizing
852 /* If interface window has been resized, change vout size */
853 intf_DbgMsg( "vout: resizing output window" );
854 p_vout->i_width = p_vout->p_sys->i_width;
855 p_vout->i_height = p_vout->p_sys->i_height;
856 p_vout->i_changes |= VOUT_SIZE_CHANGE;
858 else if( (p_vout->i_width != p_vout->p_sys->i_width) ||
859 (p_vout->i_height != p_vout->p_sys->i_height) )
861 /* If video output size has changed, change interface window size */
862 intf_DbgMsg( "vout: resizing output window" );
863 p_vout->p_sys->i_width = p_vout->i_width;
864 p_vout->p_sys->i_height = p_vout->i_height;
865 XResizeWindow( p_vout->p_sys->p_display, p_vout->p_sys->window,
866 p_vout->p_sys->i_width, p_vout->p_sys->i_height );
869 * Color/Grayscale or gamma change: in 8bpp, just change the colormap
871 if( (p_vout->i_changes & VOUT_GRAYSCALE_CHANGE)
872 && (p_vout->i_screen_depth == 8) )
874 /* FIXME: clear flags ?? */
880 if( p_vout->i_changes & VOUT_SIZE_CHANGE )
882 intf_DbgMsg( "vout info: resizing window" );
883 p_vout->i_changes &= ~VOUT_SIZE_CHANGE;
886 XResizeWindow( p_vout->p_sys->p_display, p_vout->p_sys->window,
887 p_vout->i_width, p_vout->i_height );
889 /* Destroy XImages to change their size */
892 /* Recreate XImages. If SysInit failed, the thread can't go on. */
893 if( vout_Init( p_vout ) )
895 intf_ErrMsg( "vout error: cannot resize display" );
899 /* Tell the video output thread that it will need to rebuild YUV
900 * tables. This is needed since conversion buffer size may have
902 p_vout->i_changes |= VOUT_YUV_CHANGE;
903 intf_Msg( "vout: video display resized (%dx%d)",
904 p_vout->i_width, p_vout->i_height);
911 * (Needs to be placed after VOUT_FULLSREEN_CHANGE because we can activate
912 * the size flag inside the fullscreen routine)
914 if( p_vout->i_changes & VOUT_SIZE_CHANGE )
916 int i_width, i_height, i_x, i_y;
918 p_vout->i_changes &= ~VOUT_SIZE_CHANGE;
920 intf_WarnMsg( 3, "vout: video display resized (%dx%d)",
921 p_vout->p_sys->i_width,
922 p_vout->p_sys->i_height );
924 vout_PlacePicture( p_vout, p_vout->p_sys->i_width,
925 p_vout->p_sys->i_height,
926 &i_x, &i_y, &i_width, &i_height );
928 XResizeWindow( p_vout->p_sys->p_display, p_vout->p_sys->yuv_window,
931 XMoveWindow( p_vout->p_sys->p_display, p_vout->p_sys->yuv_window,
937 /* Autohide Cursour */
938 if( mdate() - p_vout->p_sys->i_time_mouse_last_moved > 2000000 )
940 /* Hide the mouse automatically */
941 if( p_vout->p_sys->b_mouse_pointer_visible )
943 ToggleCursor( p_vout );
950 /*****************************************************************************
951 * vout_End: terminate X11 video thread output method
952 *****************************************************************************
953 * Destroy the X11 XImages created by vout_Init. It is called at the end of
954 * the thread, but also each time the window is resized.
955 *****************************************************************************/
956 static void vout_End( vout_thread_t *p_vout )
960 /* Free the direct buffers we allocated */
961 for( i_index = I_OUTPUTPICTURES ; i_index ; )
964 FreePicture( p_vout, PP_OUTPUTPICTURE[ i_index ] );
968 /* following functions are local */
970 /*****************************************************************************
971 * CreateWindow: open and set-up X11 main window
972 *****************************************************************************/
973 static int CreateWindow( vout_thread_t *p_vout )
975 XSizeHints xsize_hints;
976 XSetWindowAttributes xwindow_attributes;
981 boolean_t b_configure_notify;
982 boolean_t b_map_notify;
984 /* Set main window's size */
985 if( p_vout->render.i_height * p_vout->render.i_aspect
986 >= p_vout->render.i_width * VOUT_ASPECT_FACTOR )
988 p_vout->p_sys->i_width = p_vout->render.i_height
989 * p_vout->render.i_aspect / VOUT_ASPECT_FACTOR;
990 p_vout->p_sys->i_height = p_vout->render.i_height;
994 p_vout->p_sys->i_width = p_vout->render.i_width;
995 p_vout->p_sys->i_height = p_vout->render.i_width
996 * VOUT_ASPECT_FACTOR / p_vout->render.i_aspect;
1000 if( p_vout->p_sys->i_width <= 300 && p_vout->p_sys->i_height <= 300 )
1002 p_vout->p_sys->i_width <<= 1;
1003 p_vout->p_sys->i_height <<= 1;
1005 else if( p_vout->p_sys->i_width <= 400
1006 && p_vout->p_sys->i_height <= 400 )
1008 p_vout->p_sys->i_width += p_vout->p_sys->i_width >> 1;
1009 p_vout->p_sys->i_height += p_vout->p_sys->i_height >> 1;
1013 /* Prepare window manager hints and properties */
1014 xsize_hints.base_width = p_vout->p_sys->i_width;
1015 xsize_hints.base_height = p_vout->p_sys->i_height;
1016 xsize_hints.flags = PSize;
1017 p_vout->p_sys->wm_protocols = XInternAtom( p_vout->p_sys->p_display,
1018 "WM_PROTOCOLS", True );
1019 p_vout->p_sys->wm_delete_window = XInternAtom( p_vout->p_sys->p_display,
1020 "WM_DELETE_WINDOW", True );
1022 /* Prepare window attributes */
1023 xwindow_attributes.backing_store = Always; /* save the hidden part */
1024 xwindow_attributes.background_pixel = BlackPixel(p_vout->p_sys->p_display,
1025 p_vout->p_sys->i_screen);
1026 xwindow_attributes.event_mask = ExposureMask | StructureNotifyMask;
1029 /* Create the window and set hints - the window must receive
1030 * ConfigureNotify events, and until it is displayed, Expose and
1031 * MapNotify events. */
1033 p_vout->p_sys->window =
1034 XCreateWindow( p_vout->p_sys->p_display,
1035 DefaultRootWindow( p_vout->p_sys->p_display ),
1037 p_vout->p_sys->i_width,
1038 p_vout->p_sys->i_height,
1041 CWBackingStore | CWBackPixel | CWEventMask,
1042 &xwindow_attributes );
1044 /* Set window manager hints and properties: size hints, command,
1045 * window's name, and accepted protocols */
1046 XSetWMNormalHints( p_vout->p_sys->p_display, p_vout->p_sys->window,
1048 XSetCommand( p_vout->p_sys->p_display, p_vout->p_sys->window,
1049 p_main->ppsz_argv, p_main->i_argc );
1050 XStoreName( p_vout->p_sys->p_display, p_vout->p_sys->window,
1051 #ifdef MODULE_NAME_IS_x11
1052 VOUT_TITLE " (X11 output)"
1054 VOUT_TITLE " (XVideo output)"
1058 if( (p_vout->p_sys->wm_protocols == None) /* use WM_DELETE_WINDOW */
1059 || (p_vout->p_sys->wm_delete_window == None)
1060 || !XSetWMProtocols( p_vout->p_sys->p_display, p_vout->p_sys->window,
1061 &p_vout->p_sys->wm_delete_window, 1 ) )
1063 /* WM_DELETE_WINDOW is not supported by window manager */
1064 intf_Msg( "vout error: missing or bad window manager" );
1067 /* Creation of a graphic context that doesn't generate a GraphicsExpose
1068 * event when using functions like XCopyArea */
1069 xgcvalues.graphics_exposures = False;
1070 p_vout->p_sys->gc = XCreateGC( p_vout->p_sys->p_display,
1071 p_vout->p_sys->window,
1072 GCGraphicsExposures, &xgcvalues);
1074 /* Send orders to server, and wait until window is displayed - three
1075 * events must be received: a MapNotify event, an Expose event allowing
1076 * drawing in the window, and a ConfigureNotify to get the window
1077 * dimensions. Once those events have been received, only ConfigureNotify
1078 * events need to be received. */
1080 b_configure_notify = 0;
1082 XMapWindow( p_vout->p_sys->p_display, p_vout->p_sys->window);
1085 XNextEvent( p_vout->p_sys->p_display, &xevent);
1086 if( (xevent.type == Expose)
1087 && (xevent.xexpose.window == p_vout->p_sys->window) )
1091 else if( (xevent.type == MapNotify)
1092 && (xevent.xmap.window == p_vout->p_sys->window) )
1096 else if( (xevent.type == ConfigureNotify)
1097 && (xevent.xconfigure.window == p_vout->p_sys->window) )
1099 b_configure_notify = 1;
1100 p_vout->p_sys->i_width = xevent.xconfigure.width;
1101 p_vout->p_sys->i_height = xevent.xconfigure.height;
1103 } while( !( b_expose && b_configure_notify && b_map_notify ) );
1105 XSelectInput( p_vout->p_sys->p_display, p_vout->p_sys->window,
1106 StructureNotifyMask | KeyPressMask |
1107 ButtonPressMask | ButtonReleaseMask |
1108 PointerMotionMask );
1110 #ifdef MODULE_NAME_IS_x11
1111 if( XDefaultDepth(p_vout->p_sys->p_display, p_vout->p_sys->i_screen) == 8 )
1113 /* Allocate a new palette */
1114 p_vout->p_sys->colormap =
1115 XCreateColormap( p_vout->p_sys->p_display,
1116 DefaultRootWindow( p_vout->p_sys->p_display ),
1117 DefaultVisual( p_vout->p_sys->p_display,
1118 p_vout->p_sys->i_screen ),
1121 xwindow_attributes.colormap = p_vout->p_sys->colormap;
1122 XChangeWindowAttributes( p_vout->p_sys->p_display,
1123 p_vout->p_sys->window,
1124 CWColormap, &xwindow_attributes );
1128 /* Create YUV output sub-window. */
1129 p_vout->p_sys->yuv_window = XCreateSimpleWindow( p_vout->p_sys->p_display,
1130 p_vout->p_sys->window, 0, 0,
1131 p_vout->p_sys->i_width,
1132 p_vout->p_sys->i_height,
1134 BlackPixel( p_vout->p_sys->p_display,
1135 p_vout->p_sys->i_screen ),
1136 WhitePixel( p_vout->p_sys->p_display,
1137 p_vout->p_sys->i_screen ) );
1139 XSetWindowBackground( p_vout->p_sys->p_display, p_vout->p_sys->yuv_window,
1140 BlackPixel(p_vout->p_sys->p_display, p_vout->p_sys->i_screen ) );
1142 XMapWindow( p_vout->p_sys->p_display, p_vout->p_sys->yuv_window );
1143 XSelectInput( p_vout->p_sys->p_display, p_vout->p_sys->yuv_window,
1147 /* If the cursor was formerly blank than blank it again */
1148 if( !p_vout->p_sys->b_mouse_pointer_visible )
1150 ToggleCursor( p_vout );
1151 ToggleCursor( p_vout );
1154 /* Do NOT use XFlush here ! */
1155 XSync( p_vout->p_sys->p_display, False );
1157 /* At this stage, the window is open, displayed, and ready to
1163 /*****************************************************************************
1164 * DestroyWindow: destroy the window
1165 *****************************************************************************
1167 *****************************************************************************/
1168 static void DestroyWindow( vout_thread_t *p_vout )
1170 /* Do NOT use XFlush here ! */
1171 XSync( p_vout->p_sys->p_display, False );
1173 #ifdef MODULE_NAME_IS_xvideo
1174 XDestroyWindow( p_vout->p_sys->p_display, p_vout->p_sys->yuv_window );
1177 XUnmapWindow( p_vout->p_sys->p_display, p_vout->p_sys->window );
1178 XFreeGC( p_vout->p_sys->p_display, p_vout->p_sys->gc );
1179 XDestroyWindow( p_vout->p_sys->p_display, p_vout->p_sys->window );
1182 /*****************************************************************************
1183 * NewPicture: allocate a picture
1184 *****************************************************************************
1185 * Returns 0 on success, -1 otherwise
1186 *****************************************************************************/
1187 static int NewPicture( vout_thread_t *p_vout, picture_t *p_pic )
1189 /* We know the chroma, allocate a buffer which will be used
1190 * directly by the decoder */
1191 p_pic->p_sys = malloc( sizeof( picture_sys_t ) );
1193 if( p_pic->p_sys == NULL )
1198 if( p_vout->p_sys->b_shm )
1200 /* Create image using XShm extension */
1201 p_pic->p_sys->p_image =
1202 CreateShmImage( p_vout->p_sys->p_display,
1203 #ifdef MODULE_NAME_IS_xvideo
1204 p_vout->p_sys->i_xvport,
1205 p_vout->output.i_chroma,
1207 p_vout->p_sys->p_visual,
1208 p_vout->p_sys->i_screen_depth,
1210 &p_pic->p_sys->shminfo,
1211 p_vout->output.i_width, p_vout->output.i_height );
1215 /* Create image without XShm extension */
1216 p_pic->p_sys->p_image =
1217 CreateImage( p_vout->p_sys->p_display,
1218 #ifdef MODULE_NAME_IS_xvideo
1219 p_vout->p_sys->i_xvport,
1220 p_vout->output.i_chroma,
1222 p_vout->p_sys->p_visual,
1223 p_vout->p_sys->i_screen_depth,
1224 p_vout->p_sys->i_bytes_per_pixel,
1226 p_vout->output.i_width, p_vout->output.i_height );
1229 if( p_pic->p_sys->p_image == NULL )
1231 free( p_pic->p_sys );
1235 switch( p_vout->output.i_chroma )
1237 #ifdef MODULE_NAME_IS_xvideo
1240 p_pic->Y_PIXELS = p_pic->p_sys->p_image->data
1241 + p_pic->p_sys->p_image->offsets[0];
1242 p_pic->p[Y_PLANE].i_lines = p_vout->output.i_height;
1243 p_pic->p[Y_PLANE].i_pitch = p_pic->p_sys->p_image->pitches[0];
1244 p_pic->p[Y_PLANE].i_pixel_bytes = 1;
1245 p_pic->p[Y_PLANE].b_margin = 0;
1247 p_pic->U_PIXELS = p_pic->p_sys->p_image->data
1248 + p_pic->p_sys->p_image->offsets[1];
1249 p_pic->p[U_PLANE].i_lines = p_vout->output.i_height / 2;
1250 p_pic->p[U_PLANE].i_pitch = p_pic->p_sys->p_image->pitches[1];
1251 p_pic->p[U_PLANE].i_pixel_bytes = 1;
1252 p_pic->p[U_PLANE].b_margin = 0;
1254 p_pic->V_PIXELS = p_pic->p_sys->p_image->data
1255 + p_pic->p_sys->p_image->offsets[2];
1256 p_pic->p[V_PLANE].i_lines = p_vout->output.i_height / 2;
1257 p_pic->p[V_PLANE].i_pitch = p_pic->p_sys->p_image->pitches[2];
1258 p_pic->p[V_PLANE].i_pixel_bytes = 1;
1259 p_pic->p[V_PLANE].b_margin = 0;
1261 p_pic->i_planes = 3;
1266 p_pic->Y_PIXELS = p_pic->p_sys->p_image->data
1267 + p_pic->p_sys->p_image->offsets[0];
1268 p_pic->p[Y_PLANE].i_lines = p_vout->output.i_height;
1269 p_pic->p[Y_PLANE].i_pitch = p_pic->p_sys->p_image->pitches[0];
1270 p_pic->p[Y_PLANE].i_pixel_bytes = 1;
1271 p_pic->p[Y_PLANE].b_margin = 0;
1273 p_pic->U_PIXELS = p_pic->p_sys->p_image->data
1274 + p_pic->p_sys->p_image->offsets[2];
1275 p_pic->p[U_PLANE].i_lines = p_vout->output.i_height / 2;
1276 p_pic->p[U_PLANE].i_pitch = p_pic->p_sys->p_image->pitches[2];
1277 p_pic->p[U_PLANE].i_pixel_bytes = 1;
1278 p_pic->p[U_PLANE].b_margin = 0;
1280 p_pic->V_PIXELS = p_pic->p_sys->p_image->data
1281 + p_pic->p_sys->p_image->offsets[1];
1282 p_pic->p[V_PLANE].i_lines = p_vout->output.i_height / 2;
1283 p_pic->p[V_PLANE].i_pitch = p_pic->p_sys->p_image->pitches[1];
1284 p_pic->p[V_PLANE].i_pixel_bytes = 1;
1285 p_pic->p[V_PLANE].b_margin = 0;
1287 p_pic->i_planes = 3;
1292 p_pic->p->p_pixels = p_pic->p_sys->p_image->data
1293 + p_pic->p_sys->p_image->offsets[0];
1294 p_pic->p->i_lines = p_vout->output.i_height;
1295 /* XXX: this just looks so plain wrong... check it out ! */
1296 p_pic->p->i_pitch = p_pic->p_sys->p_image->pitches[0] / 4;
1297 p_pic->p->i_pixel_bytes = 4;
1298 p_pic->p->b_margin = 0;
1300 p_pic->i_planes = 1;
1306 p_pic->p->p_pixels = p_pic->p_sys->p_image->data
1307 + p_pic->p_sys->p_image->offsets[0];
1308 p_pic->p->i_lines = p_vout->output.i_height;
1309 p_pic->p->i_pitch = p_pic->p_sys->p_image->pitches[0];
1310 p_pic->p->i_pixel_bytes = 4;
1311 p_pic->p->b_margin = 0;
1313 p_pic->i_planes = 1;
1318 p_pic->p->p_pixels = p_pic->p_sys->p_image->data
1319 + p_pic->p_sys->p_image->offsets[0];
1320 p_pic->p->i_lines = p_vout->output.i_height;
1321 p_pic->p->i_pitch = p_pic->p_sys->p_image->pitches[0];
1322 p_pic->p->i_pixel_bytes = 2;
1323 p_pic->p->b_margin = 0;
1325 p_pic->p->i_red_mask = 0x001f;
1326 p_pic->p->i_green_mask = 0x07e0;
1327 p_pic->p->i_blue_mask = 0xf800;
1329 p_pic->i_planes = 1;
1334 p_pic->p->p_pixels = p_pic->p_sys->p_image->data
1335 + p_pic->p_sys->p_image->offsets[0];
1336 p_pic->p->i_lines = p_vout->output.i_height;
1337 p_pic->p->i_pitch = p_pic->p_sys->p_image->pitches[0];
1338 p_pic->p->i_pixel_bytes = 2;
1339 p_pic->p->b_margin = 0;
1341 p_pic->p->i_red_mask = 0x001f;
1342 p_pic->p->i_green_mask = 0x03e0;
1343 p_pic->p->i_blue_mask = 0x7c00;
1345 p_pic->i_planes = 1;
1351 p_pic->p->p_pixels = p_pic->p_sys->p_image->data
1352 + p_pic->p_sys->p_image->xoffset;
1353 p_pic->p->i_lines = p_pic->p_sys->p_image->height;
1354 p_pic->p->i_pitch = p_pic->p_sys->p_image->bytes_per_line;
1355 p_pic->p->i_pixel_bytes = p_pic->p_sys->p_image->depth;
1357 if( p_pic->p->i_pitch == 2 * p_pic->p_sys->p_image->width )
1359 p_pic->p->b_margin = 0;
1363 p_pic->p->b_margin = 1;
1364 p_pic->p->b_hidden = 1;
1365 p_pic->p->i_visible_bytes = 2 * p_pic->p_sys->p_image->width;
1368 p_pic->p->i_red_mask = p_pic->p_sys->p_image->red_mask;
1369 p_pic->p->i_green_mask = p_pic->p_sys->p_image->green_mask;
1370 p_pic->p->i_blue_mask = p_pic->p_sys->p_image->blue_mask;
1372 p_pic->i_planes = 1;
1376 case FOURCC_BI_BITFIELDS:
1378 p_pic->p->p_pixels = p_pic->p_sys->p_image->data
1379 + p_pic->p_sys->p_image->xoffset;
1380 p_pic->p->i_lines = p_pic->p_sys->p_image->height;
1381 p_pic->p->i_pitch = p_pic->p_sys->p_image->bytes_per_line;
1382 p_pic->p->i_pixel_bytes = p_pic->p_sys->p_image->depth;
1384 if( p_pic->p->i_pitch == 4 * p_pic->p_sys->p_image->width )
1386 p_pic->p->b_margin = 0;
1390 p_pic->p->b_margin = 1;
1391 p_pic->p->b_hidden = 1;
1392 p_pic->p->i_visible_bytes = 4 * p_pic->p_sys->p_image->width;
1395 p_pic->p->i_red_mask = p_pic->p_sys->p_image->red_mask;
1396 p_pic->p->i_green_mask = p_pic->p_sys->p_image->green_mask;
1397 p_pic->p->i_blue_mask = p_pic->p_sys->p_image->blue_mask;
1399 p_pic->i_planes = 1;
1405 /* Unknown chroma, tell the guy to get lost */
1406 IMAGE_FREE( p_pic->p_sys->p_image );
1407 free( p_pic->p_sys );
1408 intf_ErrMsg( "vout error: never heard of chroma 0x%.8x (%4.4s)",
1409 p_vout->output.i_chroma,
1410 (char*)&p_vout->output.i_chroma );
1411 p_pic->i_planes = 0;
1418 /*****************************************************************************
1419 * FreePicture: destroy a picture allocated with NewPicture
1420 *****************************************************************************
1421 * Destroy XImage AND associated data. If using Shm, detach shared memory
1422 * segment from server and process, then free it. The XDestroyImage manpage
1423 * says that both the image structure _and_ the data pointed to by the
1424 * image structure are freed, so no need to free p_image->data.
1425 *****************************************************************************/
1426 static void FreePicture( vout_thread_t *p_vout, picture_t *p_pic )
1428 /* The order of operations is correct */
1429 if( p_vout->p_sys->b_shm )
1431 XShmDetach( p_vout->p_sys->p_display, &p_pic->p_sys->shminfo );
1432 IMAGE_FREE( p_pic->p_sys->p_image );
1434 shmctl( p_pic->p_sys->shminfo.shmid, IPC_RMID, 0 );
1435 if( shmdt( p_pic->p_sys->shminfo.shmaddr ) )
1437 intf_ErrMsg( "vout error: cannot detach shared memory (%s)",
1443 IMAGE_FREE( p_pic->p_sys->p_image );
1446 /* Do NOT use XFlush here ! */
1447 XSync( p_vout->p_sys->p_display, False );
1449 free( p_pic->p_sys );
1452 /*****************************************************************************
1453 * ToggleFullScreen: Enable or disable full screen mode
1454 *****************************************************************************
1455 * This function will switch between fullscreen and window mode.
1457 *****************************************************************************/
1458 static void ToggleFullScreen ( vout_thread_t *p_vout )
1461 mwmhints_t mwmhints;
1462 int i_xpos, i_ypos, i_width, i_height;
1464 #ifdef ALTERNATE_FULLSCREEN
1465 XSetWindowAttributes attributes;
1468 p_vout->b_fullscreen = !p_vout->b_fullscreen;
1470 if( p_vout->b_fullscreen )
1472 Window next_parent, parent, *p_dummy, dummy1;
1473 unsigned int dummy2, dummy3;
1475 intf_WarnMsg( 3, "vout: entering fullscreen mode" );
1477 /* Save current window coordinates so they can be restored when
1478 * we exit from fullscreen mode. This is the tricky part because
1479 * this heavily depends on the behaviour of the window manager.
1480 * When you use XMoveWindow some window managers will adjust the top
1481 * of the window to the coordinates you gave, but others will instead
1482 * adjust the top of the client area to the coordinates
1483 * (don't forget windows have decorations). */
1485 /* First, get the position and size of the client area */
1486 XGetGeometry( p_vout->p_sys->p_display,
1487 p_vout->p_sys->window,
1491 &p_vout->p_sys->i_width_backup_2,
1492 &p_vout->p_sys->i_height_backup_2,
1494 XTranslateCoordinates( p_vout->p_sys->p_display,
1495 p_vout->p_sys->window,
1496 DefaultRootWindow( p_vout->p_sys->p_display ),
1499 &p_vout->p_sys->i_xpos_backup_2,
1500 &p_vout->p_sys->i_ypos_backup_2,
1503 /* Then try to get the position and size of the whole window */
1505 /* find the real parent of our window (created by the window manager),
1506 * the one which is a direct child of the root window */
1507 next_parent = parent = p_vout->p_sys->window;
1508 while( next_parent != DefaultRootWindow( p_vout->p_sys->p_display ) )
1510 parent = next_parent;
1511 XQueryTree( p_vout->p_sys->p_display,
1517 XFree((void *)p_dummy);
1520 XGetGeometry( p_vout->p_sys->p_display,
1521 p_vout->p_sys->window,
1525 &p_vout->p_sys->i_width_backup,
1526 &p_vout->p_sys->i_height_backup,
1529 XTranslateCoordinates( p_vout->p_sys->p_display,
1531 DefaultRootWindow( p_vout->p_sys->p_display ),
1534 &p_vout->p_sys->i_xpos_backup,
1535 &p_vout->p_sys->i_ypos_backup,
1538 /* fullscreen window size and position */
1541 i_width = DisplayWidth( p_vout->p_sys->p_display,
1542 p_vout->p_sys->i_screen );
1543 i_height = DisplayHeight( p_vout->p_sys->p_display,
1544 p_vout->p_sys->i_screen );
1547 /* Being a transient window allows us to really be fullscreen (display
1548 * over the taskbar for instance) but then we end-up with the same
1549 * result as with the brute force method */
1550 XSetTransientForHint( p_vout->p_sys->p_display,
1551 p_vout->p_sys->window, None );
1556 intf_WarnMsg( 3, "vout: leaving fullscreen mode" );
1558 i_xpos = p_vout->p_sys->i_xpos_backup;
1559 i_ypos = p_vout->p_sys->i_ypos_backup;
1560 i_width = p_vout->p_sys->i_width_backup;
1561 i_height = p_vout->p_sys->i_height_backup;
1564 /* To my knowledge there are two ways to create a borderless window.
1565 * There's the generic way which is to tell x to bypass the window manager,
1566 * but this creates problems with the focus of other applications.
1567 * The other way is to use the motif property "_MOTIF_WM_HINTS" which
1568 * luckily seems to be supported by most window managers.
1570 #ifndef ALTERNATE_FULLSCREEN
1571 mwmhints.flags = MWM_HINTS_DECORATIONS;
1572 mwmhints.decorations = !p_vout->b_fullscreen;
1574 prop = XInternAtom( p_vout->p_sys->p_display, "_MOTIF_WM_HINTS",
1576 XChangeProperty( p_vout->p_sys->p_display, p_vout->p_sys->window,
1577 prop, prop, 32, PropModeReplace,
1578 (unsigned char *)&mwmhints,
1579 PROP_MWM_HINTS_ELEMENTS );
1582 /* brute force way to remove decorations */
1583 attributes.override_redirect = p_vout->b_fullscreen;
1584 XChangeWindowAttributes( p_vout->p_sys->p_display,
1585 p_vout->p_sys->window,
1590 /* We need to unmap and remap the window if we want the window
1591 * manager to take our changes into effect */
1592 XUnmapWindow( p_vout->p_sys->p_display, p_vout->p_sys->window);
1594 XWindowEvent( p_vout->p_sys->p_display, p_vout->p_sys->window,
1595 StructureNotifyMask, &xevent );
1596 while( xevent.type != UnmapNotify )
1597 XWindowEvent( p_vout->p_sys->p_display, p_vout->p_sys->window,
1598 StructureNotifyMask, &xevent );
1600 XMapRaised( p_vout->p_sys->p_display, p_vout->p_sys->window);
1602 while( xevent.type != MapNotify )
1603 XWindowEvent( p_vout->p_sys->p_display, p_vout->p_sys->window,
1604 StructureNotifyMask, &xevent );
1606 XMoveResizeWindow( p_vout->p_sys->p_display,
1607 p_vout->p_sys->window,
1613 /* Purge all ConfigureNotify events, this is needed to fix a bug where we
1614 * would lose the original size of the window */
1615 while( xevent.type != ConfigureNotify )
1616 XWindowEvent( p_vout->p_sys->p_display, p_vout->p_sys->window,
1617 StructureNotifyMask, &xevent );
1618 while( XCheckWindowEvent( p_vout->p_sys->p_display, p_vout->p_sys->window,
1619 StructureNotifyMask, &xevent ) );
1622 /* We need to check that the window was really restored where we wanted */
1623 if( !p_vout->b_fullscreen )
1626 unsigned int dummy2, dummy3, dummy4, dummy5;
1628 /* Check the position */
1629 XTranslateCoordinates( p_vout->p_sys->p_display,
1630 p_vout->p_sys->window,
1631 DefaultRootWindow( p_vout->p_sys->p_display ),
1637 if( dummy2 != p_vout->p_sys->i_xpos_backup_2 ||
1638 dummy3 != p_vout->p_sys->i_ypos_backup_2 )
1640 /* Ok it didn't work... second try */
1642 XMoveWindow( p_vout->p_sys->p_display,
1643 p_vout->p_sys->window,
1644 p_vout->p_sys->i_xpos_backup_2,
1645 p_vout->p_sys->i_ypos_backup_2 );
1647 /* Purge all ConfigureNotify events, this is needed to fix a bug
1648 * where we would lose the original size of the window */
1649 XWindowEvent( p_vout->p_sys->p_display, p_vout->p_sys->window,
1650 StructureNotifyMask, &xevent );
1651 while( xevent.type != ConfigureNotify )
1652 XWindowEvent( p_vout->p_sys->p_display, p_vout->p_sys->window,
1653 StructureNotifyMask, &xevent );
1654 while( XCheckWindowEvent( p_vout->p_sys->p_display,
1655 p_vout->p_sys->window,
1656 StructureNotifyMask, &xevent ) );
1659 /* Check the size */
1660 XGetGeometry( p_vout->p_sys->p_display,
1661 p_vout->p_sys->window,
1669 if( dummy4 != p_vout->p_sys->i_width_backup_2 ||
1670 dummy5 != p_vout->p_sys->i_height_backup_2 )
1672 /* Ok it didn't work... third try */
1674 XResizeWindow( p_vout->p_sys->p_display,
1675 p_vout->p_sys->window,
1676 p_vout->p_sys->i_width_backup_2,
1677 p_vout->p_sys->i_height_backup_2 );
1679 /* Purge all ConfigureNotify events, this is needed to fix a bug
1680 * where we would lose the original size of the window */
1681 XWindowEvent( p_vout->p_sys->p_display, p_vout->p_sys->window,
1682 StructureNotifyMask, &xevent );
1683 while( xevent.type != ConfigureNotify )
1684 XWindowEvent( p_vout->p_sys->p_display, p_vout->p_sys->window,
1685 StructureNotifyMask, &xevent );
1686 while( XCheckWindowEvent( p_vout->p_sys->p_display,
1687 p_vout->p_sys->window,
1688 StructureNotifyMask, &xevent ) );
1692 #ifdef ALTERNATE_FULLSCREEN
1693 XSetInputFocus(p_vout->p_sys->p_display,
1694 p_vout->p_sys->window,
1699 /* signal that the size needs to be updated */
1700 p_vout->p_sys->i_width = i_width;
1701 p_vout->p_sys->i_height = i_height;
1702 p_vout->i_changes |= VOUT_SIZE_CHANGE;
1706 /*****************************************************************************
1707 * EnableXScreenSaver: enable screen saver
1708 *****************************************************************************
1709 * This function enables the screen saver on a display after it has been
1710 * disabled by XDisableScreenSaver.
1711 * FIXME: what happens if multiple vlc sessions are running at the same
1713 *****************************************************************************/
1714 static void EnableXScreenSaver( vout_thread_t *p_vout )
1716 #ifdef DPMSINFO_IN_DPMS_H
1720 intf_DbgMsg( "vout: enabling screen saver" );
1721 XSetScreenSaver( p_vout->p_sys->p_display, p_vout->p_sys->i_ss_timeout,
1722 p_vout->p_sys->i_ss_interval,
1723 p_vout->p_sys->i_ss_blanking,
1724 p_vout->p_sys->i_ss_exposure );
1726 /* Restore DPMS settings */
1727 #ifdef DPMSINFO_IN_DPMS_H
1728 if( DPMSQueryExtension( p_vout->p_sys->p_display, &dummy, &dummy ) )
1730 if( p_vout->p_sys->b_ss_dpms )
1732 DPMSEnable( p_vout->p_sys->p_display );
1738 /*****************************************************************************
1739 * DisableXScreenSaver: disable screen saver
1740 *****************************************************************************
1741 * See XEnableXScreenSaver
1742 *****************************************************************************/
1743 static void DisableXScreenSaver( vout_thread_t *p_vout )
1745 #ifdef DPMSINFO_IN_DPMS_H
1749 /* Save screen saver informations */
1750 XGetScreenSaver( p_vout->p_sys->p_display, &p_vout->p_sys->i_ss_timeout,
1751 &p_vout->p_sys->i_ss_interval,
1752 &p_vout->p_sys->i_ss_blanking,
1753 &p_vout->p_sys->i_ss_exposure );
1755 /* Disable screen saver */
1756 intf_DbgMsg( "vout: disabling screen saver" );
1757 XSetScreenSaver( p_vout->p_sys->p_display, 0,
1758 p_vout->p_sys->i_ss_interval,
1759 p_vout->p_sys->i_ss_blanking,
1760 p_vout->p_sys->i_ss_exposure );
1763 #ifdef DPMSINFO_IN_DPMS_H
1764 if( DPMSQueryExtension( p_vout->p_sys->p_display, &dummy, &dummy ) )
1767 /* Save DPMS current state */
1768 DPMSInfo( p_vout->p_sys->p_display, &unused,
1769 &p_vout->p_sys->b_ss_dpms );
1770 intf_DbgMsg( "vout: disabling DPMS" );
1771 DPMSDisable( p_vout->p_sys->p_display );
1776 /*****************************************************************************
1777 * CreateCursor: create a blank mouse pointer
1778 *****************************************************************************/
1779 static void CreateCursor( vout_thread_t *p_vout )
1781 XColor cursor_color;
1783 p_vout->p_sys->cursor_pixmap =
1784 XCreatePixmap( p_vout->p_sys->p_display,
1785 DefaultRootWindow( p_vout->p_sys->p_display ),
1788 XParseColor( p_vout->p_sys->p_display,
1789 XCreateColormap( p_vout->p_sys->p_display,
1791 p_vout->p_sys->p_display ),
1793 p_vout->p_sys->p_display,
1794 p_vout->p_sys->i_screen ),
1796 "black", &cursor_color );
1798 p_vout->p_sys->blank_cursor =
1799 XCreatePixmapCursor( p_vout->p_sys->p_display,
1800 p_vout->p_sys->cursor_pixmap,
1801 p_vout->p_sys->cursor_pixmap,
1802 &cursor_color, &cursor_color, 1, 1 );
1805 /*****************************************************************************
1806 * DestroyCursor: destroy the blank mouse pointer
1807 *****************************************************************************/
1808 static void DestroyCursor( vout_thread_t *p_vout )
1810 XFreePixmap( p_vout->p_sys->p_display, p_vout->p_sys->cursor_pixmap );
1813 /*****************************************************************************
1814 * ToggleCursor: hide or show the mouse pointer
1815 *****************************************************************************
1816 * This function hides the X pointer if it is visible by setting the pointer
1817 * sprite to a blank one. To show it again, we disable the sprite.
1818 *****************************************************************************/
1819 static void ToggleCursor( vout_thread_t *p_vout )
1821 if( p_vout->p_sys->b_mouse_pointer_visible )
1823 XDefineCursor( p_vout->p_sys->p_display,
1824 p_vout->p_sys->window,
1825 p_vout->p_sys->blank_cursor );
1826 p_vout->p_sys->b_mouse_pointer_visible = 0;
1830 XUndefineCursor( p_vout->p_sys->p_display, p_vout->p_sys->window );
1831 p_vout->p_sys->b_mouse_pointer_visible = 1;
1835 #ifdef MODULE_NAME_IS_xvideo
1836 /*****************************************************************************
1837 * XVideoGetPort: get YUV12 port
1838 *****************************************************************************/
1839 static int XVideoGetPort( Display *dpy, u32 i_chroma, u32 *pi_newchroma )
1841 XvAdaptorInfo *p_adaptor;
1843 int i_adaptor, i_num_adaptors, i_requested_adaptor;
1844 int i_selected_port;
1846 switch( XvQueryExtension( dpy, &i, &i, &i, &i, &i ) )
1851 case XvBadExtension:
1852 intf_WarnMsg( 3, "vout error: XvBadExtension" );
1856 intf_WarnMsg( 3, "vout error: XvBadAlloc" );
1860 intf_WarnMsg( 3, "vout error: XvQueryExtension failed" );
1864 switch( XvQueryAdaptors( dpy, DefaultRootWindow( dpy ),
1865 &i_num_adaptors, &p_adaptor ) )
1870 case XvBadExtension:
1871 intf_WarnMsg( 3, "vout error: XvBadExtension for XvQueryAdaptors" );
1875 intf_WarnMsg( 3, "vout error: XvBadAlloc for XvQueryAdaptors" );
1879 intf_WarnMsg( 3, "vout error: XvQueryAdaptors failed" );
1883 i_selected_port = -1;
1884 i_requested_adaptor = main_GetIntVariable( VOUT_XVADAPTOR_VAR, -1 );
1886 for( i_adaptor = 0; i_adaptor < i_num_adaptors; ++i_adaptor )
1888 XvImageFormatValues *p_formats;
1889 int i_format, i_num_formats;
1892 /* If we requested an adaptor and it's not this one, we aren't
1894 if( i_requested_adaptor != -1 && i_adaptor != i_requested_adaptor )
1899 /* If the adaptor doesn't have the required properties, skip it */
1900 if( !( p_adaptor[ i_adaptor ].type & XvInputMask ) ||
1901 !( p_adaptor[ i_adaptor ].type & XvImageMask ) )
1906 /* Check that adaptor supports our requested format... */
1907 p_formats = XvListImageFormats( dpy, p_adaptor[i_adaptor].base_id,
1911 i_format < i_num_formats && ( i_selected_port == -1 );
1914 /* Code removed, we can get this through xvinfo anyway */
1916 XvEncodingInfo *p_enc;
1917 int i_enc, i_num_encodings;
1918 XvAttribute *p_attr;
1919 int i_attr, i_num_attributes;
1922 /* If this is not the format we want, or at least a
1923 * similar one, forget it */
1924 if( !vout_ChromaCmp( p_formats[ i_format ].id, i_chroma ) )
1929 /* Look for the first available port supporting this format */
1930 for( i_port = p_adaptor[i_adaptor].base_id;
1931 ( i_port < p_adaptor[i_adaptor].base_id
1932 + p_adaptor[i_adaptor].num_ports )
1933 && ( i_selected_port == -1 );
1936 if( XvGrabPort( dpy, i_port, CurrentTime ) == Success )
1938 i_selected_port = i_port;
1939 *pi_newchroma = p_formats[ i_format ].id;
1943 /* If no free port was found, forget it */
1944 if( i_selected_port == -1 )
1949 /* If we found a port, print information about it */
1950 intf_WarnMsg( 3, "vout: found adaptor %i, port %i, "
1951 "image format 0x%x (%4.4s) %s",
1952 i_adaptor, i_selected_port,
1953 p_formats[ i_format ].id,
1954 (char *)&p_formats[ i_format ].id,
1955 ( p_formats[ i_format ].format
1956 == XvPacked ) ? "packed" : "planar" );
1959 intf_WarnMsg( 10, " encoding list:" );
1961 if( XvQueryEncodings( dpy, i_selected_port,
1962 &i_num_encodings, &p_enc )
1965 intf_WarnMsg( 10, " XvQueryEncodings failed" );
1969 for( i_enc = 0; i_enc < i_num_encodings; i_enc++ )
1971 intf_WarnMsg( 10, " id=%ld, name=%s, size=%ldx%ld,"
1972 " numerator=%d, denominator=%d",
1973 p_enc[i_enc].encoding_id, p_enc[i_enc].name,
1974 p_enc[i_enc].width, p_enc[i_enc].height,
1975 p_enc[i_enc].rate.numerator,
1976 p_enc[i_enc].rate.denominator );
1981 XvFreeEncodingInfo( p_enc );
1984 intf_WarnMsg( 10, " attribute list:" );
1985 p_attr = XvQueryPortAttributes( dpy, i_selected_port,
1986 &i_num_attributes );
1987 for( i_attr = 0; i_attr < i_num_attributes; i_attr++ )
1990 " name=%s, flags=[%s%s ], min=%i, max=%i",
1991 p_attr[i_attr].name,
1992 (p_attr[i_attr].flags & XvGettable) ? " get" : "",
1993 (p_attr[i_attr].flags & XvSettable) ? " set" : "",
1994 p_attr[i_attr].min_value, p_attr[i_attr].max_value );
1997 if( p_attr != NULL )
2004 if( p_formats != NULL )
2011 if( i_num_adaptors > 0 )
2013 XvFreeAdaptorInfo( p_adaptor );
2016 if( i_selected_port == -1 )
2018 if( i_requested_adaptor == -1 )
2020 intf_WarnMsg( 3, "vout: no free XVideo port found for format "
2021 "0x%.8x (%4.4s)", i_chroma, (char*)&i_chroma );
2025 intf_WarnMsg( 3, "vout: XVideo adaptor %i does not have a free "
2026 "XVideo port for format 0x%.8x (%4.4s)",
2027 i_requested_adaptor, i_chroma, (char*)&i_chroma );
2031 return( i_selected_port );
2034 /*****************************************************************************
2035 * XVideoReleasePort: release YUV12 port
2036 *****************************************************************************/
2037 static void XVideoReleasePort( Display *dpy, int i_port )
2039 XvUngrabPort( dpy, i_port, CurrentTime );
2043 /*****************************************************************************
2044 * InitDisplay: open and initialize X11 device
2045 *****************************************************************************
2046 * Create a window according to video output given size, and set other
2047 * properties according to the display properties.
2048 *****************************************************************************/
2049 static int InitDisplay( vout_thread_t *p_vout )
2051 #ifdef MODULE_NAME_IS_x11
2052 XPixmapFormatValues * p_formats; /* pixmap formats */
2053 XVisualInfo * p_xvisual; /* visuals informations */
2054 XVisualInfo xvisual_template; /* visual template */
2055 int i_count; /* array size */
2059 /* FIXME : As of 2001-03-16, XFree4 for MacOS X does not support Xshm. */
2060 p_vout->p_sys->b_shm = 0;
2062 p_vout->p_sys->b_shm = ( XShmQueryExtension( p_vout->p_sys->p_display )
2065 if( !p_vout->p_sys->b_shm )
2067 intf_WarnMsg( 1, "vout warning: XShm video extension is unavailable" );
2070 #ifdef MODULE_NAME_IS_xvideo
2071 /* XXX The brightness and contrast values should be read from environment
2072 * XXX variables... */
2074 XVideoSetAttribute( p_vout, "XV_BRIGHTNESS", 0.5 );
2075 XVideoSetAttribute( p_vout, "XV_CONTRAST", 0.5 );
2079 #ifdef MODULE_NAME_IS_x11
2080 /* Initialize structure */
2081 p_vout->p_sys->i_screen = DefaultScreen( p_vout->p_sys->p_display );
2083 /* Get screen depth */
2084 p_vout->p_sys->i_screen_depth = XDefaultDepth( p_vout->p_sys->p_display,
2085 p_vout->p_sys->i_screen );
2086 switch( p_vout->p_sys->i_screen_depth )
2090 * Screen depth is 8bpp. Use PseudoColor visual with private colormap.
2092 xvisual_template.screen = p_vout->p_sys->i_screen;
2093 xvisual_template.class = DirectColor;
2094 p_xvisual = XGetVisualInfo( p_vout->p_sys->p_display,
2095 VisualScreenMask | VisualClassMask,
2096 &xvisual_template, &i_count );
2097 if( p_xvisual == NULL )
2099 intf_ErrMsg( "vout error: no PseudoColor visual available" );
2102 p_vout->p_sys->i_bytes_per_pixel = 1;
2109 * Screen depth is higher than 8bpp. TrueColor visual is used.
2111 xvisual_template.screen = p_vout->p_sys->i_screen;
2112 xvisual_template.class = TrueColor;
2113 p_xvisual = XGetVisualInfo( p_vout->p_sys->p_display,
2114 VisualScreenMask | VisualClassMask,
2115 &xvisual_template, &i_count );
2116 if( p_xvisual == NULL )
2118 intf_ErrMsg( "vout error: no TrueColor visual available" );
2121 p_vout->p_sys->i_red_mask = p_xvisual->red_mask;
2122 p_vout->p_sys->i_green_mask = p_xvisual->green_mask;
2123 p_vout->p_sys->i_blue_mask = p_xvisual->blue_mask;
2125 /* There is no difference yet between 3 and 4 Bpp. The only way
2126 * to find the actual number of bytes per pixel is to list supported
2127 * pixmap formats. */
2128 p_formats = XListPixmapFormats( p_vout->p_sys->p_display, &i_count );
2129 p_vout->p_sys->i_bytes_per_pixel = 0;
2131 for( ; i_count-- ; p_formats++ )
2133 /* Under XFree4.0, the list contains pixmap formats available
2134 * through all video depths ; so we have to check against current
2136 if( p_formats->depth == p_vout->p_sys->i_screen_depth )
2138 if( p_formats->bits_per_pixel / 8
2139 > p_vout->p_sys->i_bytes_per_pixel )
2141 p_vout->p_sys->i_bytes_per_pixel = p_formats->bits_per_pixel / 8;
2147 p_vout->p_sys->p_visual = p_xvisual->visual;
2154 /*****************************************************************************
2155 * CreateShmImage: create an XImage or XvImage using shared memory extension
2156 *****************************************************************************
2157 * Prepare an XImage or XvImage for display function.
2158 * The order of the operations respects the recommandations of the mit-shm
2159 * document by J.Corbet and K.Packard. Most of the parameters were copied from
2160 * there. See http://ftp.xfree86.org/pub/XFree86/4.0/doc/mit-shm.TXT
2161 *****************************************************************************/
2162 static IMAGE_TYPE * CreateShmImage( Display* p_display, EXTRA_ARGS_SHM,
2163 int i_width, int i_height )
2165 IMAGE_TYPE *p_image;
2167 /* Create XImage / XvImage */
2168 #ifdef MODULE_NAME_IS_xvideo
2169 p_image = XvShmCreateImage( p_display, i_xvport, i_chroma, 0,
2170 i_width, i_height, p_shm );
2172 p_image = XShmCreateImage( p_display, p_visual, i_depth, ZPixmap, 0,
2173 p_shm, i_width, i_height );
2175 if( p_image == NULL )
2177 intf_ErrMsg( "vout error: image creation failed." );
2181 /* Allocate shared memory segment - 0776 set the access permission
2182 * rights (like umask), they are not yet supported by all X servers */
2183 p_shm->shmid = shmget( IPC_PRIVATE, DATA_SIZE(p_image), IPC_CREAT | 0776 );
2184 if( p_shm->shmid < 0 )
2186 intf_ErrMsg( "vout error: cannot allocate shared image data (%s)",
2187 strerror( errno ) );
2188 IMAGE_FREE( p_image );
2192 /* Attach shared memory segment to process (read/write) */
2193 p_shm->shmaddr = p_image->data = shmat( p_shm->shmid, 0, 0 );
2194 if(! p_shm->shmaddr )
2196 intf_ErrMsg( "vout error: cannot attach shared memory (%s)",
2198 IMAGE_FREE( p_image );
2199 shmctl( p_shm->shmid, IPC_RMID, 0 );
2203 /* Read-only data. We won't be using XShmGetImage */
2204 p_shm->readOnly = True;
2206 /* Attach shared memory segment to X server */
2207 if( XShmAttach( p_display, p_shm ) == False )
2209 intf_ErrMsg( "vout error: cannot attach shared memory to X server" );
2210 IMAGE_FREE( p_image );
2211 shmctl( p_shm->shmid, IPC_RMID, 0 );
2212 shmdt( p_shm->shmaddr );
2216 /* Send image to X server. This instruction is required, since having
2217 * built a Shm XImage and not using it causes an error on XCloseDisplay,
2218 * and remember NOT to use XFlush ! */
2219 XSync( p_display, False );
2222 /* Mark the shm segment to be removed when there are no more
2223 * attachements, so it is automatic on process exit or after shmdt */
2224 shmctl( p_shm->shmid, IPC_RMID, 0 );
2230 /*****************************************************************************
2231 * CreateImage: create an XImage or XvImage
2232 *****************************************************************************
2233 * Create a simple image used as a buffer.
2234 *****************************************************************************/
2235 static IMAGE_TYPE * CreateImage( Display *p_display, EXTRA_ARGS,
2236 int i_width, int i_height )
2238 byte_t * p_data; /* image data storage zone */
2239 IMAGE_TYPE *p_image;
2240 #ifdef MODULE_NAME_IS_x11
2241 int i_quantum; /* XImage quantum (see below) */
2242 int i_bytes_per_line;
2245 /* Allocate memory for image */
2246 #ifdef MODULE_NAME_IS_xvideo
2247 p_data = (byte_t *) malloc( i_width * i_height * 2 ); /* XXX */
2249 i_bytes_per_line = i_width * i_bytes_per_pixel;
2250 p_data = (byte_t *) malloc( i_bytes_per_line * i_height );
2254 intf_ErrMsg( "vout error: %s", strerror(ENOMEM));
2258 #ifdef MODULE_NAME_IS_x11
2259 /* Optimize the quantum of a scanline regarding its size - the quantum is
2260 a diviser of the number of bits between the start of two scanlines. */
2261 if( i_bytes_per_line & 0xf )
2265 else if( i_bytes_per_line & 0x10 )
2275 /* Create XImage. p_data will be automatically freed */
2276 #ifdef MODULE_NAME_IS_xvideo
2277 p_image = XvCreateImage( p_display, i_xvport, i_chroma,
2278 p_data, i_width, i_height );
2280 p_image = XCreateImage( p_display, p_visual, i_depth, ZPixmap, 0,
2281 p_data, i_width, i_height, i_quantum, 0 );
2283 if( p_image == NULL )
2285 intf_ErrMsg( "vout error: XCreateImage() failed" );