usp10: Correct matra type for Oriya 0x0B57.
[wine/multimedia.git] / dlls / d3d10core / view.c
blobfb289a649a48942cc875c711f4358a9ed69ab1fe
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 struct wined3d_resource *wined3d_resource_from_resource(ID3D10Resource *resource)
30 D3D10_RESOURCE_DIMENSION dimension;
32 ID3D10Resource_GetType(resource, &dimension);
34 switch(dimension)
36 case D3D10_RESOURCE_DIMENSION_BUFFER:
37 return wined3d_buffer_get_resource(((struct d3d10_buffer *)resource)->wined3d_buffer);
39 case D3D10_RESOURCE_DIMENSION_TEXTURE2D:
40 return wined3d_surface_get_resource(((struct d3d10_texture2d *)resource)->wined3d_surface);
42 default:
43 FIXME("Unhandled resource dimension %#x.\n", dimension);
44 return NULL;
48 static HRESULT set_rtdesc_from_resource(D3D10_RENDER_TARGET_VIEW_DESC *desc, ID3D10Resource *resource)
50 D3D10_RESOURCE_DIMENSION dimension;
51 HRESULT hr;
53 ID3D10Resource_GetType(resource, &dimension);
55 switch(dimension)
57 case D3D10_RESOURCE_DIMENSION_TEXTURE1D:
59 ID3D10Texture1D *texture;
60 D3D10_TEXTURE1D_DESC texture_desc;
62 hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D10Texture1D, (void **)&texture);
63 if (FAILED(hr))
65 ERR("Resource of type TEXTURE1D doesn't implement ID3D10Texture1D?\n");
66 return E_INVALIDARG;
69 ID3D10Texture1D_GetDesc(texture, &texture_desc);
70 ID3D10Texture1D_Release(texture);
72 desc->Format = texture_desc.Format;
73 if (texture_desc.ArraySize == 1)
75 desc->ViewDimension = D3D10_RTV_DIMENSION_TEXTURE1D;
76 desc->u.Texture1D.MipSlice = 0;
78 else
80 desc->ViewDimension = D3D10_RTV_DIMENSION_TEXTURE1DARRAY;
81 desc->u.Texture1DArray.MipSlice = 0;
82 desc->u.Texture1DArray.FirstArraySlice = 0;
83 desc->u.Texture1DArray.ArraySize = 1;
86 return S_OK;
89 case D3D10_RESOURCE_DIMENSION_TEXTURE2D:
91 ID3D10Texture2D *texture;
92 D3D10_TEXTURE2D_DESC texture_desc;
94 hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D10Texture2D, (void **)&texture);
95 if (FAILED(hr))
97 ERR("Resource of type TEXTURE2D doesn't implement ID3D10Texture2D?\n");
98 return E_INVALIDARG;
101 ID3D10Texture2D_GetDesc(texture, &texture_desc);
102 ID3D10Texture2D_Release(texture);
104 desc->Format = texture_desc.Format;
105 if (texture_desc.ArraySize == 1)
107 if (texture_desc.SampleDesc.Count == 1)
109 desc->ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2D;
110 desc->u.Texture2D.MipSlice = 0;
112 else
114 desc->ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2DMS;
117 else
119 if (texture_desc.SampleDesc.Count == 1)
121 desc->ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2DARRAY;
122 desc->u.Texture2DArray.MipSlice = 0;
123 desc->u.Texture2DArray.FirstArraySlice = 0;
124 desc->u.Texture2DArray.ArraySize = 1;
126 else
128 desc->ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2DMSARRAY;
129 desc->u.Texture2DMSArray.FirstArraySlice = 0;
130 desc->u.Texture2DMSArray.ArraySize = 1;
134 return S_OK;
137 case D3D10_RESOURCE_DIMENSION_TEXTURE3D:
139 ID3D10Texture3D *texture;
140 D3D10_TEXTURE3D_DESC texture_desc;
142 hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D10Texture3D, (void **)&texture);
143 if (FAILED(hr))
145 ERR("Resource of type TEXTURE3D doesn't implement ID3D10Texture3D?\n");
146 return E_INVALIDARG;
149 ID3D10Texture3D_GetDesc(texture, &texture_desc);
150 ID3D10Texture3D_Release(texture);
152 desc->Format = texture_desc.Format;
153 desc->ViewDimension = D3D10_RTV_DIMENSION_TEXTURE3D;
154 desc->u.Texture3D.MipSlice = 0;
155 desc->u.Texture3D.FirstWSlice = 0;
156 desc->u.Texture3D.WSize = 1;
158 return S_OK;
161 default:
162 FIXME("Unhandled resource dimension %#x.\n", dimension);
163 return E_INVALIDARG;
167 static inline struct d3d10_depthstencil_view *impl_from_ID3D10DepthStencilView(ID3D10DepthStencilView *iface)
169 return CONTAINING_RECORD(iface, struct d3d10_depthstencil_view, ID3D10DepthStencilView_iface);
172 /* IUnknown methods */
174 static HRESULT STDMETHODCALLTYPE d3d10_depthstencil_view_QueryInterface(ID3D10DepthStencilView *iface,
175 REFIID riid, void **object)
177 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
179 if (IsEqualGUID(riid, &IID_ID3D10DepthStencilView)
180 || IsEqualGUID(riid, &IID_ID3D10View)
181 || IsEqualGUID(riid, &IID_ID3D10DeviceChild)
182 || IsEqualGUID(riid, &IID_IUnknown))
184 IUnknown_AddRef(iface);
185 *object = iface;
186 return S_OK;
189 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
191 *object = NULL;
192 return E_NOINTERFACE;
195 static ULONG STDMETHODCALLTYPE d3d10_depthstencil_view_AddRef(ID3D10DepthStencilView *iface)
197 struct d3d10_depthstencil_view *This = impl_from_ID3D10DepthStencilView(iface);
198 ULONG refcount = InterlockedIncrement(&This->refcount);
200 TRACE("%p increasing refcount to %u.\n", This, refcount);
202 return refcount;
205 static ULONG STDMETHODCALLTYPE d3d10_depthstencil_view_Release(ID3D10DepthStencilView *iface)
207 struct d3d10_depthstencil_view *This = impl_from_ID3D10DepthStencilView(iface);
208 ULONG refcount = InterlockedDecrement(&This->refcount);
210 TRACE("%p decreasing refcount to %u.\n", This, refcount);
212 if (!refcount)
214 HeapFree(GetProcessHeap(), 0, This);
217 return refcount;
220 /* ID3D10DeviceChild methods */
222 static void STDMETHODCALLTYPE d3d10_depthstencil_view_GetDevice(ID3D10DepthStencilView *iface, ID3D10Device **device)
224 FIXME("iface %p, device %p stub!\n", iface, device);
227 static HRESULT STDMETHODCALLTYPE d3d10_depthstencil_view_GetPrivateData(ID3D10DepthStencilView *iface,
228 REFGUID guid, UINT *data_size, void *data)
230 FIXME("iface %p, guid %s, data_size %p, data %p stub!\n",
231 iface, debugstr_guid(guid), data_size, data);
233 return E_NOTIMPL;
236 static HRESULT STDMETHODCALLTYPE d3d10_depthstencil_view_SetPrivateData(ID3D10DepthStencilView *iface,
237 REFGUID guid, UINT data_size, const void *data)
239 FIXME("iface %p, guid %s, data_size %u, data %p stub!\n",
240 iface, debugstr_guid(guid), data_size, data);
242 return E_NOTIMPL;
245 static HRESULT STDMETHODCALLTYPE d3d10_depthstencil_view_SetPrivateDataInterface(ID3D10DepthStencilView *iface,
246 REFGUID guid, const IUnknown *data)
248 FIXME("iface %p, guid %s, data %p stub!\n", iface, debugstr_guid(guid), data);
250 return E_NOTIMPL;
253 /* ID3D10View methods */
255 static void STDMETHODCALLTYPE d3d10_depthstencil_view_GetResource(ID3D10DepthStencilView *iface,
256 ID3D10Resource **resource)
258 FIXME("iface %p, resource %p stub!\n", iface, resource);
261 /* ID3D10DepthStencilView methods */
263 static void STDMETHODCALLTYPE d3d10_depthstencil_view_GetDesc(ID3D10DepthStencilView *iface,
264 D3D10_DEPTH_STENCIL_VIEW_DESC *desc)
266 FIXME("iface %p, desc %p stub!\n", iface, desc);
269 static const struct ID3D10DepthStencilViewVtbl d3d10_depthstencil_view_vtbl =
271 /* IUnknown methods */
272 d3d10_depthstencil_view_QueryInterface,
273 d3d10_depthstencil_view_AddRef,
274 d3d10_depthstencil_view_Release,
275 /* ID3D10DeviceChild methods */
276 d3d10_depthstencil_view_GetDevice,
277 d3d10_depthstencil_view_GetPrivateData,
278 d3d10_depthstencil_view_SetPrivateData,
279 d3d10_depthstencil_view_SetPrivateDataInterface,
280 /* ID3D10View methods */
281 d3d10_depthstencil_view_GetResource,
282 /* ID3D10DepthStencilView methods */
283 d3d10_depthstencil_view_GetDesc,
286 HRESULT d3d10_depthstencil_view_init(struct d3d10_depthstencil_view *view)
288 view->ID3D10DepthStencilView_iface.lpVtbl = &d3d10_depthstencil_view_vtbl;
289 view->refcount = 1;
291 return S_OK;
294 /* IUnknown methods */
296 static HRESULT STDMETHODCALLTYPE d3d10_rendertarget_view_QueryInterface(ID3D10RenderTargetView *iface,
297 REFIID riid, void **object)
299 TRACE("iface %p, riid %s, object %p\n", iface, debugstr_guid(riid), object);
301 if (IsEqualGUID(riid, &IID_ID3D10RenderTargetView)
302 || IsEqualGUID(riid, &IID_ID3D10View)
303 || IsEqualGUID(riid, &IID_ID3D10DeviceChild)
304 || IsEqualGUID(riid, &IID_IUnknown))
306 IUnknown_AddRef(iface);
307 *object = iface;
308 return S_OK;
311 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid));
313 *object = NULL;
314 return E_NOINTERFACE;
317 static ULONG STDMETHODCALLTYPE d3d10_rendertarget_view_AddRef(ID3D10RenderTargetView *iface)
319 struct d3d10_rendertarget_view *This = (struct d3d10_rendertarget_view *)iface;
320 ULONG refcount = InterlockedIncrement(&This->refcount);
322 TRACE("%p increasing refcount to %u\n", This, refcount);
324 return refcount;
327 static ULONG STDMETHODCALLTYPE d3d10_rendertarget_view_Release(ID3D10RenderTargetView *iface)
329 struct d3d10_rendertarget_view *This = (struct d3d10_rendertarget_view *)iface;
330 ULONG refcount = InterlockedDecrement(&This->refcount);
332 TRACE("%p decreasing refcount to %u\n", This, refcount);
334 if (!refcount)
336 wined3d_rendertarget_view_decref(This->wined3d_view);
337 HeapFree(GetProcessHeap(), 0, This);
340 return refcount;
343 /* ID3D10DeviceChild methods */
345 static void STDMETHODCALLTYPE d3d10_rendertarget_view_GetDevice(ID3D10RenderTargetView *iface, ID3D10Device **device)
347 FIXME("iface %p, device %p stub!\n", iface, device);
350 static HRESULT STDMETHODCALLTYPE d3d10_rendertarget_view_GetPrivateData(ID3D10RenderTargetView *iface,
351 REFGUID guid, UINT *data_size, void *data)
353 FIXME("iface %p, guid %s, data_size %p, data %p stub!\n",
354 iface, debugstr_guid(guid), data_size, data);
356 return E_NOTIMPL;
359 static HRESULT STDMETHODCALLTYPE d3d10_rendertarget_view_SetPrivateData(ID3D10RenderTargetView *iface,
360 REFGUID guid, UINT data_size, const void *data)
362 FIXME("iface %p, guid %s, data_size %u, data %p stub!\n",
363 iface, debugstr_guid(guid), data_size, data);
365 return E_NOTIMPL;
368 static HRESULT STDMETHODCALLTYPE d3d10_rendertarget_view_SetPrivateDataInterface(ID3D10RenderTargetView *iface,
369 REFGUID guid, const IUnknown *data)
371 FIXME("iface %p, guid %s, data %p stub!\n", iface, debugstr_guid(guid), data);
373 return E_NOTIMPL;
376 /* ID3D10View methods */
378 static void STDMETHODCALLTYPE d3d10_rendertarget_view_GetResource(ID3D10RenderTargetView *iface,
379 ID3D10Resource **resource)
381 struct d3d10_rendertarget_view *This = (struct d3d10_rendertarget_view *)iface;
382 struct wined3d_resource *wined3d_resource;
383 IUnknown *parent;
384 HRESULT hr;
386 TRACE("iface %p, resource %p\n", iface, resource);
388 wined3d_resource = wined3d_rendertarget_view_get_resource(This->wined3d_view);
389 if (!wined3d_resource)
391 ERR("Failed to get wined3d resource.\n");
392 *resource = NULL;
393 return;
396 parent = wined3d_resource_get_parent(wined3d_resource);
397 hr = IUnknown_QueryInterface(parent, &IID_ID3D10Resource, (void **)&resource);
398 if (FAILED(hr))
400 ERR("Resource parent isn't a d3d10 resource, hr %#x\n", hr);
401 *resource = NULL;
402 return;
406 /* ID3D10RenderTargetView methods */
408 static void STDMETHODCALLTYPE d3d10_rendertarget_view_GetDesc(ID3D10RenderTargetView *iface,
409 D3D10_RENDER_TARGET_VIEW_DESC *desc)
411 struct d3d10_rendertarget_view *This = (struct d3d10_rendertarget_view *)iface;
413 TRACE("iface %p, desc %p\n", iface, desc);
415 *desc = This->desc;
418 static const struct ID3D10RenderTargetViewVtbl d3d10_rendertarget_view_vtbl =
420 /* IUnknown methods */
421 d3d10_rendertarget_view_QueryInterface,
422 d3d10_rendertarget_view_AddRef,
423 d3d10_rendertarget_view_Release,
424 /* ID3D10DeviceChild methods */
425 d3d10_rendertarget_view_GetDevice,
426 d3d10_rendertarget_view_GetPrivateData,
427 d3d10_rendertarget_view_SetPrivateData,
428 d3d10_rendertarget_view_SetPrivateDataInterface,
429 /* ID3D10View methods */
430 d3d10_rendertarget_view_GetResource,
431 /* ID3D10RenderTargetView methods */
432 d3d10_rendertarget_view_GetDesc,
435 HRESULT d3d10_rendertarget_view_init(struct d3d10_rendertarget_view *view,
436 ID3D10Resource *resource, const D3D10_RENDER_TARGET_VIEW_DESC *desc)
438 struct wined3d_resource *wined3d_resource;
439 HRESULT hr;
441 view->vtbl = &d3d10_rendertarget_view_vtbl;
442 view->refcount = 1;
444 if (!desc)
446 HRESULT hr = set_rtdesc_from_resource(&view->desc, resource);
447 if (FAILED(hr)) return hr;
449 else
451 view->desc = *desc;
454 wined3d_resource = wined3d_resource_from_resource(resource);
455 if (!wined3d_resource)
457 ERR("Failed to get wined3d resource for d3d10 resource %p.\n", resource);
458 return E_FAIL;
461 hr = wined3d_rendertarget_view_create(wined3d_resource, view, &view->wined3d_view);
462 if (FAILED(hr))
464 WARN("Failed to create a wined3d rendertarget view, hr %#x.\n", hr);
465 return hr;
468 return S_OK;
471 static inline struct d3d10_shader_resource_view *impl_from_ID3D10ShaderResourceView(ID3D10ShaderResourceView *iface)
473 return CONTAINING_RECORD(iface, struct d3d10_shader_resource_view, ID3D10ShaderResourceView_iface);
476 /* IUnknown methods */
478 static HRESULT STDMETHODCALLTYPE d3d10_shader_resource_view_QueryInterface(ID3D10ShaderResourceView *iface,
479 REFIID riid, void **object)
481 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
483 if (IsEqualGUID(riid, &IID_ID3D10ShaderResourceView)
484 || IsEqualGUID(riid, &IID_ID3D10View)
485 || IsEqualGUID(riid, &IID_ID3D10DeviceChild)
486 || IsEqualGUID(riid, &IID_IUnknown))
488 IUnknown_AddRef(iface);
489 *object = iface;
490 return S_OK;
493 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
495 *object = NULL;
496 return E_NOINTERFACE;
499 static ULONG STDMETHODCALLTYPE d3d10_shader_resource_view_AddRef(ID3D10ShaderResourceView *iface)
501 struct d3d10_shader_resource_view *This = impl_from_ID3D10ShaderResourceView(iface);
502 ULONG refcount = InterlockedIncrement(&This->refcount);
504 TRACE("%p increasing refcount to %u.\n", This, refcount);
506 return refcount;
509 static ULONG STDMETHODCALLTYPE d3d10_shader_resource_view_Release(ID3D10ShaderResourceView *iface)
511 struct d3d10_shader_resource_view *This = impl_from_ID3D10ShaderResourceView(iface);
512 ULONG refcount = InterlockedDecrement(&This->refcount);
514 TRACE("%p decreasing refcount to %u.\n", This, refcount);
516 if (!refcount)
518 HeapFree(GetProcessHeap(), 0, This);
521 return refcount;
524 /* ID3D10DeviceChild methods */
526 static void STDMETHODCALLTYPE d3d10_shader_resource_view_GetDevice(ID3D10ShaderResourceView *iface,
527 ID3D10Device **device)
529 FIXME("iface %p, device %p stub!\n", iface, device);
532 static HRESULT STDMETHODCALLTYPE d3d10_shader_resource_view_GetPrivateData(ID3D10ShaderResourceView *iface,
533 REFGUID guid, UINT *data_size, void *data)
535 FIXME("iface %p, guid %s, data_size %p, data %p stub!\n",
536 iface, debugstr_guid(guid), data_size, data);
538 return E_NOTIMPL;
541 static HRESULT STDMETHODCALLTYPE d3d10_shader_resource_view_SetPrivateData(ID3D10ShaderResourceView *iface,
542 REFGUID guid, UINT data_size, const void *data)
544 FIXME("iface %p, guid %s, data_size %u, data %p stub!\n",
545 iface, debugstr_guid(guid), data_size, data);
547 return E_NOTIMPL;
550 static HRESULT STDMETHODCALLTYPE d3d10_shader_resource_view_SetPrivateDataInterface(ID3D10ShaderResourceView *iface,
551 REFGUID guid, const IUnknown *data)
553 FIXME("iface %p, guid %s, data %p stub!\n", iface, debugstr_guid(guid), data);
555 return E_NOTIMPL;
558 /* ID3D10View methods */
560 static void STDMETHODCALLTYPE d3d10_shader_resource_view_GetResource(ID3D10ShaderResourceView *iface,
561 ID3D10Resource **resource)
563 FIXME("iface %p, resource %p stub!\n", iface, resource);
566 /* ID3D10ShaderResourceView methods */
568 static void STDMETHODCALLTYPE d3d10_shader_resource_view_GetDesc(ID3D10ShaderResourceView *iface,
569 D3D10_SHADER_RESOURCE_VIEW_DESC *desc)
571 FIXME("iface %p, desc %p stub!\n", iface, desc);
574 static const struct ID3D10ShaderResourceViewVtbl d3d10_shader_resource_view_vtbl =
576 /* IUnknown methods */
577 d3d10_shader_resource_view_QueryInterface,
578 d3d10_shader_resource_view_AddRef,
579 d3d10_shader_resource_view_Release,
580 /* ID3D10DeviceChild methods */
581 d3d10_shader_resource_view_GetDevice,
582 d3d10_shader_resource_view_GetPrivateData,
583 d3d10_shader_resource_view_SetPrivateData,
584 d3d10_shader_resource_view_SetPrivateDataInterface,
585 /* ID3D10View methods */
586 d3d10_shader_resource_view_GetResource,
587 /* ID3D10ShaderResourceView methods */
588 d3d10_shader_resource_view_GetDesc,
591 HRESULT d3d10_shader_resource_view_init(struct d3d10_shader_resource_view *view)
593 view->ID3D10ShaderResourceView_iface.lpVtbl = &d3d10_shader_resource_view_vtbl;
594 view->refcount = 1;
596 return S_OK;