Commit 9e886423 authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

dxgi: Add a separate function for factory initialization.

parent 2650885c
......@@ -80,7 +80,6 @@ HRESULT WINAPI CreateDXGIFactory(REFIID riid, void **factory)
{
struct dxgi_factory *object;
HRESULT hr;
UINT i;
TRACE("riid %s, factory %p\n", debugstr_guid(riid), factory);
......@@ -92,59 +91,13 @@ HRESULT WINAPI CreateDXGIFactory(REFIID riid, void **factory)
return E_OUTOFMEMORY;
}
object->vtbl = &dxgi_factory_vtbl;
object->refcount = 1;
EnterCriticalSection(&dxgi_cs);
object->wined3d = WineDirect3DCreate(10, (IUnknown *)object);
if(!object->wined3d)
{
hr = DXGI_ERROR_UNSUPPORTED;
LeaveCriticalSection(&dxgi_cs);
goto fail;
}
object->adapter_count = IWineD3D_GetAdapterCount(object->wined3d);
LeaveCriticalSection(&dxgi_cs);
object->adapters = HeapAlloc(GetProcessHeap(), 0, object->adapter_count * sizeof(*object->adapters));
if (!object->adapters)
{
ERR("Failed to allocate DXGI adapter array memory\n");
hr = E_OUTOFMEMORY;
goto fail;
}
for (i = 0; i < object->adapter_count; ++i)
hr = dxgi_factory_init(object);
if (FAILED(hr))
{
struct dxgi_adapter *adapter = HeapAlloc(GetProcessHeap(), 0, sizeof(*adapter));
if (!adapter)
{
UINT j;
ERR("Failed to allocate DXGI adapter memory\n");
for (j = 0; j < i; ++j)
{
HeapFree(GetProcessHeap(), 0, object->adapters[j]);
}
hr = E_OUTOFMEMORY;
goto fail;
}
hr = dxgi_adapter_init(adapter, (IWineDXGIFactory *)object, i);
if (FAILED(hr))
{
UINT j;
ERR("Failed to initialize adapter, hr %#x.\n", hr);
HeapFree(GetProcessHeap(), 0, adapter);
for (j = 0; j < i; ++j)
{
IDXGIAdapter_Release(object->adapters[j]);
}
goto fail;
}
object->adapters[i] = (IDXGIAdapter *)adapter;
WARN("Failed to initialize swapchain, hr %#x.\n", hr);
HeapFree(GetProcessHeap(), 0, object);
*factory = NULL;
return hr;
}
TRACE("Created IDXGIFactory %p\n", object);
......@@ -153,19 +106,6 @@ HRESULT WINAPI CreateDXGIFactory(REFIID riid, void **factory)
IDXGIFactory_Release((IDXGIFactory *)object);
return hr;
fail:
HeapFree(GetProcessHeap(), 0, object->adapters);
if (object->wined3d)
{
EnterCriticalSection(&dxgi_cs);
IWineD3D_Release(object->wined3d);
LeaveCriticalSection(&dxgi_cs);
}
HeapFree(GetProcessHeap(), 0, object);
*factory = NULL;
return hr;
}
static BOOL get_layer(enum dxgi_device_layer_id id, struct dxgi_device_layer *layer)
......
......@@ -75,7 +75,6 @@ const char *debug_dxgi_format(DXGI_FORMAT format) DECLSPEC_HIDDEN;
WINED3DFORMAT wined3dformat_from_dxgi_format(DXGI_FORMAT format) DECLSPEC_HIDDEN;
/* IDXGIFactory */
extern const struct IWineDXGIFactoryVtbl dxgi_factory_vtbl DECLSPEC_HIDDEN;
struct dxgi_factory
{
const struct IWineDXGIFactoryVtbl *vtbl;
......@@ -85,6 +84,8 @@ struct dxgi_factory
IDXGIAdapter **adapters;
};
HRESULT dxgi_factory_init(struct dxgi_factory *factory) DECLSPEC_HIDDEN;
/* IDXGIDevice */
struct dxgi_device
{
......
......@@ -274,7 +274,7 @@ static IWineD3D * STDMETHODCALLTYPE dxgi_factory_get_wined3d(IWineDXGIFactory *i
return This->wined3d;
}
const struct IWineDXGIFactoryVtbl dxgi_factory_vtbl =
static const struct IWineDXGIFactoryVtbl dxgi_factory_vtbl =
{
/* IUnknown methods */
dxgi_factory_QueryInterface,
......@@ -294,3 +294,74 @@ const struct IWineDXGIFactoryVtbl dxgi_factory_vtbl =
/* IWineDXGIFactory methods */
dxgi_factory_get_wined3d,
};
HRESULT dxgi_factory_init(struct dxgi_factory *factory)
{
HRESULT hr;
UINT i;
factory->vtbl = &dxgi_factory_vtbl;
factory->refcount = 1;
EnterCriticalSection(&dxgi_cs);
factory->wined3d = WineDirect3DCreate(10, (IUnknown *)factory);
if (!factory->wined3d)
{
LeaveCriticalSection(&dxgi_cs);
return DXGI_ERROR_UNSUPPORTED;
}
factory->adapter_count = IWineD3D_GetAdapterCount(factory->wined3d);
LeaveCriticalSection(&dxgi_cs);
factory->adapters = HeapAlloc(GetProcessHeap(), 0, factory->adapter_count * sizeof(*factory->adapters));
if (!factory->adapters)
{
ERR("Failed to allocate DXGI adapter array memory.\n");
hr = E_OUTOFMEMORY;
goto fail;
}
for (i = 0; i < factory->adapter_count; ++i)
{
struct dxgi_adapter *adapter = HeapAlloc(GetProcessHeap(), 0, sizeof(*adapter));
if (!adapter)
{
UINT j;
ERR("Failed to allocate DXGI adapter memory.\n");
for (j = 0; j < i; ++j)
{
IDXGIAdapter_Release(factory->adapters[j]);
}
hr = E_OUTOFMEMORY;
goto fail;
}
hr = dxgi_adapter_init(adapter, (IWineDXGIFactory *)factory, i);
if (FAILED(hr))
{
UINT j;
ERR("Failed to initialize adapter, hr %#x.\n", hr);
HeapFree(GetProcessHeap(), 0, adapter);
for (j = 0; j < i; ++j)
{
IDXGIAdapter_Release(factory->adapters[j]);
}
goto fail;
}
factory->adapters[i] = (IDXGIAdapter *)adapter;
}
return S_OK;
fail:
HeapFree(GetProcessHeap(), 0, factory->adapters);
EnterCriticalSection(&dxgi_cs);
IWineD3D_Release(factory->wined3d);
LeaveCriticalSection(&dxgi_cs);
return hr;
}
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