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