dxgi_fmt: add a helper function to detect the Xbox One
authorSteve Lhomme <robUx4@videolabs.io>
Thu, 19 Jan 2017 10:10:44 +0000 (11:10 +0100)
committerJean-Baptiste Kempf <jb@videolan.org>
Fri, 20 Jan 2017 13:36:27 +0000 (14:36 +0100)
Signed-off-by: Jean-Baptiste Kempf <jb@videolan.org>
modules/video_chroma/dxgi_fmt.c
modules/video_chroma/dxgi_fmt.h

index d956085..0b84d6f 100644 (file)
 # include "config.h"
 #endif
 
-#include "dxgi_fmt.h"
 #include <vlc_es.h>
 
+#define COBJMACROS
+#include <initguid.h>
+#include <d3d11.h>
+
+#include "dxgi_fmt.h"
+
 typedef struct
 {
     const char   *name;
@@ -119,3 +124,39 @@ void DxgiFormatMask(DXGI_FORMAT format, video_format_t *fmt)
         fmt->i_bmask = 0xff000000;
     }
 }
+
+IDXGIAdapter *D3D11DeviceAdapter(ID3D11Device *d3ddev)
+{
+    IDXGIDevice *pDXGIDevice = NULL;
+    HRESULT hr = ID3D11Device_QueryInterface(d3ddev, &IID_IDXGIDevice, (void **)&pDXGIDevice);
+    if (FAILED(hr)) {
+        return NULL;
+    }
+
+    IDXGIAdapter *p_adapter;
+    hr = IDXGIDevice_GetAdapter(pDXGIDevice, &p_adapter);
+    IDXGIDevice_Release(pDXGIDevice);
+    if (FAILED(hr)) {
+        return NULL;
+    }
+    return p_adapter;
+}
+
+bool isXboxHardware(ID3D11Device *d3ddev)
+{
+    IDXGIAdapter *p_adapter = D3D11DeviceAdapter(d3ddev);
+    if (!p_adapter)
+        return NULL;
+
+    bool result = false;
+    DXGI_ADAPTER_DESC adapterDesc;
+    if (SUCCEEDED(IDXGIAdapter_GetDesc(p_adapter, &adapterDesc))) {
+        if (adapterDesc.VendorId == 0 &&
+            adapterDesc.DeviceId == 0 &&
+            !wcscmp(L"ROOT\\SraKmd\\0000", adapterDesc.Description))
+            result = true;
+    }
+
+    IDXGIAdapter_Release(p_adapter);
+    return result;
+}
index 8f2e3bb..190bd69 100644 (file)
@@ -23,6 +23,7 @@
 #ifndef VLC_VIDEOCHROMA_DXGI_FMT_H_
 #define VLC_VIDEOCHROMA_DXGI_FMT_H_
 
+#include <dxgi.h>
 #include <dxgiformat.h>
 
 #include <vlc_common.h>
@@ -45,4 +46,8 @@ extern vlc_fourcc_t DxgiFormatFourcc(DXGI_FORMAT format);
 extern const d3d_format_t *GetRenderFormatList(void);
 extern void DxgiFormatMask(DXGI_FORMAT format, video_format_t *);
 
+typedef struct ID3D11Device ID3D11Device;
+bool isXboxHardware(ID3D11Device *d3ddev);
+IDXGIAdapter *D3D11DeviceAdapter(ID3D11Device *d3ddev);
+
 #endif /* include-guard */