d3d10core: Implement d3d10_device_UpdateSubresource().
[wine.git] / dlls / d3d10core / device.c
blob05e8de552bf334cfff13ad0ed1238679ae9080a8
1 /*
2 * Copyright 2008-2012 Henri Verbeet for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "config.h"
21 #include "wine/port.h"
23 #include "d3d10core_private.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(d3d10core);
27 static void STDMETHODCALLTYPE d3d10_null_wined3d_object_destroyed(void *parent) {}
29 const struct wined3d_parent_ops d3d10_null_wined3d_parent_ops =
31 d3d10_null_wined3d_object_destroyed,
34 /* Inner IUnknown methods */
36 static inline struct d3d10_device *impl_from_IUnknown(IUnknown *iface)
38 return CONTAINING_RECORD(iface, struct d3d10_device, IUnknown_inner);
41 static HRESULT STDMETHODCALLTYPE d3d10_device_inner_QueryInterface(IUnknown *iface, REFIID riid, void **out)
43 struct d3d10_device *device = impl_from_IUnknown(iface);
45 TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
47 if (IsEqualGUID(riid, &IID_ID3D10Device1)
48 || IsEqualGUID(riid, &IID_ID3D10Device)
49 || IsEqualGUID(riid, &IID_IUnknown))
51 *out = &device->ID3D10Device1_iface;
53 else if (IsEqualGUID(riid, &IID_ID3D10Multithread))
55 *out = &device->ID3D10Multithread_iface;
57 else if (IsEqualGUID(riid, &IID_IWineDXGIDeviceParent))
59 *out = &device->IWineDXGIDeviceParent_iface;
61 else
63 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
64 *out = NULL;
65 return E_NOINTERFACE;
68 IUnknown_AddRef((IUnknown *)*out);
69 return S_OK;
72 static ULONG STDMETHODCALLTYPE d3d10_device_inner_AddRef(IUnknown *iface)
74 struct d3d10_device *This = impl_from_IUnknown(iface);
75 ULONG refcount = InterlockedIncrement(&This->refcount);
77 TRACE("%p increasing refcount to %u\n", This, refcount);
79 return refcount;
82 static ULONG STDMETHODCALLTYPE d3d10_device_inner_Release(IUnknown *iface)
84 struct d3d10_device *device = impl_from_IUnknown(iface);
85 ULONG refcount = InterlockedDecrement(&device->refcount);
87 TRACE("%p decreasing refcount to %u.\n", device, refcount);
89 if (!refcount)
91 if (device->wined3d_device)
93 wined3d_mutex_lock();
94 wined3d_device_decref(device->wined3d_device);
95 wined3d_mutex_unlock();
97 wine_rb_destroy(&device->sampler_states, NULL, NULL);
98 wine_rb_destroy(&device->rasterizer_states, NULL, NULL);
99 wine_rb_destroy(&device->depthstencil_states, NULL, NULL);
100 wine_rb_destroy(&device->blend_states, NULL, NULL);
103 return refcount;
106 /* IUnknown methods */
108 static HRESULT STDMETHODCALLTYPE d3d10_device_QueryInterface(ID3D10Device1 *iface, REFIID riid,
109 void **ppv)
111 struct d3d10_device *This = impl_from_ID3D10Device(iface);
112 return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
115 static ULONG STDMETHODCALLTYPE d3d10_device_AddRef(ID3D10Device1 *iface)
117 struct d3d10_device *This = impl_from_ID3D10Device(iface);
118 return IUnknown_AddRef(This->outer_unk);
121 static ULONG STDMETHODCALLTYPE d3d10_device_Release(ID3D10Device1 *iface)
123 struct d3d10_device *This = impl_from_ID3D10Device(iface);
124 return IUnknown_Release(This->outer_unk);
127 /* ID3D10Device methods */
129 static void STDMETHODCALLTYPE d3d10_device_VSSetConstantBuffers(ID3D10Device1 *iface,
130 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
132 struct d3d10_device *device = impl_from_ID3D10Device(iface);
133 unsigned int i;
135 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
136 iface, start_slot, buffer_count, buffers);
138 wined3d_mutex_lock();
139 for (i = 0; i < buffer_count; ++i)
141 struct d3d10_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
143 wined3d_device_set_vs_cb(device->wined3d_device, start_slot + i,
144 buffer ? buffer->wined3d_buffer : NULL);
146 wined3d_mutex_unlock();
149 static void STDMETHODCALLTYPE d3d10_device_PSSetShaderResources(ID3D10Device1 *iface,
150 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
152 struct d3d10_device *device = impl_from_ID3D10Device(iface);
153 unsigned int i;
155 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
156 iface, start_slot, view_count, views);
158 wined3d_mutex_lock();
159 for (i = 0; i < view_count; ++i)
161 struct d3d10_shader_resource_view *view = unsafe_impl_from_ID3D10ShaderResourceView(views[i]);
163 wined3d_device_set_ps_resource_view(device->wined3d_device, start_slot + i,
164 view ? view->wined3d_view : NULL);
166 wined3d_mutex_unlock();
169 static void STDMETHODCALLTYPE d3d10_device_PSSetShader(ID3D10Device1 *iface,
170 ID3D10PixelShader *shader)
172 struct d3d10_device *This = impl_from_ID3D10Device(iface);
173 struct d3d10_pixel_shader *ps = unsafe_impl_from_ID3D10PixelShader(shader);
175 TRACE("iface %p, shader %p\n", iface, shader);
177 wined3d_mutex_lock();
178 wined3d_device_set_pixel_shader(This->wined3d_device, ps ? ps->wined3d_shader : NULL);
179 wined3d_mutex_unlock();
182 static void STDMETHODCALLTYPE d3d10_device_PSSetSamplers(ID3D10Device1 *iface,
183 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
185 struct d3d10_device *device = impl_from_ID3D10Device(iface);
186 unsigned int i;
188 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
189 iface, start_slot, sampler_count, samplers);
191 wined3d_mutex_lock();
192 for (i = 0; i < sampler_count; ++i)
194 struct d3d10_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
196 wined3d_device_set_ps_sampler(device->wined3d_device, start_slot + i,
197 sampler ? sampler->wined3d_sampler : NULL);
199 wined3d_mutex_unlock();
202 static void STDMETHODCALLTYPE d3d10_device_VSSetShader(ID3D10Device1 *iface,
203 ID3D10VertexShader *shader)
205 struct d3d10_device *This = impl_from_ID3D10Device(iface);
206 struct d3d10_vertex_shader *vs = unsafe_impl_from_ID3D10VertexShader(shader);
208 TRACE("iface %p, shader %p\n", iface, shader);
210 wined3d_mutex_lock();
211 wined3d_device_set_vertex_shader(This->wined3d_device, vs ? vs->wined3d_shader : NULL);
212 wined3d_mutex_unlock();
215 static void STDMETHODCALLTYPE d3d10_device_DrawIndexed(ID3D10Device1 *iface, UINT index_count,
216 UINT start_index_location, INT base_vertex_location)
218 struct d3d10_device *This = impl_from_ID3D10Device(iface);
220 TRACE("iface %p, index_count %u, start_index_location %u, base_vertex_location %d.\n",
221 iface, index_count, start_index_location, base_vertex_location);
223 wined3d_mutex_lock();
224 wined3d_device_set_base_vertex_index(This->wined3d_device, base_vertex_location);
225 wined3d_device_draw_indexed_primitive(This->wined3d_device, start_index_location, index_count);
226 wined3d_mutex_unlock();
229 static void STDMETHODCALLTYPE d3d10_device_Draw(ID3D10Device1 *iface, UINT vertex_count,
230 UINT start_vertex_location)
232 struct d3d10_device *This = impl_from_ID3D10Device(iface);
234 TRACE("iface %p, vertex_count %u, start_vertex_location %u\n",
235 iface, vertex_count, start_vertex_location);
237 wined3d_mutex_lock();
238 wined3d_device_draw_primitive(This->wined3d_device, start_vertex_location, vertex_count);
239 wined3d_mutex_unlock();
242 static void STDMETHODCALLTYPE d3d10_device_PSSetConstantBuffers(ID3D10Device1 *iface,
243 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
245 struct d3d10_device *device = impl_from_ID3D10Device(iface);
246 unsigned int i;
248 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
249 iface, start_slot, buffer_count, buffers);
251 wined3d_mutex_lock();
252 for (i = 0; i < buffer_count; ++i)
254 struct d3d10_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
256 wined3d_device_set_ps_cb(device->wined3d_device, start_slot + i,
257 buffer ? buffer->wined3d_buffer : NULL);
259 wined3d_mutex_unlock();
262 static void STDMETHODCALLTYPE d3d10_device_IASetInputLayout(ID3D10Device1 *iface,
263 ID3D10InputLayout *input_layout)
265 struct d3d10_device *This = impl_from_ID3D10Device(iface);
266 struct d3d10_input_layout *layout = unsafe_impl_from_ID3D10InputLayout(input_layout);
268 TRACE("iface %p, input_layout %p\n", iface, input_layout);
270 wined3d_mutex_lock();
271 wined3d_device_set_vertex_declaration(This->wined3d_device,
272 layout ? layout->wined3d_decl : NULL);
273 wined3d_mutex_unlock();
276 static void STDMETHODCALLTYPE d3d10_device_IASetVertexBuffers(ID3D10Device1 *iface, UINT start_slot,
277 UINT buffer_count, ID3D10Buffer *const *buffers, const UINT *strides, const UINT *offsets)
279 struct d3d10_device *This = impl_from_ID3D10Device(iface);
280 unsigned int i;
282 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p\n",
283 iface, start_slot, buffer_count, buffers, strides, offsets);
285 wined3d_mutex_lock();
286 for (i = 0; i < buffer_count; ++i)
288 struct d3d10_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
290 wined3d_device_set_stream_source(This->wined3d_device, start_slot + i,
291 buffer ? buffer->wined3d_buffer : NULL, offsets[i], strides[i]);
293 wined3d_mutex_unlock();
296 static void STDMETHODCALLTYPE d3d10_device_IASetIndexBuffer(ID3D10Device1 *iface,
297 ID3D10Buffer *buffer, DXGI_FORMAT format, UINT offset)
299 struct d3d10_device *This = impl_from_ID3D10Device(iface);
300 struct d3d10_buffer *buffer_impl = unsafe_impl_from_ID3D10Buffer(buffer);
302 TRACE("iface %p, buffer %p, format %s, offset %u.\n",
303 iface, buffer, debug_dxgi_format(format), offset);
305 wined3d_mutex_lock();
306 wined3d_device_set_index_buffer(This->wined3d_device,
307 buffer_impl ? buffer_impl->wined3d_buffer : NULL,
308 wined3dformat_from_dxgi_format(format));
309 wined3d_mutex_unlock();
310 if (offset) FIXME("offset %u not supported.\n", offset);
313 static void STDMETHODCALLTYPE d3d10_device_DrawIndexedInstanced(ID3D10Device1 *iface,
314 UINT instance_index_count, UINT instance_count, UINT start_index_location,
315 INT base_vertex_location, UINT start_instance_location)
317 struct d3d10_device *device = impl_from_ID3D10Device(iface);
319 TRACE("iface %p, instance_index_count %u, instance_count %u, start_index_location %u,\n"
320 "\tbase_vertex_location %d, start_instance_location %u.\n",
321 iface, instance_index_count, instance_count, start_index_location,
322 base_vertex_location, start_instance_location);
324 wined3d_mutex_lock();
325 wined3d_device_set_base_vertex_index(device->wined3d_device, base_vertex_location);
326 wined3d_device_draw_indexed_primitive_instanced(device->wined3d_device, start_index_location,
327 instance_index_count, start_instance_location, instance_count);
328 wined3d_mutex_unlock();
331 static void STDMETHODCALLTYPE d3d10_device_DrawInstanced(ID3D10Device1 *iface,
332 UINT instance_vertex_count, UINT instance_count,
333 UINT start_vertex_location, UINT start_instance_location)
335 struct d3d10_device *device = impl_from_ID3D10Device(iface);
337 TRACE("iface %p, instance_vertex_count %u, instance_count %u, start_vertex_location %u, "
338 "start_instance_location %u.\n", iface, instance_vertex_count, instance_count,
339 start_vertex_location, start_instance_location);
341 wined3d_mutex_lock();
342 wined3d_device_draw_primitive_instanced(device->wined3d_device, start_vertex_location,
343 instance_vertex_count, start_instance_location, instance_count);
344 wined3d_mutex_unlock();
347 static void STDMETHODCALLTYPE d3d10_device_GSSetConstantBuffers(ID3D10Device1 *iface,
348 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
350 struct d3d10_device *device = impl_from_ID3D10Device(iface);
351 unsigned int i;
353 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
354 iface, start_slot, buffer_count, buffers);
356 wined3d_mutex_lock();
357 for (i = 0; i < buffer_count; ++i)
359 struct d3d10_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
361 wined3d_device_set_gs_cb(device->wined3d_device, start_slot + i,
362 buffer ? buffer->wined3d_buffer : NULL);
364 wined3d_mutex_unlock();
367 static void STDMETHODCALLTYPE d3d10_device_GSSetShader(ID3D10Device1 *iface, ID3D10GeometryShader *shader)
369 struct d3d10_device *device = impl_from_ID3D10Device(iface);
370 struct d3d10_geometry_shader *gs = unsafe_impl_from_ID3D10GeometryShader(shader);
372 TRACE("iface %p, shader %p.\n", iface, shader);
374 wined3d_mutex_lock();
375 wined3d_device_set_geometry_shader(device->wined3d_device, gs ? gs->wined3d_shader : NULL);
376 wined3d_mutex_unlock();
379 static void STDMETHODCALLTYPE d3d10_device_IASetPrimitiveTopology(ID3D10Device1 *iface,
380 D3D10_PRIMITIVE_TOPOLOGY topology)
382 struct d3d10_device *This = impl_from_ID3D10Device(iface);
384 TRACE("iface %p, topology %s\n", iface, debug_d3d10_primitive_topology(topology));
386 wined3d_mutex_lock();
387 wined3d_device_set_primitive_type(This->wined3d_device, (enum wined3d_primitive_type)topology);
388 wined3d_mutex_unlock();
391 static void STDMETHODCALLTYPE d3d10_device_VSSetShaderResources(ID3D10Device1 *iface,
392 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
394 struct d3d10_device *device = impl_from_ID3D10Device(iface);
395 unsigned int i;
397 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
398 iface, start_slot, view_count, views);
400 wined3d_mutex_lock();
401 for (i = 0; i < view_count; ++i)
403 struct d3d10_shader_resource_view *view = unsafe_impl_from_ID3D10ShaderResourceView(views[i]);
405 wined3d_device_set_vs_resource_view(device->wined3d_device, start_slot + i,
406 view ? view->wined3d_view : NULL);
408 wined3d_mutex_unlock();
411 static void STDMETHODCALLTYPE d3d10_device_VSSetSamplers(ID3D10Device1 *iface,
412 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
414 struct d3d10_device *device = impl_from_ID3D10Device(iface);
415 unsigned int i;
417 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
418 iface, start_slot, sampler_count, samplers);
420 wined3d_mutex_lock();
421 for (i = 0; i < sampler_count; ++i)
423 struct d3d10_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
425 wined3d_device_set_vs_sampler(device->wined3d_device, start_slot + i,
426 sampler ? sampler->wined3d_sampler : NULL);
428 wined3d_mutex_unlock();
431 static void STDMETHODCALLTYPE d3d10_device_SetPredication(ID3D10Device1 *iface, ID3D10Predicate *predicate, BOOL value)
433 struct d3d10_device *device = impl_from_ID3D10Device(iface);
434 struct d3d10_query *query;
436 TRACE("iface %p, predicate %p, value %#x.\n", iface, predicate, value);
438 query = unsafe_impl_from_ID3D10Query((ID3D10Query *)predicate);
439 wined3d_mutex_lock();
440 wined3d_device_set_predication(device->wined3d_device, query ? query->wined3d_query : NULL, value);
441 wined3d_mutex_unlock();
444 static void STDMETHODCALLTYPE d3d10_device_GSSetShaderResources(ID3D10Device1 *iface,
445 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
447 struct d3d10_device *device = impl_from_ID3D10Device(iface);
448 unsigned int i;
450 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
451 iface, start_slot, view_count, views);
453 wined3d_mutex_lock();
454 for (i = 0; i < view_count; ++i)
456 struct d3d10_shader_resource_view *view = unsafe_impl_from_ID3D10ShaderResourceView(views[i]);
458 wined3d_device_set_gs_resource_view(device->wined3d_device, start_slot + i,
459 view ? view->wined3d_view : NULL);
461 wined3d_mutex_unlock();
464 static void STDMETHODCALLTYPE d3d10_device_GSSetSamplers(ID3D10Device1 *iface,
465 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
467 struct d3d10_device *device = impl_from_ID3D10Device(iface);
468 unsigned int i;
470 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
471 iface, start_slot, sampler_count, samplers);
473 wined3d_mutex_lock();
474 for (i = 0; i < sampler_count; ++i)
476 struct d3d10_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
478 wined3d_device_set_gs_sampler(device->wined3d_device, start_slot + i,
479 sampler ? sampler->wined3d_sampler : NULL);
481 wined3d_mutex_unlock();
484 static void STDMETHODCALLTYPE d3d10_device_OMSetRenderTargets(ID3D10Device1 *iface,
485 UINT render_target_view_count, ID3D10RenderTargetView *const *render_target_views,
486 ID3D10DepthStencilView *depth_stencil_view)
488 struct d3d10_device *device = impl_from_ID3D10Device(iface);
489 struct d3d10_depthstencil_view *dsv;
490 unsigned int i;
492 TRACE("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p.\n",
493 iface, render_target_view_count, render_target_views, depth_stencil_view);
495 wined3d_mutex_lock();
496 for (i = 0; i < render_target_view_count; ++i)
498 struct d3d10_rendertarget_view *rtv = unsafe_impl_from_ID3D10RenderTargetView(render_target_views[i]);
500 wined3d_device_set_rendertarget_view(device->wined3d_device, i,
501 rtv ? rtv->wined3d_view : NULL, FALSE);
503 for (; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
505 wined3d_device_set_rendertarget_view(device->wined3d_device, i, NULL, FALSE);
508 dsv = unsafe_impl_from_ID3D10DepthStencilView(depth_stencil_view);
509 wined3d_device_set_depth_stencil_view(device->wined3d_device,
510 dsv ? dsv->wined3d_view : NULL);
511 wined3d_mutex_unlock();
514 static void STDMETHODCALLTYPE d3d10_device_OMSetBlendState(ID3D10Device1 *iface,
515 ID3D10BlendState *blend_state, const FLOAT blend_factor[4], UINT sample_mask)
517 struct d3d10_device *device = impl_from_ID3D10Device(iface);
518 const D3D10_BLEND_DESC *desc;
520 TRACE("iface %p, blend_state %p, blend_factor {%.8e %.8e %.8e %.8e}, sample_mask 0x%08x.\n",
521 iface, blend_state, blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3], sample_mask);
523 if (blend_factor[0] != 1.0f || blend_factor[1] != 1.0f || blend_factor[2] != 1.0f || blend_factor[3] != 1.0f)
524 FIXME("Ignoring blend factor {%.8e %.8e %.8e %.8e}.\n",
525 blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3]);
526 wined3d_mutex_lock();
527 memcpy(device->blend_factor, blend_factor, 4 * sizeof(*blend_factor));
528 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_MULTISAMPLEMASK, sample_mask);
529 if (!(device->blend_state = unsafe_impl_from_ID3D10BlendState(blend_state)))
531 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ALPHABLENDENABLE, FALSE);
532 wined3d_device_set_render_state(device->wined3d_device,
533 WINED3D_RS_COLORWRITEENABLE, D3D10_COLOR_WRITE_ENABLE_ALL);
534 wined3d_device_set_render_state(device->wined3d_device,
535 WINED3D_RS_COLORWRITEENABLE1, D3D10_COLOR_WRITE_ENABLE_ALL);
536 wined3d_device_set_render_state(device->wined3d_device,
537 WINED3D_RS_COLORWRITEENABLE2, D3D10_COLOR_WRITE_ENABLE_ALL);
538 wined3d_device_set_render_state(device->wined3d_device,
539 WINED3D_RS_COLORWRITEENABLE3, D3D10_COLOR_WRITE_ENABLE_ALL);
540 wined3d_mutex_unlock();
541 return;
544 desc = &device->blend_state->desc;
545 /* glSampleCoverage() */
546 if (desc->AlphaToCoverageEnable)
547 FIXME("Ignoring AlphaToCoverageEnable %#x.\n", desc->AlphaToCoverageEnable);
548 /* glEnableIndexedEXT(GL_BLEND, ...) */
549 FIXME("Per-rendertarget blend enable not implemented.\n");
550 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ALPHABLENDENABLE, desc->BlendEnable[0]);
551 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SRCBLEND, desc->SrcBlend);
552 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_DESTBLEND, desc->DestBlend);
553 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_BLENDOP, desc->BlendOp);
554 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SEPARATEALPHABLENDENABLE, TRUE);
555 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SRCBLENDALPHA, desc->SrcBlendAlpha);
556 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_DESTBLENDALPHA, desc->DestBlendAlpha);
557 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_BLENDOPALPHA, desc->BlendOpAlpha);
558 FIXME("Color mask > 3 not implemented.\n");
559 wined3d_device_set_render_state(device->wined3d_device,
560 WINED3D_RS_COLORWRITEENABLE, desc->RenderTargetWriteMask[0]);
561 wined3d_device_set_render_state(device->wined3d_device,
562 WINED3D_RS_COLORWRITEENABLE1, desc->RenderTargetWriteMask[1]);
563 wined3d_device_set_render_state(device->wined3d_device,
564 WINED3D_RS_COLORWRITEENABLE2, desc->RenderTargetWriteMask[2]);
565 wined3d_device_set_render_state(device->wined3d_device,
566 WINED3D_RS_COLORWRITEENABLE3, desc->RenderTargetWriteMask[3]);
567 wined3d_mutex_unlock();
570 static void STDMETHODCALLTYPE d3d10_device_OMSetDepthStencilState(ID3D10Device1 *iface,
571 ID3D10DepthStencilState *depth_stencil_state, UINT stencil_ref)
573 struct d3d10_device *device = impl_from_ID3D10Device(iface);
575 TRACE("iface %p, depth_stencil_state %p, stencil_ref %u.\n",
576 iface, depth_stencil_state, stencil_ref);
578 device->depth_stencil_state = unsafe_impl_from_ID3D10DepthStencilState(depth_stencil_state);
579 device->stencil_ref = stencil_ref;
582 static void STDMETHODCALLTYPE d3d10_device_SOSetTargets(ID3D10Device1 *iface,
583 UINT target_count, ID3D10Buffer *const *targets, const UINT *offsets)
585 struct d3d10_device *device = impl_from_ID3D10Device(iface);
586 unsigned int count, i;
588 TRACE("iface %p, target_count %u, targets %p, offsets %p.\n", iface, target_count, targets, offsets);
590 count = min(target_count, 4);
591 wined3d_mutex_lock();
592 for (i = 0; i < count; ++i)
594 struct d3d10_buffer *buffer = unsafe_impl_from_ID3D10Buffer(targets[i]);
596 wined3d_device_set_stream_output(device->wined3d_device, i,
597 buffer ? buffer->wined3d_buffer : NULL, offsets[i]);
600 for (i = count; i < 4; ++i)
602 wined3d_device_set_stream_output(device->wined3d_device, i, NULL, 0);
604 wined3d_mutex_unlock();
607 static void STDMETHODCALLTYPE d3d10_device_DrawAuto(ID3D10Device1 *iface)
609 FIXME("iface %p stub!\n", iface);
612 static void STDMETHODCALLTYPE d3d10_device_RSSetState(ID3D10Device1 *iface, ID3D10RasterizerState *rasterizer_state)
614 struct d3d10_device *device = impl_from_ID3D10Device(iface);
615 const D3D10_RASTERIZER_DESC *desc;
617 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
619 wined3d_mutex_lock();
620 if (!(device->rasterizer_state = unsafe_impl_from_ID3D10RasterizerState(rasterizer_state)))
622 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_FILLMODE, WINED3D_FILL_SOLID);
623 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_CULLMODE, WINED3D_CULL_CCW);
624 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SCISSORTESTENABLE, FALSE);
625 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_MULTISAMPLEANTIALIAS, FALSE);
626 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_ANTIALIASEDLINEENABLE, FALSE);
627 wined3d_mutex_unlock();
628 return;
631 desc = &device->rasterizer_state->desc;
632 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_FILLMODE, desc->FillMode);
633 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_CULLMODE, desc->CullMode);
634 /* glFrontFace() */
635 if (desc->FrontCounterClockwise)
636 FIXME("Ignoring FrontCounterClockwise %#x.\n", desc->FrontCounterClockwise);
637 /* OpenGL style depth bias. */
638 if (desc->DepthBias || desc->SlopeScaledDepthBias)
639 FIXME("Ignoring depth bias.\n");
640 /* GL_DEPTH_CLAMP */
641 if (!desc->DepthClipEnable)
642 FIXME("Ignoring DepthClipEnable %#x.\n", desc->DepthClipEnable);
643 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_SCISSORTESTENABLE, desc->ScissorEnable);
644 wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_MULTISAMPLEANTIALIAS, desc->MultisampleEnable);
645 wined3d_device_set_render_state(device->wined3d_device,
646 WINED3D_RS_ANTIALIASEDLINEENABLE, desc->AntialiasedLineEnable);
647 wined3d_mutex_unlock();
650 static void STDMETHODCALLTYPE d3d10_device_RSSetViewports(ID3D10Device1 *iface,
651 UINT viewport_count, const D3D10_VIEWPORT *viewports)
653 struct d3d10_device *device = impl_from_ID3D10Device(iface);
654 struct wined3d_viewport wined3d_vp;
656 TRACE("iface %p, viewport_count %u, viewports %p.\n", iface, viewport_count, viewports);
658 if (viewport_count > 1)
659 FIXME("Multiple viewports not implemented.\n");
661 if (!viewport_count)
662 return;
664 wined3d_vp.x = viewports[0].TopLeftX;
665 wined3d_vp.y = viewports[0].TopLeftY;
666 wined3d_vp.width = viewports[0].Width;
667 wined3d_vp.height = viewports[0].Height;
668 wined3d_vp.min_z = viewports[0].MinDepth;
669 wined3d_vp.max_z = viewports[0].MaxDepth;
671 wined3d_mutex_lock();
672 wined3d_device_set_viewport(device->wined3d_device, &wined3d_vp);
673 wined3d_mutex_unlock();
676 static void STDMETHODCALLTYPE d3d10_device_RSSetScissorRects(ID3D10Device1 *iface,
677 UINT rect_count, const D3D10_RECT *rects)
679 struct d3d10_device *device = impl_from_ID3D10Device(iface);
681 TRACE("iface %p, rect_count %u, rects %p.\n", iface, rect_count, rects);
683 if (rect_count > 1)
684 FIXME("Multiple scissor rects not implemented.\n");
686 if (!rect_count)
687 return;
689 wined3d_mutex_lock();
690 wined3d_device_set_scissor_rect(device->wined3d_device, rects);
691 wined3d_mutex_unlock();
694 static void STDMETHODCALLTYPE d3d10_device_CopySubresourceRegion(ID3D10Device1 *iface,
695 ID3D10Resource *dst_resource, UINT dst_subresource_idx, UINT dst_x, UINT dst_y, UINT dst_z,
696 ID3D10Resource *src_resource, UINT src_subresource_idx, const D3D10_BOX *src_box)
698 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
699 struct d3d10_device *device = impl_from_ID3D10Device(iface);
700 struct wined3d_box wined3d_src_box;
702 TRACE("iface %p, dst_resource %p, dst_subresource_idx %u, dst_x %u, dst_y %u, dst_z %u, "
703 "src_resource %p, src_subresource_idx %u, src_box %p.\n",
704 iface, dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
705 src_resource, src_subresource_idx, src_box);
707 wined3d_dst_resource = wined3d_resource_from_resource(dst_resource);
708 wined3d_src_resource = wined3d_resource_from_resource(src_resource);
709 wined3d_src_box.left = src_box->left;
710 wined3d_src_box.top = src_box->top;
711 wined3d_src_box.front = src_box->front;
712 wined3d_src_box.right = src_box->right;
713 wined3d_src_box.bottom = src_box->bottom;
714 wined3d_src_box.back = src_box->back;
715 wined3d_mutex_lock();
716 wined3d_device_copy_sub_resource_region(device->wined3d_device, wined3d_dst_resource, dst_subresource_idx,
717 dst_x, dst_y, dst_z, wined3d_src_resource, src_subresource_idx, &wined3d_src_box);
718 wined3d_mutex_unlock();
721 static void STDMETHODCALLTYPE d3d10_device_CopyResource(ID3D10Device1 *iface,
722 ID3D10Resource *dst_resource, ID3D10Resource *src_resource)
724 struct wined3d_resource *wined3d_dst_resource, *wined3d_src_resource;
725 struct d3d10_device *device = impl_from_ID3D10Device(iface);
727 TRACE("iface %p, dst_resource %p, src_resource %p.\n", iface, dst_resource, src_resource);
729 wined3d_dst_resource = wined3d_resource_from_resource(dst_resource);
730 wined3d_src_resource = wined3d_resource_from_resource(src_resource);
731 wined3d_mutex_lock();
732 wined3d_device_copy_resource(device->wined3d_device, wined3d_dst_resource, wined3d_src_resource);
733 wined3d_mutex_unlock();
736 static void STDMETHODCALLTYPE d3d10_device_UpdateSubresource(ID3D10Device1 *iface,
737 ID3D10Resource *resource, UINT subresource_idx, const D3D10_BOX *box,
738 const void *data, UINT row_pitch, UINT depth_pitch)
740 struct d3d10_device *device = impl_from_ID3D10Device(iface);
741 struct wined3d_resource *wined3d_resource;
742 struct wined3d_box wined3d_box;
744 TRACE("iface %p, resource %p, subresource_idx %u, box %p, data %p, row_pitch %u, depth_pitch %u.\n",
745 iface, resource, subresource_idx, box, data, row_pitch, depth_pitch);
747 if (box)
749 wined3d_box.left = box->left;
750 wined3d_box.top = box->top;
751 wined3d_box.front = box->front;
752 wined3d_box.right = box->right;
753 wined3d_box.bottom = box->bottom;
754 wined3d_box.back = box->back;
757 wined3d_resource = wined3d_resource_from_resource(resource);
758 wined3d_mutex_lock();
759 wined3d_device_update_sub_resource(device->wined3d_device, wined3d_resource,
760 subresource_idx, box ? &wined3d_box : NULL, data, row_pitch, depth_pitch);
761 wined3d_mutex_unlock();
764 static void STDMETHODCALLTYPE d3d10_device_ClearRenderTargetView(ID3D10Device1 *iface,
765 ID3D10RenderTargetView *render_target_view, const FLOAT color_rgba[4])
767 struct d3d10_device *device = impl_from_ID3D10Device(iface);
768 struct d3d10_rendertarget_view *view = unsafe_impl_from_ID3D10RenderTargetView(render_target_view);
769 const struct wined3d_color color = {color_rgba[0], color_rgba[1], color_rgba[2], color_rgba[3]};
770 HRESULT hr;
772 TRACE("iface %p, render_target_view %p, color_rgba {%.8e, %.8e, %.8e, %.8e}.\n",
773 iface, render_target_view, color_rgba[0], color_rgba[1], color_rgba[2], color_rgba[3]);
775 wined3d_mutex_lock();
776 if (FAILED(hr = wined3d_device_clear_rendertarget_view(device->wined3d_device, view->wined3d_view, NULL, &color)))
777 ERR("Failed to clear view, hr %#x.\n", hr);
778 wined3d_mutex_unlock();
781 static void STDMETHODCALLTYPE d3d10_device_ClearDepthStencilView(ID3D10Device1 *iface,
782 ID3D10DepthStencilView *depth_stencil_view, UINT flags, FLOAT depth, UINT8 stencil)
784 FIXME("iface %p, depth_stencil_view %p, flags %#x, depth %f, stencil %u stub!\n",
785 iface, depth_stencil_view, flags, depth, stencil);
788 static void STDMETHODCALLTYPE d3d10_device_GenerateMips(ID3D10Device1 *iface,
789 ID3D10ShaderResourceView *shader_resource_view)
791 FIXME("iface %p, shader_resource_view %p stub!\n", iface, shader_resource_view);
794 static void STDMETHODCALLTYPE d3d10_device_ResolveSubresource(ID3D10Device1 *iface,
795 ID3D10Resource *dst_resource, UINT dst_subresource_idx,
796 ID3D10Resource *src_resource, UINT src_subresource_idx, DXGI_FORMAT format)
798 FIXME("iface %p, dst_resource %p, dst_subresource_idx %u,\n"
799 "\tsrc_resource %p, src_subresource_idx %u, format %s stub!\n",
800 iface, dst_resource, dst_subresource_idx,
801 src_resource, src_subresource_idx, debug_dxgi_format(format));
804 static void STDMETHODCALLTYPE d3d10_device_VSGetConstantBuffers(ID3D10Device1 *iface,
805 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
807 struct d3d10_device *device = impl_from_ID3D10Device(iface);
808 unsigned int i;
810 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
811 iface, start_slot, buffer_count, buffers);
813 wined3d_mutex_lock();
814 for (i = 0; i < buffer_count; ++i)
816 struct wined3d_buffer *wined3d_buffer;
817 struct d3d10_buffer *buffer_impl;
819 if (!(wined3d_buffer = wined3d_device_get_vs_cb(device->wined3d_device, start_slot + i)))
821 buffers[i] = NULL;
822 continue;
825 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
826 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
827 ID3D10Buffer_AddRef(buffers[i]);
829 wined3d_mutex_unlock();
832 static void STDMETHODCALLTYPE d3d10_device_PSGetShaderResources(ID3D10Device1 *iface,
833 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
835 struct d3d10_device *device = impl_from_ID3D10Device(iface);
836 unsigned int i;
838 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
839 iface, start_slot, view_count, views);
841 wined3d_mutex_lock();
842 for (i = 0; i < view_count; ++i)
844 struct wined3d_shader_resource_view *wined3d_view;
845 struct d3d10_shader_resource_view *view_impl;
847 if (!(wined3d_view = wined3d_device_get_ps_resource_view(device->wined3d_device, start_slot + i)))
849 views[i] = NULL;
850 continue;
853 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
854 views[i] = &view_impl->ID3D10ShaderResourceView_iface;
855 ID3D10ShaderResourceView_AddRef(views[i]);
857 wined3d_mutex_unlock();
860 static void STDMETHODCALLTYPE d3d10_device_PSGetShader(ID3D10Device1 *iface, ID3D10PixelShader **shader)
862 struct d3d10_device *device = impl_from_ID3D10Device(iface);
863 struct d3d10_pixel_shader *shader_impl;
864 struct wined3d_shader *wined3d_shader;
866 TRACE("iface %p, shader %p.\n", iface, shader);
868 wined3d_mutex_lock();
869 if (!(wined3d_shader = wined3d_device_get_pixel_shader(device->wined3d_device)))
871 wined3d_mutex_unlock();
872 *shader = NULL;
873 return;
876 shader_impl = wined3d_shader_get_parent(wined3d_shader);
877 wined3d_mutex_unlock();
878 *shader = &shader_impl->ID3D10PixelShader_iface;
879 ID3D10PixelShader_AddRef(*shader);
882 static void STDMETHODCALLTYPE d3d10_device_PSGetSamplers(ID3D10Device1 *iface,
883 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
885 struct d3d10_device *device = impl_from_ID3D10Device(iface);
886 unsigned int i;
888 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
889 iface, start_slot, sampler_count, samplers);
891 wined3d_mutex_lock();
892 for (i = 0; i < sampler_count; ++i)
894 struct d3d10_sampler_state *sampler_impl;
895 struct wined3d_sampler *wined3d_sampler;
897 if (!(wined3d_sampler = wined3d_device_get_ps_sampler(device->wined3d_device, start_slot + i)))
899 samplers[i] = NULL;
900 continue;
903 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
904 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
905 ID3D10SamplerState_AddRef(samplers[i]);
907 wined3d_mutex_unlock();
910 static void STDMETHODCALLTYPE d3d10_device_VSGetShader(ID3D10Device1 *iface, ID3D10VertexShader **shader)
912 struct d3d10_device *device = impl_from_ID3D10Device(iface);
913 struct d3d10_vertex_shader *shader_impl;
914 struct wined3d_shader *wined3d_shader;
916 TRACE("iface %p, shader %p.\n", iface, shader);
918 wined3d_mutex_lock();
919 if (!(wined3d_shader = wined3d_device_get_vertex_shader(device->wined3d_device)))
921 wined3d_mutex_unlock();
922 *shader = NULL;
923 return;
926 shader_impl = wined3d_shader_get_parent(wined3d_shader);
927 wined3d_mutex_unlock();
928 *shader = &shader_impl->ID3D10VertexShader_iface;
929 ID3D10VertexShader_AddRef(*shader);
932 static void STDMETHODCALLTYPE d3d10_device_PSGetConstantBuffers(ID3D10Device1 *iface,
933 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
935 struct d3d10_device *device = impl_from_ID3D10Device(iface);
936 unsigned int i;
938 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
939 iface, start_slot, buffer_count, buffers);
941 wined3d_mutex_lock();
942 for (i = 0; i < buffer_count; ++i)
944 struct wined3d_buffer *wined3d_buffer;
945 struct d3d10_buffer *buffer_impl;
947 if (!(wined3d_buffer = wined3d_device_get_ps_cb(device->wined3d_device, start_slot + i)))
949 buffers[i] = NULL;
950 continue;
953 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
954 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
955 ID3D10Buffer_AddRef(buffers[i]);
957 wined3d_mutex_unlock();
960 static void STDMETHODCALLTYPE d3d10_device_IAGetInputLayout(ID3D10Device1 *iface, ID3D10InputLayout **input_layout)
962 struct d3d10_device *device = impl_from_ID3D10Device(iface);
963 struct wined3d_vertex_declaration *wined3d_declaration;
964 struct d3d10_input_layout *input_layout_impl;
966 TRACE("iface %p, input_layout %p.\n", iface, input_layout);
968 wined3d_mutex_lock();
969 if (!(wined3d_declaration = wined3d_device_get_vertex_declaration(device->wined3d_device)))
971 wined3d_mutex_unlock();
972 *input_layout = NULL;
973 return;
976 input_layout_impl = wined3d_vertex_declaration_get_parent(wined3d_declaration);
977 wined3d_mutex_unlock();
978 *input_layout = &input_layout_impl->ID3D10InputLayout_iface;
979 ID3D10InputLayout_AddRef(*input_layout);
982 static void STDMETHODCALLTYPE d3d10_device_IAGetVertexBuffers(ID3D10Device1 *iface,
983 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers, UINT *strides, UINT *offsets)
985 struct d3d10_device *device = impl_from_ID3D10Device(iface);
986 unsigned int i;
988 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p.\n",
989 iface, start_slot, buffer_count, buffers, strides, offsets);
991 wined3d_mutex_lock();
992 for (i = 0; i < buffer_count; ++i)
994 struct wined3d_buffer *wined3d_buffer;
995 struct d3d10_buffer *buffer_impl;
997 if (FAILED(wined3d_device_get_stream_source(device->wined3d_device, start_slot + i,
998 &wined3d_buffer, &offsets[i], &strides[i])))
999 ERR("Failed to get vertex buffer.\n");
1001 if (!wined3d_buffer)
1003 buffers[i] = NULL;
1004 continue;
1007 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1008 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
1009 ID3D10Buffer_AddRef(buffers[i]);
1011 wined3d_mutex_unlock();
1014 static void STDMETHODCALLTYPE d3d10_device_IAGetIndexBuffer(ID3D10Device1 *iface,
1015 ID3D10Buffer **buffer, DXGI_FORMAT *format, UINT *offset)
1017 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1018 enum wined3d_format_id wined3d_format;
1019 struct wined3d_buffer *wined3d_buffer;
1020 struct d3d10_buffer *buffer_impl;
1022 TRACE("iface %p, buffer %p, format %p, offset %p.\n", iface, buffer, format, offset);
1024 wined3d_mutex_lock();
1025 wined3d_buffer = wined3d_device_get_index_buffer(device->wined3d_device, &wined3d_format);
1026 *format = dxgi_format_from_wined3dformat(wined3d_format);
1027 *offset = 0; /* FIXME */
1028 if (!wined3d_buffer)
1030 wined3d_mutex_unlock();
1031 *buffer = NULL;
1032 return;
1035 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1036 wined3d_mutex_unlock();
1037 *buffer = &buffer_impl->ID3D10Buffer_iface;
1038 ID3D10Buffer_AddRef(*buffer);
1041 static void STDMETHODCALLTYPE d3d10_device_GSGetConstantBuffers(ID3D10Device1 *iface,
1042 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
1044 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1045 unsigned int i;
1047 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
1048 iface, start_slot, buffer_count, buffers);
1050 wined3d_mutex_lock();
1051 for (i = 0; i < buffer_count; ++i)
1053 struct wined3d_buffer *wined3d_buffer;
1054 struct d3d10_buffer *buffer_impl;
1056 if (!(wined3d_buffer = wined3d_device_get_gs_cb(device->wined3d_device, start_slot + i)))
1058 buffers[i] = NULL;
1059 continue;
1062 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1063 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
1064 ID3D10Buffer_AddRef(buffers[i]);
1066 wined3d_mutex_unlock();
1069 static void STDMETHODCALLTYPE d3d10_device_GSGetShader(ID3D10Device1 *iface, ID3D10GeometryShader **shader)
1071 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1072 struct d3d10_geometry_shader *shader_impl;
1073 struct wined3d_shader *wined3d_shader;
1075 TRACE("iface %p, shader %p.\n", iface, shader);
1077 wined3d_mutex_lock();
1078 if (!(wined3d_shader = wined3d_device_get_geometry_shader(device->wined3d_device)))
1080 wined3d_mutex_unlock();
1081 *shader = NULL;
1082 return;
1085 shader_impl = wined3d_shader_get_parent(wined3d_shader);
1086 wined3d_mutex_unlock();
1087 *shader = &shader_impl->ID3D10GeometryShader_iface;
1088 ID3D10GeometryShader_AddRef(*shader);
1091 static void STDMETHODCALLTYPE d3d10_device_IAGetPrimitiveTopology(ID3D10Device1 *iface,
1092 D3D10_PRIMITIVE_TOPOLOGY *topology)
1094 struct d3d10_device *This = impl_from_ID3D10Device(iface);
1096 TRACE("iface %p, topology %p\n", iface, topology);
1098 wined3d_mutex_lock();
1099 wined3d_device_get_primitive_type(This->wined3d_device, (enum wined3d_primitive_type *)topology);
1100 wined3d_mutex_unlock();
1103 static void STDMETHODCALLTYPE d3d10_device_VSGetShaderResources(ID3D10Device1 *iface,
1104 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
1106 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1107 unsigned int i;
1109 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1110 iface, start_slot, view_count, views);
1112 wined3d_mutex_lock();
1113 for (i = 0; i < view_count; ++i)
1115 struct wined3d_shader_resource_view *wined3d_view;
1116 struct d3d10_shader_resource_view *view_impl;
1118 if (!(wined3d_view = wined3d_device_get_vs_resource_view(device->wined3d_device, start_slot + i)))
1120 views[i] = NULL;
1121 continue;
1124 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
1125 views[i] = &view_impl->ID3D10ShaderResourceView_iface;
1126 ID3D10ShaderResourceView_AddRef(views[i]);
1128 wined3d_mutex_unlock();
1131 static void STDMETHODCALLTYPE d3d10_device_VSGetSamplers(ID3D10Device1 *iface,
1132 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
1134 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1135 unsigned int i;
1137 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1138 iface, start_slot, sampler_count, samplers);
1140 wined3d_mutex_lock();
1141 for (i = 0; i < sampler_count; ++i)
1143 struct d3d10_sampler_state *sampler_impl;
1144 struct wined3d_sampler *wined3d_sampler;
1146 if (!(wined3d_sampler = wined3d_device_get_vs_sampler(device->wined3d_device, start_slot + i)))
1148 samplers[i] = NULL;
1149 continue;
1152 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
1153 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
1154 ID3D10SamplerState_AddRef(samplers[i]);
1156 wined3d_mutex_unlock();
1159 static void STDMETHODCALLTYPE d3d10_device_GetPredication(ID3D10Device1 *iface,
1160 ID3D10Predicate **predicate, BOOL *value)
1162 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1163 struct wined3d_query *wined3d_predicate;
1164 struct d3d10_query *predicate_impl;
1166 TRACE("iface %p, predicate %p, value %p.\n", iface, predicate, value);
1168 wined3d_mutex_lock();
1169 if (!(wined3d_predicate = wined3d_device_get_predication(device->wined3d_device, value)))
1171 wined3d_mutex_unlock();
1172 *predicate = NULL;
1173 return;
1176 predicate_impl = wined3d_query_get_parent(wined3d_predicate);
1177 wined3d_mutex_unlock();
1178 *predicate = (ID3D10Predicate *)&predicate_impl->ID3D10Query_iface;
1179 ID3D10Predicate_AddRef(*predicate);
1182 static void STDMETHODCALLTYPE d3d10_device_GSGetShaderResources(ID3D10Device1 *iface,
1183 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
1185 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1186 unsigned int i;
1188 TRACE("iface %p, start_slot %u, view_count %u, views %p.\n",
1189 iface, start_slot, view_count, views);
1191 wined3d_mutex_lock();
1192 for (i = 0; i < view_count; ++i)
1194 struct wined3d_shader_resource_view *wined3d_view;
1195 struct d3d10_shader_resource_view *view_impl;
1197 if (!(wined3d_view = wined3d_device_get_gs_resource_view(device->wined3d_device, start_slot + i)))
1199 views[i] = NULL;
1200 continue;
1203 view_impl = wined3d_shader_resource_view_get_parent(wined3d_view);
1204 views[i] = &view_impl->ID3D10ShaderResourceView_iface;
1205 ID3D10ShaderResourceView_AddRef(views[i]);
1207 wined3d_mutex_unlock();
1210 static void STDMETHODCALLTYPE d3d10_device_GSGetSamplers(ID3D10Device1 *iface,
1211 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
1213 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1214 unsigned int i;
1216 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
1217 iface, start_slot, sampler_count, samplers);
1219 wined3d_mutex_lock();
1220 for (i = 0; i < sampler_count; ++i)
1222 struct d3d10_sampler_state *sampler_impl;
1223 struct wined3d_sampler *wined3d_sampler;
1225 if (!(wined3d_sampler = wined3d_device_get_gs_sampler(device->wined3d_device, start_slot + i)))
1227 samplers[i] = NULL;
1228 continue;
1231 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
1232 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
1233 ID3D10SamplerState_AddRef(samplers[i]);
1235 wined3d_mutex_unlock();
1238 static void STDMETHODCALLTYPE d3d10_device_OMGetRenderTargets(ID3D10Device1 *iface,
1239 UINT view_count, ID3D10RenderTargetView **render_target_views, ID3D10DepthStencilView **depth_stencil_view)
1241 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1242 struct wined3d_rendertarget_view *wined3d_view;
1244 TRACE("iface %p, view_count %u, render_target_views %p, depth_stencil_view %p.\n",
1245 iface, view_count, render_target_views, depth_stencil_view);
1247 wined3d_mutex_lock();
1248 if (render_target_views)
1250 struct d3d10_rendertarget_view *view_impl;
1251 unsigned int i;
1253 for (i = 0; i < view_count; ++i)
1255 if (!(wined3d_view = wined3d_device_get_rendertarget_view(device->wined3d_device, i))
1256 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
1258 render_target_views[i] = NULL;
1259 continue;
1262 render_target_views[i] = &view_impl->ID3D10RenderTargetView_iface;
1263 ID3D10RenderTargetView_AddRef(render_target_views[i]);
1267 if (depth_stencil_view)
1269 struct d3d10_depthstencil_view *view_impl;
1271 if (!(wined3d_view = wined3d_device_get_depth_stencil_view(device->wined3d_device))
1272 || !(view_impl = wined3d_rendertarget_view_get_parent(wined3d_view)))
1274 *depth_stencil_view = NULL;
1276 else
1278 *depth_stencil_view = &view_impl->ID3D10DepthStencilView_iface;
1279 ID3D10DepthStencilView_AddRef(*depth_stencil_view);
1282 wined3d_mutex_unlock();
1285 static void STDMETHODCALLTYPE d3d10_device_OMGetBlendState(ID3D10Device1 *iface,
1286 ID3D10BlendState **blend_state, FLOAT blend_factor[4], UINT *sample_mask)
1288 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1290 TRACE("iface %p, blend_state %p, blend_factor %p, sample_mask %p.\n",
1291 iface, blend_state, blend_factor, sample_mask);
1293 if ((*blend_state = device->blend_state ? &device->blend_state->ID3D10BlendState_iface : NULL))
1294 ID3D10BlendState_AddRef(*blend_state);
1295 wined3d_mutex_lock();
1296 memcpy(blend_factor, device->blend_factor, 4 * sizeof(*blend_factor));
1297 *sample_mask = wined3d_device_get_render_state(device->wined3d_device, WINED3D_RS_MULTISAMPLEMASK);
1298 wined3d_mutex_unlock();
1301 static void STDMETHODCALLTYPE d3d10_device_OMGetDepthStencilState(ID3D10Device1 *iface,
1302 ID3D10DepthStencilState **depth_stencil_state, UINT *stencil_ref)
1304 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1306 TRACE("iface %p, depth_stencil_state %p, stencil_ref %p.\n",
1307 iface, depth_stencil_state, stencil_ref);
1309 if ((*depth_stencil_state = device->depth_stencil_state
1310 ? &device->depth_stencil_state->ID3D10DepthStencilState_iface : NULL))
1311 ID3D10DepthStencilState_AddRef(*depth_stencil_state);
1312 *stencil_ref = device->stencil_ref;
1315 static void STDMETHODCALLTYPE d3d10_device_SOGetTargets(ID3D10Device1 *iface,
1316 UINT buffer_count, ID3D10Buffer **buffers, UINT *offsets)
1318 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1319 unsigned int i;
1321 TRACE("iface %p, buffer_count %u, buffers %p, offsets %p.\n",
1322 iface, buffer_count, buffers, offsets);
1324 wined3d_mutex_lock();
1325 for (i = 0; i < buffer_count; ++i)
1327 struct wined3d_buffer *wined3d_buffer;
1328 struct d3d10_buffer *buffer_impl;
1330 if (!(wined3d_buffer = wined3d_device_get_stream_output(device->wined3d_device, i, &offsets[i])))
1332 buffers[i] = NULL;
1333 continue;
1336 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
1337 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
1338 ID3D10Buffer_AddRef(buffers[i]);
1340 wined3d_mutex_unlock();
1343 static void STDMETHODCALLTYPE d3d10_device_RSGetState(ID3D10Device1 *iface, ID3D10RasterizerState **rasterizer_state)
1345 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1347 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
1349 if ((*rasterizer_state = device->rasterizer_state ? &device->rasterizer_state->ID3D10RasterizerState_iface : NULL))
1350 ID3D10RasterizerState_AddRef(*rasterizer_state);
1353 static void STDMETHODCALLTYPE d3d10_device_RSGetViewports(ID3D10Device1 *iface,
1354 UINT *viewport_count, D3D10_VIEWPORT *viewports)
1356 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1357 struct wined3d_viewport wined3d_vp;
1359 TRACE("iface %p, viewport_count %p, viewports %p.\n", iface, viewport_count, viewports);
1361 if (!viewports)
1363 *viewport_count = 1;
1364 return;
1367 if (!*viewport_count)
1368 return;
1370 wined3d_mutex_lock();
1371 wined3d_device_get_viewport(device->wined3d_device, &wined3d_vp);
1372 wined3d_mutex_unlock();
1374 viewports[0].TopLeftX = wined3d_vp.x;
1375 viewports[0].TopLeftY = wined3d_vp.y;
1376 viewports[0].Width = wined3d_vp.width;
1377 viewports[0].Height = wined3d_vp.height;
1378 viewports[0].MinDepth = wined3d_vp.min_z;
1379 viewports[0].MaxDepth = wined3d_vp.max_z;
1381 if (*viewport_count > 1)
1382 memset(&viewports[1], 0, (*viewport_count - 1) * sizeof(*viewports));
1385 static void STDMETHODCALLTYPE d3d10_device_RSGetScissorRects(ID3D10Device1 *iface, UINT *rect_count, D3D10_RECT *rects)
1387 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1389 TRACE("iface %p, rect_count %p, rects %p.\n", iface, rect_count, rects);
1391 if (!rects)
1393 *rect_count = 1;
1394 return;
1397 if (!*rect_count)
1398 return;
1400 wined3d_mutex_lock();
1401 wined3d_device_get_scissor_rect(device->wined3d_device, rects);
1402 wined3d_mutex_unlock();
1403 if (*rect_count > 1)
1404 memset(&rects[1], 0, (*rect_count - 1) * sizeof(*rects));
1407 static HRESULT STDMETHODCALLTYPE d3d10_device_GetDeviceRemovedReason(ID3D10Device1 *iface)
1409 TRACE("iface %p.\n", iface);
1411 /* In the current implementation the device is never removed, so we can
1412 * just return S_OK here. */
1414 return S_OK;
1417 static HRESULT STDMETHODCALLTYPE d3d10_device_SetExceptionMode(ID3D10Device1 *iface, UINT flags)
1419 FIXME("iface %p, flags %#x stub!\n", iface, flags);
1421 return E_NOTIMPL;
1424 static UINT STDMETHODCALLTYPE d3d10_device_GetExceptionMode(ID3D10Device1 *iface)
1426 FIXME("iface %p stub!\n", iface);
1428 return 0;
1431 static HRESULT STDMETHODCALLTYPE d3d10_device_GetPrivateData(ID3D10Device1 *iface,
1432 REFGUID guid, UINT *data_size, void *data)
1434 IDXGIDevice *dxgi_device;
1435 HRESULT hr;
1437 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
1438 iface, debugstr_guid(guid), data_size, data);
1440 if (FAILED(hr = ID3D10Device1_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
1441 return hr;
1442 hr = IDXGIDevice_GetPrivateData(dxgi_device, guid, data_size, data);
1443 IDXGIDevice_Release(dxgi_device);
1445 return hr;
1448 static HRESULT STDMETHODCALLTYPE d3d10_device_SetPrivateData(ID3D10Device1 *iface,
1449 REFGUID guid, UINT data_size, const void *data)
1451 IDXGIDevice *dxgi_device;
1452 HRESULT hr;
1454 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
1455 iface, debugstr_guid(guid), data_size, data);
1457 if (FAILED(hr = ID3D10Device1_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
1458 return hr;
1459 hr = IDXGIDevice_SetPrivateData(dxgi_device, guid, data_size, data);
1460 IDXGIDevice_Release(dxgi_device);
1462 return hr;
1465 static HRESULT STDMETHODCALLTYPE d3d10_device_SetPrivateDataInterface(ID3D10Device1 *iface,
1466 REFGUID guid, const IUnknown *data)
1468 IDXGIDevice *dxgi_device;
1469 HRESULT hr;
1471 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
1473 if (FAILED(hr = ID3D10Device1_QueryInterface(iface, &IID_IDXGIDevice, (void **)&dxgi_device)))
1474 return hr;
1475 hr = IDXGIDevice_SetPrivateDataInterface(dxgi_device, guid, data);
1476 IDXGIDevice_Release(dxgi_device);
1478 return hr;
1481 static void STDMETHODCALLTYPE d3d10_device_ClearState(ID3D10Device1 *iface)
1483 static const float blend_factor[] = {1.0f, 1.0f, 1.0f, 1.0f};
1484 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1485 unsigned int i;
1487 TRACE("iface %p.\n", iface);
1489 wined3d_mutex_lock();
1490 wined3d_device_set_vertex_shader(device->wined3d_device, NULL);
1491 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
1493 wined3d_device_set_vs_sampler(device->wined3d_device, i, NULL);
1495 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
1497 wined3d_device_set_vs_resource_view(device->wined3d_device, i, NULL);
1499 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
1501 wined3d_device_set_vs_cb(device->wined3d_device, i, NULL);
1503 wined3d_device_set_geometry_shader(device->wined3d_device, NULL);
1504 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
1506 wined3d_device_set_gs_sampler(device->wined3d_device, i, NULL);
1508 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
1510 wined3d_device_set_gs_resource_view(device->wined3d_device, i, NULL);
1512 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
1514 wined3d_device_set_gs_cb(device->wined3d_device, i, NULL);
1516 wined3d_device_set_pixel_shader(device->wined3d_device, NULL);
1517 for (i = 0; i < D3D10_COMMONSHADER_SAMPLER_SLOT_COUNT; ++i)
1519 wined3d_device_set_ps_sampler(device->wined3d_device, i, NULL);
1521 for (i = 0; i < D3D10_COMMONSHADER_INPUT_RESOURCE_SLOT_COUNT; ++i)
1523 wined3d_device_set_ps_resource_view(device->wined3d_device, i, NULL);
1525 for (i = 0; i < D3D10_COMMONSHADER_CONSTANT_BUFFER_API_SLOT_COUNT; ++i)
1527 wined3d_device_set_ps_cb(device->wined3d_device, i, NULL);
1529 for (i = 0; i < D3D10_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT; ++i)
1531 wined3d_device_set_stream_source(device->wined3d_device, i, NULL, 0, 0);
1533 wined3d_device_set_index_buffer(device->wined3d_device, NULL, WINED3DFMT_UNKNOWN);
1534 wined3d_device_set_vertex_declaration(device->wined3d_device, NULL);
1535 wined3d_device_set_primitive_type(device->wined3d_device, WINED3D_PT_UNDEFINED);
1536 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
1538 wined3d_device_set_rendertarget_view(device->wined3d_device, i, NULL, FALSE);
1540 wined3d_device_set_depth_stencil_view(device->wined3d_device, NULL);
1541 ID3D10Device1_OMSetDepthStencilState(iface, NULL, 0);
1542 ID3D10Device1_OMSetBlendState(iface, NULL, blend_factor, D3D10_DEFAULT_SAMPLE_MASK);
1543 ID3D10Device1_RSSetViewports(iface, 0, NULL);
1544 ID3D10Device1_RSSetScissorRects(iface, 0, NULL);
1545 ID3D10Device1_RSSetState(iface, NULL);
1546 for (i = 0; i < D3D10_SO_BUFFER_SLOT_COUNT; ++i)
1548 wined3d_device_set_stream_output(device->wined3d_device, i, NULL, 0);
1550 wined3d_device_set_predication(device->wined3d_device, NULL, FALSE);
1551 wined3d_mutex_unlock();
1554 static void STDMETHODCALLTYPE d3d10_device_Flush(ID3D10Device1 *iface)
1556 FIXME("iface %p stub!\n", iface);
1559 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBuffer(ID3D10Device1 *iface,
1560 const D3D10_BUFFER_DESC *desc, const D3D10_SUBRESOURCE_DATA *data, ID3D10Buffer **buffer)
1562 struct d3d10_device *This = impl_from_ID3D10Device(iface);
1563 struct d3d10_buffer *object;
1564 HRESULT hr;
1566 TRACE("iface %p, desc %p, data %p, buffer %p.\n", iface, desc, data, buffer);
1568 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1569 if (!object)
1570 return E_OUTOFMEMORY;
1572 hr = d3d10_buffer_init(object, This, desc, data);
1573 if (FAILED(hr))
1575 WARN("Failed to initialize buffer, hr %#x.\n", hr);
1576 HeapFree(GetProcessHeap(), 0, object);
1577 return hr;
1580 *buffer = &object->ID3D10Buffer_iface;
1582 TRACE("Created ID3D10Buffer %p\n", object);
1584 return S_OK;
1587 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture1D(ID3D10Device1 *iface,
1588 const D3D10_TEXTURE1D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data, ID3D10Texture1D **texture)
1590 FIXME("iface %p, desc %p, data %p, texture %p stub!\n", iface, desc, data, texture);
1592 return E_NOTIMPL;
1595 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture2D(ID3D10Device1 *iface,
1596 const D3D10_TEXTURE2D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data,
1597 ID3D10Texture2D **texture)
1599 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1600 struct d3d10_texture2d *object;
1601 HRESULT hr;
1603 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
1605 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1606 if (!object)
1607 return E_OUTOFMEMORY;
1609 if (FAILED(hr = d3d10_texture2d_init(object, device, desc, data)))
1611 WARN("Failed to initialize texture, hr %#x.\n", hr);
1612 HeapFree(GetProcessHeap(), 0, object);
1613 return hr;
1616 *texture = &object->ID3D10Texture2D_iface;
1618 TRACE("Created ID3D10Texture2D %p\n", object);
1620 return S_OK;
1623 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture3D(ID3D10Device1 *iface,
1624 const D3D10_TEXTURE3D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data,
1625 ID3D10Texture3D **texture)
1627 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1628 struct d3d10_texture3d *object;
1629 HRESULT hr;
1631 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
1633 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1634 if (!object)
1635 return E_OUTOFMEMORY;
1637 if (FAILED(hr = d3d10_texture3d_init(object, device, desc, data)))
1639 WARN("Failed to initialize texture, hr %#x.\n", hr);
1640 HeapFree(GetProcessHeap(), 0, object);
1641 return hr;
1644 TRACE("Created 3D texture %p.\n", object);
1645 *texture = &object->ID3D10Texture3D_iface;
1647 return S_OK;
1650 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateShaderResourceView(ID3D10Device1 *iface,
1651 ID3D10Resource *resource, const D3D10_SHADER_RESOURCE_VIEW_DESC *desc, ID3D10ShaderResourceView **view)
1653 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1654 struct d3d10_shader_resource_view *object;
1655 HRESULT hr;
1657 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
1659 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
1660 return E_OUTOFMEMORY;
1662 if (FAILED(hr = d3d10_shader_resource_view_init(object, device, resource, desc)))
1664 WARN("Failed to initialize shader resource view, hr %#x.\n", hr);
1665 HeapFree(GetProcessHeap(), 0, object);
1666 return hr;
1669 TRACE("Created shader resource view %p.\n", object);
1670 *view = &object->ID3D10ShaderResourceView_iface;
1672 return S_OK;
1675 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateRenderTargetView(ID3D10Device1 *iface,
1676 ID3D10Resource *resource, const D3D10_RENDER_TARGET_VIEW_DESC *desc, ID3D10RenderTargetView **view)
1678 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1679 struct d3d10_rendertarget_view *object;
1680 HRESULT hr;
1682 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
1684 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
1685 return E_OUTOFMEMORY;
1687 if (FAILED(hr = d3d10_rendertarget_view_init(object, device, resource, desc)))
1689 WARN("Failed to initialize rendertarget view, hr %#x.\n", hr);
1690 HeapFree(GetProcessHeap(), 0, object);
1691 return hr;
1694 TRACE("Created rendertarget view %p.\n", object);
1695 *view = &object->ID3D10RenderTargetView_iface;
1697 return S_OK;
1700 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateDepthStencilView(ID3D10Device1 *iface,
1701 ID3D10Resource *resource, const D3D10_DEPTH_STENCIL_VIEW_DESC *desc, ID3D10DepthStencilView **view)
1703 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1704 struct d3d10_depthstencil_view *object;
1705 HRESULT hr;
1707 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
1709 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
1710 return E_OUTOFMEMORY;
1712 if (FAILED(hr = d3d10_depthstencil_view_init(object, device, resource, desc)))
1714 WARN("Failed to initialize depthstencil view, hr %#x.\n", hr);
1715 HeapFree(GetProcessHeap(), 0, object);
1716 return hr;
1719 TRACE("Created depthstencil view %p.\n", object);
1720 *view = &object->ID3D10DepthStencilView_iface;
1722 return S_OK;
1725 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateInputLayout(ID3D10Device1 *iface,
1726 const D3D10_INPUT_ELEMENT_DESC *element_descs, UINT element_count,
1727 const void *shader_byte_code, SIZE_T shader_byte_code_length,
1728 ID3D10InputLayout **input_layout)
1730 struct d3d10_device *This = impl_from_ID3D10Device(iface);
1731 struct d3d10_input_layout *object;
1732 HRESULT hr;
1734 TRACE("iface %p, element_descs %p, element_count %u, shader_byte_code %p,"
1735 "\tshader_byte_code_length %lu, input_layout %p\n",
1736 iface, element_descs, element_count, shader_byte_code,
1737 shader_byte_code_length, input_layout);
1739 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1740 if (!object)
1741 return E_OUTOFMEMORY;
1743 hr = d3d10_input_layout_init(object, This, element_descs, element_count,
1744 shader_byte_code, shader_byte_code_length);
1745 if (FAILED(hr))
1747 WARN("Failed to initialize input layout, hr %#x.\n", hr);
1748 HeapFree(GetProcessHeap(), 0, object);
1749 return hr;
1752 TRACE("Created input layout %p.\n", object);
1753 *input_layout = &object->ID3D10InputLayout_iface;
1755 return S_OK;
1758 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateVertexShader(ID3D10Device1 *iface,
1759 const void *byte_code, SIZE_T byte_code_length, ID3D10VertexShader **shader)
1761 struct d3d10_device *This = impl_from_ID3D10Device(iface);
1762 struct d3d10_vertex_shader *object;
1763 HRESULT hr;
1765 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p\n",
1766 iface, byte_code, byte_code_length, shader);
1768 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1769 if (!object)
1770 return E_OUTOFMEMORY;
1772 hr = d3d10_vertex_shader_init(object, This, byte_code, byte_code_length);
1773 if (FAILED(hr))
1775 WARN("Failed to initialize vertex shader, hr %#x.\n", hr);
1776 HeapFree(GetProcessHeap(), 0, object);
1777 return hr;
1780 TRACE("Created vertex shader %p.\n", object);
1781 *shader = &object->ID3D10VertexShader_iface;
1783 return S_OK;
1786 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateGeometryShader(ID3D10Device1 *iface,
1787 const void *byte_code, SIZE_T byte_code_length, ID3D10GeometryShader **shader)
1789 struct d3d10_device *This = impl_from_ID3D10Device(iface);
1790 struct d3d10_geometry_shader *object;
1791 HRESULT hr;
1793 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p.\n",
1794 iface, byte_code, byte_code_length, shader);
1796 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1797 if (!object)
1798 return E_OUTOFMEMORY;
1800 hr = d3d10_geometry_shader_init(object, This, byte_code, byte_code_length);
1801 if (FAILED(hr))
1803 WARN("Failed to initialize geometry shader, hr %#x.\n", hr);
1804 HeapFree(GetProcessHeap(), 0, object);
1805 return hr;
1808 TRACE("Created geometry shader %p.\n", object);
1809 *shader = &object->ID3D10GeometryShader_iface;
1811 return S_OK;
1814 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateGeometryShaderWithStreamOutput(ID3D10Device1 *iface,
1815 const void *byte_code, SIZE_T byte_code_length, const D3D10_SO_DECLARATION_ENTRY *output_stream_decls,
1816 UINT output_stream_decl_count, UINT output_stream_stride, ID3D10GeometryShader **shader)
1818 FIXME("iface %p, byte_code %p, byte_code_length %lu, output_stream_decls %p,\n"
1819 "\toutput_stream_decl_count %u, output_stream_stride %u, shader %p stub!\n",
1820 iface, byte_code, byte_code_length, output_stream_decls,
1821 output_stream_decl_count, output_stream_stride, shader);
1823 return E_NOTIMPL;
1826 static HRESULT STDMETHODCALLTYPE d3d10_device_CreatePixelShader(ID3D10Device1 *iface,
1827 const void *byte_code, SIZE_T byte_code_length, ID3D10PixelShader **shader)
1829 struct d3d10_device *This = impl_from_ID3D10Device(iface);
1830 struct d3d10_pixel_shader *object;
1831 HRESULT hr;
1833 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p\n",
1834 iface, byte_code, byte_code_length, shader);
1836 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1837 if (!object)
1838 return E_OUTOFMEMORY;
1840 hr = d3d10_pixel_shader_init(object, This, byte_code, byte_code_length);
1841 if (FAILED(hr))
1843 WARN("Failed to initialize pixel shader, hr %#x.\n", hr);
1844 HeapFree(GetProcessHeap(), 0, object);
1845 return hr;
1848 TRACE("Created pixel shader %p.\n", object);
1849 *shader = &object->ID3D10PixelShader_iface;
1851 return S_OK;
1854 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBlendState(ID3D10Device1 *iface,
1855 const D3D10_BLEND_DESC *desc, ID3D10BlendState **blend_state)
1857 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1858 struct d3d10_blend_state *object;
1859 struct wine_rb_entry *entry;
1860 HRESULT hr;
1862 TRACE("iface %p, desc %p, blend_state %p.\n", iface, desc, blend_state);
1864 if (!desc)
1865 return E_INVALIDARG;
1867 wined3d_mutex_lock();
1868 if ((entry = wine_rb_get(&device->blend_states, desc)))
1870 object = WINE_RB_ENTRY_VALUE(entry, struct d3d10_blend_state, entry);
1872 TRACE("Returning existing blend state %p.\n", object);
1873 *blend_state = &object->ID3D10BlendState_iface;
1874 ID3D10BlendState_AddRef(*blend_state);
1875 wined3d_mutex_unlock();
1877 return S_OK;
1879 wined3d_mutex_unlock();
1881 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1882 if (!object)
1883 return E_OUTOFMEMORY;
1885 if (FAILED(hr = d3d10_blend_state_init(object, device, desc)))
1887 WARN("Failed to initialize blend state, hr %#x.\n", hr);
1888 HeapFree(GetProcessHeap(), 0, object);
1889 return hr;
1892 TRACE("Created blend state %p.\n", object);
1893 *blend_state = &object->ID3D10BlendState_iface;
1895 return S_OK;
1898 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateDepthStencilState(ID3D10Device1 *iface,
1899 const D3D10_DEPTH_STENCIL_DESC *desc, ID3D10DepthStencilState **depth_stencil_state)
1901 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1902 struct d3d10_depthstencil_state *object;
1903 D3D10_DEPTH_STENCIL_DESC tmp_desc;
1904 struct wine_rb_entry *entry;
1905 HRESULT hr;
1907 TRACE("iface %p, desc %p, depth_stencil_state %p.\n", iface, desc, depth_stencil_state);
1909 if (!desc)
1910 return E_INVALIDARG;
1912 /* D3D10_DEPTH_STENCIL_DESC has a hole, which is a problem because we use
1913 * it as a key in the rbtree. */
1914 memset(&tmp_desc, 0, sizeof(tmp_desc));
1915 tmp_desc.DepthEnable = desc->DepthEnable;
1916 tmp_desc.DepthWriteMask = desc->DepthWriteMask;
1917 tmp_desc.DepthFunc = desc->DepthFunc;
1918 tmp_desc.StencilEnable = desc->StencilEnable;
1919 tmp_desc.StencilReadMask = desc->StencilReadMask;
1920 tmp_desc.StencilWriteMask = desc->StencilWriteMask;
1921 tmp_desc.FrontFace = desc->FrontFace;
1922 tmp_desc.BackFace = desc->BackFace;
1924 wined3d_mutex_lock();
1925 if ((entry = wine_rb_get(&device->depthstencil_states, &tmp_desc)))
1927 object = WINE_RB_ENTRY_VALUE(entry, struct d3d10_depthstencil_state, entry);
1929 TRACE("Returning existing depthstencil state %p.\n", object);
1930 *depth_stencil_state = &object->ID3D10DepthStencilState_iface;
1931 ID3D10DepthStencilState_AddRef(*depth_stencil_state);
1932 wined3d_mutex_unlock();
1934 return S_OK;
1936 wined3d_mutex_unlock();
1938 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1939 if (!object)
1940 return E_OUTOFMEMORY;
1942 if (FAILED(hr = d3d10_depthstencil_state_init(object, device, &tmp_desc)))
1944 WARN("Failed to initialize depthstencil state, hr %#x.\n", hr);
1945 HeapFree(GetProcessHeap(), 0, object);
1946 return hr;
1949 TRACE("Created depthstencil state %p.\n", object);
1950 *depth_stencil_state = &object->ID3D10DepthStencilState_iface;
1952 return S_OK;
1955 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateRasterizerState(ID3D10Device1 *iface,
1956 const D3D10_RASTERIZER_DESC *desc, ID3D10RasterizerState **rasterizer_state)
1958 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1959 struct d3d10_rasterizer_state *object;
1960 struct wine_rb_entry *entry;
1961 HRESULT hr;
1963 TRACE("iface %p, desc %p, rasterizer_state %p.\n", iface, desc, rasterizer_state);
1965 if (!desc)
1966 return E_INVALIDARG;
1968 wined3d_mutex_lock();
1969 if ((entry = wine_rb_get(&device->rasterizer_states, desc)))
1971 object = WINE_RB_ENTRY_VALUE(entry, struct d3d10_rasterizer_state, entry);
1973 TRACE("Returning existing rasterizer state %p.\n", object);
1974 *rasterizer_state = &object->ID3D10RasterizerState_iface;
1975 ID3D10RasterizerState_AddRef(*rasterizer_state);
1976 wined3d_mutex_unlock();
1978 return S_OK;
1980 wined3d_mutex_unlock();
1982 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1983 if (!object)
1984 return E_OUTOFMEMORY;
1986 if (FAILED(hr = d3d10_rasterizer_state_init(object, device, desc)))
1988 WARN("Failed to initialize rasterizer state, hr %#x.\n", hr);
1989 HeapFree(GetProcessHeap(), 0, object);
1990 return hr;
1993 TRACE("Created rasterizer state %p.\n", object);
1994 *rasterizer_state = &object->ID3D10RasterizerState_iface;
1996 return S_OK;
1999 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateSamplerState(ID3D10Device1 *iface,
2000 const D3D10_SAMPLER_DESC *desc, ID3D10SamplerState **sampler_state)
2002 struct d3d10_device *device = impl_from_ID3D10Device(iface);
2003 struct d3d10_sampler_state *object;
2004 struct wine_rb_entry *entry;
2005 HRESULT hr;
2007 TRACE("iface %p, desc %p, sampler_state %p.\n", iface, desc, sampler_state);
2009 if (!desc)
2010 return E_INVALIDARG;
2012 wined3d_mutex_lock();
2013 if ((entry = wine_rb_get(&device->sampler_states, desc)))
2015 object = WINE_RB_ENTRY_VALUE(entry, struct d3d10_sampler_state, entry);
2017 TRACE("Returning existing sampler state %p.\n", object);
2018 *sampler_state = &object->ID3D10SamplerState_iface;
2019 ID3D10SamplerState_AddRef(*sampler_state);
2020 wined3d_mutex_unlock();
2022 return S_OK;
2024 wined3d_mutex_unlock();
2026 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
2027 if (!object)
2028 return E_OUTOFMEMORY;
2030 if (FAILED(hr = d3d10_sampler_state_init(object, device, desc)))
2032 WARN("Failed to initialize sampler state, hr %#x.\n", hr);
2033 HeapFree(GetProcessHeap(), 0, object);
2034 return hr;
2037 TRACE("Created sampler state %p.\n", object);
2038 *sampler_state = &object->ID3D10SamplerState_iface;
2040 return S_OK;
2043 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateQuery(ID3D10Device1 *iface,
2044 const D3D10_QUERY_DESC *desc, ID3D10Query **query)
2046 struct d3d10_device *device = impl_from_ID3D10Device(iface);
2047 struct d3d10_query *object;
2048 HRESULT hr;
2050 TRACE("iface %p, desc %p, query %p.\n", iface, desc, query);
2052 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
2053 return E_OUTOFMEMORY;
2055 if (FAILED(hr = d3d10_query_init(object, device, desc, FALSE)))
2057 WARN("Failed to initialize query, hr %#x.\n", hr);
2058 HeapFree(GetProcessHeap(), 0, object);
2059 return hr;
2062 TRACE("Created query %p.\n", object);
2063 *query = &object->ID3D10Query_iface;
2065 return S_OK;
2068 static HRESULT STDMETHODCALLTYPE d3d10_device_CreatePredicate(ID3D10Device1 *iface,
2069 const D3D10_QUERY_DESC *desc, ID3D10Predicate **predicate)
2071 struct d3d10_device *device = impl_from_ID3D10Device(iface);
2072 struct d3d10_query *object;
2073 HRESULT hr;
2075 TRACE("iface %p, desc %p, predicate %p.\n", iface, desc, predicate);
2077 if (!desc)
2078 return E_INVALIDARG;
2080 if (desc->Query != D3D10_QUERY_OCCLUSION_PREDICATE && desc->Query != D3D10_QUERY_SO_OVERFLOW_PREDICATE)
2082 WARN("Query type %#x is not a predicate.\n", desc->Query);
2083 return E_INVALIDARG;
2086 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
2087 return E_OUTOFMEMORY;
2089 if (FAILED(hr = d3d10_query_init(object, device, desc, TRUE)))
2091 WARN("Failed to initialize predicate, hr %#x.\n", hr);
2092 HeapFree(GetProcessHeap(), 0, object);
2093 return hr;
2096 TRACE("Created predicate %p.\n", object);
2097 *predicate = (ID3D10Predicate *)&object->ID3D10Query_iface;
2099 return S_OK;
2102 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateCounter(ID3D10Device1 *iface,
2103 const D3D10_COUNTER_DESC *desc, ID3D10Counter **counter)
2105 FIXME("iface %p, desc %p, counter %p stub!\n", iface, desc, counter);
2107 return E_NOTIMPL;
2110 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckFormatSupport(ID3D10Device1 *iface,
2111 DXGI_FORMAT format, UINT *format_support)
2113 FIXME("iface %p, format %s, format_support %p stub!\n",
2114 iface, debug_dxgi_format(format), format_support);
2116 return E_NOTIMPL;
2119 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckMultisampleQualityLevels(ID3D10Device1 *iface,
2120 DXGI_FORMAT format, UINT sample_count, UINT *quality_level_count)
2122 FIXME("iface %p, format %s, sample_count %u, quality_level_count %p stub!\n",
2123 iface, debug_dxgi_format(format), sample_count, quality_level_count);
2125 return E_NOTIMPL;
2128 static void STDMETHODCALLTYPE d3d10_device_CheckCounterInfo(ID3D10Device1 *iface, D3D10_COUNTER_INFO *counter_info)
2130 FIXME("iface %p, counter_info %p stub!\n", iface, counter_info);
2133 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckCounter(ID3D10Device1 *iface,
2134 const D3D10_COUNTER_DESC *desc, D3D10_COUNTER_TYPE *type, UINT *active_counters, char *name,
2135 UINT *name_length, char *units, UINT *units_length, char *description, UINT *description_length)
2137 FIXME("iface %p, desc %p, type %p, active_counters %p, name %p, name_length %p,\n"
2138 "\tunits %p, units_length %p, description %p, description_length %p stub!\n",
2139 iface, desc, type, active_counters, name, name_length,
2140 units, units_length, description, description_length);
2142 return E_NOTIMPL;
2145 static UINT STDMETHODCALLTYPE d3d10_device_GetCreationFlags(ID3D10Device1 *iface)
2147 FIXME("iface %p stub!\n", iface);
2149 return 0;
2152 static HRESULT STDMETHODCALLTYPE d3d10_device_OpenSharedResource(ID3D10Device1 *iface,
2153 HANDLE resource_handle, REFIID guid, void **resource)
2155 FIXME("iface %p, resource_handle %p, guid %s, resource %p stub!\n",
2156 iface, resource_handle, debugstr_guid(guid), resource);
2158 return E_NOTIMPL;
2161 static void STDMETHODCALLTYPE d3d10_device_SetTextFilterSize(ID3D10Device1 *iface, UINT width, UINT height)
2163 FIXME("iface %p, width %u, height %u stub!\n", iface, width, height);
2166 static void STDMETHODCALLTYPE d3d10_device_GetTextFilterSize(ID3D10Device1 *iface, UINT *width, UINT *height)
2168 FIXME("iface %p, width %p, height %p stub!\n", iface, width, height);
2171 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateShaderResourceView1(ID3D10Device1 *iface,
2172 ID3D10Resource *resource, const D3D10_SHADER_RESOURCE_VIEW_DESC1 *desc, ID3D10ShaderResourceView1 **view)
2174 FIXME("iface %p, resource %p, desc %p, view %p stub!\n", iface, resource, desc, view);
2176 return E_NOTIMPL;
2179 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBlendState1(ID3D10Device1 *iface,
2180 const D3D10_BLEND_DESC1 *desc, ID3D10BlendState1 **blend_state)
2182 FIXME("iface %p, desc %p, blend_state %p stub!\n", iface, desc, blend_state);
2184 return E_NOTIMPL;
2187 static D3D10_FEATURE_LEVEL1 STDMETHODCALLTYPE d3d10_device_GetFeatureLevel(ID3D10Device1 *iface)
2189 FIXME("iface %p stub!\n", iface);
2191 return D3D10_FEATURE_LEVEL_10_1;
2194 static const struct ID3D10Device1Vtbl d3d10_device1_vtbl =
2196 /* IUnknown methods */
2197 d3d10_device_QueryInterface,
2198 d3d10_device_AddRef,
2199 d3d10_device_Release,
2200 /* ID3D10Device methods */
2201 d3d10_device_VSSetConstantBuffers,
2202 d3d10_device_PSSetShaderResources,
2203 d3d10_device_PSSetShader,
2204 d3d10_device_PSSetSamplers,
2205 d3d10_device_VSSetShader,
2206 d3d10_device_DrawIndexed,
2207 d3d10_device_Draw,
2208 d3d10_device_PSSetConstantBuffers,
2209 d3d10_device_IASetInputLayout,
2210 d3d10_device_IASetVertexBuffers,
2211 d3d10_device_IASetIndexBuffer,
2212 d3d10_device_DrawIndexedInstanced,
2213 d3d10_device_DrawInstanced,
2214 d3d10_device_GSSetConstantBuffers,
2215 d3d10_device_GSSetShader,
2216 d3d10_device_IASetPrimitiveTopology,
2217 d3d10_device_VSSetShaderResources,
2218 d3d10_device_VSSetSamplers,
2219 d3d10_device_SetPredication,
2220 d3d10_device_GSSetShaderResources,
2221 d3d10_device_GSSetSamplers,
2222 d3d10_device_OMSetRenderTargets,
2223 d3d10_device_OMSetBlendState,
2224 d3d10_device_OMSetDepthStencilState,
2225 d3d10_device_SOSetTargets,
2226 d3d10_device_DrawAuto,
2227 d3d10_device_RSSetState,
2228 d3d10_device_RSSetViewports,
2229 d3d10_device_RSSetScissorRects,
2230 d3d10_device_CopySubresourceRegion,
2231 d3d10_device_CopyResource,
2232 d3d10_device_UpdateSubresource,
2233 d3d10_device_ClearRenderTargetView,
2234 d3d10_device_ClearDepthStencilView,
2235 d3d10_device_GenerateMips,
2236 d3d10_device_ResolveSubresource,
2237 d3d10_device_VSGetConstantBuffers,
2238 d3d10_device_PSGetShaderResources,
2239 d3d10_device_PSGetShader,
2240 d3d10_device_PSGetSamplers,
2241 d3d10_device_VSGetShader,
2242 d3d10_device_PSGetConstantBuffers,
2243 d3d10_device_IAGetInputLayout,
2244 d3d10_device_IAGetVertexBuffers,
2245 d3d10_device_IAGetIndexBuffer,
2246 d3d10_device_GSGetConstantBuffers,
2247 d3d10_device_GSGetShader,
2248 d3d10_device_IAGetPrimitiveTopology,
2249 d3d10_device_VSGetShaderResources,
2250 d3d10_device_VSGetSamplers,
2251 d3d10_device_GetPredication,
2252 d3d10_device_GSGetShaderResources,
2253 d3d10_device_GSGetSamplers,
2254 d3d10_device_OMGetRenderTargets,
2255 d3d10_device_OMGetBlendState,
2256 d3d10_device_OMGetDepthStencilState,
2257 d3d10_device_SOGetTargets,
2258 d3d10_device_RSGetState,
2259 d3d10_device_RSGetViewports,
2260 d3d10_device_RSGetScissorRects,
2261 d3d10_device_GetDeviceRemovedReason,
2262 d3d10_device_SetExceptionMode,
2263 d3d10_device_GetExceptionMode,
2264 d3d10_device_GetPrivateData,
2265 d3d10_device_SetPrivateData,
2266 d3d10_device_SetPrivateDataInterface,
2267 d3d10_device_ClearState,
2268 d3d10_device_Flush,
2269 d3d10_device_CreateBuffer,
2270 d3d10_device_CreateTexture1D,
2271 d3d10_device_CreateTexture2D,
2272 d3d10_device_CreateTexture3D,
2273 d3d10_device_CreateShaderResourceView,
2274 d3d10_device_CreateRenderTargetView,
2275 d3d10_device_CreateDepthStencilView,
2276 d3d10_device_CreateInputLayout,
2277 d3d10_device_CreateVertexShader,
2278 d3d10_device_CreateGeometryShader,
2279 d3d10_device_CreateGeometryShaderWithStreamOutput,
2280 d3d10_device_CreatePixelShader,
2281 d3d10_device_CreateBlendState,
2282 d3d10_device_CreateDepthStencilState,
2283 d3d10_device_CreateRasterizerState,
2284 d3d10_device_CreateSamplerState,
2285 d3d10_device_CreateQuery,
2286 d3d10_device_CreatePredicate,
2287 d3d10_device_CreateCounter,
2288 d3d10_device_CheckFormatSupport,
2289 d3d10_device_CheckMultisampleQualityLevels,
2290 d3d10_device_CheckCounterInfo,
2291 d3d10_device_CheckCounter,
2292 d3d10_device_GetCreationFlags,
2293 d3d10_device_OpenSharedResource,
2294 d3d10_device_SetTextFilterSize,
2295 d3d10_device_GetTextFilterSize,
2296 d3d10_device_CreateShaderResourceView1,
2297 d3d10_device_CreateBlendState1,
2298 d3d10_device_GetFeatureLevel,
2301 static const struct IUnknownVtbl d3d10_device_inner_unknown_vtbl =
2303 /* IUnknown methods */
2304 d3d10_device_inner_QueryInterface,
2305 d3d10_device_inner_AddRef,
2306 d3d10_device_inner_Release,
2309 static inline struct d3d10_device *impl_from_ID3D10Multithread(ID3D10Multithread *iface)
2311 return CONTAINING_RECORD(iface, struct d3d10_device, ID3D10Multithread_iface);
2314 static HRESULT STDMETHODCALLTYPE d3d10_multithread_QueryInterface(ID3D10Multithread *iface, REFIID iid, void **out)
2316 struct d3d10_device *device = impl_from_ID3D10Multithread(iface);
2318 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
2320 return IUnknown_QueryInterface(device->outer_unk, iid, out);
2323 static ULONG STDMETHODCALLTYPE d3d10_multithread_AddRef(ID3D10Multithread *iface)
2325 struct d3d10_device *device = impl_from_ID3D10Multithread(iface);
2327 TRACE("iface %p.\n", iface);
2329 return IUnknown_AddRef(device->outer_unk);
2332 static ULONG STDMETHODCALLTYPE d3d10_multithread_Release(ID3D10Multithread *iface)
2334 struct d3d10_device *device = impl_from_ID3D10Multithread(iface);
2336 TRACE("iface %p.\n", iface);
2338 return IUnknown_Release(device->outer_unk);
2341 static void STDMETHODCALLTYPE d3d10_multithread_Enter(ID3D10Multithread *iface)
2343 TRACE("iface %p.\n", iface);
2345 wined3d_mutex_lock();
2348 static void STDMETHODCALLTYPE d3d10_multithread_Leave(ID3D10Multithread *iface)
2350 TRACE("iface %p.\n", iface);
2352 wined3d_mutex_unlock();
2355 static BOOL STDMETHODCALLTYPE d3d10_multithread_SetMultithreadProtected(ID3D10Multithread *iface, BOOL protect)
2357 FIXME("iface %p, protect %#x stub!\n", iface, protect);
2359 return TRUE;
2362 static BOOL STDMETHODCALLTYPE d3d10_multithread_GetMultithreadProtected(ID3D10Multithread *iface)
2364 FIXME("iface %p stub!\n", iface);
2366 return TRUE;
2369 static const struct ID3D10MultithreadVtbl d3d10_multithread_vtbl =
2371 d3d10_multithread_QueryInterface,
2372 d3d10_multithread_AddRef,
2373 d3d10_multithread_Release,
2374 d3d10_multithread_Enter,
2375 d3d10_multithread_Leave,
2376 d3d10_multithread_SetMultithreadProtected,
2377 d3d10_multithread_GetMultithreadProtected,
2380 /* IWineDXGIDeviceParent IUnknown methods */
2382 static inline struct d3d10_device *device_from_dxgi_device_parent(IWineDXGIDeviceParent *iface)
2384 return CONTAINING_RECORD(iface, struct d3d10_device, IWineDXGIDeviceParent_iface);
2387 static HRESULT STDMETHODCALLTYPE dxgi_device_parent_QueryInterface(IWineDXGIDeviceParent *iface,
2388 REFIID riid, void **ppv)
2390 struct d3d10_device *device = device_from_dxgi_device_parent(iface);
2391 return IUnknown_QueryInterface(device->outer_unk, riid, ppv);
2394 static ULONG STDMETHODCALLTYPE dxgi_device_parent_AddRef(IWineDXGIDeviceParent *iface)
2396 struct d3d10_device *device = device_from_dxgi_device_parent(iface);
2397 return IUnknown_AddRef(device->outer_unk);
2400 static ULONG STDMETHODCALLTYPE dxgi_device_parent_Release(IWineDXGIDeviceParent *iface)
2402 struct d3d10_device *device = device_from_dxgi_device_parent(iface);
2403 return IUnknown_Release(device->outer_unk);
2406 static struct wined3d_device_parent * STDMETHODCALLTYPE dxgi_device_parent_get_wined3d_device_parent(
2407 IWineDXGIDeviceParent *iface)
2409 struct d3d10_device *device = device_from_dxgi_device_parent(iface);
2410 return &device->device_parent;
2413 static const struct IWineDXGIDeviceParentVtbl d3d10_dxgi_device_parent_vtbl =
2415 /* IUnknown methods */
2416 dxgi_device_parent_QueryInterface,
2417 dxgi_device_parent_AddRef,
2418 dxgi_device_parent_Release,
2419 /* IWineDXGIDeviceParent methods */
2420 dxgi_device_parent_get_wined3d_device_parent,
2423 static inline struct d3d10_device *device_from_wined3d_device_parent(struct wined3d_device_parent *device_parent)
2425 return CONTAINING_RECORD(device_parent, struct d3d10_device, device_parent);
2428 static void CDECL device_parent_wined3d_device_created(struct wined3d_device_parent *device_parent,
2429 struct wined3d_device *wined3d_device)
2431 struct d3d10_device *device = device_from_wined3d_device_parent(device_parent);
2433 TRACE("device_parent %p, wined3d_device %p.\n", device_parent, wined3d_device);
2435 wined3d_device_incref(wined3d_device);
2436 device->wined3d_device = wined3d_device;
2439 static void CDECL device_parent_mode_changed(struct wined3d_device_parent *device_parent)
2441 TRACE("device_parent %p.\n", device_parent);
2444 static void CDECL device_parent_activate(struct wined3d_device_parent *device_parent, BOOL activate)
2446 TRACE("device_parent %p, activate %#x.\n", device_parent, activate);
2449 static HRESULT CDECL device_parent_surface_created(struct wined3d_device_parent *device_parent,
2450 void *container_parent, struct wined3d_surface *surface, void **parent,
2451 const struct wined3d_parent_ops **parent_ops)
2453 TRACE("device_parent %p, container_parent %p, surface %p, parent %p, parent_ops %p.\n",
2454 device_parent, container_parent, surface, parent, parent_ops);
2456 *parent = container_parent;
2457 *parent_ops = &d3d10_null_wined3d_parent_ops;
2459 return S_OK;
2462 static HRESULT CDECL device_parent_volume_created(struct wined3d_device_parent *device_parent,
2463 void *container_parent, struct wined3d_volume *volume, void **parent,
2464 const struct wined3d_parent_ops **parent_ops)
2466 TRACE("device_parent %p, container_parent %p, volume %p, parent %p, parent_ops %p.\n",
2467 device_parent, container_parent, volume, parent, parent_ops);
2469 *parent = container_parent;
2470 *parent_ops = &d3d10_null_wined3d_parent_ops;
2472 return S_OK;
2475 static HRESULT CDECL device_parent_create_swapchain_surface(struct wined3d_device_parent *device_parent,
2476 void *container_parent, const struct wined3d_resource_desc *wined3d_desc, struct wined3d_surface **surface)
2478 struct d3d10_device *device = device_from_wined3d_device_parent(device_parent);
2479 struct wined3d_resource *sub_resource;
2480 struct d3d10_texture2d *texture;
2481 D3D10_TEXTURE2D_DESC desc;
2482 HRESULT hr;
2484 FIXME("device_parent %p, container_parent %p, wined3d_desc %p, surface %p partial stub!\n",
2485 device_parent, container_parent, wined3d_desc, surface);
2487 FIXME("Implement DXGI<->wined3d usage conversion\n");
2489 desc.Width = wined3d_desc->width;
2490 desc.Height = wined3d_desc->height;
2491 desc.MipLevels = 1;
2492 desc.ArraySize = 1;
2493 desc.Format = dxgi_format_from_wined3dformat(wined3d_desc->format);
2494 desc.SampleDesc.Count = wined3d_desc->multisample_type ? wined3d_desc->multisample_type : 1;
2495 desc.SampleDesc.Quality = wined3d_desc->multisample_quality;
2496 desc.Usage = D3D10_USAGE_DEFAULT;
2497 desc.BindFlags = D3D10_BIND_RENDER_TARGET;
2498 desc.CPUAccessFlags = 0;
2499 desc.MiscFlags = 0;
2501 if (FAILED(hr = d3d10_device_CreateTexture2D(&device->ID3D10Device1_iface,
2502 &desc, NULL, (ID3D10Texture2D **)&texture)))
2504 ERR("CreateTexture2D failed, returning %#x\n", hr);
2505 return hr;
2508 sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, 0);
2509 *surface = wined3d_surface_from_resource(sub_resource);
2510 wined3d_surface_incref(*surface);
2511 ID3D10Texture2D_Release(&texture->ID3D10Texture2D_iface);
2513 return S_OK;
2516 static HRESULT CDECL device_parent_create_swapchain(struct wined3d_device_parent *device_parent,
2517 struct wined3d_swapchain_desc *desc, struct wined3d_swapchain **swapchain)
2519 struct d3d10_device *device = device_from_wined3d_device_parent(device_parent);
2520 IWineDXGIDevice *wine_device;
2521 HRESULT hr;
2523 TRACE("device_parent %p, desc %p, swapchain %p.\n", device_parent, desc, swapchain);
2525 if (FAILED(hr = d3d10_device_QueryInterface(&device->ID3D10Device1_iface,
2526 &IID_IWineDXGIDevice, (void **)&wine_device)))
2528 ERR("Device should implement IWineDXGIDevice.\n");
2529 return E_FAIL;
2532 hr = IWineDXGIDevice_create_swapchain(wine_device, desc, swapchain);
2533 IWineDXGIDevice_Release(wine_device);
2534 if (FAILED(hr))
2536 ERR("Failed to create DXGI swapchain, returning %#x\n", hr);
2537 return hr;
2540 return S_OK;
2543 static const struct wined3d_device_parent_ops d3d10_wined3d_device_parent_ops =
2545 device_parent_wined3d_device_created,
2546 device_parent_mode_changed,
2547 device_parent_activate,
2548 device_parent_surface_created,
2549 device_parent_volume_created,
2550 device_parent_create_swapchain_surface,
2551 device_parent_create_swapchain,
2554 static void *d3d10_rb_alloc(size_t size)
2556 return HeapAlloc(GetProcessHeap(), 0, size);
2559 static void *d3d10_rb_realloc(void *ptr, size_t size)
2561 return HeapReAlloc(GetProcessHeap(), 0, ptr, size);
2564 static void d3d10_rb_free(void *ptr)
2566 HeapFree(GetProcessHeap(), 0, ptr);
2569 static int d3d10_sampler_state_compare(const void *key, const struct wine_rb_entry *entry)
2571 const D3D10_SAMPLER_DESC *ka = key;
2572 const D3D10_SAMPLER_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d10_sampler_state, entry)->desc;
2574 return memcmp(ka, kb, sizeof(*ka));
2577 static const struct wine_rb_functions d3d10_sampler_state_rb_ops =
2579 d3d10_rb_alloc,
2580 d3d10_rb_realloc,
2581 d3d10_rb_free,
2582 d3d10_sampler_state_compare,
2585 static int d3d10_blend_state_compare(const void *key, const struct wine_rb_entry *entry)
2587 const D3D10_BLEND_DESC *ka = key;
2588 const D3D10_BLEND_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d10_blend_state, entry)->desc;
2590 return memcmp(ka, kb, sizeof(*ka));
2593 static const struct wine_rb_functions d3d10_blend_state_rb_ops =
2595 d3d10_rb_alloc,
2596 d3d10_rb_realloc,
2597 d3d10_rb_free,
2598 d3d10_blend_state_compare,
2601 static int d3d10_depthstencil_state_compare(const void *key, const struct wine_rb_entry *entry)
2603 const D3D10_DEPTH_STENCIL_DESC *ka = key;
2604 const D3D10_DEPTH_STENCIL_DESC *kb = &WINE_RB_ENTRY_VALUE(entry,
2605 const struct d3d10_depthstencil_state, entry)->desc;
2607 return memcmp(ka, kb, sizeof(*ka));
2610 static const struct wine_rb_functions d3d10_depthstencil_state_rb_ops =
2612 d3d10_rb_alloc,
2613 d3d10_rb_realloc,
2614 d3d10_rb_free,
2615 d3d10_depthstencil_state_compare,
2618 static int d3d10_rasterizer_state_compare(const void *key, const struct wine_rb_entry *entry)
2620 const D3D10_RASTERIZER_DESC *ka = key;
2621 const D3D10_RASTERIZER_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d10_rasterizer_state, entry)->desc;
2623 return memcmp(ka, kb, sizeof(*ka));
2626 static const struct wine_rb_functions d3d10_rasterizer_state_rb_ops =
2628 d3d10_rb_alloc,
2629 d3d10_rb_realloc,
2630 d3d10_rb_free,
2631 d3d10_rasterizer_state_compare,
2634 HRESULT d3d10_device_init(struct d3d10_device *device, void *outer_unknown)
2636 device->IUnknown_inner.lpVtbl = &d3d10_device_inner_unknown_vtbl;
2637 device->ID3D10Device1_iface.lpVtbl = &d3d10_device1_vtbl;
2638 device->ID3D10Multithread_iface.lpVtbl = &d3d10_multithread_vtbl;
2639 device->IWineDXGIDeviceParent_iface.lpVtbl = &d3d10_dxgi_device_parent_vtbl;
2640 device->device_parent.ops = &d3d10_wined3d_device_parent_ops;
2641 device->refcount = 1;
2642 /* COM aggregation always takes place */
2643 device->outer_unk = outer_unknown;
2645 if (wine_rb_init(&device->blend_states, &d3d10_blend_state_rb_ops) == -1)
2647 WARN("Failed to initialize blend state rbtree.\n");
2648 return E_FAIL;
2650 device->blend_factor[0] = 1.0f;
2651 device->blend_factor[1] = 1.0f;
2652 device->blend_factor[2] = 1.0f;
2653 device->blend_factor[3] = 1.0f;
2655 if (wine_rb_init(&device->depthstencil_states, &d3d10_depthstencil_state_rb_ops) == -1)
2657 WARN("Failed to initialize depthstencil state rbtree.\n");
2658 wine_rb_destroy(&device->blend_states, NULL, NULL);
2659 return E_FAIL;
2662 if (wine_rb_init(&device->rasterizer_states, &d3d10_rasterizer_state_rb_ops) == -1)
2664 WARN("Failed to initialize rasterizer state rbtree.\n");
2665 wine_rb_destroy(&device->depthstencil_states, NULL, NULL);
2666 wine_rb_destroy(&device->blend_states, NULL, NULL);
2667 return E_FAIL;
2670 if (wine_rb_init(&device->sampler_states, &d3d10_sampler_state_rb_ops) == -1)
2672 WARN("Failed to initialize sampler state rbtree.\n");
2673 wine_rb_destroy(&device->rasterizer_states, NULL, NULL);
2674 wine_rb_destroy(&device->depthstencil_states, NULL, NULL);
2675 wine_rb_destroy(&device->blend_states, NULL, NULL);
2676 return E_FAIL;
2679 return S_OK;