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
|
|
|
*/
|
|
|
|
|
2003-04-12 02:06:42 +02:00
|
|
|
#include "config.h"
|
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);
|
2011-04-07 18:46:01 +02:00
|
|
|
wined3d_mutex_lock();
|
2012-05-22 18:01:08 +02:00
|
|
|
wined3d_swapchain_incref(swapchain->wined3d_swapchain);
|
2011-04-07 18:46:01 +02:00
|
|
|
wined3d_mutex_unlock();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2009-08-25 08:17:14 +02:00
|
|
|
wined3d_mutex_lock();
|
2012-05-22 18:01:08 +02:00
|
|
|
wined3d_swapchain_decref(swapchain->wined3d_swapchain);
|
2009-08-25 08:17:14 +02:00
|
|
|
wined3d_mutex_unlock();
|
|
|
|
|
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);
|
2007-05-26 22:57:43 +02:00
|
|
|
HRESULT hr;
|
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;
|
|
|
|
|
2009-08-25 08:17:14 +02:00
|
|
|
wined3d_mutex_lock();
|
2012-05-22 18:01:08 +02:00
|
|
|
hr = wined3d_swapchain_present(swapchain->wined3d_swapchain, src_rect,
|
|
|
|
dst_rect, dst_window_override, dirty_region, 0);
|
2009-08-25 08:17:14 +02:00
|
|
|
wined3d_mutex_unlock();
|
|
|
|
|
2007-05-26 22:57:43 +02:00
|
|
|
return hr;
|
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);
|
2011-04-29 13:03:41 +02:00
|
|
|
struct wined3d_surface *wined3d_surface = NULL;
|
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
|
|
|
|
2009-08-25 08:17:14 +02:00
|
|
|
wined3d_mutex_lock();
|
2012-10-04 13:53:27 +02:00
|
|
|
if ((wined3d_surface = wined3d_swapchain_get_back_buffer(swapchain->wined3d_swapchain,
|
|
|
|
backbuffer_idx, (enum wined3d_backbuffer_type)backbuffer_type)))
|
2010-08-31 18:41:40 +02:00
|
|
|
{
|
2012-04-19 20:44:56 +02:00
|
|
|
surface_impl = wined3d_surface_get_parent(wined3d_surface);
|
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
|
|
|
|
{
|
|
|
|
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)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wined3d_parent_ops d3d8_swapchain_wined3d_parent_ops =
|
|
|
|
{
|
|
|
|
d3d8_swapchain_wined3d_object_released,
|
|
|
|
};
|
|
|
|
|
2012-07-02 14:45:59 +02:00
|
|
|
static HRESULT swapchain_init(struct d3d8_swapchain *swapchain, struct d3d8_device *device,
|
2012-07-02 14:45:58 +02:00
|
|
|
struct wined3d_swapchain_desc *desc)
|
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;
|
2009-12-20 20:41:35 +01:00
|
|
|
|
|
|
|
wined3d_mutex_lock();
|
2013-01-16 08:51:49 +01:00
|
|
|
hr = wined3d_swapchain_create(device->wined3d_device, desc, swapchain,
|
|
|
|
&d3d8_swapchain_wined3d_parent_ops, &swapchain->wined3d_swapchain);
|
2009-12-20 20:41:35 +01:00
|
|
|
wined3d_mutex_unlock();
|
|
|
|
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
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,
|
|
|
|
struct d3d8_swapchain **swapchain)
|
|
|
|
{
|
|
|
|
struct d3d8_swapchain *object;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
|
|
|
|
if (FAILED(hr = swapchain_init(object, device, desc)))
|
|
|
|
{
|
|
|
|
WARN("Failed to initialize swapchain, hr %#x.\n", hr);
|
|
|
|
HeapFree(GetProcessHeap(), 0, object);
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
TRACE("Created swapchain %p.\n", object);
|
|
|
|
*swapchain = object;
|
|
|
|
|
|
|
|
return D3D_OK;
|
|
|
|
}
|