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