2003-07-01 03:09:17 +02:00
|
|
|
/*
|
|
|
|
* IDirect3DQuery9 implementation
|
|
|
|
*
|
|
|
|
* Copyright 2002-2003 Raphael Junqueira
|
2005-03-03 14:57:15 +01:00
|
|
|
* Copyright 2002-2003 Jason Edmeades
|
|
|
|
* Copyright 2005 Oliver Stieber
|
2003-07-01 03:09:17 +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
|
2003-07-01 03:09:17 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
#include "d3d9_private.h"
|
|
|
|
|
2005-03-03 14:57:15 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
|
2003-07-01 03:09:17 +02:00
|
|
|
|
2012-06-12 17:03:48 +02:00
|
|
|
static inline struct d3d9_query *impl_from_IDirect3DQuery9(IDirect3DQuery9 *iface)
|
2011-04-12 04:04:02 +02:00
|
|
|
{
|
2012-06-12 17:03:48 +02:00
|
|
|
return CONTAINING_RECORD(iface, struct d3d9_query, IDirect3DQuery9_iface);
|
2011-04-12 04:04:02 +02:00
|
|
|
}
|
|
|
|
|
2012-06-12 17:03:48 +02:00
|
|
|
static HRESULT WINAPI d3d9_query_QueryInterface(IDirect3DQuery9 *iface, REFIID riid, void **out)
|
2011-04-12 04:04:02 +02:00
|
|
|
{
|
2015-09-16 19:23:29 +02:00
|
|
|
TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
|
2003-07-01 03:09:17 +02:00
|
|
|
|
2012-04-01 13:12:05 +02:00
|
|
|
if (IsEqualGUID(riid, &IID_IDirect3DQuery9)
|
|
|
|
|| IsEqualGUID(riid, &IID_IUnknown))
|
|
|
|
{
|
2008-11-02 23:49:40 +01:00
|
|
|
IDirect3DQuery9_AddRef(iface);
|
2012-06-12 17:03:48 +02:00
|
|
|
*out = iface;
|
2006-06-07 15:13:29 +02:00
|
|
|
return S_OK;
|
2003-07-01 03:09:17 +02:00
|
|
|
}
|
|
|
|
|
2012-04-01 13:12:05 +02:00
|
|
|
WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
|
|
|
|
|
2012-06-12 17:03:48 +02:00
|
|
|
*out = NULL;
|
2003-07-01 03:09:17 +02:00
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
2012-06-12 17:03:48 +02:00
|
|
|
static ULONG WINAPI d3d9_query_AddRef(IDirect3DQuery9 *iface)
|
2011-04-12 04:04:02 +02:00
|
|
|
{
|
2012-06-12 17:03:48 +02:00
|
|
|
struct d3d9_query *query = impl_from_IDirect3DQuery9(iface);
|
|
|
|
ULONG refcount = InterlockedIncrement(&query->refcount);
|
2005-01-24 12:31:45 +01:00
|
|
|
|
2012-06-12 17:03:48 +02:00
|
|
|
TRACE("%p increasing refcount to %u.\n", iface, refcount);
|
2009-10-20 11:05:02 +02:00
|
|
|
|
2012-06-12 17:03:48 +02:00
|
|
|
return refcount;
|
2003-07-01 03:09:17 +02:00
|
|
|
}
|
|
|
|
|
2012-06-12 17:03:48 +02:00
|
|
|
static ULONG WINAPI d3d9_query_Release(IDirect3DQuery9 *iface)
|
2011-04-12 04:04:02 +02:00
|
|
|
{
|
2012-06-12 17:03:48 +02:00
|
|
|
struct d3d9_query *query = impl_from_IDirect3DQuery9(iface);
|
|
|
|
ULONG refcount = InterlockedDecrement(&query->refcount);
|
2005-01-24 12:31:45 +01:00
|
|
|
|
2012-06-12 17:03:48 +02:00
|
|
|
TRACE("%p decreasing refcount to %u.\n", iface, refcount);
|
2005-01-24 12:31:45 +01:00
|
|
|
|
2012-06-12 17:03:48 +02:00
|
|
|
if (!refcount)
|
|
|
|
{
|
2009-08-26 10:18:09 +02:00
|
|
|
wined3d_mutex_lock();
|
2012-06-12 17:03:48 +02:00
|
|
|
wined3d_query_decref(query->wined3d_query);
|
2009-08-26 10:18:09 +02:00
|
|
|
wined3d_mutex_unlock();
|
|
|
|
|
2012-06-12 17:03:48 +02:00
|
|
|
IDirect3DDevice9Ex_Release(query->parent_device);
|
|
|
|
HeapFree(GetProcessHeap(), 0, query);
|
2003-07-01 03:09:17 +02:00
|
|
|
}
|
2012-06-12 17:03:48 +02:00
|
|
|
return refcount;
|
2003-07-01 03:09:17 +02:00
|
|
|
}
|
|
|
|
|
2012-06-12 17:03:48 +02:00
|
|
|
static HRESULT WINAPI d3d9_query_GetDevice(IDirect3DQuery9 *iface, IDirect3DDevice9 **device)
|
2009-12-04 11:50:47 +01:00
|
|
|
{
|
2012-06-12 17:03:48 +02:00
|
|
|
struct d3d9_query *query = impl_from_IDirect3DQuery9(iface);
|
2005-03-03 14:57:15 +01:00
|
|
|
|
2009-12-04 11:50:47 +01:00
|
|
|
TRACE("iface %p, device %p.\n", iface, device);
|
2005-03-03 14:57:15 +01:00
|
|
|
|
2012-06-12 17:03:48 +02:00
|
|
|
*device = (IDirect3DDevice9 *)query->parent_device;
|
2009-12-04 11:50:47 +01:00
|
|
|
IDirect3DDevice9_AddRef(*device);
|
|
|
|
|
|
|
|
TRACE("Returning device %p.\n", *device);
|
2009-08-26 10:18:09 +02:00
|
|
|
|
2009-12-04 11:50:47 +01:00
|
|
|
return D3D_OK;
|
2003-07-01 03:09:17 +02:00
|
|
|
}
|
|
|
|
|
2012-06-12 17:03:48 +02:00
|
|
|
static D3DQUERYTYPE WINAPI d3d9_query_GetType(IDirect3DQuery9 *iface)
|
2011-04-12 04:04:02 +02:00
|
|
|
{
|
2012-06-12 17:03:48 +02:00
|
|
|
struct d3d9_query *query = impl_from_IDirect3DQuery9(iface);
|
2011-05-04 22:36:26 +02:00
|
|
|
D3DQUERYTYPE type;
|
2009-10-20 11:05:02 +02:00
|
|
|
|
|
|
|
TRACE("iface %p.\n", iface);
|
2007-06-12 10:16:23 +02:00
|
|
|
|
2009-08-26 10:18:09 +02:00
|
|
|
wined3d_mutex_lock();
|
2012-06-12 17:03:48 +02:00
|
|
|
type = wined3d_query_get_type(query->wined3d_query);
|
2009-08-26 10:18:09 +02:00
|
|
|
wined3d_mutex_unlock();
|
|
|
|
|
2011-05-04 22:36:26 +02:00
|
|
|
return type;
|
2003-07-01 03:09:17 +02:00
|
|
|
}
|
|
|
|
|
2012-06-12 17:03:48 +02:00
|
|
|
static DWORD WINAPI d3d9_query_GetDataSize(IDirect3DQuery9 *iface)
|
2011-04-12 04:04:02 +02:00
|
|
|
{
|
2012-06-12 17:03:48 +02:00
|
|
|
struct d3d9_query *query = impl_from_IDirect3DQuery9(iface);
|
2014-04-16 18:14:48 +02:00
|
|
|
enum wined3d_query_type type;
|
2007-06-12 10:16:23 +02:00
|
|
|
DWORD ret;
|
2009-10-20 11:05:02 +02:00
|
|
|
|
|
|
|
TRACE("iface %p.\n", iface);
|
2007-06-12 10:16:23 +02:00
|
|
|
|
2009-08-26 10:18:09 +02:00
|
|
|
wined3d_mutex_lock();
|
2014-04-16 18:14:48 +02:00
|
|
|
type = wined3d_query_get_type(query->wined3d_query);
|
2016-11-21 15:15:53 +01:00
|
|
|
if (type == WINED3D_QUERY_TYPE_OCCLUSION)
|
|
|
|
ret = sizeof(DWORD);
|
|
|
|
else if (type == WINED3D_QUERY_TYPE_TIMESTAMP_DISJOINT)
|
2014-04-16 18:14:48 +02:00
|
|
|
ret = sizeof(BOOL);
|
|
|
|
else
|
|
|
|
ret = wined3d_query_get_data_size(query->wined3d_query);
|
2009-08-26 10:18:09 +02:00
|
|
|
wined3d_mutex_unlock();
|
|
|
|
|
2007-06-12 10:16:23 +02:00
|
|
|
return ret;
|
2003-07-01 03:09:17 +02:00
|
|
|
}
|
|
|
|
|
2012-06-12 17:03:48 +02:00
|
|
|
static HRESULT WINAPI d3d9_query_Issue(IDirect3DQuery9 *iface, DWORD flags)
|
2011-04-12 04:04:02 +02:00
|
|
|
{
|
2012-06-12 17:03:48 +02:00
|
|
|
struct d3d9_query *query = impl_from_IDirect3DQuery9(iface);
|
2007-06-12 10:16:23 +02:00
|
|
|
HRESULT hr;
|
2009-10-20 11:05:02 +02:00
|
|
|
|
2012-06-12 17:03:48 +02:00
|
|
|
TRACE("iface %p, flags %#x.\n", iface, flags);
|
2007-06-12 10:16:23 +02:00
|
|
|
|
2009-08-26 10:18:09 +02:00
|
|
|
wined3d_mutex_lock();
|
2012-06-12 17:03:48 +02:00
|
|
|
hr = wined3d_query_issue(query->wined3d_query, flags);
|
2009-08-26 10:18:09 +02:00
|
|
|
wined3d_mutex_unlock();
|
|
|
|
|
2007-06-12 10:16:23 +02:00
|
|
|
return hr;
|
2003-07-01 03:09:17 +02:00
|
|
|
}
|
|
|
|
|
2012-06-12 17:03:48 +02:00
|
|
|
static HRESULT WINAPI d3d9_query_GetData(IDirect3DQuery9 *iface, void *data, DWORD size, DWORD flags)
|
2011-04-12 04:04:02 +02:00
|
|
|
{
|
2012-06-12 17:03:48 +02:00
|
|
|
struct d3d9_query *query = impl_from_IDirect3DQuery9(iface);
|
2014-04-16 18:14:48 +02:00
|
|
|
enum wined3d_query_type type;
|
2007-06-12 10:16:23 +02:00
|
|
|
HRESULT hr;
|
2009-10-20 11:05:02 +02:00
|
|
|
|
|
|
|
TRACE("iface %p, data %p, size %u, flags %#x.\n",
|
2012-06-12 17:03:48 +02:00
|
|
|
iface, data, size, flags);
|
2007-06-12 10:16:23 +02:00
|
|
|
|
2009-08-26 10:18:09 +02:00
|
|
|
wined3d_mutex_lock();
|
2014-04-16 18:14:48 +02:00
|
|
|
type = wined3d_query_get_type(query->wined3d_query);
|
|
|
|
if (type == WINED3D_QUERY_TYPE_TIMESTAMP_DISJOINT && data)
|
|
|
|
{
|
|
|
|
struct wined3d_query_data_timestamp_disjoint data_disjoint;
|
|
|
|
|
2014-06-13 15:08:51 +02:00
|
|
|
if (size > sizeof(data_disjoint.disjoint))
|
|
|
|
size = sizeof(data_disjoint.disjoint);
|
|
|
|
|
2014-04-16 18:14:48 +02:00
|
|
|
hr = wined3d_query_get_data(query->wined3d_query, &data_disjoint, sizeof(data_disjoint), flags);
|
2014-06-13 15:08:51 +02:00
|
|
|
memcpy(data, &data_disjoint.disjoint, size);
|
2014-04-16 18:14:48 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
hr = wined3d_query_get_data(query->wined3d_query, data, size, flags);
|
|
|
|
}
|
2009-08-26 10:18:09 +02:00
|
|
|
wined3d_mutex_unlock();
|
|
|
|
|
2007-06-12 10:16:23 +02:00
|
|
|
return hr;
|
2003-07-01 03:09:17 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-06-12 17:03:48 +02:00
|
|
|
static const struct IDirect3DQuery9Vtbl d3d9_query_vtbl =
|
2003-07-01 03:09:17 +02:00
|
|
|
{
|
2012-06-12 17:03:48 +02:00
|
|
|
d3d9_query_QueryInterface,
|
|
|
|
d3d9_query_AddRef,
|
|
|
|
d3d9_query_Release,
|
|
|
|
d3d9_query_GetDevice,
|
|
|
|
d3d9_query_GetType,
|
|
|
|
d3d9_query_GetDataSize,
|
|
|
|
d3d9_query_Issue,
|
|
|
|
d3d9_query_GetData,
|
2003-07-01 03:09:17 +02:00
|
|
|
};
|
|
|
|
|
2012-06-12 17:03:48 +02:00
|
|
|
HRESULT query_init(struct d3d9_query *query, struct d3d9_device *device, D3DQUERYTYPE type)
|
2010-01-17 21:31:29 +01:00
|
|
|
{
|
|
|
|
HRESULT hr;
|
2003-07-01 03:09:17 +02:00
|
|
|
|
2012-06-12 17:03:48 +02:00
|
|
|
query->IDirect3DQuery9_iface.lpVtbl = &d3d9_query_vtbl;
|
|
|
|
query->refcount = 1;
|
2005-11-08 13:46:21 +01:00
|
|
|
|
2010-01-17 21:31:29 +01:00
|
|
|
wined3d_mutex_lock();
|
2014-09-19 10:41:47 +02:00
|
|
|
hr = wined3d_query_create(device->wined3d_device, type, query, &query->wined3d_query);
|
2010-01-17 21:31:29 +01:00
|
|
|
wined3d_mutex_unlock();
|
|
|
|
if (FAILED(hr))
|
2007-06-12 10:16:23 +02:00
|
|
|
{
|
2010-01-17 21:31:29 +01:00
|
|
|
WARN("Failed to create wined3d query, hr %#x.\n", hr);
|
2007-06-12 10:16:23 +02:00
|
|
|
return hr;
|
|
|
|
}
|
2005-11-08 13:46:21 +01:00
|
|
|
|
2012-06-12 17:03:48 +02:00
|
|
|
query->parent_device = &device->IDirect3DDevice9Ex_iface;
|
|
|
|
IDirect3DDevice9Ex_AddRef(query->parent_device);
|
2005-11-08 13:46:21 +01:00
|
|
|
|
2010-01-17 21:31:29 +01:00
|
|
|
return D3D_OK;
|
2003-07-01 03:09:17 +02:00
|
|
|
}
|