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 static inline struct d3d9_device
*impl_from_IDirect3DDevice9Ex(IDirect3DDevice9Ex
*iface
)
186 return CONTAINING_RECORD(iface
, struct d3d9_device
, IDirect3DDevice9Ex_iface
);
189 static HRESULT WINAPI
d3d9_device_QueryInterface(IDirect3DDevice9Ex
*iface
, REFIID riid
, void **out
)
191 TRACE("iface %p, riid %s, out %p.\n", iface
, debugstr_guid(riid
), out
);
193 if (IsEqualGUID(riid
, &IID_IDirect3DDevice9
)
194 || IsEqualGUID(riid
, &IID_IUnknown
))
196 IDirect3DDevice9Ex_AddRef(iface
);
201 if (IsEqualGUID(riid
, &IID_IDirect3DDevice9Ex
))
203 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
205 /* Find out if the creating d3d9 interface was created with Direct3DCreate9Ex.
206 * It doesn't matter with which function the device was created. */
207 if (!device
->d3d_parent
->extended
)
209 WARN("IDirect3D9 instance wasn't created with CreateDirect3D9Ex, returning E_NOINTERFACE.\n");
211 return E_NOINTERFACE
;
214 IDirect3DDevice9Ex_AddRef(iface
);
219 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
222 return E_NOINTERFACE
;
225 static ULONG WINAPI
d3d9_device_AddRef(IDirect3DDevice9Ex
*iface
)
227 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
228 ULONG refcount
= InterlockedIncrement(&device
->refcount
);
230 TRACE("%p increasing refcount to %u.\n", iface
, refcount
);
235 static ULONG WINAPI DECLSPEC_HOTPATCH
d3d9_device_Release(IDirect3DDevice9Ex
*iface
)
237 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
240 if (device
->in_destruction
)
243 refcount
= InterlockedDecrement(&device
->refcount
);
245 TRACE("%p decreasing refcount to %u.\n", iface
, refcount
);
250 device
->in_destruction
= TRUE
;
252 wined3d_mutex_lock();
253 for (i
= 0; i
< device
->fvf_decl_count
; ++i
)
255 wined3d_vertex_declaration_decref(device
->fvf_decls
[i
].decl
);
257 HeapFree(GetProcessHeap(), 0, device
->fvf_decls
);
259 wined3d_device_uninit_3d(device
->wined3d_device
);
260 wined3d_device_release_focus_window(device
->wined3d_device
);
261 wined3d_device_decref(device
->wined3d_device
);
262 wined3d_mutex_unlock();
264 IDirect3D9Ex_Release(&device
->d3d_parent
->IDirect3D9Ex_iface
);
266 HeapFree(GetProcessHeap(), 0, device
);
272 static HRESULT WINAPI
d3d9_device_TestCooperativeLevel(IDirect3DDevice9Ex
*iface
)
274 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
276 TRACE("iface %p.\n", iface
);
278 if (device
->not_reset
)
280 TRACE("D3D9 device is marked not reset.\n");
281 return D3DERR_DEVICENOTRESET
;
287 static UINT WINAPI
d3d9_device_GetAvailableTextureMem(IDirect3DDevice9Ex
*iface
)
289 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
292 TRACE("iface %p.\n", iface
);
294 wined3d_mutex_lock();
295 hr
= wined3d_device_get_available_texture_mem(device
->wined3d_device
);
296 wined3d_mutex_unlock();
301 static HRESULT WINAPI
d3d9_device_EvictManagedResources(IDirect3DDevice9Ex
*iface
)
303 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
305 TRACE("iface %p.\n", iface
);
307 wined3d_mutex_lock();
308 wined3d_device_evict_managed_resources(device
->wined3d_device
);
309 wined3d_mutex_unlock();
314 static HRESULT WINAPI
d3d9_device_GetDirect3D(IDirect3DDevice9Ex
*iface
, IDirect3D9
**d3d9
)
316 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
318 TRACE("iface %p, d3d9 %p.\n", iface
, d3d9
);
321 return D3DERR_INVALIDCALL
;
323 return IDirect3D9Ex_QueryInterface(&device
->d3d_parent
->IDirect3D9Ex_iface
, &IID_IDirect3D9
, (void **)d3d9
);
326 static HRESULT WINAPI
d3d9_device_GetDeviceCaps(IDirect3DDevice9Ex
*iface
, D3DCAPS9
*caps
)
328 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
329 WINED3DCAPS
*wined3d_caps
;
332 TRACE("iface %p, caps %p.\n", iface
, caps
);
335 return D3DERR_INVALIDCALL
;
337 if (!(wined3d_caps
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*wined3d_caps
))))
338 return D3DERR_INVALIDCALL
; /* well this is what MSDN says to return */
340 memset(caps
, 0, sizeof(*caps
));
342 wined3d_mutex_lock();
343 hr
= wined3d_device_get_device_caps(device
->wined3d_device
, wined3d_caps
);
344 wined3d_mutex_unlock();
346 WINECAPSTOD3D9CAPS(caps
, wined3d_caps
)
347 HeapFree(GetProcessHeap(), 0, wined3d_caps
);
349 /* Some functionality is implemented in d3d9.dll, not wined3d.dll. Add the needed caps */
350 caps
->DevCaps2
|= D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES
;
357 static HRESULT WINAPI
d3d9_device_GetDisplayMode(IDirect3DDevice9Ex
*iface
, UINT swapchain
, D3DDISPLAYMODE
*mode
)
359 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
360 struct wined3d_display_mode wined3d_mode
;
363 TRACE("iface %p, swapchain %u, mode %p.\n", iface
, swapchain
, mode
);
365 wined3d_mutex_lock();
366 hr
= wined3d_device_get_display_mode(device
->wined3d_device
, swapchain
, &wined3d_mode
, NULL
);
367 wined3d_mutex_unlock();
371 mode
->Width
= wined3d_mode
.width
;
372 mode
->Height
= wined3d_mode
.height
;
373 mode
->RefreshRate
= wined3d_mode
.refresh_rate
;
374 mode
->Format
= d3dformat_from_wined3dformat(wined3d_mode
.format_id
);
380 static HRESULT WINAPI
d3d9_device_GetCreationParameters(IDirect3DDevice9Ex
*iface
,
381 D3DDEVICE_CREATION_PARAMETERS
*parameters
)
383 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
386 TRACE("iface %p, parameters %p.\n", iface
, parameters
);
388 wined3d_mutex_lock();
389 hr
= wined3d_device_get_creation_parameters(device
->wined3d_device
,
390 (struct wined3d_device_creation_parameters
*)parameters
);
391 wined3d_mutex_unlock();
396 static HRESULT WINAPI
d3d9_device_SetCursorProperties(IDirect3DDevice9Ex
*iface
,
397 UINT hotspot_x
, UINT hotspot_y
, IDirect3DSurface9
*bitmap
)
399 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
400 struct d3d9_surface
*bitmap_impl
= unsafe_impl_from_IDirect3DSurface9(bitmap
);
403 TRACE("iface %p, hotspot_x %u, hotspot_y %u, bitmap %p.\n",
404 iface
, hotspot_x
, hotspot_y
, bitmap
);
408 WARN("No cursor bitmap, returning D3DERR_INVALIDCALL.\n");
409 return D3DERR_INVALIDCALL
;
412 wined3d_mutex_lock();
413 hr
= wined3d_device_set_cursor_properties(device
->wined3d_device
,
414 hotspot_x
, hotspot_y
, bitmap_impl
->wined3d_surface
);
415 wined3d_mutex_unlock();
420 static void WINAPI
d3d9_device_SetCursorPosition(IDirect3DDevice9Ex
*iface
, int x
, int y
, DWORD flags
)
422 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
424 TRACE("iface %p, x %u, y %u, flags %#x.\n", iface
, x
, y
, flags
);
426 wined3d_mutex_lock();
427 wined3d_device_set_cursor_position(device
->wined3d_device
, x
, y
, flags
);
428 wined3d_mutex_unlock();
431 static BOOL WINAPI
d3d9_device_ShowCursor(IDirect3DDevice9Ex
*iface
, BOOL show
)
433 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
436 TRACE("iface %p, show %#x.\n", iface
, show
);
438 wined3d_mutex_lock();
439 ret
= wined3d_device_show_cursor(device
->wined3d_device
, show
);
440 wined3d_mutex_unlock();
445 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_device_CreateAdditionalSwapChain(IDirect3DDevice9Ex
*iface
,
446 D3DPRESENT_PARAMETERS
*present_parameters
, IDirect3DSwapChain9
**swapchain
)
448 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
449 struct wined3d_swapchain_desc desc
;
450 struct d3d9_swapchain
*object
;
453 TRACE("iface %p, present_parameters %p, swapchain %p.\n",
454 iface
, present_parameters
, swapchain
);
456 desc
.backbuffer_width
= present_parameters
->BackBufferWidth
;
457 desc
.backbuffer_height
= present_parameters
->BackBufferHeight
;
458 desc
.backbuffer_format
= wined3dformat_from_d3dformat(present_parameters
->BackBufferFormat
);
459 desc
.backbuffer_count
= max(1, present_parameters
->BackBufferCount
);
460 desc
.multisample_type
= present_parameters
->MultiSampleType
;
461 desc
.multisample_quality
= present_parameters
->MultiSampleQuality
;
462 desc
.swap_effect
= present_parameters
->SwapEffect
;
463 desc
.device_window
= present_parameters
->hDeviceWindow
;
464 desc
.windowed
= present_parameters
->Windowed
;
465 desc
.enable_auto_depth_stencil
= present_parameters
->EnableAutoDepthStencil
;
466 desc
.auto_depth_stencil_format
= wined3dformat_from_d3dformat(present_parameters
->AutoDepthStencilFormat
);
467 desc
.flags
= present_parameters
->Flags
;
468 desc
.refresh_rate
= present_parameters
->FullScreen_RefreshRateInHz
;
469 desc
.swap_interval
= present_parameters
->PresentationInterval
;
470 desc
.auto_restore_display_mode
= TRUE
;
472 if (SUCCEEDED(hr
= d3d9_swapchain_create(device
, &desc
, &object
)))
473 *swapchain
= &object
->IDirect3DSwapChain9_iface
;
475 present_parameters
->BackBufferWidth
= desc
.backbuffer_width
;
476 present_parameters
->BackBufferHeight
= desc
.backbuffer_height
;
477 present_parameters
->BackBufferFormat
= d3dformat_from_wined3dformat(desc
.backbuffer_format
);
478 present_parameters
->BackBufferCount
= desc
.backbuffer_count
;
479 present_parameters
->MultiSampleType
= desc
.multisample_type
;
480 present_parameters
->MultiSampleQuality
= desc
.multisample_quality
;
481 present_parameters
->SwapEffect
= desc
.swap_effect
;
482 present_parameters
->hDeviceWindow
= desc
.device_window
;
483 present_parameters
->Windowed
= desc
.windowed
;
484 present_parameters
->EnableAutoDepthStencil
= desc
.enable_auto_depth_stencil
;
485 present_parameters
->AutoDepthStencilFormat
= d3dformat_from_wined3dformat(desc
.auto_depth_stencil_format
);
486 present_parameters
->Flags
= desc
.flags
;
487 present_parameters
->FullScreen_RefreshRateInHz
= desc
.refresh_rate
;
488 present_parameters
->PresentationInterval
= desc
.swap_interval
;
493 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_device_GetSwapChain(IDirect3DDevice9Ex
*iface
,
494 UINT swapchain_idx
, IDirect3DSwapChain9
**swapchain
)
496 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
497 struct wined3d_swapchain
*wined3d_swapchain
= NULL
;
498 struct d3d9_swapchain
*swapchain_impl
;
501 TRACE("iface %p, swapchain_idx %u, swapchain %p.\n", iface
, swapchain_idx
, swapchain
);
503 wined3d_mutex_lock();
504 hr
= wined3d_device_get_swapchain(device
->wined3d_device
, swapchain_idx
, &wined3d_swapchain
);
505 if (SUCCEEDED(hr
) && wined3d_swapchain
)
507 swapchain_impl
= wined3d_swapchain_get_parent(wined3d_swapchain
);
508 *swapchain
= &swapchain_impl
->IDirect3DSwapChain9_iface
;
509 IDirect3DSwapChain9_AddRef(*swapchain
);
510 wined3d_swapchain_decref(wined3d_swapchain
);
516 wined3d_mutex_unlock();
521 static UINT WINAPI
d3d9_device_GetNumberOfSwapChains(IDirect3DDevice9Ex
*iface
)
523 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
526 TRACE("iface %p.\n", iface
);
528 wined3d_mutex_lock();
529 count
= wined3d_device_get_swapchain_count(device
->wined3d_device
);
530 wined3d_mutex_unlock();
535 static HRESULT CDECL
reset_enum_callback(struct wined3d_resource
*resource
)
537 struct wined3d_resource_desc desc
;
539 wined3d_resource_get_desc(resource
, &desc
);
540 if (desc
.pool
== WINED3D_POOL_DEFAULT
)
542 struct d3d9_surface
*surface
;
544 if (desc
.resource_type
!= WINED3D_RTYPE_SURFACE
)
546 WARN("Resource %p in pool D3DPOOL_DEFAULT blocks the Reset call.\n", resource
);
547 return D3DERR_INVALIDCALL
;
550 surface
= wined3d_resource_get_parent(resource
);
551 if (surface
->refcount
)
553 WARN("Surface %p (resource %p) in pool D3DPOOL_DEFAULT blocks the Reset call.\n", surface
, resource
);
554 return D3DERR_INVALIDCALL
;
557 WARN("Surface %p (resource %p) is an implicit resource with ref 0.\n", surface
, resource
);
563 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_device_Reset(IDirect3DDevice9Ex
*iface
,
564 D3DPRESENT_PARAMETERS
*present_parameters
)
566 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
567 struct wined3d_swapchain_desc swapchain_desc
;
570 TRACE("iface %p, present_parameters %p.\n", iface
, present_parameters
);
572 /* Reset states that hold a COM object. WineD3D holds an internal reference to set objects, because
573 * such objects can still be used for rendering after their external d3d9 object has been destroyed.
574 * These objects must not be enumerated. Unsetting them tells WineD3D that the application will not
575 * make use of the hidden reference and destroys the objects.
577 * Unsetting them is no problem, because the states are supposed to be reset anyway. If the validation
578 * below fails, the device is considered "lost", and _Reset and _Release are the only allowed calls
580 wined3d_mutex_lock();
582 swapchain_desc
.backbuffer_width
= present_parameters
->BackBufferWidth
;
583 swapchain_desc
.backbuffer_height
= present_parameters
->BackBufferHeight
;
584 swapchain_desc
.backbuffer_format
= wined3dformat_from_d3dformat(present_parameters
->BackBufferFormat
);
585 swapchain_desc
.backbuffer_count
= max(1, present_parameters
->BackBufferCount
);
586 swapchain_desc
.multisample_type
= present_parameters
->MultiSampleType
;
587 swapchain_desc
.multisample_quality
= present_parameters
->MultiSampleQuality
;
588 swapchain_desc
.swap_effect
= present_parameters
->SwapEffect
;
589 swapchain_desc
.device_window
= present_parameters
->hDeviceWindow
;
590 swapchain_desc
.windowed
= present_parameters
->Windowed
;
591 swapchain_desc
.enable_auto_depth_stencil
= present_parameters
->EnableAutoDepthStencil
;
592 swapchain_desc
.auto_depth_stencil_format
= wined3dformat_from_d3dformat(present_parameters
->AutoDepthStencilFormat
);
593 swapchain_desc
.flags
= present_parameters
->Flags
;
594 swapchain_desc
.refresh_rate
= present_parameters
->FullScreen_RefreshRateInHz
;
595 swapchain_desc
.swap_interval
= present_parameters
->PresentationInterval
;
596 swapchain_desc
.auto_restore_display_mode
= TRUE
;
598 hr
= wined3d_device_reset(device
->wined3d_device
, &swapchain_desc
, reset_enum_callback
);
600 device
->not_reset
= TRUE
;
602 device
->not_reset
= FALSE
;
604 wined3d_mutex_unlock();
609 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_device_Present(IDirect3DDevice9Ex
*iface
,
610 const RECT
*src_rect
, const RECT
*dst_rect
, HWND dst_window_override
, const RGNDATA
*dirty_region
)
612 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
615 TRACE("iface %p, src_rect %p, dst_rect %p, dst_window_override %p, dirty_region %p.\n",
616 iface
, src_rect
, dst_rect
, dst_window_override
, dirty_region
);
618 wined3d_mutex_lock();
619 hr
= wined3d_device_present(device
->wined3d_device
, src_rect
, dst_rect
,
620 dst_window_override
, dirty_region
, 0);
621 wined3d_mutex_unlock();
626 static HRESULT WINAPI
d3d9_device_GetBackBuffer(IDirect3DDevice9Ex
*iface
, UINT swapchain
,
627 UINT backbuffer_idx
, D3DBACKBUFFER_TYPE backbuffer_type
, IDirect3DSurface9
**backbuffer
)
629 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
630 struct wined3d_surface
*wined3d_surface
= NULL
;
631 struct d3d9_surface
*surface_impl
;
634 TRACE("iface %p, swapchain %u, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n",
635 iface
, swapchain
, backbuffer_idx
, backbuffer_type
, backbuffer
);
637 wined3d_mutex_lock();
638 hr
= wined3d_device_get_back_buffer(device
->wined3d_device
, swapchain
,
639 backbuffer_idx
, (enum wined3d_backbuffer_type
)backbuffer_type
, &wined3d_surface
);
640 if (SUCCEEDED(hr
) && wined3d_surface
&& backbuffer
)
642 surface_impl
= wined3d_surface_get_parent(wined3d_surface
);
643 *backbuffer
= &surface_impl
->IDirect3DSurface9_iface
;
644 IDirect3DSurface9_AddRef(*backbuffer
);
645 wined3d_surface_decref(wined3d_surface
);
647 wined3d_mutex_unlock();
651 static HRESULT WINAPI
d3d9_device_GetRasterStatus(IDirect3DDevice9Ex
*iface
,
652 UINT swapchain
, D3DRASTER_STATUS
*raster_status
)
654 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
657 TRACE("iface %p, swapchain %u, raster_status %p.\n", iface
, swapchain
, raster_status
);
659 wined3d_mutex_lock();
660 hr
= wined3d_device_get_raster_status(device
->wined3d_device
,
661 swapchain
, (struct wined3d_raster_status
*)raster_status
);
662 wined3d_mutex_unlock();
667 static HRESULT WINAPI
d3d9_device_SetDialogBoxMode(IDirect3DDevice9Ex
*iface
, BOOL enable
)
669 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
672 TRACE("iface %p, enable %#x.\n", iface
, enable
);
674 wined3d_mutex_lock();
675 hr
= wined3d_device_set_dialog_box_mode(device
->wined3d_device
, enable
);
676 wined3d_mutex_unlock();
681 static void WINAPI
d3d9_device_SetGammaRamp(IDirect3DDevice9Ex
*iface
,
682 UINT swapchain
, DWORD flags
, const D3DGAMMARAMP
*ramp
)
684 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
686 TRACE("iface %p, swapchain %u, flags %#x, ramp %p.\n", iface
, swapchain
, flags
, ramp
);
688 /* Note: D3DGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
689 wined3d_mutex_lock();
690 wined3d_device_set_gamma_ramp(device
->wined3d_device
, swapchain
, flags
, (const struct wined3d_gamma_ramp
*)ramp
);
691 wined3d_mutex_unlock();
694 static void WINAPI
d3d9_device_GetGammaRamp(IDirect3DDevice9Ex
*iface
, UINT swapchain
, D3DGAMMARAMP
*ramp
)
696 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
698 TRACE("iface %p, swapchain %u, ramp %p.\n", iface
, swapchain
, ramp
);
700 /* Note: D3DGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
701 wined3d_mutex_lock();
702 wined3d_device_get_gamma_ramp(device
->wined3d_device
, swapchain
, (struct wined3d_gamma_ramp
*)ramp
);
703 wined3d_mutex_unlock();
706 static HRESULT WINAPI
d3d9_device_CreateTexture(IDirect3DDevice9Ex
*iface
,
707 UINT width
, UINT height
, UINT levels
, DWORD usage
, D3DFORMAT format
,
708 D3DPOOL pool
, IDirect3DTexture9
**texture
, HANDLE
*shared_handle
)
710 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
711 struct d3d9_texture
*object
;
712 BOOL set_mem
= FALSE
;
715 TRACE("iface %p, width %u, height %u, levels %u, usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
716 iface
, width
, height
, levels
, usage
, format
, pool
, texture
, shared_handle
);
720 if (pool
== D3DPOOL_SYSTEMMEM
)
723 return D3DERR_INVALIDCALL
;
727 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
730 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
733 ERR("Failed to allocate texture memory.\n");
734 return D3DERR_OUTOFVIDEOMEMORY
;
737 hr
= texture_init(object
, device
, width
, height
, levels
, usage
, format
, pool
);
740 WARN("Failed to initialize texture, hr %#x.\n", hr
);
741 HeapFree(GetProcessHeap(), 0, object
);
747 struct wined3d_resource
*resource
;
748 struct d3d9_surface
*surface
;
750 resource
= wined3d_texture_get_sub_resource(object
->wined3d_texture
, 0);
751 surface
= wined3d_resource_get_parent(resource
);
752 wined3d_surface_set_mem(surface
->wined3d_surface
, *shared_handle
);
755 TRACE("Created texture %p.\n", object
);
756 *texture
= (IDirect3DTexture9
*)&object
->IDirect3DBaseTexture9_iface
;
761 static HRESULT WINAPI
d3d9_device_CreateVolumeTexture(IDirect3DDevice9Ex
*iface
,
762 UINT width
, UINT height
, UINT depth
, UINT levels
, DWORD usage
, D3DFORMAT format
,
763 D3DPOOL pool
, IDirect3DVolumeTexture9
**texture
, HANDLE
*shared_handle
)
765 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
766 struct d3d9_texture
*object
;
769 TRACE("iface %p, width %u, height %u, depth %u, levels %u\n",
770 iface
, width
, height
, depth
, levels
);
771 TRACE("usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
772 usage
, format
, pool
, texture
, shared_handle
);
775 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
777 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
780 ERR("Failed to allocate volume texture memory.\n");
781 return D3DERR_OUTOFVIDEOMEMORY
;
784 hr
= volumetexture_init(object
, device
, width
, height
, depth
, levels
, usage
, format
, pool
);
787 WARN("Failed to initialize volume texture, hr %#x.\n", hr
);
788 HeapFree(GetProcessHeap(), 0, object
);
792 TRACE("Created volume texture %p.\n", object
);
793 *texture
= (IDirect3DVolumeTexture9
*)&object
->IDirect3DBaseTexture9_iface
;
798 static HRESULT WINAPI
d3d9_device_CreateCubeTexture(IDirect3DDevice9Ex
*iface
,
799 UINT edge_length
, UINT levels
, DWORD usage
, D3DFORMAT format
, D3DPOOL pool
,
800 IDirect3DCubeTexture9
**texture
, HANDLE
*shared_handle
)
802 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
803 struct d3d9_texture
*object
;
806 TRACE("iface %p, edge_length %u, levels %u, usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
807 iface
, edge_length
, levels
, usage
, format
, pool
, texture
, shared_handle
);
810 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
812 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
815 ERR("Failed to allocate cube texture memory.\n");
816 return D3DERR_OUTOFVIDEOMEMORY
;
819 hr
= cubetexture_init(object
, device
, edge_length
, levels
, usage
, format
, pool
);
822 WARN("Failed to initialize cube texture, hr %#x.\n", hr
);
823 HeapFree(GetProcessHeap(), 0, object
);
827 TRACE("Created cube texture %p.\n", object
);
828 *texture
= (IDirect3DCubeTexture9
*)&object
->IDirect3DBaseTexture9_iface
;
833 static HRESULT WINAPI
d3d9_device_CreateVertexBuffer(IDirect3DDevice9Ex
*iface
, UINT size
,
834 DWORD usage
, DWORD fvf
, D3DPOOL pool
, IDirect3DVertexBuffer9
**buffer
,
835 HANDLE
*shared_handle
)
837 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
838 struct d3d9_vertexbuffer
*object
;
841 TRACE("iface %p, size %u, usage %#x, fvf %#x, pool %#x, buffer %p, shared_handle %p.\n",
842 iface
, size
, usage
, fvf
, pool
, buffer
, shared_handle
);
845 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
847 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
850 ERR("Failed to allocate buffer memory.\n");
851 return D3DERR_OUTOFVIDEOMEMORY
;
854 hr
= vertexbuffer_init(object
, device
, size
, usage
, fvf
, pool
);
857 WARN("Failed to initialize vertex buffer, hr %#x.\n", hr
);
858 HeapFree(GetProcessHeap(), 0, object
);
862 TRACE("Created vertex buffer %p.\n", object
);
863 *buffer
= &object
->IDirect3DVertexBuffer9_iface
;
868 static HRESULT WINAPI
d3d9_device_CreateIndexBuffer(IDirect3DDevice9Ex
*iface
, UINT size
,
869 DWORD usage
, D3DFORMAT format
, D3DPOOL pool
, IDirect3DIndexBuffer9
**buffer
,
870 HANDLE
*shared_handle
)
872 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
873 struct d3d9_indexbuffer
*object
;
876 TRACE("iface %p, size %u, usage %#x, format %#x, pool %#x, buffer %p, shared_handle %p.\n",
877 iface
, size
, usage
, format
, pool
, buffer
, shared_handle
);
880 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
882 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
885 ERR("Failed to allocate buffer memory.\n");
886 return D3DERR_OUTOFVIDEOMEMORY
;
889 hr
= indexbuffer_init(object
, device
, size
, usage
, format
, pool
);
892 WARN("Failed to initialize index buffer, hr %#x.\n", hr
);
893 HeapFree(GetProcessHeap(), 0, object
);
897 TRACE("Created index buffer %p.\n", object
);
898 *buffer
= &object
->IDirect3DIndexBuffer9_iface
;
903 static HRESULT
d3d9_device_create_surface(struct d3d9_device
*device
, UINT width
, UINT height
,
904 D3DFORMAT format
, BOOL lockable
, BOOL discard
, UINT level
, IDirect3DSurface9
**surface
,
905 UINT usage
, D3DPOOL pool
, D3DMULTISAMPLE_TYPE multisample_type
, DWORD multisample_quality
)
907 struct d3d9_surface
*object
;
910 TRACE("device %p, width %u, height %u, format %#x, lockable %#x, discard %#x, level %u, surface %p.\n"
911 "usage %#x, pool %#x, multisample_type %#x, multisample_quality %u.\n",
912 device
, width
, height
, format
, lockable
, discard
, level
, surface
, usage
, pool
,
913 multisample_type
, multisample_quality
);
915 if (!(object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
))))
917 FIXME("Failed to allocate surface memory.\n");
918 return D3DERR_OUTOFVIDEOMEMORY
;
921 hr
= surface_init(object
, device
, width
, height
, format
, lockable
, discard
,
922 level
, usage
, pool
, multisample_type
, multisample_quality
);
925 WARN("Failed to initialize surface, hr %#x.\n", hr
);
926 HeapFree(GetProcessHeap(), 0, object
);
930 TRACE("Created surface %p.\n", object
);
931 *surface
= &object
->IDirect3DSurface9_iface
;
936 static HRESULT WINAPI
d3d9_device_CreateRenderTarget(IDirect3DDevice9Ex
*iface
, UINT width
, UINT height
,
937 D3DFORMAT format
, D3DMULTISAMPLE_TYPE multisample_type
, DWORD multisample_quality
,
938 BOOL lockable
, IDirect3DSurface9
**surface
, HANDLE
*shared_handle
)
940 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
943 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u.\n"
944 "lockable %#x, surface %p, shared_handle %p.\n",
945 iface
, width
, height
, format
, multisample_type
, multisample_quality
,
946 lockable
, surface
, shared_handle
);
949 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
951 hr
= d3d9_device_create_surface(device
, width
, height
, format
, lockable
, FALSE
, 0, surface
,
952 D3DUSAGE_RENDERTARGET
, D3DPOOL_DEFAULT
, multisample_type
, multisample_quality
);
957 static HRESULT WINAPI
d3d9_device_CreateDepthStencilSurface(IDirect3DDevice9Ex
*iface
, UINT width
, UINT height
,
958 D3DFORMAT format
, D3DMULTISAMPLE_TYPE multisample_type
, DWORD multisample_quality
,
959 BOOL discard
, IDirect3DSurface9
**surface
, HANDLE
*shared_handle
)
961 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
964 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u.\n"
965 "discard %#x, surface %p, shared_handle %p.\n",
966 iface
, width
, height
, format
, multisample_type
, multisample_quality
,
967 discard
, surface
, shared_handle
);
970 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
972 hr
= d3d9_device_create_surface(device
, width
, height
, format
, TRUE
, discard
, 0, surface
,
973 D3DUSAGE_DEPTHSTENCIL
, D3DPOOL_DEFAULT
, multisample_type
, multisample_quality
);
979 static HRESULT WINAPI
d3d9_device_UpdateSurface(IDirect3DDevice9Ex
*iface
,
980 IDirect3DSurface9
*src_surface
, const RECT
*src_rect
,
981 IDirect3DSurface9
*dst_surface
, const POINT
*dst_point
)
983 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
984 struct d3d9_surface
*src
= unsafe_impl_from_IDirect3DSurface9(src_surface
);
985 struct d3d9_surface
*dst
= unsafe_impl_from_IDirect3DSurface9(dst_surface
);
988 TRACE("iface %p, src_surface %p, src_rect %p, dst_surface %p, dst_point %p.\n",
989 iface
, src_surface
, src_rect
, dst_surface
, dst_point
);
991 wined3d_mutex_lock();
992 hr
= wined3d_device_update_surface(device
->wined3d_device
, src
->wined3d_surface
, src_rect
,
993 dst
->wined3d_surface
, dst_point
);
994 wined3d_mutex_unlock();
999 static HRESULT WINAPI
d3d9_device_UpdateTexture(IDirect3DDevice9Ex
*iface
,
1000 IDirect3DBaseTexture9
*src_texture
, IDirect3DBaseTexture9
*dst_texture
)
1002 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1003 struct d3d9_texture
*src_impl
, *dst_impl
;
1006 TRACE("iface %p, src_texture %p, dst_texture %p.\n", iface
, src_texture
, dst_texture
);
1008 src_impl
= unsafe_impl_from_IDirect3DBaseTexture9(src_texture
);
1009 dst_impl
= unsafe_impl_from_IDirect3DBaseTexture9(dst_texture
);
1011 wined3d_mutex_lock();
1012 hr
= wined3d_device_update_texture(device
->wined3d_device
,
1013 src_impl
->wined3d_texture
, dst_impl
->wined3d_texture
);
1014 wined3d_mutex_unlock();
1019 static HRESULT WINAPI
d3d9_device_GetRenderTargetData(IDirect3DDevice9Ex
*iface
,
1020 IDirect3DSurface9
*render_target
, IDirect3DSurface9
*dst_surface
)
1022 struct d3d9_surface
*rt_impl
= unsafe_impl_from_IDirect3DSurface9(render_target
);
1023 struct d3d9_surface
*dst_impl
= unsafe_impl_from_IDirect3DSurface9(dst_surface
);
1026 TRACE("iface %p, render_target %p, dst_surface %p.\n", iface
, render_target
, dst_surface
);
1028 wined3d_mutex_lock();
1029 hr
= wined3d_surface_get_render_target_data(dst_impl
->wined3d_surface
, rt_impl
->wined3d_surface
);
1030 wined3d_mutex_unlock();
1035 static HRESULT WINAPI
d3d9_device_GetFrontBufferData(IDirect3DDevice9Ex
*iface
,
1036 UINT swapchain
, IDirect3DSurface9
*dst_surface
)
1038 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1039 struct d3d9_surface
*dst_impl
= unsafe_impl_from_IDirect3DSurface9(dst_surface
);
1042 TRACE("iface %p, swapchain %u, dst_surface %p.\n", iface
, swapchain
, dst_surface
);
1044 wined3d_mutex_lock();
1045 hr
= wined3d_device_get_front_buffer_data(device
->wined3d_device
, swapchain
, dst_impl
->wined3d_surface
);
1046 wined3d_mutex_unlock();
1051 static HRESULT WINAPI
d3d9_device_StretchRect(IDirect3DDevice9Ex
*iface
, IDirect3DSurface9
*src_surface
,
1052 const RECT
*src_rect
, IDirect3DSurface9
*dst_surface
, const RECT
*dst_rect
, D3DTEXTUREFILTERTYPE filter
)
1054 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1055 struct d3d9_surface
*src
= unsafe_impl_from_IDirect3DSurface9(src_surface
);
1056 struct d3d9_surface
*dst
= unsafe_impl_from_IDirect3DSurface9(dst_surface
);
1057 HRESULT hr
= D3DERR_INVALIDCALL
;
1058 struct wined3d_resource_desc src_desc
, dst_desc
;
1059 struct wined3d_resource
*wined3d_resource
;
1061 TRACE("iface %p, src_surface %p, src_rect %p, dst_surface %p, dst_rect %p, filter %#x.\n",
1062 iface
, src_surface
, src_rect
, dst_surface
, dst_rect
, filter
);
1064 wined3d_mutex_lock();
1065 wined3d_resource
= wined3d_surface_get_resource(dst
->wined3d_surface
);
1066 wined3d_resource_get_desc(wined3d_resource
, &dst_desc
);
1068 wined3d_resource
= wined3d_surface_get_resource(src
->wined3d_surface
);
1069 wined3d_resource_get_desc(wined3d_resource
, &src_desc
);
1071 if (src_desc
.usage
& WINED3DUSAGE_DEPTHSTENCIL
)
1073 if (device
->in_scene
)
1075 WARN("Rejecting depth / stencil blit while in scene.\n");
1081 if (src_rect
->left
|| src_rect
->top
|| src_rect
->right
!= src_desc
.width
1082 || src_rect
->bottom
!= src_desc
.height
)
1084 WARN("Rejecting depth / stencil blit with invalid source rect %s.\n",
1085 wine_dbgstr_rect(src_rect
));
1091 if (dst_rect
->left
|| dst_rect
->top
|| dst_rect
->right
!= dst_desc
.width
1092 || dst_rect
->bottom
!= dst_desc
.height
)
1094 WARN("Rejecting depth / stencil blit with invalid destination rect %s.\n",
1095 wine_dbgstr_rect(dst_rect
));
1099 if (src_desc
.width
!= dst_desc
.width
|| src_desc
.height
!= dst_desc
.height
)
1101 WARN("Rejecting depth / stencil blit with mismatched surface sizes.\n");
1106 hr
= wined3d_surface_blt(dst
->wined3d_surface
, dst_rect
, src
->wined3d_surface
, src_rect
, 0, NULL
, filter
);
1107 if (hr
== WINEDDERR_INVALIDRECT
)
1108 hr
= D3DERR_INVALIDCALL
;
1111 wined3d_mutex_unlock();
1115 static HRESULT WINAPI
d3d9_device_ColorFill(IDirect3DDevice9Ex
*iface
,
1116 IDirect3DSurface9
*surface
, const RECT
*rect
, D3DCOLOR color
)
1118 const struct wined3d_color c
=
1120 ((color
>> 16) & 0xff) / 255.0f
,
1121 ((color
>> 8) & 0xff) / 255.0f
,
1122 (color
& 0xff) / 255.0f
,
1123 ((color
>> 24) & 0xff) / 255.0f
,
1125 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1126 struct d3d9_surface
*surface_impl
= unsafe_impl_from_IDirect3DSurface9(surface
);
1127 struct wined3d_resource
*wined3d_resource
;
1128 struct wined3d_resource_desc desc
;
1131 TRACE("iface %p, surface %p, rect %p, color 0x%08x.\n", iface
, surface
, rect
, color
);
1133 wined3d_mutex_lock();
1135 wined3d_resource
= wined3d_surface_get_resource(surface_impl
->wined3d_surface
);
1136 wined3d_resource_get_desc(wined3d_resource
, &desc
);
1138 /* This method is only allowed with surfaces that are render targets, or
1139 * offscreen plain surfaces in D3DPOOL_DEFAULT. */
1140 if (!(desc
.usage
& WINED3DUSAGE_RENDERTARGET
) && desc
.pool
!= WINED3D_POOL_DEFAULT
)
1142 wined3d_mutex_unlock();
1143 WARN("Surface is not a render target, or not a stand-alone D3DPOOL_DEFAULT surface\n");
1144 return D3DERR_INVALIDCALL
;
1147 /* Colorfill can only be used on rendertarget surfaces, or offscreen plain surfaces in D3DPOOL_DEFAULT */
1148 hr
= wined3d_device_color_fill(device
->wined3d_device
, surface_impl
->wined3d_surface
, rect
, &c
);
1150 wined3d_mutex_unlock();
1155 static HRESULT WINAPI
d3d9_device_CreateOffscreenPlainSurface(IDirect3DDevice9Ex
*iface
,
1156 UINT width
, UINT height
, D3DFORMAT format
, D3DPOOL pool
, IDirect3DSurface9
**surface
,
1157 HANDLE
*shared_handle
)
1159 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1161 TRACE("iface %p, width %u, height %u, format %#x, pool %#x, surface %p, shared_handle %p.\n",
1162 iface
, width
, height
, format
, pool
, surface
, shared_handle
);
1165 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
1167 if (pool
== D3DPOOL_MANAGED
)
1169 WARN("Attempting to create a managed offscreen plain surface.\n");
1170 return D3DERR_INVALIDCALL
;
1172 /* FIXME: Offscreen surfaces are supposed to be always lockable,
1173 * regardless of the pool they're created in. Should we set dynamic usage
1175 return d3d9_device_create_surface(device
, width
, height
, format
, TRUE
,
1176 FALSE
, 0, surface
, 0, pool
, D3DMULTISAMPLE_NONE
, 0);
1179 static HRESULT WINAPI
d3d9_device_SetRenderTarget(IDirect3DDevice9Ex
*iface
, DWORD idx
, IDirect3DSurface9
*surface
)
1181 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1182 struct d3d9_surface
*surface_impl
= unsafe_impl_from_IDirect3DSurface9(surface
);
1185 TRACE("iface %p, idx %u, surface %p.\n", iface
, idx
, surface
);
1187 if (idx
>= D3D9_MAX_SIMULTANEOUS_RENDERTARGETS
)
1189 WARN("Invalid index %u specified.\n", idx
);
1190 return D3DERR_INVALIDCALL
;
1193 wined3d_mutex_lock();
1194 hr
= wined3d_device_set_render_target(device
->wined3d_device
, idx
,
1195 surface_impl
? surface_impl
->wined3d_surface
: NULL
, TRUE
);
1196 wined3d_mutex_unlock();
1201 static HRESULT WINAPI
d3d9_device_GetRenderTarget(IDirect3DDevice9Ex
*iface
, DWORD idx
, IDirect3DSurface9
**surface
)
1203 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1204 struct wined3d_surface
*wined3d_surface
;
1205 struct d3d9_surface
*surface_impl
;
1208 TRACE("iface %p, idx %u, surface %p.\n", iface
, idx
, surface
);
1211 return D3DERR_INVALIDCALL
;
1213 if (idx
>= D3D9_MAX_SIMULTANEOUS_RENDERTARGETS
)
1215 WARN("Invalid index %u specified.\n", idx
);
1216 return D3DERR_INVALIDCALL
;
1219 wined3d_mutex_lock();
1220 hr
= wined3d_device_get_render_target(device
->wined3d_device
, idx
, &wined3d_surface
);
1223 surface_impl
= wined3d_surface_get_parent(wined3d_surface
);
1224 *surface
= &surface_impl
->IDirect3DSurface9_iface
;
1225 IDirect3DSurface9_AddRef(*surface
);
1226 wined3d_surface_decref(wined3d_surface
);
1230 if (hr
!= WINED3DERR_NOTFOUND
)
1231 WARN("Failed to get render target %u, hr %#x.\n", idx
, hr
);
1234 wined3d_mutex_unlock();
1239 static HRESULT WINAPI
d3d9_device_SetDepthStencilSurface(IDirect3DDevice9Ex
*iface
, IDirect3DSurface9
*depth_stencil
)
1241 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1242 struct d3d9_surface
*ds_impl
= unsafe_impl_from_IDirect3DSurface9(depth_stencil
);
1245 TRACE("iface %p, depth_stencil %p.\n", iface
, depth_stencil
);
1247 wined3d_mutex_lock();
1248 hr
= wined3d_device_set_depth_stencil(device
->wined3d_device
, ds_impl
? ds_impl
->wined3d_surface
: NULL
);
1249 wined3d_mutex_unlock();
1254 static HRESULT WINAPI
d3d9_device_GetDepthStencilSurface(IDirect3DDevice9Ex
*iface
, IDirect3DSurface9
**depth_stencil
)
1256 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1257 struct wined3d_surface
*wined3d_surface
;
1258 struct d3d9_surface
*surface_impl
;
1261 TRACE("iface %p, depth_stencil %p.\n", iface
, depth_stencil
);
1264 return D3DERR_INVALIDCALL
;
1266 wined3d_mutex_lock();
1267 hr
= wined3d_device_get_depth_stencil(device
->wined3d_device
, &wined3d_surface
);
1270 surface_impl
= wined3d_surface_get_parent(wined3d_surface
);
1271 *depth_stencil
= &surface_impl
->IDirect3DSurface9_iface
;
1272 IDirect3DSurface9_AddRef(*depth_stencil
);
1273 wined3d_surface_decref(wined3d_surface
);
1277 if (hr
!= WINED3DERR_NOTFOUND
)
1278 WARN("Call to IWineD3DDevice_GetDepthStencilSurface failed with 0x%08x\n", hr
);
1279 *depth_stencil
= NULL
;
1281 wined3d_mutex_unlock();
1286 static HRESULT WINAPI
d3d9_device_BeginScene(IDirect3DDevice9Ex
*iface
)
1288 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1291 TRACE("iface %p.\n", iface
);
1293 wined3d_mutex_lock();
1294 if (SUCCEEDED(hr
= wined3d_device_begin_scene(device
->wined3d_device
)))
1295 device
->in_scene
= TRUE
;
1296 wined3d_mutex_unlock();
1301 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_device_EndScene(IDirect3DDevice9Ex
*iface
)
1303 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1306 TRACE("iface %p.\n", iface
);
1308 wined3d_mutex_lock();
1309 if (SUCCEEDED(hr
= wined3d_device_end_scene(device
->wined3d_device
)))
1310 device
->in_scene
= FALSE
;
1311 wined3d_mutex_unlock();
1316 static HRESULT WINAPI
d3d9_device_Clear(IDirect3DDevice9Ex
*iface
, DWORD rect_count
,
1317 const D3DRECT
*rects
, DWORD flags
, D3DCOLOR color
, float z
, DWORD stencil
)
1319 const struct wined3d_color c
=
1321 ((color
>> 16) & 0xff) / 255.0f
,
1322 ((color
>> 8) & 0xff) / 255.0f
,
1323 (color
& 0xff) / 255.0f
,
1324 ((color
>> 24) & 0xff) / 255.0f
,
1326 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1329 TRACE("iface %p, rect_count %u, rects %p, flags %#x, color 0x%08x, z %.8e, stencil %u.\n",
1330 iface
, rect_count
, rects
, flags
, color
, z
, stencil
);
1332 wined3d_mutex_lock();
1333 hr
= wined3d_device_clear(device
->wined3d_device
, rect_count
, (const RECT
*)rects
, flags
, &c
, z
, stencil
);
1334 wined3d_mutex_unlock();
1339 static HRESULT WINAPI
d3d9_device_SetTransform(IDirect3DDevice9Ex
*iface
,
1340 D3DTRANSFORMSTATETYPE state
, const D3DMATRIX
*matrix
)
1342 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1345 TRACE("iface %p, state %#x, matrix %p.\n", iface
, state
, matrix
);
1347 /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
1348 wined3d_mutex_lock();
1349 hr
= wined3d_device_set_transform(device
->wined3d_device
, state
, (const struct wined3d_matrix
*)matrix
);
1350 wined3d_mutex_unlock();
1355 static HRESULT WINAPI
d3d9_device_GetTransform(IDirect3DDevice9Ex
*iface
,
1356 D3DTRANSFORMSTATETYPE state
, D3DMATRIX
*matrix
)
1358 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1361 TRACE("iface %p, state %#x, matrix %p.\n", iface
, state
, matrix
);
1363 /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
1364 wined3d_mutex_lock();
1365 hr
= wined3d_device_get_transform(device
->wined3d_device
, state
, (struct wined3d_matrix
*)matrix
);
1366 wined3d_mutex_unlock();
1371 static HRESULT WINAPI
d3d9_device_MultiplyTransform(IDirect3DDevice9Ex
*iface
,
1372 D3DTRANSFORMSTATETYPE state
, const D3DMATRIX
*matrix
)
1374 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1377 TRACE("iface %p, state %#x, matrix %p.\n", iface
, state
, matrix
);
1379 /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
1380 wined3d_mutex_lock();
1381 hr
= wined3d_device_multiply_transform(device
->wined3d_device
, state
, (const struct wined3d_matrix
*)matrix
);
1382 wined3d_mutex_unlock();
1387 static HRESULT WINAPI
d3d9_device_SetViewport(IDirect3DDevice9Ex
*iface
, const D3DVIEWPORT9
*viewport
)
1389 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1392 TRACE("iface %p, viewport %p.\n", iface
, viewport
);
1394 /* Note: D3DVIEWPORT9 is compatible with struct wined3d_viewport. */
1395 wined3d_mutex_lock();
1396 hr
= wined3d_device_set_viewport(device
->wined3d_device
, (const struct wined3d_viewport
*)viewport
);
1397 wined3d_mutex_unlock();
1402 static HRESULT WINAPI
d3d9_device_GetViewport(IDirect3DDevice9Ex
*iface
, D3DVIEWPORT9
*viewport
)
1404 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1407 TRACE("iface %p, viewport %p.\n", iface
, viewport
);
1409 /* Note: D3DVIEWPORT9 is compatible with struct wined3d_viewport. */
1410 wined3d_mutex_lock();
1411 hr
= wined3d_device_get_viewport(device
->wined3d_device
, (struct wined3d_viewport
*)viewport
);
1412 wined3d_mutex_unlock();
1417 static HRESULT WINAPI
d3d9_device_SetMaterial(IDirect3DDevice9Ex
*iface
, const D3DMATERIAL9
*material
)
1419 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1422 TRACE("iface %p, material %p.\n", iface
, material
);
1424 /* Note: D3DMATERIAL9 is compatible with struct wined3d_material. */
1425 wined3d_mutex_lock();
1426 hr
= wined3d_device_set_material(device
->wined3d_device
, (const struct wined3d_material
*)material
);
1427 wined3d_mutex_unlock();
1432 static HRESULT WINAPI
d3d9_device_GetMaterial(IDirect3DDevice9Ex
*iface
, D3DMATERIAL9
*material
)
1434 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1437 TRACE("iface %p, material %p.\n", iface
, material
);
1439 /* Note: D3DMATERIAL9 is compatible with struct wined3d_material. */
1440 wined3d_mutex_lock();
1441 hr
= wined3d_device_get_material(device
->wined3d_device
, (struct wined3d_material
*)material
);
1442 wined3d_mutex_unlock();
1447 static HRESULT WINAPI
d3d9_device_SetLight(IDirect3DDevice9Ex
*iface
, DWORD index
, const D3DLIGHT9
*light
)
1449 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1452 TRACE("iface %p, index %u, light %p.\n", iface
, index
, light
);
1454 /* Note: D3DLIGHT9 is compatible with struct wined3d_light. */
1455 wined3d_mutex_lock();
1456 hr
= wined3d_device_set_light(device
->wined3d_device
, index
, (const struct wined3d_light
*)light
);
1457 wined3d_mutex_unlock();
1462 static HRESULT WINAPI
d3d9_device_GetLight(IDirect3DDevice9Ex
*iface
, DWORD index
, D3DLIGHT9
*light
)
1464 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1467 TRACE("iface %p, index %u, light %p.\n", iface
, index
, light
);
1469 /* Note: D3DLIGHT9 is compatible with struct wined3d_light. */
1470 wined3d_mutex_lock();
1471 hr
= wined3d_device_get_light(device
->wined3d_device
, index
, (struct wined3d_light
*)light
);
1472 wined3d_mutex_unlock();
1477 static HRESULT WINAPI
d3d9_device_LightEnable(IDirect3DDevice9Ex
*iface
, DWORD index
, BOOL enable
)
1479 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1482 TRACE("iface %p, index %u, enable %#x.\n", iface
, index
, enable
);
1484 wined3d_mutex_lock();
1485 hr
= wined3d_device_set_light_enable(device
->wined3d_device
, index
, enable
);
1486 wined3d_mutex_unlock();
1491 static HRESULT WINAPI
d3d9_device_GetLightEnable(IDirect3DDevice9Ex
*iface
, DWORD index
, BOOL
*enable
)
1493 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1496 TRACE("iface %p, index %u, enable %p.\n", iface
, index
, enable
);
1498 wined3d_mutex_lock();
1499 hr
= wined3d_device_get_light_enable(device
->wined3d_device
, index
, enable
);
1500 wined3d_mutex_unlock();
1505 static HRESULT WINAPI
d3d9_device_SetClipPlane(IDirect3DDevice9Ex
*iface
, DWORD index
, const float *plane
)
1507 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1510 TRACE("iface %p, index %u, plane %p.\n", iface
, index
, plane
);
1512 wined3d_mutex_lock();
1513 hr
= wined3d_device_set_clip_plane(device
->wined3d_device
, index
, (const struct wined3d_vec4
*)plane
);
1514 wined3d_mutex_unlock();
1519 static HRESULT WINAPI
d3d9_device_GetClipPlane(IDirect3DDevice9Ex
*iface
, DWORD index
, float *plane
)
1521 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1524 TRACE("iface %p, index %u, plane %p.\n", iface
, index
, plane
);
1526 wined3d_mutex_lock();
1527 hr
= wined3d_device_get_clip_plane(device
->wined3d_device
, index
, (struct wined3d_vec4
*)plane
);
1528 wined3d_mutex_unlock();
1533 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_device_SetRenderState(IDirect3DDevice9Ex
*iface
,
1534 D3DRENDERSTATETYPE state
, DWORD value
)
1536 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1539 TRACE("iface %p, state %#x, value %#x.\n", iface
, state
, value
);
1541 wined3d_mutex_lock();
1542 hr
= wined3d_device_set_render_state(device
->wined3d_device
, state
, value
);
1543 wined3d_mutex_unlock();
1548 static HRESULT WINAPI
d3d9_device_GetRenderState(IDirect3DDevice9Ex
*iface
,
1549 D3DRENDERSTATETYPE state
, DWORD
*value
)
1551 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1554 TRACE("iface %p, state %#x, value %p.\n", iface
, state
, value
);
1556 wined3d_mutex_lock();
1557 hr
= wined3d_device_get_render_state(device
->wined3d_device
, state
, value
);
1558 wined3d_mutex_unlock();
1563 static HRESULT WINAPI
d3d9_device_CreateStateBlock(IDirect3DDevice9Ex
*iface
,
1564 D3DSTATEBLOCKTYPE type
, IDirect3DStateBlock9
**stateblock
)
1566 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1567 struct d3d9_stateblock
*object
;
1570 TRACE("iface %p, type %#x, stateblock %p.\n", iface
, type
, stateblock
);
1572 if (type
!= D3DSBT_ALL
&& type
!= D3DSBT_PIXELSTATE
&& type
!= D3DSBT_VERTEXSTATE
)
1574 WARN("Unexpected stateblock type, returning D3DERR_INVALIDCALL.\n");
1575 return D3DERR_INVALIDCALL
;
1578 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
1581 ERR("Failed to allocate stateblock memory.\n");
1582 return E_OUTOFMEMORY
;
1585 hr
= stateblock_init(object
, device
, type
, NULL
);
1588 WARN("Failed to initialize stateblock, hr %#x.\n", hr
);
1589 HeapFree(GetProcessHeap(), 0, object
);
1593 TRACE("Created stateblock %p.\n", object
);
1594 *stateblock
= &object
->IDirect3DStateBlock9_iface
;
1599 static HRESULT WINAPI
d3d9_device_BeginStateBlock(IDirect3DDevice9Ex
*iface
)
1601 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1604 TRACE("iface %p.\n", iface
);
1606 wined3d_mutex_lock();
1607 hr
= wined3d_device_begin_stateblock(device
->wined3d_device
);
1608 wined3d_mutex_unlock();
1613 static HRESULT WINAPI
d3d9_device_EndStateBlock(IDirect3DDevice9Ex
*iface
, IDirect3DStateBlock9
**stateblock
)
1615 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1616 struct wined3d_stateblock
*wined3d_stateblock
;
1617 struct d3d9_stateblock
*object
;
1620 TRACE("iface %p, stateblock %p.\n", iface
, stateblock
);
1622 wined3d_mutex_lock();
1623 hr
= wined3d_device_end_stateblock(device
->wined3d_device
, &wined3d_stateblock
);
1624 wined3d_mutex_unlock();
1627 WARN("IWineD3DDevice_EndStateBlock() failed, hr %#x.\n", hr
);
1631 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
1634 ERR("Failed to allocate stateblock memory.\n");
1635 wined3d_mutex_lock();
1636 wined3d_stateblock_decref(wined3d_stateblock
);
1637 wined3d_mutex_unlock();
1638 return E_OUTOFMEMORY
;
1641 hr
= stateblock_init(object
, device
, 0, wined3d_stateblock
);
1644 WARN("Failed to initialize stateblock, hr %#x.\n", hr
);
1645 wined3d_mutex_lock();
1646 wined3d_stateblock_decref(wined3d_stateblock
);
1647 wined3d_mutex_unlock();
1648 HeapFree(GetProcessHeap(), 0, object
);
1652 TRACE("Created stateblock %p.\n", object
);
1653 *stateblock
= &object
->IDirect3DStateBlock9_iface
;
1658 static HRESULT WINAPI
d3d9_device_SetClipStatus(IDirect3DDevice9Ex
*iface
, const 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_set_clip_status(device
->wined3d_device
, (const struct wined3d_clip_status
*)clip_status
);
1667 wined3d_mutex_unlock();
1672 static HRESULT WINAPI
d3d9_device_GetClipStatus(IDirect3DDevice9Ex
*iface
, D3DCLIPSTATUS9
*clip_status
)
1674 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1677 TRACE("iface %p, clip_status %p.\n", iface
, clip_status
);
1679 wined3d_mutex_lock();
1680 hr
= wined3d_device_get_clip_status(device
->wined3d_device
, (struct wined3d_clip_status
*)clip_status
);
1681 wined3d_mutex_unlock();
1686 static HRESULT WINAPI
d3d9_device_GetTexture(IDirect3DDevice9Ex
*iface
, DWORD stage
, IDirect3DBaseTexture9
**texture
)
1688 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1689 struct wined3d_texture
*wined3d_texture
= NULL
;
1690 struct d3d9_texture
*texture_impl
;
1693 TRACE("iface %p, stage %u, texture %p.\n", iface
, stage
, texture
);
1696 return D3DERR_INVALIDCALL
;
1698 wined3d_mutex_lock();
1699 hr
= wined3d_device_get_texture(device
->wined3d_device
, stage
, &wined3d_texture
);
1700 if (SUCCEEDED(hr
) && wined3d_texture
)
1702 texture_impl
= wined3d_texture_get_parent(wined3d_texture
);
1703 *texture
= &texture_impl
->IDirect3DBaseTexture9_iface
;
1704 IDirect3DBaseTexture9_AddRef(*texture
);
1705 wined3d_texture_decref(wined3d_texture
);
1710 WARN("Call to get texture (%u) failed (%p).\n", stage
, wined3d_texture
);
1713 wined3d_mutex_unlock();
1718 static HRESULT WINAPI
d3d9_device_SetTexture(IDirect3DDevice9Ex
*iface
, DWORD stage
, IDirect3DBaseTexture9
*texture
)
1720 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1721 struct d3d9_texture
*texture_impl
;
1724 TRACE("iface %p, stage %u, texture %p.\n", iface
, stage
, texture
);
1726 texture_impl
= unsafe_impl_from_IDirect3DBaseTexture9(texture
);
1728 wined3d_mutex_lock();
1729 hr
= wined3d_device_set_texture(device
->wined3d_device
, stage
,
1730 texture_impl
? texture_impl
->wined3d_texture
: NULL
);
1731 wined3d_mutex_unlock();
1736 static const enum wined3d_texture_stage_state tss_lookup
[] =
1738 WINED3D_TSS_INVALID
, /* 0, unused */
1739 WINED3D_TSS_COLOR_OP
, /* 1, D3DTSS_COLOROP */
1740 WINED3D_TSS_COLOR_ARG1
, /* 2, D3DTSS_COLORARG1 */
1741 WINED3D_TSS_COLOR_ARG2
, /* 3, D3DTSS_COLORARG2 */
1742 WINED3D_TSS_ALPHA_OP
, /* 4, D3DTSS_ALPHAOP */
1743 WINED3D_TSS_ALPHA_ARG1
, /* 5, D3DTSS_ALPHAARG1 */
1744 WINED3D_TSS_ALPHA_ARG2
, /* 6, D3DTSS_ALPHAARG2 */
1745 WINED3D_TSS_BUMPENV_MAT00
, /* 7, D3DTSS_BUMPENVMAT00 */
1746 WINED3D_TSS_BUMPENV_MAT01
, /* 8, D3DTSS_BUMPENVMAT01 */
1747 WINED3D_TSS_BUMPENV_MAT10
, /* 9, D3DTSS_BUMPENVMAT10 */
1748 WINED3D_TSS_BUMPENV_MAT11
, /* 10, D3DTSS_BUMPENVMAT11 */
1749 WINED3D_TSS_TEXCOORD_INDEX
, /* 11, D3DTSS_TEXCOORDINDEX */
1750 WINED3D_TSS_INVALID
, /* 12, unused */
1751 WINED3D_TSS_INVALID
, /* 13, unused */
1752 WINED3D_TSS_INVALID
, /* 14, unused */
1753 WINED3D_TSS_INVALID
, /* 15, unused */
1754 WINED3D_TSS_INVALID
, /* 16, unused */
1755 WINED3D_TSS_INVALID
, /* 17, unused */
1756 WINED3D_TSS_INVALID
, /* 18, unused */
1757 WINED3D_TSS_INVALID
, /* 19, unused */
1758 WINED3D_TSS_INVALID
, /* 20, unused */
1759 WINED3D_TSS_INVALID
, /* 21, unused */
1760 WINED3D_TSS_BUMPENV_LSCALE
, /* 22, D3DTSS_BUMPENVLSCALE */
1761 WINED3D_TSS_BUMPENV_LOFFSET
, /* 23, D3DTSS_BUMPENVLOFFSET */
1762 WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS
, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
1763 WINED3D_TSS_INVALID
, /* 25, unused */
1764 WINED3D_TSS_COLOR_ARG0
, /* 26, D3DTSS_COLORARG0 */
1765 WINED3D_TSS_ALPHA_ARG0
, /* 27, D3DTSS_ALPHAARG0 */
1766 WINED3D_TSS_RESULT_ARG
, /* 28, D3DTSS_RESULTARG */
1767 WINED3D_TSS_INVALID
, /* 29, unused */
1768 WINED3D_TSS_INVALID
, /* 30, unused */
1769 WINED3D_TSS_INVALID
, /* 31, unused */
1770 WINED3D_TSS_CONSTANT
, /* 32, D3DTSS_CONSTANT */
1773 static HRESULT WINAPI
d3d9_device_GetTextureStageState(IDirect3DDevice9Ex
*iface
,
1774 DWORD stage
, D3DTEXTURESTAGESTATETYPE state
, DWORD
*value
)
1776 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1779 TRACE("iface %p, stage %u, state %#x, value %p.\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 hr
= wined3d_device_get_texture_stage_state(device
->wined3d_device
, stage
, tss_lookup
[state
], value
);
1789 wined3d_mutex_unlock();
1794 static HRESULT WINAPI
d3d9_device_SetTextureStageState(IDirect3DDevice9Ex
*iface
,
1795 DWORD stage
, D3DTEXTURESTAGESTATETYPE state
, DWORD value
)
1797 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1800 TRACE("iface %p, stage %u, state %#x, value %#x.\n", iface
, stage
, state
, value
);
1802 if (state
>= sizeof(tss_lookup
) / sizeof(*tss_lookup
))
1804 WARN("Invalid state %#x passed.\n", state
);
1808 wined3d_mutex_lock();
1809 hr
= wined3d_device_set_texture_stage_state(device
->wined3d_device
, stage
, tss_lookup
[state
], value
);
1810 wined3d_mutex_unlock();
1815 static HRESULT WINAPI
d3d9_device_GetSamplerState(IDirect3DDevice9Ex
*iface
,
1816 DWORD sampler
, D3DSAMPLERSTATETYPE state
, DWORD
*value
)
1818 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1821 TRACE("iface %p, sampler %u, state %#x, value %p.\n", iface
, sampler
, state
, value
);
1823 wined3d_mutex_lock();
1824 hr
= wined3d_device_get_sampler_state(device
->wined3d_device
, sampler
, state
, value
);
1825 wined3d_mutex_unlock();
1830 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_device_SetSamplerState(IDirect3DDevice9Ex
*iface
,
1831 DWORD sampler
, D3DSAMPLERSTATETYPE state
, DWORD value
)
1833 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1836 TRACE("iface %p, sampler %u, state %#x, value %#x.\n", iface
, sampler
, state
, value
);
1838 wined3d_mutex_lock();
1839 hr
= wined3d_device_set_sampler_state(device
->wined3d_device
, sampler
, state
, value
);
1840 wined3d_mutex_unlock();
1845 static HRESULT WINAPI
d3d9_device_ValidateDevice(IDirect3DDevice9Ex
*iface
, DWORD
*pass_count
)
1847 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1850 TRACE("iface %p, pass_count %p.\n", iface
, pass_count
);
1852 wined3d_mutex_lock();
1853 hr
= wined3d_device_validate_device(device
->wined3d_device
, pass_count
);
1854 wined3d_mutex_unlock();
1859 static HRESULT WINAPI
d3d9_device_SetPaletteEntries(IDirect3DDevice9Ex
*iface
,
1860 UINT palette_idx
, const PALETTEENTRY
*entries
)
1862 FIXME("iface %p, palette_idx %u, entries %p unimplemented.\n", iface
, palette_idx
, entries
);
1864 return D3DERR_INVALIDCALL
;
1867 static HRESULT WINAPI
d3d9_device_GetPaletteEntries(IDirect3DDevice9Ex
*iface
,
1868 UINT palette_idx
, PALETTEENTRY
*entries
)
1870 FIXME("iface %p, palette_idx %u, entries %p unimplemented.\n", iface
, palette_idx
, entries
);
1872 return D3DERR_INVALIDCALL
;
1875 static HRESULT WINAPI
d3d9_device_SetCurrentTexturePalette(IDirect3DDevice9Ex
*iface
, UINT palette_idx
)
1877 FIXME("iface %p, palette_idx %u unimplemented.\n", iface
, palette_idx
);
1879 return D3DERR_INVALIDCALL
;
1882 static HRESULT WINAPI
d3d9_device_GetCurrentTexturePalette(IDirect3DDevice9Ex
*iface
, UINT
*palette_idx
)
1884 FIXME("iface %p, palette_idx %p.\n", iface
, palette_idx
);
1886 return D3DERR_INVALIDCALL
;
1889 static HRESULT WINAPI
d3d9_device_SetScissorRect(IDirect3DDevice9Ex
*iface
, const RECT
*rect
)
1891 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1894 TRACE("iface %p, rect %p.\n", iface
, rect
);
1896 wined3d_mutex_lock();
1897 hr
= wined3d_device_set_scissor_rect(device
->wined3d_device
, rect
);
1898 wined3d_mutex_unlock();
1903 static HRESULT WINAPI
d3d9_device_GetScissorRect(IDirect3DDevice9Ex
*iface
, RECT
*rect
)
1905 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1908 TRACE("iface %p, rect %p.\n", iface
, rect
);
1910 wined3d_mutex_lock();
1911 hr
= wined3d_device_get_scissor_rect(device
->wined3d_device
, rect
);
1912 wined3d_mutex_unlock();
1917 static HRESULT WINAPI
d3d9_device_SetSoftwareVertexProcessing(IDirect3DDevice9Ex
*iface
, BOOL software
)
1919 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1922 TRACE("iface %p, software %#x.\n", iface
, software
);
1924 wined3d_mutex_lock();
1925 hr
= wined3d_device_set_software_vertex_processing(device
->wined3d_device
, software
);
1926 wined3d_mutex_unlock();
1931 static BOOL WINAPI
d3d9_device_GetSoftwareVertexProcessing(IDirect3DDevice9Ex
*iface
)
1933 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1936 TRACE("iface %p.\n", iface
);
1938 wined3d_mutex_lock();
1939 ret
= wined3d_device_get_software_vertex_processing(device
->wined3d_device
);
1940 wined3d_mutex_unlock();
1945 static HRESULT WINAPI
d3d9_device_SetNPatchMode(IDirect3DDevice9Ex
*iface
, float segment_count
)
1947 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1950 TRACE("iface %p, segment_count %.8e.\n", iface
, segment_count
);
1952 wined3d_mutex_lock();
1953 hr
= wined3d_device_set_npatch_mode(device
->wined3d_device
, segment_count
);
1954 wined3d_mutex_unlock();
1959 static float WINAPI
d3d9_device_GetNPatchMode(IDirect3DDevice9Ex
*iface
)
1961 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1964 TRACE("iface %p.\n", iface
);
1966 wined3d_mutex_lock();
1967 ret
= wined3d_device_get_npatch_mode(device
->wined3d_device
);
1968 wined3d_mutex_unlock();
1973 static HRESULT WINAPI
d3d9_device_DrawPrimitive(IDirect3DDevice9Ex
*iface
,
1974 D3DPRIMITIVETYPE primitive_type
, UINT start_vertex
, UINT primitive_count
)
1976 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1979 TRACE("iface %p, primitive_type %#x, start_vertex %u, primitive_count %u.\n",
1980 iface
, primitive_type
, start_vertex
, primitive_count
);
1982 wined3d_mutex_lock();
1983 wined3d_device_set_primitive_type(device
->wined3d_device
, primitive_type
);
1984 hr
= wined3d_device_draw_primitive(device
->wined3d_device
, start_vertex
,
1985 vertex_count_from_primitive_count(primitive_type
, primitive_count
));
1986 wined3d_mutex_unlock();
1991 static HRESULT WINAPI
d3d9_device_DrawIndexedPrimitive(IDirect3DDevice9Ex
*iface
,
1992 D3DPRIMITIVETYPE primitive_type
, INT base_vertex_idx
, UINT min_vertex_idx
,
1993 UINT vertex_count
, UINT start_idx
, UINT primitive_count
)
1995 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1998 TRACE("iface %p, primitive_type %#x, base_vertex_idx %u, min_vertex_idx %u,\n"
1999 "vertex_count %u, start_idx %u, primitive_count %u.\n",
2000 iface
, primitive_type
, base_vertex_idx
, min_vertex_idx
,
2001 vertex_count
, start_idx
, primitive_count
);
2003 wined3d_mutex_lock();
2004 wined3d_device_set_base_vertex_index(device
->wined3d_device
, base_vertex_idx
);
2005 wined3d_device_set_primitive_type(device
->wined3d_device
, primitive_type
);
2006 hr
= wined3d_device_draw_indexed_primitive(device
->wined3d_device
, start_idx
,
2007 vertex_count_from_primitive_count(primitive_type
, primitive_count
));
2008 wined3d_mutex_unlock();
2013 static HRESULT WINAPI
d3d9_device_DrawPrimitiveUP(IDirect3DDevice9Ex
*iface
,
2014 D3DPRIMITIVETYPE primitive_type
, UINT primitive_count
, const void *data
, UINT stride
)
2016 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2019 TRACE("iface %p, primitive_type %#x, primitive_count %u, data %p, stride %u.\n",
2020 iface
, primitive_type
, primitive_count
, data
, stride
);
2022 wined3d_mutex_lock();
2023 wined3d_device_set_primitive_type(device
->wined3d_device
, primitive_type
);
2024 hr
= wined3d_device_draw_primitive_up(device
->wined3d_device
,
2025 vertex_count_from_primitive_count(primitive_type
, primitive_count
),
2027 wined3d_mutex_unlock();
2032 static HRESULT WINAPI
d3d9_device_DrawIndexedPrimitiveUP(IDirect3DDevice9Ex
*iface
,
2033 D3DPRIMITIVETYPE primitive_type
, UINT min_vertex_idx
, UINT index_count
,
2034 UINT primitive_count
, const void *index_data
, D3DFORMAT index_format
,
2035 const void *vertex_data
, UINT vertex_stride
)
2037 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2040 TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, index_count %u, primitive_count %u,\n"
2041 "index_data %p, index_format %#x, vertex_data %p, vertex_stride %u.\n",
2042 iface
, primitive_type
, min_vertex_idx
, index_count
, primitive_count
,
2043 index_data
, index_format
, vertex_data
, vertex_stride
);
2045 wined3d_mutex_lock();
2046 wined3d_device_set_primitive_type(device
->wined3d_device
, primitive_type
);
2047 hr
= wined3d_device_draw_indexed_primitive_up(device
->wined3d_device
,
2048 vertex_count_from_primitive_count(primitive_type
, primitive_count
), index_data
,
2049 wined3dformat_from_d3dformat(index_format
), vertex_data
, vertex_stride
);
2050 wined3d_mutex_unlock();
2055 static HRESULT WINAPI
d3d9_device_ProcessVertices(IDirect3DDevice9Ex
*iface
,
2056 UINT src_start_idx
, UINT dst_idx
, UINT vertex_count
, IDirect3DVertexBuffer9
*dst_buffer
,
2057 IDirect3DVertexDeclaration9
*declaration
, DWORD flags
)
2059 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2060 struct d3d9_vertexbuffer
*dst_impl
= unsafe_impl_from_IDirect3DVertexBuffer9(dst_buffer
);
2061 struct d3d9_vertex_declaration
*decl_impl
= unsafe_impl_from_IDirect3DVertexDeclaration9(declaration
);
2064 TRACE("iface %p, src_start_idx %u, dst_idx %u, vertex_count %u, dst_buffer %p, declaration %p, flags %#x.\n",
2065 iface
, src_start_idx
, dst_idx
, vertex_count
, dst_buffer
, declaration
, flags
);
2067 wined3d_mutex_lock();
2068 hr
= wined3d_device_process_vertices(device
->wined3d_device
, src_start_idx
, dst_idx
, vertex_count
,
2069 dst_impl
->wined3d_buffer
, decl_impl
? decl_impl
->wined3d_declaration
: NULL
,
2070 flags
, dst_impl
->fvf
);
2071 wined3d_mutex_unlock();
2076 static HRESULT WINAPI
d3d9_device_CreateVertexDeclaration(IDirect3DDevice9Ex
*iface
,
2077 const D3DVERTEXELEMENT9
*elements
, IDirect3DVertexDeclaration9
**declaration
)
2079 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2080 struct d3d9_vertex_declaration
*object
;
2083 TRACE("iface %p, elements %p, declaration %p.\n", iface
, elements
, declaration
);
2087 WARN("Caller passed a NULL declaration, returning D3DERR_INVALIDCALL.\n");
2088 return D3DERR_INVALIDCALL
;
2091 if (SUCCEEDED(hr
= d3d9_vertex_declaration_create(device
, elements
, &object
)))
2092 *declaration
= &object
->IDirect3DVertexDeclaration9_iface
;
2097 static HRESULT WINAPI
d3d9_device_SetVertexDeclaration(IDirect3DDevice9Ex
*iface
,
2098 IDirect3DVertexDeclaration9
*declaration
)
2100 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2101 struct d3d9_vertex_declaration
*decl_impl
= unsafe_impl_from_IDirect3DVertexDeclaration9(declaration
);
2104 TRACE("iface %p, declaration %p.\n", iface
, declaration
);
2106 wined3d_mutex_lock();
2107 hr
= wined3d_device_set_vertex_declaration(device
->wined3d_device
,
2108 decl_impl
? decl_impl
->wined3d_declaration
: NULL
);
2109 wined3d_mutex_unlock();
2114 static HRESULT WINAPI
d3d9_device_GetVertexDeclaration(IDirect3DDevice9Ex
*iface
,
2115 IDirect3DVertexDeclaration9
**declaration
)
2117 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2118 struct wined3d_vertex_declaration
*wined3d_declaration
= NULL
;
2119 struct d3d9_vertex_declaration
*declaration_impl
;
2122 TRACE("iface %p, declaration %p.\n", iface
, declaration
);
2124 if (!declaration
) return D3DERR_INVALIDCALL
;
2126 wined3d_mutex_lock();
2127 hr
= wined3d_device_get_vertex_declaration(device
->wined3d_device
, &wined3d_declaration
);
2128 if (SUCCEEDED(hr
) && wined3d_declaration
)
2130 declaration_impl
= wined3d_vertex_declaration_get_parent(wined3d_declaration
);
2131 *declaration
= &declaration_impl
->IDirect3DVertexDeclaration9_iface
;
2132 IDirect3DVertexDeclaration9_AddRef(*declaration
);
2133 wined3d_vertex_declaration_decref(wined3d_declaration
);
2137 *declaration
= NULL
;
2139 wined3d_mutex_unlock();
2141 TRACE("Returning %p.\n", *declaration
);
2145 static struct wined3d_vertex_declaration
*device_get_fvf_declaration(struct d3d9_device
*device
, DWORD fvf
)
2147 struct wined3d_vertex_declaration
*wined3d_declaration
;
2148 struct fvf_declaration
*fvf_decls
= device
->fvf_decls
;
2149 struct d3d9_vertex_declaration
*d3d9_declaration
;
2150 D3DVERTEXELEMENT9
*elements
;
2151 int p
, low
, high
; /* deliberately signed */
2154 TRACE("Searching for declaration for fvf %08x... ", fvf
);
2157 high
= device
->fvf_decl_count
- 1;
2160 p
= (low
+ high
) >> 1;
2163 if (fvf_decls
[p
].fvf
== fvf
)
2165 TRACE("found %p.\n", fvf_decls
[p
].decl
);
2166 return fvf_decls
[p
].decl
;
2169 if (fvf_decls
[p
].fvf
< fvf
)
2174 TRACE("not found. Creating and inserting at position %d.\n", low
);
2176 if (FAILED(hr
= vdecl_convert_fvf(fvf
, &elements
)))
2179 hr
= d3d9_vertex_declaration_create(device
, elements
, &d3d9_declaration
);
2180 HeapFree(GetProcessHeap(), 0, elements
);
2184 if (device
->fvf_decl_size
== device
->fvf_decl_count
)
2186 UINT grow
= max(device
->fvf_decl_size
/ 2, 8);
2188 fvf_decls
= HeapReAlloc(GetProcessHeap(), 0, fvf_decls
, sizeof(*fvf_decls
) * (device
->fvf_decl_size
+ grow
));
2191 IDirect3DVertexDeclaration9_Release(&d3d9_declaration
->IDirect3DVertexDeclaration9_iface
);
2194 device
->fvf_decls
= fvf_decls
;
2195 device
->fvf_decl_size
+= grow
;
2198 d3d9_declaration
->fvf
= fvf
;
2199 wined3d_declaration
= d3d9_declaration
->wined3d_declaration
;
2200 wined3d_vertex_declaration_incref(wined3d_declaration
);
2201 IDirect3DVertexDeclaration9_Release(&d3d9_declaration
->IDirect3DVertexDeclaration9_iface
);
2203 memmove(fvf_decls
+ low
+ 1, fvf_decls
+ low
, sizeof(*fvf_decls
) * (device
->fvf_decl_count
- low
));
2204 fvf_decls
[low
].decl
= wined3d_declaration
;
2205 fvf_decls
[low
].fvf
= fvf
;
2206 ++device
->fvf_decl_count
;
2208 TRACE("Returning %p. %u declatations in array.\n", wined3d_declaration
, device
->fvf_decl_count
);
2210 return wined3d_declaration
;
2213 static HRESULT WINAPI
d3d9_device_SetFVF(IDirect3DDevice9Ex
*iface
, DWORD fvf
)
2215 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2216 struct wined3d_vertex_declaration
*decl
;
2219 TRACE("iface %p, fvf %#x.\n", iface
, fvf
);
2223 WARN("%#x is not a valid FVF.\n", fvf
);
2227 wined3d_mutex_lock();
2228 if (!(decl
= device_get_fvf_declaration(device
, fvf
)))
2230 wined3d_mutex_unlock();
2231 ERR("Failed to create a vertex declaration for fvf %#x.\n", fvf
);
2232 return D3DERR_DRIVERINTERNALERROR
;
2235 hr
= wined3d_device_set_vertex_declaration(device
->wined3d_device
, decl
);
2237 ERR("Failed to set vertex declaration.\n");
2238 wined3d_mutex_unlock();
2243 static HRESULT WINAPI
d3d9_device_GetFVF(IDirect3DDevice9Ex
*iface
, DWORD
*fvf
)
2245 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2246 struct wined3d_vertex_declaration
*wined3d_declaration
;
2247 struct d3d9_vertex_declaration
*d3d9_declaration
;
2250 TRACE("iface %p, fvf %p.\n", iface
, fvf
);
2252 wined3d_mutex_lock();
2253 if (FAILED(hr
= wined3d_device_get_vertex_declaration(device
->wined3d_device
, &wined3d_declaration
)))
2255 wined3d_mutex_unlock();
2256 WARN("Failed to get vertex declaration, hr %#x.\n", hr
);
2261 if (wined3d_declaration
)
2263 d3d9_declaration
= wined3d_vertex_declaration_get_parent(wined3d_declaration
);
2264 *fvf
= d3d9_declaration
->fvf
;
2265 wined3d_vertex_declaration_decref(wined3d_declaration
);
2271 wined3d_mutex_unlock();
2273 TRACE("Returning FVF %#x.\n", *fvf
);
2278 static HRESULT WINAPI
d3d9_device_CreateVertexShader(IDirect3DDevice9Ex
*iface
,
2279 const DWORD
*byte_code
, IDirect3DVertexShader9
**shader
)
2281 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2282 struct d3d9_vertexshader
*object
;
2285 TRACE("iface %p, byte_code %p, shader %p.\n", iface
, byte_code
, shader
);
2287 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
2290 ERR("Failed to allocate vertex shader memory.\n");
2291 return E_OUTOFMEMORY
;
2294 hr
= vertexshader_init(object
, device
, byte_code
);
2297 WARN("Failed to initialize vertex shader, hr %#x.\n", hr
);
2298 HeapFree(GetProcessHeap(), 0, object
);
2302 TRACE("Created vertex shader %p.\n", object
);
2303 *shader
= &object
->IDirect3DVertexShader9_iface
;
2308 static HRESULT WINAPI
d3d9_device_SetVertexShader(IDirect3DDevice9Ex
*iface
, IDirect3DVertexShader9
*shader
)
2310 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2311 struct d3d9_vertexshader
*shader_obj
= unsafe_impl_from_IDirect3DVertexShader9(shader
);
2314 TRACE("iface %p, shader %p.\n", iface
, shader
);
2316 wined3d_mutex_lock();
2317 hr
= wined3d_device_set_vertex_shader(device
->wined3d_device
,
2318 shader_obj
? shader_obj
->wined3d_shader
: NULL
);
2319 wined3d_mutex_unlock();
2324 static HRESULT WINAPI
d3d9_device_GetVertexShader(IDirect3DDevice9Ex
*iface
, IDirect3DVertexShader9
**shader
)
2326 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2327 struct d3d9_vertexshader
*shader_impl
;
2328 struct wined3d_shader
*wined3d_shader
;
2330 TRACE("iface %p, shader %p.\n", iface
, shader
);
2332 wined3d_mutex_lock();
2333 wined3d_shader
= wined3d_device_get_vertex_shader(device
->wined3d_device
);
2336 shader_impl
= wined3d_shader_get_parent(wined3d_shader
);
2337 *shader
= &shader_impl
->IDirect3DVertexShader9_iface
;
2338 IDirect3DVertexShader9_AddRef(*shader
);
2339 wined3d_shader_decref(wined3d_shader
);
2345 wined3d_mutex_unlock();
2347 TRACE("Returning %p.\n", *shader
);
2352 static HRESULT WINAPI
d3d9_device_SetVertexShaderConstantF(IDirect3DDevice9Ex
*iface
,
2353 UINT reg_idx
, const float *data
, UINT count
)
2355 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2358 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2360 if (reg_idx
+ count
> D3D9_MAX_VERTEX_SHADER_CONSTANTF
)
2362 WARN("Trying to access %u constants, but d3d9 only supports %u\n",
2363 reg_idx
+ count
, D3D9_MAX_VERTEX_SHADER_CONSTANTF
);
2364 return D3DERR_INVALIDCALL
;
2367 wined3d_mutex_lock();
2368 hr
= wined3d_device_set_vs_consts_f(device
->wined3d_device
, reg_idx
, data
, count
);
2369 wined3d_mutex_unlock();
2374 static HRESULT WINAPI
d3d9_device_GetVertexShaderConstantF(IDirect3DDevice9Ex
*iface
,
2375 UINT reg_idx
, float *data
, UINT count
)
2377 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2380 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2382 if (reg_idx
+ count
> D3D9_MAX_VERTEX_SHADER_CONSTANTF
)
2384 WARN("Trying to access %u constants, but d3d9 only supports %u\n",
2385 reg_idx
+ count
, D3D9_MAX_VERTEX_SHADER_CONSTANTF
);
2386 return D3DERR_INVALIDCALL
;
2389 wined3d_mutex_lock();
2390 hr
= wined3d_device_get_vs_consts_f(device
->wined3d_device
, reg_idx
, data
, count
);
2391 wined3d_mutex_unlock();
2396 static HRESULT WINAPI
d3d9_device_SetVertexShaderConstantI(IDirect3DDevice9Ex
*iface
,
2397 UINT reg_idx
, const int *data
, UINT count
)
2399 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2402 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2404 wined3d_mutex_lock();
2405 hr
= wined3d_device_set_vs_consts_i(device
->wined3d_device
, reg_idx
, data
, count
);
2406 wined3d_mutex_unlock();
2411 static HRESULT WINAPI
d3d9_device_GetVertexShaderConstantI(IDirect3DDevice9Ex
*iface
,
2412 UINT reg_idx
, int *data
, UINT count
)
2414 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2417 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2419 wined3d_mutex_lock();
2420 hr
= wined3d_device_get_vs_consts_i(device
->wined3d_device
, reg_idx
, data
, count
);
2421 wined3d_mutex_unlock();
2426 static HRESULT WINAPI
d3d9_device_SetVertexShaderConstantB(IDirect3DDevice9Ex
*iface
,
2427 UINT reg_idx
, const BOOL
*data
, UINT count
)
2429 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2432 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2434 wined3d_mutex_lock();
2435 hr
= wined3d_device_set_vs_consts_b(device
->wined3d_device
, reg_idx
, data
, count
);
2436 wined3d_mutex_unlock();
2441 static HRESULT WINAPI
d3d9_device_GetVertexShaderConstantB(IDirect3DDevice9Ex
*iface
,
2442 UINT reg_idx
, BOOL
*data
, UINT count
)
2444 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2447 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2449 wined3d_mutex_lock();
2450 hr
= wined3d_device_get_vs_consts_b(device
->wined3d_device
, reg_idx
, data
, count
);
2451 wined3d_mutex_unlock();
2456 static HRESULT WINAPI
d3d9_device_SetStreamSource(IDirect3DDevice9Ex
*iface
,
2457 UINT stream_idx
, IDirect3DVertexBuffer9
*buffer
, UINT offset
, UINT stride
)
2459 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2460 struct d3d9_vertexbuffer
*buffer_impl
= unsafe_impl_from_IDirect3DVertexBuffer9(buffer
);
2463 TRACE("iface %p, stream_idx %u, buffer %p, offset %u, stride %u.\n",
2464 iface
, stream_idx
, buffer
, offset
, stride
);
2466 wined3d_mutex_lock();
2467 hr
= wined3d_device_set_stream_source(device
->wined3d_device
, stream_idx
,
2468 buffer_impl
? buffer_impl
->wined3d_buffer
: NULL
, offset
, stride
);
2469 wined3d_mutex_unlock();
2474 static HRESULT WINAPI
d3d9_device_GetStreamSource(IDirect3DDevice9Ex
*iface
,
2475 UINT stream_idx
, IDirect3DVertexBuffer9
**buffer
, UINT
*offset
, UINT
*stride
)
2477 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2478 struct d3d9_vertexbuffer
*buffer_impl
;
2479 struct wined3d_buffer
*wined3d_buffer
;
2482 TRACE("iface %p, stream_idx %u, buffer %p, offset %p, stride %p.\n",
2483 iface
, stream_idx
, buffer
, offset
, stride
);
2486 return D3DERR_INVALIDCALL
;
2488 wined3d_mutex_lock();
2489 hr
= wined3d_device_get_stream_source(device
->wined3d_device
, stream_idx
, &wined3d_buffer
, offset
, stride
);
2490 if (SUCCEEDED(hr
) && wined3d_buffer
)
2492 buffer_impl
= wined3d_buffer_get_parent(wined3d_buffer
);
2493 *buffer
= &buffer_impl
->IDirect3DVertexBuffer9_iface
;
2494 IDirect3DVertexBuffer9_AddRef(*buffer
);
2495 wined3d_buffer_decref(wined3d_buffer
);
2500 FIXME("Call to GetStreamSource failed %p %p\n", offset
, stride
);
2503 wined3d_mutex_unlock();
2508 static HRESULT WINAPI
d3d9_device_SetStreamSourceFreq(IDirect3DDevice9Ex
*iface
, UINT stream_idx
, UINT freq
)
2510 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2513 TRACE("iface %p, stream_idx %u, freq %u.\n", iface
, stream_idx
, freq
);
2515 wined3d_mutex_lock();
2516 hr
= wined3d_device_set_stream_source_freq(device
->wined3d_device
, stream_idx
, freq
);
2517 wined3d_mutex_unlock();
2522 static HRESULT WINAPI
d3d9_device_GetStreamSourceFreq(IDirect3DDevice9Ex
*iface
, UINT stream_idx
, UINT
*freq
)
2524 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2527 TRACE("iface %p, stream_idx %u, freq %p.\n", iface
, stream_idx
, freq
);
2529 wined3d_mutex_lock();
2530 hr
= wined3d_device_get_stream_source_freq(device
->wined3d_device
, stream_idx
, freq
);
2531 wined3d_mutex_unlock();
2536 static HRESULT WINAPI
d3d9_device_SetIndices(IDirect3DDevice9Ex
*iface
, IDirect3DIndexBuffer9
*buffer
)
2538 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2539 struct d3d9_indexbuffer
*ib
= unsafe_impl_from_IDirect3DIndexBuffer9(buffer
);
2542 TRACE("iface %p, buffer %p.\n", iface
, buffer
);
2544 wined3d_mutex_lock();
2545 hr
= wined3d_device_set_index_buffer(device
->wined3d_device
,
2546 ib
? ib
->wined3d_buffer
: NULL
,
2547 ib
? ib
->format
: WINED3DFMT_UNKNOWN
);
2548 wined3d_mutex_unlock();
2553 static HRESULT WINAPI
d3d9_device_GetIndices(IDirect3DDevice9Ex
*iface
, IDirect3DIndexBuffer9
**buffer
)
2555 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2556 struct wined3d_buffer
*retIndexData
= NULL
;
2557 struct d3d9_indexbuffer
*buffer_impl
;
2560 TRACE("iface %p, buffer %p.\n", iface
, buffer
);
2563 return D3DERR_INVALIDCALL
;
2565 wined3d_mutex_lock();
2566 hr
= wined3d_device_get_index_buffer(device
->wined3d_device
, &retIndexData
);
2567 if (SUCCEEDED(hr
) && retIndexData
)
2569 buffer_impl
= wined3d_buffer_get_parent(retIndexData
);
2570 *buffer
= &buffer_impl
->IDirect3DIndexBuffer9_iface
;
2571 IDirect3DIndexBuffer9_AddRef(*buffer
);
2572 wined3d_buffer_decref(retIndexData
);
2577 FIXME("Call to GetIndices failed\n");
2580 wined3d_mutex_unlock();
2585 static HRESULT WINAPI
d3d9_device_CreatePixelShader(IDirect3DDevice9Ex
*iface
,
2586 const DWORD
*byte_code
, IDirect3DPixelShader9
**shader
)
2588 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2589 struct d3d9_pixelshader
*object
;
2592 TRACE("iface %p, byte_code %p, shader %p.\n", iface
, byte_code
, shader
);
2594 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
2597 FIXME("Failed to allocate pixel shader memory.\n");
2598 return E_OUTOFMEMORY
;
2601 hr
= pixelshader_init(object
, device
, byte_code
);
2604 WARN("Failed to initialize pixel shader, hr %#x.\n", hr
);
2605 HeapFree(GetProcessHeap(), 0, object
);
2609 TRACE("Created pixel shader %p.\n", object
);
2610 *shader
= &object
->IDirect3DPixelShader9_iface
;
2615 static HRESULT WINAPI
d3d9_device_SetPixelShader(IDirect3DDevice9Ex
*iface
, IDirect3DPixelShader9
*shader
)
2617 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2618 struct d3d9_pixelshader
*shader_obj
= unsafe_impl_from_IDirect3DPixelShader9(shader
);
2621 TRACE("iface %p, shader %p.\n", iface
, shader
);
2623 wined3d_mutex_lock();
2624 hr
= wined3d_device_set_pixel_shader(device
->wined3d_device
,
2625 shader_obj
? shader_obj
->wined3d_shader
: NULL
);
2626 wined3d_mutex_unlock();
2631 static HRESULT WINAPI
d3d9_device_GetPixelShader(IDirect3DDevice9Ex
*iface
, IDirect3DPixelShader9
**shader
)
2633 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2634 struct d3d9_pixelshader
*shader_impl
;
2635 struct wined3d_shader
*wined3d_shader
;
2637 TRACE("iface %p, shader %p.\n", iface
, shader
);
2639 if (!shader
) return D3DERR_INVALIDCALL
;
2641 wined3d_mutex_lock();
2642 wined3d_shader
= wined3d_device_get_pixel_shader(device
->wined3d_device
);
2645 shader_impl
= wined3d_shader_get_parent(wined3d_shader
);
2646 *shader
= &shader_impl
->IDirect3DPixelShader9_iface
;
2647 IDirect3DPixelShader9_AddRef(*shader
);
2648 wined3d_shader_decref(wined3d_shader
);
2654 wined3d_mutex_unlock();
2656 TRACE("Returning %p.\n", *shader
);
2661 static HRESULT WINAPI
d3d9_device_SetPixelShaderConstantF(IDirect3DDevice9Ex
*iface
,
2662 UINT reg_idx
, const float *data
, UINT count
)
2664 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2667 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2669 wined3d_mutex_lock();
2670 hr
= wined3d_device_set_ps_consts_f(device
->wined3d_device
, reg_idx
, data
, count
);
2671 wined3d_mutex_unlock();
2676 static HRESULT WINAPI
d3d9_device_GetPixelShaderConstantF(IDirect3DDevice9Ex
*iface
,
2677 UINT reg_idx
, float *data
, UINT count
)
2679 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2682 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2684 wined3d_mutex_lock();
2685 hr
= wined3d_device_get_ps_consts_f(device
->wined3d_device
, reg_idx
, data
, count
);
2686 wined3d_mutex_unlock();
2691 static HRESULT WINAPI
d3d9_device_SetPixelShaderConstantI(IDirect3DDevice9Ex
*iface
,
2692 UINT reg_idx
, const int *data
, UINT count
)
2694 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2697 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2699 wined3d_mutex_lock();
2700 hr
= wined3d_device_set_ps_consts_i(device
->wined3d_device
, reg_idx
, data
, count
);
2701 wined3d_mutex_unlock();
2706 static HRESULT WINAPI
d3d9_device_GetPixelShaderConstantI(IDirect3DDevice9Ex
*iface
,
2707 UINT reg_idx
, int *data
, UINT count
)
2709 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2712 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2714 wined3d_mutex_lock();
2715 hr
= wined3d_device_get_ps_consts_i(device
->wined3d_device
, reg_idx
, data
, count
);
2716 wined3d_mutex_unlock();
2721 static HRESULT WINAPI
d3d9_device_SetPixelShaderConstantB(IDirect3DDevice9Ex
*iface
,
2722 UINT reg_idx
, const BOOL
*data
, UINT count
)
2724 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2727 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2729 wined3d_mutex_lock();
2730 hr
= wined3d_device_set_ps_consts_b(device
->wined3d_device
, reg_idx
, data
, count
);
2731 wined3d_mutex_unlock();
2736 static HRESULT WINAPI
d3d9_device_GetPixelShaderConstantB(IDirect3DDevice9Ex
*iface
,
2737 UINT reg_idx
, BOOL
*data
, UINT count
)
2739 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2742 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2744 wined3d_mutex_lock();
2745 hr
= wined3d_device_get_ps_consts_b(device
->wined3d_device
, reg_idx
, data
, count
);
2746 wined3d_mutex_unlock();
2751 static HRESULT WINAPI
d3d9_device_DrawRectPatch(IDirect3DDevice9Ex
*iface
, UINT handle
,
2752 const float *segment_count
, const D3DRECTPATCH_INFO
*patch_info
)
2754 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2757 TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
2758 iface
, handle
, segment_count
, patch_info
);
2760 wined3d_mutex_lock();
2761 hr
= wined3d_device_draw_rect_patch(device
->wined3d_device
, handle
,
2762 segment_count
, (const struct wined3d_rect_patch_info
*)patch_info
);
2763 wined3d_mutex_unlock();
2768 static HRESULT WINAPI
d3d9_device_DrawTriPatch(IDirect3DDevice9Ex
*iface
, UINT handle
,
2769 const float *segment_count
, const D3DTRIPATCH_INFO
*patch_info
)
2771 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2774 TRACE("iface %p, handle %#x, segment_count %p, patch_info %p.\n",
2775 iface
, handle
, segment_count
, patch_info
);
2777 wined3d_mutex_lock();
2778 hr
= wined3d_device_draw_tri_patch(device
->wined3d_device
, handle
,
2779 segment_count
, (const struct wined3d_tri_patch_info
*)patch_info
);
2780 wined3d_mutex_unlock();
2785 static HRESULT WINAPI
d3d9_device_DeletePatch(IDirect3DDevice9Ex
*iface
, UINT handle
)
2787 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2790 TRACE("iface %p, handle %#x.\n", iface
, handle
);
2792 wined3d_mutex_lock();
2793 hr
= wined3d_device_delete_patch(device
->wined3d_device
, handle
);
2794 wined3d_mutex_unlock();
2799 static HRESULT WINAPI
d3d9_device_CreateQuery(IDirect3DDevice9Ex
*iface
, D3DQUERYTYPE type
, IDirect3DQuery9
**query
)
2801 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2802 struct d3d9_query
*object
;
2805 TRACE("iface %p, type %#x, query %p.\n", iface
, type
, query
);
2807 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
2810 ERR("Failed to allocate query memory.\n");
2811 return E_OUTOFMEMORY
;
2814 hr
= query_init(object
, device
, type
);
2817 WARN("Failed to initialize query, hr %#x.\n", hr
);
2818 HeapFree(GetProcessHeap(), 0, object
);
2822 TRACE("Created query %p.\n", object
);
2823 if (query
) *query
= &object
->IDirect3DQuery9_iface
;
2824 else IDirect3DQuery9_Release(&object
->IDirect3DQuery9_iface
);
2829 static HRESULT WINAPI
d3d9_device_SetConvolutionMonoKernel(IDirect3DDevice9Ex
*iface
,
2830 UINT width
, UINT height
, float *rows
, float *columns
)
2832 FIXME("iface %p, width %u, height %u, rows %p, columns %p stub!\n",
2833 iface
, width
, height
, rows
, columns
);
2838 static HRESULT WINAPI
d3d9_device_ComposeRects(IDirect3DDevice9Ex
*iface
,
2839 IDirect3DSurface9
*src_surface
, IDirect3DSurface9
*dst_surface
, IDirect3DVertexBuffer9
*src_descs
,
2840 UINT rect_count
, IDirect3DVertexBuffer9
*dst_descs
, D3DCOMPOSERECTSOP operation
, INT offset_x
, INT offset_y
)
2842 FIXME("iface %p, src_surface %p, dst_surface %p, src_descs %p, rect_count %u,\n"
2843 "dst_descs %p, operation %#x, offset_x %u, offset_y %u stub!\n",
2844 iface
, src_surface
, dst_surface
, src_descs
, rect_count
,
2845 dst_descs
, operation
, offset_x
, offset_y
);
2850 static HRESULT WINAPI
d3d9_device_PresentEx(IDirect3DDevice9Ex
*iface
,
2851 const RECT
*src_rect
, const RECT
*dst_rect
, HWND dst_window_override
,
2852 const RGNDATA
*dirty_region
, DWORD flags
)
2854 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2857 TRACE("iface %p, src_rect %s, dst_rect %s, dst_window_override %p, dirty_region %p, flags %#x.\n",
2858 iface
, wine_dbgstr_rect(src_rect
), wine_dbgstr_rect(dst_rect
),
2859 dst_window_override
, dirty_region
, flags
);
2861 wined3d_mutex_lock();
2862 hr
= wined3d_device_present(device
->wined3d_device
, src_rect
, dst_rect
,
2863 dst_window_override
, dirty_region
, flags
);
2864 wined3d_mutex_unlock();
2869 static HRESULT WINAPI
d3d9_device_GetGPUThreadPriority(IDirect3DDevice9Ex
*iface
, INT
*priority
)
2871 FIXME("iface %p, priority %p stub!\n", iface
, priority
);
2876 static HRESULT WINAPI
d3d9_device_SetGPUThreadPriority(IDirect3DDevice9Ex
*iface
, INT priority
)
2878 FIXME("iface %p, priority %d stub!\n", iface
, priority
);
2883 static HRESULT WINAPI
d3d9_device_WaitForVBlank(IDirect3DDevice9Ex
*iface
, UINT swapchain_idx
)
2885 FIXME("iface %p, swapchain_idx %u stub!\n", iface
, swapchain_idx
);
2890 static HRESULT WINAPI
d3d9_device_CheckResourceResidency(IDirect3DDevice9Ex
*iface
,
2891 IDirect3DResource9
**resources
, UINT32 resource_count
)
2893 FIXME("iface %p, resources %p, resource_count %u stub!\n",
2894 iface
, resources
, resource_count
);
2899 static HRESULT WINAPI
d3d9_device_SetMaximumFrameLatency(IDirect3DDevice9Ex
*iface
, UINT max_latency
)
2901 FIXME("iface %p, max_latency %u stub!\n", iface
, max_latency
);
2906 static HRESULT WINAPI
d3d9_device_GetMaximumFrameLatency(IDirect3DDevice9Ex
*iface
, UINT
*max_latency
)
2908 FIXME("iface %p, max_latency %p stub!\n", iface
, max_latency
);
2915 static HRESULT WINAPI
d3d9_device_CheckDeviceState(IDirect3DDevice9Ex
*iface
, HWND dst_window
)
2919 TRACE("iface %p, dst_window %p stub!\n", iface
, dst_window
);
2922 FIXME("iface %p, dst_window %p stub!\n", iface
, dst_window
);
2927 static HRESULT WINAPI
d3d9_device_CreateRenderTargetEx(IDirect3DDevice9Ex
*iface
,
2928 UINT width
, UINT height
, D3DFORMAT format
, D3DMULTISAMPLE_TYPE multisample_type
, DWORD multisample_quality
,
2929 BOOL lockable
, IDirect3DSurface9
**surface
, HANDLE
*shared_handle
, DWORD usage
)
2931 FIXME("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u,\n"
2932 "lockable %#x, surface %p, shared_handle %p, usage %#x stub!\n",
2933 iface
, width
, height
, format
, multisample_type
, multisample_quality
,
2934 lockable
, surface
, shared_handle
, usage
);
2937 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
2942 static HRESULT WINAPI
d3d9_device_CreateOffscreenPlainSurfaceEx(IDirect3DDevice9Ex
*iface
,
2943 UINT width
, UINT height
, D3DFORMAT format
, D3DPOOL pool
, IDirect3DSurface9
**surface
,
2944 HANDLE
*shared_handle
, DWORD usage
)
2946 FIXME("iface %p, width %u, height %u, format %#x, pool %#x, surface %p, shared_handle %p, usage %#x stub!\n",
2947 iface
, width
, height
, format
, pool
, surface
, shared_handle
, usage
);
2952 static HRESULT WINAPI
d3d9_device_CreateDepthStencilSurfaceEx(IDirect3DDevice9Ex
*iface
,
2953 UINT width
, UINT height
, D3DFORMAT format
, D3DMULTISAMPLE_TYPE multisample_type
, DWORD multisample_quality
,
2954 BOOL discard
, IDirect3DSurface9
**surface
, HANDLE
*shared_handle
, DWORD usage
)
2956 FIXME("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u,\n"
2957 "discard %#x, surface %p, shared_handle %p, usage %#x stub!\n",
2958 iface
, width
, height
, format
, multisample_type
, multisample_quality
,
2959 discard
, surface
, shared_handle
, usage
);
2962 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
2967 static HRESULT WINAPI
d3d9_device_ResetEx(IDirect3DDevice9Ex
*iface
,
2968 D3DPRESENT_PARAMETERS
*present_parameters
, D3DDISPLAYMODEEX
*mode
)
2970 FIXME("iface %p, present_parameters %p, mode %p stub!\n", iface
, present_parameters
, mode
);
2975 static HRESULT WINAPI
d3d9_device_GetDisplayModeEx(IDirect3DDevice9Ex
*iface
,
2976 UINT swapchain_idx
, D3DDISPLAYMODEEX
*mode
, D3DDISPLAYROTATION
*rotation
)
2978 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2979 struct wined3d_display_mode wined3d_mode
;
2982 TRACE("iface %p, swapchain_idx %u, mode %p, rotation %p.\n",
2983 iface
, swapchain_idx
, mode
, rotation
);
2985 if (mode
->Size
!= sizeof(*mode
))
2986 return D3DERR_INVALIDCALL
;
2988 wined3d_mutex_lock();
2989 hr
= wined3d_device_get_display_mode(device
->wined3d_device
, swapchain_idx
, &wined3d_mode
,
2990 (enum wined3d_display_rotation
*)rotation
);
2991 wined3d_mutex_unlock();
2995 mode
->Width
= wined3d_mode
.width
;
2996 mode
->Height
= wined3d_mode
.height
;
2997 mode
->RefreshRate
= wined3d_mode
.refresh_rate
;
2998 mode
->Format
= d3dformat_from_wined3dformat(wined3d_mode
.format_id
);
2999 mode
->ScanLineOrdering
= wined3d_mode
.scanline_ordering
;
3005 static const struct IDirect3DDevice9ExVtbl d3d9_device_vtbl
=
3008 d3d9_device_QueryInterface
,
3010 d3d9_device_Release
,
3011 /* IDirect3DDevice9 */
3012 d3d9_device_TestCooperativeLevel
,
3013 d3d9_device_GetAvailableTextureMem
,
3014 d3d9_device_EvictManagedResources
,
3015 d3d9_device_GetDirect3D
,
3016 d3d9_device_GetDeviceCaps
,
3017 d3d9_device_GetDisplayMode
,
3018 d3d9_device_GetCreationParameters
,
3019 d3d9_device_SetCursorProperties
,
3020 d3d9_device_SetCursorPosition
,
3021 d3d9_device_ShowCursor
,
3022 d3d9_device_CreateAdditionalSwapChain
,
3023 d3d9_device_GetSwapChain
,
3024 d3d9_device_GetNumberOfSwapChains
,
3026 d3d9_device_Present
,
3027 d3d9_device_GetBackBuffer
,
3028 d3d9_device_GetRasterStatus
,
3029 d3d9_device_SetDialogBoxMode
,
3030 d3d9_device_SetGammaRamp
,
3031 d3d9_device_GetGammaRamp
,
3032 d3d9_device_CreateTexture
,
3033 d3d9_device_CreateVolumeTexture
,
3034 d3d9_device_CreateCubeTexture
,
3035 d3d9_device_CreateVertexBuffer
,
3036 d3d9_device_CreateIndexBuffer
,
3037 d3d9_device_CreateRenderTarget
,
3038 d3d9_device_CreateDepthStencilSurface
,
3039 d3d9_device_UpdateSurface
,
3040 d3d9_device_UpdateTexture
,
3041 d3d9_device_GetRenderTargetData
,
3042 d3d9_device_GetFrontBufferData
,
3043 d3d9_device_StretchRect
,
3044 d3d9_device_ColorFill
,
3045 d3d9_device_CreateOffscreenPlainSurface
,
3046 d3d9_device_SetRenderTarget
,
3047 d3d9_device_GetRenderTarget
,
3048 d3d9_device_SetDepthStencilSurface
,
3049 d3d9_device_GetDepthStencilSurface
,
3050 d3d9_device_BeginScene
,
3051 d3d9_device_EndScene
,
3053 d3d9_device_SetTransform
,
3054 d3d9_device_GetTransform
,
3055 d3d9_device_MultiplyTransform
,
3056 d3d9_device_SetViewport
,
3057 d3d9_device_GetViewport
,
3058 d3d9_device_SetMaterial
,
3059 d3d9_device_GetMaterial
,
3060 d3d9_device_SetLight
,
3061 d3d9_device_GetLight
,
3062 d3d9_device_LightEnable
,
3063 d3d9_device_GetLightEnable
,
3064 d3d9_device_SetClipPlane
,
3065 d3d9_device_GetClipPlane
,
3066 d3d9_device_SetRenderState
,
3067 d3d9_device_GetRenderState
,
3068 d3d9_device_CreateStateBlock
,
3069 d3d9_device_BeginStateBlock
,
3070 d3d9_device_EndStateBlock
,
3071 d3d9_device_SetClipStatus
,
3072 d3d9_device_GetClipStatus
,
3073 d3d9_device_GetTexture
,
3074 d3d9_device_SetTexture
,
3075 d3d9_device_GetTextureStageState
,
3076 d3d9_device_SetTextureStageState
,
3077 d3d9_device_GetSamplerState
,
3078 d3d9_device_SetSamplerState
,
3079 d3d9_device_ValidateDevice
,
3080 d3d9_device_SetPaletteEntries
,
3081 d3d9_device_GetPaletteEntries
,
3082 d3d9_device_SetCurrentTexturePalette
,
3083 d3d9_device_GetCurrentTexturePalette
,
3084 d3d9_device_SetScissorRect
,
3085 d3d9_device_GetScissorRect
,
3086 d3d9_device_SetSoftwareVertexProcessing
,
3087 d3d9_device_GetSoftwareVertexProcessing
,
3088 d3d9_device_SetNPatchMode
,
3089 d3d9_device_GetNPatchMode
,
3090 d3d9_device_DrawPrimitive
,
3091 d3d9_device_DrawIndexedPrimitive
,
3092 d3d9_device_DrawPrimitiveUP
,
3093 d3d9_device_DrawIndexedPrimitiveUP
,
3094 d3d9_device_ProcessVertices
,
3095 d3d9_device_CreateVertexDeclaration
,
3096 d3d9_device_SetVertexDeclaration
,
3097 d3d9_device_GetVertexDeclaration
,
3100 d3d9_device_CreateVertexShader
,
3101 d3d9_device_SetVertexShader
,
3102 d3d9_device_GetVertexShader
,
3103 d3d9_device_SetVertexShaderConstantF
,
3104 d3d9_device_GetVertexShaderConstantF
,
3105 d3d9_device_SetVertexShaderConstantI
,
3106 d3d9_device_GetVertexShaderConstantI
,
3107 d3d9_device_SetVertexShaderConstantB
,
3108 d3d9_device_GetVertexShaderConstantB
,
3109 d3d9_device_SetStreamSource
,
3110 d3d9_device_GetStreamSource
,
3111 d3d9_device_SetStreamSourceFreq
,
3112 d3d9_device_GetStreamSourceFreq
,
3113 d3d9_device_SetIndices
,
3114 d3d9_device_GetIndices
,
3115 d3d9_device_CreatePixelShader
,
3116 d3d9_device_SetPixelShader
,
3117 d3d9_device_GetPixelShader
,
3118 d3d9_device_SetPixelShaderConstantF
,
3119 d3d9_device_GetPixelShaderConstantF
,
3120 d3d9_device_SetPixelShaderConstantI
,
3121 d3d9_device_GetPixelShaderConstantI
,
3122 d3d9_device_SetPixelShaderConstantB
,
3123 d3d9_device_GetPixelShaderConstantB
,
3124 d3d9_device_DrawRectPatch
,
3125 d3d9_device_DrawTriPatch
,
3126 d3d9_device_DeletePatch
,
3127 d3d9_device_CreateQuery
,
3128 /* IDirect3DDevice9Ex */
3129 d3d9_device_SetConvolutionMonoKernel
,
3130 d3d9_device_ComposeRects
,
3131 d3d9_device_PresentEx
,
3132 d3d9_device_GetGPUThreadPriority
,
3133 d3d9_device_SetGPUThreadPriority
,
3134 d3d9_device_WaitForVBlank
,
3135 d3d9_device_CheckResourceResidency
,
3136 d3d9_device_SetMaximumFrameLatency
,
3137 d3d9_device_GetMaximumFrameLatency
,
3138 d3d9_device_CheckDeviceState
,
3139 d3d9_device_CreateRenderTargetEx
,
3140 d3d9_device_CreateOffscreenPlainSurfaceEx
,
3141 d3d9_device_CreateDepthStencilSurfaceEx
,
3142 d3d9_device_ResetEx
,
3143 d3d9_device_GetDisplayModeEx
,
3146 static inline struct d3d9_device
*device_from_device_parent(struct wined3d_device_parent
*device_parent
)
3148 return CONTAINING_RECORD(device_parent
, struct d3d9_device
, device_parent
);
3151 static void CDECL
device_parent_wined3d_device_created(struct wined3d_device_parent
*device_parent
,
3152 struct wined3d_device
*device
)
3154 TRACE("device_parent %p, device %p.\n", device_parent
, device
);
3157 static void CDECL
device_parent_mode_changed(struct wined3d_device_parent
*device_parent
)
3159 TRACE("device_parent %p.\n", device_parent
);
3162 static HRESULT CDECL
device_parent_create_surface(struct wined3d_device_parent
*device_parent
,
3163 void *container_parent
, UINT width
, UINT height
, enum wined3d_format_id format
, DWORD usage
,
3164 enum wined3d_pool pool
, UINT level
, enum wined3d_cubemap_face face
, struct wined3d_surface
**surface
)
3166 struct d3d9_device
*device
= device_from_device_parent(device_parent
);
3167 struct d3d9_surface
*d3d_surface
;
3168 BOOL lockable
= TRUE
;
3171 TRACE("device_parent %p, container_parent %p, width %u, height %u, format %#x, usage %#x,\n"
3172 "\tpool %#x, level %u, face %u, surface %p.\n",
3173 device_parent
, container_parent
, width
, height
, format
, usage
, pool
, level
, face
, surface
);
3175 if (pool
== WINED3D_POOL_DEFAULT
&& !(usage
& D3DUSAGE_DYNAMIC
))
3178 hr
= d3d9_device_create_surface(device
, width
, height
,
3179 d3dformat_from_wined3dformat(format
), lockable
, FALSE
/* Discard */, level
,
3180 (IDirect3DSurface9
**)&d3d_surface
, usage
, pool
, D3DMULTISAMPLE_NONE
, 0 /* MultisampleQuality */);
3183 WARN("Failed to create surface, hr %#x.\n", hr
);
3187 *surface
= d3d_surface
->wined3d_surface
;
3188 wined3d_surface_incref(*surface
);
3190 d3d_surface
->container
= container_parent
;
3191 IDirect3DDevice9Ex_Release(d3d_surface
->parent_device
);
3192 d3d_surface
->parent_device
= NULL
;
3194 IDirect3DSurface9_Release(&d3d_surface
->IDirect3DSurface9_iface
);
3195 d3d_surface
->forwardReference
= container_parent
;
3200 static HRESULT CDECL
device_parent_create_rendertarget(struct wined3d_device_parent
*device_parent
,
3201 void *container_parent
, UINT width
, UINT height
, enum wined3d_format_id format
,
3202 enum wined3d_multisample_type multisample_type
, DWORD multisample_quality
, BOOL lockable
,
3203 struct wined3d_surface
**surface
)
3205 struct d3d9_device
*device
= device_from_device_parent(device_parent
);
3206 struct d3d9_surface
*d3d_surface
;
3209 TRACE("device_parent %p, container_parent %p, width %u, height %u, format %#x, multisample_type %#x,\n"
3210 "\tmultisample_quality %u, lockable %u, surface %p.\n",
3211 device_parent
, container_parent
, width
, height
, format
, multisample_type
,
3212 multisample_quality
, lockable
, surface
);
3214 hr
= d3d9_device_CreateRenderTarget(&device
->IDirect3DDevice9Ex_iface
, width
, height
,
3215 d3dformat_from_wined3dformat(format
), multisample_type
, multisample_quality
, lockable
,
3216 (IDirect3DSurface9
**)&d3d_surface
, NULL
);
3219 WARN("Failed to create rendertarget, hr %#x.\n", hr
);
3223 *surface
= d3d_surface
->wined3d_surface
;
3224 wined3d_surface_incref(*surface
);
3226 d3d_surface
->container
= container_parent
;
3227 /* Implicit surfaces are created with an refcount of 0 */
3228 IDirect3DSurface9_Release(&d3d_surface
->IDirect3DSurface9_iface
);
3233 static HRESULT CDECL
device_parent_create_depth_stencil(struct wined3d_device_parent
*device_parent
,
3234 UINT width
, UINT height
, enum wined3d_format_id format
, enum wined3d_multisample_type multisample_type
,
3235 DWORD multisample_quality
, BOOL discard
, struct wined3d_surface
**surface
)
3237 struct d3d9_device
*device
= device_from_device_parent(device_parent
);
3238 struct d3d9_surface
*d3d_surface
;
3241 TRACE("device_parent %p, width %u, height %u, format %#x, multisample_type %#x,\n"
3242 "\tmultisample_quality %u, discard %u, surface %p.\n",
3243 device_parent
, width
, height
, format
, multisample_type
, multisample_quality
, discard
, surface
);
3245 hr
= d3d9_device_CreateDepthStencilSurface(&device
->IDirect3DDevice9Ex_iface
, width
,
3246 height
, d3dformat_from_wined3dformat(format
), multisample_type
, multisample_quality
,
3247 discard
, (IDirect3DSurface9
**)&d3d_surface
, NULL
);
3250 WARN("Failed to create depth/stencil surface, hr %#x.\n", hr
);
3254 *surface
= d3d_surface
->wined3d_surface
;
3255 wined3d_surface_incref(*surface
);
3256 d3d_surface
->container
= (IUnknown
*)&device
->IDirect3DDevice9Ex_iface
;
3257 /* Implicit surfaces are created with an refcount of 0 */
3258 IDirect3DSurface9_Release(&d3d_surface
->IDirect3DSurface9_iface
);
3263 static HRESULT CDECL
device_parent_create_volume(struct wined3d_device_parent
*device_parent
,
3264 void *container_parent
, UINT width
, UINT height
, UINT depth
, enum wined3d_format_id format
,
3265 enum wined3d_pool pool
, DWORD usage
, struct wined3d_volume
**volume
)
3267 struct d3d9_device
*device
= device_from_device_parent(device_parent
);
3268 struct d3d9_volume
*object
;
3271 TRACE("device_parent %p, container_parent %p, width %u, height %u, depth %u, "
3272 "format %#x, pool %#x, usage %#x, volume %p\n",
3273 device_parent
, container_parent
, width
, height
, depth
,
3274 format
, pool
, usage
, volume
);
3276 /* Allocate the storage for the device */
3277 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
3280 FIXME("Allocation of memory failed\n");
3282 return D3DERR_OUTOFVIDEOMEMORY
;
3285 hr
= volume_init(object
, device
, width
, height
, depth
, usage
, format
, pool
);
3288 WARN("Failed to initialize volume, hr %#x.\n", hr
);
3289 HeapFree(GetProcessHeap(), 0, object
);
3293 *volume
= object
->wined3d_volume
;
3294 wined3d_volume_incref(*volume
);
3295 IDirect3DVolume9_Release(&object
->IDirect3DVolume9_iface
);
3297 object
->container
= container_parent
;
3298 object
->forwardReference
= container_parent
;
3300 TRACE("Created volume %p.\n", object
);
3305 static HRESULT CDECL
device_parent_create_swapchain(struct wined3d_device_parent
*device_parent
,
3306 struct wined3d_swapchain_desc
*desc
, struct wined3d_swapchain
**swapchain
)
3308 struct d3d9_device
*device
= device_from_device_parent(device_parent
);
3309 struct d3d9_swapchain
*d3d_swapchain
;
3312 TRACE("device_parent %p, desc %p, swapchain %p\n", device_parent
, desc
, swapchain
);
3314 hr
= d3d9_swapchain_create(device
, desc
, &d3d_swapchain
);
3317 WARN("Failed to create swapchain, hr %#x.\n", hr
);
3322 *swapchain
= d3d_swapchain
->wined3d_swapchain
;
3323 wined3d_swapchain_incref(*swapchain
);
3324 IDirect3DSwapChain9_Release(&d3d_swapchain
->IDirect3DSwapChain9_iface
);
3329 static const struct wined3d_device_parent_ops d3d9_wined3d_device_parent_ops
=
3331 device_parent_wined3d_device_created
,
3332 device_parent_mode_changed
,
3333 device_parent_create_surface
,
3334 device_parent_create_rendertarget
,
3335 device_parent_create_depth_stencil
,
3336 device_parent_create_volume
,
3337 device_parent_create_swapchain
,
3340 static void setup_fpu(void)
3342 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
3344 __asm__
volatile ("fnstcw %0" : "=m" (cw
));
3345 cw
= (cw
& ~0xf3f) | 0x3f;
3346 __asm__
volatile ("fldcw %0" : : "m" (cw
));
3347 #elif defined(__i386__) && defined(_MSC_VER)
3350 cw
= (cw
& ~0xf3f) | 0x3f;
3353 FIXME("FPU setup not implemented for this platform.\n");
3357 HRESULT
device_init(struct d3d9_device
*device
, struct d3d9
*parent
, struct wined3d
*wined3d
,
3358 UINT adapter
, D3DDEVTYPE device_type
, HWND focus_window
, DWORD flags
,
3359 D3DPRESENT_PARAMETERS
*parameters
, D3DDISPLAYMODEEX
*mode
)
3361 struct wined3d_swapchain_desc
*swapchain_desc
;
3366 FIXME("Ignoring display mode.\n");
3368 device
->IDirect3DDevice9Ex_iface
.lpVtbl
= &d3d9_device_vtbl
;
3369 device
->device_parent
.ops
= &d3d9_wined3d_device_parent_ops
;
3370 device
->refcount
= 1;
3372 if (!(flags
& D3DCREATE_FPU_PRESERVE
)) setup_fpu();
3374 wined3d_mutex_lock();
3375 hr
= wined3d_device_create(wined3d
, adapter
, device_type
, focus_window
, flags
, 4,
3376 &device
->device_parent
, &device
->wined3d_device
);
3379 WARN("Failed to create wined3d device, hr %#x.\n", hr
);
3380 wined3d_mutex_unlock();
3384 if (flags
& D3DCREATE_ADAPTERGROUP_DEVICE
)
3388 wined3d_get_device_caps(wined3d
, adapter
, device_type
, &caps
);
3389 count
= caps
.NumberOfAdaptersInGroup
;
3392 if (flags
& D3DCREATE_MULTITHREADED
)
3393 wined3d_device_set_multithreaded(device
->wined3d_device
);
3395 if (!parameters
->Windowed
)
3398 focus_window
= parameters
->hDeviceWindow
;
3399 if (FAILED(hr
= wined3d_device_acquire_focus_window(device
->wined3d_device
, focus_window
)))
3401 ERR("Failed to acquire focus window, hr %#x.\n", hr
);
3402 wined3d_device_decref(device
->wined3d_device
);
3403 wined3d_mutex_unlock();
3407 for (i
= 0; i
< count
; ++i
)
3409 HWND device_window
= parameters
[i
].hDeviceWindow
;
3411 if (!device_window
) device_window
= focus_window
;
3412 wined3d_device_setup_fullscreen_window(device
->wined3d_device
, device_window
,
3413 parameters
[i
].BackBufferWidth
,
3414 parameters
[i
].BackBufferHeight
);
3418 swapchain_desc
= HeapAlloc(GetProcessHeap(), 0, sizeof(*swapchain_desc
) * count
);
3419 if (!swapchain_desc
)
3421 ERR("Failed to allocate wined3d parameters.\n");
3422 wined3d_device_decref(device
->wined3d_device
);
3423 wined3d_mutex_unlock();
3424 return E_OUTOFMEMORY
;
3427 for (i
= 0; i
< count
; ++i
)
3429 swapchain_desc
[i
].backbuffer_width
= parameters
[i
].BackBufferWidth
;
3430 swapchain_desc
[i
].backbuffer_height
= parameters
[i
].BackBufferHeight
;
3431 swapchain_desc
[i
].backbuffer_format
= wined3dformat_from_d3dformat(parameters
[i
].BackBufferFormat
);
3432 swapchain_desc
[i
].backbuffer_count
= max(1, parameters
[i
].BackBufferCount
);
3433 swapchain_desc
[i
].multisample_type
= parameters
[i
].MultiSampleType
;
3434 swapchain_desc
[i
].multisample_quality
= parameters
[i
].MultiSampleQuality
;
3435 swapchain_desc
[i
].swap_effect
= parameters
[i
].SwapEffect
;
3436 swapchain_desc
[i
].device_window
= parameters
[i
].hDeviceWindow
;
3437 swapchain_desc
[i
].windowed
= parameters
[i
].Windowed
;
3438 swapchain_desc
[i
].enable_auto_depth_stencil
= parameters
[i
].EnableAutoDepthStencil
;
3439 swapchain_desc
[i
].auto_depth_stencil_format
=
3440 wined3dformat_from_d3dformat(parameters
[i
].AutoDepthStencilFormat
);
3441 swapchain_desc
[i
].flags
= parameters
[i
].Flags
;
3442 swapchain_desc
[i
].refresh_rate
= parameters
[i
].FullScreen_RefreshRateInHz
;
3443 swapchain_desc
[i
].swap_interval
= parameters
[i
].PresentationInterval
;
3444 swapchain_desc
[i
].auto_restore_display_mode
= TRUE
;
3447 hr
= wined3d_device_init_3d(device
->wined3d_device
, swapchain_desc
);
3450 WARN("Failed to initialize 3D, hr %#x.\n", hr
);
3451 wined3d_device_release_focus_window(device
->wined3d_device
);
3452 HeapFree(GetProcessHeap(), 0, swapchain_desc
);
3453 wined3d_device_decref(device
->wined3d_device
);
3454 wined3d_mutex_unlock();
3458 wined3d_mutex_unlock();
3460 for (i
= 0; i
< count
; ++i
)
3462 parameters
[i
].BackBufferWidth
= swapchain_desc
[i
].backbuffer_width
;
3463 parameters
[i
].BackBufferHeight
= swapchain_desc
[i
].backbuffer_height
;
3464 parameters
[i
].BackBufferFormat
= d3dformat_from_wined3dformat(swapchain_desc
[i
].backbuffer_format
);
3465 parameters
[i
].BackBufferCount
= swapchain_desc
[i
].backbuffer_count
;
3466 parameters
[i
].MultiSampleType
= swapchain_desc
[i
].multisample_type
;
3467 parameters
[i
].MultiSampleQuality
= swapchain_desc
[i
].multisample_quality
;
3468 parameters
[i
].SwapEffect
= swapchain_desc
[i
].swap_effect
;
3469 parameters
[i
].hDeviceWindow
= swapchain_desc
[i
].device_window
;
3470 parameters
[i
].Windowed
= swapchain_desc
[i
].windowed
;
3471 parameters
[i
].EnableAutoDepthStencil
= swapchain_desc
[i
].enable_auto_depth_stencil
;
3472 parameters
[i
].AutoDepthStencilFormat
=
3473 d3dformat_from_wined3dformat(swapchain_desc
[i
].auto_depth_stencil_format
);
3474 parameters
[i
].Flags
= swapchain_desc
[i
].flags
;
3475 parameters
[i
].FullScreen_RefreshRateInHz
= swapchain_desc
[i
].refresh_rate
;
3476 parameters
[i
].PresentationInterval
= swapchain_desc
[i
].swap_interval
;
3478 HeapFree(GetProcessHeap(), 0, swapchain_desc
);
3480 /* Initialize the converted declaration array. This creates a valid pointer
3481 * and when adding decls HeapReAlloc() can be used without further checking. */
3482 device
->fvf_decls
= HeapAlloc(GetProcessHeap(), 0, 0);
3483 if (!device
->fvf_decls
)
3485 ERR("Failed to allocate FVF vertex declaration map memory.\n");
3486 wined3d_mutex_lock();
3487 wined3d_device_uninit_3d(device
->wined3d_device
);
3488 wined3d_device_release_focus_window(device
->wined3d_device
);
3489 wined3d_device_decref(device
->wined3d_device
);
3490 wined3d_mutex_unlock();
3491 return E_OUTOFMEMORY
;
3494 IDirect3D9Ex_AddRef(&parent
->IDirect3D9Ex_iface
);
3495 device
->d3d_parent
= parent
;