Commit b9194848 authored by Steve Lhomme's avatar Steve Lhomme Committed by Jean-Baptiste Kempf

d3d9_fmt: group some D3D9 objects together

And make the D3D9 device creation more generic
Signed-off-by: Jean-Baptiste Kempf's avatarJean-Baptiste Kempf <jb@videolan.org>
parent 0547c4a9
...@@ -31,6 +31,27 @@ struct picture_sys_t ...@@ -31,6 +31,27 @@ struct picture_sys_t
LPDIRECT3DSURFACE9 surface; LPDIRECT3DSURFACE9 surface;
}; };
typedef struct
{
bool use_ex;
union {
LPDIRECT3D9 obj;
LPDIRECT3D9EX objex;
};
} d3d9_handle_t;
typedef struct
{
/* d3d9_handle_t hd3d; TODO */
union
{
LPDIRECT3DDEVICE9 dev;
LPDIRECT3DDEVICE9EX devex;
};
D3DPRESENT_PARAMETERS pp;
UINT adapterId;
} d3d9_device_t;
#include "../codec/avcodec/va_surface.h" #include "../codec/avcodec/va_surface.h"
static inline picture_sys_t *ActivePictureSys(picture_t *p_pic) static inline picture_sys_t *ActivePictureSys(picture_t *p_pic)
......
...@@ -131,20 +131,10 @@ struct d3dctx ...@@ -131,20 +131,10 @@ struct d3dctx
{ {
HINSTANCE hdll; /* handle of the opened d3d9 dll */ HINSTANCE hdll; /* handle of the opened d3d9 dll */
HINSTANCE hxdll; /* handle of the opened d3d9x dll */ HINSTANCE hxdll; /* handle of the opened d3d9x dll */
union d3d9_handle_t hd3d;
{ d3d9_device_t d3d_dev;
LPDIRECT3D9 obj;
LPDIRECT3D9EX objex;
};
union
{
LPDIRECT3DDEVICE9 dev;
LPDIRECT3DDEVICE9EX devex;
};
D3DPRESENT_PARAMETERS pp;
D3DCAPS9 caps; D3DCAPS9 caps;
HWND hwnd; HWND hwnd;
bool use_ex;
}; };
struct vout_display_sys_t struct vout_display_sys_t
...@@ -435,7 +425,7 @@ static picture_pool_t *Direct3D9CreatePicturePool(vlc_object_t *o, ...@@ -435,7 +425,7 @@ static picture_pool_t *Direct3D9CreatePicturePool(vlc_object_t *o,
if (unlikely(picsys == NULL)) if (unlikely(picsys == NULL))
goto error; goto error;
HRESULT hr = IDirect3DDevice9_CreateOffscreenPlainSurface(d3dctx->dev, HRESULT hr = IDirect3DDevice9_CreateOffscreenPlainSurface(d3dctx->d3d_dev.dev,
fmt->i_width, fmt->i_width,
fmt->i_height, fmt->i_height,
format, format,
...@@ -496,6 +486,7 @@ static void Prepare(vout_display_t *vd, picture_t *picture, subpicture_t *subpic ...@@ -496,6 +486,7 @@ static void Prepare(vout_display_t *vd, picture_t *picture, subpicture_t *subpic
{ {
vout_display_sys_t *sys = vd->sys; vout_display_sys_t *sys = vd->sys;
LPDIRECT3DSURFACE9 surface = picture->p_sys->surface; LPDIRECT3DSURFACE9 surface = picture->p_sys->surface;
d3d9_device_t *p_d3d9_dev = &sys->d3dctx.d3d_dev;
/* FIXME it is a bit ugly, we need the surface to be unlocked for /* FIXME it is a bit ugly, we need the surface to be unlocked for
* rendering. * rendering.
...@@ -515,7 +506,7 @@ static void Prepare(vout_display_t *vd, picture_t *picture, subpicture_t *subpic ...@@ -515,7 +506,7 @@ static void Prepare(vout_display_t *vd, picture_t *picture, subpicture_t *subpic
visibleSource.top = 0; visibleSource.top = 0;
visibleSource.right = picture->format.i_visible_width; visibleSource.right = picture->format.i_visible_width;
visibleSource.bottom = picture->format.i_visible_height; visibleSource.bottom = picture->format.i_visible_height;
hr = IDirect3DDevice9_StretchRect( sys->d3dctx.dev, pic_ctx->picsys.surface, &visibleSource, surface, &visibleSource, D3DTEXF_NONE); hr = IDirect3DDevice9_StretchRect( p_d3d9_dev->dev, pic_ctx->picsys.surface, &visibleSource, surface, &visibleSource, D3DTEXF_NONE);
if (FAILED(hr)) { if (FAILED(hr)) {
msg_Err(vd, "Failed to copy the hw surface to the decoder surface (hr=0x%0lx)", hr ); msg_Err(vd, "Failed to copy the hw surface to the decoder surface (hr=0x%0lx)", hr );
} }
...@@ -523,7 +514,7 @@ static void Prepare(vout_display_t *vd, picture_t *picture, subpicture_t *subpic ...@@ -523,7 +514,7 @@ static void Prepare(vout_display_t *vd, picture_t *picture, subpicture_t *subpic
} }
/* check if device is still available */ /* check if device is still available */
HRESULT hr = IDirect3DDevice9_TestCooperativeLevel(sys->d3dctx.dev); HRESULT hr = IDirect3DDevice9_TestCooperativeLevel(p_d3d9_dev->dev);
if (FAILED(hr)) { if (FAILED(hr)) {
if (hr == D3DERR_DEVICENOTRESET && !sys->reset_device) { if (hr == D3DERR_DEVICENOTRESET && !sys->reset_device) {
vout_display_SendEventPicturesInvalid(vd); vout_display_SendEventPicturesInvalid(vd);
...@@ -559,6 +550,7 @@ static void Prepare(vout_display_t *vd, picture_t *picture, subpicture_t *subpic ...@@ -559,6 +550,7 @@ static void Prepare(vout_display_t *vd, picture_t *picture, subpicture_t *subpic
static void Display(vout_display_t *vd, picture_t *picture, subpicture_t *subpicture) static void Display(vout_display_t *vd, picture_t *picture, subpicture_t *subpicture)
{ {
vout_display_sys_t *sys = vd->sys; vout_display_sys_t *sys = vd->sys;
const d3d9_device_t *p_d3d9_dev = &sys->d3dctx.d3d_dev;
if (sys->lost_not_ready) { if (sys->lost_not_ready) {
picture_Release(picture); picture_Release(picture);
...@@ -573,10 +565,10 @@ static void Display(vout_display_t *vd, picture_t *picture, subpicture_t *subpic ...@@ -573,10 +565,10 @@ static void Display(vout_display_t *vd, picture_t *picture, subpicture_t *subpic
const RECT dst = sys->sys.rect_dest_clipped; const RECT dst = sys->sys.rect_dest_clipped;
HRESULT hr; HRESULT hr;
if (sys->d3dctx.use_ex) { if (sys->d3dctx.hd3d.use_ex) {
hr = IDirect3DDevice9Ex_PresentEx(sys->d3dctx.devex, &src, &dst, NULL, NULL, 0); hr = IDirect3DDevice9Ex_PresentEx(p_d3d9_dev->devex, &src, &dst, NULL, NULL, 0);
} else { } else {
hr = IDirect3DDevice9_Present(sys->d3dctx.dev, &src, &dst, NULL, NULL); hr = IDirect3DDevice9_Present(p_d3d9_dev->dev, &src, &dst, NULL, NULL);
} }
if (FAILED(hr)) { if (FAILED(hr)) {
msg_Dbg(vd, "Failed IDirect3DDevice9_Present: 0x%0lx", hr); msg_Dbg(vd, "Failed IDirect3DDevice9_Present: 0x%0lx", hr);
...@@ -768,17 +760,17 @@ static int Direct3D9Create(vlc_object_t *o, struct d3dctx *d3dctx, const video_f ...@@ -768,17 +760,17 @@ static int Direct3D9Create(vlc_object_t *o, struct d3dctx *d3dctx, const video_f
/* Create the D3D object. */ /* Create the D3D object. */
if (OurDirect3DCreate9Ex) { if (OurDirect3DCreate9Ex) {
HRESULT hr = OurDirect3DCreate9Ex(D3D_SDK_VERSION, &d3dctx->objex); HRESULT hr = OurDirect3DCreate9Ex(D3D_SDK_VERSION, &d3dctx->hd3d.objex);
if(!FAILED(hr)) { if(!FAILED(hr)) {
msg_Dbg(o, "Using Direct3D9 Extended API!"); msg_Dbg(o, "Using Direct3D9 Extended API!");
d3dctx->use_ex = true; d3dctx->hd3d.use_ex = true;
} }
} }
if (!d3dctx->obj) if (!d3dctx->hd3d.obj)
{ {
d3dctx->obj = OurDirect3DCreate9(D3D_SDK_VERSION); d3dctx->hd3d.obj = OurDirect3DCreate9(D3D_SDK_VERSION);
if (!d3dctx->obj) { if (!d3dctx->hd3d.obj) {
msg_Err(o, "Could not create Direct3D9 instance."); msg_Err(o, "Could not create Direct3D9 instance.");
goto error; goto error;
} }
...@@ -792,7 +784,7 @@ static int Direct3D9Create(vlc_object_t *o, struct d3dctx *d3dctx, const video_f ...@@ -792,7 +784,7 @@ static int Direct3D9Create(vlc_object_t *o, struct d3dctx *d3dctx, const video_f
** Get device capabilities ** Get device capabilities
*/ */
ZeroMemory(&d3dctx->caps, sizeof(d3dctx->caps)); ZeroMemory(&d3dctx->caps, sizeof(d3dctx->caps));
HRESULT hr = IDirect3D9_GetDeviceCaps(d3dctx->obj, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &d3dctx->caps); HRESULT hr = IDirect3D9_GetDeviceCaps(d3dctx->hd3d.obj, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &d3dctx->caps);
if (FAILED(hr)) { if (FAILED(hr)) {
msg_Err(o, "Could not read adapter capabilities. (hr=0x%0lx)", hr); msg_Err(o, "Could not read adapter capabilities. (hr=0x%0lx)", hr);
goto error; goto error;
...@@ -827,14 +819,14 @@ static void Direct3D9Destroy(vlc_object_t *o, struct d3dctx *d3dctx) ...@@ -827,14 +819,14 @@ static void Direct3D9Destroy(vlc_object_t *o, struct d3dctx *d3dctx)
{ {
VLC_UNUSED(o); VLC_UNUSED(o);
if (d3dctx->obj) if (d3dctx->hd3d.obj)
IDirect3D9_Release(d3dctx->obj); IDirect3D9_Release(d3dctx->hd3d.obj);
if (d3dctx->hdll) if (d3dctx->hdll)
FreeLibrary(d3dctx->hdll); FreeLibrary(d3dctx->hdll);
if (d3dctx->hxdll) if (d3dctx->hxdll)
FreeLibrary(d3dctx->hxdll); FreeLibrary(d3dctx->hxdll);
d3dctx->obj = NULL; d3dctx->hd3d.obj = NULL;
d3dctx->hdll = NULL; d3dctx->hdll = NULL;
d3dctx->hxdll = NULL; d3dctx->hxdll = NULL;
} }
...@@ -844,26 +836,26 @@ static void Direct3D9Destroy(vlc_object_t *o, struct d3dctx *d3dctx) ...@@ -844,26 +836,26 @@ static void Direct3D9Destroy(vlc_object_t *o, struct d3dctx *d3dctx)
* It setup vout_display_sys_t::d3dpp and vout_display_sys_t::rect_display * It setup vout_display_sys_t::d3dpp and vout_display_sys_t::rect_display
* from the default adapter. * from the default adapter.
*/ */
static int Direct3D9FillPresentationParameters(vlc_object_t *o, struct d3dctx *d3dctx, const video_format_t *source) static int Direct3D9FillPresentationParameters(vlc_object_t *o, d3d9_handle_t *hd3d, UINT AdapterToUse, HWND hwnd,
const video_format_t *source, d3d9_device_t *out)
{ {
/* /*
** Get the current desktop display mode, so we can set up a back ** Get the current desktop display mode, so we can set up a back
** buffer of the same format ** buffer of the same format
*/ */
D3DDISPLAYMODE d3ddm; D3DDISPLAYMODE d3ddm;
HRESULT hr = IDirect3D9_GetAdapterDisplayMode(d3dctx->obj, HRESULT hr = IDirect3D9_GetAdapterDisplayMode(hd3d->obj, AdapterToUse, &d3ddm);
D3DADAPTER_DEFAULT, &d3ddm);
if (FAILED(hr)) { if (FAILED(hr)) {
msg_Err(o, "Could not read adapter display mode. (hr=0x%0lx)", hr); msg_Err(o, "Could not read adapter display mode. (hr=0x%0lx)", hr);
return VLC_EGENERIC; return VLC_EGENERIC;
} }
/* Set up the structure used to create the D3DDevice. */ /* Set up the structure used to create the D3DDevice. */
D3DPRESENT_PARAMETERS *d3dpp = &d3dctx->pp; D3DPRESENT_PARAMETERS *d3dpp = &out->pp;
ZeroMemory(d3dpp, sizeof(D3DPRESENT_PARAMETERS)); ZeroMemory(d3dpp, sizeof(D3DPRESENT_PARAMETERS));
d3dpp->Flags = D3DPRESENTFLAG_VIDEO; d3dpp->Flags = D3DPRESENTFLAG_VIDEO;
d3dpp->Windowed = TRUE; d3dpp->Windowed = TRUE;
d3dpp->hDeviceWindow = d3dctx->hwnd; d3dpp->hDeviceWindow = hwnd;
d3dpp->BackBufferWidth = __MAX((unsigned int)GetSystemMetrics(SM_CXVIRTUALSCREEN), d3dpp->BackBufferWidth = __MAX((unsigned int)GetSystemMetrics(SM_CXVIRTUALSCREEN),
source->i_width); source->i_width);
d3dpp->BackBufferHeight = __MAX((unsigned int)GetSystemMetrics(SM_CYVIRTUALSCREEN), d3dpp->BackBufferHeight = __MAX((unsigned int)GetSystemMetrics(SM_CYVIRTUALSCREEN),
...@@ -882,10 +874,11 @@ static int Direct3D9FillPresentationParameters(vlc_object_t *o, struct d3dctx *d ...@@ -882,10 +874,11 @@ static int Direct3D9FillPresentationParameters(vlc_object_t *o, struct d3dctx *d
static int Direct3D9CreateResources (vout_display_t *, video_format_t *); static int Direct3D9CreateResources (vout_display_t *, video_format_t *);
static void Direct3D9DestroyResources(vout_display_t *); static void Direct3D9DestroyResources(vout_display_t *);
static int Direct3D9CreateDevice(vlc_object_t *o, struct d3dctx *d3dctx, const video_format_t *source) static HRESULT D3D9_CreateDevice(vlc_object_t *o, d3d9_handle_t *hd3d, HWND hwnd,
const video_format_t *source, const D3DCAPS9 *caps,
d3d9_device_t *out)
{ {
if (Direct3D9FillPresentationParameters(o, d3dctx, source)) HRESULT hr;
return VLC_EGENERIC;
UINT AdapterToUse = D3DADAPTER_DEFAULT; UINT AdapterToUse = D3DADAPTER_DEFAULT;
D3DDEVTYPE DeviceType = D3DDEVTYPE_HAL; D3DDEVTYPE DeviceType = D3DDEVTYPE_HAL;
...@@ -893,9 +886,9 @@ static int Direct3D9CreateDevice(vlc_object_t *o, struct d3dctx *d3dctx, const v ...@@ -893,9 +886,9 @@ static int Direct3D9CreateDevice(vlc_object_t *o, struct d3dctx *d3dctx, const v
#ifndef NDEBUG #ifndef NDEBUG
// Look for 'NVIDIA PerfHUD' adapter // Look for 'NVIDIA PerfHUD' adapter
// If it is present, override default settings // If it is present, override default settings
for (UINT Adapter=0; Adapter< IDirect3D9_GetAdapterCount(d3dctx->obj); ++Adapter) { for (UINT Adapter=0; Adapter< IDirect3D9_GetAdapterCount(hd3d->obj); ++Adapter) {
D3DADAPTER_IDENTIFIER9 Identifier; D3DADAPTER_IDENTIFIER9 Identifier;
HRESULT Res = IDirect3D9_GetAdapterIdentifier(d3dctx->obj,Adapter,0,&Identifier); HRESULT Res = IDirect3D9_GetAdapterIdentifier(hd3d->obj,Adapter,0,&Identifier);
if (SUCCEEDED(Res) && strstr(Identifier.Description,"PerfHUD") != 0) { if (SUCCEEDED(Res) && strstr(Identifier.Description,"PerfHUD") != 0) {
AdapterToUse = Adapter; AdapterToUse = Adapter;
DeviceType = D3DDEVTYPE_REF; DeviceType = D3DDEVTYPE_REF;
...@@ -904,9 +897,12 @@ static int Direct3D9CreateDevice(vlc_object_t *o, struct d3dctx *d3dctx, const v ...@@ -904,9 +897,12 @@ static int Direct3D9CreateDevice(vlc_object_t *o, struct d3dctx *d3dctx, const v
} }
#endif #endif
if (Direct3D9FillPresentationParameters(o, hd3d, AdapterToUse, hwnd, source, out))
return E_INVALIDARG;
/* */ /* */
D3DADAPTER_IDENTIFIER9 d3dai; D3DADAPTER_IDENTIFIER9 d3dai;
if (FAILED(IDirect3D9_GetAdapterIdentifier(d3dctx->obj, AdapterToUse,0, &d3dai))) { if (FAILED(IDirect3D9_GetAdapterIdentifier(hd3d->obj, AdapterToUse,0, &d3dai))) {
msg_Warn(o, "IDirect3D9_GetAdapterIdentifier failed"); msg_Warn(o, "IDirect3D9_GetAdapterIdentifier failed");
} else { } else {
msg_Dbg(o, "Direct3d9 Device: %s %lu %lu %lu", d3dai.Description, msg_Dbg(o, "Direct3d9 Device: %s %lu %lu %lu", d3dai.Description,
...@@ -914,29 +910,32 @@ static int Direct3D9CreateDevice(vlc_object_t *o, struct d3dctx *d3dctx, const v ...@@ -914,29 +910,32 @@ static int Direct3D9CreateDevice(vlc_object_t *o, struct d3dctx *d3dctx, const v
} }
DWORD creationFlags = D3DCREATE_MULTITHREADED; DWORD creationFlags = D3DCREATE_MULTITHREADED;
if ( (d3dctx->caps.DevCaps & D3DDEVCAPS_DRAWPRIMTLVERTEX) && if ( (caps->DevCaps & D3DDEVCAPS_DRAWPRIMTLVERTEX) &&
(d3dctx->caps.DevCaps & D3DDEVCAPS_HWRASTERIZATION) ) { (caps->DevCaps & D3DDEVCAPS_HWRASTERIZATION) ) {
creationFlags |= D3DCREATE_HARDWARE_VERTEXPROCESSING; creationFlags |= D3DCREATE_HARDWARE_VERTEXPROCESSING;
} else if (d3dctx->caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) { } else if (caps->DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) {
creationFlags |= D3DCREATE_MIXED_VERTEXPROCESSING; creationFlags |= D3DCREATE_MIXED_VERTEXPROCESSING;
} else { } else {
creationFlags |= D3DCREATE_SOFTWARE_VERTEXPROCESSING; creationFlags |= D3DCREATE_SOFTWARE_VERTEXPROCESSING;
} }
// Create the D3DDevice if (hd3d->use_ex)
HRESULT hr; hr = IDirect3D9Ex_CreateDeviceEx(hd3d->objex, AdapterToUse,
if (d3dctx->use_ex) { DeviceType, hwnd,
hr = IDirect3D9Ex_CreateDeviceEx(d3dctx->objex, AdapterToUse,
DeviceType, d3dctx->hwnd,
creationFlags, creationFlags,
&d3dctx->pp, NULL, &d3dctx->devex); &out->pp, NULL, &out->devex);
} else { else
hr = IDirect3D9_CreateDevice(d3dctx->obj, AdapterToUse, hr = IDirect3D9_CreateDevice(hd3d->obj, AdapterToUse,
DeviceType, d3dctx->hwnd, DeviceType, hwnd,
creationFlags, creationFlags,
&d3dctx->pp, &d3dctx->dev); &out->pp, &out->dev);
} return hr;
}
static int Direct3D9CreateDevice(vlc_object_t *o, struct d3dctx *d3dctx, const video_format_t *source)
{
// Create the D3DDevice
HRESULT hr = D3D9_CreateDevice(o, &d3dctx->hd3d, d3dctx->hwnd, source, &d3dctx->caps, &d3dctx->d3d_dev);
return FAILED(hr) ? VLC_EGENERIC : VLC_SUCCESS; return FAILED(hr) ? VLC_EGENERIC : VLC_SUCCESS;
} }
...@@ -944,9 +943,9 @@ static void Direct3D9DestroyDevice(vlc_object_t *o, struct d3dctx *d3dctx) ...@@ -944,9 +943,9 @@ static void Direct3D9DestroyDevice(vlc_object_t *o, struct d3dctx *d3dctx)
{ {
VLC_UNUSED(o); VLC_UNUSED(o);
if (d3dctx->dev) if (d3dctx->d3d_dev.dev)
IDirect3DDevice9_Release(d3dctx->dev); IDirect3DDevice9_Release(d3dctx->d3d_dev.dev);
d3dctx->dev = NULL; d3dctx->d3d_dev.dev = NULL;
} }
/** /**
...@@ -961,19 +960,20 @@ static int Direct3D9Open(vout_display_t *vd, video_format_t *fmt) ...@@ -961,19 +960,20 @@ static int Direct3D9Open(vout_display_t *vd, video_format_t *fmt)
if (Direct3D9CreateDevice(VLC_OBJECT(vd), &sys->d3dctx, &vd->source) != VLC_SUCCESS) if (Direct3D9CreateDevice(VLC_OBJECT(vd), &sys->d3dctx, &vd->source) != VLC_SUCCESS)
return VLC_EGENERIC; return VLC_EGENERIC;
const d3d9_device_t *p_d3d9_dev = &sys->d3dctx.d3d_dev;
/* */ /* */
RECT *display = &vd->sys->sys.rect_display; RECT *display = &vd->sys->sys.rect_display;
display->left = 0; display->left = 0;
display->top = 0; display->top = 0;
display->right = sys->d3dctx.pp.BackBufferWidth; display->right = p_d3d9_dev->pp.BackBufferWidth;
display->bottom = sys->d3dctx.pp.BackBufferHeight; display->bottom = p_d3d9_dev->pp.BackBufferHeight;
*fmt = vd->source; *fmt = vd->source;
/* Find the appropriate D3DFORMAT for the render chroma, the format will be the closest to /* Find the appropriate D3DFORMAT for the render chroma, the format will be the closest to
* the requested chroma which is usable by the hardware in an offscreen surface, as they * the requested chroma which is usable by the hardware in an offscreen surface, as they
* typically support more formats than textures */ * typically support more formats than textures */
const d3d_format_t *d3dfmt = Direct3DFindFormat(vd, fmt->i_chroma, sys->d3dctx.pp.BackBufferFormat); const d3d_format_t *d3dfmt = Direct3DFindFormat(vd, fmt->i_chroma, p_d3d9_dev->pp.BackBufferFormat);
if (!d3dfmt) { if (!d3dfmt) {
msg_Err(vd, "surface pixel format is not supported."); msg_Err(vd, "surface pixel format is not supported.");
goto error; goto error;
...@@ -1019,8 +1019,10 @@ static void Direct3D9Close(vout_display_t *vd) ...@@ -1019,8 +1019,10 @@ static void Direct3D9Close(vout_display_t *vd)
static int Direct3D9Reset(vout_display_t *vd) static int Direct3D9Reset(vout_display_t *vd)
{ {
vout_display_sys_t *sys = vd->sys; vout_display_sys_t *sys = vd->sys;
struct d3dctx *d3dctx = &sys->d3dctx;
d3d9_device_t *p_d3d9_dev = &d3dctx->d3d_dev;
if (Direct3D9FillPresentationParameters(VLC_OBJECT(vd), &sys->d3dctx, &vd->source)) if (Direct3D9FillPresentationParameters(VLC_OBJECT(vd), &d3dctx->hd3d, p_d3d9_dev->adapterId, d3dctx->hwnd, &vd->source, &d3dctx->d3d_dev))
return VLC_EGENERIC; return VLC_EGENERIC;
/* release all D3D objects */ /* release all D3D objects */
...@@ -1028,10 +1030,10 @@ static int Direct3D9Reset(vout_display_t *vd) ...@@ -1028,10 +1030,10 @@ static int Direct3D9Reset(vout_display_t *vd)
/* */ /* */
HRESULT hr; HRESULT hr;
if (sys->d3dctx.use_ex){ if (d3dctx->hd3d.use_ex){
hr = IDirect3DDevice9Ex_ResetEx(sys->d3dctx.devex, &sys->d3dctx.pp, NULL); hr = IDirect3DDevice9Ex_ResetEx(p_d3d9_dev->devex, &p_d3d9_dev->pp, NULL);
} else { } else {
hr = IDirect3DDevice9_Reset(sys->d3dctx.dev, &sys->d3dctx.pp); hr = IDirect3DDevice9_Reset(p_d3d9_dev->dev, &p_d3d9_dev->pp);
} }
if (FAILED(hr)) { if (FAILED(hr)) {
msg_Err(vd, "IDirect3DDevice9_Reset failed! (hr=0x%0lx)", hr); msg_Err(vd, "IDirect3DDevice9_Reset failed! (hr=0x%0lx)", hr);
...@@ -1061,6 +1063,7 @@ static void Direct3D9DestroyShaders(vout_display_t *vd); ...@@ -1061,6 +1063,7 @@ static void Direct3D9DestroyShaders(vout_display_t *vd);
static int Direct3D9CreateResources(vout_display_t *vd, video_format_t *fmt) static int Direct3D9CreateResources(vout_display_t *vd, video_format_t *fmt)
{ {
vout_display_sys_t *sys = vd->sys; vout_display_sys_t *sys = vd->sys;
struct d3dctx *d3dctx = &sys->d3dctx;
if (Direct3D9CreateScene(vd, fmt)) { if (Direct3D9CreateScene(vd, fmt)) {
msg_Err(vd, "Direct3D scene initialization failed !"); msg_Err(vd, "Direct3D scene initialization failed !");
...@@ -1073,15 +1076,15 @@ static int Direct3D9CreateResources(vout_display_t *vd, video_format_t *fmt) ...@@ -1073,15 +1076,15 @@ static int Direct3D9CreateResources(vout_display_t *vd, video_format_t *fmt)
sys->d3dregion_format = D3DFMT_UNKNOWN; sys->d3dregion_format = D3DFMT_UNKNOWN;
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
D3DFORMAT fmt = i == 0 ? D3DFMT_A8B8G8R8 : D3DFMT_A8R8G8B8; D3DFORMAT dfmt = i == 0 ? D3DFMT_A8B8G8R8 : D3DFMT_A8R8G8B8;
if (SUCCEEDED(IDirect3D9_CheckDeviceFormat(sys->d3dctx.obj, if (SUCCEEDED(IDirect3D9_CheckDeviceFormat(d3dctx->hd3d.obj,
D3DADAPTER_DEFAULT, D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL, D3DDEVTYPE_HAL,
sys->d3dctx.pp.BackBufferFormat, d3dctx->d3d_dev.pp.BackBufferFormat,
D3DUSAGE_DYNAMIC, D3DUSAGE_DYNAMIC,
D3DRTYPE_TEXTURE, D3DRTYPE_TEXTURE,
fmt))) { dfmt))) {
sys->d3dregion_format = fmt; sys->d3dregion_format = dfmt;
break; break;
} }
} }
...@@ -1108,7 +1111,7 @@ static int Direct3D9CheckConversion(vout_display_t *vd, ...@@ -1108,7 +1111,7 @@ static int Direct3D9CheckConversion(vout_display_t *vd,
D3DFORMAT src, D3DFORMAT dst) D3DFORMAT src, D3DFORMAT dst)
{ {
vout_display_sys_t *sys = vd->sys; vout_display_sys_t *sys = vd->sys;
LPDIRECT3D9 d3dobj = sys->d3dctx.obj; LPDIRECT3D9 d3dobj = sys->d3dctx.hd3d.obj;
HRESULT hr; HRESULT hr;
/* test whether device can create a surface of that format */ /* test whether device can create a surface of that format */
...@@ -1199,7 +1202,8 @@ static const d3d_format_t *Direct3DFindFormat(vout_display_t *vd, vlc_fourcc_t c ...@@ -1199,7 +1202,8 @@ static const d3d_format_t *Direct3DFindFormat(vout_display_t *vd, vlc_fourcc_t c
static int Direct3D9CreateScene(vout_display_t *vd, const video_format_t *fmt) static int Direct3D9CreateScene(vout_display_t *vd, const video_format_t *fmt)
{ {
vout_display_sys_t *sys = vd->sys; vout_display_sys_t *sys = vd->sys;
LPDIRECT3DDEVICE9 d3ddev = sys->d3dctx.dev; const d3d9_device_t *p_d3d9_dev = &sys->d3dctx.d3d_dev;
LPDIRECT3DDEVICE9 d3ddev = p_d3d9_dev->dev;
HRESULT hr; HRESULT hr;
/* /*
...@@ -1213,7 +1217,7 @@ static int Direct3D9CreateScene(vout_display_t *vd, const video_format_t *fmt) ...@@ -1213,7 +1217,7 @@ static int Direct3D9CreateScene(vout_display_t *vd, const video_format_t *fmt)
fmt->i_height, fmt->i_height,
1, 1,
D3DUSAGE_RENDERTARGET, D3DUSAGE_RENDERTARGET,
sys->d3dctx.pp.BackBufferFormat, p_d3d9_dev->pp.BackBufferFormat,
D3DPOOL_DEFAULT, D3DPOOL_DEFAULT,
&d3dtex, &d3dtex,
NULL); NULL);
...@@ -1381,7 +1385,7 @@ static int Direct3D9CompileShader(vout_display_t *vd, const char *shader_source, ...@@ -1381,7 +1385,7 @@ static int Direct3D9CompileShader(vout_display_t *vd, const char *shader_source,
return VLC_EGENERIC; return VLC_EGENERIC;
} }
hr = IDirect3DDevice9_CreatePixelShader(sys->d3dctx.dev, hr = IDirect3DDevice9_CreatePixelShader(sys->d3dctx.d3d_dev.dev,
ID3DXBuffer_GetBufferPointer(compiled_shader), ID3DXBuffer_GetBufferPointer(compiled_shader),
&sys->d3dx_shader); &sys->d3dx_shader);
...@@ -1641,7 +1645,7 @@ static int Direct3D9ImportPicture(vout_display_t *vd, ...@@ -1641,7 +1645,7 @@ static int Direct3D9ImportPicture(vout_display_t *vd,
if ( copy_rect.left & 1 ) copy_rect.left--; if ( copy_rect.left & 1 ) copy_rect.left--;
if ( copy_rect.bottom & 1 ) copy_rect.bottom++; if ( copy_rect.bottom & 1 ) copy_rect.bottom++;
if ( copy_rect.top & 1 ) copy_rect.top--; if ( copy_rect.top & 1 ) copy_rect.top--;
hr = IDirect3DDevice9_StretchRect(sys->d3dctx.dev, source, &copy_rect, destination, hr = IDirect3DDevice9_StretchRect(sys->d3dctx.d3d_dev.dev, source, &copy_rect, destination,
&copy_rect, D3DTEXF_NONE); &copy_rect, D3DTEXF_NONE);
IDirect3DSurface9_Release(destination); IDirect3DSurface9_Release(destination);
if (FAILED(hr)) { if (FAILED(hr)) {
...@@ -1704,7 +1708,7 @@ static void Direct3D9ImportSubpicture(vout_display_t *vd, ...@@ -1704,7 +1708,7 @@ static void Direct3D9ImportSubpicture(vout_display_t *vd,
d3dr->format = sys->d3dregion_format; d3dr->format = sys->d3dregion_format;
d3dr->width = r->fmt.i_width; d3dr->width = r->fmt.i_width;
d3dr->height = r->fmt.i_height; d3dr->height = r->fmt.i_height;
hr = IDirect3DDevice9_CreateTexture(sys->d3dctx.dev, hr = IDirect3DDevice9_CreateTexture(sys->d3dctx.d3d_dev.dev,
d3dr->width, d3dr->height, d3dr->width, d3dr->height,
1, 1,
D3DUSAGE_DYNAMIC, D3DUSAGE_DYNAMIC,
...@@ -1793,7 +1797,7 @@ static int Direct3D9RenderRegion(vout_display_t *vd, ...@@ -1793,7 +1797,7 @@ static int Direct3D9RenderRegion(vout_display_t *vd,
{ {
vout_display_sys_t *sys = vd->sys; vout_display_sys_t *sys = vd->sys;
LPDIRECT3DDEVICE9 d3ddev = vd->sys->d3dctx.dev; LPDIRECT3DDEVICE9 d3ddev = vd->sys->d3dctx.d3d_dev.dev;
LPDIRECT3DVERTEXBUFFER9 d3dvtc = sys->d3dvtc; LPDIRECT3DVERTEXBUFFER9 d3dvtc = sys->d3dvtc;
LPDIRECT3DTEXTURE9 d3dtex = region->texture; LPDIRECT3DTEXTURE9 d3dtex = region->texture;
...@@ -1878,7 +1882,7 @@ static void Direct3D9RenderScene(vout_display_t *vd, ...@@ -1878,7 +1882,7 @@ static void Direct3D9RenderScene(vout_display_t *vd,
d3d_region_t *subpicture) d3d_region_t *subpicture)
{ {
vout_display_sys_t *sys = vd->sys; vout_display_sys_t *sys = vd->sys;
LPDIRECT3DDEVICE9 d3ddev = sys->d3dctx.dev; LPDIRECT3DDEVICE9 d3ddev = sys->d3dctx.d3d_dev.dev;
HRESULT hr; HRESULT hr;
if (sys->clear_scene) { if (sys->clear_scene) {
...@@ -2025,7 +2029,7 @@ GLConvUpdate(const opengl_tex_converter_t *tc, GLuint *textures, ...@@ -2025,7 +2029,7 @@ GLConvUpdate(const opengl_tex_converter_t *tc, GLuint *textures,
.right = pic->format.i_visible_width, .right = pic->format.i_visible_width,
.bottom = pic->format.i_visible_height .bottom = pic->format.i_visible_height
}; };
hr = IDirect3DDevice9Ex_StretchRect(priv->d3dctx.devex, picsys->surface, hr = IDirect3DDevice9Ex_StretchRect(priv->d3dctx.d3d_dev.devex, picsys->surface,
&rect, priv->dx_render, NULL, D3DTEXF_NONE);