2 * IDirect3DDevice9 implementation
4 * Copyright 2002-2005 Jason Edmeades
5 * Copyright 2002-2005 Raphael Junqueira
6 * Copyright 2005 Oliver Stieber
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "d3d9_private.h"
25 static void STDMETHODCALLTYPE
d3d9_null_wined3d_object_destroyed(void *parent
) {}
27 static const struct wined3d_parent_ops d3d9_null_wined3d_parent_ops
=
29 d3d9_null_wined3d_object_destroyed
,
32 D3DFORMAT
d3dformat_from_wined3dformat(enum wined3d_format_id format
)
34 BYTE
*c
= (BYTE
*)&format
;
36 /* Don't translate FOURCC formats */
37 if (isprint(c
[0]) && isprint(c
[1]) && isprint(c
[2]) && isprint(c
[3])) return format
;
41 case WINED3DFMT_UNKNOWN
: return D3DFMT_UNKNOWN
;
42 case WINED3DFMT_B8G8R8_UNORM
: return D3DFMT_R8G8B8
;
43 case WINED3DFMT_B8G8R8A8_UNORM
: return D3DFMT_A8R8G8B8
;
44 case WINED3DFMT_B8G8R8X8_UNORM
: return D3DFMT_X8R8G8B8
;
45 case WINED3DFMT_B5G6R5_UNORM
: return D3DFMT_R5G6B5
;
46 case WINED3DFMT_B5G5R5X1_UNORM
: return D3DFMT_X1R5G5B5
;
47 case WINED3DFMT_B5G5R5A1_UNORM
: return D3DFMT_A1R5G5B5
;
48 case WINED3DFMT_B4G4R4A4_UNORM
: return D3DFMT_A4R4G4B4
;
49 case WINED3DFMT_B2G3R3_UNORM
: return D3DFMT_R3G3B2
;
50 case WINED3DFMT_A8_UNORM
: return D3DFMT_A8
;
51 case WINED3DFMT_B2G3R3A8_UNORM
: return D3DFMT_A8R3G3B2
;
52 case WINED3DFMT_B4G4R4X4_UNORM
: return D3DFMT_X4R4G4B4
;
53 case WINED3DFMT_R10G10B10A2_UNORM
: return D3DFMT_A2B10G10R10
;
54 case WINED3DFMT_R8G8B8A8_UNORM
: return D3DFMT_A8B8G8R8
;
55 case WINED3DFMT_R8G8B8X8_UNORM
: return D3DFMT_X8B8G8R8
;
56 case WINED3DFMT_R16G16_UNORM
: return D3DFMT_G16R16
;
57 case WINED3DFMT_B10G10R10A2_UNORM
: return D3DFMT_A2R10G10B10
;
58 case WINED3DFMT_R16G16B16A16_UNORM
: return D3DFMT_A16B16G16R16
;
59 case WINED3DFMT_P8_UINT_A8_UNORM
: return D3DFMT_A8P8
;
60 case WINED3DFMT_P8_UINT
: return D3DFMT_P8
;
61 case WINED3DFMT_L8_UNORM
: return D3DFMT_L8
;
62 case WINED3DFMT_L8A8_UNORM
: return D3DFMT_A8L8
;
63 case WINED3DFMT_L4A4_UNORM
: return D3DFMT_A4L4
;
64 case WINED3DFMT_R8G8_SNORM
: return D3DFMT_V8U8
;
65 case WINED3DFMT_R5G5_SNORM_L6_UNORM
: return D3DFMT_L6V5U5
;
66 case WINED3DFMT_R8G8_SNORM_L8X8_UNORM
: return D3DFMT_X8L8V8U8
;
67 case WINED3DFMT_R8G8B8A8_SNORM
: return D3DFMT_Q8W8V8U8
;
68 case WINED3DFMT_R16G16_SNORM
: return D3DFMT_V16U16
;
69 case WINED3DFMT_R10G10B10_SNORM_A2_UNORM
: return D3DFMT_A2W10V10U10
;
70 case WINED3DFMT_D16_LOCKABLE
: return D3DFMT_D16_LOCKABLE
;
71 case WINED3DFMT_D32_UNORM
: return D3DFMT_D32
;
72 case WINED3DFMT_S1_UINT_D15_UNORM
: return D3DFMT_D15S1
;
73 case WINED3DFMT_D24_UNORM_S8_UINT
: return D3DFMT_D24S8
;
74 case WINED3DFMT_X8D24_UNORM
: return D3DFMT_D24X8
;
75 case WINED3DFMT_S4X4_UINT_D24_UNORM
: return D3DFMT_D24X4S4
;
76 case WINED3DFMT_D16_UNORM
: return D3DFMT_D16
;
77 case WINED3DFMT_L16_UNORM
: return D3DFMT_L16
;
78 case WINED3DFMT_D32_FLOAT
: return D3DFMT_D32F_LOCKABLE
;
79 case WINED3DFMT_S8_UINT_D24_FLOAT
: return D3DFMT_D24FS8
;
80 case WINED3DFMT_VERTEXDATA
: return D3DFMT_VERTEXDATA
;
81 case WINED3DFMT_R16_UINT
: return D3DFMT_INDEX16
;
82 case WINED3DFMT_R32_UINT
: return D3DFMT_INDEX32
;
83 case WINED3DFMT_R16G16B16A16_SNORM
: return D3DFMT_Q16W16V16U16
;
84 case WINED3DFMT_R16_FLOAT
: return D3DFMT_R16F
;
85 case WINED3DFMT_R16G16_FLOAT
: return D3DFMT_G16R16F
;
86 case WINED3DFMT_R16G16B16A16_FLOAT
: return D3DFMT_A16B16G16R16F
;
87 case WINED3DFMT_R32_FLOAT
: return D3DFMT_R32F
;
88 case WINED3DFMT_R32G32_FLOAT
: return D3DFMT_G32R32F
;
89 case WINED3DFMT_R32G32B32A32_FLOAT
: return D3DFMT_A32B32G32R32F
;
90 case WINED3DFMT_R8G8_SNORM_Cx
: return D3DFMT_CxV8U8
;
92 FIXME("Unhandled wined3d format %#x.\n", format
);
93 return D3DFMT_UNKNOWN
;
97 enum wined3d_format_id
wined3dformat_from_d3dformat(D3DFORMAT format
)
99 BYTE
*c
= (BYTE
*)&format
;
101 /* Don't translate FOURCC formats */
102 if (isprint(c
[0]) && isprint(c
[1]) && isprint(c
[2]) && isprint(c
[3])) return format
;
106 case D3DFMT_UNKNOWN
: return WINED3DFMT_UNKNOWN
;
107 case D3DFMT_R8G8B8
: return WINED3DFMT_B8G8R8_UNORM
;
108 case D3DFMT_A8R8G8B8
: return WINED3DFMT_B8G8R8A8_UNORM
;
109 case D3DFMT_X8R8G8B8
: return WINED3DFMT_B8G8R8X8_UNORM
;
110 case D3DFMT_R5G6B5
: return WINED3DFMT_B5G6R5_UNORM
;
111 case D3DFMT_X1R5G5B5
: return WINED3DFMT_B5G5R5X1_UNORM
;
112 case D3DFMT_A1R5G5B5
: return WINED3DFMT_B5G5R5A1_UNORM
;
113 case D3DFMT_A4R4G4B4
: return WINED3DFMT_B4G4R4A4_UNORM
;
114 case D3DFMT_R3G3B2
: return WINED3DFMT_B2G3R3_UNORM
;
115 case D3DFMT_A8
: return WINED3DFMT_A8_UNORM
;
116 case D3DFMT_A8R3G3B2
: return WINED3DFMT_B2G3R3A8_UNORM
;
117 case D3DFMT_X4R4G4B4
: return WINED3DFMT_B4G4R4X4_UNORM
;
118 case D3DFMT_A2B10G10R10
: return WINED3DFMT_R10G10B10A2_UNORM
;
119 case D3DFMT_A8B8G8R8
: return WINED3DFMT_R8G8B8A8_UNORM
;
120 case D3DFMT_X8B8G8R8
: return WINED3DFMT_R8G8B8X8_UNORM
;
121 case D3DFMT_G16R16
: return WINED3DFMT_R16G16_UNORM
;
122 case D3DFMT_A2R10G10B10
: return WINED3DFMT_B10G10R10A2_UNORM
;
123 case D3DFMT_A16B16G16R16
: return WINED3DFMT_R16G16B16A16_UNORM
;
124 case D3DFMT_A8P8
: return WINED3DFMT_P8_UINT_A8_UNORM
;
125 case D3DFMT_P8
: return WINED3DFMT_P8_UINT
;
126 case D3DFMT_L8
: return WINED3DFMT_L8_UNORM
;
127 case D3DFMT_A8L8
: return WINED3DFMT_L8A8_UNORM
;
128 case D3DFMT_A4L4
: return WINED3DFMT_L4A4_UNORM
;
129 case D3DFMT_V8U8
: return WINED3DFMT_R8G8_SNORM
;
130 case D3DFMT_L6V5U5
: return WINED3DFMT_R5G5_SNORM_L6_UNORM
;
131 case D3DFMT_X8L8V8U8
: return WINED3DFMT_R8G8_SNORM_L8X8_UNORM
;
132 case D3DFMT_Q8W8V8U8
: return WINED3DFMT_R8G8B8A8_SNORM
;
133 case D3DFMT_V16U16
: return WINED3DFMT_R16G16_SNORM
;
134 case D3DFMT_A2W10V10U10
: return WINED3DFMT_R10G10B10_SNORM_A2_UNORM
;
135 case D3DFMT_D16_LOCKABLE
: return WINED3DFMT_D16_LOCKABLE
;
136 case D3DFMT_D32
: return WINED3DFMT_D32_UNORM
;
137 case D3DFMT_D15S1
: return WINED3DFMT_S1_UINT_D15_UNORM
;
138 case D3DFMT_D24S8
: return WINED3DFMT_D24_UNORM_S8_UINT
;
139 case D3DFMT_D24X8
: return WINED3DFMT_X8D24_UNORM
;
140 case D3DFMT_D24X4S4
: return WINED3DFMT_S4X4_UINT_D24_UNORM
;
141 case D3DFMT_D16
: return WINED3DFMT_D16_UNORM
;
142 case D3DFMT_L16
: return WINED3DFMT_L16_UNORM
;
143 case D3DFMT_D32F_LOCKABLE
: return WINED3DFMT_D32_FLOAT
;
144 case D3DFMT_D24FS8
: return WINED3DFMT_S8_UINT_D24_FLOAT
;
145 case D3DFMT_VERTEXDATA
: return WINED3DFMT_VERTEXDATA
;
146 case D3DFMT_INDEX16
: return WINED3DFMT_R16_UINT
;
147 case D3DFMT_INDEX32
: return WINED3DFMT_R32_UINT
;
148 case D3DFMT_Q16W16V16U16
: return WINED3DFMT_R16G16B16A16_SNORM
;
149 case D3DFMT_R16F
: return WINED3DFMT_R16_FLOAT
;
150 case D3DFMT_G16R16F
: return WINED3DFMT_R16G16_FLOAT
;
151 case D3DFMT_A16B16G16R16F
: return WINED3DFMT_R16G16B16A16_FLOAT
;
152 case D3DFMT_R32F
: return WINED3DFMT_R32_FLOAT
;
153 case D3DFMT_G32R32F
: return WINED3DFMT_R32G32_FLOAT
;
154 case D3DFMT_A32B32G32R32F
: return WINED3DFMT_R32G32B32A32_FLOAT
;
155 case D3DFMT_CxV8U8
: return WINED3DFMT_R8G8_SNORM_Cx
;
157 FIXME("Unhandled D3DFORMAT %#x\n", format
);
158 return WINED3DFMT_UNKNOWN
;
162 static UINT
vertex_count_from_primitive_count(D3DPRIMITIVETYPE primitive_type
, UINT primitive_count
)
164 switch(primitive_type
)
166 case D3DPT_POINTLIST
:
167 return primitive_count
;
170 return primitive_count
* 2;
172 case D3DPT_LINESTRIP
:
173 return primitive_count
+ 1;
175 case D3DPT_TRIANGLELIST
:
176 return primitive_count
* 3;
178 case D3DPT_TRIANGLESTRIP
:
179 case D3DPT_TRIANGLEFAN
:
180 return primitive_count
+ 2;
183 FIXME("Unhandled primitive type %#x\n", primitive_type
);
188 void present_parameters_from_wined3d_swapchain_desc(D3DPRESENT_PARAMETERS
*present_parameters
,
189 const struct wined3d_swapchain_desc
*swapchain_desc
)
191 present_parameters
->BackBufferWidth
= swapchain_desc
->backbuffer_width
;
192 present_parameters
->BackBufferHeight
= swapchain_desc
->backbuffer_height
;
193 present_parameters
->BackBufferFormat
= d3dformat_from_wined3dformat(swapchain_desc
->backbuffer_format
);
194 present_parameters
->BackBufferCount
= swapchain_desc
->backbuffer_count
;
195 present_parameters
->MultiSampleType
= swapchain_desc
->multisample_type
;
196 present_parameters
->MultiSampleQuality
= swapchain_desc
->multisample_quality
;
197 present_parameters
->SwapEffect
= swapchain_desc
->swap_effect
;
198 present_parameters
->hDeviceWindow
= swapchain_desc
->device_window
;
199 present_parameters
->Windowed
= swapchain_desc
->windowed
;
200 present_parameters
->EnableAutoDepthStencil
= swapchain_desc
->enable_auto_depth_stencil
;
201 present_parameters
->AutoDepthStencilFormat
202 = d3dformat_from_wined3dformat(swapchain_desc
->auto_depth_stencil_format
);
203 present_parameters
->Flags
= swapchain_desc
->flags
;
204 present_parameters
->FullScreen_RefreshRateInHz
= swapchain_desc
->refresh_rate
;
205 present_parameters
->PresentationInterval
= swapchain_desc
->swap_interval
;
208 static void wined3d_swapchain_desc_from_present_parameters(struct wined3d_swapchain_desc
*swapchain_desc
,
209 const D3DPRESENT_PARAMETERS
*present_parameters
)
211 swapchain_desc
->backbuffer_width
= present_parameters
->BackBufferWidth
;
212 swapchain_desc
->backbuffer_height
= present_parameters
->BackBufferHeight
;
213 swapchain_desc
->backbuffer_format
= wined3dformat_from_d3dformat(present_parameters
->BackBufferFormat
);
214 swapchain_desc
->backbuffer_count
= max(1, present_parameters
->BackBufferCount
);
215 swapchain_desc
->multisample_type
= present_parameters
->MultiSampleType
;
216 swapchain_desc
->multisample_quality
= present_parameters
->MultiSampleQuality
;
217 swapchain_desc
->swap_effect
= present_parameters
->SwapEffect
;
218 swapchain_desc
->device_window
= present_parameters
->hDeviceWindow
;
219 swapchain_desc
->windowed
= present_parameters
->Windowed
;
220 swapchain_desc
->enable_auto_depth_stencil
= present_parameters
->EnableAutoDepthStencil
;
221 swapchain_desc
->auto_depth_stencil_format
222 = wined3dformat_from_d3dformat(present_parameters
->AutoDepthStencilFormat
);
223 swapchain_desc
->flags
= present_parameters
->Flags
;
224 swapchain_desc
->refresh_rate
= present_parameters
->FullScreen_RefreshRateInHz
;
225 swapchain_desc
->swap_interval
= present_parameters
->PresentationInterval
;
226 swapchain_desc
->auto_restore_display_mode
= TRUE
;
229 static HRESULT WINAPI
d3d9_device_QueryInterface(IDirect3DDevice9Ex
*iface
, REFIID riid
, void **out
)
231 TRACE("iface %p, riid %s, out %p.\n", iface
, debugstr_guid(riid
), out
);
233 if (IsEqualGUID(riid
, &IID_IDirect3DDevice9
)
234 || IsEqualGUID(riid
, &IID_IUnknown
))
236 IDirect3DDevice9Ex_AddRef(iface
);
241 if (IsEqualGUID(riid
, &IID_IDirect3DDevice9Ex
))
243 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
245 /* Find out if the creating d3d9 interface was created with Direct3DCreate9Ex.
246 * It doesn't matter with which function the device was created. */
247 if (!device
->d3d_parent
->extended
)
249 WARN("IDirect3D9 instance wasn't created with CreateDirect3D9Ex, returning E_NOINTERFACE.\n");
251 return E_NOINTERFACE
;
254 IDirect3DDevice9Ex_AddRef(iface
);
259 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
262 return E_NOINTERFACE
;
265 static ULONG WINAPI
d3d9_device_AddRef(IDirect3DDevice9Ex
*iface
)
267 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
268 ULONG refcount
= InterlockedIncrement(&device
->refcount
);
270 TRACE("%p increasing refcount to %u.\n", iface
, refcount
);
275 static ULONG WINAPI DECLSPEC_HOTPATCH
d3d9_device_Release(IDirect3DDevice9Ex
*iface
)
277 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
280 if (device
->in_destruction
)
283 refcount
= InterlockedDecrement(&device
->refcount
);
285 TRACE("%p decreasing refcount to %u.\n", iface
, refcount
);
290 device
->in_destruction
= TRUE
;
292 wined3d_mutex_lock();
293 for (i
= 0; i
< device
->fvf_decl_count
; ++i
)
295 wined3d_vertex_declaration_decref(device
->fvf_decls
[i
].decl
);
297 HeapFree(GetProcessHeap(), 0, device
->fvf_decls
);
299 if (device
->vertex_buffer
)
300 wined3d_buffer_decref(device
->vertex_buffer
);
301 if (device
->index_buffer
)
302 wined3d_buffer_decref(device
->index_buffer
);
304 wined3d_device_uninit_3d(device
->wined3d_device
);
305 wined3d_device_release_focus_window(device
->wined3d_device
);
306 wined3d_device_decref(device
->wined3d_device
);
307 wined3d_mutex_unlock();
309 IDirect3D9Ex_Release(&device
->d3d_parent
->IDirect3D9Ex_iface
);
311 HeapFree(GetProcessHeap(), 0, device
);
317 static HRESULT WINAPI
d3d9_device_TestCooperativeLevel(IDirect3DDevice9Ex
*iface
)
319 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
321 TRACE("iface %p.\n", iface
);
323 if (device
->not_reset
)
325 TRACE("D3D9 device is marked not reset.\n");
326 return D3DERR_DEVICENOTRESET
;
332 static UINT WINAPI
d3d9_device_GetAvailableTextureMem(IDirect3DDevice9Ex
*iface
)
334 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
337 TRACE("iface %p.\n", iface
);
339 wined3d_mutex_lock();
340 hr
= wined3d_device_get_available_texture_mem(device
->wined3d_device
);
341 wined3d_mutex_unlock();
346 static HRESULT WINAPI
d3d9_device_EvictManagedResources(IDirect3DDevice9Ex
*iface
)
348 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
350 TRACE("iface %p.\n", iface
);
352 wined3d_mutex_lock();
353 wined3d_device_evict_managed_resources(device
->wined3d_device
);
354 wined3d_mutex_unlock();
359 static HRESULT WINAPI
d3d9_device_GetDirect3D(IDirect3DDevice9Ex
*iface
, IDirect3D9
**d3d9
)
361 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
363 TRACE("iface %p, d3d9 %p.\n", iface
, d3d9
);
366 return D3DERR_INVALIDCALL
;
368 return IDirect3D9Ex_QueryInterface(&device
->d3d_parent
->IDirect3D9Ex_iface
, &IID_IDirect3D9
, (void **)d3d9
);
371 static HRESULT WINAPI
d3d9_device_GetDeviceCaps(IDirect3DDevice9Ex
*iface
, D3DCAPS9
*caps
)
373 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
374 WINED3DCAPS
*wined3d_caps
;
377 TRACE("iface %p, caps %p.\n", iface
, caps
);
380 return D3DERR_INVALIDCALL
;
382 if (!(wined3d_caps
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*wined3d_caps
))))
383 return D3DERR_INVALIDCALL
; /* well this is what MSDN says to return */
385 memset(caps
, 0, sizeof(*caps
));
387 wined3d_mutex_lock();
388 hr
= wined3d_device_get_device_caps(device
->wined3d_device
, wined3d_caps
);
389 wined3d_mutex_unlock();
391 WINECAPSTOD3D9CAPS(caps
, wined3d_caps
)
392 HeapFree(GetProcessHeap(), 0, wined3d_caps
);
394 /* Some functionality is implemented in d3d9.dll, not wined3d.dll. Add the needed caps */
395 caps
->DevCaps2
|= D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES
;
402 static HRESULT WINAPI
d3d9_device_GetDisplayMode(IDirect3DDevice9Ex
*iface
, UINT swapchain
, D3DDISPLAYMODE
*mode
)
404 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
405 struct wined3d_display_mode wined3d_mode
;
408 TRACE("iface %p, swapchain %u, mode %p.\n", iface
, swapchain
, mode
);
410 wined3d_mutex_lock();
411 hr
= wined3d_device_get_display_mode(device
->wined3d_device
, swapchain
, &wined3d_mode
, NULL
);
412 wined3d_mutex_unlock();
416 mode
->Width
= wined3d_mode
.width
;
417 mode
->Height
= wined3d_mode
.height
;
418 mode
->RefreshRate
= wined3d_mode
.refresh_rate
;
419 mode
->Format
= d3dformat_from_wined3dformat(wined3d_mode
.format_id
);
425 static HRESULT WINAPI
d3d9_device_GetCreationParameters(IDirect3DDevice9Ex
*iface
,
426 D3DDEVICE_CREATION_PARAMETERS
*parameters
)
428 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
430 TRACE("iface %p, parameters %p.\n", iface
, parameters
);
432 wined3d_mutex_lock();
433 wined3d_device_get_creation_parameters(device
->wined3d_device
,
434 (struct wined3d_device_creation_parameters
*)parameters
);
435 wined3d_mutex_unlock();
440 static HRESULT WINAPI
d3d9_device_SetCursorProperties(IDirect3DDevice9Ex
*iface
,
441 UINT hotspot_x
, UINT hotspot_y
, IDirect3DSurface9
*bitmap
)
443 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
444 struct d3d9_surface
*bitmap_impl
= unsafe_impl_from_IDirect3DSurface9(bitmap
);
447 TRACE("iface %p, hotspot_x %u, hotspot_y %u, bitmap %p.\n",
448 iface
, hotspot_x
, hotspot_y
, bitmap
);
452 WARN("No cursor bitmap, returning D3DERR_INVALIDCALL.\n");
453 return D3DERR_INVALIDCALL
;
456 wined3d_mutex_lock();
457 hr
= wined3d_device_set_cursor_properties(device
->wined3d_device
,
458 hotspot_x
, hotspot_y
, bitmap_impl
->wined3d_surface
);
459 wined3d_mutex_unlock();
464 static void WINAPI
d3d9_device_SetCursorPosition(IDirect3DDevice9Ex
*iface
, int x
, int y
, DWORD flags
)
466 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
468 TRACE("iface %p, x %u, y %u, flags %#x.\n", iface
, x
, y
, flags
);
470 wined3d_mutex_lock();
471 wined3d_device_set_cursor_position(device
->wined3d_device
, x
, y
, flags
);
472 wined3d_mutex_unlock();
475 static BOOL WINAPI
d3d9_device_ShowCursor(IDirect3DDevice9Ex
*iface
, BOOL show
)
477 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
480 TRACE("iface %p, show %#x.\n", iface
, show
);
482 wined3d_mutex_lock();
483 ret
= wined3d_device_show_cursor(device
->wined3d_device
, show
);
484 wined3d_mutex_unlock();
489 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_device_CreateAdditionalSwapChain(IDirect3DDevice9Ex
*iface
,
490 D3DPRESENT_PARAMETERS
*present_parameters
, IDirect3DSwapChain9
**swapchain
)
492 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
493 struct wined3d_swapchain_desc desc
;
494 struct d3d9_swapchain
*object
;
497 TRACE("iface %p, present_parameters %p, swapchain %p.\n",
498 iface
, present_parameters
, swapchain
);
500 wined3d_swapchain_desc_from_present_parameters(&desc
, present_parameters
);
501 if (SUCCEEDED(hr
= d3d9_swapchain_create(device
, &desc
, &object
)))
502 *swapchain
= (IDirect3DSwapChain9
*)&object
->IDirect3DSwapChain9Ex_iface
;
503 present_parameters_from_wined3d_swapchain_desc(present_parameters
, &desc
);
508 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_device_GetSwapChain(IDirect3DDevice9Ex
*iface
,
509 UINT swapchain_idx
, IDirect3DSwapChain9
**swapchain
)
511 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
512 struct wined3d_swapchain
*wined3d_swapchain
;
513 struct d3d9_swapchain
*swapchain_impl
;
516 TRACE("iface %p, swapchain_idx %u, swapchain %p.\n", iface
, swapchain_idx
, swapchain
);
518 wined3d_mutex_lock();
519 if ((wined3d_swapchain
= wined3d_device_get_swapchain(device
->wined3d_device
, swapchain_idx
)))
521 swapchain_impl
= wined3d_swapchain_get_parent(wined3d_swapchain
);
522 *swapchain
= (IDirect3DSwapChain9
*)&swapchain_impl
->IDirect3DSwapChain9Ex_iface
;
523 IDirect3DSwapChain9Ex_AddRef(*swapchain
);
529 hr
= D3DERR_INVALIDCALL
;
531 wined3d_mutex_unlock();
536 static UINT WINAPI
d3d9_device_GetNumberOfSwapChains(IDirect3DDevice9Ex
*iface
)
538 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
541 TRACE("iface %p.\n", iface
);
543 wined3d_mutex_lock();
544 count
= wined3d_device_get_swapchain_count(device
->wined3d_device
);
545 wined3d_mutex_unlock();
550 static HRESULT CDECL
reset_enum_callback(struct wined3d_resource
*resource
)
552 struct wined3d_resource_desc desc
;
554 wined3d_resource_get_desc(resource
, &desc
);
555 if (desc
.pool
== WINED3D_POOL_DEFAULT
)
557 struct d3d9_surface
*surface
;
559 if (desc
.resource_type
== WINED3D_RTYPE_TEXTURE
)
561 IUnknown
*parent
= wined3d_resource_get_parent(resource
);
562 IDirect3DBaseTexture9
*texture
;
564 if (SUCCEEDED(IUnknown_QueryInterface(parent
, &IID_IDirect3DBaseTexture9
, (void **)&texture
)))
566 IDirect3DBaseTexture9_Release(texture
);
567 WARN("Texture %p (resource %p) in pool D3DPOOL_DEFAULT blocks the Reset call.\n", texture
, resource
);
568 return D3DERR_INVALIDCALL
;
574 if (desc
.resource_type
!= WINED3D_RTYPE_SURFACE
)
576 WARN("Resource %p in pool D3DPOOL_DEFAULT blocks the Reset call.\n", resource
);
577 return D3DERR_INVALIDCALL
;
580 surface
= wined3d_resource_get_parent(resource
);
581 if (surface
->resource
.refcount
)
583 WARN("Surface %p (resource %p) in pool D3DPOOL_DEFAULT blocks the Reset call.\n", surface
, resource
);
584 return D3DERR_INVALIDCALL
;
587 WARN("Surface %p (resource %p) is an implicit resource with ref 0.\n", surface
, resource
);
593 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_device_Reset(IDirect3DDevice9Ex
*iface
,
594 D3DPRESENT_PARAMETERS
*present_parameters
)
596 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
597 struct wined3d_swapchain_desc swapchain_desc
;
600 TRACE("iface %p, present_parameters %p.\n", iface
, present_parameters
);
602 wined3d_mutex_lock();
604 if (device
->vertex_buffer
)
606 wined3d_buffer_decref(device
->vertex_buffer
);
607 device
->vertex_buffer
= NULL
;
608 device
->vertex_buffer_size
= 0;
610 if (device
->index_buffer
)
612 wined3d_buffer_decref(device
->index_buffer
);
613 device
->index_buffer
= NULL
;
614 device
->index_buffer_size
= 0;
617 wined3d_swapchain_desc_from_present_parameters(&swapchain_desc
, present_parameters
);
618 hr
= wined3d_device_reset(device
->wined3d_device
, &swapchain_desc
,
619 NULL
, reset_enum_callback
, !device
->d3d_parent
->extended
);
620 if (FAILED(hr
) && !device
->d3d_parent
->extended
)
621 device
->not_reset
= TRUE
;
623 device
->not_reset
= FALSE
;
624 wined3d_mutex_unlock();
629 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_device_Present(IDirect3DDevice9Ex
*iface
,
630 const RECT
*src_rect
, const RECT
*dst_rect
, HWND dst_window_override
, const RGNDATA
*dirty_region
)
632 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
635 TRACE("iface %p, src_rect %p, dst_rect %p, dst_window_override %p, dirty_region %p.\n",
636 iface
, src_rect
, dst_rect
, dst_window_override
, dirty_region
);
638 wined3d_mutex_lock();
639 hr
= wined3d_device_present(device
->wined3d_device
, src_rect
, dst_rect
,
640 dst_window_override
, dirty_region
, 0);
641 wined3d_mutex_unlock();
646 static HRESULT WINAPI
d3d9_device_GetBackBuffer(IDirect3DDevice9Ex
*iface
, UINT swapchain
,
647 UINT backbuffer_idx
, D3DBACKBUFFER_TYPE backbuffer_type
, IDirect3DSurface9
**backbuffer
)
649 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
650 struct wined3d_surface
*wined3d_surface
= NULL
;
651 struct d3d9_surface
*surface_impl
;
654 TRACE("iface %p, swapchain %u, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n",
655 iface
, swapchain
, backbuffer_idx
, backbuffer_type
, backbuffer
);
657 wined3d_mutex_lock();
658 hr
= wined3d_device_get_back_buffer(device
->wined3d_device
, swapchain
,
659 backbuffer_idx
, (enum wined3d_backbuffer_type
)backbuffer_type
, &wined3d_surface
);
660 if (SUCCEEDED(hr
) && wined3d_surface
&& backbuffer
)
662 surface_impl
= wined3d_surface_get_parent(wined3d_surface
);
663 *backbuffer
= &surface_impl
->IDirect3DSurface9_iface
;
664 IDirect3DSurface9_AddRef(*backbuffer
);
666 wined3d_mutex_unlock();
670 static HRESULT WINAPI
d3d9_device_GetRasterStatus(IDirect3DDevice9Ex
*iface
,
671 UINT swapchain
, D3DRASTER_STATUS
*raster_status
)
673 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
676 TRACE("iface %p, swapchain %u, raster_status %p.\n", iface
, swapchain
, raster_status
);
678 wined3d_mutex_lock();
679 hr
= wined3d_device_get_raster_status(device
->wined3d_device
,
680 swapchain
, (struct wined3d_raster_status
*)raster_status
);
681 wined3d_mutex_unlock();
686 static HRESULT WINAPI
d3d9_device_SetDialogBoxMode(IDirect3DDevice9Ex
*iface
, BOOL enable
)
688 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
691 TRACE("iface %p, enable %#x.\n", iface
, enable
);
693 wined3d_mutex_lock();
694 hr
= wined3d_device_set_dialog_box_mode(device
->wined3d_device
, enable
);
695 wined3d_mutex_unlock();
700 static void WINAPI
d3d9_device_SetGammaRamp(IDirect3DDevice9Ex
*iface
,
701 UINT swapchain
, DWORD flags
, const D3DGAMMARAMP
*ramp
)
703 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
705 TRACE("iface %p, swapchain %u, flags %#x, ramp %p.\n", iface
, swapchain
, flags
, ramp
);
707 /* Note: D3DGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
708 wined3d_mutex_lock();
709 wined3d_device_set_gamma_ramp(device
->wined3d_device
, swapchain
, flags
, (const struct wined3d_gamma_ramp
*)ramp
);
710 wined3d_mutex_unlock();
713 static void WINAPI
d3d9_device_GetGammaRamp(IDirect3DDevice9Ex
*iface
, UINT swapchain
, D3DGAMMARAMP
*ramp
)
715 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
717 TRACE("iface %p, swapchain %u, ramp %p.\n", iface
, swapchain
, ramp
);
719 /* Note: D3DGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
720 wined3d_mutex_lock();
721 wined3d_device_get_gamma_ramp(device
->wined3d_device
, swapchain
, (struct wined3d_gamma_ramp
*)ramp
);
722 wined3d_mutex_unlock();
725 static HRESULT WINAPI
d3d9_device_CreateTexture(IDirect3DDevice9Ex
*iface
,
726 UINT width
, UINT height
, UINT levels
, DWORD usage
, D3DFORMAT format
,
727 D3DPOOL pool
, IDirect3DTexture9
**texture
, HANDLE
*shared_handle
)
729 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
730 struct d3d9_texture
*object
;
731 BOOL set_mem
= FALSE
;
734 TRACE("iface %p, width %u, height %u, levels %u, usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
735 iface
, width
, height
, levels
, usage
, format
, pool
, texture
, shared_handle
);
740 if (!device
->d3d_parent
->extended
)
742 WARN("Trying to create a shared or user memory texture on a non-ex device.\n");
746 if (pool
== D3DPOOL_SYSTEMMEM
)
749 return D3DERR_INVALIDCALL
;
754 if (pool
!= D3DPOOL_DEFAULT
)
756 WARN("Trying to create a shared texture in pool %#x.\n", pool
);
757 return D3DERR_INVALIDCALL
;
759 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
763 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
765 return D3DERR_OUTOFVIDEOMEMORY
;
767 hr
= texture_init(object
, device
, width
, height
, levels
, usage
, format
, pool
);
770 WARN("Failed to initialize texture, hr %#x.\n", hr
);
771 HeapFree(GetProcessHeap(), 0, object
);
777 struct wined3d_resource
*resource
;
778 struct d3d9_surface
*surface
;
780 resource
= wined3d_texture_get_sub_resource(object
->wined3d_texture
, 0);
781 surface
= wined3d_resource_get_parent(resource
);
782 wined3d_surface_update_desc(surface
->wined3d_surface
, width
, height
,
783 wined3dformat_from_d3dformat(format
), WINED3D_MULTISAMPLE_NONE
, 0,
787 TRACE("Created texture %p.\n", object
);
788 *texture
= (IDirect3DTexture9
*)&object
->IDirect3DBaseTexture9_iface
;
793 static HRESULT WINAPI
d3d9_device_CreateVolumeTexture(IDirect3DDevice9Ex
*iface
,
794 UINT width
, UINT height
, UINT depth
, UINT levels
, DWORD usage
, D3DFORMAT format
,
795 D3DPOOL pool
, IDirect3DVolumeTexture9
**texture
, HANDLE
*shared_handle
)
797 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
798 struct d3d9_texture
*object
;
801 TRACE("iface %p, width %u, height %u, depth %u, levels %u\n",
802 iface
, width
, height
, depth
, levels
);
803 TRACE("usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
804 usage
, format
, pool
, texture
, shared_handle
);
809 if (!device
->d3d_parent
->extended
)
811 WARN("Trying to create a shared volume texture on a non-ex device.\n");
815 if (pool
!= D3DPOOL_DEFAULT
)
817 WARN("Trying to create a shared volume texture in pool %#x.\n", pool
);
818 return D3DERR_INVALIDCALL
;
820 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
823 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
825 return D3DERR_OUTOFVIDEOMEMORY
;
827 hr
= volumetexture_init(object
, device
, width
, height
, depth
, levels
, usage
, format
, pool
);
830 WARN("Failed to initialize volume texture, hr %#x.\n", hr
);
831 HeapFree(GetProcessHeap(), 0, object
);
835 TRACE("Created volume texture %p.\n", object
);
836 *texture
= (IDirect3DVolumeTexture9
*)&object
->IDirect3DBaseTexture9_iface
;
841 static HRESULT WINAPI
d3d9_device_CreateCubeTexture(IDirect3DDevice9Ex
*iface
,
842 UINT edge_length
, UINT levels
, DWORD usage
, D3DFORMAT format
, D3DPOOL pool
,
843 IDirect3DCubeTexture9
**texture
, HANDLE
*shared_handle
)
845 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
846 struct d3d9_texture
*object
;
849 TRACE("iface %p, edge_length %u, levels %u, usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
850 iface
, edge_length
, levels
, usage
, format
, pool
, texture
, shared_handle
);
855 if (!device
->d3d_parent
->extended
)
857 WARN("Trying to create a shared cube texture on a non-ex device.\n");
861 if (pool
!= D3DPOOL_DEFAULT
)
863 WARN("Trying to create a shared cube texture in pool %#x.\n", pool
);
864 return D3DERR_INVALIDCALL
;
866 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
869 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
871 return D3DERR_OUTOFVIDEOMEMORY
;
873 hr
= cubetexture_init(object
, device
, edge_length
, levels
, usage
, format
, pool
);
876 WARN("Failed to initialize cube texture, hr %#x.\n", hr
);
877 HeapFree(GetProcessHeap(), 0, object
);
881 TRACE("Created cube texture %p.\n", object
);
882 *texture
= (IDirect3DCubeTexture9
*)&object
->IDirect3DBaseTexture9_iface
;
887 static HRESULT WINAPI
d3d9_device_CreateVertexBuffer(IDirect3DDevice9Ex
*iface
, UINT size
,
888 DWORD usage
, DWORD fvf
, D3DPOOL pool
, IDirect3DVertexBuffer9
**buffer
,
889 HANDLE
*shared_handle
)
891 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
892 struct d3d9_vertexbuffer
*object
;
895 TRACE("iface %p, size %u, usage %#x, fvf %#x, pool %#x, buffer %p, shared_handle %p.\n",
896 iface
, size
, usage
, fvf
, pool
, buffer
, shared_handle
);
900 if (!device
->d3d_parent
->extended
)
902 WARN("Trying to create a shared vertex buffer on a non-ex device.\n");
906 if (pool
!= D3DPOOL_DEFAULT
)
908 WARN("Trying to create a shared vertex buffer in pool %#x.\n", pool
);
909 return D3DERR_NOTAVAILABLE
;
911 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
914 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
916 return D3DERR_OUTOFVIDEOMEMORY
;
918 hr
= vertexbuffer_init(object
, device
, size
, usage
, fvf
, pool
);
921 WARN("Failed to initialize vertex buffer, hr %#x.\n", hr
);
922 HeapFree(GetProcessHeap(), 0, object
);
926 TRACE("Created vertex buffer %p.\n", object
);
927 *buffer
= &object
->IDirect3DVertexBuffer9_iface
;
932 static HRESULT WINAPI
d3d9_device_CreateIndexBuffer(IDirect3DDevice9Ex
*iface
, UINT size
,
933 DWORD usage
, D3DFORMAT format
, D3DPOOL pool
, IDirect3DIndexBuffer9
**buffer
,
934 HANDLE
*shared_handle
)
936 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
937 struct d3d9_indexbuffer
*object
;
940 TRACE("iface %p, size %u, usage %#x, format %#x, pool %#x, buffer %p, shared_handle %p.\n",
941 iface
, size
, usage
, format
, pool
, buffer
, shared_handle
);
945 if (!device
->d3d_parent
->extended
)
947 WARN("Trying to create a shared index buffer on a non-ex device.\n");
951 if (pool
!= D3DPOOL_DEFAULT
)
953 WARN("Trying to create a shared index buffer in pool %#x.\n", pool
);
954 return D3DERR_NOTAVAILABLE
;
956 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
959 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
961 return D3DERR_OUTOFVIDEOMEMORY
;
963 hr
= indexbuffer_init(object
, device
, size
, usage
, format
, pool
);
966 WARN("Failed to initialize index buffer, hr %#x.\n", hr
);
967 HeapFree(GetProcessHeap(), 0, object
);
971 TRACE("Created index buffer %p.\n", object
);
972 *buffer
= &object
->IDirect3DIndexBuffer9_iface
;
977 static HRESULT
d3d9_device_create_surface(struct d3d9_device
*device
, UINT width
, UINT height
,
978 D3DFORMAT format
, DWORD flags
, IDirect3DSurface9
**surface
, UINT usage
, D3DPOOL pool
,
979 D3DMULTISAMPLE_TYPE multisample_type
, DWORD multisample_quality
, void *user_mem
)
981 struct wined3d_resource
*sub_resource
;
982 struct wined3d_resource_desc desc
;
983 struct d3d9_surface
*surface_impl
;
984 struct wined3d_texture
*texture
;
987 TRACE("device %p, width %u, height %u, format %#x, flags %#x, surface %p.\n"
988 "usage %#x, pool %#x, multisample_type %#x, multisample_quality %u.\n",
989 device
, width
, height
, format
, flags
, surface
, usage
, pool
,
990 multisample_type
, multisample_quality
);
992 desc
.resource_type
= WINED3D_RTYPE_TEXTURE
;
993 desc
.format
= wined3dformat_from_d3dformat(format
);
994 desc
.multisample_type
= multisample_type
;
995 desc
.multisample_quality
= multisample_quality
;
996 desc
.usage
= usage
& WINED3DUSAGE_MASK
;
999 desc
.height
= height
;
1003 wined3d_mutex_lock();
1005 if (FAILED(hr
= wined3d_texture_create(device
->wined3d_device
, &desc
,
1006 1, flags
, NULL
, &d3d9_null_wined3d_parent_ops
, &texture
)))
1008 wined3d_mutex_unlock();
1009 WARN("Failed to create texture, hr %#x.\n", hr
);
1013 sub_resource
= wined3d_texture_get_sub_resource(texture
, 0);
1014 surface_impl
= wined3d_resource_get_parent(sub_resource
);
1015 surface_impl
->forwardReference
= NULL
;
1016 surface_impl
->parent_device
= &device
->IDirect3DDevice9Ex_iface
;
1017 *surface
= &surface_impl
->IDirect3DSurface9_iface
;
1018 IDirect3DSurface9_AddRef(*surface
);
1019 wined3d_texture_decref(texture
);
1022 wined3d_surface_update_desc(surface_impl
->wined3d_surface
, width
, height
,
1023 desc
.format
, multisample_type
, multisample_quality
, user_mem
, 0);
1025 wined3d_mutex_unlock();
1030 static HRESULT WINAPI
d3d9_device_CreateRenderTarget(IDirect3DDevice9Ex
*iface
, UINT width
, UINT height
,
1031 D3DFORMAT format
, D3DMULTISAMPLE_TYPE multisample_type
, DWORD multisample_quality
,
1032 BOOL lockable
, IDirect3DSurface9
**surface
, HANDLE
*shared_handle
)
1034 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1037 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u.\n"
1038 "lockable %#x, surface %p, shared_handle %p.\n",
1039 iface
, width
, height
, format
, multisample_type
, multisample_quality
,
1040 lockable
, surface
, shared_handle
);
1045 if (!device
->d3d_parent
->extended
)
1047 WARN("Trying to create a shared render target on a non-ex device.\n");
1051 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
1055 flags
|= WINED3D_SURFACE_MAPPABLE
;
1057 return d3d9_device_create_surface(device
, width
, height
, format
, flags
, surface
,
1058 D3DUSAGE_RENDERTARGET
, D3DPOOL_DEFAULT
, multisample_type
, multisample_quality
, NULL
);
1061 static HRESULT WINAPI
d3d9_device_CreateDepthStencilSurface(IDirect3DDevice9Ex
*iface
, UINT width
, UINT height
,
1062 D3DFORMAT format
, D3DMULTISAMPLE_TYPE multisample_type
, DWORD multisample_quality
,
1063 BOOL discard
, IDirect3DSurface9
**surface
, HANDLE
*shared_handle
)
1065 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1066 DWORD flags
= WINED3D_SURFACE_MAPPABLE
;
1068 TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u.\n"
1069 "discard %#x, surface %p, shared_handle %p.\n",
1070 iface
, width
, height
, format
, multisample_type
, multisample_quality
,
1071 discard
, surface
, shared_handle
);
1076 if (!device
->d3d_parent
->extended
)
1078 WARN("Trying to create a shared depth stencil on a non-ex device.\n");
1082 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
1086 flags
|= WINED3D_SURFACE_DISCARD
;
1088 return d3d9_device_create_surface(device
, width
, height
, format
, flags
, surface
,
1089 D3DUSAGE_DEPTHSTENCIL
, D3DPOOL_DEFAULT
, multisample_type
, multisample_quality
, NULL
);
1093 static HRESULT WINAPI
d3d9_device_UpdateSurface(IDirect3DDevice9Ex
*iface
,
1094 IDirect3DSurface9
*src_surface
, const RECT
*src_rect
,
1095 IDirect3DSurface9
*dst_surface
, const POINT
*dst_point
)
1097 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1098 struct d3d9_surface
*src
= unsafe_impl_from_IDirect3DSurface9(src_surface
);
1099 struct d3d9_surface
*dst
= unsafe_impl_from_IDirect3DSurface9(dst_surface
);
1102 TRACE("iface %p, src_surface %p, src_rect %p, dst_surface %p, dst_point %p.\n",
1103 iface
, src_surface
, src_rect
, dst_surface
, dst_point
);
1105 wined3d_mutex_lock();
1106 hr
= wined3d_device_update_surface(device
->wined3d_device
, src
->wined3d_surface
, src_rect
,
1107 dst
->wined3d_surface
, dst_point
);
1108 wined3d_mutex_unlock();
1113 static HRESULT WINAPI
d3d9_device_UpdateTexture(IDirect3DDevice9Ex
*iface
,
1114 IDirect3DBaseTexture9
*src_texture
, IDirect3DBaseTexture9
*dst_texture
)
1116 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1117 struct d3d9_texture
*src_impl
, *dst_impl
;
1120 TRACE("iface %p, src_texture %p, dst_texture %p.\n", iface
, src_texture
, dst_texture
);
1122 src_impl
= unsafe_impl_from_IDirect3DBaseTexture9(src_texture
);
1123 dst_impl
= unsafe_impl_from_IDirect3DBaseTexture9(dst_texture
);
1125 wined3d_mutex_lock();
1126 hr
= wined3d_device_update_texture(device
->wined3d_device
,
1127 src_impl
->wined3d_texture
, dst_impl
->wined3d_texture
);
1128 wined3d_mutex_unlock();
1133 static HRESULT WINAPI
d3d9_device_GetRenderTargetData(IDirect3DDevice9Ex
*iface
,
1134 IDirect3DSurface9
*render_target
, IDirect3DSurface9
*dst_surface
)
1136 struct d3d9_surface
*rt_impl
= unsafe_impl_from_IDirect3DSurface9(render_target
);
1137 struct d3d9_surface
*dst_impl
= unsafe_impl_from_IDirect3DSurface9(dst_surface
);
1140 TRACE("iface %p, render_target %p, dst_surface %p.\n", iface
, render_target
, dst_surface
);
1142 wined3d_mutex_lock();
1143 hr
= wined3d_surface_get_render_target_data(dst_impl
->wined3d_surface
, rt_impl
->wined3d_surface
);
1144 wined3d_mutex_unlock();
1149 static HRESULT WINAPI
d3d9_device_GetFrontBufferData(IDirect3DDevice9Ex
*iface
,
1150 UINT swapchain
, IDirect3DSurface9
*dst_surface
)
1152 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1153 struct d3d9_surface
*dst_impl
= unsafe_impl_from_IDirect3DSurface9(dst_surface
);
1156 TRACE("iface %p, swapchain %u, dst_surface %p.\n", iface
, swapchain
, dst_surface
);
1158 wined3d_mutex_lock();
1159 hr
= wined3d_device_get_front_buffer_data(device
->wined3d_device
, swapchain
, dst_impl
->wined3d_surface
);
1160 wined3d_mutex_unlock();
1165 static HRESULT WINAPI
d3d9_device_StretchRect(IDirect3DDevice9Ex
*iface
, IDirect3DSurface9
*src_surface
,
1166 const RECT
*src_rect
, IDirect3DSurface9
*dst_surface
, const RECT
*dst_rect
, D3DTEXTUREFILTERTYPE filter
)
1168 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1169 struct d3d9_surface
*src
= unsafe_impl_from_IDirect3DSurface9(src_surface
);
1170 struct d3d9_surface
*dst
= unsafe_impl_from_IDirect3DSurface9(dst_surface
);
1171 HRESULT hr
= D3DERR_INVALIDCALL
;
1172 struct wined3d_resource_desc src_desc
, dst_desc
;
1173 struct wined3d_resource
*wined3d_resource
;
1175 TRACE("iface %p, src_surface %p, src_rect %p, dst_surface %p, dst_rect %p, filter %#x.\n",
1176 iface
, src_surface
, src_rect
, dst_surface
, dst_rect
, filter
);
1178 wined3d_mutex_lock();
1179 wined3d_resource
= wined3d_surface_get_resource(dst
->wined3d_surface
);
1180 wined3d_resource_get_desc(wined3d_resource
, &dst_desc
);
1182 wined3d_resource
= wined3d_surface_get_resource(src
->wined3d_surface
);
1183 wined3d_resource_get_desc(wined3d_resource
, &src_desc
);
1185 if (src_desc
.usage
& WINED3DUSAGE_DEPTHSTENCIL
)
1187 if (device
->in_scene
)
1189 WARN("Rejecting depth / stencil blit while in scene.\n");
1195 if (src_rect
->left
|| src_rect
->top
|| src_rect
->right
!= src_desc
.width
1196 || src_rect
->bottom
!= src_desc
.height
)
1198 WARN("Rejecting depth / stencil blit with invalid source rect %s.\n",
1199 wine_dbgstr_rect(src_rect
));
1205 if (dst_rect
->left
|| dst_rect
->top
|| dst_rect
->right
!= dst_desc
.width
1206 || dst_rect
->bottom
!= dst_desc
.height
)
1208 WARN("Rejecting depth / stencil blit with invalid destination rect %s.\n",
1209 wine_dbgstr_rect(dst_rect
));
1213 if (src_desc
.width
!= dst_desc
.width
|| src_desc
.height
!= dst_desc
.height
)
1215 WARN("Rejecting depth / stencil blit with mismatched surface sizes.\n");
1220 hr
= wined3d_surface_blt(dst
->wined3d_surface
, dst_rect
, src
->wined3d_surface
, src_rect
, 0, NULL
, filter
);
1221 if (hr
== WINEDDERR_INVALIDRECT
)
1222 hr
= D3DERR_INVALIDCALL
;
1225 wined3d_mutex_unlock();
1229 static HRESULT WINAPI
d3d9_device_ColorFill(IDirect3DDevice9Ex
*iface
,
1230 IDirect3DSurface9
*surface
, const RECT
*rect
, D3DCOLOR color
)
1232 const struct wined3d_color c
=
1234 ((color
>> 16) & 0xff) / 255.0f
,
1235 ((color
>> 8) & 0xff) / 255.0f
,
1236 (color
& 0xff) / 255.0f
,
1237 ((color
>> 24) & 0xff) / 255.0f
,
1239 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1240 struct d3d9_surface
*surface_impl
= unsafe_impl_from_IDirect3DSurface9(surface
);
1241 struct wined3d_resource
*wined3d_resource
;
1242 struct wined3d_resource_desc desc
;
1245 TRACE("iface %p, surface %p, rect %p, color 0x%08x.\n", iface
, surface
, rect
, color
);
1247 wined3d_mutex_lock();
1249 wined3d_resource
= wined3d_surface_get_resource(surface_impl
->wined3d_surface
);
1250 wined3d_resource_get_desc(wined3d_resource
, &desc
);
1252 /* This method is only allowed with surfaces that are render targets, or
1253 * offscreen plain surfaces in D3DPOOL_DEFAULT. */
1254 if (!(desc
.usage
& WINED3DUSAGE_RENDERTARGET
) && desc
.pool
!= WINED3D_POOL_DEFAULT
)
1256 wined3d_mutex_unlock();
1257 WARN("Surface is not a render target, or not a stand-alone D3DPOOL_DEFAULT surface\n");
1258 return D3DERR_INVALIDCALL
;
1261 /* Colorfill can only be used on rendertarget surfaces, or offscreen plain surfaces in D3DPOOL_DEFAULT */
1262 hr
= wined3d_device_color_fill(device
->wined3d_device
, surface_impl
->wined3d_surface
, rect
, &c
);
1264 wined3d_mutex_unlock();
1269 static HRESULT WINAPI
d3d9_device_CreateOffscreenPlainSurface(IDirect3DDevice9Ex
*iface
,
1270 UINT width
, UINT height
, D3DFORMAT format
, D3DPOOL pool
, IDirect3DSurface9
**surface
,
1271 HANDLE
*shared_handle
)
1273 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1274 void *user_mem
= NULL
;
1276 TRACE("iface %p, width %u, height %u, format %#x, pool %#x, surface %p, shared_handle %p.\n",
1277 iface
, width
, height
, format
, pool
, surface
, shared_handle
);
1280 if (pool
== D3DPOOL_MANAGED
)
1282 WARN("Attempting to create a managed offscreen plain surface.\n");
1283 return D3DERR_INVALIDCALL
;
1288 if (!device
->d3d_parent
->extended
)
1290 WARN("Trying to create a shared or user memory surface on a non-ex device.\n");
1294 if (pool
== D3DPOOL_SYSTEMMEM
)
1295 user_mem
= *shared_handle
;
1298 if (pool
!= D3DPOOL_DEFAULT
)
1300 WARN("Trying to create a shared surface in pool %#x.\n", pool
);
1301 return D3DERR_INVALIDCALL
;
1303 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
1307 /* FIXME: Offscreen surfaces are supposed to be always lockable,
1308 * regardless of the pool they're created in. Should we set dynamic usage
1310 return d3d9_device_create_surface(device
, width
, height
, format
,
1311 WINED3D_SURFACE_MAPPABLE
, surface
, 0, pool
, D3DMULTISAMPLE_NONE
, 0, user_mem
);
1314 static HRESULT WINAPI
d3d9_device_SetRenderTarget(IDirect3DDevice9Ex
*iface
, DWORD idx
, IDirect3DSurface9
*surface
)
1316 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1317 struct d3d9_surface
*surface_impl
= unsafe_impl_from_IDirect3DSurface9(surface
);
1320 TRACE("iface %p, idx %u, surface %p.\n", iface
, idx
, surface
);
1322 if (idx
>= D3D9_MAX_SIMULTANEOUS_RENDERTARGETS
)
1324 WARN("Invalid index %u specified.\n", idx
);
1325 return D3DERR_INVALIDCALL
;
1328 if (!idx
&& !surface_impl
)
1330 WARN("Trying to set render target 0 to NULL.\n");
1331 return D3DERR_INVALIDCALL
;
1334 wined3d_mutex_lock();
1335 hr
= wined3d_device_set_render_target(device
->wined3d_device
, idx
,
1336 surface_impl
? surface_impl
->wined3d_surface
: NULL
, TRUE
);
1337 wined3d_mutex_unlock();
1342 static HRESULT WINAPI
d3d9_device_GetRenderTarget(IDirect3DDevice9Ex
*iface
, DWORD idx
, IDirect3DSurface9
**surface
)
1344 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1345 struct wined3d_surface
*wined3d_surface
;
1346 struct d3d9_surface
*surface_impl
;
1347 HRESULT hr
= D3D_OK
;
1349 TRACE("iface %p, idx %u, surface %p.\n", iface
, idx
, surface
);
1352 return D3DERR_INVALIDCALL
;
1354 if (idx
>= D3D9_MAX_SIMULTANEOUS_RENDERTARGETS
)
1356 WARN("Invalid index %u specified.\n", idx
);
1357 return D3DERR_INVALIDCALL
;
1360 wined3d_mutex_lock();
1361 if ((wined3d_surface
= wined3d_device_get_render_target(device
->wined3d_device
, idx
)))
1363 surface_impl
= wined3d_surface_get_parent(wined3d_surface
);
1364 *surface
= &surface_impl
->IDirect3DSurface9_iface
;
1365 IDirect3DSurface9_AddRef(*surface
);
1369 hr
= WINED3DERR_NOTFOUND
;
1372 wined3d_mutex_unlock();
1377 static HRESULT WINAPI
d3d9_device_SetDepthStencilSurface(IDirect3DDevice9Ex
*iface
, IDirect3DSurface9
*depth_stencil
)
1379 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1380 struct d3d9_surface
*ds_impl
= unsafe_impl_from_IDirect3DSurface9(depth_stencil
);
1382 TRACE("iface %p, depth_stencil %p.\n", iface
, depth_stencil
);
1384 wined3d_mutex_lock();
1385 wined3d_device_set_depth_stencil(device
->wined3d_device
, ds_impl
? ds_impl
->wined3d_surface
: NULL
);
1386 wined3d_mutex_unlock();
1391 static HRESULT WINAPI
d3d9_device_GetDepthStencilSurface(IDirect3DDevice9Ex
*iface
, IDirect3DSurface9
**depth_stencil
)
1393 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1394 struct wined3d_surface
*wined3d_surface
;
1395 struct d3d9_surface
*surface_impl
;
1396 HRESULT hr
= D3D_OK
;
1398 TRACE("iface %p, depth_stencil %p.\n", iface
, depth_stencil
);
1401 return D3DERR_INVALIDCALL
;
1403 wined3d_mutex_lock();
1404 if ((wined3d_surface
= wined3d_device_get_depth_stencil(device
->wined3d_device
)))
1406 surface_impl
= wined3d_surface_get_parent(wined3d_surface
);
1407 *depth_stencil
= &surface_impl
->IDirect3DSurface9_iface
;
1408 IDirect3DSurface9_AddRef(*depth_stencil
);
1412 hr
= WINED3DERR_NOTFOUND
;
1413 *depth_stencil
= NULL
;
1415 wined3d_mutex_unlock();
1420 static HRESULT WINAPI
d3d9_device_BeginScene(IDirect3DDevice9Ex
*iface
)
1422 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1425 TRACE("iface %p.\n", iface
);
1427 wined3d_mutex_lock();
1428 if (SUCCEEDED(hr
= wined3d_device_begin_scene(device
->wined3d_device
)))
1429 device
->in_scene
= TRUE
;
1430 wined3d_mutex_unlock();
1435 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_device_EndScene(IDirect3DDevice9Ex
*iface
)
1437 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1440 TRACE("iface %p.\n", iface
);
1442 wined3d_mutex_lock();
1443 if (SUCCEEDED(hr
= wined3d_device_end_scene(device
->wined3d_device
)))
1444 device
->in_scene
= FALSE
;
1445 wined3d_mutex_unlock();
1450 static HRESULT WINAPI
d3d9_device_Clear(IDirect3DDevice9Ex
*iface
, DWORD rect_count
,
1451 const D3DRECT
*rects
, DWORD flags
, D3DCOLOR color
, float z
, DWORD stencil
)
1453 const struct wined3d_color c
=
1455 ((color
>> 16) & 0xff) / 255.0f
,
1456 ((color
>> 8) & 0xff) / 255.0f
,
1457 (color
& 0xff) / 255.0f
,
1458 ((color
>> 24) & 0xff) / 255.0f
,
1460 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1463 TRACE("iface %p, rect_count %u, rects %p, flags %#x, color 0x%08x, z %.8e, stencil %u.\n",
1464 iface
, rect_count
, rects
, flags
, color
, z
, stencil
);
1466 wined3d_mutex_lock();
1467 hr
= wined3d_device_clear(device
->wined3d_device
, rect_count
, (const RECT
*)rects
, flags
, &c
, z
, stencil
);
1468 wined3d_mutex_unlock();
1473 static HRESULT WINAPI
d3d9_device_SetTransform(IDirect3DDevice9Ex
*iface
,
1474 D3DTRANSFORMSTATETYPE state
, const D3DMATRIX
*matrix
)
1476 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1478 TRACE("iface %p, state %#x, matrix %p.\n", iface
, state
, matrix
);
1480 /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
1481 wined3d_mutex_lock();
1482 wined3d_device_set_transform(device
->wined3d_device
, state
, (const struct wined3d_matrix
*)matrix
);
1483 wined3d_mutex_unlock();
1488 static HRESULT WINAPI
d3d9_device_GetTransform(IDirect3DDevice9Ex
*iface
,
1489 D3DTRANSFORMSTATETYPE state
, D3DMATRIX
*matrix
)
1491 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1493 TRACE("iface %p, state %#x, matrix %p.\n", iface
, state
, matrix
);
1495 /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
1496 wined3d_mutex_lock();
1497 wined3d_device_get_transform(device
->wined3d_device
, state
, (struct wined3d_matrix
*)matrix
);
1498 wined3d_mutex_unlock();
1503 static HRESULT WINAPI
d3d9_device_MultiplyTransform(IDirect3DDevice9Ex
*iface
,
1504 D3DTRANSFORMSTATETYPE state
, const D3DMATRIX
*matrix
)
1506 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1508 TRACE("iface %p, state %#x, matrix %p.\n", iface
, state
, matrix
);
1510 /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
1511 wined3d_mutex_lock();
1512 wined3d_device_multiply_transform(device
->wined3d_device
, state
, (const struct wined3d_matrix
*)matrix
);
1513 wined3d_mutex_unlock();
1518 static HRESULT WINAPI
d3d9_device_SetViewport(IDirect3DDevice9Ex
*iface
, const D3DVIEWPORT9
*viewport
)
1520 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1522 TRACE("iface %p, viewport %p.\n", iface
, viewport
);
1524 /* Note: D3DVIEWPORT9 is compatible with struct wined3d_viewport. */
1525 wined3d_mutex_lock();
1526 wined3d_device_set_viewport(device
->wined3d_device
, (const struct wined3d_viewport
*)viewport
);
1527 wined3d_mutex_unlock();
1532 static HRESULT WINAPI
d3d9_device_GetViewport(IDirect3DDevice9Ex
*iface
, D3DVIEWPORT9
*viewport
)
1534 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1536 TRACE("iface %p, viewport %p.\n", iface
, viewport
);
1538 /* Note: D3DVIEWPORT9 is compatible with struct wined3d_viewport. */
1539 wined3d_mutex_lock();
1540 wined3d_device_get_viewport(device
->wined3d_device
, (struct wined3d_viewport
*)viewport
);
1541 wined3d_mutex_unlock();
1546 static HRESULT WINAPI
d3d9_device_SetMaterial(IDirect3DDevice9Ex
*iface
, const D3DMATERIAL9
*material
)
1548 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1550 TRACE("iface %p, material %p.\n", iface
, material
);
1552 /* Note: D3DMATERIAL9 is compatible with struct wined3d_material. */
1553 wined3d_mutex_lock();
1554 wined3d_device_set_material(device
->wined3d_device
, (const struct wined3d_material
*)material
);
1555 wined3d_mutex_unlock();
1560 static HRESULT WINAPI
d3d9_device_GetMaterial(IDirect3DDevice9Ex
*iface
, D3DMATERIAL9
*material
)
1562 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1564 TRACE("iface %p, material %p.\n", iface
, material
);
1566 /* Note: D3DMATERIAL9 is compatible with struct wined3d_material. */
1567 wined3d_mutex_lock();
1568 wined3d_device_get_material(device
->wined3d_device
, (struct wined3d_material
*)material
);
1569 wined3d_mutex_unlock();
1574 static HRESULT WINAPI
d3d9_device_SetLight(IDirect3DDevice9Ex
*iface
, DWORD index
, const D3DLIGHT9
*light
)
1576 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1579 TRACE("iface %p, index %u, light %p.\n", iface
, index
, light
);
1581 /* Note: D3DLIGHT9 is compatible with struct wined3d_light. */
1582 wined3d_mutex_lock();
1583 hr
= wined3d_device_set_light(device
->wined3d_device
, index
, (const struct wined3d_light
*)light
);
1584 wined3d_mutex_unlock();
1589 static HRESULT WINAPI
d3d9_device_GetLight(IDirect3DDevice9Ex
*iface
, DWORD index
, D3DLIGHT9
*light
)
1591 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1594 TRACE("iface %p, index %u, light %p.\n", iface
, index
, light
);
1596 /* Note: D3DLIGHT9 is compatible with struct wined3d_light. */
1597 wined3d_mutex_lock();
1598 hr
= wined3d_device_get_light(device
->wined3d_device
, index
, (struct wined3d_light
*)light
);
1599 wined3d_mutex_unlock();
1604 static HRESULT WINAPI
d3d9_device_LightEnable(IDirect3DDevice9Ex
*iface
, DWORD index
, BOOL enable
)
1606 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1609 TRACE("iface %p, index %u, enable %#x.\n", iface
, index
, enable
);
1611 wined3d_mutex_lock();
1612 hr
= wined3d_device_set_light_enable(device
->wined3d_device
, index
, enable
);
1613 wined3d_mutex_unlock();
1618 static HRESULT WINAPI
d3d9_device_GetLightEnable(IDirect3DDevice9Ex
*iface
, DWORD index
, BOOL
*enable
)
1620 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1623 TRACE("iface %p, index %u, enable %p.\n", iface
, index
, enable
);
1625 wined3d_mutex_lock();
1626 hr
= wined3d_device_get_light_enable(device
->wined3d_device
, index
, enable
);
1627 wined3d_mutex_unlock();
1632 static HRESULT WINAPI
d3d9_device_SetClipPlane(IDirect3DDevice9Ex
*iface
, DWORD index
, const float *plane
)
1634 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1637 TRACE("iface %p, index %u, plane %p.\n", iface
, index
, plane
);
1639 wined3d_mutex_lock();
1640 hr
= wined3d_device_set_clip_plane(device
->wined3d_device
, index
, (const struct wined3d_vec4
*)plane
);
1641 wined3d_mutex_unlock();
1646 static HRESULT WINAPI
d3d9_device_GetClipPlane(IDirect3DDevice9Ex
*iface
, DWORD index
, float *plane
)
1648 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1651 TRACE("iface %p, index %u, plane %p.\n", iface
, index
, plane
);
1653 wined3d_mutex_lock();
1654 hr
= wined3d_device_get_clip_plane(device
->wined3d_device
, index
, (struct wined3d_vec4
*)plane
);
1655 wined3d_mutex_unlock();
1660 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_device_SetRenderState(IDirect3DDevice9Ex
*iface
,
1661 D3DRENDERSTATETYPE state
, DWORD value
)
1663 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1665 TRACE("iface %p, state %#x, value %#x.\n", iface
, state
, value
);
1667 wined3d_mutex_lock();
1668 wined3d_device_set_render_state(device
->wined3d_device
, state
, value
);
1669 wined3d_mutex_unlock();
1674 static HRESULT WINAPI
d3d9_device_GetRenderState(IDirect3DDevice9Ex
*iface
,
1675 D3DRENDERSTATETYPE state
, DWORD
*value
)
1677 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1679 TRACE("iface %p, state %#x, value %p.\n", iface
, state
, value
);
1681 wined3d_mutex_lock();
1682 *value
= wined3d_device_get_render_state(device
->wined3d_device
, state
);
1683 wined3d_mutex_unlock();
1688 static HRESULT WINAPI
d3d9_device_CreateStateBlock(IDirect3DDevice9Ex
*iface
,
1689 D3DSTATEBLOCKTYPE type
, IDirect3DStateBlock9
**stateblock
)
1691 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1692 struct d3d9_stateblock
*object
;
1695 TRACE("iface %p, type %#x, stateblock %p.\n", iface
, type
, stateblock
);
1697 if (type
!= D3DSBT_ALL
&& type
!= D3DSBT_PIXELSTATE
&& type
!= D3DSBT_VERTEXSTATE
)
1699 WARN("Unexpected stateblock type, returning D3DERR_INVALIDCALL.\n");
1700 return D3DERR_INVALIDCALL
;
1703 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
1705 return E_OUTOFMEMORY
;
1707 hr
= stateblock_init(object
, device
, type
, NULL
);
1710 WARN("Failed to initialize stateblock, hr %#x.\n", hr
);
1711 HeapFree(GetProcessHeap(), 0, object
);
1715 TRACE("Created stateblock %p.\n", object
);
1716 *stateblock
= &object
->IDirect3DStateBlock9_iface
;
1721 static HRESULT WINAPI
d3d9_device_BeginStateBlock(IDirect3DDevice9Ex
*iface
)
1723 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1726 TRACE("iface %p.\n", iface
);
1728 wined3d_mutex_lock();
1729 hr
= wined3d_device_begin_stateblock(device
->wined3d_device
);
1730 wined3d_mutex_unlock();
1735 static HRESULT WINAPI
d3d9_device_EndStateBlock(IDirect3DDevice9Ex
*iface
, IDirect3DStateBlock9
**stateblock
)
1737 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1738 struct wined3d_stateblock
*wined3d_stateblock
;
1739 struct d3d9_stateblock
*object
;
1742 TRACE("iface %p, stateblock %p.\n", iface
, stateblock
);
1744 wined3d_mutex_lock();
1745 hr
= wined3d_device_end_stateblock(device
->wined3d_device
, &wined3d_stateblock
);
1746 wined3d_mutex_unlock();
1749 WARN("IWineD3DDevice_EndStateBlock() failed, hr %#x.\n", hr
);
1753 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
1756 wined3d_mutex_lock();
1757 wined3d_stateblock_decref(wined3d_stateblock
);
1758 wined3d_mutex_unlock();
1759 return E_OUTOFMEMORY
;
1762 hr
= stateblock_init(object
, device
, 0, wined3d_stateblock
);
1765 WARN("Failed to initialize stateblock, hr %#x.\n", hr
);
1766 wined3d_mutex_lock();
1767 wined3d_stateblock_decref(wined3d_stateblock
);
1768 wined3d_mutex_unlock();
1769 HeapFree(GetProcessHeap(), 0, object
);
1773 TRACE("Created stateblock %p.\n", object
);
1774 *stateblock
= &object
->IDirect3DStateBlock9_iface
;
1779 static HRESULT WINAPI
d3d9_device_SetClipStatus(IDirect3DDevice9Ex
*iface
, const D3DCLIPSTATUS9
*clip_status
)
1781 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1784 TRACE("iface %p, clip_status %p.\n", iface
, clip_status
);
1786 wined3d_mutex_lock();
1787 hr
= wined3d_device_set_clip_status(device
->wined3d_device
, (const struct wined3d_clip_status
*)clip_status
);
1788 wined3d_mutex_unlock();
1793 static HRESULT WINAPI
d3d9_device_GetClipStatus(IDirect3DDevice9Ex
*iface
, D3DCLIPSTATUS9
*clip_status
)
1795 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1798 TRACE("iface %p, clip_status %p.\n", iface
, clip_status
);
1800 wined3d_mutex_lock();
1801 hr
= wined3d_device_get_clip_status(device
->wined3d_device
, (struct wined3d_clip_status
*)clip_status
);
1802 wined3d_mutex_unlock();
1807 static HRESULT WINAPI
d3d9_device_GetTexture(IDirect3DDevice9Ex
*iface
, DWORD stage
, IDirect3DBaseTexture9
**texture
)
1809 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1810 struct wined3d_texture
*wined3d_texture
= NULL
;
1811 struct d3d9_texture
*texture_impl
;
1813 TRACE("iface %p, stage %u, texture %p.\n", iface
, stage
, texture
);
1816 return D3DERR_INVALIDCALL
;
1818 wined3d_mutex_lock();
1819 if ((wined3d_texture
= wined3d_device_get_texture(device
->wined3d_device
, stage
)))
1821 texture_impl
= wined3d_texture_get_parent(wined3d_texture
);
1822 *texture
= &texture_impl
->IDirect3DBaseTexture9_iface
;
1823 IDirect3DBaseTexture9_AddRef(*texture
);
1829 wined3d_mutex_unlock();
1834 static HRESULT WINAPI
d3d9_device_SetTexture(IDirect3DDevice9Ex
*iface
, DWORD stage
, IDirect3DBaseTexture9
*texture
)
1836 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1837 struct d3d9_texture
*texture_impl
;
1840 TRACE("iface %p, stage %u, texture %p.\n", iface
, stage
, texture
);
1842 texture_impl
= unsafe_impl_from_IDirect3DBaseTexture9(texture
);
1844 wined3d_mutex_lock();
1845 hr
= wined3d_device_set_texture(device
->wined3d_device
, stage
,
1846 texture_impl
? texture_impl
->wined3d_texture
: NULL
);
1847 wined3d_mutex_unlock();
1852 static const enum wined3d_texture_stage_state tss_lookup
[] =
1854 WINED3D_TSS_INVALID
, /* 0, unused */
1855 WINED3D_TSS_COLOR_OP
, /* 1, D3DTSS_COLOROP */
1856 WINED3D_TSS_COLOR_ARG1
, /* 2, D3DTSS_COLORARG1 */
1857 WINED3D_TSS_COLOR_ARG2
, /* 3, D3DTSS_COLORARG2 */
1858 WINED3D_TSS_ALPHA_OP
, /* 4, D3DTSS_ALPHAOP */
1859 WINED3D_TSS_ALPHA_ARG1
, /* 5, D3DTSS_ALPHAARG1 */
1860 WINED3D_TSS_ALPHA_ARG2
, /* 6, D3DTSS_ALPHAARG2 */
1861 WINED3D_TSS_BUMPENV_MAT00
, /* 7, D3DTSS_BUMPENVMAT00 */
1862 WINED3D_TSS_BUMPENV_MAT01
, /* 8, D3DTSS_BUMPENVMAT01 */
1863 WINED3D_TSS_BUMPENV_MAT10
, /* 9, D3DTSS_BUMPENVMAT10 */
1864 WINED3D_TSS_BUMPENV_MAT11
, /* 10, D3DTSS_BUMPENVMAT11 */
1865 WINED3D_TSS_TEXCOORD_INDEX
, /* 11, D3DTSS_TEXCOORDINDEX */
1866 WINED3D_TSS_INVALID
, /* 12, unused */
1867 WINED3D_TSS_INVALID
, /* 13, unused */
1868 WINED3D_TSS_INVALID
, /* 14, unused */
1869 WINED3D_TSS_INVALID
, /* 15, unused */
1870 WINED3D_TSS_INVALID
, /* 16, unused */
1871 WINED3D_TSS_INVALID
, /* 17, unused */
1872 WINED3D_TSS_INVALID
, /* 18, unused */
1873 WINED3D_TSS_INVALID
, /* 19, unused */
1874 WINED3D_TSS_INVALID
, /* 20, unused */
1875 WINED3D_TSS_INVALID
, /* 21, unused */
1876 WINED3D_TSS_BUMPENV_LSCALE
, /* 22, D3DTSS_BUMPENVLSCALE */
1877 WINED3D_TSS_BUMPENV_LOFFSET
, /* 23, D3DTSS_BUMPENVLOFFSET */
1878 WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS
, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
1879 WINED3D_TSS_INVALID
, /* 25, unused */
1880 WINED3D_TSS_COLOR_ARG0
, /* 26, D3DTSS_COLORARG0 */
1881 WINED3D_TSS_ALPHA_ARG0
, /* 27, D3DTSS_ALPHAARG0 */
1882 WINED3D_TSS_RESULT_ARG
, /* 28, D3DTSS_RESULTARG */
1883 WINED3D_TSS_INVALID
, /* 29, unused */
1884 WINED3D_TSS_INVALID
, /* 30, unused */
1885 WINED3D_TSS_INVALID
, /* 31, unused */
1886 WINED3D_TSS_CONSTANT
, /* 32, D3DTSS_CONSTANT */
1889 static HRESULT WINAPI
d3d9_device_GetTextureStageState(IDirect3DDevice9Ex
*iface
,
1890 DWORD stage
, D3DTEXTURESTAGESTATETYPE state
, DWORD
*value
)
1892 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1894 TRACE("iface %p, stage %u, state %#x, value %p.\n", iface
, stage
, state
, value
);
1896 if (state
>= sizeof(tss_lookup
) / sizeof(*tss_lookup
))
1898 WARN("Invalid state %#x passed.\n", state
);
1902 wined3d_mutex_lock();
1903 *value
= wined3d_device_get_texture_stage_state(device
->wined3d_device
, stage
, tss_lookup
[state
]);
1904 wined3d_mutex_unlock();
1909 static HRESULT WINAPI
d3d9_device_SetTextureStageState(IDirect3DDevice9Ex
*iface
,
1910 DWORD stage
, D3DTEXTURESTAGESTATETYPE state
, DWORD value
)
1912 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1914 TRACE("iface %p, stage %u, state %#x, value %#x.\n", iface
, stage
, state
, value
);
1916 if (state
>= sizeof(tss_lookup
) / sizeof(*tss_lookup
))
1918 WARN("Invalid state %#x passed.\n", state
);
1922 wined3d_mutex_lock();
1923 wined3d_device_set_texture_stage_state(device
->wined3d_device
, stage
, tss_lookup
[state
], value
);
1924 wined3d_mutex_unlock();
1929 static HRESULT WINAPI
d3d9_device_GetSamplerState(IDirect3DDevice9Ex
*iface
,
1930 DWORD sampler
, D3DSAMPLERSTATETYPE state
, DWORD
*value
)
1932 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1934 TRACE("iface %p, sampler %u, state %#x, value %p.\n", iface
, sampler
, state
, value
);
1936 wined3d_mutex_lock();
1937 *value
= wined3d_device_get_sampler_state(device
->wined3d_device
, sampler
, state
);
1938 wined3d_mutex_unlock();
1943 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_device_SetSamplerState(IDirect3DDevice9Ex
*iface
,
1944 DWORD sampler
, D3DSAMPLERSTATETYPE state
, DWORD value
)
1946 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1948 TRACE("iface %p, sampler %u, state %#x, value %#x.\n", iface
, sampler
, state
, value
);
1950 wined3d_mutex_lock();
1951 wined3d_device_set_sampler_state(device
->wined3d_device
, sampler
, state
, value
);
1952 wined3d_mutex_unlock();
1957 static HRESULT WINAPI
d3d9_device_ValidateDevice(IDirect3DDevice9Ex
*iface
, DWORD
*pass_count
)
1959 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
1962 TRACE("iface %p, pass_count %p.\n", iface
, pass_count
);
1964 wined3d_mutex_lock();
1965 hr
= wined3d_device_validate_device(device
->wined3d_device
, pass_count
);
1966 wined3d_mutex_unlock();
1971 static HRESULT WINAPI
d3d9_device_SetPaletteEntries(IDirect3DDevice9Ex
*iface
,
1972 UINT palette_idx
, const PALETTEENTRY
*entries
)
1974 WARN("iface %p, palette_idx %u, entries %p unimplemented.\n", iface
, palette_idx
, entries
);
1976 /* The d3d9 palette API is non-functional on Windows. Getters and setters are implemented,
1977 * and some drivers allow the creation of P8 surfaces. These surfaces can be copied to
1978 * other P8 surfaces with StretchRect, but cannot be converted to (A)RGB.
1980 * Some older(dx7) cards may have support for P8 textures, but games cannot rely on this. */
1984 static HRESULT WINAPI
d3d9_device_GetPaletteEntries(IDirect3DDevice9Ex
*iface
,
1985 UINT palette_idx
, PALETTEENTRY
*entries
)
1987 FIXME("iface %p, palette_idx %u, entries %p unimplemented.\n", iface
, palette_idx
, entries
);
1989 return D3DERR_INVALIDCALL
;
1992 static HRESULT WINAPI
d3d9_device_SetCurrentTexturePalette(IDirect3DDevice9Ex
*iface
, UINT palette_idx
)
1994 WARN("iface %p, palette_idx %u unimplemented.\n", iface
, palette_idx
);
1999 static HRESULT WINAPI
d3d9_device_GetCurrentTexturePalette(IDirect3DDevice9Ex
*iface
, UINT
*palette_idx
)
2001 FIXME("iface %p, palette_idx %p.\n", iface
, palette_idx
);
2003 return D3DERR_INVALIDCALL
;
2006 static HRESULT WINAPI
d3d9_device_SetScissorRect(IDirect3DDevice9Ex
*iface
, const RECT
*rect
)
2008 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2010 TRACE("iface %p, rect %p.\n", iface
, rect
);
2012 wined3d_mutex_lock();
2013 wined3d_device_set_scissor_rect(device
->wined3d_device
, rect
);
2014 wined3d_mutex_unlock();
2019 static HRESULT WINAPI
d3d9_device_GetScissorRect(IDirect3DDevice9Ex
*iface
, RECT
*rect
)
2021 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2023 TRACE("iface %p, rect %p.\n", iface
, rect
);
2025 wined3d_mutex_lock();
2026 wined3d_device_get_scissor_rect(device
->wined3d_device
, rect
);
2027 wined3d_mutex_unlock();
2032 static HRESULT WINAPI
d3d9_device_SetSoftwareVertexProcessing(IDirect3DDevice9Ex
*iface
, BOOL software
)
2034 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2036 TRACE("iface %p, software %#x.\n", iface
, software
);
2038 wined3d_mutex_lock();
2039 wined3d_device_set_software_vertex_processing(device
->wined3d_device
, software
);
2040 wined3d_mutex_unlock();
2045 static BOOL WINAPI
d3d9_device_GetSoftwareVertexProcessing(IDirect3DDevice9Ex
*iface
)
2047 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2050 TRACE("iface %p.\n", iface
);
2052 wined3d_mutex_lock();
2053 ret
= wined3d_device_get_software_vertex_processing(device
->wined3d_device
);
2054 wined3d_mutex_unlock();
2059 static HRESULT WINAPI
d3d9_device_SetNPatchMode(IDirect3DDevice9Ex
*iface
, float segment_count
)
2061 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2064 TRACE("iface %p, segment_count %.8e.\n", iface
, segment_count
);
2066 wined3d_mutex_lock();
2067 hr
= wined3d_device_set_npatch_mode(device
->wined3d_device
, segment_count
);
2068 wined3d_mutex_unlock();
2073 static float WINAPI
d3d9_device_GetNPatchMode(IDirect3DDevice9Ex
*iface
)
2075 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2078 TRACE("iface %p.\n", iface
);
2080 wined3d_mutex_lock();
2081 ret
= wined3d_device_get_npatch_mode(device
->wined3d_device
);
2082 wined3d_mutex_unlock();
2087 static HRESULT WINAPI
d3d9_device_DrawPrimitive(IDirect3DDevice9Ex
*iface
,
2088 D3DPRIMITIVETYPE primitive_type
, UINT start_vertex
, UINT primitive_count
)
2090 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2093 TRACE("iface %p, primitive_type %#x, start_vertex %u, primitive_count %u.\n",
2094 iface
, primitive_type
, start_vertex
, primitive_count
);
2096 wined3d_mutex_lock();
2097 wined3d_device_set_primitive_type(device
->wined3d_device
, primitive_type
);
2098 hr
= wined3d_device_draw_primitive(device
->wined3d_device
, start_vertex
,
2099 vertex_count_from_primitive_count(primitive_type
, primitive_count
));
2100 wined3d_mutex_unlock();
2105 static HRESULT WINAPI
d3d9_device_DrawIndexedPrimitive(IDirect3DDevice9Ex
*iface
,
2106 D3DPRIMITIVETYPE primitive_type
, INT base_vertex_idx
, UINT min_vertex_idx
,
2107 UINT vertex_count
, UINT start_idx
, UINT primitive_count
)
2109 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2112 TRACE("iface %p, primitive_type %#x, base_vertex_idx %u, min_vertex_idx %u,\n"
2113 "vertex_count %u, start_idx %u, primitive_count %u.\n",
2114 iface
, primitive_type
, base_vertex_idx
, min_vertex_idx
,
2115 vertex_count
, start_idx
, primitive_count
);
2117 wined3d_mutex_lock();
2118 wined3d_device_set_base_vertex_index(device
->wined3d_device
, base_vertex_idx
);
2119 wined3d_device_set_primitive_type(device
->wined3d_device
, primitive_type
);
2120 hr
= wined3d_device_draw_indexed_primitive(device
->wined3d_device
, start_idx
,
2121 vertex_count_from_primitive_count(primitive_type
, primitive_count
));
2122 wined3d_mutex_unlock();
2127 /* The caller is responsible for wined3d locking */
2128 static HRESULT
d3d9_device_prepare_vertex_buffer(struct d3d9_device
*device
, UINT min_size
)
2132 if (device
->vertex_buffer_size
< min_size
|| !device
->vertex_buffer
)
2134 UINT size
= max(device
->vertex_buffer_size
* 2, min_size
);
2135 struct wined3d_buffer
*buffer
;
2137 TRACE("Growing vertex buffer to %u bytes\n", size
);
2139 hr
= wined3d_buffer_create_vb(device
->wined3d_device
, size
, WINED3DUSAGE_DYNAMIC
| WINED3DUSAGE_WRITEONLY
,
2140 WINED3D_POOL_DEFAULT
, NULL
, &d3d9_null_wined3d_parent_ops
, &buffer
);
2143 ERR("(%p) wined3d_buffer_create_vb failed with hr = %08x\n", device
, hr
);
2147 if (device
->vertex_buffer
)
2148 wined3d_buffer_decref(device
->vertex_buffer
);
2150 device
->vertex_buffer
= buffer
;
2151 device
->vertex_buffer_size
= size
;
2152 device
->vertex_buffer_pos
= 0;
2157 static HRESULT WINAPI
d3d9_device_DrawPrimitiveUP(IDirect3DDevice9Ex
*iface
,
2158 D3DPRIMITIVETYPE primitive_type
, UINT primitive_count
, const void *data
, UINT stride
)
2160 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2162 UINT vtx_count
= vertex_count_from_primitive_count(primitive_type
, primitive_count
);
2163 UINT size
= vtx_count
* stride
;
2167 TRACE("iface %p, primitive_type %#x, primitive_count %u, data %p, stride %u.\n",
2168 iface
, primitive_type
, primitive_count
, data
, stride
);
2170 if (!primitive_count
)
2172 WARN("primitive_count is 0, returning D3D_OK\n");
2176 wined3d_mutex_lock();
2178 hr
= d3d9_device_prepare_vertex_buffer(device
, size
);
2182 vb_pos
= device
->vertex_buffer_pos
;
2183 align
= vb_pos
% stride
;
2184 if (align
) align
= stride
- align
;
2185 if (vb_pos
+ size
+ align
> device
->vertex_buffer_size
)
2190 hr
= wined3d_buffer_map(device
->vertex_buffer
, vb_pos
, size
, &buffer_data
,
2191 vb_pos
? WINED3D_MAP_NOOVERWRITE
: WINED3D_MAP_DISCARD
);
2194 memcpy(buffer_data
, data
, size
);
2195 wined3d_buffer_unmap(device
->vertex_buffer
);
2196 device
->vertex_buffer_pos
= vb_pos
+ size
;
2198 hr
= wined3d_device_set_stream_source(device
->wined3d_device
, 0, device
->vertex_buffer
, 0, stride
);
2202 wined3d_device_set_primitive_type(device
->wined3d_device
, primitive_type
);
2203 hr
= wined3d_device_draw_primitive(device
->wined3d_device
, vb_pos
/ stride
, vtx_count
);
2204 wined3d_device_set_stream_source(device
->wined3d_device
, 0, NULL
, 0, 0);
2207 wined3d_mutex_unlock();
2211 /* The caller is responsible for wined3d locking */
2212 static HRESULT
d3d9_device_prepare_index_buffer(struct d3d9_device
*device
, UINT min_size
)
2216 if (device
->index_buffer_size
< min_size
|| !device
->index_buffer
)
2218 UINT size
= max(device
->index_buffer_size
* 2, min_size
);
2219 struct wined3d_buffer
*buffer
;
2221 TRACE("Growing index buffer to %u bytes\n", size
);
2223 hr
= wined3d_buffer_create_ib(device
->wined3d_device
, size
, WINED3DUSAGE_DYNAMIC
| WINED3DUSAGE_WRITEONLY
,
2224 WINED3D_POOL_DEFAULT
, NULL
, &d3d9_null_wined3d_parent_ops
, &buffer
);
2227 ERR("(%p) wined3d_buffer_create_ib failed with hr = %08x\n", device
, hr
);
2231 if (device
->index_buffer
)
2232 wined3d_buffer_decref(device
->index_buffer
);
2234 device
->index_buffer
= buffer
;
2235 device
->index_buffer_size
= size
;
2236 device
->index_buffer_pos
= 0;
2241 static HRESULT WINAPI
d3d9_device_DrawIndexedPrimitiveUP(IDirect3DDevice9Ex
*iface
,
2242 D3DPRIMITIVETYPE primitive_type
, UINT min_vertex_idx
, UINT vertex_count
,
2243 UINT primitive_count
, const void *index_data
, D3DFORMAT index_format
,
2244 const void *vertex_data
, UINT vertex_stride
)
2246 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2250 UINT idx_count
= vertex_count_from_primitive_count(primitive_type
, primitive_count
);
2251 UINT idx_fmt_size
= index_format
== D3DFMT_INDEX16
? 2 : 4;
2252 UINT idx_size
= idx_count
* idx_fmt_size
;
2255 UINT vtx_size
= vertex_count
* vertex_stride
;
2258 TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, vertex_count %u, primitive_count %u,\n"
2259 "index_data %p, index_format %#x, vertex_data %p, vertex_stride %u.\n",
2260 iface
, primitive_type
, min_vertex_idx
, vertex_count
, primitive_count
,
2261 index_data
, index_format
, vertex_data
, vertex_stride
);
2263 if (!primitive_count
)
2265 WARN("primitive_count is 0, returning D3D_OK\n");
2269 wined3d_mutex_lock();
2271 hr
= d3d9_device_prepare_vertex_buffer(device
, vtx_size
);
2275 vb_pos
= device
->vertex_buffer_pos
;
2276 align
= vb_pos
% vertex_stride
;
2277 if (align
) align
= vertex_stride
- align
;
2278 if (vb_pos
+ vtx_size
+ align
> device
->vertex_buffer_size
)
2283 hr
= wined3d_buffer_map(device
->vertex_buffer
, vb_pos
, vtx_size
, &buffer_data
,
2284 vb_pos
? WINED3D_MAP_NOOVERWRITE
: WINED3D_MAP_DISCARD
);
2287 memcpy(buffer_data
, vertex_data
, vtx_size
);
2288 wined3d_buffer_unmap(device
->vertex_buffer
);
2289 device
->vertex_buffer_pos
= vb_pos
+ vtx_size
;
2291 hr
= d3d9_device_prepare_index_buffer(device
, idx_size
);
2295 ib_pos
= device
->index_buffer_pos
;
2296 align
= ib_pos
% idx_fmt_size
;
2297 if (align
) align
= idx_fmt_size
- align
;
2298 if (ib_pos
+ idx_size
+ align
> device
->index_buffer_size
)
2303 hr
= wined3d_buffer_map(device
->index_buffer
, ib_pos
, idx_size
, &buffer_data
,
2304 ib_pos
? WINED3D_MAP_NOOVERWRITE
: WINED3D_MAP_DISCARD
);
2307 memcpy(buffer_data
, index_data
, idx_size
);
2308 wined3d_buffer_unmap(device
->index_buffer
);
2309 device
->index_buffer_pos
= ib_pos
+ idx_size
;
2311 hr
= wined3d_device_set_stream_source(device
->wined3d_device
, 0, device
->vertex_buffer
, 0, vertex_stride
);
2315 wined3d_device_set_index_buffer(device
->wined3d_device
, device
->index_buffer
,
2316 wined3dformat_from_d3dformat(index_format
));
2317 wined3d_device_set_base_vertex_index(device
->wined3d_device
, vb_pos
/ vertex_stride
);
2319 wined3d_device_set_primitive_type(device
->wined3d_device
, primitive_type
);
2320 hr
= wined3d_device_draw_indexed_primitive(device
->wined3d_device
, ib_pos
/ idx_fmt_size
, idx_count
);
2322 wined3d_device_set_stream_source(device
->wined3d_device
, 0, NULL
, 0, 0);
2323 wined3d_device_set_index_buffer(device
->wined3d_device
, NULL
, WINED3DFMT_UNKNOWN
);
2324 wined3d_device_set_base_vertex_index(device
->wined3d_device
, 0);
2327 wined3d_mutex_unlock();
2331 static HRESULT WINAPI
d3d9_device_ProcessVertices(IDirect3DDevice9Ex
*iface
,
2332 UINT src_start_idx
, UINT dst_idx
, UINT vertex_count
, IDirect3DVertexBuffer9
*dst_buffer
,
2333 IDirect3DVertexDeclaration9
*declaration
, DWORD flags
)
2335 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2336 struct d3d9_vertexbuffer
*dst_impl
= unsafe_impl_from_IDirect3DVertexBuffer9(dst_buffer
);
2337 struct d3d9_vertex_declaration
*decl_impl
= unsafe_impl_from_IDirect3DVertexDeclaration9(declaration
);
2340 TRACE("iface %p, src_start_idx %u, dst_idx %u, vertex_count %u, dst_buffer %p, declaration %p, flags %#x.\n",
2341 iface
, src_start_idx
, dst_idx
, vertex_count
, dst_buffer
, declaration
, flags
);
2343 wined3d_mutex_lock();
2344 hr
= wined3d_device_process_vertices(device
->wined3d_device
, src_start_idx
, dst_idx
, vertex_count
,
2345 dst_impl
->wined3d_buffer
, decl_impl
? decl_impl
->wined3d_declaration
: NULL
,
2346 flags
, dst_impl
->fvf
);
2347 wined3d_mutex_unlock();
2352 static HRESULT WINAPI
d3d9_device_CreateVertexDeclaration(IDirect3DDevice9Ex
*iface
,
2353 const D3DVERTEXELEMENT9
*elements
, IDirect3DVertexDeclaration9
**declaration
)
2355 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2356 struct d3d9_vertex_declaration
*object
;
2359 TRACE("iface %p, elements %p, declaration %p.\n", iface
, elements
, declaration
);
2363 WARN("Caller passed a NULL declaration, returning D3DERR_INVALIDCALL.\n");
2364 return D3DERR_INVALIDCALL
;
2367 if (SUCCEEDED(hr
= d3d9_vertex_declaration_create(device
, elements
, &object
)))
2368 *declaration
= &object
->IDirect3DVertexDeclaration9_iface
;
2373 static HRESULT WINAPI
d3d9_device_SetVertexDeclaration(IDirect3DDevice9Ex
*iface
,
2374 IDirect3DVertexDeclaration9
*declaration
)
2376 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2377 struct d3d9_vertex_declaration
*decl_impl
= unsafe_impl_from_IDirect3DVertexDeclaration9(declaration
);
2379 TRACE("iface %p, declaration %p.\n", iface
, declaration
);
2381 wined3d_mutex_lock();
2382 wined3d_device_set_vertex_declaration(device
->wined3d_device
,
2383 decl_impl
? decl_impl
->wined3d_declaration
: NULL
);
2384 wined3d_mutex_unlock();
2389 static HRESULT WINAPI
d3d9_device_GetVertexDeclaration(IDirect3DDevice9Ex
*iface
,
2390 IDirect3DVertexDeclaration9
**declaration
)
2392 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2393 struct wined3d_vertex_declaration
*wined3d_declaration
;
2394 struct d3d9_vertex_declaration
*declaration_impl
;
2396 TRACE("iface %p, declaration %p.\n", iface
, declaration
);
2398 if (!declaration
) return D3DERR_INVALIDCALL
;
2400 wined3d_mutex_lock();
2401 if ((wined3d_declaration
= wined3d_device_get_vertex_declaration(device
->wined3d_device
)))
2403 declaration_impl
= wined3d_vertex_declaration_get_parent(wined3d_declaration
);
2404 *declaration
= &declaration_impl
->IDirect3DVertexDeclaration9_iface
;
2405 IDirect3DVertexDeclaration9_AddRef(*declaration
);
2409 *declaration
= NULL
;
2411 wined3d_mutex_unlock();
2413 TRACE("Returning %p.\n", *declaration
);
2417 static struct wined3d_vertex_declaration
*device_get_fvf_declaration(struct d3d9_device
*device
, DWORD fvf
)
2419 struct wined3d_vertex_declaration
*wined3d_declaration
;
2420 struct fvf_declaration
*fvf_decls
= device
->fvf_decls
;
2421 struct d3d9_vertex_declaration
*d3d9_declaration
;
2422 D3DVERTEXELEMENT9
*elements
;
2423 int p
, low
, high
; /* deliberately signed */
2426 TRACE("Searching for declaration for fvf %08x... ", fvf
);
2429 high
= device
->fvf_decl_count
- 1;
2432 p
= (low
+ high
) >> 1;
2435 if (fvf_decls
[p
].fvf
== fvf
)
2437 TRACE("found %p.\n", fvf_decls
[p
].decl
);
2438 return fvf_decls
[p
].decl
;
2441 if (fvf_decls
[p
].fvf
< fvf
)
2446 TRACE("not found. Creating and inserting at position %d.\n", low
);
2448 if (FAILED(hr
= vdecl_convert_fvf(fvf
, &elements
)))
2451 hr
= d3d9_vertex_declaration_create(device
, elements
, &d3d9_declaration
);
2452 HeapFree(GetProcessHeap(), 0, elements
);
2456 if (device
->fvf_decl_size
== device
->fvf_decl_count
)
2458 UINT grow
= max(device
->fvf_decl_size
/ 2, 8);
2460 fvf_decls
= HeapReAlloc(GetProcessHeap(), 0, fvf_decls
, sizeof(*fvf_decls
) * (device
->fvf_decl_size
+ grow
));
2463 IDirect3DVertexDeclaration9_Release(&d3d9_declaration
->IDirect3DVertexDeclaration9_iface
);
2466 device
->fvf_decls
= fvf_decls
;
2467 device
->fvf_decl_size
+= grow
;
2470 d3d9_declaration
->fvf
= fvf
;
2471 wined3d_declaration
= d3d9_declaration
->wined3d_declaration
;
2472 wined3d_vertex_declaration_incref(wined3d_declaration
);
2473 IDirect3DVertexDeclaration9_Release(&d3d9_declaration
->IDirect3DVertexDeclaration9_iface
);
2475 memmove(fvf_decls
+ low
+ 1, fvf_decls
+ low
, sizeof(*fvf_decls
) * (device
->fvf_decl_count
- low
));
2476 fvf_decls
[low
].decl
= wined3d_declaration
;
2477 fvf_decls
[low
].fvf
= fvf
;
2478 ++device
->fvf_decl_count
;
2480 TRACE("Returning %p. %u declarations in array.\n", wined3d_declaration
, device
->fvf_decl_count
);
2482 return wined3d_declaration
;
2485 static HRESULT WINAPI
d3d9_device_SetFVF(IDirect3DDevice9Ex
*iface
, DWORD fvf
)
2487 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2488 struct wined3d_vertex_declaration
*decl
;
2490 TRACE("iface %p, fvf %#x.\n", iface
, fvf
);
2494 WARN("%#x is not a valid FVF.\n", fvf
);
2498 wined3d_mutex_lock();
2499 if (!(decl
= device_get_fvf_declaration(device
, fvf
)))
2501 wined3d_mutex_unlock();
2502 ERR("Failed to create a vertex declaration for fvf %#x.\n", fvf
);
2503 return D3DERR_DRIVERINTERNALERROR
;
2506 wined3d_device_set_vertex_declaration(device
->wined3d_device
, decl
);
2507 wined3d_mutex_unlock();
2512 static HRESULT WINAPI
d3d9_device_GetFVF(IDirect3DDevice9Ex
*iface
, DWORD
*fvf
)
2514 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2515 struct wined3d_vertex_declaration
*wined3d_declaration
;
2516 struct d3d9_vertex_declaration
*d3d9_declaration
;
2518 TRACE("iface %p, fvf %p.\n", iface
, fvf
);
2520 wined3d_mutex_lock();
2521 if ((wined3d_declaration
= wined3d_device_get_vertex_declaration(device
->wined3d_device
)))
2523 d3d9_declaration
= wined3d_vertex_declaration_get_parent(wined3d_declaration
);
2524 *fvf
= d3d9_declaration
->fvf
;
2530 wined3d_mutex_unlock();
2532 TRACE("Returning FVF %#x.\n", *fvf
);
2537 static HRESULT WINAPI
d3d9_device_CreateVertexShader(IDirect3DDevice9Ex
*iface
,
2538 const DWORD
*byte_code
, IDirect3DVertexShader9
**shader
)
2540 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2541 struct d3d9_vertexshader
*object
;
2544 TRACE("iface %p, byte_code %p, shader %p.\n", iface
, byte_code
, shader
);
2546 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
2548 return E_OUTOFMEMORY
;
2550 hr
= vertexshader_init(object
, device
, byte_code
);
2553 WARN("Failed to initialize vertex shader, hr %#x.\n", hr
);
2554 HeapFree(GetProcessHeap(), 0, object
);
2558 TRACE("Created vertex shader %p.\n", object
);
2559 *shader
= &object
->IDirect3DVertexShader9_iface
;
2564 static HRESULT WINAPI
d3d9_device_SetVertexShader(IDirect3DDevice9Ex
*iface
, IDirect3DVertexShader9
*shader
)
2566 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2567 struct d3d9_vertexshader
*shader_obj
= unsafe_impl_from_IDirect3DVertexShader9(shader
);
2569 TRACE("iface %p, shader %p.\n", iface
, shader
);
2571 wined3d_mutex_lock();
2572 wined3d_device_set_vertex_shader(device
->wined3d_device
,
2573 shader_obj
? shader_obj
->wined3d_shader
: NULL
);
2574 wined3d_mutex_unlock();
2579 static HRESULT WINAPI
d3d9_device_GetVertexShader(IDirect3DDevice9Ex
*iface
, IDirect3DVertexShader9
**shader
)
2581 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2582 struct d3d9_vertexshader
*shader_impl
;
2583 struct wined3d_shader
*wined3d_shader
;
2585 TRACE("iface %p, shader %p.\n", iface
, shader
);
2587 wined3d_mutex_lock();
2588 if ((wined3d_shader
= wined3d_device_get_vertex_shader(device
->wined3d_device
)))
2590 shader_impl
= wined3d_shader_get_parent(wined3d_shader
);
2591 *shader
= &shader_impl
->IDirect3DVertexShader9_iface
;
2592 IDirect3DVertexShader9_AddRef(*shader
);
2598 wined3d_mutex_unlock();
2600 TRACE("Returning %p.\n", *shader
);
2605 static HRESULT WINAPI
d3d9_device_SetVertexShaderConstantF(IDirect3DDevice9Ex
*iface
,
2606 UINT reg_idx
, const float *data
, UINT count
)
2608 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2611 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2613 if (reg_idx
+ count
> D3D9_MAX_VERTEX_SHADER_CONSTANTF
)
2615 WARN("Trying to access %u constants, but d3d9 only supports %u\n",
2616 reg_idx
+ count
, D3D9_MAX_VERTEX_SHADER_CONSTANTF
);
2617 return D3DERR_INVALIDCALL
;
2620 wined3d_mutex_lock();
2621 hr
= wined3d_device_set_vs_consts_f(device
->wined3d_device
, reg_idx
, data
, count
);
2622 wined3d_mutex_unlock();
2627 static HRESULT WINAPI
d3d9_device_GetVertexShaderConstantF(IDirect3DDevice9Ex
*iface
,
2628 UINT reg_idx
, float *data
, UINT count
)
2630 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2633 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2635 if (reg_idx
+ count
> D3D9_MAX_VERTEX_SHADER_CONSTANTF
)
2637 WARN("Trying to access %u constants, but d3d9 only supports %u\n",
2638 reg_idx
+ count
, D3D9_MAX_VERTEX_SHADER_CONSTANTF
);
2639 return D3DERR_INVALIDCALL
;
2642 wined3d_mutex_lock();
2643 hr
= wined3d_device_get_vs_consts_f(device
->wined3d_device
, reg_idx
, data
, count
);
2644 wined3d_mutex_unlock();
2649 static HRESULT WINAPI
d3d9_device_SetVertexShaderConstantI(IDirect3DDevice9Ex
*iface
,
2650 UINT reg_idx
, const int *data
, UINT count
)
2652 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2655 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2657 wined3d_mutex_lock();
2658 hr
= wined3d_device_set_vs_consts_i(device
->wined3d_device
, reg_idx
, data
, count
);
2659 wined3d_mutex_unlock();
2664 static HRESULT WINAPI
d3d9_device_GetVertexShaderConstantI(IDirect3DDevice9Ex
*iface
,
2665 UINT reg_idx
, int *data
, UINT count
)
2667 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2670 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2672 wined3d_mutex_lock();
2673 hr
= wined3d_device_get_vs_consts_i(device
->wined3d_device
, reg_idx
, data
, count
);
2674 wined3d_mutex_unlock();
2679 static HRESULT WINAPI
d3d9_device_SetVertexShaderConstantB(IDirect3DDevice9Ex
*iface
,
2680 UINT reg_idx
, const BOOL
*data
, UINT count
)
2682 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2685 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2687 wined3d_mutex_lock();
2688 hr
= wined3d_device_set_vs_consts_b(device
->wined3d_device
, reg_idx
, data
, count
);
2689 wined3d_mutex_unlock();
2694 static HRESULT WINAPI
d3d9_device_GetVertexShaderConstantB(IDirect3DDevice9Ex
*iface
,
2695 UINT reg_idx
, BOOL
*data
, UINT count
)
2697 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2700 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2702 wined3d_mutex_lock();
2703 hr
= wined3d_device_get_vs_consts_b(device
->wined3d_device
, reg_idx
, data
, count
);
2704 wined3d_mutex_unlock();
2709 static HRESULT WINAPI
d3d9_device_SetStreamSource(IDirect3DDevice9Ex
*iface
,
2710 UINT stream_idx
, IDirect3DVertexBuffer9
*buffer
, UINT offset
, UINT stride
)
2712 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2713 struct d3d9_vertexbuffer
*buffer_impl
= unsafe_impl_from_IDirect3DVertexBuffer9(buffer
);
2716 TRACE("iface %p, stream_idx %u, buffer %p, offset %u, stride %u.\n",
2717 iface
, stream_idx
, buffer
, offset
, stride
);
2719 wined3d_mutex_lock();
2720 hr
= wined3d_device_set_stream_source(device
->wined3d_device
, stream_idx
,
2721 buffer_impl
? buffer_impl
->wined3d_buffer
: NULL
, offset
, stride
);
2722 wined3d_mutex_unlock();
2727 static HRESULT WINAPI
d3d9_device_GetStreamSource(IDirect3DDevice9Ex
*iface
,
2728 UINT stream_idx
, IDirect3DVertexBuffer9
**buffer
, UINT
*offset
, UINT
*stride
)
2730 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2731 struct d3d9_vertexbuffer
*buffer_impl
;
2732 struct wined3d_buffer
*wined3d_buffer
;
2735 TRACE("iface %p, stream_idx %u, buffer %p, offset %p, stride %p.\n",
2736 iface
, stream_idx
, buffer
, offset
, stride
);
2739 return D3DERR_INVALIDCALL
;
2741 wined3d_mutex_lock();
2742 hr
= wined3d_device_get_stream_source(device
->wined3d_device
, stream_idx
, &wined3d_buffer
, offset
, stride
);
2743 if (SUCCEEDED(hr
) && wined3d_buffer
)
2745 buffer_impl
= wined3d_buffer_get_parent(wined3d_buffer
);
2746 *buffer
= &buffer_impl
->IDirect3DVertexBuffer9_iface
;
2747 IDirect3DVertexBuffer9_AddRef(*buffer
);
2748 wined3d_buffer_decref(wined3d_buffer
);
2753 FIXME("Call to GetStreamSource failed %p %p\n", offset
, stride
);
2756 wined3d_mutex_unlock();
2761 static HRESULT WINAPI
d3d9_device_SetStreamSourceFreq(IDirect3DDevice9Ex
*iface
, UINT stream_idx
, UINT freq
)
2763 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2766 TRACE("iface %p, stream_idx %u, freq %u.\n", iface
, stream_idx
, freq
);
2768 wined3d_mutex_lock();
2769 hr
= wined3d_device_set_stream_source_freq(device
->wined3d_device
, stream_idx
, freq
);
2770 wined3d_mutex_unlock();
2775 static HRESULT WINAPI
d3d9_device_GetStreamSourceFreq(IDirect3DDevice9Ex
*iface
, UINT stream_idx
, UINT
*freq
)
2777 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2780 TRACE("iface %p, stream_idx %u, freq %p.\n", iface
, stream_idx
, freq
);
2782 wined3d_mutex_lock();
2783 hr
= wined3d_device_get_stream_source_freq(device
->wined3d_device
, stream_idx
, freq
);
2784 wined3d_mutex_unlock();
2789 static HRESULT WINAPI
d3d9_device_SetIndices(IDirect3DDevice9Ex
*iface
, IDirect3DIndexBuffer9
*buffer
)
2791 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2792 struct d3d9_indexbuffer
*ib
= unsafe_impl_from_IDirect3DIndexBuffer9(buffer
);
2794 TRACE("iface %p, buffer %p.\n", iface
, buffer
);
2796 wined3d_mutex_lock();
2797 wined3d_device_set_index_buffer(device
->wined3d_device
,
2798 ib
? ib
->wined3d_buffer
: NULL
,
2799 ib
? ib
->format
: WINED3DFMT_UNKNOWN
);
2800 wined3d_mutex_unlock();
2805 static HRESULT WINAPI
d3d9_device_GetIndices(IDirect3DDevice9Ex
*iface
, IDirect3DIndexBuffer9
**buffer
)
2807 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2808 enum wined3d_format_id wined3d_format
;
2809 struct wined3d_buffer
*wined3d_buffer
;
2810 struct d3d9_indexbuffer
*buffer_impl
;
2812 TRACE("iface %p, buffer %p.\n", iface
, buffer
);
2815 return D3DERR_INVALIDCALL
;
2817 wined3d_mutex_lock();
2818 if ((wined3d_buffer
= wined3d_device_get_index_buffer(device
->wined3d_device
, &wined3d_format
)))
2820 buffer_impl
= wined3d_buffer_get_parent(wined3d_buffer
);
2821 *buffer
= &buffer_impl
->IDirect3DIndexBuffer9_iface
;
2822 IDirect3DIndexBuffer9_AddRef(*buffer
);
2828 wined3d_mutex_unlock();
2833 static HRESULT WINAPI
d3d9_device_CreatePixelShader(IDirect3DDevice9Ex
*iface
,
2834 const DWORD
*byte_code
, IDirect3DPixelShader9
**shader
)
2836 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2837 struct d3d9_pixelshader
*object
;
2840 TRACE("iface %p, byte_code %p, shader %p.\n", iface
, byte_code
, shader
);
2842 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
2845 FIXME("Failed to allocate pixel shader memory.\n");
2846 return E_OUTOFMEMORY
;
2849 hr
= pixelshader_init(object
, device
, byte_code
);
2852 WARN("Failed to initialize pixel shader, hr %#x.\n", hr
);
2853 HeapFree(GetProcessHeap(), 0, object
);
2857 TRACE("Created pixel shader %p.\n", object
);
2858 *shader
= &object
->IDirect3DPixelShader9_iface
;
2863 static HRESULT WINAPI
d3d9_device_SetPixelShader(IDirect3DDevice9Ex
*iface
, IDirect3DPixelShader9
*shader
)
2865 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2866 struct d3d9_pixelshader
*shader_obj
= unsafe_impl_from_IDirect3DPixelShader9(shader
);
2868 TRACE("iface %p, shader %p.\n", iface
, shader
);
2870 wined3d_mutex_lock();
2871 wined3d_device_set_pixel_shader(device
->wined3d_device
,
2872 shader_obj
? shader_obj
->wined3d_shader
: NULL
);
2873 wined3d_mutex_unlock();
2878 static HRESULT WINAPI
d3d9_device_GetPixelShader(IDirect3DDevice9Ex
*iface
, IDirect3DPixelShader9
**shader
)
2880 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2881 struct d3d9_pixelshader
*shader_impl
;
2882 struct wined3d_shader
*wined3d_shader
;
2884 TRACE("iface %p, shader %p.\n", iface
, shader
);
2886 if (!shader
) return D3DERR_INVALIDCALL
;
2888 wined3d_mutex_lock();
2889 if ((wined3d_shader
= wined3d_device_get_pixel_shader(device
->wined3d_device
)))
2891 shader_impl
= wined3d_shader_get_parent(wined3d_shader
);
2892 *shader
= &shader_impl
->IDirect3DPixelShader9_iface
;
2893 IDirect3DPixelShader9_AddRef(*shader
);
2899 wined3d_mutex_unlock();
2901 TRACE("Returning %p.\n", *shader
);
2906 static HRESULT WINAPI
d3d9_device_SetPixelShaderConstantF(IDirect3DDevice9Ex
*iface
,
2907 UINT reg_idx
, const float *data
, UINT count
)
2909 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2912 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2914 wined3d_mutex_lock();
2915 hr
= wined3d_device_set_ps_consts_f(device
->wined3d_device
, reg_idx
, data
, count
);
2916 wined3d_mutex_unlock();
2921 static HRESULT WINAPI
d3d9_device_GetPixelShaderConstantF(IDirect3DDevice9Ex
*iface
,
2922 UINT reg_idx
, float *data
, UINT count
)
2924 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2927 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2929 wined3d_mutex_lock();
2930 hr
= wined3d_device_get_ps_consts_f(device
->wined3d_device
, reg_idx
, data
, count
);
2931 wined3d_mutex_unlock();
2936 static HRESULT WINAPI
d3d9_device_SetPixelShaderConstantI(IDirect3DDevice9Ex
*iface
,
2937 UINT reg_idx
, const int *data
, UINT count
)
2939 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2942 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2944 wined3d_mutex_lock();
2945 hr
= wined3d_device_set_ps_consts_i(device
->wined3d_device
, reg_idx
, data
, count
);
2946 wined3d_mutex_unlock();
2951 static HRESULT WINAPI
d3d9_device_GetPixelShaderConstantI(IDirect3DDevice9Ex
*iface
,
2952 UINT reg_idx
, int *data
, UINT count
)
2954 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2957 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2959 wined3d_mutex_lock();
2960 hr
= wined3d_device_get_ps_consts_i(device
->wined3d_device
, reg_idx
, data
, count
);
2961 wined3d_mutex_unlock();
2966 static HRESULT WINAPI
d3d9_device_SetPixelShaderConstantB(IDirect3DDevice9Ex
*iface
,
2967 UINT reg_idx
, const BOOL
*data
, UINT count
)
2969 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2972 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2974 wined3d_mutex_lock();
2975 hr
= wined3d_device_set_ps_consts_b(device
->wined3d_device
, reg_idx
, data
, count
);
2976 wined3d_mutex_unlock();
2981 static HRESULT WINAPI
d3d9_device_GetPixelShaderConstantB(IDirect3DDevice9Ex
*iface
,
2982 UINT reg_idx
, BOOL
*data
, UINT count
)
2984 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
2987 TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface
, reg_idx
, data
, count
);
2989 wined3d_mutex_lock();
2990 hr
= wined3d_device_get_ps_consts_b(device
->wined3d_device
, reg_idx
, data
, count
);
2991 wined3d_mutex_unlock();
2996 static HRESULT WINAPI
d3d9_device_DrawRectPatch(IDirect3DDevice9Ex
*iface
, UINT handle
,
2997 const float *segment_count
, const D3DRECTPATCH_INFO
*patch_info
)
2999 FIXME("iface %p, handle %#x, segment_count %p, patch_info %p unimplemented.\n",
3000 iface
, handle
, segment_count
, patch_info
);
3004 static HRESULT WINAPI
d3d9_device_DrawTriPatch(IDirect3DDevice9Ex
*iface
, UINT handle
,
3005 const float *segment_count
, const D3DTRIPATCH_INFO
*patch_info
)
3007 FIXME("iface %p, handle %#x, segment_count %p, patch_info %p unimplemented.\n",
3008 iface
, handle
, segment_count
, patch_info
);
3012 static HRESULT WINAPI
d3d9_device_DeletePatch(IDirect3DDevice9Ex
*iface
, UINT handle
)
3014 FIXME("iface %p, handle %#x unimplemented.\n", iface
, handle
);
3015 return D3DERR_INVALIDCALL
;
3018 static HRESULT WINAPI
d3d9_device_CreateQuery(IDirect3DDevice9Ex
*iface
, D3DQUERYTYPE type
, IDirect3DQuery9
**query
)
3020 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3021 struct d3d9_query
*object
;
3024 TRACE("iface %p, type %#x, query %p.\n", iface
, type
, query
);
3026 object
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*object
));
3028 return E_OUTOFMEMORY
;
3030 hr
= query_init(object
, device
, type
);
3033 WARN("Failed to initialize query, hr %#x.\n", hr
);
3034 HeapFree(GetProcessHeap(), 0, object
);
3038 TRACE("Created query %p.\n", object
);
3039 if (query
) *query
= &object
->IDirect3DQuery9_iface
;
3040 else IDirect3DQuery9_Release(&object
->IDirect3DQuery9_iface
);
3045 static HRESULT WINAPI
d3d9_device_SetConvolutionMonoKernel(IDirect3DDevice9Ex
*iface
,
3046 UINT width
, UINT height
, float *rows
, float *columns
)
3048 FIXME("iface %p, width %u, height %u, rows %p, columns %p stub!\n",
3049 iface
, width
, height
, rows
, columns
);
3054 static HRESULT WINAPI
d3d9_device_ComposeRects(IDirect3DDevice9Ex
*iface
,
3055 IDirect3DSurface9
*src_surface
, IDirect3DSurface9
*dst_surface
, IDirect3DVertexBuffer9
*src_descs
,
3056 UINT rect_count
, IDirect3DVertexBuffer9
*dst_descs
, D3DCOMPOSERECTSOP operation
, INT offset_x
, INT offset_y
)
3058 FIXME("iface %p, src_surface %p, dst_surface %p, src_descs %p, rect_count %u,\n"
3059 "dst_descs %p, operation %#x, offset_x %u, offset_y %u stub!\n",
3060 iface
, src_surface
, dst_surface
, src_descs
, rect_count
,
3061 dst_descs
, operation
, offset_x
, offset_y
);
3066 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_device_PresentEx(IDirect3DDevice9Ex
*iface
,
3067 const RECT
*src_rect
, const RECT
*dst_rect
, HWND dst_window_override
,
3068 const RGNDATA
*dirty_region
, DWORD flags
)
3070 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3073 TRACE("iface %p, src_rect %s, dst_rect %s, dst_window_override %p, dirty_region %p, flags %#x.\n",
3074 iface
, wine_dbgstr_rect(src_rect
), wine_dbgstr_rect(dst_rect
),
3075 dst_window_override
, dirty_region
, flags
);
3077 wined3d_mutex_lock();
3078 hr
= wined3d_device_present(device
->wined3d_device
, src_rect
, dst_rect
,
3079 dst_window_override
, dirty_region
, flags
);
3080 wined3d_mutex_unlock();
3085 static HRESULT WINAPI
d3d9_device_GetGPUThreadPriority(IDirect3DDevice9Ex
*iface
, INT
*priority
)
3087 FIXME("iface %p, priority %p stub!\n", iface
, priority
);
3092 static HRESULT WINAPI
d3d9_device_SetGPUThreadPriority(IDirect3DDevice9Ex
*iface
, INT priority
)
3094 FIXME("iface %p, priority %d stub!\n", iface
, priority
);
3099 static HRESULT WINAPI
d3d9_device_WaitForVBlank(IDirect3DDevice9Ex
*iface
, UINT swapchain_idx
)
3101 FIXME("iface %p, swapchain_idx %u stub!\n", iface
, swapchain_idx
);
3106 static HRESULT WINAPI
d3d9_device_CheckResourceResidency(IDirect3DDevice9Ex
*iface
,
3107 IDirect3DResource9
**resources
, UINT32 resource_count
)
3109 FIXME("iface %p, resources %p, resource_count %u stub!\n",
3110 iface
, resources
, resource_count
);
3115 static HRESULT WINAPI
d3d9_device_SetMaximumFrameLatency(IDirect3DDevice9Ex
*iface
, UINT max_latency
)
3117 FIXME("iface %p, max_latency %u stub!\n", iface
, max_latency
);
3122 static HRESULT WINAPI
d3d9_device_GetMaximumFrameLatency(IDirect3DDevice9Ex
*iface
, UINT
*max_latency
)
3124 FIXME("iface %p, max_latency %p stub!\n", iface
, max_latency
);
3131 static HRESULT WINAPI
d3d9_device_CheckDeviceState(IDirect3DDevice9Ex
*iface
, HWND dst_window
)
3135 TRACE("iface %p, dst_window %p stub!\n", iface
, dst_window
);
3138 FIXME("iface %p, dst_window %p stub!\n", iface
, dst_window
);
3143 static HRESULT WINAPI
d3d9_device_CreateRenderTargetEx(IDirect3DDevice9Ex
*iface
,
3144 UINT width
, UINT height
, D3DFORMAT format
, D3DMULTISAMPLE_TYPE multisample_type
, DWORD multisample_quality
,
3145 BOOL lockable
, IDirect3DSurface9
**surface
, HANDLE
*shared_handle
, DWORD usage
)
3147 FIXME("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u,\n"
3148 "lockable %#x, surface %p, shared_handle %p, usage %#x stub!\n",
3149 iface
, width
, height
, format
, multisample_type
, multisample_quality
,
3150 lockable
, surface
, shared_handle
, usage
);
3154 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
3159 static HRESULT WINAPI
d3d9_device_CreateOffscreenPlainSurfaceEx(IDirect3DDevice9Ex
*iface
,
3160 UINT width
, UINT height
, D3DFORMAT format
, D3DPOOL pool
, IDirect3DSurface9
**surface
,
3161 HANDLE
*shared_handle
, DWORD usage
)
3163 FIXME("iface %p, width %u, height %u, format %#x, pool %#x, surface %p, shared_handle %p, usage %#x stub!\n",
3164 iface
, width
, height
, format
, pool
, surface
, shared_handle
, usage
);
3169 static HRESULT WINAPI
d3d9_device_CreateDepthStencilSurfaceEx(IDirect3DDevice9Ex
*iface
,
3170 UINT width
, UINT height
, D3DFORMAT format
, D3DMULTISAMPLE_TYPE multisample_type
, DWORD multisample_quality
,
3171 BOOL discard
, IDirect3DSurface9
**surface
, HANDLE
*shared_handle
, DWORD usage
)
3173 FIXME("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u,\n"
3174 "discard %#x, surface %p, shared_handle %p, usage %#x stub!\n",
3175 iface
, width
, height
, format
, multisample_type
, multisample_quality
,
3176 discard
, surface
, shared_handle
, usage
);
3180 FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle
);
3185 static HRESULT WINAPI DECLSPEC_HOTPATCH
d3d9_device_ResetEx(IDirect3DDevice9Ex
*iface
,
3186 D3DPRESENT_PARAMETERS
*present_parameters
, D3DDISPLAYMODEEX
*mode
)
3188 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3189 struct wined3d_swapchain_desc swapchain_desc
;
3190 struct wined3d_display_mode wined3d_mode
;
3193 TRACE("iface %p, present_parameters %p, mode %p.\n", iface
, present_parameters
, mode
);
3197 wined3d_mode
.width
= mode
->Width
;
3198 wined3d_mode
.height
= mode
->Height
;
3199 wined3d_mode
.refresh_rate
= mode
->RefreshRate
;
3200 wined3d_mode
.format_id
= wined3dformat_from_d3dformat(mode
->Format
);
3201 wined3d_mode
.scanline_ordering
= mode
->ScanLineOrdering
;
3204 wined3d_mutex_lock();
3206 if (device
->vertex_buffer
)
3208 wined3d_buffer_decref(device
->vertex_buffer
);
3209 device
->vertex_buffer
= NULL
;
3210 device
->vertex_buffer_size
= 0;
3212 if (device
->index_buffer
)
3214 wined3d_buffer_decref(device
->index_buffer
);
3215 device
->index_buffer
= NULL
;
3216 device
->index_buffer_size
= 0;
3219 wined3d_swapchain_desc_from_present_parameters(&swapchain_desc
, present_parameters
);
3220 hr
= wined3d_device_reset(device
->wined3d_device
, &swapchain_desc
,
3221 mode
? &wined3d_mode
: NULL
, reset_enum_callback
, FALSE
);
3222 wined3d_mutex_unlock();
3227 static HRESULT WINAPI
d3d9_device_GetDisplayModeEx(IDirect3DDevice9Ex
*iface
,
3228 UINT swapchain_idx
, D3DDISPLAYMODEEX
*mode
, D3DDISPLAYROTATION
*rotation
)
3230 struct d3d9_device
*device
= impl_from_IDirect3DDevice9Ex(iface
);
3231 struct wined3d_display_mode wined3d_mode
;
3234 TRACE("iface %p, swapchain_idx %u, mode %p, rotation %p.\n",
3235 iface
, swapchain_idx
, mode
, rotation
);
3237 if (mode
->Size
!= sizeof(*mode
))
3238 return D3DERR_INVALIDCALL
;
3240 wined3d_mutex_lock();
3241 hr
= wined3d_device_get_display_mode(device
->wined3d_device
, swapchain_idx
, &wined3d_mode
,
3242 (enum wined3d_display_rotation
*)rotation
);
3243 wined3d_mutex_unlock();
3247 mode
->Width
= wined3d_mode
.width
;
3248 mode
->Height
= wined3d_mode
.height
;
3249 mode
->RefreshRate
= wined3d_mode
.refresh_rate
;
3250 mode
->Format
= d3dformat_from_wined3dformat(wined3d_mode
.format_id
);
3251 mode
->ScanLineOrdering
= wined3d_mode
.scanline_ordering
;
3257 static const struct IDirect3DDevice9ExVtbl d3d9_device_vtbl
=
3260 d3d9_device_QueryInterface
,
3262 d3d9_device_Release
,
3263 /* IDirect3DDevice9 */
3264 d3d9_device_TestCooperativeLevel
,
3265 d3d9_device_GetAvailableTextureMem
,
3266 d3d9_device_EvictManagedResources
,
3267 d3d9_device_GetDirect3D
,
3268 d3d9_device_GetDeviceCaps
,
3269 d3d9_device_GetDisplayMode
,
3270 d3d9_device_GetCreationParameters
,
3271 d3d9_device_SetCursorProperties
,
3272 d3d9_device_SetCursorPosition
,
3273 d3d9_device_ShowCursor
,
3274 d3d9_device_CreateAdditionalSwapChain
,
3275 d3d9_device_GetSwapChain
,
3276 d3d9_device_GetNumberOfSwapChains
,
3278 d3d9_device_Present
,
3279 d3d9_device_GetBackBuffer
,
3280 d3d9_device_GetRasterStatus
,
3281 d3d9_device_SetDialogBoxMode
,
3282 d3d9_device_SetGammaRamp
,
3283 d3d9_device_GetGammaRamp
,
3284 d3d9_device_CreateTexture
,
3285 d3d9_device_CreateVolumeTexture
,
3286 d3d9_device_CreateCubeTexture
,
3287 d3d9_device_CreateVertexBuffer
,
3288 d3d9_device_CreateIndexBuffer
,
3289 d3d9_device_CreateRenderTarget
,
3290 d3d9_device_CreateDepthStencilSurface
,
3291 d3d9_device_UpdateSurface
,
3292 d3d9_device_UpdateTexture
,
3293 d3d9_device_GetRenderTargetData
,
3294 d3d9_device_GetFrontBufferData
,
3295 d3d9_device_StretchRect
,
3296 d3d9_device_ColorFill
,
3297 d3d9_device_CreateOffscreenPlainSurface
,
3298 d3d9_device_SetRenderTarget
,
3299 d3d9_device_GetRenderTarget
,
3300 d3d9_device_SetDepthStencilSurface
,
3301 d3d9_device_GetDepthStencilSurface
,
3302 d3d9_device_BeginScene
,
3303 d3d9_device_EndScene
,
3305 d3d9_device_SetTransform
,
3306 d3d9_device_GetTransform
,
3307 d3d9_device_MultiplyTransform
,
3308 d3d9_device_SetViewport
,
3309 d3d9_device_GetViewport
,
3310 d3d9_device_SetMaterial
,
3311 d3d9_device_GetMaterial
,
3312 d3d9_device_SetLight
,
3313 d3d9_device_GetLight
,
3314 d3d9_device_LightEnable
,
3315 d3d9_device_GetLightEnable
,
3316 d3d9_device_SetClipPlane
,
3317 d3d9_device_GetClipPlane
,
3318 d3d9_device_SetRenderState
,
3319 d3d9_device_GetRenderState
,
3320 d3d9_device_CreateStateBlock
,
3321 d3d9_device_BeginStateBlock
,
3322 d3d9_device_EndStateBlock
,
3323 d3d9_device_SetClipStatus
,
3324 d3d9_device_GetClipStatus
,
3325 d3d9_device_GetTexture
,
3326 d3d9_device_SetTexture
,
3327 d3d9_device_GetTextureStageState
,
3328 d3d9_device_SetTextureStageState
,
3329 d3d9_device_GetSamplerState
,
3330 d3d9_device_SetSamplerState
,
3331 d3d9_device_ValidateDevice
,
3332 d3d9_device_SetPaletteEntries
,
3333 d3d9_device_GetPaletteEntries
,
3334 d3d9_device_SetCurrentTexturePalette
,
3335 d3d9_device_GetCurrentTexturePalette
,
3336 d3d9_device_SetScissorRect
,
3337 d3d9_device_GetScissorRect
,
3338 d3d9_device_SetSoftwareVertexProcessing
,
3339 d3d9_device_GetSoftwareVertexProcessing
,
3340 d3d9_device_SetNPatchMode
,
3341 d3d9_device_GetNPatchMode
,
3342 d3d9_device_DrawPrimitive
,
3343 d3d9_device_DrawIndexedPrimitive
,
3344 d3d9_device_DrawPrimitiveUP
,
3345 d3d9_device_DrawIndexedPrimitiveUP
,
3346 d3d9_device_ProcessVertices
,
3347 d3d9_device_CreateVertexDeclaration
,
3348 d3d9_device_SetVertexDeclaration
,
3349 d3d9_device_GetVertexDeclaration
,
3352 d3d9_device_CreateVertexShader
,
3353 d3d9_device_SetVertexShader
,
3354 d3d9_device_GetVertexShader
,
3355 d3d9_device_SetVertexShaderConstantF
,
3356 d3d9_device_GetVertexShaderConstantF
,
3357 d3d9_device_SetVertexShaderConstantI
,
3358 d3d9_device_GetVertexShaderConstantI
,
3359 d3d9_device_SetVertexShaderConstantB
,
3360 d3d9_device_GetVertexShaderConstantB
,
3361 d3d9_device_SetStreamSource
,
3362 d3d9_device_GetStreamSource
,
3363 d3d9_device_SetStreamSourceFreq
,
3364 d3d9_device_GetStreamSourceFreq
,
3365 d3d9_device_SetIndices
,
3366 d3d9_device_GetIndices
,
3367 d3d9_device_CreatePixelShader
,
3368 d3d9_device_SetPixelShader
,
3369 d3d9_device_GetPixelShader
,
3370 d3d9_device_SetPixelShaderConstantF
,
3371 d3d9_device_GetPixelShaderConstantF
,
3372 d3d9_device_SetPixelShaderConstantI
,
3373 d3d9_device_GetPixelShaderConstantI
,
3374 d3d9_device_SetPixelShaderConstantB
,
3375 d3d9_device_GetPixelShaderConstantB
,
3376 d3d9_device_DrawRectPatch
,
3377 d3d9_device_DrawTriPatch
,
3378 d3d9_device_DeletePatch
,
3379 d3d9_device_CreateQuery
,
3380 /* IDirect3DDevice9Ex */
3381 d3d9_device_SetConvolutionMonoKernel
,
3382 d3d9_device_ComposeRects
,
3383 d3d9_device_PresentEx
,
3384 d3d9_device_GetGPUThreadPriority
,
3385 d3d9_device_SetGPUThreadPriority
,
3386 d3d9_device_WaitForVBlank
,
3387 d3d9_device_CheckResourceResidency
,
3388 d3d9_device_SetMaximumFrameLatency
,
3389 d3d9_device_GetMaximumFrameLatency
,
3390 d3d9_device_CheckDeviceState
,
3391 d3d9_device_CreateRenderTargetEx
,
3392 d3d9_device_CreateOffscreenPlainSurfaceEx
,
3393 d3d9_device_CreateDepthStencilSurfaceEx
,
3394 d3d9_device_ResetEx
,
3395 d3d9_device_GetDisplayModeEx
,
3398 static inline struct d3d9_device
*device_from_device_parent(struct wined3d_device_parent
*device_parent
)
3400 return CONTAINING_RECORD(device_parent
, struct d3d9_device
, device_parent
);
3403 static void CDECL
device_parent_wined3d_device_created(struct wined3d_device_parent
*device_parent
,
3404 struct wined3d_device
*device
)
3406 TRACE("device_parent %p, device %p.\n", device_parent
, device
);
3409 static void CDECL
device_parent_mode_changed(struct wined3d_device_parent
*device_parent
)
3411 TRACE("device_parent %p.\n", device_parent
);
3414 static HRESULT CDECL
device_parent_surface_created(struct wined3d_device_parent
*device_parent
,
3415 void *container_parent
, struct wined3d_surface
*surface
, void **parent
,
3416 const struct wined3d_parent_ops
**parent_ops
)
3418 struct d3d9_device
*device
= device_from_device_parent(device_parent
);
3419 struct d3d9_surface
*d3d_surface
;
3421 TRACE("device_parent %p, container_parent %p, surface %p, parent %p, parent_ops %p.\n",
3422 device_parent
, container_parent
, surface
, parent
, parent_ops
);
3424 if (!(d3d_surface
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*d3d_surface
))))
3426 FIXME("Failed to allocate surface memory.\n");
3427 return D3DERR_OUTOFVIDEOMEMORY
;
3430 surface_init(d3d_surface
, surface
, device
, parent_ops
);
3431 *parent
= d3d_surface
;
3432 TRACE("Created surface %p.\n", d3d_surface
);
3434 d3d_surface
->container
= container_parent
;
3435 IDirect3DDevice9Ex_Release(d3d_surface
->parent_device
);
3436 d3d_surface
->parent_device
= NULL
;
3438 IDirect3DSurface9_Release(&d3d_surface
->IDirect3DSurface9_iface
);
3439 d3d_surface
->forwardReference
= container_parent
;
3444 static HRESULT CDECL
device_parent_volume_created(struct wined3d_device_parent
*device_parent
,
3445 void *container_parent
, struct wined3d_volume
*volume
, void **parent
,
3446 const struct wined3d_parent_ops
**parent_ops
)
3448 struct d3d9_volume
*d3d_volume
;
3450 TRACE("device_parent %p, container_parent %p, volume %p, parent %p, parent_ops %p.\n",
3451 device_parent
, container_parent
, volume
, parent
, parent_ops
);
3453 if (!(d3d_volume
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(*d3d_volume
))))
3454 return E_OUTOFMEMORY
;
3456 volume_init(d3d_volume
, volume
, parent_ops
);
3457 *parent
= d3d_volume
;
3458 TRACE("Created volume %p.\n", d3d_volume
);
3460 d3d_volume
->container
= container_parent
;
3462 IDirect3DVolume9_Release(&d3d_volume
->IDirect3DVolume9_iface
);
3463 d3d_volume
->forwardReference
= container_parent
;
3468 static HRESULT CDECL
device_parent_create_swapchain_surface(struct wined3d_device_parent
*device_parent
,
3469 void *container_parent
, const struct wined3d_resource_desc
*desc
, struct wined3d_surface
**surface
)
3471 struct d3d9_device
*device
= device_from_device_parent(device_parent
);
3472 struct wined3d_resource_desc texture_desc
;
3473 struct d3d9_surface
*d3d_surface
;
3474 struct wined3d_texture
*texture
;
3477 TRACE("device_parent %p, container_parent %p, desc %p, surface %p.\n",
3478 device_parent
, container_parent
, desc
, surface
);
3480 if (container_parent
== device_parent
)
3481 container_parent
= &device
->IDirect3DDevice9Ex_iface
;
3483 texture_desc
= *desc
;
3484 texture_desc
.resource_type
= WINED3D_RTYPE_TEXTURE
;
3485 if (FAILED(hr
= wined3d_texture_create(device
->wined3d_device
, &texture_desc
, 1,
3486 WINED3D_SURFACE_MAPPABLE
, container_parent
, &d3d9_null_wined3d_parent_ops
, &texture
)))
3488 WARN("Failed to create texture, hr %#x.\n", hr
);
3492 *surface
= wined3d_surface_from_resource(wined3d_texture_get_sub_resource(texture
, 0));
3493 wined3d_surface_incref(*surface
);
3494 wined3d_texture_decref(texture
);
3496 d3d_surface
= wined3d_surface_get_parent(*surface
);
3497 d3d_surface
->forwardReference
= NULL
;
3498 d3d_surface
->parent_device
= &device
->IDirect3DDevice9Ex_iface
;
3503 static HRESULT CDECL
device_parent_create_swapchain(struct wined3d_device_parent
*device_parent
,
3504 struct wined3d_swapchain_desc
*desc
, struct wined3d_swapchain
**swapchain
)
3506 struct d3d9_device
*device
= device_from_device_parent(device_parent
);
3507 struct d3d9_swapchain
*d3d_swapchain
;
3510 TRACE("device_parent %p, desc %p, swapchain %p\n", device_parent
, desc
, swapchain
);
3512 hr
= d3d9_swapchain_create(device
, desc
, &d3d_swapchain
);
3515 WARN("Failed to create swapchain, hr %#x.\n", hr
);
3520 *swapchain
= d3d_swapchain
->wined3d_swapchain
;
3521 wined3d_swapchain_incref(*swapchain
);
3522 IDirect3DSwapChain9Ex_Release(&d3d_swapchain
->IDirect3DSwapChain9Ex_iface
);
3527 static const struct wined3d_device_parent_ops d3d9_wined3d_device_parent_ops
=
3529 device_parent_wined3d_device_created
,
3530 device_parent_mode_changed
,
3531 device_parent_surface_created
,
3532 device_parent_volume_created
,
3533 device_parent_create_swapchain_surface
,
3534 device_parent_create_swapchain
,
3537 static void setup_fpu(void)
3539 #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
3541 __asm__
volatile ("fnstcw %0" : "=m" (cw
));
3542 cw
= (cw
& ~0xf3f) | 0x3f;
3543 __asm__
volatile ("fldcw %0" : : "m" (cw
));
3544 #elif defined(__i386__) && defined(_MSC_VER)
3547 cw
= (cw
& ~0xf3f) | 0x3f;
3550 FIXME("FPU setup not implemented for this platform.\n");
3554 HRESULT
device_init(struct d3d9_device
*device
, struct d3d9
*parent
, struct wined3d
*wined3d
,
3555 UINT adapter
, D3DDEVTYPE device_type
, HWND focus_window
, DWORD flags
,
3556 D3DPRESENT_PARAMETERS
*parameters
, D3DDISPLAYMODEEX
*mode
)
3558 struct wined3d_swapchain_desc
*swapchain_desc
;
3563 FIXME("Ignoring display mode.\n");
3565 device
->IDirect3DDevice9Ex_iface
.lpVtbl
= &d3d9_device_vtbl
;
3566 device
->device_parent
.ops
= &d3d9_wined3d_device_parent_ops
;
3567 device
->refcount
= 1;
3569 if (!(flags
& D3DCREATE_FPU_PRESERVE
)) setup_fpu();
3571 wined3d_mutex_lock();
3572 hr
= wined3d_device_create(wined3d
, adapter
, device_type
, focus_window
, flags
, 4,
3573 &device
->device_parent
, &device
->wined3d_device
);
3576 WARN("Failed to create wined3d device, hr %#x.\n", hr
);
3577 wined3d_mutex_unlock();
3581 if (flags
& D3DCREATE_ADAPTERGROUP_DEVICE
)
3585 wined3d_get_device_caps(wined3d
, adapter
, device_type
, &caps
);
3586 count
= caps
.NumberOfAdaptersInGroup
;
3589 if (flags
& D3DCREATE_MULTITHREADED
)
3590 wined3d_device_set_multithreaded(device
->wined3d_device
);
3592 if (!parameters
->Windowed
)
3595 focus_window
= parameters
->hDeviceWindow
;
3596 if (FAILED(hr
= wined3d_device_acquire_focus_window(device
->wined3d_device
, focus_window
)))
3598 ERR("Failed to acquire focus window, hr %#x.\n", hr
);
3599 wined3d_device_decref(device
->wined3d_device
);
3600 wined3d_mutex_unlock();
3604 for (i
= 0; i
< count
; ++i
)
3606 HWND device_window
= parameters
[i
].hDeviceWindow
;
3608 if (!device_window
) device_window
= focus_window
;
3609 wined3d_device_setup_fullscreen_window(device
->wined3d_device
, device_window
,
3610 parameters
[i
].BackBufferWidth
,
3611 parameters
[i
].BackBufferHeight
);
3615 swapchain_desc
= HeapAlloc(GetProcessHeap(), 0, sizeof(*swapchain_desc
) * count
);
3616 if (!swapchain_desc
)
3618 ERR("Failed to allocate wined3d parameters.\n");
3619 wined3d_device_decref(device
->wined3d_device
);
3620 wined3d_mutex_unlock();
3621 return E_OUTOFMEMORY
;
3624 for (i
= 0; i
< count
; ++i
)
3626 wined3d_swapchain_desc_from_present_parameters(&swapchain_desc
[i
], ¶meters
[i
]);
3629 hr
= wined3d_device_init_3d(device
->wined3d_device
, swapchain_desc
);
3632 WARN("Failed to initialize 3D, hr %#x.\n", hr
);
3633 wined3d_device_release_focus_window(device
->wined3d_device
);
3634 HeapFree(GetProcessHeap(), 0, swapchain_desc
);
3635 wined3d_device_decref(device
->wined3d_device
);
3636 wined3d_mutex_unlock();
3640 wined3d_mutex_unlock();
3642 for (i
= 0; i
< count
; ++i
)
3644 present_parameters_from_wined3d_swapchain_desc(¶meters
[i
], &swapchain_desc
[i
]);
3646 HeapFree(GetProcessHeap(), 0, swapchain_desc
);
3648 /* Initialize the converted declaration array. This creates a valid pointer
3649 * and when adding decls HeapReAlloc() can be used without further checking. */
3650 device
->fvf_decls
= HeapAlloc(GetProcessHeap(), 0, 0);
3651 if (!device
->fvf_decls
)
3653 ERR("Failed to allocate FVF vertex declaration map memory.\n");
3654 wined3d_mutex_lock();
3655 wined3d_device_uninit_3d(device
->wined3d_device
);
3656 wined3d_device_release_focus_window(device
->wined3d_device
);
3657 wined3d_device_decref(device
->wined3d_device
);
3658 wined3d_mutex_unlock();
3659 return E_OUTOFMEMORY
;
3662 IDirect3D9Ex_AddRef(&parent
->IDirect3D9Ex_iface
);
3663 device
->d3d_parent
= parent
;