d3dx9: Use float functions in D3DXQuaternionRotationMatrix().
[wine.git] / dlls / d3d9 / device.c
blobcd7e001bfa6e133e88bed9548a8b8d262ce65a3a
1 /*
2 * IDirect3DDevice9 implementation
4 * Copyright 2002-2005 Jason Edmeades
5 * Copyright 2002-2005 Raphael Junqueira
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 D3DFORMAT d3dformat_from_wined3dformat(enum wined3d_format_id format)
30 BYTE *c = (BYTE *)&format;
32 /* Don't translate FOURCC formats */
33 if (isprint(c[0]) && isprint(c[1]) && isprint(c[2]) && isprint(c[3])) return format;
35 switch(format)
37 case WINED3DFMT_UNKNOWN: return D3DFMT_UNKNOWN;
38 case WINED3DFMT_B8G8R8_UNORM: return D3DFMT_R8G8B8;
39 case WINED3DFMT_B8G8R8A8_UNORM: return D3DFMT_A8R8G8B8;
40 case WINED3DFMT_B8G8R8X8_UNORM: return D3DFMT_X8R8G8B8;
41 case WINED3DFMT_B5G6R5_UNORM: return D3DFMT_R5G6B5;
42 case WINED3DFMT_B5G5R5X1_UNORM: return D3DFMT_X1R5G5B5;
43 case WINED3DFMT_B5G5R5A1_UNORM: return D3DFMT_A1R5G5B5;
44 case WINED3DFMT_B4G4R4A4_UNORM: return D3DFMT_A4R4G4B4;
45 case WINED3DFMT_B2G3R3_UNORM: return D3DFMT_R3G3B2;
46 case WINED3DFMT_A8_UNORM: return D3DFMT_A8;
47 case WINED3DFMT_B2G3R3A8_UNORM: return D3DFMT_A8R3G3B2;
48 case WINED3DFMT_B4G4R4X4_UNORM: return D3DFMT_X4R4G4B4;
49 case WINED3DFMT_R10G10B10A2_UNORM: return D3DFMT_A2B10G10R10;
50 case WINED3DFMT_R8G8B8A8_UNORM: return D3DFMT_A8B8G8R8;
51 case WINED3DFMT_R8G8B8X8_UNORM: return D3DFMT_X8B8G8R8;
52 case WINED3DFMT_R16G16_UNORM: return D3DFMT_G16R16;
53 case WINED3DFMT_B10G10R10A2_UNORM: return D3DFMT_A2R10G10B10;
54 case WINED3DFMT_R16G16B16A16_UNORM: return D3DFMT_A16B16G16R16;
55 case WINED3DFMT_P8_UINT_A8_UNORM: return D3DFMT_A8P8;
56 case WINED3DFMT_P8_UINT: return D3DFMT_P8;
57 case WINED3DFMT_L8_UNORM: return D3DFMT_L8;
58 case WINED3DFMT_L8A8_UNORM: return D3DFMT_A8L8;
59 case WINED3DFMT_L4A4_UNORM: return D3DFMT_A4L4;
60 case WINED3DFMT_R8G8_SNORM: return D3DFMT_V8U8;
61 case WINED3DFMT_R5G5_SNORM_L6_UNORM: return D3DFMT_L6V5U5;
62 case WINED3DFMT_R8G8_SNORM_L8X8_UNORM: return D3DFMT_X8L8V8U8;
63 case WINED3DFMT_R8G8B8A8_SNORM: return D3DFMT_Q8W8V8U8;
64 case WINED3DFMT_R16G16_SNORM: return D3DFMT_V16U16;
65 case WINED3DFMT_R10G10B10_SNORM_A2_UNORM: return D3DFMT_A2W10V10U10;
66 case WINED3DFMT_D16_LOCKABLE: return D3DFMT_D16_LOCKABLE;
67 case WINED3DFMT_D32_UNORM: return D3DFMT_D32;
68 case WINED3DFMT_S1_UINT_D15_UNORM: return D3DFMT_D15S1;
69 case WINED3DFMT_D24_UNORM_S8_UINT: return D3DFMT_D24S8;
70 case WINED3DFMT_X8D24_UNORM: return D3DFMT_D24X8;
71 case WINED3DFMT_S4X4_UINT_D24_UNORM: return D3DFMT_D24X4S4;
72 case WINED3DFMT_D16_UNORM: return D3DFMT_D16;
73 case WINED3DFMT_L16_UNORM: return D3DFMT_L16;
74 case WINED3DFMT_D32_FLOAT: return D3DFMT_D32F_LOCKABLE;
75 case WINED3DFMT_S8_UINT_D24_FLOAT: return D3DFMT_D24FS8;
76 case WINED3DFMT_VERTEXDATA: return D3DFMT_VERTEXDATA;
77 case WINED3DFMT_R16_UINT: return D3DFMT_INDEX16;
78 case WINED3DFMT_R32_UINT: return D3DFMT_INDEX32;
79 case WINED3DFMT_R16G16B16A16_SNORM: return D3DFMT_Q16W16V16U16;
80 case WINED3DFMT_R16_FLOAT: return D3DFMT_R16F;
81 case WINED3DFMT_R16G16_FLOAT: return D3DFMT_G16R16F;
82 case WINED3DFMT_R16G16B16A16_FLOAT: return D3DFMT_A16B16G16R16F;
83 case WINED3DFMT_R32_FLOAT: return D3DFMT_R32F;
84 case WINED3DFMT_R32G32_FLOAT: return D3DFMT_G32R32F;
85 case WINED3DFMT_R32G32B32A32_FLOAT: return D3DFMT_A32B32G32R32F;
86 case WINED3DFMT_R8G8_SNORM_Cx: return D3DFMT_CxV8U8;
87 default:
88 FIXME("Unhandled wined3d format %#x.\n", format);
89 return D3DFMT_UNKNOWN;
93 enum wined3d_format_id wined3dformat_from_d3dformat(D3DFORMAT format)
95 BYTE *c = (BYTE *)&format;
97 /* Don't translate FOURCC formats */
98 if (isprint(c[0]) && isprint(c[1]) && isprint(c[2]) && isprint(c[3])) return format;
100 switch(format)
102 case D3DFMT_UNKNOWN: return WINED3DFMT_UNKNOWN;
103 case D3DFMT_R8G8B8: return WINED3DFMT_B8G8R8_UNORM;
104 case D3DFMT_A8R8G8B8: return WINED3DFMT_B8G8R8A8_UNORM;
105 case D3DFMT_X8R8G8B8: return WINED3DFMT_B8G8R8X8_UNORM;
106 case D3DFMT_R5G6B5: return WINED3DFMT_B5G6R5_UNORM;
107 case D3DFMT_X1R5G5B5: return WINED3DFMT_B5G5R5X1_UNORM;
108 case D3DFMT_A1R5G5B5: return WINED3DFMT_B5G5R5A1_UNORM;
109 case D3DFMT_A4R4G4B4: return WINED3DFMT_B4G4R4A4_UNORM;
110 case D3DFMT_R3G3B2: return WINED3DFMT_B2G3R3_UNORM;
111 case D3DFMT_A8: return WINED3DFMT_A8_UNORM;
112 case D3DFMT_A8R3G3B2: return WINED3DFMT_B2G3R3A8_UNORM;
113 case D3DFMT_X4R4G4B4: return WINED3DFMT_B4G4R4X4_UNORM;
114 case D3DFMT_A2B10G10R10: return WINED3DFMT_R10G10B10A2_UNORM;
115 case D3DFMT_A8B8G8R8: return WINED3DFMT_R8G8B8A8_UNORM;
116 case D3DFMT_X8B8G8R8: return WINED3DFMT_R8G8B8X8_UNORM;
117 case D3DFMT_G16R16: return WINED3DFMT_R16G16_UNORM;
118 case D3DFMT_A2R10G10B10: return WINED3DFMT_B10G10R10A2_UNORM;
119 case D3DFMT_A16B16G16R16: return WINED3DFMT_R16G16B16A16_UNORM;
120 case D3DFMT_A8P8: return WINED3DFMT_P8_UINT_A8_UNORM;
121 case D3DFMT_P8: return WINED3DFMT_P8_UINT;
122 case D3DFMT_L8: return WINED3DFMT_L8_UNORM;
123 case D3DFMT_A8L8: return WINED3DFMT_L8A8_UNORM;
124 case D3DFMT_A4L4: return WINED3DFMT_L4A4_UNORM;
125 case D3DFMT_V8U8: return WINED3DFMT_R8G8_SNORM;
126 case D3DFMT_L6V5U5: return WINED3DFMT_R5G5_SNORM_L6_UNORM;
127 case D3DFMT_X8L8V8U8: return WINED3DFMT_R8G8_SNORM_L8X8_UNORM;
128 case D3DFMT_Q8W8V8U8: return WINED3DFMT_R8G8B8A8_SNORM;
129 case D3DFMT_V16U16: return WINED3DFMT_R16G16_SNORM;
130 case D3DFMT_A2W10V10U10: return WINED3DFMT_R10G10B10_SNORM_A2_UNORM;
131 case D3DFMT_D16_LOCKABLE: return WINED3DFMT_D16_LOCKABLE;
132 case D3DFMT_D32: return WINED3DFMT_D32_UNORM;
133 case D3DFMT_D15S1: return WINED3DFMT_S1_UINT_D15_UNORM;
134 case D3DFMT_D24S8: return WINED3DFMT_D24_UNORM_S8_UINT;
135 case D3DFMT_D24X8: return WINED3DFMT_X8D24_UNORM;
136 case D3DFMT_D24X4S4: return WINED3DFMT_S4X4_UINT_D24_UNORM;
137 case D3DFMT_D16: return WINED3DFMT_D16_UNORM;
138 case D3DFMT_L16: return WINED3DFMT_L16_UNORM;
139 case D3DFMT_D32F_LOCKABLE: return WINED3DFMT_D32_FLOAT;
140 case D3DFMT_D24FS8: return WINED3DFMT_S8_UINT_D24_FLOAT;
141 case D3DFMT_VERTEXDATA: return WINED3DFMT_VERTEXDATA;
142 case D3DFMT_INDEX16: return WINED3DFMT_R16_UINT;
143 case D3DFMT_INDEX32: return WINED3DFMT_R32_UINT;
144 case D3DFMT_Q16W16V16U16: return WINED3DFMT_R16G16B16A16_SNORM;
145 case D3DFMT_R16F: return WINED3DFMT_R16_FLOAT;
146 case D3DFMT_G16R16F: return WINED3DFMT_R16G16_FLOAT;
147 case D3DFMT_A16B16G16R16F: return WINED3DFMT_R16G16B16A16_FLOAT;
148 case D3DFMT_R32F: return WINED3DFMT_R32_FLOAT;
149 case D3DFMT_G32R32F: return WINED3DFMT_R32G32_FLOAT;
150 case D3DFMT_A32B32G32R32F: return WINED3DFMT_R32G32B32A32_FLOAT;
151 case D3DFMT_CxV8U8: return WINED3DFMT_R8G8_SNORM_Cx;
152 default:
153 FIXME("Unhandled D3DFORMAT %#x\n", format);
154 return WINED3DFMT_UNKNOWN;
158 static UINT vertex_count_from_primitive_count(D3DPRIMITIVETYPE primitive_type, UINT primitive_count)
160 switch(primitive_type)
162 case D3DPT_POINTLIST:
163 return primitive_count;
165 case D3DPT_LINELIST:
166 return primitive_count * 2;
168 case D3DPT_LINESTRIP:
169 return primitive_count + 1;
171 case D3DPT_TRIANGLELIST:
172 return primitive_count * 3;
174 case D3DPT_TRIANGLESTRIP:
175 case D3DPT_TRIANGLEFAN:
176 return primitive_count + 2;
178 default:
179 FIXME("Unhandled primitive type %#x\n", primitive_type);
180 return 0;
184 void present_parameters_from_wined3d_swapchain_desc(D3DPRESENT_PARAMETERS *present_parameters,
185 const struct wined3d_swapchain_desc *swapchain_desc)
187 present_parameters->BackBufferWidth = swapchain_desc->backbuffer_width;
188 present_parameters->BackBufferHeight = swapchain_desc->backbuffer_height;
189 present_parameters->BackBufferFormat = d3dformat_from_wined3dformat(swapchain_desc->backbuffer_format);
190 present_parameters->BackBufferCount = swapchain_desc->backbuffer_count;
191 present_parameters->MultiSampleType = swapchain_desc->multisample_type;
192 present_parameters->MultiSampleQuality = swapchain_desc->multisample_quality;
193 present_parameters->SwapEffect = swapchain_desc->swap_effect;
194 present_parameters->hDeviceWindow = swapchain_desc->device_window;
195 present_parameters->Windowed = swapchain_desc->windowed;
196 present_parameters->EnableAutoDepthStencil = swapchain_desc->enable_auto_depth_stencil;
197 present_parameters->AutoDepthStencilFormat
198 = d3dformat_from_wined3dformat(swapchain_desc->auto_depth_stencil_format);
199 present_parameters->Flags = swapchain_desc->flags;
200 present_parameters->FullScreen_RefreshRateInHz = swapchain_desc->refresh_rate;
201 present_parameters->PresentationInterval = swapchain_desc->swap_interval;
204 static void wined3d_swapchain_desc_from_present_parameters(struct wined3d_swapchain_desc *swapchain_desc,
205 const D3DPRESENT_PARAMETERS *present_parameters)
207 swapchain_desc->backbuffer_width = present_parameters->BackBufferWidth;
208 swapchain_desc->backbuffer_height = present_parameters->BackBufferHeight;
209 swapchain_desc->backbuffer_format = wined3dformat_from_d3dformat(present_parameters->BackBufferFormat);
210 swapchain_desc->backbuffer_count = max(1, present_parameters->BackBufferCount);
211 swapchain_desc->multisample_type = present_parameters->MultiSampleType;
212 swapchain_desc->multisample_quality = present_parameters->MultiSampleQuality;
213 swapchain_desc->swap_effect = present_parameters->SwapEffect;
214 swapchain_desc->device_window = present_parameters->hDeviceWindow;
215 swapchain_desc->windowed = present_parameters->Windowed;
216 swapchain_desc->enable_auto_depth_stencil = present_parameters->EnableAutoDepthStencil;
217 swapchain_desc->auto_depth_stencil_format
218 = wined3dformat_from_d3dformat(present_parameters->AutoDepthStencilFormat);
219 swapchain_desc->flags = present_parameters->Flags;
220 swapchain_desc->refresh_rate = present_parameters->FullScreen_RefreshRateInHz;
221 swapchain_desc->swap_interval = present_parameters->PresentationInterval;
222 swapchain_desc->auto_restore_display_mode = TRUE;
225 static inline struct d3d9_device *impl_from_IDirect3DDevice9Ex(IDirect3DDevice9Ex *iface)
227 return CONTAINING_RECORD(iface, struct d3d9_device, IDirect3DDevice9Ex_iface);
230 static HRESULT WINAPI d3d9_device_QueryInterface(IDirect3DDevice9Ex *iface, REFIID riid, void **out)
232 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
234 if (IsEqualGUID(riid, &IID_IDirect3DDevice9)
235 || IsEqualGUID(riid, &IID_IUnknown))
237 IDirect3DDevice9Ex_AddRef(iface);
238 *out = iface;
239 return S_OK;
242 if (IsEqualGUID(riid, &IID_IDirect3DDevice9Ex))
244 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
246 /* Find out if the creating d3d9 interface was created with Direct3DCreate9Ex.
247 * It doesn't matter with which function the device was created. */
248 if (!device->d3d_parent->extended)
250 WARN("IDirect3D9 instance wasn't created with CreateDirect3D9Ex, returning E_NOINTERFACE.\n");
251 *out = NULL;
252 return E_NOINTERFACE;
255 IDirect3DDevice9Ex_AddRef(iface);
256 *out = iface;
257 return S_OK;
260 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
262 *out = NULL;
263 return E_NOINTERFACE;
266 static ULONG WINAPI d3d9_device_AddRef(IDirect3DDevice9Ex *iface)
268 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
269 ULONG refcount = InterlockedIncrement(&device->refcount);
271 TRACE("%p increasing refcount to %u.\n", iface, refcount);
273 return refcount;
276 static ULONG WINAPI DECLSPEC_HOTPATCH d3d9_device_Release(IDirect3DDevice9Ex *iface)
278 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
279 ULONG refcount;
281 if (device->in_destruction)
282 return 0;
284 refcount = InterlockedDecrement(&device->refcount);
286 TRACE("%p decreasing refcount to %u.\n", iface, refcount);
288 if (!refcount)
290 unsigned i;
291 device->in_destruction = TRUE;
293 wined3d_mutex_lock();
294 for (i = 0; i < device->fvf_decl_count; ++i)
296 wined3d_vertex_declaration_decref(device->fvf_decls[i].decl);
298 HeapFree(GetProcessHeap(), 0, device->fvf_decls);
300 wined3d_device_uninit_3d(device->wined3d_device);
301 wined3d_device_release_focus_window(device->wined3d_device);
302 wined3d_device_decref(device->wined3d_device);
303 wined3d_mutex_unlock();
305 IDirect3D9Ex_Release(&device->d3d_parent->IDirect3D9Ex_iface);
307 HeapFree(GetProcessHeap(), 0, device);
310 return refcount;
313 static HRESULT WINAPI d3d9_device_TestCooperativeLevel(IDirect3DDevice9Ex *iface)
315 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
317 TRACE("iface %p.\n", iface);
319 if (device->not_reset)
321 TRACE("D3D9 device is marked not reset.\n");
322 return D3DERR_DEVICENOTRESET;
325 return D3D_OK;
328 static UINT WINAPI d3d9_device_GetAvailableTextureMem(IDirect3DDevice9Ex *iface)
330 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
331 HRESULT hr;
333 TRACE("iface %p.\n", iface);
335 wined3d_mutex_lock();
336 hr = wined3d_device_get_available_texture_mem(device->wined3d_device);
337 wined3d_mutex_unlock();
339 return hr;
342 static HRESULT WINAPI d3d9_device_EvictManagedResources(IDirect3DDevice9Ex *iface)
344 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
346 TRACE("iface %p.\n", iface);
348 wined3d_mutex_lock();
349 wined3d_device_evict_managed_resources(device->wined3d_device);
350 wined3d_mutex_unlock();
352 return D3D_OK;
355 static HRESULT WINAPI d3d9_device_GetDirect3D(IDirect3DDevice9Ex *iface, IDirect3D9 **d3d9)
357 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
359 TRACE("iface %p, d3d9 %p.\n", iface, d3d9);
361 if (!d3d9)
362 return D3DERR_INVALIDCALL;
364 return IDirect3D9Ex_QueryInterface(&device->d3d_parent->IDirect3D9Ex_iface, &IID_IDirect3D9, (void **)d3d9);
367 static HRESULT WINAPI d3d9_device_GetDeviceCaps(IDirect3DDevice9Ex *iface, D3DCAPS9 *caps)
369 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
370 WINED3DCAPS *wined3d_caps;
371 HRESULT hr;
373 TRACE("iface %p, caps %p.\n", iface, caps);
375 if (!caps)
376 return D3DERR_INVALIDCALL;
378 if (!(wined3d_caps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*wined3d_caps))))
379 return D3DERR_INVALIDCALL; /* well this is what MSDN says to return */
381 memset(caps, 0, sizeof(*caps));
383 wined3d_mutex_lock();
384 hr = wined3d_device_get_device_caps(device->wined3d_device, wined3d_caps);
385 wined3d_mutex_unlock();
387 WINECAPSTOD3D9CAPS(caps, wined3d_caps)
388 HeapFree(GetProcessHeap(), 0, wined3d_caps);
390 /* Some functionality is implemented in d3d9.dll, not wined3d.dll. Add the needed caps */
391 caps->DevCaps2 |= D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES;
393 filter_caps(caps);
395 return hr;
398 static HRESULT WINAPI d3d9_device_GetDisplayMode(IDirect3DDevice9Ex *iface, UINT swapchain, D3DDISPLAYMODE *mode)
400 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
401 struct wined3d_display_mode wined3d_mode;
402 HRESULT hr;
404 TRACE("iface %p, swapchain %u, mode %p.\n", iface, swapchain, mode);
406 wined3d_mutex_lock();
407 hr = wined3d_device_get_display_mode(device->wined3d_device, swapchain, &wined3d_mode, NULL);
408 wined3d_mutex_unlock();
410 if (SUCCEEDED(hr))
412 mode->Width = wined3d_mode.width;
413 mode->Height = wined3d_mode.height;
414 mode->RefreshRate = wined3d_mode.refresh_rate;
415 mode->Format = d3dformat_from_wined3dformat(wined3d_mode.format_id);
418 return hr;
421 static HRESULT WINAPI d3d9_device_GetCreationParameters(IDirect3DDevice9Ex *iface,
422 D3DDEVICE_CREATION_PARAMETERS *parameters)
424 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
425 HRESULT hr;
427 TRACE("iface %p, parameters %p.\n", iface, parameters);
429 wined3d_mutex_lock();
430 hr = wined3d_device_get_creation_parameters(device->wined3d_device,
431 (struct wined3d_device_creation_parameters *)parameters);
432 wined3d_mutex_unlock();
434 return hr;
437 static HRESULT WINAPI d3d9_device_SetCursorProperties(IDirect3DDevice9Ex *iface,
438 UINT hotspot_x, UINT hotspot_y, IDirect3DSurface9 *bitmap)
440 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
441 struct d3d9_surface *bitmap_impl = unsafe_impl_from_IDirect3DSurface9(bitmap);
442 HRESULT hr;
444 TRACE("iface %p, hotspot_x %u, hotspot_y %u, bitmap %p.\n",
445 iface, hotspot_x, hotspot_y, bitmap);
447 if (!bitmap)
449 WARN("No cursor bitmap, returning D3DERR_INVALIDCALL.\n");
450 return D3DERR_INVALIDCALL;
453 wined3d_mutex_lock();
454 hr = wined3d_device_set_cursor_properties(device->wined3d_device,
455 hotspot_x, hotspot_y, bitmap_impl->wined3d_surface);
456 wined3d_mutex_unlock();
458 return hr;
461 static void WINAPI d3d9_device_SetCursorPosition(IDirect3DDevice9Ex *iface, int x, int y, DWORD flags)
463 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
465 TRACE("iface %p, x %u, y %u, flags %#x.\n", iface, x, y, flags);
467 wined3d_mutex_lock();
468 wined3d_device_set_cursor_position(device->wined3d_device, x, y, flags);
469 wined3d_mutex_unlock();
472 static BOOL WINAPI d3d9_device_ShowCursor(IDirect3DDevice9Ex *iface, BOOL show)
474 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
475 BOOL ret;
477 TRACE("iface %p, show %#x.\n", iface, show);
479 wined3d_mutex_lock();
480 ret = wined3d_device_show_cursor(device->wined3d_device, show);
481 wined3d_mutex_unlock();
483 return ret;
486 static HRESULT WINAPI DECLSPEC_HOTPATCH d3d9_device_CreateAdditionalSwapChain(IDirect3DDevice9Ex *iface,
487 D3DPRESENT_PARAMETERS *present_parameters, IDirect3DSwapChain9 **swapchain)
489 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
490 struct wined3d_swapchain_desc desc;
491 struct d3d9_swapchain *object;
492 HRESULT hr;
494 TRACE("iface %p, present_parameters %p, swapchain %p.\n",
495 iface, present_parameters, swapchain);
497 wined3d_swapchain_desc_from_present_parameters(&desc, present_parameters);
498 if (SUCCEEDED(hr = d3d9_swapchain_create(device, &desc, &object)))
499 *swapchain = &object->IDirect3DSwapChain9_iface;
500 present_parameters_from_wined3d_swapchain_desc(present_parameters, &desc);
502 return hr;
505 static HRESULT WINAPI DECLSPEC_HOTPATCH d3d9_device_GetSwapChain(IDirect3DDevice9Ex *iface,
506 UINT swapchain_idx, IDirect3DSwapChain9 **swapchain)
508 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
509 struct wined3d_swapchain *wined3d_swapchain;
510 struct d3d9_swapchain *swapchain_impl;
511 HRESULT hr;
513 TRACE("iface %p, swapchain_idx %u, swapchain %p.\n", iface, swapchain_idx, swapchain);
515 wined3d_mutex_lock();
516 if ((wined3d_swapchain = wined3d_device_get_swapchain(device->wined3d_device, swapchain_idx)))
518 swapchain_impl = wined3d_swapchain_get_parent(wined3d_swapchain);
519 *swapchain = &swapchain_impl->IDirect3DSwapChain9_iface;
520 IDirect3DSwapChain9_AddRef(*swapchain);
521 hr = D3D_OK;
523 else
525 *swapchain = NULL;
526 hr = D3DERR_INVALIDCALL;
528 wined3d_mutex_unlock();
530 return hr;
533 static UINT WINAPI d3d9_device_GetNumberOfSwapChains(IDirect3DDevice9Ex *iface)
535 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
536 UINT count;
538 TRACE("iface %p.\n", iface);
540 wined3d_mutex_lock();
541 count = wined3d_device_get_swapchain_count(device->wined3d_device);
542 wined3d_mutex_unlock();
544 return count;
547 static HRESULT CDECL reset_enum_callback(struct wined3d_resource *resource)
549 struct wined3d_resource_desc desc;
551 wined3d_resource_get_desc(resource, &desc);
552 if (desc.pool == WINED3D_POOL_DEFAULT)
554 struct d3d9_surface *surface;
556 if (desc.resource_type != WINED3D_RTYPE_SURFACE)
558 WARN("Resource %p in pool D3DPOOL_DEFAULT blocks the Reset call.\n", resource);
559 return D3DERR_INVALIDCALL;
562 surface = wined3d_resource_get_parent(resource);
563 if (surface->refcount)
565 WARN("Surface %p (resource %p) in pool D3DPOOL_DEFAULT blocks the Reset call.\n", surface, resource);
566 return D3DERR_INVALIDCALL;
569 WARN("Surface %p (resource %p) is an implicit resource with ref 0.\n", surface, resource);
572 return D3D_OK;
575 static HRESULT WINAPI DECLSPEC_HOTPATCH d3d9_device_Reset(IDirect3DDevice9Ex *iface,
576 D3DPRESENT_PARAMETERS *present_parameters)
578 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
579 struct wined3d_swapchain_desc swapchain_desc;
580 HRESULT hr;
582 TRACE("iface %p, present_parameters %p.\n", iface, present_parameters);
584 wined3d_mutex_lock();
585 wined3d_swapchain_desc_from_present_parameters(&swapchain_desc, present_parameters);
586 hr = wined3d_device_reset(device->wined3d_device, &swapchain_desc, NULL, reset_enum_callback);
587 if (FAILED(hr))
588 device->not_reset = TRUE;
589 else
590 device->not_reset = FALSE;
591 wined3d_mutex_unlock();
593 return hr;
596 static HRESULT WINAPI DECLSPEC_HOTPATCH d3d9_device_Present(IDirect3DDevice9Ex *iface,
597 const RECT *src_rect, const RECT *dst_rect, HWND dst_window_override, const RGNDATA *dirty_region)
599 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
600 HRESULT hr;
602 TRACE("iface %p, src_rect %p, dst_rect %p, dst_window_override %p, dirty_region %p.\n",
603 iface, src_rect, dst_rect, dst_window_override, dirty_region);
605 wined3d_mutex_lock();
606 hr = wined3d_device_present(device->wined3d_device, src_rect, dst_rect,
607 dst_window_override, dirty_region, 0);
608 wined3d_mutex_unlock();
610 return hr;
613 static HRESULT WINAPI d3d9_device_GetBackBuffer(IDirect3DDevice9Ex *iface, UINT swapchain,
614 UINT backbuffer_idx, D3DBACKBUFFER_TYPE backbuffer_type, IDirect3DSurface9 **backbuffer)
616 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
617 struct wined3d_surface *wined3d_surface = NULL;
618 struct d3d9_surface *surface_impl;
619 HRESULT hr;
621 TRACE("iface %p, swapchain %u, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n",
622 iface, swapchain, backbuffer_idx, backbuffer_type, backbuffer);
624 wined3d_mutex_lock();
625 hr = wined3d_device_get_back_buffer(device->wined3d_device, swapchain,
626 backbuffer_idx, (enum wined3d_backbuffer_type)backbuffer_type, &wined3d_surface);
627 if (SUCCEEDED(hr) && wined3d_surface && backbuffer)
629 surface_impl = wined3d_surface_get_parent(wined3d_surface);
630 *backbuffer = &surface_impl->IDirect3DSurface9_iface;
631 IDirect3DSurface9_AddRef(*backbuffer);
632 wined3d_surface_decref(wined3d_surface);
634 wined3d_mutex_unlock();
636 return hr;
638 static HRESULT WINAPI d3d9_device_GetRasterStatus(IDirect3DDevice9Ex *iface,
639 UINT swapchain, D3DRASTER_STATUS *raster_status)
641 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
642 HRESULT hr;
644 TRACE("iface %p, swapchain %u, raster_status %p.\n", iface, swapchain, raster_status);
646 wined3d_mutex_lock();
647 hr = wined3d_device_get_raster_status(device->wined3d_device,
648 swapchain, (struct wined3d_raster_status *)raster_status);
649 wined3d_mutex_unlock();
651 return hr;
654 static HRESULT WINAPI d3d9_device_SetDialogBoxMode(IDirect3DDevice9Ex *iface, BOOL enable)
656 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
657 HRESULT hr;
659 TRACE("iface %p, enable %#x.\n", iface, enable);
661 wined3d_mutex_lock();
662 hr = wined3d_device_set_dialog_box_mode(device->wined3d_device, enable);
663 wined3d_mutex_unlock();
665 return hr;
668 static void WINAPI d3d9_device_SetGammaRamp(IDirect3DDevice9Ex *iface,
669 UINT swapchain, DWORD flags, const D3DGAMMARAMP *ramp)
671 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
673 TRACE("iface %p, swapchain %u, flags %#x, ramp %p.\n", iface, swapchain, flags, ramp);
675 /* Note: D3DGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
676 wined3d_mutex_lock();
677 wined3d_device_set_gamma_ramp(device->wined3d_device, swapchain, flags, (const struct wined3d_gamma_ramp *)ramp);
678 wined3d_mutex_unlock();
681 static void WINAPI d3d9_device_GetGammaRamp(IDirect3DDevice9Ex *iface, UINT swapchain, D3DGAMMARAMP *ramp)
683 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
685 TRACE("iface %p, swapchain %u, ramp %p.\n", iface, swapchain, ramp);
687 /* Note: D3DGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
688 wined3d_mutex_lock();
689 wined3d_device_get_gamma_ramp(device->wined3d_device, swapchain, (struct wined3d_gamma_ramp *)ramp);
690 wined3d_mutex_unlock();
693 static HRESULT WINAPI d3d9_device_CreateTexture(IDirect3DDevice9Ex *iface,
694 UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format,
695 D3DPOOL pool, IDirect3DTexture9 **texture, HANDLE *shared_handle)
697 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
698 struct d3d9_texture *object;
699 BOOL set_mem = FALSE;
700 HRESULT hr;
702 TRACE("iface %p, width %u, height %u, levels %u, usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
703 iface, width, height, levels, usage, format, pool, texture, shared_handle);
705 if (shared_handle)
707 if (pool == D3DPOOL_SYSTEMMEM)
709 if (levels != 1)
710 return D3DERR_INVALIDCALL;
711 set_mem = TRUE;
713 else
714 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle);
717 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
718 if (!object)
720 ERR("Failed to allocate texture memory.\n");
721 return D3DERR_OUTOFVIDEOMEMORY;
724 hr = texture_init(object, device, width, height, levels, usage, format, pool);
725 if (FAILED(hr))
727 WARN("Failed to initialize texture, hr %#x.\n", hr);
728 HeapFree(GetProcessHeap(), 0, object);
729 return hr;
732 if (set_mem)
734 struct wined3d_resource *resource;
735 struct d3d9_surface *surface;
737 resource = wined3d_texture_get_sub_resource(object->wined3d_texture, 0);
738 surface = wined3d_resource_get_parent(resource);
739 wined3d_surface_set_mem(surface->wined3d_surface, *shared_handle);
742 TRACE("Created texture %p.\n", object);
743 *texture = (IDirect3DTexture9 *)&object->IDirect3DBaseTexture9_iface;
745 return D3D_OK;
748 static HRESULT WINAPI d3d9_device_CreateVolumeTexture(IDirect3DDevice9Ex *iface,
749 UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format,
750 D3DPOOL pool, IDirect3DVolumeTexture9 **texture, HANDLE *shared_handle)
752 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
753 struct d3d9_texture *object;
754 HRESULT hr;
756 TRACE("iface %p, width %u, height %u, depth %u, levels %u\n",
757 iface, width, height, depth, levels);
758 TRACE("usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
759 usage, format, pool, texture, shared_handle);
761 if (shared_handle)
762 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle);
764 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
765 if (!object)
767 ERR("Failed to allocate volume texture memory.\n");
768 return D3DERR_OUTOFVIDEOMEMORY;
771 hr = volumetexture_init(object, device, width, height, depth, levels, usage, format, pool);
772 if (FAILED(hr))
774 WARN("Failed to initialize volume texture, hr %#x.\n", hr);
775 HeapFree(GetProcessHeap(), 0, object);
776 return hr;
779 TRACE("Created volume texture %p.\n", object);
780 *texture = (IDirect3DVolumeTexture9 *)&object->IDirect3DBaseTexture9_iface;
782 return D3D_OK;
785 static HRESULT WINAPI d3d9_device_CreateCubeTexture(IDirect3DDevice9Ex *iface,
786 UINT edge_length, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool,
787 IDirect3DCubeTexture9 **texture, HANDLE *shared_handle)
789 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
790 struct d3d9_texture *object;
791 HRESULT hr;
793 TRACE("iface %p, edge_length %u, levels %u, usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
794 iface, edge_length, levels, usage, format, pool, texture, shared_handle);
796 if (shared_handle)
797 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle);
799 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
800 if (!object)
802 ERR("Failed to allocate cube texture memory.\n");
803 return D3DERR_OUTOFVIDEOMEMORY;
806 hr = cubetexture_init(object, device, edge_length, levels, usage, format, pool);
807 if (FAILED(hr))
809 WARN("Failed to initialize cube texture, hr %#x.\n", hr);
810 HeapFree(GetProcessHeap(), 0, object);
811 return hr;
814 TRACE("Created cube texture %p.\n", object);
815 *texture = (IDirect3DCubeTexture9 *)&object->IDirect3DBaseTexture9_iface;
817 return D3D_OK;
820 static HRESULT WINAPI d3d9_device_CreateVertexBuffer(IDirect3DDevice9Ex *iface, UINT size,
821 DWORD usage, DWORD fvf, D3DPOOL pool, IDirect3DVertexBuffer9 **buffer,
822 HANDLE *shared_handle)
824 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
825 struct d3d9_vertexbuffer *object;
826 HRESULT hr;
828 TRACE("iface %p, size %u, usage %#x, fvf %#x, pool %#x, buffer %p, shared_handle %p.\n",
829 iface, size, usage, fvf, pool, buffer, shared_handle);
831 if (shared_handle)
832 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle);
834 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
835 if (!object)
837 ERR("Failed to allocate buffer memory.\n");
838 return D3DERR_OUTOFVIDEOMEMORY;
841 hr = vertexbuffer_init(object, device, size, usage, fvf, pool);
842 if (FAILED(hr))
844 WARN("Failed to initialize vertex buffer, hr %#x.\n", hr);
845 HeapFree(GetProcessHeap(), 0, object);
846 return hr;
849 TRACE("Created vertex buffer %p.\n", object);
850 *buffer = &object->IDirect3DVertexBuffer9_iface;
852 return D3D_OK;
855 static HRESULT WINAPI d3d9_device_CreateIndexBuffer(IDirect3DDevice9Ex *iface, UINT size,
856 DWORD usage, D3DFORMAT format, D3DPOOL pool, IDirect3DIndexBuffer9 **buffer,
857 HANDLE *shared_handle)
859 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
860 struct d3d9_indexbuffer *object;
861 HRESULT hr;
863 TRACE("iface %p, size %u, usage %#x, format %#x, pool %#x, buffer %p, shared_handle %p.\n",
864 iface, size, usage, format, pool, buffer, shared_handle);
866 if (shared_handle)
867 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle);
869 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
870 if (!object)
872 ERR("Failed to allocate buffer memory.\n");
873 return D3DERR_OUTOFVIDEOMEMORY;
876 hr = indexbuffer_init(object, device, size, usage, format, pool);
877 if (FAILED(hr))
879 WARN("Failed to initialize index buffer, hr %#x.\n", hr);
880 HeapFree(GetProcessHeap(), 0, object);
881 return hr;
884 TRACE("Created index buffer %p.\n", object);
885 *buffer = &object->IDirect3DIndexBuffer9_iface;
887 return D3D_OK;
890 static HRESULT d3d9_device_create_surface(struct d3d9_device *device, UINT width, UINT height,
891 D3DFORMAT format, BOOL lockable, BOOL discard, UINT level, IDirect3DSurface9 **surface,
892 UINT usage, D3DPOOL pool, D3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality)
894 struct d3d9_surface *object;
895 HRESULT hr;
897 TRACE("device %p, width %u, height %u, format %#x, lockable %#x, discard %#x, level %u, surface %p.\n"
898 "usage %#x, pool %#x, multisample_type %#x, multisample_quality %u.\n",
899 device, width, height, format, lockable, discard, level, surface, usage, pool,
900 multisample_type, multisample_quality);
902 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
904 FIXME("Failed to allocate surface memory.\n");
905 return D3DERR_OUTOFVIDEOMEMORY;
908 hr = surface_init(object, device, width, height, format, lockable, discard,
909 level, usage, pool, multisample_type, multisample_quality);
910 if (FAILED(hr))
912 WARN("Failed to initialize surface, hr %#x.\n", hr);
913 HeapFree(GetProcessHeap(), 0, object);
914 return hr;
917 TRACE("Created surface %p.\n", object);
918 *surface = &object->IDirect3DSurface9_iface;
920 return D3D_OK;
923 static HRESULT WINAPI d3d9_device_CreateRenderTarget(IDirect3DDevice9Ex *iface, UINT width, UINT height,
924 D3DFORMAT format, D3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality,
925 BOOL lockable, IDirect3DSurface9 **surface, HANDLE *shared_handle)
927 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
928 HRESULT hr;
930 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u.\n"
931 "lockable %#x, surface %p, shared_handle %p.\n",
932 iface, width, height, format, multisample_type, multisample_quality,
933 lockable, surface, shared_handle);
935 if (shared_handle)
936 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle);
938 hr = d3d9_device_create_surface(device, width, height, format, lockable, FALSE, 0, surface,
939 D3DUSAGE_RENDERTARGET, D3DPOOL_DEFAULT, multisample_type, multisample_quality);
941 return hr;
944 static HRESULT WINAPI d3d9_device_CreateDepthStencilSurface(IDirect3DDevice9Ex *iface, UINT width, UINT height,
945 D3DFORMAT format, D3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality,
946 BOOL discard, IDirect3DSurface9 **surface, HANDLE *shared_handle)
948 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
949 HRESULT hr;
951 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u.\n"
952 "discard %#x, surface %p, shared_handle %p.\n",
953 iface, width, height, format, multisample_type, multisample_quality,
954 discard, surface, shared_handle);
956 if (shared_handle)
957 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle);
959 hr = d3d9_device_create_surface(device, width, height, format, TRUE, discard, 0, surface,
960 D3DUSAGE_DEPTHSTENCIL, D3DPOOL_DEFAULT, multisample_type, multisample_quality);
962 return hr;
966 static HRESULT WINAPI d3d9_device_UpdateSurface(IDirect3DDevice9Ex *iface,
967 IDirect3DSurface9 *src_surface, const RECT *src_rect,
968 IDirect3DSurface9 *dst_surface, const POINT *dst_point)
970 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
971 struct d3d9_surface *src = unsafe_impl_from_IDirect3DSurface9(src_surface);
972 struct d3d9_surface *dst = unsafe_impl_from_IDirect3DSurface9(dst_surface);
973 HRESULT hr;
975 TRACE("iface %p, src_surface %p, src_rect %p, dst_surface %p, dst_point %p.\n",
976 iface, src_surface, src_rect, dst_surface, dst_point);
978 wined3d_mutex_lock();
979 hr = wined3d_device_update_surface(device->wined3d_device, src->wined3d_surface, src_rect,
980 dst->wined3d_surface, dst_point);
981 wined3d_mutex_unlock();
983 return hr;
986 static HRESULT WINAPI d3d9_device_UpdateTexture(IDirect3DDevice9Ex *iface,
987 IDirect3DBaseTexture9 *src_texture, IDirect3DBaseTexture9 *dst_texture)
989 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
990 struct d3d9_texture *src_impl, *dst_impl;
991 HRESULT hr;
993 TRACE("iface %p, src_texture %p, dst_texture %p.\n", iface, src_texture, dst_texture);
995 src_impl = unsafe_impl_from_IDirect3DBaseTexture9(src_texture);
996 dst_impl = unsafe_impl_from_IDirect3DBaseTexture9(dst_texture);
998 wined3d_mutex_lock();
999 hr = wined3d_device_update_texture(device->wined3d_device,
1000 src_impl->wined3d_texture, dst_impl->wined3d_texture);
1001 wined3d_mutex_unlock();
1003 return hr;
1006 static HRESULT WINAPI d3d9_device_GetRenderTargetData(IDirect3DDevice9Ex *iface,
1007 IDirect3DSurface9 *render_target, IDirect3DSurface9 *dst_surface)
1009 struct d3d9_surface *rt_impl = unsafe_impl_from_IDirect3DSurface9(render_target);
1010 struct d3d9_surface *dst_impl = unsafe_impl_from_IDirect3DSurface9(dst_surface);
1011 HRESULT hr;
1013 TRACE("iface %p, render_target %p, dst_surface %p.\n", iface, render_target, dst_surface);
1015 wined3d_mutex_lock();
1016 hr = wined3d_surface_get_render_target_data(dst_impl->wined3d_surface, rt_impl->wined3d_surface);
1017 wined3d_mutex_unlock();
1019 return hr;
1022 static HRESULT WINAPI d3d9_device_GetFrontBufferData(IDirect3DDevice9Ex *iface,
1023 UINT swapchain, IDirect3DSurface9 *dst_surface)
1025 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
1026 struct d3d9_surface *dst_impl = unsafe_impl_from_IDirect3DSurface9(dst_surface);
1027 HRESULT hr;
1029 TRACE("iface %p, swapchain %u, dst_surface %p.\n", iface, swapchain, dst_surface);
1031 wined3d_mutex_lock();
1032 hr = wined3d_device_get_front_buffer_data(device->wined3d_device, swapchain, dst_impl->wined3d_surface);
1033 wined3d_mutex_unlock();
1035 return hr;
1038 static HRESULT WINAPI d3d9_device_StretchRect(IDirect3DDevice9Ex *iface, IDirect3DSurface9 *src_surface,
1039 const RECT *src_rect, IDirect3DSurface9 *dst_surface, const RECT *dst_rect, D3DTEXTUREFILTERTYPE filter)
1041 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
1042 struct d3d9_surface *src = unsafe_impl_from_IDirect3DSurface9(src_surface);
1043 struct d3d9_surface *dst = unsafe_impl_from_IDirect3DSurface9(dst_surface);
1044 HRESULT hr = D3DERR_INVALIDCALL;
1045 struct wined3d_resource_desc src_desc, dst_desc;
1046 struct wined3d_resource *wined3d_resource;
1048 TRACE("iface %p, src_surface %p, src_rect %p, dst_surface %p, dst_rect %p, filter %#x.\n",
1049 iface, src_surface, src_rect, dst_surface, dst_rect, filter);
1051 wined3d_mutex_lock();
1052 wined3d_resource = wined3d_surface_get_resource(dst->wined3d_surface);
1053 wined3d_resource_get_desc(wined3d_resource, &dst_desc);
1055 wined3d_resource = wined3d_surface_get_resource(src->wined3d_surface);
1056 wined3d_resource_get_desc(wined3d_resource, &src_desc);
1058 if (src_desc.usage & WINED3DUSAGE_DEPTHSTENCIL)
1060 if (device->in_scene)
1062 WARN("Rejecting depth / stencil blit while in scene.\n");
1063 goto done;
1066 if (src_rect)
1068 if (src_rect->left || src_rect->top || src_rect->right != src_desc.width
1069 || src_rect->bottom != src_desc.height)
1071 WARN("Rejecting depth / stencil blit with invalid source rect %s.\n",
1072 wine_dbgstr_rect(src_rect));
1073 goto done;
1076 if (dst_rect)
1078 if (dst_rect->left || dst_rect->top || dst_rect->right != dst_desc.width
1079 || dst_rect->bottom != dst_desc.height)
1081 WARN("Rejecting depth / stencil blit with invalid destination rect %s.\n",
1082 wine_dbgstr_rect(dst_rect));
1083 goto done;
1086 if (src_desc.width != dst_desc.width || src_desc.height != dst_desc.height)
1088 WARN("Rejecting depth / stencil blit with mismatched surface sizes.\n");
1089 goto done;
1093 hr = wined3d_surface_blt(dst->wined3d_surface, dst_rect, src->wined3d_surface, src_rect, 0, NULL, filter);
1094 if (hr == WINEDDERR_INVALIDRECT)
1095 hr = D3DERR_INVALIDCALL;
1097 done:
1098 wined3d_mutex_unlock();
1099 return hr;
1102 static HRESULT WINAPI d3d9_device_ColorFill(IDirect3DDevice9Ex *iface,
1103 IDirect3DSurface9 *surface, const RECT *rect, D3DCOLOR color)
1105 const struct wined3d_color c =
1107 ((color >> 16) & 0xff) / 255.0f,
1108 ((color >> 8) & 0xff) / 255.0f,
1109 (color & 0xff) / 255.0f,
1110 ((color >> 24) & 0xff) / 255.0f,
1112 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
1113 struct d3d9_surface *surface_impl = unsafe_impl_from_IDirect3DSurface9(surface);
1114 struct wined3d_resource *wined3d_resource;
1115 struct wined3d_resource_desc desc;
1116 HRESULT hr;
1118 TRACE("iface %p, surface %p, rect %p, color 0x%08x.\n", iface, surface, rect, color);
1120 wined3d_mutex_lock();
1122 wined3d_resource = wined3d_surface_get_resource(surface_impl->wined3d_surface);
1123 wined3d_resource_get_desc(wined3d_resource, &desc);
1125 /* This method is only allowed with surfaces that are render targets, or
1126 * offscreen plain surfaces in D3DPOOL_DEFAULT. */
1127 if (!(desc.usage & WINED3DUSAGE_RENDERTARGET) && desc.pool != WINED3D_POOL_DEFAULT)
1129 wined3d_mutex_unlock();
1130 WARN("Surface is not a render target, or not a stand-alone D3DPOOL_DEFAULT surface\n");
1131 return D3DERR_INVALIDCALL;
1134 /* Colorfill can only be used on rendertarget surfaces, or offscreen plain surfaces in D3DPOOL_DEFAULT */
1135 hr = wined3d_device_color_fill(device->wined3d_device, surface_impl->wined3d_surface, rect, &c);
1137 wined3d_mutex_unlock();
1139 return hr;
1142 static HRESULT WINAPI d3d9_device_CreateOffscreenPlainSurface(IDirect3DDevice9Ex *iface,
1143 UINT width, UINT height, D3DFORMAT format, D3DPOOL pool, IDirect3DSurface9 **surface,
1144 HANDLE *shared_handle)
1146 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
1148 TRACE("iface %p, width %u, height %u, format %#x, pool %#x, surface %p, shared_handle %p.\n",
1149 iface, width, height, format, pool, surface, shared_handle);
1151 if (shared_handle)
1152 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle);
1154 if (pool == D3DPOOL_MANAGED)
1156 WARN("Attempting to create a managed offscreen plain surface.\n");
1157 return D3DERR_INVALIDCALL;
1159 /* FIXME: Offscreen surfaces are supposed to be always lockable,
1160 * regardless of the pool they're created in. Should we set dynamic usage
1161 * here? */
1162 return d3d9_device_create_surface(device, width, height, format, TRUE,
1163 FALSE, 0, surface, 0, pool, D3DMULTISAMPLE_NONE, 0);
1166 static HRESULT WINAPI d3d9_device_SetRenderTarget(IDirect3DDevice9Ex *iface, DWORD idx, IDirect3DSurface9 *surface)
1168 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
1169 struct d3d9_surface *surface_impl = unsafe_impl_from_IDirect3DSurface9(surface);
1170 HRESULT hr;
1172 TRACE("iface %p, idx %u, surface %p.\n", iface, idx, surface);
1174 if (idx >= D3D9_MAX_SIMULTANEOUS_RENDERTARGETS)
1176 WARN("Invalid index %u specified.\n", idx);
1177 return D3DERR_INVALIDCALL;
1180 wined3d_mutex_lock();
1181 hr = wined3d_device_set_render_target(device->wined3d_device, idx,
1182 surface_impl ? surface_impl->wined3d_surface : NULL, TRUE);
1183 wined3d_mutex_unlock();
1185 return hr;
1188 static HRESULT WINAPI d3d9_device_GetRenderTarget(IDirect3DDevice9Ex *iface, DWORD idx, IDirect3DSurface9 **surface)
1190 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
1191 struct wined3d_surface *wined3d_surface;
1192 struct d3d9_surface *surface_impl;
1193 HRESULT hr;
1195 TRACE("iface %p, idx %u, surface %p.\n", iface, idx, surface);
1197 if (!surface)
1198 return D3DERR_INVALIDCALL;
1200 if (idx >= D3D9_MAX_SIMULTANEOUS_RENDERTARGETS)
1202 WARN("Invalid index %u specified.\n", idx);
1203 return D3DERR_INVALIDCALL;
1206 wined3d_mutex_lock();
1207 hr = wined3d_device_get_render_target(device->wined3d_device, idx, &wined3d_surface);
1208 if (SUCCEEDED(hr))
1210 surface_impl = wined3d_surface_get_parent(wined3d_surface);
1211 *surface = &surface_impl->IDirect3DSurface9_iface;
1212 IDirect3DSurface9_AddRef(*surface);
1213 wined3d_surface_decref(wined3d_surface);
1215 else
1217 if (hr != WINED3DERR_NOTFOUND)
1218 WARN("Failed to get render target %u, hr %#x.\n", idx, hr);
1219 *surface = NULL;
1221 wined3d_mutex_unlock();
1223 return hr;
1226 static HRESULT WINAPI d3d9_device_SetDepthStencilSurface(IDirect3DDevice9Ex *iface, IDirect3DSurface9 *depth_stencil)
1228 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
1229 struct d3d9_surface *ds_impl = unsafe_impl_from_IDirect3DSurface9(depth_stencil);
1230 HRESULT hr;
1232 TRACE("iface %p, depth_stencil %p.\n", iface, depth_stencil);
1234 wined3d_mutex_lock();
1235 hr = wined3d_device_set_depth_stencil(device->wined3d_device, ds_impl ? ds_impl->wined3d_surface : NULL);
1236 wined3d_mutex_unlock();
1238 return hr;
1241 static HRESULT WINAPI d3d9_device_GetDepthStencilSurface(IDirect3DDevice9Ex *iface, IDirect3DSurface9 **depth_stencil)
1243 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
1244 struct wined3d_surface *wined3d_surface;
1245 struct d3d9_surface *surface_impl;
1246 HRESULT hr;
1248 TRACE("iface %p, depth_stencil %p.\n", iface, depth_stencil);
1250 if (!depth_stencil)
1251 return D3DERR_INVALIDCALL;
1253 wined3d_mutex_lock();
1254 hr = wined3d_device_get_depth_stencil(device->wined3d_device, &wined3d_surface);
1255 if (SUCCEEDED(hr))
1257 surface_impl = wined3d_surface_get_parent(wined3d_surface);
1258 *depth_stencil = &surface_impl->IDirect3DSurface9_iface;
1259 IDirect3DSurface9_AddRef(*depth_stencil);
1260 wined3d_surface_decref(wined3d_surface);
1262 else
1264 if (hr != WINED3DERR_NOTFOUND)
1265 WARN("Call to IWineD3DDevice_GetDepthStencilSurface failed with 0x%08x\n", hr);
1266 *depth_stencil = NULL;
1268 wined3d_mutex_unlock();
1270 return hr;
1273 static HRESULT WINAPI d3d9_device_BeginScene(IDirect3DDevice9Ex *iface)
1275 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
1276 HRESULT hr;
1278 TRACE("iface %p.\n", iface);
1280 wined3d_mutex_lock();
1281 if (SUCCEEDED(hr = wined3d_device_begin_scene(device->wined3d_device)))
1282 device->in_scene = TRUE;
1283 wined3d_mutex_unlock();
1285 return hr;
1288 static HRESULT WINAPI DECLSPEC_HOTPATCH d3d9_device_EndScene(IDirect3DDevice9Ex *iface)
1290 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
1291 HRESULT hr;
1293 TRACE("iface %p.\n", iface);
1295 wined3d_mutex_lock();
1296 if (SUCCEEDED(hr = wined3d_device_end_scene(device->wined3d_device)))
1297 device->in_scene = FALSE;
1298 wined3d_mutex_unlock();
1300 return hr;
1303 static HRESULT WINAPI d3d9_device_Clear(IDirect3DDevice9Ex *iface, DWORD rect_count,
1304 const D3DRECT *rects, DWORD flags, D3DCOLOR color, float z, DWORD stencil)
1306 const struct wined3d_color c =
1308 ((color >> 16) & 0xff) / 255.0f,
1309 ((color >> 8) & 0xff) / 255.0f,
1310 (color & 0xff) / 255.0f,
1311 ((color >> 24) & 0xff) / 255.0f,
1313 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
1314 HRESULT hr;
1316 TRACE("iface %p, rect_count %u, rects %p, flags %#x, color 0x%08x, z %.8e, stencil %u.\n",
1317 iface, rect_count, rects, flags, color, z, stencil);
1319 wined3d_mutex_lock();
1320 hr = wined3d_device_clear(device->wined3d_device, rect_count, (const RECT *)rects, flags, &c, z, stencil);
1321 wined3d_mutex_unlock();
1323 return hr;
1326 static HRESULT WINAPI d3d9_device_SetTransform(IDirect3DDevice9Ex *iface,
1327 D3DTRANSFORMSTATETYPE state, const D3DMATRIX *matrix)
1329 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
1331 TRACE("iface %p, state %#x, matrix %p.\n", iface, state, matrix);
1333 /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
1334 wined3d_mutex_lock();
1335 wined3d_device_set_transform(device->wined3d_device, state, (const struct wined3d_matrix *)matrix);
1336 wined3d_mutex_unlock();
1338 return D3D_OK;
1341 static HRESULT WINAPI d3d9_device_GetTransform(IDirect3DDevice9Ex *iface,
1342 D3DTRANSFORMSTATETYPE state, D3DMATRIX *matrix)
1344 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
1346 TRACE("iface %p, state %#x, matrix %p.\n", iface, state, matrix);
1348 /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
1349 wined3d_mutex_lock();
1350 wined3d_device_get_transform(device->wined3d_device, state, (struct wined3d_matrix *)matrix);
1351 wined3d_mutex_unlock();
1353 return D3D_OK;
1356 static HRESULT WINAPI d3d9_device_MultiplyTransform(IDirect3DDevice9Ex *iface,
1357 D3DTRANSFORMSTATETYPE state, const D3DMATRIX *matrix)
1359 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
1361 TRACE("iface %p, state %#x, matrix %p.\n", iface, state, matrix);
1363 /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
1364 wined3d_mutex_lock();
1365 wined3d_device_multiply_transform(device->wined3d_device, state, (const struct wined3d_matrix *)matrix);
1366 wined3d_mutex_unlock();
1368 return D3D_OK;
1371 static HRESULT WINAPI d3d9_device_SetViewport(IDirect3DDevice9Ex *iface, const D3DVIEWPORT9 *viewport)
1373 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
1375 TRACE("iface %p, viewport %p.\n", iface, viewport);
1377 /* Note: D3DVIEWPORT9 is compatible with struct wined3d_viewport. */
1378 wined3d_mutex_lock();
1379 wined3d_device_set_viewport(device->wined3d_device, (const struct wined3d_viewport *)viewport);
1380 wined3d_mutex_unlock();
1382 return D3D_OK;
1385 static HRESULT WINAPI d3d9_device_GetViewport(IDirect3DDevice9Ex *iface, D3DVIEWPORT9 *viewport)
1387 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
1389 TRACE("iface %p, viewport %p.\n", iface, viewport);
1391 /* Note: D3DVIEWPORT9 is compatible with struct wined3d_viewport. */
1392 wined3d_mutex_lock();
1393 wined3d_device_get_viewport(device->wined3d_device, (struct wined3d_viewport *)viewport);
1394 wined3d_mutex_unlock();
1396 return D3D_OK;
1399 static HRESULT WINAPI d3d9_device_SetMaterial(IDirect3DDevice9Ex *iface, const D3DMATERIAL9 *material)
1401 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
1403 TRACE("iface %p, material %p.\n", iface, material);
1405 /* Note: D3DMATERIAL9 is compatible with struct wined3d_material. */
1406 wined3d_mutex_lock();
1407 wined3d_device_set_material(device->wined3d_device, (const struct wined3d_material *)material);
1408 wined3d_mutex_unlock();
1410 return D3D_OK;
1413 static HRESULT WINAPI d3d9_device_GetMaterial(IDirect3DDevice9Ex *iface, D3DMATERIAL9 *material)
1415 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
1417 TRACE("iface %p, material %p.\n", iface, material);
1419 /* Note: D3DMATERIAL9 is compatible with struct wined3d_material. */
1420 wined3d_mutex_lock();
1421 wined3d_device_get_material(device->wined3d_device, (struct wined3d_material *)material);
1422 wined3d_mutex_unlock();
1424 return D3D_OK;
1427 static HRESULT WINAPI d3d9_device_SetLight(IDirect3DDevice9Ex *iface, DWORD index, const D3DLIGHT9 *light)
1429 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
1430 HRESULT hr;
1432 TRACE("iface %p, index %u, light %p.\n", iface, index, light);
1434 /* Note: D3DLIGHT9 is compatible with struct wined3d_light. */
1435 wined3d_mutex_lock();
1436 hr = wined3d_device_set_light(device->wined3d_device, index, (const struct wined3d_light *)light);
1437 wined3d_mutex_unlock();
1439 return hr;
1442 static HRESULT WINAPI d3d9_device_GetLight(IDirect3DDevice9Ex *iface, DWORD index, D3DLIGHT9 *light)
1444 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
1445 HRESULT hr;
1447 TRACE("iface %p, index %u, light %p.\n", iface, index, light);
1449 /* Note: D3DLIGHT9 is compatible with struct wined3d_light. */
1450 wined3d_mutex_lock();
1451 hr = wined3d_device_get_light(device->wined3d_device, index, (struct wined3d_light *)light);
1452 wined3d_mutex_unlock();
1454 return hr;
1457 static HRESULT WINAPI d3d9_device_LightEnable(IDirect3DDevice9Ex *iface, DWORD index, BOOL enable)
1459 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
1460 HRESULT hr;
1462 TRACE("iface %p, index %u, enable %#x.\n", iface, index, enable);
1464 wined3d_mutex_lock();
1465 hr = wined3d_device_set_light_enable(device->wined3d_device, index, enable);
1466 wined3d_mutex_unlock();
1468 return hr;
1471 static HRESULT WINAPI d3d9_device_GetLightEnable(IDirect3DDevice9Ex *iface, DWORD index, BOOL *enable)
1473 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
1474 HRESULT hr;
1476 TRACE("iface %p, index %u, enable %p.\n", iface, index, enable);
1478 wined3d_mutex_lock();
1479 hr = wined3d_device_get_light_enable(device->wined3d_device, index, enable);
1480 wined3d_mutex_unlock();
1482 return hr;
1485 static HRESULT WINAPI d3d9_device_SetClipPlane(IDirect3DDevice9Ex *iface, DWORD index, const float *plane)
1487 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
1488 HRESULT hr;
1490 TRACE("iface %p, index %u, plane %p.\n", iface, index, plane);
1492 wined3d_mutex_lock();
1493 hr = wined3d_device_set_clip_plane(device->wined3d_device, index, (const struct wined3d_vec4 *)plane);
1494 wined3d_mutex_unlock();
1496 return hr;
1499 static HRESULT WINAPI d3d9_device_GetClipPlane(IDirect3DDevice9Ex *iface, DWORD index, float *plane)
1501 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
1502 HRESULT hr;
1504 TRACE("iface %p, index %u, plane %p.\n", iface, index, plane);
1506 wined3d_mutex_lock();
1507 hr = wined3d_device_get_clip_plane(device->wined3d_device, index, (struct wined3d_vec4 *)plane);
1508 wined3d_mutex_unlock();
1510 return hr;
1513 static HRESULT WINAPI DECLSPEC_HOTPATCH d3d9_device_SetRenderState(IDirect3DDevice9Ex *iface,
1514 D3DRENDERSTATETYPE state, DWORD value)
1516 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
1518 TRACE("iface %p, state %#x, value %#x.\n", iface, state, value);
1520 wined3d_mutex_lock();
1521 wined3d_device_set_render_state(device->wined3d_device, state, value);
1522 wined3d_mutex_unlock();
1524 return D3D_OK;
1527 static HRESULT WINAPI d3d9_device_GetRenderState(IDirect3DDevice9Ex *iface,
1528 D3DRENDERSTATETYPE state, DWORD *value)
1530 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
1532 TRACE("iface %p, state %#x, value %p.\n", iface, state, value);
1534 wined3d_mutex_lock();
1535 *value = wined3d_device_get_render_state(device->wined3d_device, state);
1536 wined3d_mutex_unlock();
1538 return D3D_OK;
1541 static HRESULT WINAPI d3d9_device_CreateStateBlock(IDirect3DDevice9Ex *iface,
1542 D3DSTATEBLOCKTYPE type, IDirect3DStateBlock9 **stateblock)
1544 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
1545 struct d3d9_stateblock *object;
1546 HRESULT hr;
1548 TRACE("iface %p, type %#x, stateblock %p.\n", iface, type, stateblock);
1550 if (type != D3DSBT_ALL && type != D3DSBT_PIXELSTATE && type != D3DSBT_VERTEXSTATE)
1552 WARN("Unexpected stateblock type, returning D3DERR_INVALIDCALL.\n");
1553 return D3DERR_INVALIDCALL;
1556 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1557 if (!object)
1559 ERR("Failed to allocate stateblock memory.\n");
1560 return E_OUTOFMEMORY;
1563 hr = stateblock_init(object, device, type, NULL);
1564 if (FAILED(hr))
1566 WARN("Failed to initialize stateblock, hr %#x.\n", hr);
1567 HeapFree(GetProcessHeap(), 0, object);
1568 return hr;
1571 TRACE("Created stateblock %p.\n", object);
1572 *stateblock = &object->IDirect3DStateBlock9_iface;
1574 return D3D_OK;
1577 static HRESULT WINAPI d3d9_device_BeginStateBlock(IDirect3DDevice9Ex *iface)
1579 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
1580 HRESULT hr;
1582 TRACE("iface %p.\n", iface);
1584 wined3d_mutex_lock();
1585 hr = wined3d_device_begin_stateblock(device->wined3d_device);
1586 wined3d_mutex_unlock();
1588 return hr;
1591 static HRESULT WINAPI d3d9_device_EndStateBlock(IDirect3DDevice9Ex *iface, IDirect3DStateBlock9 **stateblock)
1593 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
1594 struct wined3d_stateblock *wined3d_stateblock;
1595 struct d3d9_stateblock *object;
1596 HRESULT hr;
1598 TRACE("iface %p, stateblock %p.\n", iface, stateblock);
1600 wined3d_mutex_lock();
1601 hr = wined3d_device_end_stateblock(device->wined3d_device, &wined3d_stateblock);
1602 wined3d_mutex_unlock();
1603 if (FAILED(hr))
1605 WARN("IWineD3DDevice_EndStateBlock() failed, hr %#x.\n", hr);
1606 return hr;
1609 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1610 if (!object)
1612 ERR("Failed to allocate stateblock memory.\n");
1613 wined3d_mutex_lock();
1614 wined3d_stateblock_decref(wined3d_stateblock);
1615 wined3d_mutex_unlock();
1616 return E_OUTOFMEMORY;
1619 hr = stateblock_init(object, device, 0, wined3d_stateblock);
1620 if (FAILED(hr))
1622 WARN("Failed to initialize stateblock, hr %#x.\n", hr);
1623 wined3d_mutex_lock();
1624 wined3d_stateblock_decref(wined3d_stateblock);
1625 wined3d_mutex_unlock();
1626 HeapFree(GetProcessHeap(), 0, object);
1627 return hr;
1630 TRACE("Created stateblock %p.\n", object);
1631 *stateblock = &object->IDirect3DStateBlock9_iface;
1633 return D3D_OK;
1636 static HRESULT WINAPI d3d9_device_SetClipStatus(IDirect3DDevice9Ex *iface, const D3DCLIPSTATUS9 *clip_status)
1638 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
1639 HRESULT hr;
1641 TRACE("iface %p, clip_status %p.\n", iface, clip_status);
1643 wined3d_mutex_lock();
1644 hr = wined3d_device_set_clip_status(device->wined3d_device, (const struct wined3d_clip_status *)clip_status);
1645 wined3d_mutex_unlock();
1647 return hr;
1650 static HRESULT WINAPI d3d9_device_GetClipStatus(IDirect3DDevice9Ex *iface, D3DCLIPSTATUS9 *clip_status)
1652 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
1653 HRESULT hr;
1655 TRACE("iface %p, clip_status %p.\n", iface, clip_status);
1657 wined3d_mutex_lock();
1658 hr = wined3d_device_get_clip_status(device->wined3d_device, (struct wined3d_clip_status *)clip_status);
1659 wined3d_mutex_unlock();
1661 return hr;
1664 static HRESULT WINAPI d3d9_device_GetTexture(IDirect3DDevice9Ex *iface, DWORD stage, IDirect3DBaseTexture9 **texture)
1666 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
1667 struct wined3d_texture *wined3d_texture = NULL;
1668 struct d3d9_texture *texture_impl;
1670 TRACE("iface %p, stage %u, texture %p.\n", iface, stage, texture);
1672 if (!texture)
1673 return D3DERR_INVALIDCALL;
1675 wined3d_mutex_lock();
1676 if ((wined3d_texture = wined3d_device_get_texture(device->wined3d_device, stage)))
1678 texture_impl = wined3d_texture_get_parent(wined3d_texture);
1679 *texture = &texture_impl->IDirect3DBaseTexture9_iface;
1680 IDirect3DBaseTexture9_AddRef(*texture);
1682 else
1684 *texture = NULL;
1686 wined3d_mutex_unlock();
1688 return D3D_OK;
1691 static HRESULT WINAPI d3d9_device_SetTexture(IDirect3DDevice9Ex *iface, DWORD stage, IDirect3DBaseTexture9 *texture)
1693 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
1694 struct d3d9_texture *texture_impl;
1695 HRESULT hr;
1697 TRACE("iface %p, stage %u, texture %p.\n", iface, stage, texture);
1699 texture_impl = unsafe_impl_from_IDirect3DBaseTexture9(texture);
1701 wined3d_mutex_lock();
1702 hr = wined3d_device_set_texture(device->wined3d_device, stage,
1703 texture_impl ? texture_impl->wined3d_texture : NULL);
1704 wined3d_mutex_unlock();
1706 return hr;
1709 static const enum wined3d_texture_stage_state tss_lookup[] =
1711 WINED3D_TSS_INVALID, /* 0, unused */
1712 WINED3D_TSS_COLOR_OP, /* 1, D3DTSS_COLOROP */
1713 WINED3D_TSS_COLOR_ARG1, /* 2, D3DTSS_COLORARG1 */
1714 WINED3D_TSS_COLOR_ARG2, /* 3, D3DTSS_COLORARG2 */
1715 WINED3D_TSS_ALPHA_OP, /* 4, D3DTSS_ALPHAOP */
1716 WINED3D_TSS_ALPHA_ARG1, /* 5, D3DTSS_ALPHAARG1 */
1717 WINED3D_TSS_ALPHA_ARG2, /* 6, D3DTSS_ALPHAARG2 */
1718 WINED3D_TSS_BUMPENV_MAT00, /* 7, D3DTSS_BUMPENVMAT00 */
1719 WINED3D_TSS_BUMPENV_MAT01, /* 8, D3DTSS_BUMPENVMAT01 */
1720 WINED3D_TSS_BUMPENV_MAT10, /* 9, D3DTSS_BUMPENVMAT10 */
1721 WINED3D_TSS_BUMPENV_MAT11, /* 10, D3DTSS_BUMPENVMAT11 */
1722 WINED3D_TSS_TEXCOORD_INDEX, /* 11, D3DTSS_TEXCOORDINDEX */
1723 WINED3D_TSS_INVALID, /* 12, unused */
1724 WINED3D_TSS_INVALID, /* 13, unused */
1725 WINED3D_TSS_INVALID, /* 14, unused */
1726 WINED3D_TSS_INVALID, /* 15, unused */
1727 WINED3D_TSS_INVALID, /* 16, unused */
1728 WINED3D_TSS_INVALID, /* 17, unused */
1729 WINED3D_TSS_INVALID, /* 18, unused */
1730 WINED3D_TSS_INVALID, /* 19, unused */
1731 WINED3D_TSS_INVALID, /* 20, unused */
1732 WINED3D_TSS_INVALID, /* 21, unused */
1733 WINED3D_TSS_BUMPENV_LSCALE, /* 22, D3DTSS_BUMPENVLSCALE */
1734 WINED3D_TSS_BUMPENV_LOFFSET, /* 23, D3DTSS_BUMPENVLOFFSET */
1735 WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
1736 WINED3D_TSS_INVALID, /* 25, unused */
1737 WINED3D_TSS_COLOR_ARG0, /* 26, D3DTSS_COLORARG0 */
1738 WINED3D_TSS_ALPHA_ARG0, /* 27, D3DTSS_ALPHAARG0 */
1739 WINED3D_TSS_RESULT_ARG, /* 28, D3DTSS_RESULTARG */
1740 WINED3D_TSS_INVALID, /* 29, unused */
1741 WINED3D_TSS_INVALID, /* 30, unused */
1742 WINED3D_TSS_INVALID, /* 31, unused */
1743 WINED3D_TSS_CONSTANT, /* 32, D3DTSS_CONSTANT */
1746 static HRESULT WINAPI d3d9_device_GetTextureStageState(IDirect3DDevice9Ex *iface,
1747 DWORD stage, D3DTEXTURESTAGESTATETYPE state, DWORD *value)
1749 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
1751 TRACE("iface %p, stage %u, state %#x, value %p.\n", iface, stage, state, value);
1753 if (state >= sizeof(tss_lookup) / sizeof(*tss_lookup))
1755 WARN("Invalid state %#x passed.\n", state);
1756 return D3D_OK;
1759 wined3d_mutex_lock();
1760 *value = wined3d_device_get_texture_stage_state(device->wined3d_device, stage, tss_lookup[state]);
1761 wined3d_mutex_unlock();
1763 return D3D_OK;
1766 static HRESULT WINAPI d3d9_device_SetTextureStageState(IDirect3DDevice9Ex *iface,
1767 DWORD stage, D3DTEXTURESTAGESTATETYPE state, DWORD value)
1769 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
1771 TRACE("iface %p, stage %u, state %#x, value %#x.\n", iface, stage, state, value);
1773 if (state >= sizeof(tss_lookup) / sizeof(*tss_lookup))
1775 WARN("Invalid state %#x passed.\n", state);
1776 return D3D_OK;
1779 wined3d_mutex_lock();
1780 wined3d_device_set_texture_stage_state(device->wined3d_device, stage, tss_lookup[state], value);
1781 wined3d_mutex_unlock();
1783 return D3D_OK;
1786 static HRESULT WINAPI d3d9_device_GetSamplerState(IDirect3DDevice9Ex *iface,
1787 DWORD sampler, D3DSAMPLERSTATETYPE state, DWORD *value)
1789 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
1791 TRACE("iface %p, sampler %u, state %#x, value %p.\n", iface, sampler, state, value);
1793 wined3d_mutex_lock();
1794 *value = wined3d_device_get_sampler_state(device->wined3d_device, sampler, state);
1795 wined3d_mutex_unlock();
1797 return D3D_OK;
1800 static HRESULT WINAPI DECLSPEC_HOTPATCH d3d9_device_SetSamplerState(IDirect3DDevice9Ex *iface,
1801 DWORD sampler, D3DSAMPLERSTATETYPE state, DWORD value)
1803 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
1805 TRACE("iface %p, sampler %u, state %#x, value %#x.\n", iface, sampler, state, value);
1807 wined3d_mutex_lock();
1808 wined3d_device_set_sampler_state(device->wined3d_device, sampler, state, value);
1809 wined3d_mutex_unlock();
1811 return D3D_OK;
1814 static HRESULT WINAPI d3d9_device_ValidateDevice(IDirect3DDevice9Ex *iface, DWORD *pass_count)
1816 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
1817 HRESULT hr;
1819 TRACE("iface %p, pass_count %p.\n", iface, pass_count);
1821 wined3d_mutex_lock();
1822 hr = wined3d_device_validate_device(device->wined3d_device, pass_count);
1823 wined3d_mutex_unlock();
1825 return hr;
1828 static HRESULT WINAPI d3d9_device_SetPaletteEntries(IDirect3DDevice9Ex *iface,
1829 UINT palette_idx, const PALETTEENTRY *entries)
1831 FIXME("iface %p, palette_idx %u, entries %p unimplemented.\n", iface, palette_idx, entries);
1833 return D3DERR_INVALIDCALL;
1836 static HRESULT WINAPI d3d9_device_GetPaletteEntries(IDirect3DDevice9Ex *iface,
1837 UINT palette_idx, PALETTEENTRY *entries)
1839 FIXME("iface %p, palette_idx %u, entries %p unimplemented.\n", iface, palette_idx, entries);
1841 return D3DERR_INVALIDCALL;
1844 static HRESULT WINAPI d3d9_device_SetCurrentTexturePalette(IDirect3DDevice9Ex *iface, UINT palette_idx)
1846 FIXME("iface %p, palette_idx %u unimplemented.\n", iface, palette_idx);
1848 return D3DERR_INVALIDCALL;
1851 static HRESULT WINAPI d3d9_device_GetCurrentTexturePalette(IDirect3DDevice9Ex *iface, UINT *palette_idx)
1853 FIXME("iface %p, palette_idx %p.\n", iface, palette_idx);
1855 return D3DERR_INVALIDCALL;
1858 static HRESULT WINAPI d3d9_device_SetScissorRect(IDirect3DDevice9Ex *iface, const RECT *rect)
1860 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
1862 TRACE("iface %p, rect %p.\n", iface, rect);
1864 wined3d_mutex_lock();
1865 wined3d_device_set_scissor_rect(device->wined3d_device, rect);
1866 wined3d_mutex_unlock();
1868 return D3D_OK;
1871 static HRESULT WINAPI d3d9_device_GetScissorRect(IDirect3DDevice9Ex *iface, RECT *rect)
1873 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
1875 TRACE("iface %p, rect %p.\n", iface, rect);
1877 wined3d_mutex_lock();
1878 wined3d_device_get_scissor_rect(device->wined3d_device, rect);
1879 wined3d_mutex_unlock();
1881 return D3D_OK;
1884 static HRESULT WINAPI d3d9_device_SetSoftwareVertexProcessing(IDirect3DDevice9Ex *iface, BOOL software)
1886 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
1888 TRACE("iface %p, software %#x.\n", iface, software);
1890 wined3d_mutex_lock();
1891 wined3d_device_set_software_vertex_processing(device->wined3d_device, software);
1892 wined3d_mutex_unlock();
1894 return D3D_OK;
1897 static BOOL WINAPI d3d9_device_GetSoftwareVertexProcessing(IDirect3DDevice9Ex *iface)
1899 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
1900 BOOL ret;
1902 TRACE("iface %p.\n", iface);
1904 wined3d_mutex_lock();
1905 ret = wined3d_device_get_software_vertex_processing(device->wined3d_device);
1906 wined3d_mutex_unlock();
1908 return ret;
1911 static HRESULT WINAPI d3d9_device_SetNPatchMode(IDirect3DDevice9Ex *iface, float segment_count)
1913 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
1914 HRESULT hr;
1916 TRACE("iface %p, segment_count %.8e.\n", iface, segment_count);
1918 wined3d_mutex_lock();
1919 hr = wined3d_device_set_npatch_mode(device->wined3d_device, segment_count);
1920 wined3d_mutex_unlock();
1922 return hr;
1925 static float WINAPI d3d9_device_GetNPatchMode(IDirect3DDevice9Ex *iface)
1927 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
1928 float ret;
1930 TRACE("iface %p.\n", iface);
1932 wined3d_mutex_lock();
1933 ret = wined3d_device_get_npatch_mode(device->wined3d_device);
1934 wined3d_mutex_unlock();
1936 return ret;
1939 static HRESULT WINAPI d3d9_device_DrawPrimitive(IDirect3DDevice9Ex *iface,
1940 D3DPRIMITIVETYPE primitive_type, UINT start_vertex, UINT primitive_count)
1942 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
1943 HRESULT hr;
1945 TRACE("iface %p, primitive_type %#x, start_vertex %u, primitive_count %u.\n",
1946 iface, primitive_type, start_vertex, primitive_count);
1948 wined3d_mutex_lock();
1949 wined3d_device_set_primitive_type(device->wined3d_device, primitive_type);
1950 hr = wined3d_device_draw_primitive(device->wined3d_device, start_vertex,
1951 vertex_count_from_primitive_count(primitive_type, primitive_count));
1952 wined3d_mutex_unlock();
1954 return hr;
1957 static HRESULT WINAPI d3d9_device_DrawIndexedPrimitive(IDirect3DDevice9Ex *iface,
1958 D3DPRIMITIVETYPE primitive_type, INT base_vertex_idx, UINT min_vertex_idx,
1959 UINT vertex_count, UINT start_idx, UINT primitive_count)
1961 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
1962 HRESULT hr;
1964 TRACE("iface %p, primitive_type %#x, base_vertex_idx %u, min_vertex_idx %u,\n"
1965 "vertex_count %u, start_idx %u, primitive_count %u.\n",
1966 iface, primitive_type, base_vertex_idx, min_vertex_idx,
1967 vertex_count, start_idx, primitive_count);
1969 wined3d_mutex_lock();
1970 wined3d_device_set_base_vertex_index(device->wined3d_device, base_vertex_idx);
1971 wined3d_device_set_primitive_type(device->wined3d_device, primitive_type);
1972 hr = wined3d_device_draw_indexed_primitive(device->wined3d_device, start_idx,
1973 vertex_count_from_primitive_count(primitive_type, primitive_count));
1974 wined3d_mutex_unlock();
1976 return hr;
1979 static HRESULT WINAPI d3d9_device_DrawPrimitiveUP(IDirect3DDevice9Ex *iface,
1980 D3DPRIMITIVETYPE primitive_type, UINT primitive_count, const void *data, UINT stride)
1982 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
1983 HRESULT hr;
1985 TRACE("iface %p, primitive_type %#x, primitive_count %u, data %p, stride %u.\n",
1986 iface, primitive_type, primitive_count, data, stride);
1988 wined3d_mutex_lock();
1989 wined3d_device_set_primitive_type(device->wined3d_device, primitive_type);
1990 hr = wined3d_device_draw_primitive_up(device->wined3d_device,
1991 vertex_count_from_primitive_count(primitive_type, primitive_count),
1992 data, stride);
1993 wined3d_mutex_unlock();
1995 return hr;
1998 static HRESULT WINAPI d3d9_device_DrawIndexedPrimitiveUP(IDirect3DDevice9Ex *iface,
1999 D3DPRIMITIVETYPE primitive_type, UINT min_vertex_idx, UINT index_count,
2000 UINT primitive_count, const void *index_data, D3DFORMAT index_format,
2001 const void *vertex_data, UINT vertex_stride)
2003 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
2004 HRESULT hr;
2006 TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, index_count %u, primitive_count %u,\n"
2007 "index_data %p, index_format %#x, vertex_data %p, vertex_stride %u.\n",
2008 iface, primitive_type, min_vertex_idx, index_count, primitive_count,
2009 index_data, index_format, vertex_data, vertex_stride);
2011 wined3d_mutex_lock();
2012 wined3d_device_set_primitive_type(device->wined3d_device, primitive_type);
2013 hr = wined3d_device_draw_indexed_primitive_up(device->wined3d_device,
2014 vertex_count_from_primitive_count(primitive_type, primitive_count), index_data,
2015 wined3dformat_from_d3dformat(index_format), vertex_data, vertex_stride);
2016 wined3d_mutex_unlock();
2018 return hr;
2021 static HRESULT WINAPI d3d9_device_ProcessVertices(IDirect3DDevice9Ex *iface,
2022 UINT src_start_idx, UINT dst_idx, UINT vertex_count, IDirect3DVertexBuffer9 *dst_buffer,
2023 IDirect3DVertexDeclaration9 *declaration, DWORD flags)
2025 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
2026 struct d3d9_vertexbuffer *dst_impl = unsafe_impl_from_IDirect3DVertexBuffer9(dst_buffer);
2027 struct d3d9_vertex_declaration *decl_impl = unsafe_impl_from_IDirect3DVertexDeclaration9(declaration);
2028 HRESULT hr;
2030 TRACE("iface %p, src_start_idx %u, dst_idx %u, vertex_count %u, dst_buffer %p, declaration %p, flags %#x.\n",
2031 iface, src_start_idx, dst_idx, vertex_count, dst_buffer, declaration, flags);
2033 wined3d_mutex_lock();
2034 hr = wined3d_device_process_vertices(device->wined3d_device, src_start_idx, dst_idx, vertex_count,
2035 dst_impl->wined3d_buffer, decl_impl ? decl_impl->wined3d_declaration : NULL,
2036 flags, dst_impl->fvf);
2037 wined3d_mutex_unlock();
2039 return hr;
2042 static HRESULT WINAPI d3d9_device_CreateVertexDeclaration(IDirect3DDevice9Ex *iface,
2043 const D3DVERTEXELEMENT9 *elements, IDirect3DVertexDeclaration9 **declaration)
2045 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
2046 struct d3d9_vertex_declaration *object;
2047 HRESULT hr;
2049 TRACE("iface %p, elements %p, declaration %p.\n", iface, elements, declaration);
2051 if (!declaration)
2053 WARN("Caller passed a NULL declaration, returning D3DERR_INVALIDCALL.\n");
2054 return D3DERR_INVALIDCALL;
2057 if (SUCCEEDED(hr = d3d9_vertex_declaration_create(device, elements, &object)))
2058 *declaration = &object->IDirect3DVertexDeclaration9_iface;
2060 return hr;
2063 static HRESULT WINAPI d3d9_device_SetVertexDeclaration(IDirect3DDevice9Ex *iface,
2064 IDirect3DVertexDeclaration9 *declaration)
2066 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
2067 struct d3d9_vertex_declaration *decl_impl = unsafe_impl_from_IDirect3DVertexDeclaration9(declaration);
2069 TRACE("iface %p, declaration %p.\n", iface, declaration);
2071 wined3d_mutex_lock();
2072 wined3d_device_set_vertex_declaration(device->wined3d_device,
2073 decl_impl ? decl_impl->wined3d_declaration : NULL);
2074 wined3d_mutex_unlock();
2076 return D3D_OK;
2079 static HRESULT WINAPI d3d9_device_GetVertexDeclaration(IDirect3DDevice9Ex *iface,
2080 IDirect3DVertexDeclaration9 **declaration)
2082 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
2083 struct wined3d_vertex_declaration *wined3d_declaration;
2084 struct d3d9_vertex_declaration *declaration_impl;
2086 TRACE("iface %p, declaration %p.\n", iface, declaration);
2088 if (!declaration) return D3DERR_INVALIDCALL;
2090 wined3d_mutex_lock();
2091 if ((wined3d_declaration = wined3d_device_get_vertex_declaration(device->wined3d_device)))
2093 declaration_impl = wined3d_vertex_declaration_get_parent(wined3d_declaration);
2094 *declaration = &declaration_impl->IDirect3DVertexDeclaration9_iface;
2095 IDirect3DVertexDeclaration9_AddRef(*declaration);
2097 else
2099 *declaration = NULL;
2101 wined3d_mutex_unlock();
2103 TRACE("Returning %p.\n", *declaration);
2104 return D3D_OK;
2107 static struct wined3d_vertex_declaration *device_get_fvf_declaration(struct d3d9_device *device, DWORD fvf)
2109 struct wined3d_vertex_declaration *wined3d_declaration;
2110 struct fvf_declaration *fvf_decls = device->fvf_decls;
2111 struct d3d9_vertex_declaration *d3d9_declaration;
2112 D3DVERTEXELEMENT9 *elements;
2113 int p, low, high; /* deliberately signed */
2114 HRESULT hr;
2116 TRACE("Searching for declaration for fvf %08x... ", fvf);
2118 low = 0;
2119 high = device->fvf_decl_count - 1;
2120 while (low <= high)
2122 p = (low + high) >> 1;
2123 TRACE("%d ", p);
2125 if (fvf_decls[p].fvf == fvf)
2127 TRACE("found %p.\n", fvf_decls[p].decl);
2128 return fvf_decls[p].decl;
2131 if (fvf_decls[p].fvf < fvf)
2132 low = p + 1;
2133 else
2134 high = p - 1;
2136 TRACE("not found. Creating and inserting at position %d.\n", low);
2138 if (FAILED(hr = vdecl_convert_fvf(fvf, &elements)))
2139 return NULL;
2141 hr = d3d9_vertex_declaration_create(device, elements, &d3d9_declaration);
2142 HeapFree(GetProcessHeap(), 0, elements);
2143 if (FAILED(hr))
2144 return NULL;
2146 if (device->fvf_decl_size == device->fvf_decl_count)
2148 UINT grow = max(device->fvf_decl_size / 2, 8);
2150 fvf_decls = HeapReAlloc(GetProcessHeap(), 0, fvf_decls, sizeof(*fvf_decls) * (device->fvf_decl_size + grow));
2151 if (!fvf_decls)
2153 IDirect3DVertexDeclaration9_Release(&d3d9_declaration->IDirect3DVertexDeclaration9_iface);
2154 return NULL;
2156 device->fvf_decls = fvf_decls;
2157 device->fvf_decl_size += grow;
2160 d3d9_declaration->fvf = fvf;
2161 wined3d_declaration = d3d9_declaration->wined3d_declaration;
2162 wined3d_vertex_declaration_incref(wined3d_declaration);
2163 IDirect3DVertexDeclaration9_Release(&d3d9_declaration->IDirect3DVertexDeclaration9_iface);
2165 memmove(fvf_decls + low + 1, fvf_decls + low, sizeof(*fvf_decls) * (device->fvf_decl_count - low));
2166 fvf_decls[low].decl = wined3d_declaration;
2167 fvf_decls[low].fvf = fvf;
2168 ++device->fvf_decl_count;
2170 TRACE("Returning %p. %u declatations in array.\n", wined3d_declaration, device->fvf_decl_count);
2172 return wined3d_declaration;
2175 static HRESULT WINAPI d3d9_device_SetFVF(IDirect3DDevice9Ex *iface, DWORD fvf)
2177 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
2178 struct wined3d_vertex_declaration *decl;
2180 TRACE("iface %p, fvf %#x.\n", iface, fvf);
2182 if (!fvf)
2184 WARN("%#x is not a valid FVF.\n", fvf);
2185 return D3D_OK;
2188 wined3d_mutex_lock();
2189 if (!(decl = device_get_fvf_declaration(device, fvf)))
2191 wined3d_mutex_unlock();
2192 ERR("Failed to create a vertex declaration for fvf %#x.\n", fvf);
2193 return D3DERR_DRIVERINTERNALERROR;
2196 wined3d_device_set_vertex_declaration(device->wined3d_device, decl);
2197 wined3d_mutex_unlock();
2199 return D3D_OK;
2202 static HRESULT WINAPI d3d9_device_GetFVF(IDirect3DDevice9Ex *iface, DWORD *fvf)
2204 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
2205 struct wined3d_vertex_declaration *wined3d_declaration;
2206 struct d3d9_vertex_declaration *d3d9_declaration;
2208 TRACE("iface %p, fvf %p.\n", iface, fvf);
2210 wined3d_mutex_lock();
2211 if ((wined3d_declaration = wined3d_device_get_vertex_declaration(device->wined3d_device)))
2213 d3d9_declaration = wined3d_vertex_declaration_get_parent(wined3d_declaration);
2214 *fvf = d3d9_declaration->fvf;
2216 else
2218 *fvf = 0;
2220 wined3d_mutex_unlock();
2222 TRACE("Returning FVF %#x.\n", *fvf);
2224 return D3D_OK;
2227 static HRESULT WINAPI d3d9_device_CreateVertexShader(IDirect3DDevice9Ex *iface,
2228 const DWORD *byte_code, IDirect3DVertexShader9 **shader)
2230 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
2231 struct d3d9_vertexshader *object;
2232 HRESULT hr;
2234 TRACE("iface %p, byte_code %p, shader %p.\n", iface, byte_code, shader);
2236 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2237 if (!object)
2239 ERR("Failed to allocate vertex shader memory.\n");
2240 return E_OUTOFMEMORY;
2243 hr = vertexshader_init(object, device, byte_code);
2244 if (FAILED(hr))
2246 WARN("Failed to initialize vertex shader, hr %#x.\n", hr);
2247 HeapFree(GetProcessHeap(), 0, object);
2248 return hr;
2251 TRACE("Created vertex shader %p.\n", object);
2252 *shader = &object->IDirect3DVertexShader9_iface;
2254 return D3D_OK;
2257 static HRESULT WINAPI d3d9_device_SetVertexShader(IDirect3DDevice9Ex *iface, IDirect3DVertexShader9 *shader)
2259 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
2260 struct d3d9_vertexshader *shader_obj = unsafe_impl_from_IDirect3DVertexShader9(shader);
2262 TRACE("iface %p, shader %p.\n", iface, shader);
2264 wined3d_mutex_lock();
2265 wined3d_device_set_vertex_shader(device->wined3d_device,
2266 shader_obj ? shader_obj->wined3d_shader : NULL);
2267 wined3d_mutex_unlock();
2269 return D3D_OK;
2272 static HRESULT WINAPI d3d9_device_GetVertexShader(IDirect3DDevice9Ex *iface, IDirect3DVertexShader9 **shader)
2274 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
2275 struct d3d9_vertexshader *shader_impl;
2276 struct wined3d_shader *wined3d_shader;
2278 TRACE("iface %p, shader %p.\n", iface, shader);
2280 wined3d_mutex_lock();
2281 if ((wined3d_shader = wined3d_device_get_vertex_shader(device->wined3d_device)))
2283 shader_impl = wined3d_shader_get_parent(wined3d_shader);
2284 *shader = &shader_impl->IDirect3DVertexShader9_iface;
2285 IDirect3DVertexShader9_AddRef(*shader);
2287 else
2289 *shader = NULL;
2291 wined3d_mutex_unlock();
2293 TRACE("Returning %p.\n", *shader);
2295 return D3D_OK;
2298 static HRESULT WINAPI d3d9_device_SetVertexShaderConstantF(IDirect3DDevice9Ex *iface,
2299 UINT reg_idx, const float *data, UINT count)
2301 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
2302 HRESULT hr;
2304 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
2306 if (reg_idx + count > D3D9_MAX_VERTEX_SHADER_CONSTANTF)
2308 WARN("Trying to access %u constants, but d3d9 only supports %u\n",
2309 reg_idx + count, D3D9_MAX_VERTEX_SHADER_CONSTANTF);
2310 return D3DERR_INVALIDCALL;
2313 wined3d_mutex_lock();
2314 hr = wined3d_device_set_vs_consts_f(device->wined3d_device, reg_idx, data, count);
2315 wined3d_mutex_unlock();
2317 return hr;
2320 static HRESULT WINAPI d3d9_device_GetVertexShaderConstantF(IDirect3DDevice9Ex *iface,
2321 UINT reg_idx, float *data, UINT count)
2323 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
2324 HRESULT hr;
2326 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
2328 if (reg_idx + count > D3D9_MAX_VERTEX_SHADER_CONSTANTF)
2330 WARN("Trying to access %u constants, but d3d9 only supports %u\n",
2331 reg_idx + count, D3D9_MAX_VERTEX_SHADER_CONSTANTF);
2332 return D3DERR_INVALIDCALL;
2335 wined3d_mutex_lock();
2336 hr = wined3d_device_get_vs_consts_f(device->wined3d_device, reg_idx, data, count);
2337 wined3d_mutex_unlock();
2339 return hr;
2342 static HRESULT WINAPI d3d9_device_SetVertexShaderConstantI(IDirect3DDevice9Ex *iface,
2343 UINT reg_idx, const int *data, UINT count)
2345 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
2346 HRESULT hr;
2348 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
2350 wined3d_mutex_lock();
2351 hr = wined3d_device_set_vs_consts_i(device->wined3d_device, reg_idx, data, count);
2352 wined3d_mutex_unlock();
2354 return hr;
2357 static HRESULT WINAPI d3d9_device_GetVertexShaderConstantI(IDirect3DDevice9Ex *iface,
2358 UINT reg_idx, int *data, UINT count)
2360 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
2361 HRESULT hr;
2363 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
2365 wined3d_mutex_lock();
2366 hr = wined3d_device_get_vs_consts_i(device->wined3d_device, reg_idx, data, count);
2367 wined3d_mutex_unlock();
2369 return hr;
2372 static HRESULT WINAPI d3d9_device_SetVertexShaderConstantB(IDirect3DDevice9Ex *iface,
2373 UINT reg_idx, const BOOL *data, UINT count)
2375 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
2376 HRESULT hr;
2378 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
2380 wined3d_mutex_lock();
2381 hr = wined3d_device_set_vs_consts_b(device->wined3d_device, reg_idx, data, count);
2382 wined3d_mutex_unlock();
2384 return hr;
2387 static HRESULT WINAPI d3d9_device_GetVertexShaderConstantB(IDirect3DDevice9Ex *iface,
2388 UINT reg_idx, BOOL *data, UINT count)
2390 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
2391 HRESULT hr;
2393 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
2395 wined3d_mutex_lock();
2396 hr = wined3d_device_get_vs_consts_b(device->wined3d_device, reg_idx, data, count);
2397 wined3d_mutex_unlock();
2399 return hr;
2402 static HRESULT WINAPI d3d9_device_SetStreamSource(IDirect3DDevice9Ex *iface,
2403 UINT stream_idx, IDirect3DVertexBuffer9 *buffer, UINT offset, UINT stride)
2405 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
2406 struct d3d9_vertexbuffer *buffer_impl = unsafe_impl_from_IDirect3DVertexBuffer9(buffer);
2407 HRESULT hr;
2409 TRACE("iface %p, stream_idx %u, buffer %p, offset %u, stride %u.\n",
2410 iface, stream_idx, buffer, offset, stride);
2412 wined3d_mutex_lock();
2413 hr = wined3d_device_set_stream_source(device->wined3d_device, stream_idx,
2414 buffer_impl ? buffer_impl->wined3d_buffer : NULL, offset, stride);
2415 wined3d_mutex_unlock();
2417 return hr;
2420 static HRESULT WINAPI d3d9_device_GetStreamSource(IDirect3DDevice9Ex *iface,
2421 UINT stream_idx, IDirect3DVertexBuffer9 **buffer, UINT *offset, UINT *stride)
2423 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
2424 struct d3d9_vertexbuffer *buffer_impl;
2425 struct wined3d_buffer *wined3d_buffer;
2426 HRESULT hr;
2428 TRACE("iface %p, stream_idx %u, buffer %p, offset %p, stride %p.\n",
2429 iface, stream_idx, buffer, offset, stride);
2431 if (!buffer)
2432 return D3DERR_INVALIDCALL;
2434 wined3d_mutex_lock();
2435 hr = wined3d_device_get_stream_source(device->wined3d_device, stream_idx, &wined3d_buffer, offset, stride);
2436 if (SUCCEEDED(hr) && wined3d_buffer)
2438 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
2439 *buffer = &buffer_impl->IDirect3DVertexBuffer9_iface;
2440 IDirect3DVertexBuffer9_AddRef(*buffer);
2441 wined3d_buffer_decref(wined3d_buffer);
2443 else
2445 if (FAILED(hr))
2446 FIXME("Call to GetStreamSource failed %p %p\n", offset, stride);
2447 *buffer = NULL;
2449 wined3d_mutex_unlock();
2451 return hr;
2454 static HRESULT WINAPI d3d9_device_SetStreamSourceFreq(IDirect3DDevice9Ex *iface, UINT stream_idx, UINT freq)
2456 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
2457 HRESULT hr;
2459 TRACE("iface %p, stream_idx %u, freq %u.\n", iface, stream_idx, freq);
2461 wined3d_mutex_lock();
2462 hr = wined3d_device_set_stream_source_freq(device->wined3d_device, stream_idx, freq);
2463 wined3d_mutex_unlock();
2465 return hr;
2468 static HRESULT WINAPI d3d9_device_GetStreamSourceFreq(IDirect3DDevice9Ex *iface, UINT stream_idx, UINT *freq)
2470 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
2471 HRESULT hr;
2473 TRACE("iface %p, stream_idx %u, freq %p.\n", iface, stream_idx, freq);
2475 wined3d_mutex_lock();
2476 hr = wined3d_device_get_stream_source_freq(device->wined3d_device, stream_idx, freq);
2477 wined3d_mutex_unlock();
2479 return hr;
2482 static HRESULT WINAPI d3d9_device_SetIndices(IDirect3DDevice9Ex *iface, IDirect3DIndexBuffer9 *buffer)
2484 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
2485 struct d3d9_indexbuffer *ib = unsafe_impl_from_IDirect3DIndexBuffer9(buffer);
2487 TRACE("iface %p, buffer %p.\n", iface, buffer);
2489 wined3d_mutex_lock();
2490 wined3d_device_set_index_buffer(device->wined3d_device,
2491 ib ? ib->wined3d_buffer : NULL,
2492 ib ? ib->format : WINED3DFMT_UNKNOWN);
2493 wined3d_mutex_unlock();
2495 return D3D_OK;
2498 static HRESULT WINAPI d3d9_device_GetIndices(IDirect3DDevice9Ex *iface, IDirect3DIndexBuffer9 **buffer)
2500 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
2501 struct wined3d_buffer *wined3d_buffer;
2502 struct d3d9_indexbuffer *buffer_impl;
2504 TRACE("iface %p, buffer %p.\n", iface, buffer);
2506 if (!buffer)
2507 return D3DERR_INVALIDCALL;
2509 wined3d_mutex_lock();
2510 if ((wined3d_buffer = wined3d_device_get_index_buffer(device->wined3d_device)))
2512 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
2513 *buffer = &buffer_impl->IDirect3DIndexBuffer9_iface;
2514 IDirect3DIndexBuffer9_AddRef(*buffer);
2516 else
2518 *buffer = NULL;
2520 wined3d_mutex_unlock();
2522 return D3D_OK;
2525 static HRESULT WINAPI d3d9_device_CreatePixelShader(IDirect3DDevice9Ex *iface,
2526 const DWORD *byte_code, IDirect3DPixelShader9 **shader)
2528 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
2529 struct d3d9_pixelshader *object;
2530 HRESULT hr;
2532 TRACE("iface %p, byte_code %p, shader %p.\n", iface, byte_code, shader);
2534 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2535 if (!object)
2537 FIXME("Failed to allocate pixel shader memory.\n");
2538 return E_OUTOFMEMORY;
2541 hr = pixelshader_init(object, device, byte_code);
2542 if (FAILED(hr))
2544 WARN("Failed to initialize pixel shader, hr %#x.\n", hr);
2545 HeapFree(GetProcessHeap(), 0, object);
2546 return hr;
2549 TRACE("Created pixel shader %p.\n", object);
2550 *shader = &object->IDirect3DPixelShader9_iface;
2552 return D3D_OK;
2555 static HRESULT WINAPI d3d9_device_SetPixelShader(IDirect3DDevice9Ex *iface, IDirect3DPixelShader9 *shader)
2557 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
2558 struct d3d9_pixelshader *shader_obj = unsafe_impl_from_IDirect3DPixelShader9(shader);
2560 TRACE("iface %p, shader %p.\n", iface, shader);
2562 wined3d_mutex_lock();
2563 wined3d_device_set_pixel_shader(device->wined3d_device,
2564 shader_obj ? shader_obj->wined3d_shader : NULL);
2565 wined3d_mutex_unlock();
2567 return D3D_OK;
2570 static HRESULT WINAPI d3d9_device_GetPixelShader(IDirect3DDevice9Ex *iface, IDirect3DPixelShader9 **shader)
2572 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
2573 struct d3d9_pixelshader *shader_impl;
2574 struct wined3d_shader *wined3d_shader;
2576 TRACE("iface %p, shader %p.\n", iface, shader);
2578 if (!shader) return D3DERR_INVALIDCALL;
2580 wined3d_mutex_lock();
2581 if ((wined3d_shader = wined3d_device_get_pixel_shader(device->wined3d_device)))
2583 shader_impl = wined3d_shader_get_parent(wined3d_shader);
2584 *shader = &shader_impl->IDirect3DPixelShader9_iface;
2585 IDirect3DPixelShader9_AddRef(*shader);
2587 else
2589 *shader = NULL;
2591 wined3d_mutex_unlock();
2593 TRACE("Returning %p.\n", *shader);
2595 return D3D_OK;
2598 static HRESULT WINAPI d3d9_device_SetPixelShaderConstantF(IDirect3DDevice9Ex *iface,
2599 UINT reg_idx, const float *data, UINT count)
2601 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
2602 HRESULT hr;
2604 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
2606 wined3d_mutex_lock();
2607 hr = wined3d_device_set_ps_consts_f(device->wined3d_device, reg_idx, data, count);
2608 wined3d_mutex_unlock();
2610 return hr;
2613 static HRESULT WINAPI d3d9_device_GetPixelShaderConstantF(IDirect3DDevice9Ex *iface,
2614 UINT reg_idx, float *data, UINT count)
2616 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
2617 HRESULT hr;
2619 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
2621 wined3d_mutex_lock();
2622 hr = wined3d_device_get_ps_consts_f(device->wined3d_device, reg_idx, data, count);
2623 wined3d_mutex_unlock();
2625 return hr;
2628 static HRESULT WINAPI d3d9_device_SetPixelShaderConstantI(IDirect3DDevice9Ex *iface,
2629 UINT reg_idx, const int *data, UINT count)
2631 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
2632 HRESULT hr;
2634 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
2636 wined3d_mutex_lock();
2637 hr = wined3d_device_set_ps_consts_i(device->wined3d_device, reg_idx, data, count);
2638 wined3d_mutex_unlock();
2640 return hr;
2643 static HRESULT WINAPI d3d9_device_GetPixelShaderConstantI(IDirect3DDevice9Ex *iface,
2644 UINT reg_idx, int *data, UINT count)
2646 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
2647 HRESULT hr;
2649 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
2651 wined3d_mutex_lock();
2652 hr = wined3d_device_get_ps_consts_i(device->wined3d_device, reg_idx, data, count);
2653 wined3d_mutex_unlock();
2655 return hr;
2658 static HRESULT WINAPI d3d9_device_SetPixelShaderConstantB(IDirect3DDevice9Ex *iface,
2659 UINT reg_idx, const BOOL *data, UINT count)
2661 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
2662 HRESULT hr;
2664 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
2666 wined3d_mutex_lock();
2667 hr = wined3d_device_set_ps_consts_b(device->wined3d_device, reg_idx, data, count);
2668 wined3d_mutex_unlock();
2670 return hr;
2673 static HRESULT WINAPI d3d9_device_GetPixelShaderConstantB(IDirect3DDevice9Ex *iface,
2674 UINT reg_idx, BOOL *data, UINT count)
2676 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
2677 HRESULT hr;
2679 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
2681 wined3d_mutex_lock();
2682 hr = wined3d_device_get_ps_consts_b(device->wined3d_device, reg_idx, data, count);
2683 wined3d_mutex_unlock();
2685 return hr;
2688 static HRESULT WINAPI d3d9_device_DrawRectPatch(IDirect3DDevice9Ex *iface, UINT handle,
2689 const float *segment_count, const D3DRECTPATCH_INFO *patch_info)
2691 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
2692 HRESULT hr;
2694 TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
2695 iface, handle, segment_count, patch_info);
2697 wined3d_mutex_lock();
2698 hr = wined3d_device_draw_rect_patch(device->wined3d_device, handle,
2699 segment_count, (const struct wined3d_rect_patch_info *)patch_info);
2700 wined3d_mutex_unlock();
2702 return hr;
2705 static HRESULT WINAPI d3d9_device_DrawTriPatch(IDirect3DDevice9Ex *iface, UINT handle,
2706 const float *segment_count, const D3DTRIPATCH_INFO *patch_info)
2708 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
2709 HRESULT hr;
2711 TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
2712 iface, handle, segment_count, patch_info);
2714 wined3d_mutex_lock();
2715 hr = wined3d_device_draw_tri_patch(device->wined3d_device, handle,
2716 segment_count, (const struct wined3d_tri_patch_info *)patch_info);
2717 wined3d_mutex_unlock();
2719 return hr;
2722 static HRESULT WINAPI d3d9_device_DeletePatch(IDirect3DDevice9Ex *iface, UINT handle)
2724 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
2725 HRESULT hr;
2727 TRACE("iface %p, handle %#x.\n", iface, handle);
2729 wined3d_mutex_lock();
2730 hr = wined3d_device_delete_patch(device->wined3d_device, handle);
2731 wined3d_mutex_unlock();
2733 return hr;
2736 static HRESULT WINAPI d3d9_device_CreateQuery(IDirect3DDevice9Ex *iface, D3DQUERYTYPE type, IDirect3DQuery9 **query)
2738 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
2739 struct d3d9_query *object;
2740 HRESULT hr;
2742 TRACE("iface %p, type %#x, query %p.\n", iface, type, query);
2744 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2745 if (!object)
2747 ERR("Failed to allocate query memory.\n");
2748 return E_OUTOFMEMORY;
2751 hr = query_init(object, device, type);
2752 if (FAILED(hr))
2754 WARN("Failed to initialize query, hr %#x.\n", hr);
2755 HeapFree(GetProcessHeap(), 0, object);
2756 return hr;
2759 TRACE("Created query %p.\n", object);
2760 if (query) *query = &object->IDirect3DQuery9_iface;
2761 else IDirect3DQuery9_Release(&object->IDirect3DQuery9_iface);
2763 return D3D_OK;
2766 static HRESULT WINAPI d3d9_device_SetConvolutionMonoKernel(IDirect3DDevice9Ex *iface,
2767 UINT width, UINT height, float *rows, float *columns)
2769 FIXME("iface %p, width %u, height %u, rows %p, columns %p stub!\n",
2770 iface, width, height, rows, columns);
2772 return E_NOTIMPL;
2775 static HRESULT WINAPI d3d9_device_ComposeRects(IDirect3DDevice9Ex *iface,
2776 IDirect3DSurface9 *src_surface, IDirect3DSurface9 *dst_surface, IDirect3DVertexBuffer9 *src_descs,
2777 UINT rect_count, IDirect3DVertexBuffer9 *dst_descs, D3DCOMPOSERECTSOP operation, INT offset_x, INT offset_y)
2779 FIXME("iface %p, src_surface %p, dst_surface %p, src_descs %p, rect_count %u,\n"
2780 "dst_descs %p, operation %#x, offset_x %u, offset_y %u stub!\n",
2781 iface, src_surface, dst_surface, src_descs, rect_count,
2782 dst_descs, operation, offset_x, offset_y);
2784 return E_NOTIMPL;
2787 static HRESULT WINAPI d3d9_device_PresentEx(IDirect3DDevice9Ex *iface,
2788 const RECT *src_rect, const RECT *dst_rect, HWND dst_window_override,
2789 const RGNDATA *dirty_region, DWORD flags)
2791 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
2792 HRESULT hr;
2794 TRACE("iface %p, src_rect %s, dst_rect %s, dst_window_override %p, dirty_region %p, flags %#x.\n",
2795 iface, wine_dbgstr_rect(src_rect), wine_dbgstr_rect(dst_rect),
2796 dst_window_override, dirty_region, flags);
2798 wined3d_mutex_lock();
2799 hr = wined3d_device_present(device->wined3d_device, src_rect, dst_rect,
2800 dst_window_override, dirty_region, flags);
2801 wined3d_mutex_unlock();
2803 return hr;
2806 static HRESULT WINAPI d3d9_device_GetGPUThreadPriority(IDirect3DDevice9Ex *iface, INT *priority)
2808 FIXME("iface %p, priority %p stub!\n", iface, priority);
2810 return E_NOTIMPL;
2813 static HRESULT WINAPI d3d9_device_SetGPUThreadPriority(IDirect3DDevice9Ex *iface, INT priority)
2815 FIXME("iface %p, priority %d stub!\n", iface, priority);
2817 return E_NOTIMPL;
2820 static HRESULT WINAPI d3d9_device_WaitForVBlank(IDirect3DDevice9Ex *iface, UINT swapchain_idx)
2822 FIXME("iface %p, swapchain_idx %u stub!\n", iface, swapchain_idx);
2824 return E_NOTIMPL;
2827 static HRESULT WINAPI d3d9_device_CheckResourceResidency(IDirect3DDevice9Ex *iface,
2828 IDirect3DResource9 **resources, UINT32 resource_count)
2830 FIXME("iface %p, resources %p, resource_count %u stub!\n",
2831 iface, resources, resource_count);
2833 return E_NOTIMPL;
2836 static HRESULT WINAPI d3d9_device_SetMaximumFrameLatency(IDirect3DDevice9Ex *iface, UINT max_latency)
2838 FIXME("iface %p, max_latency %u stub!\n", iface, max_latency);
2840 return E_NOTIMPL;
2843 static HRESULT WINAPI d3d9_device_GetMaximumFrameLatency(IDirect3DDevice9Ex *iface, UINT *max_latency)
2845 FIXME("iface %p, max_latency %p stub!\n", iface, max_latency);
2847 *max_latency = 2;
2849 return E_NOTIMPL;
2852 static HRESULT WINAPI d3d9_device_CheckDeviceState(IDirect3DDevice9Ex *iface, HWND dst_window)
2854 static int i;
2856 TRACE("iface %p, dst_window %p stub!\n", iface, dst_window);
2858 if (!i++)
2859 FIXME("iface %p, dst_window %p stub!\n", iface, dst_window);
2861 return D3D_OK;
2864 static HRESULT WINAPI d3d9_device_CreateRenderTargetEx(IDirect3DDevice9Ex *iface,
2865 UINT width, UINT height, D3DFORMAT format, D3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality,
2866 BOOL lockable, IDirect3DSurface9 **surface, HANDLE *shared_handle, DWORD usage)
2868 FIXME("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u,\n"
2869 "lockable %#x, surface %p, shared_handle %p, usage %#x stub!\n",
2870 iface, width, height, format, multisample_type, multisample_quality,
2871 lockable, surface, shared_handle, usage);
2873 if (shared_handle)
2874 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle);
2876 return E_NOTIMPL;
2879 static HRESULT WINAPI d3d9_device_CreateOffscreenPlainSurfaceEx(IDirect3DDevice9Ex *iface,
2880 UINT width, UINT height, D3DFORMAT format, D3DPOOL pool, IDirect3DSurface9 **surface,
2881 HANDLE *shared_handle, DWORD usage)
2883 FIXME("iface %p, width %u, height %u, format %#x, pool %#x, surface %p, shared_handle %p, usage %#x stub!\n",
2884 iface, width, height, format, pool, surface, shared_handle, usage);
2886 return E_NOTIMPL;
2889 static HRESULT WINAPI d3d9_device_CreateDepthStencilSurfaceEx(IDirect3DDevice9Ex *iface,
2890 UINT width, UINT height, D3DFORMAT format, D3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality,
2891 BOOL discard, IDirect3DSurface9 **surface, HANDLE *shared_handle, DWORD usage)
2893 FIXME("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u,\n"
2894 "discard %#x, surface %p, shared_handle %p, usage %#x stub!\n",
2895 iface, width, height, format, multisample_type, multisample_quality,
2896 discard, surface, shared_handle, usage);
2898 if (shared_handle)
2899 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle);
2901 return E_NOTIMPL;
2904 static HRESULT WINAPI d3d9_device_ResetEx(IDirect3DDevice9Ex *iface,
2905 D3DPRESENT_PARAMETERS *present_parameters, D3DDISPLAYMODEEX *mode)
2907 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
2908 struct wined3d_swapchain_desc swapchain_desc;
2909 struct wined3d_display_mode wined3d_mode;
2910 HRESULT hr;
2912 TRACE("iface %p, present_parameters %p, mode %p.\n", iface, present_parameters, mode);
2914 if (mode)
2916 wined3d_mode.width = mode->Width;
2917 wined3d_mode.height = mode->Height;
2918 wined3d_mode.refresh_rate = mode->RefreshRate;
2919 wined3d_mode.format_id = wined3dformat_from_d3dformat(mode->Format);
2920 wined3d_mode.scanline_ordering = mode->ScanLineOrdering;
2923 wined3d_mutex_lock();
2924 wined3d_swapchain_desc_from_present_parameters(&swapchain_desc, present_parameters);
2925 hr = wined3d_device_reset(device->wined3d_device, &swapchain_desc,
2926 mode ? &wined3d_mode : NULL, reset_enum_callback);
2927 if (FAILED(hr))
2928 device->not_reset = TRUE;
2929 else
2930 device->not_reset = FALSE;
2931 wined3d_mutex_unlock();
2933 return hr;
2936 static HRESULT WINAPI d3d9_device_GetDisplayModeEx(IDirect3DDevice9Ex *iface,
2937 UINT swapchain_idx, D3DDISPLAYMODEEX *mode, D3DDISPLAYROTATION *rotation)
2939 struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
2940 struct wined3d_display_mode wined3d_mode;
2941 HRESULT hr;
2943 TRACE("iface %p, swapchain_idx %u, mode %p, rotation %p.\n",
2944 iface, swapchain_idx, mode, rotation);
2946 if (mode->Size != sizeof(*mode))
2947 return D3DERR_INVALIDCALL;
2949 wined3d_mutex_lock();
2950 hr = wined3d_device_get_display_mode(device->wined3d_device, swapchain_idx, &wined3d_mode,
2951 (enum wined3d_display_rotation *)rotation);
2952 wined3d_mutex_unlock();
2954 if (SUCCEEDED(hr))
2956 mode->Width = wined3d_mode.width;
2957 mode->Height = wined3d_mode.height;
2958 mode->RefreshRate = wined3d_mode.refresh_rate;
2959 mode->Format = d3dformat_from_wined3dformat(wined3d_mode.format_id);
2960 mode->ScanLineOrdering = wined3d_mode.scanline_ordering;
2963 return hr;
2966 static const struct IDirect3DDevice9ExVtbl d3d9_device_vtbl =
2968 /* IUnknown */
2969 d3d9_device_QueryInterface,
2970 d3d9_device_AddRef,
2971 d3d9_device_Release,
2972 /* IDirect3DDevice9 */
2973 d3d9_device_TestCooperativeLevel,
2974 d3d9_device_GetAvailableTextureMem,
2975 d3d9_device_EvictManagedResources,
2976 d3d9_device_GetDirect3D,
2977 d3d9_device_GetDeviceCaps,
2978 d3d9_device_GetDisplayMode,
2979 d3d9_device_GetCreationParameters,
2980 d3d9_device_SetCursorProperties,
2981 d3d9_device_SetCursorPosition,
2982 d3d9_device_ShowCursor,
2983 d3d9_device_CreateAdditionalSwapChain,
2984 d3d9_device_GetSwapChain,
2985 d3d9_device_GetNumberOfSwapChains,
2986 d3d9_device_Reset,
2987 d3d9_device_Present,
2988 d3d9_device_GetBackBuffer,
2989 d3d9_device_GetRasterStatus,
2990 d3d9_device_SetDialogBoxMode,
2991 d3d9_device_SetGammaRamp,
2992 d3d9_device_GetGammaRamp,
2993 d3d9_device_CreateTexture,
2994 d3d9_device_CreateVolumeTexture,
2995 d3d9_device_CreateCubeTexture,
2996 d3d9_device_CreateVertexBuffer,
2997 d3d9_device_CreateIndexBuffer,
2998 d3d9_device_CreateRenderTarget,
2999 d3d9_device_CreateDepthStencilSurface,
3000 d3d9_device_UpdateSurface,
3001 d3d9_device_UpdateTexture,
3002 d3d9_device_GetRenderTargetData,
3003 d3d9_device_GetFrontBufferData,
3004 d3d9_device_StretchRect,
3005 d3d9_device_ColorFill,
3006 d3d9_device_CreateOffscreenPlainSurface,
3007 d3d9_device_SetRenderTarget,
3008 d3d9_device_GetRenderTarget,
3009 d3d9_device_SetDepthStencilSurface,
3010 d3d9_device_GetDepthStencilSurface,
3011 d3d9_device_BeginScene,
3012 d3d9_device_EndScene,
3013 d3d9_device_Clear,
3014 d3d9_device_SetTransform,
3015 d3d9_device_GetTransform,
3016 d3d9_device_MultiplyTransform,
3017 d3d9_device_SetViewport,
3018 d3d9_device_GetViewport,
3019 d3d9_device_SetMaterial,
3020 d3d9_device_GetMaterial,
3021 d3d9_device_SetLight,
3022 d3d9_device_GetLight,
3023 d3d9_device_LightEnable,
3024 d3d9_device_GetLightEnable,
3025 d3d9_device_SetClipPlane,
3026 d3d9_device_GetClipPlane,
3027 d3d9_device_SetRenderState,
3028 d3d9_device_GetRenderState,
3029 d3d9_device_CreateStateBlock,
3030 d3d9_device_BeginStateBlock,
3031 d3d9_device_EndStateBlock,
3032 d3d9_device_SetClipStatus,
3033 d3d9_device_GetClipStatus,
3034 d3d9_device_GetTexture,
3035 d3d9_device_SetTexture,
3036 d3d9_device_GetTextureStageState,
3037 d3d9_device_SetTextureStageState,
3038 d3d9_device_GetSamplerState,
3039 d3d9_device_SetSamplerState,
3040 d3d9_device_ValidateDevice,
3041 d3d9_device_SetPaletteEntries,
3042 d3d9_device_GetPaletteEntries,
3043 d3d9_device_SetCurrentTexturePalette,
3044 d3d9_device_GetCurrentTexturePalette,
3045 d3d9_device_SetScissorRect,
3046 d3d9_device_GetScissorRect,
3047 d3d9_device_SetSoftwareVertexProcessing,
3048 d3d9_device_GetSoftwareVertexProcessing,
3049 d3d9_device_SetNPatchMode,
3050 d3d9_device_GetNPatchMode,
3051 d3d9_device_DrawPrimitive,
3052 d3d9_device_DrawIndexedPrimitive,
3053 d3d9_device_DrawPrimitiveUP,
3054 d3d9_device_DrawIndexedPrimitiveUP,
3055 d3d9_device_ProcessVertices,
3056 d3d9_device_CreateVertexDeclaration,
3057 d3d9_device_SetVertexDeclaration,
3058 d3d9_device_GetVertexDeclaration,
3059 d3d9_device_SetFVF,
3060 d3d9_device_GetFVF,
3061 d3d9_device_CreateVertexShader,
3062 d3d9_device_SetVertexShader,
3063 d3d9_device_GetVertexShader,
3064 d3d9_device_SetVertexShaderConstantF,
3065 d3d9_device_GetVertexShaderConstantF,
3066 d3d9_device_SetVertexShaderConstantI,
3067 d3d9_device_GetVertexShaderConstantI,
3068 d3d9_device_SetVertexShaderConstantB,
3069 d3d9_device_GetVertexShaderConstantB,
3070 d3d9_device_SetStreamSource,
3071 d3d9_device_GetStreamSource,
3072 d3d9_device_SetStreamSourceFreq,
3073 d3d9_device_GetStreamSourceFreq,
3074 d3d9_device_SetIndices,
3075 d3d9_device_GetIndices,
3076 d3d9_device_CreatePixelShader,
3077 d3d9_device_SetPixelShader,
3078 d3d9_device_GetPixelShader,
3079 d3d9_device_SetPixelShaderConstantF,
3080 d3d9_device_GetPixelShaderConstantF,
3081 d3d9_device_SetPixelShaderConstantI,
3082 d3d9_device_GetPixelShaderConstantI,
3083 d3d9_device_SetPixelShaderConstantB,
3084 d3d9_device_GetPixelShaderConstantB,
3085 d3d9_device_DrawRectPatch,
3086 d3d9_device_DrawTriPatch,
3087 d3d9_device_DeletePatch,
3088 d3d9_device_CreateQuery,
3089 /* IDirect3DDevice9Ex */
3090 d3d9_device_SetConvolutionMonoKernel,
3091 d3d9_device_ComposeRects,
3092 d3d9_device_PresentEx,
3093 d3d9_device_GetGPUThreadPriority,
3094 d3d9_device_SetGPUThreadPriority,
3095 d3d9_device_WaitForVBlank,
3096 d3d9_device_CheckResourceResidency,
3097 d3d9_device_SetMaximumFrameLatency,
3098 d3d9_device_GetMaximumFrameLatency,
3099 d3d9_device_CheckDeviceState,
3100 d3d9_device_CreateRenderTargetEx,
3101 d3d9_device_CreateOffscreenPlainSurfaceEx,
3102 d3d9_device_CreateDepthStencilSurfaceEx,
3103 d3d9_device_ResetEx,
3104 d3d9_device_GetDisplayModeEx,
3107 static inline struct d3d9_device *device_from_device_parent(struct wined3d_device_parent *device_parent)
3109 return CONTAINING_RECORD(device_parent, struct d3d9_device, device_parent);
3112 static void CDECL device_parent_wined3d_device_created(struct wined3d_device_parent *device_parent,
3113 struct wined3d_device *device)
3115 TRACE("device_parent %p, device %p.\n", device_parent, device);
3118 static void CDECL device_parent_mode_changed(struct wined3d_device_parent *device_parent)
3120 TRACE("device_parent %p.\n", device_parent);
3123 static HRESULT CDECL device_parent_create_texture_surface(struct wined3d_device_parent *device_parent,
3124 void *container_parent, UINT width, UINT height, enum wined3d_format_id format, DWORD usage,
3125 enum wined3d_pool pool, UINT level, enum wined3d_cubemap_face face, struct wined3d_surface **surface)
3127 struct d3d9_device *device = device_from_device_parent(device_parent);
3128 struct d3d9_surface *d3d_surface;
3129 BOOL lockable = TRUE;
3130 HRESULT hr;
3132 TRACE("device_parent %p, container_parent %p, width %u, height %u, format %#x, usage %#x,\n"
3133 "\tpool %#x, level %u, face %u, surface %p.\n",
3134 device_parent, container_parent, width, height, format, usage, pool, level, face, surface);
3136 if (pool == WINED3D_POOL_DEFAULT && !(usage & D3DUSAGE_DYNAMIC))
3137 lockable = FALSE;
3139 hr = d3d9_device_create_surface(device, width, height,
3140 d3dformat_from_wined3dformat(format), lockable, FALSE /* Discard */, level,
3141 (IDirect3DSurface9 **)&d3d_surface, usage, pool, D3DMULTISAMPLE_NONE, 0 /* MultisampleQuality */);
3142 if (FAILED(hr))
3144 WARN("Failed to create surface, hr %#x.\n", hr);
3145 return hr;
3148 *surface = d3d_surface->wined3d_surface;
3149 wined3d_surface_incref(*surface);
3151 d3d_surface->container = container_parent;
3152 IDirect3DDevice9Ex_Release(d3d_surface->parent_device);
3153 d3d_surface->parent_device = NULL;
3155 IDirect3DSurface9_Release(&d3d_surface->IDirect3DSurface9_iface);
3156 d3d_surface->forwardReference = container_parent;
3158 return hr;
3161 static HRESULT CDECL device_parent_create_swapchain_surface(struct wined3d_device_parent *device_parent,
3162 void *container_parent, UINT width, UINT height, enum wined3d_format_id format_id, DWORD usage,
3163 enum wined3d_multisample_type multisample_type, DWORD multisample_quality, struct wined3d_surface **surface)
3165 struct d3d9_device *device = device_from_device_parent(device_parent);
3166 struct d3d9_surface *d3d_surface;
3167 HRESULT hr;
3169 TRACE("device_parent %p, container_parent %p, width %u, height %u, format_id %#x, usage %#x,\n"
3170 "\tmultisample_type %#x, multisample_quality %u, surface %p.\n",
3171 device_parent, container_parent, width, height, format_id, usage,
3172 multisample_type, multisample_quality, surface);
3174 if (FAILED(hr = d3d9_device_create_surface(device, width, height, d3dformat_from_wined3dformat(format_id),
3175 TRUE, FALSE, 0, (IDirect3DSurface9 **)&d3d_surface, usage, D3DPOOL_DEFAULT, multisample_type,
3176 multisample_quality)))
3178 WARN("Failed to create surface, hr %#x.\n", hr);
3179 return hr;
3182 *surface = d3d_surface->wined3d_surface;
3183 wined3d_surface_incref(*surface);
3185 if (container_parent == device_parent)
3186 d3d_surface->container = (IUnknown *)&device->IDirect3DDevice9Ex_iface;
3187 else
3188 d3d_surface->container = container_parent;
3189 /* Implicit surfaces are created with an refcount of 0 */
3190 IDirect3DSurface9_Release(&d3d_surface->IDirect3DSurface9_iface);
3192 return hr;
3195 static HRESULT CDECL device_parent_create_volume(struct wined3d_device_parent *device_parent,
3196 void *container_parent, UINT width, UINT height, UINT depth, enum wined3d_format_id format,
3197 enum wined3d_pool pool, DWORD usage, struct wined3d_volume **volume)
3199 struct d3d9_device *device = device_from_device_parent(device_parent);
3200 struct d3d9_volume *object;
3201 HRESULT hr;
3203 TRACE("device_parent %p, container_parent %p, width %u, height %u, depth %u, "
3204 "format %#x, pool %#x, usage %#x, volume %p\n",
3205 device_parent, container_parent, width, height, depth,
3206 format, pool, usage, volume);
3208 /* Allocate the storage for the device */
3209 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
3210 if (!object)
3212 FIXME("Allocation of memory failed\n");
3213 *volume = NULL;
3214 return D3DERR_OUTOFVIDEOMEMORY;
3217 hr = volume_init(object, device, width, height, depth, usage, format, pool);
3218 if (FAILED(hr))
3220 WARN("Failed to initialize volume, hr %#x.\n", hr);
3221 HeapFree(GetProcessHeap(), 0, object);
3222 return hr;
3225 *volume = object->wined3d_volume;
3226 wined3d_volume_incref(*volume);
3227 IDirect3DVolume9_Release(&object->IDirect3DVolume9_iface);
3229 object->container = container_parent;
3230 object->forwardReference = container_parent;
3232 TRACE("Created volume %p.\n", object);
3234 return hr;
3237 static HRESULT CDECL device_parent_create_swapchain(struct wined3d_device_parent *device_parent,
3238 struct wined3d_swapchain_desc *desc, struct wined3d_swapchain **swapchain)
3240 struct d3d9_device *device = device_from_device_parent(device_parent);
3241 struct d3d9_swapchain *d3d_swapchain;
3242 HRESULT hr;
3244 TRACE("device_parent %p, desc %p, swapchain %p\n", device_parent, desc, swapchain);
3246 hr = d3d9_swapchain_create(device, desc, &d3d_swapchain);
3247 if (FAILED(hr))
3249 WARN("Failed to create swapchain, hr %#x.\n", hr);
3250 *swapchain = NULL;
3251 return hr;
3254 *swapchain = d3d_swapchain->wined3d_swapchain;
3255 wined3d_swapchain_incref(*swapchain);
3256 IDirect3DSwapChain9_Release(&d3d_swapchain->IDirect3DSwapChain9_iface);
3258 return hr;
3261 static const struct wined3d_device_parent_ops d3d9_wined3d_device_parent_ops =
3263 device_parent_wined3d_device_created,
3264 device_parent_mode_changed,
3265 device_parent_create_swapchain_surface,
3266 device_parent_create_texture_surface,
3267 device_parent_create_volume,
3268 device_parent_create_swapchain,
3271 static void setup_fpu(void)
3273 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
3274 WORD cw;
3275 __asm__ volatile ("fnstcw %0" : "=m" (cw));
3276 cw = (cw & ~0xf3f) | 0x3f;
3277 __asm__ volatile ("fldcw %0" : : "m" (cw));
3278 #elif defined(__i386__) && defined(_MSC_VER)
3279 WORD cw;
3280 __asm fnstcw cw;
3281 cw = (cw & ~0xf3f) | 0x3f;
3282 __asm fldcw cw;
3283 #else
3284 FIXME("FPU setup not implemented for this platform.\n");
3285 #endif
3288 HRESULT device_init(struct d3d9_device *device, struct d3d9 *parent, struct wined3d *wined3d,
3289 UINT adapter, D3DDEVTYPE device_type, HWND focus_window, DWORD flags,
3290 D3DPRESENT_PARAMETERS *parameters, D3DDISPLAYMODEEX *mode)
3292 struct wined3d_swapchain_desc *swapchain_desc;
3293 UINT i, count = 1;
3294 HRESULT hr;
3296 if (mode)
3297 FIXME("Ignoring display mode.\n");
3299 device->IDirect3DDevice9Ex_iface.lpVtbl = &d3d9_device_vtbl;
3300 device->device_parent.ops = &d3d9_wined3d_device_parent_ops;
3301 device->refcount = 1;
3303 if (!(flags & D3DCREATE_FPU_PRESERVE)) setup_fpu();
3305 wined3d_mutex_lock();
3306 hr = wined3d_device_create(wined3d, adapter, device_type, focus_window, flags, 4,
3307 &device->device_parent, &device->wined3d_device);
3308 if (FAILED(hr))
3310 WARN("Failed to create wined3d device, hr %#x.\n", hr);
3311 wined3d_mutex_unlock();
3312 return hr;
3315 if (flags & D3DCREATE_ADAPTERGROUP_DEVICE)
3317 WINED3DCAPS caps;
3319 wined3d_get_device_caps(wined3d, adapter, device_type, &caps);
3320 count = caps.NumberOfAdaptersInGroup;
3323 if (flags & D3DCREATE_MULTITHREADED)
3324 wined3d_device_set_multithreaded(device->wined3d_device);
3326 if (!parameters->Windowed)
3328 if (!focus_window)
3329 focus_window = parameters->hDeviceWindow;
3330 if (FAILED(hr = wined3d_device_acquire_focus_window(device->wined3d_device, focus_window)))
3332 ERR("Failed to acquire focus window, hr %#x.\n", hr);
3333 wined3d_device_decref(device->wined3d_device);
3334 wined3d_mutex_unlock();
3335 return hr;
3338 for (i = 0; i < count; ++i)
3340 HWND device_window = parameters[i].hDeviceWindow;
3342 if (!device_window) device_window = focus_window;
3343 wined3d_device_setup_fullscreen_window(device->wined3d_device, device_window,
3344 parameters[i].BackBufferWidth,
3345 parameters[i].BackBufferHeight);
3349 swapchain_desc = HeapAlloc(GetProcessHeap(), 0, sizeof(*swapchain_desc) * count);
3350 if (!swapchain_desc)
3352 ERR("Failed to allocate wined3d parameters.\n");
3353 wined3d_device_decref(device->wined3d_device);
3354 wined3d_mutex_unlock();
3355 return E_OUTOFMEMORY;
3358 for (i = 0; i < count; ++i)
3360 wined3d_swapchain_desc_from_present_parameters(&swapchain_desc[i], &parameters[i]);
3363 hr = wined3d_device_init_3d(device->wined3d_device, swapchain_desc);
3364 if (FAILED(hr))
3366 WARN("Failed to initialize 3D, hr %#x.\n", hr);
3367 wined3d_device_release_focus_window(device->wined3d_device);
3368 HeapFree(GetProcessHeap(), 0, swapchain_desc);
3369 wined3d_device_decref(device->wined3d_device);
3370 wined3d_mutex_unlock();
3371 return hr;
3374 wined3d_mutex_unlock();
3376 for (i = 0; i < count; ++i)
3378 present_parameters_from_wined3d_swapchain_desc(&parameters[i], &swapchain_desc[i]);
3380 HeapFree(GetProcessHeap(), 0, swapchain_desc);
3382 /* Initialize the converted declaration array. This creates a valid pointer
3383 * and when adding decls HeapReAlloc() can be used without further checking. */
3384 device->fvf_decls = HeapAlloc(GetProcessHeap(), 0, 0);
3385 if (!device->fvf_decls)
3387 ERR("Failed to allocate FVF vertex declaration map memory.\n");
3388 wined3d_mutex_lock();
3389 wined3d_device_uninit_3d(device->wined3d_device);
3390 wined3d_device_release_focus_window(device->wined3d_device);
3391 wined3d_device_decref(device->wined3d_device);
3392 wined3d_mutex_unlock();
3393 return E_OUTOFMEMORY;
3396 IDirect3D9Ex_AddRef(&parent->IDirect3D9Ex_iface);
3397 device->d3d_parent = parent;
3399 return D3D_OK;