ntdll: Tweak the file mapping permission checks some more, with tests.
[wine] / dlls / d3d10core / device.c
1 /*
2  * Copyright 2008-2009 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 /* Inner IUnknown methods */
28
29 static inline struct d3d10_device *d3d10_device_from_inner_unknown(IUnknown *iface)
30 {
31     return (struct d3d10_device *)((char*)iface - FIELD_OFFSET(struct d3d10_device, inner_unknown_vtbl));
32 }
33
34 static HRESULT STDMETHODCALLTYPE d3d10_device_inner_QueryInterface(IUnknown *iface, REFIID riid, void **object)
35 {
36     struct d3d10_device *This = d3d10_device_from_inner_unknown(iface);
37
38     TRACE("iface %p, riid %s, object %p\n", iface, debugstr_guid(riid), object);
39
40     if (IsEqualGUID(riid, &IID_IUnknown)
41             || IsEqualGUID(riid, &IID_ID3D10Device))
42     {
43         IUnknown_AddRef((IUnknown *)This);
44         *object = This;
45         return S_OK;
46     }
47
48     if (IsEqualGUID(riid, &IID_IWineD3DDeviceParent))
49     {
50         IUnknown_AddRef((IUnknown *)&This->device_parent_vtbl);
51         *object = &This->device_parent_vtbl;
52         return S_OK;
53     }
54
55     WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid));
56
57     *object = NULL;
58     return E_NOINTERFACE;
59 }
60
61 static ULONG STDMETHODCALLTYPE d3d10_device_inner_AddRef(IUnknown *iface)
62 {
63     struct d3d10_device *This = d3d10_device_from_inner_unknown(iface);
64     ULONG refcount = InterlockedIncrement(&This->refcount);
65
66     TRACE("%p increasing refcount to %u\n", This, refcount);
67
68     return refcount;
69 }
70
71 static ULONG STDMETHODCALLTYPE d3d10_device_inner_Release(IUnknown *iface)
72 {
73     struct d3d10_device *This = d3d10_device_from_inner_unknown(iface);
74     ULONG refcount = InterlockedDecrement(&This->refcount);
75
76     TRACE("%p decreasing refcount to %u\n", This, refcount);
77
78     if (!refcount)
79     {
80         if (This->wined3d_device) IWineD3DDevice_Release(This->wined3d_device);
81     }
82
83     return refcount;
84 }
85
86 /* IUnknown methods */
87
88 static HRESULT STDMETHODCALLTYPE d3d10_device_QueryInterface(ID3D10Device *iface, REFIID riid, void **object)
89 {
90     struct d3d10_device *This = (struct d3d10_device *)iface;
91     TRACE("Forwarding to outer IUnknown\n");
92     return IUnknown_QueryInterface(This->outer_unknown, riid, object);
93 }
94
95 static ULONG STDMETHODCALLTYPE d3d10_device_AddRef(ID3D10Device *iface)
96 {
97     struct d3d10_device *This = (struct d3d10_device *)iface;
98     TRACE("Forwarding to outer IUnknown\n");
99     return IUnknown_AddRef(This->outer_unknown);
100 }
101
102 static ULONG STDMETHODCALLTYPE d3d10_device_Release(ID3D10Device *iface)
103 {
104     struct d3d10_device *This = (struct d3d10_device *)iface;
105     TRACE("Forwarding to outer IUnknown\n");
106     return IUnknown_Release(This->outer_unknown);
107 }
108
109 /* ID3D10Device methods */
110
111 static void STDMETHODCALLTYPE d3d10_device_VSSetConstantBuffers(ID3D10Device *iface,
112         UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
113 {
114     FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p stub!\n",
115             iface, start_slot, buffer_count, buffers);
116 }
117
118 static void STDMETHODCALLTYPE d3d10_device_PSSetShaderResources(ID3D10Device *iface,
119         UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
120 {
121     FIXME("iface %p, start_slot %u, view_count %u, views %p stub!\n",
122             iface, start_slot, view_count, views);
123 }
124
125 static void STDMETHODCALLTYPE d3d10_device_PSSetShader(ID3D10Device *iface, ID3D10PixelShader *shader)
126 {
127     struct d3d10_device *This = (struct d3d10_device *)iface;
128     struct d3d10_pixel_shader *ps = (struct d3d10_pixel_shader *)shader;
129
130     TRACE("iface %p, shader %p\n", iface, shader);
131
132     IWineD3DDevice_SetPixelShader(This->wined3d_device, ps ? ps->wined3d_shader : NULL);
133 }
134
135 static void STDMETHODCALLTYPE d3d10_device_PSSetSamplers(ID3D10Device *iface,
136         UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
137 {
138     FIXME("iface %p, start_slot %u, sampler_count %u, samplers %p stub!\n",
139             iface, start_slot, sampler_count, samplers);
140 }
141
142 static void STDMETHODCALLTYPE d3d10_device_VSSetShader(ID3D10Device *iface, ID3D10VertexShader *shader)
143 {
144     FIXME("iface %p, shader %p stub!\n", iface, shader);
145 }
146
147 static void STDMETHODCALLTYPE d3d10_device_DrawIndexed(ID3D10Device *iface,
148         UINT index_count, UINT start_index_location, INT base_vertex_location)
149 {
150     FIXME("iface %p, index_count %u, start_index_location %u, base_vertex_location %d stub!\n",
151             iface, index_count, start_index_location, base_vertex_location);
152 }
153
154 static void STDMETHODCALLTYPE d3d10_device_Draw(ID3D10Device *iface,
155         UINT vertex_count, UINT start_vertex_location)
156 {
157     struct d3d10_device *This = (struct d3d10_device *)iface;
158
159     TRACE("iface %p, vertex_count %u, start_vertex_location %u\n",
160             iface, vertex_count, start_vertex_location);
161
162     IWineD3DDevice_DrawPrimitive(This->wined3d_device, start_vertex_location, vertex_count);
163 }
164
165 static void STDMETHODCALLTYPE d3d10_device_PSSetConstantBuffers(ID3D10Device *iface,
166         UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
167 {
168     FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p stub!\n",
169             iface, start_slot, buffer_count, buffers);
170 }
171
172 static void STDMETHODCALLTYPE d3d10_device_IASetInputLayout(ID3D10Device *iface, ID3D10InputLayout *input_layout)
173 {
174     struct d3d10_device *This = (struct d3d10_device *)iface;
175
176     TRACE("iface %p, input_layout %p\n", iface, input_layout);
177
178     IWineD3DDevice_SetVertexDeclaration(This->wined3d_device,
179             ((struct d3d10_input_layout *)input_layout)->wined3d_decl);
180 }
181
182 static void STDMETHODCALLTYPE d3d10_device_IASetVertexBuffers(ID3D10Device *iface,
183         UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers,
184         const UINT *strides, const UINT *offsets)
185 {
186     struct d3d10_device *This = (struct d3d10_device *)iface;
187     unsigned int i;
188
189     TRACE("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p\n",
190             iface, start_slot, buffer_count, buffers, strides, offsets);
191
192     for (i = 0; i < buffer_count; ++i)
193     {
194         IWineD3DDevice_SetStreamSource(This->wined3d_device, start_slot,
195                 ((struct d3d10_buffer *)buffers[i])->wined3d_buffer, offsets[i], strides[i]);
196     }
197 }
198
199 static void STDMETHODCALLTYPE d3d10_device_IASetIndexBuffer(ID3D10Device *iface,
200         ID3D10Buffer *buffer, DXGI_FORMAT format, UINT offset)
201 {
202     FIXME("iface %p, buffer %p, format %s, offset %u stub!\n",
203             iface, buffer, debug_dxgi_format(format), offset);
204 }
205
206 static void STDMETHODCALLTYPE d3d10_device_DrawIndexedInstanced(ID3D10Device *iface,
207         UINT instance_index_count, UINT instance_count, UINT start_index_location,
208         INT base_vertex_location, UINT start_instance_location)
209 {
210     FIXME("iface %p, instance_index_count %u, instance_count %u, start_index_location %u,\n"
211             "\tbase_vertex_location %d, start_instance_location %u stub!\n",
212             iface, instance_index_count, instance_count, start_index_location,
213             base_vertex_location, start_instance_location);
214 }
215
216 static void STDMETHODCALLTYPE d3d10_device_DrawInstanced(ID3D10Device *iface,
217         UINT instance_vertex_count, UINT instance_count,
218         UINT start_vertex_location, UINT start_instance_location)
219 {
220     FIXME("iface %p, instance_vertex_count %u, instance_count %u, start_vertex_location %u,\n"
221             "\tstart_instance_location %u stub!\n", iface, instance_vertex_count, instance_count,
222             start_vertex_location, start_instance_location);
223 }
224
225 static void STDMETHODCALLTYPE d3d10_device_GSSetConstantBuffers(ID3D10Device *iface,
226         UINT start_slot, UINT buffer_count, ID3D10Buffer *const *buffers)
227 {
228     FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p stub!\n",
229             iface, start_slot, buffer_count, buffers);
230 }
231
232 static void STDMETHODCALLTYPE d3d10_device_GSSetShader(ID3D10Device *iface, ID3D10GeometryShader *shader)
233 {
234     FIXME("iface %p, shader %p stub!\n", iface, shader);
235 }
236
237 static void STDMETHODCALLTYPE d3d10_device_IASetPrimitiveTopology(ID3D10Device *iface, D3D10_PRIMITIVE_TOPOLOGY topology)
238 {
239     struct d3d10_device *This = (struct d3d10_device *)iface;
240
241     TRACE("iface %p, topology %s\n", iface, debug_d3d10_primitive_topology(topology));
242
243     IWineD3DDevice_SetPrimitiveType(This->wined3d_device, (WINED3DPRIMITIVETYPE)topology);
244 }
245
246 static void STDMETHODCALLTYPE d3d10_device_VSSetShaderResources(ID3D10Device *iface,
247         UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
248 {
249     FIXME("iface %p, start_slot %u, view_count %u, views %p stub!\n",
250             iface, start_slot, view_count, views);
251 }
252
253 static void STDMETHODCALLTYPE d3d10_device_VSSetSamplers(ID3D10Device *iface,
254         UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
255 {
256     FIXME("iface %p, start_slot %u, sampler_count %u, samplers %p stub!\n",
257             iface, start_slot, sampler_count, samplers);
258 }
259
260 static void STDMETHODCALLTYPE d3d10_device_SetPredication(ID3D10Device *iface, ID3D10Predicate *predicate, BOOL value)
261 {
262     FIXME("iface %p, predicate %p, value %d stub!\n", iface, predicate, value);
263 }
264
265 static void STDMETHODCALLTYPE d3d10_device_GSSetShaderResources(ID3D10Device *iface,
266         UINT start_slot, UINT view_count, ID3D10ShaderResourceView *const *views)
267 {
268     FIXME("iface %p, start_slot %u, view_count %u, views %p stub!\n",
269             iface, start_slot, view_count, views);
270 }
271
272 static void STDMETHODCALLTYPE d3d10_device_GSSetSamplers(ID3D10Device *iface,
273         UINT start_slot, UINT sampler_count, ID3D10SamplerState *const *samplers)
274 {
275     FIXME("iface %p, start_slot %u, sampler_count %u, samplers %p stub!\n",
276             iface, start_slot, sampler_count, samplers);
277 }
278
279 static void STDMETHODCALLTYPE d3d10_device_OMSetRenderTargets(ID3D10Device *iface,
280         UINT render_target_view_count, ID3D10RenderTargetView *const *render_target_views,
281         ID3D10DepthStencilView *depth_stencil_view)
282 {
283     FIXME("iface %p, render_target_view_count %u, render_target_views %p, depth_stencil_view %p\n",
284             iface, render_target_view_count, render_target_views, depth_stencil_view);
285 }
286
287 static void STDMETHODCALLTYPE d3d10_device_OMSetBlendState(ID3D10Device *iface,
288         ID3D10BlendState *blend_state, const FLOAT blend_factor[4], UINT sample_mask)
289 {
290     FIXME("iface %p, blend_state %p, blend_factor [%f %f %f %f], sample_mask 0x%08x stub!\n",
291             iface, blend_state, blend_factor[0], blend_factor[1], blend_factor[2], blend_factor[3], sample_mask);
292 }
293
294 static void STDMETHODCALLTYPE d3d10_device_OMSetDepthStencilState(ID3D10Device *iface,
295         ID3D10DepthStencilState *depth_stencil_state, UINT stencil_ref)
296 {
297     FIXME("iface %p, depth_stencil_state %p, stencil_ref %u stub!\n",
298             iface, depth_stencil_state, stencil_ref);
299 }
300
301 static void STDMETHODCALLTYPE d3d10_device_SOSetTargets(ID3D10Device *iface,
302         UINT target_count, ID3D10Buffer *const *targets, const UINT *offsets)
303 {
304     FIXME("iface %p, target_count %u, targets %p, offsets %p stub!\n", iface, target_count, targets, offsets);
305 }
306
307 static void STDMETHODCALLTYPE d3d10_device_DrawAuto(ID3D10Device *iface)
308 {
309     FIXME("iface %p stub!\n", iface);
310 }
311
312 static void STDMETHODCALLTYPE d3d10_device_RSSetState(ID3D10Device *iface, ID3D10RasterizerState *rasterizer_state)
313 {
314     FIXME("iface %p, rasterizer_state %p stub!\n", iface, rasterizer_state);
315 }
316
317 static void STDMETHODCALLTYPE d3d10_device_RSSetViewports(ID3D10Device *iface,
318         UINT viewport_count, const D3D10_VIEWPORT *viewports)
319 {
320     FIXME("iface %p, viewport_count %u, viewports %p stub!\n", iface, viewport_count, viewports);
321 }
322
323 static void STDMETHODCALLTYPE d3d10_device_RSSetScissorRects(ID3D10Device *iface,
324         UINT rect_count, const D3D10_RECT *rects)
325 {
326     FIXME("iface %p, rect_count %u, rects %p\n", iface, rect_count, rects);
327 }
328
329 static void STDMETHODCALLTYPE d3d10_device_CopySubresourceRegion(ID3D10Device *iface,
330         ID3D10Resource *dst_resource, UINT dst_subresource_idx, UINT dst_x, UINT dst_y, UINT dst_z,
331         ID3D10Resource *src_resource, UINT src_subresource_idx, const D3D10_BOX *src_box)
332 {
333     FIXME("iface %p, dst_resource %p, dst_subresource_idx %u, dst_x %u, dst_y %u, dst_z %u,\n"
334             "\tsrc_resource %p, src_subresource_idx %u, src_box %p stub!\n",
335             iface, dst_resource, dst_subresource_idx, dst_x, dst_y, dst_z,
336             src_resource, src_subresource_idx, src_box);
337 }
338
339 static void STDMETHODCALLTYPE d3d10_device_CopyResource(ID3D10Device *iface,
340         ID3D10Resource *dst_resource, ID3D10Resource *src_resource)
341 {
342     FIXME("iface %p, dst_resource %p, src_resource %p stub!\n", iface, dst_resource, src_resource);
343 }
344
345 static void STDMETHODCALLTYPE d3d10_device_UpdateSubresource(ID3D10Device *iface,
346         ID3D10Resource *resource, UINT subresource_idx, const D3D10_BOX *box,
347         const void *data, UINT row_pitch, UINT depth_pitch)
348 {
349     FIXME("iface %p, resource %p, subresource_idx %u, box %p, data %p, row_pitch %u, depth_pitch %u stub!\n",
350             iface, resource, subresource_idx, box, data, row_pitch, depth_pitch);
351 }
352
353 static void STDMETHODCALLTYPE d3d10_device_ClearRenderTargetView(ID3D10Device *iface,
354         ID3D10RenderTargetView *render_target_view, const FLOAT color_rgba[4])
355 {
356     struct d3d10_device *This = (struct d3d10_device *)iface;
357     IWineD3DRendertargetView *wined3d_view = ((struct d3d10_rendertarget_view *)render_target_view)->wined3d_view;
358
359     TRACE("iface %p, render_target_view %p, color_rgba [%f %f %f %f]\n",
360             iface, render_target_view, color_rgba[0], color_rgba[1], color_rgba[2], color_rgba[3]);
361
362     IWineD3DDevice_ClearRendertargetView(This->wined3d_device, wined3d_view, color_rgba);
363 }
364
365 static void STDMETHODCALLTYPE d3d10_device_ClearDepthStencilView(ID3D10Device *iface,
366         ID3D10DepthStencilView *depth_stencil_view, UINT flags, FLOAT depth, UINT8 stencil)
367 {
368     FIXME("iface %p, depth_stencil_view %p, flags %#x, depth %f, stencil %u stub!\n",
369             iface, depth_stencil_view, flags, depth, stencil);
370 }
371
372 static void STDMETHODCALLTYPE d3d10_device_GenerateMips(ID3D10Device *iface, ID3D10ShaderResourceView *shader_resource_view)
373 {
374     FIXME("iface %p, shader_resource_view %p stub!\n", iface, shader_resource_view);
375 }
376
377 static void STDMETHODCALLTYPE d3d10_device_ResolveSubresource(ID3D10Device *iface,
378         ID3D10Resource *dst_resource, UINT dst_subresource_idx,
379         ID3D10Resource *src_resource, UINT src_subresource_idx, DXGI_FORMAT format)
380 {
381     FIXME("iface %p, dst_resource %p, dst_subresource_idx %u,\n"
382             "\tsrc_resource %p, src_subresource_idx %u, format %s stub!\n",
383             iface, dst_resource, dst_subresource_idx,
384             src_resource, src_subresource_idx, debug_dxgi_format(format));
385 }
386
387 static void STDMETHODCALLTYPE d3d10_device_VSGetConstantBuffers(ID3D10Device *iface,
388         UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
389 {
390     FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p stub!\n",
391             iface, start_slot, buffer_count, buffers);
392 }
393
394 static void STDMETHODCALLTYPE d3d10_device_PSGetShaderResources(ID3D10Device *iface,
395         UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
396 {
397     FIXME("iface %p, start_slot %u, view_count %u, views %p stub!\n",
398             iface, start_slot, view_count, views);
399 }
400
401 static void STDMETHODCALLTYPE d3d10_device_PSGetShader(ID3D10Device *iface, ID3D10PixelShader **shader)
402 {
403     FIXME("iface %p, shader %p stub!\n", iface, shader);
404 }
405
406 static void STDMETHODCALLTYPE d3d10_device_PSGetSamplers(ID3D10Device *iface,
407         UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
408 {
409     FIXME("iface %p, start_slot %u, sampler_count %u, samplers %p stub!\n",
410             iface, start_slot, sampler_count, samplers);
411 }
412
413 static void STDMETHODCALLTYPE d3d10_device_VSGetShader(ID3D10Device *iface, ID3D10VertexShader **shader)
414 {
415     FIXME("iface %p, shader %p stub!\n", iface, shader);
416 }
417
418 static void STDMETHODCALLTYPE d3d10_device_PSGetConstantBuffers(ID3D10Device *iface,
419         UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
420 {
421     FIXME("iface %p, start_slot %u, buffer_count %u, buffer %p stub!\n",
422             iface, start_slot, buffer_count, buffers);
423 }
424
425 static void STDMETHODCALLTYPE d3d10_device_IAGetInputLayout(ID3D10Device *iface, ID3D10InputLayout **input_layout)
426 {
427     FIXME("iface %p, input_layout %p stub!\n", iface, input_layout);
428 }
429
430 static void STDMETHODCALLTYPE d3d10_device_IAGetVertexBuffers(ID3D10Device *iface,
431         UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers, UINT *strides, UINT *offsets)
432 {
433     FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p, strides %p, offsets %p stub!\n",
434             iface, start_slot, buffer_count, buffers, strides, offsets);
435 }
436
437 static void STDMETHODCALLTYPE d3d10_device_IAGetIndexBuffer(ID3D10Device *iface,
438         ID3D10Buffer **buffer, DXGI_FORMAT *format, UINT *offset)
439 {
440     FIXME("iface %p, buffer %p, format %p, offset %p stub!\n", iface, buffer, format, offset);
441 }
442
443 static void STDMETHODCALLTYPE d3d10_device_GSGetConstantBuffers(ID3D10Device *iface,
444         UINT start_slot, UINT buffer_count, ID3D10Buffer **buffers)
445 {
446     FIXME("iface %p, start_slot %u, buffer_count %u, buffers %p stub!\n",
447             iface, start_slot, buffer_count, buffers);
448 }
449
450 static void STDMETHODCALLTYPE d3d10_device_GSGetShader(ID3D10Device *iface, ID3D10GeometryShader **shader)
451 {
452     FIXME("iface %p, shader %p stub!\n", iface, shader);
453 }
454
455 static void STDMETHODCALLTYPE d3d10_device_IAGetPrimitiveTopology(ID3D10Device *iface, D3D10_PRIMITIVE_TOPOLOGY *topology)
456 {
457     struct d3d10_device *This = (struct d3d10_device *)iface;
458
459     TRACE("iface %p, topology %p\n", iface, topology);
460
461     IWineD3DDevice_GetPrimitiveType(This->wined3d_device, (WINED3DPRIMITIVETYPE *)topology);
462 }
463
464 static void STDMETHODCALLTYPE d3d10_device_VSGetShaderResources(ID3D10Device *iface,
465         UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
466 {
467     FIXME("iface %p, start_slot %u, view_count %u, views %p stub!\n",
468             iface, start_slot, view_count, views);
469 }
470
471 static void STDMETHODCALLTYPE d3d10_device_VSGetSamplers(ID3D10Device *iface,
472         UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
473 {
474     FIXME("iface %p, start_slot %u, sampler_count %u, samplers %p stub!\n",
475             iface, start_slot, sampler_count, samplers);
476 }
477
478 static void STDMETHODCALLTYPE d3d10_device_GetPredication(ID3D10Device *iface,
479         ID3D10Predicate **predicate, BOOL *value)
480 {
481     FIXME("iface %p, predicate %p, value %p stub!\n", iface, predicate, value);
482 }
483
484 static void STDMETHODCALLTYPE d3d10_device_GSGetShaderResources(ID3D10Device *iface,
485         UINT start_slot, UINT view_count, ID3D10ShaderResourceView **views)
486 {
487     FIXME("iface %p, start_slot %u, view_count %u, views %p stub!\n",
488             iface, start_slot, view_count, views);
489 }
490
491 static void STDMETHODCALLTYPE d3d10_device_GSGetSamplers(ID3D10Device *iface,
492         UINT start_slot, UINT sampler_count, ID3D10SamplerState **samplers)
493 {
494     FIXME("iface %p, start_slot %u, sampler_count %u, samplers %p stub!\n",
495             iface, start_slot, sampler_count, samplers);
496 }
497
498 static void STDMETHODCALLTYPE d3d10_device_OMGetRenderTargets(ID3D10Device *iface,
499         UINT view_count, ID3D10RenderTargetView **render_target_views, ID3D10DepthStencilView **depth_stencil_view)
500 {
501     FIXME("iface %p, view_count %u, render_target_views %p, depth_stencil_view %p stub!\n",
502             iface, view_count, render_target_views, depth_stencil_view);
503 }
504
505 static void STDMETHODCALLTYPE d3d10_device_OMGetBlendState(ID3D10Device *iface,
506         ID3D10BlendState **blend_state, FLOAT blend_factor[4], UINT *sample_mask)
507 {
508     FIXME("iface %p, blend_state %p, blend_factor %p, sample_mask %p stub!\n",
509             iface, blend_state, blend_factor, sample_mask);
510 }
511
512 static void STDMETHODCALLTYPE d3d10_device_OMGetDepthStencilState(ID3D10Device *iface,
513         ID3D10DepthStencilState **depth_stencil_state, UINT *stencil_ref)
514 {
515     FIXME("iface %p, depth_stencil_state %p, stencil_ref %p stub!\n",
516             iface, depth_stencil_state, stencil_ref);
517 }
518
519 static void STDMETHODCALLTYPE d3d10_device_SOGetTargets(ID3D10Device *iface,
520         UINT buffer_count, ID3D10Buffer **buffers, UINT *offsets)
521 {
522     FIXME("iface %p, buffer_count %u, buffers %p, offsets %p stub!\n",
523             iface, buffer_count, buffers, offsets);
524 }
525
526 static void STDMETHODCALLTYPE d3d10_device_RSGetState(ID3D10Device *iface, ID3D10RasterizerState **rasterizer_state)
527 {
528     FIXME("iface %p, rasterizer_state %p stub!\n", iface, rasterizer_state);
529 }
530
531 static void STDMETHODCALLTYPE d3d10_device_RSGetViewports(ID3D10Device *iface,
532         UINT *viewport_count, D3D10_VIEWPORT *viewports)
533 {
534     FIXME("iface %p, viewport_count %p, viewports %p stub!\n", iface, viewport_count, viewports);
535 }
536
537 static void STDMETHODCALLTYPE d3d10_device_RSGetScissorRects(ID3D10Device *iface, UINT *rect_count, D3D10_RECT *rects)
538 {
539     FIXME("iface %p, rect_count %p, rects %p stub!\n", iface, rect_count, rects);
540 }
541
542 static HRESULT STDMETHODCALLTYPE d3d10_device_GetDeviceRemovedReason(ID3D10Device *iface)
543 {
544     FIXME("iface %p stub!\n", iface);
545
546     return E_NOTIMPL;
547 }
548
549 static HRESULT STDMETHODCALLTYPE d3d10_device_SetExceptionMode(ID3D10Device *iface, UINT flags)
550 {
551     FIXME("iface %p, flags %#x stub!\n", iface, flags);
552
553     return E_NOTIMPL;
554 }
555
556 static UINT STDMETHODCALLTYPE d3d10_device_GetExceptionMode(ID3D10Device *iface)
557 {
558     FIXME("iface %p stub!\n", iface);
559
560     return 0;
561 }
562
563 static HRESULT STDMETHODCALLTYPE d3d10_device_GetPrivateData(ID3D10Device *iface,
564         REFGUID guid, UINT *data_size, void *data)
565 {
566     FIXME("iface %p, guid %s, data_size %p, data %p stub!\n",
567             iface, debugstr_guid(guid), data_size, data);
568
569     return E_NOTIMPL;
570 }
571
572 static HRESULT STDMETHODCALLTYPE d3d10_device_SetPrivateData(ID3D10Device *iface,
573         REFGUID guid, UINT data_size, const void *data)
574 {
575     FIXME("iface %p, guid %s, data_size %u, data %p stub!\n",
576             iface, debugstr_guid(guid), data_size, data);
577
578     return E_NOTIMPL;
579 }
580
581 static HRESULT STDMETHODCALLTYPE d3d10_device_SetPrivateDataInterface(ID3D10Device *iface,
582         REFGUID guid, const IUnknown *data)
583 {
584     FIXME("iface %p, guid %s, data %p stub!\n", iface, debugstr_guid(guid), data);
585
586     return E_NOTIMPL;
587 }
588
589 static void STDMETHODCALLTYPE d3d10_device_ClearState(ID3D10Device *iface)
590 {
591     FIXME("iface %p stub!\n", iface);
592 }
593
594 static void STDMETHODCALLTYPE d3d10_device_Flush(ID3D10Device *iface)
595 {
596     FIXME("iface %p stub!\n", iface);
597 }
598
599 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBuffer(ID3D10Device *iface,
600         const D3D10_BUFFER_DESC *desc, const D3D10_SUBRESOURCE_DATA *data, ID3D10Buffer **buffer)
601 {
602     struct d3d10_device *This = (struct d3d10_device *)iface;
603     struct wined3d_buffer_desc wined3d_desc;
604     struct d3d10_buffer *object;
605     HRESULT hr;
606
607     FIXME("iface %p, desc %p, data %p, buffer %p partial stub!\n", iface, desc, data, buffer);
608
609     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
610     if (!object)
611     {
612         ERR("Failed to allocate D3D10 buffer object memory\n");
613         return E_OUTOFMEMORY;
614     }
615
616     object->vtbl = &d3d10_buffer_vtbl;
617     object->refcount = 1;
618
619     FIXME("Implement DXGI<->wined3d usage conversion\n");
620
621     wined3d_desc.byte_width = desc->ByteWidth;
622     wined3d_desc.usage = desc->Usage;
623     wined3d_desc.bind_flags = desc->BindFlags;
624     wined3d_desc.cpu_access_flags = desc->CPUAccessFlags;
625     wined3d_desc.misc_flags = desc->MiscFlags;
626
627     hr = IWineD3DDevice_CreateBuffer(This->wined3d_device, &wined3d_desc,
628             data ? data->pSysMem : NULL, (IUnknown *)object, &object->wined3d_buffer);
629     if (FAILED(hr))
630     {
631         ERR("CreateBuffer failed, returning %#x\n", hr);
632         HeapFree(GetProcessHeap(), 0, object);
633         return hr;
634     }
635
636     *buffer = (ID3D10Buffer *)object;
637
638     TRACE("Created ID3D10Buffer %p\n", object);
639
640     return S_OK;
641 }
642
643 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture1D(ID3D10Device *iface,
644         const D3D10_TEXTURE1D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data, ID3D10Texture1D **texture)
645 {
646     FIXME("iface %p, desc %p, data %p, texture %p stub!\n", iface, desc, data, texture);
647
648     return E_NOTIMPL;
649 }
650
651 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture2D(ID3D10Device *iface,
652         const D3D10_TEXTURE2D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data, ID3D10Texture2D **texture)
653 {
654     struct d3d10_device *This = (struct d3d10_device *)iface;
655     struct d3d10_texture2d *object;
656     HRESULT hr;
657
658     FIXME("iface %p, desc %p, data %p, texture %p partial stub!\n", iface, desc, data, texture);
659
660     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
661     if (!object)
662     {
663         ERR("Failed to allocate D3D10 texture2d object memory\n");
664         return E_OUTOFMEMORY;
665     }
666
667     object->vtbl = &d3d10_texture2d_vtbl;
668     object->refcount = 1;
669     object->desc = *desc;
670
671     if (desc->MipLevels == 1 && desc->ArraySize == 1)
672     {
673         IWineDXGIDevice *wine_device;
674
675         hr = ID3D10Device_QueryInterface(iface, &IID_IWineDXGIDevice, (void **)&wine_device);
676         if (FAILED(hr))
677         {
678             ERR("Device should implement IWineDXGIDevice\n");
679             HeapFree(GetProcessHeap(), 0, object);
680             return E_FAIL;
681         }
682
683         hr = IWineDXGIDevice_create_surface(wine_device, NULL, 0, NULL,
684                 (IUnknown *)object, (void **)&object->dxgi_surface);
685         IWineDXGIDevice_Release(wine_device);
686         if (FAILED(hr))
687         {
688             ERR("Failed to create DXGI surface, returning %#x\n", hr);
689             HeapFree(GetProcessHeap(), 0, object);
690             return hr;
691         }
692
693         FIXME("Implement DXGI<->wined3d usage conversion\n");
694
695         hr = IWineD3DDevice_CreateSurface(This->wined3d_device, desc->Width, desc->Height,
696                 wined3dformat_from_dxgi_format(desc->Format), FALSE, FALSE, 0,
697                 &object->wined3d_surface, WINED3DRTYPE_SURFACE, desc->Usage, WINED3DPOOL_DEFAULT,
698                 desc->SampleDesc.Count > 1 ? desc->SampleDesc.Count : WINED3DMULTISAMPLE_NONE,
699                 desc->SampleDesc.Quality, SURFACE_OPENGL, (IUnknown *)object);
700         if (FAILED(hr))
701         {
702             ERR("CreateSurface failed, returning %#x\n", hr);
703             IDXGISurface_Release(object->dxgi_surface);
704             HeapFree(GetProcessHeap(), 0, object);
705             return hr;
706         }
707     }
708
709     *texture = (ID3D10Texture2D *)object;
710
711     TRACE("Created ID3D10Texture2D %p\n", object);
712
713     return S_OK;
714 }
715
716 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateTexture3D(ID3D10Device *iface,
717         const D3D10_TEXTURE3D_DESC *desc, const D3D10_SUBRESOURCE_DATA *data, ID3D10Texture3D **texture)
718 {
719     FIXME("iface %p, desc %p, data %p, texture %p stub!\n", iface, desc, data, texture);
720
721     return E_NOTIMPL;
722 }
723
724 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateShaderResourceView(ID3D10Device *iface,
725         ID3D10Resource *resource, const D3D10_SHADER_RESOURCE_VIEW_DESC *desc, ID3D10ShaderResourceView **view)
726 {
727     FIXME("iface %p, resource %p, desc %p, view %p stub!\n", iface, resource, desc, view);
728
729     return E_NOTIMPL;
730 }
731
732 static IWineD3DResource *d3d10_device_wined3d_resource_from_resource(ID3D10Resource *resource)
733 {
734     D3D10_RESOURCE_DIMENSION dimension;
735
736     ID3D10Resource_GetType(resource, &dimension);
737
738     switch(dimension)
739     {
740         case D3D10_RESOURCE_DIMENSION_BUFFER:
741             return (IWineD3DResource *)((struct d3d10_buffer *)resource)->wined3d_buffer;
742
743         case D3D10_RESOURCE_DIMENSION_TEXTURE2D:
744             return (IWineD3DResource *)((struct d3d10_texture2d *)resource)->wined3d_surface;
745
746         default:
747             FIXME("Unhandled resource dimension %#x\n", dimension);
748             return NULL;
749     }
750 }
751
752 static HRESULT d3d10_device_set_rtdesc_from_resource(D3D10_RENDER_TARGET_VIEW_DESC *desc, ID3D10Resource *resource)
753 {
754     D3D10_RESOURCE_DIMENSION dimension;
755     HRESULT hr;
756
757     ID3D10Resource_GetType(resource, &dimension);
758
759     switch(dimension)
760     {
761         case D3D10_RESOURCE_DIMENSION_TEXTURE1D:
762         {
763             ID3D10Texture1D *texture;
764             D3D10_TEXTURE1D_DESC texture_desc;
765
766             hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D10Texture1D, (void **)&texture);
767             if (FAILED(hr))
768             {
769                 ERR("Resource of type TEXTURE1D doesn't implement ID3D10Texture1D?\n");
770                 return E_INVALIDARG;
771             }
772
773             ID3D10Texture1D_GetDesc(texture, &texture_desc);
774             ID3D10Texture1D_Release(texture);
775
776             desc->Format = texture_desc.Format;
777             if (texture_desc.ArraySize == 1)
778             {
779                 desc->ViewDimension = D3D10_RTV_DIMENSION_TEXTURE1D;
780                 desc->Texture1D.MipSlice = 0;
781             }
782             else
783             {
784                 desc->ViewDimension = D3D10_RTV_DIMENSION_TEXTURE1DARRAY;
785                 desc->Texture1DArray.MipSlice = 0;
786                 desc->Texture1DArray.FirstArraySlice = 0;
787                 desc->Texture1DArray.ArraySize = 1;
788             }
789
790             return S_OK;
791         }
792
793         case D3D10_RESOURCE_DIMENSION_TEXTURE2D:
794         {
795             ID3D10Texture2D *texture;
796             D3D10_TEXTURE2D_DESC texture_desc;
797
798             hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D10Texture2D, (void **)&texture);
799             if (FAILED(hr))
800             {
801                 ERR("Resource of type TEXTURE2D doesn't implement ID3D10Texture2D?\n");
802                 return E_INVALIDARG;
803             }
804
805             ID3D10Texture2D_GetDesc(texture, &texture_desc);
806             ID3D10Texture2D_Release(texture);
807
808             desc->Format = texture_desc.Format;
809             if (texture_desc.ArraySize == 1)
810             {
811                 if (texture_desc.SampleDesc.Count == 1)
812                 {
813                     desc->ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2D;
814                     desc->Texture2D.MipSlice = 0;
815                 }
816                 else
817                 {
818                     desc->ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2DMS;
819                 }
820             }
821             else
822             {
823                 if (texture_desc.SampleDesc.Count == 1)
824                 {
825                     desc->ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2DARRAY;
826                     desc->Texture2DArray.MipSlice = 0;
827                     desc->Texture2DArray.FirstArraySlice = 0;
828                     desc->Texture2DArray.ArraySize = 1;
829                 }
830                 else
831                 {
832                     desc->ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2DMSARRAY;
833                     desc->Texture2DMSArray.FirstArraySlice = 0;
834                     desc->Texture2DMSArray.ArraySize = 1;
835                 }
836             }
837
838             return S_OK;
839         }
840
841         case D3D10_RESOURCE_DIMENSION_TEXTURE3D:
842         {
843             ID3D10Texture3D *texture;
844             D3D10_TEXTURE3D_DESC texture_desc;
845
846             hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D10Texture3D, (void **)&texture);
847             if (FAILED(hr))
848             {
849                 ERR("Resource of type TEXTURE3D doesn't implement ID3D10Texture3D?\n");
850                 return E_INVALIDARG;
851             }
852
853             ID3D10Texture3D_GetDesc(texture, &texture_desc);
854             ID3D10Texture3D_Release(texture);
855
856             desc->Format = texture_desc.Format;
857             desc->ViewDimension = D3D10_RTV_DIMENSION_TEXTURE3D;
858             desc->Texture3D.MipSlice = 0;
859             desc->Texture3D.FirstWSlice = 0;
860             desc->Texture3D.WSize = 1;
861
862             return S_OK;
863         }
864
865         default:
866             FIXME("Unhandled resource dimension %#x\n", dimension);
867             return E_INVALIDARG;
868     }
869 }
870
871 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateRenderTargetView(ID3D10Device *iface,
872         ID3D10Resource *resource, const D3D10_RENDER_TARGET_VIEW_DESC *desc, ID3D10RenderTargetView **view)
873 {
874     struct d3d10_device *This = (struct d3d10_device *)iface;
875     struct d3d10_rendertarget_view *object;
876     IWineD3DResource *wined3d_resource;
877
878     TRACE("iface %p, resource %p, desc %p, view %p stub!\n", iface, resource, desc, view);
879
880     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
881     if (!object)
882     {
883         ERR("Failed to allocate D3D10 rendertarget view object memory\n");
884         return E_OUTOFMEMORY;
885     }
886
887     object->vtbl = &d3d10_rendertarget_view_vtbl;
888     object->refcount = 1;
889
890     if (!desc)
891     {
892         HRESULT hr = d3d10_device_set_rtdesc_from_resource(&object->desc, resource);
893         if (FAILED(hr))
894         {
895             HeapFree(GetProcessHeap(), 0, object);
896             return hr;
897         }
898     }
899     else
900     {
901         object->desc = *desc;
902     }
903
904     wined3d_resource = d3d10_device_wined3d_resource_from_resource(resource);
905     if (!wined3d_resource)
906     {
907         FIXME("Failed to get wined3d resource for d3d10 resource %p\n", resource);
908         HeapFree(GetProcessHeap(), 0, object);
909         return E_FAIL;
910     }
911     IWineD3DDevice_CreateRendertargetView(This->wined3d_device,
912             wined3d_resource, (IUnknown *)object, &object->wined3d_view);
913
914     *view = (ID3D10RenderTargetView *)object;
915
916     return S_OK;
917 }
918
919 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateDepthStencilView(ID3D10Device *iface,
920         ID3D10Resource *resource, const D3D10_DEPTH_STENCIL_VIEW_DESC *desc, ID3D10DepthStencilView **view)
921 {
922     FIXME("iface %p, resource %p, desc %p, view %p stub!\n", iface, resource, desc, view);
923
924     return E_NOTIMPL;
925 }
926
927 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateInputLayout(ID3D10Device *iface,
928         const D3D10_INPUT_ELEMENT_DESC *element_descs, UINT element_count, const void *shader_byte_code,
929         SIZE_T shader_byte_code_length, ID3D10InputLayout **input_layout)
930 {
931     struct d3d10_device *This = (struct d3d10_device *)iface;
932     struct d3d10_input_layout *object;
933     WINED3DVERTEXELEMENT *wined3d_elements;
934     UINT wined3d_element_count;
935     HRESULT hr;
936
937     TRACE("iface %p, element_descs %p, element_count %u, shader_byte_code %p,"
938             "\tshader_byte_code_length %lu, input_layout %p\n",
939             iface, element_descs, element_count, shader_byte_code,
940             shader_byte_code_length, input_layout);
941
942     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
943     if (!object)
944     {
945         ERR("Failed to allocate D3D10 input layout object memory\n");
946         return E_OUTOFMEMORY;
947     }
948
949     object->vtbl = &d3d10_input_layout_vtbl;
950     object->refcount = 1;
951
952     hr = d3d10_input_layout_to_wined3d_declaration(element_descs, element_count,
953             shader_byte_code, shader_byte_code_length, &wined3d_elements, &wined3d_element_count);
954     if (FAILED(hr))
955     {
956         HeapFree(GetProcessHeap(), 0, object);
957         return hr;
958     }
959
960     IWineD3DDevice_CreateVertexDeclaration(This->wined3d_device, &object->wined3d_decl,
961             (IUnknown *)object, wined3d_elements, wined3d_element_count);
962
963     HeapFree(GetProcessHeap(), 0, wined3d_elements);
964
965     *input_layout = (ID3D10InputLayout *)object;
966
967     return S_OK;
968 }
969
970 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateVertexShader(ID3D10Device *iface,
971         const void *byte_code, SIZE_T byte_code_length, ID3D10VertexShader **shader)
972 {
973     struct d3d10_vertex_shader *object;
974
975     FIXME("iface %p, byte_code %p, byte_code_length %lu, shader %p stub!\n",
976             iface, byte_code, byte_code_length, shader);
977
978     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
979     if (!object)
980     {
981         ERR("Failed to allocate D3D10 vertex shader object memory\n");
982         return E_OUTOFMEMORY;
983     }
984
985     object->vtbl = &d3d10_vertex_shader_vtbl;
986     object->refcount = 1;
987
988     *shader = (ID3D10VertexShader *)object;
989
990     return S_OK;
991 }
992
993 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateGeometryShader(ID3D10Device *iface,
994         const void *byte_code, SIZE_T byte_code_length, ID3D10GeometryShader **shader)
995 {
996     struct d3d10_geometry_shader *object;
997
998     FIXME("iface %p, byte_code %p, byte_code_length %lu, shader %p stub!\n",
999             iface, byte_code, byte_code_length, shader);
1000
1001     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1002     if (!object)
1003     {
1004         ERR("Failed to allocate D3D10 geometry shader object memory\n");
1005         return E_OUTOFMEMORY;
1006     }
1007
1008     object->vtbl = &d3d10_geometry_shader_vtbl;
1009     object->refcount = 1;
1010
1011     *shader = (ID3D10GeometryShader *)object;
1012
1013     return S_OK;
1014 }
1015
1016 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateGeometryShaderWithStreamOutput(ID3D10Device *iface,
1017         const void *byte_code, SIZE_T byte_code_length, const D3D10_SO_DECLARATION_ENTRY *output_stream_decls,
1018         UINT output_stream_decl_count, UINT output_stream_stride, ID3D10GeometryShader **shader)
1019 {
1020     FIXME("iface %p, byte_code %p, byte_code_length %lu, output_stream_decls %p,\n"
1021             "\toutput_stream_decl_count %u, output_stream_stride %u, shader %p stub!\n",
1022             iface, byte_code, byte_code_length, output_stream_decls,
1023             output_stream_decl_count, output_stream_stride, shader);
1024
1025     return E_NOTIMPL;
1026 }
1027
1028 static HRESULT STDMETHODCALLTYPE d3d10_device_CreatePixelShader(ID3D10Device *iface,
1029         const void *byte_code, SIZE_T byte_code_length, ID3D10PixelShader **shader)
1030 {
1031     struct d3d10_device *This = (struct d3d10_device *)iface;
1032     struct d3d10_pixel_shader *object;
1033     struct d3d10_shader_info shader_info;
1034     HRESULT hr;
1035
1036     TRACE("iface %p, byte_code %p, byte_code_length %lu, shader %p\n",
1037             iface, byte_code, byte_code_length, shader);
1038
1039     object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object));
1040     if (!object)
1041     {
1042         ERR("Failed to allocate D3D10 pixel shader object memory\n");
1043         return E_OUTOFMEMORY;
1044     }
1045
1046     object->vtbl = &d3d10_pixel_shader_vtbl;
1047     object->refcount = 1;
1048
1049     shader_info.output_signature = &object->output_signature;
1050     hr = shader_extract_from_dxbc(byte_code, byte_code_length, &shader_info);
1051     if (FAILED(hr))
1052     {
1053         ERR("Failed to extract shader, hr %#x\n", hr);
1054         HeapFree(GetProcessHeap(), 0, object);
1055         return hr;
1056     }
1057
1058     hr = IWineD3DDevice_CreatePixelShader(This->wined3d_device,
1059             shader_info.shader_code, &object->output_signature,
1060             &object->wined3d_shader, (IUnknown *)object);
1061     if (FAILED(hr))
1062     {
1063         ERR("CreatePixelShader failed, hr %#x\n", hr);
1064         shader_free_signature(&object->output_signature);
1065         HeapFree(GetProcessHeap(), 0, object);
1066         return hr;
1067     }
1068
1069     *shader = (ID3D10PixelShader *)object;
1070
1071     return S_OK;
1072 }
1073
1074 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateBlendState(ID3D10Device *iface,
1075         const D3D10_BLEND_DESC *desc, ID3D10BlendState **blend_state)
1076 {
1077     FIXME("iface %p, desc %p, blend_state %p stub!\n", iface, desc, blend_state);
1078
1079     return E_NOTIMPL;
1080 }
1081
1082 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateDepthStencilState(ID3D10Device *iface,
1083         const D3D10_DEPTH_STENCIL_DESC *desc, ID3D10DepthStencilState **depth_stencil_state)
1084 {
1085     FIXME("iface %p, desc %p, depth_stencil_state %p stub!\n", iface, desc, depth_stencil_state);
1086
1087     return E_NOTIMPL;
1088 }
1089
1090 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateRasterizerState(ID3D10Device *iface,
1091         const D3D10_RASTERIZER_DESC *desc, ID3D10RasterizerState **rasterizer_state)
1092 {
1093     FIXME("iface %p, desc %p, rasterizer_state %p stub!\n", iface, desc, rasterizer_state);
1094
1095     return E_NOTIMPL;
1096 }
1097
1098 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateSamplerState(ID3D10Device *iface,
1099         const D3D10_SAMPLER_DESC *desc, ID3D10SamplerState **sampler_state)
1100 {
1101     FIXME("iface %p, desc %p, sampler_state %p stub!\n", iface, desc, sampler_state);
1102
1103     return E_NOTIMPL;
1104 }
1105
1106 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateQuery(ID3D10Device *iface,
1107         const D3D10_QUERY_DESC *desc, ID3D10Query **query)
1108 {
1109     FIXME("iface %p, desc %p, query %p stub!\n", iface, desc, query);
1110
1111     return E_NOTIMPL;
1112 }
1113
1114 static HRESULT STDMETHODCALLTYPE d3d10_device_CreatePredicate(ID3D10Device *iface,
1115         const D3D10_QUERY_DESC *desc, ID3D10Predicate **predicate)
1116 {
1117     FIXME("iface %p, desc %p, predicate %p stub!\n", iface, desc, predicate);
1118
1119     return E_NOTIMPL;
1120 }
1121
1122 static HRESULT STDMETHODCALLTYPE d3d10_device_CreateCounter(ID3D10Device *iface,
1123         const D3D10_COUNTER_DESC *desc, ID3D10Counter **counter)
1124 {
1125     FIXME("iface %p, desc %p, counter %p stub!\n", iface, desc, counter);
1126
1127     return E_NOTIMPL;
1128 }
1129
1130 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckFormatSupport(ID3D10Device *iface,
1131         DXGI_FORMAT format, UINT *format_support)
1132 {
1133     FIXME("iface %p, format %s, format_support %p stub!\n",
1134             iface, debug_dxgi_format(format), format_support);
1135
1136     return E_NOTIMPL;
1137 }
1138
1139 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckMultisampleQualityLevels(ID3D10Device *iface,
1140         DXGI_FORMAT format, UINT sample_count, UINT *quality_level_count)
1141 {
1142     FIXME("iface %p, format %s, sample_count %u, quality_level_count %p stub!\n",
1143             iface, debug_dxgi_format(format), sample_count, quality_level_count);
1144
1145     return E_NOTIMPL;
1146 }
1147
1148 static void STDMETHODCALLTYPE d3d10_device_CheckCounterInfo(ID3D10Device *iface, D3D10_COUNTER_INFO *counter_info)
1149 {
1150     FIXME("iface %p, counter_info %p stub!\n", iface, counter_info);
1151 }
1152
1153 static HRESULT STDMETHODCALLTYPE d3d10_device_CheckCounter(ID3D10Device *iface,
1154         const D3D10_COUNTER_DESC *desc, D3D10_COUNTER_TYPE *type, UINT *active_counters, LPSTR name,
1155         UINT *name_length, LPSTR units, UINT *units_length, LPSTR description, UINT *description_length)
1156 {
1157     FIXME("iface %p, desc %p, type %p, active_counters %p, name %p, name_length %p,\n"
1158             "\tunits %p, units_length %p, description %p, description_length %p stub!\n",
1159             iface, desc, type, active_counters, name, name_length,
1160             units, units_length, description, description_length);
1161
1162     return E_NOTIMPL;
1163 }
1164
1165 static UINT STDMETHODCALLTYPE d3d10_device_GetCreationFlags(ID3D10Device *iface)
1166 {
1167     FIXME("iface %p stub!\n", iface);
1168
1169     return 0;
1170 }
1171
1172 static HRESULT STDMETHODCALLTYPE d3d10_device_OpenSharedResource(ID3D10Device *iface,
1173         HANDLE resource_handle, REFIID guid, void **resource)
1174 {
1175     FIXME("iface %p, resource_handle %p, guid %s, resource %p stub!\n",
1176             iface, resource_handle, debugstr_guid(guid), resource);
1177
1178     return E_NOTIMPL;
1179 }
1180
1181 static void STDMETHODCALLTYPE d3d10_device_SetTextFilterSize(ID3D10Device *iface, UINT width, UINT height)
1182 {
1183     FIXME("iface %p, width %u, height %u stub!\n", iface, width, height);
1184 }
1185
1186 static void STDMETHODCALLTYPE d3d10_device_GetTextFilterSize(ID3D10Device *iface, UINT *width, UINT *height)
1187 {
1188     FIXME("iface %p, width %p, height %p stub!\n", iface, width, height);
1189 }
1190
1191 const struct ID3D10DeviceVtbl d3d10_device_vtbl =
1192 {
1193     /* IUnknown methods */
1194     d3d10_device_QueryInterface,
1195     d3d10_device_AddRef,
1196     d3d10_device_Release,
1197     /* ID3D10Device methods */
1198     d3d10_device_VSSetConstantBuffers,
1199     d3d10_device_PSSetShaderResources,
1200     d3d10_device_PSSetShader,
1201     d3d10_device_PSSetSamplers,
1202     d3d10_device_VSSetShader,
1203     d3d10_device_DrawIndexed,
1204     d3d10_device_Draw,
1205     d3d10_device_PSSetConstantBuffers,
1206     d3d10_device_IASetInputLayout,
1207     d3d10_device_IASetVertexBuffers,
1208     d3d10_device_IASetIndexBuffer,
1209     d3d10_device_DrawIndexedInstanced,
1210     d3d10_device_DrawInstanced,
1211     d3d10_device_GSSetConstantBuffers,
1212     d3d10_device_GSSetShader,
1213     d3d10_device_IASetPrimitiveTopology,
1214     d3d10_device_VSSetShaderResources,
1215     d3d10_device_VSSetSamplers,
1216     d3d10_device_SetPredication,
1217     d3d10_device_GSSetShaderResources,
1218     d3d10_device_GSSetSamplers,
1219     d3d10_device_OMSetRenderTargets,
1220     d3d10_device_OMSetBlendState,
1221     d3d10_device_OMSetDepthStencilState,
1222     d3d10_device_SOSetTargets,
1223     d3d10_device_DrawAuto,
1224     d3d10_device_RSSetState,
1225     d3d10_device_RSSetViewports,
1226     d3d10_device_RSSetScissorRects,
1227     d3d10_device_CopySubresourceRegion,
1228     d3d10_device_CopyResource,
1229     d3d10_device_UpdateSubresource,
1230     d3d10_device_ClearRenderTargetView,
1231     d3d10_device_ClearDepthStencilView,
1232     d3d10_device_GenerateMips,
1233     d3d10_device_ResolveSubresource,
1234     d3d10_device_VSGetConstantBuffers,
1235     d3d10_device_PSGetShaderResources,
1236     d3d10_device_PSGetShader,
1237     d3d10_device_PSGetSamplers,
1238     d3d10_device_VSGetShader,
1239     d3d10_device_PSGetConstantBuffers,
1240     d3d10_device_IAGetInputLayout,
1241     d3d10_device_IAGetVertexBuffers,
1242     d3d10_device_IAGetIndexBuffer,
1243     d3d10_device_GSGetConstantBuffers,
1244     d3d10_device_GSGetShader,
1245     d3d10_device_IAGetPrimitiveTopology,
1246     d3d10_device_VSGetShaderResources,
1247     d3d10_device_VSGetSamplers,
1248     d3d10_device_GetPredication,
1249     d3d10_device_GSGetShaderResources,
1250     d3d10_device_GSGetSamplers,
1251     d3d10_device_OMGetRenderTargets,
1252     d3d10_device_OMGetBlendState,
1253     d3d10_device_OMGetDepthStencilState,
1254     d3d10_device_SOGetTargets,
1255     d3d10_device_RSGetState,
1256     d3d10_device_RSGetViewports,
1257     d3d10_device_RSGetScissorRects,
1258     d3d10_device_GetDeviceRemovedReason,
1259     d3d10_device_SetExceptionMode,
1260     d3d10_device_GetExceptionMode,
1261     d3d10_device_GetPrivateData,
1262     d3d10_device_SetPrivateData,
1263     d3d10_device_SetPrivateDataInterface,
1264     d3d10_device_ClearState,
1265     d3d10_device_Flush,
1266     d3d10_device_CreateBuffer,
1267     d3d10_device_CreateTexture1D,
1268     d3d10_device_CreateTexture2D,
1269     d3d10_device_CreateTexture3D,
1270     d3d10_device_CreateShaderResourceView,
1271     d3d10_device_CreateRenderTargetView,
1272     d3d10_device_CreateDepthStencilView,
1273     d3d10_device_CreateInputLayout,
1274     d3d10_device_CreateVertexShader,
1275     d3d10_device_CreateGeometryShader,
1276     d3d10_device_CreateGeometryShaderWithStreamOutput,
1277     d3d10_device_CreatePixelShader,
1278     d3d10_device_CreateBlendState,
1279     d3d10_device_CreateDepthStencilState,
1280     d3d10_device_CreateRasterizerState,
1281     d3d10_device_CreateSamplerState,
1282     d3d10_device_CreateQuery,
1283     d3d10_device_CreatePredicate,
1284     d3d10_device_CreateCounter,
1285     d3d10_device_CheckFormatSupport,
1286     d3d10_device_CheckMultisampleQualityLevels,
1287     d3d10_device_CheckCounterInfo,
1288     d3d10_device_CheckCounter,
1289     d3d10_device_GetCreationFlags,
1290     d3d10_device_OpenSharedResource,
1291     d3d10_device_SetTextFilterSize,
1292     d3d10_device_GetTextFilterSize,
1293 };
1294
1295 const struct IUnknownVtbl d3d10_device_inner_unknown_vtbl =
1296 {
1297     /* IUnknown methods */
1298     d3d10_device_inner_QueryInterface,
1299     d3d10_device_inner_AddRef,
1300     d3d10_device_inner_Release,
1301 };
1302
1303 /* IWineD3DDeviceParent IUnknown methods */
1304
1305 static inline struct d3d10_device *device_from_device_parent(IWineD3DDeviceParent *iface)
1306 {
1307     return (struct d3d10_device *)((char*)iface - FIELD_OFFSET(struct d3d10_device, device_parent_vtbl));
1308 }
1309
1310 static HRESULT STDMETHODCALLTYPE device_parent_QueryInterface(IWineD3DDeviceParent *iface, REFIID riid, void **object)
1311 {
1312     struct d3d10_device *This = device_from_device_parent(iface);
1313     return d3d10_device_QueryInterface((ID3D10Device *)This, riid, object);
1314 }
1315
1316 static ULONG STDMETHODCALLTYPE device_parent_AddRef(IWineD3DDeviceParent *iface)
1317 {
1318     struct d3d10_device *This = device_from_device_parent(iface);
1319     return d3d10_device_AddRef((ID3D10Device *)This);
1320 }
1321
1322 static ULONG STDMETHODCALLTYPE device_parent_Release(IWineD3DDeviceParent *iface)
1323 {
1324     struct d3d10_device *This = device_from_device_parent(iface);
1325     return d3d10_device_Release((ID3D10Device *)This);
1326 }
1327
1328 /* IWineD3DDeviceParent methods */
1329
1330 static void STDMETHODCALLTYPE device_parent_WineD3DDeviceCreated(IWineD3DDeviceParent *iface, IWineD3DDevice *device)
1331 {
1332     struct d3d10_device *This = device_from_device_parent(iface);
1333
1334     TRACE("iface %p, device %p\n", iface, device);
1335
1336     IWineD3DDevice_AddRef(device);
1337     This->wined3d_device = device;
1338 }
1339
1340 static HRESULT STDMETHODCALLTYPE device_parent_CreateSurface(IWineD3DDeviceParent *iface,
1341         IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, DWORD usage,
1342         WINED3DPOOL pool, UINT level, WINED3DCUBEMAP_FACES face, IWineD3DSurface **surface)
1343 {
1344     struct d3d10_device *This = device_from_device_parent(iface);
1345     struct d3d10_texture2d *texture;
1346     D3D10_TEXTURE2D_DESC desc;
1347     HRESULT hr;
1348
1349     FIXME("iface %p, superior %p, width %u, height %u, format %#x, usage %#x,\n"
1350             "\tpool %#x, level %u, face %u, surface %p partial stub!\n",
1351             iface, superior, width, height, format, usage, pool, level, face, surface);
1352
1353     FIXME("Implement DXGI<->wined3d usage conversion\n");
1354
1355     desc.Width = width;
1356     desc.Height = height;
1357     desc.MipLevels = 1;
1358     desc.ArraySize = 1;
1359     desc.Format = dxgi_format_from_wined3dformat(format);
1360     desc.SampleDesc.Count = 1;
1361     desc.SampleDesc.Quality = 0;
1362     desc.Usage = usage;
1363     desc.BindFlags = 0;
1364     desc.CPUAccessFlags = 0;
1365     desc.MiscFlags = 0;
1366
1367     hr = d3d10_device_CreateTexture2D((ID3D10Device *)This, &desc, NULL, (ID3D10Texture2D **)&texture);
1368     if (FAILED(hr))
1369     {
1370         ERR("CreateTexture2D failed, returning %#x\n", hr);
1371         return hr;
1372     }
1373
1374     *surface = texture->wined3d_surface;
1375
1376     return S_OK;
1377 }
1378
1379 static HRESULT STDMETHODCALLTYPE device_parent_CreateRenderTarget(IWineD3DDeviceParent *iface,
1380         IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, WINED3DMULTISAMPLE_TYPE multisample_type,
1381         DWORD multisample_quality, BOOL lockable, IWineD3DSurface **surface)
1382 {
1383     struct d3d10_device *This = device_from_device_parent(iface);
1384     struct d3d10_texture2d *texture;
1385     D3D10_TEXTURE2D_DESC desc;
1386     HRESULT hr;
1387
1388     FIXME("iface %p, superior %p, width %u, height %u, format %#x, multisample_type %#x,\n"
1389             "\tmultisample_quality %u, lockable %u, surface %p partial stub!\n",
1390             iface, superior, width, height, format, multisample_type, multisample_quality, lockable, surface);
1391
1392     FIXME("Implement DXGI<->wined3d usage conversion\n");
1393
1394     desc.Width = width;
1395     desc.Height = height;
1396     desc.MipLevels = 1;
1397     desc.ArraySize = 1;
1398     desc.Format = dxgi_format_from_wined3dformat(format);
1399     desc.SampleDesc.Count = multisample_type ? multisample_type : 1;
1400     desc.SampleDesc.Quality = multisample_quality;
1401     desc.Usage = D3D10_USAGE_DEFAULT;
1402     desc.BindFlags = D3D10_BIND_RENDER_TARGET;
1403     desc.CPUAccessFlags = 0;
1404     desc.MiscFlags = 0;
1405
1406     hr = d3d10_device_CreateTexture2D((ID3D10Device *)This, &desc, NULL, (ID3D10Texture2D **)&texture);
1407     if (FAILED(hr))
1408     {
1409         ERR("CreateTexture2D failed, returning %#x\n", hr);
1410         return hr;
1411     }
1412
1413     *surface = texture->wined3d_surface;
1414
1415     return S_OK;
1416 }
1417
1418 static HRESULT STDMETHODCALLTYPE device_parent_CreateDepthStencilSurface(IWineD3DDeviceParent *iface,
1419         IUnknown *superior, UINT width, UINT height, WINED3DFORMAT format, WINED3DMULTISAMPLE_TYPE multisample_type,
1420         DWORD multisample_quality, BOOL discard, IWineD3DSurface **surface)
1421 {
1422     struct d3d10_device *This = device_from_device_parent(iface);
1423     struct d3d10_texture2d *texture;
1424     D3D10_TEXTURE2D_DESC desc;
1425     HRESULT hr;
1426
1427     FIXME("iface %p, superior %p, width %u, height %u, format %#x, multisample_type %#x,\n"
1428             "\tmultisample_quality %u, discard %u, surface %p partial stub!\n",
1429             iface, superior, width, height, format, multisample_type, multisample_quality, discard, surface);
1430
1431     FIXME("Implement DXGI<->wined3d usage conversion\n");
1432
1433     desc.Width = width;
1434     desc.Height = height;
1435     desc.MipLevels = 1;
1436     desc.ArraySize = 1;
1437     desc.Format = dxgi_format_from_wined3dformat(format);
1438     desc.SampleDesc.Count = multisample_type ? multisample_type : 1;
1439     desc.SampleDesc.Quality = multisample_quality;
1440     desc.Usage = D3D10_USAGE_DEFAULT;
1441     desc.BindFlags = D3D10_BIND_RENDER_TARGET;
1442     desc.CPUAccessFlags = 0;
1443     desc.MiscFlags = 0;
1444
1445     hr = d3d10_device_CreateTexture2D((ID3D10Device *)This, &desc, NULL, (ID3D10Texture2D **)&texture);
1446     if (FAILED(hr))
1447     {
1448         ERR("CreateTexture2D failed, returning %#x\n", hr);
1449         return hr;
1450     }
1451
1452     *surface = texture->wined3d_surface;
1453
1454     return S_OK;
1455 }
1456
1457 static HRESULT STDMETHODCALLTYPE device_parent_CreateVolume(IWineD3DDeviceParent *iface,
1458         IUnknown *superior, UINT width, UINT height, UINT depth, WINED3DFORMAT format,
1459         WINED3DPOOL pool, DWORD usage, IWineD3DVolume **volume)
1460 {
1461     FIXME("iface %p, superior %p, width %u, height %u, depth %u, format %#x, pool %#x, usage %#x, volume %p stub!\n",
1462             iface, superior, width, height, depth, format, pool, usage, volume);
1463
1464     return E_NOTIMPL;
1465 }
1466
1467 static HRESULT STDMETHODCALLTYPE device_parent_CreateSwapChain(IWineD3DDeviceParent *iface,
1468         WINED3DPRESENT_PARAMETERS *present_parameters, IWineD3DSwapChain **swapchain)
1469 {
1470     IWineDXGIDevice *wine_device;
1471     HRESULT hr;
1472
1473     TRACE("iface %p, present_parameters %p, swapchain %p\n", iface, present_parameters, swapchain);
1474
1475     hr = IWineD3DDeviceParent_QueryInterface(iface, &IID_IWineDXGIDevice, (void **)&wine_device);
1476     if (FAILED(hr))
1477     {
1478         ERR("Device should implement IWineDXGIDevice\n");
1479         return E_FAIL;
1480     }
1481
1482     hr = IWineDXGIDevice_create_swapchain(wine_device, present_parameters, swapchain);
1483     IWineDXGIDevice_Release(wine_device);
1484     if (FAILED(hr))
1485     {
1486         ERR("Failed to create DXGI swapchain, returning %#x\n", hr);
1487         return hr;
1488     }
1489
1490     return S_OK;
1491 }
1492
1493 const struct IWineD3DDeviceParentVtbl d3d10_wined3d_device_parent_vtbl =
1494 {
1495     /* IUnknown methods */
1496     device_parent_QueryInterface,
1497     device_parent_AddRef,
1498     device_parent_Release,
1499     /* IWineD3DDeviceParent methods */
1500     device_parent_WineD3DDeviceCreated,
1501     device_parent_CreateSurface,
1502     device_parent_CreateRenderTarget,
1503     device_parent_CreateDepthStencilSurface,
1504     device_parent_CreateVolume,
1505     device_parent_CreateSwapChain,
1506 };