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
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
;
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
;
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
;
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
;
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
;
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;
179 FIXME("Unhandled primitive type %#x\n", primitive_type
);
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
);
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");
252 return E_NOINTERFACE
;
255 IDirect3DDevice9Ex_AddRef(iface
);
260 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
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
);
276 static ULONG WINAPI DECLSPEC_HOTPATCH
d3d9_device_Release(IDirect3DDevice9Ex
*iface
)
278 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
281 if (device
->in_destruction
)
284 refcount
= InterlockedDecrement(&device
->refcount
);
286 TRACE("%p decreasing refcount to %u.\n", iface
, refcount
);
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 if (device
->vertex_buffer
)
301 wined3d_buffer_decref(device
->vertex_buffer
);
302 if (device
->index_buffer
)
303 wined3d_buffer_decref(device
->index_buffer
);
305 wined3d_device_uninit_3d(device
->wined3d_device
);
306 wined3d_device_release_focus_window(device
->wined3d_device
);
307 wined3d_device_decref(device
->wined3d_device
);
308 wined3d_mutex_unlock();
310 IDirect3D9Ex_Release(&device
->d3d_parent
->IDirect3D9Ex_iface
);
312 HeapFree(GetProcessHeap(), 0, device
);
318 static HRESULT WINAPI
d3d9_device_TestCooperativeLevel(IDirect3DDevice9Ex
*iface
)
320 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
322 TRACE("iface %p.\n", iface
);
324 if (device
->not_reset
)
326 TRACE("D3D9 device is marked not reset.\n");
327 return D3DERR_DEVICENOTRESET
;
333 static UINT WINAPI
d3d9_device_GetAvailableTextureMem(IDirect3DDevice9Ex
*iface
)
335 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
338 TRACE("iface %p.\n", iface
);
340 wined3d_mutex_lock();
341 hr
= wined3d_device_get_available_texture_mem(device
->wined3d_device
);
342 wined3d_mutex_unlock();
347 static HRESULT WINAPI
d3d9_device_EvictManagedResources(IDirect3DDevice9Ex
*iface
)
349 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
351 TRACE("iface %p.\n", iface
);
353 wined3d_mutex_lock();
354 wined3d_device_evict_managed_resources(device
->wined3d_device
);
355 wined3d_mutex_unlock();
360 static HRESULT WINAPI
d3d9_device_GetDirect3D(IDirect3DDevice9Ex
*iface
, IDirect3D9
**d3d9
)
362 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
364 TRACE("iface %p, d3d9 %p.\n", iface
, d3d9
);
367 return D3DERR_INVALIDCALL
;
369 return IDirect3D9Ex_QueryInterface(&device
->d3d_parent
->IDirect3D9Ex_iface
, &IID_IDirect3D9
, (void **)d3d9
);
372 static HRESULT WINAPI
d3d9_device_GetDeviceCaps(IDirect3DDevice9Ex
*iface
, D3DCAPS9
*caps
)
374 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
375 WINED3DCAPS
*wined3d_caps
;
378 TRACE("iface %p, caps %p.\n", iface
, caps
);
381 return D3DERR_INVALIDCALL
;
383 if (!(wined3d_caps
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*wined3d_caps
))))
384 return D3DERR_INVALIDCALL
; /* well this is what MSDN says to return */
386 memset(caps
, 0, sizeof(*caps
));
388 wined3d_mutex_lock();
389 hr
= wined3d_device_get_device_caps(device
->wined3d_device
, wined3d_caps
);
390 wined3d_mutex_unlock();
392 WINECAPSTOD3D9CAPS(caps
, wined3d_caps
)
393 HeapFree(GetProcessHeap(), 0, wined3d_caps
);
395 /* Some functionality is implemented in d3d9.dll, not wined3d.dll. Add the needed caps */
396 caps
->DevCaps2
|= D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES
;
403 static HRESULT WINAPI
d3d9_device_GetDisplayMode(IDirect3DDevice9Ex
*iface
, UINT swapchain
, D3DDISPLAYMODE
*mode
)
405 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
406 struct wined3d_display_mode wined3d_mode
;
409 TRACE("iface %p, swapchain %u, mode %p.\n", iface
, swapchain
, mode
);
411 wined3d_mutex_lock();
412 hr
= wined3d_device_get_display_mode(device
->wined3d_device
, swapchain
, &wined3d_mode
, NULL
);
413 wined3d_mutex_unlock();
417 mode
->Width
= wined3d_mode
.width
;
418 mode
->Height
= wined3d_mode
.height
;
419 mode
->RefreshRate
= wined3d_mode
.refresh_rate
;
420 mode
->Format
= d3dformat_from_wined3dformat(wined3d_mode
.format_id
);
426 static HRESULT WINAPI
d3d9_device_GetCreationParameters(IDirect3DDevice9Ex
*iface
,
427 D3DDEVICE_CREATION_PARAMETERS
*parameters
)
429 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
431 TRACE("iface %p, parameters %p.\n", iface
, parameters
);
433 wined3d_mutex_lock();
434 wined3d_device_get_creation_parameters(device
->wined3d_device
,
435 (struct wined3d_device_creation_parameters
*)parameters
);
436 wined3d_mutex_unlock();
441 static HRESULT WINAPI
d3d9_device_SetCursorProperties(IDirect3DDevice9Ex
*iface
,
442 UINT hotspot_x
, UINT hotspot_y
, IDirect3DSurface9
*bitmap
)
444 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
445 struct d3d9_surface
*bitmap_impl
= unsafe_impl_from_IDirect3DSurface9(bitmap
);
448 TRACE("iface %p, hotspot_x %u, hotspot_y %u, bitmap %p.\n",
449 iface
, hotspot_x
, hotspot_y
, bitmap
);
453 WARN("No cursor bitmap, returning D3DERR_INVALIDCALL.\n");
454 return D3DERR_INVALIDCALL
;
457 wined3d_mutex_lock();
458 hr
= wined3d_device_set_cursor_properties(device
->wined3d_device
,
459 hotspot_x
, hotspot_y
, bitmap_impl
->wined3d_surface
);
460 wined3d_mutex_unlock();
465 static void WINAPI
d3d9_device_SetCursorPosition(IDirect3DDevice9Ex
*iface
, int x
, int y
, DWORD flags
)
467 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
469 TRACE("iface %p, x %u, y %u, flags %#x.\n", iface
, x
, y
, flags
);
471 wined3d_mutex_lock();
472 wined3d_device_set_cursor_position(device
->wined3d_device
, x
, y
, flags
);
473 wined3d_mutex_unlock();
476 static BOOL WINAPI
d3d9_device_ShowCursor(IDirect3DDevice9Ex
*iface
, BOOL show
)
478 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
481 TRACE("iface %p, show %#x.\n", iface
, show
);
483 wined3d_mutex_lock();
484 ret
= wined3d_device_show_cursor(device
->wined3d_device
, show
);
485 wined3d_mutex_unlock();
490 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_device_CreateAdditionalSwapChain(IDirect3DDevice9Ex
*iface
,
491 D3DPRESENT_PARAMETERS
*present_parameters
, IDirect3DSwapChain9
**swapchain
)
493 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
494 struct wined3d_swapchain_desc desc
;
495 struct d3d9_swapchain
*object
;
498 TRACE("iface %p, present_parameters %p, swapchain %p.\n",
499 iface
, present_parameters
, swapchain
);
501 wined3d_swapchain_desc_from_present_parameters(&desc
, present_parameters
);
502 if (SUCCEEDED(hr
= d3d9_swapchain_create(device
, &desc
, &object
)))
503 *swapchain
= &object
->IDirect3DSwapChain9_iface
;
504 present_parameters_from_wined3d_swapchain_desc(present_parameters
, &desc
);
509 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_device_GetSwapChain(IDirect3DDevice9Ex
*iface
,
510 UINT swapchain_idx
, IDirect3DSwapChain9
**swapchain
)
512 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
513 struct wined3d_swapchain
*wined3d_swapchain
;
514 struct d3d9_swapchain
*swapchain_impl
;
517 TRACE("iface %p, swapchain_idx %u, swapchain %p.\n", iface
, swapchain_idx
, swapchain
);
519 wined3d_mutex_lock();
520 if ((wined3d_swapchain
= wined3d_device_get_swapchain(device
->wined3d_device
, swapchain_idx
)))
522 swapchain_impl
= wined3d_swapchain_get_parent(wined3d_swapchain
);
523 *swapchain
= &swapchain_impl
->IDirect3DSwapChain9_iface
;
524 IDirect3DSwapChain9_AddRef(*swapchain
);
530 hr
= D3DERR_INVALIDCALL
;
532 wined3d_mutex_unlock();
537 static UINT WINAPI
d3d9_device_GetNumberOfSwapChains(IDirect3DDevice9Ex
*iface
)
539 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
542 TRACE("iface %p.\n", iface
);
544 wined3d_mutex_lock();
545 count
= wined3d_device_get_swapchain_count(device
->wined3d_device
);
546 wined3d_mutex_unlock();
551 static HRESULT CDECL
reset_enum_callback(struct wined3d_resource
*resource
)
553 struct wined3d_resource_desc desc
;
555 wined3d_resource_get_desc(resource
, &desc
);
556 if (desc
.pool
== WINED3D_POOL_DEFAULT
)
558 struct d3d9_surface
*surface
;
560 if (desc
.resource_type
== WINED3D_RTYPE_TEXTURE
)
562 IUnknown
*parent
= wined3d_resource_get_parent(resource
);
563 IDirect3DBaseTexture9
*texture
;
565 if (SUCCEEDED(IUnknown_QueryInterface(parent
, &IID_IDirect3DBaseTexture9
, (void **)&texture
)))
567 IDirect3DBaseTexture9_Release(texture
);
568 WARN("Texture %p (resource %p) in pool D3DPOOL_DEFAULT blocks the Reset call.\n", texture
, resource
);
569 return D3DERR_INVALIDCALL
;
575 if (desc
.resource_type
!= WINED3D_RTYPE_SURFACE
)
577 WARN("Resource %p in pool D3DPOOL_DEFAULT blocks the Reset call.\n", resource
);
578 return D3DERR_INVALIDCALL
;
581 surface
= wined3d_resource_get_parent(resource
);
582 if (surface
->refcount
)
584 WARN("Surface %p (resource %p) in pool D3DPOOL_DEFAULT blocks the Reset call.\n", surface
, resource
);
585 return D3DERR_INVALIDCALL
;
588 WARN("Surface %p (resource %p) is an implicit resource with ref 0.\n", surface
, resource
);
594 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_device_Reset(IDirect3DDevice9Ex
*iface
,
595 D3DPRESENT_PARAMETERS
*present_parameters
)
597 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
598 struct wined3d_swapchain_desc swapchain_desc
;
601 TRACE("iface %p, present_parameters %p.\n", iface
, present_parameters
);
603 wined3d_mutex_lock();
605 if (device
->vertex_buffer
)
607 wined3d_buffer_decref(device
->vertex_buffer
);
608 device
->vertex_buffer
= NULL
;
609 device
->vertex_buffer_size
= 0;
611 if (device
->index_buffer
)
613 wined3d_buffer_decref(device
->index_buffer
);
614 device
->index_buffer
= NULL
;
615 device
->index_buffer_size
= 0;
618 wined3d_swapchain_desc_from_present_parameters(&swapchain_desc
, present_parameters
);
619 hr
= wined3d_device_reset(device
->wined3d_device
, &swapchain_desc
,
620 NULL
, reset_enum_callback
, !device
->d3d_parent
->extended
);
621 if (FAILED(hr
) && !device
->d3d_parent
->extended
)
622 device
->not_reset
= TRUE
;
624 device
->not_reset
= FALSE
;
625 wined3d_mutex_unlock();
630 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_device_Present(IDirect3DDevice9Ex
*iface
,
631 const RECT
*src_rect
, const RECT
*dst_rect
, HWND dst_window_override
, const RGNDATA
*dirty_region
)
633 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
636 TRACE("iface %p, src_rect %p, dst_rect %p, dst_window_override %p, dirty_region %p.\n",
637 iface
, src_rect
, dst_rect
, dst_window_override
, dirty_region
);
639 wined3d_mutex_lock();
640 hr
= wined3d_device_present(device
->wined3d_device
, src_rect
, dst_rect
,
641 dst_window_override
, dirty_region
, 0);
642 wined3d_mutex_unlock();
647 static HRESULT WINAPI
d3d9_device_GetBackBuffer(IDirect3DDevice9Ex
*iface
, UINT swapchain
,
648 UINT backbuffer_idx
, D3DBACKBUFFER_TYPE backbuffer_type
, IDirect3DSurface9
**backbuffer
)
650 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
651 struct wined3d_surface
*wined3d_surface
= NULL
;
652 struct d3d9_surface
*surface_impl
;
655 TRACE("iface %p, swapchain %u, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n",
656 iface
, swapchain
, backbuffer_idx
, backbuffer_type
, backbuffer
);
658 wined3d_mutex_lock();
659 hr
= wined3d_device_get_back_buffer(device
->wined3d_device
, swapchain
,
660 backbuffer_idx
, (enum wined3d_backbuffer_type
)backbuffer_type
, &wined3d_surface
);
661 if (SUCCEEDED(hr
) && wined3d_surface
&& backbuffer
)
663 surface_impl
= wined3d_surface_get_parent(wined3d_surface
);
664 *backbuffer
= &surface_impl
->IDirect3DSurface9_iface
;
665 IDirect3DSurface9_AddRef(*backbuffer
);
667 wined3d_mutex_unlock();
671 static HRESULT WINAPI
d3d9_device_GetRasterStatus(IDirect3DDevice9Ex
*iface
,
672 UINT swapchain
, D3DRASTER_STATUS
*raster_status
)
674 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
677 TRACE("iface %p, swapchain %u, raster_status %p.\n", iface
, swapchain
, raster_status
);
679 wined3d_mutex_lock();
680 hr
= wined3d_device_get_raster_status(device
->wined3d_device
,
681 swapchain
, (struct wined3d_raster_status
*)raster_status
);
682 wined3d_mutex_unlock();
687 static HRESULT WINAPI
d3d9_device_SetDialogBoxMode(IDirect3DDevice9Ex
*iface
, BOOL enable
)
689 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
692 TRACE("iface %p, enable %#x.\n", iface
, enable
);
694 wined3d_mutex_lock();
695 hr
= wined3d_device_set_dialog_box_mode(device
->wined3d_device
, enable
);
696 wined3d_mutex_unlock();
701 static void WINAPI
d3d9_device_SetGammaRamp(IDirect3DDevice9Ex
*iface
,
702 UINT swapchain
, DWORD flags
, const D3DGAMMARAMP
*ramp
)
704 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
706 TRACE("iface %p, swapchain %u, flags %#x, ramp %p.\n", iface
, swapchain
, flags
, ramp
);
708 /* Note: D3DGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
709 wined3d_mutex_lock();
710 wined3d_device_set_gamma_ramp(device
->wined3d_device
, swapchain
, flags
, (const struct wined3d_gamma_ramp
*)ramp
);
711 wined3d_mutex_unlock();
714 static void WINAPI
d3d9_device_GetGammaRamp(IDirect3DDevice9Ex
*iface
, UINT swapchain
, D3DGAMMARAMP
*ramp
)
716 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
718 TRACE("iface %p, swapchain %u, ramp %p.\n", iface
, swapchain
, ramp
);
720 /* Note: D3DGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
721 wined3d_mutex_lock();
722 wined3d_device_get_gamma_ramp(device
->wined3d_device
, swapchain
, (struct wined3d_gamma_ramp
*)ramp
);
723 wined3d_mutex_unlock();
726 static HRESULT WINAPI
d3d9_device_CreateTexture(IDirect3DDevice9Ex
*iface
,
727 UINT width
, UINT height
, UINT levels
, DWORD usage
, D3DFORMAT format
,
728 D3DPOOL pool
, IDirect3DTexture9
**texture
, HANDLE
*shared_handle
)
730 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
731 struct d3d9_texture
*object
;
732 BOOL set_mem
= FALSE
;
735 TRACE("iface %p, width %u, height %u, levels %u, usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
736 iface
, width
, height
, levels
, usage
, format
, pool
, texture
, shared_handle
);
740 if (pool
== D3DPOOL_SYSTEMMEM
)
743 return D3DERR_INVALIDCALL
;
747 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
750 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
752 return D3DERR_OUTOFVIDEOMEMORY
;
754 hr
= texture_init(object
, device
, width
, height
, levels
, usage
, format
, pool
);
757 WARN("Failed to initialize texture, hr %#x.\n", hr
);
758 HeapFree(GetProcessHeap(), 0, object
);
764 struct wined3d_resource
*resource
;
765 struct d3d9_surface
*surface
;
767 resource
= wined3d_texture_get_sub_resource(object
->wined3d_texture
, 0);
768 surface
= wined3d_resource_get_parent(resource
);
769 wined3d_surface_set_mem(surface
->wined3d_surface
, *shared_handle
);
772 TRACE("Created texture %p.\n", object
);
773 *texture
= (IDirect3DTexture9
*)&object
->IDirect3DBaseTexture9_iface
;
778 static HRESULT WINAPI
d3d9_device_CreateVolumeTexture(IDirect3DDevice9Ex
*iface
,
779 UINT width
, UINT height
, UINT depth
, UINT levels
, DWORD usage
, D3DFORMAT format
,
780 D3DPOOL pool
, IDirect3DVolumeTexture9
**texture
, HANDLE
*shared_handle
)
782 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
783 struct d3d9_texture
*object
;
786 TRACE("iface %p, width %u, height %u, depth %u, levels %u\n",
787 iface
, width
, height
, depth
, levels
);
788 TRACE("usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
789 usage
, format
, pool
, texture
, shared_handle
);
792 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
794 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
796 return D3DERR_OUTOFVIDEOMEMORY
;
798 hr
= volumetexture_init(object
, device
, width
, height
, depth
, levels
, usage
, format
, pool
);
801 WARN("Failed to initialize volume texture, hr %#x.\n", hr
);
802 HeapFree(GetProcessHeap(), 0, object
);
806 TRACE("Created volume texture %p.\n", object
);
807 *texture
= (IDirect3DVolumeTexture9
*)&object
->IDirect3DBaseTexture9_iface
;
812 static HRESULT WINAPI
d3d9_device_CreateCubeTexture(IDirect3DDevice9Ex
*iface
,
813 UINT edge_length
, UINT levels
, DWORD usage
, D3DFORMAT format
, D3DPOOL pool
,
814 IDirect3DCubeTexture9
**texture
, HANDLE
*shared_handle
)
816 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
817 struct d3d9_texture
*object
;
820 TRACE("iface %p, edge_length %u, levels %u, usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
821 iface
, edge_length
, levels
, usage
, format
, pool
, texture
, shared_handle
);
824 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
826 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
828 return D3DERR_OUTOFVIDEOMEMORY
;
830 hr
= cubetexture_init(object
, device
, edge_length
, levels
, usage
, format
, pool
);
833 WARN("Failed to initialize cube texture, hr %#x.\n", hr
);
834 HeapFree(GetProcessHeap(), 0, object
);
838 TRACE("Created cube texture %p.\n", object
);
839 *texture
= (IDirect3DCubeTexture9
*)&object
->IDirect3DBaseTexture9_iface
;
844 static HRESULT WINAPI
d3d9_device_CreateVertexBuffer(IDirect3DDevice9Ex
*iface
, UINT size
,
845 DWORD usage
, DWORD fvf
, D3DPOOL pool
, IDirect3DVertexBuffer9
**buffer
,
846 HANDLE
*shared_handle
)
848 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
849 struct d3d9_vertexbuffer
*object
;
852 TRACE("iface %p, size %u, usage %#x, fvf %#x, pool %#x, buffer %p, shared_handle %p.\n",
853 iface
, size
, usage
, fvf
, pool
, buffer
, shared_handle
);
856 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
858 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
860 return D3DERR_OUTOFVIDEOMEMORY
;
862 hr
= vertexbuffer_init(object
, device
, size
, usage
, fvf
, pool
);
865 WARN("Failed to initialize vertex buffer, hr %#x.\n", hr
);
866 HeapFree(GetProcessHeap(), 0, object
);
870 TRACE("Created vertex buffer %p.\n", object
);
871 *buffer
= &object
->IDirect3DVertexBuffer9_iface
;
876 static HRESULT WINAPI
d3d9_device_CreateIndexBuffer(IDirect3DDevice9Ex
*iface
, UINT size
,
877 DWORD usage
, D3DFORMAT format
, D3DPOOL pool
, IDirect3DIndexBuffer9
**buffer
,
878 HANDLE
*shared_handle
)
880 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
881 struct d3d9_indexbuffer
*object
;
884 TRACE("iface %p, size %u, usage %#x, format %#x, pool %#x, buffer %p, shared_handle %p.\n",
885 iface
, size
, usage
, format
, pool
, buffer
, shared_handle
);
888 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
890 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
892 return D3DERR_OUTOFVIDEOMEMORY
;
894 hr
= indexbuffer_init(object
, device
, size
, usage
, format
, pool
);
897 WARN("Failed to initialize index buffer, hr %#x.\n", hr
);
898 HeapFree(GetProcessHeap(), 0, object
);
902 TRACE("Created index buffer %p.\n", object
);
903 *buffer
= &object
->IDirect3DIndexBuffer9_iface
;
908 static HRESULT
d3d9_device_create_surface(struct d3d9_device
*device
, UINT width
, UINT height
,
909 D3DFORMAT format
, DWORD flags
, IDirect3DSurface9
**surface
, UINT usage
, D3DPOOL pool
,
910 D3DMULTISAMPLE_TYPE multisample_type
, DWORD multisample_quality
)
912 struct d3d9_surface
*object
;
915 TRACE("device %p, width %u, height %u, format %#x, flags %#x, surface %p.\n"
916 "usage %#x, pool %#x, multisample_type %#x, multisample_quality %u.\n",
917 device
, width
, height
, format
, flags
, surface
, usage
, pool
,
918 multisample_type
, multisample_quality
);
920 if (!(object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
))))
922 FIXME("Failed to allocate surface memory.\n");
923 return D3DERR_OUTOFVIDEOMEMORY
;
926 if (FAILED(hr
= surface_init(object
, device
, width
, height
, format
,
927 flags
, usage
, pool
, multisample_type
, multisample_quality
)))
929 WARN("Failed to initialize surface, hr %#x.\n", hr
);
930 HeapFree(GetProcessHeap(), 0, object
);
934 TRACE("Created surface %p.\n", object
);
935 *surface
= &object
->IDirect3DSurface9_iface
;
940 static HRESULT WINAPI
d3d9_device_CreateRenderTarget(IDirect3DDevice9Ex
*iface
, UINT width
, UINT height
,
941 D3DFORMAT format
, D3DMULTISAMPLE_TYPE multisample_type
, DWORD multisample_quality
,
942 BOOL lockable
, IDirect3DSurface9
**surface
, HANDLE
*shared_handle
)
944 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
947 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u.\n"
948 "lockable %#x, surface %p, shared_handle %p.\n",
949 iface
, width
, height
, format
, multisample_type
, multisample_quality
,
950 lockable
, surface
, shared_handle
);
953 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
956 flags
|= WINED3D_SURFACE_MAPPABLE
;
958 return d3d9_device_create_surface(device
, width
, height
, format
, flags
, surface
,
959 D3DUSAGE_RENDERTARGET
, D3DPOOL_DEFAULT
, multisample_type
, multisample_quality
);
962 static HRESULT WINAPI
d3d9_device_CreateDepthStencilSurface(IDirect3DDevice9Ex
*iface
, UINT width
, UINT height
,
963 D3DFORMAT format
, D3DMULTISAMPLE_TYPE multisample_type
, DWORD multisample_quality
,
964 BOOL discard
, IDirect3DSurface9
**surface
, HANDLE
*shared_handle
)
966 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
967 DWORD flags
= WINED3D_SURFACE_MAPPABLE
;
969 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u.\n"
970 "discard %#x, surface %p, shared_handle %p.\n",
971 iface
, width
, height
, format
, multisample_type
, multisample_quality
,
972 discard
, surface
, shared_handle
);
975 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
978 flags
|= WINED3D_SURFACE_DISCARD
;
980 return d3d9_device_create_surface(device
, width
, height
, format
, flags
, surface
,
981 D3DUSAGE_DEPTHSTENCIL
, D3DPOOL_DEFAULT
, multisample_type
, multisample_quality
);
985 static HRESULT WINAPI
d3d9_device_UpdateSurface(IDirect3DDevice9Ex
*iface
,
986 IDirect3DSurface9
*src_surface
, const RECT
*src_rect
,
987 IDirect3DSurface9
*dst_surface
, const POINT
*dst_point
)
989 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
990 struct d3d9_surface
*src
= unsafe_impl_from_IDirect3DSurface9(src_surface
);
991 struct d3d9_surface
*dst
= unsafe_impl_from_IDirect3DSurface9(dst_surface
);
994 TRACE("iface %p, src_surface %p, src_rect %p, dst_surface %p, dst_point %p.\n",
995 iface
, src_surface
, src_rect
, dst_surface
, dst_point
);
997 wined3d_mutex_lock();
998 hr
= wined3d_device_update_surface(device
->wined3d_device
, src
->wined3d_surface
, src_rect
,
999 dst
->wined3d_surface
, dst_point
);
1000 wined3d_mutex_unlock();
1005 static HRESULT WINAPI
d3d9_device_UpdateTexture(IDirect3DDevice9Ex
*iface
,
1006 IDirect3DBaseTexture9
*src_texture
, IDirect3DBaseTexture9
*dst_texture
)
1008 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1009 struct d3d9_texture
*src_impl
, *dst_impl
;
1012 TRACE("iface %p, src_texture %p, dst_texture %p.\n", iface
, src_texture
, dst_texture
);
1014 src_impl
= unsafe_impl_from_IDirect3DBaseTexture9(src_texture
);
1015 dst_impl
= unsafe_impl_from_IDirect3DBaseTexture9(dst_texture
);
1017 wined3d_mutex_lock();
1018 hr
= wined3d_device_update_texture(device
->wined3d_device
,
1019 src_impl
->wined3d_texture
, dst_impl
->wined3d_texture
);
1020 wined3d_mutex_unlock();
1025 static HRESULT WINAPI
d3d9_device_GetRenderTargetData(IDirect3DDevice9Ex
*iface
,
1026 IDirect3DSurface9
*render_target
, IDirect3DSurface9
*dst_surface
)
1028 struct d3d9_surface
*rt_impl
= unsafe_impl_from_IDirect3DSurface9(render_target
);
1029 struct d3d9_surface
*dst_impl
= unsafe_impl_from_IDirect3DSurface9(dst_surface
);
1032 TRACE("iface %p, render_target %p, dst_surface %p.\n", iface
, render_target
, dst_surface
);
1034 wined3d_mutex_lock();
1035 hr
= wined3d_surface_get_render_target_data(dst_impl
->wined3d_surface
, rt_impl
->wined3d_surface
);
1036 wined3d_mutex_unlock();
1041 static HRESULT WINAPI
d3d9_device_GetFrontBufferData(IDirect3DDevice9Ex
*iface
,
1042 UINT swapchain
, IDirect3DSurface9
*dst_surface
)
1044 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1045 struct d3d9_surface
*dst_impl
= unsafe_impl_from_IDirect3DSurface9(dst_surface
);
1048 TRACE("iface %p, swapchain %u, dst_surface %p.\n", iface
, swapchain
, dst_surface
);
1050 wined3d_mutex_lock();
1051 hr
= wined3d_device_get_front_buffer_data(device
->wined3d_device
, swapchain
, dst_impl
->wined3d_surface
);
1052 wined3d_mutex_unlock();
1057 static HRESULT WINAPI
d3d9_device_StretchRect(IDirect3DDevice9Ex
*iface
, IDirect3DSurface9
*src_surface
,
1058 const RECT
*src_rect
, IDirect3DSurface9
*dst_surface
, const RECT
*dst_rect
, D3DTEXTUREFILTERTYPE filter
)
1060 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1061 struct d3d9_surface
*src
= unsafe_impl_from_IDirect3DSurface9(src_surface
);
1062 struct d3d9_surface
*dst
= unsafe_impl_from_IDirect3DSurface9(dst_surface
);
1063 HRESULT hr
= D3DERR_INVALIDCALL
;
1064 struct wined3d_resource_desc src_desc
, dst_desc
;
1065 struct wined3d_resource
*wined3d_resource
;
1067 TRACE("iface %p, src_surface %p, src_rect %p, dst_surface %p, dst_rect %p, filter %#x.\n",
1068 iface
, src_surface
, src_rect
, dst_surface
, dst_rect
, filter
);
1070 wined3d_mutex_lock();
1071 wined3d_resource
= wined3d_surface_get_resource(dst
->wined3d_surface
);
1072 wined3d_resource_get_desc(wined3d_resource
, &dst_desc
);
1074 wined3d_resource
= wined3d_surface_get_resource(src
->wined3d_surface
);
1075 wined3d_resource_get_desc(wined3d_resource
, &src_desc
);
1077 if (src_desc
.usage
& WINED3DUSAGE_DEPTHSTENCIL
)
1079 if (device
->in_scene
)
1081 WARN("Rejecting depth / stencil blit while in scene.\n");
1087 if (src_rect
->left
|| src_rect
->top
|| src_rect
->right
!= src_desc
.width
1088 || src_rect
->bottom
!= src_desc
.height
)
1090 WARN("Rejecting depth / stencil blit with invalid source rect %s.\n",
1091 wine_dbgstr_rect(src_rect
));
1097 if (dst_rect
->left
|| dst_rect
->top
|| dst_rect
->right
!= dst_desc
.width
1098 || dst_rect
->bottom
!= dst_desc
.height
)
1100 WARN("Rejecting depth / stencil blit with invalid destination rect %s.\n",
1101 wine_dbgstr_rect(dst_rect
));
1105 if (src_desc
.width
!= dst_desc
.width
|| src_desc
.height
!= dst_desc
.height
)
1107 WARN("Rejecting depth / stencil blit with mismatched surface sizes.\n");
1112 hr
= wined3d_surface_blt(dst
->wined3d_surface
, dst_rect
, src
->wined3d_surface
, src_rect
, 0, NULL
, filter
);
1113 if (hr
== WINEDDERR_INVALIDRECT
)
1114 hr
= D3DERR_INVALIDCALL
;
1117 wined3d_mutex_unlock();
1121 static HRESULT WINAPI
d3d9_device_ColorFill(IDirect3DDevice9Ex
*iface
,
1122 IDirect3DSurface9
*surface
, const RECT
*rect
, D3DCOLOR color
)
1124 const struct wined3d_color c
=
1126 ((color
>> 16) & 0xff) / 255.0f
,
1127 ((color
>> 8) & 0xff) / 255.0f
,
1128 (color
& 0xff) / 255.0f
,
1129 ((color
>> 24) & 0xff) / 255.0f
,
1131 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1132 struct d3d9_surface
*surface_impl
= unsafe_impl_from_IDirect3DSurface9(surface
);
1133 struct wined3d_resource
*wined3d_resource
;
1134 struct wined3d_resource_desc desc
;
1137 TRACE("iface %p, surface %p, rect %p, color 0x%08x.\n", iface
, surface
, rect
, color
);
1139 wined3d_mutex_lock();
1141 wined3d_resource
= wined3d_surface_get_resource(surface_impl
->wined3d_surface
);
1142 wined3d_resource_get_desc(wined3d_resource
, &desc
);
1144 /* This method is only allowed with surfaces that are render targets, or
1145 * offscreen plain surfaces in D3DPOOL_DEFAULT. */
1146 if (!(desc
.usage
& WINED3DUSAGE_RENDERTARGET
) && desc
.pool
!= WINED3D_POOL_DEFAULT
)
1148 wined3d_mutex_unlock();
1149 WARN("Surface is not a render target, or not a stand-alone D3DPOOL_DEFAULT surface\n");
1150 return D3DERR_INVALIDCALL
;
1153 /* Colorfill can only be used on rendertarget surfaces, or offscreen plain surfaces in D3DPOOL_DEFAULT */
1154 hr
= wined3d_device_color_fill(device
->wined3d_device
, surface_impl
->wined3d_surface
, rect
, &c
);
1156 wined3d_mutex_unlock();
1161 static HRESULT WINAPI
d3d9_device_CreateOffscreenPlainSurface(IDirect3DDevice9Ex
*iface
,
1162 UINT width
, UINT height
, D3DFORMAT format
, D3DPOOL pool
, IDirect3DSurface9
**surface
,
1163 HANDLE
*shared_handle
)
1165 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1167 TRACE("iface %p, width %u, height %u, format %#x, pool %#x, surface %p, shared_handle %p.\n",
1168 iface
, width
, height
, format
, pool
, surface
, shared_handle
);
1171 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
1173 if (pool
== D3DPOOL_MANAGED
)
1175 WARN("Attempting to create a managed offscreen plain surface.\n");
1176 return D3DERR_INVALIDCALL
;
1178 /* FIXME: Offscreen surfaces are supposed to be always lockable,
1179 * regardless of the pool they're created in. Should we set dynamic usage
1181 return d3d9_device_create_surface(device
, width
, height
, format
,
1182 WINED3D_SURFACE_MAPPABLE
, surface
, 0, pool
, D3DMULTISAMPLE_NONE
, 0);
1185 static HRESULT WINAPI
d3d9_device_SetRenderTarget(IDirect3DDevice9Ex
*iface
, DWORD idx
, IDirect3DSurface9
*surface
)
1187 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1188 struct d3d9_surface
*surface_impl
= unsafe_impl_from_IDirect3DSurface9(surface
);
1191 TRACE("iface %p, idx %u, surface %p.\n", iface
, idx
, surface
);
1193 if (idx
>= D3D9_MAX_SIMULTANEOUS_RENDERTARGETS
)
1195 WARN("Invalid index %u specified.\n", idx
);
1196 return D3DERR_INVALIDCALL
;
1199 wined3d_mutex_lock();
1200 hr
= wined3d_device_set_render_target(device
->wined3d_device
, idx
,
1201 surface_impl
? surface_impl
->wined3d_surface
: NULL
, TRUE
);
1202 wined3d_mutex_unlock();
1207 static HRESULT WINAPI
d3d9_device_GetRenderTarget(IDirect3DDevice9Ex
*iface
, DWORD idx
, IDirect3DSurface9
**surface
)
1209 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1210 struct wined3d_surface
*wined3d_surface
;
1211 struct d3d9_surface
*surface_impl
;
1212 HRESULT hr
= D3D_OK
;
1214 TRACE("iface %p, idx %u, surface %p.\n", iface
, idx
, surface
);
1217 return D3DERR_INVALIDCALL
;
1219 if (idx
>= D3D9_MAX_SIMULTANEOUS_RENDERTARGETS
)
1221 WARN("Invalid index %u specified.\n", idx
);
1222 return D3DERR_INVALIDCALL
;
1225 wined3d_mutex_lock();
1226 if ((wined3d_surface
= wined3d_device_get_render_target(device
->wined3d_device
, idx
)))
1228 surface_impl
= wined3d_surface_get_parent(wined3d_surface
);
1229 *surface
= &surface_impl
->IDirect3DSurface9_iface
;
1230 IDirect3DSurface9_AddRef(*surface
);
1234 hr
= WINED3DERR_NOTFOUND
;
1237 wined3d_mutex_unlock();
1242 static HRESULT WINAPI
d3d9_device_SetDepthStencilSurface(IDirect3DDevice9Ex
*iface
, IDirect3DSurface9
*depth_stencil
)
1244 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1245 struct d3d9_surface
*ds_impl
= unsafe_impl_from_IDirect3DSurface9(depth_stencil
);
1247 TRACE("iface %p, depth_stencil %p.\n", iface
, depth_stencil
);
1249 wined3d_mutex_lock();
1250 wined3d_device_set_depth_stencil(device
->wined3d_device
, ds_impl
? ds_impl
->wined3d_surface
: NULL
);
1251 wined3d_mutex_unlock();
1256 static HRESULT WINAPI
d3d9_device_GetDepthStencilSurface(IDirect3DDevice9Ex
*iface
, IDirect3DSurface9
**depth_stencil
)
1258 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1259 struct wined3d_surface
*wined3d_surface
;
1260 struct d3d9_surface
*surface_impl
;
1261 HRESULT hr
= D3D_OK
;
1263 TRACE("iface %p, depth_stencil %p.\n", iface
, depth_stencil
);
1266 return D3DERR_INVALIDCALL
;
1268 wined3d_mutex_lock();
1269 if ((wined3d_surface
= wined3d_device_get_depth_stencil(device
->wined3d_device
)))
1271 surface_impl
= wined3d_surface_get_parent(wined3d_surface
);
1272 *depth_stencil
= &surface_impl
->IDirect3DSurface9_iface
;
1273 IDirect3DSurface9_AddRef(*depth_stencil
);
1277 hr
= WINED3DERR_NOTFOUND
;
1278 *depth_stencil
= NULL
;
1280 wined3d_mutex_unlock();
1285 static HRESULT WINAPI
d3d9_device_BeginScene(IDirect3DDevice9Ex
*iface
)
1287 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1290 TRACE("iface %p.\n", iface
);
1292 wined3d_mutex_lock();
1293 if (SUCCEEDED(hr
= wined3d_device_begin_scene(device
->wined3d_device
)))
1294 device
->in_scene
= TRUE
;
1295 wined3d_mutex_unlock();
1300 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_device_EndScene(IDirect3DDevice9Ex
*iface
)
1302 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1305 TRACE("iface %p.\n", iface
);
1307 wined3d_mutex_lock();
1308 if (SUCCEEDED(hr
= wined3d_device_end_scene(device
->wined3d_device
)))
1309 device
->in_scene
= FALSE
;
1310 wined3d_mutex_unlock();
1315 static HRESULT WINAPI
d3d9_device_Clear(IDirect3DDevice9Ex
*iface
, DWORD rect_count
,
1316 const D3DRECT
*rects
, DWORD flags
, D3DCOLOR color
, float z
, DWORD stencil
)
1318 const struct wined3d_color c
=
1320 ((color
>> 16) & 0xff) / 255.0f
,
1321 ((color
>> 8) & 0xff) / 255.0f
,
1322 (color
& 0xff) / 255.0f
,
1323 ((color
>> 24) & 0xff) / 255.0f
,
1325 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1328 TRACE("iface %p, rect_count %u, rects %p, flags %#x, color 0x%08x, z %.8e, stencil %u.\n",
1329 iface
, rect_count
, rects
, flags
, color
, z
, stencil
);
1331 wined3d_mutex_lock();
1332 hr
= wined3d_device_clear(device
->wined3d_device
, rect_count
, (const RECT
*)rects
, flags
, &c
, z
, stencil
);
1333 wined3d_mutex_unlock();
1338 static HRESULT WINAPI
d3d9_device_SetTransform(IDirect3DDevice9Ex
*iface
,
1339 D3DTRANSFORMSTATETYPE state
, const D3DMATRIX
*matrix
)
1341 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1343 TRACE("iface %p, state %#x, matrix %p.\n", iface
, state
, matrix
);
1345 /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
1346 wined3d_mutex_lock();
1347 wined3d_device_set_transform(device
->wined3d_device
, state
, (const struct wined3d_matrix
*)matrix
);
1348 wined3d_mutex_unlock();
1353 static HRESULT WINAPI
d3d9_device_GetTransform(IDirect3DDevice9Ex
*iface
,
1354 D3DTRANSFORMSTATETYPE state
, D3DMATRIX
*matrix
)
1356 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1358 TRACE("iface %p, state %#x, matrix %p.\n", iface
, state
, matrix
);
1360 /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
1361 wined3d_mutex_lock();
1362 wined3d_device_get_transform(device
->wined3d_device
, state
, (struct wined3d_matrix
*)matrix
);
1363 wined3d_mutex_unlock();
1368 static HRESULT WINAPI
d3d9_device_MultiplyTransform(IDirect3DDevice9Ex
*iface
,
1369 D3DTRANSFORMSTATETYPE state
, const D3DMATRIX
*matrix
)
1371 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1373 TRACE("iface %p, state %#x, matrix %p.\n", iface
, state
, matrix
);
1375 /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
1376 wined3d_mutex_lock();
1377 wined3d_device_multiply_transform(device
->wined3d_device
, state
, (const struct wined3d_matrix
*)matrix
);
1378 wined3d_mutex_unlock();
1383 static HRESULT WINAPI
d3d9_device_SetViewport(IDirect3DDevice9Ex
*iface
, const D3DVIEWPORT9
*viewport
)
1385 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1387 TRACE("iface %p, viewport %p.\n", iface
, viewport
);
1389 /* Note: D3DVIEWPORT9 is compatible with struct wined3d_viewport. */
1390 wined3d_mutex_lock();
1391 wined3d_device_set_viewport(device
->wined3d_device
, (const struct wined3d_viewport
*)viewport
);
1392 wined3d_mutex_unlock();
1397 static HRESULT WINAPI
d3d9_device_GetViewport(IDirect3DDevice9Ex
*iface
, D3DVIEWPORT9
*viewport
)
1399 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1401 TRACE("iface %p, viewport %p.\n", iface
, viewport
);
1403 /* Note: D3DVIEWPORT9 is compatible with struct wined3d_viewport. */
1404 wined3d_mutex_lock();
1405 wined3d_device_get_viewport(device
->wined3d_device
, (struct wined3d_viewport
*)viewport
);
1406 wined3d_mutex_unlock();
1411 static HRESULT WINAPI
d3d9_device_SetMaterial(IDirect3DDevice9Ex
*iface
, const D3DMATERIAL9
*material
)
1413 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1415 TRACE("iface %p, material %p.\n", iface
, material
);
1417 /* Note: D3DMATERIAL9 is compatible with struct wined3d_material. */
1418 wined3d_mutex_lock();
1419 wined3d_device_set_material(device
->wined3d_device
, (const struct wined3d_material
*)material
);
1420 wined3d_mutex_unlock();
1425 static HRESULT WINAPI
d3d9_device_GetMaterial(IDirect3DDevice9Ex
*iface
, D3DMATERIAL9
*material
)
1427 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1429 TRACE("iface %p, material %p.\n", iface
, material
);
1431 /* Note: D3DMATERIAL9 is compatible with struct wined3d_material. */
1432 wined3d_mutex_lock();
1433 wined3d_device_get_material(device
->wined3d_device
, (struct wined3d_material
*)material
);
1434 wined3d_mutex_unlock();
1439 static HRESULT WINAPI
d3d9_device_SetLight(IDirect3DDevice9Ex
*iface
, DWORD index
, const D3DLIGHT9
*light
)
1441 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1444 TRACE("iface %p, index %u, light %p.\n", iface
, index
, light
);
1446 /* Note: D3DLIGHT9 is compatible with struct wined3d_light. */
1447 wined3d_mutex_lock();
1448 hr
= wined3d_device_set_light(device
->wined3d_device
, index
, (const struct wined3d_light
*)light
);
1449 wined3d_mutex_unlock();
1454 static HRESULT WINAPI
d3d9_device_GetLight(IDirect3DDevice9Ex
*iface
, DWORD index
, D3DLIGHT9
*light
)
1456 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1459 TRACE("iface %p, index %u, light %p.\n", iface
, index
, light
);
1461 /* Note: D3DLIGHT9 is compatible with struct wined3d_light. */
1462 wined3d_mutex_lock();
1463 hr
= wined3d_device_get_light(device
->wined3d_device
, index
, (struct wined3d_light
*)light
);
1464 wined3d_mutex_unlock();
1469 static HRESULT WINAPI
d3d9_device_LightEnable(IDirect3DDevice9Ex
*iface
, DWORD index
, BOOL enable
)
1471 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1474 TRACE("iface %p, index %u, enable %#x.\n", iface
, index
, enable
);
1476 wined3d_mutex_lock();
1477 hr
= wined3d_device_set_light_enable(device
->wined3d_device
, index
, enable
);
1478 wined3d_mutex_unlock();
1483 static HRESULT WINAPI
d3d9_device_GetLightEnable(IDirect3DDevice9Ex
*iface
, DWORD index
, BOOL
*enable
)
1485 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1488 TRACE("iface %p, index %u, enable %p.\n", iface
, index
, enable
);
1490 wined3d_mutex_lock();
1491 hr
= wined3d_device_get_light_enable(device
->wined3d_device
, index
, enable
);
1492 wined3d_mutex_unlock();
1497 static HRESULT WINAPI
d3d9_device_SetClipPlane(IDirect3DDevice9Ex
*iface
, DWORD index
, const float *plane
)
1499 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1502 TRACE("iface %p, index %u, plane %p.\n", iface
, index
, plane
);
1504 wined3d_mutex_lock();
1505 hr
= wined3d_device_set_clip_plane(device
->wined3d_device
, index
, (const struct wined3d_vec4
*)plane
);
1506 wined3d_mutex_unlock();
1511 static HRESULT WINAPI
d3d9_device_GetClipPlane(IDirect3DDevice9Ex
*iface
, DWORD index
, float *plane
)
1513 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1516 TRACE("iface %p, index %u, plane %p.\n", iface
, index
, plane
);
1518 wined3d_mutex_lock();
1519 hr
= wined3d_device_get_clip_plane(device
->wined3d_device
, index
, (struct wined3d_vec4
*)plane
);
1520 wined3d_mutex_unlock();
1525 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_device_SetRenderState(IDirect3DDevice9Ex
*iface
,
1526 D3DRENDERSTATETYPE state
, DWORD value
)
1528 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1530 TRACE("iface %p, state %#x, value %#x.\n", iface
, state
, value
);
1532 wined3d_mutex_lock();
1533 wined3d_device_set_render_state(device
->wined3d_device
, state
, value
);
1534 wined3d_mutex_unlock();
1539 static HRESULT WINAPI
d3d9_device_GetRenderState(IDirect3DDevice9Ex
*iface
,
1540 D3DRENDERSTATETYPE state
, DWORD
*value
)
1542 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1544 TRACE("iface %p, state %#x, value %p.\n", iface
, state
, value
);
1546 wined3d_mutex_lock();
1547 *value
= wined3d_device_get_render_state(device
->wined3d_device
, state
);
1548 wined3d_mutex_unlock();
1553 static HRESULT WINAPI
d3d9_device_CreateStateBlock(IDirect3DDevice9Ex
*iface
,
1554 D3DSTATEBLOCKTYPE type
, IDirect3DStateBlock9
**stateblock
)
1556 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1557 struct d3d9_stateblock
*object
;
1560 TRACE("iface %p, type %#x, stateblock %p.\n", iface
, type
, stateblock
);
1562 if (type
!= D3DSBT_ALL
&& type
!= D3DSBT_PIXELSTATE
&& type
!= D3DSBT_VERTEXSTATE
)
1564 WARN("Unexpected stateblock type, returning D3DERR_INVALIDCALL.\n");
1565 return D3DERR_INVALIDCALL
;
1568 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
1570 return E_OUTOFMEMORY
;
1572 hr
= stateblock_init(object
, device
, type
, NULL
);
1575 WARN("Failed to initialize stateblock, hr %#x.\n", hr
);
1576 HeapFree(GetProcessHeap(), 0, object
);
1580 TRACE("Created stateblock %p.\n", object
);
1581 *stateblock
= &object
->IDirect3DStateBlock9_iface
;
1586 static HRESULT WINAPI
d3d9_device_BeginStateBlock(IDirect3DDevice9Ex
*iface
)
1588 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1591 TRACE("iface %p.\n", iface
);
1593 wined3d_mutex_lock();
1594 hr
= wined3d_device_begin_stateblock(device
->wined3d_device
);
1595 wined3d_mutex_unlock();
1600 static HRESULT WINAPI
d3d9_device_EndStateBlock(IDirect3DDevice9Ex
*iface
, IDirect3DStateBlock9
**stateblock
)
1602 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1603 struct wined3d_stateblock
*wined3d_stateblock
;
1604 struct d3d9_stateblock
*object
;
1607 TRACE("iface %p, stateblock %p.\n", iface
, stateblock
);
1609 wined3d_mutex_lock();
1610 hr
= wined3d_device_end_stateblock(device
->wined3d_device
, &wined3d_stateblock
);
1611 wined3d_mutex_unlock();
1614 WARN("IWineD3DDevice_EndStateBlock() failed, hr %#x.\n", hr
);
1618 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
1621 wined3d_mutex_lock();
1622 wined3d_stateblock_decref(wined3d_stateblock
);
1623 wined3d_mutex_unlock();
1624 return E_OUTOFMEMORY
;
1627 hr
= stateblock_init(object
, device
, 0, wined3d_stateblock
);
1630 WARN("Failed to initialize stateblock, hr %#x.\n", hr
);
1631 wined3d_mutex_lock();
1632 wined3d_stateblock_decref(wined3d_stateblock
);
1633 wined3d_mutex_unlock();
1634 HeapFree(GetProcessHeap(), 0, object
);
1638 TRACE("Created stateblock %p.\n", object
);
1639 *stateblock
= &object
->IDirect3DStateBlock9_iface
;
1644 static HRESULT WINAPI
d3d9_device_SetClipStatus(IDirect3DDevice9Ex
*iface
, const D3DCLIPSTATUS9
*clip_status
)
1646 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1649 TRACE("iface %p, clip_status %p.\n", iface
, clip_status
);
1651 wined3d_mutex_lock();
1652 hr
= wined3d_device_set_clip_status(device
->wined3d_device
, (const struct wined3d_clip_status
*)clip_status
);
1653 wined3d_mutex_unlock();
1658 static HRESULT WINAPI
d3d9_device_GetClipStatus(IDirect3DDevice9Ex
*iface
, D3DCLIPSTATUS9
*clip_status
)
1660 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1663 TRACE("iface %p, clip_status %p.\n", iface
, clip_status
);
1665 wined3d_mutex_lock();
1666 hr
= wined3d_device_get_clip_status(device
->wined3d_device
, (struct wined3d_clip_status
*)clip_status
);
1667 wined3d_mutex_unlock();
1672 static HRESULT WINAPI
d3d9_device_GetTexture(IDirect3DDevice9Ex
*iface
, DWORD stage
, IDirect3DBaseTexture9
**texture
)
1674 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1675 struct wined3d_texture
*wined3d_texture
= NULL
;
1676 struct d3d9_texture
*texture_impl
;
1678 TRACE("iface %p, stage %u, texture %p.\n", iface
, stage
, texture
);
1681 return D3DERR_INVALIDCALL
;
1683 wined3d_mutex_lock();
1684 if ((wined3d_texture
= wined3d_device_get_texture(device
->wined3d_device
, stage
)))
1686 texture_impl
= wined3d_texture_get_parent(wined3d_texture
);
1687 *texture
= &texture_impl
->IDirect3DBaseTexture9_iface
;
1688 IDirect3DBaseTexture9_AddRef(*texture
);
1694 wined3d_mutex_unlock();
1699 static HRESULT WINAPI
d3d9_device_SetTexture(IDirect3DDevice9Ex
*iface
, DWORD stage
, IDirect3DBaseTexture9
*texture
)
1701 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1702 struct d3d9_texture
*texture_impl
;
1705 TRACE("iface %p, stage %u, texture %p.\n", iface
, stage
, texture
);
1707 texture_impl
= unsafe_impl_from_IDirect3DBaseTexture9(texture
);
1709 wined3d_mutex_lock();
1710 hr
= wined3d_device_set_texture(device
->wined3d_device
, stage
,
1711 texture_impl
? texture_impl
->wined3d_texture
: NULL
);
1712 wined3d_mutex_unlock();
1717 static const enum wined3d_texture_stage_state tss_lookup
[] =
1719 WINED3D_TSS_INVALID
, /* 0, unused */
1720 WINED3D_TSS_COLOR_OP
, /* 1, D3DTSS_COLOROP */
1721 WINED3D_TSS_COLOR_ARG1
, /* 2, D3DTSS_COLORARG1 */
1722 WINED3D_TSS_COLOR_ARG2
, /* 3, D3DTSS_COLORARG2 */
1723 WINED3D_TSS_ALPHA_OP
, /* 4, D3DTSS_ALPHAOP */
1724 WINED3D_TSS_ALPHA_ARG1
, /* 5, D3DTSS_ALPHAARG1 */
1725 WINED3D_TSS_ALPHA_ARG2
, /* 6, D3DTSS_ALPHAARG2 */
1726 WINED3D_TSS_BUMPENV_MAT00
, /* 7, D3DTSS_BUMPENVMAT00 */
1727 WINED3D_TSS_BUMPENV_MAT01
, /* 8, D3DTSS_BUMPENVMAT01 */
1728 WINED3D_TSS_BUMPENV_MAT10
, /* 9, D3DTSS_BUMPENVMAT10 */
1729 WINED3D_TSS_BUMPENV_MAT11
, /* 10, D3DTSS_BUMPENVMAT11 */
1730 WINED3D_TSS_TEXCOORD_INDEX
, /* 11, D3DTSS_TEXCOORDINDEX */
1731 WINED3D_TSS_INVALID
, /* 12, unused */
1732 WINED3D_TSS_INVALID
, /* 13, unused */
1733 WINED3D_TSS_INVALID
, /* 14, unused */
1734 WINED3D_TSS_INVALID
, /* 15, unused */
1735 WINED3D_TSS_INVALID
, /* 16, unused */
1736 WINED3D_TSS_INVALID
, /* 17, unused */
1737 WINED3D_TSS_INVALID
, /* 18, unused */
1738 WINED3D_TSS_INVALID
, /* 19, unused */
1739 WINED3D_TSS_INVALID
, /* 20, unused */
1740 WINED3D_TSS_INVALID
, /* 21, unused */
1741 WINED3D_TSS_BUMPENV_LSCALE
, /* 22, D3DTSS_BUMPENVLSCALE */
1742 WINED3D_TSS_BUMPENV_LOFFSET
, /* 23, D3DTSS_BUMPENVLOFFSET */
1743 WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS
, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
1744 WINED3D_TSS_INVALID
, /* 25, unused */
1745 WINED3D_TSS_COLOR_ARG0
, /* 26, D3DTSS_COLORARG0 */
1746 WINED3D_TSS_ALPHA_ARG0
, /* 27, D3DTSS_ALPHAARG0 */
1747 WINED3D_TSS_RESULT_ARG
, /* 28, D3DTSS_RESULTARG */
1748 WINED3D_TSS_INVALID
, /* 29, unused */
1749 WINED3D_TSS_INVALID
, /* 30, unused */
1750 WINED3D_TSS_INVALID
, /* 31, unused */
1751 WINED3D_TSS_CONSTANT
, /* 32, D3DTSS_CONSTANT */
1754 static HRESULT WINAPI
d3d9_device_GetTextureStageState(IDirect3DDevice9Ex
*iface
,
1755 DWORD stage
, D3DTEXTURESTAGESTATETYPE state
, DWORD
*value
)
1757 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1759 TRACE("iface %p, stage %u, state %#x, value %p.\n", iface
, stage
, state
, value
);
1761 if (state
>= sizeof(tss_lookup
) / sizeof(*tss_lookup
))
1763 WARN("Invalid state %#x passed.\n", state
);
1767 wined3d_mutex_lock();
1768 *value
= wined3d_device_get_texture_stage_state(device
->wined3d_device
, stage
, tss_lookup
[state
]);
1769 wined3d_mutex_unlock();
1774 static HRESULT WINAPI
d3d9_device_SetTextureStageState(IDirect3DDevice9Ex
*iface
,
1775 DWORD stage
, D3DTEXTURESTAGESTATETYPE state
, DWORD value
)
1777 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1779 TRACE("iface %p, stage %u, state %#x, value %#x.\n", iface
, stage
, state
, value
);
1781 if (state
>= sizeof(tss_lookup
) / sizeof(*tss_lookup
))
1783 WARN("Invalid state %#x passed.\n", state
);
1787 wined3d_mutex_lock();
1788 wined3d_device_set_texture_stage_state(device
->wined3d_device
, stage
, tss_lookup
[state
], value
);
1789 wined3d_mutex_unlock();
1794 static HRESULT WINAPI
d3d9_device_GetSamplerState(IDirect3DDevice9Ex
*iface
,
1795 DWORD sampler
, D3DSAMPLERSTATETYPE state
, DWORD
*value
)
1797 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1799 TRACE("iface %p, sampler %u, state %#x, value %p.\n", iface
, sampler
, state
, value
);
1801 wined3d_mutex_lock();
1802 *value
= wined3d_device_get_sampler_state(device
->wined3d_device
, sampler
, state
);
1803 wined3d_mutex_unlock();
1808 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_device_SetSamplerState(IDirect3DDevice9Ex
*iface
,
1809 DWORD sampler
, D3DSAMPLERSTATETYPE state
, DWORD value
)
1811 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1813 TRACE("iface %p, sampler %u, state %#x, value %#x.\n", iface
, sampler
, state
, value
);
1815 wined3d_mutex_lock();
1816 wined3d_device_set_sampler_state(device
->wined3d_device
, sampler
, state
, value
);
1817 wined3d_mutex_unlock();
1822 static HRESULT WINAPI
d3d9_device_ValidateDevice(IDirect3DDevice9Ex
*iface
, DWORD
*pass_count
)
1824 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1827 TRACE("iface %p, pass_count %p.\n", iface
, pass_count
);
1829 wined3d_mutex_lock();
1830 hr
= wined3d_device_validate_device(device
->wined3d_device
, pass_count
);
1831 wined3d_mutex_unlock();
1836 static HRESULT WINAPI
d3d9_device_SetPaletteEntries(IDirect3DDevice9Ex
*iface
,
1837 UINT palette_idx
, const PALETTEENTRY
*entries
)
1839 WARN("iface %p, palette_idx %u, entries %p unimplemented.\n", iface
, palette_idx
, entries
);
1841 /* The d3d9 palette API is non-functional on Windows. Getters and setters are implemented,
1842 * and some drivers allow the creation of P8 surfaces. These surfaces can be copied to
1843 * other P8 surfaces with StretchRect, but cannot be converted to (A)RGB.
1845 * Some older(dx7) cards may have support for P8 textures, but games cannot rely on this. */
1849 static HRESULT WINAPI
d3d9_device_GetPaletteEntries(IDirect3DDevice9Ex
*iface
,
1850 UINT palette_idx
, PALETTEENTRY
*entries
)
1852 FIXME("iface %p, palette_idx %u, entries %p unimplemented.\n", iface
, palette_idx
, entries
);
1854 return D3DERR_INVALIDCALL
;
1857 static HRESULT WINAPI
d3d9_device_SetCurrentTexturePalette(IDirect3DDevice9Ex
*iface
, UINT palette_idx
)
1859 WARN("iface %p, palette_idx %u unimplemented.\n", iface
, palette_idx
);
1864 static HRESULT WINAPI
d3d9_device_GetCurrentTexturePalette(IDirect3DDevice9Ex
*iface
, UINT
*palette_idx
)
1866 FIXME("iface %p, palette_idx %p.\n", iface
, palette_idx
);
1868 return D3DERR_INVALIDCALL
;
1871 static HRESULT WINAPI
d3d9_device_SetScissorRect(IDirect3DDevice9Ex
*iface
, const 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_set_scissor_rect(device
->wined3d_device
, rect
);
1879 wined3d_mutex_unlock();
1884 static HRESULT WINAPI
d3d9_device_GetScissorRect(IDirect3DDevice9Ex
*iface
, RECT
*rect
)
1886 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1888 TRACE("iface %p, rect %p.\n", iface
, rect
);
1890 wined3d_mutex_lock();
1891 wined3d_device_get_scissor_rect(device
->wined3d_device
, rect
);
1892 wined3d_mutex_unlock();
1897 static HRESULT WINAPI
d3d9_device_SetSoftwareVertexProcessing(IDirect3DDevice9Ex
*iface
, BOOL software
)
1899 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1901 TRACE("iface %p, software %#x.\n", iface
, software
);
1903 wined3d_mutex_lock();
1904 wined3d_device_set_software_vertex_processing(device
->wined3d_device
, software
);
1905 wined3d_mutex_unlock();
1910 static BOOL WINAPI
d3d9_device_GetSoftwareVertexProcessing(IDirect3DDevice9Ex
*iface
)
1912 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1915 TRACE("iface %p.\n", iface
);
1917 wined3d_mutex_lock();
1918 ret
= wined3d_device_get_software_vertex_processing(device
->wined3d_device
);
1919 wined3d_mutex_unlock();
1924 static HRESULT WINAPI
d3d9_device_SetNPatchMode(IDirect3DDevice9Ex
*iface
, float segment_count
)
1926 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1929 TRACE("iface %p, segment_count %.8e.\n", iface
, segment_count
);
1931 wined3d_mutex_lock();
1932 hr
= wined3d_device_set_npatch_mode(device
->wined3d_device
, segment_count
);
1933 wined3d_mutex_unlock();
1938 static float WINAPI
d3d9_device_GetNPatchMode(IDirect3DDevice9Ex
*iface
)
1940 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1943 TRACE("iface %p.\n", iface
);
1945 wined3d_mutex_lock();
1946 ret
= wined3d_device_get_npatch_mode(device
->wined3d_device
);
1947 wined3d_mutex_unlock();
1952 static HRESULT WINAPI
d3d9_device_DrawPrimitive(IDirect3DDevice9Ex
*iface
,
1953 D3DPRIMITIVETYPE primitive_type
, UINT start_vertex
, UINT primitive_count
)
1955 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1958 TRACE("iface %p, primitive_type %#x, start_vertex %u, primitive_count %u.\n",
1959 iface
, primitive_type
, start_vertex
, primitive_count
);
1961 wined3d_mutex_lock();
1962 wined3d_device_set_primitive_type(device
->wined3d_device
, primitive_type
);
1963 hr
= wined3d_device_draw_primitive(device
->wined3d_device
, start_vertex
,
1964 vertex_count_from_primitive_count(primitive_type
, primitive_count
));
1965 wined3d_mutex_unlock();
1970 static HRESULT WINAPI
d3d9_device_DrawIndexedPrimitive(IDirect3DDevice9Ex
*iface
,
1971 D3DPRIMITIVETYPE primitive_type
, INT base_vertex_idx
, UINT min_vertex_idx
,
1972 UINT vertex_count
, UINT start_idx
, UINT primitive_count
)
1974 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1977 TRACE("iface %p, primitive_type %#x, base_vertex_idx %u, min_vertex_idx %u,\n"
1978 "vertex_count %u, start_idx %u, primitive_count %u.\n",
1979 iface
, primitive_type
, base_vertex_idx
, min_vertex_idx
,
1980 vertex_count
, start_idx
, primitive_count
);
1982 wined3d_mutex_lock();
1983 wined3d_device_set_base_vertex_index(device
->wined3d_device
, base_vertex_idx
);
1984 wined3d_device_set_primitive_type(device
->wined3d_device
, primitive_type
);
1985 hr
= wined3d_device_draw_indexed_primitive(device
->wined3d_device
, start_idx
,
1986 vertex_count_from_primitive_count(primitive_type
, primitive_count
));
1987 wined3d_mutex_unlock();
1992 static void STDMETHODCALLTYPE
d3d9_null_wined3d_object_destroyed(void *parent
) {}
1994 static const struct wined3d_parent_ops d3d9_null_wined3d_parent_ops
=
1996 d3d9_null_wined3d_object_destroyed
,
1999 /* The caller is responsible for wined3d locking */
2000 static HRESULT
d3d9_device_prepare_vertex_buffer(struct d3d9_device
*device
, UINT min_size
)
2004 if (device
->vertex_buffer_size
< min_size
|| !device
->vertex_buffer
)
2006 UINT size
= max(device
->vertex_buffer_size
* 2, min_size
);
2007 struct wined3d_buffer
*buffer
;
2009 TRACE("Growing vertex buffer to %u bytes\n", size
);
2011 hr
= wined3d_buffer_create_vb(device
->wined3d_device
, size
, WINED3DUSAGE_DYNAMIC
| WINED3DUSAGE_WRITEONLY
,
2012 WINED3D_POOL_DEFAULT
, NULL
, &d3d9_null_wined3d_parent_ops
, &buffer
);
2015 ERR("(%p) wined3d_buffer_create_vb failed with hr = %08x\n", device
, hr
);
2019 if (device
->vertex_buffer
)
2020 wined3d_buffer_decref(device
->vertex_buffer
);
2022 device
->vertex_buffer
= buffer
;
2023 device
->vertex_buffer_size
= size
;
2024 device
->vertex_buffer_pos
= 0;
2029 static HRESULT WINAPI
d3d9_device_DrawPrimitiveUP(IDirect3DDevice9Ex
*iface
,
2030 D3DPRIMITIVETYPE primitive_type
, UINT primitive_count
, const void *data
, UINT stride
)
2032 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2034 UINT vtx_count
= vertex_count_from_primitive_count(primitive_type
, primitive_count
);
2035 UINT size
= vtx_count
* stride
;
2039 TRACE("iface %p, primitive_type %#x, primitive_count %u, data %p, stride %u.\n",
2040 iface
, primitive_type
, primitive_count
, data
, stride
);
2042 if (!primitive_count
)
2044 WARN("primitive_count is 0, returning D3D_OK\n");
2048 wined3d_mutex_lock();
2050 hr
= d3d9_device_prepare_vertex_buffer(device
, size
);
2054 vb_pos
= device
->vertex_buffer_pos
;
2055 align
= vb_pos
% stride
;
2056 if (align
) align
= stride
- align
;
2057 if (vb_pos
+ size
+ align
> device
->vertex_buffer_size
)
2062 hr
= wined3d_buffer_map(device
->vertex_buffer
, vb_pos
, size
, &buffer_data
,
2063 vb_pos
? WINED3D_MAP_NOOVERWRITE
: WINED3D_MAP_DISCARD
);
2066 memcpy(buffer_data
, data
, size
);
2067 wined3d_buffer_unmap(device
->vertex_buffer
);
2068 device
->vertex_buffer_pos
= vb_pos
+ size
;
2070 hr
= wined3d_device_set_stream_source(device
->wined3d_device
, 0, device
->vertex_buffer
, 0, stride
);
2074 wined3d_device_set_primitive_type(device
->wined3d_device
, primitive_type
);
2075 hr
= wined3d_device_draw_primitive(device
->wined3d_device
, vb_pos
/ stride
, vtx_count
);
2076 wined3d_device_set_stream_source(device
->wined3d_device
, 0, NULL
, 0, 0);
2079 wined3d_mutex_unlock();
2083 /* The caller is responsible for wined3d locking */
2084 static HRESULT
d3d9_device_prepare_index_buffer(struct d3d9_device
*device
, UINT min_size
)
2088 if (device
->index_buffer_size
< min_size
|| !device
->index_buffer
)
2090 UINT size
= max(device
->index_buffer_size
* 2, min_size
);
2091 struct wined3d_buffer
*buffer
;
2093 TRACE("Growing index buffer to %u bytes\n", size
);
2095 hr
= wined3d_buffer_create_ib(device
->wined3d_device
, size
, WINED3DUSAGE_DYNAMIC
| WINED3DUSAGE_WRITEONLY
,
2096 WINED3D_POOL_DEFAULT
, NULL
, &d3d9_null_wined3d_parent_ops
, &buffer
);
2099 ERR("(%p) wined3d_buffer_create_ib failed with hr = %08x\n", device
, hr
);
2103 if (device
->index_buffer
)
2104 wined3d_buffer_decref(device
->index_buffer
);
2106 device
->index_buffer
= buffer
;
2107 device
->index_buffer_size
= size
;
2108 device
->index_buffer_pos
= 0;
2113 static HRESULT WINAPI
d3d9_device_DrawIndexedPrimitiveUP(IDirect3DDevice9Ex
*iface
,
2114 D3DPRIMITIVETYPE primitive_type
, UINT min_vertex_idx
, UINT vertex_count
,
2115 UINT primitive_count
, const void *index_data
, D3DFORMAT index_format
,
2116 const void *vertex_data
, UINT vertex_stride
)
2118 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2122 UINT idx_count
= vertex_count_from_primitive_count(primitive_type
, primitive_count
);
2123 UINT idx_fmt_size
= index_format
== D3DFMT_INDEX16
? 2 : 4;
2124 UINT idx_size
= idx_count
* idx_fmt_size
;
2127 UINT vtx_size
= vertex_count
* vertex_stride
;
2130 TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, vertex_count %u, primitive_count %u,\n"
2131 "index_data %p, index_format %#x, vertex_data %p, vertex_stride %u.\n",
2132 iface
, primitive_type
, min_vertex_idx
, vertex_count
, primitive_count
,
2133 index_data
, index_format
, vertex_data
, vertex_stride
);
2135 if (!primitive_count
)
2137 WARN("primitive_count is 0, returning D3D_OK\n");
2141 wined3d_mutex_lock();
2143 hr
= d3d9_device_prepare_vertex_buffer(device
, vtx_size
);
2147 vb_pos
= device
->vertex_buffer_pos
;
2148 align
= vb_pos
% vertex_stride
;
2149 if (align
) align
= vertex_stride
- align
;
2150 if (vb_pos
+ vtx_size
+ align
> device
->vertex_buffer_size
)
2155 hr
= wined3d_buffer_map(device
->vertex_buffer
, vb_pos
, vtx_size
, &buffer_data
,
2156 vb_pos
? WINED3D_MAP_NOOVERWRITE
: WINED3D_MAP_DISCARD
);
2159 memcpy(buffer_data
, vertex_data
, vtx_size
);
2160 wined3d_buffer_unmap(device
->vertex_buffer
);
2161 device
->vertex_buffer_pos
= vb_pos
+ vtx_size
;
2163 hr
= d3d9_device_prepare_index_buffer(device
, idx_size
);
2167 ib_pos
= device
->index_buffer_pos
;
2168 align
= ib_pos
% idx_fmt_size
;
2169 if (align
) align
= idx_fmt_size
- align
;
2170 if (ib_pos
+ idx_size
+ align
> device
->index_buffer_size
)
2175 hr
= wined3d_buffer_map(device
->index_buffer
, ib_pos
, idx_size
, &buffer_data
,
2176 ib_pos
? WINED3D_MAP_NOOVERWRITE
: WINED3D_MAP_DISCARD
);
2179 memcpy(buffer_data
, index_data
, idx_size
);
2180 wined3d_buffer_unmap(device
->index_buffer
);
2181 device
->index_buffer_pos
= ib_pos
+ idx_size
;
2183 hr
= wined3d_device_set_stream_source(device
->wined3d_device
, 0, device
->vertex_buffer
, 0, vertex_stride
);
2187 wined3d_device_set_index_buffer(device
->wined3d_device
, device
->index_buffer
,
2188 wined3dformat_from_d3dformat(index_format
));
2189 wined3d_device_set_base_vertex_index(device
->wined3d_device
, vb_pos
/ vertex_stride
);
2191 wined3d_device_set_primitive_type(device
->wined3d_device
, primitive_type
);
2192 hr
= wined3d_device_draw_indexed_primitive(device
->wined3d_device
, ib_pos
/ idx_fmt_size
, idx_count
);
2194 wined3d_device_set_stream_source(device
->wined3d_device
, 0, NULL
, 0, 0);
2195 wined3d_device_set_index_buffer(device
->wined3d_device
, NULL
, WINED3DFMT_UNKNOWN
);
2196 wined3d_device_set_base_vertex_index(device
->wined3d_device
, 0);
2199 wined3d_mutex_unlock();
2203 static HRESULT WINAPI
d3d9_device_ProcessVertices(IDirect3DDevice9Ex
*iface
,
2204 UINT src_start_idx
, UINT dst_idx
, UINT vertex_count
, IDirect3DVertexBuffer9
*dst_buffer
,
2205 IDirect3DVertexDeclaration9
*declaration
, DWORD flags
)
2207 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2208 struct d3d9_vertexbuffer
*dst_impl
= unsafe_impl_from_IDirect3DVertexBuffer9(dst_buffer
);
2209 struct d3d9_vertex_declaration
*decl_impl
= unsafe_impl_from_IDirect3DVertexDeclaration9(declaration
);
2212 TRACE("iface %p, src_start_idx %u, dst_idx %u, vertex_count %u, dst_buffer %p, declaration %p, flags %#x.\n",
2213 iface
, src_start_idx
, dst_idx
, vertex_count
, dst_buffer
, declaration
, flags
);
2215 wined3d_mutex_lock();
2216 hr
= wined3d_device_process_vertices(device
->wined3d_device
, src_start_idx
, dst_idx
, vertex_count
,
2217 dst_impl
->wined3d_buffer
, decl_impl
? decl_impl
->wined3d_declaration
: NULL
,
2218 flags
, dst_impl
->fvf
);
2219 wined3d_mutex_unlock();
2224 static HRESULT WINAPI
d3d9_device_CreateVertexDeclaration(IDirect3DDevice9Ex
*iface
,
2225 const D3DVERTEXELEMENT9
*elements
, IDirect3DVertexDeclaration9
**declaration
)
2227 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2228 struct d3d9_vertex_declaration
*object
;
2231 TRACE("iface %p, elements %p, declaration %p.\n", iface
, elements
, declaration
);
2235 WARN("Caller passed a NULL declaration, returning D3DERR_INVALIDCALL.\n");
2236 return D3DERR_INVALIDCALL
;
2239 if (SUCCEEDED(hr
= d3d9_vertex_declaration_create(device
, elements
, &object
)))
2240 *declaration
= &object
->IDirect3DVertexDeclaration9_iface
;
2245 static HRESULT WINAPI
d3d9_device_SetVertexDeclaration(IDirect3DDevice9Ex
*iface
,
2246 IDirect3DVertexDeclaration9
*declaration
)
2248 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2249 struct d3d9_vertex_declaration
*decl_impl
= unsafe_impl_from_IDirect3DVertexDeclaration9(declaration
);
2251 TRACE("iface %p, declaration %p.\n", iface
, declaration
);
2253 wined3d_mutex_lock();
2254 wined3d_device_set_vertex_declaration(device
->wined3d_device
,
2255 decl_impl
? decl_impl
->wined3d_declaration
: NULL
);
2256 wined3d_mutex_unlock();
2261 static HRESULT WINAPI
d3d9_device_GetVertexDeclaration(IDirect3DDevice9Ex
*iface
,
2262 IDirect3DVertexDeclaration9
**declaration
)
2264 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2265 struct wined3d_vertex_declaration
*wined3d_declaration
;
2266 struct d3d9_vertex_declaration
*declaration_impl
;
2268 TRACE("iface %p, declaration %p.\n", iface
, declaration
);
2270 if (!declaration
) return D3DERR_INVALIDCALL
;
2272 wined3d_mutex_lock();
2273 if ((wined3d_declaration
= wined3d_device_get_vertex_declaration(device
->wined3d_device
)))
2275 declaration_impl
= wined3d_vertex_declaration_get_parent(wined3d_declaration
);
2276 *declaration
= &declaration_impl
->IDirect3DVertexDeclaration9_iface
;
2277 IDirect3DVertexDeclaration9_AddRef(*declaration
);
2281 *declaration
= NULL
;
2283 wined3d_mutex_unlock();
2285 TRACE("Returning %p.\n", *declaration
);
2289 static struct wined3d_vertex_declaration
*device_get_fvf_declaration(struct d3d9_device
*device
, DWORD fvf
)
2291 struct wined3d_vertex_declaration
*wined3d_declaration
;
2292 struct fvf_declaration
*fvf_decls
= device
->fvf_decls
;
2293 struct d3d9_vertex_declaration
*d3d9_declaration
;
2294 D3DVERTEXELEMENT9
*elements
;
2295 int p
, low
, high
; /* deliberately signed */
2298 TRACE("Searching for declaration for fvf %08x... ", fvf
);
2301 high
= device
->fvf_decl_count
- 1;
2304 p
= (low
+ high
) >> 1;
2307 if (fvf_decls
[p
].fvf
== fvf
)
2309 TRACE("found %p.\n", fvf_decls
[p
].decl
);
2310 return fvf_decls
[p
].decl
;
2313 if (fvf_decls
[p
].fvf
< fvf
)
2318 TRACE("not found. Creating and inserting at position %d.\n", low
);
2320 if (FAILED(hr
= vdecl_convert_fvf(fvf
, &elements
)))
2323 hr
= d3d9_vertex_declaration_create(device
, elements
, &d3d9_declaration
);
2324 HeapFree(GetProcessHeap(), 0, elements
);
2328 if (device
->fvf_decl_size
== device
->fvf_decl_count
)
2330 UINT grow
= max(device
->fvf_decl_size
/ 2, 8);
2332 fvf_decls
= HeapReAlloc(GetProcessHeap(), 0, fvf_decls
, sizeof(*fvf_decls
) * (device
->fvf_decl_size
+ grow
));
2335 IDirect3DVertexDeclaration9_Release(&d3d9_declaration
->IDirect3DVertexDeclaration9_iface
);
2338 device
->fvf_decls
= fvf_decls
;
2339 device
->fvf_decl_size
+= grow
;
2342 d3d9_declaration
->fvf
= fvf
;
2343 wined3d_declaration
= d3d9_declaration
->wined3d_declaration
;
2344 wined3d_vertex_declaration_incref(wined3d_declaration
);
2345 IDirect3DVertexDeclaration9_Release(&d3d9_declaration
->IDirect3DVertexDeclaration9_iface
);
2347 memmove(fvf_decls
+ low
+ 1, fvf_decls
+ low
, sizeof(*fvf_decls
) * (device
->fvf_decl_count
- low
));
2348 fvf_decls
[low
].decl
= wined3d_declaration
;
2349 fvf_decls
[low
].fvf
= fvf
;
2350 ++device
->fvf_decl_count
;
2352 TRACE("Returning %p. %u declatations in array.\n", wined3d_declaration
, device
->fvf_decl_count
);
2354 return wined3d_declaration
;
2357 static HRESULT WINAPI
d3d9_device_SetFVF(IDirect3DDevice9Ex
*iface
, DWORD fvf
)
2359 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2360 struct wined3d_vertex_declaration
*decl
;
2362 TRACE("iface %p, fvf %#x.\n", iface
, fvf
);
2366 WARN("%#x is not a valid FVF.\n", fvf
);
2370 wined3d_mutex_lock();
2371 if (!(decl
= device_get_fvf_declaration(device
, fvf
)))
2373 wined3d_mutex_unlock();
2374 ERR("Failed to create a vertex declaration for fvf %#x.\n", fvf
);
2375 return D3DERR_DRIVERINTERNALERROR
;
2378 wined3d_device_set_vertex_declaration(device
->wined3d_device
, decl
);
2379 wined3d_mutex_unlock();
2384 static HRESULT WINAPI
d3d9_device_GetFVF(IDirect3DDevice9Ex
*iface
, DWORD
*fvf
)
2386 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2387 struct wined3d_vertex_declaration
*wined3d_declaration
;
2388 struct d3d9_vertex_declaration
*d3d9_declaration
;
2390 TRACE("iface %p, fvf %p.\n", iface
, fvf
);
2392 wined3d_mutex_lock();
2393 if ((wined3d_declaration
= wined3d_device_get_vertex_declaration(device
->wined3d_device
)))
2395 d3d9_declaration
= wined3d_vertex_declaration_get_parent(wined3d_declaration
);
2396 *fvf
= d3d9_declaration
->fvf
;
2402 wined3d_mutex_unlock();
2404 TRACE("Returning FVF %#x.\n", *fvf
);
2409 static HRESULT WINAPI
d3d9_device_CreateVertexShader(IDirect3DDevice9Ex
*iface
,
2410 const DWORD
*byte_code
, IDirect3DVertexShader9
**shader
)
2412 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2413 struct d3d9_vertexshader
*object
;
2416 TRACE("iface %p, byte_code %p, shader %p.\n", iface
, byte_code
, shader
);
2418 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
2420 return E_OUTOFMEMORY
;
2422 hr
= vertexshader_init(object
, device
, byte_code
);
2425 WARN("Failed to initialize vertex shader, hr %#x.\n", hr
);
2426 HeapFree(GetProcessHeap(), 0, object
);
2430 TRACE("Created vertex shader %p.\n", object
);
2431 *shader
= &object
->IDirect3DVertexShader9_iface
;
2436 static HRESULT WINAPI
d3d9_device_SetVertexShader(IDirect3DDevice9Ex
*iface
, IDirect3DVertexShader9
*shader
)
2438 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2439 struct d3d9_vertexshader
*shader_obj
= unsafe_impl_from_IDirect3DVertexShader9(shader
);
2441 TRACE("iface %p, shader %p.\n", iface
, shader
);
2443 wined3d_mutex_lock();
2444 wined3d_device_set_vertex_shader(device
->wined3d_device
,
2445 shader_obj
? shader_obj
->wined3d_shader
: NULL
);
2446 wined3d_mutex_unlock();
2451 static HRESULT WINAPI
d3d9_device_GetVertexShader(IDirect3DDevice9Ex
*iface
, IDirect3DVertexShader9
**shader
)
2453 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2454 struct d3d9_vertexshader
*shader_impl
;
2455 struct wined3d_shader
*wined3d_shader
;
2457 TRACE("iface %p, shader %p.\n", iface
, shader
);
2459 wined3d_mutex_lock();
2460 if ((wined3d_shader
= wined3d_device_get_vertex_shader(device
->wined3d_device
)))
2462 shader_impl
= wined3d_shader_get_parent(wined3d_shader
);
2463 *shader
= &shader_impl
->IDirect3DVertexShader9_iface
;
2464 IDirect3DVertexShader9_AddRef(*shader
);
2470 wined3d_mutex_unlock();
2472 TRACE("Returning %p.\n", *shader
);
2477 static HRESULT WINAPI
d3d9_device_SetVertexShaderConstantF(IDirect3DDevice9Ex
*iface
,
2478 UINT reg_idx
, const float *data
, UINT count
)
2480 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2483 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2485 if (reg_idx
+ count
> D3D9_MAX_VERTEX_SHADER_CONSTANTF
)
2487 WARN("Trying to access %u constants, but d3d9 only supports %u\n",
2488 reg_idx
+ count
, D3D9_MAX_VERTEX_SHADER_CONSTANTF
);
2489 return D3DERR_INVALIDCALL
;
2492 wined3d_mutex_lock();
2493 hr
= wined3d_device_set_vs_consts_f(device
->wined3d_device
, reg_idx
, data
, count
);
2494 wined3d_mutex_unlock();
2499 static HRESULT WINAPI
d3d9_device_GetVertexShaderConstantF(IDirect3DDevice9Ex
*iface
,
2500 UINT reg_idx
, float *data
, UINT count
)
2502 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2505 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2507 if (reg_idx
+ count
> D3D9_MAX_VERTEX_SHADER_CONSTANTF
)
2509 WARN("Trying to access %u constants, but d3d9 only supports %u\n",
2510 reg_idx
+ count
, D3D9_MAX_VERTEX_SHADER_CONSTANTF
);
2511 return D3DERR_INVALIDCALL
;
2514 wined3d_mutex_lock();
2515 hr
= wined3d_device_get_vs_consts_f(device
->wined3d_device
, reg_idx
, data
, count
);
2516 wined3d_mutex_unlock();
2521 static HRESULT WINAPI
d3d9_device_SetVertexShaderConstantI(IDirect3DDevice9Ex
*iface
,
2522 UINT reg_idx
, const int *data
, UINT count
)
2524 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2527 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2529 wined3d_mutex_lock();
2530 hr
= wined3d_device_set_vs_consts_i(device
->wined3d_device
, reg_idx
, data
, count
);
2531 wined3d_mutex_unlock();
2536 static HRESULT WINAPI
d3d9_device_GetVertexShaderConstantI(IDirect3DDevice9Ex
*iface
,
2537 UINT reg_idx
, int *data
, UINT count
)
2539 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2542 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2544 wined3d_mutex_lock();
2545 hr
= wined3d_device_get_vs_consts_i(device
->wined3d_device
, reg_idx
, data
, count
);
2546 wined3d_mutex_unlock();
2551 static HRESULT WINAPI
d3d9_device_SetVertexShaderConstantB(IDirect3DDevice9Ex
*iface
,
2552 UINT reg_idx
, const BOOL
*data
, UINT count
)
2554 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2557 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2559 wined3d_mutex_lock();
2560 hr
= wined3d_device_set_vs_consts_b(device
->wined3d_device
, reg_idx
, data
, count
);
2561 wined3d_mutex_unlock();
2566 static HRESULT WINAPI
d3d9_device_GetVertexShaderConstantB(IDirect3DDevice9Ex
*iface
,
2567 UINT reg_idx
, BOOL
*data
, UINT count
)
2569 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2572 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2574 wined3d_mutex_lock();
2575 hr
= wined3d_device_get_vs_consts_b(device
->wined3d_device
, reg_idx
, data
, count
);
2576 wined3d_mutex_unlock();
2581 static HRESULT WINAPI
d3d9_device_SetStreamSource(IDirect3DDevice9Ex
*iface
,
2582 UINT stream_idx
, IDirect3DVertexBuffer9
*buffer
, UINT offset
, UINT stride
)
2584 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2585 struct d3d9_vertexbuffer
*buffer_impl
= unsafe_impl_from_IDirect3DVertexBuffer9(buffer
);
2588 TRACE("iface %p, stream_idx %u, buffer %p, offset %u, stride %u.\n",
2589 iface
, stream_idx
, buffer
, offset
, stride
);
2591 wined3d_mutex_lock();
2592 hr
= wined3d_device_set_stream_source(device
->wined3d_device
, stream_idx
,
2593 buffer_impl
? buffer_impl
->wined3d_buffer
: NULL
, offset
, stride
);
2594 wined3d_mutex_unlock();
2599 static HRESULT WINAPI
d3d9_device_GetStreamSource(IDirect3DDevice9Ex
*iface
,
2600 UINT stream_idx
, IDirect3DVertexBuffer9
**buffer
, UINT
*offset
, UINT
*stride
)
2602 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2603 struct d3d9_vertexbuffer
*buffer_impl
;
2604 struct wined3d_buffer
*wined3d_buffer
;
2607 TRACE("iface %p, stream_idx %u, buffer %p, offset %p, stride %p.\n",
2608 iface
, stream_idx
, buffer
, offset
, stride
);
2611 return D3DERR_INVALIDCALL
;
2613 wined3d_mutex_lock();
2614 hr
= wined3d_device_get_stream_source(device
->wined3d_device
, stream_idx
, &wined3d_buffer
, offset
, stride
);
2615 if (SUCCEEDED(hr
) && wined3d_buffer
)
2617 buffer_impl
= wined3d_buffer_get_parent(wined3d_buffer
);
2618 *buffer
= &buffer_impl
->IDirect3DVertexBuffer9_iface
;
2619 IDirect3DVertexBuffer9_AddRef(*buffer
);
2620 wined3d_buffer_decref(wined3d_buffer
);
2625 FIXME("Call to GetStreamSource failed %p %p\n", offset
, stride
);
2628 wined3d_mutex_unlock();
2633 static HRESULT WINAPI
d3d9_device_SetStreamSourceFreq(IDirect3DDevice9Ex
*iface
, UINT stream_idx
, UINT freq
)
2635 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2638 TRACE("iface %p, stream_idx %u, freq %u.\n", iface
, stream_idx
, freq
);
2640 wined3d_mutex_lock();
2641 hr
= wined3d_device_set_stream_source_freq(device
->wined3d_device
, stream_idx
, freq
);
2642 wined3d_mutex_unlock();
2647 static HRESULT WINAPI
d3d9_device_GetStreamSourceFreq(IDirect3DDevice9Ex
*iface
, UINT stream_idx
, UINT
*freq
)
2649 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2652 TRACE("iface %p, stream_idx %u, freq %p.\n", iface
, stream_idx
, freq
);
2654 wined3d_mutex_lock();
2655 hr
= wined3d_device_get_stream_source_freq(device
->wined3d_device
, stream_idx
, freq
);
2656 wined3d_mutex_unlock();
2661 static HRESULT WINAPI
d3d9_device_SetIndices(IDirect3DDevice9Ex
*iface
, IDirect3DIndexBuffer9
*buffer
)
2663 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2664 struct d3d9_indexbuffer
*ib
= unsafe_impl_from_IDirect3DIndexBuffer9(buffer
);
2666 TRACE("iface %p, buffer %p.\n", iface
, buffer
);
2668 wined3d_mutex_lock();
2669 wined3d_device_set_index_buffer(device
->wined3d_device
,
2670 ib
? ib
->wined3d_buffer
: NULL
,
2671 ib
? ib
->format
: WINED3DFMT_UNKNOWN
);
2672 wined3d_mutex_unlock();
2677 static HRESULT WINAPI
d3d9_device_GetIndices(IDirect3DDevice9Ex
*iface
, IDirect3DIndexBuffer9
**buffer
)
2679 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2680 enum wined3d_format_id wined3d_format
;
2681 struct wined3d_buffer
*wined3d_buffer
;
2682 struct d3d9_indexbuffer
*buffer_impl
;
2684 TRACE("iface %p, buffer %p.\n", iface
, buffer
);
2687 return D3DERR_INVALIDCALL
;
2689 wined3d_mutex_lock();
2690 if ((wined3d_buffer
= wined3d_device_get_index_buffer(device
->wined3d_device
, &wined3d_format
)))
2692 buffer_impl
= wined3d_buffer_get_parent(wined3d_buffer
);
2693 *buffer
= &buffer_impl
->IDirect3DIndexBuffer9_iface
;
2694 IDirect3DIndexBuffer9_AddRef(*buffer
);
2700 wined3d_mutex_unlock();
2705 static HRESULT WINAPI
d3d9_device_CreatePixelShader(IDirect3DDevice9Ex
*iface
,
2706 const DWORD
*byte_code
, IDirect3DPixelShader9
**shader
)
2708 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2709 struct d3d9_pixelshader
*object
;
2712 TRACE("iface %p, byte_code %p, shader %p.\n", iface
, byte_code
, shader
);
2714 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
2717 FIXME("Failed to allocate pixel shader memory.\n");
2718 return E_OUTOFMEMORY
;
2721 hr
= pixelshader_init(object
, device
, byte_code
);
2724 WARN("Failed to initialize pixel shader, hr %#x.\n", hr
);
2725 HeapFree(GetProcessHeap(), 0, object
);
2729 TRACE("Created pixel shader %p.\n", object
);
2730 *shader
= &object
->IDirect3DPixelShader9_iface
;
2735 static HRESULT WINAPI
d3d9_device_SetPixelShader(IDirect3DDevice9Ex
*iface
, IDirect3DPixelShader9
*shader
)
2737 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2738 struct d3d9_pixelshader
*shader_obj
= unsafe_impl_from_IDirect3DPixelShader9(shader
);
2740 TRACE("iface %p, shader %p.\n", iface
, shader
);
2742 wined3d_mutex_lock();
2743 wined3d_device_set_pixel_shader(device
->wined3d_device
,
2744 shader_obj
? shader_obj
->wined3d_shader
: NULL
);
2745 wined3d_mutex_unlock();
2750 static HRESULT WINAPI
d3d9_device_GetPixelShader(IDirect3DDevice9Ex
*iface
, IDirect3DPixelShader9
**shader
)
2752 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2753 struct d3d9_pixelshader
*shader_impl
;
2754 struct wined3d_shader
*wined3d_shader
;
2756 TRACE("iface %p, shader %p.\n", iface
, shader
);
2758 if (!shader
) return D3DERR_INVALIDCALL
;
2760 wined3d_mutex_lock();
2761 if ((wined3d_shader
= wined3d_device_get_pixel_shader(device
->wined3d_device
)))
2763 shader_impl
= wined3d_shader_get_parent(wined3d_shader
);
2764 *shader
= &shader_impl
->IDirect3DPixelShader9_iface
;
2765 IDirect3DPixelShader9_AddRef(*shader
);
2771 wined3d_mutex_unlock();
2773 TRACE("Returning %p.\n", *shader
);
2778 static HRESULT WINAPI
d3d9_device_SetPixelShaderConstantF(IDirect3DDevice9Ex
*iface
,
2779 UINT reg_idx
, const float *data
, UINT count
)
2781 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2784 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2786 wined3d_mutex_lock();
2787 hr
= wined3d_device_set_ps_consts_f(device
->wined3d_device
, reg_idx
, data
, count
);
2788 wined3d_mutex_unlock();
2793 static HRESULT WINAPI
d3d9_device_GetPixelShaderConstantF(IDirect3DDevice9Ex
*iface
,
2794 UINT reg_idx
, float *data
, UINT count
)
2796 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2799 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2801 wined3d_mutex_lock();
2802 hr
= wined3d_device_get_ps_consts_f(device
->wined3d_device
, reg_idx
, data
, count
);
2803 wined3d_mutex_unlock();
2808 static HRESULT WINAPI
d3d9_device_SetPixelShaderConstantI(IDirect3DDevice9Ex
*iface
,
2809 UINT reg_idx
, const int *data
, UINT count
)
2811 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2814 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2816 wined3d_mutex_lock();
2817 hr
= wined3d_device_set_ps_consts_i(device
->wined3d_device
, reg_idx
, data
, count
);
2818 wined3d_mutex_unlock();
2823 static HRESULT WINAPI
d3d9_device_GetPixelShaderConstantI(IDirect3DDevice9Ex
*iface
,
2824 UINT reg_idx
, int *data
, UINT count
)
2826 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2829 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2831 wined3d_mutex_lock();
2832 hr
= wined3d_device_get_ps_consts_i(device
->wined3d_device
, reg_idx
, data
, count
);
2833 wined3d_mutex_unlock();
2838 static HRESULT WINAPI
d3d9_device_SetPixelShaderConstantB(IDirect3DDevice9Ex
*iface
,
2839 UINT reg_idx
, const BOOL
*data
, UINT count
)
2841 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2844 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2846 wined3d_mutex_lock();
2847 hr
= wined3d_device_set_ps_consts_b(device
->wined3d_device
, reg_idx
, data
, count
);
2848 wined3d_mutex_unlock();
2853 static HRESULT WINAPI
d3d9_device_GetPixelShaderConstantB(IDirect3DDevice9Ex
*iface
,
2854 UINT reg_idx
, BOOL
*data
, UINT count
)
2856 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2859 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2861 wined3d_mutex_lock();
2862 hr
= wined3d_device_get_ps_consts_b(device
->wined3d_device
, reg_idx
, data
, count
);
2863 wined3d_mutex_unlock();
2868 static HRESULT WINAPI
d3d9_device_DrawRectPatch(IDirect3DDevice9Ex
*iface
, UINT handle
,
2869 const float *segment_count
, const D3DRECTPATCH_INFO
*patch_info
)
2871 FIXME("iface %p, handle %#x, segment_count %p, patch_info %p unimplemented.\n",
2872 iface
, handle
, segment_count
, patch_info
);
2876 static HRESULT WINAPI
d3d9_device_DrawTriPatch(IDirect3DDevice9Ex
*iface
, UINT handle
,
2877 const float *segment_count
, const D3DTRIPATCH_INFO
*patch_info
)
2879 FIXME("iface %p, handle %#x, segment_count %p, patch_info %p unimplemented.\n",
2880 iface
, handle
, segment_count
, patch_info
);
2884 static HRESULT WINAPI
d3d9_device_DeletePatch(IDirect3DDevice9Ex
*iface
, UINT handle
)
2886 FIXME("iface %p, handle %#x unimplemented.\n", iface
, handle
);
2887 return D3DERR_INVALIDCALL
;
2890 static HRESULT WINAPI
d3d9_device_CreateQuery(IDirect3DDevice9Ex
*iface
, D3DQUERYTYPE type
, IDirect3DQuery9
**query
)
2892 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2893 struct d3d9_query
*object
;
2896 TRACE("iface %p, type %#x, query %p.\n", iface
, type
, query
);
2898 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
2900 return E_OUTOFMEMORY
;
2902 hr
= query_init(object
, device
, type
);
2905 WARN("Failed to initialize query, hr %#x.\n", hr
);
2906 HeapFree(GetProcessHeap(), 0, object
);
2910 TRACE("Created query %p.\n", object
);
2911 if (query
) *query
= &object
->IDirect3DQuery9_iface
;
2912 else IDirect3DQuery9_Release(&object
->IDirect3DQuery9_iface
);
2917 static HRESULT WINAPI
d3d9_device_SetConvolutionMonoKernel(IDirect3DDevice9Ex
*iface
,
2918 UINT width
, UINT height
, float *rows
, float *columns
)
2920 FIXME("iface %p, width %u, height %u, rows %p, columns %p stub!\n",
2921 iface
, width
, height
, rows
, columns
);
2926 static HRESULT WINAPI
d3d9_device_ComposeRects(IDirect3DDevice9Ex
*iface
,
2927 IDirect3DSurface9
*src_surface
, IDirect3DSurface9
*dst_surface
, IDirect3DVertexBuffer9
*src_descs
,
2928 UINT rect_count
, IDirect3DVertexBuffer9
*dst_descs
, D3DCOMPOSERECTSOP operation
, INT offset_x
, INT offset_y
)
2930 FIXME("iface %p, src_surface %p, dst_surface %p, src_descs %p, rect_count %u,\n"
2931 "dst_descs %p, operation %#x, offset_x %u, offset_y %u stub!\n",
2932 iface
, src_surface
, dst_surface
, src_descs
, rect_count
,
2933 dst_descs
, operation
, offset_x
, offset_y
);
2938 static HRESULT WINAPI
d3d9_device_PresentEx(IDirect3DDevice9Ex
*iface
,
2939 const RECT
*src_rect
, const RECT
*dst_rect
, HWND dst_window_override
,
2940 const RGNDATA
*dirty_region
, DWORD flags
)
2942 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2945 TRACE("iface %p, src_rect %s, dst_rect %s, dst_window_override %p, dirty_region %p, flags %#x.\n",
2946 iface
, wine_dbgstr_rect(src_rect
), wine_dbgstr_rect(dst_rect
),
2947 dst_window_override
, dirty_region
, flags
);
2949 wined3d_mutex_lock();
2950 hr
= wined3d_device_present(device
->wined3d_device
, src_rect
, dst_rect
,
2951 dst_window_override
, dirty_region
, flags
);
2952 wined3d_mutex_unlock();
2957 static HRESULT WINAPI
d3d9_device_GetGPUThreadPriority(IDirect3DDevice9Ex
*iface
, INT
*priority
)
2959 FIXME("iface %p, priority %p stub!\n", iface
, priority
);
2964 static HRESULT WINAPI
d3d9_device_SetGPUThreadPriority(IDirect3DDevice9Ex
*iface
, INT priority
)
2966 FIXME("iface %p, priority %d stub!\n", iface
, priority
);
2971 static HRESULT WINAPI
d3d9_device_WaitForVBlank(IDirect3DDevice9Ex
*iface
, UINT swapchain_idx
)
2973 FIXME("iface %p, swapchain_idx %u stub!\n", iface
, swapchain_idx
);
2978 static HRESULT WINAPI
d3d9_device_CheckResourceResidency(IDirect3DDevice9Ex
*iface
,
2979 IDirect3DResource9
**resources
, UINT32 resource_count
)
2981 FIXME("iface %p, resources %p, resource_count %u stub!\n",
2982 iface
, resources
, resource_count
);
2987 static HRESULT WINAPI
d3d9_device_SetMaximumFrameLatency(IDirect3DDevice9Ex
*iface
, UINT max_latency
)
2989 FIXME("iface %p, max_latency %u stub!\n", iface
, max_latency
);
2994 static HRESULT WINAPI
d3d9_device_GetMaximumFrameLatency(IDirect3DDevice9Ex
*iface
, UINT
*max_latency
)
2996 FIXME("iface %p, max_latency %p stub!\n", iface
, max_latency
);
3003 static HRESULT WINAPI
d3d9_device_CheckDeviceState(IDirect3DDevice9Ex
*iface
, HWND dst_window
)
3007 TRACE("iface %p, dst_window %p stub!\n", iface
, dst_window
);
3010 FIXME("iface %p, dst_window %p stub!\n", iface
, dst_window
);
3015 static HRESULT WINAPI
d3d9_device_CreateRenderTargetEx(IDirect3DDevice9Ex
*iface
,
3016 UINT width
, UINT height
, D3DFORMAT format
, D3DMULTISAMPLE_TYPE multisample_type
, DWORD multisample_quality
,
3017 BOOL lockable
, IDirect3DSurface9
**surface
, HANDLE
*shared_handle
, DWORD usage
)
3019 FIXME("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u,\n"
3020 "lockable %#x, surface %p, shared_handle %p, usage %#x stub!\n",
3021 iface
, width
, height
, format
, multisample_type
, multisample_quality
,
3022 lockable
, surface
, shared_handle
, usage
);
3025 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
3030 static HRESULT WINAPI
d3d9_device_CreateOffscreenPlainSurfaceEx(IDirect3DDevice9Ex
*iface
,
3031 UINT width
, UINT height
, D3DFORMAT format
, D3DPOOL pool
, IDirect3DSurface9
**surface
,
3032 HANDLE
*shared_handle
, DWORD usage
)
3034 FIXME("iface %p, width %u, height %u, format %#x, pool %#x, surface %p, shared_handle %p, usage %#x stub!\n",
3035 iface
, width
, height
, format
, pool
, surface
, shared_handle
, usage
);
3040 static HRESULT WINAPI
d3d9_device_CreateDepthStencilSurfaceEx(IDirect3DDevice9Ex
*iface
,
3041 UINT width
, UINT height
, D3DFORMAT format
, D3DMULTISAMPLE_TYPE multisample_type
, DWORD multisample_quality
,
3042 BOOL discard
, IDirect3DSurface9
**surface
, HANDLE
*shared_handle
, DWORD usage
)
3044 FIXME("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u,\n"
3045 "discard %#x, surface %p, shared_handle %p, usage %#x stub!\n",
3046 iface
, width
, height
, format
, multisample_type
, multisample_quality
,
3047 discard
, surface
, shared_handle
, usage
);
3050 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
3055 static HRESULT WINAPI
d3d9_device_ResetEx(IDirect3DDevice9Ex
*iface
,
3056 D3DPRESENT_PARAMETERS
*present_parameters
, D3DDISPLAYMODEEX
*mode
)
3058 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3059 struct wined3d_swapchain_desc swapchain_desc
;
3060 struct wined3d_display_mode wined3d_mode
;
3063 TRACE("iface %p, present_parameters %p, mode %p.\n", iface
, present_parameters
, mode
);
3067 wined3d_mode
.width
= mode
->Width
;
3068 wined3d_mode
.height
= mode
->Height
;
3069 wined3d_mode
.refresh_rate
= mode
->RefreshRate
;
3070 wined3d_mode
.format_id
= wined3dformat_from_d3dformat(mode
->Format
);
3071 wined3d_mode
.scanline_ordering
= mode
->ScanLineOrdering
;
3074 wined3d_mutex_lock();
3076 if (device
->vertex_buffer
)
3078 wined3d_buffer_decref(device
->vertex_buffer
);
3079 device
->vertex_buffer
= NULL
;
3080 device
->vertex_buffer_size
= 0;
3082 if (device
->index_buffer
)
3084 wined3d_buffer_decref(device
->index_buffer
);
3085 device
->index_buffer
= NULL
;
3086 device
->index_buffer_size
= 0;
3089 wined3d_swapchain_desc_from_present_parameters(&swapchain_desc
, present_parameters
);
3090 hr
= wined3d_device_reset(device
->wined3d_device
, &swapchain_desc
,
3091 mode
? &wined3d_mode
: NULL
, reset_enum_callback
, FALSE
);
3092 wined3d_mutex_unlock();
3097 static HRESULT WINAPI
d3d9_device_GetDisplayModeEx(IDirect3DDevice9Ex
*iface
,
3098 UINT swapchain_idx
, D3DDISPLAYMODEEX
*mode
, D3DDISPLAYROTATION
*rotation
)
3100 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3101 struct wined3d_display_mode wined3d_mode
;
3104 TRACE("iface %p, swapchain_idx %u, mode %p, rotation %p.\n",
3105 iface
, swapchain_idx
, mode
, rotation
);
3107 if (mode
->Size
!= sizeof(*mode
))
3108 return D3DERR_INVALIDCALL
;
3110 wined3d_mutex_lock();
3111 hr
= wined3d_device_get_display_mode(device
->wined3d_device
, swapchain_idx
, &wined3d_mode
,
3112 (enum wined3d_display_rotation
*)rotation
);
3113 wined3d_mutex_unlock();
3117 mode
->Width
= wined3d_mode
.width
;
3118 mode
->Height
= wined3d_mode
.height
;
3119 mode
->RefreshRate
= wined3d_mode
.refresh_rate
;
3120 mode
->Format
= d3dformat_from_wined3dformat(wined3d_mode
.format_id
);
3121 mode
->ScanLineOrdering
= wined3d_mode
.scanline_ordering
;
3127 static const struct IDirect3DDevice9ExVtbl d3d9_device_vtbl
=
3130 d3d9_device_QueryInterface
,
3132 d3d9_device_Release
,
3133 /* IDirect3DDevice9 */
3134 d3d9_device_TestCooperativeLevel
,
3135 d3d9_device_GetAvailableTextureMem
,
3136 d3d9_device_EvictManagedResources
,
3137 d3d9_device_GetDirect3D
,
3138 d3d9_device_GetDeviceCaps
,
3139 d3d9_device_GetDisplayMode
,
3140 d3d9_device_GetCreationParameters
,
3141 d3d9_device_SetCursorProperties
,
3142 d3d9_device_SetCursorPosition
,
3143 d3d9_device_ShowCursor
,
3144 d3d9_device_CreateAdditionalSwapChain
,
3145 d3d9_device_GetSwapChain
,
3146 d3d9_device_GetNumberOfSwapChains
,
3148 d3d9_device_Present
,
3149 d3d9_device_GetBackBuffer
,
3150 d3d9_device_GetRasterStatus
,
3151 d3d9_device_SetDialogBoxMode
,
3152 d3d9_device_SetGammaRamp
,
3153 d3d9_device_GetGammaRamp
,
3154 d3d9_device_CreateTexture
,
3155 d3d9_device_CreateVolumeTexture
,
3156 d3d9_device_CreateCubeTexture
,
3157 d3d9_device_CreateVertexBuffer
,
3158 d3d9_device_CreateIndexBuffer
,
3159 d3d9_device_CreateRenderTarget
,
3160 d3d9_device_CreateDepthStencilSurface
,
3161 d3d9_device_UpdateSurface
,
3162 d3d9_device_UpdateTexture
,
3163 d3d9_device_GetRenderTargetData
,
3164 d3d9_device_GetFrontBufferData
,
3165 d3d9_device_StretchRect
,
3166 d3d9_device_ColorFill
,
3167 d3d9_device_CreateOffscreenPlainSurface
,
3168 d3d9_device_SetRenderTarget
,
3169 d3d9_device_GetRenderTarget
,
3170 d3d9_device_SetDepthStencilSurface
,
3171 d3d9_device_GetDepthStencilSurface
,
3172 d3d9_device_BeginScene
,
3173 d3d9_device_EndScene
,
3175 d3d9_device_SetTransform
,
3176 d3d9_device_GetTransform
,
3177 d3d9_device_MultiplyTransform
,
3178 d3d9_device_SetViewport
,
3179 d3d9_device_GetViewport
,
3180 d3d9_device_SetMaterial
,
3181 d3d9_device_GetMaterial
,
3182 d3d9_device_SetLight
,
3183 d3d9_device_GetLight
,
3184 d3d9_device_LightEnable
,
3185 d3d9_device_GetLightEnable
,
3186 d3d9_device_SetClipPlane
,
3187 d3d9_device_GetClipPlane
,
3188 d3d9_device_SetRenderState
,
3189 d3d9_device_GetRenderState
,
3190 d3d9_device_CreateStateBlock
,
3191 d3d9_device_BeginStateBlock
,
3192 d3d9_device_EndStateBlock
,
3193 d3d9_device_SetClipStatus
,
3194 d3d9_device_GetClipStatus
,
3195 d3d9_device_GetTexture
,
3196 d3d9_device_SetTexture
,
3197 d3d9_device_GetTextureStageState
,
3198 d3d9_device_SetTextureStageState
,
3199 d3d9_device_GetSamplerState
,
3200 d3d9_device_SetSamplerState
,
3201 d3d9_device_ValidateDevice
,
3202 d3d9_device_SetPaletteEntries
,
3203 d3d9_device_GetPaletteEntries
,
3204 d3d9_device_SetCurrentTexturePalette
,
3205 d3d9_device_GetCurrentTexturePalette
,
3206 d3d9_device_SetScissorRect
,
3207 d3d9_device_GetScissorRect
,
3208 d3d9_device_SetSoftwareVertexProcessing
,
3209 d3d9_device_GetSoftwareVertexProcessing
,
3210 d3d9_device_SetNPatchMode
,
3211 d3d9_device_GetNPatchMode
,
3212 d3d9_device_DrawPrimitive
,
3213 d3d9_device_DrawIndexedPrimitive
,
3214 d3d9_device_DrawPrimitiveUP
,
3215 d3d9_device_DrawIndexedPrimitiveUP
,
3216 d3d9_device_ProcessVertices
,
3217 d3d9_device_CreateVertexDeclaration
,
3218 d3d9_device_SetVertexDeclaration
,
3219 d3d9_device_GetVertexDeclaration
,
3222 d3d9_device_CreateVertexShader
,
3223 d3d9_device_SetVertexShader
,
3224 d3d9_device_GetVertexShader
,
3225 d3d9_device_SetVertexShaderConstantF
,
3226 d3d9_device_GetVertexShaderConstantF
,
3227 d3d9_device_SetVertexShaderConstantI
,
3228 d3d9_device_GetVertexShaderConstantI
,
3229 d3d9_device_SetVertexShaderConstantB
,
3230 d3d9_device_GetVertexShaderConstantB
,
3231 d3d9_device_SetStreamSource
,
3232 d3d9_device_GetStreamSource
,
3233 d3d9_device_SetStreamSourceFreq
,
3234 d3d9_device_GetStreamSourceFreq
,
3235 d3d9_device_SetIndices
,
3236 d3d9_device_GetIndices
,
3237 d3d9_device_CreatePixelShader
,
3238 d3d9_device_SetPixelShader
,
3239 d3d9_device_GetPixelShader
,
3240 d3d9_device_SetPixelShaderConstantF
,
3241 d3d9_device_GetPixelShaderConstantF
,
3242 d3d9_device_SetPixelShaderConstantI
,
3243 d3d9_device_GetPixelShaderConstantI
,
3244 d3d9_device_SetPixelShaderConstantB
,
3245 d3d9_device_GetPixelShaderConstantB
,
3246 d3d9_device_DrawRectPatch
,
3247 d3d9_device_DrawTriPatch
,
3248 d3d9_device_DeletePatch
,
3249 d3d9_device_CreateQuery
,
3250 /* IDirect3DDevice9Ex */
3251 d3d9_device_SetConvolutionMonoKernel
,
3252 d3d9_device_ComposeRects
,
3253 d3d9_device_PresentEx
,
3254 d3d9_device_GetGPUThreadPriority
,
3255 d3d9_device_SetGPUThreadPriority
,
3256 d3d9_device_WaitForVBlank
,
3257 d3d9_device_CheckResourceResidency
,
3258 d3d9_device_SetMaximumFrameLatency
,
3259 d3d9_device_GetMaximumFrameLatency
,
3260 d3d9_device_CheckDeviceState
,
3261 d3d9_device_CreateRenderTargetEx
,
3262 d3d9_device_CreateOffscreenPlainSurfaceEx
,
3263 d3d9_device_CreateDepthStencilSurfaceEx
,
3264 d3d9_device_ResetEx
,
3265 d3d9_device_GetDisplayModeEx
,
3268 static inline struct d3d9_device
*device_from_device_parent(struct wined3d_device_parent
*device_parent
)
3270 return CONTAINING_RECORD(device_parent
, struct d3d9_device
, device_parent
);
3273 static void CDECL
device_parent_wined3d_device_created(struct wined3d_device_parent
*device_parent
,
3274 struct wined3d_device
*device
)
3276 TRACE("device_parent %p, device %p.\n", device_parent
, device
);
3279 static void CDECL
device_parent_mode_changed(struct wined3d_device_parent
*device_parent
)
3281 TRACE("device_parent %p.\n", device_parent
);
3284 static HRESULT CDECL
device_parent_create_texture_surface(struct wined3d_device_parent
*device_parent
,
3285 void *container_parent
, const struct wined3d_resource_desc
*desc
, UINT sub_resource_idx
,
3286 DWORD flags
, struct wined3d_surface
**surface
)
3288 struct d3d9_device
*device
= device_from_device_parent(device_parent
);
3289 struct d3d9_surface
*d3d_surface
;
3292 TRACE("device_parent %p, container_parent %p, desc %p, sub_resource_idx %u, flags %#x, surface %p.\n",
3293 device_parent
, container_parent
, desc
, sub_resource_idx
, flags
, surface
);
3295 if (FAILED(hr
= d3d9_device_create_surface(device
, desc
->width
, desc
->height
,
3296 d3dformat_from_wined3dformat(desc
->format
), flags
, (IDirect3DSurface9
**)&d3d_surface
,
3297 desc
->usage
, desc
->pool
, desc
->multisample_type
, desc
->multisample_quality
)))
3299 WARN("Failed to create surface, hr %#x.\n", hr
);
3303 *surface
= d3d_surface
->wined3d_surface
;
3304 wined3d_surface_incref(*surface
);
3306 d3d_surface
->container
= container_parent
;
3307 IDirect3DDevice9Ex_Release(d3d_surface
->parent_device
);
3308 d3d_surface
->parent_device
= NULL
;
3310 IDirect3DSurface9_Release(&d3d_surface
->IDirect3DSurface9_iface
);
3311 d3d_surface
->forwardReference
= container_parent
;
3316 static HRESULT CDECL
device_parent_create_swapchain_surface(struct wined3d_device_parent
*device_parent
,
3317 void *container_parent
, const struct wined3d_resource_desc
*desc
, struct wined3d_surface
**surface
)
3319 struct d3d9_device
*device
= device_from_device_parent(device_parent
);
3320 struct wined3d_resource_desc texture_desc
;
3321 struct d3d9_surface
*d3d_surface
;
3322 struct wined3d_texture
*texture
;
3325 TRACE("device_parent %p, container_parent %p, desc %p, surface %p.\n",
3326 device_parent
, container_parent
, desc
, surface
);
3328 if (container_parent
== device_parent
)
3329 container_parent
= &device
->IDirect3DDevice9Ex_iface
;
3331 texture_desc
= *desc
;
3332 texture_desc
.resource_type
= WINED3D_RTYPE_TEXTURE
;
3333 if (FAILED(hr
= wined3d_texture_create_2d(device
->wined3d_device
, &texture_desc
, 1,
3334 WINED3D_SURFACE_MAPPABLE
, container_parent
, &d3d9_null_wined3d_parent_ops
, &texture
)))
3336 WARN("Failed to create texture, hr %#x.\n", hr
);
3340 *surface
= wined3d_surface_from_resource(wined3d_texture_get_sub_resource(texture
, 0));
3341 wined3d_surface_incref(*surface
);
3342 wined3d_texture_decref(texture
);
3344 d3d_surface
= wined3d_surface_get_parent(*surface
);
3345 d3d_surface
->forwardReference
= NULL
;
3346 d3d_surface
->parent_device
= &device
->IDirect3DDevice9Ex_iface
;
3351 static HRESULT CDECL
device_parent_create_volume(struct wined3d_device_parent
*device_parent
,
3352 void *container_parent
, UINT width
, UINT height
, UINT depth
, enum wined3d_format_id format
,
3353 enum wined3d_pool pool
, DWORD usage
, struct wined3d_volume
**volume
)
3355 struct d3d9_device
*device
= device_from_device_parent(device_parent
);
3356 struct d3d9_volume
*object
;
3359 TRACE("device_parent %p, container_parent %p, width %u, height %u, depth %u, "
3360 "format %#x, pool %#x, usage %#x, volume %p\n",
3361 device_parent
, container_parent
, width
, height
, depth
,
3362 format
, pool
, usage
, volume
);
3364 /* Allocate the storage for the device */
3365 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
3368 FIXME("Allocation of memory failed\n");
3370 return D3DERR_OUTOFVIDEOMEMORY
;
3373 hr
= volume_init(object
, device
, width
, height
, depth
, usage
, format
, pool
);
3376 WARN("Failed to initialize volume, hr %#x.\n", hr
);
3377 HeapFree(GetProcessHeap(), 0, object
);
3381 *volume
= object
->wined3d_volume
;
3382 wined3d_volume_incref(*volume
);
3383 IDirect3DVolume9_Release(&object
->IDirect3DVolume9_iface
);
3385 object
->container
= container_parent
;
3386 object
->forwardReference
= container_parent
;
3388 TRACE("Created volume %p.\n", object
);
3393 static HRESULT CDECL
device_parent_create_swapchain(struct wined3d_device_parent
*device_parent
,
3394 struct wined3d_swapchain_desc
*desc
, struct wined3d_swapchain
**swapchain
)
3396 struct d3d9_device
*device
= device_from_device_parent(device_parent
);
3397 struct d3d9_swapchain
*d3d_swapchain
;
3400 TRACE("device_parent %p, desc %p, swapchain %p\n", device_parent
, desc
, swapchain
);
3402 hr
= d3d9_swapchain_create(device
, desc
, &d3d_swapchain
);
3405 WARN("Failed to create swapchain, hr %#x.\n", hr
);
3410 *swapchain
= d3d_swapchain
->wined3d_swapchain
;
3411 wined3d_swapchain_incref(*swapchain
);
3412 IDirect3DSwapChain9_Release(&d3d_swapchain
->IDirect3DSwapChain9_iface
);
3417 static const struct wined3d_device_parent_ops d3d9_wined3d_device_parent_ops
=
3419 device_parent_wined3d_device_created
,
3420 device_parent_mode_changed
,
3421 device_parent_create_swapchain_surface
,
3422 device_parent_create_texture_surface
,
3423 device_parent_create_volume
,
3424 device_parent_create_swapchain
,
3427 static void setup_fpu(void)
3429 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
3431 __asm__
volatile ("fnstcw %0" : "=m" (cw
));
3432 cw
= (cw
& ~0xf3f) | 0x3f;
3433 __asm__
volatile ("fldcw %0" : : "m" (cw
));
3434 #elif defined(__i386__) && defined(_MSC_VER)
3437 cw
= (cw
& ~0xf3f) | 0x3f;
3440 FIXME("FPU setup not implemented for this platform.\n");
3444 HRESULT
device_init(struct d3d9_device
*device
, struct d3d9
*parent
, struct wined3d
*wined3d
,
3445 UINT adapter
, D3DDEVTYPE device_type
, HWND focus_window
, DWORD flags
,
3446 D3DPRESENT_PARAMETERS
*parameters
, D3DDISPLAYMODEEX
*mode
)
3448 struct wined3d_swapchain_desc
*swapchain_desc
;
3453 FIXME("Ignoring display mode.\n");
3455 device
->IDirect3DDevice9Ex_iface
.lpVtbl
= &d3d9_device_vtbl
;
3456 device
->device_parent
.ops
= &d3d9_wined3d_device_parent_ops
;
3457 device
->refcount
= 1;
3459 if (!(flags
& D3DCREATE_FPU_PRESERVE
)) setup_fpu();
3461 wined3d_mutex_lock();
3462 hr
= wined3d_device_create(wined3d
, adapter
, device_type
, focus_window
, flags
, 4,
3463 &device
->device_parent
, &device
->wined3d_device
);
3466 WARN("Failed to create wined3d device, hr %#x.\n", hr
);
3467 wined3d_mutex_unlock();
3471 if (flags
& D3DCREATE_ADAPTERGROUP_DEVICE
)
3475 wined3d_get_device_caps(wined3d
, adapter
, device_type
, &caps
);
3476 count
= caps
.NumberOfAdaptersInGroup
;
3479 if (flags
& D3DCREATE_MULTITHREADED
)
3480 wined3d_device_set_multithreaded(device
->wined3d_device
);
3482 if (!parameters
->Windowed
)
3485 focus_window
= parameters
->hDeviceWindow
;
3486 if (FAILED(hr
= wined3d_device_acquire_focus_window(device
->wined3d_device
, focus_window
)))
3488 ERR("Failed to acquire focus window, hr %#x.\n", hr
);
3489 wined3d_device_decref(device
->wined3d_device
);
3490 wined3d_mutex_unlock();
3494 for (i
= 0; i
< count
; ++i
)
3496 HWND device_window
= parameters
[i
].hDeviceWindow
;
3498 if (!device_window
) device_window
= focus_window
;
3499 wined3d_device_setup_fullscreen_window(device
->wined3d_device
, device_window
,
3500 parameters
[i
].BackBufferWidth
,
3501 parameters
[i
].BackBufferHeight
);
3505 swapchain_desc
= HeapAlloc(GetProcessHeap(), 0, sizeof(*swapchain_desc
) * count
);
3506 if (!swapchain_desc
)
3508 ERR("Failed to allocate wined3d parameters.\n");
3509 wined3d_device_decref(device
->wined3d_device
);
3510 wined3d_mutex_unlock();
3511 return E_OUTOFMEMORY
;
3514 for (i
= 0; i
< count
; ++i
)
3516 wined3d_swapchain_desc_from_present_parameters(&swapchain_desc
[i
], ¶meters
[i
]);
3519 hr
= wined3d_device_init_3d(device
->wined3d_device
, swapchain_desc
);
3522 WARN("Failed to initialize 3D, hr %#x.\n", hr
);
3523 wined3d_device_release_focus_window(device
->wined3d_device
);
3524 HeapFree(GetProcessHeap(), 0, swapchain_desc
);
3525 wined3d_device_decref(device
->wined3d_device
);
3526 wined3d_mutex_unlock();
3530 wined3d_mutex_unlock();
3532 for (i
= 0; i
< count
; ++i
)
3534 present_parameters_from_wined3d_swapchain_desc(¶meters
[i
], &swapchain_desc
[i
]);
3536 HeapFree(GetProcessHeap(), 0, swapchain_desc
);
3538 /* Initialize the converted declaration array. This creates a valid pointer
3539 * and when adding decls HeapReAlloc() can be used without further checking. */
3540 device
->fvf_decls
= HeapAlloc(GetProcessHeap(), 0, 0);
3541 if (!device
->fvf_decls
)
3543 ERR("Failed to allocate FVF vertex declaration map memory.\n");
3544 wined3d_mutex_lock();
3545 wined3d_device_uninit_3d(device
->wined3d_device
);
3546 wined3d_device_release_focus_window(device
->wined3d_device
);
3547 wined3d_device_decref(device
->wined3d_device
);
3548 wined3d_mutex_unlock();
3549 return E_OUTOFMEMORY
;
3552 IDirect3D9Ex_AddRef(&parent
->IDirect3D9Ex_iface
);
3553 device
->d3d_parent
= parent
;