2 * IDirect3DQuery9 implementation
4 * Copyright 2002-2003 Raphael Junqueira
5 * Copyright 2002-2003 Jason Edmeades
6 * Copyright 2005 Oliver Stieber
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "d3d9_private.h"
25 static inline struct d3d9_query
*impl_from_IDirect3DQuery9(IDirect3DQuery9
*iface
)
27 return CONTAINING_RECORD(iface
, struct d3d9_query
, IDirect3DQuery9_iface
);
30 static HRESULT WINAPI
d3d9_query_QueryInterface(IDirect3DQuery9
*iface
, REFIID riid
, void **out
)
32 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), out
);
34 if (IsEqualGUID(riid
, &IID_IDirect3DQuery9
)
35 || IsEqualGUID(riid
, &IID_IUnknown
))
37 IDirect3DQuery9_AddRef(iface
);
42 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
48 static ULONG WINAPI
d3d9_query_AddRef(IDirect3DQuery9
*iface
)
50 struct d3d9_query
*query
= impl_from_IDirect3DQuery9(iface
);
51 ULONG refcount
= InterlockedIncrement(&query
->refcount
);
53 TRACE("%p increasing refcount to %u.\n", iface
, refcount
);
58 static ULONG WINAPI
d3d9_query_Release(IDirect3DQuery9
*iface
)
60 struct d3d9_query
*query
= impl_from_IDirect3DQuery9(iface
);
61 ULONG refcount
= InterlockedDecrement(&query
->refcount
);
63 TRACE("%p decreasing refcount to %u.\n", iface
, refcount
);
68 wined3d_query_decref(query
->wined3d_query
);
69 wined3d_mutex_unlock();
71 IDirect3DDevice9Ex_Release(query
->parent_device
);
72 HeapFree(GetProcessHeap(), 0, query
);
77 static HRESULT WINAPI
d3d9_query_GetDevice(IDirect3DQuery9
*iface
, IDirect3DDevice9
**device
)
79 struct d3d9_query
*query
= impl_from_IDirect3DQuery9(iface
);
81 TRACE("iface %p, device %p.\n", iface
, device
);
83 *device
= (IDirect3DDevice9
*)query
->parent_device
;
84 IDirect3DDevice9_AddRef(*device
);
86 TRACE("Returning device %p.\n", *device
);
91 static D3DQUERYTYPE WINAPI
d3d9_query_GetType(IDirect3DQuery9
*iface
)
93 struct d3d9_query
*query
= impl_from_IDirect3DQuery9(iface
);
96 TRACE("iface %p.\n", iface
);
99 type
= wined3d_query_get_type(query
->wined3d_query
);
100 wined3d_mutex_unlock();
105 static DWORD WINAPI
d3d9_query_GetDataSize(IDirect3DQuery9
*iface
)
107 struct d3d9_query
*query
= impl_from_IDirect3DQuery9(iface
);
108 enum wined3d_query_type type
;
111 TRACE("iface %p.\n", iface
);
113 wined3d_mutex_lock();
114 type
= wined3d_query_get_type(query
->wined3d_query
);
115 if (type
== WINED3D_QUERY_TYPE_TIMESTAMP_DISJOINT
)
118 ret
= wined3d_query_get_data_size(query
->wined3d_query
);
119 wined3d_mutex_unlock();
124 static HRESULT WINAPI
d3d9_query_Issue(IDirect3DQuery9
*iface
, DWORD flags
)
126 struct d3d9_query
*query
= impl_from_IDirect3DQuery9(iface
);
129 TRACE("iface %p, flags %#x.\n", iface
, flags
);
131 wined3d_mutex_lock();
132 hr
= wined3d_query_issue(query
->wined3d_query
, flags
);
133 wined3d_mutex_unlock();
138 static HRESULT WINAPI
d3d9_query_GetData(IDirect3DQuery9
*iface
, void *data
, DWORD size
, DWORD flags
)
140 struct d3d9_query
*query
= impl_from_IDirect3DQuery9(iface
);
141 enum wined3d_query_type type
;
144 TRACE("iface %p, data %p, size %u, flags %#x.\n",
145 iface
, data
, size
, flags
);
147 wined3d_mutex_lock();
148 type
= wined3d_query_get_type(query
->wined3d_query
);
149 if (type
== WINED3D_QUERY_TYPE_TIMESTAMP_DISJOINT
&& data
)
151 struct wined3d_query_data_timestamp_disjoint data_disjoint
;
153 hr
= wined3d_query_get_data(query
->wined3d_query
, &data_disjoint
, sizeof(data_disjoint
), flags
);
154 *(BOOL
*)data
= data_disjoint
.disjoint
;
158 hr
= wined3d_query_get_data(query
->wined3d_query
, data
, size
, flags
);
160 wined3d_mutex_unlock();
166 static const struct IDirect3DQuery9Vtbl d3d9_query_vtbl
=
168 d3d9_query_QueryInterface
,
171 d3d9_query_GetDevice
,
173 d3d9_query_GetDataSize
,
178 HRESULT
query_init(struct d3d9_query
*query
, struct d3d9_device
*device
, D3DQUERYTYPE type
)
182 query
->IDirect3DQuery9_iface
.lpVtbl
= &d3d9_query_vtbl
;
185 wined3d_mutex_lock();
186 hr
= wined3d_query_create(device
->wined3d_device
, type
, &query
->wined3d_query
);
187 wined3d_mutex_unlock();
190 WARN("Failed to create wined3d query, hr %#x.\n", hr
);
194 query
->parent_device
= &device
->IDirect3DDevice9Ex_iface
;
195 IDirect3DDevice9Ex_AddRef(query
->parent_device
);