d3dx9: Add ID3DXRenderToSurface interface stub.
[wine] / dlls / d3dx9_36 / render.c
1 /*
2  * Copyright (C) 2012 Józef Kucia
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 "wine/debug.h"
21 #include "d3dx9_36_private.h"
22
23 WINE_DEFAULT_DEBUG_CHANNEL(d3dx);
24
25 struct render_to_surface
26 {
27     ID3DXRenderToSurface ID3DXRenderToSurface_iface;
28     LONG ref;
29
30     IDirect3DDevice9 *device;
31 };
32
33 static inline struct render_to_surface *impl_from_ID3DXRenderToSurface(ID3DXRenderToSurface *iface)
34 {
35     return CONTAINING_RECORD(iface, struct render_to_surface, ID3DXRenderToSurface_iface);
36 }
37
38 static HRESULT WINAPI D3DXRenderToSurface_QueryInterface(ID3DXRenderToSurface *iface,
39                                                          REFIID riid,
40                                                          void **out)
41 {
42     TRACE("iface %p, riid %s, out %p\n", iface, debugstr_guid(riid), out);
43
44     if (IsEqualGUID(riid, &IID_ID3DXRenderToSurface)
45             || IsEqualGUID(riid, &IID_IUnknown))
46     {
47         IUnknown_AddRef(iface);
48         *out = iface;
49         return S_OK;
50     }
51
52     WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid));
53
54     *out = NULL;
55     return E_NOINTERFACE;
56 }
57
58 static ULONG WINAPI D3DXRenderToSurface_AddRef(ID3DXRenderToSurface *iface)
59 {
60     struct render_to_surface *render = impl_from_ID3DXRenderToSurface(iface);
61     ULONG ref = InterlockedIncrement(&render->ref);
62
63     TRACE("%p increasing refcount to %u\n", iface, ref);
64
65     return ref;
66 }
67
68 static ULONG WINAPI D3DXRenderToSurface_Release(ID3DXRenderToSurface *iface)
69 {
70     struct render_to_surface *render = impl_from_ID3DXRenderToSurface(iface);
71     ULONG ref = InterlockedDecrement(&render->ref);
72
73     TRACE("%p decreasing refcount to %u\n", iface, ref);
74
75     if (!ref)
76     {
77         IDirect3DDevice9_Release(render->device);
78         HeapFree(GetProcessHeap(), 0, render);
79     }
80
81     return ref;
82 }
83
84 static HRESULT WINAPI D3DXRenderToSurface_GetDevice(ID3DXRenderToSurface *iface,
85                                                     IDirect3DDevice9 **device)
86 {
87     FIXME("(%p)->(%p): stub\n", iface, device);
88     return E_NOTIMPL;
89 }
90
91 static HRESULT WINAPI D3DXRenderToSurface_GetDesc(ID3DXRenderToSurface *iface,
92                                                   D3DXRTS_DESC *desc)
93 {
94     FIXME("(%p)->(%p): stub\n", iface, desc);
95     return E_NOTIMPL;
96 }
97
98 static HRESULT WINAPI D3DXRenderToSurface_BeginScene(ID3DXRenderToSurface *iface,
99                                                      IDirect3DSurface9 *surface,
100                                                      const D3DVIEWPORT9 *viewport)
101 {
102     FIXME("(%p)->(%p, %p): stub\n", iface, surface, viewport);
103     return E_NOTIMPL;
104 }
105
106 static HRESULT WINAPI D3DXRenderToSurface_EndScene(ID3DXRenderToSurface *iface,
107                                                    DWORD mip_filter)
108 {
109     FIXME("(%p)->(%#x): stub\n", iface, mip_filter);
110     return E_NOTIMPL;
111 }
112
113 static HRESULT WINAPI D3DXRenderToSurface_OnLostDevice(ID3DXRenderToSurface *iface)
114 {
115     FIXME("(%p)->(): stub\n", iface);
116     return D3D_OK;
117 }
118
119 static HRESULT WINAPI D3DXRenderToSurface_OnResetDevice(ID3DXRenderToSurface *iface)
120 {
121     FIXME("(%p)->(): stub\n", iface);
122     return D3D_OK;
123 }
124
125 static const ID3DXRenderToSurfaceVtbl d3dx_render_to_surface_vtbl =
126 {
127     /* IUnknown methods */
128     D3DXRenderToSurface_QueryInterface,
129     D3DXRenderToSurface_AddRef,
130     D3DXRenderToSurface_Release,
131     /* ID3DXRenderToSurface methods */
132     D3DXRenderToSurface_GetDevice,
133     D3DXRenderToSurface_GetDesc,
134     D3DXRenderToSurface_BeginScene,
135     D3DXRenderToSurface_EndScene,
136     D3DXRenderToSurface_OnLostDevice,
137     D3DXRenderToSurface_OnResetDevice
138 };
139
140 HRESULT WINAPI D3DXCreateRenderToSurface(IDirect3DDevice9 *device,
141                                          UINT width,
142                                          UINT height,
143                                          D3DFORMAT format,
144                                          BOOL depth_stencil,
145                                          D3DFORMAT depth_stencil_format,
146                                          ID3DXRenderToSurface **out)
147 {
148     struct render_to_surface *render;
149
150     FIXME("(%p, %u, %u, %#x, %d, %#x, %p): semi-stub\n", device, width, height, format,
151             depth_stencil, depth_stencil_format, out);
152
153     if (!device || !out) return D3DERR_INVALIDCALL;
154
155     render = HeapAlloc(GetProcessHeap(), 0, sizeof(struct render_to_surface));
156     if (!render) return E_OUTOFMEMORY;
157
158     render->ID3DXRenderToSurface_iface.lpVtbl = &d3dx_render_to_surface_vtbl;
159     render->ref = 1;
160
161     IDirect3DDevice9_AddRef(device);
162     render->device = device;
163
164     *out = &render->ID3DXRenderToSurface_iface;
165     return D3D_OK;
166 }