d3d8: Get rid of the format switching code in d3d8_device_CopyRects().
[wine.git] / dlls / d3d10core / state.c
blobc816803345f3ce3a84a1cf8b08fa2ce3a9e60e97
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 "d3d10core_private.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(d3d10core);
27 static inline struct d3d10_blend_state *impl_from_ID3D10BlendState(ID3D10BlendState *iface)
29 return CONTAINING_RECORD(iface, struct d3d10_blend_state, ID3D10BlendState_iface);
32 /* IUnknown methods */
34 static HRESULT STDMETHODCALLTYPE d3d10_blend_state_QueryInterface(ID3D10BlendState *iface,
35 REFIID riid, void **object)
37 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
39 if (IsEqualGUID(riid, &IID_ID3D10BlendState)
40 || IsEqualGUID(riid, &IID_ID3D10DeviceChild)
41 || IsEqualGUID(riid, &IID_IUnknown))
43 IUnknown_AddRef(iface);
44 *object = iface;
45 return S_OK;
48 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
50 *object = NULL;
51 return E_NOINTERFACE;
54 static ULONG STDMETHODCALLTYPE d3d10_blend_state_AddRef(ID3D10BlendState *iface)
56 struct d3d10_blend_state *This = impl_from_ID3D10BlendState(iface);
57 ULONG refcount = InterlockedIncrement(&This->refcount);
59 TRACE("%p increasing refcount to %u.\n", This, refcount);
61 return refcount;
64 static ULONG STDMETHODCALLTYPE d3d10_blend_state_Release(ID3D10BlendState *iface)
66 struct d3d10_blend_state *state = impl_from_ID3D10BlendState(iface);
67 ULONG refcount = InterlockedDecrement(&state->refcount);
69 TRACE("%p decreasing refcount to %u.\n", state, refcount);
71 if (!refcount)
73 struct d3d10_device *device = impl_from_ID3D10Device(state->device);
74 wine_rb_remove(&device->blend_states, &state->desc);
75 ID3D10Device1_Release(state->device);
76 HeapFree(GetProcessHeap(), 0, state);
79 return refcount;
82 /* ID3D10DeviceChild methods */
84 static void STDMETHODCALLTYPE d3d10_blend_state_GetDevice(ID3D10BlendState *iface, ID3D10Device **device)
86 struct d3d10_blend_state *state = impl_from_ID3D10BlendState(iface);
88 TRACE("iface %p, device %p.\n", iface, device);
90 *device = (ID3D10Device *)state->device;
91 ID3D10Device_AddRef(*device);
94 static HRESULT STDMETHODCALLTYPE d3d10_blend_state_GetPrivateData(ID3D10BlendState *iface,
95 REFGUID guid, UINT *data_size, void *data)
97 FIXME("iface %p, guid %s, data_size %p, data %p stub!\n",
98 iface, debugstr_guid(guid), data_size, data);
100 return E_NOTIMPL;
103 static HRESULT STDMETHODCALLTYPE d3d10_blend_state_SetPrivateData(ID3D10BlendState *iface,
104 REFGUID guid, UINT data_size, const void *data)
106 FIXME("iface %p, guid %s, data_size %u, data %p stub!\n",
107 iface, debugstr_guid(guid), data_size, data);
109 return E_NOTIMPL;
112 static HRESULT STDMETHODCALLTYPE d3d10_blend_state_SetPrivateDataInterface(ID3D10BlendState *iface,
113 REFGUID guid, const IUnknown *data)
115 FIXME("iface %p, guid %s, data %p stub!\n", iface, debugstr_guid(guid), data);
117 return E_NOTIMPL;
120 /* ID3D10BlendState methods */
122 static void STDMETHODCALLTYPE d3d10_blend_state_GetDesc(ID3D10BlendState *iface,
123 D3D10_BLEND_DESC *desc)
125 struct d3d10_blend_state *state = impl_from_ID3D10BlendState(iface);
127 TRACE("iface %p, desc %p.\n", iface, desc);
129 *desc = state->desc;
132 static const struct ID3D10BlendStateVtbl d3d10_blend_state_vtbl =
134 /* IUnknown methods */
135 d3d10_blend_state_QueryInterface,
136 d3d10_blend_state_AddRef,
137 d3d10_blend_state_Release,
138 /* ID3D10DeviceChild methods */
139 d3d10_blend_state_GetDevice,
140 d3d10_blend_state_GetPrivateData,
141 d3d10_blend_state_SetPrivateData,
142 d3d10_blend_state_SetPrivateDataInterface,
143 /* ID3D10BlendState methods */
144 d3d10_blend_state_GetDesc,
147 HRESULT d3d10_blend_state_init(struct d3d10_blend_state *state, struct d3d10_device *device,
148 const D3D10_BLEND_DESC *desc)
150 state->ID3D10BlendState_iface.lpVtbl = &d3d10_blend_state_vtbl;
151 state->refcount = 1;
152 state->desc = *desc;
154 if (wine_rb_put(&device->blend_states, desc, &state->entry) == -1)
156 ERR("Failed to insert blend state entry.\n");
157 return E_FAIL;
160 state->device = &device->ID3D10Device1_iface;
161 ID3D10Device1_AddRef(state->device);
163 return S_OK;
166 struct d3d10_blend_state *unsafe_impl_from_ID3D10BlendState(ID3D10BlendState *iface)
168 if (!iface)
169 return NULL;
170 assert(iface->lpVtbl == &d3d10_blend_state_vtbl);
172 return impl_from_ID3D10BlendState(iface);
175 static inline struct d3d10_depthstencil_state *impl_from_ID3D10DepthStencilState(ID3D10DepthStencilState *iface)
177 return CONTAINING_RECORD(iface, struct d3d10_depthstencil_state, ID3D10DepthStencilState_iface);
180 /* IUnknown methods */
182 static HRESULT STDMETHODCALLTYPE d3d10_depthstencil_state_QueryInterface(ID3D10DepthStencilState *iface,
183 REFIID riid, void **object)
185 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
187 if (IsEqualGUID(riid, &IID_ID3D10DepthStencilState)
188 || IsEqualGUID(riid, &IID_ID3D10DeviceChild)
189 || IsEqualGUID(riid, &IID_IUnknown))
191 IUnknown_AddRef(iface);
192 *object = iface;
193 return S_OK;
196 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
198 *object = NULL;
199 return E_NOINTERFACE;
202 static ULONG STDMETHODCALLTYPE d3d10_depthstencil_state_AddRef(ID3D10DepthStencilState *iface)
204 struct d3d10_depthstencil_state *This = impl_from_ID3D10DepthStencilState(iface);
205 ULONG refcount = InterlockedIncrement(&This->refcount);
207 TRACE("%p increasing refcount to %u.\n", This, refcount);
209 return refcount;
212 static ULONG STDMETHODCALLTYPE d3d10_depthstencil_state_Release(ID3D10DepthStencilState *iface)
214 struct d3d10_depthstencil_state *state = impl_from_ID3D10DepthStencilState(iface);
215 ULONG refcount = InterlockedDecrement(&state->refcount);
217 TRACE("%p decreasing refcount to %u.\n", state, refcount);
219 if (!refcount)
221 struct d3d10_device *device = impl_from_ID3D10Device(state->device);
222 wine_rb_remove(&device->depthstencil_states, &state->desc);
223 ID3D10Device1_Release(state->device);
224 HeapFree(GetProcessHeap(), 0, state);
227 return refcount;
230 /* ID3D10DeviceChild methods */
232 static void STDMETHODCALLTYPE d3d10_depthstencil_state_GetDevice(ID3D10DepthStencilState *iface, ID3D10Device **device)
234 struct d3d10_depthstencil_state *state = impl_from_ID3D10DepthStencilState(iface);
236 TRACE("iface %p, device %p.\n", iface, device);
238 *device = (ID3D10Device *)state->device;
239 ID3D10Device_AddRef(*device);
242 static HRESULT STDMETHODCALLTYPE d3d10_depthstencil_state_GetPrivateData(ID3D10DepthStencilState *iface,
243 REFGUID guid, UINT *data_size, void *data)
245 FIXME("iface %p, guid %s, data_size %p, data %p stub!\n",
246 iface, debugstr_guid(guid), data_size, data);
248 return E_NOTIMPL;
251 static HRESULT STDMETHODCALLTYPE d3d10_depthstencil_state_SetPrivateData(ID3D10DepthStencilState *iface,
252 REFGUID guid, UINT data_size, const void *data)
254 FIXME("iface %p, guid %s, data_size %u, data %p stub!\n",
255 iface, debugstr_guid(guid), data_size, data);
257 return E_NOTIMPL;
260 static HRESULT STDMETHODCALLTYPE d3d10_depthstencil_state_SetPrivateDataInterface(ID3D10DepthStencilState *iface,
261 REFGUID guid, const IUnknown *data)
263 FIXME("iface %p, guid %s, data %p stub!\n", iface, debugstr_guid(guid), data);
265 return E_NOTIMPL;
268 /* ID3D10DepthStencilState methods */
270 static void STDMETHODCALLTYPE d3d10_depthstencil_state_GetDesc(ID3D10DepthStencilState *iface,
271 D3D10_DEPTH_STENCIL_DESC *desc)
273 struct d3d10_depthstencil_state *state = impl_from_ID3D10DepthStencilState(iface);
275 TRACE("iface %p, desc %p.\n", iface, desc);
277 *desc = state->desc;
280 static const struct ID3D10DepthStencilStateVtbl d3d10_depthstencil_state_vtbl =
282 /* IUnknown methods */
283 d3d10_depthstencil_state_QueryInterface,
284 d3d10_depthstencil_state_AddRef,
285 d3d10_depthstencil_state_Release,
286 /* ID3D10DeviceChild methods */
287 d3d10_depthstencil_state_GetDevice,
288 d3d10_depthstencil_state_GetPrivateData,
289 d3d10_depthstencil_state_SetPrivateData,
290 d3d10_depthstencil_state_SetPrivateDataInterface,
291 /* ID3D10DepthStencilState methods */
292 d3d10_depthstencil_state_GetDesc,
295 HRESULT d3d10_depthstencil_state_init(struct d3d10_depthstencil_state *state, struct d3d10_device *device,
296 const D3D10_DEPTH_STENCIL_DESC *desc)
298 state->ID3D10DepthStencilState_iface.lpVtbl = &d3d10_depthstencil_state_vtbl;
299 state->refcount = 1;
300 state->desc = *desc;
302 if (wine_rb_put(&device->depthstencil_states, desc, &state->entry) == -1)
304 ERR("Failed to insert depthstencil state entry.\n");
305 return E_FAIL;
308 state->device = &device->ID3D10Device1_iface;
309 ID3D10Device1_AddRef(state->device);
311 return S_OK;
314 struct d3d10_depthstencil_state *unsafe_impl_from_ID3D10DepthStencilState(ID3D10DepthStencilState *iface)
316 if (!iface)
317 return NULL;
318 assert(iface->lpVtbl == &d3d10_depthstencil_state_vtbl);
320 return impl_from_ID3D10DepthStencilState(iface);
323 static inline struct d3d10_rasterizer_state *impl_from_ID3D10RasterizerState(ID3D10RasterizerState *iface)
325 return CONTAINING_RECORD(iface, struct d3d10_rasterizer_state, ID3D10RasterizerState_iface);
328 /* IUnknown methods */
330 static HRESULT STDMETHODCALLTYPE d3d10_rasterizer_state_QueryInterface(ID3D10RasterizerState *iface,
331 REFIID riid, void **object)
333 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
335 if (IsEqualGUID(riid, &IID_ID3D10RasterizerState)
336 || IsEqualGUID(riid, &IID_ID3D10DeviceChild)
337 || IsEqualGUID(riid, &IID_IUnknown))
339 IUnknown_AddRef(iface);
340 *object = iface;
341 return S_OK;
344 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
346 *object = NULL;
347 return E_NOINTERFACE;
350 static ULONG STDMETHODCALLTYPE d3d10_rasterizer_state_AddRef(ID3D10RasterizerState *iface)
352 struct d3d10_rasterizer_state *This = impl_from_ID3D10RasterizerState(iface);
353 ULONG refcount = InterlockedIncrement(&This->refcount);
355 TRACE("%p increasing refcount to %u.\n", This, refcount);
357 return refcount;
360 static ULONG STDMETHODCALLTYPE d3d10_rasterizer_state_Release(ID3D10RasterizerState *iface)
362 struct d3d10_rasterizer_state *state = impl_from_ID3D10RasterizerState(iface);
363 ULONG refcount = InterlockedDecrement(&state->refcount);
365 TRACE("%p decreasing refcount to %u.\n", state, refcount);
367 if (!refcount)
369 struct d3d10_device *device = impl_from_ID3D10Device(state->device);
370 wine_rb_remove(&device->rasterizer_states, &state->desc);
371 ID3D10Device1_Release(state->device);
372 HeapFree(GetProcessHeap(), 0, state);
375 return refcount;
378 /* ID3D10DeviceChild methods */
380 static void STDMETHODCALLTYPE d3d10_rasterizer_state_GetDevice(ID3D10RasterizerState *iface, ID3D10Device **device)
382 struct d3d10_rasterizer_state *state = impl_from_ID3D10RasterizerState(iface);
384 TRACE("iface %p, device %p.\n", iface, device);
386 *device = (ID3D10Device *)state->device;
387 ID3D10Device_AddRef(*device);
390 static HRESULT STDMETHODCALLTYPE d3d10_rasterizer_state_GetPrivateData(ID3D10RasterizerState *iface,
391 REFGUID guid, UINT *data_size, void *data)
393 FIXME("iface %p, guid %s, data_size %p, data %p stub!\n",
394 iface, debugstr_guid(guid), data_size, data);
396 return E_NOTIMPL;
399 static HRESULT STDMETHODCALLTYPE d3d10_rasterizer_state_SetPrivateData(ID3D10RasterizerState *iface,
400 REFGUID guid, UINT data_size, const void *data)
402 FIXME("iface %p, guid %s, data_size %u, data %p stub!\n",
403 iface, debugstr_guid(guid), data_size, data);
405 return E_NOTIMPL;
408 static HRESULT STDMETHODCALLTYPE d3d10_rasterizer_state_SetPrivateDataInterface(ID3D10RasterizerState *iface,
409 REFGUID guid, const IUnknown *data)
411 FIXME("iface %p, guid %s, data %p stub!\n", iface, debugstr_guid(guid), data);
413 return E_NOTIMPL;
416 /* ID3D10RasterizerState methods */
418 static void STDMETHODCALLTYPE d3d10_rasterizer_state_GetDesc(ID3D10RasterizerState *iface,
419 D3D10_RASTERIZER_DESC *desc)
421 struct d3d10_rasterizer_state *state = impl_from_ID3D10RasterizerState(iface);
423 TRACE("iface %p, desc %p.\n", iface, desc);
425 *desc = state->desc;
428 static const struct ID3D10RasterizerStateVtbl d3d10_rasterizer_state_vtbl =
430 /* IUnknown methods */
431 d3d10_rasterizer_state_QueryInterface,
432 d3d10_rasterizer_state_AddRef,
433 d3d10_rasterizer_state_Release,
434 /* ID3D10DeviceChild methods */
435 d3d10_rasterizer_state_GetDevice,
436 d3d10_rasterizer_state_GetPrivateData,
437 d3d10_rasterizer_state_SetPrivateData,
438 d3d10_rasterizer_state_SetPrivateDataInterface,
439 /* ID3D10RasterizerState methods */
440 d3d10_rasterizer_state_GetDesc,
443 HRESULT d3d10_rasterizer_state_init(struct d3d10_rasterizer_state *state, struct d3d10_device *device,
444 const D3D10_RASTERIZER_DESC *desc)
446 state->ID3D10RasterizerState_iface.lpVtbl = &d3d10_rasterizer_state_vtbl;
447 state->refcount = 1;
448 state->desc = *desc;
450 if (wine_rb_put(&device->rasterizer_states, desc, &state->entry) == -1)
452 ERR("Failed to insert rasterizer state entry.\n");
453 return E_FAIL;
456 state->device = &device->ID3D10Device1_iface;
457 ID3D10Device1_AddRef(state->device);
459 return S_OK;
462 struct d3d10_rasterizer_state *unsafe_impl_from_ID3D10RasterizerState(ID3D10RasterizerState *iface)
464 if (!iface)
465 return NULL;
466 assert(iface->lpVtbl == &d3d10_rasterizer_state_vtbl);
468 return impl_from_ID3D10RasterizerState(iface);
471 static inline struct d3d10_sampler_state *impl_from_ID3D10SamplerState(ID3D10SamplerState *iface)
473 return CONTAINING_RECORD(iface, struct d3d10_sampler_state, ID3D10SamplerState_iface);
476 /* IUnknown methods */
478 static HRESULT STDMETHODCALLTYPE d3d10_sampler_state_QueryInterface(ID3D10SamplerState *iface,
479 REFIID riid, void **object)
481 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
483 if (IsEqualGUID(riid, &IID_ID3D10SamplerState)
484 || IsEqualGUID(riid, &IID_ID3D10DeviceChild)
485 || IsEqualGUID(riid, &IID_IUnknown))
487 IUnknown_AddRef(iface);
488 *object = iface;
489 return S_OK;
492 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
494 *object = NULL;
495 return E_NOINTERFACE;
498 static ULONG STDMETHODCALLTYPE d3d10_sampler_state_AddRef(ID3D10SamplerState *iface)
500 struct d3d10_sampler_state *This = impl_from_ID3D10SamplerState(iface);
501 ULONG refcount = InterlockedIncrement(&This->refcount);
503 TRACE("%p increasing refcount to %u.\n", This, refcount);
505 return refcount;
508 static ULONG STDMETHODCALLTYPE d3d10_sampler_state_Release(ID3D10SamplerState *iface)
510 struct d3d10_sampler_state *state = impl_from_ID3D10SamplerState(iface);
511 ULONG refcount = InterlockedDecrement(&state->refcount);
513 TRACE("%p decreasing refcount to %u.\n", state, refcount);
515 if (!refcount)
517 struct d3d10_device *device = impl_from_ID3D10Device(state->device);
519 wined3d_sampler_decref(state->wined3d_sampler);
520 wine_rb_remove(&device->sampler_states, &state->desc);
521 ID3D10Device1_Release(state->device);
522 HeapFree(GetProcessHeap(), 0, state);
525 return refcount;
528 /* ID3D10DeviceChild methods */
530 static void STDMETHODCALLTYPE d3d10_sampler_state_GetDevice(ID3D10SamplerState *iface, ID3D10Device **device)
532 struct d3d10_sampler_state *state = impl_from_ID3D10SamplerState(iface);
534 TRACE("iface %p, device %p.\n", iface, device);
536 *device = (ID3D10Device *)state->device;
537 ID3D10Device_AddRef(*device);
540 static HRESULT STDMETHODCALLTYPE d3d10_sampler_state_GetPrivateData(ID3D10SamplerState *iface,
541 REFGUID guid, UINT *data_size, void *data)
543 FIXME("iface %p, guid %s, data_size %p, data %p stub!\n",
544 iface, debugstr_guid(guid), data_size, data);
546 return E_NOTIMPL;
549 static HRESULT STDMETHODCALLTYPE d3d10_sampler_state_SetPrivateData(ID3D10SamplerState *iface,
550 REFGUID guid, UINT data_size, const void *data)
552 FIXME("iface %p, guid %s, data_size %u, data %p stub!\n",
553 iface, debugstr_guid(guid), data_size, data);
555 return E_NOTIMPL;
558 static HRESULT STDMETHODCALLTYPE d3d10_sampler_state_SetPrivateDataInterface(ID3D10SamplerState *iface,
559 REFGUID guid, const IUnknown *data)
561 FIXME("iface %p, guid %s, data %p stub!\n", iface, debugstr_guid(guid), data);
563 return E_NOTIMPL;
566 /* ID3D10SamplerState methods */
568 static void STDMETHODCALLTYPE d3d10_sampler_state_GetDesc(ID3D10SamplerState *iface,
569 D3D10_SAMPLER_DESC *desc)
571 struct d3d10_sampler_state *state = impl_from_ID3D10SamplerState(iface);
573 TRACE("iface %p, desc %p.\n", iface, desc);
575 *desc = state->desc;
578 static const struct ID3D10SamplerStateVtbl d3d10_sampler_state_vtbl =
580 /* IUnknown methods */
581 d3d10_sampler_state_QueryInterface,
582 d3d10_sampler_state_AddRef,
583 d3d10_sampler_state_Release,
584 /* ID3D10DeviceChild methods */
585 d3d10_sampler_state_GetDevice,
586 d3d10_sampler_state_GetPrivateData,
587 d3d10_sampler_state_SetPrivateData,
588 d3d10_sampler_state_SetPrivateDataInterface,
589 /* ID3D10SamplerState methods */
590 d3d10_sampler_state_GetDesc,
593 HRESULT d3d10_sampler_state_init(struct d3d10_sampler_state *state, struct d3d10_device *device,
594 const D3D10_SAMPLER_DESC *desc)
596 HRESULT hr;
598 state->ID3D10SamplerState_iface.lpVtbl = &d3d10_sampler_state_vtbl;
599 state->refcount = 1;
600 state->desc = *desc;
602 if (FAILED(hr = wined3d_sampler_create(state, &state->wined3d_sampler)))
604 WARN("Failed to create wined3d sampler, hr %#x.\n", hr);
605 return hr;
608 if (wine_rb_put(&device->sampler_states, desc, &state->entry) == -1)
610 ERR("Failed to insert sampler state entry.\n");
611 wined3d_sampler_decref(state->wined3d_sampler);
612 return E_FAIL;
615 state->device = &device->ID3D10Device1_iface;
616 ID3D10Device1_AddRef(state->device);
618 return S_OK;
621 struct d3d10_sampler_state *unsafe_impl_from_ID3D10SamplerState(ID3D10SamplerState *iface)
623 if (!iface)
624 return NULL;
625 assert(iface->lpVtbl == &d3d10_sampler_state_vtbl);
627 return impl_from_ID3D10SamplerState(iface);