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