d3d8/tests: Only run the vertex/pixel shader constant apply tests when the implementa...
[wine] / dlls / d3d9 / query.c
1 /*
2  * IDirect3DQuery9 implementation
3  *
4  * Copyright 2002-2003 Raphael Junqueira
5  * Copyright 2002-2003 Jason Edmeades
6  * Copyright 2005 Oliver Stieber
7  *
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.
12  *
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.
17  *
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
21  */
22
23 #include "config.h"
24 #include "d3d9_private.h"
25
26 WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
27
28 /* IDirect3DQuery9 IUnknown parts follow: */
29 static HRESULT WINAPI IDirect3DQuery9Impl_QueryInterface(LPDIRECT3DQUERY9 iface, REFIID riid, LPVOID* ppobj) {
30     IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
31
32     TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
33
34     if (IsEqualGUID(riid, &IID_IUnknown)
35         || IsEqualGUID(riid, &IID_IDirect3DQuery9)) {
36         IDirect3DQuery9_AddRef(iface);
37         *ppobj = This;
38         return S_OK;
39     }
40
41     WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
42     *ppobj = NULL;
43     return E_NOINTERFACE;
44 }
45
46 static ULONG WINAPI IDirect3DQuery9Impl_AddRef(LPDIRECT3DQUERY9 iface) {
47     IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
48     ULONG ref = InterlockedIncrement(&This->ref);
49
50     TRACE("%p increasing refcount to %u.\n", iface, ref);
51
52     return ref;
53 }
54
55 static ULONG WINAPI IDirect3DQuery9Impl_Release(LPDIRECT3DQUERY9 iface) {
56     IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
57     ULONG ref = InterlockedDecrement(&This->ref);
58
59     TRACE("%p decreasing refcount to %u.\n", iface, ref);
60
61     if (ref == 0) {
62         wined3d_mutex_lock();
63         IWineD3DQuery_Release(This->wineD3DQuery);
64         wined3d_mutex_unlock();
65
66         IDirect3DDevice9Ex_Release(This->parentDevice);
67         HeapFree(GetProcessHeap(), 0, This);
68     }
69     return ref;
70 }
71
72 /* IDirect3DQuery9 Interface follow: */
73 static HRESULT WINAPI IDirect3DQuery9Impl_GetDevice(LPDIRECT3DQUERY9 iface, IDirect3DDevice9** ppDevice) {
74     IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
75     IWineD3DDevice* pDevice;
76     HRESULT hr;
77
78     TRACE("iface %p, device %p.\n", iface, ppDevice);
79
80     wined3d_mutex_lock();
81     hr = IWineD3DQuery_GetDevice(This->wineD3DQuery, &pDevice);
82     if(hr != D3D_OK){
83         *ppDevice = NULL;
84     }else{
85         hr = IWineD3DDevice_GetParent(pDevice, (IUnknown **)ppDevice);
86         IWineD3DDevice_Release(pDevice);
87     }
88     wined3d_mutex_unlock();
89
90     return hr;
91 }
92
93 static D3DQUERYTYPE WINAPI IDirect3DQuery9Impl_GetType(LPDIRECT3DQUERY9 iface) {
94     IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
95     HRESULT hr;
96
97     TRACE("iface %p.\n", iface);
98
99     wined3d_mutex_lock();
100     hr = IWineD3DQuery_GetType(This->wineD3DQuery);
101     wined3d_mutex_unlock();
102
103     return hr;
104 }
105
106 static DWORD WINAPI IDirect3DQuery9Impl_GetDataSize(LPDIRECT3DQUERY9 iface) {
107     IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
108     DWORD ret;
109
110     TRACE("iface %p.\n", iface);
111
112     wined3d_mutex_lock();
113     ret = IWineD3DQuery_GetDataSize(This->wineD3DQuery);
114     wined3d_mutex_unlock();
115
116     return ret;
117 }
118
119 static HRESULT WINAPI IDirect3DQuery9Impl_Issue(LPDIRECT3DQUERY9 iface, DWORD dwIssueFlags) {
120     IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
121     HRESULT hr;
122
123     TRACE("iface %p, flags %#x.\n", iface, dwIssueFlags);
124
125     wined3d_mutex_lock();
126     hr = IWineD3DQuery_Issue(This->wineD3DQuery, dwIssueFlags);
127     wined3d_mutex_unlock();
128
129     return hr;
130 }
131
132 static HRESULT WINAPI IDirect3DQuery9Impl_GetData(LPDIRECT3DQUERY9 iface, void* pData, DWORD dwSize, DWORD dwGetDataFlags) {
133     IDirect3DQuery9Impl *This = (IDirect3DQuery9Impl *)iface;
134     HRESULT hr;
135
136     TRACE("iface %p, data %p, size %u, flags %#x.\n",
137             iface, pData, dwSize, dwGetDataFlags);
138
139     wined3d_mutex_lock();
140     hr = IWineD3DQuery_GetData(This->wineD3DQuery, pData, dwSize, dwGetDataFlags);
141     wined3d_mutex_unlock();
142
143     return hr;
144 }
145
146
147 static const IDirect3DQuery9Vtbl Direct3DQuery9_Vtbl =
148 {
149     IDirect3DQuery9Impl_QueryInterface,
150     IDirect3DQuery9Impl_AddRef,
151     IDirect3DQuery9Impl_Release,
152     IDirect3DQuery9Impl_GetDevice,
153     IDirect3DQuery9Impl_GetType,
154     IDirect3DQuery9Impl_GetDataSize,
155     IDirect3DQuery9Impl_Issue,
156     IDirect3DQuery9Impl_GetData
157 };
158
159
160 /* IDirect3DDevice9 IDirect3DQuery9 Methods follow: */
161 HRESULT WINAPI IDirect3DDevice9Impl_CreateQuery(LPDIRECT3DDEVICE9EX iface, D3DQUERYTYPE Type, IDirect3DQuery9** ppQuery) {
162     IDirect3DDevice9Impl *This = (IDirect3DDevice9Impl *)iface;
163     IDirect3DQuery9Impl *object = NULL;
164     HRESULT hr = D3D_OK;
165
166     TRACE("iface %p, type %#x, query %p.\n", iface, Type, ppQuery);
167
168     if (!ppQuery)
169     {
170         wined3d_mutex_lock();
171         hr = IWineD3DDevice_CreateQuery(This->WineD3DDevice, Type, NULL, NULL);
172         wined3d_mutex_unlock();
173
174         return hr;
175     }
176
177     /* Allocate the storage for the device */
178     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(IDirect3DQuery9Impl));
179     if (NULL == object) {
180         ERR("Allocation of memory failed, returning D3DERR_OUTOFVIDEOMEMORY\n");
181         return D3DERR_OUTOFVIDEOMEMORY;
182     }
183
184     object->lpVtbl = &Direct3DQuery9_Vtbl;
185     object->ref = 1;
186
187     wined3d_mutex_lock();
188     hr = IWineD3DDevice_CreateQuery(This->WineD3DDevice, Type, &object->wineD3DQuery, (IUnknown *)object);
189     wined3d_mutex_unlock();
190
191     if (FAILED(hr)) {
192
193         /* free up object */
194         WARN("(%p) call to IWineD3DDevice_CreateQuery failed\n", This);
195         HeapFree(GetProcessHeap(), 0, object);
196     } else {
197         IDirect3DDevice9Ex_AddRef(iface);
198         object->parentDevice = iface;
199         *ppQuery = (LPDIRECT3DQUERY9) object;
200         TRACE("(%p) : Created query %p\n", This , object);
201     }
202     TRACE("(%p) : returning %x\n", This, hr);
203     return hr;
204 }