d3d10core/tests: Add a small test for ID3D10Device_CreateShaderResourceView().
[wine] / dlls / d3d10core / state.c
1 /*
2  * Copyright 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 static inline struct d3d10_blend_state *impl_from_ID3D10BlendState(ID3D10BlendState *iface)
28 {
29     return CONTAINING_RECORD(iface, struct d3d10_blend_state, ID3D10BlendState_iface);
30 }
31
32 /* IUnknown methods */
33
34 static HRESULT STDMETHODCALLTYPE d3d10_blend_state_QueryInterface(ID3D10BlendState *iface,
35         REFIID riid, void **object)
36 {
37     TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
38
39     if (IsEqualGUID(riid, &IID_ID3D10BlendState)
40             || IsEqualGUID(riid, &IID_ID3D10DeviceChild)
41             || IsEqualGUID(riid, &IID_IUnknown))
42     {
43         IUnknown_AddRef(iface);
44         *object = iface;
45         return S_OK;
46     }
47
48     WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
49
50     *object = NULL;
51     return E_NOINTERFACE;
52 }
53
54 static ULONG STDMETHODCALLTYPE d3d10_blend_state_AddRef(ID3D10BlendState *iface)
55 {
56     struct d3d10_blend_state *This = impl_from_ID3D10BlendState(iface);
57     ULONG refcount = InterlockedIncrement(&This->refcount);
58
59     TRACE("%p increasing refcount to %u.\n", This, refcount);
60
61     return refcount;
62 }
63
64 static ULONG STDMETHODCALLTYPE d3d10_blend_state_Release(ID3D10BlendState *iface)
65 {
66     struct d3d10_blend_state *This = impl_from_ID3D10BlendState(iface);
67     ULONG refcount = InterlockedDecrement(&This->refcount);
68
69     TRACE("%p decreasing refcount to %u.\n", This, refcount);
70
71     if (!refcount)
72     {
73         HeapFree(GetProcessHeap(), 0, This);
74     }
75
76     return refcount;
77 }
78
79 /* ID3D10DeviceChild methods */
80
81 static void STDMETHODCALLTYPE d3d10_blend_state_GetDevice(ID3D10BlendState *iface, ID3D10Device **device)
82 {
83     FIXME("iface %p, device %p stub!\n", iface, device);
84 }
85
86 static HRESULT STDMETHODCALLTYPE d3d10_blend_state_GetPrivateData(ID3D10BlendState *iface,
87         REFGUID guid, UINT *data_size, void *data)
88 {
89     FIXME("iface %p, guid %s, data_size %p, data %p stub!\n",
90             iface, debugstr_guid(guid), data_size, data);
91
92     return E_NOTIMPL;
93 }
94
95 static HRESULT STDMETHODCALLTYPE d3d10_blend_state_SetPrivateData(ID3D10BlendState *iface,
96         REFGUID guid, UINT data_size, const void *data)
97 {
98     FIXME("iface %p, guid %s, data_size %u, data %p stub!\n",
99             iface, debugstr_guid(guid), data_size, data);
100
101     return E_NOTIMPL;
102 }
103
104 static HRESULT STDMETHODCALLTYPE d3d10_blend_state_SetPrivateDataInterface(ID3D10BlendState *iface,
105         REFGUID guid, const IUnknown *data)
106 {
107     FIXME("iface %p, guid %s, data %p stub!\n", iface, debugstr_guid(guid), data);
108
109     return E_NOTIMPL;
110 }
111
112 /* ID3D10BlendState methods */
113
114 static void STDMETHODCALLTYPE d3d10_blend_state_GetDesc(ID3D10BlendState *iface,
115         D3D10_BLEND_DESC *desc)
116 {
117     FIXME("iface %p, desc %p stub!\n", iface, desc);
118 }
119
120 static const struct ID3D10BlendStateVtbl d3d10_blend_state_vtbl =
121 {
122     /* IUnknown methods */
123     d3d10_blend_state_QueryInterface,
124     d3d10_blend_state_AddRef,
125     d3d10_blend_state_Release,
126     /* ID3D10DeviceChild methods */
127     d3d10_blend_state_GetDevice,
128     d3d10_blend_state_GetPrivateData,
129     d3d10_blend_state_SetPrivateData,
130     d3d10_blend_state_SetPrivateDataInterface,
131     /* ID3D10BlendState methods */
132     d3d10_blend_state_GetDesc,
133 };
134
135 HRESULT d3d10_blend_state_init(struct d3d10_blend_state *state)
136 {
137     state->ID3D10BlendState_iface.lpVtbl = &d3d10_blend_state_vtbl;
138     state->refcount = 1;
139
140     return S_OK;
141 }
142
143 static inline struct d3d10_depthstencil_state *impl_from_ID3D10DepthStencilState(ID3D10DepthStencilState *iface)
144 {
145     return CONTAINING_RECORD(iface, struct d3d10_depthstencil_state, ID3D10DepthStencilState_iface);
146 }
147
148 /* IUnknown methods */
149
150 static HRESULT STDMETHODCALLTYPE d3d10_depthstencil_state_QueryInterface(ID3D10DepthStencilState *iface,
151         REFIID riid, void **object)
152 {
153     TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
154
155     if (IsEqualGUID(riid, &IID_ID3D10DepthStencilState)
156             || IsEqualGUID(riid, &IID_ID3D10DeviceChild)
157             || IsEqualGUID(riid, &IID_IUnknown))
158     {
159         IUnknown_AddRef(iface);
160         *object = iface;
161         return S_OK;
162     }
163
164     WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
165
166     *object = NULL;
167     return E_NOINTERFACE;
168 }
169
170 static ULONG STDMETHODCALLTYPE d3d10_depthstencil_state_AddRef(ID3D10DepthStencilState *iface)
171 {
172     struct d3d10_depthstencil_state *This = impl_from_ID3D10DepthStencilState(iface);
173     ULONG refcount = InterlockedIncrement(&This->refcount);
174
175     TRACE("%p increasing refcount to %u.\n", This, refcount);
176
177     return refcount;
178 }
179
180 static ULONG STDMETHODCALLTYPE d3d10_depthstencil_state_Release(ID3D10DepthStencilState *iface)
181 {
182     struct d3d10_depthstencil_state *This = impl_from_ID3D10DepthStencilState(iface);
183     ULONG refcount = InterlockedDecrement(&This->refcount);
184
185     TRACE("%p decreasing refcount to %u.\n", This, refcount);
186
187     if (!refcount)
188     {
189         HeapFree(GetProcessHeap(), 0, This);
190     }
191
192     return refcount;
193 }
194
195 /* ID3D10DeviceChild methods */
196
197 static void STDMETHODCALLTYPE d3d10_depthstencil_state_GetDevice(ID3D10DepthStencilState *iface, ID3D10Device **device)
198 {
199     FIXME("iface %p, device %p stub!\n", iface, device);
200 }
201
202 static HRESULT STDMETHODCALLTYPE d3d10_depthstencil_state_GetPrivateData(ID3D10DepthStencilState *iface,
203         REFGUID guid, UINT *data_size, void *data)
204 {
205     FIXME("iface %p, guid %s, data_size %p, data %p stub!\n",
206             iface, debugstr_guid(guid), data_size, data);
207
208     return E_NOTIMPL;
209 }
210
211 static HRESULT STDMETHODCALLTYPE d3d10_depthstencil_state_SetPrivateData(ID3D10DepthStencilState *iface,
212         REFGUID guid, UINT data_size, const void *data)
213 {
214     FIXME("iface %p, guid %s, data_size %u, data %p stub!\n",
215             iface, debugstr_guid(guid), data_size, data);
216
217     return E_NOTIMPL;
218 }
219
220 static HRESULT STDMETHODCALLTYPE d3d10_depthstencil_state_SetPrivateDataInterface(ID3D10DepthStencilState *iface,
221         REFGUID guid, const IUnknown *data)
222 {
223     FIXME("iface %p, guid %s, data %p stub!\n", iface, debugstr_guid(guid), data);
224
225     return E_NOTIMPL;
226 }
227
228 /* ID3D10DepthStencilState methods */
229
230 static void STDMETHODCALLTYPE d3d10_depthstencil_state_GetDesc(ID3D10DepthStencilState *iface,
231         D3D10_DEPTH_STENCIL_DESC *desc)
232 {
233     FIXME("iface %p, desc %p stub!\n", iface, desc);
234 }
235
236 static const struct ID3D10DepthStencilStateVtbl d3d10_depthstencil_state_vtbl =
237 {
238     /* IUnknown methods */
239     d3d10_depthstencil_state_QueryInterface,
240     d3d10_depthstencil_state_AddRef,
241     d3d10_depthstencil_state_Release,
242     /* ID3D10DeviceChild methods */
243     d3d10_depthstencil_state_GetDevice,
244     d3d10_depthstencil_state_GetPrivateData,
245     d3d10_depthstencil_state_SetPrivateData,
246     d3d10_depthstencil_state_SetPrivateDataInterface,
247     /* ID3D10DepthStencilState methods */
248     d3d10_depthstencil_state_GetDesc,
249 };
250
251 HRESULT d3d10_depthstencil_state_init(struct d3d10_depthstencil_state *state)
252 {
253     state->ID3D10DepthStencilState_iface.lpVtbl = &d3d10_depthstencil_state_vtbl;
254     state->refcount = 1;
255
256     return S_OK;
257 }
258
259 static inline struct d3d10_rasterizer_state *impl_from_ID3D10RasterizerState(ID3D10RasterizerState *iface)
260 {
261     return CONTAINING_RECORD(iface, struct d3d10_rasterizer_state, ID3D10RasterizerState_iface);
262 }
263
264 /* IUnknown methods */
265
266 static HRESULT STDMETHODCALLTYPE d3d10_rasterizer_state_QueryInterface(ID3D10RasterizerState *iface,
267         REFIID riid, void **object)
268 {
269     TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
270
271     if (IsEqualGUID(riid, &IID_ID3D10RasterizerState)
272             || IsEqualGUID(riid, &IID_ID3D10DeviceChild)
273             || IsEqualGUID(riid, &IID_IUnknown))
274     {
275         IUnknown_AddRef(iface);
276         *object = iface;
277         return S_OK;
278     }
279
280     WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
281
282     *object = NULL;
283     return E_NOINTERFACE;
284 }
285
286 static ULONG STDMETHODCALLTYPE d3d10_rasterizer_state_AddRef(ID3D10RasterizerState *iface)
287 {
288     struct d3d10_rasterizer_state *This = impl_from_ID3D10RasterizerState(iface);
289     ULONG refcount = InterlockedIncrement(&This->refcount);
290
291     TRACE("%p increasing refcount to %u.\n", This, refcount);
292
293     return refcount;
294 }
295
296 static ULONG STDMETHODCALLTYPE d3d10_rasterizer_state_Release(ID3D10RasterizerState *iface)
297 {
298     struct d3d10_rasterizer_state *This = impl_from_ID3D10RasterizerState(iface);
299     ULONG refcount = InterlockedDecrement(&This->refcount);
300
301     TRACE("%p decreasing refcount to %u.\n", This, refcount);
302
303     if (!refcount)
304     {
305         HeapFree(GetProcessHeap(), 0, This);
306     }
307
308     return refcount;
309 }
310
311 /* ID3D10DeviceChild methods */
312
313 static void STDMETHODCALLTYPE d3d10_rasterizer_state_GetDevice(ID3D10RasterizerState *iface, ID3D10Device **device)
314 {
315     FIXME("iface %p, device %p stub!\n", iface, device);
316 }
317
318 static HRESULT STDMETHODCALLTYPE d3d10_rasterizer_state_GetPrivateData(ID3D10RasterizerState *iface,
319         REFGUID guid, UINT *data_size, void *data)
320 {
321     FIXME("iface %p, guid %s, data_size %p, data %p stub!\n",
322             iface, debugstr_guid(guid), data_size, data);
323
324     return E_NOTIMPL;
325 }
326
327 static HRESULT STDMETHODCALLTYPE d3d10_rasterizer_state_SetPrivateData(ID3D10RasterizerState *iface,
328         REFGUID guid, UINT data_size, const void *data)
329 {
330     FIXME("iface %p, guid %s, data_size %u, data %p stub!\n",
331             iface, debugstr_guid(guid), data_size, data);
332
333     return E_NOTIMPL;
334 }
335
336 static HRESULT STDMETHODCALLTYPE d3d10_rasterizer_state_SetPrivateDataInterface(ID3D10RasterizerState *iface,
337         REFGUID guid, const IUnknown *data)
338 {
339     FIXME("iface %p, guid %s, data %p stub!\n", iface, debugstr_guid(guid), data);
340
341     return E_NOTIMPL;
342 }
343
344 /* ID3D10RasterizerState methods */
345
346 static void STDMETHODCALLTYPE d3d10_rasterizer_state_GetDesc(ID3D10RasterizerState *iface,
347         D3D10_RASTERIZER_DESC *desc)
348 {
349     FIXME("iface %p, desc %p stub!\n", iface, desc);
350 }
351
352 static const struct ID3D10RasterizerStateVtbl d3d10_rasterizer_state_vtbl =
353 {
354     /* IUnknown methods */
355     d3d10_rasterizer_state_QueryInterface,
356     d3d10_rasterizer_state_AddRef,
357     d3d10_rasterizer_state_Release,
358     /* ID3D10DeviceChild methods */
359     d3d10_rasterizer_state_GetDevice,
360     d3d10_rasterizer_state_GetPrivateData,
361     d3d10_rasterizer_state_SetPrivateData,
362     d3d10_rasterizer_state_SetPrivateDataInterface,
363     /* ID3D10RasterizerState methods */
364     d3d10_rasterizer_state_GetDesc,
365 };
366
367 HRESULT d3d10_rasterizer_state_init(struct d3d10_rasterizer_state *state)
368 {
369     state->ID3D10RasterizerState_iface.lpVtbl = &d3d10_rasterizer_state_vtbl;
370     state->refcount = 1;
371
372     return S_OK;
373 }
374
375 static inline struct d3d10_sampler_state *impl_from_ID3D10SamplerState(ID3D10SamplerState *iface)
376 {
377     return CONTAINING_RECORD(iface, struct d3d10_sampler_state, ID3D10SamplerState_iface);
378 }
379
380 /* IUnknown methods */
381
382 static HRESULT STDMETHODCALLTYPE d3d10_sampler_state_QueryInterface(ID3D10SamplerState *iface,
383         REFIID riid, void **object)
384 {
385     TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
386
387     if (IsEqualGUID(riid, &IID_ID3D10SamplerState)
388             || IsEqualGUID(riid, &IID_ID3D10DeviceChild)
389             || IsEqualGUID(riid, &IID_IUnknown))
390     {
391         IUnknown_AddRef(iface);
392         *object = iface;
393         return S_OK;
394     }
395
396     WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
397
398     *object = NULL;
399     return E_NOINTERFACE;
400 }
401
402 static ULONG STDMETHODCALLTYPE d3d10_sampler_state_AddRef(ID3D10SamplerState *iface)
403 {
404     struct d3d10_sampler_state *This = impl_from_ID3D10SamplerState(iface);
405     ULONG refcount = InterlockedIncrement(&This->refcount);
406
407     TRACE("%p increasing refcount to %u.\n", This, refcount);
408
409     return refcount;
410 }
411
412 static ULONG STDMETHODCALLTYPE d3d10_sampler_state_Release(ID3D10SamplerState *iface)
413 {
414     struct d3d10_sampler_state *This = impl_from_ID3D10SamplerState(iface);
415     ULONG refcount = InterlockedDecrement(&This->refcount);
416
417     TRACE("%p decreasing refcount to %u.\n", This, refcount);
418
419     if (!refcount)
420     {
421         HeapFree(GetProcessHeap(), 0, This);
422     }
423
424     return refcount;
425 }
426
427 /* ID3D10DeviceChild methods */
428
429 static void STDMETHODCALLTYPE d3d10_sampler_state_GetDevice(ID3D10SamplerState *iface, ID3D10Device **device)
430 {
431     FIXME("iface %p, device %p stub!\n", iface, device);
432 }
433
434 static HRESULT STDMETHODCALLTYPE d3d10_sampler_state_GetPrivateData(ID3D10SamplerState *iface,
435         REFGUID guid, UINT *data_size, void *data)
436 {
437     FIXME("iface %p, guid %s, data_size %p, data %p stub!\n",
438             iface, debugstr_guid(guid), data_size, data);
439
440     return E_NOTIMPL;
441 }
442
443 static HRESULT STDMETHODCALLTYPE d3d10_sampler_state_SetPrivateData(ID3D10SamplerState *iface,
444         REFGUID guid, UINT data_size, const void *data)
445 {
446     FIXME("iface %p, guid %s, data_size %u, data %p stub!\n",
447             iface, debugstr_guid(guid), data_size, data);
448
449     return E_NOTIMPL;
450 }
451
452 static HRESULT STDMETHODCALLTYPE d3d10_sampler_state_SetPrivateDataInterface(ID3D10SamplerState *iface,
453         REFGUID guid, const IUnknown *data)
454 {
455     FIXME("iface %p, guid %s, data %p stub!\n", iface, debugstr_guid(guid), data);
456
457     return E_NOTIMPL;
458 }
459
460 /* ID3D10SamplerState methods */
461
462 static void STDMETHODCALLTYPE d3d10_sampler_state_GetDesc(ID3D10SamplerState *iface,
463         D3D10_SAMPLER_DESC *desc)
464 {
465     FIXME("iface %p, desc %p stub!\n", iface, desc);
466 }
467
468 static const struct ID3D10SamplerStateVtbl d3d10_sampler_state_vtbl =
469 {
470     /* IUnknown methods */
471     d3d10_sampler_state_QueryInterface,
472     d3d10_sampler_state_AddRef,
473     d3d10_sampler_state_Release,
474     /* ID3D10DeviceChild methods */
475     d3d10_sampler_state_GetDevice,
476     d3d10_sampler_state_GetPrivateData,
477     d3d10_sampler_state_SetPrivateData,
478     d3d10_sampler_state_SetPrivateDataInterface,
479     /* ID3D10SamplerState methods */
480     d3d10_sampler_state_GetDesc,
481 };
482
483 HRESULT d3d10_sampler_state_init(struct d3d10_sampler_state *state)
484 {
485     state->ID3D10SamplerState_iface.lpVtbl = &d3d10_sampler_state_vtbl;
486     state->refcount = 1;
487
488     return S_OK;
489 }