kernel32/nls: Convert remaining files to UTF-8.
[wine.git] / dlls / d3d11 / async.c
blobc100e732277724fab22d3b27fc031c7b47902f8e
1 /*
2 * Copyright 2009 Henri Verbeet for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "config.h"
21 #include "wine/port.h"
23 #include "d3d11_private.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(d3d11);
27 /* ID3D11Query methods */
29 static inline struct d3d_query *impl_from_ID3D11Query(ID3D11Query *iface)
31 return CONTAINING_RECORD(iface, struct d3d_query, ID3D11Query_iface);
34 static HRESULT STDMETHODCALLTYPE d3d11_query_QueryInterface(ID3D11Query *iface, REFIID riid, void **object)
36 struct d3d_query *query = impl_from_ID3D11Query(iface);
38 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
40 if ((IsEqualGUID(riid, &IID_ID3D11Predicate) && query->predicate)
41 || IsEqualGUID(riid, &IID_ID3D11Query)
42 || IsEqualGUID(riid, &IID_ID3D11Asynchronous)
43 || IsEqualGUID(riid, &IID_ID3D11DeviceChild)
44 || IsEqualGUID(riid, &IID_IUnknown))
46 ID3D11Query_AddRef(iface);
47 *object = iface;
48 return S_OK;
51 if ((IsEqualGUID(riid, &IID_ID3D10Predicate) && query->predicate)
52 || IsEqualGUID(riid, &IID_ID3D10Query)
53 || IsEqualGUID(riid, &IID_ID3D10Asynchronous)
54 || IsEqualGUID(riid, &IID_ID3D10DeviceChild))
56 ID3D10Query_AddRef(&query->ID3D10Query_iface);
57 *object = &query->ID3D10Query_iface;
58 return S_OK;
61 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
63 *object = NULL;
64 return E_NOINTERFACE;
67 static ULONG STDMETHODCALLTYPE d3d11_query_AddRef(ID3D11Query *iface)
69 struct d3d_query *query = impl_from_ID3D11Query(iface);
70 ULONG refcount = InterlockedIncrement(&query->refcount);
72 TRACE("%p increasing refcount to %u.\n", query, refcount);
74 return refcount;
77 static ULONG STDMETHODCALLTYPE d3d11_query_Release(ID3D11Query *iface)
79 struct d3d_query *query = impl_from_ID3D11Query(iface);
80 ULONG refcount = InterlockedDecrement(&query->refcount);
82 TRACE("%p decreasing refcount to %u.\n", query, refcount);
84 if (!refcount)
86 ID3D11Device_Release(query->device);
87 wined3d_mutex_lock();
88 wined3d_query_decref(query->wined3d_query);
89 wined3d_private_store_cleanup(&query->private_store);
90 wined3d_mutex_unlock();
91 HeapFree(GetProcessHeap(), 0, query);
94 return refcount;
97 static void STDMETHODCALLTYPE d3d11_query_GetDevice(ID3D11Query *iface, ID3D11Device **device)
99 struct d3d_query *query = impl_from_ID3D11Query(iface);
101 TRACE("iface %p, device %p.\n", iface, device);
103 *device = query->device;
104 ID3D11Device_AddRef(*device);
107 static HRESULT STDMETHODCALLTYPE d3d11_query_GetPrivateData(ID3D11Query *iface,
108 REFGUID guid, UINT *data_size, void *data)
110 struct d3d_query *query = impl_from_ID3D11Query(iface);
112 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
114 return d3d_get_private_data(&query->private_store, guid, data_size, data);
117 static HRESULT STDMETHODCALLTYPE d3d11_query_SetPrivateData(ID3D11Query *iface,
118 REFGUID guid, UINT data_size, const void *data)
120 struct d3d_query *query = impl_from_ID3D11Query(iface);
122 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
124 return d3d_set_private_data(&query->private_store, guid, data_size, data);
127 static HRESULT STDMETHODCALLTYPE d3d11_query_SetPrivateDataInterface(ID3D11Query *iface,
128 REFGUID guid, const IUnknown *data)
130 struct d3d_query *query = impl_from_ID3D11Query(iface);
132 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
134 return d3d_set_private_data_interface(&query->private_store, guid, data);
137 static UINT STDMETHODCALLTYPE d3d11_query_GetDataSize(ID3D11Query *iface)
139 FIXME("iface %p stub!\n", iface);
141 return 0;
144 static void STDMETHODCALLTYPE d3d11_query_GetDesc(ID3D11Query *iface, D3D11_QUERY_DESC *desc)
146 FIXME("iface %p, desc %p stub!\n", iface, desc);
149 static const struct ID3D11QueryVtbl d3d11_query_vtbl =
151 /* IUnknown methods */
152 d3d11_query_QueryInterface,
153 d3d11_query_AddRef,
154 d3d11_query_Release,
155 /* ID3D11DeviceChild methods */
156 d3d11_query_GetDevice,
157 d3d11_query_GetPrivateData,
158 d3d11_query_SetPrivateData,
159 d3d11_query_SetPrivateDataInterface,
160 /* ID3D11Asynchronous methods */
161 d3d11_query_GetDataSize,
162 /* ID3D11Query methods */
163 d3d11_query_GetDesc,
166 struct d3d_query *unsafe_impl_from_ID3D11Query(ID3D11Query *iface)
168 if (!iface)
169 return NULL;
170 assert(iface->lpVtbl == &d3d11_query_vtbl);
171 return CONTAINING_RECORD(iface, struct d3d_query, ID3D11Query_iface);
174 /* ID3D10Query methods */
176 static inline struct d3d_query *impl_from_ID3D10Query(ID3D10Query *iface)
178 return CONTAINING_RECORD(iface, struct d3d_query, ID3D10Query_iface);
181 /* IUnknown methods */
183 static HRESULT STDMETHODCALLTYPE d3d10_query_QueryInterface(ID3D10Query *iface, REFIID riid, void **object)
185 struct d3d_query *query = impl_from_ID3D10Query(iface);
187 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
189 return d3d11_query_QueryInterface(&query->ID3D11Query_iface, riid, object);
192 static ULONG STDMETHODCALLTYPE d3d10_query_AddRef(ID3D10Query *iface)
194 struct d3d_query *query = impl_from_ID3D10Query(iface);
196 TRACE("iface %p.\n", iface);
198 return d3d11_query_AddRef(&query->ID3D11Query_iface);
201 static ULONG STDMETHODCALLTYPE d3d10_query_Release(ID3D10Query *iface)
203 struct d3d_query *query = impl_from_ID3D10Query(iface);
205 TRACE("iface %p.\n", iface);
207 return d3d11_query_Release(&query->ID3D11Query_iface);
210 /* ID3D10DeviceChild methods */
212 static void STDMETHODCALLTYPE d3d10_query_GetDevice(ID3D10Query *iface, ID3D10Device **device)
214 struct d3d_query *query = impl_from_ID3D10Query(iface);
216 TRACE("iface %p, device %p.\n", iface, device);
218 ID3D11Device_QueryInterface(query->device, &IID_ID3D10Device, (void **)device);
221 static HRESULT STDMETHODCALLTYPE d3d10_query_GetPrivateData(ID3D10Query *iface,
222 REFGUID guid, UINT *data_size, void *data)
224 struct d3d_query *query = impl_from_ID3D10Query(iface);
226 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
227 iface, debugstr_guid(guid), data_size, data);
229 return d3d_get_private_data(&query->private_store, guid, data_size, data);
232 static HRESULT STDMETHODCALLTYPE d3d10_query_SetPrivateData(ID3D10Query *iface,
233 REFGUID guid, UINT data_size, const void *data)
235 struct d3d_query *query = impl_from_ID3D10Query(iface);
237 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
238 iface, debugstr_guid(guid), data_size, data);
240 return d3d_set_private_data(&query->private_store, guid, data_size, data);
243 static HRESULT STDMETHODCALLTYPE d3d10_query_SetPrivateDataInterface(ID3D10Query *iface,
244 REFGUID guid, const IUnknown *data)
246 struct d3d_query *query = impl_from_ID3D10Query(iface);
248 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
250 return d3d_set_private_data_interface(&query->private_store, guid, data);
253 /* ID3D10Asynchronous methods */
255 static void STDMETHODCALLTYPE d3d10_query_Begin(ID3D10Query *iface)
257 FIXME("iface %p stub!\n", iface);
260 static void STDMETHODCALLTYPE d3d10_query_End(ID3D10Query *iface)
262 FIXME("iface %p stub!\n", iface);
265 static HRESULT STDMETHODCALLTYPE d3d10_query_GetData(ID3D10Query *iface, void *data, UINT data_size, UINT flags)
267 FIXME("iface %p, data %p, data_size %u, flags %#x stub!\n", iface, data, data_size, flags);
269 return E_NOTIMPL;
272 static UINT STDMETHODCALLTYPE d3d10_query_GetDataSize(ID3D10Query *iface)
274 FIXME("iface %p stub!\n", iface);
276 return 0;
279 /* ID3D10Query methods */
281 static void STDMETHODCALLTYPE d3d10_query_GetDesc(ID3D10Query *iface, D3D10_QUERY_DESC *desc)
283 FIXME("iface %p, desc %p stub!\n", iface, desc);
286 static const struct ID3D10QueryVtbl d3d10_query_vtbl =
288 /* IUnknown methods */
289 d3d10_query_QueryInterface,
290 d3d10_query_AddRef,
291 d3d10_query_Release,
292 /* ID3D10DeviceChild methods */
293 d3d10_query_GetDevice,
294 d3d10_query_GetPrivateData,
295 d3d10_query_SetPrivateData,
296 d3d10_query_SetPrivateDataInterface,
297 /* ID3D10Asynchronous methods */
298 d3d10_query_Begin,
299 d3d10_query_End,
300 d3d10_query_GetData,
301 d3d10_query_GetDataSize,
302 /* ID3D10Query methods */
303 d3d10_query_GetDesc,
306 struct d3d_query *unsafe_impl_from_ID3D10Query(ID3D10Query *iface)
308 if (!iface)
309 return NULL;
310 assert(iface->lpVtbl == &d3d10_query_vtbl);
311 return CONTAINING_RECORD(iface, struct d3d_query, ID3D10Query_iface);
314 static HRESULT d3d_query_init(struct d3d_query *query, struct d3d_device *device,
315 const D3D11_QUERY_DESC *desc, BOOL predicate)
317 HRESULT hr;
319 static const enum wined3d_query_type query_type_map[] =
321 /* D3D11_QUERY_EVENT */ WINED3D_QUERY_TYPE_EVENT,
322 /* D3D11_QUERY_OCCLUSION */ WINED3D_QUERY_TYPE_OCCLUSION,
323 /* D3D11_QUERY_TIMESTAMP */ WINED3D_QUERY_TYPE_TIMESTAMP,
324 /* D3D11_QUERY_TIMESTAMP_DISJOINT */ WINED3D_QUERY_TYPE_TIMESTAMP_DISJOINT,
325 /* D3D11_QUERY_PIPELINE_STATISTICS */ WINED3D_QUERY_TYPE_PIPELINE_STATISTICS,
326 /* D3D11_QUERY_OCCLUSION_PREDICATE */ WINED3D_QUERY_TYPE_OCCLUSION,
327 /* D3D11_QUERY_SO_STATISTICS */ WINED3D_QUERY_TYPE_SO_STATISTICS,
328 /* D3D11_QUERY_SO_OVERFLOW_PREDICATE */ WINED3D_QUERY_TYPE_SO_OVERFLOW,
331 if (desc->Query >= sizeof(query_type_map) / sizeof(*query_type_map))
333 FIXME("Unhandled query type %#x.\n", desc->Query);
334 return E_INVALIDARG;
337 if (desc->MiscFlags)
338 FIXME("Ignoring MiscFlags %#x.\n", desc->MiscFlags);
340 query->ID3D11Query_iface.lpVtbl = &d3d11_query_vtbl;
341 query->ID3D10Query_iface.lpVtbl = &d3d10_query_vtbl;
342 query->refcount = 1;
343 wined3d_mutex_lock();
344 wined3d_private_store_init(&query->private_store);
346 if (FAILED(hr = wined3d_query_create(device->wined3d_device,
347 query_type_map[desc->Query], query, &query->wined3d_query)))
349 WARN("Failed to create wined3d query, hr %#x.\n", hr);
350 wined3d_private_store_cleanup(&query->private_store);
351 wined3d_mutex_unlock();
352 return hr;
354 wined3d_mutex_unlock();
356 query->predicate = predicate;
357 query->device = &device->ID3D11Device_iface;
358 ID3D11Device_AddRef(query->device);
360 return S_OK;
363 HRESULT d3d_query_create(struct d3d_device *device, const D3D11_QUERY_DESC *desc, BOOL predicate,
364 struct d3d_query **query)
366 struct d3d_query *object;
367 BOOL is_predicate_type;
368 HRESULT hr;
370 if (!desc)
371 return E_INVALIDARG;
373 is_predicate_type = desc->Query == D3D11_QUERY_OCCLUSION_PREDICATE
374 || desc->Query == D3D11_QUERY_SO_OVERFLOW_PREDICATE
375 || desc->Query == D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM0
376 || desc->Query == D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM1
377 || desc->Query == D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM2
378 || desc->Query == D3D11_QUERY_SO_OVERFLOW_PREDICATE_STREAM3;
380 if (!is_predicate_type && predicate)
382 WARN("Query type %u is not a predicate.\n", desc->Query);
383 return E_INVALIDARG;
386 if (is_predicate_type)
387 predicate = TRUE;
389 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
390 return E_OUTOFMEMORY;
392 if (FAILED(hr = d3d_query_init(object, device, desc, predicate)))
394 WARN("Failed to initialize predicate, hr %#x.\n", hr);
395 HeapFree(GetProcessHeap(), 0, object);
396 return hr;
399 TRACE("Created predicate %p.\n", object);
400 *query = object;
402 return S_OK;