2 * Copyright 2002-2003 Jason Edmeades
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.
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.
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
21 #include "d3d9_private.h"
23 WINE_DEFAULT_DEBUG_CHANNEL(d3d9
);
25 static HRESULT WINAPI
d3d9_vertexshader_QueryInterface(IDirect3DVertexShader9
*iface
, REFIID riid
, void **object
)
27 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
29 if (IsEqualGUID(riid
, &IID_IDirect3DVertexShader9
)
30 || IsEqualGUID(riid
, &IID_IUnknown
))
32 IDirect3DVertexShader9_AddRef(iface
);
37 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
43 static ULONG WINAPI
d3d9_vertexshader_AddRef(IDirect3DVertexShader9
*iface
)
45 IDirect3DVertexShader9Impl
*shader
= (IDirect3DVertexShader9Impl
*)iface
;
46 ULONG refcount
= InterlockedIncrement(&shader
->ref
);
48 TRACE("%p increasing refcount to %u.\n", iface
, refcount
);
52 IDirect3DDevice9Ex_AddRef(shader
->parentDevice
);
54 IWineD3DVertexShader_AddRef(shader
->wineD3DVertexShader
);
55 wined3d_mutex_unlock();
61 static ULONG WINAPI
d3d9_vertexshader_Release(IDirect3DVertexShader9
*iface
)
63 IDirect3DVertexShader9Impl
*shader
= (IDirect3DVertexShader9Impl
*)iface
;
64 ULONG refcount
= InterlockedDecrement(&shader
->ref
);
66 TRACE("%p decreasing refcount to %u.\n", iface
, refcount
);
70 IDirect3DDevice9Ex
*device
= shader
->parentDevice
;
73 IWineD3DVertexShader_Release(shader
->wineD3DVertexShader
);
74 wined3d_mutex_unlock();
76 /* Release the device last, as it may cause the device to be destroyed. */
77 IDirect3DDevice9Ex_Release(device
);
83 static HRESULT WINAPI
d3d9_vertexshader_GetDevice(IDirect3DVertexShader9
*iface
, IDirect3DDevice9
**device
)
85 TRACE("iface %p, device %p.\n", iface
, device
);
87 *device
= (IDirect3DDevice9
*)((IDirect3DVertexShader9Impl
*)iface
)->parentDevice
;
88 IDirect3DDevice9_AddRef(*device
);
90 TRACE("Returning device %p.\n", *device
);
95 static HRESULT WINAPI
d3d9_vertexshader_GetFunction(IDirect3DVertexShader9
*iface
,
96 void *data
, UINT
*data_size
)
100 TRACE("iface %p, data %p, data_size %p.\n", iface
, data
, data_size
);
102 wined3d_mutex_lock();
103 hr
= IWineD3DVertexShader_GetFunction(((IDirect3DVertexShader9Impl
*)iface
)->wineD3DVertexShader
, data
, data_size
);
104 wined3d_mutex_unlock();
109 static const IDirect3DVertexShader9Vtbl d3d9_vertexshader_vtbl
=
112 d3d9_vertexshader_QueryInterface
,
113 d3d9_vertexshader_AddRef
,
114 d3d9_vertexshader_Release
,
115 /* IDirect3DVertexShader9 */
116 d3d9_vertexshader_GetDevice
,
117 d3d9_vertexshader_GetFunction
,
120 static void STDMETHODCALLTYPE
d3d9_vertexshader_wined3d_object_destroyed(void *parent
)
122 HeapFree(GetProcessHeap(), 0, parent
);
125 static const struct wined3d_parent_ops d3d9_vertexshader_wined3d_parent_ops
=
127 d3d9_vertexshader_wined3d_object_destroyed
,
130 HRESULT
vertexshader_init(IDirect3DVertexShader9Impl
*shader
, IDirect3DDevice9Impl
*device
, const DWORD
*byte_code
)
135 shader
->lpVtbl
= &d3d9_vertexshader_vtbl
;
137 wined3d_mutex_lock();
138 hr
= IWineD3DDevice_CreateVertexShader(device
->WineD3DDevice
, byte_code
, NULL
,
139 shader
, &d3d9_vertexshader_wined3d_parent_ops
, &shader
->wineD3DVertexShader
);
140 wined3d_mutex_unlock();
143 WARN("Failed to create wined3d vertex shader, hr %#x.\n", hr
);
147 shader
->parentDevice
= (IDirect3DDevice9Ex
*)device
;
148 IDirect3DDevice9Ex_AddRef(shader
->parentDevice
);
153 static HRESULT WINAPI
d3d9_pixelshader_QueryInterface(IDirect3DPixelShader9
*iface
, REFIID riid
, void **object
)
155 TRACE("iface %p, riid %s, object %p.\n", iface
, debugstr_guid(riid
), object
);
157 if (IsEqualGUID(riid
, &IID_IDirect3DPixelShader9
)
158 || IsEqualGUID(riid
, &IID_IUnknown
))
160 IDirect3DPixelShader9_AddRef(iface
);
165 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
168 return E_NOINTERFACE
;
171 static ULONG WINAPI
d3d9_pixelshader_AddRef(IDirect3DPixelShader9
*iface
)
173 IDirect3DPixelShader9Impl
*shader
= (IDirect3DPixelShader9Impl
*)iface
;
174 ULONG refcount
= InterlockedIncrement(&shader
->ref
);
176 TRACE("%p increasing refcount to %u.\n", iface
, refcount
);
180 IDirect3DDevice9Ex_AddRef(shader
->parentDevice
);
181 wined3d_mutex_lock();
182 IWineD3DPixelShader_AddRef(shader
->wineD3DPixelShader
);
183 wined3d_mutex_unlock();
189 static ULONG WINAPI
d3d9_pixelshader_Release(IDirect3DPixelShader9
*iface
)
191 IDirect3DPixelShader9Impl
*shader
= (IDirect3DPixelShader9Impl
*)iface
;
192 ULONG refcount
= InterlockedDecrement(&shader
->ref
);
194 TRACE("%p decreasing refcount to %u.\n", iface
, refcount
);
198 IDirect3DDevice9Ex
*device
= shader
->parentDevice
;
200 wined3d_mutex_lock();
201 IWineD3DPixelShader_Release(shader
->wineD3DPixelShader
);
202 wined3d_mutex_unlock();
204 /* Release the device last, as it may cause the device to be destroyed. */
205 IDirect3DDevice9Ex_Release(device
);
211 static HRESULT WINAPI
d3d9_pixelshader_GetDevice(IDirect3DPixelShader9
*iface
, IDirect3DDevice9
**device
)
213 TRACE("iface %p, device %p.\n", iface
, device
);
215 *device
= (IDirect3DDevice9
*)((IDirect3DPixelShader9Impl
*)iface
)->parentDevice
;
216 IDirect3DDevice9_AddRef(*device
);
218 TRACE("Returning device %p.\n", *device
);
223 static HRESULT WINAPI
d3d9_pixelshader_GetFunction(IDirect3DPixelShader9
*iface
, void *data
, UINT
*data_size
)
227 TRACE("iface %p, data %p, data_size %p.\n", iface
, data
, data_size
);
229 wined3d_mutex_lock();
230 hr
= IWineD3DPixelShader_GetFunction(((IDirect3DPixelShader9Impl
*)iface
)->wineD3DPixelShader
, data
, data_size
);
231 wined3d_mutex_unlock();
236 static const IDirect3DPixelShader9Vtbl d3d9_pixelshader_vtbl
=
239 d3d9_pixelshader_QueryInterface
,
240 d3d9_pixelshader_AddRef
,
241 d3d9_pixelshader_Release
,
242 /* IDirect3DPixelShader9 */
243 d3d9_pixelshader_GetDevice
,
244 d3d9_pixelshader_GetFunction
,
247 static void STDMETHODCALLTYPE
d3d9_pixelshader_wined3d_object_destroyed(void *parent
)
249 HeapFree(GetProcessHeap(), 0, parent
);
252 static const struct wined3d_parent_ops d3d9_pixelshader_wined3d_parent_ops
=
254 d3d9_pixelshader_wined3d_object_destroyed
,
257 HRESULT
pixelshader_init(IDirect3DPixelShader9Impl
*shader
, IDirect3DDevice9Impl
*device
, const DWORD
*byte_code
)
262 shader
->lpVtbl
= &d3d9_pixelshader_vtbl
;
264 wined3d_mutex_lock();
265 hr
= IWineD3DDevice_CreatePixelShader(device
->WineD3DDevice
, byte_code
, NULL
, shader
,
266 &d3d9_pixelshader_wined3d_parent_ops
, &shader
->wineD3DPixelShader
);
267 wined3d_mutex_unlock();
270 WARN("Failed to created wined3d pixel shader, hr %#x.\n", hr
);
274 shader
->parentDevice
= (IDirect3DDevice9Ex
*)device
;
275 IDirect3DDevice9Ex_AddRef(shader
->parentDevice
);