1 | /*
|
---|
2 | * Copyright 2002-2003 Jason Edmeades
|
---|
3 | * Raphael Junqueira
|
---|
4 | *
|
---|
5 | * This library is free software; you can redistribute it and/or
|
---|
6 | * modify it under the terms of the GNU Lesser General Public
|
---|
7 | * License as published by the Free Software Foundation; either
|
---|
8 | * version 2.1 of the License, or (at your option) any later version.
|
---|
9 | *
|
---|
10 | * This library is distributed in the hope that it will be useful,
|
---|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
13 | * Lesser General Public License for more details.
|
---|
14 | *
|
---|
15 | * You should have received a copy of the GNU Lesser General Public
|
---|
16 | * License along with this library; if not, write to the Free Software
|
---|
17 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
---|
18 | */
|
---|
19 |
|
---|
20 | /*
|
---|
21 | * Oracle LGPL Disclaimer: For the avoidance of doubt, except that if any license choice
|
---|
22 | * other than GPL or LGPL is available it will apply instead, Oracle elects to use only
|
---|
23 | * the Lesser General Public License version 2.1 (LGPLv2) at this time for any software where
|
---|
24 | * a choice of LGPL license versions is made available with the language indicating
|
---|
25 | * that LGPLv2 or any later version may be used, or where a choice of which version
|
---|
26 | * of the LGPL is applied is otherwise unspecified.
|
---|
27 | */
|
---|
28 |
|
---|
29 | #include "config.h"
|
---|
30 | #include "d3d9_private.h"
|
---|
31 |
|
---|
32 | WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
|
---|
33 |
|
---|
34 | static inline struct d3d9_vertexshader *impl_from_IDirect3DVertexShader9(IDirect3DVertexShader9 *iface)
|
---|
35 | {
|
---|
36 | return CONTAINING_RECORD(iface, struct d3d9_vertexshader, IDirect3DVertexShader9_iface);
|
---|
37 | }
|
---|
38 |
|
---|
39 | static HRESULT WINAPI d3d9_vertexshader_QueryInterface(IDirect3DVertexShader9 *iface, REFIID riid, void **out)
|
---|
40 | {
|
---|
41 | TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
|
---|
42 |
|
---|
43 | if (IsEqualGUID(riid, &IID_IDirect3DVertexShader9)
|
---|
44 | || IsEqualGUID(riid, &IID_IUnknown))
|
---|
45 | {
|
---|
46 | IDirect3DVertexShader9_AddRef(iface);
|
---|
47 | *out = iface;
|
---|
48 | return S_OK;
|
---|
49 | }
|
---|
50 |
|
---|
51 | WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
|
---|
52 |
|
---|
53 | *out = NULL;
|
---|
54 | return E_NOINTERFACE;
|
---|
55 | }
|
---|
56 |
|
---|
57 | static ULONG WINAPI d3d9_vertexshader_AddRef(IDirect3DVertexShader9 *iface)
|
---|
58 | {
|
---|
59 | struct d3d9_vertexshader *shader = impl_from_IDirect3DVertexShader9(iface);
|
---|
60 | ULONG refcount = InterlockedIncrement(&shader->refcount);
|
---|
61 |
|
---|
62 | TRACE("%p increasing refcount to %u.\n", iface, refcount);
|
---|
63 |
|
---|
64 | if (refcount == 1)
|
---|
65 | {
|
---|
66 | IDirect3DDevice9Ex_AddRef(shader->parent_device);
|
---|
67 | wined3d_mutex_lock();
|
---|
68 | wined3d_shader_incref(shader->wined3d_shader);
|
---|
69 | wined3d_mutex_unlock();
|
---|
70 | }
|
---|
71 |
|
---|
72 | return refcount;
|
---|
73 | }
|
---|
74 |
|
---|
75 | static ULONG WINAPI d3d9_vertexshader_Release(IDirect3DVertexShader9 *iface)
|
---|
76 | {
|
---|
77 | struct d3d9_vertexshader *shader = impl_from_IDirect3DVertexShader9(iface);
|
---|
78 | ULONG refcount = InterlockedDecrement(&shader->refcount);
|
---|
79 |
|
---|
80 | TRACE("%p decreasing refcount to %u.\n", iface, refcount);
|
---|
81 |
|
---|
82 | if (!refcount)
|
---|
83 | {
|
---|
84 | IDirect3DDevice9Ex *device = shader->parent_device;
|
---|
85 |
|
---|
86 | wined3d_mutex_lock();
|
---|
87 | wined3d_shader_decref(shader->wined3d_shader);
|
---|
88 | wined3d_mutex_unlock();
|
---|
89 |
|
---|
90 | /* Release the device last, as it may cause the device to be destroyed. */
|
---|
91 | IDirect3DDevice9Ex_Release(device);
|
---|
92 | }
|
---|
93 |
|
---|
94 | return refcount;
|
---|
95 | }
|
---|
96 |
|
---|
97 | static HRESULT WINAPI d3d9_vertexshader_GetDevice(IDirect3DVertexShader9 *iface, IDirect3DDevice9 **device)
|
---|
98 | {
|
---|
99 | struct d3d9_vertexshader *shader = impl_from_IDirect3DVertexShader9(iface);
|
---|
100 |
|
---|
101 | TRACE("iface %p, device %p.\n", iface, device);
|
---|
102 |
|
---|
103 | *device = (IDirect3DDevice9 *)shader->parent_device;
|
---|
104 | IDirect3DDevice9_AddRef(*device);
|
---|
105 |
|
---|
106 | TRACE("Returning device %p.\n", *device);
|
---|
107 |
|
---|
108 | return D3D_OK;
|
---|
109 | }
|
---|
110 |
|
---|
111 | static HRESULT WINAPI d3d9_vertexshader_GetFunction(IDirect3DVertexShader9 *iface, void *data, UINT *data_size)
|
---|
112 | {
|
---|
113 | struct d3d9_vertexshader *shader = impl_from_IDirect3DVertexShader9(iface);
|
---|
114 | HRESULT hr;
|
---|
115 |
|
---|
116 | TRACE("iface %p, data %p, data_size %p.\n", iface, data, data_size);
|
---|
117 |
|
---|
118 | wined3d_mutex_lock();
|
---|
119 | hr = wined3d_shader_get_byte_code(shader->wined3d_shader, data, data_size);
|
---|
120 | wined3d_mutex_unlock();
|
---|
121 |
|
---|
122 | return hr;
|
---|
123 | }
|
---|
124 |
|
---|
125 | static const IDirect3DVertexShader9Vtbl d3d9_vertexshader_vtbl =
|
---|
126 | {
|
---|
127 | /* IUnknown */
|
---|
128 | d3d9_vertexshader_QueryInterface,
|
---|
129 | d3d9_vertexshader_AddRef,
|
---|
130 | d3d9_vertexshader_Release,
|
---|
131 | /* IDirect3DVertexShader9 */
|
---|
132 | d3d9_vertexshader_GetDevice,
|
---|
133 | d3d9_vertexshader_GetFunction,
|
---|
134 | };
|
---|
135 |
|
---|
136 | static void STDMETHODCALLTYPE d3d9_vertexshader_wined3d_object_destroyed(void *parent)
|
---|
137 | {
|
---|
138 | HeapFree(GetProcessHeap(), 0, parent);
|
---|
139 | }
|
---|
140 |
|
---|
141 | static const struct wined3d_parent_ops d3d9_vertexshader_wined3d_parent_ops =
|
---|
142 | {
|
---|
143 | d3d9_vertexshader_wined3d_object_destroyed,
|
---|
144 | };
|
---|
145 |
|
---|
146 | HRESULT vertexshader_init(struct d3d9_vertexshader *shader, struct d3d9_device *device, const DWORD *byte_code)
|
---|
147 | {
|
---|
148 | HRESULT hr;
|
---|
149 |
|
---|
150 | shader->refcount = 1;
|
---|
151 | shader->IDirect3DVertexShader9_iface.lpVtbl = &d3d9_vertexshader_vtbl;
|
---|
152 |
|
---|
153 | wined3d_mutex_lock();
|
---|
154 | hr = wined3d_shader_create_vs(device->wined3d_device, byte_code, NULL,
|
---|
155 | shader, &d3d9_vertexshader_wined3d_parent_ops, &shader->wined3d_shader, 3);
|
---|
156 | wined3d_mutex_unlock();
|
---|
157 | if (FAILED(hr))
|
---|
158 | {
|
---|
159 | WARN("Failed to create wined3d vertex shader, hr %#x.\n", hr);
|
---|
160 | return hr;
|
---|
161 | }
|
---|
162 |
|
---|
163 | shader->parent_device = &device->IDirect3DDevice9Ex_iface;
|
---|
164 | IDirect3DDevice9Ex_AddRef(shader->parent_device);
|
---|
165 |
|
---|
166 | return D3D_OK;
|
---|
167 | }
|
---|
168 |
|
---|
169 | struct d3d9_vertexshader *unsafe_impl_from_IDirect3DVertexShader9(IDirect3DVertexShader9 *iface)
|
---|
170 | {
|
---|
171 | if (!iface)
|
---|
172 | return NULL;
|
---|
173 | assert(iface->lpVtbl == &d3d9_vertexshader_vtbl);
|
---|
174 |
|
---|
175 | return impl_from_IDirect3DVertexShader9(iface);
|
---|
176 | }
|
---|
177 |
|
---|
178 | static inline struct d3d9_pixelshader *impl_from_IDirect3DPixelShader9(IDirect3DPixelShader9 *iface)
|
---|
179 | {
|
---|
180 | return CONTAINING_RECORD(iface, struct d3d9_pixelshader, IDirect3DPixelShader9_iface);
|
---|
181 | }
|
---|
182 |
|
---|
183 | static HRESULT WINAPI d3d9_pixelshader_QueryInterface(IDirect3DPixelShader9 *iface, REFIID riid, void **out)
|
---|
184 | {
|
---|
185 | TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
|
---|
186 |
|
---|
187 | if (IsEqualGUID(riid, &IID_IDirect3DPixelShader9)
|
---|
188 | || IsEqualGUID(riid, &IID_IUnknown))
|
---|
189 | {
|
---|
190 | IDirect3DPixelShader9_AddRef(iface);
|
---|
191 | *out = iface;
|
---|
192 | return S_OK;
|
---|
193 | }
|
---|
194 |
|
---|
195 | WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
|
---|
196 |
|
---|
197 | *out = NULL;
|
---|
198 | return E_NOINTERFACE;
|
---|
199 | }
|
---|
200 |
|
---|
201 | static ULONG WINAPI d3d9_pixelshader_AddRef(IDirect3DPixelShader9 *iface)
|
---|
202 | {
|
---|
203 | struct d3d9_pixelshader *shader = impl_from_IDirect3DPixelShader9(iface);
|
---|
204 | ULONG refcount = InterlockedIncrement(&shader->refcount);
|
---|
205 |
|
---|
206 | TRACE("%p increasing refcount to %u.\n", iface, refcount);
|
---|
207 |
|
---|
208 | if (refcount == 1)
|
---|
209 | {
|
---|
210 | IDirect3DDevice9Ex_AddRef(shader->parent_device);
|
---|
211 | wined3d_mutex_lock();
|
---|
212 | wined3d_shader_incref(shader->wined3d_shader);
|
---|
213 | wined3d_mutex_unlock();
|
---|
214 | }
|
---|
215 |
|
---|
216 | return refcount;
|
---|
217 | }
|
---|
218 |
|
---|
219 | static ULONG WINAPI d3d9_pixelshader_Release(IDirect3DPixelShader9 *iface)
|
---|
220 | {
|
---|
221 | struct d3d9_pixelshader *shader = impl_from_IDirect3DPixelShader9(iface);
|
---|
222 | ULONG refcount = InterlockedDecrement(&shader->refcount);
|
---|
223 |
|
---|
224 | TRACE("%p decreasing refcount to %u.\n", iface, refcount);
|
---|
225 |
|
---|
226 | if (!refcount)
|
---|
227 | {
|
---|
228 | IDirect3DDevice9Ex *device = shader->parent_device;
|
---|
229 |
|
---|
230 | wined3d_mutex_lock();
|
---|
231 | wined3d_shader_decref(shader->wined3d_shader);
|
---|
232 | wined3d_mutex_unlock();
|
---|
233 |
|
---|
234 | /* Release the device last, as it may cause the device to be destroyed. */
|
---|
235 | IDirect3DDevice9Ex_Release(device);
|
---|
236 | }
|
---|
237 |
|
---|
238 | return refcount;
|
---|
239 | }
|
---|
240 |
|
---|
241 | static HRESULT WINAPI d3d9_pixelshader_GetDevice(IDirect3DPixelShader9 *iface, IDirect3DDevice9 **device)
|
---|
242 | {
|
---|
243 | struct d3d9_pixelshader *shader = impl_from_IDirect3DPixelShader9(iface);
|
---|
244 |
|
---|
245 | TRACE("iface %p, device %p.\n", iface, device);
|
---|
246 |
|
---|
247 | *device = (IDirect3DDevice9 *)shader->parent_device;
|
---|
248 | IDirect3DDevice9_AddRef(*device);
|
---|
249 |
|
---|
250 | TRACE("Returning device %p.\n", *device);
|
---|
251 |
|
---|
252 | return D3D_OK;
|
---|
253 | }
|
---|
254 |
|
---|
255 | static HRESULT WINAPI d3d9_pixelshader_GetFunction(IDirect3DPixelShader9 *iface, void *data, UINT *data_size)
|
---|
256 | {
|
---|
257 | struct d3d9_pixelshader *shader = impl_from_IDirect3DPixelShader9(iface);
|
---|
258 | HRESULT hr;
|
---|
259 |
|
---|
260 | TRACE("iface %p, data %p, data_size %p.\n", iface, data, data_size);
|
---|
261 |
|
---|
262 | wined3d_mutex_lock();
|
---|
263 | hr = wined3d_shader_get_byte_code(shader->wined3d_shader, data, data_size);
|
---|
264 | wined3d_mutex_unlock();
|
---|
265 |
|
---|
266 | return hr;
|
---|
267 | }
|
---|
268 |
|
---|
269 | static const IDirect3DPixelShader9Vtbl d3d9_pixelshader_vtbl =
|
---|
270 | {
|
---|
271 | /* IUnknown */
|
---|
272 | d3d9_pixelshader_QueryInterface,
|
---|
273 | d3d9_pixelshader_AddRef,
|
---|
274 | d3d9_pixelshader_Release,
|
---|
275 | /* IDirect3DPixelShader9 */
|
---|
276 | d3d9_pixelshader_GetDevice,
|
---|
277 | d3d9_pixelshader_GetFunction,
|
---|
278 | };
|
---|
279 |
|
---|
280 | static void STDMETHODCALLTYPE d3d9_pixelshader_wined3d_object_destroyed(void *parent)
|
---|
281 | {
|
---|
282 | HeapFree(GetProcessHeap(), 0, parent);
|
---|
283 | }
|
---|
284 |
|
---|
285 | static const struct wined3d_parent_ops d3d9_pixelshader_wined3d_parent_ops =
|
---|
286 | {
|
---|
287 | d3d9_pixelshader_wined3d_object_destroyed,
|
---|
288 | };
|
---|
289 |
|
---|
290 | HRESULT pixelshader_init(struct d3d9_pixelshader *shader, struct d3d9_device *device, const DWORD *byte_code)
|
---|
291 | {
|
---|
292 | HRESULT hr;
|
---|
293 |
|
---|
294 | shader->refcount = 1;
|
---|
295 | shader->IDirect3DPixelShader9_iface.lpVtbl = &d3d9_pixelshader_vtbl;
|
---|
296 |
|
---|
297 | wined3d_mutex_lock();
|
---|
298 | hr = wined3d_shader_create_ps(device->wined3d_device, byte_code, NULL, shader,
|
---|
299 | &d3d9_pixelshader_wined3d_parent_ops, &shader->wined3d_shader, 3);
|
---|
300 | wined3d_mutex_unlock();
|
---|
301 | if (FAILED(hr))
|
---|
302 | {
|
---|
303 | WARN("Failed to created wined3d pixel shader, hr %#x.\n", hr);
|
---|
304 | return hr;
|
---|
305 | }
|
---|
306 |
|
---|
307 | shader->parent_device = &device->IDirect3DDevice9Ex_iface;
|
---|
308 | IDirect3DDevice9Ex_AddRef(shader->parent_device);
|
---|
309 |
|
---|
310 | return D3D_OK;
|
---|
311 | }
|
---|
312 |
|
---|
313 | struct d3d9_pixelshader *unsafe_impl_from_IDirect3DPixelShader9(IDirect3DPixelShader9 *iface)
|
---|
314 | {
|
---|
315 | if (!iface)
|
---|
316 | return NULL;
|
---|
317 | assert(iface->lpVtbl == &d3d9_pixelshader_vtbl);
|
---|
318 |
|
---|
319 | return impl_from_IDirect3DPixelShader9(iface);
|
---|
320 | }
|
---|