Commit 2e27ab6b authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

d3d8: Add a separate function for swapchain initialization.

parent ecbe545e
...@@ -227,11 +227,6 @@ HRESULT volume_init(IDirect3DVolume8Impl *volume, IDirect3DDevice8Impl *device, ...@@ -227,11 +227,6 @@ HRESULT volume_init(IDirect3DVolume8Impl *volume, IDirect3DDevice8Impl *device,
/* ------------------- */ /* ------------------- */
/***************************************************************************** /*****************************************************************************
* Predeclare the interface implementation structures
*/
extern const IDirect3DSwapChain8Vtbl Direct3DSwapChain8_Vtbl DECLSPEC_HIDDEN;
/*****************************************************************************
* IDirect3DSwapChain8 implementation structure * IDirect3DSwapChain8 implementation structure
*/ */
struct IDirect3DSwapChain8Impl struct IDirect3DSwapChain8Impl
...@@ -247,6 +242,9 @@ struct IDirect3DSwapChain8Impl ...@@ -247,6 +242,9 @@ struct IDirect3DSwapChain8Impl
LPDIRECT3DDEVICE8 parentDevice; LPDIRECT3DDEVICE8 parentDevice;
}; };
HRESULT swapchain_init(IDirect3DSwapChain8Impl *swapchain, IDirect3DDevice8Impl *device,
D3DPRESENT_PARAMETERS *present_parameters) DECLSPEC_HIDDEN;
/* ----------------- */ /* ----------------- */
/* IDirect3DSurface8 */ /* IDirect3DSurface8 */
/* ----------------- */ /* ----------------- */
......
...@@ -495,76 +495,35 @@ static BOOL WINAPI IDirect3DDevice8Impl_ShowCursor(LPDIRECT3DDEVICE8 iface, BOOL ...@@ -495,76 +495,35 @@ static BOOL WINAPI IDirect3DDevice8Impl_ShowCursor(LPDIRECT3DDEVICE8 iface, BOOL
return ret; return ret;
} }
static HRESULT WINAPI IDirect3DDevice8Impl_CreateAdditionalSwapChain(LPDIRECT3DDEVICE8 iface, D3DPRESENT_PARAMETERS* pPresentationParameters, IDirect3DSwapChain8** pSwapChain) { static HRESULT WINAPI IDirect3DDevice8Impl_CreateAdditionalSwapChain(IDirect3DDevice8 *iface,
D3DPRESENT_PARAMETERS *present_parameters, IDirect3DSwapChain8 **swapchain)
{
IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface; IDirect3DDevice8Impl *This = (IDirect3DDevice8Impl *)iface;
IDirect3DSwapChain8Impl* object; IDirect3DSwapChain8Impl *object;
HRESULT hrc = D3D_OK; HRESULT hr;
WINED3DPRESENT_PARAMETERS localParameters;
TRACE("iface %p, present_parameters %p, swapchain %p.\n", TRACE("iface %p, present_parameters %p, swapchain %p.\n",
iface, pPresentationParameters, pSwapChain); iface, present_parameters, swapchain);
/* Fix the back buffer count */
if(pPresentationParameters->BackBufferCount == 0) {
pPresentationParameters->BackBufferCount = 1;
}
object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object)); object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
if (NULL == object) { if (!object)
FIXME("Allocation of memory failed\n"); {
*pSwapChain = NULL; ERR("Failed to allocate swapchain memory.\n");
return D3DERR_OUTOFVIDEOMEMORY; return E_OUTOFMEMORY;
} }
object->ref = 1;
object->lpVtbl = &Direct3DSwapChain8_Vtbl;
/* Allocate an associated WineD3DDevice object */
localParameters.BackBufferWidth = pPresentationParameters->BackBufferWidth;
localParameters.BackBufferHeight = pPresentationParameters->BackBufferHeight;
localParameters.BackBufferFormat = wined3dformat_from_d3dformat(pPresentationParameters->BackBufferFormat);
localParameters.BackBufferCount = pPresentationParameters->BackBufferCount;
localParameters.MultiSampleType = pPresentationParameters->MultiSampleType;
localParameters.MultiSampleQuality = 0; /* d3d9 only */
localParameters.SwapEffect = pPresentationParameters->SwapEffect;
localParameters.hDeviceWindow = pPresentationParameters->hDeviceWindow;
localParameters.Windowed = pPresentationParameters->Windowed;
localParameters.EnableAutoDepthStencil = pPresentationParameters->EnableAutoDepthStencil;
localParameters.AutoDepthStencilFormat = wined3dformat_from_d3dformat(pPresentationParameters->AutoDepthStencilFormat);
localParameters.Flags = pPresentationParameters->Flags;
localParameters.FullScreen_RefreshRateInHz = pPresentationParameters->FullScreen_RefreshRateInHz;
localParameters.PresentationInterval = pPresentationParameters->FullScreen_PresentationInterval;
localParameters.AutoRestoreDisplayMode = TRUE;
wined3d_mutex_lock(); hr = swapchain_init(object, This, present_parameters);
hrc = IWineD3DDevice_CreateSwapChain(This->WineD3DDevice, &localParameters, if (FAILED(hr))
&object->wineD3DSwapChain, (IUnknown *)object, SURFACE_OPENGL); {
wined3d_mutex_unlock(); WARN("Failed to initialize swapchain, hr %#x.\n", hr);
HeapFree(GetProcessHeap(), 0, object);
return hr;
}
pPresentationParameters->BackBufferWidth = localParameters.BackBufferWidth; TRACE("Created swapchain %p.\n", object);
pPresentationParameters->BackBufferHeight = localParameters.BackBufferHeight; *swapchain = (IDirect3DSwapChain8 *)object;
pPresentationParameters->BackBufferFormat = d3dformat_from_wined3dformat(localParameters.BackBufferFormat);
pPresentationParameters->BackBufferCount = localParameters.BackBufferCount;
pPresentationParameters->MultiSampleType = localParameters.MultiSampleType;
pPresentationParameters->SwapEffect = localParameters.SwapEffect;
pPresentationParameters->hDeviceWindow = localParameters.hDeviceWindow;
pPresentationParameters->Windowed = localParameters.Windowed;
pPresentationParameters->EnableAutoDepthStencil = localParameters.EnableAutoDepthStencil;
pPresentationParameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(localParameters.AutoDepthStencilFormat);
pPresentationParameters->Flags = localParameters.Flags;
pPresentationParameters->FullScreen_RefreshRateInHz = localParameters.FullScreen_RefreshRateInHz;
pPresentationParameters->FullScreen_PresentationInterval = localParameters.PresentationInterval;
if (hrc != D3D_OK) { return D3D_OK;
FIXME("(%p) call to IWineD3DDevice_CreateSwapChain failed\n", This);
HeapFree(GetProcessHeap(), 0 , object);
*pSwapChain = NULL;
}else{
IUnknown_AddRef(iface);
object->parentDevice = iface;
*pSwapChain = (IDirect3DSwapChain8 *)object;
}
TRACE("(%p) returning %p\n", This, *pSwapChain);
return hrc;
} }
static HRESULT WINAPI IDirect3DDevice8Impl_Reset(LPDIRECT3DDEVICE8 iface, D3DPRESENT_PARAMETERS* pPresentationParameters) { static HRESULT WINAPI IDirect3DDevice8Impl_Reset(LPDIRECT3DDEVICE8 iface, D3DPRESENT_PARAMETERS* pPresentationParameters) {
......
...@@ -102,7 +102,7 @@ static HRESULT WINAPI IDirect3DSwapChain8Impl_GetBackBuffer(LPDIRECT3DSWAPCHAIN8 ...@@ -102,7 +102,7 @@ static HRESULT WINAPI IDirect3DSwapChain8Impl_GetBackBuffer(LPDIRECT3DSWAPCHAIN8
return hrc; return hrc;
} }
const IDirect3DSwapChain8Vtbl Direct3DSwapChain8_Vtbl = static const IDirect3DSwapChain8Vtbl Direct3DSwapChain8_Vtbl =
{ {
IDirect3DSwapChain8Impl_QueryInterface, IDirect3DSwapChain8Impl_QueryInterface,
IDirect3DSwapChain8Impl_AddRef, IDirect3DSwapChain8Impl_AddRef,
...@@ -110,3 +110,59 @@ const IDirect3DSwapChain8Vtbl Direct3DSwapChain8_Vtbl = ...@@ -110,3 +110,59 @@ const IDirect3DSwapChain8Vtbl Direct3DSwapChain8_Vtbl =
IDirect3DSwapChain8Impl_Present, IDirect3DSwapChain8Impl_Present,
IDirect3DSwapChain8Impl_GetBackBuffer IDirect3DSwapChain8Impl_GetBackBuffer
}; };
HRESULT swapchain_init(IDirect3DSwapChain8Impl *swapchain, IDirect3DDevice8Impl *device,
D3DPRESENT_PARAMETERS *present_parameters)
{
WINED3DPRESENT_PARAMETERS wined3d_parameters;
HRESULT hr;
swapchain->ref = 1;
swapchain->lpVtbl = &Direct3DSwapChain8_Vtbl;
wined3d_parameters.BackBufferWidth = present_parameters->BackBufferWidth;
wined3d_parameters.BackBufferHeight = present_parameters->BackBufferHeight;
wined3d_parameters.BackBufferFormat = wined3dformat_from_d3dformat(present_parameters->BackBufferFormat);
wined3d_parameters.BackBufferCount = max(1, present_parameters->BackBufferCount);
wined3d_parameters.MultiSampleType = present_parameters->MultiSampleType;
wined3d_parameters.MultiSampleQuality = 0; /* d3d9 only */
wined3d_parameters.SwapEffect = present_parameters->SwapEffect;
wined3d_parameters.hDeviceWindow = present_parameters->hDeviceWindow;
wined3d_parameters.Windowed = present_parameters->Windowed;
wined3d_parameters.EnableAutoDepthStencil = present_parameters->EnableAutoDepthStencil;
wined3d_parameters.AutoDepthStencilFormat = wined3dformat_from_d3dformat(present_parameters->AutoDepthStencilFormat);
wined3d_parameters.Flags = present_parameters->Flags;
wined3d_parameters.FullScreen_RefreshRateInHz = present_parameters->FullScreen_RefreshRateInHz;
wined3d_parameters.PresentationInterval = present_parameters->FullScreen_PresentationInterval;
wined3d_parameters.AutoRestoreDisplayMode = TRUE;
wined3d_mutex_lock();
hr = IWineD3DDevice_CreateSwapChain(device->WineD3DDevice, &wined3d_parameters,
&swapchain->wineD3DSwapChain, (IUnknown *)swapchain, SURFACE_OPENGL);
wined3d_mutex_unlock();
present_parameters->BackBufferWidth = wined3d_parameters.BackBufferWidth;
present_parameters->BackBufferHeight = wined3d_parameters.BackBufferHeight;
present_parameters->BackBufferFormat = d3dformat_from_wined3dformat(wined3d_parameters.BackBufferFormat);
present_parameters->BackBufferCount = wined3d_parameters.BackBufferCount;
present_parameters->MultiSampleType = wined3d_parameters.MultiSampleType;
present_parameters->SwapEffect = wined3d_parameters.SwapEffect;
present_parameters->hDeviceWindow = wined3d_parameters.hDeviceWindow;
present_parameters->Windowed = wined3d_parameters.Windowed;
present_parameters->EnableAutoDepthStencil = wined3d_parameters.EnableAutoDepthStencil;
present_parameters->AutoDepthStencilFormat = d3dformat_from_wined3dformat(wined3d_parameters.AutoDepthStencilFormat);
present_parameters->Flags = wined3d_parameters.Flags;
present_parameters->FullScreen_RefreshRateInHz = wined3d_parameters.FullScreen_RefreshRateInHz;
present_parameters->FullScreen_PresentationInterval = wined3d_parameters.PresentationInterval;
if (FAILED(hr))
{
WARN("Failed to create wined3d swapchain, hr %#x.\n", hr);
return hr;
}
swapchain->parentDevice = (IDirect3DDevice8 *)device;
IDirect3DDevice8_AddRef(swapchain->parentDevice);
return D3D_OK;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment