kernel32/tests: Comment out an UpdateResource call that causes failures.
[wine.git] / dlls / d3d9 / query.c
blob9eeabc80ca14b426b7bd1126a806d9acda5eefc2
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 IUnknown_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 EnterCriticalSection(&d3d9_cs);
61 IWineD3DQuery_Release(This->wineD3DQuery);
62 LeaveCriticalSection(&d3d9_cs);
63 IUnknown_Release(This->parentDevice);
64 HeapFree(GetProcessHeap(), 0, This);
66 return ref;
69 /* IDirect3DQuery9 Interface follow: */
70 static HRESULT WINAPI IDirect3DQuery9Impl_GetDevice(LPDIRECT3DQUERY9 iface, IDirect3DDevice9** ppDevice) {
71 IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
72 IWineD3DDevice* pDevice;
73 HRESULT hr;
75 TRACE("(%p) Relay\n", This);
77 EnterCriticalSection(&d3d9_cs);
78 hr = IWineD3DQuery_GetDevice(This->wineD3DQuery, &pDevice);
79 if(hr != D3D_OK){
80 *ppDevice = NULL;
81 }else{
82 hr = IWineD3DDevice_GetParent(pDevice, (IUnknown **)ppDevice);
83 IWineD3DDevice_Release(pDevice);
85 LeaveCriticalSection(&d3d9_cs);
86 return hr;
89 static D3DQUERYTYPE WINAPI IDirect3DQuery9Impl_GetType(LPDIRECT3DQUERY9 iface) {
90 IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
91 HRESULT hr;
92 TRACE("(%p) Relay\n", This);
94 EnterCriticalSection(&d3d9_cs);
95 hr = IWineD3DQuery_GetType(This->wineD3DQuery);
96 LeaveCriticalSection(&d3d9_cs);
97 return hr;
100 static DWORD WINAPI IDirect3DQuery9Impl_GetDataSize(LPDIRECT3DQUERY9 iface) {
101 IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
102 DWORD ret;
103 TRACE("(%p) Relay\n", This);
105 EnterCriticalSection(&d3d9_cs);
106 ret = IWineD3DQuery_GetDataSize(This->wineD3DQuery);
107 LeaveCriticalSection(&d3d9_cs);
108 return ret;
111 static HRESULT WINAPI IDirect3DQuery9Impl_Issue(LPDIRECT3DQUERY9 iface, DWORD dwIssueFlags) {
112 IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
113 HRESULT hr;
114 TRACE("(%p) Relay\n", This);
116 EnterCriticalSection(&d3d9_cs);
117 hr = IWineD3DQuery_Issue(This->wineD3DQuery, dwIssueFlags);
118 LeaveCriticalSection(&d3d9_cs);
119 return hr;
122 static HRESULT WINAPI IDirect3DQuery9Impl_GetData(LPDIRECT3DQUERY9 iface, void* pData, DWORD dwSize, DWORD dwGetDataFlags) {
123 IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
124 HRESULT hr;
125 TRACE("(%p) Relay\n", This);
127 EnterCriticalSection(&d3d9_cs);
128 hr = IWineD3DQuery_GetData(This->wineD3DQuery, pData, dwSize, dwGetDataFlags);
129 LeaveCriticalSection(&d3d9_cs);
130 return hr;
134 static const IDirect3DQuery9Vtbl Direct3DQuery9_Vtbl =
136 IDirect3DQuery9Impl_QueryInterface,
137 IDirect3DQuery9Impl_AddRef,
138 IDirect3DQuery9Impl_Release,
139 IDirect3DQuery9Impl_GetDevice,
140 IDirect3DQuery9Impl_GetType,
141 IDirect3DQuery9Impl_GetDataSize,
142 IDirect3DQuery9Impl_Issue,
143 IDirect3DQuery9Impl_GetData
147 /* IDirect3DDevice9 IDirect3DQuery9 Methods follow: */
148 HRESULT WINAPI IDirect3DDevice9Impl_CreateQuery(LPDIRECT3DDEVICE9EX iface, D3DQUERYTYPE Type, IDirect3DQuery9** ppQuery) {
149 IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
150 IDirect3DQuery9Impl *object = NULL;
151 HRESULT hr = D3D_OK;
153 TRACE("(%p) Relay\n", This);
155 if (!ppQuery)
157 EnterCriticalSection(&d3d9_cs);
158 hr = IWineD3DDevice_CreateQuery(This->WineD3DDevice, Type, NULL, NULL);
159 LeaveCriticalSection(&d3d9_cs);
160 return hr;
163 /* Allocate the storage for the device */
164 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DQuery9Impl));
165 if (NULL == object) {
166 FIXME("Allocation of memory failed, returning D3DERR_OUTOFVIDEOMEMORY\n");
167 return D3DERR_OUTOFVIDEOMEMORY;
170 object->lpVtbl = &Direct3DQuery9_Vtbl;
171 object->ref = 1;
172 EnterCriticalSection(&d3d9_cs);
173 hr = IWineD3DDevice_CreateQuery(This->WineD3DDevice, Type, &object->wineD3DQuery, (IUnknown *)object);
174 LeaveCriticalSection(&d3d9_cs);
176 if (FAILED(hr)) {
178 /* free up object */
179 FIXME("(%p) call to IWineD3DDevice_CreateQuery failed\n", This);
180 HeapFree(GetProcessHeap(), 0, object);
181 } else {
182 IUnknown_AddRef(iface);
183 object->parentDevice = iface;
184 *ppQuery = (LPDIRECT3DQUERY9) object;
185 TRACE("(%p) : Created query %p\n", This , object);
187 TRACE("(%p) : returning %x\n", This, hr);
188 return hr;