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