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