d3d9/tests: Add some more surface GetDC() tests to test_getdc().
[wine.git] / dlls / d3d11 / view.c
blobc4487d3e6cd7d6600a3d633f29c430642b3ca98c
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 #define NONAMELESSUNION
24 #include "d3d11_private.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(d3d11);
28 static HRESULT set_dsdesc_from_resource(D3D11_DEPTH_STENCIL_VIEW_DESC *desc, ID3D11Resource *resource)
30 D3D11_RESOURCE_DIMENSION dimension;
32 ID3D11Resource_GetType(resource, &dimension);
34 desc->Flags = 0;
36 switch (dimension)
38 case D3D11_RESOURCE_DIMENSION_TEXTURE1D:
40 D3D11_TEXTURE1D_DESC texture_desc;
41 ID3D11Texture1D *texture;
43 if (FAILED(ID3D11Resource_QueryInterface(resource, &IID_ID3D11Texture1D, (void **)&texture)))
45 ERR("Resource of type TEXTURE1D doesn't implement ID3D11Texture1D.\n");
46 return E_INVALIDARG;
49 ID3D11Texture1D_GetDesc(texture, &texture_desc);
50 ID3D11Texture1D_Release(texture);
52 desc->Format = texture_desc.Format;
53 if (texture_desc.ArraySize == 1)
55 desc->ViewDimension = D3D11_DSV_DIMENSION_TEXTURE1D;
56 desc->u.Texture1D.MipSlice = 0;
58 else
60 desc->ViewDimension = D3D11_DSV_DIMENSION_TEXTURE1DARRAY;
61 desc->u.Texture1DArray.MipSlice = 0;
62 desc->u.Texture1DArray.FirstArraySlice = 0;
63 desc->u.Texture1DArray.ArraySize = 1;
66 return S_OK;
69 case D3D11_RESOURCE_DIMENSION_TEXTURE2D:
71 D3D11_TEXTURE2D_DESC texture_desc;
72 ID3D11Texture2D *texture;
74 if (FAILED(ID3D11Resource_QueryInterface(resource, &IID_ID3D11Texture2D, (void **)&texture)))
76 ERR("Resource of type TEXTURE2D doesn't implement ID3D11Texture2D.\n");
77 return E_INVALIDARG;
80 ID3D11Texture2D_GetDesc(texture, &texture_desc);
81 ID3D11Texture2D_Release(texture);
83 desc->Format = texture_desc.Format;
84 if (texture_desc.ArraySize == 1)
86 if (texture_desc.SampleDesc.Count == 1)
88 desc->ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2D;
89 desc->u.Texture2D.MipSlice = 0;
91 else
93 desc->ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DMS;
96 else
98 if (texture_desc.SampleDesc.Count == 1)
100 desc->ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DARRAY;
101 desc->u.Texture2DArray.MipSlice = 0;
102 desc->u.Texture2DArray.FirstArraySlice = 0;
103 desc->u.Texture2DArray.ArraySize = 1;
105 else
107 desc->ViewDimension = D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY;
108 desc->u.Texture2DMSArray.FirstArraySlice = 0;
109 desc->u.Texture2DMSArray.ArraySize = 1;
113 return S_OK;
116 default:
117 FIXME("Unhandled resource dimension %#x.\n", dimension);
118 case D3D11_RESOURCE_DIMENSION_BUFFER:
119 case D3D11_RESOURCE_DIMENSION_TEXTURE3D:
120 return E_INVALIDARG;
124 static HRESULT set_rtdesc_from_resource(D3D11_RENDER_TARGET_VIEW_DESC *desc, ID3D11Resource *resource)
126 D3D11_RESOURCE_DIMENSION dimension;
127 HRESULT hr;
129 ID3D11Resource_GetType(resource, &dimension);
131 switch(dimension)
133 case D3D11_RESOURCE_DIMENSION_TEXTURE1D:
135 ID3D11Texture1D *texture;
136 D3D11_TEXTURE1D_DESC texture_desc;
138 hr = ID3D11Resource_QueryInterface(resource, &IID_ID3D11Texture1D, (void **)&texture);
139 if (FAILED(hr))
141 ERR("Resource of type TEXTURE1D doesn't implement ID3D11Texture1D?\n");
142 return E_INVALIDARG;
145 ID3D11Texture1D_GetDesc(texture, &texture_desc);
146 ID3D11Texture1D_Release(texture);
148 desc->Format = texture_desc.Format;
149 if (texture_desc.ArraySize == 1)
151 desc->ViewDimension = D3D11_RTV_DIMENSION_TEXTURE1D;
152 desc->u.Texture1D.MipSlice = 0;
154 else
156 desc->ViewDimension = D3D11_RTV_DIMENSION_TEXTURE1DARRAY;
157 desc->u.Texture1DArray.MipSlice = 0;
158 desc->u.Texture1DArray.FirstArraySlice = 0;
159 desc->u.Texture1DArray.ArraySize = 1;
162 return S_OK;
165 case D3D11_RESOURCE_DIMENSION_TEXTURE2D:
167 ID3D11Texture2D *texture;
168 D3D11_TEXTURE2D_DESC texture_desc;
170 hr = ID3D11Resource_QueryInterface(resource, &IID_ID3D11Texture2D, (void **)&texture);
171 if (FAILED(hr))
173 ERR("Resource of type TEXTURE2D doesn't implement ID3D11Texture2D?\n");
174 return E_INVALIDARG;
177 ID3D11Texture2D_GetDesc(texture, &texture_desc);
178 ID3D11Texture2D_Release(texture);
180 desc->Format = texture_desc.Format;
181 if (texture_desc.ArraySize == 1)
183 if (texture_desc.SampleDesc.Count == 1)
185 desc->ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
186 desc->u.Texture2D.MipSlice = 0;
188 else
190 desc->ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DMS;
193 else
195 if (texture_desc.SampleDesc.Count == 1)
197 desc->ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
198 desc->u.Texture2DArray.MipSlice = 0;
199 desc->u.Texture2DArray.FirstArraySlice = 0;
200 desc->u.Texture2DArray.ArraySize = 1;
202 else
204 desc->ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY;
205 desc->u.Texture2DMSArray.FirstArraySlice = 0;
206 desc->u.Texture2DMSArray.ArraySize = 1;
210 return S_OK;
213 case D3D11_RESOURCE_DIMENSION_TEXTURE3D:
215 ID3D11Texture3D *texture;
216 D3D11_TEXTURE3D_DESC texture_desc;
218 hr = ID3D11Resource_QueryInterface(resource, &IID_ID3D11Texture3D, (void **)&texture);
219 if (FAILED(hr))
221 ERR("Resource of type TEXTURE3D doesn't implement ID3D11Texture3D?\n");
222 return E_INVALIDARG;
225 ID3D11Texture3D_GetDesc(texture, &texture_desc);
226 ID3D11Texture3D_Release(texture);
228 desc->Format = texture_desc.Format;
229 desc->ViewDimension = D3D11_RTV_DIMENSION_TEXTURE3D;
230 desc->u.Texture3D.MipSlice = 0;
231 desc->u.Texture3D.FirstWSlice = 0;
232 desc->u.Texture3D.WSize = 1;
234 return S_OK;
237 default:
238 FIXME("Unhandled resource dimension %#x.\n", dimension);
239 return E_INVALIDARG;
243 static HRESULT set_srdesc_from_resource(D3D11_SHADER_RESOURCE_VIEW_DESC *desc, ID3D11Resource *resource)
245 D3D11_RESOURCE_DIMENSION dimension;
247 ID3D11Resource_GetType(resource, &dimension);
249 switch (dimension)
251 case D3D11_RESOURCE_DIMENSION_TEXTURE1D:
253 D3D11_TEXTURE1D_DESC texture_desc;
254 ID3D11Texture1D *texture;
256 if (FAILED(ID3D11Resource_QueryInterface(resource, &IID_ID3D11Texture1D, (void **)&texture)))
258 ERR("Resource of type TEXTURE1D doesn't implement ID3D11Texture1D.\n");
259 return E_INVALIDARG;
262 ID3D11Texture1D_GetDesc(texture, &texture_desc);
263 ID3D11Texture1D_Release(texture);
265 desc->Format = texture_desc.Format;
266 if (texture_desc.ArraySize == 1)
268 desc->ViewDimension = D3D11_SRV_DIMENSION_TEXTURE1D;
269 desc->u.Texture1D.MostDetailedMip = 0;
270 desc->u.Texture1D.MipLevels = texture_desc.MipLevels;
272 else
274 desc->ViewDimension = D3D11_SRV_DIMENSION_TEXTURE1DARRAY;
275 desc->u.Texture1DArray.MostDetailedMip = 0;
276 desc->u.Texture1DArray.MipLevels = texture_desc.MipLevels;
277 desc->u.Texture1DArray.FirstArraySlice = 0;
278 desc->u.Texture1DArray.ArraySize = texture_desc.ArraySize;
281 return S_OK;
284 case D3D11_RESOURCE_DIMENSION_TEXTURE2D:
286 D3D11_TEXTURE2D_DESC texture_desc;
287 ID3D11Texture2D *texture;
289 if (FAILED(ID3D11Resource_QueryInterface(resource, &IID_ID3D11Texture2D, (void **)&texture)))
291 ERR("Resource of type TEXTURE2D doesn't implement ID3D11Texture2D.\n");
292 return E_INVALIDARG;
295 ID3D11Texture2D_GetDesc(texture, &texture_desc);
296 ID3D11Texture2D_Release(texture);
298 desc->Format = texture_desc.Format;
299 if (texture_desc.ArraySize == 1)
301 if (texture_desc.SampleDesc.Count == 1)
303 desc->ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D;
304 desc->u.Texture2D.MostDetailedMip = 0;
305 desc->u.Texture2D.MipLevels = texture_desc.MipLevels;
307 else
309 desc->ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DMS;
312 else
314 if (texture_desc.SampleDesc.Count == 1)
316 desc->ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DARRAY;
317 desc->u.Texture2DArray.MostDetailedMip = 0;
318 desc->u.Texture2DArray.MipLevels = texture_desc.MipLevels;
319 desc->u.Texture2DArray.FirstArraySlice = 0;
320 desc->u.Texture2DArray.ArraySize = texture_desc.ArraySize;
322 else
324 desc->ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2DMSARRAY;
325 desc->u.Texture2DMSArray.FirstArraySlice = 0;
326 desc->u.Texture2DMSArray.ArraySize = texture_desc.ArraySize;
330 return S_OK;
333 case D3D11_RESOURCE_DIMENSION_TEXTURE3D:
335 D3D11_TEXTURE3D_DESC texture_desc;
336 ID3D11Texture3D *texture;
338 if (FAILED(ID3D11Resource_QueryInterface(resource, &IID_ID3D11Texture3D, (void **)&texture)))
340 ERR("Resource of type TEXTURE3D doesn't implement ID3D11Texture3D.\n");
341 return E_INVALIDARG;
344 ID3D11Texture3D_GetDesc(texture, &texture_desc);
345 ID3D11Texture3D_Release(texture);
347 desc->Format = texture_desc.Format;
348 desc->ViewDimension = D3D11_SRV_DIMENSION_TEXTURE3D;
349 desc->u.Texture3D.MostDetailedMip = 0;
350 desc->u.Texture3D.MipLevels = texture_desc.MipLevels;
352 return S_OK;
355 default:
356 FIXME("Unhandled resource dimension %#x.\n", dimension);
357 case D3D11_RESOURCE_DIMENSION_BUFFER:
358 return E_INVALIDARG;
362 /* ID3D11DepthStencilView methods */
364 static inline struct d3d_depthstencil_view *impl_from_ID3D11DepthStencilView(ID3D11DepthStencilView *iface)
366 return CONTAINING_RECORD(iface, struct d3d_depthstencil_view, ID3D11DepthStencilView_iface);
369 static HRESULT STDMETHODCALLTYPE d3d11_depthstencil_view_QueryInterface(ID3D11DepthStencilView *iface,
370 REFIID riid, void **object)
372 struct d3d_depthstencil_view *view = impl_from_ID3D11DepthStencilView(iface);
374 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
376 if (IsEqualGUID(riid, &IID_ID3D11DepthStencilView)
377 || IsEqualGUID(riid, &IID_ID3D11View)
378 || IsEqualGUID(riid, &IID_ID3D11DeviceChild)
379 || IsEqualGUID(riid, &IID_IUnknown))
381 ID3D11DepthStencilView_AddRef(iface);
382 *object = iface;
383 return S_OK;
386 if (IsEqualGUID(riid, &IID_ID3D10DepthStencilView)
387 || IsEqualGUID(riid, &IID_ID3D10View)
388 || IsEqualGUID(riid, &IID_ID3D10DeviceChild))
390 ID3D10DepthStencilView_AddRef(&view->ID3D10DepthStencilView_iface);
391 *object = &view->ID3D10DepthStencilView_iface;
392 return S_OK;
395 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
397 *object = NULL;
398 return E_NOINTERFACE;
401 static ULONG STDMETHODCALLTYPE d3d11_depthstencil_view_AddRef(ID3D11DepthStencilView *iface)
403 struct d3d_depthstencil_view *view = impl_from_ID3D11DepthStencilView(iface);
404 ULONG refcount = InterlockedIncrement(&view->refcount);
406 TRACE("%p increasing refcount to %u.\n", view, refcount);
408 return refcount;
411 static ULONG STDMETHODCALLTYPE d3d11_depthstencil_view_Release(ID3D11DepthStencilView *iface)
413 struct d3d_depthstencil_view *view = impl_from_ID3D11DepthStencilView(iface);
414 ULONG refcount = InterlockedDecrement(&view->refcount);
416 TRACE("%p decreasing refcount to %u.\n", view, refcount);
418 if (!refcount)
420 wined3d_mutex_lock();
421 wined3d_rendertarget_view_decref(view->wined3d_view);
422 ID3D11Resource_Release(view->resource);
423 ID3D11Device_Release(view->device);
424 wined3d_private_store_cleanup(&view->private_store);
425 wined3d_mutex_unlock();
426 HeapFree(GetProcessHeap(), 0, view);
429 return refcount;
432 static void STDMETHODCALLTYPE d3d11_depthstencil_view_GetDevice(ID3D11DepthStencilView *iface,
433 ID3D11Device **device)
435 struct d3d_depthstencil_view *view = impl_from_ID3D11DepthStencilView(iface);
437 TRACE("iface %p, device %p.\n", iface, device);
439 *device = view->device;
440 ID3D11Device_AddRef(*device);
443 static HRESULT STDMETHODCALLTYPE d3d11_depthstencil_view_GetPrivateData(ID3D11DepthStencilView *iface,
444 REFGUID guid, UINT *data_size, void *data)
446 struct d3d_depthstencil_view *view = impl_from_ID3D11DepthStencilView(iface);
448 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
450 return d3d_get_private_data(&view->private_store, guid, data_size, data);
453 static HRESULT STDMETHODCALLTYPE d3d11_depthstencil_view_SetPrivateData(ID3D11DepthStencilView *iface,
454 REFGUID guid, UINT data_size, const void *data)
456 struct d3d_depthstencil_view *view = impl_from_ID3D11DepthStencilView(iface);
458 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
460 return d3d_set_private_data(&view->private_store, guid, data_size, data);
463 static HRESULT STDMETHODCALLTYPE d3d11_depthstencil_view_SetPrivateDataInterface(ID3D11DepthStencilView *iface,
464 REFGUID guid, const IUnknown *data)
466 struct d3d_depthstencil_view *view = impl_from_ID3D11DepthStencilView(iface);
468 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
470 return d3d_set_private_data_interface(&view->private_store, guid, data);
473 static void STDMETHODCALLTYPE d3d11_depthstencil_view_GetResource(ID3D11DepthStencilView *iface,
474 ID3D11Resource **resource)
476 struct d3d_depthstencil_view *view = impl_from_ID3D11DepthStencilView(iface);
478 TRACE("iface %p, resource %p.\n", iface, resource);
480 *resource = view->resource;
481 ID3D11Resource_AddRef(*resource);
484 static void STDMETHODCALLTYPE d3d11_depthstencil_view_GetDesc(ID3D11DepthStencilView *iface,
485 D3D11_DEPTH_STENCIL_VIEW_DESC *desc)
487 struct d3d_depthstencil_view *view = impl_from_ID3D11DepthStencilView(iface);
489 TRACE("iface %p, desc %p.\n", iface, desc);
491 *desc = view->desc;
494 static const struct ID3D11DepthStencilViewVtbl d3d11_depthstencil_view_vtbl =
496 /* IUnknown methods */
497 d3d11_depthstencil_view_QueryInterface,
498 d3d11_depthstencil_view_AddRef,
499 d3d11_depthstencil_view_Release,
500 /* ID3D11DeviceChild methods */
501 d3d11_depthstencil_view_GetDevice,
502 d3d11_depthstencil_view_GetPrivateData,
503 d3d11_depthstencil_view_SetPrivateData,
504 d3d11_depthstencil_view_SetPrivateDataInterface,
505 /* ID3D11View methods */
506 d3d11_depthstencil_view_GetResource,
507 /* ID3D11DepthStencilView methods */
508 d3d11_depthstencil_view_GetDesc,
511 /* ID3D10DepthStencilView methods */
513 static inline struct d3d_depthstencil_view *impl_from_ID3D10DepthStencilView(ID3D10DepthStencilView *iface)
515 return CONTAINING_RECORD(iface, struct d3d_depthstencil_view, ID3D10DepthStencilView_iface);
518 /* IUnknown methods */
520 static HRESULT STDMETHODCALLTYPE d3d10_depthstencil_view_QueryInterface(ID3D10DepthStencilView *iface,
521 REFIID riid, void **object)
523 struct d3d_depthstencil_view *view = impl_from_ID3D10DepthStencilView(iface);
525 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
527 return d3d11_depthstencil_view_QueryInterface(&view->ID3D11DepthStencilView_iface, riid, object);
530 static ULONG STDMETHODCALLTYPE d3d10_depthstencil_view_AddRef(ID3D10DepthStencilView *iface)
532 struct d3d_depthstencil_view *view = impl_from_ID3D10DepthStencilView(iface);
534 TRACE("iface %p.\n", iface);
536 return d3d11_depthstencil_view_AddRef(&view->ID3D11DepthStencilView_iface);
539 static ULONG STDMETHODCALLTYPE d3d10_depthstencil_view_Release(ID3D10DepthStencilView *iface)
541 struct d3d_depthstencil_view *view = impl_from_ID3D10DepthStencilView(iface);
543 TRACE("iface %p.\n", iface);
545 return d3d11_depthstencil_view_Release(&view->ID3D11DepthStencilView_iface);
548 /* ID3D10DeviceChild methods */
550 static void STDMETHODCALLTYPE d3d10_depthstencil_view_GetDevice(ID3D10DepthStencilView *iface, ID3D10Device **device)
552 struct d3d_depthstencil_view *view = impl_from_ID3D10DepthStencilView(iface);
554 TRACE("iface %p, device %p.\n", iface, device);
556 ID3D11Device_QueryInterface(view->device, &IID_ID3D10Device, (void **)device);
559 static HRESULT STDMETHODCALLTYPE d3d10_depthstencil_view_GetPrivateData(ID3D10DepthStencilView *iface,
560 REFGUID guid, UINT *data_size, void *data)
562 struct d3d_depthstencil_view *view = impl_from_ID3D10DepthStencilView(iface);
564 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
565 iface, debugstr_guid(guid), data_size, data);
567 return d3d_get_private_data(&view->private_store, guid, data_size, data);
570 static HRESULT STDMETHODCALLTYPE d3d10_depthstencil_view_SetPrivateData(ID3D10DepthStencilView *iface,
571 REFGUID guid, UINT data_size, const void *data)
573 struct d3d_depthstencil_view *view = impl_from_ID3D10DepthStencilView(iface);
575 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
576 iface, debugstr_guid(guid), data_size, data);
578 return d3d_set_private_data(&view->private_store, guid, data_size, data);
581 static HRESULT STDMETHODCALLTYPE d3d10_depthstencil_view_SetPrivateDataInterface(ID3D10DepthStencilView *iface,
582 REFGUID guid, const IUnknown *data)
584 struct d3d_depthstencil_view *view = impl_from_ID3D10DepthStencilView(iface);
586 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
588 return d3d_set_private_data_interface(&view->private_store, guid, data);
591 /* ID3D10View methods */
593 static void STDMETHODCALLTYPE d3d10_depthstencil_view_GetResource(ID3D10DepthStencilView *iface,
594 ID3D10Resource **resource)
596 struct d3d_depthstencil_view *view = impl_from_ID3D10DepthStencilView(iface);
598 TRACE("iface %p, resource %p.\n", iface, resource);
600 ID3D11Resource_QueryInterface(view->resource, &IID_ID3D10Resource, (void **)resource);
603 /* ID3D10DepthStencilView methods */
605 static void STDMETHODCALLTYPE d3d10_depthstencil_view_GetDesc(ID3D10DepthStencilView *iface,
606 D3D10_DEPTH_STENCIL_VIEW_DESC *desc)
608 struct d3d_depthstencil_view *view = impl_from_ID3D10DepthStencilView(iface);
609 const D3D11_DEPTH_STENCIL_VIEW_DESC *d3d11_desc = &view->desc;
611 TRACE("iface %p, desc %p.\n", iface, desc);
613 desc->Format = d3d11_desc->Format;
614 desc->ViewDimension = (D3D10_DSV_DIMENSION)d3d11_desc->ViewDimension;
615 memcpy(&desc->u, &d3d11_desc->u, sizeof(desc->u));
618 static const struct ID3D10DepthStencilViewVtbl d3d10_depthstencil_view_vtbl =
620 /* IUnknown methods */
621 d3d10_depthstencil_view_QueryInterface,
622 d3d10_depthstencil_view_AddRef,
623 d3d10_depthstencil_view_Release,
624 /* ID3D10DeviceChild methods */
625 d3d10_depthstencil_view_GetDevice,
626 d3d10_depthstencil_view_GetPrivateData,
627 d3d10_depthstencil_view_SetPrivateData,
628 d3d10_depthstencil_view_SetPrivateDataInterface,
629 /* ID3D10View methods */
630 d3d10_depthstencil_view_GetResource,
631 /* ID3D10DepthStencilView methods */
632 d3d10_depthstencil_view_GetDesc,
635 static void wined3d_depth_stencil_view_desc_from_d3d11(struct wined3d_rendertarget_view_desc *wined3d_desc,
636 const D3D11_DEPTH_STENCIL_VIEW_DESC *desc)
638 wined3d_desc->format_id = wined3dformat_from_dxgi_format(desc->Format);
640 if (desc->Flags)
641 FIXME("Unhandled depth stencil view flags %#x.\n", desc->Flags);
643 switch (desc->ViewDimension)
645 case D3D11_DSV_DIMENSION_TEXTURE1D:
646 wined3d_desc->u.texture.level_idx = desc->u.Texture1D.MipSlice;
647 wined3d_desc->u.texture.layer_idx = 0;
648 wined3d_desc->u.texture.layer_count = 1;
649 break;
651 case D3D11_DSV_DIMENSION_TEXTURE1DARRAY:
652 wined3d_desc->u.texture.level_idx = desc->u.Texture1DArray.MipSlice;
653 wined3d_desc->u.texture.layer_idx = desc->u.Texture1DArray.FirstArraySlice;
654 wined3d_desc->u.texture.layer_count = desc->u.Texture1DArray.ArraySize;
655 break;
657 case D3D11_DSV_DIMENSION_TEXTURE2D:
658 wined3d_desc->u.texture.level_idx = desc->u.Texture2D.MipSlice;
659 wined3d_desc->u.texture.layer_idx = 0;
660 wined3d_desc->u.texture.layer_count = 1;
661 break;
663 case D3D11_DSV_DIMENSION_TEXTURE2DARRAY:
664 wined3d_desc->u.texture.level_idx = desc->u.Texture2DArray.MipSlice;
665 wined3d_desc->u.texture.layer_idx = desc->u.Texture2DArray.FirstArraySlice;
666 wined3d_desc->u.texture.layer_count = desc->u.Texture2DArray.ArraySize;
667 break;
669 case D3D11_DSV_DIMENSION_TEXTURE2DMS:
670 wined3d_desc->u.texture.level_idx = 0;
671 wined3d_desc->u.texture.layer_idx = 0;
672 wined3d_desc->u.texture.layer_count = 1;
673 break;
675 case D3D11_DSV_DIMENSION_TEXTURE2DMSARRAY:
676 wined3d_desc->u.texture.level_idx = 0;
677 wined3d_desc->u.texture.layer_idx = desc->u.Texture2DMSArray.FirstArraySlice;
678 wined3d_desc->u.texture.layer_count = desc->u.Texture2DMSArray.ArraySize;
679 break;
681 default:
682 FIXME("Unhandled view dimension %#x.\n", desc->ViewDimension);
683 wined3d_desc->u.texture.level_idx = 0;
684 wined3d_desc->u.texture.layer_idx = 0;
685 wined3d_desc->u.texture.layer_count = 1;
686 break;
690 static HRESULT d3d_depthstencil_view_init(struct d3d_depthstencil_view *view, struct d3d_device *device,
691 ID3D11Resource *resource, const D3D11_DEPTH_STENCIL_VIEW_DESC *desc)
693 struct wined3d_rendertarget_view_desc wined3d_desc;
694 struct wined3d_resource *wined3d_resource;
695 HRESULT hr;
697 view->ID3D11DepthStencilView_iface.lpVtbl = &d3d11_depthstencil_view_vtbl;
698 view->ID3D10DepthStencilView_iface.lpVtbl = &d3d10_depthstencil_view_vtbl;
699 view->refcount = 1;
701 if (!desc)
703 if (FAILED(hr = set_dsdesc_from_resource(&view->desc, resource)))
704 return hr;
706 else
708 view->desc = *desc;
711 wined3d_mutex_lock();
712 if (!(wined3d_resource = wined3d_resource_from_d3d11_resource(resource)))
714 wined3d_mutex_unlock();
715 ERR("Failed to get wined3d resource for d3d11 resource %p.\n", resource);
716 return E_FAIL;
719 wined3d_depth_stencil_view_desc_from_d3d11(&wined3d_desc, &view->desc);
720 if (FAILED(hr = wined3d_rendertarget_view_create(&wined3d_desc, wined3d_resource,
721 view, &d3d_null_wined3d_parent_ops, &view->wined3d_view)))
723 wined3d_mutex_unlock();
724 WARN("Failed to create a wined3d rendertarget view, hr %#x.\n", hr);
725 return hr;
728 wined3d_private_store_init(&view->private_store);
729 wined3d_mutex_unlock();
730 view->resource = resource;
731 ID3D11Resource_AddRef(resource);
732 view->device = &device->ID3D11Device_iface;
733 ID3D11Device_AddRef(view->device);
735 return S_OK;
738 HRESULT d3d_depthstencil_view_create(struct d3d_device *device, ID3D11Resource *resource,
739 const D3D11_DEPTH_STENCIL_VIEW_DESC *desc, struct d3d_depthstencil_view **view)
741 struct d3d_depthstencil_view *object;
742 HRESULT hr;
744 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
745 return E_OUTOFMEMORY;
747 if (FAILED(hr = d3d_depthstencil_view_init(object, device, resource, desc)))
749 WARN("Failed to initialize depthstencil view, hr %#x.\n", hr);
750 HeapFree(GetProcessHeap(), 0, object);
751 return hr;
754 TRACE("Created depthstencil view %p.\n", object);
755 *view = object;
757 return S_OK;
760 struct d3d_depthstencil_view *unsafe_impl_from_ID3D11DepthStencilView(ID3D11DepthStencilView *iface)
762 if (!iface)
763 return NULL;
764 assert(iface->lpVtbl == &d3d11_depthstencil_view_vtbl);
766 return impl_from_ID3D11DepthStencilView(iface);
769 struct d3d_depthstencil_view *unsafe_impl_from_ID3D10DepthStencilView(ID3D10DepthStencilView *iface)
771 if (!iface)
772 return NULL;
773 assert(iface->lpVtbl == &d3d10_depthstencil_view_vtbl);
775 return impl_from_ID3D10DepthStencilView(iface);
778 /* ID3D11RenderTargetView methods */
780 static inline struct d3d_rendertarget_view *impl_from_ID3D11RenderTargetView(ID3D11RenderTargetView *iface)
782 return CONTAINING_RECORD(iface, struct d3d_rendertarget_view, ID3D11RenderTargetView_iface);
785 static HRESULT STDMETHODCALLTYPE d3d11_rendertarget_view_QueryInterface(ID3D11RenderTargetView *iface,
786 REFIID riid, void **object)
788 struct d3d_rendertarget_view *view = impl_from_ID3D11RenderTargetView(iface);
790 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
792 if (IsEqualGUID(riid, &IID_ID3D11RenderTargetView)
793 || IsEqualGUID(riid, &IID_ID3D11View)
794 || IsEqualGUID(riid, &IID_ID3D11DeviceChild)
795 || IsEqualGUID(riid, &IID_IUnknown))
797 ID3D11RenderTargetView_AddRef(iface);
798 *object = iface;
799 return S_OK;
802 if (IsEqualGUID(riid, &IID_ID3D10RenderTargetView)
803 || IsEqualGUID(riid, &IID_ID3D10View)
804 || IsEqualGUID(riid, &IID_ID3D10DeviceChild))
806 ID3D10RenderTargetView_AddRef(&view->ID3D10RenderTargetView_iface);
807 *object = &view->ID3D10RenderTargetView_iface;
808 return S_OK;
811 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
813 *object = NULL;
814 return E_NOINTERFACE;
817 static ULONG STDMETHODCALLTYPE d3d11_rendertarget_view_AddRef(ID3D11RenderTargetView *iface)
819 struct d3d_rendertarget_view *view = impl_from_ID3D11RenderTargetView(iface);
820 ULONG refcount = InterlockedIncrement(&view->refcount);
822 TRACE("%p increasing refcount to %u.\n", view, refcount);
824 return refcount;
827 static ULONG STDMETHODCALLTYPE d3d11_rendertarget_view_Release(ID3D11RenderTargetView *iface)
829 struct d3d_rendertarget_view *view = impl_from_ID3D11RenderTargetView(iface);
830 ULONG refcount = InterlockedDecrement(&view->refcount);
832 TRACE("%p decreasing refcount to %u.\n", view, refcount);
834 if (!refcount)
836 wined3d_mutex_lock();
837 wined3d_rendertarget_view_decref(view->wined3d_view);
838 ID3D11Resource_Release(view->resource);
839 ID3D11Device_Release(view->device);
840 wined3d_private_store_cleanup(&view->private_store);
841 wined3d_mutex_unlock();
842 HeapFree(GetProcessHeap(), 0, view);
845 return refcount;
848 static void STDMETHODCALLTYPE d3d11_rendertarget_view_GetDevice(ID3D11RenderTargetView *iface,
849 ID3D11Device **device)
851 struct d3d_rendertarget_view *view = impl_from_ID3D11RenderTargetView(iface);
853 TRACE("iface %p, device %p.\n", iface, device);
855 *device = view->device;
856 ID3D11Device_AddRef(*device);
859 static HRESULT STDMETHODCALLTYPE d3d11_rendertarget_view_GetPrivateData(ID3D11RenderTargetView *iface,
860 REFGUID guid, UINT *data_size, void *data)
862 struct d3d_rendertarget_view *view = impl_from_ID3D11RenderTargetView(iface);
864 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
866 return d3d_get_private_data(&view->private_store, guid, data_size, data);
869 static HRESULT STDMETHODCALLTYPE d3d11_rendertarget_view_SetPrivateData(ID3D11RenderTargetView *iface,
870 REFGUID guid, UINT data_size, const void *data)
872 struct d3d_rendertarget_view *view = impl_from_ID3D11RenderTargetView(iface);
874 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
876 return d3d_set_private_data(&view->private_store, guid, data_size, data);
879 static HRESULT STDMETHODCALLTYPE d3d11_rendertarget_view_SetPrivateDataInterface(ID3D11RenderTargetView *iface,
880 REFGUID guid, const IUnknown *data)
882 struct d3d_rendertarget_view *view = impl_from_ID3D11RenderTargetView(iface);
884 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
886 return d3d_set_private_data_interface(&view->private_store, guid, data);
889 static void STDMETHODCALLTYPE d3d11_rendertarget_view_GetResource(ID3D11RenderTargetView *iface,
890 ID3D11Resource **resource)
892 struct d3d_rendertarget_view *view = impl_from_ID3D11RenderTargetView(iface);
894 TRACE("iface %p, resource %p.\n", iface, resource);
896 *resource = view->resource;
897 ID3D11Resource_AddRef(*resource);
900 static void STDMETHODCALLTYPE d3d11_rendertarget_view_GetDesc(ID3D11RenderTargetView *iface,
901 D3D11_RENDER_TARGET_VIEW_DESC *desc)
903 struct d3d_rendertarget_view *view = impl_from_ID3D11RenderTargetView(iface);
905 TRACE("iface %p, desc %p.\n", iface, desc);
907 *desc = view->desc;
910 static const struct ID3D11RenderTargetViewVtbl d3d11_rendertarget_view_vtbl =
912 /* IUnknown methods */
913 d3d11_rendertarget_view_QueryInterface,
914 d3d11_rendertarget_view_AddRef,
915 d3d11_rendertarget_view_Release,
916 /* ID3D11DeviceChild methods */
917 d3d11_rendertarget_view_GetDevice,
918 d3d11_rendertarget_view_GetPrivateData,
919 d3d11_rendertarget_view_SetPrivateData,
920 d3d11_rendertarget_view_SetPrivateDataInterface,
921 /* ID3D11View methods */
922 d3d11_rendertarget_view_GetResource,
923 /* ID3D11RenderTargetView methods */
924 d3d11_rendertarget_view_GetDesc,
927 /* ID3D10RenderTargetView methods */
929 static inline struct d3d_rendertarget_view *impl_from_ID3D10RenderTargetView(ID3D10RenderTargetView *iface)
931 return CONTAINING_RECORD(iface, struct d3d_rendertarget_view, ID3D10RenderTargetView_iface);
934 /* IUnknown methods */
936 static HRESULT STDMETHODCALLTYPE d3d10_rendertarget_view_QueryInterface(ID3D10RenderTargetView *iface,
937 REFIID riid, void **object)
939 struct d3d_rendertarget_view *view = impl_from_ID3D10RenderTargetView(iface);
941 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
943 return d3d11_rendertarget_view_QueryInterface(&view->ID3D11RenderTargetView_iface, riid, object);
946 static ULONG STDMETHODCALLTYPE d3d10_rendertarget_view_AddRef(ID3D10RenderTargetView *iface)
948 struct d3d_rendertarget_view *view = impl_from_ID3D10RenderTargetView(iface);
950 TRACE("iface %p.\n", iface);
952 return d3d11_rendertarget_view_AddRef(&view->ID3D11RenderTargetView_iface);
955 static ULONG STDMETHODCALLTYPE d3d10_rendertarget_view_Release(ID3D10RenderTargetView *iface)
957 struct d3d_rendertarget_view *view = impl_from_ID3D10RenderTargetView(iface);
959 TRACE("iface %p.\n", iface);
961 return d3d11_rendertarget_view_Release(&view->ID3D11RenderTargetView_iface);
964 /* ID3D10DeviceChild methods */
966 static void STDMETHODCALLTYPE d3d10_rendertarget_view_GetDevice(ID3D10RenderTargetView *iface, ID3D10Device **device)
968 struct d3d_rendertarget_view *view = impl_from_ID3D10RenderTargetView(iface);
970 TRACE("iface %p, device %p.\n", iface, device);
972 ID3D11Device_QueryInterface(view->device, &IID_ID3D10Device, (void **)device);
975 static HRESULT STDMETHODCALLTYPE d3d10_rendertarget_view_GetPrivateData(ID3D10RenderTargetView *iface,
976 REFGUID guid, UINT *data_size, void *data)
978 struct d3d_rendertarget_view *view = impl_from_ID3D10RenderTargetView(iface);
980 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
981 iface, debugstr_guid(guid), data_size, data);
983 return d3d_get_private_data(&view->private_store, guid, data_size, data);
986 static HRESULT STDMETHODCALLTYPE d3d10_rendertarget_view_SetPrivateData(ID3D10RenderTargetView *iface,
987 REFGUID guid, UINT data_size, const void *data)
989 struct d3d_rendertarget_view *view = impl_from_ID3D10RenderTargetView(iface);
991 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
992 iface, debugstr_guid(guid), data_size, data);
994 return d3d_set_private_data(&view->private_store, guid, data_size, data);
997 static HRESULT STDMETHODCALLTYPE d3d10_rendertarget_view_SetPrivateDataInterface(ID3D10RenderTargetView *iface,
998 REFGUID guid, const IUnknown *data)
1000 struct d3d_rendertarget_view *view = impl_from_ID3D10RenderTargetView(iface);
1002 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
1004 return d3d_set_private_data_interface(&view->private_store, guid, data);
1007 /* ID3D10View methods */
1009 static void STDMETHODCALLTYPE d3d10_rendertarget_view_GetResource(ID3D10RenderTargetView *iface,
1010 ID3D10Resource **resource)
1012 struct d3d_rendertarget_view *view = impl_from_ID3D10RenderTargetView(iface);
1014 TRACE("iface %p, resource %p\n", iface, resource);
1016 ID3D11Resource_QueryInterface(view->resource, &IID_ID3D10Resource, (void **)resource);
1019 /* ID3D10RenderTargetView methods */
1021 static void STDMETHODCALLTYPE d3d10_rendertarget_view_GetDesc(ID3D10RenderTargetView *iface,
1022 D3D10_RENDER_TARGET_VIEW_DESC *desc)
1024 struct d3d_rendertarget_view *view = impl_from_ID3D10RenderTargetView(iface);
1026 TRACE("iface %p, desc %p\n", iface, desc);
1028 memcpy(desc, &view->desc, sizeof(*desc));
1031 static const struct ID3D10RenderTargetViewVtbl d3d10_rendertarget_view_vtbl =
1033 /* IUnknown methods */
1034 d3d10_rendertarget_view_QueryInterface,
1035 d3d10_rendertarget_view_AddRef,
1036 d3d10_rendertarget_view_Release,
1037 /* ID3D10DeviceChild methods */
1038 d3d10_rendertarget_view_GetDevice,
1039 d3d10_rendertarget_view_GetPrivateData,
1040 d3d10_rendertarget_view_SetPrivateData,
1041 d3d10_rendertarget_view_SetPrivateDataInterface,
1042 /* ID3D10View methods */
1043 d3d10_rendertarget_view_GetResource,
1044 /* ID3D10RenderTargetView methods */
1045 d3d10_rendertarget_view_GetDesc,
1048 static void wined3d_rendertarget_view_desc_from_d3d11(struct wined3d_rendertarget_view_desc *wined3d_desc,
1049 const D3D11_RENDER_TARGET_VIEW_DESC *desc)
1051 wined3d_desc->format_id = wined3dformat_from_dxgi_format(desc->Format);
1053 switch (desc->ViewDimension)
1055 case D3D11_RTV_DIMENSION_BUFFER:
1056 wined3d_desc->u.buffer.start_idx = desc->u.Buffer.u1.FirstElement;
1057 wined3d_desc->u.buffer.count = desc->u.Buffer.u2.NumElements;
1058 break;
1060 case D3D11_RTV_DIMENSION_TEXTURE1D:
1061 wined3d_desc->u.texture.level_idx = desc->u.Texture1D.MipSlice;
1062 wined3d_desc->u.texture.layer_idx = 0;
1063 wined3d_desc->u.texture.layer_count = 1;
1064 break;
1066 case D3D11_RTV_DIMENSION_TEXTURE1DARRAY:
1067 wined3d_desc->u.texture.level_idx = desc->u.Texture1DArray.MipSlice;
1068 wined3d_desc->u.texture.layer_idx = desc->u.Texture1DArray.FirstArraySlice;
1069 wined3d_desc->u.texture.layer_count = desc->u.Texture1DArray.ArraySize;
1070 break;
1072 case D3D11_RTV_DIMENSION_TEXTURE2D:
1073 wined3d_desc->u.texture.level_idx = desc->u.Texture2D.MipSlice;
1074 wined3d_desc->u.texture.layer_idx = 0;
1075 wined3d_desc->u.texture.layer_count = 1;
1076 break;
1078 case D3D11_RTV_DIMENSION_TEXTURE2DARRAY:
1079 wined3d_desc->u.texture.level_idx = desc->u.Texture2DArray.MipSlice;
1080 wined3d_desc->u.texture.layer_idx = desc->u.Texture2DArray.FirstArraySlice;
1081 wined3d_desc->u.texture.layer_count = desc->u.Texture2DArray.ArraySize;
1082 break;
1084 case D3D11_RTV_DIMENSION_TEXTURE2DMS:
1085 wined3d_desc->u.texture.level_idx = 0;
1086 wined3d_desc->u.texture.layer_idx = 0;
1087 wined3d_desc->u.texture.layer_count = 1;
1088 break;
1090 case D3D11_RTV_DIMENSION_TEXTURE2DMSARRAY:
1091 wined3d_desc->u.texture.level_idx = 0;
1092 wined3d_desc->u.texture.layer_idx = desc->u.Texture2DMSArray.FirstArraySlice;
1093 wined3d_desc->u.texture.layer_count = desc->u.Texture2DMSArray.ArraySize;
1094 break;
1096 case D3D11_RTV_DIMENSION_TEXTURE3D:
1097 wined3d_desc->u.texture.level_idx = desc->u.Texture3D.MipSlice;
1098 wined3d_desc->u.texture.layer_idx = desc->u.Texture3D.FirstWSlice;
1099 wined3d_desc->u.texture.layer_count = desc->u.Texture3D.WSize;
1100 break;
1102 default:
1103 FIXME("Unhandled view dimension %#x.\n", desc->ViewDimension);
1104 wined3d_desc->u.texture.level_idx = 0;
1105 wined3d_desc->u.texture.layer_idx = 0;
1106 wined3d_desc->u.texture.layer_count = 1;
1107 break;
1111 static HRESULT d3d_rendertarget_view_init(struct d3d_rendertarget_view *view, struct d3d_device *device,
1112 ID3D11Resource *resource, const D3D11_RENDER_TARGET_VIEW_DESC *desc)
1114 struct wined3d_rendertarget_view_desc wined3d_desc;
1115 struct wined3d_resource *wined3d_resource;
1116 HRESULT hr;
1118 view->ID3D11RenderTargetView_iface.lpVtbl = &d3d11_rendertarget_view_vtbl;
1119 view->ID3D10RenderTargetView_iface.lpVtbl = &d3d10_rendertarget_view_vtbl;
1120 view->refcount = 1;
1122 if (!desc)
1124 HRESULT hr = set_rtdesc_from_resource(&view->desc, resource);
1125 if (FAILED(hr)) return hr;
1127 else
1129 view->desc = *desc;
1132 wined3d_mutex_lock();
1133 if (!(wined3d_resource = wined3d_resource_from_d3d11_resource(resource)))
1135 wined3d_mutex_unlock();
1136 ERR("Failed to get wined3d resource for d3d11 resource %p.\n", resource);
1137 return E_FAIL;
1140 wined3d_rendertarget_view_desc_from_d3d11(&wined3d_desc, &view->desc);
1141 if (FAILED(hr = wined3d_rendertarget_view_create(&wined3d_desc, wined3d_resource,
1142 view, &d3d_null_wined3d_parent_ops, &view->wined3d_view)))
1144 wined3d_mutex_unlock();
1145 WARN("Failed to create a wined3d rendertarget view, hr %#x.\n", hr);
1146 return hr;
1149 wined3d_private_store_init(&view->private_store);
1150 wined3d_mutex_unlock();
1151 view->resource = resource;
1152 ID3D11Resource_AddRef(resource);
1153 view->device = &device->ID3D11Device_iface;
1154 ID3D11Device_AddRef(view->device);
1156 return S_OK;
1159 HRESULT d3d_rendertarget_view_create(struct d3d_device *device, ID3D11Resource *resource,
1160 const D3D11_RENDER_TARGET_VIEW_DESC *desc, struct d3d_rendertarget_view **view)
1162 struct d3d_rendertarget_view *object;
1163 HRESULT hr;
1165 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
1166 return E_OUTOFMEMORY;
1168 if (FAILED(hr = d3d_rendertarget_view_init(object, device, resource, desc)))
1170 WARN("Failed to initialize rendertarget view, hr %#x.\n", hr);
1171 HeapFree(GetProcessHeap(), 0, object);
1172 return hr;
1175 TRACE("Created rendertarget view %p.\n", object);
1176 *view = object;
1178 return S_OK;
1181 struct d3d_rendertarget_view *unsafe_impl_from_ID3D11RenderTargetView(ID3D11RenderTargetView *iface)
1183 if (!iface)
1184 return NULL;
1185 assert(iface->lpVtbl == &d3d11_rendertarget_view_vtbl);
1187 return impl_from_ID3D11RenderTargetView(iface);
1190 struct d3d_rendertarget_view *unsafe_impl_from_ID3D10RenderTargetView(ID3D10RenderTargetView *iface)
1192 if (!iface)
1193 return NULL;
1194 assert(iface->lpVtbl == &d3d10_rendertarget_view_vtbl);
1196 return impl_from_ID3D10RenderTargetView(iface);
1199 /* ID3D11ShaderResourceView methods */
1201 static inline struct d3d_shader_resource_view *impl_from_ID3D11ShaderResourceView(ID3D11ShaderResourceView *iface)
1203 return CONTAINING_RECORD(iface, struct d3d_shader_resource_view, ID3D11ShaderResourceView_iface);
1206 static HRESULT STDMETHODCALLTYPE d3d11_shader_resource_view_QueryInterface(ID3D11ShaderResourceView *iface,
1207 REFIID riid, void **object)
1209 struct d3d_shader_resource_view *view = impl_from_ID3D11ShaderResourceView(iface);
1211 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
1213 if (IsEqualGUID(riid, &IID_ID3D11ShaderResourceView)
1214 || IsEqualGUID(riid, &IID_ID3D11View)
1215 || IsEqualGUID(riid, &IID_ID3D11DeviceChild)
1216 || IsEqualGUID(riid, &IID_IUnknown))
1218 ID3D11ShaderResourceView_AddRef(iface);
1219 *object = iface;
1220 return S_OK;
1223 if (IsEqualGUID(riid, &IID_ID3D10ShaderResourceView1)
1224 || IsEqualGUID(riid, &IID_ID3D10ShaderResourceView)
1225 || IsEqualGUID(riid, &IID_ID3D10View)
1226 || IsEqualGUID(riid, &IID_ID3D10DeviceChild))
1228 ID3D10ShaderResourceView1_AddRef(&view->ID3D10ShaderResourceView1_iface);
1229 *object = &view->ID3D10ShaderResourceView1_iface;
1230 return S_OK;
1233 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
1235 *object = NULL;
1236 return E_NOINTERFACE;
1239 static ULONG STDMETHODCALLTYPE d3d11_shader_resource_view_AddRef(ID3D11ShaderResourceView *iface)
1241 struct d3d_shader_resource_view *view = impl_from_ID3D11ShaderResourceView(iface);
1242 ULONG refcount = InterlockedIncrement(&view->refcount);
1244 TRACE("%p increasing refcount to %u.\n", view, refcount);
1246 return refcount;
1249 static ULONG STDMETHODCALLTYPE d3d11_shader_resource_view_Release(ID3D11ShaderResourceView *iface)
1251 struct d3d_shader_resource_view *view = impl_from_ID3D11ShaderResourceView(iface);
1252 ULONG refcount = InterlockedDecrement(&view->refcount);
1254 TRACE("%p decreasing refcount to %u.\n", view, refcount);
1256 if (!refcount)
1258 wined3d_mutex_lock();
1259 wined3d_shader_resource_view_decref(view->wined3d_view);
1260 ID3D11Resource_Release(view->resource);
1261 ID3D11Device_Release(view->device);
1262 wined3d_private_store_cleanup(&view->private_store);
1263 wined3d_mutex_unlock();
1264 HeapFree(GetProcessHeap(), 0, view);
1267 return refcount;
1270 static void STDMETHODCALLTYPE d3d11_shader_resource_view_GetDevice(ID3D11ShaderResourceView *iface,
1271 ID3D11Device **device)
1273 struct d3d_shader_resource_view *view = impl_from_ID3D11ShaderResourceView(iface);
1275 TRACE("iface %p, device %p.\n", iface, device);
1277 *device = view->device;
1278 ID3D11Device_AddRef(*device);
1281 static HRESULT STDMETHODCALLTYPE d3d11_shader_resource_view_GetPrivateData(ID3D11ShaderResourceView *iface,
1282 REFGUID guid, UINT *data_size, void *data)
1284 struct d3d_shader_resource_view *view = impl_from_ID3D11ShaderResourceView(iface);
1286 TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
1288 return d3d_get_private_data(&view->private_store, guid, data_size, data);
1291 static HRESULT STDMETHODCALLTYPE d3d11_shader_resource_view_SetPrivateData(ID3D11ShaderResourceView *iface,
1292 REFGUID guid, UINT data_size, const void *data)
1294 struct d3d_shader_resource_view *view = impl_from_ID3D11ShaderResourceView(iface);
1296 TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
1298 return d3d_set_private_data(&view->private_store, guid, data_size, data);
1301 static HRESULT STDMETHODCALLTYPE d3d11_shader_resource_view_SetPrivateDataInterface(ID3D11ShaderResourceView *iface,
1302 REFGUID guid, const IUnknown *data)
1304 struct d3d_shader_resource_view *view = impl_from_ID3D11ShaderResourceView(iface);
1306 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
1308 return d3d_set_private_data_interface(&view->private_store, guid, data);
1311 static void STDMETHODCALLTYPE d3d11_shader_resource_view_GetResource(ID3D11ShaderResourceView *iface,
1312 ID3D11Resource **resource)
1314 struct d3d_shader_resource_view *view = impl_from_ID3D11ShaderResourceView(iface);
1316 TRACE("iface %p, resource %p.\n", iface, resource);
1318 *resource = view->resource;
1319 ID3D11Resource_AddRef(*resource);
1322 static void STDMETHODCALLTYPE d3d11_shader_resource_view_GetDesc(ID3D11ShaderResourceView *iface,
1323 D3D11_SHADER_RESOURCE_VIEW_DESC *desc)
1325 struct d3d_shader_resource_view *view = impl_from_ID3D11ShaderResourceView(iface);
1327 TRACE("iface %p, desc %p.\n", iface, desc);
1329 *desc = view->desc;
1332 static const struct ID3D11ShaderResourceViewVtbl d3d11_shader_resource_view_vtbl =
1334 /* IUnknown methods */
1335 d3d11_shader_resource_view_QueryInterface,
1336 d3d11_shader_resource_view_AddRef,
1337 d3d11_shader_resource_view_Release,
1338 /* ID3D11DeviceChild methods */
1339 d3d11_shader_resource_view_GetDevice,
1340 d3d11_shader_resource_view_GetPrivateData,
1341 d3d11_shader_resource_view_SetPrivateData,
1342 d3d11_shader_resource_view_SetPrivateDataInterface,
1343 /* ID3D11View methods */
1344 d3d11_shader_resource_view_GetResource,
1345 /* ID3D11ShaderResourceView methods */
1346 d3d11_shader_resource_view_GetDesc,
1349 /* ID3D10ShaderResourceView methods */
1351 static inline struct d3d_shader_resource_view *impl_from_ID3D10ShaderResourceView(ID3D10ShaderResourceView1 *iface)
1353 return CONTAINING_RECORD(iface, struct d3d_shader_resource_view, ID3D10ShaderResourceView1_iface);
1356 /* IUnknown methods */
1358 static HRESULT STDMETHODCALLTYPE d3d10_shader_resource_view_QueryInterface(ID3D10ShaderResourceView1 *iface,
1359 REFIID riid, void **object)
1361 struct d3d_shader_resource_view *view = impl_from_ID3D10ShaderResourceView(iface);
1363 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
1365 return d3d11_shader_resource_view_QueryInterface(&view->ID3D11ShaderResourceView_iface, riid, object);
1368 static ULONG STDMETHODCALLTYPE d3d10_shader_resource_view_AddRef(ID3D10ShaderResourceView1 *iface)
1370 struct d3d_shader_resource_view *view = impl_from_ID3D10ShaderResourceView(iface);
1372 TRACE("iface %p.\n", iface);
1374 return d3d11_shader_resource_view_AddRef(&view->ID3D11ShaderResourceView_iface);
1377 static ULONG STDMETHODCALLTYPE d3d10_shader_resource_view_Release(ID3D10ShaderResourceView1 *iface)
1379 struct d3d_shader_resource_view *view = impl_from_ID3D10ShaderResourceView(iface);
1381 TRACE("iface %p.\n", iface);
1383 return d3d11_shader_resource_view_Release(&view->ID3D11ShaderResourceView_iface);
1386 /* ID3D10DeviceChild methods */
1388 static void STDMETHODCALLTYPE d3d10_shader_resource_view_GetDevice(ID3D10ShaderResourceView1 *iface,
1389 ID3D10Device **device)
1391 struct d3d_shader_resource_view *view = impl_from_ID3D10ShaderResourceView(iface);
1393 TRACE("iface %p, device %p.\n", iface, device);
1395 ID3D11Device_QueryInterface(view->device, &IID_ID3D10Device, (void **)device);
1398 static HRESULT STDMETHODCALLTYPE d3d10_shader_resource_view_GetPrivateData(ID3D10ShaderResourceView1 *iface,
1399 REFGUID guid, UINT *data_size, void *data)
1401 struct d3d_shader_resource_view *view = impl_from_ID3D10ShaderResourceView(iface);
1403 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
1404 iface, debugstr_guid(guid), data_size, data);
1406 return d3d_get_private_data(&view->private_store, guid, data_size, data);
1409 static HRESULT STDMETHODCALLTYPE d3d10_shader_resource_view_SetPrivateData(ID3D10ShaderResourceView1 *iface,
1410 REFGUID guid, UINT data_size, const void *data)
1412 struct d3d_shader_resource_view *view = impl_from_ID3D10ShaderResourceView(iface);
1414 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
1415 iface, debugstr_guid(guid), data_size, data);
1417 return d3d_set_private_data(&view->private_store, guid, data_size, data);
1420 static HRESULT STDMETHODCALLTYPE d3d10_shader_resource_view_SetPrivateDataInterface(ID3D10ShaderResourceView1 *iface,
1421 REFGUID guid, const IUnknown *data)
1423 struct d3d_shader_resource_view *view = impl_from_ID3D10ShaderResourceView(iface);
1425 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
1427 return d3d_set_private_data_interface(&view->private_store, guid, data);
1430 /* ID3D10View methods */
1432 static void STDMETHODCALLTYPE d3d10_shader_resource_view_GetResource(ID3D10ShaderResourceView1 *iface,
1433 ID3D10Resource **resource)
1435 struct d3d_shader_resource_view *view = impl_from_ID3D10ShaderResourceView(iface);
1437 TRACE("iface %p, resource %p.\n", iface, resource);
1439 ID3D11Resource_QueryInterface(view->resource, &IID_ID3D10Resource, (void **)resource);
1442 /* ID3D10ShaderResourceView methods */
1444 static void STDMETHODCALLTYPE d3d10_shader_resource_view_GetDesc(ID3D10ShaderResourceView1 *iface,
1445 D3D10_SHADER_RESOURCE_VIEW_DESC *desc)
1447 struct d3d_shader_resource_view *view = impl_from_ID3D10ShaderResourceView(iface);
1449 TRACE("iface %p, desc %p.\n", iface, desc);
1451 memcpy(desc, &view->desc, sizeof(*desc));
1454 static void STDMETHODCALLTYPE d3d10_shader_resource_view_GetDesc1(ID3D10ShaderResourceView1 *iface,
1455 D3D10_SHADER_RESOURCE_VIEW_DESC1 *desc)
1457 struct d3d_shader_resource_view *view = impl_from_ID3D10ShaderResourceView(iface);
1459 TRACE("iface %p, desc %p.\n", iface, desc);
1461 memcpy(desc, &view->desc, sizeof(*desc));
1464 static const struct ID3D10ShaderResourceView1Vtbl d3d10_shader_resource_view_vtbl =
1466 /* IUnknown methods */
1467 d3d10_shader_resource_view_QueryInterface,
1468 d3d10_shader_resource_view_AddRef,
1469 d3d10_shader_resource_view_Release,
1470 /* ID3D10DeviceChild methods */
1471 d3d10_shader_resource_view_GetDevice,
1472 d3d10_shader_resource_view_GetPrivateData,
1473 d3d10_shader_resource_view_SetPrivateData,
1474 d3d10_shader_resource_view_SetPrivateDataInterface,
1475 /* ID3D10View methods */
1476 d3d10_shader_resource_view_GetResource,
1477 /* ID3D10ShaderResourceView methods */
1478 d3d10_shader_resource_view_GetDesc,
1479 /* ID3D10ShaderResourceView1 methods */
1480 d3d10_shader_resource_view_GetDesc1,
1483 static HRESULT d3d_shader_resource_view_init(struct d3d_shader_resource_view *view, struct d3d_device *device,
1484 ID3D11Resource *resource, const D3D11_SHADER_RESOURCE_VIEW_DESC *desc)
1486 struct wined3d_resource *wined3d_resource;
1487 HRESULT hr;
1489 view->ID3D11ShaderResourceView_iface.lpVtbl = &d3d11_shader_resource_view_vtbl;
1490 view->ID3D10ShaderResourceView1_iface.lpVtbl = &d3d10_shader_resource_view_vtbl;
1491 view->refcount = 1;
1493 if (!desc)
1495 if (FAILED(hr = set_srdesc_from_resource(&view->desc, resource)))
1496 return hr;
1498 else
1500 view->desc = *desc;
1503 wined3d_mutex_lock();
1504 if (!(wined3d_resource = wined3d_resource_from_d3d11_resource(resource)))
1506 wined3d_mutex_unlock();
1507 ERR("Failed to get wined3d resource for d3d10 resource %p.\n", resource);
1508 return E_FAIL;
1511 if (FAILED(hr = wined3d_shader_resource_view_create(wined3d_resource,
1512 view, &d3d_null_wined3d_parent_ops, &view->wined3d_view)))
1514 wined3d_mutex_unlock();
1515 WARN("Failed to create wined3d shader resource view, hr %#x.\n", hr);
1516 return hr;
1519 wined3d_private_store_init(&view->private_store);
1520 wined3d_mutex_unlock();
1521 view->resource = resource;
1522 ID3D11Resource_AddRef(resource);
1523 view->device = &device->ID3D11Device_iface;
1524 ID3D11Device_AddRef(view->device);
1526 return S_OK;
1529 HRESULT d3d_shader_resource_view_create(struct d3d_device *device, ID3D11Resource *resource,
1530 const D3D11_SHADER_RESOURCE_VIEW_DESC *desc, struct d3d_shader_resource_view **view)
1532 struct d3d_shader_resource_view *object;
1533 HRESULT hr;
1535 if (!(object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*object))))
1536 return E_OUTOFMEMORY;
1538 if (FAILED(hr = d3d_shader_resource_view_init(object, device, resource, desc)))
1540 WARN("Failed to initialize shader resource view, hr %#x.\n", hr);
1541 HeapFree(GetProcessHeap(), 0, object);
1542 return hr;
1545 TRACE("Created shader resource view %p.\n", object);
1546 *view = object;
1548 return S_OK;
1551 struct d3d_shader_resource_view *unsafe_impl_from_ID3D11ShaderResourceView(ID3D11ShaderResourceView *iface)
1553 if (!iface)
1554 return NULL;
1555 assert(iface->lpVtbl == &d3d11_shader_resource_view_vtbl);
1556 return impl_from_ID3D11ShaderResourceView(iface);
1559 struct d3d_shader_resource_view *unsafe_impl_from_ID3D10ShaderResourceView(ID3D10ShaderResourceView *iface)
1561 if (!iface)
1562 return NULL;
1563 assert(iface->lpVtbl == (ID3D10ShaderResourceViewVtbl *)&d3d10_shader_resource_view_vtbl);
1564 return CONTAINING_RECORD(iface, struct d3d_shader_resource_view, ID3D10ShaderResourceView1_iface);