d3d10core: Implement d3d10_device_VSSetConstantBuffers().
[wine] / dlls / d3d10core / device.c
1 /*
2  * Copyright 2008-2012 Henri Verbeet for CodeWeavers
3  *
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.
8  *
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.
13  *
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
17  *
18  */
19
20 #include "config.h"
21 #include "wine/port.h"
22
23 #include "d3d10core_private.h"
24
25 WINE_DEFAULT_DEBUG_CHANNEL(d3d10core);
26
27 static void STDMETHODCALLTYPE d3d10_null_wined3d_object_destroyed(void *parent) {}
28
29 const struct wined3d_parent_ops d3d10_null_wined3d_parent_ops =
30 {
31     d3d10_null_wined3d_object_destroyed,
32 };
33
34 /* Inner IUnknown methods */
35
36 static inline struct d3d10_device *impl_from_IUnknown(IUnknown *iface)
37 {
38     return CONTAINING_RECORD(iface, struct d3d10_device, IUnknown_inner);
39 }
40
41 static HRESULT STDMETHODCALLTYPE d3d10_device_inner_QueryInterface(IUnknown *iface, REFIID riid,
42         void **ppv)
43 {
44     struct d3d10_device *This = impl_from_IUnknown(iface);
45
46     TRACE("iface %p, riid %s, ppv %p\n", iface, debugstr_guid(riid), ppv);
47
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
53     {
54         WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid));
55         *ppv = NULL;
56         return E_NOINTERFACE;
57     }
58
59     IUnknown_AddRef((IUnknown*)*ppv);
60     return S_OK;
61 }
62
63 static ULONG STDMETHODCALLTYPE d3d10_device_inner_AddRef(IUnknown *iface)
64 {
65     struct d3d10_device *This = impl_from_IUnknown(iface);
66     ULONG refcount = InterlockedIncrement(&This->refcount);
67
68     TRACE("%p increasing refcount to %u\n", This, refcount);
69
70     return refcount;
71 }
72
73 static ULONG STDMETHODCALLTYPE d3d10_device_inner_Release(IUnknown *iface)
74 {
75     struct d3d10_device *This = impl_from_IUnknown(iface);
76     ULONG refcount = InterlockedDecrement(&This->refcount);
77
78     TRACE("%p decreasing refcount to %u\n", This, refcount);
79
80     if (!refcount)
81     {
82         if (This->wined3d_device)
83             wined3d_device_decref(This->wined3d_device);
84     }
85
86     return refcount;
87 }
88
89 /* IUnknown methods */
90
91 static inline struct d3d10_device *impl_from_ID3D10Device(ID3D10Device *iface)
92 {
93     return CONTAINING_RECORD(iface, struct d3d10_device, ID3D10Device_iface);
94 }
95
96 static HRESULT STDMETHODCALLTYPE d3d10_device_QueryInterface(ID3D10Device *iface, REFIID riid,
97         void **ppv)
98 {
99     struct d3d10_device *This = impl_from_ID3D10Device(iface);
100     return IUnknown_QueryInterface(This->outer_unk, riid, ppv);
101 }
102
103 static ULONG STDMETHODCALLTYPE d3d10_device_AddRef(ID3D10Device *iface)
104 {
105     struct d3d10_device *This = impl_from_ID3D10Device(iface);
106     return IUnknown_AddRef(This->outer_unk);
107 }
108
109 static ULONG STDMETHODCALLTYPE d3d10_device_Release(ID3D10Device *iface)
110 {
111     struct d3d10_device *This = impl_from_ID3D10Device(iface);
112     return IUnknown_Release(This->outer_unk);
113 }
114
115 /* ID3D10Device methods */
116
117 static void STDMETHODCALLTYPE d3d10_device_VSSetConstantBuffers(ID3D10Device *iface,
118         UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
119 {
120     struct d3d10_device *device = impl_from_ID3D10Device(iface);
121     unsigned int i;
122
123     TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p.\n",
124             iface, start_slot, buffer_count, buffers);
125
126     for (i = 0; i < buffer_count; ++i)
127     {
128         struct d3d10_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
129
130         wined3d_device_set_vs_cb(device->wined3d_device, start_slot + i,
131                 buffer ? buffer->wined3d_buffer : NULL);
132     }
133 }
134
135 static void STDMETHODCALLTYPE d3d10_device_PSSetShaderResources(ID3D10Device *iface,
136         UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
137 {
138     FIXME("iface %p, start_slot %u, view_count %u, views %p stub!\n",
139             iface, start_slot, view_count, views);
140 }
141
142 static void STDMETHODCALLTYPE d3d10_device_PSSetShader(ID3D10Device *iface,
143         ID3D10PixelShader *shader)
144 {
145     struct d3d10_device *This = impl_from_ID3D10Device(iface);
146     struct d3d10_pixel_shader *ps = unsafe_impl_from_ID3D10PixelShader(shader);
147
148     TRACE("iface %p, shader %p\n", iface, shader);
149
150     wined3d_device_set_pixel_shader(This->wined3d_device, ps ? ps->wined3d_shader : NULL);
151 }
152
153 static void STDMETHODCALLTYPE d3d10_device_PSSetSamplers(ID3D10Device *iface,
154         UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
155 {
156     FIXME("iface %p, start_slot %u, sampler_count %u, samplers %p stub!\n",
157             iface, start_slot, sampler_count, samplers);
158 }
159
160 static void STDMETHODCALLTYPE d3d10_device_VSSetShader(ID3D10Device *iface,
161         ID3D10VertexShader *shader)
162 {
163     struct d3d10_device *This = impl_from_ID3D10Device(iface);
164     struct d3d10_vertex_shader *vs = unsafe_impl_from_ID3D10VertexShader(shader);
165
166     TRACE("iface %p, shader %p\n", iface, shader);
167
168     wined3d_device_set_vertex_shader(This->wined3d_device, vs ? vs->wined3d_shader : NULL);
169 }
170
171 static void STDMETHODCALLTYPE d3d10_device_DrawIndexed(ID3D10Device *iface, UINT index_count,
172         UINT start_index_location, INT base_vertex_location)
173 {
174     struct d3d10_device *This = impl_from_ID3D10Device(iface);
175
176     TRACE("iface %p, index_count %u, start_index_location %u, base_vertex_location %d.\n",
177             iface, index_count, start_index_location, base_vertex_location);
178
179     wined3d_device_set_base_vertex_index(This->wined3d_device, base_vertex_location);
180     wined3d_device_draw_indexed_primitive(This->wined3d_device, start_index_location, index_count);
181 }
182
183 static void STDMETHODCALLTYPE d3d10_device_Draw(ID3D10Device *iface, UINT vertex_count,
184         UINT start_vertex_location)
185 {
186     struct d3d10_device *This = impl_from_ID3D10Device(iface);
187
188     TRACE("iface %p, vertex_count %u, start_vertex_location %u\n",
189             iface, vertex_count, start_vertex_location);
190
191     wined3d_device_draw_primitive(This->wined3d_device, start_vertex_location, vertex_count);
192 }
193
194 static void STDMETHODCALLTYPE d3d10_device_PSSetConstantBuffers(ID3D10Device *iface,
195         UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
196 {
197     FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p stub!\n",
198             iface, start_slot, buffer_count, buffers);
199 }
200
201 static void STDMETHODCALLTYPE d3d10_device_IASetInputLayout(ID3D10Device *iface,
202         ID3D10InputLayout *input_layout)
203 {
204     struct d3d10_device *This = impl_from_ID3D10Device(iface);
205     struct d3d10_input_layout *layout = unsafe_impl_from_ID3D10InputLayout(input_layout);
206
207     TRACE("iface %p, input_layout %p\n", iface, input_layout);
208
209     wined3d_device_set_vertex_declaration(This->wined3d_device,
210             layout ? layout->wined3d_decl : NULL);
211 }
212
213 static void STDMETHODCALLTYPE d3d10_device_IASetVertexBuffers(ID3D10Device *iface, UINT start_slot,
214         UINT buffer_count, ID3D10Buffer *const *buffers, const UINT *strides, const UINT *offsets)
215 {
216     struct d3d10_device *This = impl_from_ID3D10Device(iface);
217     unsigned int i;
218
219     TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p\n",
220             iface, start_slot, buffer_count, buffers, strides, offsets);
221
222     for (i = 0; i < buffer_count; ++i)
223     {
224         struct d3d10_buffer *buffer = unsafe_impl_from_ID3D10Buffer(buffers[i]);
225
226         wined3d_device_set_stream_source(This->wined3d_device, start_slot + i,
227                 buffer ? buffer->wined3d_buffer : NULL, offsets[i], strides[i]);
228     }
229 }
230
231 static void STDMETHODCALLTYPE d3d10_device_IASetIndexBuffer(ID3D10Device *iface,
232         ID3D10Buffer *buffer, DXGI_FORMAT format, UINT offset)
233 {
234     struct d3d10_device *This = impl_from_ID3D10Device(iface);
235     struct d3d10_buffer *buffer_impl = unsafe_impl_from_ID3D10Buffer(buffer);
236
237     TRACE("iface %p, buffer %p, format %s, offset %u.\n",
238             iface, buffer, debug_dxgi_format(format), offset);
239
240     wined3d_device_set_index_buffer(This->wined3d_device,
241             buffer_impl ? buffer_impl->wined3d_buffer : NULL,
242             wined3dformat_from_dxgi_format(format));
243     if (offset) FIXME("offset %u not supported.\n", offset);
244 }
245
246 static void STDMETHODCALLTYPE d3d10_device_DrawIndexedInstanced(ID3D10Device *iface,
247         UINT instance_index_count, UINT instance_count, UINT start_index_location,
248         INT base_vertex_location, UINT start_instance_location)
249 {
250     struct d3d10_device *device = impl_from_ID3D10Device(iface);
251
252     TRACE("iface %p, instance_index_count %u, instance_count %u, start_index_location %u,\n"
253             "\tbase_vertex_location %d, start_instance_location %u.\n",
254             iface, instance_index_count, instance_count, start_index_location,
255             base_vertex_location, start_instance_location);
256
257     wined3d_device_set_base_vertex_index(device->wined3d_device, base_vertex_location);
258     wined3d_device_draw_indexed_primitive_instanced(device->wined3d_device, start_index_location,
259             instance_index_count, start_instance_location, instance_count);
260 }
261
262 static void STDMETHODCALLTYPE d3d10_device_DrawInstanced(ID3D10Device *iface,
263         UINT instance_vertex_count, UINT instance_count,
264         UINT start_vertex_location, UINT start_instance_location)
265 {
266     FIXME("iface %p, instance_vertex_count %u, instance_count %u, start_vertex_location %u,\n"
267             "\tstart_instance_location %u stub!\n", iface, instance_vertex_count, instance_count,
268             start_vertex_location, start_instance_location);
269 }
270
271 static void STDMETHODCALLTYPE d3d10_device_GSSetConstantBuffers(ID3D10Device *iface,
272         UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
273 {
274     FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p stub!\n",
275             iface, start_slot, buffer_count, buffers);
276 }
277
278 static void STDMETHODCALLTYPE d3d10_device_GSSetShader(ID3D10Device *iface, ID3D10GeometryShader *shader)
279 {
280     struct d3d10_device *device = impl_from_ID3D10Device(iface);
281     struct d3d10_geometry_shader *gs = unsafe_impl_from_ID3D10GeometryShader(shader);
282
283     TRACE("iface %p, shader %p.\n", iface, shader);
284
285     wined3d_device_set_geometry_shader(device->wined3d_device, gs ? gs->wined3d_shader : NULL);
286 }
287
288 static void STDMETHODCALLTYPE d3d10_device_IASetPrimitiveTopology(ID3D10Device *iface,
289         D3D10_PRIMITIVE_TOPOLOGY topology)
290 {
291     struct d3d10_device *This = impl_from_ID3D10Device(iface);
292
293     TRACE("iface %p, topology %s\n", iface, debug_d3d10_primitive_topology(topology));
294
295     wined3d_device_set_primitive_type(This->wined3d_device, (enum wined3d_primitive_type)topology);
296 }
297
298 static void STDMETHODCALLTYPE d3d10_device_VSSetShaderResources(ID3D10Device *iface,
299         UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
300 {
301     FIXME("iface %p, start_slot %u, view_count %u, views %p stub!\n",
302             iface, start_slot, view_count, views);
303 }
304
305 static void STDMETHODCALLTYPE d3d10_device_VSSetSamplers(ID3D10Device *iface,
306         UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
307 {
308     FIXME("iface %p, start_slot %u, sampler_count %u, samplers %p stub!\n",
309             iface, start_slot, sampler_count, samplers);
310 }
311
312 static void STDMETHODCALLTYPE d3d10_device_SetPredication(ID3D10Device *iface, ID3D10Predicate *predicate, BOOL value)
313 {
314     FIXME("iface %p, predicate %p, value %d stub!\n", iface, predicate, value);
315 }
316
317 static void STDMETHODCALLTYPE d3d10_device_GSSetShaderResources(ID3D10Device *iface,
318         UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
319 {
320     FIXME("iface %p, start_slot %u, view_count %u, views %p stub!\n",
321             iface, start_slot, view_count, views);
322 }
323
324 static void STDMETHODCALLTYPE d3d10_device_GSSetSamplers(ID3D10Device *iface,
325         UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
326 {
327     FIXME("iface %p, start_slot %u, sampler_count %u, samplers %p stub!\n",
328             iface, start_slot, sampler_count, samplers);
329 }
330
331 static void STDMETHODCALLTYPE d3d10_device_OMSetRenderTargets(ID3D10Device *iface,
332         UINT render_target_view_count, ID3D10RenderTargetView *const *render_target_views,
333         ID3D10DepthStencilView *depth_stencil_view)
334 {
335     FIXME("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p\n",
336             iface, render_target_view_count, render_target_views, depth_stencil_view);
337 }
338
339 static void STDMETHODCALLTYPE d3d10_device_OMSetBlendState(ID3D10Device *iface,
340         ID3D10BlendState *blend_state, const FLOAT blend_factor[4], UINT sample_mask)
341 {
342     struct d3d10_device *device = impl_from_ID3D10Device(iface);
343
344     TRACE("iface %p, blend_state %p, blend_factor [%f %f %f %f], sample_mask 0x%08x.\n",
345             iface, blend_state, blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3], sample_mask);
346
347     device->blend_state = unsafe_impl_from_ID3D10BlendState(blend_state);
348     memcpy(device->blend_factor, blend_factor, 4 * sizeof(*blend_factor));
349     device->sample_mask = sample_mask;
350 }
351
352 static void STDMETHODCALLTYPE d3d10_device_OMSetDepthStencilState(ID3D10Device *iface,
353         ID3D10DepthStencilState *depth_stencil_state, UINT stencil_ref)
354 {
355     struct d3d10_device *device = impl_from_ID3D10Device(iface);
356
357     TRACE("iface %p, depth_stencil_state %p, stencil_ref %u.\n",
358             iface, depth_stencil_state, stencil_ref);
359
360     device->depth_stencil_state = unsafe_impl_from_ID3D10DepthStencilState(depth_stencil_state);
361     device->stencil_ref = stencil_ref;
362 }
363
364 static void STDMETHODCALLTYPE d3d10_device_SOSetTargets(ID3D10Device *iface,
365         UINT target_count, ID3D10Buffer *const *targets, const UINT *offsets)
366 {
367     struct d3d10_device *device = impl_from_ID3D10Device(iface);
368     unsigned int count, i;
369
370     TRACE("iface %p, target_count %u, targets %p, offsets %p.\n", iface, target_count, targets, offsets);
371
372     count = min(target_count, 4);
373     for (i = 0; i < count; ++i)
374     {
375         struct d3d10_buffer *buffer = unsafe_impl_from_ID3D10Buffer(targets[i]);
376
377         wined3d_device_set_stream_output(device->wined3d_device, i,
378                 buffer ? buffer->wined3d_buffer : NULL, offsets[i]);
379     }
380
381     for (i = count; i < 4; ++i)
382     {
383         wined3d_device_set_stream_output(device->wined3d_device, i, NULL, 0);
384     }
385 }
386
387 static void STDMETHODCALLTYPE d3d10_device_DrawAuto(ID3D10Device *iface)
388 {
389     FIXME("iface %p stub!\n", iface);
390 }
391
392 static void STDMETHODCALLTYPE d3d10_device_RSSetState(ID3D10Device *iface, ID3D10RasterizerState *rasterizer_state)
393 {
394     struct d3d10_device *device = impl_from_ID3D10Device(iface);
395
396     TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
397
398     device->rasterizer_state = unsafe_impl_from_ID3D10RasterizerState(rasterizer_state);
399 }
400
401 static void STDMETHODCALLTYPE d3d10_device_RSSetViewports(ID3D10Device *iface,
402         UINT viewport_count, const D3D10_VIEWPORT *viewports)
403 {
404     struct d3d10_device *device = impl_from_ID3D10Device(iface);
405     struct wined3d_viewport wined3d_vp;
406
407     TRACE("iface %p, viewport_count %u, viewports %p.\n", iface, viewport_count, viewports);
408
409     if (viewport_count > 1)
410         FIXME("Multiple viewports not implemented.\n");
411
412     if (!viewport_count)
413         return;
414
415     wined3d_vp.x = viewports[0].TopLeftX;
416     wined3d_vp.y = viewports[0].TopLeftY;
417     wined3d_vp.width = viewports[0].Width;
418     wined3d_vp.height = viewports[0].Height;
419     wined3d_vp.min_z = viewports[0].MinDepth;
420     wined3d_vp.max_z = viewports[0].MaxDepth;
421
422     wined3d_device_set_viewport(device->wined3d_device, &wined3d_vp);
423 }
424
425 static void STDMETHODCALLTYPE d3d10_device_RSSetScissorRects(ID3D10Device *iface,
426         UINT rect_count, const D3D10_RECT *rects)
427 {
428     struct d3d10_device *device = impl_from_ID3D10Device(iface);
429
430     TRACE("iface %p, rect_count %u, rects %p.\n", iface, rect_count, rects);
431
432     if (rect_count > 1)
433         FIXME("Multiple scissor rects not implemented.\n");
434
435     if (!rect_count)
436         return;
437
438     wined3d_device_set_scissor_rect(device->wined3d_device, rects);
439 }
440
441 static void STDMETHODCALLTYPE d3d10_device_CopySubresourceRegion(ID3D10Device *iface,
442         ID3D10Resource *dst_resource, UINT dst_subresource_idx, UINT dst_x, UINT dst_y, UINT dst_z,
443         ID3D10Resource *src_resource, UINT src_subresource_idx, const D3D10_BOX *src_box)
444 {
445     FIXME("iface %p, dst_resource %p, dst_subresource_idx %u, dst_x %u, dst_y %u, dst_z %u,\n"
446             "\tsrc_resource %p, src_subresource_idx %u, src_box %p stub!\n",
447             iface, dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
448             src_resource, src_subresource_idx, src_box);
449 }
450
451 static void STDMETHODCALLTYPE d3d10_device_CopyResource(ID3D10Device *iface,
452         ID3D10Resource *dst_resource, ID3D10Resource *src_resource)
453 {
454     FIXME("iface %p, dst_resource %p, src_resource %p stub!\n", iface, dst_resource, src_resource);
455 }
456
457 static void STDMETHODCALLTYPE d3d10_device_UpdateSubresource(ID3D10Device *iface,
458         ID3D10Resource *resource, UINT subresource_idx, const D3D10_BOX *box,
459         const void *data, UINT row_pitch, UINT depth_pitch)
460 {
461     FIXME("iface %p, resource %p, subresource_idx %u, box %p, data %p, row_pitch %u, depth_pitch %u stub!\n",
462             iface, resource, subresource_idx, box, data, row_pitch, depth_pitch);
463 }
464
465 static void STDMETHODCALLTYPE d3d10_device_ClearRenderTargetView(ID3D10Device *iface,
466         ID3D10RenderTargetView *render_target_view, const FLOAT color_rgba[4])
467 {
468     struct d3d10_device *This = impl_from_ID3D10Device(iface);
469     struct d3d10_rendertarget_view *view = unsafe_impl_from_ID3D10RenderTargetView(render_target_view);
470     const struct wined3d_color color = {color_rgba[0], color_rgba[1], color_rgba[2], color_rgba[3]};
471
472     TRACE("iface %p, render_target_view %p, color_rgba [%f %f %f %f]\n",
473             iface, render_target_view, color_rgba[0], color_rgba[1], color_rgba[2], color_rgba[3]);
474
475     wined3d_device_clear_rendertarget_view(This->wined3d_device, view->wined3d_view, &color);
476 }
477
478 static void STDMETHODCALLTYPE d3d10_device_ClearDepthStencilView(ID3D10Device *iface,
479         ID3D10DepthStencilView *depth_stencil_view, UINT flags, FLOAT depth, UINT8 stencil)
480 {
481     FIXME("iface %p, depth_stencil_view %p, flags %#x, depth %f, stencil %u stub!\n",
482             iface, depth_stencil_view, flags, depth, stencil);
483 }
484
485 static void STDMETHODCALLTYPE d3d10_device_GenerateMips(ID3D10Device *iface, ID3D10ShaderResourceView *shader_resource_view)
486 {
487     FIXME("iface %p, shader_resource_view %p stub!\n", iface, shader_resource_view);
488 }
489
490 static void STDMETHODCALLTYPE d3d10_device_ResolveSubresource(ID3D10Device *iface,
491         ID3D10Resource *dst_resource, UINT dst_subresource_idx,
492         ID3D10Resource *src_resource, UINT src_subresource_idx, DXGI_FORMAT format)
493 {
494     FIXME("iface %p, dst_resource %p, dst_subresource_idx %u,\n"
495             "\tsrc_resource %p, src_subresource_idx %u, format %s stub!\n",
496             iface, dst_resource, dst_subresource_idx,
497             src_resource, src_subresource_idx, debug_dxgi_format(format));
498 }
499
500 static void STDMETHODCALLTYPE d3d10_device_VSGetConstantBuffers(ID3D10Device *iface,
501         UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
502 {
503     FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p stub!\n",
504             iface, start_slot, buffer_count, buffers);
505 }
506
507 static void STDMETHODCALLTYPE d3d10_device_PSGetShaderResources(ID3D10Device *iface,
508         UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
509 {
510     FIXME("iface %p, start_slot %u, view_count %u, views %p stub!\n",
511             iface, start_slot, view_count, views);
512 }
513
514 static void STDMETHODCALLTYPE d3d10_device_PSGetShader(ID3D10Device *iface, ID3D10PixelShader **shader)
515 {
516     struct d3d10_device *device = impl_from_ID3D10Device(iface);
517     struct d3d10_pixel_shader *shader_impl;
518     struct wined3d_shader *wined3d_shader;
519
520     TRACE("iface %p, shader %p.\n", iface, shader);
521
522     if (!(wined3d_shader = wined3d_device_get_pixel_shader(device->wined3d_device)))
523     {
524         *shader = NULL;
525         return;
526     }
527
528     shader_impl = wined3d_shader_get_parent(wined3d_shader);
529     *shader = &shader_impl->ID3D10PixelShader_iface;
530     ID3D10PixelShader_AddRef(*shader);
531 }
532
533 static void STDMETHODCALLTYPE d3d10_device_PSGetSamplers(ID3D10Device *iface,
534         UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
535 {
536     FIXME("iface %p, start_slot %u, sampler_count %u, samplers %p stub!\n",
537             iface, start_slot, sampler_count, samplers);
538 }
539
540 static void STDMETHODCALLTYPE d3d10_device_VSGetShader(ID3D10Device *iface, ID3D10VertexShader **shader)
541 {
542     struct d3d10_device *device = impl_from_ID3D10Device(iface);
543     struct d3d10_vertex_shader *shader_impl;
544     struct wined3d_shader *wined3d_shader;
545
546     TRACE("iface %p, shader %p.\n", iface, shader);
547
548     if (!(wined3d_shader = wined3d_device_get_vertex_shader(device->wined3d_device)))
549     {
550         *shader = NULL;
551         return;
552     }
553
554     shader_impl = wined3d_shader_get_parent(wined3d_shader);
555     *shader = &shader_impl->ID3D10VertexShader_iface;
556     ID3D10VertexShader_AddRef(*shader);
557 }
558
559 static void STDMETHODCALLTYPE d3d10_device_PSGetConstantBuffers(ID3D10Device *iface,
560         UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
561 {
562     FIXME("iface %p, start_slot %u, buffer_count %u, buffer %p stub!\n",
563             iface, start_slot, buffer_count, buffers);
564 }
565
566 static void STDMETHODCALLTYPE d3d10_device_IAGetInputLayout(ID3D10Device *iface, ID3D10InputLayout **input_layout)
567 {
568     struct d3d10_device *device = impl_from_ID3D10Device(iface);
569     struct wined3d_vertex_declaration *wined3d_declaration;
570     struct d3d10_input_layout *input_layout_impl;
571
572     TRACE("iface %p, input_layout %p.\n", iface, input_layout);
573
574     if (!(wined3d_declaration = wined3d_device_get_vertex_declaration(device->wined3d_device)))
575     {
576         *input_layout = NULL;
577         return;
578     }
579
580     input_layout_impl = wined3d_vertex_declaration_get_parent(wined3d_declaration);
581     *input_layout = &input_layout_impl->ID3D10InputLayout_iface;
582     ID3D10InputLayout_AddRef(*input_layout);
583 }
584
585 static void STDMETHODCALLTYPE d3d10_device_IAGetVertexBuffers(ID3D10Device *iface,
586         UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers, UINT *strides, UINT *offsets)
587 {
588     struct d3d10_device *device = impl_from_ID3D10Device(iface);
589     unsigned int i;
590
591     TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p.\n",
592             iface, start_slot, buffer_count, buffers, strides, offsets);
593
594     for (i = 0; i < buffer_count; ++i)
595     {
596         struct wined3d_buffer *wined3d_buffer;
597         struct d3d10_buffer *buffer_impl;
598
599         if (FAILED(wined3d_device_get_stream_source(device->wined3d_device, start_slot + i,
600                 &wined3d_buffer, &offsets[i], &strides[i])))
601             ERR("Failed to get vertex buffer.\n");
602
603         if (!wined3d_buffer)
604         {
605             buffers[i] = NULL;
606             continue;
607         }
608
609         buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
610         buffers[i] = &buffer_impl->ID3D10Buffer_iface;
611         ID3D10Buffer_AddRef(buffers[i]);
612     }
613 }
614
615 static void STDMETHODCALLTYPE d3d10_device_IAGetIndexBuffer(ID3D10Device *iface,
616         ID3D10Buffer **buffer, DXGI_FORMAT *format, UINT *offset)
617 {
618     struct d3d10_device *device = impl_from_ID3D10Device(iface);
619     enum wined3d_format_id wined3d_format;
620     struct wined3d_buffer *wined3d_buffer;
621     struct d3d10_buffer *buffer_impl;
622
623     TRACE("iface %p, buffer %p, format %p, offset %p.\n", iface, buffer, format, offset);
624
625     wined3d_buffer = wined3d_device_get_index_buffer(device->wined3d_device, &wined3d_format);
626     *format = dxgi_format_from_wined3dformat(wined3d_format);
627     *offset = 0; /* FIXME */
628     if (!wined3d_buffer)
629     {
630         *buffer = NULL;
631         return;
632     }
633
634     buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
635     *buffer = &buffer_impl->ID3D10Buffer_iface;
636     ID3D10Buffer_AddRef(*buffer);
637 }
638
639 static void STDMETHODCALLTYPE d3d10_device_GSGetConstantBuffers(ID3D10Device *iface,
640         UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
641 {
642     FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p stub!\n",
643             iface, start_slot, buffer_count, buffers);
644 }
645
646 static void STDMETHODCALLTYPE d3d10_device_GSGetShader(ID3D10Device *iface, ID3D10GeometryShader **shader)
647 {
648     struct d3d10_device *device = impl_from_ID3D10Device(iface);
649     struct d3d10_geometry_shader *shader_impl;
650     struct wined3d_shader *wined3d_shader;
651
652     TRACE("iface %p, shader %p.\n", iface, shader);
653
654     if (!(wined3d_shader = wined3d_device_get_geometry_shader(device->wined3d_device)))
655     {
656         *shader = NULL;
657         return;
658     }
659
660     shader_impl = wined3d_shader_get_parent(wined3d_shader);
661     *shader = &shader_impl->ID3D10GeometryShader_iface;
662     ID3D10GeometryShader_AddRef(*shader);
663 }
664
665 static void STDMETHODCALLTYPE d3d10_device_IAGetPrimitiveTopology(ID3D10Device *iface,
666         D3D10_PRIMITIVE_TOPOLOGY *topology)
667 {
668     struct d3d10_device *This = impl_from_ID3D10Device(iface);
669
670     TRACE("iface %p, topology %p\n", iface, topology);
671
672     wined3d_device_get_primitive_type(This->wined3d_device, (enum wined3d_primitive_type *)topology);
673 }
674
675 static void STDMETHODCALLTYPE d3d10_device_VSGetShaderResources(ID3D10Device *iface,
676         UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
677 {
678     FIXME("iface %p, start_slot %u, view_count %u, views %p stub!\n",
679             iface, start_slot, view_count, views);
680 }
681
682 static void STDMETHODCALLTYPE d3d10_device_VSGetSamplers(ID3D10Device *iface,
683         UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
684 {
685     FIXME("iface %p, start_slot %u, sampler_count %u, samplers %p stub!\n",
686             iface, start_slot, sampler_count, samplers);
687 }
688
689 static void STDMETHODCALLTYPE d3d10_device_GetPredication(ID3D10Device *iface,
690         ID3D10Predicate **predicate, BOOL *value)
691 {
692     FIXME("iface %p, predicate %p, value %p stub!\n", iface, predicate, value);
693 }
694
695 static void STDMETHODCALLTYPE d3d10_device_GSGetShaderResources(ID3D10Device *iface,
696         UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
697 {
698     FIXME("iface %p, start_slot %u, view_count %u, views %p stub!\n",
699             iface, start_slot, view_count, views);
700 }
701
702 static void STDMETHODCALLTYPE d3d10_device_GSGetSamplers(ID3D10Device *iface,
703         UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
704 {
705     FIXME("iface %p, start_slot %u, sampler_count %u, samplers %p stub!\n",
706             iface, start_slot, sampler_count, samplers);
707 }
708
709 static void STDMETHODCALLTYPE d3d10_device_OMGetRenderTargets(ID3D10Device *iface,
710         UINT view_count, ID3D10RenderTargetView **render_target_views, ID3D10DepthStencilView **depth_stencil_view)
711 {
712     FIXME("iface %p, view_count %u, render_target_views %p, depth_stencil_view %p stub!\n",
713             iface, view_count, render_target_views, depth_stencil_view);
714 }
715
716 static void STDMETHODCALLTYPE d3d10_device_OMGetBlendState(ID3D10Device *iface,
717         ID3D10BlendState **blend_state, FLOAT blend_factor[4], UINT *sample_mask)
718 {
719     struct d3d10_device *device = impl_from_ID3D10Device(iface);
720
721     TRACE("iface %p, blend_state %p, blend_factor %p, sample_mask %p.\n",
722             iface, blend_state, blend_factor, sample_mask);
723
724     if ((*blend_state = device->blend_state ? &device->blend_state->ID3D10BlendState_iface : NULL))
725         ID3D10BlendState_AddRef(*blend_state);
726     memcpy(blend_factor, device->blend_factor, 4 * sizeof(*blend_factor));
727     *sample_mask = device->sample_mask;
728 }
729
730 static void STDMETHODCALLTYPE d3d10_device_OMGetDepthStencilState(ID3D10Device *iface,
731         ID3D10DepthStencilState **depth_stencil_state, UINT *stencil_ref)
732 {
733     struct d3d10_device *device = impl_from_ID3D10Device(iface);
734
735     TRACE("iface %p, depth_stencil_state %p, stencil_ref %p.\n",
736             iface, depth_stencil_state, stencil_ref);
737
738     if ((*depth_stencil_state = device->depth_stencil_state
739             ? &device->depth_stencil_state->ID3D10DepthStencilState_iface : NULL))
740         ID3D10DepthStencilState_AddRef(*depth_stencil_state);
741     *stencil_ref = device->stencil_ref;
742 }
743
744 static void STDMETHODCALLTYPE d3d10_device_SOGetTargets(ID3D10Device *iface,
745         UINT buffer_count, ID3D10Buffer **buffers, UINT *offsets)
746 {
747     struct d3d10_device *device = impl_from_ID3D10Device(iface);
748     unsigned int i;
749
750     TRACE("iface %p, buffer_count %u, buffers %p, offsets %p.\n",
751             iface, buffer_count, buffers, offsets);
752
753     for (i = 0; i < buffer_count; ++i)
754     {
755         struct wined3d_buffer *wined3d_buffer;
756         struct d3d10_buffer *buffer_impl;
757
758         if (!(wined3d_buffer = wined3d_device_get_stream_output(device->wined3d_device, i, &offsets[i])))
759         {
760             buffers[i] = NULL;
761             continue;
762         }
763
764         buffer_impl = wined3d_buffer_get_parent(wined3d_buffer);
765         buffers[i] = &buffer_impl->ID3D10Buffer_iface;
766         ID3D10Buffer_AddRef(buffers[i]);
767     }
768 }
769
770 static void STDMETHODCALLTYPE d3d10_device_RSGetState(ID3D10Device *iface, ID3D10RasterizerState **rasterizer_state)
771 {
772     struct d3d10_device *device = impl_from_ID3D10Device(iface);
773
774     TRACE("iface %p, rasterizer_state %p.\n", iface, rasterizer_state);
775
776     if ((*rasterizer_state = device->rasterizer_state ? &device->rasterizer_state->ID3D10RasterizerState_iface : NULL))
777         ID3D10RasterizerState_AddRef(*rasterizer_state);
778 }
779
780 static void STDMETHODCALLTYPE d3d10_device_RSGetViewports(ID3D10Device *iface,
781         UINT *viewport_count, D3D10_VIEWPORT *viewports)
782 {
783     struct d3d10_device *device = impl_from_ID3D10Device(iface);
784     struct wined3d_viewport wined3d_vp;
785
786     TRACE("iface %p, viewport_count %p, viewports %p.\n", iface, viewport_count, viewports);
787
788     if (!viewports)
789     {
790         *viewport_count = 1;
791         return;
792     }
793
794     if (!*viewport_count)
795         return;
796
797     wined3d_device_get_viewport(device->wined3d_device, &wined3d_vp);
798
799     viewports[0].TopLeftX = wined3d_vp.x;
800     viewports[0].TopLeftY = wined3d_vp.y;
801     viewports[0].Width = wined3d_vp.width;
802     viewports[0].Height = wined3d_vp.height;
803     viewports[0].MinDepth = wined3d_vp.min_z;
804     viewports[0].MaxDepth = wined3d_vp.max_z;
805
806     if (*viewport_count > 1)
807         memset(&viewports[1], 0, (*viewport_count - 1) * sizeof(*viewports));
808 }
809
810 static void STDMETHODCALLTYPE d3d10_device_RSGetScissorRects(ID3D10Device *iface, UINT *rect_count, D3D10_RECT *rects)
811 {
812     struct d3d10_device *device = impl_from_ID3D10Device(iface);
813
814     TRACE("iface %p, rect_count %p, rects %p.\n", iface, rect_count, rects);
815
816     if (!rects)
817     {
818         *rect_count = 1;
819         return;
820     }
821
822     if (!*rect_count)
823         return;
824
825     wined3d_device_get_scissor_rect(device->wined3d_device, rects);
826     if (*rect_count > 1)
827         memset(&rects[1], 0, (*rect_count - 1) * sizeof(*rects));
828 }
829
830 static HRESULT STDMETHODCALLTYPE d3d10_device_GetDeviceRemovedReason(ID3D10Device *iface)
831 {
832     FIXME("iface %p stub!\n", iface);
833
834     return E_NOTIMPL;
835 }
836
837 static HRESULT STDMETHODCALLTYPE d3d10_device_SetExceptionMode(ID3D10Device *iface, UINT flags)
838 {
839     FIXME("iface %p, flags %#x stub!\n", iface, flags);
840
841     return E_NOTIMPL;
842 }
843
844 static UINT STDMETHODCALLTYPE d3d10_device_GetExceptionMode(ID3D10Device *iface)
845 {
846     FIXME("iface %p stub!\n", iface);
847
848     return 0;
849 }
850
851 static HRESULT STDMETHODCALLTYPE d3d10_device_GetPrivateData(ID3D10Device *iface,
852         REFGUID guid, UINT *data_size, void *data)
853 {
854     FIXME("iface %p, guid %s, data_size %p, data %p stub!\n",
855             iface, debugstr_guid(guid), data_size, data);
856
857     return E_NOTIMPL;
858 }
859
860 static HRESULT STDMETHODCALLTYPE d3d10_device_SetPrivateData(ID3D10Device *iface,
861         REFGUID guid, UINT data_size, const void *data)
862 {
863     FIXME("iface %p, guid %s, data_size %u, data %p stub!\n",
864             iface, debugstr_guid(guid), data_size, data);
865
866     return E_NOTIMPL;
867 }
868
869 static HRESULT STDMETHODCALLTYPE d3d10_device_SetPrivateDataInterface(ID3D10Device *iface,
870         REFGUID guid, const IUnknown *data)
871 {
872     FIXME("iface %p, guid %s, data %p stub!\n", iface, debugstr_guid(guid), data);
873
874     return E_NOTIMPL;
875 }
876
877 static void STDMETHODCALLTYPE d3d10_device_ClearState(ID3D10Device *iface)
878 {
879     FIXME("iface %p stub!\n", iface);
880 }
881
882 static void STDMETHODCALLTYPE d3d10_device_Flush(ID3D10Device *iface)
883 {
884     FIXME("iface %p stub!\n", iface);
885 }
886
887 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBuffer(ID3D10Device *iface,
888         const D3D10_BUFFER_DESC *desc, const D3D10_SUBRESOURCE_DATA *data, ID3D10Buffer **buffer)
889 {
890     struct d3d10_device *This = impl_from_ID3D10Device(iface);
891     struct d3d10_buffer *object;
892     HRESULT hr;
893
894     FIXME("iface %p, desc %p, data %p, buffer %p partial stub!\n", iface, desc, data, buffer);
895
896     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
897     if (!object)
898     {
899         ERR("Failed to allocate D3D10 buffer object memory\n");
900         return E_OUTOFMEMORY;
901     }
902
903     hr = d3d10_buffer_init(object, This, desc, data);
904     if (FAILED(hr))
905     {
906         WARN("Failed to initialize buffer, hr %#x.\n", hr);
907         HeapFree(GetProcessHeap(), 0, object);
908         return hr;
909     }
910
911     *buffer = &object->ID3D10Buffer_iface;
912
913     TRACE("Created ID3D10Buffer %p\n", object);
914
915     return S_OK;
916 }
917
918 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture1D(ID3D10Device *iface,
919         const D3D10_TEXTURE1D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data, ID3D10Texture1D **texture)
920 {
921     FIXME("iface %p, desc %p, data %p, texture %p stub!\n", iface, desc, data, texture);
922
923     return E_NOTIMPL;
924 }
925
926 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture2D(ID3D10Device *iface,
927         const D3D10_TEXTURE2D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data,
928         ID3D10Texture2D **texture)
929 {
930     struct d3d10_device *This = impl_from_ID3D10Device(iface);
931     struct d3d10_texture2d *object;
932     HRESULT hr;
933
934     FIXME("iface %p, desc %p, data %p, texture %p partial stub!\n", iface, desc, data, texture);
935
936     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
937     if (!object)
938     {
939         ERR("Failed to allocate D3D10 texture2d object memory\n");
940         return E_OUTOFMEMORY;
941     }
942
943     hr = d3d10_texture2d_init(object, This, desc);
944     if (FAILED(hr))
945     {
946         WARN("Failed to initialize texture, hr %#x.\n", hr);
947         HeapFree(GetProcessHeap(), 0, object);
948         return hr;
949     }
950
951     *texture = &object->ID3D10Texture2D_iface;
952
953     TRACE("Created ID3D10Texture2D %p\n", object);
954
955     return S_OK;
956 }
957
958 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture3D(ID3D10Device *iface,
959         const D3D10_TEXTURE3D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data,
960         ID3D10Texture3D **texture)
961 {
962     struct d3d10_device *device = impl_from_ID3D10Device(iface);
963     struct d3d10_texture3d *object;
964     HRESULT hr;
965
966     TRACE("iface %p, desc %p, data %p, texture %p.\n", iface, desc, data, texture);
967
968     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
969     if (!object)
970     {
971         ERR("Failed to allocate D3D10 texture3d object memory.\n");
972         return E_OUTOFMEMORY;
973     }
974
975     hr = d3d10_texture3d_init(object, device, desc);
976     if (FAILED(hr))
977     {
978         WARN("Failed to initialize texture, hr %#x.\n", hr);
979         HeapFree(GetProcessHeap(), 0, object);
980         return hr;
981     }
982
983     TRACE("Created 3D texture %p.\n", object);
984     *texture = &object->ID3D10Texture3D_iface;
985
986     return S_OK;
987 }
988
989 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateShaderResourceView(ID3D10Device *iface,
990         ID3D10Resource *resource, const D3D10_SHADER_RESOURCE_VIEW_DESC *desc, ID3D10ShaderResourceView **view)
991 {
992     struct d3d10_shader_resource_view *object;
993     HRESULT hr;
994
995     TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
996
997     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
998     if (!object)
999     {
1000         ERR("Failed to allocate D3D10 shader resource view object memory.\n");
1001         return E_OUTOFMEMORY;
1002     }
1003
1004     if (FAILED(hr = d3d10_shader_resource_view_init(object, resource, desc)))
1005     {
1006         WARN("Failed to initialize shader resource view, hr %#x.\n", hr);
1007         HeapFree(GetProcessHeap(), 0, object);
1008         return hr;
1009     }
1010
1011     TRACE("Created shader resource view %p.\n", object);
1012     *view = &object->ID3D10ShaderResourceView_iface;
1013
1014     return S_OK;
1015 }
1016
1017 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateRenderTargetView(ID3D10Device *iface,
1018         ID3D10Resource *resource, const D3D10_RENDER_TARGET_VIEW_DESC *desc, ID3D10RenderTargetView **view)
1019 {
1020     struct d3d10_rendertarget_view *object;
1021     HRESULT hr;
1022
1023     TRACE("iface %p, resource %p, desc %p, view %p stub!\n", iface, resource, desc, view);
1024
1025     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1026     if (!object)
1027     {
1028         ERR("Failed to allocate D3D10 rendertarget view object memory\n");
1029         return E_OUTOFMEMORY;
1030     }
1031
1032     hr = d3d10_rendertarget_view_init(object, resource, desc);
1033     if (FAILED(hr))
1034     {
1035         WARN("Failed to initialize rendertarget view, hr %#x.\n", hr);
1036         HeapFree(GetProcessHeap(), 0, object);
1037         return hr;
1038     }
1039
1040     TRACE("Created rendertarget view %p.\n", object);
1041     *view = &object->ID3D10RenderTargetView_iface;
1042
1043     return S_OK;
1044 }
1045
1046 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateDepthStencilView(ID3D10Device *iface,
1047         ID3D10Resource *resource, const D3D10_DEPTH_STENCIL_VIEW_DESC *desc, ID3D10DepthStencilView **view)
1048 {
1049     struct d3d10_depthstencil_view *object;
1050     HRESULT hr;
1051
1052     TRACE("iface %p, resource %p, desc %p, view %p.\n", iface, resource, desc, view);
1053
1054     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1055     if (!object)
1056     {
1057         ERR("Failed to allocate D3D10 depthstencil view object memory.\n");
1058         return E_OUTOFMEMORY;
1059     }
1060
1061     if (FAILED(hr = d3d10_depthstencil_view_init(object, resource, desc)))
1062     {
1063         WARN("Failed to initialize depthstencil view, hr %#x.\n", hr);
1064         HeapFree(GetProcessHeap(), 0, object);
1065         return hr;
1066     }
1067
1068     TRACE("Created depthstencil view %p.\n", object);
1069     *view = &object->ID3D10DepthStencilView_iface;
1070
1071     return S_OK;
1072 }
1073
1074 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateInputLayout(ID3D10Device *iface,
1075         const D3D10_INPUT_ELEMENT_DESC *element_descs, UINT element_count,
1076         const void *shader_byte_code, SIZE_T shader_byte_code_length,
1077         ID3D10InputLayout **input_layout)
1078 {
1079     struct d3d10_device *This = impl_from_ID3D10Device(iface);
1080     struct d3d10_input_layout *object;
1081     HRESULT hr;
1082
1083     TRACE("iface %p, element_descs %p, element_count %u, shader_byte_code %p,"
1084             "\tshader_byte_code_length %lu, input_layout %p\n",
1085             iface, element_descs, element_count, shader_byte_code,
1086             shader_byte_code_length, input_layout);
1087
1088     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1089     if (!object)
1090     {
1091         ERR("Failed to allocate D3D10 input layout object memory\n");
1092         return E_OUTOFMEMORY;
1093     }
1094
1095     hr = d3d10_input_layout_init(object, This, element_descs, element_count,
1096             shader_byte_code, shader_byte_code_length);
1097     if (FAILED(hr))
1098     {
1099         WARN("Failed to initialize input layout, hr %#x.\n", hr);
1100         HeapFree(GetProcessHeap(), 0, object);
1101         return hr;
1102     }
1103
1104     TRACE("Created input layout %p.\n", object);
1105     *input_layout = &object->ID3D10InputLayout_iface;
1106
1107     return S_OK;
1108 }
1109
1110 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateVertexShader(ID3D10Device *iface,
1111         const void *byte_code, SIZE_T byte_code_length, ID3D10VertexShader **shader)
1112 {
1113     struct d3d10_device *This = impl_from_ID3D10Device(iface);
1114     struct d3d10_vertex_shader *object;
1115     HRESULT hr;
1116
1117     TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p\n",
1118             iface, byte_code, byte_code_length, shader);
1119
1120     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1121     if (!object)
1122     {
1123         ERR("Failed to allocate D3D10 vertex shader object memory\n");
1124         return E_OUTOFMEMORY;
1125     }
1126
1127     hr = d3d10_vertex_shader_init(object, This, byte_code, byte_code_length);
1128     if (FAILED(hr))
1129     {
1130         WARN("Failed to initialize vertex shader, hr %#x.\n", hr);
1131         HeapFree(GetProcessHeap(), 0, object);
1132         return hr;
1133     }
1134
1135     TRACE("Created vertex shader %p.\n", object);
1136     *shader = &object->ID3D10VertexShader_iface;
1137
1138     return S_OK;
1139 }
1140
1141 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateGeometryShader(ID3D10Device *iface,
1142         const void *byte_code, SIZE_T byte_code_length, ID3D10GeometryShader **shader)
1143 {
1144     struct d3d10_device *This = impl_from_ID3D10Device(iface);
1145     struct d3d10_geometry_shader *object;
1146     HRESULT hr;
1147
1148     FIXME("iface %p, byte_code %p, byte_code_length %lu, shader %p stub!\n",
1149             iface, byte_code, byte_code_length, shader);
1150
1151     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1152     if (!object)
1153     {
1154         ERR("Failed to allocate D3D10 geometry shader object memory\n");
1155         return E_OUTOFMEMORY;
1156     }
1157
1158     hr = d3d10_geometry_shader_init(object, This, byte_code, byte_code_length);
1159     if (FAILED(hr))
1160     {
1161         WARN("Failed to initialize geometry shader, hr %#x.\n", hr);
1162         HeapFree(GetProcessHeap(), 0, object);
1163         return hr;
1164     }
1165
1166     TRACE("Created geometry shader %p.\n", object);
1167     *shader = &object->ID3D10GeometryShader_iface;
1168
1169     return S_OK;
1170 }
1171
1172 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateGeometryShaderWithStreamOutput(ID3D10Device *iface,
1173         const void *byte_code, SIZE_T byte_code_length, const D3D10_SO_DECLARATION_ENTRY *output_stream_decls,
1174         UINT output_stream_decl_count, UINT output_stream_stride, ID3D10GeometryShader **shader)
1175 {
1176     FIXME("iface %p, byte_code %p, byte_code_length %lu, output_stream_decls %p,\n"
1177             "\toutput_stream_decl_count %u, output_stream_stride %u, shader %p stub!\n",
1178             iface, byte_code, byte_code_length, output_stream_decls,
1179             output_stream_decl_count, output_stream_stride, shader);
1180
1181     return E_NOTIMPL;
1182 }
1183
1184 static HRESULT STDMETHODCALLTYPE d3d10_device_CreatePixelShader(ID3D10Device *iface,
1185         const void *byte_code, SIZE_T byte_code_length, ID3D10PixelShader **shader)
1186 {
1187     struct d3d10_device *This = impl_from_ID3D10Device(iface);
1188     struct d3d10_pixel_shader *object;
1189     HRESULT hr;
1190
1191     TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p\n",
1192             iface, byte_code, byte_code_length, shader);
1193
1194     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1195     if (!object)
1196     {
1197         ERR("Failed to allocate D3D10 pixel shader object memory\n");
1198         return E_OUTOFMEMORY;
1199     }
1200
1201     hr = d3d10_pixel_shader_init(object, This, byte_code, byte_code_length);
1202     if (FAILED(hr))
1203     {
1204         WARN("Failed to initialize pixel shader, hr %#x.\n", hr);
1205         HeapFree(GetProcessHeap(), 0, object);
1206         return hr;
1207     }
1208
1209     TRACE("Created pixel shader %p.\n", object);
1210     *shader = &object->ID3D10PixelShader_iface;
1211
1212     return S_OK;
1213 }
1214
1215 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBlendState(ID3D10Device *iface,
1216         const D3D10_BLEND_DESC *desc, ID3D10BlendState **blend_state)
1217 {
1218     struct d3d10_blend_state *object;
1219     HRESULT hr;
1220
1221     TRACE("iface %p, desc %p, blend_state %p.\n", iface, desc, blend_state);
1222
1223     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1224     if (!object)
1225     {
1226         ERR("Failed to allocate D3D10 blend state object memory.\n");
1227         return E_OUTOFMEMORY;
1228     }
1229
1230     hr = d3d10_blend_state_init(object);
1231     if (FAILED(hr))
1232     {
1233         WARN("Failed to initialize blend state, hr %#x.\n", hr);
1234         HeapFree(GetProcessHeap(), 0, object);
1235         return hr;
1236     }
1237
1238     TRACE("Created blend state %p.\n", object);
1239     *blend_state = &object->ID3D10BlendState_iface;
1240
1241     return S_OK;
1242 }
1243
1244 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateDepthStencilState(ID3D10Device *iface,
1245         const D3D10_DEPTH_STENCIL_DESC *desc, ID3D10DepthStencilState **depth_stencil_state)
1246 {
1247     struct d3d10_depthstencil_state *object;
1248     HRESULT hr;
1249
1250     TRACE("iface %p, desc %p, depth_stencil_state %p.\n", iface, desc, depth_stencil_state);
1251
1252     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1253     if (!object)
1254     {
1255         ERR("Failed to allocate D3D10 depthstencil state object memory.\n");
1256         return E_OUTOFMEMORY;
1257     }
1258
1259     hr = d3d10_depthstencil_state_init(object);
1260     if (FAILED(hr))
1261     {
1262         WARN("Failed to initialize depthstencil state, hr %#x.\n", hr);
1263         HeapFree(GetProcessHeap(), 0, object);
1264         return hr;
1265     }
1266
1267     TRACE("Created depthstencil state %p.\n", object);
1268     *depth_stencil_state = &object->ID3D10DepthStencilState_iface;
1269
1270     return S_OK;
1271 }
1272
1273 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateRasterizerState(ID3D10Device *iface,
1274         const D3D10_RASTERIZER_DESC *desc, ID3D10RasterizerState **rasterizer_state)
1275 {
1276     struct d3d10_rasterizer_state *object;
1277     HRESULT hr;
1278
1279     TRACE("iface %p, desc %p, rasterizer_state %p.\n", iface, desc, rasterizer_state);
1280
1281     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1282     if (!object)
1283     {
1284         ERR("Failed to allocate D3D10 rasterizer state object memory.\n");
1285         return E_OUTOFMEMORY;
1286     }
1287
1288     hr = d3d10_rasterizer_state_init(object);
1289     if (FAILED(hr))
1290     {
1291         WARN("Failed to initialize rasterizer state, hr %#x.\n", hr);
1292         HeapFree(GetProcessHeap(), 0, object);
1293         return hr;
1294     }
1295
1296     TRACE("Created rasterizer state %p.\n", object);
1297     *rasterizer_state = &object->ID3D10RasterizerState_iface;
1298
1299     return S_OK;
1300 }
1301
1302 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateSamplerState(ID3D10Device *iface,
1303         const D3D10_SAMPLER_DESC *desc, ID3D10SamplerState **sampler_state)
1304 {
1305     struct d3d10_sampler_state *object;
1306     HRESULT hr;
1307
1308     TRACE("iface %p, desc %p, sampler_state %p.\n", iface, desc, sampler_state);
1309
1310     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1311     if (!object)
1312     {
1313         ERR("Failed to allocate D3D10 sampler state object memory.\n");
1314         return E_OUTOFMEMORY;
1315     }
1316
1317     hr = d3d10_sampler_state_init(object);
1318     if (FAILED(hr))
1319     {
1320         WARN("Failed to initialize sampler state, hr %#x.\n", hr);
1321         HeapFree(GetProcessHeap(), 0, object);
1322         return hr;
1323     }
1324
1325     TRACE("Created sampler state %p.\n", object);
1326     *sampler_state = &object->ID3D10SamplerState_iface;
1327
1328     return S_OK;
1329 }
1330
1331 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateQuery(ID3D10Device *iface,
1332         const D3D10_QUERY_DESC *desc, ID3D10Query **query)
1333 {
1334     struct d3d10_query *object;
1335     HRESULT hr;
1336
1337     TRACE("iface %p, desc %p, query %p.\n", iface, desc, query);
1338
1339     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1340     if (!object)
1341     {
1342         ERR("Failed to allocate D3D10 query object memory.\n");
1343         return E_OUTOFMEMORY;
1344     }
1345
1346     hr = d3d10_query_init(object);
1347     if (FAILED(hr))
1348     {
1349         WARN("Failed to initialize query, hr %#x.\n", hr);
1350         HeapFree(GetProcessHeap(), 0, object);
1351         return hr;
1352     }
1353
1354     TRACE("Created query %p.\n", object);
1355     *query = &object->ID3D10Query_iface;
1356
1357     return S_OK;
1358 }
1359
1360 static HRESULT STDMETHODCALLTYPE d3d10_device_CreatePredicate(ID3D10Device *iface,
1361         const D3D10_QUERY_DESC *desc, ID3D10Predicate **predicate)
1362 {
1363     FIXME("iface %p, desc %p, predicate %p stub!\n", iface, desc, predicate);
1364
1365     return E_NOTIMPL;
1366 }
1367
1368 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateCounter(ID3D10Device *iface,
1369         const D3D10_COUNTER_DESC *desc, ID3D10Counter **counter)
1370 {
1371     FIXME("iface %p, desc %p, counter %p stub!\n", iface, desc, counter);
1372
1373     return E_NOTIMPL;
1374 }
1375
1376 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckFormatSupport(ID3D10Device *iface,
1377         DXGI_FORMAT format, UINT *format_support)
1378 {
1379     FIXME("iface %p, format %s, format_support %p stub!\n",
1380             iface, debug_dxgi_format(format), format_support);
1381
1382     return E_NOTIMPL;
1383 }
1384
1385 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckMultisampleQualityLevels(ID3D10Device *iface,
1386         DXGI_FORMAT format, UINT sample_count, UINT *quality_level_count)
1387 {
1388     FIXME("iface %p, format %s, sample_count %u, quality_level_count %p stub!\n",
1389             iface, debug_dxgi_format(format), sample_count, quality_level_count);
1390
1391     return E_NOTIMPL;
1392 }
1393
1394 static void STDMETHODCALLTYPE d3d10_device_CheckCounterInfo(ID3D10Device *iface, D3D10_COUNTER_INFO *counter_info)
1395 {
1396     FIXME("iface %p, counter_info %p stub!\n", iface, counter_info);
1397 }
1398
1399 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckCounter(ID3D10Device *iface,
1400         const D3D10_COUNTER_DESC *desc, D3D10_COUNTER_TYPE *type, UINT *active_counters, LPSTR name,
1401         UINT *name_length, LPSTR units, UINT *units_length, LPSTR description, UINT *description_length)
1402 {
1403     FIXME("iface %p, desc %p, type %p, active_counters %p, name %p, name_length %p,\n"
1404             "\tunits %p, units_length %p, description %p, description_length %p stub!\n",
1405             iface, desc, type, active_counters, name, name_length,
1406             units, units_length, description, description_length);
1407
1408     return E_NOTIMPL;
1409 }
1410
1411 static UINT STDMETHODCALLTYPE d3d10_device_GetCreationFlags(ID3D10Device *iface)
1412 {
1413     FIXME("iface %p stub!\n", iface);
1414
1415     return 0;
1416 }
1417
1418 static HRESULT STDMETHODCALLTYPE d3d10_device_OpenSharedResource(ID3D10Device *iface,
1419         HANDLE resource_handle, REFIID guid, void **resource)
1420 {
1421     FIXME("iface %p, resource_handle %p, guid %s, resource %p stub!\n",
1422             iface, resource_handle, debugstr_guid(guid), resource);
1423
1424     return E_NOTIMPL;
1425 }
1426
1427 static void STDMETHODCALLTYPE d3d10_device_SetTextFilterSize(ID3D10Device *iface, UINT width, UINT height)
1428 {
1429     FIXME("iface %p, width %u, height %u stub!\n", iface, width, height);
1430 }
1431
1432 static void STDMETHODCALLTYPE d3d10_device_GetTextFilterSize(ID3D10Device *iface, UINT *width, UINT *height)
1433 {
1434     FIXME("iface %p, width %p, height %p stub!\n", iface, width, height);
1435 }
1436
1437 static const struct ID3D10DeviceVtbl d3d10_device_vtbl =
1438 {
1439     /* IUnknown methods */
1440     d3d10_device_QueryInterface,
1441     d3d10_device_AddRef,
1442     d3d10_device_Release,
1443     /* ID3D10Device methods */
1444     d3d10_device_VSSetConstantBuffers,
1445     d3d10_device_PSSetShaderResources,
1446     d3d10_device_PSSetShader,
1447     d3d10_device_PSSetSamplers,
1448     d3d10_device_VSSetShader,
1449     d3d10_device_DrawIndexed,
1450     d3d10_device_Draw,
1451     d3d10_device_PSSetConstantBuffers,
1452     d3d10_device_IASetInputLayout,
1453     d3d10_device_IASetVertexBuffers,
1454     d3d10_device_IASetIndexBuffer,
1455     d3d10_device_DrawIndexedInstanced,
1456     d3d10_device_DrawInstanced,
1457     d3d10_device_GSSetConstantBuffers,
1458     d3d10_device_GSSetShader,
1459     d3d10_device_IASetPrimitiveTopology,
1460     d3d10_device_VSSetShaderResources,
1461     d3d10_device_VSSetSamplers,
1462     d3d10_device_SetPredication,
1463     d3d10_device_GSSetShaderResources,
1464     d3d10_device_GSSetSamplers,
1465     d3d10_device_OMSetRenderTargets,
1466     d3d10_device_OMSetBlendState,
1467     d3d10_device_OMSetDepthStencilState,
1468     d3d10_device_SOSetTargets,
1469     d3d10_device_DrawAuto,
1470     d3d10_device_RSSetState,
1471     d3d10_device_RSSetViewports,
1472     d3d10_device_RSSetScissorRects,
1473     d3d10_device_CopySubresourceRegion,
1474     d3d10_device_CopyResource,
1475     d3d10_device_UpdateSubresource,
1476     d3d10_device_ClearRenderTargetView,
1477     d3d10_device_ClearDepthStencilView,
1478     d3d10_device_GenerateMips,
1479     d3d10_device_ResolveSubresource,
1480     d3d10_device_VSGetConstantBuffers,
1481     d3d10_device_PSGetShaderResources,
1482     d3d10_device_PSGetShader,
1483     d3d10_device_PSGetSamplers,
1484     d3d10_device_VSGetShader,
1485     d3d10_device_PSGetConstantBuffers,
1486     d3d10_device_IAGetInputLayout,
1487     d3d10_device_IAGetVertexBuffers,
1488     d3d10_device_IAGetIndexBuffer,
1489     d3d10_device_GSGetConstantBuffers,
1490     d3d10_device_GSGetShader,
1491     d3d10_device_IAGetPrimitiveTopology,
1492     d3d10_device_VSGetShaderResources,
1493     d3d10_device_VSGetSamplers,
1494     d3d10_device_GetPredication,
1495     d3d10_device_GSGetShaderResources,
1496     d3d10_device_GSGetSamplers,
1497     d3d10_device_OMGetRenderTargets,
1498     d3d10_device_OMGetBlendState,
1499     d3d10_device_OMGetDepthStencilState,
1500     d3d10_device_SOGetTargets,
1501     d3d10_device_RSGetState,
1502     d3d10_device_RSGetViewports,
1503     d3d10_device_RSGetScissorRects,
1504     d3d10_device_GetDeviceRemovedReason,
1505     d3d10_device_SetExceptionMode,
1506     d3d10_device_GetExceptionMode,
1507     d3d10_device_GetPrivateData,
1508     d3d10_device_SetPrivateData,
1509     d3d10_device_SetPrivateDataInterface,
1510     d3d10_device_ClearState,
1511     d3d10_device_Flush,
1512     d3d10_device_CreateBuffer,
1513     d3d10_device_CreateTexture1D,
1514     d3d10_device_CreateTexture2D,
1515     d3d10_device_CreateTexture3D,
1516     d3d10_device_CreateShaderResourceView,
1517     d3d10_device_CreateRenderTargetView,
1518     d3d10_device_CreateDepthStencilView,
1519     d3d10_device_CreateInputLayout,
1520     d3d10_device_CreateVertexShader,
1521     d3d10_device_CreateGeometryShader,
1522     d3d10_device_CreateGeometryShaderWithStreamOutput,
1523     d3d10_device_CreatePixelShader,
1524     d3d10_device_CreateBlendState,
1525     d3d10_device_CreateDepthStencilState,
1526     d3d10_device_CreateRasterizerState,
1527     d3d10_device_CreateSamplerState,
1528     d3d10_device_CreateQuery,
1529     d3d10_device_CreatePredicate,
1530     d3d10_device_CreateCounter,
1531     d3d10_device_CheckFormatSupport,
1532     d3d10_device_CheckMultisampleQualityLevels,
1533     d3d10_device_CheckCounterInfo,
1534     d3d10_device_CheckCounter,
1535     d3d10_device_GetCreationFlags,
1536     d3d10_device_OpenSharedResource,
1537     d3d10_device_SetTextFilterSize,
1538     d3d10_device_GetTextFilterSize,
1539 };
1540
1541 static const struct IUnknownVtbl d3d10_device_inner_unknown_vtbl =
1542 {
1543     /* IUnknown methods */
1544     d3d10_device_inner_QueryInterface,
1545     d3d10_device_inner_AddRef,
1546     d3d10_device_inner_Release,
1547 };
1548
1549 static void STDMETHODCALLTYPE d3d10_subresource_destroyed(void *parent) {}
1550
1551 static const struct wined3d_parent_ops d3d10_subresource_parent_ops =
1552 {
1553     d3d10_subresource_destroyed,
1554 };
1555
1556 /* IWineDXGIDeviceParent IUnknown methods */
1557
1558 static inline struct d3d10_device *device_from_dxgi_device_parent(IWineDXGIDeviceParent *iface)
1559 {
1560     return CONTAINING_RECORD(iface, struct d3d10_device, IWineDXGIDeviceParent_iface);
1561 }
1562
1563 static HRESULT STDMETHODCALLTYPE dxgi_device_parent_QueryInterface(IWineDXGIDeviceParent *iface,
1564         REFIID riid, void **ppv)
1565 {
1566     struct d3d10_device *device = device_from_dxgi_device_parent(iface);
1567     return IUnknown_QueryInterface(device->outer_unk, riid, ppv);
1568 }
1569
1570 static ULONG STDMETHODCALLTYPE dxgi_device_parent_AddRef(IWineDXGIDeviceParent *iface)
1571 {
1572     struct d3d10_device *device = device_from_dxgi_device_parent(iface);
1573     return IUnknown_AddRef(device->outer_unk);
1574 }
1575
1576 static ULONG STDMETHODCALLTYPE dxgi_device_parent_Release(IWineDXGIDeviceParent *iface)
1577 {
1578     struct d3d10_device *device = device_from_dxgi_device_parent(iface);
1579     return IUnknown_Release(device->outer_unk);
1580 }
1581
1582 static struct wined3d_device_parent * STDMETHODCALLTYPE dxgi_device_parent_get_wined3d_device_parent(
1583         IWineDXGIDeviceParent *iface)
1584 {
1585     struct d3d10_device *device = device_from_dxgi_device_parent(iface);
1586     return &device->device_parent;
1587 }
1588
1589 static const struct IWineDXGIDeviceParentVtbl d3d10_dxgi_device_parent_vtbl =
1590 {
1591     /* IUnknown methods */
1592     dxgi_device_parent_QueryInterface,
1593     dxgi_device_parent_AddRef,
1594     dxgi_device_parent_Release,
1595     /* IWineDXGIDeviceParent methods */
1596     dxgi_device_parent_get_wined3d_device_parent,
1597 };
1598
1599 static inline struct d3d10_device *device_from_wined3d_device_parent(struct wined3d_device_parent *device_parent)
1600 {
1601     return CONTAINING_RECORD(device_parent, struct d3d10_device, device_parent);
1602 }
1603
1604 static void CDECL device_parent_wined3d_device_created(struct wined3d_device_parent *device_parent,
1605         struct wined3d_device *wined3d_device)
1606 {
1607     struct d3d10_device *device = device_from_wined3d_device_parent(device_parent);
1608
1609     TRACE("device_parent %p, wined3d_device %p.\n", device_parent, wined3d_device);
1610
1611     wined3d_device_incref(wined3d_device);
1612     device->wined3d_device = wined3d_device;
1613 }
1614
1615 static void CDECL device_parent_mode_changed(struct wined3d_device_parent *device_parent)
1616 {
1617     TRACE("device_parent %p.\n", device_parent);
1618 }
1619
1620 static HRESULT CDECL device_parent_create_texture_surface(struct wined3d_device_parent *device_parent,
1621         void *container_parent, UINT width, UINT height, enum wined3d_format_id format, DWORD usage,
1622         enum wined3d_pool pool, UINT sub_resource_idx, struct wined3d_surface **surface)
1623 {
1624     struct d3d10_device *device = device_from_wined3d_device_parent(device_parent);
1625
1626     TRACE("device_parent %p, container_parent %p, width %u, height %u, format %#x, usage %#x,\n"
1627             "\tpool %#x, sub_resource_idx %u, surface %p.\n",
1628             device_parent, container_parent, width, height, format, usage, pool, sub_resource_idx, surface);
1629
1630     return wined3d_surface_create(device->wined3d_device, width, height, format, usage, pool,
1631             WINED3D_MULTISAMPLE_NONE, 0, WINED3D_SURFACE_TYPE_OPENGL, 0, container_parent,
1632             &d3d10_null_wined3d_parent_ops, surface);
1633 }
1634
1635 static HRESULT CDECL device_parent_create_swapchain_surface(struct wined3d_device_parent *device_parent,
1636         void *container_parent, UINT width, UINT height, enum wined3d_format_id format_id, DWORD usage,
1637         enum wined3d_multisample_type multisample_type, DWORD multisample_quality, struct wined3d_surface **surface)
1638 {
1639     struct d3d10_device *device = device_from_wined3d_device_parent(device_parent);
1640     struct wined3d_resource *sub_resource;
1641     struct d3d10_texture2d *texture;
1642     D3D10_TEXTURE2D_DESC desc;
1643     HRESULT hr;
1644
1645     FIXME("device_parent %p, container_parent %p, width %u, height %u, format_id %#x, usage %#x,\n"
1646             "\tmultisample_type %#x, multisample_quality %u, surface %p partial stub!\n",
1647             device_parent, container_parent, width, height, format_id, usage,
1648             multisample_type, multisample_quality, surface);
1649
1650     FIXME("Implement DXGI<->wined3d usage conversion\n");
1651
1652     desc.Width = width;
1653     desc.Height = height;
1654     desc.MipLevels = 1;
1655     desc.ArraySize = 1;
1656     desc.Format = dxgi_format_from_wined3dformat(format_id);
1657     desc.SampleDesc.Count = multisample_type ? multisample_type : 1;
1658     desc.SampleDesc.Quality = multisample_quality;
1659     desc.Usage = D3D10_USAGE_DEFAULT;
1660     desc.BindFlags = D3D10_BIND_RENDER_TARGET;
1661     desc.CPUAccessFlags = 0;
1662     desc.MiscFlags = 0;
1663
1664     hr = d3d10_device_CreateTexture2D(&device->ID3D10Device_iface, &desc, NULL,
1665             (ID3D10Texture2D **)&texture);
1666     if (FAILED(hr))
1667     {
1668         ERR("CreateTexture2D failed, returning %#x\n", hr);
1669         return hr;
1670     }
1671
1672     sub_resource = wined3d_texture_get_sub_resource(texture->wined3d_texture, 0);
1673     *surface = wined3d_surface_from_resource(sub_resource);
1674     wined3d_surface_incref(*surface);
1675     ID3D10Texture2D_Release(&texture->ID3D10Texture2D_iface);
1676
1677     return S_OK;
1678 }
1679
1680 static HRESULT CDECL device_parent_create_volume(struct wined3d_device_parent *device_parent,
1681         void *container_parent, UINT width, UINT height, UINT depth, enum wined3d_format_id format,
1682         enum wined3d_pool pool, DWORD usage, struct wined3d_volume **volume)
1683 {
1684     HRESULT hr;
1685
1686     TRACE("device_parent %p, container_parent %p, width %u, height %u, depth %u, "
1687             "format %#x, pool %#x, usage %#x, volume %p.\n",
1688             device_parent, container_parent, width, height, depth,
1689             format, pool, usage, volume);
1690
1691     hr = wined3d_volume_create(device_from_wined3d_device_parent(device_parent)->wined3d_device,
1692             width, height, depth, usage, format, pool, NULL, &d3d10_subresource_parent_ops, volume);
1693     if (FAILED(hr))
1694     {
1695         WARN("Failed to create wined3d volume, hr %#x.\n", hr);
1696         return hr;
1697     }
1698
1699     return S_OK;
1700 }
1701
1702 static HRESULT CDECL device_parent_create_swapchain(struct wined3d_device_parent *device_parent,
1703         struct wined3d_swapchain_desc *desc, struct wined3d_swapchain **swapchain)
1704 {
1705     struct d3d10_device *device = device_from_wined3d_device_parent(device_parent);
1706     IWineDXGIDevice *wine_device;
1707     HRESULT hr;
1708
1709     TRACE("device_parent %p, desc %p, swapchain %p\n", device_parent, desc, swapchain);
1710
1711     hr = d3d10_device_QueryInterface(&device->ID3D10Device_iface, &IID_IWineDXGIDevice,
1712             (void **)&wine_device);
1713     if (FAILED(hr))
1714     {
1715         ERR("Device should implement IWineDXGIDevice\n");
1716         return E_FAIL;
1717     }
1718
1719     hr = IWineDXGIDevice_create_swapchain(wine_device, desc, swapchain);
1720     IWineDXGIDevice_Release(wine_device);
1721     if (FAILED(hr))
1722     {
1723         ERR("Failed to create DXGI swapchain, returning %#x\n", hr);
1724         return hr;
1725     }
1726
1727     return S_OK;
1728 }
1729
1730 static const struct wined3d_device_parent_ops d3d10_wined3d_device_parent_ops =
1731 {
1732     device_parent_wined3d_device_created,
1733     device_parent_mode_changed,
1734     device_parent_create_swapchain_surface,
1735     device_parent_create_texture_surface,
1736     device_parent_create_volume,
1737     device_parent_create_swapchain,
1738 };
1739
1740 void d3d10_device_init(struct d3d10_device *device, void *outer_unknown)
1741 {
1742     device->ID3D10Device_iface.lpVtbl = &d3d10_device_vtbl;
1743     device->IUnknown_inner.lpVtbl = &d3d10_device_inner_unknown_vtbl;
1744     device->IWineDXGIDeviceParent_iface.lpVtbl = &d3d10_dxgi_device_parent_vtbl;
1745     device->device_parent.ops = &d3d10_wined3d_device_parent_ops;
1746     device->refcount = 1;
1747     /* COM aggregation always takes place */
1748     device->outer_unk = outer_unknown;
1749 }