]> git.sesse.net Git - vlc/blob - modules/video_output/x11/xcommon.h
Xlib: use mouse-events variable and fix event mask
[vlc] / modules / video_output / x11 / xcommon.h
1 /*****************************************************************************
2  * xcommon.h: Defines common to the X11 and XVideo plugins
3  *****************************************************************************
4  * Copyright (C) 1998-2001 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Vincent Seguin <seguin@via.ecp.fr>
8  *          Samuel Hocevar <sam@zoy.org>
9  *          David Kennedy <dkennedy@tinytoad.com>
10  *          Gildas Bazin <gbazin@netcourrier.com>
11  *
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.
16  *
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.
21  *
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  *****************************************************************************/
26
27 /*****************************************************************************
28  * Defines
29  *****************************************************************************/
30 #if defined(MODULE_NAME_IS_xvmc)
31 #   define IMAGE_TYPE     XvImage
32 #   define EXTRA_ARGS     int i_xvport, int i_chroma, int i_bits_per_pixel
33 #   define EXTRA_ARGS_SHM int i_xvport, int i_chroma, XShmSegmentInfo *p_shm
34 #   define DATA_SIZE(p)   (p)->data_size
35 #   define IMAGE_FREE     XFree      /* There is nothing like XvDestroyImage */
36 #else
37 #   define IMAGE_TYPE     XImage
38 #   define EXTRA_ARGS     Visual *p_visual, int i_depth, int i_bytes_per_pixel
39 #   define EXTRA_ARGS_SHM Visual *p_visual, int i_depth, XShmSegmentInfo *p_shm
40 #   define DATA_SIZE(p)   ((p)->bytes_per_line * (p)->height)
41 #   define IMAGE_FREE     XDestroyImage
42 #endif
43
44 #define X11_FOURCC( a, b, c, d ) \
45         ( ((uint32_t)a) | ( ((uint32_t)b) << 8 ) \
46            | ( ((uint32_t)c) << 16 ) | ( ((uint32_t)d) << 24 ) )
47 #define VLC2X11_FOURCC( i ) \
48         X11_FOURCC( ((char *)&i)[0], ((char *)&i)[1], ((char *)&i)[2], \
49                     ((char *)&i)[3] )
50 #define X112VLC_FOURCC( i ) \
51         VLC_FOURCC( i & 0xff, (i >> 8) & 0xff, (i >> 16) & 0xff, \
52                     (i >> 24) & 0xff )
53
54 struct vout_window_t;
55
56 /*****************************************************************************
57  * x11_window_t: X11 window descriptor
58  *****************************************************************************
59  * This structure contains all the data necessary to describe an X11 window.
60  *****************************************************************************/
61 typedef struct x11_window_t
62 {
63     struct vout_window_t*owner_window;               /* owner window (if any) */
64     Window              base_window;                          /* base window */
65     Window              video_window;     /* sub-window for displaying video */
66     GC                  gc;              /* graphic context instance handler */
67
68     unsigned int        i_width;                             /* window width */
69     unsigned int        i_height;                           /* window height */
70     int                 i_x;                          /* window x coordinate */
71     int                 i_y;                          /* window y coordinate */
72
73     Atom                wm_protocols;
74     Atom                wm_delete_window;
75 } x11_window_t;
76
77 /*****************************************************************************
78  * Xxmc defines
79  *****************************************************************************/
80
81 #ifdef MODULE_NAME_IS_xvmc
82
83 typedef struct
84 {         /* CLUT == Color LookUp Table */
85     uint8_t cb;
86     uint8_t cr;
87     uint8_t y;
88     uint8_t foo;
89 } clut_t;
90
91 #define XX44_PALETTE_SIZE 32
92 #define OVL_PALETTE_SIZE 256
93 #define XVMC_MAX_SURFACES 16
94 #define XVMC_MAX_SUBPICTURES 4
95 #define FOURCC_IA44 0x34344149
96 #define FOURCC_AI44 0x34344941
97
98 typedef struct
99 {
100     unsigned size;
101     unsigned max_used;
102     uint32_t cluts[XX44_PALETTE_SIZE];
103     /* cache palette entries for both colors and clip_colors */
104     int lookup_cache[OVL_PALETTE_SIZE*2];
105 } xx44_palette_t;
106
107 /*
108  * Functions to handle the vlc-specific palette.
109  */
110
111 void clear_xx44_palette( xx44_palette_t *p );
112
113 /*
114  * Convert the xine-specific palette to something useful.
115  */
116
117 void xx44_to_xvmc_palette( const xx44_palette_t *p,unsigned char *xvmc_palette,
118              unsigned first_xx44_entry, unsigned num_xx44_entries,
119              unsigned num_xvmc_components, char *xvmc_components );
120
121 typedef struct
122 {
123     vlc_macroblocks_t   vlc_mc;
124     XvMCBlockArray      blocks;            /* pointer to memory for dct block array  */
125     int                 num_blocks;
126     XvMCMacroBlock      *macroblockptr;     /* pointer to current macro block         */
127     XvMCMacroBlock      *macroblockbaseptr; /* pointer to base MacroBlock in MB array */
128     XvMCMacroBlockArray macro_blocks;      /* pointer to memory for macroblock array */
129     int                 slices;
130 } xvmc_macroblocks_t;
131
132 typedef struct
133 {
134     unsigned int        mpeg_flags;
135     unsigned int        accel_flags;
136     unsigned int        max_width;
137     unsigned int        max_height;
138     unsigned int        sub_max_width;
139     unsigned int        sub_max_height;
140     int                 type_id;
141     XvImageFormatValues subPicType;
142     int                 flags;
143 } xvmc_capabilities_t;
144
145 typedef struct xvmc_surface_handler_s
146 {
147     XvMCSurface         surfaces[XVMC_MAX_SURFACES];
148     int                 surfInUse[XVMC_MAX_SURFACES];
149     int                 surfValid[XVMC_MAX_SURFACES];
150     XvMCSubpicture      subpictures[XVMC_MAX_SUBPICTURES];
151     int                 subInUse[XVMC_MAX_SUBPICTURES];
152     int                 subValid[XVMC_MAX_SUBPICTURES];
153     pthread_mutex_t     mutex;
154 } xvmc_surface_handler_t;
155
156 typedef struct context_lock_s
157 {
158     pthread_mutex_t     mutex;
159     pthread_cond_t      cond;
160     int                 num_readers;
161 } context_lock_t;
162
163 #define XVMCLOCKDISPLAY(display) XLockDisplay(display);
164 #define XVMCUNLOCKDISPLAY(display) XUnlockDisplay(display);
165
166 void xvmc_context_reader_unlock( context_lock_t *c );
167 void xvmc_context_reader_lock( context_lock_t *c );
168 void xvmc_context_writer_lock( context_lock_t *c );
169 void xvmc_context_writer_unlock( context_lock_t *c );
170 void free_context_lock( context_lock_t *c );
171 void xxmc_dispose_context( vout_thread_t *p_vout );
172
173 int xxmc_xvmc_surface_valid( vout_thread_t *p_vout, XvMCSurface *surf );
174 void xxmc_xvmc_free_surface( vout_thread_t *p_vout, XvMCSurface *surf );
175
176 void xvmc_vld_slice( picture_t *picture );
177 void xvmc_vld_frame( picture_t *picture );
178
179 void xxmc_do_update_frame( picture_t *picture, uint32_t width, uint32_t height,
180         double ratio, int format, int flags);
181
182 int checkXvMCCap( vout_thread_t *p_vout);
183
184 XvMCSubpicture *xxmc_xvmc_alloc_subpicture( vout_thread_t *p_vout,
185         XvMCContext *context, unsigned short width, unsigned short height,
186         int xvimage_id );
187
188 void xxmc_xvmc_free_subpicture( vout_thread_t *p_vout, XvMCSubpicture *sub );
189 void blend_xx44( uint8_t *dst_img, subpicture_t *sub_img, int dst_width,
190         int dst_height, int dst_pitch, xx44_palette_t *palette,int ia44);
191
192 #endif /* XvMC defines */
193
194 /*****************************************************************************
195  * vout_sys_t: video output method descriptor
196  *****************************************************************************
197  * This structure is part of the video output thread descriptor.
198  * It describes the X11 and XVideo specific properties of an output thread.
199  *****************************************************************************/
200 struct vout_sys_t
201 {
202     /* Internal settings and properties */
203     Display *           p_display;                        /* display pointer */
204
205     int                 i_screen;                           /* screen number */
206
207     /* Our window */
208     x11_window_t        window;
209
210     /* X11 generic properties */
211 #ifdef HAVE_SYS_SHM_H
212     int                 i_shm_opcode;      /* shared memory extension opcode */
213 #endif
214
215 #if defined(MODULE_NAME_IS_xvmc)
216     int                 i_xvport;
217     bool          b_paint_colourkey;
218     int                 i_colourkey;
219 #endif
220
221     /* Screen saver properties */
222     int                 i_ss_timeout;                             /* timeout */
223     int                 i_ss_interval;           /* interval between changes */
224     int                 i_ss_blanking;                      /* blanking mode */
225     int                 i_ss_exposure;                      /* exposure mode */
226 #ifdef DPMSINFO_IN_DPMS_H
227     BOOL                b_ss_dpms;                              /* DPMS mode */
228 #endif
229
230     /* Mouse pointer properties */
231     bool          b_mouse_pointer_visible;
232     mtime_t             i_time_mouse_last_moved; /* used to auto-hide pointer*/
233     mtime_t             i_mouse_hide_timeout;      /* after time hide cursor */
234     Cursor              blank_cursor;                   /* the hidden cursor */
235     mtime_t             i_time_button_last_pressed;   /* to track dbl-clicks */
236     Pixmap              cursor_pixmap;
237
238 #ifdef MODULE_NAME_IS_glx
239     /* GLX properties */
240     int                 b_glx13;
241     GLXContext          gwctx;
242     GLXWindow           gwnd;
243 #endif
244
245 #ifdef MODULE_NAME_IS_xvmc
246     /* XvMC related stuff here */
247     xvmc_macroblocks_t  macroblocks;
248     xvmc_capabilities_t *xvmc_cap;
249     unsigned int        xvmc_num_cap;
250     unsigned int        xvmc_max_subpic_x;
251     unsigned int        xvmc_max_subpic_y;
252     int                 xvmc_eventbase;
253     int                 xvmc_errbase;
254     int                 hwSubpictures;
255     XvMCSubpicture      *old_subpic;
256     XvMCSubpicture      *new_subpic;
257     xx44_palette_t      palette;
258     int                 first_overlay;
259     float               cpu_saver;
260     int                 cpu_save_enabled;
261     int                 reverse_nvidia_palette;
262     int                 context_flags;
263
264     /*
265      * These variables are protected by the context lock:
266      */
267     unsigned            xvmc_cur_cap;
268     int                 xvmc_backend_subpic;
269     XvMCContext         context;
270     int                 contextActive;
271     xvmc_surface_handler_t xvmc_surf_handler;
272     unsigned            xvmc_mpeg;
273     unsigned            xvmc_accel;
274     unsigned            last_accel_request;
275     unsigned            xvmc_width;
276     unsigned            xvmc_height;
277     int                 have_xvmc_autopaint;
278     int                 xvmc_xoverlay_type;
279     int                 unsigned_intra;
280
281     /*
282      * Only creation and destruction of the below.
283      */
284     char                *xvmc_palette;
285     XvImage             *subImage;
286     XShmSegmentInfo     subShmInfo;
287
288     /*
289      * The mutex below is needed since XlockDisplay wasn't really enough
290      * to protect the XvMC Calls.
291      */
292     context_lock_t      xvmc_lock;
293     subpicture_t *      p_last_subtitle_save;
294     int                 xvmc_deinterlace_method;
295     int                 xvmc_crop_style;
296     mtime_t             last_date;
297
298     //alphablend_t       alphablend_extra_data;
299 #endif
300
301 #ifdef HAVE_XSP
302     int                 i_hw_scale;
303 #endif
304 };
305
306 /*****************************************************************************
307  * picture_sys_t: direct buffer method descriptor
308  *****************************************************************************
309  * This structure is part of the picture descriptor, it describes the
310  * XVideo specific properties of a direct buffer.
311  *****************************************************************************/
312 struct picture_sys_t
313 {
314     IMAGE_TYPE *        p_image;
315
316 #ifdef HAVE_SYS_SHM_H
317     XShmSegmentInfo     shminfo;       /* shared memory zone information */
318 #endif
319
320 #ifdef MODULE_NAME_IS_xvmc
321     XvMCSurface         *xvmc_surf;
322     vlc_xxmc_t           xxmc_data;
323     int                  last_sw_format;
324     vout_thread_t        *p_vout;
325     int                  nb_display;
326 #endif
327 };
328
329 /*****************************************************************************
330  * mwmhints_t: window manager hints
331  *****************************************************************************
332  * Fullscreen needs to be able to hide the wm decorations so we provide
333  * this structure to make it easier.
334  *****************************************************************************/
335 #define MWM_HINTS_DECORATIONS   (1L << 1)
336 #define PROP_MWM_HINTS_ELEMENTS 5
337
338 typedef struct mwmhints_t
339 {
340     unsigned long flags;
341     unsigned long functions;
342     unsigned long decorations;
343     signed   long input_mode;
344     unsigned long status;
345 } mwmhints_t;
346
347 /*****************************************************************************
348  * Chroma defines
349  *****************************************************************************/
350 #if defined(MODULE_NAME_IS_xvmc)
351 #   define MAX_DIRECTBUFFERS (VOUT_MAX_PICTURES+2)
352 #else
353 #   define MAX_DIRECTBUFFERS 2
354 #endif
355
356 #ifndef MODULE_NAME_IS_glx
357 IMAGE_TYPE *CreateImage    ( vout_thread_t *,
358                              Display *, EXTRA_ARGS, int, int );
359 #ifdef HAVE_SYS_SHM_H
360 IMAGE_TYPE *CreateShmImage ( vout_thread_t *,
361                                     Display *, EXTRA_ARGS_SHM, int, int );
362 #endif
363 #endif
364