1 /*****************************************************************************
2 * xcommon.c: Functions common to the X11 and XVideo plugins
3 *****************************************************************************
4 * Copyright (C) 1998-2006 the VideoLAN team
7 * Authors: Vincent Seguin <seguin@via.ecp.fr>
8 * Sam Hocevar <sam@zoy.org>
9 * David Kennedy <dkennedy@tinytoad.com>
10 * Gildas Bazin <gbazin@videolan.org>
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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25 *****************************************************************************/
27 /*****************************************************************************
29 *****************************************************************************/
30 #include <errno.h> /* ENOMEM */
31 #include <stdlib.h> /* free() */
32 #include <string.h> /* strerror() */
35 #include <vlc_interface.h>
36 #include <vlc_playlist.h>
40 #ifdef HAVE_MACHINE_PARAM_H
42 # include <machine/param.h>
43 # include <sys/types.h> /* typedef ushort */
48 # include <netinet/in.h> /* BSD: struct in_addr */
52 # include <sys/shm.h> /* shmget(), shmctl() */
56 #include <X11/Xproto.h>
58 #include <X11/Xutil.h>
59 #include <X11/keysym.h>
61 # include <X11/extensions/XShm.h>
63 #ifdef DPMSINFO_IN_DPMS_H
64 # include <X11/extensions/dpms.h>
67 #if defined(MODULE_NAME_IS_xvideo) || defined(MODULE_NAME_IS_xvmc)
68 # include <X11/extensions/Xv.h>
69 # include <X11/extensions/Xvlib.h>
72 #ifdef MODULE_NAME_IS_glx
77 # include <X11/extensions/Xinerama.h>
80 #ifdef HAVE_X11_EXTENSIONS_XF86VMODE_H
81 # include <X11/extensions/xf86vmode.h>
84 #ifdef MODULE_NAME_IS_xvmc
85 # include <X11/extensions/vldXvMC.h>
86 # include "../../codec/xvmc/accel_xvmc.h"
91 /*****************************************************************************
93 *****************************************************************************/
94 int E_(Activate) ( vlc_object_t * );
95 void E_(Deactivate) ( vlc_object_t * );
97 static int InitVideo ( vout_thread_t * );
98 static void EndVideo ( vout_thread_t * );
99 static void DisplayVideo ( vout_thread_t *, picture_t * );
100 static int ManageVideo ( vout_thread_t * );
101 static int Control ( vout_thread_t *, int, va_list );
103 static int InitDisplay ( vout_thread_t * );
105 static int CreateWindow ( vout_thread_t *, x11_window_t * );
106 static void DestroyWindow ( vout_thread_t *, x11_window_t * );
108 static int NewPicture ( vout_thread_t *, picture_t * );
109 static void FreePicture ( vout_thread_t *, picture_t * );
111 static IMAGE_TYPE *CreateImage ( vout_thread_t *,
112 Display *, EXTRA_ARGS, int, int );
113 #ifdef HAVE_SYS_SHM_H
114 static IMAGE_TYPE *CreateShmImage ( vout_thread_t *,
115 Display *, EXTRA_ARGS_SHM, int, int );
116 static vlc_bool_t b_shm = VLC_TRUE;
119 static void ToggleFullScreen ( vout_thread_t * );
121 static void EnableXScreenSaver ( vout_thread_t * );
122 static void DisableXScreenSaver ( vout_thread_t * );
124 static void CreateCursor ( vout_thread_t * );
125 static void DestroyCursor ( vout_thread_t * );
126 static void ToggleCursor ( vout_thread_t * );
128 #if defined(MODULE_NAME_IS_xvideo) || defined(MODULE_NAME_IS_xvmc)
129 static int XVideoGetPort ( vout_thread_t *, vlc_fourcc_t, vlc_fourcc_t * );
130 static void XVideoReleasePort( vout_thread_t *, int );
133 #ifdef MODULE_NAME_IS_x11
134 static void SetPalette ( vout_thread_t *,
135 uint16_t *, uint16_t *, uint16_t * );
138 #ifdef MODULE_NAME_IS_xvmc
139 static void RenderVideo ( vout_thread_t *, picture_t * );
140 static int xvmc_check_yv12( Display *display, XvPortID port );
141 static void xvmc_update_XV_DOUBLE_BUFFER( vout_thread_t *p_vout );
144 static void TestNetWMSupport( vout_thread_t * );
145 static int ConvertKey( int );
147 static int WindowOnTop( vout_thread_t *, vlc_bool_t );
149 static int X11ErrorHandler( Display *, XErrorEvent * );
151 /*****************************************************************************
152 * Activate: allocate X11 video thread output method
153 *****************************************************************************
154 * This function allocate and initialize a X11 vout method. It uses some of the
155 * vout properties to choose the window size, and change them according to the
156 * actual properties of the display.
157 *****************************************************************************/
158 int E_(Activate) ( vlc_object_t *p_this )
160 vout_thread_t *p_vout = (vout_thread_t *)p_this;
163 #if defined(MODULE_NAME_IS_xvmc)
166 #if defined(MODULE_NAME_IS_xvideo) || defined(MODULE_NAME_IS_xvmc)
168 vlc_fourcc_t i_chroma = 0;
169 vlc_bool_t b_chroma = 0;
172 p_vout->pf_init = InitVideo;
173 p_vout->pf_end = EndVideo;
174 p_vout->pf_manage = ManageVideo;
175 #ifdef MODULE_NAME_IS_xvmc
176 p_vout->pf_render = RenderVideo;
178 p_vout->pf_render = NULL;
180 p_vout->pf_display = DisplayVideo;
181 p_vout->pf_control = Control;
183 /* Allocate structure */
184 p_vout->p_sys = malloc( sizeof( vout_sys_t ) );
185 if( p_vout->p_sys == NULL )
187 msg_Err( p_vout, "out of memory" );
191 vlc_mutex_init( p_vout, &p_vout->p_sys->lock );
193 /* Open display, using the "display" config variable or the DISPLAY
194 * environment variable */
195 psz_display = config_GetPsz( p_vout, MODULE_STRING "-display" );
197 p_vout->p_sys->p_display = XOpenDisplay( psz_display );
199 if( p_vout->p_sys->p_display == NULL ) /* error */
201 msg_Err( p_vout, "cannot open display %s",
202 XDisplayName( psz_display ) );
203 free( p_vout->p_sys );
204 if( psz_display ) free( psz_display );
207 if( psz_display ) free( psz_display );
209 /* Replace error handler so we can intercept some non-fatal errors */
210 XSetErrorHandler( X11ErrorHandler );
212 /* Get a screen ID matching the XOpenDisplay return value */
213 p_vout->p_sys->i_screen = DefaultScreen( p_vout->p_sys->p_display );
215 #if defined(MODULE_NAME_IS_xvideo) || defined(MODULE_NAME_IS_xvmc)
216 psz_chroma = config_GetPsz( p_vout, "xvideo-chroma" );
219 if( strlen( psz_chroma ) >= 4 )
221 /* Do not use direct assignment because we are not sure of the
223 memcpy(&i_chroma, psz_chroma, 4);
232 msg_Dbg( p_vout, "forcing chroma 0x%.8x (%4.4s)",
233 i_chroma, (char*)&i_chroma );
237 i_chroma = p_vout->render.i_chroma;
240 /* Check that we have access to an XVideo port providing this chroma */
241 p_vout->p_sys->i_xvport = XVideoGetPort( p_vout, VLC2X11_FOURCC(i_chroma),
242 &p_vout->output.i_chroma );
243 if( p_vout->p_sys->i_xvport < 0 )
245 /* If a specific chroma format was requested, then we don't try to
246 * be cleverer than the user. He knew pretty well what he wanted. */
249 XCloseDisplay( p_vout->p_sys->p_display );
250 free( p_vout->p_sys );
254 /* It failed, but it's not completely lost ! We try to open an
255 * XVideo port for an YUY2 picture. We'll need to do an YUV
256 * conversion, but at least it has got scaling. */
257 p_vout->p_sys->i_xvport =
258 XVideoGetPort( p_vout, X11_FOURCC('Y','U','Y','2'),
259 &p_vout->output.i_chroma );
260 if( p_vout->p_sys->i_xvport < 0 )
262 /* It failed, but it's not completely lost ! We try to open an
263 * XVideo port for a simple 16bpp RGB picture. We'll need to do
264 * an YUV conversion, but at least it has got scaling. */
265 p_vout->p_sys->i_xvport =
266 XVideoGetPort( p_vout, X11_FOURCC('R','V','1','6'),
267 &p_vout->output.i_chroma );
268 if( p_vout->p_sys->i_xvport < 0 )
270 XCloseDisplay( p_vout->p_sys->p_display );
271 free( p_vout->p_sys );
276 p_vout->output.i_chroma = X112VLC_FOURCC(p_vout->output.i_chroma);
279 /* Create blank cursor (for mouse cursor autohiding) */
280 p_vout->p_sys->i_time_mouse_last_moved = mdate();
281 p_vout->p_sys->b_mouse_pointer_visible = 1;
282 CreateCursor( p_vout );
284 /* Set main window's size */
285 p_vout->p_sys->original_window.i_width = p_vout->i_window_width;
286 p_vout->p_sys->original_window.i_height = p_vout->i_window_height;
287 var_Create( p_vout, "video-title", VLC_VAR_STRING | VLC_VAR_DOINHERIT );
288 /* Spawn base window - this window will include the video output window,
289 * but also command buttons, subtitles and other indicators */
290 if( CreateWindow( p_vout, &p_vout->p_sys->original_window ) )
292 msg_Err( p_vout, "cannot create X11 window" );
293 DestroyCursor( p_vout );
294 XCloseDisplay( p_vout->p_sys->p_display );
295 free( p_vout->p_sys );
299 /* Open and initialize device. */
300 if( InitDisplay( p_vout ) )
302 msg_Err( p_vout, "cannot initialize X11 display" );
303 DestroyCursor( p_vout );
304 DestroyWindow( p_vout, &p_vout->p_sys->original_window );
305 XCloseDisplay( p_vout->p_sys->p_display );
306 free( p_vout->p_sys );
310 /* Disable screen saver */
311 DisableXScreenSaver( p_vout );
314 p_vout->p_sys->b_altfullscreen = 0;
315 p_vout->p_sys->i_time_button_last_pressed = 0;
317 TestNetWMSupport( p_vout );
319 #ifdef MODULE_NAME_IS_xvmc
320 p_vout->p_sys->p_last_subtitle_save = NULL;
321 psz_value = config_GetPsz( p_vout, "xvmc-deinterlace-mode" );
323 /* Look what method was requested */
324 //var_Create( p_vout, "xvmc-deinterlace-mode", VLC_VAR_STRING );
325 //var_Change( p_vout, "xvmc-deinterlace-mode", VLC_VAR_INHERITVALUE, &val, NULL );
328 if( (strcmp(psz_value, "bob") == 0) ||
329 (strcmp(psz_value, "blend") == 0) )
330 p_vout->p_sys->xvmc_deinterlace_method = 2;
331 else if (strcmp(psz_value, "discard") == 0)
332 p_vout->p_sys->xvmc_deinterlace_method = 1;
334 p_vout->p_sys->xvmc_deinterlace_method = 0;
338 p_vout->p_sys->xvmc_deinterlace_method = 0;
340 /* Look what method was requested */
341 //var_Create( p_vout, "xvmc-crop-style", VLC_VAR_STRING );
342 //var_Change( p_vout, "xvmc-crop-style", VLC_VAR_INHERITVALUE, &val, NULL );
343 psz_value = config_GetPsz( p_vout, "xvmc-crop-style" );
347 if( strncmp( psz_value, "eq", 2 ) == 0 )
348 p_vout->p_sys->xvmc_crop_style = 1;
349 else if( strncmp( psz_value, "4-16", 4 ) == 0)
350 p_vout->p_sys->xvmc_crop_style = 2;
351 else if( strncmp( psz_value, "16-4", 4 ) == 0)
352 p_vout->p_sys->xvmc_crop_style = 3;
354 p_vout->p_sys->xvmc_crop_style = 0;
358 p_vout->p_sys->xvmc_crop_style = 0;
360 msg_Dbg(p_vout, "Deinterlace = %d", p_vout->p_sys->xvmc_deinterlace_method);
361 msg_Dbg(p_vout, "Crop = %d", p_vout->p_sys->xvmc_crop_style);
363 if( !checkXvMCCap( p_vout ) )
365 msg_Err( p_vout, "no XVMC capability found" );
366 E_(Deactivate)( p_vout );
369 sub_pic.p_sys = NULL;
370 p_vout->p_sys->last_date = 0;
373 /* Variable to indicate if the window should be on top of others */
374 /* Trigger a callback right now */
375 var_Get( p_vout, "video-on-top", &val );
376 var_Set( p_vout, "video-on-top", val );
381 /*****************************************************************************
382 * Deactivate: destroy X11 video thread output method
383 *****************************************************************************
384 * Terminate an output method created by Open
385 *****************************************************************************/
386 void E_(Deactivate) ( vlc_object_t *p_this )
388 vout_thread_t *p_vout = (vout_thread_t *)p_this;
390 /* If the fullscreen window is still open, close it */
391 if( p_vout->b_fullscreen )
393 ToggleFullScreen( p_vout );
396 /* Restore cursor if it was blanked */
397 if( !p_vout->p_sys->b_mouse_pointer_visible )
399 ToggleCursor( p_vout );
402 #ifdef MODULE_NAME_IS_x11
403 /* Destroy colormap */
404 if( XDefaultDepth(p_vout->p_sys->p_display, p_vout->p_sys->i_screen) == 8 )
406 XFreeColormap( p_vout->p_sys->p_display, p_vout->p_sys->colormap );
408 #elif defined(MODULE_NAME_IS_xvideo)
409 XVideoReleasePort( p_vout, p_vout->p_sys->i_xvport );
410 #elif defined(MODULE_NAME_IS_xvmc)
411 if( p_vout->p_sys->xvmc_cap )
413 xvmc_context_writer_lock( &p_vout->p_sys->xvmc_lock );
414 xxmc_dispose_context( p_vout );
415 if( p_vout->p_sys->old_subpic )
417 xxmc_xvmc_free_subpicture( p_vout, p_vout->p_sys->old_subpic );
418 p_vout->p_sys->old_subpic = NULL;
420 if( p_vout->p_sys->new_subpic )
422 xxmc_xvmc_free_subpicture( p_vout, p_vout->p_sys->new_subpic );
423 p_vout->p_sys->new_subpic = NULL;
425 free( p_vout->p_sys->xvmc_cap );
426 xvmc_context_writer_unlock( &p_vout->p_sys->xvmc_lock );
430 DestroyCursor( p_vout );
431 EnableXScreenSaver( p_vout );
432 DestroyWindow( p_vout, &p_vout->p_sys->original_window );
433 XCloseDisplay( p_vout->p_sys->p_display );
435 /* Destroy structure */
436 vlc_mutex_destroy( &p_vout->p_sys->lock );
437 #ifdef MODULE_NAME_IS_xvmc
438 free_context_lock( &p_vout->p_sys->xvmc_lock );
441 free( p_vout->p_sys );
444 #ifdef MODULE_NAME_IS_xvmc
446 #define XINE_IMGFMT_YV12 (('2'<<24)|('1'<<16)|('V'<<8)|'Y')
449 static int xvmc_check_yv12( Display *display, XvPortID port )
451 XvImageFormatValues *formatValues;
455 formatValues = XvListImageFormats( display, port, &formats );
457 for( i = 0; i < formats; i++ )
459 if( ( formatValues[i].id == XINE_IMGFMT_YV12 ) &&
460 ( !( strncmp( formatValues[i].guid, "YV12", 4 ) ) ) )
462 XFree (formatValues);
467 XFree (formatValues);
471 static void xvmc_sync_surface( vout_thread_t *p_vout, XvMCSurface * srf )
473 XvMCSyncSurface( p_vout->p_sys->p_display, srf );
476 static void xvmc_update_XV_DOUBLE_BUFFER( vout_thread_t *p_vout )
479 int xv_double_buffer;
481 xv_double_buffer = 1;
483 XLockDisplay( p_vout->p_sys->p_display );
484 atom = XInternAtom( p_vout->p_sys->p_display, "XV_DOUBLE_BUFFER", False );
486 XvSetPortAttribute (p_vout->p_sys->p_display, p_vout->p_sys->i_xvport, atom, xv_double_buffer);
488 XvMCSetAttribute( p_vout->p_sys->p_display, &p_vout->p_sys->context, atom, xv_double_buffer );
489 XUnlockDisplay( p_vout->p_sys->p_display );
491 //xprintf(this->xine, XINE_VERBOSITY_DEBUG,
492 // "video_out_xxmc: double buffering mode = %d\n", xv_double_buffer);
495 static void RenderVideo( vout_thread_t *p_vout, picture_t *p_pic )
497 vlc_xxmc_t *xxmc = NULL;
499 vlc_mutex_lock( &p_vout->p_sys->lock );
500 xvmc_context_reader_lock( &p_vout->p_sys->xvmc_lock );
502 xxmc = &p_pic->p_sys->xxmc_data;
503 if( (!xxmc->decoded ||
504 !xxmc_xvmc_surface_valid( p_vout, p_pic->p_sys->xvmc_surf )) )
506 vlc_mutex_unlock( &p_vout->p_sys->lock );
507 xvmc_context_reader_unlock( &p_vout->p_sys->xvmc_lock );
511 vlc_mutex_lock( &p_vout->lastsubtitle_lock );
513 if (p_vout->p_last_subtitle != NULL)
515 if( p_vout->p_sys->p_last_subtitle_save != p_vout->p_last_subtitle )
517 p_vout->p_sys->new_subpic =
518 xxmc_xvmc_alloc_subpicture( p_vout, &p_vout->p_sys->context,
519 p_vout->p_sys->xvmc_width,
520 p_vout->p_sys->xvmc_height,
521 p_vout->p_sys->xvmc_cap[p_vout->p_sys->xvmc_cur_cap].subPicType.id );
523 if (p_vout->p_sys->new_subpic)
525 XVMCLOCKDISPLAY( p_vout->p_sys->p_display );
526 XvMCClearSubpicture( p_vout->p_sys->p_display,
527 p_vout->p_sys->new_subpic,
530 p_vout->p_sys->xvmc_width,
531 p_vout->p_sys->xvmc_height,
533 XVMCUNLOCKDISPLAY( p_vout->p_sys->p_display );
534 clear_xx44_palette( &p_vout->p_sys->palette );
536 if( sub_pic.p_sys == NULL )
538 sub_pic.p_sys = malloc( sizeof( picture_sys_t ) );
539 if( sub_pic.p_sys != NULL )
541 sub_pic.p_sys->p_vout = p_vout;
542 sub_pic.p_sys->xvmc_surf = NULL;
543 sub_pic.p_sys->p_image = p_vout->p_sys->subImage;
546 sub_pic.p_sys->p_image = p_vout->p_sys->subImage;
547 sub_pic.p->p_pixels = sub_pic.p_sys->p_image->data;
548 sub_pic.p->i_pitch = p_vout->output.i_width;
550 memset( p_vout->p_sys->subImage->data, 0,
551 (p_vout->p_sys->subImage->width * p_vout->p_sys->subImage->height) );
553 if (p_vout->p_last_subtitle != NULL)
555 blend_xx44( p_vout->p_sys->subImage->data,
556 p_vout->p_last_subtitle,
557 p_vout->p_sys->subImage->width,
558 p_vout->p_sys->subImage->height,
559 p_vout->p_sys->subImage->width,
560 &p_vout->p_sys->palette,
561 (p_vout->p_sys->subImage->id == FOURCC_IA44) );
564 XVMCLOCKDISPLAY( p_vout->p_sys->p_display );
565 XvMCCompositeSubpicture( p_vout->p_sys->p_display,
566 p_vout->p_sys->new_subpic,
567 p_vout->p_sys->subImage,
570 p_vout->output.i_width, /* overlay->width, */
571 p_vout->output.i_height, /* overlay->height */
574 XVMCUNLOCKDISPLAY( p_vout->p_sys->p_display );
575 if (p_vout->p_sys->old_subpic)
577 xxmc_xvmc_free_subpicture( p_vout,
578 p_vout->p_sys->old_subpic);
579 p_vout->p_sys->old_subpic = NULL;
581 if (p_vout->p_sys->new_subpic)
583 p_vout->p_sys->old_subpic = p_vout->p_sys->new_subpic;
584 p_vout->p_sys->new_subpic = NULL;
585 xx44_to_xvmc_palette( &p_vout->p_sys->palette,
586 p_vout->p_sys->xvmc_palette,
588 p_vout->p_sys->old_subpic->num_palette_entries,
589 p_vout->p_sys->old_subpic->entry_bytes,
590 p_vout->p_sys->old_subpic->component_order );
591 XVMCLOCKDISPLAY( p_vout->p_sys->p_display );
592 XvMCSetSubpicturePalette( p_vout->p_sys->p_display,
593 p_vout->p_sys->old_subpic,
594 p_vout->p_sys->xvmc_palette );
595 XvMCFlushSubpicture( p_vout->p_sys->p_display,
596 p_vout->p_sys->old_subpic);
597 XvMCSyncSubpicture( p_vout->p_sys->p_display,
598 p_vout->p_sys->old_subpic );
599 XVMCUNLOCKDISPLAY( p_vout->p_sys->p_display );
602 XVMCLOCKDISPLAY( p_vout->p_sys->p_display);
603 if (p_vout->p_sys->xvmc_backend_subpic )
605 XvMCBlendSubpicture( p_vout->p_sys->p_display,
606 p_pic->p_sys->xvmc_surf,
607 p_vout->p_sys->old_subpic,
610 p_vout->p_sys->xvmc_width,
611 p_vout->p_sys->xvmc_height,
614 p_vout->p_sys->xvmc_width,
615 p_vout->p_sys->xvmc_height );
619 XvMCBlendSubpicture2( p_vout->p_sys->p_display,
620 p_pic->p_sys->xvmc_surf,
621 p_pic->p_sys->xvmc_surf,
622 p_vout->p_sys->old_subpic,
625 p_vout->p_sys->xvmc_width,
626 p_vout->p_sys->xvmc_height,
629 p_vout->p_sys->xvmc_width,
630 p_vout->p_sys->xvmc_height );
632 XVMCUNLOCKDISPLAY(p_vout->p_sys->p_display);
637 XVMCLOCKDISPLAY( p_vout->p_sys->p_display );
638 if( p_vout->p_sys->xvmc_backend_subpic )
640 XvMCBlendSubpicture( p_vout->p_sys->p_display,
641 p_pic->p_sys->xvmc_surf,
642 p_vout->p_sys->old_subpic,
644 p_vout->p_sys->xvmc_width,
645 p_vout->p_sys->xvmc_height,
647 p_vout->p_sys->xvmc_width,
648 p_vout->p_sys->xvmc_height );
652 XvMCBlendSubpicture2( p_vout->p_sys->p_display,
653 p_pic->p_sys->xvmc_surf,
654 p_pic->p_sys->xvmc_surf,
655 p_vout->p_sys->old_subpic,
657 p_vout->p_sys->xvmc_width,
658 p_vout->p_sys->xvmc_height,
660 p_vout->p_sys->xvmc_width,
661 p_vout->p_sys->xvmc_height );
663 XVMCUNLOCKDISPLAY( p_vout->p_sys->p_display );
666 p_vout->p_sys->p_last_subtitle_save = p_vout->p_last_subtitle;
668 vlc_mutex_unlock( &p_vout->lastsubtitle_lock );
669 xvmc_context_reader_unlock( &p_vout->p_sys->xvmc_lock );
671 vlc_mutex_unlock( &p_vout->p_sys->lock );
675 /*****************************************************************************
676 * InitVideo: initialize X11 video thread output method
677 *****************************************************************************
678 * This function create the XImages needed by the output thread. It is called
679 * at the beginning of the thread, but also each time the window is resized.
680 *****************************************************************************/
681 static int InitVideo( vout_thread_t *p_vout )
683 unsigned int i_index = 0;
686 I_OUTPUTPICTURES = 0;
688 #if defined(MODULE_NAME_IS_xvideo) || defined(MODULE_NAME_IS_xvmc)
689 /* Initialize the output structure; we already found an XVideo port,
690 * and the corresponding chroma we will be using. Since we can
691 * arbitrary scale, stick to the coordinates and aspect. */
692 p_vout->output.i_width = p_vout->render.i_width;
693 p_vout->output.i_height = p_vout->render.i_height;
694 p_vout->output.i_aspect = p_vout->render.i_aspect;
696 p_vout->fmt_out = p_vout->fmt_in;
697 p_vout->fmt_out.i_chroma = p_vout->output.i_chroma;
699 switch( p_vout->output.i_chroma )
701 case VLC_FOURCC('R','V','1','6'):
702 #if defined( WORDS_BIGENDIAN )
703 p_vout->output.i_rmask = 0xf800;
704 p_vout->output.i_gmask = 0x07e0;
705 p_vout->output.i_bmask = 0x001f;
707 p_vout->output.i_rmask = 0x001f;
708 p_vout->output.i_gmask = 0x07e0;
709 p_vout->output.i_bmask = 0xf800;
712 case VLC_FOURCC('R','V','1','5'):
713 #if defined( WORDS_BIGENDIAN )
714 p_vout->output.i_rmask = 0x7c00;
715 p_vout->output.i_gmask = 0x03e0;
716 p_vout->output.i_bmask = 0x001f;
718 p_vout->output.i_rmask = 0x001f;
719 p_vout->output.i_gmask = 0x03e0;
720 p_vout->output.i_bmask = 0x7c00;
725 #elif defined(MODULE_NAME_IS_x11)
726 /* Initialize the output structure: RGB with square pixels, whatever
727 * the input format is, since it's the only format we know */
728 switch( p_vout->p_sys->i_screen_depth )
730 case 8: /* FIXME: set the palette */
731 p_vout->output.i_chroma = VLC_FOURCC('R','G','B','2'); break;
733 p_vout->output.i_chroma = VLC_FOURCC('R','V','1','5'); break;
735 p_vout->output.i_chroma = VLC_FOURCC('R','V','1','6'); break;
738 p_vout->output.i_chroma = VLC_FOURCC('R','V','3','2'); break;
740 msg_Err( p_vout, "unknown screen depth %i",
741 p_vout->p_sys->i_screen_depth );
745 vout_PlacePicture( p_vout, p_vout->p_sys->p_win->i_width,
746 p_vout->p_sys->p_win->i_height,
748 &p_vout->fmt_out.i_visible_width,
749 &p_vout->fmt_out.i_visible_height );
751 p_vout->fmt_out.i_chroma = p_vout->output.i_chroma;
753 p_vout->output.i_width = p_vout->fmt_out.i_width =
754 p_vout->fmt_out.i_visible_width * p_vout->fmt_in.i_width /
755 p_vout->fmt_in.i_visible_width;
756 p_vout->output.i_height = p_vout->fmt_out.i_height =
757 p_vout->fmt_out.i_visible_height * p_vout->fmt_in.i_height /
758 p_vout->fmt_in.i_visible_height;
759 p_vout->fmt_out.i_x_offset =
760 p_vout->fmt_out.i_visible_width * p_vout->fmt_in.i_x_offset /
761 p_vout->fmt_in.i_visible_width;
762 p_vout->fmt_out.i_y_offset =
763 p_vout->fmt_out.i_visible_height * p_vout->fmt_in.i_y_offset /
764 p_vout->fmt_in.i_visible_height;
766 p_vout->fmt_out.i_sar_num = p_vout->fmt_out.i_sar_den = 1;
767 p_vout->output.i_aspect = p_vout->fmt_out.i_aspect =
768 p_vout->fmt_out.i_width * VOUT_ASPECT_FACTOR /p_vout->fmt_out.i_height;
770 msg_Dbg( p_vout, "x11 image size %ix%i (%i,%i,%ix%i)",
771 p_vout->fmt_out.i_width, p_vout->fmt_out.i_height,
772 p_vout->fmt_out.i_x_offset, p_vout->fmt_out.i_y_offset,
773 p_vout->fmt_out.i_visible_width,
774 p_vout->fmt_out.i_visible_height );
777 /* Try to initialize up to MAX_DIRECTBUFFERS direct buffers */
778 while( I_OUTPUTPICTURES < MAX_DIRECTBUFFERS )
782 /* Find an empty picture slot */
783 for( i_index = 0 ; i_index < VOUT_MAX_PICTURES ; i_index++ )
785 if( p_vout->p_picture[ i_index ].i_status == FREE_PICTURE )
787 p_pic = p_vout->p_picture + i_index;
792 /* Allocate the picture */
793 if( p_pic == NULL || NewPicture( p_vout, p_pic ) )
798 p_pic->i_status = DESTROYED_PICTURE;
799 p_pic->i_type = DIRECT_PICTURE;
801 PP_OUTPUTPICTURE[ I_OUTPUTPICTURES ] = p_pic;
806 if( p_vout->output.i_chroma == VLC_FOURCC('Y','V','1','2') )
808 /* U and V inverted compared to I420
809 * Fixme: this should be handled by the vout core */
810 p_vout->output.i_chroma = VLC_FOURCC('I','4','2','0');
811 p_vout->fmt_out.i_chroma = VLC_FOURCC('I','4','2','0');
817 /*****************************************************************************
818 * DisplayVideo: displays previously rendered output
819 *****************************************************************************
820 * This function sends the currently rendered image to X11 server.
821 * (The Xv extension takes care of "double-buffering".)
822 *****************************************************************************/
823 static void DisplayVideo( vout_thread_t *p_vout, picture_t *p_pic )
825 unsigned int i_width, i_height, i_x, i_y;
827 vout_PlacePicture( p_vout, p_vout->p_sys->p_win->i_width,
828 p_vout->p_sys->p_win->i_height,
829 &i_x, &i_y, &i_width, &i_height );
831 vlc_mutex_lock( &p_vout->p_sys->lock );
833 #ifdef MODULE_NAME_IS_xvmc
834 xvmc_context_reader_lock( &p_vout->p_sys->xvmc_lock );
836 vlc_xxmc_t *xxmc = &p_picture->p_sys->xxmc_data;
837 if( !xxmc->decoded ||
838 !xxmc_xvmc_surface_valid( p_vout, p_picture->p_sys->xvmc_surf ) )
840 msg_Dbg( p_vout, "DisplayVideo decoded=%d\tsurfacevalid=%d",
842 xxmc_xvmc_surface_valid( p_vout, p_picture->p_sys->xvmc_surf ) );
843 vlc_mutex_unlock( &p_vout->p_sys->lock );
844 xvmc_context_reader_unlock( &p_vout->p_sys->xvmc_lock );
848 src_width = p_vout->output.i_width;
849 src_height = p_vout->output.i_height;
851 if( p_vout->p_sys->xvmc_crop_style == 1 )
858 else if( p_vout->p_sys->xvmc_crop_style == 2 )
865 else if( p_vout->p_sys->xvmc_crop_style == 3 )
878 if( p_vout->p_sys->xvmc_deinterlace_method > 0 )
879 { /* BOB DEINTERLACE */
880 if( (p_picture->p_sys->nb_display == 0) ||
881 (p_vout->p_sys->xvmc_deinterlace_method == 1) )
883 first_field = (p_picture->b_top_field_first) ?
884 XVMC_BOTTOM_FIELD : XVMC_TOP_FIELD;
888 first_field = (p_picture->b_top_field_first) ?
889 XVMC_TOP_FIELD : XVMC_BOTTOM_FIELD;
894 first_field = XVMC_FRAME_PICTURE;
897 XVMCLOCKDISPLAY( p_vout->p_sys->p_display );
898 XvMCFlushSurface( p_vout->p_sys->p_display, p_picture->p_sys->xvmc_surf );
899 /* XvMCSyncSurface(p_vout->p_sys->p_display, p_picture->p_sys->xvmc_surf); */
900 XvMCPutSurface( p_vout->p_sys->p_display,
901 p_picture->p_sys->xvmc_surf,
902 p_vout->p_sys->p_win->video_window,
913 XVMCUNLOCKDISPLAY( p_vout->p_sys->p_display );
914 if( p_vout->p_sys->xvmc_deinterlace_method == 2 )
915 { /* BOB DEINTERLACE */
916 if( p_picture->p_sys->nb_display == 0 )/* && ((t2-t1) < 15000)) */
918 mtime_t last_date = p_picture->date;
920 vlc_mutex_lock( &p_vout->picture_lock );
921 if( !p_vout->p_sys->last_date )
923 p_picture->date += 20000;
927 p_picture->date = ((3 * p_picture->date -
928 p_vout->p_sys->last_date) / 2 );
930 p_vout->p_sys->last_date = last_date;
931 p_picture->b_force = 1;
932 p_picture->p_sys->nb_display = 1;
933 vlc_mutex_unlock( &p_vout->picture_lock );
937 p_picture->p_sys->nb_display = 0;
938 p_picture->b_force = 0;
941 xvmc_context_reader_unlock( &p_vout->p_sys->xvmc_lock );
944 #ifdef HAVE_SYS_SHM_H
945 if( p_vout->p_sys->b_shm )
947 /* Display rendered image using shared memory extension */
948 # if defined(MODULE_NAME_IS_xvideo) || defined(MODULE_NAME_IS_xvmc)
949 XvShmPutImage( p_vout->p_sys->p_display, p_vout->p_sys->i_xvport,
950 p_vout->p_sys->p_win->video_window,
951 p_vout->p_sys->p_win->gc, p_pic->p_sys->p_image,
952 p_vout->fmt_out.i_x_offset,
953 p_vout->fmt_out.i_y_offset,
954 p_vout->fmt_out.i_visible_width,
955 p_vout->fmt_out.i_visible_height,
956 0 /*dest_x*/, 0 /*dest_y*/, i_width, i_height,
957 False /* Don't put True here or you'll waste your CPU */ );
959 XShmPutImage( p_vout->p_sys->p_display,
960 p_vout->p_sys->p_win->video_window,
961 p_vout->p_sys->p_win->gc, p_pic->p_sys->p_image,
962 p_vout->fmt_out.i_x_offset,
963 p_vout->fmt_out.i_y_offset,
964 0 /*dest_x*/, 0 /*dest_y*/,
965 p_vout->fmt_out.i_visible_width,
966 p_vout->fmt_out.i_visible_height,
967 False /* Don't put True here ! */ );
971 #endif /* HAVE_SYS_SHM_H */
973 /* Use standard XPutImage -- this is gonna be slow ! */
974 #if defined(MODULE_NAME_IS_xvideo) || defined(MODULE_NAME_IS_xvmc)
975 XvPutImage( p_vout->p_sys->p_display, p_vout->p_sys->i_xvport,
976 p_vout->p_sys->p_win->video_window,
977 p_vout->p_sys->p_win->gc, p_pic->p_sys->p_image,
978 p_vout->fmt_out.i_x_offset,
979 p_vout->fmt_out.i_y_offset,
980 p_vout->fmt_out.i_visible_width,
981 p_vout->fmt_out.i_visible_height,
982 0 /*dest_x*/, 0 /*dest_y*/, i_width, i_height );
984 XPutImage( p_vout->p_sys->p_display,
985 p_vout->p_sys->p_win->video_window,
986 p_vout->p_sys->p_win->gc, p_pic->p_sys->p_image,
987 p_vout->fmt_out.i_x_offset,
988 p_vout->fmt_out.i_y_offset,
989 0 /*dest_x*/, 0 /*dest_y*/,
990 p_vout->fmt_out.i_visible_width,
991 p_vout->fmt_out.i_visible_height );
995 /* Make sure the command is sent now - do NOT use XFlush !*/
996 XSync( p_vout->p_sys->p_display, False );
998 vlc_mutex_unlock( &p_vout->p_sys->lock );
1001 /*****************************************************************************
1002 * ManageVideo: handle X11 events
1003 *****************************************************************************
1004 * This function should be called regularly by video output thread. It manages
1005 * X11 events and allows window resizing. It returns a non null value on
1007 *****************************************************************************/
1008 static int ManageVideo( vout_thread_t *p_vout )
1010 XEvent xevent; /* X11 event */
1013 vlc_mutex_lock( &p_vout->p_sys->lock );
1015 #ifdef MODULE_NAME_IS_xvmc
1016 xvmc_context_reader_lock( &p_vout->p_sys->xvmc_lock );
1019 /* Handle events from the owner window */
1020 if( p_vout->p_sys->p_win->owner_window )
1022 while( XCheckWindowEvent( p_vout->p_sys->p_display,
1023 p_vout->p_sys->p_win->owner_window,
1024 StructureNotifyMask, &xevent ) == True )
1026 /* ConfigureNotify event: prepare */
1027 if( xevent.type == ConfigureNotify )
1029 /* Update dimensions */
1030 XResizeWindow( p_vout->p_sys->p_display,
1031 p_vout->p_sys->p_win->base_window,
1032 xevent.xconfigure.width,
1033 xevent.xconfigure.height );
1038 /* Handle X11 events: ConfigureNotify events are parsed to know if the
1039 * output window's size changed, MapNotify and UnmapNotify to know if the
1040 * window is mapped (and if the display is useful), and ClientMessages
1041 * to intercept window destruction requests */
1043 while( XCheckWindowEvent( p_vout->p_sys->p_display,
1044 p_vout->p_sys->p_win->base_window,
1045 StructureNotifyMask | KeyPressMask |
1046 ButtonPressMask | ButtonReleaseMask |
1047 PointerMotionMask | Button1MotionMask , &xevent )
1050 /* ConfigureNotify event: prepare */
1051 if( xevent.type == ConfigureNotify )
1053 if( (unsigned int)xevent.xconfigure.width
1054 != p_vout->p_sys->p_win->i_width
1055 || (unsigned int)xevent.xconfigure.height
1056 != p_vout->p_sys->p_win->i_height )
1058 /* Update dimensions */
1059 p_vout->i_changes |= VOUT_SIZE_CHANGE;
1060 p_vout->p_sys->p_win->i_width = xevent.xconfigure.width;
1061 p_vout->p_sys->p_win->i_height = xevent.xconfigure.height;
1064 /* Keyboard event */
1065 else if( xevent.type == KeyPress )
1067 unsigned int state = xevent.xkey.state;
1068 KeySym x_key_symbol;
1069 char i_key; /* ISO Latin-1 key */
1071 /* We may have keys like F1 trough F12, ESC ... */
1072 x_key_symbol = XKeycodeToKeysym( p_vout->p_sys->p_display,
1073 xevent.xkey.keycode, 0 );
1074 val.i_int = ConvertKey( (int)x_key_symbol );
1076 xevent.xkey.state &= ~ShiftMask;
1077 xevent.xkey.state &= ~ControlMask;
1078 xevent.xkey.state &= ~Mod1Mask;
1081 XLookupString( &xevent.xkey, &i_key, 1, NULL, NULL ) )
1084 * The reason why I use this instead of XK_0 is that
1085 * with XLookupString, we don't have to care about
1092 if( state & ShiftMask )
1094 val.i_int |= KEY_MODIFIER_SHIFT;
1096 if( state & ControlMask )
1098 val.i_int |= KEY_MODIFIER_CTRL;
1100 if( state & Mod1Mask )
1102 val.i_int |= KEY_MODIFIER_ALT;
1104 var_Set( p_vout->p_libvlc, "key-pressed", val );
1108 else if( xevent.type == ButtonPress )
1110 switch( ((XButtonEvent *)&xevent)->button )
1113 var_Get( p_vout, "mouse-button-down", &val );
1115 var_Set( p_vout, "mouse-button-down", val );
1117 /* detect double-clicks */
1118 if( ( ((XButtonEvent *)&xevent)->time -
1119 p_vout->p_sys->i_time_button_last_pressed ) < 300 )
1121 p_vout->i_changes |= VOUT_FULLSCREEN_CHANGE;
1124 p_vout->p_sys->i_time_button_last_pressed =
1125 ((XButtonEvent *)&xevent)->time;
1128 var_Get( p_vout, "mouse-button-down", &val );
1130 var_Set( p_vout, "mouse-button-down", val );
1134 var_Get( p_vout, "mouse-button-down", &val );
1136 var_Set( p_vout, "mouse-button-down", val );
1140 var_Get( p_vout, "mouse-button-down", &val );
1142 var_Set( p_vout, "mouse-button-down", val );
1146 var_Get( p_vout, "mouse-button-down", &val );
1148 var_Set( p_vout, "mouse-button-down", val );
1153 else if( xevent.type == ButtonRelease )
1155 switch( ((XButtonEvent *)&xevent)->button )
1158 var_Get( p_vout, "mouse-button-down", &val );
1160 var_Set( p_vout, "mouse-button-down", val );
1162 val.b_bool = VLC_TRUE;
1163 var_Set( p_vout, "mouse-clicked", val );
1168 playlist_t *p_playlist;
1170 var_Get( p_vout, "mouse-button-down", &val );
1172 var_Set( p_vout, "mouse-button-down", val );
1174 p_playlist = vlc_object_find( p_vout,
1175 VLC_OBJECT_PLAYLIST,
1177 if( p_playlist != NULL )
1180 var_Get( p_playlist, "intf-show", &val );
1181 val.b_bool = !val.b_bool;
1182 var_Set( p_playlist, "intf-show", val );
1183 vlc_object_release( p_playlist );
1190 intf_thread_t *p_intf;
1191 playlist_t *p_playlist;
1193 var_Get( p_vout, "mouse-button-down", &val );
1195 var_Set( p_vout, "mouse-button-down", val );
1196 p_intf = vlc_object_find( p_vout, VLC_OBJECT_INTF,
1200 p_intf->b_menu_change = 1;
1201 vlc_object_release( p_intf );
1204 p_playlist = vlc_object_find( p_vout,
1205 VLC_OBJECT_PLAYLIST,
1207 if( p_playlist != NULL )
1209 vlc_value_t val; val.b_bool = VLC_TRUE;
1210 var_Set( p_playlist, "intf-popupmenu", val );
1211 vlc_object_release( p_playlist );
1217 var_Get( p_vout, "mouse-button-down", &val );
1219 var_Set( p_vout, "mouse-button-down", val );
1223 var_Get( p_vout, "mouse-button-down", &val );
1225 var_Set( p_vout, "mouse-button-down", val );
1231 else if( xevent.type == MotionNotify )
1233 unsigned int i_width, i_height, i_x, i_y;
1236 /* somewhat different use for vout_PlacePicture:
1237 * here the values are needed to give to mouse coordinates
1238 * in the original picture space */
1239 vout_PlacePicture( p_vout, p_vout->p_sys->p_win->i_width,
1240 p_vout->p_sys->p_win->i_height,
1241 &i_x, &i_y, &i_width, &i_height );
1243 val.i_int = ( xevent.xmotion.x - i_x ) *
1244 p_vout->fmt_in.i_visible_width / i_width +
1245 p_vout->fmt_in.i_x_offset;
1246 var_Set( p_vout, "mouse-x", val );
1247 val.i_int = ( xevent.xmotion.y - i_y ) *
1248 p_vout->fmt_in.i_visible_height / i_height +
1249 p_vout->fmt_in.i_y_offset;
1250 var_Set( p_vout, "mouse-y", val );
1252 val.b_bool = VLC_TRUE;
1253 var_Set( p_vout, "mouse-moved", val );
1255 p_vout->p_sys->i_time_mouse_last_moved = mdate();
1256 if( ! p_vout->p_sys->b_mouse_pointer_visible )
1258 ToggleCursor( p_vout );
1261 else if( xevent.type == ReparentNotify /* XXX: why do we get this? */
1262 || xevent.type == MapNotify
1263 || xevent.type == UnmapNotify )
1265 /* Ignore these events */
1267 else /* Other events */
1269 msg_Warn( p_vout, "unhandled event %d received", xevent.type );
1273 /* Handle events for video output sub-window */
1274 while( XCheckWindowEvent( p_vout->p_sys->p_display,
1275 p_vout->p_sys->p_win->video_window,
1276 ExposureMask, &xevent ) == True )
1278 /* Window exposed (only handled if stream playback is paused) */
1279 if( xevent.type == Expose )
1281 if( ((XExposeEvent *)&xevent)->count == 0 )
1283 /* (if this is the last a collection of expose events...) */
1285 if( p_vout->p_libvlc->p_input_bank->pp_input[0] != NULL )
1287 if( PAUSE_S == p_vout->p_libvlc->p_input_bank->pp_input[0]
1288 ->stream.control.i_status )
1290 /* XVideoDisplay( p_vout )*/;
1298 /* ClientMessage event - only WM_PROTOCOLS with WM_DELETE_WINDOW data
1299 * are handled - according to the man pages, the format is always 32
1301 while( XCheckTypedEvent( p_vout->p_sys->p_display,
1302 ClientMessage, &xevent ) )
1304 if( (xevent.xclient.message_type == p_vout->p_sys->p_win->wm_protocols)
1305 && ((Atom)xevent.xclient.data.l[0]
1306 == p_vout->p_sys->p_win->wm_delete_window ) )
1308 /* the user wants to close the window */
1309 playlist_t * p_playlist =
1310 (playlist_t *)vlc_object_find( p_vout, VLC_OBJECT_PLAYLIST,
1312 if( p_playlist != NULL )
1314 playlist_Stop( p_playlist );
1315 vlc_object_release( p_playlist );
1323 if ( p_vout->i_changes & VOUT_FULLSCREEN_CHANGE )
1327 /* Update the object variable and trigger callback */
1328 val.b_bool = !p_vout->b_fullscreen;
1329 var_Set( p_vout, "fullscreen", val );
1331 ToggleFullScreen( p_vout );
1332 p_vout->i_changes &= ~VOUT_FULLSCREEN_CHANGE;
1335 if( p_vout->i_changes & VOUT_CROP_CHANGE ||
1336 p_vout->i_changes & VOUT_ASPECT_CHANGE )
1338 p_vout->i_changes &= ~VOUT_CROP_CHANGE;
1339 p_vout->i_changes &= ~VOUT_ASPECT_CHANGE;
1341 p_vout->fmt_out.i_x_offset = p_vout->fmt_in.i_x_offset;
1342 p_vout->fmt_out.i_y_offset = p_vout->fmt_in.i_y_offset;
1343 p_vout->fmt_out.i_visible_width = p_vout->fmt_in.i_visible_width;
1344 p_vout->fmt_out.i_visible_height = p_vout->fmt_in.i_visible_height;
1345 p_vout->fmt_out.i_aspect = p_vout->fmt_in.i_aspect;
1346 p_vout->fmt_out.i_sar_num = p_vout->fmt_in.i_sar_num;
1347 p_vout->fmt_out.i_sar_den = p_vout->fmt_in.i_sar_den;
1348 p_vout->output.i_aspect = p_vout->fmt_in.i_aspect;
1350 p_vout->i_changes |= VOUT_SIZE_CHANGE;
1356 * (Needs to be placed after VOUT_FULLSREEN_CHANGE because we can activate
1357 * the size flag inside the fullscreen routine)
1359 if( p_vout->i_changes & VOUT_SIZE_CHANGE )
1361 unsigned int i_width, i_height, i_x, i_y;
1363 p_vout->i_changes &= ~VOUT_SIZE_CHANGE;
1365 #ifdef MODULE_NAME_IS_x11
1366 /* We need to signal the vout thread about the size change because it
1367 * is doing the rescaling */
1368 p_vout->i_changes |= VOUT_SIZE_CHANGE;
1371 vout_PlacePicture( p_vout, p_vout->p_sys->p_win->i_width,
1372 p_vout->p_sys->p_win->i_height,
1373 &i_x, &i_y, &i_width, &i_height );
1375 XMoveResizeWindow( p_vout->p_sys->p_display,
1376 p_vout->p_sys->p_win->video_window,
1377 i_x, i_y, i_width, i_height );
1380 /* Autohide Cursour */
1381 if( mdate() - p_vout->p_sys->i_time_mouse_last_moved > 2000000 )
1383 /* Hide the mouse automatically */
1384 if( p_vout->p_sys->b_mouse_pointer_visible )
1386 ToggleCursor( p_vout );
1390 #ifdef MODULE_NAME_IS_xvmc
1391 xvmc_context_reader_unlock( &p_vout->p_sys->xvmc_lock );
1394 vlc_mutex_unlock( &p_vout->p_sys->lock );
1398 /*****************************************************************************
1399 * EndVideo: terminate X11 video thread output method
1400 *****************************************************************************
1401 * Destroy the X11 XImages created by Init. It is called at the end of
1402 * the thread, but also each time the window is resized.
1403 *****************************************************************************/
1404 static void EndVideo( vout_thread_t *p_vout )
1408 /* Free the direct buffers we allocated */
1409 for( i_index = I_OUTPUTPICTURES ; i_index ; )
1412 FreePicture( p_vout, PP_OUTPUTPICTURE[ i_index ] );
1416 /* following functions are local */
1418 /*****************************************************************************
1419 * CreateWindow: open and set-up X11 main window
1420 *****************************************************************************/
1421 static int CreateWindow( vout_thread_t *p_vout, x11_window_t *p_win )
1423 XSizeHints xsize_hints;
1424 XSetWindowAttributes xwindow_attributes;
1425 XGCValues xgcvalues;
1428 vlc_bool_t b_expose = VLC_FALSE;
1429 vlc_bool_t b_configure_notify = VLC_FALSE;
1430 vlc_bool_t b_map_notify = VLC_FALSE;
1433 /* Prepare window manager hints and properties */
1434 p_win->wm_protocols =
1435 XInternAtom( p_vout->p_sys->p_display, "WM_PROTOCOLS", True );
1436 p_win->wm_delete_window =
1437 XInternAtom( p_vout->p_sys->p_display, "WM_DELETE_WINDOW", True );
1439 /* Never have a 0-pixel-wide window */
1440 xsize_hints.min_width = 2;
1441 xsize_hints.min_height = 1;
1443 /* Prepare window attributes */
1444 xwindow_attributes.backing_store = Always; /* save the hidden part */
1445 xwindow_attributes.background_pixel = BlackPixel(p_vout->p_sys->p_display,
1446 p_vout->p_sys->i_screen);
1447 xwindow_attributes.event_mask = ExposureMask | StructureNotifyMask;
1449 if( !p_vout->b_fullscreen )
1451 p_win->owner_window =
1452 (Window)vout_RequestWindow( p_vout, &p_win->i_x, &p_win->i_y,
1453 &p_win->i_width, &p_win->i_height );
1455 xsize_hints.base_width = xsize_hints.width = p_win->i_width;
1456 xsize_hints.base_height = xsize_hints.height = p_win->i_height;
1457 xsize_hints.flags = PSize | PMinSize;
1459 if( p_win->i_x >=0 || p_win->i_y >= 0 )
1461 xsize_hints.x = p_win->i_x;
1462 xsize_hints.y = p_win->i_y;
1463 xsize_hints.flags |= PPosition;
1468 /* Fullscreen window size and position */
1469 p_win->owner_window = 0;
1470 p_win->i_x = p_win->i_y = 0;
1472 DisplayWidth( p_vout->p_sys->p_display, p_vout->p_sys->i_screen );
1474 DisplayHeight( p_vout->p_sys->p_display, p_vout->p_sys->i_screen );
1477 if( !p_win->owner_window )
1479 /* Create the window and set hints - the window must receive
1480 * ConfigureNotify events, and until it is displayed, Expose and
1481 * MapNotify events. */
1483 p_win->base_window =
1484 XCreateWindow( p_vout->p_sys->p_display,
1485 DefaultRootWindow( p_vout->p_sys->p_display ),
1486 p_win->i_x, p_win->i_y,
1487 p_win->i_width, p_win->i_height,
1490 CWBackingStore | CWBackPixel | CWEventMask,
1491 &xwindow_attributes );
1493 if( !p_vout->b_fullscreen )
1495 /* Set window manager hints and properties: size hints, command,
1496 * window's name, and accepted protocols */
1497 XSetWMNormalHints( p_vout->p_sys->p_display,
1498 p_win->base_window, &xsize_hints );
1499 XSetCommand( p_vout->p_sys->p_display, p_win->base_window,
1500 p_vout->p_libvlc->ppsz_argv, p_vout->p_libvlc->i_argc );
1502 if( !var_GetBool( p_vout, "video-deco") )
1505 mwmhints_t mwmhints;
1507 mwmhints.flags = MWM_HINTS_DECORATIONS;
1508 mwmhints.decorations = False;
1510 prop = XInternAtom( p_vout->p_sys->p_display, "_MOTIF_WM_HINTS",
1513 XChangeProperty( p_vout->p_sys->p_display,
1515 prop, prop, 32, PropModeReplace,
1516 (unsigned char *)&mwmhints,
1517 PROP_MWM_HINTS_ELEMENTS );
1521 var_Get( p_vout, "video-title", &val );
1522 if( !val.psz_string || !*val.psz_string )
1524 XStoreName( p_vout->p_sys->p_display, p_win->base_window,
1525 #ifdef MODULE_NAME_IS_x11
1526 VOUT_TITLE " (X11 output)"
1527 #elif defined(MODULE_NAME_IS_glx)
1528 VOUT_TITLE " (GLX output)"
1530 VOUT_TITLE " (XVideo output)"
1536 XStoreName( p_vout->p_sys->p_display,
1537 p_win->base_window, val.psz_string );
1539 if( val.psz_string ) free( val.psz_string );
1547 unsigned int dummy4, dummy5;
1549 /* Select events we are interested in. */
1550 XSelectInput( p_vout->p_sys->p_display, p_win->owner_window,
1551 StructureNotifyMask );
1553 /* Get the parent window's geometry information */
1554 XGetGeometry( p_vout->p_sys->p_display, p_win->owner_window,
1555 &dummy1, &dummy2, &dummy3,
1560 /* We are already configured */
1561 b_configure_notify = VLC_TRUE;
1563 /* From man XSelectInput: only one client at a time can select a
1564 * ButtonPress event, so we need to open a new window anyway. */
1565 p_win->base_window =
1566 XCreateWindow( p_vout->p_sys->p_display,
1567 p_win->owner_window,
1569 p_win->i_width, p_win->i_height,
1571 0, CopyFromParent, 0,
1572 CWBackingStore | CWBackPixel | CWEventMask,
1573 &xwindow_attributes );
1576 if( (p_win->wm_protocols == None) /* use WM_DELETE_WINDOW */
1577 || (p_win->wm_delete_window == None)
1578 || !XSetWMProtocols( p_vout->p_sys->p_display, p_win->base_window,
1579 &p_win->wm_delete_window, 1 ) )
1581 /* WM_DELETE_WINDOW is not supported by window manager */
1582 msg_Warn( p_vout, "missing or bad window manager" );
1585 /* Creation of a graphic context that doesn't generate a GraphicsExpose
1586 * event when using functions like XCopyArea */
1587 xgcvalues.graphics_exposures = False;
1588 p_win->gc = XCreateGC( p_vout->p_sys->p_display,
1590 GCGraphicsExposures, &xgcvalues );
1592 /* Send orders to server, and wait until window is displayed - three
1593 * events must be received: a MapNotify event, an Expose event allowing
1594 * drawing in the window, and a ConfigureNotify to get the window
1595 * dimensions. Once those events have been received, only
1596 * ConfigureNotify events need to be received. */
1597 XMapWindow( p_vout->p_sys->p_display, p_win->base_window );
1600 XWindowEvent( p_vout->p_sys->p_display, p_win->base_window,
1601 SubstructureNotifyMask | StructureNotifyMask |
1602 ExposureMask, &xevent);
1603 if( (xevent.type == Expose)
1604 && (xevent.xexpose.window == p_win->base_window) )
1606 b_expose = VLC_TRUE;
1607 /* ConfigureNotify isn't sent if there isn't a window manager.
1608 * Expose should be the last event to be received so it should
1609 * be fine to assume we won't receive it anymore. */
1610 b_configure_notify = VLC_TRUE;
1612 else if( (xevent.type == MapNotify)
1613 && (xevent.xmap.window == p_win->base_window) )
1615 b_map_notify = VLC_TRUE;
1617 else if( (xevent.type == ConfigureNotify)
1618 && (xevent.xconfigure.window == p_win->base_window) )
1620 b_configure_notify = VLC_TRUE;
1621 p_win->i_width = xevent.xconfigure.width;
1622 p_win->i_height = xevent.xconfigure.height;
1624 } while( !( b_expose && b_configure_notify && b_map_notify ) );
1626 XSelectInput( p_vout->p_sys->p_display, p_win->base_window,
1627 StructureNotifyMask | KeyPressMask |
1628 ButtonPressMask | ButtonReleaseMask |
1629 PointerMotionMask );
1631 #ifdef MODULE_NAME_IS_x11
1632 if( XDefaultDepth(p_vout->p_sys->p_display, p_vout->p_sys->i_screen) == 8 )
1634 /* Allocate a new palette */
1635 p_vout->p_sys->colormap =
1636 XCreateColormap( p_vout->p_sys->p_display,
1637 DefaultRootWindow( p_vout->p_sys->p_display ),
1638 DefaultVisual( p_vout->p_sys->p_display,
1639 p_vout->p_sys->i_screen ),
1642 xwindow_attributes.colormap = p_vout->p_sys->colormap;
1643 XChangeWindowAttributes( p_vout->p_sys->p_display, p_win->base_window,
1644 CWColormap, &xwindow_attributes );
1648 /* Create video output sub-window. */
1649 p_win->video_window = XCreateSimpleWindow(
1650 p_vout->p_sys->p_display,
1651 p_win->base_window, 0, 0,
1652 p_win->i_width, p_win->i_height,
1654 BlackPixel( p_vout->p_sys->p_display,
1655 p_vout->p_sys->i_screen ),
1656 WhitePixel( p_vout->p_sys->p_display,
1657 p_vout->p_sys->i_screen ) );
1659 XSetWindowBackground( p_vout->p_sys->p_display, p_win->video_window,
1660 BlackPixel( p_vout->p_sys->p_display,
1661 p_vout->p_sys->i_screen ) );
1663 XMapWindow( p_vout->p_sys->p_display, p_win->video_window );
1664 XSelectInput( p_vout->p_sys->p_display, p_win->video_window,
1667 /* make sure the video window will be centered in the next ManageVideo() */
1668 p_vout->i_changes |= VOUT_SIZE_CHANGE;
1670 /* If the cursor was formerly blank than blank it again */
1671 if( !p_vout->p_sys->b_mouse_pointer_visible )
1673 ToggleCursor( p_vout );
1674 ToggleCursor( p_vout );
1677 /* Do NOT use XFlush here ! */
1678 XSync( p_vout->p_sys->p_display, False );
1680 /* At this stage, the window is open, displayed, and ready to
1682 p_vout->p_sys->p_win = p_win;
1687 /*****************************************************************************
1688 * DestroyWindow: destroy the window
1689 *****************************************************************************
1691 *****************************************************************************/
1692 static void DestroyWindow( vout_thread_t *p_vout, x11_window_t *p_win )
1694 /* Do NOT use XFlush here ! */
1695 XSync( p_vout->p_sys->p_display, False );
1697 if( p_win->video_window != None )
1698 XDestroyWindow( p_vout->p_sys->p_display, p_win->video_window );
1700 XFreeGC( p_vout->p_sys->p_display, p_win->gc );
1702 XUnmapWindow( p_vout->p_sys->p_display, p_win->base_window );
1703 XDestroyWindow( p_vout->p_sys->p_display, p_win->base_window );
1705 if( p_win->owner_window )
1706 vout_ReleaseWindow( p_vout, (void *)p_win->owner_window );
1709 /*****************************************************************************
1710 * NewPicture: allocate a picture
1711 *****************************************************************************
1712 * Returns 0 on success, -1 otherwise
1713 *****************************************************************************/
1714 static int NewPicture( vout_thread_t *p_vout, picture_t *p_pic )
1716 #ifndef MODULE_NAME_IS_glx
1718 #if defined(MODULE_NAME_IS_xvideo) || defined(MODULE_NAME_IS_xvmc)
1722 /* We know the chroma, allocate a buffer which will be used
1723 * directly by the decoder */
1724 p_pic->p_sys = malloc( sizeof( picture_sys_t ) );
1726 if( p_pic->p_sys == NULL )
1731 #ifdef MODULE_NAME_IS_xvmc
1732 p_pic->p_sys->p_vout = p_vout;
1733 p_pic->p_sys->xvmc_surf = NULL;
1734 p_pic->p_sys->xxmc_data.decoded = 0;
1735 p_pic->p_sys->xxmc_data.proc_xxmc_update_frame = xxmc_do_update_frame;
1736 p_pic->p_accel_data = &p_pic->p_sys->xxmc_data;
1737 p_pic->p_sys->nb_display = 0;
1740 /* Fill in picture_t fields */
1741 vout_InitPicture( VLC_OBJECT(p_vout), p_pic, p_vout->output.i_chroma,
1742 p_vout->output.i_width, p_vout->output.i_height,
1743 p_vout->output.i_aspect );
1745 #ifdef HAVE_SYS_SHM_H
1746 if( p_vout->p_sys->b_shm )
1748 /* Create image using XShm extension */
1749 p_pic->p_sys->p_image =
1750 CreateShmImage( p_vout, p_vout->p_sys->p_display,
1751 # if defined(MODULE_NAME_IS_xvideo) || defined(MODULE_NAME_IS_xvmc)
1752 p_vout->p_sys->i_xvport,
1753 VLC2X11_FOURCC(p_vout->output.i_chroma),
1755 p_vout->p_sys->p_visual,
1756 p_vout->p_sys->i_screen_depth,
1758 &p_pic->p_sys->shminfo,
1759 p_vout->output.i_width, p_vout->output.i_height );
1762 if( !p_vout->p_sys->b_shm || !p_pic->p_sys->p_image )
1763 #endif /* HAVE_SYS_SHM_H */
1765 /* Create image without XShm extension */
1766 p_pic->p_sys->p_image =
1767 CreateImage( p_vout, p_vout->p_sys->p_display,
1768 #if defined(MODULE_NAME_IS_xvideo) || defined(MODULE_NAME_IS_xvmc)
1769 p_vout->p_sys->i_xvport,
1770 VLC2X11_FOURCC(p_vout->output.i_chroma),
1771 p_pic->format.i_bits_per_pixel,
1773 p_vout->p_sys->p_visual,
1774 p_vout->p_sys->i_screen_depth,
1775 p_vout->p_sys->i_bytes_per_pixel,
1777 p_vout->output.i_width, p_vout->output.i_height );
1779 #ifdef HAVE_SYS_SHM_H
1780 if( p_pic->p_sys->p_image && p_vout->p_sys->b_shm )
1782 msg_Warn( p_vout, "couldn't create SHM image, disabling SHM" );
1783 p_vout->p_sys->b_shm = VLC_FALSE;
1785 #endif /* HAVE_SYS_SHM_H */
1788 if( p_pic->p_sys->p_image == NULL )
1790 free( p_pic->p_sys );
1794 switch( p_vout->output.i_chroma )
1796 #if defined(MODULE_NAME_IS_xvideo) || defined(MODULE_NAME_IS_xvmc)
1797 case VLC_FOURCC('I','4','2','0'):
1798 case VLC_FOURCC('Y','V','1','2'):
1799 case VLC_FOURCC('Y','2','1','1'):
1800 case VLC_FOURCC('Y','U','Y','2'):
1801 case VLC_FOURCC('U','Y','V','Y'):
1802 case VLC_FOURCC('R','V','1','5'):
1803 case VLC_FOURCC('R','V','1','6'):
1804 case VLC_FOURCC('R','V','2','4'): /* Fixme: pixel pitch == 4 ? */
1805 case VLC_FOURCC('R','V','3','2'):
1807 for( i_plane = 0; i_plane < p_pic->p_sys->p_image->num_planes;
1810 p_pic->p[i_plane].p_pixels = p_pic->p_sys->p_image->data
1811 + p_pic->p_sys->p_image->offsets[i_plane];
1812 p_pic->p[i_plane].i_pitch =
1813 p_pic->p_sys->p_image->pitches[i_plane];
1815 if( p_vout->output.i_chroma == VLC_FOURCC('Y','V','1','2') )
1817 /* U and V inverted compared to I420
1818 * Fixme: this should be handled by the vout core */
1819 p_pic->U_PIXELS = p_pic->p_sys->p_image->data
1820 + p_pic->p_sys->p_image->offsets[2];
1821 p_pic->V_PIXELS = p_pic->p_sys->p_image->data
1822 + p_pic->p_sys->p_image->offsets[1];
1827 case VLC_FOURCC('R','G','B','2'):
1828 case VLC_FOURCC('R','V','1','6'):
1829 case VLC_FOURCC('R','V','1','5'):
1830 case VLC_FOURCC('R','V','2','4'):
1831 case VLC_FOURCC('R','V','3','2'):
1833 p_pic->p->i_lines = p_pic->p_sys->p_image->height;
1834 p_pic->p->i_visible_lines = p_pic->p_sys->p_image->height;
1835 p_pic->p->p_pixels = p_pic->p_sys->p_image->data
1836 + p_pic->p_sys->p_image->xoffset;
1837 p_pic->p->i_pitch = p_pic->p_sys->p_image->bytes_per_line;
1839 /* p_pic->p->i_pixel_pitch = 4 for RV24 but this should be set
1840 * properly by vout_InitPicture() */
1841 p_pic->p->i_visible_pitch = p_pic->p->i_pixel_pitch
1842 * p_pic->p_sys->p_image->width;
1847 /* Unknown chroma, tell the guy to get lost */
1848 IMAGE_FREE( p_pic->p_sys->p_image );
1849 free( p_pic->p_sys );
1850 msg_Err( p_vout, "never heard of chroma 0x%.8x (%4.4s)",
1851 p_vout->output.i_chroma, (char*)&p_vout->output.i_chroma );
1852 p_pic->i_planes = 0;
1856 #endif /* !MODULE_NAME_IS_glx */
1861 /*****************************************************************************
1862 * FreePicture: destroy a picture allocated with NewPicture
1863 *****************************************************************************
1864 * Destroy XImage AND associated data. If using Shm, detach shared memory
1865 * segment from server and process, then free it. The XDestroyImage manpage
1866 * says that both the image structure _and_ the data pointed to by the
1867 * image structure are freed, so no need to free p_image->data.
1868 *****************************************************************************/
1869 static void FreePicture( vout_thread_t *p_vout, picture_t *p_pic )
1871 /* The order of operations is correct */
1872 #ifdef HAVE_SYS_SHM_H
1873 if( p_vout->p_sys->b_shm )
1875 XShmDetach( p_vout->p_sys->p_display, &p_pic->p_sys->shminfo );
1876 IMAGE_FREE( p_pic->p_sys->p_image );
1878 shmctl( p_pic->p_sys->shminfo.shmid, IPC_RMID, 0 );
1879 if( shmdt( p_pic->p_sys->shminfo.shmaddr ) )
1881 msg_Err( p_vout, "cannot detach shared memory (%s)",
1888 IMAGE_FREE( p_pic->p_sys->p_image );
1891 #ifdef MODULE_NAME_IS_xvmc
1892 if( p_pic->p_sys->xvmc_surf != NULL )
1894 xxmc_xvmc_free_surface(p_vout , p_pic->p_sys->xvmc_surf);
1895 p_pic->p_sys->xvmc_surf = NULL;
1899 /* Do NOT use XFlush here ! */
1900 XSync( p_vout->p_sys->p_display, False );
1902 free( p_pic->p_sys );
1905 /*****************************************************************************
1906 * ToggleFullScreen: Enable or disable full screen mode
1907 *****************************************************************************
1908 * This function will switch between fullscreen and window mode.
1909 *****************************************************************************/
1910 static void ToggleFullScreen ( vout_thread_t *p_vout )
1914 mwmhints_t mwmhints;
1915 XSetWindowAttributes attributes;
1917 #ifdef HAVE_XINERAMA
1921 p_vout->b_fullscreen = !p_vout->b_fullscreen;
1923 if( p_vout->b_fullscreen )
1925 msg_Dbg( p_vout, "entering fullscreen mode" );
1927 p_vout->p_sys->b_altfullscreen =
1928 config_GetInt( p_vout, MODULE_STRING "-altfullscreen" );
1930 XUnmapWindow( p_vout->p_sys->p_display,
1931 p_vout->p_sys->p_win->base_window );
1933 p_vout->p_sys->p_win = &p_vout->p_sys->fullscreen_window;
1935 CreateWindow( p_vout, p_vout->p_sys->p_win );
1936 XDestroyWindow( p_vout->p_sys->p_display,
1937 p_vout->p_sys->fullscreen_window.video_window );
1938 XReparentWindow( p_vout->p_sys->p_display,
1939 p_vout->p_sys->original_window.video_window,
1940 p_vout->p_sys->fullscreen_window.base_window, 0, 0 );
1941 p_vout->p_sys->fullscreen_window.video_window =
1942 p_vout->p_sys->original_window.video_window;
1944 /* To my knowledge there are two ways to create a borderless window.
1945 * There's the generic way which is to tell x to bypass the window
1946 * manager, but this creates problems with the focus of other
1948 * The other way is to use the motif property "_MOTIF_WM_HINTS" which
1949 * luckily seems to be supported by most window managers. */
1950 if( !p_vout->p_sys->b_altfullscreen )
1952 mwmhints.flags = MWM_HINTS_DECORATIONS;
1953 mwmhints.decorations = False;
1955 prop = XInternAtom( p_vout->p_sys->p_display, "_MOTIF_WM_HINTS",
1957 XChangeProperty( p_vout->p_sys->p_display,
1958 p_vout->p_sys->p_win->base_window,
1959 prop, prop, 32, PropModeReplace,
1960 (unsigned char *)&mwmhints,
1961 PROP_MWM_HINTS_ELEMENTS );
1965 /* brute force way to remove decorations */
1966 attributes.override_redirect = True;
1967 XChangeWindowAttributes( p_vout->p_sys->p_display,
1968 p_vout->p_sys->p_win->base_window,
1972 /* Make sure the change is effective */
1973 XReparentWindow( p_vout->p_sys->p_display,
1974 p_vout->p_sys->p_win->base_window,
1975 DefaultRootWindow( p_vout->p_sys->p_display ),
1979 if( p_vout->p_sys->b_net_wm_state_fullscreen )
1981 XClientMessageEvent event;
1983 memset( &event, 0, sizeof( XClientMessageEvent ) );
1985 event.type = ClientMessage;
1986 event.message_type = p_vout->p_sys->net_wm_state;
1987 event.display = p_vout->p_sys->p_display;
1988 event.window = p_vout->p_sys->p_win->base_window;
1990 event.data.l[ 0 ] = 1; /* set property */
1991 event.data.l[ 1 ] = p_vout->p_sys->net_wm_state_fullscreen;
1993 XSendEvent( p_vout->p_sys->p_display,
1994 DefaultRootWindow( p_vout->p_sys->p_display ),
1995 False, SubstructureRedirectMask,
1999 /* Make sure the change is effective */
2000 XReparentWindow( p_vout->p_sys->p_display,
2001 p_vout->p_sys->p_win->base_window,
2002 DefaultRootWindow( p_vout->p_sys->p_display ),
2005 #ifdef HAVE_XINERAMA
2006 if( XineramaQueryExtension( p_vout->p_sys->p_display, &i_d1, &i_d2 ) &&
2007 XineramaIsActive( p_vout->p_sys->p_display ) )
2009 XineramaScreenInfo *screens; /* infos for xinerama */
2012 msg_Dbg( p_vout, "using XFree Xinerama extension");
2014 #define SCREEN p_vout->p_sys->p_win->i_screen
2016 /* Get Information about Xinerama (num of screens) */
2017 screens = XineramaQueryScreens( p_vout->p_sys->p_display,
2020 SCREEN = config_GetInt( p_vout,
2021 MODULE_STRING "-xineramascreen" );
2023 /* just check that user has entered a good value */
2024 if( SCREEN >= i_num_screens || SCREEN < 0 )
2026 msg_Dbg( p_vout, "requested screen number invalid (%d/%d)", SCREEN, i_num_screens );
2030 /* Get the X/Y upper left corner coordinate of the above screen */
2031 p_vout->p_sys->p_win->i_x = screens[SCREEN].x_org;
2032 p_vout->p_sys->p_win->i_y = screens[SCREEN].y_org;
2034 /* Set the Height/width to the screen resolution */
2035 p_vout->p_sys->p_win->i_width = screens[SCREEN].width;
2036 p_vout->p_sys->p_win->i_height = screens[SCREEN].height;
2046 /* The window wasn't necessarily created at the requested size */
2047 p_vout->p_sys->p_win->i_x = p_vout->p_sys->p_win->i_y = 0;
2049 #ifdef HAVE_XF86VIDMODE
2050 XF86VidModeModeLine mode;
2053 if( XF86VidModeGetModeLine( p_vout->p_sys->p_display,
2054 p_vout->p_sys->i_screen, &i_dummy,
2057 p_vout->p_sys->p_win->i_width = mode.hdisplay;
2058 p_vout->p_sys->p_win->i_height = mode.vdisplay;
2060 /* move cursor to the middle of the window to prevent
2061 * unwanted display move if the display is smaller than the
2063 XWarpPointer( p_vout->p_sys->p_display, None,
2064 p_vout->p_sys->p_win->base_window, 0, 0, 0, 0,
2065 mode.hdisplay / 2 , mode.vdisplay / 2 );
2066 /* force desktop view to upper left corner */
2067 XF86VidModeSetViewPort( p_vout->p_sys->p_display,
2068 p_vout->p_sys->i_screen, 0, 0 );
2073 p_vout->p_sys->p_win->i_width =
2074 DisplayWidth( p_vout->p_sys->p_display,
2075 p_vout->p_sys->i_screen );
2076 p_vout->p_sys->p_win->i_height =
2077 DisplayHeight( p_vout->p_sys->p_display,
2078 p_vout->p_sys->i_screen );
2083 XMoveResizeWindow( p_vout->p_sys->p_display,
2084 p_vout->p_sys->p_win->base_window,
2085 p_vout->p_sys->p_win->i_x,
2086 p_vout->p_sys->p_win->i_y,
2087 p_vout->p_sys->p_win->i_width,
2088 p_vout->p_sys->p_win->i_height );
2092 msg_Dbg( p_vout, "leaving fullscreen mode" );
2094 XReparentWindow( p_vout->p_sys->p_display,
2095 p_vout->p_sys->original_window.video_window,
2096 p_vout->p_sys->original_window.base_window, 0, 0 );
2098 p_vout->p_sys->fullscreen_window.video_window = None;
2099 DestroyWindow( p_vout, &p_vout->p_sys->fullscreen_window );
2100 p_vout->p_sys->p_win = &p_vout->p_sys->original_window;
2102 XMapWindow( p_vout->p_sys->p_display,
2103 p_vout->p_sys->p_win->base_window );
2106 /* Unfortunately, using XSync() here is not enough to ensure the
2107 * window has already been mapped because the XMapWindow() request
2108 * has not necessarily been sent directly to our window (remember,
2109 * the call is first redirected to the window manager) */
2112 XWindowEvent( p_vout->p_sys->p_display,
2113 p_vout->p_sys->p_win->base_window,
2114 StructureNotifyMask, &xevent );
2115 } while( xevent.type != MapNotify );
2117 /* Be careful, this can generate a BadMatch error if the window is not
2118 * already mapped by the server (see above) */
2119 XSetInputFocus(p_vout->p_sys->p_display,
2120 p_vout->p_sys->p_win->base_window,
2124 /* signal that the size needs to be updated */
2125 p_vout->i_changes |= VOUT_SIZE_CHANGE;
2128 /*****************************************************************************
2129 * EnableXScreenSaver: enable screen saver
2130 *****************************************************************************
2131 * This function enables the screen saver on a display after it has been
2132 * disabled by XDisableScreenSaver.
2133 * FIXME: what happens if multiple vlc sessions are running at the same
2135 *****************************************************************************/
2136 static void EnableXScreenSaver( vout_thread_t *p_vout )
2138 #ifdef DPMSINFO_IN_DPMS_H
2142 if( p_vout->p_sys->i_ss_timeout )
2144 XSetScreenSaver( p_vout->p_sys->p_display, p_vout->p_sys->i_ss_timeout,
2145 p_vout->p_sys->i_ss_interval,
2146 p_vout->p_sys->i_ss_blanking,
2147 p_vout->p_sys->i_ss_exposure );
2150 /* Restore DPMS settings */
2151 #ifdef DPMSINFO_IN_DPMS_H
2152 if( DPMSQueryExtension( p_vout->p_sys->p_display, &dummy, &dummy ) )
2154 if( p_vout->p_sys->b_ss_dpms )
2156 DPMSEnable( p_vout->p_sys->p_display );
2162 /*****************************************************************************
2163 * DisableXScreenSaver: disable screen saver
2164 *****************************************************************************
2165 * See XEnableXScreenSaver
2166 *****************************************************************************/
2167 static void DisableXScreenSaver( vout_thread_t *p_vout )
2169 #ifdef DPMSINFO_IN_DPMS_H
2173 /* Save screen saver information */
2174 XGetScreenSaver( p_vout->p_sys->p_display, &p_vout->p_sys->i_ss_timeout,
2175 &p_vout->p_sys->i_ss_interval,
2176 &p_vout->p_sys->i_ss_blanking,
2177 &p_vout->p_sys->i_ss_exposure );
2179 /* Disable screen saver */
2180 if( p_vout->p_sys->i_ss_timeout )
2182 XSetScreenSaver( p_vout->p_sys->p_display, 0,
2183 p_vout->p_sys->i_ss_interval,
2184 p_vout->p_sys->i_ss_blanking,
2185 p_vout->p_sys->i_ss_exposure );
2189 #ifdef DPMSINFO_IN_DPMS_H
2190 if( DPMSQueryExtension( p_vout->p_sys->p_display, &dummy, &dummy ) )
2193 /* Save DPMS current state */
2194 DPMSInfo( p_vout->p_sys->p_display, &unused,
2195 &p_vout->p_sys->b_ss_dpms );
2196 DPMSDisable( p_vout->p_sys->p_display );
2201 /*****************************************************************************
2202 * CreateCursor: create a blank mouse pointer
2203 *****************************************************************************/
2204 static void CreateCursor( vout_thread_t *p_vout )
2206 XColor cursor_color;
2208 p_vout->p_sys->cursor_pixmap =
2209 XCreatePixmap( p_vout->p_sys->p_display,
2210 DefaultRootWindow( p_vout->p_sys->p_display ),
2213 XParseColor( p_vout->p_sys->p_display,
2214 XCreateColormap( p_vout->p_sys->p_display,
2216 p_vout->p_sys->p_display ),
2218 p_vout->p_sys->p_display,
2219 p_vout->p_sys->i_screen ),
2221 "black", &cursor_color );
2223 p_vout->p_sys->blank_cursor =
2224 XCreatePixmapCursor( p_vout->p_sys->p_display,
2225 p_vout->p_sys->cursor_pixmap,
2226 p_vout->p_sys->cursor_pixmap,
2227 &cursor_color, &cursor_color, 1, 1 );
2230 /*****************************************************************************
2231 * DestroyCursor: destroy the blank mouse pointer
2232 *****************************************************************************/
2233 static void DestroyCursor( vout_thread_t *p_vout )
2235 XFreePixmap( p_vout->p_sys->p_display, p_vout->p_sys->cursor_pixmap );
2238 /*****************************************************************************
2239 * ToggleCursor: hide or show the mouse pointer
2240 *****************************************************************************
2241 * This function hides the X pointer if it is visible by setting the pointer
2242 * sprite to a blank one. To show it again, we disable the sprite.
2243 *****************************************************************************/
2244 static void ToggleCursor( vout_thread_t *p_vout )
2246 if( p_vout->p_sys->b_mouse_pointer_visible )
2248 XDefineCursor( p_vout->p_sys->p_display,
2249 p_vout->p_sys->p_win->base_window,
2250 p_vout->p_sys->blank_cursor );
2251 p_vout->p_sys->b_mouse_pointer_visible = 0;
2255 XUndefineCursor( p_vout->p_sys->p_display,
2256 p_vout->p_sys->p_win->base_window );
2257 p_vout->p_sys->b_mouse_pointer_visible = 1;
2261 #if defined(MODULE_NAME_IS_xvideo) || defined(MODULE_NAME_IS_xvmc)
2262 /*****************************************************************************
2263 * XVideoGetPort: get YUV12 port
2264 *****************************************************************************/
2265 static int XVideoGetPort( vout_thread_t *p_vout,
2266 vlc_fourcc_t i_chroma, vlc_fourcc_t *pi_newchroma )
2268 XvAdaptorInfo *p_adaptor;
2270 unsigned int i_adaptor, i_num_adaptors;
2271 int i_requested_adaptor;
2272 int i_selected_port;
2274 switch( XvQueryExtension( p_vout->p_sys->p_display, &i, &i, &i, &i, &i ) )
2279 case XvBadExtension:
2280 msg_Warn( p_vout, "XvBadExtension" );
2284 msg_Warn( p_vout, "XvBadAlloc" );
2288 msg_Warn( p_vout, "XvQueryExtension failed" );
2292 switch( XvQueryAdaptors( p_vout->p_sys->p_display,
2293 DefaultRootWindow( p_vout->p_sys->p_display ),
2294 &i_num_adaptors, &p_adaptor ) )
2299 case XvBadExtension:
2300 msg_Warn( p_vout, "XvBadExtension for XvQueryAdaptors" );
2304 msg_Warn( p_vout, "XvBadAlloc for XvQueryAdaptors" );
2308 msg_Warn( p_vout, "XvQueryAdaptors failed" );
2312 i_selected_port = -1;
2313 #ifdef MODULE_NAME_IS_xvmc
2314 i_requested_adaptor = config_GetInt( p_vout, "xvmc-adaptor" );
2316 i_requested_adaptor = config_GetInt( p_vout, "xvideo-adaptor" );
2318 for( i_adaptor = 0; i_adaptor < i_num_adaptors; ++i_adaptor )
2320 XvImageFormatValues *p_formats;
2321 int i_format, i_num_formats;
2324 /* If we requested an adaptor and it's not this one, we aren't
2326 if( i_requested_adaptor != -1 && ((int)i_adaptor != i_requested_adaptor) )
2331 /* If the adaptor doesn't have the required properties, skip it */
2332 if( !( p_adaptor[ i_adaptor ].type & XvInputMask ) ||
2333 !( p_adaptor[ i_adaptor ].type & XvImageMask ) )
2338 /* Check that adaptor supports our requested format... */
2339 p_formats = XvListImageFormats( p_vout->p_sys->p_display,
2340 p_adaptor[i_adaptor].base_id,
2344 i_format < i_num_formats && ( i_selected_port == -1 );
2347 XvAttribute *p_attr;
2348 int i_attr, i_num_attributes;
2350 /* If this is not the format we want, or at least a
2351 * similar one, forget it */
2352 if( !vout_ChromaCmp( p_formats[ i_format ].id, i_chroma ) )
2357 /* Look for the first available port supporting this format */
2358 for( i_port = p_adaptor[i_adaptor].base_id;
2359 ( i_port < (int)(p_adaptor[i_adaptor].base_id
2360 + p_adaptor[i_adaptor].num_ports) )
2361 && ( i_selected_port == -1 );
2364 if( XvGrabPort( p_vout->p_sys->p_display, i_port, CurrentTime )
2367 i_selected_port = i_port;
2368 *pi_newchroma = p_formats[ i_format ].id;
2372 /* If no free port was found, forget it */
2373 if( i_selected_port == -1 )
2378 /* If we found a port, print information about it */
2379 msg_Dbg( p_vout, "adaptor %i, port %i, format 0x%x (%4.4s) %s",
2380 i_adaptor, i_selected_port, p_formats[ i_format ].id,
2381 (char *)&p_formats[ i_format ].id,
2382 ( p_formats[ i_format ].format == XvPacked ) ?
2383 "packed" : "planar" );
2385 /* Make sure XV_AUTOPAINT_COLORKEY is set */
2386 p_attr = XvQueryPortAttributes( p_vout->p_sys->p_display,
2388 &i_num_attributes );
2390 for( i_attr = 0; i_attr < i_num_attributes; i_attr++ )
2392 if( !strcmp( p_attr[i_attr].name, "XV_AUTOPAINT_COLORKEY" ) )
2394 const Atom autopaint =
2395 XInternAtom( p_vout->p_sys->p_display,
2396 "XV_AUTOPAINT_COLORKEY", False );
2397 XvSetPortAttribute( p_vout->p_sys->p_display,
2398 i_selected_port, autopaint, 1 );
2403 if( p_attr != NULL )
2409 if( p_formats != NULL )
2416 if( i_num_adaptors > 0 )
2418 XvFreeAdaptorInfo( p_adaptor );
2421 if( i_selected_port == -1 )
2423 int i_chroma_tmp = X112VLC_FOURCC( i_chroma );
2424 if( i_requested_adaptor == -1 )
2426 msg_Warn( p_vout, "no free XVideo port found for format "
2427 "0x%.8x (%4.4s)", i_chroma_tmp, (char*)&i_chroma_tmp );
2431 msg_Warn( p_vout, "XVideo adaptor %i does not have a free "
2432 "XVideo port for format 0x%.8x (%4.4s)",
2433 i_requested_adaptor, i_chroma_tmp, (char*)&i_chroma_tmp );
2437 return i_selected_port;
2440 /*****************************************************************************
2441 * XVideoReleasePort: release YUV12 port
2442 *****************************************************************************/
2443 static void XVideoReleasePort( vout_thread_t *p_vout, int i_port )
2445 XvUngrabPort( p_vout->p_sys->p_display, i_port, CurrentTime );
2449 /*****************************************************************************
2450 * InitDisplay: open and initialize X11 device
2451 *****************************************************************************
2452 * Create a window according to video output given size, and set other
2453 * properties according to the display properties.
2454 *****************************************************************************/
2455 static int InitDisplay( vout_thread_t *p_vout )
2457 #ifdef MODULE_NAME_IS_x11
2458 XPixmapFormatValues * p_formats; /* pixmap formats */
2459 XVisualInfo * p_xvisual; /* visuals information */
2460 XVisualInfo xvisual_template; /* visual template */
2461 int i_count, i; /* array size */
2464 #ifdef HAVE_SYS_SHM_H
2465 p_vout->p_sys->b_shm = 0;
2467 if( config_GetInt( p_vout, MODULE_STRING "-shm" ) )
2470 /* FIXME: As of 2001-03-16, XFree4 for MacOS X does not support Xshm */
2472 p_vout->p_sys->b_shm =
2473 ( XShmQueryExtension( p_vout->p_sys->p_display ) == True );
2476 if( !p_vout->p_sys->b_shm )
2478 msg_Warn( p_vout, "XShm video extension is unavailable" );
2483 msg_Dbg( p_vout, "disabling XShm video extension" );
2487 msg_Warn( p_vout, "XShm video extension is unavailable" );
2491 #ifdef MODULE_NAME_IS_xvideo
2492 /* XXX The brightness and contrast values should be read from environment
2493 * XXX variables... */
2495 XVideoSetAttribute( p_vout, "XV_BRIGHTNESS", 0.5 );
2496 XVideoSetAttribute( p_vout, "XV_CONTRAST", 0.5 );
2500 #ifdef MODULE_NAME_IS_x11
2501 /* Initialize structure */
2502 p_vout->p_sys->i_screen = DefaultScreen( p_vout->p_sys->p_display );
2504 /* Get screen depth */
2505 p_vout->p_sys->i_screen_depth = XDefaultDepth( p_vout->p_sys->p_display,
2506 p_vout->p_sys->i_screen );
2507 switch( p_vout->p_sys->i_screen_depth )
2511 * Screen depth is 8bpp. Use PseudoColor visual with private colormap.
2513 xvisual_template.screen = p_vout->p_sys->i_screen;
2514 xvisual_template.class = DirectColor;
2515 p_xvisual = XGetVisualInfo( p_vout->p_sys->p_display,
2516 VisualScreenMask | VisualClassMask,
2517 &xvisual_template, &i_count );
2518 if( p_xvisual == NULL )
2520 msg_Err( p_vout, "no PseudoColor visual available" );
2521 return VLC_EGENERIC;
2523 p_vout->p_sys->i_bytes_per_pixel = 1;
2524 p_vout->output.pf_setpalette = SetPalette;
2531 * Screen depth is higher than 8bpp. TrueColor visual is used.
2533 xvisual_template.screen = p_vout->p_sys->i_screen;
2534 xvisual_template.class = TrueColor;
2535 /* In some cases, we get a truecolor class adaptor that has a different
2536 color depth. So try to get a real true color one first */
2537 xvisual_template.depth = p_vout->p_sys->i_screen_depth;
2539 p_xvisual = XGetVisualInfo( p_vout->p_sys->p_display,
2540 VisualScreenMask | VisualClassMask |
2542 &xvisual_template, &i_count );
2543 if( p_xvisual == NULL )
2545 msg_Warn( p_vout, "No screen matching the required color depth" );
2546 p_xvisual = XGetVisualInfo( p_vout->p_sys->p_display,
2547 VisualScreenMask | VisualClassMask,
2548 &xvisual_template, &i_count );
2549 if( p_xvisual == NULL )
2552 msg_Err( p_vout, "no TrueColor visual available" );
2553 return VLC_EGENERIC;
2557 p_vout->output.i_rmask = p_xvisual->red_mask;
2558 p_vout->output.i_gmask = p_xvisual->green_mask;
2559 p_vout->output.i_bmask = p_xvisual->blue_mask;
2561 /* There is no difference yet between 3 and 4 Bpp. The only way
2562 * to find the actual number of bytes per pixel is to list supported
2563 * pixmap formats. */
2564 p_formats = XListPixmapFormats( p_vout->p_sys->p_display, &i_count );
2565 p_vout->p_sys->i_bytes_per_pixel = 0;
2567 for( i = 0; i < i_count; i++ )
2569 /* Under XFree4.0, the list contains pixmap formats available
2570 * through all video depths ; so we have to check against current
2572 if( p_formats[i].depth == (int)p_vout->p_sys->i_screen_depth )
2574 if( p_formats[i].bits_per_pixel / 8
2575 > (int)p_vout->p_sys->i_bytes_per_pixel )
2577 p_vout->p_sys->i_bytes_per_pixel =
2578 p_formats[i].bits_per_pixel / 8;
2582 if( p_formats ) XFree( p_formats );
2586 p_vout->p_sys->p_visual = p_xvisual->visual;
2593 #ifdef HAVE_SYS_SHM_H
2594 /*****************************************************************************
2595 * CreateShmImage: create an XImage or XvImage using shared memory extension
2596 *****************************************************************************
2597 * Prepare an XImage or XvImage for display function.
2598 * The order of the operations respects the recommandations of the mit-shm
2599 * document by J.Corbet and K.Packard. Most of the parameters were copied from
2600 * there. See http://ftp.xfree86.org/pub/XFree86/4.0/doc/mit-shm.TXT
2601 *****************************************************************************/
2602 static IMAGE_TYPE * CreateShmImage( vout_thread_t *p_vout,
2603 Display* p_display, EXTRA_ARGS_SHM,
2604 int i_width, int i_height )
2606 IMAGE_TYPE *p_image;
2609 /* Create XImage / XvImage */
2610 #ifdef MODULE_NAME_IS_xvideo
2612 /* Make sure the buffer is aligned to multiple of 16 */
2613 i_height = ( i_height + 15 ) >> 4 << 4;
2614 i_width = ( i_width + 15 ) >> 4 << 4;
2616 p_image = XvShmCreateImage( p_display, i_xvport, i_chroma, 0,
2617 i_width, i_height, p_shm );
2618 #elif defined(MODULE_NAME_IS_xvmc)
2619 p_image = XvShmCreateImage( p_display, i_xvport, i_chroma, 0,
2620 i_width, i_height, p_shm );
2622 p_image = XShmCreateImage( p_display, p_visual, i_depth, ZPixmap, 0,
2623 p_shm, i_width, i_height );
2625 if( p_image == NULL )
2627 msg_Err( p_vout, "image creation failed" );
2631 /* Allocate shared memory segment - 0776 set the access permission
2632 * rights (like umask), they are not yet supported by all X servers */
2633 p_shm->shmid = shmget( IPC_PRIVATE, DATA_SIZE(p_image), IPC_CREAT | 0776 );
2634 if( p_shm->shmid < 0 )
2636 msg_Err( p_vout, "cannot allocate shared image data (%s)",
2637 strerror( errno ) );
2638 IMAGE_FREE( p_image );
2642 /* Attach shared memory segment to process (read/write) */
2643 p_shm->shmaddr = p_image->data = shmat( p_shm->shmid, 0, 0 );
2644 if(! p_shm->shmaddr )
2646 msg_Err( p_vout, "cannot attach shared memory (%s)",
2648 IMAGE_FREE( p_image );
2649 shmctl( p_shm->shmid, IPC_RMID, 0 );
2653 /* Read-only data. We won't be using XShmGetImage */
2654 p_shm->readOnly = True;
2656 /* Attach shared memory segment to X server */
2657 XSynchronize( p_display, True );
2659 result = XShmAttach( p_display, p_shm );
2660 if( result == False || !b_shm )
2662 msg_Err( p_vout, "cannot attach shared memory to X server" );
2663 IMAGE_FREE( p_image );
2664 shmctl( p_shm->shmid, IPC_RMID, 0 );
2665 shmdt( p_shm->shmaddr );
2668 XSynchronize( p_display, False );
2670 /* Send image to X server. This instruction is required, since having
2671 * built a Shm XImage and not using it causes an error on XCloseDisplay,
2672 * and remember NOT to use XFlush ! */
2673 XSync( p_display, False );
2676 /* Mark the shm segment to be removed when there are no more
2677 * attachements, so it is automatic on process exit or after shmdt */
2678 shmctl( p_shm->shmid, IPC_RMID, 0 );
2685 /*****************************************************************************
2686 * CreateImage: create an XImage or XvImage
2687 *****************************************************************************
2688 * Create a simple image used as a buffer.
2689 *****************************************************************************/
2690 static IMAGE_TYPE * CreateImage( vout_thread_t *p_vout,
2691 Display *p_display, EXTRA_ARGS,
2692 int i_width, int i_height )
2694 byte_t * p_data; /* image data storage zone */
2695 IMAGE_TYPE *p_image;
2696 #ifdef MODULE_NAME_IS_x11
2697 int i_quantum; /* XImage quantum (see below) */
2698 int i_bytes_per_line;
2701 /* Allocate memory for image */
2702 #ifdef MODULE_NAME_IS_xvideo
2704 /* Make sure the buffer is aligned to multiple of 16 */
2705 i_height = ( i_height + 15 ) >> 4 << 4;
2706 i_width = ( i_width + 15 ) >> 4 << 4;
2708 p_data = (byte_t *) malloc( i_width * i_height * i_bits_per_pixel / 8 );
2709 #elif defined(MODULE_NAME_IS_x11)
2710 i_bytes_per_line = i_width * i_bytes_per_pixel;
2711 p_data = (byte_t *) malloc( i_bytes_per_line * i_height );
2715 msg_Err( p_vout, "out of memory" );
2719 #ifdef MODULE_NAME_IS_x11
2720 /* Optimize the quantum of a scanline regarding its size - the quantum is
2721 a diviser of the number of bits between the start of two scanlines. */
2722 if( i_bytes_per_line & 0xf )
2726 else if( i_bytes_per_line & 0x10 )
2736 /* Create XImage. p_data will be automatically freed */
2737 #ifdef MODULE_NAME_IS_xvideo
2738 p_image = XvCreateImage( p_display, i_xvport, i_chroma,
2739 (char *)p_data, i_width, i_height );
2740 #elif defined(MODULE_NAME_IS_x11)
2741 p_image = XCreateImage( p_display, p_visual, i_depth, ZPixmap, 0,
2742 (char *)p_data, i_width, i_height, i_quantum, 0 );
2744 if( p_image == NULL )
2746 msg_Err( p_vout, "XCreateImage() failed" );
2754 /*****************************************************************************
2755 * X11ErrorHandler: replace error handler so we can intercept some of them
2756 *****************************************************************************/
2757 static int X11ErrorHandler( Display * display, XErrorEvent * event )
2759 /* Ingnore errors on XSetInputFocus()
2760 * (they happen when a window is not yet mapped) */
2761 if( event->request_code == X_SetInputFocus )
2763 fprintf(stderr, "XSetInputFocus failed\n");
2767 if( event->request_code == 150 /* MIT-SHM */ &&
2768 event->minor_code == X_ShmAttach )
2770 fprintf(stderr, "XShmAttach failed\n");
2775 XSetErrorHandler(NULL);
2776 return (XSetErrorHandler(X11ErrorHandler))( display, event );
2779 #ifdef MODULE_NAME_IS_x11
2780 /*****************************************************************************
2781 * SetPalette: sets an 8 bpp palette
2782 *****************************************************************************
2783 * This function sets the palette given as an argument. It does not return
2784 * anything, but could later send information on which colors it was unable
2786 *****************************************************************************/
2787 static void SetPalette( vout_thread_t *p_vout,
2788 uint16_t *red, uint16_t *green, uint16_t *blue )
2791 XColor p_colors[255];
2793 /* allocate palette */
2794 for( i = 0; i < 255; i++ )
2796 /* kludge: colors are indexed reversely because color 255 seems
2797 * to be reserved for black even if we try to set it to white */
2798 p_colors[ i ].pixel = 255 - i;
2799 p_colors[ i ].pad = 0;
2800 p_colors[ i ].flags = DoRed | DoGreen | DoBlue;
2801 p_colors[ i ].red = red[ 255 - i ];
2802 p_colors[ i ].blue = blue[ 255 - i ];
2803 p_colors[ i ].green = green[ 255 - i ];
2806 XStoreColors( p_vout->p_sys->p_display,
2807 p_vout->p_sys->colormap, p_colors, 255 );
2811 /*****************************************************************************
2812 * Control: control facility for the vout
2813 *****************************************************************************/
2814 static int Control( vout_thread_t *p_vout, int i_query, va_list args )
2817 unsigned int i_width, i_height;
2818 unsigned int *pi_width, *pi_height;
2824 if( p_vout->p_sys->p_win->owner_window )
2825 return vout_ControlWindow( p_vout,
2826 (void *)p_vout->p_sys->p_win->owner_window, i_query, args);
2828 pi_width = va_arg( args, unsigned int * );
2829 pi_height = va_arg( args, unsigned int * );
2831 vlc_mutex_lock( &p_vout->p_sys->lock );
2832 *pi_width = p_vout->p_sys->p_win->i_width;
2833 *pi_height = p_vout->p_sys->p_win->i_height;
2834 vlc_mutex_unlock( &p_vout->p_sys->lock );
2838 if( p_vout->p_sys->p_win->owner_window )
2839 return vout_ControlWindow( p_vout,
2840 (void *)p_vout->p_sys->p_win->owner_window, i_query, args);
2842 vlc_mutex_lock( &p_vout->p_sys->lock );
2844 i_width = va_arg( args, unsigned int );
2845 i_height = va_arg( args, unsigned int );
2846 if( !i_width ) i_width = p_vout->i_window_width;
2847 if( !i_height ) i_height = p_vout->i_window_height;
2849 #ifdef MODULE_NAME_IS_xvmc
2850 xvmc_context_reader_lock( &p_vout->p_sys->xvmc_lock );
2852 /* Update dimensions */
2853 XResizeWindow( p_vout->p_sys->p_display,
2854 p_vout->p_sys->p_win->base_window,
2855 i_width, i_height );
2856 #ifdef MODULE_NAME_IS_xvmc
2857 xvmc_context_reader_unlock( &p_vout->p_sys->xvmc_lock );
2859 vlc_mutex_unlock( &p_vout->p_sys->lock );
2863 vlc_mutex_lock( &p_vout->p_sys->lock );
2864 XUnmapWindow( p_vout->p_sys->p_display,
2865 p_vout->p_sys->original_window.base_window );
2866 vlc_mutex_unlock( &p_vout->p_sys->lock );
2870 vlc_mutex_lock( &p_vout->p_sys->lock );
2871 if( i_query == VOUT_REPARENT ) d = (Drawable)va_arg( args, int );
2873 #ifdef MODULE_NAME_IS_xvmc
2874 xvmc_context_reader_lock( &p_vout->p_sys->xvmc_lock );
2876 XReparentWindow( p_vout->p_sys->p_display,
2877 p_vout->p_sys->original_window.base_window,
2878 DefaultRootWindow( p_vout->p_sys->p_display ),
2881 XReparentWindow( p_vout->p_sys->p_display,
2882 p_vout->p_sys->original_window.base_window,
2884 XSync( p_vout->p_sys->p_display, False );
2885 p_vout->p_sys->original_window.owner_window = 0;
2886 #ifdef MODULE_NAME_IS_xvmc
2887 xvmc_context_reader_unlock( &p_vout->p_sys->xvmc_lock );
2889 vlc_mutex_unlock( &p_vout->p_sys->lock );
2890 return vout_vaControlDefault( p_vout, i_query, args );
2892 case VOUT_SET_STAY_ON_TOP:
2893 if( p_vout->p_sys->p_win->owner_window )
2894 return vout_ControlWindow( p_vout,
2895 (void *)p_vout->p_sys->p_win->owner_window, i_query, args);
2897 b_arg = va_arg( args, vlc_bool_t );
2898 vlc_mutex_lock( &p_vout->p_sys->lock );
2899 #ifdef MODULE_NAME_IS_xvmc
2900 xvmc_context_reader_lock( &p_vout->p_sys->xvmc_lock );
2902 WindowOnTop( p_vout, b_arg );
2903 #ifdef MODULE_NAME_IS_xvmc
2904 xvmc_context_reader_unlock( &p_vout->p_sys->xvmc_lock );
2906 vlc_mutex_unlock( &p_vout->p_sys->lock );
2910 return vout_vaControlDefault( p_vout, i_query, args );
2914 /*****************************************************************************
2915 * TestNetWMSupport: tests for Extended Window Manager Hints support
2916 *****************************************************************************/
2917 static void TestNetWMSupport( vout_thread_t *p_vout )
2919 int i_ret, i_format;
2920 unsigned long i, i_items, i_bytesafter;
2921 Atom net_wm_supported;
2922 union { Atom *p_atom; unsigned char *p_char; } p_args;
2924 p_args.p_atom = NULL;
2926 p_vout->p_sys->b_net_wm_state_fullscreen = VLC_FALSE;
2927 p_vout->p_sys->b_net_wm_state_above = VLC_FALSE;
2928 p_vout->p_sys->b_net_wm_state_below = VLC_FALSE;
2929 p_vout->p_sys->b_net_wm_state_stays_on_top = VLC_FALSE;
2932 XInternAtom( p_vout->p_sys->p_display, "_NET_SUPPORTED", False );
2934 i_ret = XGetWindowProperty( p_vout->p_sys->p_display,
2935 DefaultRootWindow( p_vout->p_sys->p_display ),
2937 0, 16384, False, AnyPropertyType,
2939 &i_format, &i_items, &i_bytesafter,
2940 (unsigned char **)&p_args );
2942 if( i_ret != Success || i_items == 0 ) return;
2944 msg_Dbg( p_vout, "Window manager supports NetWM" );
2946 p_vout->p_sys->net_wm_state =
2947 XInternAtom( p_vout->p_sys->p_display, "_NET_WM_STATE", False );
2948 p_vout->p_sys->net_wm_state_fullscreen =
2949 XInternAtom( p_vout->p_sys->p_display, "_NET_WM_STATE_FULLSCREEN",
2951 p_vout->p_sys->net_wm_state_above =
2952 XInternAtom( p_vout->p_sys->p_display, "_NET_WM_STATE_ABOVE", False );
2953 p_vout->p_sys->net_wm_state_below =
2954 XInternAtom( p_vout->p_sys->p_display, "_NET_WM_STATE_BELOW", False );
2955 p_vout->p_sys->net_wm_state_stays_on_top =
2956 XInternAtom( p_vout->p_sys->p_display, "_NET_WM_STATE_STAYS_ON_TOP",
2959 for( i = 0; i < i_items; i++ )
2961 if( p_args.p_atom[i] == p_vout->p_sys->net_wm_state_fullscreen )
2964 "Window manager supports _NET_WM_STATE_FULLSCREEN" );
2965 p_vout->p_sys->b_net_wm_state_fullscreen = VLC_TRUE;
2967 else if( p_args.p_atom[i] == p_vout->p_sys->net_wm_state_above )
2969 msg_Dbg( p_vout, "Window manager supports _NET_WM_STATE_ABOVE" );
2970 p_vout->p_sys->b_net_wm_state_above = VLC_TRUE;
2972 else if( p_args.p_atom[i] == p_vout->p_sys->net_wm_state_below )
2974 msg_Dbg( p_vout, "Window manager supports _NET_WM_STATE_BELOW" );
2975 p_vout->p_sys->b_net_wm_state_below = VLC_TRUE;
2977 else if( p_args.p_atom[i] == p_vout->p_sys->net_wm_state_stays_on_top )
2980 "Window manager supports _NET_WM_STATE_STAYS_ON_TOP" );
2981 p_vout->p_sys->b_net_wm_state_stays_on_top = VLC_TRUE;
2985 XFree( p_args.p_atom );
2988 /*****************************************************************************
2989 * Key events handling
2990 *****************************************************************************/
2996 } x11keys_to_vlckeys[] =
2998 { XK_F1, KEY_F1 }, { XK_F2, KEY_F2 }, { XK_F3, KEY_F3 }, { XK_F4, KEY_F4 },
2999 { XK_F5, KEY_F5 }, { XK_F6, KEY_F6 }, { XK_F7, KEY_F7 }, { XK_F8, KEY_F8 },
3000 { XK_F9, KEY_F9 }, { XK_F10, KEY_F10 }, { XK_F11, KEY_F11 },
3001 { XK_F12, KEY_F12 },
3003 { XK_Return, KEY_ENTER },
3004 { XK_KP_Enter, KEY_ENTER },
3005 { XK_space, KEY_SPACE },
3006 { XK_Escape, KEY_ESC },
3008 { XK_Menu, KEY_MENU },
3009 { XK_Left, KEY_LEFT },
3010 { XK_Right, KEY_RIGHT },
3012 { XK_Down, KEY_DOWN },
3014 { XK_Home, KEY_HOME },
3015 { XK_End, KEY_END },
3016 { XK_Page_Up, KEY_PAGEUP },
3017 { XK_Page_Down, KEY_PAGEDOWN },
3019 { XK_Insert, KEY_INSERT },
3020 { XK_Delete, KEY_DELETE },
3025 static int ConvertKey( int i_key )
3029 for( i = 0; x11keys_to_vlckeys[i].i_x11key != 0; i++ )
3031 if( x11keys_to_vlckeys[i].i_x11key == i_key )
3033 return x11keys_to_vlckeys[i].i_vlckey;
3040 /*****************************************************************************
3041 * WindowOnTop: Switches the "always on top" state of the video window.
3042 *****************************************************************************/
3043 static int WindowOnTop( vout_thread_t *p_vout, vlc_bool_t b_on_top )
3045 if( p_vout->p_sys->b_net_wm_state_stays_on_top )
3047 XClientMessageEvent event;
3049 memset( &event, 0, sizeof( XClientMessageEvent ) );
3051 event.type = ClientMessage;
3052 event.message_type = p_vout->p_sys->net_wm_state;
3053 event.display = p_vout->p_sys->p_display;
3054 event.window = p_vout->p_sys->p_win->base_window;
3056 event.data.l[ 0 ] = b_on_top; /* set property */
3057 event.data.l[ 1 ] = p_vout->p_sys->net_wm_state_stays_on_top;
3059 XSendEvent( p_vout->p_sys->p_display,
3060 DefaultRootWindow( p_vout->p_sys->p_display ),
3061 False, SubstructureRedirectMask,
3065 /* use _NET_WM_STATE_ABOVE if window manager
3066 * doesn't handle _NET_WM_STATE_STAYS_ON_TOP */
3067 else if( p_vout->p_sys->b_net_wm_state_above )
3069 XClientMessageEvent event;
3071 memset( &event, 0, sizeof( XClientMessageEvent ) );
3073 event.type = ClientMessage;
3074 event.message_type = p_vout->p_sys->net_wm_state;
3075 event.display = p_vout->p_sys->p_display;
3076 event.window = p_vout->p_sys->p_win->base_window;
3078 event.data.l[ 0 ] = b_on_top; /* set property */
3079 event.data.l[ 1 ] = p_vout->p_sys->net_wm_state_above;
3081 XSendEvent( p_vout->p_sys->p_display,
3082 DefaultRootWindow( p_vout->p_sys->p_display ),
3083 False, SubstructureRedirectMask,