atl80: Added AtlComModuleRegisterServer implementation (based on AtlModuleRegisterSer...
[wine] / dlls / d3d10core / view.c
1 /*
2  * Copyright 2009 Henri Verbeet for CodeWeavers
3  *
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.
8  *
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.
13  *
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
17  *
18  */
19
20 #include "config.h"
21 #include "wine/port.h"
22
23 #define NONAMELESSUNION
24 #include "d3d10core_private.h"
25
26 WINE_DEFAULT_DEBUG_CHANNEL(d3d10core);
27
28 static struct wined3d_resource *wined3d_resource_from_resource(ID3D10Resource *resource)
29 {
30     D3D10_RESOURCE_DIMENSION dimension;
31
32     ID3D10Resource_GetType(resource, &dimension);
33
34     switch(dimension)
35     {
36         case D3D10_RESOURCE_DIMENSION_BUFFER:
37             return wined3d_buffer_get_resource(((struct d3d10_buffer *)resource)->wined3d_buffer);
38
39         case D3D10_RESOURCE_DIMENSION_TEXTURE2D:
40             return wined3d_texture_get_resource(((struct d3d10_texture2d *)resource)->wined3d_texture);
41
42         default:
43             FIXME("Unhandled resource dimension %#x.\n", dimension);
44             return NULL;
45     }
46 }
47
48 static HRESULT set_dsdesc_from_resource(D3D10_DEPTH_STENCIL_VIEW_DESC *desc, ID3D10Resource *resource)
49 {
50     D3D10_RESOURCE_DIMENSION dimension;
51
52     ID3D10Resource_GetType(resource, &dimension);
53
54     switch (dimension)
55     {
56         case D3D10_RESOURCE_DIMENSION_TEXTURE1D:
57         {
58             D3D10_TEXTURE1D_DESC texture_desc;
59             ID3D10Texture1D *texture;
60
61             if (FAILED(ID3D10Resource_QueryInterface(resource, &IID_ID3D10Texture1D, (void **)&texture)))
62             {
63                 ERR("Resource of type TEXTURE1D doesn't implement ID3D10Texture1D.\n");
64                 return E_INVALIDARG;
65             }
66
67             ID3D10Texture1D_GetDesc(texture, &texture_desc);
68             ID3D10Texture1D_Release(texture);
69
70             desc->Format = texture_desc.Format;
71             if (texture_desc.ArraySize == 1)
72             {
73                 desc->ViewDimension = D3D10_DSV_DIMENSION_TEXTURE1D;
74                 desc->u.Texture1D.MipSlice = 0;
75             }
76             else
77             {
78                 desc->ViewDimension = D3D10_DSV_DIMENSION_TEXTURE1DARRAY;
79                 desc->u.Texture1DArray.MipSlice = 0;
80                 desc->u.Texture1DArray.FirstArraySlice = 0;
81                 desc->u.Texture1DArray.ArraySize = 1;
82             }
83
84             return S_OK;
85         }
86
87         case D3D10_RESOURCE_DIMENSION_TEXTURE2D:
88         {
89             D3D10_TEXTURE2D_DESC texture_desc;
90             ID3D10Texture2D *texture;
91
92             if (FAILED(ID3D10Resource_QueryInterface(resource, &IID_ID3D10Texture2D, (void **)&texture)))
93             {
94                 ERR("Resource of type TEXTURE2D doesn't implement ID3D10Texture2D.\n");
95                 return E_INVALIDARG;
96             }
97
98             ID3D10Texture2D_GetDesc(texture, &texture_desc);
99             ID3D10Texture2D_Release(texture);
100
101             desc->Format = texture_desc.Format;
102             if (texture_desc.ArraySize == 1)
103             {
104                 if (texture_desc.SampleDesc.Count == 1)
105                 {
106                     desc->ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2D;
107                     desc->u.Texture2D.MipSlice = 0;
108                 }
109                 else
110                 {
111                     desc->ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2DMS;
112                 }
113             }
114             else
115             {
116                 if (texture_desc.SampleDesc.Count == 1)
117                 {
118                     desc->ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2DARRAY;
119                     desc->u.Texture2DArray.MipSlice = 0;
120                     desc->u.Texture2DArray.FirstArraySlice = 0;
121                     desc->u.Texture2DArray.ArraySize = 1;
122                 }
123                 else
124                 {
125                     desc->ViewDimension = D3D10_DSV_DIMENSION_TEXTURE2DMSARRAY;
126                     desc->u.Texture2DMSArray.FirstArraySlice = 0;
127                     desc->u.Texture2DMSArray.ArraySize = 1;
128                 }
129             }
130
131             return S_OK;
132         }
133
134         default:
135             FIXME("Unhandled resource dimension %#x.\n", dimension);
136         case D3D10_RESOURCE_DIMENSION_BUFFER:
137         case D3D10_RESOURCE_DIMENSION_TEXTURE3D:
138             return E_INVALIDARG;
139     }
140 }
141
142 static HRESULT set_rtdesc_from_resource(D3D10_RENDER_TARGET_VIEW_DESC *desc, ID3D10Resource *resource)
143 {
144     D3D10_RESOURCE_DIMENSION dimension;
145     HRESULT hr;
146
147     ID3D10Resource_GetType(resource, &dimension);
148
149     switch(dimension)
150     {
151         case D3D10_RESOURCE_DIMENSION_TEXTURE1D:
152         {
153             ID3D10Texture1D *texture;
154             D3D10_TEXTURE1D_DESC texture_desc;
155
156             hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D10Texture1D, (void **)&texture);
157             if (FAILED(hr))
158             {
159                 ERR("Resource of type TEXTURE1D doesn't implement ID3D10Texture1D?\n");
160                 return E_INVALIDARG;
161             }
162
163             ID3D10Texture1D_GetDesc(texture, &texture_desc);
164             ID3D10Texture1D_Release(texture);
165
166             desc->Format = texture_desc.Format;
167             if (texture_desc.ArraySize == 1)
168             {
169                 desc->ViewDimension = D3D10_RTV_DIMENSION_TEXTURE1D;
170                 desc->u.Texture1D.MipSlice = 0;
171             }
172             else
173             {
174                 desc->ViewDimension = D3D10_RTV_DIMENSION_TEXTURE1DARRAY;
175                 desc->u.Texture1DArray.MipSlice = 0;
176                 desc->u.Texture1DArray.FirstArraySlice = 0;
177                 desc->u.Texture1DArray.ArraySize = 1;
178             }
179
180             return S_OK;
181         }
182
183         case D3D10_RESOURCE_DIMENSION_TEXTURE2D:
184         {
185             ID3D10Texture2D *texture;
186             D3D10_TEXTURE2D_DESC texture_desc;
187
188             hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D10Texture2D, (void **)&texture);
189             if (FAILED(hr))
190             {
191                 ERR("Resource of type TEXTURE2D doesn't implement ID3D10Texture2D?\n");
192                 return E_INVALIDARG;
193             }
194
195             ID3D10Texture2D_GetDesc(texture, &texture_desc);
196             ID3D10Texture2D_Release(texture);
197
198             desc->Format = texture_desc.Format;
199             if (texture_desc.ArraySize == 1)
200             {
201                 if (texture_desc.SampleDesc.Count == 1)
202                 {
203                     desc->ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2D;
204                     desc->u.Texture2D.MipSlice = 0;
205                 }
206                 else
207                 {
208                     desc->ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2DMS;
209                 }
210             }
211             else
212             {
213                 if (texture_desc.SampleDesc.Count == 1)
214                 {
215                     desc->ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2DARRAY;
216                     desc->u.Texture2DArray.MipSlice = 0;
217                     desc->u.Texture2DArray.FirstArraySlice = 0;
218                     desc->u.Texture2DArray.ArraySize = 1;
219                 }
220                 else
221                 {
222                     desc->ViewDimension = D3D10_RTV_DIMENSION_TEXTURE2DMSARRAY;
223                     desc->u.Texture2DMSArray.FirstArraySlice = 0;
224                     desc->u.Texture2DMSArray.ArraySize = 1;
225                 }
226             }
227
228             return S_OK;
229         }
230
231         case D3D10_RESOURCE_DIMENSION_TEXTURE3D:
232         {
233             ID3D10Texture3D *texture;
234             D3D10_TEXTURE3D_DESC texture_desc;
235
236             hr = ID3D10Resource_QueryInterface(resource, &IID_ID3D10Texture3D, (void **)&texture);
237             if (FAILED(hr))
238             {
239                 ERR("Resource of type TEXTURE3D doesn't implement ID3D10Texture3D?\n");
240                 return E_INVALIDARG;
241             }
242
243             ID3D10Texture3D_GetDesc(texture, &texture_desc);
244             ID3D10Texture3D_Release(texture);
245
246             desc->Format = texture_desc.Format;
247             desc->ViewDimension = D3D10_RTV_DIMENSION_TEXTURE3D;
248             desc->u.Texture3D.MipSlice = 0;
249             desc->u.Texture3D.FirstWSlice = 0;
250             desc->u.Texture3D.WSize = 1;
251
252             return S_OK;
253         }
254
255         default:
256             FIXME("Unhandled resource dimension %#x.\n", dimension);
257             return E_INVALIDARG;
258     }
259 }
260
261 static HRESULT set_srdesc_from_resource(D3D10_SHADER_RESOURCE_VIEW_DESC *desc, ID3D10Resource *resource)
262 {
263     D3D10_RESOURCE_DIMENSION dimension;
264
265     ID3D10Resource_GetType(resource, &dimension);
266
267     switch (dimension)
268     {
269         case D3D10_RESOURCE_DIMENSION_TEXTURE1D:
270         {
271             D3D10_TEXTURE1D_DESC texture_desc;
272             ID3D10Texture1D *texture;
273
274             if (FAILED(ID3D10Resource_QueryInterface(resource, &IID_ID3D10Texture1D, (void **)&texture)))
275             {
276                 ERR("Resource of type TEXTURE1D doesn't implement ID3D10Texture1D.\n");
277                 return E_INVALIDARG;
278             }
279
280             ID3D10Texture1D_GetDesc(texture, &texture_desc);
281             ID3D10Texture1D_Release(texture);
282
283             desc->Format = texture_desc.Format;
284             if (texture_desc.ArraySize == 1)
285             {
286                 desc->ViewDimension = D3D10_SRV_DIMENSION_TEXTURE1D;
287                 desc->u.Texture1D.MostDetailedMip = 0;
288                 desc->u.Texture1D.MipLevels = texture_desc.MipLevels;
289             }
290             else
291             {
292                 desc->ViewDimension = D3D10_SRV_DIMENSION_TEXTURE1DARRAY;
293                 desc->u.Texture1DArray.MostDetailedMip = 0;
294                 desc->u.Texture1DArray.MipLevels = texture_desc.MipLevels;
295                 desc->u.Texture1DArray.FirstArraySlice = 0;
296                 desc->u.Texture1DArray.ArraySize = texture_desc.ArraySize;
297             }
298
299             return S_OK;
300         }
301
302         case D3D10_RESOURCE_DIMENSION_TEXTURE2D:
303         {
304             D3D10_TEXTURE2D_DESC texture_desc;
305             ID3D10Texture2D *texture;
306
307             if (FAILED(ID3D10Resource_QueryInterface(resource, &IID_ID3D10Texture2D, (void **)&texture)))
308             {
309                 ERR("Resource of type TEXTURE2D doesn't implement ID3D10Texture2D.\n");
310                 return E_INVALIDARG;
311             }
312
313             ID3D10Texture2D_GetDesc(texture, &texture_desc);
314             ID3D10Texture2D_Release(texture);
315
316             desc->Format = texture_desc.Format;
317             if (texture_desc.ArraySize == 1)
318             {
319                 if (texture_desc.SampleDesc.Count == 1)
320                 {
321                     desc->ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2D;
322                     desc->u.Texture2D.MostDetailedMip = 0;
323                     desc->u.Texture2D.MipLevels = texture_desc.MipLevels;
324                 }
325                 else
326                 {
327                     desc->ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2DMS;
328                 }
329             }
330             else
331             {
332                 if (texture_desc.SampleDesc.Count == 1)
333                 {
334                     desc->ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2DARRAY;
335                     desc->u.Texture2DArray.MostDetailedMip = 0;
336                     desc->u.Texture2DArray.MipLevels = texture_desc.MipLevels;
337                     desc->u.Texture2DArray.FirstArraySlice = 0;
338                     desc->u.Texture2DArray.ArraySize = texture_desc.ArraySize;
339                 }
340                 else
341                 {
342                     desc->ViewDimension = D3D10_SRV_DIMENSION_TEXTURE2DMSARRAY;
343                     desc->u.Texture2DMSArray.FirstArraySlice = 0;
344                     desc->u.Texture2DMSArray.ArraySize = texture_desc.ArraySize;
345                 }
346             }
347
348             return S_OK;
349         }
350
351         case D3D10_RESOURCE_DIMENSION_TEXTURE3D:
352         {
353             D3D10_TEXTURE3D_DESC texture_desc;
354             ID3D10Texture3D *texture;
355
356             if (FAILED(ID3D10Resource_QueryInterface(resource, &IID_ID3D10Texture3D, (void **)&texture)))
357             {
358                 ERR("Resource of type TEXTURE3D doesn't implement ID3D10Texture3D.\n");
359                 return E_INVALIDARG;
360             }
361
362             ID3D10Texture3D_GetDesc(texture, &texture_desc);
363             ID3D10Texture3D_Release(texture);
364
365             desc->Format = texture_desc.Format;
366             desc->ViewDimension = D3D10_SRV_DIMENSION_TEXTURE3D;
367             desc->u.Texture3D.MostDetailedMip = 0;
368             desc->u.Texture3D.MipLevels = texture_desc.MipLevels;
369
370             return S_OK;
371         }
372
373         default:
374             FIXME("Unhandled resource dimension %#x.\n", dimension);
375         case D3D10_RESOURCE_DIMENSION_BUFFER:
376             return E_INVALIDARG;
377     }
378 }
379
380 static inline struct d3d10_depthstencil_view *impl_from_ID3D10DepthStencilView(ID3D10DepthStencilView *iface)
381 {
382     return CONTAINING_RECORD(iface, struct d3d10_depthstencil_view, ID3D10DepthStencilView_iface);
383 }
384
385 /* IUnknown methods */
386
387 static HRESULT STDMETHODCALLTYPE d3d10_depthstencil_view_QueryInterface(ID3D10DepthStencilView *iface,
388         REFIID riid, void **object)
389 {
390     TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
391
392     if (IsEqualGUID(riid, &IID_ID3D10DepthStencilView)
393             || IsEqualGUID(riid, &IID_ID3D10View)
394             || IsEqualGUID(riid, &IID_ID3D10DeviceChild)
395             || IsEqualGUID(riid, &IID_IUnknown))
396     {
397         IUnknown_AddRef(iface);
398         *object = iface;
399         return S_OK;
400     }
401
402     WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
403
404     *object = NULL;
405     return E_NOINTERFACE;
406 }
407
408 static ULONG STDMETHODCALLTYPE d3d10_depthstencil_view_AddRef(ID3D10DepthStencilView *iface)
409 {
410     struct d3d10_depthstencil_view *This = impl_from_ID3D10DepthStencilView(iface);
411     ULONG refcount = InterlockedIncrement(&This->refcount);
412
413     TRACE("%p increasing refcount to %u.\n", This, refcount);
414
415     return refcount;
416 }
417
418 static ULONG STDMETHODCALLTYPE d3d10_depthstencil_view_Release(ID3D10DepthStencilView *iface)
419 {
420     struct d3d10_depthstencil_view *This = impl_from_ID3D10DepthStencilView(iface);
421     ULONG refcount = InterlockedDecrement(&This->refcount);
422
423     TRACE("%p decreasing refcount to %u.\n", This, refcount);
424
425     if (!refcount)
426     {
427         ID3D10Resource_Release(This->resource);
428         HeapFree(GetProcessHeap(), 0, This);
429     }
430
431     return refcount;
432 }
433
434 /* ID3D10DeviceChild methods */
435
436 static void STDMETHODCALLTYPE d3d10_depthstencil_view_GetDevice(ID3D10DepthStencilView *iface, ID3D10Device **device)
437 {
438     FIXME("iface %p, device %p stub!\n", iface, device);
439 }
440
441 static HRESULT STDMETHODCALLTYPE d3d10_depthstencil_view_GetPrivateData(ID3D10DepthStencilView *iface,
442         REFGUID guid, UINT *data_size, void *data)
443 {
444     FIXME("iface %p, guid %s, data_size %p, data %p stub!\n",
445             iface, debugstr_guid(guid), data_size, data);
446
447     return E_NOTIMPL;
448 }
449
450 static HRESULT STDMETHODCALLTYPE d3d10_depthstencil_view_SetPrivateData(ID3D10DepthStencilView *iface,
451         REFGUID guid, UINT data_size, const void *data)
452 {
453     FIXME("iface %p, guid %s, data_size %u, data %p stub!\n",
454             iface, debugstr_guid(guid), data_size, data);
455
456     return E_NOTIMPL;
457 }
458
459 static HRESULT STDMETHODCALLTYPE d3d10_depthstencil_view_SetPrivateDataInterface(ID3D10DepthStencilView *iface,
460         REFGUID guid, const IUnknown *data)
461 {
462     FIXME("iface %p, guid %s, data %p stub!\n", iface, debugstr_guid(guid), data);
463
464     return E_NOTIMPL;
465 }
466
467 /* ID3D10View methods */
468
469 static void STDMETHODCALLTYPE d3d10_depthstencil_view_GetResource(ID3D10DepthStencilView *iface,
470         ID3D10Resource **resource)
471 {
472     struct d3d10_depthstencil_view *view = impl_from_ID3D10DepthStencilView(iface);
473
474     TRACE("iface %p, resource %p.\n", iface, resource);
475
476     *resource = view->resource;
477     ID3D10Resource_AddRef(*resource);
478 }
479
480 /* ID3D10DepthStencilView methods */
481
482 static void STDMETHODCALLTYPE d3d10_depthstencil_view_GetDesc(ID3D10DepthStencilView *iface,
483         D3D10_DEPTH_STENCIL_VIEW_DESC *desc)
484 {
485     struct d3d10_depthstencil_view *view = impl_from_ID3D10DepthStencilView(iface);
486
487     TRACE("iface %p, desc %p.\n", iface, desc);
488
489     *desc = view->desc;
490 }
491
492 static const struct ID3D10DepthStencilViewVtbl d3d10_depthstencil_view_vtbl =
493 {
494     /* IUnknown methods */
495     d3d10_depthstencil_view_QueryInterface,
496     d3d10_depthstencil_view_AddRef,
497     d3d10_depthstencil_view_Release,
498     /* ID3D10DeviceChild methods */
499     d3d10_depthstencil_view_GetDevice,
500     d3d10_depthstencil_view_GetPrivateData,
501     d3d10_depthstencil_view_SetPrivateData,
502     d3d10_depthstencil_view_SetPrivateDataInterface,
503     /* ID3D10View methods */
504     d3d10_depthstencil_view_GetResource,
505     /* ID3D10DepthStencilView methods */
506     d3d10_depthstencil_view_GetDesc,
507 };
508
509 HRESULT d3d10_depthstencil_view_init(struct d3d10_depthstencil_view *view,
510         ID3D10Resource *resource, const D3D10_DEPTH_STENCIL_VIEW_DESC *desc)
511 {
512     HRESULT hr;
513
514     view->ID3D10DepthStencilView_iface.lpVtbl = &d3d10_depthstencil_view_vtbl;
515     view->refcount = 1;
516
517     if (!desc)
518     {
519         if (FAILED(hr = set_dsdesc_from_resource(&view->desc, resource)))
520             return hr;
521     }
522     else
523     {
524         view->desc = *desc;
525     }
526
527     view->resource = resource;
528     ID3D10Resource_AddRef(resource);
529
530     return S_OK;
531 }
532
533 static inline struct d3d10_rendertarget_view *impl_from_ID3D10RenderTargetView(ID3D10RenderTargetView *iface)
534 {
535     return CONTAINING_RECORD(iface, struct d3d10_rendertarget_view, ID3D10RenderTargetView_iface);
536 }
537
538 /* IUnknown methods */
539
540 static HRESULT STDMETHODCALLTYPE d3d10_rendertarget_view_QueryInterface(ID3D10RenderTargetView *iface,
541         REFIID riid, void **object)
542 {
543     TRACE("iface %p, riid %s, object %p\n", iface, debugstr_guid(riid), object);
544
545     if (IsEqualGUID(riid, &IID_ID3D10RenderTargetView)
546             || IsEqualGUID(riid, &IID_ID3D10View)
547             || IsEqualGUID(riid, &IID_ID3D10DeviceChild)
548             || IsEqualGUID(riid, &IID_IUnknown))
549     {
550         IUnknown_AddRef(iface);
551         *object = iface;
552         return S_OK;
553     }
554
555     WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid));
556
557     *object = NULL;
558     return E_NOINTERFACE;
559 }
560
561 static ULONG STDMETHODCALLTYPE d3d10_rendertarget_view_AddRef(ID3D10RenderTargetView *iface)
562 {
563     struct d3d10_rendertarget_view *This = impl_from_ID3D10RenderTargetView(iface);
564     ULONG refcount = InterlockedIncrement(&This->refcount);
565
566     TRACE("%p increasing refcount to %u\n", This, refcount);
567
568     return refcount;
569 }
570
571 static ULONG STDMETHODCALLTYPE d3d10_rendertarget_view_Release(ID3D10RenderTargetView *iface)
572 {
573     struct d3d10_rendertarget_view *This = impl_from_ID3D10RenderTargetView(iface);
574     ULONG refcount = InterlockedDecrement(&This->refcount);
575
576     TRACE("%p decreasing refcount to %u\n", This, refcount);
577
578     if (!refcount)
579     {
580         wined3d_rendertarget_view_decref(This->wined3d_view);
581         ID3D10Resource_Release(This->resource);
582         HeapFree(GetProcessHeap(), 0, This);
583     }
584
585     return refcount;
586 }
587
588 /* ID3D10DeviceChild methods */
589
590 static void STDMETHODCALLTYPE d3d10_rendertarget_view_GetDevice(ID3D10RenderTargetView *iface, ID3D10Device **device)
591 {
592     FIXME("iface %p, device %p stub!\n", iface, device);
593 }
594
595 static HRESULT STDMETHODCALLTYPE d3d10_rendertarget_view_GetPrivateData(ID3D10RenderTargetView *iface,
596         REFGUID guid, UINT *data_size, void *data)
597 {
598     FIXME("iface %p, guid %s, data_size %p, data %p stub!\n",
599             iface, debugstr_guid(guid), data_size, data);
600
601     return E_NOTIMPL;
602 }
603
604 static HRESULT STDMETHODCALLTYPE d3d10_rendertarget_view_SetPrivateData(ID3D10RenderTargetView *iface,
605         REFGUID guid, UINT data_size, const void *data)
606 {
607     FIXME("iface %p, guid %s, data_size %u, data %p stub!\n",
608             iface, debugstr_guid(guid), data_size, data);
609
610     return E_NOTIMPL;
611 }
612
613 static HRESULT STDMETHODCALLTYPE d3d10_rendertarget_view_SetPrivateDataInterface(ID3D10RenderTargetView *iface,
614         REFGUID guid, const IUnknown *data)
615 {
616     FIXME("iface %p, guid %s, data %p stub!\n", iface, debugstr_guid(guid), data);
617
618     return E_NOTIMPL;
619 }
620
621 /* ID3D10View methods */
622
623 static void STDMETHODCALLTYPE d3d10_rendertarget_view_GetResource(ID3D10RenderTargetView *iface,
624         ID3D10Resource **resource)
625 {
626     struct d3d10_rendertarget_view *view = impl_from_ID3D10RenderTargetView(iface);
627
628     TRACE("iface %p, resource %p\n", iface, resource);
629
630     *resource = view->resource;
631     ID3D10Resource_AddRef(*resource);
632 }
633
634 /* ID3D10RenderTargetView methods */
635
636 static void STDMETHODCALLTYPE d3d10_rendertarget_view_GetDesc(ID3D10RenderTargetView *iface,
637         D3D10_RENDER_TARGET_VIEW_DESC *desc)
638 {
639     struct d3d10_rendertarget_view *This = impl_from_ID3D10RenderTargetView(iface);
640
641     TRACE("iface %p, desc %p\n", iface, desc);
642
643     *desc = This->desc;
644 }
645
646 static const struct ID3D10RenderTargetViewVtbl d3d10_rendertarget_view_vtbl =
647 {
648     /* IUnknown methods */
649     d3d10_rendertarget_view_QueryInterface,
650     d3d10_rendertarget_view_AddRef,
651     d3d10_rendertarget_view_Release,
652     /* ID3D10DeviceChild methods */
653     d3d10_rendertarget_view_GetDevice,
654     d3d10_rendertarget_view_GetPrivateData,
655     d3d10_rendertarget_view_SetPrivateData,
656     d3d10_rendertarget_view_SetPrivateDataInterface,
657     /* ID3D10View methods */
658     d3d10_rendertarget_view_GetResource,
659     /* ID3D10RenderTargetView methods */
660     d3d10_rendertarget_view_GetDesc,
661 };
662
663 HRESULT d3d10_rendertarget_view_init(struct d3d10_rendertarget_view *view,
664         ID3D10Resource *resource, const D3D10_RENDER_TARGET_VIEW_DESC *desc)
665 {
666     struct wined3d_resource *wined3d_resource;
667     HRESULT hr;
668
669     view->ID3D10RenderTargetView_iface.lpVtbl = &d3d10_rendertarget_view_vtbl;
670     view->refcount = 1;
671
672     if (!desc)
673     {
674         HRESULT hr = set_rtdesc_from_resource(&view->desc, resource);
675         if (FAILED(hr)) return hr;
676     }
677     else
678     {
679         view->desc = *desc;
680     }
681
682     wined3d_resource = wined3d_resource_from_resource(resource);
683     if (!wined3d_resource)
684     {
685         ERR("Failed to get wined3d resource for d3d10 resource %p.\n", resource);
686         return E_FAIL;
687     }
688
689     hr = wined3d_rendertarget_view_create(wined3d_resource, view, &view->wined3d_view);
690     if (FAILED(hr))
691     {
692         WARN("Failed to create a wined3d rendertarget view, hr %#x.\n", hr);
693         return hr;
694     }
695
696     view->resource = resource;
697     ID3D10Resource_AddRef(resource);
698
699     return S_OK;
700 }
701
702 struct d3d10_rendertarget_view *unsafe_impl_from_ID3D10RenderTargetView(ID3D10RenderTargetView *iface)
703 {
704     if (!iface)
705         return NULL;
706     assert(iface->lpVtbl == &d3d10_rendertarget_view_vtbl);
707
708     return impl_from_ID3D10RenderTargetView(iface);
709 }
710
711 static inline struct d3d10_shader_resource_view *impl_from_ID3D10ShaderResourceView(ID3D10ShaderResourceView *iface)
712 {
713     return CONTAINING_RECORD(iface, struct d3d10_shader_resource_view, ID3D10ShaderResourceView_iface);
714 }
715
716 /* IUnknown methods */
717
718 static HRESULT STDMETHODCALLTYPE d3d10_shader_resource_view_QueryInterface(ID3D10ShaderResourceView *iface,
719         REFIID riid, void **object)
720 {
721     TRACE("iface %p, riid %s, object %p.\n", iface, debugstr_guid(riid), object);
722
723     if (IsEqualGUID(riid, &IID_ID3D10ShaderResourceView)
724             || IsEqualGUID(riid, &IID_ID3D10View)
725             || IsEqualGUID(riid, &IID_ID3D10DeviceChild)
726             || IsEqualGUID(riid, &IID_IUnknown))
727     {
728         IUnknown_AddRef(iface);
729         *object = iface;
730         return S_OK;
731     }
732
733     WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(riid));
734
735     *object = NULL;
736     return E_NOINTERFACE;
737 }
738
739 static ULONG STDMETHODCALLTYPE d3d10_shader_resource_view_AddRef(ID3D10ShaderResourceView *iface)
740 {
741     struct d3d10_shader_resource_view *This = impl_from_ID3D10ShaderResourceView(iface);
742     ULONG refcount = InterlockedIncrement(&This->refcount);
743
744     TRACE("%p increasing refcount to %u.\n", This, refcount);
745
746     return refcount;
747 }
748
749 static ULONG STDMETHODCALLTYPE d3d10_shader_resource_view_Release(ID3D10ShaderResourceView *iface)
750 {
751     struct d3d10_shader_resource_view *This = impl_from_ID3D10ShaderResourceView(iface);
752     ULONG refcount = InterlockedDecrement(&This->refcount);
753
754     TRACE("%p decreasing refcount to %u.\n", This, refcount);
755
756     if (!refcount)
757     {
758         ID3D10Resource_Release(This->resource);
759         HeapFree(GetProcessHeap(), 0, This);
760     }
761
762     return refcount;
763 }
764
765 /* ID3D10DeviceChild methods */
766
767 static void STDMETHODCALLTYPE d3d10_shader_resource_view_GetDevice(ID3D10ShaderResourceView *iface,
768         ID3D10Device **device)
769 {
770     FIXME("iface %p, device %p stub!\n", iface, device);
771 }
772
773 static HRESULT STDMETHODCALLTYPE d3d10_shader_resource_view_GetPrivateData(ID3D10ShaderResourceView *iface,
774         REFGUID guid, UINT *data_size, void *data)
775 {
776     FIXME("iface %p, guid %s, data_size %p, data %p stub!\n",
777             iface, debugstr_guid(guid), data_size, data);
778
779     return E_NOTIMPL;
780 }
781
782 static HRESULT STDMETHODCALLTYPE d3d10_shader_resource_view_SetPrivateData(ID3D10ShaderResourceView *iface,
783         REFGUID guid, UINT data_size, const void *data)
784 {
785     FIXME("iface %p, guid %s, data_size %u, data %p stub!\n",
786             iface, debugstr_guid(guid), data_size, data);
787
788     return E_NOTIMPL;
789 }
790
791 static HRESULT STDMETHODCALLTYPE d3d10_shader_resource_view_SetPrivateDataInterface(ID3D10ShaderResourceView *iface,
792         REFGUID guid, const IUnknown *data)
793 {
794     FIXME("iface %p, guid %s, data %p stub!\n", iface, debugstr_guid(guid), data);
795
796     return E_NOTIMPL;
797 }
798
799 /* ID3D10View methods */
800
801 static void STDMETHODCALLTYPE d3d10_shader_resource_view_GetResource(ID3D10ShaderResourceView *iface,
802         ID3D10Resource **resource)
803 {
804     struct d3d10_shader_resource_view *view = impl_from_ID3D10ShaderResourceView(iface);
805
806     TRACE("iface %p, resource %p.\n", iface, resource);
807
808     *resource = view->resource;
809     ID3D10Resource_AddRef(*resource);
810 }
811
812 /* ID3D10ShaderResourceView methods */
813
814 static void STDMETHODCALLTYPE d3d10_shader_resource_view_GetDesc(ID3D10ShaderResourceView *iface,
815         D3D10_SHADER_RESOURCE_VIEW_DESC *desc)
816 {
817     struct d3d10_shader_resource_view *view = impl_from_ID3D10ShaderResourceView(iface);
818
819     TRACE("iface %p, desc %p.\n", iface, desc);
820
821     *desc = view->desc;
822 }
823
824 static const struct ID3D10ShaderResourceViewVtbl d3d10_shader_resource_view_vtbl =
825 {
826     /* IUnknown methods */
827     d3d10_shader_resource_view_QueryInterface,
828     d3d10_shader_resource_view_AddRef,
829     d3d10_shader_resource_view_Release,
830     /* ID3D10DeviceChild methods */
831     d3d10_shader_resource_view_GetDevice,
832     d3d10_shader_resource_view_GetPrivateData,
833     d3d10_shader_resource_view_SetPrivateData,
834     d3d10_shader_resource_view_SetPrivateDataInterface,
835     /* ID3D10View methods */
836     d3d10_shader_resource_view_GetResource,
837     /* ID3D10ShaderResourceView methods */
838     d3d10_shader_resource_view_GetDesc,
839 };
840
841 HRESULT d3d10_shader_resource_view_init(struct d3d10_shader_resource_view *view,
842         ID3D10Resource *resource, const D3D10_SHADER_RESOURCE_VIEW_DESC *desc)
843 {
844     HRESULT hr;
845
846     view->ID3D10ShaderResourceView_iface.lpVtbl = &d3d10_shader_resource_view_vtbl;
847     view->refcount = 1;
848
849     if (!desc)
850     {
851         if (FAILED(hr = set_srdesc_from_resource(&view->desc, resource)))
852             return hr;
853     }
854     else
855     {
856         view->desc = *desc;
857     }
858
859     view->resource = resource;
860     ID3D10Resource_AddRef(resource);
861
862     return S_OK;
863 }