1 | /*
|
---|
2 | * IDirect3DDevice9 implementation
|
---|
3 | *
|
---|
4 | * Copyright 2002-2005 Jason Edmeades
|
---|
5 | * Copyright 2002-2005 Raphael Junqueira
|
---|
6 | * Copyright 2005 Oliver Stieber
|
---|
7 | *
|
---|
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.
|
---|
12 | *
|
---|
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.
|
---|
17 | *
|
---|
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
|
---|
21 | */
|
---|
22 |
|
---|
23 | #include "config.h"
|
---|
24 | #include "d3d9_private.h"
|
---|
25 |
|
---|
26 | #ifdef VBOX_WITH_WDDM
|
---|
27 | # include <iprt/assert.h>
|
---|
28 | # include "../../common/VBoxVideoTools.h"
|
---|
29 | #endif
|
---|
30 |
|
---|
31 | WINE_DEFAULT_DEBUG_CHANNEL(d3d9);
|
---|
32 |
|
---|
33 | D3DFORMAT d3dformat_from_wined3dformat(enum wined3d_format_id format)
|
---|
34 | {
|
---|
35 | BYTE *c = (BYTE *)&format;
|
---|
36 |
|
---|
37 | /* Don't translate FOURCC formats */
|
---|
38 | if (isprint(c[0]) && isprint(c[1]) && isprint(c[2]) && isprint(c[3])) return format;
|
---|
39 |
|
---|
40 | switch(format)
|
---|
41 | {
|
---|
42 | case WINED3DFMT_UNKNOWN: return D3DFMT_UNKNOWN;
|
---|
43 | case WINED3DFMT_B8G8R8_UNORM: return D3DFMT_R8G8B8;
|
---|
44 | case WINED3DFMT_B8G8R8A8_UNORM: return D3DFMT_A8R8G8B8;
|
---|
45 | case WINED3DFMT_B8G8R8X8_UNORM: return D3DFMT_X8R8G8B8;
|
---|
46 | case WINED3DFMT_B5G6R5_UNORM: return D3DFMT_R5G6B5;
|
---|
47 | case WINED3DFMT_B5G5R5X1_UNORM: return D3DFMT_X1R5G5B5;
|
---|
48 | case WINED3DFMT_B5G5R5A1_UNORM: return D3DFMT_A1R5G5B5;
|
---|
49 | case WINED3DFMT_B4G4R4A4_UNORM: return D3DFMT_A4R4G4B4;
|
---|
50 | case WINED3DFMT_B2G3R3_UNORM: return D3DFMT_R3G3B2;
|
---|
51 | case WINED3DFMT_A8_UNORM: return D3DFMT_A8;
|
---|
52 | case WINED3DFMT_B2G3R3A8_UNORM: return D3DFMT_A8R3G3B2;
|
---|
53 | case WINED3DFMT_B4G4R4X4_UNORM: return D3DFMT_X4R4G4B4;
|
---|
54 | case WINED3DFMT_R10G10B10A2_UNORM: return D3DFMT_A2B10G10R10;
|
---|
55 | case WINED3DFMT_R8G8B8A8_UNORM: return D3DFMT_A8B8G8R8;
|
---|
56 | case WINED3DFMT_R8G8B8X8_UNORM: return D3DFMT_X8B8G8R8;
|
---|
57 | case WINED3DFMT_R16G16_UNORM: return D3DFMT_G16R16;
|
---|
58 | case WINED3DFMT_B10G10R10A2_UNORM: return D3DFMT_A2R10G10B10;
|
---|
59 | case WINED3DFMT_R16G16B16A16_UNORM: return D3DFMT_A16B16G16R16;
|
---|
60 | case WINED3DFMT_P8_UINT_A8_UNORM: return D3DFMT_A8P8;
|
---|
61 | case WINED3DFMT_P8_UINT: return D3DFMT_P8;
|
---|
62 | case WINED3DFMT_L8_UNORM: return D3DFMT_L8;
|
---|
63 | case WINED3DFMT_L8A8_UNORM: return D3DFMT_A8L8;
|
---|
64 | case WINED3DFMT_L4A4_UNORM: return D3DFMT_A4L4;
|
---|
65 | case WINED3DFMT_R8G8_SNORM: return D3DFMT_V8U8;
|
---|
66 | case WINED3DFMT_R5G5_SNORM_L6_UNORM: return D3DFMT_L6V5U5;
|
---|
67 | case WINED3DFMT_R8G8_SNORM_L8X8_UNORM: return D3DFMT_X8L8V8U8;
|
---|
68 | case WINED3DFMT_R8G8B8A8_SNORM: return D3DFMT_Q8W8V8U8;
|
---|
69 | case WINED3DFMT_R16G16_SNORM: return D3DFMT_V16U16;
|
---|
70 | case WINED3DFMT_R10G10B10_SNORM_A2_UNORM: return D3DFMT_A2W10V10U10;
|
---|
71 | case WINED3DFMT_D16_LOCKABLE: return D3DFMT_D16_LOCKABLE;
|
---|
72 | case WINED3DFMT_D32_UNORM: return D3DFMT_D32;
|
---|
73 | case WINED3DFMT_S1_UINT_D15_UNORM: return D3DFMT_D15S1;
|
---|
74 | case WINED3DFMT_D24_UNORM_S8_UINT: return D3DFMT_D24S8;
|
---|
75 | case WINED3DFMT_X8D24_UNORM: return D3DFMT_D24X8;
|
---|
76 | case WINED3DFMT_S4X4_UINT_D24_UNORM: return D3DFMT_D24X4S4;
|
---|
77 | case WINED3DFMT_D16_UNORM: return D3DFMT_D16;
|
---|
78 | case WINED3DFMT_L16_UNORM: return D3DFMT_L16;
|
---|
79 | case WINED3DFMT_D32_FLOAT: return D3DFMT_D32F_LOCKABLE;
|
---|
80 | case WINED3DFMT_S8_UINT_D24_FLOAT: return D3DFMT_D24FS8;
|
---|
81 | case WINED3DFMT_VERTEXDATA: return D3DFMT_VERTEXDATA;
|
---|
82 | case WINED3DFMT_R16_UINT: return D3DFMT_INDEX16;
|
---|
83 | case WINED3DFMT_R32_UINT: return D3DFMT_INDEX32;
|
---|
84 | case WINED3DFMT_R16G16B16A16_SNORM: return D3DFMT_Q16W16V16U16;
|
---|
85 | case WINED3DFMT_R16_FLOAT: return D3DFMT_R16F;
|
---|
86 | case WINED3DFMT_R16G16_FLOAT: return D3DFMT_G16R16F;
|
---|
87 | case WINED3DFMT_R16G16B16A16_FLOAT: return D3DFMT_A16B16G16R16F;
|
---|
88 | case WINED3DFMT_R32_FLOAT: return D3DFMT_R32F;
|
---|
89 | case WINED3DFMT_R32G32_FLOAT: return D3DFMT_G32R32F;
|
---|
90 | case WINED3DFMT_R32G32B32A32_FLOAT: return D3DFMT_A32B32G32R32F;
|
---|
91 | case WINED3DFMT_R8G8_SNORM_Cx: return D3DFMT_CxV8U8;
|
---|
92 | default:
|
---|
93 | FIXME("Unhandled wined3d format %#x.\n", format);
|
---|
94 | return D3DFMT_UNKNOWN;
|
---|
95 | }
|
---|
96 | }
|
---|
97 |
|
---|
98 | enum wined3d_format_id wined3dformat_from_d3dformat(D3DFORMAT format)
|
---|
99 | {
|
---|
100 | BYTE *c = (BYTE *)&format;
|
---|
101 |
|
---|
102 | /* Don't translate FOURCC formats */
|
---|
103 | if (isprint(c[0]) && isprint(c[1]) && isprint(c[2]) && isprint(c[3])) return format;
|
---|
104 |
|
---|
105 | switch(format)
|
---|
106 | {
|
---|
107 | case D3DFMT_UNKNOWN: return WINED3DFMT_UNKNOWN;
|
---|
108 | case D3DFMT_R8G8B8: return WINED3DFMT_B8G8R8_UNORM;
|
---|
109 | case D3DFMT_A8R8G8B8: return WINED3DFMT_B8G8R8A8_UNORM;
|
---|
110 | case D3DFMT_X8R8G8B8: return WINED3DFMT_B8G8R8X8_UNORM;
|
---|
111 | case D3DFMT_R5G6B5: return WINED3DFMT_B5G6R5_UNORM;
|
---|
112 | case D3DFMT_X1R5G5B5: return WINED3DFMT_B5G5R5X1_UNORM;
|
---|
113 | case D3DFMT_A1R5G5B5: return WINED3DFMT_B5G5R5A1_UNORM;
|
---|
114 | case D3DFMT_A4R4G4B4: return WINED3DFMT_B4G4R4A4_UNORM;
|
---|
115 | case D3DFMT_R3G3B2: return WINED3DFMT_B2G3R3_UNORM;
|
---|
116 | case D3DFMT_A8: return WINED3DFMT_A8_UNORM;
|
---|
117 | case D3DFMT_A8R3G3B2: return WINED3DFMT_B2G3R3A8_UNORM;
|
---|
118 | case D3DFMT_X4R4G4B4: return WINED3DFMT_B4G4R4X4_UNORM;
|
---|
119 | case D3DFMT_A2B10G10R10: return WINED3DFMT_R10G10B10A2_UNORM;
|
---|
120 | case D3DFMT_A8B8G8R8: return WINED3DFMT_R8G8B8A8_UNORM;
|
---|
121 | case D3DFMT_X8B8G8R8: return WINED3DFMT_R8G8B8X8_UNORM;
|
---|
122 | case D3DFMT_G16R16: return WINED3DFMT_R16G16_UNORM;
|
---|
123 | case D3DFMT_A2R10G10B10: return WINED3DFMT_B10G10R10A2_UNORM;
|
---|
124 | case D3DFMT_A16B16G16R16: return WINED3DFMT_R16G16B16A16_UNORM;
|
---|
125 | case D3DFMT_A8P8: return WINED3DFMT_P8_UINT_A8_UNORM;
|
---|
126 | case D3DFMT_P8: return WINED3DFMT_P8_UINT;
|
---|
127 | case D3DFMT_L8: return WINED3DFMT_L8_UNORM;
|
---|
128 | case D3DFMT_A8L8: return WINED3DFMT_L8A8_UNORM;
|
---|
129 | case D3DFMT_A4L4: return WINED3DFMT_L4A4_UNORM;
|
---|
130 | case D3DFMT_V8U8: return WINED3DFMT_R8G8_SNORM;
|
---|
131 | case D3DFMT_L6V5U5: return WINED3DFMT_R5G5_SNORM_L6_UNORM;
|
---|
132 | case D3DFMT_X8L8V8U8: return WINED3DFMT_R8G8_SNORM_L8X8_UNORM;
|
---|
133 | case D3DFMT_Q8W8V8U8: return WINED3DFMT_R8G8B8A8_SNORM;
|
---|
134 | case D3DFMT_V16U16: return WINED3DFMT_R16G16_SNORM;
|
---|
135 | case D3DFMT_A2W10V10U10: return WINED3DFMT_R10G10B10_SNORM_A2_UNORM;
|
---|
136 | case D3DFMT_D16_LOCKABLE: return WINED3DFMT_D16_LOCKABLE;
|
---|
137 | case D3DFMT_D32: return WINED3DFMT_D32_UNORM;
|
---|
138 | case D3DFMT_D15S1: return WINED3DFMT_S1_UINT_D15_UNORM;
|
---|
139 | case D3DFMT_D24S8: return WINED3DFMT_D24_UNORM_S8_UINT;
|
---|
140 | case D3DFMT_D24X8: return WINED3DFMT_X8D24_UNORM;
|
---|
141 | case D3DFMT_D24X4S4: return WINED3DFMT_S4X4_UINT_D24_UNORM;
|
---|
142 | case D3DFMT_D16: return WINED3DFMT_D16_UNORM;
|
---|
143 | case D3DFMT_L16: return WINED3DFMT_L16_UNORM;
|
---|
144 | case D3DFMT_D32F_LOCKABLE: return WINED3DFMT_D32_FLOAT;
|
---|
145 | case D3DFMT_D24FS8: return WINED3DFMT_S8_UINT_D24_FLOAT;
|
---|
146 | case D3DFMT_VERTEXDATA: return WINED3DFMT_VERTEXDATA;
|
---|
147 | case D3DFMT_INDEX16: return WINED3DFMT_R16_UINT;
|
---|
148 | case D3DFMT_INDEX32: return WINED3DFMT_R32_UINT;
|
---|
149 | case D3DFMT_Q16W16V16U16: return WINED3DFMT_R16G16B16A16_SNORM;
|
---|
150 | case D3DFMT_R16F: return WINED3DFMT_R16_FLOAT;
|
---|
151 | case D3DFMT_G16R16F: return WINED3DFMT_R16G16_FLOAT;
|
---|
152 | case D3DFMT_A16B16G16R16F: return WINED3DFMT_R16G16B16A16_FLOAT;
|
---|
153 | case D3DFMT_R32F: return WINED3DFMT_R32_FLOAT;
|
---|
154 | case D3DFMT_G32R32F: return WINED3DFMT_R32G32_FLOAT;
|
---|
155 | case D3DFMT_A32B32G32R32F: return WINED3DFMT_R32G32B32A32_FLOAT;
|
---|
156 | case D3DFMT_CxV8U8: return WINED3DFMT_R8G8_SNORM_Cx;
|
---|
157 | default:
|
---|
158 | FIXME("Unhandled D3DFORMAT %#x\n", format);
|
---|
159 | return WINED3DFMT_UNKNOWN;
|
---|
160 | }
|
---|
161 | }
|
---|
162 |
|
---|
163 | static UINT vertex_count_from_primitive_count(D3DPRIMITIVETYPE primitive_type, UINT primitive_count)
|
---|
164 | {
|
---|
165 | switch(primitive_type)
|
---|
166 | {
|
---|
167 | case D3DPT_POINTLIST:
|
---|
168 | return primitive_count;
|
---|
169 |
|
---|
170 | case D3DPT_LINELIST:
|
---|
171 | return primitive_count * 2;
|
---|
172 |
|
---|
173 | case D3DPT_LINESTRIP:
|
---|
174 | return primitive_count + 1;
|
---|
175 |
|
---|
176 | case D3DPT_TRIANGLELIST:
|
---|
177 | return primitive_count * 3;
|
---|
178 |
|
---|
179 | case D3DPT_TRIANGLESTRIP:
|
---|
180 | case D3DPT_TRIANGLEFAN:
|
---|
181 | return primitive_count + 2;
|
---|
182 |
|
---|
183 | default:
|
---|
184 | FIXME("Unhandled primitive type %#x\n", primitive_type);
|
---|
185 | return 0;
|
---|
186 | }
|
---|
187 | }
|
---|
188 |
|
---|
189 | void present_parameters_from_wined3d_swapchain_desc(D3DPRESENT_PARAMETERS *present_parameters,
|
---|
190 | const struct wined3d_swapchain_desc *swapchain_desc)
|
---|
191 | {
|
---|
192 | present_parameters->BackBufferWidth = swapchain_desc->backbuffer_width;
|
---|
193 | present_parameters->BackBufferHeight = swapchain_desc->backbuffer_height;
|
---|
194 | present_parameters->BackBufferFormat = d3dformat_from_wined3dformat(swapchain_desc->backbuffer_format);
|
---|
195 | present_parameters->BackBufferCount = swapchain_desc->backbuffer_count;
|
---|
196 | present_parameters->MultiSampleType = swapchain_desc->multisample_type;
|
---|
197 | present_parameters->MultiSampleQuality = swapchain_desc->multisample_quality;
|
---|
198 | present_parameters->SwapEffect = swapchain_desc->swap_effect;
|
---|
199 | present_parameters->hDeviceWindow = swapchain_desc->device_window;
|
---|
200 | present_parameters->Windowed = swapchain_desc->windowed;
|
---|
201 | present_parameters->EnableAutoDepthStencil = swapchain_desc->enable_auto_depth_stencil;
|
---|
202 | present_parameters->AutoDepthStencilFormat
|
---|
203 | = d3dformat_from_wined3dformat(swapchain_desc->auto_depth_stencil_format);
|
---|
204 | present_parameters->Flags = swapchain_desc->flags;
|
---|
205 | present_parameters->FullScreen_RefreshRateInHz = swapchain_desc->refresh_rate;
|
---|
206 | present_parameters->PresentationInterval = swapchain_desc->swap_interval;
|
---|
207 | }
|
---|
208 |
|
---|
209 | static void wined3d_swapchain_desc_from_present_parameters(struct wined3d_swapchain_desc *swapchain_desc,
|
---|
210 | const D3DPRESENT_PARAMETERS *present_parameters)
|
---|
211 | {
|
---|
212 | swapchain_desc->backbuffer_width = present_parameters->BackBufferWidth;
|
---|
213 | swapchain_desc->backbuffer_height = present_parameters->BackBufferHeight;
|
---|
214 | swapchain_desc->backbuffer_format = wined3dformat_from_d3dformat(present_parameters->BackBufferFormat);
|
---|
215 | swapchain_desc->backbuffer_count = max(1, present_parameters->BackBufferCount);
|
---|
216 | swapchain_desc->multisample_type = present_parameters->MultiSampleType;
|
---|
217 | swapchain_desc->multisample_quality = present_parameters->MultiSampleQuality;
|
---|
218 | swapchain_desc->swap_effect = present_parameters->SwapEffect;
|
---|
219 | swapchain_desc->device_window = present_parameters->hDeviceWindow;
|
---|
220 | swapchain_desc->windowed = present_parameters->Windowed;
|
---|
221 | swapchain_desc->enable_auto_depth_stencil = present_parameters->EnableAutoDepthStencil;
|
---|
222 | swapchain_desc->auto_depth_stencil_format
|
---|
223 | = wined3dformat_from_d3dformat(present_parameters->AutoDepthStencilFormat);
|
---|
224 | swapchain_desc->flags = present_parameters->Flags;
|
---|
225 | swapchain_desc->refresh_rate = present_parameters->FullScreen_RefreshRateInHz;
|
---|
226 | swapchain_desc->swap_interval = present_parameters->PresentationInterval;
|
---|
227 | swapchain_desc->auto_restore_display_mode = TRUE;
|
---|
228 | #ifdef VBOX_WITH_WDDM
|
---|
229 | swapchain_desc->pHgsmi = NULL;
|
---|
230 | #endif
|
---|
231 |
|
---|
232 | }
|
---|
233 |
|
---|
234 | static inline struct d3d9_device *impl_from_IDirect3DDevice9Ex(IDirect3DDevice9Ex *iface)
|
---|
235 | {
|
---|
236 | return CONTAINING_RECORD(iface, struct d3d9_device, IDirect3DDevice9Ex_iface);
|
---|
237 | }
|
---|
238 |
|
---|
239 | static HRESULT WINAPI d3d9_device_QueryInterface(IDirect3DDevice9Ex *iface, REFIID riid, void **out)
|
---|
240 | {
|
---|
241 | TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
|
---|
242 |
|
---|
243 | if (IsEqualGUID(riid, &IID_IDirect3DDevice9)
|
---|
244 | || IsEqualGUID(riid, &IID_IUnknown))
|
---|
245 | {
|
---|
246 | IDirect3DDevice9Ex_AddRef(iface);
|
---|
247 | *out = iface;
|
---|
248 | return S_OK;
|
---|
249 | }
|
---|
250 |
|
---|
251 | if (IsEqualGUID(riid, &IID_IDirect3DDevice9Ex))
|
---|
252 | {
|
---|
253 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
254 |
|
---|
255 | /* Find out if the creating d3d9 interface was created with Direct3DCreate9Ex.
|
---|
256 | * It doesn't matter with which function the device was created. */
|
---|
257 | if (!device->d3d_parent->extended)
|
---|
258 | {
|
---|
259 | WARN("IDirect3D9 instance wasn't created with CreateDirect3D9Ex, returning E_NOINTERFACE.\n");
|
---|
260 | *out = NULL;
|
---|
261 | return E_NOINTERFACE;
|
---|
262 | }
|
---|
263 |
|
---|
264 | IDirect3DDevice9Ex_AddRef(iface);
|
---|
265 | *out = iface;
|
---|
266 | return S_OK;
|
---|
267 | }
|
---|
268 |
|
---|
269 | WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
|
---|
270 |
|
---|
271 | *out = NULL;
|
---|
272 | return E_NOINTERFACE;
|
---|
273 | }
|
---|
274 |
|
---|
275 | static ULONG WINAPI d3d9_device_AddRef(IDirect3DDevice9Ex *iface)
|
---|
276 | {
|
---|
277 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
278 | ULONG refcount = InterlockedIncrement(&device->refcount);
|
---|
279 |
|
---|
280 | TRACE("%p increasing refcount to %u.\n", iface, refcount);
|
---|
281 |
|
---|
282 | return refcount;
|
---|
283 | }
|
---|
284 |
|
---|
285 | #ifdef VBOX
|
---|
286 | static LONG d3d9_device_Term(struct d3d9_device *device)
|
---|
287 | {
|
---|
288 | unsigned i;
|
---|
289 | LONG refs = device->refcount;
|
---|
290 | LONG wined3d_refs;
|
---|
291 | device->in_destruction = TRUE;
|
---|
292 |
|
---|
293 | if (refs != 1)
|
---|
294 | {
|
---|
295 | WARN("unexpected ref count %d, destroying in anyway", refs);
|
---|
296 | }
|
---|
297 |
|
---|
298 | wined3d_mutex_lock();
|
---|
299 | for (i = 0; i < device->fvf_decl_count; ++i)
|
---|
300 | {
|
---|
301 | wined3d_vertex_declaration_decref(device->fvf_decls[i].decl);
|
---|
302 | }
|
---|
303 | HeapFree(GetProcessHeap(), 0, device->fvf_decls);
|
---|
304 |
|
---|
305 | if (device->vertex_buffer)
|
---|
306 | wined3d_buffer_decref(device->vertex_buffer);
|
---|
307 | if (device->index_buffer)
|
---|
308 | wined3d_buffer_decref(device->index_buffer);
|
---|
309 |
|
---|
310 | wined3d_device_uninit_3d(device->wined3d_device);
|
---|
311 | # ifndef VBOX_WITH_WDDM
|
---|
312 | wined3d_device_release_focus_window(device->wined3d_device);
|
---|
313 | # endif
|
---|
314 | wined3d_refs = wined3d_device_decref(device->wined3d_device);
|
---|
315 | wined3d_mutex_unlock();
|
---|
316 |
|
---|
317 | IDirect3D9Ex_Release(&device->d3d_parent->IDirect3D9Ex_iface);
|
---|
318 |
|
---|
319 | HeapFree(GetProcessHeap(), 0, device);
|
---|
320 |
|
---|
321 | return wined3d_refs;
|
---|
322 | }
|
---|
323 | #endif
|
---|
324 |
|
---|
325 | static ULONG WINAPI DECLSPEC_HOTPATCH d3d9_device_Release(IDirect3DDevice9Ex *iface)
|
---|
326 | {
|
---|
327 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
328 | ULONG refcount;
|
---|
329 |
|
---|
330 | if (device->in_destruction)
|
---|
331 | return 0;
|
---|
332 |
|
---|
333 | refcount = InterlockedDecrement(&device->refcount);
|
---|
334 |
|
---|
335 | TRACE("%p decreasing refcount to %u.\n", iface, refcount);
|
---|
336 |
|
---|
337 | if (!refcount)
|
---|
338 | {
|
---|
339 | #ifdef VBOX
|
---|
340 | d3d9_device_Term(device);
|
---|
341 | #else
|
---|
342 | unsigned i;
|
---|
343 | device->in_destruction = TRUE;
|
---|
344 |
|
---|
345 | wined3d_mutex_lock();
|
---|
346 | for (i = 0; i < device->fvf_decl_count; ++i)
|
---|
347 | {
|
---|
348 | wined3d_vertex_declaration_decref(device->fvf_decls[i].decl);
|
---|
349 | }
|
---|
350 | HeapFree(GetProcessHeap(), 0, device->fvf_decls);
|
---|
351 |
|
---|
352 | if (device->vertex_buffer)
|
---|
353 | wined3d_buffer_decref(device->vertex_buffer);
|
---|
354 | if (device->index_buffer)
|
---|
355 | wined3d_buffer_decref(device->index_buffer);
|
---|
356 |
|
---|
357 | wined3d_device_uninit_3d(device->wined3d_device);
|
---|
358 | wined3d_device_release_focus_window(device->wined3d_device);
|
---|
359 | wined3d_device_decref(device->wined3d_device);
|
---|
360 | wined3d_mutex_unlock();
|
---|
361 |
|
---|
362 | IDirect3D9Ex_Release(&device->d3d_parent->IDirect3D9Ex_iface);
|
---|
363 |
|
---|
364 | HeapFree(GetProcessHeap(), 0, device);
|
---|
365 | #endif
|
---|
366 | }
|
---|
367 |
|
---|
368 | return refcount;
|
---|
369 | }
|
---|
370 |
|
---|
371 | static HRESULT WINAPI d3d9_device_TestCooperativeLevel(IDirect3DDevice9Ex *iface)
|
---|
372 | {
|
---|
373 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
374 |
|
---|
375 | TRACE("iface %p.\n", iface);
|
---|
376 |
|
---|
377 | if (device->not_reset)
|
---|
378 | {
|
---|
379 | TRACE("D3D9 device is marked not reset.\n");
|
---|
380 | return D3DERR_DEVICENOTRESET;
|
---|
381 | }
|
---|
382 |
|
---|
383 | return D3D_OK;
|
---|
384 | }
|
---|
385 |
|
---|
386 | static UINT WINAPI d3d9_device_GetAvailableTextureMem(IDirect3DDevice9Ex *iface)
|
---|
387 | {
|
---|
388 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
389 | HRESULT hr;
|
---|
390 |
|
---|
391 | TRACE("iface %p.\n", iface);
|
---|
392 |
|
---|
393 | wined3d_mutex_lock();
|
---|
394 | hr = wined3d_device_get_available_texture_mem(device->wined3d_device);
|
---|
395 | wined3d_mutex_unlock();
|
---|
396 |
|
---|
397 | return hr;
|
---|
398 | }
|
---|
399 |
|
---|
400 | static HRESULT WINAPI d3d9_device_EvictManagedResources(IDirect3DDevice9Ex *iface)
|
---|
401 | {
|
---|
402 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
403 |
|
---|
404 | TRACE("iface %p.\n", iface);
|
---|
405 |
|
---|
406 | wined3d_mutex_lock();
|
---|
407 | wined3d_device_evict_managed_resources(device->wined3d_device);
|
---|
408 | wined3d_mutex_unlock();
|
---|
409 |
|
---|
410 | return D3D_OK;
|
---|
411 | }
|
---|
412 |
|
---|
413 | static HRESULT WINAPI d3d9_device_GetDirect3D(IDirect3DDevice9Ex *iface, IDirect3D9 **d3d9)
|
---|
414 | {
|
---|
415 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
416 |
|
---|
417 | TRACE("iface %p, d3d9 %p.\n", iface, d3d9);
|
---|
418 |
|
---|
419 | if (!d3d9)
|
---|
420 | return D3DERR_INVALIDCALL;
|
---|
421 |
|
---|
422 | return IDirect3D9Ex_QueryInterface(&device->d3d_parent->IDirect3D9Ex_iface, &IID_IDirect3D9, (void **)d3d9);
|
---|
423 | }
|
---|
424 |
|
---|
425 | static HRESULT WINAPI d3d9_device_GetDeviceCaps(IDirect3DDevice9Ex *iface, D3DCAPS9 *caps)
|
---|
426 | {
|
---|
427 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
428 | WINED3DCAPS *wined3d_caps;
|
---|
429 | HRESULT hr;
|
---|
430 |
|
---|
431 | TRACE("iface %p, caps %p.\n", iface, caps);
|
---|
432 |
|
---|
433 | if (!caps)
|
---|
434 | return D3DERR_INVALIDCALL;
|
---|
435 |
|
---|
436 | if (!(wined3d_caps = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*wined3d_caps))))
|
---|
437 | return D3DERR_INVALIDCALL; /* well this is what MSDN says to return */
|
---|
438 |
|
---|
439 | memset(caps, 0, sizeof(*caps));
|
---|
440 |
|
---|
441 | wined3d_mutex_lock();
|
---|
442 | hr = wined3d_device_get_device_caps(device->wined3d_device, wined3d_caps);
|
---|
443 | wined3d_mutex_unlock();
|
---|
444 |
|
---|
445 | WINECAPSTOD3D9CAPS(caps, wined3d_caps)
|
---|
446 | HeapFree(GetProcessHeap(), 0, wined3d_caps);
|
---|
447 |
|
---|
448 | /* Some functionality is implemented in d3d9.dll, not wined3d.dll. Add the needed caps */
|
---|
449 | caps->DevCaps2 |= D3DDEVCAPS2_CAN_STRETCHRECT_FROM_TEXTURES;
|
---|
450 |
|
---|
451 | filter_caps(caps);
|
---|
452 |
|
---|
453 | return hr;
|
---|
454 | }
|
---|
455 |
|
---|
456 | static HRESULT WINAPI d3d9_device_GetDisplayMode(IDirect3DDevice9Ex *iface, UINT swapchain, D3DDISPLAYMODE *mode)
|
---|
457 | {
|
---|
458 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
459 | struct wined3d_display_mode wined3d_mode;
|
---|
460 | HRESULT hr;
|
---|
461 |
|
---|
462 | TRACE("iface %p, swapchain %u, mode %p.\n", iface, swapchain, mode);
|
---|
463 |
|
---|
464 | wined3d_mutex_lock();
|
---|
465 | hr = wined3d_device_get_display_mode(device->wined3d_device, swapchain, &wined3d_mode, NULL);
|
---|
466 | wined3d_mutex_unlock();
|
---|
467 |
|
---|
468 | if (SUCCEEDED(hr))
|
---|
469 | {
|
---|
470 | mode->Width = wined3d_mode.width;
|
---|
471 | mode->Height = wined3d_mode.height;
|
---|
472 | mode->RefreshRate = wined3d_mode.refresh_rate;
|
---|
473 | mode->Format = d3dformat_from_wined3dformat(wined3d_mode.format_id);
|
---|
474 | }
|
---|
475 |
|
---|
476 | return hr;
|
---|
477 | }
|
---|
478 |
|
---|
479 | static HRESULT WINAPI d3d9_device_GetCreationParameters(IDirect3DDevice9Ex *iface,
|
---|
480 | D3DDEVICE_CREATION_PARAMETERS *parameters)
|
---|
481 | {
|
---|
482 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
483 |
|
---|
484 | TRACE("iface %p, parameters %p.\n", iface, parameters);
|
---|
485 |
|
---|
486 | wined3d_mutex_lock();
|
---|
487 | wined3d_device_get_creation_parameters(device->wined3d_device,
|
---|
488 | (struct wined3d_device_creation_parameters *)parameters);
|
---|
489 | wined3d_mutex_unlock();
|
---|
490 |
|
---|
491 | return D3D_OK;
|
---|
492 | }
|
---|
493 |
|
---|
494 | static HRESULT WINAPI d3d9_device_SetCursorProperties(IDirect3DDevice9Ex *iface,
|
---|
495 | UINT hotspot_x, UINT hotspot_y, IDirect3DSurface9 *bitmap)
|
---|
496 | {
|
---|
497 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
498 | struct d3d9_surface *bitmap_impl = unsafe_impl_from_IDirect3DSurface9(bitmap);
|
---|
499 | HRESULT hr;
|
---|
500 |
|
---|
501 | TRACE("iface %p, hotspot_x %u, hotspot_y %u, bitmap %p.\n",
|
---|
502 | iface, hotspot_x, hotspot_y, bitmap);
|
---|
503 |
|
---|
504 | if (!bitmap)
|
---|
505 | {
|
---|
506 | WARN("No cursor bitmap, returning D3DERR_INVALIDCALL.\n");
|
---|
507 | return D3DERR_INVALIDCALL;
|
---|
508 | }
|
---|
509 |
|
---|
510 | wined3d_mutex_lock();
|
---|
511 | hr = wined3d_device_set_cursor_properties(device->wined3d_device,
|
---|
512 | hotspot_x, hotspot_y, bitmap_impl->wined3d_surface);
|
---|
513 | wined3d_mutex_unlock();
|
---|
514 |
|
---|
515 | return hr;
|
---|
516 | }
|
---|
517 |
|
---|
518 | static void WINAPI d3d9_device_SetCursorPosition(IDirect3DDevice9Ex *iface, int x, int y, DWORD flags)
|
---|
519 | {
|
---|
520 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
521 |
|
---|
522 | TRACE("iface %p, x %u, y %u, flags %#x.\n", iface, x, y, flags);
|
---|
523 |
|
---|
524 | wined3d_mutex_lock();
|
---|
525 | wined3d_device_set_cursor_position(device->wined3d_device, x, y, flags);
|
---|
526 | wined3d_mutex_unlock();
|
---|
527 | }
|
---|
528 |
|
---|
529 | static BOOL WINAPI d3d9_device_ShowCursor(IDirect3DDevice9Ex *iface, BOOL show)
|
---|
530 | {
|
---|
531 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
532 | BOOL ret;
|
---|
533 |
|
---|
534 | TRACE("iface %p, show %#x.\n", iface, show);
|
---|
535 |
|
---|
536 | wined3d_mutex_lock();
|
---|
537 | ret = wined3d_device_show_cursor(device->wined3d_device, show);
|
---|
538 | wined3d_mutex_unlock();
|
---|
539 |
|
---|
540 | return ret;
|
---|
541 | }
|
---|
542 |
|
---|
543 | static HRESULT WINAPI DECLSPEC_HOTPATCH d3d9_device_CreateAdditionalSwapChain(IDirect3DDevice9Ex *iface,
|
---|
544 | D3DPRESENT_PARAMETERS *present_parameters, IDirect3DSwapChain9 **swapchain)
|
---|
545 | {
|
---|
546 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
547 | struct wined3d_swapchain_desc desc;
|
---|
548 | struct d3d9_swapchain *object;
|
---|
549 | HRESULT hr;
|
---|
550 |
|
---|
551 | TRACE("iface %p, present_parameters %p, swapchain %p.\n",
|
---|
552 | iface, present_parameters, swapchain);
|
---|
553 |
|
---|
554 | wined3d_swapchain_desc_from_present_parameters(&desc, present_parameters);
|
---|
555 | if (SUCCEEDED(hr = d3d9_swapchain_create(device, &desc, &object)))
|
---|
556 | *swapchain = &object->IDirect3DSwapChain9_iface;
|
---|
557 | present_parameters_from_wined3d_swapchain_desc(present_parameters, &desc);
|
---|
558 |
|
---|
559 | return hr;
|
---|
560 | }
|
---|
561 |
|
---|
562 | static HRESULT WINAPI DECLSPEC_HOTPATCH d3d9_device_GetSwapChain(IDirect3DDevice9Ex *iface,
|
---|
563 | UINT swapchain_idx, IDirect3DSwapChain9 **swapchain)
|
---|
564 | {
|
---|
565 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
566 | struct wined3d_swapchain *wined3d_swapchain;
|
---|
567 | struct d3d9_swapchain *swapchain_impl;
|
---|
568 | HRESULT hr;
|
---|
569 |
|
---|
570 | TRACE("iface %p, swapchain_idx %u, swapchain %p.\n", iface, swapchain_idx, swapchain);
|
---|
571 |
|
---|
572 | wined3d_mutex_lock();
|
---|
573 | if ((wined3d_swapchain = wined3d_device_get_swapchain(device->wined3d_device, swapchain_idx)))
|
---|
574 | {
|
---|
575 | swapchain_impl = wined3d_swapchain_get_parent(wined3d_swapchain);
|
---|
576 | *swapchain = &swapchain_impl->IDirect3DSwapChain9_iface;
|
---|
577 | IDirect3DSwapChain9_AddRef(*swapchain);
|
---|
578 | hr = D3D_OK;
|
---|
579 | }
|
---|
580 | else
|
---|
581 | {
|
---|
582 | *swapchain = NULL;
|
---|
583 | hr = D3DERR_INVALIDCALL;
|
---|
584 | }
|
---|
585 | wined3d_mutex_unlock();
|
---|
586 |
|
---|
587 | return hr;
|
---|
588 | }
|
---|
589 |
|
---|
590 | static UINT WINAPI d3d9_device_GetNumberOfSwapChains(IDirect3DDevice9Ex *iface)
|
---|
591 | {
|
---|
592 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
593 | UINT count;
|
---|
594 |
|
---|
595 | TRACE("iface %p.\n", iface);
|
---|
596 |
|
---|
597 | wined3d_mutex_lock();
|
---|
598 | count = wined3d_device_get_swapchain_count(device->wined3d_device);
|
---|
599 | wined3d_mutex_unlock();
|
---|
600 |
|
---|
601 | return count;
|
---|
602 | }
|
---|
603 |
|
---|
604 | static HRESULT CDECL reset_enum_callback(struct wined3d_resource *resource)
|
---|
605 | {
|
---|
606 | struct wined3d_resource_desc desc;
|
---|
607 |
|
---|
608 | wined3d_resource_get_desc(resource, &desc);
|
---|
609 | if (desc.pool == WINED3D_POOL_DEFAULT)
|
---|
610 | {
|
---|
611 | struct d3d9_surface *surface;
|
---|
612 |
|
---|
613 | if (desc.resource_type == WINED3D_RTYPE_TEXTURE)
|
---|
614 | {
|
---|
615 | IUnknown *parent = wined3d_resource_get_parent(resource);
|
---|
616 | IDirect3DBaseTexture9 *texture;
|
---|
617 |
|
---|
618 | if (SUCCEEDED(IUnknown_QueryInterface(parent, &IID_IDirect3DBaseTexture9, (void **)&texture)))
|
---|
619 | {
|
---|
620 | IDirect3DBaseTexture9_Release(texture);
|
---|
621 | WARN("Texture %p (resource %p) in pool D3DPOOL_DEFAULT blocks the Reset call.\n", texture, resource);
|
---|
622 | return D3DERR_INVALIDCALL;
|
---|
623 | }
|
---|
624 |
|
---|
625 | return D3D_OK;
|
---|
626 | }
|
---|
627 |
|
---|
628 | if (desc.resource_type != WINED3D_RTYPE_SURFACE)
|
---|
629 | {
|
---|
630 | WARN("Resource %p in pool D3DPOOL_DEFAULT blocks the Reset call.\n", resource);
|
---|
631 | return D3DERR_INVALIDCALL;
|
---|
632 | }
|
---|
633 |
|
---|
634 | surface = wined3d_resource_get_parent(resource);
|
---|
635 | if (surface->refcount)
|
---|
636 | {
|
---|
637 | WARN("Surface %p (resource %p) in pool D3DPOOL_DEFAULT blocks the Reset call.\n", surface, resource);
|
---|
638 | return D3DERR_INVALIDCALL;
|
---|
639 | }
|
---|
640 |
|
---|
641 | WARN("Surface %p (resource %p) is an implicit resource with ref 0.\n", surface, resource);
|
---|
642 | }
|
---|
643 |
|
---|
644 | return D3D_OK;
|
---|
645 | }
|
---|
646 |
|
---|
647 | static HRESULT WINAPI DECLSPEC_HOTPATCH d3d9_device_Reset(IDirect3DDevice9Ex *iface,
|
---|
648 | D3DPRESENT_PARAMETERS *present_parameters)
|
---|
649 | {
|
---|
650 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
651 | struct wined3d_swapchain_desc swapchain_desc;
|
---|
652 | HRESULT hr;
|
---|
653 |
|
---|
654 | TRACE("iface %p, present_parameters %p.\n", iface, present_parameters);
|
---|
655 |
|
---|
656 | wined3d_mutex_lock();
|
---|
657 |
|
---|
658 | if (device->vertex_buffer)
|
---|
659 | {
|
---|
660 | wined3d_buffer_decref(device->vertex_buffer);
|
---|
661 | device->vertex_buffer = NULL;
|
---|
662 | device->vertex_buffer_size = 0;
|
---|
663 | }
|
---|
664 | if (device->index_buffer)
|
---|
665 | {
|
---|
666 | wined3d_buffer_decref(device->index_buffer);
|
---|
667 | device->index_buffer = NULL;
|
---|
668 | device->index_buffer_size = 0;
|
---|
669 | }
|
---|
670 |
|
---|
671 | wined3d_swapchain_desc_from_present_parameters(&swapchain_desc, present_parameters);
|
---|
672 | hr = wined3d_device_reset(device->wined3d_device, &swapchain_desc,
|
---|
673 | NULL, reset_enum_callback, !device->d3d_parent->extended);
|
---|
674 | if (FAILED(hr) && !device->d3d_parent->extended)
|
---|
675 | device->not_reset = TRUE;
|
---|
676 | else
|
---|
677 | device->not_reset = FALSE;
|
---|
678 | wined3d_mutex_unlock();
|
---|
679 |
|
---|
680 | return hr;
|
---|
681 | }
|
---|
682 |
|
---|
683 | static HRESULT WINAPI DECLSPEC_HOTPATCH d3d9_device_Present(IDirect3DDevice9Ex *iface,
|
---|
684 | const RECT *src_rect, const RECT *dst_rect, HWND dst_window_override, const RGNDATA *dirty_region)
|
---|
685 | {
|
---|
686 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
687 | HRESULT hr;
|
---|
688 |
|
---|
689 | TRACE("iface %p, src_rect %p, dst_rect %p, dst_window_override %p, dirty_region %p.\n",
|
---|
690 | iface, src_rect, dst_rect, dst_window_override, dirty_region);
|
---|
691 |
|
---|
692 | wined3d_mutex_lock();
|
---|
693 | hr = wined3d_device_present(device->wined3d_device, src_rect, dst_rect,
|
---|
694 | dst_window_override, dirty_region, 0);
|
---|
695 | wined3d_mutex_unlock();
|
---|
696 |
|
---|
697 | return hr;
|
---|
698 | }
|
---|
699 |
|
---|
700 | static HRESULT WINAPI d3d9_device_GetBackBuffer(IDirect3DDevice9Ex *iface, UINT swapchain,
|
---|
701 | UINT backbuffer_idx, D3DBACKBUFFER_TYPE backbuffer_type, IDirect3DSurface9 **backbuffer)
|
---|
702 | {
|
---|
703 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
704 | struct wined3d_surface *wined3d_surface = NULL;
|
---|
705 | struct d3d9_surface *surface_impl;
|
---|
706 | HRESULT hr;
|
---|
707 |
|
---|
708 | TRACE("iface %p, swapchain %u, backbuffer_idx %u, backbuffer_type %#x, backbuffer %p.\n",
|
---|
709 | iface, swapchain, backbuffer_idx, backbuffer_type, backbuffer);
|
---|
710 |
|
---|
711 | wined3d_mutex_lock();
|
---|
712 | hr = wined3d_device_get_back_buffer(device->wined3d_device, swapchain,
|
---|
713 | backbuffer_idx, (enum wined3d_backbuffer_type)backbuffer_type, &wined3d_surface);
|
---|
714 | if (SUCCEEDED(hr) && wined3d_surface && backbuffer)
|
---|
715 | {
|
---|
716 | surface_impl = wined3d_surface_get_parent(wined3d_surface);
|
---|
717 | *backbuffer = &surface_impl->IDirect3DSurface9_iface;
|
---|
718 | IDirect3DSurface9_AddRef(*backbuffer);
|
---|
719 | }
|
---|
720 | wined3d_mutex_unlock();
|
---|
721 |
|
---|
722 | return hr;
|
---|
723 | }
|
---|
724 | static HRESULT WINAPI d3d9_device_GetRasterStatus(IDirect3DDevice9Ex *iface,
|
---|
725 | UINT swapchain, D3DRASTER_STATUS *raster_status)
|
---|
726 | {
|
---|
727 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
728 | HRESULT hr;
|
---|
729 |
|
---|
730 | TRACE("iface %p, swapchain %u, raster_status %p.\n", iface, swapchain, raster_status);
|
---|
731 |
|
---|
732 | wined3d_mutex_lock();
|
---|
733 | hr = wined3d_device_get_raster_status(device->wined3d_device,
|
---|
734 | swapchain, (struct wined3d_raster_status *)raster_status);
|
---|
735 | wined3d_mutex_unlock();
|
---|
736 |
|
---|
737 | return hr;
|
---|
738 | }
|
---|
739 |
|
---|
740 | static HRESULT WINAPI d3d9_device_SetDialogBoxMode(IDirect3DDevice9Ex *iface, BOOL enable)
|
---|
741 | {
|
---|
742 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
743 | HRESULT hr;
|
---|
744 |
|
---|
745 | TRACE("iface %p, enable %#x.\n", iface, enable);
|
---|
746 |
|
---|
747 | wined3d_mutex_lock();
|
---|
748 | hr = wined3d_device_set_dialog_box_mode(device->wined3d_device, enable);
|
---|
749 | wined3d_mutex_unlock();
|
---|
750 |
|
---|
751 | return hr;
|
---|
752 | }
|
---|
753 |
|
---|
754 | static void WINAPI d3d9_device_SetGammaRamp(IDirect3DDevice9Ex *iface,
|
---|
755 | UINT swapchain, DWORD flags, const D3DGAMMARAMP *ramp)
|
---|
756 | {
|
---|
757 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
758 |
|
---|
759 | TRACE("iface %p, swapchain %u, flags %#x, ramp %p.\n", iface, swapchain, flags, ramp);
|
---|
760 |
|
---|
761 | /* Note: D3DGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
|
---|
762 | wined3d_mutex_lock();
|
---|
763 | wined3d_device_set_gamma_ramp(device->wined3d_device, swapchain, flags, (const struct wined3d_gamma_ramp *)ramp);
|
---|
764 | wined3d_mutex_unlock();
|
---|
765 | }
|
---|
766 |
|
---|
767 | static void WINAPI d3d9_device_GetGammaRamp(IDirect3DDevice9Ex *iface, UINT swapchain, D3DGAMMARAMP *ramp)
|
---|
768 | {
|
---|
769 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
770 |
|
---|
771 | TRACE("iface %p, swapchain %u, ramp %p.\n", iface, swapchain, ramp);
|
---|
772 |
|
---|
773 | /* Note: D3DGAMMARAMP is compatible with struct wined3d_gamma_ramp. */
|
---|
774 | wined3d_mutex_lock();
|
---|
775 | wined3d_device_get_gamma_ramp(device->wined3d_device, swapchain, (struct wined3d_gamma_ramp *)ramp);
|
---|
776 | wined3d_mutex_unlock();
|
---|
777 | }
|
---|
778 |
|
---|
779 | #ifdef VBOX_WITH_WDDM
|
---|
780 | //#pragma comment(linker, "/export:VBoxWineExD3DDev9Flush=_VBoxWineExD3DDev9Flush@4")
|
---|
781 |
|
---|
782 | VBOXWINEEX_DECL(HRESULT) VBoxWineExD3DDev9Flush(IDirect3DDevice9Ex *iface)
|
---|
783 | {
|
---|
784 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
785 | HRESULT hr;
|
---|
786 |
|
---|
787 | TRACE("iface %p, Flush\n", iface);
|
---|
788 |
|
---|
789 | wined3d_mutex_lock();
|
---|
790 | hr = wined3d_device_flush(device->wined3d_device);
|
---|
791 | wined3d_mutex_unlock();
|
---|
792 |
|
---|
793 | return hr;
|
---|
794 | }
|
---|
795 |
|
---|
796 | VBOXWINEEX_DECL(HRESULT) VBoxWineExD3DDev9FlushToHost(IDirect3DDevice9Ex *iface)
|
---|
797 | {
|
---|
798 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
799 | HRESULT hr;
|
---|
800 |
|
---|
801 | TRACE("iface %p, FlushToHost\n", iface);
|
---|
802 |
|
---|
803 | wined3d_mutex_lock();
|
---|
804 | hr = wined3d_device_flush_to_host(device->wined3d_device);
|
---|
805 | wined3d_mutex_unlock();
|
---|
806 |
|
---|
807 | return hr;
|
---|
808 | }
|
---|
809 |
|
---|
810 | VBOXWINEEX_DECL(HRESULT) VBoxWineExD3DDev9Finish(IDirect3DDevice9Ex *iface)
|
---|
811 | {
|
---|
812 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
813 | HRESULT hr;
|
---|
814 |
|
---|
815 | TRACE("iface %p, FlushToHost\n", iface);
|
---|
816 |
|
---|
817 | wined3d_mutex_lock();
|
---|
818 | hr = wined3d_device_finish(device->wined3d_device);
|
---|
819 | wined3d_mutex_unlock();
|
---|
820 |
|
---|
821 | return hr;
|
---|
822 | }
|
---|
823 |
|
---|
824 | VBOXWINEEX_DECL(HRESULT) VBoxWineExD3DDev9GetHostId(IDirect3DDevice9Ex *iface, int32_t *pi32Id)
|
---|
825 | {
|
---|
826 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
827 | HRESULT hr;
|
---|
828 |
|
---|
829 | TRACE("iface %p, FlushToHost\n", iface);
|
---|
830 |
|
---|
831 | wined3d_mutex_lock();
|
---|
832 | hr = wined3d_device_get_host_id(device->wined3d_device, pi32Id);
|
---|
833 | wined3d_mutex_unlock();
|
---|
834 |
|
---|
835 | return hr;
|
---|
836 | }
|
---|
837 |
|
---|
838 | //#pragma comment(linker, "/export:VBoxWineExD3DDev9CreateTexture=_VBoxWineExD3DDev9CreateTexture@40")
|
---|
839 |
|
---|
840 | VBOXWINEEX_DECL(HRESULT) VBoxWineExD3DDev9CreateTexture(IDirect3DDevice9Ex *iface,
|
---|
841 | UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format,
|
---|
842 | D3DPOOL pool, IDirect3DTexture9 **texture, HANDLE *shared_handle,
|
---|
843 | void **pavClientMem) /* <- extension arg to pass in the client memory buffer,
|
---|
844 | * applicable ONLY for SYSMEM textures */
|
---|
845 | {
|
---|
846 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
847 | struct d3d9_texture *object;
|
---|
848 | HRESULT hr;
|
---|
849 |
|
---|
850 | TRACE("iface %p, width %u, height %u, levels %u, usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
|
---|
851 | iface, width, height, levels, usage, format, pool, texture, shared_handle);
|
---|
852 |
|
---|
853 | object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
|
---|
854 | if (!object)
|
---|
855 | return D3DERR_OUTOFVIDEOMEMORY;
|
---|
856 |
|
---|
857 | hr = texture_init(object, device, width, height, levels, usage, format, pool, shared_handle, pavClientMem);
|
---|
858 | if (FAILED(hr))
|
---|
859 | {
|
---|
860 | WARN("Failed to initialize texture, hr %#x.\n", hr);
|
---|
861 | HeapFree(GetProcessHeap(), 0, object);
|
---|
862 | return hr;
|
---|
863 | }
|
---|
864 |
|
---|
865 | TRACE("Created texture %p.\n", object);
|
---|
866 | *texture = (IDirect3DTexture9 *)&object->IDirect3DBaseTexture9_iface;
|
---|
867 |
|
---|
868 | return D3D_OK;
|
---|
869 | }
|
---|
870 |
|
---|
871 | VBOXWINEEX_DECL(HRESULT) VBoxWineExD3DDev9CreateVolumeTexture(IDirect3DDevice9Ex *iface,
|
---|
872 | UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format,
|
---|
873 | D3DPOOL pool, IDirect3DVolumeTexture9 **texture, HANDLE *shared_handle,
|
---|
874 | void **pavClientMem)
|
---|
875 | {
|
---|
876 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
877 | struct d3d9_texture *object;
|
---|
878 | HRESULT hr;
|
---|
879 |
|
---|
880 | TRACE("iface %p, width %u, height %u, depth %u, levels %u\n",
|
---|
881 | iface, width, height, depth, levels);
|
---|
882 | TRACE("usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
|
---|
883 | usage, format, pool, texture, shared_handle);
|
---|
884 |
|
---|
885 | if (shared_handle)
|
---|
886 | FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle);
|
---|
887 |
|
---|
888 | object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
|
---|
889 | if (!object)
|
---|
890 | return D3DERR_OUTOFVIDEOMEMORY;
|
---|
891 |
|
---|
892 | hr = volumetexture_init(object, device, width, height, depth, levels, usage, format, pool, shared_handle, pavClientMem);
|
---|
893 | if (FAILED(hr))
|
---|
894 | {
|
---|
895 | WARN("Failed to initialize volume texture, hr %#x.\n", hr);
|
---|
896 | HeapFree(GetProcessHeap(), 0, object);
|
---|
897 | return hr;
|
---|
898 | }
|
---|
899 |
|
---|
900 | TRACE("Created volume texture %p.\n", object);
|
---|
901 | *texture = (IDirect3DVolumeTexture9 *)&object->IDirect3DBaseTexture9_iface;
|
---|
902 |
|
---|
903 | return D3D_OK;
|
---|
904 | }
|
---|
905 |
|
---|
906 | VBOXWINEEX_DECL(HRESULT) VBoxWineExD3DDev9CreateCubeTexture(IDirect3DDevice9Ex *iface,
|
---|
907 | UINT edge_length, UINT levels, DWORD usage, D3DFORMAT format,
|
---|
908 | D3DPOOL pool, IDirect3DCubeTexture9 **texture, HANDLE *shared_handle,
|
---|
909 | void **pavClientMem) /* <- extension arg to pass in the client memory buffer,
|
---|
910 | * applicable ONLY for SYSMEM textures */
|
---|
911 | {
|
---|
912 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
913 | struct d3d9_texture *object;
|
---|
914 | HRESULT hr;
|
---|
915 |
|
---|
916 | TRACE("iface %p, edge_length %u, levels %u, usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
|
---|
917 | iface, edge_length, levels, usage, format, pool, texture, shared_handle);
|
---|
918 |
|
---|
919 | if (shared_handle)
|
---|
920 | FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle);
|
---|
921 |
|
---|
922 | object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
|
---|
923 | if (!object)
|
---|
924 | return D3DERR_OUTOFVIDEOMEMORY;
|
---|
925 |
|
---|
926 | hr = cubetexture_init(object, device, edge_length, levels, usage, format, pool, shared_handle, pavClientMem);
|
---|
927 | if (FAILED(hr))
|
---|
928 | {
|
---|
929 | WARN("Failed to initialize cube texture, hr %#x.\n", hr);
|
---|
930 | HeapFree(GetProcessHeap(), 0, object);
|
---|
931 | return hr;
|
---|
932 | }
|
---|
933 |
|
---|
934 | TRACE("Created cube texture %p.\n", object);
|
---|
935 | *texture = (IDirect3DCubeTexture9 *)&object->IDirect3DBaseTexture9_iface;
|
---|
936 |
|
---|
937 | return D3D_OK;
|
---|
938 | }
|
---|
939 |
|
---|
940 | #endif
|
---|
941 |
|
---|
942 | static HRESULT WINAPI d3d9_device_CreateTexture(IDirect3DDevice9Ex *iface,
|
---|
943 | UINT width, UINT height, UINT levels, DWORD usage, D3DFORMAT format,
|
---|
944 | D3DPOOL pool, IDirect3DTexture9 **texture, HANDLE *shared_handle)
|
---|
945 | {
|
---|
946 | #ifdef VBOX_WITH_WDDM
|
---|
947 | return VBoxWineExD3DDev9CreateTexture(iface, width, height, levels, usage, format,
|
---|
948 | pool, texture, shared_handle,
|
---|
949 | NULL);
|
---|
950 | #else
|
---|
951 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
952 | struct d3d9_texture *object;
|
---|
953 | BOOL set_mem = FALSE;
|
---|
954 | HRESULT hr;
|
---|
955 |
|
---|
956 | TRACE("iface %p, width %u, height %u, levels %u, usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
|
---|
957 | iface, width, height, levels, usage, format, pool, texture, shared_handle);
|
---|
958 |
|
---|
959 | if (shared_handle)
|
---|
960 | {
|
---|
961 | if (pool == D3DPOOL_SYSTEMMEM)
|
---|
962 | {
|
---|
963 | if (levels != 1)
|
---|
964 | return D3DERR_INVALIDCALL;
|
---|
965 | set_mem = TRUE;
|
---|
966 | }
|
---|
967 | else
|
---|
968 | FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle);
|
---|
969 | }
|
---|
970 |
|
---|
971 | object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
|
---|
972 | if (!object)
|
---|
973 | return D3DERR_OUTOFVIDEOMEMORY;
|
---|
974 |
|
---|
975 | hr = texture_init(object, device, width, height, levels, usage, format, pool);
|
---|
976 | if (FAILED(hr))
|
---|
977 | {
|
---|
978 | WARN("Failed to initialize texture, hr %#x.\n", hr);
|
---|
979 | HeapFree(GetProcessHeap(), 0, object);
|
---|
980 | return hr;
|
---|
981 | }
|
---|
982 |
|
---|
983 | if (set_mem)
|
---|
984 | {
|
---|
985 | struct wined3d_resource *resource;
|
---|
986 | struct d3d9_surface *surface;
|
---|
987 |
|
---|
988 | resource = wined3d_texture_get_sub_resource(object->wined3d_texture, 0);
|
---|
989 | surface = wined3d_resource_get_parent(resource);
|
---|
990 | wined3d_surface_set_mem(surface->wined3d_surface, *shared_handle);
|
---|
991 | }
|
---|
992 |
|
---|
993 | TRACE("Created texture %p.\n", object);
|
---|
994 | *texture = (IDirect3DTexture9 *)&object->IDirect3DBaseTexture9_iface;
|
---|
995 |
|
---|
996 | return D3D_OK;
|
---|
997 | #endif
|
---|
998 | }
|
---|
999 |
|
---|
1000 | static HRESULT WINAPI d3d9_device_CreateVolumeTexture(IDirect3DDevice9Ex *iface,
|
---|
1001 | UINT width, UINT height, UINT depth, UINT levels, DWORD usage, D3DFORMAT format,
|
---|
1002 | D3DPOOL pool, IDirect3DVolumeTexture9 **texture, HANDLE *shared_handle)
|
---|
1003 | {
|
---|
1004 | #ifdef VBOX_WITH_WDDM
|
---|
1005 | return VBoxWineExD3DDev9CreateVolumeTexture(iface, width, height, depth, levels, usage, format,
|
---|
1006 | pool, texture, shared_handle, NULL);
|
---|
1007 | #else
|
---|
1008 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
1009 | struct d3d9_texture *object;
|
---|
1010 | HRESULT hr;
|
---|
1011 |
|
---|
1012 | TRACE("iface %p, width %u, height %u, depth %u, levels %u\n",
|
---|
1013 | iface, width, height, depth, levels);
|
---|
1014 | TRACE("usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
|
---|
1015 | usage, format, pool, texture, shared_handle);
|
---|
1016 |
|
---|
1017 | if (shared_handle)
|
---|
1018 | FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle);
|
---|
1019 |
|
---|
1020 | object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
|
---|
1021 | if (!object)
|
---|
1022 | return D3DERR_OUTOFVIDEOMEMORY;
|
---|
1023 |
|
---|
1024 | hr = volumetexture_init(object, device, width, height, depth, levels, usage, format, pool);
|
---|
1025 | if (FAILED(hr))
|
---|
1026 | {
|
---|
1027 | WARN("Failed to initialize volume texture, hr %#x.\n", hr);
|
---|
1028 | HeapFree(GetProcessHeap(), 0, object);
|
---|
1029 | return hr;
|
---|
1030 | }
|
---|
1031 |
|
---|
1032 | TRACE("Created volume texture %p.\n", object);
|
---|
1033 | *texture = (IDirect3DVolumeTexture9 *)&object->IDirect3DBaseTexture9_iface;
|
---|
1034 |
|
---|
1035 | return D3D_OK;
|
---|
1036 | #endif
|
---|
1037 | }
|
---|
1038 |
|
---|
1039 | static HRESULT WINAPI d3d9_device_CreateCubeTexture(IDirect3DDevice9Ex *iface,
|
---|
1040 | UINT edge_length, UINT levels, DWORD usage, D3DFORMAT format, D3DPOOL pool,
|
---|
1041 | IDirect3DCubeTexture9 **texture, HANDLE *shared_handle)
|
---|
1042 | {
|
---|
1043 | #ifdef VBOX_WITH_WDDM
|
---|
1044 | return VBoxWineExD3DDev9CreateCubeTexture(iface, edge_length, levels, usage, format,
|
---|
1045 | pool, texture, shared_handle, NULL);
|
---|
1046 | #else
|
---|
1047 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
1048 | struct d3d9_texture *object;
|
---|
1049 | HRESULT hr;
|
---|
1050 |
|
---|
1051 | TRACE("iface %p, edge_length %u, levels %u, usage %#x, format %#x, pool %#x, texture %p, shared_handle %p.\n",
|
---|
1052 | iface, edge_length, levels, usage, format, pool, texture, shared_handle);
|
---|
1053 |
|
---|
1054 | if (shared_handle)
|
---|
1055 | FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle);
|
---|
1056 |
|
---|
1057 | object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
|
---|
1058 | if (!object)
|
---|
1059 | return D3DERR_OUTOFVIDEOMEMORY;
|
---|
1060 |
|
---|
1061 | hr = cubetexture_init(object, device, edge_length, levels, usage, format, pool);
|
---|
1062 | if (FAILED(hr))
|
---|
1063 | {
|
---|
1064 | WARN("Failed to initialize cube texture, hr %#x.\n", hr);
|
---|
1065 | HeapFree(GetProcessHeap(), 0, object);
|
---|
1066 | return hr;
|
---|
1067 | }
|
---|
1068 |
|
---|
1069 | TRACE("Created cube texture %p.\n", object);
|
---|
1070 | *texture = (IDirect3DCubeTexture9 *)&object->IDirect3DBaseTexture9_iface;
|
---|
1071 |
|
---|
1072 | return D3D_OK;
|
---|
1073 | #endif
|
---|
1074 | }
|
---|
1075 |
|
---|
1076 | static HRESULT WINAPI d3d9_device_CreateVertexBuffer(IDirect3DDevice9Ex *iface, UINT size,
|
---|
1077 | DWORD usage, DWORD fvf, D3DPOOL pool, IDirect3DVertexBuffer9 **buffer,
|
---|
1078 | HANDLE *shared_handle)
|
---|
1079 | {
|
---|
1080 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
1081 | struct d3d9_vertexbuffer *object;
|
---|
1082 | HRESULT hr;
|
---|
1083 |
|
---|
1084 | TRACE("iface %p, size %u, usage %#x, fvf %#x, pool %#x, buffer %p, shared_handle %p.\n",
|
---|
1085 | iface, size, usage, fvf, pool, buffer, shared_handle);
|
---|
1086 |
|
---|
1087 | if (shared_handle)
|
---|
1088 | FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle);
|
---|
1089 |
|
---|
1090 | object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
|
---|
1091 | if (!object)
|
---|
1092 | return D3DERR_OUTOFVIDEOMEMORY;
|
---|
1093 |
|
---|
1094 | hr = vertexbuffer_init(object, device, size, usage, fvf, pool);
|
---|
1095 | if (FAILED(hr))
|
---|
1096 | {
|
---|
1097 | WARN("Failed to initialize vertex buffer, hr %#x.\n", hr);
|
---|
1098 | HeapFree(GetProcessHeap(), 0, object);
|
---|
1099 | return hr;
|
---|
1100 | }
|
---|
1101 |
|
---|
1102 | TRACE("Created vertex buffer %p.\n", object);
|
---|
1103 | *buffer = &object->IDirect3DVertexBuffer9_iface;
|
---|
1104 |
|
---|
1105 | return D3D_OK;
|
---|
1106 | }
|
---|
1107 |
|
---|
1108 | static HRESULT WINAPI d3d9_device_CreateIndexBuffer(IDirect3DDevice9Ex *iface, UINT size,
|
---|
1109 | DWORD usage, D3DFORMAT format, D3DPOOL pool, IDirect3DIndexBuffer9 **buffer,
|
---|
1110 | HANDLE *shared_handle)
|
---|
1111 | {
|
---|
1112 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
1113 | struct d3d9_indexbuffer *object;
|
---|
1114 | HRESULT hr;
|
---|
1115 |
|
---|
1116 | TRACE("iface %p, size %u, usage %#x, format %#x, pool %#x, buffer %p, shared_handle %p.\n",
|
---|
1117 | iface, size, usage, format, pool, buffer, shared_handle);
|
---|
1118 |
|
---|
1119 | if (shared_handle)
|
---|
1120 | FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle);
|
---|
1121 |
|
---|
1122 | object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
|
---|
1123 | if (!object)
|
---|
1124 | return D3DERR_OUTOFVIDEOMEMORY;
|
---|
1125 |
|
---|
1126 | hr = indexbuffer_init(object, device, size, usage, format, pool);
|
---|
1127 | if (FAILED(hr))
|
---|
1128 | {
|
---|
1129 | WARN("Failed to initialize index buffer, hr %#x.\n", hr);
|
---|
1130 | HeapFree(GetProcessHeap(), 0, object);
|
---|
1131 | return hr;
|
---|
1132 | }
|
---|
1133 |
|
---|
1134 | TRACE("Created index buffer %p.\n", object);
|
---|
1135 | *buffer = &object->IDirect3DIndexBuffer9_iface;
|
---|
1136 |
|
---|
1137 | return D3D_OK;
|
---|
1138 | }
|
---|
1139 |
|
---|
1140 | static HRESULT d3d9_device_create_surface(struct d3d9_device *device, UINT width, UINT height,
|
---|
1141 | D3DFORMAT format, DWORD flags, IDirect3DSurface9 **surface, UINT usage, D3DPOOL pool,
|
---|
1142 | D3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality
|
---|
1143 | #ifdef VBOX_WITH_WDDM
|
---|
1144 | , HANDLE *shared_handle
|
---|
1145 | , void *pvClientMem
|
---|
1146 | #endif
|
---|
1147 | )
|
---|
1148 | {
|
---|
1149 | struct d3d9_surface *object;
|
---|
1150 | HRESULT hr;
|
---|
1151 |
|
---|
1152 | TRACE("device %p, width %u, height %u, format %#x, flags %#x, surface %p.\n"
|
---|
1153 | "usage %#x, pool %#x, multisample_type %#x, multisample_quality %u.\n",
|
---|
1154 | device, width, height, format, flags, surface, usage, pool,
|
---|
1155 | multisample_type, multisample_quality);
|
---|
1156 |
|
---|
1157 | if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
|
---|
1158 | {
|
---|
1159 | FIXME("Failed to allocate surface memory.\n");
|
---|
1160 | return D3DERR_OUTOFVIDEOMEMORY;
|
---|
1161 | }
|
---|
1162 |
|
---|
1163 | #ifdef VBOX_WITH_WDDM
|
---|
1164 | if (FAILED(hr = surface_init(object, device, width, height, format,
|
---|
1165 | flags, usage, pool, multisample_type, multisample_quality
|
---|
1166 | , shared_handle
|
---|
1167 | , pvClientMem
|
---|
1168 | )))
|
---|
1169 | #else
|
---|
1170 | if (FAILED(hr = surface_init(object, device, width, height, format,
|
---|
1171 | flags, usage, pool, multisample_type, multisample_quality)))
|
---|
1172 | #endif
|
---|
1173 | {
|
---|
1174 | WARN("Failed to initialize surface, hr %#x.\n", hr);
|
---|
1175 | HeapFree(GetProcessHeap(), 0, object);
|
---|
1176 | return hr;
|
---|
1177 | }
|
---|
1178 |
|
---|
1179 | TRACE("Created surface %p.\n", object);
|
---|
1180 | *surface = &object->IDirect3DSurface9_iface;
|
---|
1181 |
|
---|
1182 | return D3D_OK;
|
---|
1183 | }
|
---|
1184 |
|
---|
1185 | static HRESULT WINAPI d3d9_device_CreateRenderTarget(IDirect3DDevice9Ex *iface, UINT width, UINT height,
|
---|
1186 | D3DFORMAT format, D3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality,
|
---|
1187 | BOOL lockable, IDirect3DSurface9 **surface, HANDLE *shared_handle)
|
---|
1188 | {
|
---|
1189 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
1190 | DWORD flags = 0;
|
---|
1191 |
|
---|
1192 | TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u.\n"
|
---|
1193 | "lockable %#x, surface %p, shared_handle %p.\n",
|
---|
1194 | iface, width, height, format, multisample_type, multisample_quality,
|
---|
1195 | lockable, surface, shared_handle);
|
---|
1196 |
|
---|
1197 | if (shared_handle)
|
---|
1198 | FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle);
|
---|
1199 |
|
---|
1200 | if (lockable)
|
---|
1201 | flags |= WINED3D_SURFACE_MAPPABLE;
|
---|
1202 |
|
---|
1203 | return d3d9_device_create_surface(device, width, height, format, flags, surface,
|
---|
1204 | D3DUSAGE_RENDERTARGET, D3DPOOL_DEFAULT, multisample_type, multisample_quality
|
---|
1205 | #ifdef VBOX_WITH_WDDM
|
---|
1206 | , shared_handle
|
---|
1207 | , NULL
|
---|
1208 | #endif
|
---|
1209 | );
|
---|
1210 | }
|
---|
1211 |
|
---|
1212 | static HRESULT WINAPI d3d9_device_CreateDepthStencilSurface(IDirect3DDevice9Ex *iface, UINT width, UINT height,
|
---|
1213 | D3DFORMAT format, D3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality,
|
---|
1214 | BOOL discard, IDirect3DSurface9 **surface, HANDLE *shared_handle)
|
---|
1215 | {
|
---|
1216 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
1217 | DWORD flags = WINED3D_SURFACE_MAPPABLE;
|
---|
1218 |
|
---|
1219 | TRACE("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u.\n"
|
---|
1220 | "discard %#x, surface %p, shared_handle %p.\n",
|
---|
1221 | iface, width, height, format, multisample_type, multisample_quality,
|
---|
1222 | discard, surface, shared_handle);
|
---|
1223 |
|
---|
1224 | if (shared_handle)
|
---|
1225 | FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle);
|
---|
1226 |
|
---|
1227 | if (discard)
|
---|
1228 | flags |= WINED3D_SURFACE_DISCARD;
|
---|
1229 |
|
---|
1230 | return d3d9_device_create_surface(device, width, height, format, flags, surface,
|
---|
1231 | D3DUSAGE_DEPTHSTENCIL, D3DPOOL_DEFAULT, multisample_type, multisample_quality
|
---|
1232 | #ifdef VBOX_WITH_WDDM
|
---|
1233 | , shared_handle
|
---|
1234 | , NULL
|
---|
1235 | #endif
|
---|
1236 | );
|
---|
1237 | }
|
---|
1238 |
|
---|
1239 |
|
---|
1240 | static HRESULT WINAPI d3d9_device_UpdateSurface(IDirect3DDevice9Ex *iface,
|
---|
1241 | IDirect3DSurface9 *src_surface, const RECT *src_rect,
|
---|
1242 | IDirect3DSurface9 *dst_surface, const POINT *dst_point)
|
---|
1243 | {
|
---|
1244 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
1245 | struct d3d9_surface *src = unsafe_impl_from_IDirect3DSurface9(src_surface);
|
---|
1246 | struct d3d9_surface *dst = unsafe_impl_from_IDirect3DSurface9(dst_surface);
|
---|
1247 | HRESULT hr;
|
---|
1248 |
|
---|
1249 | TRACE("iface %p, src_surface %p, src_rect %p, dst_surface %p, dst_point %p.\n",
|
---|
1250 | iface, src_surface, src_rect, dst_surface, dst_point);
|
---|
1251 |
|
---|
1252 | wined3d_mutex_lock();
|
---|
1253 | hr = wined3d_device_update_surface(device->wined3d_device, src->wined3d_surface, src_rect,
|
---|
1254 | dst->wined3d_surface, dst_point);
|
---|
1255 | wined3d_mutex_unlock();
|
---|
1256 |
|
---|
1257 | return hr;
|
---|
1258 | }
|
---|
1259 |
|
---|
1260 | static HRESULT WINAPI d3d9_device_UpdateTexture(IDirect3DDevice9Ex *iface,
|
---|
1261 | IDirect3DBaseTexture9 *src_texture, IDirect3DBaseTexture9 *dst_texture)
|
---|
1262 | {
|
---|
1263 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
1264 | struct d3d9_texture *src_impl, *dst_impl;
|
---|
1265 | HRESULT hr;
|
---|
1266 |
|
---|
1267 | TRACE("iface %p, src_texture %p, dst_texture %p.\n", iface, src_texture, dst_texture);
|
---|
1268 |
|
---|
1269 | src_impl = unsafe_impl_from_IDirect3DBaseTexture9(src_texture);
|
---|
1270 | dst_impl = unsafe_impl_from_IDirect3DBaseTexture9(dst_texture);
|
---|
1271 |
|
---|
1272 | wined3d_mutex_lock();
|
---|
1273 | hr = wined3d_device_update_texture(device->wined3d_device,
|
---|
1274 | src_impl->wined3d_texture, dst_impl->wined3d_texture);
|
---|
1275 | wined3d_mutex_unlock();
|
---|
1276 |
|
---|
1277 | return hr;
|
---|
1278 | }
|
---|
1279 |
|
---|
1280 | static HRESULT WINAPI d3d9_device_GetRenderTargetData(IDirect3DDevice9Ex *iface,
|
---|
1281 | IDirect3DSurface9 *render_target, IDirect3DSurface9 *dst_surface)
|
---|
1282 | {
|
---|
1283 | struct d3d9_surface *rt_impl = unsafe_impl_from_IDirect3DSurface9(render_target);
|
---|
1284 | struct d3d9_surface *dst_impl = unsafe_impl_from_IDirect3DSurface9(dst_surface);
|
---|
1285 | HRESULT hr;
|
---|
1286 |
|
---|
1287 | TRACE("iface %p, render_target %p, dst_surface %p.\n", iface, render_target, dst_surface);
|
---|
1288 |
|
---|
1289 | wined3d_mutex_lock();
|
---|
1290 | hr = wined3d_surface_get_render_target_data(dst_impl->wined3d_surface, rt_impl->wined3d_surface);
|
---|
1291 | wined3d_mutex_unlock();
|
---|
1292 |
|
---|
1293 | return hr;
|
---|
1294 | }
|
---|
1295 |
|
---|
1296 | static HRESULT WINAPI d3d9_device_GetFrontBufferData(IDirect3DDevice9Ex *iface,
|
---|
1297 | UINT swapchain, IDirect3DSurface9 *dst_surface)
|
---|
1298 | {
|
---|
1299 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
1300 | struct d3d9_surface *dst_impl = unsafe_impl_from_IDirect3DSurface9(dst_surface);
|
---|
1301 | HRESULT hr;
|
---|
1302 |
|
---|
1303 | TRACE("iface %p, swapchain %u, dst_surface %p.\n", iface, swapchain, dst_surface);
|
---|
1304 |
|
---|
1305 | wined3d_mutex_lock();
|
---|
1306 | hr = wined3d_device_get_front_buffer_data(device->wined3d_device, swapchain, dst_impl->wined3d_surface);
|
---|
1307 | wined3d_mutex_unlock();
|
---|
1308 |
|
---|
1309 | return hr;
|
---|
1310 | }
|
---|
1311 |
|
---|
1312 | static HRESULT WINAPI d3d9_device_StretchRect(IDirect3DDevice9Ex *iface, IDirect3DSurface9 *src_surface,
|
---|
1313 | const RECT *src_rect, IDirect3DSurface9 *dst_surface, const RECT *dst_rect, D3DTEXTUREFILTERTYPE filter)
|
---|
1314 | {
|
---|
1315 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
1316 | struct d3d9_surface *src = unsafe_impl_from_IDirect3DSurface9(src_surface);
|
---|
1317 | struct d3d9_surface *dst = unsafe_impl_from_IDirect3DSurface9(dst_surface);
|
---|
1318 | HRESULT hr = D3DERR_INVALIDCALL;
|
---|
1319 | struct wined3d_resource_desc src_desc, dst_desc;
|
---|
1320 | struct wined3d_resource *wined3d_resource;
|
---|
1321 |
|
---|
1322 | TRACE("iface %p, src_surface %p, src_rect %p, dst_surface %p, dst_rect %p, filter %#x.\n",
|
---|
1323 | iface, src_surface, src_rect, dst_surface, dst_rect, filter);
|
---|
1324 |
|
---|
1325 | wined3d_mutex_lock();
|
---|
1326 | wined3d_resource = wined3d_surface_get_resource(dst->wined3d_surface);
|
---|
1327 | wined3d_resource_get_desc(wined3d_resource, &dst_desc);
|
---|
1328 |
|
---|
1329 | wined3d_resource = wined3d_surface_get_resource(src->wined3d_surface);
|
---|
1330 | wined3d_resource_get_desc(wined3d_resource, &src_desc);
|
---|
1331 |
|
---|
1332 | if (src_desc.usage & WINED3DUSAGE_DEPTHSTENCIL)
|
---|
1333 | {
|
---|
1334 | if (device->in_scene)
|
---|
1335 | {
|
---|
1336 | WARN("Rejecting depth / stencil blit while in scene.\n");
|
---|
1337 | goto done;
|
---|
1338 | }
|
---|
1339 |
|
---|
1340 | if (src_rect)
|
---|
1341 | {
|
---|
1342 | if (src_rect->left || src_rect->top || src_rect->right != src_desc.width
|
---|
1343 | || src_rect->bottom != src_desc.height)
|
---|
1344 | {
|
---|
1345 | WARN("Rejecting depth / stencil blit with invalid source rect %s.\n",
|
---|
1346 | wine_dbgstr_rect(src_rect));
|
---|
1347 | goto done;
|
---|
1348 | }
|
---|
1349 | }
|
---|
1350 | if (dst_rect)
|
---|
1351 | {
|
---|
1352 | if (dst_rect->left || dst_rect->top || dst_rect->right != dst_desc.width
|
---|
1353 | || dst_rect->bottom != dst_desc.height)
|
---|
1354 | {
|
---|
1355 | WARN("Rejecting depth / stencil blit with invalid destination rect %s.\n",
|
---|
1356 | wine_dbgstr_rect(dst_rect));
|
---|
1357 | goto done;
|
---|
1358 | }
|
---|
1359 | }
|
---|
1360 | if (src_desc.width != dst_desc.width || src_desc.height != dst_desc.height)
|
---|
1361 | {
|
---|
1362 | WARN("Rejecting depth / stencil blit with mismatched surface sizes.\n");
|
---|
1363 | goto done;
|
---|
1364 | }
|
---|
1365 | }
|
---|
1366 |
|
---|
1367 | hr = wined3d_surface_blt(dst->wined3d_surface, dst_rect, src->wined3d_surface, src_rect, 0, NULL, filter);
|
---|
1368 | if (hr == WINEDDERR_INVALIDRECT)
|
---|
1369 | hr = D3DERR_INVALIDCALL;
|
---|
1370 |
|
---|
1371 | done:
|
---|
1372 | wined3d_mutex_unlock();
|
---|
1373 | return hr;
|
---|
1374 | }
|
---|
1375 |
|
---|
1376 | static HRESULT WINAPI d3d9_device_ColorFill(IDirect3DDevice9Ex *iface,
|
---|
1377 | IDirect3DSurface9 *surface, const RECT *rect, D3DCOLOR color)
|
---|
1378 | {
|
---|
1379 | const struct wined3d_color c =
|
---|
1380 | {
|
---|
1381 | ((color >> 16) & 0xff) / 255.0f,
|
---|
1382 | ((color >> 8) & 0xff) / 255.0f,
|
---|
1383 | (color & 0xff) / 255.0f,
|
---|
1384 | ((color >> 24) & 0xff) / 255.0f,
|
---|
1385 | };
|
---|
1386 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
1387 | struct d3d9_surface *surface_impl = unsafe_impl_from_IDirect3DSurface9(surface);
|
---|
1388 | struct wined3d_resource *wined3d_resource;
|
---|
1389 | struct wined3d_resource_desc desc;
|
---|
1390 | HRESULT hr;
|
---|
1391 |
|
---|
1392 | TRACE("iface %p, surface %p, rect %p, color 0x%08x.\n", iface, surface, rect, color);
|
---|
1393 |
|
---|
1394 | wined3d_mutex_lock();
|
---|
1395 |
|
---|
1396 | wined3d_resource = wined3d_surface_get_resource(surface_impl->wined3d_surface);
|
---|
1397 | wined3d_resource_get_desc(wined3d_resource, &desc);
|
---|
1398 |
|
---|
1399 | /* This method is only allowed with surfaces that are render targets, or
|
---|
1400 | * offscreen plain surfaces in D3DPOOL_DEFAULT. */
|
---|
1401 | if (!(desc.usage & WINED3DUSAGE_RENDERTARGET) && desc.pool != WINED3D_POOL_DEFAULT)
|
---|
1402 | {
|
---|
1403 | wined3d_mutex_unlock();
|
---|
1404 | WARN("Surface is not a render target, or not a stand-alone D3DPOOL_DEFAULT surface\n");
|
---|
1405 | return D3DERR_INVALIDCALL;
|
---|
1406 | }
|
---|
1407 |
|
---|
1408 | /* Colorfill can only be used on rendertarget surfaces, or offscreen plain surfaces in D3DPOOL_DEFAULT */
|
---|
1409 | hr = wined3d_device_color_fill(device->wined3d_device, surface_impl->wined3d_surface, rect, &c);
|
---|
1410 |
|
---|
1411 | wined3d_mutex_unlock();
|
---|
1412 |
|
---|
1413 | return hr;
|
---|
1414 | }
|
---|
1415 |
|
---|
1416 | static HRESULT WINAPI d3d9_device_CreateOffscreenPlainSurface(IDirect3DDevice9Ex *iface,
|
---|
1417 | UINT width, UINT height, D3DFORMAT format, D3DPOOL pool, IDirect3DSurface9 **surface,
|
---|
1418 | HANDLE *shared_handle)
|
---|
1419 | {
|
---|
1420 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
1421 |
|
---|
1422 | TRACE("iface %p, width %u, height %u, format %#x, pool %#x, surface %p, shared_handle %p.\n",
|
---|
1423 | iface, width, height, format, pool, surface, shared_handle);
|
---|
1424 |
|
---|
1425 | if (shared_handle)
|
---|
1426 | FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle);
|
---|
1427 |
|
---|
1428 | if (pool == D3DPOOL_MANAGED)
|
---|
1429 | {
|
---|
1430 | WARN("Attempting to create a managed offscreen plain surface.\n");
|
---|
1431 | return D3DERR_INVALIDCALL;
|
---|
1432 | }
|
---|
1433 | /* FIXME: Offscreen surfaces are supposed to be always lockable,
|
---|
1434 | * regardless of the pool they're created in. Should we set dynamic usage
|
---|
1435 | * here? */
|
---|
1436 | return d3d9_device_create_surface(device, width, height, format,
|
---|
1437 | WINED3D_SURFACE_MAPPABLE, surface, 0, pool, D3DMULTISAMPLE_NONE, 0
|
---|
1438 | #ifdef VBOX_WITH_WDDM
|
---|
1439 | , shared_handle
|
---|
1440 | , NULL
|
---|
1441 | #endif
|
---|
1442 | );
|
---|
1443 | }
|
---|
1444 |
|
---|
1445 | static HRESULT WINAPI d3d9_device_SetRenderTarget(IDirect3DDevice9Ex *iface, DWORD idx, IDirect3DSurface9 *surface)
|
---|
1446 | {
|
---|
1447 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
1448 | struct d3d9_surface *surface_impl = unsafe_impl_from_IDirect3DSurface9(surface);
|
---|
1449 | HRESULT hr;
|
---|
1450 |
|
---|
1451 | TRACE("iface %p, idx %u, surface %p.\n", iface, idx, surface);
|
---|
1452 |
|
---|
1453 | if (idx >= D3D9_MAX_SIMULTANEOUS_RENDERTARGETS)
|
---|
1454 | {
|
---|
1455 | WARN("Invalid index %u specified.\n", idx);
|
---|
1456 | return D3DERR_INVALIDCALL;
|
---|
1457 | }
|
---|
1458 |
|
---|
1459 | wined3d_mutex_lock();
|
---|
1460 | hr = wined3d_device_set_render_target(device->wined3d_device, idx,
|
---|
1461 | surface_impl ? surface_impl->wined3d_surface : NULL, TRUE);
|
---|
1462 | wined3d_mutex_unlock();
|
---|
1463 |
|
---|
1464 | return hr;
|
---|
1465 | }
|
---|
1466 |
|
---|
1467 | static HRESULT WINAPI d3d9_device_GetRenderTarget(IDirect3DDevice9Ex *iface, DWORD idx, IDirect3DSurface9 **surface)
|
---|
1468 | {
|
---|
1469 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
1470 | struct wined3d_surface *wined3d_surface;
|
---|
1471 | struct d3d9_surface *surface_impl;
|
---|
1472 | HRESULT hr = D3D_OK;
|
---|
1473 |
|
---|
1474 | TRACE("iface %p, idx %u, surface %p.\n", iface, idx, surface);
|
---|
1475 |
|
---|
1476 | if (!surface)
|
---|
1477 | return D3DERR_INVALIDCALL;
|
---|
1478 |
|
---|
1479 | if (idx >= D3D9_MAX_SIMULTANEOUS_RENDERTARGETS)
|
---|
1480 | {
|
---|
1481 | WARN("Invalid index %u specified.\n", idx);
|
---|
1482 | return D3DERR_INVALIDCALL;
|
---|
1483 | }
|
---|
1484 |
|
---|
1485 | wined3d_mutex_lock();
|
---|
1486 | if ((wined3d_surface = wined3d_device_get_render_target(device->wined3d_device, idx)))
|
---|
1487 | {
|
---|
1488 | surface_impl = wined3d_surface_get_parent(wined3d_surface);
|
---|
1489 | *surface = &surface_impl->IDirect3DSurface9_iface;
|
---|
1490 | IDirect3DSurface9_AddRef(*surface);
|
---|
1491 | }
|
---|
1492 | else
|
---|
1493 | {
|
---|
1494 | hr = WINED3DERR_NOTFOUND;
|
---|
1495 | *surface = NULL;
|
---|
1496 | }
|
---|
1497 | wined3d_mutex_unlock();
|
---|
1498 |
|
---|
1499 | return hr;
|
---|
1500 | }
|
---|
1501 |
|
---|
1502 | static HRESULT WINAPI d3d9_device_SetDepthStencilSurface(IDirect3DDevice9Ex *iface, IDirect3DSurface9 *depth_stencil)
|
---|
1503 | {
|
---|
1504 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
1505 | struct d3d9_surface *ds_impl = unsafe_impl_from_IDirect3DSurface9(depth_stencil);
|
---|
1506 |
|
---|
1507 | TRACE("iface %p, depth_stencil %p.\n", iface, depth_stencil);
|
---|
1508 |
|
---|
1509 | wined3d_mutex_lock();
|
---|
1510 | wined3d_device_set_depth_stencil(device->wined3d_device, ds_impl ? ds_impl->wined3d_surface : NULL);
|
---|
1511 | wined3d_mutex_unlock();
|
---|
1512 |
|
---|
1513 | return D3D_OK;
|
---|
1514 | }
|
---|
1515 |
|
---|
1516 | static HRESULT WINAPI d3d9_device_GetDepthStencilSurface(IDirect3DDevice9Ex *iface, IDirect3DSurface9 **depth_stencil)
|
---|
1517 | {
|
---|
1518 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
1519 | struct wined3d_surface *wined3d_surface;
|
---|
1520 | struct d3d9_surface *surface_impl;
|
---|
1521 | HRESULT hr = D3D_OK;
|
---|
1522 |
|
---|
1523 | TRACE("iface %p, depth_stencil %p.\n", iface, depth_stencil);
|
---|
1524 |
|
---|
1525 | if (!depth_stencil)
|
---|
1526 | return D3DERR_INVALIDCALL;
|
---|
1527 |
|
---|
1528 | wined3d_mutex_lock();
|
---|
1529 | if ((wined3d_surface = wined3d_device_get_depth_stencil(device->wined3d_device)))
|
---|
1530 | {
|
---|
1531 | surface_impl = wined3d_surface_get_parent(wined3d_surface);
|
---|
1532 | *depth_stencil = &surface_impl->IDirect3DSurface9_iface;
|
---|
1533 | IDirect3DSurface9_AddRef(*depth_stencil);
|
---|
1534 | }
|
---|
1535 | else
|
---|
1536 | {
|
---|
1537 | hr = WINED3DERR_NOTFOUND;
|
---|
1538 | *depth_stencil = NULL;
|
---|
1539 | }
|
---|
1540 | wined3d_mutex_unlock();
|
---|
1541 |
|
---|
1542 | return hr;
|
---|
1543 | }
|
---|
1544 |
|
---|
1545 | static HRESULT WINAPI d3d9_device_BeginScene(IDirect3DDevice9Ex *iface)
|
---|
1546 | {
|
---|
1547 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
1548 | HRESULT hr;
|
---|
1549 |
|
---|
1550 | TRACE("iface %p.\n", iface);
|
---|
1551 |
|
---|
1552 | wined3d_mutex_lock();
|
---|
1553 | if (SUCCEEDED(hr = wined3d_device_begin_scene(device->wined3d_device)))
|
---|
1554 | device->in_scene = TRUE;
|
---|
1555 | wined3d_mutex_unlock();
|
---|
1556 |
|
---|
1557 | return hr;
|
---|
1558 | }
|
---|
1559 |
|
---|
1560 | static HRESULT WINAPI DECLSPEC_HOTPATCH d3d9_device_EndScene(IDirect3DDevice9Ex *iface)
|
---|
1561 | {
|
---|
1562 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
1563 | HRESULT hr;
|
---|
1564 |
|
---|
1565 | TRACE("iface %p.\n", iface);
|
---|
1566 |
|
---|
1567 | wined3d_mutex_lock();
|
---|
1568 | if (SUCCEEDED(hr = wined3d_device_end_scene(device->wined3d_device)))
|
---|
1569 | device->in_scene = FALSE;
|
---|
1570 | wined3d_mutex_unlock();
|
---|
1571 |
|
---|
1572 | return hr;
|
---|
1573 | }
|
---|
1574 |
|
---|
1575 | static HRESULT WINAPI d3d9_device_Clear(IDirect3DDevice9Ex *iface, DWORD rect_count,
|
---|
1576 | const D3DRECT *rects, DWORD flags, D3DCOLOR color, float z, DWORD stencil)
|
---|
1577 | {
|
---|
1578 | const struct wined3d_color c =
|
---|
1579 | {
|
---|
1580 | ((color >> 16) & 0xff) / 255.0f,
|
---|
1581 | ((color >> 8) & 0xff) / 255.0f,
|
---|
1582 | (color & 0xff) / 255.0f,
|
---|
1583 | ((color >> 24) & 0xff) / 255.0f,
|
---|
1584 | };
|
---|
1585 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
1586 | HRESULT hr;
|
---|
1587 |
|
---|
1588 | TRACE("iface %p, rect_count %u, rects %p, flags %#x, color 0x%08x, z %.8e, stencil %u.\n",
|
---|
1589 | iface, rect_count, rects, flags, color, z, stencil);
|
---|
1590 |
|
---|
1591 | wined3d_mutex_lock();
|
---|
1592 | hr = wined3d_device_clear(device->wined3d_device, rect_count, (const RECT *)rects, flags, &c, z, stencil);
|
---|
1593 | wined3d_mutex_unlock();
|
---|
1594 |
|
---|
1595 | return hr;
|
---|
1596 | }
|
---|
1597 |
|
---|
1598 | static HRESULT WINAPI d3d9_device_SetTransform(IDirect3DDevice9Ex *iface,
|
---|
1599 | D3DTRANSFORMSTATETYPE state, const D3DMATRIX *matrix)
|
---|
1600 | {
|
---|
1601 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
1602 |
|
---|
1603 | TRACE("iface %p, state %#x, matrix %p.\n", iface, state, matrix);
|
---|
1604 |
|
---|
1605 | /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
|
---|
1606 | wined3d_mutex_lock();
|
---|
1607 | wined3d_device_set_transform(device->wined3d_device, state, (const struct wined3d_matrix *)matrix);
|
---|
1608 | wined3d_mutex_unlock();
|
---|
1609 |
|
---|
1610 | return D3D_OK;
|
---|
1611 | }
|
---|
1612 |
|
---|
1613 | static HRESULT WINAPI d3d9_device_GetTransform(IDirect3DDevice9Ex *iface,
|
---|
1614 | D3DTRANSFORMSTATETYPE state, D3DMATRIX *matrix)
|
---|
1615 | {
|
---|
1616 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
1617 |
|
---|
1618 | TRACE("iface %p, state %#x, matrix %p.\n", iface, state, matrix);
|
---|
1619 |
|
---|
1620 | /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
|
---|
1621 | wined3d_mutex_lock();
|
---|
1622 | wined3d_device_get_transform(device->wined3d_device, state, (struct wined3d_matrix *)matrix);
|
---|
1623 | wined3d_mutex_unlock();
|
---|
1624 |
|
---|
1625 | return D3D_OK;
|
---|
1626 | }
|
---|
1627 |
|
---|
1628 | static HRESULT WINAPI d3d9_device_MultiplyTransform(IDirect3DDevice9Ex *iface,
|
---|
1629 | D3DTRANSFORMSTATETYPE state, const D3DMATRIX *matrix)
|
---|
1630 | {
|
---|
1631 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
1632 |
|
---|
1633 | TRACE("iface %p, state %#x, matrix %p.\n", iface, state, matrix);
|
---|
1634 |
|
---|
1635 | /* Note: D3DMATRIX is compatible with struct wined3d_matrix. */
|
---|
1636 | wined3d_mutex_lock();
|
---|
1637 | wined3d_device_multiply_transform(device->wined3d_device, state, (const struct wined3d_matrix *)matrix);
|
---|
1638 | wined3d_mutex_unlock();
|
---|
1639 |
|
---|
1640 | return D3D_OK;
|
---|
1641 | }
|
---|
1642 |
|
---|
1643 | static HRESULT WINAPI d3d9_device_SetViewport(IDirect3DDevice9Ex *iface, const D3DVIEWPORT9 *viewport)
|
---|
1644 | {
|
---|
1645 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
1646 |
|
---|
1647 | TRACE("iface %p, viewport %p.\n", iface, viewport);
|
---|
1648 |
|
---|
1649 | /* Note: D3DVIEWPORT9 is compatible with struct wined3d_viewport. */
|
---|
1650 | wined3d_mutex_lock();
|
---|
1651 | wined3d_device_set_viewport(device->wined3d_device, (const struct wined3d_viewport *)viewport);
|
---|
1652 | wined3d_mutex_unlock();
|
---|
1653 |
|
---|
1654 | return D3D_OK;
|
---|
1655 | }
|
---|
1656 |
|
---|
1657 | static HRESULT WINAPI d3d9_device_GetViewport(IDirect3DDevice9Ex *iface, D3DVIEWPORT9 *viewport)
|
---|
1658 | {
|
---|
1659 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
1660 |
|
---|
1661 | TRACE("iface %p, viewport %p.\n", iface, viewport);
|
---|
1662 |
|
---|
1663 | /* Note: D3DVIEWPORT9 is compatible with struct wined3d_viewport. */
|
---|
1664 | wined3d_mutex_lock();
|
---|
1665 | wined3d_device_get_viewport(device->wined3d_device, (struct wined3d_viewport *)viewport);
|
---|
1666 | wined3d_mutex_unlock();
|
---|
1667 |
|
---|
1668 | return D3D_OK;
|
---|
1669 | }
|
---|
1670 |
|
---|
1671 | static HRESULT WINAPI d3d9_device_SetMaterial(IDirect3DDevice9Ex *iface, const D3DMATERIAL9 *material)
|
---|
1672 | {
|
---|
1673 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
1674 |
|
---|
1675 | TRACE("iface %p, material %p.\n", iface, material);
|
---|
1676 |
|
---|
1677 | /* Note: D3DMATERIAL9 is compatible with struct wined3d_material. */
|
---|
1678 | wined3d_mutex_lock();
|
---|
1679 | wined3d_device_set_material(device->wined3d_device, (const struct wined3d_material *)material);
|
---|
1680 | wined3d_mutex_unlock();
|
---|
1681 |
|
---|
1682 | return D3D_OK;
|
---|
1683 | }
|
---|
1684 |
|
---|
1685 | static HRESULT WINAPI d3d9_device_GetMaterial(IDirect3DDevice9Ex *iface, D3DMATERIAL9 *material)
|
---|
1686 | {
|
---|
1687 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
1688 |
|
---|
1689 | TRACE("iface %p, material %p.\n", iface, material);
|
---|
1690 |
|
---|
1691 | /* Note: D3DMATERIAL9 is compatible with struct wined3d_material. */
|
---|
1692 | wined3d_mutex_lock();
|
---|
1693 | wined3d_device_get_material(device->wined3d_device, (struct wined3d_material *)material);
|
---|
1694 | wined3d_mutex_unlock();
|
---|
1695 |
|
---|
1696 | return D3D_OK;
|
---|
1697 | }
|
---|
1698 |
|
---|
1699 | static HRESULT WINAPI d3d9_device_SetLight(IDirect3DDevice9Ex *iface, DWORD index, const D3DLIGHT9 *light)
|
---|
1700 | {
|
---|
1701 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
1702 | HRESULT hr;
|
---|
1703 |
|
---|
1704 | TRACE("iface %p, index %u, light %p.\n", iface, index, light);
|
---|
1705 |
|
---|
1706 | /* Note: D3DLIGHT9 is compatible with struct wined3d_light. */
|
---|
1707 | wined3d_mutex_lock();
|
---|
1708 | hr = wined3d_device_set_light(device->wined3d_device, index, (const struct wined3d_light *)light);
|
---|
1709 | wined3d_mutex_unlock();
|
---|
1710 |
|
---|
1711 | return hr;
|
---|
1712 | }
|
---|
1713 |
|
---|
1714 | static HRESULT WINAPI d3d9_device_GetLight(IDirect3DDevice9Ex *iface, DWORD index, D3DLIGHT9 *light)
|
---|
1715 | {
|
---|
1716 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
1717 | HRESULT hr;
|
---|
1718 |
|
---|
1719 | TRACE("iface %p, index %u, light %p.\n", iface, index, light);
|
---|
1720 |
|
---|
1721 | /* Note: D3DLIGHT9 is compatible with struct wined3d_light. */
|
---|
1722 | wined3d_mutex_lock();
|
---|
1723 | hr = wined3d_device_get_light(device->wined3d_device, index, (struct wined3d_light *)light);
|
---|
1724 | wined3d_mutex_unlock();
|
---|
1725 |
|
---|
1726 | return hr;
|
---|
1727 | }
|
---|
1728 |
|
---|
1729 | static HRESULT WINAPI d3d9_device_LightEnable(IDirect3DDevice9Ex *iface, DWORD index, BOOL enable)
|
---|
1730 | {
|
---|
1731 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
1732 | HRESULT hr;
|
---|
1733 |
|
---|
1734 | TRACE("iface %p, index %u, enable %#x.\n", iface, index, enable);
|
---|
1735 |
|
---|
1736 | wined3d_mutex_lock();
|
---|
1737 | hr = wined3d_device_set_light_enable(device->wined3d_device, index, enable);
|
---|
1738 | wined3d_mutex_unlock();
|
---|
1739 |
|
---|
1740 | return hr;
|
---|
1741 | }
|
---|
1742 |
|
---|
1743 | static HRESULT WINAPI d3d9_device_GetLightEnable(IDirect3DDevice9Ex *iface, DWORD index, BOOL *enable)
|
---|
1744 | {
|
---|
1745 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
1746 | HRESULT hr;
|
---|
1747 |
|
---|
1748 | TRACE("iface %p, index %u, enable %p.\n", iface, index, enable);
|
---|
1749 |
|
---|
1750 | wined3d_mutex_lock();
|
---|
1751 | hr = wined3d_device_get_light_enable(device->wined3d_device, index, enable);
|
---|
1752 | wined3d_mutex_unlock();
|
---|
1753 |
|
---|
1754 | return hr;
|
---|
1755 | }
|
---|
1756 |
|
---|
1757 | static HRESULT WINAPI d3d9_device_SetClipPlane(IDirect3DDevice9Ex *iface, DWORD index, const float *plane)
|
---|
1758 | {
|
---|
1759 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
1760 | HRESULT hr;
|
---|
1761 |
|
---|
1762 | TRACE("iface %p, index %u, plane %p.\n", iface, index, plane);
|
---|
1763 |
|
---|
1764 | wined3d_mutex_lock();
|
---|
1765 | hr = wined3d_device_set_clip_plane(device->wined3d_device, index, (const struct wined3d_vec4 *)plane);
|
---|
1766 | wined3d_mutex_unlock();
|
---|
1767 |
|
---|
1768 | return hr;
|
---|
1769 | }
|
---|
1770 |
|
---|
1771 | static HRESULT WINAPI d3d9_device_GetClipPlane(IDirect3DDevice9Ex *iface, DWORD index, float *plane)
|
---|
1772 | {
|
---|
1773 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
1774 | HRESULT hr;
|
---|
1775 |
|
---|
1776 | TRACE("iface %p, index %u, plane %p.\n", iface, index, plane);
|
---|
1777 |
|
---|
1778 | wined3d_mutex_lock();
|
---|
1779 | hr = wined3d_device_get_clip_plane(device->wined3d_device, index, (struct wined3d_vec4 *)plane);
|
---|
1780 | wined3d_mutex_unlock();
|
---|
1781 |
|
---|
1782 | return hr;
|
---|
1783 | }
|
---|
1784 |
|
---|
1785 | static HRESULT WINAPI DECLSPEC_HOTPATCH d3d9_device_SetRenderState(IDirect3DDevice9Ex *iface,
|
---|
1786 | D3DRENDERSTATETYPE state, DWORD value)
|
---|
1787 | {
|
---|
1788 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
1789 |
|
---|
1790 | TRACE("iface %p, state %#x, value %#x.\n", iface, state, value);
|
---|
1791 |
|
---|
1792 | wined3d_mutex_lock();
|
---|
1793 | wined3d_device_set_render_state(device->wined3d_device, state, value);
|
---|
1794 | wined3d_mutex_unlock();
|
---|
1795 |
|
---|
1796 | return D3D_OK;
|
---|
1797 | }
|
---|
1798 |
|
---|
1799 | static HRESULT WINAPI d3d9_device_GetRenderState(IDirect3DDevice9Ex *iface,
|
---|
1800 | D3DRENDERSTATETYPE state, DWORD *value)
|
---|
1801 | {
|
---|
1802 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
1803 |
|
---|
1804 | TRACE("iface %p, state %#x, value %p.\n", iface, state, value);
|
---|
1805 |
|
---|
1806 | wined3d_mutex_lock();
|
---|
1807 | *value = wined3d_device_get_render_state(device->wined3d_device, state);
|
---|
1808 | wined3d_mutex_unlock();
|
---|
1809 |
|
---|
1810 | return D3D_OK;
|
---|
1811 | }
|
---|
1812 |
|
---|
1813 | static HRESULT WINAPI d3d9_device_CreateStateBlock(IDirect3DDevice9Ex *iface,
|
---|
1814 | D3DSTATEBLOCKTYPE type, IDirect3DStateBlock9 **stateblock)
|
---|
1815 | {
|
---|
1816 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
1817 | struct d3d9_stateblock *object;
|
---|
1818 | HRESULT hr;
|
---|
1819 |
|
---|
1820 | TRACE("iface %p, type %#x, stateblock %p.\n", iface, type, stateblock);
|
---|
1821 |
|
---|
1822 | if (type != D3DSBT_ALL && type != D3DSBT_PIXELSTATE && type != D3DSBT_VERTEXSTATE)
|
---|
1823 | {
|
---|
1824 | WARN("Unexpected stateblock type, returning D3DERR_INVALIDCALL.\n");
|
---|
1825 | return D3DERR_INVALIDCALL;
|
---|
1826 | }
|
---|
1827 |
|
---|
1828 | object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
|
---|
1829 | if (!object)
|
---|
1830 | return E_OUTOFMEMORY;
|
---|
1831 |
|
---|
1832 | hr = stateblock_init(object, device, type, NULL);
|
---|
1833 | if (FAILED(hr))
|
---|
1834 | {
|
---|
1835 | WARN("Failed to initialize stateblock, hr %#x.\n", hr);
|
---|
1836 | HeapFree(GetProcessHeap(), 0, object);
|
---|
1837 | return hr;
|
---|
1838 | }
|
---|
1839 |
|
---|
1840 | TRACE("Created stateblock %p.\n", object);
|
---|
1841 | *stateblock = &object->IDirect3DStateBlock9_iface;
|
---|
1842 |
|
---|
1843 | return D3D_OK;
|
---|
1844 | }
|
---|
1845 |
|
---|
1846 | static HRESULT WINAPI d3d9_device_BeginStateBlock(IDirect3DDevice9Ex *iface)
|
---|
1847 | {
|
---|
1848 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
1849 | HRESULT hr;
|
---|
1850 |
|
---|
1851 | TRACE("iface %p.\n", iface);
|
---|
1852 |
|
---|
1853 | wined3d_mutex_lock();
|
---|
1854 | hr = wined3d_device_begin_stateblock(device->wined3d_device);
|
---|
1855 | wined3d_mutex_unlock();
|
---|
1856 |
|
---|
1857 | return hr;
|
---|
1858 | }
|
---|
1859 |
|
---|
1860 | static HRESULT WINAPI d3d9_device_EndStateBlock(IDirect3DDevice9Ex *iface, IDirect3DStateBlock9 **stateblock)
|
---|
1861 | {
|
---|
1862 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
1863 | struct wined3d_stateblock *wined3d_stateblock;
|
---|
1864 | struct d3d9_stateblock *object;
|
---|
1865 | HRESULT hr;
|
---|
1866 |
|
---|
1867 | TRACE("iface %p, stateblock %p.\n", iface, stateblock);
|
---|
1868 |
|
---|
1869 | wined3d_mutex_lock();
|
---|
1870 | hr = wined3d_device_end_stateblock(device->wined3d_device, &wined3d_stateblock);
|
---|
1871 | wined3d_mutex_unlock();
|
---|
1872 | if (FAILED(hr))
|
---|
1873 | {
|
---|
1874 | WARN("IWineD3DDevice_EndStateBlock() failed, hr %#x.\n", hr);
|
---|
1875 | return hr;
|
---|
1876 | }
|
---|
1877 |
|
---|
1878 | object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
|
---|
1879 | if (!object)
|
---|
1880 | {
|
---|
1881 | wined3d_mutex_lock();
|
---|
1882 | wined3d_stateblock_decref(wined3d_stateblock);
|
---|
1883 | wined3d_mutex_unlock();
|
---|
1884 | return E_OUTOFMEMORY;
|
---|
1885 | }
|
---|
1886 |
|
---|
1887 | hr = stateblock_init(object, device, 0, wined3d_stateblock);
|
---|
1888 | if (FAILED(hr))
|
---|
1889 | {
|
---|
1890 | WARN("Failed to initialize stateblock, hr %#x.\n", hr);
|
---|
1891 | wined3d_mutex_lock();
|
---|
1892 | wined3d_stateblock_decref(wined3d_stateblock);
|
---|
1893 | wined3d_mutex_unlock();
|
---|
1894 | HeapFree(GetProcessHeap(), 0, object);
|
---|
1895 | return hr;
|
---|
1896 | }
|
---|
1897 |
|
---|
1898 | TRACE("Created stateblock %p.\n", object);
|
---|
1899 | *stateblock = &object->IDirect3DStateBlock9_iface;
|
---|
1900 |
|
---|
1901 | return D3D_OK;
|
---|
1902 | }
|
---|
1903 |
|
---|
1904 | static HRESULT WINAPI d3d9_device_SetClipStatus(IDirect3DDevice9Ex *iface, const D3DCLIPSTATUS9 *clip_status)
|
---|
1905 | {
|
---|
1906 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
1907 | HRESULT hr;
|
---|
1908 |
|
---|
1909 | TRACE("iface %p, clip_status %p.\n", iface, clip_status);
|
---|
1910 |
|
---|
1911 | wined3d_mutex_lock();
|
---|
1912 | hr = wined3d_device_set_clip_status(device->wined3d_device, (const struct wined3d_clip_status *)clip_status);
|
---|
1913 | wined3d_mutex_unlock();
|
---|
1914 |
|
---|
1915 | return hr;
|
---|
1916 | }
|
---|
1917 |
|
---|
1918 | static HRESULT WINAPI d3d9_device_GetClipStatus(IDirect3DDevice9Ex *iface, D3DCLIPSTATUS9 *clip_status)
|
---|
1919 | {
|
---|
1920 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
1921 | HRESULT hr;
|
---|
1922 |
|
---|
1923 | TRACE("iface %p, clip_status %p.\n", iface, clip_status);
|
---|
1924 |
|
---|
1925 | wined3d_mutex_lock();
|
---|
1926 | hr = wined3d_device_get_clip_status(device->wined3d_device, (struct wined3d_clip_status *)clip_status);
|
---|
1927 | wined3d_mutex_unlock();
|
---|
1928 |
|
---|
1929 | return hr;
|
---|
1930 | }
|
---|
1931 |
|
---|
1932 | static HRESULT WINAPI d3d9_device_GetTexture(IDirect3DDevice9Ex *iface, DWORD stage, IDirect3DBaseTexture9 **texture)
|
---|
1933 | {
|
---|
1934 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
1935 | struct wined3d_texture *wined3d_texture = NULL;
|
---|
1936 | struct d3d9_texture *texture_impl;
|
---|
1937 |
|
---|
1938 | TRACE("iface %p, stage %u, texture %p.\n", iface, stage, texture);
|
---|
1939 |
|
---|
1940 | if (!texture)
|
---|
1941 | return D3DERR_INVALIDCALL;
|
---|
1942 |
|
---|
1943 | wined3d_mutex_lock();
|
---|
1944 | if ((wined3d_texture = wined3d_device_get_texture(device->wined3d_device, stage)))
|
---|
1945 | {
|
---|
1946 | texture_impl = wined3d_texture_get_parent(wined3d_texture);
|
---|
1947 | *texture = &texture_impl->IDirect3DBaseTexture9_iface;
|
---|
1948 | IDirect3DBaseTexture9_AddRef(*texture);
|
---|
1949 | }
|
---|
1950 | else
|
---|
1951 | {
|
---|
1952 | *texture = NULL;
|
---|
1953 | }
|
---|
1954 | wined3d_mutex_unlock();
|
---|
1955 |
|
---|
1956 | return D3D_OK;
|
---|
1957 | }
|
---|
1958 |
|
---|
1959 | static HRESULT WINAPI d3d9_device_SetTexture(IDirect3DDevice9Ex *iface, DWORD stage, IDirect3DBaseTexture9 *texture)
|
---|
1960 | {
|
---|
1961 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
1962 | struct d3d9_texture *texture_impl;
|
---|
1963 | HRESULT hr;
|
---|
1964 |
|
---|
1965 | TRACE("iface %p, stage %u, texture %p.\n", iface, stage, texture);
|
---|
1966 |
|
---|
1967 | texture_impl = unsafe_impl_from_IDirect3DBaseTexture9(texture);
|
---|
1968 |
|
---|
1969 | wined3d_mutex_lock();
|
---|
1970 | hr = wined3d_device_set_texture(device->wined3d_device, stage,
|
---|
1971 | texture_impl ? texture_impl->wined3d_texture : NULL);
|
---|
1972 | wined3d_mutex_unlock();
|
---|
1973 |
|
---|
1974 | return hr;
|
---|
1975 | }
|
---|
1976 |
|
---|
1977 | static const enum wined3d_texture_stage_state tss_lookup[] =
|
---|
1978 | {
|
---|
1979 | WINED3D_TSS_INVALID, /* 0, unused */
|
---|
1980 | WINED3D_TSS_COLOR_OP, /* 1, D3DTSS_COLOROP */
|
---|
1981 | WINED3D_TSS_COLOR_ARG1, /* 2, D3DTSS_COLORARG1 */
|
---|
1982 | WINED3D_TSS_COLOR_ARG2, /* 3, D3DTSS_COLORARG2 */
|
---|
1983 | WINED3D_TSS_ALPHA_OP, /* 4, D3DTSS_ALPHAOP */
|
---|
1984 | WINED3D_TSS_ALPHA_ARG1, /* 5, D3DTSS_ALPHAARG1 */
|
---|
1985 | WINED3D_TSS_ALPHA_ARG2, /* 6, D3DTSS_ALPHAARG2 */
|
---|
1986 | WINED3D_TSS_BUMPENV_MAT00, /* 7, D3DTSS_BUMPENVMAT00 */
|
---|
1987 | WINED3D_TSS_BUMPENV_MAT01, /* 8, D3DTSS_BUMPENVMAT01 */
|
---|
1988 | WINED3D_TSS_BUMPENV_MAT10, /* 9, D3DTSS_BUMPENVMAT10 */
|
---|
1989 | WINED3D_TSS_BUMPENV_MAT11, /* 10, D3DTSS_BUMPENVMAT11 */
|
---|
1990 | WINED3D_TSS_TEXCOORD_INDEX, /* 11, D3DTSS_TEXCOORDINDEX */
|
---|
1991 | WINED3D_TSS_INVALID, /* 12, unused */
|
---|
1992 | WINED3D_TSS_INVALID, /* 13, unused */
|
---|
1993 | WINED3D_TSS_INVALID, /* 14, unused */
|
---|
1994 | WINED3D_TSS_INVALID, /* 15, unused */
|
---|
1995 | WINED3D_TSS_INVALID, /* 16, unused */
|
---|
1996 | WINED3D_TSS_INVALID, /* 17, unused */
|
---|
1997 | WINED3D_TSS_INVALID, /* 18, unused */
|
---|
1998 | WINED3D_TSS_INVALID, /* 19, unused */
|
---|
1999 | WINED3D_TSS_INVALID, /* 20, unused */
|
---|
2000 | WINED3D_TSS_INVALID, /* 21, unused */
|
---|
2001 | WINED3D_TSS_BUMPENV_LSCALE, /* 22, D3DTSS_BUMPENVLSCALE */
|
---|
2002 | WINED3D_TSS_BUMPENV_LOFFSET, /* 23, D3DTSS_BUMPENVLOFFSET */
|
---|
2003 | WINED3D_TSS_TEXTURE_TRANSFORM_FLAGS, /* 24, D3DTSS_TEXTURETRANSFORMFLAGS */
|
---|
2004 | WINED3D_TSS_INVALID, /* 25, unused */
|
---|
2005 | WINED3D_TSS_COLOR_ARG0, /* 26, D3DTSS_COLORARG0 */
|
---|
2006 | WINED3D_TSS_ALPHA_ARG0, /* 27, D3DTSS_ALPHAARG0 */
|
---|
2007 | WINED3D_TSS_RESULT_ARG, /* 28, D3DTSS_RESULTARG */
|
---|
2008 | WINED3D_TSS_INVALID, /* 29, unused */
|
---|
2009 | WINED3D_TSS_INVALID, /* 30, unused */
|
---|
2010 | WINED3D_TSS_INVALID, /* 31, unused */
|
---|
2011 | WINED3D_TSS_CONSTANT, /* 32, D3DTSS_CONSTANT */
|
---|
2012 | };
|
---|
2013 |
|
---|
2014 | static HRESULT WINAPI d3d9_device_GetTextureStageState(IDirect3DDevice9Ex *iface,
|
---|
2015 | DWORD stage, D3DTEXTURESTAGESTATETYPE state, DWORD *value)
|
---|
2016 | {
|
---|
2017 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
2018 |
|
---|
2019 | TRACE("iface %p, stage %u, state %#x, value %p.\n", iface, stage, state, value);
|
---|
2020 |
|
---|
2021 | if (state >= sizeof(tss_lookup) / sizeof(*tss_lookup))
|
---|
2022 | {
|
---|
2023 | WARN("Invalid state %#x passed.\n", state);
|
---|
2024 | return D3D_OK;
|
---|
2025 | }
|
---|
2026 |
|
---|
2027 | wined3d_mutex_lock();
|
---|
2028 | *value = wined3d_device_get_texture_stage_state(device->wined3d_device, stage, tss_lookup[state]);
|
---|
2029 | wined3d_mutex_unlock();
|
---|
2030 |
|
---|
2031 | return D3D_OK;
|
---|
2032 | }
|
---|
2033 |
|
---|
2034 | static HRESULT WINAPI d3d9_device_SetTextureStageState(IDirect3DDevice9Ex *iface,
|
---|
2035 | DWORD stage, D3DTEXTURESTAGESTATETYPE state, DWORD value)
|
---|
2036 | {
|
---|
2037 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
2038 |
|
---|
2039 | TRACE("iface %p, stage %u, state %#x, value %#x.\n", iface, stage, state, value);
|
---|
2040 |
|
---|
2041 | if (state >= sizeof(tss_lookup) / sizeof(*tss_lookup))
|
---|
2042 | {
|
---|
2043 | WARN("Invalid state %#x passed.\n", state);
|
---|
2044 | return D3D_OK;
|
---|
2045 | }
|
---|
2046 |
|
---|
2047 | wined3d_mutex_lock();
|
---|
2048 | wined3d_device_set_texture_stage_state(device->wined3d_device, stage, tss_lookup[state], value);
|
---|
2049 | wined3d_mutex_unlock();
|
---|
2050 |
|
---|
2051 | return D3D_OK;
|
---|
2052 | }
|
---|
2053 |
|
---|
2054 | static HRESULT WINAPI d3d9_device_GetSamplerState(IDirect3DDevice9Ex *iface,
|
---|
2055 | DWORD sampler, D3DSAMPLERSTATETYPE state, DWORD *value)
|
---|
2056 | {
|
---|
2057 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
2058 |
|
---|
2059 | TRACE("iface %p, sampler %u, state %#x, value %p.\n", iface, sampler, state, value);
|
---|
2060 |
|
---|
2061 | wined3d_mutex_lock();
|
---|
2062 | *value = wined3d_device_get_sampler_state(device->wined3d_device, sampler, state);
|
---|
2063 | wined3d_mutex_unlock();
|
---|
2064 |
|
---|
2065 | return D3D_OK;
|
---|
2066 | }
|
---|
2067 |
|
---|
2068 | static HRESULT WINAPI DECLSPEC_HOTPATCH d3d9_device_SetSamplerState(IDirect3DDevice9Ex *iface,
|
---|
2069 | DWORD sampler, D3DSAMPLERSTATETYPE state, DWORD value)
|
---|
2070 | {
|
---|
2071 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
2072 |
|
---|
2073 | TRACE("iface %p, sampler %u, state %#x, value %#x.\n", iface, sampler, state, value);
|
---|
2074 |
|
---|
2075 | wined3d_mutex_lock();
|
---|
2076 | wined3d_device_set_sampler_state(device->wined3d_device, sampler, state, value);
|
---|
2077 | wined3d_mutex_unlock();
|
---|
2078 |
|
---|
2079 | return D3D_OK;
|
---|
2080 | }
|
---|
2081 |
|
---|
2082 | static HRESULT WINAPI d3d9_device_ValidateDevice(IDirect3DDevice9Ex *iface, DWORD *pass_count)
|
---|
2083 | {
|
---|
2084 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
2085 | HRESULT hr;
|
---|
2086 |
|
---|
2087 | TRACE("iface %p, pass_count %p.\n", iface, pass_count);
|
---|
2088 |
|
---|
2089 | wined3d_mutex_lock();
|
---|
2090 | hr = wined3d_device_validate_device(device->wined3d_device, pass_count);
|
---|
2091 | wined3d_mutex_unlock();
|
---|
2092 |
|
---|
2093 | return hr;
|
---|
2094 | }
|
---|
2095 |
|
---|
2096 | static HRESULT WINAPI d3d9_device_SetPaletteEntries(IDirect3DDevice9Ex *iface,
|
---|
2097 | UINT palette_idx, const PALETTEENTRY *entries)
|
---|
2098 | {
|
---|
2099 | WARN("iface %p, palette_idx %u, entries %p unimplemented.\n", iface, palette_idx, entries);
|
---|
2100 |
|
---|
2101 | /* The d3d9 palette API is non-functional on Windows. Getters and setters are implemented,
|
---|
2102 | * and some drivers allow the creation of P8 surfaces. These surfaces can be copied to
|
---|
2103 | * other P8 surfaces with StretchRect, but cannot be converted to (A)RGB.
|
---|
2104 | *
|
---|
2105 | * Some older(dx7) cards may have support for P8 textures, but games cannot rely on this. */
|
---|
2106 | return D3D_OK;
|
---|
2107 | }
|
---|
2108 |
|
---|
2109 | static HRESULT WINAPI d3d9_device_GetPaletteEntries(IDirect3DDevice9Ex *iface,
|
---|
2110 | UINT palette_idx, PALETTEENTRY *entries)
|
---|
2111 | {
|
---|
2112 | FIXME("iface %p, palette_idx %u, entries %p unimplemented.\n", iface, palette_idx, entries);
|
---|
2113 |
|
---|
2114 | return D3DERR_INVALIDCALL;
|
---|
2115 | }
|
---|
2116 |
|
---|
2117 | static HRESULT WINAPI d3d9_device_SetCurrentTexturePalette(IDirect3DDevice9Ex *iface, UINT palette_idx)
|
---|
2118 | {
|
---|
2119 | WARN("iface %p, palette_idx %u unimplemented.\n", iface, palette_idx);
|
---|
2120 |
|
---|
2121 | return D3D_OK;
|
---|
2122 | }
|
---|
2123 |
|
---|
2124 | static HRESULT WINAPI d3d9_device_GetCurrentTexturePalette(IDirect3DDevice9Ex *iface, UINT *palette_idx)
|
---|
2125 | {
|
---|
2126 | FIXME("iface %p, palette_idx %p.\n", iface, palette_idx);
|
---|
2127 |
|
---|
2128 | return D3DERR_INVALIDCALL;
|
---|
2129 | }
|
---|
2130 |
|
---|
2131 | static HRESULT WINAPI d3d9_device_SetScissorRect(IDirect3DDevice9Ex *iface, const RECT *rect)
|
---|
2132 | {
|
---|
2133 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
2134 |
|
---|
2135 | TRACE("iface %p, rect %p.\n", iface, rect);
|
---|
2136 |
|
---|
2137 | wined3d_mutex_lock();
|
---|
2138 | wined3d_device_set_scissor_rect(device->wined3d_device, rect);
|
---|
2139 | wined3d_mutex_unlock();
|
---|
2140 |
|
---|
2141 | return D3D_OK;
|
---|
2142 | }
|
---|
2143 |
|
---|
2144 | static HRESULT WINAPI d3d9_device_GetScissorRect(IDirect3DDevice9Ex *iface, RECT *rect)
|
---|
2145 | {
|
---|
2146 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
2147 |
|
---|
2148 | TRACE("iface %p, rect %p.\n", iface, rect);
|
---|
2149 |
|
---|
2150 | wined3d_mutex_lock();
|
---|
2151 | wined3d_device_get_scissor_rect(device->wined3d_device, rect);
|
---|
2152 | wined3d_mutex_unlock();
|
---|
2153 |
|
---|
2154 | return D3D_OK;
|
---|
2155 | }
|
---|
2156 |
|
---|
2157 | static HRESULT WINAPI d3d9_device_SetSoftwareVertexProcessing(IDirect3DDevice9Ex *iface, BOOL software)
|
---|
2158 | {
|
---|
2159 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
2160 |
|
---|
2161 | TRACE("iface %p, software %#x.\n", iface, software);
|
---|
2162 |
|
---|
2163 | wined3d_mutex_lock();
|
---|
2164 | wined3d_device_set_software_vertex_processing(device->wined3d_device, software);
|
---|
2165 | wined3d_mutex_unlock();
|
---|
2166 |
|
---|
2167 | return D3D_OK;
|
---|
2168 | }
|
---|
2169 |
|
---|
2170 | static BOOL WINAPI d3d9_device_GetSoftwareVertexProcessing(IDirect3DDevice9Ex *iface)
|
---|
2171 | {
|
---|
2172 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
2173 | BOOL ret;
|
---|
2174 |
|
---|
2175 | TRACE("iface %p.\n", iface);
|
---|
2176 |
|
---|
2177 | wined3d_mutex_lock();
|
---|
2178 | ret = wined3d_device_get_software_vertex_processing(device->wined3d_device);
|
---|
2179 | wined3d_mutex_unlock();
|
---|
2180 |
|
---|
2181 | return ret;
|
---|
2182 | }
|
---|
2183 |
|
---|
2184 | static HRESULT WINAPI d3d9_device_SetNPatchMode(IDirect3DDevice9Ex *iface, float segment_count)
|
---|
2185 | {
|
---|
2186 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
2187 | HRESULT hr;
|
---|
2188 |
|
---|
2189 | TRACE("iface %p, segment_count %.8e.\n", iface, segment_count);
|
---|
2190 |
|
---|
2191 | wined3d_mutex_lock();
|
---|
2192 | hr = wined3d_device_set_npatch_mode(device->wined3d_device, segment_count);
|
---|
2193 | wined3d_mutex_unlock();
|
---|
2194 |
|
---|
2195 | return hr;
|
---|
2196 | }
|
---|
2197 |
|
---|
2198 | static float WINAPI d3d9_device_GetNPatchMode(IDirect3DDevice9Ex *iface)
|
---|
2199 | {
|
---|
2200 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
2201 | float ret;
|
---|
2202 |
|
---|
2203 | TRACE("iface %p.\n", iface);
|
---|
2204 |
|
---|
2205 | wined3d_mutex_lock();
|
---|
2206 | ret = wined3d_device_get_npatch_mode(device->wined3d_device);
|
---|
2207 | wined3d_mutex_unlock();
|
---|
2208 |
|
---|
2209 | return ret;
|
---|
2210 | }
|
---|
2211 |
|
---|
2212 | static HRESULT WINAPI d3d9_device_DrawPrimitive(IDirect3DDevice9Ex *iface,
|
---|
2213 | D3DPRIMITIVETYPE primitive_type, UINT start_vertex, UINT primitive_count)
|
---|
2214 | {
|
---|
2215 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
2216 | HRESULT hr;
|
---|
2217 |
|
---|
2218 | TRACE("iface %p, primitive_type %#x, start_vertex %u, primitive_count %u.\n",
|
---|
2219 | iface, primitive_type, start_vertex, primitive_count);
|
---|
2220 |
|
---|
2221 | wined3d_mutex_lock();
|
---|
2222 | wined3d_device_set_primitive_type(device->wined3d_device, primitive_type);
|
---|
2223 | hr = wined3d_device_draw_primitive(device->wined3d_device, start_vertex,
|
---|
2224 | vertex_count_from_primitive_count(primitive_type, primitive_count));
|
---|
2225 | wined3d_mutex_unlock();
|
---|
2226 |
|
---|
2227 | return hr;
|
---|
2228 | }
|
---|
2229 |
|
---|
2230 | static HRESULT WINAPI d3d9_device_DrawIndexedPrimitive(IDirect3DDevice9Ex *iface,
|
---|
2231 | D3DPRIMITIVETYPE primitive_type, INT base_vertex_idx, UINT min_vertex_idx,
|
---|
2232 | UINT vertex_count, UINT start_idx, UINT primitive_count)
|
---|
2233 | {
|
---|
2234 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
2235 | HRESULT hr;
|
---|
2236 |
|
---|
2237 | TRACE("iface %p, primitive_type %#x, base_vertex_idx %u, min_vertex_idx %u,\n"
|
---|
2238 | "vertex_count %u, start_idx %u, primitive_count %u.\n",
|
---|
2239 | iface, primitive_type, base_vertex_idx, min_vertex_idx,
|
---|
2240 | vertex_count, start_idx, primitive_count);
|
---|
2241 |
|
---|
2242 | wined3d_mutex_lock();
|
---|
2243 | wined3d_device_set_base_vertex_index(device->wined3d_device, base_vertex_idx);
|
---|
2244 | wined3d_device_set_primitive_type(device->wined3d_device, primitive_type);
|
---|
2245 | hr = wined3d_device_draw_indexed_primitive(device->wined3d_device, start_idx,
|
---|
2246 | vertex_count_from_primitive_count(primitive_type, primitive_count));
|
---|
2247 | wined3d_mutex_unlock();
|
---|
2248 |
|
---|
2249 | return hr;
|
---|
2250 | }
|
---|
2251 |
|
---|
2252 | static void STDMETHODCALLTYPE d3d9_null_wined3d_object_destroyed(void *parent) {}
|
---|
2253 |
|
---|
2254 | static const struct wined3d_parent_ops d3d9_null_wined3d_parent_ops =
|
---|
2255 | {
|
---|
2256 | d3d9_null_wined3d_object_destroyed,
|
---|
2257 | };
|
---|
2258 |
|
---|
2259 | /* The caller is responsible for wined3d locking */
|
---|
2260 | static HRESULT d3d9_device_prepare_vertex_buffer(struct d3d9_device *device, UINT min_size)
|
---|
2261 | {
|
---|
2262 | HRESULT hr;
|
---|
2263 |
|
---|
2264 | if (device->vertex_buffer_size < min_size || !device->vertex_buffer)
|
---|
2265 | {
|
---|
2266 | UINT size = max(device->vertex_buffer_size * 2, min_size);
|
---|
2267 | struct wined3d_buffer *buffer;
|
---|
2268 |
|
---|
2269 | TRACE("Growing vertex buffer to %u bytes\n", size);
|
---|
2270 |
|
---|
2271 | hr = wined3d_buffer_create_vb(device->wined3d_device, size, WINED3DUSAGE_DYNAMIC | WINED3DUSAGE_WRITEONLY,
|
---|
2272 | WINED3D_POOL_DEFAULT, NULL, &d3d9_null_wined3d_parent_ops, &buffer);
|
---|
2273 | if (FAILED(hr))
|
---|
2274 | {
|
---|
2275 | ERR("(%p) wined3d_buffer_create_vb failed with hr = %08x\n", device, hr);
|
---|
2276 | return hr;
|
---|
2277 | }
|
---|
2278 |
|
---|
2279 | if (device->vertex_buffer)
|
---|
2280 | wined3d_buffer_decref(device->vertex_buffer);
|
---|
2281 |
|
---|
2282 | device->vertex_buffer = buffer;
|
---|
2283 | device->vertex_buffer_size = size;
|
---|
2284 | device->vertex_buffer_pos = 0;
|
---|
2285 | }
|
---|
2286 | return D3D_OK;
|
---|
2287 | }
|
---|
2288 |
|
---|
2289 | static HRESULT WINAPI d3d9_device_DrawPrimitiveUP(IDirect3DDevice9Ex *iface,
|
---|
2290 | D3DPRIMITIVETYPE primitive_type, UINT primitive_count, const void *data, UINT stride)
|
---|
2291 | {
|
---|
2292 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
2293 | HRESULT hr;
|
---|
2294 | UINT vtx_count = vertex_count_from_primitive_count(primitive_type, primitive_count);
|
---|
2295 | UINT size = vtx_count * stride;
|
---|
2296 | UINT vb_pos, align;
|
---|
2297 | BYTE *buffer_data;
|
---|
2298 |
|
---|
2299 | TRACE("iface %p, primitive_type %#x, primitive_count %u, data %p, stride %u.\n",
|
---|
2300 | iface, primitive_type, primitive_count, data, stride);
|
---|
2301 |
|
---|
2302 | if (!primitive_count)
|
---|
2303 | {
|
---|
2304 | WARN("primitive_count is 0, returning D3D_OK\n");
|
---|
2305 | return D3D_OK;
|
---|
2306 | }
|
---|
2307 |
|
---|
2308 | wined3d_mutex_lock();
|
---|
2309 |
|
---|
2310 | hr = d3d9_device_prepare_vertex_buffer(device, size);
|
---|
2311 | if (FAILED(hr))
|
---|
2312 | goto done;
|
---|
2313 |
|
---|
2314 | vb_pos = device->vertex_buffer_pos;
|
---|
2315 | align = vb_pos % stride;
|
---|
2316 | if (align) align = stride - align;
|
---|
2317 | if (vb_pos + size + align > device->vertex_buffer_size)
|
---|
2318 | vb_pos = 0;
|
---|
2319 | else
|
---|
2320 | vb_pos += align;
|
---|
2321 |
|
---|
2322 | hr = wined3d_buffer_map(device->vertex_buffer, vb_pos, size, &buffer_data,
|
---|
2323 | vb_pos ? WINED3D_MAP_NOOVERWRITE : WINED3D_MAP_DISCARD);
|
---|
2324 | if (FAILED(hr))
|
---|
2325 | goto done;
|
---|
2326 | memcpy(buffer_data, data, size);
|
---|
2327 | wined3d_buffer_unmap(device->vertex_buffer);
|
---|
2328 | device->vertex_buffer_pos = vb_pos + size;
|
---|
2329 |
|
---|
2330 | hr = wined3d_device_set_stream_source(device->wined3d_device, 0, device->vertex_buffer, 0, stride);
|
---|
2331 | if (FAILED(hr))
|
---|
2332 | goto done;
|
---|
2333 |
|
---|
2334 | wined3d_device_set_primitive_type(device->wined3d_device, primitive_type);
|
---|
2335 | hr = wined3d_device_draw_primitive(device->wined3d_device, vb_pos / stride, vtx_count);
|
---|
2336 | wined3d_device_set_stream_source(device->wined3d_device, 0, NULL, 0, 0);
|
---|
2337 |
|
---|
2338 | done:
|
---|
2339 | wined3d_mutex_unlock();
|
---|
2340 | return hr;
|
---|
2341 | }
|
---|
2342 |
|
---|
2343 | /* The caller is responsible for wined3d locking */
|
---|
2344 | static HRESULT d3d9_device_prepare_index_buffer(struct d3d9_device *device, UINT min_size)
|
---|
2345 | {
|
---|
2346 | HRESULT hr;
|
---|
2347 |
|
---|
2348 | if (device->index_buffer_size < min_size || !device->index_buffer)
|
---|
2349 | {
|
---|
2350 | UINT size = max(device->index_buffer_size * 2, min_size);
|
---|
2351 | struct wined3d_buffer *buffer;
|
---|
2352 |
|
---|
2353 | TRACE("Growing index buffer to %u bytes\n", size);
|
---|
2354 |
|
---|
2355 | hr = wined3d_buffer_create_ib(device->wined3d_device, size, WINED3DUSAGE_DYNAMIC | WINED3DUSAGE_WRITEONLY,
|
---|
2356 | WINED3D_POOL_DEFAULT, NULL, &d3d9_null_wined3d_parent_ops, &buffer);
|
---|
2357 | if (FAILED(hr))
|
---|
2358 | {
|
---|
2359 | ERR("(%p) wined3d_buffer_create_ib failed with hr = %08x\n", device, hr);
|
---|
2360 | return hr;
|
---|
2361 | }
|
---|
2362 |
|
---|
2363 | if (device->index_buffer)
|
---|
2364 | wined3d_buffer_decref(device->index_buffer);
|
---|
2365 |
|
---|
2366 | device->index_buffer = buffer;
|
---|
2367 | device->index_buffer_size = size;
|
---|
2368 | device->index_buffer_pos = 0;
|
---|
2369 | }
|
---|
2370 | return D3D_OK;
|
---|
2371 | }
|
---|
2372 |
|
---|
2373 | static HRESULT WINAPI d3d9_device_DrawIndexedPrimitiveUP(IDirect3DDevice9Ex *iface,
|
---|
2374 | D3DPRIMITIVETYPE primitive_type, UINT min_vertex_idx, UINT vertex_count,
|
---|
2375 | UINT primitive_count, const void *index_data, D3DFORMAT index_format,
|
---|
2376 | const void *vertex_data, UINT vertex_stride)
|
---|
2377 | {
|
---|
2378 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
2379 | HRESULT hr;
|
---|
2380 | BYTE *buffer_data;
|
---|
2381 |
|
---|
2382 | UINT idx_count = vertex_count_from_primitive_count(primitive_type, primitive_count);
|
---|
2383 | UINT idx_fmt_size = index_format == D3DFMT_INDEX16 ? 2 : 4;
|
---|
2384 | UINT idx_size = idx_count * idx_fmt_size;
|
---|
2385 | UINT ib_pos;
|
---|
2386 |
|
---|
2387 | UINT vtx_size = vertex_count * vertex_stride;
|
---|
2388 | UINT vb_pos, align;
|
---|
2389 |
|
---|
2390 | TRACE("iface %p, primitive_type %#x, min_vertex_idx %u, vertex_count %u, primitive_count %u,\n"
|
---|
2391 | "index_data %p, index_format %#x, vertex_data %p, vertex_stride %u.\n",
|
---|
2392 | iface, primitive_type, min_vertex_idx, vertex_count, primitive_count,
|
---|
2393 | index_data, index_format, vertex_data, vertex_stride);
|
---|
2394 |
|
---|
2395 | if (!primitive_count)
|
---|
2396 | {
|
---|
2397 | WARN("primitive_count is 0, returning D3D_OK\n");
|
---|
2398 | return D3D_OK;
|
---|
2399 | }
|
---|
2400 |
|
---|
2401 | wined3d_mutex_lock();
|
---|
2402 |
|
---|
2403 | hr = d3d9_device_prepare_vertex_buffer(device, vtx_size);
|
---|
2404 | if (FAILED(hr))
|
---|
2405 | goto done;
|
---|
2406 |
|
---|
2407 | vb_pos = device->vertex_buffer_pos;
|
---|
2408 | align = vb_pos % vertex_stride;
|
---|
2409 | if (align) align = vertex_stride - align;
|
---|
2410 | if (vb_pos + vtx_size + align > device->vertex_buffer_size)
|
---|
2411 | vb_pos = 0;
|
---|
2412 | else
|
---|
2413 | vb_pos += align;
|
---|
2414 |
|
---|
2415 | hr = wined3d_buffer_map(device->vertex_buffer, vb_pos, vtx_size, &buffer_data,
|
---|
2416 | vb_pos ? WINED3D_MAP_NOOVERWRITE : WINED3D_MAP_DISCARD);
|
---|
2417 | if (FAILED(hr))
|
---|
2418 | goto done;
|
---|
2419 | memcpy(buffer_data, vertex_data, vtx_size);
|
---|
2420 | wined3d_buffer_unmap(device->vertex_buffer);
|
---|
2421 | device->vertex_buffer_pos = vb_pos + vtx_size;
|
---|
2422 |
|
---|
2423 | hr = d3d9_device_prepare_index_buffer(device, idx_size);
|
---|
2424 | if (FAILED(hr))
|
---|
2425 | goto done;
|
---|
2426 |
|
---|
2427 | ib_pos = device->index_buffer_pos;
|
---|
2428 | align = ib_pos % idx_fmt_size;
|
---|
2429 | if (align) align = idx_fmt_size - align;
|
---|
2430 | if (ib_pos + idx_size + align > device->index_buffer_size)
|
---|
2431 | ib_pos = 0;
|
---|
2432 | else
|
---|
2433 | ib_pos += align;
|
---|
2434 |
|
---|
2435 | hr = wined3d_buffer_map(device->index_buffer, ib_pos, idx_size, &buffer_data,
|
---|
2436 | ib_pos ? WINED3D_MAP_NOOVERWRITE : WINED3D_MAP_DISCARD);
|
---|
2437 | if (FAILED(hr))
|
---|
2438 | goto done;
|
---|
2439 | memcpy(buffer_data, index_data, idx_size);
|
---|
2440 | wined3d_buffer_unmap(device->index_buffer);
|
---|
2441 | device->index_buffer_pos = ib_pos + idx_size;
|
---|
2442 |
|
---|
2443 | hr = wined3d_device_set_stream_source(device->wined3d_device, 0, device->vertex_buffer, 0, vertex_stride);
|
---|
2444 | if (FAILED(hr))
|
---|
2445 | goto done;
|
---|
2446 |
|
---|
2447 | wined3d_device_set_index_buffer(device->wined3d_device, device->index_buffer,
|
---|
2448 | wined3dformat_from_d3dformat(index_format));
|
---|
2449 | wined3d_device_set_base_vertex_index(device->wined3d_device, vb_pos / vertex_stride);
|
---|
2450 |
|
---|
2451 | wined3d_device_set_primitive_type(device->wined3d_device, primitive_type);
|
---|
2452 | hr = wined3d_device_draw_indexed_primitive(device->wined3d_device, ib_pos / idx_fmt_size, idx_count);
|
---|
2453 |
|
---|
2454 | wined3d_device_set_stream_source(device->wined3d_device, 0, NULL, 0, 0);
|
---|
2455 | wined3d_device_set_index_buffer(device->wined3d_device, NULL, WINED3DFMT_UNKNOWN);
|
---|
2456 | wined3d_device_set_base_vertex_index(device->wined3d_device, 0);
|
---|
2457 |
|
---|
2458 | done:
|
---|
2459 | wined3d_mutex_unlock();
|
---|
2460 | return hr;
|
---|
2461 | }
|
---|
2462 |
|
---|
2463 | static HRESULT WINAPI d3d9_device_ProcessVertices(IDirect3DDevice9Ex *iface,
|
---|
2464 | UINT src_start_idx, UINT dst_idx, UINT vertex_count, IDirect3DVertexBuffer9 *dst_buffer,
|
---|
2465 | IDirect3DVertexDeclaration9 *declaration, DWORD flags)
|
---|
2466 | {
|
---|
2467 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
2468 | struct d3d9_vertexbuffer *dst_impl = unsafe_impl_from_IDirect3DVertexBuffer9(dst_buffer);
|
---|
2469 | struct d3d9_vertex_declaration *decl_impl = unsafe_impl_from_IDirect3DVertexDeclaration9(declaration);
|
---|
2470 | HRESULT hr;
|
---|
2471 |
|
---|
2472 | TRACE("iface %p, src_start_idx %u, dst_idx %u, vertex_count %u, dst_buffer %p, declaration %p, flags %#x.\n",
|
---|
2473 | iface, src_start_idx, dst_idx, vertex_count, dst_buffer, declaration, flags);
|
---|
2474 |
|
---|
2475 | wined3d_mutex_lock();
|
---|
2476 | hr = wined3d_device_process_vertices(device->wined3d_device, src_start_idx, dst_idx, vertex_count,
|
---|
2477 | dst_impl->wined3d_buffer, decl_impl ? decl_impl->wined3d_declaration : NULL,
|
---|
2478 | flags, dst_impl->fvf);
|
---|
2479 | wined3d_mutex_unlock();
|
---|
2480 |
|
---|
2481 | return hr;
|
---|
2482 | }
|
---|
2483 |
|
---|
2484 | static HRESULT WINAPI d3d9_device_CreateVertexDeclaration(IDirect3DDevice9Ex *iface,
|
---|
2485 | const D3DVERTEXELEMENT9 *elements, IDirect3DVertexDeclaration9 **declaration)
|
---|
2486 | {
|
---|
2487 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
2488 | struct d3d9_vertex_declaration *object;
|
---|
2489 | HRESULT hr;
|
---|
2490 |
|
---|
2491 | TRACE("iface %p, elements %p, declaration %p.\n", iface, elements, declaration);
|
---|
2492 |
|
---|
2493 | if (!declaration)
|
---|
2494 | {
|
---|
2495 | WARN("Caller passed a NULL declaration, returning D3DERR_INVALIDCALL.\n");
|
---|
2496 | return D3DERR_INVALIDCALL;
|
---|
2497 | }
|
---|
2498 |
|
---|
2499 | if (SUCCEEDED(hr = d3d9_vertex_declaration_create(device, elements, &object)))
|
---|
2500 | *declaration = &object->IDirect3DVertexDeclaration9_iface;
|
---|
2501 |
|
---|
2502 | return hr;
|
---|
2503 | }
|
---|
2504 |
|
---|
2505 | static HRESULT WINAPI d3d9_device_SetVertexDeclaration(IDirect3DDevice9Ex *iface,
|
---|
2506 | IDirect3DVertexDeclaration9 *declaration)
|
---|
2507 | {
|
---|
2508 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
2509 | struct d3d9_vertex_declaration *decl_impl = unsafe_impl_from_IDirect3DVertexDeclaration9(declaration);
|
---|
2510 |
|
---|
2511 | TRACE("iface %p, declaration %p.\n", iface, declaration);
|
---|
2512 |
|
---|
2513 | wined3d_mutex_lock();
|
---|
2514 | wined3d_device_set_vertex_declaration(device->wined3d_device,
|
---|
2515 | decl_impl ? decl_impl->wined3d_declaration : NULL);
|
---|
2516 | wined3d_mutex_unlock();
|
---|
2517 |
|
---|
2518 | return D3D_OK;
|
---|
2519 | }
|
---|
2520 |
|
---|
2521 | static HRESULT WINAPI d3d9_device_GetVertexDeclaration(IDirect3DDevice9Ex *iface,
|
---|
2522 | IDirect3DVertexDeclaration9 **declaration)
|
---|
2523 | {
|
---|
2524 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
2525 | struct wined3d_vertex_declaration *wined3d_declaration;
|
---|
2526 | struct d3d9_vertex_declaration *declaration_impl;
|
---|
2527 |
|
---|
2528 | TRACE("iface %p, declaration %p.\n", iface, declaration);
|
---|
2529 |
|
---|
2530 | if (!declaration) return D3DERR_INVALIDCALL;
|
---|
2531 |
|
---|
2532 | wined3d_mutex_lock();
|
---|
2533 | if ((wined3d_declaration = wined3d_device_get_vertex_declaration(device->wined3d_device)))
|
---|
2534 | {
|
---|
2535 | declaration_impl = wined3d_vertex_declaration_get_parent(wined3d_declaration);
|
---|
2536 | *declaration = &declaration_impl->IDirect3DVertexDeclaration9_iface;
|
---|
2537 | IDirect3DVertexDeclaration9_AddRef(*declaration);
|
---|
2538 | }
|
---|
2539 | else
|
---|
2540 | {
|
---|
2541 | *declaration = NULL;
|
---|
2542 | }
|
---|
2543 | wined3d_mutex_unlock();
|
---|
2544 |
|
---|
2545 | TRACE("Returning %p.\n", *declaration);
|
---|
2546 | return D3D_OK;
|
---|
2547 | }
|
---|
2548 |
|
---|
2549 | static struct wined3d_vertex_declaration *device_get_fvf_declaration(struct d3d9_device *device, DWORD fvf)
|
---|
2550 | {
|
---|
2551 | struct wined3d_vertex_declaration *wined3d_declaration;
|
---|
2552 | struct fvf_declaration *fvf_decls = device->fvf_decls;
|
---|
2553 | struct d3d9_vertex_declaration *d3d9_declaration;
|
---|
2554 | D3DVERTEXELEMENT9 *elements;
|
---|
2555 | int p, low, high; /* deliberately signed */
|
---|
2556 | HRESULT hr;
|
---|
2557 |
|
---|
2558 | TRACE("Searching for declaration for fvf %08x... ", fvf);
|
---|
2559 |
|
---|
2560 | low = 0;
|
---|
2561 | high = device->fvf_decl_count - 1;
|
---|
2562 | while (low <= high)
|
---|
2563 | {
|
---|
2564 | p = (low + high) >> 1;
|
---|
2565 | TRACE("%d ", p);
|
---|
2566 |
|
---|
2567 | if (fvf_decls[p].fvf == fvf)
|
---|
2568 | {
|
---|
2569 | TRACE("found %p.\n", fvf_decls[p].decl);
|
---|
2570 | return fvf_decls[p].decl;
|
---|
2571 | }
|
---|
2572 |
|
---|
2573 | if (fvf_decls[p].fvf < fvf)
|
---|
2574 | low = p + 1;
|
---|
2575 | else
|
---|
2576 | high = p - 1;
|
---|
2577 | }
|
---|
2578 | TRACE("not found. Creating and inserting at position %d.\n", low);
|
---|
2579 |
|
---|
2580 | if (FAILED(hr = vdecl_convert_fvf(fvf, &elements)))
|
---|
2581 | return NULL;
|
---|
2582 |
|
---|
2583 | hr = d3d9_vertex_declaration_create(device, elements, &d3d9_declaration);
|
---|
2584 | HeapFree(GetProcessHeap(), 0, elements);
|
---|
2585 | if (FAILED(hr))
|
---|
2586 | return NULL;
|
---|
2587 |
|
---|
2588 | if (device->fvf_decl_size == device->fvf_decl_count)
|
---|
2589 | {
|
---|
2590 | UINT grow = max(device->fvf_decl_size / 2, 8);
|
---|
2591 |
|
---|
2592 | fvf_decls = HeapReAlloc(GetProcessHeap(), 0, fvf_decls, sizeof(*fvf_decls) * (device->fvf_decl_size + grow));
|
---|
2593 | if (!fvf_decls)
|
---|
2594 | {
|
---|
2595 | IDirect3DVertexDeclaration9_Release(&d3d9_declaration->IDirect3DVertexDeclaration9_iface);
|
---|
2596 | return NULL;
|
---|
2597 | }
|
---|
2598 | device->fvf_decls = fvf_decls;
|
---|
2599 | device->fvf_decl_size += grow;
|
---|
2600 | }
|
---|
2601 |
|
---|
2602 | d3d9_declaration->fvf = fvf;
|
---|
2603 | wined3d_declaration = d3d9_declaration->wined3d_declaration;
|
---|
2604 | wined3d_vertex_declaration_incref(wined3d_declaration);
|
---|
2605 | IDirect3DVertexDeclaration9_Release(&d3d9_declaration->IDirect3DVertexDeclaration9_iface);
|
---|
2606 |
|
---|
2607 | memmove(fvf_decls + low + 1, fvf_decls + low, sizeof(*fvf_decls) * (device->fvf_decl_count - low));
|
---|
2608 | fvf_decls[low].decl = wined3d_declaration;
|
---|
2609 | fvf_decls[low].fvf = fvf;
|
---|
2610 | ++device->fvf_decl_count;
|
---|
2611 |
|
---|
2612 | TRACE("Returning %p. %u declatations in array.\n", wined3d_declaration, device->fvf_decl_count);
|
---|
2613 |
|
---|
2614 | return wined3d_declaration;
|
---|
2615 | }
|
---|
2616 |
|
---|
2617 | static HRESULT WINAPI d3d9_device_SetFVF(IDirect3DDevice9Ex *iface, DWORD fvf)
|
---|
2618 | {
|
---|
2619 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
2620 | struct wined3d_vertex_declaration *decl;
|
---|
2621 |
|
---|
2622 | TRACE("iface %p, fvf %#x.\n", iface, fvf);
|
---|
2623 |
|
---|
2624 | if (!fvf)
|
---|
2625 | {
|
---|
2626 | WARN("%#x is not a valid FVF.\n", fvf);
|
---|
2627 | return D3D_OK;
|
---|
2628 | }
|
---|
2629 |
|
---|
2630 | wined3d_mutex_lock();
|
---|
2631 | if (!(decl = device_get_fvf_declaration(device, fvf)))
|
---|
2632 | {
|
---|
2633 | wined3d_mutex_unlock();
|
---|
2634 | ERR("Failed to create a vertex declaration for fvf %#x.\n", fvf);
|
---|
2635 | return D3DERR_DRIVERINTERNALERROR;
|
---|
2636 | }
|
---|
2637 |
|
---|
2638 | wined3d_device_set_vertex_declaration(device->wined3d_device, decl);
|
---|
2639 | wined3d_mutex_unlock();
|
---|
2640 |
|
---|
2641 | return D3D_OK;
|
---|
2642 | }
|
---|
2643 |
|
---|
2644 | static HRESULT WINAPI d3d9_device_GetFVF(IDirect3DDevice9Ex *iface, DWORD *fvf)
|
---|
2645 | {
|
---|
2646 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
2647 | struct wined3d_vertex_declaration *wined3d_declaration;
|
---|
2648 | struct d3d9_vertex_declaration *d3d9_declaration;
|
---|
2649 |
|
---|
2650 | TRACE("iface %p, fvf %p.\n", iface, fvf);
|
---|
2651 |
|
---|
2652 | wined3d_mutex_lock();
|
---|
2653 | if ((wined3d_declaration = wined3d_device_get_vertex_declaration(device->wined3d_device)))
|
---|
2654 | {
|
---|
2655 | d3d9_declaration = wined3d_vertex_declaration_get_parent(wined3d_declaration);
|
---|
2656 | *fvf = d3d9_declaration->fvf;
|
---|
2657 | }
|
---|
2658 | else
|
---|
2659 | {
|
---|
2660 | *fvf = 0;
|
---|
2661 | }
|
---|
2662 | wined3d_mutex_unlock();
|
---|
2663 |
|
---|
2664 | TRACE("Returning FVF %#x.\n", *fvf);
|
---|
2665 |
|
---|
2666 | return D3D_OK;
|
---|
2667 | }
|
---|
2668 |
|
---|
2669 | static HRESULT WINAPI d3d9_device_CreateVertexShader(IDirect3DDevice9Ex *iface,
|
---|
2670 | const DWORD *byte_code, IDirect3DVertexShader9 **shader)
|
---|
2671 | {
|
---|
2672 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
2673 | struct d3d9_vertexshader *object;
|
---|
2674 | HRESULT hr;
|
---|
2675 |
|
---|
2676 | TRACE("iface %p, byte_code %p, shader %p.\n", iface, byte_code, shader);
|
---|
2677 |
|
---|
2678 | object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
|
---|
2679 | if (!object)
|
---|
2680 | return E_OUTOFMEMORY;
|
---|
2681 |
|
---|
2682 | hr = vertexshader_init(object, device, byte_code);
|
---|
2683 | if (FAILED(hr))
|
---|
2684 | {
|
---|
2685 | WARN("Failed to initialize vertex shader, hr %#x.\n", hr);
|
---|
2686 | HeapFree(GetProcessHeap(), 0, object);
|
---|
2687 | return hr;
|
---|
2688 | }
|
---|
2689 |
|
---|
2690 | TRACE("Created vertex shader %p.\n", object);
|
---|
2691 | *shader = &object->IDirect3DVertexShader9_iface;
|
---|
2692 |
|
---|
2693 | return D3D_OK;
|
---|
2694 | }
|
---|
2695 |
|
---|
2696 | static HRESULT WINAPI d3d9_device_SetVertexShader(IDirect3DDevice9Ex *iface, IDirect3DVertexShader9 *shader)
|
---|
2697 | {
|
---|
2698 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
2699 | struct d3d9_vertexshader *shader_obj = unsafe_impl_from_IDirect3DVertexShader9(shader);
|
---|
2700 |
|
---|
2701 | TRACE("iface %p, shader %p.\n", iface, shader);
|
---|
2702 |
|
---|
2703 | wined3d_mutex_lock();
|
---|
2704 | wined3d_device_set_vertex_shader(device->wined3d_device,
|
---|
2705 | shader_obj ? shader_obj->wined3d_shader : NULL);
|
---|
2706 | wined3d_mutex_unlock();
|
---|
2707 |
|
---|
2708 | return D3D_OK;
|
---|
2709 | }
|
---|
2710 |
|
---|
2711 | static HRESULT WINAPI d3d9_device_GetVertexShader(IDirect3DDevice9Ex *iface, IDirect3DVertexShader9 **shader)
|
---|
2712 | {
|
---|
2713 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
2714 | struct d3d9_vertexshader *shader_impl;
|
---|
2715 | struct wined3d_shader *wined3d_shader;
|
---|
2716 |
|
---|
2717 | TRACE("iface %p, shader %p.\n", iface, shader);
|
---|
2718 |
|
---|
2719 | wined3d_mutex_lock();
|
---|
2720 | if ((wined3d_shader = wined3d_device_get_vertex_shader(device->wined3d_device)))
|
---|
2721 | {
|
---|
2722 | shader_impl = wined3d_shader_get_parent(wined3d_shader);
|
---|
2723 | *shader = &shader_impl->IDirect3DVertexShader9_iface;
|
---|
2724 | IDirect3DVertexShader9_AddRef(*shader);
|
---|
2725 | }
|
---|
2726 | else
|
---|
2727 | {
|
---|
2728 | *shader = NULL;
|
---|
2729 | }
|
---|
2730 | wined3d_mutex_unlock();
|
---|
2731 |
|
---|
2732 | TRACE("Returning %p.\n", *shader);
|
---|
2733 |
|
---|
2734 | return D3D_OK;
|
---|
2735 | }
|
---|
2736 |
|
---|
2737 | static HRESULT WINAPI d3d9_device_SetVertexShaderConstantF(IDirect3DDevice9Ex *iface,
|
---|
2738 | UINT reg_idx, const float *data, UINT count)
|
---|
2739 | {
|
---|
2740 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
2741 | HRESULT hr;
|
---|
2742 |
|
---|
2743 | TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
|
---|
2744 |
|
---|
2745 | if (reg_idx + count > D3D9_MAX_VERTEX_SHADER_CONSTANTF)
|
---|
2746 | {
|
---|
2747 | WARN("Trying to access %u constants, but d3d9 only supports %u\n",
|
---|
2748 | reg_idx + count, D3D9_MAX_VERTEX_SHADER_CONSTANTF);
|
---|
2749 | return D3DERR_INVALIDCALL;
|
---|
2750 | }
|
---|
2751 |
|
---|
2752 | wined3d_mutex_lock();
|
---|
2753 | hr = wined3d_device_set_vs_consts_f(device->wined3d_device, reg_idx, data, count);
|
---|
2754 | wined3d_mutex_unlock();
|
---|
2755 |
|
---|
2756 | return hr;
|
---|
2757 | }
|
---|
2758 |
|
---|
2759 | static HRESULT WINAPI d3d9_device_GetVertexShaderConstantF(IDirect3DDevice9Ex *iface,
|
---|
2760 | UINT reg_idx, float *data, UINT count)
|
---|
2761 | {
|
---|
2762 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
2763 | HRESULT hr;
|
---|
2764 |
|
---|
2765 | TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
|
---|
2766 |
|
---|
2767 | if (reg_idx + count > D3D9_MAX_VERTEX_SHADER_CONSTANTF)
|
---|
2768 | {
|
---|
2769 | WARN("Trying to access %u constants, but d3d9 only supports %u\n",
|
---|
2770 | reg_idx + count, D3D9_MAX_VERTEX_SHADER_CONSTANTF);
|
---|
2771 | return D3DERR_INVALIDCALL;
|
---|
2772 | }
|
---|
2773 |
|
---|
2774 | wined3d_mutex_lock();
|
---|
2775 | hr = wined3d_device_get_vs_consts_f(device->wined3d_device, reg_idx, data, count);
|
---|
2776 | wined3d_mutex_unlock();
|
---|
2777 |
|
---|
2778 | return hr;
|
---|
2779 | }
|
---|
2780 |
|
---|
2781 | static HRESULT WINAPI d3d9_device_SetVertexShaderConstantI(IDirect3DDevice9Ex *iface,
|
---|
2782 | UINT reg_idx, const int *data, UINT count)
|
---|
2783 | {
|
---|
2784 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
2785 | HRESULT hr;
|
---|
2786 |
|
---|
2787 | TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
|
---|
2788 |
|
---|
2789 | wined3d_mutex_lock();
|
---|
2790 | hr = wined3d_device_set_vs_consts_i(device->wined3d_device, reg_idx, data, count);
|
---|
2791 | wined3d_mutex_unlock();
|
---|
2792 |
|
---|
2793 | return hr;
|
---|
2794 | }
|
---|
2795 |
|
---|
2796 | static HRESULT WINAPI d3d9_device_GetVertexShaderConstantI(IDirect3DDevice9Ex *iface,
|
---|
2797 | UINT reg_idx, int *data, UINT count)
|
---|
2798 | {
|
---|
2799 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
2800 | HRESULT hr;
|
---|
2801 |
|
---|
2802 | TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
|
---|
2803 |
|
---|
2804 | wined3d_mutex_lock();
|
---|
2805 | hr = wined3d_device_get_vs_consts_i(device->wined3d_device, reg_idx, data, count);
|
---|
2806 | wined3d_mutex_unlock();
|
---|
2807 |
|
---|
2808 | return hr;
|
---|
2809 | }
|
---|
2810 |
|
---|
2811 | static HRESULT WINAPI d3d9_device_SetVertexShaderConstantB(IDirect3DDevice9Ex *iface,
|
---|
2812 | UINT reg_idx, const BOOL *data, UINT count)
|
---|
2813 | {
|
---|
2814 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
2815 | HRESULT hr;
|
---|
2816 |
|
---|
2817 | TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
|
---|
2818 |
|
---|
2819 | wined3d_mutex_lock();
|
---|
2820 | hr = wined3d_device_set_vs_consts_b(device->wined3d_device, reg_idx, data, count);
|
---|
2821 | wined3d_mutex_unlock();
|
---|
2822 |
|
---|
2823 | return hr;
|
---|
2824 | }
|
---|
2825 |
|
---|
2826 | static HRESULT WINAPI d3d9_device_GetVertexShaderConstantB(IDirect3DDevice9Ex *iface,
|
---|
2827 | UINT reg_idx, BOOL *data, UINT count)
|
---|
2828 | {
|
---|
2829 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
2830 | HRESULT hr;
|
---|
2831 |
|
---|
2832 | TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
|
---|
2833 |
|
---|
2834 | wined3d_mutex_lock();
|
---|
2835 | hr = wined3d_device_get_vs_consts_b(device->wined3d_device, reg_idx, data, count);
|
---|
2836 | wined3d_mutex_unlock();
|
---|
2837 |
|
---|
2838 | return hr;
|
---|
2839 | }
|
---|
2840 |
|
---|
2841 | static HRESULT WINAPI d3d9_device_SetStreamSource(IDirect3DDevice9Ex *iface,
|
---|
2842 | UINT stream_idx, IDirect3DVertexBuffer9 *buffer, UINT offset, UINT stride)
|
---|
2843 | {
|
---|
2844 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
2845 | struct d3d9_vertexbuffer *buffer_impl = unsafe_impl_from_IDirect3DVertexBuffer9(buffer);
|
---|
2846 | HRESULT hr;
|
---|
2847 |
|
---|
2848 | TRACE("iface %p, stream_idx %u, buffer %p, offset %u, stride %u.\n",
|
---|
2849 | iface, stream_idx, buffer, offset, stride);
|
---|
2850 |
|
---|
2851 | wined3d_mutex_lock();
|
---|
2852 | hr = wined3d_device_set_stream_source(device->wined3d_device, stream_idx,
|
---|
2853 | buffer_impl ? buffer_impl->wined3d_buffer : NULL, offset, stride);
|
---|
2854 | wined3d_mutex_unlock();
|
---|
2855 |
|
---|
2856 | return hr;
|
---|
2857 | }
|
---|
2858 |
|
---|
2859 | static HRESULT WINAPI d3d9_device_GetStreamSource(IDirect3DDevice9Ex *iface,
|
---|
2860 | UINT stream_idx, IDirect3DVertexBuffer9 **buffer, UINT *offset, UINT *stride)
|
---|
2861 | {
|
---|
2862 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
2863 | struct d3d9_vertexbuffer *buffer_impl;
|
---|
2864 | struct wined3d_buffer *wined3d_buffer;
|
---|
2865 | HRESULT hr;
|
---|
2866 |
|
---|
2867 | TRACE("iface %p, stream_idx %u, buffer %p, offset %p, stride %p.\n",
|
---|
2868 | iface, stream_idx, buffer, offset, stride);
|
---|
2869 |
|
---|
2870 | if (!buffer)
|
---|
2871 | return D3DERR_INVALIDCALL;
|
---|
2872 |
|
---|
2873 | wined3d_mutex_lock();
|
---|
2874 | hr = wined3d_device_get_stream_source(device->wined3d_device, stream_idx, &wined3d_buffer, offset, stride);
|
---|
2875 | if (SUCCEEDED(hr) && wined3d_buffer)
|
---|
2876 | {
|
---|
2877 | buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
|
---|
2878 | *buffer = &buffer_impl->IDirect3DVertexBuffer9_iface;
|
---|
2879 | IDirect3DVertexBuffer9_AddRef(*buffer);
|
---|
2880 | wined3d_buffer_decref(wined3d_buffer);
|
---|
2881 | }
|
---|
2882 | else
|
---|
2883 | {
|
---|
2884 | if (FAILED(hr))
|
---|
2885 | FIXME("Call to GetStreamSource failed %p %p\n", offset, stride);
|
---|
2886 | *buffer = NULL;
|
---|
2887 | }
|
---|
2888 | wined3d_mutex_unlock();
|
---|
2889 |
|
---|
2890 | return hr;
|
---|
2891 | }
|
---|
2892 |
|
---|
2893 | static HRESULT WINAPI d3d9_device_SetStreamSourceFreq(IDirect3DDevice9Ex *iface, UINT stream_idx, UINT freq)
|
---|
2894 | {
|
---|
2895 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
2896 | HRESULT hr;
|
---|
2897 |
|
---|
2898 | TRACE("iface %p, stream_idx %u, freq %u.\n", iface, stream_idx, freq);
|
---|
2899 |
|
---|
2900 | wined3d_mutex_lock();
|
---|
2901 | hr = wined3d_device_set_stream_source_freq(device->wined3d_device, stream_idx, freq);
|
---|
2902 | wined3d_mutex_unlock();
|
---|
2903 |
|
---|
2904 | return hr;
|
---|
2905 | }
|
---|
2906 |
|
---|
2907 | static HRESULT WINAPI d3d9_device_GetStreamSourceFreq(IDirect3DDevice9Ex *iface, UINT stream_idx, UINT *freq)
|
---|
2908 | {
|
---|
2909 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
2910 | HRESULT hr;
|
---|
2911 |
|
---|
2912 | TRACE("iface %p, stream_idx %u, freq %p.\n", iface, stream_idx, freq);
|
---|
2913 |
|
---|
2914 | wined3d_mutex_lock();
|
---|
2915 | hr = wined3d_device_get_stream_source_freq(device->wined3d_device, stream_idx, freq);
|
---|
2916 | wined3d_mutex_unlock();
|
---|
2917 |
|
---|
2918 | return hr;
|
---|
2919 | }
|
---|
2920 |
|
---|
2921 | static HRESULT WINAPI d3d9_device_SetIndices(IDirect3DDevice9Ex *iface, IDirect3DIndexBuffer9 *buffer)
|
---|
2922 | {
|
---|
2923 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
2924 | struct d3d9_indexbuffer *ib = unsafe_impl_from_IDirect3DIndexBuffer9(buffer);
|
---|
2925 |
|
---|
2926 | TRACE("iface %p, buffer %p.\n", iface, buffer);
|
---|
2927 |
|
---|
2928 | wined3d_mutex_lock();
|
---|
2929 | wined3d_device_set_index_buffer(device->wined3d_device,
|
---|
2930 | ib ? ib->wined3d_buffer : NULL,
|
---|
2931 | ib ? ib->format : WINED3DFMT_UNKNOWN);
|
---|
2932 | wined3d_mutex_unlock();
|
---|
2933 |
|
---|
2934 | return D3D_OK;
|
---|
2935 | }
|
---|
2936 |
|
---|
2937 | static HRESULT WINAPI d3d9_device_GetIndices(IDirect3DDevice9Ex *iface, IDirect3DIndexBuffer9 **buffer)
|
---|
2938 | {
|
---|
2939 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
2940 | enum wined3d_format_id wined3d_format;
|
---|
2941 | struct wined3d_buffer *wined3d_buffer;
|
---|
2942 | struct d3d9_indexbuffer *buffer_impl;
|
---|
2943 |
|
---|
2944 | TRACE("iface %p, buffer %p.\n", iface, buffer);
|
---|
2945 |
|
---|
2946 | if (!buffer)
|
---|
2947 | return D3DERR_INVALIDCALL;
|
---|
2948 |
|
---|
2949 | wined3d_mutex_lock();
|
---|
2950 | if ((wined3d_buffer = wined3d_device_get_index_buffer(device->wined3d_device, &wined3d_format)))
|
---|
2951 | {
|
---|
2952 | buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
|
---|
2953 | *buffer = &buffer_impl->IDirect3DIndexBuffer9_iface;
|
---|
2954 | IDirect3DIndexBuffer9_AddRef(*buffer);
|
---|
2955 | }
|
---|
2956 | else
|
---|
2957 | {
|
---|
2958 | *buffer = NULL;
|
---|
2959 | }
|
---|
2960 | wined3d_mutex_unlock();
|
---|
2961 |
|
---|
2962 | return D3D_OK;
|
---|
2963 | }
|
---|
2964 |
|
---|
2965 | static HRESULT WINAPI d3d9_device_CreatePixelShader(IDirect3DDevice9Ex *iface,
|
---|
2966 | const DWORD *byte_code, IDirect3DPixelShader9 **shader)
|
---|
2967 | {
|
---|
2968 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
2969 | struct d3d9_pixelshader *object;
|
---|
2970 | HRESULT hr;
|
---|
2971 |
|
---|
2972 | TRACE("iface %p, byte_code %p, shader %p.\n", iface, byte_code, shader);
|
---|
2973 |
|
---|
2974 | object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
|
---|
2975 | if (!object)
|
---|
2976 | {
|
---|
2977 | FIXME("Failed to allocate pixel shader memory.\n");
|
---|
2978 | return E_OUTOFMEMORY;
|
---|
2979 | }
|
---|
2980 |
|
---|
2981 | hr = pixelshader_init(object, device, byte_code);
|
---|
2982 | if (FAILED(hr))
|
---|
2983 | {
|
---|
2984 | WARN("Failed to initialize pixel shader, hr %#x.\n", hr);
|
---|
2985 | HeapFree(GetProcessHeap(), 0, object);
|
---|
2986 | return hr;
|
---|
2987 | }
|
---|
2988 |
|
---|
2989 | TRACE("Created pixel shader %p.\n", object);
|
---|
2990 | *shader = &object->IDirect3DPixelShader9_iface;
|
---|
2991 |
|
---|
2992 | return D3D_OK;
|
---|
2993 | }
|
---|
2994 |
|
---|
2995 | static HRESULT WINAPI d3d9_device_SetPixelShader(IDirect3DDevice9Ex *iface, IDirect3DPixelShader9 *shader)
|
---|
2996 | {
|
---|
2997 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
2998 | struct d3d9_pixelshader *shader_obj = unsafe_impl_from_IDirect3DPixelShader9(shader);
|
---|
2999 |
|
---|
3000 | TRACE("iface %p, shader %p.\n", iface, shader);
|
---|
3001 |
|
---|
3002 | wined3d_mutex_lock();
|
---|
3003 | wined3d_device_set_pixel_shader(device->wined3d_device,
|
---|
3004 | shader_obj ? shader_obj->wined3d_shader : NULL);
|
---|
3005 | wined3d_mutex_unlock();
|
---|
3006 |
|
---|
3007 | return D3D_OK;
|
---|
3008 | }
|
---|
3009 |
|
---|
3010 | static HRESULT WINAPI d3d9_device_GetPixelShader(IDirect3DDevice9Ex *iface, IDirect3DPixelShader9 **shader)
|
---|
3011 | {
|
---|
3012 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
3013 | struct d3d9_pixelshader *shader_impl;
|
---|
3014 | struct wined3d_shader *wined3d_shader;
|
---|
3015 |
|
---|
3016 | TRACE("iface %p, shader %p.\n", iface, shader);
|
---|
3017 |
|
---|
3018 | if (!shader) return D3DERR_INVALIDCALL;
|
---|
3019 |
|
---|
3020 | wined3d_mutex_lock();
|
---|
3021 | if ((wined3d_shader = wined3d_device_get_pixel_shader(device->wined3d_device)))
|
---|
3022 | {
|
---|
3023 | shader_impl = wined3d_shader_get_parent(wined3d_shader);
|
---|
3024 | *shader = &shader_impl->IDirect3DPixelShader9_iface;
|
---|
3025 | IDirect3DPixelShader9_AddRef(*shader);
|
---|
3026 | }
|
---|
3027 | else
|
---|
3028 | {
|
---|
3029 | *shader = NULL;
|
---|
3030 | }
|
---|
3031 | wined3d_mutex_unlock();
|
---|
3032 |
|
---|
3033 | TRACE("Returning %p.\n", *shader);
|
---|
3034 |
|
---|
3035 | return D3D_OK;
|
---|
3036 | }
|
---|
3037 |
|
---|
3038 | static HRESULT WINAPI d3d9_device_SetPixelShaderConstantF(IDirect3DDevice9Ex *iface,
|
---|
3039 | UINT reg_idx, const float *data, UINT count)
|
---|
3040 | {
|
---|
3041 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
3042 | HRESULT hr;
|
---|
3043 |
|
---|
3044 | TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
|
---|
3045 |
|
---|
3046 | wined3d_mutex_lock();
|
---|
3047 | hr = wined3d_device_set_ps_consts_f(device->wined3d_device, reg_idx, data, count);
|
---|
3048 | wined3d_mutex_unlock();
|
---|
3049 |
|
---|
3050 | return hr;
|
---|
3051 | }
|
---|
3052 |
|
---|
3053 | static HRESULT WINAPI d3d9_device_GetPixelShaderConstantF(IDirect3DDevice9Ex *iface,
|
---|
3054 | UINT reg_idx, float *data, UINT count)
|
---|
3055 | {
|
---|
3056 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
3057 | HRESULT hr;
|
---|
3058 |
|
---|
3059 | TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
|
---|
3060 |
|
---|
3061 | wined3d_mutex_lock();
|
---|
3062 | hr = wined3d_device_get_ps_consts_f(device->wined3d_device, reg_idx, data, count);
|
---|
3063 | wined3d_mutex_unlock();
|
---|
3064 |
|
---|
3065 | return hr;
|
---|
3066 | }
|
---|
3067 |
|
---|
3068 | static HRESULT WINAPI d3d9_device_SetPixelShaderConstantI(IDirect3DDevice9Ex *iface,
|
---|
3069 | UINT reg_idx, const int *data, UINT count)
|
---|
3070 | {
|
---|
3071 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
3072 | HRESULT hr;
|
---|
3073 |
|
---|
3074 | TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
|
---|
3075 |
|
---|
3076 | wined3d_mutex_lock();
|
---|
3077 | hr = wined3d_device_set_ps_consts_i(device->wined3d_device, reg_idx, data, count);
|
---|
3078 | wined3d_mutex_unlock();
|
---|
3079 |
|
---|
3080 | return hr;
|
---|
3081 | }
|
---|
3082 |
|
---|
3083 | static HRESULT WINAPI d3d9_device_GetPixelShaderConstantI(IDirect3DDevice9Ex *iface,
|
---|
3084 | UINT reg_idx, int *data, UINT count)
|
---|
3085 | {
|
---|
3086 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
3087 | HRESULT hr;
|
---|
3088 |
|
---|
3089 | TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
|
---|
3090 |
|
---|
3091 | wined3d_mutex_lock();
|
---|
3092 | hr = wined3d_device_get_ps_consts_i(device->wined3d_device, reg_idx, data, count);
|
---|
3093 | wined3d_mutex_unlock();
|
---|
3094 |
|
---|
3095 | return hr;
|
---|
3096 | }
|
---|
3097 |
|
---|
3098 | static HRESULT WINAPI d3d9_device_SetPixelShaderConstantB(IDirect3DDevice9Ex *iface,
|
---|
3099 | UINT reg_idx, const BOOL *data, UINT count)
|
---|
3100 | {
|
---|
3101 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
3102 | HRESULT hr;
|
---|
3103 |
|
---|
3104 | TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
|
---|
3105 |
|
---|
3106 | wined3d_mutex_lock();
|
---|
3107 | hr = wined3d_device_set_ps_consts_b(device->wined3d_device, reg_idx, data, count);
|
---|
3108 | wined3d_mutex_unlock();
|
---|
3109 |
|
---|
3110 | return hr;
|
---|
3111 | }
|
---|
3112 |
|
---|
3113 | static HRESULT WINAPI d3d9_device_GetPixelShaderConstantB(IDirect3DDevice9Ex *iface,
|
---|
3114 | UINT reg_idx, BOOL *data, UINT count)
|
---|
3115 | {
|
---|
3116 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
3117 | HRESULT hr;
|
---|
3118 |
|
---|
3119 | TRACE("iface %p, reg_idx %u, data %p, count %u.\n", iface, reg_idx, data, count);
|
---|
3120 |
|
---|
3121 | wined3d_mutex_lock();
|
---|
3122 | hr = wined3d_device_get_ps_consts_b(device->wined3d_device, reg_idx, data, count);
|
---|
3123 | wined3d_mutex_unlock();
|
---|
3124 |
|
---|
3125 | return hr;
|
---|
3126 | }
|
---|
3127 |
|
---|
3128 | static HRESULT WINAPI d3d9_device_DrawRectPatch(IDirect3DDevice9Ex *iface, UINT handle,
|
---|
3129 | const float *segment_count, const D3DRECTPATCH_INFO *patch_info)
|
---|
3130 | {
|
---|
3131 | FIXME("iface %p, handle %#x, segment_count %p, patch_info %p unimplemented.\n",
|
---|
3132 | iface, handle, segment_count, patch_info);
|
---|
3133 | return D3D_OK;
|
---|
3134 | }
|
---|
3135 |
|
---|
3136 | static HRESULT WINAPI d3d9_device_DrawTriPatch(IDirect3DDevice9Ex *iface, UINT handle,
|
---|
3137 | const float *segment_count, const D3DTRIPATCH_INFO *patch_info)
|
---|
3138 | {
|
---|
3139 | FIXME("iface %p, handle %#x, segment_count %p, patch_info %p unimplemented.\n",
|
---|
3140 | iface, handle, segment_count, patch_info);
|
---|
3141 | return D3D_OK;
|
---|
3142 | }
|
---|
3143 |
|
---|
3144 | static HRESULT WINAPI d3d9_device_DeletePatch(IDirect3DDevice9Ex *iface, UINT handle)
|
---|
3145 | {
|
---|
3146 | FIXME("iface %p, handle %#x unimplemented.\n", iface, handle);
|
---|
3147 | return D3DERR_INVALIDCALL;
|
---|
3148 | }
|
---|
3149 |
|
---|
3150 | static HRESULT WINAPI d3d9_device_CreateQuery(IDirect3DDevice9Ex *iface, D3DQUERYTYPE type, IDirect3DQuery9 **query)
|
---|
3151 | {
|
---|
3152 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
3153 | struct d3d9_query *object;
|
---|
3154 | HRESULT hr;
|
---|
3155 |
|
---|
3156 | TRACE("iface %p, type %#x, query %p.\n", iface, type, query);
|
---|
3157 |
|
---|
3158 | object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
|
---|
3159 | if (!object)
|
---|
3160 | return E_OUTOFMEMORY;
|
---|
3161 |
|
---|
3162 | hr = query_init(object, device, type);
|
---|
3163 | if (FAILED(hr))
|
---|
3164 | {
|
---|
3165 | WARN("Failed to initialize query, hr %#x.\n", hr);
|
---|
3166 | HeapFree(GetProcessHeap(), 0, object);
|
---|
3167 | return hr;
|
---|
3168 | }
|
---|
3169 |
|
---|
3170 | TRACE("Created query %p.\n", object);
|
---|
3171 | if (query) *query = &object->IDirect3DQuery9_iface;
|
---|
3172 | else IDirect3DQuery9_Release(&object->IDirect3DQuery9_iface);
|
---|
3173 |
|
---|
3174 | return D3D_OK;
|
---|
3175 | }
|
---|
3176 |
|
---|
3177 | static HRESULT WINAPI d3d9_device_SetConvolutionMonoKernel(IDirect3DDevice9Ex *iface,
|
---|
3178 | UINT width, UINT height, float *rows, float *columns)
|
---|
3179 | {
|
---|
3180 | FIXME("iface %p, width %u, height %u, rows %p, columns %p stub!\n",
|
---|
3181 | iface, width, height, rows, columns);
|
---|
3182 |
|
---|
3183 | return E_NOTIMPL;
|
---|
3184 | }
|
---|
3185 |
|
---|
3186 | static HRESULT WINAPI d3d9_device_ComposeRects(IDirect3DDevice9Ex *iface,
|
---|
3187 | IDirect3DSurface9 *src_surface, IDirect3DSurface9 *dst_surface, IDirect3DVertexBuffer9 *src_descs,
|
---|
3188 | UINT rect_count, IDirect3DVertexBuffer9 *dst_descs, D3DCOMPOSERECTSOP operation, INT offset_x, INT offset_y)
|
---|
3189 | {
|
---|
3190 | FIXME("iface %p, src_surface %p, dst_surface %p, src_descs %p, rect_count %u,\n"
|
---|
3191 | "dst_descs %p, operation %#x, offset_x %u, offset_y %u stub!\n",
|
---|
3192 | iface, src_surface, dst_surface, src_descs, rect_count,
|
---|
3193 | dst_descs, operation, offset_x, offset_y);
|
---|
3194 |
|
---|
3195 | return E_NOTIMPL;
|
---|
3196 | }
|
---|
3197 |
|
---|
3198 | static HRESULT WINAPI d3d9_device_PresentEx(IDirect3DDevice9Ex *iface,
|
---|
3199 | const RECT *src_rect, const RECT *dst_rect, HWND dst_window_override,
|
---|
3200 | const RGNDATA *dirty_region, DWORD flags)
|
---|
3201 | {
|
---|
3202 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
3203 | HRESULT hr;
|
---|
3204 |
|
---|
3205 | TRACE("iface %p, src_rect %s, dst_rect %s, dst_window_override %p, dirty_region %p, flags %#x.\n",
|
---|
3206 | iface, wine_dbgstr_rect(src_rect), wine_dbgstr_rect(dst_rect),
|
---|
3207 | dst_window_override, dirty_region, flags);
|
---|
3208 |
|
---|
3209 | wined3d_mutex_lock();
|
---|
3210 | hr = wined3d_device_present(device->wined3d_device, src_rect, dst_rect,
|
---|
3211 | dst_window_override, dirty_region, flags);
|
---|
3212 | wined3d_mutex_unlock();
|
---|
3213 |
|
---|
3214 | return hr;
|
---|
3215 | }
|
---|
3216 |
|
---|
3217 | static HRESULT WINAPI d3d9_device_GetGPUThreadPriority(IDirect3DDevice9Ex *iface, INT *priority)
|
---|
3218 | {
|
---|
3219 | FIXME("iface %p, priority %p stub!\n", iface, priority);
|
---|
3220 |
|
---|
3221 | return E_NOTIMPL;
|
---|
3222 | }
|
---|
3223 |
|
---|
3224 | static HRESULT WINAPI d3d9_device_SetGPUThreadPriority(IDirect3DDevice9Ex *iface, INT priority)
|
---|
3225 | {
|
---|
3226 | FIXME("iface %p, priority %d stub!\n", iface, priority);
|
---|
3227 |
|
---|
3228 | return E_NOTIMPL;
|
---|
3229 | }
|
---|
3230 |
|
---|
3231 | static HRESULT WINAPI d3d9_device_WaitForVBlank(IDirect3DDevice9Ex *iface, UINT swapchain_idx)
|
---|
3232 | {
|
---|
3233 | FIXME("iface %p, swapchain_idx %u stub!\n", iface, swapchain_idx);
|
---|
3234 |
|
---|
3235 | return E_NOTIMPL;
|
---|
3236 | }
|
---|
3237 |
|
---|
3238 | static HRESULT WINAPI d3d9_device_CheckResourceResidency(IDirect3DDevice9Ex *iface,
|
---|
3239 | IDirect3DResource9 **resources, UINT32 resource_count)
|
---|
3240 | {
|
---|
3241 | FIXME("iface %p, resources %p, resource_count %u stub!\n",
|
---|
3242 | iface, resources, resource_count);
|
---|
3243 |
|
---|
3244 | return E_NOTIMPL;
|
---|
3245 | }
|
---|
3246 |
|
---|
3247 | static HRESULT WINAPI d3d9_device_SetMaximumFrameLatency(IDirect3DDevice9Ex *iface, UINT max_latency)
|
---|
3248 | {
|
---|
3249 | FIXME("iface %p, max_latency %u stub!\n", iface, max_latency);
|
---|
3250 |
|
---|
3251 | return E_NOTIMPL;
|
---|
3252 | }
|
---|
3253 |
|
---|
3254 | static HRESULT WINAPI d3d9_device_GetMaximumFrameLatency(IDirect3DDevice9Ex *iface, UINT *max_latency)
|
---|
3255 | {
|
---|
3256 | FIXME("iface %p, max_latency %p stub!\n", iface, max_latency);
|
---|
3257 |
|
---|
3258 | *max_latency = 2;
|
---|
3259 |
|
---|
3260 | return E_NOTIMPL;
|
---|
3261 | }
|
---|
3262 |
|
---|
3263 | static HRESULT WINAPI d3d9_device_CheckDeviceState(IDirect3DDevice9Ex *iface, HWND dst_window)
|
---|
3264 | {
|
---|
3265 | static int i;
|
---|
3266 |
|
---|
3267 | TRACE("iface %p, dst_window %p stub!\n", iface, dst_window);
|
---|
3268 |
|
---|
3269 | if (!i++)
|
---|
3270 | FIXME("iface %p, dst_window %p stub!\n", iface, dst_window);
|
---|
3271 |
|
---|
3272 | return D3D_OK;
|
---|
3273 | }
|
---|
3274 |
|
---|
3275 | static HRESULT WINAPI d3d9_device_CreateRenderTargetEx(IDirect3DDevice9Ex *iface,
|
---|
3276 | UINT width, UINT height, D3DFORMAT format, D3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality,
|
---|
3277 | BOOL lockable, IDirect3DSurface9 **surface, HANDLE *shared_handle, DWORD usage)
|
---|
3278 | {
|
---|
3279 | FIXME("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u,\n"
|
---|
3280 | "lockable %#x, surface %p, shared_handle %p, usage %#x stub!\n",
|
---|
3281 | iface, width, height, format, multisample_type, multisample_quality,
|
---|
3282 | lockable, surface, shared_handle, usage);
|
---|
3283 |
|
---|
3284 | if (shared_handle)
|
---|
3285 | FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle);
|
---|
3286 |
|
---|
3287 | return E_NOTIMPL;
|
---|
3288 | }
|
---|
3289 |
|
---|
3290 | static HRESULT WINAPI d3d9_device_CreateOffscreenPlainSurfaceEx(IDirect3DDevice9Ex *iface,
|
---|
3291 | UINT width, UINT height, D3DFORMAT format, D3DPOOL pool, IDirect3DSurface9 **surface,
|
---|
3292 | HANDLE *shared_handle, DWORD usage)
|
---|
3293 | {
|
---|
3294 | FIXME("iface %p, width %u, height %u, format %#x, pool %#x, surface %p, shared_handle %p, usage %#x stub!\n",
|
---|
3295 | iface, width, height, format, pool, surface, shared_handle, usage);
|
---|
3296 |
|
---|
3297 | return E_NOTIMPL;
|
---|
3298 | }
|
---|
3299 |
|
---|
3300 | static HRESULT WINAPI d3d9_device_CreateDepthStencilSurfaceEx(IDirect3DDevice9Ex *iface,
|
---|
3301 | UINT width, UINT height, D3DFORMAT format, D3DMULTISAMPLE_TYPE multisample_type, DWORD multisample_quality,
|
---|
3302 | BOOL discard, IDirect3DSurface9 **surface, HANDLE *shared_handle, DWORD usage)
|
---|
3303 | {
|
---|
3304 | FIXME("iface %p, width %u, height %u, format %#x, multisample_type %#x, multisample_quality %u,\n"
|
---|
3305 | "discard %#x, surface %p, shared_handle %p, usage %#x stub!\n",
|
---|
3306 | iface, width, height, format, multisample_type, multisample_quality,
|
---|
3307 | discard, surface, shared_handle, usage);
|
---|
3308 |
|
---|
3309 | if (shared_handle)
|
---|
3310 | FIXME("Resource sharing not implemented, *shared_handle %p.\n", *shared_handle);
|
---|
3311 |
|
---|
3312 | return E_NOTIMPL;
|
---|
3313 | }
|
---|
3314 |
|
---|
3315 | static HRESULT WINAPI d3d9_device_ResetEx(IDirect3DDevice9Ex *iface,
|
---|
3316 | D3DPRESENT_PARAMETERS *present_parameters, D3DDISPLAYMODEEX *mode)
|
---|
3317 | {
|
---|
3318 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
3319 | struct wined3d_swapchain_desc swapchain_desc;
|
---|
3320 | struct wined3d_display_mode wined3d_mode;
|
---|
3321 | HRESULT hr;
|
---|
3322 |
|
---|
3323 | TRACE("iface %p, present_parameters %p, mode %p.\n", iface, present_parameters, mode);
|
---|
3324 |
|
---|
3325 | if (mode)
|
---|
3326 | {
|
---|
3327 | wined3d_mode.width = mode->Width;
|
---|
3328 | wined3d_mode.height = mode->Height;
|
---|
3329 | wined3d_mode.refresh_rate = mode->RefreshRate;
|
---|
3330 | wined3d_mode.format_id = wined3dformat_from_d3dformat(mode->Format);
|
---|
3331 | wined3d_mode.scanline_ordering = mode->ScanLineOrdering;
|
---|
3332 | }
|
---|
3333 |
|
---|
3334 | wined3d_mutex_lock();
|
---|
3335 |
|
---|
3336 | if (device->vertex_buffer)
|
---|
3337 | {
|
---|
3338 | wined3d_buffer_decref(device->vertex_buffer);
|
---|
3339 | device->vertex_buffer = NULL;
|
---|
3340 | device->vertex_buffer_size = 0;
|
---|
3341 | }
|
---|
3342 | if (device->index_buffer)
|
---|
3343 | {
|
---|
3344 | wined3d_buffer_decref(device->index_buffer);
|
---|
3345 | device->index_buffer = NULL;
|
---|
3346 | device->index_buffer_size = 0;
|
---|
3347 | }
|
---|
3348 |
|
---|
3349 | wined3d_swapchain_desc_from_present_parameters(&swapchain_desc, present_parameters);
|
---|
3350 | hr = wined3d_device_reset(device->wined3d_device, &swapchain_desc,
|
---|
3351 | mode ? &wined3d_mode : NULL, reset_enum_callback, FALSE);
|
---|
3352 | wined3d_mutex_unlock();
|
---|
3353 |
|
---|
3354 | return hr;
|
---|
3355 | }
|
---|
3356 |
|
---|
3357 | static HRESULT WINAPI d3d9_device_GetDisplayModeEx(IDirect3DDevice9Ex *iface,
|
---|
3358 | UINT swapchain_idx, D3DDISPLAYMODEEX *mode, D3DDISPLAYROTATION *rotation)
|
---|
3359 | {
|
---|
3360 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
3361 | struct wined3d_display_mode wined3d_mode;
|
---|
3362 | HRESULT hr;
|
---|
3363 |
|
---|
3364 | TRACE("iface %p, swapchain_idx %u, mode %p, rotation %p.\n",
|
---|
3365 | iface, swapchain_idx, mode, rotation);
|
---|
3366 |
|
---|
3367 | if (mode->Size != sizeof(*mode))
|
---|
3368 | return D3DERR_INVALIDCALL;
|
---|
3369 |
|
---|
3370 | wined3d_mutex_lock();
|
---|
3371 | hr = wined3d_device_get_display_mode(device->wined3d_device, swapchain_idx, &wined3d_mode,
|
---|
3372 | (enum wined3d_display_rotation *)rotation);
|
---|
3373 | wined3d_mutex_unlock();
|
---|
3374 |
|
---|
3375 | if (SUCCEEDED(hr))
|
---|
3376 | {
|
---|
3377 | mode->Width = wined3d_mode.width;
|
---|
3378 | mode->Height = wined3d_mode.height;
|
---|
3379 | mode->RefreshRate = wined3d_mode.refresh_rate;
|
---|
3380 | mode->Format = d3dformat_from_wined3dformat(wined3d_mode.format_id);
|
---|
3381 | mode->ScanLineOrdering = wined3d_mode.scanline_ordering;
|
---|
3382 | }
|
---|
3383 |
|
---|
3384 | return hr;
|
---|
3385 | }
|
---|
3386 |
|
---|
3387 | static const struct IDirect3DDevice9ExVtbl d3d9_device_vtbl =
|
---|
3388 | {
|
---|
3389 | /* IUnknown */
|
---|
3390 | d3d9_device_QueryInterface,
|
---|
3391 | d3d9_device_AddRef,
|
---|
3392 | d3d9_device_Release,
|
---|
3393 | /* IDirect3DDevice9 */
|
---|
3394 | d3d9_device_TestCooperativeLevel,
|
---|
3395 | d3d9_device_GetAvailableTextureMem,
|
---|
3396 | d3d9_device_EvictManagedResources,
|
---|
3397 | d3d9_device_GetDirect3D,
|
---|
3398 | d3d9_device_GetDeviceCaps,
|
---|
3399 | d3d9_device_GetDisplayMode,
|
---|
3400 | d3d9_device_GetCreationParameters,
|
---|
3401 | d3d9_device_SetCursorProperties,
|
---|
3402 | d3d9_device_SetCursorPosition,
|
---|
3403 | d3d9_device_ShowCursor,
|
---|
3404 | d3d9_device_CreateAdditionalSwapChain,
|
---|
3405 | d3d9_device_GetSwapChain,
|
---|
3406 | d3d9_device_GetNumberOfSwapChains,
|
---|
3407 | d3d9_device_Reset,
|
---|
3408 | d3d9_device_Present,
|
---|
3409 | d3d9_device_GetBackBuffer,
|
---|
3410 | d3d9_device_GetRasterStatus,
|
---|
3411 | d3d9_device_SetDialogBoxMode,
|
---|
3412 | d3d9_device_SetGammaRamp,
|
---|
3413 | d3d9_device_GetGammaRamp,
|
---|
3414 | d3d9_device_CreateTexture,
|
---|
3415 | d3d9_device_CreateVolumeTexture,
|
---|
3416 | d3d9_device_CreateCubeTexture,
|
---|
3417 | d3d9_device_CreateVertexBuffer,
|
---|
3418 | d3d9_device_CreateIndexBuffer,
|
---|
3419 | d3d9_device_CreateRenderTarget,
|
---|
3420 | d3d9_device_CreateDepthStencilSurface,
|
---|
3421 | d3d9_device_UpdateSurface,
|
---|
3422 | d3d9_device_UpdateTexture,
|
---|
3423 | d3d9_device_GetRenderTargetData,
|
---|
3424 | d3d9_device_GetFrontBufferData,
|
---|
3425 | d3d9_device_StretchRect,
|
---|
3426 | d3d9_device_ColorFill,
|
---|
3427 | d3d9_device_CreateOffscreenPlainSurface,
|
---|
3428 | d3d9_device_SetRenderTarget,
|
---|
3429 | d3d9_device_GetRenderTarget,
|
---|
3430 | d3d9_device_SetDepthStencilSurface,
|
---|
3431 | d3d9_device_GetDepthStencilSurface,
|
---|
3432 | d3d9_device_BeginScene,
|
---|
3433 | d3d9_device_EndScene,
|
---|
3434 | d3d9_device_Clear,
|
---|
3435 | d3d9_device_SetTransform,
|
---|
3436 | d3d9_device_GetTransform,
|
---|
3437 | d3d9_device_MultiplyTransform,
|
---|
3438 | d3d9_device_SetViewport,
|
---|
3439 | d3d9_device_GetViewport,
|
---|
3440 | d3d9_device_SetMaterial,
|
---|
3441 | d3d9_device_GetMaterial,
|
---|
3442 | d3d9_device_SetLight,
|
---|
3443 | d3d9_device_GetLight,
|
---|
3444 | d3d9_device_LightEnable,
|
---|
3445 | d3d9_device_GetLightEnable,
|
---|
3446 | d3d9_device_SetClipPlane,
|
---|
3447 | d3d9_device_GetClipPlane,
|
---|
3448 | d3d9_device_SetRenderState,
|
---|
3449 | d3d9_device_GetRenderState,
|
---|
3450 | d3d9_device_CreateStateBlock,
|
---|
3451 | d3d9_device_BeginStateBlock,
|
---|
3452 | d3d9_device_EndStateBlock,
|
---|
3453 | d3d9_device_SetClipStatus,
|
---|
3454 | d3d9_device_GetClipStatus,
|
---|
3455 | d3d9_device_GetTexture,
|
---|
3456 | d3d9_device_SetTexture,
|
---|
3457 | d3d9_device_GetTextureStageState,
|
---|
3458 | d3d9_device_SetTextureStageState,
|
---|
3459 | d3d9_device_GetSamplerState,
|
---|
3460 | d3d9_device_SetSamplerState,
|
---|
3461 | d3d9_device_ValidateDevice,
|
---|
3462 | d3d9_device_SetPaletteEntries,
|
---|
3463 | d3d9_device_GetPaletteEntries,
|
---|
3464 | d3d9_device_SetCurrentTexturePalette,
|
---|
3465 | d3d9_device_GetCurrentTexturePalette,
|
---|
3466 | d3d9_device_SetScissorRect,
|
---|
3467 | d3d9_device_GetScissorRect,
|
---|
3468 | d3d9_device_SetSoftwareVertexProcessing,
|
---|
3469 | d3d9_device_GetSoftwareVertexProcessing,
|
---|
3470 | d3d9_device_SetNPatchMode,
|
---|
3471 | d3d9_device_GetNPatchMode,
|
---|
3472 | d3d9_device_DrawPrimitive,
|
---|
3473 | d3d9_device_DrawIndexedPrimitive,
|
---|
3474 | d3d9_device_DrawPrimitiveUP,
|
---|
3475 | d3d9_device_DrawIndexedPrimitiveUP,
|
---|
3476 | d3d9_device_ProcessVertices,
|
---|
3477 | d3d9_device_CreateVertexDeclaration,
|
---|
3478 | d3d9_device_SetVertexDeclaration,
|
---|
3479 | d3d9_device_GetVertexDeclaration,
|
---|
3480 | d3d9_device_SetFVF,
|
---|
3481 | d3d9_device_GetFVF,
|
---|
3482 | d3d9_device_CreateVertexShader,
|
---|
3483 | d3d9_device_SetVertexShader,
|
---|
3484 | d3d9_device_GetVertexShader,
|
---|
3485 | d3d9_device_SetVertexShaderConstantF,
|
---|
3486 | d3d9_device_GetVertexShaderConstantF,
|
---|
3487 | d3d9_device_SetVertexShaderConstantI,
|
---|
3488 | d3d9_device_GetVertexShaderConstantI,
|
---|
3489 | d3d9_device_SetVertexShaderConstantB,
|
---|
3490 | d3d9_device_GetVertexShaderConstantB,
|
---|
3491 | d3d9_device_SetStreamSource,
|
---|
3492 | d3d9_device_GetStreamSource,
|
---|
3493 | d3d9_device_SetStreamSourceFreq,
|
---|
3494 | d3d9_device_GetStreamSourceFreq,
|
---|
3495 | d3d9_device_SetIndices,
|
---|
3496 | d3d9_device_GetIndices,
|
---|
3497 | d3d9_device_CreatePixelShader,
|
---|
3498 | d3d9_device_SetPixelShader,
|
---|
3499 | d3d9_device_GetPixelShader,
|
---|
3500 | d3d9_device_SetPixelShaderConstantF,
|
---|
3501 | d3d9_device_GetPixelShaderConstantF,
|
---|
3502 | d3d9_device_SetPixelShaderConstantI,
|
---|
3503 | d3d9_device_GetPixelShaderConstantI,
|
---|
3504 | d3d9_device_SetPixelShaderConstantB,
|
---|
3505 | d3d9_device_GetPixelShaderConstantB,
|
---|
3506 | d3d9_device_DrawRectPatch,
|
---|
3507 | d3d9_device_DrawTriPatch,
|
---|
3508 | d3d9_device_DeletePatch,
|
---|
3509 | d3d9_device_CreateQuery,
|
---|
3510 | /* IDirect3DDevice9Ex */
|
---|
3511 | d3d9_device_SetConvolutionMonoKernel,
|
---|
3512 | d3d9_device_ComposeRects,
|
---|
3513 | d3d9_device_PresentEx,
|
---|
3514 | d3d9_device_GetGPUThreadPriority,
|
---|
3515 | d3d9_device_SetGPUThreadPriority,
|
---|
3516 | d3d9_device_WaitForVBlank,
|
---|
3517 | d3d9_device_CheckResourceResidency,
|
---|
3518 | d3d9_device_SetMaximumFrameLatency,
|
---|
3519 | d3d9_device_GetMaximumFrameLatency,
|
---|
3520 | d3d9_device_CheckDeviceState,
|
---|
3521 | d3d9_device_CreateRenderTargetEx,
|
---|
3522 | d3d9_device_CreateOffscreenPlainSurfaceEx,
|
---|
3523 | d3d9_device_CreateDepthStencilSurfaceEx,
|
---|
3524 | d3d9_device_ResetEx,
|
---|
3525 | d3d9_device_GetDisplayModeEx,
|
---|
3526 | };
|
---|
3527 |
|
---|
3528 | static inline struct d3d9_device *device_from_device_parent(struct wined3d_device_parent *device_parent)
|
---|
3529 | {
|
---|
3530 | return CONTAINING_RECORD(device_parent, struct d3d9_device, device_parent);
|
---|
3531 | }
|
---|
3532 |
|
---|
3533 | static void CDECL device_parent_wined3d_device_created(struct wined3d_device_parent *device_parent,
|
---|
3534 | struct wined3d_device *device)
|
---|
3535 | {
|
---|
3536 | TRACE("device_parent %p, device %p.\n", device_parent, device);
|
---|
3537 | }
|
---|
3538 |
|
---|
3539 | static void CDECL device_parent_mode_changed(struct wined3d_device_parent *device_parent)
|
---|
3540 | {
|
---|
3541 | TRACE("device_parent %p.\n", device_parent);
|
---|
3542 | }
|
---|
3543 |
|
---|
3544 | static HRESULT CDECL device_parent_create_texture_surface(struct wined3d_device_parent *device_parent,
|
---|
3545 | void *container_parent, const struct wined3d_resource_desc *desc, UINT sub_resource_idx,
|
---|
3546 | DWORD flags, struct wined3d_surface **surface
|
---|
3547 | #ifdef VBOX_WITH_WDDM
|
---|
3548 | , HANDLE *shared_handle
|
---|
3549 | , void *pvClientMem
|
---|
3550 | #endif
|
---|
3551 | )
|
---|
3552 | {
|
---|
3553 | struct d3d9_device *device = device_from_device_parent(device_parent);
|
---|
3554 | struct d3d9_surface *d3d_surface;
|
---|
3555 | HRESULT hr;
|
---|
3556 |
|
---|
3557 | TRACE("device_parent %p, container_parent %p, desc %p, sub_resource_idx %u, flags %#x, surface %p.\n",
|
---|
3558 | device_parent, container_parent, desc, sub_resource_idx, flags, surface);
|
---|
3559 |
|
---|
3560 | #ifdef VBOX_WITH_WDDM
|
---|
3561 | if (FAILED(hr = d3d9_device_create_surface(device, desc->width, desc->height,
|
---|
3562 | d3dformat_from_wined3dformat(desc->format), flags, (IDirect3DSurface9 **)&d3d_surface,
|
---|
3563 | desc->usage, desc->pool, desc->multisample_type, desc->multisample_quality
|
---|
3564 | , shared_handle
|
---|
3565 | , pvClientMem
|
---|
3566 | )))
|
---|
3567 | #else
|
---|
3568 | if (FAILED(hr = d3d9_device_create_surface(device, desc->width, desc->height,
|
---|
3569 | d3dformat_from_wined3dformat(desc->format), flags, (IDirect3DSurface9 **)&d3d_surface,
|
---|
3570 | desc->usage, desc->pool, desc->multisample_type, desc->multisample_quality)))
|
---|
3571 | #endif
|
---|
3572 | {
|
---|
3573 | WARN("Failed to create surface, hr %#x.\n", hr);
|
---|
3574 | return hr;
|
---|
3575 | }
|
---|
3576 |
|
---|
3577 | *surface = d3d_surface->wined3d_surface;
|
---|
3578 | wined3d_surface_incref(*surface);
|
---|
3579 |
|
---|
3580 | d3d_surface->container = container_parent;
|
---|
3581 | IDirect3DDevice9Ex_Release(d3d_surface->parent_device);
|
---|
3582 | d3d_surface->parent_device = NULL;
|
---|
3583 |
|
---|
3584 | IDirect3DSurface9_Release(&d3d_surface->IDirect3DSurface9_iface);
|
---|
3585 | d3d_surface->forwardReference = container_parent;
|
---|
3586 |
|
---|
3587 | return hr;
|
---|
3588 | }
|
---|
3589 |
|
---|
3590 | static HRESULT CDECL device_parent_create_swapchain_surface(struct wined3d_device_parent *device_parent,
|
---|
3591 | void *container_parent, const struct wined3d_resource_desc *desc, struct wined3d_surface **surface)
|
---|
3592 | {
|
---|
3593 | struct d3d9_device *device = device_from_device_parent(device_parent);
|
---|
3594 | struct wined3d_resource_desc texture_desc;
|
---|
3595 | struct d3d9_surface *d3d_surface;
|
---|
3596 | struct wined3d_texture *texture;
|
---|
3597 | HRESULT hr;
|
---|
3598 |
|
---|
3599 | TRACE("device_parent %p, container_parent %p, desc %p, surface %p.\n",
|
---|
3600 | device_parent, container_parent, desc, surface);
|
---|
3601 |
|
---|
3602 | if (container_parent == device_parent)
|
---|
3603 | container_parent = &device->IDirect3DDevice9Ex_iface;
|
---|
3604 |
|
---|
3605 | texture_desc = *desc;
|
---|
3606 | texture_desc.resource_type = WINED3D_RTYPE_TEXTURE;
|
---|
3607 | #ifdef VBOX_WITH_WDDM
|
---|
3608 | if (FAILED(hr = wined3d_texture_create_2d(device->wined3d_device, &texture_desc, 1,
|
---|
3609 | WINED3D_SURFACE_MAPPABLE, container_parent, &d3d9_null_wined3d_parent_ops, &texture
|
---|
3610 | , NULL, NULL)))
|
---|
3611 | #else
|
---|
3612 | if (FAILED(hr = wined3d_texture_create_2d(device->wined3d_device, &texture_desc, 1,
|
---|
3613 | WINED3D_SURFACE_MAPPABLE, container_parent, &d3d9_null_wined3d_parent_ops, &texture)))
|
---|
3614 | #endif
|
---|
3615 | {
|
---|
3616 | WARN("Failed to create texture, hr %#x.\n", hr);
|
---|
3617 | return hr;
|
---|
3618 | }
|
---|
3619 |
|
---|
3620 | *surface = wined3d_surface_from_resource(wined3d_texture_get_sub_resource(texture, 0));
|
---|
3621 | wined3d_surface_incref(*surface);
|
---|
3622 | wined3d_texture_decref(texture);
|
---|
3623 |
|
---|
3624 | d3d_surface = wined3d_surface_get_parent(*surface);
|
---|
3625 | d3d_surface->forwardReference = NULL;
|
---|
3626 | d3d_surface->parent_device = &device->IDirect3DDevice9Ex_iface;
|
---|
3627 | return hr;
|
---|
3628 | }
|
---|
3629 |
|
---|
3630 | static HRESULT CDECL device_parent_create_volume(struct wined3d_device_parent *device_parent,
|
---|
3631 | void *container_parent, UINT width, UINT height, UINT depth, enum wined3d_format_id format,
|
---|
3632 | enum wined3d_pool pool, DWORD usage, struct wined3d_volume **volume
|
---|
3633 | #ifdef VBOX_WITH_WDDM
|
---|
3634 | , HANDLE *shared_handle
|
---|
3635 | , void *pvClientMem
|
---|
3636 | #endif
|
---|
3637 | )
|
---|
3638 | {
|
---|
3639 | struct d3d9_device *device = device_from_device_parent(device_parent);
|
---|
3640 | struct d3d9_volume *object;
|
---|
3641 | HRESULT hr;
|
---|
3642 |
|
---|
3643 | TRACE("device_parent %p, container_parent %p, width %u, height %u, depth %u, "
|
---|
3644 | "format %#x, pool %#x, usage %#x, volume %p\n",
|
---|
3645 | device_parent, container_parent, width, height, depth,
|
---|
3646 | format, pool, usage, volume);
|
---|
3647 |
|
---|
3648 | /* Allocate the storage for the device */
|
---|
3649 | object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
|
---|
3650 | if (!object)
|
---|
3651 | {
|
---|
3652 | FIXME("Allocation of memory failed\n");
|
---|
3653 | *volume = NULL;
|
---|
3654 | return D3DERR_OUTOFVIDEOMEMORY;
|
---|
3655 | }
|
---|
3656 |
|
---|
3657 | hr = volume_init(object, device, width, height, depth, usage, format, pool
|
---|
3658 | #ifdef VBOX_WITH_WDDM
|
---|
3659 | , shared_handle
|
---|
3660 | , pvClientMem
|
---|
3661 | #endif
|
---|
3662 | );
|
---|
3663 | if (FAILED(hr))
|
---|
3664 | {
|
---|
3665 | WARN("Failed to initialize volume, hr %#x.\n", hr);
|
---|
3666 | HeapFree(GetProcessHeap(), 0, object);
|
---|
3667 | return hr;
|
---|
3668 | }
|
---|
3669 |
|
---|
3670 | *volume = object->wined3d_volume;
|
---|
3671 | wined3d_volume_incref(*volume);
|
---|
3672 | IDirect3DVolume9_Release(&object->IDirect3DVolume9_iface);
|
---|
3673 |
|
---|
3674 | object->container = container_parent;
|
---|
3675 | object->forwardReference = container_parent;
|
---|
3676 |
|
---|
3677 | TRACE("Created volume %p.\n", object);
|
---|
3678 |
|
---|
3679 | return hr;
|
---|
3680 | }
|
---|
3681 |
|
---|
3682 | static HRESULT CDECL device_parent_create_swapchain(struct wined3d_device_parent *device_parent,
|
---|
3683 | struct wined3d_swapchain_desc *desc, struct wined3d_swapchain **swapchain)
|
---|
3684 | {
|
---|
3685 | struct d3d9_device *device = device_from_device_parent(device_parent);
|
---|
3686 | struct d3d9_swapchain *d3d_swapchain;
|
---|
3687 | HRESULT hr;
|
---|
3688 |
|
---|
3689 | TRACE("device_parent %p, desc %p, swapchain %p\n", device_parent, desc, swapchain);
|
---|
3690 |
|
---|
3691 | hr = d3d9_swapchain_create(device, desc, &d3d_swapchain);
|
---|
3692 | if (FAILED(hr))
|
---|
3693 | {
|
---|
3694 | WARN("Failed to create swapchain, hr %#x.\n", hr);
|
---|
3695 | *swapchain = NULL;
|
---|
3696 | return hr;
|
---|
3697 | }
|
---|
3698 |
|
---|
3699 | *swapchain = d3d_swapchain->wined3d_swapchain;
|
---|
3700 | wined3d_swapchain_incref(*swapchain);
|
---|
3701 | IDirect3DSwapChain9_Release(&d3d_swapchain->IDirect3DSwapChain9_iface);
|
---|
3702 |
|
---|
3703 | return hr;
|
---|
3704 | }
|
---|
3705 |
|
---|
3706 | static const struct wined3d_device_parent_ops d3d9_wined3d_device_parent_ops =
|
---|
3707 | {
|
---|
3708 | device_parent_wined3d_device_created,
|
---|
3709 | device_parent_mode_changed,
|
---|
3710 | device_parent_create_swapchain_surface,
|
---|
3711 | device_parent_create_texture_surface,
|
---|
3712 | device_parent_create_volume,
|
---|
3713 | device_parent_create_swapchain,
|
---|
3714 | };
|
---|
3715 |
|
---|
3716 | static void setup_fpu(void)
|
---|
3717 | {
|
---|
3718 | #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))
|
---|
3719 | WORD cw;
|
---|
3720 | __asm__ volatile ("fnstcw %0" : "=m" (cw));
|
---|
3721 | cw = (cw & ~0xf3f) | 0x3f;
|
---|
3722 | __asm__ volatile ("fldcw %0" : : "m" (cw));
|
---|
3723 | #elif defined(__i386__) && defined(_MSC_VER)
|
---|
3724 | WORD cw;
|
---|
3725 | __asm fnstcw cw;
|
---|
3726 | cw = (cw & ~0xf3f) | 0x3f;
|
---|
3727 | __asm fldcw cw;
|
---|
3728 | #elif defined(RT_ARCH_AMD64)
|
---|
3729 | /* @todo: impl*/
|
---|
3730 | #else
|
---|
3731 | FIXME("FPU setup not implemented for this platform.\n");
|
---|
3732 | #endif
|
---|
3733 | }
|
---|
3734 |
|
---|
3735 | HRESULT device_init(struct d3d9_device *device, struct d3d9 *parent, struct wined3d *wined3d,
|
---|
3736 | UINT adapter, D3DDEVTYPE device_type, HWND focus_window, DWORD flags
|
---|
3737 | #ifdef VBOX_WITH_WDDM
|
---|
3738 | , VBOXWINEEX_D3DPRESENT_PARAMETERS *parameters
|
---|
3739 | #else
|
---|
3740 | , D3DPRESENT_PARAMETERS *parameters
|
---|
3741 | #endif
|
---|
3742 | , D3DDISPLAYMODEEX *mode)
|
---|
3743 | {
|
---|
3744 | struct wined3d_swapchain_desc *swapchain_desc;
|
---|
3745 | UINT i, count = 1;
|
---|
3746 | HRESULT hr;
|
---|
3747 |
|
---|
3748 | if (mode)
|
---|
3749 | FIXME("Ignoring display mode.\n");
|
---|
3750 |
|
---|
3751 | device->IDirect3DDevice9Ex_iface.lpVtbl = &d3d9_device_vtbl;
|
---|
3752 | device->device_parent.ops = &d3d9_wined3d_device_parent_ops;
|
---|
3753 | device->refcount = 1;
|
---|
3754 |
|
---|
3755 | if (!(flags & D3DCREATE_FPU_PRESERVE)) setup_fpu();
|
---|
3756 |
|
---|
3757 | wined3d_mutex_lock();
|
---|
3758 | hr = wined3d_device_create(wined3d, adapter, device_type, focus_window, flags, 4,
|
---|
3759 | &device->device_parent, &device->wined3d_device);
|
---|
3760 | if (FAILED(hr))
|
---|
3761 | {
|
---|
3762 | WARN("Failed to create wined3d device, hr %#x.\n", hr);
|
---|
3763 | wined3d_mutex_unlock();
|
---|
3764 | return hr;
|
---|
3765 | }
|
---|
3766 |
|
---|
3767 | if (flags & D3DCREATE_ADAPTERGROUP_DEVICE)
|
---|
3768 | {
|
---|
3769 | WINED3DCAPS caps;
|
---|
3770 |
|
---|
3771 | wined3d_get_device_caps(wined3d, adapter, device_type, &caps);
|
---|
3772 | count = caps.NumberOfAdaptersInGroup;
|
---|
3773 | }
|
---|
3774 |
|
---|
3775 | if (flags & D3DCREATE_MULTITHREADED)
|
---|
3776 | wined3d_device_set_multithreaded(device->wined3d_device);
|
---|
3777 |
|
---|
3778 | #ifndef VBOX_WITH_WDDM
|
---|
3779 | if (!parameters->Windowed)
|
---|
3780 | {
|
---|
3781 | if (!focus_window)
|
---|
3782 | focus_window = parameters->hDeviceWindow;
|
---|
3783 | if (FAILED(hr = wined3d_device_acquire_focus_window(device->wined3d_device, focus_window)))
|
---|
3784 | {
|
---|
3785 | ERR("Failed to acquire focus window, hr %#x.\n", hr);
|
---|
3786 | wined3d_device_decref(device->wined3d_device);
|
---|
3787 | wined3d_mutex_unlock();
|
---|
3788 | return hr;
|
---|
3789 | }
|
---|
3790 |
|
---|
3791 | for (i = 0; i < count; ++i)
|
---|
3792 | {
|
---|
3793 | HWND device_window = parameters[i].hDeviceWindow;
|
---|
3794 |
|
---|
3795 | if (!device_window) device_window = focus_window;
|
---|
3796 | wined3d_device_setup_fullscreen_window(device->wined3d_device, device_window,
|
---|
3797 | parameters[i].BackBufferWidth,
|
---|
3798 | parameters[i].BackBufferHeight);
|
---|
3799 | }
|
---|
3800 | }
|
---|
3801 | #else
|
---|
3802 | if (!parameters->Base.Windowed)
|
---|
3803 | {
|
---|
3804 | ERR("non-windowed mode unsupported!");
|
---|
3805 | parameters->Base.Windowed = TRUE;
|
---|
3806 | }
|
---|
3807 | #endif
|
---|
3808 |
|
---|
3809 | swapchain_desc = HeapAlloc(GetProcessHeap(), 0, sizeof(*swapchain_desc) * count);
|
---|
3810 | if (!swapchain_desc)
|
---|
3811 | {
|
---|
3812 | ERR("Failed to allocate wined3d parameters.\n");
|
---|
3813 | wined3d_device_decref(device->wined3d_device);
|
---|
3814 | wined3d_mutex_unlock();
|
---|
3815 | return E_OUTOFMEMORY;
|
---|
3816 | }
|
---|
3817 |
|
---|
3818 | for (i = 0; i < count; ++i)
|
---|
3819 | {
|
---|
3820 | #ifdef VBOX_WITH_WDDM
|
---|
3821 | wined3d_swapchain_desc_from_present_parameters(&swapchain_desc[i], ¶meters[i].Base);
|
---|
3822 | swapchain_desc[i].pHgsmi = parameters[i].pHgsmi;
|
---|
3823 | #else
|
---|
3824 | wined3d_swapchain_desc_from_present_parameters(&swapchain_desc[i], ¶meters[i]);
|
---|
3825 | #endif
|
---|
3826 | }
|
---|
3827 |
|
---|
3828 | hr = wined3d_device_init_3d(device->wined3d_device, swapchain_desc);
|
---|
3829 | if (FAILED(hr))
|
---|
3830 | {
|
---|
3831 | WARN("Failed to initialize 3D, hr %#x.\n", hr);
|
---|
3832 | #ifndef VBOX_WITH_WDDM
|
---|
3833 | wined3d_device_release_focus_window(device->wined3d_device);
|
---|
3834 | #endif
|
---|
3835 | HeapFree(GetProcessHeap(), 0, swapchain_desc);
|
---|
3836 | wined3d_device_decref(device->wined3d_device);
|
---|
3837 | wined3d_mutex_unlock();
|
---|
3838 | return hr;
|
---|
3839 | }
|
---|
3840 |
|
---|
3841 | wined3d_mutex_unlock();
|
---|
3842 |
|
---|
3843 | for (i = 0; i < count; ++i)
|
---|
3844 | {
|
---|
3845 | #ifndef VBOX_WITH_WDDM
|
---|
3846 | present_parameters_from_wined3d_swapchain_desc(¶meters[i], &swapchain_desc[i]);
|
---|
3847 | #else
|
---|
3848 | present_parameters_from_wined3d_swapchain_desc(¶meters[i].Base, &swapchain_desc[i]);
|
---|
3849 | #endif
|
---|
3850 | }
|
---|
3851 | HeapFree(GetProcessHeap(), 0, swapchain_desc);
|
---|
3852 |
|
---|
3853 | /* Initialize the converted declaration array. This creates a valid pointer
|
---|
3854 | * and when adding decls HeapReAlloc() can be used without further checking. */
|
---|
3855 | device->fvf_decls = HeapAlloc(GetProcessHeap(), 0, 0);
|
---|
3856 | if (!device->fvf_decls)
|
---|
3857 | {
|
---|
3858 | ERR("Failed to allocate FVF vertex declaration map memory.\n");
|
---|
3859 | wined3d_mutex_lock();
|
---|
3860 | wined3d_device_uninit_3d(device->wined3d_device);
|
---|
3861 | #ifndef VBOX_WITH_WDDM
|
---|
3862 | wined3d_device_release_focus_window(device->wined3d_device);
|
---|
3863 | #endif
|
---|
3864 | wined3d_device_decref(device->wined3d_device);
|
---|
3865 | wined3d_mutex_unlock();
|
---|
3866 | return E_OUTOFMEMORY;
|
---|
3867 | }
|
---|
3868 |
|
---|
3869 | IDirect3D9Ex_AddRef(&parent->IDirect3D9Ex_iface);
|
---|
3870 | device->d3d_parent = parent;
|
---|
3871 |
|
---|
3872 | return D3D_OK;
|
---|
3873 | }
|
---|
3874 |
|
---|
3875 | #ifdef VBOX_WITH_WDDM
|
---|
3876 | AssertCompile(sizeof (struct wined3d_box) == sizeof (VBOXBOX3D));
|
---|
3877 | AssertCompile(RT_SIZEOFMEMB(struct wined3d_box, left) == RT_SIZEOFMEMB(VBOXBOX3D, Left));
|
---|
3878 | AssertCompile(RT_SIZEOFMEMB(struct wined3d_box, top) == RT_SIZEOFMEMB(VBOXBOX3D, Top));
|
---|
3879 | AssertCompile(RT_SIZEOFMEMB(struct wined3d_box, right) == RT_SIZEOFMEMB(VBOXBOX3D, Right));
|
---|
3880 | AssertCompile(RT_SIZEOFMEMB(struct wined3d_box, bottom) == RT_SIZEOFMEMB(VBOXBOX3D, Bottom));
|
---|
3881 | AssertCompile(RT_SIZEOFMEMB(struct wined3d_box, front) == RT_SIZEOFMEMB(VBOXBOX3D, Front));
|
---|
3882 | AssertCompile(RT_SIZEOFMEMB(struct wined3d_box, back) == RT_SIZEOFMEMB(VBOXBOX3D, Back));
|
---|
3883 |
|
---|
3884 | AssertCompile(RT_OFFSETOF(struct wined3d_box, left) == RT_OFFSETOF(VBOXBOX3D, Left));
|
---|
3885 | AssertCompile(RT_OFFSETOF(struct wined3d_box, top) == RT_OFFSETOF(VBOXBOX3D, Top));
|
---|
3886 | AssertCompile(RT_OFFSETOF(struct wined3d_box, right) == RT_OFFSETOF(VBOXBOX3D, Right));
|
---|
3887 | AssertCompile(RT_OFFSETOF(struct wined3d_box, bottom) == RT_OFFSETOF(VBOXBOX3D, Bottom));
|
---|
3888 | AssertCompile(RT_OFFSETOF(struct wined3d_box, front) == RT_OFFSETOF(VBOXBOX3D, Front));
|
---|
3889 | AssertCompile(RT_OFFSETOF(struct wined3d_box, back) == RT_OFFSETOF(VBOXBOX3D, Back));
|
---|
3890 |
|
---|
3891 | VBOXWINEEX_DECL(HRESULT) VBoxWineExD3DDev9VolBlt(IDirect3DDevice9Ex *iface,
|
---|
3892 | IDirect3DVolume9 *pSourceVolume, IDirect3DVolume9 *pDestinationVolume,
|
---|
3893 | const VBOXBOX3D *pSrcBoxArg,
|
---|
3894 | const VBOXPOINT3D *pDstPoin3D)
|
---|
3895 | {
|
---|
3896 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
3897 | struct d3d9_volume *src = unsafe_impl_from_IDirect3DVolume9(pSourceVolume);
|
---|
3898 | struct d3d9_volume *dst = unsafe_impl_from_IDirect3DVolume9(pDestinationVolume);
|
---|
3899 | HRESULT hr;
|
---|
3900 |
|
---|
3901 | wined3d_mutex_lock();
|
---|
3902 | hr = wined3d_device_blt_vol(device->wined3d_device, src->wined3d_volume, dst->wined3d_volume, (struct wined3d_box*)pSrcBoxArg, pDstPoin3D);
|
---|
3903 | wined3d_mutex_unlock();
|
---|
3904 |
|
---|
3905 | return hr;
|
---|
3906 | }
|
---|
3907 |
|
---|
3908 | VBOXWINEEX_DECL(HRESULT) VBoxWineExD3DDev9VolTexBlt(IDirect3DDevice9Ex *iface,
|
---|
3909 | IDirect3DVolumeTexture9 *pSourceTexture, IDirect3DVolumeTexture9 *pDestinationTexture,
|
---|
3910 | const VBOXBOX3D *pSrcBoxArg,
|
---|
3911 | const VBOXPOINT3D *pDstPoin3D)
|
---|
3912 | {
|
---|
3913 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
3914 | struct d3d9_texture *src = unsafe_impl_from_IDirect3DBaseTexture9((IDirect3DBaseTexture9*)pSourceTexture);
|
---|
3915 | struct d3d9_texture *dst = unsafe_impl_from_IDirect3DBaseTexture9((IDirect3DBaseTexture9*)pDestinationTexture);
|
---|
3916 | HRESULT hr;
|
---|
3917 |
|
---|
3918 | wined3d_mutex_lock();
|
---|
3919 | hr = wined3d_device_blt_voltex(device->wined3d_device, src->wined3d_texture, dst->wined3d_texture, (struct wined3d_box*)pSrcBoxArg, pDstPoin3D);
|
---|
3920 | wined3d_mutex_unlock();
|
---|
3921 |
|
---|
3922 | return hr;
|
---|
3923 | }
|
---|
3924 |
|
---|
3925 | VBOXWINEEX_DECL(HRESULT) VBoxWineExD3DDev9Term(IDirect3DDevice9Ex *iface)
|
---|
3926 | {
|
---|
3927 | struct d3d9_device *device = impl_from_IDirect3DDevice9Ex(iface);
|
---|
3928 | struct wined3d_device *wined3d_device = device->wined3d_device;
|
---|
3929 | LONG wined3d_refs;
|
---|
3930 | if (device->refcount != 1)
|
---|
3931 | {
|
---|
3932 | WARN("unexpected ref count %d, destroying in anyway", device->refcount);
|
---|
3933 | }
|
---|
3934 | wined3d_refs = d3d9_device_Term(device);
|
---|
3935 | if (wined3d_refs)
|
---|
3936 | {
|
---|
3937 | ERR("unexpected wined3dRefs %d, destroying in anyway", wined3d_refs);
|
---|
3938 | while (wined3d_device_decref(wined3d_device)) {}
|
---|
3939 | }
|
---|
3940 | return D3D_OK;
|
---|
3941 | }
|
---|
3942 | #endif
|
---|