[vlc-commits] d3d11: add a way to create a d3d11_device_t from an external ID3D11DeviceContext

Steve Lhomme git at videolan.org
Tue Nov 20 09:18:14 CET 2018


vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Fri Nov 16 16:46:57 2018 +0100| [ce5f4d712fdb36cc37b5a736190c2757df30dc71] | committer: Steve Lhomme

d3d11: add a way to create a d3d11_device_t from an external ID3D11DeviceContext

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

 modules/video_chroma/d3d11_fmt.c | 36 ++++++++++++++++++++++++++++++++++++
 modules/video_chroma/d3d11_fmt.h |  4 ++++
 2 files changed, 40 insertions(+)

diff --git a/modules/video_chroma/d3d11_fmt.c b/modules/video_chroma/d3d11_fmt.c
index 07ee9ae261..a887cd14cc 100644
--- a/modules/video_chroma/d3d11_fmt.c
+++ b/modules/video_chroma/d3d11_fmt.c
@@ -228,6 +228,42 @@ void D3D11_ReleaseDevice(d3d11_device_t *d3d_dev)
 #endif
 }
 
+#undef D3D11_CreateDeviceExternal
+HRESULT D3D11_CreateDeviceExternal(vlc_object_t *obj, ID3D11DeviceContext *d3d11ctx,
+                                   bool hw_decoding, d3d11_device_t *out)
+{
+    HRESULT hr;
+    ID3D11DeviceContext_GetDevice( d3d11ctx, &out->d3ddevice );
+
+    if (hw_decoding)
+    {
+        UINT creationFlags = ID3D11Device_GetCreationFlags(out->d3ddevice);
+        if (!(creationFlags & D3D11_CREATE_DEVICE_VIDEO_SUPPORT))
+        {
+            msg_Err(obj, "the provided D3D11 device doesn't support decoding");
+            ID3D11Device_Release(out->d3ddevice);
+            out->d3ddevice = NULL;
+            return E_FAIL;
+        }
+    }
+
+    ID3D11DeviceContext_AddRef( d3d11ctx );
+    out->d3dcontext = d3d11ctx;
+    out->owner = false;
+    out->feature_level = ID3D11Device_GetFeatureLevel(out->d3ddevice );
+
+    HANDLE context_lock = INVALID_HANDLE_VALUE;
+    UINT dataSize = sizeof(context_lock);
+    hr = ID3D11DeviceContext_GetPrivateData(d3d11ctx, &GUID_CONTEXT_MUTEX, &dataSize, &context_lock);
+    if (SUCCEEDED(hr))
+        out->context_mutex = context_lock;
+    else
+        out->context_mutex = INVALID_HANDLE_VALUE;
+
+    D3D11_GetDriverVersion(obj, out);
+    return S_OK;
+}
+
 #undef D3D11_CreateDevice
 HRESULT D3D11_CreateDevice(vlc_object_t *obj, d3d11_handle_t *hd3d,
                            bool hw_decoding, d3d11_device_t *out)
diff --git a/modules/video_chroma/d3d11_fmt.h b/modules/video_chroma/d3d11_fmt.h
index 115ce48406..bd1fbe6490 100644
--- a/modules/video_chroma/d3d11_fmt.h
+++ b/modules/video_chroma/d3d11_fmt.h
@@ -108,6 +108,10 @@ int D3D11_AllocateResourceView(vlc_object_t *obj, ID3D11Device *d3ddevice,
 HRESULT D3D11_CreateDevice(vlc_object_t *obj, d3d11_handle_t *,
                            bool hw_decoding, d3d11_device_t *out);
 #define D3D11_CreateDevice(a,b,c,d)  D3D11_CreateDevice( VLC_OBJECT(a), b, c, d )
+HRESULT D3D11_CreateDeviceExternal(vlc_object_t *obj, ID3D11DeviceContext *,
+                                   bool hw_decoding, d3d11_device_t *out);
+#define D3D11_CreateDeviceExternal(a,b,c,d) \
+    D3D11_CreateDeviceExternal( VLC_OBJECT(a), b, c, d )
 
 void D3D11_ReleaseDevice(d3d11_device_t *);
 



More information about the vlc-commits mailing list