From f003d8ea367f247e3ff49b672003817a0c3cdb30 Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 30 Jun 2017 12:46:12 +0200 Subject: d3d: UWP support for D3D11VA For some braindead reason, Microsoft decided to prevent you from dynamically loading system libraries. This makes portability harder. And we're talking about portability between Microsoft OSes! --- video/decode/d3d.c | 14 ++++++++++++++ video/decode/d3d.h | 1 + video/decode/hw_d3d11va.c | 16 ++++------------ video/out/opengl/hwdec_d3d11eglrgb.c | 13 ++++--------- 4 files changed, 23 insertions(+), 21 deletions(-) diff --git a/video/decode/d3d.c b/video/decode/d3d.c index 3e6e1accc8..36d914d545 100644 --- a/video/decode/d3d.c +++ b/video/decode/d3d.c @@ -107,15 +107,29 @@ static const struct d3dva_mode d3dva_modes[] = { #endif HMODULE d3d11_dll, d3d9_dll, dxva2_dll; +PFN_D3D11_CREATE_DEVICE d3d11_D3D11CreateDevice; static pthread_once_t d3d_load_once = PTHREAD_ONCE_INIT; +#if !HAVE_UWP static void d3d_do_load(void) { d3d11_dll = LoadLibrary(L"d3d11.dll"); d3d9_dll = LoadLibrary(L"d3d9.dll"); dxva2_dll = LoadLibrary(L"dxva2.dll"); + + if (d3d11_dll) { + d3d11_D3D11CreateDevice = + (void *)GetProcAddress(d3d11_dll, "D3D11CreateDevice"); + } } +#else +static void d3d_do_load(void) +{ + + d3d11_D3D11CreateDevice = D3D11CreateDevice; +} +#endif void d3d_load_dlls(void) { diff --git a/video/decode/d3d.h b/video/decode/d3d.h index 334f12151e..8ae244c585 100644 --- a/video/decode/d3d.h +++ b/video/decode/d3d.h @@ -42,6 +42,7 @@ struct d3d_decoder_fmt { // Must call d3d_load_dlls() before accessing. Once this is done, the DLLs // remain loaded forever. extern HMODULE d3d11_dll, d3d9_dll, dxva2_dll; +extern PFN_D3D11_CREATE_DEVICE d3d11_D3D11CreateDevice; void d3d_load_dlls(void); diff --git a/video/decode/hw_d3d11va.c b/video/decode/hw_d3d11va.c index c8255a36db..b75960945d 100644 --- a/video/decode/hw_d3d11va.c +++ b/video/decode/hw_d3d11va.c @@ -607,22 +607,14 @@ static struct mp_hwdec_ctx *d3d11_create_dev(struct mpv_global *global, HRESULT hr; d3d_load_dlls(); - if (!d3d11_dll) { + if (!d3d11_D3D11CreateDevice) { mp_err(plog, "Failed to load D3D11 library\n"); return NULL; } - PFN_D3D11_CREATE_DEVICE CreateDevice = - (void *)GetProcAddress(d3d11_dll, "D3D11CreateDevice"); - if (!CreateDevice) { - mp_err(plog, "Failed to get D3D11CreateDevice symbol from DLL: %s\n", - mp_LastError_to_str()); - return NULL; - } - - hr = CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, - D3D11_CREATE_DEVICE_VIDEO_SUPPORT, NULL, 0, - D3D11_SDK_VERSION, &device, NULL, NULL); + hr = d3d11_D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, + D3D11_CREATE_DEVICE_VIDEO_SUPPORT, NULL, 0, + D3D11_SDK_VERSION, &device, NULL, NULL); if (FAILED(hr)) { mp_err(plog, "Failed to create D3D11 Device: %s\n", mp_HRESULT_to_str(hr)); diff --git a/video/out/opengl/hwdec_d3d11eglrgb.c b/video/out/opengl/hwdec_d3d11eglrgb.c index 5b32290f8f..d1e96cf295 100644 --- a/video/out/opengl/hwdec_d3d11eglrgb.c +++ b/video/out/opengl/hwdec_d3d11eglrgb.c @@ -105,20 +105,15 @@ static int create(struct gl_hwdec *hw) p->egl_display = egl_display; - if (!d3d11_dll) { + if (!d3d11_D3D11CreateDevice) { if (!hw->probing) MP_ERR(hw, "Failed to load D3D11 library\n"); goto fail; } - PFN_D3D11_CREATE_DEVICE CreateDevice = - (void *)GetProcAddress(d3d11_dll, "D3D11CreateDevice"); - if (!CreateDevice) - goto fail; - - hr = CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, - D3D11_CREATE_DEVICE_VIDEO_SUPPORT, NULL, 0, - D3D11_SDK_VERSION, &p->d3d11_device, NULL, NULL); + hr = d3d11_D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, + D3D11_CREATE_DEVICE_VIDEO_SUPPORT, NULL, 0, + D3D11_SDK_VERSION, &p->d3d11_device, NULL, NULL); if (FAILED(hr)) { int lev = hw->probing ? MSGL_V : MSGL_ERR; mp_msg(hw->log, lev, "Failed to create D3D11 Device: %s\n", -- cgit v1.2.3