]> git.sesse.net Git - vlc/blobdiff - modules/video_output/msw/common.h
direct3d11: support more pixel formats
[vlc] / modules / video_output / msw / common.h
index b5bbe07c4baeec5ead82d3cdd97535f532aa69b5..2aeeba730fbe1ac493cc67b33b3bf2543e4d0f2d 100644 (file)
@@ -1,67 +1,56 @@
 /*****************************************************************************
  * common.h: Windows video output header file
  *****************************************************************************
- * Copyright (C) 2001-2009 the VideoLAN team
+ * Copyright (C) 2001-2009 VLC authors and VideoLAN
  * $Id$
  *
  * Authors: Gildas Bazin <gbazin@videolan.org>
  *          Damien Fouilleul <damienf@videolan.org>
+ *          Martell Malone <martellmalone@gmail.com>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
+#ifdef MODULE_NAME_IS_directdraw
+# include <ddraw.h>
+#endif
+#ifdef MODULE_NAME_IS_direct3d11
+# include <d3d11.h>
+# if VLC_WINSTORE_APP
+#  include <dxgi1_2.h>
+# else
+#  include <dxgi.h>
+#endif
+# include <d3dcompiler.h>
+#endif
+#ifdef MODULE_NAME_IS_direct3d9
+# include <d3d9.h>
+# include <d3dx9effect.h>
+#endif
+#ifdef MODULE_NAME_IS_glwin32
+# include "../opengl.h"
+#endif
+#ifdef MODULE_NAME_IS_direct2d
+# include <d2d1.h>
+#endif
+
 /*****************************************************************************
  * event_thread_t: event thread
  *****************************************************************************/
-#include <vlc_picture_pool.h>
 #include "events.h"
 
-#ifdef MODULE_NAME_IS_wingapi
-    typedef struct GXDisplayProperties {
-        DWORD cxWidth;
-        DWORD cyHeight;
-        long cbxPitch;
-        long cbyPitch;
-        long cBPP;
-        DWORD ffFormat;
-    } GXDisplayProperties;
-
-    typedef struct GXScreenRect {
-        DWORD dwTop;
-        DWORD dwLeft;
-        DWORD dwWidth;
-        DWORD dwHeight;
-    } GXScreenRect;
-
-#   define GX_FULLSCREEN    0x01
-#   define GX_NORMALKEYS    0x02
-#   define GX_LANDSCAPEKEYS 0x03
-
-#   ifndef kfLandscape
-#       define kfLandscape      0x8
-#       define kfPalette        0x10
-#       define kfDirect         0x20
-#       define kfDirect555      0x40
-#       define kfDirect565      0x80
-#       define kfDirect888      0x100
-#       define kfDirect444      0x200
-#       define kfDirectInverted 0x400
-#   endif
-
-#endif
-
 /*****************************************************************************
  * vout_sys_t: video output method descriptor
  *****************************************************************************
@@ -80,15 +69,8 @@ struct vout_display_sys_t
     HWND                 hparent;             /* Handle of the parent window */
     HWND                 hfswnd;          /* Handle of the fullscreen window */
 
-    /* Multi-monitor support */
-    HMONITOR             hmonitor;          /* handle of the current monitor */
-    GUID                 *p_display_driver;
-    HMONITOR             (WINAPI* MonitorFromWindow)(HWND, DWORD);
-    BOOL                 (WINAPI* GetMonitorInfo)(HMONITOR, LPMONITORINFO);
-
     /* size of the display */
     RECT         rect_display;
-    int          display_depth;
 
     /* size of the overall window (including black bands) */
     RECT         rect_parent;
@@ -99,14 +81,8 @@ struct vout_display_sys_t
     bool is_first_display;
     bool is_on_top;
 
-#ifndef UNDER_CE
-
     /* screensaver system settings to be restored when vout is closed */
-    UINT i_spi_lowpowertimeout;
-    UINT i_spi_powerofftimeout;
-    UINT i_spi_screensavetimeout;
-
-#endif
+    UINT i_spi_screensaveactive;
 
     /* Coordinates of src and dest images (used when blitting to display) */
     RECT         rect_src;
@@ -114,45 +90,97 @@ struct vout_display_sys_t
     RECT         rect_dest;
     RECT         rect_dest_clipped;
 
-    bool   allow_hw_yuv;    /* Should we use hardware YUV->RGB conversions */
+    picture_pool_t *pool;
 
+#ifdef MODULE_NAME_IS_directdraw
+    /* Multi-monitor support */
+    HMONITOR             hmonitor;          /* handle of the current monitor */
+    GUID                 *display_driver;
 
-#ifdef MODULE_NAME_IS_directx
     /* Overlay alignment restrictions */
     int          i_align_src_boundary;
     int          i_align_src_size;
     int          i_align_dest_boundary;
     int          i_align_dest_size;
 
-    bool      b_wallpaper;    /* show as desktop wallpaper ? */
+    bool   use_wallpaper;   /* show as desktop wallpaper ? */
 
-    bool   b_using_overlay;         /* Are we using an overlay surface */
-    bool   b_use_sysmem;   /* Should we use system memory for surfaces */
-    bool   b_3buf_overlay;   /* Should we use triple buffered overlays */
+    bool   use_overlay;     /* Are we using an overlay surface */
+    bool   restore_overlay;
 
     /* DDraw capabilities */
-    int          b_caps_overlay_clipping;
+    bool            can_blit_fourcc;
 
-    unsigned int    i_rgb_colorkey;      /* colorkey in RGB used by the overlay */
-    unsigned int    i_colorkey;                 /* colorkey used by the overlay */
+    uint32_t        i_rgb_colorkey;      /* colorkey in RGB used by the overlay */
+    uint32_t        i_colorkey;                 /* colorkey used by the overlay */
 
     COLORREF        color_bkg;
     COLORREF        color_bkgtxt;
 
-    LPDIRECTDRAW2        p_ddobject;                    /* DirectDraw object */
-    LPDIRECTDRAWSURFACE2 p_display;                        /* Display device */
-    LPDIRECTDRAWSURFACE2 p_current_surface;   /* surface currently displayed */
-    LPDIRECTDRAWCLIPPER  p_clipper;             /* clipper used for blitting */
+    LPDIRECTDRAW2        ddobject;                    /* DirectDraw object */
+    LPDIRECTDRAWSURFACE2 display;                        /* Display device */
+    LPDIRECTDRAWCLIPPER  clipper;             /* clipper used for blitting */
     HINSTANCE            hddraw_dll;       /* handle of the opened ddraw dll */
+
+    picture_sys_t        *picsys;
+
+    /* It protects the following variables */
     vlc_mutex_t    lock;
+    bool           ch_wallpaper;
+    bool           wallpaper_requested;
 #endif
 
 #ifdef MODULE_NAME_IS_glwin32
-    HDC hGLDC;
-    HGLRC hGLRC;
+    HDC                   hGLDC;
+    HGLRC                 hGLRC;
+    vlc_gl_t              gl;
+    vout_display_opengl_t *vgl;
+    HDC                   affinityHDC; // DC for the selected GPU
+#endif
+
+#ifdef MODULE_NAME_IS_direct2d
+    HINSTANCE              d2_dll;            /* handle of the opened d2d1 dll */
+    ID2D1Factory           *d2_factory;                         /* D2D factory */
+    ID2D1HwndRenderTarget  *d2_render_target;          /* D2D rendering target */
+    ID2D1Bitmap            *d2_bitmap;                            /* D2 bitmap */
 #endif
 
-#ifdef MODULE_NAME_IS_direct3d
+#ifdef MODULE_NAME_IS_direct3d11
+#if !VLC_WINSTORE_APP
+    HINSTANCE                hdxgi_dll;        /* handle of the opened dxgi dll */
+    HINSTANCE                hd3d11_dll;       /* handle of the opened d3d11 dll */
+    HINSTANCE                hd3dcompiler_dll; /* handle of the opened d3dcompiler dll */
+    IDXGIAdapter             *dxgiadapter;     /* DXGI adapter */
+    IDXGIFactory             *dxgifactory;     /* DXGI factory */
+    IDXGISwapChain           *dxgiswapChain;   /* DXGI 1.0 swap chain */
+    /* We should find a better way to store this or atleast a shorter name */
+    PFN_D3D11_CREATE_DEVICE_AND_SWAP_CHAIN OurD3D11CreateDeviceAndSwapChain;
+    PFN_D3D11_CREATE_DEVICE                OurD3D11CreateDevice;
+    pD3DCompile                            OurD3DCompile;
+#else
+    IDXGISwapChain1          *dxgiswapChain;   /* DXGI 1.1 swap chain */
+#endif
+    ID3D11Device             *d3ddevice;       /* D3D device */
+    ID3D11DeviceContext      *d3dcontext;      /* D3D context */
+    ID3D11Texture2D          *d3dtexture;
+    ID3D11ShaderResourceView *d3dresViewY;
+    ID3D11ShaderResourceView *d3dresViewUV;
+    ID3D11RenderTargetView   *d3drenderTargetView;
+    ID3D11DepthStencilView   *d3ddepthStencilView;
+    ID3D11VertexShader       *d3dvertexShader;
+    ID3D11PixelShader        *d3dpixelShader;
+    ID3D11InputLayout        *d3dvertexLayout;
+    ID3D11SamplerState       *d3dsampState;
+    picture_sys_t            *picsys;
+    D3D_FEATURE_LEVEL        d3dfeaturelevel;
+    DXGI_FORMAT              d3dFormatTex;
+    DXGI_FORMAT              d3dFormatY;
+    DXGI_FORMAT              d3dFormatUV;
+    vlc_fourcc_t             vlcFormat;
+#endif
+
+#ifdef MODULE_NAME_IS_direct3d9
+    bool allow_hw_yuv;    /* Should we use hardware YUV->RGB conversions */
     /* show video on desktop window ? */
     bool use_desktop;
     struct {
@@ -164,19 +192,27 @@ struct vout_display_sys_t
 
     // core objects
     HINSTANCE               hd3d9_dll;       /* handle of the opened d3d9 dll */
+    HINSTANCE               hd3d9x_dll;      /* handle of the opened d3d9x dll */
+    IDirect3DPixelShader9*  d3dx_shader;
     LPDIRECT3D9             d3dobj;
+    D3DCAPS9                d3dcaps;
     LPDIRECT3DDEVICE9       d3ddev;
     D3DPRESENT_PARAMETERS   d3dpp;
+
     // scene objects
     LPDIRECT3DTEXTURE9      d3dtex;
     LPDIRECT3DVERTEXBUFFER9 d3dvtc;
+    D3DFORMAT               d3dregion_format;
+    int                     d3dregion_count;
+    struct d3d_region_t     *d3dregion;
 
-    picture_resource_t      resource;
-    picture_pool_t          *pool;
+    picture_sys_t           *picsys;
 
     /* */
     bool                    reset_device;
     bool                    reopen_device;
+    bool                    lost_not_ready;
+    bool                    clear_scene;
 
     /* It protects the following variables */
     vlc_mutex_t    lock;
@@ -184,67 +220,23 @@ struct vout_display_sys_t
     bool           desktop_requested;
 #endif
 
-#ifdef MODULE_NAME_IS_wingdi
-
+#if defined(MODULE_NAME_IS_wingdi)
     int  i_depth;
 
     /* Our offscreen bitmap and its framebuffer */
     HDC        off_dc;
     HBITMAP    off_bitmap;
-    uint8_t *  p_pic_buffer;
-    int        i_pic_pitch;
-    int        i_pic_pixel_pitch;
-
-    BITMAPINFO bitmapinfo;
-    RGBQUAD    red;
-    RGBQUAD    green;
-    RGBQUAD    blue;
-#endif
 
-#ifdef MODULE_NAME_IS_wingapi
-    int        i_depth;
-    int        render_width;
-    int        render_height;
-           /* Our offscreen bitmap and its framebuffer */
-    HDC        off_dc;
-    HBITMAP    off_bitmap;
-    uint8_t *  p_pic_buffer;
-    int        i_pic_pitch;
-    int        i_pic_pixel_pitch;
-
-    BITMAPINFO bitmapinfo;
-    RGBQUAD    red;
-    RGBQUAD    green;
-    RGBQUAD    blue;
-
-    HINSTANCE  gapi_dll;                   /* handle of the opened gapi dll */
-
-    /* GAPI functions */
-    int (*GXOpenDisplay)(HWND hWnd, DWORD dwFlags);
-    int (*GXCloseDisplay)();
-    void *(*GXBeginDraw)();
-    int (*GXEndDraw)();
-    GXDisplayProperties (*GXGetDisplayProperties)();
-    int (*GXSuspend)();
-    int (*GXResume)();
+    struct
+    {
+        BITMAPINFO bitmapinfo;
+        RGBQUAD    red;
+        RGBQUAD    green;
+        RGBQUAD    blue;
+    };
 #endif
 };
 
-#ifdef MODULE_NAME_IS_wingapi
-#   define GXOpenDisplay p_vout->p_sys->GXOpenDisplay
-#   define GXCloseDisplay p_vout->p_sys->GXCloseDisplay
-#   define GXBeginDraw p_vout->p_sys->GXBeginDraw
-#   define GXEndDraw p_vout->p_sys->GXEndDraw
-#   define GXGetDisplayProperties p_vout->p_sys->GXGetDisplayProperties
-#   define GXSuspend p_vout->p_sys->GXSuspend
-#   define GXResume p_vout->p_sys->GXResume
-#endif
-
-/*****************************************************************************
- * Prototypes from directx.c
- *****************************************************************************/
-int DirectDrawUpdateOverlay(vout_display_t *);
-
 /*****************************************************************************
  * Prototypes from common.c
  *****************************************************************************/
@@ -253,11 +245,15 @@ void CommonClean(vout_display_t *);
 void CommonManage(vout_display_t *);
 int  CommonControl(vout_display_t *, int , va_list );
 void CommonDisplay(vout_display_t *);
+int  CommonUpdatePicture(picture_t *, picture_t **, uint8_t *, unsigned);
 
 void UpdateRects (vout_display_t *,
                   const vout_display_cfg_t *,
                   const video_format_t *,
                   bool is_forced);
+void AlignRect(RECT *, int align_boundary, int align_size);
+
+picture_pool_t *CommonPool(vout_display_t *, unsigned);
 
 /*****************************************************************************
  * Constants
@@ -266,58 +262,3 @@ void UpdateRects (vout_display_t *,
 #define DX_POSITION_CHANGE 0x1000
 #define DX_WALLPAPER_CHANGE 0x2000
 #define DX_DESKTOP_CHANGE 0x4000
-
-/*****************************************************************************
- * WinCE helpers
- *****************************************************************************/
-#ifdef UNDER_CE
-
-#define AdjustWindowRect(a,b,c)
-
-#ifndef GCL_HBRBACKGROUND
-#   define GCL_HBRBACKGROUND (-10)
-#endif
-
-//#define FindWindowEx(a,b,c,d) 0
-
-#define GetWindowPlacement(a,b)
-#define SetWindowPlacement(a,b)
-/*typedef struct _WINDOWPLACEMENT {
-    UINT length;
-    UINT flags;
-    UINT showCmd;
-    POINT ptMinPosition;
-    POINT ptMaxPosition;
-    RECT rcNormalPosition;
-} WINDOWPLACEMENT;*/
-
-#ifndef WM_NCMOUSEMOVE
-#   define WM_NCMOUSEMOVE 160
-#endif
-#ifndef CS_OWNDC
-#   define CS_OWNDC 32
-#endif
-#ifndef SC_SCREENSAVE
-#   define SC_SCREENSAVE 0xF140
-#endif
-#ifndef SC_MONITORPOWER
-#   define SC_MONITORPOWER 0xF170
-#endif
-#ifndef WM_NCPAINT
-#   define WM_NCPAINT 133
-#endif
-#ifndef WS_OVERLAPPEDWINDOW
-#   define WS_OVERLAPPEDWINDOW 0xcf0000
-#endif
-#ifndef WS_EX_NOPARENTNOTIFY
-#   define WS_EX_NOPARENTNOTIFY 4
-#endif
-#ifndef WS_EX_APPWINDOW
-#define WS_EX_APPWINDOW 0x40000
-#endif
-
-//#define SetWindowLongPtr SetWindowLong
-//#define GetWindowLongPtr GetWindowLong
-//#define GWLP_USERDATA GWL_USERDATA
-
-#endif //UNDER_CE