WGL: OpenGL provider module for Windows
[vlc.git] / modules / video_output / win32 / common.h
blob0e654e052999ffddf1aa2e4e0afe54271dd19ca3
1 /*****************************************************************************
2 * common.h: Windows video output header file
3 *****************************************************************************
4 * Copyright (C) 2001-2009 VLC authors and VideoLAN
5 * $Id$
7 * Authors: Gildas Bazin <gbazin@videolan.org>
8 * Damien Fouilleul <damienf@videolan.org>
9 * Martell Malone <martellmalone@gmail.com>
11 * This program is free software; you can redistribute it and/or modify it
12 * under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation; either version 2.1 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public License
22 * along with this program; if not, write to the Free Software Foundation,
23 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
24 *****************************************************************************/
26 #ifdef MODULE_NAME_IS_directdraw
27 # include <ddraw.h>
28 #endif
29 #ifdef MODULE_NAME_IS_direct3d11
30 # include <d3d11.h>
31 # include <dxgi1_2.h>
32 # include <d3dcompiler.h>
33 #endif
34 #ifdef MODULE_NAME_IS_direct3d9
35 # include <d3d9.h>
36 # include <d3dx9effect.h>
37 #endif
38 #if defined(MODULE_NAME_IS_glwin32) || defined(MODULE_NAME_IS_wgl)
39 # include "../opengl.h"
40 #endif
41 #ifdef MODULE_NAME_IS_direct2d
42 # include <d2d1.h>
43 #endif
45 /*****************************************************************************
46 * event_thread_t: event thread
47 *****************************************************************************/
48 #include "events.h"
50 #ifdef MODULE_NAME_IS_direct3d11
51 typedef struct
53 DXGI_FORMAT textureFormat;
54 DXGI_FORMAT resourceFormatYRGB;
55 DXGI_FORMAT resourceFormatUV;
56 } d3d_quad_cfg_t;
58 typedef struct
60 ID3D11Buffer *pVertexBuffer;
61 ID3D11Texture2D *pTexture;
62 ID3D11ShaderResourceView *d3dresViewY;
63 ID3D11ShaderResourceView *d3dresViewUV;
64 ID3D11PixelShader *d3dpixelShader;
65 D3D11_VIEWPORT cropViewport;
66 } d3d_quad_t;
67 #endif
69 #if VLC_WINSTORE_APP
70 extern const GUID GUID_SWAPCHAIN_WIDTH;
71 extern const GUID GUID_SWAPCHAIN_HEIGHT;
72 #endif
74 /*****************************************************************************
75 * vout_sys_t: video output method descriptor
76 *****************************************************************************
77 * This structure is part of the video output thread descriptor.
78 * It describes the module specific properties of an output thread.
79 *****************************************************************************/
80 struct vout_display_sys_t
82 /* */
83 event_thread_t *event;
85 /* */
86 HWND hwnd; /* Handle of the main window */
87 HWND hvideownd; /* Handle of the video sub-window */
88 struct vout_window_t *parent_window; /* Parent window VLC object */
89 HWND hparent; /* Handle of the parent window */
90 HWND hfswnd; /* Handle of the fullscreen window */
92 /* size of the display */
93 RECT rect_display;
95 /* size of the overall window (including black bands) */
96 RECT rect_parent;
98 unsigned changes; /* changes made to the video display */
100 /* Misc */
101 bool is_first_display;
102 bool is_on_top;
104 /* screensaver system settings to be restored when vout is closed */
105 UINT i_spi_screensaveactive;
107 /* Coordinates of src and dest images (used when blitting to display) */
108 RECT rect_src;
109 RECT rect_src_clipped;
110 RECT rect_dest;
111 RECT rect_dest_clipped;
113 picture_pool_t *pool;
115 #ifdef MODULE_NAME_IS_directdraw
116 /* Multi-monitor support */
117 HMONITOR hmonitor; /* handle of the current monitor */
118 GUID *display_driver;
120 /* Overlay alignment restrictions */
121 int i_align_src_boundary;
122 int i_align_src_size;
123 int i_align_dest_boundary;
124 int i_align_dest_size;
126 bool use_wallpaper; /* show as desktop wallpaper ? */
128 bool use_overlay; /* Are we using an overlay surface */
129 bool restore_overlay;
131 /* DDraw capabilities */
132 bool can_blit_fourcc;
134 uint32_t i_rgb_colorkey; /* colorkey in RGB used by the overlay */
135 uint32_t i_colorkey; /* colorkey used by the overlay */
137 COLORREF color_bkg;
138 COLORREF color_bkgtxt;
140 LPDIRECTDRAW2 ddobject; /* DirectDraw object */
141 LPDIRECTDRAWSURFACE2 display; /* Display device */
142 LPDIRECTDRAWCLIPPER clipper; /* clipper used for blitting */
143 HINSTANCE hddraw_dll; /* handle of the opened ddraw dll */
145 picture_sys_t *picsys;
147 /* It protects the following variables */
148 vlc_mutex_t lock;
149 bool ch_wallpaper;
150 bool wallpaper_requested;
151 #endif
153 #if defined(MODULE_NAME_IS_glwin32) || defined(MODULE_NAME_IS_wgl)
154 HDC hGLDC;
155 HGLRC hGLRC;
156 vlc_gl_t gl;
157 # ifdef MODULE_NAME_IS_glwin32
158 vout_display_opengl_t *vgl;
159 # endif
160 HDC affinityHDC; // DC for the selected GPU
161 #endif
163 #ifdef MODULE_NAME_IS_direct2d
164 HINSTANCE d2_dll; /* handle of the opened d2d1 dll */
165 ID2D1Factory *d2_factory; /* D2D factory */
166 ID2D1HwndRenderTarget *d2_render_target; /* D2D rendering target */
167 ID2D1Bitmap *d2_bitmap; /* D2 bitmap */
168 #endif
170 #ifdef MODULE_NAME_IS_direct3d11
171 #if !VLC_WINSTORE_APP
172 HINSTANCE hdxgi_dll; /* handle of the opened dxgi dll */
173 HINSTANCE hd3d11_dll; /* handle of the opened d3d11 dll */
174 HINSTANCE hd3dcompiler_dll; /* handle of the opened d3dcompiler dll */
175 IDXGIFactory2 *dxgifactory; /* DXGI 1.2 factory */
176 /* We should find a better way to store this or atleast a shorter name */
177 PFN_D3D11_CREATE_DEVICE_AND_SWAP_CHAIN OurD3D11CreateDeviceAndSwapChain;
178 PFN_D3D11_CREATE_DEVICE OurD3D11CreateDevice;
179 pD3DCompile OurD3DCompile;
180 #else
181 HANDLE context_lock; /* D3D11 Context lock necessary
182 for hw decoding on WinRT */
183 #endif
184 IDXGISwapChain1 *dxgiswapChain; /* DXGI 1.1 swap chain */
185 ID3D11Device *d3ddevice; /* D3D device */
186 ID3D11DeviceContext *d3dcontext; /* D3D context */
187 d3d_quad_t picQuad;
188 d3d_quad_cfg_t picQuadConfig;
190 /* staging quad to adjust visible borders */
191 d3d_quad_t stagingQuad;
193 ID3D11RenderTargetView *d3drenderTargetView;
194 ID3D11DepthStencilView *d3ddepthStencilView;
195 const char *d3dPxShader;
197 // SPU
198 vlc_fourcc_t pSubpictureChromas[2];
199 const char *psz_rgbaPxShader;
200 ID3D11PixelShader *pSPUPixelShader;
201 DXGI_FORMAT d3dregion_format;
202 int d3dregion_count;
203 picture_t **d3dregions;
204 #endif
206 #ifdef MODULE_NAME_IS_direct3d9
207 bool allow_hw_yuv; /* Should we use hardware YUV->RGB conversions */
208 /* show video on desktop window ? */
209 bool use_desktop;
210 struct {
211 bool is_fullscreen;
212 bool is_on_top;
213 RECT win;
214 } desktop_save;
215 vout_display_cfg_t cfg_saved; /* configuration used before going into desktop mode */
217 // core objects
218 HINSTANCE hd3d9_dll; /* handle of the opened d3d9 dll */
219 HINSTANCE hd3d9x_dll; /* handle of the opened d3d9x dll */
220 IDirect3DPixelShader9* d3dx_shader;
221 LPDIRECT3D9 d3dobj;
222 D3DCAPS9 d3dcaps;
223 LPDIRECT3DDEVICE9 d3ddev;
224 D3DPRESENT_PARAMETERS d3dpp;
225 bool use_d3d9ex;
227 // scene objects
228 LPDIRECT3DTEXTURE9 d3dtex;
229 LPDIRECT3DVERTEXBUFFER9 d3dvtc;
230 D3DFORMAT d3dregion_format;
231 int d3dregion_count;
232 struct d3d_region_t *d3dregion;
234 picture_sys_t *picsys;
236 /* */
237 bool reset_device;
238 bool reopen_device;
239 bool lost_not_ready;
240 bool clear_scene;
242 /* It protects the following variables */
243 vlc_mutex_t lock;
244 bool ch_desktop;
245 bool desktop_requested;
246 #endif
248 #if defined(MODULE_NAME_IS_wingdi)
249 int i_depth;
251 /* Our offscreen bitmap and its framebuffer */
252 HDC off_dc;
253 HBITMAP off_bitmap;
255 struct
257 BITMAPINFO bitmapinfo;
258 RGBQUAD red;
259 RGBQUAD green;
260 RGBQUAD blue;
262 #endif
265 /*****************************************************************************
266 * Prototypes from common.c
267 *****************************************************************************/
268 int CommonInit(vout_display_t *);
269 void CommonClean(vout_display_t *);
270 void CommonManage(vout_display_t *);
271 int CommonControl(vout_display_t *, int , va_list );
272 void CommonDisplay(vout_display_t *);
273 int CommonUpdatePicture(picture_t *, picture_t **, uint8_t *, unsigned);
275 void UpdateRects (vout_display_t *,
276 const vout_display_cfg_t *,
277 const video_format_t *,
278 bool is_forced);
279 void AlignRect(RECT *, int align_boundary, int align_size);
281 picture_pool_t *CommonPool(vout_display_t *, unsigned);
283 /*****************************************************************************
284 * Constants
285 *****************************************************************************/
286 #define IDM_TOGGLE_ON_TOP WM_USER + 1
287 #define DX_POSITION_CHANGE 0x1000
288 #define DX_WALLPAPER_CHANGE 0x2000
289 #define DX_DESKTOP_CHANGE 0x4000