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))
|
|
|
|
{
|
2006-02-25 12:15:08 +00:00
|
|
|
IUnknown_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);
|
2011-04-07 16:46:01 +00:00
|
|
|
wined3d_mutex_lock();
|
2012-05-22 16:01:08 +00:00
|
|
|
wined3d_swapchain_incref(swapchain->wined3d_swapchain);
|
2011-04-07 16:46:01 +00:00
|
|
|
wined3d_mutex_unlock();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2009-08-25 06:17:14 +00:00
|
|
|
wined3d_mutex_lock();
|
2012-05-22 16:01:08 +00:00
|
|
|
wined3d_swapchain_decref(swapchain->wined3d_swapchain);
|
2009-08-25 06:17:14 +00:00
|
|
|
wined3d_mutex_unlock();
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2012-05-22 16:01:08 +00:00
|
|
|
static HRESULT WINAPI d3d8_swapchain_Present(IDirect3DSwapChain8 *iface,
|
|
|
|
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);
|
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
|
|
|
|
2009-08-25 06:17:14 +00:00
|
|
|
wined3d_mutex_lock();
|
2012-05-22 16:01:08 +00:00
|
|
|
hr = wined3d_swapchain_present(swapchain->wined3d_swapchain, src_rect,
|
|
|
|
dst_rect, dst_window_override, dirty_region, 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);
|
2011-04-29 11:03:41 +00:00
|
|
|
struct wined3d_surface *wined3d_surface = NULL;
|
2012-05-23 16:14:33 +00:00
|
|
|
struct d3d8_surface *surface_impl;
|
2010-08-31 16:41:40 +00:00
|
|
|
HRESULT hr;
|
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
|
|
|
|
2009-08-25 06:17:14 +00:00
|
|
|
wined3d_mutex_lock();
|
2012-05-22 16:01:08 +00:00
|
|
|
hr = wined3d_swapchain_get_back_buffer(swapchain->wined3d_swapchain,
|
|
|
|
backbuffer_idx, (enum wined3d_backbuffer_type)backbuffer_type, &wined3d_surface);
|
2011-04-29 11:03:41 +00:00
|
|
|
if (SUCCEEDED(hr) && wined3d_surface)
|
2010-08-31 16:41:40 +00:00
|
|
|
{
|
2012-04-19 18:44:56 +00:00
|
|
|
surface_impl = wined3d_surface_get_parent(wined3d_surface);
|
2012-05-22 16:01:08 +00:00
|
|
|
*backbuffer = &surface_impl->IDirect3DSurface8_iface;
|
|
|
|
IDirect3DSurface8_AddRef(*backbuffer);
|
2011-04-29 11:03:41 +00:00
|
|
|
wined3d_surface_decref(wined3d_surface);
|
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)
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, parent);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wined3d_parent_ops d3d8_swapchain_wined3d_parent_ops =
|
|
|
|
{
|
|
|
|
d3d8_swapchain_wined3d_object_released,
|
|
|
|
};
|
|
|
|
|
2012-05-22 16:01:08 +00:00
|
|
|
HRESULT swapchain_init(struct d3d8_swapchain *swapchain, struct d3d8_device *device,
|
2012-07-02 12:45:58 +00:00
|
|
|
struct wined3d_swapchain_desc *desc)
|
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;
|
2009-12-20 19:41:35 +00:00
|
|
|
|
|
|
|
wined3d_mutex_lock();
|
2012-07-02 12:45:58 +00:00
|
|
|
hr = wined3d_swapchain_create(device->wined3d_device, desc,
|
2012-01-19 23:36:28 +00:00
|
|
|
WINED3D_SURFACE_TYPE_OPENGL, swapchain, &d3d8_swapchain_wined3d_parent_ops,
|
2011-04-13 17:14:31 +00:00
|
|
|
&swapchain->wined3d_swapchain);
|
2009-12-20 19:41:35 +00:00
|
|
|
wined3d_mutex_unlock();
|
|
|
|
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|