gdi32: Simplify the code a little by using a separate variable for the return value.
[wine/multimedia.git] / dlls / d3d9 / query.c
blob42523320f33fa15516649e22387b240be33c768c
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 IDirect3DQuery9Impl *impl_from_IDirect3DQuery9(IDirect3DQuery9 *iface)
30 return CONTAINING_RECORD(iface, IDirect3DQuery9Impl, IDirect3DQuery9_iface);
33 static HRESULT WINAPI IDirect3DQuery9Impl_QueryInterface(IDirect3DQuery9 *iface, REFIID riid,
34 void **ppobj)
36 IDirect3DQuery9Impl *This = impl_from_IDirect3DQuery9(iface);
38 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), ppobj);
40 if (IsEqualGUID(riid, &IID_IUnknown)
41 || IsEqualGUID(riid, &IID_IDirect3DQuery9)) {
42 IDirect3DQuery9_AddRef(iface);
43 *ppobj = This;
44 return S_OK;
47 WARN("(%p)->(%s,%p),not found\n", This, debugstr_guid(riid), ppobj);
48 *ppobj = NULL;
49 return E_NOINTERFACE;
52 static ULONG WINAPI IDirect3DQuery9Impl_AddRef(IDirect3DQuery9 *iface)
54 IDirect3DQuery9Impl *This = impl_from_IDirect3DQuery9(iface);
55 ULONG ref = InterlockedIncrement(&This->ref);
57 TRACE("%p increasing refcount to %u.\n", iface, ref);
59 return ref;
62 static ULONG WINAPI IDirect3DQuery9Impl_Release(IDirect3DQuery9 *iface)
64 IDirect3DQuery9Impl *This = impl_from_IDirect3DQuery9(iface);
65 ULONG ref = InterlockedDecrement(&This->ref);
67 TRACE("%p decreasing refcount to %u.\n", iface, ref);
69 if (ref == 0) {
70 wined3d_mutex_lock();
71 wined3d_query_decref(This->wineD3DQuery);
72 wined3d_mutex_unlock();
74 IDirect3DDevice9Ex_Release(This->parentDevice);
75 HeapFree(GetProcessHeap(), 0, This);
77 return ref;
80 static HRESULT WINAPI IDirect3DQuery9Impl_GetDevice(IDirect3DQuery9 *iface,
81 IDirect3DDevice9 **device)
83 IDirect3DQuery9Impl *This = impl_from_IDirect3DQuery9(iface);
85 TRACE("iface %p, device %p.\n", iface, device);
87 *device = (IDirect3DDevice9 *)This->parentDevice;
88 IDirect3DDevice9_AddRef(*device);
90 TRACE("Returning device %p.\n", *device);
92 return D3D_OK;
95 static D3DQUERYTYPE WINAPI IDirect3DQuery9Impl_GetType(IDirect3DQuery9 *iface)
97 IDirect3DQuery9Impl *This = impl_from_IDirect3DQuery9(iface);
98 D3DQUERYTYPE type;
100 TRACE("iface %p.\n", iface);
102 wined3d_mutex_lock();
103 type = wined3d_query_get_type(This->wineD3DQuery);
104 wined3d_mutex_unlock();
106 return type;
109 static DWORD WINAPI IDirect3DQuery9Impl_GetDataSize(IDirect3DQuery9 *iface)
111 IDirect3DQuery9Impl *This = impl_from_IDirect3DQuery9(iface);
112 DWORD ret;
114 TRACE("iface %p.\n", iface);
116 wined3d_mutex_lock();
117 ret = wined3d_query_get_data_size(This->wineD3DQuery);
118 wined3d_mutex_unlock();
120 return ret;
123 static HRESULT WINAPI IDirect3DQuery9Impl_Issue(IDirect3DQuery9 *iface, DWORD dwIssueFlags)
125 IDirect3DQuery9Impl *This = impl_from_IDirect3DQuery9(iface);
126 HRESULT hr;
128 TRACE("iface %p, flags %#x.\n", iface, dwIssueFlags);
130 wined3d_mutex_lock();
131 hr = wined3d_query_issue(This->wineD3DQuery, dwIssueFlags);
132 wined3d_mutex_unlock();
134 return hr;
137 static HRESULT WINAPI IDirect3DQuery9Impl_GetData(IDirect3DQuery9 *iface, void *pData,
138 DWORD dwSize, DWORD dwGetDataFlags)
140 IDirect3DQuery9Impl *This = impl_from_IDirect3DQuery9(iface);
141 HRESULT hr;
143 TRACE("iface %p, data %p, size %u, flags %#x.\n",
144 iface, pData, dwSize, dwGetDataFlags);
146 wined3d_mutex_lock();
147 hr = wined3d_query_get_data(This->wineD3DQuery, pData, dwSize, dwGetDataFlags);
148 wined3d_mutex_unlock();
150 return hr;
154 static const IDirect3DQuery9Vtbl Direct3DQuery9_Vtbl =
156 IDirect3DQuery9Impl_QueryInterface,
157 IDirect3DQuery9Impl_AddRef,
158 IDirect3DQuery9Impl_Release,
159 IDirect3DQuery9Impl_GetDevice,
160 IDirect3DQuery9Impl_GetType,
161 IDirect3DQuery9Impl_GetDataSize,
162 IDirect3DQuery9Impl_Issue,
163 IDirect3DQuery9Impl_GetData
166 HRESULT query_init(IDirect3DQuery9Impl *query, IDirect3DDevice9Impl *device, D3DQUERYTYPE type)
168 HRESULT hr;
170 query->IDirect3DQuery9_iface.lpVtbl = &Direct3DQuery9_Vtbl;
171 query->ref = 1;
173 wined3d_mutex_lock();
174 hr = wined3d_query_create(device->wined3d_device, type, &query->wineD3DQuery);
175 wined3d_mutex_unlock();
176 if (FAILED(hr))
178 WARN("Failed to create wined3d query, hr %#x.\n", hr);
179 return hr;
182 query->parentDevice = &device->IDirect3DDevice9Ex_iface;
183 IDirect3DDevice9Ex_AddRef(query->parentDevice);
185 return D3D_OK;