Sweden-Number/dlls/d3d9/query.c

207 lines
5.8 KiB
C
Raw Normal View History

/*
* IDirect3DQuery9 implementation
*
* Copyright 2002-2003 Raphael Junqueira
* Copyright 2002-2003 Jason Edmeades
* Copyright 2005 Oliver Stieber
*
* 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
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
*/
#include "config.h"
#include "d3d9_private.h"
WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
2012-06-12 17:03:48 +02:00
static inline struct d3d9_query *impl_from_IDirect3DQuery9(IDirect3DQuery9 *iface)
{
2012-06-12 17:03:48 +02:00
return CONTAINING_RECORD(iface, struct d3d9_query, IDirect3DQuery9_iface);
}
2012-06-12 17:03:48 +02:00
static HRESULT WINAPI d3d9_query_QueryInterface(IDirect3DQuery9 *iface, REFIID riid, void **out)
{
2015-09-16 19:23:29 +02:00
TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
if (IsEqualGUID(riid, &IID_IDirect3DQuery9)
|| IsEqualGUID(riid, &IID_IUnknown))
{
IDirect3DQuery9_AddRef(iface);
2012-06-12 17:03:48 +02:00
*out = iface;
return S_OK;
}
WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
2012-06-12 17:03:48 +02:00
*out = NULL;
return E_NOINTERFACE;
}
2012-06-12 17:03:48 +02:00
static ULONG WINAPI d3d9_query_AddRef(IDirect3DQuery9 *iface)
{
2012-06-12 17:03:48 +02:00
struct d3d9_query *query = impl_from_IDirect3DQuery9(iface);
ULONG refcount = InterlockedIncrement(&query->refcount);
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;
}
2012-06-12 17:03:48 +02:00
static ULONG WINAPI d3d9_query_Release(IDirect3DQuery9 *iface)
{
2012-06-12 17:03:48 +02:00
struct d3d9_query *query = impl_from_IDirect3DQuery9(iface);
ULONG refcount = InterlockedDecrement(&query->refcount);
2012-06-12 17:03:48 +02:00
TRACE("%p decreasing refcount to %u.\n", iface, refcount);
2012-06-12 17:03:48 +02:00
if (!refcount)
{
wined3d_mutex_lock();
2012-06-12 17:03:48 +02:00
wined3d_query_decref(query->wined3d_query);
wined3d_mutex_unlock();
2012-06-12 17:03:48 +02:00
IDirect3DDevice9Ex_Release(query->parent_device);
HeapFree(GetProcessHeap(), 0, query);
}
2012-06-12 17:03:48 +02:00
return refcount;
}
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);
2009-12-04 11:50:47 +01:00
TRACE("iface %p, device %p.\n", iface, device);
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-12-04 11:50:47 +01:00
return D3D_OK;
}
2012-06-12 17:03:48 +02:00
static D3DQUERYTYPE WINAPI d3d9_query_GetType(IDirect3DQuery9 *iface)
{
2012-06-12 17:03:48 +02:00
struct d3d9_query *query = impl_from_IDirect3DQuery9(iface);
D3DQUERYTYPE type;
2009-10-20 11:05:02 +02:00
TRACE("iface %p.\n", iface);
2007-06-12 10:16:23 +02:00
wined3d_mutex_lock();
2012-06-12 17:03:48 +02:00
type = wined3d_query_get_type(query->wined3d_query);
wined3d_mutex_unlock();
return type;
}
2012-06-12 17:03:48 +02:00
static DWORD WINAPI d3d9_query_GetDataSize(IDirect3DQuery9 *iface)
{
2012-06-12 17:03:48 +02:00
struct d3d9_query *query = impl_from_IDirect3DQuery9(iface);
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
wined3d_mutex_lock();
type = wined3d_query_get_type(query->wined3d_query);
if (type == WINED3D_QUERY_TYPE_OCCLUSION)
ret = sizeof(DWORD);
else if (type == WINED3D_QUERY_TYPE_TIMESTAMP_DISJOINT)
ret = sizeof(BOOL);
else
ret = wined3d_query_get_data_size(query->wined3d_query);
wined3d_mutex_unlock();
2007-06-12 10:16:23 +02:00
return ret;
}
2012-06-12 17:03:48 +02:00
static HRESULT WINAPI d3d9_query_Issue(IDirect3DQuery9 *iface, DWORD flags)
{
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
wined3d_mutex_lock();
2012-06-12 17:03:48 +02:00
hr = wined3d_query_issue(query->wined3d_query, flags);
wined3d_mutex_unlock();
2007-06-12 10:16:23 +02:00
return hr;
}
2012-06-12 17:03:48 +02:00
static HRESULT WINAPI d3d9_query_GetData(IDirect3DQuery9 *iface, void *data, DWORD size, DWORD flags)
{
2012-06-12 17:03:48 +02:00
struct d3d9_query *query = impl_from_IDirect3DQuery9(iface);
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
wined3d_mutex_lock();
type = wined3d_query_get_type(query->wined3d_query);
if (type == WINED3D_QUERY_TYPE_TIMESTAMP_DISJOINT && data)
{
struct wined3d_query_data_timestamp_disjoint data_disjoint;
if (size > sizeof(data_disjoint.disjoint))
size = sizeof(data_disjoint.disjoint);
hr = wined3d_query_get_data(query->wined3d_query, &data_disjoint, sizeof(data_disjoint), flags);
memcpy(data, &data_disjoint.disjoint, size);
}
else
{
hr = wined3d_query_get_data(query->wined3d_query, data, size, flags);
}
wined3d_mutex_unlock();
2007-06-12 10:16:23 +02:00
return hr;
}
2012-06-12 17:03:48 +02:00
static const struct IDirect3DQuery9Vtbl d3d9_query_vtbl =
{
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,
};
2012-06-12 17:03:48 +02:00
HRESULT query_init(struct d3d9_query *query, struct d3d9_device *device, D3DQUERYTYPE type)
{
HRESULT hr;
2012-06-12 17:03:48 +02:00
query->IDirect3DQuery9_iface.lpVtbl = &d3d9_query_vtbl;
query->refcount = 1;
wined3d_mutex_lock();
hr = wined3d_query_create(device->wined3d_device, type, query, &query->wined3d_query);
wined3d_mutex_unlock();
if (FAILED(hr))
2007-06-12 10:16:23 +02:00
{
WARN("Failed to create wined3d query, hr %#x.\n", hr);
2007-06-12 10:16:23 +02:00
return hr;
}
2012-06-12 17:03:48 +02:00
query->parent_device = &device->IDirect3DDevice9Ex_iface;
IDirect3DDevice9Ex_AddRef(query->parent_device);
return D3D_OK;
}