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