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
21 #include "wine/port.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
);
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
);
44 FIXME("Unhandled resource dimension %#x.\n", dimension
);
49 static HRESULT
set_rtdesc_from_resource(D3D10_RENDER_TARGET_VIEW_DESC
*desc
, ID3D10Resource
*resource
)
51 D3D10_RESOURCE_DIMENSION dimension
;
54 ID3D10Resource_GetType(resource
, &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
);
66 ERR("Resource of type TEXTURE1D doesn't implement ID3D10Texture1D?\n");
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;
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;
90 case D3D10_RESOURCE_DIMENSION_TEXTURE2D
:
92 ID3D10Texture2D
*texture
;
93 D3D10_TEXTURE2D_DESC texture_desc
;
95 hr
= ID3D10Resource_QueryInterface(resource
, &IID_ID3D10Texture2D
, (void **)&texture
);
98 ERR("Resource of type TEXTURE2D doesn't implement ID3D10Texture2D?\n");
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;
115 desc
->ViewDimension
= D3D10_RTV_DIMENSION_TEXTURE2DMS
;
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;
129 desc
->ViewDimension
= D3D10_RTV_DIMENSION_TEXTURE2DMSARRAY
;
130 desc
->u
.Texture2DMSArray
.FirstArraySlice
= 0;
131 desc
->u
.Texture2DMSArray
.ArraySize
= 1;
138 case D3D10_RESOURCE_DIMENSION_TEXTURE3D
:
140 ID3D10Texture3D
*texture
;
141 D3D10_TEXTURE3D_DESC texture_desc
;
143 hr
= ID3D10Resource_QueryInterface(resource
, &IID_ID3D10Texture3D
, (void **)&texture
);
146 ERR("Resource of type TEXTURE3D doesn't implement ID3D10Texture3D?\n");
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;
163 FIXME("Unhandled resource dimension %#x.\n", dimension
);
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
);
190 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
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
);
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
);
215 HeapFree(GetProcessHeap(), 0, This
);
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
);
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
);
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
);
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
;
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
);
317 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid
));
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
);
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
);
342 wined3d_rendertarget_view_decref(This
->wined3d_view
);
343 HeapFree(GetProcessHeap(), 0, This
);
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
);
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
);
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
);
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
;
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");
402 parent
= wined3d_resource_get_parent(wined3d_resource
);
403 hr
= IUnknown_QueryInterface(parent
, &IID_ID3D10Resource
, (void **)&resource
);
406 ERR("Resource parent isn't a d3d10 resource, hr %#x\n", hr
);
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
);
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
;
447 view
->ID3D10RenderTargetView_iface
.lpVtbl
= &d3d10_rendertarget_view_vtbl
;
452 HRESULT hr
= set_rtdesc_from_resource(&view
->desc
, resource
);
453 if (FAILED(hr
)) return hr
;
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
);
467 hr
= wined3d_rendertarget_view_create(wined3d_resource
, view
, &view
->wined3d_view
);
470 WARN("Failed to create a wined3d rendertarget view, hr %#x.\n", hr
);
477 struct d3d10_rendertarget_view
*unsafe_impl_from_ID3D10RenderTargetView(ID3D10RenderTargetView
*iface
)
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
);
508 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid
));
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
);
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
);
533 HeapFree(GetProcessHeap(), 0, This
);
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
);
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
);
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
);
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
;