1 /*****************************************************************************
2 * x11.c: Screen capture module.
3 *****************************************************************************
4 * Copyright (C) 2004-2008 the VideoLAN team
7 * Authors: Gildas Bazin <gbazin@videolan.org>
8 * Antoine Cellerier <dionoea at videolan dot org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
25 /*****************************************************************************
27 *****************************************************************************/
33 #include <vlc_common.h>
36 #include <X11/Xutil.h>
40 int screen_InitCapture( demux_t *p_demux )
42 demux_sys_t *p_sys = p_demux->p_sys;
44 char *psz_display = var_CreateGetNonEmptyString( p_demux, "x11-display" );
45 XWindowAttributes win_info;
48 /* Open the display */
49 p_display = XOpenDisplay( psz_display );
53 msg_Err( p_demux, "cannot open display" );
56 p_sys->p_data = (void *)p_display;
58 /* Get the parameters of the root window */
59 if( !XGetWindowAttributes( p_display,
60 DefaultRootWindow( p_display ),
63 msg_Err( p_demux, "can't get root window attributes" );
64 XCloseDisplay( p_display );
68 switch( win_info.depth )
70 case 8: /* FIXME: set the palette */
71 i_chroma = VLC_FOURCC('R','G','B','2'); break;
73 i_chroma = VLC_FOURCC('R','V','1','5'); break;
75 i_chroma = VLC_FOURCC('R','V','1','6'); break;
78 i_chroma = VLC_FOURCC('R','V','3','2');
82 msg_Err( p_demux, "unknown screen depth %i", win_info.depth );
83 XCloseDisplay( p_display );
87 es_format_Init( &p_sys->fmt, VIDEO_ES, i_chroma );
88 p_sys->fmt.video.i_visible_width =
89 p_sys->fmt.video.i_width = win_info.width;
90 p_sys->fmt.video.i_visible_height =
91 p_sys->fmt.video.i_height = win_info.height;
92 p_sys->fmt.video.i_bits_per_pixel = win_info.depth;
93 p_sys->fmt.video.i_chroma = i_chroma;
96 win_info.visual->red_mask;
97 win_info.visual->green_mask;
98 win_info.visual->blue_mask;
99 win_info.visual->bits_per_rgb;
105 int screen_CloseCapture( demux_t *p_demux )
107 demux_sys_t *p_sys = p_demux->p_sys;
108 Display *p_display = (Display *)p_sys->p_data;
110 XCloseDisplay( p_display );
113 module_unneed( p_sys->p_blend, p_sys->p_blend->p_module );
114 vlc_object_detach( p_sys->p_blend );
115 vlc_object_release( p_sys->p_blend );
120 block_t *screen_Capture( demux_t *p_demux )
122 demux_sys_t *p_sys = p_demux->p_sys;
123 Display *p_display = (Display *)p_sys->p_data;
127 int root_x = 0, root_y = 0;
129 if( p_sys->b_follow_mouse || p_sys->p_mouse )
131 Window root = DefaultRootWindow( p_display ), child;
134 if( XQueryPointer( p_display, root,
135 &root, &child, &root_x, &root_y, &win_x, &win_y,
138 if( p_sys->b_follow_mouse )
139 FollowMouse( p_sys, root_x, root_y );
142 msg_Dbg( p_demux, "XQueryPointer() failed" );
146 image = XGetImage( p_display, DefaultRootWindow( p_display ),
147 p_sys->i_left, p_sys->i_top, p_sys->fmt.video.i_width,
148 p_sys->fmt.video.i_height, AllPlanes, ZPixmap );
152 msg_Warn( p_demux, "cannot get image" );
156 i_size = image->bytes_per_line * image->height;
158 if( !( p_block = block_New( p_demux, i_size ) ) )
160 msg_Warn( p_demux, "cannot get block" );
161 XDestroyImage( image );
165 vlc_memcpy( p_block->p_buffer, image->data, i_size );
168 RenderCursor( p_demux, root_x, root_y,
171 XDestroyImage( image );