urlmon: Fix return value from QueryService.
[wine.git] / dlls / d3d10core / view.c
blob72b7f4e1c3052e14faccfdd70c695f0e34267be8
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 IWineD3DResource *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 (IWineD3DResource *)((struct d3d10_buffer *)resource)->wined3d_buffer;
39 case D3D10_RESOURCE_DIMENSION_TEXTURE2D:
40 return (IWineD3DResource *)((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 /* IUnknown methods */
169 static HRESULT STDMETHODCALLTYPE d3d10_depthstencil_view_QueryInterface(ID3D10DepthStencilView *iface,
170 REFIID riid, void **object)
172 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
174 if (IsEqualGUID(riid, &IID_ID3D10DepthStencilView)
175 || IsEqualGUID(riid, &IID_ID3D10View)
176 || IsEqualGUID(riid, &IID_ID3D10DeviceChild)
177 || IsEqualGUID(riid, &IID_IUnknown))
179 IUnknown_AddRef(iface);
180 *object = iface;
181 return S_OK;
184 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
186 *object = NULL;
187 return E_NOINTERFACE;
190 static ULONG STDMETHODCALLTYPE d3d10_depthstencil_view_AddRef(ID3D10DepthStencilView *iface)
192 struct d3d10_depthstencil_view *This = (struct d3d10_depthstencil_view *)iface;
193 ULONG refcount = InterlockedIncrement(&This->refcount);
195 TRACE("%p increasing refcount to %u.\n", This, refcount);
197 return refcount;
200 static ULONG STDMETHODCALLTYPE d3d10_depthstencil_view_Release(ID3D10DepthStencilView *iface)
202 struct d3d10_depthstencil_view *This = (struct d3d10_depthstencil_view *)iface;
203 ULONG refcount = InterlockedDecrement(&This->refcount);
205 TRACE("%p decreasing refcount to %u.\n", This, refcount);
207 if (!refcount)
209 HeapFree(GetProcessHeap(), 0, This);
212 return refcount;
215 /* ID3D10DeviceChild methods */
217 static void STDMETHODCALLTYPE d3d10_depthstencil_view_GetDevice(ID3D10DepthStencilView *iface, ID3D10Device **device)
219 FIXME("iface %p, device %p stub!\n", iface, device);
222 static HRESULT STDMETHODCALLTYPE d3d10_depthstencil_view_GetPrivateData(ID3D10DepthStencilView *iface,
223 REFGUID guid, UINT *data_size, void *data)
225 FIXME("iface %p, guid %s, data_size %p, data %p stub!\n",
226 iface, debugstr_guid(guid), data_size, data);
228 return E_NOTIMPL;
231 static HRESULT STDMETHODCALLTYPE d3d10_depthstencil_view_SetPrivateData(ID3D10DepthStencilView *iface,
232 REFGUID guid, UINT data_size, const void *data)
234 FIXME("iface %p, guid %s, data_size %u, data %p stub!\n",
235 iface, debugstr_guid(guid), data_size, data);
237 return E_NOTIMPL;
240 static HRESULT STDMETHODCALLTYPE d3d10_depthstencil_view_SetPrivateDataInterface(ID3D10DepthStencilView *iface,
241 REFGUID guid, const IUnknown *data)
243 FIXME("iface %p, guid %s, data %p stub!\n", iface, debugstr_guid(guid), data);
245 return E_NOTIMPL;
248 /* ID3D10View methods */
250 static void STDMETHODCALLTYPE d3d10_depthstencil_view_GetResource(ID3D10DepthStencilView *iface,
251 ID3D10Resource **resource)
253 FIXME("iface %p, resource %p stub!\n", iface, resource);
256 /* ID3D10DepthStencilView methods */
258 static void STDMETHODCALLTYPE d3d10_depthstencil_view_GetDesc(ID3D10DepthStencilView *iface,
259 D3D10_DEPTH_STENCIL_VIEW_DESC *desc)
261 FIXME("iface %p, desc %p stub!\n", iface, desc);
264 static const struct ID3D10DepthStencilViewVtbl d3d10_depthstencil_view_vtbl =
266 /* IUnknown methods */
267 d3d10_depthstencil_view_QueryInterface,
268 d3d10_depthstencil_view_AddRef,
269 d3d10_depthstencil_view_Release,
270 /* ID3D10DeviceChild methods */
271 d3d10_depthstencil_view_GetDevice,
272 d3d10_depthstencil_view_GetPrivateData,
273 d3d10_depthstencil_view_SetPrivateData,
274 d3d10_depthstencil_view_SetPrivateDataInterface,
275 /* ID3D10View methods */
276 d3d10_depthstencil_view_GetResource,
277 /* ID3D10DepthStencilView methods */
278 d3d10_depthstencil_view_GetDesc,
281 HRESULT d3d10_depthstencil_view_init(struct d3d10_depthstencil_view *view)
283 view->vtbl = &d3d10_depthstencil_view_vtbl;
284 view->refcount = 1;
286 return S_OK;
289 /* IUnknown methods */
291 static HRESULT STDMETHODCALLTYPE d3d10_rendertarget_view_QueryInterface(ID3D10RenderTargetView *iface,
292 REFIID riid, void **object)
294 TRACE("iface %p, riid %s, object %p\n", iface, debugstr_guid(riid), object);
296 if (IsEqualGUID(riid, &IID_ID3D10RenderTargetView)
297 || IsEqualGUID(riid, &IID_ID3D10View)
298 || IsEqualGUID(riid, &IID_ID3D10DeviceChild)
299 || IsEqualGUID(riid, &IID_IUnknown))
301 IUnknown_AddRef(iface);
302 *object = iface;
303 return S_OK;
306 WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid));
308 *object = NULL;
309 return E_NOINTERFACE;
312 static ULONG STDMETHODCALLTYPE d3d10_rendertarget_view_AddRef(ID3D10RenderTargetView *iface)
314 struct d3d10_rendertarget_view *This = (struct d3d10_rendertarget_view *)iface;
315 ULONG refcount = InterlockedIncrement(&This->refcount);
317 TRACE("%p increasing refcount to %u\n", This, refcount);
319 return refcount;
322 static ULONG STDMETHODCALLTYPE d3d10_rendertarget_view_Release(ID3D10RenderTargetView *iface)
324 struct d3d10_rendertarget_view *This = (struct d3d10_rendertarget_view *)iface;
325 ULONG refcount = InterlockedDecrement(&This->refcount);
327 TRACE("%p decreasing refcount to %u\n", This, refcount);
329 if (!refcount)
331 IWineD3DRendertargetView_Release(This->wined3d_view);
332 HeapFree(GetProcessHeap(), 0, This);
335 return refcount;
338 /* ID3D10DeviceChild methods */
340 static void STDMETHODCALLTYPE d3d10_rendertarget_view_GetDevice(ID3D10RenderTargetView *iface, ID3D10Device **device)
342 FIXME("iface %p, device %p stub!\n", iface, device);
345 static HRESULT STDMETHODCALLTYPE d3d10_rendertarget_view_GetPrivateData(ID3D10RenderTargetView *iface,
346 REFGUID guid, UINT *data_size, void *data)
348 FIXME("iface %p, guid %s, data_size %p, data %p stub!\n",
349 iface, debugstr_guid(guid), data_size, data);
351 return E_NOTIMPL;
354 static HRESULT STDMETHODCALLTYPE d3d10_rendertarget_view_SetPrivateData(ID3D10RenderTargetView *iface,
355 REFGUID guid, UINT data_size, const void *data)
357 FIXME("iface %p, guid %s, data_size %u, data %p stub!\n",
358 iface, debugstr_guid(guid), data_size, data);
360 return E_NOTIMPL;
363 static HRESULT STDMETHODCALLTYPE d3d10_rendertarget_view_SetPrivateDataInterface(ID3D10RenderTargetView *iface,
364 REFGUID guid, const IUnknown *data)
366 FIXME("iface %p, guid %s, data %p stub!\n", iface, debugstr_guid(guid), data);
368 return E_NOTIMPL;
371 /* ID3D10View methods */
373 static void STDMETHODCALLTYPE d3d10_rendertarget_view_GetResource(ID3D10RenderTargetView *iface,
374 ID3D10Resource **resource)
376 struct d3d10_rendertarget_view *This = (struct d3d10_rendertarget_view *)iface;
377 IWineD3DResource *wined3d_resource;
378 IUnknown *parent;
379 HRESULT hr;
381 TRACE("iface %p, resource %p\n", iface, resource);
383 hr = IWineD3DRendertargetView_GetResource(This->wined3d_view, &wined3d_resource);
384 if (FAILED(hr))
386 ERR("Failed to get wined3d resource, hr %#x\n", hr);
387 *resource = NULL;
388 return;
391 parent = IWineD3DResource_GetParent(wined3d_resource);
392 hr = IUnknown_QueryInterface(parent, &IID_ID3D10Resource, (void **)&resource);
393 IWineD3DResource_Release(wined3d_resource);
394 if (FAILED(hr))
396 ERR("Resource parent isn't a d3d10 resource, hr %#x\n", hr);
397 *resource = NULL;
398 return;
402 /* ID3D10RenderTargetView methods */
404 static void STDMETHODCALLTYPE d3d10_rendertarget_view_GetDesc(ID3D10RenderTargetView *iface,
405 D3D10_RENDER_TARGET_VIEW_DESC *desc)
407 struct d3d10_rendertarget_view *This = (struct d3d10_rendertarget_view *)iface;
409 TRACE("iface %p, desc %p\n", iface, desc);
411 *desc = This->desc;
414 static const struct ID3D10RenderTargetViewVtbl d3d10_rendertarget_view_vtbl =
416 /* IUnknown methods */
417 d3d10_rendertarget_view_QueryInterface,
418 d3d10_rendertarget_view_AddRef,
419 d3d10_rendertarget_view_Release,
420 /* ID3D10DeviceChild methods */
421 d3d10_rendertarget_view_GetDevice,
422 d3d10_rendertarget_view_GetPrivateData,
423 d3d10_rendertarget_view_SetPrivateData,
424 d3d10_rendertarget_view_SetPrivateDataInterface,
425 /* ID3D10View methods */
426 d3d10_rendertarget_view_GetResource,
427 /* ID3D10RenderTargetView methods */
428 d3d10_rendertarget_view_GetDesc,
431 HRESULT d3d10_rendertarget_view_init(struct d3d10_rendertarget_view *view, struct d3d10_device *device,
432 ID3D10Resource *resource, const D3D10_RENDER_TARGET_VIEW_DESC *desc)
434 IWineD3DResource *wined3d_resource;
435 HRESULT hr;
437 view->vtbl = &d3d10_rendertarget_view_vtbl;
438 view->refcount = 1;
440 if (!desc)
442 HRESULT hr = set_rtdesc_from_resource(&view->desc, resource);
443 if (FAILED(hr)) return hr;
445 else
447 view->desc = *desc;
450 wined3d_resource = wined3d_resource_from_resource(resource);
451 if (!wined3d_resource)
453 ERR("Failed to get wined3d resource for d3d10 resource %p.\n", resource);
454 return E_FAIL;
457 hr = IWineD3DDevice_CreateRendertargetView(device->wined3d_device,
458 wined3d_resource, (IUnknown *)view, &view->wined3d_view);
459 if (FAILED(hr))
461 WARN("Failed to create a wined3d rendertarget view, hr %#x.\n", hr);
462 return hr;
465 return S_OK;
468 /* IUnknown methods */
470 static HRESULT STDMETHODCALLTYPE d3d10_shader_resource_view_QueryInterface(ID3D10ShaderResourceView *iface,
471 REFIID riid, void **object)
473 TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
475 if (IsEqualGUID(riid, &IID_ID3D10ShaderResourceView)
476 || IsEqualGUID(riid, &IID_ID3D10View)
477 || IsEqualGUID(riid, &IID_ID3D10DeviceChild)
478 || IsEqualGUID(riid, &IID_IUnknown))
480 IUnknown_AddRef(iface);
481 *object = iface;
482 return S_OK;
485 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
487 *object = NULL;
488 return E_NOINTERFACE;
491 static ULONG STDMETHODCALLTYPE d3d10_shader_resource_view_AddRef(ID3D10ShaderResourceView *iface)
493 struct d3d10_shader_resource_view *This = (struct d3d10_shader_resource_view *)iface;
494 ULONG refcount = InterlockedIncrement(&This->refcount);
496 TRACE("%p increasing refcount to %u.\n", This, refcount);
498 return refcount;
501 static ULONG STDMETHODCALLTYPE d3d10_shader_resource_view_Release(ID3D10ShaderResourceView *iface)
503 struct d3d10_shader_resource_view *This = (struct d3d10_shader_resource_view *)iface;
504 ULONG refcount = InterlockedDecrement(&This->refcount);
506 TRACE("%p decreasing refcount to %u.\n", This, refcount);
508 if (!refcount)
510 HeapFree(GetProcessHeap(), 0, This);
513 return refcount;
516 /* ID3D10DeviceChild methods */
518 static void STDMETHODCALLTYPE d3d10_shader_resource_view_GetDevice(ID3D10ShaderResourceView *iface,
519 ID3D10Device **device)
521 FIXME("iface %p, device %p stub!\n", iface, device);
524 static HRESULT STDMETHODCALLTYPE d3d10_shader_resource_view_GetPrivateData(ID3D10ShaderResourceView *iface,
525 REFGUID guid, UINT *data_size, void *data)
527 FIXME("iface %p, guid %s, data_size %p, data %p stub!\n",
528 iface, debugstr_guid(guid), data_size, data);
530 return E_NOTIMPL;
533 static HRESULT STDMETHODCALLTYPE d3d10_shader_resource_view_SetPrivateData(ID3D10ShaderResourceView *iface,
534 REFGUID guid, UINT data_size, const void *data)
536 FIXME("iface %p, guid %s, data_size %u, data %p stub!\n",
537 iface, debugstr_guid(guid), data_size, data);
539 return E_NOTIMPL;
542 static HRESULT STDMETHODCALLTYPE d3d10_shader_resource_view_SetPrivateDataInterface(ID3D10ShaderResourceView *iface,
543 REFGUID guid, const IUnknown *data)
545 FIXME("iface %p, guid %s, data %p stub!\n", iface, debugstr_guid(guid), data);
547 return E_NOTIMPL;
550 /* ID3D10View methods */
552 static void STDMETHODCALLTYPE d3d10_shader_resource_view_GetResource(ID3D10ShaderResourceView *iface,
553 ID3D10Resource **resource)
555 FIXME("iface %p, resource %p stub!\n", iface, resource);
558 /* ID3D10ShaderResourceView methods */
560 static void STDMETHODCALLTYPE d3d10_shader_resource_view_GetDesc(ID3D10ShaderResourceView *iface,
561 D3D10_SHADER_RESOURCE_VIEW_DESC *desc)
563 FIXME("iface %p, desc %p stub!\n", iface, desc);
566 static const struct ID3D10ShaderResourceViewVtbl d3d10_shader_resource_view_vtbl =
568 /* IUnknown methods */
569 d3d10_shader_resource_view_QueryInterface,
570 d3d10_shader_resource_view_AddRef,
571 d3d10_shader_resource_view_Release,
572 /* ID3D10DeviceChild methods */
573 d3d10_shader_resource_view_GetDevice,
574 d3d10_shader_resource_view_GetPrivateData,
575 d3d10_shader_resource_view_SetPrivateData,
576 d3d10_shader_resource_view_SetPrivateDataInterface,
577 /* ID3D10View methods */
578 d3d10_shader_resource_view_GetResource,
579 /* ID3D10ShaderResourceView methods */
580 d3d10_shader_resource_view_GetDesc,
583 HRESULT d3d10_shader_resource_view_init(struct d3d10_shader_resource_view *view)
585 view->vtbl = &d3d10_shader_resource_view_vtbl;
586 view->refcount = 1;
588 return S_OK;