wineps: Simplify the failure path.
[wine/multimedia.git] / dlls / d3d10core / view.c
blob57c4148e63dc510e2e51a6d7522779982e52f68f
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"
22 #include <assert.h>
24 #define NONAMELESSUNION
25 #include "d3d10core_private.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(d3d10core);
29 static struct wined3d_resource *wined3d_resource_from_resource(ID3D10Resource *resource)
31 D3D10_RESOURCE_DIMENSION dimension;
33 ID3D10Resource_GetType(resource, &dimension);
35 switch(dimension)
37 case D3D10_RESOURCE_DIMENSION_BUFFER:
38 return wined3d_buffer_get_resource(((struct d3d10_buffer *)resource)->wined3d_buffer);
40 case D3D10_RESOURCE_DIMENSION_TEXTURE2D:
41 return wined3d_surface_get_resource(((struct d3d10_texture2d *)resource)->wined3d_surface);
43 default:
44 FIXME("Unhandled resource dimension %#x.\n", dimension);
45 return NULL;
49 static HRESULT set_rtdesc_from_resource(D3D10_RENDER_TARGET_VIEW_DESC *desc, ID3D10Resource *resource)
51 D3D10_RESOURCE_DIMENSION dimension;
52 HRESULT hr;
54 ID3D10Resource_GetType(resource, &dimension);
56 switch(dimension)
58 case D3D10_RESOURCE_DIMENSION_TEXTURE1D:
60 ID3D10Texture1D *texture;
61 D3D10_TEXTURE1D_DESC texture_desc;
63 hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D10Texture1D, (void **)&texture);
64 if (FAILED(hr))
66 ERR("Resource of type TEXTURE1D doesn't implement ID3D10Texture1D?\n");
67 return E_INVALIDARG;
70 ID3D10Texture1D_GetDesc(texture, &texture_desc);
71 ID3D10Texture1D_Release(texture);
73 desc->Format = texture_desc.Format;
74 if (texture_desc.ArraySize == 1)
76 desc->ViewDimension = D3D10_RTV_DIMENSION_TEXTURE1D;
77 desc->u.Texture1D.MipSlice = 0;
79 else
81 desc->ViewDimension = D3D10_RTV_DIMENSION_TEXTURE1DARRAY;
82 desc->u.Texture1DArray.MipSlice = 0;
83 desc->u.Texture1DArray.FirstArraySlice = 0;
84 desc->u.Texture1DArray.ArraySize = 1;
87 return S_OK;
90 case D3D10_RESOURCE_DIMENSION_TEXTURE2D:
92 ID3D10Texture2D *texture;
93 D3D10_TEXTURE2D_DESC texture_desc;
95 hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D10Texture2D, (void **)&texture);
96 if (FAILED(hr))
98 ERR("Resource of type TEXTURE2D doesn't implement ID3D10Texture2D?\n");
99 return E_INVALIDARG;
102 ID3D10Texture2D_GetDesc(texture, &texture_desc);
103 ID3D10Texture2D_Release(texture);
105 desc->Format = texture_desc.Format;
106 if (texture_desc.ArraySize == 1)
108 if (texture_desc.SampleDesc.Count == 1)
110 desc->ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2D;
111 desc->u.Texture2D.MipSlice = 0;
113 else
115 desc->ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2DMS;
118 else
120 if (texture_desc.SampleDesc.Count == 1)
122 desc->ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2DARRAY;
123 desc->u.Texture2DArray.MipSlice = 0;
124 desc->u.Texture2DArray.FirstArraySlice = 0;
125 desc->u.Texture2DArray.ArraySize = 1;
127 else
129 desc->ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2DMSARRAY;
130 desc->u.Texture2DMSArray.FirstArraySlice = 0;
131 desc->u.Texture2DMSArray.ArraySize = 1;
135 return S_OK;
138 case D3D10_RESOURCE_DIMENSION_TEXTURE3D:
140 ID3D10Texture3D *texture;
141 D3D10_TEXTURE3D_DESC texture_desc;
143 hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D10Texture3D, (void **)&texture);
144 if (FAILED(hr))
146 ERR("Resource of type TEXTURE3D doesn't implement ID3D10Texture3D?\n");
147 return E_INVALIDARG;
150 ID3D10Texture3D_GetDesc(texture, &texture_desc);
151 ID3D10Texture3D_Release(texture);
153 desc->Format = texture_desc.Format;
154 desc->ViewDimension = D3D10_RTV_DIMENSION_TEXTURE3D;
155 desc->u.Texture3D.MipSlice = 0;
156 desc->u.Texture3D.FirstWSlice = 0;
157 desc->u.Texture3D.WSize = 1;
159 return S_OK;
162 default:
163 FIXME("Unhandled resource dimension %#x.\n", dimension);
164 return E_INVALIDARG;
168 static inline struct d3d10_depthstencil_view *impl_from_ID3D10DepthStencilView(ID3D10DepthStencilView *iface)
170 return CONTAINING_RECORD(iface, struct d3d10_depthstencil_view, ID3D10DepthStencilView_iface);
173 /* IUnknown methods */
175 static HRESULT STDMETHODCALLTYPE d3d10_depthstencil_view_QueryInterface(ID3D10DepthStencilView *iface,
176 REFIID riid, void **object)
178 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
180 if (IsEqualGUID(riid, &IID_ID3D10DepthStencilView)
181 || IsEqualGUID(riid, &IID_ID3D10View)
182 || IsEqualGUID(riid, &IID_ID3D10DeviceChild)
183 || IsEqualGUID(riid, &IID_IUnknown))
185 IUnknown_AddRef(iface);
186 *object = iface;
187 return S_OK;
190 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
192 *object = NULL;
193 return E_NOINTERFACE;
196 static ULONG STDMETHODCALLTYPE d3d10_depthstencil_view_AddRef(ID3D10DepthStencilView *iface)
198 struct d3d10_depthstencil_view *This = impl_from_ID3D10DepthStencilView(iface);
199 ULONG refcount = InterlockedIncrement(&This->refcount);
201 TRACE("%p increasing refcount to %u.\n", This, refcount);
203 return refcount;
206 static ULONG STDMETHODCALLTYPE d3d10_depthstencil_view_Release(ID3D10DepthStencilView *iface)
208 struct d3d10_depthstencil_view *This = impl_from_ID3D10DepthStencilView(iface);
209 ULONG refcount = InterlockedDecrement(&This->refcount);
211 TRACE("%p decreasing refcount to %u.\n", This, refcount);
213 if (!refcount)
215 HeapFree(GetProcessHeap(), 0, This);
218 return refcount;
221 /* ID3D10DeviceChild methods */
223 static void STDMETHODCALLTYPE d3d10_depthstencil_view_GetDevice(ID3D10DepthStencilView *iface, ID3D10Device **device)
225 FIXME("iface %p, device %p stub!\n", iface, device);
228 static HRESULT STDMETHODCALLTYPE d3d10_depthstencil_view_GetPrivateData(ID3D10DepthStencilView *iface,
229 REFGUID guid, UINT *data_size, void *data)
231 FIXME("iface %p, guid %s, data_size %p, data %p stub!\n",
232 iface, debugstr_guid(guid), data_size, data);
234 return E_NOTIMPL;
237 static HRESULT STDMETHODCALLTYPE d3d10_depthstencil_view_SetPrivateData(ID3D10DepthStencilView *iface,
238 REFGUID guid, UINT data_size, const void *data)
240 FIXME("iface %p, guid %s, data_size %u, data %p stub!\n",
241 iface, debugstr_guid(guid), data_size, data);
243 return E_NOTIMPL;
246 static HRESULT STDMETHODCALLTYPE d3d10_depthstencil_view_SetPrivateDataInterface(ID3D10DepthStencilView *iface,
247 REFGUID guid, const IUnknown *data)
249 FIXME("iface %p, guid %s, data %p stub!\n", iface, debugstr_guid(guid), data);
251 return E_NOTIMPL;
254 /* ID3D10View methods */
256 static void STDMETHODCALLTYPE d3d10_depthstencil_view_GetResource(ID3D10DepthStencilView *iface,
257 ID3D10Resource **resource)
259 FIXME("iface %p, resource %p stub!\n", iface, resource);
262 /* ID3D10DepthStencilView methods */
264 static void STDMETHODCALLTYPE d3d10_depthstencil_view_GetDesc(ID3D10DepthStencilView *iface,
265 D3D10_DEPTH_STENCIL_VIEW_DESC *desc)
267 FIXME("iface %p, desc %p stub!\n", iface, desc);
270 static const struct ID3D10DepthStencilViewVtbl d3d10_depthstencil_view_vtbl =
272 /* IUnknown methods */
273 d3d10_depthstencil_view_QueryInterface,
274 d3d10_depthstencil_view_AddRef,
275 d3d10_depthstencil_view_Release,
276 /* ID3D10DeviceChild methods */
277 d3d10_depthstencil_view_GetDevice,
278 d3d10_depthstencil_view_GetPrivateData,
279 d3d10_depthstencil_view_SetPrivateData,
280 d3d10_depthstencil_view_SetPrivateDataInterface,
281 /* ID3D10View methods */
282 d3d10_depthstencil_view_GetResource,
283 /* ID3D10DepthStencilView methods */
284 d3d10_depthstencil_view_GetDesc,
287 HRESULT d3d10_depthstencil_view_init(struct d3d10_depthstencil_view *view)
289 view->ID3D10DepthStencilView_iface.lpVtbl = &d3d10_depthstencil_view_vtbl;
290 view->refcount = 1;
292 return S_OK;
295 static inline struct d3d10_rendertarget_view *impl_from_ID3D10RenderTargetView(ID3D10RenderTargetView *iface)
297 return CONTAINING_RECORD(iface, struct d3d10_rendertarget_view, ID3D10RenderTargetView_iface);
300 /* IUnknown methods */
302 static HRESULT STDMETHODCALLTYPE d3d10_rendertarget_view_QueryInterface(ID3D10RenderTargetView *iface,
303 REFIID riid, void **object)
305 TRACE("iface %p, riid %s, object %p\n", iface, debugstr_guid(riid), object);
307 if (IsEqualGUID(riid, &IID_ID3D10RenderTargetView)
308 || IsEqualGUID(riid, &IID_ID3D10View)
309 || IsEqualGUID(riid, &IID_ID3D10DeviceChild)
310 || IsEqualGUID(riid, &IID_IUnknown))
312 IUnknown_AddRef(iface);
313 *object = iface;
314 return S_OK;
317 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid));
319 *object = NULL;
320 return E_NOINTERFACE;
323 static ULONG STDMETHODCALLTYPE d3d10_rendertarget_view_AddRef(ID3D10RenderTargetView *iface)
325 struct d3d10_rendertarget_view *This = impl_from_ID3D10RenderTargetView(iface);
326 ULONG refcount = InterlockedIncrement(&This->refcount);
328 TRACE("%p increasing refcount to %u\n", This, refcount);
330 return refcount;
333 static ULONG STDMETHODCALLTYPE d3d10_rendertarget_view_Release(ID3D10RenderTargetView *iface)
335 struct d3d10_rendertarget_view *This = impl_from_ID3D10RenderTargetView(iface);
336 ULONG refcount = InterlockedDecrement(&This->refcount);
338 TRACE("%p decreasing refcount to %u\n", This, refcount);
340 if (!refcount)
342 wined3d_rendertarget_view_decref(This->wined3d_view);
343 HeapFree(GetProcessHeap(), 0, This);
346 return refcount;
349 /* ID3D10DeviceChild methods */
351 static void STDMETHODCALLTYPE d3d10_rendertarget_view_GetDevice(ID3D10RenderTargetView *iface, ID3D10Device **device)
353 FIXME("iface %p, device %p stub!\n", iface, device);
356 static HRESULT STDMETHODCALLTYPE d3d10_rendertarget_view_GetPrivateData(ID3D10RenderTargetView *iface,
357 REFGUID guid, UINT *data_size, void *data)
359 FIXME("iface %p, guid %s, data_size %p, data %p stub!\n",
360 iface, debugstr_guid(guid), data_size, data);
362 return E_NOTIMPL;
365 static HRESULT STDMETHODCALLTYPE d3d10_rendertarget_view_SetPrivateData(ID3D10RenderTargetView *iface,
366 REFGUID guid, UINT data_size, const void *data)
368 FIXME("iface %p, guid %s, data_size %u, data %p stub!\n",
369 iface, debugstr_guid(guid), data_size, data);
371 return E_NOTIMPL;
374 static HRESULT STDMETHODCALLTYPE d3d10_rendertarget_view_SetPrivateDataInterface(ID3D10RenderTargetView *iface,
375 REFGUID guid, const IUnknown *data)
377 FIXME("iface %p, guid %s, data %p stub!\n", iface, debugstr_guid(guid), data);
379 return E_NOTIMPL;
382 /* ID3D10View methods */
384 static void STDMETHODCALLTYPE d3d10_rendertarget_view_GetResource(ID3D10RenderTargetView *iface,
385 ID3D10Resource **resource)
387 struct d3d10_rendertarget_view *This = impl_from_ID3D10RenderTargetView(iface);
388 struct wined3d_resource *wined3d_resource;
389 IUnknown *parent;
390 HRESULT hr;
392 TRACE("iface %p, resource %p\n", iface, resource);
394 wined3d_resource = wined3d_rendertarget_view_get_resource(This->wined3d_view);
395 if (!wined3d_resource)
397 ERR("Failed to get wined3d resource.\n");
398 *resource = NULL;
399 return;
402 parent = wined3d_resource_get_parent(wined3d_resource);
403 hr = IUnknown_QueryInterface(parent, &IID_ID3D10Resource, (void **)&resource);
404 if (FAILED(hr))
406 ERR("Resource parent isn't a d3d10 resource, hr %#x\n", hr);
407 *resource = NULL;
408 return;
412 /* ID3D10RenderTargetView methods */
414 static void STDMETHODCALLTYPE d3d10_rendertarget_view_GetDesc(ID3D10RenderTargetView *iface,
415 D3D10_RENDER_TARGET_VIEW_DESC *desc)
417 struct d3d10_rendertarget_view *This = impl_from_ID3D10RenderTargetView(iface);
419 TRACE("iface %p, desc %p\n", iface, desc);
421 *desc = This->desc;
424 static const struct ID3D10RenderTargetViewVtbl d3d10_rendertarget_view_vtbl =
426 /* IUnknown methods */
427 d3d10_rendertarget_view_QueryInterface,
428 d3d10_rendertarget_view_AddRef,
429 d3d10_rendertarget_view_Release,
430 /* ID3D10DeviceChild methods */
431 d3d10_rendertarget_view_GetDevice,
432 d3d10_rendertarget_view_GetPrivateData,
433 d3d10_rendertarget_view_SetPrivateData,
434 d3d10_rendertarget_view_SetPrivateDataInterface,
435 /* ID3D10View methods */
436 d3d10_rendertarget_view_GetResource,
437 /* ID3D10RenderTargetView methods */
438 d3d10_rendertarget_view_GetDesc,
441 HRESULT d3d10_rendertarget_view_init(struct d3d10_rendertarget_view *view,
442 ID3D10Resource *resource, const D3D10_RENDER_TARGET_VIEW_DESC *desc)
444 struct wined3d_resource *wined3d_resource;
445 HRESULT hr;
447 view->ID3D10RenderTargetView_iface.lpVtbl = &d3d10_rendertarget_view_vtbl;
448 view->refcount = 1;
450 if (!desc)
452 HRESULT hr = set_rtdesc_from_resource(&view->desc, resource);
453 if (FAILED(hr)) return hr;
455 else
457 view->desc = *desc;
460 wined3d_resource = wined3d_resource_from_resource(resource);
461 if (!wined3d_resource)
463 ERR("Failed to get wined3d resource for d3d10 resource %p.\n", resource);
464 return E_FAIL;
467 hr = wined3d_rendertarget_view_create(wined3d_resource, view, &view->wined3d_view);
468 if (FAILED(hr))
470 WARN("Failed to create a wined3d rendertarget view, hr %#x.\n", hr);
471 return hr;
474 return S_OK;
477 struct d3d10_rendertarget_view *unsafe_impl_from_ID3D10RenderTargetView(ID3D10RenderTargetView *iface)
479 if (!iface)
480 return NULL;
481 assert(iface->lpVtbl == &d3d10_rendertarget_view_vtbl);
483 return impl_from_ID3D10RenderTargetView(iface);
486 static inline struct d3d10_shader_resource_view *impl_from_ID3D10ShaderResourceView(ID3D10ShaderResourceView *iface)
488 return CONTAINING_RECORD(iface, struct d3d10_shader_resource_view, ID3D10ShaderResourceView_iface);
491 /* IUnknown methods */
493 static HRESULT STDMETHODCALLTYPE d3d10_shader_resource_view_QueryInterface(ID3D10ShaderResourceView *iface,
494 REFIID riid, void **object)
496 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
498 if (IsEqualGUID(riid, &IID_ID3D10ShaderResourceView)
499 || IsEqualGUID(riid, &IID_ID3D10View)
500 || IsEqualGUID(riid, &IID_ID3D10DeviceChild)
501 || IsEqualGUID(riid, &IID_IUnknown))
503 IUnknown_AddRef(iface);
504 *object = iface;
505 return S_OK;
508 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
510 *object = NULL;
511 return E_NOINTERFACE;
514 static ULONG STDMETHODCALLTYPE d3d10_shader_resource_view_AddRef(ID3D10ShaderResourceView *iface)
516 struct d3d10_shader_resource_view *This = impl_from_ID3D10ShaderResourceView(iface);
517 ULONG refcount = InterlockedIncrement(&This->refcount);
519 TRACE("%p increasing refcount to %u.\n", This, refcount);
521 return refcount;
524 static ULONG STDMETHODCALLTYPE d3d10_shader_resource_view_Release(ID3D10ShaderResourceView *iface)
526 struct d3d10_shader_resource_view *This = impl_from_ID3D10ShaderResourceView(iface);
527 ULONG refcount = InterlockedDecrement(&This->refcount);
529 TRACE("%p decreasing refcount to %u.\n", This, refcount);
531 if (!refcount)
533 HeapFree(GetProcessHeap(), 0, This);
536 return refcount;
539 /* ID3D10DeviceChild methods */
541 static void STDMETHODCALLTYPE d3d10_shader_resource_view_GetDevice(ID3D10ShaderResourceView *iface,
542 ID3D10Device **device)
544 FIXME("iface %p, device %p stub!\n", iface, device);
547 static HRESULT STDMETHODCALLTYPE d3d10_shader_resource_view_GetPrivateData(ID3D10ShaderResourceView *iface,
548 REFGUID guid, UINT *data_size, void *data)
550 FIXME("iface %p, guid %s, data_size %p, data %p stub!\n",
551 iface, debugstr_guid(guid), data_size, data);
553 return E_NOTIMPL;
556 static HRESULT STDMETHODCALLTYPE d3d10_shader_resource_view_SetPrivateData(ID3D10ShaderResourceView *iface,
557 REFGUID guid, UINT data_size, const void *data)
559 FIXME("iface %p, guid %s, data_size %u, data %p stub!\n",
560 iface, debugstr_guid(guid), data_size, data);
562 return E_NOTIMPL;
565 static HRESULT STDMETHODCALLTYPE d3d10_shader_resource_view_SetPrivateDataInterface(ID3D10ShaderResourceView *iface,
566 REFGUID guid, const IUnknown *data)
568 FIXME("iface %p, guid %s, data %p stub!\n", iface, debugstr_guid(guid), data);
570 return E_NOTIMPL;
573 /* ID3D10View methods */
575 static void STDMETHODCALLTYPE d3d10_shader_resource_view_GetResource(ID3D10ShaderResourceView *iface,
576 ID3D10Resource **resource)
578 FIXME("iface %p, resource %p stub!\n", iface, resource);
581 /* ID3D10ShaderResourceView methods */
583 static void STDMETHODCALLTYPE d3d10_shader_resource_view_GetDesc(ID3D10ShaderResourceView *iface,
584 D3D10_SHADER_RESOURCE_VIEW_DESC *desc)
586 FIXME("iface %p, desc %p stub!\n", iface, desc);
589 static const struct ID3D10ShaderResourceViewVtbl d3d10_shader_resource_view_vtbl =
591 /* IUnknown methods */
592 d3d10_shader_resource_view_QueryInterface,
593 d3d10_shader_resource_view_AddRef,
594 d3d10_shader_resource_view_Release,
595 /* ID3D10DeviceChild methods */
596 d3d10_shader_resource_view_GetDevice,
597 d3d10_shader_resource_view_GetPrivateData,
598 d3d10_shader_resource_view_SetPrivateData,
599 d3d10_shader_resource_view_SetPrivateDataInterface,
600 /* ID3D10View methods */
601 d3d10_shader_resource_view_GetResource,
602 /* ID3D10ShaderResourceView methods */
603 d3d10_shader_resource_view_GetDesc,
606 HRESULT d3d10_shader_resource_view_init(struct d3d10_shader_resource_view *view)
608 view->ID3D10ShaderResourceView_iface.lpVtbl = &d3d10_shader_resource_view_vtbl;
609 view->refcount = 1;
611 return S_OK;