]> git.sesse.net Git - vlc/blob - modules/video_output/msw/common.h
Direct3D: reject too old drivers and let them fallback to DirectDraw
[vlc] / modules / video_output / msw / common.h
1 /*****************************************************************************
2  * common.h: Windows video output header file
3  *****************************************************************************
4  * Copyright (C) 2001-2009 the VideoLAN team
5  * $Id$
6  *
7  * Authors: Gildas Bazin <gbazin@videolan.org>
8  *          Damien Fouilleul <damienf@videolan.org>
9  *
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.
14  *
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.
19  *
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  *****************************************************************************/
24
25 /*****************************************************************************
26  * event_thread_t: event thread
27  *****************************************************************************/
28 #include <vlc_picture_pool.h>
29 #include "events.h"
30
31 #ifdef MODULE_NAME_IS_wingapi
32     typedef struct GXDisplayProperties {
33         DWORD cxWidth;
34         DWORD cyHeight;
35         long cbxPitch;
36         long cbyPitch;
37         long cBPP;
38         DWORD ffFormat;
39     } GXDisplayProperties;
40
41     typedef struct GXScreenRect {
42         DWORD dwTop;
43         DWORD dwLeft;
44         DWORD dwWidth;
45         DWORD dwHeight;
46     } GXScreenRect;
47
48 #   define GX_FULLSCREEN    0x01
49 #   define GX_NORMALKEYS    0x02
50 #   define GX_LANDSCAPEKEYS 0x03
51
52 #   ifndef kfLandscape
53 #       define kfLandscape      0x8
54 #       define kfPalette        0x10
55 #       define kfDirect         0x20
56 #       define kfDirect555      0x40
57 #       define kfDirect565      0x80
58 #       define kfDirect888      0x100
59 #       define kfDirect444      0x200
60 #       define kfDirectInverted 0x400
61 #   endif
62
63 #endif
64
65 /*****************************************************************************
66  * vout_sys_t: video output method descriptor
67  *****************************************************************************
68  * This structure is part of the video output thread descriptor.
69  * It describes the module specific properties of an output thread.
70  *****************************************************************************/
71 struct vout_display_sys_t
72 {
73     /* */
74     event_thread_t *event;
75
76     /* */
77     HWND                 hwnd;                  /* Handle of the main window */
78     HWND                 hvideownd;        /* Handle of the video sub-window */
79     struct vout_window_t *parent_window;         /* Parent window VLC object */
80     HWND                 hparent;             /* Handle of the parent window */
81     HWND                 hfswnd;          /* Handle of the fullscreen window */
82
83     /* size of the display */
84     RECT         rect_display;
85     int          display_depth;
86
87     /* size of the overall window (including black bands) */
88     RECT         rect_parent;
89
90     unsigned changes;        /* changes made to the video display */
91
92     /* Misc */
93     bool is_first_display;
94     bool is_on_top;
95
96 #ifndef UNDER_CE
97
98     /* screensaver system settings to be restored when vout is closed */
99     UINT i_spi_lowpowertimeout;
100     UINT i_spi_powerofftimeout;
101     UINT i_spi_screensavetimeout;
102
103 #endif
104
105     /* Coordinates of src and dest images (used when blitting to display) */
106     RECT         rect_src;
107     RECT         rect_src_clipped;
108     RECT         rect_dest;
109     RECT         rect_dest_clipped;
110
111     picture_pool_t *pool;
112
113 #ifdef MODULE_NAME_IS_directx
114     /* Multi-monitor support */
115     HMONITOR             hmonitor;          /* handle of the current monitor */
116     GUID                 *display_driver;
117
118     /* Overlay alignment restrictions */
119     int          i_align_src_boundary;
120     int          i_align_src_size;
121     int          i_align_dest_boundary;
122     int          i_align_dest_size;
123
124     bool   use_wallpaper;   /* show as desktop wallpaper ? */
125
126     bool   use_overlay;     /* Are we using an overlay surface */
127     bool   restore_overlay;
128
129     /* DDraw capabilities */
130     bool            can_blit_fourcc;
131
132     uint32_t        i_rgb_colorkey;      /* colorkey in RGB used by the overlay */
133     uint32_t        i_colorkey;                 /* colorkey used by the overlay */
134
135     COLORREF        color_bkg;
136     COLORREF        color_bkgtxt;
137
138     LPDIRECTDRAW2        ddobject;                    /* DirectDraw object */
139     LPDIRECTDRAWSURFACE2 display;                        /* Display device */
140     LPDIRECTDRAWCLIPPER  clipper;             /* clipper used for blitting */
141     HINSTANCE            hddraw_dll;       /* handle of the opened ddraw dll */
142
143     picture_resource_t   resource;
144
145     /* It protects the following variables */
146     vlc_mutex_t    lock;
147     bool           ch_wallpaper;
148     bool           wallpaper_requested;
149 #endif
150
151 #ifdef MODULE_NAME_IS_glwin32
152     HDC                   hGLDC;
153     HGLRC                 hGLRC;
154     vlc_gl_t              gl;
155     vout_display_opengl_t *vgl;
156 #endif
157
158 #ifdef MODULE_NAME_IS_direct2d
159     HINSTANCE              d2_dll;            /* handle of the opened d2d1 dll */
160     ID2D1Factory           *d2_factory;                         /* D2D factory */
161     ID2D1HwndRenderTarget  *d2_render_target;          /* D2D rendering target */
162     ID2D1Bitmap            *d2_bitmap;                            /* D2 bitmap */
163 #endif
164
165 #ifdef MODULE_NAME_IS_direct3d
166     bool allow_hw_yuv;    /* Should we use hardware YUV->RGB conversions */
167     /* show video on desktop window ? */
168     bool use_desktop;
169     struct {
170         bool is_fullscreen;
171         bool is_on_top;
172         RECT win;
173     } desktop_save;
174     vout_display_cfg_t cfg_saved; /* configuration used before going into desktop mode */
175
176     // core objects
177     HINSTANCE               hd3d9_dll;       /* handle of the opened d3d9 dll */
178     LPDIRECT3D9             d3dobj;
179     D3DCAPS9                d3dcaps;
180     LPDIRECT3DDEVICE9       d3ddev;
181     D3DPRESENT_PARAMETERS   d3dpp;
182     // scene objects
183     LPDIRECT3DTEXTURE9      d3dtex;
184     LPDIRECT3DVERTEXBUFFER9 d3dvtc;
185     D3DFORMAT               d3dregion_format;
186     int                     d3dregion_count;
187     struct d3d_region_t     *d3dregion;
188
189     picture_resource_t      resource;
190
191     /* */
192     bool                    reset_device;
193     bool                    reopen_device;
194     bool                    clear_scene;
195
196     /* It protects the following variables */
197     vlc_mutex_t    lock;
198     bool           ch_desktop;
199     bool           desktop_requested;
200 #endif
201
202 #if defined(MODULE_NAME_IS_wingdi) || defined(MODULE_NAME_IS_wingapi)
203     int  i_depth;
204
205     /* Our offscreen bitmap and its framebuffer */
206     HDC        off_dc;
207     HBITMAP    off_bitmap;
208
209     struct
210     {
211         BITMAPINFO bitmapinfo;
212         RGBQUAD    red;
213         RGBQUAD    green;
214         RGBQUAD    blue;
215     };
216
217 #   ifdef MODULE_NAME_IS_wingapi
218     HINSTANCE  gapi_dll;                   /* handle of the opened gapi dll */
219
220     /* GAPI functions */
221     int (*GXOpenDisplay)(HWND hWnd, DWORD dwFlags);
222     int (*GXCloseDisplay)();
223     void *(*GXBeginDraw)();
224     int (*GXEndDraw)();
225     GXDisplayProperties (*GXGetDisplayProperties)();
226     int (*GXSuspend)();
227     int (*GXResume)();
228 #   endif
229 #endif
230 };
231
232 #ifdef MODULE_NAME_IS_wingapi
233 #   define GXOpenDisplay          vd->sys->GXOpenDisplay
234 #   define GXCloseDisplay         vd->sys->GXCloseDisplay
235 #   define GXBeginDraw            vd->sys->GXBeginDraw
236 #   define GXEndDraw              vd->sys->GXEndDraw
237 #   define GXGetDisplayProperties vd->sys->GXGetDisplayProperties
238 #   define GXSuspend              vd->sys->GXSuspend
239 #   define GXResume               vd->sys->GXResume
240 #endif
241
242 /*****************************************************************************
243  * Prototypes from common.c
244  *****************************************************************************/
245 int  CommonInit(vout_display_t *);
246 void CommonClean(vout_display_t *);
247 void CommonManage(vout_display_t *);
248 int  CommonControl(vout_display_t *, int , va_list );
249 void CommonDisplay(vout_display_t *);
250 int  CommonUpdatePicture(picture_t *, picture_t **, uint8_t *, unsigned);
251
252 void UpdateRects (vout_display_t *,
253                   const vout_display_cfg_t *,
254                   const video_format_t *,
255                   bool is_forced);
256 void AlignRect(RECT *, int align_boundary, int align_size);
257
258 /*****************************************************************************
259  * Constants
260  *****************************************************************************/
261 #define IDM_TOGGLE_ON_TOP WM_USER + 1
262 #define DX_POSITION_CHANGE 0x1000
263 #define DX_WALLPAPER_CHANGE 0x2000
264 #define DX_DESKTOP_CHANGE 0x4000
265
266 /*****************************************************************************
267  * WinCE helpers
268  *****************************************************************************/
269 #ifdef UNDER_CE
270
271 #define AdjustWindowRect(a,b,c) AdjustWindowRectEx(a,b,c,0)
272
273 #ifndef GCL_HBRBACKGROUND
274 #   define GCL_HBRBACKGROUND (-10)
275 #endif
276
277 //#define FindWindowEx(a,b,c,d) 0
278
279 #define GetWindowPlacement(a,b)
280 #define SetWindowPlacement(a,b)
281 /*typedef struct _WINDOWPLACEMENT {
282     UINT length;
283     UINT flags;
284     UINT showCmd;
285     POINT ptMinPosition;
286     POINT ptMaxPosition;
287     RECT rcNormalPosition;
288 } WINDOWPLACEMENT;*/
289
290 #ifndef WM_NCMOUSEMOVE
291 #   define WM_NCMOUSEMOVE 160
292 #endif
293 #ifndef CS_OWNDC
294 #   define CS_OWNDC 32
295 #endif
296 #ifndef SC_SCREENSAVE
297 #   define SC_SCREENSAVE 0xF140
298 #endif
299 #ifndef SC_MONITORPOWER
300 #   define SC_MONITORPOWER 0xF170
301 #endif
302 #ifndef WM_NCPAINT
303 #   define WM_NCPAINT 133
304 #endif
305 #ifndef WS_OVERLAPPEDWINDOW
306 #   define WS_OVERLAPPEDWINDOW 0xcf0000
307 #endif
308 #ifndef WS_EX_NOPARENTNOTIFY
309 #   define WS_EX_NOPARENTNOTIFY 4
310 #endif
311 #ifndef WS_EX_APPWINDOW
312 #define WS_EX_APPWINDOW 0x40000
313 #endif
314
315 //#define SetWindowLongPtr SetWindowLong
316 //#define GetWindowLongPtr GetWindowLong
317 //#define GWLP_USERDATA GWL_USERDATA
318
319 #endif //UNDER_CE