2008-10-22 17:41:16 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2008 Henri Verbeet for CodeWeavers
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "wine/port.h"
|
|
|
|
|
|
|
|
#include "dxgi_private.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(dxgi);
|
|
|
|
|
2011-06-07 10:00:30 +02:00
|
|
|
static inline struct dxgi_device *impl_from_IWineDXGIDevice(IWineDXGIDevice *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, struct dxgi_device, IWineDXGIDevice_iface);
|
|
|
|
}
|
|
|
|
|
2008-10-22 17:41:16 +02:00
|
|
|
/* IUnknown methods */
|
|
|
|
|
2009-01-19 10:39:05 +01:00
|
|
|
static HRESULT STDMETHODCALLTYPE dxgi_device_QueryInterface(IWineDXGIDevice *iface, REFIID riid, void **object)
|
2008-10-22 17:41:16 +02:00
|
|
|
{
|
2011-06-07 10:00:30 +02:00
|
|
|
struct dxgi_device *This = impl_from_IWineDXGIDevice(iface);
|
2008-11-14 13:57:06 +01:00
|
|
|
|
2008-10-22 17:41:16 +02:00
|
|
|
TRACE("iface %p, riid %s, object %p\n", iface, debugstr_guid(riid), object);
|
|
|
|
|
|
|
|
if (IsEqualGUID(riid, &IID_IUnknown)
|
|
|
|
|| IsEqualGUID(riid, &IID_IDXGIObject)
|
2009-01-19 10:39:05 +01:00
|
|
|
|| IsEqualGUID(riid, &IID_IDXGIDevice)
|
2015-10-26 02:30:23 +01:00
|
|
|
|| IsEqualGUID(riid, &IID_IDXGIDevice1)
|
2018-05-01 07:21:18 +02:00
|
|
|
|| IsEqualGUID(riid, &IID_IDXGIDevice2)
|
2009-01-19 10:39:05 +01:00
|
|
|
|| IsEqualGUID(riid, &IID_IWineDXGIDevice))
|
2008-10-22 17:41:16 +02:00
|
|
|
{
|
|
|
|
IUnknown_AddRef(iface);
|
|
|
|
*object = iface;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2008-11-14 13:57:06 +01:00
|
|
|
if (This->child_layer)
|
|
|
|
{
|
2015-10-26 02:30:23 +01:00
|
|
|
TRACE("forwarding to child layer %p.\n", This->child_layer);
|
2008-11-14 13:57:06 +01:00
|
|
|
return IUnknown_QueryInterface(This->child_layer, riid, object);
|
|
|
|
}
|
|
|
|
|
2015-10-26 02:30:23 +01:00
|
|
|
WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
|
2008-10-22 17:41:16 +02:00
|
|
|
|
|
|
|
*object = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
2009-01-19 10:39:05 +01:00
|
|
|
static ULONG STDMETHODCALLTYPE dxgi_device_AddRef(IWineDXGIDevice *iface)
|
2008-10-22 17:41:16 +02:00
|
|
|
{
|
2011-06-07 10:00:30 +02:00
|
|
|
struct dxgi_device *This = impl_from_IWineDXGIDevice(iface);
|
2008-10-22 17:41:16 +02:00
|
|
|
ULONG refcount = InterlockedIncrement(&This->refcount);
|
|
|
|
|
|
|
|
TRACE("%p increasing refcount to %u\n", This, refcount);
|
|
|
|
|
|
|
|
return refcount;
|
|
|
|
}
|
|
|
|
|
2009-01-19 10:39:05 +01:00
|
|
|
static ULONG STDMETHODCALLTYPE dxgi_device_Release(IWineDXGIDevice *iface)
|
2008-10-22 17:41:16 +02:00
|
|
|
{
|
2016-04-14 12:20:22 +02:00
|
|
|
struct dxgi_device *device = impl_from_IWineDXGIDevice(iface);
|
|
|
|
ULONG refcount = InterlockedDecrement(&device->refcount);
|
2008-10-22 17:41:16 +02:00
|
|
|
|
2016-04-14 12:20:22 +02:00
|
|
|
TRACE("%p decreasing refcount to %u.\n", device, refcount);
|
2008-10-22 17:41:16 +02:00
|
|
|
|
|
|
|
if (!refcount)
|
|
|
|
{
|
2016-04-14 12:20:22 +02:00
|
|
|
if (device->child_layer)
|
|
|
|
IUnknown_Release(device->child_layer);
|
2015-09-17 01:10:13 +02:00
|
|
|
wined3d_mutex_lock();
|
2016-04-14 12:20:22 +02:00
|
|
|
wined3d_device_uninit_3d(device->wined3d_device);
|
|
|
|
wined3d_device_decref(device->wined3d_device);
|
2015-09-17 01:10:13 +02:00
|
|
|
wined3d_mutex_unlock();
|
2018-01-30 15:54:56 +01:00
|
|
|
IWineDXGIAdapter_Release(device->adapter);
|
2016-04-14 12:20:22 +02:00
|
|
|
wined3d_private_store_cleanup(&device->private_store);
|
2018-02-06 00:34:19 +01:00
|
|
|
heap_free(device);
|
2008-10-22 17:41:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return refcount;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* IDXGIObject methods */
|
|
|
|
|
2009-01-19 10:39:05 +01:00
|
|
|
static HRESULT STDMETHODCALLTYPE dxgi_device_SetPrivateData(IWineDXGIDevice *iface,
|
|
|
|
REFGUID guid, UINT data_size, const void *data)
|
2008-10-22 17:41:16 +02:00
|
|
|
{
|
2015-02-12 09:34:57 +01:00
|
|
|
struct dxgi_device *device = impl_from_IWineDXGIDevice(iface);
|
2008-10-22 17:41:16 +02:00
|
|
|
|
2015-02-12 09:34:57 +01:00
|
|
|
TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
|
|
|
|
|
|
|
|
return dxgi_set_private_data(&device->private_store, guid, data_size, data);
|
2008-10-22 17:41:16 +02:00
|
|
|
}
|
|
|
|
|
2009-01-19 10:39:05 +01:00
|
|
|
static HRESULT STDMETHODCALLTYPE dxgi_device_SetPrivateDataInterface(IWineDXGIDevice *iface,
|
|
|
|
REFGUID guid, const IUnknown *object)
|
2008-10-22 17:41:16 +02:00
|
|
|
{
|
2015-02-12 09:34:58 +01:00
|
|
|
struct dxgi_device *device = impl_from_IWineDXGIDevice(iface);
|
2008-10-22 17:41:16 +02:00
|
|
|
|
2015-02-12 09:34:58 +01:00
|
|
|
TRACE("iface %p, guid %s, object %p.\n", iface, debugstr_guid(guid), object);
|
|
|
|
|
|
|
|
return dxgi_set_private_data_interface(&device->private_store, guid, object);
|
2008-10-22 17:41:16 +02:00
|
|
|
}
|
|
|
|
|
2009-01-19 10:39:05 +01:00
|
|
|
static HRESULT STDMETHODCALLTYPE dxgi_device_GetPrivateData(IWineDXGIDevice *iface,
|
|
|
|
REFGUID guid, UINT *data_size, void *data)
|
2008-10-22 17:41:16 +02:00
|
|
|
{
|
2015-02-12 09:34:59 +01:00
|
|
|
struct dxgi_device *device = impl_from_IWineDXGIDevice(iface);
|
|
|
|
|
|
|
|
TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
|
2008-10-22 17:41:16 +02:00
|
|
|
|
2015-02-12 09:34:59 +01:00
|
|
|
return dxgi_get_private_data(&device->private_store, guid, data_size, data);
|
2008-10-22 17:41:16 +02:00
|
|
|
}
|
|
|
|
|
2009-01-19 10:39:05 +01:00
|
|
|
static HRESULT STDMETHODCALLTYPE dxgi_device_GetParent(IWineDXGIDevice *iface, REFIID riid, void **parent)
|
2008-10-22 17:41:16 +02:00
|
|
|
{
|
2009-12-03 11:38:20 +01:00
|
|
|
IDXGIAdapter *adapter;
|
|
|
|
HRESULT hr;
|
2008-10-22 17:41:16 +02:00
|
|
|
|
2009-12-03 11:38:20 +01:00
|
|
|
TRACE("iface %p, riid %s, parent %p.\n", iface, debugstr_guid(riid), parent);
|
|
|
|
|
2012-08-28 11:10:56 +02:00
|
|
|
hr = IWineDXGIDevice_GetAdapter(iface, &adapter);
|
2009-12-03 11:38:20 +01:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
ERR("Failed to get adapter, hr %#x.\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = IDXGIAdapter_QueryInterface(adapter, riid, parent);
|
|
|
|
IDXGIAdapter_Release(adapter);
|
|
|
|
|
|
|
|
return hr;
|
2008-10-22 17:41:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* IDXGIDevice methods */
|
|
|
|
|
2009-01-19 10:39:05 +01:00
|
|
|
static HRESULT STDMETHODCALLTYPE dxgi_device_GetAdapter(IWineDXGIDevice *iface, IDXGIAdapter **adapter)
|
2008-10-22 17:41:16 +02:00
|
|
|
{
|
2016-04-14 12:20:22 +02:00
|
|
|
struct dxgi_device *device = impl_from_IWineDXGIDevice(iface);
|
2008-10-22 17:41:16 +02:00
|
|
|
|
2016-04-14 12:20:22 +02:00
|
|
|
TRACE("iface %p, adapter %p.\n", iface, adapter);
|
2008-11-20 13:32:00 +01:00
|
|
|
|
2016-04-14 12:20:22 +02:00
|
|
|
*adapter = (IDXGIAdapter *)device->adapter;
|
|
|
|
IDXGIAdapter_AddRef(*adapter);
|
|
|
|
return S_OK;
|
2008-10-22 17:41:16 +02:00
|
|
|
}
|
|
|
|
|
2009-01-19 10:39:05 +01:00
|
|
|
static HRESULT STDMETHODCALLTYPE dxgi_device_CreateSurface(IWineDXGIDevice *iface,
|
2008-10-22 17:41:16 +02:00
|
|
|
const DXGI_SURFACE_DESC *desc, UINT surface_count, DXGI_USAGE usage,
|
|
|
|
const DXGI_SHARED_RESOURCE *shared_resource, IDXGISurface **surface)
|
|
|
|
{
|
2011-05-18 22:30:13 +02:00
|
|
|
struct wined3d_device_parent *device_parent;
|
2013-06-04 09:57:08 +02:00
|
|
|
struct wined3d_resource_desc surface_desc;
|
2011-05-18 22:30:13 +02:00
|
|
|
IWineDXGIDeviceParent *dxgi_device_parent;
|
2009-01-15 09:58:44 +01:00
|
|
|
HRESULT hr;
|
|
|
|
UINT i;
|
2009-01-19 10:39:06 +01:00
|
|
|
UINT j;
|
2009-01-15 09:58:44 +01:00
|
|
|
|
2018-01-25 10:56:29 +01:00
|
|
|
TRACE("iface %p, desc %p, surface_count %u, usage %#x, shared_resource %p, surface %p.\n",
|
2008-10-22 17:41:16 +02:00
|
|
|
iface, desc, surface_count, usage, shared_resource, surface);
|
|
|
|
|
2011-05-18 22:30:13 +02:00
|
|
|
hr = IWineDXGIDevice_QueryInterface(iface, &IID_IWineDXGIDeviceParent, (void **)&dxgi_device_parent);
|
2009-01-19 10:39:06 +01:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2018-01-25 10:56:29 +01:00
|
|
|
ERR("Device should implement IWineDXGIDeviceParent.\n");
|
2009-01-19 10:39:06 +01:00
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2011-05-18 22:30:13 +02:00
|
|
|
device_parent = IWineDXGIDeviceParent_get_wined3d_device_parent(dxgi_device_parent);
|
|
|
|
|
2016-04-18 19:06:30 +02:00
|
|
|
surface_desc.resource_type = WINED3D_RTYPE_TEXTURE_2D;
|
2013-06-04 09:57:08 +02:00
|
|
|
surface_desc.format = wined3dformat_from_dxgi_format(desc->Format);
|
2015-08-06 00:21:55 +02:00
|
|
|
wined3d_sample_desc_from_dxgi(&surface_desc.multisample_type,
|
|
|
|
&surface_desc.multisample_quality, &desc->SampleDesc);
|
2018-01-25 10:56:29 +01:00
|
|
|
surface_desc.usage = wined3d_usage_from_dxgi_usage(usage);
|
2018-02-02 17:58:54 +01:00
|
|
|
surface_desc.access = WINED3D_RESOURCE_ACCESS_GPU;
|
2013-06-04 09:57:08 +02:00
|
|
|
surface_desc.width = desc->Width;
|
|
|
|
surface_desc.height = desc->Height;
|
|
|
|
surface_desc.depth = 1;
|
|
|
|
surface_desc.size = 0;
|
2009-01-19 10:39:06 +01:00
|
|
|
|
2015-09-17 01:10:14 +02:00
|
|
|
wined3d_mutex_lock();
|
2009-01-15 09:58:44 +01:00
|
|
|
memset(surface, 0, surface_count * sizeof(*surface));
|
|
|
|
for (i = 0; i < surface_count; ++i)
|
|
|
|
{
|
2015-09-03 20:56:26 +02:00
|
|
|
struct wined3d_texture *wined3d_texture;
|
2009-01-19 10:39:06 +01:00
|
|
|
IUnknown *parent;
|
|
|
|
|
2015-09-03 20:56:26 +02:00
|
|
|
if (FAILED(hr = device_parent->ops->create_swapchain_texture(device_parent,
|
2017-02-09 05:51:56 +01:00
|
|
|
NULL, &surface_desc, 0, &wined3d_texture)))
|
2009-01-15 09:58:44 +01:00
|
|
|
{
|
2013-06-04 09:57:08 +02:00
|
|
|
ERR("Failed to create surface, hr %#x.\n", hr);
|
2009-01-15 09:58:44 +01:00
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
2015-09-03 20:56:26 +02:00
|
|
|
parent = wined3d_texture_get_parent(wined3d_texture);
|
2009-01-19 10:39:06 +01:00
|
|
|
hr = IUnknown_QueryInterface(parent, &IID_IDXGISurface, (void **)&surface[i]);
|
2015-09-03 20:56:26 +02:00
|
|
|
wined3d_texture_decref(wined3d_texture);
|
2009-01-19 10:39:06 +01:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2018-01-25 10:56:29 +01:00
|
|
|
ERR("Surface should implement IDXGISurface.\n");
|
2009-01-19 10:39:06 +01:00
|
|
|
goto fail;
|
|
|
|
}
|
2009-01-15 09:58:44 +01:00
|
|
|
|
2018-01-25 10:56:29 +01:00
|
|
|
TRACE("Created IDXGISurface %p (%u/%u).\n", surface[i], i + 1, surface_count);
|
2009-01-15 09:58:44 +01:00
|
|
|
}
|
2015-09-17 01:10:14 +02:00
|
|
|
wined3d_mutex_unlock();
|
2011-05-18 22:30:13 +02:00
|
|
|
IWineDXGIDeviceParent_Release(dxgi_device_parent);
|
2009-01-15 09:58:44 +01:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
|
|
|
|
fail:
|
2015-09-17 01:10:14 +02:00
|
|
|
wined3d_mutex_unlock();
|
2009-01-19 10:39:06 +01:00
|
|
|
for (j = 0; j < i; ++j)
|
2009-01-15 09:58:44 +01:00
|
|
|
{
|
2009-01-19 10:39:06 +01:00
|
|
|
IDXGISurface_Release(surface[i]);
|
2009-01-15 09:58:44 +01:00
|
|
|
}
|
2011-05-18 22:30:13 +02:00
|
|
|
IWineDXGIDeviceParent_Release(dxgi_device_parent);
|
2009-01-15 09:58:44 +01:00
|
|
|
return hr;
|
2008-10-22 17:41:16 +02:00
|
|
|
}
|
|
|
|
|
2009-01-19 10:39:05 +01:00
|
|
|
static HRESULT STDMETHODCALLTYPE dxgi_device_QueryResourceResidency(IWineDXGIDevice *iface,
|
2008-10-22 17:41:16 +02:00
|
|
|
IUnknown *const *resources, DXGI_RESIDENCY *residency, UINT resource_count)
|
|
|
|
{
|
|
|
|
FIXME("iface %p, resources %p, residency %p, resource_count %u stub!\n",
|
|
|
|
iface, resources, residency, resource_count);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2009-01-19 10:39:05 +01:00
|
|
|
static HRESULT STDMETHODCALLTYPE dxgi_device_SetGPUThreadPriority(IWineDXGIDevice *iface, INT priority)
|
2008-10-22 17:41:16 +02:00
|
|
|
{
|
|
|
|
FIXME("iface %p, priority %d stub!\n", iface, priority);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2009-01-19 10:39:05 +01:00
|
|
|
static HRESULT STDMETHODCALLTYPE dxgi_device_GetGPUThreadPriority(IWineDXGIDevice *iface, INT *priority)
|
2008-10-22 17:41:16 +02:00
|
|
|
{
|
|
|
|
FIXME("iface %p, priority %p stub!\n", iface, priority);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2015-10-26 02:30:23 +01:00
|
|
|
static HRESULT STDMETHODCALLTYPE dxgi_device_SetMaximumFrameLatency(IWineDXGIDevice *iface, UINT max_latency)
|
|
|
|
{
|
2018-05-15 10:25:59 +02:00
|
|
|
struct dxgi_device *device = impl_from_IWineDXGIDevice(iface);
|
|
|
|
|
|
|
|
TRACE("iface %p, max_latency %u.\n", iface, max_latency);
|
2015-10-26 02:30:23 +01:00
|
|
|
|
|
|
|
if (max_latency > DXGI_FRAME_LATENCY_MAX)
|
|
|
|
return DXGI_ERROR_INVALID_CALL;
|
|
|
|
|
2018-05-15 10:25:59 +02:00
|
|
|
wined3d_mutex_lock();
|
|
|
|
wined3d_device_set_max_frame_latency(device->wined3d_device, max_latency);
|
|
|
|
wined3d_mutex_unlock();
|
|
|
|
|
|
|
|
return S_OK;
|
2015-10-26 02:30:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE dxgi_device_GetMaximumFrameLatency(IWineDXGIDevice *iface, UINT *max_latency)
|
|
|
|
{
|
2018-05-15 10:25:59 +02:00
|
|
|
struct dxgi_device *device = impl_from_IWineDXGIDevice(iface);
|
2015-10-26 02:30:23 +01:00
|
|
|
|
2018-05-15 10:25:59 +02:00
|
|
|
TRACE("iface %p, max_latency %p.\n", iface, max_latency);
|
2015-10-26 02:30:23 +01:00
|
|
|
|
2018-05-15 10:25:59 +02:00
|
|
|
if (!max_latency)
|
|
|
|
return DXGI_ERROR_INVALID_CALL;
|
|
|
|
|
|
|
|
wined3d_mutex_lock();
|
|
|
|
*max_latency = wined3d_device_get_max_frame_latency(device->wined3d_device);
|
|
|
|
wined3d_mutex_unlock();
|
|
|
|
|
|
|
|
return S_OK;
|
2015-10-26 02:30:23 +01:00
|
|
|
}
|
|
|
|
|
2018-05-01 07:21:18 +02:00
|
|
|
static HRESULT STDMETHODCALLTYPE dxgi_device_OfferResources(IWineDXGIDevice *iface, UINT resource_count,
|
|
|
|
IDXGIResource * const *resources, DXGI_OFFER_RESOURCE_PRIORITY priority)
|
|
|
|
{
|
|
|
|
FIXME("iface %p, resource_count %u, resources %p, priority %u stub!\n", iface, resource_count,
|
|
|
|
resources, priority);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE dxgi_device_ReclaimResources(IWineDXGIDevice *iface, UINT resource_count,
|
|
|
|
IDXGIResource * const *resources, BOOL *discarded)
|
|
|
|
{
|
|
|
|
FIXME("iface %p, resource_count %u, resources %p, discarded %p stub!\n", iface, resource_count,
|
|
|
|
resources, discarded);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE dxgi_device_EnqueueSetEvent(IWineDXGIDevice *iface, HANDLE event)
|
|
|
|
{
|
|
|
|
FIXME("iface %p, event %p stub!\n", iface, event);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2009-01-19 10:39:05 +01:00
|
|
|
/* IWineDXGIDevice methods */
|
|
|
|
|
2015-08-06 00:21:57 +02:00
|
|
|
static HRESULT STDMETHODCALLTYPE dxgi_device_create_surface(IWineDXGIDevice *iface,
|
2016-09-01 11:42:54 +02:00
|
|
|
struct wined3d_texture *wined3d_texture, DXGI_USAGE usage,
|
2015-08-06 00:21:57 +02:00
|
|
|
const DXGI_SHARED_RESOURCE *shared_resource, IUnknown *outer, void **surface)
|
2009-01-19 10:39:06 +01:00
|
|
|
{
|
|
|
|
struct dxgi_surface *object;
|
2009-12-07 11:08:38 +01:00
|
|
|
HRESULT hr;
|
2009-01-19 10:39:06 +01:00
|
|
|
|
2016-09-01 11:42:54 +02:00
|
|
|
TRACE("iface %p, wined3d_texture %p, usage %#x, shared_resource %p, outer %p, surface %p.\n",
|
|
|
|
iface, wined3d_texture, usage, shared_resource, outer, surface);
|
2009-01-19 10:39:06 +01:00
|
|
|
|
2018-02-06 00:34:19 +01:00
|
|
|
if (!(object = heap_alloc_zero(sizeof(*object))))
|
2009-01-19 10:39:06 +01:00
|
|
|
{
|
|
|
|
ERR("Failed to allocate DXGI surface object memory\n");
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
2016-09-01 11:42:54 +02:00
|
|
|
if (FAILED(hr = dxgi_surface_init(object, (IDXGIDevice *)iface, outer, wined3d_texture)))
|
2009-01-19 10:39:06 +01:00
|
|
|
{
|
2009-12-07 11:08:38 +01:00
|
|
|
WARN("Failed to initialize surface, hr %#x.\n", hr);
|
2018-02-06 00:34:19 +01:00
|
|
|
heap_free(object);
|
2009-12-07 11:08:38 +01:00
|
|
|
return hr;
|
2009-01-19 10:39:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("Created IDXGISurface %p\n", object);
|
2016-03-29 08:36:59 +02:00
|
|
|
*surface = outer ? &object->IUnknown_iface : (IUnknown *)&object->IDXGISurface1_iface;
|
2009-01-19 10:39:06 +01:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2009-02-24 07:43:02 +01:00
|
|
|
static HRESULT STDMETHODCALLTYPE dxgi_device_create_swapchain(IWineDXGIDevice *iface,
|
2016-04-12 12:29:38 +02:00
|
|
|
struct wined3d_swapchain_desc *desc, BOOL implicit, struct wined3d_swapchain **wined3d_swapchain)
|
2009-02-24 07:43:02 +01:00
|
|
|
{
|
2016-04-12 12:29:38 +02:00
|
|
|
struct dxgi_device *device = impl_from_IWineDXGIDevice(iface);
|
2009-02-24 07:43:02 +01:00
|
|
|
struct dxgi_swapchain *object;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2011-12-02 08:15:52 +01:00
|
|
|
TRACE("iface %p, desc %p, wined3d_swapchain %p.\n",
|
|
|
|
iface, desc, wined3d_swapchain);
|
2009-12-28 17:38:05 +01:00
|
|
|
|
2018-02-06 00:34:19 +01:00
|
|
|
if (!(object = heap_alloc_zero(sizeof(*object))))
|
2009-02-24 07:43:02 +01:00
|
|
|
{
|
|
|
|
ERR("Failed to allocate DXGI swapchain object memory\n");
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
2016-04-12 12:29:38 +02:00
|
|
|
if (FAILED(hr = dxgi_swapchain_init(object, device, desc, implicit)))
|
2009-02-24 07:43:02 +01:00
|
|
|
{
|
2009-12-28 17:38:05 +01:00
|
|
|
WARN("Failed to initialize swapchain, hr %#x.\n", hr);
|
2018-02-06 00:34:19 +01:00
|
|
|
heap_free(object);
|
2009-02-24 07:43:02 +01:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2016-04-12 12:29:38 +02:00
|
|
|
TRACE("Created IDXGISwapChain %p.\n", object);
|
2009-12-28 17:38:05 +01:00
|
|
|
*wined3d_swapchain = object->wined3d_swapchain;
|
2009-02-24 07:43:02 +01:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2009-11-19 11:41:25 +01:00
|
|
|
static const struct IWineDXGIDeviceVtbl dxgi_device_vtbl =
|
2008-10-22 17:41:16 +02:00
|
|
|
{
|
|
|
|
/* IUnknown methods */
|
|
|
|
dxgi_device_QueryInterface,
|
|
|
|
dxgi_device_AddRef,
|
|
|
|
dxgi_device_Release,
|
|
|
|
/* IDXGIObject methods */
|
|
|
|
dxgi_device_SetPrivateData,
|
|
|
|
dxgi_device_SetPrivateDataInterface,
|
|
|
|
dxgi_device_GetPrivateData,
|
|
|
|
dxgi_device_GetParent,
|
|
|
|
/* IDXGIDevice methods */
|
|
|
|
dxgi_device_GetAdapter,
|
|
|
|
dxgi_device_CreateSurface,
|
|
|
|
dxgi_device_QueryResourceResidency,
|
|
|
|
dxgi_device_SetGPUThreadPriority,
|
|
|
|
dxgi_device_GetGPUThreadPriority,
|
2015-10-26 02:30:23 +01:00
|
|
|
/* IDXGIDevice1 methods */
|
|
|
|
dxgi_device_SetMaximumFrameLatency,
|
|
|
|
dxgi_device_GetMaximumFrameLatency,
|
2018-05-01 07:21:18 +02:00
|
|
|
/* IDXGIDevice2 methods */
|
|
|
|
dxgi_device_OfferResources,
|
|
|
|
dxgi_device_ReclaimResources,
|
|
|
|
dxgi_device_EnqueueSetEvent,
|
2015-01-20 15:47:04 +01:00
|
|
|
/* IWineDXGIDevice methods */
|
2009-01-19 10:39:06 +01:00
|
|
|
dxgi_device_create_surface,
|
2009-02-24 07:43:02 +01:00
|
|
|
dxgi_device_create_swapchain,
|
2008-10-22 17:41:16 +02:00
|
|
|
};
|
2009-11-19 11:41:25 +01:00
|
|
|
|
|
|
|
HRESULT dxgi_device_init(struct dxgi_device *device, struct dxgi_device_layer *layer,
|
2016-03-09 23:19:19 +01:00
|
|
|
IDXGIFactory *factory, IDXGIAdapter *adapter,
|
|
|
|
const D3D_FEATURE_LEVEL *feature_levels, unsigned int level_count)
|
2009-11-19 11:41:25 +01:00
|
|
|
{
|
2011-05-18 22:30:13 +02:00
|
|
|
struct wined3d_device_parent *wined3d_device_parent;
|
2014-09-15 11:03:36 +02:00
|
|
|
struct wined3d_swapchain_desc swapchain_desc;
|
2011-05-18 22:30:13 +02:00
|
|
|
IWineDXGIDeviceParent *dxgi_device_parent;
|
2014-09-15 11:03:34 +02:00
|
|
|
struct dxgi_adapter *dxgi_adapter;
|
2014-09-15 11:03:35 +02:00
|
|
|
struct dxgi_factory *dxgi_factory;
|
2016-03-09 23:19:19 +01:00
|
|
|
D3D_FEATURE_LEVEL feature_level;
|
2009-11-19 11:41:25 +01:00
|
|
|
void *layer_base;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2018-02-14 12:35:49 +01:00
|
|
|
if (!(dxgi_factory = unsafe_impl_from_IDXGIFactory(factory)))
|
2014-09-15 11:03:35 +02:00
|
|
|
{
|
|
|
|
WARN("This is not the factory we're looking for.\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2018-01-30 15:54:56 +01:00
|
|
|
if (!(dxgi_adapter = unsafe_impl_from_IDXGIAdapter(adapter)))
|
2014-09-15 11:03:34 +02:00
|
|
|
{
|
|
|
|
WARN("This is not the adapter we're looking for.\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2011-06-07 10:00:30 +02:00
|
|
|
device->IWineDXGIDevice_iface.lpVtbl = &dxgi_device_vtbl;
|
2009-11-19 11:41:25 +01:00
|
|
|
device->refcount = 1;
|
2015-09-17 01:10:14 +02:00
|
|
|
wined3d_mutex_lock();
|
2015-02-12 09:34:57 +01:00
|
|
|
wined3d_private_store_init(&device->private_store);
|
2009-11-19 11:41:25 +01:00
|
|
|
|
|
|
|
layer_base = device + 1;
|
|
|
|
|
2014-09-15 11:03:35 +02:00
|
|
|
if (FAILED(hr = layer->create(layer->id, &layer_base, 0,
|
|
|
|
device, &IID_IUnknown, (void **)&device->child_layer)))
|
2009-11-19 11:41:25 +01:00
|
|
|
{
|
|
|
|
WARN("Failed to create device, returning %#x.\n", hr);
|
2015-02-12 09:34:57 +01:00
|
|
|
wined3d_private_store_cleanup(&device->private_store);
|
2015-09-17 01:10:14 +02:00
|
|
|
wined3d_mutex_unlock();
|
2014-09-15 11:03:35 +02:00
|
|
|
return hr;
|
2009-11-19 11:41:25 +01:00
|
|
|
}
|
|
|
|
|
2014-09-15 11:03:35 +02:00
|
|
|
if (FAILED(hr = IWineDXGIDevice_QueryInterface(&device->IWineDXGIDevice_iface,
|
|
|
|
&IID_IWineDXGIDeviceParent, (void **)&dxgi_device_parent)))
|
2009-11-19 11:41:25 +01:00
|
|
|
{
|
2017-02-25 07:10:13 +01:00
|
|
|
ERR("DXGI device should implement IWineDXGIDeviceParent.\n");
|
2014-09-15 11:03:35 +02:00
|
|
|
IUnknown_Release(device->child_layer);
|
2015-02-12 09:34:57 +01:00
|
|
|
wined3d_private_store_cleanup(&device->private_store);
|
2015-09-17 01:10:14 +02:00
|
|
|
wined3d_mutex_unlock();
|
2014-09-15 11:03:35 +02:00
|
|
|
return hr;
|
2009-11-19 11:41:25 +01:00
|
|
|
}
|
2011-05-18 22:30:13 +02:00
|
|
|
wined3d_device_parent = IWineDXGIDeviceParent_get_wined3d_device_parent(dxgi_device_parent);
|
2014-09-15 11:03:35 +02:00
|
|
|
IWineDXGIDeviceParent_Release(dxgi_device_parent);
|
2011-05-18 22:30:13 +02:00
|
|
|
|
2016-03-09 23:19:19 +01:00
|
|
|
if (!(feature_level = dxgi_check_feature_level_support(dxgi_factory, dxgi_adapter,
|
|
|
|
feature_levels, level_count)))
|
2011-10-25 16:58:46 +02:00
|
|
|
{
|
2014-09-15 11:03:35 +02:00
|
|
|
IUnknown_Release(device->child_layer);
|
2015-02-12 09:34:57 +01:00
|
|
|
wined3d_private_store_cleanup(&device->private_store);
|
2015-09-17 01:10:14 +02:00
|
|
|
wined3d_mutex_unlock();
|
2016-03-09 23:19:19 +01:00
|
|
|
return E_FAIL;
|
2011-10-25 16:58:46 +02:00
|
|
|
}
|
|
|
|
|
2014-09-15 11:03:35 +02:00
|
|
|
hr = wined3d_device_create(dxgi_factory->wined3d, dxgi_adapter->ordinal, WINED3D_DEVICE_TYPE_HAL,
|
|
|
|
NULL, 0, 4, wined3d_device_parent, &device->wined3d_device);
|
2009-11-19 11:41:25 +01:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
WARN("Failed to create a wined3d device, returning %#x.\n", hr);
|
2014-09-15 11:03:35 +02:00
|
|
|
IUnknown_Release(device->child_layer);
|
2015-02-12 09:34:57 +01:00
|
|
|
wined3d_private_store_cleanup(&device->private_store);
|
2015-09-17 01:10:14 +02:00
|
|
|
wined3d_mutex_unlock();
|
2014-09-15 11:03:35 +02:00
|
|
|
return hr;
|
2009-11-19 11:41:25 +01:00
|
|
|
}
|
|
|
|
|
2016-03-09 23:19:19 +01:00
|
|
|
layer->set_feature_level(layer->id, device->child_layer, feature_level);
|
|
|
|
|
2014-09-15 11:03:36 +02:00
|
|
|
memset(&swapchain_desc, 0, sizeof(swapchain_desc));
|
|
|
|
swapchain_desc.swap_effect = WINED3D_SWAP_EFFECT_DISCARD;
|
|
|
|
swapchain_desc.device_window = dxgi_factory_get_device_window(dxgi_factory);
|
|
|
|
swapchain_desc.windowed = TRUE;
|
|
|
|
if (FAILED(hr = wined3d_device_init_3d(device->wined3d_device, &swapchain_desc)))
|
|
|
|
{
|
|
|
|
ERR("Failed to initialize 3D, hr %#x.\n", hr);
|
|
|
|
wined3d_device_decref(device->wined3d_device);
|
|
|
|
IUnknown_Release(device->child_layer);
|
2015-02-12 09:34:57 +01:00
|
|
|
wined3d_private_store_cleanup(&device->private_store);
|
2015-09-17 01:10:14 +02:00
|
|
|
wined3d_mutex_unlock();
|
2014-09-15 11:03:36 +02:00
|
|
|
return hr;
|
|
|
|
}
|
2015-09-17 01:10:14 +02:00
|
|
|
wined3d_mutex_unlock();
|
2014-09-15 11:03:36 +02:00
|
|
|
|
2018-01-30 15:54:56 +01:00
|
|
|
device->adapter = &dxgi_adapter->IWineDXGIAdapter_iface;
|
|
|
|
IWineDXGIAdapter_AddRef(device->adapter);
|
2009-11-19 11:41:25 +01:00
|
|
|
|
2014-09-15 11:03:35 +02:00
|
|
|
return S_OK;
|
2009-11-19 11:41:25 +01:00
|
|
|
}
|