]> git.sesse.net Git - vlc/blob - modules/video_output/msw/common.h
direct3d11: support more pixel formats
[vlc] / modules / video_output / msw / common.h
1 /*****************************************************************************
2  * common.h: Windows video output header file
3  *****************************************************************************
4  * Copyright (C) 2001-2009 VLC authors and VideoLAN
5  * $Id$
6  *
7  * Authors: Gildas Bazin <gbazin@videolan.org>
8  *          Damien Fouilleul <damienf@videolan.org>
9  *          Martell Malone <martellmalone@gmail.com>
10  *
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.
15  *
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.
20  *
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  *****************************************************************************/
25
26 #ifdef MODULE_NAME_IS_directdraw
27 # include <ddraw.h>
28 #endif
29 #ifdef MODULE_NAME_IS_direct3d11
30 # include <d3d11.h>
31 # if VLC_WINSTORE_APP
32 #  include <dxgi1_2.h>
33 # else
34 #  include <dxgi.h>
35 #endif
36 # include <d3dcompiler.h>
37 #endif
38 #ifdef MODULE_NAME_IS_direct3d9
39 # include <d3d9.h>
40 # include <d3dx9effect.h>
41 #endif
42 #ifdef MODULE_NAME_IS_glwin32
43 # include "../opengl.h"
44 #endif
45 #ifdef MODULE_NAME_IS_direct2d
46 # include <d2d1.h>
47 #endif
48
49 /*****************************************************************************
50  * event_thread_t: event thread
51  *****************************************************************************/
52 #include "events.h"
53
54 /*****************************************************************************
55  * vout_sys_t: video output method descriptor
56  *****************************************************************************
57  * This structure is part of the video output thread descriptor.
58  * It describes the module specific properties of an output thread.
59  *****************************************************************************/
60 struct vout_display_sys_t
61 {
62     /* */
63     event_thread_t *event;
64
65     /* */
66     HWND                 hwnd;                  /* Handle of the main window */
67     HWND                 hvideownd;        /* Handle of the video sub-window */
68     struct vout_window_t *parent_window;         /* Parent window VLC object */
69     HWND                 hparent;             /* Handle of the parent window */
70     HWND                 hfswnd;          /* Handle of the fullscreen window */
71
72     /* size of the display */
73     RECT         rect_display;
74
75     /* size of the overall window (including black bands) */
76     RECT         rect_parent;
77
78     unsigned changes;        /* changes made to the video display */
79
80     /* Misc */
81     bool is_first_display;
82     bool is_on_top;
83
84     /* screensaver system settings to be restored when vout is closed */
85     UINT i_spi_screensaveactive;
86
87     /* Coordinates of src and dest images (used when blitting to display) */
88     RECT         rect_src;
89     RECT         rect_src_clipped;
90     RECT         rect_dest;
91     RECT         rect_dest_clipped;
92
93     picture_pool_t *pool;
94
95 #ifdef MODULE_NAME_IS_directdraw
96     /* Multi-monitor support */
97     HMONITOR             hmonitor;          /* handle of the current monitor */
98     GUID                 *display_driver;
99
100     /* Overlay alignment restrictions */
101     int          i_align_src_boundary;
102     int          i_align_src_size;
103     int          i_align_dest_boundary;
104     int          i_align_dest_size;
105
106     bool   use_wallpaper;   /* show as desktop wallpaper ? */
107
108     bool   use_overlay;     /* Are we using an overlay surface */
109     bool   restore_overlay;
110
111     /* DDraw capabilities */
112     bool            can_blit_fourcc;
113
114     uint32_t        i_rgb_colorkey;      /* colorkey in RGB used by the overlay */
115     uint32_t        i_colorkey;                 /* colorkey used by the overlay */
116
117     COLORREF        color_bkg;
118     COLORREF        color_bkgtxt;
119
120     LPDIRECTDRAW2        ddobject;                    /* DirectDraw object */
121     LPDIRECTDRAWSURFACE2 display;                        /* Display device */
122     LPDIRECTDRAWCLIPPER  clipper;             /* clipper used for blitting */
123     HINSTANCE            hddraw_dll;       /* handle of the opened ddraw dll */
124
125     picture_sys_t        *picsys;
126
127     /* It protects the following variables */
128     vlc_mutex_t    lock;
129     bool           ch_wallpaper;
130     bool           wallpaper_requested;
131 #endif
132
133 #ifdef MODULE_NAME_IS_glwin32
134     HDC                   hGLDC;
135     HGLRC                 hGLRC;
136     vlc_gl_t              gl;
137     vout_display_opengl_t *vgl;
138     HDC                   affinityHDC; // DC for the selected GPU
139 #endif
140
141 #ifdef MODULE_NAME_IS_direct2d
142     HINSTANCE              d2_dll;            /* handle of the opened d2d1 dll */
143     ID2D1Factory           *d2_factory;                         /* D2D factory */
144     ID2D1HwndRenderTarget  *d2_render_target;          /* D2D rendering target */
145     ID2D1Bitmap            *d2_bitmap;                            /* D2 bitmap */
146 #endif
147
148 #ifdef MODULE_NAME_IS_direct3d11
149 #if !VLC_WINSTORE_APP
150     HINSTANCE                hdxgi_dll;        /* handle of the opened dxgi dll */
151     HINSTANCE                hd3d11_dll;       /* handle of the opened d3d11 dll */
152     HINSTANCE                hd3dcompiler_dll; /* handle of the opened d3dcompiler dll */
153     IDXGIAdapter             *dxgiadapter;     /* DXGI adapter */
154     IDXGIFactory             *dxgifactory;     /* DXGI factory */
155     IDXGISwapChain           *dxgiswapChain;   /* DXGI 1.0 swap chain */
156     /* We should find a better way to store this or atleast a shorter name */
157     PFN_D3D11_CREATE_DEVICE_AND_SWAP_CHAIN OurD3D11CreateDeviceAndSwapChain;
158     PFN_D3D11_CREATE_DEVICE                OurD3D11CreateDevice;
159     pD3DCompile                            OurD3DCompile;
160 #else
161     IDXGISwapChain1          *dxgiswapChain;   /* DXGI 1.1 swap chain */
162 #endif
163     ID3D11Device             *d3ddevice;       /* D3D device */
164     ID3D11DeviceContext      *d3dcontext;      /* D3D context */
165     ID3D11Texture2D          *d3dtexture;
166     ID3D11ShaderResourceView *d3dresViewY;
167     ID3D11ShaderResourceView *d3dresViewUV;
168     ID3D11RenderTargetView   *d3drenderTargetView;
169     ID3D11DepthStencilView   *d3ddepthStencilView;
170     ID3D11VertexShader       *d3dvertexShader;
171     ID3D11PixelShader        *d3dpixelShader;
172     ID3D11InputLayout        *d3dvertexLayout;
173     ID3D11SamplerState       *d3dsampState;
174     picture_sys_t            *picsys;
175     D3D_FEATURE_LEVEL        d3dfeaturelevel;
176     DXGI_FORMAT              d3dFormatTex;
177     DXGI_FORMAT              d3dFormatY;
178     DXGI_FORMAT              d3dFormatUV;
179     vlc_fourcc_t             vlcFormat;
180 #endif
181
182 #ifdef MODULE_NAME_IS_direct3d9
183     bool allow_hw_yuv;    /* Should we use hardware YUV->RGB conversions */
184     /* show video on desktop window ? */
185     bool use_desktop;
186     struct {
187         bool is_fullscreen;
188         bool is_on_top;
189         RECT win;
190     } desktop_save;
191     vout_display_cfg_t cfg_saved; /* configuration used before going into desktop mode */
192
193     // core objects
194     HINSTANCE               hd3d9_dll;       /* handle of the opened d3d9 dll */
195     HINSTANCE               hd3d9x_dll;      /* handle of the opened d3d9x dll */
196     IDirect3DPixelShader9*  d3dx_shader;
197     LPDIRECT3D9             d3dobj;
198     D3DCAPS9                d3dcaps;
199     LPDIRECT3DDEVICE9       d3ddev;
200     D3DPRESENT_PARAMETERS   d3dpp;
201
202     // scene objects
203     LPDIRECT3DTEXTURE9      d3dtex;
204     LPDIRECT3DVERTEXBUFFER9 d3dvtc;
205     D3DFORMAT               d3dregion_format;
206     int                     d3dregion_count;
207     struct d3d_region_t     *d3dregion;
208
209     picture_sys_t           *picsys;
210
211     /* */
212     bool                    reset_device;
213     bool                    reopen_device;
214     bool                    lost_not_ready;
215     bool                    clear_scene;
216
217     /* It protects the following variables */
218     vlc_mutex_t    lock;
219     bool           ch_desktop;
220     bool           desktop_requested;
221 #endif
222
223 #if defined(MODULE_NAME_IS_wingdi)
224     int  i_depth;
225
226     /* Our offscreen bitmap and its framebuffer */
227     HDC        off_dc;
228     HBITMAP    off_bitmap;
229
230     struct
231     {
232         BITMAPINFO bitmapinfo;
233         RGBQUAD    red;
234         RGBQUAD    green;
235         RGBQUAD    blue;
236     };
237 #endif
238 };
239
240 /*****************************************************************************
241  * Prototypes from common.c
242  *****************************************************************************/
243 int  CommonInit(vout_display_t *);
244 void CommonClean(vout_display_t *);
245 void CommonManage(vout_display_t *);
246 int  CommonControl(vout_display_t *, int , va_list );
247 void CommonDisplay(vout_display_t *);
248 int  CommonUpdatePicture(picture_t *, picture_t **, uint8_t *, unsigned);
249
250 void UpdateRects (vout_display_t *,
251                   const vout_display_cfg_t *,
252                   const video_format_t *,
253                   bool is_forced);
254 void AlignRect(RECT *, int align_boundary, int align_size);
255
256 picture_pool_t *CommonPool(vout_display_t *, unsigned);
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