winedbg: Make the crash dialog slightly larger and minimize/maximize-able.
[wine/multimedia.git] / dlls / d3d9 / query.c
blobd3634133601b3c609ff9be3c53df600b74429bbb
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 static inline struct d3d9_query *impl_from_IDirect3DQuery9(IDirect3DQuery9 *iface)
30 return CONTAINING_RECORD(iface, struct d3d9_query, IDirect3DQuery9_iface);
33 static HRESULT WINAPI d3d9_query_QueryInterface(IDirect3DQuery9 *iface, REFIID riid, void **out)
35 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), out);
37 if (IsEqualGUID(riid, &IID_IDirect3DQuery9)
38 || IsEqualGUID(riid, &IID_IUnknown))
40 IDirect3DQuery9_AddRef(iface);
41 *out = iface;
42 return S_OK;
45 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
47 *out = NULL;
48 return E_NOINTERFACE;
51 static ULONG WINAPI d3d9_query_AddRef(IDirect3DQuery9 *iface)
53 struct d3d9_query *query = impl_from_IDirect3DQuery9(iface);
54 ULONG refcount = InterlockedIncrement(&query->refcount);
56 TRACE("%p increasing refcount to %u.\n", iface, refcount);
58 return refcount;
61 static ULONG WINAPI d3d9_query_Release(IDirect3DQuery9 *iface)
63 struct d3d9_query *query = impl_from_IDirect3DQuery9(iface);
64 ULONG refcount = InterlockedDecrement(&query->refcount);
66 TRACE("%p decreasing refcount to %u.\n", iface, refcount);
68 if (!refcount)
70 wined3d_mutex_lock();
71 wined3d_query_decref(query->wined3d_query);
72 wined3d_mutex_unlock();
74 IDirect3DDevice9Ex_Release(query->parent_device);
75 HeapFree(GetProcessHeap(), 0, query);
77 return refcount;
80 static HRESULT WINAPI d3d9_query_GetDevice(IDirect3DQuery9 *iface, IDirect3DDevice9 **device)
82 struct d3d9_query *query = impl_from_IDirect3DQuery9(iface);
84 TRACE("iface %p, device %p.\n", iface, device);
86 *device = (IDirect3DDevice9 *)query->parent_device;
87 IDirect3DDevice9_AddRef(*device);
89 TRACE("Returning device %p.\n", *device);
91 return D3D_OK;
94 static D3DQUERYTYPE WINAPI d3d9_query_GetType(IDirect3DQuery9 *iface)
96 struct d3d9_query *query = impl_from_IDirect3DQuery9(iface);
97 D3DQUERYTYPE type;
99 TRACE("iface %p.\n", iface);
101 wined3d_mutex_lock();
102 type = wined3d_query_get_type(query->wined3d_query);
103 wined3d_mutex_unlock();
105 return type;
108 static DWORD WINAPI d3d9_query_GetDataSize(IDirect3DQuery9 *iface)
110 struct d3d9_query *query = impl_from_IDirect3DQuery9(iface);
111 DWORD ret;
113 TRACE("iface %p.\n", iface);
115 wined3d_mutex_lock();
116 ret = wined3d_query_get_data_size(query->wined3d_query);
117 wined3d_mutex_unlock();
119 return ret;
122 static HRESULT WINAPI d3d9_query_Issue(IDirect3DQuery9 *iface, DWORD flags)
124 struct d3d9_query *query = impl_from_IDirect3DQuery9(iface);
125 HRESULT hr;
127 TRACE("iface %p, flags %#x.\n", iface, flags);
129 wined3d_mutex_lock();
130 hr = wined3d_query_issue(query->wined3d_query, flags);
131 wined3d_mutex_unlock();
133 return hr;
136 static HRESULT WINAPI d3d9_query_GetData(IDirect3DQuery9 *iface, void *data, DWORD size, DWORD flags)
138 struct d3d9_query *query = impl_from_IDirect3DQuery9(iface);
139 HRESULT hr;
141 TRACE("iface %p, data %p, size %u, flags %#x.\n",
142 iface, data, size, flags);
144 wined3d_mutex_lock();
145 hr = wined3d_query_get_data(query->wined3d_query, data, size, flags);
146 wined3d_mutex_unlock();
148 return hr;
152 static const struct IDirect3DQuery9Vtbl d3d9_query_vtbl =
154 d3d9_query_QueryInterface,
155 d3d9_query_AddRef,
156 d3d9_query_Release,
157 d3d9_query_GetDevice,
158 d3d9_query_GetType,
159 d3d9_query_GetDataSize,
160 d3d9_query_Issue,
161 d3d9_query_GetData,
164 HRESULT query_init(struct d3d9_query *query, struct d3d9_device *device, D3DQUERYTYPE type)
166 HRESULT hr;
168 query->IDirect3DQuery9_iface.lpVtbl = &d3d9_query_vtbl;
169 query->refcount = 1;
171 wined3d_mutex_lock();
172 hr = wined3d_query_create(device->wined3d_device, type, &query->wined3d_query);
173 wined3d_mutex_unlock();
174 if (FAILED(hr))
176 WARN("Failed to create wined3d query, hr %#x.\n", hr);
177 return hr;
180 query->parent_device = &device->IDirect3DDevice9Ex_iface;
181 IDirect3DDevice9Ex_AddRef(query->parent_device);
183 return D3D_OK;