webservices/tests: Add a test to show that the reader converts text to UTF-8.
[wine.git] / dlls / d3d11 / state.c
blob43dd10ffa7fd3aca2feedae52b6ce21a3bcbebb9
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 /* ID3D11BlendState methods */
29 static HRESULT STDMETHODCALLTYPE d3d11_blend_state_QueryInterface(ID3D11BlendState *iface,
30 REFIID riid, void **object)
32 struct d3d_blend_state *state = impl_from_ID3D11BlendState(iface);
34 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
36 if (IsEqualGUID(riid, &IID_ID3D11BlendState)
37 || IsEqualGUID(riid, &IID_ID3D11DeviceChild)
38 || IsEqualGUID(riid, &IID_IUnknown))
40 ID3D11BlendState_AddRef(iface);
41 *object = iface;
42 return S_OK;
45 if (IsEqualGUID(riid, &IID_ID3D10BlendState1)
46 || IsEqualGUID(riid, &IID_ID3D10BlendState)
47 || IsEqualGUID(riid, &IID_ID3D10DeviceChild))
49 ID3D10BlendState1_AddRef(&state->ID3D10BlendState1_iface);
50 *object = &state->ID3D10BlendState1_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 d3d11_blend_state_AddRef(ID3D11BlendState *iface)
62 struct d3d_blend_state *state = impl_from_ID3D11BlendState(iface);
63 ULONG refcount = InterlockedIncrement(&state->refcount);
65 TRACE("%p increasing refcount to %u.\n", state, refcount);
67 return refcount;
70 static ULONG STDMETHODCALLTYPE d3d11_blend_state_Release(ID3D11BlendState *iface)
72 struct d3d_blend_state *state = impl_from_ID3D11BlendState(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_ID3D11Device(state->device);
80 wined3d_mutex_lock();
81 wine_rb_remove(&device->blend_states, &state->entry);
82 ID3D11Device_Release(state->device);
83 wined3d_private_store_cleanup(&state->private_store);
84 wined3d_mutex_unlock();
85 HeapFree(GetProcessHeap(), 0, state);
88 return refcount;
91 static void STDMETHODCALLTYPE d3d11_blend_state_GetDevice(ID3D11BlendState *iface,
92 ID3D11Device **device)
94 struct d3d_blend_state *state = impl_from_ID3D11BlendState(iface);
96 TRACE("iface %p, device %p.\n", iface, device);
98 *device = state->device;
99 ID3D11Device_AddRef(*device);
102 static HRESULT STDMETHODCALLTYPE d3d11_blend_state_GetPrivateData(ID3D11BlendState *iface,
103 REFGUID guid, UINT *data_size, void *data)
105 struct d3d_blend_state *state = impl_from_ID3D11BlendState(iface);
107 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
109 return d3d_get_private_data(&state->private_store, guid, data_size, data);
112 static HRESULT STDMETHODCALLTYPE d3d11_blend_state_SetPrivateData(ID3D11BlendState *iface,
113 REFGUID guid, UINT data_size, const void *data)
115 struct d3d_blend_state *state = impl_from_ID3D11BlendState(iface);
117 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
119 return d3d_set_private_data(&state->private_store, guid, data_size, data);
122 static HRESULT STDMETHODCALLTYPE d3d11_blend_state_SetPrivateDataInterface(ID3D11BlendState *iface,
123 REFGUID guid, const IUnknown *data)
125 struct d3d_blend_state *state = impl_from_ID3D11BlendState(iface);
127 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
129 return d3d_set_private_data_interface(&state->private_store, guid, data);
132 static void STDMETHODCALLTYPE d3d11_blend_state_GetDesc(ID3D11BlendState *iface, D3D11_BLEND_DESC *desc)
134 struct d3d_blend_state *state = impl_from_ID3D11BlendState(iface);
136 TRACE("iface %p, desc %p.\n", iface, desc);
138 *desc = state->desc;
141 static const struct ID3D11BlendStateVtbl d3d11_blend_state_vtbl =
143 /* IUnknown methods */
144 d3d11_blend_state_QueryInterface,
145 d3d11_blend_state_AddRef,
146 d3d11_blend_state_Release,
147 /* ID3D11DeviceChild methods */
148 d3d11_blend_state_GetDevice,
149 d3d11_blend_state_GetPrivateData,
150 d3d11_blend_state_SetPrivateData,
151 d3d11_blend_state_SetPrivateDataInterface,
152 /* ID3D11BlendState methods */
153 d3d11_blend_state_GetDesc,
156 /* ID3D10BlendState methods */
158 static inline struct d3d_blend_state *impl_from_ID3D10BlendState(ID3D10BlendState1 *iface)
160 return CONTAINING_RECORD(iface, struct d3d_blend_state, ID3D10BlendState1_iface);
163 /* IUnknown methods */
165 static HRESULT STDMETHODCALLTYPE d3d10_blend_state_QueryInterface(ID3D10BlendState1 *iface,
166 REFIID riid, void **object)
168 struct d3d_blend_state *state = impl_from_ID3D10BlendState(iface);
170 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
172 return d3d11_blend_state_QueryInterface(&state->ID3D11BlendState_iface, riid, object);
175 static ULONG STDMETHODCALLTYPE d3d10_blend_state_AddRef(ID3D10BlendState1 *iface)
177 struct d3d_blend_state *state = impl_from_ID3D10BlendState(iface);
179 TRACE("iface %p.\n", iface);
181 return d3d11_blend_state_AddRef(&state->ID3D11BlendState_iface);
184 static ULONG STDMETHODCALLTYPE d3d10_blend_state_Release(ID3D10BlendState1 *iface)
186 struct d3d_blend_state *state = impl_from_ID3D10BlendState(iface);
188 TRACE("iface %p.\n", iface);
190 return d3d11_blend_state_Release(&state->ID3D11BlendState_iface);
193 /* ID3D10DeviceChild methods */
195 static void STDMETHODCALLTYPE d3d10_blend_state_GetDevice(ID3D10BlendState1 *iface, ID3D10Device **device)
197 struct d3d_blend_state *state = impl_from_ID3D10BlendState(iface);
199 TRACE("iface %p, device %p.\n", iface, device);
201 ID3D11Device_QueryInterface(state->device, &IID_ID3D10Device, (void **)device);
204 static HRESULT STDMETHODCALLTYPE d3d10_blend_state_GetPrivateData(ID3D10BlendState1 *iface,
205 REFGUID guid, UINT *data_size, void *data)
207 struct d3d_blend_state *state = impl_from_ID3D10BlendState(iface);
209 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
210 iface, debugstr_guid(guid), data_size, data);
212 return d3d_get_private_data(&state->private_store, guid, data_size, data);
215 static HRESULT STDMETHODCALLTYPE d3d10_blend_state_SetPrivateData(ID3D10BlendState1 *iface,
216 REFGUID guid, UINT data_size, const void *data)
218 struct d3d_blend_state *state = impl_from_ID3D10BlendState(iface);
220 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
221 iface, debugstr_guid(guid), data_size, data);
223 return d3d_set_private_data(&state->private_store, guid, data_size, data);
226 static HRESULT STDMETHODCALLTYPE d3d10_blend_state_SetPrivateDataInterface(ID3D10BlendState1 *iface,
227 REFGUID guid, const IUnknown *data)
229 struct d3d_blend_state *state = impl_from_ID3D10BlendState(iface);
231 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
233 return d3d_set_private_data_interface(&state->private_store, guid, data);
236 /* ID3D10BlendState methods */
238 static void STDMETHODCALLTYPE d3d10_blend_state_GetDesc(ID3D10BlendState1 *iface, D3D10_BLEND_DESC *desc)
240 struct d3d_blend_state *state = impl_from_ID3D10BlendState(iface);
241 const D3D11_BLEND_DESC *d3d11_desc = &state->desc;
242 unsigned int i;
244 TRACE("iface %p, desc %p.\n", iface, desc);
246 desc->AlphaToCoverageEnable = d3d11_desc->AlphaToCoverageEnable;
247 desc->SrcBlend = d3d11_desc->RenderTarget[0].SrcBlend;
248 desc->DestBlend = d3d11_desc->RenderTarget[0].DestBlend;
249 desc->BlendOp = d3d11_desc->RenderTarget[0].BlendOp;
250 desc->SrcBlendAlpha = d3d11_desc->RenderTarget[0].SrcBlendAlpha;
251 desc->DestBlendAlpha = d3d11_desc->RenderTarget[0].DestBlendAlpha;
252 desc->BlendOpAlpha = d3d11_desc->RenderTarget[0].BlendOpAlpha;
253 for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i)
255 desc->BlendEnable[i] = d3d11_desc->RenderTarget[i].BlendEnable;
256 desc->RenderTargetWriteMask[i] = d3d11_desc->RenderTarget[i].RenderTargetWriteMask;
260 static void STDMETHODCALLTYPE d3d10_blend_state_GetDesc1(ID3D10BlendState1 *iface, D3D10_BLEND_DESC1 *desc)
262 struct d3d_blend_state *state = impl_from_ID3D10BlendState(iface);
264 TRACE("iface %p, desc %p.\n", iface, desc);
266 memcpy(desc, &state->desc, sizeof(*desc));
269 static const struct ID3D10BlendState1Vtbl d3d10_blend_state_vtbl =
271 /* IUnknown methods */
272 d3d10_blend_state_QueryInterface,
273 d3d10_blend_state_AddRef,
274 d3d10_blend_state_Release,
275 /* ID3D10DeviceChild methods */
276 d3d10_blend_state_GetDevice,
277 d3d10_blend_state_GetPrivateData,
278 d3d10_blend_state_SetPrivateData,
279 d3d10_blend_state_SetPrivateDataInterface,
280 /* ID3D10BlendState methods */
281 d3d10_blend_state_GetDesc,
282 /* ID3D10BlendState1 methods */
283 d3d10_blend_state_GetDesc1,
286 HRESULT d3d_blend_state_init(struct d3d_blend_state *state, struct d3d_device *device,
287 const D3D11_BLEND_DESC *desc)
289 state->ID3D11BlendState_iface.lpVtbl = &d3d11_blend_state_vtbl;
290 state->ID3D10BlendState1_iface.lpVtbl = &d3d10_blend_state_vtbl;
291 state->refcount = 1;
292 wined3d_mutex_lock();
293 wined3d_private_store_init(&state->private_store);
294 state->desc = *desc;
296 if (wine_rb_put(&device->blend_states, desc, &state->entry) == -1)
298 ERR("Failed to insert blend state entry.\n");
299 wined3d_private_store_cleanup(&state->private_store);
300 wined3d_mutex_unlock();
301 return E_FAIL;
303 wined3d_mutex_unlock();
305 state->device = &device->ID3D11Device_iface;
306 ID3D11Device_AddRef(state->device);
308 return S_OK;
311 struct d3d_blend_state *unsafe_impl_from_ID3D11BlendState(ID3D11BlendState *iface)
313 if (!iface)
314 return NULL;
315 assert(iface->lpVtbl == &d3d11_blend_state_vtbl);
317 return impl_from_ID3D11BlendState(iface);
320 struct d3d_blend_state *unsafe_impl_from_ID3D10BlendState(ID3D10BlendState *iface)
322 if (!iface)
323 return NULL;
324 assert(iface->lpVtbl == (ID3D10BlendStateVtbl *)&d3d10_blend_state_vtbl);
326 return impl_from_ID3D10BlendState((ID3D10BlendState1 *)iface);
329 /* ID3D11DepthStencilState methods */
331 static HRESULT STDMETHODCALLTYPE d3d11_depthstencil_state_QueryInterface(ID3D11DepthStencilState *iface,
332 REFIID riid, void **object)
334 struct d3d_depthstencil_state *state = impl_from_ID3D11DepthStencilState(iface);
336 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
338 if (IsEqualGUID(riid, &IID_ID3D11DepthStencilState)
339 || IsEqualGUID(riid, &IID_ID3D11DeviceChild)
340 || IsEqualGUID(riid, &IID_IUnknown))
342 ID3D11DepthStencilState_AddRef(iface);
343 *object = iface;
344 return S_OK;
347 if (IsEqualGUID(riid, &IID_ID3D10DepthStencilState)
348 || IsEqualGUID(riid, &IID_ID3D10DeviceChild))
350 ID3D10DepthStencilState_AddRef(&state->ID3D10DepthStencilState_iface);
351 *object = &state->ID3D10DepthStencilState_iface;
352 return S_OK;
355 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
357 *object = NULL;
358 return E_NOINTERFACE;
361 static ULONG STDMETHODCALLTYPE d3d11_depthstencil_state_AddRef(ID3D11DepthStencilState *iface)
363 struct d3d_depthstencil_state *state = impl_from_ID3D11DepthStencilState(iface);
364 ULONG refcount = InterlockedIncrement(&state->refcount);
366 TRACE("%p increasing refcount to %u.\n", state, refcount);
368 return refcount;
371 static ULONG STDMETHODCALLTYPE d3d11_depthstencil_state_Release(ID3D11DepthStencilState *iface)
373 struct d3d_depthstencil_state *state = impl_from_ID3D11DepthStencilState(iface);
374 ULONG refcount = InterlockedDecrement(&state->refcount);
376 TRACE("%p decreasing refcount to %u.\n", state, refcount);
378 if (!refcount)
380 struct d3d_device *device = impl_from_ID3D11Device(state->device);
381 wined3d_mutex_lock();
382 wine_rb_remove(&device->depthstencil_states, &state->entry);
383 ID3D11Device_Release(state->device);
384 wined3d_private_store_cleanup(&state->private_store);
385 wined3d_mutex_unlock();
386 HeapFree(GetProcessHeap(), 0, state);
389 return refcount;
392 static void STDMETHODCALLTYPE d3d11_depthstencil_state_GetDevice(ID3D11DepthStencilState *iface,
393 ID3D11Device **device)
395 struct d3d_depthstencil_state *state = impl_from_ID3D11DepthStencilState(iface);
397 TRACE("iface %p, device %p.\n", iface, device);
399 *device = state->device;
400 ID3D11Device_AddRef(*device);
403 static HRESULT STDMETHODCALLTYPE d3d11_depthstencil_state_GetPrivateData(ID3D11DepthStencilState *iface,
404 REFGUID guid, UINT *data_size, void *data)
406 struct d3d_depthstencil_state *state = impl_from_ID3D11DepthStencilState(iface);
408 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
410 return d3d_get_private_data(&state->private_store, guid, data_size, data);
413 static HRESULT STDMETHODCALLTYPE d3d11_depthstencil_state_SetPrivateData(ID3D11DepthStencilState *iface,
414 REFGUID guid, UINT data_size, const void *data)
416 struct d3d_depthstencil_state *state = impl_from_ID3D11DepthStencilState(iface);
418 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
420 return d3d_set_private_data(&state->private_store, guid, data_size, data);
423 static HRESULT STDMETHODCALLTYPE d3d11_depthstencil_state_SetPrivateDataInterface(ID3D11DepthStencilState *iface,
424 REFGUID guid, const IUnknown *data)
426 struct d3d_depthstencil_state *state = impl_from_ID3D11DepthStencilState(iface);
428 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
430 return d3d_set_private_data_interface(&state->private_store, guid, data);
433 static void STDMETHODCALLTYPE d3d11_depthstencil_state_GetDesc(ID3D11DepthStencilState *iface,
434 D3D11_DEPTH_STENCIL_DESC *desc)
436 struct d3d_depthstencil_state *state = impl_from_ID3D11DepthStencilState(iface);
438 TRACE("iface %p, desc %p.\n", iface, desc);
440 *desc = state->desc;
443 static const struct ID3D11DepthStencilStateVtbl d3d11_depthstencil_state_vtbl =
445 /* IUnknown methods */
446 d3d11_depthstencil_state_QueryInterface,
447 d3d11_depthstencil_state_AddRef,
448 d3d11_depthstencil_state_Release,
449 /* ID3D11DeviceChild methods */
450 d3d11_depthstencil_state_GetDevice,
451 d3d11_depthstencil_state_GetPrivateData,
452 d3d11_depthstencil_state_SetPrivateData,
453 d3d11_depthstencil_state_SetPrivateDataInterface,
454 /* ID3D11DepthStencilState methods */
455 d3d11_depthstencil_state_GetDesc,
458 /* ID3D10DepthStencilState methods */
460 static inline struct d3d_depthstencil_state *impl_from_ID3D10DepthStencilState(ID3D10DepthStencilState *iface)
462 return CONTAINING_RECORD(iface, struct d3d_depthstencil_state, ID3D10DepthStencilState_iface);
465 /* IUnknown methods */
467 static HRESULT STDMETHODCALLTYPE d3d10_depthstencil_state_QueryInterface(ID3D10DepthStencilState *iface,
468 REFIID riid, void **object)
470 struct d3d_depthstencil_state *state = impl_from_ID3D10DepthStencilState(iface);
472 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
474 return d3d11_depthstencil_state_QueryInterface(&state->ID3D11DepthStencilState_iface, riid, object);
477 static ULONG STDMETHODCALLTYPE d3d10_depthstencil_state_AddRef(ID3D10DepthStencilState *iface)
479 struct d3d_depthstencil_state *state = impl_from_ID3D10DepthStencilState(iface);
481 TRACE("iface %p.\n", iface);
483 return d3d11_depthstencil_state_AddRef(&state->ID3D11DepthStencilState_iface);
486 static ULONG STDMETHODCALLTYPE d3d10_depthstencil_state_Release(ID3D10DepthStencilState *iface)
488 struct d3d_depthstencil_state *state = impl_from_ID3D10DepthStencilState(iface);
490 TRACE("iface %p.\n", iface);
492 return d3d11_depthstencil_state_Release(&state->ID3D11DepthStencilState_iface);
495 /* ID3D10DeviceChild methods */
497 static void STDMETHODCALLTYPE d3d10_depthstencil_state_GetDevice(ID3D10DepthStencilState *iface, ID3D10Device **device)
499 struct d3d_depthstencil_state *state = impl_from_ID3D10DepthStencilState(iface);
501 TRACE("iface %p, device %p.\n", iface, device);
503 ID3D11Device_QueryInterface(state->device, &IID_ID3D10Device, (void **)device);
506 static HRESULT STDMETHODCALLTYPE d3d10_depthstencil_state_GetPrivateData(ID3D10DepthStencilState *iface,
507 REFGUID guid, UINT *data_size, void *data)
509 struct d3d_depthstencil_state *state = impl_from_ID3D10DepthStencilState(iface);
511 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
512 iface, debugstr_guid(guid), data_size, data);
514 return d3d_get_private_data(&state->private_store, guid, data_size, data);
517 static HRESULT STDMETHODCALLTYPE d3d10_depthstencil_state_SetPrivateData(ID3D10DepthStencilState *iface,
518 REFGUID guid, UINT data_size, const void *data)
520 struct d3d_depthstencil_state *state = impl_from_ID3D10DepthStencilState(iface);
522 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
523 iface, debugstr_guid(guid), data_size, data);
525 return d3d_set_private_data(&state->private_store, guid, data_size, data);
528 static HRESULT STDMETHODCALLTYPE d3d10_depthstencil_state_SetPrivateDataInterface(ID3D10DepthStencilState *iface,
529 REFGUID guid, const IUnknown *data)
531 struct d3d_depthstencil_state *state = impl_from_ID3D10DepthStencilState(iface);
533 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
535 return d3d_set_private_data_interface(&state->private_store, guid, data);
538 /* ID3D10DepthStencilState methods */
540 static void STDMETHODCALLTYPE d3d10_depthstencil_state_GetDesc(ID3D10DepthStencilState *iface,
541 D3D10_DEPTH_STENCIL_DESC *desc)
543 struct d3d_depthstencil_state *state = impl_from_ID3D10DepthStencilState(iface);
545 TRACE("iface %p, desc %p.\n", iface, desc);
547 memcpy(desc, &state->desc, sizeof(*desc));
550 static const struct ID3D10DepthStencilStateVtbl d3d10_depthstencil_state_vtbl =
552 /* IUnknown methods */
553 d3d10_depthstencil_state_QueryInterface,
554 d3d10_depthstencil_state_AddRef,
555 d3d10_depthstencil_state_Release,
556 /* ID3D10DeviceChild methods */
557 d3d10_depthstencil_state_GetDevice,
558 d3d10_depthstencil_state_GetPrivateData,
559 d3d10_depthstencil_state_SetPrivateData,
560 d3d10_depthstencil_state_SetPrivateDataInterface,
561 /* ID3D10DepthStencilState methods */
562 d3d10_depthstencil_state_GetDesc,
565 HRESULT d3d_depthstencil_state_init(struct d3d_depthstencil_state *state, struct d3d_device *device,
566 const D3D11_DEPTH_STENCIL_DESC *desc)
568 state->ID3D11DepthStencilState_iface.lpVtbl = &d3d11_depthstencil_state_vtbl;
569 state->ID3D10DepthStencilState_iface.lpVtbl = &d3d10_depthstencil_state_vtbl;
570 state->refcount = 1;
571 wined3d_mutex_lock();
572 wined3d_private_store_init(&state->private_store);
573 state->desc = *desc;
575 if (wine_rb_put(&device->depthstencil_states, desc, &state->entry) == -1)
577 ERR("Failed to insert depthstencil state entry.\n");
578 wined3d_private_store_cleanup(&state->private_store);
579 wined3d_mutex_unlock();
580 return E_FAIL;
582 wined3d_mutex_unlock();
584 state->device = &device->ID3D11Device_iface;
585 ID3D11Device_AddRef(state->device);
587 return S_OK;
590 struct d3d_depthstencil_state *unsafe_impl_from_ID3D11DepthStencilState(ID3D11DepthStencilState *iface)
592 if (!iface)
593 return NULL;
594 assert(iface->lpVtbl == &d3d11_depthstencil_state_vtbl);
596 return impl_from_ID3D11DepthStencilState(iface);
599 struct d3d_depthstencil_state *unsafe_impl_from_ID3D10DepthStencilState(ID3D10DepthStencilState *iface)
601 if (!iface)
602 return NULL;
603 assert(iface->lpVtbl == &d3d10_depthstencil_state_vtbl);
605 return impl_from_ID3D10DepthStencilState(iface);
608 /* ID3D11RasterizerState methods */
610 static inline struct d3d_rasterizer_state *impl_from_ID3D11RasterizerState(ID3D11RasterizerState *iface)
612 return CONTAINING_RECORD(iface, struct d3d_rasterizer_state, ID3D11RasterizerState_iface);
615 static HRESULT STDMETHODCALLTYPE d3d11_rasterizer_state_QueryInterface(ID3D11RasterizerState *iface,
616 REFIID riid, void **object)
618 struct d3d_rasterizer_state *state = impl_from_ID3D11RasterizerState(iface);
620 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
622 if (IsEqualGUID(riid, &IID_ID3D11RasterizerState)
623 || IsEqualGUID(riid, &IID_ID3D11DeviceChild)
624 || IsEqualGUID(riid, &IID_IUnknown))
626 ID3D11RasterizerState_AddRef(iface);
627 *object = iface;
628 return S_OK;
631 if (IsEqualGUID(riid, &IID_ID3D10RasterizerState)
632 || IsEqualGUID(riid, &IID_ID3D10DeviceChild))
634 ID3D10RasterizerState_AddRef(&state->ID3D10RasterizerState_iface);
635 *object = &state->ID3D10RasterizerState_iface;
636 return S_OK;
639 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
641 *object = NULL;
642 return E_NOINTERFACE;
645 static ULONG STDMETHODCALLTYPE d3d11_rasterizer_state_AddRef(ID3D11RasterizerState *iface)
647 struct d3d_rasterizer_state *state = impl_from_ID3D11RasterizerState(iface);
648 ULONG refcount = InterlockedIncrement(&state->refcount);
650 TRACE("%p increasing refcount to %u.\n", state, refcount);
652 if (refcount == 1)
654 ID3D11Device_AddRef(state->device);
655 wined3d_mutex_lock();
656 wined3d_rasterizer_state_incref(state->wined3d_state);
657 wined3d_mutex_unlock();
660 return refcount;
663 static ULONG STDMETHODCALLTYPE d3d11_rasterizer_state_Release(ID3D11RasterizerState *iface)
665 struct d3d_rasterizer_state *state = impl_from_ID3D11RasterizerState(iface);
666 ULONG refcount = InterlockedDecrement(&state->refcount);
668 TRACE("%p decreasing refcount to %u.\n", state, refcount);
670 if (!refcount)
672 ID3D11Device *device = state->device;
674 wined3d_mutex_lock();
675 wined3d_rasterizer_state_decref(state->wined3d_state);
676 wined3d_mutex_unlock();
678 ID3D11Device_Release(device);
681 return refcount;
684 static void STDMETHODCALLTYPE d3d11_rasterizer_state_GetDevice(ID3D11RasterizerState *iface,
685 ID3D11Device **device)
687 struct d3d_rasterizer_state *state = impl_from_ID3D11RasterizerState(iface);
689 TRACE("iface %p, device %p.\n", iface, device);
691 *device = state->device;
692 ID3D11Device_AddRef(*device);
695 static HRESULT STDMETHODCALLTYPE d3d11_rasterizer_state_GetPrivateData(ID3D11RasterizerState *iface,
696 REFGUID guid, UINT *data_size, void *data)
698 struct d3d_rasterizer_state *state = impl_from_ID3D11RasterizerState(iface);
700 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
702 return d3d_get_private_data(&state->private_store, guid, data_size, data);
705 static HRESULT STDMETHODCALLTYPE d3d11_rasterizer_state_SetPrivateData(ID3D11RasterizerState *iface,
706 REFGUID guid, UINT data_size, const void *data)
708 struct d3d_rasterizer_state *state = impl_from_ID3D11RasterizerState(iface);
710 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
712 return d3d_set_private_data(&state->private_store, guid, data_size, data);
715 static HRESULT STDMETHODCALLTYPE d3d11_rasterizer_state_SetPrivateDataInterface(ID3D11RasterizerState *iface,
716 REFGUID guid, const IUnknown *data)
718 struct d3d_rasterizer_state *state = impl_from_ID3D11RasterizerState(iface);
720 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
722 return d3d_set_private_data_interface(&state->private_store, guid, data);
725 static void STDMETHODCALLTYPE d3d11_rasterizer_state_GetDesc(ID3D11RasterizerState *iface,
726 D3D11_RASTERIZER_DESC *desc)
728 struct d3d_rasterizer_state *state = impl_from_ID3D11RasterizerState(iface);
730 TRACE("iface %p, desc %p.\n", iface, desc);
732 *desc = state->desc;
735 static const struct ID3D11RasterizerStateVtbl d3d11_rasterizer_state_vtbl =
737 /* IUnknown methods */
738 d3d11_rasterizer_state_QueryInterface,
739 d3d11_rasterizer_state_AddRef,
740 d3d11_rasterizer_state_Release,
741 /* ID3D11DeviceChild methods */
742 d3d11_rasterizer_state_GetDevice,
743 d3d11_rasterizer_state_GetPrivateData,
744 d3d11_rasterizer_state_SetPrivateData,
745 d3d11_rasterizer_state_SetPrivateDataInterface,
746 /* ID3D11RasterizerState methods */
747 d3d11_rasterizer_state_GetDesc,
750 /* ID3D10RasterizerState methods */
752 static inline struct d3d_rasterizer_state *impl_from_ID3D10RasterizerState(ID3D10RasterizerState *iface)
754 return CONTAINING_RECORD(iface, struct d3d_rasterizer_state, ID3D10RasterizerState_iface);
757 /* IUnknown methods */
759 static HRESULT STDMETHODCALLTYPE d3d10_rasterizer_state_QueryInterface(ID3D10RasterizerState *iface,
760 REFIID riid, void **object)
762 struct d3d_rasterizer_state *state = impl_from_ID3D10RasterizerState(iface);
764 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
766 return d3d11_rasterizer_state_QueryInterface(&state->ID3D11RasterizerState_iface, riid, object);
769 static ULONG STDMETHODCALLTYPE d3d10_rasterizer_state_AddRef(ID3D10RasterizerState *iface)
771 struct d3d_rasterizer_state *state = impl_from_ID3D10RasterizerState(iface);
773 TRACE("iface %p.\n", iface);
775 return d3d11_rasterizer_state_AddRef(&state->ID3D11RasterizerState_iface);
778 static ULONG STDMETHODCALLTYPE d3d10_rasterizer_state_Release(ID3D10RasterizerState *iface)
780 struct d3d_rasterizer_state *state = impl_from_ID3D10RasterizerState(iface);
782 TRACE("iface %p.\n", state);
784 return d3d11_rasterizer_state_Release(&state->ID3D11RasterizerState_iface);
787 /* ID3D10DeviceChild methods */
789 static void STDMETHODCALLTYPE d3d10_rasterizer_state_GetDevice(ID3D10RasterizerState *iface, ID3D10Device **device)
791 struct d3d_rasterizer_state *state = impl_from_ID3D10RasterizerState(iface);
793 TRACE("iface %p, device %p.\n", iface, device);
795 ID3D11Device_QueryInterface(state->device, &IID_ID3D10Device, (void **)device);
798 static HRESULT STDMETHODCALLTYPE d3d10_rasterizer_state_GetPrivateData(ID3D10RasterizerState *iface,
799 REFGUID guid, UINT *data_size, void *data)
801 struct d3d_rasterizer_state *state = impl_from_ID3D10RasterizerState(iface);
803 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
804 iface, debugstr_guid(guid), data_size, data);
806 return d3d_get_private_data(&state->private_store, guid, data_size, data);
809 static HRESULT STDMETHODCALLTYPE d3d10_rasterizer_state_SetPrivateData(ID3D10RasterizerState *iface,
810 REFGUID guid, UINT data_size, const void *data)
812 struct d3d_rasterizer_state *state = impl_from_ID3D10RasterizerState(iface);
814 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
815 iface, debugstr_guid(guid), data_size, data);
817 return d3d_set_private_data(&state->private_store, guid, data_size, data);
820 static HRESULT STDMETHODCALLTYPE d3d10_rasterizer_state_SetPrivateDataInterface(ID3D10RasterizerState *iface,
821 REFGUID guid, const IUnknown *data)
823 struct d3d_rasterizer_state *state = impl_from_ID3D10RasterizerState(iface);
825 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
827 return d3d_set_private_data_interface(&state->private_store, guid, data);
830 /* ID3D10RasterizerState methods */
832 static void STDMETHODCALLTYPE d3d10_rasterizer_state_GetDesc(ID3D10RasterizerState *iface,
833 D3D10_RASTERIZER_DESC *desc)
835 struct d3d_rasterizer_state *state = impl_from_ID3D10RasterizerState(iface);
837 TRACE("iface %p, desc %p.\n", iface, desc);
839 memcpy(desc, &state->desc, sizeof(*desc));
842 static const struct ID3D10RasterizerStateVtbl d3d10_rasterizer_state_vtbl =
844 /* IUnknown methods */
845 d3d10_rasterizer_state_QueryInterface,
846 d3d10_rasterizer_state_AddRef,
847 d3d10_rasterizer_state_Release,
848 /* ID3D10DeviceChild methods */
849 d3d10_rasterizer_state_GetDevice,
850 d3d10_rasterizer_state_GetPrivateData,
851 d3d10_rasterizer_state_SetPrivateData,
852 d3d10_rasterizer_state_SetPrivateDataInterface,
853 /* ID3D10RasterizerState methods */
854 d3d10_rasterizer_state_GetDesc,
857 static void STDMETHODCALLTYPE d3d_rasterizer_state_wined3d_object_destroyed(void *parent)
859 struct d3d_rasterizer_state *state = parent;
860 struct d3d_device *device = impl_from_ID3D11Device(state->device);
862 wine_rb_remove(&device->rasterizer_states, &state->entry);
863 wined3d_private_store_cleanup(&state->private_store);
864 HeapFree(GetProcessHeap(), 0, parent);
867 static const struct wined3d_parent_ops d3d_rasterizer_state_wined3d_parent_ops =
869 d3d_rasterizer_state_wined3d_object_destroyed,
872 HRESULT d3d_rasterizer_state_init(struct d3d_rasterizer_state *state, struct d3d_device *device,
873 const D3D11_RASTERIZER_DESC *desc)
875 struct wined3d_rasterizer_state_desc wined3d_desc;
876 HRESULT hr;
878 state->ID3D11RasterizerState_iface.lpVtbl = &d3d11_rasterizer_state_vtbl;
879 state->ID3D10RasterizerState_iface.lpVtbl = &d3d10_rasterizer_state_vtbl;
880 state->refcount = 1;
881 wined3d_mutex_lock();
882 wined3d_private_store_init(&state->private_store);
883 state->desc = *desc;
885 if (wine_rb_put(&device->rasterizer_states, desc, &state->entry) == -1)
887 ERR("Failed to insert rasterizer state entry.\n");
888 wined3d_private_store_cleanup(&state->private_store);
889 wined3d_mutex_unlock();
890 return E_FAIL;
893 wined3d_desc.front_ccw = desc->FrontCounterClockwise;
895 /* We cannot fail after creating a wined3d_rasterizer_state object. It
896 * would lead to double free. */
897 if (FAILED(hr = wined3d_rasterizer_state_create(device->wined3d_device, &wined3d_desc,
898 state, &d3d_rasterizer_state_wined3d_parent_ops, &state->wined3d_state)))
900 WARN("Failed to create wined3d rasterizer state, hr %#x.\n", hr);
901 wined3d_private_store_cleanup(&state->private_store);
902 wine_rb_remove(&device->rasterizer_states, &state->entry);
903 wined3d_mutex_unlock();
904 return hr;
906 wined3d_mutex_unlock();
908 ID3D11Device_AddRef(state->device = &device->ID3D11Device_iface);
910 return S_OK;
913 struct d3d_rasterizer_state *unsafe_impl_from_ID3D11RasterizerState(ID3D11RasterizerState *iface)
915 if (!iface)
916 return NULL;
917 assert(iface->lpVtbl == &d3d11_rasterizer_state_vtbl);
919 return impl_from_ID3D11RasterizerState(iface);
922 struct d3d_rasterizer_state *unsafe_impl_from_ID3D10RasterizerState(ID3D10RasterizerState *iface)
924 if (!iface)
925 return NULL;
926 assert(iface->lpVtbl == &d3d10_rasterizer_state_vtbl);
928 return impl_from_ID3D10RasterizerState(iface);
931 /* ID3D11SampleState methods */
933 static inline struct d3d_sampler_state *impl_from_ID3D11SamplerState(ID3D11SamplerState *iface)
935 return CONTAINING_RECORD(iface, struct d3d_sampler_state, ID3D11SamplerState_iface);
938 static HRESULT STDMETHODCALLTYPE d3d11_sampler_state_QueryInterface(ID3D11SamplerState *iface,
939 REFIID riid, void **object)
941 struct d3d_sampler_state *state = impl_from_ID3D11SamplerState(iface);
943 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
945 if (IsEqualGUID(riid, &IID_ID3D11SamplerState)
946 || IsEqualGUID(riid, &IID_ID3D11DeviceChild)
947 || IsEqualGUID(riid, &IID_IUnknown))
949 ID3D11SamplerState_AddRef(iface);
950 *object = iface;
951 return S_OK;
954 if (IsEqualGUID(riid, &IID_ID3D10SamplerState)
955 || IsEqualGUID(riid, &IID_ID3D10DeviceChild))
957 ID3D10SamplerState_AddRef(&state->ID3D10SamplerState_iface);
958 *object = &state->ID3D10SamplerState_iface;
959 return S_OK;
962 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
964 *object = NULL;
965 return E_NOINTERFACE;
968 static ULONG STDMETHODCALLTYPE d3d11_sampler_state_AddRef(ID3D11SamplerState *iface)
970 struct d3d_sampler_state *state = impl_from_ID3D11SamplerState(iface);
971 ULONG refcount = InterlockedIncrement(&state->refcount);
973 TRACE("%p increasing refcount to %u.\n", state, refcount);
975 if (refcount == 1)
977 ID3D11Device_AddRef(state->device);
978 wined3d_mutex_lock();
979 wined3d_sampler_incref(state->wined3d_sampler);
980 wined3d_mutex_unlock();
983 return refcount;
986 static ULONG STDMETHODCALLTYPE d3d11_sampler_state_Release(ID3D11SamplerState *iface)
988 struct d3d_sampler_state *state = impl_from_ID3D11SamplerState(iface);
989 ULONG refcount = InterlockedDecrement(&state->refcount);
991 TRACE("%p decreasing refcount to %u.\n", state, refcount);
993 if (!refcount)
995 ID3D11Device *device = state->device;
997 wined3d_mutex_lock();
998 wined3d_sampler_decref(state->wined3d_sampler);
999 wined3d_mutex_unlock();
1001 ID3D11Device_Release(device);
1004 return refcount;
1007 static void STDMETHODCALLTYPE d3d11_sampler_state_GetDevice(ID3D11SamplerState *iface,
1008 ID3D11Device **device)
1010 struct d3d_sampler_state *state = impl_from_ID3D11SamplerState(iface);
1012 TRACE("iface %p, device %p.\n", iface, device);
1014 *device = state->device;
1015 ID3D11Device_AddRef(*device);
1018 static HRESULT STDMETHODCALLTYPE d3d11_sampler_state_GetPrivateData(ID3D11SamplerState *iface,
1019 REFGUID guid, UINT *data_size, void *data)
1021 struct d3d_sampler_state *state = impl_from_ID3D11SamplerState(iface);
1023 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
1025 return d3d_get_private_data(&state->private_store, guid, data_size, data);
1028 static HRESULT STDMETHODCALLTYPE d3d11_sampler_state_SetPrivateData(ID3D11SamplerState *iface,
1029 REFGUID guid, UINT data_size, const void *data)
1031 struct d3d_sampler_state *state = impl_from_ID3D11SamplerState(iface);
1033 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
1035 return d3d_set_private_data(&state->private_store, guid, data_size, data);
1038 static HRESULT STDMETHODCALLTYPE d3d11_sampler_state_SetPrivateDataInterface(ID3D11SamplerState *iface,
1039 REFGUID guid, const IUnknown *data)
1041 struct d3d_sampler_state *state = impl_from_ID3D11SamplerState(iface);
1043 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
1045 return d3d_set_private_data_interface(&state->private_store, guid, data);
1048 static void STDMETHODCALLTYPE d3d11_sampler_state_GetDesc(ID3D11SamplerState *iface,
1049 D3D11_SAMPLER_DESC *desc)
1051 struct d3d_sampler_state *state = impl_from_ID3D11SamplerState(iface);
1053 TRACE("iface %p, desc %p.\n", iface, desc);
1055 *desc = state->desc;
1058 static const struct ID3D11SamplerStateVtbl d3d11_sampler_state_vtbl =
1060 /* IUnknown methods */
1061 d3d11_sampler_state_QueryInterface,
1062 d3d11_sampler_state_AddRef,
1063 d3d11_sampler_state_Release,
1064 /* ID3D11DeviceChild methods */
1065 d3d11_sampler_state_GetDevice,
1066 d3d11_sampler_state_GetPrivateData,
1067 d3d11_sampler_state_SetPrivateData,
1068 d3d11_sampler_state_SetPrivateDataInterface,
1069 /* ID3D11SamplerState methods */
1070 d3d11_sampler_state_GetDesc,
1073 /* ID3D10SamplerState methods */
1075 static inline struct d3d_sampler_state *impl_from_ID3D10SamplerState(ID3D10SamplerState *iface)
1077 return CONTAINING_RECORD(iface, struct d3d_sampler_state, ID3D10SamplerState_iface);
1080 /* IUnknown methods */
1082 static HRESULT STDMETHODCALLTYPE d3d10_sampler_state_QueryInterface(ID3D10SamplerState *iface,
1083 REFIID riid, void **object)
1085 struct d3d_sampler_state *state = impl_from_ID3D10SamplerState(iface);
1087 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
1089 return d3d11_sampler_state_QueryInterface(&state->ID3D11SamplerState_iface, riid, object);
1092 static ULONG STDMETHODCALLTYPE d3d10_sampler_state_AddRef(ID3D10SamplerState *iface)
1094 struct d3d_sampler_state *state = impl_from_ID3D10SamplerState(iface);
1096 TRACE("iface %p.\n", iface);
1098 return d3d11_sampler_state_AddRef(&state->ID3D11SamplerState_iface);
1101 static ULONG STDMETHODCALLTYPE d3d10_sampler_state_Release(ID3D10SamplerState *iface)
1103 struct d3d_sampler_state *state = impl_from_ID3D10SamplerState(iface);
1105 TRACE("iface %p.\n", iface);
1107 return d3d11_sampler_state_Release(&state->ID3D11SamplerState_iface);
1110 /* ID3D10DeviceChild methods */
1112 static void STDMETHODCALLTYPE d3d10_sampler_state_GetDevice(ID3D10SamplerState *iface, ID3D10Device **device)
1114 struct d3d_sampler_state *state = impl_from_ID3D10SamplerState(iface);
1116 TRACE("iface %p, device %p.\n", iface, device);
1118 ID3D11Device_QueryInterface(state->device, &IID_ID3D10Device, (void **)device);
1121 static HRESULT STDMETHODCALLTYPE d3d10_sampler_state_GetPrivateData(ID3D10SamplerState *iface,
1122 REFGUID guid, UINT *data_size, void *data)
1124 struct d3d_sampler_state *state = impl_from_ID3D10SamplerState(iface);
1126 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
1127 iface, debugstr_guid(guid), data_size, data);
1129 return d3d_get_private_data(&state->private_store, guid, data_size, data);
1132 static HRESULT STDMETHODCALLTYPE d3d10_sampler_state_SetPrivateData(ID3D10SamplerState *iface,
1133 REFGUID guid, UINT data_size, const void *data)
1135 struct d3d_sampler_state *state = impl_from_ID3D10SamplerState(iface);
1137 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
1138 iface, debugstr_guid(guid), data_size, data);
1140 return d3d_set_private_data(&state->private_store, guid, data_size, data);
1143 static HRESULT STDMETHODCALLTYPE d3d10_sampler_state_SetPrivateDataInterface(ID3D10SamplerState *iface,
1144 REFGUID guid, const IUnknown *data)
1146 struct d3d_sampler_state *state = impl_from_ID3D10SamplerState(iface);
1148 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
1150 return d3d_set_private_data_interface(&state->private_store, guid, data);
1153 /* ID3D10SamplerState methods */
1155 static void STDMETHODCALLTYPE d3d10_sampler_state_GetDesc(ID3D10SamplerState *iface,
1156 D3D10_SAMPLER_DESC *desc)
1158 struct d3d_sampler_state *state = impl_from_ID3D10SamplerState(iface);
1160 TRACE("iface %p, desc %p.\n", iface, desc);
1162 memcpy(desc, &state->desc, sizeof(*desc));
1165 static const struct ID3D10SamplerStateVtbl d3d10_sampler_state_vtbl =
1167 /* IUnknown methods */
1168 d3d10_sampler_state_QueryInterface,
1169 d3d10_sampler_state_AddRef,
1170 d3d10_sampler_state_Release,
1171 /* ID3D10DeviceChild methods */
1172 d3d10_sampler_state_GetDevice,
1173 d3d10_sampler_state_GetPrivateData,
1174 d3d10_sampler_state_SetPrivateData,
1175 d3d10_sampler_state_SetPrivateDataInterface,
1176 /* ID3D10SamplerState methods */
1177 d3d10_sampler_state_GetDesc,
1180 static void STDMETHODCALLTYPE d3d_sampler_wined3d_object_destroyed(void *parent)
1182 struct d3d_sampler_state *state = parent;
1183 struct d3d_device *device = impl_from_ID3D11Device(state->device);
1185 wine_rb_remove(&device->sampler_states, &state->entry);
1186 wined3d_private_store_cleanup(&state->private_store);
1187 HeapFree(GetProcessHeap(), 0, parent);
1190 static const struct wined3d_parent_ops d3d_sampler_wined3d_parent_ops =
1192 d3d_sampler_wined3d_object_destroyed,
1195 static enum wined3d_texture_address wined3d_texture_address_from_d3d11(enum D3D11_TEXTURE_ADDRESS_MODE t)
1197 return (enum wined3d_texture_address)t;
1200 static enum wined3d_texture_filter_type wined3d_texture_filter_mip_from_d3d11(enum D3D11_FILTER f)
1202 if (D3D11_DECODE_MIP_FILTER(f) == D3D11_FILTER_TYPE_LINEAR)
1203 return WINED3D_TEXF_LINEAR;
1204 return WINED3D_TEXF_POINT;
1207 static enum wined3d_texture_filter_type wined3d_texture_filter_mag_from_d3d11(enum D3D11_FILTER f)
1209 if (D3D11_DECODE_MAG_FILTER(f) == D3D11_FILTER_TYPE_LINEAR)
1210 return WINED3D_TEXF_LINEAR;
1211 return WINED3D_TEXF_POINT;
1214 static enum wined3d_texture_filter_type wined3d_texture_filter_min_from_d3d11(enum D3D11_FILTER f)
1216 if (D3D11_DECODE_MIN_FILTER(f) == D3D11_FILTER_TYPE_LINEAR)
1217 return WINED3D_TEXF_LINEAR;
1218 return WINED3D_TEXF_POINT;
1221 static BOOL wined3d_texture_compare_from_d3d11(enum D3D11_FILTER f)
1223 return D3D11_DECODE_IS_COMPARISON_FILTER(f);
1226 static enum wined3d_cmp_func wined3d_cmp_func_from_d3d11(D3D11_COMPARISON_FUNC f)
1228 return (enum wined3d_cmp_func)f;
1231 HRESULT d3d_sampler_state_init(struct d3d_sampler_state *state, struct d3d_device *device,
1232 const D3D11_SAMPLER_DESC *desc)
1234 struct wined3d_sampler_desc wined3d_desc;
1235 HRESULT hr;
1237 state->ID3D11SamplerState_iface.lpVtbl = &d3d11_sampler_state_vtbl;
1238 state->ID3D10SamplerState_iface.lpVtbl = &d3d10_sampler_state_vtbl;
1239 state->refcount = 1;
1240 wined3d_mutex_lock();
1241 wined3d_private_store_init(&state->private_store);
1242 state->desc = *desc;
1244 wined3d_desc.address_u = wined3d_texture_address_from_d3d11(desc->AddressU);
1245 wined3d_desc.address_v = wined3d_texture_address_from_d3d11(desc->AddressV);
1246 wined3d_desc.address_w = wined3d_texture_address_from_d3d11(desc->AddressW);
1247 memcpy(wined3d_desc.border_color, desc->BorderColor, sizeof(wined3d_desc.border_color));
1248 wined3d_desc.mag_filter = wined3d_texture_filter_mag_from_d3d11(desc->Filter);
1249 wined3d_desc.min_filter = wined3d_texture_filter_min_from_d3d11(desc->Filter);
1250 wined3d_desc.mip_filter = wined3d_texture_filter_mip_from_d3d11(desc->Filter);
1251 wined3d_desc.lod_bias = desc->MipLODBias;
1252 wined3d_desc.min_lod = desc->MinLOD;
1253 wined3d_desc.max_lod = desc->MaxLOD;
1254 wined3d_desc.mip_base_level = 0;
1255 wined3d_desc.max_anisotropy = D3D11_DECODE_IS_ANISOTROPIC_FILTER(desc->Filter) ? desc->MaxAnisotropy : 1;
1256 wined3d_desc.compare = wined3d_texture_compare_from_d3d11(desc->Filter);
1257 wined3d_desc.comparison_func = wined3d_cmp_func_from_d3d11(desc->ComparisonFunc);
1258 wined3d_desc.srgb_decode = TRUE;
1260 if (wine_rb_put(&device->sampler_states, desc, &state->entry) == -1)
1262 ERR("Failed to insert sampler state entry.\n");
1263 wined3d_private_store_cleanup(&state->private_store);
1264 wined3d_mutex_unlock();
1265 return E_FAIL;
1268 /* We cannot fail after creating a wined3d_sampler object. It would lead to
1269 * double free. */
1270 if (FAILED(hr = wined3d_sampler_create(device->wined3d_device, &wined3d_desc,
1271 state, &d3d_sampler_wined3d_parent_ops, &state->wined3d_sampler)))
1273 WARN("Failed to create wined3d sampler, hr %#x.\n", hr);
1274 wined3d_private_store_cleanup(&state->private_store);
1275 wine_rb_remove(&device->sampler_states, &state->entry);
1276 wined3d_mutex_unlock();
1277 return hr;
1279 wined3d_mutex_unlock();
1281 state->device = &device->ID3D11Device_iface;
1282 ID3D11Device_AddRef(state->device);
1284 return S_OK;
1287 struct d3d_sampler_state *unsafe_impl_from_ID3D11SamplerState(ID3D11SamplerState *iface)
1289 if (!iface)
1290 return NULL;
1291 assert(iface->lpVtbl == &d3d11_sampler_state_vtbl);
1293 return impl_from_ID3D11SamplerState(iface);
1296 struct d3d_sampler_state *unsafe_impl_from_ID3D10SamplerState(ID3D10SamplerState *iface)
1298 if (!iface)
1299 return NULL;
1300 assert(iface->lpVtbl == &d3d10_sampler_state_vtbl);
1302 return impl_from_ID3D10SamplerState(iface);