2008-10-29 09:00:26 +01: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-06 10:25:49 +02:00
|
|
|
static inline struct dxgi_swapchain *impl_from_IDXGISwapChain(IDXGISwapChain *iface)
|
|
|
|
{
|
|
|
|
return CONTAINING_RECORD(iface, struct dxgi_swapchain, IDXGISwapChain_iface);
|
|
|
|
}
|
|
|
|
|
2008-10-29 09:00:26 +01:00
|
|
|
/* IUnknown methods */
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE dxgi_swapchain_QueryInterface(IDXGISwapChain *iface, REFIID riid, void **object)
|
|
|
|
{
|
|
|
|
TRACE("iface %p, riid %s, object %p\n", iface, debugstr_guid(riid), object);
|
|
|
|
|
|
|
|
if (IsEqualGUID(riid, &IID_IUnknown)
|
|
|
|
|| IsEqualGUID(riid, &IID_IDXGIObject)
|
|
|
|
|| IsEqualGUID(riid, &IID_IDXGIDeviceSubObject)
|
|
|
|
|| IsEqualGUID(riid, &IID_IDXGISwapChain))
|
|
|
|
{
|
|
|
|
IUnknown_AddRef(iface);
|
|
|
|
*object = iface;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid));
|
|
|
|
|
|
|
|
*object = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG STDMETHODCALLTYPE dxgi_swapchain_AddRef(IDXGISwapChain *iface)
|
|
|
|
{
|
2011-06-06 10:25:49 +02:00
|
|
|
struct dxgi_swapchain *This = impl_from_IDXGISwapChain(iface);
|
2008-10-29 09:00:26 +01:00
|
|
|
ULONG refcount = InterlockedIncrement(&This->refcount);
|
|
|
|
|
|
|
|
TRACE("%p increasing refcount to %u\n", This, refcount);
|
|
|
|
|
2011-04-07 18:46:01 +02:00
|
|
|
if (refcount == 1)
|
2011-04-13 19:14:31 +02:00
|
|
|
wined3d_swapchain_incref(This->wined3d_swapchain);
|
2011-04-07 18:46:01 +02:00
|
|
|
|
2008-10-29 09:00:26 +01:00
|
|
|
return refcount;
|
|
|
|
}
|
|
|
|
|
|
|
|
static ULONG STDMETHODCALLTYPE dxgi_swapchain_Release(IDXGISwapChain *iface)
|
|
|
|
{
|
2011-06-06 10:25:49 +02:00
|
|
|
struct dxgi_swapchain *This = impl_from_IDXGISwapChain(iface);
|
2008-10-29 09:00:26 +01:00
|
|
|
ULONG refcount = InterlockedDecrement(&This->refcount);
|
|
|
|
|
|
|
|
TRACE("%p decreasing refcount to %u\n", This, refcount);
|
|
|
|
|
|
|
|
if (!refcount)
|
|
|
|
{
|
2011-05-16 23:01:22 +02:00
|
|
|
struct wined3d_device *wined3d_device;
|
2009-02-24 07:43:02 +01:00
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
FIXME("Only a single swapchain is supported\n");
|
|
|
|
|
2011-04-13 19:14:31 +02:00
|
|
|
wined3d_device = wined3d_swapchain_get_device(This->wined3d_swapchain);
|
2011-05-16 23:01:22 +02:00
|
|
|
hr = wined3d_device_uninit_3d(wined3d_device);
|
2009-02-24 07:43:02 +01:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
2011-04-13 19:14:31 +02:00
|
|
|
ERR("Uninit3D failed, hr %#x\n", hr);
|
2009-02-24 07:43:02 +01:00
|
|
|
}
|
2008-10-29 09:00:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return refcount;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* IDXGIObject methods */
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE dxgi_swapchain_SetPrivateData(IDXGISwapChain *iface,
|
|
|
|
REFGUID guid, UINT data_size, const void *data)
|
|
|
|
{
|
|
|
|
FIXME("iface %p, guid %s, data_size %u, data %p stub!\n", iface, debugstr_guid(guid), data_size, data);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE dxgi_swapchain_SetPrivateDataInterface(IDXGISwapChain *iface,
|
|
|
|
REFGUID guid, const IUnknown *object)
|
|
|
|
{
|
|
|
|
FIXME("iface %p, guid %s, object %p stub!\n", iface, debugstr_guid(guid), object);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE dxgi_swapchain_GetPrivateData(IDXGISwapChain *iface,
|
|
|
|
REFGUID guid, UINT *data_size, void *data)
|
|
|
|
{
|
|
|
|
FIXME("iface %p, guid %s, data_size %p, data %p stub!\n", iface, debugstr_guid(guid), data_size, data);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE dxgi_swapchain_GetParent(IDXGISwapChain *iface, REFIID riid, void **parent)
|
|
|
|
{
|
|
|
|
FIXME("iface %p, riid %s, parent %p stub!\n", iface, debugstr_guid(riid), parent);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* IDXGIDeviceSubObject methods */
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE dxgi_swapchain_GetDevice(IDXGISwapChain *iface, REFIID riid, void **device)
|
|
|
|
{
|
|
|
|
FIXME("iface %p, riid %s, device %p stub!\n", iface, debugstr_guid(riid), device);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* IDXGISwapChain methods */
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE dxgi_swapchain_Present(IDXGISwapChain *iface, UINT sync_interval, UINT flags)
|
|
|
|
{
|
2011-06-06 10:25:49 +02:00
|
|
|
struct dxgi_swapchain *This = impl_from_IDXGISwapChain(iface);
|
2008-10-29 09:00:26 +01:00
|
|
|
|
2009-02-24 07:43:02 +01:00
|
|
|
TRACE("iface %p, sync_interval %u, flags %#x\n", iface, sync_interval, flags);
|
|
|
|
|
|
|
|
if (sync_interval) FIXME("Unimplemented sync interval %u\n", sync_interval);
|
|
|
|
if (flags) FIXME("Unimplemented flags %#x\n", flags);
|
|
|
|
|
2011-04-13 19:14:31 +02:00
|
|
|
return wined3d_swapchain_present(This->wined3d_swapchain, NULL, NULL, NULL, NULL, 0);
|
2008-10-29 09:00:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE dxgi_swapchain_GetBuffer(IDXGISwapChain *iface,
|
|
|
|
UINT buffer_idx, REFIID riid, void **surface)
|
|
|
|
{
|
2011-06-06 10:25:49 +02:00
|
|
|
struct dxgi_swapchain *This = impl_from_IDXGISwapChain(iface);
|
2011-04-29 13:03:41 +02:00
|
|
|
struct wined3d_surface *backbuffer;
|
2009-02-24 07:43:02 +01:00
|
|
|
IUnknown *parent;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("iface %p, buffer_idx %u, riid %s, surface %p\n",
|
2008-10-29 09:00:26 +01:00
|
|
|
iface, buffer_idx, debugstr_guid(riid), surface);
|
|
|
|
|
2009-02-24 07:43:02 +01:00
|
|
|
EnterCriticalSection(&dxgi_cs);
|
|
|
|
|
2012-10-04 13:53:27 +02:00
|
|
|
if (!(backbuffer = wined3d_swapchain_get_back_buffer(This->wined3d_swapchain,
|
|
|
|
buffer_idx, WINED3D_BACKBUFFER_TYPE_MONO)))
|
2009-02-24 07:43:02 +01:00
|
|
|
{
|
|
|
|
LeaveCriticalSection(&dxgi_cs);
|
2012-10-04 13:53:27 +02:00
|
|
|
return DXGI_ERROR_INVALID_CALL;
|
2009-02-24 07:43:02 +01:00
|
|
|
}
|
|
|
|
|
2011-04-29 13:03:41 +02:00
|
|
|
parent = wined3d_surface_get_parent(backbuffer);
|
2010-08-31 18:41:40 +02:00
|
|
|
hr = IUnknown_QueryInterface(parent, riid, surface);
|
2009-02-24 07:43:02 +01:00
|
|
|
LeaveCriticalSection(&dxgi_cs);
|
|
|
|
|
|
|
|
return hr;
|
2008-10-29 09:00:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE dxgi_swapchain_SetFullscreenState(IDXGISwapChain *iface,
|
|
|
|
BOOL fullscreen, IDXGIOutput *target)
|
|
|
|
{
|
|
|
|
FIXME("iface %p, fullscreen %u, target %p stub!\n", iface, fullscreen, target);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE dxgi_swapchain_GetFullscreenState(IDXGISwapChain *iface,
|
|
|
|
BOOL *fullscreen, IDXGIOutput **target)
|
|
|
|
{
|
|
|
|
FIXME("iface %p, fullscreen %p, target %p stub!\n", iface, fullscreen, target);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE dxgi_swapchain_GetDesc(IDXGISwapChain *iface, DXGI_SWAP_CHAIN_DESC *desc)
|
|
|
|
{
|
2012-09-24 20:01:29 +02:00
|
|
|
struct dxgi_swapchain *swapchain = impl_from_IDXGISwapChain(iface);
|
|
|
|
struct wined3d_swapchain_desc wined3d_desc;
|
2008-10-29 09:00:26 +01:00
|
|
|
|
2012-09-24 20:01:29 +02:00
|
|
|
FIXME("iface %p, desc %p partial stub!\n", iface, desc);
|
|
|
|
|
|
|
|
if (desc == NULL)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
EnterCriticalSection(&dxgi_cs);
|
2012-10-04 13:53:28 +02:00
|
|
|
wined3d_swapchain_get_desc(swapchain->wined3d_swapchain, &wined3d_desc);
|
2012-09-24 20:01:29 +02:00
|
|
|
LeaveCriticalSection(&dxgi_cs);
|
|
|
|
|
|
|
|
FIXME("Ignoring ScanlineOrdering, Scaling, SwapEffect and Flags\n");
|
|
|
|
|
|
|
|
desc->BufferDesc.Width = wined3d_desc.backbuffer_width;
|
|
|
|
desc->BufferDesc.Height = wined3d_desc.backbuffer_height;
|
|
|
|
desc->BufferDesc.RefreshRate.Numerator = wined3d_desc.refresh_rate;
|
|
|
|
desc->BufferDesc.RefreshRate.Denominator = 1;
|
|
|
|
desc->BufferDesc.Format = dxgi_format_from_wined3dformat(wined3d_desc.backbuffer_format);
|
|
|
|
desc->BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
|
|
|
|
desc->BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
|
|
|
|
desc->SampleDesc.Count = wined3d_desc.multisample_type;
|
|
|
|
desc->SampleDesc.Quality = wined3d_desc.multisample_quality;
|
|
|
|
desc->BufferCount = wined3d_desc.backbuffer_count;
|
|
|
|
desc->OutputWindow = wined3d_desc.device_window;
|
|
|
|
desc->Windowed = wined3d_desc.windowed;
|
|
|
|
desc->SwapEffect = DXGI_SWAP_EFFECT_DISCARD;
|
|
|
|
desc->Flags = 0;
|
|
|
|
|
2012-10-04 13:53:28 +02:00
|
|
|
return S_OK;
|
2008-10-29 09:00:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE dxgi_swapchain_ResizeBuffers(IDXGISwapChain *iface,
|
|
|
|
UINT buffer_count, UINT width, UINT height, DXGI_FORMAT format, UINT flags)
|
|
|
|
{
|
|
|
|
FIXME("iface %p, buffer_count %u, width %u, height %u, format %s, flags %#x stub!\n",
|
|
|
|
iface, buffer_count, width, height, debug_dxgi_format(format), flags);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE dxgi_swapchain_ResizeTarget(IDXGISwapChain *iface,
|
|
|
|
const DXGI_MODE_DESC *target_mode_desc)
|
|
|
|
{
|
|
|
|
FIXME("iface %p, target_mode_desc %p stub!\n", iface, target_mode_desc);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE dxgi_swapchain_GetContainingOutput(IDXGISwapChain *iface, IDXGIOutput **output)
|
|
|
|
{
|
|
|
|
FIXME("iface %p, output %p stub!\n", iface, output);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE dxgi_swapchain_GetFrameStatistics(IDXGISwapChain *iface, DXGI_FRAME_STATISTICS *stats)
|
|
|
|
{
|
|
|
|
FIXME("iface %p, stats %p stub!\n", iface, stats);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE dxgi_swapchain_GetLastPresentCount(IDXGISwapChain *iface, UINT *last_present_count)
|
|
|
|
{
|
|
|
|
FIXME("iface %p, last_present_count %p stub!\n", iface, last_present_count);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2009-12-28 17:38:05 +01:00
|
|
|
static const struct IDXGISwapChainVtbl dxgi_swapchain_vtbl =
|
2008-10-29 09:00:26 +01:00
|
|
|
{
|
|
|
|
/* IUnknown methods */
|
|
|
|
dxgi_swapchain_QueryInterface,
|
|
|
|
dxgi_swapchain_AddRef,
|
|
|
|
dxgi_swapchain_Release,
|
|
|
|
/* IDXGIObject methods */
|
|
|
|
dxgi_swapchain_SetPrivateData,
|
|
|
|
dxgi_swapchain_SetPrivateDataInterface,
|
|
|
|
dxgi_swapchain_GetPrivateData,
|
|
|
|
dxgi_swapchain_GetParent,
|
|
|
|
/* IDXGIDeviceSubObject methods */
|
|
|
|
dxgi_swapchain_GetDevice,
|
|
|
|
/* IDXGISwapChain methods */
|
|
|
|
dxgi_swapchain_Present,
|
|
|
|
dxgi_swapchain_GetBuffer,
|
|
|
|
dxgi_swapchain_SetFullscreenState,
|
|
|
|
dxgi_swapchain_GetFullscreenState,
|
|
|
|
dxgi_swapchain_GetDesc,
|
|
|
|
dxgi_swapchain_ResizeBuffers,
|
|
|
|
dxgi_swapchain_ResizeTarget,
|
|
|
|
dxgi_swapchain_GetContainingOutput,
|
|
|
|
dxgi_swapchain_GetFrameStatistics,
|
|
|
|
dxgi_swapchain_GetLastPresentCount,
|
|
|
|
};
|
2009-12-28 17:38:05 +01:00
|
|
|
|
2011-04-07 18:46:01 +02:00
|
|
|
static void STDMETHODCALLTYPE dxgi_swapchain_wined3d_object_released(void *parent)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wined3d_parent_ops dxgi_swapchain_wined3d_parent_ops =
|
|
|
|
{
|
|
|
|
dxgi_swapchain_wined3d_object_released,
|
|
|
|
};
|
|
|
|
|
2009-12-28 17:38:05 +01:00
|
|
|
HRESULT dxgi_swapchain_init(struct dxgi_swapchain *swapchain, struct dxgi_device *device,
|
2011-12-02 08:15:52 +01:00
|
|
|
struct wined3d_swapchain_desc *desc)
|
2009-12-28 17:38:05 +01:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
2011-06-06 10:25:49 +02:00
|
|
|
swapchain->IDXGISwapChain_iface.lpVtbl = &dxgi_swapchain_vtbl;
|
2009-12-28 17:38:05 +01:00
|
|
|
swapchain->refcount = 1;
|
|
|
|
|
2011-12-02 08:15:52 +01:00
|
|
|
hr = wined3d_swapchain_create(device->wined3d_device, desc,
|
2012-01-20 00:36:28 +01:00
|
|
|
WINED3D_SURFACE_TYPE_OPENGL, swapchain, &dxgi_swapchain_wined3d_parent_ops,
|
2011-04-07 18:46:01 +02:00
|
|
|
&swapchain->wined3d_swapchain);
|
2009-12-28 17:38:05 +01:00
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
WARN("Failed to create wined3d swapchain, hr %#x.\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|