d3d11: Implement d3d11_device_CreateDepthStencilState().
[wine/multimedia.git] / dlls / d3d11 / state.c
blob15860676fae15492d51d200038ae2abae6d8b0e3
1 /*
2 * Copyright 2009 Henri Verbeet for CodeWeavers
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.
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.
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
20 #include "config.h"
21 #include "wine/port.h"
23 #include "d3d11_private.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(d3d11);
27 #define D3D10_FILTER_MIP_MASK 0x01
28 #define D3D10_FILTER_MAG_MASK 0x04
29 #define D3D10_FILTER_MIN_MASK 0x10
30 #define D3D10_FILTER_ANISO_MASK 0x40
31 #define D3D10_FILTER_COMPARE_MASK 0x80
33 static inline struct d3d10_blend_state *impl_from_ID3D10BlendState(ID3D10BlendState *iface)
35 return CONTAINING_RECORD(iface, struct d3d10_blend_state, ID3D10BlendState_iface);
38 /* IUnknown methods */
40 static HRESULT STDMETHODCALLTYPE d3d10_blend_state_QueryInterface(ID3D10BlendState *iface,
41 REFIID riid, void **object)
43 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
45 if (IsEqualGUID(riid, &IID_ID3D10BlendState)
46 || IsEqualGUID(riid, &IID_ID3D10DeviceChild)
47 || IsEqualGUID(riid, &IID_IUnknown))
49 IUnknown_AddRef(iface);
50 *object = iface;
51 return S_OK;
54 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
56 *object = NULL;
57 return E_NOINTERFACE;
60 static ULONG STDMETHODCALLTYPE d3d10_blend_state_AddRef(ID3D10BlendState *iface)
62 struct d3d10_blend_state *This = impl_from_ID3D10BlendState(iface);
63 ULONG refcount = InterlockedIncrement(&This->refcount);
65 TRACE("%p increasing refcount to %u.\n", This, refcount);
67 return refcount;
70 static ULONG STDMETHODCALLTYPE d3d10_blend_state_Release(ID3D10BlendState *iface)
72 struct d3d10_blend_state *state = impl_from_ID3D10BlendState(iface);
73 ULONG refcount = InterlockedDecrement(&state->refcount);
75 TRACE("%p decreasing refcount to %u.\n", state, refcount);
77 if (!refcount)
79 struct d3d_device *device = impl_from_ID3D10Device(state->device);
80 wined3d_mutex_lock();
81 wine_rb_remove(&device->blend_states, &state->desc);
82 ID3D10Device1_Release(state->device);
83 wined3d_private_store_cleanup(&state->private_store);
84 wined3d_mutex_unlock();
85 HeapFree(GetProcessHeap(), 0, state);
88 return refcount;
91 /* ID3D10DeviceChild methods */
93 static void STDMETHODCALLTYPE d3d10_blend_state_GetDevice(ID3D10BlendState *iface, ID3D10Device **device)
95 struct d3d10_blend_state *state = impl_from_ID3D10BlendState(iface);
97 TRACE("iface %p, device %p.\n", iface, device);
99 *device = (ID3D10Device *)state->device;
100 ID3D10Device_AddRef(*device);
103 static HRESULT STDMETHODCALLTYPE d3d10_blend_state_GetPrivateData(ID3D10BlendState *iface,
104 REFGUID guid, UINT *data_size, void *data)
106 struct d3d10_blend_state *state = impl_from_ID3D10BlendState(iface);
108 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
109 iface, debugstr_guid(guid), data_size, data);
111 return d3d_get_private_data(&state->private_store, guid, data_size, data);
114 static HRESULT STDMETHODCALLTYPE d3d10_blend_state_SetPrivateData(ID3D10BlendState *iface,
115 REFGUID guid, UINT data_size, const void *data)
117 struct d3d10_blend_state *state = impl_from_ID3D10BlendState(iface);
119 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
120 iface, debugstr_guid(guid), data_size, data);
122 return d3d_set_private_data(&state->private_store, guid, data_size, data);
125 static HRESULT STDMETHODCALLTYPE d3d10_blend_state_SetPrivateDataInterface(ID3D10BlendState *iface,
126 REFGUID guid, const IUnknown *data)
128 struct d3d10_blend_state *state = impl_from_ID3D10BlendState(iface);
130 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
132 return d3d_set_private_data_interface(&state->private_store, guid, data);
135 /* ID3D10BlendState methods */
137 static void STDMETHODCALLTYPE d3d10_blend_state_GetDesc(ID3D10BlendState *iface,
138 D3D10_BLEND_DESC *desc)
140 struct d3d10_blend_state *state = impl_from_ID3D10BlendState(iface);
142 TRACE("iface %p, desc %p.\n", iface, desc);
144 *desc = state->desc;
147 static const struct ID3D10BlendStateVtbl d3d10_blend_state_vtbl =
149 /* IUnknown methods */
150 d3d10_blend_state_QueryInterface,
151 d3d10_blend_state_AddRef,
152 d3d10_blend_state_Release,
153 /* ID3D10DeviceChild methods */
154 d3d10_blend_state_GetDevice,
155 d3d10_blend_state_GetPrivateData,
156 d3d10_blend_state_SetPrivateData,
157 d3d10_blend_state_SetPrivateDataInterface,
158 /* ID3D10BlendState methods */
159 d3d10_blend_state_GetDesc,
162 HRESULT d3d10_blend_state_init(struct d3d10_blend_state *state, struct d3d_device *device,
163 const D3D10_BLEND_DESC *desc)
165 state->ID3D10BlendState_iface.lpVtbl = &d3d10_blend_state_vtbl;
166 state->refcount = 1;
167 wined3d_mutex_lock();
168 wined3d_private_store_init(&state->private_store);
169 state->desc = *desc;
171 if (wine_rb_put(&device->blend_states, desc, &state->entry) == -1)
173 ERR("Failed to insert blend state entry.\n");
174 wined3d_private_store_cleanup(&state->private_store);
175 wined3d_mutex_unlock();
176 return E_FAIL;
178 wined3d_mutex_unlock();
180 state->device = &device->ID3D10Device1_iface;
181 ID3D10Device1_AddRef(state->device);
183 return S_OK;
186 struct d3d10_blend_state *unsafe_impl_from_ID3D10BlendState(ID3D10BlendState *iface)
188 if (!iface)
189 return NULL;
190 assert(iface->lpVtbl == &d3d10_blend_state_vtbl);
192 return impl_from_ID3D10BlendState(iface);
195 /* ID3D11DepthStencilState methods */
197 static inline struct d3d_depthstencil_state *impl_from_ID3D11DepthStencilState(ID3D11DepthStencilState *iface)
199 return CONTAINING_RECORD(iface, struct d3d_depthstencil_state, ID3D11DepthStencilState_iface);
202 static HRESULT STDMETHODCALLTYPE d3d11_depthstencil_state_QueryInterface(ID3D11DepthStencilState *iface,
203 REFIID riid, void **object)
205 struct d3d_depthstencil_state *state = impl_from_ID3D11DepthStencilState(iface);
207 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
209 if (IsEqualGUID(riid, &IID_ID3D11DepthStencilState)
210 || IsEqualGUID(riid, &IID_ID3D11DeviceChild)
211 || IsEqualGUID(riid, &IID_IUnknown))
213 ID3D11DepthStencilState_AddRef(iface);
214 *object = iface;
215 return S_OK;
218 if (IsEqualGUID(riid, &IID_ID3D10DepthStencilState)
219 || IsEqualGUID(riid, &IID_ID3D10DeviceChild))
221 ID3D10DepthStencilState_AddRef(&state->ID3D10DepthStencilState_iface);
222 *object = &state->ID3D10DepthStencilState_iface;
223 return S_OK;
226 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
228 *object = NULL;
229 return E_NOINTERFACE;
232 static ULONG STDMETHODCALLTYPE d3d11_depthstencil_state_AddRef(ID3D11DepthStencilState *iface)
234 struct d3d_depthstencil_state *state = impl_from_ID3D11DepthStencilState(iface);
235 ULONG refcount = InterlockedIncrement(&state->refcount);
237 TRACE("%p increasing refcount to %u.\n", state, refcount);
239 return refcount;
242 static ULONG STDMETHODCALLTYPE d3d11_depthstencil_state_Release(ID3D11DepthStencilState *iface)
244 struct d3d_depthstencil_state *state = impl_from_ID3D11DepthStencilState(iface);
245 ULONG refcount = InterlockedDecrement(&state->refcount);
247 TRACE("%p decreasing refcount to %u.\n", state, refcount);
249 if (!refcount)
251 struct d3d_device *device = impl_from_ID3D11Device(state->device);
252 wined3d_mutex_lock();
253 wine_rb_remove(&device->depthstencil_states, &state->desc);
254 ID3D11Device_Release(state->device);
255 wined3d_private_store_cleanup(&state->private_store);
256 wined3d_mutex_unlock();
257 HeapFree(GetProcessHeap(), 0, state);
260 return refcount;
263 static void STDMETHODCALLTYPE d3d11_depthstencil_state_GetDevice(ID3D11DepthStencilState *iface,
264 ID3D11Device **device)
266 struct d3d_depthstencil_state *state = impl_from_ID3D11DepthStencilState(iface);
268 TRACE("iface %p, device %p.\n", iface, device);
270 *device = state->device;
271 ID3D11Device_AddRef(*device);
274 static HRESULT STDMETHODCALLTYPE d3d11_depthstencil_state_GetPrivateData(ID3D11DepthStencilState *iface,
275 REFGUID guid, UINT *data_size, void *data)
277 struct d3d_depthstencil_state *state = impl_from_ID3D11DepthStencilState(iface);
279 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
281 return d3d_get_private_data(&state->private_store, guid, data_size, data);
284 static HRESULT STDMETHODCALLTYPE d3d11_depthstencil_state_SetPrivateData(ID3D11DepthStencilState *iface,
285 REFGUID guid, UINT data_size, const void *data)
287 struct d3d_depthstencil_state *state = impl_from_ID3D11DepthStencilState(iface);
289 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
291 return d3d_set_private_data(&state->private_store, guid, data_size, data);
294 static HRESULT STDMETHODCALLTYPE d3d11_depthstencil_state_SetPrivateDataInterface(ID3D11DepthStencilState *iface,
295 REFGUID guid, const IUnknown *data)
297 struct d3d_depthstencil_state *state = impl_from_ID3D11DepthStencilState(iface);
299 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
301 return d3d_set_private_data_interface(&state->private_store, guid, data);
304 static void STDMETHODCALLTYPE d3d11_depthstencil_state_GetDesc(ID3D11DepthStencilState *iface,
305 D3D11_DEPTH_STENCIL_DESC *desc)
307 struct d3d_depthstencil_state *state = impl_from_ID3D11DepthStencilState(iface);
309 TRACE("iface %p, desc %p.\n", iface, desc);
311 *desc = state->desc;
314 static const struct ID3D11DepthStencilStateVtbl d3d11_depthstencil_state_vtbl =
316 /* IUnknown methods */
317 d3d11_depthstencil_state_QueryInterface,
318 d3d11_depthstencil_state_AddRef,
319 d3d11_depthstencil_state_Release,
320 /* ID3D11DeviceChild methods */
321 d3d11_depthstencil_state_GetDevice,
322 d3d11_depthstencil_state_GetPrivateData,
323 d3d11_depthstencil_state_SetPrivateData,
324 d3d11_depthstencil_state_SetPrivateDataInterface,
325 /* ID3D11DepthStencilState methods */
326 d3d11_depthstencil_state_GetDesc,
329 /* ID3D10DepthStencilState methods */
331 static inline struct d3d_depthstencil_state *impl_from_ID3D10DepthStencilState(ID3D10DepthStencilState *iface)
333 return CONTAINING_RECORD(iface, struct d3d_depthstencil_state, ID3D10DepthStencilState_iface);
336 /* IUnknown methods */
338 static HRESULT STDMETHODCALLTYPE d3d10_depthstencil_state_QueryInterface(ID3D10DepthStencilState *iface,
339 REFIID riid, void **object)
341 struct d3d_depthstencil_state *state = impl_from_ID3D10DepthStencilState(iface);
343 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
345 return d3d11_depthstencil_state_QueryInterface(&state->ID3D11DepthStencilState_iface, riid, object);
348 static ULONG STDMETHODCALLTYPE d3d10_depthstencil_state_AddRef(ID3D10DepthStencilState *iface)
350 struct d3d_depthstencil_state *state = impl_from_ID3D10DepthStencilState(iface);
352 TRACE("iface %p.\n", iface);
354 return d3d11_depthstencil_state_AddRef(&state->ID3D11DepthStencilState_iface);
357 static ULONG STDMETHODCALLTYPE d3d10_depthstencil_state_Release(ID3D10DepthStencilState *iface)
359 struct d3d_depthstencil_state *state = impl_from_ID3D10DepthStencilState(iface);
361 TRACE("iface %p.\n", iface);
363 return d3d11_depthstencil_state_Release(&state->ID3D11DepthStencilState_iface);
366 /* ID3D10DeviceChild methods */
368 static void STDMETHODCALLTYPE d3d10_depthstencil_state_GetDevice(ID3D10DepthStencilState *iface, ID3D10Device **device)
370 struct d3d_depthstencil_state *state = impl_from_ID3D10DepthStencilState(iface);
372 TRACE("iface %p, device %p.\n", iface, device);
374 ID3D11Device_QueryInterface(state->device, &IID_ID3D10Device, (void **)device);
377 static HRESULT STDMETHODCALLTYPE d3d10_depthstencil_state_GetPrivateData(ID3D10DepthStencilState *iface,
378 REFGUID guid, UINT *data_size, void *data)
380 struct d3d_depthstencil_state *state = impl_from_ID3D10DepthStencilState(iface);
382 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
383 iface, debugstr_guid(guid), data_size, data);
385 return d3d_get_private_data(&state->private_store, guid, data_size, data);
388 static HRESULT STDMETHODCALLTYPE d3d10_depthstencil_state_SetPrivateData(ID3D10DepthStencilState *iface,
389 REFGUID guid, UINT data_size, const void *data)
391 struct d3d_depthstencil_state *state = impl_from_ID3D10DepthStencilState(iface);
393 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
394 iface, debugstr_guid(guid), data_size, data);
396 return d3d_set_private_data(&state->private_store, guid, data_size, data);
399 static HRESULT STDMETHODCALLTYPE d3d10_depthstencil_state_SetPrivateDataInterface(ID3D10DepthStencilState *iface,
400 REFGUID guid, const IUnknown *data)
402 struct d3d_depthstencil_state *state = impl_from_ID3D10DepthStencilState(iface);
404 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
406 return d3d_set_private_data_interface(&state->private_store, guid, data);
409 /* ID3D10DepthStencilState methods */
411 static void STDMETHODCALLTYPE d3d10_depthstencil_state_GetDesc(ID3D10DepthStencilState *iface,
412 D3D10_DEPTH_STENCIL_DESC *desc)
414 struct d3d_depthstencil_state *state = impl_from_ID3D10DepthStencilState(iface);
416 TRACE("iface %p, desc %p.\n", iface, desc);
418 memcpy(desc, &state->desc, sizeof(*desc));
421 static const struct ID3D10DepthStencilStateVtbl d3d10_depthstencil_state_vtbl =
423 /* IUnknown methods */
424 d3d10_depthstencil_state_QueryInterface,
425 d3d10_depthstencil_state_AddRef,
426 d3d10_depthstencil_state_Release,
427 /* ID3D10DeviceChild methods */
428 d3d10_depthstencil_state_GetDevice,
429 d3d10_depthstencil_state_GetPrivateData,
430 d3d10_depthstencil_state_SetPrivateData,
431 d3d10_depthstencil_state_SetPrivateDataInterface,
432 /* ID3D10DepthStencilState methods */
433 d3d10_depthstencil_state_GetDesc,
436 HRESULT d3d_depthstencil_state_init(struct d3d_depthstencil_state *state, struct d3d_device *device,
437 const D3D11_DEPTH_STENCIL_DESC *desc)
439 state->ID3D11DepthStencilState_iface.lpVtbl = &d3d11_depthstencil_state_vtbl;
440 state->ID3D10DepthStencilState_iface.lpVtbl = &d3d10_depthstencil_state_vtbl;
441 state->refcount = 1;
442 wined3d_mutex_lock();
443 wined3d_private_store_init(&state->private_store);
444 state->desc = *desc;
446 if (wine_rb_put(&device->depthstencil_states, desc, &state->entry) == -1)
448 ERR("Failed to insert depthstencil state entry.\n");
449 wined3d_private_store_cleanup(&state->private_store);
450 wined3d_mutex_unlock();
451 return E_FAIL;
453 wined3d_mutex_unlock();
455 state->device = &device->ID3D11Device_iface;
456 ID3D11Device_AddRef(state->device);
458 return S_OK;
461 struct d3d_depthstencil_state *unsafe_impl_from_ID3D10DepthStencilState(ID3D10DepthStencilState *iface)
463 if (!iface)
464 return NULL;
465 assert(iface->lpVtbl == &d3d10_depthstencil_state_vtbl);
467 return impl_from_ID3D10DepthStencilState(iface);
470 /* ID3D11RasterizerState methods */
472 static inline struct d3d_rasterizer_state *impl_from_ID3D11RasterizerState(ID3D11RasterizerState *iface)
474 return CONTAINING_RECORD(iface, struct d3d_rasterizer_state, ID3D11RasterizerState_iface);
477 static HRESULT STDMETHODCALLTYPE d3d11_rasterizer_state_QueryInterface(ID3D11RasterizerState *iface,
478 REFIID riid, void **object)
480 struct d3d_rasterizer_state *state = impl_from_ID3D11RasterizerState(iface);
482 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
484 if (IsEqualGUID(riid, &IID_ID3D11RasterizerState)
485 || IsEqualGUID(riid, &IID_ID3D11DeviceChild)
486 || IsEqualGUID(riid, &IID_IUnknown))
488 ID3D11RasterizerState_AddRef(iface);
489 *object = iface;
490 return S_OK;
493 if (IsEqualGUID(riid, &IID_ID3D10RasterizerState)
494 || IsEqualGUID(riid, &IID_ID3D10DeviceChild))
496 ID3D10RasterizerState_AddRef(&state->ID3D10RasterizerState_iface);
497 *object = &state->ID3D10RasterizerState_iface;
498 return S_OK;
501 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
503 *object = NULL;
504 return E_NOINTERFACE;
507 static ULONG STDMETHODCALLTYPE d3d11_rasterizer_state_AddRef(ID3D11RasterizerState *iface)
509 struct d3d_rasterizer_state *state = impl_from_ID3D11RasterizerState(iface);
510 ULONG refcount = InterlockedIncrement(&state->refcount);
512 TRACE("%p increasing refcount to %u.\n", state, refcount);
514 return refcount;
517 static ULONG STDMETHODCALLTYPE d3d11_rasterizer_state_Release(ID3D11RasterizerState *iface)
519 struct d3d_rasterizer_state *state = impl_from_ID3D11RasterizerState(iface);
520 ULONG refcount = InterlockedDecrement(&state->refcount);
522 TRACE("%p decreasing refcount to %u.\n", state, refcount);
524 if (!refcount)
526 struct d3d_device *device = impl_from_ID3D11Device(state->device);
527 wined3d_mutex_lock();
528 wine_rb_remove(&device->rasterizer_states, &state->desc);
529 ID3D11Device_Release(state->device);
530 wined3d_private_store_cleanup(&state->private_store);
531 wined3d_mutex_unlock();
532 HeapFree(GetProcessHeap(), 0, state);
535 return refcount;
538 static void STDMETHODCALLTYPE d3d11_rasterizer_state_GetDevice(ID3D11RasterizerState *iface,
539 ID3D11Device **device)
541 struct d3d_rasterizer_state *state = impl_from_ID3D11RasterizerState(iface);
543 TRACE("iface %p, device %p.\n", iface, device);
545 *device = state->device;
546 ID3D11Device_AddRef(*device);
549 static HRESULT STDMETHODCALLTYPE d3d11_rasterizer_state_GetPrivateData(ID3D11RasterizerState *iface,
550 REFGUID guid, UINT *data_size, void *data)
552 struct d3d_rasterizer_state *state = impl_from_ID3D11RasterizerState(iface);
554 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
556 return d3d_get_private_data(&state->private_store, guid, data_size, data);
559 static HRESULT STDMETHODCALLTYPE d3d11_rasterizer_state_SetPrivateData(ID3D11RasterizerState *iface,
560 REFGUID guid, UINT data_size, const void *data)
562 struct d3d_rasterizer_state *state = impl_from_ID3D11RasterizerState(iface);
564 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
566 return d3d_set_private_data(&state->private_store, guid, data_size, data);
569 static HRESULT STDMETHODCALLTYPE d3d11_rasterizer_state_SetPrivateDataInterface(ID3D11RasterizerState *iface,
570 REFGUID guid, const IUnknown *data)
572 struct d3d_rasterizer_state *state = impl_from_ID3D11RasterizerState(iface);
574 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
576 return d3d_set_private_data_interface(&state->private_store, guid, data);
579 static void STDMETHODCALLTYPE d3d11_rasterizer_state_GetDesc(ID3D11RasterizerState *iface,
580 D3D11_RASTERIZER_DESC *desc)
582 struct d3d_rasterizer_state *state = impl_from_ID3D11RasterizerState(iface);
584 TRACE("iface %p, desc %p.\n", iface, desc);
586 *desc = state->desc;
589 static const struct ID3D11RasterizerStateVtbl d3d11_rasterizer_state_vtbl =
591 /* IUnknown methods */
592 d3d11_rasterizer_state_QueryInterface,
593 d3d11_rasterizer_state_AddRef,
594 d3d11_rasterizer_state_Release,
595 /* ID3D11DeviceChild methods */
596 d3d11_rasterizer_state_GetDevice,
597 d3d11_rasterizer_state_GetPrivateData,
598 d3d11_rasterizer_state_SetPrivateData,
599 d3d11_rasterizer_state_SetPrivateDataInterface,
600 /* ID3D11RasterizerState methods */
601 d3d11_rasterizer_state_GetDesc,
604 /* ID3D10RasterizerState methods */
606 static inline struct d3d_rasterizer_state *impl_from_ID3D10RasterizerState(ID3D10RasterizerState *iface)
608 return CONTAINING_RECORD(iface, struct d3d_rasterizer_state, ID3D10RasterizerState_iface);
611 /* IUnknown methods */
613 static HRESULT STDMETHODCALLTYPE d3d10_rasterizer_state_QueryInterface(ID3D10RasterizerState *iface,
614 REFIID riid, void **object)
616 struct d3d_rasterizer_state *state = impl_from_ID3D10RasterizerState(iface);
618 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
620 return d3d11_rasterizer_state_QueryInterface(&state->ID3D11RasterizerState_iface, riid, object);
623 static ULONG STDMETHODCALLTYPE d3d10_rasterizer_state_AddRef(ID3D10RasterizerState *iface)
625 struct d3d_rasterizer_state *state = impl_from_ID3D10RasterizerState(iface);
627 TRACE("iface %p.\n", iface);
629 return d3d11_rasterizer_state_AddRef(&state->ID3D11RasterizerState_iface);
632 static ULONG STDMETHODCALLTYPE d3d10_rasterizer_state_Release(ID3D10RasterizerState *iface)
634 struct d3d_rasterizer_state *state = impl_from_ID3D10RasterizerState(iface);
636 TRACE("iface %p.\n", state);
638 return d3d11_rasterizer_state_Release(&state->ID3D11RasterizerState_iface);
641 /* ID3D10DeviceChild methods */
643 static void STDMETHODCALLTYPE d3d10_rasterizer_state_GetDevice(ID3D10RasterizerState *iface, ID3D10Device **device)
645 struct d3d_rasterizer_state *state = impl_from_ID3D10RasterizerState(iface);
647 TRACE("iface %p, device %p.\n", iface, device);
649 ID3D11Device_QueryInterface(state->device, &IID_ID3D10Device, (void **)device);
652 static HRESULT STDMETHODCALLTYPE d3d10_rasterizer_state_GetPrivateData(ID3D10RasterizerState *iface,
653 REFGUID guid, UINT *data_size, void *data)
655 struct d3d_rasterizer_state *state = impl_from_ID3D10RasterizerState(iface);
657 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
658 iface, debugstr_guid(guid), data_size, data);
660 return d3d_get_private_data(&state->private_store, guid, data_size, data);
663 static HRESULT STDMETHODCALLTYPE d3d10_rasterizer_state_SetPrivateData(ID3D10RasterizerState *iface,
664 REFGUID guid, UINT data_size, const void *data)
666 struct d3d_rasterizer_state *state = impl_from_ID3D10RasterizerState(iface);
668 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
669 iface, debugstr_guid(guid), data_size, data);
671 return d3d_set_private_data(&state->private_store, guid, data_size, data);
674 static HRESULT STDMETHODCALLTYPE d3d10_rasterizer_state_SetPrivateDataInterface(ID3D10RasterizerState *iface,
675 REFGUID guid, const IUnknown *data)
677 struct d3d_rasterizer_state *state = impl_from_ID3D10RasterizerState(iface);
679 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
681 return d3d_set_private_data_interface(&state->private_store, guid, data);
684 /* ID3D10RasterizerState methods */
686 static void STDMETHODCALLTYPE d3d10_rasterizer_state_GetDesc(ID3D10RasterizerState *iface,
687 D3D10_RASTERIZER_DESC *desc)
689 struct d3d_rasterizer_state *state = impl_from_ID3D10RasterizerState(iface);
691 TRACE("iface %p, desc %p.\n", iface, desc);
693 memcpy(desc, &state->desc, sizeof(*desc));
696 static const struct ID3D10RasterizerStateVtbl d3d10_rasterizer_state_vtbl =
698 /* IUnknown methods */
699 d3d10_rasterizer_state_QueryInterface,
700 d3d10_rasterizer_state_AddRef,
701 d3d10_rasterizer_state_Release,
702 /* ID3D10DeviceChild methods */
703 d3d10_rasterizer_state_GetDevice,
704 d3d10_rasterizer_state_GetPrivateData,
705 d3d10_rasterizer_state_SetPrivateData,
706 d3d10_rasterizer_state_SetPrivateDataInterface,
707 /* ID3D10RasterizerState methods */
708 d3d10_rasterizer_state_GetDesc,
711 HRESULT d3d_rasterizer_state_init(struct d3d_rasterizer_state *state, struct d3d_device *device,
712 const D3D11_RASTERIZER_DESC *desc)
714 state->ID3D11RasterizerState_iface.lpVtbl = &d3d11_rasterizer_state_vtbl;
715 state->ID3D10RasterizerState_iface.lpVtbl = &d3d10_rasterizer_state_vtbl;
716 state->refcount = 1;
717 wined3d_mutex_lock();
718 wined3d_private_store_init(&state->private_store);
719 state->desc = *desc;
721 if (wine_rb_put(&device->rasterizer_states, desc, &state->entry) == -1)
723 ERR("Failed to insert rasterizer state entry.\n");
724 wined3d_private_store_cleanup(&state->private_store);
725 wined3d_mutex_unlock();
726 return E_FAIL;
728 wined3d_mutex_unlock();
730 state->device = &device->ID3D11Device_iface;
731 ID3D11Device_AddRef(state->device);
733 return S_OK;
736 struct d3d_rasterizer_state *unsafe_impl_from_ID3D10RasterizerState(ID3D10RasterizerState *iface)
738 if (!iface)
739 return NULL;
740 assert(iface->lpVtbl == &d3d10_rasterizer_state_vtbl);
742 return impl_from_ID3D10RasterizerState(iface);
745 static inline struct d3d10_sampler_state *impl_from_ID3D10SamplerState(ID3D10SamplerState *iface)
747 return CONTAINING_RECORD(iface, struct d3d10_sampler_state, ID3D10SamplerState_iface);
750 /* IUnknown methods */
752 static HRESULT STDMETHODCALLTYPE d3d10_sampler_state_QueryInterface(ID3D10SamplerState *iface,
753 REFIID riid, void **object)
755 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
757 if (IsEqualGUID(riid, &IID_ID3D10SamplerState)
758 || IsEqualGUID(riid, &IID_ID3D10DeviceChild)
759 || IsEqualGUID(riid, &IID_IUnknown))
761 IUnknown_AddRef(iface);
762 *object = iface;
763 return S_OK;
766 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
768 *object = NULL;
769 return E_NOINTERFACE;
772 static ULONG STDMETHODCALLTYPE d3d10_sampler_state_AddRef(ID3D10SamplerState *iface)
774 struct d3d10_sampler_state *This = impl_from_ID3D10SamplerState(iface);
775 ULONG refcount = InterlockedIncrement(&This->refcount);
777 TRACE("%p increasing refcount to %u.\n", This, refcount);
779 return refcount;
782 static ULONG STDMETHODCALLTYPE d3d10_sampler_state_Release(ID3D10SamplerState *iface)
784 struct d3d10_sampler_state *state = impl_from_ID3D10SamplerState(iface);
785 ULONG refcount = InterlockedDecrement(&state->refcount);
787 TRACE("%p decreasing refcount to %u.\n", state, refcount);
789 if (!refcount)
791 struct d3d_device *device = impl_from_ID3D10Device(state->device);
793 wined3d_mutex_lock();
794 wined3d_sampler_decref(state->wined3d_sampler);
795 wine_rb_remove(&device->sampler_states, &state->desc);
796 ID3D10Device1_Release(state->device);
797 wined3d_private_store_cleanup(&state->private_store);
798 wined3d_mutex_unlock();
799 HeapFree(GetProcessHeap(), 0, state);
802 return refcount;
805 /* ID3D10DeviceChild methods */
807 static void STDMETHODCALLTYPE d3d10_sampler_state_GetDevice(ID3D10SamplerState *iface, ID3D10Device **device)
809 struct d3d10_sampler_state *state = impl_from_ID3D10SamplerState(iface);
811 TRACE("iface %p, device %p.\n", iface, device);
813 *device = (ID3D10Device *)state->device;
814 ID3D10Device_AddRef(*device);
817 static HRESULT STDMETHODCALLTYPE d3d10_sampler_state_GetPrivateData(ID3D10SamplerState *iface,
818 REFGUID guid, UINT *data_size, void *data)
820 struct d3d10_sampler_state *state = impl_from_ID3D10SamplerState(iface);
822 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
823 iface, debugstr_guid(guid), data_size, data);
825 return d3d_get_private_data(&state->private_store, guid, data_size, data);
828 static HRESULT STDMETHODCALLTYPE d3d10_sampler_state_SetPrivateData(ID3D10SamplerState *iface,
829 REFGUID guid, UINT data_size, const void *data)
831 struct d3d10_sampler_state *state = impl_from_ID3D10SamplerState(iface);
833 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
834 iface, debugstr_guid(guid), data_size, data);
836 return d3d_set_private_data(&state->private_store, guid, data_size, data);
839 static HRESULT STDMETHODCALLTYPE d3d10_sampler_state_SetPrivateDataInterface(ID3D10SamplerState *iface,
840 REFGUID guid, const IUnknown *data)
842 struct d3d10_sampler_state *state = impl_from_ID3D10SamplerState(iface);
844 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
846 return d3d_set_private_data_interface(&state->private_store, guid, data);
849 /* ID3D10SamplerState methods */
851 static void STDMETHODCALLTYPE d3d10_sampler_state_GetDesc(ID3D10SamplerState *iface,
852 D3D10_SAMPLER_DESC *desc)
854 struct d3d10_sampler_state *state = impl_from_ID3D10SamplerState(iface);
856 TRACE("iface %p, desc %p.\n", iface, desc);
858 *desc = state->desc;
861 static const struct ID3D10SamplerStateVtbl d3d10_sampler_state_vtbl =
863 /* IUnknown methods */
864 d3d10_sampler_state_QueryInterface,
865 d3d10_sampler_state_AddRef,
866 d3d10_sampler_state_Release,
867 /* ID3D10DeviceChild methods */
868 d3d10_sampler_state_GetDevice,
869 d3d10_sampler_state_GetPrivateData,
870 d3d10_sampler_state_SetPrivateData,
871 d3d10_sampler_state_SetPrivateDataInterface,
872 /* ID3D10SamplerState methods */
873 d3d10_sampler_state_GetDesc,
876 static enum wined3d_texture_address wined3d_texture_address_from_d3d10core(enum D3D10_TEXTURE_ADDRESS_MODE t)
878 return (enum wined3d_texture_address)t;
881 static enum wined3d_texture_filter_type wined3d_texture_filter_mip_from_d3d10core(enum D3D10_FILTER f)
883 if (f & D3D10_FILTER_MIP_MASK)
884 return WINED3D_TEXF_LINEAR;
885 return WINED3D_TEXF_POINT;
888 static enum wined3d_texture_filter_type wined3d_texture_filter_mag_from_d3d10core(enum D3D10_FILTER f)
890 if (f & D3D10_FILTER_MAG_MASK)
891 return WINED3D_TEXF_LINEAR;
892 return WINED3D_TEXF_POINT;
895 static enum wined3d_texture_filter_type wined3d_texture_filter_min_from_d3d10core(enum D3D10_FILTER f)
897 if (f & D3D10_FILTER_MIN_MASK)
898 return WINED3D_TEXF_LINEAR;
899 return WINED3D_TEXF_POINT;
902 static BOOL wined3d_texture_compare_from_d3d10core(enum D3D10_FILTER f)
904 return f & D3D10_FILTER_COMPARE_MASK;
907 static enum wined3d_cmp_func wined3d_cmp_func_from_d3d10core(D3D10_COMPARISON_FUNC f)
909 return (enum wined3d_cmp_func)f;
912 HRESULT d3d10_sampler_state_init(struct d3d10_sampler_state *state, struct d3d_device *device,
913 const D3D10_SAMPLER_DESC *desc)
915 struct wined3d_sampler_desc wined3d_desc;
916 HRESULT hr;
918 state->ID3D10SamplerState_iface.lpVtbl = &d3d10_sampler_state_vtbl;
919 state->refcount = 1;
920 wined3d_mutex_lock();
921 wined3d_private_store_init(&state->private_store);
922 state->desc = *desc;
924 wined3d_desc.address_u = wined3d_texture_address_from_d3d10core(desc->AddressU);
925 wined3d_desc.address_v = wined3d_texture_address_from_d3d10core(desc->AddressV);
926 wined3d_desc.address_w = wined3d_texture_address_from_d3d10core(desc->AddressW);
927 memcpy(wined3d_desc.border_color, desc->BorderColor, sizeof(wined3d_desc.border_color));
928 wined3d_desc.mag_filter = wined3d_texture_filter_mag_from_d3d10core(desc->Filter);
929 wined3d_desc.min_filter = wined3d_texture_filter_min_from_d3d10core(desc->Filter);
930 wined3d_desc.mip_filter = wined3d_texture_filter_mip_from_d3d10core(desc->Filter);
931 wined3d_desc.lod_bias = desc->MipLODBias;
932 wined3d_desc.min_lod = desc->MinLOD;
933 wined3d_desc.max_lod = desc->MaxLOD;
934 wined3d_desc.max_anisotropy = desc->Filter & D3D10_FILTER_ANISO_MASK ? desc->MaxAnisotropy : 1;
935 wined3d_desc.compare = wined3d_texture_compare_from_d3d10core(desc->Filter);
936 wined3d_desc.comparison_func = wined3d_cmp_func_from_d3d10core(desc->ComparisonFunc);
937 wined3d_desc.srgb_decode = FALSE;
939 if (FAILED(hr = wined3d_sampler_create(device->wined3d_device, &wined3d_desc, state, &state->wined3d_sampler)))
941 WARN("Failed to create wined3d sampler, hr %#x.\n", hr);
942 wined3d_private_store_cleanup(&state->private_store);
943 wined3d_mutex_unlock();
944 return hr;
947 if (wine_rb_put(&device->sampler_states, desc, &state->entry) == -1)
949 ERR("Failed to insert sampler state entry.\n");
950 wined3d_sampler_decref(state->wined3d_sampler);
951 wined3d_private_store_cleanup(&state->private_store);
952 wined3d_mutex_unlock();
953 return E_FAIL;
955 wined3d_mutex_unlock();
957 state->device = &device->ID3D10Device1_iface;
958 ID3D10Device1_AddRef(state->device);
960 return S_OK;
963 struct d3d10_sampler_state *unsafe_impl_from_ID3D10SamplerState(ID3D10SamplerState *iface)
965 if (!iface)
966 return NULL;
967 assert(iface->lpVtbl == &d3d10_sampler_state_vtbl);
969 return impl_from_ID3D10SamplerState(iface);