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