Module: wine Branch: master Commit: 0dc7de15e0ceb645d5e2024eee321a8e1557bb71 URL: https://gitlab.winehq.org/wine/wine/-/commit/0dc7de15e0ceb645d5e2024eee321a8...
Author: Zebediah Figura zfigura@codeweavers.com Date: Wed May 17 15:53:06 2023 -0500
dxgi: Do not create a d3d11 swapchain object for the implicit swapchain.
This swapchain is never actually exposed, and effectively only exists due to implementation constraints. When it was introduced, it was necessary or simplest to create a dxgi swapchain object, but currently that's no longer necessary, and avoiding that allows some code to be simplified.
---
dlls/dxgi/device.c | 20 +++--------------- dlls/dxgi/swapchain.c | 57 ++++++++++----------------------------------------- 2 files changed, 14 insertions(+), 63 deletions(-)
diff --git a/dlls/dxgi/device.c b/dlls/dxgi/device.c index 8e99fb5edba..60febf4d8e1 100644 --- a/dlls/dxgi/device.c +++ b/dlls/dxgi/device.c @@ -490,7 +490,6 @@ HRESULT dxgi_device_init(struct dxgi_device *device, struct dxgi_device_layer *l struct wined3d_device_parent *wined3d_device_parent; struct wined3d_swapchain_desc swapchain_desc; IWineDXGIDeviceParent *dxgi_device_parent; - struct d3d11_swapchain *swapchain; struct dxgi_adapter *dxgi_adapter; struct dxgi_factory *dxgi_factory; struct dxgi_output *dxgi_output; @@ -572,9 +571,10 @@ HRESULT dxgi_device_init(struct dxgi_device *device, struct dxgi_device_layer *l swapchain_desc.output = dxgi_output->wined3d_output; IDXGIOutput_Release(output);
- if (!(swapchain = heap_alloc_zero(sizeof(*swapchain)))) + if (FAILED(hr = wined3d_swapchain_create(device->wined3d_device, &swapchain_desc, + NULL, NULL, &dxgi_null_wined3d_parent_ops, &device->implicit_swapchain))) { - ERR("Failed to allocate swapchain memory.\n"); + ERR("Failed to create implicit swapchain, hr %#lx.\n", hr); wined3d_device_decref(device->wined3d_device); IUnknown_Release(device->child_layer); wined3d_private_store_cleanup(&device->private_store); @@ -582,20 +582,6 @@ HRESULT dxgi_device_init(struct dxgi_device *device, struct dxgi_device_layer *l return E_OUTOFMEMORY; }
- if (FAILED(hr = d3d11_swapchain_init(swapchain, device, &swapchain_desc))) - { - WARN("Failed to initialize swapchain, hr %#lx.\n", hr); - heap_free(swapchain); - wined3d_device_decref(device->wined3d_device); - IUnknown_Release(device->child_layer); - wined3d_private_store_cleanup(&device->private_store); - wined3d_mutex_unlock(); - return hr; - } - device->implicit_swapchain = swapchain->wined3d_swapchain; - - TRACE("Created swapchain %p.\n", swapchain); - wined3d_mutex_unlock();
device->adapter = &dxgi_adapter->IWineDXGIAdapter_iface; diff --git a/dlls/dxgi/swapchain.c b/dlls/dxgi/swapchain.c index f760e931bb1..6efe5f33dcb 100644 --- a/dlls/dxgi/swapchain.c +++ b/dlls/dxgi/swapchain.c @@ -236,11 +236,9 @@ static ULONG STDMETHODCALLTYPE d3d11_swapchain_Release(IDXGISwapChain1 *iface) WARN("Releasing fullscreen swapchain.\n"); IDXGIOutput_Release(swapchain->target); } - if (swapchain->factory) - IWineDXGIFactory_Release(swapchain->factory); + IWineDXGIFactory_Release(swapchain->factory); wined3d_swapchain_decref(swapchain->wined3d_swapchain); - if (device) - IWineDXGIDevice_Release(device); + IWineDXGIDevice_Release(device); }
return refcount; @@ -284,13 +282,6 @@ static HRESULT STDMETHODCALLTYPE d3d11_swapchain_GetParent(IDXGISwapChain1 *ifac
TRACE("iface %p, riid %s, parent %p.\n", iface, debugstr_guid(riid), parent);
- if (!swapchain->factory) - { - ERR("Implicit swapchain does not store reference to parent.\n"); - *parent = NULL; - return E_NOINTERFACE; - } - return IWineDXGIFactory_QueryInterface(swapchain->factory, riid, parent); }
@@ -302,13 +293,6 @@ static HRESULT STDMETHODCALLTYPE d3d11_swapchain_GetDevice(IDXGISwapChain1 *ifac
TRACE("iface %p, riid %s, device %p.\n", iface, debugstr_guid(riid), device);
- if (!swapchain->device) - { - ERR("Implicit swapchain does not store reference to device.\n"); - *device = NULL; - return E_NOINTERFACE; - } - return IWineDXGIDevice_QueryInterface(swapchain->device, riid, device); }
@@ -587,12 +571,6 @@ static HRESULT STDMETHODCALLTYPE d3d11_swapchain_GetContainingOutput(IDXGISwapCh return S_OK; }
- if (!swapchain->factory) - { - ERR("Implicit swapchain does not store a reference to factory.\n"); - return E_NOINTERFACE; - } - window = d3d11_swapchain_get_hwnd(swapchain); return dxgi_get_output_from_window(swapchain->factory, window, output); } @@ -889,27 +867,16 @@ HRESULT d3d11_swapchain_init(struct d3d11_swapchain *swapchain, struct dxgi_devi BOOL fullscreen; HRESULT hr;
- /* A reference to the implicit swapchain is held by the wined3d device. In - * order to avoid circular references we do not keep a reference to the - * device in the implicit swapchain. */ - if (!(desc->flags & WINED3D_SWAPCHAIN_IMPLICIT)) - { - if (desc->backbuffer_format == WINED3DFMT_UNKNOWN) - return E_INVALIDARG; + if (desc->backbuffer_format == WINED3DFMT_UNKNOWN) + return E_INVALIDARG;
- if (FAILED(hr = IWineDXGIAdapter_GetParent(device->adapter, - &IID_IWineDXGIFactory, (void **)&swapchain->factory))) - { - WARN("Failed to get adapter parent, hr %#lx.\n", hr); - return hr; - } - IWineDXGIDevice_AddRef(swapchain->device = &device->IWineDXGIDevice_iface); - } - else + if (FAILED(hr = IWineDXGIAdapter_GetParent(device->adapter, + &IID_IWineDXGIFactory, (void **)&swapchain->factory))) { - swapchain->device = NULL; - swapchain->factory = NULL; + WARN("Failed to get adapter parent, hr %#lx.\n", hr); + return hr; } + IWineDXGIDevice_AddRef(swapchain->device = &device->IWineDXGIDevice_iface);
swapchain->IDXGISwapChain1_iface.lpVtbl = &d3d11_swapchain_vtbl; swapchain->state_parent.ops = &d3d11_swapchain_state_parent_ops; @@ -969,10 +936,8 @@ HRESULT d3d11_swapchain_init(struct d3d11_swapchain *swapchain, struct dxgi_devi cleanup: wined3d_private_store_cleanup(&swapchain->private_store); wined3d_mutex_unlock(); - if (swapchain->factory) - IWineDXGIFactory_Release(swapchain->factory); - if (swapchain->device) - IWineDXGIDevice_Release(swapchain->device); + IWineDXGIFactory_Release(swapchain->factory); + IWineDXGIDevice_Release(swapchain->device); return hr; }