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.29 2002/04/28 11:56:13 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 */
48 # include <sys/shm.h> /* shmget(), shmctl() */
52 #include <X11/Xutil.h>
53 #include <X11/keysym.h>
55 # include <X11/extensions/XShm.h>
57 #ifdef DPMSINFO_IN_DPMS_H
58 # include <X11/extensions/dpms.h>
61 #ifdef MODULE_NAME_IS_xvideo
62 # include <X11/extensions/Xv.h>
63 # include <X11/extensions/Xvlib.h>
67 #include "video_output.h"
70 #include "interface.h"
71 #include "netutils.h" /* network_ChannelJoin */
73 #include "stream_control.h" /* needed by input_ext-intf.h... */
74 #include "input_ext-intf.h"
76 #ifdef MODULE_NAME_IS_xvideo
77 # define IMAGE_TYPE XvImage
78 # define EXTRA_ARGS int i_xvport, int i_chroma
79 # define EXTRA_ARGS_SHM int i_xvport, int i_chroma, XShmSegmentInfo *p_shm
80 # define DATA_SIZE(p) (p)->data_size
81 # define IMAGE_FREE XFree /* There is nothing like XvDestroyImage */
83 # define IMAGE_TYPE XImage
84 # define EXTRA_ARGS Visual *p_visual, int i_depth, int i_bytes_per_pixel
85 # define EXTRA_ARGS_SHM Visual *p_visual, int i_depth, XShmSegmentInfo *p_shm
86 # define DATA_SIZE(p) ((p)->bytes_per_line * (p)->height)
87 # define IMAGE_FREE XDestroyImage
90 /*****************************************************************************
92 *****************************************************************************/
93 static int vout_Create ( vout_thread_t * );
94 static void vout_Destroy ( vout_thread_t * );
95 static void vout_Render ( vout_thread_t *, picture_t * );
96 static void vout_Display ( vout_thread_t *, picture_t * );
97 static int vout_Manage ( vout_thread_t * );
98 static int vout_Init ( vout_thread_t * );
99 static void vout_End ( vout_thread_t * );
101 static int InitDisplay ( vout_thread_t * );
103 static int CreateWindow ( vout_thread_t * );
104 static void DestroyWindow ( vout_thread_t * );
106 static int NewPicture ( vout_thread_t *, picture_t * );
107 static void FreePicture ( vout_thread_t *, picture_t * );
109 static IMAGE_TYPE *CreateImage ( Display *, EXTRA_ARGS, int, int );
110 #ifdef HAVE_SYS_SHM_H
111 static IMAGE_TYPE *CreateShmImage ( Display *, EXTRA_ARGS_SHM, int, int );
114 static void ToggleFullScreen ( vout_thread_t * );
116 static void EnableXScreenSaver ( vout_thread_t * );
117 static void DisableXScreenSaver ( vout_thread_t * );
119 static void CreateCursor ( vout_thread_t * );
120 static void DestroyCursor ( vout_thread_t * );
121 static void ToggleCursor ( vout_thread_t * );
123 #ifdef MODULE_NAME_IS_xvideo
124 static int XVideoGetPort ( Display *, u32, u32 * );
125 static void XVideoReleasePort ( Display *, int );
128 #ifdef MODULE_NAME_IS_x11
129 static void SetPalette ( vout_thread_t *, u16 *, u16 *, u16 * );
132 /*****************************************************************************
133 * vout_sys_t: video output method descriptor
134 *****************************************************************************
135 * This structure is part of the video output thread descriptor.
136 * It describes the X11 and XVideo specific properties of an output thread.
137 *****************************************************************************/
138 typedef struct vout_sys_s
140 /* Internal settings and properties */
141 Display * p_display; /* display pointer */
143 Visual * p_visual; /* visual pointer */
144 int i_screen; /* screen number */
145 Window window; /* root window */
146 GC gc; /* graphic context instance handler */
148 #ifdef HAVE_SYS_SHM_H
149 boolean_t b_shm; /* shared memory extension flag */
152 #ifdef MODULE_NAME_IS_xvideo
153 Window yuv_window; /* sub-window for displaying yuv video
157 Colormap colormap; /* colormap used (8bpp only) */
160 int i_bytes_per_pixel;
161 int i_bytes_per_line;
164 /* X11 generic properties */
166 Atom wm_delete_window;
168 int i_width; /* width of main window */
169 int i_height; /* height of main window */
170 boolean_t b_altfullscreen; /* which fullscreen method */
172 /* Backup of window position and size before fullscreen switch */
177 int i_width_backup_2;
178 int i_height_backup_2;
182 /* Screen saver properties */
183 int i_ss_timeout; /* timeout */
184 int i_ss_interval; /* interval between changes */
185 int i_ss_blanking; /* blanking mode */
186 int i_ss_exposure; /* exposure mode */
187 #ifdef DPMSINFO_IN_DPMS_H
188 BOOL b_ss_dpms; /* DPMS mode */
191 /* Mouse pointer properties */
192 boolean_t b_mouse_pointer_visible;
193 mtime_t i_time_mouse_last_moved; /* used to auto-hide pointer*/
194 Cursor blank_cursor; /* the hidden cursor */
195 Pixmap cursor_pixmap;
199 /*****************************************************************************
200 * picture_sys_t: direct buffer method descriptor
201 *****************************************************************************
202 * This structure is part of the picture descriptor, it describes the
203 * XVideo specific properties of a direct buffer.
204 *****************************************************************************/
205 typedef struct picture_sys_s
207 IMAGE_TYPE * p_image;
209 #ifdef HAVE_SYS_SHM_H
210 XShmSegmentInfo shminfo; /* shared memory zone information */
215 /*****************************************************************************
216 * mwmhints_t: window manager hints
217 *****************************************************************************
218 * Fullscreen needs to be able to hide the wm decorations so we provide
219 * this structure to make it easier.
220 *****************************************************************************/
221 #define MWM_HINTS_DECORATIONS (1L << 1)
222 #define PROP_MWM_HINTS_ELEMENTS 5
223 typedef struct mwmhints_s
232 /*****************************************************************************
234 *****************************************************************************/
235 #ifdef MODULE_NAME_IS_xvideo
236 # define MAX_DIRECTBUFFERS 10
238 # define MAX_DIRECTBUFFERS 2
241 /*****************************************************************************
242 * Seeking function TODO: put this in a generic location !
243 *****************************************************************************/
244 static __inline__ void vout_Seek( off_t i_seek )
248 vlc_mutex_lock( &p_input_bank->lock );
249 if( p_input_bank->pp_input[0] != NULL )
251 #define S p_input_bank->pp_input[0]->stream
252 i_tell = S.p_selected_area->i_tell + i_seek * (off_t)50 * S.i_mux_rate;
254 i_tell = ( i_tell <= 0 /*S.p_selected_area->i_start*/ )
255 ? 0 /*S.p_selected_area->i_start*/
256 : ( i_tell >= S.p_selected_area->i_size )
257 ? S.p_selected_area->i_size
260 input_Seek( p_input_bank->pp_input[0], i_tell );
263 vlc_mutex_unlock( &p_input_bank->lock );
266 /*****************************************************************************
267 * Functions exported as capabilities. They are declared as static so that
268 * we don't pollute the namespace too much.
269 *****************************************************************************/
270 void _M( vout_getfunctions )( function_list_t * p_function_list )
272 p_function_list->functions.vout.pf_create = vout_Create;
273 p_function_list->functions.vout.pf_init = vout_Init;
274 p_function_list->functions.vout.pf_end = vout_End;
275 p_function_list->functions.vout.pf_destroy = vout_Destroy;
276 p_function_list->functions.vout.pf_manage = vout_Manage;
277 p_function_list->functions.vout.pf_render = vout_Render;
278 p_function_list->functions.vout.pf_display = vout_Display;
281 /*****************************************************************************
282 * vout_Create: allocate X11 video thread output method
283 *****************************************************************************
284 * This function allocate and initialize a X11 vout method. It uses some of the
285 * vout properties to choose the window size, and change them according to the
286 * actual properties of the display.
287 *****************************************************************************/
288 static int vout_Create( vout_thread_t *p_vout )
292 /* Allocate structure */
293 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
294 if( p_vout->p_sys == NULL )
296 intf_ErrMsg( "vout error: %s", strerror(ENOMEM) );
300 /* Open display, unsing the "display" config variable or the DISPLAY
301 * environment variable */
302 psz_display = config_GetPszVariable( MODULE_STRING "-display" );
304 p_vout->p_sys->p_display = XOpenDisplay( psz_display );
306 if( p_vout->p_sys->p_display == NULL ) /* error */
308 intf_ErrMsg( "vout error: cannot open display %s",
309 XDisplayName( psz_display ) );
310 free( p_vout->p_sys );
311 if( psz_display ) free( psz_display );
314 if( psz_display ) free( psz_display );
316 p_vout->p_sys->i_screen = DefaultScreen( p_vout->p_sys->p_display );
318 #ifdef MODULE_NAME_IS_xvideo
319 /* Check that we have access to an XVideo port providing this chroma */
320 p_vout->p_sys->i_xvport = XVideoGetPort( p_vout->p_sys->p_display,
321 p_vout->render.i_chroma,
322 &p_vout->output.i_chroma );
323 if( p_vout->p_sys->i_xvport < 0 )
325 /* It failed, but it's not completely lost ! We try to open an
326 * XVideo port for an YUY2 picture. We'll need to do an YUV
327 * conversion, but at least it has got scaling. */
328 p_vout->p_sys->i_xvport = XVideoGetPort( p_vout->p_sys->p_display,
330 &p_vout->output.i_chroma );
331 if( p_vout->p_sys->i_xvport < 0 )
333 /* It failed, but it's not completely lost ! We try to open an
334 * XVideo port for a simple 16bpp RGB picture. We'll need to do
335 * an YUV conversion, but at least it has got scaling. */
336 p_vout->p_sys->i_xvport = XVideoGetPort( p_vout->p_sys->p_display,
338 &p_vout->output.i_chroma );
339 if( p_vout->p_sys->i_xvport < 0 )
341 XCloseDisplay( p_vout->p_sys->p_display );
342 free( p_vout->p_sys );
349 /* Create blank cursor (for mouse cursor autohiding) */
350 p_vout->p_sys->i_time_mouse_last_moved = mdate();
351 p_vout->p_sys->b_mouse_pointer_visible = 1;
352 CreateCursor( p_vout );
354 /* Spawn base window - this window will include the video output window,
355 * but also command buttons, subtitles and other indicators */
356 if( CreateWindow( p_vout ) )
358 intf_ErrMsg( "vout error: cannot create X11 window" );
359 DestroyCursor( p_vout );
360 XCloseDisplay( p_vout->p_sys->p_display );
361 free( p_vout->p_sys );
365 /* Open and initialize device. */
366 if( InitDisplay( p_vout ) )
368 intf_ErrMsg( "vout error: cannot initialize X11 display" );
369 DestroyCursor( p_vout );
370 DestroyWindow( p_vout );
371 XCloseDisplay( p_vout->p_sys->p_display );
372 free( p_vout->p_sys );
376 /* Disable screen saver */
377 DisableXScreenSaver( p_vout );
380 p_vout->p_sys->b_altfullscreen = 0;
385 /*****************************************************************************
386 * vout_Destroy: destroy X11 video thread output method
387 *****************************************************************************
388 * Terminate an output method created by vout_CreateOutputMethod
389 *****************************************************************************/
390 static void vout_Destroy( vout_thread_t *p_vout )
392 /* Restore cursor if it was blanked */
393 if( !p_vout->p_sys->b_mouse_pointer_visible )
395 ToggleCursor( p_vout );
398 #ifdef MODULE_NAME_IS_x11
399 /* Destroy colormap */
400 if( XDefaultDepth(p_vout->p_sys->p_display, p_vout->p_sys->i_screen) == 8 )
402 XFreeColormap( p_vout->p_sys->p_display, p_vout->p_sys->colormap );
405 XVideoReleasePort( p_vout->p_sys->p_display, p_vout->p_sys->i_xvport );
408 DestroyCursor( p_vout );
409 EnableXScreenSaver( p_vout );
410 DestroyWindow( p_vout );
412 XCloseDisplay( p_vout->p_sys->p_display );
414 /* Destroy structure */
415 free( p_vout->p_sys );
418 /*****************************************************************************
419 * vout_Init: initialize X11 video thread output method
420 *****************************************************************************
421 * This function create the XImages needed by the output thread. It is called
422 * at the beginning of the thread, but also each time the window is resized.
423 *****************************************************************************/
424 static int vout_Init( vout_thread_t *p_vout )
429 I_OUTPUTPICTURES = 0;
431 #ifdef MODULE_NAME_IS_xvideo
432 /* Initialize the output structure; we already found an XVideo port,
433 * and the corresponding chroma we will be using. Since we can
434 * arbitrary scale, stick to the coordinates and aspect. */
435 p_vout->output.i_width = p_vout->render.i_width;
436 p_vout->output.i_height = p_vout->render.i_height;
437 p_vout->output.i_aspect = p_vout->render.i_aspect;
439 switch( p_vout->output.i_chroma )
442 p_vout->output.i_rmask = 0x001f;
443 p_vout->output.i_gmask = 0x07e0;
444 p_vout->output.i_bmask = 0xf800;
447 p_vout->output.i_rmask = 0x001f;
448 p_vout->output.i_gmask = 0x03e0;
449 p_vout->output.i_bmask = 0x7c00;
454 /* Initialize the output structure: RGB with square pixels, whatever
455 * the input format is, since it's the only format we know */
456 switch( p_vout->p_sys->i_screen_depth )
458 case 8: /* FIXME: set the palette */
459 p_vout->output.i_chroma = FOURCC_RGB2; break;
461 p_vout->output.i_chroma = FOURCC_RV15; break;
463 p_vout->output.i_chroma = FOURCC_RV16; break;
465 p_vout->output.i_chroma = FOURCC_RV24; break;
467 p_vout->output.i_chroma = FOURCC_RV24; break;
469 intf_ErrMsg( "vout error: unknown screen depth" );
473 p_vout->output.i_width = p_vout->p_sys->i_width;
474 p_vout->output.i_height = p_vout->p_sys->i_height;
476 /* Assume we have square pixels */
477 p_vout->output.i_aspect = p_vout->p_sys->i_width
478 * VOUT_ASPECT_FACTOR / p_vout->p_sys->i_height;
481 /* Try to initialize up to MAX_DIRECTBUFFERS direct buffers */
482 while( I_OUTPUTPICTURES < MAX_DIRECTBUFFERS )
486 /* Find an empty picture slot */
487 for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
489 if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
491 p_pic = p_vout->p_picture + i_index;
496 /* Allocate the picture */
497 if( p_pic == NULL || NewPicture( p_vout, p_pic ) )
502 p_pic->i_status = DESTROYED_PICTURE;
503 p_pic->i_type = DIRECT_PICTURE;
505 PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
513 /*****************************************************************************
514 * vout_Render: render previously calculated output
515 *****************************************************************************/
516 static void vout_Render( vout_thread_t *p_vout, picture_t *p_pic )
521 /*****************************************************************************
522 * vout_Display: displays previously rendered output
523 *****************************************************************************
524 * This function sends the currently rendered image to X11 server.
525 * (The Xv extension takes care of "double-buffering".)
526 *****************************************************************************/
527 static void vout_Display( vout_thread_t *p_vout, picture_t *p_pic )
529 int i_width, i_height, i_x, i_y;
531 vout_PlacePicture( p_vout, p_vout->p_sys->i_width, p_vout->p_sys->i_height,
532 &i_x, &i_y, &i_width, &i_height );
534 #ifdef HAVE_SYS_SHM_H
535 if( p_vout->p_sys->b_shm )
537 /* Display rendered image using shared memory extension */
538 # ifdef MODULE_NAME_IS_xvideo
539 XvShmPutImage( p_vout->p_sys->p_display, p_vout->p_sys->i_xvport,
540 p_vout->p_sys->yuv_window, p_vout->p_sys->gc,
541 p_pic->p_sys->p_image, 0 /*src_x*/, 0 /*src_y*/,
542 p_vout->output.i_width, p_vout->output.i_height,
543 0 /*dest_x*/, 0 /*dest_y*/, i_width, i_height,
544 False /* Don't put True here or you'll waste your CPU */ );
546 XShmPutImage( p_vout->p_sys->p_display, p_vout->p_sys->window,
547 p_vout->p_sys->gc, p_pic->p_sys->p_image,
548 0 /*src_x*/, 0 /*src_y*/, 0 /*dest_x*/, 0 /*dest_y*/,
549 p_vout->output.i_width, p_vout->output.i_height,
550 False /* Don't put True here ! */ );
554 #endif /* HAVE_SYS_SHM_H */
556 /* Use standard XPutImage -- this is gonna be slow ! */
557 #ifdef MODULE_NAME_IS_xvideo
558 XvPutImage( p_vout->p_sys->p_display, p_vout->p_sys->i_xvport,
559 p_vout->p_sys->yuv_window, p_vout->p_sys->gc,
560 p_pic->p_sys->p_image, 0 /*src_x*/, 0 /*src_y*/,
561 p_vout->output.i_width, p_vout->output.i_height,
562 0 /*dest_x*/, 0 /*dest_y*/, i_width, i_height );
564 XPutImage( p_vout->p_sys->p_display, p_vout->p_sys->window,
565 p_vout->p_sys->gc, p_pic->p_sys->p_image,
566 0 /*src_x*/, 0 /*src_y*/, 0 /*dest_x*/, 0 /*dest_y*/,
567 p_vout->output.i_width, p_vout->output.i_height );
571 /* Make sure the command is sent now - do NOT use XFlush !*/
572 XSync( p_vout->p_sys->p_display, False );
575 /*****************************************************************************
576 * vout_Manage: handle X11 events
577 *****************************************************************************
578 * This function should be called regularly by video output thread. It manages
579 * X11 events and allows window resizing. It returns a non null value on
581 *****************************************************************************/
582 static int vout_Manage( vout_thread_t *p_vout )
584 XEvent xevent; /* X11 event */
585 boolean_t b_resized; /* window has been resized */
586 char i_key; /* ISO Latin-1 key */
589 /* Handle X11 events: ConfigureNotify events are parsed to know if the
590 * output window's size changed, MapNotify and UnmapNotify to know if the
591 * window is mapped (and if the display is useful), and ClientMessages
592 * to intercept window destruction requests */
595 while( XCheckWindowEvent( p_vout->p_sys->p_display, p_vout->p_sys->window,
596 StructureNotifyMask | KeyPressMask |
597 ButtonPressMask | ButtonReleaseMask |
598 PointerMotionMask | Button1MotionMask , &xevent )
601 /* ConfigureNotify event: prepare */
602 if( xevent.type == ConfigureNotify )
604 if( (xevent.xconfigure.width != p_vout->p_sys->i_width)
605 || (xevent.xconfigure.height != p_vout->p_sys->i_height) )
607 /* Update dimensions */
609 p_vout->i_changes |= VOUT_SIZE_CHANGE;
610 p_vout->p_sys->i_width = xevent.xconfigure.width;
611 p_vout->p_sys->i_height = xevent.xconfigure.height;
614 /* MapNotify event: change window status and disable screen saver */
615 else if( xevent.type == MapNotify)
617 if( (p_vout != NULL) && !p_vout->b_active )
619 DisableXScreenSaver( p_vout );
620 p_vout->b_active = 1;
623 /* UnmapNotify event: change window status and enable screen saver */
624 else if( xevent.type == UnmapNotify )
626 if( (p_vout != NULL) && p_vout->b_active )
628 EnableXScreenSaver( p_vout );
629 p_vout->b_active = 0;
633 else if( xevent.type == KeyPress )
635 /* We may have keys like F1 trough F12, ESC ... */
636 x_key_symbol = XKeycodeToKeysym( p_vout->p_sys->p_display,
637 xevent.xkey.keycode, 0 );
638 switch( x_key_symbol )
641 if( p_vout->b_fullscreen )
643 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
647 p_main->p_intf->b_die = 1;
651 p_main->p_intf->b_menu_change = 1;
666 input_Seek( p_input_bank->pp_input[0],
667 p_input_bank->pp_input[0]->stream.p_selected_area->i_start );
670 input_Seek( p_input_bank->pp_input[0],
671 p_input_bank->pp_input[0]->stream.p_selected_area->i_size );
680 input_SetStatus( p_input_bank->pp_input[0],
681 INPUT_STATUS_PAUSE );
686 * The reason why I use this instead of XK_0 is that
687 * with XLookupString, we don't have to care about
690 if( XLookupString( &xevent.xkey, &i_key, 1, NULL, NULL ) )
692 /* FIXME: handle stuff here */
697 p_main->p_intf->b_die = 1;
701 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
704 case '0': network_ChannelJoin( 0 ); break;
705 case '1': network_ChannelJoin( 1 ); break;
706 case '2': network_ChannelJoin( 2 ); break;
707 case '3': network_ChannelJoin( 3 ); break;
708 case '4': network_ChannelJoin( 4 ); break;
709 case '5': network_ChannelJoin( 5 ); break;
710 case '6': network_ChannelJoin( 6 ); break;
711 case '7': network_ChannelJoin( 7 ); break;
712 case '8': network_ChannelJoin( 8 ); break;
713 case '9': network_ChannelJoin( 9 ); break;
723 else if( xevent.type == ButtonPress )
725 switch( ((XButtonEvent *)&xevent)->button )
728 /* In this part we will eventually manage
729 * clicks for DVD navigation for instance. For the
730 * moment just pause the stream. */
731 input_SetStatus( p_input_bank->pp_input[0],
732 INPUT_STATUS_PAUSE );
745 else if( xevent.type == ButtonRelease )
747 switch( ((XButtonEvent *)&xevent)->button )
750 /* FIXME: need locking ! */
751 p_main->p_intf->b_menu_change = 1;
756 else if( xevent.type == MotionNotify )
758 p_vout->p_sys->i_time_mouse_last_moved = mdate();
759 if( ! p_vout->p_sys->b_mouse_pointer_visible )
761 ToggleCursor( p_vout );
764 /* Reparent move -- XXX: why are we getting this ? */
765 else if( xevent.type == ReparentNotify )
772 intf_WarnMsg( 3, "vout: unhandled event %d received", xevent.type );
776 #ifdef MODULE_NAME_IS_xvideo
777 /* Handle events for YUV video output sub-window */
778 while( XCheckWindowEvent( p_vout->p_sys->p_display,
779 p_vout->p_sys->yuv_window,
780 ExposureMask, &xevent ) == True )
782 /* Window exposed (only handled if stream playback is paused) */
783 if( xevent.type == Expose )
785 if( ((XExposeEvent *)&xevent)->count == 0 )
787 /* (if this is the last a collection of expose events...) */
788 if( p_input_bank->pp_input[0] != NULL )
791 p_input_bank->pp_input[0]->stream.control.i_status )
793 /* XVideoDisplay( p_vout )*/;
801 /* ClientMessage event - only WM_PROTOCOLS with WM_DELETE_WINDOW data
802 * are handled - according to the man pages, the format is always 32
804 while( XCheckTypedEvent( p_vout->p_sys->p_display,
805 ClientMessage, &xevent ) )
807 if( (xevent.xclient.message_type == p_vout->p_sys->wm_protocols)
808 && (xevent.xclient.data.l[0] == p_vout->p_sys->wm_delete_window ) )
810 p_main->p_intf->b_die = 1;
817 if ( p_vout->i_changes & VOUT_FULLSCREEN_CHANGE )
819 ToggleFullScreen( p_vout );
820 p_vout->i_changes &= ~VOUT_FULLSCREEN_CHANGE;
825 #ifdef MODULE_NAME_IS_x11
827 * Handle vout window resizing
832 /* If interface window has been resized, change vout size */
833 p_vout->i_width = p_vout->p_sys->i_width;
834 p_vout->i_height = p_vout->p_sys->i_height;
835 p_vout->i_changes |= VOUT_SIZE_CHANGE;
837 else if( (p_vout->i_width != p_vout->p_sys->i_width) ||
838 (p_vout->i_height != p_vout->p_sys->i_height) )
840 /* If video output size has changed, change interface window size */
841 p_vout->p_sys->i_width = p_vout->i_width;
842 p_vout->p_sys->i_height = p_vout->i_height;
843 XResizeWindow( p_vout->p_sys->p_display, p_vout->p_sys->window,
844 p_vout->p_sys->i_width, p_vout->p_sys->i_height );
847 * Color/Grayscale or gamma change: in 8bpp, just change the colormap
849 if( (p_vout->i_changes & VOUT_GRAYSCALE_CHANGE)
850 && (p_vout->i_screen_depth == 8) )
852 /* FIXME: clear flags ?? */
858 if( p_vout->i_changes & VOUT_SIZE_CHANGE )
860 p_vout->i_changes &= ~VOUT_SIZE_CHANGE;
863 XResizeWindow( p_vout->p_sys->p_display, p_vout->p_sys->window,
864 p_vout->i_width, p_vout->i_height );
866 /* Destroy XImages to change their size */
869 /* Recreate XImages. If SysInit failed, the thread can't go on. */
870 if( vout_Init( p_vout ) )
872 intf_ErrMsg( "vout error: cannot resize display" );
876 /* Tell the video output thread that it will need to rebuild YUV
877 * tables. This is needed since conversion buffer size may have
879 p_vout->i_changes |= VOUT_YUV_CHANGE;
880 intf_Msg( "vout: video display resized (%dx%d)",
881 p_vout->i_width, p_vout->i_height);
888 * (Needs to be placed after VOUT_FULLSREEN_CHANGE because we can activate
889 * the size flag inside the fullscreen routine)
891 if( p_vout->i_changes & VOUT_SIZE_CHANGE )
893 int i_width, i_height, i_x, i_y;
895 p_vout->i_changes &= ~VOUT_SIZE_CHANGE;
897 intf_WarnMsg( 3, "vout: video display resized (%dx%d)",
898 p_vout->p_sys->i_width,
899 p_vout->p_sys->i_height );
901 vout_PlacePicture( p_vout, p_vout->p_sys->i_width,
902 p_vout->p_sys->i_height,
903 &i_x, &i_y, &i_width, &i_height );
905 XResizeWindow( p_vout->p_sys->p_display, p_vout->p_sys->yuv_window,
908 XMoveWindow( p_vout->p_sys->p_display, p_vout->p_sys->yuv_window,
914 /* Autohide Cursour */
915 if( mdate() - p_vout->p_sys->i_time_mouse_last_moved > 2000000 )
917 /* Hide the mouse automatically */
918 if( p_vout->p_sys->b_mouse_pointer_visible )
920 ToggleCursor( p_vout );
927 /*****************************************************************************
928 * vout_End: terminate X11 video thread output method
929 *****************************************************************************
930 * Destroy the X11 XImages created by vout_Init. It is called at the end of
931 * the thread, but also each time the window is resized.
932 *****************************************************************************/
933 static void vout_End( vout_thread_t *p_vout )
937 /* Free the direct buffers we allocated */
938 for( i_index = I_OUTPUTPICTURES ; i_index ; )
941 FreePicture( p_vout, PP_OUTPUTPICTURE[ i_index ] );
945 /* following functions are local */
947 /*****************************************************************************
948 * CreateWindow: open and set-up X11 main window
949 *****************************************************************************/
950 static int CreateWindow( vout_thread_t *p_vout )
952 XSizeHints xsize_hints;
953 XSetWindowAttributes xwindow_attributes;
958 boolean_t b_configure_notify;
959 boolean_t b_map_notify;
961 /* Set main window's size */
962 p_vout->p_sys->i_width = p_vout->i_window_width;
963 p_vout->p_sys->i_height = p_vout->i_window_height;
965 /* Prepare window manager hints and properties */
966 xsize_hints.base_width = p_vout->p_sys->i_width;
967 xsize_hints.base_height = p_vout->p_sys->i_height;
968 xsize_hints.flags = PSize;
969 p_vout->p_sys->wm_protocols = XInternAtom( p_vout->p_sys->p_display,
970 "WM_PROTOCOLS", True );
971 p_vout->p_sys->wm_delete_window = XInternAtom( p_vout->p_sys->p_display,
972 "WM_DELETE_WINDOW", True );
974 /* Prepare window attributes */
975 xwindow_attributes.backing_store = Always; /* save the hidden part */
976 xwindow_attributes.background_pixel = BlackPixel(p_vout->p_sys->p_display,
977 p_vout->p_sys->i_screen);
978 xwindow_attributes.event_mask = ExposureMask | StructureNotifyMask;
981 /* Create the window and set hints - the window must receive
982 * ConfigureNotify events, and until it is displayed, Expose and
983 * MapNotify events. */
985 p_vout->p_sys->window =
986 XCreateWindow( p_vout->p_sys->p_display,
987 DefaultRootWindow( p_vout->p_sys->p_display ),
989 p_vout->p_sys->i_width,
990 p_vout->p_sys->i_height,
993 CWBackingStore | CWBackPixel | CWEventMask,
994 &xwindow_attributes );
996 /* Set window manager hints and properties: size hints, command,
997 * window's name, and accepted protocols */
998 XSetWMNormalHints( p_vout->p_sys->p_display, p_vout->p_sys->window,
1000 XSetCommand( p_vout->p_sys->p_display, p_vout->p_sys->window,
1001 p_main->ppsz_argv, p_main->i_argc );
1002 XStoreName( p_vout->p_sys->p_display, p_vout->p_sys->window,
1003 #ifdef MODULE_NAME_IS_x11
1004 VOUT_TITLE " (X11 output)"
1006 VOUT_TITLE " (XVideo output)"
1010 if( (p_vout->p_sys->wm_protocols == None) /* use WM_DELETE_WINDOW */
1011 || (p_vout->p_sys->wm_delete_window == None)
1012 || !XSetWMProtocols( p_vout->p_sys->p_display, p_vout->p_sys->window,
1013 &p_vout->p_sys->wm_delete_window, 1 ) )
1015 /* WM_DELETE_WINDOW is not supported by window manager */
1016 intf_Msg( "vout error: missing or bad window manager" );
1019 /* Creation of a graphic context that doesn't generate a GraphicsExpose
1020 * event when using functions like XCopyArea */
1021 xgcvalues.graphics_exposures = False;
1022 p_vout->p_sys->gc = XCreateGC( p_vout->p_sys->p_display,
1023 p_vout->p_sys->window,
1024 GCGraphicsExposures, &xgcvalues);
1026 /* Send orders to server, and wait until window is displayed - three
1027 * events must be received: a MapNotify event, an Expose event allowing
1028 * drawing in the window, and a ConfigureNotify to get the window
1029 * dimensions. Once those events have been received, only ConfigureNotify
1030 * events need to be received. */
1032 b_configure_notify = 0;
1034 XMapWindow( p_vout->p_sys->p_display, p_vout->p_sys->window);
1037 XNextEvent( p_vout->p_sys->p_display, &xevent);
1038 if( (xevent.type == Expose)
1039 && (xevent.xexpose.window == p_vout->p_sys->window) )
1043 else if( (xevent.type == MapNotify)
1044 && (xevent.xmap.window == p_vout->p_sys->window) )
1048 else if( (xevent.type == ConfigureNotify)
1049 && (xevent.xconfigure.window == p_vout->p_sys->window) )
1051 b_configure_notify = 1;
1052 p_vout->p_sys->i_width = xevent.xconfigure.width;
1053 p_vout->p_sys->i_height = xevent.xconfigure.height;
1055 } while( !( b_expose && b_configure_notify && b_map_notify ) );
1057 XSelectInput( p_vout->p_sys->p_display, p_vout->p_sys->window,
1058 StructureNotifyMask | KeyPressMask |
1059 ButtonPressMask | ButtonReleaseMask |
1060 PointerMotionMask );
1062 #ifdef MODULE_NAME_IS_x11
1063 if( XDefaultDepth(p_vout->p_sys->p_display, p_vout->p_sys->i_screen) == 8 )
1065 /* Allocate a new palette */
1066 p_vout->p_sys->colormap =
1067 XCreateColormap( p_vout->p_sys->p_display,
1068 DefaultRootWindow( p_vout->p_sys->p_display ),
1069 DefaultVisual( p_vout->p_sys->p_display,
1070 p_vout->p_sys->i_screen ),
1073 xwindow_attributes.colormap = p_vout->p_sys->colormap;
1074 XChangeWindowAttributes( p_vout->p_sys->p_display,
1075 p_vout->p_sys->window,
1076 CWColormap, &xwindow_attributes );
1080 /* Create YUV output sub-window. */
1081 p_vout->p_sys->yuv_window = XCreateSimpleWindow( p_vout->p_sys->p_display,
1082 p_vout->p_sys->window, 0, 0,
1083 p_vout->p_sys->i_width,
1084 p_vout->p_sys->i_height,
1086 BlackPixel( p_vout->p_sys->p_display,
1087 p_vout->p_sys->i_screen ),
1088 WhitePixel( p_vout->p_sys->p_display,
1089 p_vout->p_sys->i_screen ) );
1091 XSetWindowBackground( p_vout->p_sys->p_display, p_vout->p_sys->yuv_window,
1092 BlackPixel(p_vout->p_sys->p_display, p_vout->p_sys->i_screen ) );
1094 XMapWindow( p_vout->p_sys->p_display, p_vout->p_sys->yuv_window );
1095 XSelectInput( p_vout->p_sys->p_display, p_vout->p_sys->yuv_window,
1098 /* make sure the YUV window will be centered in the next vout_Manage() */
1099 p_vout->i_changes |= VOUT_SIZE_CHANGE;
1102 /* If the cursor was formerly blank than blank it again */
1103 if( !p_vout->p_sys->b_mouse_pointer_visible )
1105 ToggleCursor( p_vout );
1106 ToggleCursor( p_vout );
1109 /* Do NOT use XFlush here ! */
1110 XSync( p_vout->p_sys->p_display, False );
1112 /* At this stage, the window is open, displayed, and ready to
1118 /*****************************************************************************
1119 * DestroyWindow: destroy the window
1120 *****************************************************************************
1122 *****************************************************************************/
1123 static void DestroyWindow( vout_thread_t *p_vout )
1125 /* Do NOT use XFlush here ! */
1126 XSync( p_vout->p_sys->p_display, False );
1128 #ifdef MODULE_NAME_IS_xvideo
1129 XDestroyWindow( p_vout->p_sys->p_display, p_vout->p_sys->yuv_window );
1132 XUnmapWindow( p_vout->p_sys->p_display, p_vout->p_sys->window );
1133 XFreeGC( p_vout->p_sys->p_display, p_vout->p_sys->gc );
1134 XDestroyWindow( p_vout->p_sys->p_display, p_vout->p_sys->window );
1137 /*****************************************************************************
1138 * NewPicture: allocate a picture
1139 *****************************************************************************
1140 * Returns 0 on success, -1 otherwise
1141 *****************************************************************************/
1142 static int NewPicture( vout_thread_t *p_vout, picture_t *p_pic )
1144 /* We know the chroma, allocate a buffer which will be used
1145 * directly by the decoder */
1146 p_pic->p_sys = malloc( sizeof( picture_sys_t ) );
1148 if( p_pic->p_sys == NULL )
1153 #ifdef HAVE_SYS_SHM_H
1154 if( p_vout->p_sys->b_shm )
1156 /* Create image using XShm extension */
1157 p_pic->p_sys->p_image =
1158 CreateShmImage( p_vout->p_sys->p_display,
1159 # ifdef MODULE_NAME_IS_xvideo
1160 p_vout->p_sys->i_xvport,
1161 p_vout->output.i_chroma,
1163 p_vout->p_sys->p_visual,
1164 p_vout->p_sys->i_screen_depth,
1166 &p_pic->p_sys->shminfo,
1167 p_vout->output.i_width, p_vout->output.i_height );
1170 #endif /* HAVE_SYS_SHM_H */
1172 /* Create image without XShm extension */
1173 p_pic->p_sys->p_image =
1174 CreateImage( p_vout->p_sys->p_display,
1175 #ifdef MODULE_NAME_IS_xvideo
1176 p_vout->p_sys->i_xvport,
1177 p_vout->output.i_chroma,
1179 p_vout->p_sys->p_visual,
1180 p_vout->p_sys->i_screen_depth,
1181 p_vout->p_sys->i_bytes_per_pixel,
1183 p_vout->output.i_width, p_vout->output.i_height );
1186 if( p_pic->p_sys->p_image == NULL )
1188 free( p_pic->p_sys );
1192 switch( p_vout->output.i_chroma )
1194 #ifdef MODULE_NAME_IS_xvideo
1197 p_pic->Y_PIXELS = p_pic->p_sys->p_image->data
1198 + p_pic->p_sys->p_image->offsets[0];
1199 p_pic->p[Y_PLANE].i_lines = p_vout->output.i_height;
1200 p_pic->p[Y_PLANE].i_pitch = p_pic->p_sys->p_image->pitches[0];
1201 p_pic->p[Y_PLANE].i_pixel_bytes = 1;
1202 p_pic->p[Y_PLANE].b_margin = 0;
1204 p_pic->U_PIXELS = p_pic->p_sys->p_image->data
1205 + p_pic->p_sys->p_image->offsets[1];
1206 p_pic->p[U_PLANE].i_lines = p_vout->output.i_height / 2;
1207 p_pic->p[U_PLANE].i_pitch = p_pic->p_sys->p_image->pitches[1];
1208 p_pic->p[U_PLANE].i_pixel_bytes = 1;
1209 p_pic->p[U_PLANE].b_margin = 0;
1211 p_pic->V_PIXELS = p_pic->p_sys->p_image->data
1212 + p_pic->p_sys->p_image->offsets[2];
1213 p_pic->p[V_PLANE].i_lines = p_vout->output.i_height / 2;
1214 p_pic->p[V_PLANE].i_pitch = p_pic->p_sys->p_image->pitches[2];
1215 p_pic->p[V_PLANE].i_pixel_bytes = 1;
1216 p_pic->p[V_PLANE].b_margin = 0;
1218 p_pic->i_planes = 3;
1223 p_pic->Y_PIXELS = p_pic->p_sys->p_image->data
1224 + p_pic->p_sys->p_image->offsets[0];
1225 p_pic->p[Y_PLANE].i_lines = p_vout->output.i_height;
1226 p_pic->p[Y_PLANE].i_pitch = p_pic->p_sys->p_image->pitches[0];
1227 p_pic->p[Y_PLANE].i_pixel_bytes = 1;
1228 p_pic->p[Y_PLANE].b_margin = 0;
1230 p_pic->U_PIXELS = p_pic->p_sys->p_image->data
1231 + p_pic->p_sys->p_image->offsets[2];
1232 p_pic->p[U_PLANE].i_lines = p_vout->output.i_height / 2;
1233 p_pic->p[U_PLANE].i_pitch = p_pic->p_sys->p_image->pitches[2];
1234 p_pic->p[U_PLANE].i_pixel_bytes = 1;
1235 p_pic->p[U_PLANE].b_margin = 0;
1237 p_pic->V_PIXELS = p_pic->p_sys->p_image->data
1238 + p_pic->p_sys->p_image->offsets[1];
1239 p_pic->p[V_PLANE].i_lines = p_vout->output.i_height / 2;
1240 p_pic->p[V_PLANE].i_pitch = p_pic->p_sys->p_image->pitches[1];
1241 p_pic->p[V_PLANE].i_pixel_bytes = 1;
1242 p_pic->p[V_PLANE].b_margin = 0;
1244 p_pic->i_planes = 3;
1249 p_pic->p->p_pixels = p_pic->p_sys->p_image->data
1250 + p_pic->p_sys->p_image->offsets[0];
1251 p_pic->p->i_lines = p_vout->output.i_height;
1252 /* XXX: this just looks so plain wrong... check it out ! */
1253 p_pic->p->i_pitch = p_pic->p_sys->p_image->pitches[0] / 4;
1254 p_pic->p->i_pixel_bytes = 4;
1255 p_pic->p->b_margin = 0;
1257 p_pic->i_planes = 1;
1263 p_pic->p->p_pixels = p_pic->p_sys->p_image->data
1264 + p_pic->p_sys->p_image->offsets[0];
1265 p_pic->p->i_lines = p_vout->output.i_height;
1266 p_pic->p->i_pitch = p_pic->p_sys->p_image->pitches[0];
1267 p_pic->p->i_pixel_bytes = 4;
1268 p_pic->p->b_margin = 0;
1270 p_pic->i_planes = 1;
1275 p_pic->p->p_pixels = p_pic->p_sys->p_image->data
1276 + p_pic->p_sys->p_image->offsets[0];
1277 p_pic->p->i_lines = p_vout->output.i_height;
1278 p_pic->p->i_pitch = p_pic->p_sys->p_image->pitches[0];
1279 p_pic->p->i_pixel_bytes = 2;
1280 p_pic->p->b_margin = 0;
1282 p_pic->i_planes = 1;
1287 p_pic->p->p_pixels = p_pic->p_sys->p_image->data
1288 + p_pic->p_sys->p_image->offsets[0];
1289 p_pic->p->i_lines = p_vout->output.i_height;
1290 p_pic->p->i_pitch = p_pic->p_sys->p_image->pitches[0];
1291 p_pic->p->i_pixel_bytes = 2;
1292 p_pic->p->b_margin = 0;
1294 p_pic->i_planes = 1;
1300 p_pic->p->p_pixels = p_pic->p_sys->p_image->data
1301 + p_pic->p_sys->p_image->xoffset;
1302 p_pic->p->i_lines = p_pic->p_sys->p_image->height;
1303 p_pic->p->i_pitch = p_pic->p_sys->p_image->bytes_per_line;
1304 p_pic->p->i_pixel_bytes = p_pic->p_sys->p_image->depth;
1306 if( p_pic->p->i_pitch == p_pic->p_sys->p_image->width )
1308 p_pic->p->b_margin = 0;
1312 p_pic->p->b_margin = 1;
1313 p_pic->p->b_hidden = 1;
1314 p_pic->p->i_visible_bytes = p_pic->p_sys->p_image->width;
1317 p_pic->i_planes = 1;
1324 p_pic->p->p_pixels = p_pic->p_sys->p_image->data
1325 + p_pic->p_sys->p_image->xoffset;
1326 p_pic->p->i_lines = p_pic->p_sys->p_image->height;
1327 p_pic->p->i_pitch = p_pic->p_sys->p_image->bytes_per_line;
1328 p_pic->p->i_pixel_bytes = p_pic->p_sys->p_image->depth;
1330 if( p_pic->p->i_pitch == 2 * p_pic->p_sys->p_image->width )
1332 p_pic->p->b_margin = 0;
1336 p_pic->p->b_margin = 1;
1337 p_pic->p->b_hidden = 1;
1338 p_pic->p->i_visible_bytes = 2 * p_pic->p_sys->p_image->width;
1341 p_pic->i_planes = 1;
1348 p_pic->p->p_pixels = p_pic->p_sys->p_image->data
1349 + p_pic->p_sys->p_image->xoffset;
1350 p_pic->p->i_lines = p_pic->p_sys->p_image->height;
1351 p_pic->p->i_pitch = p_pic->p_sys->p_image->bytes_per_line;
1352 p_pic->p->i_pixel_bytes = p_pic->p_sys->p_image->depth;
1354 if( p_pic->p->i_pitch == 4 * p_pic->p_sys->p_image->width )
1356 p_pic->p->b_margin = 0;
1360 p_pic->p->b_margin = 1;
1361 p_pic->p->b_hidden = 1;
1362 p_pic->p->i_visible_bytes = 4 * p_pic->p_sys->p_image->width;
1365 p_pic->i_planes = 1;
1371 /* Unknown chroma, tell the guy to get lost */
1372 IMAGE_FREE( p_pic->p_sys->p_image );
1373 free( p_pic->p_sys );
1374 intf_ErrMsg( "vout error: never heard of chroma 0x%.8x (%4.4s)",
1375 p_vout->output.i_chroma,
1376 (char*)&p_vout->output.i_chroma );
1377 p_pic->i_planes = 0;
1384 /*****************************************************************************
1385 * FreePicture: destroy a picture allocated with NewPicture
1386 *****************************************************************************
1387 * Destroy XImage AND associated data. If using Shm, detach shared memory
1388 * segment from server and process, then free it. The XDestroyImage manpage
1389 * says that both the image structure _and_ the data pointed to by the
1390 * image structure are freed, so no need to free p_image->data.
1391 *****************************************************************************/
1392 static void FreePicture( vout_thread_t *p_vout, picture_t *p_pic )
1394 /* The order of operations is correct */
1395 #ifdef HAVE_SYS_SHM_H
1396 if( p_vout->p_sys->b_shm )
1398 XShmDetach( p_vout->p_sys->p_display, &p_pic->p_sys->shminfo );
1399 IMAGE_FREE( p_pic->p_sys->p_image );
1401 shmctl( p_pic->p_sys->shminfo.shmid, IPC_RMID, 0 );
1402 if( shmdt( p_pic->p_sys->shminfo.shmaddr ) )
1404 intf_ErrMsg( "vout error: cannot detach shared memory (%s)",
1411 IMAGE_FREE( p_pic->p_sys->p_image );
1414 /* Do NOT use XFlush here ! */
1415 XSync( p_vout->p_sys->p_display, False );
1417 free( p_pic->p_sys );
1420 /*****************************************************************************
1421 * ToggleFullScreen: Enable or disable full screen mode
1422 *****************************************************************************
1423 * This function will switch between fullscreen and window mode.
1425 *****************************************************************************/
1426 static void ToggleFullScreen ( vout_thread_t *p_vout )
1429 mwmhints_t mwmhints;
1430 int i_xpos, i_ypos, i_width, i_height;
1432 XSetWindowAttributes attributes;
1434 p_vout->b_fullscreen = !p_vout->b_fullscreen;
1436 if( p_vout->b_fullscreen )
1438 Window next_parent, parent, *p_dummy, dummy1;
1439 unsigned int dummy2, dummy3;
1441 intf_WarnMsg( 3, "vout: entering fullscreen mode" );
1443 /* Only check the fullscreen method when we actually go fullscreen,
1444 * because to go back to window mode we need to know in which
1445 * fullscreen mode we where */
1446 p_vout->p_sys->b_altfullscreen =
1447 config_GetIntVariable( MODULE_STRING "-altfullscreen" );
1449 /* Save current window coordinates so they can be restored when
1450 * we exit from fullscreen mode. This is the tricky part because
1451 * this heavily depends on the behaviour of the window manager.
1452 * When you use XMoveWindow some window managers will adjust the top
1453 * of the window to the coordinates you gave, but others will instead
1454 * adjust the top of the client area to the coordinates
1455 * (don't forget windows have decorations). */
1457 /* First, get the position and size of the client area */
1458 XGetGeometry( p_vout->p_sys->p_display,
1459 p_vout->p_sys->window,
1463 &p_vout->p_sys->i_width_backup_2,
1464 &p_vout->p_sys->i_height_backup_2,
1466 XTranslateCoordinates( p_vout->p_sys->p_display,
1467 p_vout->p_sys->window,
1468 DefaultRootWindow( p_vout->p_sys->p_display ),
1471 &p_vout->p_sys->i_xpos_backup_2,
1472 &p_vout->p_sys->i_ypos_backup_2,
1475 /* Then try to get the position and size of the whole window */
1477 /* find the real parent of our window (created by the window manager),
1478 * the one which is a direct child of the root window */
1479 next_parent = parent = p_vout->p_sys->window;
1480 while( next_parent != DefaultRootWindow( p_vout->p_sys->p_display ) )
1482 parent = next_parent;
1483 XQueryTree( p_vout->p_sys->p_display,
1489 XFree((void *)p_dummy);
1492 XGetGeometry( p_vout->p_sys->p_display,
1493 p_vout->p_sys->window,
1497 &p_vout->p_sys->i_width_backup,
1498 &p_vout->p_sys->i_height_backup,
1501 XTranslateCoordinates( p_vout->p_sys->p_display,
1503 DefaultRootWindow( p_vout->p_sys->p_display ),
1506 &p_vout->p_sys->i_xpos_backup,
1507 &p_vout->p_sys->i_ypos_backup,
1510 /* fullscreen window size and position */
1513 i_width = DisplayWidth( p_vout->p_sys->p_display,
1514 p_vout->p_sys->i_screen );
1515 i_height = DisplayHeight( p_vout->p_sys->p_display,
1516 p_vout->p_sys->i_screen );
1521 intf_WarnMsg( 3, "vout: leaving fullscreen mode" );
1523 i_xpos = p_vout->p_sys->i_xpos_backup;
1524 i_ypos = p_vout->p_sys->i_ypos_backup;
1525 i_width = p_vout->p_sys->i_width_backup;
1526 i_height = p_vout->p_sys->i_height_backup;
1529 /* To my knowledge there are two ways to create a borderless window.
1530 * There's the generic way which is to tell x to bypass the window manager,
1531 * but this creates problems with the focus of other applications.
1532 * The other way is to use the motif property "_MOTIF_WM_HINTS" which
1533 * luckily seems to be supported by most window managers.
1535 if( !p_vout->p_sys->b_altfullscreen )
1537 mwmhints.flags = MWM_HINTS_DECORATIONS;
1538 mwmhints.decorations = !p_vout->b_fullscreen;
1540 prop = XInternAtom( p_vout->p_sys->p_display, "_MOTIF_WM_HINTS",
1542 XChangeProperty( p_vout->p_sys->p_display, p_vout->p_sys->window,
1543 prop, prop, 32, PropModeReplace,
1544 (unsigned char *)&mwmhints,
1545 PROP_MWM_HINTS_ELEMENTS );
1549 /* brute force way to remove decorations */
1550 attributes.override_redirect = p_vout->b_fullscreen;
1551 XChangeWindowAttributes( p_vout->p_sys->p_display,
1552 p_vout->p_sys->window,
1557 /* We need to unmap and remap the window if we want the window
1558 * manager to take our changes into effect */
1559 XUnmapWindow( p_vout->p_sys->p_display, p_vout->p_sys->window);
1561 XWindowEvent( p_vout->p_sys->p_display, p_vout->p_sys->window,
1562 StructureNotifyMask, &xevent );
1563 while( xevent.type != UnmapNotify )
1564 XWindowEvent( p_vout->p_sys->p_display, p_vout->p_sys->window,
1565 StructureNotifyMask, &xevent );
1567 XMapRaised( p_vout->p_sys->p_display, p_vout->p_sys->window);
1569 while( xevent.type != MapNotify )
1570 XWindowEvent( p_vout->p_sys->p_display, p_vout->p_sys->window,
1571 StructureNotifyMask, &xevent );
1573 XMoveResizeWindow( p_vout->p_sys->p_display,
1574 p_vout->p_sys->window,
1580 /* Purge all ConfigureNotify events, this is needed to fix a bug where we
1581 * would lose the original size of the window */
1582 while( xevent.type != ConfigureNotify )
1583 XWindowEvent( p_vout->p_sys->p_display, p_vout->p_sys->window,
1584 StructureNotifyMask, &xevent );
1585 while( XCheckWindowEvent( p_vout->p_sys->p_display, p_vout->p_sys->window,
1586 StructureNotifyMask, &xevent ) );
1589 /* We need to check that the window was really restored where we wanted */
1590 if( !p_vout->b_fullscreen )
1593 unsigned int dummy2, dummy3, dummy4, dummy5;
1595 /* Check the position */
1596 XTranslateCoordinates( p_vout->p_sys->p_display,
1597 p_vout->p_sys->window,
1598 DefaultRootWindow( p_vout->p_sys->p_display ),
1604 if( dummy2 != p_vout->p_sys->i_xpos_backup_2 ||
1605 dummy3 != p_vout->p_sys->i_ypos_backup_2 )
1607 /* Ok it didn't work... second try */
1609 XMoveWindow( p_vout->p_sys->p_display,
1610 p_vout->p_sys->window,
1611 p_vout->p_sys->i_xpos_backup_2,
1612 p_vout->p_sys->i_ypos_backup_2 );
1614 /* Purge all ConfigureNotify events, this is needed to fix a bug
1615 * where we would lose the original size of the window */
1616 XWindowEvent( p_vout->p_sys->p_display, p_vout->p_sys->window,
1617 StructureNotifyMask, &xevent );
1618 while( xevent.type != ConfigureNotify )
1619 XWindowEvent( p_vout->p_sys->p_display, p_vout->p_sys->window,
1620 StructureNotifyMask, &xevent );
1621 while( XCheckWindowEvent( p_vout->p_sys->p_display,
1622 p_vout->p_sys->window,
1623 StructureNotifyMask, &xevent ) );
1626 /* Check the size */
1627 XGetGeometry( p_vout->p_sys->p_display,
1628 p_vout->p_sys->window,
1636 if( dummy4 != p_vout->p_sys->i_width_backup_2 ||
1637 dummy5 != p_vout->p_sys->i_height_backup_2 )
1639 /* Ok it didn't work... third try */
1641 XResizeWindow( p_vout->p_sys->p_display,
1642 p_vout->p_sys->window,
1643 p_vout->p_sys->i_width_backup_2,
1644 p_vout->p_sys->i_height_backup_2 );
1646 /* Purge all ConfigureNotify events, this is needed to fix a bug
1647 * where we would lose the original size of the window */
1648 XWindowEvent( p_vout->p_sys->p_display, p_vout->p_sys->window,
1649 StructureNotifyMask, &xevent );
1650 while( xevent.type != ConfigureNotify )
1651 XWindowEvent( p_vout->p_sys->p_display, p_vout->p_sys->window,
1652 StructureNotifyMask, &xevent );
1653 while( XCheckWindowEvent( p_vout->p_sys->p_display,
1654 p_vout->p_sys->window,
1655 StructureNotifyMask, &xevent ) );
1659 if( p_vout->p_sys->b_altfullscreen )
1660 XSetInputFocus(p_vout->p_sys->p_display,
1661 p_vout->p_sys->window,
1665 /* signal that the size needs to be updated */
1666 p_vout->p_sys->i_width = i_width;
1667 p_vout->p_sys->i_height = i_height;
1668 p_vout->i_changes |= VOUT_SIZE_CHANGE;
1672 /*****************************************************************************
1673 * EnableXScreenSaver: enable screen saver
1674 *****************************************************************************
1675 * This function enables the screen saver on a display after it has been
1676 * disabled by XDisableScreenSaver.
1677 * FIXME: what happens if multiple vlc sessions are running at the same
1679 *****************************************************************************/
1680 static void EnableXScreenSaver( vout_thread_t *p_vout )
1682 #ifdef DPMSINFO_IN_DPMS_H
1686 XSetScreenSaver( p_vout->p_sys->p_display, p_vout->p_sys->i_ss_timeout,
1687 p_vout->p_sys->i_ss_interval,
1688 p_vout->p_sys->i_ss_blanking,
1689 p_vout->p_sys->i_ss_exposure );
1691 /* Restore DPMS settings */
1692 #ifdef DPMSINFO_IN_DPMS_H
1693 if( DPMSQueryExtension( p_vout->p_sys->p_display, &dummy, &dummy ) )
1695 if( p_vout->p_sys->b_ss_dpms )
1697 DPMSEnable( p_vout->p_sys->p_display );
1703 /*****************************************************************************
1704 * DisableXScreenSaver: disable screen saver
1705 *****************************************************************************
1706 * See XEnableXScreenSaver
1707 *****************************************************************************/
1708 static void DisableXScreenSaver( vout_thread_t *p_vout )
1710 #ifdef DPMSINFO_IN_DPMS_H
1714 /* Save screen saver informations */
1715 XGetScreenSaver( p_vout->p_sys->p_display, &p_vout->p_sys->i_ss_timeout,
1716 &p_vout->p_sys->i_ss_interval,
1717 &p_vout->p_sys->i_ss_blanking,
1718 &p_vout->p_sys->i_ss_exposure );
1720 /* Disable screen saver */
1721 XSetScreenSaver( p_vout->p_sys->p_display, 0,
1722 p_vout->p_sys->i_ss_interval,
1723 p_vout->p_sys->i_ss_blanking,
1724 p_vout->p_sys->i_ss_exposure );
1727 #ifdef DPMSINFO_IN_DPMS_H
1728 if( DPMSQueryExtension( p_vout->p_sys->p_display, &dummy, &dummy ) )
1731 /* Save DPMS current state */
1732 DPMSInfo( p_vout->p_sys->p_display, &unused,
1733 &p_vout->p_sys->b_ss_dpms );
1734 DPMSDisable( p_vout->p_sys->p_display );
1739 /*****************************************************************************
1740 * CreateCursor: create a blank mouse pointer
1741 *****************************************************************************/
1742 static void CreateCursor( vout_thread_t *p_vout )
1744 XColor cursor_color;
1746 p_vout->p_sys->cursor_pixmap =
1747 XCreatePixmap( p_vout->p_sys->p_display,
1748 DefaultRootWindow( p_vout->p_sys->p_display ),
1751 XParseColor( p_vout->p_sys->p_display,
1752 XCreateColormap( p_vout->p_sys->p_display,
1754 p_vout->p_sys->p_display ),
1756 p_vout->p_sys->p_display,
1757 p_vout->p_sys->i_screen ),
1759 "black", &cursor_color );
1761 p_vout->p_sys->blank_cursor =
1762 XCreatePixmapCursor( p_vout->p_sys->p_display,
1763 p_vout->p_sys->cursor_pixmap,
1764 p_vout->p_sys->cursor_pixmap,
1765 &cursor_color, &cursor_color, 1, 1 );
1768 /*****************************************************************************
1769 * DestroyCursor: destroy the blank mouse pointer
1770 *****************************************************************************/
1771 static void DestroyCursor( vout_thread_t *p_vout )
1773 XFreePixmap( p_vout->p_sys->p_display, p_vout->p_sys->cursor_pixmap );
1776 /*****************************************************************************
1777 * ToggleCursor: hide or show the mouse pointer
1778 *****************************************************************************
1779 * This function hides the X pointer if it is visible by setting the pointer
1780 * sprite to a blank one. To show it again, we disable the sprite.
1781 *****************************************************************************/
1782 static void ToggleCursor( vout_thread_t *p_vout )
1784 if( p_vout->p_sys->b_mouse_pointer_visible )
1786 XDefineCursor( p_vout->p_sys->p_display,
1787 p_vout->p_sys->window,
1788 p_vout->p_sys->blank_cursor );
1789 p_vout->p_sys->b_mouse_pointer_visible = 0;
1793 XUndefineCursor( p_vout->p_sys->p_display, p_vout->p_sys->window );
1794 p_vout->p_sys->b_mouse_pointer_visible = 1;
1798 #ifdef MODULE_NAME_IS_xvideo
1799 /*****************************************************************************
1800 * XVideoGetPort: get YUV12 port
1801 *****************************************************************************/
1802 static int XVideoGetPort( Display *dpy, u32 i_chroma, u32 *pi_newchroma )
1804 XvAdaptorInfo *p_adaptor;
1806 int i_adaptor, i_num_adaptors, i_requested_adaptor;
1807 int i_selected_port;
1809 switch( XvQueryExtension( dpy, &i, &i, &i, &i, &i ) )
1814 case XvBadExtension:
1815 intf_WarnMsg( 3, "vout error: XvBadExtension" );
1819 intf_WarnMsg( 3, "vout error: XvBadAlloc" );
1823 intf_WarnMsg( 3, "vout error: XvQueryExtension failed" );
1827 switch( XvQueryAdaptors( dpy, DefaultRootWindow( dpy ),
1828 &i_num_adaptors, &p_adaptor ) )
1833 case XvBadExtension:
1834 intf_WarnMsg( 3, "vout error: XvBadExtension for XvQueryAdaptors" );
1838 intf_WarnMsg( 3, "vout error: XvBadAlloc for XvQueryAdaptors" );
1842 intf_WarnMsg( 3, "vout error: XvQueryAdaptors failed" );
1846 i_selected_port = -1;
1847 i_requested_adaptor = config_GetIntVariable( "xvideo-adaptor" );
1849 for( i_adaptor = 0; i_adaptor < i_num_adaptors; ++i_adaptor )
1851 XvImageFormatValues *p_formats;
1852 int i_format, i_num_formats;
1855 /* If we requested an adaptor and it's not this one, we aren't
1857 if( i_requested_adaptor != -1 && i_adaptor != i_requested_adaptor )
1862 /* If the adaptor doesn't have the required properties, skip it */
1863 if( !( p_adaptor[ i_adaptor ].type & XvInputMask ) ||
1864 !( p_adaptor[ i_adaptor ].type & XvImageMask ) )
1869 /* Check that adaptor supports our requested format... */
1870 p_formats = XvListImageFormats( dpy, p_adaptor[i_adaptor].base_id,
1874 i_format < i_num_formats && ( i_selected_port == -1 );
1877 /* Code removed, we can get this through xvinfo anyway */
1879 XvEncodingInfo *p_enc;
1880 int i_enc, i_num_encodings;
1881 XvAttribute *p_attr;
1882 int i_attr, i_num_attributes;
1885 /* If this is not the format we want, or at least a
1886 * similar one, forget it */
1887 if( !vout_ChromaCmp( p_formats[ i_format ].id, i_chroma ) )
1892 /* Look for the first available port supporting this format */
1893 for( i_port = p_adaptor[i_adaptor].base_id;
1894 ( i_port < p_adaptor[i_adaptor].base_id
1895 + p_adaptor[i_adaptor].num_ports )
1896 && ( i_selected_port == -1 );
1899 if( XvGrabPort( dpy, i_port, CurrentTime ) == Success )
1901 i_selected_port = i_port;
1902 *pi_newchroma = p_formats[ i_format ].id;
1906 /* If no free port was found, forget it */
1907 if( i_selected_port == -1 )
1912 /* If we found a port, print information about it */
1913 intf_WarnMsg( 3, "vout: found adaptor %i, port %i, "
1914 "image format 0x%x (%4.4s) %s",
1915 i_adaptor, i_selected_port,
1916 p_formats[ i_format ].id,
1917 (char *)&p_formats[ i_format ].id,
1918 ( p_formats[ i_format ].format
1919 == XvPacked ) ? "packed" : "planar" );
1922 intf_WarnMsg( 10, " encoding list:" );
1924 if( XvQueryEncodings( dpy, i_selected_port,
1925 &i_num_encodings, &p_enc )
1928 intf_WarnMsg( 10, " XvQueryEncodings failed" );
1932 for( i_enc = 0; i_enc < i_num_encodings; i_enc++ )
1934 intf_WarnMsg( 10, " id=%ld, name=%s, size=%ldx%ld,"
1935 " numerator=%d, denominator=%d",
1936 p_enc[i_enc].encoding_id, p_enc[i_enc].name,
1937 p_enc[i_enc].width, p_enc[i_enc].height,
1938 p_enc[i_enc].rate.numerator,
1939 p_enc[i_enc].rate.denominator );
1944 XvFreeEncodingInfo( p_enc );
1947 intf_WarnMsg( 10, " attribute list:" );
1948 p_attr = XvQueryPortAttributes( dpy, i_selected_port,
1949 &i_num_attributes );
1950 for( i_attr = 0; i_attr < i_num_attributes; i_attr++ )
1953 " name=%s, flags=[%s%s ], min=%i, max=%i",
1954 p_attr[i_attr].name,
1955 (p_attr[i_attr].flags & XvGettable) ? " get" : "",
1956 (p_attr[i_attr].flags & XvSettable) ? " set" : "",
1957 p_attr[i_attr].min_value, p_attr[i_attr].max_value );
1960 if( p_attr != NULL )
1967 if( p_formats != NULL )
1974 if( i_num_adaptors > 0 )
1976 XvFreeAdaptorInfo( p_adaptor );
1979 if( i_selected_port == -1 )
1981 if( i_requested_adaptor == -1 )
1983 intf_WarnMsg( 3, "vout: no free XVideo port found for format "
1984 "0x%.8x (%4.4s)", i_chroma, (char*)&i_chroma );
1988 intf_WarnMsg( 3, "vout: XVideo adaptor %i does not have a free "
1989 "XVideo port for format 0x%.8x (%4.4s)",
1990 i_requested_adaptor, i_chroma, (char*)&i_chroma );
1994 return( i_selected_port );
1997 /*****************************************************************************
1998 * XVideoReleasePort: release YUV12 port
1999 *****************************************************************************/
2000 static void XVideoReleasePort( Display *dpy, int i_port )
2002 XvUngrabPort( dpy, i_port, CurrentTime );
2006 /*****************************************************************************
2007 * InitDisplay: open and initialize X11 device
2008 *****************************************************************************
2009 * Create a window according to video output given size, and set other
2010 * properties according to the display properties.
2011 *****************************************************************************/
2012 static int InitDisplay( vout_thread_t *p_vout )
2014 #ifdef MODULE_NAME_IS_x11
2015 XPixmapFormatValues * p_formats; /* pixmap formats */
2016 XVisualInfo * p_xvisual; /* visuals informations */
2017 XVisualInfo xvisual_template; /* visual template */
2018 int i_count; /* array size */
2021 #ifdef HAVE_SYS_SHM_H
2023 /* FIXME : As of 2001-03-16, XFree4 for MacOS X does not support Xshm. */
2024 p_vout->p_sys->b_shm = 0;
2026 p_vout->p_sys->b_shm = ( XShmQueryExtension( p_vout->p_sys->p_display )
2029 if( !p_vout->p_sys->b_shm )
2032 intf_WarnMsg( 1, "vout warning: XShm video extension is unavailable" );
2035 #ifdef MODULE_NAME_IS_xvideo
2036 /* XXX The brightness and contrast values should be read from environment
2037 * XXX variables... */
2039 XVideoSetAttribute( p_vout, "XV_BRIGHTNESS", 0.5 );
2040 XVideoSetAttribute( p_vout, "XV_CONTRAST", 0.5 );
2044 #ifdef MODULE_NAME_IS_x11
2045 /* Initialize structure */
2046 p_vout->p_sys->i_screen = DefaultScreen( p_vout->p_sys->p_display );
2048 /* Get screen depth */
2049 p_vout->p_sys->i_screen_depth = XDefaultDepth( p_vout->p_sys->p_display,
2050 p_vout->p_sys->i_screen );
2051 switch( p_vout->p_sys->i_screen_depth )
2055 * Screen depth is 8bpp. Use PseudoColor visual with private colormap.
2057 xvisual_template.screen = p_vout->p_sys->i_screen;
2058 xvisual_template.class = DirectColor;
2059 p_xvisual = XGetVisualInfo( p_vout->p_sys->p_display,
2060 VisualScreenMask | VisualClassMask,
2061 &xvisual_template, &i_count );
2062 if( p_xvisual == NULL )
2064 intf_ErrMsg( "vout error: no PseudoColor visual available" );
2067 p_vout->p_sys->i_bytes_per_pixel = 1;
2068 p_vout->output.pf_setpalette = SetPalette;
2075 * Screen depth is higher than 8bpp. TrueColor visual is used.
2077 xvisual_template.screen = p_vout->p_sys->i_screen;
2078 xvisual_template.class = TrueColor;
2079 p_xvisual = XGetVisualInfo( p_vout->p_sys->p_display,
2080 VisualScreenMask | VisualClassMask,
2081 &xvisual_template, &i_count );
2082 if( p_xvisual == NULL )
2084 intf_ErrMsg( "vout error: no TrueColor visual available" );
2088 p_vout->output.i_rmask = p_xvisual->red_mask;
2089 p_vout->output.i_gmask = p_xvisual->green_mask;
2090 p_vout->output.i_bmask = p_xvisual->blue_mask;
2092 /* There is no difference yet between 3 and 4 Bpp. The only way
2093 * to find the actual number of bytes per pixel is to list supported
2094 * pixmap formats. */
2095 p_formats = XListPixmapFormats( p_vout->p_sys->p_display, &i_count );
2096 p_vout->p_sys->i_bytes_per_pixel = 0;
2098 for( ; i_count-- ; p_formats++ )
2100 /* Under XFree4.0, the list contains pixmap formats available
2101 * through all video depths ; so we have to check against current
2103 if( p_formats->depth == p_vout->p_sys->i_screen_depth )
2105 if( p_formats->bits_per_pixel / 8
2106 > p_vout->p_sys->i_bytes_per_pixel )
2108 p_vout->p_sys->i_bytes_per_pixel = p_formats->bits_per_pixel / 8;
2114 p_vout->p_sys->p_visual = p_xvisual->visual;
2121 #ifdef HAVE_SYS_SHM_H
2122 /*****************************************************************************
2123 * CreateShmImage: create an XImage or XvImage using shared memory extension
2124 *****************************************************************************
2125 * Prepare an XImage or XvImage for display function.
2126 * The order of the operations respects the recommandations of the mit-shm
2127 * document by J.Corbet and K.Packard. Most of the parameters were copied from
2128 * there. See http://ftp.xfree86.org/pub/XFree86/4.0/doc/mit-shm.TXT
2129 *****************************************************************************/
2130 static IMAGE_TYPE * CreateShmImage( Display* p_display, EXTRA_ARGS_SHM,
2131 int i_width, int i_height )
2133 IMAGE_TYPE *p_image;
2135 /* Create XImage / XvImage */
2136 #ifdef MODULE_NAME_IS_xvideo
2137 p_image = XvShmCreateImage( p_display, i_xvport, i_chroma, 0,
2138 i_width, i_height, p_shm );
2140 p_image = XShmCreateImage( p_display, p_visual, i_depth, ZPixmap, 0,
2141 p_shm, i_width, i_height );
2143 if( p_image == NULL )
2145 intf_ErrMsg( "vout error: image creation failed." );
2149 /* Allocate shared memory segment - 0776 set the access permission
2150 * rights (like umask), they are not yet supported by all X servers */
2151 p_shm->shmid = shmget( IPC_PRIVATE, DATA_SIZE(p_image), IPC_CREAT | 0776 );
2152 if( p_shm->shmid < 0 )
2154 intf_ErrMsg( "vout error: cannot allocate shared image data (%s)",
2155 strerror( errno ) );
2156 IMAGE_FREE( p_image );
2160 /* Attach shared memory segment to process (read/write) */
2161 p_shm->shmaddr = p_image->data = shmat( p_shm->shmid, 0, 0 );
2162 if(! p_shm->shmaddr )
2164 intf_ErrMsg( "vout error: cannot attach shared memory (%s)",
2166 IMAGE_FREE( p_image );
2167 shmctl( p_shm->shmid, IPC_RMID, 0 );
2171 /* Read-only data. We won't be using XShmGetImage */
2172 p_shm->readOnly = True;
2174 /* Attach shared memory segment to X server */
2175 if( XShmAttach( p_display, p_shm ) == False )
2177 intf_ErrMsg( "vout error: cannot attach shared memory to X server" );
2178 IMAGE_FREE( p_image );
2179 shmctl( p_shm->shmid, IPC_RMID, 0 );
2180 shmdt( p_shm->shmaddr );
2184 /* Send image to X server. This instruction is required, since having
2185 * built a Shm XImage and not using it causes an error on XCloseDisplay,
2186 * and remember NOT to use XFlush ! */
2187 XSync( p_display, False );
2190 /* Mark the shm segment to be removed when there are no more
2191 * attachements, so it is automatic on process exit or after shmdt */
2192 shmctl( p_shm->shmid, IPC_RMID, 0 );
2199 /*****************************************************************************
2200 * CreateImage: create an XImage or XvImage
2201 *****************************************************************************
2202 * Create a simple image used as a buffer.
2203 *****************************************************************************/
2204 static IMAGE_TYPE * CreateImage( Display *p_display, EXTRA_ARGS,
2205 int i_width, int i_height )
2207 byte_t * p_data; /* image data storage zone */
2208 IMAGE_TYPE *p_image;
2209 #ifdef MODULE_NAME_IS_x11
2210 int i_quantum; /* XImage quantum (see below) */
2211 int i_bytes_per_line;
2214 /* Allocate memory for image */
2215 #ifdef MODULE_NAME_IS_xvideo
2216 p_data = (byte_t *) malloc( i_width * i_height * 2 ); /* XXX */
2218 i_bytes_per_line = i_width * i_bytes_per_pixel;
2219 p_data = (byte_t *) malloc( i_bytes_per_line * i_height );
2223 intf_ErrMsg( "vout error: %s", strerror(ENOMEM));
2227 #ifdef MODULE_NAME_IS_x11
2228 /* Optimize the quantum of a scanline regarding its size - the quantum is
2229 a diviser of the number of bits between the start of two scanlines. */
2230 if( i_bytes_per_line & 0xf )
2234 else if( i_bytes_per_line & 0x10 )
2244 /* Create XImage. p_data will be automatically freed */
2245 #ifdef MODULE_NAME_IS_xvideo
2246 p_image = XvCreateImage( p_display, i_xvport, i_chroma,
2247 p_data, i_width, i_height );
2249 p_image = XCreateImage( p_display, p_visual, i_depth, ZPixmap, 0,
2250 p_data, i_width, i_height, i_quantum, 0 );
2252 if( p_image == NULL )
2254 intf_ErrMsg( "vout error: XCreateImage() failed" );
2262 #ifdef MODULE_NAME_IS_x11
2263 /*****************************************************************************
2264 * SetPalette: sets an 8 bpp palette
2265 *****************************************************************************
2266 * This function sets the palette given as an argument. It does not return
2267 * anything, but could later send information on which colors it was unable
2269 *****************************************************************************/
2270 static void SetPalette( vout_thread_t *p_vout, u16 *red, u16 *green, u16 *blue )
2273 XColor p_colors[255];
2275 /* allocate palette */
2276 for( i = 0; i < 255; i++ )
2278 /* kludge: colors are indexed reversely because color 255 seems
2279 * to be reserved for black even if we try to set it to white */
2280 p_colors[ i ].pixel = 255 - i;
2281 p_colors[ i ].pad = 0;
2282 p_colors[ i ].flags = DoRed | DoGreen | DoBlue;
2283 p_colors[ i ].red = red[ 255 - i ];
2284 p_colors[ i ].blue = blue[ 255 - i ];
2285 p_colors[ i ].green = green[ 255 - i ];
2288 XStoreColors( p_vout->p_sys->p_display,
2289 p_vout->p_sys->colormap, p_colors, 255 );