2002-09-27 22:46:16 +00:00
|
|
|
/*
|
|
|
|
* IDirect3DSwapChain8 implementation
|
|
|
|
*
|
2006-02-25 12:15:08 +00:00
|
|
|
* Copyright 2005 Oliver Stieber
|
2002-09-27 22:46:16 +00:00
|
|
|
*
|
|
|
|
* 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
|
2006-05-18 12:49:52 +00:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
2002-09-27 22:46:16 +00:00
|
|
|
*/
|
|
|
|
|
2003-04-12 00:06:42 +00:00
|
|
|
#include "config.h"
|
2002-09-27 22:46:16 +00:00
|
|
|
#include "d3d8_private.h"
|
|
|
|
|
2006-02-25 12:15:08 +00:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(d3d8);
|
2002-09-27 22:46:16 +00:00
|
|
|
|
2012-05-22 16:01:08 +00:00
|
|
|
static inline struct d3d8_swapchain *impl_from_IDirect3DSwapChain8(IDirect3DSwapChain8 *iface)
|
2002-09-27 22:46:16 +00:00
|
|
|
{
|
2012-05-22 16:01:08 +00:00
|
|
|
return CONTAINING_RECORD(iface, struct d3d8_swapchain, IDirect3DSwapChain8_iface);
|
2011-01-31 00:40:25 +00:00
|
|
|
}
|
|
|
|
|
2012-05-22 16:01:08 +00:00
|
|
|
static HRESULT WINAPI d3d8_swapchain_QueryInterface(IDirect3DSwapChain8 *iface, REFIID riid, void **out)
|
2011-01-31 00:40:25 +00:00
|
|
|
{
|
2012-05-22 16:01:08 +00:00
|
|
|
TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
|
2009-10-19 08:12:20 +00:00
|
|
|
|
2012-03-14 21:04:31 +00:00
|
|
|
if (IsEqualGUID(riid, &IID_IDirect3DSwapChain8)
|
|
|
|
|| IsEqualGUID(riid, &IID_IUnknown))
|
|
|
|
{
|
2012-08-27 10:27:34 +00:00
|
|
|
IDirect3DSwapChain8_AddRef(iface);
|
2012-05-22 16:01:08 +00:00
|
|
|
*out = iface;
|
2006-06-07 13:13:29 +00:00
|
|
|
return S_OK;
|
2002-09-27 22:46:16 +00:00
|
|
|
}
|
|
|
|
|
2012-03-14 21:04:31 +00:00
|
|
|
WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
|
|
|
|
|
2012-05-22 16:01:08 +00:00
|
|
|
*out = NULL;
|
2002-09-27 22:46:16 +00:00
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
2012-05-22 16:01:08 +00:00
|
|
|
static ULONG WINAPI d3d8_swapchain_AddRef(IDirect3DSwapChain8 *iface)
|
2011-01-31 00:40:25 +00:00
|
|
|
{
|
2012-05-22 16:01:08 +00:00
|
|
|
struct d3d8_swapchain *swapchain = impl_from_IDirect3DSwapChain8(iface);
|
|
|
|
ULONG ref = InterlockedIncrement(&swapchain->refcount);
|
2005-01-24 11:31:45 +00:00
|
|
|
|
2009-10-19 08:12:20 +00:00
|
|
|
TRACE("%p increasing refcount to %u.\n", iface, ref);
|
2005-01-24 11:31:45 +00:00
|
|
|
|
2011-04-07 16:46:01 +00:00
|
|
|
if (ref == 1)
|
|
|
|
{
|
2012-05-22 16:01:08 +00:00
|
|
|
if (swapchain->parent_device)
|
|
|
|
IDirect3DDevice8_AddRef(swapchain->parent_device);
|
|
|
|
wined3d_swapchain_incref(swapchain->wined3d_swapchain);
|
2011-04-07 16:46:01 +00:00
|
|
|
}
|
|
|
|
|
2005-01-24 11:31:45 +00:00
|
|
|
return ref;
|
2002-09-27 22:46:16 +00:00
|
|
|
}
|
|
|
|
|
2012-05-22 16:01:08 +00:00
|
|
|
static ULONG WINAPI d3d8_swapchain_Release(IDirect3DSwapChain8 *iface)
|
2011-01-31 00:40:25 +00:00
|
|
|
{
|
2012-05-22 16:01:08 +00:00
|
|
|
struct d3d8_swapchain *swapchain = impl_from_IDirect3DSwapChain8(iface);
|
|
|
|
ULONG ref = InterlockedDecrement(&swapchain->refcount);
|
2005-01-24 11:31:45 +00:00
|
|
|
|
2009-10-19 08:12:20 +00:00
|
|
|
TRACE("%p decreasing refcount to %u.\n", iface, ref);
|
2005-01-24 11:31:45 +00:00
|
|
|
|
2011-04-07 16:46:01 +00:00
|
|
|
if (!ref)
|
|
|
|
{
|
2012-05-22 16:01:08 +00:00
|
|
|
IDirect3DDevice8 *parent_device = swapchain->parent_device;
|
2011-04-07 16:46:01 +00:00
|
|
|
|
2012-05-22 16:01:08 +00:00
|
|
|
wined3d_swapchain_decref(swapchain->wined3d_swapchain);
|
2009-08-25 06:17:14 +00:00
|
|
|
|
2012-05-22 16:01:08 +00:00
|
|
|
if (parent_device)
|
|
|
|
IDirect3DDevice8_Release(parent_device);
|
2003-06-04 22:55:19 +00:00
|
|
|
}
|
2002-09-27 22:46:16 +00:00
|
|
|
return ref;
|
|
|
|
}
|
|
|
|
|
2015-02-28 20:24:54 +00:00
|
|
|
static HRESULT WINAPI DECLSPEC_HOTPATCH d3d8_swapchain_Present(IDirect3DSwapChain8 *iface,
|
2012-05-22 16:01:08 +00:00
|
|
|
const RECT *src_rect, const RECT *dst_rect, HWND dst_window_override,
|
|
|
|
const RGNDATA *dirty_region)
|
2011-01-31 00:40:25 +00:00
|
|
|
{
|
2012-05-22 16:01:08 +00:00
|
|
|
struct d3d8_swapchain *swapchain = impl_from_IDirect3DSwapChain8(iface);
|
2014-06-30 09:17:02 +00:00
|
|
|
struct d3d8_device *device = impl_from_IDirect3DDevice8(swapchain->parent_device);
|
2007-05-26 20:57:43 +00:00
|
|
|
HRESULT hr;
|
2009-10-19 08:12:20 +00:00
|
|
|
|
2012-05-22 16:01:08 +00:00
|
|
|
TRACE("iface %p, src_rect %s, dst_rect %s, dst_window_override %p, dirty_region %p.\n",
|
|
|
|
iface, wine_dbgstr_rect(src_rect), wine_dbgstr_rect(dst_rect), dst_window_override, dirty_region);
|
2007-05-26 20:57:43 +00:00
|
|
|
|
2014-06-30 09:17:02 +00:00
|
|
|
if (device->device_state != D3D8_DEVICE_STATE_OK)
|
|
|
|
return D3DERR_DEVICELOST;
|
|
|
|
|
2016-03-17 15:30:03 +00:00
|
|
|
if (dirty_region)
|
|
|
|
FIXME("Ignoring dirty_region %p.\n", dirty_region);
|
|
|
|
|
2009-08-25 06:17:14 +00:00
|
|
|
wined3d_mutex_lock();
|
2016-03-17 15:30:03 +00:00
|
|
|
hr = wined3d_swapchain_present(swapchain->wined3d_swapchain,
|
2018-03-22 07:48:31 +00:00
|
|
|
src_rect, dst_rect, dst_window_override, swapchain->swap_interval, 0);
|
2009-08-25 06:17:14 +00:00
|
|
|
wined3d_mutex_unlock();
|
|
|
|
|
2007-05-26 20:57:43 +00:00
|
|
|
return hr;
|
2002-09-27 22:46:16 +00:00
|
|
|
}
|
2003-06-04 22:55:19 +00:00
|
|
|
|
2012-05-22 16:01:08 +00:00
|
|
|
static HRESULT WINAPI d3d8_swapchain_GetBackBuffer(IDirect3DSwapChain8 *iface,
|
|
|
|
UINT backbuffer_idx, D3DBACKBUFFER_TYPE backbuffer_type, IDirect3DSurface8 **backbuffer)
|
2010-08-31 16:41:40 +00:00
|
|
|
{
|
2012-05-22 16:01:08 +00:00
|
|
|
struct d3d8_swapchain *swapchain = impl_from_IDirect3DSwapChain8(iface);
|
2015-09-03 10:52:52 +00:00
|
|
|
struct wined3d_texture *wined3d_texture;
|
2012-05-23 16:14:33 +00:00
|
|
|
struct d3d8_surface *surface_impl;
|
2012-10-04 11:53:27 +00:00
|
|
|
HRESULT hr = D3D_OK;
|
2003-06-04 22:55:19 +00:00
|
|
|
|
2009-10-19 08:12:20 +00:00
|
|
|
TRACE("iface %p, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n",
|
2012-05-22 16:01:08 +00:00
|
|
|
iface, backbuffer_idx, backbuffer_type, backbuffer);
|
2003-06-04 22:55:19 +00:00
|
|
|
|
2015-09-07 21:50:34 +00:00
|
|
|
/* backbuffer_type is ignored by native. */
|
|
|
|
|
2015-09-03 10:52:52 +00:00
|
|
|
if (!backbuffer)
|
|
|
|
{
|
|
|
|
WARN("The output pointer is NULL, returning D3DERR_INVALIDCALL.\n");
|
|
|
|
return D3DERR_INVALIDCALL;
|
|
|
|
}
|
|
|
|
|
2009-08-25 06:17:14 +00:00
|
|
|
wined3d_mutex_lock();
|
2015-09-07 21:50:34 +00:00
|
|
|
if ((wined3d_texture = wined3d_swapchain_get_back_buffer(swapchain->wined3d_swapchain, backbuffer_idx)))
|
2010-08-31 16:41:40 +00:00
|
|
|
{
|
2016-02-17 17:35:31 +00:00
|
|
|
surface_impl = wined3d_texture_get_sub_resource_parent(wined3d_texture, 0);
|
2012-05-22 16:01:08 +00:00
|
|
|
*backbuffer = &surface_impl->IDirect3DSurface8_iface;
|
|
|
|
IDirect3DSurface8_AddRef(*backbuffer);
|
2012-10-04 11:53:27 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-09-03 10:52:52 +00:00
|
|
|
/* Do not set *backbuffer = NULL, see tests/device.c, test_swapchain(). */
|
2012-10-04 11:53:27 +00:00
|
|
|
hr = D3DERR_INVALIDCALL;
|
2006-02-25 12:15:08 +00:00
|
|
|
}
|
2009-08-25 06:17:14 +00:00
|
|
|
wined3d_mutex_unlock();
|
|
|
|
|
2010-08-31 16:41:40 +00:00
|
|
|
return hr;
|
2002-09-27 22:46:16 +00:00
|
|
|
}
|
|
|
|
|
2012-05-22 16:01:08 +00:00
|
|
|
static const IDirect3DSwapChain8Vtbl d3d8_swapchain_vtbl =
|
2002-09-27 22:46:16 +00:00
|
|
|
{
|
2012-05-22 16:01:08 +00:00
|
|
|
d3d8_swapchain_QueryInterface,
|
|
|
|
d3d8_swapchain_AddRef,
|
|
|
|
d3d8_swapchain_Release,
|
|
|
|
d3d8_swapchain_Present,
|
|
|
|
d3d8_swapchain_GetBackBuffer
|
2002-09-27 22:46:16 +00:00
|
|
|
};
|
2009-12-20 19:41:35 +00:00
|
|
|
|
2011-04-07 16:46:01 +00:00
|
|
|
static void STDMETHODCALLTYPE d3d8_swapchain_wined3d_object_released(void *parent)
|
|
|
|
{
|
2018-02-07 23:10:51 +00:00
|
|
|
heap_free(parent);
|
2011-04-07 16:46:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wined3d_parent_ops d3d8_swapchain_wined3d_parent_ops =
|
|
|
|
{
|
|
|
|
d3d8_swapchain_wined3d_object_released,
|
|
|
|
};
|
|
|
|
|
2012-07-02 12:45:59 +00:00
|
|
|
static HRESULT swapchain_init(struct d3d8_swapchain *swapchain, struct d3d8_device *device,
|
2018-03-22 07:48:32 +00:00
|
|
|
struct wined3d_swapchain_desc *desc, unsigned int swap_interval)
|
2009-12-20 19:41:35 +00:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
|
|
|
|
2012-05-22 16:01:08 +00:00
|
|
|
swapchain->refcount = 1;
|
|
|
|
swapchain->IDirect3DSwapChain8_iface.lpVtbl = &d3d8_swapchain_vtbl;
|
2018-03-22 07:48:32 +00:00
|
|
|
swapchain->swap_interval = swap_interval;
|
2009-12-20 19:41:35 +00:00
|
|
|
|
2018-11-29 13:33:46 +00:00
|
|
|
if (FAILED(hr = wined3d_swapchain_create(device->wined3d_device, desc, swapchain,
|
|
|
|
&d3d8_swapchain_wined3d_parent_ops, &swapchain->wined3d_swapchain)))
|
2009-12-20 19:41:35 +00:00
|
|
|
{
|
|
|
|
WARN("Failed to create wined3d swapchain, hr %#x.\n", hr);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2012-05-22 16:01:08 +00:00
|
|
|
swapchain->parent_device = &device->IDirect3DDevice8_iface;
|
|
|
|
IDirect3DDevice8_AddRef(swapchain->parent_device);
|
2009-12-20 19:41:35 +00:00
|
|
|
|
|
|
|
return D3D_OK;
|
|
|
|
}
|
2012-07-02 12:45:59 +00:00
|
|
|
|
|
|
|
HRESULT d3d8_swapchain_create(struct d3d8_device *device, struct wined3d_swapchain_desc *desc,
|
2018-03-22 07:48:32 +00:00
|
|
|
unsigned int swap_interval, struct d3d8_swapchain **swapchain)
|
2012-07-02 12:45:59 +00:00
|
|
|
{
|
|
|
|
struct d3d8_swapchain *object;
|
|
|
|
HRESULT hr;
|
|
|
|
|
2018-02-07 23:10:51 +00:00
|
|
|
if (!(object = heap_alloc_zero(sizeof(*object))))
|
2012-07-02 12:45:59 +00:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
2018-03-22 07:48:32 +00:00
|
|
|
if (FAILED(hr = swapchain_init(object, device, desc, swap_interval)))
|
2012-07-02 12:45:59 +00:00
|
|
|
{
|
|
|
|
WARN("Failed to initialize swapchain, hr %#x.\n", hr);
|
2018-02-07 23:10:51 +00:00
|
|
|
heap_free(object);
|
2012-07-02 12:45:59 +00:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("Created swapchain %p.\n", object);
|
|
|
|
*swapchain = object;
|
|
|
|
|
|
|
|
return D3D_OK;
|
|
|
|
}
|