dplayx: Adjust GetCaps behaviour to documentation
[wine/gsoc_dplay.git] / dlls / d3d9 / query.c
bloba17d2e8402ad7e71ebf11efef87e2b9abea3c232
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;
31 TRACE("(%p) Relay\n", This);
33 if (IsEqualGUID(riid, &IID_IUnknown)
34 || IsEqualGUID(riid, &IID_IDirect3DQuery9)) {
35 IDirect3DQuery9_AddRef(iface);
36 *ppobj = This;
37 return S_OK;
40 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
41 *ppobj = NULL;
42 return E_NOINTERFACE;
45 static ULONG WINAPI IDirect3DQuery9Impl_AddRef(LPDIRECT3DQUERY9 iface) {
46 IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
47 ULONG ref = InterlockedIncrement(&This->ref);
49 TRACE("(%p) : AddRef from %d\n", This, ref - 1);
50 return ref;
53 static ULONG WINAPI IDirect3DQuery9Impl_Release(LPDIRECT3DQUERY9 iface) {
54 IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
55 ULONG ref = InterlockedDecrement(&This->ref);
57 TRACE("(%p) : ReleaseRef to %d\n", This, ref);
59 if (ref == 0) {
60 wined3d_mutex_lock();
61 IWineD3DQuery_Release(This->wineD3DQuery);
62 wined3d_mutex_unlock();
64 IDirect3DDevice9Ex_Release(This->parentDevice);
65 HeapFree(GetProcessHeap(), 0, This);
67 return ref;
70 /* IDirect3DQuery9 Interface follow: */
71 static HRESULT WINAPI IDirect3DQuery9Impl_GetDevice(LPDIRECT3DQUERY9 iface, IDirect3DDevice9** ppDevice) {
72 IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
73 IWineD3DDevice* pDevice;
74 HRESULT hr;
76 TRACE("(%p) Relay\n", This);
78 wined3d_mutex_lock();
79 hr = IWineD3DQuery_GetDevice(This->wineD3DQuery, &pDevice);
80 if(hr != D3D_OK){
81 *ppDevice = NULL;
82 }else{
83 hr = IWineD3DDevice_GetParent(pDevice, (IUnknown **)ppDevice);
84 IWineD3DDevice_Release(pDevice);
86 wined3d_mutex_unlock();
88 return hr;
91 static D3DQUERYTYPE WINAPI IDirect3DQuery9Impl_GetType(LPDIRECT3DQUERY9 iface) {
92 IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
93 HRESULT hr;
94 TRACE("(%p) Relay\n", This);
96 wined3d_mutex_lock();
97 hr = IWineD3DQuery_GetType(This->wineD3DQuery);
98 wined3d_mutex_unlock();
100 return hr;
103 static DWORD WINAPI IDirect3DQuery9Impl_GetDataSize(LPDIRECT3DQUERY9 iface) {
104 IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
105 DWORD ret;
106 TRACE("(%p) Relay\n", This);
108 wined3d_mutex_lock();
109 ret = IWineD3DQuery_GetDataSize(This->wineD3DQuery);
110 wined3d_mutex_unlock();
112 return ret;
115 static HRESULT WINAPI IDirect3DQuery9Impl_Issue(LPDIRECT3DQUERY9 iface, DWORD dwIssueFlags) {
116 IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
117 HRESULT hr;
118 TRACE("(%p) Relay\n", This);
120 wined3d_mutex_lock();
121 hr = IWineD3DQuery_Issue(This->wineD3DQuery, dwIssueFlags);
122 wined3d_mutex_unlock();
124 return hr;
127 static HRESULT WINAPI IDirect3DQuery9Impl_GetData(LPDIRECT3DQUERY9 iface, void* pData, DWORD dwSize, DWORD dwGetDataFlags) {
128 IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
129 HRESULT hr;
130 TRACE("(%p) Relay\n", This);
132 wined3d_mutex_lock();
133 hr = IWineD3DQuery_GetData(This->wineD3DQuery, pData, dwSize, dwGetDataFlags);
134 wined3d_mutex_unlock();
136 return hr;
140 static const IDirect3DQuery9Vtbl Direct3DQuery9_Vtbl =
142 IDirect3DQuery9Impl_QueryInterface,
143 IDirect3DQuery9Impl_AddRef,
144 IDirect3DQuery9Impl_Release,
145 IDirect3DQuery9Impl_GetDevice,
146 IDirect3DQuery9Impl_GetType,
147 IDirect3DQuery9Impl_GetDataSize,
148 IDirect3DQuery9Impl_Issue,
149 IDirect3DQuery9Impl_GetData
153 /* IDirect3DDevice9 IDirect3DQuery9 Methods follow: */
154 HRESULT WINAPI IDirect3DDevice9Impl_CreateQuery(LPDIRECT3DDEVICE9EX iface, D3DQUERYTYPE Type, IDirect3DQuery9** ppQuery) {
155 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
156 IDirect3DQuery9Impl *object = NULL;
157 HRESULT hr = D3D_OK;
159 TRACE("(%p) Relay\n", This);
161 if (!ppQuery)
163 wined3d_mutex_lock();
164 hr = IWineD3DDevice_CreateQuery(This->WineD3DDevice, Type, NULL, NULL);
165 wined3d_mutex_unlock();
167 return hr;
170 /* Allocate the storage for the device */
171 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DQuery9Impl));
172 if (NULL == object) {
173 ERR("Allocation of memory failed, returning D3DERR_OUTOFVIDEOMEMORY\n");
174 return D3DERR_OUTOFVIDEOMEMORY;
177 object->lpVtbl = &Direct3DQuery9_Vtbl;
178 object->ref = 1;
180 wined3d_mutex_lock();
181 hr = IWineD3DDevice_CreateQuery(This->WineD3DDevice, Type, &object->wineD3DQuery, (IUnknown *)object);
182 wined3d_mutex_unlock();
184 if (FAILED(hr)) {
186 /* free up object */
187 WARN("(%p) call to IWineD3DDevice_CreateQuery failed\n", This);
188 HeapFree(GetProcessHeap(), 0, object);
189 } else {
190 IDirect3DDevice9Ex_AddRef(iface);
191 object->parentDevice = iface;
192 *ppQuery = (LPDIRECT3DQUERY9) object;
193 TRACE("(%p) : Created query %p\n", This , object);
195 TRACE("(%p) : returning %x\n", This, hr);
196 return hr;