d3d9: Add a separate function for device initialization.
This commit is contained in:
parent
99d9983b61
commit
b9243b721a
|
@ -158,16 +158,6 @@ typedef struct IDirect3D9Impl
|
|||
|
||||
void filter_caps(D3DCAPS9* pCaps) DECLSPEC_HIDDEN;
|
||||
|
||||
/* ---------------- */
|
||||
/* IDirect3DDevice9 */
|
||||
/* ---------------- */
|
||||
|
||||
/*****************************************************************************
|
||||
* Predeclare the interface implementation structures
|
||||
*/
|
||||
extern const IDirect3DDevice9ExVtbl Direct3DDevice9_Vtbl DECLSPEC_HIDDEN;
|
||||
extern const IWineD3DDeviceParentVtbl d3d9_wined3d_device_parent_vtbl DECLSPEC_HIDDEN;
|
||||
|
||||
/*****************************************************************************
|
||||
* IDirect3DDevice9 implementation structure
|
||||
*/
|
||||
|
@ -190,6 +180,8 @@ typedef struct IDirect3DDevice9Impl
|
|||
BOOL notreset;
|
||||
} IDirect3DDevice9Impl;
|
||||
|
||||
HRESULT device_init(IDirect3DDevice9Impl *device, IWineD3D *wined3d, UINT adapter, D3DDEVTYPE device_type,
|
||||
HWND focus_window, DWORD flags, D3DPRESENT_PARAMETERS *parameters) DECLSPEC_HIDDEN;
|
||||
|
||||
/* IDirect3DDevice9: */
|
||||
extern HRESULT WINAPI IDirect3DDevice9Impl_CreateAdditionalSwapChain(IDirect3DDevice9Ex *iface,
|
||||
|
|
|
@ -2273,7 +2273,7 @@ static HRESULT WINAPI IDirect3DDevice9ExImpl_GetDisplayModeEx(IDirect3DDevice9
|
|||
return WINED3DERR_INVALIDCALL;
|
||||
}
|
||||
|
||||
const IDirect3DDevice9ExVtbl Direct3DDevice9_Vtbl =
|
||||
static const IDirect3DDevice9ExVtbl Direct3DDevice9_Vtbl =
|
||||
{
|
||||
/* IUnknown */
|
||||
IDirect3DDevice9Impl_QueryInterface,
|
||||
|
@ -2645,7 +2645,7 @@ static HRESULT STDMETHODCALLTYPE device_parent_CreateSwapChain(IWineD3DDevicePar
|
|||
return hr;
|
||||
}
|
||||
|
||||
const IWineD3DDeviceParentVtbl d3d9_wined3d_device_parent_vtbl =
|
||||
static const IWineD3DDeviceParentVtbl d3d9_wined3d_device_parent_vtbl =
|
||||
{
|
||||
/* IUnknown methods */
|
||||
device_parent_QueryInterface,
|
||||
|
@ -2659,3 +2659,111 @@ const IWineD3DDeviceParentVtbl d3d9_wined3d_device_parent_vtbl =
|
|||
device_parent_CreateVolume,
|
||||
device_parent_CreateSwapChain,
|
||||
};
|
||||
|
||||
HRESULT device_init(IDirect3DDevice9Impl *device, IWineD3D *wined3d, UINT adapter, D3DDEVTYPE device_type,
|
||||
HWND focus_window, DWORD flags, D3DPRESENT_PARAMETERS *parameters)
|
||||
{
|
||||
WINED3DPRESENT_PARAMETERS *wined3d_parameters;
|
||||
UINT i, count = 1;
|
||||
HRESULT hr;
|
||||
|
||||
device->lpVtbl = &Direct3DDevice9_Vtbl;
|
||||
device->device_parent_vtbl = &d3d9_wined3d_device_parent_vtbl;
|
||||
device->ref = 1;
|
||||
|
||||
wined3d_mutex_lock();
|
||||
hr = IWineD3D_CreateDevice(wined3d, adapter, device_type, focus_window, flags, (IUnknown *)device,
|
||||
(IWineD3DDeviceParent *)&device->device_parent_vtbl, &device->WineD3DDevice);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
WARN("Failed to create wined3d device, hr %#x.\n", hr);
|
||||
wined3d_mutex_unlock();
|
||||
return hr;
|
||||
}
|
||||
|
||||
if (flags & D3DCREATE_ADAPTERGROUP_DEVICE)
|
||||
{
|
||||
WINED3DCAPS caps;
|
||||
|
||||
IWineD3D_GetDeviceCaps(wined3d, adapter, device_type, &caps);
|
||||
count = caps.NumberOfAdaptersInGroup;
|
||||
}
|
||||
|
||||
if (flags & D3DCREATE_MULTITHREADED) IWineD3DDevice_SetMultithreaded(device->WineD3DDevice);
|
||||
|
||||
wined3d_parameters = HeapAlloc(GetProcessHeap(), 0, sizeof(*wined3d_parameters) * count);
|
||||
if (!wined3d_parameters)
|
||||
{
|
||||
ERR("Failed to allocate wined3d parameters.\n");
|
||||
IWineD3DDevice_Release(device->WineD3DDevice);
|
||||
wined3d_mutex_unlock();
|
||||
return E_OUTOFMEMORY;
|
||||
}
|
||||
|
||||
for (i = 0; i < count; ++i)
|
||||
{
|
||||
wined3d_parameters[i].BackBufferWidth = parameters[i].BackBufferWidth;
|
||||
wined3d_parameters[i].BackBufferHeight = parameters[i].BackBufferHeight;
|
||||
wined3d_parameters[i].BackBufferFormat = wined3dformat_from_d3dformat(parameters[i].BackBufferFormat);
|
||||
wined3d_parameters[i].BackBufferCount = parameters[i].BackBufferCount;
|
||||
wined3d_parameters[i].MultiSampleType = parameters[i].MultiSampleType;
|
||||
wined3d_parameters[i].MultiSampleQuality = parameters[i].MultiSampleQuality;
|
||||
wined3d_parameters[i].SwapEffect = parameters[i].SwapEffect;
|
||||
wined3d_parameters[i].hDeviceWindow = parameters[i].hDeviceWindow;
|
||||
wined3d_parameters[i].Windowed = parameters[i].Windowed;
|
||||
wined3d_parameters[i].EnableAutoDepthStencil = parameters[i].EnableAutoDepthStencil;
|
||||
wined3d_parameters[i].AutoDepthStencilFormat =
|
||||
wined3dformat_from_d3dformat(parameters[i].AutoDepthStencilFormat);
|
||||
wined3d_parameters[i].Flags = parameters[i].Flags;
|
||||
wined3d_parameters[i].FullScreen_RefreshRateInHz = parameters[i].FullScreen_RefreshRateInHz;
|
||||
wined3d_parameters[i].PresentationInterval = parameters[i].PresentationInterval;
|
||||
wined3d_parameters[i].AutoRestoreDisplayMode = TRUE;
|
||||
}
|
||||
|
||||
hr = IWineD3DDevice_Init3D(device->WineD3DDevice, wined3d_parameters);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
WARN("Failed to initialize 3D, hr %#x.\n", hr);
|
||||
HeapFree(GetProcessHeap(), 0, wined3d_parameters);
|
||||
IWineD3DDevice_Release(device->WineD3DDevice);
|
||||
wined3d_mutex_unlock();
|
||||
return hr;
|
||||
}
|
||||
|
||||
wined3d_mutex_unlock();
|
||||
|
||||
for (i = 0; i < count; ++i)
|
||||
{
|
||||
parameters[i].BackBufferWidth = wined3d_parameters[i].BackBufferWidth;
|
||||
parameters[i].BackBufferHeight = wined3d_parameters[i].BackBufferHeight;
|
||||
parameters[i].BackBufferFormat = d3dformat_from_wined3dformat(wined3d_parameters[i].BackBufferFormat);
|
||||
parameters[i].BackBufferCount = wined3d_parameters[i].BackBufferCount;
|
||||
parameters[i].MultiSampleType = wined3d_parameters[i].MultiSampleType;
|
||||
parameters[i].MultiSampleQuality = wined3d_parameters[i].MultiSampleQuality;
|
||||
parameters[i].SwapEffect = wined3d_parameters[i].SwapEffect;
|
||||
parameters[i].hDeviceWindow = wined3d_parameters[i].hDeviceWindow;
|
||||
parameters[i].Windowed = wined3d_parameters[i].Windowed;
|
||||
parameters[i].EnableAutoDepthStencil = wined3d_parameters[i].EnableAutoDepthStencil;
|
||||
parameters[i].AutoDepthStencilFormat =
|
||||
d3dformat_from_wined3dformat(wined3d_parameters[i].AutoDepthStencilFormat);
|
||||
parameters[i].Flags = wined3d_parameters[i].Flags;
|
||||
parameters[i].FullScreen_RefreshRateInHz = wined3d_parameters[i].FullScreen_RefreshRateInHz;
|
||||
parameters[i].PresentationInterval = wined3d_parameters[i].PresentationInterval;
|
||||
}
|
||||
HeapFree(GetProcessHeap(), 0, wined3d_parameters);
|
||||
|
||||
/* Initialize the converted declaration array. This creates a valid pointer
|
||||
* and when adding decls HeapReAlloc() can be used without further checking. */
|
||||
device->convertedDecls = HeapAlloc(GetProcessHeap(), 0, 0);
|
||||
if (!device->convertedDecls)
|
||||
{
|
||||
ERR("Failed to allocate FVF vertex declaration map memory.\n");
|
||||
wined3d_mutex_lock();
|
||||
IWineD3DDevice_Uninit3D(device->WineD3DDevice, D3D9CB_DestroySwapChain);
|
||||
IWineD3DDevice_Release(device->WineD3DDevice);
|
||||
wined3d_mutex_unlock();
|
||||
return E_OUTOFMEMORY;
|
||||
}
|
||||
|
||||
return D3D_OK;
|
||||
}
|
||||
|
|
|
@ -417,119 +417,36 @@ ULONG WINAPI D3D9CB_DestroySwapChain(IWineD3DSwapChain *pSwapChain) {
|
|||
return IDirect3DSwapChain9_Release((IDirect3DSwapChain9*) swapChainParent);
|
||||
}
|
||||
|
||||
static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3D9Impl_CreateDevice(LPDIRECT3D9EX iface, UINT Adapter, D3DDEVTYPE DeviceType,
|
||||
HWND hFocusWindow, DWORD BehaviourFlags,
|
||||
D3DPRESENT_PARAMETERS* pPresentationParameters,
|
||||
IDirect3DDevice9** ppReturnedDeviceInterface) {
|
||||
|
||||
IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
|
||||
IDirect3DDevice9Impl *object = NULL;
|
||||
WINED3DPRESENT_PARAMETERS *localParameters;
|
||||
UINT i, count = 1;
|
||||
static HRESULT WINAPI DECLSPEC_HOTPATCH IDirect3D9Impl_CreateDevice(IDirect3D9Ex *iface, UINT adapter,
|
||||
D3DDEVTYPE device_type, HWND focus_window, DWORD flags, D3DPRESENT_PARAMETERS *parameters,
|
||||
IDirect3DDevice9 **device)
|
||||
{
|
||||
IDirect3D9Impl *This = (IDirect3D9Impl *)iface;
|
||||
IDirect3DDevice9Impl *object;
|
||||
HRESULT hr;
|
||||
|
||||
TRACE("iface %p, adapter %u, device_type %#x, focus_window %p, flags %#x, parameters %p, device %p.\n",
|
||||
iface, Adapter, DeviceType, hFocusWindow, BehaviourFlags, pPresentationParameters,
|
||||
ppReturnedDeviceInterface);
|
||||
iface, adapter, device_type, focus_window, flags, parameters, device);
|
||||
|
||||
/* Check the validity range of the adapter parameter */
|
||||
if (Adapter >= IDirect3D9Impl_GetAdapterCount(iface)) {
|
||||
*ppReturnedDeviceInterface = NULL;
|
||||
return D3DERR_INVALIDCALL;
|
||||
object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
|
||||
if (!object)
|
||||
{
|
||||
ERR("Failed to allocate device memory.\n");
|
||||
return E_OUTOFMEMORY;
|
||||
}
|
||||
|
||||
/* Allocate the storage for the device object */
|
||||
object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DDevice9Impl));
|
||||
if (NULL == object) {
|
||||
FIXME("Allocation of memory failed\n");
|
||||
*ppReturnedDeviceInterface = NULL;
|
||||
return D3DERR_OUTOFVIDEOMEMORY;
|
||||
}
|
||||
|
||||
object->lpVtbl = &Direct3DDevice9_Vtbl;
|
||||
object->device_parent_vtbl = &d3d9_wined3d_device_parent_vtbl;
|
||||
object->ref = 1;
|
||||
*ppReturnedDeviceInterface = (IDirect3DDevice9 *)object;
|
||||
|
||||
/* Allocate an associated WineD3DDevice object */
|
||||
wined3d_mutex_lock();
|
||||
hr = IWineD3D_CreateDevice(This->WineD3D, Adapter, DeviceType, hFocusWindow, BehaviourFlags,
|
||||
(IUnknown *)object, (IWineD3DDeviceParent *)&object->device_parent_vtbl, &object->WineD3DDevice);
|
||||
if (hr != D3D_OK) {
|
||||
hr = device_init(object, This->WineD3D, adapter, device_type, focus_window, flags, parameters);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
WARN("Failed to initialize device, hr %#x.\n", hr);
|
||||
HeapFree(GetProcessHeap(), 0, object);
|
||||
*ppReturnedDeviceInterface = NULL;
|
||||
wined3d_mutex_unlock();
|
||||
|
||||
return hr;
|
||||
}
|
||||
|
||||
TRACE("(%p) : Created Device %p\n", This, object);
|
||||
TRACE("Created device %p.\n", object);
|
||||
*device = (IDirect3DDevice9 *)object;
|
||||
|
||||
if (BehaviourFlags & D3DCREATE_ADAPTERGROUP_DEVICE)
|
||||
{
|
||||
WINED3DCAPS caps;
|
||||
|
||||
IWineD3D_GetDeviceCaps(This->WineD3D, Adapter, DeviceType, &caps);
|
||||
count = caps.NumberOfAdaptersInGroup;
|
||||
}
|
||||
|
||||
if(BehaviourFlags & D3DCREATE_MULTITHREADED) {
|
||||
IWineD3DDevice_SetMultithreaded(object->WineD3DDevice);
|
||||
}
|
||||
|
||||
localParameters = HeapAlloc(GetProcessHeap(), 0, sizeof(*localParameters) * count);
|
||||
for (i = 0; i < count; ++i)
|
||||
{
|
||||
localParameters[i].BackBufferWidth = pPresentationParameters[i].BackBufferWidth;
|
||||
localParameters[i].BackBufferHeight = pPresentationParameters[i].BackBufferHeight;
|
||||
localParameters[i].BackBufferFormat = wined3dformat_from_d3dformat(pPresentationParameters[i].BackBufferFormat);
|
||||
localParameters[i].BackBufferCount = pPresentationParameters[i].BackBufferCount;
|
||||
localParameters[i].MultiSampleType = pPresentationParameters[i].MultiSampleType;
|
||||
localParameters[i].MultiSampleQuality = pPresentationParameters[i].MultiSampleQuality;
|
||||
localParameters[i].SwapEffect = pPresentationParameters[i].SwapEffect;
|
||||
localParameters[i].hDeviceWindow = pPresentationParameters[i].hDeviceWindow;
|
||||
localParameters[i].Windowed = pPresentationParameters[i].Windowed;
|
||||
localParameters[i].EnableAutoDepthStencil = pPresentationParameters[i].EnableAutoDepthStencil;
|
||||
localParameters[i].AutoDepthStencilFormat = wined3dformat_from_d3dformat(pPresentationParameters[i].AutoDepthStencilFormat);
|
||||
localParameters[i].Flags = pPresentationParameters[i].Flags;
|
||||
localParameters[i].FullScreen_RefreshRateInHz = pPresentationParameters[i].FullScreen_RefreshRateInHz;
|
||||
localParameters[i].PresentationInterval = pPresentationParameters[i].PresentationInterval;
|
||||
localParameters[i].AutoRestoreDisplayMode = TRUE;
|
||||
}
|
||||
|
||||
hr = IWineD3DDevice_Init3D(object->WineD3DDevice, localParameters);
|
||||
if (hr != D3D_OK) {
|
||||
FIXME("(%p) D3D Initialization failed for WineD3DDevice %p\n", This, object->WineD3DDevice);
|
||||
HeapFree(GetProcessHeap(), 0, object);
|
||||
*ppReturnedDeviceInterface = NULL;
|
||||
}
|
||||
|
||||
for (i = 0; i < count; ++i)
|
||||
{
|
||||
pPresentationParameters[i].BackBufferWidth = localParameters[i].BackBufferWidth;
|
||||
pPresentationParameters[i].BackBufferHeight = localParameters[i].BackBufferHeight;
|
||||
pPresentationParameters[i].BackBufferFormat = d3dformat_from_wined3dformat(localParameters[i].BackBufferFormat);
|
||||
pPresentationParameters[i].BackBufferCount = localParameters[i].BackBufferCount;
|
||||
pPresentationParameters[i].MultiSampleType = localParameters[i].MultiSampleType;
|
||||
pPresentationParameters[i].MultiSampleQuality = localParameters[i].MultiSampleQuality;
|
||||
pPresentationParameters[i].SwapEffect = localParameters[i].SwapEffect;
|
||||
pPresentationParameters[i].hDeviceWindow = localParameters[i].hDeviceWindow;
|
||||
pPresentationParameters[i].Windowed = localParameters[i].Windowed;
|
||||
pPresentationParameters[i].EnableAutoDepthStencil = localParameters[i].EnableAutoDepthStencil;
|
||||
pPresentationParameters[i].AutoDepthStencilFormat = d3dformat_from_wined3dformat(localParameters[i].AutoDepthStencilFormat);
|
||||
pPresentationParameters[i].Flags = localParameters[i].Flags;
|
||||
pPresentationParameters[i].FullScreen_RefreshRateInHz = localParameters[i].FullScreen_RefreshRateInHz;
|
||||
pPresentationParameters[i].PresentationInterval = localParameters[i].PresentationInterval;
|
||||
}
|
||||
HeapFree(GetProcessHeap(), 0, localParameters);
|
||||
|
||||
/* Initialize the converted declaration array. This creates a valid pointer and when adding decls HeapReAlloc
|
||||
* can be used without further checking
|
||||
*/
|
||||
object->convertedDecls = HeapAlloc(GetProcessHeap(), 0, 0);
|
||||
wined3d_mutex_unlock();
|
||||
|
||||
return hr;
|
||||
return D3D_OK;
|
||||
}
|
||||
|
||||
static UINT WINAPI IDirect3D9ExImpl_GetAdapterModeCountEx(IDirect3D9Ex *iface,
|
||||
|
|
Loading…
Reference in New Issue