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