d3d10core: Implement d3d10_blend_state_GetDesc().
[wine/multimedia.git] / dlls / d3d10core / device.c
blob1025b42ae8718e32adde79ee466e361de627e5be
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,
42 void **ppv)
44 struct d3d10_device *This = impl_from_IUnknown(iface);
46 TRACE("iface %p, riid %s, ppv %p\n", iface, debugstr_guid(riid), ppv);
48 if (IsEqualGUID(riid, &IID_IUnknown) || IsEqualGUID(riid, &IID_ID3D10Device))
49 *ppv = &This->ID3D10Device_iface;
50 else if (IsEqualGUID(riid, &IID_IWineDXGIDeviceParent))
51 *ppv = &This->IWineDXGIDeviceParent_iface;
52 else
54 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid));
55 *ppv = NULL;
56 return E_NOINTERFACE;
59 IUnknown_AddRef((IUnknown*)*ppv);
60 return S_OK;
63 static ULONG STDMETHODCALLTYPE d3d10_device_inner_AddRef(IUnknown *iface)
65 struct d3d10_device *This = impl_from_IUnknown(iface);
66 ULONG refcount = InterlockedIncrement(&This->refcount);
68 TRACE("%p increasing refcount to %u\n", This, refcount);
70 return refcount;
73 static ULONG STDMETHODCALLTYPE d3d10_device_inner_Release(IUnknown *iface)
75 struct d3d10_device *device = impl_from_IUnknown(iface);
76 ULONG refcount = InterlockedDecrement(&device->refcount);
78 TRACE("%p decreasing refcount to %u.\n", device, refcount);
80 if (!refcount)
82 if (device->wined3d_device)
83 wined3d_device_decref(device->wined3d_device);
84 wine_rb_destroy(&device->sampler_states, NULL, NULL);
87 return refcount;
90 /* IUnknown methods */
92 static inline struct d3d10_device *impl_from_ID3D10Device(ID3D10Device *iface)
94 return CONTAINING_RECORD(iface, struct d3d10_device, ID3D10Device_iface);
97 static HRESULT STDMETHODCALLTYPE d3d10_device_QueryInterface(ID3D10Device *iface, REFIID riid,
98 void **ppv)
100 struct d3d10_device *This = impl_from_ID3D10Device(iface);
101 return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
104 static ULONG STDMETHODCALLTYPE d3d10_device_AddRef(ID3D10Device *iface)
106 struct d3d10_device *This = impl_from_ID3D10Device(iface);
107 return IUnknown_AddRef(This->outer_unk);
110 static ULONG STDMETHODCALLTYPE d3d10_device_Release(ID3D10Device *iface)
112 struct d3d10_device *This = impl_from_ID3D10Device(iface);
113 return IUnknown_Release(This->outer_unk);
116 /* ID3D10Device methods */
118 static void STDMETHODCALLTYPE d3d10_device_VSSetConstantBuffers(ID3D10Device *iface,
119 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
121 struct d3d10_device *device = impl_from_ID3D10Device(iface);
122 unsigned int i;
124 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
125 iface, start_slot, buffer_count, buffers);
127 for (i = 0; i < buffer_count; ++i)
129 struct d3d10_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
131 wined3d_device_set_vs_cb(device->wined3d_device, start_slot + i,
132 buffer ? buffer->wined3d_buffer : NULL);
136 static void STDMETHODCALLTYPE d3d10_device_PSSetShaderResources(ID3D10Device *iface,
137 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
139 FIXME("iface %p, start_slot %u, view_count %u, views %p stub!\n",
140 iface, start_slot, view_count, views);
143 static void STDMETHODCALLTYPE d3d10_device_PSSetShader(ID3D10Device *iface,
144 ID3D10PixelShader *shader)
146 struct d3d10_device *This = impl_from_ID3D10Device(iface);
147 struct d3d10_pixel_shader *ps = unsafe_impl_from_ID3D10PixelShader(shader);
149 TRACE("iface %p, shader %p\n", iface, shader);
151 wined3d_device_set_pixel_shader(This->wined3d_device, ps ? ps->wined3d_shader : NULL);
154 static void STDMETHODCALLTYPE d3d10_device_PSSetSamplers(ID3D10Device *iface,
155 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
157 struct d3d10_device *device = impl_from_ID3D10Device(iface);
158 unsigned int i;
160 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
161 iface, start_slot, sampler_count, samplers);
163 for (i = 0; i < sampler_count; ++i)
165 struct d3d10_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
167 wined3d_device_set_ps_sampler(device->wined3d_device, start_slot + i,
168 sampler ? sampler->wined3d_sampler : NULL);
172 static void STDMETHODCALLTYPE d3d10_device_VSSetShader(ID3D10Device *iface,
173 ID3D10VertexShader *shader)
175 struct d3d10_device *This = impl_from_ID3D10Device(iface);
176 struct d3d10_vertex_shader *vs = unsafe_impl_from_ID3D10VertexShader(shader);
178 TRACE("iface %p, shader %p\n", iface, shader);
180 wined3d_device_set_vertex_shader(This->wined3d_device, vs ? vs->wined3d_shader : NULL);
183 static void STDMETHODCALLTYPE d3d10_device_DrawIndexed(ID3D10Device *iface, UINT index_count,
184 UINT start_index_location, INT base_vertex_location)
186 struct d3d10_device *This = impl_from_ID3D10Device(iface);
188 TRACE("iface %p, index_count %u, start_index_location %u, base_vertex_location %d.\n",
189 iface, index_count, start_index_location, base_vertex_location);
191 wined3d_device_set_base_vertex_index(This->wined3d_device, base_vertex_location);
192 wined3d_device_draw_indexed_primitive(This->wined3d_device, start_index_location, index_count);
195 static void STDMETHODCALLTYPE d3d10_device_Draw(ID3D10Device *iface, UINT vertex_count,
196 UINT start_vertex_location)
198 struct d3d10_device *This = impl_from_ID3D10Device(iface);
200 TRACE("iface %p, vertex_count %u, start_vertex_location %u\n",
201 iface, vertex_count, start_vertex_location);
203 wined3d_device_draw_primitive(This->wined3d_device, start_vertex_location, vertex_count);
206 static void STDMETHODCALLTYPE d3d10_device_PSSetConstantBuffers(ID3D10Device *iface,
207 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
209 struct d3d10_device *device = impl_from_ID3D10Device(iface);
210 unsigned int i;
212 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
213 iface, start_slot, buffer_count, buffers);
215 for (i = 0; i < buffer_count; ++i)
217 struct d3d10_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
219 wined3d_device_set_ps_cb(device->wined3d_device, start_slot + i,
220 buffer ? buffer->wined3d_buffer : NULL);
224 static void STDMETHODCALLTYPE d3d10_device_IASetInputLayout(ID3D10Device *iface,
225 ID3D10InputLayout *input_layout)
227 struct d3d10_device *This = impl_from_ID3D10Device(iface);
228 struct d3d10_input_layout *layout = unsafe_impl_from_ID3D10InputLayout(input_layout);
230 TRACE("iface %p, input_layout %p\n", iface, input_layout);
232 wined3d_device_set_vertex_declaration(This->wined3d_device,
233 layout ? layout->wined3d_decl : NULL);
236 static void STDMETHODCALLTYPE d3d10_device_IASetVertexBuffers(ID3D10Device *iface, UINT start_slot,
237 UINT buffer_count, ID3D10Buffer *const *buffers, const UINT *strides, const UINT *offsets)
239 struct d3d10_device *This = impl_from_ID3D10Device(iface);
240 unsigned int i;
242 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p\n",
243 iface, start_slot, buffer_count, buffers, strides, offsets);
245 for (i = 0; i < buffer_count; ++i)
247 struct d3d10_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
249 wined3d_device_set_stream_source(This->wined3d_device, start_slot + i,
250 buffer ? buffer->wined3d_buffer : NULL, offsets[i], strides[i]);
254 static void STDMETHODCALLTYPE d3d10_device_IASetIndexBuffer(ID3D10Device *iface,
255 ID3D10Buffer *buffer, DXGI_FORMAT format, UINT offset)
257 struct d3d10_device *This = impl_from_ID3D10Device(iface);
258 struct d3d10_buffer *buffer_impl = unsafe_impl_from_ID3D10Buffer(buffer);
260 TRACE("iface %p, buffer %p, format %s, offset %u.\n",
261 iface, buffer, debug_dxgi_format(format), offset);
263 wined3d_device_set_index_buffer(This->wined3d_device,
264 buffer_impl ? buffer_impl->wined3d_buffer : NULL,
265 wined3dformat_from_dxgi_format(format));
266 if (offset) FIXME("offset %u not supported.\n", offset);
269 static void STDMETHODCALLTYPE d3d10_device_DrawIndexedInstanced(ID3D10Device *iface,
270 UINT instance_index_count, UINT instance_count, UINT start_index_location,
271 INT base_vertex_location, UINT start_instance_location)
273 struct d3d10_device *device = impl_from_ID3D10Device(iface);
275 TRACE("iface %p, instance_index_count %u, instance_count %u, start_index_location %u,\n"
276 "\tbase_vertex_location %d, start_instance_location %u.\n",
277 iface, instance_index_count, instance_count, start_index_location,
278 base_vertex_location, start_instance_location);
280 wined3d_device_set_base_vertex_index(device->wined3d_device, base_vertex_location);
281 wined3d_device_draw_indexed_primitive_instanced(device->wined3d_device, start_index_location,
282 instance_index_count, start_instance_location, instance_count);
285 static void STDMETHODCALLTYPE d3d10_device_DrawInstanced(ID3D10Device *iface,
286 UINT instance_vertex_count, UINT instance_count,
287 UINT start_vertex_location, UINT start_instance_location)
289 FIXME("iface %p, instance_vertex_count %u, instance_count %u, start_vertex_location %u,\n"
290 "\tstart_instance_location %u stub!\n", iface, instance_vertex_count, instance_count,
291 start_vertex_location, start_instance_location);
294 static void STDMETHODCALLTYPE d3d10_device_GSSetConstantBuffers(ID3D10Device *iface,
295 UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
297 struct d3d10_device *device = impl_from_ID3D10Device(iface);
298 unsigned int i;
300 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
301 iface, start_slot, buffer_count, buffers);
303 for (i = 0; i < buffer_count; ++i)
305 struct d3d10_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
307 wined3d_device_set_gs_cb(device->wined3d_device, start_slot + i,
308 buffer ? buffer->wined3d_buffer : NULL);
312 static void STDMETHODCALLTYPE d3d10_device_GSSetShader(ID3D10Device *iface, ID3D10GeometryShader *shader)
314 struct d3d10_device *device = impl_from_ID3D10Device(iface);
315 struct d3d10_geometry_shader *gs = unsafe_impl_from_ID3D10GeometryShader(shader);
317 TRACE("iface %p, shader %p.\n", iface, shader);
319 wined3d_device_set_geometry_shader(device->wined3d_device, gs ? gs->wined3d_shader : NULL);
322 static void STDMETHODCALLTYPE d3d10_device_IASetPrimitiveTopology(ID3D10Device *iface,
323 D3D10_PRIMITIVE_TOPOLOGY topology)
325 struct d3d10_device *This = impl_from_ID3D10Device(iface);
327 TRACE("iface %p, topology %s\n", iface, debug_d3d10_primitive_topology(topology));
329 wined3d_device_set_primitive_type(This->wined3d_device, (enum wined3d_primitive_type)topology);
332 static void STDMETHODCALLTYPE d3d10_device_VSSetShaderResources(ID3D10Device *iface,
333 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
335 FIXME("iface %p, start_slot %u, view_count %u, views %p stub!\n",
336 iface, start_slot, view_count, views);
339 static void STDMETHODCALLTYPE d3d10_device_VSSetSamplers(ID3D10Device *iface,
340 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
342 struct d3d10_device *device = impl_from_ID3D10Device(iface);
343 unsigned int i;
345 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
346 iface, start_slot, sampler_count, samplers);
348 for (i = 0; i < sampler_count; ++i)
350 struct d3d10_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
352 wined3d_device_set_vs_sampler(device->wined3d_device, start_slot + i,
353 sampler ? sampler->wined3d_sampler : NULL);
357 static void STDMETHODCALLTYPE d3d10_device_SetPredication(ID3D10Device *iface, ID3D10Predicate *predicate, BOOL value)
359 FIXME("iface %p, predicate %p, value %d stub!\n", iface, predicate, value);
362 static void STDMETHODCALLTYPE d3d10_device_GSSetShaderResources(ID3D10Device *iface,
363 UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
365 FIXME("iface %p, start_slot %u, view_count %u, views %p stub!\n",
366 iface, start_slot, view_count, views);
369 static void STDMETHODCALLTYPE d3d10_device_GSSetSamplers(ID3D10Device *iface,
370 UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
372 struct d3d10_device *device = impl_from_ID3D10Device(iface);
373 unsigned int i;
375 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
376 iface, start_slot, sampler_count, samplers);
378 for (i = 0; i < sampler_count; ++i)
380 struct d3d10_sampler_state *sampler = unsafe_impl_from_ID3D10SamplerState(samplers[i]);
382 wined3d_device_set_gs_sampler(device->wined3d_device, start_slot + i,
383 sampler ? sampler->wined3d_sampler : NULL);
387 static void STDMETHODCALLTYPE d3d10_device_OMSetRenderTargets(ID3D10Device *iface,
388 UINT render_target_view_count, ID3D10RenderTargetView *const *render_target_views,
389 ID3D10DepthStencilView *depth_stencil_view)
391 FIXME("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p\n",
392 iface, render_target_view_count, render_target_views, depth_stencil_view);
395 static void STDMETHODCALLTYPE d3d10_device_OMSetBlendState(ID3D10Device *iface,
396 ID3D10BlendState *blend_state, const FLOAT blend_factor[4], UINT sample_mask)
398 struct d3d10_device *device = impl_from_ID3D10Device(iface);
400 TRACE("iface %p, blend_state %p, blend_factor [%f %f %f %f], sample_mask 0x%08x.\n",
401 iface, blend_state, blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3], sample_mask);
403 device->blend_state = unsafe_impl_from_ID3D10BlendState(blend_state);
404 memcpy(device->blend_factor, blend_factor, 4 * sizeof(*blend_factor));
405 device->sample_mask = sample_mask;
408 static void STDMETHODCALLTYPE d3d10_device_OMSetDepthStencilState(ID3D10Device *iface,
409 ID3D10DepthStencilState *depth_stencil_state, UINT stencil_ref)
411 struct d3d10_device *device = impl_from_ID3D10Device(iface);
413 TRACE("iface %p, depth_stencil_state %p, stencil_ref %u.\n",
414 iface, depth_stencil_state, stencil_ref);
416 device->depth_stencil_state = unsafe_impl_from_ID3D10DepthStencilState(depth_stencil_state);
417 device->stencil_ref = stencil_ref;
420 static void STDMETHODCALLTYPE d3d10_device_SOSetTargets(ID3D10Device *iface,
421 UINT target_count, ID3D10Buffer *const *targets, const UINT *offsets)
423 struct d3d10_device *device = impl_from_ID3D10Device(iface);
424 unsigned int count, i;
426 TRACE("iface %p, target_count %u, targets %p, offsets %p.\n", iface, target_count, targets, offsets);
428 count = min(target_count, 4);
429 for (i = 0; i < count; ++i)
431 struct d3d10_buffer *buffer = unsafe_impl_from_ID3D10Buffer(targets[i]);
433 wined3d_device_set_stream_output(device->wined3d_device, i,
434 buffer ? buffer->wined3d_buffer : NULL, offsets[i]);
437 for (i = count; i < 4; ++i)
439 wined3d_device_set_stream_output(device->wined3d_device, i, NULL, 0);
443 static void STDMETHODCALLTYPE d3d10_device_DrawAuto(ID3D10Device *iface)
445 FIXME("iface %p stub!\n", iface);
448 static void STDMETHODCALLTYPE d3d10_device_RSSetState(ID3D10Device *iface, ID3D10RasterizerState *rasterizer_state)
450 struct d3d10_device *device = impl_from_ID3D10Device(iface);
452 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
454 device->rasterizer_state = unsafe_impl_from_ID3D10RasterizerState(rasterizer_state);
457 static void STDMETHODCALLTYPE d3d10_device_RSSetViewports(ID3D10Device *iface,
458 UINT viewport_count, const D3D10_VIEWPORT *viewports)
460 struct d3d10_device *device = impl_from_ID3D10Device(iface);
461 struct wined3d_viewport wined3d_vp;
463 TRACE("iface %p, viewport_count %u, viewports %p.\n", iface, viewport_count, viewports);
465 if (viewport_count > 1)
466 FIXME("Multiple viewports not implemented.\n");
468 if (!viewport_count)
469 return;
471 wined3d_vp.x = viewports[0].TopLeftX;
472 wined3d_vp.y = viewports[0].TopLeftY;
473 wined3d_vp.width = viewports[0].Width;
474 wined3d_vp.height = viewports[0].Height;
475 wined3d_vp.min_z = viewports[0].MinDepth;
476 wined3d_vp.max_z = viewports[0].MaxDepth;
478 wined3d_device_set_viewport(device->wined3d_device, &wined3d_vp);
481 static void STDMETHODCALLTYPE d3d10_device_RSSetScissorRects(ID3D10Device *iface,
482 UINT rect_count, const D3D10_RECT *rects)
484 struct d3d10_device *device = impl_from_ID3D10Device(iface);
486 TRACE("iface %p, rect_count %u, rects %p.\n", iface, rect_count, rects);
488 if (rect_count > 1)
489 FIXME("Multiple scissor rects not implemented.\n");
491 if (!rect_count)
492 return;
494 wined3d_device_set_scissor_rect(device->wined3d_device, rects);
497 static void STDMETHODCALLTYPE d3d10_device_CopySubresourceRegion(ID3D10Device *iface,
498 ID3D10Resource *dst_resource, UINT dst_subresource_idx, UINT dst_x, UINT dst_y, UINT dst_z,
499 ID3D10Resource *src_resource, UINT src_subresource_idx, const D3D10_BOX *src_box)
501 FIXME("iface %p, dst_resource %p, dst_subresource_idx %u, dst_x %u, dst_y %u, dst_z %u,\n"
502 "\tsrc_resource %p, src_subresource_idx %u, src_box %p stub!\n",
503 iface, dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
504 src_resource, src_subresource_idx, src_box);
507 static void STDMETHODCALLTYPE d3d10_device_CopyResource(ID3D10Device *iface,
508 ID3D10Resource *dst_resource, ID3D10Resource *src_resource)
510 FIXME("iface %p, dst_resource %p, src_resource %p stub!\n", iface, dst_resource, src_resource);
513 static void STDMETHODCALLTYPE d3d10_device_UpdateSubresource(ID3D10Device *iface,
514 ID3D10Resource *resource, UINT subresource_idx, const D3D10_BOX *box,
515 const void *data, UINT row_pitch, UINT depth_pitch)
517 FIXME("iface %p, resource %p, subresource_idx %u, box %p, data %p, row_pitch %u, depth_pitch %u stub!\n",
518 iface, resource, subresource_idx, box, data, row_pitch, depth_pitch);
521 static void STDMETHODCALLTYPE d3d10_device_ClearRenderTargetView(ID3D10Device *iface,
522 ID3D10RenderTargetView *render_target_view, const FLOAT color_rgba[4])
524 struct d3d10_device *This = impl_from_ID3D10Device(iface);
525 struct d3d10_rendertarget_view *view = unsafe_impl_from_ID3D10RenderTargetView(render_target_view);
526 const struct wined3d_color color = {color_rgba[0], color_rgba[1], color_rgba[2], color_rgba[3]};
528 TRACE("iface %p, render_target_view %p, color_rgba [%f %f %f %f]\n",
529 iface, render_target_view, color_rgba[0], color_rgba[1], color_rgba[2], color_rgba[3]);
531 wined3d_device_clear_rendertarget_view(This->wined3d_device, view->wined3d_view, &color);
534 static void STDMETHODCALLTYPE d3d10_device_ClearDepthStencilView(ID3D10Device *iface,
535 ID3D10DepthStencilView *depth_stencil_view, UINT flags, FLOAT depth, UINT8 stencil)
537 FIXME("iface %p, depth_stencil_view %p, flags %#x, depth %f, stencil %u stub!\n",
538 iface, depth_stencil_view, flags, depth, stencil);
541 static void STDMETHODCALLTYPE d3d10_device_GenerateMips(ID3D10Device *iface, ID3D10ShaderResourceView *shader_resource_view)
543 FIXME("iface %p, shader_resource_view %p stub!\n", iface, shader_resource_view);
546 static void STDMETHODCALLTYPE d3d10_device_ResolveSubresource(ID3D10Device *iface,
547 ID3D10Resource *dst_resource, UINT dst_subresource_idx,
548 ID3D10Resource *src_resource, UINT src_subresource_idx, DXGI_FORMAT format)
550 FIXME("iface %p, dst_resource %p, dst_subresource_idx %u,\n"
551 "\tsrc_resource %p, src_subresource_idx %u, format %s stub!\n",
552 iface, dst_resource, dst_subresource_idx,
553 src_resource, src_subresource_idx, debug_dxgi_format(format));
556 static void STDMETHODCALLTYPE d3d10_device_VSGetConstantBuffers(ID3D10Device *iface,
557 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
559 struct d3d10_device *device = impl_from_ID3D10Device(iface);
560 unsigned int i;
562 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
563 iface, start_slot, buffer_count, buffers);
565 for (i = 0; i < buffer_count; ++i)
567 struct wined3d_buffer *wined3d_buffer;
568 struct d3d10_buffer *buffer_impl;
570 if (!(wined3d_buffer = wined3d_device_get_vs_cb(device->wined3d_device, start_slot + i)))
572 buffers[i] = NULL;
573 continue;
576 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
577 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
578 ID3D10Buffer_AddRef(buffers[i]);
582 static void STDMETHODCALLTYPE d3d10_device_PSGetShaderResources(ID3D10Device *iface,
583 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
585 FIXME("iface %p, start_slot %u, view_count %u, views %p stub!\n",
586 iface, start_slot, view_count, views);
589 static void STDMETHODCALLTYPE d3d10_device_PSGetShader(ID3D10Device *iface, ID3D10PixelShader **shader)
591 struct d3d10_device *device = impl_from_ID3D10Device(iface);
592 struct d3d10_pixel_shader *shader_impl;
593 struct wined3d_shader *wined3d_shader;
595 TRACE("iface %p, shader %p.\n", iface, shader);
597 if (!(wined3d_shader = wined3d_device_get_pixel_shader(device->wined3d_device)))
599 *shader = NULL;
600 return;
603 shader_impl = wined3d_shader_get_parent(wined3d_shader);
604 *shader = &shader_impl->ID3D10PixelShader_iface;
605 ID3D10PixelShader_AddRef(*shader);
608 static void STDMETHODCALLTYPE d3d10_device_PSGetSamplers(ID3D10Device *iface,
609 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
611 struct d3d10_device *device = impl_from_ID3D10Device(iface);
612 unsigned int i;
614 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
615 iface, start_slot, sampler_count, samplers);
617 for (i = 0; i < sampler_count; ++i)
619 struct d3d10_sampler_state *sampler_impl;
620 struct wined3d_sampler *wined3d_sampler;
622 if (!(wined3d_sampler = wined3d_device_get_ps_sampler(device->wined3d_device, start_slot + i)))
624 samplers[i] = NULL;
625 continue;
628 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
629 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
630 ID3D10SamplerState_AddRef(samplers[i]);
634 static void STDMETHODCALLTYPE d3d10_device_VSGetShader(ID3D10Device *iface, ID3D10VertexShader **shader)
636 struct d3d10_device *device = impl_from_ID3D10Device(iface);
637 struct d3d10_vertex_shader *shader_impl;
638 struct wined3d_shader *wined3d_shader;
640 TRACE("iface %p, shader %p.\n", iface, shader);
642 if (!(wined3d_shader = wined3d_device_get_vertex_shader(device->wined3d_device)))
644 *shader = NULL;
645 return;
648 shader_impl = wined3d_shader_get_parent(wined3d_shader);
649 *shader = &shader_impl->ID3D10VertexShader_iface;
650 ID3D10VertexShader_AddRef(*shader);
653 static void STDMETHODCALLTYPE d3d10_device_PSGetConstantBuffers(ID3D10Device *iface,
654 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
656 struct d3d10_device *device = impl_from_ID3D10Device(iface);
657 unsigned int i;
659 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
660 iface, start_slot, buffer_count, buffers);
662 for (i = 0; i < buffer_count; ++i)
664 struct wined3d_buffer *wined3d_buffer;
665 struct d3d10_buffer *buffer_impl;
667 if (!(wined3d_buffer = wined3d_device_get_ps_cb(device->wined3d_device, start_slot + i)))
669 buffers[i] = NULL;
670 continue;
673 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
674 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
675 ID3D10Buffer_AddRef(buffers[i]);
679 static void STDMETHODCALLTYPE d3d10_device_IAGetInputLayout(ID3D10Device *iface, ID3D10InputLayout **input_layout)
681 struct d3d10_device *device = impl_from_ID3D10Device(iface);
682 struct wined3d_vertex_declaration *wined3d_declaration;
683 struct d3d10_input_layout *input_layout_impl;
685 TRACE("iface %p, input_layout %p.\n", iface, input_layout);
687 if (!(wined3d_declaration = wined3d_device_get_vertex_declaration(device->wined3d_device)))
689 *input_layout = NULL;
690 return;
693 input_layout_impl = wined3d_vertex_declaration_get_parent(wined3d_declaration);
694 *input_layout = &input_layout_impl->ID3D10InputLayout_iface;
695 ID3D10InputLayout_AddRef(*input_layout);
698 static void STDMETHODCALLTYPE d3d10_device_IAGetVertexBuffers(ID3D10Device *iface,
699 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers, UINT *strides, UINT *offsets)
701 struct d3d10_device *device = impl_from_ID3D10Device(iface);
702 unsigned int i;
704 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p.\n",
705 iface, start_slot, buffer_count, buffers, strides, offsets);
707 for (i = 0; i < buffer_count; ++i)
709 struct wined3d_buffer *wined3d_buffer;
710 struct d3d10_buffer *buffer_impl;
712 if (FAILED(wined3d_device_get_stream_source(device->wined3d_device, start_slot + i,
713 &wined3d_buffer, &offsets[i], &strides[i])))
714 ERR("Failed to get vertex buffer.\n");
716 if (!wined3d_buffer)
718 buffers[i] = NULL;
719 continue;
722 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
723 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
724 ID3D10Buffer_AddRef(buffers[i]);
728 static void STDMETHODCALLTYPE d3d10_device_IAGetIndexBuffer(ID3D10Device *iface,
729 ID3D10Buffer **buffer, DXGI_FORMAT *format, UINT *offset)
731 struct d3d10_device *device = impl_from_ID3D10Device(iface);
732 enum wined3d_format_id wined3d_format;
733 struct wined3d_buffer *wined3d_buffer;
734 struct d3d10_buffer *buffer_impl;
736 TRACE("iface %p, buffer %p, format %p, offset %p.\n", iface, buffer, format, offset);
738 wined3d_buffer = wined3d_device_get_index_buffer(device->wined3d_device, &wined3d_format);
739 *format = dxgi_format_from_wined3dformat(wined3d_format);
740 *offset = 0; /* FIXME */
741 if (!wined3d_buffer)
743 *buffer = NULL;
744 return;
747 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
748 *buffer = &buffer_impl->ID3D10Buffer_iface;
749 ID3D10Buffer_AddRef(*buffer);
752 static void STDMETHODCALLTYPE d3d10_device_GSGetConstantBuffers(ID3D10Device *iface,
753 UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
755 struct d3d10_device *device = impl_from_ID3D10Device(iface);
756 unsigned int i;
758 TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
759 iface, start_slot, buffer_count, buffers);
761 for (i = 0; i < buffer_count; ++i)
763 struct wined3d_buffer *wined3d_buffer;
764 struct d3d10_buffer *buffer_impl;
766 if (!(wined3d_buffer = wined3d_device_get_gs_cb(device->wined3d_device, start_slot + i)))
768 buffers[i] = NULL;
769 continue;
772 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
773 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
774 ID3D10Buffer_AddRef(buffers[i]);
778 static void STDMETHODCALLTYPE d3d10_device_GSGetShader(ID3D10Device *iface, ID3D10GeometryShader **shader)
780 struct d3d10_device *device = impl_from_ID3D10Device(iface);
781 struct d3d10_geometry_shader *shader_impl;
782 struct wined3d_shader *wined3d_shader;
784 TRACE("iface %p, shader %p.\n", iface, shader);
786 if (!(wined3d_shader = wined3d_device_get_geometry_shader(device->wined3d_device)))
788 *shader = NULL;
789 return;
792 shader_impl = wined3d_shader_get_parent(wined3d_shader);
793 *shader = &shader_impl->ID3D10GeometryShader_iface;
794 ID3D10GeometryShader_AddRef(*shader);
797 static void STDMETHODCALLTYPE d3d10_device_IAGetPrimitiveTopology(ID3D10Device *iface,
798 D3D10_PRIMITIVE_TOPOLOGY *topology)
800 struct d3d10_device *This = impl_from_ID3D10Device(iface);
802 TRACE("iface %p, topology %p\n", iface, topology);
804 wined3d_device_get_primitive_type(This->wined3d_device, (enum wined3d_primitive_type *)topology);
807 static void STDMETHODCALLTYPE d3d10_device_VSGetShaderResources(ID3D10Device *iface,
808 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
810 FIXME("iface %p, start_slot %u, view_count %u, views %p stub!\n",
811 iface, start_slot, view_count, views);
814 static void STDMETHODCALLTYPE d3d10_device_VSGetSamplers(ID3D10Device *iface,
815 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
817 struct d3d10_device *device = impl_from_ID3D10Device(iface);
818 unsigned int i;
820 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
821 iface, start_slot, sampler_count, samplers);
823 for (i = 0; i < sampler_count; ++i)
825 struct d3d10_sampler_state *sampler_impl;
826 struct wined3d_sampler *wined3d_sampler;
828 if (!(wined3d_sampler = wined3d_device_get_vs_sampler(device->wined3d_device, start_slot + i)))
830 samplers[i] = NULL;
831 continue;
834 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
835 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
836 ID3D10SamplerState_AddRef(samplers[i]);
840 static void STDMETHODCALLTYPE d3d10_device_GetPredication(ID3D10Device *iface,
841 ID3D10Predicate **predicate, BOOL *value)
843 FIXME("iface %p, predicate %p, value %p stub!\n", iface, predicate, value);
846 static void STDMETHODCALLTYPE d3d10_device_GSGetShaderResources(ID3D10Device *iface,
847 UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
849 FIXME("iface %p, start_slot %u, view_count %u, views %p stub!\n",
850 iface, start_slot, view_count, views);
853 static void STDMETHODCALLTYPE d3d10_device_GSGetSamplers(ID3D10Device *iface,
854 UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
856 struct d3d10_device *device = impl_from_ID3D10Device(iface);
857 unsigned int i;
859 TRACE("iface %p, start_slot %u, sampler_count %u, samplers %p.\n",
860 iface, start_slot, sampler_count, samplers);
862 for (i = 0; i < sampler_count; ++i)
864 struct d3d10_sampler_state *sampler_impl;
865 struct wined3d_sampler *wined3d_sampler;
867 if (!(wined3d_sampler = wined3d_device_get_gs_sampler(device->wined3d_device, start_slot + i)))
869 samplers[i] = NULL;
870 continue;
873 sampler_impl = wined3d_sampler_get_parent(wined3d_sampler);
874 samplers[i] = &sampler_impl->ID3D10SamplerState_iface;
875 ID3D10SamplerState_AddRef(samplers[i]);
879 static void STDMETHODCALLTYPE d3d10_device_OMGetRenderTargets(ID3D10Device *iface,
880 UINT view_count, ID3D10RenderTargetView **render_target_views, ID3D10DepthStencilView **depth_stencil_view)
882 FIXME("iface %p, view_count %u, render_target_views %p, depth_stencil_view %p stub!\n",
883 iface, view_count, render_target_views, depth_stencil_view);
886 static void STDMETHODCALLTYPE d3d10_device_OMGetBlendState(ID3D10Device *iface,
887 ID3D10BlendState **blend_state, FLOAT blend_factor[4], UINT *sample_mask)
889 struct d3d10_device *device = impl_from_ID3D10Device(iface);
891 TRACE("iface %p, blend_state %p, blend_factor %p, sample_mask %p.\n",
892 iface, blend_state, blend_factor, sample_mask);
894 if ((*blend_state = device->blend_state ? &device->blend_state->ID3D10BlendState_iface : NULL))
895 ID3D10BlendState_AddRef(*blend_state);
896 memcpy(blend_factor, device->blend_factor, 4 * sizeof(*blend_factor));
897 *sample_mask = device->sample_mask;
900 static void STDMETHODCALLTYPE d3d10_device_OMGetDepthStencilState(ID3D10Device *iface,
901 ID3D10DepthStencilState **depth_stencil_state, UINT *stencil_ref)
903 struct d3d10_device *device = impl_from_ID3D10Device(iface);
905 TRACE("iface %p, depth_stencil_state %p, stencil_ref %p.\n",
906 iface, depth_stencil_state, stencil_ref);
908 if ((*depth_stencil_state = device->depth_stencil_state
909 ? &device->depth_stencil_state->ID3D10DepthStencilState_iface : NULL))
910 ID3D10DepthStencilState_AddRef(*depth_stencil_state);
911 *stencil_ref = device->stencil_ref;
914 static void STDMETHODCALLTYPE d3d10_device_SOGetTargets(ID3D10Device *iface,
915 UINT buffer_count, ID3D10Buffer **buffers, UINT *offsets)
917 struct d3d10_device *device = impl_from_ID3D10Device(iface);
918 unsigned int i;
920 TRACE("iface %p, buffer_count %u, buffers %p, offsets %p.\n",
921 iface, buffer_count, buffers, offsets);
923 for (i = 0; i < buffer_count; ++i)
925 struct wined3d_buffer *wined3d_buffer;
926 struct d3d10_buffer *buffer_impl;
928 if (!(wined3d_buffer = wined3d_device_get_stream_output(device->wined3d_device, i, &offsets[i])))
930 buffers[i] = NULL;
931 continue;
934 buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
935 buffers[i] = &buffer_impl->ID3D10Buffer_iface;
936 ID3D10Buffer_AddRef(buffers[i]);
940 static void STDMETHODCALLTYPE d3d10_device_RSGetState(ID3D10Device *iface, ID3D10RasterizerState **rasterizer_state)
942 struct d3d10_device *device = impl_from_ID3D10Device(iface);
944 TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
946 if ((*rasterizer_state = device->rasterizer_state ? &device->rasterizer_state->ID3D10RasterizerState_iface : NULL))
947 ID3D10RasterizerState_AddRef(*rasterizer_state);
950 static void STDMETHODCALLTYPE d3d10_device_RSGetViewports(ID3D10Device *iface,
951 UINT *viewport_count, D3D10_VIEWPORT *viewports)
953 struct d3d10_device *device = impl_from_ID3D10Device(iface);
954 struct wined3d_viewport wined3d_vp;
956 TRACE("iface %p, viewport_count %p, viewports %p.\n", iface, viewport_count, viewports);
958 if (!viewports)
960 *viewport_count = 1;
961 return;
964 if (!*viewport_count)
965 return;
967 wined3d_device_get_viewport(device->wined3d_device, &wined3d_vp);
969 viewports[0].TopLeftX = wined3d_vp.x;
970 viewports[0].TopLeftY = wined3d_vp.y;
971 viewports[0].Width = wined3d_vp.width;
972 viewports[0].Height = wined3d_vp.height;
973 viewports[0].MinDepth = wined3d_vp.min_z;
974 viewports[0].MaxDepth = wined3d_vp.max_z;
976 if (*viewport_count > 1)
977 memset(&viewports[1], 0, (*viewport_count - 1) * sizeof(*viewports));
980 static void STDMETHODCALLTYPE d3d10_device_RSGetScissorRects(ID3D10Device *iface, UINT *rect_count, D3D10_RECT *rects)
982 struct d3d10_device *device = impl_from_ID3D10Device(iface);
984 TRACE("iface %p, rect_count %p, rects %p.\n", iface, rect_count, rects);
986 if (!rects)
988 *rect_count = 1;
989 return;
992 if (!*rect_count)
993 return;
995 wined3d_device_get_scissor_rect(device->wined3d_device, rects);
996 if (*rect_count > 1)
997 memset(&rects[1], 0, (*rect_count - 1) * sizeof(*rects));
1000 static HRESULT STDMETHODCALLTYPE d3d10_device_GetDeviceRemovedReason(ID3D10Device *iface)
1002 FIXME("iface %p stub!\n", iface);
1004 return E_NOTIMPL;
1007 static HRESULT STDMETHODCALLTYPE d3d10_device_SetExceptionMode(ID3D10Device *iface, UINT flags)
1009 FIXME("iface %p, flags %#x stub!\n", iface, flags);
1011 return E_NOTIMPL;
1014 static UINT STDMETHODCALLTYPE d3d10_device_GetExceptionMode(ID3D10Device *iface)
1016 FIXME("iface %p stub!\n", iface);
1018 return 0;
1021 static HRESULT STDMETHODCALLTYPE d3d10_device_GetPrivateData(ID3D10Device *iface,
1022 REFGUID guid, UINT *data_size, void *data)
1024 FIXME("iface %p, guid %s, data_size %p, data %p stub!\n",
1025 iface, debugstr_guid(guid), data_size, data);
1027 return E_NOTIMPL;
1030 static HRESULT STDMETHODCALLTYPE d3d10_device_SetPrivateData(ID3D10Device *iface,
1031 REFGUID guid, UINT data_size, const void *data)
1033 FIXME("iface %p, guid %s, data_size %u, data %p stub!\n",
1034 iface, debugstr_guid(guid), data_size, data);
1036 return E_NOTIMPL;
1039 static HRESULT STDMETHODCALLTYPE d3d10_device_SetPrivateDataInterface(ID3D10Device *iface,
1040 REFGUID guid, const IUnknown *data)
1042 FIXME("iface %p, guid %s, data %p stub!\n", iface, debugstr_guid(guid), data);
1044 return E_NOTIMPL;
1047 static void STDMETHODCALLTYPE d3d10_device_ClearState(ID3D10Device *iface)
1049 FIXME("iface %p stub!\n", iface);
1052 static void STDMETHODCALLTYPE d3d10_device_Flush(ID3D10Device *iface)
1054 FIXME("iface %p stub!\n", iface);
1057 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBuffer(ID3D10Device *iface,
1058 const D3D10_BUFFER_DESC *desc, const D3D10_SUBRESOURCE_DATA *data, ID3D10Buffer **buffer)
1060 struct d3d10_device *This = impl_from_ID3D10Device(iface);
1061 struct d3d10_buffer *object;
1062 HRESULT hr;
1064 FIXME("iface %p, desc %p, data %p, buffer %p partial stub!\n", iface, desc, data, buffer);
1066 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1067 if (!object)
1069 ERR("Failed to allocate D3D10 buffer object memory\n");
1070 return E_OUTOFMEMORY;
1073 hr = d3d10_buffer_init(object, This, desc, data);
1074 if (FAILED(hr))
1076 WARN("Failed to initialize buffer, hr %#x.\n", hr);
1077 HeapFree(GetProcessHeap(), 0, object);
1078 return hr;
1081 *buffer = &object->ID3D10Buffer_iface;
1083 TRACE("Created ID3D10Buffer %p\n", object);
1085 return S_OK;
1088 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture1D(ID3D10Device *iface,
1089 const D3D10_TEXTURE1D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data, ID3D10Texture1D **texture)
1091 FIXME("iface %p, desc %p, data %p, texture %p stub!\n", iface, desc, data, texture);
1093 return E_NOTIMPL;
1096 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture2D(ID3D10Device *iface,
1097 const D3D10_TEXTURE2D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data,
1098 ID3D10Texture2D **texture)
1100 struct d3d10_device *This = impl_from_ID3D10Device(iface);
1101 struct d3d10_texture2d *object;
1102 HRESULT hr;
1104 FIXME("iface %p, desc %p, data %p, texture %p partial stub!\n", iface, desc, data, texture);
1106 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1107 if (!object)
1109 ERR("Failed to allocate D3D10 texture2d object memory\n");
1110 return E_OUTOFMEMORY;
1113 hr = d3d10_texture2d_init(object, This, desc);
1114 if (FAILED(hr))
1116 WARN("Failed to initialize texture, hr %#x.\n", hr);
1117 HeapFree(GetProcessHeap(), 0, object);
1118 return hr;
1121 *texture = &object->ID3D10Texture2D_iface;
1123 TRACE("Created ID3D10Texture2D %p\n", object);
1125 return S_OK;
1128 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture3D(ID3D10Device *iface,
1129 const D3D10_TEXTURE3D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data,
1130 ID3D10Texture3D **texture)
1132 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1133 struct d3d10_texture3d *object;
1134 HRESULT hr;
1136 TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
1138 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1139 if (!object)
1141 ERR("Failed to allocate D3D10 texture3d object memory.\n");
1142 return E_OUTOFMEMORY;
1145 hr = d3d10_texture3d_init(object, device, desc);
1146 if (FAILED(hr))
1148 WARN("Failed to initialize texture, hr %#x.\n", hr);
1149 HeapFree(GetProcessHeap(), 0, object);
1150 return hr;
1153 TRACE("Created 3D texture %p.\n", object);
1154 *texture = &object->ID3D10Texture3D_iface;
1156 return S_OK;
1159 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateShaderResourceView(ID3D10Device *iface,
1160 ID3D10Resource *resource, const D3D10_SHADER_RESOURCE_VIEW_DESC *desc, ID3D10ShaderResourceView **view)
1162 struct d3d10_shader_resource_view *object;
1163 HRESULT hr;
1165 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
1167 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1168 if (!object)
1170 ERR("Failed to allocate D3D10 shader resource view object memory.\n");
1171 return E_OUTOFMEMORY;
1174 if (FAILED(hr = d3d10_shader_resource_view_init(object, resource, desc)))
1176 WARN("Failed to initialize shader resource view, hr %#x.\n", hr);
1177 HeapFree(GetProcessHeap(), 0, object);
1178 return hr;
1181 TRACE("Created shader resource view %p.\n", object);
1182 *view = &object->ID3D10ShaderResourceView_iface;
1184 return S_OK;
1187 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateRenderTargetView(ID3D10Device *iface,
1188 ID3D10Resource *resource, const D3D10_RENDER_TARGET_VIEW_DESC *desc, ID3D10RenderTargetView **view)
1190 struct d3d10_rendertarget_view *object;
1191 HRESULT hr;
1193 TRACE("iface %p, resource %p, desc %p, view %p stub!\n", iface, resource, desc, view);
1195 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1196 if (!object)
1198 ERR("Failed to allocate D3D10 rendertarget view object memory\n");
1199 return E_OUTOFMEMORY;
1202 hr = d3d10_rendertarget_view_init(object, resource, desc);
1203 if (FAILED(hr))
1205 WARN("Failed to initialize rendertarget view, hr %#x.\n", hr);
1206 HeapFree(GetProcessHeap(), 0, object);
1207 return hr;
1210 TRACE("Created rendertarget view %p.\n", object);
1211 *view = &object->ID3D10RenderTargetView_iface;
1213 return S_OK;
1216 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateDepthStencilView(ID3D10Device *iface,
1217 ID3D10Resource *resource, const D3D10_DEPTH_STENCIL_VIEW_DESC *desc, ID3D10DepthStencilView **view)
1219 struct d3d10_depthstencil_view *object;
1220 HRESULT hr;
1222 TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
1224 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1225 if (!object)
1227 ERR("Failed to allocate D3D10 depthstencil view object memory.\n");
1228 return E_OUTOFMEMORY;
1231 if (FAILED(hr = d3d10_depthstencil_view_init(object, resource, desc)))
1233 WARN("Failed to initialize depthstencil view, hr %#x.\n", hr);
1234 HeapFree(GetProcessHeap(), 0, object);
1235 return hr;
1238 TRACE("Created depthstencil view %p.\n", object);
1239 *view = &object->ID3D10DepthStencilView_iface;
1241 return S_OK;
1244 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateInputLayout(ID3D10Device *iface,
1245 const D3D10_INPUT_ELEMENT_DESC *element_descs, UINT element_count,
1246 const void *shader_byte_code, SIZE_T shader_byte_code_length,
1247 ID3D10InputLayout **input_layout)
1249 struct d3d10_device *This = impl_from_ID3D10Device(iface);
1250 struct d3d10_input_layout *object;
1251 HRESULT hr;
1253 TRACE("iface %p, element_descs %p, element_count %u, shader_byte_code %p,"
1254 "\tshader_byte_code_length %lu, input_layout %p\n",
1255 iface, element_descs, element_count, shader_byte_code,
1256 shader_byte_code_length, input_layout);
1258 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1259 if (!object)
1261 ERR("Failed to allocate D3D10 input layout object memory\n");
1262 return E_OUTOFMEMORY;
1265 hr = d3d10_input_layout_init(object, This, element_descs, element_count,
1266 shader_byte_code, shader_byte_code_length);
1267 if (FAILED(hr))
1269 WARN("Failed to initialize input layout, hr %#x.\n", hr);
1270 HeapFree(GetProcessHeap(), 0, object);
1271 return hr;
1274 TRACE("Created input layout %p.\n", object);
1275 *input_layout = &object->ID3D10InputLayout_iface;
1277 return S_OK;
1280 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateVertexShader(ID3D10Device *iface,
1281 const void *byte_code, SIZE_T byte_code_length, ID3D10VertexShader **shader)
1283 struct d3d10_device *This = impl_from_ID3D10Device(iface);
1284 struct d3d10_vertex_shader *object;
1285 HRESULT hr;
1287 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p\n",
1288 iface, byte_code, byte_code_length, shader);
1290 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1291 if (!object)
1293 ERR("Failed to allocate D3D10 vertex shader object memory\n");
1294 return E_OUTOFMEMORY;
1297 hr = d3d10_vertex_shader_init(object, This, byte_code, byte_code_length);
1298 if (FAILED(hr))
1300 WARN("Failed to initialize vertex shader, hr %#x.\n", hr);
1301 HeapFree(GetProcessHeap(), 0, object);
1302 return hr;
1305 TRACE("Created vertex shader %p.\n", object);
1306 *shader = &object->ID3D10VertexShader_iface;
1308 return S_OK;
1311 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateGeometryShader(ID3D10Device *iface,
1312 const void *byte_code, SIZE_T byte_code_length, ID3D10GeometryShader **shader)
1314 struct d3d10_device *This = impl_from_ID3D10Device(iface);
1315 struct d3d10_geometry_shader *object;
1316 HRESULT hr;
1318 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p.\n",
1319 iface, byte_code, byte_code_length, shader);
1321 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1322 if (!object)
1324 ERR("Failed to allocate D3D10 geometry shader object memory\n");
1325 return E_OUTOFMEMORY;
1328 hr = d3d10_geometry_shader_init(object, This, byte_code, byte_code_length);
1329 if (FAILED(hr))
1331 WARN("Failed to initialize geometry shader, hr %#x.\n", hr);
1332 HeapFree(GetProcessHeap(), 0, object);
1333 return hr;
1336 TRACE("Created geometry shader %p.\n", object);
1337 *shader = &object->ID3D10GeometryShader_iface;
1339 return S_OK;
1342 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateGeometryShaderWithStreamOutput(ID3D10Device *iface,
1343 const void *byte_code, SIZE_T byte_code_length, const D3D10_SO_DECLARATION_ENTRY *output_stream_decls,
1344 UINT output_stream_decl_count, UINT output_stream_stride, ID3D10GeometryShader **shader)
1346 FIXME("iface %p, byte_code %p, byte_code_length %lu, output_stream_decls %p,\n"
1347 "\toutput_stream_decl_count %u, output_stream_stride %u, shader %p stub!\n",
1348 iface, byte_code, byte_code_length, output_stream_decls,
1349 output_stream_decl_count, output_stream_stride, shader);
1351 return E_NOTIMPL;
1354 static HRESULT STDMETHODCALLTYPE d3d10_device_CreatePixelShader(ID3D10Device *iface,
1355 const void *byte_code, SIZE_T byte_code_length, ID3D10PixelShader **shader)
1357 struct d3d10_device *This = impl_from_ID3D10Device(iface);
1358 struct d3d10_pixel_shader *object;
1359 HRESULT hr;
1361 TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p\n",
1362 iface, byte_code, byte_code_length, shader);
1364 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1365 if (!object)
1367 ERR("Failed to allocate D3D10 pixel shader object memory\n");
1368 return E_OUTOFMEMORY;
1371 hr = d3d10_pixel_shader_init(object, This, byte_code, byte_code_length);
1372 if (FAILED(hr))
1374 WARN("Failed to initialize pixel shader, hr %#x.\n", hr);
1375 HeapFree(GetProcessHeap(), 0, object);
1376 return hr;
1379 TRACE("Created pixel shader %p.\n", object);
1380 *shader = &object->ID3D10PixelShader_iface;
1382 return S_OK;
1385 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBlendState(ID3D10Device *iface,
1386 const D3D10_BLEND_DESC *desc, ID3D10BlendState **blend_state)
1388 struct d3d10_blend_state *object;
1389 HRESULT hr;
1391 TRACE("iface %p, desc %p, blend_state %p.\n", iface, desc, blend_state);
1393 if (!desc)
1394 return E_INVALIDARG;
1396 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1397 if (!object)
1399 ERR("Failed to allocate D3D10 blend state object memory.\n");
1400 return E_OUTOFMEMORY;
1403 if (FAILED(hr = d3d10_blend_state_init(object, desc)))
1405 WARN("Failed to initialize blend state, hr %#x.\n", hr);
1406 HeapFree(GetProcessHeap(), 0, object);
1407 return hr;
1410 TRACE("Created blend state %p.\n", object);
1411 *blend_state = &object->ID3D10BlendState_iface;
1413 return S_OK;
1416 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateDepthStencilState(ID3D10Device *iface,
1417 const D3D10_DEPTH_STENCIL_DESC *desc, ID3D10DepthStencilState **depth_stencil_state)
1419 struct d3d10_depthstencil_state *object;
1420 HRESULT hr;
1422 TRACE("iface %p, desc %p, depth_stencil_state %p.\n", iface, desc, depth_stencil_state);
1424 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1425 if (!object)
1427 ERR("Failed to allocate D3D10 depthstencil state object memory.\n");
1428 return E_OUTOFMEMORY;
1431 hr = d3d10_depthstencil_state_init(object);
1432 if (FAILED(hr))
1434 WARN("Failed to initialize depthstencil state, hr %#x.\n", hr);
1435 HeapFree(GetProcessHeap(), 0, object);
1436 return hr;
1439 TRACE("Created depthstencil state %p.\n", object);
1440 *depth_stencil_state = &object->ID3D10DepthStencilState_iface;
1442 return S_OK;
1445 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateRasterizerState(ID3D10Device *iface,
1446 const D3D10_RASTERIZER_DESC *desc, ID3D10RasterizerState **rasterizer_state)
1448 struct d3d10_rasterizer_state *object;
1449 HRESULT hr;
1451 TRACE("iface %p, desc %p, rasterizer_state %p.\n", iface, desc, rasterizer_state);
1453 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1454 if (!object)
1456 ERR("Failed to allocate D3D10 rasterizer state object memory.\n");
1457 return E_OUTOFMEMORY;
1460 hr = d3d10_rasterizer_state_init(object);
1461 if (FAILED(hr))
1463 WARN("Failed to initialize rasterizer state, hr %#x.\n", hr);
1464 HeapFree(GetProcessHeap(), 0, object);
1465 return hr;
1468 TRACE("Created rasterizer state %p.\n", object);
1469 *rasterizer_state = &object->ID3D10RasterizerState_iface;
1471 return S_OK;
1474 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateSamplerState(ID3D10Device *iface,
1475 const D3D10_SAMPLER_DESC *desc, ID3D10SamplerState **sampler_state)
1477 struct d3d10_device *device = impl_from_ID3D10Device(iface);
1478 struct d3d10_sampler_state *object;
1479 struct wine_rb_entry *entry;
1480 HRESULT hr;
1482 TRACE("iface %p, desc %p, sampler_state %p.\n", iface, desc, sampler_state);
1484 if (!desc)
1485 return E_INVALIDARG;
1487 if ((entry = wine_rb_get(&device->sampler_states, desc)))
1489 object = WINE_RB_ENTRY_VALUE(entry, struct d3d10_sampler_state, entry);
1491 TRACE("Returning existing sampler state %p.\n", object);
1492 *sampler_state = &object->ID3D10SamplerState_iface;
1493 ID3D10SamplerState_AddRef(*sampler_state);
1495 return S_OK;
1498 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1499 if (!object)
1501 ERR("Failed to allocate D3D10 sampler state object memory.\n");
1502 return E_OUTOFMEMORY;
1505 if (FAILED(hr = d3d10_sampler_state_init(object, device, desc)))
1507 WARN("Failed to initialize sampler state, hr %#x.\n", hr);
1508 HeapFree(GetProcessHeap(), 0, object);
1509 return hr;
1512 TRACE("Created sampler state %p.\n", object);
1513 *sampler_state = &object->ID3D10SamplerState_iface;
1515 return S_OK;
1518 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateQuery(ID3D10Device *iface,
1519 const D3D10_QUERY_DESC *desc, ID3D10Query **query)
1521 struct d3d10_query *object;
1522 HRESULT hr;
1524 TRACE("iface %p, desc %p, query %p.\n", iface, desc, query);
1526 object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1527 if (!object)
1529 ERR("Failed to allocate D3D10 query object memory.\n");
1530 return E_OUTOFMEMORY;
1533 hr = d3d10_query_init(object);
1534 if (FAILED(hr))
1536 WARN("Failed to initialize query, hr %#x.\n", hr);
1537 HeapFree(GetProcessHeap(), 0, object);
1538 return hr;
1541 TRACE("Created query %p.\n", object);
1542 *query = &object->ID3D10Query_iface;
1544 return S_OK;
1547 static HRESULT STDMETHODCALLTYPE d3d10_device_CreatePredicate(ID3D10Device *iface,
1548 const D3D10_QUERY_DESC *desc, ID3D10Predicate **predicate)
1550 FIXME("iface %p, desc %p, predicate %p stub!\n", iface, desc, predicate);
1552 return E_NOTIMPL;
1555 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateCounter(ID3D10Device *iface,
1556 const D3D10_COUNTER_DESC *desc, ID3D10Counter **counter)
1558 FIXME("iface %p, desc %p, counter %p stub!\n", iface, desc, counter);
1560 return E_NOTIMPL;
1563 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckFormatSupport(ID3D10Device *iface,
1564 DXGI_FORMAT format, UINT *format_support)
1566 FIXME("iface %p, format %s, format_support %p stub!\n",
1567 iface, debug_dxgi_format(format), format_support);
1569 return E_NOTIMPL;
1572 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckMultisampleQualityLevels(ID3D10Device *iface,
1573 DXGI_FORMAT format, UINT sample_count, UINT *quality_level_count)
1575 FIXME("iface %p, format %s, sample_count %u, quality_level_count %p stub!\n",
1576 iface, debug_dxgi_format(format), sample_count, quality_level_count);
1578 return E_NOTIMPL;
1581 static void STDMETHODCALLTYPE d3d10_device_CheckCounterInfo(ID3D10Device *iface, D3D10_COUNTER_INFO *counter_info)
1583 FIXME("iface %p, counter_info %p stub!\n", iface, counter_info);
1586 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckCounter(ID3D10Device *iface,
1587 const D3D10_COUNTER_DESC *desc, D3D10_COUNTER_TYPE *type, UINT *active_counters, LPSTR name,
1588 UINT *name_length, LPSTR units, UINT *units_length, LPSTR description, UINT *description_length)
1590 FIXME("iface %p, desc %p, type %p, active_counters %p, name %p, name_length %p,\n"
1591 "\tunits %p, units_length %p, description %p, description_length %p stub!\n",
1592 iface, desc, type, active_counters, name, name_length,
1593 units, units_length, description, description_length);
1595 return E_NOTIMPL;
1598 static UINT STDMETHODCALLTYPE d3d10_device_GetCreationFlags(ID3D10Device *iface)
1600 FIXME("iface %p stub!\n", iface);
1602 return 0;
1605 static HRESULT STDMETHODCALLTYPE d3d10_device_OpenSharedResource(ID3D10Device *iface,
1606 HANDLE resource_handle, REFIID guid, void **resource)
1608 FIXME("iface %p, resource_handle %p, guid %s, resource %p stub!\n",
1609 iface, resource_handle, debugstr_guid(guid), resource);
1611 return E_NOTIMPL;
1614 static void STDMETHODCALLTYPE d3d10_device_SetTextFilterSize(ID3D10Device *iface, UINT width, UINT height)
1616 FIXME("iface %p, width %u, height %u stub!\n", iface, width, height);
1619 static void STDMETHODCALLTYPE d3d10_device_GetTextFilterSize(ID3D10Device *iface, UINT *width, UINT *height)
1621 FIXME("iface %p, width %p, height %p stub!\n", iface, width, height);
1624 static const struct ID3D10DeviceVtbl d3d10_device_vtbl =
1626 /* IUnknown methods */
1627 d3d10_device_QueryInterface,
1628 d3d10_device_AddRef,
1629 d3d10_device_Release,
1630 /* ID3D10Device methods */
1631 d3d10_device_VSSetConstantBuffers,
1632 d3d10_device_PSSetShaderResources,
1633 d3d10_device_PSSetShader,
1634 d3d10_device_PSSetSamplers,
1635 d3d10_device_VSSetShader,
1636 d3d10_device_DrawIndexed,
1637 d3d10_device_Draw,
1638 d3d10_device_PSSetConstantBuffers,
1639 d3d10_device_IASetInputLayout,
1640 d3d10_device_IASetVertexBuffers,
1641 d3d10_device_IASetIndexBuffer,
1642 d3d10_device_DrawIndexedInstanced,
1643 d3d10_device_DrawInstanced,
1644 d3d10_device_GSSetConstantBuffers,
1645 d3d10_device_GSSetShader,
1646 d3d10_device_IASetPrimitiveTopology,
1647 d3d10_device_VSSetShaderResources,
1648 d3d10_device_VSSetSamplers,
1649 d3d10_device_SetPredication,
1650 d3d10_device_GSSetShaderResources,
1651 d3d10_device_GSSetSamplers,
1652 d3d10_device_OMSetRenderTargets,
1653 d3d10_device_OMSetBlendState,
1654 d3d10_device_OMSetDepthStencilState,
1655 d3d10_device_SOSetTargets,
1656 d3d10_device_DrawAuto,
1657 d3d10_device_RSSetState,
1658 d3d10_device_RSSetViewports,
1659 d3d10_device_RSSetScissorRects,
1660 d3d10_device_CopySubresourceRegion,
1661 d3d10_device_CopyResource,
1662 d3d10_device_UpdateSubresource,
1663 d3d10_device_ClearRenderTargetView,
1664 d3d10_device_ClearDepthStencilView,
1665 d3d10_device_GenerateMips,
1666 d3d10_device_ResolveSubresource,
1667 d3d10_device_VSGetConstantBuffers,
1668 d3d10_device_PSGetShaderResources,
1669 d3d10_device_PSGetShader,
1670 d3d10_device_PSGetSamplers,
1671 d3d10_device_VSGetShader,
1672 d3d10_device_PSGetConstantBuffers,
1673 d3d10_device_IAGetInputLayout,
1674 d3d10_device_IAGetVertexBuffers,
1675 d3d10_device_IAGetIndexBuffer,
1676 d3d10_device_GSGetConstantBuffers,
1677 d3d10_device_GSGetShader,
1678 d3d10_device_IAGetPrimitiveTopology,
1679 d3d10_device_VSGetShaderResources,
1680 d3d10_device_VSGetSamplers,
1681 d3d10_device_GetPredication,
1682 d3d10_device_GSGetShaderResources,
1683 d3d10_device_GSGetSamplers,
1684 d3d10_device_OMGetRenderTargets,
1685 d3d10_device_OMGetBlendState,
1686 d3d10_device_OMGetDepthStencilState,
1687 d3d10_device_SOGetTargets,
1688 d3d10_device_RSGetState,
1689 d3d10_device_RSGetViewports,
1690 d3d10_device_RSGetScissorRects,
1691 d3d10_device_GetDeviceRemovedReason,
1692 d3d10_device_SetExceptionMode,
1693 d3d10_device_GetExceptionMode,
1694 d3d10_device_GetPrivateData,
1695 d3d10_device_SetPrivateData,
1696 d3d10_device_SetPrivateDataInterface,
1697 d3d10_device_ClearState,
1698 d3d10_device_Flush,
1699 d3d10_device_CreateBuffer,
1700 d3d10_device_CreateTexture1D,
1701 d3d10_device_CreateTexture2D,
1702 d3d10_device_CreateTexture3D,
1703 d3d10_device_CreateShaderResourceView,
1704 d3d10_device_CreateRenderTargetView,
1705 d3d10_device_CreateDepthStencilView,
1706 d3d10_device_CreateInputLayout,
1707 d3d10_device_CreateVertexShader,
1708 d3d10_device_CreateGeometryShader,
1709 d3d10_device_CreateGeometryShaderWithStreamOutput,
1710 d3d10_device_CreatePixelShader,
1711 d3d10_device_CreateBlendState,
1712 d3d10_device_CreateDepthStencilState,
1713 d3d10_device_CreateRasterizerState,
1714 d3d10_device_CreateSamplerState,
1715 d3d10_device_CreateQuery,
1716 d3d10_device_CreatePredicate,
1717 d3d10_device_CreateCounter,
1718 d3d10_device_CheckFormatSupport,
1719 d3d10_device_CheckMultisampleQualityLevels,
1720 d3d10_device_CheckCounterInfo,
1721 d3d10_device_CheckCounter,
1722 d3d10_device_GetCreationFlags,
1723 d3d10_device_OpenSharedResource,
1724 d3d10_device_SetTextFilterSize,
1725 d3d10_device_GetTextFilterSize,
1728 static const struct IUnknownVtbl d3d10_device_inner_unknown_vtbl =
1730 /* IUnknown methods */
1731 d3d10_device_inner_QueryInterface,
1732 d3d10_device_inner_AddRef,
1733 d3d10_device_inner_Release,
1736 static void STDMETHODCALLTYPE d3d10_subresource_destroyed(void *parent) {}
1738 static const struct wined3d_parent_ops d3d10_subresource_parent_ops =
1740 d3d10_subresource_destroyed,
1743 /* IWineDXGIDeviceParent IUnknown methods */
1745 static inline struct d3d10_device *device_from_dxgi_device_parent(IWineDXGIDeviceParent *iface)
1747 return CONTAINING_RECORD(iface, struct d3d10_device, IWineDXGIDeviceParent_iface);
1750 static HRESULT STDMETHODCALLTYPE dxgi_device_parent_QueryInterface(IWineDXGIDeviceParent *iface,
1751 REFIID riid, void **ppv)
1753 struct d3d10_device *device = device_from_dxgi_device_parent(iface);
1754 return IUnknown_QueryInterface(device->outer_unk, riid, ppv);
1757 static ULONG STDMETHODCALLTYPE dxgi_device_parent_AddRef(IWineDXGIDeviceParent *iface)
1759 struct d3d10_device *device = device_from_dxgi_device_parent(iface);
1760 return IUnknown_AddRef(device->outer_unk);
1763 static ULONG STDMETHODCALLTYPE dxgi_device_parent_Release(IWineDXGIDeviceParent *iface)
1765 struct d3d10_device *device = device_from_dxgi_device_parent(iface);
1766 return IUnknown_Release(device->outer_unk);
1769 static struct wined3d_device_parent * STDMETHODCALLTYPE dxgi_device_parent_get_wined3d_device_parent(
1770 IWineDXGIDeviceParent *iface)
1772 struct d3d10_device *device = device_from_dxgi_device_parent(iface);
1773 return &device->device_parent;
1776 static const struct IWineDXGIDeviceParentVtbl d3d10_dxgi_device_parent_vtbl =
1778 /* IUnknown methods */
1779 dxgi_device_parent_QueryInterface,
1780 dxgi_device_parent_AddRef,
1781 dxgi_device_parent_Release,
1782 /* IWineDXGIDeviceParent methods */
1783 dxgi_device_parent_get_wined3d_device_parent,
1786 static inline struct d3d10_device *device_from_wined3d_device_parent(struct wined3d_device_parent *device_parent)
1788 return CONTAINING_RECORD(device_parent, struct d3d10_device, device_parent);
1791 static void CDECL device_parent_wined3d_device_created(struct wined3d_device_parent *device_parent,
1792 struct wined3d_device *wined3d_device)
1794 struct d3d10_device *device = device_from_wined3d_device_parent(device_parent);
1796 TRACE("device_parent %p, wined3d_device %p.\n", device_parent, wined3d_device);
1798 wined3d_device_incref(wined3d_device);
1799 device->wined3d_device = wined3d_device;
1802 static void CDECL device_parent_mode_changed(struct wined3d_device_parent *device_parent)
1804 TRACE("device_parent %p.\n", device_parent);
1807 static HRESULT CDECL device_parent_create_texture_surface(struct wined3d_device_parent *device_parent,
1808 void *container_parent, UINT width, UINT height, enum wined3d_format_id format, DWORD usage,
1809 enum wined3d_pool pool, UINT sub_resource_idx, struct wined3d_surface **surface)
1811 struct d3d10_device *device = device_from_wined3d_device_parent(device_parent);
1813 TRACE("device_parent %p, container_parent %p, width %u, height %u, format %#x, usage %#x,\n"
1814 "\tpool %#x, sub_resource_idx %u, surface %p.\n",
1815 device_parent, container_parent, width, height, format, usage, pool, sub_resource_idx, surface);
1817 return wined3d_surface_create(device->wined3d_device, width, height, format, usage, pool,
1818 WINED3D_MULTISAMPLE_NONE, 0, WINED3D_SURFACE_TYPE_OPENGL, 0, container_parent,
1819 &d3d10_null_wined3d_parent_ops, surface);
1822 static HRESULT CDECL device_parent_create_swapchain_surface(struct wined3d_device_parent *device_parent,
1823 void *container_parent, UINT width, UINT height, enum wined3d_format_id format_id, DWORD usage,
1824 enum wined3d_multisample_type multisample_type, DWORD multisample_quality, struct wined3d_surface **surface)
1826 struct d3d10_device *device = device_from_wined3d_device_parent(device_parent);
1827 struct wined3d_resource *sub_resource;
1828 struct d3d10_texture2d *texture;
1829 D3D10_TEXTURE2D_DESC desc;
1830 HRESULT hr;
1832 FIXME("device_parent %p, container_parent %p, width %u, height %u, format_id %#x, usage %#x,\n"
1833 "\tmultisample_type %#x, multisample_quality %u, surface %p partial stub!\n",
1834 device_parent, container_parent, width, height, format_id, usage,
1835 multisample_type, multisample_quality, surface);
1837 FIXME("Implement DXGI<->wined3d usage conversion\n");
1839 desc.Width = width;
1840 desc.Height = height;
1841 desc.MipLevels = 1;
1842 desc.ArraySize = 1;
1843 desc.Format = dxgi_format_from_wined3dformat(format_id);
1844 desc.SampleDesc.Count = multisample_type ? multisample_type : 1;
1845 desc.SampleDesc.Quality = multisample_quality;
1846 desc.Usage = D3D10_USAGE_DEFAULT;
1847 desc.BindFlags = D3D10_BIND_RENDER_TARGET;
1848 desc.CPUAccessFlags = 0;
1849 desc.MiscFlags = 0;
1851 hr = d3d10_device_CreateTexture2D(&device->ID3D10Device_iface, &desc, NULL,
1852 (ID3D10Texture2D **)&texture);
1853 if (FAILED(hr))
1855 ERR("CreateTexture2D failed, returning %#x\n", hr);
1856 return hr;
1859 sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, 0);
1860 *surface = wined3d_surface_from_resource(sub_resource);
1861 wined3d_surface_incref(*surface);
1862 ID3D10Texture2D_Release(&texture->ID3D10Texture2D_iface);
1864 return S_OK;
1867 static HRESULT CDECL device_parent_create_volume(struct wined3d_device_parent *device_parent,
1868 void *container_parent, UINT width, UINT height, UINT depth, enum wined3d_format_id format,
1869 enum wined3d_pool pool, DWORD usage, struct wined3d_volume **volume)
1871 HRESULT hr;
1873 TRACE("device_parent %p, container_parent %p, width %u, height %u, depth %u, "
1874 "format %#x, pool %#x, usage %#x, volume %p.\n",
1875 device_parent, container_parent, width, height, depth,
1876 format, pool, usage, volume);
1878 hr = wined3d_volume_create(device_from_wined3d_device_parent(device_parent)->wined3d_device,
1879 width, height, depth, usage, format, pool, NULL, &d3d10_subresource_parent_ops, volume);
1880 if (FAILED(hr))
1882 WARN("Failed to create wined3d volume, hr %#x.\n", hr);
1883 return hr;
1886 return S_OK;
1889 static HRESULT CDECL device_parent_create_swapchain(struct wined3d_device_parent *device_parent,
1890 struct wined3d_swapchain_desc *desc, struct wined3d_swapchain **swapchain)
1892 struct d3d10_device *device = device_from_wined3d_device_parent(device_parent);
1893 IWineDXGIDevice *wine_device;
1894 HRESULT hr;
1896 TRACE("device_parent %p, desc %p, swapchain %p\n", device_parent, desc, swapchain);
1898 hr = d3d10_device_QueryInterface(&device->ID3D10Device_iface, &IID_IWineDXGIDevice,
1899 (void **)&wine_device);
1900 if (FAILED(hr))
1902 ERR("Device should implement IWineDXGIDevice\n");
1903 return E_FAIL;
1906 hr = IWineDXGIDevice_create_swapchain(wine_device, desc, swapchain);
1907 IWineDXGIDevice_Release(wine_device);
1908 if (FAILED(hr))
1910 ERR("Failed to create DXGI swapchain, returning %#x\n", hr);
1911 return hr;
1914 return S_OK;
1917 static const struct wined3d_device_parent_ops d3d10_wined3d_device_parent_ops =
1919 device_parent_wined3d_device_created,
1920 device_parent_mode_changed,
1921 device_parent_create_swapchain_surface,
1922 device_parent_create_texture_surface,
1923 device_parent_create_volume,
1924 device_parent_create_swapchain,
1927 static void *d3d10_rb_alloc(size_t size)
1929 return HeapAlloc(GetProcessHeap(), 0, size);
1932 static void *d3d10_rb_realloc(void *ptr, size_t size)
1934 return HeapReAlloc(GetProcessHeap(), 0, ptr, size);
1937 static void d3d10_rb_free(void *ptr)
1939 HeapFree(GetProcessHeap(), 0, ptr);
1942 static int d3d10_sampler_state_compare(const void *key, const struct wine_rb_entry *entry)
1944 const D3D10_SAMPLER_DESC *ka = key;
1945 const D3D10_SAMPLER_DESC *kb = &WINE_RB_ENTRY_VALUE(entry, const struct d3d10_sampler_state, entry)->desc;
1947 return memcmp(ka, kb, sizeof(*ka));
1950 static const struct wine_rb_functions d3d10_sampler_state_rb_ops =
1952 d3d10_rb_alloc,
1953 d3d10_rb_realloc,
1954 d3d10_rb_free,
1955 d3d10_sampler_state_compare,
1958 HRESULT d3d10_device_init(struct d3d10_device *device, void *outer_unknown)
1960 device->ID3D10Device_iface.lpVtbl = &d3d10_device_vtbl;
1961 device->IUnknown_inner.lpVtbl = &d3d10_device_inner_unknown_vtbl;
1962 device->IWineDXGIDeviceParent_iface.lpVtbl = &d3d10_dxgi_device_parent_vtbl;
1963 device->device_parent.ops = &d3d10_wined3d_device_parent_ops;
1964 device->refcount = 1;
1965 /* COM aggregation always takes place */
1966 device->outer_unk = outer_unknown;
1968 if (wine_rb_init(&device->sampler_states, &d3d10_sampler_state_rb_ops) == -1)
1970 WARN("Failed to initialize sampler state rbtree.\n");
1971 return E_FAIL;
1974 return S_OK;