include: Add event trace flags and guid to evntrace.h.
[wine.git] / dlls / d3d10core / view.c
blob3e72f34fa72f55ce663975f51196d2b336634ce8
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 "d3d10core_private.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(d3d10core);
28 static HRESULT set_dsdesc_from_resource(D3D10_DEPTH_STENCIL_VIEW_DESC *desc, ID3D10Resource *resource)
30 D3D10_RESOURCE_DIMENSION dimension;
32 ID3D10Resource_GetType(resource, &dimension);
34 switch (dimension)
36 case D3D10_RESOURCE_DIMENSION_TEXTURE1D:
38 D3D10_TEXTURE1D_DESC texture_desc;
39 ID3D10Texture1D *texture;
41 if (FAILED(ID3D10Resource_QueryInterface(resource, &IID_ID3D10Texture1D, (void **)&texture)))
43 ERR("Resource of type TEXTURE1D doesn't implement ID3D10Texture1D.\n");
44 return E_INVALIDARG;
47 ID3D10Texture1D_GetDesc(texture, &texture_desc);
48 ID3D10Texture1D_Release(texture);
50 desc->Format = texture_desc.Format;
51 if (texture_desc.ArraySize == 1)
53 desc->ViewDimension = D3D10_DSV_DIMENSION_TEXTURE1D;
54 desc->u.Texture1D.MipSlice = 0;
56 else
58 desc->ViewDimension = D3D10_DSV_DIMENSION_TEXTURE1DARRAY;
59 desc->u.Texture1DArray.MipSlice = 0;
60 desc->u.Texture1DArray.FirstArraySlice = 0;
61 desc->u.Texture1DArray.ArraySize = 1;
64 return S_OK;
67 case D3D10_RESOURCE_DIMENSION_TEXTURE2D:
69 D3D10_TEXTURE2D_DESC texture_desc;
70 ID3D10Texture2D *texture;
72 if (FAILED(ID3D10Resource_QueryInterface(resource, &IID_ID3D10Texture2D, (void **)&texture)))
74 ERR("Resource of type TEXTURE2D doesn't implement ID3D10Texture2D.\n");
75 return E_INVALIDARG;
78 ID3D10Texture2D_GetDesc(texture, &texture_desc);
79 ID3D10Texture2D_Release(texture);
81 desc->Format = texture_desc.Format;
82 if (texture_desc.ArraySize == 1)
84 if (texture_desc.SampleDesc.Count == 1)
86 desc->ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2D;
87 desc->u.Texture2D.MipSlice = 0;
89 else
91 desc->ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2DMS;
94 else
96 if (texture_desc.SampleDesc.Count == 1)
98 desc->ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2DARRAY;
99 desc->u.Texture2DArray.MipSlice = 0;
100 desc->u.Texture2DArray.FirstArraySlice = 0;
101 desc->u.Texture2DArray.ArraySize = 1;
103 else
105 desc->ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2DMSARRAY;
106 desc->u.Texture2DMSArray.FirstArraySlice = 0;
107 desc->u.Texture2DMSArray.ArraySize = 1;
111 return S_OK;
114 default:
115 FIXME("Unhandled resource dimension %#x.\n", dimension);
116 case D3D10_RESOURCE_DIMENSION_BUFFER:
117 case D3D10_RESOURCE_DIMENSION_TEXTURE3D:
118 return E_INVALIDARG;
122 static HRESULT set_rtdesc_from_resource(D3D10_RENDER_TARGET_VIEW_DESC *desc, ID3D10Resource *resource)
124 D3D10_RESOURCE_DIMENSION dimension;
125 HRESULT hr;
127 ID3D10Resource_GetType(resource, &dimension);
129 switch(dimension)
131 case D3D10_RESOURCE_DIMENSION_TEXTURE1D:
133 ID3D10Texture1D *texture;
134 D3D10_TEXTURE1D_DESC texture_desc;
136 hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D10Texture1D, (void **)&texture);
137 if (FAILED(hr))
139 ERR("Resource of type TEXTURE1D doesn't implement ID3D10Texture1D?\n");
140 return E_INVALIDARG;
143 ID3D10Texture1D_GetDesc(texture, &texture_desc);
144 ID3D10Texture1D_Release(texture);
146 desc->Format = texture_desc.Format;
147 if (texture_desc.ArraySize == 1)
149 desc->ViewDimension = D3D10_RTV_DIMENSION_TEXTURE1D;
150 desc->u.Texture1D.MipSlice = 0;
152 else
154 desc->ViewDimension = D3D10_RTV_DIMENSION_TEXTURE1DARRAY;
155 desc->u.Texture1DArray.MipSlice = 0;
156 desc->u.Texture1DArray.FirstArraySlice = 0;
157 desc->u.Texture1DArray.ArraySize = 1;
160 return S_OK;
163 case D3D10_RESOURCE_DIMENSION_TEXTURE2D:
165 ID3D10Texture2D *texture;
166 D3D10_TEXTURE2D_DESC texture_desc;
168 hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D10Texture2D, (void **)&texture);
169 if (FAILED(hr))
171 ERR("Resource of type TEXTURE2D doesn't implement ID3D10Texture2D?\n");
172 return E_INVALIDARG;
175 ID3D10Texture2D_GetDesc(texture, &texture_desc);
176 ID3D10Texture2D_Release(texture);
178 desc->Format = texture_desc.Format;
179 if (texture_desc.ArraySize == 1)
181 if (texture_desc.SampleDesc.Count == 1)
183 desc->ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2D;
184 desc->u.Texture2D.MipSlice = 0;
186 else
188 desc->ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2DMS;
191 else
193 if (texture_desc.SampleDesc.Count == 1)
195 desc->ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2DARRAY;
196 desc->u.Texture2DArray.MipSlice = 0;
197 desc->u.Texture2DArray.FirstArraySlice = 0;
198 desc->u.Texture2DArray.ArraySize = 1;
200 else
202 desc->ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2DMSARRAY;
203 desc->u.Texture2DMSArray.FirstArraySlice = 0;
204 desc->u.Texture2DMSArray.ArraySize = 1;
208 return S_OK;
211 case D3D10_RESOURCE_DIMENSION_TEXTURE3D:
213 ID3D10Texture3D *texture;
214 D3D10_TEXTURE3D_DESC texture_desc;
216 hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D10Texture3D, (void **)&texture);
217 if (FAILED(hr))
219 ERR("Resource of type TEXTURE3D doesn't implement ID3D10Texture3D?\n");
220 return E_INVALIDARG;
223 ID3D10Texture3D_GetDesc(texture, &texture_desc);
224 ID3D10Texture3D_Release(texture);
226 desc->Format = texture_desc.Format;
227 desc->ViewDimension = D3D10_RTV_DIMENSION_TEXTURE3D;
228 desc->u.Texture3D.MipSlice = 0;
229 desc->u.Texture3D.FirstWSlice = 0;
230 desc->u.Texture3D.WSize = 1;
232 return S_OK;
235 default:
236 FIXME("Unhandled resource dimension %#x.\n", dimension);
237 return E_INVALIDARG;
241 static HRESULT set_srdesc_from_resource(D3D10_SHADER_RESOURCE_VIEW_DESC *desc, ID3D10Resource *resource)
243 D3D10_RESOURCE_DIMENSION dimension;
245 ID3D10Resource_GetType(resource, &dimension);
247 switch (dimension)
249 case D3D10_RESOURCE_DIMENSION_TEXTURE1D:
251 D3D10_TEXTURE1D_DESC texture_desc;
252 ID3D10Texture1D *texture;
254 if (FAILED(ID3D10Resource_QueryInterface(resource, &IID_ID3D10Texture1D, (void **)&texture)))
256 ERR("Resource of type TEXTURE1D doesn't implement ID3D10Texture1D.\n");
257 return E_INVALIDARG;
260 ID3D10Texture1D_GetDesc(texture, &texture_desc);
261 ID3D10Texture1D_Release(texture);
263 desc->Format = texture_desc.Format;
264 if (texture_desc.ArraySize == 1)
266 desc->ViewDimension = D3D10_SRV_DIMENSION_TEXTURE1D;
267 desc->u.Texture1D.MostDetailedMip = 0;
268 desc->u.Texture1D.MipLevels = texture_desc.MipLevels;
270 else
272 desc->ViewDimension = D3D10_SRV_DIMENSION_TEXTURE1DARRAY;
273 desc->u.Texture1DArray.MostDetailedMip = 0;
274 desc->u.Texture1DArray.MipLevels = texture_desc.MipLevels;
275 desc->u.Texture1DArray.FirstArraySlice = 0;
276 desc->u.Texture1DArray.ArraySize = texture_desc.ArraySize;
279 return S_OK;
282 case D3D10_RESOURCE_DIMENSION_TEXTURE2D:
284 D3D10_TEXTURE2D_DESC texture_desc;
285 ID3D10Texture2D *texture;
287 if (FAILED(ID3D10Resource_QueryInterface(resource, &IID_ID3D10Texture2D, (void **)&texture)))
289 ERR("Resource of type TEXTURE2D doesn't implement ID3D10Texture2D.\n");
290 return E_INVALIDARG;
293 ID3D10Texture2D_GetDesc(texture, &texture_desc);
294 ID3D10Texture2D_Release(texture);
296 desc->Format = texture_desc.Format;
297 if (texture_desc.ArraySize == 1)
299 if (texture_desc.SampleDesc.Count == 1)
301 desc->ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
302 desc->u.Texture2D.MostDetailedMip = 0;
303 desc->u.Texture2D.MipLevels = texture_desc.MipLevels;
305 else
307 desc->ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2DMS;
310 else
312 if (texture_desc.SampleDesc.Count == 1)
314 desc->ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2DARRAY;
315 desc->u.Texture2DArray.MostDetailedMip = 0;
316 desc->u.Texture2DArray.MipLevels = texture_desc.MipLevels;
317 desc->u.Texture2DArray.FirstArraySlice = 0;
318 desc->u.Texture2DArray.ArraySize = texture_desc.ArraySize;
320 else
322 desc->ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2DMSARRAY;
323 desc->u.Texture2DMSArray.FirstArraySlice = 0;
324 desc->u.Texture2DMSArray.ArraySize = texture_desc.ArraySize;
328 return S_OK;
331 case D3D10_RESOURCE_DIMENSION_TEXTURE3D:
333 D3D10_TEXTURE3D_DESC texture_desc;
334 ID3D10Texture3D *texture;
336 if (FAILED(ID3D10Resource_QueryInterface(resource, &IID_ID3D10Texture3D, (void **)&texture)))
338 ERR("Resource of type TEXTURE3D doesn't implement ID3D10Texture3D.\n");
339 return E_INVALIDARG;
342 ID3D10Texture3D_GetDesc(texture, &texture_desc);
343 ID3D10Texture3D_Release(texture);
345 desc->Format = texture_desc.Format;
346 desc->ViewDimension = D3D10_SRV_DIMENSION_TEXTURE3D;
347 desc->u.Texture3D.MostDetailedMip = 0;
348 desc->u.Texture3D.MipLevels = texture_desc.MipLevels;
350 return S_OK;
353 default:
354 FIXME("Unhandled resource dimension %#x.\n", dimension);
355 case D3D10_RESOURCE_DIMENSION_BUFFER:
356 return E_INVALIDARG;
360 static inline struct d3d10_depthstencil_view *impl_from_ID3D10DepthStencilView(ID3D10DepthStencilView *iface)
362 return CONTAINING_RECORD(iface, struct d3d10_depthstencil_view, ID3D10DepthStencilView_iface);
365 /* IUnknown methods */
367 static HRESULT STDMETHODCALLTYPE d3d10_depthstencil_view_QueryInterface(ID3D10DepthStencilView *iface,
368 REFIID riid, void **object)
370 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
372 if (IsEqualGUID(riid, &IID_ID3D10DepthStencilView)
373 || IsEqualGUID(riid, &IID_ID3D10View)
374 || IsEqualGUID(riid, &IID_ID3D10DeviceChild)
375 || IsEqualGUID(riid, &IID_IUnknown))
377 IUnknown_AddRef(iface);
378 *object = iface;
379 return S_OK;
382 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
384 *object = NULL;
385 return E_NOINTERFACE;
388 static ULONG STDMETHODCALLTYPE d3d10_depthstencil_view_AddRef(ID3D10DepthStencilView *iface)
390 struct d3d10_depthstencil_view *This = impl_from_ID3D10DepthStencilView(iface);
391 ULONG refcount = InterlockedIncrement(&This->refcount);
393 TRACE("%p increasing refcount to %u.\n", This, refcount);
395 return refcount;
398 static ULONG STDMETHODCALLTYPE d3d10_depthstencil_view_Release(ID3D10DepthStencilView *iface)
400 struct d3d10_depthstencil_view *This = impl_from_ID3D10DepthStencilView(iface);
401 ULONG refcount = InterlockedDecrement(&This->refcount);
403 TRACE("%p decreasing refcount to %u.\n", This, refcount);
405 if (!refcount)
407 wined3d_rendertarget_view_decref(This->wined3d_view);
408 ID3D10Resource_Release(This->resource);
409 ID3D10Device1_Release(This->device);
410 wined3d_private_store_cleanup(&This->private_store);
411 HeapFree(GetProcessHeap(), 0, This);
414 return refcount;
417 /* ID3D10DeviceChild methods */
419 static void STDMETHODCALLTYPE d3d10_depthstencil_view_GetDevice(ID3D10DepthStencilView *iface, ID3D10Device **device)
421 struct d3d10_depthstencil_view *view = impl_from_ID3D10DepthStencilView(iface);
423 TRACE("iface %p, device %p.\n", iface, device);
425 *device = (ID3D10Device *)view->device;
426 ID3D10Device_AddRef(*device);
429 static HRESULT STDMETHODCALLTYPE d3d10_depthstencil_view_GetPrivateData(ID3D10DepthStencilView *iface,
430 REFGUID guid, UINT *data_size, void *data)
432 struct d3d10_depthstencil_view *view = impl_from_ID3D10DepthStencilView(iface);
434 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
435 iface, debugstr_guid(guid), data_size, data);
437 return d3d10_get_private_data(&view->private_store, guid, data_size, data);
440 static HRESULT STDMETHODCALLTYPE d3d10_depthstencil_view_SetPrivateData(ID3D10DepthStencilView *iface,
441 REFGUID guid, UINT data_size, const void *data)
443 struct d3d10_depthstencil_view *view = impl_from_ID3D10DepthStencilView(iface);
445 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
446 iface, debugstr_guid(guid), data_size, data);
448 return d3d10_set_private_data(&view->private_store, guid, data_size, data);
451 static HRESULT STDMETHODCALLTYPE d3d10_depthstencil_view_SetPrivateDataInterface(ID3D10DepthStencilView *iface,
452 REFGUID guid, const IUnknown *data)
454 struct d3d10_depthstencil_view *view = impl_from_ID3D10DepthStencilView(iface);
456 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
458 return d3d10_set_private_data_interface(&view->private_store, guid, data);
461 /* ID3D10View methods */
463 static void STDMETHODCALLTYPE d3d10_depthstencil_view_GetResource(ID3D10DepthStencilView *iface,
464 ID3D10Resource **resource)
466 struct d3d10_depthstencil_view *view = impl_from_ID3D10DepthStencilView(iface);
468 TRACE("iface %p, resource %p.\n", iface, resource);
470 *resource = view->resource;
471 ID3D10Resource_AddRef(*resource);
474 /* ID3D10DepthStencilView methods */
476 static void STDMETHODCALLTYPE d3d10_depthstencil_view_GetDesc(ID3D10DepthStencilView *iface,
477 D3D10_DEPTH_STENCIL_VIEW_DESC *desc)
479 struct d3d10_depthstencil_view *view = impl_from_ID3D10DepthStencilView(iface);
481 TRACE("iface %p, desc %p.\n", iface, desc);
483 *desc = view->desc;
486 static const struct ID3D10DepthStencilViewVtbl d3d10_depthstencil_view_vtbl =
488 /* IUnknown methods */
489 d3d10_depthstencil_view_QueryInterface,
490 d3d10_depthstencil_view_AddRef,
491 d3d10_depthstencil_view_Release,
492 /* ID3D10DeviceChild methods */
493 d3d10_depthstencil_view_GetDevice,
494 d3d10_depthstencil_view_GetPrivateData,
495 d3d10_depthstencil_view_SetPrivateData,
496 d3d10_depthstencil_view_SetPrivateDataInterface,
497 /* ID3D10View methods */
498 d3d10_depthstencil_view_GetResource,
499 /* ID3D10DepthStencilView methods */
500 d3d10_depthstencil_view_GetDesc,
503 static void wined3d_depth_stencil_view_desc_from_d3d10core(struct wined3d_rendertarget_view_desc *wined3d_desc,
504 const D3D10_DEPTH_STENCIL_VIEW_DESC *desc)
506 wined3d_desc->format_id = wined3dformat_from_dxgi_format(desc->Format);
508 switch (desc->ViewDimension)
510 case D3D10_DSV_DIMENSION_TEXTURE1D:
511 wined3d_desc->u.texture.level_idx = desc->u.Texture1D.MipSlice;
512 wined3d_desc->u.texture.layer_idx = 0;
513 wined3d_desc->u.texture.layer_count = 1;
514 break;
516 case D3D10_DSV_DIMENSION_TEXTURE1DARRAY:
517 wined3d_desc->u.texture.level_idx = desc->u.Texture1DArray.MipSlice;
518 wined3d_desc->u.texture.layer_idx = desc->u.Texture1DArray.FirstArraySlice;
519 wined3d_desc->u.texture.layer_count = desc->u.Texture1DArray.ArraySize;
520 break;
522 case D3D10_DSV_DIMENSION_TEXTURE2D:
523 wined3d_desc->u.texture.level_idx = desc->u.Texture2D.MipSlice;
524 wined3d_desc->u.texture.layer_idx = 0;
525 wined3d_desc->u.texture.layer_count = 1;
526 break;
528 case D3D10_DSV_DIMENSION_TEXTURE2DARRAY:
529 wined3d_desc->u.texture.level_idx = desc->u.Texture2DArray.MipSlice;
530 wined3d_desc->u.texture.layer_idx = desc->u.Texture2DArray.FirstArraySlice;
531 wined3d_desc->u.texture.layer_count = desc->u.Texture2DArray.ArraySize;
532 break;
534 case D3D10_DSV_DIMENSION_TEXTURE2DMS:
535 wined3d_desc->u.texture.level_idx = 0;
536 wined3d_desc->u.texture.layer_idx = 0;
537 wined3d_desc->u.texture.layer_count = 1;
538 break;
540 case D3D10_DSV_DIMENSION_TEXTURE2DMSARRAY:
541 wined3d_desc->u.texture.level_idx = 0;
542 wined3d_desc->u.texture.layer_idx = desc->u.Texture2DMSArray.FirstArraySlice;
543 wined3d_desc->u.texture.layer_count = desc->u.Texture2DMSArray.ArraySize;
544 break;
546 default:
547 FIXME("Unhandled view dimension %#x.\n", desc->ViewDimension);
548 wined3d_desc->u.texture.level_idx = 0;
549 wined3d_desc->u.texture.layer_idx = 0;
550 wined3d_desc->u.texture.layer_count = 1;
551 break;
555 HRESULT d3d10_depthstencil_view_init(struct d3d10_depthstencil_view *view, struct d3d10_device *device,
556 ID3D10Resource *resource, const D3D10_DEPTH_STENCIL_VIEW_DESC *desc)
558 struct wined3d_rendertarget_view_desc wined3d_desc;
559 struct wined3d_resource *wined3d_resource;
560 HRESULT hr;
562 view->ID3D10DepthStencilView_iface.lpVtbl = &d3d10_depthstencil_view_vtbl;
563 view->refcount = 1;
565 if (!desc)
567 if (FAILED(hr = set_dsdesc_from_resource(&view->desc, resource)))
568 return hr;
570 else
572 view->desc = *desc;
575 if (!(wined3d_resource = wined3d_resource_from_resource(resource)))
577 ERR("Failed to get wined3d resource for d3d10 resource %p.\n", resource);
578 return E_FAIL;
581 wined3d_depth_stencil_view_desc_from_d3d10core(&wined3d_desc, &view->desc);
582 if (FAILED(hr = wined3d_rendertarget_view_create(&wined3d_desc, wined3d_resource,
583 view, &d3d10_null_wined3d_parent_ops, &view->wined3d_view)))
585 WARN("Failed to create a wined3d rendertarget view, hr %#x.\n", hr);
586 return hr;
589 wined3d_private_store_init(&view->private_store);
590 view->resource = resource;
591 ID3D10Resource_AddRef(resource);
592 view->device = &device->ID3D10Device1_iface;
593 ID3D10Device1_AddRef(view->device);
595 return S_OK;
598 struct d3d10_depthstencil_view *unsafe_impl_from_ID3D10DepthStencilView(ID3D10DepthStencilView *iface)
600 if (!iface)
601 return NULL;
602 assert(iface->lpVtbl == &d3d10_depthstencil_view_vtbl);
604 return impl_from_ID3D10DepthStencilView(iface);
607 static inline struct d3d10_rendertarget_view *impl_from_ID3D10RenderTargetView(ID3D10RenderTargetView *iface)
609 return CONTAINING_RECORD(iface, struct d3d10_rendertarget_view, ID3D10RenderTargetView_iface);
612 /* IUnknown methods */
614 static HRESULT STDMETHODCALLTYPE d3d10_rendertarget_view_QueryInterface(ID3D10RenderTargetView *iface,
615 REFIID riid, void **object)
617 TRACE("iface %p, riid %s, object %p\n", iface, debugstr_guid(riid), object);
619 if (IsEqualGUID(riid, &IID_ID3D10RenderTargetView)
620 || IsEqualGUID(riid, &IID_ID3D10View)
621 || IsEqualGUID(riid, &IID_ID3D10DeviceChild)
622 || IsEqualGUID(riid, &IID_IUnknown))
624 IUnknown_AddRef(iface);
625 *object = iface;
626 return S_OK;
629 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid));
631 *object = NULL;
632 return E_NOINTERFACE;
635 static ULONG STDMETHODCALLTYPE d3d10_rendertarget_view_AddRef(ID3D10RenderTargetView *iface)
637 struct d3d10_rendertarget_view *This = impl_from_ID3D10RenderTargetView(iface);
638 ULONG refcount = InterlockedIncrement(&This->refcount);
640 TRACE("%p increasing refcount to %u\n", This, refcount);
642 return refcount;
645 static ULONG STDMETHODCALLTYPE d3d10_rendertarget_view_Release(ID3D10RenderTargetView *iface)
647 struct d3d10_rendertarget_view *This = impl_from_ID3D10RenderTargetView(iface);
648 ULONG refcount = InterlockedDecrement(&This->refcount);
650 TRACE("%p decreasing refcount to %u\n", This, refcount);
652 if (!refcount)
654 wined3d_rendertarget_view_decref(This->wined3d_view);
655 ID3D10Resource_Release(This->resource);
656 ID3D10Device1_Release(This->device);
657 wined3d_private_store_cleanup(&This->private_store);
658 HeapFree(GetProcessHeap(), 0, This);
661 return refcount;
664 /* ID3D10DeviceChild methods */
666 static void STDMETHODCALLTYPE d3d10_rendertarget_view_GetDevice(ID3D10RenderTargetView *iface, ID3D10Device **device)
668 struct d3d10_rendertarget_view *view = impl_from_ID3D10RenderTargetView(iface);
670 TRACE("iface %p, device %p.\n", iface, device);
672 *device = (ID3D10Device *)view->device;
673 ID3D10Device_AddRef(*device);
676 static HRESULT STDMETHODCALLTYPE d3d10_rendertarget_view_GetPrivateData(ID3D10RenderTargetView *iface,
677 REFGUID guid, UINT *data_size, void *data)
679 struct d3d10_rendertarget_view *view = impl_from_ID3D10RenderTargetView(iface);
681 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
682 iface, debugstr_guid(guid), data_size, data);
684 return d3d10_get_private_data(&view->private_store, guid, data_size, data);
687 static HRESULT STDMETHODCALLTYPE d3d10_rendertarget_view_SetPrivateData(ID3D10RenderTargetView *iface,
688 REFGUID guid, UINT data_size, const void *data)
690 struct d3d10_rendertarget_view *view = impl_from_ID3D10RenderTargetView(iface);
692 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
693 iface, debugstr_guid(guid), data_size, data);
695 return d3d10_set_private_data(&view->private_store, guid, data_size, data);
698 static HRESULT STDMETHODCALLTYPE d3d10_rendertarget_view_SetPrivateDataInterface(ID3D10RenderTargetView *iface,
699 REFGUID guid, const IUnknown *data)
701 struct d3d10_rendertarget_view *view = impl_from_ID3D10RenderTargetView(iface);
703 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
705 return d3d10_set_private_data_interface(&view->private_store, guid, data);
708 /* ID3D10View methods */
710 static void STDMETHODCALLTYPE d3d10_rendertarget_view_GetResource(ID3D10RenderTargetView *iface,
711 ID3D10Resource **resource)
713 struct d3d10_rendertarget_view *view = impl_from_ID3D10RenderTargetView(iface);
715 TRACE("iface %p, resource %p\n", iface, resource);
717 *resource = view->resource;
718 ID3D10Resource_AddRef(*resource);
721 /* ID3D10RenderTargetView methods */
723 static void STDMETHODCALLTYPE d3d10_rendertarget_view_GetDesc(ID3D10RenderTargetView *iface,
724 D3D10_RENDER_TARGET_VIEW_DESC *desc)
726 struct d3d10_rendertarget_view *This = impl_from_ID3D10RenderTargetView(iface);
728 TRACE("iface %p, desc %p\n", iface, desc);
730 *desc = This->desc;
733 static const struct ID3D10RenderTargetViewVtbl d3d10_rendertarget_view_vtbl =
735 /* IUnknown methods */
736 d3d10_rendertarget_view_QueryInterface,
737 d3d10_rendertarget_view_AddRef,
738 d3d10_rendertarget_view_Release,
739 /* ID3D10DeviceChild methods */
740 d3d10_rendertarget_view_GetDevice,
741 d3d10_rendertarget_view_GetPrivateData,
742 d3d10_rendertarget_view_SetPrivateData,
743 d3d10_rendertarget_view_SetPrivateDataInterface,
744 /* ID3D10View methods */
745 d3d10_rendertarget_view_GetResource,
746 /* ID3D10RenderTargetView methods */
747 d3d10_rendertarget_view_GetDesc,
750 static void wined3d_rendertarget_view_desc_from_d3d10core(struct wined3d_rendertarget_view_desc *wined3d_desc,
751 const D3D10_RENDER_TARGET_VIEW_DESC *desc)
753 wined3d_desc->format_id = wined3dformat_from_dxgi_format(desc->Format);
755 switch (desc->ViewDimension)
757 case D3D10_RTV_DIMENSION_BUFFER:
758 wined3d_desc->u.buffer.start_idx = desc->u.Buffer.ElementOffset;
759 wined3d_desc->u.buffer.count = desc->u.Buffer.ElementWidth;
760 break;
762 case D3D10_RTV_DIMENSION_TEXTURE1D:
763 wined3d_desc->u.texture.level_idx = desc->u.Texture1D.MipSlice;
764 wined3d_desc->u.texture.layer_idx = 0;
765 wined3d_desc->u.texture.layer_count = 1;
766 break;
768 case D3D10_RTV_DIMENSION_TEXTURE1DARRAY:
769 wined3d_desc->u.texture.level_idx = desc->u.Texture1DArray.MipSlice;
770 wined3d_desc->u.texture.layer_idx = desc->u.Texture1DArray.FirstArraySlice;
771 wined3d_desc->u.texture.layer_count = desc->u.Texture1DArray.ArraySize;
772 break;
774 case D3D10_RTV_DIMENSION_TEXTURE2D:
775 wined3d_desc->u.texture.level_idx = desc->u.Texture2D.MipSlice;
776 wined3d_desc->u.texture.layer_idx = 0;
777 wined3d_desc->u.texture.layer_count = 1;
778 break;
780 case D3D10_RTV_DIMENSION_TEXTURE2DARRAY:
781 wined3d_desc->u.texture.level_idx = desc->u.Texture2DArray.MipSlice;
782 wined3d_desc->u.texture.layer_idx = desc->u.Texture2DArray.FirstArraySlice;
783 wined3d_desc->u.texture.layer_count = desc->u.Texture2DArray.ArraySize;
784 break;
786 case D3D10_RTV_DIMENSION_TEXTURE2DMS:
787 wined3d_desc->u.texture.level_idx = 0;
788 wined3d_desc->u.texture.layer_idx = 0;
789 wined3d_desc->u.texture.layer_count = 1;
790 break;
792 case D3D10_RTV_DIMENSION_TEXTURE2DMSARRAY:
793 wined3d_desc->u.texture.level_idx = 0;
794 wined3d_desc->u.texture.layer_idx = desc->u.Texture2DMSArray.FirstArraySlice;
795 wined3d_desc->u.texture.layer_count = desc->u.Texture2DMSArray.ArraySize;
796 break;
798 case D3D10_RTV_DIMENSION_TEXTURE3D:
799 wined3d_desc->u.texture.level_idx = desc->u.Texture3D.MipSlice;
800 wined3d_desc->u.texture.layer_idx = desc->u.Texture3D.FirstWSlice;
801 wined3d_desc->u.texture.layer_count = desc->u.Texture3D.WSize;
802 break;
804 default:
805 FIXME("Unhandled view dimension %#x.\n", desc->ViewDimension);
806 wined3d_desc->u.texture.level_idx = 0;
807 wined3d_desc->u.texture.layer_idx = 0;
808 wined3d_desc->u.texture.layer_count = 1;
809 break;
813 HRESULT d3d10_rendertarget_view_init(struct d3d10_rendertarget_view *view, struct d3d10_device *device,
814 ID3D10Resource *resource, const D3D10_RENDER_TARGET_VIEW_DESC *desc)
816 struct wined3d_rendertarget_view_desc wined3d_desc;
817 struct wined3d_resource *wined3d_resource;
818 HRESULT hr;
820 view->ID3D10RenderTargetView_iface.lpVtbl = &d3d10_rendertarget_view_vtbl;
821 view->refcount = 1;
823 if (!desc)
825 HRESULT hr = set_rtdesc_from_resource(&view->desc, resource);
826 if (FAILED(hr)) return hr;
828 else
830 view->desc = *desc;
833 wined3d_resource = wined3d_resource_from_resource(resource);
834 if (!wined3d_resource)
836 ERR("Failed to get wined3d resource for d3d10 resource %p.\n", resource);
837 return E_FAIL;
840 wined3d_rendertarget_view_desc_from_d3d10core(&wined3d_desc, &view->desc);
841 if (FAILED(hr = wined3d_rendertarget_view_create(&wined3d_desc, wined3d_resource,
842 view, &d3d10_null_wined3d_parent_ops, &view->wined3d_view)))
844 WARN("Failed to create a wined3d rendertarget view, hr %#x.\n", hr);
845 return hr;
848 wined3d_private_store_init(&view->private_store);
849 view->resource = resource;
850 ID3D10Resource_AddRef(resource);
851 view->device = &device->ID3D10Device1_iface;
852 ID3D10Device1_AddRef(view->device);
854 return S_OK;
857 struct d3d10_rendertarget_view *unsafe_impl_from_ID3D10RenderTargetView(ID3D10RenderTargetView *iface)
859 if (!iface)
860 return NULL;
861 assert(iface->lpVtbl == &d3d10_rendertarget_view_vtbl);
863 return impl_from_ID3D10RenderTargetView(iface);
866 static inline struct d3d10_shader_resource_view *impl_from_ID3D10ShaderResourceView(ID3D10ShaderResourceView *iface)
868 return CONTAINING_RECORD(iface, struct d3d10_shader_resource_view, ID3D10ShaderResourceView_iface);
871 /* IUnknown methods */
873 static HRESULT STDMETHODCALLTYPE d3d10_shader_resource_view_QueryInterface(ID3D10ShaderResourceView *iface,
874 REFIID riid, void **object)
876 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
878 if (IsEqualGUID(riid, &IID_ID3D10ShaderResourceView)
879 || IsEqualGUID(riid, &IID_ID3D10View)
880 || IsEqualGUID(riid, &IID_ID3D10DeviceChild)
881 || IsEqualGUID(riid, &IID_IUnknown))
883 IUnknown_AddRef(iface);
884 *object = iface;
885 return S_OK;
888 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
890 *object = NULL;
891 return E_NOINTERFACE;
894 static ULONG STDMETHODCALLTYPE d3d10_shader_resource_view_AddRef(ID3D10ShaderResourceView *iface)
896 struct d3d10_shader_resource_view *This = impl_from_ID3D10ShaderResourceView(iface);
897 ULONG refcount = InterlockedIncrement(&This->refcount);
899 TRACE("%p increasing refcount to %u.\n", This, refcount);
901 return refcount;
904 static ULONG STDMETHODCALLTYPE d3d10_shader_resource_view_Release(ID3D10ShaderResourceView *iface)
906 struct d3d10_shader_resource_view *This = impl_from_ID3D10ShaderResourceView(iface);
907 ULONG refcount = InterlockedDecrement(&This->refcount);
909 TRACE("%p decreasing refcount to %u.\n", This, refcount);
911 if (!refcount)
913 wined3d_shader_resource_view_decref(This->wined3d_view);
914 ID3D10Resource_Release(This->resource);
915 ID3D10Device1_Release(This->device);
916 wined3d_private_store_cleanup(&This->private_store);
917 HeapFree(GetProcessHeap(), 0, This);
920 return refcount;
923 /* ID3D10DeviceChild methods */
925 static void STDMETHODCALLTYPE d3d10_shader_resource_view_GetDevice(ID3D10ShaderResourceView *iface,
926 ID3D10Device **device)
928 struct d3d10_shader_resource_view *view = impl_from_ID3D10ShaderResourceView(iface);
930 TRACE("iface %p, device %p.\n", iface, device);
932 *device = (ID3D10Device *)view->device;
933 ID3D10Device_AddRef(*device);
936 static HRESULT STDMETHODCALLTYPE d3d10_shader_resource_view_GetPrivateData(ID3D10ShaderResourceView *iface,
937 REFGUID guid, UINT *data_size, void *data)
939 struct d3d10_shader_resource_view *view = impl_from_ID3D10ShaderResourceView(iface);
941 TRACE("iface %p, guid %s, data_size %p, data %p.\n",
942 iface, debugstr_guid(guid), data_size, data);
944 return d3d10_get_private_data(&view->private_store, guid, data_size, data);
947 static HRESULT STDMETHODCALLTYPE d3d10_shader_resource_view_SetPrivateData(ID3D10ShaderResourceView *iface,
948 REFGUID guid, UINT data_size, const void *data)
950 struct d3d10_shader_resource_view *view = impl_from_ID3D10ShaderResourceView(iface);
952 TRACE("iface %p, guid %s, data_size %u, data %p.\n",
953 iface, debugstr_guid(guid), data_size, data);
955 return d3d10_set_private_data(&view->private_store, guid, data_size, data);
958 static HRESULT STDMETHODCALLTYPE d3d10_shader_resource_view_SetPrivateDataInterface(ID3D10ShaderResourceView *iface,
959 REFGUID guid, const IUnknown *data)
961 struct d3d10_shader_resource_view *view = impl_from_ID3D10ShaderResourceView(iface);
963 TRACE("iface %p, guid %s, data %p.\n", iface, debugstr_guid(guid), data);
965 return d3d10_set_private_data_interface(&view->private_store, guid, data);
968 /* ID3D10View methods */
970 static void STDMETHODCALLTYPE d3d10_shader_resource_view_GetResource(ID3D10ShaderResourceView *iface,
971 ID3D10Resource **resource)
973 struct d3d10_shader_resource_view *view = impl_from_ID3D10ShaderResourceView(iface);
975 TRACE("iface %p, resource %p.\n", iface, resource);
977 *resource = view->resource;
978 ID3D10Resource_AddRef(*resource);
981 /* ID3D10ShaderResourceView methods */
983 static void STDMETHODCALLTYPE d3d10_shader_resource_view_GetDesc(ID3D10ShaderResourceView *iface,
984 D3D10_SHADER_RESOURCE_VIEW_DESC *desc)
986 struct d3d10_shader_resource_view *view = impl_from_ID3D10ShaderResourceView(iface);
988 TRACE("iface %p, desc %p.\n", iface, desc);
990 *desc = view->desc;
993 static const struct ID3D10ShaderResourceViewVtbl d3d10_shader_resource_view_vtbl =
995 /* IUnknown methods */
996 d3d10_shader_resource_view_QueryInterface,
997 d3d10_shader_resource_view_AddRef,
998 d3d10_shader_resource_view_Release,
999 /* ID3D10DeviceChild methods */
1000 d3d10_shader_resource_view_GetDevice,
1001 d3d10_shader_resource_view_GetPrivateData,
1002 d3d10_shader_resource_view_SetPrivateData,
1003 d3d10_shader_resource_view_SetPrivateDataInterface,
1004 /* ID3D10View methods */
1005 d3d10_shader_resource_view_GetResource,
1006 /* ID3D10ShaderResourceView methods */
1007 d3d10_shader_resource_view_GetDesc,
1010 HRESULT d3d10_shader_resource_view_init(struct d3d10_shader_resource_view *view, struct d3d10_device *device,
1011 ID3D10Resource *resource, const D3D10_SHADER_RESOURCE_VIEW_DESC *desc)
1013 struct wined3d_resource *wined3d_resource;
1014 HRESULT hr;
1016 view->ID3D10ShaderResourceView_iface.lpVtbl = &d3d10_shader_resource_view_vtbl;
1017 view->refcount = 1;
1019 if (!desc)
1021 if (FAILED(hr = set_srdesc_from_resource(&view->desc, resource)))
1022 return hr;
1024 else
1026 view->desc = *desc;
1029 if (!(wined3d_resource = wined3d_resource_from_resource(resource)))
1031 ERR("Failed to get wined3d resource for d3d10 resource %p.\n", resource);
1032 return E_FAIL;
1035 if (FAILED(hr = wined3d_shader_resource_view_create(wined3d_resource,
1036 view, &d3d10_null_wined3d_parent_ops, &view->wined3d_view)))
1038 WARN("Failed to create wined3d shader resource view, hr %#x.\n", hr);
1039 return hr;
1042 wined3d_private_store_init(&view->private_store);
1043 view->resource = resource;
1044 ID3D10Resource_AddRef(resource);
1045 view->device = &device->ID3D10Device1_iface;
1046 ID3D10Device1_AddRef(view->device);
1048 return S_OK;
1051 struct d3d10_shader_resource_view *unsafe_impl_from_ID3D10ShaderResourceView(ID3D10ShaderResourceView *iface)
1053 if (!iface)
1054 return NULL;
1055 assert(iface->lpVtbl == &d3d10_shader_resource_view_vtbl);
1056 return CONTAINING_RECORD(iface, struct d3d10_shader_resource_view, ID3D10ShaderResourceView_iface);