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