[vlc-commits] d3d11_fmt: introduce d3d11_handle_t to keep a handle on the DLL

Steve Lhomme git at videolan.org
Mon Nov 20 19:13:59 CET 2017


vlc | branch: master | Steve Lhomme <robUx4 at videolabs.io> | Sat Nov 18 14:29:17 2017 +0100| [7d0abd461446efd1c048c31ac1ebe77e2fdca37f] | committer: Jean-Baptiste Kempf

d3d11_fmt: introduce d3d11_handle_t to keep a handle on the DLL

Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=7d0abd461446efd1c048c31ac1ebe77e2fdca37f
---

 modules/codec/avcodec/d3d11va.c         |  3 ++-
 modules/video_chroma/d3d11_fmt.c        |  4 ++--
 modules/video_chroma/d3d11_fmt.h        |  9 ++++++++-
 modules/video_output/win32/direct3d11.c | 16 ++++++++--------
 4 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/modules/codec/avcodec/d3d11va.c b/modules/codec/avcodec/d3d11va.c
index 17d6a2040c..3c8ee18a3a 100644
--- a/modules/codec/avcodec/d3d11va.c
+++ b/modules/codec/avcodec/d3d11va.c
@@ -428,7 +428,8 @@ static int D3dCreateDevice(vlc_va_t *va)
 
     /* */
     d3d11_device_t d3d_dev;
-    hr = D3D11_CreateDevice(VLC_OBJECT(va), dx_sys->hdecoder_dll, true, &d3d_dev);
+    d3d11_handle_t hd3d = { .hdll = dx_sys->hdecoder_dll };
+    hr = D3D11_CreateDevice(va, &hd3d, true, &d3d_dev);
     if (FAILED(hr)) {
         msg_Err(va, "D3D11CreateDevice failed. (hr=0x%lX)", hr);
         return VLC_EGENERIC;
diff --git a/modules/video_chroma/d3d11_fmt.c b/modules/video_chroma/d3d11_fmt.c
index c5135c0984..695a47dd2b 100644
--- a/modules/video_chroma/d3d11_fmt.c
+++ b/modules/video_chroma/d3d11_fmt.c
@@ -130,14 +130,14 @@ int AllocateShaderView(vlc_object_t *obj, ID3D11Device *d3ddevice,
     return VLC_SUCCESS;
 }
 
-HRESULT D3D11_CreateDevice(vlc_object_t *obj, HINSTANCE hdecoder_dll,
+HRESULT D3D11_CreateDevice(vlc_object_t *obj, d3d11_handle_t *hd3d,
                            bool hw_decoding, d3d11_device_t *out)
 {
 #if !VLC_WINSTORE_APP
 # define D3D11CreateDevice(args...)             pf_CreateDevice(args)
     /* */
     PFN_D3D11_CREATE_DEVICE pf_CreateDevice;
-    pf_CreateDevice = (void *)GetProcAddress(hdecoder_dll, "D3D11CreateDevice");
+    pf_CreateDevice = (void *)GetProcAddress(hd3d->hdll, "D3D11CreateDevice");
     if (!pf_CreateDevice) {
         msg_Err(obj, "Cannot locate reference to D3D11CreateDevice ABI in DLL");
         return E_NOINTERFACE;
diff --git a/modules/video_chroma/d3d11_fmt.h b/modules/video_chroma/d3d11_fmt.h
index 84d3136691..4793fe75ce 100644
--- a/modules/video_chroma/d3d11_fmt.h
+++ b/modules/video_chroma/d3d11_fmt.h
@@ -35,6 +35,13 @@ typedef struct
     ID3D11DeviceContext      *d3dcontext;      /* D3D context */
 } d3d11_device_t;
 
+typedef struct
+{
+#if !VLC_WINSTORE_APP
+    HINSTANCE                 hdll;       /* handle of the opened d3d11 dll */
+#endif
+} d3d11_handle_t;
+
 /* owned by the vout for VLC_CODEC_D3D11_OPAQUE */
 struct picture_sys_t
 {
@@ -75,7 +82,7 @@ int AllocateShaderView(vlc_object_t *obj, ID3D11Device *d3ddevice,
                               ID3D11Texture2D *p_texture[D3D11_MAX_SHADER_VIEW], UINT slice_index,
                               ID3D11ShaderResourceView *resourceView[D3D11_MAX_SHADER_VIEW]);
 
-HRESULT D3D11_CreateDevice(vlc_object_t *obj, HINSTANCE hdecoder_dll,
+HRESULT D3D11_CreateDevice(vlc_object_t *obj, d3d11_handle_t *,
                            bool hw_decoding, d3d11_device_t *out);
 
 bool isXboxHardware(ID3D11Device *d3ddev);
diff --git a/modules/video_output/win32/direct3d11.c b/modules/video_output/win32/direct3d11.c
index a72a45e9f0..b98f6e372a 100644
--- a/modules/video_output/win32/direct3d11.c
+++ b/modules/video_output/win32/direct3d11.c
@@ -137,7 +137,7 @@ struct vout_display_sys_t
 
 #if !VLC_WINSTORE_APP
     HINSTANCE                hdxgi_dll;        /* handle of the opened dxgi dll */
-    HINSTANCE                hd3d11_dll;       /* handle of the opened d3d11 dll */
+    d3d11_handle_t           hd3d;
     HINSTANCE                hd3dcompiler_dll; /* handle of the opened d3dcompiler dll */
     /* We should find a better way to store this or atleast a shorter name */
     PFN_D3D11_CREATE_DEVICE_AND_SWAP_CHAIN OurD3D11CreateDeviceAndSwapChain;
@@ -418,8 +418,8 @@ static int OpenHwnd(vout_display_t *vd)
     if (!sys)
         return VLC_ENOMEM;
 
-    sys->hd3d11_dll = LoadLibrary(TEXT("D3D11.DLL"));
-    if (!sys->hd3d11_dll) {
+    sys->hd3d.hdll = LoadLibrary(TEXT("D3D11.DLL"));
+    if (!sys->hd3d.hdll) {
         msg_Warn(vd, "cannot load d3d11.dll, aborting");
         return VLC_EGENERIC;
     }
@@ -439,7 +439,7 @@ static int OpenHwnd(vout_display_t *vd)
     }
 
     sys->OurD3D11CreateDevice =
-        (void *)GetProcAddress(sys->hd3d11_dll, "D3D11CreateDevice");
+        (void *)GetProcAddress(sys->hd3d.hdll, "D3D11CreateDevice");
     if (!sys->OurD3D11CreateDevice) {
         msg_Err(vd, "Cannot locate reference to D3D11CreateDevice in d3d11 DLL");
         Direct3D11Destroy(vd);
@@ -1242,8 +1242,8 @@ static void Direct3D11Destroy(vout_display_t *vd)
 #if !VLC_WINSTORE_APP
     vout_display_sys_t *sys = vd->sys;
 
-    if (sys->hd3d11_dll)
-        FreeLibrary(sys->hd3d11_dll);
+    if (sys->hd3d.hdll)
+        FreeLibrary(sys->hd3d.hdll);
     if (sys->hd3dcompiler_dll)
         FreeLibrary(sys->hd3dcompiler_dll);
 
@@ -1251,7 +1251,7 @@ static void Direct3D11Destroy(vout_display_t *vd)
     sys->OurD3D11CreateDeviceAndSwapChain = NULL;
     sys->OurD3DCompile = NULL;
     sys->hdxgi_dll = NULL;
-    sys->hd3d11_dll = NULL;
+    sys->hd3d.hdll = NULL;
     sys->hd3dcompiler_dll = NULL;
 #else
     VLC_UNUSED(vd);
@@ -1476,7 +1476,7 @@ static int Direct3D11Open(vout_display_t *vd, video_format_t *fmt)
     //scd.Flags = 512; // DXGI_SWAP_CHAIN_FLAG_YUV_VIDEO;
     scd.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL;
 
-    hr = D3D11_CreateDevice(VLC_OBJECT(vd), sys->hd3d11_dll,
+    hr = D3D11_CreateDevice(VLC_OBJECT(vd), &sys->hd3d,
                             is_d3d11_opaque(fmt->i_chroma),
                             &sys->d3d_dev);
     if (FAILED(hr)) {



More information about the vlc-commits mailing list