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