push 149f0a5527ac85057a8ef03858d34d91c36f97e8
[wine/hacks.git] / dlls / d3d9 / query.c
blobecb2e718eebd1d786e9aa07205a18d64f228f0fe
1 /*
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 "config.h"
24 #include "d3d9_private.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
28 /* IDirect3DQuery9 IUnknown parts follow: */
29 static HRESULT WINAPI IDirect3DQuery9Impl_QueryInterface(LPDIRECT3DQUERY9 iface, REFIID riid, LPVOID* ppobj) {
30 IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
32 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
34 if (IsEqualGUID(riid, &IID_IUnknown)
35 || IsEqualGUID(riid, &IID_IDirect3DQuery9)) {
36 IDirect3DQuery9_AddRef(iface);
37 *ppobj = This;
38 return S_OK;
41 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
42 *ppobj = NULL;
43 return E_NOINTERFACE;
46 static ULONG WINAPI IDirect3DQuery9Impl_AddRef(LPDIRECT3DQUERY9 iface) {
47 IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
48 ULONG ref = InterlockedIncrement(&This->ref);
50 TRACE("%p increasing refcount to %u.\n", iface, ref);
52 return ref;
55 static ULONG WINAPI IDirect3DQuery9Impl_Release(LPDIRECT3DQUERY9 iface) {
56 IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
57 ULONG ref = InterlockedDecrement(&This->ref);
59 TRACE("%p decreasing refcount to %u.\n", iface, ref);
61 if (ref == 0) {
62 wined3d_mutex_lock();
63 IWineD3DQuery_Release(This->wineD3DQuery);
64 wined3d_mutex_unlock();
66 IDirect3DDevice9Ex_Release(This->parentDevice);
67 HeapFree(GetProcessHeap(), 0, This);
69 return ref;
72 /* IDirect3DQuery9 Interface follow: */
73 static HRESULT WINAPI IDirect3DQuery9Impl_GetDevice(IDirect3DQuery9 *iface, IDirect3DDevice9 **device)
75 IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
77 TRACE("iface %p, device %p.\n", iface, device);
79 *device = (IDirect3DDevice9 *)This->parentDevice;
80 IDirect3DDevice9_AddRef(*device);
82 TRACE("Returning device %p.\n", *device);
84 return D3D_OK;
87 static D3DQUERYTYPE WINAPI IDirect3DQuery9Impl_GetType(LPDIRECT3DQUERY9 iface) {
88 IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
89 HRESULT hr;
91 TRACE("iface %p.\n", iface);
93 wined3d_mutex_lock();
94 hr = IWineD3DQuery_GetType(This->wineD3DQuery);
95 wined3d_mutex_unlock();
97 return hr;
100 static DWORD WINAPI IDirect3DQuery9Impl_GetDataSize(LPDIRECT3DQUERY9 iface) {
101 IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
102 DWORD ret;
104 TRACE("iface %p.\n", iface);
106 wined3d_mutex_lock();
107 ret = IWineD3DQuery_GetDataSize(This->wineD3DQuery);
108 wined3d_mutex_unlock();
110 return ret;
113 static HRESULT WINAPI IDirect3DQuery9Impl_Issue(LPDIRECT3DQUERY9 iface, DWORD dwIssueFlags) {
114 IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
115 HRESULT hr;
117 TRACE("iface %p, flags %#x.\n", iface, dwIssueFlags);
119 wined3d_mutex_lock();
120 hr = IWineD3DQuery_Issue(This->wineD3DQuery, dwIssueFlags);
121 wined3d_mutex_unlock();
123 return hr;
126 static HRESULT WINAPI IDirect3DQuery9Impl_GetData(LPDIRECT3DQUERY9 iface, void* pData, DWORD dwSize, DWORD dwGetDataFlags) {
127 IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
128 HRESULT hr;
130 TRACE("iface %p, data %p, size %u, flags %#x.\n",
131 iface, pData, dwSize, dwGetDataFlags);
133 wined3d_mutex_lock();
134 hr = IWineD3DQuery_GetData(This->wineD3DQuery, pData, dwSize, dwGetDataFlags);
135 wined3d_mutex_unlock();
137 return hr;
141 static const IDirect3DQuery9Vtbl Direct3DQuery9_Vtbl =
143 IDirect3DQuery9Impl_QueryInterface,
144 IDirect3DQuery9Impl_AddRef,
145 IDirect3DQuery9Impl_Release,
146 IDirect3DQuery9Impl_GetDevice,
147 IDirect3DQuery9Impl_GetType,
148 IDirect3DQuery9Impl_GetDataSize,
149 IDirect3DQuery9Impl_Issue,
150 IDirect3DQuery9Impl_GetData
154 /* IDirect3DDevice9 IDirect3DQuery9 Methods follow: */
155 HRESULT WINAPI IDirect3DDevice9Impl_CreateQuery(LPDIRECT3DDEVICE9EX iface, D3DQUERYTYPE Type, IDirect3DQuery9** ppQuery) {
156 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
157 IDirect3DQuery9Impl *object = NULL;
158 HRESULT hr = D3D_OK;
160 TRACE("iface %p, type %#x, query %p.\n", iface, Type, ppQuery);
162 if (!ppQuery)
164 wined3d_mutex_lock();
165 hr = IWineD3DDevice_CreateQuery(This->WineD3DDevice, Type, NULL, NULL);
166 wined3d_mutex_unlock();
168 return hr;
171 /* Allocate the storage for the device */
172 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DQuery9Impl));
173 if (NULL == object) {
174 ERR("Allocation of memory failed, returning D3DERR_OUTOFVIDEOMEMORY\n");
175 return D3DERR_OUTOFVIDEOMEMORY;
178 object->lpVtbl = &Direct3DQuery9_Vtbl;
179 object->ref = 1;
181 wined3d_mutex_lock();
182 hr = IWineD3DDevice_CreateQuery(This->WineD3DDevice, Type, &object->wineD3DQuery, (IUnknown *)object);
183 wined3d_mutex_unlock();
185 if (FAILED(hr)) {
187 /* free up object */
188 WARN("(%p) call to IWineD3DDevice_CreateQuery failed\n", This);
189 HeapFree(GetProcessHeap(), 0, object);
190 } else {
191 IDirect3DDevice9Ex_AddRef(iface);
192 object->parentDevice = iface;
193 *ppQuery = (LPDIRECT3DQUERY9) object;
194 TRACE("(%p) : Created query %p\n", This , object);
196 TRACE("(%p) : returning %x\n", This, hr);
197 return hr;