mirror of https://github.com/mpv-player/mpv
hw_dxva2: create a IDirect3D9Ex device
This should allow us to create the device in situations when Direct3DCreate9 normally fails, for example if no user is logged in. While the later use-case is not very interesting, I hope it to work in some other situations as well, for example while certain drivers are in exclusive full screen mode. This is available since Windows 7, so I'm removing the old call completely.
This commit is contained in:
parent
644e23a0f5
commit
ce23dfa2fa
|
@ -357,44 +357,53 @@ static bool create_device(struct lavc_ctx *s)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
IDirect3D9* (WINAPI *Direct3DCreate9)(UINT) =
|
HRESULT (WINAPI *Direct3DCreate9Ex)(UINT, IDirect3D9Ex **) =
|
||||||
(void *)GetProcAddress(d3d9_dll, "Direct3DCreate9");
|
(void *)GetProcAddress(d3d9_dll, "Direct3DCreate9Ex");
|
||||||
if (!Direct3DCreate9) {
|
if (!Direct3DCreate9Ex) {
|
||||||
MP_ERR(p, "Failed to locate Direct3DCreate9\n");
|
MP_ERR(p, "Failed to locate Direct3DCreate9Ex\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
p->d3d9 = Direct3DCreate9(D3D_SDK_VERSION);
|
IDirect3D9Ex *d3d9ex = NULL;
|
||||||
if (!p->d3d9) {
|
HRESULT hr = Direct3DCreate9Ex(D3D_SDK_VERSION, &d3d9ex);
|
||||||
MP_ERR(p, "Failed to create IDirect3D object\n");
|
if (FAILED(hr)) {
|
||||||
|
MP_ERR(p, "Failed to create IDirect3D9Ex object\n");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
UINT adapter = D3DADAPTER_DEFAULT;
|
UINT adapter = D3DADAPTER_DEFAULT;
|
||||||
D3DDISPLAYMODE display_mode;
|
D3DDISPLAYMODEEX modeex = {0};
|
||||||
IDirect3D9_GetAdapterDisplayMode(p->d3d9, adapter, &display_mode);
|
IDirect3D9Ex_GetAdapterDisplayModeEx(d3d9ex, adapter, &modeex, NULL);
|
||||||
|
|
||||||
D3DPRESENT_PARAMETERS present_params = {
|
D3DPRESENT_PARAMETERS present_params = {
|
||||||
.Windowed = TRUE,
|
.Windowed = TRUE,
|
||||||
.BackBufferWidth = 640,
|
.BackBufferWidth = 640,
|
||||||
.BackBufferHeight = 480,
|
.BackBufferHeight = 480,
|
||||||
.BackBufferCount = 0,
|
.BackBufferCount = 0,
|
||||||
.BackBufferFormat = display_mode.Format,
|
.BackBufferFormat = modeex.Format,
|
||||||
.SwapEffect = D3DSWAPEFFECT_DISCARD,
|
.SwapEffect = D3DSWAPEFFECT_DISCARD,
|
||||||
.Flags = D3DPRESENTFLAG_VIDEO,
|
.Flags = D3DPRESENTFLAG_VIDEO,
|
||||||
};
|
};
|
||||||
HRESULT hr = IDirect3D9_CreateDevice(p->d3d9, adapter,
|
|
||||||
|
IDirect3DDevice9Ex *exdev = NULL;
|
||||||
|
hr = IDirect3D9Ex_CreateDeviceEx(d3d9ex, adapter,
|
||||||
D3DDEVTYPE_HAL,
|
D3DDEVTYPE_HAL,
|
||||||
GetShellWindow(),
|
GetShellWindow(),
|
||||||
D3DCREATE_SOFTWARE_VERTEXPROCESSING |
|
D3DCREATE_SOFTWARE_VERTEXPROCESSING |
|
||||||
D3DCREATE_MULTITHREADED |
|
D3DCREATE_MULTITHREADED |
|
||||||
D3DCREATE_FPU_PRESERVE,
|
D3DCREATE_FPU_PRESERVE,
|
||||||
&present_params,
|
&present_params,
|
||||||
&p->device);
|
NULL,
|
||||||
|
&exdev);
|
||||||
if (FAILED(hr)) {
|
if (FAILED(hr)) {
|
||||||
MP_ERR(p, "Failed to create Direct3D device: %s\n",
|
MP_ERR(p, "Failed to create Direct3D device: %s\n",
|
||||||
mp_HRESULT_to_str(hr));
|
mp_HRESULT_to_str(hr));
|
||||||
|
IDirect3D9_Release(d3d9ex);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p->d3d9 = (IDirect3D9 *)d3d9ex;
|
||||||
|
p->device = (IDirect3DDevice9 *)exdev;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue