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