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 | /*
|
---|
24 | * Oracle LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
|
---|
25 | * other than GPL or LGPL is available it will apply instead, Oracle elects to use only
|
---|
26 | * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
|
---|
27 | * a choice of LGPL license versions is made available with the language indicating
|
---|
28 | * that LGPLv2 or any later version may be used, or where a choice of which version
|
---|
29 | * of the LGPL is applied is otherwise unspecified.
|
---|
30 | */
|
---|
31 |
|
---|
32 | #include "config.h"
|
---|
33 | #include "d3d9_private.h"
|
---|
34 |
|
---|
35 | WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
|
---|
36 |
|
---|
37 | static inline struct d3d9_query *impl_from_IDirect3DQuery9(IDirect3DQuery9 *iface)
|
---|
38 | {
|
---|
39 | return CONTAINING_RECORD(iface, struct d3d9_query, IDirect3DQuery9_iface);
|
---|
40 | }
|
---|
41 |
|
---|
42 | static HRESULT WINAPI d3d9_query_QueryInterface(IDirect3DQuery9 *iface, REFIID riid, void **out)
|
---|
43 | {
|
---|
44 | TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), out);
|
---|
45 |
|
---|
46 | if (IsEqualGUID(riid, &IID_IDirect3DQuery9)
|
---|
47 | || IsEqualGUID(riid, &IID_IUnknown))
|
---|
48 | {
|
---|
49 | IDirect3DQuery9_AddRef(iface);
|
---|
50 | *out = iface;
|
---|
51 | return S_OK;
|
---|
52 | }
|
---|
53 |
|
---|
54 | WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
|
---|
55 |
|
---|
56 | *out = NULL;
|
---|
57 | return E_NOINTERFACE;
|
---|
58 | }
|
---|
59 |
|
---|
60 | static ULONG WINAPI d3d9_query_AddRef(IDirect3DQuery9 *iface)
|
---|
61 | {
|
---|
62 | struct d3d9_query *query = impl_from_IDirect3DQuery9(iface);
|
---|
63 | ULONG refcount = InterlockedIncrement(&query->refcount);
|
---|
64 |
|
---|
65 | TRACE("%p increasing refcount to %u.\n", iface, refcount);
|
---|
66 |
|
---|
67 | return refcount;
|
---|
68 | }
|
---|
69 |
|
---|
70 | static ULONG WINAPI d3d9_query_Release(IDirect3DQuery9 *iface)
|
---|
71 | {
|
---|
72 | struct d3d9_query *query = impl_from_IDirect3DQuery9(iface);
|
---|
73 | ULONG refcount = InterlockedDecrement(&query->refcount);
|
---|
74 |
|
---|
75 | TRACE("%p decreasing refcount to %u.\n", iface, refcount);
|
---|
76 |
|
---|
77 | if (!refcount)
|
---|
78 | {
|
---|
79 | wined3d_mutex_lock();
|
---|
80 | wined3d_query_decref(query->wined3d_query);
|
---|
81 | wined3d_mutex_unlock();
|
---|
82 |
|
---|
83 | IDirect3DDevice9Ex_Release(query->parent_device);
|
---|
84 | HeapFree(GetProcessHeap(), 0, query);
|
---|
85 | }
|
---|
86 | return refcount;
|
---|
87 | }
|
---|
88 |
|
---|
89 | static HRESULT WINAPI d3d9_query_GetDevice(IDirect3DQuery9 *iface, IDirect3DDevice9 **device)
|
---|
90 | {
|
---|
91 | struct d3d9_query *query = impl_from_IDirect3DQuery9(iface);
|
---|
92 |
|
---|
93 | TRACE("iface %p, device %p.\n", iface, device);
|
---|
94 |
|
---|
95 | *device = (IDirect3DDevice9 *)query->parent_device;
|
---|
96 | IDirect3DDevice9_AddRef(*device);
|
---|
97 |
|
---|
98 | TRACE("Returning device %p.\n", *device);
|
---|
99 |
|
---|
100 | return D3D_OK;
|
---|
101 | }
|
---|
102 |
|
---|
103 | static D3DQUERYTYPE WINAPI d3d9_query_GetType(IDirect3DQuery9 *iface)
|
---|
104 | {
|
---|
105 | struct d3d9_query *query = impl_from_IDirect3DQuery9(iface);
|
---|
106 | D3DQUERYTYPE type;
|
---|
107 |
|
---|
108 | TRACE("iface %p.\n", iface);
|
---|
109 |
|
---|
110 | wined3d_mutex_lock();
|
---|
111 | type = wined3d_query_get_type(query->wined3d_query);
|
---|
112 | wined3d_mutex_unlock();
|
---|
113 |
|
---|
114 | return type;
|
---|
115 | }
|
---|
116 |
|
---|
117 | static DWORD WINAPI d3d9_query_GetDataSize(IDirect3DQuery9 *iface)
|
---|
118 | {
|
---|
119 | struct d3d9_query *query = impl_from_IDirect3DQuery9(iface);
|
---|
120 | DWORD ret;
|
---|
121 |
|
---|
122 | TRACE("iface %p.\n", iface);
|
---|
123 |
|
---|
124 | wined3d_mutex_lock();
|
---|
125 | ret = wined3d_query_get_data_size(query->wined3d_query);
|
---|
126 | wined3d_mutex_unlock();
|
---|
127 |
|
---|
128 | return ret;
|
---|
129 | }
|
---|
130 |
|
---|
131 | static HRESULT WINAPI d3d9_query_Issue(IDirect3DQuery9 *iface, DWORD flags)
|
---|
132 | {
|
---|
133 | struct d3d9_query *query = impl_from_IDirect3DQuery9(iface);
|
---|
134 | HRESULT hr;
|
---|
135 |
|
---|
136 | TRACE("iface %p, flags %#x.\n", iface, flags);
|
---|
137 |
|
---|
138 | wined3d_mutex_lock();
|
---|
139 | hr = wined3d_query_issue(query->wined3d_query, flags);
|
---|
140 | wined3d_mutex_unlock();
|
---|
141 |
|
---|
142 | return hr;
|
---|
143 | }
|
---|
144 |
|
---|
145 | static HRESULT WINAPI d3d9_query_GetData(IDirect3DQuery9 *iface, void *data, DWORD size, DWORD flags)
|
---|
146 | {
|
---|
147 | struct d3d9_query *query = impl_from_IDirect3DQuery9(iface);
|
---|
148 | HRESULT hr;
|
---|
149 |
|
---|
150 | TRACE("iface %p, data %p, size %u, flags %#x.\n",
|
---|
151 | iface, data, size, flags);
|
---|
152 |
|
---|
153 | wined3d_mutex_lock();
|
---|
154 | hr = wined3d_query_get_data(query->wined3d_query, data, size, flags);
|
---|
155 | wined3d_mutex_unlock();
|
---|
156 |
|
---|
157 | return hr;
|
---|
158 | }
|
---|
159 |
|
---|
160 |
|
---|
161 | static const struct IDirect3DQuery9Vtbl d3d9_query_vtbl =
|
---|
162 | {
|
---|
163 | d3d9_query_QueryInterface,
|
---|
164 | d3d9_query_AddRef,
|
---|
165 | d3d9_query_Release,
|
---|
166 | d3d9_query_GetDevice,
|
---|
167 | d3d9_query_GetType,
|
---|
168 | d3d9_query_GetDataSize,
|
---|
169 | d3d9_query_Issue,
|
---|
170 | d3d9_query_GetData,
|
---|
171 | };
|
---|
172 |
|
---|
173 | HRESULT query_init(struct d3d9_query *query, struct d3d9_device *device, D3DQUERYTYPE type)
|
---|
174 | {
|
---|
175 | HRESULT hr;
|
---|
176 |
|
---|
177 | query->IDirect3DQuery9_iface.lpVtbl = &d3d9_query_vtbl;
|
---|
178 | query->refcount = 1;
|
---|
179 |
|
---|
180 | wined3d_mutex_lock();
|
---|
181 | hr = wined3d_query_create(device->wined3d_device, type, &query->wined3d_query);
|
---|
182 | wined3d_mutex_unlock();
|
---|
183 | if (FAILED(hr))
|
---|
184 | {
|
---|
185 | WARN("Failed to create wined3d query, hr %#x.\n", hr);
|
---|
186 | return hr;
|
---|
187 | }
|
---|
188 |
|
---|
189 | query->parent_device = &device->IDirect3DDevice9Ex_iface;
|
---|
190 | IDirect3DDevice9Ex_AddRef(query->parent_device);
|
---|
191 |
|
---|
192 | return D3D_OK;
|
---|
193 | }
|
---|